Skip to content

Commit

Permalink
Refactor Config.
Browse files Browse the repository at this point in the history
Replaces all string configuration options with enum types
that can be checked by the compiler. This prevents spelling
errors, in-place configuration definitions, and inconsistent
default values. The default value config getter signature was
removed in favour of consistently and centrally default-initialised
configuration values.

Individual default values were adjusted for better security,
such as the default password length, which was increased from
16 characters to 32.

The already existing config option deprecation map was extended
by a general migration procedure using configuration versioning.

Settings were split into Roaming and Local settings, which
go to their respective AppData locations on Windows.

Fixes #2574
Fixes #2193
  • Loading branch information
phoerious committed May 1, 2020
1 parent 5add012 commit f23c0ea
Show file tree
Hide file tree
Showing 45 changed files with 1,002 additions and 637 deletions.
10 changes: 5 additions & 5 deletions src/autotype/AutoType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ void AutoType::executeAutoTypeActions(const Entry* entry, QWidget* hideWindow, c
#endif
}

Tools::wait(qMax(100, config()->get("AutoTypeStartDelay", 500).toInt()));
Tools::wait(qMax(100, config()->get(Config::AutoTypeStartDelay).toInt()));

// Used only for selected entry auto-type
if (!window) {
Expand Down Expand Up @@ -339,7 +339,7 @@ void AutoType::performGlobalAutoType(const QList<QSharedPointer<Database>>& dbLi

m_inGlobalAutoTypeDialog.unlock();
emit autotypeRejected();
} else if ((matchList.size() == 1) && !config()->get("security/autotypeask").toBool()) {
} else if ((matchList.size() == 1) && !config()->get(Config::Security_AutoTypeAsk).toBool()) {
executeAutoTypeActions(matchList.first().entry, nullptr, matchList.first().sequence, m_windowForGlobal);
m_inGlobalAutoTypeDialog.unlock();
} else {
Expand Down Expand Up @@ -390,7 +390,7 @@ bool AutoType::parseActions(const QString& actionSequence, const Entry* entry, Q
{
QString tmpl;
bool inTmpl = false;
m_autoTypeDelay = qMax(config()->get("AutoTypeDelay").toInt(), 0);
m_autoTypeDelay = qMax(config()->get(Config::AutoTypeDelay).toInt(), 0);

QString sequence = actionSequence;
sequence.replace("{{}", "{LEFTBRACE}");
Expand Down Expand Up @@ -617,12 +617,12 @@ QList<QString> AutoType::autoTypeSequences(const Entry* entry, const QString& wi
}
}

if (config()->get("AutoTypeEntryTitleMatch").toBool()
if (config()->get(Config::AutoTypeEntryTitleMatch).toBool()
&& windowMatchesTitle(windowTitle, entry->resolvePlaceholder(entry->title()))) {
sequenceList.append(entry->effectiveAutoTypeSequence());
}

if (config()->get("AutoTypeEntryURLMatch").toBool()
if (config()->get(Config::AutoTypeEntryURLMatch).toBool()
&& windowMatchesUrl(windowTitle, entry->resolvePlaceholder(entry->url()))) {
sequenceList.append(entry->effectiveAutoTypeSequence());
}
Expand Down
4 changes: 2 additions & 2 deletions src/autotype/AutoTypeSelectDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ AutoTypeSelectDialog::AutoTypeSelectDialog(QWidget* parent)
#else
QRect screenGeometry = QApplication::desktop()->availableGeometry(QCursor::pos());
#endif
QSize size = config()->get("GUI/AutoTypeSelectDialogSize", QSize(600, 250)).toSize();
QSize size = config()->get(Config::GUI_AutoTypeSelectDialogSize).toSize();
size.setWidth(qMin(size.width(), screenGeometry.width()));
size.setHeight(qMin(size.height(), screenGeometry.height()));
resize(size);
Expand Down Expand Up @@ -111,7 +111,7 @@ void AutoTypeSelectDialog::setMatchList(const QList<AutoTypeMatch>& matchList)

void AutoTypeSelectDialog::done(int r)
{
config()->set("GUI/AutoTypeSelectDialogSize", size());
config()->set(Config::GUI_AutoTypeSelectDialogSize, size());

QDialog::done(r);
}
Expand Down
Loading

0 comments on commit f23c0ea

Please sign in to comment.