[DeckShare] Recover the share controls when the server never answers

This commit is contained in:
Lukas Brübach 2026-09-19 00:03:51 +02:00 committed by GitHub
parent 34be334b06
commit 6fa4a2eb0c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 62 additions and 2 deletions

View file

@ -22,6 +22,7 @@
#include <QMessageBox>
#include <QToolBar>
#include <QTreeView>
#include <QTimer>
#include <QUrl>
#include <QVBoxLayout>
#include <libcockatrice/deck_list/deck_list.h>
@ -108,6 +109,13 @@ TabDeckStorage::TabDeckStorage(TabSupervisor *_tabSupervisor,
connect(shareBar, &ShareBarWidget::cancelRequested, this, &TabDeckStorage::cancelShareDecks);
shareBar->setVisible(false);
shareTimeoutTimer = new QTimer(this);
shareTimeoutTimer->setSingleShot(true);
shareTimeoutTimer->setInterval(
static_cast<int>((static_cast<qint64>(SettingsCache::instance().network().getTimeOut()) + 1) *
SettingsCache::instance().network().getKeepAlive() * 1000));
connect(shareTimeoutTimer, &QTimer::timeout, this, &TabDeckStorage::onShareFromTreeTimeout);
QVBoxLayout *rightVbox = new QVBoxLayout;
rightVbox->addWidget(shareBar);
rightVbox->addWidget(serverDirView);
@ -765,10 +773,12 @@ void TabDeckStorage::actShareSelection()
PendingCommand *pend = client->prepareSessionCommand(cmd);
connect(pend, &PendingCommand::finished, this, &TabDeckStorage::shareFromTreeFinished);
client->sendCommand(pend);
shareTimeoutTimer->start();
}
void TabDeckStorage::shareFromTreeFinished(const Response &response, const CommandContainer & /*commandContainer*/)
{
shareTimeoutTimer->stop();
shareBar->setCreateEnabled(true);
if (response.response_code() != Response::RespOk) {
qWarning() << "failed to create deck share:" << response.response_code();
@ -790,3 +800,9 @@ void TabDeckStorage::showShareNotice(const QString &message, bool warning)
QMessageBox::Ok, this);
box.exec();
}
void TabDeckStorage::onShareFromTreeTimeout()
{
shareBar->setCreateEnabled(true);
showShareNotice(tr("The server did not respond in time. Try again."), true);
}

View file

@ -22,6 +22,7 @@ class QToolBar;
class QTreeWidget;
class QTreeWidgetItem;
class QGroupBox;
class QTimer;
class CommandContainer;
class Response;
class ShareBarWidget;
@ -37,6 +38,7 @@ private:
RemoteDeckList_TreeWidget *serverDirView;
QGroupBox *leftGroupBox, *rightGroupBox;
ShareBarWidget *shareBar;
QTimer *shareTimeoutTimer;
QAction *aOpenLocalDeck, *aRenameLocal, *aUpload, *aNewLocalFolder, *aDeleteLocalDeck;
QAction *aOpenDecksFolder;
@ -86,6 +88,7 @@ private slots:
void cancelShareDecks();
void onServerSelectionChanged();
void shareFromTreeFinished(const Response &r, const CommandContainer &commandContainer);
void onShareFromTreeTimeout();
void actDeleteRemoteDeck();
void deleteFolderFinished(const Response &response, const CommandContainer &commandContainer);

View file

@ -7,6 +7,7 @@
#include "../tab_supervisor.h"
#include <QMessageBox>
#include <QTimer>
#include <QVBoxLayout>
#include <libcockatrice/card/database/card_database_manager.h>
#include <libcockatrice/deck_list/deck_list.h>
@ -16,8 +17,11 @@
#include <libcockatrice/protocol/pb/response_deck_share_create.pb.h>
#include <libcockatrice/protocol/pending_command.h>
#include "../../../client/settings/cache_settings.h"
TabDeckStorageVisual::TabDeckStorageVisual(TabSupervisor *_tabSupervisor, AbstractClient *_client)
: Tab(_tabSupervisor), client(_client), visualDeckStorageWidget(new VisualDeckStorageWidget(this))
: Tab(_tabSupervisor), client(_client), visualDeckStorageWidget(new VisualDeckStorageWidget(this)),
shareTimeoutTimer(new QTimer(this))
{
connect(this, &TabDeckStorageVisual::openDeckEditor, tabSupervisor, &TabSupervisor::openDeckInNewTab);
connect(visualDeckStorageWidget, &VisualDeckStorageWidget::deckLoadRequested, this,
@ -53,6 +57,12 @@ TabDeckStorageVisual::TabDeckStorageVisual(TabSupervisor *_tabSupervisor, Abstra
layout->insertWidget(0, shareBar);
shareBar->setVisible(false);
shareTimeoutTimer->setSingleShot(true);
shareTimeoutTimer->setInterval(
static_cast<int>((static_cast<qint64>(SettingsCache::instance().network().getTimeOut()) + 1) *
SettingsCache::instance().network().getKeepAlive() * 1000));
connect(shareTimeoutTimer, &QTimer::timeout, this, &TabDeckStorageVisual::onShareTimeout);
retranslateUi();
}
@ -153,10 +163,12 @@ void TabDeckStorageVisual::actShareSelected()
PendingCommand *pend = client->prepareSessionCommand(cmd);
connect(pend, &PendingCommand::finished, this, &TabDeckStorageVisual::shareFinished);
client->sendCommand(pend);
shareTimeoutTimer->start();
}
void TabDeckStorageVisual::shareFinished(const Response &response, const CommandContainer & /*commandContainer*/)
{
shareTimeoutTimer->stop();
shareBar->setCreateEnabled(true);
if (response.response_code() != Response::RespOk) {
showShareNotice(tr("Failed to create the share link (server response code %1).")
@ -186,4 +198,10 @@ void TabDeckStorageVisual::showShareNotice(const QString &message, bool warning)
QMessageBox box(warning ? QMessageBox::Warning : QMessageBox::Information, tr("Deck share"), message,
QMessageBox::Ok, this);
box.exec();
}
void TabDeckStorageVisual::onShareTimeout()
{
shareBar->setCreateEnabled(true);
showShareNotice(tr("The server did not respond in time. Try again."), true);
}

View file

@ -19,6 +19,7 @@ class CommandContainer;
class DeckPreviewWidget;
class QFileSystemModel;
class QGroupBox;
class QTimer;
class QToolBar;
class QTreeView;
class QTreeWidget;
@ -63,6 +64,7 @@ signals:
private slots:
void actShareSelected();
void shareFinished(const Response &response, const CommandContainer &commandContainer);
void onShareTimeout();
void onShareSelectionChanged();
void handleConnectionChanged(ClientStatus status);
@ -74,6 +76,7 @@ private:
ShareBarWidget *shareBar;
AbstractClient *client;
QTimer *shareTimeoutTimer;
bool shareDeckAvailable = false;
};