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., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301 USA
21 * Authors: Martyn Russell <martyn@imendio.com>
22 * Xavier Claessens <xclaesse@gmail.com>
30 #include <glib/gi18n-lib.h>
33 #include <telepathy-glib/account-manager.h>
35 #include <libempathy/empathy-log-manager.h>
36 #include <libempathy/empathy-chatroom-manager.h>
37 #include <libempathy/empathy-chatroom.h>
38 #include <libempathy/empathy-message.h>
39 #include <libempathy/empathy-utils.h>
40 #include <libempathy/empathy-time.h>
42 #include "empathy-log-window.h"
43 #include "empathy-account-chooser.h"
44 #include "empathy-chat-view.h"
45 #include "empathy-theme-manager.h"
46 #include "empathy-ui-utils.h"
48 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
49 #include <libempathy/empathy-debug.h>
56 GtkWidget *entry_find;
57 GtkWidget *button_find;
58 GtkWidget *treeview_find;
59 GtkWidget *scrolledwindow_find;
60 EmpathyChatView *chatview_find;
61 GtkWidget *button_previous;
62 GtkWidget *button_next;
64 GtkWidget *vbox_chats;
65 GtkWidget *account_chooser_chats;
66 GtkWidget *entry_chats;
67 GtkWidget *calendar_chats;
68 GtkWidget *treeview_chats;
69 GtkWidget *scrolledwindow_chats;
70 EmpathyChatView *chatview_chats;
74 EmpathyLogManager *log_manager;
77 static void log_window_destroy_cb (GtkWidget *widget,
78 EmpathyLogWindow *window);
79 static void log_window_entry_find_changed_cb (GtkWidget *entry,
80 EmpathyLogWindow *window);
81 static void log_window_find_changed_cb (GtkTreeSelection *selection,
82 EmpathyLogWindow *window);
83 static void log_window_find_populate (EmpathyLogWindow *window,
84 const gchar *search_criteria);
85 static void log_window_find_setup (EmpathyLogWindow *window);
86 static void log_window_button_find_clicked_cb (GtkWidget *widget,
87 EmpathyLogWindow *window);
88 static void log_window_button_next_clicked_cb (GtkWidget *widget,
89 EmpathyLogWindow *window);
90 static void log_window_button_previous_clicked_cb (GtkWidget *widget,
91 EmpathyLogWindow *window);
92 static void log_window_chats_changed_cb (GtkTreeSelection *selection,
93 EmpathyLogWindow *window);
94 static void log_window_chats_populate (EmpathyLogWindow *window);
95 static void log_window_chats_setup (EmpathyLogWindow *window);
96 static void log_window_chats_accounts_changed_cb (GtkWidget *combobox,
97 EmpathyLogWindow *window);
98 static void log_window_chats_set_selected (EmpathyLogWindow *window,
100 const gchar *chat_id,
101 gboolean is_chatroom);
102 static gboolean log_window_chats_get_selected (EmpathyLogWindow *window,
105 gboolean *is_chatroom);
106 static void log_window_chats_get_messages (EmpathyLogWindow *window,
107 const gchar *date_to_show);
108 static void log_window_calendar_chats_day_selected_cb (GtkWidget *calendar,
109 EmpathyLogWindow *window);
110 static void log_window_calendar_chats_month_changed_cb (GtkWidget *calendar,
111 EmpathyLogWindow *window);
112 static void log_window_entry_chats_changed_cb (GtkWidget *entry,
113 EmpathyLogWindow *window);
114 static void log_window_entry_chats_activate_cb (GtkWidget *entry,
115 EmpathyLogWindow *window);
118 COL_FIND_ACCOUNT_ICON,
119 COL_FIND_ACCOUNT_NAME,
123 COL_FIND_IS_CHATROOM,
125 COL_FIND_DATE_READABLE,
134 COL_CHAT_IS_CHATROOM,
139 account_manager_prepared_cb (GObject *source_object,
140 GAsyncResult *result,
143 TpAccountManager *account_manager = TP_ACCOUNT_MANAGER (source_object);
144 EmpathyLogWindow *window = user_data;
147 GError *error = NULL;
149 if (!tp_account_manager_prepare_finish (account_manager, result, &error)) {
150 DEBUG ("Failed to prepare account manager: %s", error->message);
151 g_error_free (error);
155 accounts = tp_account_manager_get_valid_accounts (account_manager);
156 account_num = g_list_length (accounts);
157 g_list_free (accounts);
159 if (account_num > 1) {
160 gtk_widget_show (window->vbox_chats);
161 gtk_widget_show (window->account_chooser_chats);
163 gtk_widget_hide (window->vbox_chats);
164 gtk_widget_hide (window->account_chooser_chats);
169 empathy_log_window_show (TpAccount *account,
170 const gchar *chat_id,
171 gboolean is_chatroom,
174 static EmpathyLogWindow *window = NULL;
175 EmpathyAccountChooser *account_chooser;
176 TpAccountManager *account_manager;
181 gtk_window_present (GTK_WINDOW (window->window));
183 if (account && chat_id) {
184 gtk_notebook_set_current_page (GTK_NOTEBOOK (window->notebook), 1);
185 log_window_chats_set_selected (window, account,
186 chat_id, is_chatroom);
189 return window->window;
192 window = g_new0 (EmpathyLogWindow, 1);
193 window->log_manager = empathy_log_manager_dup_singleton ();
195 filename = empathy_file_lookup ("empathy-log-window.ui",
197 gui = empathy_builder_get_file (filename,
198 "log_window", &window->window,
199 "notebook", &window->notebook,
200 "entry_find", &window->entry_find,
201 "button_find", &window->button_find,
202 "treeview_find", &window->treeview_find,
203 "scrolledwindow_find", &window->scrolledwindow_find,
204 "button_previous", &window->button_previous,
205 "button_next", &window->button_next,
206 "entry_chats", &window->entry_chats,
207 "calendar_chats", &window->calendar_chats,
208 "vbox_chats", &window->vbox_chats,
209 "treeview_chats", &window->treeview_chats,
210 "scrolledwindow_chats", &window->scrolledwindow_chats,
214 empathy_builder_connect (gui, window,
215 "log_window", "destroy", log_window_destroy_cb,
216 "entry_find", "changed", log_window_entry_find_changed_cb,
217 "button_previous", "clicked", log_window_button_previous_clicked_cb,
218 "button_next", "clicked", log_window_button_next_clicked_cb,
219 "button_find", "clicked", log_window_button_find_clicked_cb,
220 "entry_chats", "changed", log_window_entry_chats_changed_cb,
221 "entry_chats", "activate", log_window_entry_chats_activate_cb,
224 g_object_unref (gui);
226 g_object_add_weak_pointer (G_OBJECT (window->window),
229 /* We set this up here so we can block it when needed. */
230 g_signal_connect (window->calendar_chats, "day-selected",
231 G_CALLBACK (log_window_calendar_chats_day_selected_cb),
233 g_signal_connect (window->calendar_chats, "month-changed",
234 G_CALLBACK (log_window_calendar_chats_month_changed_cb),
237 /* Configure Search EmpathyChatView */
238 window->chatview_find = empathy_theme_manager_create_view (empathy_theme_manager_get ());
239 gtk_container_add (GTK_CONTAINER (window->scrolledwindow_find),
240 GTK_WIDGET (window->chatview_find));
241 gtk_widget_show (GTK_WIDGET (window->chatview_find));
243 /* Configure Contacts EmpathyChatView */
244 window->chatview_chats = empathy_theme_manager_create_view (empathy_theme_manager_get ());
245 gtk_container_add (GTK_CONTAINER (window->scrolledwindow_chats),
246 GTK_WIDGET (window->chatview_chats));
247 gtk_widget_show (GTK_WIDGET (window->chatview_chats));
249 /* Account chooser for chats */
250 window->account_chooser_chats = empathy_account_chooser_new ();
251 account_chooser = EMPATHY_ACCOUNT_CHOOSER (window->account_chooser_chats);
253 gtk_box_pack_start (GTK_BOX (window->vbox_chats),
254 window->account_chooser_chats,
257 g_signal_connect (window->account_chooser_chats, "changed",
258 G_CALLBACK (log_window_chats_accounts_changed_cb),
262 account_manager = tp_account_manager_dup ();
263 tp_account_manager_prepare_async (account_manager, NULL,
264 account_manager_prepared_cb, window);
265 g_object_unref (account_manager);
268 log_window_find_setup (window);
271 log_window_chats_setup (window);
272 log_window_chats_populate (window);
275 if (account && chat_id) {
276 gtk_notebook_set_current_page (GTK_NOTEBOOK (window->notebook), 1);
277 log_window_chats_set_selected (window, account,
278 chat_id, is_chatroom);
282 gtk_window_set_transient_for (GTK_WINDOW (window->window),
283 GTK_WINDOW (parent));
286 gtk_widget_show (window->window);
288 return window->window;
292 log_window_destroy_cb (GtkWidget *widget,
293 EmpathyLogWindow *window)
295 g_free (window->last_find);
296 g_object_unref (window->log_manager);
305 log_window_entry_find_changed_cb (GtkWidget *entry,
306 EmpathyLogWindow *window)
309 gboolean is_sensitive = TRUE;
311 str = gtk_entry_get_text (GTK_ENTRY (window->entry_find));
313 is_sensitive &= !EMP_STR_EMPTY (str);
315 !window->last_find ||
316 (window->last_find && strcmp (window->last_find, str) != 0);
318 gtk_widget_set_sensitive (window->button_find, is_sensitive);
322 log_window_find_changed_cb (GtkTreeSelection *selection,
323 EmpathyLogWindow *window)
330 gboolean is_chatroom;
332 EmpathyMessage *message;
335 gboolean can_do_previous;
336 gboolean can_do_next;
338 /* Get selected information */
339 view = GTK_TREE_VIEW (window->treeview_find);
340 model = gtk_tree_view_get_model (view);
342 if (!gtk_tree_selection_get_selected (selection, NULL, &iter)) {
343 gtk_widget_set_sensitive (window->button_previous, FALSE);
344 gtk_widget_set_sensitive (window->button_next, FALSE);
346 empathy_chat_view_clear (window->chatview_find);
351 gtk_widget_set_sensitive (window->button_previous, TRUE);
352 gtk_widget_set_sensitive (window->button_next, TRUE);
354 gtk_tree_model_get (model, &iter,
355 COL_FIND_ACCOUNT, &account,
356 COL_FIND_CHAT_ID, &chat_id,
357 COL_FIND_IS_CHATROOM, &is_chatroom,
358 COL_FIND_DATE, &date,
361 /* Clear all current messages shown in the textview */
362 empathy_chat_view_clear (window->chatview_find);
364 /* Turn off scrolling temporarily */
365 empathy_chat_view_scroll (window->chatview_find, FALSE);
368 messages = empathy_log_manager_get_messages_for_date (window->log_manager,
373 g_object_unref (account);
377 for (l = messages; l; l = l->next) {
379 empathy_chat_view_append_message (window->chatview_find, message);
380 g_object_unref (message);
382 g_list_free (messages);
384 /* Scroll to the most recent messages */
385 empathy_chat_view_scroll (window->chatview_find, TRUE);
387 /* Highlight and find messages */
388 empathy_chat_view_highlight (window->chatview_find,
390 empathy_chat_view_find_next (window->chatview_find,
393 empathy_chat_view_find_abilities (window->chatview_find,
397 gtk_widget_set_sensitive (window->button_previous, can_do_previous);
398 gtk_widget_set_sensitive (window->button_next, can_do_next);
399 gtk_widget_set_sensitive (window->button_find, FALSE);
403 log_window_find_populate (EmpathyLogWindow *window,
404 const gchar *search_criteria)
410 GtkTreeSelection *selection;
414 view = GTK_TREE_VIEW (window->treeview_find);
415 model = gtk_tree_view_get_model (view);
416 selection = gtk_tree_view_get_selection (view);
417 store = GTK_LIST_STORE (model);
419 empathy_chat_view_clear (window->chatview_find);
421 gtk_list_store_clear (store);
423 if (EMP_STR_EMPTY (search_criteria)) {
424 /* Just clear the search. */
428 hits = empathy_log_manager_search_new (window->log_manager, search_criteria);
430 for (l = hits; l; l = l->next) {
431 EmpathyLogSearchHit *hit;
432 const gchar *account_name;
433 const gchar *account_icon;
434 gchar *date_readable;
438 /* Protect against invalid data (corrupt or old log files. */
439 if (!hit->account || !hit->chat_id) {
443 date_readable = empathy_log_manager_get_date_readable (hit->date);
444 account_name = tp_account_get_display_name (hit->account);
445 account_icon = tp_account_get_icon_name (hit->account);
447 gtk_list_store_append (store, &iter);
448 gtk_list_store_set (store, &iter,
449 COL_FIND_ACCOUNT_ICON, account_icon,
450 COL_FIND_ACCOUNT_NAME, account_name,
451 COL_FIND_ACCOUNT, hit->account,
452 COL_FIND_CHAT_NAME, hit->chat_id, /* FIXME */
453 COL_FIND_CHAT_ID, hit->chat_id,
454 COL_FIND_IS_CHATROOM, hit->is_chatroom,
455 COL_FIND_DATE, hit->date,
456 COL_FIND_DATE_READABLE, date_readable,
459 g_free (date_readable);
461 /* FIXME: Update COL_FIND_CHAT_NAME */
462 if (hit->is_chatroom) {
468 empathy_log_manager_search_free (hits);
473 log_window_find_setup (EmpathyLogWindow *window)
477 GtkTreeSelection *selection;
478 GtkTreeSortable *sortable;
479 GtkTreeViewColumn *column;
481 GtkCellRenderer *cell;
484 view = GTK_TREE_VIEW (window->treeview_find);
485 selection = gtk_tree_view_get_selection (view);
488 store = gtk_list_store_new (COL_FIND_COUNT,
489 G_TYPE_STRING, /* account icon name */
490 G_TYPE_STRING, /* account name */
491 TP_TYPE_ACCOUNT, /* account */
492 G_TYPE_STRING, /* chat name */
493 G_TYPE_STRING, /* chat id */
494 G_TYPE_BOOLEAN, /* is chatroom */
495 G_TYPE_STRING, /* date */
496 G_TYPE_STRING); /* date_readable */
498 model = GTK_TREE_MODEL (store);
499 sortable = GTK_TREE_SORTABLE (store);
501 gtk_tree_view_set_model (view, model);
504 column = gtk_tree_view_column_new ();
506 cell = gtk_cell_renderer_pixbuf_new ();
507 gtk_tree_view_column_pack_start (column, cell, FALSE);
508 gtk_tree_view_column_add_attribute (column, cell,
510 COL_FIND_ACCOUNT_ICON);
512 cell = gtk_cell_renderer_text_new ();
513 gtk_tree_view_column_pack_start (column, cell, TRUE);
514 gtk_tree_view_column_add_attribute (column, cell,
516 COL_FIND_ACCOUNT_NAME);
518 gtk_tree_view_column_set_title (column, _("Account"));
519 gtk_tree_view_append_column (view, column);
521 gtk_tree_view_column_set_resizable (column, TRUE);
522 gtk_tree_view_column_set_clickable (column, TRUE);
524 cell = gtk_cell_renderer_text_new ();
525 offset = gtk_tree_view_insert_column_with_attributes (view, -1, _("Conversation"),
526 cell, "text", COL_FIND_CHAT_NAME,
529 column = gtk_tree_view_get_column (view, offset - 1);
530 gtk_tree_view_column_set_sort_column_id (column, COL_FIND_CHAT_NAME);
531 gtk_tree_view_column_set_resizable (column, TRUE);
532 gtk_tree_view_column_set_clickable (column, TRUE);
534 cell = gtk_cell_renderer_text_new ();
535 offset = gtk_tree_view_insert_column_with_attributes (view, -1, _("Date"),
536 cell, "text", COL_FIND_DATE_READABLE,
539 column = gtk_tree_view_get_column (view, offset - 1);
540 gtk_tree_view_column_set_sort_column_id (column, COL_FIND_DATE);
541 gtk_tree_view_column_set_resizable (column, TRUE);
542 gtk_tree_view_column_set_clickable (column, TRUE);
544 /* Set up treeview properties */
545 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
546 gtk_tree_sortable_set_sort_column_id (sortable,
551 g_signal_connect (selection, "changed",
552 G_CALLBACK (log_window_find_changed_cb),
555 g_object_unref (store);
559 log_window_button_find_clicked_cb (GtkWidget *widget,
560 EmpathyLogWindow *window)
564 str = gtk_entry_get_text (GTK_ENTRY (window->entry_find));
566 /* Don't find the same crap again */
567 if (window->last_find && strcmp (window->last_find, str) == 0) {
571 g_free (window->last_find);
572 window->last_find = g_strdup (str);
574 log_window_find_populate (window, str);
578 log_window_button_next_clicked_cb (GtkWidget *widget,
579 EmpathyLogWindow *window)
581 if (window->last_find) {
582 gboolean can_do_previous;
583 gboolean can_do_next;
585 empathy_chat_view_find_next (window->chatview_find,
588 empathy_chat_view_find_abilities (window->chatview_find,
592 gtk_widget_set_sensitive (window->button_previous, can_do_previous);
593 gtk_widget_set_sensitive (window->button_next, can_do_next);
598 log_window_button_previous_clicked_cb (GtkWidget *widget,
599 EmpathyLogWindow *window)
601 if (window->last_find) {
602 gboolean can_do_previous;
603 gboolean can_do_next;
605 empathy_chat_view_find_previous (window->chatview_find,
608 empathy_chat_view_find_abilities (window->chatview_find,
612 gtk_widget_set_sensitive (window->button_previous, can_do_previous);
613 gtk_widget_set_sensitive (window->button_next, can_do_next);
622 log_window_chats_changed_cb (GtkTreeSelection *selection,
623 EmpathyLogWindow *window)
625 /* Use last date by default */
626 gtk_calendar_clear_marks (GTK_CALENDAR (window->calendar_chats));
628 log_window_chats_get_messages (window, NULL);
632 log_window_chats_populate (EmpathyLogWindow *window)
634 EmpathyAccountChooser *account_chooser;
640 GtkTreeSelection *selection;
644 account_chooser = EMPATHY_ACCOUNT_CHOOSER (window->account_chooser_chats);
645 account = empathy_account_chooser_dup_account (account_chooser);
647 view = GTK_TREE_VIEW (window->treeview_chats);
648 model = gtk_tree_view_get_model (view);
649 selection = gtk_tree_view_get_selection (view);
650 store = GTK_LIST_STORE (model);
652 if (account == NULL) {
653 gtk_list_store_clear (store);
657 /* Block signals to stop the logs being retrieved prematurely */
658 g_signal_handlers_block_by_func (selection,
659 log_window_chats_changed_cb,
662 gtk_list_store_clear (store);
664 chats = empathy_log_manager_get_chats (window->log_manager, account);
665 for (l = chats; l; l = l->next) {
666 EmpathyLogSearchHit *hit;
670 gtk_list_store_append (store, &iter);
671 gtk_list_store_set (store, &iter,
672 COL_CHAT_ICON, "empathy-available", /* FIXME */
673 COL_CHAT_NAME, hit->chat_id,
674 COL_CHAT_ACCOUNT, account,
675 COL_CHAT_ID, hit->chat_id,
676 COL_CHAT_IS_CHATROOM, hit->is_chatroom,
679 /* FIXME: Update COL_CHAT_ICON/NAME */
680 if (hit->is_chatroom) {
684 empathy_log_manager_search_free (chats);
686 /* Unblock signals */
687 g_signal_handlers_unblock_by_func (selection,
688 log_window_chats_changed_cb,
692 g_object_unref (account);
696 log_window_chats_setup (EmpathyLogWindow *window)
700 GtkTreeSelection *selection;
701 GtkTreeSortable *sortable;
702 GtkTreeViewColumn *column;
704 GtkCellRenderer *cell;
706 view = GTK_TREE_VIEW (window->treeview_chats);
707 selection = gtk_tree_view_get_selection (view);
710 store = gtk_list_store_new (COL_CHAT_COUNT,
711 G_TYPE_STRING, /* icon */
712 G_TYPE_STRING, /* name */
713 TP_TYPE_ACCOUNT, /* account */
714 G_TYPE_STRING, /* id */
715 G_TYPE_BOOLEAN); /* is chatroom */
717 model = GTK_TREE_MODEL (store);
718 sortable = GTK_TREE_SORTABLE (store);
720 gtk_tree_view_set_model (view, model);
723 column = gtk_tree_view_column_new ();
725 cell = gtk_cell_renderer_pixbuf_new ();
726 gtk_tree_view_column_pack_start (column, cell, FALSE);
727 gtk_tree_view_column_add_attribute (column, cell,
731 cell = gtk_cell_renderer_text_new ();
732 g_object_set (cell, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
733 gtk_tree_view_column_pack_start (column, cell, TRUE);
734 gtk_tree_view_column_add_attribute (column, cell,
738 gtk_tree_view_append_column (view, column);
740 /* set up treeview properties */
741 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
742 gtk_tree_sortable_set_sort_column_id (sortable,
747 g_signal_connect (selection, "changed",
748 G_CALLBACK (log_window_chats_changed_cb),
751 g_object_unref (store);
755 log_window_chats_accounts_changed_cb (GtkWidget *combobox,
756 EmpathyLogWindow *window)
758 /* Clear all current messages shown in the textview */
759 empathy_chat_view_clear (window->chatview_chats);
761 log_window_chats_populate (window);
765 log_window_chats_set_selected (EmpathyLogWindow *window,
767 const gchar *chat_id,
768 gboolean is_chatroom)
770 EmpathyAccountChooser *account_chooser;
773 GtkTreeSelection *selection;
778 account_chooser = EMPATHY_ACCOUNT_CHOOSER (window->account_chooser_chats);
779 empathy_account_chooser_set_account (account_chooser, account);
781 view = GTK_TREE_VIEW (window->treeview_chats);
782 model = gtk_tree_view_get_model (view);
783 selection = gtk_tree_view_get_selection (view);
785 if (!gtk_tree_model_get_iter_first (model, &iter)) {
789 for (ok = TRUE; ok; ok = gtk_tree_model_iter_next (model, &iter)) {
790 TpAccount *this_account;
792 gboolean this_is_chatroom;
794 gtk_tree_model_get (model, &iter,
795 COL_CHAT_ACCOUNT, &this_account,
796 COL_CHAT_ID, &this_chat_id,
797 COL_CHAT_IS_CHATROOM, &this_is_chatroom,
800 if (this_account == account &&
801 strcmp (this_chat_id, chat_id) == 0 &&
802 this_is_chatroom == is_chatroom) {
803 gtk_tree_selection_select_iter (selection, &iter);
804 path = gtk_tree_model_get_path (model, &iter);
805 gtk_tree_view_scroll_to_cell (view, path, NULL, TRUE, 0.5, 0.0);
806 gtk_tree_path_free (path);
807 g_object_unref (this_account);
808 g_free (this_chat_id);
812 g_object_unref (this_account);
813 g_free (this_chat_id);
818 log_window_chats_get_selected (EmpathyLogWindow *window,
821 gboolean *is_chatroom)
825 GtkTreeSelection *selection;
828 TpAccount *acc = NULL;
829 gboolean room = FALSE;
831 view = GTK_TREE_VIEW (window->treeview_chats);
832 model = gtk_tree_view_get_model (view);
833 selection = gtk_tree_view_get_selection (view);
835 if (!gtk_tree_selection_get_selected (selection, NULL, &iter)) {
839 gtk_tree_model_get (model, &iter,
840 COL_CHAT_ACCOUNT, &acc,
842 COL_CHAT_IS_CHATROOM, &room,
853 g_object_unref (acc);
863 log_window_chats_get_messages (EmpathyLogWindow *window,
864 const gchar *date_to_show)
868 gboolean is_chatroom;
869 EmpathyMessage *message;
877 guint month_selected;
880 if (!log_window_chats_get_selected (window, &account,
881 &chat_id, &is_chatroom)) {
885 g_signal_handlers_block_by_func (window->calendar_chats,
886 log_window_calendar_chats_day_selected_cb,
889 /* Either use the supplied date or get the last */
892 gboolean day_selected = FALSE;
894 /* Get a list of dates and show them on the calendar */
895 dates = empathy_log_manager_get_dates (window->log_manager,
899 for (l = dates; l; l = l->next) {
907 sscanf (str, "%4d%2d%2d", &year, &month, &day);
908 gtk_calendar_get_date (GTK_CALENDAR (window->calendar_chats),
919 if (year != year_selected || month != month_selected) {
924 DEBUG ("Marking date:'%s'", str);
925 gtk_calendar_mark_day (GTK_CALENDAR (window->calendar_chats), day);
933 gtk_calendar_select_day (GTK_CALENDAR (window->calendar_chats), day);
937 /* Unselect the day in the calendar */
938 gtk_calendar_select_day (GTK_CALENDAR (window->calendar_chats), 0);
941 sscanf (date, "%4d%2d%2d", &year, &month, &day);
942 gtk_calendar_get_date (GTK_CALENDAR (window->calendar_chats),
949 if (year != year_selected && month != month_selected) {
953 gtk_calendar_select_day (GTK_CALENDAR (window->calendar_chats), day);
956 g_signal_handlers_unblock_by_func (window->calendar_chats,
957 log_window_calendar_chats_day_selected_cb,
964 /* Clear all current messages shown in the textview */
965 empathy_chat_view_clear (window->chatview_chats);
967 /* Turn off scrolling temporarily */
968 empathy_chat_view_scroll (window->chatview_find, FALSE);
971 messages = empathy_log_manager_get_messages_for_date (window->log_manager,
976 for (l = messages; l; l = l->next) {
979 empathy_chat_view_append_message (window->chatview_chats,
981 g_object_unref (message);
983 g_list_free (messages);
985 /* Turn back on scrolling */
986 empathy_chat_view_scroll (window->chatview_find, TRUE);
988 /* Give the search entry main focus */
989 gtk_widget_grab_focus (window->entry_chats);
992 g_list_foreach (dates, (GFunc) g_free, NULL);
994 g_object_unref (account);
999 log_window_calendar_chats_day_selected_cb (GtkWidget *calendar,
1000 EmpathyLogWindow *window)
1008 gtk_calendar_get_date (GTK_CALENDAR (calendar), &year, &month, &day);
1010 /* We need this hear because it appears that the months start from 0 */
1013 date = g_strdup_printf ("%4.4d%2.2d%2.2d", year, month, day);
1015 DEBUG ("Currently selected date is:'%s'", date);
1017 log_window_chats_get_messages (window, date);
1023 log_window_calendar_chats_month_changed_cb (GtkWidget *calendar,
1024 EmpathyLogWindow *window)
1028 gboolean is_chatroom;
1029 guint year_selected;
1030 guint month_selected;
1035 gtk_calendar_clear_marks (GTK_CALENDAR (calendar));
1037 if (!log_window_chats_get_selected (window, &account,
1038 &chat_id, &is_chatroom)) {
1039 DEBUG ("No chat selected to get dates for...");
1043 g_object_get (calendar,
1044 "month", &month_selected,
1045 "year", &year_selected,
1048 /* We need this hear because it appears that the months start from 0 */
1051 /* Get the log object for this contact */
1052 dates = empathy_log_manager_get_dates (window->log_manager, account,
1053 chat_id, is_chatroom);
1054 g_object_unref (account);
1057 for (l = dates; l; l = l->next) {
1068 sscanf (str, "%4d%2d%2d", &year, &month, &day);
1070 if (year == year_selected && month == month_selected) {
1071 DEBUG ("Marking date:'%s'", str);
1072 gtk_calendar_mark_day (GTK_CALENDAR (window->calendar_chats), day);
1076 g_list_foreach (dates, (GFunc) g_free, NULL);
1077 g_list_free (dates);
1079 DEBUG ("Currently showing month %d and year %d", month_selected,
1084 log_window_entry_chats_changed_cb (GtkWidget *entry,
1085 EmpathyLogWindow *window)
1089 str = gtk_entry_get_text (GTK_ENTRY (window->entry_chats));
1090 empathy_chat_view_highlight (window->chatview_chats, str);
1093 empathy_chat_view_find_next (window->chatview_chats,
1100 log_window_entry_chats_activate_cb (GtkWidget *entry,
1101 EmpathyLogWindow *window)
1105 str = gtk_entry_get_text (GTK_ENTRY (window->entry_chats));
1108 empathy_chat_view_find_next (window->chatview_chats,