Removed unneeded code from setting manager. Moved some code to user

settings
openmw-30
graffy76 11 years ago
parent 74fa115d20
commit 5cba828cc9

@ -10,17 +10,7 @@
CSMSettings::SettingManager::SettingManager(QObject *parent) :
QObject(parent)
{
mReadWriteMessage = QObject::tr("<br><b>Could not open or create file for \
writing</b><br><br> Please make sure you have the right\
permissions and try again.<br>");
mReadOnlyMessage = QObject::tr("<br><b>Could not open file for \
reading</b><br><br> Please make sure you have the \
right permissions and try again.<br>");
}
{}
CSMSettings::Setting *CSMSettings::SettingManager::createSetting
(CSMSettings::SettingType typ, const QString &page, const QString &name)
@ -42,23 +32,6 @@ CSMSettings::Setting *CSMSettings::SettingManager::createSetting
return setting;
}
void CSMSettings::SettingManager::displayFileErrorMessage(const QString &message,
bool isReadOnly) const
{
// File cannot be opened or created
QMessageBox msgBox;
msgBox.setWindowTitle(QObject::tr("OpenCS configuration file I/O error"));
msgBox.setIcon(QMessageBox::Critical);
msgBox.setStandardButtons(QMessageBox::Ok);
if (!isReadOnly)
msgBox.setText (mReadWriteMessage + message);
else
msgBox.setText (message);
msgBox.exec();
}
void CSMSettings::SettingManager::addDefinitions (const QSettings *settings)
{
foreach (const QString &key, settings->allKeys())
@ -80,35 +53,9 @@ void CSMSettings::SettingManager::addDefinitions (const QSettings *settings)
values.append (setting->defaultValues());
setting->setDefinedValues (values);
qDebug() << "added definitons " << values;
}
}
QList <CSMSettings::Setting *> CSMSettings::SettingManager::findSettings
(const QStringList &list)
{
QList <CSMSettings::Setting *> settings;
foreach (const QString &value, list)
{
QStringList names = value.split(".", QString::SkipEmptyParts);
if (names.size() != 2)
continue;
Setting *setting = findSetting (names.at(0), names.at(1));
if (!setting)
continue;
settings.append (setting);
}
return settings;
}
CSMSettings::Setting *CSMSettings::SettingManager::findSetting
(const QString &pageName, const QString &settingName)
{
@ -123,19 +70,6 @@ CSMSettings::Setting *CSMSettings::SettingManager::findSetting
return 0;
}
QList <CSMSettings::Setting *> CSMSettings::SettingManager::findSettings
(const QString &pageName)
{
QList <CSMSettings::Setting *> settings;
foreach (Setting *setting, mSettings)
{
if (setting->page() == pageName)
settings.append (setting);
}
return settings;
}
CSMSettings::SettingPageMap CSMSettings::SettingManager::settingPageMap() const
{
SettingPageMap pageMap;

@ -22,8 +22,6 @@ namespace CSMSettings
{
Q_OBJECT
QString mReadOnlyMessage;
QString mReadWriteMessage;
QList <Setting *> mSettings;
public:
@ -33,13 +31,6 @@ namespace CSMSettings
Setting *findSetting
(const QString &pageName, const QString &settingName = QString());
///retrieve all settings for a specified page
QList <Setting *> findSettings (const QString &pageName);
///retrieve all settings named in the attached list.
///Setting names are specified in "PageName.SettingName" format.
QList <Setting *> findSettings (const QStringList &list);
///Retreive a map of the settings, keyed by page name
SettingPageMap settingPageMap() const;
@ -52,11 +43,6 @@ namespace CSMSettings
///add definitions to the settings specified in the page map
void addDefinitions (const QSettings *settings);
void displayFileErrorMessage(const QString &message,
bool isReadOnly) const;
QList <Setting *> settings() const { return mSettings; }
signals:
void userSettingUpdated (const QString &, const QStringList &);

@ -44,6 +44,14 @@ CSMSettings::UserSettings::UserSettings()
mSettings = 0;
mReadWriteMessage = QObject::tr("<br><b>Could not open or create file for \
writing</b><br><br> Please make sure you have the right\
permissions and try again.<br>");
mReadOnlyMessage = QObject::tr("<br><b>Could not open file for \
reading</b><br><br> Please make sure you have the \
right permissions and try again.<br>");
buildSettingModelDefaults();
}
@ -131,10 +139,10 @@ void CSMSettings::UserSettings::buildSettingModelDefaults()
* proxy slave settings, but must match any declared values the proxy
* slave has, if any.
*******************************************************************/
/*
//create setting objects, specifying the basic widget type,
//the page name, and the view name
/*
Setting *masterBoolean = createSetting (Type_RadioButton, section,
"Master Proxy");
@ -234,6 +242,7 @@ void CSMSettings::UserSettings::buildSettingModelDefaults()
slaveIntegerSpinbox->setSerializable (false);
slaveDoubleSpinbox->setSerializable (false);
slaveSlider->setSerializable (false);
slaveDial->setSerializable (false);
slaveBoolean->setDefaultValues (QStringList()
<< "One" << "Three" << "Five");
@ -285,9 +294,34 @@ CSMSettings::UserSettings::~UserSettings()
mUserSettingsInstance = 0;
}
void CSMSettings::UserSettings::displayFileErrorMessage
(const QString &userpath,
const QString &globalpath,
const QString &localpath) const
{
QString message = QObject::tr("<br><b>An error was encountered loading \
user settings files.</b><br><br> One or several files could not \
be read. This may be caused by a missing configuration file, \
incorrect file permissions or a corrupted installation of \
OpenCS.<br>");
message += QObject::tr("<br>Global filepath: ") + globalpath;
message += QObject::tr("<br>Local filepath: ") + localpath;
message += QObject::tr("<br>User filepath: ") + userpath;
QMessageBox msgBox;
msgBox.setWindowTitle(QObject::tr("OpenCS configuration file I/O error"));
msgBox.setIcon(QMessageBox::Critical);
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setText (mReadWriteMessage + message);
msgBox.exec();
}
void CSMSettings::UserSettings::loadSettings (const QString &fileName)
{
mUserFilePath = QString::fromUtf8
QString userFilePath = QString::fromUtf8
(mCfgMgr.getUserConfigPath().string().c_str());
QString globalFilePath = QString::fromUtf8
@ -296,7 +330,7 @@ void CSMSettings::UserSettings::loadSettings (const QString &fileName)
QString localFilePath = QString::fromUtf8
(mCfgMgr.getLocalPath().string().c_str());
bool isUser = QFile (mUserFilePath + fileName).exists();
bool isUser = QFile (userFilePath + fileName).exists();
bool isSystem = QFile (globalFilePath + fileName).exists();
QString otherFilePath = globalFilePath;
@ -311,22 +345,12 @@ void CSMSettings::UserSettings::loadSettings (const QString &fileName)
//error condition - notify and return
if (!isUser || !isSystem)
{
QString message = QObject::tr("<br><b>An error was encountered loading \
user settings files.</b><br><br> One or several files could not \
be read. This may be caused by a missing configuration file, \
incorrect file permissions or a corrupted installation of \
OpenCS.<br>");
message += QObject::tr("<br>Global filepath: ") + globalFilePath;
message += QObject::tr("<br>Local filepath: ") + localFilePath;
message += QObject::tr("<br>User filepath: ") + mUserFilePath;
displayFileErrorMessage ( message, true);
displayFileErrorMessage (userFilePath, globalFilePath, localFilePath);
return;
}
QSettings::setPath
(QSettings::IniFormat, QSettings::UserScope, mUserFilePath);
(QSettings::IniFormat, QSettings::UserScope, userFilePath);
QSettings::setPath
(QSettings::IniFormat, QSettings::SystemScope, otherFilePath);

@ -28,14 +28,12 @@ namespace CSMSettings {
Q_OBJECT
static UserSettings *mUserSettingsInstance;
QString mUserFilePath;
Files::ConfigurationManager mCfgMgr;
QString mReadOnlyMessage;
QString mReadWriteMessage;
QSettings *mSettings;
public:
/// Singleton implementation
@ -47,9 +45,6 @@ namespace CSMSettings {
UserSettings (UserSettings const &); //not implemented
void operator= (UserSettings const &); //not implemented
/// Writes settings to the last loaded settings file
bool writeSettings();
/// Retrieves the settings file at all three levels (global, local and user).
void loadSettings (const QString &fileName);
@ -61,6 +56,10 @@ namespace CSMSettings {
private:
void buildSettingModelDefaults();
void displayFileErrorMessage(const QString &userpath,
const QString &globalpath,
const QString &localpath) const;
};
}
#endif // USERSETTINGS_HPP

Loading…
Cancel
Save