5 A Linux/Unix GUI for Nokia mobile phones.
6 Copyright (C) 1999 Pavel Janík ml., Hugh Blemings
7 & Ján Derfiòák <ja@mail.upjs.sk>.
9 Released under the terms of the GNU GPL, see file COPYING for more details.
11 Last modification: Mon Oct 10 1999
12 Modified by Jan Derfinak
21 #include "xgnokii_cfg.h"
24 ConfigEntry config[] = {
25 {"name", &(xgnokiiConfig.user.name)},
26 {"title", &(xgnokiiConfig.user.title)},
27 {"company", &(xgnokiiConfig.user.company)},
28 {"telephone", &(xgnokiiConfig.user.telephone)},
29 {"fax", &(xgnokiiConfig.user.fax)},
30 {"email", &(xgnokiiConfig.user.email)},
31 {"address", &(xgnokiiConfig.user.address)},
32 {"viewer", &(xgnokiiConfig.helpviewer)},
33 {"mailbox", &(xgnokiiConfig.mailbox)},
34 {"simlen", &(xgnokiiConfig.maxSIMLen)},
35 {"phonelen", &(xgnokiiConfig.maxPhoneLen)},
40 static void GetDefaultValues ()
44 xgnokiiConfig.user.name = g_strdup ("");
45 xgnokiiConfig.user.title = g_strdup ("");
46 xgnokiiConfig.user.company = g_strdup ("");
47 xgnokiiConfig.user.telephone = g_strdup ("");
48 xgnokiiConfig.user.fax = g_strdup ("");
49 xgnokiiConfig.user.email = g_strdup ("");
50 xgnokiiConfig.user.address = g_strdup ("");
51 xgnokiiConfig.helpviewer = g_strdup ("netscape");
52 if ((homedir = g_get_home_dir ()) == NULL)
54 xgnokiiConfig.mailbox = g_strdup_printf ("%s/Mail/smsbox", homedir);
55 xgnokiiConfig.maxSIMLen = g_strdup ("14");
56 xgnokiiConfig.maxPhoneLen = g_strdup ("16");
60 void GUI_ReadXConfig ()
73 /* homedir = getenv("HOMEDRIVE");
74 g_strconcat(homedir, getenv("HOMEPATH"), NULL); */
75 homedir = g_get_home_dir ();
76 rcfile=g_strconcat(homedir, "\\_xgnokiirc", NULL);
78 if ((homedir = g_get_home_dir ()) == NULL)
80 g_print (_("WARNING: Can't find HOME enviroment variable!\n"));
84 if ((rcfile = g_strconcat (homedir, "/.xgnokiirc", NULL)) == NULL)
86 g_print (_("WARNING: Can't allocate memory for config reading!\n"));
91 if ((file = fopen (rcfile, "r")) == NULL)
99 if ((line = (char *) g_malloc (255)) == NULL)
101 g_print (_("WARNING: Can't allocate memory for config reading!\n"));
106 while (fgets (line, 255, file) != NULL)
111 /* Strip leading, trailing whitespace */
112 while (isspace ((gint) *current))
115 while ((strlen (current) > 0) && isspace ((gint) current[strlen (current) - 1]))
116 current[strlen (current) - 1] = '\0';
118 /* Ignore blank lines and comments */
120 if ((*current == '\n') || (*current == '\0') || (*current == '#'))
124 while (*config[i].key != '\0')
126 len = strlen (config[i].key);
127 if (g_strncasecmp (config[i].key, current, len) == 0)
130 while (isspace ((int) *current))
135 while(isspace ((int) *current))
137 g_free (*config[i].value);
142 *config[i].value = g_strndup (current, max_phonebook_number_length);
146 *config[i].value = g_strndup (current, HTMLVIEWER_LENGTH);
150 *config[i].value = g_strndup (current, MAILBOX_LENGTH);
156 if ( v > 0 && v < 100 )
157 *config[i].value = g_strndup (current, 3);
161 *config[i].value = g_strndup (current, MAX_BUSINESS_CARD_LENGTH);
175 gint GUI_SaveXConfig ()
183 if ((homedir = getenv ("HOME")) == NULL)
185 g_print (_("ERROR: Can't find HOME enviroment variable!\n"));
189 if ((rcfile = g_strconcat (homedir, "/.xgnokiirc", NULL)) == NULL)
191 g_print (_("ERROR: Can't allocate memory for config writing!\n"));
195 if ((file = fopen (rcfile, "w")) == NULL)
197 g_print (_("ERROR: Can't open file %s for writing!\n"), rcfile);
205 while (*config[i].key != '\0')
207 if ((line = g_strdup_printf ("%s = %s\n", config[i].key, *config[i].value)) == NULL)
209 g_print (_("ERROR: Can't allocate memory for config writing!\n"));
213 if (fputs (line, file) == EOF)
215 g_print (_("ERROR: Can't write config file!\n"));