Allow specifiying multiple connection configurations
This commit is contained in:
parent
e509047367
commit
2c1dbff82b
|
@ -49,19 +49,25 @@ void handleSystemdServiceError(const QString &context, const QString &name, cons
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int initSyncthingTray(bool windowed, bool waitForTray, const char *connectionConfig)
|
int initSyncthingTray(bool windowed, bool waitForTray, const Argument &connectionConfigArg)
|
||||||
{
|
{
|
||||||
// get settings
|
// get settings
|
||||||
auto &settings = Settings::values();
|
auto &settings = Settings::values();
|
||||||
const auto connectionConfigQStr(connectionConfig ? QString::fromLocal8Bit(connectionConfig) : QString());
|
static const auto defaultConnection = std::vector<const char *>({""});
|
||||||
|
const auto &connectionConfigurations = connectionConfigArg.isPresent() && !connectionConfigArg.values().empty() ? connectionConfigArg.values() : defaultConnection;
|
||||||
|
|
||||||
// handle "windowed" case
|
// handle "windowed" case
|
||||||
if (windowed) {
|
if (windowed) {
|
||||||
|
// launch Syncthing if configured
|
||||||
settings.launcher.autostart();
|
settings.launcher.autostart();
|
||||||
auto *const trayWidget = new TrayWidget();
|
|
||||||
trayWidget->setAttribute(Qt::WA_DeleteOnClose);
|
// show a window for each connection
|
||||||
trayWidget->show();
|
for (const auto *const connectionConfig : connectionConfigurations) {
|
||||||
trayWidget->applySettings(connectionConfigQStr);
|
auto *const trayWidget = new TrayWidget();
|
||||||
|
trayWidget->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
|
trayWidget->show();
|
||||||
|
trayWidget->applySettings(QString::fromLocal8Bit(connectionConfig));
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,22 +82,28 @@ int initSyncthingTray(bool windowed, bool waitForTray, const char *connectionCon
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// show tray icon
|
// launch Syncthing if configured
|
||||||
settings.launcher.autostart();
|
settings.launcher.autostart();
|
||||||
auto *const trayIcon = new TrayIcon(connectionConfigQStr, QApplication::instance());
|
|
||||||
trayIcon->show();
|
// show a tray icon for each connection
|
||||||
if (!settings.firstLaunch) {
|
TrayWidget *widget;
|
||||||
return 0;
|
for (const auto *const connectionConfig : connectionConfigurations) {
|
||||||
|
auto *const trayIcon = new TrayIcon(QString::fromLocal8Bit(connectionConfig), QApplication::instance());
|
||||||
|
trayIcon->show();
|
||||||
|
widget = &trayIcon->trayMenu().widget();
|
||||||
}
|
}
|
||||||
|
|
||||||
// show "first launch" message box
|
// show "first launch" message box
|
||||||
|
if (!settings.firstLaunch) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
QMessageBox msgBox;
|
QMessageBox msgBox;
|
||||||
msgBox.setIcon(QMessageBox::Information);
|
msgBox.setIcon(QMessageBox::Information);
|
||||||
msgBox.setText(QCoreApplication::translate("main", "You must configure how to connect to Syncthing when using Syncthing Tray the first time."));
|
msgBox.setText(QCoreApplication::translate("main", "You must configure how to connect to Syncthing when using Syncthing Tray the first time."));
|
||||||
msgBox.setInformativeText(QCoreApplication::translate(
|
msgBox.setInformativeText(QCoreApplication::translate(
|
||||||
"main", "Note that the settings dialog allows importing URL, credentials and API-key from the local Syncthing configuration."));
|
"main", "Note that the settings dialog allows importing URL, credentials and API-key from the local Syncthing configuration."));
|
||||||
msgBox.exec();
|
msgBox.exec();
|
||||||
trayIcon->trayMenu().widget().showSettingsDialog();
|
widget->showSettingsDialog();
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
@ -141,7 +153,8 @@ int runApplication(int argc, const char *const *argv)
|
||||||
Argument waitForTrayArg("wait", '\0',
|
Argument waitForTrayArg("wait", '\0',
|
||||||
"wait until the system tray becomes available instead of showing an error message if the system tray is not available on start-up");
|
"wait until the system tray becomes available instead of showing an error message if the system tray is not available on start-up");
|
||||||
waitForTrayArg.setCombinable(true);
|
waitForTrayArg.setCombinable(true);
|
||||||
ConfigValueArgument connectionArg("connection", '\0', "specifies the connection configuration to be used", { "config name" });
|
ConfigValueArgument connectionArg("connection", '\0', "specifies one or more connection configurations to be used", { "config name" });
|
||||||
|
connectionArg.setRequiredValueCount(Argument::varValueCount);
|
||||||
Argument &widgetsGuiArg = qtConfigArgs.qtWidgetsGuiArg();
|
Argument &widgetsGuiArg = qtConfigArgs.qtWidgetsGuiArg();
|
||||||
widgetsGuiArg.addSubArgument(&windowedArg);
|
widgetsGuiArg.addSubArgument(&windowedArg);
|
||||||
widgetsGuiArg.addSubArgument(&showWebUiArg);
|
widgetsGuiArg.addSubArgument(&showWebUiArg);
|
||||||
|
@ -181,7 +194,7 @@ int runApplication(int argc, const char *const *argv)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// init Syncthing Tray and immediately shutdown on failure
|
// init Syncthing Tray and immediately shutdown on failure
|
||||||
if (const auto res = initSyncthingTray(windowedArg.isPresent(), waitForTrayArg.isPresent(), connectionArg.firstValue())) {
|
if (const auto res = initSyncthingTray(windowedArg.isPresent(), waitForTrayArg.isPresent(), connectionArg)) {
|
||||||
shutdownSyncthingTray();
|
shutdownSyncthingTray();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -199,7 +212,7 @@ int runApplication(int argc, const char *const *argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
// create new/additional tray icon
|
// create new/additional tray icon
|
||||||
const auto res = initSyncthingTray(windowedArg.isPresent(), waitForTrayArg.isPresent(), connectionArg.firstValue());
|
const auto res = initSyncthingTray(windowedArg.isPresent(), waitForTrayArg.isPresent(), connectionArg);
|
||||||
if (!res) {
|
if (!res) {
|
||||||
trigger(triggerArg.isPresent(), showWebUiArg.isPresent());
|
trigger(triggerArg.isPresent(), showWebUiArg.isPresent());
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,6 +57,7 @@ using namespace std;
|
||||||
|
|
||||||
namespace QtGui {
|
namespace QtGui {
|
||||||
|
|
||||||
|
std::unique_ptr<QWidget> TrayWidget::s_dialogParent;
|
||||||
SettingsDialog *TrayWidget::s_settingsDlg = nullptr;
|
SettingsDialog *TrayWidget::s_settingsDlg = nullptr;
|
||||||
QtUtilities::AboutDialog *TrayWidget::s_aboutDlg = nullptr;
|
QtUtilities::AboutDialog *TrayWidget::s_aboutDlg = nullptr;
|
||||||
vector<TrayWidget *> TrayWidget::s_instances;
|
vector<TrayWidget *> TrayWidget::s_instances;
|
||||||
|
@ -214,11 +215,11 @@ TrayWidget::~TrayWidget()
|
||||||
|
|
||||||
void TrayWidget::showSettingsDialog()
|
void TrayWidget::showSettingsDialog()
|
||||||
{
|
{
|
||||||
if (!m_dialogParent) {
|
if (!s_dialogParent) {
|
||||||
m_dialogParent = make_unique<QWidget>();
|
s_dialogParent = make_unique<QWidget>();
|
||||||
}
|
}
|
||||||
if (!s_settingsDlg) {
|
if (!s_settingsDlg) {
|
||||||
s_settingsDlg = new SettingsDialog(&m_connection, m_dialogParent.get());
|
s_settingsDlg = new SettingsDialog(&m_connection, s_dialogParent.get());
|
||||||
connect(s_settingsDlg, &SettingsDialog::applied, &TrayWidget::applySettingsOnAllInstances);
|
connect(s_settingsDlg, &SettingsDialog::applied, &TrayWidget::applySettingsOnAllInstances);
|
||||||
|
|
||||||
// save settings to disk when applied
|
// save settings to disk when applied
|
||||||
|
@ -233,11 +234,11 @@ void TrayWidget::showSettingsDialog()
|
||||||
|
|
||||||
void TrayWidget::showAboutDialog()
|
void TrayWidget::showAboutDialog()
|
||||||
{
|
{
|
||||||
if (!m_dialogParent) {
|
if (!s_dialogParent) {
|
||||||
m_dialogParent = make_unique<QWidget>();
|
s_dialogParent = make_unique<QWidget>();
|
||||||
}
|
}
|
||||||
if (!s_aboutDlg) {
|
if (!s_aboutDlg) {
|
||||||
s_aboutDlg = new AboutDialog(m_dialogParent.get(), QString(),
|
s_aboutDlg = new AboutDialog(s_dialogParent.get(), QString(),
|
||||||
QStringLiteral(
|
QStringLiteral(
|
||||||
"<p>Developed by " APP_AUTHOR
|
"<p>Developed by " APP_AUTHOR
|
||||||
"<br>Fallback icons from KDE/Breeze project<br>Syncthing icons from <a href=\"https://syncthing.net\">Syncthing project</a><br>Using "
|
"<br>Fallback icons from KDE/Breeze project<br>Syncthing icons from <a href=\"https://syncthing.net\">Syncthing project</a><br>Using "
|
||||||
|
|
|
@ -105,8 +105,8 @@ private Q_SLOTS:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TrayMenu *m_menu;
|
TrayMenu *m_menu;
|
||||||
std::unique_ptr<QWidget> m_dialogParent;
|
|
||||||
std::unique_ptr<Ui::TrayWidget> m_ui;
|
std::unique_ptr<Ui::TrayWidget> m_ui;
|
||||||
|
static std::unique_ptr<QWidget> s_dialogParent;
|
||||||
static SettingsDialog *s_settingsDlg;
|
static SettingsDialog *s_settingsDlg;
|
||||||
static QtUtilities::AboutDialog *s_aboutDlg;
|
static QtUtilities::AboutDialog *s_aboutDlg;
|
||||||
#ifndef SYNCTHINGWIDGETS_NO_WEBVIEW
|
#ifndef SYNCTHINGWIDGETS_NO_WEBVIEW
|
||||||
|
|
Loading…
Reference in New Issue