mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
Allow offline Deck Storage tab (#5518)
* make deck storage tab no longer close on disconnect * add method for clearing remote decklist model * handle connect/disconnect in deck storage tab
This commit is contained in:
parent
e8b1e3ef0c
commit
f428148f64
5 changed files with 63 additions and 15 deletions
|
|
@ -4,7 +4,6 @@
|
|||
#include "../../server/pending_command.h"
|
||||
#include "../../server/remote/remote_decklist_tree_widget.h"
|
||||
#include "../../settings/cache_settings.h"
|
||||
#include "../game_logic/abstract_client.h"
|
||||
#include "../get_text_with_max.h"
|
||||
#include "decklist.h"
|
||||
#include "pb/command_deck_del.pb.h"
|
||||
|
|
@ -31,7 +30,9 @@
|
|||
#include <QUrl>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
TabDeckStorage::TabDeckStorage(TabSupervisor *_tabSupervisor, AbstractClient *_client)
|
||||
TabDeckStorage::TabDeckStorage(TabSupervisor *_tabSupervisor,
|
||||
AbstractClient *_client,
|
||||
const ServerInfo_User *currentUserInfo)
|
||||
: Tab(_tabSupervisor), client(_client)
|
||||
{
|
||||
localDirModel = new QFileSystemModel(this);
|
||||
|
|
@ -151,6 +152,10 @@ TabDeckStorage::TabDeckStorage(TabSupervisor *_tabSupervisor, AbstractClient *_c
|
|||
QWidget *mainWidget = new QWidget(this);
|
||||
mainWidget->setLayout(hbox);
|
||||
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()
|
||||
|
|
@ -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)
|
||||
{
|
||||
if (!localDirModel->isDir(curLeft)) {
|
||||
|
|
|
|||
|
|
@ -2,8 +2,10 @@
|
|||
#define TAB_DECK_STORAGE_H
|
||||
|
||||
#include "../../server/remote/remote_decklist_tree_widget.h"
|
||||
#include "../game_logic/abstract_client.h"
|
||||
#include "tab.h"
|
||||
|
||||
class ServerInfo_User;
|
||||
class AbstractClient;
|
||||
class QTreeView;
|
||||
class QFileSystemModel;
|
||||
|
|
@ -31,12 +33,17 @@ private:
|
|||
QAction *aOpenRemoteDeck, *aDownload, *aNewFolder, *aDeleteRemoteDeck;
|
||||
QString getTargetPath() const;
|
||||
|
||||
void setRemoteEnabled(bool enabled);
|
||||
|
||||
void uploadDeck(const QString &filePath, const QString &targetPath);
|
||||
void deleteRemoteDeck(const RemoteDeckList_TreeModel::Node *node);
|
||||
|
||||
void downloadNodeAtIndex(const QModelIndex &curLeft, const QModelIndex &curRight);
|
||||
|
||||
private slots:
|
||||
void handleConnected(const ServerInfo_User &userInfo);
|
||||
void handleConnectionChanged(ClientStatus status);
|
||||
|
||||
void actLocalDoubleClick(const QModelIndex &curLeft);
|
||||
void actOpenLocalDeck();
|
||||
|
||||
|
|
@ -63,7 +70,7 @@ private slots:
|
|||
void deleteDeckFinished(const Response &response, const CommandContainer &commandContainer);
|
||||
|
||||
public:
|
||||
TabDeckStorage(TabSupervisor *_tabSupervisor, AbstractClient *_client);
|
||||
TabDeckStorage(TabSupervisor *_tabSupervisor, AbstractClient *_client, const ServerInfo_User *currentUserInfo);
|
||||
void retranslateUi() override;
|
||||
QString getTabText() const override
|
||||
{
|
||||
|
|
|
|||
|
|
@ -279,6 +279,7 @@ void TabSupervisor::initStartupTabs()
|
|||
addDeckEditorTab(nullptr);
|
||||
|
||||
checkAndTrigger(aTabVisualDeckStorage, SettingsCache::instance().getTabVisualDeckStorageOpen());
|
||||
checkAndTrigger(aTabDeckStorage, SettingsCache::instance().getTabDeckStorageOpen());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -334,6 +335,7 @@ void TabSupervisor::resetTabsMenu()
|
|||
tabsMenu->addAction(aTabDeckEditor);
|
||||
tabsMenu->addSeparator();
|
||||
tabsMenu->addAction(aTabVisualDeckStorage);
|
||||
tabsMenu->addAction(aTabDeckStorage);
|
||||
}
|
||||
|
||||
void TabSupervisor::start(const ServerInfo_User &_userInfo)
|
||||
|
|
@ -355,10 +357,8 @@ void TabSupervisor::start(const ServerInfo_User &_userInfo)
|
|||
updatePingTime(0, -1);
|
||||
|
||||
if (userInfo->user_level() & ServerInfo_User::IsRegistered) {
|
||||
tabsMenu->addAction(aTabDeckStorage);
|
||||
tabsMenu->addAction(aTabReplays);
|
||||
|
||||
checkAndTrigger(aTabDeckStorage, SettingsCache::instance().getTabDeckStorageOpen());
|
||||
checkAndTrigger(aTabReplays, SettingsCache::instance().getTabReplaysOpen());
|
||||
}
|
||||
|
||||
|
|
@ -379,7 +379,6 @@ void TabSupervisor::startLocal(const QList<AbstractClient *> &_clients)
|
|||
resetTabsMenu();
|
||||
|
||||
tabAccount = nullptr;
|
||||
tabDeckStorage = nullptr;
|
||||
tabReplays = nullptr;
|
||||
tabAdmin = nullptr;
|
||||
tabLog = nullptr;
|
||||
|
|
@ -416,9 +415,6 @@ void TabSupervisor::stop()
|
|||
if (tabServer) {
|
||||
tabServer->closeRequest(true);
|
||||
}
|
||||
if (tabDeckStorage) {
|
||||
tabDeckStorage->closeRequest(true);
|
||||
}
|
||||
if (tabReplays) {
|
||||
tabReplays->closeRequest(true);
|
||||
}
|
||||
|
|
@ -508,7 +504,7 @@ void TabSupervisor::actTabDeckStorage(bool checked)
|
|||
{
|
||||
SettingsCache::instance().setTabDeckStorageOpen(checked);
|
||||
if (checked && !tabDeckStorage) {
|
||||
tabDeckStorage = new TabDeckStorage(this, client);
|
||||
tabDeckStorage = new TabDeckStorage(this, client, userInfo);
|
||||
connect(tabDeckStorage, &TabDeckStorage::openDeckEditor, this, &TabSupervisor::addDeckEditorTab);
|
||||
myAddTab(tabDeckStorage, aTabDeckStorage);
|
||||
connect(tabDeckStorage, &Tab::closed, this, [this] {
|
||||
|
|
|
|||
|
|
@ -270,15 +270,18 @@ void RemoteDeckList_TreeModel::refreshTree()
|
|||
client->sendCommand(pend);
|
||||
}
|
||||
|
||||
void RemoteDeckList_TreeModel::clearTree()
|
||||
{
|
||||
beginResetModel();
|
||||
root->clearTree();
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
void RemoteDeckList_TreeModel::deckListFinished(const Response &r)
|
||||
{
|
||||
const Response_DeckList &resp = r.GetExtension(Response_DeckList::ext);
|
||||
|
||||
beginResetModel();
|
||||
|
||||
root->clearTree();
|
||||
|
||||
endResetModel();
|
||||
clearTree();
|
||||
|
||||
ServerInfo_DeckStorage_TreeItem tempRoot;
|
||||
tempRoot.set_id(0);
|
||||
|
|
@ -361,3 +364,8 @@ void RemoteDeckList_TreeWidget::refreshTree()
|
|||
{
|
||||
treeModel->refreshTree();
|
||||
}
|
||||
|
||||
void RemoteDeckList_TreeWidget::clearTree()
|
||||
{
|
||||
treeModel->clearTree();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -106,6 +106,7 @@ public:
|
|||
DirectoryNode *addNamedFolderToTree(const QString &name, DirectoryNode *parent);
|
||||
void removeNode(Node *node);
|
||||
void refreshTree();
|
||||
void clearTree();
|
||||
};
|
||||
|
||||
class RemoteDeckList_TreeWidget : public QTreeView
|
||||
|
|
@ -127,6 +128,7 @@ public:
|
|||
void addFolderToTree(const QString &name, RemoteDeckList_TreeModel::DirectoryNode *parent);
|
||||
void removeNode(RemoteDeckList_TreeModel::Node *node);
|
||||
void refreshTree();
|
||||
void clearTree();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue