# kdecore Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# kurl.h

    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., 59 Temple Place - Suite 330,
    00017  *  Boston, MA 02111-1307, 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
    00122 class KDECORE_EXPORT KURL
    00123 {
    00124 public:
    00125   enum AdjustementFlags
    00126   {
    00127     NoAdjustements = 0,
    00128     StripFileProtocol = 1
    00129   };
    00130
    00134   enum URIMode
    00135   {
    00140     Auto,
    00145     Invalid,
    00150     RawURI,
    00154     URL,
    00160     Mailto
    00161   };
    00162
    00169   class KDECORE_EXPORT List : public QValueList<KURL>
    00170   {
    00171   public:
    00175       List() { }
    00181       List(const KURL &url);
    00187       List(const QStringList &list);
    00192       QStringList toStringList() const;
    00193   };
    00197   KURL();
    00198
    00202   ~KURL();
    00203
    00220   KURL( const QString& url, int encoding_hint = 0 );
    00230   KURL( const char * url, int encoding_hint = 0 );
    00240   KURL( const QCString& url, int encoding_hint = 0 );
    00241
    00246   KURL( const KURL& u );
    00251   KURL( const QUrl &u );
    00264   KURL( const KURL& _baseurl, const QString& _rel_url, int encoding_hint=0 );
    00265
    00271   QString protocol() const { return m_bIsMalformed ? QString::null : m_strProtocol; }
    00276   void setProtocol( const QString& _txt );
    00277
    00283   int uriMode() const;
    00284
    00289   QString user() const { return m_strUser; }
    00296   void setUser( const QString& _txt );
    00301   bool hasUser() const { return !m_strUser.isEmpty(); }
    00302
    00307   QString pass() const { return m_strPass; }
    00318   void setPass( const QString& _txt );
    00323   bool hasPass() const { return !m_strPass.isEmpty(); }
    00324
    00329   QString host() const { return m_strHost; }
    00330
    00337   void setHost( const QString& _txt );
    00342   bool hasHost() const { return !m_strHost.isEmpty(); }
    00343
    00349   unsigned short int port() const { return m_iPort; }
    00354   void setPort( unsigned short int _p );
    00355
    00361   QString path() const  { return m_strPath; }
    00362
    00376   QString path( int _trailing ) const;
    00377
    00386   void setPath( const QString& path );
    00387
    00392   bool hasPath() const { return !m_strPath.isEmpty(); }
    00393
    00402   void cleanPath(bool cleanDirSeparator = true);
    00403
    00415   void adjustPath(int _trailing);
    00416
    00424   void setEncodedPathAndQuery( const QString& _txt, int encoding_hint = 0 );
    00425
    00432   void setEncodedPath(const QString& _txt, int encoding_hint = 0 );
    00433
    00451   QString encodedPathAndQuery( int _trailing = 0, bool _no_empty_path = false, int encoding_hint = 0) const;
    00452
    00461   void setQuery( const QString& _txt, int encoding_hint = 0);
    00462
    00471   QString query() const;
    00472
    00477   QString ref() const { return m_strRef_encoded; }
    00478
    00483   void setRef( const QString& _txt ) { m_strRef_encoded = _txt; }
    00484
    00491   bool hasRef() const { return !m_strRef_encoded.isNull(); }
    00492
    00500   QString htmlRef() const;
    00501
    00507   QString encodedHtmlRef() const;
    00508
    00516   void setHTMLRef( const QString& _ref );
    00517
    00523   bool hasHTMLRef() const;
    00524
    00530   bool isValid() const  { return !m_bIsMalformed; }
    00534   KDE_DEPRECATED bool isMalformed() const { return !isValid(); }
    00535
    00541   bool isLocalFile() const;
    00542
    00549   void setFileEncoding(const QString &encoding);
    00550
    00557   QString fileEncoding() const;
    00558
    00565   bool hasSubURL() const;
    00566
    00577   void addPath( const QString& txt );
    00578
    00583   QString queryItem( const QString& item ) const;
    00584
    00594   QString queryItem( const QString& item, int encoding_hint ) const;
    00595
    00604   enum QueryItemsOptions { CaseInsensitiveKeys = 1 };
    00605
    00609   QMap< QString, QString > queryItems( int options=0 ) const;
    00610
    00622   QMap< QString, QString > queryItems( int options, int encoding_hint ) const;
    00623
    00634   void addQueryItem( const QString& _item, const QString& _value, int encoding_hint = 0 );
    00635
    00641   void removeQueryItem( const QString& _item );
    00642
    00656   void setFileName( const QString&_txt );
    00657
    00668   QString fileName( bool _ignore_trailing_slash_in_path = true ) const;
    00669
    00681   QString directory( bool _strip_trailing_slash_from_result = true,
    00682              bool _ignore_trailing_slash_in_path = true ) const;
    00683
    00687   void setDirectory(const QString &dir);
    00688
    00702   bool cd( const QString& _dir );
    00703
    00722   QString url( int _trailing = 0, int encoding_hint = 0) const;
    00723
    00737   QString prettyURL( int _trailing = 0) const;
    00738
    00753   QString prettyURL( int _trailing, AdjustementFlags _flags) const;
    00754   // ### BIC: Merge the two above + spell it as "Adjustment"
    00755   // Or remove completely, and let people use pathOrURL() instead
    00756
    00767   QString pathOrURL() const;
    00768
    00775   QString htmlURL() const;
    00776
    00777
    00782   bool isEmpty() const;
    00783
    00792   KURL upURL( ) const;
    00793
    00794   bool operator<(const KURL& _u) const;
    00795
    00796   KURL& operator=( const KURL& _u );
    00797   KURL& operator=( const QString& _url );
    00798   KURL& operator=( const char * _url );
    00799   KURL& operator=( const QUrl & u );
    00800
    00801   bool operator==( const KURL& _u ) const;
    00802   bool operator==( const QString& _u ) const;
    00803   bool operator!=( const KURL& _u ) const { return !( *this == _u ); }
    00804   bool operator!=( const QString& _u ) const { return !( *this == _u ); }
    00805
    00816   bool cmp( const KURL &u, bool ignore_trailing = false ) const KDE_DEPRECATED;
    00817
    00827   bool equals( const KURL &u, bool ignore_trailing = false ) const; // TODO KDE4: add bool _ignore_ref = false
    00828
    00834   bool isParentOf( const KURL& u ) const;
    00835
    00851   static List split( const QString& _url );
    00852
    00868   static List split( const KURL& _url );
    00869
    00877   static KURL join( const List& _list );
    00878
    00892   static KURL fromPathOrURL( const QString& text );
    00893
    00904   static QString encode_string(const QString &str, int encoding_hint = 0);
    00905
    00916   static QString encode_string_no_slash(const QString &str, int encoding_hint = 0);
    00917
    00928   static QString decode_string(const QString &str, int encoding_hint = 0);
    00929
    00938   static bool isRelativeURL(const QString &_url);
    00939
    00956   static QString relativeURL(const KURL &base_url, const KURL &url, int encoding_hint = 0);
    00957
    00967   static QString relativePath(const QString &base_dir, const QString &path, bool *isParent=0);
    00968
    00974   static URIMode uriModeForProtocol(const QString& protocol);
    00975
    00976 #ifdef KDE_NO_COMPAT
    00977 private:
    00978 #endif
    00982     QString filename( bool _ignore_trailing_slash_in_path = true ) const
    00983   {
    00984     return fileName(_ignore_trailing_slash_in_path);
    00985   }
    00986
    00987 protected:
    00988   void reset();
    00989   void parseURL( const QString& _url, int encoding_hint = 0 );
    00990   void parseRawURI( const QString& _url, int encoding_hint = 0 );
    00991   void parseMailto( const QString& _url, int encoding_hint = 0 );
    00992   void parse( const QString& _url, int encoding_hint = 0 );
    00993
    00994 private:
    00995   void _setQuery( const QString& _txt, int encoding_hint = 0);
    00996
    00997   QString m_strProtocol;
    00998   QString m_strUser;
    00999   QString m_strPass;
    01000   QString m_strHost;
    01001   QString m_strPath;
    01002   QString m_strRef_encoded;
    01003   QString m_strQuery_encoded;
    01004   bool m_bIsMalformed : 1;
    01005   enum URIMode m_iUriMode : 3;
    01006   uint freeForUse     : 4;
    01007   unsigned short int m_iPort;
    01008   QString m_strPath_encoded;
    01009
    01010   friend KDECORE_EXPORT QDataStream & operator<< (QDataStream & s, const KURL & a);
    01011   friend KDECORE_EXPORT QDataStream & operator>> (QDataStream & s, KURL & a);
    01012 private:
    01013   KURLPrivate* d;
    01014 };
    01015
    01023 KDECORE_EXPORT bool urlcmp( const QString& _url1, const QString& _url2 );
    01024
    01037 KDECORE_EXPORT bool urlcmp( const QString& _url1, const QString& _url2, bool _ignore_trailing, bool _ignore_ref );
    01038
    01039 KDECORE_EXPORT QDataStream & operator<< (QDataStream & s, const KURL & a);
    01040 KDECORE_EXPORT QDataStream & operator>> (QDataStream & s, KURL & a);
    01041
    01042 #endif

This file is part of the documentation for kdecore Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:18:12 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003