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

KDECore

  • kdecore
  • io
kurl.h
Go to the documentation of this file.
1 // -*- c-basic-offset: 2 -*-
2 /* This file is part of the KDE libraries
3  * Copyright (C) 1999 Torben Weis <weis@kde.org>
4  * Copyright (C) 2005-2006 David Faure <faure@kde.org>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public License
17  * along with this library; see the file COPYING.LIB. If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21 
22 #ifndef kurl_h
23 #define kurl_h
24 
25 #include <kdecore_export.h>
26 
27 #include <QtCore/QVariant>
28 #include <QtCore/QUrl>
29 #include <QtCore/QMap>
30 
31 class QStringList;
32 class QMimeData;
33 
34 class KUrlPrivate;
35 
36 // maybe we should encapsulate QUrl instead of inheriting from it.
37 // this would even allow us to inherit from KUri instead.
38 // and this way hacks like setPath() would be less ugly, and we could avoid
39 // half KDE code using setScheme() and the other half using setProtocol(), etc.
40 // (DF)
41 
111 class KDECORE_EXPORT KUrl : public QUrl // krazy:exclude=dpointer,qclasses (krazy can't deal with embedded classes)
112 {
113 public:
114  typedef QMap<QString, QString> MetaDataMap;
115  enum MimeDataFlags { DefaultMimeDataFlags = 0, NoTextExport = 1 };
116 
120  enum AdjustPathOption
121  {
125  RemoveTrailingSlash,
126 
130  LeaveTrailingSlash,
131 
135  AddTrailingSlash
136  };
137 
146  class KDECORE_EXPORT List : public QList<KUrl> //krazy:exclude=dpointer (just some convenience methods)
147  {
148  public:
152  List() { }
158  List(const KUrl &url);
164  List(const QStringList &list);
169  List(const QList<KUrl> &list);
175  List(const QList<QUrl> &list);
180  QStringList toStringList() const;
181 
191  QStringList toStringList(KUrl::AdjustPathOption trailing) const;
192 
197  operator QVariant() const;
198 
203  operator QList<QUrl>() const;
204 
222  void populateMimeData( QMimeData* mimeData,
223  const KUrl::MetaDataMap& metaData = MetaDataMap(),
224  MimeDataFlags flags = DefaultMimeDataFlags ) const;
225 
260  void populateMimeData(const KUrl::List& mostLocalUrls,
261  QMimeData* mimeData,
262  const KUrl::MetaDataMap& metaData = MetaDataMap(),
263  MimeDataFlags flags = DefaultMimeDataFlags) const;
264 
268  static bool canDecode( const QMimeData *mimeData );
269 
273  static QStringList mimeDataTypes();
274 
283  static KUrl::List fromMimeData( const QMimeData *mimeData, KUrl::MetaDataMap* metaData = 0 );
284 
289  enum DecodeOptions {
296  PreferLocalUrls,
303  PreferKdeUrls
304  };
305 
316  static KUrl::List fromMimeData( const QMimeData *mimeData,
317  DecodeOptions decodeOptions, // TODO KDE5: = PreferKdeUrls, and merge with above
318  KUrl::MetaDataMap* metaData = 0 );
319 
320  };
324  KUrl();
325 
329  ~KUrl();
330 
335  KUrl( const QString& urlOrPath );
342  explicit KUrl( const char * urlOrPath );
349  explicit KUrl( const QByteArray& urlOrPath );
350 
355  KUrl( const KUrl& u );
360  KUrl( const QUrl &u ); //krazy:exclude=qclasses
371  KUrl( const KUrl& _baseurl, const QString& _rel_url );
372 
377  QString protocol() const;
378 
383  void setProtocol( const QString& proto );
384 
389  QString user() const;
390 
397  void setUser( const QString& user );
398 
403  bool hasUser() const;
404 
409  QString pass() const;
410 
421  void setPass( const QString& pass );
422 
427  bool hasPass() const;
428 
433  bool hasHost() const;
434 
441  QString path( AdjustPathOption trailing = LeaveTrailingSlash ) const;
442 
449  QString toLocalFile( AdjustPathOption trailing = LeaveTrailingSlash ) const;
450 
452  void setPath( const QString& path );
453 
458  bool hasPath() const;
459 
463  enum CleanPathOption
464  {
469  SimplifyDirSeparators = 0x00,
470 
474  KeepDirSeparators = 0x01
475  };
476 
477  Q_DECLARE_FLAGS(CleanPathOptions,CleanPathOption)
478 
479 
487  void cleanPath(const CleanPathOption& options = SimplifyDirSeparators);
488 
489 
503  void adjustPath(AdjustPathOption trailing);
504 
510  void setEncodedPathAndQuery( const QString& _txt );
511 
512 #if 0
513 
518  void setEncodedPath(const QString& _txt );
519 #endif
520 
524  enum EncodedPathAndQueryOption
525  {
529  PermitEmptyPath=0x00,
534  AvoidEmptyPath=0x01
535  };
536  Q_DECLARE_FLAGS( EncodedPathAndQueryOptions, EncodedPathAndQueryOption)
537 
538 
546  QString encodedPathAndQuery( AdjustPathOption trailing = LeaveTrailingSlash, const EncodedPathAndQueryOptions &options = PermitEmptyPath ) const;
547 
554  void setQuery( const QString& query );
555 
564  QString query() const;
565 
571  QString ref() const;
572 
578  void setRef( const QString& fragment );
579 
586  bool hasRef() const;
587 
595  QString htmlRef() const;
596 
602  QString encodedHtmlRef() const;
603 
611  void setHTMLRef( const QString& _ref );
612 
618  bool hasHTMLRef() const;
619 
627  bool isLocalFile() const;
628 
635  void setFileEncoding(const QString &encoding);
636 
643  QString fileEncoding() const;
644 
651  bool hasSubUrl() const;
652 
663  void addPath( const QString& txt );
664 
671  enum QueryItemsOption { CaseInsensitiveKeys = 1 };
672  Q_DECLARE_FLAGS(QueryItemsOptions,QueryItemsOption)
673 
674 
686  QMap< QString, QString > queryItems( const QueryItemsOptions& options = 0 ) const;
687  // #### TODO port the above queryItems to look more like QUrl's
688  //using QUrl::queryItems; // temporary
689 
701  QString queryItem(const QString &item) const;
702 
711  void addQueryItem( const QString& _item, const QString& _value );
712 
713 
727  void setFileName( const QString&_txt );
728 
732  enum DirectoryOption
733  {
743  ObeyTrailingSlash = 0x02,
752  AppendTrailingSlash = 0x04,
757  IgnoreTrailingSlash = 0x01
758 
759  };
760  Q_DECLARE_FLAGS(DirectoryOptions,DirectoryOption)
761 
762 
763 
769  QString fileName( const DirectoryOptions& options = IgnoreTrailingSlash ) const;
770 
779  QString directory( const DirectoryOptions& options = IgnoreTrailingSlash ) const;
780 
784  void setDirectory(const QString &dir);
785 
799  bool cd( const QString& _dir );
800 
815  QString url( AdjustPathOption trailing = LeaveTrailingSlash ) const;
816 
829  QString prettyUrl( AdjustPathOption trailing = LeaveTrailingSlash ) const;
830 
841  QString pathOrUrl() const;
847  QString pathOrUrl(AdjustPathOption trailing) const; // KDE5: merge with above. Rename to toUrlOrLocalFile?
848 
854  QString toMimeDataString() const;
855 
864  KUrl upUrl( ) const;
865 
866  KUrl& operator=( const KUrl& _u );
867 
868  // Define those, since the constructors are explicit
869  KUrl& operator=( const char * _url ) { *this = KUrl(_url); return *this; }
870  KUrl& operator=( const QByteArray& _url ) { *this = KUrl(_url); return *this; }
871  KUrl& operator=( const QString& _url ) { *this = KUrl(_url); return *this; }
872 
873  bool operator==( const KUrl& _u ) const;
874  bool operator==( const QString& _u ) const;
875  bool operator!=( const KUrl& _u ) const { return !( *this == _u ); }
876  bool operator!=( const QString& _u ) const { return !( *this == _u ); }
877 
882  operator QVariant() const;
883 
895 #ifndef KDE_NO_DEPRECATED
896  KDE_DEPRECATED bool cmp( const KUrl &u, bool ignore_trailing = false ) const;
897 #endif
898 
899 
903  enum EqualsOption
904  {
915  CompareWithoutTrailingSlash = 0x01,
919  CompareWithoutFragment = 0x02,
929  AllowEmptyPath = 0x04
930  };
931  Q_DECLARE_FLAGS(EqualsOptions,EqualsOption)
932 
933 
942  bool equals( const KUrl &u, const EqualsOptions& options=0 ) const;
943 
950  bool isParentOf( const KUrl& u ) const;
951  // (this overload of the QUrl method allows to use the implicit KUrl constructors)
952  // but also the equality test
953 
969  static List split( const QString& _url );
970 
986  static List split( const KUrl& _url );
987 
995  static KUrl join( const List& _list );
996 
1006  static KUrl fromPath( const QString& text );
1007 
1013 #ifndef KDE_NO_DEPRECATED
1014  static KDE_DEPRECATED KUrl fromPathOrUrl( const QString& text );
1015 #endif
1016 
1022  static KUrl fromMimeDataByteArray( const QByteArray& str );
1023 
1040  void populateMimeData( QMimeData* mimeData,
1041  const MetaDataMap& metaData = MetaDataMap(),
1042  MimeDataFlags flags = DefaultMimeDataFlags ) const;
1043 
1054 #ifndef KDE_NO_DEPRECATED
1055  static KDE_DEPRECATED QString encode_string(const QString &str) {
1056  return QString::fromLatin1( QUrl::toPercentEncoding( str ).constData() ); //krazy:exclude=qclasses
1057  }
1058 #endif
1059 
1071 #ifndef KDE_NO_DEPRECATED
1072  static KDE_DEPRECATED QString encode_string_no_slash(const QString &str) {
1073  return QString::fromLatin1( QUrl::toPercentEncoding( str, "/" ).constData() ); //krazy:exclude=qclasses
1074  }
1075 #endif
1076 
1087 #ifndef KDE_NO_DEPRECATED
1088  static KDE_DEPRECATED QString decode_string(const QString &str) {
1089  return QUrl::fromPercentEncoding( str.toLatin1() ); //krazy:exclude=qclasses
1090  }
1091 #endif
1092 
1093 
1113  static bool isRelativeUrl(const QString &_url);
1114 
1129  static QString relativeUrl(const KUrl &base_url, const KUrl &url);
1130 
1140  static QString relativePath(const QString &base_dir, const QString &path, bool *isParent=0);
1141 
1142 private:
1143  void _setQuery( const QString& query );
1144  void _setEncodedUrl(const QByteArray& url);
1145  QString toString() const; // forbidden, use url(), prettyUrl(), or pathOrUrl() instead.
1146  operator QString() const; // forbidden, use url(), prettyUrl(), or pathOrUrl() instead.
1147 private:
1148  KUrlPrivate* const d; // Don't ever use this, it would break clear() (which is in QUrl)
1149 };
1150 
1151 Q_DECLARE_OPERATORS_FOR_FLAGS(KUrl::EncodedPathAndQueryOptions)
1152 Q_DECLARE_OPERATORS_FOR_FLAGS(KUrl::CleanPathOptions)
1153 Q_DECLARE_OPERATORS_FOR_FLAGS(KUrl::QueryItemsOptions)
1154 Q_DECLARE_OPERATORS_FOR_FLAGS(KUrl::EqualsOptions)
1155 Q_DECLARE_OPERATORS_FOR_FLAGS(KUrl::DirectoryOptions)
1156 
1157 Q_DECLARE_METATYPE(KUrl)
1158 Q_DECLARE_METATYPE(KUrl::List)
1159 
1168 #ifndef KDE_NO_DEPRECATED
1169 KDECORE_EXPORT_DEPRECATED bool urlcmp( const QString& _url1, const QString& _url2 ); // KDE5: remove, KUrl::equals is better API
1170 #endif
1171 
1184 #ifndef KDE_NO_DEPRECATED
1185 KDECORE_EXPORT_DEPRECATED bool urlcmp( const QString& _url1, const QString& _url2, const KUrl::EqualsOptions& options ); // KDE5: remove, KUrl::equals is better API
1186 #endif
1187 
1188 KDECORE_EXPORT uint qHash(const KUrl& kurl);
1189 
1190 #endif
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Tue Jul 23 2013 20:27:57 by doxygen 1.8.1.1 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.10.5 API Reference

Skip menu "kdelibs-4.10.5 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