mcabber/src/settings.c
author Mikael Berthe <mikael@lilotux.net>
Wed, 06 Jul 2005 22:27:08 +0100
changeset 282 87d6ac21cd1b
parent 281 f562b9af2de7
child 288 1eea0fa0955e
permissions -rw-r--r--
Fix "Cannot unset option" bug
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
279
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     1
/*
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     2
 * settings.c   -- Configuration stuff
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     3
 * 
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     4
 * Copyright (C) 2005 Mikael Berthe <bmikael@lists.lilotux.net>
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     5
 *
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     6
 * This program is free software; you can redistribute it and/or modify
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     7
 * it under the terms of the GNU General Public License as published by
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     8
 * the Free Software Foundation; either version 2 of the License, or (at
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
     9
 * your option) any later version.
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    10
 *
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    11
 * This program is distributed in the hope that it will be useful, but
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    12
 * WITHOUT ANY WARRANTY; without even the implied warranty of
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    14
 * General Public License for more details.
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    15
 *
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    17
 * along with this program; if not, write to the Free Software
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    18
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    19
 * USA
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    20
 */
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    21
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    22
#include <strings.h>
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    23
#include <stdlib.h>
280
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
    24
#include <ctype.h>
279
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    25
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    26
#include "settings.h"
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    27
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    28
static GSList *option;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    29
static GSList *alias;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    30
static GSList *binding;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    31
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    32
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    33
typedef struct {
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    34
  gchar *name;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    35
  gchar *value;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    36
} T_setting;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    37
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    38
inline GSList **get_list_ptr(guint type)
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    39
{
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    40
  if      (type == SETTINGS_TYPE_OPTION)  return &option;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    41
  else if (type == SETTINGS_TYPE_ALIAS)   return &alias;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    42
  else if (type == SETTINGS_TYPE_BINDING) return &binding;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    43
  return NULL;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    44
}
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    45
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    46
// Return a pointer to the node with the requested key, or NULL if none found
281
f562b9af2de7 Add "const" specifier in prototypes
Mikael Berthe <mikael@lilotux.net>
parents: 280
diff changeset
    47
GSList *settings_find(GSList *list, const gchar *key)
279
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    48
{
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    49
  GSList *ptr;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    50
  
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    51
  if (!list) return NULL;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    52
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    53
  for (ptr = list ; ptr; ptr = g_slist_next(ptr))
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    54
    if (!strcasecmp(key, ((T_setting*)ptr->data)->name))
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    55
      break;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    56
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    57
  return ptr;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    58
}
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    59
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    60
/* -- */
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
    61
280
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
    62
//  parse_assigment(assignment, pkey, pval)
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
    63
// Read assignment and split it to key, value
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
    64
//
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
    65
// If this is an assignment, the function will return TRUE and
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
    66
// set *pkey and *pval (*pval is set to NULL if value field is empty).
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
    67
//
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
    68
// If this isn't a assignment (no = char), the function will set *pval
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
    69
// to NULL and return FALSE.
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
    70
//
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
    71
// The called should g_free() *pkey and *pval (if not NULL) after use.
281
f562b9af2de7 Add "const" specifier in prototypes
Mikael Berthe <mikael@lilotux.net>
parents: 280
diff changeset
    72
guint parse_assigment(gchar *assignment, const gchar **pkey, const gchar **pval)
280
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
    73
{
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
    74
  char *key, *val, *t;
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
    75
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
    76
  *pkey = *pval = NULL;
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
    77
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
    78
  key = assignment;
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
    79
  // Remove leading spaces in option name
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
    80
  while ((!isalnum(*key)) && (*key != '=') && *key) {
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
    81
    //if (!isblank(*key))
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
    82
    //  scr_LogPrint("Error in setting parsing!\n");
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
    83
    key++;
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
    84
  }
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
    85
  if (!*key) return FALSE; // Empty assignment
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
    86
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
    87
  if (*key == '=') {
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
    88
    //scr_LogPrint("Cannot parse setting!\n");
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
    89
    return FALSE;
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
    90
  }
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
    91
  // Ok, key points to the option name
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
    92
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
    93
  for (val = key+1 ; *val && (*val != '=') ; val++)
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
    94
    if (!isalnum(*val) && !isblank(*val) && (*val != '_') && (*val != '-')) {
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
    95
      // Key should only have alnum chars...
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
    96
      //scr_LogPrint("Error in setting parsing!\n");
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
    97
      return FALSE;
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
    98
    }
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
    99
  // Remove trailing spaces in option name:
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
   100
  for (t = val-1 ; t > key && isblank(*t) ; t--)
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
   101
    ;
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
   102
  *pkey = g_strndup(key, t+1-key);
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
   103
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
   104
  if (!*val) return FALSE; // Not an assignment
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
   105
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
   106
  // Remove leading and trailing spaces in option value:
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
   107
  for (val++; *val && isblank(*val) ; val++) ;
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
   108
  for (t = val ; *t ; t++) ;
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
   109
  for (t-- ; t >= val && isblank(*t) ; t--) ;
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
   110
282
87d6ac21cd1b Fix "Cannot unset option" bug
Mikael Berthe <mikael@lilotux.net>
parents: 281
diff changeset
   111
  if (t < val) return TRUE; // no value (variable reset for example)
280
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
   112
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
   113
  *pval = g_strndup(val, t+1-val);
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
   114
  return TRUE;
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
   115
}
68ce34b4243b Add parse_assigment() function
Mikael Berthe <mikael@lilotux.net>
parents: 279
diff changeset
   116
281
f562b9af2de7 Add "const" specifier in prototypes
Mikael Berthe <mikael@lilotux.net>
parents: 280
diff changeset
   117
void settings_set(guint type, const gchar *key, const gchar *value)
279
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   118
{
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   119
  GSList **plist;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   120
  GSList *sptr;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   121
  T_setting *setting;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   122
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   123
  plist = get_list_ptr(type);
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   124
  if (!plist) return;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   125
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   126
  sptr = settings_find(*plist, key);
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   127
  if (sptr) {
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   128
    // The setting has been found.  We will update it or delete it.
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   129
    setting = (T_setting*)sptr->data;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   130
    if (setting->value)
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   131
      g_free(setting->value);
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   132
    if (!value) {
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   133
      // Let's remove the setting
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   134
      g_free(setting->name);
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   135
      *plist = g_slist_delete_link(*plist, sptr);
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   136
    } else {
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   137
      // Let's update the setting
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   138
      setting->value = g_strdup(value);
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   139
    }
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   140
  } else if (value) {
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   141
    setting = g_new(T_setting, 1);
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   142
    setting->name  = g_strdup(key);
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   143
    setting->value = g_strdup(value);
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   144
    *plist = g_slist_append(*plist, setting);
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   145
  }
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   146
}
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   147
281
f562b9af2de7 Add "const" specifier in prototypes
Mikael Berthe <mikael@lilotux.net>
parents: 280
diff changeset
   148
void settings_del(guint type, const gchar *key)
279
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   149
{
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   150
  settings_set(type, key, NULL);
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   151
}
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   152
281
f562b9af2de7 Add "const" specifier in prototypes
Mikael Berthe <mikael@lilotux.net>
parents: 280
diff changeset
   153
const gchar *settings_get(guint type, const gchar *key)
279
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   154
{
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   155
  GSList **plist;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   156
  GSList *sptr;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   157
  T_setting *setting;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   158
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   159
  plist = get_list_ptr(type);
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   160
  sptr = settings_find(*plist, key);
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   161
  if (!sptr) return NULL;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   162
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   163
  setting = (T_setting*)sptr->data;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   164
  return setting->value;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   165
}
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   166
281
f562b9af2de7 Add "const" specifier in prototypes
Mikael Berthe <mikael@lilotux.net>
parents: 280
diff changeset
   167
int settings_get_int(guint type, const gchar *key)
279
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   168
{
281
f562b9af2de7 Add "const" specifier in prototypes
Mikael Berthe <mikael@lilotux.net>
parents: 280
diff changeset
   169
  const gchar *setval = settings_get(type, key);
279
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   170
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   171
  if (setval) return atoi(setval);
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   172
  return 0;
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   173
}
f5dd437c057b Rewrite the settings system
Mikael Berthe <mikael@lilotux.net>
parents:
diff changeset
   174