#include <libempathy-gtk/empathy-log-window.h>
#include <libempathy-gtk/empathy-geometry.h>
#include <libempathy-gtk/empathy-smiley-manager.h>
+#include <libempathy-gtk/empathy-sound.h>
#include <libempathy-gtk/empathy-ui-utils.h>
#include "empathy-chat-window.h"
GtkUIManager *ui_manager;
GtkAction *menu_conv_insert_smiley;
GtkAction *menu_conv_favorite;
+ GtkAction *menu_conv_toggle_contacts;
GtkAction *menu_edit_cut;
GtkAction *menu_edit_copy;
"chat-window-tab-close-button");
context = gtk_widget_get_pango_context (hbox);
- metrics = pango_context_get_metrics (context, hbox->style->font_desc,
+ metrics = pango_context_get_metrics (context, gtk_widget_get_style (hbox)->font_desc,
pango_context_get_language (context));
char_width = pango_font_metrics_get_approximate_char_width (metrics);
pango_font_metrics_unref (metrics);
}
}
+static void
+append_markup_printf (GString *string,
+ const char *format,
+ ...)
+{
+ gchar *tmp;
+ va_list args;
+
+ va_start (args, format);
+
+ tmp = g_markup_vprintf_escaped (format, args);
+ g_string_append (string, tmp);
+ g_free (tmp);
+
+ va_end (args);
+}
+
static void
chat_window_update_chat_tab (EmpathyChat *chat)
{
EmpathyChatWindowPriv *priv;
EmpathyContact *remote_contact;
const gchar *name;
- McAccount *account;
+ const gchar *id;
+ EmpathyAccount *account;
const gchar *subject;
+ const gchar *status = NULL;
GtkWidget *widget;
GString *tooltip;
gchar *markup;
remote_contact = empathy_chat_get_remote_contact (chat);
DEBUG ("Updating chat tab, name=%s, account=%s, subject=%s, remote_contact=%p",
- name, mc_account_get_unique_name (account), subject, remote_contact);
+ name, empathy_account_get_unique_name (account), subject, remote_contact);
/* Update tab image */
if (g_list_find (priv->chats_new_msg, chat)) {
tooltip = g_string_new (NULL);
if (remote_contact) {
- markup = g_markup_printf_escaped ("<b>%s</b><small> (%s)</small>\n%s",
- empathy_contact_get_id (remote_contact),
- mc_account_get_display_name (account),
- empathy_contact_get_status (remote_contact));
- g_string_append (tooltip, markup);
- g_free (markup);
+ id = empathy_contact_get_id (remote_contact);
+ status = empathy_contact_get_presence_message (remote_contact);
+ } else {
+ id = name;
}
- else {
- markup = g_markup_printf_escaped ("<b>%s</b><small> (%s)</small>", name,
- mc_account_get_display_name (account));
- g_string_append (tooltip, markup);
- g_free (markup);
+
+ append_markup_printf (tooltip,
+ "<b>%s</b><small> (%s)</small>",
+ id,
+ empathy_account_get_display_name (account));
+
+ if (!EMP_STR_EMPTY (status)) {
+ append_markup_printf (tooltip, "\n<i>%s</i>", status);
}
if (subject) {
- markup = g_markup_printf_escaped ("\n<b>%s</b> %s", _("Topic:"), subject);
- g_string_append (tooltip, markup);
- g_free (markup);
+ append_markup_printf (tooltip, "\n<b>%s</b> %s",
+ _("Topic:"), subject);
}
+
if (g_list_find (priv->chats_composing, chat)) {
- markup = g_markup_printf_escaped ("\n%s", _("Typing a message."));
- g_string_append (tooltip, markup);
- g_free (markup);
+ append_markup_printf (tooltip, "\n%s", _("Typing a message."));
}
markup = g_string_free (tooltip, FALSE);
{
EmpathyChatWindowPriv *priv = GET_PRIV (window);
gboolean is_room;
+ gboolean active;
+ EmpathyContact *remote_contact = NULL;
/* Favorite room menu */
is_room = empathy_chat_is_room (priv->current_chat);
if (is_room) {
const gchar *room;
- McAccount *account;
- gboolean found;
+ EmpathyAccount *account;
+ gboolean found = FALSE;
+ EmpathyChatroom *chatroom;
room = empathy_chat_get_id (priv->current_chat);
account = empathy_chat_get_account (priv->current_chat);
- found = empathy_chatroom_manager_find (priv->chatroom_manager,
- account, room) != NULL;
+ chatroom = empathy_chatroom_manager_find (priv->chatroom_manager,
+ account, room);
+ if (chatroom != NULL)
+ found = empathy_chatroom_is_favorite (chatroom);
DEBUG ("This room %s favorite", found ? "is" : "is not");
gtk_toggle_action_set_active (
GTK_TOGGLE_ACTION (priv->menu_conv_favorite), found);
}
gtk_action_set_visible (priv->menu_conv_favorite, is_room);
+
+ /* Show contacts menu */
+ g_object_get (priv->current_chat,
+ "remote-contact", &remote_contact,
+ "show-contacts", &active,
+ NULL);
+ if (remote_contact == NULL) {
+ gtk_toggle_action_set_active (
+ GTK_TOGGLE_ACTION (priv->menu_conv_toggle_contacts),
+ active);
+ }
+ gtk_action_set_visible (priv->menu_conv_toggle_contacts,
+ (remote_contact == NULL));
+ if (remote_contact != NULL) {
+ g_object_unref (remote_contact);
+ }
}
static void
{
EmpathyChatWindowPriv *priv = GET_PRIV (window);
gboolean active;
- McAccount *account;
+ EmpathyAccount *account;
const gchar *room;
EmpathyChatroom *chatroom;
chatroom = empathy_chatroom_manager_find (priv->chatroom_manager,
account, room);
- if (active && !chatroom) {
+ if (chatroom == NULL) {
const gchar *name;
name = empathy_chat_get_name (priv->current_chat);
chatroom = empathy_chatroom_new_full (account, room, name, FALSE);
empathy_chatroom_manager_add (priv->chatroom_manager, chatroom);
g_object_unref (chatroom);
- return;
- }
-
- if (!active && chatroom) {
- empathy_chatroom_manager_remove (priv->chatroom_manager, chatroom);
- }
+ }
+
+ empathy_chatroom_set_favorite (chatroom, active);
+}
+
+static void
+chat_window_contacts_toggled_cb (GtkToggleAction *toggle_action,
+ EmpathyChatWindow *window)
+{
+ EmpathyChatWindowPriv *priv = GET_PRIV (window);
+ gboolean active;
+
+ active = gtk_toggle_action_get_active (toggle_action);
+
+ empathy_chat_set_show_contacts (priv->current_chat, active);
}
static const gchar *
EmpathyChat *chat)
{
EmpathyContact *sender;
- char *header, *escaped;
+ const gchar *header;
+ char *escaped;
const char *body;
GdkPixbuf *pixbuf;
NotificationData *cb_data;
cb_data->window = window;
sender = empathy_message_get_sender (message);
- header = g_strdup_printf (_("New message from %s"),
- empathy_contact_get_name (sender));
+ header = empathy_contact_get_name (sender);
body = empathy_message_get_body (message);
escaped = g_markup_escape_text (body, -1);
if (priv->notification != NULL) {
notify_notification_update (priv->notification,
header, escaped, NULL);
- notify_notification_set_icon_from_pixbuf (priv->notification, pixbuf);
+ /* if icon doesn't exist libnotify will crash */
+ if (pixbuf != NULL)
+ notify_notification_set_icon_from_pixbuf (priv->notification, pixbuf);
} else {
priv->notification = notify_notification_new (header, escaped, NULL, NULL);
notify_notification_set_timeout (priv->notification, NOTIFY_EXPIRES_DEFAULT);
- notify_notification_set_icon_from_pixbuf (priv->notification, pixbuf);
+ /* if icon doesn't exist libnotify will crash */
+ if (pixbuf != NULL)
+ notify_notification_set_icon_from_pixbuf (priv->notification, pixbuf);
g_signal_connect (priv->notification, "closed",
G_CALLBACK (chat_window_notification_closed_cb), cb_data);
notify_notification_show (priv->notification, NULL);
g_object_unref (pixbuf);
- g_free (header);
g_free (escaped);
}
+static void
+chat_window_set_highlight_room_tab_label (EmpathyChat *chat)
+{
+ gchar *markup;
+ GtkWidget *widget;
+
+ if (empathy_chat_is_room (chat) == FALSE)
+ return;
+
+ markup = g_markup_printf_escaped ("<span color=\"%s\">%s</span>",
+ "red",
+ empathy_chat_get_name (chat));
+
+ widget = g_object_get_data (G_OBJECT (chat), "chat-window-tab-label");
+ gtk_label_set_markup (GTK_LABEL (widget), markup);
+ g_free (markup);
+}
+
static void
chat_window_new_message_cb (EmpathyChat *chat,
EmpathyMessage *message,
return;
}
+ if (!g_list_find (priv->chats_new_msg, chat)) {
+ priv->chats_new_msg = g_list_prepend (priv->chats_new_msg, chat);
+ chat_window_update_chat_tab (chat);
+ }
+
/* If empathy_chat_is_room () returns TRUE, that means it's a named MUC.
* If empathy_chat_get_remote_contact () returns NULL, that means it's
* an unamed MUC (msn-like).
}
if (needs_urgency) {
- if (!has_focus)
+ if (!has_focus) {
chat_window_set_urgency_hint (window, TRUE);
+ chat_window_set_highlight_room_tab_label (chat);
+ }
empathy_sound_play (GTK_WIDGET (priv->dialog),
EMPATHY_SOUND_MESSAGE_INCOMING);
chat_window_show_or_update_notification (window, message, chat);
}
-
- if (!g_list_find (priv->chats_new_msg, chat)) {
- priv->chats_new_msg = g_list_prepend (priv->chats_new_msg, chat);
- chat_window_update_chat_tab (chat);
- }
}
static GtkNotebook *
priv->chats_new_msg = g_list_remove (priv->chats_new_msg, priv->current_chat);
chat_window_set_urgency_hint (window, FALSE);
-
+
/* Update the title, since we now mark all unread messages as read. */
chat_window_update_chat_tab (priv->current_chat);
if (info == DND_DRAG_TYPE_CONTACT_ID) {
EmpathyChat *chat;
EmpathyChatWindow *old_window;
- McAccount *account;
+ EmpathyAccount *account;
+ EmpathyAccountManager *account_manager;
const gchar *id;
gchar **strv;
const gchar *account_id;
const gchar *contact_id;
- id = (const gchar*) selection->data;
+ id = (const gchar*) gtk_selection_data_get_data (selection);
+ account_manager = empathy_account_manager_dup_singleton ();
DEBUG ("DND contact from roster with id:'%s'", id);
-
+
strv = g_strsplit (id, "/", 2);
account_id = strv[0];
contact_id = strv[1];
- account = mc_account_lookup (account_id);
+ account = empathy_account_manager_lookup (account_manager, account_id);
chat = empathy_chat_window_find_chat (account, contact_id);
if (!chat) {
- EmpathyAccountManager *account_manager;
TpConnection *connection;
- account_manager = empathy_account_manager_dup_singleton ();
- connection = empathy_account_manager_get_connection (
- account_manager, account);
+ connection = empathy_account_get_connection (account);
if (connection) {
empathy_dispatcher_chat_with_contact_id (
connection, contact_id, NULL, NULL);
}
- g_object_unref (account_manager);
g_object_unref (account);
g_strfreev (strv);
return;
}
g_object_unref (account);
+ g_object_unref (account_manager);
g_strfreev (strv);
- old_window = chat_window_find_chat (chat);
+ old_window = chat_window_find_chat (chat);
if (old_window) {
if (old_window == window) {
gtk_drag_finish (context, TRUE, FALSE, time);
return;
}
-
+
empathy_chat_window_move_chat (old_window, window, chat);
} else {
empathy_chat_window_add_chat (window, chat);
}
-
+
/* Added to take care of any outstanding chat events */
empathy_chat_window_present_chat (chat);
DEBUG ("DND tab");
- chat = (void *) selection->data;
+ chat = (void *) gtk_selection_data_get_data (selection);
old_window = chat_window_find_chat (*chat);
if (old_window) {
gtk_drag_finish (context, TRUE, FALSE, time);
return;
}
-
+
priv->dnd_same_window = FALSE;
}
"ui_manager", &priv->ui_manager,
"menu_conv_insert_smiley", &priv->menu_conv_insert_smiley,
"menu_conv_favorite", &priv->menu_conv_favorite,
+ "menu_conv_toggle_contacts", &priv->menu_conv_toggle_contacts,
"menu_edit_cut", &priv->menu_edit_cut,
"menu_edit_copy", &priv->menu_edit_copy,
"menu_edit_paste", &priv->menu_edit_paste,
"menu_conv", "activate", chat_window_conv_activate_cb,
"menu_conv_clear", "activate", chat_window_clear_activate_cb,
"menu_conv_favorite", "toggled", chat_window_favorite_toggled_cb,
+ "menu_conv_toggle_contacts", "toggled", chat_window_contacts_toggled_cb,
"menu_conv_close", "activate", chat_window_close_activate_cb,
"menu_edit", "activate", chat_window_edit_activate_cb,
"menu_edit_cut", "activate", chat_window_cut_activate_cb,
/* If this window has just been created, position it */
if (priv->chats == NULL) {
empathy_geometry_load (chat_get_window_id_for_geometry (chat), &x, &y, &w, &h);
-
+
if (x >= 0 && y >= 0) {
/* Let the window manager position it if we don't have
* good x, y coordinates.
*/
gtk_window_move (GTK_WINDOW (priv->dialog), x, y);
}
-
+
if (w > 0 && h > 0) {
/* Use the defaults from the ui file if we don't have
* good w, h geometry.
}
EmpathyChat *
-empathy_chat_window_find_chat (McAccount *account,
+empathy_chat_window_find_chat (EmpathyAccount *account,
const gchar *id)
{
GList *l;
- g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL);
g_return_val_if_fail (!EMP_STR_EMPTY (id), NULL);
for (l = chat_windows; l; l = l->next) {