ManaPlus
Public Types | Public Member Functions | Private Types | Private Attributes
ServersListModel Class Reference

#include <serverslistmodel.h>

Inheritance diagram for ServersListModel:
ListModel

Public Types

typedef std::pair< int, std::string > VersionString
 

Public Member Functions

 ServersListModel (ServerInfos *const servers, ServerDialog *const parent)
 
int getNumberOfElements ()
 
std::string getElementAt (int elementIndex)
 
const ServerInfogetServer (const int elementIndex) const
 
void setVersionString (const int index, const std::string &version)
 
- Public Member Functions inherited from ListModel
 ListModel ()
 
virtual ~ListModel ()
 

Private Types

typedef std::vector< VersionStringVersionStrings
 

Private Attributes

ServerInfosmServers
 
VersionStrings mVersionStrings
 
ServerDialogmParent
 

Detailed Description

Server and Port List Model

Definition at line 40 of file serverslistmodel.h.

Member Typedef Documentation

◆ VersionString

typedef std::pair<int, std::string> ServersListModel::VersionString

Definition at line 43 of file serverslistmodel.h.

◆ VersionStrings

typedef std::vector<VersionString> ServersListModel::VersionStrings
private

Definition at line 113 of file serverslistmodel.h.

Constructor & Destructor Documentation

◆ ServersListModel()

ServersListModel::ServersListModel ( ServerInfos *const  servers,
ServerDialog *const  parent 
)
inline

Definition at line 45 of file serverslistmodel.h.

46  :
47  mServers(servers),
48  mVersionStrings(servers != nullptr ? servers->size() : 0,
49  VersionString(0, "")),
50  mParent(parent)
51  {
52  }
VersionStrings mVersionStrings
ServerInfos * mServers
ServerDialog * mParent
std::pair< int, std::string > VersionString

Member Function Documentation

◆ getElementAt()

std::string ServersListModel::getElementAt ( int  elementIndex)
inlinevirtual

Used to get an element from the list

Implements ListModel.

Definition at line 68 of file serverslistmodel.h.

70  {
71  MutexLocker lock = mParent->lock();
72  const ServerInfo &server = mServers->at(elementIndex);
73  std::string myServer;
74  if (server.freeType == ServerFreeType::NonFree)
75  {
76  // TRANSLATORS: server license comment
77  myServer.append(_("(NON FREE)"));
78  myServer.append(" ");
79  }
80  else if (server.freeType == ServerFreeType::Unknown)
81  {
82  // TRANSLATORS: server license comment
83  myServer.append(_("(UNKNOWN)"));
84  myServer.append(" ");
85  }
86  myServer.append(server.hostname);
87  return myServer;
88  }
MutexLocker lock()
Definition: serverdialog.h:104
std::string hostname
Definition: serverinfo.h:45
ServerFreeTypeT freeType
Definition: serverinfo.h:43
#define _(s)
Definition: gettext.h:35

References _, ServerInfo::freeType, ServerInfo::hostname, ServerDialog::lock(), mParent, mServers, ServerFreeType::NonFree, and ServerFreeType::Unknown.

Referenced by ServersListBox::draw().

◆ getNumberOfElements()

int ServersListModel::getNumberOfElements ( )
inlinevirtual

Used to get number of line in the list

Implements ListModel.

Definition at line 59 of file serverslistmodel.h.

60  {
61  MutexLocker lock = mParent->lock();
62  return CAST_S32(mServers->size());
63  }
#define CAST_S32
Definition: cast.h:30

References CAST_S32, ServerDialog::lock(), mParent, and mServers.

Referenced by ServersListBox::draw().

◆ getServer()

const ServerInfo& ServersListModel::getServer ( const int  elementIndex) const
inline

Used to get the corresponding Server struct

Definition at line 93 of file serverslistmodel.h.

94  { return mServers->at(elementIndex); }

References mServers.

Referenced by ServersListBox::draw().

◆ setVersionString()

void ServersListModel::setVersionString ( const int  index,
const std::string &  version 
)
inline

Definition at line 96 of file serverslistmodel.h.

97  {
98  if (index < 0 || index >= CAST_S32(mVersionStrings.size()))
99  return;
100 
101  if (version.empty() || (gui == nullptr))
102  {
103  mVersionStrings[index] = VersionString(0, "");
104  }
105  else
106  {
108  gui->getFont()->getWidth(version), version);
109  }
110  }
int getWidth(const std::string &text) const
Definition: font.cpp:334
Font * getFont() const
Definition: gui.h:160
Gui * gui
Definition: gui.cpp:111

References CAST_S32, Gui::getFont(), Font::getWidth(), gui, and mVersionStrings.

Referenced by ServerDialog::loadServers().

Field Documentation

◆ mParent

ServerDialog* ServersListModel::mParent
private

Definition at line 117 of file serverslistmodel.h.

Referenced by getElementAt(), and getNumberOfElements().

◆ mServers

ServerInfos* ServersListModel::mServers
private

Definition at line 115 of file serverslistmodel.h.

Referenced by getElementAt(), getNumberOfElements(), and getServer().

◆ mVersionStrings

VersionStrings ServersListModel::mVersionStrings
private

Definition at line 116 of file serverslistmodel.h.

Referenced by setVersionString().


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