• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.8.3 API Reference
  • KDE Home
  • Contact Us
 

KDECore

kurl.h
Go to the documentation of this file.
00001 // -*- c-basic-offset: 2 -*-
00002 /* This file is part of the KDE libraries
00003  *  Copyright (C) 1999 Torben Weis <weis@kde.org>
00004  *  Copyright (C) 2005-2006 David Faure <faure@kde.org>
00005  *
00006  *  This library is free software; you can redistribute it and/or
00007  *  modify it under the terms of the GNU Library General Public
00008  *  License as published by the Free Software Foundation; either
00009  *  version 2 of the License, or (at your option) any later version.
00010  *
00011  *  This library is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  *  Library General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU Library General Public License
00017  *  along with this library; see the file COPYING.LIB.  If not, write to
00018  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  *  Boston, MA 02110-1301, USA.
00020  */
00021 
00022 #ifndef kurl_h
00023 #define kurl_h
00024 
00025 #include <kdecore_export.h>
00026 
00027 #include <QtCore/QVariant>
00028 #include <QtCore/QUrl>
00029 #include <QtCore/QMap>
00030 
00031 class QStringList;
00032 class QMimeData;
00033 
00034 class KUrlPrivate;
00035 
00036 // maybe we should encapsulate QUrl instead of inheriting from it.
00037 // this would even allow us to inherit from KUri instead.
00038 // and this way hacks like setPath() would be less ugly, and we could avoid
00039 // half KDE code using setScheme() and the other half using setProtocol(), etc.
00040 // (DF)
00041 
00111 class KDECORE_EXPORT KUrl : public QUrl // krazy:exclude=dpointer,qclasses (krazy can't deal with embedded classes)
00112 {
00113 public:
00114   typedef QMap<QString, QString> MetaDataMap;
00115   enum MimeDataFlags { DefaultMimeDataFlags = 0, NoTextExport = 1 };
00116 
00120   enum AdjustPathOption
00121   {
00125     RemoveTrailingSlash,
00126 
00130     LeaveTrailingSlash,
00131 
00135     AddTrailingSlash
00136   };
00137 
00146   class KDECORE_EXPORT List : public QList<KUrl> //krazy:exclude=dpointer (just some convenience methods)
00147   {
00148   public:
00152       List() { }
00158       List(const KUrl &url);
00164       List(const QStringList &list);
00169       List(const QList<KUrl> &list);
00175       List(const QList<QUrl> &list);
00180       QStringList toStringList() const;
00181 
00191       QStringList toStringList(KUrl::AdjustPathOption trailing) const;
00192 
00197       operator QVariant() const;
00198 
00203       operator QList<QUrl>() const;
00204 
00222       void populateMimeData( QMimeData* mimeData,
00223                              const KUrl::MetaDataMap& metaData = MetaDataMap(),
00224                              MimeDataFlags flags = DefaultMimeDataFlags ) const;
00225 
00260       void populateMimeData(const KUrl::List& mostLocalUrls,
00261                             QMimeData* mimeData,
00262                             const KUrl::MetaDataMap& metaData = MetaDataMap(),
00263                             MimeDataFlags flags = DefaultMimeDataFlags) const;
00264 
00268       static bool canDecode( const QMimeData *mimeData );
00269 
00273       static QStringList mimeDataTypes();
00274 
00283       static KUrl::List fromMimeData( const QMimeData *mimeData, KUrl::MetaDataMap* metaData = 0 );
00284 
00289       enum DecodeOptions {
00296         PreferLocalUrls,
00303         PreferKdeUrls
00304       };
00305 
00316       static KUrl::List fromMimeData( const QMimeData *mimeData,
00317                                       DecodeOptions decodeOptions, // TODO KDE5: = PreferKdeUrls, and merge with above
00318                                       KUrl::MetaDataMap* metaData = 0 );
00319 
00320   };
00324   KUrl();
00325 
00329   ~KUrl();
00330 
00335   KUrl( const QString& urlOrPath );
00342   explicit KUrl( const char * urlOrPath );
00349   explicit KUrl( const QByteArray& urlOrPath );
00350 
00355   KUrl( const KUrl& u );
00360   KUrl( const QUrl &u ); //krazy:exclude=qclasses
00371   KUrl( const KUrl& _baseurl, const QString& _rel_url );
00372 
00377   QString protocol() const;
00378 
00383   void setProtocol( const QString& proto );
00384 
00389   QString user() const;
00390 
00397   void setUser( const QString& user );
00398 
00403   bool hasUser() const;
00404 
00409   QString pass() const;
00410 
00421   void setPass( const QString& pass );
00422 
00427   bool hasPass() const;
00428 
00433   bool hasHost() const;
00434 
00441   QString path( AdjustPathOption trailing = LeaveTrailingSlash ) const;
00442 
00449   QString toLocalFile( AdjustPathOption trailing = LeaveTrailingSlash ) const;
00450 
00452   void setPath( const QString& path );
00453 
00458   bool hasPath() const;
00459 
00463   enum CleanPathOption
00464   {
00469     SimplifyDirSeparators = 0x00,
00470 
00474     KeepDirSeparators = 0x01
00475   };
00476 
00477   Q_DECLARE_FLAGS(CleanPathOptions,CleanPathOption)
00478 
00479   
00487   void cleanPath(const CleanPathOption& options = SimplifyDirSeparators);
00488 
00489 
00503   void adjustPath(AdjustPathOption trailing);
00504 
00510   void setEncodedPathAndQuery( const QString& _txt );
00511 
00512 #if 0
00513 
00518   void setEncodedPath(const QString& _txt );
00519 #endif
00520 
00524   enum EncodedPathAndQueryOption
00525   {
00529     PermitEmptyPath=0x00,
00534     AvoidEmptyPath=0x01
00535   };
00536   Q_DECLARE_FLAGS( EncodedPathAndQueryOptions, EncodedPathAndQueryOption)
00537 
00538   
00546   QString encodedPathAndQuery( AdjustPathOption trailing = LeaveTrailingSlash, const EncodedPathAndQueryOptions &options = PermitEmptyPath ) const;
00547 
00554   void setQuery( const QString& query );
00555 
00564   QString query() const;
00565 
00571   QString ref() const;
00572 
00578   void setRef( const QString& fragment );
00579 
00586   bool hasRef() const;
00587 
00595   QString htmlRef() const;
00596 
00602   QString encodedHtmlRef() const;
00603 
00611   void setHTMLRef( const QString& _ref );
00612 
00618   bool hasHTMLRef() const;
00619 
00627   bool isLocalFile() const;
00628 
00635   void setFileEncoding(const QString &encoding);
00636 
00643   QString fileEncoding() const;
00644 
00651   bool hasSubUrl() const;
00652 
00663   void addPath( const QString& txt );
00664 
00671   enum QueryItemsOption { CaseInsensitiveKeys = 1 };
00672   Q_DECLARE_FLAGS(QueryItemsOptions,QueryItemsOption)
00673 
00674   
00686   QMap< QString, QString > queryItems( const QueryItemsOptions& options = 0 ) const;
00687   // #### TODO port the above queryItems to look more like QUrl's
00688   //using QUrl::queryItems; // temporary
00689 
00701   QString queryItem(const QString &item) const;
00702 
00711   void addQueryItem( const QString& _item, const QString& _value );
00712 
00713 
00727   void setFileName( const QString&_txt );
00728 
00732   enum DirectoryOption
00733   {
00743     ObeyTrailingSlash = 0x02,
00752     AppendTrailingSlash = 0x04,
00757     IgnoreTrailingSlash = 0x01
00758 
00759   };
00760   Q_DECLARE_FLAGS(DirectoryOptions,DirectoryOption)
00761 
00762 
00763   
00769   QString fileName( const DirectoryOptions& options = IgnoreTrailingSlash ) const;
00770 
00779   QString directory( const DirectoryOptions& options = IgnoreTrailingSlash ) const;
00780 
00784   void setDirectory(const QString &dir);
00785 
00799   bool cd( const QString& _dir );
00800 
00815   QString url( AdjustPathOption trailing = LeaveTrailingSlash ) const;
00816 
00829   QString prettyUrl( AdjustPathOption trailing = LeaveTrailingSlash ) const;
00830 
00841   QString pathOrUrl() const;
00847   QString pathOrUrl(AdjustPathOption trailing) const; // KDE5: merge with above. Rename to toUrlOrLocalFile?
00848 
00854   QString toMimeDataString() const;
00855 
00864   KUrl upUrl( ) const;
00865 
00866   KUrl& operator=( const KUrl& _u );
00867 
00868   // Define those, since the constructors are explicit
00869   KUrl& operator=( const char * _url ) { *this = KUrl(_url); return *this; }
00870   KUrl& operator=( const QByteArray& _url ) { *this = KUrl(_url); return *this; }
00871   KUrl& operator=( const QString& _url ) { *this = KUrl(_url); return *this; }
00872 
00873   bool operator==( const KUrl& _u ) const;
00874   bool operator==( const QString& _u ) const;
00875   bool operator!=( const KUrl& _u ) const { return !( *this == _u ); }
00876   bool operator!=( const QString& _u ) const { return !( *this == _u ); }
00877 
00882   operator QVariant() const;
00883 
00895 #ifndef KDE_NO_DEPRECATED
00896   KDE_DEPRECATED bool cmp( const KUrl &u, bool ignore_trailing = false ) const;
00897 #endif
00898 
00899 
00903   enum EqualsOption
00904   {
00915     CompareWithoutTrailingSlash = 0x01,
00919     CompareWithoutFragment = 0x02,
00929     AllowEmptyPath = 0x04
00930   };
00931   Q_DECLARE_FLAGS(EqualsOptions,EqualsOption)
00932 
00933   
00942   bool equals( const KUrl &u, const EqualsOptions& options=0 ) const;
00943 
00950   bool isParentOf( const KUrl& u ) const;
00951     // (this overload of the QUrl method allows to use the implicit KUrl constructors)
00952     // but also the equality test
00953 
00969   static List split( const QString& _url );
00970 
00986   static List split( const KUrl& _url );
00987 
00995   static KUrl join( const List& _list );
00996 
01006   static KUrl fromPath( const QString& text );
01007 
01013 #ifndef KDE_NO_DEPRECATED
01014   static KDE_DEPRECATED KUrl fromPathOrUrl( const QString& text );
01015 #endif
01016 
01022   static KUrl fromMimeDataByteArray( const QByteArray& str );
01023 
01040   void populateMimeData( QMimeData* mimeData,
01041                          const MetaDataMap& metaData = MetaDataMap(),
01042                          MimeDataFlags flags = DefaultMimeDataFlags ) const;
01043 
01054 #ifndef KDE_NO_DEPRECATED
01055   static KDE_DEPRECATED QString encode_string(const QString &str) {
01056     return QString::fromLatin1( QUrl::toPercentEncoding( str ).constData() ); //krazy:exclude=qclasses
01057   }
01058 #endif
01059 
01071 #ifndef KDE_NO_DEPRECATED
01072   static KDE_DEPRECATED QString encode_string_no_slash(const QString &str) {
01073       return QString::fromLatin1( QUrl::toPercentEncoding( str, "/" ).constData() ); //krazy:exclude=qclasses
01074   }
01075 #endif
01076 
01087 #ifndef KDE_NO_DEPRECATED
01088   static KDE_DEPRECATED QString decode_string(const QString &str) {
01089       return QUrl::fromPercentEncoding( str.toLatin1() ); //krazy:exclude=qclasses
01090   }
01091 #endif
01092 
01093 
01113   static bool isRelativeUrl(const QString &_url);
01114 
01129   static QString relativeUrl(const KUrl &base_url, const KUrl &url);
01130 
01140   static QString relativePath(const QString &base_dir, const QString &path, bool *isParent=0);
01141 
01142 private:
01143   void _setQuery( const QString& query );
01144   void _setEncodedUrl(const QByteArray& url);
01145   QString toString() const; // forbidden, use url(), prettyUrl(), or pathOrUrl() instead.
01146   operator QString() const; // forbidden, use url(), prettyUrl(), or pathOrUrl() instead.
01147 private:
01148   KUrlPrivate* const d; // Don't ever use this, it would break clear() (which is in QUrl)
01149 };
01150 
01151 Q_DECLARE_OPERATORS_FOR_FLAGS(KUrl::EncodedPathAndQueryOptions)
01152 Q_DECLARE_OPERATORS_FOR_FLAGS(KUrl::CleanPathOptions)
01153 Q_DECLARE_OPERATORS_FOR_FLAGS(KUrl::QueryItemsOptions)
01154 Q_DECLARE_OPERATORS_FOR_FLAGS(KUrl::EqualsOptions)
01155 Q_DECLARE_OPERATORS_FOR_FLAGS(KUrl::DirectoryOptions)
01156 
01157 Q_DECLARE_METATYPE(KUrl)
01158 Q_DECLARE_METATYPE(KUrl::List)
01159 
01168 #ifndef KDE_NO_DEPRECATED
01169 KDECORE_EXPORT_DEPRECATED bool urlcmp( const QString& _url1, const QString& _url2 ); // KDE5: remove, KUrl::equals is better API
01170 #endif
01171 
01184 #ifndef KDE_NO_DEPRECATED
01185 KDECORE_EXPORT_DEPRECATED bool urlcmp( const QString& _url1, const QString& _url2, const KUrl::EqualsOptions& options ); // KDE5: remove, KUrl::equals is better API
01186 #endif
01187 
01188 KDECORE_EXPORT uint qHash(const KUrl& kurl);
01189 
01190 #endif
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu May 10 2012 20:49:33 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDECore

Skip menu "KDECore"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs-4.8.3 API Reference

Skip menu "kdelibs-4.8.3 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal