66 lines
1.6 KiB
C
66 lines
1.6 KiB
C
#include "settings.h"
|
|
|
|
static void mdiary_settings_parse_line(gchar *line, struct mdiary_settings *settings)
|
|
{
|
|
GRegex *regex;
|
|
GMatchInfo *match_info;
|
|
|
|
regex = g_regex_new("workspace = (.*)", G_REGEX_RAW, 0, NULL);
|
|
|
|
if (g_regex_match(regex, line, 0, &match_info) &&
|
|
g_regex_get_capture_count(regex) > 0 &&
|
|
g_match_info_matches(match_info)) {
|
|
settings->last_workspaces = g_list_append(settings->last_workspaces,
|
|
g_strdup(g_match_info_fetch(match_info, 1)));
|
|
}
|
|
|
|
g_regex_unref(regex);
|
|
}
|
|
|
|
gboolean mdiary_load_settings(gchar *filename, struct mdiary_settings *settings)
|
|
{
|
|
GFile *file;
|
|
GError *err = NULL;
|
|
GFileInputStream *stream;
|
|
GDataInputStream *dstream;
|
|
gchar *line;
|
|
|
|
file = g_file_new_for_path(filename);
|
|
stream = g_file_read(file, NULL, &err);
|
|
if (err != NULL) {
|
|
g_print("SETTINGS: %s\n", err->message);
|
|
g_error_free(err);
|
|
return FALSE;
|
|
}
|
|
dstream = g_data_input_stream_new(G_INPUT_STREAM(stream));
|
|
|
|
while (line = g_data_input_stream_read_line(G_DATA_INPUT_STREAM(dstream), NULL, NULL, NULL)) {
|
|
mdiary_settings_parse_line(line, settings);
|
|
}
|
|
|
|
g_input_stream_close(G_INPUT_STREAM(dstream), NULL, NULL);
|
|
g_input_stream_close(G_INPUT_STREAM(stream), NULL, NULL);
|
|
g_object_unref(file);
|
|
|
|
}
|
|
|
|
gboolean mdiary_save_settings(gchar *filename, struct mdiary_settings *settings)
|
|
{
|
|
g_print("SETTINGS: NYI.\n");
|
|
}
|
|
|
|
struct mdiary_settings *mdiary_settings_new()
|
|
{
|
|
struct mdiary_settings *settings;
|
|
|
|
settings = malloc(sizeof(struct mdiary_settings));
|
|
settings->last_workspaces = NULL;
|
|
|
|
return settings;
|
|
}
|
|
|
|
void mdiary_settings_free(struct mdiary_settings *settings)
|
|
{
|
|
g_list_free_full(settings->last_workspaces, g_free);
|
|
}
|