[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

@ -8,6 +8,7 @@
#include <QLineEdit>
#include <QMessageBox>
#include <QPushButton>
#include <QTimer>
#include <QVBoxLayout>
#include <libcockatrice/card/database/card_database_manager.h>
#include <libcockatrice/deck_list/deck_list.h>
@ -17,8 +18,10 @@
#include <libcockatrice/protocol/pb/response_deck_share_create.pb.h>
#include <libcockatrice/protocol/pending_command.h>
#include "../../../client/settings/cache_settings.h"
DlgShareDeck::DlgShareDeck(AbstractClient *_client, const QSharedPointer<DeckList> &_deck, QWidget *_parent)
: QDialog(_parent), client(_client), deck(_deck)
: QDialog(_parent), client(_client), deck(_deck), shareTimeoutTimer(new QTimer(this))
{
setWindowTitle(tr("Share deck"));
@ -38,6 +41,12 @@ DlgShareDeck::DlgShareDeck(AbstractClient *_client, const QSharedPointer<DeckLis
connect(buttonBox, &QDialogButtonBox::rejected, this, &DlgShareDeck::reject);
this->buttonBox = buttonBox;
layout->addWidget(buttonBox);
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, &DlgShareDeck::onShareTimeout);
}
void DlgShareDeck::actShare()
@ -57,10 +66,12 @@ void DlgShareDeck::actShare()
PendingCommand *pend = client->prepareSessionCommand(cmd);
connect(pend, &PendingCommand::finished, this, &DlgShareDeck::shareFinished);
client->sendCommand(pend);
shareTimeoutTimer->start();
}
void DlgShareDeck::shareFinished(const Response &response, const CommandContainer & /*commandContainer*/)
{
shareTimeoutTimer->stop();
if (response.response_code() != Response::RespOk) {
buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
QMessageBox::critical(this, tr("Share deck"),
@ -76,4 +87,10 @@ void DlgShareDeck::shareFinished(const Response &response, const CommandContaine
"The share expires on %2.")
.arg(share.link, DeckShareUtils::formatShareExpiry(share.expiry)));
accept();
}
void DlgShareDeck::onShareTimeout()
{
buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
QMessageBox::warning(this, tr("Share deck"), tr("The server did not respond in time. Try again."));
}

View file

@ -15,6 +15,7 @@ class CommandContainer;
class DeckList;
class QDialogButtonBox;
class QLineEdit;
class QTimer;
class Response;
/**
@ -32,12 +33,14 @@ public:
private slots:
void actShare();
void shareFinished(const Response &response, const CommandContainer &commandContainer);
void onShareTimeout();
private:
AbstractClient *client;
QSharedPointer<DeckList> deck;
QLineEdit *nameEdit;
QDialogButtonBox *buttonBox;
QTimer *shareTimeoutTimer;
};
#endif // DLG_SHARE_DECK_H

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;
};