mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-18 16:32:16 -07:00
handle connect/disconnect in replays tab
This commit is contained in:
parent
c97e6aa43e
commit
2109f4d4a1
3 changed files with 44 additions and 3 deletions
|
|
@ -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)) {
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -512,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] {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue