kontact
profilemanager.h00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef KONTACT_PROFILEMANAGER_H
00026 #define KONTACT_PROFILEMANAGER_H
00027
00028 #include <tqmap.h>
00029 #include <tqobject.h>
00030 #include <tqstring.h>
00031
00032 template <class T> class TQValueList;
00033
00034 namespace KIO {
00035 class Job;
00036 }
00037
00038 namespace Kontact {
00039
00040 class Profile
00041 {
00042 friend class ProfileManager;
00043 public:
00044 Profile();
00045
00046 explicit Profile( const TQString& id, bool isLocal = false );
00047
00048 TQString id() const;
00049
00050 TQString name() const;
00051
00052 TQString description() const;
00053
00054 bool isNull() const;
00055
00056 void setName( const TQString& name );
00057
00058 void setDescription( const TQString& description );
00059
00060 bool operator==( const Kontact::Profile& other ) const;
00061
00062 TQString saveLocation() const;
00063
00064 private:
00065
00066 enum SetLocalMode {
00067 DoNotCopyProfileFiles,
00068 CopyProfileFiles
00069 };
00070 void setLocal( SetLocalMode mode );
00071 bool isLocal() const;
00072 void setOriginalLocation( const TQString& path );
00073 void setId( const TQString& id );
00074
00075 private:
00076
00077 static void copyConfigFiles( const TQString& source, const TQString& dest );
00078
00079 TQString localSaveLocation() const;
00080
00081 private:
00082 TQString m_id;
00083 TQString m_name;
00084 TQString m_description;
00085 bool m_local;
00086 TQString m_originalLocation;
00087 };
00088
00089 class ProfileManager : public QObject
00090 {
00091 Q_OBJECT
00092 public:
00093 enum ImportError {
00094 SuccessfulImport=0,
00095 NoValidProfile
00096 };
00097
00098 enum ExportError {
00099 SuccessfulExport=0,
00100 DirectoryDoesNotExist,
00101 DirectoryNotWritable
00102 };
00103
00104 static ProfileManager* self();
00105
00106 ~ProfileManager();
00107
00108 Kontact::Profile profileById( const TQString& id ) const;
00109
00110 bool addProfile( const Kontact::Profile& profile, bool syncConfig = true );
00111
00112 void removeProfile( const Kontact::Profile& profile );
00113
00114 void removeProfile( const TQString& id );
00115
00116 void updateProfile( const Kontact::Profile& profile );
00117
00118 void loadProfile( const TQString& id );
00119
00120 void saveToProfile( const TQString& id );
00121
00122 TQValueList<Kontact::Profile> profiles() const;
00123
00124 ExportError exportProfileToDirectory( const TQString& id, const TQString& path );
00125
00126 ImportError importProfileFromDirectory( const TQString& path );
00127
00128 TQString generateNewId() const;
00129
00130 signals:
00131 void profileAdded( const TQString& id );
00132
00133 void profileRemoved( const TQString& id );
00134
00135 void profileUpdated( const TQString& id );
00136
00137 void profileLoaded( const TQString& id );
00138
00139 void saveToProfileRequested( const TQString& id );
00140
00141 void profileImportFinished( ImportError status );
00142
00143 private:
00144 static ProfileManager* m_self;
00145
00146 static Kontact::Profile readFromConfiguration( const TQString& configFile, bool isLocal );
00147
00148 explicit ProfileManager( TQObject* parent = 0 );
00149
00150 void readConfig();
00151
00152 void writeConfig() const;
00153
00154 void writeProfileConfig( const Kontact::Profile& profile ) const;
00155
00156 private:
00157 TQMap<TQString, Kontact::Profile> m_profiles;
00158 };
00159
00160 }
00161
00162 #endif // KONTACT_PROFILEMANAGER_H
|