kurl.h
/* This file is part of the KDE libraries
* Copyright (C) 1999 Torben Weis <weis@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
**/
#ifndef __kurl_h__
#define __kurl_h__
#include <qstring.h>
#include <qvaluelist.h>
#include "kdelibs_export.h"
class QUrl;
class QStringList;
template <typename K, typename V> class QMap;
class KURLPrivate;
// Defines that file-urls look like file:///path/file instead of file:/path/file
#define KURL_TRIPLE_SLASH_FILE_PROT
class KDECORE_EXPORT KURL
{
public:
enum AdjustementFlags
{
NoAdjustements = 0,
StripFileProtocol = 1
};
enum URIMode
{
Auto,
Invalid,
RawURI,
URL,
Mailto
};
class KDECORE_EXPORT List : public QValueList<KURL>
{
public:
List() { }
List(const KURL &url);
List(const QStringList &list);
QStringList toStringList() const;
};
KURL();
~KURL();
KURL( const QString& url, int encoding_hint = 0 );
KURL( const char * url, int encoding_hint = 0 );
KURL( const QCString& url, int encoding_hint = 0 );
KURL( const KURL& u );
KURL( const QUrl &u );
KURL( const KURL& _baseurl, const QString& _rel_url, int encoding_hint=0 );
QString protocol() const { return m_bIsMalformed ? QString::null : m_strProtocol; }
void setProtocol( const QString& _txt );
int uriMode() const;
QString user() const { return m_strUser; }
void setUser( const QString& _txt );
bool hasUser() const { return !m_strUser.isEmpty(); }
QString pass() const { return m_strPass; }
void setPass( const QString& _txt );
bool hasPass() const { return !m_strPass.isEmpty(); }
QString host() const { return m_strHost; }
void setHost( const QString& _txt );
bool hasHost() const { return !m_strHost.isEmpty(); }
unsigned short int port() const { return m_iPort; }
void setPort( unsigned short int _p );
QString path() const { return m_strPath; }
QString path( int _trailing ) const;
void setPath( const QString& path );
bool hasPath() const { return !m_strPath.isEmpty(); }
void cleanPath(bool cleanDirSeparator = true);
void adjustPath(int _trailing);
void setEncodedPathAndQuery( const QString& _txt, int encoding_hint = 0 );
void setEncodedPath(const QString& _txt, int encoding_hint = 0 );
QString encodedPathAndQuery( int _trailing = 0, bool _no_empty_path = false, int encoding_hint = 0) const;
void setQuery( const QString& _txt, int encoding_hint = 0);
QString query() const;
QString ref() const { return m_strRef_encoded; }
void setRef( const QString& _txt ) { m_strRef_encoded = _txt; }
bool hasRef() const { return !m_strRef_encoded.isNull(); }
QString htmlRef() const;
QString encodedHtmlRef() const;
void setHTMLRef( const QString& _ref );
bool hasHTMLRef() const;
bool isValid() const { return !m_bIsMalformed; }
KDE_DEPRECATED bool isMalformed() const { return !isValid(); }
bool isLocalFile() const;
void setFileEncoding(const QString &encoding);
QString fileEncoding() const;
bool hasSubURL() const;
void addPath( const QString& txt );
QString queryItem( const QString& item ) const;
QString queryItem( const QString& item, int encoding_hint ) const;
enum QueryItemsOptions
{
CaseInsensitiveKeys = 1
};
QMap< QString, QString > queryItems( int options=0 ) const;
QMap< QString, QString > queryItems( int options, int encoding_hint ) const;
void addQueryItem( const QString& _item, const QString& _value, int encoding_hint = 0 );
void removeQueryItem( const QString& _item );
void setFileName( const QString&_txt );
QString fileName( bool _ignore_trailing_slash_in_path = true ) const;
QString directory( bool _strip_trailing_slash_from_result = true,
bool _ignore_trailing_slash_in_path = true ) const;
void setDirectory(const QString &dir);
bool cd( const QString& _dir );
QString url( int _trailing = 0, int encoding_hint = 0) const;
QString prettyURL( int _trailing = 0) const;
QString prettyURL( int _trailing, AdjustementFlags _flags) const;
// ### BIC: Merge the two above + spell it as "Adjustment"
// Or remove completely, and let people use pathOrURL() instead
QString pathOrURL() const;
QString htmlURL() const;
bool isEmpty() const;
KURL upURL( ) const;
bool operator<(const KURL& _u) const;
KURL& operator=( const KURL& _u );
KURL& operator=( const QString& _url );
KURL& operator=( const char * _url );
KURL& operator=( const QUrl & u );
bool operator==( const KURL& _u ) const;
bool operator==( const QString& _u ) const;
bool operator!=( const KURL& _u ) const { return !( *this == _u ); }
bool operator!=( const QString& _u ) const { return !( *this == _u ); }
bool cmp( const KURL &u, bool ignore_trailing = false ) const KDE_DEPRECATED;
bool equals( const KURL &u, bool ignore_trailing = false ) const; // TODO KDE4: add bool _ignore_ref = false
bool isParentOf( const KURL& u ) const;
static List split( const QString& _url );
static List split( const KURL& _url );
static KURL join( const List& _list );
static KURL fromPathOrURL( const QString& text );
static QString encode_string(const QString &str, int encoding_hint = 0);
static QString encode_string_no_slash(const QString &str, int encoding_hint = 0);
static QString decode_string(const QString &str, int encoding_hint = 0);
static bool isRelativeURL(const QString &_url);
static QString relativeURL(const KURL &base_url, const KURL &url, int encoding_hint = 0);
static QString relativePath(const QString &base_dir, const QString &path, bool *isParent=0);
static URIMode uriModeForProtocol(const QString& protocol);
#ifdef KDE_NO_COMPAT
private:
#endif
QString filename( bool _ignore_trailing_slash_in_path = true ) const
{
return fileName(_ignore_trailing_slash_in_path);
}
protected:
void reset();
void parseURL( const QString& _url, int encoding_hint = 0 );
void parseRawURI( const QString& _url, int encoding_hint = 0 );
void parseMailto( const QString& _url, int encoding_hint = 0 );
void parse( const QString& _url, int encoding_hint = 0 );
private:
void _setQuery( const QString& _txt, int encoding_hint = 0);
QString m_strProtocol;
QString m_strUser;
QString m_strPass;
QString m_strHost;
QString m_strPath;
QString m_strRef_encoded;
QString m_strQuery_encoded;
bool m_bIsMalformed : 1;
enum URIMode m_iUriMode : 3;
uint freeForUse : 4;
unsigned short int m_iPort;
QString m_strPath_encoded;
friend KDECORE_EXPORT QDataStream & operator<< (QDataStream & s, const KURL & a);
friend KDECORE_EXPORT QDataStream & operator>> (QDataStream & s, KURL & a);
private:
KURLPrivate* d;
};
KDECORE_EXPORT bool urlcmp( const QString& _url1, const QString& _url2 );
KDECORE_EXPORT bool urlcmp( const QString& _url1, const QString& _url2, bool _ignore_trailing, bool _ignore_ref );
KDECORE_EXPORT QDataStream & operator<< (QDataStream & s, const KURL & a);
KDECORE_EXPORT QDataStream & operator>> (QDataStream & s, KURL & a);
#endif
KURL
Represents and parses a URL.
Definition: kurl.h:127
KURL::hasRef
bool hasRef() const
Tests if the URL has a reference part.
Definition: kurl.h:758
KURL::URIMode
URIMode
Defines the type of URI we are processing.
Definition: kurl.h:152
KURL::RawURI
Raw URI.
Definition: kurl.h:168
KURL::hasPass
bool hasPass() const
Tests if this URL has a password included in it.
Definition: kurl.h:467
KURL::QueryItemsOptions
QueryItemsOptions
Options for queryItems()
Definition: kurl.h:925
KURL::host
QString host() const
Returns the decoded hostname included in the URL.
Definition: kurl.h:477
KURL::isMalformed
KDE_DEPRECATED bool isMalformed() const
Tests if the URL is malformed.
Definition: kurl.h:827
KURL::port
unsigned short int port() const
Returns the port number included in the URL.
Definition: kurl.h:509
KURL::hasHost
bool hasHost() const
Tests if this URL has a hostname included in it.
Definition: kurl.h:498
KURL::AdjustementFlags
AdjustementFlags
Flags to choose how file: URLs are treated when creating their QString representation with prettyURL(...
Definition: kurl.h:136
KURL::hasPath
bool hasPath() const
Tests if this URL has a path included in it.
Definition: kurl.h:591
KURL::protocol
QString protocol() const
Returns the protocol for the URL.
Definition: kurl.h:367
KURL::ref
QString ref() const
Returns the encoded reference of the URL.
Definition: kurl.h:733
KURL::Auto
Automatically detected.
Definition: kurl.h:158
KURL::urlcmp
bool urlcmp(const QString &_url1, const QString &_url2)
Definition: kurl.cpp:2081
KURL::filename
QString filename(bool _ignore_trailing_slash_in_path=true) const
Definition: kurl.h:1718
KURL::hasUser
bool hasUser() const
Tests if this URL has a user name included in it.
Definition: kurl.h:425
KURL::operator!=
bool operator!=(const KURL &_u) const
Tests if this URL is different from the given one.
Definition: kurl.h:1430
KURL::user
QString user() const
Returns the decoded user name (login, user id, etc) included in the URL.
Definition: kurl.h:401
KURL::path
QString path() const
Returns the current decoded path.
Definition: kurl.h:532
KURL::setRef
void setRef(const QString &_txt)
Sets the encoded reference part (everything after '#')
Definition: kurl.h:746
KURL::Invalid
Invalid URI.
Definition: kurl.h:163
KURL::URL
Standards compliant URL.
Definition: kurl.h:172
KURL::operator!=
bool operator!=(const QString &_u) const
Tests if this URL is different from the one given as a string.
Definition: kurl.h:1444
KURL::List
KURL::List is a QValueList that contains KURLs with a few convenience methods.
Definition: kurl.h:187
KURL::List::List
List()
Creates an empty List.
Definition: kurl.h:193
KURL::pass
QString pass() const
Returns the decoded password (corresponding to user()) included in the URL.
Definition: kurl.h:440
KURL::isValid
bool isValid() const
Tests if the URL is well formed.
Definition: kurl.h:816

KDE Home | KDE Accessibility Home | Description of Access Keys