Compare commits

..

2 Commits

4 changed files with 94 additions and 2 deletions

View File

@ -3,17 +3,27 @@
#include "mainwindow.h" #include "mainwindow.h"
#include "mdiary.h" #include "mdiary.h"
#include "settings.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
struct mainWindow *mainWindow; struct mainWindow *mainWindow;
struct mdiary_settings *settings;
gchar *settings_path;
gtk_init(&argc, &argv); gtk_init(&argc, &argv);
settings_path = g_strdup_printf("%s/.mdiary.conf", g_get_home_dir());
settings = mdiary_settings_new();
mdiary_load_settings(settings_path, settings);
mainWindow = mainWindow_new(); mainWindow = mainWindow_new();
gtk_widget_show(mainWindow->mainWindow); gtk_widget_show(mainWindow->mainWindow);
gtk_main(); gtk_main();
mdiary_save_settings(settings_path, settings);
mdiary_settings_free(settings);
g_free(settings_path);
return 0; return 0;
} }

View File

@ -237,7 +237,7 @@ static void mdiary_add_file_to_store(gchar *filename, GtkListStore *entryListSto
file = g_file_new_for_path(filename); file = g_file_new_for_path(filename);
stream = g_file_read(file, NULL, &err); stream = g_file_read(file, NULL, &err);
if (err != NULL) { if (err != NULL) {
g_error("PARSER: Could not open %s for reading: %s\n", filename, err->message); g_print("PARSER: %s\n", filename, err->message);
g_error_free(err); g_error_free(err);
return; return;
} }

65
src/settings.c Normal file
View File

@ -0,0 +1,65 @@
#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);
}

17
src/settings.h Normal file
View File

@ -0,0 +1,17 @@
#ifndef SETTINGS_H
#define SETTINGS_H
#include <glib.h>
#include <gtk/gtk.h>
#include <stdlib.h>
struct mdiary_settings {
GList *last_workspaces;
};
gboolean mdiary_load_settings(gchar *filename, struct mdiary_settings *settings);
gboolean mdiary_save_settings(gchar *filename, struct mdiary_settings *settings);
struct mdiary_settings *mdiary_settings_new();
void mdiary_settings_free(struct mdiary_settings *settings);
#endif // SETTINGS_H