Compare commits
No commits in common. "d066bdde5811057dbe2eb3955ea33a98049b1f8d" and "130ce196a28ff7e70b5c8c81f71dcd32ae693f07" have entirely different histories.
d066bdde58
...
130ce196a2
12
src/main.c
12
src/main.c
@ -3,27 +3,17 @@
|
|||||||
|
|
||||||
#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();
|
|
||||||
|
|
||||||
mdiary_save_settings(settings_path, settings);
|
gtk_main();
|
||||||
mdiary_settings_free(settings);
|
|
||||||
g_free(settings_path);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -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_print("PARSER: %s\n", filename, err->message);
|
g_error("PARSER: Could not open %s for reading: %s\n", filename, err->message);
|
||||||
g_error_free(err);
|
g_error_free(err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1,65 +0,0 @@
|
|||||||
#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);
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
#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
|
|
Loading…
Reference in New Issue
Block a user