ManaPlus
Public Member Functions | Protected Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Friends

#include <serverdialog.h>

Inheritance diagram for ServerDialog:
Window ActionListener KeyListener SelectionListener BasicContainer2 MouseListener WidgetListener BasicContainer Widget WidgetDeathListener Widget2

Public Member Functions

 ServerDialog (ServerInfo *const serverInfo, const std::string &dir)
 
void postInit ()
 
 ~ServerDialog ()
 
void action (const ActionEvent &event)
 
void keyPressed (KeyEvent &event)
 
void valueChanged (const SelectionEvent &event)
 
void mouseClicked (MouseEvent &event)
 
void logic ()
 
void updateServer (const ServerInfo &server, const int index)
 
void connectToSelectedServer ()
 
void close ()
 
- Public Member Functions inherited from Window
 Window (const std::string &caption, const Modal modal, Window *const parent, std::string skin)
 
 ~Window ()
 
void draw (Graphics *const graphics)
 
void safeDraw (Graphics *const graphics)
 
void setContentSize (int width, int height)
 
void setLocationRelativeTo (const Widget *const widget)
 
void setLocationHorisontallyRelativeTo (const Widget *const widget)
 
void setLocationRelativeTo (const ImagePosition::Type &position, int offsetX, int offsetY)
 
void setResizable (const bool resize)
 
void redraw ()
 
void widgetResized (const Event &event)
 
void widgetMoved (const Event &event)
 
void widgetHidden (const Event &event)
 
void setCloseButton (const bool flag)
 
bool getCloseButton () const
 
void setAllowClose (const bool b)
 
bool getAlowClose () const
 
bool isResizable () const
 
void setMinWidth (const int width)
 
int getMinWidth () const
 
void setMinHeight (const int height)
 
int getMinHeight () const
 
void setMaxWidth (const int width)
 
int getMaxWidth () const
 
void setMaxHeight (const int height)
 
int getMaxHeight () const
 
void setShowTitle (bool flag)
 
void setStickyButton (const bool flag)
 
void setSticky (const bool sticky)
 
bool isSticky () const
 
void setStickyButtonLock (const bool sticky)
 
bool isStickyButtonLock () const
 
virtual void setVisible (Visible visible)
 
void setVisible (const Visible visible, const bool forceSticky)
 
bool isDefaultVisible () const
 
void setDefaultVisible (const bool save)
 
bool willSaveVisible () const
 
void setSaveVisible (const bool save)
 
WindowgetParentWindow () const
 
virtual void scheduleDelete ()
 
void mousePressed (MouseEvent &event)
 
void mouseDragged (MouseEvent &event)
 
void mouseMoved (MouseEvent &event)
 
void mouseReleased (MouseEvent &event)
 
void mouseExited (MouseEvent &event)
 
void mouseEntered (MouseEvent &event)
 
void updateResizeHandler (MouseEvent &event)
 
void setWindowName (const std::string &name)
 
const std::string & getWindowName () const
 
void loadWindowState ()
 
void saveWindowState ()
 
void setDefaultSize (const int defaultX, const int defaultY, int defaultWidth, int defaultHeight)
 
void setDefaultSize ()
 
void setDefaultSize (const int defaultWidth, const int defaultHeight, const ImagePosition::Type &position, const int offsetx, const int offsetY)
 
virtual void resetToDefaultSize ()
 
void adjustPositionAfterResize (const int oldScreenWidth, const int oldScreenHeight)
 
LayoutgetLayout ()
 
void clearLayout ()
 
void reflowLayout (int w, int h)
 
LayoutCellplace (const int x, const int y, Widget *const wg, const int w, const int h)
 
ContainerPlacer getPlacer (const int x, const int y)
 
void center ()
 
void centerHorisontally ()
 
void setModal (const Modal modal)
 
Rect getWindowArea () const
 
bool isResizeAllowed (const MouseEvent &event) const
 
void setCaptionFont (Font *font)
 
void enableVisibleSound (bool b)
 
bool isWindowVisible () const
 
void setPadding (int padding)
 
int getPadding () const
 
void setTitleBarHeight (unsigned int height)
 
unsigned int getTitleBarHeight () const
 
void setCaption (const std::string &caption)
 
const std::string & getCaption () const
 
void setAlignment (Graphics::Alignment alignment)
 
Graphics::Alignment getAlignment () const
 
void setMovable (Move movable)
 
bool isMovable () const
 
Rect getChildrenArea ()
 
virtual void resizeToContent ()
 
- Public Member Functions inherited from BasicContainer2
 BasicContainer2 (const Widget2 *const widget)
 
 ~BasicContainer2 ()
 
void setOpaque (Opaque opaque)
 
bool isOpaque () const
 
virtual void add (Widget *const widget)
 
void addXY (Widget *const widget, const int x, const int y)
 
- Public Member Functions inherited from BasicContainer
 BasicContainer (const Widget2 *const widget)
 
 ~BasicContainer ()
 
void showWidgetPart (Widget *const widget, const Rect &area)
 
void moveToTop (Widget *const widget)
 
void moveToBottom (Widget *const widget)
 
void focusNext ()
 
void focusPrevious ()
 
void setFocusHandler (FocusHandler *const focusHandler)
 
void setInternalFocusHandler (FocusHandler *const focusHandler)
 
WidgetgetWidgetAt (int x, int y)
 
void death (const Event &event)
 
WidgetfindFirstWidget (const std::set< Widget * > &list)
 
void add (Widget *const widget)
 
virtual void remove (Widget *const widget)
 
virtual void clear ()
 
- Public Member Functions inherited from Widget
 Widget (const Widget2 *const widget)
 
 ~Widget ()
 
virtual void drawFrame (Graphics *graphics)
 
virtual void safeDrawFrame (Graphics *graphics)
 
void setFrameSize (const unsigned int frameSize)
 
unsigned int getFrameSize () const
 
WidgetgetParent () const
 
void setWidth (const int width)
 
int getWidth () const
 
void setHeight (const int height)
 
int getHeight () const
 
void setSize (const int width, const int height)
 
void setX (const int x)
 
int getX () const
 
void setY (const int y)
 
int getY () const
 
void setPosition (const int x, const int y)
 
void setDimension (const Rect &dimension)
 
const RectgetDimension () const
 
void setFocusable (const bool focusable)
 
bool isFocusable () const
 
virtual bool isFocused () const
 
void setEnabled (const bool enabled)
 
bool isEnabled () const
 
void setVisible (Visible visible)
 
bool isVisible () const
 
void setBaseColor (const Color &color)
 
const ColorgetBaseColor () const
 
void setForegroundColor (const Color &color)
 
const ColorgetForegroundColor () const
 
void setBackgroundColor (const Color &color)
 
const ColorgetBackgroundColor () const
 
virtual void requestFocus ()
 
virtual void requestMoveToTop ()
 
virtual void requestMoveToBottom ()
 
FocusHandlergetFocusHandler ()
 
void addActionListener (ActionListener *const actionListener)
 
void removeActionListener (ActionListener *const actionListener)
 
void addDeathListener (WidgetDeathListener *const deathListener)
 
void removeDeathListener (WidgetDeathListener *const deathListener)
 
void addMouseListener (MouseListener *const mouseListener)
 
void removeMouseListener (MouseListener *const mouseListener)
 
void addKeyListener (KeyListener *const keyListener)
 
void removeKeyListener (KeyListener *const keyListener)
 
void addFocusListener (FocusListener *const focusListener)
 
void removeFocusListener (FocusListener *const focusListener)
 
void addWidgetListener (WidgetListener *const widgetListener)
 
void removeWidgetListener (WidgetListener *const widgetListener)
 
void setActionEventId (const std::string &actionEventId)
 
const std::string & getActionEventId () const
 
virtual void getAbsolutePosition (int &x, int &y) const
 
virtual void setParent (Widget *parent)
 
FontgetFont () const
 
void setFont (Font *const font)
 
virtual void fontChanged ()
 
bool isTabInEnabled () const
 
void setTabInEnabled (const bool enabled)
 
bool isTabOutEnabled () const
 
void setTabOutEnabled (const bool enabled)
 
void requestModalFocus ()
 
virtual void requestModalMouseInputFocus ()
 
virtual void releaseModalFocus ()
 
virtual void releaseModalMouseInputFocus ()
 
virtual bool isModalFocused () const
 
virtual bool isModalMouseInputFocused () const
 
const std::list< MouseListener * > & getMouseListeners () const A_CONST
 
const std::list< KeyListener * > & getKeyListeners () const A_CONST
 
const std::list< FocusListener * > & getFocusListeners () const A_CONST
 
virtual FocusHandlergetInternalFocusHandler ()
 
void setInternalFocusHandler (FocusHandler *const internalFocusHandler)
 
void setId (const std::string &id)
 
const std::string & getId () const
 
virtual void showPart (const Rect &rectangle)
 
bool isAllowLogic () const
 
void setMouseConsume (const bool b)
 
bool isMouseConsume () const
 
void setRedraw (const bool b)
 
virtual bool isSelectable () const
 
void setSelectable (const bool selectable)
 
void windowResized ()
 
- Public Member Functions inherited from Widget2
virtual ~Widget2 ()
 
