Allow offline Replays tab (#5519)

This commit is contained in:
RickyRister 2025-01-24 21:44:48 -08:00 committed by GitHub
parent ec6a23de56
commit 19b758591b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 65 additions and 17 deletions

View file

@ -27,7 +27,8 @@
#include <QUrl> #include <QUrl>
#include <QVBoxLayout> #include <QVBoxLayout>
TabReplays::TabReplays(TabSupervisor *_tabSupervisor, AbstractClient *_client) : Tab(_tabSupervisor), client(_client) TabReplays::TabReplays(TabSupervisor *_tabSupervisor, AbstractClient *_client, const ServerInfo_User *currentUserInfo)
: Tab(_tabSupervisor), client(_client)
{ {
localDirModel = new QFileSystemModel(this); localDirModel = new QFileSystemModel(this);
localDirModel->setRootPath(SettingsCache::instance().getReplaysPath()); localDirModel->setRootPath(SettingsCache::instance().getReplaysPath());
@ -147,6 +148,10 @@ TabReplays::TabReplays(TabSupervisor *_tabSupervisor, AbstractClient *_client) :
connect(client, SIGNAL(replayAddedEventReceived(const Event_ReplayAdded &)), this, connect(client, SIGNAL(replayAddedEventReceived(const Event_ReplayAdded &)), this,
SLOT(replayAddedEventReceived(const Event_ReplayAdded &))); SLOT(replayAddedEventReceived(const Event_ReplayAdded &)));
connect(client, &AbstractClient::userInfoChanged, this, &TabReplays::handleConnected);
connect(client, &AbstractClient::statusChanged, this, &TabReplays::handleConnectionChanged);
setRemoteEnabled(currentUserInfo && currentUserInfo->user_level() & ServerInfo_User::IsRegistered);
} }
void TabReplays::retranslateUi() void TabReplays::retranslateUi()
@ -165,6 +170,35 @@ void TabReplays::retranslateUi()
aDeleteRemoteReplay->setText(tr("Delete")); aDeleteRemoteReplay->setText(tr("Delete"));
} }
void TabReplays::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 TabReplays::handleConnectionChanged(ClientStatus status)
{
if (status == StatusDisconnected) {
setRemoteEnabled(false);
}
}
void TabReplays::setRemoteEnabled(bool enabled)
{
aOpenRemoteReplay->setEnabled(enabled);
aDownload->setEnabled(enabled);
aKeep->setEnabled(enabled);
aDeleteRemoteReplay->setEnabled(enabled);
if (enabled) {
serverDirView->refreshTree();
} else {
serverDirView->clearTree();
}
}
void TabReplays::actLocalDoubleClick(const QModelIndex &curLeft) void TabReplays::actLocalDoubleClick(const QModelIndex &curLeft)
{ {
if (!localDirModel->isDir(curLeft)) { if (!localDirModel->isDir(curLeft)) {

View file

@ -1,8 +1,10 @@
#ifndef TAB_REPLAYS_H #ifndef TAB_REPLAYS_H
#define TAB_REPLAYS_H #define TAB_REPLAYS_H
#include "../game_logic/abstract_client.h"
#include "tab.h" #include "tab.h"
class ServerInfo_User;
class Response; class Response;
class AbstractClient; class AbstractClient;
class QTreeView; class QTreeView;
@ -29,9 +31,14 @@ private:
QAction *aOpenReplaysFolder; QAction *aOpenReplaysFolder;
QAction *aOpenRemoteReplay, *aDownload, *aKeep, *aDeleteRemoteReplay; QAction *aOpenRemoteReplay, *aDownload, *aKeep, *aDeleteRemoteReplay;
void setRemoteEnabled(bool enabled);
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 actRenameLocal(); void actRenameLocal();
void actOpenLocalReplay(); void actOpenLocalReplay();
@ -58,7 +65,7 @@ signals:
void openReplay(GameReplay *replay); void openReplay(GameReplay *replay);
public: public:
TabReplays(TabSupervisor *_tabSupervisor, AbstractClient *_client); TabReplays(TabSupervisor *_tabSupervisor, AbstractClient *_client, const ServerInfo_User *currentUserInfo);
void retranslateUi() override; void retranslateUi() override;
QString getTabText() const override QString getTabText() const override
{ {

View file

@ -280,6 +280,7 @@ void TabSupervisor::initStartupTabs()
checkAndTrigger(aTabVisualDeckStorage, SettingsCache::instance().getTabVisualDeckStorageOpen()); checkAndTrigger(aTabVisualDeckStorage, SettingsCache::instance().getTabVisualDeckStorageOpen());
checkAndTrigger(aTabDeckStorage, SettingsCache::instance().getTabDeckStorageOpen()); checkAndTrigger(aTabDeckStorage, SettingsCache::instance().getTabDeckStorageOpen());
checkAndTrigger(aTabReplays, SettingsCache::instance().getTabReplaysOpen());
} }
/** /**
@ -336,6 +337,7 @@ void TabSupervisor::resetTabsMenu()
tabsMenu->addSeparator(); tabsMenu->addSeparator();
tabsMenu->addAction(aTabVisualDeckStorage); tabsMenu->addAction(aTabVisualDeckStorage);
tabsMenu->addAction(aTabDeckStorage); tabsMenu->addAction(aTabDeckStorage);
tabsMenu->addAction(aTabReplays);
} }
void TabSupervisor::start(const ServerInfo_User &_userInfo) void TabSupervisor::start(const ServerInfo_User &_userInfo)
@ -356,12 +358,6 @@ void TabSupervisor::start(const ServerInfo_User &_userInfo)
updatePingTime(0, -1); updatePingTime(0, -1);
if (userInfo->user_level() & ServerInfo_User::IsRegistered) {
tabsMenu->addAction(aTabReplays);
checkAndTrigger(aTabReplays, SettingsCache::instance().getTabReplaysOpen());
}
if (userInfo->user_level() & ServerInfo_User::IsModerator) { if (userInfo->user_level() & ServerInfo_User::IsModerator) {
tabsMenu->addSeparator(); tabsMenu->addSeparator();
tabsMenu->addAction(aTabAdmin); tabsMenu->addAction(aTabAdmin);
@ -379,7 +375,6 @@ void TabSupervisor::startLocal(const QList<AbstractClient *> &_clients)
resetTabsMenu(); resetTabsMenu();
tabAccount = nullptr; tabAccount = nullptr;
tabReplays = nullptr;
tabAdmin = nullptr; tabAdmin = nullptr;
tabLog = nullptr; tabLog = nullptr;
isLocalGame = true; isLocalGame = true;
@ -415,9 +410,6 @@ void TabSupervisor::stop()
if (tabServer) { if (tabServer) {
tabServer->closeRequest(true); tabServer->closeRequest(true);
} }
if (tabReplays) {
tabReplays->closeRequest(true);
}
if (tabAdmin) { if (tabAdmin) {
tabAdmin->closeRequest(true); tabAdmin->closeRequest(true);
} }
@ -520,7 +512,7 @@ void TabSupervisor::actTabReplays(bool checked)
{ {
SettingsCache::instance().setTabReplaysOpen(checked); SettingsCache::instance().setTabReplaysOpen(checked);
if (checked && !tabReplays) { if (checked && !tabReplays) {
tabReplays = new TabReplays(this, client); tabReplays = new TabReplays(this, client, userInfo);
connect(tabReplays, &TabReplays::openReplay, this, &TabSupervisor::openReplay); connect(tabReplays, &TabReplays::openReplay, this, &TabSupervisor::openReplay);
myAddTab(tabReplays, aTabReplays); myAddTab(tabReplays, aTabReplays);
connect(tabReplays, &Tab::closed, this, [this] { connect(tabReplays, &Tab::closed, this, [this] {

View file

@ -43,7 +43,7 @@ RemoteReplayList_TreeModel::RemoteReplayList_TreeModel(AbstractClient *_client,
RemoteReplayList_TreeModel::~RemoteReplayList_TreeModel() RemoteReplayList_TreeModel::~RemoteReplayList_TreeModel()
{ {
clearTree(); clearAll();
} }
int RemoteReplayList_TreeModel::rowCount(const QModelIndex &parent) const int RemoteReplayList_TreeModel::rowCount(const QModelIndex &parent) const
@ -242,7 +242,10 @@ ServerInfo_ReplayMatch const *RemoteReplayList_TreeModel::getEnclosingReplayMatc
return &node->getMatchInfo(); return &node->getMatchInfo();
} }
void RemoteReplayList_TreeModel::clearTree() /**
* Deletes all items in the model
*/
void RemoteReplayList_TreeModel::clearAll()
{ {
for (int i = 0; i < replayMatches.size(); ++i) for (int i = 0; i < replayMatches.size(); ++i)
delete replayMatches[i]; delete replayMatches[i];
@ -258,6 +261,13 @@ void RemoteReplayList_TreeModel::refreshTree()
client->sendCommand(pend); client->sendCommand(pend);
} }
void RemoteReplayList_TreeModel::clearTree()
{
beginResetModel();
clearAll();
endResetModel();
}
void RemoteReplayList_TreeModel::addMatchInfo(const ServerInfo_ReplayMatch &matchInfo) void RemoteReplayList_TreeModel::addMatchInfo(const ServerInfo_ReplayMatch &matchInfo)
{ {
beginInsertRows(QModelIndex(), replayMatches.size(), replayMatches.size()); beginInsertRows(QModelIndex(), replayMatches.size(), replayMatches.size());
@ -294,7 +304,7 @@ void RemoteReplayList_TreeModel::replayListFinished(const Response &r)
const Response_ReplayList &resp = r.GetExtension(Response_ReplayList::ext); const Response_ReplayList &resp = r.GetExtension(Response_ReplayList::ext);
beginResetModel(); beginResetModel();
clearTree(); clearAll();
for (int i = 0; i < resp.match_list_size(); ++i) for (int i = 0; i < resp.match_list_size(); ++i)
replayMatches.append(new MatchNode(resp.match_list(i))); replayMatches.append(new MatchNode(resp.match_list(i)));

View file

@ -73,7 +73,7 @@ private:
QList<MatchNode *> replayMatches; QList<MatchNode *> replayMatches;
QIcon dirIcon, fileIcon, lockIcon; QIcon dirIcon, fileIcon, lockIcon;
void clearTree(); void clearAll();
static const int numberOfColumns; static const int numberOfColumns;
signals: signals:
@ -94,6 +94,7 @@ public:
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
QModelIndex parent(const QModelIndex &index) const; QModelIndex parent(const QModelIndex &index) const;
Qt::ItemFlags flags(const QModelIndex &index) const; Qt::ItemFlags flags(const QModelIndex &index) const;
void clearTree();
void refreshTree(); void refreshTree();
ServerInfo_Replay const *getReplay(const QModelIndex &index) const; ServerInfo_Replay const *getReplay(const QModelIndex &index) const;
ServerInfo_ReplayMatch const *getReplayMatch(const QModelIndex &index) const; ServerInfo_ReplayMatch const *getReplayMatch(const QModelIndex &index) const;
@ -115,6 +116,10 @@ public:
ServerInfo_ReplayMatch const *getReplayMatch(const QModelIndex &ind) const; ServerInfo_ReplayMatch const *getReplayMatch(const QModelIndex &ind) const;
QList<ServerInfo_Replay const *> getSelectedReplays() const; QList<ServerInfo_Replay const *> getSelectedReplays() const;
QSet<ServerInfo_ReplayMatch const *> getSelectedReplayMatches() const; QSet<ServerInfo_ReplayMatch const *> getSelectedReplayMatches() const;
void clearTree()
{
treeModel->clearTree();
}
void refreshTree() void refreshTree()
{ {
treeModel->refreshTree(); treeModel->refreshTree();