• Skip to content
  • Skip to link menu
KDE 4.3 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,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 
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 
00216       void populateMimeData(const KUrl::List& mostLocalUrls,
00217                             QMimeData* mimeData,
00218                             const KUrl::MetaDataMap& metaData = MetaDataMap(),
00219                             MimeDataFlags flags = DefaultMimeDataFlags) const;
00220 
00224       static bool canDecode( const QMimeData *mimeData );
00225 
00229       static QStringList mimeDataTypes();
00230 
00239       static KUrl::List fromMimeData( const QMimeData *mimeData, KUrl::MetaDataMap* metaData = 0 );
00240 
00245       enum DecodeOptions {
00252         PreferLocalUrls,
00259         PreferKdeUrls
00260       };
00261 
00272       static KUrl::List fromMimeData( const QMimeData *mimeData,
00273                                       DecodeOptions decodeOptions, // TODO KDE5: = PreferKdeUrls, and merge with above
00274                                       KUrl::MetaDataMap* metaData = 0 );
00275 
00276   };
00280   KUrl();
00281 
00285   ~KUrl();
00286 
00291   KUrl( const QString& urlOrPath );
00298   explicit KUrl( const char * urlOrPath );
00305   explicit KUrl( const QByteArray& urlOrPath );
00306 
00311   KUrl( const KUrl& u );
00316   KUrl( const QUrl &u ); //krazy:exclude=qclasses
00327   KUrl( const KUrl& _baseurl, const QString& _rel_url );
00328 
00333   QString protocol() const;
00334 
00339   void setProtocol( const QString& proto );
00340 
00345   QString user() const;
00346 
00353   void setUser( const QString& user );
00354 
00359   bool hasUser() const;
00360 
00365   QString pass() const;
00366 
00377   void setPass( const QString& pass );
00378 
00383   bool hasPass() const;
00384 
00389   bool hasHost() const;
00390 
00394   enum AdjustPathOption
00395   {
00399     RemoveTrailingSlash,
00400 
00404     LeaveTrailingSlash,
00405 
00409     AddTrailingSlash
00410   };
00411 
00418   QString path( AdjustPathOption trailing = LeaveTrailingSlash ) const;
00419 
00426   QString toLocalFile( AdjustPathOption trailing = LeaveTrailingSlash ) const;
00427 
00429   void setPath( const QString& path );
00430 
00435   bool hasPath() const;
00436 
00440   enum CleanPathOption
00441   {
00446     SimplifyDirSeparators = 0x00,
00447 
00451     KeepDirSeparators = 0x01
00452   };
00453 
00454   Q_DECLARE_FLAGS(CleanPathOptions,CleanPathOption)
00455 
00456   
00464   void cleanPath(const CleanPathOption& options = SimplifyDirSeparators);
00465 
00466 
00480   void adjustPath(AdjustPathOption trailing);
00481 
00487   void setEncodedPathAndQuery( const QString& _txt );
00488 
00489 #if 0
00490 
00495   void setEncodedPath(const QString& _txt );
00496 #endif
00497 
00501   enum EncodedPathAndQueryOption
00502   {
00506     PermitEmptyPath=0x00,
00511     AvoidEmptyPath=0x01
00512   };
00513   Q_DECLARE_FLAGS( EncodedPathAndQueryOptions, EncodedPathAndQueryOption)
00514 
00515   
00523   QString encodedPathAndQuery( AdjustPathOption trailing = LeaveTrailingSlash, const EncodedPathAndQueryOptions &options = PermitEmptyPath ) const;
00524 
00531   void setQuery( const QString& query );
00532 
00541   QString query() const;
00542 
00547   QString ref() const;
00548 
00554   void setRef( const QString& fragment );
00555 
00562   bool hasRef() const;
00563 
00571   QString htmlRef() const;
00572 
00578   QString encodedHtmlRef() const;
00579 
00587   void setHTMLRef( const QString& _ref );
00588 
00594   bool hasHTMLRef() const;
00595 
00601   bool isLocalFile() const;
00602 
00609   void setFileEncoding(const QString &encoding);
00610 
00617   QString fileEncoding() const;
00618 
00625   bool hasSubUrl() const;
00626 
00637   void addPath( const QString& txt );
00638 
00645   enum QueryItemsOption { CaseInsensitiveKeys = 1 };
00646   Q_DECLARE_FLAGS(QueryItemsOptions,QueryItemsOption)
00647 
00648   
00660   QMap< QString, QString > queryItems( const QueryItemsOptions& options = 0 ) const;
00661   // #### TODO port the above queryItems to look more like QUrl's
00662   //using QUrl::queryItems; // temporary
00663 
00675   QString queryItem(const QString &item) const;
00676 
00685   void addQueryItem( const QString& _item, const QString& _value );
00686 
00687 
00701   void setFileName( const QString&_txt );
00702 
00706   enum DirectoryOption
00707   {
00717     ObeyTrailingSlash = 0x02,
00726     AppendTrailingSlash = 0x04,
00731     IgnoreTrailingSlash = 0x01
00732 
00733   };
00734   Q_DECLARE_FLAGS(DirectoryOptions,DirectoryOption)
00735 
00736 
00737   
00743   QString fileName( const DirectoryOptions& options = IgnoreTrailingSlash ) const;
00744 
00753   QString directory( const DirectoryOptions& options = IgnoreTrailingSlash ) const;
00754 
00758   void setDirectory(const QString &dir);
00759 
00773   bool cd( const QString& _dir );
00774 
00789   QString url( AdjustPathOption trailing = LeaveTrailingSlash ) const;
00790 
00803   QString prettyUrl( AdjustPathOption trailing = LeaveTrailingSlash ) const;
00804 
00815   QString pathOrUrl() const;
00821   QString pathOrUrl(AdjustPathOption trailing) const; // KDE5: merge with above
00822 
00828   QString toMimeDataString() const;
00829 
00838   KUrl upUrl( ) const;
00839 
00840   KUrl& operator=( const KUrl& _u );
00841 
00842   // Define those, since the constructors are explicit
00843   KUrl& operator=( const char * _url ) { *this = KUrl(_url); return *this; }
00844   KUrl& operator=( const QByteArray& _url ) { *this = KUrl(_url); return *this; }
00845   KUrl& operator=( const QString& _url ) { *this = KUrl(_url); return *this; }
00846 
00847   bool operator==( const KUrl& _u ) const;
00848   bool operator==( const QString& _u ) const;
00849   bool operator!=( const KUrl& _u ) const { return !( *this == _u ); }
00850   bool operator!=( const QString& _u ) const { return !( *this == _u ); }
00851 
00856   operator QVariant() const;
00857 
00869   KDE_DEPRECATED bool cmp( const KUrl &u, bool ignore_trailing = false ) const;
00870 
00871 
00875   enum EqualsOption
00876   {
00880     CompareWithoutTrailingSlash = 0x01,
00884     CompareWithoutFragment = 0x02
00885   };
00886   Q_DECLARE_FLAGS(EqualsOptions,EqualsOption)
00887 
00888   
00897   bool equals( const KUrl &u, const EqualsOptions& options=0 ) const;
00898 
00905   bool isParentOf( const KUrl& u ) const;
00906     // (this overload of the QUrl method allows to use the implicit KUrl constructors)
00907     // but also the equality test
00908 
00924   static List split( const QString& _url );
00925 
00941   static List split( const KUrl& _url );
00942 
00950   static KUrl join( const List& _list );
00951 
00960   static KUrl fromPath( const QString& text );
00961 
00967   static KDE_DEPRECATED KUrl fromPathOrUrl( const QString& text );
00968 
00974   static KUrl fromMimeDataByteArray( const QByteArray& str );
00975 
00992   void populateMimeData( QMimeData* mimeData,
00993                          const MetaDataMap& metaData = MetaDataMap(),
00994                          MimeDataFlags flags = DefaultMimeDataFlags ) const;
00995 
01006   static KDE_DEPRECATED QString encode_string(const QString &str) {
01007       return QLatin1String( QUrl::toPercentEncoding( str ) ); //krazy:exclude=qclasses
01008   }
01009 
01021   static KDE_DEPRECATED QString encode_string_no_slash(const QString &str) {
01022       return QString::fromLatin1( QUrl::toPercentEncoding( str, "/" ) ); //krazy:exclude=qclasses
01023   }
01024 
01035   static KDE_DEPRECATED QString decode_string(const QString &str) {
01036       return QUrl::fromPercentEncoding( str.toLatin1() ); //krazy:exclude=qclasses
01037   }
01038 
01039 
01059   static bool isRelativeUrl(const QString &_url);
01060 
01075   static QString relativeUrl(const KUrl &base_url, const KUrl &url);
01076 
01086   static QString relativePath(const QString &base_dir, const QString &path, bool *isParent=0);
01087 
01088 private:
01089   void _setQuery( const QString& query );
01090   void _setEncodedUrl(const QByteArray& url);
01091   QString toString() const; // forbidden, use url(), prettyUrl(), or pathOrUrl() instead.
01092   operator QString() const; // forbidden, use url(), prettyUrl(), or pathOrUrl() instead.
01093 private:
01094   KUrlPrivate* const d;
01095 };
01096 
01097 Q_DECLARE_OPERATORS_FOR_FLAGS(KUrl::EncodedPathAndQueryOptions)
01098 Q_DECLARE_OPERATORS_FOR_FLAGS(KUrl::CleanPathOptions)
01099 Q_DECLARE_OPERATORS_FOR_FLAGS(KUrl::QueryItemsOptions)
01100 Q_DECLARE_OPERATORS_FOR_FLAGS(KUrl::EqualsOptions)
01101 Q_DECLARE_OPERATORS_FOR_FLAGS(KUrl::DirectoryOptions)
01102 
01103 Q_DECLARE_METATYPE(KUrl)
01104 Q_DECLARE_METATYPE(KUrl::List)
01105 
01113 KDECORE_EXPORT bool urlcmp( const QString& _url1, const QString& _url2 );
01114 
01126 KDECORE_EXPORT bool urlcmp( const QString& _url1, const QString& _url2, const KUrl::EqualsOptions& options );
01127 
01128 KDECORE_EXPORT uint qHash(const KUrl& kurl);
01129 
01130 #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
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
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