• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

作図ソフト dia の改良版


Commit MetaInfo

Revision6d96da135d83ad049c7047e5e907df359b1c83f4 (tree)
Zeit2004-04-01 22:49:52
AutorLars Clausen <lclausen@src....>
CommiterLars Clausen

Log Message

More persistence. Yay!

Ändern Zusammenfassung

Diff

--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
1+2004-04-01 Lars Clausen <lars@raeder.dk>
2+
3+ * app/preferences.c: All preferences are now
4+ handled by persistence, old prefs load and store code is gone.
5+
6+ * lib/persistence.[ch]: Added string and color persistents. This is
7+ a different string from the one used in the printer dialog, that
8+ one has a GtkEntry attached -- may want to make that one an
9+ encapsulation of this one or something.
10+
111 2004-03-31 Lars Clausen <lars@raeder.dk>
212
313 * app/app_procs.c: Do persistence before prefs. Prefs are to be
--- a/app/preferences.c
+++ b/app/preferences.c
@@ -190,51 +190,6 @@ DiaPrefData prefs_data[] =
190190
191191 #define NUM_PREFS_DATA (sizeof(prefs_data)/sizeof(DiaPrefData))
192192
193-static const GScannerConfig dia_prefs_scanner_config =
194-{
195- (
196- " \t\n"
197- ) /* cset_skip_characters */,
198- (
199- G_CSET_a_2_z
200- "_"
201- G_CSET_A_2_Z
202- ) /* cset_identifier_first */,
203- (
204- G_CSET_a_2_z
205- "_-0123456789"
206- G_CSET_A_2_Z
207- ) /* cset_identifier_nth */,
208- ( "#\n" ) /* cpair_comment_single */,
209-
210- TRUE /* case_sensitive */,
211-
212- FALSE /* skip_comment_multi */,
213- TRUE /* skip_comment_single */,
214- FALSE /* scan_comment_multi */,
215- TRUE /* scan_identifier */,
216- TRUE /* scan_identifier_1char */,
217- FALSE /* scan_identifier_NULL */,
218- TRUE /* scan_symbols */,
219- FALSE /* scan_binary */,
220- FALSE /* scan_octal */,
221- TRUE /* scan_float */,
222- TRUE /* scan_hex */,
223- FALSE /* scan_hex_dollar */,
224- FALSE /* scan_string_sq */,
225- TRUE /* scan_string_dq */,
226- TRUE /* numbers_2_int */,
227- FALSE /* int_2_float */,
228- FALSE /* identifier_2_string */,
229- TRUE /* char_2_token */,
230- FALSE /* symbol_2_token */,
231- FALSE /* scope_0_fallback */,
232-};
233-
234-typedef enum {
235- DIA_PREFS_TOKEN_BOOLEAN = G_TOKEN_LAST
236-} DiaPrefsTokenType;
237-
238193 static void prefs_create_dialog(void);
239194 static void prefs_set_value_in_widget(GtkWidget * widget, DiaPrefData *data, char *ptr);
240195 static void prefs_get_value_from_widget(GtkWidget * widget, DiaPrefData *data, char *ptr);
@@ -271,20 +226,27 @@ prefs_set_defaults(void)
271226
272227 switch (prefs_data[i].type) {
273228 case PREF_BOOLEAN:
229+ *(int *)ptr = *(int *)prefs_data[i].default_value;
230+ *(int *)ptr = persistence_register_boolean(prefs_data[i].name, *(int *)ptr);
231+ break;
274232 case PREF_INT:
275233 case PREF_UINT:
276234 *(int *)ptr = *(int *)prefs_data[i].default_value;
235+ *(int *)ptr = persistence_register_integer(prefs_data[i].name, *(int *)ptr);
277236 break;
278237 case PREF_REAL:
279238 case PREF_UREAL:
280239 *(real *)ptr = *(real *)prefs_data[i].default_value;
240+ *(real *)ptr = persistence_register_real(prefs_data[i].name, *(real *)ptr);
281241 break;
282242 case PREF_COLOUR:
283243 *(Color *)ptr = *(Color *)prefs_data[i].default_value;
244+ *(Color *)ptr = *persistence_register_color(prefs_data[i].name, (Color *)ptr);
284245 break;
285246 case PREF_CHOICE:
286247 case PREF_STRING:
287248 *(gchar **)ptr = *(gchar **)prefs_data[i].default_value;
249+ *(gchar **)ptr = persistence_register_string(prefs_data[i].name, *(gchar **)ptr);
288250 break;
289251 case PREF_NONE:
290252 case PREF_END_GROUP:
@@ -298,213 +260,46 @@ prefs_save(void)
298260 {
299261 int i;
300262 char *ptr;
301- gchar *filename;
302- char *old_locale;
303- FILE *file;
304-
305- filename = dia_config_filename("diarc");
306-
307- file = fopen(filename, "w");
308-
309- if (!file) {
310- message_error(_("Could not open `%s' for writing"), filename);
311- g_free(filename);
312- return;
313- }
314-
315- g_free(filename);
316-
317- old_locale = setlocale(LC_NUMERIC, "C");
318- fprintf(file, "# Note: This file is automatically generated by Dia\n");
319263 for (i=0;i<NUM_PREFS_DATA;i++) {
320264 if ((prefs_data[i].type == PREF_NONE) || (prefs_data[i].type == PREF_END_GROUP))
321265 continue;
322266
323- fprintf(file, "%s=", prefs_data[i].name);
324-
325267 ptr = (char *)&prefs + prefs_data[i].offset;
326268
327269 switch (prefs_data[i].type) {
328270 case PREF_BOOLEAN:
329- fprintf(file, (*(int *)ptr)?"true\n":"false\n");
330271 persistence_set_boolean(prefs_data[i].name, *(gint *)ptr);
331272 break;
332273 case PREF_INT:
333274 case PREF_UINT:
334- fprintf(file, "%d\n", *(int *)ptr);
335275 persistence_set_integer(prefs_data[i].name, *(gint *)ptr);
336276 break;
337277 case PREF_REAL:
338278 case PREF_UREAL:
339279
340- fprintf(file, "%f\n", (double) *(real *)ptr);
341280 persistence_set_real(prefs_data[i].name, *(real *)ptr);
342281 break;
343282 case PREF_COLOUR:
344- fprintf(file, "%f %f %f\n", (double) ((Color *)ptr)->red,
345- (double) ((Color *)ptr)->green, (double) ((Color *)ptr)->blue);
283+ persistence_set_color(prefs_data[i].name, (Color *)ptr);
346284 break;
347285 case PREF_CHOICE:
348286 case PREF_STRING:
349- fprintf(file, "\"%s\"\n", *(gchar **)ptr);
287+ persistence_set_string(prefs_data[i].name, *(gchar **)ptr);
350288 break;
351289 case PREF_NONE:
352290 case PREF_END_GROUP:
353291 break;
354292 }
355293 }
356- setlocale(LC_NUMERIC, old_locale);
357- fclose(file);
358294 }
359295
360296
361-static guint
362-prefs_parse_line(GScanner *scanner)
363-{
364- guint token;
365- int symbol_nr;
366- char *ptr;
367-
368- token = g_scanner_get_next_token(scanner);
369- if (token != G_TOKEN_SYMBOL)
370- return G_TOKEN_SYMBOL;
371-
372- symbol_nr = GPOINTER_TO_INT(scanner->value.v_symbol);
373-
374- token = g_scanner_get_next_token(scanner);
375- if (token != G_TOKEN_EQUAL_SIGN)
376- return G_TOKEN_EQUAL_SIGN;
377-
378- token = g_scanner_get_next_token(scanner);
379-
380- ptr = (unsigned char *)&prefs + prefs_data[symbol_nr].offset;
381-
382- switch (prefs_data[symbol_nr].type) {
383- case PREF_BOOLEAN:
384- if (token != G_TOKEN_IDENTIFIER)
385- return G_TOKEN_IDENTIFIER;
386-
387- if (strcmp(scanner->value.v_string, "true")==0)
388- *(int *)ptr = 1;
389- else
390- *(int *)ptr = 0;
391- persistence_register_boolean(prefs_data[symbol_nr].name, *(int *)ptr);
392- break;
393-
394- case PREF_INT:
395- case PREF_UINT:
396- if (token != G_TOKEN_INT)
397- return G_TOKEN_INT;
398-
399- *(int *)ptr = scanner->value.v_int;
400- persistence_register_integer(prefs_data[symbol_nr].name, *(int *)ptr);
401- break;
402-
403- case PREF_REAL:
404- case PREF_UREAL:
405- if (token != G_TOKEN_FLOAT)
406- return G_TOKEN_FLOAT;
407-
408- *(real *)ptr = scanner->value.v_float;
409- printf("Real is %f\n", scanner->value.v_float);
410- persistence_register_real(prefs_data[symbol_nr].name, scanner->value.v_float);
411- break;
412- case PREF_COLOUR:
413- if (token != G_TOKEN_FLOAT)
414- return G_TOKEN_FLOAT;
415- ((Color *)ptr)->red = scanner->value.v_float;
416-
417- token = g_scanner_get_next_token(scanner);
418- if (token != G_TOKEN_FLOAT)
419- return G_TOKEN_FLOAT;
420- ((Color *)ptr)->green = scanner->value.v_float;
421-
422- token = g_scanner_get_next_token(scanner);
423- if (token != G_TOKEN_FLOAT)
424- return G_TOKEN_FLOAT;
425- ((Color *)ptr)->blue = scanner->value.v_float;
426-
427- break;
428- case PREF_CHOICE:
429- case PREF_STRING:
430- if (token != G_TOKEN_STRING)
431- return G_TOKEN_STRING;
432-
433- *(char **)ptr = g_strdup(scanner->value.v_string);
434- break;
435- case PREF_NONE:
436- case PREF_END_GROUP:
437- break;
438- }
439-
440- return G_TOKEN_NONE;
441-}
442-
443297
444298 void
445299 prefs_load(void)
446300 {
447- int i;
448- gchar *filename;
449- int fd;
450- GScanner *scanner;
451- guint expected_token;
452-
453- filename = dia_config_filename("diarc");
454-
455- fd = open(filename, O_RDONLY);
456-
457- if (fd < 0) {
458- const gchar *homedir = g_get_home_dir();
459-
460- g_free(filename);
461- filename = g_strconcat(homedir, G_DIR_SEPARATOR_S ".diarc", NULL);
462- fd = open(filename, O_RDONLY);
463- }
464- g_free(filename);
465-
466301 prefs_set_defaults();
467302
468- if (fd < 0) {
469- return;
470- }
471-
472- scanner = g_scanner_new ((GScannerConfig *) &dia_prefs_scanner_config);
473-
474- g_scanner_input_file (scanner, fd);
475-
476- scanner->input_name = filename;
477- for (i = 0; i < NUM_PREFS_DATA; i++)
478- if (prefs_data[i].name != NULL) {
479- g_scanner_add_symbol(scanner, prefs_data[i].name,
480- GINT_TO_POINTER(i));
481- }
482- while (1) {
483- if (g_scanner_peek_next_token(scanner) == G_TOKEN_EOF) {
484- break;
485- }
486-
487- expected_token = prefs_parse_line(scanner);
488-
489- if (expected_token != G_TOKEN_NONE) {
490- gchar *symbol_name;
491- gchar *msg;
492-
493- msg = NULL;
494- symbol_name = NULL;
495- g_scanner_unexp_token (scanner,
496- expected_token,
497- NULL,
498- "keyword",
499- symbol_name,
500- msg,
501- TRUE);
502- }
503- }
504-
505- g_scanner_destroy (scanner);
506-
507- close(fd);
508303 render_bounding_boxes = prefs.render_bounding_boxes;
509304 }
510305
@@ -561,8 +356,7 @@ prefs_get_value_from_widget(GtkWidget * widget, DiaPrefData *data,
561356 break;
562357 case PREF_INT:
563358 case PREF_UINT:
564- *((int *)ptr) =
565- gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
359+ *((int *)ptr) = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
566360 break;
567361 case PREF_REAL:
568362 case PREF_UREAL:
@@ -579,8 +373,7 @@ prefs_get_value_from_widget(GtkWidget * widget, DiaPrefData *data,
579373 break;
580374 }
581375 case PREF_STRING:
582- *((gchar **)ptr) = (gchar *)
583- gtk_entry_get_text(GTK_ENTRY(widget));
376+ *((gchar **)ptr) = (gchar *)gtk_entry_get_text(GTK_ENTRY(widget));
584377 break;
585378 case PREF_NONE:
586379 case PREF_END_GROUP:
--- a/lib/persistence.c
+++ b/lib/persistence.c
@@ -40,9 +40,10 @@
4040
4141 /* Hash table from window role (string) to PersistentWindow structure.
4242 */
43-static GHashTable *persistent_windows, *persistent_strings, *persistent_lists;
43+static GHashTable *persistent_windows, *persistent_entrystrings, *persistent_lists;
4444 static GHashTable *persistent_integers, *persistent_reals;
45-static GHashTable *persistent_booleans, *persistent_enums;
45+static GHashTable *persistent_booleans, *persistent_strings;
46+static GHashTable *persistent_colors;
4647
4748 /* *********************** LOADING FUNCTIONS *********************** */
4849
@@ -75,7 +76,7 @@ persistence_load_window(gchar *role, xmlNodePtr node)
7576
7677 /** Load a persistent string into the strings hashtable */
7778 static void
78-persistence_load_string(gchar *role, xmlNodePtr node)
79+persistence_load_entrystring(gchar *role, xmlNodePtr node)
7980 {
8081 AttributeNode attr;
8182 gchar *string = NULL;
@@ -88,7 +89,7 @@ persistence_load_string(gchar *role, xmlNodePtr node)
8889 return;
8990
9091 if (string != NULL)
91- g_hash_table_insert(persistent_strings, role, string);
92+ g_hash_table_insert(persistent_entrystrings, role, string);
9293 }
9394
9495 static void
@@ -182,6 +183,45 @@ persistence_load_boolean(gchar *role, xmlNodePtr node)
182183 printf("Boolean %s registered before loading persistence!\n", role);
183184 }
184185
186+static void
187+persistence_load_string(gchar *role, xmlNodePtr node)
188+{
189+ AttributeNode attr;
190+ gchar *stringval;
191+
192+ /* Find the contents? */
193+ attr = composite_find_attribute(node, "stringvalue");
194+ if (attr != NULL) {
195+ stringval = data_string(attribute_first_data(attr));
196+ } else
197+ return;
198+
199+ if (g_hash_table_lookup(persistent_strings, role) == NULL)
200+ g_hash_table_insert(persistent_strings, role, stringval);
201+ else
202+ printf("String %s registered before loading persistence!\n", role);
203+}
204+
205+static void
206+persistence_load_color(gchar *role, xmlNodePtr node)
207+{
208+ AttributeNode attr;
209+ Color *colorval;
210+
211+ /* Find the contents? */
212+ attr = composite_find_attribute(node, "colorvalue");
213+ if (attr != NULL) {
214+ colorval = g_new(Color, 1);
215+ data_color(attribute_first_data(attr), colorval);
216+ } else
217+ return;
218+
219+ if (g_hash_table_lookup(persistent_colors, role) == NULL)
220+ g_hash_table_insert(persistent_colors, role, colorval);
221+ else
222+ printf("Color %s registered before loading persistence!\n", role);
223+}
224+
185225 static xmlNodePtr
186226 find_node_named (xmlNodePtr p, const char *name)
187227 {
@@ -229,17 +269,19 @@ static void
229269 persistence_init()
230270 {
231271 persistence_set_type_handler("window", persistence_load_window);
232- persistence_set_type_handler("entrystring", persistence_load_string);
272+ persistence_set_type_handler("entrystring", persistence_load_entrystring);
233273 persistence_set_type_handler("list", persistence_load_list);
234274 persistence_set_type_handler("integer", persistence_load_integer);
235275 persistence_set_type_handler("real", persistence_load_real);
236276 persistence_set_type_handler("boolean", persistence_load_boolean);
277+ persistence_set_type_handler("string", persistence_load_string);
278+ persistence_set_type_handler("color", persistence_load_color);
237279
238280 if (persistent_windows == NULL) {
239281 persistent_windows = g_hash_table_new(g_str_hash, g_str_equal);
240282 }
241- if (persistent_strings == NULL) {
242- persistent_strings = g_hash_table_new(g_str_hash, g_str_equal);
283+ if (persistent_entrystrings == NULL) {
284+ persistent_entrystrings = g_hash_table_new(g_str_hash, g_str_equal);
243285 }
244286 if (persistent_lists == NULL) {
245287 persistent_lists = g_hash_table_new(g_str_hash, g_str_equal);
@@ -253,6 +295,12 @@ persistence_init()
253295 if (persistent_booleans == NULL) {
254296 persistent_booleans = g_hash_table_new(g_str_hash, g_str_equal);
255297 }
298+ if (persistent_strings == NULL) {
299+ persistent_strings = g_hash_table_new(g_str_hash, g_str_equal);
300+ }
301+ if (persistent_colors == NULL) {
302+ persistent_colors = g_hash_table_new(g_str_hash, g_str_equal);
303+ }
256304 }
257305
258306 /* Load all persistent data. */
@@ -306,18 +354,6 @@ persistence_save_window(gpointer key, gpointer value, gpointer data)
306354
307355 /* Save the contents of a string */
308356 static void
309-persistence_save_string(gpointer key, gpointer value, gpointer data)
310-{
311- xmlNodePtr tree = (xmlNodePtr)data;
312- ObjectNode stringnode;
313-
314- stringnode = (ObjectNode)xmlNewChild(tree, NULL, "entrystring", NULL);
315-
316- xmlSetProp(stringnode, "role", (char *)key);
317- data_add_string(new_attribute(stringnode, "stringvalue"), (char *)value);
318-}
319-
320-static void
321357 persistence_save_list(gpointer key, gpointer value, gpointer data)
322358 {
323359 xmlNodePtr tree = (xmlNodePtr)data;
@@ -342,6 +378,18 @@ persistence_save_list(gpointer key, gpointer value, gpointer data)
342378 }
343379
344380 static void
381+persistence_save_entrystring(gpointer key, gpointer value, gpointer data)
382+{
383+ xmlNodePtr tree = (xmlNodePtr)data;
384+ ObjectNode stringnode;
385+
386+ stringnode = (ObjectNode)xmlNewChild(tree, NULL, "entrystring", NULL);
387+
388+ xmlSetProp(stringnode, "role", (char *)key);
389+ data_add_string(new_attribute(stringnode, "stringvalue"), (char *)value);
390+}
391+
392+static void
345393 persistence_save_integer(gpointer key, gpointer value, gpointer data)
346394 {
347395 xmlNodePtr tree = (xmlNodePtr)data;
@@ -377,6 +425,30 @@ persistence_save_boolean(gpointer key, gpointer value, gpointer data)
377425 data_add_boolean(new_attribute(booleannode, "booleanvalue"), *(gboolean *)value);
378426 }
379427
428+static void
429+persistence_save_string(gpointer key, gpointer value, gpointer data)
430+{
431+ xmlNodePtr tree = (xmlNodePtr)data;
432+ ObjectNode stringnode;
433+
434+ stringnode = (ObjectNode)xmlNewChild(tree, NULL, "string", NULL);
435+
436+ xmlSetProp(stringnode, "role", (char *)key);
437+ data_add_string(new_attribute(stringnode, "stringvalue"), (gchar *)value);
438+}
439+
440+static void
441+persistence_save_color(gpointer key, gpointer value, gpointer data)
442+{
443+ xmlNodePtr tree = (xmlNodePtr)data;
444+ ObjectNode colornode;
445+
446+ colornode = (ObjectNode)xmlNewChild(tree, NULL, "color", NULL);
447+
448+ xmlSetProp(colornode, "role", (char *)key);
449+ data_add_color(new_attribute(colornode, "colorvalue"), (Color *)value);
450+}
451+
380452
381453 void
382454 persistence_save_type(xmlDocPtr doc, GHashTable *entries, GHFunc func)
@@ -403,18 +475,14 @@ persistence_save()
403475 "dia");
404476 xmlSetNs(doc->xmlRootNode, name_space);
405477
406- printf("Saving windows\n");
407478 persistence_save_type(doc, persistent_windows, persistence_save_window);
408- printf("Saving strings\n");
409- persistence_save_type(doc, persistent_strings, persistence_save_string);
410- printf("Saving lists\n");
479+ persistence_save_type(doc, persistent_entrystrings, persistence_save_string);
411480 persistence_save_type(doc, persistent_lists, persistence_save_list);
412- printf("Saving integers\n");
413481 persistence_save_type(doc, persistent_integers, persistence_save_integer);
414- printf("Saving reals\n");
415482 persistence_save_type(doc, persistent_reals, persistence_save_real);
416- printf("Saving booleans\n");
417483 persistence_save_type(doc, persistent_booleans, persistence_save_boolean);
484+ persistence_save_type(doc, persistent_strings, persistence_save_string);
485+ persistence_save_type(doc, persistent_colors, persistence_save_color);
418486
419487 xmlDiaSaveFile(filename, doc);
420488 g_free(filename);
@@ -559,10 +627,10 @@ persistence_update_string_entry(GtkWidget *widget, GdkEvent *event,
559627 gchar *role = (gchar*)userdata;
560628
561629 if (event->type == GDK_FOCUS_CHANGE) {
562- gchar *string = (gchar *)g_hash_table_lookup(persistent_strings, role);
630+ gchar *string = (gchar *)g_hash_table_lookup(persistent_entrystrings, role);
563631 gchar *entrystring = gtk_entry_get_text(GTK_ENTRY(widget));
564632 if (string == NULL || strcmp(string, entrystring)) {
565- g_hash_table_insert(persistent_strings, role, g_strdup(entrystring));
633+ g_hash_table_insert(persistent_entrystrings, role, g_strdup(entrystring));
566634 if (string != NULL) g_free(string);
567635 }
568636 }
@@ -579,12 +647,12 @@ gboolean
579647 persistence_change_string_entry(gchar *role, gchar *string,
580648 GtkWidget *widget)
581649 {
582- gchar *old_string = (gchar*)g_hash_table_lookup(persistent_strings, role);
650+ gchar *old_string = (gchar*)g_hash_table_lookup(persistent_entrystrings, role);
583651 if (old_string != NULL) {
584652 if (widget != NULL) {
585653 gtk_entry_set_text(GTK_ENTRY(widget), string);
586654 }
587- g_hash_table_insert(persistent_strings, role, g_strdup(string));
655+ g_hash_table_insert(persistent_entrystrings, role, g_strdup(string));
588656 g_free(old_string);
589657 }
590658
@@ -600,15 +668,15 @@ persistence_register_string_entry(gchar *role, GtkWidget *entry)
600668 {
601669 gchar *string;
602670 if (role == NULL) return;
603- if (persistent_strings == NULL) {
604- persistent_strings = g_hash_table_new(g_str_hash, g_str_equal);
671+ if (persistent_entrystrings == NULL) {
672+ persistent_entrystrings = g_hash_table_new(g_str_hash, g_str_equal);
605673 }
606- string = (gchar *)g_hash_table_lookup(persistent_strings, role);
674+ string = (gchar *)g_hash_table_lookup(persistent_entrystrings, role);
607675 if (string != NULL) {
608676 gtk_entry_set_text(GTK_ENTRY(entry), string);
609677 } else {
610678 string = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry)));
611- g_hash_table_insert(persistent_strings, role, string);
679+ g_hash_table_insert(persistent_entrystrings, role, string);
612680 }
613681 g_signal_connect(G_OBJECT(entry), "event",
614682 G_CALLBACK(persistence_update_string_entry), role);
@@ -626,7 +694,6 @@ persistence_register_list(const gchar *role)
626694 {
627695 PersistentList *list;
628696 if (role == NULL) return NULL;
629- printf("Registering %s\n", role);
630697 if (persistent_lists == NULL) {
631698 persistent_lists = g_hash_table_new(g_str_hash, g_str_equal);
632699 } else {
@@ -794,7 +861,7 @@ persistence_get_real(gchar *role)
794861 realval = (real *)g_hash_table_lookup(persistent_reals, role);
795862 if (realval != NULL) return *realval;
796863 printf("No real to get for %s\n", role);
797- return 0;
864+ return 0.0;
798865 }
799866
800867 void
@@ -806,7 +873,6 @@ persistence_set_real(gchar *role, real newvalue)
806873 return;
807874 }
808875 realval = (real *)g_hash_table_lookup(persistent_reals, role);
809- printf("Setting real %s to %f\n", role, newvalue);
810876 if (realval != NULL) *realval = newvalue;
811877 else printf("No real to set for %s\n", role);
812878 }
@@ -841,7 +907,7 @@ persistence_get_boolean(gchar *role)
841907 booleanval = (gboolean *)g_hash_table_lookup(persistent_booleans, role);
842908 if (booleanval != NULL) return *booleanval;
843909 printf("No boolean to get for %s\n", role);
844- return 0;
910+ return FALSE;
845911 }
846912
847913 void
@@ -853,7 +919,100 @@ persistence_set_boolean(gchar *role, gboolean newvalue)
853919 return;
854920 }
855921 booleanval = (gboolean *)g_hash_table_lookup(persistent_booleans, role);
856- printf("Setting boolean %s to %d\n", role, newvalue);
857922 if (booleanval != NULL) *booleanval = newvalue;
858923 else printf("No boolean to set for %s\n", role);
859924 }
925+
926+/* ********* STRINGS ********** */
927+gchar *
928+persistence_register_string(gchar *role, gchar *defaultvalue)
929+{
930+ gchar *stringval;
931+ if (role == NULL) return 0;
932+ if (persistent_strings == NULL) {
933+ persistent_strings = g_hash_table_new(g_str_hash, g_str_equal);
934+ }
935+ stringval = (gchar *)g_hash_table_lookup(persistent_strings, role);
936+ if (stringval == NULL) {
937+ stringval = g_strdup(defaultvalue);
938+ g_hash_table_insert(persistent_strings, role, stringval);
939+ }
940+ return stringval;
941+}
942+
943+gchar *
944+persistence_get_string(gchar *role)
945+{
946+ gchar *stringval;
947+ if (persistent_strings == NULL) {
948+ printf("No persistent strings to get for %s!\n", role);
949+ return 0;
950+ }
951+ stringval = (gchar *)g_hash_table_lookup(persistent_strings, role);
952+ if (stringval != NULL) return stringval;
953+ printf("No string to get for %s\n", role);
954+ return NULL;
955+}
956+
957+void
958+persistence_set_string(gchar *role, gchar *newvalue)
959+{
960+ gchar *stringval;
961+ if (persistent_strings == NULL) {
962+ printf("No persistent strings yet for %s!\n", role);
963+ return;
964+ }
965+ stringval = (gchar *)g_hash_table_lookup(persistent_strings, role);
966+ if (stringval != NULL) {
967+ g_hash_table_insert(persistent_strings, role, g_strdup(newvalue));
968+ g_free(stringval);
969+ }
970+ else printf("No string to set for %s\n", role);
971+}
972+
973+/* ********* COLORS ********** */
974+/* Remember that colors returned are private, not to be deallocated.
975+ * They will be smashed in some undefined way by persistence_set_color */
976+Color *
977+persistence_register_color(gchar *role, Color *defaultvalue)
978+{
979+ Color *colorval;
980+ if (role == NULL) return 0;
981+ if (persistent_colors == NULL) {
982+ persistent_colors = g_hash_table_new(g_str_hash, g_str_equal);
983+ }
984+ colorval = (Color *)g_hash_table_lookup(persistent_colors, role);
985+ if (colorval == NULL) {
986+ colorval = g_new(Color, 1);
987+ *colorval = *defaultvalue;
988+ g_hash_table_insert(persistent_colors, role, colorval);
989+ }
990+ return colorval;
991+}
992+
993+Color *
994+persistence_get_color(gchar *role)
995+{
996+ Color *colorval;
997+ if (persistent_colors == NULL) {
998+ printf("No persistent colors to get for %s!\n", role);
999+ return 0;
1000+ }
1001+ colorval = (Color *)g_hash_table_lookup(persistent_colors, role);
1002+ if (colorval != NULL) return colorval;
1003+ printf("No color to get for %s\n", role);
1004+ return 0;
1005+}
1006+
1007+void
1008+persistence_set_color(gchar *role, Color *newvalue)
1009+{
1010+ Color *colorval;
1011+ if (persistent_colors == NULL) {
1012+ printf("No persistent colors yet for %s!\n", role);
1013+ return;
1014+ }
1015+ colorval = (Color *)g_hash_table_lookup(persistent_colors, role);
1016+ if (colorval != NULL) *colorval = *newvalue;
1017+ else printf("No color to set for %s\n", role);
1018+}
--- a/lib/persistence.h
+++ b/lib/persistence.h
@@ -77,4 +77,12 @@ gboolean persistence_register_boolean(gchar *role, gboolean defaultvalue);
7777 gboolean persistence_get_boolean(gchar *role);
7878 void persistence_set_boolean(gchar *role, gboolean newvalue);
7979
80+gchar *persistence_register_string(gchar *role, gchar *defaultvalue);
81+gchar *persistence_get_string(gchar *role);
82+void persistence_set_string(gchar *role, gchar *newvalue);
83+
84+Color *persistence_register_color(gchar *role, Color *defaultvalue);
85+Color *persistence_get_color(gchar *role);
86+void persistence_set_color(gchar *role, Color *newvalue);
87+
8088 #endif