Exemplo n.º 1
0
gint
mod_cfg_get_int  (GKeyFile *f, const gchar *sec, const gchar *key, sat_cfg_int_e p)
{
     GError  *error = NULL;
     gint     param;

     /* check whether parameter is present in GKeyFile */
     if (g_key_file_has_key (f, sec, key, NULL)) {

          param = g_key_file_get_integer (f, sec, key, &error);

          if (error != NULL) {

               sat_log_log (SAT_LOG_LEVEL_ERROR,
                         _("%s: Failed to read integer (%s)"),
                         __FUNCTION__, error->message);

               g_clear_error (&error);

               /* get a timeout from global config */
               param = sat_cfg_get_int (p);
          }
     }
     /* get value from sat-cfg */
     else {
          param = sat_cfg_get_int (p);

/*           sat_log_log (SAT_LOG_LEVEL_DEBUG, */
/*                     _("%s: Integer value not found, using default (%d)"), */
/*                     __FUNCTION__, param); */
     }

     return param;
}
Exemplo n.º 2
0
PluginInfoCache::PluginInfoCache()
    : m_cacheFile(g_key_file_new())
    , m_readOnlyMode(false)
{
    GUniquePtr<char> cacheDirectory(g_build_filename(g_get_user_cache_dir(), "webkitgtk", nullptr));
    if (WebCore::makeAllDirectories(cacheDirectory.get())) {
        m_cachePath.reset(g_build_filename(cacheDirectory.get(), "plugins", nullptr));
        g_key_file_load_from_file(m_cacheFile.get(), m_cachePath.get(), G_KEY_FILE_NONE, nullptr);
    }

    if (g_key_file_has_group(m_cacheFile.get(), "schema")) {
        unsigned schemaVersion = static_cast<unsigned>(g_key_file_get_integer(m_cacheFile.get(), "schema", "version", nullptr));
        if (schemaVersion < gSchemaVersion) {
            // Cache file using an old schema, create a new empty file.
            m_cacheFile.reset(g_key_file_new());
        } else if (schemaVersion > gSchemaVersion) {
            // Cache file using a newer schema, use the cache in read only mode.
            m_readOnlyMode = true;
        } else {
            // Same schema version, we don't need to update it.
            return;
        }
    }

    g_key_file_set_integer(m_cacheFile.get(), "schema", "version", static_cast<unsigned>(gSchemaVersion));
}
Exemplo n.º 3
0
void load_int_setting(GKeyFile * f, gint * i, const gchar * key, const gchar * sect)
{
    GError * e = NULL;
    gint ii = g_key_file_get_integer(f,sect,key,&e);
    if (!e)
        *i=ii;
}
Exemplo n.º 4
0
/**
 * Initialization function.
 * @param conf mpdcron's global configuration.
 * @param fd This file descriptor points to mpdcron's configuration file.
 *           Never call g_key_file_free() on this!
 * @return On success this function should return MPDCRON_INIT_SUCCESS.
 *         On failure this function should return MPDCRON_INIT_FAILURE.
 */
