Buteo Synchronization Framework
|
This class represents a single profile, a collection of settings or data releated to some entity. More...
#include <Profile.h>
Public Member Functions | |
Profile () | |
Default Constructor. | |
Profile (const QString &aName, const QString &aType) | |
Constructs a Profile object with given name and type. | |
Profile (const QDomElement &aRoot) | |
Constructs a Profile object from XML. | |
Profile (const Profile &aSource) | |
Copy constructor. | |
virtual Profile * | clone () const |
Creates a clone of the profile. | |
virtual | ~Profile () |
Destructor. | |
QString | name () const |
Gets the name of the profile. | |
QString | displayname () const |
Gets the display name of the profile. | |
virtual void | setName (const QString &aName) |
Sets the name of the profile. | |
virtual void | setName (const QStringList &aKeys) |
Sets the name of the profile. | |
QString | type () const |
Gets the type of the profile. | |
virtual QDomElement | toXml (QDomDocument &aDoc, bool aLocalOnly=true) const |
Creates a XML representation of the profile. | |
QString | toString () const |
Outputs a XML representation of the profile to a string. | |
QString | key (const QString &aName, const QString &aDefault=QString()) const |
Gets the value of the given key. | |
QMap< QString, QString > | allKeys () const |
Gets all keys and their values. | |
QMap< QString, QString > | allNonStorageKeys () const |
Gets all keys that are not related to storages. | |
bool | boolKey (const QString &aName, bool aDefault=false) const |
Gets the value of the given boolean key. | |
QStringList | keyValues (const QString &aName) const |
Gets the values of all keys with the given name. | |
QStringList | keyNames () const |
Gets the names of all keys. | |
void | setKey (const QString &aName, const QString &aValue) |
Sets the value of a key. | |
void | setKeyValues (const QString &aName, const QStringList &aValues) |
Sets multiple values for a key. | |
void | setBoolKey (const QString &aName, bool aValue) |
Sets the value of a boolean key. | |
void | removeKey (const QString &aName) |
Removes a key from profile. All instances of the key are removed. | |
const ProfileField * | field (const QString &aName) const |
Gets the field with the given name. | |
QList< const ProfileField * > | allFields () const |
Gets all fields. | |
QList< const ProfileField * > | visibleFields () const |
Gets all visible fields of the profile. | |
bool | isValid () const |
Checks if the profile is valid. | |
QStringList | subProfileNames (const QString &aType="") const |
Gets the names of all sub-profiles with the given type. | |
Profile * | subProfile (const QString &aName, const QString &aType="") |
Gets a sub-profile with the given name and type. | |
const Profile * | subProfile (const QString &aName, const QString &aType="") const |
const method for subProfile | |
const Profile * | subProfileByKeyValue (const QString &aKey, const QString &aValue, const QString &aType, bool aEnabledOnly) const |
Gets a sub-profile by key value. | |
QList< Profile * > | allSubProfiles () |
Gets all sub-profiles. | |
QList< const Profile * > | allSubProfiles () const |
Gets all sub-profiles as const. | |
void | merge (const Profile &aSource) |
Merges a profile to this profile. | |
bool | isLoaded () const |
Checks if the profile is fully constructed by loading all sub-profiles from separate profile files. | |
void | setLoaded (bool aLoaded) |
Sets if the profile is fully loaded. | |
virtual bool | isEnabled () const |
Returns if the profile is enabled. | |
void | setEnabled (bool aEnabled) |
Set is the profile is enabled. | |
bool | isHidden () const |
Checks if the profile is hidden. | |
bool | isProtected () const |
Checks if the profile is protected. | |
Static Public Attributes | |
static const QString | TYPE_CLIENT |
String constants for different profile type names. | |
static const QString | TYPE_SERVER |
Server type . | |
static const QString | TYPE_STORAGE |
Storage type. | |
static const QString | TYPE_SYNC |
Service type. | |
This class represents a single profile, a collection of settings or data releated to some entity.
A profile can contain keys, fields and other profiles as sub-profiles. Functions for accessing all these in different ways are provided. A profile object can be created from XML and exported to XML, but otherwise the class interface does not use XML. New classes can be derived from this class for different profile types to add helper functions for accessing specific keys and fields known by the profile type.
Profile::Profile | ( | ) |
Default Constructor.
Profile::Profile | ( | const QString & | aName, |
const QString & | aType | ||
) |
|
explicit |
Constructs a Profile object from XML.
aRoot | Root element of the profile XML. |
Profile::Profile | ( | const Profile & | aSource | ) |
Copy constructor.
aSource | Copy source. |
QList< const ProfileField * > Profile::allFields | ( | ) | const |
Gets all fields.
QMap< QString, QString > Profile::allKeys | ( | ) | const |
Gets all keys and their values.
QMap< QString, QString > Profile::allNonStorageKeys | ( | ) | const |
Gets all keys that are not related to storages.
Gets all sub-profiles.
Gets all sub-profiles as const.
bool Profile::boolKey | ( | const QString & | aName, |
bool | aDefault = false |
||
) | const |
Gets the value of the given boolean key.
Returns true if the key exists and its value equals "true". If the key does not exist, the default value is returned.
aName | Name of the key to read. |
aDefault | Value to return if the key does not exist. |
|
virtual |
Creates a clone of the profile.
Reimplemented in Buteo::StorageProfile, and Buteo::SyncProfile.
QString Profile::displayname | ( | ) | const |
Gets the display name of the profile.
const ProfileField * Profile::field | ( | const QString & | aName | ) | const |
Gets the field with the given name.
If the field does not exist, NULL is returned. To get/set the value associated with the field, use the key handling functions with the name of the field.
aName | Name of the field. |
|
virtual |
Returns if the profile is enabled.
Reimplemented in Buteo::StorageProfile.
bool Profile::isHidden | ( | ) | const |
Checks if the profile is hidden.
A hidden profile should not be visible in sync ui.
bool Profile::isLoaded | ( | ) | const |
Checks if the profile is fully constructed by loading all sub-profiles from separate profile files.
A profile can have sub-profiles defined directly inside it, but typically the sub-profiles are made complete by checking if there is a separate profile file with the same name and type, and then loading and merging the keys and fields defined in these files to the ones defined directly in the main profile.
bool Profile::isProtected | ( | ) | const |
Checks if the profile is protected.
A protected profile can not be removed using the ProfileManager.
bool Profile::isValid | ( | ) | const |
Checks if the profile is valid.
A profile is valid if:
QString Profile::key | ( | const QString & | aName, |
const QString & | aDefault = QString() |
||
) | const |
Gets the value of the given key.
aName | Name of the key to read. |
aDefault | Default value. |
QStringList Profile::keyNames | ( | ) | const |
Gets the names of all keys.
QStringList Profile::keyValues | ( | const QString & | aName | ) | const |
Gets the values of all keys with the given name.
If the key does not exist at all, an empty list is returned.
aName | Name of the key to read. |
void Profile::merge | ( | const Profile & | aSource | ) |
Merges a profile to this profile.
The source profile and all its sub-profiles are merged as direct sub-profiles of this profile. This function is mainly used by the ProfileManager, when it constructs a single profile from multiple sub-profile files.
aSource | Profile to merge. |
QString Profile::name | ( | ) | const |
Gets the name of the profile.
void Profile::removeKey | ( | const QString & | aName | ) |
Removes a key from profile. All instances of the key are removed.
aName | Name of the key to remove. |
void Profile::setBoolKey | ( | const QString & | aName, |
bool | aValue | ||
) |
Sets the value of a boolean key.
The key value is set to "true" of "false". If the key does not exist yet, it is created.
aName | Name of the key. |
aValue | Value of the key. |
void Profile::setEnabled | ( | bool | aEnabled | ) |
Set is the profile is enabled.
aEnabled | New enabled status. |
void Profile::setKey | ( | const QString & | aName, |
const QString & | aValue | ||
) |
Sets the value of a key.
If the key does not exist yet, it is created.
aName | Name of the key. |
aValue | Value of the key. |
void Profile::setKeyValues | ( | const QString & | aName, |
const QStringList & | aValues | ||
) |
Sets multiple values for a key.
All previous (local) values of the key are removed. A key entry for each of the provided values is then created.
aName | Name of the key. |
aValues | Values for the key. |
void Profile::setLoaded | ( | bool | aLoaded | ) |
Sets if the profile is fully loaded.
This function is used by the ProfileManager. The purpose of this flag is to avoid loading the same sub-profile multiple times, if there are more than one references to it in the sub-profile tree.
aLoaded | Is the profile loaded. |
|
virtual |
Sets the name of the profile.
aName | Name of the profile. |
Reimplemented in Buteo::SyncProfile.
|
virtual |
Sets the name of the profile.
aKeys | Keys required to generate the profile name. |
Reimplemented in Buteo::SyncProfile.
Profile * Profile::subProfile | ( | const QString & | aName, |
const QString & | aType = "" |
||
) |
Gets a sub-profile with the given name and type.
aName | Name of the sub-profile to get. |
aType | Type of the sub-profile to get. If the type is empty, any type is accepted. |
const Profile * Profile::subProfile | ( | const QString & | aName, |
const QString & | aType = "" |
||
) | const |
const method for subProfile
const Profile * Profile::subProfileByKeyValue | ( | const QString & | aKey, |
const QString & | aValue, | ||
const QString & | aType, | ||
bool | aEnabledOnly | ||
) | const |
Gets a sub-profile by key value.
Returns the first sub-profile that has a key with the given value.
aKey | Name of the key. |
aValue | Required value of the key. |
aType | Type of the sub-profile. If empty, any type can match. |
aEnabledOnly | Should only enabled sub-profiles be compared. |
QStringList Profile::subProfileNames | ( | const QString & | aType = "" | ) | const |
Gets the names of all sub-profiles with the given type.
aType | Type of sub-profiles to get. If this is empty, all sub-profile names are returned. |
QString Profile::toString | ( | ) | const |
Outputs a XML representation of the profile to a string.
Merged sub-profile data is also included in the output string.
|
virtual |
Creates a XML representation of the profile.
aDoc | Parent document for the created XML elements. The elements are not inserted to the document by this function, but the document is required to create the elements. |
aLocalOnly | Should only local profile elements be present in the generated XML. If this is true, elements merged from sub-profiles are not included. |
Reimplemented in Buteo::SyncProfile.
QString Profile::type | ( | ) | const |
Gets the type of the profile.
QList< const ProfileField * > Profile::visibleFields | ( | ) | const |
Gets all visible fields of the profile.
Each field can define its visibility. This functions returns only fields that are visible.
|
static |
Service type.
Sync type