59 lines
1.5 KiB
C++
59 lines
1.5 KiB
C++
#include <fstream>
|
|
#include <glibmm.h>
|
|
#include "glib.h"
|
|
#include "glib/gstdio.h"
|
|
#include "config.h"
|
|
#include "portmanager.h"
|
|
|
|
#define PACKAGE_NAME "jsweeper"
|
|
#define CONFIG_FILENAME "jsweeper.ini"
|
|
|
|
void Config::Read()
|
|
{
|
|
std::string path = Glib::build_filename(Glib::get_user_config_dir(), PACKAGE_NAME);
|
|
g_mkdir_with_parents(path.c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
|
|
m_filename = Glib::build_filename(path, CONFIG_FILENAME);
|
|
|
|
ini.LoadFromDisk(m_filename);
|
|
|
|
IniGroup *group = ini.GetGroup("gui");
|
|
CellPadding = group->GetValue("cellpadding", 3);
|
|
FontSize = group->GetValue("fontsize", 10);
|
|
FontFace = group->GetValue("fontface", std::string("Sans"));
|
|
|
|
ExpandClients = group->GetValue("expandclients", true);
|
|
ExpandGroups = group->GetValue("expandgroups", false);
|
|
|
|
pm.AliasClear();
|
|
|
|
group = ini.GetGroup("aliases");
|
|
IniItemList::iterator it;
|
|
for (it = group->items.begin(); it != group->items.end(); ++it) {
|
|
IniItem *item = *it;
|
|
pm.AliasAdd(item->name, item->value);
|
|
}
|
|
}
|
|
|
|
void Config::Write()
|
|
{
|
|
IniGroup *group = ini.GetGroup("gui");
|
|
group->SetValue("cellpadding", CellPadding);
|
|
group->SetValue("fontsize", FontSize);
|
|
group->SetValue("fontface", FontFace);
|
|
|
|
group->SetValue("expandclients", ExpandClients);
|
|
group->SetValue("expandgroups", ExpandGroups);
|
|
|
|
ini.RemoveGroup("aliases");
|
|
group = ini.GetGroup("aliases");
|
|
|
|
const AliasList &list = pm.AliasGetList();
|
|
AliasList::const_iterator it;
|
|
for (it = list.begin(); it != list.end(); ++it) {
|
|
const Alias &a = *it;
|
|
group->SetValue(a.name, a.alias);
|
|
}
|
|
|
|
ini.SaveToDisk(m_filename);
|
|
}
|