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="Window", const Modal modal=Modal_false, Window *const parent=0, std::string skin="")
 
virtual ~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=0, int offsetY=0)
 
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=0, const int offsetY=0)
 
virtual void resetToDefaultSize ()
 
void adjustPositionAfterResize (const int oldScreenWidth, const int oldScreenHeight)
 
LayoutgetLayout ()
 
void clearLayout ()
 
void reflowLayout (int w=0, int h=0)
 
LayoutCellplace (const int x, const int y, Widget *const wg, const int w=1, const int h=1)
 
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)
 
virtual ~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)
 
virtual ~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)
 
virtual ~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=255U) 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=0) const
 
bool getOptionBool (const std::string &name, const bool def=false) 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=true)
 
void loadCustomServers ()
 
void saveCustomServers (const ServerInfo &currentServer=ServerInfo(), const int index=-1)
 
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(), Window::getLayout(), Window::getOptionBool(), Widget::getWidth(), isSafeMode, loadCustomServers(), Window::loadWindowState(), mAddEntryButton, mConnectButton, mDeleteButton, mDescription, mEditEntryButton, mInfoButton, mLoadButton, mPersistentIPCheckBox, mQuitButton, mServersList, Window::place(), Layout::reflow(), 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", this)),
109  // TRANSLATORS: servers dialog button
110  mConnectButton(new Button(this, _("Connect"), "connect", this)),
111  // TRANSLATORS: servers dialog button
112  mAddEntryButton(new Button(this, _("Add"), "addEntry", this)),
113  // TRANSLATORS: servers dialog button
114  mEditEntryButton(new Button(this, _("Edit"), "editEntry", this)),
115  // TRANSLATORS: servers dialog button
116  mDeleteButton(new Button(this, _("Delete"), "remove", this)),
117  // TRANSLATORS: servers dialog button
118  mLoadButton(new Button(this, _("Load"), "load", this)),
119  // TRANSLATORS: servers dialog button
120  mInfoButton(new Button(this, _("Info"), "info", this)),
123  mDownload(nullptr),
124  mServerInfo(serverInfo),
125  mPersistentIPCheckBox(nullptr),
126  mDownloadProgress(-1.0F),
128 {
129  if (isSafeMode)
130  {
131  // TRANSLATORS: servers dialog name
132  setCaption(_("Choose Your Server *** SAFE MODE ***"));
133  }
134 
135  setWindowName("ServerDialog");
136 
137  setCloseButton(true);
138 
139  mPersistentIPCheckBox = new CheckBox(this,
140  // TRANSLATORS: servers dialog checkbox
141  _("Use same ip for game sub servers"),
142  config.getBoolValue("usePersistentIP"),
143  this, "persitent ip");
144 
146 
148 
149  ScrollArea *const usedScroll = new ScrollArea(this, mServersList,
150  fromBool(getOptionBool("showbackground"), Opaque),
151  "server_background.xml");
153 
155  usedScroll->setVerticalScrollAmount(0);
156 
157  place(0, 0, usedScroll, 8, 5).setPadding(3);
158  place(0, 5, mDescription, 8);
159  place(0, 6, mPersistentIPCheckBox, 8);
160  place(0, 7, mInfoButton);
161  place(1, 7, mAddEntryButton);
162  place(2, 7, mEditEntryButton);
163  place(3, 7, mLoadButton);
164  place(4, 7, mDeleteButton);
165  place(6, 7, mQuitButton);
166  place(7, 7, mConnectButton);
167 
168  // Make sure the list has enough height
169  getLayout().setRowHeight(0, 80);
170 
171  // Do this manually instead of calling reflowLayout so we can enforce a
172  // minimum width.
173  int width = 500;
174  int height = 350;
175 
176  getLayout().reflow(width, height);
177  setContentSize(width, height);
178 
179  setMinWidth(310);
180  setMinHeight(220);
182 
183  setResizable(true);
184  addKeyListener(this);
185 
186  loadWindowState();
187 }
void setDefaultSize()
Definition: window.cpp:1186
void loadCustomServers()
#define _(s)
Definition: gettext.h:34
ServerDialogDownloadStatusT mDownloadStatus
Definition: serverdialog.h:147
int getWidth() const
Definition: widget.h:220
void loadWindowState()
Definition: window.cpp:1075
void reflow(int &nW, int &nH)
Definition: layout.cpp:35
void setMinWidth(const int width)
Definition: window.cpp:579
void addSelectionListener(SelectionListener *const selectionListener)
Definition: listbox.cpp:428
ServerInfos mServers
Definition: serverdialog.h:129
Definition: button.h:94
Configuration config
bool getOptionBool(const std::string &name, const bool def=false) const
Definition: window.cpp:1454
Button * mLoadButton
Definition: serverdialog.h:137
Button * mConnectButton
Definition: serverdialog.h:133
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:484
bool getBoolValue(const std::string &key) const
std::vector< ServerInfo > ServerInfos
Definition: serverinfo.h:226
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
LayoutCell & place(const int x, const int y, Widget *const wg, const int w=1, const int h=1)
Definition: window.cpp:1372
Button * mQuitButton
Definition: serverdialog.h:132
void addMouseListener(MouseListener *const mouseListener)
Definition: widget.cpp:291
void setCloseButton(const bool flag)
Definition: window.cpp:737
void addKeyListener(KeyListener *const keyListener)
Definition: widget.cpp:271
ServersListModel * mServersListModel
Definition: serverdialog.h:139
void setMinHeight(const int height)
Definition: window.cpp:592
LayoutCell & setPadding(int p)
Definition: layoutcell.h:59
Layout & getLayout()
Definition: window.cpp:1353
Label * mDescription
Definition: serverdialog.h:131
bool isSafeMode
Definition: client.cpp:118
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:615
Button * mDeleteButton
Definition: serverdialog.h:136
#define CREATEWIDGETR(type,...)
Definition: createwidget.h:35
Window(const std::string &caption="Window", const Modal modal=Modal_false, Window *const parent=0, std::string skin="")
Definition: window.cpp:108
float mDownloadProgress
Definition: serverdialog.h:146
void setCaption(const std::string &caption)
Definition: window.h:523
void setRowHeight(const int n, const int h)
Definition: layoutcell.cpp:127
Button * mAddEntryButton
Definition: serverdialog.h:134
void setWindowName(const std::string &name)
Definition: window.h:353
void setHorizontalScrollPolicy(const ScrollPolicy hPolicy)

◆ ~ServerDialog()

ServerDialog::~ServerDialog ( )

Destructor

Definition at line 206 of file serverdialog.cpp.

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

207 {
208  if (mDownload != nullptr)
209  {
210  mDownload->cancel();
212  }
214 }
unsigned cancel
Definition: download.h:123
#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 278 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().

279 {
280  const std::string &eventId = event.getId();
281  if (eventId == "connect")
282  {
284  }
285  else if (eventId == "quit")
286  {
287  close();
288  }
289  else if (eventId == "load")
290  {
292  }
293  else if (eventId == "addEntry")
294  {
296  }
297  else if (eventId == "editEntry")
298  {
299  const int index = mServersList->getSelected();
300  if (index >= 0)
301  {
303  this,
304  mServers.at(index),
305  index);
306  }
307  }
308  else if (eventId == "remove")
309  {
310  const int index = mServersList->getSelected();
311  if (index >= 0)
312  {
314  mServers.erase(mServers.begin() + index);
316  }
317  }
318  else if (eventId == "info")
319  {
320  const int index = mServersList->getSelected();
321  if (index >= 0)
322  {
323  if (serverInfoWindow != nullptr)
326  mServers.at(index));
327  }
328  }
329 }
void setSelected(const int selected)
Definition: listbox.cpp:392
ServerInfos mServers
Definition: serverdialog.h:129
void downloadServerList()
ServerInfoWindow * serverInfoWindow
int getSelected() const
Definition: listbox.h:167
virtual void scheduleDelete()
Definition: window.cpp:819
void saveCustomServers(const ServerInfo &currentServer=ServerInfo(), const int index=-1)
#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 896 of file serverdialog.cpp.

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

Referenced by action().

897 {
898  if (mDownload != nullptr)
899  mDownload->cancel();
901  Window::close();
902 }
void setState(const StateT state)
Definition: client.h:65
unsigned cancel
Definition: download.h:123
Client * client
Definition: client.cpp:113
virtual void close()
Definition: window.cpp:890
Net::Download * mDownload
Definition: serverdialog.h:143

