load/save configuration
parent
04a79c06e5
commit
0204abcebc
|
@ -23,6 +23,9 @@
|
|||
*/
|
||||
|
||||
class Config {
|
||||
private KeyFile keyfile;
|
||||
private string path;
|
||||
|
||||
public string control_monitor;
|
||||
public bool control_fullscreen;
|
||||
public string presentation_monitor;
|
||||
|
@ -30,14 +33,36 @@ class Config {
|
|||
public signal void configuration_changed();
|
||||
|
||||
public Config() {
|
||||
path = Environment.get_user_config_dir() + "/pdf-presenter.cfg";
|
||||
keyfile = new KeyFile();
|
||||
load();
|
||||
}
|
||||
|
||||
public void load() {
|
||||
/* TODO: load from ~/.config/pdf-presenter.cfg */
|
||||
try {
|
||||
keyfile.load_from_file (path, KeyFileFlags.NONE);
|
||||
|
||||
/* monitors section */
|
||||
control_monitor = keyfile.get_string ("monitors", "control");
|
||||
presentation_monitor = keyfile.get_string ("monitors", "presentation");
|
||||
control_fullscreen = keyfile.get_boolean ("monitors", "control_fullscreen");
|
||||
} catch(Error e) {
|
||||
stderr.printf("could not load settings: %s\n", e.message);
|
||||
}
|
||||
}
|
||||
|
||||
public void save() {
|
||||
/* TODO: save to ~/.config/pdf-presenter.cfg */
|
||||
/* monitors section */
|
||||
keyfile.set_string("monitors", "control", control_monitor);
|
||||
keyfile.set_string("monitors", "presentation", presentation_monitor);
|
||||
keyfile.set_boolean("monitors", "control_fullscreen", control_fullscreen);
|
||||
|
||||
try {
|
||||
string data = keyfile.to_data();
|
||||
var file = File.new_for_path(path);
|
||||
file.replace_contents(data, data.length, null, false, FileCreateFlags.NONE, null);
|
||||
} catch(Error e) {
|
||||
stderr.printf("could not save settings: %s\n", e.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue