• Skip to content
  • Skip to link menu
KDE 4.2 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 
00241   };
00245   KUrl();
00246 
00250   ~KUrl();
00251 
00256   KUrl( const QString& urlOrPath );
00263   explicit KUrl( const char * urlOrPath );
00270   explicit KUrl( const QByteArray& urlOrPath );
00271 
00276   KUrl( const KUrl& u );
00281   KUrl( const QUrl &u ); //krazy:exclude=qclasses
00292   KUrl( const KUrl& _baseurl, const QString& _rel_url );
00293 
00298   QString protocol() const;
00299 
00304   void setProtocol( const QString& proto );
00305 
00310   QString user() const;
00311 
00318   void setUser( const QString& user );
00319 
00324   bool hasUser() const;
00325 
00330   QString pass() const;
00331 
00342   void setPass( const QString& pass );
00343 
00348   bool hasPass() const;
00349 
00354   bool hasHost() const;
00355 
00359   enum AdjustPathOption
00360   {
00364     RemoveTrailingSlash,
00365 
00369     LeaveTrailingSlash,
00370 
00374     AddTrailingSlash
00375   };
00376 
00383   QString path( AdjustPathOption trailing = LeaveTrailingSlash ) const;
00384 
00391   QString toLocalFile( AdjustPathOption trailing = LeaveTrailingSlash ) const;
00392 
00394   void setPath( const QString& path );
00395 
00400   bool hasPath() const;
00401 
00405   enum CleanPathOption
00406   {
00411     SimplifyDirSeparators = 0x00,
00412 
00416     KeepDirSeparators = 0x01
00417   };
00418 
00419   Q_DECLARE_FLAGS(CleanPathOptions,CleanPathOption)
00420 
00421   
00429   void cleanPath(const CleanPathOption& options = SimplifyDirSeparators);
00430 
00431 
00445   void adjustPath(AdjustPathOption trailing);
00446 
00452   void setEncodedPathAndQuery( const QString& _txt );
00453 
00454 #if 0
00455 
00460   void setEncodedPath(const QString& _txt );
00461 #endif
00462 
00466   enum EncodedPathAndQueryOption
00467   {
00471     PermitEmptyPath=0x00,
00476     AvoidEmptyPath=0x01
00477   };
00478   Q_DECLARE_FLAGS( EncodedPathAndQueryOptions, EncodedPathAndQueryOption)
00479 
00480   
00488   QString encodedPathAndQuery( AdjustPathOption trailing = LeaveTrailingSlash, const EncodedPathAndQueryOptions &options = PermitEmptyPath ) const;
00489 
00496   void setQuery( const QString& query );
00497 
00506   QString query() const;
00507 
00512   QString ref() const;
00513 
00519   void setRef( const QString& fragment );
00520 
00527   bool hasRef() const;
00528 
00536   QString htmlRef() const;
00537 
00543   QString encodedHtmlRef() const;
00544 
00552   void setHTMLRef( const QString& _ref );
00553 
00559   bool hasHTMLRef() const;
00560 
00566   bool isLocalFile() const;
00567 
00574   void setFileEncoding(const QString &encoding);
00575 
00582   QString fileEncoding() const;
00583 
00590   bool hasSubUrl() const;
00591 
00602   void addPath( const QString& txt );
00603 
00610   enum QueryItemsOption { CaseInsensitiveKeys = 1 };
00611   Q_DECLARE_FLAGS(QueryItemsOptions,QueryItemsOption)
00612 
00613   
00625   QMap< QString, QString > queryItems( const QueryItemsOptions& options = 0 ) const;
00626   // #### TODO port the above queryItems to look more like QUrl's
00627   //using QUrl::queryItems; // temporary
00628 
00640   QString queryItem(const QString &item) const;
00641 
00650   void addQueryItem( const QString& _item, const QString& _value );
00651 
00652 
00666   void setFileName( const QString&_txt );
00667 
00671   enum DirectoryOption
00672   {
00682     ObeyTrailingSlash = 0x02,
00691     AppendTrailingSlash = 0x04,
00696     IgnoreTrailingSlash = 0x01
00697 
00698   };
00699   Q_DECLARE_FLAGS(DirectoryOptions,DirectoryOption)
00700 
00701 
00702   
00708   QString fileName( const DirectoryOptions& options = IgnoreTrailingSlash ) const;
00709 
00718   QString directory( const DirectoryOptions& options = IgnoreTrailingSlash ) const;
00719 
00723   void setDirectory(const QString &dir);
00724 
00738   bool cd( const QString& _dir );
00739 
00754   QString url( AdjustPathOption trailing = LeaveTrailingSlash ) const;
00755 
00768   QString prettyUrl( AdjustPathOption trailing = LeaveTrailingSlash ) const;
00769 
00780   QString pathOrUrl() const;
00786   QString pathOrUrl(AdjustPathOption trailing) const; // KDE5: merge with above
00787 
00793   QString toMimeDataString() const;
00794 
00803   KUrl upUrl( ) const;
00804 
00805   KUrl& operator=( const KUrl& _u );
00806 
00807   // Define those, since the constructors are explicit
00808   KUrl& operator=( const char * _url ) { *this = KUrl(_url); return *this; }
00809   KUrl& operator=( const QByteArray& _url ) { *this = KUrl(_url); return *this; }
00810   KUrl& operator=( const QString& _url ) { *this = KUrl(_url); return *this; }
00811 
00812   bool operator==( const KUrl& _u ) const;
00813   bool operator==( const QString& _u ) const;
00814   bool operator!=( const KUrl& _u ) const { return !( *this == _u ); }
00815   bool operator!=( const QString& _u ) const { return !( *this == _u ); }
00816 
00821   operator QVariant() const;
00822 
00834   KDE_DEPRECATED bool cmp( const KUrl &u, bool ignore_trailing = false ) const;
00835 
00836 
00840   enum EqualsOption
00841   {
00845     CompareWithoutTrailingSlash = 0x01,
00849     CompareWithoutFragment = 0x02
00850   };
00851   Q_DECLARE_FLAGS(EqualsOptions,EqualsOption)
00852 
00853   
00862   bool equals( const KUrl &u, const EqualsOptions& options=0 ) const;
00863 
00870   bool isParentOf( const KUrl& u ) const;
00871     // (this overload of the QUrl method allows to use the implicit KUrl constructors)
00872     // but also the equality test
00873 
00889   static List split( const QString& _url );
00890 
00906   static List split( const KUrl& _url );
00907 
00915   static KUrl join( const List& _list );
00916 
00925   static KUrl fromPath( const QString& text );
00926 
00932   static KDE_DEPRECATED KUrl fromPathOrUrl( const QString& text );
00933 
00939   static KUrl fromMimeDataByteArray( const QByteArray& str );
00940 
00957   void populateMimeData( QMimeData* mimeData,
00958                          const MetaDataMap& metaData = MetaDataMap(),
00959                          MimeDataFlags flags = DefaultMimeDataFlags ) const;
00960 
00971   static KDE_DEPRECATED QString encode_string(const QString &str) {
00972       return QLatin1String( QUrl::toPercentEncoding( str ) ); //krazy:exclude=qclasses
00973   }
00974 
00986   static KDE_DEPRECATED QString encode_string_no_slash(const QString &str) {
00987       return QString::fromLatin1( QUrl::toPercentEncoding( str, "/" ) ); //krazy:exclude=qclasses
00988   }
00989 
01000   static KDE_DEPRECATED QString decode_string(const QString &str) {
01001       return QUrl::fromPercentEncoding( str.toLatin1() ); //krazy:exclude=qclasses
01002   }
01003 
01004 
01013   static bool isRelativeUrl(const QString &_url);
01014 
01029   static QString relativeUrl(const KUrl &base_url, const KUrl &url);
01030 
01040   static QString relativePath(const QString &base_dir, const QString &path, bool *isParent=0);
01041 
01042 private:
01043   void _setQuery( const QString& query );
01044   void _setEncodedUrl(const QByteArray& url);
01045   QString toString() const; // forbidden, use url(), prettyUrl(), or pathOrUrl() instead.
01046   operator QString() const; // forbidden, use url(), prettyUrl(), or pathOrUrl() instead.
01047 private:
01048   KUrlPrivate* const d;
01049 };
01050 
01051 Q_DECLARE_OPERATORS_FOR_FLAGS(KUrl::EncodedPathAndQueryOptions)
01052 Q_DECLARE_OPERATORS_FOR_FLAGS(KUrl::CleanPathOptions)
01053 Q_DECLARE_OPERATORS_FOR_FLAGS(KUrl::QueryItemsOptions)
01054 Q_DECLARE_OPERATORS_FOR_FLAGS(KUrl::EqualsOptions)
01055 Q_DECLARE_OPERATORS_FOR_FLAGS(KUrl::DirectoryOptions)
01056 
01057 Q_DECLARE_METATYPE(KUrl)
01058 Q_DECLARE_METATYPE(KUrl::List)
01059 
01067 KDECORE_EXPORT bool urlcmp( const QString& _url1, const QString& _url2 );
01068 
01080 KDECORE_EXPORT bool urlcmp( const QString& _url1, const QString& _url2, const KUrl::EqualsOptions& options );
01081 
01082 KDECORE_EXPORT uint qHash(const KUrl& kurl);
01083 
01084 #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
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
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