1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
|
#ifndef SETTINGS_DIALOG_H
#define SETTINGS_DIALOG_H
#include "./settings.h"
#include "../webview/webviewdefs.h"
#if !QT_CONFIG(process)
#include <syncthingconnector/syncthingprocess.h>
#endif
#include <syncthingmodel/syncthingicons.h>
#include <qtutilities/settingsdialog/optionpage.h>
#include <qtutilities/settingsdialog/qtsettings.h>
#include <qtutilities/settingsdialog/settingsdialog.h>
#if QT_CONFIG(process)
#include <QProcess>
#endif
#include <QStringList>
#include <QWidget>
#include <optional>
QT_FORWARD_DECLARE_CLASS(QAction)
QT_FORWARD_DECLARE_CLASS(QLabel)
namespace CppUtilities {
class DateTime;
}
namespace QtUtilities {
class ColorButton;
class IconButton;
class RestartHandler;
class UpdateOptionPage;
} // namespace QtUtilities
namespace Data {
class SyncthingConnection;
class SyncthingService;
class SyncthingProcess;
class SyncthingLauncher;
class SyncthingStatusComputionModel;
} // namespace Data
namespace QtGui {
/*!
* \brief The GuiType enum specifies a GUI type.
*
* Such a value can be passed to some option pages to show only the options which are relevant
* for the particular GUI type.
*/
enum class GuiType {
TrayWidget,
Plasmoid,
};
BEGIN_DECLARE_UI_FILE_BASED_OPTION_PAGE_CUSTOM_CTOR(ConnectionOptionPage)
public:
ConnectionOptionPage(Data::SyncthingConnection *connection, QWidget *parentWidget = nullptr);
void hideConnectionStatus();
private:
DECLARE_SETUP_WIDGETS
void insertFromConfigFile(bool forceFileSelection);
void updateConnectionStatus();
void applyAndReconnect();
bool showConnectionSettings(int index);
bool cacheCurrentSettings(bool applying);
void saveCurrentConfigName(const QString &name);
void addNewConfig();
void removeSelectedConfig();
void moveSelectedConfigDown();
void moveSelectedConfigUp();
void setCurrentIndex(int currentIndex);
void toggleAdvancedSettings(bool show);
Data::SyncthingConnection *m_connection;
Data::SyncthingConnectionSettings m_primarySettings;
std::vector<Data::SyncthingConnectionSettings> m_secondarySettings;
Data::SyncthingStatusComputionModel *m_statusComputionModel;
int m_currentIndex;
END_DECLARE_OPTION_PAGE
BEGIN_DECLARE_UI_FILE_BASED_OPTION_PAGE_CUSTOM_CTOR(NotificationsOptionPage)
public:
NotificationsOptionPage(GuiType guiType = GuiType::TrayWidget, QWidget *parentWidget = nullptr);
private:
DECLARE_SETUP_WIDGETS
const GuiType m_guiType;
END_DECLARE_OPTION_PAGE
BEGIN_DECLARE_UI_FILE_BASED_OPTION_PAGE(AppearanceOptionPage)
public:
void resetPositioningSettings();
static int tabIndexToComboBoxIndex(int tabIndex);
static int comboBoxIndexToTabIndex(int comboBoxIndex);
END_DECLARE_OPTION_PAGE
BEGIN_DECLARE_UI_FILE_BASED_OPTION_PAGE_CUSTOM_CTOR(IconsOptionPage)
public:
enum class Context { Combined, UI, System };
explicit IconsOptionPage(Context context = Context::Combined, QWidget *parentWidget = nullptr);
DECLARE_SETUP_WIDGETS
private:
void update(bool preserveSize = false);
Context m_context;
Data::StatusIconSettings m_settings;
QAction *m_paletteAction = nullptr;
bool m_usePalette = false;
struct {
QtUtilities::ColorButton *colorButtons[3] = {};
QLabel *previewLabel = nullptr;
Data::StatusIconColorSet *setting = nullptr;
Data::StatusEmblem statusEmblem = Data::StatusEmblem::None;
} m_widgets[Data::StatusIconSettings::distinguishableColorCount];
END_DECLARE_OPTION_PAGE
BEGIN_DECLARE_UI_FILE_BASED_OPTION_PAGE(AutostartOptionPage)
private:
bool m_unsupported = false;
DECLARE_SETUP_WIDGETS
END_DECLARE_OPTION_PAGE
SYNCTHINGWIDGETS_EXPORT std::optional<QString> configuredAutostartPath();
SYNCTHINGWIDGETS_EXPORT QString supposedAutostartPath();
SYNCTHINGWIDGETS_EXPORT bool setAutostartPath(const QString &path);
SYNCTHINGWIDGETS_EXPORT bool isAutostartEnabled();
SYNCTHINGWIDGETS_EXPORT bool setAutostartEnabled(bool enabled, bool force = false);
BEGIN_DECLARE_TYPEDEF_UI_FILE_BASED_OPTION_PAGE(LauncherOptionPage)
class QT_UTILITIES_EXPORT LauncherOptionPage : public QObject, public ::QtUtilities::UiFileBasedOptionPage<Ui::LauncherOptionPage> {
Q_OBJECT
public:
LauncherOptionPage(QWidget *parentWidget = nullptr);
LauncherOptionPage(
const QString &tool, const QString &toolName = QString(), const QString &windowTitle = QString(), QWidget *parentWidget = nullptr);
~LauncherOptionPage() override;
bool apply() override;
void reset() override;
bool isRunning() const;
private Q_SLOTS:
void handleSyncthingLaunched(bool running);
void handleSyncthingReadyRead();
void handleSyncthingOutputAvailable(const QByteArray &output);
void handleSyncthingExited(int exitCode, QProcess::ExitStatus exitStatus);
void handleSyncthingError(QProcess::ProcessError error);
void launch();
#ifdef SYNCTHINGWIDGETS_USE_LIBSYNCTHING
void updateLibSyncthingLogLevel();
#endif
void stop();
void restoreDefaultArguments();
private:
DECLARE_SETUP_WIDGETS
Data::SyncthingProcess *const m_process;
Data::SyncthingLauncher *const m_launcher;
QAction *m_restoreArgsAction;
QAction *m_syncthingDownloadAction;
bool m_kill;
QString m_tool, m_toolName, m_windowTitle;
};
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
BEGIN_DECLARE_UI_FILE_BASED_OPTION_PAGE(SystemdOptionPage)
private:
DECLARE_SETUP_WIDGETS
void handleSystemUnitChanged();
void handleDescriptionChanged(const QString &description);
void handleStatusChanged(const QString &activeState, const QString &subState, CppUtilities::DateTime activeSince);
void handleEnabledChanged(const QString &unitFileState);
bool updateRunningColor();
bool updateEnabledColor();
void updateColors();
Data::SyncthingService *const m_service;
QStringList m_status;
QMetaObject::Connection m_unitChangedConn;
QMetaObject::Connection m_descChangedConn;
QMetaObject::Connection m_statusChangedConn;
QMetaObject::Connection m_enabledChangedConn;
END_DECLARE_OPTION_PAGE
#endif
BEGIN_DECLARE_UI_FILE_BASED_OPTION_PAGE(GeneralWebViewOptionPage)
private:
DECLARE_SETUP_WIDGETS
void showCustomCommandPrompt();
QString m_customCommand;
END_DECLARE_OPTION_PAGE
#ifndef SYNCTHINGWIDGETS_NO_WEBVIEW
DECLARE_UI_FILE_BASED_OPTION_PAGE(BuiltinWebViewOptionPage)
#else
DECLARE_OPTION_PAGE(BuiltinWebViewOptionPage)
#endif
class SYNCTHINGWIDGETS_EXPORT SettingsDialog : public QtUtilities::SettingsDialog {
Q_OBJECT
public:
explicit SettingsDialog(Data::SyncthingConnection *connection, QWidget *parent = nullptr);
explicit SettingsDialog(const QList<QtUtilities::OptionCategory *> &categories, QWidget *parent = nullptr);
explicit SettingsDialog(QWidget *parent = nullptr);
~SettingsDialog() override;
void hideConnectionStatus();
void selectLauncherSettings();
void selectUpdateSettings();
static void respawnIfRestartRequested();
Q_SIGNALS:
void wizardRequested();
public Q_SLOTS:
void resetPositioningSettings();
private:
void init();
ConnectionOptionPage *m_connectionsOptionPage = nullptr;
AppearanceOptionPage *m_appearanceOptionPage = nullptr;
QtUtilities::UpdateOptionPage *m_updateOptionPage = nullptr;
int m_launcherSettingsCategory = -1, m_launcherSettingsPageIndex = -1;
int m_updateSettingsCategory = -1, m_updateSettingsPageIndex = -1;
static QtUtilities::RestartHandler *s_restartHandler;
};
} // namespace QtGui
DECLARE_EXTERN_UI_FILE_BASED_OPTION_PAGE_NS(QtGui, ConnectionOptionPage)
DECLARE_EXTERN_UI_FILE_BASED_OPTION_PAGE_NS(QtGui, NotificationsOptionPage)
DECLARE_EXTERN_UI_FILE_BASED_OPTION_PAGE_NS(QtGui, AppearanceOptionPage)
DECLARE_EXTERN_UI_FILE_BASED_OPTION_PAGE_NS(QtGui, IconsOptionPage)
DECLARE_EXTERN_UI_FILE_BASED_OPTION_PAGE_NS(QtGui, AutostartOptionPage)
DECLARE_EXTERN_UI_FILE_BASED_OPTION_PAGE_NS(QtGui, LauncherOptionPage)
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
DECLARE_EXTERN_UI_FILE_BASED_OPTION_PAGE_NS(QtGui, SystemdOptionPage)
#endif
DECLARE_EXTERN_UI_FILE_BASED_OPTION_PAGE_NS(QtGui, GeneralWebViewOptionPage)
#ifndef SYNCTHINGWIDGETS_NO_WEBVIEW
DECLARE_EXTERN_UI_FILE_BASED_OPTION_PAGE_NS(QtGui, BuiltinWebViewOptionPage)
#endif
#endif // SETTINGS_DIALOG_H
|