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 TQt, and distribute the resulting executable,
00022     without including the source code for TQt in the source distribution.
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: // ProfileManager only
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 TQObject
00090 {
00091 Q_OBJECT
00092   TQ_OBJECT
00093 public:
00094     enum ImportError {
00095         SuccessfulImport=0,
00096         NoValidProfile
00097     };
00098 
00099     enum ExportError {
00100         SuccessfulExport=0,
00101         DirectoryDoesNotExist,
00102         DirectoryNotWritable
00103     };
00104 
00105     static ProfileManager* self();
00106 
00107     ~ProfileManager();
00108 
00109     Kontact::Profile profileById( const TQString& id ) const;
00110 
00111     bool addProfile( const Kontact::Profile& profile, bool syncConfig = true );
00112 
00113     void removeProfile( const Kontact::Profile& profile );
00114 
00115     void removeProfile( const TQString& id );
00116 
00117     void updateProfile( const Kontact::Profile& profile );
00118 
00119     void loadProfile( const TQString& id );
00120 
00121     void saveToProfile( const TQString& id );
00122 
00123     TQValueList<Kontact::Profile> profiles() const;
00124 
00125     ExportError exportProfileToDirectory( const TQString& id, const TQString& path );
00126 
00127     ImportError importProfileFromDirectory( const TQString& path );
00128 
00129     TQString generateNewId() const;
00130 
00131 signals:
00132     void profileAdded( const TQString& id );
00133 
00134     void profileRemoved( const TQString& id );
00135 
00136     void profileUpdated( const TQString& id );
00137 
00138     void profileLoaded( const TQString& id );
00139 
00140     void saveToProfileRequested( const TQString& id );
00141 
00142     void profileImportFinished( ImportError status );
00143 
00144 private:
00145     static ProfileManager* m_self;
00146 
00147     static Kontact::Profile readFromConfiguration( const TQString& configFile, bool isLocal );
00148 
00149     explicit ProfileManager( TQObject* parent = 0 );
00150 
00151     void readConfig();
00152 
00153     void writeConfig() const;
00154 
00155     void writeProfileConfig( const Kontact::Profile& profile ) const;
00156 
00157 private:
00158     TQMap<TQString, Kontact::Profile> m_profiles;
00159 };
00160 
00161 }
00162 
00163 #endif // KONTACT_PROFILEMANAGER_H