diff options
author | Patrick McDermott <pj@pehjota.net> | 2017-11-04 00:07:15 (EDT) |
---|---|---|
committer | Patrick McDermott <pj@pehjota.net> | 2017-11-04 00:07:15 (EDT) |
commit | b042bb332812b358d00ba89baaac13b7c2100f16 (patch) | |
tree | 717300fcb6758e95b55f8e8ed23a925b1fa7270c | |
parent | 45456388efcb88992dde469c7f3dfcc2658903ea (diff) | |
download | marquee-b042bb332812b358d00ba89baaac13b7c2100f16.zip marquee-b042bb332812b358d00ba89baaac13b7c2100f16.tar.gz marquee-b042bb332812b358d00ba89baaac13b7c2100f16.tar.bz2 |
[WIP] src/config/profiles.[ch]: New files
-rw-r--r-- | src/config/local.mk | 1 | ||||
-rw-r--r-- | src/config/profiles.c | 124 | ||||
-rw-r--r-- | src/config/profiles.h | 56 |
3 files changed, 181 insertions, 0 deletions
diff --git a/src/config/local.mk b/src/config/local.mk index c84084e..5af6098 100644 --- a/src/config/local.mk +++ b/src/config/local.mk @@ -1,3 +1,4 @@ marquee_SOURCES += \ %reldir%/config.c \ + %reldir%/profiles.c \ %reldir%/settings.c diff --git a/src/config/profiles.c b/src/config/profiles.c new file mode 100644 index 0000000..af2ff9c --- /dev/null +++ b/src/config/profiles.c @@ -0,0 +1,124 @@ +/* + * Configuration/browsing profiles + * + * Copyright (C) 2017 Patrick McDermott + * + * This file is part of Marquee. + * + * Marquee is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Marquee is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Marquee. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include "profiles.h" + +#include <gio/gio.h> +#include <glib.h> + +struct _MqProfiles { + gchar *file_name; + GKeyFile *key_file; +}; + +static gboolean +create(MqProfiles *profiles) +{ + GFile *file; + GFileOutputStream *stream; + + file = g_file_new_for_path(profiles->file_name); + + stream = g_file_create(file, G_FILE_CREATE_PRIVATE, NULL, NULL); + if (!stream) { + return FALSE; + } + + /* TODO: Create configs. */ + return FALSE; +} + +static void +load(MqProfiles *profiles) +{ + /* TODO: Handle parsing and ENOENT errors differently? */ + g_key_file_load_from_file(profiles->key_file, profiles->file_name, + G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS, NULL); +} + +MqProfiles * +mq_profiles_new(void) +{ + MqProfiles *profiles; + gchar *config_dir; + + profiles = g_new0(MqProfiles, 1); + + config_dir = g_build_filename(g_get_user_config_dir(), PACKAGE, NULL); + g_mkdir_with_parents(config_dir, 0700); + g_free(config_dir); + + profiles->file_name = g_build_filename(g_get_user_config_dir(), PACKAGE, + "profiles", NULL); + + if (!create(profiles)) { + load(profiles); + } + + /* TODO: Set up GFileMonitor. */ + + return profiles; +} + +gchar ** +mq_profiles_get_profiles(MqProfiles *profiles, gsize *length) +{ + return g_key_file_get_groups(profiles->key_file, length); +} + +gchar * +mq_profiles_get_name(MqProfiles *profiles, const gchar *profile) +{ + return g_key_file_get_string(profiles->key_file, profile, "name", NULL); +} + +gchar * +mq_profiles_get_color(MqProfiles *profiles, const gchar *profile) +{ + return g_key_file_get_string(profiles->key_file, profile, "color", + NULL); +} + +void +mq_profiles_set_name(MqProfiles *profiles, const gchar *profile, + const gchar *name) +{ + g_key_file_set_string(profiles->key_file, profile, "name", name); +} + +void +mq_profiles_set_color(MqProfiles *profiles, const gchar *profile, + const gchar *color) +{ + g_key_file_set_string(profiles->key_file, profile, "color", color); +} + +gboolean +mq_profiles_save(MqProfiles *profiles) +{ + /* TODO: Handle GFileError? */ + return g_key_file_save_to_file(profiles->key_file, profiles->file_name, + NULL); +} diff --git a/src/config/profiles.h b/src/config/profiles.h new file mode 100644 index 0000000..0b0a465 --- /dev/null +++ b/src/config/profiles.h @@ -0,0 +1,56 @@ +/* + * Configuration/browsing profiles + * + * Copyright (C) 2017 Patrick McDermott + * + * This file is part of Marquee. + * + * Marquee is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Marquee is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Marquee. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef MQ_PROFILES_H +#define MQ_PROFILES_H + +typedef struct _MqProfiles MqProfiles; + +#include <glib.h> + +G_BEGIN_DECLS + +MqProfiles * +mq_profiles_new(void); + +gchar ** +mq_profiles_get_profiles(MqProfiles *profiles, gsize *length); + +gchar * +mq_profiles_get_name(MqProfiles *profiles, const gchar *profile); + +gchar * +mq_profiles_get_color(MqProfiles *profiles, const gchar *profile); + +void +mq_profiles_set_name(MqProfiles *profiles, const gchar *profile, + const gchar *name); + +void +mq_profiles_set_color(MqProfiles *profiles, const gchar *profile, + const gchar *color); + +gboolean +mq_profiles_save(MqProfiles *profiles); + +G_END_DECLS + +#endif /* MQ_PROFILES_H */ |