Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Donald Haase
Cockatrice
Commits
c6c6a970
Commit
c6c6a970
authored
Feb 25, 2012
by
Max-Wilhelm Bruker
Browse files
interface & client tab for replay transfer
parent
faf6b2c5
Changes
36
Hide whitespace changes
Inline
Side-by-side
cockatrice/CMakeLists.txt
View file @
c6c6a970
...
...
@@ -54,6 +54,7 @@ SET(cockatrice_SOURCES
src/tab_message.cpp
src/tab_game.cpp
src/tab_deck_storage.cpp
src/tab_replays.cpp
src/tab_supervisor.cpp
src/tab_admin.cpp
src/tab_userlists.cpp
...
...
@@ -61,6 +62,7 @@ SET(cockatrice_SOURCES
src/userlist.cpp
src/userinfobox.cpp
src/remotedecklist_treewidget.cpp
src/remotereplaylist_treewidget.cpp
src/deckview.cpp
src/playerlistwidget.cpp
src/pixmapgenerator.cpp
...
...
@@ -122,6 +124,7 @@ SET(cockatrice_HEADERS
src/tab_message.h
src/tab_game.h
src/tab_deck_storage.h
src/tab_replays.h
src/tab_supervisor.h
src/tab_admin.h
src/tab_userlists.h
...
...
@@ -129,6 +132,7 @@ SET(cockatrice_HEADERS
src/userlist.h
src/userinfobox.h
src/remotedecklist_treewidget.h
src/remotereplaylist_treewidget.h
src/deckview.h
src/playerlistwidget.h
src/settingscache.h
...
...
cockatrice/src/localserver.cpp
View file @
c6c6a970
...
...
@@ -20,9 +20,9 @@ LocalServerInterface *LocalServer::newConnection()
return
lsi
;
}
ServerInfo_User
LocalServer
::
getUserData
(
const
QString
&
name
)
ServerInfo_User
LocalServer
::
getUserData
(
const
QString
&
name
,
bool
/*withId*/
)
{
ServerInfo_User
result
;
result
.
set_name
(
name
.
toStdString
());
return
result
;
}
\ No newline at end of file
}
cockatrice/src/localserver.h
View file @
c6c6a970
...
...
@@ -14,7 +14,7 @@ public:
LocalServerInterface
*
newConnection
();
protected:
ServerInfo_User
getUserData
(
const
QString
&
name
);
ServerInfo_User
getUserData
(
const
QString
&
name
,
bool
withId
=
false
);
};
#endif
\ No newline at end of file
cockatrice/src/localserverinterface.h
View file @
c6c6a970
...
...
@@ -18,6 +18,8 @@ private:
Response
::
ResponseCode
cmdDeckDel
(
const
Command_DeckDel
&
/*cmd*/
,
ResponseContainer
&
/*rc*/
)
{
return
Response
::
RespFunctionNotAllowed
;
}
Response
::
ResponseCode
cmdDeckUpload
(
const
Command_DeckUpload
&
/*cmd*/
,
ResponseContainer
&
/*rc*/
)
{
return
Response
::
RespFunctionNotAllowed
;
}
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
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
;
}
...
...
cockatrice/src/playertarget.cpp
View file @
c6c6a970
...
...
@@ -51,7 +51,7 @@ PlayerTarget::PlayerTarget(Player *_owner, QGraphicsItem *parentItem)
{
setCacheMode
(
DeviceCoordinateCache
);
const
std
::
string
bmp
=
_owner
->
getUserInfo
()
->
avatar_bmp
();
const
std
::
string
&
bmp
=
_owner
->
getUserInfo
()
->
avatar_bmp
();
if
(
!
fullPixmap
.
loadFromData
((
const
uchar
*
)
bmp
.
data
(),
bmp
.
size
()))
fullPixmap
=
QPixmap
();
}
...
...
@@ -144,4 +144,4 @@ AbstractCounter *PlayerTarget::addCounter(int _counterId, const QString &_name,
void
PlayerTarget
::
delCounter
()
{
playerCounter
=
0
;
}
\ No newline at end of file
}
cockatrice/src/remotedecklist_treewidget.cpp
View file @
c6c6a970
...
...
@@ -5,7 +5,7 @@
#include
"abstractclient.h"
#include
"pending_command.h"
#include
"pb/
session_commands
.pb.h"
#include
"pb/
command_deck_list
.pb.h"
#include
"pb/response_deck_list.pb.h"
#include
"pb/serverinfo_deckstorage.pb.h"
...
...
cockatrice/src/remotereplaylist_treewidget.cpp
0 → 100644
View file @
c6c6a970
#include
<QFileIconProvider>
#include
<QHeaderView>
#include
<QSortFilterProxyModel>
#include
"remotereplaylist_treewidget.h"
#include
"abstractclient.h"
#include
"pending_command.h"
#include
"pb/command_replay_list.pb.h"
#include
"pb/response_replay_list.pb.h"
#include
"pb/serverinfo_replay.pb.h"
RemoteReplayList_TreeModel
::
RemoteReplayList_TreeModel
(
AbstractClient
*
_client
,
QObject
*
parent
)
:
QAbstractItemModel
(
parent
),
client
(
_client
)
{
QFileIconProvider
fip
;
fileIcon
=
fip
.
icon
(
QFileIconProvider
::
File
);
refreshTree
();
}
RemoteReplayList_TreeModel
::~
RemoteReplayList_TreeModel
()
{
}
int
RemoteReplayList_TreeModel
::
rowCount
(
const
QModelIndex
&
parent
)
const
{
return
parent
.
isValid
()
?
0
:
replays
.
size
();
}
int
RemoteReplayList_TreeModel
::
columnCount
(
const
QModelIndex
&
/*parent*/
)
const
{
return
6
;
}
QVariant
RemoteReplayList_TreeModel
::
data
(
const
QModelIndex
&
index
,
int
role
)
const
{
if
(
!
index
.
isValid
())
return
QVariant
();
if
(
index
.
column
()
>
5
)
return
QVariant
();
ServerInfo_Replay
*
replayInfo
=
static_cast
<
ServerInfo_Replay
*>
(
index
.
internalPointer
());
switch
(
role
)
{
case
Qt
::
TextAlignmentRole
:
return
index
.
column
()
==
0
?
Qt
::
AlignRight
:
Qt
::
AlignLeft
;
case
Qt
::
DisplayRole
:
{
switch
(
index
.
column
())
{
case
0
:
return
replayInfo
->
game_id
();
case
1
:
return
QString
::
fromStdString
(
replayInfo
->
game_name
());
case
2
:
return
QString
::
fromStdString
(
replayInfo
->
replay_name
());
case
3
:
{
QStringList
playerList
;
for
(
int
i
=
0
;
i
<
replayInfo
->
player_names_size
();
++
i
)
playerList
.
append
(
QString
::
fromStdString
(
replayInfo
->
player_names
(
i
)));
return
playerList
.
join
(
", "
);
}
case
4
:
return
QDateTime
::
fromTime_t
(
replayInfo
->
time_started
());
case
5
:
return
replayInfo
->
length
();
default:
return
QVariant
();
}
}
case
Qt
::
DecorationRole
:
return
index
.
column
()
==
0
?
fileIcon
:
QVariant
();
}
return
QVariant
();
}
QVariant
RemoteReplayList_TreeModel
::
headerData
(
int
section
,
Qt
::
Orientation
orientation
,
int
role
)
const
{
if
(
orientation
!=
Qt
::
Horizontal
)
return
QVariant
();
switch
(
role
)
{
case
Qt
::
TextAlignmentRole
:
return
section
==
0
?
Qt
::
AlignRight
:
Qt
::
AlignLeft
;
case
Qt
::
DisplayRole
:
{
switch
(
section
)
{
case
0
:
return
tr
(
"Game ID"
);
case
1
:
return
tr
(
"Game name"
);
case
2
:
return
tr
(
"Replay name"
);
case
3
:
return
tr
(
"Players"
);
case
4
:
return
tr
(
"Time started"
);
case
5
:
return
tr
(
"Duration (sec)"
);
default:
return
QVariant
();
}
}
default:
return
QVariant
();
}
}
QModelIndex
RemoteReplayList_TreeModel
::
index
(
int
row
,
int
column
,
const
QModelIndex
&
parent
)
const
{
if
(
!
hasIndex
(
row
,
column
,
parent
))
return
QModelIndex
();
return
createIndex
(
row
,
column
,
(
void
*
)
&
(
replays
[
row
]));
}
QModelIndex
RemoteReplayList_TreeModel
::
parent
(
const
QModelIndex
&
ind
)
const
{
return
QModelIndex
();
}
Qt
::
ItemFlags
RemoteReplayList_TreeModel
::
flags
(
const
QModelIndex
&
index
)
const
{
if
(
!
index
.
isValid
())
return
0
;
return
Qt
::
ItemIsEnabled
|
Qt
::
ItemIsSelectable
;
}
ServerInfo_Replay
const
*
RemoteReplayList_TreeModel
::
getNode
(
const
QModelIndex
&
index
)
const
{
if
(
!
index
.
isValid
())
return
0
;
return
&
(
replays
[
index
.
row
()]);
}
void
RemoteReplayList_TreeModel
::
refreshTree
()
{
PendingCommand
*
pend
=
client
->
prepareSessionCommand
(
Command_ReplayList
());
connect
(
pend
,
SIGNAL
(
finished
(
const
Response
&
)),
this
,
SLOT
(
replayListFinished
(
const
Response
&
)));
client
->
sendCommand
(
pend
);
}
void
RemoteReplayList_TreeModel
::
replayListFinished
(
const
Response
&
r
)
{
const
Response_ReplayList
&
resp
=
r
.
GetExtension
(
Response_ReplayList
::
ext
);
beginResetModel
();
replays
.
clear
();
for
(
int
i
=
0
;
i
<
resp
.
replay_list_size
();
++
i
)
replays
.
append
(
resp
.
replay_list
(
i
));
endResetModel
();
emit
treeRefreshed
();
}
RemoteReplayList_TreeWidget
::
RemoteReplayList_TreeWidget
(
AbstractClient
*
_client
,
QWidget
*
parent
)
:
QTreeView
(
parent
)
{
treeModel
=
new
RemoteReplayList_TreeModel
(
_client
,
this
);
proxyModel
=
new
QSortFilterProxyModel
(
this
);
proxyModel
->
setSourceModel
(
treeModel
);
proxyModel
->
setDynamicSortFilter
(
true
);
proxyModel
->
setSortCaseSensitivity
(
Qt
::
CaseInsensitive
);
setModel
(
proxyModel
);
connect
(
treeModel
,
SIGNAL
(
treeRefreshed
()),
this
,
SLOT
(
expandAll
()));
header
()
->
setResizeMode
(
QHeaderView
::
ResizeToContents
);
setUniformRowHeights
(
true
);
setSortingEnabled
(
true
);
proxyModel
->
sort
(
0
,
Qt
::
AscendingOrder
);
header
()
->
setSortIndicator
(
0
,
Qt
::
AscendingOrder
);
}
ServerInfo_Replay
const
*
RemoteReplayList_TreeWidget
::
getNode
(
const
QModelIndex
&
ind
)
const
{
return
treeModel
->
getNode
(
proxyModel
->
mapToSource
(
ind
));
}
ServerInfo_Replay
const
*
RemoteReplayList_TreeWidget
::
getCurrentItem
()
const
{
return
getNode
(
selectionModel
()
->
currentIndex
());
}
cockatrice/src/remotereplaylist_treewidget.h
0 → 100644
View file @
c6c6a970
#ifndef REMOTEREPLAYLIST_TREEWIDGET_H
#define REMOTEREPLAYLIST_TREEWIDGET_H
#include
<QAbstractItemModel>
#include
<QDateTime>
#include
<QTreeView>
#include
"pb/serverinfo_replay.pb.h"
class
Response
;
class
AbstractClient
;
class
QSortFilterProxyModel
;
class
RemoteReplayList_TreeModel
:
public
QAbstractItemModel
{
Q_OBJECT
private:
AbstractClient
*
client
;
QList
<
ServerInfo_Replay
>
replays
;
QIcon
fileIcon
;
signals:
void
treeRefreshed
();
private
slots
:
void
replayListFinished
(
const
Response
&
r
);
public:
RemoteReplayList_TreeModel
(
AbstractClient
*
_client
,
QObject
*
parent
=
0
);
~
RemoteReplayList_TreeModel
();
int
rowCount
(
const
QModelIndex
&
parent
=
QModelIndex
())
const
;
int
columnCount
(
const
QModelIndex
&
/*parent*/
=
QModelIndex
())
const
;
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
;
QModelIndex
parent
(
const
QModelIndex
&
index
)
const
;
Qt
::
ItemFlags
flags
(
const
QModelIndex
&
index
)
const
;
void
refreshTree
();
ServerInfo_Replay
const
*
getNode
(
const
QModelIndex
&
index
)
const
;
};
class
RemoteReplayList_TreeWidget
:
public
QTreeView
{
private:
RemoteReplayList_TreeModel
*
treeModel
;
QSortFilterProxyModel
*
proxyModel
;
ServerInfo_Replay
const
*
getNode
(
const
QModelIndex
&
ind
)
const
;
public:
RemoteReplayList_TreeWidget
(
AbstractClient
*
_client
,
QWidget
*
parent
=
0
);
ServerInfo_Replay
const
*
getCurrentItem
()
const
;
void
refreshTree
();
};
#endif
cockatrice/src/tab_deck_storage.h
View file @
c6c6a970
...
...
@@ -12,7 +12,6 @@ class QToolBar;
class
QTreeWidget
;
class
QTreeWidgetItem
;
class
QGroupBox
;
class
ProtocolResponse
;
class
RemoteDeckList_TreeWidget
;
class
TabDeckStorage
:
public
Tab
{
...
...
cockatrice/src/tab_game.cpp
View file @
c6c6a970
...
...
@@ -957,6 +957,14 @@ CardItem *TabGame::getCard(int playerId, const QString &zoneName, int cardId) co
return
zone
->
getCard
(
cardId
,
QString
());
}
QString
TabGame
::
getTabText
()
const
{
if
(
replay
)
return
tr
(
"Replay %1: %2"
).
arg
(
gameId
).
arg
(
gameDescription
);
else
return
tr
(
"Game %1: %2"
).
arg
(
gameId
).
arg
(
gameDescription
);
}
Player
*
TabGame
::
getActiveLocalPlayer
()
const
{
Player
*
active
=
players
.
value
(
activePlayer
,
0
);
...
...
cockatrice/src/tab_game.h
View file @
c6c6a970
...
...
@@ -180,7 +180,7 @@ public:
CardItem
*
getCard
(
int
playerId
,
const
QString
&
zoneName
,
int
cardId
)
const
;
bool
isHost
()
const
{
return
hostId
==
localPlayerId
;
}
int
getGameId
()
const
{
return
gameId
;
}
QString
getTabText
()
const
{
return
tr
(
"Game %1: %2"
).
arg
(
gameId
).
arg
(
gameDescription
);
}
QString
getTabText
()
const
;
bool
getSpectator
()
const
{
return
spectator
;
}
bool
getSpectatorsCanTalk
()
const
{
return
spectatorsCanTalk
;
}
bool
getSpectatorsSeeEverything
()
const
{
return
spectatorsSeeEverything
;
}
...
...
cockatrice/src/tab_replays.cpp
0 → 100644
View file @
c6c6a970
#include
<QTreeView>
#include
<QFileSystemModel>
#include
<QSortFilterProxyModel>
#include
<QToolBar>
#include
<QVBoxLayout>
#include
<QHBoxLayout>
#include
<QAction>
#include
<QGroupBox>
#include
<QHeaderView>
#include
<QApplication>
#include
<QInputDialog>
#include
"tab_replays.h"
#include
"remotereplaylist_treewidget.h"
#include
"abstractclient.h"
#include
"tab_game.h"
#include
"settingscache.h"
#include
"pending_command.h"
#include
"pb/game_replay.pb.h"
#include
"pb/response.pb.h"
#include
"pb/response_replay_download.pb.h"
#include
"pb/command_replay_download.pb.h"
TabReplays
::
TabReplays
(
TabSupervisor
*
_tabSupervisor
,
AbstractClient
*
_client
)
:
Tab
(
_tabSupervisor
),
client
(
_client
)
{
localDirModel
=
new
QFileSystemModel
(
this
);
localDirModel
->
setRootPath
(
settingsCache
->
getReplaysPath
());
sortFilter
=
new
QSortFilterProxyModel
(
this
);
sortFilter
->
setSourceModel
(
localDirModel
);
sortFilter
->
setDynamicSortFilter
(
true
);
localDirView
=
new
QTreeView
;
localDirView
->
setModel
(
sortFilter
);
localDirView
->
setColumnHidden
(
1
,
true
);
localDirView
->
setRootIndex
(
sortFilter
->
mapFromSource
(
localDirModel
->
index
(
localDirModel
->
rootPath
(),
0
)));
localDirView
->
setSortingEnabled
(
true
);
localDirView
->
header
()
->
setResizeMode
(
QHeaderView
::
ResizeToContents
);
sortFilter
->
sort
(
0
,
Qt
::
AscendingOrder
);
localDirView
->
header
()
->
setSortIndicator
(
0
,
Qt
::
AscendingOrder
);
leftToolBar
=
new
QToolBar
;
leftToolBar
->
setOrientation
(
Qt
::
Horizontal
);
leftToolBar
->
setIconSize
(
QSize
(
32
,
32
));
QHBoxLayout
*
leftToolBarLayout
=
new
QHBoxLayout
;
leftToolBarLayout
->
addStretch
();
leftToolBarLayout
->
addWidget
(
leftToolBar
);
leftToolBarLayout
->
addStretch
();
QVBoxLayout
*
leftVbox
=
new
QVBoxLayout
;
leftVbox
->
addWidget
(
localDirView
);
leftVbox
->
addLayout
(
leftToolBarLayout
);
leftGroupBox
=
new
QGroupBox
;
leftGroupBox
->
setLayout
(
leftVbox
);
rightToolBar
=
new
QToolBar
;
rightToolBar
->
setOrientation
(
Qt
::
Horizontal
);
rightToolBar
->
setIconSize
(
QSize
(
32
,
32
));
QHBoxLayout
*
rightToolBarLayout
=
new
QHBoxLayout
;
rightToolBarLayout
->
addStretch
();
rightToolBarLayout
->
addWidget
(
rightToolBar
);
rightToolBarLayout
->
addStretch
();
serverDirView
=
new
RemoteReplayList_TreeWidget
(
client
);
QVBoxLayout
*
rightVbox
=
new
QVBoxLayout
;
rightVbox
->
addWidget
(
serverDirView
);
rightVbox
->
addLayout
(
rightToolBarLayout
);
rightGroupBox
=
new
QGroupBox
;
rightGroupBox
->
setLayout
(
rightVbox
);
QHBoxLayout
*
hbox
=
new
QHBoxLayout
;
hbox
->
addWidget
(
leftGroupBox
);
hbox
->
addWidget
(
rightGroupBox
);
aOpenLocalReplay
=
new
QAction
(
this
);
aOpenLocalReplay
->
setIcon
(
QIcon
(
":/resources/pencil.svg"
));
connect
(
aOpenLocalReplay
,
SIGNAL
(
triggered
()),
this
,
SLOT
(
actOpenLocalReplay
()));
aOpenRemoteReplay
=
new
QAction
(
this
);
aOpenRemoteReplay
->
setIcon
(
QIcon
(
":/resources/pencil.svg"
));
connect
(
aOpenRemoteReplay
,
SIGNAL
(
triggered
()),
this
,
SLOT
(
actOpenRemoteReplay
()));
aDownload
=
new
QAction
(
this
);
aDownload
->
setIcon
(
QIcon
(
":/resources/arrow_left_green.svg"
));
connect
(
aDownload
,
SIGNAL
(
triggered
()),
this
,
SLOT
(
actDownload
()));
leftToolBar
->
addAction
(
aOpenLocalReplay
);
rightToolBar
->
addAction
(
aOpenRemoteReplay
);
rightToolBar
->
addAction
(
aDownload
);
retranslateUi
();
setLayout
(
hbox
);
}
void
TabReplays
::
retranslateUi
()
{
leftGroupBox
->
setTitle
(
tr
(
"Local file system"
));
rightGroupBox
->
setTitle
(
tr
(
"Server replay storage"
));
aOpenLocalReplay
->
setText
(
tr
(
"Watch replay"
));
aOpenRemoteReplay
->
setText
(
tr
(
"Watch replay"
));
aDownload
->
setText
(
tr
(
"Download replay"
));
}
void
TabReplays
::
actOpenLocalReplay
()
{
QModelIndex
curLeft
=
sortFilter
->
mapToSource
(
localDirView
->
selectionModel
()
->
currentIndex
());
if
(
localDirModel
->
isDir
(
curLeft
))
return
;
QString
filePath
=
localDirModel
->
filePath
(
curLeft
);
QFile
f
(
filePath
);
if
(
!
f
.
open
(
QIODevice
::
ReadOnly
))
return
;
QByteArray
data
=
f
.
readAll
();
f
.
close
();
GameReplay
*
replay
=
new
GameReplay
;
replay
->
ParseFromArray
(
data
.
data
(),
data
.
size
());
emit
openReplay
(
replay
);
}
void
TabReplays
::
actOpenRemoteReplay
()
{
ServerInfo_Replay
const
*
curRight
=
serverDirView
->
getCurrentItem
();
if
(
!
curRight
)
return
;
Command_ReplayDownload
cmd
;
cmd
.
set_game_id
(
curRight
->
game_id
());
PendingCommand
*
pend
=
client
->
prepareSessionCommand
(
cmd
);
connect
(
pend
,
SIGNAL
(
finished
(
const
Response
&
)),
this
,
SLOT
(
openRemoteReplayFinished
(
const
Response
&
)));
client
->
sendCommand
(
pend
);
}
void
TabReplays
::
openRemoteReplayFinished
(
const
Response
&
r
)
{
const
Response_ReplayDownload
&
resp
=
r
.
GetExtension
(
Response_ReplayDownload
::
ext
);
GameReplay
*
replay
=
new
GameReplay
;
replay
->
ParseFromString
(
resp
.
replay_data
());
emit
openReplay
(
replay
);
}
void
TabReplays
::
actDownload
()
{
QString
filePath
;
QModelIndex
curLeft
=
sortFilter
->
mapToSource
(
localDirView
->
selectionModel
()
->
currentIndex
());
if
(
!
curLeft
.
isValid
())
filePath
=
localDirModel
->
rootPath
();
else
{
while
(
!
localDirModel
->
isDir
(
curLeft
))
curLeft
=
curLeft
.
parent
();
filePath
=
localDirModel
->
filePath
(
curLeft
);
}
ServerInfo_Replay
const
*
curRight
=
serverDirView
->
getCurrentItem
();
if
(
!
curRight
)
return
;
filePath
+=
QString
(
"/game_%1.cor"
).
arg
(
curRight
->
game_id
());
Command_ReplayDownload
cmd
;
cmd
.
set_game_id
(
curRight
->
game_id
());
PendingCommand
*
pend
=
client
->
prepareSessionCommand
(
cmd
);
pend
->
setExtraData
(
filePath
);
connect
(
pend
,
SIGNAL
(
finished
(
const
Response
&
)),
this
,
SLOT
(
downloadFinished
(
const
Response
&
)));
client
->
sendCommand
(
pend
);
}
void
TabReplays
::
downloadFinished
(
const
Response
&
r
)
{
const
Response_ReplayDownload
&
resp
=
r
.
GetExtension
(
Response_ReplayDownload
::
ext
);
PendingCommand
*
pend
=
static_cast
<
PendingCommand
*>
(
sender
());
QString
filePath
=
pend
->
getExtraData
().
toString
();
const
std
::
string
&
data
=
resp
.
replay_data
();
QFile
f
(
filePath
);
f
.
open
(
QIODevice
::
WriteOnly
);
f
.
write
((
const
char
*
)
data
.
data
(),
data
.
size
());
f
.
close
();
}
cockatrice/src/tab_replays.h
0 → 100644
View file @
c6c6a970
#ifndef TAB_REPLAYS_H
#define TAB_REPLAYS_H
#include
"tab.h"
#include
"pb/response.pb.h"
class
AbstractClient
;
class
QTreeView
;
class
QFileSystemModel
;
class
QSortFilterProxyModel
;
class
QToolBar
;
class
QGroupBox
;
class
RemoteReplayList_TreeWidget
;
class
GameReplay
;
class
TabReplays
:
public
Tab
{
Q_OBJECT
private:
AbstractClient
*
client
;
QTreeView
*
localDirView
;
QFileSystemModel
*
localDirModel
;
QSortFilterProxyModel
*
sortFilter
;
QToolBar
*
leftToolBar
,
*
rightToolBar
;
RemoteReplayList_TreeWidget
*
serverDirView
;
QGroupBox
*
leftGroupBox
,
*
rightGroupBox
;
QAction
*
aOpenLocalReplay
,
*
aOpenRemoteReplay
,
*
aDownload
;
private
slots
:
void
actOpenLocalReplay
();
void
actOpenRemoteReplay
();
void
openRemoteReplayFinished
(
const
Response
&
r
);
void
actDownload
();
void
downloadFinished
(
const
Response
&
r
);
signals:
void
openReplay
(
GameReplay
*
replay
);
public:
TabReplays
(
TabSupervisor
*
_tabSupervisor
,
AbstractClient
*
_client
);
void
retranslateUi
();
QString
getTabText
()
const
{
return
tr
(
"Game replays"
);
}
};
#endif
cockatrice/src/tab_supervisor.cpp
View file @
c6c6a970
...
...
@@ -5,6 +5,7 @@
#include
"tab_room.h"
#include
"tab_game.h"
#include
"tab_deck_storage.h"
#include
"tab_replays.h"
#include
"tab_admin.h"
#include
"tab_message.h"
#include
"tab_userlists.h"
...
...
@@ -138,8 +139,14 @@ void TabSupervisor::start(AbstractClient *_client, const ServerInfo_User &_userI
if
(
userInfo
->
user_level
()
&
ServerInfo_User
::
IsRegistered
)
{
tabDeckStorage
=
new
TabDeckStorage
(
this
,
client
);
myAddTab
(
tabDeckStorage
);
}
else
tabReplays
=
new
TabReplays
(
this
,
client
);
connect
(
tabReplays
,
SIGNAL
(
openReplay
(
GameReplay
*
)),
this
,
SLOT
(
openReplay
(
GameReplay
*
)));
myAddTab
(
tabReplays
);
}
else
{
tabDeckStorage
=
0
;
tabReplays
=
0
;
}
if
(
userInfo
->
user_level
()
&
ServerInfo_User
::
IsModerator
)
{
tabAdmin
=
new
TabAdmin
(
this
,
client
,
(
userInfo
->
user_level
()
&
ServerInfo_User
::
IsAdmin
));
...
...
@@ -155,6 +162,7 @@ void TabSupervisor::startLocal(const QList<AbstractClient *> &_clients)
{
tabUserLists
=
0
;
tabDeckStorage
=
0
;
tabReplays
=
0
;
tabAdmin
=
0
;
userInfo
=
new
ServerInfo_User
;
localClients
=
_clients
;
...
...
@@ -183,10 +191,12 @@ void TabSupervisor::stop()
tabUserLists
->
deleteLater
();
tabServer
->
deleteLater
();
tabDeckStorage
->
deleteLater
();
tabReplays
->
deleteLater
();
}
tabUserLists
=
0
;
tabServer
=
0
;
tabDeckStorage
=
0
;
tabReplays
=
0
;
clear
();
QMapIterator
<
int
,
TabRoom
*>
roomIterator
(
roomTabs
);
...
...
@@ -306,6 +316,12 @@ TabMessage *TabSupervisor::addMessageTab(const QString &receiverName, bool focus
return
tab
;
}
void
TabSupervisor
::
openReplay
(
GameReplay
*
replay
)
{
TabGame
*
replayTab
=
new
TabGame
(
replay
);
myAddTab
(
replayTab
);
}
void
TabSupervisor
::
talkLeft
(
TabMessage
*
tab
)
{
emit
setMenu
(
0
);
...
...
cockatrice/src/tab_supervisor.h
View file @
c6c6a970
...
...
@@ -12,6 +12,7 @@ class TabServer;
class
TabRoom
;
class
TabGame
;
class
TabDeckStorage
;
class
TabReplays
;
class
TabAdmin
;
class
TabMessage
;
class
TabUserLists
;
...
...
@@ -21,6 +22,7 @@ class Event_GameJoined;
class
Event_UserMessage
;
class
ServerInfo_Room
;
class
ServerInfo_User
;
class
GameReplay
;
class
CloseButton
:
public
QAbstractButton
{
Q_OBJECT
...
...
@@ -44,6 +46,7 @@ private:
TabServer
*
tabServer
;
TabUserLists
*
tabUserLists
;
TabDeckStorage
*
tabDeckStorage
;
TabReplays
*
tabReplays
;
TabAdmin
*
tabAdmin
;
QMap
<
int
,
TabRoom
*>
roomTabs
;
QMap
<
int
,
TabGame
*>
gameTabs
;
...
...
@@ -77,6 +80,7 @@ private slots:
void
addRoomTab
(
const
ServerInfo_Room
&
info
,
bool
setCurrent
);
void
roomLeft
(
TabRoom
*
tab
);
TabMessage
*
addMessageTab
(
const
QString
&
userName
,
bool
focus
);
void
openReplay
(
GameReplay
*
replay
);
void
processUserLeft
(
const
QString
&
userName
);
void
processUserJoined
(
const
QString
&
userName
);
void
talkLeft
(
TabMessage
*
tab
);
...
...
common/pb/CMakeLists.txt
View file @
c6c6a970
...
...
@@ -12,6 +12,7 @@ SET(PROTO_FILES
command_deck_del_dir.proto
command_deck_del.proto
command_deck_download.proto
command_deck_list.proto
command_deck_new_dir.proto
command_deck_select.proto
command_deck_upload.proto
...
...
@@ -29,6 +30,8 @@ SET(PROTO_FILES
command_mulligan.proto
command_next_turn.proto
command_ready_start.proto
command_replay_list.proto
command_replay_download.proto
command_reveal_cards.proto
command_roll_die.proto
command_set_active_phase.proto
...
...
@@ -107,6 +110,8 @@ SET(PROTO_FILES
response_join_room.proto
response_list_users.proto
response_login.proto
response_replay_download.proto
response_replay_list.proto
response.proto
room_commands.proto
room_event.proto
...
...
@@ -120,6 +125,7 @@ SET(PROTO_FILES
serverinfo_playerping.proto
serverinfo_playerproperties.proto
serverinfo_player.proto
serverinfo_replay.proto
serverinfo_room.proto
serverinfo_user.proto
serverinfo_zone.proto
...
...
common/pb/command_deck_list.proto
0 → 100644
View file @
c6c6a970
import
"session_commands.proto"
;
message
Command_DeckList
{
extend
SessionCommand
{
optional
Command_DeckList
ext
=
1008
;
}
}
common/pb/command_replay_download.proto
0 → 100644
View file @
c6c6a970
import
"session_commands.proto"
;
message
Command_ReplayDownload
{
extend
SessionCommand
{
optional
Command_ReplayDownload
ext
=
1101
;
}
optional
sint32
game_id
=
1
[
default
=
-
1
];
}
common/pb/command_replay_list.proto
0 → 100644
View file @
c6c6a970
import
"session_commands.proto"
;
message
Command_ReplayList
{
extend
SessionCommand
{
optional
Command_ReplayList
ext
=
1100
;
}
}
common/pb/response.proto
View file @
c6c6a970
...
...
@@ -20,6 +20,7 @@ message Response {
RespWouldOverwriteOldSession
=
17
;
RespChatFlood
=
18
;
RespUserIsBanned
=
19
;
RespAccessDenied
=
20
;
}
enum
ResponseType
{
JOIN_ROOM
=
1000
;
...
...
@@ -31,6 +32,8 @@ message Response {
DECK_LIST
=
1006
;
DECK_DOWNLOAD
=
1007
;
DECK_UPLOAD
=
1008
;
REPLAY_LIST
=
1100
;
REPLAY_DOWNLOAD
=
1101
;
}
required
uint64
cmd_id
=
1
;
optional
ResponseCode
response_code
=
2
;
...
...
Prev
1
2
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment