Skip to content

Commit

Permalink
Alter reset messages depending on dialog choice
Browse files Browse the repository at this point in the history
If picking the current canvas, it calls it "compressing", a previous
canvas is "reverting" and resetting to a different file is "replacing"
the canvas. This should be clearer than the ominous "reset" name.
  • Loading branch information
askmeaboutlo0m committed Dec 4, 2024
1 parent af87210 commit 8d69e06
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 22 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Unreleased Version 2.2.2-pre
* Server Fix: Don't transmit ban lists and logs to non-operators. Thanks Ryngtail for reporting.
* Fix: Always show color dialogs in HSV color space, since they don't behave correctly in other spaces. Thanks Meru for reporting.
* Fix: Apply pending fills when manipulating layers. Thanks MorrowShore for reporting.
* Server Feature: Show better messages when a session reset happens, specifying if it's compressing, reverting or replacing the canvas. Thanks MorrowShore for suggesting.

2024-11-06 Version 2.2.2-beta.4
* Fix: Solve rendering glitches with selection outlines that happen on some systems. Thanks xxxx for reporting.
Expand Down
29 changes: 23 additions & 6 deletions src/desktop/dialogs/resetdialog.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-or-later
#include "desktop/dialogs/resetdialog.h"
#include "desktop/filewrangler.h"
#include "desktop/main.h"
#include "desktop/utils/widgetutils.h"
#include "libclient/canvas/paintengine.h"
#include "libclient/utils/images.h"
Expand All @@ -21,10 +20,12 @@ using std::placeholders::_2;

namespace {

enum class Type { Current, Past, External };

struct ResetPoint {
drawdance::CanvasState canvasState;
QPixmap thumbnail;
bool external;
Type type;
};

QVector<ResetPoint> makeResetPoints(const canvas::PaintEngine *pe)
Expand All @@ -39,7 +40,7 @@ QVector<ResetPoint> makeResetPoints(const canvas::PaintEngine *pe)
drawdance::CanvasState::inc(
DP_snapshot_canvas_state_noinc(s)),
QPixmap{},
false,
Type::Past,
});
}
});
Expand All @@ -52,8 +53,10 @@ QVector<ResetPoint> makeResetPoints(const canvas::PaintEngine *pe)
resetPoints.append(ResetPoint{
currentCanvasState,
QPixmap{},
false,
Type::Current,
});
} else {
resetPoints[lastIndex].type = Type::Current;
}

return resetPoints;
Expand Down Expand Up @@ -204,7 +207,7 @@ void ResetDialog::onOpenSuccess(const drawdance::CanvasState &canvasState)
d->compatibilityMode ? canvasState.makeBackwardCompatible()
: canvasState,
QPixmap(),
true,
Type::External,
});
d->ui->snapshotSlider->setMaximum(d->resetPoints.size());
d->ui->snapshotSlider->setValue(0);
Expand All @@ -230,9 +233,23 @@ net::MessageList ResetDialog::getResetImage() const
return resetImage;
}

QString ResetDialog::getResetImageType() const
{
switch(d->resetPoints[d->selection].type) {
case Type::Current:
return QStringLiteral("current");
case Type::Past:
return QStringLiteral("past");
case Type::External:
return QStringLiteral("external");
default:
return QString();
}
}

