gboolean prefs_add_alias(const char * const name, const char * const value) { if (g_key_file_has_key(prefs, PREF_GROUP_ALIAS, name, NULL)) { return FALSE; } else { g_key_file_set_string(prefs, PREF_GROUP_ALIAS, name, value); _save_prefs(); return TRUE; } }
void get_icon_theme() { if (g_key_file_has_key(keyFile,"PNMixer","IconTheme",NULL)) { gchar* theme_name = g_key_file_get_string(keyFile,"PNMixer","IconTheme",NULL); if (icon_theme == NULL || (icon_theme == gtk_icon_theme_get_default())) icon_theme = gtk_icon_theme_new(); gtk_icon_theme_set_custom_theme(icon_theme,theme_name); g_free(theme_name); } else icon_theme = gtk_icon_theme_get_default(); }
char* plugin_settings_get_string(const char *const group, const char *const key, const char *const def) { if (group && key && g_key_file_has_key(settings, group, key, NULL)) { return g_key_file_get_string(settings, group, key, NULL); } else if (def) { return strdup(def); } else { return NULL; } }
gboolean prefs_remove_alias(const char * const name) { if (!g_key_file_has_key(prefs, PREF_GROUP_ALIAS, name, NULL)) { return FALSE; } else { g_key_file_remove_key(prefs, PREF_GROUP_ALIAS, name, NULL); _save_prefs(); return TRUE; } }
gboolean maki_instance_config_exists (makiInstance* inst, gchar const* group, gchar const* key) { gboolean ret; g_mutex_lock(inst->mutex.config); ret = g_key_file_has_key(inst->key_file, group, key, NULL); g_mutex_unlock(inst->mutex.config); return ret; }
/** * Updates the alignment of the volume text which is shown on the * volume popup_window (left click) around the scroll bar. */ void update_vol_text() { gboolean show = TRUE; if (g_key_file_has_key(keyFile,"PNMixer","DisplayTextVolume",NULL)) show = g_key_file_get_boolean(keyFile,"PNMixer","DisplayTextVolume",NULL); if (show) { GtkPositionType pos = GTK_POS_RIGHT; if (g_key_file_has_key(keyFile,"PNMixer","TextVolumePosition",NULL)) { gint pi = g_key_file_get_integer(keyFile,"PNMixer","TextVolumePosition",NULL); pos = pi==0?GTK_POS_TOP: pi==1?GTK_POS_BOTTOM: pi==2?GTK_POS_LEFT: GTK_POS_RIGHT; } gtk_scale_set_draw_value (GTK_SCALE (vol_scale), TRUE); gtk_scale_set_value_pos (GTK_SCALE (vol_scale), pos); } else gtk_scale_set_draw_value (GTK_SCALE (vol_scale), FALSE); }
char moloch_config_boolean(GKeyFile *keyfile, char *key, char d) { gboolean value = d; if (!keyfile) keyfile = molochKeyFile; if (g_key_file_has_key(keyfile, config.nodeName, key, NULL)) { value = g_key_file_get_boolean(keyfile, config.nodeName, key, NULL); } else if (config.nodeClass && g_key_file_has_key(keyfile, config.nodeClass, key, NULL)) { value = g_key_file_get_boolean(keyfile, config.nodeClass, key, NULL); } else if (g_key_file_has_key(keyfile, "default", key, NULL)) { value = g_key_file_get_boolean(keyfile, "default", key, NULL); } if (config.debug) { LOG("%s=%s", key, value?"true": "false"); } return value; }
int plugin_settings_string_list_clear(const char *const group, const char *const key) { if (!g_key_file_has_key(settings, group, key, NULL)) { return 0; } g_key_file_remove_key(settings, group, key, NULL); _save_settings(); return 1; }
/** * gcr_secret_exchange_receive: * @self: a #GcrSecretExchange object * @exchange: the string received * * Receive a string from the other side of secret exchange. This string will * have been created by gcr_secret_exchange_begin() or gcr_secret_exchange_send(). * * After this call completes successfully the value returned from * gcr_secret_exchange_get_secret() will have changed. * * Returns: whether the string was successfully parsed and received */ gboolean gcr_secret_exchange_receive (GcrSecretExchange *self, const gchar *exchange) { GcrSecretExchangeClass *klass; gchar *secret = NULL; gsize n_secret = 0; GKeyFile *input; gboolean ret; g_return_val_if_fail (GCR_IS_SECRET_EXCHANGE (self), FALSE); g_return_val_if_fail (exchange != NULL, FALSE); klass = GCR_SECRET_EXCHANGE_GET_CLASS (self); g_return_val_if_fail (klass->generate_exchange_key, FALSE); g_return_val_if_fail (klass->derive_transport_key, FALSE); /* Parse the input */ input = g_key_file_new (); if (!g_key_file_load_from_data (input, exchange, strlen (exchange), G_KEY_FILE_NONE, NULL)) { g_key_file_free (input); g_message ("couldn't parse secret exchange data"); return FALSE; } if (!self->pv->generated) { if (!(klass->generate_exchange_key) (self, GCR_SECRET_EXCHANGE_PROTOCOL_1, &self->pv->publi, &self->pv->n_publi)) g_return_val_if_reached (FALSE); self->pv->generated = TRUE; } ret = TRUE; if (!self->pv->derived) { if (!derive_key (self, input)) ret = FALSE; } if (ret && g_key_file_has_key (input, GCR_SECRET_EXCHANGE_PROTOCOL_1, "secret", NULL)) ret = perform_decrypt (self, input, (guchar **)&secret, &n_secret); if (ret) { egg_secure_free (self->pv->secret); self->pv->secret = secret; self->pv->n_secret = n_secret; } g_key_file_free (input); return ret; }
gboolean nm_keyfile_plugin_kf_has_key (GKeyFile *kf, const char *group, const char *key, GError **error) { gboolean has; const char *alias; GError *local = NULL; has = g_key_file_has_key (kf, group, key, &local); if (g_error_matches (local, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_GROUP_NOT_FOUND)) { alias = nm_keyfile_plugin_get_alias_for_setting_name (group); if (alias) { g_clear_error (&local); has = g_key_file_has_key (kf, alias, key, &local); } } if (local) g_propagate_error (error, local); return has; }
gchar *moloch_config_str(GKeyFile *keyfile, char *key, char *d) { if (!keyfile) keyfile = molochKeyFile; if (g_key_file_has_key(keyfile, config.nodeName, key, NULL)) { return g_key_file_get_string(keyfile, config.nodeName, key, NULL); } if (config.nodeClass && g_key_file_has_key(keyfile, config.nodeClass, key, NULL)) { return g_key_file_get_string(keyfile, config.nodeClass, key, NULL); } if (g_key_file_has_key(keyfile, "default", key, NULL)) { return g_key_file_get_string(keyfile, "default", key, NULL); } if (!d) return NULL; return g_strdup(d); }
gboolean prefs_get_boolean(preference_t pref) { const char *group = _get_group(pref); const char *key = _get_key(pref); gboolean def = _get_default_boolean(pref); if (!g_key_file_has_key(prefs, group, key, NULL)) { return def; } return g_key_file_get_boolean(prefs, group, key, NULL); }
uint32_t moloch_config_int(GKeyFile *keyfile, char *key, uint32_t d, uint32_t min, uint32_t max) { uint32_t value = d; if (!keyfile) keyfile = molochKeyFile; if (g_key_file_has_key(keyfile, config.nodeName, key, NULL)) { value = g_key_file_get_integer(keyfile, config.nodeName, key, NULL); } else if (config.nodeClass && g_key_file_has_key(keyfile, config.nodeClass, key, NULL)) { value = g_key_file_get_integer(keyfile, config.nodeClass, key, NULL); } else if (g_key_file_has_key(keyfile, "default", key, NULL)) { value = g_key_file_get_integer(keyfile, "default", key, NULL); } if (value < min) value = min; if (value > max) value = max; return value; }
bool ConfigFile::loadStringList(std::list <std::string> &variable, const std::string §ion, const std::string &key) { char **bind; variable.clear(); if (g_key_file_has_key(keyfile, section.c_str(), key.c_str(), NULL)) { bind = g_key_file_get_string_list(keyfile, section.c_str(), key.c_str(), NULL, NULL); for (int i = 0; bind[i]; i++) { variable.push_back(bind[i]); } g_strfreev (bind); return true; } return false; }
double moloch_config_double(GKeyFile *keyfile, char *key, double d, double min, double max) { double value = d; if (!keyfile) keyfile = molochKeyFile; if (g_key_file_has_key(keyfile, config.nodeName, key, NULL)) { value = g_key_file_get_double(keyfile, config.nodeName, key, NULL); } else if (config.nodeClass && g_key_file_has_key(keyfile, config.nodeClass, key, NULL)) { value = g_key_file_get_double(keyfile, config.nodeClass, key, NULL); } else if (g_key_file_has_key(keyfile, "default", key, NULL)) { value = g_key_file_get_double(keyfile, "default", key, NULL); } if (value < min) value = min; if (value > max) value = max; return value; }
bool ConfigFile::loadBoolean(bool &variable, const std::string §ion, const std::string &key, bool def, bool required) { if (g_key_file_has_key(keyfile, section.c_str(), key.c_str(), NULL)) variable = g_key_file_get_boolean(keyfile, section.c_str(), key.c_str(), NULL); else { if (required) { Log("loadConfigFile", "You have to specify `" << key << "` in [" << section << "] section of config file."); return false; } else variable = def; } return true; }
void cd_mail_retrieve_pop3_params (CDMailAccount *mailaccount, GKeyFile *pKeyFile, gchar *mailbox_name) { if( !mailaccount || !pKeyFile || !mailbox_name ) return; gboolean bFlushConfFileNeeded = FALSE; mailaccount->driver = POP3_STORAGE; mailaccount->storage = mailstorage_new(NULL); mailaccount->folder = NULL; mailaccount->server = NULL; mailaccount->port = 0; mailaccount->connection_type = CONNECTION_TYPE_PLAIN; mailaccount->user = NULL; mailaccount->password = NULL; mailaccount->auth_type = POP3_AUTH_TYPE_TRY_APOP; mailaccount->path = NULL; mailaccount->timeout = 0; if (g_key_file_has_key (pKeyFile, mailbox_name, "host", NULL)) { mailaccount->server = CD_CONFIG_GET_STRING (mailbox_name, "host"); } if (g_key_file_has_key (pKeyFile, mailbox_name, "username", NULL)) { mailaccount->user = CD_CONFIG_GET_STRING (mailbox_name, "username"); } if (g_key_file_has_key (pKeyFile, mailbox_name, "password", NULL)) { gchar *encryptedPassword = CD_CONFIG_GET_STRING (mailbox_name, "password"); cairo_dock_decrypt_string( encryptedPassword, &(mailaccount->password) ); if( encryptedPassword ) g_free(encryptedPassword); } mailaccount->connection_type = CD_CONFIG_GET_BOOLEAN_WITH_DEFAULT (mailbox_name, "use secure connection", FALSE)?CONNECTION_TYPE_TLS:CONNECTION_TYPE_PLAIN; mailaccount->port = CD_CONFIG_GET_INTEGER_WITH_DEFAULT (mailbox_name, "port", 0); mailaccount->timeout = CD_CONFIG_GET_INTEGER_WITH_DEFAULT (mailbox_name, "timeout mn", 10); }
gint prefs_get_roster_presence_indent(void) { if (!g_key_file_has_key(prefs, PREF_GROUP_UI, "roster.presence.indent", NULL)) { return 2; } gint result = g_key_file_get_integer(prefs, PREF_GROUP_UI, "roster.presence.indent", NULL); if (result < -1) { result = 0; } return result; }
static void load_session_file (const char *id, const char *path) { GKeyFile *key_file; GError *error; gboolean res; GdmSessionFile *session; key_file = g_key_file_new (); error = NULL; res = g_key_file_load_from_file (key_file, path, 0, &error); if (!res) { g_debug ("Failed to load \"%s\": %s\n", path, error->message); g_error_free (error); goto out; } if (! g_key_file_has_group (key_file, G_KEY_FILE_DESKTOP_GROUP)) { goto out; } res = g_key_file_has_key (key_file, G_KEY_FILE_DESKTOP_GROUP, "Name", NULL); if (! res) { g_debug ("\"%s\" contains no \"Name\" key\n", path); goto out; } if (!key_file_is_relevant (key_file)) { g_debug ("\"%s\" is hidden or contains non-executable TryExec program\n", path); goto out; } session = g_new0 (GdmSessionFile, 1); session->id = g_strdup (id); session->path = g_strdup (path); session->translated_name = g_key_file_get_locale_string (key_file, G_KEY_FILE_DESKTOP_GROUP, "Name", NULL, NULL); session->translated_comment = g_key_file_get_locale_string (key_file, G_KEY_FILE_DESKTOP_GROUP, "Comment", NULL, NULL); g_hash_table_insert (gdm_available_sessions_map, g_strdup (id), session); out: g_key_file_free (key_file); }
// which version of erlang is configured for this particular // branch of the dir tree gchar* which_erlang() { gchar* cfgfile = configcheckfromcwd(); if(cfgfile == NULL) { // check for a system root. // if one doesn't exist, return the system_default gchar *sysroot = systemrootcheck_from_cwd(); if(sysroot != NULL) { return sysroot; } else { return get_system_default(); } } else { if(g_file_test(cfgfile, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) { GKeyFile* kf = g_key_file_new(); GError* err = NULL; if(!g_key_file_load_from_file(kf, cfgfile, G_KEY_FILE_NONE, &err)) { if(err != NULL) { g_error("Cannot load %s: %s\n", cfgfile, err->message); } else { g_error("Cannot load %s\n", cfgfile); } } else { if(!g_key_file_has_group(kf, "Config")) { g_error("Config group not defined in %s\n", cfgfile); return NULL; } else { err = NULL; if(g_key_file_has_key(kf, "Config", "Erlang", &err)) { gchar* erlversion = g_key_file_get_string(kf, "Config", "Erlang", &err); g_free(cfgfile); // THIS VALUE MUST BE FREED return erlversion; } else { if(err != NULL) { g_error("Missing Erlang | version: %s\n", err->message); } else { g_error("Missing Erlang | version\n"); } return NULL; } } } } else { return NULL; } } return NULL; }
gchar* get_vol_command() { if (g_key_file_has_key(keyFile,"PNMixer","VolumeControlCommand",NULL)) return g_key_file_get_string(keyFile,"PNMixer","VolumeControlCommand",NULL); else { gchar buf[256]; const char** cmd = vol_cmds; while (*cmd) { snprintf(buf, 256, "which %s | grep /%s > /dev/null",*cmd,*cmd); if (!system(buf)) return g_strdup(*cmd); cmd++; } return NULL; } }
/** * pka_config_get_boolean: * @group: A string containing the group of keys. * @key: A string containing the key within the group. * @default_: An gboolean containing the default value if no value exists. * * Retrieves the value for the key matching @key in the group matching @group. * If the group or key do not exist, then @default_ is returned. * * Returns: A gboolean containing the value found or @default_. * * Side effects: None. */ gboolean pka_config_get_boolean (const gchar *group, const gchar *key, gboolean default_) { g_return_val_if_fail(group != NULL, FALSE); g_return_val_if_fail(key != NULL, FALSE); g_return_val_if_fail(config != NULL, FALSE); ENTRY; if (!g_key_file_has_key(config, group, key, NULL)) { RETURN(default_); } RETURN(g_key_file_get_boolean(config, group, key, NULL)); }
/** * pka_config_get_integer: * @group: A string containing the group of keys. * @key: A string containing the key within the group. * @default_: An integer containing the default value if no value exists. * * Retrieves the value for the key matching @key in the group matching @group. * If the group or key do not exist, then @default_ is returned. * * Returns: An integer containing the value found or @default_. * * Side effects: None. */ gint pka_config_get_integer (const gchar *group, const gchar *key, gint default_) { g_return_val_if_fail(group != NULL, 0); g_return_val_if_fail(key != NULL, 0); g_return_val_if_fail(config != NULL, 0); ENTRY; if (!g_key_file_has_key(config, group, key, NULL)) { RETURN(default_); } RETURN(g_key_file_get_integer(config, group, key, NULL)); }
/** * pka_config_get_string: * @group: A string containing the group of keys. * @key: A string containing the key within the group. * @default_: A string containing the default value if no value exists. * * Retrieves the value for the key matching @key in the group matching @group. * If the group or key do not exist, then a copy of @default_ is returned. * * Returns: A string containing either the value found or a copy of @default_. * The resulting string should be freed with g_free() when it is no longer * used. * * Side effects: None. */ gchar* pka_config_get_string (const gchar *group, const gchar *key, const gchar *default_) { g_return_val_if_fail(group != NULL, NULL); g_return_val_if_fail(key != NULL, NULL); g_return_val_if_fail(config != NULL, NULL); ENTRY; if (!g_key_file_has_key(config, group, key, NULL)) { RETURN(g_strdup(default_)); } RETURN(g_key_file_get_string(config, group, key, NULL)); }
static gboolean check_key (GKeyFile *keyfile, const char *group, const char *key, GError **error) { if (g_key_file_has_key (keyfile, group, key, error)) return TRUE; if (!error) { g_set_error (error, NM_SESSION_MONITOR_ERROR, NM_SESSION_MONITOR_ERROR_MALFORMED_DATABASE, "ConsoleKit database " CKDB_PATH " group '%s' had no '%s' key", group, key); } return FALSE; }
/** * pragha_preferences_remove_key: * */ void pragha_preferences_remove_key (PraghaPreferences *preferences, const gchar *group_name, const gchar *key) { g_return_if_fail(PRAGHA_IS_PREFERENCES(preferences)); if (g_key_file_has_group(preferences->priv->rc_keyfile, group_name) && g_key_file_has_key(preferences->priv->rc_keyfile, group_name, key, NULL)) g_key_file_remove_key(preferences->priv->rc_keyfile, group_name, key, NULL); }
static void load_settings() { const char* session_name = g_getenv("DESKTOP_SESSION"); /* load settings from current session config files */ if(!session_name) session_name = "LXDE"; char* rel_path = g_strconcat("lxsession/", session_name, "/desktop.conf", NULL); char* user_config_file = g_build_filename(g_get_user_config_dir(), rel_path, NULL); GKeyFile* kf = g_key_file_new(); if(!g_key_file_load_from_file(kf, user_config_file, G_KEY_FILE_KEEP_COMMENTS|G_KEY_FILE_KEEP_TRANSLATIONS, NULL)) { g_key_file_load_from_dirs(kf, rel_path, (const char**)g_get_system_config_dirs(), NULL, G_KEY_FILE_KEEP_COMMENTS|G_KEY_FILE_KEEP_TRANSLATIONS, NULL); } g_free(rel_path); int val; val = g_key_file_get_integer(kf, "Mouse", "AccFactor", NULL); if( val > 0) old_accel = accel = val; val = g_key_file_get_integer(kf, "Mouse", "AccThreshold", NULL); if( val > 0) old_threshold = threshold = val; old_left_handed = left_handed = g_key_file_get_boolean(kf, "Mouse", "LeftHanded", NULL); val = g_key_file_get_integer(kf, "Keyboard", "Delay", NULL); if(val > 0) old_delay = delay = val; val = g_key_file_get_integer(kf, "Keyboard", "Interval", NULL); if(val > 0) old_interval = interval = val; if( g_key_file_has_key(kf, "Keyboard", "Beep", NULL ) ) old_beep = beep = g_key_file_get_boolean(kf, "Keyboard", "Beep", NULL); g_key_file_free(kf); g_free(user_config_file); old_dclick = dclick = get_dclick_time (); }
gboolean virt_viewer_file_is_set(VirtViewerFile* self, const gchar* key) { GError *inner_error = NULL; gboolean set; g_return_val_if_fail(VIRT_VIEWER_IS_FILE(self), FALSE); g_return_val_if_fail(key != NULL, FALSE); set = g_key_file_has_key(self->priv->keyfile, MAIN_GROUP, key, &inner_error); if (inner_error == NULL) return set; else { g_clear_error(&inner_error); return FALSE; } }
gint* get_vol_meter_colors() { gsize numcols = 3; gint* vol_meter_clrs = NULL; if (g_key_file_has_key(keyFile,"PNMixer","VolMeterColor",NULL)) vol_meter_clrs = g_key_file_get_integer_list(keyFile,"PNMixer","VolMeterColor",&numcols,NULL); if (!vol_meter_clrs || (numcols != 3)) { if (vol_meter_clrs) { // corrupt value somehow report_error(_("Invalid color for volume meter in config file. Reverting to default.")); g_free(vol_meter_clrs); } vol_meter_clrs = g_malloc(3*sizeof(gint)); vol_meter_clrs[0] = 59624; vol_meter_clrs[1] = 28270; vol_meter_clrs[2] = 28270; } return vol_meter_clrs; }
/** * Updates all status icons for the different volume states like * muted, low, medium, high as well as the volume meter. This * is triggered either by apply_prefs() in the preferences subsystem, * do_alsa_reinit() or tray_icon_resized(). */ void update_status_icons() { int i,icon_width; GdkPixbuf* old_icons[4]; int size = tray_icon_size(); for(i=0;i<4;i++) old_icons[i] = status_icons[i]; if (g_key_file_has_key(keyFile,"PNMixer","IconTheme",NULL)) { status_icons[0] = get_stock_pixbuf("audio-volume-muted",size); status_icons[1] = get_stock_pixbuf("audio-volume-low",size); status_icons[2] = get_stock_pixbuf("audio-volume-medium",size); status_icons[3] = get_stock_pixbuf("audio-volume-high",size); } else { status_icons[0] = create_pixbuf("pnmixer-muted.png"); status_icons[1] = create_pixbuf("pnmixer-low.png"); status_icons[2] = create_pixbuf("pnmixer-medium.png"); status_icons[3] = create_pixbuf("pnmixer-high.png"); } icon_width = gdk_pixbuf_get_height(status_icons[0]); vol_div_factor = ((gdk_pixbuf_get_height(status_icons[0])-10)/100.0); vol_meter_width = 1.25*icon_width; if (vol_meter_width%4 != 0) vol_meter_width -= (vol_meter_width%4); if (!vol_meter_row && g_key_file_get_boolean(keyFile,"PNMixer","DrawVolMeter",NULL)) { int lim = vol_meter_width/4; vol_meter_row = g_malloc(vol_meter_width*sizeof(guchar)); for(i=0;i<lim;i++) { vol_meter_row[i*4] = vol_meter_red; vol_meter_row[i*4+1] = vol_meter_green; vol_meter_row[i*4+2] = vol_meter_blue; vol_meter_row[i*4+3] = 255; } } else if (vol_meter_row && !g_key_file_get_boolean(keyFile,"PNMixer","DrawVolMeter",NULL)) { free(vol_meter_row); vol_meter_row = NULL; if (icon_copy) g_object_unref(icon_copy); icon_copy = NULL; } draw_offset = g_key_file_get_integer(keyFile,"PNMixer","VolMeterPos",NULL); if (tray_icon) get_mute_state(TRUE); for(i = 0;i < 4;i++) if(old_icons[i]) g_object_unref(old_icons[i]); }