Scribus
Open source desktop publishing at your fingertips
scimagecachedir.h
1 /*
2 For general Scribus (>=1.3.2) copyright and licensing information please refer
3 to the COPYING file provided with the program. Following this notice may exist
4 a copyright and/or license notice that predates the release of Scribus 1.3.2
5 for which a new license (GPL+exception) is in place.
6 */
7 /***************************************************************************
8  copyright : (C) 2010 by Marcus Holland-Moritz
9  email : scribus@mhxnet.de
10 ***************************************************************************/
11 
12 /***************************************************************************
13 * *
14 * This program is free software; you can redistribute it and/or modify *
15 * it under the terms of the GNU General Public License as published by *
16 * the Free Software Foundation; either version 2 of the License, or *
17 * (at your option) any later version. *
18 * *
19 ***************************************************************************/
20 
21 #ifndef SCIMAGECACHEDIR_H
22 #define SCIMAGECACHEDIR_H
23 
24 #include <QObject>
25 #include <QHash>
26 #include <QString>
27 #include <QStringList>
28 
29 #include "scribusapi.h"
30 
31 class ScImageCacheFile;
32 class QFileInfo;
33 
38 class ScImageCacheDir : public QObject
39 {
40  Q_OBJECT
41 
42 public:
43  typedef unsigned int AccessCounter;
44 
45  ScImageCacheDir(const QString & dir, ScImageCacheDir *parent = 0, bool scanFiles = false, const QStringList & suffixList = QStringList());
46  ~ScImageCacheDir();
47  ScImageCacheDir *newSubDir(const QString & dir, bool scanFiles = false, const QStringList & suffixList = QStringList());
48  const QString & name() const { return m_name; }
49  QString path(bool relative = false) const;
50  QString path(const QString & file) const;
51  qint64 size() const;
52  bool exists() const;
53  void update();
54  bool updateFile(const QString & file);
55  bool updateAccess(const QString & dir, AccessCounter from, AccessCounter to);
56 
57  static bool lastAccess(const QString & dir, AccessCounter & access);
58 
59  static const QString accessFileName;
60 
61 signals:
62  void fileCreated(ScImageCacheFile * file, const QFileInfo & info);
63  void fileChanged(ScImageCacheFile * file, const QFileInfo & info);
64  void fileRemoved(ScImageCacheFile * file);
65 
66 private:
67  typedef QHash<QString, ScImageCacheDir *> DirMap;
68  typedef QHash<QString, ScImageCacheFile *> FileMap;
69 
70  void scan();
71  bool addDir(ScImageCacheDir *dir);
72  bool isModified();
73  bool updateFile(const QStringList & parts, int level = 0);
74  bool updateAccess(const QStringList & parts, AccessCounter from, AccessCounter to, int level = 0);
75 
76  QString m_name;
77  const QStringList m_suffix;
78  ScImageCacheDir * const m_parent;
79  bool m_exists;
80  bool m_lastAccessValid;
81  AccessCounter m_lastAccess;
82  DirMap *m_dirs;
83  FileMap *m_files;
84 };
85 
86 #endif
Representation of a directory node in the image cache tree.
Definition: scimagecachedir.h:38
Representation of a file node in the image cache tree.
Definition: scimagecachefile.h:37