summaryrefslogtreecommitdiff
path: root/src/gui/panels/panel.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2016-03-09 18:04:49 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2016-03-09 18:04:49 (GMT)
commitdc8a2b19dbb32bfe49b1ff6640cc609238b392ca (patch)
tree2103c99baeb3b792bc82fc3db28bd16ecf72b70e /src/gui/panels/panel.c
parentf8f804cf7ff9a62404b843cf303c762101572784 (diff)
Stored and loaded panels attributes using the global configuration.
Diffstat (limited to 'src/gui/panels/panel.c')
-rw-r--r--src/gui/panels/panel.c147
1 files changed, 141 insertions, 6 deletions
diff --git a/src/gui/panels/panel.c b/src/gui/panels/panel.c
index 00a4eea..71fa155 100644
--- a/src/gui/panels/panel.c
+++ b/src/gui/panels/panel.c
@@ -26,9 +26,11 @@
#include <assert.h>
+#include <stdio.h>
#include "panel-int.h"
+#include "../../common/extstr.h"
#include "../../gtkext/gtkdockable-int.h"
@@ -51,6 +53,9 @@ static const char *gtk_panel_item_get_desc(const GPanelItem *);
/* Fournit le composant graphique intégrable dans un ensemble. */
static GtkWidget *gtk_panel_item_get_widget(GPanelItem *);
+/* Construit la chaîne d'accès à un élément de configuration. */
+static char *gtk_panel_item_build_configuration_key(const GPanelItem *, const char *);
+
/* Indique le type défini pour un élément destiné à un panneau. */
@@ -140,10 +145,11 @@ static void g_panel_item_dockable_interface_init(GtkDockableInterface *iface)
/******************************************************************************
* *
* Paramètres : personality = nature du panneau à mettre en place. *
-* name = nom associé à l'élément. *
-* lname = description longue du panneau. *
-* widget = composant à présenter à l'affichage. *
-* path = chemin vers la place idéale pour le futur panneau. *
+* name = nom associé à l'élément. *
+* lname = description longue du panneau. *
+* widget = composant à présenter à l'affichage. *
+* startup = chargement au démarrage ? *
+* path = chemin vers la place idéale pour le futur panneau. *
* *
* Description : Crée un élément de panneau réactif. *
* *
@@ -153,7 +159,7 @@ static void g_panel_item_dockable_interface_init(GtkDockableInterface *iface)
* *
******************************************************************************/
-GPanelItem *g_panel_item_new(PanelItemPersonality personality, const char *name, const char *lname, GtkWidget *widget, const char *path)
+GPanelItem *g_panel_item_new(PanelItemPersonality personality, const char *name, const char *lname, GtkWidget *widget, bool startup, const char *path)
{
GPanelItem *result; /* Structure à retourner */
GEditorItem *parent; /* Autre version de l'élément */
@@ -170,7 +176,8 @@ GPanelItem *g_panel_item_new(PanelItemPersonality personality, const char *name,
result->lname = lname;
- result->path = path;
+ result->dock_at_startup = startup;
+ result->path = strdup(path);
return result;
@@ -236,6 +243,134 @@ static GtkWidget *gtk_panel_item_get_widget(GPanelItem *item)
/******************************************************************************
* *
+* Paramètres : item = instance GTK à consulter. *
+* attrib = élément de configuration à inclure dans le résultat.*
+* *
+* Description : Construit la chaîne d'accès à un élément de configuration. *
+* *
+* Retour : Chaîne de caractères à libérer après usage. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static char *gtk_panel_item_build_configuration_key(const GPanelItem *item, const char *attrib)
+{
+ char *result; /* Construction à renvoyer */
+ const char *name; /* Nom court du panneau */
+
+ name = g_editor_item_get_name(G_EDITOR_ITEM(item));
+
+ asprintf(&result, "gui.panels.%s.%s", name, attrib);
+
+ result = strrpl(result, " ", "_");
+
+ result = strlower(result);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : item = instance GTK à consulter. *
+* config = configuration à compléter. *
+* *
+* Description : Met en place les bases de la configuration du panneau. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool gtk_panel_item_setup_configuration(const GPanelItem *item, GGenConfig *config)
+{
+ bool result; /* Bilan à retourner */
+ char *key; /* Clef d'accès à un paramètre */
+ GCfgParam *param; /* Paramètre chargé */
+
+ result = true;
+
+ key = gtk_panel_item_build_configuration_key(item, "dock_at_startup");
+
+ param = g_generic_config_create_param(config, key, CPT_BOOLEAN, item->dock_at_startup);
+
+ if (param == NULL)
+ {
+ result = false;
+ goto gpisc_exit;
+ }
+
+ free(key);
+
+ key = gtk_panel_item_build_configuration_key(item, "path");
+
+ param = g_generic_config_create_param(config, key, CPT_STRING, item->path);
+ if (param == NULL)
+ result = false;
+
+ gpisc_exit:
+
+ free(key);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : item = instance GTK à consulter. *
+* config = configuration à charger. *
+* *
+* Description : Charge un panneau sur les bases de la configuration fournie. *
+* *
+* Retour : true, par conformité avec browse_all_item_panels(). *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool gtk_panel_item_apply_configuration(GPanelItem *item, GGenConfig *config)
+{
+ char *key; /* Clef d'accès à un paramètre */
+ const char *new_path; /* Nouveau chemin de placement */
+ bool status; /* Statut de l'encapsulation */
+
+ key = gtk_panel_item_build_configuration_key(item, "path");
+
+ if (g_generic_config_get_value(config, key, &new_path))
+ {
+ free(item->path);
+
+ item->path = strdup(new_path);
+
+ }
+
+ free(key);
+
+ key = gtk_panel_item_build_configuration_key(item, "dock_at_startup");
+
+ if (g_generic_config_get_value(config, key, &status))
+ {
+ item->dock_at_startup = status;
+
+ if (item->dock_at_startup)
+ g_signal_emit_by_name(item, "dock-request");
+
+ }
+
+ free(key);
+
+ return true;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : item = instance GTK à consulter. *
* *
* Description : Fournit une indication sur la personnalité du panneau. *