fw4spl
SFolderSelector.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 "uiIO/action/SFolderSelector.hpp"
8 
9 #include <fwCom/Signal.hxx>
10 
11 #include <fwData/location/Folder.hpp>
12 
13 #include <fwGui/dialog/LocationDialog.hpp>
14 
15 #include <fwServices/macros.hpp>
16 
17 namespace uiIO
18 {
19 namespace action
20 {
21 
22 fwServicesRegisterMacro( ::fwGui::IActionSrv, ::uiIO::action::SFolderSelector, ::fwData::Object );
23 
24 const ::fwCom::Signals::SignalKeyType SFolderSelector::s_FOLDER_SELECTED_SIG = "folderSelected";
25 
26 //------------------------------------------------------------------------------
27 
28 SFolderSelector::SFolderSelector( ) noexcept
29 {
30  newSignal< FolderSelectedSignalType >( s_FOLDER_SELECTED_SIG );
31 }
32 
33 //------------------------------------------------------------------------------
34 
35 SFolderSelector::~SFolderSelector() noexcept
36 {
37 }
38 
39 //------------------------------------------------------------------------------
40 
42 {
43  const auto& config = this->getConfigTree();
44  m_dialogTitle = config.get("dialogTitle", "Select a folder");
45 }
46 
47 //------------------------------------------------------------------------------
48 
50 {
51 }
52 
53 //------------------------------------------------------------------------------
54 
56 {
57  static ::boost::filesystem::path _sDefaultPath("");
59  dialogFile.setTitle(m_dialogTitle);
60  dialogFile.setDefaultLocation( ::fwData::location::Folder::New(_sDefaultPath) );
61  dialogFile.setOption(::fwGui::dialog::ILocationDialog::READ);
62  dialogFile.setType(::fwGui::dialog::ILocationDialog::FOLDER);
63 
64  ::fwData::location::Folder::sptr result;
65  result = ::fwData::location::Folder::dynamicCast( dialogFile.show() );
66  if (result)
67  {
68  auto sig = this->signal<FolderSelectedSignalType>(s_FOLDER_SELECTED_SIG);
69  sig->asyncEmit(result->getFolder());
70  }
71 }
72 
73 //------------------------------------------------------------------------------
74 
76 {
77 }
78 
79 //------------------------------------------------------------------------------
80 //
81 } // namespace action
82 } // namespace uiIO
UIIO_API void starting() override
Do nothing.
UIIO_API void updating() override
Show the dialog and send the signal with the chosen directory.
Raise a pop-up dialog to select a directory, then send it via a signal.
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.
Defines the service interface managing the menu items.
Definition: IActionSrv.hpp:24
Base class for each data object.
UIIO_API void configuring() override
Do nothing.
FWGUI_API void setTitle(const std::string &title) override
Set the title for the dialog.
Defines the generic file/folder selector dialog for IHM.
UIIO_API void stopping() override
Do nothing.
FWGUI_API void setType(::fwGui::dialog::ILocationDialog::Types type) override
Set the type of location for the dialog (SINGLE_FILE, FORLDER, MULTI_FILES)
The namespace uiIO contains a simple service to manipulate IO with IHM..
FWSERVICES_API ConfigType getConfigTree() const
Return the configuration, in an boost property tree.
Definition: IService.cpp:247