static GdkPixbuf * about_dialog_load_logo (void) { GdkPixbuf *pixbuf = NULL; GFile *file; GInputStream *input; file = gimp_data_directory_file ("images", #ifdef GIMP_UNSTABLE "gimp-devel-logo.png", #else "gimp-logo.png", #endif NULL); input = G_INPUT_STREAM (g_file_read (file, NULL, NULL)); g_object_unref (file); if (input) { pixbuf = gdk_pixbuf_new_from_stream (input, NULL, NULL); g_object_unref (input); } return pixbuf; }
void gimp_icons_set_icon_theme (GFile *path) { gchar *icon_theme_name; GFile *search_path; g_return_if_fail (path == NULL || G_IS_FILE (path)); if (path) path = g_object_ref (path); else path = gimp_data_directory_file ("icons", GIMP_DEFAULT_ICON_THEME, NULL); search_path = g_file_get_parent (path); icon_theme_name = g_file_get_basename (path); if (gimp_icons_sanity_check (search_path, "hicolor") && gimp_icons_sanity_check (search_path, icon_theme_name)) { if (icon_theme_path) { /* this is an icon theme change */ gimp_icons_change_icon_theme (search_path); if (! g_file_equal (icon_theme_path, path)) { g_object_unref (icon_theme_path); icon_theme_path = g_object_ref (path); } g_object_set (gtk_settings_get_for_screen (gdk_screen_get_default ()), "gtk-icon-theme-name", icon_theme_name, NULL); } else { /* this is the first call upon initialization */ icon_theme_path = g_object_ref (path); } } g_free (icon_theme_name); g_object_unref (search_path); g_object_unref (path); }
gboolean gimp_tags_user_install (void) { GFile *file; GOutputStream *output; GMarkupParser markup_parser; GimpXmlParser *xml_parser; const char *tags_locale; GimpTagsInstaller tags_installer = { 0, }; GError *error = NULL; gboolean result = TRUE; /* This is a special string to specify the language identifier to * look for in the gimp-tags-default.xml file. Please translate the * C in it according to the name of the po file used for * gimp-tags-default.xml. E.g. lithuanian for the translation, * that would be "tags-locale:lt". */ tags_locale = _("tags-locale:C"); if (g_str_has_prefix (tags_locale, "tags-locale:")) { tags_locale += strlen ("tags-locale:"); if (*tags_locale && *tags_locale != 'C') tags_installer.locale = tags_locale; } else { g_warning ("Wrong translation for 'tags-locale:', fix the translation!"); } tags_installer.buf = g_string_new (NULL); g_string_append (tags_installer.buf, "<?xml version='1.0' encoding='UTF-8'?>\n"); g_string_append (tags_installer.buf, "<tags>\n"); markup_parser.start_element = gimp_tags_installer_load_start_element; markup_parser.end_element = gimp_tags_installer_load_end_element; markup_parser.text = gimp_tags_installer_load_text; markup_parser.passthrough = NULL; markup_parser.error = NULL; xml_parser = gimp_xml_parser_new (&markup_parser, &tags_installer); file = gimp_data_directory_file ("tags", "gimp-tags-default.xml", NULL); result = gimp_xml_parser_parse_gfile (xml_parser, file, &error); g_object_unref (file); gimp_xml_parser_free (xml_parser); if (! result) { g_string_free (tags_installer.buf, TRUE); return FALSE; } g_string_append (tags_installer.buf, "\n</tags>\n"); file = gimp_directory_file (GIMP_TAGS_FILE, NULL); output = G_OUTPUT_STREAM (g_file_replace (file, NULL, FALSE, G_FILE_CREATE_NONE, NULL, &error)); if (! output) { g_printerr ("%s\n", error->message); result = FALSE; } else if (! g_output_stream_write_all (output, tags_installer.buf->str, tags_installer.buf->len, NULL, NULL, &error)) { GCancellable *cancellable = g_cancellable_new (); g_printerr (_("Error writing '%s': %s"), gimp_file_get_utf8_name (file), error->message); result = FALSE; /* Cancel the overwrite initiated by g_file_replace(). */ g_cancellable_cancel (cancellable); g_output_stream_close (output, cancellable, NULL); g_object_unref (cancellable); } else if (! g_output_stream_close (output, NULL, &error)) { g_printerr (_("Error closing '%s': %s"), gimp_file_get_utf8_name (file), error->message); result = FALSE; } if (output) g_object_unref (output); g_clear_error (&error); g_object_unref (file); g_string_free (tags_installer.buf, TRUE); return result; }
/** * gimp_icons_init: * * Initializes the GIMP stock icon factory. * * You don't need to call this function as gimp_ui_init() already does * this for you. */ void gimp_icons_init (void) { static gboolean initialized = FALSE; GtkSettings *settings; GdkPixbuf *pixbuf; GError *error = NULL; gchar *icons_dir; gchar *system_icon_theme; gchar *gimp_icon_theme; gint i; if (initialized) return; gimp_stock_factory = gtk_icon_factory_new (); for (i = 0; i < G_N_ELEMENTS (gimp_stock_items); i++) { register_stock_icon (gimp_stock_factory, gimp_stock_items[i].stock_id, gimp_stock_items[i].stock_id); } register_bidi_stock_icon (gimp_stock_factory, GIMP_STOCK_MENU_LEFT, GIMP_STOCK_MENU_LEFT, GIMP_STOCK_MENU_RIGHT); register_bidi_stock_icon (gimp_stock_factory, GIMP_STOCK_MENU_RIGHT, GIMP_STOCK_MENU_RIGHT, GIMP_STOCK_MENU_LEFT); register_stock_icon (gimp_stock_factory, "gimp-indexed-palette", GIMP_STOCK_COLORMAP); register_stock_icon (gimp_stock_factory, "gimp-qmask-off", GIMP_STOCK_QUICK_MASK_OFF); register_stock_icon (gimp_stock_factory, "gimp-qmask-on", GIMP_STOCK_QUICK_MASK_ON); gtk_icon_factory_add_default (gimp_stock_factory); gtk_stock_add_static (gimp_stock_items, G_N_ELEMENTS (gimp_stock_items)); gtk_stock_add_static (gimp_compat_stock_items, G_N_ELEMENTS (gimp_compat_stock_items)); /* always prepend the default icon theme, it's never removed from * the path again and acts as fallback for missing icons in other * themes. */ if (! default_search_path) default_search_path = gimp_data_directory_file ("icons", NULL); icons_dir = g_file_get_path (default_search_path); gtk_icon_theme_prepend_search_path (gtk_icon_theme_get_default (), icons_dir); g_free (icons_dir); /* if an icon theme was chosen before init(), change to it */ if (icon_theme_path) { GFile *search_path = g_file_get_parent (icon_theme_path); if (!g_file_equal (search_path, default_search_path)) { gchar *icon_dir = g_file_get_path (search_path); gtk_icon_theme_prepend_search_path (gtk_icon_theme_get_default (), icon_dir); g_free (icon_dir); } g_object_unref (search_path); gimp_icon_theme = g_file_get_basename (icon_theme_path); } else { gimp_icon_theme = g_strdup (GIMP_DEFAULT_ICON_THEME); } settings = gtk_settings_get_for_screen (gdk_screen_get_default ()); g_object_get (settings, "gtk-icon-theme-name", &system_icon_theme, NULL); g_object_set (settings, "gtk-fallback-icon-theme", system_icon_theme, "gtk-icon-theme-name", gimp_icon_theme, NULL); g_free (gimp_icon_theme); g_free (system_icon_theme); g_signal_connect (settings, "notify::gtk-icon-theme-name", G_CALLBACK (gimp_icons_notify_system_icon_theme), NULL); pixbuf = gdk_pixbuf_new_from_resource ("/org/gimp/icons/64/gimp-wilber-eek.png", &error); if (pixbuf) { gtk_icon_theme_add_builtin_icon (GIMP_STOCK_WILBER_EEK, 64, pixbuf); g_object_unref (pixbuf); } else { g_critical ("Failed to create icon image: %s", error->message); g_clear_error (&error); } initialized = TRUE; }
static void gimp_icons_change_icon_theme (GFile *new_search_path) { GFile *old_search_path = g_file_get_parent (icon_theme_path); if (! default_search_path) default_search_path = gimp_data_directory_file ("icons", NULL); if (! g_file_equal (new_search_path, old_search_path)) { GtkIconTheme *icon_theme = gtk_icon_theme_get_default (); if (g_file_equal (old_search_path, default_search_path)) { /* if the old icon theme is in the default search path, * simply prepend the new theme's path */ gchar *path_str = g_file_get_path (new_search_path); gtk_icon_theme_prepend_search_path (icon_theme, path_str); g_free (path_str); } else { /* if the old theme is not in the default search path, * we need to deal with the search path's first element */ gchar **paths; gint n_paths; gtk_icon_theme_get_search_path (icon_theme, &paths, &n_paths); if (g_file_equal (new_search_path, default_search_path)) { /* when switching to a theme in the default path, remove * the first search path element, the default search path * is still in the search path */ gtk_icon_theme_set_search_path (icon_theme, (const gchar **) paths + 1, n_paths - 1); } else { /* when switching between two non-default search paths, replace * the first element of the search path with the new * theme's path */ g_free (paths[0]); paths[0] = g_file_get_path (new_search_path); gtk_icon_theme_set_search_path (icon_theme, (const gchar **) paths, n_paths); } g_strfreev (paths); } } g_object_unref (old_search_path); }