Skip to content

Commit

Permalink
Exclude builtin server along with server component
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
askmeaboutlo0m committed Sep 22, 2023
1 parent f642e9f commit 5f2dae4
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 11 deletions.
2 changes: 2 additions & 0 deletions src/desktop/dialogs/settingsdialog/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions src/desktop/dialogs/startdialog/host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -131,6 +143,10 @@ Host::Host(QWidget *parent)
&Host::updateRemoteHosts);
updateRemoteHosts();

#ifndef DP_HAVE_BUILTIN_SERVER
useRemoteRadio->setChecked(true);
#endif

updateListServers();
updateHostEnabled();
}
Expand Down
12 changes: 11 additions & 1 deletion src/desktop/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down
20 changes: 13 additions & 7 deletions src/libclient/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -213,7 +220,6 @@ target_link_libraries(dpclient
PRIVATE
cmake-config
PUBLIC
dpserver
dpshared
${QT_PACKAGE_NAME}::Core
${QT_PACKAGE_NAME}::Network
Expand Down
15 changes: 12 additions & 3 deletions src/libclient/canvas/paintengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <QPainter>
#include <QSet>
#include <QTimer>
#include <QtEndian>
#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"

Expand All @@ -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}
Expand Down Expand Up @@ -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{};
Expand Down Expand Up @@ -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();
Expand All @@ -435,6 +441,7 @@ void PaintEngine::unsetServer()
m_server = nullptr;
}
}
#endif

drawdance::RecordStartResult PaintEngine::startRecording(const QString &path)
{
Expand Down Expand Up @@ -669,6 +676,7 @@ QImage PaintEngine::getFrameImage(
}


#ifdef DP_HAVE_BUILTIN_SERVER
void PaintEngine::onSoftReset(
void *user, unsigned int contextId, DP_CanvasState *cs)
{
Expand All @@ -680,6 +688,7 @@ void PaintEngine::onSoftReset(
Q_ARG(drawdance::CanvasState, drawdance::CanvasState::inc(cs)));
}
}
#endif

void PaintEngine::onPlayback(void *user, long long position)
{
Expand Down
8 changes: 8 additions & 0 deletions src/libclient/canvas/paintengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
};

}
Expand Down

0 comments on commit 5f2dae4

Please sign in to comment.