Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Young committed Jan 20, 2023
1 parent e92a594 commit bb22a3a
Show file tree
Hide file tree
Showing 27 changed files with 473 additions and 73 deletions.
5 changes: 3 additions & 2 deletions src/OptionDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@ class OptionDialog::impl {
* Determine which set of DB config params to show, based on whether PostgresSQL or SQLite is selected
*/
void setDbDialog(OptionDialog & optionDialog, Database::DbType db) {
qDebug() << Q_FUNC_INFO << "Set " << (db == Database::PGSQL ? "PostgresSQL" : "SQLite") << " config params visible";
qDebug() <<
Q_FUNC_INFO << "Set " << (db == Database::DbType::PGSQL ? "PostgresSQL" : "SQLite") << " config params visible";
optionDialog.groupBox_dbConfig->setVisible(false);

this->clearLayout(optionDialog);
Expand Down Expand Up @@ -792,7 +793,7 @@ void OptionDialog::changeEvent(QEvent * e) {
return;
}

void OptionDialog::setEngine(int selected) {
void OptionDialog::setEngine([[maybe_unused]] int selected) {

QVariant data = comboBox_engine->currentData();
Database::DbType newEngine = static_cast<Database::DbType>(data.toInt());
Expand Down
27 changes: 21 additions & 6 deletions src/PersistentSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
#include <QSettings>
#include <QStandardPaths>

#include "config.h"

//
// Anonymous namespace for constants, global variables and functions used only in this file
//
Expand Down Expand Up @@ -81,9 +83,9 @@ namespace {

//
// By default, QSettings stores things differently on different platforms (registry on Windows, CFPreferences API on
// Mac, a text .conf file on Linux). We prefer to force use of a text file on all platforms as potentially aids
// debugging (eg it's relatively then easy for an end user raising a bug report to upload a text config file, but it
// might be somewhat harder for them to dig around in the Windows registry).
// Mac, a text .conf file on Linux). HOWEVER, we prefer to force use of a text file on all platforms as potentially
// aids debugging (eg it's relatively then easy for an end user raising a bug report to upload a text config file,
// but it might be somewhat harder for them to dig around in the Windows registry).
//
// For similar reasons, we would like to control the location and name of the file.
//
Expand Down Expand Up @@ -116,7 +118,7 @@ void PersistentSettings::initialise(QString customUserDataDir) {
// we don't just use static initialisation.
//
// Yes, we are knowingly logging before Logging::initializeLogging() has been called (as the latter needs
// PersistentSettings::initialise() to be called first. This is OK as it just means the log message will go to the
// PersistentSettings::initialise() to be called first). This is OK as it just means the log message will go to the
// default Qt-0determined location (eg stderr on Linux).
//
// The value in this logging is that we have seen instances where the software is unable to determine a value for
Expand All @@ -130,9 +132,22 @@ void PersistentSettings::initialise(QString customUserDataDir) {
Q_FUNC_INFO << "Preferred writeable directory for user-specific configuration files is:" <<
configDir.absolutePath();

// Older versions of the software had a different, less descriptive, name for the .conf file. If the old file is
// present but the new one is not, we rename it.
QString const oldConfigFileName = QString("%1.conf").arg(CONFIG_APPLICATION_NAME_LC);
QString const newConfigFileName = QString("%1PersistentSettings.conf").arg(CONFIG_APPLICATION_NAME_LC);
if (configDir.exists(oldConfigFileName) && !configDir.exists(newConfigFileName)) {
qInfo() << Q_FUNC_INFO << "Renaming" << oldConfigFileName << "to" << newConfigFileName << "in" << configDir;
if (!configDir.rename(oldConfigFileName, newConfigFileName)) {
// QDir::rename will tell you if it failed, but not why, so we just log the failure
qWarning() <<
Q_FUNC_INFO << "Error renaming" << oldConfigFileName << "to" << newConfigFileName << "in" << configDir;
}
}

// Now we can set the full path of the persistent settings file
qSettings = std::make_unique<QSettings>(configDir.absoluteFilePath("brewtargetPersistentSettings.conf"),
QSettings::IniFormat);
qSettings = std::make_unique<QSettings>(configDir.absoluteFilePath(newConfigFileName), QSettings::IniFormat);
qInfo() << Q_FUNC_INFO << "Persistent settings file:" << qSettings->fileName();

// We've done enough now for calls to contains()/insert()/value() etc to work. Mark that we're initialised so we
// can (potentially) use one of those calls to initialise the user data directory.
Expand Down
Loading

0 comments on commit bb22a3a

Please sign in to comment.