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 56 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 96 of file serverdialog.cpp.

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.

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

◆ ~ServerDialog()

ServerDialog::~ServerDialog ( )

Destructor

Definition at line 215 of file serverdialog.cpp.

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

216 {
217  if (mDownload != nullptr)
218  {
219  mDownload->cancel();
221  }
223 }
unsigned cancel
Definition: download.h:126
#define delete2(var)
Definition: delete2.h:24
ServersListModel * mServersListModel
Definition: serverdialog.h:139
Net::Download * mDownload
Definition: serverdialog.h:143

Member Function Documentation

◆ action()

void ServerDialog::action ( const ActionEvent event)
virtual

Called when receiving actions from the widgets.

Implements ActionListener.

Definition at line 288 of file serverdialog.cpp.

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

Referenced by keyPressed(), and mouseClicked().

289 {
290  const std::string &eventId = event.getId();
291  if (eventId == "connect")
292  {
294  }
295  else if (eventId == "quit")
296  {
297  close();
298  }
299  else if (eventId == "load")
300  {
302  }
303  else if (eventId == "addEntry")
304  {
306  }
307  else if (eventId == "editEntry")
308  {
309  const int index = mServersList->getSelected();
310  if (index >= 0)
311  {
313  this,
314  mServers.at(index),
315  index);
316  }
317  }
318  else if (eventId == "remove")
319  {
320  const int index = mServersList->getSelected();
321  if (index >= 0)
322  {
324  mServers.erase(mServers.begin() + index);
326  -1);
327  }
328  }
329  else if (eventId == "info")
330  {
331  const int index = mServersList->getSelected();
332  if (index >= 0)
333  {
334  if (serverInfoWindow != nullptr)
337  mServers.at(index));
338  }
339  }
340 }
void setSelected(const int selected)
Definition: listbox.cpp:398
ServerInfos mServers
Definition: serverdialog.h:129
void downloadServerList()
ServerInfoWindow * serverInfoWindow
int getSelected() const
Definition: listbox.h:167
virtual void scheduleDelete()
Definition: window.cpp:826
void saveCustomServers(const ServerInfo &currentServer, const int index)
#define CREATEWIDGET(type,...)
Definition: createwidget.h:28
ListBox * mServersList
Definition: serverdialog.h:140
void connectToSelectedServer()
#define CREATEWIDGETR(type,...)
Definition: createwidget.h:35

◆ 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 909 of file serverdialog.cpp.

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

Referenced by action().

910 {
911  if (mDownload != nullptr)
912  mDownload->cancel();
914  Window::close();
915 }
void setState(const StateT state)
Definition: client.h:65
unsigned cancel
Definition: download.h:126
Client * client
Definition: client.cpp:117
virtual void close()
Definition: window.cpp:897
Net::Download * mDownload
Definition: serverdialog.h:143

◆ connectToSelectedServer()

void ServerDialog::connectToSelectedServer ( )

Definition at line 225 of file serverdialog.cpp.

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().

