]> git.0d.be Git - empathy.git/blobdiff - src/empathy.c
Fix translators complains about ambigous strings. Fixes bug #546154.
[empathy.git] / src / empathy.c
index f28eae9599d7497141962ea735eeecdb758e79eb..a14873f32c757c6887c8e804750796200ef5b792 100644 (file)
@@ -24,6 +24,7 @@
 
 #include <stdlib.h>
 #include <errno.h>
+#include <string.h>
 
 #include <glib.h>
 #include <glib/gi18n.h>
 
 #include <libempathy/empathy-idle.h>
 #include <libempathy/empathy-utils.h>
+#include <libempathy/empathy-dispatcher.h>
+#include <libempathy/empathy-tp-chat.h>
+#include <libempathy/empathy-tp-group.h>
 
 #include <libempathy-gtk/empathy-conf.h>
 
+#include "empathy-accounts-dialog.h"
 #include "empathy-main-window.h"
 #include "empathy-status-icon.h"
+#include "empathy-call-window.h"
+#include "empathy-chat-window.h"
 #include "bacon-message-connection.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
 
 static BaconMessageConnection *connection = NULL;
 
+static void
+dispatch_channel_cb (EmpathyDispatcher *dispatcher,
+                    TpChannel         *channel,
+                    gpointer           user_data)
+{
+       gchar *channel_type;
+
+       g_object_get (channel, "channel-type", &channel_type, NULL);
+       if (!tp_strdiff (channel_type, TP_IFACE_CHANNEL_TYPE_TEXT)) {
+               EmpathyTpChat *tp_chat;
+               EmpathyChat   *chat = NULL;
+               const gchar   *id;
+
+               tp_chat = empathy_tp_chat_new (channel);
+               empathy_run_until_ready (tp_chat);
+
+               id = empathy_tp_chat_get_id (tp_chat);
+               if (!id) {
+                       EmpathyContact *contact;
+
+                       contact = empathy_tp_chat_get_remote_contact (tp_chat);
+                       if (contact) {
+                               id = empathy_contact_get_id (contact);
+                       }
+               }
+
+               if (id) {
+                       McAccount *account;
+
+                       account = empathy_tp_chat_get_account (tp_chat);
+                       chat = empathy_chat_window_find_chat (account, id);
+               }
+
+               if (chat) {
+                       empathy_chat_set_tp_chat (chat, tp_chat);
+               } else {
+                       chat = empathy_chat_new (tp_chat);
+               }
+
+               empathy_chat_window_present_chat (chat);
+               g_object_unref (tp_chat);
+       }
+       else if (!tp_strdiff (channel_type, TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA)) {
+               empathy_call_window_new (channel);
+       }
+
+       g_free (channel_type);
+}
+
 static void
 service_ended_cb (MissionControl *mc,
                  gpointer        user_data)
@@ -67,46 +123,46 @@ operation_error_cb (MissionControl *mc,
 
        switch (error_code) {
        case MC_DISCONNECTED_ERROR:
-               message = _("Disconnected");
+               message = "Disconnected";
                break;
        case MC_INVALID_HANDLE_ERROR:
-               message = _("Invalid handle");
+               message = "Invalid handle";
                break;
        case MC_NO_MATCHING_CONNECTION_ERROR:
-               message = _("No matching connection");
+               message = "No matching connection";
                break;
        case MC_INVALID_ACCOUNT_ERROR:
-               message = _("Invalid account");
+               message = "Invalid account";
                break;
        case MC_PRESENCE_FAILURE_ERROR:
-               message = _("Presence failure");
+               message = "Presence failure";
                break;
        case MC_NO_ACCOUNTS_ERROR:
-               message = _("No accounts");
+               message = "No accounts";
                break;
        case MC_NETWORK_ERROR:
-               message = _("Network error");
+               message = "Network error";
                break;
        case MC_CONTACT_DOES_NOT_SUPPORT_VOICE_ERROR:
-               message = _("Contact does not support voice");
+               message = "Contact does not support voice";
                break;
        case MC_LOWMEM_ERROR:
-               message = _("Lowmem");
+               message = "Lowmem";
                break;
        case MC_CHANNEL_REQUEST_GENERIC_ERROR:
-               message = _("Channel request generic error");
+               message = "Channel request generic error";
                break;
        case MC_CHANNEL_BANNED_ERROR:
-               message = _("Channel banned");
+               message = "Channel banned";
                break;
        case MC_CHANNEL_FULL_ERROR:
-               message = _("Channel full");
+               message = "Channel full";
                break;
        case MC_CHANNEL_INVITE_ONLY_ERROR:
-               message = _("Channel invite only");
+               message = "Channel invite only";
                break;
        default:
-               message = _("Unknown error code");
+               message = "Unknown error code";
        }
 
        DEBUG ("Error during operation %d: %s", operation_id, message);
@@ -236,25 +292,30 @@ on_bacon_message_received (const char *message,
        DEBUG ("Other instance launched, presenting the main window. message='%s'",
                message);
 
-       startup_timestamp = atoi (message);
-
-       /* Set the proper interaction time on the window.
-        * Fall back to roundtripping to the X server when we
-        * don't have the timestamp, e.g. when launched from
-        * terminal. We also need to make sure that the window
-        * has been realized otherwise it will not work. lame. */
-       if (startup_timestamp == 0) {
-               /* Work if launched from the terminal */
-               DEBUG ("Using X server timestamp as a fallback");
-
-               if (!GTK_WIDGET_REALIZED (window)) {
-                       gtk_widget_realize (GTK_WIDGET (window));
+       if (strcmp (message, "accounts") == 0) {
+               /* accounts dialog requested */
+               empathy_accounts_dialog_show (GTK_WINDOW (window), NULL);
+       } else {
+               startup_timestamp = atoi (message);
+
+               /* Set the proper interaction time on the window.
+                * Fall back to roundtripping to the X server when we
+                * don't have the timestamp, e.g. when launched from
+                * terminal. We also need to make sure that the window
+                * has been realized otherwise it will not work. lame. */
+               if (startup_timestamp == 0) {
+                       /* Work if launched from the terminal */
+                       DEBUG ("Using X server timestamp as a fallback");
+
+                       if (!GTK_WIDGET_REALIZED (window)) {
+                               gtk_widget_realize (GTK_WIDGET (window));
+                       }
+
+                       startup_timestamp = gdk_x11_get_server_time (window->window);
                }
 
-               startup_timestamp = gdk_x11_get_server_time (window->window);
+               gtk_window_present_with_time (GTK_WINDOW (window), startup_timestamp);
        }
-
-       gtk_window_present_with_time (GTK_WINDOW (window), startup_timestamp);
 }
 
 static guint32
@@ -300,17 +361,28 @@ main (int argc, char *argv[])
 {
        guint32            startup_timestamp;
        EmpathyStatusIcon *icon;
+       EmpathyDispatcher *dispatcher;
        GtkWidget         *window;
        MissionControl    *mc;
        EmpathyIdle       *idle;
        gboolean           autoconnect = TRUE;
        gboolean           no_connect = FALSE; 
+       gboolean           hide_contact_list = FALSE;
+       gboolean           accounts_dialog = FALSE;
        GError            *error = NULL;
        GOptionEntry       options[] = {
                { "no-connect", 'n',
                  0, G_OPTION_ARG_NONE, &no_connect,
                  N_("Don't connect on startup"),
                  NULL },
+               { "hide-contact-list", 'h',
+                 0, G_OPTION_ARG_NONE, &hide_contact_list,
+                 N_("Don't show the contact list on startup"),
+                 NULL },
+               { "accounts", 'a',
+                 0, G_OPTION_ARG_NONE, &accounts_dialog,
+                 N_("Show the accounts dialog"),
+                 NULL },
                { NULL }
        };
 
@@ -345,10 +417,19 @@ main (int argc, char *argv[])
                if (!bacon_message_connection_get_is_server (connection)) {
                        gchar *message;
 
-                       DEBUG ("Activating existing instance");
+                       if (accounts_dialog) {
+                               DEBUG ("Showing accounts dialog from existing Empathy instance");
+
+                               message = g_strdup ("accounts");
+
+                       } else {
+
+                               DEBUG ("Activating existing instance");
+
+                               message = g_strdup_printf ("%" G_GUINT32_FORMAT,
+                                                          startup_timestamp);
+                       }
 
-                       message = g_strdup_printf ("%" G_GUINT32_FORMAT,
-                                                  startup_timestamp);
                        bacon_message_connection_send (connection, message);
 
                        /* We never popup a window, so tell startup-notification
@@ -373,6 +454,18 @@ main (int argc, char *argv[])
                          G_CALLBACK (operation_error_cb),
                          NULL);
 
+       if (accounts_dialog) {
+               GtkWidget *dialog;
+
+               dialog = empathy_accounts_dialog_show (NULL, NULL);
+               g_signal_connect (dialog, "destroy",
+                                 G_CALLBACK (gtk_main_quit),
+                                 NULL);
+
+               gtk_main ();
+               return 0;
+       }
+
        /* Setting up Idle */
        idle = empathy_idle_new ();
        empathy_idle_set_auto_away (idle, TRUE);
@@ -393,7 +486,7 @@ main (int argc, char *argv[])
 
        /* Setting up UI */
        window = empathy_main_window_show ();
-       icon = empathy_status_icon_new (GTK_WINDOW (window));
+       icon = empathy_status_icon_new (GTK_WINDOW (window), hide_contact_list);
 
        if (connection) {
                /* We se the callback here because we need window */
@@ -402,6 +495,12 @@ main (int argc, char *argv[])
                                                       window);
        }
 
+       /* Handle channels */
+       dispatcher = empathy_dispatcher_new ();
+       g_signal_connect (dispatcher, "dispatch-channel",
+                         G_CALLBACK (dispatch_channel_cb),
+                         NULL);
+
        gtk_main ();
 
        empathy_idle_set_state (idle, MC_PRESENCE_OFFLINE);
@@ -409,6 +508,7 @@ main (int argc, char *argv[])
        g_object_unref (mc);
        g_object_unref (idle);
        g_object_unref (icon);
+       g_object_unref (dispatcher);
 
        return EXIT_SUCCESS;
 }