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
|
||||
|
||||
int initSyncthingTray(bool windowed, bool waitForTray, const char *connectionConfig)
|
||||
int initSyncthingTray(bool windowed, bool waitForTray, const Argument &connectionConfigArg)
|
||||
{
|
||||
// get settings
|
||||
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
|
||||
if (windowed) {
|
||||
// launch Syncthing if configured
|
||||
settings.launcher.autostart();
|
||||
auto *const trayWidget = new TrayWidget();
|
||||
trayWidget->setAttribute(Qt::WA_DeleteOnClose);
|
||||
trayWidget->show();
|
||||
trayWidget->applySettings(connectionConfigQStr);
|
||||
|
||||
// show a window for each connection
|
||||
for (const auto *const connectionConfig : connectionConfigurations) {
|
||||
auto *const trayWidget = new TrayWidget();
|
||||
trayWidget->setAttribute(Qt::WA_DeleteOnClose);
|
||||
trayWidget->show();
|
||||
trayWidget->applySettings(QString::fromLocal8Bit(connectionConfig));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -76,22 +82,28 @@ int initSyncthingTray(bool windowed, bool waitForTray, const char *connectionCon
|
|||
return -1;
|
||||
}
|
||||
|
||||
// show tray icon
|
||||
// launch Syncthing if configured
|
||||
settings.launcher.autostart();
|
||||
auto *const trayIcon = new TrayIcon(connectionConfigQStr, QApplication::instance());
|
||||
trayIcon->show();
|
||||
if (!settings.firstLaunch) {
|
||||
return 0;
|
||||
|
||||
// show a tray icon for each connection
|
||||
TrayWidget *widget;
|
||||
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
|
||||
if (!settings.firstLaunch) {
|
||||
return 0;
|
||||
}
|
||||
QMessageBox msgBox;
|
||||
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.setInformativeText(QCoreApplication::translate(
|
||||
"main", "Note that the settings dialog allows importing URL, credentials and API-key from the local Syncthing configuration."));
|
||||
msgBox.exec();
|
||||
trayIcon->trayMenu().widget().showSettingsDialog();
|
||||
widget->showSettingsDialog();
|
||||
return 0;
|
||||
|
||||
#else
|
||||
|
@ -141,7 +153,8 @@ int runApplication(int argc, const char *const *argv)
|
|||
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");
|
||||
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();
|
||||
widgetsGuiArg.addSubArgument(&windowedArg);
|
||||
widgetsGuiArg.addSubArgument(&showWebUiArg);
|
||||
|
@ -181,7 +194,7 @@ int runApplication(int argc, const char *const *argv)
|
|||
#endif
|
||||
|
||||
// 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();
|
||||
return res;
|
||||
}
|
||||
|
@ -199,7 +212,7 @@ int runApplication(int argc, const char *const *argv)
|
|||
}
|
||||
|
||||
// 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) {
|
||||
trigger(triggerArg.isPresent(), showWebUiArg.isPresent());
|
||||
}
|
||||
|
|
|
@ -57,6 +57,7 @@ using namespace std;
|
|||
|
||||
namespace QtGui {
|
||||
|
||||
std::unique_ptr<QWidget> TrayWidget::s_dialogParent;
|
||||
SettingsDialog *TrayWidget::s_settingsDlg = nullptr;
|
||||
QtUtilities::AboutDialog *TrayWidget::s_aboutDlg = nullptr;
|
||||
vector<TrayWidget *> TrayWidget::s_instances;
|
||||
|
@ -214,11 +215,11 @@ TrayWidget::~TrayWidget()
|
|||
|
||||
void TrayWidget::showSettingsDialog()
|
||||
{
|
||||
if (!m_dialogParent) {
|
||||
m_dialogParent = make_unique<QWidget>();
|
||||
if (!s_dialogParent) {
|
||||
s_dialogParent = make_unique<QWidget>();
|
||||
}
|
||||
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);
|
||||
|
||||
// save settings to disk when applied
|
||||
|
@ -233,11 +234,11 @@ void TrayWidget::showSettingsDialog()
|
|||
|
||||
void TrayWidget::showAboutDialog()
|
||||
{
|
||||
if (!m_dialogParent) {
|
||||
m_dialogParent = make_unique<QWidget>();
|
||||
if (!s_dialogParent) {
|
||||
s_dialogParent = make_unique<QWidget>();
|
||||
}
|
||||
if (!s_aboutDlg) {
|
||||
s_aboutDlg = new AboutDialog(m_dialogParent.get(), QString(),
|
||||
s_aboutDlg = new AboutDialog(s_dialogParent.get(), QString(),
|
||||
QStringLiteral(
|
||||
"<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 "
|
||||
|
|
|
@ -105,8 +105,8 @@ private Q_SLOTS:
|
|||
|
||||
private:
|
||||
TrayMenu *m_menu;
|
||||
std::unique_ptr<QWidget> m_dialogParent;
|
||||
std::unique_ptr<Ui::TrayWidget> m_ui;
|
||||
static std::unique_ptr<QWidget> s_dialogParent;
|
||||
static SettingsDialog *s_settingsDlg;
|
||||
static QtUtilities::AboutDialog *s_aboutDlg;
|
||||
#ifndef SYNCTHINGWIDGETS_NO_WEBVIEW
|
||||
|
|
Loading…
Reference in New Issue