- fixed global preferences serialization
- global_preferences.?? - fixed key=value configuration class - key_file.?? git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@767 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
8a43216527
commit
2b31d6d2eb
4 changed files with 331 additions and 12 deletions
|
@ -20,6 +20,9 @@
|
|||
|
||||
#include "config.h"
|
||||
#include "global_preferences.hh"
|
||||
#include "key_file.hh"
|
||||
#include "string_utils.hh"
|
||||
#include <sstream>
|
||||
|
||||
// Do not include in header file:
|
||||
#include "singleton.tcc"
|
||||
|
@ -61,6 +64,13 @@ GlobalPreferences::modules_dir_end() const
|
|||
}
|
||||
|
||||
|
||||
const
|
||||
Glib::ustring
|
||||
GlobalPreferences::get_config_filename()
|
||||
{
|
||||
return Glib::ustring("sgpem.cfg");
|
||||
}
|
||||
|
||||
void
|
||||
GlobalPreferences::add_modules_dir(const Glib::ustring& moddir)
|
||||
{
|
||||
|
@ -74,3 +84,188 @@ GlobalPreferences::add_policies_dir(const Glib::ustring& poldir)
|
|||
_pol_dirs.insert(_pol_dirs.begin(), poldir);
|
||||
}
|
||||
|
||||
std::vector<Glib::ustring>&
|
||||
GlobalPreferences::get_policy_dirs()
|
||||
{
|
||||
return _pol_dirs;
|
||||
}
|
||||
|
||||
std::vector<Glib::ustring>&
|
||||
GlobalPreferences::get_plugin_dirs()
|
||||
{
|
||||
return _mod_dirs;
|
||||
}
|
||||
|
||||
int
|
||||
GlobalPreferences::get_speed()
|
||||
{
|
||||
return _speed;
|
||||
}
|
||||
|
||||
int
|
||||
GlobalPreferences::set_speed(int new_speed)
|
||||
{
|
||||
int old_speed = _speed;
|
||||
_speed = new_speed;
|
||||
return old_speed;
|
||||
}
|
||||
|
||||
void
|
||||
GlobalPreferences::write_configrc()
|
||||
{
|
||||
KeyFile kf;
|
||||
|
||||
key_file_write(kf);
|
||||
kf.file_write(get_config_filename());
|
||||
}
|
||||
|
||||
void
|
||||
GlobalPreferences::load_configrc()
|
||||
{
|
||||
KeyFile kf;
|
||||
|
||||
kf.file_read(get_config_filename());
|
||||
key_file_read(kf);
|
||||
}
|
||||
|
||||
void
|
||||
GlobalPreferences::write_configrc(std::ostream &os)
|
||||
{
|
||||
KeyFile kf;
|
||||
|
||||
key_file_write(kf);
|
||||
kf.file_write(os);
|
||||
}
|
||||
|
||||
void
|
||||
GlobalPreferences::load_configrc(std::istream &is)
|
||||
{
|
||||
KeyFile kf;
|
||||
|
||||
kf.file_read(is);
|
||||
key_file_read(kf);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
GlobalPreferences::key_file_read(KeyFile& kf)
|
||||
{
|
||||
|
||||
_mod_dirs.clear();
|
||||
_pol_dirs.clear();
|
||||
// read speed
|
||||
{
|
||||
int new_speed;
|
||||
const Glib::ustring* val = kf.search_value(Glib::ustring("speed"));
|
||||
if(val){
|
||||
string_to_int(*val, new_speed);
|
||||
set_speed(new_speed);
|
||||
}
|
||||
}
|
||||
// read modules directories
|
||||
{
|
||||
const Glib::ustring* val = kf.search_value(Glib::ustring("modules-dir-number"));
|
||||
if(val)
|
||||
{
|
||||
std::istringstream istr(val->c_str());
|
||||
int n;
|
||||
istr >> n;
|
||||
for(int i=1; i<=n; i++)
|
||||
{
|
||||
std::ostringstream ostr;
|
||||
ostr << "modules-dir-" << i;
|
||||
Glib::ustring key(ostr.str());
|
||||
val = kf.search_value(key);
|
||||
if(val)
|
||||
{
|
||||
// add_modules_dir(*val);
|
||||
_mod_dirs.push_back(*val);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// read policies directories
|
||||
{
|
||||
const Glib::ustring* val = kf.search_value(Glib::ustring("policies-dir-number"));
|
||||
if(val)
|
||||
{
|
||||
std::istringstream istr(val->c_str());
|
||||
int n;
|
||||
istr >> n;
|
||||
for(int i=1; i<=n; i++)
|
||||
{
|
||||
std::ostringstream ostr;
|
||||
ostr << "policies-dir-" << i;
|
||||
Glib::ustring key(ostr.str());
|
||||
val = kf.search_value(key);
|
||||
if(val)
|
||||
{
|
||||
// add_policies_dir(*val);
|
||||
_pol_dirs.push_back(*val);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
GlobalPreferences::key_file_write(KeyFile& kf)
|
||||
{
|
||||
// write speed
|
||||
{
|
||||
Glib::ustring key("speed");
|
||||
Glib::ustring value;
|
||||
int_to_string(_speed, value);
|
||||
kf.insert_key_value(key, value);
|
||||
}
|
||||
|
||||
// add modules directories
|
||||
{
|
||||
/*
|
||||
GlobalPreferences::dir_iterator iter=_globalPreferences.modules_dir_begin();
|
||||
*/
|
||||
dir_iterator iter=_mod_dirs.begin();
|
||||
dir_iterator end=_mod_dirs.end();
|
||||
int n=0;
|
||||
while(iter!=end){
|
||||
std::ostringstream ostr;
|
||||
n++;
|
||||
ostr << "modules-dir-" << n; // << std::ends;
|
||||
Glib::ustring key(ostr.str());
|
||||
kf.insert_key_value(key, (*iter));
|
||||
++iter;
|
||||
}
|
||||
Glib::ustring key("modules-dir-number");
|
||||
std::ostringstream ostr;
|
||||
ostr << n << std::ends;
|
||||
Glib::ustring value(ostr.str());
|
||||
kf.insert_key_value(key, value);
|
||||
}
|
||||
// add policies directories
|
||||
{
|
||||
/*
|
||||
GlobalPreferences::dir_iterator iter=_globalPreferences.policies_dir_begin();
|
||||
*/
|
||||
dir_iterator iter=_pol_dirs.begin();
|
||||
dir_iterator end=_pol_dirs.end();
|
||||
int n=0;
|
||||
while(iter!=end){
|
||||
std::ostringstream ostr;
|
||||
n++;
|
||||
ostr << "policies-dir-" << n; // << std::ends;
|
||||
Glib::ustring key(ostr.str());
|
||||
kf.insert_key_value(key, (*iter));
|
||||
++iter;
|
||||
}
|
||||
Glib::ustring key("policies-dir-number");
|
||||
std::ostringstream ostr;
|
||||
ostr << n << std::ends;
|
||||
Glib::ustring value(ostr.str());
|
||||
kf.insert_key_value(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue