home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kurl.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-11-08  |  56.3 KB  |  1,829 lines

  1. /* This file is part of the KDE libraries
  2.  *  Copyright (C) 1999 Torben Weis <weis@kde.org>
  3.  *
  4.  *  This library is free software; you can redistribute it and/or
  5.  *  modify it under the terms of the GNU Library General Public
  6.  *  License as published by the Free Software Foundation; either
  7.  *  version 2 of the License, or (at your option) any later version.
  8.  *
  9.  *  This library is distributed in the hope that it will be useful,
  10.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12.  *  Library General Public License for more details.
  13.  *
  14.  *  You should have received a copy of the GNU Library General Public License
  15.  *  along with this library; see the file COPYING.LIB.  If not, write to
  16.  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17.  *  Boston, MA 02110-1301, USA.
  18.  **/
  19.  
  20. #ifndef __kurl_h__
  21. #define __kurl_h__
  22.  
  23. #include <qstring.h>
  24. #include <qvaluelist.h>
  25. #include "kdelibs_export.h"
  26.  
  27. class QUrl;
  28. class QStringList;
  29. template <typename K, typename V> class QMap;
  30.  
  31. class KURLPrivate;
  32.  
  33. // Defines that file-urls look like file:///path/file instead of file:/path/file
  34. #define KURL_TRIPLE_SLASH_FILE_PROT
  35.  
  36. /**
  37.  * @brief Represents and parses a URL
  38.  *
  39.  * A prototypical URL looks like:
  40.  * @code
  41.  *   protocol://user:password@hostname:port/path/to/file.ext#reference
  42.  * @endcode
  43.  *
  44.  * KURL handles escaping of URLs. This means that the specification
  45.  * of a full URL will differ from the corresponding string that would specify a
  46.  * local file or directory in file-operations like fopen. This is because an URL
  47.  * doesn't allow certain characters and escapes them.
  48.  *
  49.  * For examle:
  50.  * - '#' -> "%23"
  51.  *  (In a URL the hash-character @c '#' is used to specify a "reference", i.e.
  52.  *  the position within a document)
  53.  * - space -> "%20"
  54.  *
  55.  * The constructor KURL(const QString&) expects a string properly escaped,
  56.  * or at least non-ambiguous.
  57.  * For instance a local file or directory <tt>"/bar/#foo#"</tt> would have the
  58.  * URL <tt>"file:///bar/%23foo%23"</tt>.
  59.  * If you have the absolute path and need the URL-escaping you should create
  60.  * KURL via the default-constructor and then call setPath(const QString&):
  61.  * @code
  62.  *     KURL kurl;
  63.  *     kurl.setPath( "/bar/#foo#" );
  64.  *     QString url = kurl.url();    // -> "file:///bar/%23foo%23"
  65.  * @endcode
  66.  *
  67.  * If you have the URL of a local file or directory and need the absolute path,
  68.  * you would use path().
  69.  * @code
  70.  *    KURL url( "file:///bar/%23foo%23" );
  71.  *    ...
  72.  *    if ( url.isLocalFile() )
  73.  *       QString path = url.path();       // -> "/bar/#foo#"
  74.  * @endcode
  75.  *
  76.  * The other way round: if the user can enter a string, that can be either a
  77.  * path or a URL, then you need to use KURL::fromPathOrURL() to build a KURL.
  78.  *
  79.  * This must also be considered, when you have separated directory and file
  80.  * strings and need to put them together.
  81.  * While you can simply concatenate normal path strings, you must take care if
  82.  * the directory-part is already an escaped URL.
  83.  * (This might be needed if the user specifies a relative path, and your
  84.  * program supplies the rest from elsewhere.)
  85.  *
  86.  * Wrong:
  87.  * @code
  88.  *    QString dirUrl = "file:///bar/";
  89.  *    QString fileName = "#foo#";
  90.  *    QString invalidURL = dirUrl + fileName;   // -> "file:///bar/#foo#" won't behave like you would expect.
  91.  * @endcode
  92.  * Instead you should use addPath().
  93.  *
  94.  * Right:
  95.  * @code
  96.  *    KURL url( "file:///bar/" );
  97.  *    QString fileName = "#foo#";
  98.  *    url.addPath( fileName );
  99.  *    QString validURL = url.url();    // -> "file:///bar/%23foo%23"
  100.  * @endcode
  101.  *
  102.  * Also consider that some URLs contain the password, but this shouldn't be
  103.  * visible. Your program should use prettyURL() every time it displays a
  104.  * URL, whether in the GUI or in debug output or...
  105.  *
  106.  * @code
  107.  *    KURL url( "ftp://name:password@ftp.faraway.org/bar/%23foo%23");
  108.  *    QString visibleURL = url.prettyURL(); // -> "ftp://name@ftp.faraway.org/bar/%23foo%23"
  109.  * @endcode
  110.  * Note that prettyURL() doesn't change the character escapes (like <tt>"%23"</tt>).
  111.  * Otherwise the URL would be invalid and the user wouldn't be able to use it in another
  112.  * context.
  113.  *
  114.  * KURL has some restrictions regarding the path
  115.  * encoding. KURL works internally with the decoded path and
  116.  * and encoded query. For example,
  117.  * @code
  118.  *    http://localhost/cgi-bin/test%20me.pl?cmd=Hello%20you
  119.  * @endcode
  120.  * would result in a decoded path <tt>"/cgi-bin/test me.pl"</tt>
  121.  * and in the encoded query <tt>"?cmd=Hello%20you"</tt>.
  122.  * Since path is internally always encoded you may @em not use
  123.  * <tt>"%00"</tt> in the path, although this is OK for the query.
  124.  *
  125.  *  @author  Torben Weis <weis@kde.org>
  126.  */
  127. class KDECORE_EXPORT KURL
  128. {
  129. public:
  130.   /**
  131.    * Flags to choose how file: URLs are treated when creating their QString
  132.    * representation with prettyURL(int,AdjustementFlags)
  133.    *
  134.    * However it is recommended to use pathOrURL() instead of this variant of prettyURL()
  135.    */
  136.   enum AdjustementFlags
  137.   {
  138.      /**
  139.      * Do not treat file: URLs differently
  140.      */
  141.     NoAdjustements = 0,
  142.     /**
  143.      * Strip the file: protocol from the string, i.e. return only the path and
  144.      * filename as a local path
  145.      */
  146.     StripFileProtocol = 1
  147.   };
  148.  
  149.   /**
  150.    * Defines the type of URI we are processing.
  151.    */
  152.   enum URIMode
  153.   {
  154.     /**
  155.      * Automatically detected. Using this mode, an appropriate processing
  156.      * mode will be selected when the URI is first processed.
  157.      */
  158.     Auto,
  159.     /**
  160.      * Invalid URI. This is something that can't be parsed as a URI at all.
  161.      * The contents are accessible through the protocol() method.
  162.      */
  163.     Invalid,
  164.     /**
  165.      * Raw URI. This type of URI should not be processed in any way.
  166.      * Contents are accessible through the path() method.
  167.      */
  168.     RawURI,
  169.     /**
  170.      * Standards compliant URL. Process as a syntactically correct URL.
  171.      */
  172.     URL,
  173.     /**
  174.      * Mailto URI. path() contains an email address which should have its
  175.      * domain part processed as a DNS name. The email address is accessible
  176.      * through the path() method.
  177.      */
  178.     Mailto
  179.   };
  180.  
  181.   /**
  182.    * KURL::List is a QValueList that contains KURLs with a few
  183.    * convenience methods.
  184.    * @see KURL
  185.    * @see QValueList
  186.    */
  187.   class KDECORE_EXPORT List : public QValueList<KURL>
  188.   {
  189.   public:
  190.     /**
  191.      * Creates an empty List.
  192.      */
  193.       List() { }
  194.       /**
  195.        * @brief Creates a list that contains the given URL as only item
  196.        *
  197.        * @param url the URL to add
  198.        */
  199.       List(const KURL &url);
  200.       /**
  201.        * @brief Creates a list that contains the URLs from the given list
  202.        *
  203.        * This equivalent to iterating over the input list and using each item
  204.        * as the argument to KURL's constructor, i.e. the resulting list will
  205.        * have as many elements as the input list, but not all entries might
  206.        * be valid.
  207.        *
  208.        * @param list the list containing the URLs as strings
  209.        *
  210.        * @see KURL(const QString &, int)
  211.        */
  212.       List(const QStringList &list);
  213.       /**
  214.        * @brief Converts the URLs of this list to a list of strings
  215.        *
  216.        * This is equivalent to iterating over the list and calling url() on
  217.        * each item.
  218.        * If you need a list of user visible URLs, i.e. not containing password
  219.        * information, iterate over the list yourself and call prettyURL() on
  220.        * each item instead.
  221.        *
  222.        * @return the list of strings
  223.        *
  224.        * @see KURL::url()
  225.        */
  226.       QStringList toStringList() const;
  227.   };
  228.   /**
  229.    * @brief Constructs an empty URL
  230.    *
  231.    * The created instance will also be invalid, see isValid()
  232.    */
  233.   KURL();
  234.  
  235.   /**
  236.    * @brief Destructs the KURL object
  237.    */
  238.   ~KURL();
  239.  
  240.   /**
  241.    * @brief Usual constructor, to construct from a string
  242.    *
  243.    * @warning It is dangerous to feed UNIX filenames into this function,
  244.    * this will work most of the time but not always.
  245.    *
  246.    * For example <tt>"/home/Torben%20Weis"</tt> will be considered a URL
  247.    * pointing to the file <tt>"/home/Torben Weis"</tt> instead
  248.    * of to the file <tt>"/home/Torben%20Weis"</tt>.
  249.    *
  250.    * This means that if you have a usual UNIX like path you should not use
  251.    * this constructor. Instead use fromPathOrURL()
  252.    *
  253.    * @param url a URL, not a filename. If the URL does not have a protocol
  254.    *            part, @c "file:" is assumed
  255.    * @param encoding_hint MIB of original encoding of URL.
  256.    *        See QTextCodec::mibEnum()
  257.    *
  258.    * @see fromPathOrURL()
  259.    */
  260.   KURL( const QString& url, int encoding_hint = 0 );
  261.   /**
  262.    * @brief Constructor taking an URL encoded in a C string
  263.    *
  264.    * Constructor taking a char * @p url, which is an @em encoded representation
  265.    * of the URL, exactly like the usual constructor. This is useful when
  266.    * the URL, in its encoded form, is strictly ASCII.
  267.    *
  268.    * @warning It is dangerous to feed UNIX filenames into this function,
  269.    * this will work most of the time but not always.
  270.    *
  271.    * For example <tt>"/home/Torben%20Weis"</tt> will be considered a URL
  272.    * pointing to the file <tt>"/home/Torben Weis"</tt> instead
  273.    * of to the file <tt>"/home/Torben%20Weis"</tt>.
  274.    *
  275.    * This means that if you have a usual UNIX like path you should not use
  276.    * this constructor. Instead use fromPathOrURL()
  277.    *
  278.    * @param url an encoded URL. If the URL does not have a protocol part,
  279.    *            @c "file:" is assumed
  280.    * @param encoding_hint MIB of original encoding of URL.
  281.    *        See QTextCodec::mibEnum()
  282.    *
  283.    * @see fromPathOrURL()
  284.    * @see QString::fromLatin1()
  285.    */
  286.   KURL( const char * url, int encoding_hint = 0 );
  287.   /**
  288.    * @brief Constructor taking an URL encoded in a QCString
  289.    *
  290.    * Constructor taking a QCString @p url, which is an @em encoded
  291.    * representation of the URL, exactly like the usual constructor. This is
  292.    * useful when the URL, in its encoded form, is strictly ASCII.
  293.    *
  294.    * @warning It is dangerous to feed UNIX filenames into this function,
  295.    * this will work most of the time but not always.
  296.    *
  297.    * For example <tt>"/home/Torben%20Weis"</tt> will be considered a URL
  298.    * pointing to the file <tt>"/home/Torben Weis"</tt> instead
  299.    * of to the file <tt>"/home/Torben%20Weis"</tt>.
  300.    *
  301.    * This means that if you have a usual UNIX like path you should not use
  302.    * this constructor. Instead use fromPathOrURL()
  303.    *
  304.    * @param url A encoded URL. If the URL does not have a protocol part,
  305.    *            @c "file:" is assumed
  306.    * @param encoding_hint MIB of original encoding of URL.
  307.    *        See QTextCodec::mibEnum()
  308.    *
  309.    * @see fromPathOrURL()
  310.    * @see QString::fromLatin1()
  311.    */
  312.   KURL( const QCString& url, int encoding_hint = 0 );
  313.  
  314.   /**
  315.    * @brief Copy constructor
  316.    *
  317.    * @param u the KURL to copy
  318.    */
  319.   KURL( const KURL& u );
  320.   /**
  321.    * @brief Constructor taking a Qt URL
  322.    *
  323.    * Converts from a Qt URL.
  324.    *
  325.    * @param u the QUrl
  326.    */
  327.   KURL( const QUrl &u );
  328.   /**
  329.    * @brief Constructor allowing relative URLs
  330.    *
  331.    * @warning It is dangerous to feed UNIX filenames into this function,
  332.    * this will work most of the time but not always.
  333.    *
  334.    * For example <tt>"/home/Torben%20Weis"</tt> will be considered a URL
  335.    * pointing to the file <tt>"/home/Torben Weis"</tt> instead
  336.    * of to the file <tt>"/home/Torben%20Weis"</tt>.
  337.    *
  338.    * This means that if you have a usual UNIX like path you should not use
  339.    * this constructor. Instead use fromPathOrURL()
  340.    *
  341.    * @param _baseurl The base url.
  342.    * @param _rel_url A relative or absolute URL.
  343.    *        If this is an absolute URL then @p _baseurl will be ignored.
  344.    *        If this is a relative URL it will be combined with @p _baseurl.
  345.    *        Note that @p _rel_url should be encoded too, in any case.
  346.    *        So do NOT pass a path here (use setPath() or addPath() or
  347.    *        fromPathOrURL() instead)
  348.    * @param encoding_hint MIB of original encoding of URL.
  349.    *        See QTextCodec::mibEnum()
  350.    *
  351.    * @see fromPathOrURL()
  352.    */
  353.   KURL( const KURL& _baseurl, const QString& _rel_url, int encoding_hint=0 );
  354.  
  355.   /**
  356.    * @brief Returns the protocol for the URL
  357.    *
  358.    * Examples for a protocol string are @c "file", @c "http", etc. but also
  359.    * @c "mailto:" and other pseudo protocols.
  360.    *
  361.    * @return the protocol of the URL, does not include the colon. If the
  362.    *         URL is malformed, @c QString::null will be returned
  363.    *
  364.    * @see setProtocol()
  365.    * @see isValid()
  366.    */
  367.   QString protocol() const { return m_bIsMalformed ? QString::null : m_strProtocol; }
  368.   /**
  369.    * @brief Sets the protocol for the URL
  370.    *
  371.    * Examples for a protocol string are @c "file", @c "http", etc. but also
  372.    * @c "mailto:" and other pseudo protocols.
  373.    *
  374.    * @param _txt the new protocol of the URL (without colon)
  375.    *
  376.    * @see protocol()
  377.    */
  378.   void setProtocol( const QString& _txt );
  379.  
  380.   /**
  381.    * @brief Returns the URI processing mode for the URL
  382.    *
  383.    * @return the URI processing mode set for this URL
  384.    *
  385.    * @see URIMode
  386.    * @see uriModeForProtocol()
  387.    *
  388.    * @since 3.2
  389.    */
  390.   int uriMode() const;
  391.  
  392.   /**
  393.    * @brief Returns the decoded user name (login, user id, etc) included in
  394.    *        the URL
  395.    *
  396.    * @return the user name or @c QString::null if there is no user name
  397.    *
  398.    * @see setUser()
  399.    * @see hasUser()
  400.    */
  401.   QString user() const { return m_strUser; }
  402.   /**
  403.    * @brief Sets the user name (login, user id, etc) to include in the URL
  404.    *
  405.    * Special characters in the user name will appear encoded in the URL.
  406.    * If there is a password associated with the user, it can be set using
  407.    * setPass().
  408.    *
  409.    * @param _txt the name of the user or @c QString::null to remove the user
  410.    *
  411.    * @see user()
  412.    * @see hasUser()
  413.    * @see hasPass()
  414.    */
  415.   void setUser( const QString& _txt );
  416.   /**
  417.    * @brief Tests if this URL has a user name included in it
  418.    *
  419.    * @return @c true if the URL has an non-empty user name
  420.    *
  421.    * @see user()
  422.    * @see setUser()
  423.    * @see hasPass()
  424.    */
  425.   bool hasUser() const { return !m_strUser.isEmpty(); }
  426.  
  427.   /**
  428.    * @brief Returns the decoded password (corresponding to user()) included
  429.    *        in the URL
  430.    *
  431.    * @note a password can only appear in a URL string if you also set
  432.    * a user, see setUser().
  433.    *
  434.    * @return the password or @c QString::null if it does not exist
  435.    *
  436.    * @see setPass()
  437.    * @see hasPass()
  438.    * @see hasUser()
  439.    */
  440.   QString pass() const { return m_strPass; }
  441.   /**
  442.    * @brief Sets the password (corresponding to user()) to include in the URL
  443.    *
  444.    * Special characters in the password will appear encoded in the URL.
  445.    * @note a password can only appear in a URL string if you also set
  446.    * a user, see setUser().
  447.    *
  448.    * @param _txt the password to set or @c QString::null to remove the password
  449.    *
  450.    * @see pass()
  451.    * @see hasPass()
  452.    * @see hasUser()
  453.    */
  454.   void setPass( const QString& _txt );
  455.   /**
  456.    * @brief Tests if this URL has a password included in it
  457.    *
  458.    * @note a password can only appear in a URL string if you also set
  459.    * a user, see setUser().
  460.    *
  461.    * @return @c true if there is a non-empty password set
  462.    *
  463.    * @see pass()
  464.    * @see setPass()
  465.    * @see hasUser()
  466.    */
  467.   bool hasPass() const { return !m_strPass.isEmpty(); }
  468.  
  469.   /**
  470.    * @brief Returns the decoded hostname included in the URL
  471.    *
  472.    * @return the name of the host or @c QString::null if no host is set
  473.    *
  474.    * @see setHost()
  475.    * @see hasHost()
  476.    */
  477.   QString host() const { return m_strHost; }
  478.  
  479.   /**
  480.    * @brief Sets the hostname to include in the URL
  481.    *
  482.    * Special characters in the hostname will appear encoded in the URL.
  483.    *
  484.    * @param _txt the new name of the host or QString::null to remove the host
  485.    *
  486.    * @see host()
  487.    * @see hasHost()
  488.    */
  489.   void setHost( const QString& _txt );
  490.   /**
  491.    * @brief Tests if this URL has a hostname included in it
  492.    *
  493.    * @return @c true if the URL has a non-empty host
  494.    *
  495.    * @see host()
  496.    * @see setHost()
  497.    */
  498.   bool hasHost() const { return !m_strHost.isEmpty(); }
  499.  
  500.   /**
  501.    * @brief Returns the port number included in the URL
  502.    *
  503.    * @return the port number or @c 0 if there is no port number specified in
  504.    *         the URL
  505.    *
  506.    * @see setPort()
  507.    * @see host()
  508.    */
  509.   unsigned short int port() const { return m_iPort; }
  510.   /**
  511.    * @brief Sets the port number to include in the URL
  512.    *
  513.    * @param _p the new port number or @c 0 to have no port number
  514.    *
  515.    * @see port()
  516.    * @see setHost()
  517.    */
  518.   void setPort( unsigned short int _p );
  519.  
  520.   /**
  521.    * @brief Returns the current decoded path
  522.    *
  523.    * This does @em not include the query.
  524.    *
  525.    * @return the path of the URL (without query), or @c QString::null if no
  526.    *         path is set
  527.    *
  528.    * @see path(int)
  529.    * @see setPath()
  530.    * @see hasPath()
  531.    */
  532.   QString path() const  { return m_strPath; }
  533.  
  534.   /**
  535.    * @brief Returns the current decoded path
  536.    *
  537.    * This does @em not include the query, see query() for accessing it.
  538.    *
  539.    * The @p _trailing parameter allows to ensure the existance or absence of
  540.    * the last (trailing) @c '/' character in the path.
  541.    * If the URL has no path, then no @c '/' is added anyway.
  542.    * And on the other side: if the path is just @c "/", then this character
  543.    * won't be stripped.
  544.    *
  545.    * Reason: <tt>"ftp://weis@host"</tt> means something completely different
  546.    * than <tt>"ftp://weis@host/"</tt>.
  547.    * So adding or stripping the '/' would really alter the URL, while
  548.    * <tt>"ftp://host/path"</tt> and <tt>"ftp://host/path/"</tt> mean the same
  549.    * directory.
  550.    *
  551.    * @param _trailing May be ( @c -1, @c 0, @c +1 ). @c -1 strips a trailing
  552.    *                  @c '/', @c +1 adds a trailing @c '/' if there is none yet
  553.    *                  and @c 0 returns the path unchanged
  554.    *
  555.    * @return the path of the URL (without query), or @c QString::null if no
  556.    *         path is set
  557.    *
  558.    * @see path()
  559.    * @see setPath()
  560.    * @see hasPath()
  561.    * @see adjustPath()
  562.    */
  563.   QString path( int _trailing ) const;
  564.  
  565.   /**
  566.    * @brief Sets the decoded path of the URL
  567.    *
  568.    * This does @em not changed the  query, see setQuery() for that.
  569.    *
  570.    * The @p path is considered to be decoded, i.e. characters not allowed in
  571.    * path, for example @c '?' will be encoded and does not indicate the
  572.    * beginning of the query part. Something that might look encoded,
  573.    * like @c "%3f" will not become decoded.
  574.    *
  575.    * @param path the new, decoded, path or @c QString::null to remove the path
  576.    *
  577.    * @see path()
  578.    * @see path(int)
  579.    * @see hasPath()
  580.    */
  581.   void setPath( const QString& path );
  582.  
  583.   /**
  584.    * @brief Tests if this URL has a path included in it
  585.    *
  586.    * @return @c true if there is a non-empty path
  587.    *
  588.    * @see path()
  589.    * @see setPath()
  590.    */
  591.   bool hasPath() const { return !m_strPath.isEmpty(); }
  592.  
  593.   /**
  594.    * @brief Resolves @c "." and @c ".." components in path
  595.    *
  596.    * Some servers seem not to like the removal of extra @c '/'
  597.    * even though it is against the specification in RFC 2396.
  598.    *
  599.    * @param cleanDirSeparator if @c true, occurrences of consecutive
  600.    *        directory separators (e.g. <tt>"/foo//bar"</tt>) are cleaned up as
  601.    *        well
  602.    *
  603.    * @see hasPath()
  604.    * @see adjustPath()
  605.    */
  606.   void cleanPath(bool cleanDirSeparator = true);
  607.  
  608.   /**
  609.    * @brief Adds or removes a trailing slash to/from the path
  610.    *
  611.    * The @p _trailing parameter allows to ensure the existance or absence of
  612.    * the last (trailing) @c '/' character in the path.
  613.    * If the URL has no path, then no @c '/' is added anyway.
  614.    * And on the other side: if the path is just @c "/", then this character
  615.    * won't be stripped.
  616.    *
  617.    * Reason: <tt>"ftp://weis@host"</tt> means something completely different
  618.    * than <tt>"ftp://weis@host/"</tt>.
  619.    * So adding or stripping the '/' would really alter the URL, while
  620.    * <tt>"ftp://host/path"</tt> and <tt>"ftp://host/path/"</tt> mean the same
  621.    * directory.
  622.    *
  623.    * @param _trailing May be ( @c -1, @c 0, @c +1 ). @c -1 strips a trailing
  624.    *                  @c '/', @c +1 adds a trailing @c '/' if there is none yet
  625.    *                  and @c 0 returns the path unchanged
  626.    *
  627.    * @see hasPath()
  628.    * @see cleanPath()
  629.    */
  630.   void adjustPath(int _trailing);
  631.  
  632.   /**
  633.    * @brief Sets both path and query of the URL in their encoded form
  634.    *
  635.    * This is useful for HTTP. It looks first for @c '?' and decodes then,
  636.    * see setEncodedPath().
  637.    * The encoded path is the concatenation of the current path and the query.
  638.    *
  639.    * @param _txt the new encoded path and encoded query
  640.    * @param encoding_hint MIB of original encoding of @p _txt .
  641.    *        See QTextCodec::mibEnum()
  642.    *
  643.    * @see encodedPathAndQuery()
  644.    * @see setPath()
  645.    * @see setQuery()
  646.    */
  647.   void setEncodedPathAndQuery( const QString& _txt, int encoding_hint = 0 );
  648.  
  649.   /**
  650.    * @brief Sets the (already encoded) path of the URL
  651.    *
  652.    * @param _txt the new encoded path
  653.    * @param encoding_hint MIB of original encoding of @p _txt .
  654.    *        See QTextCodec::mibEnum()
  655.    *
  656.    * @see setEncodedPathAndQuery()
  657.    * @see setPath()
  658.    */
  659.   void setEncodedPath(const QString& _txt, int encoding_hint = 0 );
  660.  
  661.   /**
  662.    * @brief Returns the encoded path and the query
  663.    *
  664.    * The @p _trailing parameter allows to ensure the existance or absence of
  665.    * the last (trailing) @c '/' character in the path.
  666.    * If the URL has no path, then no @c '/' is added anyway.
  667.    * And on the other side: if the path is just @c "/", then this character
  668.    * won't be stripped.
  669.    *
  670.    * Reason: <tt>"ftp://weis@host"</tt> means something completely different
  671.    * than <tt>"ftp://weis@host/"</tt>.
  672.    * So adding or stripping the '/' would really alter the URL, while
  673.    * <tt>"ftp://host/path"</tt> and <tt>"ftp://host/path/"</tt> mean the same
  674.    * directory.
  675.    *
  676.    * @param _trailing May be ( @c -1, @c 0, @c +1 ). @c -1 strips a trailing
  677.    *                  @c '/', @c +1 adds a trailing @c '/' if there is none yet
  678.    *                  and @c 0 returns the path unchanged
  679.    * @param _no_empty_path if set to @c true then an empty path is substituted
  680.    *        by @c "/"
  681.    * @param encoding_hint MIB of desired encoding of URL.
  682.    *        See QTextCodec::mibEnum()
  683.    *
  684.    * @return the concatenation of the encoded path , @c '?' and the
  685.    *         encoded query
  686.    *
  687.    * @see setEncodedPathAndQuery()
  688.    * @see path()
  689.    * @see query()
  690.    */
  691.   QString encodedPathAndQuery( int _trailing = 0, bool _no_empty_path = false, int encoding_hint = 0) const;
  692.  
  693.   /**
  694.    * @brief Sets the encoded query of the URL
  695.    *
  696.    * The query should start with a @c '?'. If it doesn't @c '?' is prepended.
  697.    *
  698.    * @param _txt this is considered to be encoded. This has a good reason:
  699.    *             the query may contain the @c '0' character
  700.    *
  701.    * @param encoding_hint MIB of the encoding. Reserved, should be @c 0 .
  702.    *        See QTextCodec::mibEnum()
  703.    *
  704.    * @see query()
  705.    */
  706.   void setQuery( const QString& _txt, int encoding_hint = 0);
  707.  
  708.   /**
  709.    * @brief Returns the encoded query of the URL
  710.    *
  711.    * The query may contain the @c '0' character.
  712.    * If a query is present it always starts with a @c '?'.
  713.    * A single @c '?' means an empty query.
  714.    * An empty string means no query.
  715.    *
  716.    * @return the encoded query or @c QString::null if there is none
  717.    *
  718.    * @see setQuery()
  719.    */
  720.   QString query() const;
  721.  
  722.   /**
  723.    * @brief Returns the encoded reference of the URL
  724.    *
  725.    * The reference is @em never decoded automatically.
  726.    *
  727.    * @return the undecoded reference, or @c QString::null if there is none
  728.    *
  729.    * @see setRef()
  730.    * @see hasRef()
  731.    * @see htmlRef()
  732.    */
  733.   QString ref() const { return m_strRef_encoded; }
  734.  
  735.   /**
  736.    * @brief Sets the encoded reference part (everything after @c '#')
  737.    *
  738.    * This is considered to be encoded, i.e. characters that are not allowed
  739.    * as part of the reference will @em not be encoded.
  740.    *
  741.    * @param _txt the encoded reference or @c QString::null to remove it
  742.    *
  743.    * @see ref()
  744.    * @see hasRef()
  745.    */
  746.   void setRef( const QString& _txt ) { m_strRef_encoded = _txt; }
  747.  
  748.   /**
  749.    * @brief Tests if the URL has a reference part
  750.    *
  751.    * @return @c true if the URL has a reference part. In a URL like
  752.    *         <tt>"http://www.kde.org/kdebase.tar#tar:/README"</tt> it would
  753.    *         return @c true as well
  754.    *
  755.    * @see ref()
  756.    * @see setRef()
  757.    */
  758.   bool hasRef() const { return !m_strRef_encoded.isNull(); }
  759.  
  760.   /**
  761.    * @brief Returns decoded the HTML-style reference
  762.    *        (the part of the URL after @c '#')
  763.    *
  764.    * @return the HTML-style reference
  765.    *
  766.    * @see encodedHtmlRef()
  767.    * @see setHTMLRef()
  768.    * @see hasHTMLRef()
  769.    * @see split()
  770.    * @see hasSubURL()
  771.    * @see ref()
  772.    */
  773.   QString htmlRef() const;
  774.  
  775.   /**
  776.    * @brief Returns the encoded HTML-style reference
  777.    *        (the part of the URL after @c '#')
  778.    *
  779.    * @return the HTML-style reference in its original, encoded, form
  780.    *
  781.    * @see htmlRef()
  782.    * @see setHTMLRef()
  783.    * @see hasHTMLRef()
  784.    */
  785.   QString encodedHtmlRef() const;
  786.  
  787.   /**
  788.    * @brief Sets the decoded HTML-style reference
  789.    *
  790.    * @param _ref the new reference. This is considered to be @em not encoded in
  791.    *         contrast to setRef(). Use @c QString::null to remove it
  792.    *
  793.    * @see htmlRef()
  794.    * @see hasHTMLRef()
  795.    */
  796.   void setHTMLRef( const QString& _ref );
  797.  
  798.   /**
  799.    * @brief Tests if there is an HTML-style reference
  800.    *
  801.    * @return @c true if the URL has an HTML-style reference
  802.    *
  803.    * @see htmlRef()
  804.    * @see encodedHtmlRef()
  805.    * @see setHTMLRef()
  806.    * @see hasRef()
  807.    */
  808.   bool hasHTMLRef() const;
  809.  
  810.   /**
  811.    * @brief Tests if the URL is well formed
  812.    *
  813.    * @return @c false if the URL is malformed. This function does @em not test
  814.    *         whether sub URLs are well-formed as well
  815.    */
  816.   bool isValid() const  { return !m_bIsMalformed; }
  817.   /**
  818.    * @brief Tests if the URL is malformed
  819.    *
  820.    * @return @c true if the URL is malformed. This function does @em not test
  821.    *         whether sub URLs are well-formed as well
  822.    *
  823.    * @deprecated Use !isValid() instead
  824.    *
  825.    * @see isValid()
  826.    */
  827.   KDE_DEPRECATED bool isMalformed() const { return !isValid(); }
  828.  
  829.   /**
  830.    * @brief Tests if the file is local
  831.    *
  832.    * @return @c true if the file is a plain local file and has no filter
  833.    *         protocols attached to it
  834.    */
  835.   bool isLocalFile() const;
  836.  
  837.   /**
  838.    * @brief Adds file encoding information
  839.    *
  840.    * Adds encoding information to the URL by adding a @c "charset" parameter.
  841.    * If there is already a charset parameter, it will be replaced.
  842.    *
  843.    * @param encoding the encoding to add or @c QString::null to remove the
  844.    *                 encoding
  845.    *
  846.    * @see fileEncoding()
  847.    * @see QTextCodec::codecForName()
  848.    */
  849.   void setFileEncoding(const QString &encoding);
  850.  
  851.   /**
  852.    * @brief Returns encoding information of the URL
  853.    *
  854.    * The encoding information is the content of the @c "charset" parameter.
  855.    *
  856.    * @return an encoding suitable for QTextCodec::codecForName()
  857.    *         or @c QString::null if not encoding was specified
  858.    */
  859.   QString fileEncoding() const;
  860.  
  861.   /**
  862.    * @brief Tests if the URL has any sub URLs
  863.    *
  864.    * See split() for examples for sub URLs.
  865.    *
  866.    * @return @c true if the file has at least one sub URL
  867.    *
  868.    * @see split()
  869.    */
  870.   bool hasSubURL() const;
  871.  
  872.   /**
  873.    * @brief Adds to the current path
  874.    *
  875.    * Assumes that the current path is a directory. @p _txt is appended to the
  876.    * current path. The function adds @c '/' if needed while concatenating.
  877.    * This means it does not matter whether the current path has a trailing
  878.    * @c '/' or not. If there is none, it becomes appended. If @p _txt
  879.    * has a leading @c '/' then this one is stripped.
  880.    *
  881.    * @param txt the text to add. It is considered to be decoded
  882.    *
  883.    * @see setPath()
  884.    * @see hasPath()
  885.    */
  886.   void addPath( const QString& txt );
  887.  
  888.   /**
  889.    * @brief Returns the value of a certain query item
  890.    *
  891.    * @param item item whose value we want
  892.    *
  893.    * @return the value of the given query item name or @c QString::null if the
  894.    *         specified item does not exist
  895.    *
  896.    * @see addQueryItem()
  897.    * @see removeQueryItem()
  898.    * @see queryItems()
  899.    * @see query()
  900.    */
  901.   QString queryItem( const QString& item ) const;
  902.  
  903.   /**
  904.    * @brief Returns the value of a certain query item
  905.    *
  906.    * @param item item whose value we want
  907.    * @param encoding_hint MIB of encoding of query.
  908.    *        See QTextCodec::mibEnum()
  909.    *
  910.    * @return the value of the given query item name or @c QString::null if the
  911.    *         specified item does not exist
  912.    *
  913.    * @see addQueryItem()
  914.    * @see removeQueryItem()
  915.    * @see queryItems()
  916.    * @see query()
  917.    */
  918.   QString queryItem( const QString& item, int encoding_hint ) const;
  919.  
  920.   /**
  921.    * Options for queryItems()
  922.    *
  923.    * @since 3.1
  924.    */
  925.   enum QueryItemsOptions
  926.   {
  927.     /**
  928.      * Normalize query keys to lowercase
  929.      */
  930.     CaseInsensitiveKeys = 1
  931.   };
  932.  
  933.   /**
  934.    * @internal, override for the below function
  935.    */
  936.   QMap< QString, QString > queryItems( int options=0 ) const;
  937.  
  938.   /**
  939.    * @brief Returns the list of query items as a map mapping keys to values
  940.    *
  941.    * @param options any of QueryItemsOptions <em>OR</em>ed together
  942.    * @param encoding_hint MIB of encoding of query.
  943.    *        See QTextCodec::mibEnum()
  944.    *
  945.    * @return the map of query items or the empty map if the URL has no
  946.    *         query items
  947.    *
  948.    * @see queryItem()
  949.    * @see addQueryItem()
  950.    * @see removeQueryItem()
  951.    * @see query()
  952.    *
  953.    * @since 3.1
  954.    */
  955.   QMap< QString, QString > queryItems( int options, int encoding_hint ) const;
  956.  
  957.   /**
  958.    * @brief Adds an additional query item
  959.    *
  960.    * To replace an existing query item, the item should first be
  961.    * removed with removeQueryItem()
  962.    *
  963.    * @param _item name of item to add
  964.    * @param _value value of item to add
  965.    * @param encoding_hint MIB of encoding to use for _value.
  966.    *        See QTextCodec::mibEnum()
  967.    *
  968.    * @see queryItem()
  969.    * @see queryItems()
  970.    * @see query()
  971.    */
  972.   void addQueryItem( const QString& _item, const QString& _value, int encoding_hint = 0 );
  973.  
  974.   /**
  975.    * @brief Removea an item from the query
  976.    *
  977.    * @param _item name of item to remove
  978.    *
  979.    * @see addQueryItem()
  980.    * @see queryItem()
  981.    * @see queryItems()
  982.    * @see query()
  983.    */
  984.   void removeQueryItem( const QString& _item );
  985.  
  986.   /**
  987.    * @brief Sets the filename of the path
  988.    *
  989.    * In comparison to addPath() this function does not assume that the current
  990.    * path is a directory. This is only assumed if the current path ends
  991.    * with @c '/'.
  992.    *
  993.    * If the current path ends with @c '/' then @p _txt is just appended,
  994.    * otherwise all text behind the last @c '/' in the current path is erased
  995.    * and @p _txt is appended then. It does not matter whether @p _txt starts
  996.    * with @c '/' or not.
  997.    *
  998.    * Any reference is reset.
  999.    *
  1000.    * @param _txt the filename to be set. It is considered to be decoded
  1001.    *
  1002.    * @see fileName()
  1003.    * @see setDirectory()
  1004.    * @see setPath()
  1005.    */
  1006.   void setFileName( const QString&_txt );
  1007.  
  1008.   /**
  1009.    * @brief Returns the filename of the path
  1010.    *
  1011.    * @p _ignore_trailing_slash_in_path tells whether a trailing @c '/' should
  1012.    * be ignored. This means that the function would return @c "torben" for
  1013.    * <tt>"file:///hallo/torben/"</tt> and <tt>"file:///hallo/torben"</tt>.
  1014.    *
  1015.    * @param _ignore_trailing_slash_in_path if set to @c false, then everything
  1016.    *        behind the last @c '/' is considered to be the filename
  1017.    *
  1018.    * @return the filename of the current path. The returned string is decoded.
  1019.    *         @c QString::null if there is no file (and thus no path)
  1020.    *
  1021.    * @see setFileName()
  1022.    * @see directory()
  1023.    * @see path()
  1024.    */
  1025.   QString fileName( bool _ignore_trailing_slash_in_path = true ) const;
  1026.  
  1027.   /**
  1028.    * @brief Returns the directory of the path
  1029.    *
  1030.    * The directory is everything between the last and the second last @c '/'
  1031.    * is returned. For example <tt>"file:///hallo/torben/"</tt> would return
  1032.    * <tt>"/hallo/torben/"</tt> while <tt>"file:///hallo/torben"</tt> would
  1033.    * return <tt>"hallo/"</tt>.
  1034.    *
  1035.    * @p _ignore_trailing_slash_in_path tells whether a trailing @c '/' should
  1036.    * be ignored. This means that the function would return @c "/hallo"
  1037.    * (or @c "/hallo" depending on @p _strip_trailing_slash_from_result) for
  1038.    * <tt>"file:///hallo/torben/"</tt> and <tt>"file:///hallo/torben"</tt>.
  1039.    *
  1040.    * @param _strip_trailing_slash_from_result tells whether the returned result
  1041.    *        should end with @c '/' or not. If the path is empty or just @c "/"
  1042.    *        then this flag has no effect
  1043.    * @param _ignore_trailing_slash_in_path if set to @c false, then everything
  1044.    *        behind the last @c '/' is considered to be the filename
  1045.    *
  1046.    * @return the directory part of the current path or @c QString::null when
  1047.    *         there is no path. The returned string is decoded
  1048.    *
  1049.    * @see setDirectory()
  1050.    * @see fileName()
  1051.    * @see path()
  1052.    */
  1053.   QString directory( bool _strip_trailing_slash_from_result = true,
  1054.              bool _ignore_trailing_slash_in_path = true ) const;
  1055.  
  1056.   /**
  1057.    * @brief Sets the directory of the path, leaving the filename empty
  1058.    *
  1059.    * @param dir the decoded directory to set
  1060.    *
  1061.    * @see directory()
  1062.    * @see setFileName()
  1063.    * @see setPath()
  1064.    */
  1065.   void setDirectory(const QString &dir);
  1066.  
  1067.   /**
  1068.    * @brief Changes the directory by descending into the given directory
  1069.    *
  1070.    * It is assumed the current URL represents a directory.
  1071.    * If @p _dir starts with a @c '/' the current URL will be
  1072.    * <tt>"protocol://host/dir"</tt> otherwise @p _dir will be appended to the
  1073.    * path. @p _dir can be @c ".."
  1074.    *
  1075.    * This function won't strip protocols. That means that when you are in
  1076.    * <tt>"file:///dir/dir2/my.tgz#tar:/"</tt> and you do <tt>cd("..")</tt> you
  1077.    * will still be in <tt>"file:///dir/dir2/my.tgz#tar:/"</tt>
  1078.    *
  1079.    * @param _dir the directory to change to
  1080.    * @return @c true if successful
  1081.    *
  1082.    * @see directory()
  1083.    * @see path()
  1084.    */
  1085.   bool cd( const QString& _dir );
  1086.  
  1087.   /**
  1088.    * @brief Returns the URL as string, with all escape sequences intact,
  1089.    *        encoded in a given charset
  1090.    *
  1091.    * This is used in particular for encoding URLs in UTF-8 before using them
  1092.    * in a drag and drop operation.
  1093.    *
  1094.    * @note that the string returned by url() will include the password of the
  1095.    * URL. If you want to show the URL to the user, use prettyURL().
  1096.    *
  1097.    * The @p _trailing parameter allows to ensure the existance or absence of
  1098.    * the last (trailing) @c '/' character in the path.
  1099.    * If the URL has no path, then no @c '/' is added anyway.
  1100.    * And on the other side: if the path is just @c "/", then this character
  1101.    * won't be stripped.
  1102.    *
  1103.    * Reason: <tt>"ftp://weis@host"</tt> means something completely different
  1104.    * than <tt>"ftp://weis@host/"</tt>.
  1105.    * So adding or stripping the '/' would really alter the URL, while
  1106.    * <tt>"ftp://host/path"</tt> and <tt>"ftp://host/path/"</tt> mean the same
  1107.    * directory.
  1108.    *
  1109.    * @param _trailing May be ( @c -1, @c 0, @c +1 ). @c -1 strips a trailing
  1110.    *                  @c '/', @c +1 adds a trailing @c '/' if there is none yet
  1111.    *                  and @c 0 returns the path unchanged
  1112.    * @param encoding_hint MIB of encoding to use.
  1113.    *        See QTextCodec::mibEnum()
  1114.    *
  1115.    * @return the complete URL, with all escape sequences intact, encoded
  1116.    *         in a given charset
  1117.    *
  1118.    * @see prettyURL()
  1119.    * @see pathOrURL()
  1120.    * @see htmlURL()
  1121.    */
  1122.   QString url( int _trailing = 0, int encoding_hint = 0) const;
  1123.  
  1124.   /**
  1125.    * @brief Returns the URL as string in human-friendly format
  1126.    *
  1127.    * Example:
  1128.    * @code
  1129.    * http://localhost:8080/test.cgi?test=hello world&name=fred
  1130.    * @endcode
  1131.    *
  1132.    * Does @em not contain the password if the URL has one, use url() if you
  1133.    * need to have it in the string.
  1134.    *
  1135.    * The @p _trailing parameter allows to ensure the existance or absence of
  1136.    * the last (trailing) @c '/' character in the path.
  1137.    * If the URL has no path, then no @c '/' is added anyway.
  1138.    * And on the other side: if the path is just @c "/", then this character
  1139.    * won't be stripped.
  1140.    *
  1141.    * Reason: <tt>"ftp://weis@host"</tt> means something completely different
  1142.    * than <tt>"ftp://weis@host/"</tt>.
  1143.    * So adding or stripping the '/' would really alter the URL, while
  1144.    * <tt>"ftp://host/path"</tt> and <tt>"ftp://host/path/"</tt> mean the same
  1145.    * directory.
  1146.    *
  1147.    * @param _trailing May be ( @c -1, @c 0, @c +1 ). @c -1 strips a trailing
  1148.    *                  @c '/', @c +1 adds a trailing @c '/' if there is none yet
  1149.    *                  and @c 0 returns the path unchanged
  1150.    * @return a human readable URL, with no non-necessary encodings/escaped
  1151.    *         characters. Password will not be shown
  1152.    *
  1153.    * @see url()
  1154.    * @see pathOrURL()
  1155.    */
  1156.   QString prettyURL( int _trailing = 0) const;
  1157.  
  1158.   /**
  1159.    * @brief Returns the URL as string in human-friendly format
  1160.    * Example:
  1161.    * @code
  1162.    * http://localhost:8080/test.cgi?test=hello world&name=fred
  1163.    * @endcode
  1164.    *
  1165.    * Does @em not contain the password if the URL has one, use url() if you
  1166.    * need to have it in the string.
  1167.    *
  1168.    * The @p _trailing parameter allows to ensure the existance or absence of
  1169.    * the last (trailing) @c '/' character in the path.
  1170.    * If the URL has no path, then no @c '/' is added anyway.
  1171.    * And on the other side: if the path is just @c "/", then this character
  1172.    * won't be stripped.
  1173.    *
  1174.    * Reason: <tt>"ftp://weis@host"</tt> means something completely different
  1175.    * than <tt>"ftp://weis@host/"</tt>.
  1176.    * So adding or stripping the '/' would really alter the URL, while
  1177.    * <tt>"ftp://host/path"</tt> and <tt>"ftp://host/path/"</tt> mean the same
  1178.    * directory.
  1179.    *
  1180.    * @param _trailing May be ( @c -1, @c 0, @c +1 ). @c -1 strips a trailing
  1181.    *                  @c '/', @c +1 adds a trailing @c '/' if there is none yet
  1182.    *                  and @c 0 returns the path unchanged
  1183.    * @param _flags if StripFileProtocol, @c "file://" will be stripped.
  1184.    *        The use of this method is now discouraged, better use pathOrURL().
  1185.    *
  1186.    * @return a human readable URL, with no non-necessary encodings/escaped
  1187.    *         characters. Password will not be shown
  1188.    *
  1189.    * @see prettyURL()
  1190.    * @see url()
  1191.    * @see pathOrURL()
  1192.    */
  1193.   QString prettyURL( int _trailing, AdjustementFlags _flags) const;
  1194.   // ### BIC: Merge the two above + spell it as "Adjustment"
  1195.   // Or remove completely, and let people use pathOrURL() instead
  1196.  
  1197.   /**
  1198.    * @brief Returns the URL as a string depending if it is a local file
  1199.    *
  1200.    * It will be either the URL (as prettyURL() would return) or, when the URL
  1201.    * is a local file without query or ref, the path().
  1202.    *
  1203.    * Use this method, together with its opposite, fromPathOrURL(),
  1204.    * to display and even let the user edit URLs.
  1205.    *
  1206.    * @return the path or URL string depending on its properties
  1207.    *
  1208.    * @see prettyURL()
  1209.    * @see path()
  1210.    * @see url()
  1211.    * @see isLocalFile()
  1212.    *
  1213.    * @since 3.4
  1214.    */
  1215.   QString pathOrURL() const;
  1216.  
  1217.   /**
  1218.    * @brief Returns the URL as string, escaped for HTML
  1219.    *
  1220.    * @return a human readable URL, with no non-necessary encodings/escaped
  1221.    *         characters which is HTML encoded for safe inclusion in HTML or
  1222.    *         rich text. Password will not be shown.
  1223.    *
  1224.    * @see prettyURL()
  1225.    * @see url()
  1226.    * @see pathOrURL()
  1227.    */
  1228.   QString htmlURL() const;
  1229.  
  1230.  
  1231.   /**
  1232.    * @brief Tests if the KURL is empty
  1233.    *
  1234.    * An empty URL has neither path nor protocol set.
  1235.    *
  1236.    * @return @c true if the URL is empty
  1237.    *
  1238.    * @see hasPath()
  1239.    * @see protocol()
  1240.    * @see isValid()
  1241.    */
  1242.   bool isEmpty() const;
  1243.  
  1244.   /**
  1245.    * @brief Returns the URL that is the best possible candidate for on level
  1246.    *        higher in the path hierachy
  1247.    *
  1248.    * This function is useful to implement the "Up" button in a file manager for
  1249.    * example.
  1250.    * cd() never strips a sub-protocol. That means that if you are in
  1251.    * <tt>"file:///home/x.tgz#gzip:/#tar:/"</tt> and hit the up button you
  1252.    * expect to see <tt>"file:///home"</tt>. The algorithm tries to go up on the
  1253.    * right-most URL. If that is not possible it strips the right most URL. It
  1254.    * continues stripping URLs until it can go up.
  1255.    *
  1256.    * @return a URL that is a level higher
  1257.    *
  1258.    * @see cd()
  1259.    * @see split()
  1260.    * @see hasSubURL()
  1261.    * @see path()
  1262.    */
  1263.   KURL upURL( ) const;
  1264.  
  1265.   /**
  1266.    * @brief Tests if this URL is less than the given URL
  1267.    *
  1268.    * The current URL is consideres <tt>"less than"</tt> then @p _u if
  1269.    * (tested in this order):
  1270.    * - it is not valid but @p _u is. See isValid()
  1271.    * - its protocol is "less than" @p _u's protocol. See protocol()
  1272.    * - its host is "less than" @p _u's host. See host()
  1273.    * - its port is "less than" @p _u's port. See port()
  1274.    * - its path is "less than" @p _u's path. See path()
  1275.    * - its encoded query is "less than" @p _u's encoded query. See query()
  1276.    * - its endoded reference is "less than" @p _u's encoded reference.
  1277.    *   See ref()
  1278.    * - its username is "less than" @p _u's username. See user()
  1279.    * - its password is "less than" @p _u's password. See pass()
  1280.    *
  1281.    * Examples:
  1282.    * @code
  1283.    * KURL url1;
  1284.    * KURL url2;
  1285.    *
  1286.    * bool lessThan = url1 < url2; // false. Both invalid, no protocols
  1287.    *
  1288.    * url2.setProtocol( QString::null );
  1289.    * lessThan = url1 < url2;            // true. url2 is valid because of setProtocol()
  1290.    *
  1291.    * url1.setProtocol( QString::null );
  1292.    * lessThan = url1 < url2;            // false. Both valid and everything empty
  1293.    *
  1294.    * url1.setProtocol( "http" );
  1295.    * url2.setProtocol( "https" );
  1296.    * lessThan = url1 < url2;            // true. "http" < "https"
  1297.    *
  1298.    * url2.setHost( "api.kde.org" );
  1299.    * url2.setProtocol( "http" );
  1300.    * url2.setProtocol( "www.kde.org" );
  1301.    * lessThan = url1 < url2;            // true. protocols equal and "api" < "www"
  1302.    *
  1303.    * url1.setProtocol( "https" );
  1304.    * url2.setProtocol( "http" );
  1305.    * lessThan = url1 < url2;            // false. "https" > "http". host doesn't matter yet
  1306.    * @endcode
  1307.    *
  1308.    * @param _u the URL to compare to
  1309.    *
  1310.    * @return @c true if the URL is less than @p _u. Otherwise @c false
  1311.    *         (equal or greater than)
  1312.    *
  1313.    * @see operator==()
  1314.    * @see QString::compare()
  1315.    */
  1316.   bool operator<(const KURL& _u) const;
  1317.  
  1318.   /**
  1319.    * @brief Copies the values of the given URL into this one
  1320.    *
  1321.    * Just assigns each member using the member's assignment operator.
  1322.    *
  1323.    * @param _u the URL to take the values from
  1324.    *
  1325.    * @return a reference to this URL (*this)
  1326.    *
  1327.    * @see equals()
  1328.    */
  1329.   KURL& operator=( const KURL& _u );
  1330.  
  1331.   /**
  1332.    * @brief Assigns the URL, given as a string, to this one
  1333.    *
  1334.    * This will reset the current URL and parse the given string.
  1335.    * See the similar constructor for known limitations.
  1336.    *
  1337.    * @param _url the QString to parse for values
  1338.    *
  1339.    * @return a reference to this URL (*this)
  1340.    *
  1341.    * @see equals()
  1342.    * @see KURL(const QString &, int)
  1343.    */
  1344.   KURL& operator=( const QString& _url );
  1345.  
  1346.   /**
  1347.    * @brief Assigns the URL, given as a C string, to this one
  1348.    *
  1349.    * This will reset the current URL and parse the given string.
  1350.    * See the similar constructor for known limitations.
  1351.    *
  1352.    * @param _url the C string to parse for values
  1353.    *
  1354.    * @return a reference to this URL (*this)
  1355.    *
  1356.    * @see equals()
  1357.    * @see KURL(const char *, int)
  1358.    */
  1359.   KURL& operator=( const char * _url );
  1360.  
  1361.   /**
  1362.    * @brief Assigns the URL, given as a Qt URL, to this one
  1363.    *
  1364.    * This will reset the current URL and parse the given string.
  1365.    *
  1366.    * @param u the Qt URL to take the values from
  1367.    *
  1368.    * @return a reference to this URL (*this)
  1369.    *
  1370.    * @see equals()
  1371.    * @see KURL(const QUrl &)
  1372.    */
  1373.   KURL& operator=( const QUrl & u );
  1374.  
  1375.   /**
  1376.    * @brief Tests if this URL is equal to the given one
  1377.    *
  1378.    * Tests each member for equality unless one of the URLs is invalid
  1379.    * in which case they are not considered equal (even if both are invalid).
  1380.    *
  1381.    * Same as equals() when used with @p ignore_trailing set to
  1382.    * @c false (default)
  1383.    *
  1384.    * @param _u the URL to compare to
  1385.    *
  1386.    * @return @c true if equal and neither this URL nor @p _u is malformed.
  1387.    *         Otherwise @c false
  1388.    *
  1389.    * @see equals()
  1390.    * @see isValid()
  1391.    * @see operator!=()
  1392.    * @see operator<()
  1393.    */
  1394.   bool operator==( const KURL& _u ) const;
  1395.  
  1396.   /**
  1397.    * @brief Tests if this URL is equal to the one given as a string
  1398.    *
  1399.    * Creates a KURL instance for @p _u and compares with that using
  1400.    * the equality operator for two KURLs.
  1401.    *
  1402.    * See the respective constructor for known limitations.
  1403.    *
  1404.    * @param _u the string to compare to
  1405.    *
  1406.    * @return @c true if equal and neither this URL nor @p _u is malformed.
  1407.    *         Otherwise @c false
  1408.    *
  1409.    * @see KURL(const QString &, int)
  1410.    * @see operator==(const KURL &)
  1411.    * @see equals()
  1412.    * @see isValid()
  1413.    * @see operator!=()
  1414.    * @see operator<()
  1415.    */
  1416.   bool operator==( const QString& _u ) const;
  1417.  
  1418.   /**
  1419.    * @brief Tests if this URL is different from the given one
  1420.    *
  1421.    * Tests by negating the result of operator==()
  1422.    *
  1423.    * @param _u the URL to compare to
  1424.    *
  1425.    * @return the negated result of operator==()
  1426.    *
  1427.    * @see operator==()
  1428.    * @see operator<()
  1429.    */
  1430.   bool operator!=( const KURL& _u ) const { return !( *this == _u ); }
  1431.  
  1432.   /**
  1433.    * @brief Tests if this URL is different from the one given as a string
  1434.    *
  1435.    * Tests by negating the result of operator==(const QString &)
  1436.    *
  1437.    * @param _u the URL to compare to
  1438.    *
  1439.    * @return the negated result of operator==(const QString &)
  1440.    *
  1441.    * @see operator==(const QString &)
  1442.    * @see operator<()
  1443.    */
  1444.   bool operator!=( const QString& _u ) const { return !( *this == _u ); }
  1445.  
  1446.   /**
  1447.    * @brief Compares this URL with another one
  1448.    *
  1449.    * The same as equals(), just with a less obvious name.
  1450.    *
  1451.    * @param u the URL to compare this one with
  1452.    * @param ignore_trailing set to @c true to ignore trailing @c '/' characters
  1453.    *
  1454.    * @return @c true if both URLs are the same
  1455.    *
  1456.    * @see operator==. This function should be used if you want to
  1457.    *      ignore trailing @c '/' characters
  1458.    *
  1459.    * @deprecated Use equals() instead.
  1460.    */
  1461.   bool cmp( const KURL &u, bool ignore_trailing = false ) const KDE_DEPRECATED;
  1462.  
  1463.   /**
  1464.    * @brief Compares this URL with another one
  1465.    *
  1466.    * @param u the URL to compare this one with
  1467.    * @param ignore_trailing set to @c true to ignore trailing @c '/' characters
  1468.    *
  1469.    * @return @c true if both urls are the same
  1470.    *
  1471.    * @see operator==. This function should be used if you want to
  1472.    *      ignore trailing @c '/' characters
  1473.    *
  1474.    * @since 3.1
  1475.    */
  1476.   bool equals( const KURL &u, bool ignore_trailing = false ) const; // TODO KDE4: add bool _ignore_ref = false
  1477.  
  1478.   /**
  1479.    * @brief Tests if the given URL is parent of this URL
  1480.    *
  1481.    * For instance, <tt>"ftp://host/dir/"</tt> is a parent of
  1482.    * <tt>"ftp://host/dir/subdir/subsubdir/"</tt>.
  1483.    *
  1484.    * @return @c true if this URL is a parent of @p u (or the same URL as @p u)
  1485.    *
  1486.    * @see equals()
  1487.    * @see cd()
  1488.    */
  1489.   bool isParentOf( const KURL& u ) const;
  1490.  
  1491.   /**
  1492.    * @brief Splits nested URLs into a list of URLs
  1493.    *
  1494.    * Example for a nested URL:
  1495.    * @code
  1496.    * file:///home/weis/kde.tgz#gzip:/#tar:/kdebase
  1497.    * @endcode
  1498.    * A URL like <tt>"http://www.kde.org#tar:/kde/README.hml#ref1"</tt> will be
  1499.    * split in <tt>"http://www.kde.org#ref1"</tt> and
  1500.    * <tt>"tar:/kde/README.html#ref1"</tt>.
  1501.    *
  1502.    * That means in turn that @c "#ref1" is an HTML-style reference and not a
  1503.    * new sub URL. Since HTML-style references mark a certain position in a
  1504.    * document this reference is appended to every URL.
  1505.    *
  1506.    * The idea behind this is that browsers, for example, only look at the first
  1507.    * URL while the rest is not of interest to them.
  1508.    *
  1509.    * @param _url the URL that has to be split
  1510.    *
  1511.    * @return an empty list on error or the list of split URLs
  1512.    *
  1513.    * @see hasSubURL()
  1514.    * @see KURL(const QString&, int)
  1515.    * @see join()
  1516.    */
  1517.   static List split( const QString& _url );
  1518.  
  1519.   /**
  1520.    * @brief Splits nested URLs into a list of URLs
  1521.    *
  1522.    * Example for a nested URL:
  1523.    * @code
  1524.    * file:///home/weis/kde.tgz#gzip:/#tar:/kdebase
  1525.    * @endcode
  1526.    * A URL like <tt>"http://www.kde.org#tar:/kde/README.hml#ref1"</tt> will be
  1527.    * split in <tt>"http://www.kde.org#ref1"</tt> and
  1528.    * <tt>"tar:/kde/README.html#ref1"</tt>.
  1529.    *
  1530.    * That means in turn that @c "#ref1" is an HTML-style reference and not a
  1531.    * new sub URL. Since HTML-style references mark a certain position in a
  1532.    * document this reference is appended to every URL.
  1533.    *
  1534.    * The idea behind this is that browsers, for example, only look at the first
  1535.    * URL while the rest is not of interest to them.
  1536.    *
  1537.    * @param _url the URL that has to be split
  1538.    *
  1539.    * @return an empty list on error or the list of split URLs
  1540.    *
  1541.    * @see hasSubURL()
  1542.    * @see join()
  1543.    */
  1544.   static List split( const KURL& _url );
  1545.  
  1546.   /**
  1547.    * @brief Joins a list of URLs into a single URL with sub URLs
  1548.    *
  1549.    * Reverses split(). Only the first URL may have a reference. This reference
  1550.    * is considered to be HTML-like and is appended at the end of the resulting
  1551.    * joined URL.
  1552.    *
  1553.    * @param _list the list to join
  1554.    *
  1555.    * @return the joined URL or an invalid URL if the list is empty
  1556.    *
  1557.    * @see split()
  1558.    */
  1559.   static KURL join( const List& _list );
  1560.  
  1561.   /**
  1562.    * @brief Creates a KURL object from a QString representing either an
  1563.    *        absolute path or a real URL
  1564.    *
  1565.    * Use this method instead of
  1566.    * @code
  1567.    * QString someDir = ...
  1568.    * KURL url = someDir;
  1569.    * @endcode
  1570.    *
  1571.    * Otherwise some characters (e.g. the '#') won't be encoded properly.
  1572.    *
  1573.    * @param text the string representation of the URL to convert
  1574.    *
  1575.    * @return the new KURL
  1576.    *
  1577.    * @see pathOrURL()
  1578.    * @see KURL(const QString&, int)
  1579.    *
  1580.    * @since 3.1
  1581.    */
  1582.   static KURL fromPathOrURL( const QString& text );
  1583.  
  1584.   /**
  1585.    * @brief Encodes a string for use in URLs
  1586.    *
  1587.    * Convenience function.
  1588.    *
  1589.    * Convert unicoded string to local encoding and use %%-style
  1590.    * encoding for all common delimiters / non-ascii characters.
  1591.    *
  1592.    * @param str the string to encode (can be @c QString::null)
  1593.    * @param encoding_hint MIB of encoding to use.
  1594.    *        See QTextCodec::mibEnum()
  1595.    *
  1596.    * @return the encoded string
  1597.    *
  1598.    * @see encode_string_no_slash()
  1599.    * @see decode_string()
  1600.    */
  1601.   static QString encode_string(const QString &str, int encoding_hint = 0);
  1602.  
  1603.   /**
  1604.    * @brief Encodes a string for use in URLs
  1605.    *
  1606.    * Convenience function.
  1607.    *
  1608.    * Convert unicoded string to local encoding and use %%-style
  1609.    * encoding for all common delimiters and non-ascii characters
  1610.    * as well as the slash @c '/'.
  1611.    *
  1612.    * @param str the string to encode (can be @c QString::null)
  1613.    * @param encoding_hint MIB of encoding to use.
  1614.    *        See QTextCodec::mibEnum()
  1615.    *
  1616.    * @see encode_string()
  1617.    * @see decode_string()
  1618.    */
  1619.   static QString encode_string_no_slash(const QString &str, int encoding_hint = 0);
  1620.  
  1621.   /**
  1622.    * @brief Decodes a string as used in URLs
  1623.    *
  1624.    * Convenience function.
  1625.    *
  1626.    * Decode %-style encoding and convert from local encoding to unicode.
  1627.    *
  1628.    * Reverse of encode_string()
  1629.    *
  1630.    * @param str the string to decode (can be @c QString::null)
  1631.    * @param encoding_hint MIB of original encoding of @p str .
  1632.    *        See QTextCodec::mibEnum()
  1633.    *
  1634.    * @return the decoded string
  1635.    *
  1636.    * @see encode_string()
  1637.    * @see encode_string_no_slash()
  1638.    */
  1639.   static QString decode_string(const QString &str, int encoding_hint = 0);
  1640.  
  1641.   /**
  1642.    * @brief Tests if a given URL is a relative as opposed to an absolute URL
  1643.    *
  1644.    * Convenience function.
  1645.    *
  1646.    * Returns whether @p _url is likely to be a "relative" URL instead of
  1647.    * an "absolute" URL.
  1648.    *
  1649.    * @param _url the URL to examine
  1650.    * @return @c true when the URL is likely to be "relative",
  1651.    *         @c false otherwise
  1652.    *
  1653.    * @see relativeURL()
  1654.    */
  1655.   static bool isRelativeURL(const QString &_url);
  1656.  
  1657.   /**
  1658.    * @brief Creates an URL relative to a base URL for a given input URL
  1659.    *
  1660.    * Convenience function
  1661.    *
  1662.    * Returns a "relative URL" based on @p base_url that points to @p url.
  1663.    *
  1664.    * If no "relative URL" can be created, e.g. because the protocol
  1665.    * and/or hostname differ between @p base_url and @p url an absolute
  1666.    * URL is returned.
  1667.    *
  1668.    * @note if @p base_url represents a directory, it should contain
  1669.    *       a trailing slash
  1670.    *
  1671.    * @param base_url the URL to derive from
  1672.    * @param url the URL to point to relatively from @p base_url
  1673.    * @param encoding_hint MIB of original encoding of @p str .
  1674.    *        See QTextCodec::mibEnum()
  1675.    *
  1676.    * @see isRelativeURL()
  1677.    * @see relativePath()
  1678.    * @see adjustPath()
  1679.    */
  1680.   static QString relativeURL(const KURL &base_url, const KURL &url, int encoding_hint = 0);
  1681.  
  1682.   /**
  1683.    * @brief Creates a path relative to a base path for a given input path
  1684.    *
  1685.    * Convenience function
  1686.    *
  1687.    * Returns a relative path based on @p base_dir that points to @p path.
  1688.    *
  1689.    * @param base_dir the base directory to derive from
  1690.    * @param path the new target directory
  1691.    * @param isParent an optional pointer to a boolean which, if provided, will
  1692.    *        be set to reflect whether @p path has @p base_dir as a parent dir
  1693.    *
  1694.    * @see relativeURL()
  1695.    */
  1696.   static QString relativePath(const QString &base_dir, const QString &path, bool *isParent=0);
  1697.  
  1698.   /**
  1699.    * @brief Determines which URI mode is suitable for processing URIs of a
  1700.    *        given protocol
  1701.    *
  1702.    * @param protocol the protocol name. See protocol()
  1703.    *
  1704.    * @return the URIMode suitable for the given protocol
  1705.    *
  1706.    * @see uriMode()
  1707.    *
  1708.    * @since 3.2
  1709.    */
  1710.   static URIMode uriModeForProtocol(const QString& protocol);
  1711.  
  1712. #ifdef KDE_NO_COMPAT
  1713. private:
  1714. #endif
  1715.   /**
  1716.    * @deprecated change code to call fileName()
  1717.    */
  1718.     QString filename( bool _ignore_trailing_slash_in_path = true ) const
  1719.   {
  1720.     return fileName(_ignore_trailing_slash_in_path);
  1721.   }
  1722.  
  1723. protected:
  1724.   /**
  1725.    * @brief Resets the members to their "null" state
  1726.    *
  1727.    * All QString members get reset to @c QString::null, the port to @c 0
  1728.    * the URIMode to @c Auto and the URL becomes invalid.
  1729.    *
  1730.    * This is like assigning a null URL, but more efficient as it doesn't
  1731.    * require the temporary object.
  1732.    *
  1733.    * Called by constructors, assignment operators and the parse methods in case
  1734.    * of a parsing error.
  1735.    *
  1736.    * @see isValid()
  1737.    * @see isEmpty()
  1738.    */
  1739.   void reset();
  1740.   
  1741.   /**
  1742.    * @brief Parses the given string and fills the URL's values on success
  1743.    *
  1744.    * Treats the string as an URL.
  1745.    *
  1746.    * @param _url the string to parse
  1747.    * @param encoding_hint MIB of original encoding of @p str .
  1748.    *        See QTextCodec::mibEnum()
  1749.    */
  1750.   void parseURL( const QString& _url, int encoding_hint = 0 );
  1751.   /**
  1752.    * @brief Parses the given string and fills the URL's values on success
  1753.    *
  1754.    * Treats the string as a generic URI.
  1755.    *
  1756.    * @param _url the string to parse
  1757.    * @param encoding_hint MIB of original encoding of @p str .
  1758.    *        See QTextCodec::mibEnum()
  1759.    */
  1760.   void parseRawURI( const QString& _url, int encoding_hint = 0 );
  1761.   /**
  1762.    * @brief Parses the given string and fills the URL's values on success
  1763.    *
  1764.    * Treats the string as a @c "mailto:" URI.
  1765.    *
  1766.    * @param _url the string to parse
  1767.    * @param encoding_hint MIB of original encoding of @p str .
  1768.    *        See QTextCodec::mibEnum()
  1769.    */
  1770.   void parseMailto( const QString& _url, int encoding_hint = 0 );
  1771.   /**
  1772.    * @brief Parses the given string and fills the URL's values on success
  1773.    *
  1774.    * @param _url the string to parse
  1775.    * @param encoding_hint MIB of original encoding of @p str .
  1776.    *        See QTextCodec::mibEnum()
  1777.    */
  1778.   void parse( const QString& _url, int encoding_hint = 0 );
  1779.  
  1780. private:
  1781.   void _setQuery( const QString& _txt, int encoding_hint = 0);
  1782.  
  1783.   QString m_strProtocol;
  1784.   QString m_strUser;
  1785.   QString m_strPass;
  1786.   QString m_strHost;
  1787.   QString m_strPath;
  1788.   QString m_strRef_encoded;
  1789.   QString m_strQuery_encoded;
  1790.   bool m_bIsMalformed : 1;
  1791.   enum URIMode m_iUriMode : 3;
  1792.   uint freeForUse     : 4;
  1793.   unsigned short int m_iPort;
  1794.   QString m_strPath_encoded;
  1795.  
  1796.   friend KDECORE_EXPORT QDataStream & operator<< (QDataStream & s, const KURL & a);
  1797.   friend KDECORE_EXPORT QDataStream & operator>> (QDataStream & s, KURL & a);
  1798. private:
  1799.   KURLPrivate* d;
  1800. };
  1801.  
  1802. /**
  1803.  * \relates KURL
  1804.  * Compares URLs. They are parsed, split and compared.
  1805.  * Two malformed URLs with the same string representation
  1806.  * are nevertheless considered to be unequal.
  1807.  * That means no malformed URL equals anything else.
  1808.  */
  1809. KDECORE_EXPORT bool urlcmp( const QString& _url1, const QString& _url2 );
  1810.  
  1811. /**
  1812.  * \relates KURL
  1813.  * Compares URLs. They are parsed, split and compared.
  1814.  * Two malformed URLs with the same string representation
  1815.  * are nevertheless considered to be unequal.
  1816.  * That means no malformed URL equals anything else.
  1817.  *
  1818.  * @param _url1 A reference URL
  1819.  * @param _url2 A URL that will be compared with the reference URL
  1820.  * @param _ignore_trailing Described in KURL::cmp
  1821.  * @param _ignore_ref If true, disables comparison of HTML-style references.
  1822.  */
  1823. KDECORE_EXPORT bool urlcmp( const QString& _url1, const QString& _url2, bool _ignore_trailing, bool _ignore_ref );
  1824.  
  1825. KDECORE_EXPORT QDataStream & operator<< (QDataStream & s, const KURL & a);
  1826. KDECORE_EXPORT QDataStream & operator>> (QDataStream & s, KURL & a);
  1827.  
  1828. #endif
  1829.