/* * Set some defaults for the given preferences structure */ void PreferencesInit (Preferences *pref) { pref->flags = FLAG_DELBS; OptImport (&pref->copts, PrefSetColorScheme (4)); OptSetVal (&pref->copts, CO_SHOWCHANGE, 1); OptSetVal (&pref->copts, CO_SHOWONOFF, 1); OptSetVal (&pref->copts, CO_WANTSBL, 1); }
/* * Load the preferences into *pref */ BOOL PrefLoad (Preferences *pref) { FILE *rcf, *stf; Contact *cont; int i; BOOL ok = TRUE; pref->away_time = default_away_time; rcf = PrefOpenRC (pref); if (rcf) { i = Read_RC_File (rcf); if (i >= 2) { stf = PrefOpenStat (pref); if (stf) PrefReadStat (stf); else ok = FALSE; } } else ok = FALSE; for (i = 0; (cont = ContactIndex (NULL, i)); i++) ContactMetaLoad (cont); switch (pref->autoupdate) { case 0: pref->flags &= ~FLAG_AUTOFINGER; case 1: OptSetVal (&pref->copts, CO_REVEALTIME, 600); if (0) case 2: pref->enc_loc = ENC_AUTO; case AUTOUPDATE_CURRENT: default: pref->autoupdate = AUTOUPDATE_CURRENT; } return ok; }
/* * Import options from a string. */ int OptImport (Opt *opts, const char *args) { strc_t par; char *argst; const char *argstt; UDWORD flag = 0; int i, ret = 0; argst = strdup (args); argstt = argst; while ((par = s_parse (&argstt))) { for (i = 0; OptList[i].name; i++) if (!strcmp (par->txt, OptList[i].name)) { flag = OptList[i].flag; break; } if (!OptList[i].name) { ret = 1; break; } if (!(par = s_parse (&argstt))) { ret = 1; break; } if (flag & COF_COLOR) { char *color = strdup (par->txt); OptSetStr (opts, flag, OptC2S (color)); OptUndef (opts, CO_CSCHEME); free (color); } else if (flag == CO_ENCODINGSTR) { UWORD enc = ConvEnc (par->txt) & ~ENC_FLAGS; OptSetVal (opts, CO_ENCODING, enc); OptSetStr (opts, CO_ENCODINGSTR, ConvEncName (enc)); } else if (flag & COF_NUMERIC) { val_t val = atoll (par->txt); if (flag == CO_CSCHEME) OptImport (opts, PrefSetColorScheme (val)); OptSetVal (opts, flag, val); } else if (~flag & COF_BOOL) OptSetStr (opts, flag, par->txt); else if (!strcasecmp (par->txt, "on") || !strcasecmp (par->txt, i18n (1085, "on"))) OptSetVal (opts, flag, 1); else if (!strcasecmp (par->txt, "off") || !strcasecmp (par->txt, i18n (1086, "off"))) OptSetVal (opts, flag, 0); else if (!strcasecmp (par->txt, "undef")) OptUndef (opts, flag); else { ret = 1; break; } } free (argst); return ret; }