kontact

profilemanager.h
1 /*
2  This file is part of KDE Kontact.
3 
4  Copyright (c) 2007 Frank Osterfeld <frank.osterfeld@kdemail.net>
5 
6  This program 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 2 of the License, or
9  (at your option) any later version.
10 
11  This program 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 this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 
20  As a special exception, permission is given to link this program
21  with any edition of TQt, and distribute the resulting executable,
22  without including the source code for TQt in the source distribution.
23 */
24 
25 #ifndef KONTACT_PROFILEMANAGER_H
26 #define KONTACT_PROFILEMANAGER_H
27 
28 #include <tqmap.h>
29 #include <tqobject.h>
30 #include <tqstring.h>
31 
32 template <class T> class TQValueList;
33 
34 namespace TDEIO {
35  class Job;
36 }
37 
38 namespace Kontact {
39 
40 class Profile
41 {
42  friend class ProfileManager;
43 public:
44  Profile();
45 
46  explicit Profile( const TQString& id, bool isLocal = false );
47 
48  TQString id() const;
49 
50  TQString name() const;
51 
52  TQString description() const;
53 
54  bool isNull() const;
55 
56  void setName( const TQString& name );
57 
58  void setDescription( const TQString& description );
59 
60  bool operator==( const Kontact::Profile& other ) const;
61 
62  TQString saveLocation() const;
63 
64 private: // ProfileManager only
65 
66  enum SetLocalMode {
67  DoNotCopyProfileFiles,
68  CopyProfileFiles
69  };
70  void setLocal( SetLocalMode mode );
71  bool isLocal() const;
72  void setOriginalLocation( const TQString& path );
73  void setId( const TQString& id );
74 
75 private:
76 
77  static void copyConfigFiles( const TQString& source, const TQString& dest );
78 
79  TQString localSaveLocation() const;
80 
81 private:
82  TQString m_id;
83  TQString m_name;
84  TQString m_description;
85  bool m_local;
86  TQString m_originalLocation;
87 };
88 
89 class ProfileManager : public TQObject
90 {
91 TQ_OBJECT
92 
93 public:
94  enum ImportError {
95  SuccessfulImport=0,
96  NoValidProfile
97  };
98 
99  enum ExportError {
100  SuccessfulExport=0,
101  DirectoryDoesNotExist,
102  DirectoryNotWritable
103  };
104 
105  static ProfileManager* self();
106 
107  ~ProfileManager();
108 
109  Kontact::Profile profileById( const TQString& id ) const;
110 
111  bool addProfile( const Kontact::Profile& profile, bool syncConfig = true );
112 
113  void removeProfile( const Kontact::Profile& profile );
114 
115  void removeProfile( const TQString& id );
116 
117  void updateProfile( const Kontact::Profile& profile );
118 
119  void loadProfile( const TQString& id );
120 
121  void saveToProfile( const TQString& id );
122 
123  TQValueList<Kontact::Profile> profiles() const;
124 
125  ExportError exportProfileToDirectory( const TQString& id, const TQString& path );
126 
127  ImportError importProfileFromDirectory( const TQString& path );
128 
129  TQString generateNewId() const;
130 
131 signals:
132  void profileAdded( const TQString& id );
133 
134  void profileRemoved( const TQString& id );
135 
136  void profileUpdated( const TQString& id );
137 
138  void profileLoaded( const TQString& id );
139 
140  void saveToProfileRequested( const TQString& id );
141 
142  void profileImportFinished( ImportError status );
143 
144 private:
145  static ProfileManager* m_self;
146 
147  static Kontact::Profile readFromConfiguration( const TQString& configFile, bool isLocal );
148 
149  explicit ProfileManager( TQObject* parent = 0 );
150 
151  void readConfig();
152 
153  void writeConfig() const;
154 
155  void writeProfileConfig( const Kontact::Profile& profile ) const;
156 
157 private:
158  TQMap<TQString, Kontact::Profile> m_profiles;
159 };
160 
161 }
162 
163 #endif // KONTACT_PROFILEMANAGER_H