replays expire after two weeks, lock can be toggled to prevent that

This commit is contained in:
Max-Wilhelm Bruker 2012-03-04 11:35:56 +01:00
parent a876a0bf5f
commit acb03c2bf2
15 changed files with 127 additions and 23 deletions

View file

@ -20,6 +20,7 @@ private:
Response::ResponseCode cmdDeckDownload(const Command_DeckDownload & /*cmd*/, ResponseContainer & /*rc*/) { return Response::RespFunctionNotAllowed; }
Response::ResponseCode cmdReplayList(const Command_ReplayList & /*cmd*/, ResponseContainer & /*rc*/) { return Response::RespFunctionNotAllowed; }
Response::ResponseCode cmdReplayDownload(const Command_ReplayDownload & /*cmd*/, ResponseContainer & /*rc*/) { return Response::RespFunctionNotAllowed; }
Response::ResponseCode cmdReplayModifyMatch(const Command_ReplayModifyMatch &cmd, ResponseContainer &rc) { return Response::RespFunctionNotAllowed; }
Response::ResponseCode cmdBanFromServer(const Command_BanFromServer & /*cmd*/, ResponseContainer & /*rc*/) { return Response::RespFunctionNotAllowed; }
Response::ResponseCode cmdShutdownServer(const Command_ShutdownServer & /*cmd*/, ResponseContainer & /*rc*/) { return Response::RespFunctionNotAllowed; }
Response::ResponseCode cmdUpdateServerMessage(const Command_UpdateServerMessage & /*cmd*/, ResponseContainer & /*rc*/) { return Response::RespFunctionNotAllowed; }

View file

