Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

QY2Settings Class Reference

#include <QY2Settings.h>

List of all members.

Public Types

enum  AccessMode { ReadOnly, ReadWrite, WriteOnly }

Public Member Functions

 QY2Settings (const QString &fileName, AccessMode accessMode=ReadOnly)
 ~QY2Settings ()
bool readError () const
bool readOk () const
bool selectSection (const QString &section)
void selectDefaultSection ()
QString currentSection () const
QStringList sections (bool includeUnnamed=false) const
QString get (const QString &key, const QString &fallback="") const
QString operator[] (const QString &key)
bool hasKey (const QString &key)
QStringList keys () const
void set (const QString &key, const QString &value)
void addSection (const QString &section)
void clearSection ()
bool save ()
bool pendingChanges () const
QString fileName () const
AccessMode accessMode () const

Protected Types

typedef QDictIterator< SectionSectionIterator

Protected Member Functions

void initSections ()
bool load ()
void saveSection (QTextStream &stream, Section *section)

Protected Attributes

QString _fileName
AccessMode _accessMode
bool _readError
QString _currentSectionName
Section_currentSection
bool _dirty
Section_defaultSection
QDict< Section_sections

Classes

class  Section


Detailed Description

Utility class that handles program settings in .ini file format:

key="value" key2 = value ; comment # comment

[section-title] key = "value" ; comment key2="value" key3 = _( "message that needs to be translated" )

[section-title2] key="value" key2="value"

key=value pairs appear one on a line each. Leading and trailing whitespace is disregarded around both key and value. Value should be quoted (but doesn't need to). Quotes in value are escaped with \".


Member Typedef Documentation

typedef QDictIterator<Section> QY2Settings::SectionIterator [protected]
 


Member Enumeration Documentation

enum QY2Settings::AccessMode
 

Enumerator:
ReadOnly 
ReadWrite 
WriteOnly 


Constructor & Destructor Documentation

QY2Settings::QY2Settings const QString &  fileName,
AccessMode  accessMode = ReadOnly
 

Constructor. Reads settings from the specified file.

Use readError() or readOk() afterwards to check for read errors.

QY2Settings::~QY2Settings  ) 
 

Destructor.

Writes any pending changes back to the file if there are any left if accessMode() is ReadWrite or WriteOnly.


Member Function Documentation

AccessMode QY2Settings::accessMode  )  const [inline]
 

Returns the access mode - one of ReadOnly, ReadWrite, WriteOnly.

void QY2Settings::addSection const QString &  section  ) 
 

Add a section with the specified name. If a section with that name already exists, it will only be selected and its old contents will remain untouched. In any case, this section becomes the current section.

void QY2Settings::clearSection  ) 
 

Clear all key=value pairs from the current section.

QString QY2Settings::currentSection  )  const [inline]
 

Returns the name of the current section or QString::null if the default section is used.

QString QY2Settings::fileName  )  const [inline]
 

Returns the file name.

QString QY2Settings::get const QString &  key,
const QString &  fallback = ""
const
 

Returns the value for the specified key in the current section. If there is no such key, the specified fallback value is returned.

bool QY2Settings::hasKey const QString &  key  ) 
 

Checks if the current section has the specified key.

void QY2Settings::initSections  )  [protected]
 

Initialize the section data

QStringList QY2Settings::keys  )  const
 

Returns a list of all keys in the current section. The list sort order is undefined.

bool QY2Settings::load  )  [protected]
 

Read the settings file. Sets _readError depending on success or failure. Returns 'true' upon success.

QString QY2Settings::operator[] const QString &  key  ) 
 

Same as get() with fallback always an empty string

bool QY2Settings::pendingChanges  )  const [inline]
 

Returns 'true' if there are any changes that need to be written.

Always returns 'false' if accessMode() is ReadOnly.

bool QY2Settings::readError  )  const [inline]
 

Returns 'true' if the settings couldn't be read from the file specified in the constructor.

bool QY2Settings::readOk  )  const [inline]
 

Returns 'true' if the settings were read without problems from the file specified in the constructor. This is simply the opposite of readError().

bool QY2Settings::save  ) 
 

Writes changed settings back to the file specified in the constructor if accessMode() is ReadWrite or WriteOnly.

Returns 'true' on success.

void QY2Settings::saveSection QTextStream &  stream,
Section section
[protected]
 

Save one section to a stream

QStringList QY2Settings::sections bool  includeUnnamed = false  )  const
 

Returns a list of all sections. 'includeUnnamed' specifies if the unnamed default section should be included in the list. The list sort order is undefined.

void QY2Settings::selectDefaultSection  ) 
 

Select the default (unnamed) section for subsequent get() calls. This is the default unless selectSection() was called.

bool QY2Settings::selectSection const QString &  section  ) 
 

Select the specified section in the settings for subsequent get() calls. Until is used, the unnamed default section is used.

In the settings file, a section is marked with

[section-title]

Using a null string (QString::null) switches back to the unnamed default section.

Returns 'true' upon success, 'false' if there is no such section (in which case the unnamed default section will be selected).

void QY2Settings::set const QString &  key,
const QString &  value
 

Set the specified key to the specified value. Overwrites any existing key-value pair or adds a new one if there is no such key yet.


Member Data Documentation

AccessMode QY2Settings::_accessMode [protected]
 

Section* QY2Settings::_currentSection [protected]
 

QString QY2Settings::_currentSectionName [protected]
 

Section* QY2Settings::_defaultSection [protected]
 

bool QY2Settings::_dirty [protected]
 

QString QY2Settings::_fileName [protected]
 

bool QY2Settings::_readError [protected]
 

QDict<Section> QY2Settings::_sections [protected]
 


The documentation for this class was generated from the following files:
Generated on Wed Sep 14 10:59:03 2005 for yast2-qt by  doxygen 1.4.4