[balsa/gtk3] Use a transient parent for the filter-run-dialog



commit 7878aa73e91148ae2765bb332dc71bbf7e0bda30
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Sat Mar 14 14:22:24 2015 -0400

    Use a transient parent for the filter-run-dialog
    
        * libbalsa/filter.h: add parent window to filters_run_dialog
        API.
        * src/filter-run-dialog.c (balsa_filter_run_dialog_new): use it,
        and add a header bar.
        (available_list_selection_changed),
        (selected_list_selection_changed): callbacks for selection
        "changed" signals, so we can set the sensitivity of various
        buttons.
        (balsa_filter_run_dialog_init): connect to the signals, and save
        the buttons in BalsaFilterRunDialog.
        (filters_run_dialog): new API.
        * src/filter-run.h: new members in BalsaFilterRunDialog for the
        buttons.
        * src/mailbox-node.c (mb_filter_cb): pass the main window as the
        transient parent for the dialog.
        * src/main-window.c (select_filters_activated): ditto.

 ChangeLog               |   22 ++++++++++++
 libbalsa/filter.h       |    2 +-
 src/filter-run-dialog.c |   85 +++++++++++++++++++++++++++++++++++++++-------
 src/filter-run.h        |   10 ++++-
 src/mailbox-node.c      |    4 ++-
 src/main-window.c       |    3 +-
 6 files changed, 108 insertions(+), 18 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index a40587d..38c7a28 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,27 @@
 2015-03-14  Peter Bloomfield  <pbloomfield bellsouth net>
 
+       Use a transient parent for the BalsaFilterRunDialog, and manage
+       sensitivity of various buttons
+
+       * libbalsa/filter.h: add parent window to filters_run_dialog
+       API.
+       * src/filter-run-dialog.c (balsa_filter_run_dialog_new): use it,
+       and add a header bar.
+       (available_list_selection_changed),
+       (selected_list_selection_changed): callbacks for selection
+       "changed" signals, so we can set the sensitivity of various
+       buttons.
+       (balsa_filter_run_dialog_init): connect to the signals, and save
+       the buttons in BalsaFilterRunDialog.
+       (filters_run_dialog): new API.
+       * src/filter-run.h: new members in BalsaFilterRunDialog for the
+       buttons.
+       * src/mailbox-node.c (mb_filter_cb): pass the main window as the
+       transient parent for the dialog.
+       * src/main-window.c (select_filters_activated): ditto.
+
+2015-03-14  Peter Bloomfield  <pbloomfield bellsouth net>
+
        reviewed by: <delete if not using a buddy>
 
        * src/toolbar-prefs.c (customize_dialog_cb): use a header bar.
diff --git a/libbalsa/filter.h b/libbalsa/filter.h
index d538d62..e04260e 100644
--- a/libbalsa/filter.h
+++ b/libbalsa/filter.h
@@ -259,7 +259,7 @@ void filters_edit_dialog(void);
 
 /* filter_run_dialog edits and runs the list of filters of the mailbox
  */
-void filters_run_dialog(LibBalsaMailbox *mbox);
+void filters_run_dialog(LibBalsaMailbox *mbox, GtkWindow *parent);
 
 /* filter_export_dialog to export filters as sieve scripts
  */
diff --git a/src/filter-run-dialog.c b/src/filter-run-dialog.c
index b0068c6..2f16e24 100644
--- a/src/filter-run-dialog.c
+++ b/src/filter-run-dialog.c
@@ -176,19 +176,22 @@ balsa_filter_run_dialog_class_init(BalsaFilterRunDialogClass * klass)
     klass->refresh = fr_refresh;
 }
 
