]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-log-window.c
Updated Basque language
[empathy.git] / libempathy-gtk / empathy-log-window.c
index c239ef5c368bcf99780a5c3565aefc0994a8250b..11ddca74b97d54aea390fece059eac019ae10b47 100644 (file)
@@ -15,9 +15,9 @@
  *
  * You should have received a copy of the GNU General Public
  * License along with this program; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- * 
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA  02110-1301  USA
+ *
  * Authors: Martyn Russell <martyn@imendio.com>
  *          Xavier Claessens <xclaesse@gmail.com>
  */
 #include <string.h>
 #include <stdlib.h>
 
-#include <glib/gi18n.h>
+#include <glib/gi18n-lib.h>
 #include <gtk/gtk.h>
-#include <glade/glade.h>
 
 #include <libempathy/empathy-log-manager.h>
+#include <libempathy/empathy-account-manager.h>
 #include <libempathy/empathy-chatroom-manager.h>
 #include <libempathy/empathy-chatroom.h>
 #include <libempathy/empathy-message.h>
-#include <libempathy/empathy-debug.h>
 #include <libempathy/empathy-utils.h>
 #include <libempathy/empathy-time.h>
 
 #include "empathy-log-window.h"
 #include "empathy-account-chooser.h"
 #include "empathy-chat-view.h"
+#include "empathy-theme-manager.h"
 #include "empathy-ui-utils.h"
 
-#define DEBUG_DOMAIN "LogWindow"
+#define DEBUG_FLAG EMPATHY_DEBUG_OTHER
+#include <libempathy/empathy-debug.h>
 
 typedef struct {
        GtkWidget         *window;
@@ -93,15 +94,12 @@ static void     log_window_chats_populate                  (EmpathyLogWindow *wi
 static void     log_window_chats_setup                     (EmpathyLogWindow *window);
 static void     log_window_chats_accounts_changed_cb       (GtkWidget        *combobox,
                                                            EmpathyLogWindow *window);
-static void     log_window_chats_new_message_cb            (EmpathyContact   *own_contact,
-                                                           EmpathyMessage   *message,
-                                                           EmpathyLogWindow *window);
 static void     log_window_chats_set_selected              (EmpathyLogWindow *window,
-                                                           McAccount        *account,
+                                                           EmpathyAccount   *account,
                                                            const gchar      *chat_id,
                                                            gboolean          is_chatroom);
 static gboolean log_window_chats_get_selected              (EmpathyLogWindow *window,
-                                                           McAccount       **account,
+                                                           EmpathyAccount  **account,
                                                            gchar           **chat_id,
                                                            gboolean         *is_chatroom);
 static void     log_window_chats_get_messages              (EmpathyLogWindow *window,
@@ -137,16 +135,17 @@ enum {
 };
 
 GtkWidget *
-empathy_log_window_show (McAccount   *account,
+empathy_log_window_show (EmpathyAccount   *account,
                        const gchar *chat_id,
                        gboolean     is_chatroom,
                        GtkWindow   *parent)
 {
        static EmpathyLogWindow *window = NULL;
        EmpathyAccountChooser   *account_chooser;
-       GList                  *accounts;
+       EmpathyAccountManager  *account_manager;
        gint                    account_num;
-       GladeXML               *glade;
+       GtkBuilder             *gui;
+       gchar                  *filename;
 
        if (window) {
                gtk_window_present (GTK_WINDOW (window->window));
@@ -161,11 +160,11 @@ empathy_log_window_show (McAccount   *account,
        }
 
        window = g_new0 (EmpathyLogWindow, 1);
-       window->log_manager = empathy_log_manager_new ();
+       window->log_manager = empathy_log_manager_dup_singleton ();
 
-       glade = empathy_glade_get_file ("empathy-log-window.glade",
-                                      "log_window",
-                                      NULL,
+       filename = empathy_file_lookup ("empathy-log-window.ui",
+                                       "libempathy-gtk");
+       gui = empathy_builder_get_file (filename,
                                       "log_window", &window->window,
                                       "notebook", &window->notebook,
                                       "entry_find", &window->entry_find,
@@ -180,8 +179,9 @@ empathy_log_window_show (McAccount   *account,
                                       "treeview_chats", &window->treeview_chats,
                                       "scrolledwindow_chats", &window->scrolledwindow_chats,
                                       NULL);
-       empathy_glade_connect (glade,
-                             window,
+       g_free (filename);
+
+       empathy_builder_connect (gui, window,
                              "log_window", "destroy", log_window_destroy_cb,
                              "entry_find", "changed", log_window_entry_find_changed_cb,
                              "button_previous", "clicked", log_window_button_previous_clicked_cb,
@@ -191,7 +191,7 @@ empathy_log_window_show (McAccount   *account,
                              "entry_chats", "activate", log_window_entry_chats_activate_cb,
                              NULL);
 
-       g_object_unref (glade);
+       g_object_unref (gui);
 
        g_object_add_weak_pointer (G_OBJECT (window->window),
                                   (gpointer) &window);
@@ -205,13 +205,13 @@ empathy_log_window_show (McAccount   *account,
                          window);
 
        /* Configure Search EmpathyChatView */
-       window->chatview_find = empathy_chat_view_new ();
+       window->chatview_find = empathy_theme_manager_create_view (empathy_theme_manager_get ());
        gtk_container_add (GTK_CONTAINER (window->scrolledwindow_find),
                           GTK_WIDGET (window->chatview_find));
        gtk_widget_show (GTK_WIDGET (window->chatview_find));
 
        /* Configure Contacts EmpathyChatView */
-       window->chatview_chats = empathy_chat_view_new ();
+       window->chatview_chats = empathy_theme_manager_create_view (empathy_theme_manager_get ());
        gtk_container_add (GTK_CONTAINER (window->scrolledwindow_chats),
                           GTK_WIDGET (window->chatview_chats));
        gtk_widget_show (GTK_WIDGET (window->chatview_chats));
@@ -229,9 +229,9 @@ empathy_log_window_show (McAccount   *account,
                          window);
 
        /* Populate */
-       accounts = mc_accounts_list ();
-       account_num = g_list_length (accounts);
-       mc_accounts_list_free (accounts);
+       account_manager = empathy_account_manager_dup_singleton ();
+       account_num = empathy_account_manager_get_count (account_manager);
+       g_object_unref (account_manager);
 
        if (account_num > 1) {
                gtk_widget_show (window->vbox_chats);
@@ -269,10 +269,6 @@ static void
 log_window_destroy_cb (GtkWidget       *widget,
                       EmpathyLogWindow *window)
 {
-       g_signal_handlers_disconnect_by_func (window->log_manager,
-                                             log_window_chats_new_message_cb,
-                                             window);
-
        g_free (window->last_find);
        g_object_unref (window->log_manager);
 
@@ -291,9 +287,9 @@ log_window_entry_find_changed_cb (GtkWidget       *entry,
 
        str = gtk_entry_get_text (GTK_ENTRY (window->entry_find));
 
-       is_sensitive &= !G_STR_EMPTY (str);
-       is_sensitive &= 
-               !window->last_find || 
+       is_sensitive &= !EMP_STR_EMPTY (str);
+       is_sensitive &=
+               !window->last_find ||
                (window->last_find && strcmp (window->last_find, str) != 0);
 
        gtk_widget_set_sensitive (window->button_find, is_sensitive);
@@ -306,7 +302,7 @@ log_window_find_changed_cb (GtkTreeSelection *selection,
        GtkTreeView   *view;
        GtkTreeModel  *model;
        GtkTreeIter    iter;
-       McAccount     *account;
+       EmpathyAccount     *account;
        gchar         *chat_id;
        gboolean       is_chatroom;
        gchar         *date;
@@ -325,7 +321,7 @@ log_window_find_changed_cb (GtkTreeSelection *selection,
                gtk_widget_set_sensitive (window->button_next, FALSE);
 
                empathy_chat_view_clear (window->chatview_find);
-       
+
                return;
        }
 
@@ -401,7 +397,7 @@ log_window_find_populate (EmpathyLogWindow *window,
 
        gtk_list_store_clear (store);
 
-       if (G_STR_EMPTY (search_criteria)) {
+       if (EMP_STR_EMPTY (search_criteria)) {
                /* Just clear the search. */
                return;
        }
@@ -422,8 +418,8 @@ log_window_find_populate (EmpathyLogWindow *window,
                }
 
                date_readable = empathy_log_manager_get_date_readable (hit->date);
-               account_name = mc_account_get_display_name (hit->account);
-               account_icon = empathy_icon_name_from_account (hit->account);
+               account_name = empathy_account_get_display_name (hit->account);
+               account_icon = empathy_account_get_icon_name (hit->account);
 
                gtk_list_store_append (store, &iter);
                gtk_list_store_set (store, &iter,
@@ -469,7 +465,7 @@ log_window_find_setup (EmpathyLogWindow *window)
        store = gtk_list_store_new (COL_FIND_COUNT,
                                    G_TYPE_STRING,          /* account icon name */
                                    G_TYPE_STRING,          /* account name */
-                                   MC_TYPE_ACCOUNT,        /* account */
+                                   EMPATHY_TYPE_ACCOUNT,   /* account */
                                    G_TYPE_STRING,          /* chat name */
                                    G_TYPE_STRING,          /* chat id */
                                    G_TYPE_BOOLEAN,         /* is chatroom */
@@ -613,7 +609,7 @@ static void
 log_window_chats_populate (EmpathyLogWindow *window)
 {
        EmpathyAccountChooser *account_chooser;
-       McAccount            *account;
+       EmpathyAccount       *account;
        GList                *chats, *l;
 
        GtkTreeView          *view;
@@ -623,13 +619,18 @@ log_window_chats_populate (EmpathyLogWindow *window)
        GtkTreeIter           iter;
 
        account_chooser = EMPATHY_ACCOUNT_CHOOSER (window->account_chooser_chats);
-       account = empathy_account_chooser_get_account (account_chooser);
+       account = empathy_account_chooser_dup_account (account_chooser);
 
        view = GTK_TREE_VIEW (window->treeview_chats);
        model = gtk_tree_view_get_model (view);
        selection = gtk_tree_view_get_selection (view);
        store = GTK_LIST_STORE (model);
 
+       if (account == NULL) {
+               gtk_list_store_clear (store);
+               return;
+       }
+
        /* Block signals to stop the logs being retrieved prematurely */
        g_signal_handlers_block_by_func (selection,
                                         log_window_chats_changed_cb,
@@ -646,7 +647,7 @@ log_window_chats_populate (EmpathyLogWindow *window)
                gtk_list_store_append (store, &iter);
                gtk_list_store_set (store, &iter,
                                    COL_CHAT_ICON, "empathy-available", /* FIXME */
-                                   COL_CHAT_NAME, hit->chat_id,                                
+                                   COL_CHAT_NAME, hit->chat_id,
                                    COL_CHAT_ACCOUNT, account,
                                    COL_CHAT_ID, hit->chat_id,
                                    COL_CHAT_IS_CHATROOM, hit->is_chatroom,
@@ -684,11 +685,11 @@ log_window_chats_setup (EmpathyLogWindow *window)
 
        /* new store */
        store = gtk_list_store_new (COL_CHAT_COUNT,
-                                   G_TYPE_STRING,    /* icon */
-                                   G_TYPE_STRING,    /* name */
-                                   MC_TYPE_ACCOUNT,  /* account */
-                                   G_TYPE_STRING,    /* id */
-                                   G_TYPE_BOOLEAN);  /* is chatroom */
+                                   G_TYPE_STRING,        /* icon */
+                                   G_TYPE_STRING,        /* name */
+                                   EMPATHY_TYPE_ACCOUNT, /* account */
+                                   G_TYPE_STRING,        /* id */
+                                   G_TYPE_BOOLEAN);      /* is chatroom */
 
        model = GTK_TREE_MODEL (store);
        sortable = GTK_TREE_SORTABLE (store);
@@ -737,20 +738,9 @@ log_window_chats_accounts_changed_cb (GtkWidget       *combobox,
        log_window_chats_populate (window);
 }
 
-static void
-log_window_chats_new_message_cb (EmpathyContact   *own_contact,
-                                EmpathyMessage   *message,
-                                EmpathyLogWindow *window)
-{
-       empathy_chat_view_append_message (window->chatview_chats, message);
-
-       /* Scroll to the most recent messages */
-       empathy_chat_view_scroll_down (window->chatview_chats);
-}
-
 static void
 log_window_chats_set_selected  (EmpathyLogWindow *window,
-                               McAccount       *account,
+                               EmpathyAccount  *account,
                                const gchar     *chat_id,
                                gboolean         is_chatroom)
 {
@@ -774,7 +764,7 @@ log_window_chats_set_selected  (EmpathyLogWindow *window,
        }
 
        for (ok = TRUE; ok; ok = gtk_tree_model_iter_next (model, &iter)) {
-               McAccount *this_account;
+               EmpathyAccount *this_account;
                gchar     *this_chat_id;
                gboolean   this_is_chatroom;
 
@@ -784,7 +774,7 @@ log_window_chats_set_selected  (EmpathyLogWindow *window,
                                    COL_CHAT_IS_CHATROOM, &this_is_chatroom,
                                    -1);
 
-               if (empathy_account_equal (this_account, account) &&
+               if (this_account == account &&
                    strcmp (this_chat_id, chat_id) == 0 &&
                    this_is_chatroom == is_chatroom) {
                        gtk_tree_selection_select_iter (selection, &iter);
@@ -803,7 +793,7 @@ log_window_chats_set_selected  (EmpathyLogWindow *window,
 
 static gboolean
 log_window_chats_get_selected (EmpathyLogWindow  *window,
-                              McAccount       **account,
+                              EmpathyAccount  **account,
                               gchar           **chat_id,
                               gboolean         *is_chatroom)
 {
@@ -812,7 +802,7 @@ log_window_chats_get_selected (EmpathyLogWindow  *window,
        GtkTreeSelection *selection;
        GtkTreeIter       iter;
        gchar            *id = NULL;
-       McAccount        *acc = NULL;
+       EmpathyAccount   *acc = NULL;
        gboolean          room = FALSE;
 
        view = GTK_TREE_VIEW (window->treeview_chats);
@@ -850,7 +840,7 @@ static void
 log_window_chats_get_messages (EmpathyLogWindow *window,
                               const gchar     *date_to_show)
 {
-       McAccount     *account;
+       EmpathyAccount     *account;
        gchar         *chat_id;
        gboolean       is_chatroom;
        EmpathyMessage *message;
@@ -908,7 +898,7 @@ log_window_chats_get_messages (EmpathyLogWindow *window,
                        }
 
 
-                       empathy_debug (DEBUG_DOMAIN, "Marking date:'%s'", str);
+                       DEBUG ("Marking date:'%s'", str);
                        gtk_calendar_mark_day (GTK_CALENDAR (window->calendar_chats), day);
 
                        if (l->next) {
@@ -972,9 +962,6 @@ log_window_chats_get_messages (EmpathyLogWindow *window,
        /* Turn back on scrolling */
        empathy_chat_view_scroll (window->chatview_find, TRUE);
 
-       /* Scroll to the most recent messages */
-       empathy_chat_view_scroll_down (window->chatview_chats);
-
        /* Give the search entry main focus */
        gtk_widget_grab_focus (window->entry_chats);
 
@@ -1002,7 +989,7 @@ log_window_calendar_chats_day_selected_cb (GtkWidget       *calendar,
 
        date = g_strdup_printf ("%4.4d%2.2d%2.2d", year, month, day);
 
-       empathy_debug (DEBUG_DOMAIN, "Currently selected date is:'%s'", date);
+       DEBUG ("Currently selected date is:'%s'", date);
 
        log_window_chats_get_messages (window, date);
 
@@ -1013,7 +1000,7 @@ static void
 log_window_calendar_chats_month_changed_cb (GtkWidget       *calendar,
                                            EmpathyLogWindow *window)
 {
-       McAccount     *account;
+       EmpathyAccount     *account;
        gchar         *chat_id;
        gboolean       is_chatroom;
        guint          year_selected;
@@ -1026,7 +1013,7 @@ log_window_calendar_chats_month_changed_cb (GtkWidget       *calendar,
 
        if (!log_window_chats_get_selected (window, &account,
                                            &chat_id, &is_chatroom)) {
-               empathy_debug (DEBUG_DOMAIN, "No chat selected to get dates for...");
+               DEBUG ("No chat selected to get dates for...");
                return;
        }
 
@@ -1058,7 +1045,7 @@ log_window_calendar_chats_month_changed_cb (GtkWidget       *calendar,
                sscanf (str, "%4d%2d%2d", &year, &month, &day);
 
                if (year == year_selected && month == month_selected) {
-                       empathy_debug (DEBUG_DOMAIN, "Marking date:'%s'", str);
+                       DEBUG ("Marking date:'%s'", str);
                        gtk_calendar_mark_day (GTK_CALENDAR (window->calendar_chats), day);
                }
        }
@@ -1066,9 +1053,8 @@ log_window_calendar_chats_month_changed_cb (GtkWidget       *calendar,
        g_list_foreach (dates, (GFunc) g_free, NULL);
        g_list_free (dates);
 
-       empathy_debug (DEBUG_DOMAIN,
-                     "Currently showing month %d and year %d",
-                     month_selected, year_selected);
+       DEBUG ("Currently showing month %d and year %d", month_selected,
+               year_selected);
 }
 
 static void