Buteo::Profile Class Reference

This class represents a single profile, a collection of settings or data releated to some entity. More...

`#include <Profile.h>`

Inheritance diagram for Buteo::Profile:

## 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.

## Detailed Description

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.

## Constructor & Destructor Documentation

## Profile() [1/3]

Profile::Profile | ( | const QString & | aName,
|  | const QString & | aType )

Constructs a Profile object with given name and type.

Parameters

  aName | Profile name.
  aType | Profile type. Prefer using predefined constants like TYPE_SYNC.

## Profile() [2/3]

Profile::Profile | ( | const QDomElement & | aRoot | ) |

explicit

Constructs a Profile object from XML.

Parameters

  aRoot | Root element of the profile XML.

## Profile() [3/3]

Profile::Profile | ( | const Profile & | aSource | ) |

Copy constructor.

Parameters

  aSource | Copy source.

## Member Function Documentation

## allFields()

QList< const ProfileField * > Profile::allFields | ( |  | ) | const

Gets all fields.

Returns
  List of pointers to the fields.

## allKeys()

QMap< QString, QString > Profile::allKeys | ( |  | ) | const

Gets all keys and their values.

Returns
  Map of key names/values.

## allNonStorageKeys()

QMap< QString, QString > Profile::allNonStorageKeys | ( |  | ) | const

Gets all keys that are not related to storages.

Returns
  Map of key names/values.

## allSubProfiles() [1/2]

QList< Profile * > Profile::allSubProfiles | ( |  | ) |

Gets all sub-profiles.

Returns
  List of sub-profiles. The returned sub-profiles are owned by the main profile and the user must not delete them.

## allSubProfiles() [2/2]

QList< const Profile * > Profile::allSubProfiles | ( |  | ) | const

Gets all sub-profiles as const.

Returns
  List of sub-profiles. The returned sub-profiles are const and are owned by the main profile and the user must not delete them.

## boolKey()

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.

Parameters

  aName | Name of the key to read.
  aDefault | Value to return if the key does not exist.

Returns
  The boolean value of the key.

## clone()

Profile * Profile::clone | ( |  | ) | const

virtual

Creates a clone of the profile.

Returns
  The clone.

Reimplemented in Buteo::StorageProfile, and Buteo::SyncProfile.

## displayname()

QString Profile::displayname | ( |  | ) | const

Gets the display name of the profile.

Returns
  Profile display name.

## field()

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.

Parameters

  aName | Name of the field.

Returns
  Pointer to the field.

## isEnabled()

bool Profile::isEnabled | ( |  | ) | const

virtual

Returns if the profile is enabled.

Returns
  Is the profile enabled.

Reimplemented in Buteo::StorageProfile.

## isHidden()

bool Profile::isHidden | ( |  | ) | const

Checks if the profile is hidden.

A hidden profile should not be visible in sync ui.

Returns
  True if hidden.

## isLoaded()

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.

Returns
  Is the profile fully loaded.

## isProtected()

bool Profile::isProtected | ( |  | ) | const

Checks if the profile is protected.

A protected profile can not be removed using the ProfileManager.

Returns
  True if protected.

## isValid()

bool Profile::isValid | ( |  | ) | const

Checks if the profile is valid.

A profile is valid if:

1. Name and type are set (not empty).
2. For each field there is a key with the same name, and the key value (or all values, if multiple keys with the same name exist) is valid for the field.
3. All sub-profiles are valid according to these three rules.
   Returns
     Is the profile valid.

## key()

QString Profile::key | ( | const QString & | aName,
|  | const QString & | aDefault = QString() ) const

Gets the value of the given key.

Parameters

  aName | Name of the key to read.
  aDefault | Default value.

Returns
  Value of the key. If the key was not found, the default is returned. If there are multiple instances of the key with the given name, the value of the first instance is returned.

## keyNames()

QStringList Profile::keyNames | ( |  | ) | const

Gets the names of all keys.

Returns
  List of key names.

## keyValues()

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.

Parameters

  aName | Name of the key to read.

Returns
  List of values associated with the key.

## merge()

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.

Parameters

  aSource | Profile to merge.

## name()

QString Profile::name | ( |  | ) | const

Gets the name of the profile.

Returns
  Profile name.

## removeKey()

void Profile::removeKey | ( | const QString & | aName | ) |

Removes a key from profile. All instances of the key are removed.

Parameters

  aName | Name of the key to remove.

## setBoolKey()

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.

Parameters

  aName | Name of the key.
  aValue | Value of the key.

## setEnabled()

void Profile::setEnabled | ( | bool | aEnabled | ) |

Set is the profile is enabled.

Parameters

  aEnabled | New enabled status.

## setKey()

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.

Parameters

  aName | Name of the key.
  aValue | Value of the key.

## setKeyValues()

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.

Parameters

  aName | Name of the key.
  aValues | Values for the key.

## setLoaded()

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.

Parameters

  aLoaded | Is the profile loaded.

## setName() [1/2]

void Profile::setName | ( | const QString & | aName | ) |

virtual

Sets the name of the profile.

Parameters

  aName | Name of the profile.

Reimplemented in Buteo::SyncProfile.

## setName() [2/2]

void Profile::setName | ( | const QStringList & | aKeys | ) |

virtual

Sets the name of the profile.

Parameters

  aKeys | Keys required to generate the profile name.

Reimplemented in Buteo::SyncProfile.

## subProfile() [1/2]

Profile * Profile::subProfile | ( | const QString & | aName,
|  | const QString & | aType = "" )

Gets a sub-profile with the given name and type.

Parameters

  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.

Returns
  The first sub-profile that matches the criteria. NULL if no such sub-profile was found. The returned sub-profile is owned by the main profile and the user must not delete it.

## subProfile() [2/2]

const Profile * Profile::subProfile | ( | const QString & | aName,
|  | const QString & | aType = "" ) const

const method for subProfile

See also
  Profile::subProfile

## subProfileByKeyValue()

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.

Parameters

  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.

Returns
  First matching sub-profile, NULL if no match.

## subProfileNames()

QStringList Profile::subProfileNames | ( | const QString & | aType = "" | ) | const

Gets the names of all sub-profiles with the given type.

Parameters

  aType | Type of sub-profiles to get. If this is empty, all sub-profile names are returned.

Returns
  Names of the sub-profiles.

## toString()

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.

Returns
  Generated XML string.

## toXml()

QDomElement Profile::toXml | ( | QDomDocument & | aDoc,
|  | bool | aLocalOnly = true ) const

virtual

Creates a XML representation of the profile.

Parameters

  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.

Returns
  Generated XML node tree.

Reimplemented in Buteo::SyncProfile.

## type()

QString Profile::type | ( |  | ) | const

Gets the type of the profile.

Returns
  Profile type.

## visibleFields()

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.

Returns
  List of pointers to the visible fields.

## Member Data Documentation

## TYPE_SYNC

const QString Profile::TYPE_SYNC

static

Service type.

Sync type

The documentation for this class was generated from the following files:

- Profile.h
- Profile.cpp