-GtkWidget *
-balsa_filter_run_dialog_new(LibBalsaMailbox * mbox)
+static GtkWidget *
+balsa_filter_run_dialog_new(LibBalsaMailbox * mbox, GtkWindow * parent)
 {
     BalsaFilterRunDialog *p;
     gchar * dialog_title;
 
     g_return_val_if_fail(mbox, NULL);
-    p = g_object_new(BALSA_TYPE_FILTER_RUN_DIALOG, NULL);
+    p = g_object_new(BALSA_TYPE_FILTER_RUN_DIALOG,
+                     "transient-for", parent,
+                     "use-header-bar", TRUE,
+                     NULL);
 
     /* We set the dialog title */
     p->mbox=mbox;
     libbalsa_mailbox_open(p->mbox, NULL); 
-    dialog_title=g_strconcat(_("Balsa Filters of Mailbox: "),
+    dialog_title=g_strconcat(_("Filters of Mailbox: "),
                              p->mbox->name,NULL);
     gtk_window_set_title(GTK_WINDOW(p),dialog_title);
     gtk_window_set_wmclass(GTK_WINDOW(p), "filter-run", "Balsa");
@@ -251,10 +254,41 @@ selected_filters_new(BalsaFilterRunDialog * p)
     return view;
 }
 
+/*
+ * Callbacks for the selection "changed" signal of the available and
+ * selected lists
+ */
+static void
+available_list_selection_changed(GtkTreeSelection * selection,
+                                 gpointer           user_data)
+{
+    BalsaFilterRunDialog *p = user_data;
+    gboolean selected;
+
+    selected = gtk_tree_selection_count_selected_rows(selection) > 0;
+    gtk_widget_set_sensitive(p->apply_selected_button, selected);
+    gtk_widget_set_sensitive(p->add_button, selected);
+}
+
+static void
+selected_list_selection_changed(GtkTreeSelection * selection,
+                                gpointer           user_data)
+{
+    BalsaFilterRunDialog *p = user_data;
+    gboolean selected;
+
+    selected = gtk_tree_selection_count_selected_rows(selection) > 0;
+    gtk_widget_set_sensitive(p->apply_now_button, selected);
+    gtk_widget_set_sensitive(p->remove_button, selected);
+    gtk_widget_set_sensitive(p->move_up_button, selected);
+    gtk_widget_set_sensitive(p->move_down_button, selected);
+}
+
 static 
 void balsa_filter_run_dialog_init(BalsaFilterRunDialog * p)
 {
     GtkWidget * bbox, * hbox,* vbox;
+    GtkTreeSelection *selection;
     GtkWidget *button;
     GtkWidget *sw;
 
@@ -299,6 +333,10 @@ void balsa_filter_run_dialog_init(BalsaFilterRunDialog * p)
     g_signal_connect(G_OBJECT(p->available_filters), "row-activated",
                      G_CALLBACK(available_list_activated), p);
 
+    selection = gtk_tree_view_get_selection(p->available_filters);
+    g_signal_connect(selection, "changed",
+                     G_CALLBACK(available_list_selection_changed), p);
+
     sw = gtk_scrolled_window_new(NULL, NULL);
     gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
                                   GTK_POLICY_AUTOMATIC,
@@ -314,7 +352,9 @@ void balsa_filter_run_dialog_init(BalsaFilterRunDialog * p)
     gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 2);
 
     /* "Apply selected" button */
-    button = gtk_button_new_with_mnemonic(_("_Apply Selected"));
+    p->apply_selected_button = button =
+        gtk_button_new_with_mnemonic(_("_Apply Selected"));
+    gtk_widget_set_sensitive(button, FALSE);
     g_signal_connect_swapped(G_OBJECT(button), "clicked",
                              G_CALLBACK(fr_apply_selected_pressed), p);
     gtk_container_add(GTK_CONTAINER(bbox), button);
@@ -325,23 +365,29 @@ void balsa_filter_run_dialog_init(BalsaFilterRunDialog * p)
     gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_SPREAD);
 
     /* Right/Add button */
-    button =
+    p->add_button = button =
         gtk_button_new_from_icon_name("go-next-symbolic",
                                       GTK_ICON_SIZE_BUTTON);
+    gtk_widget_set_tooltip_text(button,
+                                _("Add selected filter to mailbox"));
+    gtk_widget_set_sensitive(button, FALSE);
     g_signal_connect_swapped(G_OBJECT(button), "clicked",
                              G_CALLBACK(fr_add_pressed), G_OBJECT(p));
     gtk_container_add(GTK_CONTAINER(bbox), button);
     /* Left/Remove button */
-    button =
+    p->remove_button = button =
         gtk_button_new_from_icon_name("go-previous-symbolic",
                                       GTK_ICON_SIZE_BUTTON);
+    gtk_widget_set_tooltip_text(button,
+                                _("Remove selected filter from mailbox"));
+    gtk_widget_set_sensitive(button, FALSE);
     g_signal_connect_swapped(G_OBJECT(button), "clicked",
                              G_CALLBACK(fr_remove_pressed), G_OBJECT(p));
     gtk_container_add(GTK_CONTAINER(bbox), button);
 
     gtk_box_pack_start(GTK_BOX(hbox),bbox, FALSE, FALSE, 6);
 
-    vbox=gtk_box_new(GTK_ORIENTATION_VERTICAL,2);
+    vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 2);
 
     gtk_box_pack_start(GTK_BOX(hbox),vbox, TRUE, TRUE, 0);
 
@@ -354,6 +400,10 @@ void balsa_filter_run_dialog_init(BalsaFilterRunDialog * p)
     g_signal_connect(G_OBJECT(p->selected_filters), "row-activated",
                      G_CALLBACK(selected_list_activated), p);
 
+    selection = gtk_tree_view_get_selection(p->selected_filters);
+    g_signal_connect(selection, "changed",
+                     G_CALLBACK(selected_list_selection_changed), p);
+
     gtk_container_add(GTK_CONTAINER(sw), GTK_WIDGET(p->selected_filters));
 
     gtk_box_pack_start(GTK_BOX(vbox),sw, TRUE, TRUE, 0);
@@ -366,21 +416,29 @@ void balsa_filter_run_dialog_init(BalsaFilterRunDialog * p)
     gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 2);
 
     /* up button */
