From 5f2dae44b3f86949e00a306225cddaf99427706c Mon Sep 17 00:00:00 2001 From: askmeaboutloom Date: Fri, 22 Sep 2023 05:45:39 +0200 Subject: [PATCH] Exclude builtin server along with server component When not building the server (-DSERVER=OFF), the builtin server now isn't included either, meaning hosting on this computer won't be available. That means on Android, the builtin server is never available. Which makes sense, since Android likes to suspend applications, so it's not particularly suited for running a server on it. --- .../dialogs/settingsdialog/network.cpp | 2 ++ src/desktop/dialogs/startdialog/host.cpp | 16 +++++++++++++++ src/desktop/mainwindow.cpp | 12 ++++++++++- src/libclient/CMakeLists.txt | 20 ++++++++++++------- src/libclient/canvas/paintengine.cpp | 15 +++++++++++--- src/libclient/canvas/paintengine.h | 8 ++++++++ 6 files changed, 62 insertions(+), 11 deletions(-) diff --git a/src/desktop/dialogs/settingsdialog/network.cpp b/src/desktop/dialogs/settingsdialog/network.cpp index 18358890fd..a715027766 100644 --- a/src/desktop/dialogs/settingsdialog/network.cpp +++ b/src/desktop/dialogs/settingsdialog/network.cpp @@ -66,8 +66,10 @@ Network::Network(desktop::settings::Settings &settings, QWidget *parent) form->addRow(tr("Receive delay:"), messageQueueDrainRate); form->addRow(nullptr, utils::note(tr("The higher the value, the smoother strokes from other users come in."), QSizePolicy::Label)); +#ifdef DP_HAVE_BUILTIN_SERVER form->addSeparator(); initBuiltinServer(settings, form); +#endif } void Network::initAvatars(utils::SanerFormLayout *form) diff --git a/src/desktop/dialogs/startdialog/host.cpp b/src/desktop/dialogs/startdialog/host.cpp index 61e3cff3c1..3b5e8fe192 100644 --- a/src/desktop/dialogs/startdialog/host.cpp +++ b/src/desktop/dialogs/startdialog/host.cpp @@ -77,6 +77,18 @@ Host::Host(QWidget *parent) QRadioButton *useLocalRadio = new QRadioButton{tr("Host on this computer")}; useLocalRadio->setToolTip(tr("Use Drawpile's built-in server")); layout->addSpanningRow(useLocalRadio); +#ifndef DP_HAVE_BUILTIN_SERVER + useLocalRadio->setEnabled(false); +# ifdef Q_OS_ANDROID + QString notAvailableMessage = + tr("The built-in server is not available on Android."); +# else + QString notAvailableMessage = tr("The built-in server is not available on " + "this installation of Drawpile."); +# endif + layout->addSpanningRow( + utils::note(notAvailableMessage, QSizePolicy::RadioButton)); +#endif layout->addSpacer(); @@ -131,6 +143,10 @@ Host::Host(QWidget *parent) &Host::updateRemoteHosts); updateRemoteHosts(); +#ifndef DP_HAVE_BUILTIN_SERVER + useRemoteRadio->setChecked(true); +#endif + updateListServers(); updateHostEnabled(); } diff --git a/src/desktop/mainwindow.cpp b/src/desktop/mainwindow.cpp index 16d4474a02..4ac25627a3 100644 --- a/src/desktop/mainwindow.cpp +++ b/src/desktop/mainwindow.cpp @@ -85,7 +85,6 @@ static constexpr auto CTRL_KEY = Qt::CTRL; #include "libclient/net/login.h" #include "libclient/canvas/layerlist.h" #include "libclient/parentalcontrols/parentalcontrols.h" -#include "libclient/server/builtinserver.h" #include "libclient/tools/toolcontroller.h" #include "desktop/toolwidgets/brushsettings.h" @@ -125,6 +124,10 @@ static constexpr auto CTRL_KEY = Qt::CTRL; #include "desktop/bundled/kis_tablet/kis_tablet_support_win.h" #endif +#ifdef DP_HAVE_BUILTIN_SERVER +# include "libclient/server/builtinserver.h" +#endif + using desktop::settings::Settings; // Totally arbitrary nonsense constexpr auto DEBOUNCE_MS = 250; @@ -1821,6 +1824,7 @@ void MainWindow::hostSession( // Start server if hosting locally const desktop::settings::Settings &settings = dpApp().settings(); if(!useremote) { +#ifdef DP_HAVE_BUILTIN_SERVER canvas::PaintEngine *paintEngine = m_doc->canvas()->paintEngine(); server::BuiltinServer *server = new server::BuiltinServer(paintEngine, this); @@ -1844,6 +1848,10 @@ void MainWindow::hostSession( if(server->port() != cmake_config::proto::port()) { address.setPort(server->port()); } +#else + showErrorMessage(tr("Hosting on this computer is not available")); + return; +#endif } // Connect to server @@ -2073,9 +2081,11 @@ void MainWindow::onServerDisconnected(const QString &message, const QString &err { canvas::CanvasModel *canvas = m_doc->canvas(); emit hostSessionEnabled(canvas != nullptr); +#ifdef DP_HAVE_BUILTIN_SERVER if(canvas) { canvas->paintEngine()->setServer(nullptr); } +#endif getAction("invitesession")->setEnabled(false); getAction("leavesession")->setEnabled(false); diff --git a/src/libclient/CMakeLists.txt b/src/libclient/CMakeLists.txt index 96d7fad35a..a9352555b7 100644 --- a/src/libclient/CMakeLists.txt +++ b/src/libclient/CMakeLists.txt @@ -115,12 +115,6 @@ target_sources(dpclient PRIVATE net/sessionlistingmodel.h net/tcpserver.cpp net/tcpserver.h - server/builtinclient.cpp - server/builtinclient.h - server/builtinsession.cpp - server/builtinsession.h - server/builtinserver.cpp - server/builtinserver.h tools/annotation.cpp tools/annotation.h tools/beziertool.cpp @@ -198,6 +192,19 @@ target_sources(dpclient PRIVATE utils/usernamevalidator.h ) +if(SERVER) + target_compile_definitions(dpclient PUBLIC DP_HAVE_BUILTIN_SERVER=1) + target_link_libraries(dpclient PUBLIC dpserver) + target_sources(dpclient PRIVATE + server/builtinclient.cpp + server/builtinclient.h + server/builtinsession.cpp + server/builtinsession.h + server/builtinserver.cpp + server/builtinserver.h + ) +endif() + # https://gitlab.kitware.com/cmake/cmake/-/issues/19813 if(WIN32) target_sources(dpclient PRIVATE @@ -213,7 +220,6 @@ target_link_libraries(dpclient PRIVATE cmake-config PUBLIC - dpserver dpshared ${QT_PACKAGE_NAME}::Core ${QT_PACKAGE_NAME}::Network diff --git a/src/libclient/canvas/paintengine.cpp b/src/libclient/canvas/paintengine.cpp index a5e4f061f9..32f78605f6 100644 --- a/src/libclient/canvas/paintengine.cpp +++ b/src/libclient/canvas/paintengine.cpp @@ -15,11 +15,16 @@ extern "C" { #include "libclient/drawdance/perf.h" #include "libclient/drawdance/viewmode.h" #include "libclient/net/message.h" -#include "libclient/server/builtinserver.h" #include #include #include #include +#ifdef DP_HAVE_BUILTIN_SERVER +# include "libclient/server/builtinserver.h" +# define ON_SOFT_RESET_FN PaintEngine::onSoftReset +#else +# define ON_SOFT_RESET_FN nullptr +#endif #define DP_PERF_CONTEXT "paint_engine" @@ -34,7 +39,7 @@ PaintEngine::PaintEngine( , m_paintEngine( m_acls, m_snapshotQueue, wantCanvasHistoryDump, PaintEngine::onRenderTile, PaintEngine::onRenderUnlock, - PaintEngine::onRenderResize, this, PaintEngine::onSoftReset, this, + PaintEngine::onRenderResize, this, ON_SOFT_RESET_FN, this, PaintEngine::onPlayback, PaintEngine::onDumpPlayback, this) , m_fps{fps} , m_timerId{0} @@ -96,7 +101,7 @@ void PaintEngine::reset( net::MessageList localResetImage = m_paintEngine.reset( m_acls, m_snapshotQueue, localUserId, PaintEngine::onRenderTile, PaintEngine::onRenderUnlock, PaintEngine::onRenderResize, this, - PaintEngine::onSoftReset, this, PaintEngine::onPlayback, + ON_SOFT_RESET_FN, this, PaintEngine::onPlayback, PaintEngine::onDumpPlayback, this, canvasState, player); DP_mutex_lock(m_cacheMutex); m_cache = QPixmap{}; @@ -418,6 +423,7 @@ QColor PaintEngine::sampleColor(int x, int y, int layerId, int diameter) } } +#ifdef DP_HAVE_BUILTIN_SERVER void PaintEngine::setServer(server::BuiltinServer *server) { unsetServer(); @@ -435,6 +441,7 @@ void PaintEngine::unsetServer() m_server = nullptr; } } +#endif drawdance::RecordStartResult PaintEngine::startRecording(const QString &path) { @@ -669,6 +676,7 @@ QImage PaintEngine::getFrameImage( } +#ifdef DP_HAVE_BUILTIN_SERVER void PaintEngine::onSoftReset( void *user, unsigned int contextId, DP_CanvasState *cs) { @@ -680,6 +688,7 @@ void PaintEngine::onSoftReset( Q_ARG(drawdance::CanvasState, drawdance::CanvasState::inc(cs))); } } +#endif void PaintEngine::onPlayback(void *user, long long position) { diff --git a/src/libclient/canvas/paintengine.h b/src/libclient/canvas/paintengine.h index 57385ca44a..03096b722e 100644 --- a/src/libclient/canvas/paintengine.h +++ b/src/libclient/canvas/paintengine.h @@ -186,7 +186,9 @@ class PaintEngine final : public QObject { QColor sampleColor(int x, int y, int layerId, int diameter); +#ifdef DP_HAVE_BUILTIN_SERVER void setServer(server::BuiltinServer *server); +#endif drawdance::RecordStartResult startRecording(const QString &path); drawdance::RecordStartResult @@ -247,11 +249,15 @@ class PaintEngine final : public QObject { void timerEvent(QTimerEvent *) override; private slots: +#ifdef DP_HAVE_BUILTIN_SERVER void unsetServer(); +#endif private: +#ifdef DP_HAVE_BUILTIN_SERVER static void onSoftReset(void *user, unsigned int contextId, DP_CanvasState *cs); +#endif static void onPlayback(void *user, long long position); static void onDumpPlayback( void *user, long long position, DP_CanvasHistorySnapshot *chs); @@ -300,7 +306,9 @@ private slots: int m_sampleColorLastDiameter; int m_undoDepthLimit; bool m_updateLayersVisibleInFrame; +#ifdef DP_HAVE_BUILTIN_SERVER server::BuiltinServer *m_server = nullptr; +#endif }; }