Buteo Synchronization Framework
Profile.h
1 /*
2  * This file is part of buteo-syncfw package
3  *
4  * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
5  *
6  * Contact: Sateesh Kavuri <sateesh.kavuri@nokia.com>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * version 2.1 as published by the Free Software Foundation.
11  *
12  * This library is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA
21  *
22  */
23 
24 #ifndef PROFILE_H
25 #define PROFILE_H
26 
27 #include <QList>
28 #include <QMap>
29 #include <QString>
30 #include <QStringList>
31 #include "ProfileField.h"
32 
33 class QDomDocument;
34 class QDomElement;
35 
36 namespace Buteo {
37 
38 class ProfileTest;
39 class ProfilePrivate;
40 
41 
52 class Profile
53 {
54 public:
55 
57  static const QString TYPE_CLIENT;
59  static const QString TYPE_SERVER;
61  static const QString TYPE_STORAGE;
63  //static const QString TYPE_SERVICE;
65  static const QString TYPE_SYNC;
66 
70  Profile();
71 
72 
79  Profile(const QString &aName, const QString &aType);
80 
85  explicit Profile(const QDomElement &aRoot);
86 
91  Profile(const Profile &aSource);
92 
97  virtual Profile *clone() const;
98 
100  virtual ~Profile();
101 
106  QString name() const;
107 
112  QString displayname() const;
113 
118  virtual void setName(const QString &aName);
119 
124  virtual void setName(const QStringList &aKeys);
125 
130  QString type() const;
131 
142  virtual QDomElement toXml(QDomDocument &aDoc, bool aLocalOnly = true) const;
143 
149  QString toString() const;
150 
159  QString key(const QString &aName, const QString &aDefault = QString()) const;
160 
166 
172 
181  bool boolKey(const QString &aName, bool aDefault = false) const;
182 
189  QStringList keyValues(const QString &aName) const;
190 
195  QStringList keyNames() const;
196 
203  void setKey(const QString &aName, const QString &aValue);
204 
212  void setKeyValues(const QString &aName, const QStringList &aValues);
213 
221  void setBoolKey(const QString &aName, bool aValue);
222 
227  void removeKey(const QString &aName);
228 
237  const ProfileField *field(const QString &aName) const;
238 
244 
252 
263  bool isValid() const;
264 
271  QStringList subProfileNames(const QString &aType = "") const;
272 
282  Profile *subProfile(const QString &aName, const QString &aType = "");
283 
287  const Profile *subProfile(const QString &aName, const QString &aType = "") const;
288 
298  const Profile *subProfileByKeyValue(const QString &aKey,
299  const QString &aValue,
300  const QString &aType,
301  bool aEnabledOnly) const;
302 
309 
316 
325  void merge(const Profile &aSource);
326 
337  bool isLoaded() const;
338 
346  void setLoaded(bool aLoaded);
347 
352  virtual bool isEnabled() const;
353 
358  void setEnabled(bool aEnabled);
359 
365  bool isHidden() const;
366 
372  bool isProtected() const;
373 
374 private:
375 
376  Profile &operator=(const Profile &aRhs);
377 
378  ProfilePrivate *d_ptr;
379 
386  QString generateProfileId(const QStringList &aKeys);
387 
388 #ifdef SYNCFW_UNIT_TESTS
389  friend class ProfileTest;
390 #endif
391 
392 };
393 
394 }
395 
396 #endif // PROFILE_H
This class represents a profile field.
Definition: ProfileField.h:49
Private implementation class for Profile class.
Definition: Profile_p.h:35
This class represents a single profile, a collection of settings or data releated to some entity.
Definition: Profile.h:53
QList< Profile * > allSubProfiles()
Gets all sub-profiles.
Definition: Profile.cpp:427
QList< const ProfileField * > allFields() const
Gets all fields.
Definition: Profile.cpp:240
QStringList keyValues(const QString &aName) const
Gets the values of all keys with the given name.
Definition: Profile.cpp:175
void setEnabled(bool aEnabled)
Set is the profile is enabled.
Definition: Profile.cpp:491
static const QString TYPE_SERVER
Server type .
Definition: Profile.h:59
bool isHidden() const
Checks if the profile is hidden.
Definition: Profile.cpp:496
void setKeyValues(const QString &aName, const QStringList &aValues)
Sets multiple values for a key.
Definition: Profile.cpp:203
Profile()
Default Constructor.
Definition: Profile.cpp:45
QString name() const
Gets the name of the profile.
Definition: Profile.cpp:108
virtual Profile * clone() const
Creates a clone of the profile.
Definition: Profile.cpp:97
virtual ~Profile()
Destructor.
Definition: Profile.cpp:102
static const QString TYPE_STORAGE
Storage type.
Definition: Profile.h:61
void setKey(const QString &aName, const QString &aValue)
Sets the value of a key.
Definition: Profile.cpp:186
QString displayname() const
Gets the display name of the profile.
Definition: Profile.cpp:506
virtual QDomElement toXml(QDomDocument &aDoc, bool aLocalOnly=true) const
Creates a XML representation of the profile.
Definition: Profile.cpp:268
bool isValid() const
Checks if the profile is valid.
Definition: Profile.cpp:329
QMap< QString, QString > allNonStorageKeys() const
Gets all keys that are not related to storages.
Definition: Profile.cpp:150
void removeKey(const QString &aName)
Removes a key from profile. All instances of the key are removed.
Definition: Profile.cpp:223
void setLoaded(bool aLoaded)
Sets if the profile is fully loaded.
Definition: Profile.cpp:481
QString key(const QString &aName, const QString &aDefault=QString()) const
Gets the value of the given key.
Definition: Profile.cpp:129
bool boolKey(const QString &aName, bool aDefault=false) const
Gets the value of the given boolean key.
Definition: Profile.cpp:165
QStringList subProfileNames(const QString &aType="") const
Gets the names of all sub-profiles with the given type.
Definition: Profile.cpp:371
bool isLoaded() const
Checks if the profile is fully constructed by loading all sub-profiles from separate profile files.
Definition: Profile.cpp:476
const ProfileField * field(const QString &aName) const
Gets the field with the given name.
Definition: Profile.cpp:229
virtual bool isEnabled() const
Returns if the profile is enabled.
Definition: Profile.cpp:486
static const QString TYPE_CLIENT
String constants for different profile type names.
Definition: Profile.h:57
QString type() const
Gets the type of the profile.
Definition: Profile.cpp:124
static const QString TYPE_SYNC
Service type.
Definition: Profile.h:65
void setBoolKey(const QString &aName, bool aValue)
Sets the value of a boolean key.
Definition: Profile.cpp:218
void merge(const Profile &aSource)
Merges a profile to this profile.
Definition: Profile.cpp:442
QStringList keyNames() const
Gets the names of all keys.
Definition: Profile.cpp:181
QString toString() const
Outputs a XML representation of the profile to a string.
Definition: Profile.cpp:316
Profile * subProfile(const QString &aName, const QString &aType="")
Gets a sub-profile with the given name and type.
Definition: Profile.cpp:384
virtual void setName(const QString &aName)
Sets the name of the profile.
Definition: Profile.cpp:113
QList< const ProfileField * > visibleFields() const
Gets all visible fields of the profile.
Definition: Profile.cpp:247
bool isProtected() const
Checks if the profile is protected.
Definition: Profile.cpp:501
const Profile * subProfileByKeyValue(const QString &aKey, const QString &aValue, const QString &aType, bool aEnabledOnly) const
Gets a sub-profile by key value.
Definition: Profile.cpp:410
QMap< QString, QString > allKeys() const
Gets all keys and their values.
Definition: Profile.cpp:142
Definition: SyncBackupAdaptor.h:40