From 08891659242891dabba4d5885a2c2aa33ecc5399 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20M=C3=BCller?= Date: Sat, 11 Jun 2022 01:34:18 +0200 Subject: Consolidate wizard enums in single file Makes using the Qt metatype system (with Q_ENUM_NS and Q_NAMESPACE) easier. Both may not be used in multiple files within the same namespace. Even use in children namespaces (A::B) don't work when those macros are used in a parent namespace already. --- src/gui/folderman.h | 2 +- src/gui/newwizard/CMakeLists.txt | 5 +- src/gui/newwizard/enums.cpp | 39 +++++++++++++++ src/gui/newwizard/enums.h | 49 +++++++++++++++++++ src/gui/newwizard/navigation.cpp | 2 +- src/gui/newwizard/navigation.h | 2 +- src/gui/newwizard/setupwizardcontroller.h | 2 +- .../newwizard/states/abstractsetupwizardstate.h | 2 +- src/gui/newwizard/states/setupwizardstate.cpp | 16 ------- src/gui/newwizard/states/setupwizardstate.h | 56 ---------------------- src/gui/newwizard/syncmode.cpp | 16 ------- src/gui/newwizard/syncmode.h | 29 ----------- 12 files changed, 95 insertions(+), 125 deletions(-) create mode 100644 src/gui/newwizard/enums.cpp create mode 100644 src/gui/newwizard/enums.h delete mode 100644 src/gui/newwizard/states/setupwizardstate.cpp delete mode 100644 src/gui/newwizard/states/setupwizardstate.h delete mode 100644 src/gui/newwizard/syncmode.cpp delete mode 100644 src/gui/newwizard/syncmode.h (limited to 'src') diff --git a/src/gui/folderman.h b/src/gui/folderman.h index be9d7311c..9b9e50af5 100644 --- a/src/gui/folderman.h +++ b/src/gui/folderman.h @@ -25,7 +25,7 @@ #include "navigationpanehelper.h" #include "syncfileitem.h" -#include "newwizard/syncmode.h" +#include "newwizard/enums.h" class TestFolderMigration; diff --git a/src/gui/newwizard/CMakeLists.txt b/src/gui/newwizard/CMakeLists.txt index 475561c27..a64395395 100644 --- a/src/gui/newwizard/CMakeLists.txt +++ b/src/gui/newwizard/CMakeLists.txt @@ -1,4 +1,6 @@ add_library(newwizard STATIC + enums.cpp + pages/abstractsetupwizardpage.h pages/abstractsetupwizardpage.cpp @@ -39,9 +41,6 @@ add_library(newwizard STATIC postfixlineedit.cpp - syncmode.cpp - - states/setupwizardstate.cpp states/abstractsetupwizardstate.cpp states/serverurlsetupwizardstate.cpp states/basiccredentialssetupwizardstate.cpp diff --git a/src/gui/newwizard/enums.cpp b/src/gui/newwizard/enums.cpp new file mode 100644 index 000000000..8795887de --- /dev/null +++ b/src/gui/newwizard/enums.cpp @@ -0,0 +1,39 @@ +/* +* Copyright (C) Fabian Müller +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +* for more details. +*/ + +// just a stub so the MOC file can be included somewhere +#include "moc_enums.cpp" + +#include + +using namespace OCC::Wizard; + +namespace { +const char contextC[] = "SetupWizardState"; +} + +template <> +QString OCC::Utility::enumToDisplayName(SetupWizardState state) +{ + switch (state) { + case SetupWizardState::ServerUrlState: + return QApplication::translate(contextC, "Server URL"); + case SetupWizardState::CredentialsState: + return QApplication::translate(contextC, "Credentials"); + case SetupWizardState::AccountConfiguredState: + return QApplication::translate(contextC, "Sync Options"); + default: + Q_UNREACHABLE(); + } +} diff --git a/src/gui/newwizard/enums.h b/src/gui/newwizard/enums.h new file mode 100644 index 000000000..a6995b1b2 --- /dev/null +++ b/src/gui/newwizard/enums.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) Fabian Müller + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#pragma once + +#include "common/utility.h" +#include "enums.h" + +#include + +namespace OCC::Wizard { +Q_NAMESPACE + +enum class SetupWizardState { + ServerUrlState, + FirstState = ServerUrlState, + + CredentialsState, + + AccountConfiguredState, + FinalState = AccountConfiguredState, +}; +Q_ENUM_NS(SetupWizardState) + +enum class SyncMode { + Invalid = 0, + SyncEverything, + ConfigureUsingFolderWizard, + UseVfs, +}; +Q_ENUM_NS(SyncMode) + +} + +namespace OCC { +template <> +QString Utility::enumToDisplayName(Wizard::SetupWizardState state); +} diff --git a/src/gui/newwizard/navigation.cpp b/src/gui/newwizard/navigation.cpp index 0c7cdb1c0..93c3f22b3 100644 --- a/src/gui/newwizard/navigation.cpp +++ b/src/gui/newwizard/navigation.cpp @@ -19,7 +19,7 @@ void Navigation::setEntries(const QList &newEntries) removeAllItems(); for (const auto state : newEntries) { - const QString &text = setupWizardStateToText(state); + const QString text = Utility::enumToDisplayName(state); auto newButton = new QRadioButton(text, this); diff --git a/src/gui/newwizard/navigation.h b/src/gui/newwizard/navigation.h index 13b7911b4..35d7d858e 100644 --- a/src/gui/newwizard/navigation.h +++ b/src/gui/newwizard/navigation.h @@ -14,7 +14,7 @@ #pragma once -#include "states/setupwizardstate.h" +#include "enums.h" #include #include diff --git a/src/gui/newwizard/setupwizardcontroller.h b/src/gui/newwizard/setupwizardcontroller.h index a13ce49ab..de2f397e2 100644 --- a/src/gui/newwizard/setupwizardcontroller.h +++ b/src/gui/newwizard/setupwizardcontroller.h @@ -15,12 +15,12 @@ #pragma once #include "account.h" +#include "enums.h" #include "pages/abstractsetupwizardpage.h" #include "setupwizardaccountbuilder.h" #include "setupwizardcontext.h" #include "setupwizardwindow.h" #include "states/abstractsetupwizardstate.h" -#include "syncmode.h" #include #include diff --git a/src/gui/newwizard/states/abstractsetupwizardstate.h b/src/gui/newwizard/states/abstractsetupwizardstate.h index 2691de3b8..9fd67f354 100644 --- a/src/gui/newwizard/states/abstractsetupwizardstate.h +++ b/src/gui/newwizard/states/abstractsetupwizardstate.h @@ -14,10 +14,10 @@ #pragma once +#include "enums.h" #include "pages/abstractsetupwizardpage.h" #include "setupwizardaccountbuilder.h" #include "setupwizardcontext.h" -#include "setupwizardstate.h" #include "setupwizardwindow.h" namespace OCC::Wizard { diff --git a/src/gui/newwizard/states/setupwizardstate.cpp b/src/gui/newwizard/states/setupwizardstate.cpp deleted file mode 100644 index 0e3bb6505..000000000 --- a/src/gui/newwizard/states/setupwizardstate.cpp +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (C) Fabian Müller - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - */ - -// just a stub so the MOC file can be included somewhere -#include "moc_setupwizardstate.cpp" diff --git a/src/gui/newwizard/states/setupwizardstate.h b/src/gui/newwizard/states/setupwizardstate.h deleted file mode 100644 index 9d4ae00fd..000000000 --- a/src/gui/newwizard/states/setupwizardstate.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) Fabian Müller - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - */ - -#pragma once - -#include - -namespace OCC::Wizard { -Q_NAMESPACE - -/** - * Determines the state the wizard is in. The number of states is equal to the number of pages in the pagination. - * - * Every state may be represented by more than one class. These classes can be used like different "strategies". - * For instance, we have two different credentials state implementations representing different authentication - * methods. - * - * Since we need to decide which states to have at compile time, disabling or hiding optional states must be taken - * care of by the pagination class. All states have to be added here nevertheless. - */ -enum class SetupWizardState { - ServerUrlState, - FirstState = ServerUrlState, - - CredentialsState, - - AccountConfiguredState, - FinalState = AccountConfiguredState, -}; -Q_ENUM_NS(SetupWizardState) - -static QString setupWizardStateToText(SetupWizardState state) -{ - switch (state) { - case SetupWizardState::ServerUrlState: - return QObject::tr("Server URL"); - case SetupWizardState::CredentialsState: - return QObject::tr("Credentials"); - case SetupWizardState::AccountConfiguredState: - return QObject::tr("Sync Options"); - default: - Q_UNREACHABLE(); - } -} -} diff --git a/src/gui/newwizard/syncmode.cpp b/src/gui/newwizard/syncmode.cpp deleted file mode 100644 index 74b76c8f5..000000000 --- a/src/gui/newwizard/syncmode.cpp +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (C) Fabian Müller - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - */ - -// just a stub so the MOC file can be included somewhere -#include "moc_syncmode.cpp" diff --git a/src/gui/newwizard/syncmode.h b/src/gui/newwizard/syncmode.h deleted file mode 100644 index a9fa49aa5..000000000 --- a/src/gui/newwizard/syncmode.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (C) Fabian Müller - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - */ - -#pragma once - -#include - -namespace OCC::Wizard { -Q_NAMESPACE - -enum class SyncMode { - Invalid = 0, - SyncEverything, - ConfigureUsingFolderWizard, - UseVfs, -}; -Q_ENUM_NS(SyncMode) -} -- cgit v1.2.3