const ColorgetThemeColor (const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
 
const ColorgetThemeCharColor (const signed char c, bool &valid) const A_INLINE
 
virtual void setWidget2 (const Widget2 *const widget)
 
void setPalette (int palette)
 
void checkPalette ()
 
void setForegroundColor2 (const Color &color)
 
WidgetgetWindow () const
 
virtual void setWindow (Widget *const window)
 
- Public Member Functions inherited from WidgetDeathListener
virtual ~WidgetDeathListener ()
 
- Public Member Functions inherited from MouseListener
virtual ~MouseListener ()
 
virtual void mouseWheelMovedUp (MouseEvent &event)
 
virtual void mouseWheelMovedDown (MouseEvent &event)
 
- Public Member Functions inherited from WidgetListener
virtual ~WidgetListener ()
 
virtual void widgetShown (const Event &event)
 
- Public Member Functions inherited from ActionListener
virtual ~ActionListener ()
 
- Public Member Functions inherited from KeyListener
virtual ~KeyListener ()
 
virtual void keyReleased (KeyEvent &event)
 
- Public Member Functions inherited from SelectionListener
virtual ~SelectionListener ()
 

Protected Member Functions

MutexLocker lock ()
 
- Protected Member Functions inherited from Window
bool canMove () const
 
int getOption (const std::string &name, const int def) const
 
bool getOptionBool (const std::string &name, const bool def) const
 
void setTitlePadding (const int p)
 
int getTitlePadding () const
 
- Protected Member Functions inherited from BasicContainer
virtual void drawChildren (Graphics *const graphics)
 
virtual void safeDrawChildren (Graphics *const graphics)
 
virtual void logicChildren ()
 
- Protected Member Functions inherited from Widget
void distributeActionEvent ()
 
void distributeResizedEvent ()
 
void distributeMovedEvent ()
 
void distributeHiddenEvent ()
 
void distributeShownEvent ()
 
- Protected Member Functions inherited from Widget2
 Widget2 (const Widget2 *const widget)
 
- Protected Member Functions inherited from WidgetDeathListener
 WidgetDeathListener ()
 
- Protected Member Functions inherited from MouseListener
 MouseListener ()
 
- Protected Member Functions inherited from WidgetListener
 WidgetListener ()
 
- Protected Member Functions inherited from ActionListener
 ActionListener ()
 
- Protected Member Functions inherited from KeyListener
 KeyListener ()
 
- Protected Member Functions inherited from SelectionListener
 SelectionListener ()
 

Private Member Functions

void downloadServerList ()
 
void loadServers (const bool addNew)
 
void loadCustomServers ()
 
void saveCustomServers (const ServerInfo &currentServer, const int index)
 
bool needUpdateServers () const
 

Static Private Member Functions

static int downloadUpdate (void *ptr, const DownloadStatusT status, size_t total, const size_t remaining)
 

Private Attributes

Mutex mMutex
 
ServerInfos mServers
 
const std::string & mDir
 
LabelmDescription
 
ButtonmQuitButton
 
ButtonmConnectButton
 
ButtonmAddEntryButton
 
ButtonmEditEntryButton
 
ButtonmDeleteButton
 
ButtonmLoadButton
 
ButtonmInfoButton
 
ServersListModelmServersListModel
 
ListBoxmServersList
 
Net::DownloadmDownload
 
ServerInfomServerInfo
 
CheckBoxmPersistentIPCheckBox
 
float mDownloadProgress
 
ServerDialogDownloadStatusT mDownloadStatus
 

Friends

class ServersListModel
 
class EditServerDialog
 

Additional Inherited Members

- Static Public Member Functions inherited from Window
static void setWindowContainer (WindowContainer *const windowContainer)
 
- Static Public Member Functions inherited from Widget
static void setGlobalFont (Font *const font)
 
static FontgetGloablFont ()
 
static void cleanGlobalFont ()
 
static bool widgetExists (const Widget *const widget)
 
static void distributeWindowResizeEvent ()
 
static WidgetcallPostInit (Widget *const widget)
 
- Data Fields inherited from Widget
Visible mVisible
 
- Protected Types inherited from BasicContainer
typedef std::vector< Widget * > WidgetList
 
typedef WidgetList::iterator WidgetListIterator
 
typedef WidgetList::const_iterator WidgetListConstIterator
 
typedef WidgetList::reverse_iterator WidgetListReverseIterator
 
typedef WidgetList::const_reverse_iterator WidgetListCReverseIterator
 
- Protected Types inherited from Widget
typedef std::list< MouseListener * > MouseListenerList
 
typedef MouseListenerList::iterator MouseListenerIterator
 
typedef std::list< KeyListener * > KeyListenerList
 
typedef KeyListenerList::iterator KeyListenerIterator
 
typedef std::list< ActionListener * > ActionListenerList
 
typedef ActionListenerList::iterator ActionListenerIterator
 
typedef std::list< WidgetDeathListener * > WidgetDeathListenerList
 
typedef WidgetDeathListenerList::iterator WidgetDeathListenerIterator
 
typedef std::list< FocusListener * > FocusListenerList
 
typedef FocusListenerList::iterator FocusListenerIterator
 
typedef std::list< WidgetListener * > WidgetListenerList
 
typedef WidgetListenerList::iterator WidgetListenerIterator
 
- Protected Attributes inherited from Window
std::string mCaption
 
Graphics::Alignment mAlignment
 
int mPadding
 
unsigned int mTitleBarHeight
 
Move mMovable
 
int mDragOffsetX
 
int mDragOffsetY
 
bool mMoved
 
SkinmSkin
 
int mDefaultX
 
int mDefaultY
 
int mDefaultWidth
 
int mDefaultHeight
 
int mCaptionOffsetX
 
int mCaptionOffsetY
 
bool mShowTitle
 
bool mLastRedraw
 
- Protected Attributes inherited from BasicContainer2
Opaque mOpaque
 
- Protected Attributes inherited from BasicContainer
WidgetList mWidgets
 
WidgetList mLogicWidgets
 
- Protected Attributes inherited from Widget
MouseListenerList mMouseListeners
 
KeyListenerList mKeyListeners
 
ActionListenerList mActionListeners
 
WidgetDeathListenerList mDeathListeners
 
FocusListenerList mFocusListeners
 
WidgetListenerList mWidgetListeners
 
Color mForegroundColor
 
Color mBackgroundColor
 
Color mBaseColor
 
Rect mDimension
 
std::string mActionEventId
 
std::string mId
 
FocusHandlermFocusHandler
 
FocusHandlermInternalFocusHandler
 
WidgetmParent
 
FontmCurrentFont
 
unsigned int mFrameSize
 
bool mFocusable
 
bool mTabIn
 
bool mTabOut
 
bool mEnabled
 
bool mAllowLogic
 
bool mMouseConsume
 
bool mRedraw
 
bool mSelectable
 
- Protected Attributes inherited from Widget2
int mPaletteOffset
 
WidgetmWindow
 
Color mForegroundColor2
 
- Static Protected Attributes inherited from Widget
static FontmGlobalFont = 0
 

Detailed Description

The server choice dialog.

Definition at line 57 of file serverdialog.h.

Constructor & Destructor Documentation

◆ ServerDialog()

ServerDialog::ServerDialog ( ServerInfo *const  serverInfo,
const std::string &  dir 
)

Constructor

See also
Window::Window

Definition at line 97 of file serverdialog.cpp.

98  :
99  // TRANSLATORS: servers dialog name
100  Window(_("Choose Your Server"), Modal_false, nullptr, "server.xml"),
101  ActionListener(),
102  KeyListener(),
104  mMutex(),
106  mDir(dir),
107  mDescription(new Label(this, std::string())),
108  // TRANSLATORS: servers dialog button
109  mQuitButton(new Button(this, _("Quit"), "quit", BUTTON_SKIN, this)),
110  // TRANSLATORS: servers dialog button
111  mConnectButton(new Button(this, _("Connect"), "connect",
112  BUTTON_SKIN, this)),
113  // TRANSLATORS: servers dialog button
114  mAddEntryButton(new Button(this, _("Add"), "addEntry", BUTTON_SKIN, this)),
115  // TRANSLATORS: servers dialog button
116  mEditEntryButton(new Button(this, _("Edit"), "editEntry",
117  BUTTON_SKIN, this)),
118  // TRANSLATORS: servers dialog button
119  mDeleteButton(new Button(this, _("Delete"), "remove", BUTTON_SKIN, this)),
120  // TRANSLATORS: servers dialog button
121  mLoadButton(new Button(this, _("Load"), "load", BUTTON_SKIN, this)),
122  // TRANSLATORS: servers dialog button
123  mInfoButton(new Button(this, _("Info"), "info", BUTTON_SKIN, this)),
126  mDownload(nullptr),
127  mServerInfo(serverInfo),
128  mPersistentIPCheckBox(nullptr),
129  mDownloadProgress(-1.0F),
131 {
132  if (isSafeMode)
133  {
134  // TRANSLATORS: servers dialog name
135  setCaption(_("Choose Your Server *** SAFE MODE ***"));
136  }
137 #ifdef USE_OPENGL
138  else if (config.getIntValue("opengl") == RENDER_SOFTWARE)
139  {
140  // TRANSLATORS: servers dialog name
141  setCaption(_("Choose Your Server *** SOFTWARE RENDER MODE ***"));
142  }
143 #endif // USE_OPENGL
144 
145  setWindowName("ServerDialog");
146 
147  setCloseButton(true);
148 
149  mPersistentIPCheckBox = new CheckBox(this,
150  // TRANSLATORS: servers dialog checkbox
151  _("Use same ip for game sub servers"),
152  config.getBoolValue("usePersistentIP"),
153  this, "persitent ip");
154 
156 
158 
159  ScrollArea *const usedScroll = new ScrollArea(this, mServersList,
160  fromBool(getOptionBool("showbackground", false), Opaque),
161  "server_background.xml");
163 
165  usedScroll->setVerticalScrollAmount(0);
166 
167  place(0, 0, usedScroll, 8, 5).setPadding(3);
168  place(0, 5, mDescription, 8, 1);
169  place(0, 6, mPersistentIPCheckBox, 8, 1);
170  place(0, 7, mInfoButton, 1, 1);
171  place(1, 7, mAddEntryButton, 1, 1);
172  place(2, 7, mEditEntryButton, 1, 1);
173  place(3, 7, mLoadButton, 1, 1);
174  place(4, 7, mDeleteButton, 1, 1);
175  place(6, 7, mQuitButton, 1, 1);
176  place(7, 7, mConnectButton, 1, 1);
177 
178  // Make sure the list has enough height
179  getLayout().setRowHeight(0, 80);
180 
181  // Do this manually instead of calling reflowLayout so we can enforce a
182  // minimum width.
183  int width = 500;
184  int height = 350;
185 
186  getLayout().reflow(width, height);
187  setContentSize(width, height);
188 
189  setMinWidth(310);
190  setMinHeight(220);
192 
193  setResizable(true);
194  addKeyListener(this);
195 
196  loadWindowState();
197 }
#define fromBool(val, name)
Definition: booldefines.h:49
const std::string BUTTON_SKIN
Definition: button.h:89
Definition: button.h:102
bool getBoolValue(const std::string &key) const
int getIntValue(const std::string &key) const
Definition: label.h:91
LayoutCell & setPadding(int p)
Definition: layoutcell.h:60
void setRowHeight(const int n, const int h)
Definition: layoutcell.cpp:128
void reflow(int &nW, int &nH)
Definition: layout.cpp:36
void addSelectionListener(SelectionListener *const selectionListener)
Definition: listbox.cpp:435
void setVerticalScrollAmount(const int vScroll)
void setHorizontalScrollPolicy(const ScrollPolicy hPolicy)
Net::Download * mDownload
Definition: serverdialog.h:144
Button * mQuitButton
Definition: serverdialog.h:133
ServerDialogDownloadStatusT mDownloadStatus
Definition: serverdialog.h:148
const std::string & mDir
Definition: serverdialog.h:131
CheckBox * mPersistentIPCheckBox
Definition: serverdialog.h:146
Button * mConnectButton
Definition: serverdialog.h:134
Label * mDescription
Definition: serverdialog.h:132
Button * mEditEntryButton
Definition: serverdialog.h:136
ServerInfos mServers
Definition: serverdialog.h:130
Button * mInfoButton
Definition: serverdialog.h:139
friend class ServersListModel
Definition: serverdialog.h:102
void loadCustomServers()
float mDownloadProgress
Definition: serverdialog.h:147
Button * mAddEntryButton
Definition: serverdialog.h:135
Button * mLoadButton
Definition: serverdialog.h:138
ListBox * mServersList
Definition: serverdialog.h:141
Button * mDeleteButton
Definition: serverdialog.h:137
ServersListModel * mServersListModel
Definition: serverdialog.h:140
ServerInfo * mServerInfo
Definition: serverdialog.h:145
void addMouseListener(MouseListener *const mouseListener)
Definition: widget.cpp:292
void addKeyListener(KeyListener *const keyListener)
Definition: widget.cpp:272
int getHeight() const
Definition: widget.h:240
int getWidth() const
Definition: widget.h:221
void setResizable(const bool resize)
Definition: window.cpp:627
bool getOptionBool(const std::string &name, const bool def) const
Definition: window.cpp:1466
void setContentSize(int width, int height)
Definition: window.cpp:492
Layout & getLayout()
Definition: window.cpp:1365
void setWindowName(const std::string &name)
Definition: window.h:355
Window(const std::string &caption, const Modal modal, Window *const parent, std::string skin)
Definition: window.cpp:109
void setCaption(const std::string &caption)
Definition: window.h:531
void setMinHeight(const int height)
Definition: window.cpp:604
void setMinWidth(const int width)
Definition: window.cpp:591
void setCloseButton(const bool flag)
Definition: window.cpp:749
LayoutCell & place(const int x, const int y, Widget *const wg, const int w, const int h)
Definition: window.cpp:1384
void setDefaultSize()
Definition: window.cpp:1198
void loadWindowState()
Definition: window.cpp:1087
Configuration config
#define CREATEWIDGETR(type,...)
Definition: createwidget.h:36
bool isSafeMode
Definition: client.cpp:123
#define _(s)
Definition: gettext.h:35
const bool Modal_false
Definition: modal.h:30
bool Opaque
Definition: opaque.h:30
@ RENDER_SOFTWARE
Definition: rendertype.h:27
std::vector< ServerInfo > ServerInfos
Definition: serverinfo.h:227

References _, Widget::addKeyListener(), Widget::addMouseListener(), ListBox::addSelectionListener(), ImagePosition::CENTER, config, fromBool, Configuration::getBoolValue(), Widget::getHeight(), Configuration::getIntValue(), Window::getLayout(), Window::getOptionBool(), Widget::getWidth(), isSafeMode, loadCustomServers(), Window::loadWindowState(), mAddEntryButton, mConnectButton, mDeleteButton, mDescription, mEditEntryButton, mInfoButton, mLoadButton, mPersistentIPCheckBox, mQuitButton, mServersList, Window::place(), Layout::reflow(), RENDER_SOFTWARE, Window::setCaption(), Window::setCloseButton(), Window::setContentSize(), Window::setDefaultSize(), ScrollArea::setHorizontalScrollPolicy(), Window::setMinHeight(), Window::setMinWidth(), LayoutCell::setPadding(), Window::setResizable(), LayoutCell::setRowHeight(), ScrollArea::setVerticalScrollAmount(), Window::setWindowName(), and ScrollArea::SHOW_NEVER.

◆ ~ServerDialog()

ServerDialog::~ServerDialog ( )

Destructor

Definition at line 216 of file serverdialog.cpp.

217 {
218  if (mDownload != nullptr)
219  {
220  mDownload->cancel();
222  }
224 }
unsigned cancel
Definition: download.h:127
#define delete2(var)
Definition: delete2.h:25

References Net::Download::cancel, delete2, mDownload, and mServersListModel.

Member Function Documentation

◆ action()

void ServerDialog::action ( const ActionEvent event)
virtual

Called when receiving actions from the widgets.

Implements ActionListener.

Definition at line 289 of file serverdialog.cpp.

290 {
291  const std::string &eventId = event.getId();
292  if (eventId == "connect")
293  {
295  }
296  else if (eventId == "quit")
297  {
298  close();
299  }
300  else if (eventId == "load")
301  {
303  }
304  else if (eventId == "addEntry")
305  {
307  }
308  else if (eventId == "editEntry")
309  {
310  const int index = mServersList->getSelected();
311  if (index >= 0)
312  {
314  this,
315  mServers.at(index),
316  index);
317  }
318  }
319  else if (eventId == "remove")
320  {
321  const int index = mServersList->getSelected();
322  if (index >= 0)
323  {
325  mServers.erase(mServers.begin() + index);
327  -1);
328  }
329  }
330  else if (eventId == "info")
331  {
332  const int index = mServersList->getSelected();
333  if (index >= 0)
334  {
335  if (serverInfoWindow != nullptr)
338  mServers.at(index));
339  }
340  }
341 }
int getSelected() const
Definition: listbox.h:168
void setSelected(const int selected)
Definition: listbox.cpp:399
void saveCustomServers(const ServerInfo &currentServer, const int index)
void downloadServerList()
void connectToSelectedServer()
virtual void scheduleDelete()
Definition: window.cpp:831
#define CREATEWIDGET(type,...)
Definition: createwidget.h:29
ServerInfoWindow * serverInfoWindow

