1 /* Dia -- an diagram creation/manipulation program
2  * Copyright (C) 2003 Lars Clausen
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  */
18 
19 /* persistence.h -- definitions for persistent storage.
20  */
21 
22 #ifndef PERSISTENCE_H
23 #define PERSISTENCE_H
24 #include "config.h"
25 #include "geometry.h"
26 
27 #include <gtk/gtk.h>
28 
29 typedef struct {
30   int x, y;
31   int width, height;
32   gboolean isopen;
33   GtkWindow *window;
34 } PersistentWindow;
35 
36 typedef void (NullaryFunc)();
37 
38 void persistence_load(void);
39 void persistence_save(void);
40 void persistence_register_window(GtkWindow *window);
41 void persistence_register_window_create(gchar *role, NullaryFunc *func);
42 void persistence_register_string_entry(gchar *role, GtkWidget *entry);
43 gboolean persistence_change_string_entry(gchar *role, gchar *string,
44 					 GtkWidget *widget);
45 
46 /** A persistently stored list of strings.
47  * The list contains no duplicates.
48  * If sorted is FALSE, any string added will be placed in front of the list
49  * (possibly removing it from further down), thus making it an LRU list.
50  * The list is not tied to any particular GTK widget, as it has uses
51  * in a number of different places (though mostly in menus)
52  */
53 typedef struct _PersistentList {
54   const gchar *role;
55   gboolean sorted;
56   gint max_members;
57   GList *glist;
58   GList *listeners;
59 } PersistentList;
60 
61 typedef void (*PersistenceCallback)(GObject *, gpointer);
62 
63 PersistentList *persistence_register_list(const gchar *role);
64 PersistentList *persistent_list_get(const gchar *role);
65 GList *persistent_list_get_glist(const gchar *role);
66 gboolean persistent_list_add(const gchar *role, const gchar *item);
67 void persistent_list_set_max_length(const gchar *role, gint max);
68 gboolean persistent_list_remove(const gchar *role, const gchar *item);
69 void persistent_list_remove_all(const gchar *role);
70 void persistent_list_add_listener(const gchar *role, PersistenceCallback func,
71 				  GObject *watch, gpointer userdata);
72 
73 gboolean persistence_is_registered(gchar *role);
74 
75 gint persistence_register_integer(gchar *role, int defaultvalue);
76 gint persistence_get_integer(gchar *role);
77 void persistence_set_integer(gchar *role, gint newvalue);
78 
79 real persistence_register_real(gchar *role, real defaultvalue);
80 real persistence_get_real(gchar *role);
81 void persistence_set_real(gchar *role, real newvalue);
82 
83 gboolean persistence_boolean_is_registered(const gchar *role);
84 gboolean persistence_register_boolean(const gchar *role, gboolean defaultvalue);
85 gboolean persistence_get_boolean(const gchar *role);
86 void persistence_set_boolean(const gchar *role, gboolean newvalue);
87 
88 gchar *persistence_register_string(gchar *role, gchar *defaultvalue);
89 gchar *persistence_get_string(gchar *role);
90 void persistence_set_string(gchar *role, const gchar *newvalue);
91 
92 Color *persistence_register_color(gchar *role, Color *defaultvalue);
93 Color *persistence_get_color(gchar *role);
94 void persistence_set_color(gchar *role, Color *newvalue);
95 
96 #endif
97