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 
98 signals:
102  void displayServerJoinCommandLine(const ServerPtr &);
103 
108  void findMissingWADs(const ServerPtr &);
109 
110  void serverDeregistered(ServerPtr);
111  void serverFilterModified(const ServerListFilterInfo &filter);
116  void serverInfoUpdated(const ServerPtr &);
117  void serverRegistered(ServerPtr);
118  void serverDoubleClicked(const ServerPtr &);
119  void serversSelected(QList<ServerPtr> &);
120 
121 private:
122  QTimer cleanerTimer;
123  MainWindow *mainWindow;
124  ServerListModel *model;
125  bool needsCleaning;
126  ServerListProxyModel *proxyModel;
127  Qt::SortOrder sortOrder;
128  int sortIndex;
129  ServerListView *table;
130 
131  bool areColumnsWidthsSettingsChanged();
132 
133  void connectTableModelProxySlots();
134  void clearAdditionalSorting();
135 
136  ServerListModel *createModel();
137  ServerListProxyModel *createSortingProxy(ServerListModel *serverListModel);
138 
139  Qt::SortOrder getColumnDefaultSortOrder(int columnId);
140 
141  void initCleanerTimer();
142 
143  void prepareServerTable();
144 
145  void removeAdditionalSortingForColumn(const QModelIndex &modelIndex);
146  void saveColumnsWidthsSettings();
147 
148  void setupTableColumnWidths();
149  void setupTableProperties(QSortFilterProxyModel *tableModel);
150 
151  void sortAdditionally(const QModelIndex &modelIndex, Qt::SortOrder order);
152 
153  Qt::SortOrder swappedCurrentSortOrder();
154 
155  void updateCountryFlags(bool force);
156 
157 private slots:
158  void columnHeaderClicked(int);
159  void contextMenuAboutToHide();
160  void contextMenuTriggered(QAction *action);
161  void doubleClicked(const QModelIndex &);
162  void itemSelected(const QItemSelection &);
163  void mouseEntered(const QModelIndex &);
164  void saveAdditionalSortingConfig();
165  void onServerBegunRefreshing(const ServerPtr &server);
166  void onServerUpdated(const ServerPtr &server);
167  void updateHeaderTitles();
168 };
169 
170 #endif