serverlistmodel.h
1 //------------------------------------------------------------------------------
2 // serverlistmodel.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 __SERVER_LIST_MODEL_H_
24 #define __SERVER_LIST_MODEL_H_
25 
26 #include "serverapi/serverptr.h"
27 #include <QStandardItemModel>
28 
29 class EnginePlugin;
30 class Server;
31 class ServerListSortFilterProxyModel;
32 class ServerList;
33 
34 class ServerListModel : public QStandardItemModel
35 {
36  Q_OBJECT
37 
38  friend class ServerList;
39  friend class ServerListProxyModel;
40 
41 public:
53  {
54  SG_NORMAL = 200,
55  SG_WAIT = 175,
56  SG_BANNED = 150,
57  SG_TIMEOUT = 125,
58  SG_BAD = 100,
59  SG_FIRST_QUERY = 50,
60  };
61 
62  enum ServerListDataTypes
63  {
64  // Pointer to the server structure is always stored in the first column
65  SLDT_POINTER_TO_SERVER_STRUCTURE = Qt::UserRole + 1,
66  SLDT_SORT = Qt::UserRole + 2
67  };
68 
69  ServerListModel(ServerList *parent);
70 
74  int addServer(ServerPtr server);
75  QList<ServerPtr> customServers() const;
76 
81  ServerPtr findSameServer(const Server *server);
82 
88  int findServerOnTheList(const Server *server);
89 
90  ServerList *handler()
91  {
92  return parentHandler;
93  }
94 
95 
96  QList<ServerPtr> nonSpecialServers() const;
97  QList<ServerPtr> servers() const;
98  QList<ServerPtr> serversForPlugin(const EnginePlugin *plugin) const;
99 
105  void redraw(int row);
106 
111  void redraw(Server *server);
112 
113  void redrawAll();
114 
115  void removeServer(const ServerPtr &server);
116 
121  void updateFlag(int row, bool force = true);
122 
126  int updateServer(int row, ServerPtr server);
127 
128  ServerPtr serverFromList(int rowIndex) const;
129  ServerPtr serverFromList(const QModelIndex &) const;
130 
131  void setRefreshing(ServerPtr server);
132 
133 signals:
134  void allRowsContentChanged();
135  void rowContentChanged(int row);
136 
137 private:
138  void prepareHeaders();
139  ServerGroup serverGroup(int row);
140 
141  QVariant columnSortData(int row, int column);
142 
143  ServerList *parentHandler;
144 };
145 
146 #endif
int addServer(ServerPtr server)
void redraw(int row)
A representation of a server for a given game.
Definition: server.h:93
int updateServer(int row, ServerPtr server)
int findServerOnTheList(const Server *server)
Finds index of the row where server is contained.
void updateFlag(int row, bool force=true)
ServerPtr findSameServer(const Server *server)