References close(), connectToSelectedServer(), CREATEWIDGET, CREATEWIDGETR, downloadServerList(), ListBox::getSelected(), mServers, mServersList, saveCustomServers(), Window::scheduleDelete(), serverInfoWindow, and ListBox::setSelected().

Referenced by keyPressed(), and mouseClicked().

◆ close()

void ServerDialog::close ( )
virtual

Overrideable functionality for when the window is to close. This allows for class implementations to clean up or do certain actions on window close they couldn't do otherwise.

Reimplemented from Window.

Definition at line 910 of file serverdialog.cpp.

911 {
912  if (mDownload != nullptr)
913  mDownload->cancel();
915  Window::close();
916 }
void setState(const StateT state)
Definition: client.h:66
virtual void close()
Definition: window.cpp:902
Client * client
Definition: client.cpp:118
@ FORCE_QUIT
Definition: state.h:68

References Net::Download::cancel, client, Window::close(), State::FORCE_QUIT, mDownload, and Client::setState().

Referenced by action().

◆ connectToSelectedServer()

void ServerDialog::connectToSelectedServer ( )

Definition at line 226 of file serverdialog.cpp.

227 {
229  return;
230 
231  const int index = mServersList->getSelected();
232  if (index < 0)
233  return;
234 
235  if (mDownload != nullptr)
236  mDownload->cancel();
237 
238  mQuitButton->setEnabled(false);
239  mConnectButton->setEnabled(false);
240  mLoadButton->setEnabled(false);
241 
242  ServerInfo server = mServers.at(index);
243  mServerInfo->hostname = server.hostname;
245  mServerInfo->port = server.port;
246  mServerInfo->type = server.type;
247  mServerInfo->name = server.name;
253  mServerInfo->save = true;
255  mServerInfo->freeType = server.freeType;
261  mServerInfo->docs = server.docs;
262  mServerInfo->serverUrl = server.serverUrl;
263 
267 
268  if (chatLogger != nullptr)
270 
272  -1);
273 
275  {
277  {
279  if (desktop != nullptr)
281  }
282  }
283 
284  config.setValue("usePersistentIP",
287 }
ChatLogger * chatLogger
Definition: chatlogger.cpp:43
void setServerName(const std::string &serverName)
Definition: chatlogger.cpp:176
bool isSelected() const
Definition: checkbox.h:147
StateT getState() const
Definition: client.h:69
void setValue(const std::string &key, const std::string &value)
void reloadWallpaper()
Definition: desktop.cpp:122
static std::string savedPasswordKey
Definition: logindialog.h:79
static std::string savedPassword
Definition: logindialog.h:80
std::string hostname
Definition: serverinfo.h:45
std::vector< std::string > updateMirrors
Definition: serverinfo.h:53
std::string serverUrl
Definition: serverinfo.h:51
std::vector< ServerUrlInfo > nonFreeSources
Definition: serverinfo.h:56
std::string supportUrl
Definition: serverinfo.h:50
std::string althostname
Definition: serverinfo.h:46
uint16_t port
Definition: serverinfo.h:58
std::vector< HostsGroup > updateHosts
Definition: serverinfo.h:54
std::vector< ServerUrlInfo > docs
Definition: serverinfo.h:57
std::string onlineListUrl
Definition: serverinfo.h:49
int packetVersion
Definition: serverinfo.h:60
ServerTypeT type
Definition: serverinfo.h:42
bool persistentIp
Definition: serverinfo.h:62
std::string name
Definition: serverinfo.h:44
std::string registerUrl
Definition: serverinfo.h:48
std::string defaultHostName
Definition: serverinfo.h:52
std::string description
Definition: serverinfo.h:47
ServerFreeTypeT freeType
Definition: serverinfo.h:43
bool save
Definition: serverinfo.h:61
std::vector< ServerUrlInfo > freeSources
Definition: serverinfo.h:55
bool persistentIp
Definition: settings.h:153
std::vector< std::string > updateMirrors
Definition: settings.h:129
std::string supportUrl
Definition: settings.h:121
void setEnabled(const bool enabled)
Definition: widget.h:352
Desktop * desktop
Definition: desktop.cpp:49
@ CONNECT_SERVER
Definition: state.h:38
std::string empty
Definition: podict.cpp:26
Settings settings
Definition: settings.cpp:32