◆ connectToSelectedServer()

void ServerDialog::connectToSelectedServer ( )

Definition at line 216 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().

217 {
219  return;
220 
221  const int index = mServersList->getSelected();
222  if (index < 0)
223  return;
224 
225  if (mDownload != nullptr)
226  mDownload->cancel();
227 
228  mQuitButton->setEnabled(false);
229  mConnectButton->setEnabled(false);
230  mLoadButton->setEnabled(false);
231 
232  ServerInfo server = mServers.at(index);
233  mServerInfo->hostname = server.hostname;
235  mServerInfo->port = server.port;
236  mServerInfo->type = server.type;
237  mServerInfo->name = server.name;
243  mServerInfo->save = true;
245  mServerInfo->freeType = server.freeType;
251  mServerInfo->docs = server.docs;
252  mServerInfo->serverUrl = server.serverUrl;
253 
257 
258  if (chatLogger != nullptr)
260 
262 
264  {
266  {
268  if (desktop != nullptr)
270  }
271  }
272 
273  config.setValue("usePersistentIP",
276 }
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:123
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:113
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=ServerInfo(), const int index=-1)
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:114
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 449 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().

450 {
451  // Try to load the configuration value for the onlineServerList
452  std::string listFile = branding.getStringValue("onlineServerList");
453  std::string listFile2 = branding.getStringValue("onlineServerList2");
454 
455  // Fall back to manaplus.org when neither branding
456  // nor config set it
457  if (listFile.empty())
458  listFile = "http://manaplus.org/serverlist.xml";
459 
460  if (mDownload != nullptr)
461  {
462  mDownload->cancel();
464  }
465 
466  mDownload = new Net::Download(this, listFile,
467  &downloadUpdate, false, false, true);
469  branding.getStringValue("onlineServerFile")));
470  if (!listFile2.empty())
471  mDownload->addMirror(listFile2);
472  mDownload->start();
473 
474  config.setValue("serverslistupdate", getDateString());
475 }
Configuration branding
std::string getStringValue(const std::string &key) const
void addMirror(const std::string &str)
Definition: download.h:86
unsigned cancel
Definition: download.h:123
std::string pathJoin(std::string str1, const std::string &str2)
Configuration config
#define delete2(var)
Definition: delete2.h:24
const std::string & mDir
Definition: serverdialog.h:130
void setFile(const std::string &filename, const int64_t adler32=-1)
Definition: download.cpp:164
std::string getDateString()
bool start()
Definition: download.cpp:186
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 831 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().

835 {
836  if ((ptr == nullptr) || status == DownloadStatus::Cancelled)
837  return -1;
838 
839  ServerDialog *const sd = reinterpret_cast<ServerDialog*>(ptr);
840  bool finished = false;
841 
842  if (sd->mDownload == nullptr)
843  return -1;
844 
845  if (status == DownloadStatus::Complete)
846  {
847  finished = true;
848  }
849  else if (CAST_S32(status) < 0)
850  {
851  logger->log("Error retreiving server list: %s\n",
852  sd->mDownload->getError());
854  }
855  else
856  {
857  float progress = static_cast<float>(remaining);
858  if (total != 0u)
859  progress /= static_cast<float>(total);
860 
861  if (progress != progress || progress < 0.0F)
862  progress = 0.0f;
863  else if (progress > 1.0F)
864  progress = 1.0F;
865 
866  MutexLocker lock1(&sd->mMutex);
868  sd->mDownloadProgress = progress;
869  }
870 
871  if (finished)
872  {
873  MutexLocker lock1(&sd->mMutex);
875  }
876 
877  return 0;
878 }
ServerDialogDownloadStatusT mDownloadStatus
Definition: serverdialog.h:147
Logger * logger
Definition: logger.cpp:95
#define CAST_S32
Definition: cast.h:29
const char * getError() const
Definition: download.cpp:213
Net::Download * mDownload
Definition: serverdialog.h:143
void log(const char *const log_text,...)
Definition: logger.cpp:243
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 331 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().