226 {
228  return;
229 
230  const int index = mServersList->getSelected();
231  if (index < 0)
232  return;
233 
234  if (mDownload != nullptr)
235  mDownload->cancel();
236 
237  mQuitButton->setEnabled(false);
238  mConnectButton->setEnabled(false);
239  mLoadButton->setEnabled(false);
240 
241  ServerInfo server = mServers.at(index);
242  mServerInfo->hostname = server.hostname;
244  mServerInfo->port = server.port;
245  mServerInfo->type = server.type;
246  mServerInfo->name = server.name;
252  mServerInfo->save = true;
254  mServerInfo->freeType = server.freeType;
260  mServerInfo->docs = server.docs;
261  mServerInfo->serverUrl = server.serverUrl;
262 
266 
267  if (chatLogger != nullptr)
269 
271  -1);
272 
274  {
276  {
278  if (desktop != nullptr)
280  }
281  }
282 
283  config.setValue("usePersistentIP",
286 }
std::string serverUrl
Definition: serverinfo.h:50
std::string defaultHostName
Definition: serverinfo.h:51
ServerTypeT type
Definition: serverinfo.h:41
void setState(const StateT state)
Definition: client.h:65
std::string hostname
Definition: serverinfo.h:44
std::vector< ServerUrlInfo > nonFreeSources
Definition: serverinfo.h:55
unsigned cancel
Definition: download.h:126
bool persistentIp
Definition: settings.h:150
ServerInfos mServers
Definition: serverdialog.h:129
Configuration config
Button * mLoadButton
Definition: serverdialog.h:137
Button * mConnectButton
Definition: serverdialog.h:133
std::string supportUrl
Definition: settings.h:119
Client * client
Definition: client.cpp:117
ServerInfo * mServerInfo
Definition: serverdialog.h:144
std::string registerUrl
Definition: serverinfo.h:47
std::vector< std::string > updateMirrors
Definition: settings.h:127
bool persistentIp
Definition: serverinfo.h:61
Settings settings
Definition: settings.cpp:31
CheckBox * mPersistentIPCheckBox
Definition: serverdialog.h:145
std::string onlineListUrl
Definition: serverinfo.h:48
std::vector< ServerUrlInfo > freeSources
Definition: serverinfo.h:54
std::vector< ServerUrlInfo > docs
Definition: serverinfo.h:56
Button * mQuitButton
Definition: serverdialog.h:132
uint16_t port
Definition: serverinfo.h:57
int getSelected() const
Definition: listbox.h:167
std::vector< HostsGroup > updateHosts
Definition: serverinfo.h:53
std::string description
Definition: serverinfo.h:46
std::vector< std::string > updateMirrors
Definition: serverinfo.h:52
static std::string savedPassword
Definition: logindialog.h:79
void setEnabled(const bool enabled)
Definition: widget.h:351
std::string empty
Definition: podict.cpp:25
std::string supportUrl
Definition: serverinfo.h:49
int packetVersion
Definition: serverinfo.h:59
void saveCustomServers(const ServerInfo &currentServer, const int index)
Net::Download * mDownload
Definition: serverdialog.h:143
std::string althostname
Definition: serverinfo.h:45
std::string name
Definition: serverinfo.h:43
bool save
Definition: serverinfo.h:60
StateT getState() const
Definition: client.h:68
void reloadWallpaper()
Definition: desktop.cpp:121
ListBox * mServersList
Definition: serverdialog.h:140
ServerFreeTypeT freeType
Definition: serverinfo.h:42
void setServerName(const std::string &serverName)
Definition: chatlogger.cpp:176
Desktop * desktop
Definition: desktop.cpp:48
ChatLogger * chatLogger
Definition: chatlogger.cpp:43
bool isSelected() const
Definition: checkbox.h:146
void setValue(const std::string &key, const std::string &value)
static std::string savedPasswordKey
Definition: logindialog.h:78

◆ downloadServerList()

void ServerDialog::downloadServerList ( )
private

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

Definition at line 461 of file serverdialog.cpp.

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().

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

◆ downloadUpdate()

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

Definition at line 844 of file serverdialog.cpp.

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

Referenced by downloadServerList().

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

◆ 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 342 of file serverdialog.cpp.

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().