bool ResetDialog::isExternalResetImage() const
{
return d->resetPoints[d->selection].external;
return d->resetPoints[d->selection].type == Type::External;
}

}
1 change: 1 addition & 0 deletions src/desktop/dialogs/resetdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class ResetDialog final : public QDialog {
void setCanReset(bool canReset);

net::MessageList getResetImage() const;
QString getResetImageType() const;
bool isExternalResetImage() const;

signals:
Expand Down
2 changes: 1 addition & 1 deletion src/desktop/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2935,7 +2935,7 @@ void MainWindow::resetSession()
net::MessageList snapshot = dlg->getResetImage();
canvas->amendSnapshotMetadata(
snapshot, true, DP_ACL_STATE_RESET_IMAGE_SESSION_RESET_FLAGS);
m_doc->sendResetSession(snapshot);
m_doc->sendResetSession(snapshot, dlg->getResetImageType());
}
dlg->deleteLater();
});
Expand Down
10 changes: 8 additions & 2 deletions src/libclient/document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,8 @@ void Document::sendOpword(const QString &opword)
* If the document is in offline mode, this will immediately reset the current
* canvas.
*/
void Document::sendResetSession(const net::MessageList &resetImage)
void Document::sendResetSession(
const net::MessageList &resetImage, const QString &type)
{
if(!m_client->isConnected()) {
if(resetImage.isEmpty()) {
Expand All @@ -1030,7 +1031,12 @@ void Document::sendResetSession(const net::MessageList &resetImage)
}

m_resetstate = resetImage;
m_client->sendMessage(net::ServerCommand::make("reset-session"));
QJsonObject kwargs;
if(!type.isEmpty()) {
kwargs[QStringLiteral("type")] = type;
}
m_client->sendMessage(
net::ServerCommand::make("reset-session", QJsonArray(), kwargs));
}

void Document::sendResizeCanvas(int top, int right, int bottom, int left)
Expand Down
4 changes: 3 additions & 1 deletion src/libclient/document.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,9 @@ public slots:
void sendFeatureAccessLevelChange(const uint8_t[DP_FEATURE_COUNT]);
void sendLockSession(bool lock = true);
void sendOpword(const QString &opword);
void sendResetSession(const net::MessageList &resetImage = {});
void sendResetSession(
const net::MessageList &resetImage = {},
const QString &type = QString());
void sendResizeCanvas(int top, int right, int bottom, int left);
void sendUnban(int entryId);
void sendAnnounce(const QString &url);
Expand Down
20 changes: 20 additions & 0 deletions src/libclient/net/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,26 @@ Client::translateMessage(const QJsonObject &reply, const QString &fallbackKey)
} else if(key == net::ServerReply::KEY_RESET_PREPARE) {
return tr("Preparing for session reset! Please wait, the session "
"should be available again shortly…");
} else if(key == net::ServerReply::KEY_RESET_PREPARE_BY) {
// %1 is the name of the operator resetting the canvas.
return tr("Preparing for session reset by %1! Please wait, the "
"session should be available again shortly…")
.arg(params[QStringLiteral("name")].toString());
} else if(key == net::ServerReply::KEY_RESET_PREPARE_CURRENT) {
// %1 is the name of the operator reverting the canvas.
return tr("%1 is compressing the canvas! Please wait, the session "
"should be available again shortly…")
.arg(params[QStringLiteral("name")].toString());
} else if(key == net::ServerReply::KEY_RESET_PREPARE_EXTERNAL) {
// %1 is the name of the operator replacing the canvas.
return tr("%1 is replacing the canvas! Please wait, the session "
"should be available again shortly…")
.arg(params[QStringLiteral("name")].toString());
} else if(key == net::ServerReply::KEY_RESET_PREPARE_PAST) {
// %1 is the name of the operator reverting the canvas.
return tr("%1 is reverting the canvas to a previous state! Please "
"wait, the session should be available again shortly…")
.arg(params[QStringLiteral("name")].toString());
} else if(key == net::ServerReply::KEY_TERMINATE_SESSION) {
//: %1 is the name of the moderator.
return tr("Session terminated by moderator (%1).")
Expand Down
9 changes: 5 additions & 4 deletions src/libserver/opcommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,12 +389,13 @@ CmdResult
resetSession(Client *client, const QJsonArray &args, const QJsonObject &kwargs)
{
Q_UNUSED(args);
Q_UNUSED(kwargs);

if(client->session()->state() != Session::State::Running)
return CmdResult::err("Unable to reset in this state");
if(client->session()->state() != Session::State::Running) {
return CmdResult::err(QStringLiteral("Unable to reset in this state"));
}

client->session()->resetSession(client->id());
client->session()->resetSession(
client->id(), kwargs[QStringLiteral("type")].toString());
return CmdResult::ok();
}

Expand Down
44 changes: 37 additions & 7 deletions src/libserver/session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,6 @@ void Session::switchState(State newstate)

m_resetstream.clear();
m_resetstreamsize = 0;
directToAll(net::ServerReply::makeKeyAlertReset(
QStringLiteral("Preparing for session reset!"),
QStringLiteral("prepare"), net::ServerReply::KEY_RESET_PREPARE));
}