References ServerInfo::althostname, Net::Download::cancel, chatLogger, client, config, State::CONNECT_SERVER, ServerInfo::defaultHostName, ServerInfo::description, desktop, ServerInfo::docs, empty, ServerInfo::freeSources, ServerInfo::freeType, ListBox::getSelected(), Client::getState(), ServerInfo::hostname, CheckBox::isSelected(), mConnectButton, mDownload, mLoadButton, mPersistentIPCheckBox, mQuitButton, mServerInfo, mServers, mServersList, ServerInfo::name, ServerInfo::nonFreeSources, ServerInfo::onlineListUrl, ServerInfo::packetVersion, ServerInfo::persistentIp, Settings::persistentIp, ServerInfo::port, ServerInfo::registerUrl, Desktop::reloadWallpaper(), ServerInfo::save, saveCustomServers(), LoginDialog::savedPassword, LoginDialog::savedPasswordKey, ServerInfo::serverUrl, Widget::setEnabled(), ChatLogger::setServerName(), Client::setState(), settings, Configuration::setValue(), ServerInfo::supportUrl, Settings::supportUrl, ServerInfo::type, ServerInfo::updateHosts, ServerInfo::updateMirrors, and Settings::updateMirrors.

Referenced by EditServerDialog::action(), and action().

◆ downloadServerList()

void ServerDialog::downloadServerList ( )
private

Called to load a list of available server from an online xml file.

Definition at line 462 of file serverdialog.cpp.

463 {
464  // Try to load the configuration value for the onlineServerList
465  std::string listFile = branding.getStringValue("onlineServerList");
466  std::string listFile2 = branding.getStringValue("onlineServerList2");
467 
468  // Fall back to manaplus.org when neither branding
469  // nor config set it
470  if (listFile.empty())
471  listFile = "http://manaplus.org/serverlist.xml";
472 
473  if (mDownload != nullptr)
474  {
475  mDownload->cancel();
477  }
478 
479  mDownload = new Net::Download(this, listFile,
480  &downloadUpdate, false, false, true);
482  branding.getStringValue("onlineServerFile")),
483  -1);
484  if (!listFile2.empty())
485  mDownload->addMirror(listFile2);
486  mDownload->start();
487 
488  config.setValue("serverslistupdate", getDateString());
489 }
std::string getStringValue(const std::string &key) const
void setFile(const std::string &filename, const int64_t adler32)
Definition: download.cpp:166
void addMirror(const std::string &str)
Definition: download.h:88
bool start()
Definition: download.cpp:188
static int downloadUpdate(void *ptr, const DownloadStatusT status, size_t total, const size_t remaining)
Configuration branding
std::string pathJoin(std::string str1, const std::string &str2)
std::string getDateString()

References Net::Download::addMirror(), branding, Net::Download::cancel, config, delete2, downloadUpdate(), getDateString(), Configuration::getStringValue(), mDir, mDownload, pathJoin(), Net::Download::setFile(), Configuration::setValue(), and Net::Download::start().

Referenced by action(), and postInit().

◆ downloadUpdate()

int ServerDialog::downloadUpdate ( void *  ptr,
const DownloadStatusT  status,
size_t  total,
const size_t  remaining 
)
staticprivate

Definition at line 845 of file serverdialog.cpp.

849 {
850  if ((ptr == nullptr) || status == DownloadStatus::Cancelled)
851  return -1;
852 
853  ServerDialog *const sd = reinterpret_cast<ServerDialog*>(ptr);
854  bool finished = false;
855 
856  if (sd->mDownload == nullptr)
857  return -1;
858 
859  if (status == DownloadStatus::Complete)
860  {
861  finished = true;
862  }
863  else if (CAST_S32(status) < 0)
864  {
865  logger->log("Error retreiving server list: %s\n",
866  sd->mDownload->getError());
868  }
869  else
870  {
871  float progress = static_cast<float>(remaining);
872  if (total != 0U)
873  progress /= static_cast<float>(total);
874 
875  if (progress != progress || progress < 0.0F)
876  progress = 0.0F;
877  else if (progress > 1.0F)
878  progress = 1.0F;
879 
880  MutexLocker lock1(&sd->mMutex);
882  sd->mDownloadProgress = progress;
883  }
884 
885  if (finished)
886  {
887  MutexLocker lock1(&sd->mMutex);
889  }
890 
891  return 0;
892 }
#define CAST_S32
Definition: cast.h:30
void log(const char *const log_text,...)
Definition: logger.cpp:269
const char * getError() const
Definition: download.cpp:218
Logger * logger
Definition: logger.cpp:89

References DownloadStatus::Cancelled, CAST_S32, ServerDialogDownloadStatus::COMPLETE, DownloadStatus::Complete, ServerDialogDownloadStatus::ERROR, Net::Download::getError(), ServerDialogDownloadStatus::IN_PROGRESS, Logger::log(), logger, mDownload, mDownloadProgress, mDownloadStatus, and mMutex.

Referenced by downloadServerList().

◆ keyPressed()

void ServerDialog::keyPressed ( KeyEvent event)
virtual

Called if a key is pressed when the widget has keyboard focus. If a key is held down the widget will generate multiple key presses.

Parameters
eventDiscribes the event.

Reimplemented from KeyListener.

Definition at line 343 of file serverdialog.cpp.

344 {
345  PRAGMA45(GCC diagnostic push)
346  PRAGMA45(GCC diagnostic ignored "-Wswitch-enum")
347  switch (event.getActionId())
348  {
350  event.consume();
352  return;
353 
356  event.consume();
357  action(ActionEvent(nullptr,
359  return;
360 
363  return;
364 
366  {
367  const int index = mServersList->getSelected();
368  if (index >= 0)
369  {
371  mServers.erase(mServers.begin() + index);
373  -1);
374  }
375  return;
376  }
377 
379  {
380  const int index = mServersList->getSelected();
381  if (index >= 0)
382  {
383  CREATEWIDGET(EditServerDialog, this, mServers.at(index),
384  index);
385  }
386  return;
387  }
388 
389  default:
390  break;
391  }
392  PRAGMA45(GCC diagnostic pop)
393  if (!event.isConsumed())
394  mServersList->keyPressed(event);
395 }
bool isConsumed() const
InputActionT getActionId() const
Definition: keyevent.h:127
void keyPressed(KeyEvent &event)
Definition: listbox.cpp:246
void action(const ActionEvent &event)
const std::string & getActionEventId() const
Definition: widget.h:605
PRAGMA45(GCC diagnostic push) PRAGMA45(GCC diagnostic ignored "-Wredundant-decls") PRAGMA45(GCC diagnostic pop) class TestMain
@ EXIT
Definition: state.h:67

References action(), client, CREATEWIDGET, State::EXIT, Widget::getActionEventId(), KeyEvent::getActionId(), ListBox::getSelected(), InputAction::GUI_BACKSPACE, InputAction::GUI_CANCEL, InputAction::GUI_DELETE, InputAction::GUI_INSERT, InputAction::GUI_SELECT, InputAction::GUI_SELECT2, InputGuiEvent::isConsumed(), ListBox::keyPressed(), mConnectButton, mServers, mServersList, PRAGMA45(), saveCustomServers(), ListBox::setSelected(), and Client::setState().

◆ loadCustomServers()

void ServerDialog::loadCustomServers ( )
private

Definition at line 743 of file serverdialog.cpp.

744 {
745  for (int i = 0; i < MAX_SERVERLIST; ++i)
746  {
747  const std::string index = toString(i);
748  const std::string nameKey("MostUsedServerDescName" + index);
749  const std::string descKey("MostUsedServerDescription" + index);
750  const std::string hostKey("MostUsedServerName" + index);
751  const std::string typeKey("MostUsedServerType" + index);
752  const std::string portKey("MostUsedServerPort" + index);
753  const std::string onlineListUrlKey
754  ("MostUsedServerOnlineList" + index);
755  const std::string persistentIpKey("persistentIp" + index);
756  const std::string packetVersionKey
757  ("MostUsedServerPacketVersion" + index);
758 
759  ServerInfo server;
760  server.name = config.getValue(nameKey, "");
761  server.description = config.getValue(descKey, "");
762  server.onlineListUrl = config.getValue(onlineListUrlKey, "");
763  server.hostname = config.getValue(hostKey, "");
764  server.type = ServerInfo::parseType(config.getValue(typeKey, ""));
765  server.persistentIp = config.getValue(
766  persistentIpKey, 0) != 0 ? true : false;
767  server.packetVersion = config.getValue(packetVersionKey, 0);
768 
769  const int defaultPort = defaultPortForServerType(server.type);
770  server.port = CAST_U16(
771  config.getValue(portKey, defaultPort));
772 
773  // skip invalid server
774  if (!server.isValid())
775  continue;
776 
777  server.save = true;
778  mServers.push_back(server);
779  }
780 }
#define CAST_U16
Definition: cast.h:29
std::string getValue(const std::string &key, const std::string &deflt) const
bool isValid() const
Definition: serverinfo.h:150
static ServerTypeT parseType(const std::string &serverType)
Definition: serverinfo.h:197
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
static uint16_t defaultPortForServerType(const ServerTypeT type)
static const int MAX_SERVERLIST

References CAST_U16, config, defaultPortForServerType(), ServerInfo::description, ConfigurationObject::getValue(), ServerInfo::hostname, ServerInfo::isValid(), MAX_SERVERLIST, mServers, ServerInfo::name, ServerInfo::onlineListUrl, ServerInfo::packetVersion, ServerInfo::parseType(), ServerInfo::persistentIp, ServerInfo::port, ServerInfo::save, Catch::toString(), and ServerInfo::type.

Referenced by ServerDialog().

◆ loadServers()

void ServerDialog::loadServers ( const bool  addNew)
private

Definition at line 559 of file serverdialog.cpp.

560 {
562  branding.getStringValue("onlineServerFile")),
565  XmlNodeConstPtr rootNode = doc.rootNode();
566 
567  if (rootNode == nullptr ||
568  !xmlNameEqual(rootNode, "serverlist"))
569  {
570  logger->log1("Error loading server list!");
571  return;
572  }
573 
574  const int ver = XML::getProperty(rootNode, "version", 0);
575  if (ver != 1)
576  {
577  logger->log("Error: unsupported online server list version: %d",
578  ver);
579  return;
580  }
581 
582  const std::string lang = getLangShort();
583  const std::string description2("description_" + lang);
584 
585  for_each_xml_child_node(serverNode, rootNode)
586  {
587  if (!xmlNameEqual(serverNode, "server"))
588  continue;
589 
590  const std::string type = XML::getProperty(
591  serverNode, "type", "unknown");
592  ServerInfo server;
593  server.type = ServerInfo::parseType(type);
594  const std::string licenseType = XML::getProperty(
595  serverNode, "licenseType", "notset");
596  server.freeType = ServerInfo::parseFreeType(licenseType);
597 
598  // Ignore unknown server types
599  if (server.type == ServerType::UNKNOWN)
600  {
601  logger->log("Ignoring server entry with unknown type: %s",
602  type.c_str());
603  continue;
604  }
605 
606  server.name = XML::getProperty(serverNode, "name", std::string());
607  std::string version = XML::getProperty(serverNode, "minimumVersion",
608  std::string());
609 
610  const bool meetsMinimumVersion = (compareStrI(version, SMALL_VERSION)
611  <= 0);
612 
613  // For display in the list
614  if (meetsMinimumVersion)
615  version.clear();
616  else if (version.empty())
617  {
618  // TRANSLATORS: servers dialog label
619  version = _("requires a newer version");
620  }
621  else
622  {
623  // TRANSLATORS: servers dialog label
624  version = strprintf(_("requires v%s"), version.c_str());
625  }
626 
627  const Font *const font = gui->getFont();
628 
629  for_each_xml_child_node(subNode, serverNode)
630  {
631  if (xmlNameEqual(subNode, "connection"))
632  {
633  server.hostname = XML::getProperty(subNode, "hostname", "");
634  server.althostname = XML::getProperty(
635  subNode, "althostname", "");
636  server.port = CAST_U16(
637  XML::getProperty(subNode, "port", 0));
638  server.packetVersion = XML::getProperty(subNode,
639  "packetVersion", 0);
640 
641  if (server.port == 0)
642  {
643  // If no port is given, use the default for the given type
644  server.port = defaultPortForServerType(server.type);
645  }
646  }
647  else if (XmlHaveChildContent(subNode))
648  {
649  if ((xmlNameEqual(subNode, "description")
650  && server.description.empty()) || (!lang.empty()
651  && xmlNameEqual(subNode, description2.c_str())))
652  {
653  server.description = XmlChildContent(subNode);
654  }
655  else if (xmlNameEqual(subNode, "registerurl"))
656  {
657  server.registerUrl = XmlChildContent(subNode);
658  }
659  else if (xmlNameEqual(subNode, "onlineListUrl"))
660  {
661  server.onlineListUrl = XmlChildContent(subNode);
662  }
663  else if (xmlNameEqual(subNode, "support"))
664  {
665  server.supportUrl = XmlChildContent(subNode);
666  }
667  else if (xmlNameEqual(subNode, "persistentIp"))
668  {
669  std::string text = XmlChildContent(subNode);
670  server.persistentIp = (text == "1" || text == "true");
671  }
672  else if (xmlNameEqual(subNode, "updateMirror"))
673  {
674  server.updateMirrors.push_back(XmlChildContent(subNode));
675  }
676  else if (xmlNameEqual(subNode, "site"))
677  {
678  server.serverUrl = XmlChildContent(subNode);
679  }
680  }
681  if (xmlNameEqual(subNode, "updates"))
682  {
683  loadHostsGroup(subNode, server);
684  }
685  else if (xmlNameEqual(subNode, "defaultUpdateHost"))
686  {
688  // TRANSLATORS: default hosts group name
689  subNode, "name", _("default"));
690  }
691  else if (xmlNameEqual(subNode, "sources"))
692  {
693  loadServerSources(subNode, server);
694  }
695  else if (xmlNameEqual(subNode, "docs"))
696  {
697  loadServerSourcesList(subNode, server.docs);
698  }
699  }
700 
701  server.version.first = font->getWidth(version);
702  server.version.second = version;
703 
704  MutexLocker tempLock(&mMutex);
705  // Add the server to the local list if it's not already present
706  bool found = false;
707  for (unsigned int i = 0, fsz = CAST_U32(
708  mServers.size()); i < fsz; i++)
709  {
710  if (mServers[i] == server)
711  {
712  // Use the name listed in the server list
713  mServers[i].name = server.name;
714  mServers[i].type = server.type;
715  mServers[i].freeType = server.freeType;
716  mServers[i].version = server.version;
717  mServers[i].description = server.description;
718  mServers[i].registerUrl = server.registerUrl;
719  mServers[i].onlineListUrl = server.onlineListUrl;
720  mServers[i].supportUrl = server.supportUrl;
721  mServers[i].serverUrl = server.serverUrl;
722  mServers[i].althostname = server.althostname;
723  mServers[i].persistentIp = server.persistentIp;
724  mServers[i].updateMirrors = server.updateMirrors;
725  mServers[i].defaultHostName = server.defaultHostName;
726  mServers[i].updateHosts = server.updateHosts;
727  mServers[i].packetVersion = server.packetVersion;
728  mServers[i].freeSources = server.freeSources;
729  mServers[i].nonFreeSources = server.nonFreeSources;
730  mServers[i].docs = server.docs;
731  mServersListModel->setVersionString(i, version);
732  found = true;
733  break;
734  }
735  }
736  if (!found && addNew)
737  mServers.push_back(server);
738  }
739  if (mServersList->getSelected() < 0)
741 }
#define CAST_U32
Definition: cast.h:31
Definition: font.h:90
int getWidth(const std::string &text) const
Definition: font.cpp:334
Font * getFont() const
Definition: gui.h:160
void log1(const char *const log_text)
Definition: logger.cpp:238
static ServerFreeTypeT parseFreeType(const std::string &serverFreeType)
Definition: serverinfo.h:214
VersionString version
Definition: serverinfo.h:59
void setVersionString(const int index, const std::string &version)
Gui * gui
Definition: gui.cpp:111
std::string getLangShort()
Definition: langs.cpp:102
#define for_each_xml_child_node(var, parent)
Definition: libxml.h:161
#define SMALL_VERSION
Definition: main.h:44
std::string langProperty(const xmlNodePtr node, const char *const name, const std::string &def)
Definition: libxml.cpp:258
int getProperty(const xmlNodePtr node, const char *const name, int def)
Definition: libxml.cpp:174
static void loadServerSourcesList(const xmlNodePtr node, std::vector< ServerUrlInfo > &list)
static void loadHostsGroup(const xmlNodePtr node, ServerInfo &server)
static void loadServerSources(const xmlNodePtr node, ServerInfo &server)
const bool SkipError_true
Definition: skiperror.h:30
std::string strprintf(const char *const format,...)
int compareStrI(const std::string &a, const std::string &b)
const bool UseVirtFs_false
Definition: usevirtfs.h:30

