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