1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2006-2007 Imendio AB
4 * Copyright (C) 2007-2008 Collabora Ltd.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
21 * Authors: Martyn Russell <martyn@imendio.com>
22 * Xavier Claessens <xclaesse@gmail.com>
30 #include <glib/gi18n.h>
32 #include <glade/glade.h>
34 #include <libempathy/empathy-log-manager.h>
35 #include <libempathy/empathy-chatroom-manager.h>
36 #include <libempathy/empathy-chatroom.h>
37 #include <libempathy/empathy-message.h>
38 #include <libempathy/empathy-utils.h>
39 #include <libempathy/empathy-time.h>
41 #include "empathy-log-window.h"
42 #include "empathy-account-chooser.h"
43 #include "empathy-chat-view.h"
44 #include "empathy-ui-utils.h"
46 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
47 #include <libempathy/empathy-debug.h>
54 GtkWidget *entry_find;
55 GtkWidget *button_find;
56 GtkWidget *treeview_find;
57 GtkWidget *scrolledwindow_find;
58 EmpathyChatView *chatview_find;
59 GtkWidget *button_previous;
60 GtkWidget *button_next;
62 GtkWidget *vbox_chats;
63 GtkWidget *account_chooser_chats;
64 GtkWidget *entry_chats;
65 GtkWidget *calendar_chats;
66 GtkWidget *treeview_chats;
67 GtkWidget *scrolledwindow_chats;
68 EmpathyChatView *chatview_chats;
72 EmpathyLogManager *log_manager;
75 static void log_window_destroy_cb (GtkWidget *widget,
76 EmpathyLogWindow *window);
77 static void log_window_entry_find_changed_cb (GtkWidget *entry,
78 EmpathyLogWindow *window);
79 static void log_window_find_changed_cb (GtkTreeSelection *selection,
80 EmpathyLogWindow *window);
81 static void log_window_find_populate (EmpathyLogWindow *window,
82 const gchar *search_criteria);
83 static void log_window_find_setup (EmpathyLogWindow *window);
84 static void log_window_button_find_clicked_cb (GtkWidget *widget,
85 EmpathyLogWindow *window);
86 static void log_window_button_next_clicked_cb (GtkWidget *widget,
87 EmpathyLogWindow *window);
88 static void log_window_button_previous_clicked_cb (GtkWidget *widget,
89 EmpathyLogWindow *window);
90 static void log_window_chats_changed_cb (GtkTreeSelection *selection,
91 EmpathyLogWindow *window);
92 static void log_window_chats_populate (EmpathyLogWindow *window);
93 static void log_window_chats_setup (EmpathyLogWindow *window);
94 static void log_window_chats_accounts_changed_cb (GtkWidget *combobox,
95 EmpathyLogWindow *window);
96 static void log_window_chats_set_selected (EmpathyLogWindow *window,
99 gboolean is_chatroom);
100 static gboolean log_window_chats_get_selected (EmpathyLogWindow *window,
103 gboolean *is_chatroom);
104 static void log_window_chats_get_messages (EmpathyLogWindow *window,
105 const gchar *date_to_show);
106 static void log_window_calendar_chats_day_selected_cb (GtkWidget *calendar,
107 EmpathyLogWindow *window);
108 static void log_window_calendar_chats_month_changed_cb (GtkWidget *calendar,
109 EmpathyLogWindow *window);
110 static void log_window_entry_chats_changed_cb (GtkWidget *entry,
111 EmpathyLogWindow *window);
112 static void log_window_entry_chats_activate_cb (GtkWidget *entry,
113 EmpathyLogWindow *window);
116 COL_FIND_ACCOUNT_ICON,
117 COL_FIND_ACCOUNT_NAME,
121 COL_FIND_IS_CHATROOM,
123 COL_FIND_DATE_READABLE,
132 COL_CHAT_IS_CHATROOM,
137 empathy_log_window_show (McAccount *account,
138 const gchar *chat_id,
139 gboolean is_chatroom,
142 static EmpathyLogWindow *window = NULL;
143 EmpathyAccountChooser *account_chooser;
150 gtk_window_present (GTK_WINDOW (window->window));
152 if (account && chat_id) {
153 gtk_notebook_set_current_page (GTK_NOTEBOOK (window->notebook), 1);
154 log_window_chats_set_selected (window, account,
155 chat_id, is_chatroom);
158 return window->window;
161 window = g_new0 (EmpathyLogWindow, 1);
162 window->log_manager = empathy_log_manager_new ();
164 filename = empathy_file_lookup ("empathy-log-window.glade",
166 glade = empathy_glade_get_file (filename,
169 "log_window", &window->window,
170 "notebook", &window->notebook,
171 "entry_find", &window->entry_find,
172 "button_find", &window->button_find,
173 "treeview_find", &window->treeview_find,
174 "scrolledwindow_find", &window->scrolledwindow_find,
175 "button_previous", &window->button_previous,
176 "button_next", &window->button_next,
177 "entry_chats", &window->entry_chats,
178 "calendar_chats", &window->calendar_chats,
179 "vbox_chats", &window->vbox_chats,
180 "treeview_chats", &window->treeview_chats,
181 "scrolledwindow_chats", &window->scrolledwindow_chats,
185 empathy_glade_connect (glade,
187 "log_window", "destroy", log_window_destroy_cb,
188 "entry_find", "changed", log_window_entry_find_changed_cb,
189 "button_previous", "clicked", log_window_button_previous_clicked_cb,
190 "button_next", "clicked", log_window_button_next_clicked_cb,
191 "button_find", "clicked", log_window_button_find_clicked_cb,
192 "entry_chats", "changed", log_window_entry_chats_changed_cb,
193 "entry_chats", "activate", log_window_entry_chats_activate_cb,
196 g_object_unref (glade);
198 g_object_add_weak_pointer (G_OBJECT (window->window),
201 /* We set this up here so we can block it when needed. */
202 g_signal_connect (window->calendar_chats, "day-selected",
203 G_CALLBACK (log_window_calendar_chats_day_selected_cb),
205 g_signal_connect (window->calendar_chats, "month-changed",
206 G_CALLBACK (log_window_calendar_chats_month_changed_cb),
209 /* Configure Search EmpathyChatView */
210 window->chatview_find = empathy_chat_view_new ();
211 gtk_container_add (GTK_CONTAINER (window->scrolledwindow_find),
212 GTK_WIDGET (window->chatview_find));
213 gtk_widget_show (GTK_WIDGET (window->chatview_find));
215 /* Configure Contacts EmpathyChatView */
216 window->chatview_chats = empathy_chat_view_new ();
217 gtk_container_add (GTK_CONTAINER (window->scrolledwindow_chats),
218 GTK_WIDGET (window->chatview_chats));
219 gtk_widget_show (GTK_WIDGET (window->chatview_chats));
221 /* Account chooser for chats */
222 window->account_chooser_chats = empathy_account_chooser_new ();
223 account_chooser = EMPATHY_ACCOUNT_CHOOSER (window->account_chooser_chats);
225 gtk_box_pack_start (GTK_BOX (window->vbox_chats),
226 window->account_chooser_chats,
229 g_signal_connect (window->account_chooser_chats, "changed",
230 G_CALLBACK (log_window_chats_accounts_changed_cb),
234 accounts = mc_accounts_list ();
235 account_num = g_list_length (accounts);
236 mc_accounts_list_free (accounts);
238 if (account_num > 1) {
239 gtk_widget_show (window->vbox_chats);
240 gtk_widget_show (window->account_chooser_chats);
242 gtk_widget_hide (window->vbox_chats);
243 gtk_widget_hide (window->account_chooser_chats);
247 log_window_find_setup (window);
250 log_window_chats_setup (window);
251 log_window_chats_populate (window);
254 if (account && chat_id) {
255 gtk_notebook_set_current_page (GTK_NOTEBOOK (window->notebook), 1);
256 log_window_chats_set_selected (window, account,
257 chat_id, is_chatroom);
261 gtk_window_set_transient_for (GTK_WINDOW (window->window),
262 GTK_WINDOW (parent));
265 gtk_widget_show (window->window);
267 return window->window;
271 log_window_destroy_cb (GtkWidget *widget,
272 EmpathyLogWindow *window)
274 g_free (window->last_find);
275 g_object_unref (window->log_manager);
284 log_window_entry_find_changed_cb (GtkWidget *entry,
285 EmpathyLogWindow *window)
288 gboolean is_sensitive = TRUE;
290 str = gtk_entry_get_text (GTK_ENTRY (window->entry_find));
292 is_sensitive &= !G_STR_EMPTY (str);
294 !window->last_find ||
295 (window->last_find && strcmp (window->last_find, str) != 0);
297 gtk_widget_set_sensitive (window->button_find, is_sensitive);
301 log_window_find_changed_cb (GtkTreeSelection *selection,
302 EmpathyLogWindow *window)
309 gboolean is_chatroom;
311 EmpathyMessage *message;
314 gboolean can_do_previous;
315 gboolean can_do_next;
317 /* Get selected information */
318 view = GTK_TREE_VIEW (window->treeview_find);
319 model = gtk_tree_view_get_model (view);
321 if (!gtk_tree_selection_get_selected (selection, NULL, &iter)) {
322 gtk_widget_set_sensitive (window->button_previous, FALSE);
323 gtk_widget_set_sensitive (window->button_next, FALSE);
325 empathy_chat_view_clear (window->chatview_find);
330 gtk_widget_set_sensitive (window->button_previous, TRUE);
331 gtk_widget_set_sensitive (window->button_next, TRUE);
333 gtk_tree_model_get (model, &iter,
334 COL_FIND_ACCOUNT, &account,
335 COL_FIND_CHAT_ID, &chat_id,
336 COL_FIND_IS_CHATROOM, &is_chatroom,
337 COL_FIND_DATE, &date,
340 /* Clear all current messages shown in the textview */
341 empathy_chat_view_clear (window->chatview_find);
343 /* Turn off scrolling temporarily */
344 empathy_chat_view_scroll (window->chatview_find, FALSE);
347 messages = empathy_log_manager_get_messages_for_date (window->log_manager,
352 g_object_unref (account);
356 for (l = messages; l; l = l->next) {
358 empathy_chat_view_append_message (window->chatview_find, message);
359 g_object_unref (message);
361 g_list_free (messages);
363 /* Scroll to the most recent messages */
364 empathy_chat_view_scroll (window->chatview_find, TRUE);
366 /* Highlight and find messages */
367 empathy_chat_view_highlight (window->chatview_find,
369 empathy_chat_view_find_next (window->chatview_find,
372 empathy_chat_view_find_abilities (window->chatview_find,
376 gtk_widget_set_sensitive (window->button_previous, can_do_previous);
377 gtk_widget_set_sensitive (window->button_next, can_do_next);
378 gtk_widget_set_sensitive (window->button_find, FALSE);
382 log_window_find_populate (EmpathyLogWindow *window,
383 const gchar *search_criteria)
389 GtkTreeSelection *selection;
393 view = GTK_TREE_VIEW (window->treeview_find);
394 model = gtk_tree_view_get_model (view);
395 selection = gtk_tree_view_get_selection (view);
396 store = GTK_LIST_STORE (model);
398 empathy_chat_view_clear (window->chatview_find);
400 gtk_list_store_clear (store);
402 if (G_STR_EMPTY (search_criteria)) {
403 /* Just clear the search. */
407 hits = empathy_log_manager_search_new (window->log_manager, search_criteria);
409 for (l = hits; l; l = l->next) {
410 EmpathyLogSearchHit *hit;
411 const gchar *account_name;
412 const gchar *account_icon;
413 gchar *date_readable;
417 /* Protect against invalid data (corrupt or old log files. */
418 if (!hit->account || !hit->chat_id) {
422 date_readable = empathy_log_manager_get_date_readable (hit->date);
423 account_name = mc_account_get_display_name (hit->account);
424 account_icon = empathy_icon_name_from_account (hit->account);
426 gtk_list_store_append (store, &iter);
427 gtk_list_store_set (store, &iter,
428 COL_FIND_ACCOUNT_ICON, account_icon,
429 COL_FIND_ACCOUNT_NAME, account_name,
430 COL_FIND_ACCOUNT, hit->account,
431 COL_FIND_CHAT_NAME, hit->chat_id, /* FIXME */
432 COL_FIND_CHAT_ID, hit->chat_id,
433 COL_FIND_IS_CHATROOM, hit->is_chatroom,
434 COL_FIND_DATE, hit->date,
435 COL_FIND_DATE_READABLE, date_readable,
438 g_free (date_readable);
440 /* FIXME: Update COL_FIND_CHAT_NAME */
441 if (hit->is_chatroom) {
447 empathy_log_manager_search_free (hits);
452 log_window_find_setup (EmpathyLogWindow *window)
456 GtkTreeSelection *selection;
457 GtkTreeSortable *sortable;
458 GtkTreeViewColumn *column;
460 GtkCellRenderer *cell;
463 view = GTK_TREE_VIEW (window->treeview_find);
464 selection = gtk_tree_view_get_selection (view);
467 store = gtk_list_store_new (COL_FIND_COUNT,
468 G_TYPE_STRING, /* account icon name */
469 G_TYPE_STRING, /* account name */
470 MC_TYPE_ACCOUNT, /* account */
471 G_TYPE_STRING, /* chat name */
472 G_TYPE_STRING, /* chat id */
473 G_TYPE_BOOLEAN, /* is chatroom */
474 G_TYPE_STRING, /* date */
475 G_TYPE_STRING); /* date_readable */
477 model = GTK_TREE_MODEL (store);
478 sortable = GTK_TREE_SORTABLE (store);
480 gtk_tree_view_set_model (view, model);
483 column = gtk_tree_view_column_new ();
485 cell = gtk_cell_renderer_pixbuf_new ();
486 gtk_tree_view_column_pack_start (column, cell, FALSE);
487 gtk_tree_view_column_add_attribute (column, cell,
489 COL_FIND_ACCOUNT_ICON);
491 cell = gtk_cell_renderer_text_new ();
492 gtk_tree_view_column_pack_start (column, cell, TRUE);
493 gtk_tree_view_column_add_attribute (column, cell,
495 COL_FIND_ACCOUNT_NAME);
497 gtk_tree_view_column_set_title (column, _("Account"));
498 gtk_tree_view_append_column (view, column);
500 gtk_tree_view_column_set_resizable (column, TRUE);
501 gtk_tree_view_column_set_clickable (column, TRUE);
503 cell = gtk_cell_renderer_text_new ();
504 offset = gtk_tree_view_insert_column_with_attributes (view, -1, _("Conversation"),
505 cell, "text", COL_FIND_CHAT_NAME,
508 column = gtk_tree_view_get_column (view, offset - 1);
509 gtk_tree_view_column_set_sort_column_id (column, COL_FIND_CHAT_NAME);
510 gtk_tree_view_column_set_resizable (column, TRUE);
511 gtk_tree_view_column_set_clickable (column, TRUE);
513 cell = gtk_cell_renderer_text_new ();
514 offset = gtk_tree_view_insert_column_with_attributes (view, -1, _("Date"),
515 cell, "text", COL_FIND_DATE_READABLE,
518 column = gtk_tree_view_get_column (view, offset - 1);
519 gtk_tree_view_column_set_sort_column_id (column, COL_FIND_DATE);
520 gtk_tree_view_column_set_resizable (column, TRUE);
521 gtk_tree_view_column_set_clickable (column, TRUE);
523 /* Set up treeview properties */
524 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
525 gtk_tree_sortable_set_sort_column_id (sortable,
530 g_signal_connect (selection, "changed",
531 G_CALLBACK (log_window_find_changed_cb),
534 g_object_unref (store);
538 log_window_button_find_clicked_cb (GtkWidget *widget,
539 EmpathyLogWindow *window)
543 str = gtk_entry_get_text (GTK_ENTRY (window->entry_find));
545 /* Don't find the same crap again */
546 if (window->last_find && strcmp (window->last_find, str) == 0) {
550 g_free (window->last_find);
551 window->last_find = g_strdup (str);
553 log_window_find_populate (window, str);
557 log_window_button_next_clicked_cb (GtkWidget *widget,
558 EmpathyLogWindow *window)
560 if (window->last_find) {
561 gboolean can_do_previous;
562 gboolean can_do_next;
564 empathy_chat_view_find_next (window->chatview_find,
567 empathy_chat_view_find_abilities (window->chatview_find,
571 gtk_widget_set_sensitive (window->button_previous, can_do_previous);
572 gtk_widget_set_sensitive (window->button_next, can_do_next);
577 log_window_button_previous_clicked_cb (GtkWidget *widget,
578 EmpathyLogWindow *window)
580 if (window->last_find) {
581 gboolean can_do_previous;
582 gboolean can_do_next;
584 empathy_chat_view_find_previous (window->chatview_find,
587 empathy_chat_view_find_abilities (window->chatview_find,
591 gtk_widget_set_sensitive (window->button_previous, can_do_previous);
592 gtk_widget_set_sensitive (window->button_next, can_do_next);
601 log_window_chats_changed_cb (GtkTreeSelection *selection,
602 EmpathyLogWindow *window)
604 /* Use last date by default */
605 gtk_calendar_clear_marks (GTK_CALENDAR (window->calendar_chats));
607 log_window_chats_get_messages (window, NULL);
611 log_window_chats_populate (EmpathyLogWindow *window)
613 EmpathyAccountChooser *account_chooser;
619 GtkTreeSelection *selection;
623 account_chooser = EMPATHY_ACCOUNT_CHOOSER (window->account_chooser_chats);
624 account = empathy_account_chooser_get_account (account_chooser);
626 view = GTK_TREE_VIEW (window->treeview_chats);
627 model = gtk_tree_view_get_model (view);
628 selection = gtk_tree_view_get_selection (view);
629 store = GTK_LIST_STORE (model);
631 /* Block signals to stop the logs being retrieved prematurely */
632 g_signal_handlers_block_by_func (selection,
633 log_window_chats_changed_cb,
636 gtk_list_store_clear (store);
638 chats = empathy_log_manager_get_chats (window->log_manager, account);
639 for (l = chats; l; l = l->next) {
640 EmpathyLogSearchHit *hit;
644 gtk_list_store_append (store, &iter);
645 gtk_list_store_set (store, &iter,
646 COL_CHAT_ICON, "empathy-available", /* FIXME */
647 COL_CHAT_NAME, hit->chat_id,
648 COL_CHAT_ACCOUNT, account,
649 COL_CHAT_ID, hit->chat_id,
650 COL_CHAT_IS_CHATROOM, hit->is_chatroom,
653 /* FIXME: Update COL_CHAT_ICON/NAME */
654 if (hit->is_chatroom) {
658 empathy_log_manager_search_free (chats);
660 /* Unblock signals */
661 g_signal_handlers_unblock_by_func (selection,
662 log_window_chats_changed_cb,
666 g_object_unref (account);
670 log_window_chats_setup (EmpathyLogWindow *window)
674 GtkTreeSelection *selection;
675 GtkTreeSortable *sortable;
676 GtkTreeViewColumn *column;
678 GtkCellRenderer *cell;
680 view = GTK_TREE_VIEW (window->treeview_chats);
681 selection = gtk_tree_view_get_selection (view);
684 store = gtk_list_store_new (COL_CHAT_COUNT,
685 G_TYPE_STRING, /* icon */
686 G_TYPE_STRING, /* name */
687 MC_TYPE_ACCOUNT, /* account */
688 G_TYPE_STRING, /* id */
689 G_TYPE_BOOLEAN); /* is chatroom */
691 model = GTK_TREE_MODEL (store);
692 sortable = GTK_TREE_SORTABLE (store);
694 gtk_tree_view_set_model (view, model);
697 column = gtk_tree_view_column_new ();
699 cell = gtk_cell_renderer_pixbuf_new ();
700 gtk_tree_view_column_pack_start (column, cell, FALSE);
701 gtk_tree_view_column_add_attribute (column, cell,
705 cell = gtk_cell_renderer_text_new ();
706 g_object_set (cell, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
707 gtk_tree_view_column_pack_start (column, cell, TRUE);
708 gtk_tree_view_column_add_attribute (column, cell,
712 gtk_tree_view_append_column (view, column);
714 /* set up treeview properties */
715 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
716 gtk_tree_sortable_set_sort_column_id (sortable,
721 g_signal_connect (selection, "changed",
722 G_CALLBACK (log_window_chats_changed_cb),
725 g_object_unref (store);
729 log_window_chats_accounts_changed_cb (GtkWidget *combobox,
730 EmpathyLogWindow *window)
732 /* Clear all current messages shown in the textview */
733 empathy_chat_view_clear (window->chatview_chats);
735 log_window_chats_populate (window);
739 log_window_chats_set_selected (EmpathyLogWindow *window,
741 const gchar *chat_id,
742 gboolean is_chatroom)
744 EmpathyAccountChooser *account_chooser;
747 GtkTreeSelection *selection;
752 account_chooser = EMPATHY_ACCOUNT_CHOOSER (window->account_chooser_chats);
753 empathy_account_chooser_set_account (account_chooser, account);
755 view = GTK_TREE_VIEW (window->treeview_chats);
756 model = gtk_tree_view_get_model (view);
757 selection = gtk_tree_view_get_selection (view);
759 if (!gtk_tree_model_get_iter_first (model, &iter)) {
763 for (ok = TRUE; ok; ok = gtk_tree_model_iter_next (model, &iter)) {
764 McAccount *this_account;
766 gboolean this_is_chatroom;
768 gtk_tree_model_get (model, &iter,
769 COL_CHAT_ACCOUNT, &this_account,
770 COL_CHAT_ID, &this_chat_id,
771 COL_CHAT_IS_CHATROOM, &this_is_chatroom,
774 if (empathy_account_equal (this_account, account) &&
775 strcmp (this_chat_id, chat_id) == 0 &&
776 this_is_chatroom == is_chatroom) {
777 gtk_tree_selection_select_iter (selection, &iter);
778 path = gtk_tree_model_get_path (model, &iter);
779 gtk_tree_view_scroll_to_cell (view, path, NULL, TRUE, 0.5, 0.0);
780 gtk_tree_path_free (path);
781 g_object_unref (this_account);
782 g_free (this_chat_id);
786 g_object_unref (this_account);
787 g_free (this_chat_id);
792 log_window_chats_get_selected (EmpathyLogWindow *window,
795 gboolean *is_chatroom)
799 GtkTreeSelection *selection;
802 McAccount *acc = NULL;
803 gboolean room = FALSE;
805 view = GTK_TREE_VIEW (window->treeview_chats);
806 model = gtk_tree_view_get_model (view);
807 selection = gtk_tree_view_get_selection (view);
809 if (!gtk_tree_selection_get_selected (selection, NULL, &iter)) {
813 gtk_tree_model_get (model, &iter,
814 COL_CHAT_ACCOUNT, &acc,
816 COL_CHAT_IS_CHATROOM, &room,
827 g_object_unref (acc);
837 log_window_chats_get_messages (EmpathyLogWindow *window,
838 const gchar *date_to_show)
842 gboolean is_chatroom;
843 EmpathyMessage *message;
851 guint month_selected;
854 if (!log_window_chats_get_selected (window, &account,
855 &chat_id, &is_chatroom)) {
859 g_signal_handlers_block_by_func (window->calendar_chats,
860 log_window_calendar_chats_day_selected_cb,
863 /* Either use the supplied date or get the last */
866 gboolean day_selected = FALSE;
868 /* Get a list of dates and show them on the calendar */
869 dates = empathy_log_manager_get_dates (window->log_manager,
873 for (l = dates; l; l = l->next) {
881 sscanf (str, "%4d%2d%2d", &year, &month, &day);
882 gtk_calendar_get_date (GTK_CALENDAR (window->calendar_chats),
893 if (year != year_selected || month != month_selected) {
898 DEBUG ("Marking date:'%s'", str);
899 gtk_calendar_mark_day (GTK_CALENDAR (window->calendar_chats), day);
907 gtk_calendar_select_day (GTK_CALENDAR (window->calendar_chats), day);
911 /* Unselect the day in the calendar */
912 gtk_calendar_select_day (GTK_CALENDAR (window->calendar_chats), 0);
915 sscanf (date, "%4d%2d%2d", &year, &month, &day);
916 gtk_calendar_get_date (GTK_CALENDAR (window->calendar_chats),
923 if (year != year_selected && month != month_selected) {
927 gtk_calendar_select_day (GTK_CALENDAR (window->calendar_chats), day);
930 g_signal_handlers_unblock_by_func (window->calendar_chats,
931 log_window_calendar_chats_day_selected_cb,
938 /* Clear all current messages shown in the textview */
939 empathy_chat_view_clear (window->chatview_chats);
941 /* Turn off scrolling temporarily */
942 empathy_chat_view_scroll (window->chatview_find, FALSE);
945 messages = empathy_log_manager_get_messages_for_date (window->log_manager,
950 for (l = messages; l; l = l->next) {
953 empathy_chat_view_append_message (window->chatview_chats,
955 g_object_unref (message);
957 g_list_free (messages);
959 /* Turn back on scrolling */
960 empathy_chat_view_scroll (window->chatview_find, TRUE);
962 /* Give the search entry main focus */
963 gtk_widget_grab_focus (window->entry_chats);
966 g_list_foreach (dates, (GFunc) g_free, NULL);
968 g_object_unref (account);
973 log_window_calendar_chats_day_selected_cb (GtkWidget *calendar,
974 EmpathyLogWindow *window)
982 gtk_calendar_get_date (GTK_CALENDAR (calendar), &year, &month, &day);
984 /* We need this hear because it appears that the months start from 0 */
987 date = g_strdup_printf ("%4.4d%2.2d%2.2d", year, month, day);
989 DEBUG ("Currently selected date is:'%s'", date);
991 log_window_chats_get_messages (window, date);
997 log_window_calendar_chats_month_changed_cb (GtkWidget *calendar,
998 EmpathyLogWindow *window)
1002 gboolean is_chatroom;
1003 guint year_selected;
1004 guint month_selected;
1009 gtk_calendar_clear_marks (GTK_CALENDAR (calendar));
1011 if (!log_window_chats_get_selected (window, &account,
1012 &chat_id, &is_chatroom)) {
1013 DEBUG ("No chat selected to get dates for...");
1017 g_object_get (calendar,
1018 "month", &month_selected,
1019 "year", &year_selected,
1022 /* We need this hear because it appears that the months start from 0 */
1025 /* Get the log object for this contact */
1026 dates = empathy_log_manager_get_dates (window->log_manager, account,
1027 chat_id, is_chatroom);
1028 g_object_unref (account);
1031 for (l = dates; l; l = l->next) {
1042 sscanf (str, "%4d%2d%2d", &year, &month, &day);
1044 if (year == year_selected && month == month_selected) {
1045 DEBUG ("Marking date:'%s'", str);
1046 gtk_calendar_mark_day (GTK_CALENDAR (window->calendar_chats), day);
1050 g_list_foreach (dates, (GFunc) g_free, NULL);
1051 g_list_free (dates);
1053 DEBUG ("Currently showing month %d and year %d", month_selected,
1058 log_window_entry_chats_changed_cb (GtkWidget *entry,
1059 EmpathyLogWindow *window)
1063 str = gtk_entry_get_text (GTK_ENTRY (window->entry_chats));
1064 empathy_chat_view_highlight (window->chatview_chats, str);
1067 empathy_chat_view_find_next (window->chatview_chats,
1074 log_window_entry_chats_activate_cb (GtkWidget *entry,
1075 EmpathyLogWindow *window)
1079 str = gtk_entry_get_text (GTK_ENTRY (window->entry_chats));
1082 empathy_chat_view_find_next (window->chatview_chats,