References _, ServerInfo::althostname, branding, CAST_U16, CAST_U32, compareStrI(), ServerInfo::defaultHostName, defaultPortForServerType(), ServerInfo::description, ServerInfo::docs, for_each_xml_child_node, ServerInfo::freeSources, ServerInfo::freeType, Gui::getFont(), getLangShort(), XML::getProperty(), ListBox::getSelected(), Configuration::getStringValue(), Font::getWidth(), gui, ServerInfo::hostname, XML::langProperty(), loadHostsGroup(), loadServerSources(), loadServerSourcesList(), Logger::log(), Logger::log1(), logger, mDir, mMutex, mServers, mServersList, mServersListModel, ServerInfo::name, ServerInfo::nonFreeSources, ServerInfo::onlineListUrl, ServerInfo::packetVersion, ServerInfo::parseFreeType(), ServerInfo::parseType(), pathJoin(), ServerInfo::persistentIp, ServerInfo::port, ServerInfo::registerUrl, XML::Document::rootNode(), ServerInfo::serverUrl, ListBox::setSelected(), ServersListModel::setVersionString(), SkipError_true, SMALL_VERSION, strprintf(), ServerInfo::supportUrl, ServerInfo::type, ServerType::UNKNOWN, ServerInfo::updateHosts, ServerInfo::updateMirrors, UseVirtFs_false, and ServerInfo::version.

Referenced by logic(), and postInit().

◆ lock()

MutexLocker ServerDialog::lock ( )
inlineprotected

Definition at line 104 of file serverdialog.h.

105  { return MutexLocker(&mMutex); }

References mMutex.

Referenced by ServersListModel::getElementAt(), and ServersListModel::getNumberOfElements().

◆ logic()

void ServerDialog::logic ( )
virtual

Called for all widgets in the gui each time Gui::logic is called. You can do logic stuff here like playing an animation.

See also
Gui::logic

Reimplemented from BasicContainer.

Definition at line 422 of file serverdialog.cpp.

423 {
424  BLOCK_START("ServerDialog::logic")
425  {
426  MutexLocker tempLock(&mMutex);
428  {
429  loadServers(true);
431  mDescription->setCaption(std::string());
432  logger->log("Servers list updated");
433  }
435  {
436  // TRANSLATORS: servers dialog label
437  mDescription->setCaption(strprintf(_("Downloading server list..."
438  "%2.2f%%"), static_cast<double>(mDownloadProgress * 100)));
439  }
441  {
442  // TRANSLATORS: servers dialog label
443  mDescription->setCaption(_("Waiting for server..."));
444  }
446  {
447  // TRANSLATORS: servers dialog label
448  mDescription->setCaption(_("Preparing download"));
449  }
451  {
452  // TRANSLATORS: servers dialog label
453  mDescription->setCaption(_("Error retreiving server list!"));
454  logger->log("Error: servers list updating error");
455  }
456  }
457 
458  Window::logic();
459  BLOCK_END("ServerDialog::logic")
460 }
void setCaption(const std::string &caption)
Definition: label.cpp:264
void loadServers(const bool addNew)
#define BLOCK_END(name)
Definition: perfomance.h:80
#define BLOCK_START(name)
Definition: perfomance.h:79

References _, BLOCK_END, BLOCK_START, ServerDialogDownloadStatus::COMPLETE, ServerDialogDownloadStatus::ERROR, ServerDialogDownloadStatus::IDLE, ServerDialogDownloadStatus::IN_PROGRESS, loadServers(), Logger::log(), logger, BasicContainer::logic(), mDescription, mDownloadProgress, mDownloadStatus, mMutex, ServerDialogDownloadStatus::OVER, ServerDialogDownloadStatus::PREPARING, Label::setCaption(), and strprintf().

◆ mouseClicked()

void ServerDialog::mouseClicked ( MouseEvent event)
virtual

Called when a mouse button is pressed and released (clicked) on the widget area.

Parameters
eventDescribes the event.

Reimplemented from MouseListener.

Definition at line 408 of file serverdialog.cpp.

409 {
410  if (event.getButton() == MouseButton::LEFT)
411  {
412  event.consume();
413  if (event.getClickCount() == 2 &&
414  event.getSource() == mServersList)
415  {
418  }
419  }
420 }
Widget * getSource() const
Definition: event.h:104
MouseButtonT getButton() const
Definition: mouseevent.h:116
int getClickCount() const
Definition: mouseevent.h:147

References action(), Widget::getActionEventId(), MouseEvent::getButton(), MouseEvent::getClickCount(), Event::getSource(), MouseButton::LEFT, mConnectButton, and mServersList.

◆ needUpdateServers()

bool ServerDialog::needUpdateServers ( ) const
private

Definition at line 899 of file serverdialog.cpp.

900 {
901  if (mServers.empty() || config.getStringValue("serverslistupdate")
902  != getDateString())
903  {
904  return true;
905  }
906 
907  return false;
908 }

References config, getDateString(), Configuration::getStringValue(), and mServers.

Referenced by postInit().

◆ postInit()

void ServerDialog::postInit ( )
virtual

Reimplemented from Window.

Definition at line 199 of file serverdialog.cpp.

