handle connect/disconnect in deck storage tab

This commit is contained in:
RickyRister 2025-01-24 02:36:42 -08:00
parent ac2bbfea30
commit a9031ef6ab
3 changed files with 46 additions and 4 deletions

View file

@ -4,7 +4,6 @@
#include "../../server/pending_command.h" #include "../../server/pending_command.h"
#include "../../server/remote/remote_decklist_tree_widget.h" #include "../../server/remote/remote_decklist_tree_widget.h"
#include "../../settings/cache_settings.h" #include "../../settings/cache_settings.h"
#include "../game_logic/abstract_client.h"
#include "../get_text_with_max.h" #include "../get_text_with_max.h"
#include "decklist.h" #include "decklist.h"
#include "pb/command_deck_del.pb.h" #include "pb/command_deck_del.pb.h"
@ -31,7 +30,9 @@
#include <QUrl> #include <QUrl>
#include <QVBoxLayout> #include <QVBoxLayout>
TabDeckStorage::TabDeckStorage(TabSupervisor *_tabSupervisor, AbstractClient *_client) TabDeckStorage::TabDeckStorage(TabSupervisor *_tabSupervisor,
AbstractClient *_client,
const ServerInfo_User *currentUserInfo)
: Tab(_tabSupervisor), client(_client) : Tab(_tabSupervisor), client(_client)
{ {
localDirModel = new QFileSystemModel(this); localDirModel = new QFileSystemModel(this);
@ -151,6 +152,10 @@ TabDeckStorage::TabDeckStorage(TabSupervisor *_tabSupervisor, AbstractClient *_c
QWidget *mainWidget = new QWidget(this); QWidget *mainWidget = new QWidget(this);
mainWidget->setLayout(hbox); mainWidget->setLayout(hbox);
setCentralWidget(mainWidget); setCentralWidget(mainWidget);
connect(client, &AbstractClient::userInfoChanged, this, &TabDeckStorage::handleConnected);
connect(client, &AbstractClient::statusChanged, this, &TabDeckStorage::handleConnectionChanged);
setRemoteEnabled(currentUserInfo && currentUserInfo->user_level() & ServerInfo_User::IsRegistered);
} }
void TabDeckStorage::retranslateUi() void TabDeckStorage::retranslateUi()
@ -187,6 +192,36 @@ QString TabDeckStorage::getTargetPath() const
} }
} }
void TabDeckStorage::handleConnected(const ServerInfo_User &userInfo)
{
setRemoteEnabled(userInfo.user_level() & ServerInfo_User::IsRegistered);
}
/**
* This is only responsible for handling the disconnect. The connect is already handled elsewhere
*/
void TabDeckStorage::handleConnectionChanged(ClientStatus status)
{
if (status == StatusDisconnected) {
setRemoteEnabled(false);
}
}
void TabDeckStorage::setRemoteEnabled(bool enabled)
{
aUpload->setEnabled(enabled);
aOpenRemoteDeck->setEnabled(enabled);
aDownload->setEnabled(enabled);
aNewFolder->setEnabled(enabled);
aDeleteRemoteDeck->setEnabled(enabled);
if (enabled) {
serverDirView->refreshTree();
} else {
serverDirView->clearTree();
}
}
void TabDeckStorage::actLocalDoubleClick(const QModelIndex &curLeft) void TabDeckStorage::actLocalDoubleClick(const QModelIndex &curLeft)
{ {
if (!localDirModel->isDir(curLeft)) { if (!localDirModel->isDir(curLeft)) {

View file

@ -2,8 +2,10 @@
#define TAB_DECK_STORAGE_H #define TAB_DECK_STORAGE_H
#include "../../server/remote/remote_decklist_tree_widget.h" #include "../../server/remote/remote_decklist_tree_widget.h"
#include "../game_logic/abstract_client.h"
#include "tab.h" #include "tab.h"
class ServerInfo_User;
class AbstractClient; class AbstractClient;
class QTreeView; class QTreeView;
class QFileSystemModel; class QFileSystemModel;
@ -31,12 +33,17 @@ private:
QAction *aOpenRemoteDeck, *aDownload, *aNewFolder, *aDeleteRemoteDeck; QAction *aOpenRemoteDeck, *aDownload, *aNewFolder, *aDeleteRemoteDeck;
QString getTargetPath() const; QString getTargetPath() const;
void setRemoteEnabled(bool enabled);
void uploadDeck(const QString &filePath, const QString &targetPath); void uploadDeck(const QString &filePath, const QString &targetPath);
void deleteRemoteDeck(const RemoteDeckList_TreeModel::Node *node); void deleteRemoteDeck(const RemoteDeckList_TreeModel::Node *node);
void downloadNodeAtIndex(const QModelIndex &curLeft, const QModelIndex &curRight); void downloadNodeAtIndex(const QModelIndex &curLeft, const QModelIndex &curRight);
private slots: private slots:
void handleConnected(const ServerInfo_User &userInfo);
void handleConnectionChanged(ClientStatus status);
void actLocalDoubleClick(const QModelIndex &curLeft); void actLocalDoubleClick(const QModelIndex &curLeft);
void actOpenLocalDeck(); void actOpenLocalDeck();
@ -63,7 +70,7 @@ private slots:
void deleteDeckFinished(const Response &response, const CommandContainer &commandContainer); void deleteDeckFinished(const Response &response, const CommandContainer &commandContainer);
public: public:
TabDeckStorage(TabSupervisor *_tabSupervisor, AbstractClient *_client); TabDeckStorage(TabSupervisor *_tabSupervisor, AbstractClient *_client, const ServerInfo_User *currentUserInfo);
void retranslateUi() override; void retranslateUi() override;
QString getTabText() const override QString getTabText() const override
{ {

View file

@ -504,7 +504,7 @@ void TabSupervisor::actTabDeckStorage(bool checked)
{ {
SettingsCache::instance().setTabDeckStorageOpen(checked); SettingsCache::instance().setTabDeckStorageOpen(checked);
if (checked && !tabDeckStorage) { if (checked && !tabDeckStorage) {
tabDeckStorage = new TabDeckStorage(this, client); tabDeckStorage = new TabDeckStorage(this, client, userInfo);
connect(tabDeckStorage, &TabDeckStorage::openDeckEditor, this, &TabSupervisor::addDeckEditorTab); connect(tabDeckStorage, &TabDeckStorage::openDeckEditor, this, &TabSupervisor::addDeckEditorTab);
myAddTab(tabDeckStorage, aTabDeckStorage); myAddTab(tabDeckStorage, aTabDeckStorage);
connect(tabDeckStorage, &Tab::closed, this, [this] { connect(tabDeckStorage, &Tab::closed, this, [this] {