[balsa/popover: 3/30] pref-manager: Use GtkPopover for "Add" options



commit bccdcaac68ffb6d7de1f798de1fa7218b3fb7ebe
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Mon Oct 7 15:00:19 2019 -0400

    pref-manager: Use GtkPopover for "Add" options
    
    Use GtkPopover for the "Add" button options for Remote mailbox
    servers and Address books, for the type of server or address
    book, respectively.
    
    * src/address-book-config.c (add_vcard_cb), (add_externq_cb),
      (add_ldif_cb), (add_ldap_cb), (add_gpe_cb), (add_rubrica_cb),
      (add_osmo_cb), (balsa_address_book_add_menu): create a
      GMenuModel instead of a GtkMenu;
    * src/address-book-config.h: corresponding API;
    * src/pref-manager.c (add_menu_cb), (pop3_add_cb), (imap_add_cb):
      make them GAction callbacks;
      (server_add_menu_model): create a GMenuModel instead of a GtkMenu;
      (pm_grid_add_address_books_group): use the GMenuModel to
      populate a GtkPopover;
      (pm_grid_add_remote_mailbox_servers_group): ditto.

 ChangeLog                 |  18 +++++++
 src/address-book-config.c | 124 ++++++++++++++++++++++++++++------------------
 src/address-book-config.h |   4 +-
 src/pref-manager.c        |  92 +++++++++++++++++++++-------------
 4 files changed, 154 insertions(+), 84 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index f2db91999..837d1c655 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1244,6 +1244,24 @@
        (lbh_get_web_view): if the widget is not a WebKitWebView but is
        a GtkContainer, look at all its descendants for a WebKitWebView.
 
+2019-10-07  Peter Bloomfield  <pbloomfield bellsouth net>
+
+       Use GtkPopover for the "Add" button options for Remote mailbox
+       servers and Address books, for the type of server or address
+       book, respectively.
+
+       * src/address-book-config.c (add_vcard_cb), (add_externq_cb),
+       (add_ldif_cb), (add_ldap_cb), (add_gpe_cb), (add_rubrica_cb),
+       (add_osmo_cb), (balsa_address_book_add_menu): create a
+       GMenuModel instead of a GtkMenu;
+       * src/address-book-config.h: corresponding API;
+       * src/pref-manager.c (add_menu_cb), (pop3_add_cb),
+       (imap_add_cb): make them GAction callbacks;
+       (server_add_menu_model): create a GMenuModel instead of a GtkMenu;
+       (pm_grid_add_address_books_group): use the GMenuModel to
+       populate a GtkPopover;
+       (pm_grid_add_remote_mailbox_servers_group): ditto.
+
 2019-10-01  Peter Bloomfield  <pbloomfield bellsouth net>
 
        Build: we need -Wformat for -Wformat-security to be effective
diff --git a/src/address-book-config.c b/src/address-book-config.c
index e0c76be27..e40b3003f 100644
--- a/src/address-book-config.c
+++ b/src/address-book-config.c
@@ -855,24 +855,36 @@ modify_book(AddressBookConfig * abc)
 /* Pref manager callbacks */
 
 static void
-add_vcard_cb(GtkWidget * widget, AddressBookConfig * abc)
+add_vcard_cb(GSimpleAction *action,
+             GVariant      *parameter,
+             gpointer       user_data)
 {
+    AddressBookConfig *abc = user_data;
+
     abc->type = LIBBALSA_TYPE_ADDRESS_BOOK_VCARD;
     abc->window = create_vcard_dialog(abc);
     gtk_widget_show_all(abc->window);
 }
 
 static void
-add_externq_cb(GtkWidget * widget, AddressBookConfig * abc)
+add_externq_cb(GSimpleAction *action,
+               GVariant      *parameter,
+               gpointer       user_data)
 {
+    AddressBookConfig *abc = user_data;
+
     abc->type = LIBBALSA_TYPE_ADDRESS_BOOK_EXTERNQ;
     abc->window = create_externq_dialog(abc);
     gtk_widget_show_all(abc->window);
 }
 
 static void
