Debian Codegraph @

src/network/room.h

raw symbols SCIP
1 /***************************************************************************
2 * Copyright (C) 2009 by The qGo Project *
3 * *
4 * This file is part of qGo. *
5 * *
6 * qGo is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, see <http://www.gnu.org/licenses/> *
18 * or write to the Free Software Foundation, Inc., *
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20 ***************************************************************************/
21
22
23 #ifndef ROOM_H
24 #define ROOM_H
25
26 #include <QObject>
27 #include <QString>
28 #include <QTableView>
29
30 class NetworkConnection;
31 class BoardDispatch;
32 class PlayerListing;
33 class GameListing;
34 class FilteredView;
35 class PlayerListModel;
36 class GamesListModel;
37 class Talk;
38
39 /* The main purpose of this class is to manage player and game listings.
40 * Listings must be created and retrieved using get...() methods of this class.
41 * After modification of a listing, the corresponding recv...() method should be called
42 * (this can be done asynchronously using Qt's signal/slot mechanism).
43 * In the current implementation listings are never removed, so other objects may rely
44 * on pointers to listings remaining valid (until the connection is destroyed). */
45
46 class Room : public QObject
47 {
48 Q_OBJECT
49
50 public:
51 Room(NetworkConnection * c);
52 void setConnection(NetworkConnection * c);
53 virtual ~Room();
54 void onError(void);
55 void recvToggle(int type, bool val);
56
57 // These functions create a listing if it does not exist
58 PlayerListing * getPlayerListing(const QString & name);
59 PlayerListing * getPlayerListing(const unsigned int id);
60 PlayerListing * getPlayerListingByNotNickname(const QString & notnickname);
61 GameListing * getGameListing(unsigned int key);
62
63 BoardDispatch * getNewBoardDispatch(unsigned int key);
64
65 // This function creates a Talk if it does not exist
66 Talk * getTalk(PlayerListing *opponent);
67 // This function returns NULL if no Talk exists
68 Talk * getIfTalk(const PlayerListing *opponent);
69 void closeTalk(const PlayerListing *opponent);
70
71 void slot_refreshGames(void);
72 void slot_refreshPlayers(void);
73 void recvPlayerListing(PlayerListing *g);
74 void recvGameListing(GameListing *g);
75 protected:
76 unsigned int players;
77 unsigned int games;
78 private:
79 PlayerListModel * playerListModel;
80 GamesListModel * gamesListModel;
81
82 QTableView * playerView, * gamesView;
83 NetworkConnection * connection;
84 QModelIndex popup_item;
85
86 GameListing * popup_gamelisting;
87 PlayerListing * popup_playerlisting;
88
89 QAction *statsAct, *matchAct, *talkAct, *removeFriendAct, *addFriendAct, *removeWatchAct, *addWatchAct, *blockAct;
90 QAction *joinObserveAct, *observeOutsideAct;
91
92 QMap <const PlayerListing *, Talk *> talkMap;
93
94 // These functions expect QModelIndex from the proxy models
95 void slot_playerOpenTalk(const QModelIndex &);
96 void slot_gamesDoubleClicked(const QModelIndex &);
97 void slot_showPopup(const QPoint & iPoint);
98 void slot_showGamesPopup(const QPoint & iPoint);
99 private:
100 void openTalk(PlayerListing * listing);
101 };
102
103 #endif //ROOM_H