source: calamares/trunk/fuentes/src/libcalamares/GlobalStorage.h @ 7538

Last change on this file since 7538 was 7538, checked in by kbut, 13 months ago

sync with github

File size: 3.1 KB
Line 
1/* === This file is part of Calamares - <https://github.com/calamares> ===
2 *
3 *   Copyright 2014-2015, Teo Mrnjavac <teo@kde.org>
4 *   Copyright 2017-2018, Adriaan de Groot <groot@kde.org>
5 *
6 *   Calamares is free software: you can redistribute it and/or modify
7 *   it under the terms of the GNU General Public License as published by
8 *   the Free Software Foundation, either version 3 of the License, or
9 *   (at your option) any later version.
10 *
11 *   Calamares is distributed in the hope that it will be useful,
12 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 *   GNU General Public License for more details.
15 *
16 *   You should have received a copy of the GNU General Public License
17 *   along with Calamares. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef CALAMARES_GLOBALSTORAGE_H
21#define CALAMARES_GLOBALSTORAGE_H
22
23#include "CalamaresConfig.h"
24
25#include <QVariantMap>
26
27#ifdef WITH_PYTHON
28namespace boost
29{
30namespace python
31{
32namespace api
33{
34class object;
35}
36class list;
37}
38}
39#endif
40
41namespace Calamares
42{
43
44class DebugWindow;
45
46class GlobalStorage : public QObject
47{
48    Q_OBJECT
49public:
50    explicit GlobalStorage();
51
52    //NOTE: thread safety is guaranteed by JobQueue, which executes jobs one by one.
53    //      If at any time jobs become concurrent, this class must be made thread-safe.
54    bool contains( const QString& key ) const;
55    int count() const;
56    void insert( const QString& key, const QVariant& value );
57    QStringList keys() const;
58    int remove( const QString& key );
59    QVariant value( const QString& key ) const;
60
61    /// @brief dump keys and values to the debug log
62    void debugDump() const;
63    /** @brief write as JSON to the given filename
64     *
65     * No tidying, sanitization, or censoring is done -- for instance,
66     * the user module sets a slightly-obscured password in global storage,
67     * and this JSON file will contain that password in-the-only-slightly-
68     * obscured form.
69     */
70    bool save( const QString& filename );
71
72signals:
73    void changed();
74
75private:
76    QVariantMap m;
77
78    friend DebugWindow;
79};
80
81} // namespace Calamares
82
83#ifdef WITH_PYTHON
84namespace CalamaresPython
85{
86
87class GlobalStoragePythonWrapper
88{
89public:
90    explicit GlobalStoragePythonWrapper( Calamares::GlobalStorage* gs );
91
92    bool contains( const std::string& key ) const;
93    int count() const;
94    void insert( const std::string& key, const boost::python::api::object& value );
95    boost::python::list keys() const;
96    int remove( const std::string& key );
97    boost::python::api::object value( const std::string& key ) const;
98
99    // This is a helper for scripts that do not go through
100    // the JobQueue (i.e. the module testpython script),
101    // which allocate their own (singleton) GlobalStorage.
102    static Calamares::GlobalStorage* globalStorageInstance() { return s_gs_instance; }
103
104private:
105    Calamares::GlobalStorage* m_gs;
106    static Calamares::GlobalStorage* s_gs_instance;  // See globalStorageInstance()
107};
108
109} // namespace CalamaresPython
110#endif
111
112#endif // CALAMARES_GLOBALSTORAGE_H
Note: See TracBrowser for help on using the repository browser.