+static void
+megaphone_applet_finalize (GObject *object)
+{
+ MegaphoneAppletPriv *priv = GET_PRIV (object);
+
+ if (priv->contact) {
+ g_object_unref (priv->contact);
+ }
+ if (priv->factory) {
+ g_object_unref (priv->factory);
+ }
+ if (priv->account_manager) {
+ g_signal_handlers_disconnect_by_func (priv->account_manager,
+ megaphone_applet_new_connection_cb, object);
+ g_object_unref (priv->account_manager);
+ }
+
+ if (priv->gconf_cnxn != 0) {
+ gconf_client_notify_remove (priv->gconf, priv->gconf_cnxn);
+ }
+ g_object_unref (priv->gconf);
+ g_free (priv->id);
+
+ G_OBJECT_CLASS (megaphone_applet_parent_class)->finalize (object);
+}
+
+static void
+megaphone_applet_class_init (MegaphoneAppletClass *class)
+{
+ GObjectClass *object_class;
+
+ object_class = G_OBJECT_CLASS (class);
+
+ object_class->finalize = megaphone_applet_finalize;
+
+ g_type_class_add_private (object_class, sizeof (MegaphoneAppletPriv));
+ empathy_gtk_init ();
+}
+
+static void
+megaphone_applet_init (MegaphoneApplet *applet)
+{
+ MegaphoneAppletPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (applet,
+ MEGAPHONE_TYPE_APPLET, MegaphoneAppletPriv);
+
+ applet->priv = priv;
+ priv->gconf = gconf_client_get_default ();
+ priv->account_manager = empathy_account_manager_dup_singleton ();
+ g_signal_connect (priv->account_manager, "new-connection",
+ G_CALLBACK (megaphone_applet_new_connection_cb), applet);
+
+ /* Image holds the contact avatar */
+ priv->image = gtk_image_new ();
+ gtk_widget_show (priv->image);
+ gtk_container_add (GTK_CONTAINER (applet), priv->image);
+
+ /* We want transparency */
+ panel_applet_set_flags (PANEL_APPLET (applet), PANEL_APPLET_EXPAND_MINOR);
+ panel_applet_set_background_widget (PANEL_APPLET (applet), GTK_WIDGET (applet));
+
+ /* Listen for clicks on the applet to dispatch a channel */
+ g_signal_connect (applet, "button-press-event",
+ G_CALLBACK (megaphone_applet_button_press_event_cb),
+ applet);
+
+ /* Allow to resize our avatar when needed */
+ g_signal_connect (applet, "size-allocate",
+ G_CALLBACK (megaphone_applet_size_allocate_cb),
+ applet);
+}
+
+static void
+megaphone_applet_set_contact (MegaphoneApplet *applet,
+ const gchar *str)
+{
+ MegaphoneAppletPriv *priv = GET_PRIV (applet);
+ TpConnection *connection;
+ gchar **strv = NULL;
+
+ DEBUG ("Setting new contact %s", str);
+
+ /* Release old contact, if any */
+ if (priv->contact) {
+ g_signal_handlers_disconnect_by_func (priv->contact,
+ megaphone_applet_update_contact,
+ applet);
+ g_object_unref (priv->contact),
+ priv->contact = NULL;
+ }
+ if (priv->account) {
+ g_object_unref (priv->account),
+ priv->account = NULL;
+ }
+ if (priv->factory) {
+ g_object_unref (priv->factory),
+ priv->factory = NULL;
+ }
+
+ /* Lookup the new contact */
+ if (str) {
+ strv = g_strsplit (str, "/", 2);
+ priv->account = mc_account_lookup (strv[0]);
+ priv->id = strv[1];
+ g_free (strv[0]);
+ g_free (strv);
+ }
+
+ if (priv->account) {
+ connection = empathy_account_manager_get_connection (
+ priv->account_manager, priv->account);
+ if (connection) {
+ megaphone_applet_new_connection_cb (priv->account_manager,
+ connection, priv->account, applet);
+ }
+ }
+}
+
+static void
+megaphone_applet_information_cb (BonoboUIComponent *uic,
+ MegaphoneApplet *applet,
+ const gchar *verb_name)
+{
+ MegaphoneAppletPriv *priv = GET_PRIV (applet);
+
+ /* FIXME: We should grey out the menu item if there are no available contact */
+ if (priv->contact) {
+ empathy_contact_information_dialog_show (priv->contact, NULL);
+ }
+}
+
+static void
+megaphone_applet_preferences_cb (BonoboUIComponent *uic,
+ MegaphoneApplet *applet,
+ const gchar *verb_name)
+{
+ megaphone_applet_show_preferences (applet);
+}
+