qTox  Version: nightly | Commit: bc751c8e1cac455f9690654fcfe0f560d2d7dfdd
Classes | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
SettingsSerializer Class Reference

Serializes a QSettings's data in an (optionally) encrypted binary format. SettingsSerializer can detect regular .ini files and serialized ones, it will read both regular and serialized .ini, but only save in serialized format. The file is encrypted with the current profile's password, if any. The file is only written to disk if save() is called, the destructor does not save to disk All member functions are reentrant, but not thread safe. More...

#include <settingsserializer.h>

Collaboration diagram for SettingsSerializer:
Collaboration graph

Classes

struct  Array
 
struct  Value
 

Public Member Functions

 SettingsSerializer (QString filePath, const ToxEncrypt *passKey=nullptr)
 
void load ()
 Loads the settings from file. More...
 
void save ()
 Saves the current settings back to file. More...
 
void beginGroup (const QString &prefix)
 
void endGroup ()
 
int beginReadArray (const QString &prefix)
 
void beginWriteArray (const QString &prefix, int size=-1)
 
void endArray ()
 
void setArrayIndex (int i)
 
void setValue (const QString &key, const QVariant &value)
 
QVariant value (const QString &key, const QVariant &defaultValue=QVariant()) const
 

Static Public Member Functions

static bool isSerializedFormat (QString filePath)
 Checks if the file is serialized settings. More...
 

Private Types

enum  RecordTag : uint8_t {
  RecordTag::Value = 0, RecordTag::GroupStart = 1, RecordTag::ArrayStart = 2, RecordTag::ArrayValue = 3,
  RecordTag::ArrayEnd = 4
}
 

Private Member Functions

const ValuefindValue (const QString &key) const
 
ValuefindValue (const QString &key)
 
void readSerialized ()
 
void readIni ()
 
void removeValue (const QString &key)
 
void removeGroup (int group)
 Remove group. More...
 
void writePackedVariant (QDataStream &dataStream, const QVariant &v)
 

Private Attributes

QString path
 
const ToxEncryptpassKey
 
int group
 
int array
 
int arrayIndex
 
QStringList groups
 
QVector< Arrayarrays
 
QVector< Valuevalues
 

Static Private Attributes

static const char magic [] = {0x51, 0x54, 0x4F, 0x58}
 

Friends

QDataStream & writeStream (QDataStream &dataStream, const SettingsSerializer::RecordTag &tag)
 
QDataStream & readStream (QDataStream &dataStream, SettingsSerializer::RecordTag &tag)
 

Detailed Description

Serializes a QSettings's data in an (optionally) encrypted binary format. SettingsSerializer can detect regular .ini files and serialized ones, it will read both regular and serialized .ini, but only save in serialized format. The file is encrypted with the current profile's password, if any. The file is only written to disk if save() is called, the destructor does not save to disk All member functions are reentrant, but not thread safe.

Definition at line 29 of file settingsserializer.h.

Member Enumeration Documentation

◆ RecordTag

enum SettingsSerializer::RecordTag : uint8_t
strongprivate
Enumerator
Value 
GroupStart 
ArrayStart 
ArrayValue 
ArrayEnd 

Definition at line 51 of file settingsserializer.h.

Constructor & Destructor Documentation

◆ SettingsSerializer()

SettingsSerializer::SettingsSerializer ( QString  filePath,
const ToxEncrypt passKey = nullptr 
)

Definition at line 102 of file settingsserializer.cpp.

Member Function Documentation

◆ beginGroup()

void SettingsSerializer::beginGroup ( const QString &  prefix)

Definition at line 111 of file settingsserializer.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ beginReadArray()

int SettingsSerializer::beginReadArray ( const QString &  prefix)

Definition at line 129 of file settingsserializer.cpp.

Here is the caller graph for this function:

◆ beginWriteArray()

void SettingsSerializer::beginWriteArray ( const QString &  prefix,
int  size = -1 
)

Definition at line 146 of file settingsserializer.cpp.

Here is the caller graph for this function:

◆ endArray()

void SettingsSerializer::endArray ( )

Definition at line 165 of file settingsserializer.cpp.

Here is the caller graph for this function:

◆ endGroup()

void SettingsSerializer::endGroup ( )

Definition at line 124 of file settingsserializer.cpp.

Here is the caller graph for this function:

◆ findValue() [1/2]

SettingsSerializer::Value * SettingsSerializer::findValue ( const QString &  key)
private

Definition at line 218 of file settingsserializer.cpp.

Here is the call graph for this function:

◆ findValue() [2/2]

const SettingsSerializer::Value * SettingsSerializer::findValue ( const QString &  key) const
private

Definition at line 197 of file settingsserializer.cpp.

Here is the caller graph for this function:

◆ isSerializedFormat()

bool SettingsSerializer::isSerializedFormat ( QString  filePath)
static

Checks if the file is serialized settings.

Parameters
filePathPath to file to check.
Returns
False on error, true otherwise.

Definition at line 228 of file settingsserializer.cpp.

Here is the caller graph for this function:

◆ load()

void SettingsSerializer::load ( )

Loads the settings from file.

Definition at line 242 of file settingsserializer.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ readIni()

void SettingsSerializer::readIni ( )
private

Definition at line 402 of file settingsserializer.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ readSerialized()

void SettingsSerializer::readSerialized ( )
private

Definition at line 320 of file settingsserializer.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeGroup()

void SettingsSerializer::removeGroup ( int  group)
private

Remove group.

Note
The group must be empty.
Parameters
groupID of group to remove.

Definition at line 536 of file settingsserializer.cpp.

Here is the caller graph for this function:

◆ removeValue()

void SettingsSerializer::removeValue ( const QString &  key)
private

◆ save()

void SettingsSerializer::save ( )

Saves the current settings back to file.

Definition at line 253 of file settingsserializer.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setArrayIndex()

void SettingsSerializer::setArrayIndex ( int  i)

Definition at line 170 of file settingsserializer.cpp.

Here is the caller graph for this function:

◆ setValue()

void SettingsSerializer::setValue ( const QString &  key,
const QVariant &  value 
)

Definition at line 175 of file settingsserializer.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ value()

QVariant SettingsSerializer::value ( const QString &  key,
const QVariant &  defaultValue = QVariant() 
) const

Definition at line 188 of file settingsserializer.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ writePackedVariant()

void SettingsSerializer::writePackedVariant ( QDataStream &  dataStream,
const QVariant &  v 
)
private

Definition at line 552 of file settingsserializer.cpp.

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ readStream

QDataStream& readStream ( QDataStream &  dataStream,
SettingsSerializer::RecordTag tag 
)
friend

Definition at line 81 of file settingsserializer.cpp.

◆ writeStream

QDataStream& writeStream ( QDataStream &  dataStream,
const SettingsSerializer::RecordTag tag 
)
friend

Definition at line 63 of file settingsserializer.cpp.

Member Data Documentation

◆ array

int SettingsSerializer::array
private

Definition at line 107 of file settingsserializer.h.

◆ arrayIndex

int SettingsSerializer::arrayIndex
private

Definition at line 107 of file settingsserializer.h.

◆ arrays

QVector<Array> SettingsSerializer::arrays
private

Definition at line 109 of file settingsserializer.h.

◆ group

int SettingsSerializer::group
private

Definition at line 107 of file settingsserializer.h.

◆ groups

QStringList SettingsSerializer::groups
private

Definition at line 108 of file settingsserializer.h.

◆ magic

const char SettingsSerializer::magic = {0x51, 0x54, 0x4F, 0x58}
staticprivate

Definition at line 111 of file settingsserializer.h.

◆ passKey

const ToxEncrypt* SettingsSerializer::passKey
private

Definition at line 106 of file settingsserializer.h.

◆ path

QString SettingsSerializer::path
private

Definition at line 105 of file settingsserializer.h.

◆ values

QVector<Value> SettingsSerializer::values
private

Definition at line 110 of file settingsserializer.h.


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