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  SLDT_SERVER_GROUP = Qt::UserRole + 3
68  };
69 
70  ServerListModel(ServerList *parent);
71 
75  int addServer(ServerPtr server);
76  QList<ServerPtr> customServers() const;
77 
82  ServerPtr findSameServer(const Server *server);
83 
89  int findServerOnTheList(const Server *server);
90 
91  ServerList *handler()
92  {
93  return parentHandler;
94  }
95 
96 
97  QList<ServerPtr> nonSpecialServers() const;
98  QList<ServerPtr> servers() const;
99  QList<ServerPtr> serversForPlugin(const EnginePlugin *plugin) const;
100 
106  void redraw(int row);
107 
112  void redraw(Server *server);
113 
114  void redrawAll();
115 
116  void removeServer(const ServerPtr &server);
117 
122  void updateFlag(int row, bool force = true);
123 
127  int updateServer(int row, ServerPtr server);
128 
129  ServerPtr serverFromList(int rowIndex) const;
130  ServerPtr serverFromList(const QModelIndex &) const;
131 
132  void setRefreshing(ServerPtr server);
133 
134 signals:
135  void allRowsContentChanged();
136  void rowContentChanged(int row);
137 
138 private:
139  void prepareHeaders();
140  ServerGroup serverGroup(int row);
141 
142  QVariant columnSortData(int row, int column);
143 
144  ServerList *parentHandler;
145 };
146 
147 #endif