m_state = newstate;
Expand Down Expand Up @@ -1369,15 +1366,48 @@ void Session::handleInitCancel(int ctxId)
abortReset();
}

void Session::resetSession(int resetter)
void Session::resetSession(int resetter, const QString &type)
{
Q_ASSERT(m_state == State::Running);
Q_ASSERT(getClientById(resetter));

m_initUser = resetter;
switchState(State::Reset);

getClientById(resetter)->sendDirectMessage(net::ServerReply::makeReset(
Client *client = getClientById(resetter);
Q_ASSERT(client);
QString name = client->username();
QJsonObject params = {{QStringLiteral("name"), name}};
if(type == QStringLiteral("current")) {
directToAll(net::ServerReply::makeKeyAlertReset(
QStringLiteral("%1 is compressing the canvas! Please wait, the "
"session should be available again shortly…")
.arg(name),
QStringLiteral("prepare"),
net::ServerReply::KEY_RESET_PREPARE_CURRENT, params));
} else if(type == QStringLiteral("past")) {
directToAll(net::ServerReply::makeKeyAlertReset(
QStringLiteral(
"%1 is reverting the canvas to a previous state! Please wait, "
"the session should be available again shortly…")
.arg(name),
QStringLiteral("prepare"), net::ServerReply::KEY_RESET_PREPARE_PAST,
params));
} else if(type == QStringLiteral("external")) {
directToAll(net::ServerReply::makeKeyAlertReset(
QStringLiteral("%1 is replacing the canvas! Please wait, the "
"session should be available again shortly…")
.arg(name),
QStringLiteral("prepare"),
net::ServerReply::KEY_RESET_PREPARE_EXTERNAL, params));
} else {
directToAll(net::ServerReply::makeKeyAlertReset(
QStringLiteral("Preparing for session reset by %1! Please wait, "
"the session should be available again shortly…")
.arg(name),
QStringLiteral("prepare"), net::ServerReply::KEY_RESET_PREPARE_BY,
params));
}

client->sendDirectMessage(net::ServerReply::makeReset(
QStringLiteral("Prepared to receive session data"),
QStringLiteral("init")));
}
Expand Down
2 changes: 1 addition & 1 deletion src/libserver/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ class Session : public QObject, public sessionlisting::Announcable {
State state() const { return m_state; }

// Resetting related functions, called via opcommands
void resetSession(int resetter);
void resetSession(int resetter, const QString &type);
virtual void readyToAutoReset(
const AutoResetResponseParams &params, const QString &payload) = 0;
void handleInitBegin(int ctxId);
Expand Down
4 changes: 4 additions & 0 deletions src/libshared/net/servercmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ struct ServerReply {
static constexpr char KEY_RESET_CANCEL[] = "resetcancel";
static constexpr char KEY_RESET_FAILED[] = "resetfailed";
static constexpr char KEY_RESET_PREPARE[] = "resetprepare";
static constexpr char KEY_RESET_PREPARE_BY[] = "resetprepareby";
static constexpr char KEY_RESET_PREPARE_CURRENT[] = "resetpreparecurrent";
static constexpr char KEY_RESET_PREPARE_EXTERNAL[] = "resetprepareexternal";
static constexpr char KEY_RESET_PREPARE_PAST[] = "resetpreparepast";
static constexpr char KEY_TERMINATE_SESSION[] = "terminatesession";
static constexpr char KEY_TERMINATE_SESSION_ADMIN[] =
"terminatesessionadmin";
Expand Down

0 comments on commit 8d69e06

Please sign in to comment.