1
/* ============================================================
3
* This file is a part of digiKam project
4
* http://www.digikam.org
7
* Description : Handling of database specific URLs
9
* Copyright (C) 2007-2008 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
11
* This program is free software; you can redistribute it
12
* and/or modify it under the terms of the GNU General
13
* Public License as published by the Free Software Foundation;
14
* either version 2, or (at your option)
17
* This program is distributed in the hope that it will be useful,
18
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
* GNU General Public License for more details.
22
* ============================================================ */
38
#include "digikam_export.h"
39
#include "databaseparameters.h"
40
#include "databaseaccess.h"
45
class DIGIKAM_DATABASE_EXPORT DatabaseUrl : public KUrl
50
* This class shall facilitate the usage of
51
* digikamalbums:/, digikamtags:/, digikamdates:/ and digikamsearch: URLs.
52
* It provides functions to set and get the parameters stored in such a URL.
53
* (with the exception of the search parameters in a search URL, which
54
* are out of the scope of this class.)
58
* Create a digikamalbums:/ URL from a file:// URL.
59
* The file URL can point to a file or a directory (an album in this case).
60
* The additional information stored in the URL need to be supplied as well:
61
* - The album root in which the entity pointed to is stored.
62
* This is the left part of the file URL.
63
* (if the file is "/media/fotos/Summer 2007/001.jpg", the album root may be "/media/fotos")
64
* - The parameters of the database that is referenced
66
static DatabaseUrl fromFileUrl(const KUrl& fileUrl,
67
const KUrl& albumRoot,
69
const DatabaseParameters& parameters = DatabaseAccess::parameters());
71
static DatabaseUrl fromFileUrl(const KUrl& fileUrl,
72
const KUrl& albumRoot,
73
const DatabaseParameters& parameters = DatabaseAccess::parameters());
76
* Create a digikamalbums:/ url from an album name and an image in this album.
77
* If name is empty, the album is referenced.
78
* Other parameters as above.
80
static DatabaseUrl fromAlbumAndName(const QString& name,
82
const KUrl& albumRoot,
84
const DatabaseParameters& parameters = DatabaseAccess::parameters());
86
static DatabaseUrl fromAlbumAndName(const QString& name,
88
const KUrl& albumRoot,
89
const DatabaseParameters& parameters = DatabaseAccess::parameters());
92
* Create an empty digikamalbums:/ url
94
static DatabaseUrl albumUrl(const DatabaseParameters& parameters = DatabaseAccess::parameters());
97
* Create a digikamtags:/ url from a list of tag IDs, where this list is the tag hierarchy
98
* of the referenced tag, with the topmost parent first, and the tag last in the list.
99
* An empty list references the root tag.
101
static DatabaseUrl fromTagIds(const QList<int>& tagIds,
102
const DatabaseParameters& parameters = DatabaseAccess::parameters());
105
* Create an empty digikamdates:/ url
107
static DatabaseUrl dateUrl(const DatabaseParameters& parameters = DatabaseAccess::parameters());
110
* Create a digikamdates:/ url for the month of the given date.
111
* (The whole month of the given date will included in the referenced time span)
113
static DatabaseUrl fromDateForMonth(const QDate& date,
114
const DatabaseParameters& parameters = DatabaseAccess::parameters());
117
* Create a digikamdates:/ url for the year of the given date.
118
* (The whole year of the given date will included in the referenced time span)
120
static DatabaseUrl fromDateForYear(const QDate& date,
121
const DatabaseParameters& parameters = DatabaseAccess::parameters());
124
* Create a digikamdates:/ url for a specified time span which begin with the
125
* start date (inclusive) and ends before the end date (exclusive).
126
* To cover the whole year of 1984, you would pass 1/1/1984 and 1/1/1985.
128
static DatabaseUrl fromDateRange(const QDate& startDate, const QDate& endDate,
129
const DatabaseParameters& parameters = DatabaseAccess::parameters());
132
* Create a digikamsearch: URL for the search with the given id.
134
static DatabaseUrl searchUrl(int searchId,
135
const DatabaseParameters& parameters = DatabaseAccess::parameters());
137
* Create a DatabaseUrl object from a KUrl, to retrieve the information stored
139
DatabaseUrl(const KUrl& digikamUrl);
142
* Create an invalid database URL
147
* These test for the protocol of this URL.
148
* The protocol string is of course available via protocol().
150
bool isAlbumUrl() const;
151
bool isTagUrl() const;
152
bool isDateUrl() const;
153
bool isSearchUrl() const;
156
* Returns the DatabaseParameters stored in this URL.
157
* Applicable to all protocols.
159
DatabaseParameters parameters() const;
161
* Change the database parameters stored in this URL
162
* Applicable to all protocols.
164
void setParameters(const DatabaseParameters& parameters);
167
* The following methods are only applicable for a certain protocol each.
168
* If the URL has another protocol, the return value of these methods is undefined.
173
/** Returns the album root URL of the file or album referenced by this URL
174
* In the example above, this is "file://media/fotos"
176
KUrl albumRoot() const;
178
/** Returns the album root path of the file or album referenced by this URL
179
* In the example above, this is "/media/fotos"
181
QString albumRootPath() const;
183
/** Returns the album root id */
184
int albumRootId() const;
186
/** Returns the album: This is the directory hierarchy below the album root.
187
* In the example above, the album is "/Summer 2007"
189
QString album() const;
192
* Returns the file name. In the example above, this is "001.jpg"
194
QString name() const;
197
* Converts this digikamalbums:// URL to a file:// URL
199
KUrl fileUrl() const;
204
* Returns the tag ID, or -1 if the root tag is referenced
209
* Returns the tag ids of all tags in the tag path of this tag,
210
* the topmost tag in the hierarchy first.
212
QList<int> tagIds() const;
217
* Return the referenced start date (included in the referenced span)
219
QDate startDate() const;
222
* Return the referenced end date (excluded from the referenced span)
224
QDate endDate() const;
229
* Return the id of the search.
231
int searchId() const;
233
DatabaseUrl(const DatabaseUrl& url);
235
DatabaseUrl& operator=(const KUrl& digikamalbumsUrl);
236
DatabaseUrl& operator=(const DatabaseUrl& url);
238
bool operator==(const KUrl& digikamalbumsUrl);
241
} // namespace Digikam
243
#endif // DATABASEURL_H