5 A Linux/Unix GUI for Nokia mobile phones.
7 Released under the terms of the GNU GPL, see file COPYING for more details.
16 #include "xgnokii_cfg.h"
19 ConfigEntry config[] = {
20 {"name", &(xgnokiiConfig.user.name)},
21 {"title", &(xgnokiiConfig.user.title)},
22 {"company", &(xgnokiiConfig.user.company)},
23 {"telephone", &(xgnokiiConfig.user.telephone)},
24 {"fax", &(xgnokiiConfig.user.fax)},
25 {"email", &(xgnokiiConfig.user.email)},
26 {"address", &(xgnokiiConfig.user.address)},
27 {"viewer", &(xgnokiiConfig.helpviewer)},
28 {"mailbox", &(xgnokiiConfig.mailbox)},
29 {"simlen", &(xgnokiiConfig.maxSIMLen)},
30 {"phonelen", &(xgnokiiConfig.maxPhoneLen)},
35 static void GetDefaultValues ()
39 xgnokiiConfig.user.name = g_strdup ("");
40 xgnokiiConfig.user.title = g_strdup ("");
41 xgnokiiConfig.user.company = g_strdup ("");
42 xgnokiiConfig.user.telephone = g_strdup ("");
43 xgnokiiConfig.user.fax = g_strdup ("");
44 xgnokiiConfig.user.email = g_strdup ("");
45 xgnokiiConfig.user.address = g_strdup ("");
46 xgnokiiConfig.helpviewer = g_strdup ("netscape");
47 if ((homedir = g_get_home_dir ()) == NULL)
49 xgnokiiConfig.mailbox = g_strdup_printf ("%s/Mail/smsbox", homedir);
50 xgnokiiConfig.maxSIMLen = g_strdup ("14");
51 xgnokiiConfig.maxPhoneLen = g_strdup ("16");
55 void GUI_ReadXConfig ()
68 /* homedir = getenv("HOMEDRIVE");
69 g_strconcat(homedir, getenv("HOMEPATH"), NULL); */
70 homedir = g_get_home_dir ();
71 rcfile=g_strconcat(homedir, "\\_xgnokiirc", NULL);
73 if ((homedir = g_get_home_dir ()) == NULL)
75 g_print (_("WARNING: Can't find HOME enviroment variable!\n"));
79 if ((rcfile = g_strconcat (homedir, "/.xgnokiirc", NULL)) == NULL)
81 g_print (_("WARNING: Can't allocate memory for config reading!\n"));
86 if ((file = fopen (rcfile, "r")) == NULL)
94 if ((line = (char *) g_malloc (255)) == NULL)
96 g_print (_("WARNING: Can't allocate memory for config reading!\n"));
101 while (fgets (line, 255, file) != NULL)
106 /* Strip leading, trailing whitespace */
107 while (isspace ((gint) *current))
110 while ((strlen (current) > 0) && isspace ((gint) current[strlen (current) - 1]))
111 current[strlen (current) - 1] = '\0';
113 /* Ignore blank lines and comments */
115 if ((*current == '\n') || (*current == '\0') || (*current == '#'))
119 while (*config[i].key != '\0')
121 len = strlen (config[i].key);
122 if (g_strncasecmp (config[i].key, current, len) == 0)
125 while (isspace ((int) *current))
130 while(isspace ((int) *current))
132 g_free (*config[i].value);
137 *config[i].value = g_strndup (current, max_phonebook_number_length);
141 *config[i].value = g_strndup (current, HTMLVIEWER_LENGTH);
145 *config[i].value = g_strndup (current, MAILBOX_LENGTH);
151 if ( v > 0 && v < 100 )
152 *config[i].value = g_strndup (current, 3);
156 *config[i].value = g_strndup (current, MAX_BUSINESS_CARD_LENGTH);
170 gint GUI_SaveXConfig ()
178 if ((homedir = getenv ("HOME")) == NULL)
180 g_print (_("ERROR: Can't find HOME enviroment variable!\n"));
184 if ((rcfile = g_strconcat (homedir, "/.xgnokiirc", NULL)) == NULL)
186 g_print (_("ERROR: Can't allocate memory for config writing!\n"));
190 if ((file = fopen (rcfile, "w")) == NULL)
192 g_print (_("ERROR: Can't open file %s for writing!\n"), rcfile);
200 while (*config[i].key != '\0')
202 if ((line = g_strdup_printf ("%s = %s\n", config[i].key, *config[i].value)) == NULL)
204 g_print (_("ERROR: Can't allocate memory for config writing!\n"));
208 if (fputs (line, file) == EOF)
210 g_print (_("ERROR: Can't write config file!\n"));