int init(G_GNUC_UNUSED const struct mpdcron_config *conf, GKeyFile *fd)
{
	GError *parse_error;

	/* Use mpdcron_log() as logging function.
	 * It's a macro around daemon_log that adds MPDCRON_MODULE as a prefix
	 * to log strings.
	 */
	mpdcron_log(LOG_NOTICE, "Hello from example module!");

	/* Parse configuration here. */
	parse_error = NULL;
	count = g_key_file_get_integer(fd, "example", "count", &parse_error);
	if (parse_error != NULL) {
		switch (parse_error->code) {
			case G_KEY_FILE_ERROR_GROUP_NOT_FOUND:
			case G_KEY_FILE_ERROR_KEY_NOT_FOUND:
				/* ignore */
				g_error_free(parse_error);
				break;
			default:
				mpdcron_log(LOG_ERR, "Parse error: %s", parse_error->message);
				g_error_free(parse_error);
				return MPDCRON_INIT_FAILURE;
		}
	}
	if (count <= 0)
		count = 5;

	last_volume = -1;
	return MPDCRON_INIT_SUCCESS;
}
Exemplo n.º 5
0
bool ConfigFile::loadInteger(int &variable, const std::string &section, const std::string &key, int def) {
	if (g_key_file_has_key(keyfile, section.c_str(), key.c_str(), NULL)) {
		GError *error = NULL;
		variable = (int) g_key_file_get_integer(keyfile, section.c_str(), key.c_str(), &error);
		if (error) {
			if (error->code == G_KEY_FILE_ERROR_INVALID_VALUE) {
				char *value;
				if ((value = g_key_file_get_string(keyfile, section.c_str(), key.c_str(), NULL)) != NULL) {
					if (strcmp( value,"$filename:port") == 0) {
						variable = m_port;
						g_error_free(error);
						return true;
					}
				}
				Log("loadConfigFile", "Value of key `" << key << "` in [" << section << "] section is not integer.");
			}
			g_error_free(error);
			return false;
		}
	}
	else {
		if (def == INT_MAX) {
			Log("loadConfigFile", "You have to specify `" << key << "` in [" << section << "] section of config file.");
			return false;
		}
		else
			variable = def;
	}
	return true;
}
Exemplo n.º 6
0
/* Retrieve an integer property from the preferences ini file. If an error occurs (usually because
   the preferences file does not exist, or the key value is not present, then the default value
   in the g_param_spec is used instead */
