File indexing completed on 2025-01-19 03:53:31
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2007-03-19 0007 * Description : Core database Url interface. 0008 * 0009 * SPDX-FileCopyrightText: 2007-2008 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #ifndef DIGIKAM_CORE_DB_URL_H 0016 #define DIGIKAM_CORE_DB_URL_H 0017 0018 // Qt includes 0019 0020 #include <QDateTime> 0021 #include <QList> 0022 #include <QUrl> 0023 0024 // Local includes 0025 0026 #include "digikam_export.h" 0027 #include "dbengineparameters.h" 0028 #include "coredbaccess.h" 0029 0030 namespace Digikam 0031 { 0032 0033 class DIGIKAM_DATABASE_EXPORT CoreDbUrl : public QUrl 0034 { 0035 public: 0036 0037 /** 0038 * This class shall facilitate the usage of 0039 * digikamalbums:/, digikamtags:/, digikamdates:/ and digikamsearch: URLs. 0040 * It provides functions to set and get the parameters stored in such a URL. 0041 * (with the exception of the search parameters in a search URL, which 0042 * are out of the scope of this class.) 0043 */ 0044 0045 /** 0046 * Create a digikamalbums:/ URL from a file:// URL. 0047 * The file URL can point to a file or a directory (an album in this case). 0048 * The additional information stored in the URL need to be supplied as well: 0049 * - The album root in which the entity pointed to is stored. 0050 * This is the left part of the file URL. 0051 * (if the file is "/media/fotos/Summer 2007/001.jpg", the album root may be "/media/fotos") 0052 * - The parameters of the database that is referenced 0053 */ 0054 static CoreDbUrl fromFileUrl(const QUrl& fileUrl, 0055 const QUrl& albumRoot, 0056 int albumRootId, 0057 const DbEngineParameters& parameters = CoreDbAccess::parameters()); 0058 0059 static CoreDbUrl fromFileUrl(const QUrl& fileUrl, 0060 const QUrl& albumRoot, 0061 const DbEngineParameters& parameters = CoreDbAccess::parameters()); 0062 0063 /** 0064 * Create a digikamalbums:/ url from an album name and an image in this album. 0065 * If name is empty, the album is referenced. 0066 * Other parameters as above. 0067 */ 0068 static CoreDbUrl fromAlbumAndName(const QString& name, 0069 const QString& album, 0070 const QUrl& albumRoot, 0071 int albumRootId, 0072 const DbEngineParameters& parameters = CoreDbAccess::parameters()); 0073 0074 static CoreDbUrl fromAlbumAndName(const QString& name, 0075 const QString& album, 0076 const QUrl& albumRoot, 0077 const DbEngineParameters& parameters = CoreDbAccess::parameters()); 0078 0079 /** 0080 * Create an empty digikamalbums:/ url 0081 */ 0082 static CoreDbUrl albumUrl(const DbEngineParameters& parameters = CoreDbAccess::parameters()); 0083 0084 /** 0085 * Create a digikamtags:/ url from a list of tag IDs, where this list is the tag hierarchy 0086 * of the referenced tag, with the topmost parent first, and the tag last in the list. 0087 * An empty list references the root tag. 0088 */ 0089 static CoreDbUrl fromTagIds(const QList<int>& tagIds, 0090 const DbEngineParameters& parameters = CoreDbAccess::parameters()); 0091 0092 /** 0093 * Create an empty digikamdates:/ url 0094 */ 0095 static CoreDbUrl dateUrl(const DbEngineParameters& parameters = CoreDbAccess::parameters()); 0096 0097 /** 0098 * Create a digikamdates:/ url for the month of the given date. 0099 * (The whole month of the given date will included in the referenced time span) 0100 */ 0101 static CoreDbUrl fromDateForMonth(const QDate& date, 0102 const DbEngineParameters& parameters = CoreDbAccess::parameters()); 0103 0104 /** 0105 * Create a digikamdates:/ url for the year of the given date. 0106 * (The whole year of the given date will included in the referenced time span) 0107 */ 0108 static CoreDbUrl fromDateForYear(const QDate& date, 0109 const DbEngineParameters& parameters = CoreDbAccess::parameters()); 0110 0111 /** 0112 * Create a digikamdates:/ url for a specified time span which begin with the 0113 * start date (inclusive) and ends before the end date (exclusive). 0114 * To cover the whole year of 1984, you would pass 1/1/1984 and 1/1/1985. 0115 */ 0116 static CoreDbUrl fromDateRange(const QDate& startDate, const QDate& endDate, 0117 const DbEngineParameters& parameters = CoreDbAccess::parameters()); 0118 0119 /** 0120 * Create an empty digikammapimages:/ url 0121 */ 0122 static CoreDbUrl mapImagesUrl(const DbEngineParameters& parameters = CoreDbAccess::parameters()); 0123 0124 static CoreDbUrl fromAreaRange(const qreal lat1, const qreal lng1, 0125 const qreal lat2, const qreal lng2, 0126 const DbEngineParameters& parameters = CoreDbAccess::parameters()); 0127 0128 /** 0129 * Create a digikamsearch: URL for the search with the given id. 0130 */ 0131 static CoreDbUrl searchUrl(int searchId, const DbEngineParameters& parameters = CoreDbAccess::parameters()); 0132 0133 /** 0134 * Create a CoreDbUrl object from a QUrl, to retrieve the information stored 0135 */ 0136 explicit CoreDbUrl(const QUrl& digikamUrl); 0137 0138 /** 0139 * Create an invalid database URL 0140 */ 0141 CoreDbUrl(); 0142 0143 /** 0144 * These test for the protocol of this URL. 0145 * The protocol string is of course available via protocol(). 0146 */ 0147 bool isAlbumUrl() const; 0148 bool isTagUrl() const; 0149 bool isDateUrl() const; 0150 bool isSearchUrl() const; 0151 bool isMapImagesUrl() const; 0152 0153 /** 0154 * Returns the DbEngineParameters stored in this URL. 0155 * Applicable to all protocols. 0156 */ 0157 DbEngineParameters parameters() const; 0158 0159 /** 0160 * Change the database parameters stored in this URL 0161 * Applicable to all protocols. 0162 */ 0163 void setParameters(const DbEngineParameters& parameters); 0164 0165 /** 0166 * The following methods are only applicable for a certain protocol each. 0167 * If the URL has another protocol, the return value of these methods is undefined. 0168 */ 0169 0170 /// Album URL 0171 0172 /** 0173 * Returns the album root URL of the file or album referenced by this URL 0174 * In the example above, this is "file://media/fotos" 0175 */ 0176 QUrl albumRoot() const; 0177 0178 /** 0179 * Returns the album root path of the file or album referenced by this URL 0180 * In the example above, this is "/media/fotos" 0181 */ 0182 QString albumRootPath() const; 0183 0184 /** 0185 * Returns the album root id 0186 */ 0187 int albumRootId() const; 0188 0189 /** 0190 * Returns the album: This is the directory hierarchy below the album root. 0191 * In the example above, the album is "/Summer 2007" 0192 */ 0193 QString album() const; 0194 0195 /** 0196 * Returns the file name. In the example above, this is "001.jpg" 0197 */ 0198 QString name() const; 0199 0200 /** 0201 * Converts this digikamalbums:// URL to a file:// URL 0202 */ 0203 QUrl fileUrl() const; 0204 0205 /// Tag URL 0206 0207 /** 0208 * Returns the tag ID, or -1 if the root tag is referenced 0209 */ 0210 int tagId() const; 0211 0212 /** 0213 * Returns the tag ids of all tags in the tag path of this tag, 0214 * the topmost tag in the hierarchy first. 0215 */ 0216 QList<int> tagIds() const; 0217 0218 /// Date URL 0219 0220 /** 0221 * Return the referenced start date (included in the referenced span) 0222 */ 0223 QDate startDate() const; 0224 0225 /** 0226 * Return the referenced end date (excluded from the referenced span) 0227 */ 0228 QDate endDate() const; 0229 0230 /// MapImages URL 0231 0232 /** 0233 * Returns the coordinates surrounding the map area. 0234 * Returns true if the string to number conversion was ok. 0235 */ 0236 bool areaCoordinates(double* lat1, double* lat2, double* lon1, double* lon2) const; 0237 0238 /// Search URL 0239 0240 /** 0241 * Return the id of the search. 0242 */ 0243 int searchId() const; 0244 0245 CoreDbUrl(const CoreDbUrl& url); 0246 0247 CoreDbUrl& operator=(const QUrl& digikamalbumsUrl); 0248 CoreDbUrl& operator=(const CoreDbUrl& url); 0249 0250 bool operator==(const QUrl& digikamalbumsUrl) const; 0251 }; 0252 0253 } // namespace Digikam 0254 0255 #endif // DIGIKAM_CORE_DB_URL_H