• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 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
31class QStringList;
32class QMimeData;
33
34class 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
111class KDECORE_EXPORT KUrl : public QUrl // krazy:exclude=dpointer,qclasses (krazy can't deal with embedded classes)
112{
113public:
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
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
596 QString htmlRef() const;
597
604 QString encodedHtmlRef() const;
605
613 void setHTMLRef( const QString& _ref );
614
620 bool hasHTMLRef() const;
621
629 bool isLocalFile() const;
630
637 void setFileEncoding(const QString &encoding);
638
645 QString fileEncoding() const;
646
653 bool hasSubUrl() const;
654
665 void addPath( const QString& txt );
666
673 enum QueryItemsOption { CaseInsensitiveKeys = 1 };
674 Q_DECLARE_FLAGS(QueryItemsOptions,QueryItemsOption)
675
676
688 QMap< QString, QString > queryItems( const QueryItemsOptions& options = 0 ) const;
689 // #### TODO port the above queryItems to look more like QUrl's
690 //using QUrl::queryItems; // temporary
691
703 QString queryItem(const QString &item) const;
704
713 void addQueryItem( const QString& _item, const QString& _value );
714
715
729 void setFileName( const QString&_txt );
730
734 enum DirectoryOption
735 {
745 ObeyTrailingSlash = 0x02,
754 AppendTrailingSlash = 0x04,
759 IgnoreTrailingSlash = 0x01
760
761 };
762 Q_DECLARE_FLAGS(DirectoryOptions,DirectoryOption)
763
764
765
771 QString fileName( const DirectoryOptions& options = IgnoreTrailingSlash ) const;
772
781 QString directory( const DirectoryOptions& options = IgnoreTrailingSlash ) const;
782
786 void setDirectory(const QString &dir);
787
801 bool cd( const QString& _dir );
802
817 QString url( AdjustPathOption trailing = LeaveTrailingSlash ) const;
818
831 QString prettyUrl( AdjustPathOption trailing = LeaveTrailingSlash ) const;
832
843 QString pathOrUrl() const;
849 QString pathOrUrl(AdjustPathOption trailing) const; // KDE5: merge with above. Rename to toUrlOrLocalFile?
850
856 QString toMimeDataString() const;
857
866 KUrl upUrl( ) const;
867
868 KUrl& operator=( const KUrl& _u );
869
870 // Define those, since the constructors are explicit
871 KUrl& operator=( const char * _url ) { *this = KUrl(_url); return *this; }
872 KUrl& operator=( const QByteArray& _url ) { *this = KUrl(_url); return *this; }
873 KUrl& operator=( const QString& _url ) { *this = KUrl(_url); return *this; }
874
875 bool operator==( const KUrl& _u ) const;
876 bool operator==( const QString& _u ) const;
877 bool operator!=( const KUrl& _u ) const { return !( *this == _u ); }
878 bool operator!=( const QString& _u ) const { return !( *this == _u ); }
879
884 operator QVariant() const;
885
897#ifndef KDE_NO_DEPRECATED
898 KDE_DEPRECATED bool cmp( const KUrl &u, bool ignore_trailing = false ) const;
899#endif
900
901
905 enum EqualsOption
906 {
917 CompareWithoutTrailingSlash = 0x01,
921 CompareWithoutFragment = 0x02,
931 AllowEmptyPath = 0x04
932 };
933 Q_DECLARE_FLAGS(EqualsOptions,EqualsOption)
934
935
944 bool equals( const KUrl &u, const EqualsOptions& options=0 ) const;
945
952 bool isParentOf( const KUrl& u ) const;
953 // (this overload of the QUrl method allows to use the implicit KUrl constructors)
954 // but also the equality test
955
971 static List split( const QString& _url );
972
988 static List split( const KUrl& _url );
989
997 static KUrl join( const List& _list );
998
1008 static KUrl fromPath( const QString& text );
1009
1015#ifndef KDE_NO_DEPRECATED
1016 static KDE_DEPRECATED KUrl fromPathOrUrl( const QString& text );
1017#endif
1018
1024 static KUrl fromMimeDataByteArray( const QByteArray& str );
1025
1042 void populateMimeData( QMimeData* mimeData,
1043 const MetaDataMap& metaData = MetaDataMap(),
1044 MimeDataFlags flags = DefaultMimeDataFlags ) const;
1045
1056#ifndef KDE_NO_DEPRECATED
1057 static KDE_DEPRECATED QString encode_string(const QString &str) {
1058 return QString::fromLatin1( QUrl::toPercentEncoding( str ).constData() ); //krazy:exclude=qclasses
1059 }
1060#endif
1061
1073#ifndef KDE_NO_DEPRECATED
1074 static KDE_DEPRECATED QString encode_string_no_slash(const QString &str) {
1075 return QString::fromLatin1( QUrl::toPercentEncoding( str, "/" ).constData() ); //krazy:exclude=qclasses
1076 }
1077#endif
1078
1089#ifndef KDE_NO_DEPRECATED
1090 static KDE_DEPRECATED QString decode_string(const QString &str) {
1091 return QUrl::fromPercentEncoding( str.toLatin1() ); //krazy:exclude=qclasses
1092 }
1093#endif
1094
1095
1115 static bool isRelativeUrl(const QString &_url);
1116
1131 static QString relativeUrl(const KUrl &base_url, const KUrl &url);
1132
1142 static QString relativePath(const QString &base_dir, const QString &path, bool *isParent=0);
1143
1144private:
1145 void _setQuery( const QString& query );
1146 void _setEncodedUrl(const QByteArray& url);
1147 QString toString() const; // forbidden, use url(), prettyUrl(), or pathOrUrl() instead.
1148 operator QString() const; // forbidden, use url(), prettyUrl(), or pathOrUrl() instead.
1149private:
1150 KUrlPrivate* const d; // Don't ever use this, it would break clear() (which is in QUrl)
1151};
1152
1153Q_DECLARE_OPERATORS_FOR_FLAGS(KUrl::EncodedPathAndQueryOptions)
1154Q_DECLARE_OPERATORS_FOR_FLAGS(KUrl::CleanPathOptions)
1155Q_DECLARE_OPERATORS_FOR_FLAGS(KUrl::QueryItemsOptions)
1156Q_DECLARE_OPERATORS_FOR_FLAGS(KUrl::EqualsOptions)
1157Q_DECLARE_OPERATORS_FOR_FLAGS(KUrl::DirectoryOptions)
1158
1159Q_DECLARE_METATYPE(KUrl)
1160Q_DECLARE_METATYPE(KUrl::List)
1161
1162
1170#ifndef KDE_NO_DEPRECATED
1171KDECORE_EXPORT_DEPRECATED bool urlcmp( const QString& _url1, const QString& _url2 ); // KDE5: remove, KUrl::equals is better API
1172#endif
1173
1186#ifndef KDE_NO_DEPRECATED
1187KDECORE_EXPORT_DEPRECATED bool urlcmp( const QString& _url1, const QString& _url2, const KUrl::EqualsOptions& options ); // KDE5: remove, KUrl::equals is better API
1188#endif
1189
1190KDECORE_EXPORT uint qHash(const KUrl& kurl);
1191
1192#endif
KUrl::List
KUrl::List is a QList that contains KUrls with a few convenience methods.
Definition: kurl.h:147
KUrl::List::List
List()
Creates an empty List.
Definition: kurl.h:152
KUrl::List::DecodeOptions
DecodeOptions
Flags to be used in fromMimeData.
Definition: kurl.h:289
KUrl::List::PreferLocalUrls
@ PreferLocalUrls
When the mimedata contains both KDE-style URLs (eg: desktop:/foo) and the "most local" version of the...
Definition: kurl.h:296
KUrl
Represents and parses a URL.
Definition: kurl.h:112
KUrl::operator=
KUrl & operator=(const QByteArray &_url)
Definition: kurl.h:872
KUrl::DirectoryOption
DirectoryOption
option to be used in fileName and directory
Definition: kurl.h:735
KUrl::MetaDataMap
QMap< QString, QString > MetaDataMap
Definition: kurl.h:114
KUrl::encode_string_no_slash
static QString encode_string_no_slash(const QString &str)
Convert unicoded string to local encoding and use %-style encoding for all common delimiters / non-as...
Definition: kurl.h:1074
KUrl::EncodedPathAndQueryOption
EncodedPathAndQueryOption
Option to be used in encodedPathAndQuery.
Definition: kurl.h:525
KUrl::encode_string
static QString encode_string(const QString &str)
Convert unicoded string to local encoding and use %-style encoding for all common delimiters / non-as...
Definition: kurl.h:1057
KUrl::AdjustPathOption
AdjustPathOption
Options to be used in adjustPath.
Definition: kurl.h:121
KUrl::LeaveTrailingSlash
@ LeaveTrailingSlash
Do not change the path.
Definition: kurl.h:130
KUrl::RemoveTrailingSlash
@ RemoveTrailingSlash
strips a trailing '/', except when the path is already just "/".
Definition: kurl.h:125
KUrl::operator!=
bool operator!=(const QString &_u) const
Definition: kurl.h:878
KUrl::QueryItemsOption
QueryItemsOption
Options for queryItems.
Definition: kurl.h:673
KUrl::CleanPathOption
CleanPathOption
Options to be used in cleanPath.
Definition: kurl.h:464
KUrl::EqualsOption
EqualsOption
Flags to be used in URL comparison functions like equals, or urlcmp.
Definition: kurl.h:906
KUrl::decode_string
static QString decode_string(const QString &str)
Decode %-style encoding and convert from local encoding to unicode.
Definition: kurl.h:1090
KUrl::operator!=
bool operator!=(const KUrl &_u) const
Definition: kurl.h:877
KUrl::operator=
KUrl & operator=(const char *_url)
Definition: kurl.h:871
KUrl::operator=
KUrl & operator=(const QString &_url)
Definition: kurl.h:873
KUrl::MimeDataFlags
MimeDataFlags
Definition: kurl.h:115
QList
Definition: kaboutdata.h:33
QMap
QStringList
QString
QUrl
QVariant
operator==
bool operator==(const KEntry &k1, const KEntry &k2)
Definition: kconfigdata.h:72
kdecore_export.h
urlcmp
bool urlcmp(const QString &_url1, const QString &_url2)
Definition: kurl.cpp:1605
isLocalFile
static bool isLocalFile(const QUrl &url)
Definition: kurl.cpp:905
hasSubUrl
static bool hasSubUrl(const QUrl &url)
Definition: kurl.cpp:983
qHash
uint qHash(const KUrl &kurl)
Definition: kurl.cpp:1914
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 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.14.38 API Reference

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