serverlist.h
1 //------------------------------------------------------------------------------
2 // serverlist.h
3 //------------------------------------------------------------------------------
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301, USA.
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2009 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 
24 #ifndef __SERVERLIST_H_
25 #define __SERVERLIST_H_
26 
27 #include <QObject>
28 #include <QTimer>
29 
30 #include "serverapi/serverptr.h"
31 
32 class EnginePlugin;
33 class PWad;
34 class IniSection;
35 class Server;
37 class ServerListModel;
39 class ServerListView;
40 class WadFindResult;
41 class QAction;
42 class QItemSelection;
43 class QModelIndex;
44 class QPoint;
45 class QSortFilterProxyModel;
46 
47 class ServerList : public QObject
48 {
49  Q_OBJECT
50 
51  public:
52  ServerList(ServerListView* serverTable, QWidget* pMainWindow);
53  ~ServerList();
54 
55  void cleanUpForce();
56 
57  QWidget* getMainWindow() { return mainWindow; }
58  bool hasAtLeastOneServer() const;
59 
60  bool isAnyColumnSortedAdditionally() const;
61  bool isSortingAdditionallyByColumn(int column) const;
62  bool isSortingByColumn(int columnIndex);
63 
64  void removeCustomServers();
65  void removeNonSpecialServers();
66  QList<ServerPtr> selectedServers() const;
67  QList<ServerPtr> servers() const;
68  QList<ServerPtr> serversForPlugin(const EnginePlugin *plugin) const;
69 
70  ServerPtr serverFromIndex(const QModelIndex&);
71 
72  public slots:
73  void applyFilter(const ServerListFilterInfo& filterInfo);
74  void cleanUp();
78  void lookupHosts();
79  void redraw();
80  void refreshSelected();
81  void registerServer(ServerPtr server);
82  void removeServer(const ServerPtr &server);
88  void setGroupServersWithPlayersAtTop(bool b);
89 
90  void tableMiddleClicked(const QModelIndex& index, const QPoint& cursorPosition);
91  void tableRightClicked(const QModelIndex& index, const QPoint& cursorPosition);
92  void updateCountryFlags();
93  void updateSearch(const QString& search);
94 
95  signals:
99  void displayServerJoinCommandLine(const ServerPtr&);
100 
105  void findMissingWADs(const ServerPtr&);
106 
107  void serverDeregistered(ServerPtr);
108  void serverFilterModified(const ServerListFilterInfo& filter);
113  void serverInfoUpdated(const ServerPtr&);
114  void serverRegistered(ServerPtr);
115  void serverDoubleClicked(const ServerPtr&);
116  void serversSelected(QList<ServerPtr>&);
117 
118  private:
119  QTimer cleanerTimer;
120  QWidget* mainWindow;
121  ServerListModel* model;
122  bool needsCleaning;
123  ServerListProxyModel *proxyModel;
124  Qt::SortOrder sortOrder;
125  int sortIndex;
126  ServerListView* table;
127 
128  bool areColumnsWidthsSettingsChanged();
129 
130  void connectTableModelProxySlots();
131  void clearAdditionalSorting();
132 
133  ServerListModel* createModel();
134  ServerListProxyModel *createSortingProxy(ServerListModel* serverListModel);
135 
136  Qt::SortOrder getColumnDefaultSortOrder(int columnId);
137 
138  void initCleanerTimer();
139 
140  void prepareServerTable();
141 
142  void removeAdditionalSortingForColumn(const QModelIndex &modelIndex);
143  void saveColumnsWidthsSettings();
144 
145  void setupTableColumnWidths();
146  void setupTableProperties(QSortFilterProxyModel* tableModel);
147 
148  void sortAdditionally(const QModelIndex &modelIndex, Qt::SortOrder order);
149 
150  Qt::SortOrder swappedCurrentSortOrder();
151 
152  void updateCountryFlags(bool force);
153 
154  private slots:
155  void columnHeaderClicked(int);
156  void contextMenuAboutToHide();
157  void contextMenuTriggered(QAction* action);
158  void doubleClicked(const QModelIndex&);
159  void itemSelected(const QItemSelection&);
160  void mouseEntered(const QModelIndex&);
161  void saveAdditionalSortingConfig();
162  void onServerBegunRefreshing(const ServerPtr &server);
163  void onServerUpdated(const ServerPtr &server);
164  void updateHeaderTitles();
165 };
166 
167 #endif
void displayServerJoinCommandLine(const ServerPtr &)
Structure describing server filter.
PWAD hosted on a server.
A representation of a server for a given game.
Definition: server.h:93
void lookupHosts()
Looks up hosts for all available servers.
Definition: serverlist.cpp:292
void serverInfoUpdated(const ServerPtr &)
Emitted every time when a server info is updated through onServerUpdated().
void findMissingWADs(const ServerPtr &)
void setCountryFlagsIfNotPresent()
Sets country flags for servers that don&#39;t have flags present yet.
Definition: serverlist.cpp:483
INI section representation.
Definition: inisection.h:40