~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to lib/util/rurl.h

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2010-05-05 07:21:55 UTC
  • mfrom: (1.2.3 upstream) (5.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100505072155-h78lx19pu04sbhtn
Tags: 4:4.0.0-2
* Upload to unstable (Closes: #579947, #481832).
* Acknowledge obsolete NMU fixes (Closes: #562410, #546961).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#ifndef RURL_H_LIB
2
 
#define RURL_H_LIB
3
 
 
4
 
#include <kurl.h>
5
 
 
6
 
/**
7
 
@file rurl.h
8
 
Classes and functions to work with relative URLs.
9
 
*/
10
 
 
11
 
/**Classes and functions to work with relative URLs.*/
12
 
namespace Relative
13
 
{
14
 
 
15
 
/**Relative name of a file or directory.*/   
16
 
class Name{
17
 
public:
18
 
    enum Type { File, Directory, Auto };
19
 
    
20
 
    /**Constructor takes the relative name of a directory or file.
21
 
    Leading slash in the name will be deleted.
22
 
    If type is Auto names like:
23
 
    name/name/ are directories
24
 
    name/name are files.
25
 
    Trailing slash will be deleted for files (type == File).*/
26
 
    Name(const QString &rurl, const Type type = Auto);
27
 
    Name(const char *rurl, const Type type = Auto);
28
 
    
29
 
    /**Sets the relative name.*/
30
 
    void setRURL(const QString &rurl, const Type type);
31
 
    /**Gets the relative name in form 
32
 
    dir/dir/  -> directory
33
 
    or
34
 
    dir/dir/file -> file.*/
35
 
    QString rurl() const;
36
 
    
37
 
    /**Adds addendum to the directory path. This honors file names so
38
 
    if RName represents /dir1/dir2/fname.ext
39
 
    addPath(dir3) will change RName to /dir1/dir2/dir3/fname.ext*/
40
 
    void addPath(const QString &addendum);
41
 
    /**Removes "//" from the name.*/
42
 
    void cleanRURL();
43
 
    
44
 
    /**Returns the extension of a file or QString::null for directories.
45
 
    If complete is true then returns extensions like "tar.gz".
46
 
    Else returns "gz".*/
47
 
    QString extension(bool complete = true) const;
48
 
    /**Returns the name of the file without the path or QString::null
49
 
    for directories.*/
50
 
    QString fileName() const;
51
 
    /**Returns the name of the directory or QString::null if there are no dirs in path.*/
52
 
    QString directory() const;
53
 
 
54
 
    /**Returns true if the type of RName is file.*/
55
 
    bool isFile() const;
56
 
    /**Returns true if the type of RName is directory.*/
57
 
    bool isDirectory() const;
58
 
    /**Checks if RName is valid.*/
59
 
    bool isValid() const;
60
 
    
61
 
    /**Returns a type of the relative name - file or directory.*/
62
 
    Type type() const;
63
 
    /**Sets a type of the relative name - file or directory.
64
 
    If Auto is passed, nothing happens.*/
65
 
    void setType(const Type type);
66
 
    
67
 
    /**Creates and returns relative name between base and url. Base and url should be absolute.
68
 
    Base is considered to be a directory.*/
69
 
    static Name relativeName(const QString &base, const QString &url);
70
 
    /**Cleans rurl by removing extra slashes.*/
71
 
    static QString cleanName(const QString &rurl);
72
 
    /**Corrects rurl according to the given type and returns corrected url.
73
 
    Also cleans url (see @ref cleanRURL).*/
74
 
    static QString correctName(const QString &rurl, const Type type = Auto);
75
 
 
76
 
    bool operator == (const Name &rname);
77
 
    bool operator != (const Name &rname);
78
 
 
79
 
protected:
80
 
    /**Corrects m_rurl and m_type according to the relative name storing policy,
81
 
    i.e. removes leading slash, removes trailing slash for files, changes type
82
 
    to be either File or Directory, but not Auto. Also cleans url (see @ref cleanRURL).*/
83
 
    void correct();
84
 
 
85
 
private:
86
 
    QString m_rurl;    
87
 
    Type m_type;
88
 
};
89
 
 
90
 
/**Relative name of file or directory to some base location.*/
91
 
class URL: public Name{
92
 
public:
93
 
    /**Evaluates the relative path between url and base and creates RURL object.
94
 
    base should be an url to the directory or location, not a file.
95
 
    The check is not performed. url should be the usual url. Only the
96
 
    path of this url is taken into account when evaluating relative path.*/
97
 
    URL(KURL base, KURL url, Type type = Auto);
98
 
    /**Creates RURL object with given base and relative or full url (according to
99
 
    the isUrlRelative value).*/
100
 
    URL(KURL base, QString url, bool isUrlRelative, Type type = Auto);
101
 
 
102
 
    /**Sets a new base for a RURL.*/
103
 
    void setBase(const KURL &base);
104
 
    /**Sets a new base for a RURL. Base is is considered to be a
105
 
    directory and converted to KURL using KURL::setPath().*/
106
 
    void setBase(const QString &base);
107
 
    /**Returns RURL base.*/
108
 
    KURL base() const;
109
 
    /**Returns a path of a base KURL (using KURL::path()). Trailing slash is guaranteed.*/
110
 
    QString basePath() const;
111
 
 
112
 
    /**Returns a complete url to the RURL location. This is basically base + rurl.
113
 
    This also resolves ".." components in path.
114
 
    Directories always have trailing slash in KURL
115
 
    (this means that if url() == "file:/test/dir/" then
116
 
    url() != KURL("/test/dir") and
117
 
    url() == KURL("/test/dir/").*/
118
 
    KURL url() const;
119
 
    /**Returns a path of a complete url to the location. The url is basically base + rurl.
120
 
    This method only returns a path part of the KURL (using KURL::path()).
121
 
    Trailing slash is guaranteed for directories and no trailing slash - for files.
122
 
    This also resolves ".." components in path.*/
123
 
    QString urlPath() const;
124
 
    /**Returns a directory of a complete url to the location. The url is constructed as base + rurl.
125
 
    Returns the same as urlPath() for directories.
126
 
    This method uses KURL::directory to determine the directory.
127
 
    Trailing slash is guaranteed.
128
 
    This also resolves ".." components in path.*/
129
 
    QString urlDirectory() const;
130
 
 
131
 
    /**Returns a new URL that is relative to given base. Relative part is taken from
132
 
    current URL object.*/
133
 
    URL relativeTo(KURL base);
134
 
 
135
 
    /**Returns a new relative URL constructed from base and given url.*/
136
 
    static URL relativeURL(KURL base, KURL url);
137
 
    /**Returns a new relative URL constructed from base and given url. url parameter
138
 
    is either relative or full (depends on isUrlRelative value).*/
139
 
    static URL relativeURL(KURL base, QString url, bool isUrlRelative);
140
 
 
141
 
    bool operator == (const URL &url);
142
 
    bool operator != (const URL &url);
143
 
 
144
 
private:
145
 
    KURL m_base;
146
 
};
147
 
 
148
 
/**Relative directory name.*/
149
 
class Directory: public URL{
150
 
public:
151
 
    /**Works as URL::URL(KURL, KURL), only implies Name::Directory mode.*/
152
 
    Directory(KURL base, KURL url);
153
 
    /**Works as URL::URL(KURL, QString, bool), only implies Name::Directory mode.*/
154
 
    Directory(KURL base, QString url, bool isRelativeUrl);
155
 
 
156
 
    /**Works as URL::setRURL(QString), only implies Name::Directory mode.*/
157
 
    void setRURL(QString rurl);
158
 
 
159
 
private:
160
 
    void setRURL(QString rurl, Type type);
161
 
 
162
 
};
163
 
 
164
 
/**Relative file name.*/
165
 
class File: public URL{
166
 
public:
167
 
    /**Works as URL::URL(KURL, KURL), only implies Name::File mode.*/
168
 
    File(KURL base, KURL url);
169
 
    /**Works as URL::URL(KURL, KURL), only implies Name::File mode.*/
170
 
    File(KURL base, QString url, bool isRelativeUrl);
171
 
 
172
 
    /**Works as URL::setRURL(QString), only implies Name::File mode.*/
173
 
    void setRURL(QString rurl);
174
 
 
175
 
private:
176
 
    void setRURL(QString rurl, Type type);
177
 
    
178
 
};
179
 
 
180
 
}
181
 
 
182
 
#endif