-    button =
+    p->move_up_button = button =
         gtk_button_new_from_icon_name("go-up-symbolic",
                                       GTK_ICON_SIZE_BUTTON);
+    gtk_widget_set_sensitive(button, FALSE);
+    gtk_widget_set_tooltip_text(button,
+                                _("Move selected filter up"));
     g_signal_connect(G_OBJECT(button), "clicked",
                     G_CALLBACK(fr_up_pressed), p);
     gtk_container_add(GTK_CONTAINER(bbox), button);
     /* down button */
-    button =
+    p->move_down_button = button =
         gtk_button_new_from_icon_name("go-down-symbolic",
                                       GTK_ICON_SIZE_BUTTON);
+    gtk_widget_set_sensitive(button, FALSE);
+    gtk_widget_set_tooltip_text(button,
+                                _("Move selected filter down"));
     g_signal_connect(G_OBJECT(button), "clicked",
                     G_CALLBACK(fr_down_pressed), p);
     gtk_container_add(GTK_CONTAINER(bbox), button);
 
-    button = gtk_button_new_with_mnemonic(_("A_pply Now!"));
+    p->apply_now_button = button =
+        gtk_button_new_with_mnemonic(_("A_pply Now!"));
+    gtk_widget_set_sensitive(button, FALSE);
     g_signal_connect_swapped(G_OBJECT(button), "clicked",
                              G_CALLBACK(fr_apply_now_pressed), G_OBJECT(p));
     gtk_container_add(GTK_CONTAINER(bbox), button);
@@ -417,7 +475,8 @@ fr_refresh(BalsaFilterRunDialog * fr_dialog,GSList * names_changing,
  */
 
 void
-filters_run_dialog(LibBalsaMailbox *mbox)
+filters_run_dialog(LibBalsaMailbox * mbox,
+                   GtkWindow       * parent)
 {
     GList * lst;
     GtkWidget * p;
@@ -440,7 +499,7 @@ filters_run_dialog(LibBalsaMailbox *mbox)
        return;
     }
 
-    p = balsa_filter_run_dialog_new(mbox);
+    p = balsa_filter_run_dialog_new(mbox, parent);
     if (!p) return;
 
     gtk_window_set_default_size(GTK_WINDOW(p),500,250);
diff --git a/src/filter-run.h b/src/filter-run.h
index b21138f..5f1a86b 100644
--- a/src/filter-run.h
+++ b/src/filter-run.h
@@ -78,6 +78,14 @@ struct _BalsaFilterRunDialog {
 
     /* Temporary list variable */
     GSList *filters;
+
+    /* Buttons */
+    GtkWidget *add_button;
+    GtkWidget *remove_button;
+    GtkWidget *move_up_button;
+    GtkWidget *move_down_button;
+    GtkWidget *apply_selected_button;
+    GtkWidget *apply_now_button;
 };
 
 struct _BalsaFilterRunDialogClass {
@@ -89,8 +97,6 @@ struct _BalsaFilterRunDialogClass {
 
 GType balsa_filter_run_dialog_get_type(void) G_GNUC_CONST;
 
-GtkWidget *balsa_filter_run_dialog_new(LibBalsaMailbox * mbox);
-
 void fr_clean_associated_mailbox_filters(GtkTreeView * filter_list);
 
 void fr_destroy_window_cb(GtkWidget * widget,gpointer throwaway);
diff --git a/src/mailbox-node.c b/src/mailbox-node.c
index e06e701..6a5554c 100644
--- a/src/mailbox-node.c
+++ b/src/mailbox-node.c
@@ -1027,7 +1027,9 @@ mb_rescan_cb(GtkWidget * widget, BalsaMailboxNode * mbnode)
 static void
 mb_filter_cb(GtkWidget * widget, BalsaMailboxNode * mbnode)
 {
-    if (mbnode->mailbox) filters_run_dialog(mbnode->mailbox);
+    if (mbnode->mailbox)
+        filters_run_dialog(mbnode->mailbox,
+                           GTK_WINDOW(balsa_app.main_window));
     else
        /* FIXME : Perhaps should we be able to apply filters on
           folders (ie recurse on all mailboxes in it), but there are
diff --git a/src/main-window.c b/src/main-window.c
index 292e277..4d5acd0 100644
--- a/src/main-window.c
+++ b/src/main-window.c
@@ -1423,7 +1423,8 @@ select_filters_activated(GSimpleAction * action,
 
     index = balsa_window_find_current_index(window);
     if (index)
-        filters_run_dialog(BALSA_INDEX(index)->mailbox_node->mailbox);
+        filters_run_dialog(BALSA_INDEX(index)->mailbox_node->mailbox,
+                           GTK_WINDOW(balsa_app.main_window));
     else
        /* FIXME : Perhaps should we be able to apply filters on folders (ie recurse on all mailboxes in it),
           but there are problems of infinite recursion (when one mailbox being filtered is also the 
destination


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]