]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-chat.c
use gtk_box_new() instead of gtk_[h,v]box_new()
[empathy.git] / libempathy-gtk / empathy-chat.c
index a8903b476832bd003224255f2eb4c35fba864c1c..f2afc4d4e4f3046999f8fa1290cf83ac0b7c0eff 100644 (file)
@@ -277,11 +277,13 @@ account_reconnected (EmpathyChat *chat,
                        if (priv->sms_channel)
                                empathy_sms_contact_id (
                                        account, priv->id,
-                                       TP_USER_ACTION_TIME_NOT_USER_ACTION);
+                                       TP_USER_ACTION_TIME_NOT_USER_ACTION,
+                                       NULL, NULL);
                        else
                                empathy_chat_with_contact_id (
                                        account, priv->id,
-                                       TP_USER_ACTION_TIME_NOT_USER_ACTION);
+                                       TP_USER_ACTION_TIME_NOT_USER_ACTION,
+                                       NULL, NULL);
                        break;
                case TP_HANDLE_TYPE_ROOM:
                        empathy_join_muc (account, priv->id,
@@ -756,26 +758,20 @@ chat_command_topic (EmpathyChat *chat,
                    GStrv        strv)
 {
        EmpathyChatPriv *priv = GET_PRIV (chat);
-       EmpathyTpChatProperty *property;
-       GValue value = {0, };
 
-       property = empathy_tp_chat_get_property (priv->tp_chat, "subject");
-       if (property == NULL) {
+       if (!empathy_tp_chat_supports_subject (priv->tp_chat)) {
                empathy_chat_view_append_event (chat->view,
                        _("Topic not supported on this conversation"));
                return;
        }
 
-       if (!(property->flags & TP_PROPERTY_FLAG_WRITE)) {
+       if (!empathy_tp_chat_can_set_subject (priv->tp_chat)) {
                empathy_chat_view_append_event (chat->view,
                        _("You are not allowed to change the topic"));
                return;
        }
 
-       g_value_init (&value, G_TYPE_STRING);
-       g_value_set_string (&value, strv[1]);
-       empathy_tp_chat_set_property (priv->tp_chat, "subject", &value);
-       g_value_unset (&value);
+       empathy_tp_chat_set_subject (priv->tp_chat, strv[1]);
 }
 
 void
@@ -1451,6 +1447,51 @@ chat_message_acknowledged_cb (EmpathyTpChat  *tp_chat,
        }
 }
 
+static void
+append_balance_error (EmpathyChat *chat,
+                     const gchar *message_body)
+{
+       EmpathyChatPriv *priv = GET_PRIV (chat);
+       TpConnection *conn = tp_channel_borrow_connection (TP_CHANNEL (priv->tp_chat));
+       const gchar *uri = tp_connection_get_balance_uri (conn);
+       const gchar *error = _("insufficient balance to send message");
+       gchar *str, *str_markup = NULL;
+
+       if (message_body != NULL) {
+               str = g_strdup_printf (_("Error sending message '%s': %s"), message_body, error);
+       } else {
+               str = g_strdup_printf (_("Error sending message: %s"), error);
+       }
+
+       if (!tp_str_empty (uri)) {
+               /* translators: error used when user doesn't have enough credit on his
+                * account to send the message. */
+               gchar *markup_error = g_strdup_printf (_("insufficient balance to send message."
+                                                        " <a href='%s'>Top up</a>."), uri);
+
+               if (message_body != NULL) {
+                       gchar *escaped_body = g_markup_escape_text (message_body, -1);
+
+                       str_markup = g_strdup_printf (_("Error sending message '%s': %s"),
+                               escaped_body, markup_error);
+
+                       g_free (escaped_body);
+               } else {
+                       str_markup = g_strdup_printf (_("Error sending message: %s"), markup_error);
+               }
+
+               g_free (markup_error);
+       }
+
+       if (str_markup != NULL)
+               empathy_chat_view_append_event_markup (chat->view, str_markup, str);
+       else
+               empathy_chat_view_append_event (chat->view, str);
+
+       g_free (str);
+       g_free (str_markup);
+}
+
 static void
 chat_send_error_cb (EmpathyTpChat          *tp_chat,
                    const gchar            *message_body,
@@ -1462,9 +1503,8 @@ chat_send_error_cb (EmpathyTpChat          *tp_chat,
        gchar       *str;
 
        if (!tp_strdiff (dbus_error, TP_ERROR_STR_INSUFFICIENT_BALANCE)) {
-               /* translators: error used when user doesn't have enough credit on his
-                * account to send the message. */
-               error = _("insufficient balance to send message");
+               append_balance_error (chat, message_body);
+               return;
        } else if (!tp_strdiff (dbus_error, TP_ERROR_STR_NOT_CAPABLE)) {
                error = _("not capable");
        }
@@ -1540,16 +1580,12 @@ chat_topic_expander_activate_cb (GtkExpander *expander,
 }
 
 static void
-chat_property_changed_cb (EmpathyTpChat *tp_chat,
-                         const gchar   *name,
-                         GValue        *value,
-                         EmpathyChat   *chat)
+chat_subject_changed_cb (EmpathyChat *chat)
 {
        EmpathyChatPriv *priv = GET_PRIV (chat);
 
-       if (!tp_strdiff (name, "subject")) {
                g_free (priv->subject);
-               priv->subject = g_value_dup_string (value);
+               priv->subject = g_strdup (empathy_tp_chat_get_subject (priv->tp_chat));
                g_object_notify (G_OBJECT (chat), "subject");
 
                if (EMP_STR_EMPTY (priv->subject)) {
@@ -1579,12 +1615,16 @@ chat_property_changed_cb (EmpathyTpChat *tp_chat,
                        empathy_chat_view_append_event (EMPATHY_CHAT (chat)->view, str);
                        g_free (str);
                }
-       }
-       else if (!tp_strdiff (name, "name")) {
+}
+
+static void
+chat_title_changed_cb (EmpathyChat *chat)
+{
+       EmpathyChatPriv *priv = GET_PRIV (chat);
+
                g_free (priv->name);
-               priv->name = g_value_dup_string (value);
+               priv->name = g_strdup (empathy_tp_chat_get_title (priv->tp_chat));
                g_object_notify (G_OBJECT (chat), "name");
-       }
 }
 
 static gboolean
@@ -2291,7 +2331,10 @@ chat_input_populate_popup_cb (GtkTextView *view,
        switch (priv->most_recent_event_type) {
            case GDK_BUTTON_PRESS:
                /* get the location from the pointer */
-               gtk_widget_get_pointer (GTK_WIDGET (view), &x, &y);
+               gdk_window_get_device_position (gtk_widget_get_window (GTK_WIDGET (view)),
+                       gdk_device_manager_get_client_pointer (gdk_display_get_device_manager (
+                               gtk_widget_get_display (GTK_WIDGET (view)))), &x, &y, NULL);
+
                gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (view),
                                                       GTK_TEXT_WINDOW_WIDGET,
                                                       x, y,
@@ -3097,12 +3140,14 @@ chat_finalize (GObject *object)
                        chat_send_error_cb, chat);
                g_signal_handlers_disconnect_by_func (priv->tp_chat,
                        chat_state_changed_cb, chat);
-               g_signal_handlers_disconnect_by_func (priv->tp_chat,
-                       chat_property_changed_cb, chat);
                g_signal_handlers_disconnect_by_func (priv->tp_chat,
                        chat_members_changed_cb, chat);
                g_signal_handlers_disconnect_by_func (priv->tp_chat,
                        chat_remote_contact_changed_cb, chat);
+               g_signal_handlers_disconnect_by_func (priv->tp_chat,
+                       chat_title_changed_cb, chat);
+               g_signal_handlers_disconnect_by_func (priv->tp_chat,
+                       chat_subject_changed_cb, chat);
                empathy_tp_chat_leave (priv->tp_chat, "");
                g_object_unref (priv->tp_chat);
        }
@@ -3428,7 +3473,7 @@ chat_prompt_to_save_password (EmpathyChat *self,
        gtk_info_bar_set_message_type (GTK_INFO_BAR (data->info_bar),
                                       GTK_MESSAGE_QUESTION);
 
-       hbox = gtk_hbox_new (FALSE, 5);
+       hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
        gtk_box_pack_start (GTK_BOX (content_area), hbox, TRUE, TRUE, 0);
 
        /* Add image */
@@ -3622,7 +3667,7 @@ display_password_info_bar (EmpathyChat *self)
 
        content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
 
-       hbox = gtk_hbox_new (FALSE, 5);
+       hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
        gtk_box_pack_start (GTK_BOX (content_area), hbox, TRUE, TRUE, 0);
 
        /* Add image */
@@ -3782,7 +3827,6 @@ empathy_chat_set_tp_chat (EmpathyChat   *chat,
                          EmpathyTpChat *tp_chat)
 {
        EmpathyChatPriv *priv = GET_PRIV (chat);
-       GPtrArray       *properties;
 
        g_return_if_fail (EMPATHY_IS_CHAT (chat));
        g_return_if_fail (EMPATHY_IS_TP_CHAT (tp_chat));
@@ -3813,9 +3857,6 @@ empathy_chat_set_tp_chat (EmpathyChat   *chat,
        g_signal_connect (tp_chat, "chat-state-changed-empathy",
                          G_CALLBACK (chat_state_changed_cb),
                          chat);
-       g_signal_connect (tp_chat, "property-changed",
-                         G_CALLBACK (chat_property_changed_cb),
-                         chat);
        g_signal_connect (tp_chat, "members-changed",
                          G_CALLBACK (chat_members_changed_cb),
                          chat);
@@ -3834,28 +3875,18 @@ empathy_chat_set_tp_chat (EmpathyChat   *chat,
        g_signal_connect_swapped (tp_chat, "notify::n-messages-sending",
                                  G_CALLBACK (chat_n_messages_sending_changed_cb),
                                  chat);
+       g_signal_connect_swapped (tp_chat, "notify::title",
+                                 G_CALLBACK (chat_title_changed_cb),
+                                 chat);
+       g_signal_connect_swapped (tp_chat, "notify::subject",
+                                 G_CALLBACK (chat_subject_changed_cb),
+                                 chat);
 
        /* Get initial value of properties */
-       properties = empathy_tp_chat_get_properties (priv->tp_chat);
-       if (properties != NULL) {
-               guint i;
-
-               for (i = 0; i < properties->len; i++) {
-                       EmpathyTpChatProperty *property;
-
-                       property = g_ptr_array_index (properties, i);
-                       if (property->value == NULL)
-                               continue;
-
-                       chat_property_changed_cb (priv->tp_chat,
-                                                 property->name,
-                                                 property->value,
-                                                 chat);
-               }
-       }
-
        chat_sms_channel_changed_cb (chat);
        chat_remote_contact_changed_cb (chat);
+       chat_title_changed_cb (chat);
+       chat_subject_changed_cb (chat);
 
        if (chat->input_text_view) {
                gtk_widget_set_sensitive (chat->input_text_view, TRUE);