/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Copyright (C) 2002-2007 Imendio AB
- * Copyright (C) 2007-2008 Collabora Ltd.
+ * Copyright (C) 2007-2010 Collabora Ltd.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
#include <libempathy-gtk/empathy-geometry.h>
#include <libempathy-gtk/empathy-gtk-enum-types.h>
#include <libempathy-gtk/empathy-new-message-dialog.h>
+#include <libempathy-gtk/empathy-new-call-dialog.h>
#include <libempathy-gtk/empathy-log-window.h>
#include <libempathy-gtk/empathy-presence-chooser.h>
#include <libempathy-gtk/empathy-sound.h>
#include "empathy-chatrooms-window.h"
#include "empathy-event-manager.h"
#include "empathy-ft-manager.h"
+#include "empathy-migrate-butterfly-logs.h"
#define DEBUG_FLAG EMPATHY_DEBUG_OTHER
#include <libempathy/empathy-debug.h>
guint size_timeout_id;
GHashTable *errors;
+ /* stores a mapping from TpAccount to Handler ID to prevent
+ * to listen more than once to the status-changed signal */
+ GHashTable *status_changed_handlers;
+
/* Actions that are enabled when there are connected accounts */
GList *actions_connected;
+
+ /* The idle event source to migrate butterfly's logs */
+ guint butterfly_log_migration_contact_added_id;
} EmpathyMainWindow;
static EmpathyMainWindow *main_window = NULL;
if (data->on) {
icon_name = data->event->icon_name;
- pixbuf = contact_list_store_get_contact_status_icon_with_icon_name (
- data->window->list_store,
- contact, icon_name);
+ pixbuf = empathy_pixbuf_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
} else {
pixbuf = contact_list_store_get_contact_status_icon (
data->window->list_store,
TpAccount *account;
account = g_object_get_data (G_OBJECT (button), "account");
- empathy_accounts_dialog_show (GTK_WINDOW (window->window), account);
+
+ empathy_accounts_dialog_show_application (
+ gtk_widget_get_screen (GTK_WIDGET (button)),
+ account, FALSE, FALSE);
main_window_remove_error (window, account);
}
GtkWidget *close_button;
GtkWidget *action_area;
GtkWidget *action_table;
- GtkRcStyle *rc_style;
gchar *str;
const gchar *icon_name;
}
info_bar = gtk_info_bar_new ();
- gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
+ gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_ERROR);
gtk_widget_set_no_show_all (info_bar, TRUE);
gtk_box_pack_start (GTK_BOX (window->errors_vbox), info_bar, FALSE, TRUE, 0);
label = gtk_label_new (str);
gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
+ gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
+ gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
gtk_widget_show (label);
g_free (str);
content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
gtk_box_pack_start (GTK_BOX (content_area), image, FALSE, FALSE, 0);
- gtk_box_pack_start (GTK_BOX (content_area), label, FALSE, FALSE, 0);
-
- /* make small style for the buttons */
- rc_style = gtk_rc_style_new ();
- rc_style->xthickness = rc_style->ythickness = 4;
+ gtk_box_pack_start (GTK_BOX (content_area), label, TRUE, TRUE, 0);
image = gtk_image_new_from_stock (GTK_STOCK_REFRESH, GTK_ICON_SIZE_BUTTON);
retry_button = gtk_button_new ();
gtk_button_set_image (GTK_BUTTON (retry_button), image);
- gtk_widget_modify_style (retry_button, rc_style);
gtk_widget_set_tooltip_text (retry_button, _("Reconnect"));
gtk_widget_show (retry_button);
image = gtk_image_new_from_stock (GTK_STOCK_EDIT, GTK_ICON_SIZE_BUTTON);
edit_button = gtk_button_new ();
gtk_button_set_image (GTK_BUTTON (edit_button), image);
- gtk_widget_modify_style (edit_button, rc_style);
gtk_widget_set_tooltip_text (edit_button, _("Edit Account"));
gtk_widget_show (edit_button);
image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_BUTTON);
close_button = gtk_button_new ();
gtk_button_set_image (GTK_BUTTON (close_button), image);
- gtk_widget_modify_style (close_button, rc_style);
gtk_widget_set_tooltip_text (close_button, _("Close"));
gtk_widget_show (close_button);
gtk_widget_show (window->errors_vbox);
- g_object_unref (rc_style);
g_hash_table_insert (window->errors, g_object_ref (account), info_bar);
}
main_window_destroy_cb (GtkWidget *widget,
EmpathyMainWindow *window)
{
+ GHashTableIter iter;
+ gpointer key, value;
+
/* Save user-defined accelerators. */
main_window_accels_save ();
g_object_unref (window->list_store);
g_hash_table_destroy (window->errors);
+ /* disconnect all handlers of status-changed signal */
+ g_hash_table_iter_init (&iter, window->status_changed_handlers);
+ while (g_hash_table_iter_next (&iter, &key, &value))
+ g_signal_handler_disconnect (TP_ACCOUNT (key),
+ GPOINTER_TO_UINT (value));
+
+ g_hash_table_destroy (window->status_changed_handlers);
+
g_signal_handlers_disconnect_by_func (window->event_manager,
main_window_event_added_cb,
window);
window);
g_object_unref (window->event_manager);
g_object_unref (window->ui_manager);
+ g_object_unref (window->chatroom_manager);
g_free (window);
}
empathy_new_message_dialog_show (GTK_WINDOW (window->window));
}
+static void
+main_window_chat_new_call_cb (GtkAction *action,
+ EmpathyMainWindow *window)
+{
+ empathy_new_call_dialog_show (GTK_WINDOW (window->window));
+}
+
static void
main_window_chat_add_contact_cb (GtkAction *action,
EmpathyMainWindow *window)
value == CONTACT_LIST_NORMAL_SIZE_WITH_AVATARS);
empathy_contact_list_store_set_is_compact (window->list_store,
value == CONTACT_LIST_COMPACT_SIZE);
-
- gtk_action_set_sensitive (GTK_ACTION (window->show_protocols),
- value != CONTACT_LIST_COMPACT_SIZE );
}
static void main_window_notify_show_protocols_cb (EmpathyConf *conf,
main_window_edit_accounts_cb (GtkAction *action,
EmpathyMainWindow *window)
{
- empathy_accounts_dialog_show (GTK_WINDOW (window->window), NULL);
+ empathy_accounts_dialog_show_application (gdk_screen_get_default (),
+ NULL, FALSE, FALSE);
}
static void
main_window_help_debug_cb (GtkAction *action,
EmpathyMainWindow *window)
{
- empathy_debug_window_new (NULL);
+ GdkScreen *screen = gdk_screen_get_default ();
+ GError *error = NULL;
+ gchar *argv[2] = { NULL, };
+ gint i = 0;
+ gchar *path;
+
+ g_return_if_fail (GDK_IS_SCREEN (screen));
+
+ /* Try to run from source directory if possible */
+ path = g_build_filename (g_getenv ("EMPATHY_SRCDIR"), "src",
+ "empathy-debugger", NULL);
+
+ if (!g_file_test (path, G_FILE_TEST_EXISTS)) {
+ g_free (path);
+ path = g_build_filename (BIN_DIR, "empathy-debugger", NULL);
+ }
+
+ argv[i++] = path;
+
+ gdk_spawn_on_screen (screen, NULL, argv, NULL,
+ G_SPAWN_SEARCH_PATH,
+ NULL, NULL, NULL, &error);
+
+ if (error) {
+ g_warning ("Failed to open debug window: %s", error->message);
+ g_error_free (error);
+ }
+
+ g_free (path);
}
static void
return FALSE;
}
- empathy_accounts_dialog_show (GTK_WINDOW (window->window), NULL);
+ empathy_accounts_dialog_show_application (
+ gtk_widget_get_screen (GTK_WIDGET (throbber_ebox)),
+ NULL, FALSE, FALSE);
return FALSE;
}
gboolean valid,
EmpathyMainWindow *window)
{
+ if (valid) {
+ gulong handler_id;
+ handler_id = GPOINTER_TO_UINT (g_hash_table_lookup (
+ window->status_changed_handlers, account));
+
+ /* connect signal only if it was not connected yet */
+ if (handler_id == 0) {
+ handler_id = g_signal_connect (account,
+ "status-changed",
+ G_CALLBACK (main_window_connection_changed_cb),
+ window);
+ g_hash_table_insert (window->status_changed_handlers,
+ account, GUINT_TO_POINTER (handler_id));
+ }
+ }
+
main_window_account_removed_cb (manager, account, window);
}
const gchar *actions_connected[] = {
"room",
"chat_new_message",
+ "chat_new_call",
"chat_add_contact",
"edit_personal_information"
};
accounts = tp_account_manager_get_valid_accounts (window->account_manager);
for (j = accounts; j != NULL; j = j->next) {
TpAccount *account = TP_ACCOUNT (j->data);
+ gulong handler_id;
- g_signal_connect (account, "status-changed",
+ handler_id = g_signal_connect (account, "status-changed",
G_CALLBACK (main_window_connection_changed_cb),
window);
+ g_hash_table_insert (window->status_changed_handlers,
+ account, GUINT_TO_POINTER (handler_id));
}
+ g_signal_connect (manager, "account-validity-changed",
+ G_CALLBACK (main_window_account_validity_changed_cb),
+ window);
+
main_window_update_status (window);
/* Disable the "Previous Conversations" menu entry if there is no account */
g_list_free (accounts);
}
+static void
+main_window_contact_added_cb (EmpathyContactMonitor *monitor,
+ EmpathyContact *contact,
+ EmpathyMainWindow *window)
+{
+ if (!empathy_migrate_butterfly_logs (contact)) {
+ g_signal_handler_disconnect (monitor,
+ window->butterfly_log_migration_contact_added_id);
+ window->butterfly_log_migration_contact_added_id = 0;
+ }
+}
+
GtkWidget *
empathy_main_window_show (void)
{
GSList *l;
if (main_window) {
- empathy_window_present (GTK_WINDOW (main_window->window), TRUE);
+ empathy_window_present (GTK_WINDOW (main_window->window));
return main_window->window;
}
"main_window", "destroy", main_window_destroy_cb,
"chat_quit", "activate", main_window_chat_quit_cb,
"chat_new_message", "activate", main_window_chat_new_message_cb,
+ "chat_new_call", "activate", main_window_chat_new_call_cb,
"view_history", "activate", main_window_view_history_cb,
"room_join_new", "activate", main_window_room_join_new_cb,
"room_join_favorites", "activate", main_window_room_join_favorites_cb,
g_object_unref,
NULL);
+ window->status_changed_handlers = g_hash_table_new_full (g_direct_hash,
+ g_direct_equal,
+ NULL,
+ NULL);
+
/* Set up menu */
main_window_favorite_chatroom_menu_setup (window);
EMPATHY_CONTACT_FEATURE_ALL);
g_signal_connect (monitor, "contact-presence-changed",
G_CALLBACK (main_window_contact_presence_changed_cb), window);
+ window->butterfly_log_migration_contact_added_id = g_signal_connect (monitor, "contact-added",
+ G_CALLBACK (main_window_contact_added_cb), window);
g_object_unref (list_iface);
gtk_widget_show (GTK_WIDGET (window->list_view));