fw4spl
src/fwGui/dialog/LocationDialog.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/LocationDialog.hpp"
8 
9 #include <fwServices/registry/ActiveWorkers.hpp>
10 
11 namespace fwGui
12 {
13 namespace dialog
14 {
15 //-----------------------------------------------------------------------------
16 
18 {
19 
20  ::fwServices::registry::ActiveWorkers::getDefaultWorker()->postTask< void >(std::function< void() >(
21  [&] {
22  ::fwGui::GuiBaseObject::sptr guiObj = ::fwGui::factory::New(ILocationDialog::REGISTRY_KEY);
23  m_implementation = ::fwGui::dialog::ILocationDialog::dynamicCast(guiObj);
24  })
25  ).wait();
26 }
27 
28 //------------------------------------------------------------------------------
29 
30 LocationDialog::~LocationDialog()
31 {
32 }
33 
34 //-----------------------------------------------------------------------------
35 
36 ::fwData::location::ILocation::sptr LocationDialog::show()
37 {
38  typedef SPTR (::fwData::location::ILocation) R;
39 
40  std::function< R() > func = std::bind(&ILocationDialog::show, m_implementation);
41  std::shared_future< R > f = ::fwServices::registry::ActiveWorkers::getDefaultWorker()->postTask< R >(func);
42 
43  f.wait();
44  return f.get();
45 }
46 
47 //-----------------------------------------------------------------------------
48 
49 void LocationDialog::setType( ::fwGui::dialog::ILocationDialog::Types type)
50 {
51  m_implementation->setType( type );
52 }
53 
54 //-----------------------------------------------------------------------------
55 
56 void LocationDialog::addFilter(const std::string& filterName, const std::string& wildcardList )
57 {
58  m_implementation->addFilter(filterName, wildcardList);
59 }
60 
61 //-----------------------------------------------------------------------------
62 
63 ILocationDialog& LocationDialog::setOption( ::fwGui::dialog::ILocationDialog::Options option)
64 {
65  return m_implementation->setOption(option);
66 }
67 
68 //-----------------------------------------------------------------------------
69 
70 void LocationDialog::setTitle(const std::string& title)
71 {
72  m_implementation->setTitle(title);
73 }
74 
75 //-----------------------------------------------------------------------------
76 
77 const std::string& LocationDialog::getTitle()
78 {
79  return m_implementation->getTitle();
80 }
81 
82 //-----------------------------------------------------------------------------
83 
84 void LocationDialog::setDefaultLocation(::fwData::location::ILocation::sptr loc)
85 {
86  m_implementation->setDefaultLocation(loc);
87 }
88 
89 //-----------------------------------------------------------------------------
90 
91 const ::boost::filesystem::path LocationDialog::getDefaultLocation()
92 {
93  return m_implementation->getDefaultLocation();
94 }
95 
96 //-----------------------------------------------------------------------------
97 
98 void LocationDialog::saveDefaultLocation(::fwData::location::ILocation::sptr loc)
99 {
100  m_implementation->saveDefaultLocation(loc);
101 }
102 
103 //-----------------------------------------------------------------------------
104 
106 {
107  return m_implementation->getCurrentSelection();
108 }
109 
110 //-----------------------------------------------------------------------------
111 
112 } //namespace dialog
113 } //namespace fwGui
#define SPTR(_cls_)
The namespace fwGui contains the base interface for IHM services.
Definition: SJobBar.hpp:23
virtual FWGUI_API void setDefaultLocation(::fwData::location::ILocation::sptr loc) override
Set the initial location for the dialog.
FWGUI_API::fwGui::dialog::ILocationDialog & setOption(::fwGui::dialog::ILocationDialog::Options option) override
allow to set option to the file dialog mode=READ/WRITE, check=FILE_MUST_EXIST
FWGUI_API::fwData::location::ILocation::sptr show() override
Display the dialog.
FWGUI_API void addFilter(const std::string &filterName, const std::string &wildcardList) override
specify some filtering when browsing files:
FWGUI_API const std::string & getTitle() override
Returns the title for the dialog.
Abstract class to define a location ( fileSystem, directory(IES) etc.... )
Definition: ILocation.hpp:28
static FWGUI_API const FactoryRegistryKeyType REGISTRY_KEY
this unique key should be used for all factory for specific LocationDialog(qt,wx,...)
static FWSERVICES_API::fwThread::Worker::sptr getDefaultWorker()
Get the default registered worker.
FWGUI_APIconst::boost::filesystem::path getDefaultLocation() override
Gets the default location for the dialog (from preferences or specified by user)
FWGUI_API LocationDialog()
Will instantiate the concrete implementation.
FWGUI_API void setTitle(const std::string &title) override
Set the title for the dialog.
FWGUI_API std::string getCurrentSelection() const override
Gets the current extension file selection.
FWGUI_API void setType(::fwGui::dialog::ILocationDialog::Types type) override
Set the type of location for the dialog (SINGLE_FILE, FORLDER, MULTI_FILES)
FWGUI_API void saveDefaultLocation(::fwData::location::ILocation::sptr loc) override
Save the specified default location for the dialog in preferences (if available)
virtual FWGUI_API::fwData::location::ILocation::sptr show()=0