[balsa/gtk3] Port address-book editor to GAplication et al
- From: Peter Bloomfield <peterb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [balsa/gtk3] Port address-book editor to GAplication et al
- Date: Tue, 27 Jan 2015 17:38:04 +0000 (UTC)
commit 1bbe4dee2f165a39fe195e0b93bfb0549211e349
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date: Tue Jan 27 12:32:00 2015 -0500
Port address-book editor to GAplication et al
* src/ab-main.c (bab_load_cb), (bab_set_address_book),
(address_book_change_state), (set_address_book_menu_items),
(address_book_change), (file_new_vcard_activated),
(file_new_extern_activated), (file_new_ldif_activated),
(file_new_ldap_activated), (file_new_gpe_activated),
(file_new_rubrica_activated), (file_properties_activated),
(file_delete_activated), (file_quit_activated),
(entry_new_activated), (entry_delete_activated),
(help_about_activated), (get_main_menu),
(list_selection_changed_cb), (list_row_activated_cb),
(bab_get_filter_box), (bab_window_new), (main): port to
GApplication and friends.
* ui/Makefile.am: add ab-main.ui.
ChangeLog | 16 ++
src/ab-main.c | 509 +++++++++++++++++++++++++-------------------------------
ui/Makefile.am | 3 +-
3 files changed, 246 insertions(+), 282 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index c65bda7..9ab942c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,21 @@
2015-01-27 Peter Bloomfield <pbloomfield bellsouth net>
+ * src/ab-main.c (bab_load_cb), (bab_set_address_book),
+ (address_book_change_state), (set_address_book_menu_items),
+ (address_book_change), (file_new_vcard_activated),
+ (file_new_extern_activated), (file_new_ldif_activated),
+ (file_new_ldap_activated), (file_new_gpe_activated),
+ (file_new_rubrica_activated), (file_properties_activated),
+ (file_delete_activated), (file_quit_activated),
+ (entry_new_activated), (entry_delete_activated),
+ (help_about_activated), (get_main_menu),
+ (list_selection_changed_cb), (list_row_activated_cb),
+ (bab_get_filter_box), (bab_window_new), (main): port to
+ GApplication and friends.
+ * ui/Makefile.am: add ab-main.ui.
+
+2015-01-27 Peter Bloomfield <pbloomfield bellsouth net>
+
* ui/ab-main.ui: GtkBuilder description of address-book editor
UI.
diff --git a/src/ab-main.c b/src/ab-main.c
index 9c7e0db..c046880 100644
--- a/src/ab-main.c
+++ b/src/ab-main.c
@@ -50,6 +50,7 @@
#include "address-book-rubrica.h"
#endif /* HAVE_RUBRICA */
#include "address-book-config.h"
+#include "application-helpers.h"
#include "libbalsa-conf.h"
#include "libbalsa.h"
#include <glib/gi18n.h>
@@ -61,15 +62,14 @@ struct ABMainWindow {
GtkWidget *apply_button, *remove_button, *cancel_button;
GtkWidget *edit_widget;
GtkWidget *entries[NUM_FIELDS];
- GtkRadioAction *first_radio_action;
GList *address_book_list;
gchar *default_address_book_prefix;
LibBalsaAddressBook *default_address_book;
LibBalsaAddressBook* address_book;
LibBalsaAddress *displayed_address;
- GtkActionGroup *action_group;
- GtkUIManager *ui_manager;
+
+ GMenu *file_menu;
} contacts_app;
@@ -124,14 +124,13 @@ bab_load_cb(LibBalsaAddressBook *libbalsa_ab,
LibBalsaAddress *address, GtkTreeModel *model)
{
GtkTreeIter iter;
- GList *address_list;
- g_return_if_fail ( LIBBALSA_IS_ADDRESS_BOOK(libbalsa_ab) );
+ g_return_if_fail(LIBBALSA_IS_ADDRESS_BOOK(libbalsa_ab));
- if ( address == NULL )
+ if (address == NULL)
return;
- if ( libbalsa_address_is_dist_list(libbalsa_ab, address) ) {
+ if (libbalsa_address_is_dist_list(libbalsa_ab, address)) {
gchar *address_string = libbalsa_address_to_gchar(address, -1);
gtk_list_store_prepend(GTK_LIST_STORE(model), &iter);
@@ -144,41 +143,42 @@ bab_load_cb(LibBalsaAddressBook *libbalsa_ab,
g_free(address_string);
} else {
- address_list = address->address_list;
- while ( address_list ) {
+ GList *l;
+
+ for (l = address->address_list; l; l = l->next) {
gtk_list_store_prepend(GTK_LIST_STORE(model), &iter);
/* GtkListStore refs address once for each address in
* the list, and unrefs it the same number of times when
* cleared */
gtk_list_store_set(GTK_LIST_STORE(model), &iter,
LIST_COLUMN_NAME, address->full_name,
- LIST_COLUMN_ADDRSPEC, address_list->data,
+ LIST_COLUMN_ADDRSPEC, l->data,
LIST_COLUMN_ADDRESS, address,
-1);
-
- address_list = g_list_next(address_list);
}
}
}
static gboolean
-bab_set_address_book(LibBalsaAddressBook *ab, GtkWidget* list,
- const gchar *filter)
+bab_set_address_book(LibBalsaAddressBook * ab,
+ GtkWidget * list,
+ const gchar * filter)
{
+ GtkTreeModel *model;
LibBalsaABErr ab_err;
- GtkTreeModel* model = gtk_tree_view_get_model(GTK_TREE_VIEW(list));
g_return_val_if_fail(ab, FALSE);
- contacts_app.address_book = ab;
+ contacts_app.address_book = ab;
+ model = gtk_tree_view_get_model(GTK_TREE_VIEW(list));
gtk_list_store_clear(GTK_LIST_STORE(model));
- if( (ab_err=libbalsa_address_book_load(ab, filter,
- (LibBalsaAddressBookLoadFunc)
- bab_load_cb, model))
- != LBABERR_OK) {
- printf("error loading address book from %s: %d\n",
- ab->name, ab_err);
+ if ((ab_err =
+ libbalsa_address_book_load(ab, filter,
+ (LibBalsaAddressBookLoadFunc)
+ bab_load_cb, model)) != LBABERR_OK) {
+ printf("error loading address book from %s: %d\n", ab->name,
+ ab_err);
}
return TRUE;
@@ -216,23 +216,29 @@ bab_window_set_title(LibBalsaAddressBook * address_book)
}
static void
-select_address_book_cb(GtkRadioAction * action, GtkRadioAction * current,
- gpointer data)
+address_book_change_state(GSimpleAction * action,
+ GVariant * state,
+ gpointer user_data)
{
+ const gchar *value;
+ GList *l;
LibBalsaAddressBook *address_book;
- if (action != current)
- return;
+ value = g_variant_get_string(state, NULL);
+ for (l = contacts_app.address_book_list; l; l = l->next) {
+ address_book = l->data;
+ if (strcmp(value, address_book->name) == 0)
+ break;
+ }
- address_book =
- g_list_nth_data(contacts_app.address_book_list,
- gtk_radio_action_get_current_value(action));
- if (!address_book)
+ if (!l || !(address_book = l->data))
return;
ab_clear_edit_widget();
bab_set_address_book(address_book, contacts_app.entry_list, NULL);
bab_window_set_title(address_book);
+
+ g_simple_action_set_state(action, state);
}
static void
@@ -244,47 +250,72 @@ address_changed_cb(struct ABMainWindow *aw)
/* File menu callback helpers */
-#define BAB_MERGE_ID "balsa-ab-merge-id-key"
-
static void
-add_address_book(LibBalsaAddressBook * address_book)
+set_address_book_menu_items(void)
{
- static guint pos;
- gchar *label;
- GtkRadioAction *radio_action;
- gchar *accelerator;
- guint merge_id;
-
- label = g_strdup_printf("_%d:%s", ++pos, address_book->name);
- radio_action = gtk_radio_action_new(address_book->name, label,
- NULL, NULL, pos - 1);
- g_free(label);
-
- if (contacts_app.first_radio_action) {
- GSList *group =
- gtk_radio_action_get_group(contacts_app.first_radio_action);
- gtk_radio_action_set_group(radio_action, group);
- if (address_book == contacts_app.default_address_book)
- contacts_app.first_radio_action = radio_action;
- } else
- contacts_app.first_radio_action = radio_action;
-
- g_signal_connect(G_OBJECT(radio_action), "changed",
- G_CALLBACK(select_address_book_cb), NULL);
-
- accelerator = pos <= 9 ? g_strdup_printf("<control>%d", pos) : NULL;
- gtk_action_group_add_action_with_accel(contacts_app.action_group,
- GTK_ACTION(radio_action),
- accelerator);
- g_free(accelerator);
-
- merge_id = gtk_ui_manager_new_merge_id(contacts_app.ui_manager);
- gtk_ui_manager_add_ui(contacts_app.ui_manager, merge_id,
- "/ui/MainMenu/FileMenu/",
- address_book->name, address_book->name,
- GTK_UI_MANAGER_AUTO, FALSE);
- g_object_set_data(G_OBJECT(address_book), BAB_MERGE_ID,
- GUINT_TO_POINTER(merge_id));
+ GString *string;
+ GList *l;
+ guint pos;
+ gchar *s;
+ GtkBuilder *builder;
+ static GActionEntry entry = {
+ "address-book", libbalsa_radio_activated, "s", NULL,
+ address_book_change_state
+ };
+
+ pos = g_menu_model_get_n_items(G_MENU_MODEL (contacts_app.file_menu));
+ g_menu_remove(contacts_app.file_menu, --pos);
+
+ pos = 0;
+ string = g_string_new(NULL);
+ g_string_append(string, "<interface>");
+ g_string_append(string, "<menu id='address-book-menu'>");
+ g_string_append(string, "<section>");
+ for (l = contacts_app.address_book_list; l; l = l->next) {
+ LibBalsaAddressBook *address_book = l->data;
+
+ if (!address_book)
+ continue;
+
+ g_string_append(string, "<item>");
+
+ g_string_append(string, "<attribute name='label'>");
+ g_string_append_printf(string, "_%d:%s", ++pos,
+ address_book->name);
+ g_string_append(string, "</attribute>");
+
+ g_string_append(string, "<attribute name='action'>");
+ g_string_append(string, "win.address-book");
+ g_string_append(string, "</attribute>");
+
+ g_string_append(string, "<attribute name='target'>");
+ g_string_append(string, address_book->name);
+ g_string_append(string, "</attribute>");
+
+ g_string_append(string, "<attribute name='accel'>");
+ g_string_append_printf(string, "<Primary>%d", pos);
+ g_string_append(string, "</attribute>");
+
+ g_string_append(string, "</item>");
+ }
+ g_string_append(string, "</section>");
+ g_string_append(string, "</menu>");
+ g_string_append(string, "</interface>");
+ s = g_string_free(string, FALSE);
+
+ builder = gtk_builder_new_from_string(s, -1);
+ g_free(s);
+
+ g_menu_append_section(contacts_app.file_menu, NULL,
+ G_MENU_MODEL(gtk_builder_get_object
+ (builder, "address-book-menu")));
+ g_object_unref(builder);
+
+ string = g_string_new(NULL);
+ g_string_append_printf(string, "'%s'", contacts_app.address_book->name);
+ entry.state = g_string_free(string, FALSE);
+ g_action_map_add_action_entries(G_ACTION_MAP(contacts_app.window),
+ &entry, 1, contacts_app.window);
}
static gboolean
@@ -309,7 +340,6 @@ get_unused_group(const gchar * prefix)
return g_strdup_printf("%s%d", prefix, ++max);
}
-#define BAB_RADIO_ACTION "bab-radio-action-key"
#define BAB_PREFIX_LEN 3 /* strlen("_1:") */
static void
@@ -317,29 +347,12 @@ address_book_change(LibBalsaAddressBook * address_book, gboolean append)
{
gchar *group;
- if (append) {
+ if (append)
contacts_app.address_book_list =
g_list_append(contacts_app.address_book_list, address_book);
- add_address_book(address_book);
- } else {
- GtkRadioAction *radio_action =
- g_object_get_data(G_OBJECT(address_book), BAB_RADIO_ACTION);
- gchar *label;
-
- g_object_get(G_OBJECT(radio_action), "label", &label, NULL);
- if (strlen(label) <= BAB_PREFIX_LEN
- || strcmp(label + BAB_PREFIX_LEN, address_book->name) != 0) {
- gchar *new_label;
-
- label[BAB_PREFIX_LEN] = 0;
- new_label = g_strconcat(label, address_book->name, NULL);
- g_object_set(G_OBJECT(radio_action), "label", new_label, NULL);
- g_free(new_label);
- bab_window_set_title(address_book);
- }
- g_free(label);
- }
+ set_address_book_menu_items();
+ bab_window_set_title(address_book);
group = address_book->config_prefix ?
g_strdup(address_book->config_prefix) :
@@ -351,7 +364,9 @@ address_book_change(LibBalsaAddressBook * address_book, gboolean append)
}
static void
-file_new_vcard_cb(GtkAction * action, gpointer user_data)
+file_new_vcard_activated(GSimpleAction * action,
+ GVariant * state,
+ gpointer user_data)
{
balsa_address_book_config_new_from_type
(LIBBALSA_TYPE_ADDRESS_BOOK_VCARD, address_book_change,
@@ -359,7 +374,9 @@ file_new_vcard_cb(GtkAction * action, gpointer user_data)
}
static void
-file_new_extern_cb(GtkAction * action, gpointer user_data)
+file_new_extern_activated(GSimpleAction * action,
+ GVariant * state,
+ gpointer user_data)
{
balsa_address_book_config_new_from_type
(LIBBALSA_TYPE_ADDRESS_BOOK_EXTERN, address_book_change,
@@ -367,7 +384,9 @@ file_new_extern_cb(GtkAction * action, gpointer user_data)
}
static void
-file_new_ldif_cb(GtkAction * action, gpointer user_data)
+file_new_ldif_activated(GSimpleAction * action,
+ GVariant * state,
+ gpointer user_data)
{
balsa_address_book_config_new_from_type
(LIBBALSA_TYPE_ADDRESS_BOOK_LDIF, address_book_change,
@@ -376,7 +395,9 @@ file_new_ldif_cb(GtkAction * action, gpointer user_data)
#if ENABLE_LDAP
static void
-file_new_ldap_cb(GtkAction * action, gpointer user_data)
+file_new_ldap_activated(GSimpleAction * action,
+ GVariant * state,
+ gpointer user_data)
{
balsa_address_book_config_new_from_type
(LIBBALSA_TYPE_ADDRESS_BOOK_LDAP, address_book_change,
@@ -386,7 +407,9 @@ file_new_ldap_cb(GtkAction * action, gpointer user_data)
#if HAVE_SQLITE
static void
-file_new_gpe_cb(GtkAction * action, gpointer user_data)
+file_new_gpe_activated(GSimpleAction * action,
+ GVariant * state,
+ gpointer user_data)
{
balsa_address_book_config_new_from_type
(LIBBALSA_TYPE_ADDRESS_BOOK_GPE, address_book_change,
@@ -396,7 +419,9 @@ file_new_gpe_cb(GtkAction * action, gpointer user_data)
#if HAVE_RUBRICA
static void
-file_new_rubrica_cb(GtkAction * action, gpointer user_data)
+file_new_rubrica_activated(GSimpleAction * action,
+ GVariant * state,
+ gpointer user_data)
{
balsa_address_book_config_new_from_type
(LIBBALSA_TYPE_ADDRESS_BOOK_RUBRICA, address_book_change,
@@ -405,28 +430,25 @@ file_new_rubrica_cb(GtkAction * action, gpointer user_data)
#endif /* HAVE_RUBRICA */
static void
-file_properties_cb(GtkAction * action, gpointer user_data)
+file_properties_activated(GSimpleAction * action,
+ GVariant * state,
+ gpointer user_data)
{
LibBalsaAddressBook *address_book;
- GtkAction *radio_action;
if (!(address_book = contacts_app.address_book))
return;
- radio_action = gtk_action_group_get_action(contacts_app.action_group,
- address_book->name);
- g_object_set_data(G_OBJECT(address_book), BAB_RADIO_ACTION,
- radio_action);
balsa_address_book_config_new(address_book, address_book_change,
contacts_app.window);
}
static void
-file_delete_cb(GtkAction * action, gpointer user_data)
+file_delete_activated(GSimpleAction * action,
+ GVariant * state,
+ gpointer user_data)
{
LibBalsaAddressBook *address_book;
- guint merge_id;
- GtkAction *radio_action;
GList *list;
if (!(address_book = contacts_app.address_book)
@@ -439,17 +461,6 @@ file_delete_cb(GtkAction * action, gpointer user_data)
libbalsa_conf_queue_sync();
}
- merge_id = GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(address_book),
- BAB_MERGE_ID));
- gtk_ui_manager_remove_ui(contacts_app.ui_manager, merge_id);
-
- radio_action = gtk_action_group_get_action(contacts_app.action_group,
- address_book->name);
- gtk_action_group_remove_action(contacts_app.action_group, radio_action);
- g_object_unref(radio_action);
- if (contacts_app.first_radio_action == (GtkRadioAction*) radio_action)
- contacts_app.first_radio_action = NULL;
-
/* Leave a NULL item in the address book list, to avoid changing the
* positions of the other books. */
list = g_list_find(contacts_app.address_book_list, address_book);
@@ -463,15 +474,22 @@ file_delete_cb(GtkAction * action, gpointer user_data)
if (!list)
return;
- radio_action = gtk_action_group_get_action(contacts_app.action_group,
- address_book->name);
- if (!contacts_app.first_radio_action)
- contacts_app.first_radio_action = (GtkRadioAction*) radio_action;
- gtk_action_activate(radio_action);
+ contacts_app.address_book = list->data;
+ set_address_book_menu_items();
+}
+
+static void
+file_quit_activated(GSimpleAction * action,
+ GVariant * state,
+ gpointer user_data)
+{
+ gtk_main_quit();
}
static void
-edit_new_entry_cb(GtkAction * action, gpointer user_data)
+entry_new_activated(GSimpleAction * action,
+ GVariant * state,
+ gpointer user_data)
{
GtkTreeSelection *selection;
@@ -515,7 +533,9 @@ ab_remove_address(LibBalsaAddress* address)
}
static void
-edit_delete_entry_cb(GtkAction * action, gpointer user_data)
+entry_delete_activated(GSimpleAction * action,
+ GVariant * state,
+ gpointer user_data)
{
GtkTreeView *v = GTK_TREE_VIEW(contacts_app.entry_list);
GtkTreeSelection *selection = gtk_tree_view_get_selection(v);
@@ -533,125 +553,62 @@ edit_delete_entry_cb(GtkAction * action, gpointer user_data)
}
}
-/* Normal items */
-static GtkActionEntry entries[] = {
- {"FileMenu", NULL, N_("_File")},
- {"EntryMenu", NULL, N_("_Entry")},
- {"HelpMenu", NULL, N_("_Help")},
- {"New", "document-new", N_("_New")},
- {"NewVcard", NULL, N_("VCard Address Book (GnomeCard)"), NULL, NULL,
- G_CALLBACK(file_new_vcard_cb)},
- {"NewExtern", NULL, N_("External query (a program)"), NULL, NULL,
- G_CALLBACK(file_new_extern_cb)},
- {"NewLdif", NULL, N_("LDIF Address Book"), NULL, NULL,
- G_CALLBACK(file_new_ldif_cb)},
-#if ENABLE_LDAP
- {"NewLdap", NULL, N_("LDAP Address Book"), NULL, NULL,
- G_CALLBACK(file_new_ldap_cb)},
-#endif /* ENABLE_LDAP */
-#if HAVE_SQLITE
- {"NewGpe", NULL, N_("GPE Address Book"), NULL, NULL,
- G_CALLBACK(file_new_gpe_cb)},
-#endif /* HAVE_SQLITE */
-#if HAVE_RUBRICA
- {"NewRubrica", NULL, N_("Rubrica Address Book"), NULL, NULL,
- G_CALLBACK(file_new_rubrica_cb)},
-#endif /* HAVE_RUBRICA */
- {"Properties", "document-properties", N_("_Properties"), NULL,
- N_("Edit address book properties"), G_CALLBACK(file_properties_cb)},
- {"Delete", "edit-delete", N_("_Delete"), NULL,
- N_("Delete address book"), G_CALLBACK(file_delete_cb)},
- {"Quit", "application-exit", N_("_Quit"), NULL, N_("Exit the program"),
- gtk_main_quit},
- {"NewEntry", "document-new", N_("_New Entry"), "<shift><control>N",
- N_("Add new entry"), G_CALLBACK(edit_new_entry_cb)},
- {"DeleteEntry", "edit-delete", N_("_Delete Entry"), NULL,
- N_("Delete entry"), G_CALLBACK(edit_delete_entry_cb)},
- {"About", "help-about", N_("_About"), NULL, NULL, NULL}
-};
+static void
+help_about_activated(GSimpleAction * action,
+ GVariant * state,
+ gpointer user_data)
+{
+ /* Help? */
+}
-static const char *ui_description =
-"<ui>"
-" <menubar name='MainMenu'>"
-" <menu action='FileMenu'>"
-" <menu action='New'>"
-" <menuitem action='NewVcard'/>"
-" <menuitem action='NewExtern'/>"
-" <menuitem action='NewLdif'/>"
+static void
+get_main_menu(GtkApplication * application)
+{
+ static GActionEntry win_entries[] = {
+ {"file-new-vcard", file_new_vcard_activated},
+ {"file-new-external", file_new_extern_activated},
+ {"file-new-ldif", file_new_ldif_activated},
#if ENABLE_LDAP
-" <menuitem action='NewLdap'/>"
+ {"file-new-ldap", file_new_ldap_activated},
#endif /* ENABLE_LDAP */
#if HAVE_SQLITE
-" <menuitem action='NewGpe'/>"
+ {"file-new-gpe", file_new_gpe_activated},
#endif /* HAVE_SQLITE */
#if HAVE_RUBRICA
-" <menuitem action='NewRubrica'/>"
+ {"file-new-rubrica", file_new_rubrica_activated},
#endif /* HAVE_RUBRICA */
-" </menu>"
-" <menuitem action='Properties'/>"
-" <menuitem action='Delete'/>"
-" <separator/>"
-" <menuitem action='Quit'/>"
-" <separator/>"
-" </menu>"
-" <menu action='EntryMenu'>"
-" <menuitem action='NewEntry'/>"
-" <menuitem action='DeleteEntry'/>"
-" </menu>"
-" <menu action='HelpMenu'>"
-" <menuitem action='About'/>"
-" </menu>"
-" </menubar>"
-"</ui>";
-
-static void
-get_main_menu(GtkWidget * window, GtkWidget ** menubar,
- GList * address_books)
-{
- GtkActionGroup *action_group;
- GtkUIManager *ui_manager;
- GtkAccelGroup *accel_group;
- GError *error = NULL;
- GList *ab;
-#if HAVE_MACOSX_DESKTOP
- IgeMacMenuGroup *group;
-#endif
-
- contacts_app.action_group = action_group =
- gtk_action_group_new("MenuActions");
- gtk_action_group_set_translation_domain(action_group, NULL);
- gtk_action_group_add_actions(action_group, entries,
- G_N_ELEMENTS(entries), window);
-
- contacts_app.ui_manager = ui_manager = gtk_ui_manager_new();
- gtk_ui_manager_insert_action_group(ui_manager, action_group, 0);
-
- accel_group = gtk_ui_manager_get_accel_group(ui_manager);
- gtk_window_add_accel_group(GTK_WINDOW(window), accel_group);
-
- if (!gtk_ui_manager_add_ui_from_string(ui_manager, ui_description,
- -1, &error)) {
- g_message("building menus failed: %s", error->message);
- g_error_free(error);
- return;
+ {"file-properties", file_properties_activated},
+ {"file-delete", file_delete_activated},
+ {"file-quit", file_quit_activated},
+ {"entry-new", entry_new_activated},
+ {"entry-delete", entry_delete_activated},
+ {"help-about", help_about_activated},
+ };
+ GtkBuilder *builder;
+ gchar *ui_file;
+ GError *err = NULL;
+
+ builder = gtk_builder_new();
+ ui_file = g_build_filename(BALSA_DATA_PREFIX, "ui", "ab-main.ui",
+ NULL);
+ if (gtk_builder_add_from_file(builder, ui_file, &err)) {
+ gtk_application_set_menubar(application,
+ G_MENU_MODEL(gtk_builder_get_object
+ (builder, "menubar")));
+ contacts_app.file_menu =
+ G_MENU(gtk_builder_get_object(builder, "file-menu"));
+ } else {
+ g_print("%s error: %s\n", __func__, err->message);
+ g_error_free(err);
}
+ g_free(ui_file);
+ g_object_unref(builder);
- for (ab = address_books; ab; ab = ab->next)
- add_address_book(LIBBALSA_ADDRESS_BOOK(ab->data));
-
-#if HAVE_MACOSX_DESKTOP
- ige_mac_menu_set_menu_bar(GTK_MENU_SHELL(gtk_ui_manager_get_widget(ui_manager, "/MainMenu")));
- ige_mac_menu_set_quit_menu_item(GTK_MENU_ITEM(gtk_ui_manager_get_widget(ui_manager,
"/MainMenu/FileMenu/Quit")));
-
- group = ige_mac_menu_add_app_menu_group();
- ige_mac_menu_add_app_menu_item(group,
- GTK_MENU_ITEM(gtk_ui_manager_get_widget(ui_manager,
"/MainMenu/HelpMenu/About")),
- NULL);
-#endif
+ g_action_map_add_action_entries(G_ACTION_MAP(contacts_app.window),
+ win_entries, G_N_ELEMENTS(win_entries),
+ contacts_app.window);
- if (menubar)
- /* Finally, return the actual menu bar created by the UIManager. */
- *menubar = gtk_ui_manager_get_widget(ui_manager, "/MainMenu");
+ set_address_book_menu_items();
}
static void
@@ -681,28 +638,21 @@ ab_clear_edit_widget(void)
static void
list_selection_changed_cb(GtkTreeSelection *selection, gpointer data)
{
-#if 0
GtkTreeIter iter;
GtkTreeModel *model;
GValue gv = {0,};
LibBalsaAddress *address;
- if(contacts_app.edit_widget &&
- GTK_WIDGET_VISIBLE(contacts_app.edit_widget) &&
- GTK_WIDGET_IS_SENSITIVE(contacts_app.edit_widget))
- return;
+
if(!gtk_tree_selection_get_selected(selection, &model, &iter))
return;
gtk_tree_model_get_value(model, &iter, LIST_COLUMN_ADDRESS, &gv);
address = LIBBALSA_ADDRESS(g_value_get_object(&gv));
- if (address) {
- if (address != contacts_app.displayed_address)
- ab_set_edit_widget(address, TRUE);
- /* gtk_widget_set_sensitive(contacts_app.edit_widget, FALSE); */
- } else
+ if (address)
+ ab_set_edit_widget(address, TRUE);
+ else
ab_clear_edit_widget();
g_value_unset(&gv);
contacts_app.displayed_address = address;
-#endif
}
static void
@@ -720,12 +670,9 @@ list_row_activated_cb(GtkTreeView *tree, gpointer data)
gtk_tree_model_get_value(model, &iter, LIST_COLUMN_ADDRESS, &gv);
address = LIBBALSA_ADDRESS(g_value_get_object(&gv));
if (address) {
- if (address != contacts_app.displayed_address)
- ab_set_edit_widget(address, TRUE);
+ ab_set_edit_widget(address, TRUE);
printf("Switch page..\n");
gtk_notebook_set_current_page(GTK_NOTEBOOK(contacts_app.notebook), 1);
- /* gtk_widget_set_sensitive(contacts_app.edit_widget, TRUE); */
- contacts_app.displayed_address = address;
} else
ab_clear_edit_widget();
g_value_unset(&gv);
@@ -951,8 +898,8 @@ bab_get_filter_box(void)
gtk_label_set_mnemonic_widget(GTK_LABEL(find_label), find_entry);
button = gtk_button_new();
gtk_container_add(GTK_CONTAINER(button),
- gtk_image_new_from_stock("gtk-ok",
- GTK_ICON_SIZE_BUTTON));
+ gtk_image_new_from_icon_name("gtk-ok",
+ GTK_ICON_SIZE_BUTTON));
gtk_box_pack_start(GTK_BOX(search_hbox), button, FALSE, FALSE, 1);
g_signal_connect(G_OBJECT(find_entry), "activate",
@@ -976,11 +923,17 @@ ew_key_pressed(GtkEntry * entry, GdkEventKey * event, struct ABMainWindow *abmw)
}
static GtkWidget*
-bab_window_new()
+bab_window_new(GtkApplication * application)
{
- GtkWidget* menubar = NULL, *main_vbox, *scroll;
- GtkWidget *wnd = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- GtkWidget *browse_widget, *edit_widget;
+ GtkWidget *wnd;
+ GtkWidget *main_vbox;
+ GtkWidget *scroll;
+ GtkWidget *browse_widget;
+ GtkWidget *edit_widget;
+
+ contacts_app.window =
+ GTK_WINDOW(wnd = gtk_application_window_new(application));
+ get_main_menu(application);
gtk_window_set_title(GTK_WINDOW(wnd), "Contacts");
@@ -988,13 +941,6 @@ bab_window_new()
main_vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 1);
gtk_container_add(GTK_CONTAINER(wnd), main_vbox);
- get_main_menu(GTK_WIDGET(wnd), &menubar, contacts_app.address_book_list);
-#ifndef HAVE_MACOSX_DESKTOP
- if (menubar)
- gtk_box_pack_start(GTK_BOX(main_vbox),
- menubar, FALSE, FALSE, 1);
-#endif
-
contacts_app.notebook = gtk_notebook_new();
gtk_box_pack_start(GTK_BOX(main_vbox),
contacts_app.notebook, TRUE, TRUE, 1);
@@ -1094,6 +1040,18 @@ information_real(void)
int
main(int argc, char *argv[])
{
+ GtkApplication *application;
+ GList *l;
+
+ application =
+ gtk_application_new("org.desktop.BalsaAb", G_APPLICATION_FLAGS_NONE);
+ if (!g_application_register(G_APPLICATION(application), NULL, NULL))
+ g_message("Could not register address book editor");
+ if (g_application_get_is_remote(G_APPLICATION(application))) {
+ g_object_unref(application);
+ return 1;
+ }
+
#ifdef ENABLE_NLS
/* Initialize the i18n stuff */
bindtextdomain(PACKAGE, GNOMELOCALEDIR);
@@ -1102,22 +1060,7 @@ main(int argc, char *argv[])
setlocale(LC_ALL, "");
#endif
- /* FIXME: do we need to allow a non-GUI mode? */
- gtk_init_check(&argc, &argv);
-
bab_init();
- LIBBALSA_TYPE_ADDRESS_BOOK_VCARD;
- LIBBALSA_TYPE_ADDRESS_BOOK_EXTERN;
- LIBBALSA_TYPE_ADDRESS_BOOK_LDIF;
-#if ENABLE_LDAP
- LIBBALSA_TYPE_ADDRESS_BOOK_LDAP;
-#endif
-#if HAVE_SQLITE
- LIBBALSA_TYPE_ADDRESS_BOOK_GPE;
-#endif
-#if HAVE_RUBRICA
- LIBBALSA_TYPE_ADDRESS_BOOK_RUBRICA;
-#endif /* HAVE_RUBRICA */
libbalsa_real_information_func = (LibBalsaInformationFunc)information_real;
g_mime_init(GMIME_ENABLE_RFC2047_WORKAROUNDS);
@@ -1128,26 +1071,30 @@ main(int argc, char *argv[])
libbalsa_conf_pop_group();
libbalsa_conf_foreach_group(ADDRESS_BOOK_SECTION_PREFIX,
bab_config_init, NULL);
+ if (contacts_app.address_book_list)
+ contacts_app.address_book =
+ contacts_app.address_book_list->data;
+
+ ab_window = bab_window_new(application);
- ab_window = bab_window_new();
- contacts_app.window = GTK_WINDOW(ab_window);
g_signal_connect(G_OBJECT(ab_window), "destroy",
G_CALLBACK(bab_cleanup), NULL);
g_signal_connect(G_OBJECT(ab_window), "delete-event",
G_CALLBACK(bab_delete_ok), NULL);
+ bab_set_address_book(contacts_app.address_book,
+ contacts_app.entry_list, NULL);
/* session management */
gtk_widget_show_all(ab_window);
gtk_widget_hide(contacts_app.edit_widget);
- if (contacts_app.first_radio_action)
- gtk_action_activate(GTK_ACTION(contacts_app.first_radio_action));
-
gtk_main();
/* Proper shutdown here */
- g_list_foreach(contacts_app.address_book_list, (GFunc)g_object_unref, NULL);
+ for (l = contacts_app.address_book_list; l; l = l->next)
+ if (l->data)
+ g_object_unref(l->data);
g_list_free(contacts_app.address_book_list);
return 0;
diff --git a/ui/Makefile.am b/ui/Makefile.am
index dadf7c3..07803cf 100644
--- a/ui/Makefile.am
+++ b/ui/Makefile.am
@@ -2,7 +2,8 @@ balsa_ui_FILES = \
source-viewer.ui \
main-window.ui \
message-window.ui \
- sendmsg-window.ui
+ sendmsg-window.ui \
+ ab-main.ui
EXTRA_DIST = $(balsa_ui_FILES)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]