33 |
|
|
34 |
preferencestype preferences; |
preferencestype preferences; |
35 |
extern gchar *xlogdir; |
extern gchar *xlogdir; |
36 |
|
#define PREFERENCES_VERSION 1 |
37 |
|
gboolean newprefsfile = FALSE; |
38 |
|
|
39 |
|
static void make_default_preferences (void) |
40 |
|
{ |
41 |
|
GString *sdir = g_string_new (""); |
42 |
|
|
43 |
|
preferences.version = 0; |
44 |
|
preferences.x = 10; |
45 |
|
preferences.y = 30; |
46 |
|
preferences.width = 750; |
47 |
|
preferences.height = 540; |
48 |
|
preferences.latitude = 0.0; |
49 |
|
preferences.NS = 1; |
50 |
|
preferences.longitude = 0.0; |
51 |
|
preferences.EW = 1; |
52 |
|
preferences.units = 1; |
53 |
|
preferences.bands = g_strdup ("1.8,3.5,7,10,14,18,21,24,28"); |
54 |
|
preferences.modes = g_strdup ("CW,SSB,PSK31,MFSK,MT63,SSTV"); |
55 |
|
preferences.bandseditbox = 0; |
56 |
|
preferences.modeseditbox = 0; |
57 |
|
preferences.bandoptionmenu = 0; |
58 |
|
preferences.modeoptionmenu = 0; |
59 |
|
preferences.printall = 0; |
60 |
|
preferences.printsize = 0; |
61 |
|
preferences.printpoint = 0; |
62 |
|
preferences.printorientation = 0; |
63 |
|
preferences.printdestination = 0; |
64 |
|
preferences.hamlib = 0; |
65 |
|
preferences.radio = g_strdup ("Dummy"); |
66 |
|
preferences.device = g_strdup ("/dev/ttyS1"); |
67 |
|
preferences.rigconf = g_strdup ("?"); |
68 |
|
preferences.round = 3; |
69 |
|
preferences.polltime = 0; |
70 |
|
preferences.clock = 0; |
71 |
|
preferences.themecolor = g_strdup ("blue"); |
72 |
|
preferences.themefont = g_strdup ("Sans 10"); |
73 |
|
preferences.logcolor = 1; |
74 |
|
preferences.autosave = 5; |
75 |
|
g_string_printf (sdir, "%s.", G_DIR_SEPARATOR_S); |
76 |
|
g_string_append (sdir, PACKAGE); |
77 |
|
preferences.savedir = g_strconcat (g_get_home_dir (), sdir->str, NULL); |
78 |
|
g_string_free (sdir, TRUE); |
79 |
|
preferences.saving = 1; |
80 |
|
preferences.logstoload = g_strdup ("*"); |
81 |
|
preferences.locator = g_strdup ("AA00AA"); |
82 |
|
preferences.freefield1 = g_strdup ("UNKNOWN"); |
83 |
|
preferences.freefield2 = g_strdup ("UNKNOWN"); |
84 |
|
preferences.callsign = g_strdup ("N0CALL"); |
85 |
|
preferences.defaultmhz = g_strdup ("?"); |
86 |
|
preferences.defaultmode = g_strdup ("?"); |
87 |
|
preferences.defaulttxrst = g_strdup ("?"); |
88 |
|
preferences.defaultrxrst = g_strdup ("?"); |
89 |
|
preferences.defaultpower = g_strdup ("?"); |
90 |
|
preferences.defaultfreefield1 = g_strdup ("?"); |
91 |
|
preferences.defaultfreefield2 = g_strdup ("?"); |
92 |
|
preferences.defaultremarks = g_strdup ("?"); |
93 |
|
preferences.b4columns = g_strdup ("1,1,1,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0"); |
94 |
|
preferences.logcwidths = g_strdup ("50,100,50,50,100,50,50,50,50,50,50,50,100,100,100,100,100,200"); |
95 |
|
preferences.typeaheadfind = 1; |
96 |
|
preferences.remoteadding = 1; |
97 |
|
preferences.viewtoolbar = 1; |
98 |
|
preferences.viewb4 = 0; |
99 |
|
preferences.b4x = 10; |
100 |
|
preferences.b4y = 30; |
101 |
|
preferences.b4width = 500; |
102 |
|
preferences.b4height = 300; |
103 |
|
} |
104 |
|
|
105 |
void |
void |
106 |
parseloadpreferences (xmlDocPtr p, xmlNodePtr cur) |
parseloadpreferences (xmlDocPtr p, xmlNodePtr cur) |
109 |
cur = cur->xmlChildrenNode; |
cur = cur->xmlChildrenNode; |
110 |
while (cur != NULL) |
while (cur != NULL) |
111 |
{ |
{ |
112 |
|
if ((!xmlStrcmp(cur->name, (const xmlChar *)"version"))) |
113 |
|
{ |
114 |
|
key = xmlNodeListGetString (p, cur->xmlChildrenNode, 1); |
115 |
|
preferences.version = atoi (key); |
116 |
|
xmlFree (key); |
117 |
|
} |
118 |
if ((!xmlStrcmp(cur->name, (const xmlChar *)"x"))) |
if ((!xmlStrcmp(cur->name, (const xmlChar *)"x"))) |
119 |
{ |
{ |
120 |
key = xmlNodeListGetString (p, cur->xmlChildrenNode, 1); |
key = xmlNodeListGetString (p, cur->xmlChildrenNode, 1); |
397 |
preferences.b4columns = g_strdup (key); |
preferences.b4columns = g_strdup (key); |
398 |
xmlFree (key); |
xmlFree (key); |
399 |
} |
} |
400 |
|
else if ((!xmlStrcmp(cur->name, (const xmlChar *)"logcwidths"))) |
401 |
|
{ |
402 |
|
key = xmlNodeListGetString (p, cur->xmlChildrenNode, 1); |
403 |
|
preferences.logcwidths = g_strdup (key); |
404 |
|
xmlFree (key); |
405 |
|
} |
406 |
else if ((!xmlStrcmp(cur->name, (const xmlChar *)"typeaheadfind"))) |
else if ((!xmlStrcmp(cur->name, (const xmlChar *)"typeaheadfind"))) |
407 |
{ |
{ |
408 |
key = xmlNodeListGetString (p, cur->xmlChildrenNode, 1); |
key = xmlNodeListGetString (p, cur->xmlChildrenNode, 1); |
463 |
|
|
464 |
for (node = cur->children; node != NULL; node = node->next) |
for (node = cur->children; node != NULL; node = node->next) |
465 |
{ |
{ |
466 |
|
if (!strcmp (node->name, "version")) |
467 |
|
{ |
468 |
|
key = g_strdup_printf ("%d", PREFERENCES_VERSION); |
469 |
|
xmlNodeSetContent (node, key); |
470 |
|
g_free (key); |
471 |
|
} |
472 |
if (!strcmp (node->name, "x")) |
if (!strcmp (node->name, "x")) |
473 |
{ |
{ |
474 |
key = g_strdup_printf ("%d", preferences.x); |
key = g_strdup_printf ("%d", preferences.x); |
751 |
xmlNodeSetContent (node, key); |
xmlNodeSetContent (node, key); |
752 |
g_free (key); |
g_free (key); |
753 |
} |
} |
754 |
|
else if (!strcmp (node->name, "logcwidths")) |
755 |
|
{ |
756 |
|
key = g_strdup (preferences.logcwidths); |
757 |
|
xmlNodeSetContent (node, key); |
758 |
|
g_free (key); |
759 |
|
} |
760 |
else if (!strcmp (node->name, "typeaheadfind")) |
else if (!strcmp (node->name, "typeaheadfind")) |
761 |
{ |
{ |
762 |
key = g_strdup_printf ("%d", preferences.typeaheadfind); |
key = g_strdup_printf ("%d", preferences.typeaheadfind); |
808 |
} |
} |
809 |
} |
} |
810 |
|
|
811 |
void |
|
812 |
|
static void |
813 |
newsavepreferences (xmlNodePtr cur) |
newsavepreferences (xmlNodePtr cur) |
814 |
{ |
{ |
815 |
gchar *key; |
gchar *key; |
|
GString *sdir = g_string_new (""); |
|
816 |
|
|
817 |
preferences.x = 10; |
make_default_preferences (); |
818 |
preferences.y = 30; |
key = g_strdup_printf ("%d", PREFERENCES_VERSION); |
819 |
preferences.width = 750; |
xmlNewTextChild (cur, NULL, "version", key); |
|
preferences.height = 540; |
|
|
preferences.latitude = 0.0; |
|
|
preferences.NS = 1; |
|
|
preferences.longitude = 0.0; |
|
|
preferences.EW = 1; |
|
|
preferences.units = 1; |
|
|
preferences.bands = g_strdup ("1.8,3.5,7,10,14,18,21,24,28"); |
|
|
preferences.modes = g_strdup ("CW,SSB,PSK31,MFSK,MT63,SSTV"); |
|
|
preferences.bandseditbox = 0; |
|
|
preferences.modeseditbox = 0; |
|
|
preferences.bandoptionmenu = 0; |
|
|
preferences.modeoptionmenu = 0; |
|
|
preferences.printall = 0; |
|
|
preferences.printsize = 0; |
|
|
preferences.printpoint = 0; |
|
|
preferences.printorientation = 0; |
|
|
preferences.printdestination = 0; |
|
|
preferences.hamlib = 0; |
|
|
preferences.radio = g_strdup ("Dummy"); |
|
|
preferences.device = g_strdup ("/dev/ttyS1"); |
|
|
preferences.rigconf = g_strdup ("?"); |
|
|
preferences.round = 3; |
|
|
preferences.polltime = 0; |
|
|
preferences.clock = 0; |
|
|
preferences.themecolor = g_strdup ("blue"); |
|
|
preferences.themefont = g_strdup ("Sans 10"); |
|
|
preferences.logcolor = 1; |
|
|
preferences.autosave = 5; |
|
|
g_string_printf (sdir, "%s.", G_DIR_SEPARATOR_S); |
|
|
g_string_append (sdir, PACKAGE); |
|
|
preferences.savedir = g_strconcat (g_get_home_dir (), sdir->str, NULL); |
|
|
g_string_free (sdir, TRUE); |
|
|
preferences.saving = 1; |
|
|
preferences.logstoload = g_strdup ("*"); |
|
|
preferences.locator = g_strdup ("AA00AA"); |
|
|
preferences.freefield1 = g_strdup ("UNKNOWN"); |
|
|
preferences.freefield2 = g_strdup ("UNKNOWN"); |
|
|
preferences.callsign = g_strdup ("N0CALL"); |
|
|
preferences.defaultmhz = g_strdup ("?"); |
|
|
preferences.defaultmode = g_strdup ("?"); |
|
|
preferences.defaulttxrst = g_strdup ("?"); |
|
|
preferences.defaultrxrst = g_strdup ("?"); |
|
|
preferences.defaultpower = g_strdup ("?"); |
|
|
preferences.defaultfreefield1 = g_strdup ("?"); |
|
|
preferences.defaultfreefield2 = g_strdup ("?"); |
|
|
preferences.defaultremarks = g_strdup ("?"); |
|
|
preferences.b4columns = g_strdup ("1,1,1,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0"); |
|
|
preferences.typeaheadfind = 1; |
|
|
preferences.remoteadding = 1; |
|
|
preferences.viewtoolbar = 1; |
|
|
preferences.viewb4 = 0; |
|
|
preferences.b4x = 10; |
|
|
preferences.b4y = 30; |
|
|
preferences.b4width = 500; |
|
|
preferences.b4height = 300; |
|
|
|
|
820 |
key = g_strdup_printf ("%d", preferences.x); |
key = g_strdup_printf ("%d", preferences.x); |
821 |
xmlNewTextChild (cur, NULL, "x", key); |
xmlNewTextChild (cur, NULL, "x", key); |
822 |
key = g_strdup_printf ("%d", preferences.y); |
key = g_strdup_printf ("%d", preferences.y); |
911 |
xmlNewTextChild (cur, NULL, "defaultremarks", key); |
xmlNewTextChild (cur, NULL, "defaultremarks", key); |
912 |
key = g_strdup_printf ("%s", preferences.b4columns); |
key = g_strdup_printf ("%s", preferences.b4columns); |
913 |
xmlNewTextChild (cur, NULL, "b4columns", key); |
xmlNewTextChild (cur, NULL, "b4columns", key); |
914 |
|
key = g_strdup_printf ("%s", preferences.logcwidths); |
915 |
|
xmlNewTextChild (cur, NULL, "logcwidths", key); |
916 |
key = g_strdup_printf ("%d", preferences.typeaheadfind); |
key = g_strdup_printf ("%d", preferences.typeaheadfind); |
917 |
xmlNewTextChild (cur, NULL, "typeaheadfind", key); |
xmlNewTextChild (cur, NULL, "typeaheadfind", key); |
918 |
key = g_strdup_printf ("%d", preferences.remoteadding); |
key = g_strdup_printf ("%d", preferences.remoteadding); |
939 |
xmlDocPtr prefs; |
xmlDocPtr prefs; |
940 |
xmlNodePtr cur, node; |
xmlNodePtr cur, node; |
941 |
|
|
942 |
|
|
943 |
|
make_default_preferences (); |
944 |
/* open preferences file */ |
/* open preferences file */ |
945 |
preferencesfile = |
preferencesfile = |
946 |
g_strconcat (xlogdir, G_DIR_SEPARATOR_S, "preferences.xml", NULL); |
g_strconcat (xlogdir, G_DIR_SEPARATOR_S, "preferences.xml", NULL); |
983 |
newsavepreferences (node); |
newsavepreferences (node); |
984 |
xmlSaveFormatFile (preferencesfile, prefs, 1); |
xmlSaveFormatFile (preferencesfile, prefs, 1); |
985 |
xmlFreeDoc (prefs); |
xmlFreeDoc (prefs); |
986 |
|
newprefsfile = TRUE; |
987 |
} |
} |
988 |
g_free (preferencesfile); |
g_free (preferencesfile); |
989 |
} |
} |
991 |
void |
void |
992 |
savepreferences (void) |
savepreferences (void) |
993 |
{ |
{ |
994 |
gchar *preferencesfile; |
gchar *preferencesfile, *key; |
995 |
xmlDocPtr prefs; |
xmlDocPtr prefs; |
996 |
xmlNodePtr cur; |
xmlNodePtr root, cur; |
997 |
|
|
998 |
/* open preferences file */ |
/* open preferences file */ |
999 |
preferencesfile = |
preferencesfile = |
1004 |
g_warning (_("preferences not parsed successfully")); |
g_warning (_("preferences not parsed successfully")); |
1005 |
return; |
return; |
1006 |
} |
} |
1007 |
cur = xmlDocGetRootElement (prefs); |
root = xmlDocGetRootElement (prefs); |
1008 |
if (cur == NULL) |
if (root == NULL) |
1009 |
{ |
{ |
1010 |
g_warning (_("empty preferences file")); |
g_warning (_("empty preferences file")); |
1011 |
xmlFreeDoc (prefs); |
xmlFreeDoc (prefs); |
1012 |
return; |
return; |
1013 |
} |
} |
1014 |
if (xmlStrcmp(cur->name, (const xmlChar *) "xlog")) |
if (xmlStrcmp(root->name, (const xmlChar *) "xlog")) |
1015 |
{ |
{ |
1016 |
g_warning (_("document of the wrong type, root node is not xlog")); |
g_warning (_("document of the wrong type, root node is not xlog")); |
1017 |
xmlFreeDoc (prefs); |
xmlFreeDoc (prefs); |
1018 |
return; |
return; |
1019 |
} |
} |
1020 |
cur = cur->xmlChildrenNode; |
cur = root->xmlChildrenNode; |
1021 |
while (cur != NULL) |
while (cur != NULL) |
1022 |
{ |
{ |
1023 |
if ((!xmlStrcmp(cur->name, (const xmlChar *)"xlog_preferences"))) |
if ((!xmlStrcmp(cur->name, (const xmlChar *)"xlog_preferences"))) |
1024 |
|
{ |
1025 |
parsesavepreferences (cur); |
parsesavepreferences (cur); |
1026 |
|
if (!newprefsfile && (preferences.version < 1)) |
1027 |
|
{ |
1028 |
|
/* introduced in xlog version 0.9.8 */ |
1029 |
|
key = g_strdup_printf ("%d", PREFERENCES_VERSION); |
1030 |
|
xmlNewTextChild (cur, NULL, "version", key); |
1031 |
|
key = g_strdup_printf ("%s", preferences.logcwidths); |
1032 |
|
xmlNewTextChild (cur, NULL, "logcwidths", key); |
1033 |
|
g_free (key); |
1034 |
|
} |
1035 |
|
} |
1036 |
cur = cur->next; |
cur = cur->next; |
1037 |
} |
} |
1038 |
xmlSaveFormatFile (preferencesfile, prefs, 0); |
xmlSaveFormatFile (preferencesfile, prefs, 0); |