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 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/gossip-chatroom-manager.h>
36 #include <libempathy/gossip-chatroom.h>
37 #include <libempathy/gossip-message.h>
38 #include <libempathy/gossip-debug.h>
39 #include <libempathy/gossip-utils.h>
40 #include <libempathy/gossip-time.h>
42 #include "gossip-log-window.h"
43 #include "gossip-account-chooser.h"
44 #include "gossip-chat-view.h"
45 #include "gossip-ui-utils.h"
47 #define DEBUG_DOMAIN "LogWindow"
54 GtkWidget *entry_find;
55 GtkWidget *button_find;
56 GtkWidget *treeview_find;
57 GtkWidget *scrolledwindow_find;
58 GossipChatView *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 GossipChatView *chatview_chats;
72 EmpathyLogManager *log_manager;
76 log_window_destroy_cb (GtkWidget *widget,
77 GossipLogWindow *window);
79 log_window_entry_find_changed_cb (GtkWidget *entry,
80 GossipLogWindow *window);
82 log_window_find_changed_cb (GtkTreeSelection *selection,
83 GossipLogWindow *window);
85 log_window_find_populate (GossipLogWindow *window,
86 const gchar *search_criteria);
88 log_window_find_setup (GossipLogWindow *window);
90 log_window_button_find_clicked_cb (GtkWidget *widget,
91 GossipLogWindow *window);
93 log_window_button_next_clicked_cb (GtkWidget *widget,
94 GossipLogWindow *window);
96 log_window_button_previous_clicked_cb (GtkWidget *widget,
97 GossipLogWindow *window);
99 log_window_chats_changed_cb (GtkTreeSelection *selection,
100 GossipLogWindow *window);
102 log_window_chats_populate (GossipLogWindow *window);
104 log_window_chats_setup (GossipLogWindow *window);
106 log_window_chats_accounts_changed_cb (GtkWidget *combobox,
107 GossipLogWindow *window);
109 log_window_chats_new_message_cb (GossipContact *own_contact,
110 GossipMessage *message,
111 GossipLogWindow *window);
113 //log_window_chats_is_today_selected (GossipLogWindow *window);
115 log_window_chats_set_selected (GossipLogWindow *window,
117 const gchar *chat_id,
118 gboolean is_chatroom);
120 log_window_chats_get_selected (GossipLogWindow *window,
123 gboolean *is_chatroom);
125 log_window_chats_get_messages (GossipLogWindow *window,
126 const gchar *date_to_show);
128 log_window_calendar_chats_day_selected_cb (GtkWidget *calendar,
129 GossipLogWindow *window);
131 log_window_calendar_chats_month_changed_cb (GtkWidget *calendar,
132 GossipLogWindow *window);
134 log_window_entry_chats_changed_cb (GtkWidget *entry,
135 GossipLogWindow *window);
137 log_window_entry_chats_activate_cb (GtkWidget *entry,
138 GossipLogWindow *window);
141 COL_FIND_ACCOUNT_ICON,
142 COL_FIND_ACCOUNT_NAME,
146 COL_FIND_IS_CHATROOM,
148 COL_FIND_DATE_READABLE,
157 COL_CHAT_IS_CHATROOM,
162 gossip_log_window_show (McAccount *account,
163 const gchar *chat_id,
164 gboolean is_chatroom,
167 static GossipLogWindow *window = NULL;
168 GossipAccountChooser *account_chooser;
174 gtk_window_present (GTK_WINDOW (window->window));
176 if (account && chat_id) {
177 gtk_notebook_set_current_page (GTK_NOTEBOOK (window->notebook), 1);
178 log_window_chats_set_selected (window, account,
179 chat_id, is_chatroom);
185 window = g_new0 (GossipLogWindow, 1);
186 window->log_manager = empathy_log_manager_new ();
188 glade = gossip_glade_get_file ("gossip-log-window.glade",
191 "log_window", &window->window,
192 "notebook", &window->notebook,
193 "entry_find", &window->entry_find,
194 "button_find", &window->button_find,
195 "treeview_find", &window->treeview_find,
196 "scrolledwindow_find", &window->scrolledwindow_find,
197 "button_previous", &window->button_previous,
198 "button_next", &window->button_next,
199 "entry_chats", &window->entry_chats,
200 "calendar_chats", &window->calendar_chats,
201 "vbox_chats", &window->vbox_chats,
202 "treeview_chats", &window->treeview_chats,
203 "scrolledwindow_chats", &window->scrolledwindow_chats,
205 gossip_glade_connect (glade,
207 "log_window", "destroy", log_window_destroy_cb,
208 "entry_find", "changed", log_window_entry_find_changed_cb,
209 "button_previous", "clicked", log_window_button_previous_clicked_cb,
210 "button_next", "clicked", log_window_button_next_clicked_cb,
211 "button_find", "clicked", log_window_button_find_clicked_cb,
212 "entry_chats", "changed", log_window_entry_chats_changed_cb,
213 "entry_chats", "activate", log_window_entry_chats_activate_cb,
216 g_object_unref (glade);
218 g_object_add_weak_pointer (G_OBJECT (window->window),
221 /* We set this up here so we can block it when needed. */
222 g_signal_connect (window->calendar_chats, "day-selected",
223 G_CALLBACK (log_window_calendar_chats_day_selected_cb),
225 g_signal_connect (window->calendar_chats, "month-changed",
226 G_CALLBACK (log_window_calendar_chats_month_changed_cb),
229 /* Configure Search GossipChatView */
230 window->chatview_find = gossip_chat_view_new ();
231 gtk_container_add (GTK_CONTAINER (window->scrolledwindow_find),
232 GTK_WIDGET (window->chatview_find));
233 gtk_widget_show (GTK_WIDGET (window->chatview_find));
235 /* Configure Contacts GossipChatView */
236 window->chatview_chats = gossip_chat_view_new ();
237 gtk_container_add (GTK_CONTAINER (window->scrolledwindow_chats),
238 GTK_WIDGET (window->chatview_chats));
239 gtk_widget_show (GTK_WIDGET (window->chatview_chats));
241 /* Account chooser for chats */
242 window->account_chooser_chats = gossip_account_chooser_new ();
243 account_chooser = GOSSIP_ACCOUNT_CHOOSER (window->account_chooser_chats);
244 gossip_account_chooser_set_can_select_all (account_chooser, TRUE);
246 gtk_box_pack_start (GTK_BOX (window->vbox_chats),
247 window->account_chooser_chats,
250 g_signal_connect (window->account_chooser_chats, "changed",
251 G_CALLBACK (log_window_chats_accounts_changed_cb),
255 accounts = mc_accounts_list ();
256 account_num = g_list_length (accounts);
257 mc_accounts_list_free (accounts);
259 if (account_num > 1) {
260 gtk_widget_show (window->vbox_chats);
261 gtk_widget_show (window->account_chooser_chats);
263 gtk_widget_hide (window->vbox_chats);
264 gtk_widget_hide (window->account_chooser_chats);
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);
290 log_window_destroy_cb (GtkWidget *widget,
291 GossipLogWindow *window)
293 g_signal_handlers_disconnect_by_func (window->log_manager,
294 log_window_chats_new_message_cb,
297 g_free (window->last_find);
298 g_object_unref (window->log_manager);
307 log_window_entry_find_changed_cb (GtkWidget *entry,
308 GossipLogWindow *window)
311 gboolean is_sensitive = TRUE;
313 str = gtk_entry_get_text (GTK_ENTRY (window->entry_find));
315 is_sensitive &= !G_STR_EMPTY (str);
317 !window->last_find ||
318 (window->last_find && strcmp (window->last_find, str) != 0);
320 gtk_widget_set_sensitive (window->button_find, is_sensitive);
324 log_window_find_changed_cb (GtkTreeSelection *selection,
325 GossipLogWindow *window)
332 gboolean is_chatroom;
334 GossipMessage *message;
337 gboolean can_do_previous;
338 gboolean can_do_next;
340 /* Get selected information */
341 view = GTK_TREE_VIEW (window->treeview_find);
342 model = gtk_tree_view_get_model (view);
344 if (!gtk_tree_selection_get_selected (selection, NULL, &iter)) {
345 gtk_widget_set_sensitive (window->button_previous, FALSE);
346 gtk_widget_set_sensitive (window->button_next, FALSE);
348 gossip_chat_view_clear (window->chatview_find);
353 gtk_widget_set_sensitive (window->button_previous, TRUE);
354 gtk_widget_set_sensitive (window->button_next, TRUE);
356 gtk_tree_model_get (model, &iter,
357 COL_FIND_ACCOUNT, &account,
358 COL_FIND_CHAT_ID, &chat_id,
359 COL_FIND_IS_CHATROOM, &is_chatroom,
360 COL_FIND_DATE, &date,
363 /* Clear all current messages shown in the textview */
364 gossip_chat_view_clear (window->chatview_find);
366 /* Turn off scrolling temporarily */
367 gossip_chat_view_scroll (window->chatview_find, FALSE);
370 messages = empathy_log_manager_get_messages_for_date (window->log_manager,
375 g_object_unref (account);
379 for (l = messages; l; l = l->next) {
381 gossip_chat_view_append_message (window->chatview_find, message);
382 g_object_unref (message);
384 g_list_free (messages);
386 /* Scroll to the most recent messages */
387 gossip_chat_view_scroll (window->chatview_find, TRUE);
389 /* Highlight and find messages */
390 gossip_chat_view_highlight (window->chatview_find,
392 gossip_chat_view_find_next (window->chatview_find,
395 gossip_chat_view_find_abilities (window->chatview_find,
399 gtk_widget_set_sensitive (window->button_previous, can_do_previous);
400 gtk_widget_set_sensitive (window->button_next, can_do_next);
401 gtk_widget_set_sensitive (window->button_find, FALSE);
405 log_window_find_populate (GossipLogWindow *window,
406 const gchar *search_criteria)
412 GtkTreeSelection *selection;
416 view = GTK_TREE_VIEW (window->treeview_find);
417 model = gtk_tree_view_get_model (view);
418 selection = gtk_tree_view_get_selection (view);
419 store = GTK_LIST_STORE (model);
421 gossip_chat_view_clear (window->chatview_find);
423 gtk_list_store_clear (store);
425 if (G_STR_EMPTY (search_criteria)) {
426 /* Just clear the search. */
430 hits = empathy_log_manager_search_new (window->log_manager, search_criteria);
432 for (l = hits; l; l = l->next) {
433 EmpathyLogSearchHit *hit;
434 const gchar *account_name;
435 const gchar *account_icon;
436 gchar *date_readable;
440 /* Protect against invalid data (corrupt or old log files. */
441 if (!hit->account || !hit->chat_id) {
445 date_readable = empathy_log_manager_get_date_readable (hit->date);
446 account_name = mc_account_get_display_name (hit->account);
447 account_icon = gossip_icon_name_from_account (hit->account);
449 gtk_list_store_append (store, &iter);
450 gtk_list_store_set (store, &iter,
451 COL_FIND_ACCOUNT_ICON, account_icon,
452 COL_FIND_ACCOUNT_NAME, account_name,
453 COL_FIND_ACCOUNT, hit->account,
454 COL_FIND_CHAT_NAME, hit->chat_id, /* FIXME */
455 COL_FIND_CHAT_ID, hit->chat_id,
456 COL_FIND_IS_CHATROOM, hit->is_chatroom,
457 COL_FIND_DATE, hit->date,
458 COL_FIND_DATE_READABLE, date_readable,
461 g_free (date_readable);
463 /* FIXME: Update COL_FIND_CHAT_NAME */
464 if (hit->is_chatroom) {
470 empathy_log_manager_search_free (hits);
475 log_window_find_setup (GossipLogWindow *window)
479 GtkTreeSelection *selection;
480 GtkTreeSortable *sortable;
481 GtkTreeViewColumn *column;
483 GtkCellRenderer *cell;
486 view = GTK_TREE_VIEW (window->treeview_find);
487 selection = gtk_tree_view_get_selection (view);
490 store = gtk_list_store_new (COL_FIND_COUNT,
491 G_TYPE_STRING, /* account icon name */
492 G_TYPE_STRING, /* account name */
493 MC_TYPE_ACCOUNT, /* account */
494 G_TYPE_STRING, /* chat name */
495 G_TYPE_STRING, /* chat id */
496 G_TYPE_BOOLEAN, /* is chatroom */
497 G_TYPE_STRING, /* date */
498 G_TYPE_STRING); /* date_readable */
500 model = GTK_TREE_MODEL (store);
501 sortable = GTK_TREE_SORTABLE (store);
503 gtk_tree_view_set_model (view, model);
506 column = gtk_tree_view_column_new ();
508 cell = gtk_cell_renderer_pixbuf_new ();
509 gtk_tree_view_column_pack_start (column, cell, FALSE);
510 gtk_tree_view_column_add_attribute (column, cell,
512 COL_FIND_ACCOUNT_ICON);
514 cell = gtk_cell_renderer_text_new ();
515 gtk_tree_view_column_pack_start (column, cell, TRUE);
516 gtk_tree_view_column_add_attribute (column, cell,
518 COL_FIND_ACCOUNT_NAME);
520 gtk_tree_view_column_set_title (column, _("Account"));
521 gtk_tree_view_append_column (view, column);
523 gtk_tree_view_column_set_resizable (column, TRUE);
524 gtk_tree_view_column_set_clickable (column, TRUE);
526 cell = gtk_cell_renderer_text_new ();
527 offset = gtk_tree_view_insert_column_with_attributes (view, -1, _("Conversation"),
528 cell, "text", COL_FIND_CHAT_NAME,
531 column = gtk_tree_view_get_column (view, offset - 1);
532 gtk_tree_view_column_set_sort_column_id (column, COL_FIND_CHAT_NAME);
533 gtk_tree_view_column_set_resizable (column, TRUE);
534 gtk_tree_view_column_set_clickable (column, TRUE);
536 cell = gtk_cell_renderer_text_new ();
537 offset = gtk_tree_view_insert_column_with_attributes (view, -1, _("Date"),
538 cell, "text", COL_FIND_DATE_READABLE,
541 column = gtk_tree_view_get_column (view, offset - 1);
542 gtk_tree_view_column_set_sort_column_id (column, COL_FIND_DATE);
543 gtk_tree_view_column_set_resizable (column, TRUE);
544 gtk_tree_view_column_set_clickable (column, TRUE);
546 /* Set up treeview properties */
547 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
548 gtk_tree_sortable_set_sort_column_id (sortable,
553 g_signal_connect (selection, "changed",
554 G_CALLBACK (log_window_find_changed_cb),
557 g_object_unref (store);
561 log_window_button_find_clicked_cb (GtkWidget *widget,
562 GossipLogWindow *window)
566 str = gtk_entry_get_text (GTK_ENTRY (window->entry_find));
568 /* Don't find the same crap again */
569 if (window->last_find && strcmp (window->last_find, str) == 0) {
573 g_free (window->last_find);
574 window->last_find = g_strdup (str);
576 log_window_find_populate (window, str);
580 log_window_button_next_clicked_cb (GtkWidget *widget,
581 GossipLogWindow *window)
583 if (window->last_find) {
584 gboolean can_do_previous;
585 gboolean can_do_next;
587 gossip_chat_view_find_next (window->chatview_find,
590 gossip_chat_view_find_abilities (window->chatview_find,
594 gtk_widget_set_sensitive (window->button_previous, can_do_previous);
595 gtk_widget_set_sensitive (window->button_next, can_do_next);
600 log_window_button_previous_clicked_cb (GtkWidget *widget,
601 GossipLogWindow *window)
603 if (window->last_find) {
604 gboolean can_do_previous;
605 gboolean can_do_next;
607 gossip_chat_view_find_previous (window->chatview_find,
610 gossip_chat_view_find_abilities (window->chatview_find,
614 gtk_widget_set_sensitive (window->button_previous, can_do_previous);
615 gtk_widget_set_sensitive (window->button_next, can_do_next);
624 log_window_chats_changed_cb (GtkTreeSelection *selection,
625 GossipLogWindow *window)
627 /* Use last date by default */
628 gtk_calendar_clear_marks (GTK_CALENDAR (window->calendar_chats));
630 log_window_chats_get_messages (window, NULL);
634 log_window_chats_populate (GossipLogWindow *window)
636 GossipAccountChooser *account_chooser;
642 GtkTreeSelection *selection;
646 account_chooser = GOSSIP_ACCOUNT_CHOOSER (window->account_chooser_chats);
647 account = gossip_account_chooser_get_account (account_chooser);
649 view = GTK_TREE_VIEW (window->treeview_chats);
650 model = gtk_tree_view_get_model (view);
651 selection = gtk_tree_view_get_selection (view);
652 store = GTK_LIST_STORE (model);
654 /* Block signals to stop the logs being retrieved prematurely */
655 g_signal_handlers_block_by_func (selection,
656 log_window_chats_changed_cb,
659 gtk_list_store_clear (store);
661 chats = empathy_log_manager_get_chats (window->log_manager, account);
662 for (l = chats; l; l = l->next) {
663 EmpathyLogSearchHit *hit;
667 gtk_list_store_append (store, &iter);
668 gtk_list_store_set (store, &iter,
669 COL_CHAT_ICON, "empathy-available",
670 COL_CHAT_NAME, hit->chat_id,
671 COL_CHAT_ACCOUNT, account,
672 COL_CHAT_ID, hit->chat_id,
673 COL_CHAT_IS_CHATROOM, hit->is_chatroom,
676 /* FIXME: Update COL_CHAT_ICON/NAME */
677 if (hit->is_chatroom) {
681 empathy_log_manager_search_free (chats);
683 /* Unblock signals */
684 g_signal_handlers_unblock_by_func (selection,
685 log_window_chats_changed_cb,
689 g_object_unref (account);
693 log_window_chats_setup (GossipLogWindow *window)
697 GtkTreeSelection *selection;
698 GtkTreeSortable *sortable;
699 GtkTreeViewColumn *column;
701 GtkCellRenderer *cell;
703 view = GTK_TREE_VIEW (window->treeview_chats);
704 selection = gtk_tree_view_get_selection (view);
707 store = gtk_list_store_new (COL_CHAT_COUNT,
708 G_TYPE_STRING, /* icon */
709 G_TYPE_STRING, /* name */
710 MC_TYPE_ACCOUNT, /* account */
711 G_TYPE_STRING, /* id */
712 G_TYPE_BOOLEAN); /* is chatroom */
714 model = GTK_TREE_MODEL (store);
715 sortable = GTK_TREE_SORTABLE (store);
717 gtk_tree_view_set_model (view, model);
720 column = gtk_tree_view_column_new ();
722 cell = gtk_cell_renderer_pixbuf_new ();
723 gtk_tree_view_column_pack_start (column, cell, FALSE);
724 gtk_tree_view_column_add_attribute (column, cell,
728 cell = gtk_cell_renderer_text_new ();
729 g_object_set (cell, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
730 gtk_tree_view_column_pack_start (column, cell, TRUE);
731 gtk_tree_view_column_add_attribute (column, cell,
735 gtk_tree_view_append_column (view, column);
737 /* set up treeview properties */
738 gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
739 gtk_tree_sortable_set_sort_column_id (sortable,
744 g_signal_connect (selection, "changed",
745 G_CALLBACK (log_window_chats_changed_cb),
748 g_object_unref (store);
752 log_window_chats_accounts_changed_cb (GtkWidget *combobox,
753 GossipLogWindow *window)
755 /* Clear all current messages shown in the textview */
756 gossip_chat_view_clear (window->chatview_chats);
758 log_window_chats_populate (window);
762 log_window_chats_new_message_cb (GossipContact *own_contact,
763 GossipMessage *message,
764 GossipLogWindow *window)
766 gossip_chat_view_append_message (window->chatview_chats, message);
768 /* Scroll to the most recent messages */
769 gossip_chat_view_scroll_down (window->chatview_chats);
774 log_window_chats_is_today_selected (GossipLogWindow *window)
781 guint month_selected;
786 t = gossip_time_get_current ();
787 timestamp = gossip_time_to_string_local (t, "%Y%m%d");
789 sscanf (timestamp, "%4d%2d%2d", &year, &month, &day);
791 gtk_calendar_get_date (GTK_CALENDAR (window->calendar_chats),
796 /* Hack since this starts at 0 */
799 selected = (day_selected == day &&
800 month_selected == month &&
801 year_selected == year);
810 log_window_chats_set_selected (GossipLogWindow *window,
812 const gchar *chat_id,
813 gboolean is_chatroom)
817 GtkTreeSelection *selection;
822 view = GTK_TREE_VIEW (window->treeview_chats);
823 model = gtk_tree_view_get_model (view);
824 selection = gtk_tree_view_get_selection (view);
826 if (!gtk_tree_model_get_iter_first (model, &iter)) {
830 for (ok = TRUE; ok; ok = gtk_tree_model_iter_next (model, &iter)) {
831 McAccount *this_account;
833 gboolean this_is_chatroom;
835 gtk_tree_model_get (model, &iter,
836 COL_CHAT_ACCOUNT, &this_account,
837 COL_CHAT_ID, &this_chat_id,
838 COL_CHAT_IS_CHATROOM, &this_is_chatroom,
841 if (gossip_account_equal (this_account, account) &&
842 strcmp (this_chat_id, chat_id) == 0 &&
843 this_is_chatroom == is_chatroom) {
844 gtk_tree_selection_select_iter (selection, &iter);
845 path = gtk_tree_model_get_path (model, &iter);
846 gtk_tree_view_scroll_to_cell (view, path, NULL, TRUE, 0.5, 0.0);
847 gtk_tree_path_free (path);
848 g_object_unref (this_account);
849 g_free (this_chat_id);
853 g_object_unref (this_account);
854 g_free (this_chat_id);
859 log_window_chats_get_selected (GossipLogWindow *window,
862 gboolean *is_chatroom)
866 GtkTreeSelection *selection;
869 McAccount *acc = NULL;
870 gboolean room = FALSE;
872 view = GTK_TREE_VIEW (window->treeview_chats);
873 model = gtk_tree_view_get_model (view);
874 selection = gtk_tree_view_get_selection (view);
876 if (!gtk_tree_selection_get_selected (selection, NULL, &iter)) {
880 gtk_tree_model_get (model, &iter,
881 COL_CHAT_ACCOUNT, &acc,
883 COL_CHAT_IS_CHATROOM, &room,
894 g_object_unref (acc);
904 log_window_chats_get_messages (GossipLogWindow *window,
905 const gchar *date_to_show)
909 gboolean is_chatroom;
910 GossipMessage *message;
918 guint month_selected;
921 if (!log_window_chats_get_selected (window, &account,
922 &chat_id, &is_chatroom)) {
926 g_signal_handlers_block_by_func (window->calendar_chats,
927 log_window_calendar_chats_day_selected_cb,
930 /* Either use the supplied date or get the last */
933 gboolean day_selected = FALSE;
935 /* Get a list of dates and show them on the calendar */
936 dates = empathy_log_manager_get_dates (window->log_manager,
940 for (l = dates; l; l = l->next) {
948 sscanf (str, "%4d%2d%2d", &year, &month, &day);
949 gtk_calendar_get_date (GTK_CALENDAR (window->calendar_chats),
960 if (year != year_selected || month != month_selected) {
965 gossip_debug (DEBUG_DOMAIN, "Marking date:'%s'", str);
966 gtk_calendar_mark_day (GTK_CALENDAR (window->calendar_chats), day);
974 gtk_calendar_select_day (GTK_CALENDAR (window->calendar_chats), day);
978 /* Unselect the day in the calendar */
979 gtk_calendar_select_day (GTK_CALENDAR (window->calendar_chats), 0);
982 sscanf (date, "%4d%2d%2d", &year, &month, &day);
983 gtk_calendar_get_date (GTK_CALENDAR (window->calendar_chats),
990 if (year != year_selected && month != month_selected) {
994 gtk_calendar_select_day (GTK_CALENDAR (window->calendar_chats), day);
996 g_signal_handlers_unblock_by_func (window->calendar_chats,
997 log_window_calendar_chats_day_selected_cb,
1000 /* Clear all current messages shown in the textview */
1001 gossip_chat_view_clear (window->chatview_chats);
1003 /* Turn off scrolling temporarily */
1004 gossip_chat_view_scroll (window->chatview_find, FALSE);
1007 messages = empathy_log_manager_get_messages_for_date (window->log_manager,
1012 for (l = messages; l; l = l->next) {
1015 gossip_chat_view_append_message (window->chatview_chats,
1017 g_object_unref (message);
1019 g_list_free (messages);
1021 g_list_foreach (dates, (GFunc) g_free, NULL);
1022 g_list_free (dates);
1024 g_object_unref (account);
1027 /* Turn back on scrolling */
1028 gossip_chat_view_scroll (window->chatview_find, TRUE);
1030 /* Scroll to the most recent messages */
1031 gossip_chat_view_scroll_down (window->chatview_chats);
1033 /* Give the search entry main focus */
1034 gtk_widget_grab_focus (window->entry_chats);
1038 log_window_calendar_chats_day_selected_cb (GtkWidget *calendar,
1039 GossipLogWindow *window)
1047 gtk_calendar_get_date (GTK_CALENDAR (calendar), &year, &month, &day);
1049 /* We need this hear because it appears that the months start from 0 */
1052 date = g_strdup_printf ("%4.4d%2.2d%2.2d", year, month, day);
1054 gossip_debug (DEBUG_DOMAIN, "Currently selected date is:'%s'", date);
1056 log_window_chats_get_messages (window, date);
1062 log_window_calendar_chats_month_changed_cb (GtkWidget *calendar,
1063 GossipLogWindow *window)
1067 gboolean is_chatroom;
1068 guint year_selected;
1069 guint month_selected;
1074 gtk_calendar_clear_marks (GTK_CALENDAR (calendar));
1076 if (!log_window_chats_get_selected (window, &account,
1077 &chat_id, &is_chatroom)) {
1078 gossip_debug (DEBUG_DOMAIN, "No chat selected to get dates for...");
1082 g_object_get (calendar,
1083 "month", &month_selected,
1084 "year", &year_selected,
1087 /* We need this hear because it appears that the months start from 0 */
1090 /* Get the log object for this contact */
1091 dates = empathy_log_manager_get_dates (window->log_manager, account,
1092 chat_id, is_chatroom);
1093 g_object_unref (account);
1096 for (l = dates; l; l = l->next) {
1107 sscanf (str, "%4d%2d%2d", &year, &month, &day);
1109 if (year == year_selected && month == month_selected) {
1110 gossip_debug (DEBUG_DOMAIN, "Marking date:'%s'", str);
1111 gtk_calendar_mark_day (GTK_CALENDAR (window->calendar_chats), day);
1115 g_list_foreach (dates, (GFunc) g_free, NULL);
1116 g_list_free (dates);
1118 gossip_debug (DEBUG_DOMAIN,
1119 "Currently showing month %d and year %d",
1120 month_selected, year_selected);
1124 log_window_entry_chats_changed_cb (GtkWidget *entry,
1125 GossipLogWindow *window)
1129 str = gtk_entry_get_text (GTK_ENTRY (window->entry_chats));
1130 gossip_chat_view_highlight (window->chatview_chats, str);
1133 gossip_chat_view_find_next (window->chatview_chats,
1140 log_window_entry_chats_activate_cb (GtkWidget *entry,
1141 GossipLogWindow *window)
1145 str = gtk_entry_get_text (GTK_ENTRY (window->entry_chats));
1148 gossip_chat_view_find_next (window->chatview_chats,