200 {
203 
205 
206  loadServers(true);
207 
208  mServersList->setSelected(0); // Do this after for the Delete button
209 
210  if (needUpdateServers())
212  else
213  logger->log("Skipping servers list update");
214 }
bool needUpdateServers() const
virtual void requestFocus()
Definition: widget.cpp:204
virtual void setVisible(Visible visible)
Definition: window.cpp:778
void postInit()
Definition: window.cpp:249
const bool Visible_true
Definition: visible.h:30

References downloadServerList(), loadServers(), Logger::log(), logger, mConnectButton, mServersList, needUpdateServers(), Window::postInit(), Widget::requestFocus(), ListBox::setSelected(), Window::setVisible(), and Visible_true.

◆ saveCustomServers()

void ServerDialog::saveCustomServers ( const ServerInfo currentServer,
const int  index 
)
private

Definition at line 782 of file serverdialog.cpp.

784 {
785  // Make sure the current server is mentioned first
786  if (currentServer.isValid())
787  {
788  if (index >= 0 && CAST_SIZE(index) < mServers.size())
789  {
790  mServers[index] = currentServer;
791  }
792  else
793  {
794  FOR_EACH (ServerInfos::iterator, i, mServers)
795  {
796  if (*i == currentServer)
797  {
798  mServers.erase(i);
799  break;
800  }
801  }
802  mServers.insert(mServers.begin(), currentServer);
803  }
804  }
805 
806  int savedServerCount = 0;
807 
808  for (unsigned i = 0, fsz = CAST_U32(mServers.size());
809  i < fsz && savedServerCount < MAX_SERVERLIST; ++ i)
810  {
811  const ServerInfo &server = mServers.at(i);
812 
813  // Only save servers that were loaded from settings
814  if (!(server.save && server.isValid()))
815  continue;
816 
817  const std::string num = toString(savedServerCount);
818  const std::string nameKey("MostUsedServerDescName" + num);
819  const std::string descKey("MostUsedServerDescription" + num);
820  const std::string hostKey("MostUsedServerName" + num);
821  const std::string typeKey("MostUsedServerType" + num);
822  const std::string portKey("MostUsedServerPort" + num);
823  const std::string onlineListUrlKey
824  ("MostUsedServerOnlineList" + num);
825  const std::string persistentIpKey("persistentIp" + num);
826  const std::string packetVersionKey
827  ("MostUsedServerPacketVersion" + num);
828 
829  config.setValue(nameKey, server.name);
830  config.setValue(descKey, server.description);
831  config.setValue(onlineListUrlKey, server.onlineListUrl);
832  config.setValue(hostKey, server.hostname);
833  config.setValue(typeKey, serverTypeToString(server.type));
834  config.setValue(portKey, toString(server.port));
835  config.setValue(persistentIpKey, server.persistentIp);
836  config.setValue(packetVersionKey, server.packetVersion);
837  ++ savedServerCount;
838  }
839 
840  // Insert an invalid entry at the end to make the loading stop there
841  if (savedServerCount < MAX_SERVERLIST)
842  config.setValue("MostUsedServerName" + toString(savedServerCount), "");
843 }
#define CAST_SIZE
Definition: cast.h:34
#define FOR_EACH(type, iter, array)
Definition: foreach.h:25
static std::string serverTypeToString(const ServerTypeT type)

References CAST_SIZE, CAST_U32, config, ServerInfo::description, FOR_EACH, ServerInfo::hostname, ServerInfo::isValid(), MAX_SERVERLIST, mServers, ServerInfo::name, ServerInfo::onlineListUrl, ServerInfo::packetVersion, ServerInfo::persistentIp, ServerInfo::port, ServerInfo::save, serverTypeToString(), Configuration::setValue(), Catch::toString(), and ServerInfo::type.

Referenced by action(), connectToSelectedServer(), keyPressed(), and updateServer().

◆ updateServer()

void ServerDialog::updateServer ( const ServerInfo server,
const int  index 
)

Definition at line 894 of file serverdialog.cpp.

895 {
896  saveCustomServers(server, index);
897 }

References saveCustomServers().

Referenced by EditServerDialog::action().

◆ valueChanged()

void ServerDialog::valueChanged ( const SelectionEvent event)
virtual

Called when the selected value changed in the servers list box.

Reimplemented from SelectionListener.

Definition at line 397 of file serverdialog.cpp.

398 {
399  const int index = mServersList->getSelected();
400  if (index == -1)
401  {
402  mDeleteButton->setEnabled(false);
403  return;
404  }
405  mDeleteButton->setEnabled(true);
406 }

References ListBox::getSelected(), mDeleteButton, mServersList, and Widget::setEnabled().

Friends And Related Function Documentation

◆ EditServerDialog

friend class EditServerDialog
friend

Definition at line 108 of file serverdialog.h.

◆ ServersListModel

friend class ServersListModel
friend

Definition at line 102 of file serverdialog.h.

Field Documentation

◆ mAddEntryButton

Button* ServerDialog::mAddEntryButton
private

Definition at line 135 of file serverdialog.h.

Referenced by ServerDialog().

◆ mConnectButton

Button* ServerDialog::mConnectButton
private

◆ mDeleteButton

Button* ServerDialog::mDeleteButton
private

Definition at line 137 of file serverdialog.h.

Referenced by ServerDialog(), and valueChanged().

◆ mDescription

Label* ServerDialog::mDescription
private

Definition at line 132 of file serverdialog.h.

Referenced by logic(), and ServerDialog().

◆ mDir

const std::string& ServerDialog::mDir
private

Definition at line 131 of file serverdialog.h.

Referenced by downloadServerList(), and loadServers().

◆ mDownload

Net::Download* ServerDialog::mDownload
private

Status of the current download.

Definition at line 144 of file serverdialog.h.

Referenced by close(), connectToSelectedServer(), downloadServerList(), downloadUpdate(), and ~ServerDialog().

◆ mDownloadProgress

float ServerDialog::mDownloadProgress
private

Definition at line 147 of file serverdialog.h.

Referenced by downloadUpdate(), and logic().

◆ mDownloadStatus

ServerDialogDownloadStatusT ServerDialog::mDownloadStatus
private

Definition at line 148 of file serverdialog.h.

Referenced by downloadUpdate(), and logic().

◆ mEditEntryButton

Button* ServerDialog::mEditEntryButton
private

Definition at line 136 of file serverdialog.h.

Referenced by ServerDialog().

◆ mInfoButton

Button* ServerDialog::mInfoButton
private

Definition at line 139 of file serverdialog.h.

Referenced by ServerDialog().

◆ mLoadButton

Button* ServerDialog::mLoadButton
private

Definition at line 138 of file serverdialog.h.

Referenced by connectToSelectedServer(), and ServerDialog().

◆ mMutex

Mutex ServerDialog::mMutex
private

Definition at line 129 of file serverdialog.h.

Referenced by downloadUpdate(), loadServers(), lock(), and logic().

◆ mPersistentIPCheckBox

CheckBox* ServerDialog::mPersistentIPCheckBox
private

Definition at line 146 of file serverdialog.h.

Referenced by connectToSelectedServer(), and ServerDialog().

◆ mQuitButton

Button* ServerDialog::mQuitButton
private

Definition at line 133 of file serverdialog.h.

Referenced by connectToSelectedServer(), and ServerDialog().

◆ mServerInfo

ServerInfo* ServerDialog::mServerInfo
private

Definition at line 145 of file serverdialog.h.

Referenced by connectToSelectedServer().

◆ mServers

ServerInfos ServerDialog::mServers
private

◆ mServersList

ListBox* ServerDialog::mServersList
private

◆ mServersListModel

ServersListModel* ServerDialog::mServersListModel
private

Definition at line 140 of file serverdialog.h.

Referenced by loadServers(), and ~ServerDialog().


The documentation for this class was generated from the following files: