• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • 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 (krazy can't deal with embedded classes)
00112 {
00113 public:
00114   typedef QMap<QString, QString> MetaDataMap;
00115   enum MimeDataFlags { DefaultMimeDataFlags = 0, NoTextExport = 1 };
00116 
00125   class KDECORE_EXPORT List : public QList<KUrl> //krazy:exclude=dpointer (just some convenience methods)
00126   {
00127   public:
00131       List() { }
00137       List(const KUrl &url);
00143       List(const QStringList &list);
00148       List(const QList<KUrl> &list);
00153       QStringList toStringList() const;
00154 
00159       operator QVariant() const;
00160 
00178       void populateMimeData( QMimeData* mimeData,
00179                              const KUrl::MetaDataMap& metaData = MetaDataMap(),
00180                              MimeDataFlags flags = DefaultMimeDataFlags ) const;
00181 
00185       static bool canDecode( const QMimeData *mimeData );
00186 
00190       static QStringList mimeDataTypes();
00191 
00200       static KUrl::List fromMimeData( const QMimeData *mimeData, KUrl::MetaDataMap* metaData = 0 );
00201 
00202   };
00206   KUrl();
00207 
00211   ~KUrl();
00212 
00217   KUrl( const QString& urlOrPath );
00224   explicit KUrl( const char * urlOrPath );
00231   explicit KUrl( const QByteArray& urlOrPath );
00232 
00237   KUrl( const KUrl& u );
00242   KUrl( const QUrl &u );
00253   KUrl( const KUrl& _baseurl, const QString& _rel_url );
00254 
00259   QString protocol() const;
00260 
00265   void setProtocol( const QString& proto );
00266 
00271   QString user() const;
00272 
00279   void setUser( const QString& user );
00280 
00285   bool hasUser() const;
00286 
00291   QString pass() const;
00292 
00303   void setPass( const QString& pass );
00304 
00309   bool hasPass() const;
00310 
00315   bool hasHost() const;
00316 
00320   enum AdjustPathOption
00321   {
00325     RemoveTrailingSlash,
00326 
00330     LeaveTrailingSlash,
00331 
00335     AddTrailingSlash
00336   };
00337 
00344   QString path( AdjustPathOption trailing = LeaveTrailingSlash ) const;
00345 
00352   QString toLocalFile( AdjustPathOption trailing = LeaveTrailingSlash ) const;
00353 
00355   void setPath( const QString& path );
00356 
00361   bool hasPath() const;
00362 
00366   enum CleanPathOption
00367   {
00372     SimplifyDirSeparators = 0x00,
00373 
00377     KeepDirSeparators = 0x01
00378   };
00379 
00380   Q_DECLARE_FLAGS(CleanPathOptions,CleanPathOption)
00381 
00382   
00390   void cleanPath(const CleanPathOption& options = SimplifyDirSeparators);
00391 
00392 
00406   void adjustPath(AdjustPathOption trailing);
00407 
00413   void setEncodedPathAndQuery( const QString& _txt );
00414 
00415 #if 0
00416 
00421   void setEncodedPath(const QString& _txt );
00422 #endif
00423 
00427   enum EncodedPathAndQueryOption
00428   {
00432     PermitEmptyPath=0x00,
00437     AvoidEmptyPath=0x01
00438   };
00439   Q_DECLARE_FLAGS( EncodedPathAndQueryOptions, EncodedPathAndQueryOption)
00440 
00441   
00449   QString encodedPathAndQuery( AdjustPathOption trailing = LeaveTrailingSlash, const EncodedPathAndQueryOptions &options = PermitEmptyPath ) const;
00450 
00457   void setQuery( const QString& query );
00458 
00467   QString query() const;
00468 
00473   QString ref() const;
00474 
00480   void setRef( const QString& fragment );
00481 
00488   bool hasRef() const;
00489 
00497   QString htmlRef() const;
00498 
00504   QString encodedHtmlRef() const;
00505 
00513   void setHTMLRef( const QString& _ref );
00514 
00520   bool hasHTMLRef() const;
00521 
00527   bool isLocalFile() const;
00528 
00535   void setFileEncoding(const QString &encoding);
00536 
00543   QString fileEncoding() const;
00544 
00551   bool hasSubUrl() const;
00552 
00563   void addPath( const QString& txt );
00564 
00571   enum QueryItemsOption { CaseInsensitiveKeys = 1 };
00572   Q_DECLARE_FLAGS(QueryItemsOptions,QueryItemsOption)
00573 
00574   
00586   QMap< QString, QString > queryItems( const QueryItemsOptions& options = 0 ) const;
00587   // #### TODO port the above queryItems to look more like QUrl's
00588   //using QUrl::queryItems; // temporary
00589 
00601   QString queryItem(const QString &item) const;
00602 
00611   void addQueryItem( const QString& _item, const QString& _value );
00612 
00613 
00627   void setFileName( const QString&_txt );
00628 
00632   enum DirectoryOption
00633   {
00643     ObeyTrailingSlash = 0x02,
00652     AppendTrailingSlash = 0x04,
00656     IgnoreTrailingSlash = 0x01
00657 
00658   };
00659   Q_DECLARE_FLAGS(DirectoryOptions,DirectoryOption)
00660 
00661 
00662   
00668   QString fileName( const DirectoryOptions& options = IgnoreTrailingSlash ) const;
00669 
00678   QString directory( const DirectoryOptions& options = IgnoreTrailingSlash ) const;
00679 
00683   void setDirectory(const QString &dir);
00684 
00698   bool cd( const QString& _dir );
00699 
00714   QString url( AdjustPathOption trailing = LeaveTrailingSlash ) const;
00715 
00728   QString prettyUrl( AdjustPathOption trailing = LeaveTrailingSlash ) const;
00729 
00740   QString pathOrUrl() const;
00741 
00747   QString toMimeDataString() const;
00748 
00757   KUrl upUrl( ) const;
00758 
00759   KUrl& operator=( const KUrl& _u );
00760 
00761   // Define those, since the constructors are explicit
00762   KUrl& operator=( const char * _url ) { *this = KUrl(_url); return *this; }
00763   KUrl& operator=( const QByteArray& _url ) { *this = KUrl(_url); return *this; }
00764   KUrl& operator=( const QString& _url ) { *this = KUrl(_url); return *this; }
00765 
00766   bool operator==( const KUrl& _u ) const;
00767   bool operator==( const QString& _u ) const;
00768   bool operator!=( const KUrl& _u ) const { return !( *this == _u ); }
00769   bool operator!=( const QString& _u ) const { return !( *this == _u ); }
00770 
00775   operator QVariant() const;
00776 
00788   KDE_DEPRECATED bool cmp( const KUrl &u, bool ignore_trailing = false ) const;
00789 
00790 
00794   enum EqualsOption
00795   {
00799     CompareWithoutTrailingSlash = 0x01,
00803     CompareWithoutFragment = 0x02
00804   };
00805   Q_DECLARE_FLAGS(EqualsOptions,EqualsOption)
00806 
00807   
00816   bool equals( const KUrl &u, const EqualsOptions& options=0 ) const;
00817 
00824   bool isParentOf( const KUrl& u ) const;
00825     // (this overload of the QUrl method allows to use the implicit KUrl constructors)
00826     // but also the equality test
00827 
00843   static List split( const QString& _url );
00844 
00860   static List split( const KUrl& _url );
00861 
00869   static KUrl join( const List& _list );
00870 
00879   static KUrl fromPath( const QString& text );
00880 
00886   static KDE_DEPRECATED KUrl fromPathOrUrl( const QString& text );
00887 
00893   static KUrl fromMimeDataByteArray( const QByteArray& str );
00894 
00911   void populateMimeData( QMimeData* mimeData,
00912                          const MetaDataMap& metaData = MetaDataMap(),
00913                          MimeDataFlags flags = DefaultMimeDataFlags ) const;
00914 
00925   static KDE_DEPRECATED QString encode_string(const QString &str) {
00926       return QLatin1String( QUrl::toPercentEncoding( str ) );
00927   }
00928 
00940   static KDE_DEPRECATED QString encode_string_no_slash(const QString &str) {
00941       return QString::fromLatin1( QUrl::toPercentEncoding( str, "/" ) );
00942   }
00943 
00954   static KDE_DEPRECATED QString decode_string(const QString &str) {
00955       return QUrl::fromPercentEncoding( str.toLatin1() );
00956   }
00957 
00958 
00967   static bool isRelativeUrl(const QString &_url);
00968 
00983   static QString relativeUrl(const KUrl &base_url, const KUrl &url);
00984 
00994   static QString relativePath(const QString &base_dir, const QString &path, bool *isParent=0);
00995 
00996 private:
00997   void _setQuery( const QString& query );
00998   void _setEncodedUrl(const QByteArray& url);
00999   QString toString() const; // forbidden, use url(), prettyUrl(), or pathOrUrl() instead.
01000   operator QString() const; // forbidden, use url(), prettyUrl(), or pathOrUrl() instead.
01001 private:
01002   KUrlPrivate* const d;
01003 };
01004 
01005 Q_DECLARE_OPERATORS_FOR_FLAGS(KUrl::EncodedPathAndQueryOptions)
01006 Q_DECLARE_OPERATORS_FOR_FLAGS(KUrl::CleanPathOptions)
01007 Q_DECLARE_OPERATORS_FOR_FLAGS(KUrl::QueryItemsOptions)
01008 Q_DECLARE_OPERATORS_FOR_FLAGS(KUrl::EqualsOptions)
01009 Q_DECLARE_OPERATORS_FOR_FLAGS(KUrl::DirectoryOptions)
01010 
01011 Q_DECLARE_METATYPE(KUrl)
01012 Q_DECLARE_METATYPE(KUrl::List)
01013 
01021 KDECORE_EXPORT bool urlcmp( const QString& _url1, const QString& _url2 );
01022 
01034 KDECORE_EXPORT bool urlcmp( const QString& _url1, const QString& _url2, const KUrl::EqualsOptions& options );
01035 
01036 /*
01037  * MSVC needs it.
01038  */
01039 Q_CORE_EXPORT uint qHash(const QString &key);
01040 inline uint qHash(const KUrl& kurl){ return qHash(kurl.url()); }
01041 
01042 #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
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
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