Scribus
Open source desktop publishing at your fingertips
scimagecacheproxy.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 SCIMAGECACHEPROXY_H
22 #define SCIMAGECACHEPROXY_H
23 
24 #include "scconfig.h"
25 #include "scribusapi.h"
26 
27 #include <QImage>
28 #include <QString>
29 #include <QMap>
30 
31 class ScImage;
32 class ScLockedFile;
34 
39 class SCRIBUS_API ScImageCacheProxy
40 {
41 public:
42  static const QString metaSuffix;
43  static const QString referenceSuffix;
44  static const QString imageSuffix;
45 
50  ScImageCacheProxy(const QString & fn);
52 
56  bool enabled() const { return m_isEnabled; }
60  const QString & getFilename() const { return m_filename; }
66  bool load(QImage & image);
72  bool save(const QImage & image);
77  bool touch() const;
81  void addMetadata(const QString & key, const QString & value);
85  void addModifier(const QString & key, const QString & value);
89  void delModifier(const QString & key);
94  bool canUseCachedImage() const;
95 
99  void addInfo(const QString & key, const QString & value);
103  QString getInfo(const QString & key) const;
104 
110  static QString getBaseName(const QString & metafile);
117  static bool getRefCount(const QString & reffile, int & refcount);
124  static bool fixRefCount(const QString & reffile, int refcount);
136  static bool removeCacheEntry(const QString & metafile, bool haveMasterLock = false);
137 
138 private:
139  // Don't turn this into a QHash, element order is important
140  typedef QMap<QString, QString> MetaMap;
141 
142  const QString m_filename;
143  const bool m_isEnabled;
144  mutable QString m_metanameCache;
145  MetaMap m_metadata;
146  MetaMap m_modifier;
147  MetaMap m_imginfo;
148 
149  static QString imageFile(const QString & base);
150  static QString referenceFile(const QString & base);
151 
152  static bool createCacheDir();
153  static QString addDirLevels(QString name);
154 
155  const QString & metaName() const;
156  QString imageBaseName(const QImage & image) const;
157 
158  bool loadMetadata(MetaMap *meta, MetaMap *mod, MetaMap *info, QString *base) const;
159 
160  static bool loadMetadata(ScLockedFile *file, MetaMap *meta, MetaMap *mod, MetaMap *info, QString *base);
161  static bool loadMetadata(const QString & fn, MetaMap *meta, MetaMap *mod, MetaMap *info, QString *base);
162  static void saveMetadata(ScLockedFile *file, const MetaMap & map, const MetaMap & mod, const MetaMap & info, const QString & base);
163 
164  static bool getRefCountAbs(const QString & reffile, int & refcount);
165  static bool loadRef(ScLockedFile *file, int & refcount);
166  static void saveRef(ScLockedFile *file, int refcount);
167  static bool refImage(ScLockedFile *file);
168  static bool unrefImage(ScLockedFile *file, const QString & imageName);
169 };
170 
171 #endif
static const QString imageSuffix
Cache image file suffix.
Definition: scimagecacheproxy.h:44
Base class for locked file access.
Definition: sclockedfile.h:37
static const QString referenceSuffix
Reference file suffix.
Definition: scimagecacheproxy.h:43
Definition: scimage.h:36
bool enabled() const
Check if the image cache is enabled.
Definition: scimagecacheproxy.h:56
Scribus image cache manager.
Definition: scimagecachemanager.h:39
Scribus image cache proxy.
Definition: scimagecacheproxy.h:39
static const QString metaSuffix
Meta file suffix.
Definition: scimagecacheproxy.h:42
const QString & getFilename() const
Get original image file name.
Definition: scimagecacheproxy.h:60