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 
93  void tableMiddleClicked();
94  void showContextMenu(const QPoint &position);
95  void updateCountryFlags();
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