ManaPlus
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes
ItemLinkHandler Class Reference

#include <itemlinkhandler.h>

Inheritance diagram for ItemLinkHandler:
LinkHandler

Public Member Functions

 ItemLinkHandler ()
 
 ~ItemLinkHandler ()
 
void handleLink (const std::string &link, MouseEvent *event)
 
void setAllowCommands (const bool b)
 
- Public Member Functions inherited from LinkHandler
 LinkHandler ()
 
virtual ~LinkHandler ()
 

Private Member Functions

void handleCommandLink (const std::string &link, const std::string &prefix)
 

Static Private Member Functions

static void handleHelpLink (const std::string &link)
 
static void handleHttpLink (const std::string &link, const MouseEvent *const event)
 
static void handleItemLink (const std::string &link)
 
static void handleSearchLink (const std::string &link)
 

Private Attributes

bool mAllowCommands
 

Detailed Description

Definition at line 31 of file itemlinkhandler.h.

Constructor & Destructor Documentation

◆ ItemLinkHandler()

ItemLinkHandler::ItemLinkHandler ( )

Definition at line 59 of file itemlinkhandler.cpp.

59  :
60  LinkHandler(),
61  mAllowCommands(true)
62 {
63 }

◆ ~ItemLinkHandler()

ItemLinkHandler::~ItemLinkHandler ( )

Definition at line 65 of file itemlinkhandler.cpp.

66 {
67 }

Member Function Documentation

◆ handleCommandLink()

void ItemLinkHandler::handleCommandLink ( const std::string &  link,
const std::string &  prefix 
)
private

Definition at line 69 of file itemlinkhandler.cpp.

71 {
72  std::string cmd;
73  std::string args;
74 
75  const std::string cmdStr = link.substr(prefix.size());
76  if (!parse2Str(cmdStr, cmd, args))
77  {
78  cmd = cmdStr;
79  args.clear();
80  }
81  if (mAllowCommands)
82  {
83  inputManager.executeRemoteChatCommand(cmd, args, nullptr);
84  }
85  else
86  {
89  // TRANSLATORS: dialog message
90  _("Run command"),
91  strprintf("/%s %s", cmd.c_str(), args.c_str()),
93  false,
94  Modal_true,
95  nullptr);
97  }
98 }
void setCommand(const std::string &command, const std::string &args)
bool executeRemoteChatCommand(const std::string &cmd, const std::string &args, ChatTab *const tab)
void addActionListener(ActionListener *const actionListener)
Definition: widget.cpp:252
#define CREATEWIDGETR(type,...)
Definition: createwidget.h:36
#define _(s)
Definition: gettext.h:35
InputActionRemoteListener inputActionRemoteListener
InputManager inputManager
const bool Modal_true
Definition: modal.h:30
ConfirmDialog * confirmDlg
Definition: traderecv.cpp:49
static const std::string SOUND_REQUEST
Definition: sound.h:29
std::string strprintf(const char *const format,...)
bool parse2Str(const std::string &args, std::string &str1, std::string &str2)

References _, Widget::addActionListener(), confirmDlg, CREATEWIDGETR, InputManager::executeRemoteChatCommand(), inputActionRemoteListener, inputManager, mAllowCommands, Modal_true, parse2Str(), InputActionRemoteListener::setCommand(), SOUND_REQUEST, and strprintf().

Referenced by handleLink().

◆ handleHelpLink()

void ItemLinkHandler::handleHelpLink ( const std::string &  link)
staticprivate

Definition at line 100 of file itemlinkhandler.cpp.

101 {
102  if (helpWindow != nullptr)
103  {
104  helpWindow->loadHelp(link.substr(7));
106  }
107 }
void loadHelp(const std::string &helpFile)
Definition: helpwindow.cpp:126
virtual void requestMoveToTop()
Definition: widget.cpp:213
HelpWindow * helpWindow
Definition: helpwindow.cpp:54

References helpWindow, HelpWindow::loadHelp(), and Widget::requestMoveToTop().

Referenced by handleLink().

◆ handleHttpLink()

void ItemLinkHandler::handleHttpLink ( const std::string &  link,
const MouseEvent *const  event 
)
staticprivate

Definition at line 109 of file itemlinkhandler.cpp.

111 {
112  if (event == nullptr)
113  return;
114  std::string url = link;
115  replaceAll(url, " ", "");
116  listener.url = url;
117  const MouseButtonT button = event->getButton();
118  if (button == MouseButton::LEFT)
119  {
121  // TRANSLATORS: dialog message
122  _("Open url"),
123  url,
125  false,
126  Modal_true,
127  nullptr);
129  }
130  else if (button == MouseButton::RIGHT)
131  {
132  if (popupMenu != nullptr)
134  }
135 }
void showLinkPopup(const std::string &link)
Definition: popupmenu.cpp:2194
MouseButton ::T MouseButtonT
Definition: mousebutton.h:78
bool url(InputEvent &event)
Definition: commands.cpp:64
PopupMenu * popupMenu
Definition: popupmenu.cpp:103
std::string & replaceAll(std::string &context, const std::string &from, const std::string &to)
std::string url

References _, Widget::addActionListener(), confirmDlg, CREATEWIDGETR, MouseButton::LEFT, anonymous_namespace{itemlinkhandler.cpp}::listener, Modal_true, popupMenu, replaceAll(), MouseButton::RIGHT, PopupMenu::showLinkPopup(), SOUND_REQUEST, OpenUrlListener::url, and Actions::url().

Referenced by handleLink().

◆ handleItemLink()

void ItemLinkHandler::handleItemLink ( const std::string &  link)
staticprivate

Definition at line 137 of file itemlinkhandler.cpp.

138 {
139  if ((itemPopup == nullptr) || link.empty())
140  return;
141 
142  const char ch = link[0];
143  if (ch < '0' || ch > '9')
144  return;
145 
146  STD_VECTOR<int> str;
147  splitToIntVector(str, link, ',');
148  if (str.empty())
149  return;
150 
151  const int id = str[0];
152 
153  if (id > 0)
154  {
155  str.erase(str.begin());
156  while (str.size() < maxCards)
157  str.push_back(0);
158  const ItemColor color =
160 
161  const ItemInfo &itemInfo = ItemDB::get(id);
162  // +++ need add support for options.
163  itemPopup->setItem(itemInfo, color, true, -1, &str[0], nullptr);
164  if (itemPopup->isPopupVisible())
165  {
167  }
168  else if (viewport != nullptr)
169  {
171  viewport->mMouseY);
172  }
173  }
174 }
#define maxCards
Definition: cards.h:25
static ItemColor getColorFromCards(const int *const cards)
void setItem(const ItemInfo &item, const ItemColor color, const bool showImage, int id, const int *const cards, const ItemOptionsList *const options)
Definition: itempopup.cpp:189
void position(const int x, const int y)
Definition: popup.cpp:235
bool isPopupVisible() const
Definition: popup.h:174
int mMouseX
Definition: viewport.h:154
int mMouseY
Definition: viewport.h:155
void setVisible(Visible visible)
Definition: widget.cpp:225
Viewport * viewport
Definition: viewport.cpp:36
uint16_t ItemColor
Definition: itemcolor.h:30
ItemPopup * itemPopup
Definition: itempopup.cpp:64
bool itemInfo(InputEvent &event)
Definition: commands.cpp:105
const ItemInfo & get(const int id)
Definition: itemdb.cpp:792
void splitToIntVector(std::vector< int > &tokens, const std::string &text, const char separator)
const bool Visible_false
Definition: visible.h:30

References ItemDB::get(), ItemColorManager::getColorFromCards(), Popup::isPopupVisible(), Actions::itemInfo(), itemPopup, maxCards, Viewport::mMouseX, Viewport::mMouseY, Popup::position(), ItemPopup::setItem(), Widget::setVisible(), splitToIntVector(), viewport, and Visible_false.

Referenced by handleLink().

◆ handleLink()

void ItemLinkHandler::handleLink ( const std::string &  link,
MouseEvent event 
)
virtual

Implements LinkHandler.

Definition at line 185 of file itemlinkhandler.cpp.

187 {
188  if (link.empty())
189  return;
190 
191  if (strStartWith(link, "http://") || strStartWith(link, "https://"))
192  {
193  handleHttpLink(link, event);
194  }
195  else if (link[0] == '?')
196  {
197  handleSearchLink(link);
198  }
199  else if (strStartWith(link, "help://"))
200  {
201  handleHelpLink(link);
202  }
203  else if (strStartWith(link, settings.linkCommandSymbol))
204  {
206  }
207  else if (strStartWith(link, "="))
208  {
209  handleCommandLink(link, "=");
210  }
211  else if (link == "news")
212  {
213  if (helpWindow != nullptr)
214  helpWindow->loadHelpSimple("news");
215  }
216  else if (link == "copyright")
217  {
219  }
220  else if (link[0] == 'q')
221  {
222  questsWindow->selectQuest(atoi(link.substr(1).c_str()));
223  }
224  else
225  {
226  handleItemLink(link);
227  }
228 }
void loadHelpSimple(const std::string &helpFile)
Definition: helpwindow.cpp:139
void executeAction(const InputActionT keyNum)
static void handleHttpLink(const std::string &link, const MouseEvent *const event)
void handleCommandLink(const std::string &link, const std::string &prefix)
static void handleItemLink(const std::string &link)
static void handleSearchLink(const std::string &link)
static void handleHelpLink(const std::string &link)
void selectQuest(const int varId)
std::string linkCommandSymbol
Definition: settings.h:127
QuestsWindow * questsWindow
Settings settings
Definition: settings.cpp:32
bool strStartWith(const std::string &str1, const std::string &str2)

References InputManager::executeAction(), handleCommandLink(), handleHelpLink(), handleHttpLink(), handleItemLink(), handleSearchLink(), helpWindow, inputManager, Settings::linkCommandSymbol, HelpWindow::loadHelpSimple(), questsWindow, QuestsWindow::selectQuest(), settings, strStartWith(), and InputAction::WINDOW_ABOUT.

◆ handleSearchLink()

void ItemLinkHandler::handleSearchLink ( const std::string &  link)
staticprivate

Definition at line 176 of file itemlinkhandler.cpp.

177 {
178  if (helpWindow != nullptr)
179  {
180  helpWindow->search(link.substr(1));
182  }
183 }
void search(const std::string &text)
Definition: helpwindow.cpp:187

References helpWindow, Widget::requestMoveToTop(), and HelpWindow::search().

Referenced by handleLink().

◆ setAllowCommands()

void ItemLinkHandler::setAllowCommands ( const bool  b)
inline

Definition at line 43 of file itemlinkhandler.h.

44  { mAllowCommands = b; }

References mAllowCommands.

Referenced by ChatWindow::ChatWindow().

Field Documentation

◆ mAllowCommands

bool ItemLinkHandler::mAllowCommands
private

Definition at line 59 of file itemlinkhandler.h.

Referenced by handleCommandLink(), and setAllowCommands().


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