Use ~/.config to save and load preferences

This commit is contained in:
Pierre Pronchery 2021-02-21 17:45:05 +01:00
parent a263c7615f
commit 8efa57d525
2 changed files with 14 additions and 33 deletions

View File

@ -137,8 +137,6 @@ static void _panel_reset(Panel * panel, GdkRectangle * rect);
/* helpers */ /* helpers */
#include "helper.c" #include "helper.c"
static String * _config_get_filename(void);
/* public */ /* public */
/* panel_new */ /* panel_new */
@ -207,7 +205,6 @@ static int _new_config(Panel * panel)
size_t i; size_t i;
gint width; gint width;
gint height; gint height;
String * filename;
for(i = 0; i < sizeof(_panel_sizes) / sizeof(*_panel_sizes); i++) for(i = 0; i < sizeof(_panel_sizes) / sizeof(*_panel_sizes); i++)
{ {
@ -221,12 +218,10 @@ static int _new_config(Panel * panel)
} }
if((panel->config = config_new()) == NULL) if((panel->config = config_new()) == NULL)
return -1; return -1;
if((filename = _config_get_filename()) == NULL) if(config_load_preferences(panel->config, PANEL_CONFIG_VENDOR,
return -1; PACKAGE, PANEL_CONFIG_FILE) != 0)
if(config_load(panel->config, filename) != 0)
/* we can ignore this error */ /* we can ignore this error */
panel_error(NULL, _("Could not load configuration"), 1); panel_error(NULL, _("Could not load configuration"), 1);
string_delete(filename);
return 0; return 0;
} }
@ -651,14 +646,8 @@ static void _reset_on_idle_load(Panel * panel, PanelPosition position)
/* panel_save */ /* panel_save */
int panel_save(Panel * panel) int panel_save(Panel * panel)
{ {
int ret; return config_save_preferences_user(panel->config, PANEL_CONFIG_VENDOR,
String * filename; PACKAGE, PANEL_CONFIG_FILE);
if((filename = _config_get_filename()) == NULL)
return -1;
ret = config_save(panel->config, filename);
string_delete(filename);
return ret;
} }
@ -1399,17 +1388,6 @@ static void _preferences_on_panel_up(gpointer data)
/* private */ /* private */
/* functions */ /* functions */
/* config_get_filename */
static String * _config_get_filename(void)
{
char const * homedir;
if((homedir = getenv("HOME")) == NULL)
homedir = g_get_home_dir();
return string_new_format("%s/%s", homedir, PANEL_CONFIG_FILE);
}
/* accessors */ /* accessors */
/* panel_can_shutdown */ /* panel_can_shutdown */
static gboolean _panel_can_shutdown(void) static gboolean _panel_can_shutdown(void)

View File

@ -18,15 +18,17 @@
#ifndef PANEL_PANEL_H #ifndef PANEL_PANEL_H
# define PANEL_PANEL_H # define PANEL_PANEL_H
# include <gtk/gtk.h> # include <System/string.h>
# include <Desktop.h>
# include "../include/Panel/panel.h" # include "../include/Panel/panel.h"
# include "../config.h"
/* Panel */ /* Panel */
/* types */ /* types */
typedef struct _PanelPrefs typedef struct _PanelPrefs
{ {
char const * iconsize; String const * iconsize;
int monitor; int monitor;
} PanelPrefs; } PanelPrefs;
@ -34,7 +36,8 @@ typedef struct _PanelPrefs
/* constants */ /* constants */
# define PANEL_BORDER_WIDTH 4 # define PANEL_BORDER_WIDTH 4
# define PANEL_CONFIG_FILE ".panel" # define PANEL_CONFIG_FILE "Panel.conf"
# define PANEL_CONFIG_VENDOR "DeforaOS/" VENDOR
# define PANEL_ICON_SIZE_DEFAULT "panel-large" # define PANEL_ICON_SIZE_DEFAULT "panel-large"
# define PANEL_ICON_SIZE_UNSET NULL # define PANEL_ICON_SIZE_UNSET NULL
@ -48,12 +51,12 @@ Panel * panel_new(PanelPrefs const * prefs);
void panel_delete(Panel * panel); void panel_delete(Panel * panel);
/* accessors */ /* accessors */
char const * panel_get_config(Panel * panel, char const * section, String const * panel_get_config(Panel * panel, String const * section,
char const * variable); String const * variable);
/* useful */ /* useful */
int panel_error(Panel * panel, char const * message, int ret); int panel_error(Panel * panel, String const * message, int ret);
int panel_load(Panel * panel, PanelPosition position, char const * applet); int panel_load(Panel * panel, PanelPosition position, String const * applet);
int panel_reset(Panel * panel); int panel_reset(Panel * panel);
int panel_save(Panel * panel); int panel_save(Panel * panel);