332 {
333  PRAGMA45(GCC diagnostic push)
334  PRAGMA45(GCC diagnostic ignored "-Wswitch-enum")
335  switch (event.getActionId())
336  {
338  event.consume();
340  return;
341 
344  event.consume();
345  action(ActionEvent(nullptr,
347  return;
348 
351  return;
352 
354  {
355  const int index = mServersList->getSelected();
356  if (index >= 0)
357  {
359  mServers.erase(mServers.begin() + index);
361  }
362  return;
363  }
364 
366  {
367  const int index = mServersList->getSelected();
368  if (index >= 0)
369  {
370  CREATEWIDGET(EditServerDialog, this, mServers.at(index),
371  index);
372  }
373  return;
374  }
375 
376  default:
377  break;
378  }
379  PRAGMA45(GCC diagnostic pop)
380  if (!event.isConsumed())
381  mServersList->keyPressed(event);
382 }
void setSelected(const int selected)
Definition: listbox.cpp:392
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:130
Button * mConnectButton
Definition: serverdialog.h:133
const std::string & getActionEventId() const
Definition: widget.h:604
Client * client
Definition: client.cpp:113
void action(const ActionEvent &event)
int getSelected() const
Definition: listbox.h:167
bool isConsumed() const
void saveCustomServers(const ServerInfo &currentServer=ServerInfo(), const int index=-1)
#define CREATEWIDGET(type,...)
Definition: createwidget.h:28
ListBox * mServersList
Definition: serverdialog.h:140
void keyPressed(KeyEvent &event)
Definition: listbox.cpp:239

◆ loadCustomServers()

void ServerDialog::loadCustomServers ( )
private

Definition at line 729 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().

730 {
731  for (int i = 0; i < MAX_SERVERLIST; ++i)
732  {
733  const std::string index = toString(i);
734  const std::string nameKey("MostUsedServerDescName" + index);
735  const std::string descKey("MostUsedServerDescription" + index);
736  const std::string hostKey("MostUsedServerName" + index);
737  const std::string typeKey("MostUsedServerType" + index);
738  const std::string portKey("MostUsedServerPort" + index);
739  const std::string onlineListUrlKey
740  ("MostUsedServerOnlineList" + index);
741  const std::string persistentIpKey("persistentIp" + index);
742  const std::string packetVersionKey
743  ("MostUsedServerPacketVersion" + index);
744 
745  ServerInfo server;
746  server.name = config.getValue(nameKey, "");
747  server.description = config.getValue(descKey, "");
748  server.onlineListUrl = config.getValue(onlineListUrlKey, "");
749  server.hostname = config.getValue(hostKey, "");
750  server.type = ServerInfo::parseType(config.getValue(typeKey, ""));
751  server.persistentIp = config.getValue(
752  persistentIpKey, 0) != 0 ? true : false;
753  server.packetVersion = config.getValue(packetVersionKey, 0);
754 
755  const int defaultPort = defaultPortForServerType(server.type);
756  server.port = CAST_U16(
757  config.getValue(portKey, defaultPort));
758 
759  // skip invalid server
760  if (!server.isValid())
761  continue;
762 
763  server.save = true;
764  mServers.push_back(server);
765  }
766 }
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 = true)
private

Definition at line 545 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().

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

410 {
411  BLOCK_START("ServerDialog::logic")
412  {
413  MutexLocker tempLock(&mMutex);
415  {
416  loadServers();
418  mDescription->setCaption(std::string());
419  logger->log("Servers list updated");
420  }
422  {
423  // TRANSLATORS: servers dialog label
424  mDescription->setCaption(strprintf(_("Downloading server list..."
425  "%2.2f%%"), static_cast<double>(mDownloadProgress * 100)));
426  }
428  {
429  // TRANSLATORS: servers dialog label
430  mDescription->setCaption(_("Waiting for server..."));
431  }
433  {
434  // TRANSLATORS: servers dialog label
435  mDescription->setCaption(_("Preparing download"));
436  }
438  {
439  // TRANSLATORS: servers dialog label
440  mDescription->setCaption(_("Error retreiving server list!"));
441  logger->log("Error: servers list updating error");
442  }
443  }
444 
445  Window::logic();
446  BLOCK_END("ServerDialog::logic")
447 }
#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:95
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
void setCaption(const std::string &caption)
Definition: label.cpp:256
void loadServers(const bool addNew=true)
Label * mDescription
Definition: serverdialog.h:131
void log(const char *const log_text,...)
Definition: logger.cpp:243
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 395 of file serverdialog.cpp.

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

396 {
397  if (event.getButton() == MouseButton::LEFT)
398  {
399  event.consume();
400  if (event.getClickCount() == 2 &&
401  event.getSource() == mServersList)
402  {
405  }
406  }
407 }
MouseButtonT getButton() const
Definition: mouseevent.h:113
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:144

◆ needUpdateServers()

bool ServerDialog::needUpdateServers ( ) const
private

Definition at line 885 of file serverdialog.cpp.

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

Referenced by postInit().

886 {
887  if (mServers.empty() || config.getStringValue("serverslistupdate")
888  != getDateString())
889  {
890  return true;
891  }
892 
893  return false;
894 }
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 189 of file serverdialog.cpp.

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

190 {
193 
195 
196  loadServers(true);
197 
198  mServersList->setSelected(0); // Do this after for the Delete button
199 
200  if (needUpdateServers())
202  else
203  logger->log("Skipping servers list update");
204 }
void setSelected(const int selected)
Definition: listbox.cpp:392
const bool Visible_true
Definition: visible.h:29
Button * mConnectButton
Definition: serverdialog.h:133
Logger * logger
Definition: logger.cpp:95
void downloadServerList()
virtual void requestFocus()
Definition: widget.cpp:203
void loadServers(const bool addNew=true)
virtual void setVisible(Visible visible)
Definition: window.cpp:766
ListBox * mServersList
Definition: serverdialog.h:140
bool needUpdateServers() const
void log(const char *const log_text,...)
Definition: logger.cpp:243
void postInit()
Definition: window.cpp:241

◆ saveCustomServers()

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

Definition at line 768 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().

770 {
771  // Make sure the current server is mentioned first
772  if (currentServer.isValid())
773  {
774  if (index >= 0 && CAST_SIZE(index) < mServers.size())
775  {
776  mServers[index] = currentServer;
777  }
778  else
779  {
780  FOR_EACH (ServerInfos::iterator, i, mServers)
781  {
782  if (*i == currentServer)
783  {
784  mServers.erase(i);
785  break;
786  }
787  }
788  mServers.insert(mServers.begin(), currentServer);
789  }
790  }
791 
792  int savedServerCount = 0;
793 
794  for (unsigned i = 0, fsz = CAST_U32(mServers.size());
795  i < fsz && savedServerCount < MAX_SERVERLIST; ++ i)
796  {
797  const ServerInfo &server = mServers.at(i);
798 
799  // Only save servers that were loaded from settings
800  if (!(server.save && server.isValid()))
801  continue;
802 
803  const std::string num = toString(savedServerCount);
804  const std::string nameKey("MostUsedServerDescName" + num);
805  const std::string descKey("MostUsedServerDescription" + num);
806  const std::string hostKey("MostUsedServerName" + num);
807  const std::string typeKey("MostUsedServerType" + num);
808  const std::string portKey("MostUsedServerPort" + num);
809  const std::string onlineListUrlKey
810  ("MostUsedServerOnlineList" + num);
811  const std::string persistentIpKey("persistentIp" + num);
812  const std::string packetVersionKey
813  ("MostUsedServerPacketVersion" + num);
814 
815  config.setValue(nameKey, server.name);
816  config.setValue(descKey, server.description);
817  config.setValue(onlineListUrlKey, server.onlineListUrl);
818  config.setValue(hostKey, server.hostname);
819  config.setValue(typeKey, serverTypeToString(server.type));
820  config.setValue(portKey, toString(server.port));
821  config.setValue(persistentIpKey, server.persistentIp);
822  config.setValue(packetVersionKey, server.packetVersion);
823  ++ savedServerCount;
824  }
825 
826  // Insert an invalid entry at the end to make the loading stop there
827  if (savedServerCount < MAX_SERVERLIST)
828  config.setValue("MostUsedServerName" + toString(savedServerCount), "");
829 }
#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 880 of file serverdialog.cpp.

References saveCustomServers().

Referenced by EditServerDialog::action().

881 {
882  saveCustomServers(server, index);
883 }
void saveCustomServers(const ServerInfo &currentServer=ServerInfo(), const int index=-1)

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

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

385 {
386  const int index = mServersList->getSelected();
387  if (index == -1)
388  {
389  mDeleteButton->setEnabled(false);
390  return;
391  }
392  mDeleteButton->setEnabled(true);
393 }
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: