fw4spl
src/fwGui/dialog/LoggerDialog.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 "fwGui/dialog/LoggerDialog.hpp"
8 
9 #include <fwServices/registry/ActiveWorkers.hpp>
10 
11 #include <fwThread/Worker.hpp>
12 #include <fwThread/Worker.hxx>
13 
14 #include <functional>
15 
16 namespace fwGui
17 {
18 namespace dialog
19 {
20 
21 //-----------------------------------------------------------------------------
22 
24  const std::string& title, const std::string& message, const ::fwLog::Logger::sptr& logger)
25 {
26  ::fwGui::dialog::LoggerDialog dialog(title, message, logger);
27  return dialog.show();
28 }
29 
30 //-----------------------------------------------------------------------------
31 
33 {
34  ::fwGui::GuiBaseObject::sptr guiObj = ::fwGui::factory::New(ILoggerDialog::REGISTRY_KEY);
35  m_implementation = ::fwGui::dialog::ILoggerDialog::dynamicCast(guiObj);
36 }
37 
38 //-----------------------------------------------------------------------------
39 
41 {
42 }
43 
44 //-----------------------------------------------------------------------------
45 
46 LoggerDialog::LoggerDialog(const std::string& title, const std::string& message, const ::fwLog::Logger::sptr& logger)
47 {
48  ::fwGui::GuiBaseObject::sptr guiObj = ::fwGui::factory::New(ILoggerDialog::REGISTRY_KEY);
49  m_implementation = ::fwGui::dialog::ILoggerDialog::dynamicCast(guiObj);
50  m_implementation->setTitle(title);
51  m_implementation->setMessage(message);
52  m_implementation->setLogger(logger);
53 }
54 
55 //-----------------------------------------------------------------------------
56 
57 void LoggerDialog::setTitle(const std::string& title)
58 {
59  m_implementation->setTitle(title);
60 }
61 
62 //-----------------------------------------------------------------------------
63 
64 void LoggerDialog::setMessage(const std::string& message)
65 {
66  m_implementation->setMessage(message);
67 }
68 
69 //-----------------------------------------------------------------------------
70 
71 void LoggerDialog::setLogger(const ::fwLog::Logger::sptr& logger)
72 {
73  m_implementation->setLogger(logger);
74 }
75 
76 //-----------------------------------------------------------------------------
77 
79 {
80  if(m_implementation)
81  {
82  std::function<bool()> func = std::bind(&ILoggerDialog::show, m_implementation);
83  std::shared_future<bool> f = ::fwServices::registry::ActiveWorkers::getDefaultWorker()->postTask<bool>(func);
84  f.wait();
85 
86  return f.get();
87  }
88 
89  return false;
90 }
91 
92 //-----------------------------------------------------------------------------
93 
94 } //namespace dialog
95 } //namespace fwGui
virtual FWGUI_API void setLogger(const ::fwLog::Logger::sptr &logger) override
Set the dialog logger.
virtual FWGUI_API bool show()=0
Show the dialog and return whether the user has selected the Ok or Cancel button. ...
The namespace fwGui contains the base interface for IHM services.
Definition: SJobBar.hpp:23
ILoggerDialog is used to display a dialog message and a set of logs Use the Delegate design pattern...
static FWGUI_API const FactoryRegistryKeyType REGISTRY_KEY
This unique key should be used for all factory for specific Selector(qt,wx,...)
virtual FWGUI_API void setTitle(const std::string &title) override
Set the dialog title.
virtual FWGUI_API void setMessage(const std::string &message) override
Set the dialog message.
virtual FWGUI_API ~LoggerDialog()
Destructor.
virtual FWGUI_API bool show() override
Show the dialog and return whether the user has selected the Ok or Cancel button. ...
FWGUI_API LoggerDialog()
Constructor that will instantiate the concrete implementation.
static FWSERVICES_API::fwThread::Worker::sptr getDefaultWorker()
Get the default registered worker.
static FWGUI_API bool showLoggerDialog(const std::string &title, const std::string &message, const ::fwLog::Logger::sptr &logger)