~ubuntu-branches/ubuntu/jaunty/plasma-widget-network-manager/jaunty-updates

« back to all changes in this revision

Viewing changes to libs/storage/connectionpersistence.h

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Mercatante
  • Date: 2009-02-10 16:33:42 UTC
  • Revision ID: james.westby@ubuntu.com-20090210163342-y22tcldf0fuyqqm9
Tags: upstream-0.0+svn924363
ImportĀ upstreamĀ versionĀ 0.0+svn924363

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright 2009 Will Stephenson <wstephenson@kde.org>
 
3
 
 
4
This library is free software; you can redistribute it and/or
 
5
modify it under the terms of the GNU Lesser General Public
 
6
License as published by the Free Software Foundation; either
 
7
version 2.1 of the License, or (at your option) version 3, or any
 
8
later version accepted by the membership of KDE e.V. (or its
 
9
successor approved by the membership of KDE e.V.), which shall
 
10
act as a proxy defined in Section 6 of version 3 of the license.
 
11
 
 
12
This library is distributed in the hope that it will be useful,
 
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
Lesser General Public License for more details.
 
16
 
 
17
You should have received a copy of the GNU Lesser General Public
 
18
License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 
19
*/
 
20
 
 
21
#ifndef CONNECTIONPERSISTENCE_H
 
22
#define CONNECTIONPERSISTENCE_H
 
23
 
 
24
#include <QObject>
 
25
#include <QHash>
 
26
#include <QtGui/qwindowdefs.h> // krazy:exclude=includes (for WId)
 
27
 
 
28
#include <KSharedConfig>
 
29
 
 
30
#include "knm_export.h"
 
31
 
 
32
namespace Knm
 
33
{
 
34
class Connection;
 
35
class Setting;
 
36
class SettingPersistence;
 
37
 
 
38
class KNM_EXPORT ConnectionPersistence : public QObject
 
39
{
 
40
Q_OBJECT
 
41
public:
 
42
    static const QString NETWORKMANAGEMENT_RCFILE;
 
43
    static const QString CONNECTION_PERSISTENCE_PATH;
 
44
    enum SecretStorageMode { Secure, PlainText };
 
45
    class EnumError
 
46
    {
 
47
    public:
 
48
        enum type {NoError = 0, MissingContents, WalletDisabled, WalletNotFound, WalletOpenRefused };
 
49
    };
 
50
    /**
 
51
     * Work with an existing Connection
 
52
     */
 
53
    ConnectionPersistence(Connection *, KSharedConfig::Ptr config, SecretStorageMode mode = Secure);
 
54
    /**
 
55
     * Deserialise a connection from the specified config file
 
56
     */
 
57
    ConnectionPersistence(KSharedConfig::Ptr config, SecretStorageMode mode = Secure);
 
58
 
 
59
    ~ConnectionPersistence();
 
60
 
 
61
    Connection * connection() const;
 
62
 
 
63
    // get/set the window ID used for focus stealing prevention
 
64
    static void setWalletWid( WId wid ) {
 
65
        s_walletWId = wid;
 
66
    }
 
67
 
 
68
    static WId walletWid() {
 
69
        return s_walletWId;
 
70
    }
 
71
 
 
72
    void save();
 
73
    // This assumes the connection has already been constructed with the uuid, type ctor
 
74
    // and populated with all the Settings
 
75
    void load();
 
76
    /**
 
77
     * Trigger asynchronously loading this connection's secrets.
 
78
     * You should connect to the @ref gotSecrets() signal before calling this method
 
79
     * If the SecretStorageMode is PlainText, the signal will be emitted immediately!
 
80
     */
 
81
    void loadSecrets();
 
82
Q_SIGNALS:
 
83
    /**
 
84
     * Emitted when secrets have become available
 
85
     */
 
86
    void loadSecretsResult(uint);
 
87
protected Q_SLOTS:
 
88
    void walletOpenedForRead(bool);
 
89
private:
 
90
    SettingPersistence * persistenceFor(Setting *);
 
91
    QString walletKeyFor(const Setting *) const;
 
92
 
 
93
    static QString s_walletFolderName;
 
94
    static WId s_walletWId;
 
95
 
 
96
    QHash<Setting*, SettingPersistence*> m_persistences;
 
97
    Connection * m_connection;
 
98
    KSharedConfig::Ptr m_config;
 
99
    SecretStorageMode m_storageMode;
 
100
};
 
101
 
 
102
} // namespace Knm
 
103
 
 
104
#endif // CONNECTIONPERSISTENCE_H