static gint
mame_gui_prefs_get_int_property_from_key_file (MameGuiPrefs *pr, gchar *property) {
	GError *error = NULL;
	gint val;
	
	val = g_key_file_get_integer (pr->priv->prefs_ini_file, "Preferences", property, &error);

	if (error) {
		GMAMEUI_DEBUG ("Error retrieving integer UI option %s - %s", property, error->message);
		g_error_free (error);
		error = NULL;

		GParamSpec *spec;
		GValue value = { 0, };

		spec = g_object_class_find_property (G_OBJECT_GET_CLASS (pr), property);
		
		g_value_init (&value, G_TYPE_INT);
		g_param_value_set_default (spec, &value);
		
		val = g_value_get_int (&value);
		GMAMEUI_DEBUG (_("Retrieving default integer value for %s: %i"), property, val);
	}
	
	return val;
}
Exemplo n.º 7
0
static gboolean
get_values (GKeyFile *kfile, const gchar *group,
	    gchar **email, gchar **name, gboolean *personal, size_t *tstamp)
{
	GError *err;
	err = NULL;

	do {
		*email = g_key_file_get_value (kfile, group, EMAIL_KEY, &err);
		if (!*email)
			break;

		*tstamp = (time_t)g_key_file_get_integer (kfile, group,
							  TSTAMP_KEY, &err);
		if (err)
			break;
		*personal = g_key_file_get_boolean (kfile, group,
						    PERSONAL_KEY, NULL);
		*name = g_key_file_get_value (kfile, group, NAME_KEY, NULL);


		return TRUE;

	} while (0);

	g_warning ("error getting value for %s: %s",
		   group, err->message ? err->message: "error");
	g_clear_error (&err);

	return FALSE;
}
DLLIMPORT bool stardict_misc_plugin_init(void)
{
	std::string res = get_cfg_filename();
	if (!g_file_test(res.c_str(), G_FILE_TEST_EXISTS)) {
		g_file_set_contents(res.c_str(), "[update]\nlatest_version_num=0\nlast_prompt_num=0\nversion_msg_title=\nversion_msg_content=\nlatest_news=\n[misc]\nshow_ads=true\n", -1, NULL);
	}
	GKeyFile *keyfile = g_key_file_new();
	g_key_file_load_from_file(keyfile, res.c_str(), G_KEY_FILE_NONE, NULL);
	GError *err;
	err = NULL;
	latest_version_num = g_key_file_get_integer(keyfile, "update", "latest_version_num", &err);
	if (err) {
		g_error_free (err);
		latest_version_num = 0;
	}
	err = NULL;
	last_prompt_num = g_key_file_get_integer(keyfile, "update", "last_prompt_num", &err);
	if (err) {
		g_error_free (err);
		last_prompt_num = 0;
	}
	char *str;
	str = g_key_file_get_string(keyfile, "update", "version_msg_title", NULL);
	if (str) {
		version_msg_title = str;
		g_free(str);
	}
	str = g_key_file_get_string(keyfile, "update", "version_msg_content", NULL);
	if (str) {
		version_msg_content = str;
		g_free(str);
	}
	str = g_key_file_get_string(keyfile, "update", "latest_news", NULL);
	if (str) {
		latest_news = str;
		g_free(str);
	}
	err = NULL;
	show_ads = g_key_file_get_boolean(keyfile, "misc", "show_ads", &err);
	if (err) {
		g_error_free (err);
		show_ads = true;
	}
	g_key_file_free(keyfile);
	g_print(_("Update info plug-in loaded.\n"));
	return false;
}
Exemplo n.º 9
0
static gboolean
_accounts_rename(const char * const account_name, const char * const new_name)
{
    if (g_key_file_has_group(accounts, new_name)) {
        return FALSE;
    }

    if (!g_key_file_has_group(accounts, account_name)) {
        return FALSE;
    }

    g_key_file_set_boolean(accounts, new_name, "enabled",
        g_key_file_get_boolean(accounts, account_name, "enabled", NULL));

    g_key_file_set_integer(accounts, new_name, "priority.online",
        g_key_file_get_integer(accounts, account_name, "priority.online", NULL));
    g_key_file_set_integer(accounts, new_name, "priority.chat",
        g_key_file_get_integer(accounts, account_name, "priority.chat", NULL));
    g_key_file_set_integer(accounts, new_name, "priority.away",
        g_key_file_get_integer(accounts, account_name, "priority.away", NULL));
    g_key_file_set_integer(accounts, new_name, "priority.xa",
        g_key_file_get_integer(accounts, account_name, "priority.xa", NULL));
    g_key_file_set_integer(accounts, new_name, "priority.dnd",
        g_key_file_get_integer(accounts, account_name, "priority.dnd", NULL));

    // copy other string properties
    int i;
    for (i = 0; i < ARRAY_SIZE(string_keys); i++) {
        char *value = g_key_file_get_string(accounts, account_name, string_keys[i], NULL);
        if (value != NULL) {
            g_key_file_set_string(accounts, new_name, string_keys[i], value);
            g_free(value);
        }
    }

    g_key_file_remove_group(accounts, account_name, NULL);
    _save_accounts();

    autocomplete_remove(all_ac, account_name);
    autocomplete_add(all_ac, new_name);
    if (g_key_file_get_boolean(accounts, new_name, "enabled", NULL)) {
        autocomplete_remove(enabled_ac, account_name);
        autocomplete_add(enabled_ac, new_name);
    }

    return TRUE;
}
Exemplo n.º 10
0
void
prefs_load(void)
{
    GError *err;
    prefs_loc = _get_preferences_file();

    if (g_file_test(prefs_loc, G_FILE_TEST_EXISTS)) {
        g_chmod(prefs_loc, S_IRUSR | S_IWUSR);
    }

    prefs = g_key_file_new();
    g_key_file_load_from_file(prefs, prefs_loc, G_KEY_FILE_KEEP_COMMENTS,
        NULL);

    err = NULL;
    log_maxsize = g_key_file_get_integer(prefs, PREF_GROUP_LOGGING, "maxsize", &err);
    if (err) {
        log_maxsize = 0;
        g_error_free(err);
    }

    // move pre 0.4.7 otr.warn to enc.warn
    err = NULL;
    gboolean otr_warn = g_key_file_get_boolean(prefs, PREF_GROUP_UI, "otr.warn", &err);
    if (err == NULL) {
        g_key_file_set_boolean(prefs, PREF_GROUP_UI, _get_key(PREF_ENC_WARN), otr_warn);
        g_key_file_remove_key(prefs, PREF_GROUP_UI, "otr.warn", NULL);
    } else {
        g_error_free(err);
    }

    // migrate pre 0.4.7 time settings format
    if (g_key_file_has_key(prefs, PREF_GROUP_UI, "time", NULL)) {
        char *time = g_key_file_get_string(prefs, PREF_GROUP_UI, "time", NULL);
        if (g_strcmp0(time, "minutes") == 0) {
            g_key_file_set_string(prefs, PREF_GROUP_UI, "time", "%H:%M");
        } else if (g_strcmp0(time, "seconds") == 0) {
            g_key_file_set_string(prefs, PREF_GROUP_UI, "time", "%H:%M:%S");
        } else if (g_strcmp0(time, "off") == 0) {
            g_key_file_set_string(prefs, PREF_GROUP_UI, "time", "");
        }
    }
    if (g_key_file_has_key(prefs, PREF_GROUP_UI, "time.statusbar", NULL)) {
        char *time = g_key_file_get_string(prefs, PREF_GROUP_UI, "time.statusbar", NULL);
        if (g_strcmp0(time, "minutes") == 0) {
            g_key_file_set_string(prefs, PREF_GROUP_UI, "time.statusbar", "%H:%M");
        } else if (g_strcmp0(time, "seconds") == 0) {
            g_key_file_set_string(prefs, PREF_GROUP_UI, "time.statusbar", "%H:%M:%S");
        } else if (g_strcmp0(time, "off") == 0) {
            g_key_file_set_string(prefs, PREF_GROUP_UI, "time.statusbar", "");
        }
    }

    _save_prefs();

    boolean_choice_ac = autocomplete_new();
    autocomplete_add(boolean_choice_ac, "on");
    autocomplete_add(boolean_choice_ac, "off");
}
Exemplo n.º 11
0
static WebSite *
get_site(WebApplet *webapplet, gchar *name)
{
  WebSite *site = g_new0(WebSite, 1);
  site->url = g_strdup(g_key_file_get_string(webapplet->sites_file,
                       name, "URL", NULL));
  site->name = g_strdup(g_key_file_get_string(webapplet->sites_file,
                        name, "Name", NULL));
  site->webapplet = webapplet;

  /* Width specific for this website */
  if (g_key_file_has_key(webapplet->sites_file, name, "Width", NULL))
  {
    site->width = g_key_file_get_integer(webapplet->sites_file,
                                         name, "Width", NULL);
  }

  /* Height specific for this website */
  if (g_key_file_has_key(webapplet->sites_file, name, "Height", NULL))
  {
    site->height = g_key_file_get_integer(webapplet->sites_file,
                                          name, "Height", NULL);
  }

  /* Icon, usually at least 48x48, or scalable */
  if (g_key_file_has_key(webapplet->sites_file, name, "Icon-svg", NULL))
  {
    site->icon = g_strdup(g_key_file_get_string(webapplet->sites_file,
                          name, "Icon-svg", NULL));
  }

  /* Icon over Icon-48 because Icon could be 64px */
  else if (g_key_file_has_key(webapplet->sites_file, name, "Icon", NULL))
  {
    site->icon = g_strdup(g_key_file_get_string(webapplet->sites_file,
                          name, "Icon", NULL));
  }

  else if (g_key_file_has_key(webapplet->sites_file, name, "Icon-48", NULL))
  {
    site->icon = g_strdup(g_key_file_get_string(webapplet->sites_file,
                          name, "Icon-48", NULL));
  }

  return site;
}
Exemplo n.º 12
0
static struct list_elem *read_file(const gchar *filename)
{
  gchar *full_filename = NULL;
  GKeyFile *settingsfile = NULL;
  struct list_elem *list_item = NULL;

  if( !(full_filename = g_strconcat(CONF_DIR_PATH, "/", filename, NULL)) )
    goto cleanup;

  if( !(settingsfile = g_key_file_new()) )
    goto cleanup;

  if( !g_key_file_load_from_file(settingsfile, full_filename, G_KEY_FILE_NONE, NULL) )
    goto cleanup;

  if( !(list_item = calloc(1, sizeof *list_item)) )
    goto cleanup;

  list_item->name = g_key_file_get_string(settingsfile, APP_INFO_ENTRY, APP_INFO_NAME_KEY, NULL);
  log_debug("Appname = %s\n", list_item->name);
  list_item->launch = g_key_file_get_string(settingsfile, APP_INFO_ENTRY, APP_INFO_LAUNCH_KEY, NULL);
  log_debug("Launch = %s\n", list_item->launch);
  list_item->mode = g_key_file_get_string(settingsfile, APP_INFO_ENTRY, APP_INFO_MODE_KEY, NULL);
  log_debug("Launch mode = %s\n", list_item->mode);
  list_item->upstart = g_key_file_get_integer(settingsfile, APP_INFO_ENTRY, APP_INFO_UPSTART_KEY, NULL);
  log_debug("Upstart control = %d\n", list_item->upstart);
  list_item->systemd = g_key_file_get_integer(settingsfile, APP_INFO_ENTRY, APP_INFO_SYSTEMD_KEY, NULL);
  log_debug("Systemd control = %d\n", list_item->systemd);
  list_item->post = g_key_file_get_integer(settingsfile, APP_INFO_ENTRY, APP_INFO_POST, NULL);

cleanup:

  if(settingsfile) 
	g_key_file_free(settingsfile);
  g_free(full_filename);

  /* if a minimum set of required elements is not filled in we discard the list_item */
  if( list_item && !(list_item->name && list_item->mode) )
  {
    log_debug("Element invalid, discarding\n");
    free_elem(list_item); 
    list_item = 0;
  }

  return list_item;
}
Exemplo n.º 13
0
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 ();
}
Exemplo n.º 14
0
int
egg_desktop_file_get_integer (EggDesktopFile *desktop_file,
			      const char     *key,
    			      GError	    **error)
{
  return g_key_file_get_integer (desktop_file->key_file,
				 EGG_DESKTOP_FILE_GROUP, key,
				 error);
}
Exemplo n.º 15
0
void lxdm_get_tty(void)
{
	char *s = g_key_file_get_string(config, "server", "arg", 0);
	int arc;
	char **arg;
	int len;
	int gotvtarg = 0;
	gboolean plymouth;
    
	plymouth=plymouth_is_running();
	if(plymouth)
	{
		g_message("found plymouth running\n");
		plymouth_prepare_transition();
	}

	old_tty=get_active_vt();
	if( !s ) s = g_strdup("/usr/bin/X");
	g_shell_parse_argv(s, &arc, &arg, 0);
	g_free(s);
	for( len = 0; arg && arg[len]; len++ )
	{
		char *p = arg[len];
		if( !strncmp(p, "vt", 2) && isdigit(p[2]) &&
		( !p[3] || (isdigit(p[3]) && !p[4]) ) )
		{
			def_tty = atoi(p + 2);
			gotvtarg = 1;
		}
		else if(!strcmp(p,"-background") || !strcmp(p,"-nr"))
		{
			nr_tty=1;
		}
		else if(p[0]==':' && isdigit(p[1]))
		{
			def_display=atoi(p+1);
		}
	}
	if(!gotvtarg)
	{
		/* support plymouth */
		if(g_key_file_get_integer(config, "server", "active_vt", 0) )
			/* use the active vt */
			def_tty = old_tty;
		if(plymouth)
		{
			nr_tty=1;
			plymouth_quit_with_transition();
		}
	}
	else
	{
		if(plymouth) /* set tty and plymouth running */
			plymouth_quit_without_transition();
	}
	g_strfreev(arg);
}
Exemplo n.º 16
0
/*
 * May terminate application if error occurs
 */
static guint pyra_rmp_get_default_value(gchar const *key) {
	PyraRMP const *default_rmp = pyra_default_rmp();
	GError *error = NULL;
	guint result;
	result = g_key_file_get_integer(default_rmp->key_file, pyra_rmp_group_name, key, &error);
	if (error)
		g_error(_("Could not get default value for key '%s': %s"), key, error->message);
	return result;
}
Exemplo n.º 17
0
static guint pyra_rmp_get_value(PyraRMP *rmp, gchar const *key) {
	GError *error = NULL;
	guint result = g_key_file_get_integer(rmp->key_file, pyra_rmp_group_name, key, &error);
	if (error) {
		g_clear_error(&error);
		result = pyra_rmp_get_default_value(key);
	}
	return result;
}
Exemplo n.º 18
0
gint prefs_get_inpblock(void)
{
    int val = g_key_file_get_integer(prefs, PREF_GROUP_UI, "inpblock", NULL);
    if (val == 0) {
        return INPBLOCK_DEFAULT;
    } else {
        return val;
    }
}
Exemplo n.º 19
0
int
plugin_settings_get_int(const char *const group, const char *const key, int def)
{
    if (group && key && g_key_file_has_key(settings, group, key, NULL)) {
        return g_key_file_get_integer(settings, group, key, NULL);
    } else {
        return def;
    }
}
Exemplo n.º 20
0
static void read_int_config(gint *item, GKeyFile *gkey, const char *key)
{
  gint tmp;
  GError *err = NULL;
  tmp = g_key_file_get_integer(gkey, pref_group, key, &err);
  if (err)
    return; /* key not found, exit */
  *item = tmp;
}
Exemplo n.º 21
0
gint
prefs_get_autoping(void)
{
    if (!g_key_file_has_key(prefs, PREF_GROUP_CONNECTION, "autoping", NULL)) {
        return 60;
    } else {
        return g_key_file_get_integer(prefs, PREF_GROUP_CONNECTION, "autoping", NULL);
    }
}
Exemplo n.º 22
0
gint
prefs_get_reconnect(void)
{
    if (!g_key_file_has_key(prefs, PREF_GROUP_CONNECTION, "reconnect", NULL)) {
        return 30;
    } else {
        return g_key_file_get_integer(prefs, PREF_GROUP_CONNECTION, "reconnect", NULL);
    }
}
Exemplo n.º 23
0
void MetadataManager::cleanupMetadata()
{
	XOJ_CHECK_TYPE(MetadataManager);

	GList* data = NULL;

	gsize lenght = 0;
	gchar** groups = g_key_file_get_groups(this->config, &lenght);

	for (gsize i = 0; i < lenght; i++)
	{
		char* group = groups[i];

		GFile* file = g_file_new_for_uri(group);
		bool exists = g_file_query_exists(file, NULL);
		g_object_unref(file);

		if (!exists)
		{
			g_key_file_remove_group(this->config, group, NULL);
			continue;
		}

		GError* error = NULL;
		// TODO LOW PRIO: newer GTK Version use _int64 instead of integer
		int time = g_key_file_get_integer(this->config, group, "atime", &error);
		if (error)
		{
			g_error_free(error);
			continue;
		}

		GroupTimeEntry* e = g_new(GroupTimeEntry, 1);
		e->group = group;
		e->time = time;

		data = g_list_insert_sorted(data, e, (GCompareFunc) timeCompareFunc);
	}

	int count = g_list_length(data);
	GList* d = data;
	if (count > METADATA_MAX_ITEMS)
	{
		for (int i = count - METADATA_MAX_ITEMS; i > 0 && d; i--)
		{
			GroupTimeEntry* e = (GroupTimeEntry*) d->data;
			g_key_file_remove_group(this->config, e->group, NULL);
			d = d->next;
		}
	}

	g_list_foreach(data, (GFunc) g_free, NULL);
	g_list_free(data);

	g_strfreev(groups);
}
Exemplo n.º 24
0
void 
gpc_queue_purge_request(GPilotRequest **req) 
{
	gchar *section = NULL;
	int num;
	GKeyFile *kfile;

	LOG (("gpc_queue_purge_request()"));

	g_return_if_fail (req != NULL);
	g_return_if_fail (*req != NULL);

	kfile = get_queue_kfile ();
	set_section ((*req)->pilot_id, (*req)->type, &section);
	num = g_key_file_get_integer (kfile, section, NUMREQ, NULL);
	num--;
	g_key_file_set_integer (kfile, section, NUMREQ, num);

	g_key_file_remove_group (kfile, (*req)->queue_data.section_name, NULL);

	switch((*req)->type) {
	case GREQ_INSTALL:
		unlink((*req)->parameters.install.filename);
		g_free((*req)->parameters.install.filename);
		g_free((*req)->parameters.install.description);
		break;
	case GREQ_RESTORE:
		g_free((*req)->parameters.restore.directory);
		break;
	case GREQ_CONDUIT:
		g_free((*req)->parameters.conduit.name);
		break;
	case GREQ_GET_USERINFO: 
		break;
	case GREQ_GET_SYSINFO: 
		break;
	case GREQ_NEW_USERINFO: 
	case GREQ_SET_USERINFO: 
		g_free((*req)->parameters.set_userinfo.user_id);
		g_free((*req)->parameters.set_userinfo.password);
		break;
	default: 
		g_assert_not_reached();
		break;
	}
	g_free((*req)->cradle);
	g_free((*req)->client_id);
	g_free((*req)->queue_data.section_name);
	g_free(*req);
	*req = NULL;
  
	g_free (section);

	save_queue_kfile (kfile);
	g_key_file_free (kfile);
} 
Exemplo n.º 25
0
static void read_config(const char *file)
{
	GKeyFile *keyfile;
	GError *err = NULL;
	char *str;

	DBG("read_config(): reading file %s", file);
    
	keyfile = g_key_file_new();

	if (!g_key_file_load_from_file(keyfile, file, 0, &err)) {
		g_clear_error(&err);
		goto done;
	}

	rfcomm_channel = g_key_file_get_integer(keyfile, "General",
						"RfcommChannel", &err);
	if (err) {
		DBG("%s: %s", file, err->message);
		g_clear_error(&err);
	} else {
		DBG("RFCOMM channel = %d", rfcomm_channel);
	}

	str = g_key_file_get_string(keyfile, "General", "ServiceName", &err);
	if (err) {
		DBG("%s: %s", file, err->message);
		g_clear_error(&err);
              service_name = service_name_default;
	} else {
		DBG("service name = %s", str);
		service_name = g_strdup(str);
		g_free(str);
	}

	high_security = g_key_file_get_boolean(keyfile, "General",
						"HighSecurity", &err);
	if (err) {
		DBG("%s: %s", file, err->message);
		g_clear_error(&err);
	} else {
		DBG("high security = %d", high_security);
	}

	cmd_line = g_key_file_get_string(keyfile, "General",
						"ModemBridgeCmdLine", &err);
	if (err) {
		DBG("%s: %s", file, err->message);
		g_clear_error(&err);
	} else {
		DBG("command line = %s", cmd_line);
	}

done:
	g_key_file_free(keyfile);
}
Exemplo n.º 26
0
Arquivo: main.c Projeto: tadeboro/hip
static void
update_processor (AppData *data)
{
  if (data->mem)
    memory_free (data->mem);
  if (data->regs)
    registers_free (data->regs);
  if (data->symtable)
    symbol_table_free (data->symtable);

  /* Create empty symbol table (to be populated during parse) */
  data->symtable = symbol_table_new ();

  /* Create registers */
  data->regs = registers_new (g_key_file_get_integer (data->settings,
						      "processor",
						      "no_registers",
						      NULL));
  /* Create designated memory segments */
  data->mem = memory_new ();
  memory_add_data_segment (data->mem, MEM_SEG_DATA,
			   g_key_file_get_integer (data->settings,
						   "data segment",
						   "origin",
						   NULL),
			   g_key_file_get_integer (data->settings,
						   "data segment",
						   "size",
						   NULL));
  memory_add_data_segment (data->mem, MEM_SEG_CODE,
			   g_key_file_get_integer (data->settings,
						   "code segment",
						   "origin",
						   NULL),
			   g_key_file_get_integer (data->settings,
						   "code segment",
						   "size",
						   NULL));
  update_symtable (data);
  update_mcode (data);
  update_data (data);
  update_regs (data);
}
Exemplo n.º 27
0
gint cf_key_file_get_integer (const gchar *group, const gchar *key) {
    GError *err = NULL;
    gint value = g_key_file_get_integer (cf_key_file, group, key, &err);
    if (err != NULL) {
        cf_show_error (&err);
        cf_key_file_set_integer (group, key, 0);
        value = 0;
    }
    return value;
}
static gboolean
gst_dvb_base_bin_conf_set_int (GstElement * dvbbasebin, const gchar * property,
    GKeyFile * kf, const gchar * channel_name, const gchar * key)
{
  gint v;

  v = g_key_file_get_integer (kf, channel_name, key, NULL);
  g_object_set (dvbbasebin, property, v, NULL);
  return TRUE;
}
Exemplo n.º 29
0
/**
 * pk_cnf_get_config:
 **/
static PkCnfPolicyConfig *
pk_cnf_get_config (void)
{
	GKeyFile *file;
	gchar *path;
	gboolean ret;
	_cleanup_error_free_ GError *error = NULL;
	PkCnfPolicyConfig *config;

	/* create */
	config = g_new0 (PkCnfPolicyConfig, 1);

	/* set defaults if the conf file is not found */
	config->single_match = PK_CNF_POLICY_UNKNOWN;
	config->multiple_match = PK_CNF_POLICY_UNKNOWN;
	config->single_install = PK_CNF_POLICY_UNKNOWN;
	config->multiple_install = PK_CNF_POLICY_UNKNOWN;
	config->software_source_search = TRUE;
	config->similar_name_search = TRUE;
	config->locations = NULL;
	config->max_search_time = 5000;

	/* load file */
	file = g_key_file_new ();
	path = g_build_filename (SYSCONFDIR, "PackageKit", "CommandNotFound.conf", NULL);
	ret = g_key_file_load_from_file (file, path, G_KEY_FILE_NONE, &error);
	if (!ret) {
		g_printerr ("failed to load config file: %s\n", error->message);
		goto out;
	}

	/* get data */
	config->single_match = pk_cnf_get_policy_from_file (file, "SingleMatch");
	config->multiple_match = pk_cnf_get_policy_from_file (file, "MultipleMatch");
	config->single_install = pk_cnf_get_policy_from_file (file, "SingleInstall");
	config->multiple_install = pk_cnf_get_policy_from_file (file, "MultipleInstall");
	config->software_source_search = g_key_file_get_boolean (file, "CommandNotFound", "SoftwareSourceSearch", NULL);
	config->similar_name_search = g_key_file_get_boolean (file, "CommandNotFound", "SimilarNameSearch", NULL);
	config->locations = g_key_file_get_string_list (file, "CommandNotFound", "SearchLocations", NULL, NULL);
	config->max_search_time = g_key_file_get_integer (file, "CommandNotFound", "MaxSearchTime", NULL);

	/* fallback */
	if (config->locations == NULL) {
		g_warning ("not found SearchLocations, using fallback");
		config->locations = g_strsplit ("/usr/bin;/usr/sbin", ";", -1);
	}
	if (config->max_search_time == 0) {
		g_warning ("not found MaxSearchTime, using fallback");
		config->max_search_time = 2000;
	}
out:
	g_free (path);
	g_key_file_free (file);
	return config;
}
void PythonCompletionFramework::load_preferences()
{
    JediCompletePluginPref* pref = JediCompletePluginPref::instance();

    std::string config_file = get_config_file();

    // Initialising options from config file
    GKeyFile* keyfile = g_key_file_new();
    if (g_key_file_load_from_file(keyfile, config_file.c_str(), G_KEY_FILE_NONE, NULL)) {
	const char* group = get_plugin_name();

	pref->row_text_max =
	    g_key_file_get_integer(keyfile, group, "maximum_char_in_row", NULL);
	pref->suggestion_window_height_max =
	    g_key_file_get_integer(keyfile, group, "maximum_sug_window_height", NULL);
	pref->page_up_down_skip_amount =
	    g_key_file_get_integer(keyfile, group, "page_up_down_skip_amount", NULL);
	pref->start_completion_with_dot =
	    g_key_file_get_boolean(keyfile, group, "start_completion_with_dot", NULL);
	pref->jedi_server_port =
	    g_key_file_get_integer(keyfile, group, "server_port", NULL);
	gchar* temp;
	temp = g_key_file_get_string(keyfile, group, "python_path", NULL);
	pref->python_path = temp;
	g_free(temp);
    } else {
	pref->row_text_max = 120;
	pref->suggestion_window_height_max = 300;
	pref->page_up_down_skip_amount = 4;
	pref->start_completion_with_dot = true;
	pref->jedi_server_port = 8080;
	pref->python_path = "/usr/bin/python";
    }
    // hidden preference "server_script_dir"
    gchar* dirname = g_path_get_dirname(config_file.c_str());
    pref->server_script_dir = dirname;
    g_free(dirname);

    g_key_file_free(keyfile);

    this->updated_preferences();
}