• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

KDECore

kurl.h

Go to the documentation of this file.
00001 /* This file is part of the KDE libraries
00002  *  Copyright (C) 1999 Torben Weis <weis@kde.org>
00003  *
00004  *  This library is free software; you can redistribute it and/or
00005  *  modify it under the terms of the GNU Library General Public
00006  *  License as published by the Free Software Foundation; either
00007  *  version 2 of the License, or (at your option) any later version.
00008  *
00009  *  This library is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  *  Library General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU Library General Public License
00015  *  along with this library; see the file COPYING.LIB.  If not, write to
00016  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  *  Boston, MA 02110-1301, USA.
00018  **/
00019 
00020 #ifndef __kurl_h__
00021 #define __kurl_h__
00022 
00023 #include <qstring.h>
00024 #include <qvaluelist.h>
00025 #include "kdelibs_export.h"
00026 
00027 class QUrl;
00028 class QStringList;
00029 template <typename K, typename V> class QMap;
00030 
00031 class KURLPrivate;
00032 
00033 // Defines that file-urls look like file:///path/file instead of file:/path/file
00034 #define KURL_TRIPLE_SLASH_FILE_PROT
00035 
00127 class KDECORE_EXPORT KURL
00128 {
00129 public:
00136   enum AdjustementFlags
00137   {
00141     NoAdjustements = 0,
00146     StripFileProtocol = 1
00147   };
00148 
00152   enum URIMode
00153   {
00158     Auto,
00163     Invalid,
00168     RawURI,
00172     URL,
00178     Mailto
00179   };
00180 
00187   class KDECORE_EXPORT List : public QValueList<KURL>
00188   {
00189   public:
00193       List() { }
00199       List(const KURL &url);
00212       List(const QStringList &list);
00226       QStringList toStringList() const;
00227   };
00233   KURL();
00234 
00238   ~KURL();
00239 
00260   KURL( const QString& url, int encoding_hint = 0 );
00286   KURL( const char * url, int encoding_hint = 0 );
00312   KURL( const QCString& url, int encoding_hint = 0 );
00313 
00319   KURL( const KURL& u );
00327   KURL( const QUrl &u );
00353   KURL( const KURL& _baseurl, const QString& _rel_url, int encoding_hint=0 );
00354 
00367   QString protocol() const { return m_bIsMalformed ? QString::null : m_strProtocol; }
00378   void setProtocol( const QString& _txt );
00379 
00390   int uriMode() const;
00391 
00401   QString user() const { return m_strUser; }
00415   void setUser( const QString& _txt );
00425   bool hasUser() const { return !m_strUser.isEmpty(); }
00426 
00440   QString pass() const { return m_strPass; }
00454   void setPass( const QString& _txt );
00467   bool hasPass() const { return !m_strPass.isEmpty(); }
00468 
00477   QString host() const { return m_strHost; }
00478 
00489   void setHost( const QString& _txt );
00498   bool hasHost() const { return !m_strHost.isEmpty(); }
00499 
00509   unsigned short int port() const { return m_iPort; }
00518   void setPort( unsigned short int _p );
00519 
00532   QString path() const  { return m_strPath; }
00533 
00563   QString path( int _trailing ) const;
00564 
00581   void setPath( const QString& path );
00582 
00591   bool hasPath() const { return !m_strPath.isEmpty(); }
00592 
00606   void cleanPath(bool cleanDirSeparator = true);
00607 
00630   void adjustPath(int _trailing);
00631 
00647   void setEncodedPathAndQuery( const QString& _txt, int encoding_hint = 0 );
00648 
00659   void setEncodedPath(const QString& _txt, int encoding_hint = 0 );
00660 
00691   QString encodedPathAndQuery( int _trailing = 0, bool _no_empty_path = false, int encoding_hint = 0) const;
00692 
00706   void setQuery( const QString& _txt, int encoding_hint = 0);
00707 
00720   QString query() const;
00721 
00733   QString ref() const { return m_strRef_encoded; }
00734 
00746   void setRef( const QString& _txt ) { m_strRef_encoded = _txt; }
00747 
00758   bool hasRef() const { return !m_strRef_encoded.isNull(); }
00759 
00773   QString htmlRef() const;
00774 
00785   QString encodedHtmlRef() const;
00786 
00796   void setHTMLRef( const QString& _ref );
00797 
00808   bool hasHTMLRef() const;
00809 
00816   bool isValid() const  { return !m_bIsMalformed; }
00827   KDE_DEPRECATED bool isMalformed() const { return !isValid(); }
00828 
00835   bool isLocalFile() const;
00836 
00849   void setFileEncoding(const QString &encoding);
00850 
00859   QString fileEncoding() const;
00860 
00870   bool hasSubURL() const;
00871 
00886   void addPath( const QString& txt );
00887 
00901   QString queryItem( const QString& item ) const;
00902 
00918   QString queryItem( const QString& item, int encoding_hint ) const;
00919 
00925   enum QueryItemsOptions
00926   {
00930     CaseInsensitiveKeys = 1
00931   };
00932 
00936   QMap< QString, QString > queryItems( int options=0 ) const;
00937 
00955   QMap< QString, QString > queryItems( int options, int encoding_hint ) const;
00956 
00972   void addQueryItem( const QString& _item, const QString& _value, int encoding_hint = 0 );
00973 
00984   void removeQueryItem( const QString& _item );
00985 
01006   void setFileName( const QString&_txt );
01007 
01025   QString fileName( bool _ignore_trailing_slash_in_path = true ) const;
01026 
01053   QString directory( bool _strip_trailing_slash_from_result = true,
01054              bool _ignore_trailing_slash_in_path = true ) const;
01055 
01065   void setDirectory(const QString &dir);
01066 
01085   bool cd( const QString& _dir );
01086 
01122   QString url( int _trailing = 0, int encoding_hint = 0) const;
01123 
01156   QString prettyURL( int _trailing = 0) const;
01157 
01193   QString prettyURL( int _trailing, AdjustementFlags _flags) const;
01194   // ### BIC: Merge the two above + spell it as "Adjustment"
01195   // Or remove completely, and let people use pathOrURL() instead
01196 
01215   QString pathOrURL() const;
01216 
01228   QString htmlURL() const;
01229 
01230 
01242   bool isEmpty() const;
01243 
01263   KURL upURL( ) const;
01264 
01316   bool operator<(const KURL& _u) const;
01317 
01329   KURL& operator=( const KURL& _u );
01330 
01344   KURL& operator=( const QString& _url );
01345 
01359   KURL& operator=( const char * _url );
01360 
01373   KURL& operator=( const QUrl & u );
01374 
01394   bool operator==( const KURL& _u ) const;
01395 
01416   bool operator==( const QString& _u ) const;
01417 
01430   bool operator!=( const KURL& _u ) const { return !( *this == _u ); }
01431 
01444   bool operator!=( const QString& _u ) const { return !( *this == _u ); }
01445 
01461   bool cmp( const KURL &u, bool ignore_trailing = false ) const KDE_DEPRECATED;
01462 
01476   bool equals( const KURL &u, bool ignore_trailing = false ) const; // TODO KDE4: add bool _ignore_ref = false
01477 
01489   bool isParentOf( const KURL& u ) const;
01490 
01517   static List split( const QString& _url );
01518 
01544   static List split( const KURL& _url );
01545 
01559   static KURL join( const List& _list );
01560 
01582   static KURL fromPathOrURL( const QString& text );
01583 
01601   static QString encode_string(const QString &str, int encoding_hint = 0);
01602 
01619   static QString encode_string_no_slash(const QString &str, int encoding_hint = 0);
01620 
01639   static QString decode_string(const QString &str, int encoding_hint = 0);
01640 
01655   static bool isRelativeURL(const QString &_url);
01656 
01680   static QString relativeURL(const KURL &base_url, const KURL &url, int encoding_hint = 0);
01681 
01696   static QString relativePath(const QString &base_dir, const QString &path, bool *isParent=0);
01697 
01710   static URIMode uriModeForProtocol(const QString& protocol);
01711 
01712 #ifdef KDE_NO_COMPAT
01713 private:
01714 #endif
01715 
01718     QString filename( bool _ignore_trailing_slash_in_path = true ) const
01719   {
01720     return fileName(_ignore_trailing_slash_in_path);
01721   }
01722 
01723 protected:
01739   void reset();
01740   
01750   void parseURL( const QString& _url, int encoding_hint = 0 );
01760   void parseRawURI( const QString& _url, int encoding_hint = 0 );
01770   void parseMailto( const QString& _url, int encoding_hint = 0 );
01778   void parse( const QString& _url, int encoding_hint = 0 );
01779 
01780 private:
01781   void _setQuery( const QString& _txt, int encoding_hint = 0);
01782 
01783   QString m_strProtocol;
01784   QString m_strUser;
01785   QString m_strPass;
01786   QString m_strHost;
01787   QString m_strPath;
01788   QString m_strRef_encoded;
01789   QString m_strQuery_encoded;
01790   bool m_bIsMalformed : 1;
01791   enum URIMode m_iUriMode : 3;
01792   uint freeForUse     : 4;
01793   unsigned short int m_iPort;
01794   QString m_strPath_encoded;
01795 
01796   friend KDECORE_EXPORT QDataStream & operator<< (QDataStream & s, const KURL & a);
01797   friend KDECORE_EXPORT QDataStream & operator>> (QDataStream & s, KURL & a);
01798 private:
01799   KURLPrivate* d;
01800 };
01801 
01809 KDECORE_EXPORT bool urlcmp( const QString& _url1, const QString& _url2 );
01810 
01823 KDECORE_EXPORT bool urlcmp( const QString& _url1, const QString& _url2, bool _ignore_trailing, bool _ignore_ref );
01824 
01825 KDECORE_EXPORT QDataStream & operator<< (QDataStream & s, const KURL & a);
01826 KDECORE_EXPORT QDataStream & operator>> (QDataStream & s, KURL & a);
01827 
01828 #endif

KDECore

Skip menu "KDECore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • dcop
  • DNSSD
  • interfaces
  • Kate
  • kconf_update
  • KDECore
  • KDED
  • kdefx
  • KDEsu
  • kdeui
  • KDocTools
  • KHTML
  • KImgIO
  • KInit
  • kio
  • kioslave
  • KJS
  • KNewStuff
  • KParts
  • KUtils
Generated for API Reference by doxygen 1.5.9
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