343 {
344  PRAGMA45(GCC diagnostic push)
345  PRAGMA45(GCC diagnostic ignored "-Wswitch-enum")
346  switch (event.getActionId())
347  {
349  event.consume();
351  return;
352 
355  event.consume();
356  action(ActionEvent(nullptr,
358  return;
359 
362  return;
363 
365  {
366  const int index = mServersList->getSelected();
367  if (index >= 0)
368  {
370  mServers.erase(mServers.begin() + index);
372  -1);
373  }
374  return;
375  }
376 
378  {
379  const int index = mServersList->getSelected();
380  if (index >= 0)
381  {
382  CREATEWIDGET(EditServerDialog, this, mServers.at(index),
383  index);
384  }
385  return;
386  }
387 
388  default:
389  break;
390  }
391  PRAGMA45(GCC diagnostic pop)
392  if (!event.isConsumed())
393  mServersList->keyPressed(event);
394 }
void setSelected(const int selected)
Definition: listbox.cpp:398
void setState(const StateT state)
Definition: client.h:65
PRAGMA45(GCC diagnostic push) PRAGMA45(GCC diagnostic ignored "-Wunused-result") int TestLauncher
ServerInfos mServers
Definition: serverdialog.h:129
InputActionT getActionId() const
Definition: keyevent.h:126
Button * mConnectButton
Definition: serverdialog.h:133
const std::string & getActionEventId() const
Definition: widget.h:604
Client * client
Definition: client.cpp:117
void action(const ActionEvent &event)
int getSelected() const
Definition: listbox.h:167
bool isConsumed() const
void saveCustomServers(const ServerInfo &currentServer, const int index)
#define CREATEWIDGET(type,...)
Definition: createwidget.h:28
ListBox * mServersList
Definition: serverdialog.h:140
void keyPressed(KeyEvent &event)
Definition: listbox.cpp:245

◆ loadCustomServers()

void ServerDialog::loadCustomServers ( )
private

Definition at line 742 of file serverdialog.cpp.

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().

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

◆ loadServers()

void ServerDialog::loadServers ( const bool  addNew)
private

Definition at line 558 of file serverdialog.cpp.

References _, ServerInfo::althostname, branding, CAST_U16, CAST_U32, compareStrI(), ServerInfo::defaultHostName, defaultPortForServerType(), ServerInfo::description, ServerInfo::docs, ServerCommandType::font, for_each_xml_child_node, ServerInfo::freeSources, ServerInfo::freeType, Gui::getFont(), getLangShort(), XML::getProperty(), ListBox::getSelected(), Configuration::getStringValue(), gui, ServerInfo::hostname, ServerCommandType::lang, 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, ServerInfo::version, and ServerCommandType::version.

Referenced by logic(), and postInit().

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

◆ lock()

MutexLocker ServerDialog::lock ( )
inlineprotected

Definition at line 103 of file serverdialog.h.

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

104  { return MutexLocker(&mMutex); }

◆ 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 421 of file serverdialog.cpp.

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().

422 {
423  BLOCK_START("ServerDialog::logic")
424  {
425  MutexLocker tempLock(&mMutex);
427  {
428  loadServers(true);
430  mDescription->setCaption(std::string());
431  logger->log("Servers list updated");
432  }
434  {
435  // TRANSLATORS: servers dialog label
436  mDescription->setCaption(strprintf(_("Downloading server list..."
437  "%2.2f%%"), static_cast<double>(mDownloadProgress * 100)));
438  }
440  {
441  // TRANSLATORS: servers dialog label
442  mDescription->setCaption(_("Waiting for server..."));
443  }
445  {
446  // TRANSLATORS: servers dialog label
447  mDescription->setCaption(_("Preparing download"));
448  }
450  {
451  // TRANSLATORS: servers dialog label
452  mDescription->setCaption(_("Error retreiving server list!"));
453  logger->log("Error: servers list updating error");
454  }
455  }
456 
457  Window::logic();
458  BLOCK_END("ServerDialog::logic")
459 }
#define _(s)
Definition: gettext.h:34
ServerDialogDownloadStatusT mDownloadStatus
Definition: serverdialog.h:147
#define BLOCK_START(name)
Definition: perfomance.h:78
#define BLOCK_END(name)
Definition: perfomance.h:79
Logger * logger
Definition: logger.cpp:88
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
void setCaption(const std::string &caption)
Definition: label.cpp:261
Label * mDescription
Definition: serverdialog.h:131
void loadServers(const bool addNew)
void log(const char *const log_text,...)
Definition: logger.cpp:264
float mDownloadProgress
Definition: serverdialog.h:146

◆ 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 407 of file serverdialog.cpp.

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

408 {
409  if (event.getButton() == MouseButton::LEFT)
410  {
411  event.consume();
412  if (event.getClickCount() == 2 &&
413  event.getSource() == mServersList)
414  {
417  }
418  }
419 }
MouseButtonT getButton() const
Definition: mouseevent.h:115
Button * mConnectButton
Definition: serverdialog.h:133
const std::string & getActionEventId() const
Definition: widget.h:604
void action(const ActionEvent &event)
ListBox * mServersList
Definition: serverdialog.h:140
int getClickCount() const
Definition: mouseevent.h:146

◆ needUpdateServers()

bool ServerDialog::needUpdateServers ( ) const
private

Definition at line 898 of file serverdialog.cpp.

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

Referenced by postInit().

899 {
900  if (mServers.empty() || config.getStringValue("serverslistupdate")
901  != getDateString())
902  {
903  return true;
904  }
905 
906  return false;
907 }
std::string getStringValue(const std::string &key) const
ServerInfos mServers
Definition: serverdialog.h:129
Configuration config
std::string getDateString()

◆ postInit()

void ServerDialog::postInit ( )
virtual

Reimplemented from Window.

Definition at line 198 of file serverdialog.cpp.

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

199 {
202 
204 
205  loadServers(true);
206 
207  mServersList->setSelected(0); // Do this after for the Delete button
208 
209  if (needUpdateServers())
211  else
212  logger->log("Skipping servers list update");
213 }
void setSelected(const int selected)
Definition: listbox.cpp:398
const bool Visible_true
Definition: visible.h:29
Button * mConnectButton
Definition: serverdialog.h:133
Logger * logger
Definition: logger.cpp:88
void downloadServerList()
virtual void requestFocus()
Definition: widget.cpp:203
virtual void setVisible(Visible visible)
Definition: window.cpp:773
void loadServers(const bool addNew)
ListBox * mServersList
Definition: serverdialog.h:140
bool needUpdateServers() const
void log(const char *const log_text,...)
Definition: logger.cpp:264
void postInit()
Definition: window.cpp:248

◆ saveCustomServers()

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

Definition at line 781 of file serverdialog.cpp.

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().

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

◆ updateServer()

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

Definition at line 893 of file serverdialog.cpp.

References saveCustomServers().

Referenced by EditServerDialog::action().

894 {
895  saveCustomServers(server, index);
896 }
void saveCustomServers(const ServerInfo &currentServer, const int index)

◆ 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 396 of file serverdialog.cpp.

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

397 {
398  const int index = mServersList->getSelected();
399  if (index == -1)
400  {
401  mDeleteButton->setEnabled(false);
402  return;
403  }
404  mDeleteButton->setEnabled(true);
405 }
int getSelected() const
Definition: listbox.h:167
void setEnabled(const bool enabled)
Definition: widget.h:351
ListBox * mServersList
Definition: serverdialog.h:140
Button * mDeleteButton
Definition: serverdialog.h:136

Friends And Related Function Documentation

◆ EditServerDialog

friend class EditServerDialog
friend

Definition at line 107 of file serverdialog.h.

◆ ServersListModel

friend class ServersListModel
friend

Definition at line 101 of file serverdialog.h.

Field Documentation

◆ mAddEntryButton

Button* ServerDialog::mAddEntryButton
private

Definition at line 134 of file serverdialog.h.

Referenced by ServerDialog().

◆ mConnectButton

Button* ServerDialog::mConnectButton
private

◆ mDeleteButton

Button* ServerDialog::mDeleteButton
private

Definition at line 136 of file serverdialog.h.

Referenced by ServerDialog(), and valueChanged().

◆ mDescription

Label* ServerDialog::mDescription
private

Definition at line 131 of file serverdialog.h.

Referenced by logic(), and ServerDialog().

◆ mDir

const std::string& ServerDialog::mDir
private

Definition at line 130 of file serverdialog.h.

Referenced by downloadServerList(), and loadServers().

◆ mDownload

Net::Download* ServerDialog::mDownload
private

Status of the current download.

Definition at line 143 of file serverdialog.h.

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

◆ mDownloadProgress

float ServerDialog::mDownloadProgress
private

Definition at line 146 of file serverdialog.h.

Referenced by downloadUpdate(), and logic().

◆ mDownloadStatus

ServerDialogDownloadStatusT ServerDialog::mDownloadStatus
private

Definition at line 147 of file serverdialog.h.

Referenced by downloadUpdate(), and logic().

◆ mEditEntryButton

Button* ServerDialog::mEditEntryButton
private

Definition at line 135 of file serverdialog.h.

Referenced by ServerDialog().

◆ mInfoButton

Button* ServerDialog::mInfoButton
private

Definition at line 138 of file serverdialog.h.

Referenced by ServerDialog().

◆ mLoadButton

Button* ServerDialog::mLoadButton
private

Definition at line 137 of file serverdialog.h.

Referenced by connectToSelectedServer(), and ServerDialog().

◆ mMutex

Mutex ServerDialog::mMutex
private

Definition at line 128 of file serverdialog.h.

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

◆ mPersistentIPCheckBox

CheckBox* ServerDialog::mPersistentIPCheckBox
private

Definition at line 145 of file serverdialog.h.

Referenced by connectToSelectedServer(), and ServerDialog().

◆ mQuitButton

Button* ServerDialog::mQuitButton
private

Definition at line 132 of file serverdialog.h.

Referenced by connectToSelectedServer(), and ServerDialog().

◆ mServerInfo

ServerInfo* ServerDialog::mServerInfo
private

Definition at line 144 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 139 of file serverdialog.h.

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


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