-add_ldif_cb(GtkWidget * widget, AddressBookConfig * abc)
+add_ldif_cb(GSimpleAction *action,
+            GVariant      *parameter,
+            gpointer       user_data)
 {
+    AddressBookConfig *abc = user_data;
+
     abc->type = LIBBALSA_TYPE_ADDRESS_BOOK_LDIF;
     abc->window = create_ldif_dialog(abc);
     gtk_widget_show_all(abc->window);
@@ -880,8 +892,12 @@ add_ldif_cb(GtkWidget * widget, AddressBookConfig * abc)
 
 #ifdef ENABLE_LDAP
 static void
-add_ldap_cb(GtkWidget * widget, AddressBookConfig * abc)
+add_ldap_cb(GSimpleAction *action,
+            GVariant      *parameter,
+            gpointer       user_data)
 {
+    AddressBookConfig *abc = user_data;
+
     abc->type = LIBBALSA_TYPE_ADDRESS_BOOK_LDAP;
     abc->window = create_ldap_dialog(abc);
     gtk_widget_show_all(abc->window);
@@ -890,8 +906,12 @@ add_ldap_cb(GtkWidget * widget, AddressBookConfig * abc)
 
 #ifdef HAVE_SQLITE
 static void
-add_gpe_cb(GtkWidget * widget, AddressBookConfig * abc)
+add_gpe_cb(GSimpleAction *action,
+           GVariant      *parameter,
+           gpointer       user_data)
 {
+    AddressBookConfig *abc = user_data;
+
     abc->type = LIBBALSA_TYPE_ADDRESS_BOOK_GPE;
     abc->window = create_gpe_dialog(abc);
     gtk_widget_show_all(abc->window);
@@ -900,8 +920,12 @@ add_gpe_cb(GtkWidget * widget, AddressBookConfig * abc)
 
 #ifdef HAVE_RUBRICA
 static void
-add_rubrica_cb(GtkWidget * widget, AddressBookConfig * abc)
+add_rubrica_cb(GSimpleAction *action,
+               GVariant      *parameter,
+               gpointer       user_data)
 {
+    AddressBookConfig *abc = user_data;
+
     abc->type = LIBBALSA_TYPE_ADDRESS_BOOK_RUBRICA;
     abc->window = create_rubrica_dialog(abc);
     gtk_widget_show_all(abc->window);
@@ -910,72 +934,78 @@ add_rubrica_cb(GtkWidget * widget, AddressBookConfig * abc)
 
 #ifdef HAVE_OSMO
 static void
-add_osmo_cb(GtkWidget * widget, AddressBookConfig * abc)
+add_osmo_cb(GSimpleAction *action,
+            GVariant      *parameter,
+            gpointer       user_data)
 {
+    AddressBookConfig *abc = user_data;
+
     abc->type = LIBBALSA_TYPE_ADDRESS_BOOK_OSMO;
     abc->window = create_osmo_dialog(abc);
     gtk_widget_show_all(abc->window);
 }
 #endif /* HAVE_OSMO */
 
-GtkWidget *
+GMenuModel *
 balsa_address_book_add_menu(BalsaAddressBookCallback callback,
-                            GtkWindow * parent)
+                            GtkWindow               *parent)
 {
-    GtkWidget *menu;
-    GtkWidget *menuitem;
     AddressBookConfig *abc;
+    GSimpleActionGroup *simple;
+    GMenu *menu;
+    static const GActionEntry address_book_entries[] = {
+        {"add-vcard", add_vcard_cb},
+        {"add-externq", add_externq_cb},
+        {"add-ldif", add_ldif_cb},
+#ifdef ENABLE_LDAP
+        {"add-ldap", add_ldap_cb},
+#endif /* ENABLE_LDAP */
+#ifdef HAVE_SQLITE
+        {"add-gpe", add_gpe_cb},
+#endif /* HAVE_SQLITE */
+#ifdef HAVE_RUBRICA
+        {"add-rubrica", add_rubrica_cb},
+#endif /* HAVE_RUBRICA */
+#ifdef HAVE_OSMO
+        {"add-osmo", add_osmo_cb},
+#endif /* HAVE_OSMO */
+    };
 
-    menu = gtk_menu_new();
     abc = g_new0(AddressBookConfig, 1);
     abc->callback = callback;
     abc->parent = parent;
-    g_object_weak_ref(G_OBJECT(menu), (GWeakNotify) g_free, abc);
-
-    menuitem =
-        gtk_menu_item_new_with_label(_("vCard Address Book (GnomeCard)"));
-    g_signal_connect(menuitem, "activate",
-                     G_CALLBACK(add_vcard_cb), abc);
-    gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
-
-    menuitem =
-        gtk_menu_item_new_with_label(_("External query (a program)"));
-    g_signal_connect(menuitem, "activate",
-                     G_CALLBACK(add_externq_cb), abc);
-    gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
-
-    menuitem = gtk_menu_item_new_with_label(_("LDIF Address Book"));
-    g_signal_connect(menuitem, "activate",
-                     G_CALLBACK(add_ldif_cb), abc);
-    gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
+    g_object_weak_ref(G_OBJECT(parent), (GWeakNotify) g_free, abc);
+
+    simple = g_simple_action_group_new();
+    g_action_map_add_action_entries(G_ACTION_MAP(simple),
+                                    address_book_entries,
+                                    G_N_ELEMENTS(address_book_entries),
+                                    abc);
+    gtk_widget_insert_action_group(GTK_WIDGET(parent),
+                                   "address-book",
+                                   G_ACTION_GROUP(simple));
+    g_object_unref(simple);
+
+    menu = g_menu_new();
+    g_menu_append(menu, _("vCard Address Book (GnomeCard)"), "address-book.add-vcard");
+    g_menu_append(menu, _("External query (a program)"), "address-book.add-externq");
+    g_menu_append(menu, _("LDIF Address Book"), "address-book.add-ldif");
 
 #ifdef ENABLE_LDAP
-    menuitem = gtk_menu_item_new_with_label(_("LDAP Address Book"));
-    g_signal_connect(menuitem, "activate",
-                     G_CALLBACK(add_ldap_cb), abc);
-    gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
+    g_menu_append(menu, _("LDAP Address Book"), "address-book.add-ldap");
 #endif /* ENABLE_LDAP */
 
 #ifdef HAVE_SQLITE
-    menuitem = gtk_menu_item_new_with_label(_("GPE Address Book"));
-    g_signal_connect(menuitem, "activate",
-                     G_CALLBACK(add_gpe_cb), abc);
-    gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
+    g_menu_append(menu, _("GPE Address Book"), "address-book.add-gpe");
 #endif /* HAVE_SQLITE */
 
 #ifdef HAVE_RUBRICA
-    menuitem = gtk_menu_item_new_with_label(_("Rubrica2 Address Book"));
-    g_signal_connect(menuitem, "activate",
-                     G_CALLBACK(add_rubrica_cb), abc);
-    gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
+    g_menu_append(menu, _("Rubrica2 Address Book"), "address-book.add-rubrica");
 #endif /* HAVE_RUBRICA */
 
 #ifdef HAVE_OSMO
-    menuitem = gtk_menu_item_new_with_label(_("Osmo Address Book"));
-    g_signal_connect(menuitem, "activate",
-                     G_CALLBACK(add_osmo_cb), abc);
-    gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
+    g_menu_append(menu, _("Osmo Address Book"), "address-book.add-osmo");
 #endif
 
-    return menu;
+    return G_MENU_MODEL(menu);
 }
diff --git a/src/address-book-config.h b/src/address-book-config.h
index 97e7cee5f..0ea3fa4e7 100644
--- a/src/address-book-config.h
+++ b/src/address-book-config.h
@@ -29,7 +29,7 @@ void balsa_address_book_config_new(LibBalsaAddressBook * address_book,
 void balsa_address_book_config_new_from_type(GType type,
                                              BalsaAddressBookCallback
                                              callback, GtkWindow * parent);
-GtkWidget *balsa_address_book_add_menu(BalsaAddressBookCallback callback,
-                                       GtkWindow * parent);
+GMenuModel *balsa_address_book_add_menu(BalsaAddressBookCallback callback,
+                                        GtkWindow * parent);
 
 #endif                         /* __ADDRESS_BOOK_CONFIG_H__ */
diff --git a/src/pref-manager.c b/src/pref-manager.c
index 3ba341aaf..493ea59bf 100644
--- a/src/pref-manager.c
+++ b/src/pref-manager.c
@@ -1643,10 +1643,7 @@ address_book_set_default_cb(GtkTreeView * tree_view)
 static void
 add_menu_cb(GtkWidget * menu, GtkWidget * widget)
 {
-    gtk_widget_show_all(menu);
-    gtk_menu_popup_at_widget(GTK_MENU(menu), GTK_WIDGET(widget),
-                             GDK_GRAVITY_NORTH_WEST, GDK_GRAVITY_NORTH_WEST,
-                             NULL);
+    gtk_popover_popup(GTK_POPOVER(menu));
 }
 
 static void
@@ -1677,28 +1674,46 @@ address_book_delete_cb(GtkTreeView * tree_view)
 }
 
 static void
-pop3_add_cb(void)
+pop3_add_cb(GSimpleAction *action,
+            GVariant      *parameter,
+            gpointer       user_data)
 {
     mailbox_conf_new(LIBBALSA_TYPE_MAILBOX_POP3);
 }
 
-static GtkWidget *
-server_add_menu_widget(void)
+static void
+imap_add_cb(GSimpleAction *action,
+            GVariant      *parameter,
+            gpointer       user_data)
 {
-    GtkWidget *menu;
-    GtkWidget *menuitem;
+    folder_conf_add_imap_cb(NULL, NULL);
+}
 
-    menu = gtk_menu_new();
-    menuitem = gtk_menu_item_new_with_label(_("Remote POP3 mailbox…"));
-    g_signal_connect(menuitem, "activate",
-                     G_CALLBACK(pop3_add_cb), NULL);
-    gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
-    menuitem = gtk_menu_item_new_with_label(_("Remote IMAP folder…"));
-    g_signal_connect(menuitem, "activate",
-                    G_CALLBACK(folder_conf_add_imap_cb), NULL);
-    gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
+static GMenuModel *
+server_add_menu_model(GtkWidget *parent)
+{
+    GSimpleActionGroup *simple;
+    GMenu *menu;
+    static const GActionEntry pref_manager_entries[] = {
+        {"add-pop3", pop3_add_cb},
+        {"add-imap", imap_add_cb}
+    };
 
-    return menu;
+    simple = g_simple_action_group_new();
+    g_action_map_add_action_entries(G_ACTION_MAP(simple),
+                                    pref_manager_entries,
+                                    G_N_ELEMENTS(pref_manager_entries),
+                                    NULL);
+    gtk_widget_insert_action_group(GTK_WIDGET(parent),
+                                   "pref-manager",
+                                   G_ACTION_GROUP(simple));
+    g_object_unref(simple);
+
+    menu = g_menu_new();
+    g_menu_append(menu, _("Remote POP3 mailbox…"), "pref-manager.add-pop3");
+    g_menu_append(menu, _("Remote IMAP folder…"), "pref-manager.add-imap");
+
+    return G_MENU_MODEL(menu);
 }
 
 static void
@@ -1952,7 +1967,9 @@ pm_grid_add_remote_mailbox_servers_group(GtkWidget * grid_widget)
     GtkListStore *store;
     GtkCellRenderer *renderer;
     GtkTreeViewColumn *column;
+    GMenuModel *menu_model;
     GtkWidget *server_add_menu;
+    GtkWidget *button;
 
     pm_grid_attach(grid, pm_group_label(_("Remote mailbox servers")), 0, row, 3, 1);
 
@@ -1994,12 +2011,14 @@ pm_grid_add_remote_mailbox_servers_group(GtkWidget * grid_widget)
 
     vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, ROW_SPACING);
 
-    server_add_menu = server_add_menu_widget();
+    menu_model = server_add_menu_model(vbox);
+    server_add_menu = gtk_popover_new_from_model(NULL, menu_model);
     g_object_weak_ref(G_OBJECT(vbox), (GWeakNotify) g_object_unref,
-                      server_add_menu);
-    g_object_ref_sink(server_add_menu);
-    add_button_to_box(_("_Add"), G_CALLBACK(add_menu_cb),
-                      server_add_menu, vbox);
+                      menu_model);
+
+    button = add_button_to_box(_("_Add"), G_CALLBACK(add_menu_cb),
+                               server_add_menu, vbox);
+    gtk_popover_set_relative_to(GTK_POPOVER(server_add_menu), button);
 
     add_button_to_box(_("_Modify"), G_CALLBACK(server_edit_cb),
                       tree_view, vbox);
@@ -2699,8 +2718,10 @@ pm_grid_add_address_books_group(GtkWidget * grid_widget)
     GtkCellRenderer *renderer;
     GtkTreeViewColumn *column;
     GtkWidget *scrolledwindow;
+    GMenuModel *menu_model;
     GtkWidget *address_book_add_menu;
     GtkWidget *vbox;
+    GtkWidget *button;
 
     pm_grid_attach(grid, pm_group_label(_("Address books")), 0, row, 3, 1);
 
@@ -2748,22 +2769,23 @@ pm_grid_add_address_books_group(GtkWidget * grid_widget)
                                 (GTK_TREE_VIEW(tree_view)),
                                 GTK_SELECTION_BROWSE);
 
-    g_signal_connect(tree_view, "row-activated", 
+    g_signal_connect(tree_view, "row-activated",
                      G_CALLBACK(address_book_edit_cb), NULL);
 
     gtk_container_add(GTK_CONTAINER(scrolledwindow), tree_view);
 
-    address_book_add_menu =
-        balsa_address_book_add_menu(address_book_change,
-                                    GTK_WINDOW(property_box));
-    g_object_weak_ref(G_OBJECT(grid), (GWeakNotify) g_object_unref,
-                      address_book_add_menu);
-    g_object_ref_sink(address_book_add_menu);
+    menu_model = balsa_address_book_add_menu(address_book_change,
+                                             GTK_WINDOW(property_box));
+    address_book_add_menu = gtk_popover_new_from_model(NULL, menu_model);
+    g_object_weak_ref(G_OBJECT(address_book_add_menu),
+                      (GWeakNotify) g_object_unref, menu_model);
 
     vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, HIG_PADDING);
-    add_button_to_box(_("_Add"),
-                      G_CALLBACK(add_menu_cb),
-                      address_book_add_menu, vbox);
+
+    button = add_button_to_box(_("_Add"),
+                               G_CALLBACK(add_menu_cb),
+                               address_book_add_menu, vbox);
+    gtk_popover_set_relative_to(GTK_POPOVER(address_book_add_menu), button);
 
     add_button_to_box(_("_Modify"),
                       G_CALLBACK(address_book_edit_cb),
@@ -2771,7 +2793,7 @@ pm_grid_add_address_books_group(GtkWidget * grid_widget)
     add_button_to_box(_("_Delete"),
                       G_CALLBACK(address_book_delete_cb),
                       tree_view, vbox);
-    add_button_to_box(_("_Set as default"), 
+    add_button_to_box(_("_Set as default"),
                       G_CALLBACK(address_book_set_default_cb),
                       tree_view, vbox);
     pm_grid_attach(grid, vbox, 2, row, 1, 1);


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