Allow opening wizard from Plasmoid
This commit is contained in:
parent
63acf60cd8
commit
5fd07ee1c0
|
@ -10,6 +10,7 @@
|
|||
#include <syncthingwidgets/misc/textviewdialog.h>
|
||||
#include <syncthingwidgets/settings/settings.h>
|
||||
#include <syncthingwidgets/settings/settingsdialog.h>
|
||||
#include <syncthingwidgets/settings/wizard.h>
|
||||
#include <syncthingwidgets/webview/webviewdialog.h>
|
||||
|
||||
#include <syncthingmodel/syncthingicons.h>
|
||||
|
@ -80,6 +81,7 @@ SyncthingApplet::SyncthingApplet(QObject *parent, const QVariantList &data)
|
|||
, m_downloadModel(m_connection)
|
||||
, m_recentChangesModel(m_connection)
|
||||
, m_settingsDlg(nullptr)
|
||||
, m_wizard(nullptr)
|
||||
, m_imageProvider(nullptr)
|
||||
#ifndef SYNCTHINGWIDGETS_NO_WEBVIEW
|
||||
, m_webViewDlg(nullptr)
|
||||
|
@ -88,6 +90,7 @@ SyncthingApplet::SyncthingApplet(QObject *parent, const QVariantList &data)
|
|||
, m_hasInternalErrors(false)
|
||||
, m_initialized(false)
|
||||
, m_showTabTexts(false)
|
||||
, m_applyingSettingsForWizard(false)
|
||||
{
|
||||
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
|
||||
m_notifier.setService(&m_service);
|
||||
|
@ -271,6 +274,8 @@ void SyncthingApplet::setCurrentConnectionConfigIndex(int index)
|
|||
#endif
|
||||
if (!systemdConsideredForReconnect && (reconnectRequired || !m_connection.isConnected())) {
|
||||
m_connection.reconnect();
|
||||
} else {
|
||||
concludeWizard();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -329,6 +334,8 @@ void SyncthingApplet::showSettingsDlg()
|
|||
{
|
||||
if (!m_settingsDlg) {
|
||||
m_settingsDlg = new SettingsDialog(*this);
|
||||
// show wizard when requested
|
||||
connect(m_settingsDlg, &SettingsDialog::wizardRequested, this, &SyncthingApplet::showWizard);
|
||||
// ensure settings take effect when applied
|
||||
connect(m_settingsDlg, &SettingsDialog::applied, this, &SyncthingApplet::handleSettingsChanged);
|
||||
// save plasmoid specific settings to disk when applied
|
||||
|
@ -341,6 +348,43 @@ void SyncthingApplet::showSettingsDlg()
|
|||
m_settingsDlg->activateWindow();
|
||||
}
|
||||
|
||||
void SyncthingApplet::showWizard()
|
||||
{
|
||||
if (!m_wizard) {
|
||||
m_wizard = Wizard::instance();
|
||||
connect(m_wizard, &Wizard::destroyed, this, [this] { m_wizard = nullptr; });
|
||||
connect(m_wizard, &Wizard::settingsDialogRequested, this, &SyncthingApplet::showSettingsDlg);
|
||||
connect(m_wizard, &Wizard::openSyncthingRequested, this, &SyncthingApplet::showWebUI);
|
||||
connect(m_wizard, &Wizard::settingsChanged, this, &SyncthingApplet::applySettingsChangesFromWizard);
|
||||
}
|
||||
centerWidget(m_wizard);
|
||||
m_wizard->show();
|
||||
m_wizard->activateWindow();
|
||||
}
|
||||
|
||||
void SyncthingApplet::applySettingsChangesFromWizard()
|
||||
{
|
||||
// reset possibly opened settings dialog to be consistent with new configuration
|
||||
if (m_settingsDlg) {
|
||||
m_settingsDlg->reset();
|
||||
}
|
||||
|
||||
// ensure first connection is selected as this is the connection the wizard configures
|
||||
m_applyingSettingsForWizard = true;
|
||||
applySettings(0);
|
||||
}
|
||||
|
||||
void SyncthingApplet::concludeWizard(const QString &errorMessage)
|
||||
{
|
||||
if (!m_applyingSettingsForWizard) {
|
||||
return;
|
||||
}
|
||||
m_applyingSettingsForWizard = false;
|
||||
if (m_wizard) {
|
||||
m_wizard->handleConfigurationApplied(errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
void SyncthingApplet::showWebUI()
|
||||
{
|
||||
#ifndef SYNCTHINGWIDGETS_NO_WEBVIEW
|
||||
|
@ -450,36 +494,7 @@ void SyncthingApplet::copyToClipboard(const QString &text)
|
|||
*/
|
||||
void SyncthingApplet::handleSettingsChanged()
|
||||
{
|
||||
const KConfigGroup config(this->config());
|
||||
const auto &settings(Settings::values());
|
||||
|
||||
// apply notifiction settings
|
||||
settings.apply(m_notifier);
|
||||
|
||||
// apply appearance settings
|
||||
setSize(config.readEntry<QSize>("size", QSize(25, 25)));
|
||||
setShowingTabTexts(config.readEntry<bool>("showTabTexts", false));
|
||||
IconManager::instance().applySettings(&settings.icons.status);
|
||||
|
||||
// restore selected states
|
||||
// note: The settings dialog writes this to the Plasmoid's config like the other settings. However, it
|
||||
// is simpler and more efficient to assign the states directly. Of course this is only possible if
|
||||
// the dialog has already been shown.
|
||||
if (m_settingsDlg) {
|
||||
setPassiveStates(m_settingsDlg->appearanceOptionPage()->passiveStatusSelection()->items());
|
||||
} else {
|
||||
m_passiveSelectionModel.applyVariantList(config.readEntry("passiveStates", QVariantList()));
|
||||
}
|
||||
|
||||
// apply connection config
|
||||
const int currentConfig = m_currentConnectionConfig;
|
||||
m_currentConnectionConfig = -1; // force update
|
||||
setCurrentConnectionConfigIndex(currentConfig);
|
||||
|
||||
// update status icons and tooltip because the reconnect interval might have changed
|
||||
updateStatusIconAndTooltip();
|
||||
|
||||
emit settingsChanged();
|
||||
applySettings();
|
||||
}
|
||||
|
||||
void SyncthingApplet::handleConnectionStatusChanged(Data::SyncthingStatus previousStatus, Data::SyncthingStatus newStatus)
|
||||
|
@ -491,6 +506,18 @@ void SyncthingApplet::handleConnectionStatusChanged(Data::SyncthingStatus previo
|
|||
|
||||
setPassive(static_cast<int>(newStatus) < passiveStates().size() && passiveStates().at(static_cast<int>(newStatus)).isChecked());
|
||||
updateStatusIconAndTooltip();
|
||||
|
||||
if (m_applyingSettingsForWizard) {
|
||||
switch (newStatus) {
|
||||
case SyncthingStatus::Disconnected:
|
||||
concludeWizard(tr("Unable to establish connection to Syncthing."));
|
||||
break;
|
||||
case SyncthingStatus::Reconnecting:
|
||||
break;
|
||||
default:
|
||||
concludeWizard();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SyncthingApplet::handleDevicesChanged()
|
||||
|
@ -587,6 +614,40 @@ void SyncthingApplet::setBrightColors(bool brightColors)
|
|||
m_recentChangesModel.setBrightColors(brightColors);
|
||||
}
|
||||
|
||||
void SyncthingApplet::applySettings(int changeConnectionIndex)
|
||||
{
|
||||
const KConfigGroup config = this->config();
|
||||
const auto &settings = Settings::values();
|
||||
|
||||
// apply notifiction settings
|
||||
settings.apply(m_notifier);
|
||||
|
||||
// apply appearance settings
|
||||
setSize(config.readEntry<QSize>("size", QSize(25, 25)));
|
||||
setShowingTabTexts(config.readEntry<bool>("showTabTexts", false));
|
||||
IconManager::instance().applySettings(&settings.icons.status);
|
||||
|
||||
// restore selected states
|
||||
// note: The settings dialog writes this to the Plasmoid's config like the other settings. However, it
|
||||
// is simpler and more efficient to assign the states directly. Of course this is only possible if
|
||||
// the dialog has already been shown.
|
||||
if (m_settingsDlg) {
|
||||
setPassiveStates(m_settingsDlg->appearanceOptionPage()->passiveStatusSelection()->items());
|
||||
} else {
|
||||
m_passiveSelectionModel.applyVariantList(config.readEntry("passiveStates", QVariantList()));
|
||||
}
|
||||
|
||||
// apply connection config
|
||||
const int newConfig = changeConnectionIndex < 0 ? m_currentConnectionConfig : changeConnectionIndex;
|
||||
m_currentConnectionConfig = -1; // force update
|
||||
setCurrentConnectionConfigIndex(newConfig);
|
||||
|
||||
// update status icons and tooltip because the reconnect interval might have changed
|
||||
updateStatusIconAndTooltip();
|
||||
|
||||
emit settingsChanged();
|
||||
}
|
||||
|
||||
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
|
||||
void SyncthingApplet::handleSystemdStatusChanged()
|
||||
{
|
||||
|
|
|
@ -36,7 +36,8 @@ class IconManager;
|
|||
|
||||
namespace QtGui {
|
||||
class WebViewDialog;
|
||||
}
|
||||
class Wizard;
|
||||
} // namespace QtGui
|
||||
|
||||
namespace QtForkAwesome {
|
||||
class QuickImageProvider;
|
||||
|
@ -127,6 +128,7 @@ public Q_SLOTS:
|
|||
void init() override;
|
||||
void initEngine(QObject *object);
|
||||
void showSettingsDlg();
|
||||
void showWizard();
|
||||
void showWebUI();
|
||||
void showLog();
|
||||
void showOwnDeviceId();
|
||||
|
@ -190,6 +192,9 @@ private Q_SLOTS:
|
|||
void handleThemeChanged();
|
||||
void setPassive(bool passive);
|
||||
void setBrightColors(bool brightColors);
|
||||
void applySettings(int changeConnectionIndex = -1);
|
||||
void applySettingsChangesFromWizard();
|
||||
void concludeWizard(const QString &errorMessage = QString());
|
||||
|
||||
private:
|
||||
Plasma::Theme m_theme;
|
||||
|
@ -212,6 +217,7 @@ private:
|
|||
Data::SyncthingRecentChangesModel m_recentChangesModel;
|
||||
Data::SyncthingStatusSelectionModel m_passiveSelectionModel;
|
||||
SettingsDialog *m_settingsDlg;
|
||||
QtGui::Wizard *m_wizard;
|
||||
QtGui::DBusStatusNotifier m_dbusNotifier;
|
||||
std::vector<Data::SyncthingLogEntry> m_notifications;
|
||||
QtForkAwesome::QuickImageProvider *m_imageProvider;
|
||||
|
@ -222,6 +228,7 @@ private:
|
|||
bool m_hasInternalErrors;
|
||||
bool m_initialized;
|
||||
bool m_showTabTexts;
|
||||
bool m_applyingSettingsForWizard;
|
||||
QSize m_size;
|
||||
};
|
||||
|
||||
|
|
|
@ -61,15 +61,15 @@ Wizard::Wizard(QWidget *parent, Qt::WindowFlags flags)
|
|||
connect(mainConfigPage, &MainConfigWizardPage::configurationSelected, this, &Wizard::handleConfigurationSelected);
|
||||
connect(this, &Wizard::configApplied, finalPage, &FinalWizardPage::completeChanged);
|
||||
connect(this, &Wizard::configApplied, finalPage, &FinalWizardPage::showResults);
|
||||
#ifdef SETTINGS_WIZARD_AUTOSTART
|
||||
auto *const autostartPage = new AutostartWizardPage(this);
|
||||
connect(autostartPage, &AutostartWizardPage::autostartSelected, this, &Wizard::handleAutostartSelected);
|
||||
#endif
|
||||
addPage(welcomePage);
|
||||
addPage(detectionPage);
|
||||
addPage(mainConfigPage);
|
||||
#ifdef SETTINGS_WIZARD_AUTOSTART
|
||||
addPage(autostartPage);
|
||||
if (!Settings::values().isPlasmoid) {
|
||||
auto *const autostartPage = new AutostartWizardPage(this);
|
||||
connect(autostartPage, &AutostartWizardPage::autostartSelected, this, &Wizard::handleAutostartSelected);
|
||||
addPage(autostartPage);
|
||||
}
|
||||
#endif
|
||||
addPage(applyPage);
|
||||
addPage(finalPage);
|
||||
|
@ -642,7 +642,7 @@ void MainConfigWizardPage::initializePage()
|
|||
|
||||
// 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()) {
|
||||
if (!Settings::values().isPlasmoid && (successfulTestLaunch || Data::SyncthingLauncher::isLibSyncthingAvailable())) {
|
||||
launchOptions << tr("Syncthing Tray's launcher");
|
||||
if (successfulTestLaunch) {
|
||||
m_ui->cfgLauncherExternalRadioButton->show();
|
||||
|
|
Loading…
Reference in New Issue