fw4spl
LaunchBrowserActionService.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2017.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #include "uiGenericQt/action/LaunchBrowserActionService.hpp"
8 
9 #include <fwCore/base.hpp>
10 
11 #include <fwServices/macros.hpp>
12 
13 #include <boost/filesystem/operations.hpp>
14 #include <boost/filesystem/path.hpp>
15 
16 #include <QCoreApplication>
17 #include <QDesktopServices>
18 #include <QUrl>
19 
20 namespace uiGenericQt
21 {
22 
23 namespace action
24 {
25 
26 //------------------------------------------------------------------------------
27 
29 
30 //------------------------------------------------------------------------------
31 
33 {
34  m_url = "";
35 }
36 
37 //------------------------------------------------------------------------------
38 
40 {
41 }
42 
43 //------------------------------------------------------------------------------
44 
45 void LaunchBrowserActionService::info(std::ostream& _sstream )
46 {
47  _sstream << "Action for manage url" << std::endl;
48 }
49 
50 //-----------------------------------------------------------------------------
51 
53 {
56 
57  std::vector < Configuration > urlConfig = m_configuration->find("url");
58  if(!urlConfig.empty())
59  {
60  m_url = urlConfig.at(0)->getValue();
61  }
62 }
63 
64 //------------------------------------------------------------------------------
65 
67 {
69 
70  SLM_WARN_IF("URL is empty.", m_url.empty());
71  QUrl url(QString::fromStdString(m_url), QUrl::TolerantMode);
72 
73  if(url.isRelative()) // no scheme
74  {
75  ::boost::filesystem::path path(QCoreApplication::applicationDirPath().toStdString());
76  path = path.parent_path(); // install folder path
77  path /= url.path().toStdString();
78 
79  QString urlStr = QString::fromStdString("file:///" + path.string());
80  url = QUrl(urlStr, QUrl::TolerantMode);
81  }
82 
83  bool isSuccess = QDesktopServices::openUrl(url);
84  SLM_WARN_IF("Browser wasn't successfully launched.", !isSuccess);
85 }
86 
87 //------------------------------------------------------------------------------
88 
90 {
92 }
93 
94 //------------------------------------------------------------------------------
95 
97 {
99 }
100 //------------------------------------------------------------------------------
101 
102 } // namespace action
103 
104 } // namespace uiGenericQt
This action launch a browser on the url given in configuration.
FWGUI_API void actionServiceStarting()
Method called when the action service is starting.
Definition: IActionSrv.cpp:160
The namespace uiGenericQt contains actions to show help, acknowledgments and about frame...
#define SLM_TRACE_FUNC()
Trace contextual function signature.
Definition: spyLog.hpp:329
virtual UIGENERICQT_API ~LaunchBrowserActionService() noexcept
Destructor. Do nothing.
FWGUI_API void actionServiceStopping()
Method called when the action service is stopping.
Definition: IActionSrv.cpp:153
Defines the service interface managing the menu items.
Definition: IActionSrv.hpp:24
void updating() override
Launch a browser on the url given in the configuration.
FWGUI_API void initialize()
Initialize the action.
Definition: IActionSrv.cpp:69
UIGENERICQT_API LaunchBrowserActionService() noexcept
Constructor. Do nothing.
Base class for each data object.
::fwRuntime::ConfigurationElement::sptr m_configuration
Configuration element used to configure service internal state using a generic XML like structure TOD...
Definition: IService.hpp:670
#define SLM_WARN_IF(message, cond)
Definition: spyLog.hpp:265
void info(std::ostream &_sstream) override
Write information in a stream.