Reformat and (slightly) decruft all the things.

This commit is contained in:
Petr Mrázek
2013-11-04 02:53:05 +01:00
parent d6e4fb2971
commit bb7e8985f6
208 changed files with 4492 additions and 3767 deletions

View File

@ -3,7 +3,7 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@ -16,17 +16,15 @@
#include "include/basicsettingsobject.h"
#include "include/setting.h"
BasicSettingsObject::BasicSettingsObject(QObject *parent) :
SettingsObject(parent)
BasicSettingsObject::BasicSettingsObject(QObject *parent) : SettingsObject(parent)
{
}
void BasicSettingsObject::changeSetting(const Setting &setting, QVariant value)
{
if (contains(setting.id()))
{
if(value.isValid())
if (value.isValid())
config.setValue(setting.configKey(), value);
else
config.remove(setting.configKey());

View File

@ -3,7 +3,7 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@ -19,10 +19,8 @@
#include <QTextStream>
#include <QStringList>
INIFile::INIFile()
{
}
QString INIFile::unescape(QString orig)
@ -47,50 +45,50 @@ bool INIFile::saveFile(QString fileName)
file.open(QIODevice::WriteOnly);
QTextStream out(&file);
out.setCodec("UTF-8");
for (Iterator iter = begin(); iter != end(); iter++)
{
QString value = iter.value().toString();
value = escape(value);
out << iter.key() << "=" << value << "\n";
}
return true;
}
bool INIFile::loadFile(QString fileName)
{
QFile file(fileName);
if(!file.open(QIODevice::ReadOnly))
if (!file.open(QIODevice::ReadOnly))
return false;
bool success = loadFile(file.readAll());
file.close();
return success;
}
bool INIFile::loadFile( QByteArray file )
bool INIFile::loadFile(QByteArray file)
{
QTextStream in(file);
in.setCodec("UTF-8");
QStringList lines = in.readAll().split('\n');
for (int i = 0; i < lines.count(); i++)
{
QString & lineRaw = lines[i];
QString &lineRaw = lines[i];
// Ignore comments.
QString line = lineRaw.left(lineRaw.indexOf('#')).trimmed();
int eqPos = line.indexOf('=');
if(eqPos == -1)
if (eqPos == -1)
continue;
QString key = line.left(eqPos).trimmed();
QString valueStr = line.right(line.length() - eqPos - 1).trimmed();
valueStr = unescape(valueStr);
QVariant value(valueStr);
this->operator [](key) = value;
this->operator[](key) = value;
}
return true;
}
@ -99,10 +97,10 @@ QVariant INIFile::get(QString key, QVariant def) const
if (!this->contains(key))
return def;
else
return this->operator [](key);
return this->operator[](key);
}
void INIFile::set(QString key, QVariant val)
{
this->operator [](key) = val;
this->operator[](key) = val;
}

View File

@ -3,7 +3,7 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@ -16,8 +16,8 @@
#include "include/inisettingsobject.h"
#include "include/setting.h"
INISettingsObject::INISettingsObject(const QString &path, QObject *parent) :
SettingsObject(parent)
INISettingsObject::INISettingsObject(const QString &path, QObject *parent)
: SettingsObject(parent)
{
m_filePath = path;
m_ini.loadFile(path);
@ -32,7 +32,7 @@ void INISettingsObject::changeSetting(const Setting &setting, QVariant value)
{
if (contains(setting.id()))
{
if(value.isValid())
if (value.isValid())
m_ini.set(setting.configKey(), value);
else
m_ini.remove(setting.configKey());
@ -40,7 +40,7 @@ void INISettingsObject::changeSetting(const Setting &setting, QVariant value)
}
}
void INISettingsObject::resetSetting ( const Setting& setting )
void INISettingsObject::resetSetting(const Setting &setting)
{
if (contains(setting.id()))
{

View File

@ -3,7 +3,7 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@ -15,8 +15,8 @@
#include "include/overridesetting.h"
OverrideSetting::OverrideSetting(const QString &name, Setting *other, QObject *parent) :
Setting(name, QVariant(), parent)
OverrideSetting::OverrideSetting(const QString &name, Setting *other, QObject *parent)
: Setting(name, QVariant(), parent)
{
m_other = other;
}

View File

@ -3,7 +3,7 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@ -16,10 +16,9 @@
#include "include/setting.h"
#include "include/settingsobject.h"
Setting::Setting(QString id, QVariant defVal, QObject *parent) :
QObject(parent), m_id(id), m_defVal(defVal)
Setting::Setting(QString id, QVariant defVal, QObject *parent)
: QObject(parent), m_id(id), m_defVal(defVal)
{
}
QVariant Setting::get() const
@ -32,7 +31,7 @@ QVariant Setting::get() const
else
{
QVariant test = sbase->retrieveValue(*this);
if(!test.isValid())
if (!test.isValid())
return defValue();
return test;
}

View File

@ -3,7 +3,7 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@ -18,10 +18,8 @@
#include <QVariant>
SettingsObject::SettingsObject(QObject *parent) :
QObject(parent)
SettingsObject::SettingsObject(QObject *parent) : QObject(parent)
{
}
bool SettingsObject::registerSetting(Setting *setting)
@ -29,24 +27,26 @@ bool SettingsObject::registerSetting(Setting *setting)
// Check if setting is null or we already have a setting with the same ID.
if (!setting)
{
qDebug(QString("Failed to register setting. Setting is null.").
arg(setting->id()).toUtf8());
qDebug(QString("Failed to register setting. Setting is null.")
.arg(setting->id())
.toUtf8());
return false; // Fail
}
if (contains(setting->id()))
{
qDebug(QString("Failed to register setting %1. ID already exists.").
arg(setting->id()).toUtf8());
qDebug(QString("Failed to register setting %1. ID already exists.")
.arg(setting->id())
.toUtf8());
return false; // Fail
}
m_settings.insert(setting->id(), setting);
setting->setParent(this); // Take ownership.
// Connect signals.
connectSignals(*setting);
// qDebug(QString("Registered setting %1.").arg(setting->id()).toUtf8());
return true;
}
@ -55,22 +55,21 @@ void SettingsObject::unregisterSetting(Setting *setting)
{
if (!setting || !m_settings.contains(setting->id()))
return; // We can't unregister something that's not registered.
m_settings.remove(setting->id());
// Disconnect signals.
disconnectSignals(*setting);
setting->setParent(NULL); // Drop ownership.
}
Setting *SettingsObject::getSetting(const QString &id) const
{
// Make sure there is a setting with the given ID.
if (!m_settings.contains(id))
return NULL;
return m_settings[id];
}
@ -85,8 +84,7 @@ bool SettingsObject::set(const QString &id, QVariant value)
Setting *setting = getSetting(id);
if (!setting)
{
qDebug(QString("Error changing setting %1. Setting doesn't exist.").
arg(id).toUtf8());
qDebug(QString("Error changing setting %1. Setting doesn't exist.").arg(id).toUtf8());
return false;
}
else
@ -99,11 +97,10 @@ bool SettingsObject::set(const QString &id, QVariant value)
void SettingsObject::reset(const QString &id) const
{
Setting *setting = getSetting(id);
if(setting)
if (setting)
setting->reset();
}
QList<Setting *> SettingsObject::getSettings()
{
return m_settings.values();
@ -114,29 +111,26 @@ bool SettingsObject::contains(const QString &id)
return m_settings.contains(id);
}
void SettingsObject::connectSignals(const Setting &setting)
{
connect(&setting, SIGNAL(settingChanged(const Setting &, QVariant)),
SLOT(changeSetting(const Setting &, QVariant)));
connect(&setting, SIGNAL(settingChanged(const Setting &, QVariant)),
SIGNAL(settingChanged(const Setting &, QVariant)));
connect(&setting, SIGNAL(settingReset(Setting)),
SLOT(resetSetting(const Setting &)));
connect(&setting, SIGNAL(settingReset(Setting)),
SIGNAL(settingReset(const Setting &)));
connect(&setting, SIGNAL(settingReset(Setting)), SLOT(resetSetting(const Setting &)));
connect(&setting, SIGNAL(settingReset(Setting)), SIGNAL(settingReset(const Setting &)));
}
void SettingsObject::disconnectSignals(const Setting &setting)
{
setting.disconnect(SIGNAL(settingChanged(const Setting &, QVariant)),
this, SLOT(changeSetting(const Setting &, QVariant)));
setting.disconnect(SIGNAL(settingChanged(const Setting &, QVariant)),
this, SIGNAL(settingChanged(const Setting &, QVariant)));
setting.disconnect(SIGNAL(settingReset(const Setting &, QVariant)),
this, SLOT(resetSetting(const Setting &, QVariant)));
setting.disconnect(SIGNAL(settingReset(const Setting &, QVariant)),
this, SIGNAL(settingReset(const Setting &, QVariant)));
setting.disconnect(SIGNAL(settingChanged(const Setting &, QVariant)), this,
SLOT(changeSetting(const Setting &, QVariant)));
setting.disconnect(SIGNAL(settingChanged(const Setting &, QVariant)), this,
SIGNAL(settingChanged(const Setting &, QVariant)));
setting.disconnect(SIGNAL(settingReset(const Setting &, QVariant)), this,
SLOT(resetSetting(const Setting &, QVariant)));
setting.disconnect(SIGNAL(settingReset(const Setting &, QVariant)), this,
SIGNAL(settingReset(const Setting &, QVariant)));
}

View File

@ -27,7 +27,7 @@ QString scramble(QString in_)
{
QByteArray in = in_.toUtf8();
QByteArray out;
for (int i = 0; i<in.length(); i++)
for (int i = 0; i < in.length(); i++)
out.append(in.at(i) ^ scrambler);
return QString::fromUtf8(out);
}
@ -81,7 +81,7 @@ QStringList StubKeyring::getStoredAccounts(QString service)
QStringList out;
QStringList in(m_settings.allKeys());
QStringListIterator it(in);
while(it.hasNext())
while (it.hasNext())
{
QString c = it.next();
if (c.startsWith(service))
@ -90,15 +90,16 @@ QStringList StubKeyring::getStoredAccounts(QString service)
return out;
}
void StubKeyring::removeStoredAccount ( QString service, QString username )
void StubKeyring::removeStoredAccount(QString service, QString username)
{
QString key = generateKey(service, username);
m_settings.remove(key);
}
//FIXME: this needs tweaking/changes for user account level storage
StubKeyring::StubKeyring() :
// m_settings(QSettings::UserScope, "Orochimarufan", "Keyring")
m_settings("keyring.cfg", QSettings::IniFormat)
// FIXME: this needs tweaking/changes for user account level storage
StubKeyring::StubKeyring()
:
// m_settings(QSettings::UserScope, "Orochimarufan", "Keyring")
m_settings("keyring.cfg", QSettings::IniFormat)
{
}

View File

@ -15,8 +15,7 @@
* limitations under the License.
*/
#ifndef STUBKEYRING_H
#define STUBKEYRING_H
#pragma once
#include "include/keyring.h"
@ -30,12 +29,14 @@ public:
virtual bool hasPassword(QString service, QString username);
virtual QStringList getStoredAccounts(QString service);
virtual void removeStoredAccount(QString service, QString username);
private:
friend class Keyring;
explicit StubKeyring();
virtual bool isValid() { return true; }
virtual bool isValid()
{
return true;
}
QSettings m_settings;
};
#endif // STUBKEYRING_H