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 PWad;
33 class IniSection;
34 class Server;
36 class ServerListModel;
38 class ServerListView;
39 class WadFindResult;
40 class QAction;
41 class QItemSelection;
42 class QModelIndex;
43 class QPoint;
44 class QSortFilterProxyModel;
45 
46 class ServerListHandler : public QObject
47 {
48  Q_OBJECT
49 
50  public:
51  ServerListHandler(ServerListView* serverTable, QWidget* pMainWindow);
53 
54  void clearTable();
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  QList<ServerPtr> selectedServers();
65 
66  ServerPtr serverFromIndex(const QModelIndex&);
67 
68  ServerListModel* serverModel() { return model; }
69  ServerListView* serverTable() { return table; }
70 
71  public slots:
72  void applyFilter(const ServerListFilterInfo& filterInfo);
73  void cleanUp();
77  void lookupHosts();
78  void redraw();
79  void refreshAll();
80  void refreshSelected();
81  void serverBegunRefreshing(const ServerPtr &server);
82  void serverUpdated(const ServerPtr &server, int response);
83 
89  void setGroupServersWithPlayersAtTop(bool b);
90 
91  void tableMiddleClicked(const QModelIndex& index, const QPoint& cursorPosition);
92  void tableRightClicked(const QModelIndex& index, const QPoint& cursorPosition);
93  void updateCountryFlags();
94  void updateSearch(const QString& search);
95 
96  protected slots:
98  void columnHeaderClicked(int);
99  void doubleClicked(const QModelIndex&);
100  void itemSelected(const QItemSelection&);
101  void modelCleared();
102  void mouseEntered(const QModelIndex&);
103 
104  signals:
108  void displayServerJoinCommandLine(const ServerPtr&);
109 
114  void findMissingWADs(const ServerPtr&);
115 
116  void serverFilterModified(const ServerListFilterInfo& filter);
121  void serverInfoUpdated(const ServerPtr&);
122  void serverDoubleClicked(const ServerPtr&);
123  void serversSelected(QList<ServerPtr>&);
124 
125  protected:
126  // TODO: These need to be set by appearance configuration.
127  static const QString FONT_COLOR_MISSING;
128  static const QString FONT_COLOR_OPTIONAL;
129  static const QString FONT_COLOR_FOUND;
130 
131  QTimer cleanerTimer;
132 
133  QWidget* mainWindow;
134  ServerListModel* model;
135  bool needsCleaning;
136  ServerListProxyModel *sortingProxy;
137 
138  Qt::SortOrder sortOrder;
139  int sortIndex;
140  ServerListView* table;
141 
142  QString createIwadToolTip(ServerPtr server);
143  QString createPlayersToolTip(ServerCPtr server);
144  QString createPortToolTip(ServerCPtr server);
145  QString createPwadsToolTip(ServerPtr server);
146  QString createPwadToolTipInfo(const PWad& pwad, const ServerPtr &server);
147  QString createServerNameToolTip(ServerCPtr server);
148 
149  bool areColumnsWidthsSettingsChanged();
150 
151  void connectTableModelProxySlots();
152 
153  ServerListModel* createModel();
154  ServerListProxyModel *createSortingProxy(ServerListModel* serverListModel);
155 
156  Qt::SortOrder getColumnDefaultSortOrder(int columnId);
157 
158  void initCleanerTimer();
159 
160  void prepareServerTable();
161 
162  void saveColumnsWidthsSettings();
163 
164  void setupTableColumnWidths();
165  void setupTableProperties(QSortFilterProxyModel* tableModel);
166 
167  Qt::SortOrder swapCurrentSortOrder();
168 
169  void updateCountryFlags(bool force);
170 
171  private:
172  void clearAdditionalSorting();
173  WadFindResult findWad(ServerPtr server, const QString &name) const;
174  void removeAdditionalSortingForColumn(const QModelIndex &modelIndex);
175  void sortAdditionally(const QModelIndex &modelIndex, Qt::SortOrder order);
176 
177  private slots:
178  void contextMenuAboutToHide();
179  void contextMenuTriggered(QAction* action);
180  void saveAdditionalSortingConfig();
181  void updateHeaderTitles();
182 };
183 
184 #endif
Structure describing server filter.
void setCountryFlagsIfNotPresent()
Sets country flags for servers that don't have flags present yet.
Definition: serverlist.cpp:663
PWAD hosted on a server.
void findMissingWADs(const ServerPtr &)
A representation of a server for a given game.
Definition: server.h:93
void displayServerJoinCommandLine(const ServerPtr &)
void columnHeaderClicked(int)
Handles column sorting.
Definition: serverlist.cpp:132
void lookupHosts()
Looks up hosts for all available servers.
Definition: serverlist.cpp:506
INI section representation.
Definition: inisection.h:40
void serverInfoUpdated(const ServerPtr &)
Emitted every time when a server info is updated through serverUpdated()