97 lines
3.3 KiB
C++
97 lines
3.3 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;
|
|
|
|
group = ini.GetGroup("gui");
|
|
CellPadding = group->GetValue("cellpadding", 3);
|
|
FontSize = group->GetValue("fontsize", 10);
|
|
FontFace = group->GetValue("fontface", "Sans");
|
|
Antialias = group->GetValue("antialias", false);
|
|
|
|
group = ini.GetGroup("general");
|
|
UseConnections = group->GetValue("useconnections", true);
|
|
UseAliases = group->GetValue("usealiases", true);
|
|
LocalAliases = group->GetValue("localaliases", true);
|
|
SeparateByPortType = group->GetValue("separatebyporttype", false);
|
|
ExpandClients = group->GetValue("expandclients", true);
|
|
ExpandGroups = group->GetValue("expandgroups", false);
|
|
|
|
group = ini.GetGroup("colours");
|
|
Background = Colour(group->GetValue("background", "#404040"));
|
|
GridLinesClient = Colour(group->GetValue("gridlinesclient", "#000000"));
|
|
GridLinesGroup = Colour(group->GetValue("gridlinesgroup", "#1A1A1A"));
|
|
GridLinesPort = Colour(group->GetValue("gridlinesport", "#333333"));
|
|
Text = Colour(group->GetValue("text", "#FFFFFF"));
|
|
TabClient = Colour(group->GetValue("tabclient", "#1A1B1B"));
|
|
TabGroup = Colour(group->GetValue("tabgroup", "#295630"));
|
|
TabPortAudio = Colour(group->GetValue("tabportaudio", "#294056"));
|
|
TabPortMidi = Colour(group->GetValue("tabportmidi", "#4F3030"));
|
|
|
|
pm.AliasClear();
|
|
|
|
group = ini.GetGroup("aliases");
|
|
IniItemList::const_iterator it;
|
|
for (it = group->items.begin(); it != group->items.end(); ++it) {
|
|
const IniItem *item = *it;
|
|
pm.AliasAdd(item->name, item->value);
|
|
}
|
|
}
|
|
|
|
void Config::Write()
|
|
{
|
|
IniGroup *group;
|
|
|
|
group = ini.GetGroup("gui");
|
|
group->SetValue("cellpadding", CellPadding);
|
|
group->SetValue("fontsize", FontSize);
|
|
group->SetValue("fontface", FontFace);
|
|
group->SetValue("antialias", Antialias);
|
|
|
|
group = ini.GetGroup("general");
|
|
group->SetValue("useconnections", UseConnections);
|
|
group->SetValue("usealiases", UseAliases);
|
|
group->SetValue("localaliases", LocalAliases);
|
|
group->SetValue("separatebyporttype", SeparateByPortType);
|
|
group->SetValue("expandclients", ExpandClients);
|
|
group->SetValue("expandgroups", ExpandGroups);
|
|
|
|
group = ini.GetGroup("colours");
|
|
group->SetValue("background", Background.ToCode());
|
|
group->SetValue("gridlinesclient", GridLinesClient.ToCode());
|
|
group->SetValue("gridlinesgroup", GridLinesGroup.ToCode());
|
|
group->SetValue("gridlinesport", GridLinesPort.ToCode());
|
|
group->SetValue("text", Text.ToCode());
|
|
group->SetValue("tabclient", TabClient.ToCode());
|
|
group->SetValue("tabgroup", TabGroup.ToCode());
|
|
group->SetValue("tabportaudio", TabPortAudio.ToCode());
|
|
group->SetValue("tabportmidi", TabPortMidi.ToCode());
|
|
|
|
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.m_match, a.m_replace);
|
|
}
|
|
|
|
ini.SaveToDisk(m_filename);
|
|
}
|