forked from nemomobile/mlite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmfiledatastore.h
126 lines (112 loc) · 4.02 KB
/
mfiledatastore.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/***************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation ([email protected])
**
** This file is part of libmeegotouch.
**
** If you have questions regarding the use of this file, please contact
** Nokia at [email protected].
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation
** and appearing in the file LICENSE.LGPL included in the packaging
** of this file.
**
****************************************************************************/
#ifndef MFILEDATASTORE_H
#define MFILEDATASTORE_H
#include "mlite-global.h"
#include "mdatastore.h"
class MFileDataStorePrivate;
/*!
* Concrete implementation of \c MDataStore interface. This class stores the data to the
* filesystem. The file name is given as a constructor parameter.
*/
class MLITESHARED_EXPORT MFileDataStore : public MDataStore
{
Q_OBJECT
public:
/*!
* Constructor.
* \param filePath Absolute path to the file that the settings will be written to and read from.
*/
explicit MFileDataStore(const QString &filePath);
/*!
* Destructor
*/
virtual ~MFileDataStore();
//! \reimp
/*!
* If \c isWritable returns \c false, this method returns \c false.
*/
virtual bool createValue(const QString &key, const QVariant &value);
/*!
* If \c isWritable returns \c false, this method returns \c false.
*/
virtual bool setValue(const QString &key, const QVariant &value);
/*!
* If \c isReadable returns \c false, this method returns an empty QVariant.
*/
virtual QVariant value(const QString &key) const;
/*!
* If \c isReadable returns \c false, this method returns an empty list.
*/
virtual QStringList allKeys() const;
/*!
* If \c isWritable returns \c false, this method does nothing.
*/
virtual void remove(const QString &key);
/*!
* If \c isWritable returns \c false, this method does nothing.
*/
virtual void clear();
/*!
* If \c isReadable returns \c false, this method returns \c false.
*/
virtual bool contains(const QString &key) const;
//! \reimp_end
/*!
* Queries if this data store is readable. If this method returns \c true you
* can use the reading methods of this class (\c value, \c allKeys, \c contains).
* If this method returns \c false, the reading methods don't provide the real data.
* \sa value, allKeys, contains
* \return \c true if the data store can be read.
*/
bool isReadable() const;
/*!
* Queries if this data store is writable. If this method returns \c true you
* can use the writing methods of this class (\c setValue, \c remove, \c clear).
* If this method returns \c false, the writing methods don't modify the data store.
* \sa setValue, remove, clear
* \return \c true if the data store can be written.
*/
bool isWritable() const;
private:
/*!
* Takes a snapshot of keys and values in the underlying QSettings.
* This allows us to check for external modifications. QSettings seems
* to pick up such modifications automatically, so we compare the settings
* to the snapshot when we notice a file change.
*/
void takeSnapshot();
private slots:
/*!
* Notifies that the settings file has been changed in the filesystem externally
* \param fileName The name of the file modified
*/
void fileChanged(const QString &fileName);
/*!
* Notifies that the directory of the settings file has been changed in the filesystem externally
* \param fileName The name of the file modified
*/
void directoryChanged(const QString &fileName);
protected:
MFileDataStorePrivate * const d_ptr;
private:
Q_DECLARE_PRIVATE(MFileDataStore)
Q_DISABLE_COPY(MFileDataStore)
};
#endif // MFILEDATASTORE_H