[dia] information hiding: privatize Persistent* structs



commit 5323e2c8fa7a716e4f1f558ae26ba9ddc9a1ddea
Author: Hans Breuer <hans breuer org>
Date:   Sat Jan 8 16:24:27 2011 +0100

    information hiding: privatize Persistent* structs
    
    Just a single herlper function is necessary to remove
    two structs from an often included header.

 lib/diadynamicmenu.c |    7 +++----
 lib/persistence.c    |   38 +++++++++++++++++++++++++++++++++++++-
 lib/persistence.h    |   25 +++----------------------
 3 files changed, 43 insertions(+), 27 deletions(-)
---
diff --git a/lib/diadynamicmenu.c b/lib/diadynamicmenu.c
index 8223efb..2953e0c 100644
--- a/lib/diadynamicmenu.c
+++ b/lib/diadynamicmenu.c
@@ -414,11 +414,10 @@ void
 dia_dynamic_menu_reset(GtkWidget *item, gpointer userdata)
 {
   DiaDynamicMenu *ddm = DIA_DYNAMIC_MENU(userdata);
-  PersistentList *plist = persistent_list_get(ddm->persistent_name);
   gchar *active = dia_dynamic_menu_get_entry(ddm);
-  g_list_foreach(plist->glist, (GFunc)g_free, NULL);
-  g_list_free(plist->glist);
-  plist->glist = NULL;
+
+  persistent_list_clear(ddm->persistent_name);
+
   dia_dynamic_menu_create_menu(ddm);
   if (active)
     dia_dynamic_menu_select_entry(ddm, active);
diff --git a/lib/persistence.c b/lib/persistence.c
index fc950d9..6081431 100644
--- a/lib/persistence.c
+++ b/lib/persistence.c
@@ -39,6 +39,30 @@
 #include <gtk/gtk.h>
 #include <libxml/tree.h>
 
+/* private data structures */
+/** A persistently stored list of strings.
+ * The list contains no duplicates.
+ * If sorted is FALSE, any string added will be placed in front of the list
+ * (possibly removing it from further down), thus making it an LRU list.
+ * The list is not tied to any particular GTK widget, as it has uses
+ * in a number of different places (though mostly in menus)
+ */
+struct _PersistentList {
+  const gchar *role;
+  gboolean sorted;
+  gint max_members;
+  GList *glist;
+  GList *listeners;
+};
+
+/** Some storage windo information */
+typedef struct {
+  int x, y;
+  int width, height;
+  gboolean isopen;
+  GtkWindow *window;
+} PersistentWindow;
+
 /* Hash table from window role (string) to PersistentWindow structure.
  */
 static GHashTable *persistent_windows, *persistent_entrystrings, *persistent_lists;
@@ -736,7 +760,6 @@ persistence_register_string_entry(gchar *role, GtkWidget *entry)
 }
 
 /* ********* LISTS ********** */
-
 /* Lists are used for e.g. recent files, selected fonts, etc. 
  * Anywhere where the user occasionally picks from a long list and
  * is likely to reuse the items.
@@ -901,6 +924,19 @@ persistent_list_add_listener(const gchar *role, PersistenceCallback func,
   }
 }
 
+/**
+ * Empty the list
+ */
+void
+persistent_list_clear(const gchar *role)
+{
+  PersistentList *plist = persistent_list_get(role);
+
+  g_list_foreach(plist->glist, (GFunc)g_free, NULL);
+  g_list_free(plist->glist);
+  plist->glist = NULL;
+}
+
 /* ********* INTEGERS ********** */
 gint
 persistence_register_integer(gchar *role, int defaultvalue)
diff --git a/lib/persistence.h b/lib/persistence.h
index a21c9a4..5980a77 100644
--- a/lib/persistence.h
+++ b/lib/persistence.h
@@ -21,18 +21,10 @@
 
 #ifndef PERSISTENCE_H
 #define PERSISTENCE_H
-#include "config.h"
 #include "geometry.h"
 
 #include <gtk/gtk.h>
 
-typedef struct {
-  int x, y;
-  int width, height;
-  gboolean isopen;
-  GtkWindow *window;
-} PersistentWindow;
-
 typedef void (NullaryFunc)();
 
 void persistence_load(void);
@@ -43,20 +35,8 @@ void persistence_register_string_entry(gchar *role, GtkWidget *entry);
 gboolean persistence_change_string_entry(gchar *role, gchar *string,
 					 GtkWidget *widget);
 
-/** A persistently stored list of strings.
- * The list contains no duplicates.
- * If sorted is FALSE, any string added will be placed in front of the list
- * (possibly removing it from further down), thus making it an LRU list.
- * The list is not tied to any particular GTK widget, as it has uses
- * in a number of different places (though mostly in menus)
- */
-typedef struct _PersistentList {
-  const gchar *role;
-  gboolean sorted;
-  gint max_members;
-  GList *glist;
-  GList *listeners;
-} PersistentList;
+
+typedef struct _PersistentList PersistentList;
 
 typedef void (*PersistenceCallback)(GObject *, gpointer);
 
@@ -69,6 +49,7 @@ gboolean persistent_list_remove(const gchar *role, const gchar *item);
 void persistent_list_remove_all(const gchar *role);
 void persistent_list_add_listener(const gchar *role, PersistenceCallback func, 
 				  GObject *watch, gpointer userdata);
+void persistent_list_clear(const gchar *role);
 
 gboolean persistence_is_registered(gchar *role);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]