serverlistcounttracker.h
1 //------------------------------------------------------------------------------
2 // serverlistcounttracker.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) 2015 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #ifndef idd4447d5c_3443_4b8c_9902_82b5f6d51a47
24 #define idd4447d5c_3443_4b8c_9902_82b5f6d51a47
25 
26 #include "dptr.h"
27 #include "serverapi/serverptr.h"
28 
29 class EnginePlugin;
30 
32 {
33  int numBots;
34  int numHumanPlayers;
35  int numPlayers;
36 
37  int numCustomServers;
38  int numGenericServers;
39  int numLanServers;
40  int numServers;
41  int numRefreshing;
42 
44 
45  void countPlayers(const ServerPtr &server);
46  void discountPlayers(const ServerPtr &server);
47 
48  void countServer(const ServerPtr &server);
49  void discountServer(const ServerPtr &server);
50 
51  int refreshedPercent() const;
52 
53  ServerListCount& operator+=(const ServerListCount &other);
54 };
55 
56 class ServerListCountTracker : public QObject
57 {
58  Q_OBJECT;
59 
60 public:
61  ServerListCountTracker(QObject *parent = 0);
62 
63  const ServerListCount &count() const;
64  void setPluginFilter(const EnginePlugin *plugin);
65 
66 public slots:
67  void deregisterServer(ServerPtr server);
68  void registerServer(ServerPtr server);
69 
70 signals:
71  void updated();
72 
73 private:
75 
76 private slots:
77  void onServerBegunRefreshing(ServerPtr server);
78  void onServerUpdated(ServerPtr server);
79 };
80 
81 #endif