fw4spl
src/fwGui/dialog/ProgressDialog.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/ProgressDialog.hpp"
8 
9 #include <fwServices/registry/ActiveWorkers.hpp>
10 
11 #include <functional>
12 
13 namespace fwGui
14 {
15 namespace dialog
16 {
17 //-----------------------------------------------------------------------------
18 
19 ProgressDialog::ProgressDialog(const std::string& title, const std::string& message)
20 {
22  [&] {
23  ::fwGui::GuiBaseObject::sptr guiObj = ::fwGui::factory::New(IProgressDialog::REGISTRY_KEY);
24  m_implementation = ::fwGui::dialog::IProgressDialog::dynamicCast(guiObj);
25  if(m_implementation)
26  {
27  m_implementation->setTitle(title);
28  m_implementation->setMessage(message);
29  }
30  } ).wait();
31 }
32 
33 //-----------------------------------------------------------------------------
34 
35 ProgressDialog::~ProgressDialog()
36 {
37  ::fwServices::registry::ActiveWorkers::getDefaultWorker()->postTask<void>( [&] { m_implementation.reset();
38  } ).wait();
39 }
40 
41 //-----------------------------------------------------------------------------
42 
43 void ProgressDialog::setTitle(const std::string& title)
44 {
46  [&] {
47  if(m_implementation)
48  {
49  m_implementation->setTitle(title);
50  }
51  } ).wait();
52 }
53 
54 //-----------------------------------------------------------------------------
55 
56 void ProgressDialog::setMessage(const std::string& msg)
57 {
59  [&] {
60  if(m_implementation)
61  {
62  m_implementation->setMessage(msg);
63  }
64  } ).wait();
65 }
66 
67 //-----------------------------------------------------------------------------
68 
69 void ProgressDialog::operator()(float percent, std::string msg)
70 {
72  [&] {
73  if(m_implementation)
74  {
75  (*m_implementation)(percent, msg);
76  }
77  } ).wait();
78 }
79 
80 //-----------------------------------------------------------------------------
81 
82 void ProgressDialog::setCancelCallback(CancelCallbackType callback)
83 {
85  [&] {
86  if(m_implementation)
87  {
88  m_implementation->setCancelCallback(callback);
89  }
90  } ).wait();
91 }
92 
93 //-----------------------------------------------------------------------------
94 
95 void ProgressDialog::cancelPressed()
96 {
97  assert(0);
98 }
99 
100 //-----------------------------------------------------------------------------
101 
102 void ProgressDialog::hideCancelButton()
103 {
105  [&] {
106  m_implementation->hideCancelButton();
107  } ).wait();
108 }
109 
110 } //namespace dialog
111 } //namespace fwGui
FWGUI_API void setTitle(const std::string &title) override
set the title for the dialog
The namespace fwGui contains the base interface for IHM services.
Definition: SJobBar.hpp:23
static FWGUI_API const FactoryRegistryKeyType REGISTRY_KEY
this unique key should be used for all factory for specific LocationDialog(qt,wx,...)
FWGUI_API void setMessage(const std::string &message) override
set the message for the dialog
FWGUI_API void operator()(float percent, std::string msg) override
action called by fwTools::ProgressAdviser
FWGUI_API ProgressDialog(const std::string &title=std::string(), const std::string &msg=std::string())
will instanciate the concrete implementation
static FWSERVICES_API::fwThread::Worker::sptr getDefaultWorker()
Get the default registered worker.