builtin-gconf.c 67.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/**
 * @file builtin-gconf.c
 * GConf compatibility module - for dynamic mce settings
 * <p>
 * Copyright (C) 2012-2019 Jolla Ltd.
 * <p>
 * @author Simo Piiroinen <simo.piiroinen@jollamobile.com>
 *
 * mce is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License
 * version 2.1 as published by the Free Software Foundation.
 *
 * mce is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with mce.  If not, see <http://www.gnu.org/licenses/>.
 */
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35

/* ------------------------------------------------------------------------- *
 * NOTE: This module implements just enough of the GConf API to allow us
 * to detach mce from D-Bus session bus. By no means is this even meant
 * to be a complete GConf replacement.
 *
 * CAVEATS include *at least*:
 * - the keys have no hierarchy
 * - anything related to directories is simply ignored
 * - gconf_client_get() returns the real thing, not deep copied duplicate
 * - pair values are not supported
 * - adding new values is not supported
 * - value types can't be changed
 * ------------------------------------------------------------------------- */

36 37 38
#include "mce-log.h"
#include "mce-io.h"
#include "mce-dbus.h"
39
#include "mce-setting.h"
40

41
#include "powerkey.h"
42
#include "tklock.h"
43
#include "event-input.h"
44

45
#include "modules/memnotify.h"
46
#include "modules/display.h"
47
#include "modules/proximity.h"
48 49 50
#include "modules/powersavemode.h"
#include "modules/doubletap.h"
#include "modules/led.h"
51
#include "modules/inactivity.h"
52

53 54
#include <stdlib.h>
#include <string.h>
55
#include <errno.h>
56
#include <glob.h>
57

58 59 60 61 62 63 64 65 66 67 68 69
/* ========================================================================= *
 *
 * CONFIGURATION
 *
 * ========================================================================= */

/** Enable error logging to stderr via gconf_log_error() */
#define GCONF_ENABLE_ERROR_LOGGING 01

/** Enable debug logging to stderr via gconf_log_debug() */
#define GCONF_ENABLE_DEBUG_LOGGING 01

70 71 72
/** Path to persistent storage file */
#define VALUES_PATH G_STRINGIFY(MCE_VAR_DIR)"/builtin-gconf.values"

73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
/* ========================================================================= *
 *
 * MACROS
 *
 * ========================================================================= */

/** Tag unused parameters as such to avoid compilation warnings */
#define unused(variable) (void)&variable

/* ========================================================================= *
 *
 * FUNCTION PROTOTYPES
 *
 * ========================================================================= */

static GQuark gconf_error_quark(void);
static void gconf_set_error(GError **err, gint code, const gchar *fmt, ...);
static char *gconf_strip_string(char *str);
static int gconf_parse_int(const char *str);
static double gconf_parse_float(const char *str);
static gboolean gconf_parse_bool(const char *str);
static GConfValueType gconf_parse_type(int chr);
static const char *gconf_type_repr(GConfValueType type);
static gboolean gconf_require_type(const char *key, const GConfValue *value, GConfValueType type, GError **err);
static gboolean gconf_require_list_type(const char *key, const GConfValue *value, GConfValueType type, GError **err);
gchar *gconf_concat_dir_and_key(const gchar *dir, const gchar *key);
99
#if GCONF_ENABLE_DEBUG_LOGGING
100
static char *gconf_value_repr(const char *key, GConfValue *self);
101
#endif
102
static char *gconf_value_str(GConfValue *self);
103 104 105 106 107 108 109 110 111 112
static void gconf_value_unset(GConfValue *self);
static gboolean gconf_value_list_validata(GSList *src, GConfValueType type);
static GSList *gconf_value_list_copy(GSList *src);
static GSList *gconf_value_list_free(GSList *list);
static void gconf_value_set_from_string(GConfValue *self, const char *data);
static GConfValue *gconf_value_init(GConfValueType type, GConfValueType list_type, const char *data);
GConfValue *gconf_value_copy(const GConfValue *src);
GConfValue *gconf_value_new(GConfValueType type);
void gconf_value_free(GConfValue *self);
gboolean gconf_value_get_bool(const GConfValue *self);
113
bool gconf_value_set_bool(GConfValue *self, gboolean val);
114
int gconf_value_get_int(const GConfValue *self);
115
bool gconf_value_set_int(GConfValue *self, gint val);
116
double gconf_value_get_float(const GConfValue *self);
117
bool gconf_value_set_float(GConfValue *self, double val);
118
const char *gconf_value_get_string(const GConfValue *self);
119
bool gconf_value_set_string(GConfValue *self, const char *val);
120 121 122
GConfValueType gconf_value_get_list_type(const GConfValue *self);
void gconf_value_set_list_type(GConfValue *self, GConfValueType list_type);
GSList *gconf_value_get_list(const GConfValue *self);
123
bool gconf_value_set_list(GConfValue *self, GSList *list);
124
static GConfEntry *gconf_entry_init(const char *key, const char *type, const char *data);
125 126
static void gconf_entry_free(GConfEntry *self);
static void gconf_entry_free_cb(gpointer self);
127 128
const char *gconf_entry_get_key(const GConfEntry *entry);
GConfValue *gconf_entry_get_value(const GConfEntry *entry);
129
#if GCONF_ENABLE_DEBUG_LOGGING
130
static void gconf_client_debug(GConfClient *self);
131
#endif
132
GConfClient *gconf_client_get_default(void);
133
static void gconf_client_free_default(void);
134 135 136 137 138
void gconf_client_add_dir(GConfClient *client, const gchar *dir, GConfClientPreloadType preload, GError **err);
static GConfEntry *gconf_client_find_entry(GConfClient *self, const gchar *key, GError **err);
static GConfValue *gconf_client_find_value(GConfClient *self, const gchar *key, GError **err);
GConfValue *gconf_client_get(GConfClient *self, const gchar *key, GError **err);
static void gconf_client_notify_free(GConfClientNotify *self);
139
static void gconf_client_notify_free_cb(gpointer self);
140 141 142 143 144 145 146 147 148 149 150
static GConfClientNotify *gconf_client_notify_new(const gchar *namespace_section, GConfClientNotifyFunc func, gpointer user_data, GFreeFunc destroy_notify);
static void gconf_client_notify_change(GConfClient *client, const gchar *namespace_section);
guint gconf_client_notify_add(GConfClient *client, const gchar *namespace_section, GConfClientNotifyFunc func, gpointer user_data, GFreeFunc destroy_notify, GError **err);
void gconf_client_notify_remove(GConfClient *client, guint cnxn);
gboolean gconf_client_set_bool(GConfClient *client, const gchar *key, gboolean val, GError **err);
gboolean gconf_client_set_int(GConfClient *client, const gchar *key, gint val, GError **err);
gboolean gconf_client_set_float(GConfClient *client, const gchar *key, double val, GError **err);
gboolean gconf_client_set_string(GConfClient *client, const gchar *key, const gchar *val, GError **err);
gboolean gconf_client_set_list(GConfClient *client, const gchar *key, GConfValueType list_type, GSList *list, GError **err);
void gconf_client_suggest_sync(GConfClient *client, GError **err);

151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
/* ========================================================================= *
 *
 * MISCELLANEOUS UTILITIES
 *
 * ========================================================================= */

/* Null tolerant string equality predicate
 *
 * @param s1 string
 * @param s2 string
 *
 * @return true if both s1 and s2 are null or same string, false otherwise
 */
static inline bool eq(const char *s1, const char *s2)
{
    return (s1 && s2) ? !strcmp(s1, s2) : (s1 == s2);
}

169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
/* ========================================================================= *
 *
 * ERRORS & LOGGING
 *
 * ========================================================================= */

/** Our custom error quark */
static
GQuark
gconf_error_quark (void)
{
  return g_quark_from_static_string ("gconf-setting-error-quark");
}

#define GCONF_ERROR gconf_error_quark()

/** Error logging function */
#if GCONF_ENABLE_ERROR_LOGGING
187
# define gconf_log_error(FMT, ARG...) mce_log_file(LL_WARN, __FILE__, __FUNCTION__, FMT , ##ARG)
188
#else
189
# define gconf_log_error(FMT, ARG...) do{}while(0)
190 191 192 193
#endif

/** Debug logging function */
#if GCONF_ENABLE_DEBUG_LOGGING
194 195
# define gconf_log_debug_p()          mce_log_p(LL_DEBUG)
# define gconf_log_debug(FMT, ARG...) mce_log_file(LL_DEBUG, __FILE__, __FUNCTION__, FMT , ##ARG)
196
#else
197 198
# define gconf_log_debug_p()          0
# define gconf_log_debug(FMT, ARG...) do{}while(0)
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
#endif

/** Set GError helper */
static
void
gconf_set_error(GError **err, gint code, const gchar *fmt, ...)
__attribute__((format(printf, 3, 4)));

static
void
gconf_set_error(GError **err, gint code, const gchar *fmt, ...)
{
  char *msg = 0;

  va_list va;
  va_start(va, fmt);
  if( vasprintf(&msg, fmt, va) < 0 )
  {
    msg = 0;
  }
  va_end(va);

221 222 223 224
  /* Assume caller will report error in appropriate context,
   * log from builtin-gconf only in debug verbosity level */
  mce_log(LL_DEBUG, "%s", msg ?: "unknown");

225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338
  g_set_error_literal(err, GCONF_ERROR, code, msg ?: "unknown");
  free(msg);
}

/* ========================================================================= *
 *
 * STRING PARSING
 *
 * ========================================================================= */

/** ASCII white character predicate */
static inline gboolean gconf_white_p(int c)
{
  return (c > 0) && (c <= 32);
}

/** ASCII non-white character predicate */
static inline gboolean gconf_black_p(int c)
{
  return (c < 0) || (c > 32);
}

/** Strip excess whitespace from string */
static char *gconf_strip_string(char *str)
{
  if( str )
  {
    char *s = str;
    char *d = str;

    while( gconf_white_p(*s) ) ++s;

    for( ;; )
    {
      while( gconf_black_p(*s) ) *d++ = *s++;

      while( gconf_white_p(*s) ) ++s;

      if( !*s ) break;

      *d++ = ' ';
    }
    *d = 0;
  }
  return str;
}

/** Array of strings we accept as: boolean true */
static const char * const gconf_true_lut[] = { "true", "t", "yes", "y", 0 };

/** Array of strings we accept as: boolean false */
static const char * const gconf_false_lut[] = { "false", "f", "no", "n", 0 };

/** String to int helper */
static int gconf_parse_int(const char *str)
{
  char *end = 0;
  int   res = strtol(str, &end, 0);

  if( (end <= str) || *end )
  {
    gconf_log_error("'%s': is not fully qualified integer", str);
  }
  return res;
}

/** String to double helper */
static double gconf_parse_float(const char *str)
{
  char  *end = 0;
  double res = strtod(str, &end);

  if( (end <= str) || *end )
  {
    gconf_log_error("'%s': is not fully qualified float", str);
  }
  return res;
}

/** String to bool helper */
static gboolean gconf_parse_bool(const char *str)
{
  for( size_t i = 0; gconf_true_lut[i]; ++i )
  {
    if( !strcmp(gconf_true_lut[i], str) ) return TRUE;
  }

  for( size_t i = 0; gconf_false_lut[i]; ++i )
  {
    if( !strcmp(gconf_false_lut[i], str) ) return FALSE;
  }

  int res = gconf_parse_int(str);
  if( res < 0 || res > 1 )
  {
    gconf_log_error("'%s': is not fully qualified bool", str);
  }
  return res;
}

/** Char to GConfValueType helper */
static GConfValueType gconf_parse_type(int chr)
{
  GConfValueType res = GCONF_VALUE_INVALID;

  switch( chr )
  {
  case 'b': res = GCONF_VALUE_BOOL;   break;
  case 'i': res = GCONF_VALUE_INT;    break;
  case 'f': res = GCONF_VALUE_FLOAT;  break;
  case 's': res = GCONF_VALUE_STRING; break;
  case 'a': res = GCONF_VALUE_LIST;   break;

  default:
339
    gconf_log_error("unknown type '%c'", chr);
340 341 342 343 344 345 346 347 348 349 350
    break;
  }
  return res;
}

/* ========================================================================= *
 *
 * MISCELLANEOUS
 *
 * ========================================================================= */

351
#if GCONF_ENABLE_DEBUG_LOGGING
352 353 354 355 356 357 358
/** Boolean to text helper */
static
const char *
gconf_bool_repr(gboolean value)
{
  return value ? *gconf_true_lut : *gconf_false_lut;
}
359
#endif
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459

/** GConfValueType to text helper */
static
const char *
gconf_type_repr(GConfValueType type)
{
  const char *res = "unknown";

  switch( type )
  {
  case GCONF_VALUE_INVALID: res = "invalid"; break;
  case GCONF_VALUE_STRING:  res = "string";  break;
  case GCONF_VALUE_INT:     res = "int";     break;
  case GCONF_VALUE_FLOAT:   res = "float";   break;
  case GCONF_VALUE_BOOL:    res = "bool";    break;
  case GCONF_VALUE_SCHEMA:  res = "schema";  break;
  case GCONF_VALUE_LIST:    res = "list";    break;
  case GCONF_VALUE_PAIR:    res = "pair";    break;
  default: break;
  }

  return res;
}

/** Type checking helper */
static
gboolean
gconf_require_type(const char *key, const GConfValue *value,
                   GConfValueType type, GError **err)
{
  if( value->type == type )
  {
    return TRUE;
  }

  gconf_set_error(err, GCONF_ERROR_TYPE_MISMATCH, "%s: is %s, not %s",
                  key, gconf_type_repr(value->type), gconf_type_repr(type));
  return FALSE;
}

/** List type checking helper */
static
gboolean
gconf_require_list_type(const char *key, const GConfValue *value,
                        GConfValueType type, GError **err)
{
  if( !gconf_require_type(key, value, GCONF_VALUE_LIST, err) )
  {
    return FALSE;
  }
  if( value->list_type == type )
  {
    return TRUE;
  }

  gconf_set_error(err, GCONF_ERROR_TYPE_MISMATCH,
                  "%s: is %s list, not %s list", key,
                  gconf_type_repr(value->list_type), gconf_type_repr(type));
  return FALSE;
}

/** See GConf API documentation */
gchar *
gconf_concat_dir_and_key(const gchar *dir,
                         const gchar *key)
{
  gchar *res = g_strconcat(dir ?: "", "/", key ?: "", NULL);

  if( res != 0 )
  {
    gchar *s = res;
    gchar *d = res;

    while( *s )
    {
      /* copy other than '/' verbatim */
      if( *s != '/' )
      {
        *d++ = *s++;
        continue;
      }

      /* compress '///' into '/' */
      while( *++s == '/' ) {}
      *d++ = '/';
    }

    /* terminate */
    *d = 0;
  }

  return res;
}

/* ========================================================================= *
 *
 * GConfValue
 *
 * ========================================================================= */

460
#if GCONF_ENABLE_DEBUG_LOGGING
461 462 463 464
/** GConfValue to text helper
 *
 * The result is for human readable for debugging purposes
 */
465 466 467 468 469 470
static
char *
gconf_value_repr(const char *key, GConfValue *self)
{
  char   *data = 0;
  size_t  size = 0;
471 472 473 474 475 476
  FILE   *file = 0;

  if( !(file = open_memstream(&data, &size)) )
  {
    goto cleanup;
  }
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542

  fprintf(file, "'%s' %s", key, gconf_type_repr(self->type));

  switch( self->type )
  {
  case GCONF_VALUE_STRING:
    fprintf(file, " '%s'", self->data.s);
    break;

  case GCONF_VALUE_INT:
    fprintf(file, " %d", self->data.i);
    break;

  case GCONF_VALUE_FLOAT:
    fprintf(file, " %g", self->data.f);
    break;

  case GCONF_VALUE_BOOL:
    fprintf(file, " %s", gconf_bool_repr(self->data.b));
    break;

  case GCONF_VALUE_SCHEMA:
    fprintf(file, " %g", self->data.f);
    break;

  case GCONF_VALUE_LIST:
    fprintf(file, " of %s [", gconf_type_repr(self->list_type));

    for( GSList *v_iter = self->list_head; v_iter; v_iter = v_iter->next )
    {
      switch( (self = v_iter->data)->type )
      {
      case GCONF_VALUE_STRING:
        fprintf(file, " '%s'", self->data.s);
        break;

      case GCONF_VALUE_INT:
        fprintf(file, " %d", self->data.i);
        break;

      case GCONF_VALUE_FLOAT:
        fprintf(file, " %g", self->data.f);
        break;

      case GCONF_VALUE_BOOL:
        fprintf(file, " %s", gconf_bool_repr(self->data.b));
        break;

      default:
        fprintf(file, " ???");
        break;
      }
    }
    fprintf(file, " ]");
    break;

  case GCONF_VALUE_PAIR:
    fprintf(file, "pair (");
    fprintf(file, " )");
    break;

  case GCONF_VALUE_INVALID:
  default:
    break;
  }

543 544
cleanup:
  if( file ) fclose(file);
545 546 547

  return data;
}
548
#endif
549

550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614
/** GConfValue to text helper
 *
 * The result is compatible with gconf_value_set_from_string()
 */
static
char *
gconf_value_str(GConfValue *self)
{
  char   *data = 0;
  size_t  size = 0;
  FILE   *file = 0;

  if( !(file = open_memstream(&data, &size)) )
  {
    goto cleanup;
  }

  switch( self->type )
  {
  case GCONF_VALUE_STRING:
    fprintf(file, "%s", self->data.s);
    break;

  case GCONF_VALUE_INT:
    fprintf(file, "%d", self->data.i);
    break;

  case GCONF_VALUE_FLOAT:
    fprintf(file, "%g", self->data.f);
    break;

  case GCONF_VALUE_BOOL:
    fprintf(file, "%s", gconf_bool_repr(self->data.b));
    break;

  case GCONF_VALUE_SCHEMA:
    fprintf(file, "%g", self->data.f);
    break;

  case GCONF_VALUE_LIST:
    for( GSList *v_iter = self->list_head; v_iter; v_iter = v_iter->next )
    {
      switch( (self = v_iter->data)->type )
      {
      case GCONF_VALUE_STRING:
        fprintf(file, "%s", self->data.s);
        break;

      case GCONF_VALUE_INT:
        fprintf(file, "%d", self->data.i);
        break;

      case GCONF_VALUE_FLOAT:
        fprintf(file, "%g", self->data.f);
        break;

      case GCONF_VALUE_BOOL:
        fprintf(file, "%s", gconf_bool_repr(self->data.b));
        break;

      default:
        fprintf(file, "???");
        break;
      }
      if( v_iter->next ) {
615
        fprintf(file, ",");
616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634
      }
    }
    break;

  case GCONF_VALUE_PAIR:
    fprintf(file, "???");
    break;
  case GCONF_VALUE_INVALID:
  default:
    break;
  }

cleanup:

  if( file ) fclose(file);

  return data;
}

635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669
/** Release dynamic resources of value, but not the value itself */
static
void
gconf_value_unset(GConfValue *self)
{
  // clear the list of values
  for( GSList *elem = self->list_head; elem; elem = elem->next )
  {
    gconf_value_free(elem->data);
  }
  g_slist_free(self->list_head), self->list_head = 0;

  // free any dynamically allocated data
  switch( self->type )
  {
  case GCONF_VALUE_STRING:
    free(self->data.s), self->data.s = 0;
    break;

  default:
    break;
  }
}

/** Helper for type checking a list of values */
static
gboolean
gconf_value_list_validata(GSList *src, GConfValueType type)
{
  for( ; src; src = src->next )
  {
    GConfValue *val = src->data;

    if( !val )
    {
670
      gconf_log_error("list has NULL value");
671 672 673 674 675
      return FALSE;
    }

    if( val->type != type )
    {
676
      gconf_log_error("list has %s value, expected %s\n",
677
                      gconf_type_repr(val->type), gconf_type_repr(type));
678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728
      return FALSE;
    }
  }
  return TRUE;
}

/** Helper for deep copying list of values */
static
GSList *
gconf_value_list_copy(GSList *src)
{
  GSList *res = 0;

  for( ; src; src = src->next )
  {
    res = g_slist_prepend(res, gconf_value_copy(src->data));
  }
  res = g_slist_reverse(res);

  return res;
}

/** Helper for recursively releasing a list of values */
static
GSList *
gconf_value_list_free(GSList *list)
{
  g_slist_free_full(list, (GDestroyNotify)gconf_value_free);
  return 0;
}

/** Parse value content from text */
static void gconf_value_set_from_string(GConfValue *self, const char *data)
{
  char *now, *zen, *tmp = 0;

  switch( self->type )
  {
  case GCONF_VALUE_BOOL:
    self->data.b = gconf_parse_bool(data);
    break;

  case GCONF_VALUE_INT:
    self->data.i = gconf_parse_int(data);
    break;

  case GCONF_VALUE_FLOAT:
    self->data.f = gconf_parse_float(data);
    break;

  case GCONF_VALUE_STRING:
729
    free(self->data.s);
730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747
    self->data.s = strdup(data);
    break;

  case GCONF_VALUE_LIST:
    switch( self->list_type )
    {
    case GCONF_VALUE_BOOL:
    case GCONF_VALUE_INT:
    case GCONF_VALUE_FLOAT:
    case GCONF_VALUE_STRING:
      break;

    default:
      self->list_type = GCONF_VALUE_INVALID;
      self->type      = GCONF_VALUE_INVALID;
      goto cleanup;
    }

748 749
    self->list_head = gconf_value_list_free(self->list_head);

750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876
    for( now = tmp = strdup(data); now; now = zen )
    {
      if( (zen = strchr(now, ',')) )
      {
        *zen++ = 0;
      }

      GConfValue *elem = gconf_value_init(self->list_type,
                                          GCONF_VALUE_INVALID,
                                          gconf_strip_string(now));
      self->list_head = g_slist_prepend(self->list_head, elem);
    }
    self->list_head = g_slist_reverse(self->list_head);
    break;

  default:
    self->list_type = GCONF_VALUE_INVALID;
    self->type      = GCONF_VALUE_INVALID;
    break;
  }

cleanup:

  free(tmp);
}

/** Create and initialize a GConfValue */
static
GConfValue *
gconf_value_init(GConfValueType type, GConfValueType list_type,
                 const char *data)
{
  GConfValue *self = calloc(1, sizeof *self);

  self->refcount  = 1;
  self->list_type = GCONF_VALUE_INVALID;
  self->type      = type;

  if( self->type == GCONF_VALUE_LIST )
  {
    self->list_type = list_type;
  }

  if( data != 0 )
  {
    gconf_value_set_from_string(self, data);
  }

  return self;
}

/** See GConf API documentation */
GConfValue *
gconf_value_copy(const GConfValue *src)
{
  GConfValue *self = gconf_value_init(src->type, src->list_type, 0);

  if( self->type != src->type || self->list_type != src->list_type )
  {
    goto cleanup;
  }

  switch( self->type )
  {
  case GCONF_VALUE_BOOL:
    self->data.b = src->data.b;
    break;

  case GCONF_VALUE_INT:
    self->data.i = src->data.i;
    break;

  case GCONF_VALUE_FLOAT:
    self->data.f = src->data.f;
    break;

  case GCONF_VALUE_STRING:
    self->data.s = src->data.s ? strdup(src->data.s) : 0;
    break;

  case GCONF_VALUE_LIST:
    self->list_head = gconf_value_list_copy(src->list_head);
    break;

  default:
    self->list_type = GCONF_VALUE_INVALID;
    self->type      = GCONF_VALUE_INVALID;
    break;
  }

cleanup:
  return self;
}

/** See GConf API documentation */
GConfValue *
gconf_value_new(GConfValueType type)
{
  return gconf_value_init(type, GCONF_VALUE_INVALID, 0);
}

/** See GConf API documentation */
void
gconf_value_free(GConfValue *self)
{
  if( self != 0 && --self->refcount == 0 )
  {
    /* get rid of dynamically allocated resources */
    gconf_value_unset(self);

    /* mark the value as invalid to ease stale pointer debugging */
    self->type      = GCONF_VALUE_INVALID;
    self->list_type = GCONF_VALUE_INVALID;

    /* free the value itself too */
    free(self);
  }
}

/** See GConf API documentation */
gboolean
gconf_value_get_bool(const GConfValue *self)
{
  return (self->type == GCONF_VALUE_BOOL) ? self->data.b : 0;
}

/** See GConf API documentation */
877
bool
878 879
gconf_value_set_bool(GConfValue *self, gboolean val)
{
880 881 882
  bool changed = false;

  if( self->type != GCONF_VALUE_BOOL )
883
  {
884
    gconf_log_error("not a bool value");
885
  }
886
  else if( self->data.b != val )
887
  {
888 889
    self->data.b = val;
    changed = true;
890
  }
891 892

  return changed;
893 894 895 896 897 898 899 900 901 902
}

/** See GConf API documentation */
int
gconf_value_get_int(const GConfValue *self)
{
  return (self->type == GCONF_VALUE_INT) ? self->data.i : 0;
}

/** See GConf API documentation */
903
bool
904 905
gconf_value_set_int(GConfValue *self, gint val)
{
906 907 908
  bool changed = false;

  if( self->type != GCONF_VALUE_INT )
909
  {
910
    gconf_log_error("not an int value");
911
  }
912
  else if( self->data.i != val )
913
  {
914 915
    self->data.i = val;
    changed = true;
916
  }
917 918

  return changed;
919 920 921 922 923 924 925 926 927 928
}

/** See GConf API documentation */
double
gconf_value_get_float(const GConfValue *self)
{
  return (self->type == GCONF_VALUE_FLOAT) ? self->data.f : 0;
}

/** See GConf API documentation */
929
bool
930 931
gconf_value_set_float(GConfValue *self, double val)
{
932 933 934
  bool changed = false;

  if( self->type != GCONF_VALUE_FLOAT )
935
  {
936
    gconf_log_error("not a float value");
937
  }
938
  else if( self->data.f != val )
939
  {
940 941
    self->data.f = val;
    changed = true;
942
  }
943 944

  return changed;
945 946 947 948 949 950 951 952 953 954
}

/** See GConf API documentation */
const char *
gconf_value_get_string(const GConfValue *self)
{
  return (self->type == GCONF_VALUE_STRING) ? self->data.s : 0;
}

/** See GConf API documentation */
955
bool
956 957
gconf_value_set_string(GConfValue *self, const char *val)
{
958 959 960
  bool changed = false;

  if( self->type != GCONF_VALUE_STRING )
961
  {
962
    gconf_log_error("not a string value");
963
  }
964
  else if( !eq(self->data.s, val) )
965
  {
966 967
    free(self->data.s), self->data.s = val ? strdup(val) : 0;
    changed = true;
968
  }
969 970

  return changed;
971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992
}

/** See GConf API documentation */
GConfValueType
gconf_value_get_list_type(const GConfValue *self)
{
  return self->list_type;
}

/** See GConf API documentation */
void
gconf_value_set_list_type(GConfValue *self, GConfValueType list_type)
{
  switch( list_type )
  {
  case GCONF_VALUE_STRING:
  case GCONF_VALUE_INT:
  case GCONF_VALUE_FLOAT:
  case GCONF_VALUE_BOOL:
    break;

  default:
993
    gconf_log_error("list type can't be %s", gconf_type_repr(list_type));
994 995 996 997 998
    goto cleanup;
  }

  if( self->type != GCONF_VALUE_LIST )
  {
999
    gconf_log_error("not a list value");
1000 1001 1002 1003 1004 1005 1006 1007 1008 1009
    goto cleanup;
  }

  if( self->list_type == GCONF_VALUE_INVALID )
  {
    self->list_type = list_type;
  }

  if( self->list_type != list_type )
  {
1010
    gconf_log_error("list type already set");
1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025
    goto cleanup;
  }

cleanup:
  return;
}

/** See GConf API documentation */
GSList *
gconf_value_get_list(const GConfValue *self)
{
  return self->list_head;
}

/** See GConf API documentation */
1026
bool
1027 1028
gconf_value_set_list(GConfValue *self, GSList *list)
{
1029 1030 1031 1032
  // TODO: proper list compare would be saner, but for now
  // list has changed if string representation changes ...
  char *prev = gconf_value_str(self);

1033 1034 1035 1036 1037 1038
  self->list_head = gconf_value_list_free(self->list_head);

  if( gconf_value_list_validata(list, self->list_type) )
  {
    self->list_head = gconf_value_list_copy(list);
  }
1039 1040 1041 1042 1043 1044 1045

  char *curr = gconf_value_str(self);
  bool changed = !eq(prev, curr);
  free(curr);
  free(prev);

  return changed;
1046 1047 1048 1049 1050 1051 1052 1053
}

/* ========================================================================= *
 *
 * GConfEntry
 *
 * ========================================================================= */

1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073
static
void
gconf_entry_free(GConfEntry *self)
{
  if( self )
  {
    gconf_value_free(self->value);
    free(self->key);
    free(self->def);
    free(self);
  }
}

static
void
gconf_entry_free_cb(gpointer self)
{
  gconf_entry_free(self);
}

1074 1075 1076 1077 1078 1079 1080
/** Create a GConfEntry object */
static
GConfEntry *
gconf_entry_init(const char *key, const char *type, const char *data)
{
  GConfEntry *self = calloc(1, sizeof *self);
  self->key = strdup(key);
1081
  self->def = data ? strdup(data) : 0;
1082 1083 1084 1085 1086 1087 1088 1089 1090 1091

  GConfValueType ltype = GCONF_VALUE_INVALID;
  GConfValueType vtype = gconf_parse_type(type[0]);

  if( vtype == GCONF_VALUE_LIST )
  {
    ltype = gconf_parse_type(type[1]);
  }

  self->value = gconf_value_init(vtype, ltype, data);
1092 1093 1094 1095

  self->notify_entered = false;
  self->notify_changed = false;

1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126
  return self;
}

/** See GConf API documentation */
const char *
gconf_entry_get_key(const GConfEntry *entry)
{
  return entry ? entry->key : 0;
}

/** See GConf API documentation */
GConfValue *
gconf_entry_get_value(const GConfEntry *entry)
{
  return entry ? entry->value : 0;
}

/* ========================================================================= *
 *
 * DATABASE
 *
 * ========================================================================= */

/** Built-in set of supported keys and default values */
typedef struct
{
  const char *key;
  const char *type;
  const char *def;
} setting_t;

1127 1128 1129 1130 1131 1132 1133 1134 1135
/** Custom stringify macro for comma separated lists
 *
 * G_STRINGIFY() uses standard two phase expansion - which
 * does not work with comma separated lists. Using gcc
 * pre-prosessor extension allows also those to work.
 */
#define CUSTOM_STRINGIFY2(v...) #v
#define CUSTOM_STRINGIFY(v) CUSTOM_STRINGIFY2(v)

1136 1137 1138
static const setting_t gconf_defaults[] =
{
  {
1139
    .key  = MCE_SETTING_EM_ENABLE_PSM,
1140
    .type = "b",
1141
    .def  = G_STRINGIFY(MCE_DEFAULT_EM_ENABLE_PSM),
1142 1143
  },
  {
1144
    .key  = MCE_SETTING_EM_FORCED_PSM,
1145
    .type = "b",
1146
    .def  = G_STRINGIFY(MCE_DEFAULT_EM_FORCED_PSM),
1147 1148
  },
  {
1149
    .key  = MCE_SETTING_EM_PSM_THRESHOLD,
1150
    .type = "i",
1151
    .def  = G_STRINGIFY(MCE_DEFAULT_EM_PSM_THRESHOLD),
1152 1153
  },
  {
1154
    .key  = MCE_SETTING_EM_POSSIBLE_PSM_THRESHOLDS,
1155
    .type = "ai",
1156
    .def  = CUSTOM_STRINGIFY(MCE_DEFAULT_EM_POSSIBLE_PSM_THRESHOLDS),
1157 1158
  },
  {
1159
    .key  = MCE_SETTING_DISPLAY_ALS_ENABLED,
1160
    .type = "b",
1161
    .def  = G_STRINGIFY(MCE_DEFAULT_DISPLAY_ALS_ENABLED),
1162 1163
  },
  {
1164
    .key  = MCE_SETTING_DISPLAY_ALS_AUTOBRIGHTNESS,
1165
    .type = "b",
1166
    .def  = G_STRINGIFY(MCE_DEFAULT_DISPLAY_ALS_AUTOBRIGHTNESS),
1167
  },
1168
  {
1169
    .key  = MCE_SETTING_DISPLAY_ALS_INPUT_FILTER,
1170
    .type = "s",
1171
    .def  = MCE_DEFAULT_DISPLAY_ALS_INPUT_FILTER,
1172 1173
  },
  {
1174
    .key  = MCE_SETTING_DISPLAY_ALS_SAMPLE_TIME,
1175
    .type = "i",
1176
    .def  = G_STRINGIFY(MCE_DEFAULT_DISPLAY_ALS_SAMPLE_TIME),
1177
  },
1178
  {
1179
    .key  = MCE_SETTING_DISPLAY_COLOR_PROFILE,
1180 1181 1182
    .type = "s",
    .def  = "",
  },
1183
  {
1184
    .key  = MCE_SETTING_DISPLAY_DIM_TIMEOUT,
1185
    .type = "i",
1186
    .def  = G_STRINGIFY(MCE_DEFAULT_DISPLAY_DIM_TIMEOUT),
1187 1188
  },
  {
1189
    .key  = MCE_SETTING_DISPLAY_DIM_WITH_KEYBOARD_TIMEOUT,
1190
    .type = "i",
1191
    .def  = G_STRINGIFY(MCE_DEFAULT_DISPLAY_DIM_WITH_KEYBOARD_TIMEOUT),
1192 1193
  },
  {
1194
    .key  = MCE_SETTING_DISPLAY_BLANK_TIMEOUT,
1195
    .type = "i",
1196
    .def  = G_STRINGIFY(MCE_DEFAULT_DISPLAY_BLANK_TIMEOUT),
1197 1198
  },
  {
1199
    .key  = MCE_SETTING_DISPLAY_BLANK_FROM_LOCKSCREEN_TIMEOUT,
1200
    .type = "i",
1201
    .def  = G_STRINGIFY(MCE_DEFAULT_DISPLAY_BLANK_FROM_LOCKSCREEN_TIMEOUT),
1202 1203
  },
  {
1204
    .key  = MCE_SETTING_DISPLAY_BLANK_FROM_LPM_ON_TIMEOUT,
1205
    .type = "i",
1206
    .def  = G_STRINGIFY(MCE_DEFAULT_DISPLAY_BLANK_FROM_LPM_ON_TIMEOUT),
1207 1208
  },
  {
1209
    .key  = MCE_SETTING_DISPLAY_BLANK_FROM_LPM_OFF_TIMEOUT,
1210
    .type = "i",
1211
    .def  = G_STRINGIFY(MCE_DEFAULT_DISPLAY_BLANK_FROM_LPM_OFF_TIMEOUT),
1212
  },
spiiroin's avatar
spiiroin committed
1213
  {
1214
    .key  = MCE_SETTING_DISPLAY_NEVER_BLANK,
spiiroin's avatar
spiiroin committed
1215
    .type = "i",
1216
    .def  = G_STRINGIFY(MCE_DEFAULT_DISPLAY_NEVER_BLANK),
spiiroin's avatar
spiiroin committed
1217
  },
1218
  {
1219
    .key  = MCE_SETTING_DISPLAY_BRIGHTNESS,
1220
    .type = "i",
1221
    .def  = G_STRINGIFY(MCE_DEFAULT_DISPLAY_BRIGHTNESS),
1222 1223
  },
  {
1224
    .key  = MCE_SETTING_DISPLAY_BRIGHTNESS_LEVEL_SIZE,
1225
    .type = "i",
1226
    .def  = G_STRINGIFY(MCE_DEFAULT_DISPLAY_BRIGHTNESS_LEVEL_SIZE),
1227 1228
  },
  {
1229
    .key  = MCE_SETTING_DISPLAY_BRIGHTNESS_LEVEL_COUNT,
1230
    .type = "i",
1231
    .def  = G_STRINGIFY(MCE_DEFAULT_DISPLAY_BRIGHTNESS_LEVEL_COUNT),
1232
  },
1233
  {
1234
    .key  = MCE_SETTING_DISPLAY_DIM_STATIC_BRIGHTNESS,
1235
    .type = "i",
1236
    .def  = G_STRINGIFY(MCE_DEFAULT_DISPLAY_DIM_STATIC_BRIGHTNESS)
1237 1238
  },
  {
1239
    .key  = MCE_SETTING_DISPLAY_DIM_DYNAMIC_BRIGHTNESS,
1240
    .type = "i",
1241
    .def  = G_STRINGIFY(MCE_DEFAULT_DISPLAY_DIM_DYNAMIC_BRIGHTNESS)
1242 1243
  },
  {
1244
    .key  = MCE_SETTING_DISPLAY_DIM_COMPOSITOR_LO,
1245
    .type = "i",
1246
    .def  = G_STRINGIFY(MCE_DEFAULT_DISPLAY_DIM_COMPOSITOR_LO)
1247 1248
  },
  {
1249
    .key  = MCE_SETTING_DISPLAY_DIM_COMPOSITOR_HI,
1250
    .type = "i",
1251
    .def  = G_STRINGIFY(MCE_DEFAULT_DISPLAY_DIM_COMPOSITOR_HI)
1252
  },
1253
  {
1254
    .key  = MCE_SETTING_DISPLAY_DIM_TIMEOUT_LIST,
1255
    .type = "ai",
1256
    .def  = CUSTOM_STRINGIFY(MCE_DEFAULT_DISPLAY_DIM_TIMEOUT_LIST),
1257
  },
1258
  {
1259
    .key  = MCE_SETTING_ORIENTATION_SENSOR_ENABLED,
1260
    .type = "b",
1261
    .def  = G_STRINGIFY(MCE_DEFAULT_ORIENTATION_SENSOR_ENABLED),
1262
  },
1263
  {
1264
    .key  = MCE_SETTING_FLIPOVER_GESTURE_ENABLED,
1265
    .type = "b",
1266
    .def  = G_STRINGIFY(MCE_DEFAULT_FLIPOVER_GESTURE_ENABLED),
1267 1268
  },
  {
1269
    .key  = MCE_SETTING_ORIENTATION_CHANGE_IS_ACTIVITY,
1270
    .type = "b",
1271
    .def  = G_STRINGIFY(MCE_DEFAULT_ORIENTATION_CHANGE_IS_ACTIVITY),
1272
  },
1273
  {
1274
    .key  = MCE_SETTING_DISPLAY_BLANKING_PAUSE_MODE,
1275
    .type = "i",
1276
    .def  = G_STRINGIFY(MCE_DEFAULT_DISPLAY_BLANKING_PAUSE_MODE),
1277
  },
1278
  {
1279
    .key  = MCE_SETTING_DISPLAY_BLANK_TIMEOUT_LIST,
1280
    .type = "ai",
1281
    .def  = CUSTOM_STRINGIFY(MCE_DEFAULT_DISPLAY_BLANK_TIMEOUT_LIST),
1282 1283
  },
  {
1284
    .key  = MCE_SETTING_DISPLAY_ADAPTIVE_DIMMING,
1285
    .type = "b",
1286
    .def  = G_STRINGIFY(MCE_DEFAULT_DISPLAY_ADAPTIVE_DIMMING),
1287 1288
  },
  {
1289
    .key  = MCE_SETTING_DISPLAY_ADAPTIVE_DIM_THRESHOLD,
1290
    .type = "i",
1291
    .def  = G_STRINGIFY(MCE_DEFAULT_DISPLAY_ADAPTIVE_DIM_THRESHOLD),
1292 1293
  },
  {
1294
    .key  = MCE_SETTING_USE_LOW_POWER_MODE,
1295
    .type = "b",
1296
    .def  = G_STRINGIFY(MCE_DEFAULT_USE_LOW_POWER_MODE),
1297 1298
  },
  {
1299
    .key  = MCE_SETTING_TK_AUTOLOCK_ENABLED,
1300
    .type = "b",
1301
    .def  = G_STRINGIFY(MCE_DEFAULT_TK_AUTOLOCK_ENABLED),
1302
  },
1303
  {
1304
    .key  = MCE_SETTING_TK_INPUT_POLICY_ENABLED,
1305
    .type = "b",
1306
    .def  = G_STRINGIFY(MCE_DEFAULT_TK_INPUT_POLICY_ENABLED),
1307
  },
1308
  {
1309
    .key  = MCE_SETTING_TK_VOLKEY_POLICY,
1310
    .type = "i",
1311
    .def  = G_STRINGIFY(MCE_DEFAULT_TK_VOLKEY_POLICY),
1312
  },
1313
  {
1314
    .key  = MCE_SETTING_TK_LPMUI_TRIGGERING,
1315
    .type = "i",
1316
    .def  = G_STRINGIFY(MCE_DEFAULT_TK_LPMUI_TRIGGERING),
1317
  },
1318
  {
1319
    .key  = MCE_SETTING_TK_PROXIMITY_BLOCKS_TOUCH,
1320
    .type = "b",
1321
    .def  = G_STRINGIFY(MCE_DEFAULT_TK_PROXIMITY_BLOCKS_TOUCH),
1322
  },
1323
  {
1324
    .key  = MCE_SETTING_TK_DEVICELOCK_IN_LOCKSCREEN,
1325
    .type = "b",
1326
    .def  = G_STRINGIFY(MCE_DEFAULT_TK_DEVICELOCK_IN_LOCKSCREEN),
1327
  },
1328
  {
1329
    .key  = MCE_SETTING_TK_LID_SENSOR_ENABLED,
1330
    .type = "b",
1331
    .def  = G_STRINGIFY(MCE_DEFAULT_TK_LID_SENSOR_ENABLED),
1332
  },
1333
  {
1334
    .key  = MCE_SETTING_TK_FILTER_LID_WITH_ALS,
1335
    .type = "b",
1336
    .def  = G_STRINGIFY(MCE_DEFAULT_TK_FILTER_LID_WITH_ALS),
1337
  },
1338
  {
1339
    .key  = MCE_SETTING_TK_FILTER_LID_ALS_LIMIT,
1340
    .type = "i",
1341
    .def  = G_STRINGIFY(MCE_DEFAULT_TK_FILTER_LID_ALS_LIMIT),
1342
  },
1343
  {
1344
    .key  = MCE_SETTING_TK_LID_OPEN_ACTIONS,
1345
    .type = "i",
1346
    .def  = G_STRINGIFY(MCE_DEFAULT_TK_LID_OPEN_ACTIONS),
1347 1348
  },
  {
1349
    .key  = MCE_SETTING_TK_LID_CLOSE_ACTIONS,
1350
    .type = "i",
1351
    .def  = G_STRINGIFY(MCE_DEFAULT_TK_LID_CLOSE_ACTIONS),
1352
  },
1353
  {
1354
    .key  = MCE_SETTING_TK_KBD_OPEN_TRIGGER,
1355
    .type = "i",
1356
    .def  = G_STRINGIFY(MCE_DEFAULT_TK_KBD_OPEN_TRIGGER),
1357 1358
  },
  {
1359
    .key  = MCE_SETTING_TK_KBD_OPEN_ACTIONS,
1360
    .type = "i",
1361
    .def  = G_STRINGIFY(MCE_DEFAULT_TK_KBD_OPEN_ACTIONS),
1362 1363
  },
  {
1364
    .key  = MCE_SETTING_TK_KBD_CLOSE_TRIGGER,
1365
    .type = "i",
1366
    .def  = G_STRINGIFY(MCE_DEFAULT_TK_KBD_CLOSE_TRIGGER),
1367 1368
  },
  {
1369
    .key  = MCE_SETTING_TK_KBD_CLOSE_ACTIONS,
1370
    .type = "i",
1371
    .def  = G_STRINGIFY(MCE_DEFAULT_TK_KBD_CLOSE_ACTIONS),
1372
  },
1373
  {
1374
    .key  = MCE_SETTING_TK_AUTOLOCK_DELAY,
1375
    .type = "i",
1376
    .def  = G_STRINGIFY(MCE_DEFAULT_TK_AUTOLOCK_DELAY),
1377
  },
1378
  {
1379
    .key  = MCE_SETTING_BLANKING_INHIBIT_MODE,
1380
    .type = "i",
1381
    .def  = G_STRINGIFY(MCE_DEFAULT_BLANKING_INHIBIT_MODE),
1382
  },
1383
  {
1384
    .key  = MCE_SETTING_KBD_SLIDE_INHIBIT,
1385
    .type = "i",
1386
    .def  = G_STRINGIFY(MCE_DEFAULT_KBD_SLIDE_INHIBIT),
1387
  },
1388
  {
1389
    .key  = MCE_SETTING_USE_AUTOSUSPEND,
1390
    .type = "i",
1391
    .def  = G_STRINGIFY(MCE_DEFAULT_USE_AUTOSUSPEND),
1392
  },
1393
  {
1394
    .key  = MCE_SETTING_CPU_SCALING_GOVERNOR,
1395
    .type = "i",
1396
    .def  = G_STRINGIFY(MCE_DEFAULT_CPU_SCALING_GOVERNOR),
1397
  },
1398
  {
1399
    .key  = MCE_SETTING_LIPSTICK_CORE_DELAY,
1400
    .type = "i",
1401
    .def  = G_STRINGIFY(MCE_DEFAULT_LIPSTICK_CORE_DELAY),
1402
  },
1403
  {
1404
    .key  = MCE_SETTING_BRIGHTNESS_FADE_DEFAULT_MS,
1405
    .type = "i",
1406
    .def  = G_STRINGIFY(MCE_DEFAULT_BRIGHTNESS_FADE_DEFAULT_MS),
1407 1408
  },
  {
1409
    .key  = MCE_SETTING_BRIGHTNESS_FADE_DIMMING_MS,
1410
    .type = "i",
1411
    .def  = G_STRINGIFY(MCE_DEFAULT_BRIGHTNESS_FADE_DIMMING_MS),
1412 1413
  },
  {
1414
    .key  = MCE_SETTING_BRIGHTNESS_FADE_ALS_MS,
1415
    .type = "i",
1416
    .def  = G_STRINGIFY(MCE_DEFAULT_BRIGHTNESS_FADE_ALS_MS),
1417 1418
  },
  {
1419
    .key  = MCE_SETTING_BRIGHTNESS_FADE_BLANK_MS,
1420
    .type = "i",
1421
    .def  = G_STRINGIFY(MCE_DEFAULT_BRIGHTNESS_FADE_BLANK_MS),
1422 1423
  },
  {
1424
    .key  = MCE_SETTING_BRIGHTNESS_FADE_UNBLANK_MS,
1425
    .type = "i",
1426
    .def  = G_STRINGIFY(MCE_DEFAULT_BRIGHTNESS_FADE_UNBLANK_MS),
1427
  },
1428
  {
1429
    .key  = MCE_SETTING_DISPLAY_OFF_OVERRIDE,
1430
    .type = "i",
1431
    .def  = G_STRINGIFY(MCE_DEFAULT_DISPLAY_OFF_OVERRIDE),
1432
  },
1433
  {
1434
    .key  = MCE_SETTING_TK_AUTO_BLANK_DISABLE,
1435
    .type = "i",
1436
    .def  = G_STRINGIFY(MCE_DEFAULT_TK_AUTO_BLANK_DISABLE),
1437
  },
1438 1439
#ifdef ENABLE_DOUBLETAP_EMULATION
  {
1440
    .key  = MCE_SETTING_USE_FAKE_DOUBLETAP,
1441
    .type = "b",
1442
    .def  = G_STRINGIFY(MCE_DEFAULT_USE_FAKE_DOUBLETAP),
1443 1444
  },
#endif
1445
  {
1446
    .key  = MCE_SETTING_TOUCH_UNBLOCK_DELAY,
1447
    .type = "i",
1448
    .def  = G_STRINGIFY(MCE_DEFAULT_TOUCH_UNBLOCK_DELAY),
1449
  },
1450
  {
1451
    .key  = MCE_SETTING_INPUT_GRAB_ALLOWED,
1452
    .type = "i",
1453
    .def  = G_STRINGIFY(MCE_DEFAULT_INPUT_GRAB_ALLOWED),
1454
  },
1455
  {
1456
    .key  = MCE_SETTING_LED_PATH"/"MCE_LED_PATTERN_BATTERY_CHARGING,
1457
    .type = "b",
1458
    .def  = G_STRINGIFY(MCE_DEFAULT_LED_PATTERN_ENABLED),
1459 1460
  },
  {
1461
    .key  = MCE_SETTING_LED_PATH"/"MCE_LED_PATTERN_BATTERY_FULL,
1462
    .type = "b",
1463
    .def  = G_STRINGIFY(MCE_DEFAULT_LED_PATTERN_ENABLED),
1464 1465
  },
  {
1466
    .key  = MCE_SETTING_LED_PATH"/"MCE_LED_PATTERN_COMMUNICATION_EVENT,
1467
    .type = "b",
1468
    .def  = G_STRINGIFY(MCE_DEFAULT_LED_PATTERN_ENABLED),
1469 1470
  },
  {
1471
    .key  = MCE_SETTING_LED_PATH"/"MCE_LED_PATTERN_POWER_OFF,
1472
    .type = "b",
1473
    .def  = G_STRINGIFY(MCE_DEFAULT_LED_PATTERN_ENABLED),
1474 1475
  },
  {
1476
    .key  = MCE_SETTING_LED_PATH"/"MCE_LED_PATTERN_POWER_ON,
1477
    .type = "b",
1478
    .def  = G_STRINGIFY(MCE_DEFAULT_LED_PATTERN_ENABLED),
1479 1480
  },
  {
1481
    .key  = MCE_SETTING_LED_PATH"/"MCE_LED_PATTERN_CAMERA,
1482
    .type = "b",
1483
    .def  = G_STRINGIFY(MCE_DEFAULT_LED_PATTERN_ENABLED),
1484 1485
  },
  {
1486
    .key  = MCE_SETTING_LED_PATH"/"MCE_LED_PATTERN_DEVICE_ON,
1487
    .type = "b",
1488
    .def  = G_STRINGIFY(MCE_DEFAULT_LED_PATTERN_ENABLED),
1489 1490
  },
  {
1491
    .key  = MCE_SETTING_LED_PATH"/"MCE_LED_PATTERN_BATTERY_LOW,
1492
    .type = "b",
1493
    .def  = G_STRINGIFY(MCE_DEFAULT_LED_PATTERN_ENABLED),
1494 1495
  },
  {
1496
    .key  = MCE_SETTING_LED_PATH"/"MCE_LED_PATTERN_COMMUNICATION_EVENT_BATTERY_FULL,
1497
    .type = "b",
1498
    .def  = G_STRINGIFY(MCE_DEFAULT_LED_PATTERN_ENABLED),
1499
  },
1500
  {
1501
    .key  = MCE_SETTING_LED_PATH"/"MCE_LED_PATTERN_BATTERY_CHARGING_FLAT,
1502
    .type = "b",
1503
    .def  = G_STRINGIFY(MCE_DEFAULT_LED_PATTERN_ENABLED),
1504
  },
1505
  {
1506
    .key  = MCE_SETTING_LED_PATH"/"MCE_LED_PATTERN_COMMON_NOTIFICATION,
1507
    .type = "b",
1508
    .def  = G_STRINGIFY(MCE_DEFAULT_LED_PATTERN_ENABLED),
1509 1510
  },
  {
1511
    .key  = MCE_SETTING_LED_PATH"/"MCE_LED_PATTERN_COMMUNICATION_CALL,
1512
    .type