void cd_mail_create_mh_params( GKeyFile *pKeyFile, gchar *pMailAccountName )
{
	g_key_file_set_string (pKeyFile, pMailAccountName, "type", "mh");
	g_key_file_set_comment (pKeyFile, pMailAccountName, "type", ">0 ", NULL);

	g_key_file_set_integer (pKeyFile, pMailAccountName, "timeout mn", 10);
	g_key_file_set_comment (pKeyFile, pMailAccountName, "timeout mn", "I0[1;30] timeout:\n{In minutes.}", NULL);
}
Пример #2
0
/* copies all keys and comments from one group to another, deleting the old
 * group. */
static gboolean
gst_preset_default_rename_preset (GstPreset * preset, const gchar * old_name,
    const gchar * new_name)
{
  GKeyFile *presets;
  gchar *str;
  gchar **keys;
  gsize i, num_keys;

  /* get the presets from the type */
  if (!(presets = preset_get_keyfile (preset)))
    goto no_presets;

  if (!g_key_file_has_group (presets, old_name))
    goto no_group;

  /* copy group comment if there is any */
  if ((str = g_key_file_get_comment (presets, old_name, NULL, NULL))) {
    g_key_file_set_comment (presets, new_name, NULL, str, NULL);
    g_free (str);
  }

  /* get all keys from the old group and copy them in the new group */
  keys = g_key_file_get_keys (presets, old_name, &num_keys, NULL);
  for (i = 0; i < num_keys; i++) {
    /* copy key comment if there is any */
    if ((str = g_key_file_get_comment (presets, old_name, keys[i], NULL))) {
      g_key_file_set_comment (presets, new_name, keys[i], str, NULL);
      g_free (str);
    }
    /* copy key value */
    str = g_key_file_get_value (presets, old_name, keys[i], NULL);
    g_key_file_set_value (presets, new_name, keys[i], str);
    g_free (str);
  }
  g_strfreev (keys);

  /* remove old group */
  g_key_file_remove_group (presets, old_name, NULL);

  /* save updated version */
  return gst_preset_default_save_presets_file (preset);

  /* ERRORS */
no_presets:
  {
    GST_WARNING_OBJECT (preset, "no presets");
    return FALSE;
  }
no_group:
  {
    GST_WARNING_OBJECT (preset, "no preset named %s", old_name);
    return FALSE;
  }
}
void cd_mail_create_feed_params( GKeyFile *pKeyFile, gchar *pMailAccountName )
{
	g_key_file_set_string (pKeyFile, pMailAccountName, "type", "feed");
	g_key_file_set_comment (pKeyFile, pMailAccountName, "type", ">0 ", NULL);

	g_key_file_set_string (pKeyFile, pMailAccountName, "path", "http://www.cairo-dock.org/rss/cd_svn.xml");
	g_key_file_set_comment (pKeyFile, pMailAccountName, "path", "s0 address of feed:", NULL);

	g_key_file_set_integer (pKeyFile, pMailAccountName, "timeout mn", 10);
	g_key_file_set_comment (pKeyFile, pMailAccountName, "timeout mn", "I0[1;30] timeout:\n{In minutes.}", NULL);
}
void cd_mail_create_imap_params( GKeyFile *pKeyFile, gchar *pMailAccountName )
{
	g_key_file_set_string (pKeyFile, pMailAccountName, "type", "imap");
	g_key_file_set_comment (pKeyFile, pMailAccountName, "type", ">0 ", NULL);

	g_key_file_set_string (pKeyFile, pMailAccountName, "host", "imap.myhost.org");
	g_key_file_set_comment (pKeyFile, pMailAccountName, "host", "s0 server address:", NULL);

	g_key_file_set_string (pKeyFile, pMailAccountName, "username", "myLogin");
	g_key_file_set_comment (pKeyFile, pMailAccountName, "username", "s0 username:"******"password", "");
	g_key_file_set_comment (pKeyFile, pMailAccountName, "password", "p0 password:"******"port", 0);
	g_key_file_set_comment (pKeyFile, pMailAccountName, "port", "i0 port:\n{Enter 0 to use the default port. Default ports are 143 for IMAP4 and 993 for IMAP4 over SSL.}", NULL);

	g_key_file_set_boolean (pKeyFile, pMailAccountName, "use secure connection", FALSE);
	g_key_file_set_comment (pKeyFile, pMailAccountName, "use secure connection", "b0 use secure connection (SSL)", NULL);

	g_key_file_set_string (pKeyFile, pMailAccountName, "server_directory", "Inbox");
	g_key_file_set_comment (pKeyFile, pMailAccountName, "server_directory", "s0 directory on server:", NULL);

	g_key_file_set_integer (pKeyFile, pMailAccountName, "timeout mn", 10);
	g_key_file_set_comment (pKeyFile, pMailAccountName, "timeout mn", "I0[1;30] timeout:\n{In minutes.}", NULL);
}
void cd_mail_create_gmail_params( GKeyFile *pKeyFile, gchar *pMailAccountName )
{
	g_key_file_set_string (pKeyFile, pMailAccountName, "type", "gmail");
	g_key_file_set_comment (pKeyFile, pMailAccountName, "type", ">0 ", NULL);

	g_key_file_set_string (pKeyFile, pMailAccountName, "username", "myLogin");
	g_key_file_set_comment (pKeyFile, pMailAccountName, "username", "s0 username:"******"password", "");
	g_key_file_set_comment (pKeyFile, pMailAccountName, "password", "p0 password:"******"timeout mn", 10);
	g_key_file_set_comment (pKeyFile, pMailAccountName, "timeout mn", "I0[1;30] timeout:\n{In minutes.}", NULL);
}
Пример #6
0
void test_setcomment()
{
	GKeyFile *keyfile;
	gchar *comment;

	const gchar *data = 
	    "[1]\n"
	    "key1=123\n"
	    "key2=456\n";
	
	keyfile = load_data (data, 0);
	
	g_key_file_set_comment(keyfile,"1","key1","comment1",NULL);
	
	comment = g_key_file_get_comment(keyfile,"1","key1",NULL);
	
	g_assert(!strcmp(comment,"comment1\n"));
	
	g_key_file_remove_comment(keyfile,"1","key1",NULL);
	
	g_free(comment);
	
	comment = g_key_file_get_comment(keyfile,"1","key1",NULL);
	
	g_assert(comment == NULL);
	
}
Пример #7
0
void
gnc_exp_parser_shutdown (void)
{
    GKeyFile* key_file;
    gchar *filename;

    if (!parser_inited)
        return;

    filename = gnc_exp_parser_filname();
    key_file = g_key_file_new();
    g_hash_table_foreach (variable_bindings, set_one_key, key_file);
    g_key_file_set_comment(key_file, GROUP_NAME, NULL,
                           " Variables are in the form 'name=value'",
                           NULL);
    gnc_key_file_save_to_file(filename, key_file, NULL);
    g_key_file_free(key_file);
    g_free(filename);

    g_hash_table_foreach_remove (variable_bindings, remove_binding, NULL);
    g_hash_table_destroy (variable_bindings);
    variable_bindings = NULL;

    last_error = PARSER_NO_ERROR;
    last_gncp_error = NO_ERR;

    parser_inited = FALSE;
}
void cairo_dock_add_widget_to_conf_file (GKeyFile *pKeyFile, const gchar *cGroupName, const gchar *ckeyName, const gchar *cInitialValue, gchar iWidgetType, const gchar *cDescription, const gchar *cTooltip)
{
	g_key_file_set_string (pKeyFile, cGroupName, ckeyName, cInitialValue);
	gchar *Comment = g_strdup_printf ("%c0 %s%s%s%s", iWidgetType, cDescription, cTooltip ? "\n{" : "", cTooltip ? cTooltip : "", cTooltip ? "}" : "");
	g_key_file_set_comment (pKeyFile, cGroupName, ckeyName, Comment, NULL);
	g_free (Comment);
}
Пример #9
0
static void
preset_merge (GKeyFile * system, GKeyFile * user)
{
  gchar *str;
  gchar **groups, **keys;
  gsize i, j, num_groups, num_keys;

  /* copy file comment if there is any */
  if ((str = g_key_file_get_comment (user, NULL, NULL, NULL))) {
    g_key_file_set_comment (system, NULL, NULL, str, NULL);
    g_free (str);
  }

  /* get groups in user and copy into system */
  groups = g_key_file_get_groups (user, &num_groups);
  for (i = 0; i < num_groups; i++) {
    /* copy group comment if there is any */
    if ((str = g_key_file_get_comment (user, groups[i], NULL, NULL))) {
      g_key_file_set_comment (system, groups[i], NULL, str, NULL);
      g_free (str);
    }

    /* ignore private groups */
    if (groups[i][0] == '_')
      continue;

    /* if group already exists in system, remove and re-add keys from user */
    if (g_key_file_has_group (system, groups[i])) {
      g_key_file_remove_group (system, groups[i], NULL);
    }

    keys = g_key_file_get_keys (user, groups[i], &num_keys, NULL);
    for (j = 0; j < num_keys; j++) {
      /* copy key comment if there is any */
      if ((str = g_key_file_get_comment (user, groups[i], keys[j], NULL))) {
        g_key_file_set_comment (system, groups[i], keys[j], str, NULL);
        g_free (str);
      }
      str = g_key_file_get_value (user, groups[i], keys[j], NULL);
      g_key_file_set_value (system, groups[i], keys[j], str);
      g_free (str);
    }
    g_strfreev (keys);
  }
  g_strfreev (groups);
}
Пример #10
0
/**************************************************
 * save_common
 *
 * save settings to a key file
 **************************************************/
bool
CsvImportSettings::save_common (void)
{
    auto keyfile = gnc_state_get_current ();
    auto group = csv_group_prefix + m_settings_type + " - " + m_name;

    // Start Saving the Common settings
    g_key_file_set_string (keyfile, group.c_str(), CSV_NAME, m_name.c_str());

    g_key_file_set_integer (keyfile, group.c_str(), CSV_SKIP_START, m_skip_start_lines);
    g_key_file_set_integer (keyfile, group.c_str(), CSV_SKIP_END, m_skip_end_lines);
    g_key_file_set_boolean (keyfile, group.c_str(), CSV_SKIP_ALT, m_skip_alt_lines);
    g_key_file_set_boolean (keyfile, group.c_str(), CSV_FORMAT,
        (m_file_format == GncImpFileFormat::CSV) ? true : false);

    g_key_file_set_string (keyfile, group.c_str(), CSV_SEP, m_separators.c_str());
    g_key_file_set_integer (keyfile, group.c_str(), CSV_DATE, m_date_format);
    std::ostringstream cmt_ss;
    cmt_ss << "Supported date formats: ";
    int fmt_num = 0;
    std::for_each (GncDate::c_formats.cbegin(), GncDate::c_formats.cend(),
                    [&cmt_ss, &fmt_num](const GncDateFormat& fmt)
                        { cmt_ss << fmt_num++ << ": '" << fmt.m_fmt << "', "; });
    auto cmt = cmt_ss.str().substr(0, static_cast<long>(cmt_ss.tellp()) - 2);
    g_key_file_set_comment (keyfile, group.c_str(), CSV_DATE, cmt.c_str(), nullptr);
    g_key_file_set_integer (keyfile, group.c_str(), CSV_CURRENCY, m_currency_format);
    g_key_file_set_string (keyfile, group.c_str(), CSV_ENCODING, m_encoding.c_str());

    if (!m_column_widths.empty())
        g_key_file_set_integer_list (keyfile, group.c_str(), CSV_COL_WIDTHS,
                (gint*)(m_column_widths.data()), m_column_widths.size());

    // Do a test read of encoding
    GError *key_error = nullptr;
    bool error = false;
    auto enc_val = g_key_file_get_string (keyfile, group.c_str(), CSV_ENCODING, &key_error);
    auto enc_str = std::string{enc_val};
    if (enc_val)
        g_free (enc_val);

    if ((key_error) || (enc_str != m_encoding.c_str()))
    {
        if (key_error)
        {
            g_warning ("Error reading group %s key %s: %s", group.c_str(), CSV_ENCODING, key_error->message);
            g_error_free (key_error);
        }
        else
            g_warning ("Error comparing group %s key %s: '%s' and '%s'", group.c_str(), CSV_ENCODING, enc_str.c_str(), group.c_str());
        error = true;
    }
    return error;
}
Пример #11
0
gboolean
dfu_key_file_rename_group (GKeyFile   *keyfile,
                           const char *oldgroup,
                           const char *newgroup)
{
  char         **keys;
  char          *value;
  unsigned int   i;

  g_return_val_if_fail (keyfile != NULL, FALSE);

  if (!g_key_file_has_group (keyfile, oldgroup))
    return TRUE;

  keys = g_key_file_get_keys (keyfile, oldgroup, NULL, NULL);
  for (i = 0; keys[i] != NULL; i++) {
    value = g_key_file_get_value (keyfile, oldgroup, keys[i], NULL);
    g_key_file_set_value (keyfile, newgroup, keys[i], value);
    g_free (value);

    value = g_key_file_get_comment (keyfile, oldgroup, keys[i], NULL);
    if (value) {
      g_key_file_set_comment (keyfile, newgroup, keys[i], value, NULL);
      g_free (value);
    }
  }
  g_strfreev (keys);

  value = g_key_file_get_comment (keyfile, oldgroup, NULL, NULL);
  if (value) {
    g_key_file_set_comment (keyfile, newgroup, NULL, value, NULL);
    g_free (value);
  }

  g_key_file_remove_group (keyfile, oldgroup, NULL);

  return TRUE;
}
Пример #12
0
static gboolean
set_comment (GKeyFile *kfile)
{
	GError *err;
	const char *comment =
		" automatically generated -- do not edit";

	err = NULL;
	if (!g_key_file_set_comment (kfile, NULL, NULL, comment, &err)) {
		g_warning ("could not write comment to keyfile: %s",
			   err->message);
		g_error_free (err);
		return FALSE;
	}

	return TRUE;
}
void cd_mail_create_pop3_params( GKeyFile *pKeyFile, gchar *pMailAccountName )
{
	g_key_file_set_string (pKeyFile, pMailAccountName, "type", "pop3");
	g_key_file_set_comment (pKeyFile, pMailAccountName, "type", ">0 ", NULL);  // on lui met un widget pour ne pas que la cle se fasse bazarder lors d'une mise a jour du fichier de conf.
	
	g_key_file_set_string (pKeyFile, pMailAccountName, "host", "pop3.myhost.org");
	g_key_file_set_comment (pKeyFile, pMailAccountName, "host", "s0 server address:", NULL);

	g_key_file_set_string (pKeyFile, pMailAccountName, "username", "myLogin");
	g_key_file_set_comment (pKeyFile, pMailAccountName, "username", "s0 username:"******"password", "");
	g_key_file_set_comment (pKeyFile, pMailAccountName, "password", "p0 password:\n{The password will be crypted.}", NULL);

	g_key_file_set_integer (pKeyFile, pMailAccountName, "port", 0);
	g_key_file_set_comment (pKeyFile, pMailAccountName, "port", "i0 port:\n{Enter 0 to use the default port. Default ports are 110 for POP3 or APOP and 995 for POP3S.}", NULL);

	g_key_file_set_boolean (pKeyFile, pMailAccountName, "use secure connection", FALSE);
	g_key_file_set_comment (pKeyFile, pMailAccountName, "use secure connection", "b0 use secure connection (SSL)", NULL);

	g_key_file_set_integer (pKeyFile, pMailAccountName, "timeout mn", 10);
	g_key_file_set_comment (pKeyFile, pMailAccountName, "timeout mn", "I0[1;30] timeout:\n{In minutes.}", NULL);
}
static gboolean
apply_revision_override (RpmostreedTransaction    *transaction,
                         OstreeRepo               *repo,
                         OstreeAsyncProgress      *progress,
                         RpmOstreeSysrootUpgrader *upgrader,
                         const char               *revision,
                         GCancellable             *cancellable,
                         GError                  **error)
{
  g_autoptr(GKeyFile) origin = NULL;
  g_autofree char *checksum = NULL;
  g_autofree char *version = NULL;
  const char *refspec;

  origin = rpmostree_sysroot_upgrader_dup_origin (upgrader);
  if (origin == NULL)
    {
      g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                           "Booted deployment has no origin");
      return FALSE;
    }

  if (!rpmostreed_parse_revision (revision,
                                  &checksum,
                                  &version,
                                  error))
    return FALSE;

  refspec = rpmostree_sysroot_upgrader_get_refspec (upgrader);
  if (refspec == NULL)
    {
      g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                           "Could not find refspec for booted deployment");
        return FALSE;
    }

  if (version != NULL)
    {
      rpmostreed_transaction_emit_message_printf (transaction,
                                                  "Resolving version '%s'",
                                                  version);

      if (!rpmostreed_repo_lookup_version (repo, refspec, version, progress,
                                           cancellable, &checksum, error))
        return FALSE;
    }
  else
    {
      g_assert (checksum != NULL);

      rpmostreed_transaction_emit_message_printf (transaction,
                                                  "Validating checksum '%s'",
                                                  checksum);

      if (!rpmostreed_repo_lookup_checksum (repo, refspec, checksum,
                                            progress, cancellable, error))
        return FALSE;
    }

  g_key_file_set_string (origin, "origin", "override-commit", checksum);

  if (version != NULL)
    {
      g_autofree char *comment = NULL;

      /* Add a comment with the version, to be nice. */
      comment = g_strdup_printf ("Version %s [%.10s]", version, checksum);
      g_key_file_set_comment (origin, "origin", "override-commit", comment, NULL);
    }

  if (!rpmostree_sysroot_upgrader_set_origin (upgrader, origin, cancellable, error))
    return FALSE;

  return TRUE;
}
Пример #15
0
Файл: erln8.c Проект: mkb/erln8
// generate the initial ~/ERLN8_CONFIG_DIR/config file with some
// default settings
// TODO: more settings, Linux, FreeBSD etc
void init_main_config() {
  GKeyFile* kf = g_key_file_new();
  g_key_file_set_boolean(kf,
                         "Erln8",
                         "color",
                         TRUE);
  g_key_file_set_comment(kf,
                         "Erln8",
                         "color",
                         "Either true or false, case sensitive",
                         NULL);
  g_key_file_set_boolean(kf,
                         "Erln8",
                         "banner",
                         FALSE);
  g_key_file_set_comment(kf,
                         "Erln8",
                         "banner",
                         "Show the version of Erlang that erln8 is running",
                         NULL);
  g_key_file_set_string(kf,
                        "Erln8",
                        "default_config",
                        "default");
  g_key_file_set_comment(kf,
                         "Erln8",
                         "default_config",
                         "The default config to use for a build",
                         NULL);
  g_key_file_set_string(kf,
                        "Erln8",
                        "system_default",
                        "");
  g_key_file_set_comment(kf,
                         "Erln8",
                         "system_default",
                         "If an erln8.config file isn't found, use this one.",
                         NULL);
  g_key_file_set_string(kf,
                        "Repos",
                        "default",
                        "https://github.com/erlang/otp.git");
  g_key_file_set_string(kf,
                        "Erlangs",
                        "none",
                        "");
  g_key_file_set_string(kf,
                        "Configs",
                        "default",
                        "");
  g_key_file_set_string(kf,
                        "Configs",
                        "osx_llvm",
                        "--disable-hipe --enable-smp-support --enable-threads --enable-kernel-poll --enable-darwin-64bit");
  g_key_file_set_string(kf,
                        "Configs",
                        "osx_llvm_dtrace",
                        "--disable-hipe --enable-smp-support --enable-threads --enable-kernel-poll --enable-darwin-64bit --enable-vm-probes --with-dynamic-trace=dtrace");
  g_key_file_set_string(kf,
                        "Configs",
                        "osx_gcc",
                        "--disable-hipe --enable-smp-support --enable-threads --enable-kernel-poll --enable-darwin-64bit");
  g_key_file_set_string(kf,
                        "Configs",
                        "osx_gcc_env",
                        "CC=gcc-4.2 CPPFLAGS=\'-DNDEBUG\' MAKEFLAGS=\'-j 3\'");
  GError* error = NULL;
  gchar* d = g_key_file_to_data (kf, NULL, &error);
  if(error != NULL) {
    g_error("Unable to create ~/" ERLN8_CONFIG_DIR "/config: %s\n", error->message);
    //g_error_free(error);
  }
  gchar* fn = get_configdir_file_name("config");
  printf("Creating " ERLN8_CONFIG_FILE " file: %s\n", fn);
  GError* contentserror = NULL;
  if(!g_file_set_contents(fn, d, -1, &contentserror)) {
    if(contentserror != NULL) {
      g_error("Unable to write contents to ~/" ERLN8_CONFIG_DIR "/config: %s\n", contentserror->message);
    } else {
      g_error("Unable to write contents to ~/" ERLN8_CONFIG_DIR "/config\n");
    }
  }
  g_free(fn);
  g_free(d);
  g_key_file_free(kf);
  if(!opt_quickstart) {
    printf("%sIf you only want to use the canonical OTP repo, run `erln8 --clone default` before continuing%s\n", yellow(), color_reset());
  }
}
Пример #16
0
/* Open the named notmuch configuration file. If the filename is NULL,
 * the value of the environment variable $NOTMUCH_CONFIG will be used.
 * If $NOTMUCH_CONFIG is unset, the default configuration file
 * ($HOME/.notmuch-config) will be used.
 *
 * If any error occurs, (out of memory, or a permission-denied error,
 * etc.), this function will print a message to stderr and return
 * NULL.
 *
 * FILE NOT FOUND: When the specified configuration file (whether from
 * 'filename' or the $NOTMUCH_CONFIG environment variable) does not
 * exist, the behavior of this function depends on the 'is_new_ret'
 * variable.
 *
 *	If is_new_ret is NULL, then a "file not found" message will be
 *	printed to stderr and NULL will be returned.

 *	If is_new_ret is non-NULL then a default configuration will be
 *	returned and *is_new_ret will be set to 1 on return so that
 *	the caller can recognize this case.
 *
 * 	These default configuration settings are determined as
 * 	follows:
 *
 *		database_path:		$HOME/mail
 *
 *		user_name:		From /etc/passwd
 *
 *		user_primary_mail: 	$EMAIL variable if set, otherwise
 *					constructed from the username and
 *					hostname of the current machine.
 *
 *		user_other_email:	Not set.
 *
 *	The default configuration also contains comments to guide the
 *	user in editing the file directly.
 */
notmuch_config_t *
notmuch_config_open (void *ctx,
		     const char *filename,
		     notmuch_bool_t *is_new_ret)
{
    GError *error = NULL;
    int is_new = 0;
    size_t tmp;
    char *notmuch_config_env = NULL;
    int file_had_database_group;
    int file_had_new_group;
    int file_had_user_group;
    int file_had_maildir_group;
    int file_had_search_group;

    if (is_new_ret)
	*is_new_ret = 0;

    notmuch_config_t *config = talloc (ctx, notmuch_config_t);
    if (config == NULL) {
	fprintf (stderr, "Out of memory.\n");
	return NULL;
    }
    
    talloc_set_destructor (config, notmuch_config_destructor);

    if (filename) {
	config->filename = talloc_strdup (config, filename);
    } else if ((notmuch_config_env = getenv ("NOTMUCH_CONFIG"))) {
	config->filename = talloc_strdup (config, notmuch_config_env);
    } else {
	config->filename = talloc_asprintf (config, "%s/.notmuch-config",
					    getenv ("HOME"));
    }

    config->key_file = g_key_file_new ();

    config->database_path = NULL;
    config->user_name = NULL;
    config->user_primary_email = NULL;
    config->user_other_email = NULL;
    config->user_other_email_length = 0;
    config->new_tags = NULL;
    config->new_tags_length = 0;
    config->new_ignore = NULL;
    config->new_ignore_length = 0;
    config->maildir_synchronize_flags = TRUE;
    config->search_exclude_tags = NULL;
    config->search_exclude_tags_length = 0;

    if (! g_key_file_load_from_file (config->key_file,
				     config->filename,
				     G_KEY_FILE_KEEP_COMMENTS,
				     &error))
    {
	/* If the caller passed a non-NULL value for is_new_ret, then
	 * the caller is prepared for a default configuration file in
	 * the case of FILE NOT FOUND. Otherwise, any read failure is
	 * an error.
	 */
	if (is_new_ret &&
	    error->domain == G_FILE_ERROR &&
	    error->code == G_FILE_ERROR_NOENT)
	{
	    g_error_free (error);
	    is_new = 1;
	}
	else
	{
	    fprintf (stderr, "Error reading configuration file %s: %s\n",
		     config->filename, error->message);
	    talloc_free (config);
	    g_error_free (error);
	    return NULL;
	}
    }

    /* Whenever we know of configuration sections that don't appear in
     * the configuration file, we add some comments to help the user
     * understand what can be done.
     *
     * It would be convenient to just add those comments now, but
     * apparently g_key_file will clear any comments when keys are
     * added later that create the groups. So we have to check for the
     * groups now, but add the comments only after setting all of our
     * values.
     */
    file_had_database_group = g_key_file_has_group (config->key_file,
						    "database");
    file_had_new_group = g_key_file_has_group (config->key_file, "new");
    file_had_user_group = g_key_file_has_group (config->key_file, "user");
    file_had_maildir_group = g_key_file_has_group (config->key_file, "maildir");
    file_had_search_group = g_key_file_has_group (config->key_file, "search");


    if (notmuch_config_get_database_path (config) == NULL) {
	char *path = talloc_asprintf (config, "%s/mail",
				      getenv ("HOME"));
	notmuch_config_set_database_path (config, path);
	talloc_free (path);
    }

    if (notmuch_config_get_user_name (config) == NULL) {
	char *name = get_name_from_passwd_file (config);
	notmuch_config_set_user_name (config, name);
	talloc_free (name);
    }

    if (notmuch_config_get_user_primary_email (config) == NULL) {
	char *email = getenv ("EMAIL");
	if (email) {
	    notmuch_config_set_user_primary_email (config, email);
	} else {
	    char hostname[256];
	    struct hostent *hostent;
	    const char *domainname;

	    char *username = get_username_from_passwd_file (config);

	    gethostname (hostname, 256);
	    hostname[255] = '\0';

	    hostent = gethostbyname (hostname);
	    if (hostent && (domainname = strchr (hostent->h_name, '.')))
		domainname += 1;
	    else
		domainname = "(none)";

	    email = talloc_asprintf (config, "%s@%s.%s",
				     username, hostname, domainname);

	    notmuch_config_set_user_primary_email (config, email);

	    talloc_free (username);
	    talloc_free (email);
	}
    }

    if (notmuch_config_get_new_tags (config, &tmp) == NULL) {
        const char *tags[] = { "unread", "inbox" };
	notmuch_config_set_new_tags (config, tags, 2);
    }

    if (notmuch_config_get_new_ignore (config, &tmp) == NULL) {
	notmuch_config_set_new_ignore (config, NULL, 0);
    }

    if (notmuch_config_get_search_exclude_tags (config, &tmp) == NULL) {
	if (is_new) {
	    const char *tags[] = { "deleted", "spam" };
	    notmuch_config_set_search_exclude_tags (config, tags, 2);
	} else {
	    notmuch_config_set_search_exclude_tags (config, NULL, 0);
	}
    }

    error = NULL;
    config->maildir_synchronize_flags =
	g_key_file_get_boolean (config->key_file,
				"maildir", "synchronize_flags", &error);
    if (error) {
	notmuch_config_set_maildir_synchronize_flags (config, TRUE);
	g_error_free (error);
    }

    /* Whenever we know of configuration sections that don't appear in
     * the configuration file, we add some comments to help the user
     * understand what can be done. */
    if (is_new)
    {
	g_key_file_set_comment (config->key_file, NULL, NULL,
				toplevel_config_comment, NULL);
    }

    if (! file_had_database_group)
    {
	g_key_file_set_comment (config->key_file, "database", NULL,
				database_config_comment, NULL);
    }

    if (! file_had_new_group)
    {
	g_key_file_set_comment (config->key_file, "new", NULL,
				new_config_comment, NULL);
    }

    if (! file_had_user_group)
    {
	g_key_file_set_comment (config->key_file, "user", NULL,
				user_config_comment, NULL);
    }

    if (! file_had_maildir_group)
    {
	g_key_file_set_comment (config->key_file, "maildir", NULL,
				maildir_config_comment, NULL);
    }

    if (! file_had_search_group) {
	g_key_file_set_comment (config->key_file, "search", NULL,
				search_config_comment, NULL);
    }

    if (is_new_ret)
	*is_new_ret = is_new;

    return config;
}
Пример #17
0
static void
set_defaults(GKeyFile *keyfile)
{
    gchar *dir;
    GError *error = NULL;

    g_assert(keyfile != NULL);

    /* Image dir */
    if (g_key_file_has_key(keyfile, "Default", PWGALLERY_RCKEY_IMAGE_DIR,
                           NULL ) == FALSE)
    {
        g_key_file_set_value(keyfile, "Default", PWGALLERY_RCKEY_IMAGE_DIR,
                             PWGALLERY_DEFAULT_IMAGE_DIR);

        g_key_file_set_comment(keyfile, "Default", PWGALLERY_RCKEY_IMAGE_DIR,
                               _("Image directory"),
                               NULL);
    }

    /* Galleries dir */
    if (g_key_file_has_key(keyfile, "Default", PWGALLERY_RCKEY_GAL_DIR,
                           NULL ) == FALSE)
    {
        dir = g_strdup_printf("file://%s/%s/%s", g_get_home_dir(),
                              PWGALLERY_CONFIGRC_DIR,
                              PWGALLERY_DEFAULT_GAL_DIR);
        g_key_file_set_value(keyfile, "Default", PWGALLERY_RCKEY_GAL_DIR,
                             dir);
        g_free(dir);
        g_key_file_set_comment(keyfile, "Default", PWGALLERY_RCKEY_GAL_DIR,
                               _("Galleries directory"),
                               NULL);
    }

    /* Templates dir */
    if (g_key_file_has_key(keyfile, "Default", PWGALLERY_RCKEY_TEMPL_DIR,
                           NULL ) == FALSE)
    {
        dir = g_strdup_printf("file://%s/%s/%s", g_get_home_dir(),
                              PWGALLERY_CONFIGRC_DIR,
                              PWGALLERY_DEFAULT_TEMPL_DIR);
        g_key_file_set_value(keyfile, "Default", PWGALLERY_RCKEY_TEMPL_DIR,
                             dir);
        g_free(dir);
        g_key_file_set_comment(keyfile, "Default", PWGALLERY_RCKEY_TEMPL_DIR,
                               _("Template directory"),
                               NULL);
    }

    /* Output dir */
    if (g_key_file_has_key(keyfile, "Default", PWGALLERY_RCKEY_OUTPUT_DIR,
                           NULL ) == FALSE)
    {
        g_key_file_set_value(keyfile, "Default", PWGALLERY_RCKEY_OUTPUT_DIR,
                             PWGALLERY_DEFAULT_OUTPUT_DIR);

        g_key_file_set_comment(keyfile, "Default", PWGALLERY_RCKEY_OUTPUT_DIR,
                               _("Default output directory for galleries"),
                               NULL);
    }

    /* Page generator style */
    if (g_key_file_has_key(keyfile, "Default", PWGALLERY_RCKEY_PAGE_GEN,
                           NULL ) == FALSE)
    {
        g_key_file_set_value(keyfile, "Default", PWGALLERY_RCKEY_PAGE_GEN,
                             PWGALLERY_DEFAULT_PAGE_GEN);

        g_key_file_set_comment(keyfile, "Default", PWGALLERY_RCKEY_PAGE_GEN,
                               _("Default page generator style"),
                               NULL);
    }

    /* Page generator program */
    if (g_key_file_has_key(keyfile, "Default", PWGALLERY_RCKEY_PAGE_GEN_PROG,
                           NULL ) == FALSE)
    {
        g_key_file_set_value(keyfile, "Default", PWGALLERY_RCKEY_PAGE_GEN_PROG,
                             PWGALLERY_DEFAULT_PAGE_GEN_PROG);

        g_key_file_set_comment(keyfile, "Default",
                               PWGALLERY_RCKEY_PAGE_GEN_PROG,
                               _("Default page generator program"),
                               NULL);
    }

    /* Thumbnail width */
    if (g_key_file_has_key(keyfile, "Default", PWGALLERY_RCKEY_THUMB_W,
                           NULL ) == FALSE)
    {
        g_key_file_set_value(keyfile, "Default", PWGALLERY_RCKEY_THUMB_W,
                             PWGALLERY_DEFAULT_THUMB_W);

        g_key_file_set_comment(keyfile, "Default", PWGALLERY_RCKEY_THUMB_W,
                               _("Default width of the thumbnails"),
                               NULL);
    }


    /* Image height */
    if (g_key_file_has_key(keyfile, "Default", PWGALLERY_RCKEY_IMAGE_H,
                           NULL ) == FALSE)
    {
        g_key_file_set_value(keyfile, "Default", PWGALLERY_RCKEY_IMAGE_H,
                             PWGALLERY_DEFAULT_IMAGE_H);

        g_key_file_set_comment(keyfile, "Default", PWGALLERY_RCKEY_IMAGE_H,
                               _("Default height of the images"),
                               NULL);
    }

    /* Image height2 */
    if (g_key_file_has_key(keyfile, "Default", PWGALLERY_RCKEY_IMAGE_H2,
                           NULL ) == FALSE)
    {
        g_key_file_set_value(keyfile, "Default", PWGALLERY_RCKEY_IMAGE_H2,
                             PWGALLERY_DEFAULT_IMAGE_H2);

        g_key_file_set_comment(keyfile, "Default", PWGALLERY_RCKEY_IMAGE_H2,
                               _("Default height of the second set of images"),
                               NULL);
    }

    /* Image height3 */
    if (g_key_file_has_key(keyfile, "Default", PWGALLERY_RCKEY_IMAGE_H3,
                           NULL ) == FALSE)
    {
        g_key_file_set_value(keyfile, "Default", PWGALLERY_RCKEY_IMAGE_H3,
                             PWGALLERY_DEFAULT_IMAGE_H3);

        g_key_file_set_comment(keyfile, "Default", PWGALLERY_RCKEY_IMAGE_H3,
                               _("Default height of the third set of images"),
                               NULL);
    }

    /* Image height4 */
    if (g_key_file_has_key(keyfile, "Default", PWGALLERY_RCKEY_IMAGE_H4,
                           NULL ) == FALSE)
    {
        g_key_file_set_value(keyfile, "Default", PWGALLERY_RCKEY_IMAGE_H4,
                             PWGALLERY_DEFAULT_IMAGE_H4);

        g_key_file_set_comment(keyfile, "Default", PWGALLERY_RCKEY_IMAGE_H4,
                               _("Default height of the fourth set of images"),
                               NULL);
    }


    /* Index page template */
    if (g_key_file_has_key(keyfile, "Default", PWGALLERY_RCKEY_TEMPL_INDEX,
                           NULL ) == FALSE)
    {
        dir = g_strdup_printf("file://%s/%s/%s/%s", g_get_home_dir(),
                              PWGALLERY_CONFIGRC_DIR,
                              PWGALLERY_DEFAULT_TEMPL_DIR,
                              PWGALLERY_DEFAULT_TEMPL_INDEX);
        g_key_file_set_value(keyfile, "Default", PWGALLERY_RCKEY_TEMPL_INDEX,
                             dir);
        g_free(dir);

        g_key_file_set_comment(keyfile, "Default", PWGALLERY_RCKEY_TEMPL_INDEX,
                               _("Default template for index page"),
                               NULL);
    }

    /* Index page per image template */
    if (g_key_file_has_key(keyfile, "Default", PWGALLERY_RCKEY_TEMPL_INDEXIMG,
                           NULL ) == FALSE)
    {
        dir = g_strdup_printf("file://%s/%s/%s/%s", g_get_home_dir(),
                              PWGALLERY_CONFIGRC_DIR,
                              PWGALLERY_DEFAULT_TEMPL_DIR,
                              PWGALLERY_DEFAULT_TEMPL_INDEXIMG);
        g_key_file_set_value(keyfile, "Default", PWGALLERY_RCKEY_TEMPL_INDEXIMG,
                             dir);
        g_free(dir);

        g_key_file_set_comment(keyfile, "Default",
                               PWGALLERY_RCKEY_TEMPL_INDEXIMG,
                               _("Default template for index page per image"),
                               NULL);
    }

    /* Index page per generic template */
    if (g_key_file_has_key(keyfile, "Default", PWGALLERY_RCKEY_TEMPL_INDEXGEN,
                           NULL ) == FALSE)
    {
        dir = g_strdup_printf("file://%s/%s/%s/%s", g_get_home_dir(),
                              PWGALLERY_CONFIGRC_DIR,
                              PWGALLERY_DEFAULT_TEMPL_DIR,
                              PWGALLERY_DEFAULT_TEMPL_INDEXGEN);
        g_key_file_set_value(keyfile, "Default", PWGALLERY_RCKEY_TEMPL_INDEXGEN,
                             dir);
        g_free(dir);

        g_key_file_set_comment(keyfile, "Default",
                               PWGALLERY_RCKEY_TEMPL_INDEXGEN,
                               _("Default template for index page per generic"),
                               NULL);
    }

    /* Image page template */
    if (g_key_file_has_key(keyfile, "Default", PWGALLERY_RCKEY_TEMPL_IMAGE,
                           NULL ) == FALSE)
    {
        dir = g_strdup_printf("file://%s/%s/%s/%s", g_get_home_dir(),
                              PWGALLERY_CONFIGRC_DIR,
                              PWGALLERY_DEFAULT_TEMPL_DIR,
                              PWGALLERY_DEFAULT_TEMPL_IMAGE);
        g_key_file_set_value(keyfile, "Default", PWGALLERY_RCKEY_TEMPL_IMAGE,
                             dir);
        g_free(dir);

        g_key_file_set_comment(keyfile, "Default", PWGALLERY_RCKEY_TEMPL_IMAGE,
                               _("Default template for image page"),
                               NULL);
    }

    /* Generic page template */
    if (g_key_file_has_key(keyfile, "Default", PWGALLERY_RCKEY_TEMPL_GEN,
                           NULL ) == FALSE)
    {
        dir = g_strdup_printf("file://%s/%s/%s/%s", g_get_home_dir(),
                              PWGALLERY_CONFIGRC_DIR,
                              PWGALLERY_DEFAULT_TEMPL_DIR,
                              PWGALLERY_DEFAULT_TEMPL_GEN);
        g_key_file_set_value(keyfile, "Default", PWGALLERY_RCKEY_TEMPL_GEN,
                             dir);
        g_free(dir);

        g_key_file_set_comment(keyfile, "Default", PWGALLERY_RCKEY_TEMPL_GEN,
                               _("Default template for generic page"),
                               NULL);
    }


    /* Remove exif info */
    if (g_key_file_has_key(keyfile, "Default", PWGALLERY_RCKEY_REMOVE_EXIF,
                           NULL ) == FALSE)
    {
        g_key_file_set_value(keyfile, "Default", PWGALLERY_RCKEY_REMOVE_EXIF,
                             PWGALLERY_DEFAULT_REMOVE_EXIF);

        g_key_file_set_comment(keyfile, "Default", PWGALLERY_RCKEY_REMOVE_EXIF,
                               _("Default value for exif information "
                                 "removal (0 for keep, 1 for remove)"),
                               NULL);
    }

    /* Rename images */
    if (g_key_file_has_key(keyfile, "Default", PWGALLERY_RCKEY_RENAME,
                           NULL ) == FALSE)
    {
        g_key_file_set_value(keyfile, "Default", PWGALLERY_RCKEY_RENAME,
                             PWGALLERY_DEFAULT_RENAME);

        g_key_file_set_comment(keyfile, "Default", PWGALLERY_RCKEY_RENAME,
                               _("Default value for renameing images "
                                 "automatically"),
                               NULL);
    }


    /* Global comment */
    /* FIXME: this is prepended in the configrc file on each load? */
    g_key_file_set_comment(keyfile, "Default", NULL,
                           _("This is automatically created configrc file "
                             "for Penguin's Web Gallery."),
                           &error);
    if (error != NULL)
    {
        g_warning("Failed to set comment: %s",
                  error->message);
        g_error_free(error);
        error = NULL;
    }

}
Пример #18
0
/**************************************************
 * save
 *
 * save settings to a key file
 **************************************************/
bool
CsvTransSettings::save (void)
{
    if (trans_preset_is_reserved_name (m_name))
    {
        PWARN ("Ignoring attempt to save to reserved name '%s'", m_name.c_str());
        return true;
    }

    if ((m_name.find('[') != std::string::npos))
    {
        PWARN ("Name '%s' contains invalid characters '[]'. Refusing to save", m_name.c_str());
        return true;
    }

    auto keyfile = gnc_state_get_current ();
    auto group = csv_group_prefix + m_name;

    // Drop previous saved settings with this name
    g_key_file_remove_group (keyfile, group.c_str(), nullptr);

    // Start Saving the settings
    g_key_file_set_string (keyfile, group.c_str(), CSV_NAME, m_name.c_str());
    g_key_file_set_boolean (keyfile, group.c_str(), CSV_MULTI_SPLIT, m_multi_split);
    g_key_file_set_integer (keyfile, group.c_str(), CSV_SKIP_START, m_skip_start_lines);
    g_key_file_set_integer (keyfile, group.c_str(), CSV_SKIP_END, m_skip_end_lines);
    g_key_file_set_boolean (keyfile, group.c_str(), CSV_SKIP_ALT, m_skip_alt_lines);
    g_key_file_set_boolean (keyfile, group.c_str(), CSV_FORMAT,
        (m_file_format == GncImpFileFormat::CSV) ? true : false);

    g_key_file_set_string (keyfile, group.c_str(), CSV_SEP, m_separators.c_str());
    g_key_file_set_integer (keyfile, group.c_str(), CSV_DATE, m_date_format);
    std::ostringstream cmt_ss;
    cmt_ss << "Supported date formats: ";
    int fmt_num = 0;
    std::for_each (GncDate::c_formats.cbegin(), GncDate::c_formats.cend(),
                    [&cmt_ss, &fmt_num](const GncDateFormat& fmt)
                        { cmt_ss << fmt_num++ << ": '" << fmt.m_fmt << "', "; });
    auto cmt = cmt_ss.str().substr(0, static_cast<long>(cmt_ss.tellp()) - 2);
    g_key_file_set_comment (keyfile, group.c_str(), CSV_DATE,
                            cmt.c_str(), nullptr);
    g_key_file_set_integer (keyfile, group.c_str(), CSV_CURRENCY, m_currency_format);
    g_key_file_set_string (keyfile, group.c_str(), CSV_ENCODING, m_encoding.c_str());

    if (m_base_account)
        g_key_file_set_string (keyfile, group.c_str(), CSV_ACCOUNT, gnc_account_get_full_name(m_base_account));

    std::vector<const char*> col_types_str;
    for (auto col_type : m_column_types)
        col_types_str.push_back(gnc_csv_col_type_strs[col_type]);

    if (!col_types_str.empty())
        g_key_file_set_string_list (keyfile, group.c_str(), CSV_COL_TYPES,
                col_types_str.data(), col_types_str.size());

    if (!m_column_widths.empty())
        g_key_file_set_integer_list (keyfile, group.c_str(), CSV_COL_WIDTHS,
                (gint*)(m_column_widths.data()), m_column_widths.size());

    // Do a test read of encoding
    GError *key_error = nullptr;
    bool error = false;
    auto enc_val = g_key_file_get_string (keyfile, group.c_str(), CSV_ENCODING, &key_error);
    auto enc_str = std::string{enc_val};
    if (enc_val)
        g_free (enc_val);

    if ((key_error) || (enc_str != m_encoding.c_str()))
    {
        if (key_error)
        {
            g_warning ("Error reading group %s key %s: %s", group.c_str(), CSV_COL_TYPES, key_error->message);
            g_error_free (key_error);
        }
        else
            g_warning ("Error comparing group %s key %s: '%s' and '%s'", group.c_str(), CSV_COL_TYPES, enc_str.c_str(), group.c_str());
        error = true;
    }
    return error;
}
Пример #19
0
void
img_save_slideshow( img_window_struct *img,
					const gchar       *output )
{
	GKeyFile *img_key_file;
	gchar *conf, *string, *path, *filename, *file, *font_desc;
	gint count = 0;
	gsize len;
	GtkTreeIter iter;
	slide_struct *entry;
	GtkTreeModel *model;

	model = GTK_TREE_MODEL( img->thumbnail_model );
	if (!gtk_tree_model_get_iter_first (model, &iter))
		return;

	img_key_file = g_key_file_new();

	/* Slideshow settings */
	g_key_file_set_comment(img_key_file, NULL, NULL, comment_string, NULL);

    g_key_file_set_string(img_key_file, "slideshow settings",
                          "video codec",
                          video_format_list[img->video_format_index].config_name);

                          g_key_file_set_integer(img_key_file, "slideshow settings",
                          "video width", img->video_size[0]);
    g_key_file_set_integer(img_key_file, "slideshow settings",
                          "video height", img->video_size[1]);

    g_key_file_set_string(img_key_file, "slideshow settings",
                "fps",
                video_format_list[img->video_format_index].fps_list[img->fps_index].name);

    if (NULL != video_format_list[img->video_format_index].aspect_ratio_list)
        g_key_file_set_string(img_key_file, "slideshow settings",
                "aspect ratio",
                video_format_list[img->video_format_index].aspect_ratio_list[img->aspect_ratio_index].name);

    if (NULL != video_format_list[img->video_format_index].bitratelist)
        g_key_file_set_integer(img_key_file, "slideshow settings",
                "bitrate",
                video_format_list[img->video_format_index].bitratelist[img->bitrate_index].value);

	g_key_file_set_double_list( img_key_file, "slideshow settings",
								"background color", img->background_color, 3 );
	g_key_file_set_boolean(img_key_file,"slideshow settings", "distort images", img->distort_images);

	g_key_file_set_integer(img_key_file, "slideshow settings", "number of slides", img->slides_nr);

	/* Slide settings */
	do
	{
		count++;
		gtk_tree_model_get(model, &iter,1,&entry,-1);
		conf = g_strdup_printf("slide %d",count);

        if (entry->load_ok)
            filename = entry->o_filename;
        else
            filename = entry->original_filename;

        if (filename)
		{
			/* Save original filename and rotation */
			g_key_file_set_string( img_key_file, conf,
								   "filename", filename);
			g_key_file_set_integer( img_key_file, conf, "angle", entry->angle );
		}
		else
		{
			/* We are dealing with an empty slide */
			gdouble *start_color = entry->g_start_color,
					*stop_color  = entry->g_stop_color,
					*start_point = entry->g_start_point,
					*stop_point  = entry->g_stop_point;

			g_key_file_set_integer(img_key_file, conf, "gradient",	entry->gradient);
			g_key_file_set_double_list(img_key_file, conf, "start_color", start_color, 3 );
			g_key_file_set_double_list(img_key_file, conf, "stop_color" , stop_color , 3 );
			g_key_file_set_double_list(img_key_file, conf, "start_point", start_point, 2 );
			g_key_file_set_double_list(img_key_file, conf, "stop_point" , stop_point , 2 );
		}

		/* Duration */
		g_key_file_set_integer(img_key_file,conf, "duration",		entry->duration);

		/* Transition */
		g_key_file_set_integer(img_key_file,conf, "transition_id",	entry->transition_id);
		g_key_file_set_integer(img_key_file,conf, "speed", 			entry->speed);

		/* Stop points */
		g_key_file_set_integer(img_key_file,conf, "no_points",		entry->no_points);
		if (entry->no_points > 0)
		{
			gint    point_counter;
			gdouble my_points[entry->no_points * 4];

			for( point_counter = 0;
				 point_counter < entry->no_points;
				 point_counter++ )
			{
				ImgStopPoint *my_point = g_list_nth_data(entry->points,point_counter);
				my_points[ (point_counter * 4) + 0] = (gdouble)my_point->time;
				my_points[ (point_counter * 4) + 1] = my_point->offx;
				my_points[ (point_counter * 4) + 2] = my_point->offy;
				my_points[ (point_counter * 4) + 3] = my_point->zoom;
			}
			g_key_file_set_double_list(img_key_file,conf, "points", my_points, (gsize) entry->no_points * 4);
		}

		/* Subtitle */
		/* EXPLANATION: Only facultative field here is subtitle text, since user
		 * may have set other text properties on slide and we would let them out
		 * if we only save slides with text present. */
		if( entry->subtitle )
			g_key_file_set_string (img_key_file, conf,"text",			entry->subtitle);

		font_desc = pango_font_description_to_string(entry->font_desc);
		g_key_file_set_integer(img_key_file,conf, "anim id",		entry->anim_id);
		g_key_file_set_integer(img_key_file,conf, "anim duration",	entry->anim_duration);
		g_key_file_set_integer(img_key_file,conf, "text pos",		entry->position);
		g_key_file_set_integer(img_key_file,conf, "placing",		entry->placing);
		g_key_file_set_string (img_key_file, conf,"font",			font_desc);
		g_key_file_set_double_list(img_key_file, conf,"font color",entry->font_color,4);
        g_key_file_set_double_list(img_key_file, conf,"font bgcolor",entry->font_bgcolor,4);
		g_free(font_desc);
		g_free(conf);
	}
	while (gtk_tree_model_iter_next (model,&iter));
	count = 0;

	/* Background music */
	model = gtk_tree_view_get_model(GTK_TREE_VIEW(img->music_file_treeview));
	if (gtk_tree_model_get_iter_first (model, &iter))
	{
		g_key_file_set_integer(img_key_file, "music", "number", gtk_tree_model_iter_n_children(model, NULL));
		do
		{
			count++;
			gtk_tree_model_get(model, &iter, 0, &path, 1, &filename ,-1);
			conf = g_strdup_printf("music_%d",count);
			file = g_build_filename(path, filename, NULL);
			g_free(path);
			g_free(filename);
			g_key_file_set_string(img_key_file, "music", conf, file);
			g_free(file);
			g_free(conf);
		}
		while (gtk_tree_model_iter_next (model, &iter));
	}

	/* Write the project file */
	conf = g_key_file_to_data(img_key_file, &len, NULL);
	g_file_set_contents( output, conf, len, NULL );
	g_free (conf);

	string = g_path_get_basename( output );
	img_set_window_title(img,string);
	g_free(string);
	g_key_file_free(img_key_file);

	if( img->project_filename )
		g_free( img->project_filename );
	img->project_filename = g_strdup( output );

	img->project_is_modified = FALSE;
}
static gboolean
apply_revision_override (RpmostreedTransaction    *transaction,
                         OstreeRepo               *repo,
                         OstreeAsyncProgress      *progress,
                         RpmOstreeSysrootUpgrader *upgrader,
                         const char               *revision,
                         GCancellable             *cancellable,
                         GError                  **error)
{
  RpmOstreeOrigin *origin = rpmostree_sysroot_upgrader_get_origin (upgrader);
  g_autoptr(GKeyFile) new_origin = NULL;
  g_autofree char *checksum = NULL;
  g_autofree char *version = NULL;

  new_origin = rpmostree_origin_dup_keyfile (origin);

  if (!rpmostreed_parse_revision (revision,
                                  &checksum,
                                  &version,
                                  error))
    return FALSE;

  if (version != NULL)
    {
      rpmostreed_transaction_emit_message_printf (transaction,
                                                  "Resolving version '%s'",
                                                  version);

      if (!rpmostreed_repo_lookup_version (repo, rpmostree_origin_get_refspec (origin),
                                           version, progress,
                                           cancellable, &checksum, error))
        return FALSE;
    }
  else
    {
      g_assert (checksum != NULL);

      rpmostreed_transaction_emit_message_printf (transaction,
                                                  "Validating checksum '%s'",
                                                  checksum);

      if (!rpmostreed_repo_lookup_checksum (repo, rpmostree_origin_get_refspec (origin),
                                            checksum, progress, cancellable, error))
        return FALSE;
    }

  g_key_file_set_string (new_origin, "origin", "override-commit", checksum);

  if (version != NULL)
    {
      g_autofree char *comment = NULL;

      /* Add a comment with the version, to be nice. */
      comment = g_strdup_printf ("Version %s [%.10s]", version, checksum);
      g_key_file_set_comment (new_origin, "origin", "override-commit", comment, NULL);
    }

  if (!rpmostree_sysroot_upgrader_set_origin (upgrader, new_origin, cancellable, error))
    return FALSE;

  return TRUE;
}
Пример #21
0
int tilp_config_write(void)
{
	char* ini_file;
	GKeyFile* kf;
	GError* error = NULL;
	gchar *content;
	FILE* f;
	gint remap;
	int ret = 0;

	remap = ticalcs_remap_model_from_usb(options.cable_model, options.calc_model);

	// get file location
	ini_file = get_config_path();

	kf = g_key_file_new();

	g_key_file_set_comment(kf, NULL, NULL, 
		"# Config file for TiLP\n" \
		"# Copyright (C) 1999-2011 The TiLP Team <*****@*****.**>\n" \
		"# Warning: any comments that you add to this file WILL be overwritten", &error);

	// Section [DEVICE]
	g_key_file_set_string (kf, SECTION_DEVICE, "calc_model", ticalcs_model_to_string(remap));
	g_key_file_set_comment(kf, SECTION_DEVICE, "calc_model", "Calculator model", &error);

	g_key_file_set_string (kf, SECTION_DEVICE, "cable_model", ticables_model_to_string(options.cable_model));
	g_key_file_set_comment(kf, SECTION_DEVICE, "cable_model", "Cable model", &error);

	g_key_file_set_string (kf, SECTION_DEVICE, "cable_port", ticables_port_to_string(options.cable_port));
	g_key_file_set_comment(kf, SECTION_DEVICE, "cable_port", "Port", &error);

	g_key_file_set_integer(kf, SECTION_DEVICE, "cable_timeout", options.cable_timeout);
	g_key_file_set_comment(kf, SECTION_DEVICE, "cable_timeout", "Timeout in tenth of seconds", &error);

	g_key_file_set_integer(kf, SECTION_DEVICE, "cable_delay", options.cable_delay);
	g_key_file_set_comment(kf, SECTION_DEVICE, "cable_delay", "Inter-bit delay in us", &error);

	// Section [GUI]

	g_key_file_set_integer(kf, SECTION_GUI, "pane_x_size", options.pane_x_size);
	g_key_file_set_comment(kf, SECTION_GUI, "pane_x_size", "Size of remote view", &error);

	g_key_file_set_integer(kf, SECTION_GUI, "pane_y_size", options.pane_y_size);
	g_key_file_set_comment(kf, SECTION_GUI, "pane_y_size", "Size of remote view", &error);

	g_key_file_set_integer(kf, SECTION_GUI, "wnd_x_size1", options.wnd_x_size1);
	g_key_file_set_comment(kf, SECTION_GUI, "wnd_x_size1", "Size of window (full)", &error);

	g_key_file_set_integer(kf, SECTION_GUI, "wnd_y_size1", options.wnd_y_size1);
	g_key_file_set_comment(kf, SECTION_GUI, "wnd_y_size1", "Size of window (full)", &error);

	g_key_file_set_integer(kf, SECTION_GUI, "wnd_x_size2", options.wnd_x_size2);
	g_key_file_set_comment(kf, SECTION_GUI, "wnd_x_size2", "Size of window (no local)", &error);

	g_key_file_set_integer(kf, SECTION_GUI, "wnd_y_size2", options.wnd_y_size2);
	g_key_file_set_comment(kf, SECTION_GUI, "wnd_y_size2", "Size of window (no local)", &error);

	g_key_file_set_integer(kf, SECTION_GUI, "local_sort", options.local_sort);
	g_key_file_set_comment(kf, SECTION_GUI, "local_sort", "Sorting mode for local view", &error);

	g_key_file_set_integer(kf, SECTION_GUI, "local_sort_order", options.local_sort_order);
	g_key_file_set_comment(kf, SECTION_GUI, "local_sort_order", "Sorting order for local view", &error);

	g_key_file_set_integer(kf, SECTION_GUI, "remote_sort", options.remote_sort);
	g_key_file_set_comment(kf, SECTION_GUI, "remote_sort", "Sorting mode for remote view", &error);

	g_key_file_set_integer(kf, SECTION_GUI, "remote_sort_order", options.remote_sort_order);
	g_key_file_set_comment(kf, SECTION_GUI, "remote_sort_order", "Sorting order for remote view", &error);

	g_key_file_set_integer(kf, SECTION_GUI, "fs_type", options.filesel_type);
	g_key_file_set_comment(kf, SECTION_GUI, "fs_type", "Obsolete, ignored by current TiLP", &error);

	g_key_file_set_integer(kf, SECTION_GUI, "filesel_type", options.filesel_type);
	g_key_file_set_comment(kf, SECTION_GUI, "filesel_type", "File Selector type", &error);

	g_key_file_set_integer(kf, SECTION_GUI, "full_gui", options.full_gui);
	g_key_file_set_comment(kf, SECTION_GUI, "full_gui", "Use full gui (TiLP-I) or just remote view", &error);

	// Section [OPTIONS]
	g_key_file_set_integer(kf, SECTION_OPTIONS, "auto_detect", options.auto_detect);
	g_key_file_set_comment(kf, SECTION_OPTIONS, "auto_detect", "Auto-detect USB handheld model", &error);

	g_key_file_set_integer(kf, SECTION_OPTIONS, "show_all", options.show_all);
	g_key_file_set_comment(kf, SECTION_OPTIONS, "show_all", "Show hidden files in local view", &error);

	g_key_file_set_integer(kf, SECTION_OPTIONS, "overwrite", options.overwrite);
	g_key_file_set_comment(kf, SECTION_OPTIONS, "overwrite", "Ask for overwriting", &error);

	g_key_file_set_integer(kf, SECTION_OPTIONS, "recv_as_group", options.recv_as_group);
	g_key_file_set_comment(kf, SECTION_OPTIONS, "recv_as_group", "Receive as group instead of single files", &error);

	g_key_file_set_integer(kf, SECTION_OPTIONS, "backup_as_tigroup", options.backup_as_tigroup);
	g_key_file_set_comment(kf, SECTION_OPTIONS, "backup_as_tigroup", "Receive as TIGroup instead of backup/group files", &error);

	g_key_file_set_string (kf, SECTION_OPTIONS, "working_dir", options.working_dir);
	g_key_file_set_comment(kf, SECTION_OPTIONS, "working_dir", "Working folder", &error);

	// Section [FONTS]
	g_key_file_set_string (kf, SECTION_FONTS, "remote_font_name", options.remote_font_name);
	g_key_file_set_comment(kf, SECTION_FONTS, "remote_font_name", "Font to use for remote view", &error);

	g_key_file_set_string (kf, SECTION_FONTS, "local_font_name", options.local_font_name);
	g_key_file_set_comment(kf, SECTION_FONTS, "local_font_name", "Font to use for local view", &error);

	// Section [SCREEN]
	g_key_file_set_integer(kf, SECTION_SCREEN, "screen_format", options.screen_format);
	g_key_file_set_comment(kf, SECTION_SCREEN, "screen_format", "Screen format", &error);

	g_key_file_set_integer(kf, SECTION_SCREEN, "screen_scaling", options.screen_scaling);
	g_key_file_set_comment(kf, SECTION_SCREEN, "screen_scaling", "Screen scaling", &error);

	g_key_file_set_integer(kf, SECTION_SCREEN, "screen_clipping", options.screen_clipping);
	g_key_file_set_comment(kf, SECTION_SCREEN, "screen_clipping", "Screen clipping", &error);

	g_key_file_set_integer(kf, SECTION_SCREEN, "screen_blurry", options.screen_blurry);
	g_key_file_set_comment(kf, SECTION_SCREEN, "screen_blurry", "Save as blurry image", &error);

	// export file as string
	content = g_key_file_to_data(kf, NULL, &error);
	if(error != NULL)
	{
		fprintf (stderr, "Unable to read file: %s\n", error->message);
		g_error_free(error);
		ret = -1;
		goto exit;
	} 
	
	// write content
	f = fopen(ini_file, "wt");
	if (f == NULL) 
	{
		gif->msg_box1(_("Error"), _("Unable to write the config file (~/.tilp or ~/tilp.ini).\n"));
		ret = -1;
		goto exit;
	}
	if (fwrite(content, strlen(content), 1, f) < 1)
	{
		ret = -1;
	}
	fclose(f);

exit:
	// free structures
	g_free(content);
	g_key_file_free(kf);
	g_free(ini_file);

	return ret;
}
void cairo_dock_replace_key_values (GKeyFile *pOriginalKeyFile, GKeyFile *pReplacementKeyFile, gboolean bUseOriginalKeys, gchar iIdentifier)
{
	g_print ("%s (%d, %d)\n", __func__, iIdentifier, bUseOriginalKeys);
	GError *erreur = NULL;
	gsize length = 0;
	gchar **pKeyList;
	gchar **pGroupList = g_key_file_get_groups ((bUseOriginalKeys ? pOriginalKeyFile : pReplacementKeyFile), &length);
	g_return_if_fail (pGroupList != NULL);
	gchar *cGroupName, *cKeyName, *cKeyValue, *cComment;
	int i, j;

	i = 0;
	while (pGroupList[i] != NULL)
	{
		cGroupName = pGroupList[i];

		length = 0;
		pKeyList = g_key_file_get_keys ((bUseOriginalKeys ? pOriginalKeyFile : pReplacementKeyFile), cGroupName, NULL, NULL);
		g_return_if_fail (pKeyList != NULL);
		
		j = 0;
		while (pKeyList[j] != NULL)
		{
			cKeyName = pKeyList[j];
			//g_print ("%s\n  %s", cKeyName, g_key_file_get_comment (pOriginalKeyFile, cGroupName, cKeyName, NULL));

			if (iIdentifier != 0)
			{
				cComment = g_key_file_get_comment (bUseOriginalKeys ? pOriginalKeyFile : pReplacementKeyFile, cGroupName, cKeyName, NULL);
				//g_print ("%s\n  %s", cKeyName, cComment);
				if (cComment == NULL || strlen (cComment) < 2 || cComment[1] != iIdentifier)
				{
					//g_print ("  on saute %s;%s (%s)\n", cGroupName, cKeyName, cComment);
					g_free (cComment);
					j ++;
					continue ;
				}
				g_free (cComment);
			}

			cKeyValue =  g_key_file_get_string (pReplacementKeyFile, cGroupName, cKeyName, &erreur);
			if (erreur != NULL)
			{
				cd_warning (erreur->message);
				g_error_free (erreur);
				erreur = NULL;
			}
			else
			{
				//g_print (" -> %s\n", cKeyValue);
				if (cKeyValue[strlen(cKeyValue) - 1] == '\n')
					cKeyValue[strlen(cKeyValue) - 1] = '\0';
				g_key_file_set_string (pOriginalKeyFile, cGroupName, cKeyName, (cKeyValue != NULL ? cKeyValue : ""));
			}
			g_free (cKeyValue);
			j ++;
		}

		g_strfreev (pKeyList);
		i ++;
	}
	g_strfreev (pGroupList);
	
	if (bUseOriginalKeys)
	{
		pGroupList = g_key_file_get_groups (pReplacementKeyFile, &length);
		i = 0;
		while (pGroupList[i] != NULL)
		{
			cGroupName = pGroupList[i];

			length = 0;
			pKeyList = g_key_file_get_keys (pReplacementKeyFile, cGroupName, NULL, NULL);

			j = 0;
			while (pKeyList[j] != NULL)
			{
				cKeyName = pKeyList[j];
				//g_print ("%s\n  %s", cKeyName, g_key_file_get_comment (pOriginalKeyFile, cGroupName, cKeyName, NULL));

				cComment = g_key_file_get_comment (pReplacementKeyFile, cGroupName, cKeyName, NULL);
				if (cComment == NULL || strlen (cComment) < 3 || (cComment[1] != '0' && cComment[2] != '0'))
				{
					g_free (cComment);
					j ++;
					continue ;
				}
				if (iIdentifier != 0)
				{
					if (cComment == NULL || strlen (cComment) < 2 || cComment[1] != iIdentifier)
					{
						//g_print ("  on saute %s;%s (%s)\n", cGroupName, cKeyName, cComment);
						g_free (cComment);
						j ++;
						continue ;
					}
				}

				cKeyValue =  g_key_file_get_string (pReplacementKeyFile, cGroupName, cKeyName, &erreur);
				if (erreur != NULL)
				{
					cd_warning (erreur->message);
					g_error_free (erreur);
					erreur = NULL;
				}
				else
				{
					//g_print (" -> %s\n", cKeyValue);
					if (cKeyValue[strlen(cKeyValue) - 1] == '\n')
						cKeyValue[strlen(cKeyValue) - 1] = '\0';
					g_key_file_set_string (pOriginalKeyFile, cGroupName, cKeyName, (cKeyValue != NULL ? cKeyValue : ""));
					if (cComment != NULL)
					{
						g_key_file_set_comment (pOriginalKeyFile, cGroupName, cKeyName, cComment, &erreur);
						if (erreur != NULL)
						{
							cd_warning (erreur->message);
							g_error_free (erreur);
							erreur = NULL;
						}
					}
				}
				g_free (cKeyValue);
				g_free (cComment);
				j ++;
			}

			g_strfreev (pKeyList);
			i ++;
		}
		g_strfreev (pGroupList);
	}
}