2022-08-06 21:08:55 +02:00
|
|
|
#include "./wizard.h"
|
2022-08-23 18:19:47 +02:00
|
|
|
#include "./setupdetection.h"
|
2022-08-06 21:08:55 +02:00
|
|
|
|
2022-08-23 12:31:43 +02:00
|
|
|
#include "../misc/statusinfo.h"
|
|
|
|
|
2022-08-06 21:08:55 +02:00
|
|
|
// use meta-data of syncthingtray application here
|
|
|
|
#include "resources/../../tray/resources/config.h"
|
|
|
|
|
2022-09-03 21:32:44 +02:00
|
|
|
#include "ui_autostartwizardpage.h"
|
2022-08-23 21:06:58 +02:00
|
|
|
#include "ui_mainconfigwizardpage.h"
|
|
|
|
|
2022-08-27 23:35:15 +02:00
|
|
|
#include <qtutilities/misc/dialogutils.h>
|
|
|
|
|
2022-08-23 18:19:47 +02:00
|
|
|
#include <QCheckBox>
|
2022-08-06 21:08:55 +02:00
|
|
|
#include <QCommandLinkButton>
|
|
|
|
#include <QDesktopServices>
|
2022-08-27 23:35:15 +02:00
|
|
|
#include <QDialog>
|
2022-08-22 23:48:18 +02:00
|
|
|
#include <QFileDialog>
|
2022-08-06 21:08:55 +02:00
|
|
|
#include <QFrame>
|
|
|
|
#include <QLabel>
|
2022-08-22 23:48:18 +02:00
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QProgressBar>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QStringList>
|
2022-08-27 23:35:15 +02:00
|
|
|
#include <QTextEdit>
|
2022-08-06 21:08:55 +02:00
|
|
|
#include <QUrl>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
2022-08-27 23:35:15 +02:00
|
|
|
#include <initializer_list>
|
2022-08-06 21:08:55 +02:00
|
|
|
#include <string_view>
|
|
|
|
|
2022-09-03 21:32:44 +02:00
|
|
|
#if (defined(PLATFORM_LINUX) && !defined(Q_OS_ANDROID)) || defined(PLATFORM_WINDOWS) || defined(PLATFORM_MAC)
|
|
|
|
#define SETTINGS_WIZARD_AUTOSTART
|
|
|
|
#endif
|
|
|
|
|
2022-08-06 21:08:55 +02:00
|
|
|
namespace QtGui {
|
|
|
|
|
|
|
|
Wizard *Wizard::s_instance = nullptr;
|
|
|
|
|
|
|
|
Wizard::Wizard(QWidget *parent, Qt::WindowFlags flags)
|
|
|
|
: QWizard(parent, flags)
|
|
|
|
{
|
|
|
|
setWindowTitle(tr("Setup wizard - ") + QStringLiteral(APP_NAME));
|
2022-09-11 12:58:47 +02:00
|
|
|
setWindowIcon(QIcon(QString::fromUtf8(":/icons/hicolor/scalable/app/syncthingtray.svg")));
|
2022-08-25 21:47:20 +02:00
|
|
|
setMinimumSize(770, 550);
|
2022-08-06 21:08:55 +02:00
|
|
|
|
2022-09-03 21:32:44 +02:00
|
|
|
auto *const welcomePage = new WelcomeWizardPage(this);
|
2022-08-23 18:19:47 +02:00
|
|
|
auto *const detectionPage = new DetectionWizardPage(this);
|
|
|
|
auto *const mainConfigPage = new MainConfigWizardPage(this);
|
|
|
|
connect(mainConfigPage, &MainConfigWizardPage::retry, detectionPage, &DetectionWizardPage::refresh);
|
2022-09-03 21:32:44 +02:00
|
|
|
connect(mainConfigPage, &MainConfigWizardPage::configurationSelected, this, &Wizard::handleConfigurationSelected);
|
|
|
|
#ifdef SETTINGS_WIZARD_AUTOSTART
|
|
|
|
auto *const autostartPage = new AutostartWizardPage(this);
|
|
|
|
connect(autostartPage, &AutostartWizardPage::autostartSelected, this, &Wizard::handleAutostartSelected);
|
|
|
|
#endif
|
|
|
|
addPage(welcomePage);
|
2022-08-23 18:19:47 +02:00
|
|
|
addPage(detectionPage);
|
|
|
|
addPage(mainConfigPage);
|
2022-09-03 21:32:44 +02:00
|
|
|
#ifdef SETTINGS_WIZARD_AUTOSTART
|
|
|
|
addPage(autostartPage);
|
|
|
|
#endif
|
2022-08-27 23:35:15 +02:00
|
|
|
|
|
|
|
connect(this, &QWizard::customButtonClicked, this, &Wizard::showDetailsFromSetupDetection);
|
2022-08-06 21:08:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Wizard::~Wizard()
|
|
|
|
{
|
|
|
|
if (this == s_instance) {
|
|
|
|
s_instance = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Wizard *Wizard::instance()
|
|
|
|
{
|
|
|
|
if (!s_instance) {
|
|
|
|
s_instance = new Wizard();
|
|
|
|
s_instance->setAttribute(Qt::WA_DeleteOnClose, true);
|
|
|
|
}
|
|
|
|
return s_instance;
|
|
|
|
}
|
|
|
|
|
2022-08-23 18:19:47 +02:00
|
|
|
SetupDetection &Wizard::setupDetection()
|
|
|
|
{
|
|
|
|
if (!m_setupDetection) {
|
|
|
|
m_setupDetection = std::make_unique<SetupDetection>();
|
|
|
|
}
|
|
|
|
return *m_setupDetection;
|
|
|
|
}
|
|
|
|
|
2022-08-27 23:35:15 +02:00
|
|
|
void Wizard::showDetailsFromSetupDetection()
|
|
|
|
{
|
|
|
|
auto const &detection = setupDetection();
|
|
|
|
auto info = QString();
|
|
|
|
auto addParagraph = [&info](const QString &text) {
|
|
|
|
info.append(QStringLiteral("<p><b>"));
|
|
|
|
info.append(text);
|
|
|
|
info.append(QStringLiteral("</b></p>"));
|
|
|
|
};
|
|
|
|
auto addListRo = [&info](const QStringList &items) {
|
|
|
|
info.append(QStringLiteral("<ul><li>"));
|
|
|
|
info.append(items.join(QStringLiteral("</li><li>")));
|
|
|
|
info.append(QStringLiteral("</li></ul>"));
|
|
|
|
};
|
|
|
|
auto addList = [&addListRo](QStringList &items) {
|
|
|
|
addListRo(items);
|
|
|
|
items.clear();
|
|
|
|
};
|
|
|
|
auto infoItems = QStringList();
|
|
|
|
if (detection.configFilePath.isEmpty()) {
|
|
|
|
infoItems << tr("Unable to locate Syncthing config file.");
|
|
|
|
} else {
|
|
|
|
infoItems << tr("Located Syncthing config file: ") + detection.configFilePath;
|
|
|
|
if (detection.hasConfig()) {
|
|
|
|
infoItems << tr("Syncthing config file looks ok.");
|
|
|
|
} else {
|
|
|
|
infoItems << tr("Syncthing config file looks invalid/incomplete.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
addParagraph(tr("Syncthing configuration:"));
|
|
|
|
addList(infoItems);
|
|
|
|
|
|
|
|
// add connection info
|
|
|
|
if (detection.connection.isConnected()) {
|
|
|
|
auto statusInfo = StatusInfo();
|
|
|
|
statusInfo.updateConnectionStatus(detection.connection);
|
|
|
|
statusInfo.updateConnectionStatus(detection.connection);
|
|
|
|
infoItems << tr("Could connect to Syncthing under: ") + detection.connection.syncthingUrl();
|
|
|
|
infoItems << tr("Syncthing version: ") + detection.connection.syncthingVersion();
|
|
|
|
infoItems << tr("Syncthing device ID: ") + detection.connection.myId();
|
|
|
|
infoItems << tr("Syncthing status: ") + statusInfo.statusText();
|
|
|
|
if (!statusInfo.additionalStatusText().isEmpty()) {
|
|
|
|
infoItems << tr("Additional Syncthing status info: ") + statusInfo.additionalStatusText();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
infoItems << tr("Coult NOT connect to Syncthing under: ") + detection.connection.syncthingUrl();
|
|
|
|
}
|
|
|
|
addParagraph(tr("API connection:"));
|
|
|
|
addList(infoItems);
|
|
|
|
if (!detection.connectionErrors.isEmpty()) {
|
|
|
|
addParagraph(tr("API connection errors:"));
|
|
|
|
addListRo(detection.connectionErrors);
|
|
|
|
}
|
|
|
|
|
|
|
|
// add systemd service info
|
|
|
|
addParagraph(tr("Systemd:"));
|
|
|
|
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
|
|
|
|
infoItems << tr("State of user unit file \"%1\": ").arg(detection.userService.unitName()) + detection.userService.unitFileState();
|
|
|
|
infoItems << tr("State of system unit file \"%1\": ").arg(detection.systemService.unitName()) + detection.systemService.unitFileState();
|
|
|
|
addList(infoItems);
|
|
|
|
#else
|
|
|
|
addListRo(QStringList(tr("No available")));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// add launcher info
|
|
|
|
const auto successfulTestLaunch = detection.launcherExitCode.has_value() && detection.launcherExitStatus.value() == QProcess::NormalExit;
|
|
|
|
if (successfulTestLaunch) {
|
|
|
|
infoItems << tr("Could test-launch Syncthing successfully, exit code: ") + QString::number(detection.launcherExitCode.value());
|
|
|
|
infoItems << tr("Syncthing version returned from test-launch: ") + QString::fromLocal8Bit(detection.launcherOutput.trimmed());
|
|
|
|
} else {
|
|
|
|
infoItems << tr("Unable to test-launch Syncthing: ") + detection.launcher.errorString();
|
|
|
|
}
|
|
|
|
infoItems << tr("Built-in Syncthing available: ") + (Data::SyncthingLauncher::isLibSyncthingAvailable() ? tr("yes") : tr("no"));
|
|
|
|
addParagraph(tr("Launcher:"));
|
|
|
|
addList(infoItems);
|
|
|
|
|
|
|
|
// show info in dialog
|
|
|
|
auto dlg = QDialog(this);
|
|
|
|
dlg.setWindowFlags(Qt::Tool);
|
|
|
|
dlg.setWindowTitle(tr("Details from setup detection - ") + QStringLiteral(APP_NAME));
|
|
|
|
dlg.resize(500, 400);
|
|
|
|
QtUtilities::centerWidgetAvoidingOverflow(&dlg);
|
|
|
|
auto layout = QBoxLayout(QBoxLayout::Up);
|
|
|
|
layout.setContentsMargins(0, 0, 0, 0);
|
|
|
|
auto textEdit = QTextEdit(this);
|
|
|
|
textEdit.setHtml(info);
|
|
|
|
layout.addWidget(&textEdit);
|
|
|
|
dlg.setLayout(&layout);
|
|
|
|
dlg.exec();
|
|
|
|
}
|
|
|
|
|
2022-09-03 21:32:44 +02:00
|
|
|
void Wizard::handleConfigurationSelected(MainConfiguration mainConfig, ExtraConfiguration extraConfig)
|
|
|
|
{
|
|
|
|
m_mainConfig = mainConfig;
|
|
|
|
m_extraConfig = extraConfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Wizard::handleAutostartSelected(bool autostartEnabled)
|
|
|
|
{
|
|
|
|
m_autoStart = autostartEnabled;
|
|
|
|
}
|
|
|
|
|
2022-08-06 21:08:55 +02:00
|
|
|
WelcomeWizardPage::WelcomeWizardPage(QWidget *parent)
|
|
|
|
: QWizardPage(parent)
|
|
|
|
{
|
|
|
|
auto *const infoLabel = new QLabel(this);
|
|
|
|
infoLabel->setWordWrap(true);
|
2022-08-27 19:19:03 +02:00
|
|
|
const auto &settings = Settings::values();
|
|
|
|
if (settings.firstLaunch || settings.fakeFirstLaunch) {
|
|
|
|
setTitle(tr("Welcome to Syncthing Tray"));
|
|
|
|
setSubTitle(tr("It looks like you're launching Syncthing Tray for the first time."));
|
|
|
|
infoLabel->setText(tr("You must configure how to connect to Syncthing and how to launch Syncthing (if that's wanted) when using Syncthing "
|
|
|
|
"Tray the first time. A "
|
|
|
|
"guided/automated setup is still in the works so the manual setup is currently the only option."));
|
|
|
|
} else {
|
|
|
|
setTitle(tr("Wizard's start page"));
|
|
|
|
setSubTitle(tr("This wizard will help you configuring Syncthing Tray."));
|
|
|
|
}
|
2022-08-06 21:08:55 +02:00
|
|
|
|
2022-08-22 23:48:18 +02:00
|
|
|
QCommandLinkButton *startWizardCommand = nullptr;
|
2022-08-27 19:19:03 +02:00
|
|
|
if (settings.enableWipFeatures) {
|
2022-08-22 23:48:18 +02:00
|
|
|
startWizardCommand = new QCommandLinkButton(this);
|
|
|
|
startWizardCommand->setText(tr("Start guided setup"));
|
|
|
|
startWizardCommand->setDescription(
|
2022-08-23 18:19:47 +02:00
|
|
|
tr("Allows to configure Syncthing Tray automatically for the local Syncthing instance and helps you starting Syncthing if wanted."));
|
2022-08-25 21:35:22 +02:00
|
|
|
startWizardCommand->setIcon(
|
|
|
|
QIcon::fromTheme(QStringLiteral("tools-wizard"), QIcon(QStringLiteral(":/icons/hicolor/scalable/actions/tools-wizard.svg"))));
|
2022-08-23 18:19:47 +02:00
|
|
|
connect(startWizardCommand, &QCommandLinkButton::clicked, this, [this] { this->wizard()->next(); });
|
2022-08-22 23:48:18 +02:00
|
|
|
}
|
|
|
|
|
2022-08-06 21:08:55 +02:00
|
|
|
auto *const showSettingsCommand = new QCommandLinkButton(this);
|
2022-08-27 19:19:03 +02:00
|
|
|
if (settings.firstLaunch) {
|
|
|
|
showSettingsCommand->setText(tr("Configure connection and launcher settings manually"));
|
|
|
|
} else {
|
|
|
|
showSettingsCommand->setText(tr("Head back to settings to configure connection and launcher manually"));
|
|
|
|
}
|
2022-08-06 21:08:55 +02:00
|
|
|
showSettingsCommand->setDescription(
|
2022-08-08 23:05:55 +02:00
|
|
|
tr("Note that the connection settings allow importing URL, credentials and API-key from the local Syncthing configuration."));
|
2022-08-25 21:35:22 +02:00
|
|
|
showSettingsCommand->setIcon(
|
|
|
|
QIcon::fromTheme(QStringLiteral("preferences-other"), QIcon(QStringLiteral(":/icons/hicolor/scalable/apps/preferences-other.svg"))));
|
2022-08-06 21:08:55 +02:00
|
|
|
connect(showSettingsCommand, &QCommandLinkButton::clicked, this, [this] {
|
|
|
|
if (auto *const wizard = qobject_cast<Wizard *>(this->wizard())) {
|
|
|
|
emit wizard->settingsRequested();
|
|
|
|
wizard->close();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
auto *const line = new QFrame(this);
|
|
|
|
line->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));
|
|
|
|
line->setFrameShape(QFrame::HLine);
|
|
|
|
line->setFrameShadow(QFrame::Sunken);
|
|
|
|
|
|
|
|
auto *const showDocsCommand = new QCommandLinkButton(this);
|
|
|
|
showDocsCommand->setText(tr("Show Syncthing's documentation"));
|
2022-08-08 23:05:55 +02:00
|
|
|
showDocsCommand->setDescription(tr("It contains general information about configuring Syncthing."));
|
2022-08-25 21:35:22 +02:00
|
|
|
showDocsCommand->setIcon(
|
|
|
|
QIcon::fromTheme(QStringLiteral("help-contents"), QIcon(QStringLiteral(":/icons/hicolor/scalable/apps/system-help.svg"))));
|
2022-08-06 21:08:55 +02:00
|
|
|
connect(showDocsCommand, &QCommandLinkButton::clicked, this, [] { QDesktopServices::openUrl(QStringLiteral("https://docs.syncthing.net/")); });
|
|
|
|
|
|
|
|
auto *const showReadmeCommand = new QCommandLinkButton(this);
|
2022-08-08 23:05:55 +02:00
|
|
|
showReadmeCommand->setText(tr("Show Syncthing Tray's README"));
|
|
|
|
showReadmeCommand->setDescription(tr("It contains documentation about this GUI integration specifically."));
|
2022-08-06 21:08:55 +02:00
|
|
|
showReadmeCommand->setIcon(showDocsCommand->icon());
|
|
|
|
connect(showReadmeCommand, &QCommandLinkButton::clicked, this, [] {
|
|
|
|
if constexpr (std::string_view(APP_VERSION).find('-') == std::string_view::npos) {
|
|
|
|
QDesktopServices::openUrl(QStringLiteral(APP_URL "/blob/v" APP_VERSION "/README.md"));
|
|
|
|
} else {
|
|
|
|
QDesktopServices::openUrl(QStringLiteral(APP_URL "/blob/master/README.md"));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
auto *const layout = new QVBoxLayout;
|
|
|
|
layout->addWidget(infoLabel);
|
2022-08-22 23:48:18 +02:00
|
|
|
if (startWizardCommand) {
|
|
|
|
layout->addWidget(startWizardCommand);
|
|
|
|
}
|
2022-08-06 21:08:55 +02:00
|
|
|
layout->addWidget(showSettingsCommand);
|
|
|
|
layout->addStretch();
|
|
|
|
layout->addWidget(line);
|
|
|
|
layout->addWidget(showDocsCommand);
|
|
|
|
layout->addWidget(showReadmeCommand);
|
|
|
|
setLayout(layout);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WelcomeWizardPage::isComplete() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-08-22 23:48:18 +02:00
|
|
|
DetectionWizardPage::DetectionWizardPage(QWidget *parent)
|
|
|
|
: QWizardPage(parent)
|
|
|
|
{
|
|
|
|
setTitle(tr("Checking current Syncthing setup"));
|
2022-08-23 18:19:47 +02:00
|
|
|
setSubTitle(tr("Checking Syncthing configuration and whether Syncthing is already running or can be started …"));
|
2022-08-22 23:48:18 +02:00
|
|
|
|
2022-08-23 18:19:47 +02:00
|
|
|
auto *const progressBar = new QProgressBar(this);
|
|
|
|
progressBar->setMinimum(0);
|
|
|
|
progressBar->setMaximum(0);
|
2022-08-22 23:48:18 +02:00
|
|
|
|
|
|
|
auto *const layout = new QVBoxLayout;
|
2022-08-23 18:19:47 +02:00
|
|
|
layout->addWidget(progressBar);
|
2022-08-22 23:48:18 +02:00
|
|
|
setLayout(layout);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DetectionWizardPage::isComplete() const
|
|
|
|
{
|
2022-08-23 18:19:47 +02:00
|
|
|
return m_setupDetection && m_setupDetection->isDone();
|
2022-08-22 23:48:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void DetectionWizardPage::initializePage()
|
|
|
|
{
|
2022-08-23 18:19:47 +02:00
|
|
|
auto *const wizard = qobject_cast<Wizard *>(this->wizard());
|
|
|
|
if (!wizard) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_setupDetection = &wizard->setupDetection();
|
|
|
|
m_setupDetection->reset();
|
2022-08-22 23:48:18 +02:00
|
|
|
emit completeChanged();
|
|
|
|
QTimer::singleShot(0, this, &DetectionWizardPage::tryToConnect);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DetectionWizardPage::cleanupPage()
|
|
|
|
{
|
2022-08-23 18:19:47 +02:00
|
|
|
if (m_setupDetection) {
|
|
|
|
m_setupDetection->disconnect(this);
|
|
|
|
m_setupDetection->reset();
|
2022-08-23 12:31:43 +02:00
|
|
|
}
|
2022-08-22 23:48:18 +02:00
|
|
|
}
|
|
|
|
|
2022-08-23 18:19:47 +02:00
|
|
|
void DetectionWizardPage::refresh()
|
2022-08-22 23:48:18 +02:00
|
|
|
{
|
2022-08-23 18:19:47 +02:00
|
|
|
initializePage();
|
|
|
|
}
|
2022-08-23 12:31:43 +02:00
|
|
|
|
2022-08-23 18:19:47 +02:00
|
|
|
void DetectionWizardPage::tryToConnect()
|
|
|
|
{
|
|
|
|
// determine path of Syncthing's config file, possibly ask user to select it
|
|
|
|
m_setupDetection->determinePaths();
|
|
|
|
if (m_setupDetection->configFilePath.isEmpty()) {
|
2022-08-22 23:48:18 +02:00
|
|
|
auto msgbox = QMessageBox(wizard());
|
|
|
|
auto yesButton = QPushButton(tr("Yes, continue configuration"));
|
|
|
|
auto noButton = QPushButton(tr("No, let me select Syncthing's configuration file manually"));
|
|
|
|
msgbox.setIcon(QMessageBox::Question);
|
|
|
|
msgbox.setText(
|
|
|
|
tr("It looks like Syncthing has not been running on this system before as its configuration cannot be found. Is that correct?"));
|
|
|
|
msgbox.addButton(&yesButton, QMessageBox::YesRole);
|
|
|
|
msgbox.addButton(&noButton, QMessageBox::NoRole);
|
|
|
|
msgbox.exec();
|
|
|
|
if (msgbox.clickedButton() == &noButton) {
|
2022-08-23 18:19:47 +02:00
|
|
|
m_setupDetection->configFilePath = QFileDialog::getOpenFileName(
|
2022-08-22 23:48:18 +02:00
|
|
|
wizard(), tr("Select Syncthing's configuration file"), QString(), QStringLiteral("XML files (*.xml);All files (*.*)"));
|
|
|
|
}
|
|
|
|
}
|
2022-08-23 12:31:43 +02:00
|
|
|
|
2022-08-23 18:19:47 +02:00
|
|
|
// start setup detection tests
|
|
|
|
connect(m_setupDetection, &SetupDetection::done, this, &DetectionWizardPage::continueIfDone);
|
|
|
|
m_setupDetection->startTest();
|
2022-08-22 23:48:18 +02:00
|
|
|
}
|
|
|
|
|
2022-08-23 18:19:47 +02:00
|
|
|
void DetectionWizardPage::continueIfDone()
|
2022-08-22 23:48:18 +02:00
|
|
|
{
|
2022-08-23 18:19:47 +02:00
|
|
|
m_setupDetection->disconnect(this);
|
|
|
|
emit completeChanged();
|
|
|
|
wizard()->next();
|
2022-08-22 23:48:18 +02:00
|
|
|
}
|
|
|
|
|
2022-08-23 18:19:47 +02:00
|
|
|
MainConfigWizardPage::MainConfigWizardPage(QWidget *parent)
|
|
|
|
: QWizardPage(parent)
|
2022-08-23 21:06:58 +02:00
|
|
|
, m_ui(new Ui::MainConfigWizardPage)
|
2022-08-27 23:35:15 +02:00
|
|
|
, m_configSelected(false)
|
2022-08-23 12:31:43 +02:00
|
|
|
{
|
2022-08-23 18:19:47 +02:00
|
|
|
setTitle(tr("Select what configuration to apply"));
|
|
|
|
setSubTitle(tr("Something when wrong when checking the Syncthing setup."));
|
2022-08-27 23:35:15 +02:00
|
|
|
setButtonText(QWizard::CustomButton1, tr("Show details from setup detection"));
|
2022-08-23 21:06:58 +02:00
|
|
|
m_ui->setupUi(this);
|
2022-08-27 23:35:15 +02:00
|
|
|
|
|
|
|
// connect signals & slots
|
|
|
|
for (auto *const option : std::initializer_list<QRadioButton *>{ m_ui->cfgCurrentlyRunningRadioButton, m_ui->cfgLauncherExternalRadioButton,
|
2022-09-03 21:35:44 +02:00
|
|
|
m_ui->cfgLauncherBuiltInRadioButton, m_ui->cfgSystemdUserUnitRadioButton, m_ui->cfgSystemdSystemUnitRadioButton }) {
|
2022-08-27 23:35:15 +02:00
|
|
|
connect(option, &QRadioButton::toggled, this, &MainConfigWizardPage::handleSelectionChanged);
|
|
|
|
}
|
2022-08-23 21:06:58 +02:00
|
|
|
}
|
2022-08-23 12:31:43 +02:00
|
|
|
|
2022-08-23 21:06:58 +02:00
|
|
|
MainConfigWizardPage::~MainConfigWizardPage()
|
|
|
|
{
|
2022-08-23 12:31:43 +02:00
|
|
|
}
|
|
|
|
|
2022-08-23 18:19:47 +02:00
|
|
|
bool MainConfigWizardPage::isComplete() const
|
2022-08-23 12:31:43 +02:00
|
|
|
{
|
2022-08-27 23:35:15 +02:00
|
|
|
return m_configSelected;
|
2022-08-23 12:31:43 +02:00
|
|
|
}
|
|
|
|
|
2022-08-23 18:19:47 +02:00
|
|
|
void MainConfigWizardPage::initializePage()
|
2022-08-23 12:31:43 +02:00
|
|
|
{
|
2022-08-23 18:19:47 +02:00
|
|
|
auto *const wizard = qobject_cast<Wizard *>(this->wizard());
|
|
|
|
if (!wizard) {
|
|
|
|
return;
|
2022-08-23 12:31:43 +02:00
|
|
|
}
|
|
|
|
|
2022-08-27 23:35:15 +02:00
|
|
|
// enable button to show details from setup detection
|
|
|
|
wizard->setOption(QWizard::HaveCustomButton1, true);
|
|
|
|
|
|
|
|
// hide all configuration options as a starting point
|
|
|
|
for (auto *const option : std::initializer_list<QWidget *>{ m_ui->cfgCurrentlyRunningRadioButton, m_ui->cfgLauncherExternalRadioButton,
|
2022-09-03 21:35:44 +02:00
|
|
|
m_ui->cfgLauncherBuiltInRadioButton, m_ui->cfgSystemdUserUnitRadioButton, m_ui->cfgSystemdSystemUnitRadioButton,
|
2022-08-27 23:35:15 +02:00
|
|
|
m_ui->enableSystemdIntegrationCheckBox }) {
|
|
|
|
option->hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
// offer enabling Systemd integration if at least one unit is available
|
2022-08-23 18:19:47 +02:00
|
|
|
auto const &detection = wizard->setupDetection();
|
2022-08-27 23:35:15 +02:00
|
|
|
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
|
|
|
|
if (detection.userService.isUnitAvailable() || detection.systemService.isUnitAvailable()) {
|
|
|
|
m_ui->enableSystemdIntegrationCheckBox->show();
|
|
|
|
m_ui->enableSystemdIntegrationCheckBox->setChecked(true);
|
2022-08-22 23:48:18 +02:00
|
|
|
}
|
2022-08-27 23:35:15 +02:00
|
|
|
#endif
|
2022-08-23 12:31:43 +02:00
|
|
|
|
2022-08-27 23:35:15 +02:00
|
|
|
// add short summary as sub title and offer configurations that make sense
|
2022-08-23 18:19:47 +02:00
|
|
|
if (detection.connection.isConnected()) {
|
2022-08-27 23:35:15 +02:00
|
|
|
// do not propose any options to launch Syncthing if it is already running
|
|
|
|
setSubTitle(tr("Looks like Syncthing is already running and Syncthing Tray can be configured accordingly automatically."));
|
|
|
|
m_ui->cfgCurrentlyRunningRadioButton->show();
|
|
|
|
m_ui->cfgCurrentlyRunningRadioButton->setChecked(true);
|
2022-08-23 21:06:58 +02:00
|
|
|
} else {
|
2022-08-27 23:35:15 +02:00
|
|
|
// propose options to launch Syncthing if it is not running
|
|
|
|
auto launchOptions = QStringList();
|
|
|
|
launchOptions.reserve(2);
|
2022-08-23 12:31:43 +02:00
|
|
|
|
2022-08-27 23:35:15 +02:00
|
|
|
// enable options to launch Syncthing via Systemd if Systemd units have been found
|
2022-08-23 12:31:43 +02:00
|
|
|
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
|
2022-08-27 23:35:15 +02:00
|
|
|
const auto canLaunchViaUserUnit = detection.userService.canEnableOrStart();
|
|
|
|
const auto canLaunchViaSystemUnit = detection.systemService.canEnableOrStart();
|
|
|
|
if (canLaunchViaUserUnit) {
|
2022-09-03 21:35:44 +02:00
|
|
|
m_ui->cfgSystemdUserUnitRadioButton->show();
|
2022-08-27 23:35:15 +02:00
|
|
|
}
|
|
|
|
if (canLaunchViaSystemUnit) {
|
2022-09-03 21:35:44 +02:00
|
|
|
m_ui->cfgSystemdSystemUnitRadioButton->show();
|
2022-08-27 23:35:15 +02:00
|
|
|
}
|
|
|
|
if (canLaunchViaUserUnit) {
|
2022-09-03 21:35:44 +02:00
|
|
|
m_ui->cfgSystemdUserUnitRadioButton->setChecked(true);
|
2022-08-27 23:35:15 +02:00
|
|
|
} else if (canLaunchViaSystemUnit) {
|
2022-09-03 21:35:44 +02:00
|
|
|
m_ui->cfgSystemdSystemUnitRadioButton->setChecked(true);
|
2022-08-27 23:35:15 +02:00
|
|
|
}
|
|
|
|
if (canLaunchViaUserUnit || canLaunchViaSystemUnit) {
|
|
|
|
launchOptions << tr("Systemd");
|
|
|
|
}
|
2022-08-23 12:31:43 +02:00
|
|
|
#endif
|
|
|
|
|
2022-08-27 23:35:15 +02:00
|
|
|
// enable options to launch Syncthing via built-in launcher if Syncthing executable found or libsyncthing available
|
|
|
|
const auto successfulTestLaunch = detection.launcherExitCode.has_value() && detection.launcherExitStatus.value() == QProcess::NormalExit;
|
|
|
|
if (successfulTestLaunch || Data::SyncthingLauncher::isLibSyncthingAvailable()) {
|
|
|
|
launchOptions << tr("Syncthing Tray");
|
|
|
|
if (successfulTestLaunch) {
|
|
|
|
m_ui->cfgLauncherExternalRadioButton->show();
|
|
|
|
}
|
|
|
|
if (Data::SyncthingLauncher::isLibSyncthingAvailable()) {
|
2022-09-03 21:35:44 +02:00
|
|
|
m_ui->cfgLauncherBuiltInRadioButton->show();
|
2022-08-27 23:35:15 +02:00
|
|
|
}
|
|
|
|
if (successfulTestLaunch) {
|
|
|
|
m_ui->cfgLauncherExternalRadioButton->setChecked(true);
|
|
|
|
} else {
|
2022-09-03 21:35:44 +02:00
|
|
|
m_ui->cfgLauncherBuiltInRadioButton->setChecked(true);
|
2022-08-27 23:35:15 +02:00
|
|
|
}
|
|
|
|
}
|
2022-08-23 18:19:47 +02:00
|
|
|
|
2022-08-27 23:35:15 +02:00
|
|
|
if (!launchOptions.isEmpty()) {
|
|
|
|
setSubTitle(tr("Looks like Syncthing is not running yet. You can launch it via %1.").arg(launchOptions.join(tr(" and "))));
|
|
|
|
} else {
|
|
|
|
setSubTitle(tr("Looks like Syncthing is not running yet and needs to be installed before Syncthing Tray can be configured."));
|
|
|
|
}
|
2022-08-23 18:19:47 +02:00
|
|
|
}
|
2022-08-27 23:35:15 +02:00
|
|
|
|
|
|
|
handleSelectionChanged();
|
2022-08-23 18:19:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainConfigWizardPage::cleanupPage()
|
|
|
|
{
|
2022-08-27 23:35:15 +02:00
|
|
|
wizard()->setOption(QWizard::HaveCustomButton1, false);
|
2022-08-23 18:19:47 +02:00
|
|
|
emit retry();
|
2022-08-22 23:48:18 +02:00
|
|
|
}
|
|
|
|
|
2022-09-03 21:32:44 +02:00
|
|
|
bool MainConfigWizardPage::validatePage()
|
|
|
|
{
|
|
|
|
auto mainConfig = MainConfiguration::None;
|
|
|
|
if (m_ui->cfgCurrentlyRunningRadioButton->isChecked()) {
|
|
|
|
mainConfig = MainConfiguration::CurrentlyRunning;
|
|
|
|
} else if (m_ui->cfgLauncherExternalRadioButton->isChecked()) {
|
|
|
|
mainConfig = MainConfiguration::LauncherExternal;
|
2022-09-03 21:35:44 +02:00
|
|
|
} else if (m_ui->cfgLauncherBuiltInRadioButton->isChecked()) {
|
2022-09-03 21:32:44 +02:00
|
|
|
mainConfig = MainConfiguration::LauncherBuiltIn;
|
2022-09-03 21:35:44 +02:00
|
|
|
} else if (m_ui->cfgSystemdUserUnitRadioButton) {
|
2022-09-03 21:32:44 +02:00
|
|
|
mainConfig = MainConfiguration::SystemdUserUnit;
|
2022-09-03 21:35:44 +02:00
|
|
|
} else if (m_ui->cfgSystemdSystemUnitRadioButton) {
|
2022-09-03 21:32:44 +02:00
|
|
|
mainConfig = MainConfiguration::SystemdSystemUnit;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto extraConfig = ExtraConfiguration::None;
|
|
|
|
CppUtilities::modFlagEnum(extraConfig, ExtraConfiguration::SystemdIntegration, m_ui->enableSystemdIntegrationCheckBox->isChecked());
|
|
|
|
|
|
|
|
emit configurationSelected(mainConfig, extraConfig);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-08-27 23:35:15 +02:00
|
|
|
void MainConfigWizardPage::handleSelectionChanged()
|
|
|
|
{
|
|
|
|
// enable/disable option for Systemd integration
|
|
|
|
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
|
|
|
|
if (m_ui->cfgCurrentlyRunningRadioButton->isVisible()) {
|
|
|
|
const auto &systemdSettings = Settings::values().systemd;
|
|
|
|
m_ui->enableSystemdIntegrationCheckBox->setEnabled(systemdSettings.showButton || systemdSettings.considerForReconnect);
|
|
|
|
} else {
|
2022-09-03 21:35:44 +02:00
|
|
|
if ((m_ui->cfgSystemdUserUnitRadioButton->isVisible() && m_ui->cfgSystemdUserUnitRadioButton->isChecked())
|
|
|
|
|| ((m_ui->cfgSystemdSystemUnitRadioButton->isVisible() && m_ui->cfgSystemdSystemUnitRadioButton->isChecked()))) {
|
2022-08-27 23:35:15 +02:00
|
|
|
m_ui->enableSystemdIntegrationCheckBox->setChecked(true);
|
|
|
|
m_ui->enableSystemdIntegrationCheckBox->setEnabled(true);
|
|
|
|
} else {
|
|
|
|
m_ui->enableSystemdIntegrationCheckBox->setChecked(false);
|
|
|
|
m_ui->enableSystemdIntegrationCheckBox->setEnabled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// set completed state according to selection
|
|
|
|
auto configSelected = false;
|
|
|
|
for (auto *const option : std::initializer_list<QRadioButton *>{ m_ui->cfgCurrentlyRunningRadioButton, m_ui->cfgLauncherExternalRadioButton,
|
2022-09-03 21:35:44 +02:00
|
|
|
m_ui->cfgLauncherBuiltInRadioButton, m_ui->cfgSystemdUserUnitRadioButton, m_ui->cfgSystemdSystemUnitRadioButton }) {
|
2022-08-27 23:35:15 +02:00
|
|
|
if ((configSelected = option->isChecked())) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
configSelected = configSelected || (m_ui->enableSystemdIntegrationCheckBox->isEnabled() && m_ui->enableSystemdIntegrationCheckBox->isChecked());
|
|
|
|
if (configSelected != m_configSelected) {
|
|
|
|
m_configSelected = configSelected;
|
|
|
|
emit completeChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-03 21:32:44 +02:00
|
|
|
AutostartWizardPage::AutostartWizardPage(QWidget *parent)
|
|
|
|
: QWizardPage(parent)
|
|
|
|
, m_ui(new Ui::AutostartWizardPage)
|
|
|
|
, m_configSelected(false)
|
|
|
|
{
|
|
|
|
setTitle(tr("Configure autostart"));
|
|
|
|
setSubTitle(tr("Select whether to start Syncthing Tray automatically"));
|
|
|
|
m_ui->setupUi(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
AutostartWizardPage::~AutostartWizardPage()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AutostartWizardPage::isComplete() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AutostartWizardPage::initializePage()
|
|
|
|
{
|
|
|
|
auto *const wizard = qobject_cast<Wizard *>(this->wizard());
|
|
|
|
if (!wizard) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto *const widget :
|
|
|
|
std::initializer_list<QWidget *>{ m_ui->launcherEnabledLabel, m_ui->systemdEnabledLabel, m_ui->launcherDisabledLabel }) {
|
|
|
|
widget->hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (wizard->mainConfig()) {
|
|
|
|
case MainConfiguration::None:
|
|
|
|
case MainConfiguration::CurrentlyRunning:
|
|
|
|
m_ui->launcherDisabledLabel->show();
|
|
|
|
break;
|
|
|
|
case MainConfiguration::LauncherExternal:
|
|
|
|
case MainConfiguration::LauncherBuiltIn:
|
|
|
|
m_ui->launcherEnabledLabel->show();
|
|
|
|
break;
|
|
|
|
case MainConfiguration::SystemdUserUnit:
|
|
|
|
case MainConfiguration::SystemdSystemUnit:
|
|
|
|
m_ui->systemdEnabledLabel->show();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AutostartWizardPage::cleanupPage()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AutostartWizardPage::validatePage()
|
|
|
|
{
|
|
|
|
emit autostartSelected(m_ui->enableAutostartCheckBox->isChecked());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-08-06 21:08:55 +02:00
|
|
|
} // namespace QtGui
|