Exemplo n.º 1
0
void test_setlocale()
{
	GKeyFile *keyfile;
	gchar *value;
	gchar **list;
	gchar *input_list[2] = {"test2","test3"};
	gsize length = 2;
	
	const gchar *data = 
	    "[1]\n"
	    "key1=123\n"
	    "key2=456\n";
	
	keyfile = load_data (data, 0);
	
	g_key_file_set_locale_string(keyfile,"1","key3","C","test");
	
	value = g_key_file_get_locale_string(keyfile,"1","key3","C",NULL);
	
	g_assert(!strcmp(value,"test"));
	
	g_free(value);
	
	value = g_key_file_get_locale_string(keyfile,"1","key3","de",NULL);
	
	g_assert(value == NULL);
	
	g_key_file_set_locale_string_list(keyfile,"1","key4","C",input_list,2);
	
	list = g_key_file_get_locale_string_list(keyfile,"1","key4","C",&length,NULL);
	
	g_assert(!strcmp(list[0],"test2"));
	g_assert(!strcmp(list[1],"test3"));
	
}
Exemplo n.º 2
0
static gboolean
nemo_link_local_set_key (const char *uri,
			     const char *key,
			     const char *value,
			     gboolean    localize)
{
	gboolean success;
	GKeyFile *key_file;
	GFile *file;
	
	file = g_file_new_for_uri (uri);
	key_file = g_key_file_new ();
	if (!_g_key_file_load_from_gfile (key_file, file, G_KEY_FILE_KEEP_COMMENTS, NULL)) {
		g_key_file_free (key_file);
		g_object_unref (file);
		return FALSE;
	}
	if (localize) {
		g_key_file_set_locale_string (key_file,
					      MAIN_GROUP,
					      key,
					      get_language (), 
					      value);
	} else {
		g_key_file_set_string (key_file, MAIN_GROUP, key, value);
	}
	
	
	success = _g_key_file_save_to_gfile (key_file,  file, NULL);
	g_key_file_free (key_file);
	g_object_unref (file);
	return success;
}
static void
save_entry (GtkEntry *entry, GKeyFile *key_file, const char *uri)
{
	GError *error;
	ItemEntry *item_entry;
	const char *val;
	gchar **languages;

	item_entry = g_object_get_data (G_OBJECT (entry), "item_entry");
	val = gtk_entry_get_text (entry);

	if (strcmp (val, item_entry->current_value) == 0) {
		return; /* No actual change, don't update file */
	}

	g_free (item_entry->current_value);
	item_entry->current_value = g_strdup (val);
	
	if (item_entry->localized) {
		languages = (gchar **) g_get_language_names ();
		g_key_file_set_locale_string (key_file, MAIN_GROUP, item_entry->field, languages[0], val);
	} else {
		g_key_file_set_string (key_file, MAIN_GROUP, item_entry->field, val);
	}

	error = NULL;

	if (!_g_key_file_save_to_uri (key_file, uri, &error)) {
		g_warning ("%s", error->message);
		g_error_free (error);
	}
}
Exemplo n.º 4
0
void
panel_key_file_set_locale_string (GKeyFile    *keyfile,
				  const gchar *key,
				  const gchar *value)
{
	const char         *locale;
	const char * const *langs_pointer;
	int                 i;

	locale = NULL;
	langs_pointer = g_get_language_names ();
	for (i = 0; langs_pointer[i] != NULL; i++) {
		/* find first without encoding  */
		if (strchr (langs_pointer[i], '.') == NULL) {
			locale = langs_pointer[i]; 
			break;
		}
	}

	if (locale)
		g_key_file_set_locale_string (keyfile, G_KEY_FILE_DESKTOP_GROUP,
					      key, locale, value);
	else
		g_key_file_set_string (keyfile, G_KEY_FILE_DESKTOP_GROUP,
				       key, value);
}
/* Serialize the top-level profiles
 * Note: They don't have to be containerprofiles */
static gboolean
serialize_encoding_profile (GKeyFile * out, GstEncodingProfile * prof)
{
  gchar *profgroupname;
  const GList *tmp;
  guint i;
  const gchar *profname, *profdesc, *profpreset, *proftype;
  GstCaps *profformat;

  profname = gst_encoding_profile_get_name (prof);
  profdesc = gst_encoding_profile_get_description (prof);
  profformat = gst_encoding_profile_get_format (prof);
  profpreset = gst_encoding_profile_get_preset (prof);
  proftype = gst_encoding_profile_get_type_nick (prof);

  profgroupname = g_strdup_printf ("profile-%s", profname);

  g_key_file_set_string (out, profgroupname, "name", profname);

  g_key_file_set_value (out, profgroupname, "type", proftype);

  if (profdesc) {
    gchar *locale;

    locale = get_locale ();
    if (locale != NULL) {
      g_key_file_set_locale_string (out, profgroupname, "description",
          locale, profdesc);
      g_free (locale);
    } else {
      g_key_file_set_string (out, profgroupname, "description", profdesc);
    }
  }
  if (profformat) {
    gchar *tmpc = gst_caps_to_string (profformat);
    g_key_file_set_string (out, profgroupname, "format", tmpc);
    g_free (tmpc);
  }
  if (profpreset)
    g_key_file_set_string (out, profgroupname, "preset", profpreset);

  /* stream profiles */
  if (GST_IS_ENCODING_CONTAINER_PROFILE (prof)) {
    for (tmp =
        gst_encoding_container_profile_get_profiles
        (GST_ENCODING_CONTAINER_PROFILE (prof)), i = 0; tmp;
        tmp = tmp->next, i++) {
      GstEncodingProfile *sprof = (GstEncodingProfile *) tmp->data;

      if (!serialize_stream_profiles (out, sprof, profname, i))
        return FALSE;
    }
  }
  if (profformat)
    gst_caps_unref (profformat);
  g_free (profgroupname);
  return TRUE;
}
Exemplo n.º 6
0
static void _dentry_tooltip_changed(GtkEditable *editable, FmFilePropertiesDEntryData *data)
{
    /* g_debug("entry content changed"); */
    if (data->lang)
        g_key_file_set_locale_string(data->kf, GRP_NAME, "Comment", data->lang,
                                     gtk_entry_get_text(GTK_ENTRY(editable)));
    else
        g_key_file_set_string(data->kf, GRP_NAME, "Comment",
                              gtk_entry_get_text(GTK_ENTRY(editable)));
    data->changed = TRUE;
}
Exemplo n.º 7
0
gboolean vfs_app_desktop_rename( char* desktop_file_path, char* new_name )   //sfm
{
    if ( !desktop_file_path || !new_name )
        return FALSE;
        
    GKeyFile* kfile = g_key_file_new();
    
    // load
    if ( !g_key_file_load_from_file( kfile, desktop_file_path,
                                        G_KEY_FILE_KEEP_COMMENTS
                                        | G_KEY_FILE_KEEP_TRANSLATIONS, NULL ) )
    {
        g_key_file_free( kfile );
        return FALSE;
    }

    // get user's locale
    const char* locale = NULL;
    const char* const * langs = g_get_language_names();
    char* dot = strchr( langs[0], '.' );
    if( dot )
        locale = g_strndup( langs[0], (size_t)(dot - langs[0]) );
    else
        locale = langs[0];
    if ( !locale || locale[0] == '\0' )
        locale = "en";
    char* l = g_strdup( locale );
    char* ll = strchr( l, '_' );
    if ( ll )
        ll[0] = '\0';

    // update keyfile
    g_key_file_set_locale_string( kfile, desktop_entry_name, "Name", l, new_name );
    if ( strcmp( l, locale ) )
        g_key_file_set_locale_string( kfile, desktop_entry_name, "Name", locale, new_name );
    g_free( l );

    // get keyfile as string
    char* data = g_key_file_to_data( kfile, NULL, NULL );
    g_key_file_free( kfile );
    
    // overwrite desktop file
    if ( data )
    {
        FILE* file = fopen( desktop_file_path, "w" );
        if ( file )
        {
            int result = fputs( data, file );
            g_free( data );
            fclose( file );
            if ( result < 0 )
                return FALSE;
        }
        else
        {
            g_free( data );
            return FALSE;
        }
    }
    else
        return FALSE;
    return TRUE;
}