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 #ifndef __SERVERLIST_H_
24 #define __SERVERLIST_H_
25 
26 #include <QObject>
27 #include <QTimer>
28 
29 #include "serverapi/serverptr.h"
30 
31 class EnginePlugin;
32 class PWad;
33 class IniSection;
34 class MainWindow;
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, MainWindow *pMainWindow);
53  ~ServerList() override;
54 
55  void cleanUpForce();
56  void cleanUpRightNow();
57 
58  MainWindow *getMainWindow()
59  {
60  return mainWindow;
61  }
62  bool hasAtLeastOneServer() const;
63 
64  bool isAnyColumnSortedAdditionally() const;
65  bool isSortingAdditionallyByColumn(int column) const;
66  bool isSortingByColumn(int columnIndex);
67 
68  void removeCustomServers();
69  void removeNonSpecialServers();
70  QList<ServerPtr> selectedServers() const;
71  QList<ServerPtr> servers() const;
72  QList<ServerPtr> serversForPlugin(const EnginePlugin *plugin) const;
73 
74  ServerPtr serverFromIndex(const QModelIndex &);
75 
76 public slots:
77  void applyFilter(const ServerListFilterInfo &filterInfo);
78  void cleanUp();
82  void lookupHosts();
83  void redraw();
84  void refreshSelected();
85  void registerServer(ServerPtr server);
86  void removeServer(const ServerPtr &server);
92  void setGroupServersWithPlayersAtTop(bool b);
93 
94  void tableMiddleClicked();
95  void tableRightClicked(const QModelIndex &index, const QPoint &cursorPosition);
96  void updateCountryFlags();
97  void updateSearch(const QString &search);
98 
99 signals:
103  void displayServerJoinCommandLine(const ServerPtr &);
104 
109  void findMissingWADs(const ServerPtr &);
110 
111  void serverDeregistered(ServerPtr);
112  void serverFilterModified(const ServerListFilterInfo &filter);
117  void serverInfoUpdated(const ServerPtr &);
118  void serverRegistered(ServerPtr);
119  void serverDoubleClicked(const ServerPtr &);
120  void serversSelected(QList<ServerPtr> &);
121 
122 private:
123  QTimer cleanerTimer;
124  MainWindow *mainWindow;
125  ServerListModel *model;
126  bool needsCleaning;
127  ServerListProxyModel *proxyModel;
128  Qt::SortOrder sortOrder;
129  int sortIndex;
130  ServerListView *table;
131 
132  bool areColumnsWidthsSettingsChanged();
133 
134  void connectTableModelProxySlots();
135  void clearAdditionalSorting();
136 
137  ServerListModel *createModel();
138  ServerListProxyModel *createSortingProxy(ServerListModel *serverListModel);
139 
140  Qt::SortOrder getColumnDefaultSortOrder(int columnId);
141 
142  void initCleanerTimer();
143 
144  void prepareServerTable();
145 
146  void removeAdditionalSortingForColumn(const QModelIndex &modelIndex);
147  void saveColumnsWidthsSettings();
148 
149  void setupTableColumnWidths();
150  void setupTableProperties(QSortFilterProxyModel *tableModel);
151 
152  void sortAdditionally(const QModelIndex &modelIndex, Qt::SortOrder order);
153 
154  Qt::SortOrder swappedCurrentSortOrder();
155 
156  void updateCountryFlags(bool force);
157 
158 private slots:
159  void columnHeaderClicked(int);
160  void contextMenuAboutToHide();
161  void contextMenuTriggered(QAction *action);
162  void doubleClicked(const QModelIndex &);
163  void itemSelected(const QItemSelection &);
164  void mouseEntered(const QModelIndex &);
165  void saveAdditionalSortingConfig();
166  void onServerBegunRefreshing(const ServerPtr &server);
167  void onServerUpdated(const ServerPtr &server);
168  void updateHeaderTitles();
169 };
170 
171 #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:297
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:487
INI section representation.
Definition: inisection.h:40