[krb5-auth-dialog] Use GtkApplication
- From: Guido GÃnther <guidog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [krb5-auth-dialog] Use GtkApplication
- Date: Mon, 12 Sep 2011 10:17:36 +0000 (UTC)
commit 072bf062baf562bcf35436c5ebb62919cdf069e4
Author: Guido GÃnther <agx sigxcpu org>
Date: Sun Sep 11 10:59:14 2011 +0200
Use GtkApplication
to work towards better singleton operation. Since GApplication acquires
the DBus name already don't try to own the name in ka-dbus again.
src/ka-applet.c | 16 ++++++++++------
src/ka-dbus.c | 41 +++++++++--------------------------------
src/ka-dialog.c | 2 +-
3 files changed, 20 insertions(+), 39 deletions(-)
---
diff --git a/src/ka-applet.c b/src/ka-applet.c
index 35edfab..5e2a0a5 100644
--- a/src/ka-applet.c
+++ b/src/ka-applet.c
@@ -62,18 +62,18 @@ const gchar *ka_signal_names[KA_SIGNAL_COUNT] = {
struct _KaApplet {
- GObject parent;
+ GtkApplication parent;
KaAppletPrivate *priv;
};
struct _KaAppletClass {
- GObjectClass parent;
+ GtkApplicationClass parent;
guint signals[KA_SIGNAL_COUNT];
};
-G_DEFINE_TYPE (KaApplet, ka_applet, G_TYPE_OBJECT);
+G_DEFINE_TYPE (KaApplet, ka_applet, GTK_TYPE_APPLICATION);
struct _KaAppletPrivate {
GtkBuilder *uixml;
@@ -342,7 +342,9 @@ ka_applet_class_init (KaAppletClass *klass)
static KaApplet *
ka_applet_new (void)
{
- return g_object_new (KA_TYPE_APPLET, NULL);
+ return g_object_new (KA_TYPE_APPLET,
+ "application-id", "org.gnome.KrbAuthDialog",
+ NULL);
}
@@ -936,9 +938,10 @@ KaApplet *
ka_applet_create ()
{
KaApplet *applet = ka_applet_new ();
+ GtkWindow *main_window;
GError *error = NULL;
gboolean ret;
-
+
if (!(ka_applet_setup_icons (applet)))
g_error ("Failure to setup icons");
gtk_window_set_default_icon_name (applet->priv->icons[val_icon]);
@@ -966,7 +969,8 @@ ka_applet_create ()
applet->priv->gconf = ka_gconf_init (applet);
g_return_val_if_fail (applet->priv->gconf != NULL, NULL);
- ka_main_window_create (applet, applet->priv->uixml);
+ main_window = ka_main_window_create (applet, applet->priv->uixml);
+ gtk_application_add_window (GTK_APPLICATION(applet), main_window);
ka_preferences_window_create (applet, applet->priv->uixml);
applet->priv->loader = ka_plugin_loader_create (applet);
diff --git a/src/ka-dbus.c b/src/ka-dbus.c
index 7d5831e..e03742d 100644
--- a/src/ka-dbus.c
+++ b/src/ka-dbus.c
@@ -24,7 +24,6 @@
#include "ka-dialog.h"
#include "ka-dbus.h"
-static guint dbus_owner_id;
static GDBusConnection *dbus_connection;
static const char *dbus_object_path = "/org/gnome/KrbAuthDialog";
static const char *dbus_interface_name = "org.gnome.KrbAuthDialog";
@@ -171,18 +170,19 @@ static const GDBusInterfaceVTable interface_vtable =
static void
-ka_dbus_on_bus_acquired (GDBusConnection *connection,
- const gchar *name G_GNUC_UNUSED,
- gpointer user_data)
+ka_dbus_on_get_bus_cb (GObject *source_object G_GNUC_UNUSED,
+ GAsyncResult *res,
+ gpointer user_data)
{
KaApplet *applet = user_data;
guint id;
+ dbus_connection = g_bus_get_finish (res, NULL);
introspection_data = g_dbus_node_info_new_for_xml (
ka_dbus_introspection_xml,
NULL);
- id = g_dbus_connection_register_object (connection,
+ id = g_dbus_connection_register_object (dbus_connection,
"/org/gnome/KrbAuthDialog",
introspection_data->interfaces[0],
&interface_vtable,
@@ -190,22 +190,8 @@ ka_dbus_on_bus_acquired (GDBusConnection *connection,
NULL, /* user_data_free_func */
NULL); /* GError** */
if (!id)
- g_error ("Failed to regiester DBus object");
+ g_error ("Failed to register DBus object");
ka_dbus_connect_signals (applet);
-
- dbus_connection = connection;
-}
-
-
-static void
-ka_dbus_on_name_lost (GDBusConnection *connection G_GNUC_UNUSED,
- const gchar *name G_GNUC_UNUSED,
- gpointer user_data)
-{
- KaApplet *applet = user_data;
-
- g_warning ("Cannot acquire DBUS name");
- ka_applet_destroy (applet);
}
@@ -217,10 +203,6 @@ ka_dbus_disconnect ()
introspection_data = NULL;
}
- if (dbus_owner_id) {
- g_bus_unown_name (dbus_owner_id);
- dbus_owner_id = 0;
- }
dbus_connection = NULL;
}
@@ -230,17 +212,12 @@ ka_dbus_connect (KaApplet *applet)
{
g_return_val_if_fail (applet != 0, FALSE);
- dbus_owner_id = g_bus_own_name (G_BUS_TYPE_SESSION,
- "org.gnome.KrbAuthDialog",
- G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT,
- ka_dbus_on_bus_acquired,
- NULL,
- ka_dbus_on_name_lost,
- applet,
- NULL);
+ g_bus_get (G_BUS_TYPE_SESSION, NULL, ka_dbus_on_get_bus_cb,
+ applet);
return TRUE;
}
/*
* vim:ts=4:sts=4:sw=4:et:
*/
+
diff --git a/src/ka-dialog.c b/src/ka-dialog.c
index 3cadc49..8e042bf 100644
--- a/src/ka-dialog.c
+++ b/src/ka-dialog.c
@@ -1125,7 +1125,7 @@ main (int argc, char *argv[])
g_idle_add ((GSourceFunc) credentials_expiring_once, applet);
monitor = monitor_ccache (applet);
- gtk_main ();
+ g_application_run (G_APPLICATION(applet), argc, argv);
}
ka_dbus_disconnect ();
ka_nm_shutdown ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]