digiKam
collectionmanager_p.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date : 2007-04-09
7  * Description : Collection location management - private containers.
8  *
9  * Copyright (C) 2007-2009 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
10  *
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)
15  * any later version.
16  *
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.
21  *
22  * ============================================================ */
23 
24 #ifndef DIGIKAM_COLLECTION_MANAGER_P_H
25 #define DIGIKAM_COLLECTION_MANAGER_P_H
26 
27 #include "collectionmanager.h"
28 
29 // Qt includes
30 
31 #include <QDir>
32 #include <QDirIterator>
33 #include <QCoreApplication>
34 #include <QCryptographicHash>
35 #include <QReadWriteLock>
36 #include <QUrlQuery>
37 #include <QThread>
38 
39 // KDE includes
40 
41 #include <klocalizedstring.h>
42 
43 // Solid includes
44 
45 #if defined(Q_CC_CLANG)
46 # pragma clang diagnostic push
47 # pragma clang diagnostic ignored "-Wnonportable-include-path"
48 #endif
49 
50 #include <solid/device.h>
51 #include <solid/deviceinterface.h>
52 #include <solid/devicenotifier.h>
53 #include <solid/storageaccess.h>
54 #include <solid/storagedrive.h>
55 #include <solid/storagevolume.h>
56 #include <solid/opticaldisc.h>
57 #include <solid/predicate.h>
58 
59 #if defined(Q_CC_CLANG)
60 # pragma clang diagnostic pop
61 #endif
62 
63 // Local includes
64 
65 #include "digikam_debug.h"
66 #include "coredbaccess.h"
67 #include "coredbchangesets.h"
68 #include "coredbtransaction.h"
69 #include "coredb.h"
70 #include "collectionscanner.h"
71 #include "collectionlocation.h"
72 
73 namespace Digikam
74 {
75 
76 class Q_DECL_HIDDEN AlbumRootLocation : public CollectionLocation
77 {
78 
79 public:
80 
82  : available(false),
83  hidden (false)
84  {
85  }
86 
87  explicit AlbumRootLocation(const AlbumRootInfo& info)
88  {
89  qCDebug(DIGIKAM_DATABASE_LOG) << "Creating new Location " << info.specificPath << " uuid " << info.identifier;
90  m_id = info.id;
91  m_type = (Type)info.type;
92  QString path = info.specificPath;
93 
94  if ((path != QLatin1String("/")) &&
95  path.endsWith(QLatin1Char('/')))
96  {
97  path.chop(1);
98  }
99 
100  specificPath = path;
101  identifier = info.identifier;
102  m_label = info.label;
103 
104  m_path.clear();
105 
106  setStatus((CollectionLocation::Status)info.status);
107  }
108 
110  {
111  if (hidden)
112  {
114  }
115  else
116  {
117  if (available)
118  {
120  }
121  else
122  {
124  }
125  }
126  }
127 
129  {
130  m_status = s;
131 
132  // status is exclusive, and Hidden wins
133  // but really both states are independent
134  // - a hidden location might or might not be available
135 
137  {
138  available = true;
139  hidden = false;
140  }
141  else if (m_status == CollectionLocation::LocationHidden)
142  {
143  available = false;
144  hidden = true;
145  }
146  else // Unavailable, Null, Deleted
147  {
148  available = false;
149  hidden = false;
150  }
151  }
152 
153  void setId(int id)
154  {
155  m_id = id;
156  }
157 
158  void setAbsolutePath(const QString& path)
159  {
160  m_path = path;
161  }
162 
163  void setType(Type type)
164  {
165  m_type = type;
166  }
167 
168  void setLabel(const QString& label)
169  {
170  m_label = label;
171  }
172 
173 public:
174 
175  QString identifier;
176  QString specificPath;
177  bool available;
178  bool hidden;
179 };
180 
181 // -------------------------------------------------
182 
183 class Q_DECL_HIDDEN SolidVolumeInfo
184 {
185 
186 public:
187 
189  : isRemovable (false),
190  isOpticalDisc(false),
191  isMounted (false)
192  {
193  }
194 
195  bool isNull() const
196  {
197  return path.isNull();
198  }
199 
200 public:
201 
202  QString udi;
203  QString path;
204  QString uuid;
205  QString label;
206  bool isRemovable;
208  bool isMounted;
209 };
210 
211 // -------------------------------------------------
212 
213 class Q_DECL_HIDDEN CollectionManager::Private
214 {
215 
216 public:
217 
218  explicit Private(CollectionManager* const s);
219 
221  QList<SolidVolumeInfo> actuallyListVolumes();
222  void slotTriggerUpdateVolumesList();
224 
225 
227  QList<SolidVolumeInfo> listVolumes();
228 
233  SolidVolumeInfo findVolumeForLocation(const AlbumRootLocation* location, const QList<SolidVolumeInfo>& volumes);
234 
239  SolidVolumeInfo findVolumeForUrl(const QUrl& fileUrl, const QList<SolidVolumeInfo>& volumes);
240 
242  static QString volumeIdentifier(const SolidVolumeInfo& info);
243 
245  QString volumeIdentifier(const QString& path);
246 
248  QString networkShareIdentifier(const QString& path);
249 
251  QString pathFromIdentifier(const AlbumRootLocation* location);
252 
254  QStringList networkShareMountPathsFromIdentifier(const AlbumRootLocation* location);
255 
257  static QString directoryHash(const QString& path);
258 
260  bool checkIfExists(const QString& path, QList<CollectionLocation> assumeDeleted);
261 
263  QString technicalDescription(const AlbumRootLocation* location);
264 
265 public:
266 
267  QReadWriteLock lock;
268  QMap<int, AlbumRootLocation*> locations;
270  QStringList udisToWatch;
273 };
274 
275 // -------------------------------------------------
276 
277 class Q_DECL_HIDDEN ChangingDB
278 {
279 
280 public:
281 
283  : d(dd)
284  {
285  d->changingDB = true;
286  }
287 
289  {
290  d->changingDB = false;
291  }
292 
293 public:
294 
296 };
297 
298 } // namespace Digikam
299 
300 #endif // DIGIKAM_COLLECTION_MANAGER_P_H
Definition: coredbalbuminfo.h:48
QString identifier
Definition: coredbalbuminfo.h:64
AlbumRoot::Type type
Definition: coredbalbuminfo.h:62
QString label
Definition: coredbalbuminfo.h:61
int id
Definition: coredbalbuminfo.h:56
QString specificPath
Definition: coredbalbuminfo.h:65
int status
Definition: coredbalbuminfo.h:63
Definition: collectionmanager_p.h:77
QString identifier
Definition: collectionmanager_p.h:175
bool available
Definition: collectionmanager_p.h:177
void setStatusFromFlags()
Definition: collectionmanager_p.h:109
bool hidden
Definition: collectionmanager_p.h:178
void setStatus(CollectionLocation::Status s)
Definition: collectionmanager_p.h:128
void setId(int id)
Definition: collectionmanager_p.h:153
void setType(Type type)
Definition: collectionmanager_p.h:163
void setLabel(const QString &label)
Definition: collectionmanager_p.h:168
QString specificPath
Definition: collectionmanager_p.h:176
void setAbsolutePath(const QString &path)
Definition: collectionmanager_p.h:158
AlbumRootLocation()
Definition: collectionmanager_p.h:81
AlbumRootLocation(const AlbumRootInfo &info)
Definition: collectionmanager_p.h:87
Definition: albummanager_p.h:215
ChangingDB(CollectionManager::Private *const dd)
Definition: collectionmanager_p.h:282
~ChangingDB()
Definition: collectionmanager_p.h:288
CollectionManager::Private *const d
Definition: collectionmanager_p.h:295
Definition: collectionlocation.h:41
Type
Definition: collectionlocation.h:80
Status
Definition: collectionlocation.h:46
@ LocationHidden
Definition: collectionlocation.h:62
@ LocationUnavailable
Definition: collectionlocation.h:68
@ LocationAvailable
Definition: collectionlocation.h:56
Definition: collectionmanager_p.h:214
QList< SolidVolumeInfo > volumesListCache
Definition: collectionmanager_p.h:223
QStringList udisToWatch
Definition: collectionmanager_p.h:270
bool changingDB
Definition: collectionmanager_p.h:269
CollectionManager * s
Definition: collectionmanager_p.h:272
QReadWriteLock lock
Definition: collectionmanager_p.h:267
bool watchEnabled
Definition: collectionmanager_p.h:271
QMap< int, AlbumRootLocation * > locations
Definition: collectionmanager_p.h:268
Definition: collectionmanager.h:45
Definition: collectionmanager_p.h:184
bool isOpticalDisc
is an optical disk device as CD/DVD/BR
Definition: collectionmanager_p.h:207
bool isMounted
is mounted on File System.
Definition: collectionmanager_p.h:208
SolidVolumeInfo()
Definition: collectionmanager_p.h:188
QString label
volume label (think of CDs)
Definition: collectionmanager_p.h:205
bool isNull() const
Definition: collectionmanager_p.h:195
bool isRemovable
may be removed
Definition: collectionmanager_p.h:206
QString udi
Solid device UDI of the StorageAccess device.
Definition: collectionmanager_p.h:202
QString uuid
UUID as from Solid.
Definition: collectionmanager_p.h:204
QString path
mount path of volume, with trailing slash
Definition: collectionmanager_p.h:203
Definition: piwigotalker.h:48
std::vector< T > location(const std::vector< T > &shape, unsigned long idx)
Definition: shapepredictor.h:109
Definition: datefolderview.cpp:43
Type
Definition: gpsitemcontainer.h:45