serverlist.h
1 //------------------------------------------------------------------------------
2 // serverlist.h
3 //------------------------------------------------------------------------------
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library 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 GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; 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 MainWindow;
36 class Server;
38 class ServerListModel;
40 class ServerListView;
41 class WadFindResult;
42 class QAction;
43 class QItemSelection;
44 class QModelIndex;
45 class QPoint;
46 class QSortFilterProxyModel;
47 
48 class ServerList : public QObject
49 {
50  Q_OBJECT
51 
52  public:
53  ServerList(ServerListView* serverTable, MainWindow* pMainWindow);
54  ~ServerList();
55 
56  void cleanUpForce();
57  void cleanUpRightNow();
58 
59  MainWindow* getMainWindow() { return mainWindow; }
60  bool hasAtLeastOneServer() const;
61 
62  bool isAnyColumnSortedAdditionally() const;
63  bool isSortingAdditionallyByColumn(int column) const;
64  bool isSortingByColumn(int columnIndex);
65 
66  void removeCustomServers();
67  void removeNonSpecialServers();
68  QList<ServerPtr> selectedServers() const;
69  QList<ServerPtr> servers() const;
70  QList<ServerPtr> serversForPlugin(const EnginePlugin *plugin) const;
71 
72  ServerPtr serverFromIndex(const QModelIndex&);
73 
74  public slots:
75  void applyFilter(const ServerListFilterInfo& filterInfo);
76  void cleanUp();
80  void lookupHosts();
81  void redraw();
82  void refreshSelected();
83  void registerServer(ServerPtr server);
84  void removeServer(const ServerPtr &server);
90  void setGroupServersWithPlayersAtTop(bool b);
91 
92  void tableMiddleClicked(const QModelIndex& index, const QPoint& cursorPosition);
93  void tableRightClicked(const QModelIndex& index, const QPoint& cursorPosition);
94  void updateCountryFlags();
95  void updateSearch(const QString& search);
96 
97  signals:
101  void displayServerJoinCommandLine(const ServerPtr&);
102 
107  void findMissingWADs(const ServerPtr&);
108 
109  void serverDeregistered(ServerPtr);
110  void serverFilterModified(const ServerListFilterInfo& filter);
115  void serverInfoUpdated(const ServerPtr&);
116  void serverRegistered(ServerPtr);
117  void serverDoubleClicked(const ServerPtr&);
118  void serversSelected(QList<ServerPtr>&);
119 
120  private:
121  QTimer cleanerTimer;
122  MainWindow* mainWindow;
123  ServerListModel* model;
124  bool needsCleaning;
125  ServerListProxyModel *proxyModel;
126  Qt::SortOrder sortOrder;
127  int sortIndex;
128  ServerListView* table;
129 
130  bool areColumnsWidthsSettingsChanged();
131 
132  void connectTableModelProxySlots();
133  void clearAdditionalSorting();
134 
135  ServerListModel* createModel();
136  ServerListProxyModel *createSortingProxy(ServerListModel* serverListModel);
137 
138  Qt::SortOrder getColumnDefaultSortOrder(int columnId);
139 
140  void initCleanerTimer();
141 
142  void prepareServerTable();
143 
144  void removeAdditionalSortingForColumn(const QModelIndex &modelIndex);
145  void saveColumnsWidthsSettings();
146 
147  void setupTableColumnWidths();
148  void setupTableProperties(QSortFilterProxyModel* tableModel);
149 
150  void sortAdditionally(const QModelIndex &modelIndex, Qt::SortOrder order);
151 
152  Qt::SortOrder swappedCurrentSortOrder();
153 
154  void updateCountryFlags(bool force);
155 
156  private slots:
157  void columnHeaderClicked(int);
158  void contextMenuAboutToHide();
159  void contextMenuTriggered(QAction* action);
160  void doubleClicked(const QModelIndex&);
161  void itemSelected(const QItemSelection&);
162  void mouseEntered(const QModelIndex&);
163  void saveAdditionalSortingConfig();
164  void onServerBegunRefreshing(const ServerPtr &server);
165  void onServerUpdated(const ServerPtr &server);
166  void updateHeaderTitles();
167 };
168 
169 #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:307
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:501
INI section representation.
Definition: inisection.h:40