summaryrefslogtreecommitdiffstats
path: root/kontact/src/profilemanager.h
blob: bd05d49d7a261e5db8a01b320451fada8d18f832 (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
163
/*
    This file is part of KDE Kontact.

    Copyright (c) 2007 Frank Osterfeld <[email protected]>

    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 TQt, and distribute the resulting executable,
    without including the source code for TQt in the source distribution.
*/

#ifndef KONTACT_PROFILEMANAGER_H
#define KONTACT_PROFILEMANAGER_H

#include <tqmap.h>
#include <tqobject.h>
#include <tqstring.h>

template <class T> class TQValueList;

namespace TDEIO {
    class Job;
}

namespace Kontact {

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

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

    TQString id() const;

    TQString name() const;

    TQString description() const;

    bool isNull() const;

    void setName( const TQString& name );

    void setDescription( const TQString& description );

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

    TQString saveLocation() const;

private: // ProfileManager only

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

private:

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

    TQString localSaveLocation() const;

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

class ProfileManager : public TQObject
{
TQ_OBJECT
  
public:
    enum ImportError {
        SuccessfulImport=0,
        NoValidProfile
    };

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

    static ProfileManager* self();

    ~ProfileManager();

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

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

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

    void removeProfile( const TQString& id );

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

    void loadProfile( const TQString& id );

    void saveToProfile( const TQString& id );

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

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

    ImportError importProfileFromDirectory( const TQString& path );

    TQString generateNewId() const;

signals:
    void profileAdded( const TQString& id );

    void profileRemoved( const TQString& id );

    void profileUpdated( const TQString& id );

    void profileLoaded( const TQString& id );

    void saveToProfileRequested( const TQString& id );

    void profileImportFinished( ImportError status );

private:
    static ProfileManager* m_self;

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

    explicit ProfileManager( TQObject* parent = 0 );

    void readConfig();

    void writeConfig() const;

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

private:
    TQMap<TQString, Kontact::Profile> m_profiles;
};

}

#endif // KONTACT_PROFILEMANAGER_H