7 #include "preferences/SPreferences.hpp" 9 #include <fwAtomConversion/convert.hpp> 11 #include <fwAtomsBoostIO/Reader.hpp> 12 #include <fwAtomsBoostIO/types.hpp> 13 #include <fwAtomsBoostIO/Writer.hpp> 15 #include <fwData/Composite.hpp> 17 #include <fwDataCamp/visitor/RecursiveLock.hpp> 19 #include <fwPreferences/helper.hpp> 21 #include <fwRuntime/ConfigurationElement.hpp> 23 #include <fwServices/macros.hpp> 25 #include <fwZip/ReadDirArchive.hpp> 26 #include <fwZip/WriteDirArchive.hpp> 28 #include <boost/filesystem.hpp> 60 std::vector < ::fwRuntime::ConfigurationElement::sptr > vectConfig =
m_configuration->find(
"filename");
61 SLM_ASSERT(
"The <filename> element must exist.", !vectConfig.empty() );
67 void SPreferences::load()
69 if (::boost::filesystem::is_regular_file(
m_prefFile))
71 const ::boost::filesystem::path folderPath =
m_prefFile.parent_path();
72 const ::boost::filesystem::path filename =
m_prefFile.filename();
74 ::fwData::Object::sptr data = this->getInOut< ::fwData::Object >(::fwPreferences::s_PREFERENCES_KEY);
79 data = this->getObject< ::fwData::Object >();
83 ::fwZip::IReadArchive::sptr readArchive = ::fwZip::ReadDirArchive::New(folderPath.string());
87 ::fwAtoms::Object::sptr atom = ::fwAtoms::Object::dynamicCast( reader.read( readArchive, filename ) );
89 ::fwData::Object::sptr newData = ::fwAtomConversion::convert(atom,
91 data->shallowCopy(newData);
102 void SPreferences::save()
104 const ::boost::filesystem::path folderPath =
m_prefFile.parent_path();
105 const ::boost::filesystem::path filename =
m_prefFile.filename();
107 ::fwData::Object::sptr obj = this->getInOut< ::fwData::Object >(::fwPreferences::s_PREFERENCES_KEY);
112 obj = this->getObject< ::fwData::Object >();
119 ::fwAtoms::Object::sptr atom = ::fwAtomConversion::convert(obj);
121 ::fwZip::IWriteArchive::sptr writeArchive = ::fwZip::WriteDirArchive::New(folderPath.string());
122 ::fwAtomsBoostIO::FormatType format = ::fwAtomsBoostIO::JSON;
125 && !(::boost::filesystem::status(
m_prefFile).permissions() & ::boost::filesystem::owner_write) )
128 "Please, change file permission.");
#define FW_DEPRECATED_KEY(newKey, access, version)
Use this macro when deprecating a service key to warn the developer.
Preferences service API. This class represents the base interface for preferences services...
::boost::filesystem::path m_prefFile
preference file
This policy changes data's uuid if it already exists.
Service to load and save preferences.
#define SLM_ERROR(message)
virtual PREFERENCES_API void updating() override
Updates service and saves preferences.
The namespace preferences contains the service to manage the application's preferences (window size/p...
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
This class is an helper to lock an object and all its children recursively.
::fwRuntime::ConfigurationElement::sptr m_configuration
Configuration element used to configure service internal state using a generic XML like structure TOD...
This class defines a composite object.
virtual PREFERENCES_API void configuring() override
Configure the service before starting. Apply the configuration to service.
virtual PREFERENCES_API void stopping() override
Stops service and saves preferences.
virtual PREFERENCES_API void starting() override
Starts service and loads preferences if exists.