[Xfce4-commits] <ristretto:master> Implement rudimentary support for image-editor dialog

Stephan Arts noreply at xfce.org
Fri Mar 30 20:32:08 CEST 2012


Updating branch refs/heads/master
         to ece295739705d1e6fa824062f58d6eeaa70e9dbf (commit)
       from f1bb06c3cb065c449e82b20cb75e8104d7421730 (commit)

commit ece295739705d1e6fa824062f58d6eeaa70e9dbf
Author: Stephan Arts <stephan at xfce.org>
Date:   Fri Mar 30 20:30:08 2012 +0200

    Implement rudimentary support for image-editor dialog

 src/main_window.c |   81 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 79 insertions(+), 2 deletions(-)

diff --git a/src/main_window.c b/src/main_window.c
index edef1fa..5c37477 100644
--- a/src/main_window.c
+++ b/src/main_window.c
@@ -2876,17 +2876,29 @@ cb_rstto_main_window_edit (
     const gchar *content_type = rstto_file_get_content_type (r_file);
     const gchar *editor = rstto_mime_db_lookup (window->priv->db, content_type);
     GList *files = g_list_prepend (NULL, rstto_file_get_file (r_file));
+    GList *app_infos = NULL;
+    GList *app_infos_iter = NULL;
     GDesktopAppInfo *app_info = NULL;
+    GtkCellRenderer    *renderer;
     GtkWidget *dialog = NULL;
     GtkWidget *content_area;
     GtkWidget *hbox;
     GtkWidget *vbox;
     GtkWidget *image;
     GtkWidget *label;
+    GtkWidget *check_button;
     GtkWidget *treeview;
     GtkWidget *scrolled_window;
+    GtkListStore       *list_store;
+    GtkTreeIter   iter;
+    GtkTreeSelection *selection;
     gchar *label_text = NULL;
 
+    const gchar *icon;
+    const gchar *id;
+    const gchar *name;
+    const GdkPixbuf *pixbuf;
+
     if ( editor != NULL )
     {
         app_info = g_desktop_app_info_new (editor);
@@ -2901,7 +2913,7 @@ cb_rstto_main_window_edit (
     dialog = gtk_dialog_new_with_buttons (
             _("Edit with"),
             GTK_WINDOW (window),
-            GTK_DIALOG_DESTROY_WITH_PARENT,
+            GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL,
             GTK_STOCK_CANCEL,
             GTK_RESPONSE_CANCEL,
             GTK_STOCK_OK,
@@ -2914,8 +2926,60 @@ cb_rstto_main_window_edit (
     image = gtk_image_new_from_icon_name (content_type, GTK_ICON_SIZE_DIALOG);
     label_text = g_strdup_printf (_("Open %s and other files of type %s with:"), rstto_file_get_display_name (r_file), content_type);
     label = gtk_label_new (label_text);
+    check_button = gtk_check_button_new_with_mnemonic(_("Use as _default for this kind of file"));
     scrolled_window = gtk_scrolled_window_new (NULL, NULL);
     treeview = gtk_tree_view_new ();
+    list_store = gtk_list_store_new (3, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_OBJECT);
+
+    gtk_tree_view_set_headers_visible (
+            GTK_TREE_VIEW (treeview),
+            FALSE);
+    gtk_tree_view_set_model (
+            GTK_TREE_VIEW (treeview),
+            GTK_TREE_MODEL (list_store));
+
+    renderer = gtk_cell_renderer_pixbuf_new();
+    gtk_tree_view_insert_column_with_attributes (
+        GTK_TREE_VIEW (treeview),
+        0,"", renderer, "pixbuf", 0, NULL);
+
+    renderer = gtk_cell_renderer_text_new ();
+    gtk_tree_view_insert_column_with_attributes (
+        GTK_TREE_VIEW (treeview),
+        1,"", renderer, "text", 1, NULL);
+
+    app_infos = g_app_info_get_all_for_type (content_type);
+    app_infos_iter = app_infos;
+
+    while (app_infos_iter)
+    {
+        id = g_app_info_get_id (app_infos_iter->data);
+
+        /* Do not add ristretto to the list */
+        if (strcmp (id, "ristretto.desktop"))
+        {
+            icon = g_icon_to_string (g_app_info_get_icon (app_infos_iter->data));
+
+            pixbuf = gtk_icon_theme_load_icon (
+                    gtk_icon_theme_get_default (),
+                    icon,
+                    36,
+                    GTK_ICON_LOOKUP_FORCE_SIZE,
+                    NULL);
+
+            name = g_app_info_get_display_name (app_infos_iter->data),
+
+            gtk_list_store_append (list_store, &iter);
+
+            gtk_list_store_set (list_store, &iter,
+                                0, pixbuf,
+                                1, name,
+                                2, app_infos_iter->data,
+                                -1);
+        }
+        app_infos_iter = g_list_next (app_infos_iter);
+    }
+
 
     gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
 
@@ -2926,13 +2990,26 @@ cb_rstto_main_window_edit (
 
     gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
     gtk_box_pack_start (GTK_BOX (vbox), scrolled_window, TRUE, TRUE, 0);
+    gtk_box_pack_start (GTK_BOX (vbox), check_button, FALSE, FALSE, 0);
     gtk_container_add (GTK_CONTAINER (content_area), vbox);
 
     gtk_widget_show_all (content_area);
 
     if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK)
     {
-
+        selection = gtk_tree_view_get_selection ( GTK_TREE_VIEW (treeview));
+        if (gtk_tree_selection_get_selected (selection, NULL, &iter))
+        {
+            gtk_tree_model_get (GTK_TREE_MODEL (list_store), &iter, 2, &app_info, -1);
+            if ( app_info != NULL )
+            {
+                g_app_info_launch (G_APP_INFO(app_info), files, NULL, NULL);
+                if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check_button)))
+                {
+                    rstto_mime_db_store (window->priv->db, content_type, g_app_info_get_id (G_APP_INFO(app_info)));
+                }
+            }
+        }
     }
 
     gtk_widget_destroy (dialog);


More information about the Xfce4-commits mailing list