kontact

profilemanager.h

00001 /*
00002     This file is part of KDE Kontact.
00003 
00004     Copyright (c) 2007 Frank Osterfeld <frank.osterfeld@kdemail.net>
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019 
00020     As a special exception, permission is given to link this program
00021     with any edition of Qt, and distribute the resulting executable,
00022     without including the source code for Qt in the source distribution.
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: // ProfileManager only
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
KDE Home | KDE Accessibility Home | Description of Access Keys