@ -9,6 +9,8 @@
#include "pb/response_replay_list.pb.h"
#include "pb/serverinfo_replay.pb.h"
const int RemoteReplayList_TreeModel::numberOfColumns = 6;
RemoteReplayList_TreeModel::MatchNode::MatchNode(const ServerInfo_ReplayMatch &_matchInfo)
: RemoteReplayList_TreeModel::Node(QString::fromStdString(_matchInfo.game_name())), matchInfo(_matchInfo)
{
@ -22,12 +24,18 @@ RemoteReplayList_TreeModel::MatchNode::~MatchNode()
delete at(i);
}
void RemoteReplayList_TreeModel::MatchNode::updateMatchInfo(const ServerInfo_ReplayMatch &_matchInfo)
{
matchInfo.MergeFrom(_matchInfo);
}
RemoteReplayList_TreeModel::RemoteReplayList_TreeModel(AbstractClient *_client, QObject *parent)
: QAbstractItemModel(parent), client(_client)
{
QFileIconProvider fip;
dirIcon = fip.icon(QFileIconProvider::Folder);
fileIcon = fip.icon(QFileIconProvider::File);
lockIcon = QIcon(":/resources/lock.svg");
refreshTree();
}
@ -49,16 +57,11 @@ int RemoteReplayList_TreeModel::rowCount(const QModelIndex &parent) const
return 0;
}
int RemoteReplayList_TreeModel::columnCount(const QModelIndex &/*parent*/) const
{
return 5;
}
QVariant RemoteReplayList_TreeModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
if (index.column() > 4)
if (index.column() >= numberOfColumns)
return QVariant();
ReplayNode *replayNode = dynamic_cast<ReplayNode *>(static_cast<Node *>(index.internalPointer()));
@ -71,7 +74,7 @@ QVariant RemoteReplayList_TreeModel::data(const QModelIndex &index, int role) co
switch (index.column()) {
case 0: return replayInfo.replay_id();
case 1: return QString::fromStdString(replayInfo.replay_name());
case 4: return replayInfo.duration();
case 5: return replayInfo.duration();
default: return QVariant();
}
}
@ -94,13 +97,17 @@ QVariant RemoteReplayList_TreeModel::data(const QModelIndex &index, int role) co
playerList.append(QString::fromStdString(matchInfo.player_names(i)));
return playerList.join(", ");
}
case 3: return QDateTime::fromTime_t(matchInfo.time_started());
case 4: return matchInfo.length();
case 4: return QDateTime::fromTime_t(matchInfo.time_started());
case 5: return matchInfo.length();
default: return QVariant();
}
}
case Qt::DecorationRole:
return index.column() == 0 ? dirIcon : QVariant();
switch (index.column()) {
case 0: return dirIcon;
case 3: return matchInfo.do_not_hide() ? lockIcon : QVariant();
default: return QVariant();
}
}
}
return QVariant();
@ -118,8 +125,9 @@ QVariant RemoteReplayList_TreeModel::headerData(int section, Qt::Orientation ori
case 0: return tr("ID");
case 1: return tr("Name");
case 2: return tr("Players");
case 3: return tr("Time started");
case 4: return tr("Duration (sec)");
case 3: return tr("Keep");
case 4: return tr("Time started");
case 5: return tr("Duration (sec)");
default: return QVariant();
}
}
@ -180,9 +188,13 @@ ServerInfo_ReplayMatch const* RemoteReplayList_TreeModel::getReplayMatch(const Q
return 0;
MatchNode *node = dynamic_cast<MatchNode *>(static_cast<Node *>(index.internalPointer()));
if (!node)
return 0;
return &node->getMatchInfo();
if (!node) {
ReplayNode *node = dynamic_cast<ReplayNode *>(static_cast<Node *>(index.internalPointer()));
if (!node)
return 0;
return &node->getParent()->getMatchInfo();
} else
return &node->getMatchInfo();
}
void RemoteReplayList_TreeModel::clearTree()
@ -209,6 +221,16 @@ void RemoteReplayList_TreeModel::addMatchInfo(const ServerInfo_ReplayMatch &matc
emit treeRefreshed();
}
void RemoteReplayList_TreeModel::updateMatchInfo(int gameId, const ServerInfo_ReplayMatch &matchInfo)
{
for (int i = 0; i < replayMatches.size(); ++i)
if (replayMatches[i]->getMatchInfo().game_id() == gameId) {
replayMatches[i]->updateMatchInfo(matchInfo);
emit dataChanged(createIndex(i, 0, (void *) replayMatches[i]), createIndex(i, numberOfColumns - 1, (void *) replayMatches[i]));
break;
}
}
void RemoteReplayList_TreeModel::replayListFinished(const Response &r)
{
const Response_ReplayList &resp = r.GetExtension(Response_ReplayList::ext);
@ -246,7 +268,7 @@ ServerInfo_Replay const *RemoteReplayList_TreeWidget::getCurrentReplay() const
return treeModel->getReplay(proxyModel->mapToSource(selectionModel()->currentIndex()));
}
void RemoteReplayList_TreeWidget::addMatchInfo(const ServerInfo_ReplayMatch &matchInfo)
ServerInfo_ReplayMatch const *RemoteReplayList_TreeWidget::getCurrentReplayMatch() const
{
treeModel->addMatchInfo(matchInfo);
return treeModel->getReplayMatch(proxyModel->mapToSource(selectionModel()->currentIndex()));
}

View file

@ -33,6 +33,7 @@ private:
~MatchNode();
void clearTree();
const ServerInfo_ReplayMatch &getMatchInfo() { return matchInfo; }
void updateMatchInfo(const ServerInfo_ReplayMatch &_matchInfo);
};
class ReplayNode : public Node {
private:
@ -48,8 +49,10 @@ private:
AbstractClient *client;
QList<MatchNode *> replayMatches;
QIcon dirIcon, fileIcon;
QIcon dirIcon, fileIcon, lockIcon;
void clearTree();
static const int numberOfColumns;
signals:
void treeRefreshed();
private slots:
@ -58,7 +61,7 @@ public:
RemoteReplayList_TreeModel(AbstractClient *_client, QObject *parent = 0);
~RemoteReplayList_TreeModel();
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &/*parent*/ = QModelIndex()) const;
int columnCount(const QModelIndex &/*parent*/ = QModelIndex()) const { return numberOfColumns; }
QVariant data(const QModelIndex &index, int role) const;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
@ -68,6 +71,7 @@ public:
ServerInfo_Replay const* getReplay(const QModelIndex &index) const;
ServerInfo_ReplayMatch const* getReplayMatch(const QModelIndex &index) const;
void addMatchInfo(const ServerInfo_ReplayMatch &matchInfo);
void updateMatchInfo(int gameId, const ServerInfo_ReplayMatch &matchInfo);
};
class RemoteReplayList_TreeWidget : public QTreeView {
@ -80,7 +84,8 @@ public:
ServerInfo_Replay const *getCurrentReplay() const;
ServerInfo_ReplayMatch const *getCurrentReplayMatch() const;
void refreshTree();
void addMatchInfo(const ServerInfo_ReplayMatch &matchInfo);
void addMatchInfo(const ServerInfo_ReplayMatch &matchInfo) { treeModel->addMatchInfo(matchInfo); }
void updateMatchInfo(int gameId, const ServerInfo_ReplayMatch &matchInfo) { treeModel->updateMatchInfo(gameId, matchInfo); }
};
#endif

View file

@ -20,6 +20,7 @@
#include "pb/response.pb.h"
#include "pb/response_replay_download.pb.h"
#include "pb/command_replay_download.pb.h"
#include "pb/command_replay_modify_match.pb.h"
#include "pb/event_replay_added.pb.h"
TabReplays::TabReplays(TabSupervisor *_tabSupervisor, AbstractClient *_client)
@ -84,10 +85,14 @@ TabReplays::TabReplays(TabSupervisor *_tabSupervisor, AbstractClient *_client)
aDownload = new QAction(this);
aDownload->setIcon(QIcon(":/resources/arrow_left_green.svg"));
connect(aDownload, SIGNAL(triggered()), this, SLOT(actDownload()));
aKeep = new QAction(this);
aKeep->setIcon(QIcon(":/resources/lock.svg"));
connect(aKeep, SIGNAL(triggered()), this, SLOT(actKeepRemoteReplay()));
leftToolBar->addAction(aOpenLocalReplay);
rightToolBar->addAction(aOpenRemoteReplay);
rightToolBar->addAction(aDownload);
rightToolBar->addAction(aKeep);
retranslateUi();
setLayout(hbox);
@ -103,6 +108,7 @@ void TabReplays::retranslateUi()
aOpenLocalReplay->setText(tr("Watch replay"));
aOpenRemoteReplay->setText(tr("Watch replay"));
aDownload->setText(tr("Download replay"));
aKeep->setText(tr("Toggle expiration lock"));
}
void TabReplays::actOpenLocalReplay()
@ -187,6 +193,35 @@ void TabReplays::downloadFinished(const Response &r)
f.close();
}
void TabReplays::actKeepRemoteReplay()
{
ServerInfo_ReplayMatch const *curRight = serverDirView->getCurrentReplayMatch();
if (!curRight)
return;
Command_ReplayModifyMatch cmd;
cmd.set_game_id(curRight->game_id());
cmd.set_do_not_hide(!curRight->do_not_hide());
PendingCommand *pend = client->prepareSessionCommand(cmd);
connect(pend, SIGNAL(finished(const Response &)), this, SLOT(keepRemoteReplayFinished(const Response &)));
client->sendCommand(pend);
}
void TabReplays::keepRemoteReplayFinished(const Response &r)
{
if (r.response_code() != Response::RespOk)
return;
PendingCommand *pend = static_cast<PendingCommand *>(sender());
const Command_ReplayModifyMatch &cmd = pend->getCommandContainer().session_command(0).GetExtension(Command_ReplayModifyMatch::ext);
ServerInfo_ReplayMatch temp;
temp.set_do_not_hide(cmd.do_not_hide());
serverDirView->updateMatchInfo(cmd.game_id(), temp);
}
void TabReplays::replayAddedEventReceived(const Event_ReplayAdded &event)
{
serverDirView->addMatchInfo(event.match_info());

View file

@ -25,7 +25,7 @@ private:
RemoteReplayList_TreeWidget *serverDirView;
QGroupBox *leftGroupBox, *rightGroupBox;
QAction *aOpenLocalReplay, *aOpenRemoteReplay, *aDownload;
QAction *aOpenLocalReplay, *aOpenRemoteReplay, *aDownload, *aKeep;
private slots:
void actOpenLocalReplay();
@ -35,6 +35,9 @@ private slots:
void actDownload();
void downloadFinished(const Response &r);
void actKeepRemoteReplay();
void keepRemoteReplayFinished(const Response &r);
void replayAddedEventReceived(const Event_ReplayAdded &event);
signals:
void openReplay(GameReplay *replay);