serverlistcounttracker.h
1 //------------------------------------------------------------------------------
2 // serverlistcounttracker.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) 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 #include <QObject>
30 
31 class EnginePlugin;
32 
34 {
35  int numBots;
36  int numHumanPlayers;
37  int numPlayers;
38 
39  int numCustomServers;
40  int numGenericServers;
41  int numLanServers;
42  int numServers;
43  int numRefreshing;
44 
46 
47  void countPlayers(const ServerPtr &server);
48  void discountPlayers(const ServerPtr &server);
49 
50  void countServer(const ServerPtr &server);
51  void discountServer(const ServerPtr &server);
52 
53  int refreshedPercent() const;
54 
55  ServerListCount &operator+=(const ServerListCount &other);
56 };
57 
58 class ServerListCountTracker : public QObject
59 {
60  Q_OBJECT
61 
62 public:
63  ServerListCountTracker(QObject *parent = nullptr);
64 
65  const ServerListCount &count() const;
66  void setPluginFilter(const EnginePlugin *plugin);
67 
68 public slots:
69  void deregisterServer(ServerPtr server);
70  void registerServer(ServerPtr server);
71 
72 signals:
73  void updated();
74 
75 private:
77 
78 private slots:
79  void onServerBegunRefreshing(ServerPtr server);
80  void onServerUpdated(ServerPtr server);
81 };
82 
83 #endif