QIcon get_file_icon(const QString& content_type) { static QCache<QString, QIcon> cache; cache.setMaxCost(100); if (cache.contains(content_type)) return QIcon(*(cache.object(content_type))); QByteArray ba = content_type.toLocal8Bit(); GIcon* gicon = g_content_type_get_icon(ba.constData()); QStringList tried_names; if (G_IS_THEMED_ICON(gicon)) { const gchar * const * names = g_themed_icon_get_names(reinterpret_cast<GThemedIcon*>(gicon)); if (names != 0) { int i = 0; while(names[i] != 0) { QString name = QString::fromLocal8Bit(names[i]); QIcon r = QIcon::fromTheme(name); if (r.isNull()) { tried_names << name; } else { cache.insert(content_type, new QIcon(r)); g_object_unref(gicon); return r; } i++; } } else { qDebug() << "get_file_icon: empty or invalid result of g_themed_icon_get_names"; } } else { qDebug() << "get_file_icon: gicon is not themed icon"; } qDebug() << "get_file_icon(" << content_type << "): no valid names" << tried_names << "; returning null icon"; cache.insert(content_type, new QIcon()); g_object_unref(gicon); return QIcon(); }
static GdkPixbuf* get_icon_pixbuf_for_content_type (const char *ctype, size_t size) { GIcon *icon; GdkPixbuf *pixbuf; icon = g_content_type_get_icon (ctype); pixbuf = NULL; /* based on a snippet from http://www.gtkforums.com/about4721.html */ if (G_IS_THEMED_ICON(icon)) { gchar const * const *names; names = g_themed_icon_get_names (G_THEMED_ICON(icon)); pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default(), *names, size, 0, NULL); } else if (G_IS_FILE_ICON(icon)) { GFile *icon_file; gchar *path; icon_file = g_file_icon_get_file (G_FILE_ICON(icon)); path = g_file_get_path (icon_file); pixbuf = gdk_pixbuf_new_from_file_at_size (path, size, size, NULL); g_free (path); g_object_unref(icon_file); } g_object_unref(icon); return pixbuf; }
static GdkPixbuf * icon_cache_get_mime_type_icon (IconCache * icon_cache, const char * mime_type) { GIcon * icon; const char * key = NULL; GdkPixbuf * pixbuf; icon = g_content_type_get_icon (mime_type); key = _icon_cache_get_icon_key (icon); if (key == NULL) key = VOID_PIXBUF_KEY; pixbuf = g_hash_table_lookup (icon_cache->cache, key); if (pixbuf != NULL) { g_object_ref (pixbuf); g_object_unref (G_OBJECT (icon)); return pixbuf; } pixbuf = _get_icon_pixbuf (icon, icon_cache->icon_size, icon_cache->icon_theme); if (pixbuf != NULL) g_hash_table_insert (icon_cache->cache, (gpointer) key, g_object_ref (pixbuf)); g_object_unref (G_OBJECT (icon)); return pixbuf; }
static void trg_cell_renderer_file_icon_refresh(TrgCellRendererFileIcon * fi) { TrgCellRendererFileIconPrivate *priv = TRG_CELL_RENDERER_FILE_ICON_GET_PRIVATE(fi); if (priv->file_id == -2) { return; } else if (priv->file_id == -1) { g_object_set(fi, "stock-id", GTK_STOCK_DIRECTORY, NULL); } else if (priv->text) { #ifndef WIN32 gboolean uncertain; gchar *mimetype = g_content_type_guess(priv->text, NULL, 0, &uncertain); GIcon *icon = NULL; if (!uncertain && mimetype) icon = g_content_type_get_icon(mimetype); g_free(mimetype); if (icon) { g_object_set(fi, "gicon", icon, NULL); g_object_unref(icon); } else { g_object_set(fi, "stock-id", GTK_STOCK_FILE, NULL); } #else g_object_set(fi, "stock-id", GTK_STOCK_FILE, NULL); #endif } }
foreach_slist (elem, file_list) { GtkTreeIter iter; gchar **path_arr = elem->data; GIcon *icon = NULL; gchar *content_type = g_content_type_guess(path_arr[level], NULL, 0, NULL); if (content_type) { icon = g_content_type_get_icon(content_type); if (icon) { GtkIconInfo *icon_info; icon_info = gtk_icon_theme_lookup_by_gicon(gtk_icon_theme_get_default(), icon, 16, 0); if (!icon_info) { g_object_unref(icon); icon = NULL; } else gtk_icon_info_free(icon_info); } g_free(content_type); } if (patterns_match(header_patterns, path_arr[level])) { if (! icon) icon = g_icon_new_for_string("prjorg-header", NULL); gtk_tree_store_insert_with_values(s_file_store, &iter, parent, 0, FILEVIEW_COLUMN_ICON, icon, FILEVIEW_COLUMN_NAME, path_arr[level], FILEVIEW_COLUMN_COLOR, project ? NULL : &s_external_color, -1); } else if (patterns_match(source_patterns, path_arr[level])) { if (! icon) icon = g_icon_new_for_string("prjorg-source", NULL); gtk_tree_store_insert_with_values(s_file_store, &iter, parent, 0, FILEVIEW_COLUMN_ICON, icon, FILEVIEW_COLUMN_NAME, path_arr[level], FILEVIEW_COLUMN_COLOR, project ? NULL : &s_external_color, -1); } else { if (! icon) icon = g_icon_new_for_string("prjorg-file", NULL); gtk_tree_store_insert_with_values(s_file_store, &iter, parent, 0, FILEVIEW_COLUMN_ICON, icon, FILEVIEW_COLUMN_NAME, path_arr[level], FILEVIEW_COLUMN_COLOR, project ? NULL : &s_external_color, -1); } if (icon) g_object_unref(icon); }
/* libbalsa_icon_finder: * locate a suitable icon (pixmap graphic) based on 'mime-type' and/or * 'filename', either of which can be NULL. If both arguments are * non-NULL, 'mime-type' has priority. If both are NULL, the default * 'attachment.png' icon will be returned. This function *MUST* * return the complete path to the icon file. */ GdkPixbuf * libbalsa_icon_finder(GtkWidget * widget, const char * mime_type, const LibbalsaVfs * for_file, gchar ** used_type, GtkIconSize size) { const gchar *content_type; GdkPixbuf *pixbuf = NULL; gint width, height; GtkIconTheme *icon_theme; GIcon *icon; if (!gtk_icon_size_lookup(size, &width, &height)) width = 16; if (mime_type) content_type = mime_type; else if (for_file) { content_type = libbalsa_vfs_get_mime_type(for_file); } else content_type = "application/octet-stream"; /* ask GIO for the icon */ if ((icon_theme = gtk_icon_theme_get_default()) == NULL) return NULL; icon = g_content_type_get_icon(content_type); if (icon != NULL) { if (G_IS_THEMED_ICON(icon)) { gint i; GStrv icon_names; g_object_get(G_OBJECT(icon), "names", &icon_names, NULL); if (icon_names != NULL) { for (i = 0; pixbuf == NULL && icon_names[i] != NULL; i++) { pixbuf = gtk_icon_theme_load_icon(icon_theme, icon_names[i], width, GTK_ICON_LOOKUP_FORCE_SIZE, NULL); } g_strfreev(icon_names); } } g_object_unref(icon); } if (pixbuf == NULL) { /* load the default pixbuf */ pixbuf = libbalsa_default_attachment_pixbuf(width); } if (used_type) *used_type = g_strdup(content_type); return pixbuf; }
static void file_chooser_dialog_response_cb (GtkDialog *dialog, int response, gpointer user_data) { GthSlideshowPreferences *self = user_data; switch (response) { case GTK_RESPONSE_DELETE_EVENT: case GTK_RESPONSE_CANCEL: gtk_widget_destroy (GTK_WIDGET (dialog)); break; case GTK_RESPONSE_OK: { GSList *files; GthIconCache *icon_cache; GtkListStore *list_store; GSList *scan; files = gtk_file_chooser_get_files (GTK_FILE_CHOOSER (dialog)); icon_cache = gth_icon_cache_new_for_widget(GTK_WIDGET (self), GTK_ICON_SIZE_MENU); list_store = (GtkListStore *) gtk_builder_get_object (self->priv->builder, "files_liststore"); for (scan = files; scan; scan = scan->next) { GFile *file = scan->data; GIcon *icon; GdkPixbuf *pixbuf; char *uri; char *name; GtkTreeIter iter; icon = g_content_type_get_icon ("audio"); pixbuf = gth_icon_cache_get_pixbuf (icon_cache, icon); uri = g_file_get_uri (file); name = _g_file_get_display_name (file); gtk_list_store_append (list_store, &iter); gtk_list_store_set (list_store, &iter, FILE_COLUMN_ICON, pixbuf, FILE_COLUMN_NAME, name, FILE_COLUMN_URI, uri, -1); g_free (name); g_free (uri); g_object_unref (pixbuf); } gth_icon_cache_free (icon_cache); g_slist_foreach (files, (GFunc) g_object_unref, NULL); g_slist_free (files); } gtk_widget_destroy (GTK_WIDGET (dialog)); break; } }
GIcon * mousepad_util_icon_for_mime_type (const gchar *mime_type) { gchar *content_type; GIcon *icon = NULL; g_return_val_if_fail (mime_type != NULL, NULL); content_type = g_content_type_from_mime_type (mime_type); if (content_type != NULL) icon = g_content_type_get_icon (content_type); return icon; }
static GIcon * icon_for_mimetype (const char *mimetype) { char *content_type; GIcon *icon; content_type = g_content_type_from_mime_type (mimetype); if (!content_type) return NULL; icon = g_content_type_get_icon (content_type); g_free (content_type); return icon; }
void rejilla_mime_filter_add_mime (RejillaMimeFilter *filter, const gchar *mime) { GtkFileFilter *item; item = g_hash_table_lookup (filter->priv->table, mime); if (!item) { GIcon *icon; GtkTreeIter row; gchar *description; GtkTreeModel *model; description = g_content_type_get_description (mime); icon = g_content_type_get_icon (mime); /* create the GtkFileFilter */ item = gtk_file_filter_new (); gtk_file_filter_set_name (item, mime); gtk_file_filter_add_mime_type (item, mime); g_hash_table_insert (filter->priv->table, g_strdup (mime), item); g_object_add_toggle_ref (G_OBJECT (item), (GToggleNotify) rejilla_mime_filter_destroy_item_cb, filter); model = gtk_combo_box_get_model (GTK_COMBO_BOX (filter->combo)); gtk_list_store_append (GTK_LIST_STORE (model), &row); g_object_ref_sink (item); gtk_list_store_set (GTK_LIST_STORE (model), &row, REJILLA_MIME_FILTER_DISPLAY_COL, description, REJILLA_MIME_FILTER_ICON_COL, icon, REJILLA_MIME_FILTER_FILTER_COL, item, -1); g_object_unref (icon); g_free (description); /* we check that the first entry at least is visible */ if (gtk_combo_box_get_active (GTK_COMBO_BOX (filter->combo)) == -1 && gtk_tree_model_get_iter_first (model, &row) == TRUE) gtk_combo_box_set_active_iter (GTK_COMBO_BOX (filter->combo), &row); } else g_object_ref (item); }
GIcon * photos_utils_get_icon_from_cursor (TrackerSparqlCursor *cursor) { GIcon *icon = NULL; gboolean is_remote = FALSE; const gchar *identifier; const gchar *mime_type; const gchar *rdf_type; identifier = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_IDENTIFIER, NULL); if (identifier != NULL) { if (g_str_has_prefix (identifier, "facebook:") || g_str_has_prefix (identifier, "flickr:")) is_remote = TRUE; } if (!is_remote) { const gchar *uri; uri = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_URI, NULL); if (uri != NULL) icon = photos_utils_get_thumbnail_icon (uri); } if (icon != NULL) goto out; mime_type = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_MIME_TYPE, NULL); if (mime_type != NULL) icon = g_content_type_get_icon (mime_type); if (icon != NULL) goto out; rdf_type = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_RDF_TYPE, NULL); if (mime_type != NULL) icon = photos_utils_icon_from_rdf_type (rdf_type); if (icon != NULL) goto out; icon = g_themed_icon_new ("image-x-generic"); out: return icon; }
GIcon * photos_utils_get_icon_from_item (PhotosBaseItem *item) { GIcon *icon = NULL; gboolean is_remote = FALSE; const gchar *identifier; const gchar *mime_type; identifier = photos_base_item_get_identifier (item); if (identifier != NULL) { if (g_str_has_prefix (identifier, "facebook:") || g_str_has_prefix (identifier, "flickr:") || g_str_has_prefix (identifier, "google:")) is_remote = TRUE; } if (!is_remote) icon = photos_utils_get_thumbnail_icon (item); if (icon != NULL) goto out; mime_type = photos_base_item_get_mime_type (item); if (mime_type != NULL) icon = g_content_type_get_icon (mime_type); if (icon != NULL) goto out; if (photos_base_item_is_collection (item)) { gint size; size = photos_utils_get_icon_size (); icon = photos_utils_create_collection_icon (size, NULL); } if (icon != NULL) goto out; icon = g_themed_icon_new ("image-x-generic"); out: return icon; }
static void set_icon(GtkWindow *window, const gchar *uri) { GFile *file; GIcon *icon; GFileInfo *info; GdkScreen *screen; GtkIconTheme *icon_theme; const gchar *icon_name = NULL, *content_type; screen = gtk_widget_get_screen (GTK_WIDGET (window)); icon_theme = gtk_icon_theme_get_for_screen (screen); file = g_file_new_for_uri (uri); info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, G_FILE_QUERY_INFO_NONE, NULL, NULL); g_object_unref (file); if (! info) return; content_type = g_file_info_get_content_type (info); icon = g_content_type_get_icon (content_type); if (G_IS_THEMED_ICON (icon)) { const gchar * const *names = NULL; names = g_themed_icon_get_names (G_THEMED_ICON (icon)); if (names) { gint i; for (i = 0; names[i]; i++) { if (gtk_icon_theme_has_icon (icon_theme, names[i])) { icon_name = names[i]; break; } } } } if (icon_name) { gtk_window_set_icon_name (window, icon_name); } g_object_unref (icon); }
GdkPixbuf * get_mime_type_pixbuf (const char *mime_type, int icon_size, GtkIconTheme *icon_theme) { GdkPixbuf *pixbuf = NULL; GIcon *icon; if (icon_theme == NULL) icon_theme = gtk_icon_theme_get_default (); icon = g_content_type_get_icon (mime_type); pixbuf = get_icon_pixbuf (icon, icon_size, icon_theme); g_object_unref (icon); return pixbuf; }
GdkPixbuf * _g_mime_type_get_icon (const char *mime_type, int icon_size, GtkIconTheme *icon_theme) { GdkPixbuf *pixbuf = NULL; GIcon *icon; if (icon_theme == NULL) icon_theme = gtk_icon_theme_get_default (); icon = g_content_type_get_icon (mime_type); if (icon == NULL) icon = g_themed_icon_new ("text-x-generic"); pixbuf = _g_icon_get_pixbuf (icon, icon_size, icon_theme); g_object_unref (icon); return pixbuf; }
static GdkPixbuf * get_fallback_icon (void) { GtkIconTheme *icon_theme; GtkIconInfo *icon_info; GdkPixbuf *pix; GIcon *icon = NULL; icon_theme = gtk_icon_theme_get_default (); icon = g_content_type_get_icon ("application/x-font-ttf"); icon_info = gtk_icon_theme_lookup_by_gicon (icon_theme, icon, 128, GTK_ICON_LOOKUP_GENERIC_FALLBACK); g_object_unref (icon); if (!icon_info) return NULL; pix = gtk_icon_info_load_icon (icon_info, NULL); gtk_icon_info_free (icon_info); return pix; }
wxString wxGTKMimeTypesManagerImpl::GetIconFromMimeType(const wxString& mime) { wxString icon; #if GTK_CHECK_VERSION(2,14,0) if (!wx_is_at_least_gtk2(14)) return icon; wxGtkString type(g_content_type_from_mime_type(mime.utf8_str())); wxGtkObject<GIcon> gicon(g_content_type_get_icon(type)); if ( !gicon ) return icon; GtkIconTheme *theme(gtk_icon_theme_get_default()); if ( !theme ) return icon; // Notice that we can't use wxGtkObject here because a special function // needs to be used for freeing this object prior to GTK+ 3.8. GtkIconInfo* const giconinfo = gtk_icon_theme_lookup_by_gicon ( theme, gicon, 256, GTK_ICON_LOOKUP_NO_SVG ); if ( giconinfo ) { icon = wxString::FromUTF8(gtk_icon_info_get_filename(giconinfo)); wxGCC_WARNING_SUPPRESS(deprecated-declarations) gtk_icon_info_free(giconinfo); wxGCC_WARNING_RESTORE() } #endif // GTK_CHECK_VERSION(2,14,0) return icon; }
static void fr_file_selector_dialog_realize (GtkWidget *widget) { FrFileSelectorDialog *self; GIcon *icon; int sidebar_size; GTK_WIDGET_CLASS (fr_file_selector_dialog_parent_class)->realize (widget); self = FR_FILE_SELECTOR_DIALOG (widget); self->priv->icon_cache = gth_icon_cache_new_for_widget (GTK_WIDGET (self), GTK_ICON_SIZE_MENU); icon = g_content_type_get_icon ("text/plain"); gth_icon_cache_set_fallback (self->priv->icon_cache, icon); g_object_unref (icon); _fr_file_selector_dialog_update_size (self); sidebar_size = g_settings_get_int (self->priv->settings, PREF_FILE_SELECTOR_SIDEBAR_SIZE); if (sidebar_size <= 0) sidebar_size = get_font_size (widget) * SIDEBAR_CHARS; gtk_paned_set_position (GTK_PANED (GET_WIDGET ("main_paned")), sidebar_size); }
void gth_slideshow_preferences_set_audio (GthSlideshowPreferences *self, char **files) { GthIconCache *icon_cache; GtkListStore *list_store; int i; icon_cache = gth_icon_cache_new_for_widget(GTK_WIDGET (self), GTK_ICON_SIZE_MENU); list_store = (GtkListStore *) gtk_builder_get_object (self->priv->builder, "files_liststore"); gtk_list_store_clear (list_store); for (i = 0; files[i] != NULL; i++) { GIcon *icon; GdkPixbuf *pixbuf; GFile *file; char *name; GtkTreeIter iter; icon = g_content_type_get_icon ("audio"); pixbuf = gth_icon_cache_get_pixbuf (icon_cache, icon); file = g_file_new_for_uri (files[i]); name = _g_file_get_display_name (file); gtk_list_store_append (list_store, &iter); gtk_list_store_set (list_store, &iter, FILE_COLUMN_ICON, pixbuf, FILE_COLUMN_NAME, name, FILE_COLUMN_URI, files[i], -1); g_free (name); g_object_unref (file); g_object_unref (pixbuf); } gth_icon_cache_free (icon_cache); }
static gboolean video_area_expose_event_cb (GtkWidget *widget, GdkEventExpose *event, gpointer user_data) { GthMediaViewerPage *self = user_data; if (event->count > 0) return FALSE; if (self->priv->xwin_assigned && self->priv->has_video) return FALSE; if (self->priv->icon == NULL) { char *type; GIcon *icon; int size; type = NULL; if (self->priv->file_data != NULL) type = g_content_type_from_mime_type (gth_file_data_get_mime_type (self->priv->file_data)); if (type == NULL) type = g_content_type_from_mime_type ("text/plain"); icon = g_content_type_get_icon (type); size = widget->allocation.width; if (size > widget->allocation.height) size = widget->allocation.height; size = size / 3; self->priv->icon = _g_icon_get_pixbuf (icon, size, gtk_icon_theme_get_for_screen (gtk_widget_get_screen (widget))); g_object_unref (icon); g_free (type); } gdk_draw_rectangle (gtk_widget_get_window (widget), self->priv->has_video ? widget->style->black_gc : widget->style->text_gc[GTK_WIDGET_STATE (widget)], TRUE, event->area.x, event->area.y, event->area.width, event->area.height); if (self->priv->icon != NULL) { int icon_w, icon_h; int icon_x, icon_y; PangoRectangle logical_rect; int x, y; icon_w = gdk_pixbuf_get_width (self->priv->icon); icon_h = gdk_pixbuf_get_height (self->priv->icon); pango_layout_set_width (self->priv->caption_layout, PANGO_SCALE * (icon_w * 3 / 2)); pango_layout_get_extents (self->priv->caption_layout, NULL, &logical_rect); icon_x = (widget->allocation.width - icon_w) / 2; x = (widget->allocation.width - PANGO_PIXELS (logical_rect.width)) / 2 + PANGO_PIXELS (logical_rect.x); icon_y = (widget->allocation.height - (icon_h + PANGO_PIXELS (logical_rect.height))) / 2; y = icon_y + icon_h; gdk_draw_pixbuf (gtk_widget_get_window (widget), widget->style->base_gc[GTK_WIDGET_STATE (widget)], self->priv->icon, 0, 0, icon_x, icon_y, icon_w, icon_h, GDK_RGB_DITHER_NORMAL, 0, 0); gdk_draw_layout (gtk_widget_get_window (widget), widget->style->base_gc[GTK_WIDGET_STATE (widget)], x, y, self->priv->caption_layout); } return FALSE; }
void xfburn_directory_browser_load_path (XfburnDirectoryBrowser * browser, const gchar * path) { XfburnDirectoryBrowserPrivate *priv = XFBURN_DIRECTORY_BROWSER_GET_PRIVATE (browser); GtkTreeModel *model; GDir *dir; GError *error = NULL; GdkPixbuf *icon_directory, *icon_file; const gchar *dir_entry; int x, y; gchar *temp; GdkScreen *screen; GtkIconTheme *icon_theme; gboolean show_hidden; dir = g_dir_open (path, 0, &error); if (!dir) { g_warning ("unable to open the %s directory : %s", path, error->message); g_error_free (error); return; } temp = g_strdup (path); g_free (priv->current_path); priv->current_path = temp; model = gtk_tree_view_get_model (GTK_TREE_VIEW (browser)); gtk_list_store_clear (GTK_LIST_STORE (model)); screen = gtk_widget_get_screen (GTK_WIDGET (browser)); icon_theme = gtk_icon_theme_get_for_screen (screen); gtk_icon_size_lookup (GTK_ICON_SIZE_SMALL_TOOLBAR, &x, &y); icon_directory = gtk_icon_theme_load_icon (icon_theme, "gnome-fs-directory", x, 0, NULL); icon_file = gtk_icon_theme_load_icon (icon_theme, "gnome-fs-regular", x, 0, NULL); show_hidden = xfburn_settings_get_boolean ("show-hidden-files", FALSE); while ((dir_entry = g_dir_read_name (dir))) { gchar *full_path; struct stat s; if (dir_entry[0] == '.') { /* skip . and .. */ if (dir_entry[1] == '\0' || (dir_entry[1] == '.' && dir_entry[2] == '\0')) continue; if (!show_hidden) continue; } full_path = g_build_filename (path, dir_entry, NULL); #if 0 if (g_file_test (full_path, G_FILE_TEST_IS_SYMLINK)) { g_free (full_path); continue; } #endif if (stat (full_path, &s) == 0) { gchar *humansize; gchar *path_utf8; GError *conv_error = NULL; /* from the g_dir_read_name () docs: most of the time Linux stores filenames in utf8, but older versions might not, so convert here */ path_utf8 = g_filename_to_utf8 (full_path, -1, NULL, NULL, &conv_error); if (!path_utf8 || conv_error) { g_warning ("Failed to convert filename '%s' to utf8: %s. Falling back to native encoding.", full_path, conv_error->message); path_utf8 = g_strdup (full_path); if (conv_error) g_error_free (conv_error); } humansize = xfburn_humanreadable_filesize (s.st_size); if ((s.st_mode & S_IFDIR)) { GtkTreeIter iter; gtk_list_store_append (GTK_LIST_STORE (model), &iter); gtk_list_store_set (GTK_LIST_STORE (model), &iter, DIRECTORY_BROWSER_COLUMN_ICON, icon_directory, DIRECTORY_BROWSER_COLUMN_FILE, dir_entry, DIRECTORY_BROWSER_COLUMN_HUMANSIZE, humansize, DIRECTORY_BROWSER_COLUMN_SIZE, (guint64) s.st_size, DIRECTORY_BROWSER_COLUMN_TYPE, _(DIRECTORY), DIRECTORY_BROWSER_COLUMN_PATH, path_utf8, -1); } else if ((s.st_mode & S_IFREG)) { GtkTreeIter iter; GFileInfo *mime_info = NULL; GIcon *mime_icon = NULL; GdkPixbuf *mime_icon_pixbuf = NULL; const gchar *mime_str = NULL; GFile *file = NULL; const gchar *content_type = NULL; gtk_list_store_append (GTK_LIST_STORE (model), &iter); file = g_file_new_for_path(path_utf8); mime_info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, G_FILE_QUERY_INFO_NONE, NULL, NULL); content_type = g_file_info_get_content_type (mime_info); mime_str = g_content_type_get_description (content_type); mime_icon = g_content_type_get_icon (content_type); if (mime_icon != NULL) { GtkIconInfo *icon_info = gtk_icon_theme_lookup_by_gicon (icon_theme, mime_icon, x, GTK_ICON_LOOKUP_USE_BUILTIN); if (icon_info != NULL) { mime_icon_pixbuf = gtk_icon_info_load_icon (icon_info, NULL); gtk_icon_info_free (icon_info); } g_object_unref (mime_icon); } gtk_list_store_set (GTK_LIST_STORE (model), &iter, DIRECTORY_BROWSER_COLUMN_ICON, (G_IS_OBJECT (mime_icon_pixbuf) ? mime_icon_pixbuf : icon_file), DIRECTORY_BROWSER_COLUMN_FILE, dir_entry, DIRECTORY_BROWSER_COLUMN_HUMANSIZE, humansize, DIRECTORY_BROWSER_COLUMN_SIZE, (guint64) s.st_size, DIRECTORY_BROWSER_COLUMN_TYPE, mime_str, DIRECTORY_BROWSER_COLUMN_PATH, path_utf8, -1); g_object_unref(file); } g_free (humansize); g_free (path_utf8); } g_free (full_path); } if (icon_directory) g_object_unref (icon_directory); if (icon_file) g_object_unref (icon_file); g_dir_close (dir); }
static gboolean video_area_draw_cb (GtkWidget *widget, cairo_t *cr, gpointer user_data) { GthMediaViewerPage *self = user_data; GtkAllocation allocation; GtkStyleContext *style_context; if (self->priv->xwin_assigned && self->priv->has_video) return FALSE; gtk_widget_get_allocation (widget, &allocation); style_context = gtk_widget_get_style_context (widget); if (self->priv->icon == NULL) { char *type; GIcon *icon; int size; type = NULL; if (self->priv->file_data != NULL) type = g_content_type_from_mime_type (gth_file_data_get_mime_type (self->priv->file_data)); if (type == NULL) type = g_content_type_from_mime_type ("text/plain"); icon = g_content_type_get_icon (type); size = allocation.width; if (size > allocation.height) size = allocation.height; size = size / 3; self->priv->icon = _g_icon_get_pixbuf (icon, size, _gtk_widget_get_icon_theme (widget)); g_object_unref (icon); g_free (type); } cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); cairo_rectangle (cr, 0, 0, allocation.width, allocation.height); cairo_fill (cr); if (self->priv->icon != NULL) { int icon_w, icon_h; int text_w; int icon_x, icon_y; PangoRectangle logical_rect; int x, y; PangoFontDescription *font; icon_w = gdk_pixbuf_get_width (self->priv->icon); icon_h = gdk_pixbuf_get_height (self->priv->icon); text_w = (icon_w * 3 / 2); pango_layout_set_width (self->priv->caption_layout, PANGO_SCALE * text_w); pango_layout_get_extents (self->priv->caption_layout, NULL, &logical_rect); icon_x = (allocation.width - icon_w) / 2; x = (allocation.width - text_w) / 2; icon_y = (allocation.height - (icon_h + PANGO_PIXELS (logical_rect.height))) / 2; y = icon_y + icon_h; gdk_cairo_set_source_pixbuf (cr, self->priv->icon, icon_x, icon_y); cairo_rectangle (cr, icon_x, icon_y, icon_w, icon_h); cairo_fill (cr); cairo_move_to (cr, x, y); gtk_style_context_get (style_context, gtk_widget_get_state_flags (widget), "font", &font, NULL); pango_layout_set_font_description (self->priv->caption_layout, font); pango_cairo_layout_path (cr, self->priv->caption_layout); cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); cairo_fill (cr); } return TRUE; }
gint main (gint argc, gchar **argv) { GtkWidget *window, *toolbar, *grid, *treeview, *scrolled_window; GtkWidget *hbox, *hbox1, *hbox2, *checkbox, *option_menu, *menu; gint i; static const gchar *toolbar_styles[] = { "icons", "text", "both (vertical)", "both (horizontal)" }; GtkToolItem *item; GtkListStore *store; GtkWidget *image; GtkWidget *menuitem; GtkWidget *button; GtkWidget *label; GIcon *gicon; GSList *group; gtk_init (&argc, &argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); g_signal_connect (window, "destroy", G_CALLBACK(gtk_main_quit), NULL); grid = gtk_grid_new (); gtk_container_add (GTK_CONTAINER (window), grid); toolbar = gtk_toolbar_new (); gtk_widget_set_vexpand (toolbar, TRUE); gtk_grid_attach (GTK_GRID (grid), toolbar, 0, 0, 2, 1); hbox1 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3); gtk_container_set_border_width (GTK_CONTAINER (hbox1), 5); gtk_widget_set_vexpand (hbox1, TRUE); gtk_grid_attach (GTK_GRID (grid), hbox1, 1, 1, 1, 1); hbox2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2); gtk_container_set_border_width (GTK_CONTAINER (hbox2), 5); gtk_widget_set_vexpand (hbox2, TRUE); gtk_grid_attach (GTK_GRID (grid), hbox2, 1, 2, 1, 1); checkbox = gtk_check_button_new_with_mnemonic("_Vertical"); gtk_box_pack_start (GTK_BOX (hbox1), checkbox, FALSE, FALSE, 0); g_signal_connect (checkbox, "toggled", G_CALLBACK (change_orientation), toolbar); checkbox = gtk_check_button_new_with_mnemonic("_Show Arrow"); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbox), TRUE); gtk_box_pack_start (GTK_BOX (hbox1), checkbox, FALSE, FALSE, 0); g_signal_connect (checkbox, "toggled", G_CALLBACK (change_show_arrow), toolbar); checkbox = gtk_check_button_new_with_mnemonic("_Set Toolbar Style:"); g_signal_connect (checkbox, "toggled", G_CALLBACK (set_toolbar_style_toggled), toolbar); gtk_box_pack_start (GTK_BOX (hbox1), checkbox, FALSE, FALSE, 0); option_menu = gtk_combo_box_text_new (); gtk_widget_set_sensitive (option_menu, FALSE); g_object_set_data (G_OBJECT (checkbox), "option-menu", option_menu); for (i = 0; i < G_N_ELEMENTS (toolbar_styles); i++) gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (option_menu), toolbar_styles[i]); gtk_combo_box_set_active (GTK_COMBO_BOX (option_menu), gtk_toolbar_get_style (GTK_TOOLBAR (toolbar))); gtk_box_pack_start (GTK_BOX (hbox2), option_menu, FALSE, FALSE, 0); g_signal_connect (option_menu, "changed", G_CALLBACK (change_toolbar_style), toolbar); checkbox = gtk_check_button_new_with_mnemonic("_Set Icon Size:"); g_signal_connect (checkbox, "toggled", G_CALLBACK (set_icon_size_toggled), toolbar); gtk_box_pack_start (GTK_BOX (hbox2), checkbox, FALSE, FALSE, 0); option_menu = gtk_combo_box_text_new (); g_object_set_data (G_OBJECT (checkbox), "option-menu", option_menu); gtk_widget_set_sensitive (option_menu, FALSE); gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (option_menu), "small toolbar"); gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (option_menu), "large toolbar"); gtk_box_pack_start (GTK_BOX (hbox2), option_menu, FALSE, FALSE, 0); g_signal_connect (option_menu, "changed", G_CALLBACK (icon_size_history_changed), toolbar); scrolled_window = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_widget_set_hexpand (scrolled_window, TRUE); gtk_widget_set_vexpand (scrolled_window, TRUE); gtk_grid_attach (GTK_GRID (grid), scrolled_window, 1, 3, 1, 1); store = create_items_list (&treeview); gtk_container_add (GTK_CONTAINER (scrolled_window), treeview); item = gtk_tool_button_new (NULL, NULL); gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), "document-new"); gtk_tool_button_set_label (GTK_TOOL_BUTTON (item), "Custom label"); add_item_to_list (store, item, "New"); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); gdk_threads_add_timeout (3000, (GSourceFunc) timeout_cb, item); gtk_tool_item_set_expand (item, TRUE); menu = gtk_menu_new (); for (i = 0; i < 20; i++) { char *text; text = g_strdup_printf ("Menuitem %d", i); menuitem = gtk_menu_item_new_with_label (text); g_free (text); gtk_widget_show (menuitem); gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); } item = gtk_menu_tool_button_new (NULL, NULL); gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), "document-open"); gtk_tool_button_set_label (GTK_TOOL_BUTTON (item), "Open"); gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (item), menu); add_item_to_list (store, item, "Open"); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); gdk_threads_add_timeout (3000, (GSourceFunc) timeout_cb1, item); menu = gtk_menu_new (); for (i = 0; i < 20; i++) { char *text; text = g_strdup_printf ("A%d", i); menuitem = gtk_menu_item_new_with_label (text); g_free (text); gtk_widget_show (menuitem); gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); } item = gtk_menu_tool_button_new (NULL, NULL); gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), "go-previous"); gtk_tool_button_set_label (GTK_TOOL_BUTTON (item), "Back"); gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (item), menu); add_item_to_list (store, item, "BackWithHistory"); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); item = gtk_separator_tool_item_new (); add_item_to_list (store, item, "-----"); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); image = gtk_image_new_from_icon_name ("dialog-warning", GTK_ICON_SIZE_DIALOG); item = gtk_tool_item_new (); gtk_widget_show (image); gtk_container_add (GTK_CONTAINER (item), image); add_item_to_list (store, item, "(Custom Item)"); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); item = gtk_tool_button_new (NULL, NULL); gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), "go-previous"); gtk_tool_button_set_label (GTK_TOOL_BUTTON (item), "Back"); add_item_to_list (store, item, "Back"); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); item = gtk_separator_tool_item_new (); add_item_to_list (store, item, "-----"); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); item = gtk_tool_button_new (NULL, NULL); gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), "go-next"); gtk_tool_button_set_label (GTK_TOOL_BUTTON (item), "Forward"); add_item_to_list (store, item, "Forward"); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); item = gtk_toggle_tool_button_new (); gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), "format-text-bold"); g_signal_connect (item, "toggled", G_CALLBACK (bold_toggled), NULL); add_item_to_list (store, item, "Bold"); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); gtk_widget_set_sensitive (GTK_WIDGET (item), FALSE); item = gtk_separator_tool_item_new (); add_item_to_list (store, item, "-----"); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); gtk_tool_item_set_expand (item, TRUE); gtk_separator_tool_item_set_draw (GTK_SEPARATOR_TOOL_ITEM (item), FALSE); g_assert (gtk_toolbar_get_nth_item (GTK_TOOLBAR (toolbar), 0) != 0); item = gtk_radio_tool_button_new (NULL); gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), "format-justify-left"); group = gtk_radio_tool_button_get_group (GTK_RADIO_TOOL_BUTTON (item)); add_item_to_list (store, item, "Left"); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); item = gtk_radio_tool_button_new (group); gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), "format-justify-center"); make_prop_editor (G_OBJECT (item)); group = gtk_radio_tool_button_get_group (GTK_RADIO_TOOL_BUTTON (item)); add_item_to_list (store, item, "Center"); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); item = gtk_radio_tool_button_new (group); gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), "format-justify-right"); add_item_to_list (store, item, "Right"); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); item = gtk_tool_button_new (gtk_image_new_from_file ("apple-red.png"), "_Apple"); add_item_to_list (store, item, "Apple"); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); gtk_tool_button_set_use_underline (GTK_TOOL_BUTTON (item), TRUE); gicon = g_content_type_get_icon ("video/ogg"); image = gtk_image_new_from_gicon (gicon, GTK_ICON_SIZE_LARGE_TOOLBAR); g_object_unref (gicon); item = gtk_tool_button_new (image, "Video"); add_item_to_list (store, item, "Video"); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); image = gtk_image_new_from_icon_name ("utilities-terminal", GTK_ICON_SIZE_LARGE_TOOLBAR); item = gtk_tool_button_new (image, "Terminal"); add_item_to_list (store, item, "Terminal"); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); image = gtk_spinner_new (); gtk_spinner_start (GTK_SPINNER (image)); item = gtk_tool_button_new (image, "Spinner"); add_item_to_list (store, item, "Spinner"); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5); gtk_container_set_border_width (GTK_CONTAINER (hbox), 5); gtk_widget_set_hexpand (hbox, TRUE); gtk_grid_attach (GTK_GRID (grid), hbox, 1, 4, 1, 1); button = gtk_button_new_with_label ("Drag me to the toolbar"); gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0); label = gtk_label_new ("Drop index:"); gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); label = gtk_label_new (""); gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); checkbox = gtk_check_button_new_with_mnemonic("_Right to left"); if (gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbox), TRUE); else gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbox), FALSE); g_signal_connect (checkbox, "toggled", G_CALLBACK (rtl_toggled), NULL); gtk_box_pack_end (GTK_BOX (hbox), checkbox, FALSE, FALSE, 0); gtk_drag_source_set (button, GDK_BUTTON1_MASK, target_table, G_N_ELEMENTS (target_table), GDK_ACTION_MOVE); gtk_drag_dest_set (toolbar, GTK_DEST_DEFAULT_DROP, target_table, G_N_ELEMENTS (target_table), GDK_ACTION_MOVE); g_signal_connect (toolbar, "drag_motion", G_CALLBACK (toolbar_drag_motion), NULL); g_signal_connect (toolbar, "drag_leave", G_CALLBACK (toolbar_drag_leave), NULL); g_signal_connect (toolbar, "drag_drop", G_CALLBACK (toolbar_drag_drop), label); gtk_widget_show_all (window); make_prop_editor (G_OBJECT (toolbar)); g_signal_connect (window, "delete_event", G_CALLBACK (gtk_main_quit), NULL); g_signal_connect (toolbar, "popup_context_menu", G_CALLBACK (popup_context_menu), NULL); gtk_main (); return 0; }
/* Function implementations */ static void fl_parser_start_node_cb (void *user_data, const char *node_name, const char **attr) { ParserData *data; GFileInfo *info; data = (ParserData *) user_data; data->depth++; d(g_print ("%d: %s\n", data->depth, node_name)); if (data->depth > 2) { g_set_error (data->error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, "Don't expect node '%s' as child of 'file', 'folder' or 'parent-folder'", node_name); return; } else if (data->depth == 1) { if (strcmp (node_name, "folder-listing") != 0) { g_set_error (data->error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, "Expected 'folder-listing', got '%s'", node_name); return; } return; } if (strcmp (node_name, "parent-folder") == 0) { /* Just ignore parent-folder items */ return; } info = g_file_info_new (); if (strcmp (node_name, "file") == 0) { g_file_info_set_file_type (info, G_FILE_TYPE_REGULAR); } else if (strcmp (node_name, "folder") == 0) { GIcon *icon; g_file_info_set_file_type (info, G_FILE_TYPE_DIRECTORY); g_file_info_set_content_type (info, "inode/directory"); icon = g_themed_icon_new ("folder"); g_file_info_set_icon (info, icon); g_object_unref (icon); icon = g_themed_icon_new ("folder-symbolic"); g_file_info_set_symbolic_icon (info, icon); g_object_unref (icon); } else { g_set_error (data->error, G_MARKUP_ERROR, G_MARKUP_ERROR_UNKNOWN_ELEMENT, "Unknown element '%s'", node_name); return; } if (!fl_parser_fill_file_info (info, attr)) { d(g_print ("Failed to fill GnomeVFSFileInfo from node '%s'\n", node_name)); g_object_unref (info); return; } if (g_file_info_get_content_type (info) == NULL) { char *mime_type; mime_type = g_content_type_guess (g_file_info_get_name (info), NULL, 0, NULL); g_file_info_set_content_type (info, mime_type); g_free (mime_type); } if (g_file_info_get_content_type (info) == NULL) { g_file_info_set_content_type (info, "application/octet-stream"); } if (g_file_info_get_file_type (info) == G_FILE_TYPE_REGULAR) { GIcon *icon; const char *content_type; content_type = g_file_info_get_content_type (info); icon = g_content_type_get_icon (content_type); if (icon != NULL) { if (G_IS_THEMED_ICON (icon)) g_themed_icon_append_name (G_THEMED_ICON (icon), "text-x-generic"); g_file_info_set_icon (info, icon); g_object_unref (icon); } icon = g_content_type_get_symbolic_icon (content_type); if (icon != NULL) { if (G_IS_THEMED_ICON (icon)) g_themed_icon_append_name (G_THEMED_ICON (icon), "text-x-generic-symbolic"); g_file_info_set_symbolic_icon (info, icon); g_object_unref (icon); } } /* Permissions on folders in OBEX has different semantics than POSIX. * In POSIX, if a folder is not writable, it means that it's content * can't be removed, whereas in OBEX, it just means that the folder * itself can't be removed. Therefore we must set all folders to RWD and * handle the error when it happens. */ if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) { g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ, TRUE); g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE, TRUE); } data->elements = g_list_prepend (data->elements, info); }
static void nautilus_file_management_properties_dialog_setup_media_page (GladeXML *xml_dialog) { unsigned int n; GList *l; GList *content_types; GtkWidget *other_type_combo_box; GtkListStore *other_type_list_store; GtkCellRenderer *renderer; GtkTreeIter iter; const char *s[] = {"media_audio_cdda_combobox", "x-content/audio-cdda", "media_video_dvd_combobox", "x-content/video-dvd", "media_music_player_combobox", "x-content/audio-player", "media_dcf_combobox", "x-content/image-dcf", "media_software_combobox", "x-content/software", NULL}; for (n = 0; s[n*2] != NULL; n++) { nautilus_autorun_prepare_combo_box (glade_xml_get_widget (xml_dialog, s[n*2]), s[n*2 + 1], TRUE, TRUE, NULL, NULL); } other_type_combo_box = glade_xml_get_widget (xml_dialog, "media_other_type_combobox"); other_type_list_store = gtk_list_store_new (3, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING); gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (other_type_list_store), 1, GTK_SORT_ASCENDING); content_types = g_content_types_get_registered (); for (l = content_types; l != NULL; l = l->next) { char *content_type = l->data; char *description; GIcon *icon; NautilusIconInfo *icon_info; GdkPixbuf *pixbuf; int icon_size; if (!g_str_has_prefix (content_type, "x-content/")) continue; for (n = 0; s[n*2] != NULL; n++) { if (strcmp (content_type, s[n*2 + 1]) == 0) { goto skip; } } icon_size = nautilus_get_icon_size_for_stock_size (GTK_ICON_SIZE_MENU); description = g_content_type_get_description (content_type); gtk_list_store_append (other_type_list_store, &iter); icon = g_content_type_get_icon (content_type); if (icon != NULL) { icon_info = nautilus_icon_info_lookup (icon, icon_size); g_object_unref (icon); pixbuf = nautilus_icon_info_get_pixbuf_nodefault_at_size (icon_info, icon_size); g_object_unref (icon_info); } else { pixbuf = NULL; } gtk_list_store_set (other_type_list_store, &iter, 0, pixbuf, 1, description, 2, content_type, -1); if (pixbuf != NULL) g_object_unref (pixbuf); g_free (description); skip: ; } g_list_foreach (content_types, (GFunc) g_free, NULL); g_list_free (content_types); gtk_combo_box_set_model (GTK_COMBO_BOX (other_type_combo_box), GTK_TREE_MODEL (other_type_list_store)); renderer = gtk_cell_renderer_pixbuf_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (other_type_combo_box), renderer, FALSE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (other_type_combo_box), renderer, "pixbuf", 0, NULL); renderer = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (other_type_combo_box), renderer, TRUE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (other_type_combo_box), renderer, "text", 1, NULL); g_signal_connect (G_OBJECT (other_type_combo_box), "changed", G_CALLBACK (other_type_combo_box_changed), glade_xml_get_widget (xml_dialog, "media_other_action_combobox")); gtk_combo_box_set_active (GTK_COMBO_BOX (other_type_combo_box), 0); nautilus_file_management_properties_dialog_update_media_sensitivity (xml_dialog); }
static void file_info_from_message (SoupMessage *msg, GFileInfo *info, GFileAttributeMatcher *matcher) { const char *text; GHashTable *params; char *basename; char *ed_name; basename = ed_name = NULL; /* prefer the filename from the Content-Disposition (rfc2183) header if one if present. See bug 551298. */ if (soup_message_headers_get_content_disposition (msg->response_headers, NULL, ¶ms)) { const char *name = g_hash_table_lookup (params, "filename"); if (name) basename = g_strdup (name); g_hash_table_destroy (params); } if (basename == NULL) { const SoupURI *uri; uri = soup_message_get_uri (msg); basename = http_uri_get_basename (uri->path); } g_debug ("basename:%s\n", basename); /* read http/1.1 rfc, until then we copy the local files * behaviour */ if (basename != NULL && (g_file_attribute_matcher_matches (matcher, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME) || g_file_attribute_matcher_matches (matcher, G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME))) ed_name = gvfs_file_info_populate_names_as_local (info, basename); g_free (basename); g_free (ed_name); if (soup_message_headers_get_encoding (msg->response_headers) == SOUP_ENCODING_CONTENT_LENGTH) { goffset start, end, length; gboolean ret; ret = soup_message_headers_get_content_range (msg->response_headers, &start, &end, &length); if (ret && length != -1) { g_file_info_set_size (info, length); } else if (!ret) { length = soup_message_headers_get_content_length (msg->response_headers); g_file_info_set_size (info, length); } } g_file_info_set_file_type (info, G_FILE_TYPE_REGULAR); text = soup_message_headers_get_content_type (msg->response_headers, NULL); if (text) { GIcon *icon; g_file_info_set_content_type (info, text); g_file_info_set_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE, text); icon = g_content_type_get_icon (text); g_file_info_set_icon (info, icon); g_object_unref (icon); icon = g_content_type_get_symbolic_icon (text); g_file_info_set_symbolic_icon (info, icon); g_object_unref (icon); } text = soup_message_headers_get_one (msg->response_headers, "Last-Modified"); if (text) { SoupDate *sd; GTimeVal tv; sd = soup_date_new_from_string(text); if (sd) { soup_date_to_timeval (sd, &tv); g_file_info_set_modification_time (info, &tv); soup_date_free (sd); } } text = soup_message_headers_get_one (msg->response_headers, "ETag"); if (text) { g_file_info_set_attribute_string (info, G_FILE_ATTRIBUTE_ETAG_VALUE, text); } }
nsresult nsIconChannel::InitWithGIO(nsIMozIconURI *aIconURI) { GIcon *icon = NULL; nsCOMPtr<nsIURL> fileURI; // Read icon content aIconURI->GetIconURL(getter_AddRefs(fileURI)); // Get icon for file specified by URI if (fileURI) { bool isFile; nsAutoCString spec; fileURI->GetAsciiSpec(spec); if (NS_SUCCEEDED(fileURI->SchemeIs("file", &isFile)) && isFile) { GFile *file = g_file_new_for_uri(spec.get()); GFileInfo *fileInfo = g_file_query_info(file, G_FILE_ATTRIBUTE_STANDARD_ICON, G_FILE_QUERY_INFO_NONE, NULL, NULL); g_object_unref(file); if (fileInfo) { // icon from g_content_type_get_icon doesn't need unref icon = g_file_info_get_icon(fileInfo); if (icon) g_object_ref(icon); g_object_unref(fileInfo); } } } // Try to get icon by using MIME type if (!icon) { nsAutoCString type; aIconURI->GetContentType(type); // Try to get MIME type from file extension by using nsIMIMEService if (type.IsEmpty()) { nsCOMPtr<nsIMIMEService> ms(do_GetService("@mozilla.org/mime;1")); if (ms) { nsAutoCString fileExt; aIconURI->GetFileExtension(fileExt); ms->GetTypeFromExtension(fileExt, type); } } char *ctype = NULL; // character representation of content type if (!type.IsEmpty()) { ctype = g_content_type_from_mime_type(type.get()); } if (ctype) { icon = g_content_type_get_icon(ctype); g_free(ctype); } } // Get default icon theme GtkIconTheme *iconTheme = gtk_icon_theme_get_default(); GtkIconInfo *iconInfo = NULL; // Get icon size int32_t iconSize = GetIconSize(aIconURI); if (icon) { // Use icon and theme to get GtkIconInfo iconInfo = gtk_icon_theme_lookup_by_gicon(iconTheme, icon, iconSize, (GtkIconLookupFlags)0); g_object_unref(icon); } if (!iconInfo) { // Mozilla's mimetype lookup failed. Try the "unknown" icon. iconInfo = gtk_icon_theme_lookup_icon(iconTheme, "unknown", iconSize, (GtkIconLookupFlags)0); if (!iconInfo) { return NS_ERROR_NOT_AVAILABLE; } } // Create a GdkPixbuf buffer containing icon and scale it GdkPixbuf* buf = gtk_icon_info_load_icon(iconInfo, NULL); gtk_icon_info_free(iconInfo); if (!buf) { return NS_ERROR_UNEXPECTED; } nsresult rv = ScaleIconBuf(&buf, iconSize); NS_ENSURE_SUCCESS(rv, rv); rv = moz_gdk_pixbuf_to_channel(buf, aIconURI, getter_AddRefs(mRealChannel)); g_object_unref(buf); return rv; }
static void ft_manager_add_handler_to_list (EmpathyFTManager *manager, EmpathyFTHandler *handler, const GError *error) { GtkTreeRowReference *row_ref; GtkTreeIter iter; GtkTreeSelection *selection; GtkTreePath *path; GIcon *icon; const char *content_type, *second_line; char *first_line, *message; EmpathyFTManagerPriv *priv = GET_PRIV (manager); icon = NULL; /* get the icon name from the mime-type of the file. */ content_type = empathy_ft_handler_get_content_type (handler); if (content_type != NULL) icon = g_content_type_get_icon (content_type); /* append the handler in the store */ gtk_list_store_insert_with_values (GTK_LIST_STORE (priv->model), &iter, G_MAXINT, COL_FT_OBJECT, handler, COL_ICON, icon, -1); if (icon != NULL) g_object_unref (icon); /* insert the new row_ref in the hash table */ path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->model), &iter); row_ref = gtk_tree_row_reference_new (GTK_TREE_MODEL (priv->model), path); gtk_tree_path_free (path); g_hash_table_insert (priv->ft_handler_to_row_ref, g_object_ref (handler), row_ref); /* select the new row */ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview)); gtk_tree_selection_select_iter (selection, &iter); if (error != NULL) { message = ft_manager_format_error_message (handler, error); ft_manager_update_handler_message (manager, row_ref, message); g_free (message); return; } /* update the row with the initial values. * the only case where we postpone this is in case we're managing * an outgoing+hashing transfer, as the hashing started signal will * take care of updating the information. */ if (empathy_ft_handler_is_incoming (handler) || !empathy_ft_handler_get_use_hash (handler)) { first_line = ft_manager_format_contact_info (handler); second_line = _("Waiting for the other participant’s response"); message = g_strdup_printf ("%s\n%s", first_line, second_line); ft_manager_update_handler_message (manager, row_ref, message); g_free (first_line); g_free (message); } /* hook up the signals and start the transfer */ ft_manager_start_transfer (manager, handler); }
static VALUE rg_s_get_icon(G_GNUC_UNUSED VALUE type) { return GOBJ2RVAL_UNREF(g_content_type_get_icon(RVAL2CSTR(type))); }
void dlg_resize_images (GthBrowser *browser, GList *file_list) { DialogData *data; GArray *savers; GthFileData *first_file_data; GthUnit unit; int default_width_in_pixels; int default_height_in_pixels; if (gth_browser_get_dialog (browser, "resize_images") != NULL) { gtk_window_present (GTK_WINDOW (gth_browser_get_dialog (browser, "resize_images"))); return; } data = g_new0 (DialogData, 1); data->browser = browser; data->builder = _gtk_builder_new_from_file ("resize-images.ui", "resize_images"); data->settings = g_settings_new (GTHUMB_RESIZE_IMAGES_SCHEMA); data->file_list = gth_file_data_list_dup (file_list); data->use_destination = TRUE; /* Get the widgets. */ data->dialog = _gtk_builder_get_widget (data->builder, "resize_images_dialog"); gth_browser_set_dialog (browser, "resize_images", data->dialog); g_object_set_data (G_OBJECT (data->dialog), "dialog_data", data); /* Set widgets data. */ first_file_data = (GthFileData *) data->file_list->data; _gtk_file_chooser_set_file_parent (GTK_FILE_CHOOSER (GET_WIDGET ("destination_filechooserbutton")), first_file_data->file, NULL); unit = g_settings_get_enum (data->settings, PREF_RESIZE_IMAGES_UNIT); gtk_combo_box_set_active (GTK_COMBO_BOX (GET_WIDGET ("unit_combobox")), unit); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("keep_ratio_checkbutton")), g_settings_get_boolean (data->settings, PREF_RESIZE_IMAGES_KEEP_RATIO)); default_width_in_pixels = DEFAULT_WIDTH_PIXELS; default_height_in_pixels = DEFAULT_HEIGHT_PIXELS; if (data->file_list->next == NULL) { GthMetadataProvider *provider; int width; int height; provider = g_object_new (GTH_TYPE_METADATA_PROVIDER_IMAGE, NULL); gth_metadata_provider_read (provider, first_file_data, "image::width,image::height", NULL); width = g_file_info_get_attribute_int32 (first_file_data->info, "image::width"); height = g_file_info_get_attribute_int32 (first_file_data->info, "image::height"); if ((width > 0) && (height > 0)) { data->known_ratio = TRUE; data->ratio = (double) width / height; default_width_in_pixels = width; default_height_in_pixels = height; } g_object_unref (provider); } if (unit == GTH_UNIT_PERCENTAGE) { data->latest_width_in_pixel = default_width_in_pixels; data->latest_height_in_pixel = default_height_in_pixels; data->latest_width_in_percentage = g_settings_get_int (data->settings, PREF_RESIZE_IMAGES_SERIES_WIDTH); data->latest_height_in_percentage = g_settings_get_int (data->settings, PREF_RESIZE_IMAGES_SERIES_HEIGHT); gtk_spin_button_set_value (GTK_SPIN_BUTTON (GET_WIDGET ("width_spinbutton")), data->latest_width_in_percentage); gtk_spin_button_set_value (GTK_SPIN_BUTTON (GET_WIDGET ("height_spinbutton")), data->latest_height_in_percentage); } else if (unit == GTH_UNIT_PIXELS) { data->latest_width_in_percentage = DEFAULT_WIDTH_PERCENTAGE; data->latest_height_in_percentage = DEFAULT_HEIGHT_PERCENTAGE; data->latest_width_in_pixel = g_settings_get_int (data->settings, PREF_RESIZE_IMAGES_SERIES_WIDTH); data->latest_height_in_pixel = g_settings_get_int (data->settings, PREF_RESIZE_IMAGES_SERIES_HEIGHT); gtk_spin_button_set_value (GTK_SPIN_BUTTON (GET_WIDGET ("width_spinbutton")), data->latest_width_in_pixel); gtk_spin_button_set_value (GTK_SPIN_BUTTON (GET_WIDGET ("height_spinbutton")), data->latest_height_in_pixel); } savers = gth_main_get_type_set ("image-saver"); if (savers != NULL) { GtkListStore *list_store; GtkTreeIter iter; char *default_mime_type; GthIconCache *icon_cache; int i; list_store = (GtkListStore *) GET_WIDGET ("mime_type_liststore"); gtk_list_store_append (list_store, &iter); gtk_list_store_set (list_store, &iter, MIME_TYPE_COLUMN_ICON, NULL, MIME_TYPE_COLUMN_TYPE, NULL, MIME_TYPE_COLUMN_DESCRIPTION, _("Keep the original format"), -1); gtk_combo_box_set_active_iter (GTK_COMBO_BOX (GET_WIDGET ("mime_type_combobox")), &iter); default_mime_type = g_settings_get_string (data->settings, PREF_RESIZE_IMAGES_MIME_TYPE); icon_cache = gth_icon_cache_new_for_widget (data->dialog, GTK_ICON_SIZE_MENU); for (i = 0; i < savers->len; i++) { GType saver_type; GthImageSaver *saver; const char *mime_type; GdkPixbuf *pixbuf; saver_type = g_array_index (savers, GType, i); saver = g_object_new (saver_type, NULL); mime_type = gth_image_saver_get_mime_type (saver); pixbuf = gth_icon_cache_get_pixbuf (icon_cache, g_content_type_get_icon (mime_type)); gtk_list_store_append (list_store, &iter); gtk_list_store_set (list_store, &iter, MIME_TYPE_COLUMN_ICON, pixbuf, MIME_TYPE_COLUMN_TYPE, mime_type, MIME_TYPE_COLUMN_DESCRIPTION, g_content_type_get_description (mime_type), -1); if (strcmp (default_mime_type, mime_type) == 0) gtk_combo_box_set_active_iter (GTK_COMBO_BOX (GET_WIDGET ("mime_type_combobox")), &iter); g_object_unref (pixbuf); g_object_unref (saver); } gth_icon_cache_free (icon_cache); g_free (default_mime_type); } /* Set the signals handlers. */ g_signal_connect (G_OBJECT (data->dialog), "destroy", G_CALLBACK (destroy_cb), data); g_signal_connect (GET_WIDGET ("ok_button"), "clicked", G_CALLBACK (ok_clicked_cb), data); g_signal_connect (GET_WIDGET ("help_button"), "clicked", G_CALLBACK (help_clicked_cb), data); g_signal_connect_swapped (GET_WIDGET ("cancel_button"), "clicked", G_CALLBACK (gtk_widget_destroy), G_OBJECT (data->dialog)); g_signal_connect (GET_WIDGET ("unit_combobox"), "changed", G_CALLBACK (unit_combobox_changed_cb), data); g_signal_connect (GET_WIDGET ("use_destination_checkbutton"), "toggled", G_CALLBACK (use_destination_checkbutton_toggled_cb), data); data->width_spinbutton_event = g_signal_connect (GET_WIDGET ("width_spinbutton"), "value-changed", G_CALLBACK (width_spinbutton_value_changed_cb), data); data->height_spinbutton_event = g_signal_connect (GET_WIDGET ("height_spinbutton"), "value-changed", G_CALLBACK (height_spinbutton_value_changed_cb), data); /* Run dialog. */ update_width_height_properties (data); width_spinbutton_value_changed_cb (NULL, data); if (GTH_IS_FILE_SOURCE_VFS (gth_browser_get_location_source (browser))) gtk_widget_hide (GET_WIDGET ("use_destination_checkbutton")); gtk_window_set_transient_for (GTK_WINDOW (data->dialog), GTK_WINDOW (browser)); gtk_window_set_modal (GTK_WINDOW (data->dialog), FALSE); gtk_widget_show (data->dialog); }