]> git.0d.be Git - empathy.git/blobdiff - src/empathy-main.c
Disconnect signals from chatroom_manager. Fixes bug #447178.
[empathy.git] / src / empathy-main.c
index 15f4c504f263f2b0d0e6fa854b70cf698e07242d..92a66b2c89eb29757ce279245165049bc667d7c2 100644 (file)
 #include <stdlib.h>
 
 #include <glib.h>
+#include <glib/gi18n.h>
 #include <gtk/gtk.h>
 
-#include <libtelepathy/tp-helpers.h>
+#include <libgnome/gnome-program.h>
+#include <libgnomeui/gnome-ui-init.h>
 
 #include <libmissioncontrol/mc-account.h>
 #include <libmissioncontrol/mc-account-monitor.h>
 #include <libmissioncontrol/mission-control.h>
 
-#include <libempathy/empathy-session.h>
 #include <libempathy/gossip-debug.h>
+#include <libempathy/gossip-utils.h>
+#include <libempathy/gossip-presence.h>
 #include <libempathy-gtk/empathy-main-window.h>
-#include <libempathy-gtk/gossip-stock.h>
-#include <libempathy-gtk/gossip-accounts-dialog.h>
+#include <libempathy-gtk/empathy-status-icon.h>
 
-#define DEBUG_DOMAIN "Empathy"
+#define DEBUG_DOMAIN "EmpathyMain"
 
 static void error_cb              (MissionControl *mc,
                                   GError         *error,
                                   gpointer        data);
 static void service_ended_cb      (MissionControl *mc,
                                   gpointer        user_data);
-static void start_mission_control (MissionControl *mc);
-static void destroy_cb            (GtkWidget      *window,
+static void operation_error_cb    (MissionControl *mc,
+                                  guint           operation_id,
+                                  guint           error_code,
                                   gpointer        user_data);
-static void icon_activate_cb      (GtkStatusIcon  *status_icon,
-                                  GtkWidget      *window);
+static void start_mission_control (MissionControl *mc);
 
 static void
 error_cb (MissionControl *mc,
@@ -69,6 +71,17 @@ service_ended_cb (MissionControl *mc,
        gossip_debug (DEBUG_DOMAIN, "Mission Control stopped");
 }
 
+static void
+operation_error_cb (MissionControl *mc,
+                   guint           operation_id,
+                   guint           error_code,
+                   gpointer        user_data)
+{
+       gossip_debug (DEBUG_DOMAIN, "Error code %d during operation %d",
+                     error_code,
+                     operation_id);
+}
+
 static void
 account_enabled_cb (McAccountMonitor *monitor,
                    gchar            *unique_name,
@@ -85,100 +98,91 @@ start_mission_control (MissionControl *mc)
 
        presence = mission_control_get_presence_actual (mc, NULL);
 
-       if (presence != MC_PRESENCE_UNSET &&
-           presence != MC_PRESENCE_OFFLINE) {
+       if (presence > MC_PRESENCE_OFFLINE) {
                /* MC is already running and online, nothing to do */
                return;
        }
 
        gossip_debug (DEBUG_DOMAIN, "Starting Mission Control...");
 
-       /* FIXME: Save/Restore status message */
-       mission_control_set_presence (mc, MC_PRESENCE_AVAILABLE,
+       mission_control_set_presence (mc,
+                                     MC_PRESENCE_AVAILABLE,
                                      NULL,
                                      (McCallback) error_cb,
                                      NULL);
-
-       mission_control_connect_all_with_default_presence (mc,
-                                                          (McCallback) error_cb,
-                                                          NULL);
-}
-
-static void
-destroy_cb (GtkWidget *window,
-           gpointer   user_data)
-{
-       gossip_stock_finalize ();
-       empathy_session_finalize ();
-       gtk_main_quit ();
-}
-
-static void
-icon_activate_cb (GtkStatusIcon *status_icon,
-                 GtkWidget     *window)
-{
-       if (GTK_WIDGET_VISIBLE (window)) {
-               gtk_widget_hide (window);
-       } else {
-               gtk_widget_show (window);
-       }
 }
 
 int
 main (int argc, char *argv[])
 {
-       GList            *accounts;
-       GtkStatusIcon    *icon;
-       GtkWidget        *window;
-       MissionControl   *mc;
-       McAccountMonitor *monitor;
-
-       gtk_init (&argc, &argv);
-
-       /* FIXME: This is a horrible hack */
-       gossip_stock_init (gtk_window_new (GTK_WINDOW_TOPLEVEL));
-
-       /* Setting up the main window */
-       window = empathy_main_window_show ();
-       g_signal_connect (window, "destroy",
-                         G_CALLBACK (destroy_cb),
-                         NULL);
-       g_signal_connect (window, "delete-event",
-                         G_CALLBACK (gtk_widget_hide_on_delete),
-                         NULL);
+       EmpathyStatusIcon *icon;
+       GtkWidget         *window;
+       MissionControl    *mc;
+       McAccountMonitor  *monitor;
+       GnomeProgram      *program;
+       gboolean           no_connect = FALSE;
+       GOptionContext    *context;
+       GOptionEntry       options[] = {
+               { "no-connect", 'n',
+                 0, G_OPTION_ARG_NONE, &no_connect,
+                 N_("Don't connect on startup"),
+                 NULL },
+               { NULL }
+       };
+
+       bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
+       bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+       textdomain (GETTEXT_PACKAGE);
+
+       context = g_option_context_new (_("- Empathy Instant Messenger"));
+       g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE);
+
+       g_set_application_name (PACKAGE_NAME);
+
+       program = gnome_program_init ("empathy",
+                                     PACKAGE_VERSION,
+                                     LIBGNOMEUI_MODULE,
+                                     argc, argv,
+                                     GNOME_PROGRAM_STANDARD_PROPERTIES,
+                                     "goption-context", context,
+                                     GNOME_PARAM_HUMAN_READABLE_NAME, PACKAGE_NAME,
+                                     NULL);
 
-       /* Setting up the tray icon */
-       icon = gtk_status_icon_new_from_stock (GOSSIP_STOCK_AVAILABLE);
-       gtk_status_icon_set_tooltip (icon, "Empathy - click here to show/hide the main window");
-       gtk_status_icon_set_visible (icon, TRUE);
-       g_signal_connect (icon, "activate",
-                         G_CALLBACK (icon_activate_cb),
-                         window);
-
-       /* Show the accounts dialog if there is no enabled accounts */
-       accounts = mc_accounts_list_by_enabled (TRUE);
-       if (accounts) {
-               mc_accounts_list_free (accounts);
-       } else {
-               gossip_accounts_dialog_show ();
-       }
+       gtk_window_set_default_icon_name ("empathy");
+       gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (),
+                                          DATADIR G_DIR_SEPARATOR_S "empathy");
 
        /* Setting up MC */
        monitor = mc_account_monitor_new ();
-       mc = mission_control_new (tp_get_bus ());
+       mc = gossip_mission_control_new ();
        g_signal_connect (monitor, "account-enabled",
                          G_CALLBACK (account_enabled_cb),
                          mc);
        g_signal_connect (mc, "ServiceEnded",
                          G_CALLBACK (service_ended_cb),
                          NULL);
-       start_mission_control (mc);
+       g_signal_connect (mc, "Error",
+                         G_CALLBACK (operation_error_cb),
+                         NULL);
+
+       if (!no_connect) {
+               start_mission_control (mc);
+       }
+
+       /* Setting up UI */
+       window = empathy_main_window_show ();
+       icon = empathy_status_icon_new (GTK_WINDOW (window));
 
        gtk_main ();
 
+       mission_control_set_presence (mc,
+                                     MC_PRESENCE_OFFLINE,
+                                     NULL, NULL, NULL);
+
        g_object_unref (monitor);
        g_object_unref (mc);
        g_object_unref (icon);
+       g_object_unref (program);
 
        return EXIT_SUCCESS;
 }