summaryrefslogtreecommitdiffstats
path: root/kontact/src/profilemanager.h
blob: e8b10adb54ec56cef4bb0edeaf1feb0d1bbf1b07 (plain)
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
    This file is part of KDE Kontact.

    Copyright (c) 2007 Frank Osterfeld <frank.osterfeld@kdemail.net>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

    As a special exception, permission is given to link this program
    with any edition of Qt, and distribute the resulting executable,
    without including the source code for Qt in the source distribution.
*/

#ifndef KONTACT_PROFILEMANAGER_H
#define KONTACT_PROFILEMANAGER_H

#include <qmap.h>
#include <qobject.h>
#include <qstring.h>

template <class T> class QValueList;

namespace KIO {
    class Job;
}

namespace Kontact {

class Profile
{
    friend class ProfileManager;
public:
    Profile();

    explicit Profile( const QString& id, bool isLocal = false );

    QString id() const;

    QString name() const;

    QString description() const;

    bool isNull() const;

    void setName( const QString& name );

    void setDescription( const QString& description );

    bool operator==( const Kontact::Profile& other ) const;

    QString saveLocation() const;

private: // ProfileManager only

    enum SetLocalMode {
        DoNotCopyProfileFiles,
        CopyProfileFiles
    };
    void setLocal( SetLocalMode mode );
    bool isLocal() const;
    void setOriginalLocation( const QString& path );
    void setId( const QString& id );

private:

    static void copyConfigFiles( const QString& source, const QString& dest );

    QString localSaveLocation() const;

private:
    QString m_id;
    QString m_name;
    QString m_description;
    bool m_local;
    QString m_originalLocation;
};

class ProfileManager : public QObject
{
Q_OBJECT
public:
    enum ImportError {
        SuccessfulImport=0,
        NoValidProfile
    };

    enum ExportError {
        SuccessfulExport=0,
        DirectoryDoesNotExist,
        DirectoryNotWritable
    };

    static ProfileManager* self();

    ~ProfileManager();

    Kontact::Profile profileById( const QString& id ) const;

    bool addProfile( const Kontact::Profile& profile, bool syncConfig = true );

    void removeProfile( const Kontact::Profile& profile );

    void removeProfile( const QString& id );

    void updateProfile( const Kontact::Profile& profile );

    void loadProfile( const QString& id );

    void saveToProfile( const QString& id );

    QValueList<Kontact::Profile> profiles() const;

    ExportError exportProfileToDirectory( const QString& id, const QString& path );

    ImportError importProfileFromDirectory( const QString& path );

    QString generateNewId() const;

signals:
    void profileAdded( const QString& id );

    void profileRemoved( const QString& id );

    void profileUpdated( const QString& id );

    void profileLoaded( const QString& id );

    void saveToProfileRequested( const QString& id );

    void profileImportFinished( ImportError status );

private:
    static ProfileManager* m_self;

    static Kontact::Profile readFromConfiguration( const QString& configFile, bool isLocal );

    explicit ProfileManager( QObject* parent = 0 );

    void readConfig();

    void writeConfig() const;

    void writeProfileConfig( const Kontact::Profile& profile ) const;

private:
    QMap<QString, Kontact::Profile> m_profiles;
};

}

#endif // KONTACT_PROFILEMANAGER_H