diff --git a/include/syncthing b/include/syncthing new file mode 120000 index 0000000..a1d8d5f --- /dev/null +++ b/include/syncthing @@ -0,0 +1 @@ +../libsyncthing \ No newline at end of file diff --git a/widgets/CMakeLists.txt b/widgets/CMakeLists.txt index 1a6bc38..a169bf7 100644 --- a/widgets/CMakeLists.txt +++ b/widgets/CMakeLists.txt @@ -90,7 +90,7 @@ option(USE_LIBSYNCTHING "whether libsyncthing should be included for the launche if (USE_LIBSYNCTHING) find_package(syncthing ${META_APP_VERSION} REQUIRED) use_syncthing() - set_source_files_properties(misc/syncthinglauncher.cpp PROPERTIES COMPILE_DEFINITIONS SYNCTHINGWIDGETS_USE_LIBSYNCTHING) + list(APPEND META_PUBLIC_COMPILE_DEFINITIONS SYNCTHINGWIDGETS_USE_LIBSYNCTHING) endif () # configure logging JavaScript events to stderr diff --git a/widgets/misc/syncthinglauncher.cpp b/widgets/misc/syncthinglauncher.cpp index 8876175..3b89f90 100644 --- a/widgets/misc/syncthinglauncher.cpp +++ b/widgets/misc/syncthinglauncher.cpp @@ -30,7 +30,9 @@ SyncthingLauncher *SyncthingLauncher::s_mainInstance = nullptr; */ SyncthingLauncher::SyncthingLauncher(QObject *parent) : QObject(parent) +#ifdef SYNCTHINGWIDGETS_USE_LIBSYNCTHING , m_libsyncthingLogLevel(LibSyncthing::LogLevel::Info) +#endif , m_manuallyStopped(true) , m_emittingOutput(false) { @@ -100,8 +102,12 @@ void SyncthingLauncher::launch(const QString &program, const QStringList &argume return; } +#ifdef SYNCTHINGWIDGETS_USE_LIBSYNCTHING // use libsyncthing m_startFuture = QtConcurrent::run(std::bind(&SyncthingLauncher::runLibSyncthing, this, LibSyncthing::RuntimeOptions{})); +#else + showLibSyncthingNotSupported(); +#endif } /*! @@ -118,16 +124,21 @@ void SyncthingLauncher::launch(const Settings::Launcher &launcherSettings) return; } if (launcherSettings.useLibSyncthing) { +#ifdef SYNCTHINGWIDGETS_USE_LIBSYNCTHING LibSyncthing::RuntimeOptions options; options.configDir = launcherSettings.libSyncthing.configDir.toStdString(); options.dataDir = launcherSettings.libSyncthing.configDir.toStdString(); setLibSyncthingLogLevel(launcherSettings.libSyncthing.logLevel); launch(options); +#else + showLibSyncthingNotSupported(); +#endif } else { launch(launcherSettings.syncthingPath, SyncthingProcess::splitArguments(launcherSettings.syncthingArgs)); } } +#ifdef SYNCTHINGWIDGETS_USE_LIBSYNCTHING /*! * \brief Launches a Syncthing instance using the internal library with the specified \a runtimeOptions. * \remarks Does nothing if already running an instance. @@ -140,6 +151,7 @@ void SyncthingLauncher::launch(const LibSyncthing::RuntimeOptions &runtimeOption m_manuallyStopped = false; m_startFuture = QtConcurrent::run(std::bind(&SyncthingLauncher::runLibSyncthing, this, runtimeOptions)); } +#endif void SyncthingLauncher::terminate() { @@ -203,11 +215,9 @@ static const char *const logLevelStrings[] = { "[WARNING] ", "[FATAL] ", }; -#endif void SyncthingLauncher::handleLoggingCallback(LibSyncthing::LogLevel level, const char *message, size_t messageSize) { -#ifdef SYNCTHINGWIDGETS_USE_LIBSYNCTHING if (level < m_libsyncthingLogLevel) { return; } @@ -219,12 +229,8 @@ void SyncthingLauncher::handleLoggingCallback(LibSyncthing::LogLevel level, cons messageData.append('\n'); handleOutputAvailable(move(messageData)); -#else - CPP_UTILITIES_UNUSED(level) - CPP_UTILITIES_UNUSED(message) - CPP_UTILITIES_UNUSED(messageSize) -#endif } +#endif void SyncthingLauncher::handleOutputAvailable(QByteArray &&data) { @@ -235,27 +241,29 @@ void SyncthingLauncher::handleOutputAvailable(QByteArray &&data) } } +#ifdef SYNCTHINGWIDGETS_USE_LIBSYNCTHING void SyncthingLauncher::runLibSyncthing(const LibSyncthing::RuntimeOptions &runtimeOptions) { -#ifdef SYNCTHINGWIDGETS_USE_LIBSYNCTHING LibSyncthing::setLoggingCallback(bind(&SyncthingLauncher::handleLoggingCallback, this, _1, _2, _3)); emit runningChanged(true); const auto exitCode = LibSyncthing::runSyncthing(runtimeOptions); emit exited(static_cast(exitCode), exitCode == 0 ? QProcess::NormalExit : QProcess::CrashExit); emit runningChanged(false); -#else - CPP_UTILITIES_UNUSED(runtimeOptions) - handleOutputAvailable(QByteArray("libsyncthing support not enabled")); - emit exited(-1, QProcess::CrashExit); -#endif } void SyncthingLauncher::stopLibSyncthing() { -#ifdef SYNCTHINGWIDGETS_USE_LIBSYNCTHING LibSyncthing::stopSyncthing(); // no need to emit exited/runningChanged here; that is already done in runLibSyncthing() -#endif } +#else +void SyncthingLauncher::showLibSyncthingNotSupported() +{ + handleOutputAvailable(QByteArray("libsyncthing support not enabled")); + emit exited(-1, QProcess::CrashExit); +} +#endif + + } // namespace Data diff --git a/widgets/misc/syncthinglauncher.h b/widgets/misc/syncthinglauncher.h index 2e2a5a3..3e14439 100644 --- a/widgets/misc/syncthinglauncher.h +++ b/widgets/misc/syncthinglauncher.h @@ -3,16 +3,15 @@ #include "../global.h" +#ifdef SYNCTHINGWIDGETS_USE_LIBSYNCTHING +#include +#endif + #include -#include "../../libsyncthing/interface.h" #include #include -namespace LibSyncthing { -struct RuntimeOptions; -} - namespace Settings { struct Launcher; } @@ -35,12 +34,17 @@ public: bool isManuallyStopped() const; bool isEmittingOutput() const; void setEmittingOutput(bool emittingOutput); +#ifdef SYNCTHINGWIDGETS_USE_LIBSYNCTHING LibSyncthing::LogLevel libSyncthingLogLevel() const; void setLibSyncthingLogLevel(LibSyncthing::LogLevel logLevel); +#endif static bool isLibSyncthingAvailable(); static SyncthingLauncher *mainInstance(); static void setMainInstance(SyncthingLauncher *mainInstance); static QString libSyncthingVersionInfo(); +#ifdef SYNCTHINGWIDGETS_USE_LIBSYNCTHING + void launch(const LibSyncthing::RuntimeOptions &runtimeOptions); +#endif Q_SIGNALS: void confirmKill(); @@ -52,7 +56,6 @@ Q_SIGNALS: public Q_SLOTS: void launch(const QString &program, const QStringList &arguments); void launch(const Settings::Launcher &launcherSettings); - void launch(const LibSyncthing::RuntimeOptions &runtimeOptions); void terminate(); void kill(); void tearDownLibSyncthing(); @@ -61,11 +64,17 @@ private Q_SLOTS: void handleProcessReadyRead(); void handleProcessStateChanged(QProcess::ProcessState newState); void handleProcessFinished(int exitCode, QProcess::ExitStatus exitStatus); - void handleLoggingCallback(LibSyncthing::LogLevel, const char *message, std::size_t messageSize); +#ifdef SYNCTHINGWIDGETS_USE_LIBSYNCTHING void runLibSyncthing(const LibSyncthing::RuntimeOptions &runtimeOptions); void stopLibSyncthing(); +#else + void showLibSyncthingNotSupported(); +#endif private: +#ifdef SYNCTHINGWIDGETS_USE_LIBSYNCTHING + void handleLoggingCallback(LibSyncthing::LogLevel, const char *message, std::size_t messageSize); +#endif void handleOutputAvailable(QByteArray &&data); SyncthingProcess m_process; @@ -73,7 +82,9 @@ private: QFuture m_stopFuture; QByteArray m_outputBuffer; CppUtilities::DateTime m_futureStarted; +#ifdef SYNCTHINGWIDGETS_USE_LIBSYNCTHING LibSyncthing::LogLevel m_libsyncthingLogLevel; +#endif bool m_manuallyStopped; bool m_emittingOutput; bool m_useLibSyncthing; @@ -118,6 +129,7 @@ inline bool SyncthingLauncher::isEmittingOutput() const return m_emittingOutput; } +#ifdef SYNCTHINGWIDGETS_USE_LIBSYNCTHING /// \brief Returns the log level used for libsyncthing. inline LibSyncthing::LogLevel SyncthingLauncher::libSyncthingLogLevel() const { @@ -129,6 +141,7 @@ inline void SyncthingLauncher::setLibSyncthingLogLevel(LibSyncthing::LogLevel lo { m_libsyncthingLogLevel = logLevel; } +#endif /// \brief Returns the SyncthingLauncher instance previously assigned via SyncthingLauncher::setMainInstance(). inline SyncthingLauncher *SyncthingLauncher::mainInstance() diff --git a/widgets/settings/settings.cpp b/widgets/settings/settings.cpp index 2ccf28a..1176ed1 100644 --- a/widgets/settings/settings.cpp +++ b/widgets/settings/settings.cpp @@ -301,10 +301,12 @@ void restore() auto &launcher = v.launcher; launcher.autostartEnabled = settings.value(QStringLiteral("syncthingAutostart"), launcher.autostartEnabled).toBool(); launcher.useLibSyncthing = settings.value(QStringLiteral("useLibSyncthing"), launcher.useLibSyncthing).toBool(); +#ifdef SYNCTHINGWIDGETS_USE_LIBSYNCTHING launcher.libSyncthing.configDir = settings.value(QStringLiteral("libSyncthingConfigDir"), launcher.libSyncthing.configDir).toString(); launcher.libSyncthing.dataDir = settings.value(QStringLiteral("libSyncthingDataDir"), launcher.libSyncthing.dataDir).toString(); launcher.libSyncthing.logLevel = static_cast( settings.value(QStringLiteral("libSyncthingLogLevel"), static_cast(launcher.libSyncthing.logLevel)).toInt()); +#endif launcher.syncthingPath = settings.value(QStringLiteral("syncthingPath"), launcher.syncthingPath).toString(); launcher.syncthingArgs = settings.value(QStringLiteral("syncthingArgs"), launcher.syncthingArgs).toString(); launcher.considerForReconnect = settings.value(QStringLiteral("considerLauncherForReconnect"), launcher.considerForReconnect).toBool(); @@ -406,9 +408,11 @@ void save() const auto &launcher = v.launcher; settings.setValue(QStringLiteral("syncthingAutostart"), launcher.autostartEnabled); settings.setValue(QStringLiteral("useLibSyncthing"), launcher.useLibSyncthing); +#ifdef SYNCTHINGWIDGETS_USE_LIBSYNCTHING settings.setValue(QStringLiteral("libSyncthingConfigDir"), launcher.libSyncthing.configDir); settings.setValue(QStringLiteral("libSyncthingDataDir"), launcher.libSyncthing.dataDir); settings.setValue(QStringLiteral("libSyncthingLogLevel"), static_cast(launcher.libSyncthing.logLevel)); +#endif settings.setValue(QStringLiteral("syncthingPath"), launcher.syncthingPath); settings.setValue(QStringLiteral("syncthingArgs"), launcher.syncthingArgs); settings.setValue(QStringLiteral("considerLauncherForReconnect"), launcher.considerForReconnect); diff --git a/widgets/settings/settings.h b/widgets/settings/settings.h index 335529d..6ecd989 100644 --- a/widgets/settings/settings.h +++ b/widgets/settings/settings.h @@ -1,11 +1,15 @@ #ifndef SETTINGS_H #define SETTINGS_H -#include -#include "../../libsyncthing/interface.h" -#include #include "../global.h" +#ifdef SYNCTHINGWIDGETS_USE_LIBSYNCTHING +#include +#endif + +#include +#include + #include #include @@ -81,11 +85,13 @@ struct SYNCTHINGWIDGETS_EXPORT Launcher { bool considerForReconnect = false; bool showButton = false; +#ifdef SYNCTHINGWIDGETS_USE_LIBSYNCTHING struct SYNCTHINGWIDGETS_EXPORT LibSyncthing { QString configDir; QString dataDir; ::LibSyncthing::LogLevel logLevel = ::LibSyncthing::LogLevel::Info; } libSyncthing; +#endif static Data::SyncthingProcess &toolProcess(const QString &tool); static std::vector allProcesses(); diff --git a/widgets/settings/settingsdialog.cpp b/widgets/settings/settingsdialog.cpp index 961b6e6..54b6884 100644 --- a/widgets/settings/settingsdialog.cpp +++ b/widgets/settings/settingsdialog.cpp @@ -950,8 +950,10 @@ QWidget *LauncherOptionPage::setupWidget() connect(m_launcher, &SyncthingLauncher::outputAvailable, this, &LauncherOptionPage::handleSyncthingOutputAvailable, Qt::QueuedConnection); connect(m_launcher, &SyncthingLauncher::exited, this, &LauncherOptionPage::handleSyncthingExited, Qt::QueuedConnection); connect(m_launcher, &SyncthingLauncher::errorOccurred, this, &LauncherOptionPage::handleSyncthingError, Qt::QueuedConnection); +#ifdef SYNCTHINGWIDGETS_USE_LIBSYNCTHING connect(ui()->logLevelComboBox, static_cast(&QComboBox::currentIndexChanged), this, &LauncherOptionPage::updateLibSyncthingLogLevel); +#endif m_launcher->setEmittingOutput(true); } connect(ui()->launchNowPushButton, &QPushButton::clicked, this, &LauncherOptionPage::launch); @@ -966,9 +968,11 @@ bool LauncherOptionPage::apply() if (m_tool.isEmpty()) { settings.autostartEnabled = ui()->enabledCheckBox->isChecked(); settings.useLibSyncthing = ui()->useBuiltInVersionCheckBox->isChecked(); +#ifdef SYNCTHINGWIDGETS_USE_LIBSYNCTHING settings.libSyncthing.configDir = ui()->configDirPathSelection->lineEdit()->text(); settings.libSyncthing.dataDir = ui()->dataDirPathSelection->lineEdit()->text(); settings.libSyncthing.logLevel = static_cast(ui()->logLevelComboBox->currentIndex()); +#endif settings.syncthingPath = ui()->syncthingPathSelection->lineEdit()->text(); settings.syncthingArgs = ui()->argumentsLineEdit->text(); settings.considerForReconnect = ui()->considerForReconnectCheckBox->isChecked(); @@ -989,9 +993,11 @@ void LauncherOptionPage::reset() ui()->enabledCheckBox->setChecked(settings.autostartEnabled); ui()->useBuiltInVersionCheckBox->setChecked(settings.useLibSyncthing); ui()->useBuiltInVersionCheckBox->setVisible(settings.useLibSyncthing || SyncthingLauncher::isLibSyncthingAvailable()); +#ifdef SYNCTHINGWIDGETS_USE_LIBSYNCTHING ui()->configDirPathSelection->lineEdit()->setText(settings.libSyncthing.configDir); ui()->dataDirPathSelection->lineEdit()->setText(settings.libSyncthing.dataDir); ui()->logLevelComboBox->setCurrentIndex(static_cast(settings.libSyncthing.logLevel)); +#endif ui()->syncthingPathSelection->lineEdit()->setText(settings.syncthingPath); ui()->argumentsLineEdit->setText(settings.syncthingArgs); ui()->considerForReconnectCheckBox->setChecked(settings.considerForReconnect); @@ -1128,10 +1134,12 @@ void LauncherOptionPage::launch() handleSyncthingLaunched(true); } +#ifdef SYNCTHINGWIDGETS_USE_LIBSYNCTHING void LauncherOptionPage::updateLibSyncthingLogLevel() { m_launcher->setLibSyncthingLogLevel(static_cast(ui()->logLevelComboBox->currentIndex())); } +#endif void LauncherOptionPage::stop() { diff --git a/widgets/settings/settingsdialog.h b/widgets/settings/settingsdialog.h index 6a2a1af..b9acbe9 100644 --- a/widgets/settings/settingsdialog.h +++ b/widgets/settings/settingsdialog.h @@ -122,7 +122,9 @@ private Q_SLOTS: void handleSyncthingError(QProcess::ProcessError error); bool isRunning() const; void launch(); +#ifdef SYNCTHINGWIDGETS_USE_LIBSYNCTHING void updateLibSyncthingLogLevel(); +#endif void stop(); void restoreDefaultArguments();