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 <qmap.h>
00029 #include <qobject.h>
00030 #include <qstring.h>
00031
00032 template <class T> class QValueList;
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 QString& id );
00047
00048 QString id() const;
00049
00050 QString name() const;
00051
00052 QString description() const;
00053
00054 bool isNull() const;
00055
00056 void setName( const QString& name );
00057
00058 void setDescription( const QString& description );
00059
00060 bool operator==( const Kontact::Profile& other ) const;
00061
00062 QString 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 QString& path );
00073 void setId( const QString& id );
00074
00075 private:
00076
00077 static void copyConfigFiles( const QString& source, const QString& dest );
00078
00079 QString localSaveLocation() const;
00080
00081 private:
00082 QString m_id;
00083 QString m_name;
00084 QString m_description;
00085 bool m_local;
00086 QString 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 QString& id ) const;
00109
00110 bool addProfile( const Kontact::Profile& profile );
00111
00112 void removeProfile( const Kontact::Profile& profile );
00113
00114 void removeProfile( const QString& id );
00115
00116 void updateProfile( const Kontact::Profile& profile );
00117
00118 void loadProfile( const QString& id );
00119
00120 void saveToProfile( const QString& id );
00121
00122 QValueList<Kontact::Profile> profiles() const;
00123
00124 ExportError exportProfileToDirectory( const QString& id, const QString& path );
00125
00126 ImportError importProfileFromDirectory( const QString& path );
00127
00128 QString generateNewId() const;
00129
00130 signals:
00131 void profileAdded( const QString& id );
00132
00133 void profileRemoved( const QString& id );
00134
00135 void profileUpdated( const QString& id );
00136
00137 void profileLoaded( const QString& id );
00138
00139 void saveToProfileRequested( const QString& id );
00140
00141 void profileImportFinished( ImportError status );
00142
00143 private:
00144 static ProfileManager* m_self;
00145
00146 static Kontact::Profile readFromConfiguration( const QString& configFile, bool isLocal );
00147
00148 explicit ProfileManager( QObject* parent = 0 );
00149
00150 void readConfig();
00151
00152 void writeConfig() const;
00153
00154 void writeProfileConfig( const Kontact::Profile& profile ) const;
00155
00156 private:
00157 QMap<QString, Kontact::Profile> m_profiles;
00158 };
00159
00160 }
00161
00162 #endif // KONTACT_PROFILEMANAGER_H
|