Scribus
Open source desktop publishing at your fingertips
sclockedfile.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 SCLOCKEDFILE_H
22 #define SCLOCKEDFILE_H
23 
24 #include "scconfig.h"
25 #include "scribusapi.h"
26 
27 #include <QFile>
28 #include <QString>
29 #include <QTemporaryFile>
30 
31 class QFileInfo;
32 
38 {
39 public:
40  virtual ~ScLockedFile();
41 
42  void setName(const QString & name);
43  const QString & name() const { return m_fileName; }
44  bool createPath() const;
45 
46  bool lock();
47  bool unlock();
48  bool locked() const { return m_isLocked; }
49 
50  bool exists() const;
51  bool remove() const;
52 
53  virtual bool open() = 0;
54  virtual bool commit() = 0;
55 
56  virtual QIODevice *io() = 0;
57 
58  static const QString lockSuffix;
59 
60 protected:
61  ScLockedFile();
62  ScLockedFile(const QString & name);
63 
64  QString m_fileName;
65  bool m_isOpened;
66 
67 private:
68  bool m_isLocked;
69 
70  QString lockName() const;
71 };
72 
78 {
79 public:
81  ScLockedFileRO(const QString & name);
82 
83  virtual bool open();
84  virtual bool commit();
85 
86  virtual QIODevice *io() { return &m_file; }
87 
88 private:
89  QFile m_file;
90 };
91 
97 {
98 public:
100  ScLockedFileRW(const QString & name);
101 
102  virtual bool open();
103  virtual bool commit();
104 
105  virtual QIODevice *io() { return &m_file; }
106 
107 private:
108  QTemporaryFile m_file;
109 
110  static QString templateName(const QFileInfo & info);
111 };
112 
113 #endif
Read-only locked file access.
Definition: sclockedfile.h:77
Base class for locked file access.
Definition: sclockedfile.h:37
Read/write locked file access.
Definition: sclockedfile.h:96