• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • kdelibs
  • 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);
00174       QStringList toStringList() const;
00175 
00185       QStringList toStringList(KUrl::AdjustPathOption trailing) const;
00186 
00191       operator QVariant() const;
00192 
00210       void populateMimeData( QMimeData* mimeData,
00211                              const KUrl::MetaDataMap& metaData = MetaDataMap(),
00212                              MimeDataFlags flags = DefaultMimeDataFlags ) const;
00213 
00248       void populateMimeData(const KUrl::List& mostLocalUrls,
00249                             QMimeData* mimeData,
00250                             const KUrl::MetaDataMap& metaData = MetaDataMap(),
00251                             MimeDataFlags flags = DefaultMimeDataFlags) const;
00252 
00256       static bool canDecode( const QMimeData *mimeData );
00257 
00261       static QStringList mimeDataTypes();
00262 
00271       static KUrl::List fromMimeData( const QMimeData *mimeData, KUrl::MetaDataMap* metaData = 0 );
00272 
00277       enum DecodeOptions {
00284         PreferLocalUrls,
00291         PreferKdeUrls
00292       };
00293 
00304       static KUrl::List fromMimeData( const QMimeData *mimeData,
00305                                       DecodeOptions decodeOptions, // TODO KDE5: = PreferKdeUrls, and merge with above
00306                                       KUrl::MetaDataMap* metaData = 0 );
00307 
00308   };
00312   KUrl();
00313 
00317   ~KUrl();
00318 
00323   KUrl( const QString& urlOrPath );
00330   explicit KUrl( const char * urlOrPath );
00337   explicit KUrl( const QByteArray& urlOrPath );
00338 
00343   KUrl( const KUrl& u );
00348   KUrl( const QUrl &u ); //krazy:exclude=qclasses
00359   KUrl( const KUrl& _baseurl, const QString& _rel_url );
00360 
00365   QString protocol() const;
00366 
00371   void setProtocol( const QString& proto );
00372 
00377   QString user() const;
00378 
00385   void setUser( const QString& user );
00386 
00391   bool hasUser() const;
00392 
00397   QString pass() const;
00398 
00409   void setPass( const QString& pass );
00410 
00415   bool hasPass() const;
00416 
00421   bool hasHost() const;
00422 
00429   QString path( AdjustPathOption trailing = LeaveTrailingSlash ) const;
00430 
00437   QString toLocalFile( AdjustPathOption trailing = LeaveTrailingSlash ) const;
00438 
00440   void setPath( const QString& path );
00441 
00446   bool hasPath() const;
00447 
00451   enum CleanPathOption
00452   {
00457     SimplifyDirSeparators = 0x00,
00458 
00462     KeepDirSeparators = 0x01
00463   };
00464 
00465   Q_DECLARE_FLAGS(CleanPathOptions,CleanPathOption)
00466 
00467   
00475   void cleanPath(const CleanPathOption& options = SimplifyDirSeparators);
00476 
00477 
00491   void adjustPath(AdjustPathOption trailing);
00492 
00498   void setEncodedPathAndQuery( const QString& _txt );
00499 
00500 #if 0
00501 
00506   void setEncodedPath(const QString& _txt );
00507 #endif
00508 
00512   enum EncodedPathAndQueryOption
00513   {
00517     PermitEmptyPath=0x00,
00522     AvoidEmptyPath=0x01
00523   };
00524   Q_DECLARE_FLAGS( EncodedPathAndQueryOptions, EncodedPathAndQueryOption)
00525 
00526   
00534   QString encodedPathAndQuery( AdjustPathOption trailing = LeaveTrailingSlash, const EncodedPathAndQueryOptions &options = PermitEmptyPath ) const;
00535 
00542   void setQuery( const QString& query );
00543 
00552   QString query() const;
00553 
00559   QString ref() const;
00560 
00566   void setRef( const QString& fragment );
00567 
00574   bool hasRef() const;
00575 
00583   QString htmlRef() const;
00584 
00590   QString encodedHtmlRef() const;
00591 
00599   void setHTMLRef( const QString& _ref );
00600 
00606   bool hasHTMLRef() const;
00607 
00613   bool isLocalFile() const;
00614 
00621   void setFileEncoding(const QString &encoding);
00622 
00629   QString fileEncoding() const;
00630 
00637   bool hasSubUrl() const;
00638 
00649   void addPath( const QString& txt );
00650 
00657   enum QueryItemsOption { CaseInsensitiveKeys = 1 };
00658   Q_DECLARE_FLAGS(QueryItemsOptions,QueryItemsOption)
00659 
00660   
00672   QMap< QString, QString > queryItems( const QueryItemsOptions& options = 0 ) const;
00673   // #### TODO port the above queryItems to look more like QUrl's
00674   //using QUrl::queryItems; // temporary
00675 
00687   QString queryItem(const QString &item) const;
00688 
00697   void addQueryItem( const QString& _item, const QString& _value );
00698 
00699 
00713   void setFileName( const QString&_txt );
00714 
00718   enum DirectoryOption
00719   {
00729     ObeyTrailingSlash = 0x02,
00738     AppendTrailingSlash = 0x04,
00743     IgnoreTrailingSlash = 0x01
00744 
00745   };
00746   Q_DECLARE_FLAGS(DirectoryOptions,DirectoryOption)
00747 
00748 
00749   
00755   QString fileName( const DirectoryOptions& options = IgnoreTrailingSlash ) const;
00756 
00765   QString directory( const DirectoryOptions& options = IgnoreTrailingSlash ) const;
00766 
00770   void setDirectory(const QString &dir);
00771 
00785   bool cd( const QString& _dir );
00786 
00801   QString url( AdjustPathOption trailing = LeaveTrailingSlash ) const;
00802 
00815   QString prettyUrl( AdjustPathOption trailing = LeaveTrailingSlash ) const;
00816 
00827   QString pathOrUrl() const;
00833   QString pathOrUrl(AdjustPathOption trailing) const; // KDE5: merge with above. Rename to toUrlOrLocalFile?
00834 
00840   QString toMimeDataString() const;
00841 
00850   KUrl upUrl( ) const;
00851 
00852   KUrl& operator=( const KUrl& _u );
00853 
00854   // Define those, since the constructors are explicit
00855   KUrl& operator=( const char * _url ) { *this = KUrl(_url); return *this; }
00856   KUrl& operator=( const QByteArray& _url ) { *this = KUrl(_url); return *this; }
00857   KUrl& operator=( const QString& _url ) { *this = KUrl(_url); return *this; }
00858 
00859   bool operator==( const KUrl& _u ) const;
00860   bool operator==( const QString& _u ) const;
00861   bool operator!=( const KUrl& _u ) const { return !( *this == _u ); }
00862   bool operator!=( const QString& _u ) const { return !( *this == _u ); }
00863 
00868   operator QVariant() const;
00869 
00881 #ifndef KDE_NO_DEPRECATED
00882   KDE_DEPRECATED bool cmp( const KUrl &u, bool ignore_trailing = false ) const;
00883 #endif
00884 
00885 
00889   enum EqualsOption
00890   {
00901     CompareWithoutTrailingSlash = 0x01,
00905     CompareWithoutFragment = 0x02,
00915     AllowEmptyPath = 0x04
00916   };
00917   Q_DECLARE_FLAGS(EqualsOptions,EqualsOption)
00918 
00919   
00928   bool equals( const KUrl &u, const EqualsOptions& options=0 ) const;
00929 
00936   bool isParentOf( const KUrl& u ) const;
00937     // (this overload of the QUrl method allows to use the implicit KUrl constructors)
00938     // but also the equality test
00939 
00955   static List split( const QString& _url );
00956 
00972   static List split( const KUrl& _url );
00973 
00981   static KUrl join( const List& _list );
00982 
00992   static KUrl fromPath( const QString& text );
00993 
00999 #ifndef KDE_NO_DEPRECATED
01000   static KDE_DEPRECATED KUrl fromPathOrUrl( const QString& text );
01001 #endif
01002 
01008   static KUrl fromMimeDataByteArray( const QByteArray& str );
01009 
01026   void populateMimeData( QMimeData* mimeData,
01027                          const MetaDataMap& metaData = MetaDataMap(),
01028                          MimeDataFlags flags = DefaultMimeDataFlags ) const;
01029 
01040 #ifndef KDE_NO_DEPRECATED
01041   static KDE_DEPRECATED QString encode_string(const QString &str) {
01042     return QString::fromLatin1( QUrl::toPercentEncoding( str ).constData() ); //krazy:exclude=qclasses
01043   }
01044 #endif
01045 
01057 #ifndef KDE_NO_DEPRECATED
01058   static KDE_DEPRECATED QString encode_string_no_slash(const QString &str) {
01059       return QString::fromLatin1( QUrl::toPercentEncoding( str, "/" ).constData() ); //krazy:exclude=qclasses
01060   }
01061 #endif
01062 
01073 #ifndef KDE_NO_DEPRECATED
01074   static KDE_DEPRECATED QString decode_string(const QString &str) {
01075       return QUrl::fromPercentEncoding( str.toLatin1() ); //krazy:exclude=qclasses
01076   }
01077 #endif
01078 
01079 
01099   static bool isRelativeUrl(const QString &_url);
01100 
01115   static QString relativeUrl(const KUrl &base_url, const KUrl &url);
01116 
01126   static QString relativePath(const QString &base_dir, const QString &path, bool *isParent=0);
01127 
01128 private:
01129   void _setQuery( const QString& query );
01130   void _setEncodedUrl(const QByteArray& url);
01131   QString toString() const; // forbidden, use url(), prettyUrl(), or pathOrUrl() instead.
01132   operator QString() const; // forbidden, use url(), prettyUrl(), or pathOrUrl() instead.
01133 private:
01134   KUrlPrivate* const d; // Don't ever use this, it would break clear() (which is in QUrl)
01135 };
01136 
01137 Q_DECLARE_OPERATORS_FOR_FLAGS(KUrl::EncodedPathAndQueryOptions)
01138 Q_DECLARE_OPERATORS_FOR_FLAGS(KUrl::CleanPathOptions)
01139 Q_DECLARE_OPERATORS_FOR_FLAGS(KUrl::QueryItemsOptions)
01140 Q_DECLARE_OPERATORS_FOR_FLAGS(KUrl::EqualsOptions)
01141 Q_DECLARE_OPERATORS_FOR_FLAGS(KUrl::DirectoryOptions)
01142 
01143 Q_DECLARE_METATYPE(KUrl)
01144 Q_DECLARE_METATYPE(KUrl::List)
01145 
01154 #ifndef KDE_NO_DEPRECATED
01155 KDECORE_EXPORT_DEPRECATED bool urlcmp( const QString& _url1, const QString& _url2 ); // KDE5: remove, KUrl::equals is better API
01156 #endif
01157 
01170 #ifndef KDE_NO_DEPRECATED
01171 KDECORE_EXPORT_DEPRECATED bool urlcmp( const QString& _url1, const QString& _url2, const KUrl::EqualsOptions& options ); // KDE5: remove, KUrl::equals is better API
01172 #endif
01173 
01174 KDECORE_EXPORT uint qHash(const KUrl& kurl);
01175 
01176 #endif

KDECore

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • 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
Generated for kdelibs by doxygen 1.7.3
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal