ArnLib  4.0.x
Active Registry Network
ArnPersist.hpp
Go to the documentation of this file.
1 // Copyright (C) 2010-2022 Michael Wiklund.
2 // All rights reserved.
3 // Contact: arnlib@wiklunden.se
4 //
5 // This file is part of the ArnLib - Active Registry Network.
6 // Parts of ArnLib depend on Qt and/or other libraries that have their own
7 // licenses. Usage of these other libraries is subject to their respective
8 // license agreements.
9 //
10 // GNU Lesser General Public License Usage
11 // This file may be used under the terms of the GNU Lesser General Public
12 // License version 2.1 as published by the Free Software Foundation and
13 // appearing in the file LICENSE_LGPL.txt included in the packaging of this
14 // file. In addition, as a special exception, you may use the rights described
15 // in the Nokia Qt LGPL Exception version 1.1, included in the file
16 // LGPL_EXCEPTION.txt in this package.
17 //
18 // GNU General Public License Usage
19 // Alternatively, this file may be used under the terms of the GNU General Public
20 // License version 3.0 as published by the Free Software Foundation and appearing
21 // in the file LICENSE_GPL.txt included in the packaging of this file.
22 //
23 // Other Usage
24 // Alternatively, this file may be used in accordance with the terms and conditions
25 // contained in a signed written agreement between you and Michael Wiklund.
26 //
27 // This program is distributed in the hope that it will be useful, but WITHOUT ANY
28 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
29 // PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
30 //
31 
32 #ifndef ARNPERSIST_HPP
33 #define ARNPERSIST_HPP
34 
35 #include "ArnLib_global.hpp"
36 #include "ArnM.hpp"
37 #include <QMap>
38 #include <QList>
39 #include <QStringList>
40 #include <QObject>
41 
42 class ArnPersist;
43 class ArnPersistPrivate;
44 class ArnPersistSapi;
45 class ArnDependOffer;
46 class QSqlDatabase;
47 class QSqlQuery;
48 class QDir;
49 
50 namespace Arn {
51 class XStringMap;
52 }
53 
54 
56 class ArnItemPersist : protected ArnItem
57 {
58  Q_OBJECT
59 
60 public:
61  struct StoreType {
62  enum E {
63  DataBase = 0,
64  File
65  };
66  MQ_DECLARE_ENUM( StoreType)
67  };
68  explicit ArnItemPersist( ArnPersist* arnPersist);
69  virtual ~ArnItemPersist();
70  void setStoreId( int id) {_storeId = id;}
71  int storeId() const {return _storeId;}
72  void setStoreType( StoreType type) {_storeType = type;}
73  StoreType storeType() const {return _storeType;}
74  void setMandatory( bool v) {_isMandatory = v;}
75  bool isMandatory() const {return _isMandatory;}
76 
77  ArnItem* toArnItem() {return this;}
78  static ArnItemPersist* fromArnItem( ArnItem* item) {return static_cast<ArnItemPersist*>( item);}
79 
80  void arnImport( const QByteArray& data, int ignoreSame = Arn::SameValue::DefaultAction);
81  void setValue( const QByteArray& value, int ignoreSame = Arn::SameValue::DefaultAction);
82 
83  using ArnItem::open;
84  using ArnItem::linkId;
86  using ArnItem::setDelay;
87  using ArnItem::addMode;
88  using ArnItem::getMode;
89  using ArnItem::path;
90  using ArnItem::deleteLater;
91  using ArnItem::arnExport;
94 
95 private:
96  StoreType _storeType;
97  int _storeId;
98  bool _isMandatory;
99  ArnPersist* _arnPersist;
100 };
101 
102 
103 class ARNLIBSHARED_EXPORT ArnVcs : public QObject
104 {
105  Q_OBJECT
106 
107 public:
108  explicit ArnVcs( QObject* parent = arnNullptr);
109  ~ArnVcs();
110 
111 signals:
112  void notify( const QString msg);
113  void progress( int, QString msg=QString());
114 
115  void userSettingsR( QString name, QString email);
116  void filesR( QStringList files);
117  void tagR();
118  void commitR();
119  void checkoutR();
120  void branchesR( QStringList branches);
121  void tagsR( QStringList tags);
122  void statusR( QString statusLines);
123  void diffR( QString diffLines);
124  void logRecordR( QString lines);
125  void logR( QStringList refs, QStringList msgs);
126 
127 public slots:
128  virtual void log( int numLog);
129  virtual void files( QString ref);
130  virtual void commit( QString commitMsg, QStringList files, QString name, QString email);
131  virtual void tag( QString name, QString ref);
132  virtual void diff( QString ref, QStringList files);
133  virtual void logRecord( QString ref);
134  virtual void tags();
135  virtual void branches();
136  virtual void status();
137  virtual void userSettings();
138  virtual void setUserSettings( QString userName, QString userEmail);
139  virtual void checkout( QString ref, QStringList files);
140 
141 private slots:
142 
143 private:
144 };
146 
147 
149 
168 class ARNLIBSHARED_EXPORT ArnPersist : public QObject
169 {
170  Q_OBJECT
171  Q_DECLARE_PRIVATE(ArnPersist)
172 
173 public:
174  explicit ArnPersist( QObject* parent = arnNullptr);
175  ~ArnPersist();
176 
178 
184  bool setMountPoint( const QString& path);
185 
187 
200  void setPersistDir( const QString& path);
201 
203 
208  void setArchiveDir( const QString& path);
209 
211 
218  void setVcs( ArnVcs* vcs);
219 
221 
226  bool setupDataBase( const QString& dbName = "persist.db");
227 
229 
234  bool flush( const QString& path = QString());
235 
237  QString metaDbValue( const QString& attr, const QString& def = QString());
238  bool setMetaDbValue( const QString& attr, const QString& value);
239  bool getDbId( const QString& path, int& storeId);
240  bool getDbValue( int storeId, QString& path, QByteArray& value);
241  bool getDbValue( const QString& path, QByteArray& value, int& storeId);
242  bool getDbMandatoryList( QList<int>& storeIdList);
243  bool getDbList( bool isUsed, QList<int>& storeIdList);
244  bool insertDbValue( const QString& path, const QByteArray& value);
245  bool updateDbValue( int storeId, const QByteArray& value);
246  bool updateDbUsed( int storeId, int isUsed);
247  bool updateDbMandatory( int storeId, int isMandatory);
249 
250 public slots:
252 
257  bool doArchive( const QString& name = QString());
258 
260 protected:
261  ArnPersist( ArnPersistPrivate& dd, QObject* parent);
262  ArnPersistPrivate* const d_ptr;
264 
265 private slots:
266  void sapiFlush( const QString& path);
267  void sapiTest( const QString& str, int i=0);
268  void sapiLs( const QString& path);
269  void sapiLoad();
270  void sapiRm( const QString& path);
271  void sapiTouch( const QString& path);
272  void sapiDbMandatory( const QString& path, bool isMandatory);
273  void sapiDbMandatoryLs( const QString& path);
274  void sapiDbLs( const QString& path, bool isUsed = true);
275  void sapiDbMarkUnused( const QString& path);
276  void sapiInfo();
277 
278  void vcsCheckoutR();
279 
280  void doArnModeChanged( const QString& path, uint linkId, Arn::ObjectMode mode);
281  void doArnUpdate();
282  void doArnDestroy();
283  void destroyRpc();
284 
285 private:
286  void init();
287  ArnItemPersist* getPersistItem( const QString& path);
288  ArnItemPersist* setupMandatory( const QString& path, bool isMandatory);
289  void removeFilePersistItem( const QString& path);
290  void getFileList( QStringList& flist, const QDir& dir, const QDir* baseDir = arnNullptr);
291  void loadFile( const QString& relPath);
292  void doLoadMandatory();
293  void doLoadFiles();
294  void setupSapi( ArnPersistSapi* sapi);
295  void convertFileList( QStringList& files, Arn::NameF nameF);
296  void dbSetupReadValue( const QString& meta, const QString& valueTxt,
297  QByteArray& value);
298  void dbSetupWriteValue(QString& meta, QString& valueTxt, QByteArray& value);
299 };
300 
301 #endif // ARNPERSIST_HPP
void setValue(const ArnItem &other, int ignoreSame=Arn::SameValue::DefaultAction)
Assign the value of an other ArnItem to an Arn Data Object
Definition: ArnItem.hpp:440
void setDelay(int delay)
Set delay of data changed signal.
Definition: ArnItem.cpp:199
Class for handling persistent Arn Data object.
Definition: ArnPersist.hpp:168
Class for advertising that a service is available.
Definition: ArnDepend.hpp:59
Arn::DataType type() const
The type stored in the Arn Data Object
Definition: ArnItem.hpp:135
Arn::ObjectMode getMode() const
Definition: ArnItem.hpp:166
void addMode(Arn::ObjectMode mode)
Add general mode settings for this Arn Data Object
Definition: ArnItem.hpp:159
QByteArray arnExport() const
Definition: ArnItem.hpp:345
QByteArray toByteArray(bool *isOk=arnNullptr) const
Definition: ArnItem.hpp:387
void setIgnoreSameValue(bool isIgnore=true)
Set skipping assignment of equal value.
Definition: ArnItem.hpp:141
void arnImport(const QByteArray &data, int ignoreSame=Arn::SameValue::DefaultAction)
Import data to an Arn Data Object
Definition: ArnItem.hpp:339
bool open(const QString &path)
Open a handle to an Arn Data Object
Definition: ArnItemB.cpp:91
Assigning same value gives default action set in ArnM or ArnItem.
Definition: Arn.hpp:68
Definition: Arn.cpp:43
QString path(Arn::NameF nameF=Arn::NameF::EmptyOk) const
Path of the Arn Data Object
void bypassDelayPending()
Definition: ArnItem.cpp:228
uint linkId() const
Get the id for this Arn Data Object
#define ARNLIBSHARED_EXPORT
#define MQ_DECLARE_ENUM(EStruct)
Enums.
Definition: MQFlagsBase.hpp:70
Handle for an Arn Data Object.
Definition: ArnItem.hpp:72