]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-presence-chooser.c
Updated Basque language
[empathy.git] / libempathy-gtk / empathy-presence-chooser.c
index f57c5d34f5b2d7fed90a3f59f7707d3d618b6c9e..ba36e091c518a65419e6544c9169e3dc58b85813 100644 (file)
@@ -34,8 +34,8 @@
 #include <gdk/gdkkeysyms.h>
 
 #include <telepathy-glib/util.h>
-#include <libmissioncontrol/mc-enum-types.h>
 
+#include <libempathy/empathy-connectivity.h>
 #include <libempathy/empathy-idle.h>
 #include <libempathy/empathy-utils.h>
 #include <libempathy/empathy-status-presets.h>
@@ -80,9 +80,9 @@ enum {
 
 /* For combobox's model */
 enum {
+       COL_STATUS_TEXT,
        COL_STATE_ICON_NAME,
        COL_STATE,
-       COL_STATUS_TEXT,
        COL_DISPLAY_MARKUP,
        COL_STATUS_CUSTOMISABLE,
        COL_TYPE,
@@ -99,42 +99,49 @@ typedef enum  {
 
 typedef struct {
        EmpathyIdle *idle;
+       EmpathyConnectivity *connectivity;
+
+       gulong state_change_signal_id;
 
        gboolean     editing_status;
        int          block_set_editing;
        int          block_changed;
        guint        focus_out_idle_source;
 
-       McPresence   state;
+       TpConnectionPresenceType state;
        PresenceChooserEntryType previous_type;
 
-       McPresence   flash_state_1;
-       McPresence   flash_state_2;
+       TpConnectionPresenceType   flash_state_1;
+       TpConnectionPresenceType   flash_state_2;
        guint        flash_timeout_id;
 } EmpathyPresenceChooserPriv;
 
 /* States to be listed in the menu.
  * Each state has a boolean telling if it can have custom message */
-static guint states[] = {MC_PRESENCE_AVAILABLE, TRUE,
-                        MC_PRESENCE_DO_NOT_DISTURB, TRUE,
-                        MC_PRESENCE_AWAY, TRUE,
-                        MC_PRESENCE_HIDDEN, FALSE,
-                        MC_PRESENCE_OFFLINE, FALSE};
+static struct { TpConnectionPresenceType state;
+         gboolean customisable;
+} states[] = { { TP_CONNECTION_PRESENCE_TYPE_AVAILABLE, TRUE } ,
+                        { TP_CONNECTION_PRESENCE_TYPE_BUSY, TRUE },
+                        { TP_CONNECTION_PRESENCE_TYPE_AWAY, TRUE },
+                        { TP_CONNECTION_PRESENCE_TYPE_HIDDEN, FALSE },
+                        { TP_CONNECTION_PRESENCE_TYPE_OFFLINE, FALSE},
+                        { TP_CONNECTION_PRESENCE_TYPE_UNSET, },
+                       };
 
 static void            presence_chooser_finalize               (GObject                    *object);
 static void            presence_chooser_presence_changed_cb    (EmpathyPresenceChooser      *chooser);
 static gboolean        presence_chooser_flash_timeout_cb       (EmpathyPresenceChooser      *chooser);
 static void            presence_chooser_flash_start            (EmpathyPresenceChooser      *chooser,
-                                                               McPresence                  state_1,
-                                                               McPresence                  state_2);
+                                                               TpConnectionPresenceType                  state_1,
+                                                               TpConnectionPresenceType                  state_2);
 static void            presence_chooser_flash_stop             (EmpathyPresenceChooser      *chooser,
-                                                               McPresence                  state);
+                                                               TpConnectionPresenceType                  state);
 static void            presence_chooser_menu_add_item          (GtkWidget                  *menu,
                                                                const gchar                *str,
-                                                               McPresence                  state);
+                                                               TpConnectionPresenceType                  state);
 static void            presence_chooser_noncustom_activate_cb  (GtkWidget                  *item,
                                                                gpointer                    user_data);
-static void            presence_chooser_set_state              (McPresence                  state,
+static void            presence_chooser_set_state              (TpConnectionPresenceType                  state,
                                                                const gchar                *status);
 static void            presence_chooser_custom_activate_cb     (GtkWidget                  *item,
                                                                gpointer                    user_data);
@@ -159,42 +166,41 @@ presence_chooser_create_model (EmpathyPresenceChooser *self)
        int i;
 
        store = gtk_list_store_new (N_COLUMNS,
-                                   G_TYPE_STRING,    /* COL_STATE_ICON_NAME */
-                                   MC_TYPE_PRESENCE, /* COL_STATE */
                                    G_TYPE_STRING,    /* COL_STATUS_TEXT */
+                                   G_TYPE_STRING,    /* COL_STATE_ICON_NAME */
+                                   G_TYPE_UINT,      /* COL_STATE */
                                    G_TYPE_STRING,    /* COL_DISPLAY_MARKUP */
                                    G_TYPE_BOOLEAN,   /* COL_STATUS_CUSTOMISABLE */
                                    G_TYPE_INT);      /* COL_TYPE */
 
        custom_message = g_strdup_printf ("<i>%s</i>", _("Custom Message..."));
 
-       for (i = 0; i < G_N_ELEMENTS (states); i += 2) {
+       for (i = 0; states[i].state != TP_CONNECTION_PRESENCE_TYPE_UNSET; i++) {
                GList       *list, *l;
                const char *status, *icon_name;
 
-               status = empathy_presence_get_default_message (states[i]);
-               icon_name = empathy_icon_name_for_presence (states[i]);
+               status = empathy_presence_get_default_message (states[i].state);
+               icon_name = empathy_icon_name_for_presence (states[i].state);
 
                gtk_list_store_insert_with_values (store, NULL, -1,
-                       COL_STATE_ICON_NAME, icon_name,
-                       COL_STATE, states[i],
                        COL_STATUS_TEXT, status,
+                       COL_STATE_ICON_NAME, icon_name,
+                       COL_STATE, states[i].state,
                        COL_DISPLAY_MARKUP, status,
-                       COL_STATUS_CUSTOMISABLE, states[i+1],
+                       COL_STATUS_CUSTOMISABLE, states[i].customisable,
                        COL_TYPE, ENTRY_TYPE_BUILTIN,
                        -1);
 
-               if (states[i+1]) {
-
+               if (states[i].customisable) {
                        /* Set custom messages if wanted */
-                       list = empathy_status_presets_get (states[i], -1);
+                       list = empathy_status_presets_get (states[i].state, -1);
                        list = g_list_sort (list, (GCompareFunc) g_utf8_collate);
                        for (l = list; l; l = l->next) {
                                gtk_list_store_insert_with_values (store,
                                        NULL, -1,
-                                       COL_STATE_ICON_NAME, icon_name,
-                                       COL_STATE, states[i],
                                        COL_STATUS_TEXT, l->data,
+                                       COL_STATE_ICON_NAME, icon_name,
+                                       COL_STATE, states[i].state,
                                        COL_DISPLAY_MARKUP, l->data,
                                        COL_STATUS_CUSTOMISABLE, TRUE,
                                        COL_TYPE, ENTRY_TYPE_SAVED,
@@ -203,9 +209,9 @@ presence_chooser_create_model (EmpathyPresenceChooser *self)
                        g_list_free (list);
 
                        gtk_list_store_insert_with_values (store, NULL, -1,
+                               COL_STATUS_TEXT, _("Custom Message..."),
                                COL_STATE_ICON_NAME, icon_name,
-                               COL_STATE, states[i],
-                               COL_STATUS_TEXT, "",
+                               COL_STATE, states[i].state,
                                COL_DISPLAY_MARKUP, custom_message,
                                COL_STATUS_CUSTOMISABLE, TRUE,
                                COL_TYPE, ENTRY_TYPE_CUSTOM,
@@ -220,8 +226,8 @@ presence_chooser_create_model (EmpathyPresenceChooser *self)
                        -1);
 
        gtk_list_store_insert_with_values (store, NULL, -1,
+               COL_STATUS_TEXT, _("Edit Custom Messages..."),
                COL_STATE_ICON_NAME, GTK_STOCK_EDIT,
-               COL_STATUS_TEXT, "",
                COL_DISPLAY_MARKUP, _("Edit Custom Messages..."),
                COL_TYPE, ENTRY_TYPE_EDIT_CUSTOM,
                -1);
@@ -279,7 +285,7 @@ static gboolean
 presence_chooser_is_preset (EmpathyPresenceChooser *self)
 {
        EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
-       McPresence state;
+       TpConnectionPresenceType state;
        const char *status;
        GList *presets, *l;
        gboolean match = FALSE;
@@ -291,7 +297,7 @@ presence_chooser_is_preset (EmpathyPresenceChooser *self)
        for (l = presets; l; l = l->next) {
                char *preset = (char *) l->data;
 
-               if (!strcmp (status, preset)) {
+               if (!tp_strdiff (status, preset)) {
                        match = TRUE;
                        break;
                }
@@ -407,17 +413,14 @@ mc_set_custom_state (EmpathyPresenceChooser *self)
        /* update the status with MC */
        status = gtk_entry_get_text (GTK_ENTRY (entry));
 
-       DEBUG ("Sending state to MC-> %s (%s)\n",
-               g_enum_get_value (g_type_class_peek (MC_TYPE_PRESENCE),
-                       priv->state)->value_name,
-               status);
+       DEBUG ("Sending state to MC-> %d (%s)\n", priv->state, status);
 
        empathy_idle_set_presence (priv->idle, priv->state, status);
 }
 
 static void
 ui_set_custom_state (EmpathyPresenceChooser *self,
-                    McPresence state,
+                    TpConnectionPresenceType state,
                     const char *status)
 {
        EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
@@ -433,7 +436,7 @@ ui_set_custom_state (EmpathyPresenceChooser *self,
        gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
                                           GTK_ENTRY_ICON_PRIMARY,
                                           icon_name);
-       gtk_entry_set_text (GTK_ENTRY (entry), status);
+       gtk_entry_set_text (GTK_ENTRY (entry), status == NULL ? "" : status);
        presence_chooser_set_favorite_icon (self);
 
        priv->block_changed--;
@@ -462,13 +465,17 @@ presence_chooser_entry_icon_release_cb (EmpathyPresenceChooser *self,
        }
        else {
                PresenceChooserEntryType type;
-               McPresence state;
+               TpConnectionPresenceType state;
                const char *status;
 
                type = presence_chooser_get_entry_type (self);
                state = empathy_idle_get_state (priv->idle);
                status = empathy_idle_get_status (priv->idle);
 
+               if (!empathy_status_presets_is_valid (state))
+                       /* It doesn't make sense to add such presence as favorite */
+                       return;
+
                if (presence_chooser_is_preset (self)) {
                        /* remove the entry */
                        DEBUG ("REMOVING PRESET (%i, %s)\n", state, status);
@@ -554,7 +561,7 @@ presence_chooser_changed_cb (GtkComboBox *self, gpointer user_data)
        EmpathyPresenceChooserPriv *priv = GET_PRIV (self);
        GtkTreeIter iter;
        char *icon_name;
-       McPresence new_state;
+       TpConnectionPresenceType new_state;
        gboolean customisable = TRUE;
        PresenceChooserEntryType type = -1;
        GtkWidget *entry;
@@ -627,6 +634,9 @@ presence_chooser_changed_cb (GtkComboBox *self, gpointer user_data)
                presence_chooser_set_status_editing (
                        EMPATHY_PRESENCE_CHOOSER (self),
                        FALSE);
+               gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
+                                          GTK_ENTRY_ICON_PRIMARY,
+                                          icon_name);
 
                gtk_tree_model_get (model, &iter,
                                    COL_STATUS_TEXT, &status,
@@ -703,6 +713,14 @@ presence_chooser_entry_focus_out_cb (EmpathyPresenceChooser *chooser,
        return FALSE;
 }
 
+static void
+presence_chooser_connectivity_state_change (EmpathyConnectivity *connectivity,
+                                           gboolean new_online,
+                                           EmpathyPresenceChooser *chooser)
+{
+       gtk_widget_set_sensitive (GTK_WIDGET (chooser), new_online);
+}
+
 static void
 empathy_presence_chooser_init (EmpathyPresenceChooser *chooser)
 {
@@ -774,6 +792,14 @@ empathy_presence_chooser_init (EmpathyPresenceChooser *chooser)
        /* FIXME: this string sucks */
        gtk_widget_set_tooltip_text (GTK_WIDGET (chooser),
                _("Set your presence and current status"));
+
+       priv->connectivity = empathy_connectivity_dup_singleton ();
+       priv->state_change_signal_id = g_signal_connect (priv->connectivity,
+               "state-change",
+               G_CALLBACK (presence_chooser_connectivity_state_change),
+               chooser);
+       presence_chooser_connectivity_state_change (priv->connectivity,
+               empathy_connectivity_is_online (priv->connectivity), chooser);
 }
 
 static void
@@ -796,6 +822,12 @@ presence_chooser_finalize (GObject *object)
                                              object);
        g_object_unref (priv->idle);
 
+       g_signal_handler_disconnect (priv->connectivity,
+                                    priv->state_change_signal_id);
+       priv->state_change_signal_id = 0;
+
+       g_object_unref (priv->connectivity);
+
        G_OBJECT_CLASS (empathy_presence_chooser_parent_class)->finalize (object);
 }
 
@@ -820,8 +852,8 @@ static void
 presence_chooser_presence_changed_cb (EmpathyPresenceChooser *chooser)
 {
        EmpathyPresenceChooserPriv *priv;
-       McPresence                  state;
-       McPresence                  flash_state;
+       TpConnectionPresenceType    state;
+       TpConnectionPresenceType    flash_state;
        const gchar                *status;
        GtkTreeModel               *model;
        GtkTreeIter                 iter;
@@ -843,7 +875,7 @@ presence_chooser_presence_changed_cb (EmpathyPresenceChooser *chooser)
             valid;
             valid = gtk_tree_model_iter_next (model, &iter)) {
                int m_type;
-               McPresence m_state;
+               TpConnectionPresenceType m_state;
                char *m_status;
 
                gtk_tree_model_get (model, &iter,
@@ -871,7 +903,7 @@ presence_chooser_presence_changed_cb (EmpathyPresenceChooser *chooser)
                                COL_STATUS_TEXT, &m_status,
                                -1);
 
-               match = !strcmp (status, m_status);
+               match = !tp_strdiff (status, m_status);
 
                g_free (m_status);
 
@@ -889,7 +921,7 @@ presence_chooser_presence_changed_cb (EmpathyPresenceChooser *chooser)
                ui_set_custom_state (chooser, state, status);
        }
 
-       if (flash_state != MC_PRESENCE_UNSET) {
+       if (flash_state != TP_CONNECTION_PRESENCE_TYPE_UNSET) {
                presence_chooser_flash_start (chooser, state, flash_state);
        }
        else {
@@ -901,7 +933,7 @@ static gboolean
 presence_chooser_flash_timeout_cb (EmpathyPresenceChooser *chooser)
 {
        EmpathyPresenceChooserPriv *priv;
-       McPresence                  state;
+       TpConnectionPresenceType    state;
        static gboolean             on = FALSE;
        GtkWidget                  *entry;
 
@@ -926,8 +958,8 @@ presence_chooser_flash_timeout_cb (EmpathyPresenceChooser *chooser)
 
 static void
 presence_chooser_flash_start (EmpathyPresenceChooser *chooser,
-                             McPresence              state_1,
-                             McPresence              state_2)
+                             TpConnectionPresenceType state_1,
+                             TpConnectionPresenceType state_2)
 {
        EmpathyPresenceChooserPriv *priv;
 
@@ -947,7 +979,7 @@ presence_chooser_flash_start (EmpathyPresenceChooser *chooser,
 
 static void
 presence_chooser_flash_stop (EmpathyPresenceChooser *chooser,
-                            McPresence             state)
+                            TpConnectionPresenceType state)
 {
        EmpathyPresenceChooserPriv *priv = GET_PRIV (chooser);
        GtkWidget *entry;
@@ -981,21 +1013,21 @@ empathy_presence_chooser_create_menu (void)
 
        menu = gtk_menu_new ();
 
-       for (i = 0; i < G_N_ELEMENTS (states); i += 2) {
+       for (i = 0; states[i].state != TP_CONNECTION_PRESENCE_TYPE_UNSET; i++) {
                GList       *list, *l;
 
-               status = empathy_presence_get_default_message (states[i]);
+               status = empathy_presence_get_default_message (states[i].state);
                presence_chooser_menu_add_item (menu,
                                                status,
-                                               states[i]);
+                                               states[i].state);
 
-               if (states[i+1]) {
+               if (states[i].customisable) {
                        /* Set custom messages if wanted */
-                       list = empathy_status_presets_get (states[i], 5);
+                       list = empathy_status_presets_get (states[i].state, 5);
                        for (l = list; l; l = l->next) {
                                presence_chooser_menu_add_item (menu,
                                                                l->data,
-                                                               states[i]);
+                                                               states[i].state);
                        }
                        g_list_free (list);
                }
@@ -1026,7 +1058,7 @@ empathy_presence_chooser_create_menu (void)
 static void
 presence_chooser_menu_add_item (GtkWidget   *menu,
                                const gchar *str,
-                               McPresence   state)
+                               TpConnectionPresenceType state)
 {
        GtkWidget   *item;
        GtkWidget   *image;
@@ -1043,6 +1075,7 @@ presence_chooser_menu_add_item (GtkWidget   *menu,
        gtk_widget_show (image);
 
        gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
+       gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (item), TRUE);
        gtk_widget_show (item);
 
        g_object_set_data_full (G_OBJECT (item),
@@ -1058,7 +1091,7 @@ static void
 presence_chooser_noncustom_activate_cb (GtkWidget *item,
                                        gpointer   user_data)
 {
-       McPresence   state;
+       TpConnectionPresenceType state;
        const gchar *status;
 
        status = g_object_get_data (G_OBJECT (item), "status");
@@ -1068,7 +1101,7 @@ presence_chooser_noncustom_activate_cb (GtkWidget *item,
 }
 
 static void
-presence_chooser_set_state (McPresence   state,
+presence_chooser_set_state (TpConnectionPresenceType state,
                            const gchar *status)
 {
        EmpathyIdle *idle;