GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/windows/serverdialog.h Lines: 1 1 100.0 %
Date: 2017-11-29 Branches: 0 0 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2004-2009  The Mana World Development Team
4
 *  Copyright (C) 2009-2010  The Mana Developers
5
 *  Copyright (C) 2011-2017  The ManaPlus Developers
6
 *
7
 *  This file is part of The ManaPlus Client.
8
 *
9
 *  This program is free software; you can redistribute it and/or modify
10
 *  it under the terms of the GNU General Public License as published by
11
 *  the Free Software Foundation; either version 2 of the License, or
12
 *  any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
#ifndef GUI_WINDOWS_SERVERDIALOG_H
24
#define GUI_WINDOWS_SERVERDIALOG_H
25
26
#include "gui/widgets/window.h"
27
28
#include "enums/gui/serverdialogdonwloadstatus.h"
29
30
#include "enums/net/downloadstatus.h"
31
32
#include "net/serverinfo.h"
33
34
#include "utils/mutex.h"
35
36
#include "listeners/actionlistener.h"
37
#include "listeners/keylistener.h"
38
#include "listeners/selectionlistener.h"
39
40
class Button;
41
class CheckBox;
42
class Label;
43
class ListBox;
44
class ServersListModel;
45
46
namespace Net
47
{
48
    class Download;
49
}  // namespace Net
50
51
/**
52
 * The server choice dialog.
53
 *
54
 * \ingroup Interface
55
 */
56
class ServerDialog final : public Window,
57
                           public ActionListener,
58
                           public KeyListener,
59
                           public SelectionListener
60
{
61
    public:
62
        /**
63
         * Constructor
64
         *
65
         * @see Window::Window
66
         */
67
        ServerDialog(ServerInfo *const serverInfo, const std::string &dir);
68
69
        A_DELETE_COPY(ServerDialog)
70
71
        void postInit() override final;
72
73
        /**
74
         * Destructor
75
         */
76
        ~ServerDialog();
77
78
        /**
79
         * Called when receiving actions from the widgets.
80
         */
81
        void action(const ActionEvent &event) override final;
82
83
        void keyPressed(KeyEvent &event) override final;
84
85
        /**
86
         * Called when the selected value changed in the servers list box.
87
         */
88
        void valueChanged(const SelectionEvent &event) override final;
89
90
        void mouseClicked(MouseEvent &event) override final;
91
92
        void logic() override final;
93
94
        void updateServer(const ServerInfo &server, const int index);
95
96
        void connectToSelectedServer();
97
98
        void close() override final;
99
100
    protected:
101
        friend class ServersListModel;
102
103
        MutexLocker lock()
104
144
        { return MutexLocker(&mMutex); }
105
106
    private:
107
        friend class EditServerDialog;
108
109
        /**
110
         * Called to load a list of available server from an online xml file.
111
         */
112
        void downloadServerList();
113
114
        void loadServers(const bool addNew = true);
115
116
        void loadCustomServers();
117
118
        void saveCustomServers(const ServerInfo &currentServer = ServerInfo(),
119
                               const int index = -1);
120
121
        bool needUpdateServers() const;
122
123
        static int downloadUpdate(void *ptr,
124
                                  const DownloadStatusT status,
125
                                  size_t total,
126
                                  const size_t remaining);
127
128
        Mutex mMutex;
129
        ServerInfos mServers;
130
        const std::string &mDir;
131
        Label  *mDescription A_NONNULLPOINTER;
132
        Button *mQuitButton A_NONNULLPOINTER;
133
        Button *mConnectButton A_NONNULLPOINTER;
134
        Button *mAddEntryButton A_NONNULLPOINTER;
135
        Button *mEditEntryButton A_NONNULLPOINTER;
136
        Button *mDeleteButton A_NONNULLPOINTER;
137
        Button *mLoadButton A_NONNULLPOINTER;
138
        Button *mInfoButton A_NONNULLPOINTER;
139
        ServersListModel *mServersListModel A_NONNULLPOINTER;
140
        ListBox *mServersList A_NONNULLPOINTER;
141
142
        /** Status of the current download. */
143
        Net::Download *mDownload;
144
        ServerInfo *mServerInfo;
145
        CheckBox *mPersistentIPCheckBox;
146
        float mDownloadProgress;
147
        ServerDialogDownloadStatusT mDownloadStatus;
148
};
149
150
#endif  // GUI_WINDOWS_SERVERDIALOG_H