2 * Copyright (C) 2006-2007 Imendio AB
3 * Copyright (C) 2007-2011 Collabora Ltd.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301 USA
20 * Authors: Martyn Russell <martyn@imendio.com>
21 * Xavier Claessens <xclaesse@gmail.com>
22 * Emilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk>
26 #include "empathy-log-window.h"
28 #include <glib/gi18n-lib.h>
29 #include <telepathy-glib/proxy-subclass.h>
30 #include <tp-account-widgets/tpaw-builder.h>
31 #include <tp-account-widgets/tpaw-images.h>
32 #include <tp-account-widgets/tpaw-camera-monitor.h>
33 #include <tp-account-widgets/tpaw-utils.h>
34 #include <telepathy-glib/telepathy-glib-dbus.h>
36 #include "action-chain-internal.h"
37 #include "empathy-account-chooser.h"
38 #include "empathy-call-utils.h"
39 #include "empathy-geometry.h"
40 #include "empathy-gsettings.h"
41 #include "empathy-images.h"
42 #include "empathy-individual-information-dialog.h"
43 #include "empathy-request-util.h"
44 #include "empathy-theme-manager.h"
45 #include "empathy-ui-utils.h"
46 #include "empathy-utils.h"
47 #include "empathy-webkit-utils.h"
48 #include "extensions.h"
50 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
51 #include "empathy-debug.h"
53 #define EMPATHY_NS "http://live.gnome.org/Empathy"
55 G_DEFINE_TYPE (EmpathyLogWindow
, empathy_log_window
, GTK_TYPE_WINDOW
);
57 struct _EmpathyLogWindowPriv
61 GtkWidget
*button_profile
;
62 GtkWidget
*button_chat
;
63 GtkWidget
*button_call
;
64 GtkWidget
*button_video
;
66 GtkWidget
*search_entry
;
71 GtkWidget
*treeview_who
;
72 GtkWidget
*treeview_what
;
73 GtkWidget
*treeview_when
;
76 GtkTreeStore
*store_events
;
78 GtkWidget
*account_chooser
;
82 /* List of selected GDates, free with g_list_free_full (l, g_date_free) */
85 TplActionChain
*chain
;
86 TplLogManager
*log_manager
;
88 /* Hash of TpChannel<->TpAccount for use by the observer until we can
89 * get a TpAccount from a TpConnection or wherever */
91 TpBaseClient
*observer
;
93 EmpathyContact
*selected_contact
;
94 EmpathyContact
*events_contact
;
96 TpawCameraMonitor
*camera_monitor
;
97 GBinding
*button_video_binding
;
99 /* Used to cancel logger calls when no longer needed */
102 /* List of owned TplLogSearchHits, free with tpl_log_search_hit_free */
106 /* Only used while waiting for the account chooser to be ready */
107 TpAccount
*selected_account
;
108 gchar
*selected_chat_id
;
109 gboolean selected_is_chatroom
;
111 GSettings
*gsettings_chat
;
112 GSettings
*gsettings_desktop
;
115 static void log_window_search_entry_changed_cb (GtkWidget
*entry
,
116 EmpathyLogWindow
*self
);
117 static void log_window_search_entry_activate_cb (GtkWidget
*widget
,
118 EmpathyLogWindow
*self
);
119 static void log_window_search_entry_icon_pressed_cb (GtkEntry
*entry
,
120 GtkEntryIconPosition icon_pos
,
123 static void log_window_who_populate (EmpathyLogWindow
*self
);
124 static void log_window_who_setup (EmpathyLogWindow
*self
);
125 static void log_window_when_setup (EmpathyLogWindow
*self
);
126 static void log_window_what_setup (EmpathyLogWindow
*self
);
127 static void log_window_events_setup (EmpathyLogWindow
*self
);
128 static void log_window_chats_accounts_changed_cb (GtkWidget
*combobox
,
129 EmpathyLogWindow
*self
);
130 static void log_window_chats_set_selected (EmpathyLogWindow
*self
);
131 static void log_window_chats_get_messages (EmpathyLogWindow
*self
,
132 gboolean force_get_dates
);
133 static void log_window_when_changed_cb (GtkTreeSelection
*selection
,
134 EmpathyLogWindow
*self
);
135 static void log_window_delete_menu_clicked_cb (GtkMenuItem
*menuitem
,
136 EmpathyLogWindow
*self
);
137 static void start_spinner (void);
139 static void log_window_create_observer (EmpathyLogWindow
*window
);
140 static gboolean
log_window_events_button_press_event (GtkWidget
*webview
,
141 GdkEventButton
*event
, EmpathyLogWindow
*self
);
142 static void log_window_update_buttons_sensitivity (EmpathyLogWindow
*self
);
145 empathy_account_chooser_filter_has_logs (TpAccount
*account
,
146 EmpathyAccountChooserFilterResultCallback callback
,
147 gpointer callback_data
,
169 COL_WHO_NAME_SORT_KEY
,
198 COL_EVENTS_PRETTY_DATE
,
207 #define CALENDAR_ICON "stock_calendar"
209 /* Seconds between two messages to be considered one conversation */
210 #define MAX_GAP 30*60
212 #define WHAT_TYPE_SEPARATOR -1
216 EVENT_CALL_INCOMING
= 1 << 0,
217 EVENT_CALL_OUTGOING
= 1 << 1,
218 EVENT_CALL_MISSED
= 1 << 2,
219 EVENT_CALL_ALL
= 1 << 3,
223 log_window_get_selected (EmpathyLogWindow
*window
,
228 TplEventTypeMask
*event_mask
,
229 EventSubtype
*subtype
);
231 static EmpathyLogWindow
*log_window
= NULL
;
233 static gboolean has_element
;
236 #define _date_copy(d) g_date_new_julian (g_date_get_julian (d))
241 EmpathyLogWindow
*self
;
245 TplEventTypeMask event_mask
;
246 EventSubtype subtype
;
251 ctx_new (EmpathyLogWindow
*self
,
255 TplEventTypeMask event_mask
,
256 EventSubtype subtype
,
259 Ctx
*ctx
= g_slice_new0 (Ctx
);
263 ctx
->account
= g_object_ref (account
);
265 ctx
->entity
= g_object_ref (entity
);
267 ctx
->date
= _date_copy (date
);
268 ctx
->event_mask
= event_mask
;
269 ctx
->subtype
= subtype
;
278 tp_clear_object (&ctx
->account
);
279 tp_clear_object (&ctx
->entity
);
280 tp_clear_pointer (&ctx
->date
, g_date_free
);
282 g_slice_free (Ctx
, ctx
);
286 select_account_once_ready (EmpathyLogWindow
*self
,
288 const gchar
*chat_id
,
289 gboolean is_chatroom
)
291 EmpathyAccountChooser
*account_chooser
;
293 account_chooser
= EMPATHY_ACCOUNT_CHOOSER (self
->priv
->account_chooser
);
295 tp_clear_object (&self
->priv
->selected_account
);
296 self
->priv
->selected_account
= g_object_ref (account
);
298 g_free (self
->priv
->selected_chat_id
);
299 self
->priv
->selected_chat_id
= g_strdup (chat_id
);
301 self
->priv
->selected_is_chatroom
= is_chatroom
;
303 empathy_account_chooser_set_account (account_chooser
,
304 self
->priv
->selected_account
);
308 toolbutton_profile_clicked (GtkToolButton
*toolbutton
,
309 EmpathyLogWindow
*self
)
311 FolksIndividual
*individual
;
313 g_return_if_fail (self
!= NULL
);
314 g_return_if_fail (EMPATHY_IS_CONTACT (self
->priv
->selected_contact
));
316 individual
= empathy_ensure_individual_from_tp_contact (
317 empathy_contact_get_tp_contact (self
->priv
->selected_contact
));
319 empathy_display_individual_info (individual
);
321 g_object_unref (individual
);
325 toolbutton_chat_clicked (GtkToolButton
*toolbutton
,
326 EmpathyLogWindow
*self
)
328 g_return_if_fail (self
!= NULL
);
329 g_return_if_fail (EMPATHY_IS_CONTACT (self
->priv
->selected_contact
));
331 empathy_chat_with_contact (self
->priv
->selected_contact
,
332 gtk_get_current_event_time ());
336 toolbutton_av_clicked (GtkToolButton
*toolbutton
,
337 EmpathyLogWindow
*self
)
341 g_return_if_fail (self
!= NULL
);
342 g_return_if_fail (EMPATHY_IS_CONTACT (self
->priv
->selected_contact
));
344 video
= (GTK_WIDGET (toolbutton
) == self
->priv
->button_video
);
346 empathy_call_new_with_streams (
347 empathy_contact_get_id (self
->priv
->selected_contact
),
348 empathy_contact_get_account (self
->priv
->selected_contact
),
349 TRUE
, video
, gtk_get_current_event_time ());
353 insert_or_change_row (EmpathyLogWindow
*self
,
359 char *str
= gtk_tree_path_to_string (path
);
360 char *script
, *text
, *date
, *stock_icon
;
361 GString
*escaped_text
;
365 gtk_tree_model_get (model
, iter
,
366 COL_EVENTS_TEXT
, &text
,
367 COL_EVENTS_PRETTY_DATE
, &date
,
368 COL_EVENTS_ICON
, &stock_icon
,
371 if (!tp_str_empty (stock_icon
))
373 GtkIconInfo
*icon_info
= gtk_icon_theme_lookup_icon (
374 gtk_icon_theme_get_default (),
376 GTK_ICON_SIZE_MENU
, 0);
378 if (icon_info
!= NULL
)
379 icon
= g_strdup (gtk_icon_info_get_filename (icon_info
));
381 g_object_unref (icon_info
);
384 escaped_text
= g_string_new (NULL
);
386 /* Only need to deal with «'» and «\».
388 * Note that these never appear in non-ascii utf8 characters, so just
389 * pretend like we have an ascii string...
391 for (i
= 0; text
&& text
[i
]; i
++)
395 if (c
== '\'' || c
== '\\')
396 g_string_append_c (escaped_text
, '\\');
398 g_string_append_c (escaped_text
, c
);
401 script
= g_strdup_printf ("javascript:%s([%s], '%s', '%s', '%s');",
403 g_strdelimit (str
, ":", ','),
405 icon
!= NULL
? icon
: "",
408 webkit_web_view_execute_script (WEBKIT_WEB_VIEW (self
->priv
->webview
),
411 g_string_free (escaped_text
, TRUE
);
421 store_events_row_inserted (GtkTreeModel
*model
,
424 EmpathyLogWindow
*self
)
426 insert_or_change_row (self
, "insertRow", model
, path
, iter
);
430 store_events_row_changed (GtkTreeModel
*model
,
433 EmpathyLogWindow
*self
)
435 insert_or_change_row (self
, "changeRow", model
, path
, iter
);
439 store_events_row_deleted (GtkTreeModel
*model
,
441 EmpathyLogWindow
*self
)
443 char *str
= gtk_tree_path_to_string (path
);
446 script
= g_strdup_printf ("javascript:deleteRow([%s]);",
447 g_strdelimit (str
, ":", ','));
449 webkit_web_view_execute_script (WEBKIT_WEB_VIEW (self
->priv
->webview
),
457 store_events_has_child_rows (GtkTreeModel
*model
,
460 EmpathyLogWindow
*self
)
462 char *str
= gtk_tree_path_to_string (path
);
465 script
= g_strdup_printf ("javascript:hasChildRows([%s], %u);",
466 g_strdelimit (str
, ":", ','),
467 gtk_tree_model_iter_has_child (model
, iter
));
469 webkit_web_view_execute_script (WEBKIT_WEB_VIEW (self
->priv
->webview
),
477 store_events_rows_reordered (GtkTreeModel
*model
,
481 EmpathyLogWindow
*self
)
483 char *str
= gtk_tree_path_to_string (path
);
484 int i
, children
= gtk_tree_model_iter_n_children (model
, iter
);
485 char **new_order_strv
, *new_order_s
;
488 new_order_strv
= g_new0 (char *, children
+ 1);
490 for (i
= 0; i
< children
; i
++)
491 new_order_strv
[i
] = g_strdup_printf ("%i", new_order
[i
]);
493 new_order_s
= g_strjoinv (",", new_order_strv
);
495 script
= g_strdup_printf ("javascript:reorderRows([%s], [%s]);",
496 str
== NULL
? "" : g_strdelimit (str
, ":", ','),
499 webkit_web_view_execute_script (WEBKIT_WEB_VIEW (self
->priv
->webview
),
504 g_free (new_order_s
);
505 g_strfreev (new_order_strv
);
509 events_webview_handle_navigation (WebKitWebView
*webview
,
510 WebKitWebFrame
*frame
,
511 WebKitNetworkRequest
*request
,
512 WebKitWebNavigationAction
*navigation_action
,
513 WebKitWebPolicyDecision
*policy_decision
,
514 EmpathyLogWindow
*window
)
516 empathy_url_show (GTK_WIDGET (webview
),
517 webkit_network_request_get_uri (request
));
519 webkit_web_policy_decision_ignore (policy_decision
);
524 empathy_log_window_constructor (GType type
,
526 GObjectConstructParam
*props
)
530 if (log_window
!= NULL
)
532 retval
= (GObject
*) log_window
;
536 retval
= G_OBJECT_CLASS (empathy_log_window_parent_class
)
537 ->constructor (type
, n_props
, props
);
539 log_window
= EMPATHY_LOG_WINDOW (retval
);
540 g_object_add_weak_pointer (retval
, (gpointer
) &log_window
);
547 empathy_log_window_dispose (GObject
*object
)
549 EmpathyLogWindow
*self
= EMPATHY_LOG_WINDOW (object
);
551 if (self
->priv
->source
!= 0)
553 g_source_remove (self
->priv
->source
);
554 self
->priv
->source
= 0;
557 if (self
->priv
->current_dates
!= NULL
)
559 g_list_free_full (self
->priv
->current_dates
,
560 (GDestroyNotify
) g_date_free
);
561 self
->priv
->current_dates
= NULL
;
564 tp_clear_pointer (&self
->priv
->chain
, _tpl_action_chain_free
);
565 tp_clear_pointer (&self
->priv
->channels
, g_hash_table_unref
);
567 tp_clear_object (&self
->priv
->observer
);
568 tp_clear_object (&self
->priv
->log_manager
);
569 tp_clear_object (&self
->priv
->selected_account
);
570 tp_clear_object (&self
->priv
->selected_contact
);
571 tp_clear_object (&self
->priv
->events_contact
);
572 tp_clear_object (&self
->priv
->camera_monitor
);
574 tp_clear_object (&self
->priv
->gsettings_chat
);
575 tp_clear_object (&self
->priv
->gsettings_desktop
);
577 tp_clear_object (&self
->priv
->store_events
);
579 G_OBJECT_CLASS (empathy_log_window_parent_class
)->dispose (object
);
583 empathy_log_window_finalize (GObject
*object
)
585 EmpathyLogWindow
*self
= EMPATHY_LOG_WINDOW (object
);
587 g_free (self
->priv
->last_find
);
588 g_free (self
->priv
->selected_chat_id
);
590 G_OBJECT_CLASS (empathy_log_window_parent_class
)->finalize (object
);
594 empathy_log_window_class_init (
595 EmpathyLogWindowClass
*empathy_log_window_class
)
597 GObjectClass
*object_class
= G_OBJECT_CLASS (empathy_log_window_class
);
599 g_type_class_add_private (empathy_log_window_class
,
600 sizeof (EmpathyLogWindowPriv
));
602 object_class
->constructor
= empathy_log_window_constructor
;
603 object_class
->dispose
= empathy_log_window_dispose
;
604 object_class
->finalize
= empathy_log_window_finalize
;
608 empathy_log_window_init (EmpathyLogWindow
*self
)
610 EmpathyAccountChooser
*account_chooser
;
614 GtkWidget
*vbox
, *accounts
, *search
, *label
, *closeitem
;
615 GtkWidget
*scrolledwindow_events
;
618 self
->priv
= G_TYPE_INSTANCE_GET_PRIVATE (self
,
619 EMPATHY_TYPE_LOG_WINDOW
, EmpathyLogWindowPriv
);
621 self
->priv
->chain
= _tpl_action_chain_new_async (NULL
, NULL
, NULL
);
623 self
->priv
->camera_monitor
= tpaw_camera_monitor_dup_singleton ();
625 self
->priv
->log_manager
= tpl_log_manager_dup_singleton ();
627 self
->priv
->gsettings_chat
= g_settings_new (EMPATHY_PREFS_CHAT_SCHEMA
);
628 self
->priv
->gsettings_desktop
= g_settings_new (
629 EMPATHY_PREFS_DESKTOP_INTERFACE_SCHEMA
);
631 gtk_window_set_title (GTK_WINDOW (self
), _("History"));
632 gtk_widget_set_can_focus (GTK_WIDGET (self
), FALSE
);
633 gtk_window_set_default_size (GTK_WINDOW (self
), 800, 600);
635 filename
= empathy_file_lookup ("empathy-log-window.ui", "libempathy-gtk");
636 gui
= tpaw_builder_get_file (filename
,
637 "vbox1", &self
->priv
->vbox
,
638 "toolbutton_profile", &self
->priv
->button_profile
,
639 "toolbutton_chat", &self
->priv
->button_chat
,
640 "toolbutton_call", &self
->priv
->button_call
,
641 "toolbutton_video", &self
->priv
->button_video
,
642 "toolbutton_accounts", &accounts
,
643 "toolbutton_search", &search
,
644 "imagemenuitem_close", &closeitem
,
645 "treeview_who", &self
->priv
->treeview_who
,
646 "treeview_what", &self
->priv
->treeview_what
,
647 "treeview_when", &self
->priv
->treeview_when
,
648 "scrolledwindow_events", &scrolledwindow_events
,
649 "notebook", &self
->priv
->notebook
,
650 "spinner", &self
->priv
->spinner
,
654 tpaw_builder_connect (gui
, self
,
655 "toolbutton_profile", "clicked", toolbutton_profile_clicked
,
656 "toolbutton_chat", "clicked", toolbutton_chat_clicked
,
657 "toolbutton_call", "clicked", toolbutton_av_clicked
,
658 "toolbutton_video", "clicked", toolbutton_av_clicked
,
659 "imagemenuitem_delete", "activate", log_window_delete_menu_clicked_cb
,
662 gtk_container_add (GTK_CONTAINER (self
), self
->priv
->vbox
);
664 g_object_unref (gui
);
666 g_signal_connect_swapped (closeitem
, "activate",
667 G_CALLBACK (gtk_widget_destroy
), self
);
669 /* Account chooser for chats */
670 vbox
= gtk_box_new (GTK_ORIENTATION_VERTICAL
, 3);
672 self
->priv
->account_chooser
= empathy_account_chooser_new ();
673 account_chooser
= EMPATHY_ACCOUNT_CHOOSER (self
->priv
->account_chooser
);
674 empathy_account_chooser_set_has_all_option (account_chooser
, TRUE
);
675 empathy_account_chooser_set_filter (account_chooser
,
676 empathy_account_chooser_filter_has_logs
, NULL
);
677 empathy_account_chooser_set_all (account_chooser
);
679 gtk_style_context_add_class (gtk_widget_get_style_context (self
->priv
->account_chooser
),
680 GTK_STYLE_CLASS_RAISED
);
682 g_signal_connect (self
->priv
->account_chooser
, "changed",
683 G_CALLBACK (log_window_chats_accounts_changed_cb
),
686 label
= gtk_label_new (_("Show"));
688 gtk_box_pack_start (GTK_BOX (vbox
),
689 self
->priv
->account_chooser
,
692 gtk_box_pack_start (GTK_BOX (vbox
),
696 gtk_widget_show_all (vbox
);
697 gtk_container_add (GTK_CONTAINER (accounts
), vbox
);
700 vbox
= gtk_box_new (GTK_ORIENTATION_VERTICAL
, 3);
702 self
->priv
->search_entry
= gtk_entry_new ();
703 gtk_entry_set_icon_from_icon_name (GTK_ENTRY (self
->priv
->search_entry
),
704 GTK_ENTRY_ICON_SECONDARY
, "edit-find-symbolic");
705 gtk_entry_set_icon_sensitive (GTK_ENTRY (self
->priv
->search_entry
),
706 GTK_ENTRY_ICON_SECONDARY
, FALSE
);
708 label
= gtk_label_new (_("Search"));
710 gtk_box_pack_start (GTK_BOX (vbox
),
711 self
->priv
->search_entry
,
714 gtk_box_pack_start (GTK_BOX (vbox
),
718 gtk_widget_show_all (vbox
);
719 gtk_container_add (GTK_CONTAINER (search
), vbox
);
721 g_signal_connect (self
->priv
->search_entry
, "changed",
722 G_CALLBACK (log_window_search_entry_changed_cb
),
725 g_signal_connect (self
->priv
->search_entry
, "activate",
726 G_CALLBACK (log_window_search_entry_activate_cb
),
729 g_signal_connect (self
->priv
->search_entry
, "icon-press",
730 G_CALLBACK (log_window_search_entry_icon_pressed_cb
),
734 log_window_events_setup (self
);
735 log_window_who_setup (self
);
736 log_window_what_setup (self
);
737 log_window_when_setup (self
);
739 log_window_create_observer (self
);
741 log_window_who_populate (self
);
744 self
->priv
->webview
= webkit_web_view_new ();
745 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow_events
),
746 GTK_POLICY_NEVER
, GTK_POLICY_AUTOMATIC
);
747 gtk_container_add (GTK_CONTAINER (scrolledwindow_events
),
748 self
->priv
->webview
);
749 gtk_widget_show (self
->priv
->webview
);
751 empathy_webkit_bind_font_setting (WEBKIT_WEB_VIEW (self
->priv
->webview
),
752 self
->priv
->gsettings_desktop
,
753 EMPATHY_PREFS_DESKTOP_INTERFACE_FONT_NAME
);
755 filename
= empathy_file_lookup ("empathy-log-window.html", "data");
756 gfile
= g_file_new_for_path (filename
);
759 uri
= g_file_get_uri (gfile
);
760 webkit_web_view_load_uri (WEBKIT_WEB_VIEW (self
->priv
->webview
), uri
);
761 g_object_unref (gfile
);
764 /* handle all navigation externally */
765 g_signal_connect (self
->priv
->webview
, "navigation-policy-decision-requested",
766 G_CALLBACK (events_webview_handle_navigation
), self
);
768 /* listen to changes to the treemodel */
769 g_signal_connect (self
->priv
->store_events
, "row-inserted",
770 G_CALLBACK (store_events_row_inserted
), self
);
771 g_signal_connect (self
->priv
->store_events
, "row-changed",
772 G_CALLBACK (store_events_row_changed
), self
);
773 g_signal_connect (self
->priv
->store_events
, "row-deleted",
774 G_CALLBACK (store_events_row_deleted
), self
);
775 g_signal_connect (self
->priv
->store_events
, "rows-reordered",
776 G_CALLBACK (store_events_rows_reordered
), self
);
777 g_signal_connect (self
->priv
->store_events
, "row-has-child-toggled",
778 G_CALLBACK (store_events_has_child_rows
), self
);
780 /* track clicked row */
781 g_signal_connect (self
->priv
->webview
, "button-press-event",
782 G_CALLBACK (log_window_events_button_press_event
), self
);
784 log_window_update_buttons_sensitivity (self
);
785 gtk_widget_show (GTK_WIDGET (self
));
787 empathy_geometry_bind (GTK_WINDOW (self
), "log-window");
791 empathy_log_window_show (TpAccount
*account
,
792 const gchar
*chat_id
,
793 gboolean is_chatroom
,
796 log_window
= g_object_new (EMPATHY_TYPE_LOG_WINDOW
, NULL
);
798 gtk_window_present (GTK_WINDOW (log_window
));
800 if (account
!= NULL
&& chat_id
!= NULL
)
801 select_account_once_ready (log_window
, account
, chat_id
, is_chatroom
);
804 gtk_window_set_transient_for (GTK_WINDOW (log_window
),
805 GTK_WINDOW (parent
));
807 return GTK_WIDGET (log_window
);
811 account_equal (TpAccount
*a
,
814 return g_str_equal (tp_proxy_get_object_path (a
),
815 tp_proxy_get_object_path (b
));
819 entity_equal (TplEntity
*a
,
822 return g_str_equal (tpl_entity_get_identifier (a
),
823 tpl_entity_get_identifier (b
));
827 is_same_confroom (TplEvent
*e1
,
830 TplEntity
*sender1
= tpl_event_get_sender (e1
);
831 TplEntity
*receiver1
= tpl_event_get_receiver (e1
);
832 TplEntity
*sender2
= tpl_event_get_sender (e2
);
833 TplEntity
*receiver2
= tpl_event_get_receiver (e2
);
834 TplEntity
*room1
, *room2
;
836 if (receiver1
== NULL
|| receiver2
== NULL
)
839 if (tpl_entity_get_entity_type (sender1
) == TPL_ENTITY_ROOM
)
841 else if (tpl_entity_get_entity_type (receiver1
) == TPL_ENTITY_ROOM
)
846 if (tpl_entity_get_entity_type (sender2
) == TPL_ENTITY_ROOM
)
848 else if (tpl_entity_get_entity_type (receiver2
) == TPL_ENTITY_ROOM
)
853 return g_str_equal (tpl_entity_get_identifier (room1
),
854 tpl_entity_get_identifier (room2
));
858 maybe_refresh_logs (TpChannel
*channel
,
861 GList
*accounts
= NULL
, *entities
= NULL
, *dates
= NULL
;
863 TplEventTypeMask event_mask
;
864 GDate
*anytime
= NULL
, *today
= NULL
;
865 GDateTime
*now
= NULL
;
866 gboolean refresh
= FALSE
;
870 if (!log_window_get_selected (log_window
,
871 &accounts
, &entities
, &anyone
, &dates
, &event_mask
, NULL
))
873 DEBUG ("Could not get selected rows");
877 type
= tp_channel_get_channel_type (channel
);
879 /* If the channel type is not in the What pane, whatever has happened
880 * won't be displayed in the events pane. */
881 if (!tp_strdiff (type
, TP_IFACE_CHANNEL_TYPE_TEXT
) &&
882 !(event_mask
& TPL_EVENT_MASK_TEXT
))
884 if ((!tp_strdiff (type
, TP_IFACE_CHANNEL_TYPE_CALL
)) &&
885 !(event_mask
& TPL_EVENT_MASK_CALL
))
888 anytime
= g_date_new_dmy (2, 1, -1);
889 now
= g_date_time_new_now_local ();
890 today
= g_date_new_dmy (g_date_time_get_day_of_month (now
),
891 g_date_time_get_month (now
),
892 g_date_time_get_year (now
));
894 /* If Today (or anytime) isn't selected, anything that has happened now
895 * won't be displayed. */
896 if (!g_list_find_custom (dates
, anytime
, (GCompareFunc
) g_date_compare
) &&
897 !g_list_find_custom (dates
, today
, (GCompareFunc
) g_date_compare
))
906 for (acc
= accounts
, ent
= entities
;
907 acc
!= NULL
&& ent
!= NULL
;
908 acc
= g_list_next (acc
), ent
= g_list_next (ent
))
910 if (!account_equal (account
, acc
->data
))
913 if (!tp_strdiff (tp_channel_get_identifier (channel
),
914 tpl_entity_get_identifier (ent
->data
)))
922 tp_clear_pointer (&anytime
, g_date_free
);
923 tp_clear_pointer (&today
, g_date_free
);
924 tp_clear_pointer (&now
, g_date_time_unref
);
925 g_list_free_full (accounts
, g_object_unref
);
926 g_list_free_full (entities
, g_object_unref
);
927 g_list_free_full (dates
, (GFreeFunc
) g_date_free
);
931 DEBUG ("Refreshing logs after received event");
933 /* FIXME: We need to populate the entities in case we
934 * didn't have any previous logs with this contact. */
935 log_window_chats_get_messages (log_window
, FALSE
);
940 on_msg_sent (TpTextChannel
*channel
,
941 TpSignalledMessage
*message
,
944 EmpathyLogWindow
*self
)
946 TpAccount
*account
= g_hash_table_lookup (self
->priv
->channels
, channel
);
948 maybe_refresh_logs (TP_CHANNEL (channel
), account
);
952 on_msg_received (TpTextChannel
*channel
,
953 TpSignalledMessage
*message
,
954 EmpathyLogWindow
*self
)
956 TpMessage
*msg
= TP_MESSAGE (message
);
957 TpChannelTextMessageType type
= tp_message_get_message_type (msg
);
958 TpAccount
*account
= g_hash_table_lookup (self
->priv
->channels
, channel
);
960 if (type
!= TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL
&&
961 type
!= TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION
)
964 maybe_refresh_logs (TP_CHANNEL (channel
), account
);
968 on_channel_ended (TpChannel
*channel
,
972 EmpathyLogWindow
*self
)
974 if (self
->priv
->channels
!= NULL
)
975 g_hash_table_remove (self
->priv
->channels
, channel
);
979 on_call_ended (TpChannel
*channel
,
983 EmpathyLogWindow
*self
)
985 TpAccount
*account
= g_hash_table_lookup (self
->priv
->channels
, channel
);
987 maybe_refresh_logs (channel
, account
);
989 if (self
->priv
->channels
!= NULL
)
990 g_hash_table_remove (self
->priv
->channels
, channel
);
994 observe_channels (TpSimpleObserver
*observer
,
996 TpConnection
*connection
,
998 TpChannelDispatchOperation
*dispatch_operation
,
1000 TpObserveChannelsContext
*context
,
1003 EmpathyLogWindow
*self
= user_data
;
1007 for (l
= channels
; l
!= NULL
; l
= g_list_next (l
))
1009 TpChannel
*channel
= l
->data
;
1010 const gchar
*type
= tp_channel_get_channel_type (channel
);
1012 if (!tp_strdiff (type
, TP_IFACE_CHANNEL_TYPE_TEXT
))
1014 TpTextChannel
*text_channel
= TP_TEXT_CHANNEL (channel
);
1016 g_hash_table_insert (self
->priv
->channels
,
1017 g_object_ref (channel
), g_object_ref (account
));
1019 tp_g_signal_connect_object (text_channel
, "message-sent",
1020 G_CALLBACK (on_msg_sent
), self
, 0);
1021 tp_g_signal_connect_object (text_channel
, "message-received",
1022 G_CALLBACK (on_msg_received
), self
, 0);
1023 tp_g_signal_connect_object (channel
, "invalidated",
1024 G_CALLBACK (on_channel_ended
), self
, 0);
1026 else if (!tp_strdiff (type
, TP_IFACE_CHANNEL_TYPE_CALL
))
1028 g_hash_table_insert (self
->priv
->channels
,
1029 g_object_ref (channel
), g_object_ref (account
));
1031 tp_g_signal_connect_object (channel
, "invalidated",
1032 G_CALLBACK (on_call_ended
), self
, 0);
1036 g_warning ("Unknown channel type: %s", type
);
1040 tp_observe_channels_context_accept (context
);
1044 log_window_create_observer (EmpathyLogWindow
*self
)
1046 TpAccountManager
*am
;
1048 am
= tp_account_manager_dup ();
1050 self
->priv
->observer
= tp_simple_observer_new_with_am (am
, TRUE
, "LogWindow",
1051 TRUE
, observe_channels
,
1052 g_object_ref (self
), g_object_unref
);
1054 self
->priv
->channels
= g_hash_table_new_full (g_direct_hash
, g_direct_equal
,
1055 g_object_unref
, g_object_unref
);
1057 tp_base_client_take_observer_filter (self
->priv
->observer
,
1059 TP_PROP_CHANNEL_CHANNEL_TYPE
, G_TYPE_STRING
,
1060 TP_IFACE_CHANNEL_TYPE_TEXT
,
1062 tp_base_client_take_observer_filter (self
->priv
->observer
,
1064 TP_PROP_CHANNEL_CHANNEL_TYPE
, G_TYPE_STRING
,
1065 TP_IFACE_CHANNEL_TYPE_CALL
,
1068 tp_base_client_register (self
->priv
->observer
, NULL
);
1070 g_object_unref (am
);
1074 event_get_target (TplEvent
*event
)
1076 TplEntity
*sender
= tpl_event_get_sender (event
);
1077 TplEntity
*receiver
= tpl_event_get_receiver (event
);
1079 if (tpl_entity_get_entity_type (sender
) == TPL_ENTITY_SELF
)
1086 model_is_parent (GtkTreeModel
*model
,
1090 TplEvent
*stored_event
;
1093 gboolean found
= FALSE
;
1096 if (gtk_tree_model_iter_parent (model
, &parent
, iter
))
1099 gtk_tree_model_get (model
, iter
,
1100 COL_EVENTS_ACCOUNT
, &account
,
1101 COL_EVENTS_TARGET
, &target
,
1102 COL_EVENTS_EVENT
, &stored_event
,
1105 if (G_OBJECT_TYPE (event
) == G_OBJECT_TYPE (stored_event
) &&
1106 account_equal (account
, tpl_event_get_account (event
)) &&
1107 (entity_equal (target
, event_get_target (event
)) ||
1108 is_same_confroom (event
, stored_event
)))
1113 gtk_tree_model_iter_nth_child (model
, &child
, iter
,
1114 gtk_tree_model_iter_n_children (model
, iter
) - 1);
1116 gtk_tree_model_get (model
, &child
,
1117 COL_EVENTS_TS
, ×tamp
,
1120 if (ABS (tpl_event_get_timestamp (event
) - timestamp
) < MAX_GAP
)
1122 /* The gap is smaller than 30 min */
1127 g_object_unref (stored_event
);
1128 g_object_unref (account
);
1129 g_object_unref (target
);
1135 get_display_string_for_chat_message (EmpathyMessage
*message
,
1138 EmpathyContact
*sender
, *receiver
, *target
;
1139 TplEntity
*ent_sender
, *ent_receiver
;
1140 const gchar
*format
;
1142 sender
= empathy_message_get_sender (message
);
1143 receiver
= empathy_message_get_receiver (message
);
1145 ent_sender
= tpl_event_get_sender (event
);
1146 ent_receiver
= tpl_event_get_receiver (event
);
1148 /* If this is a MUC, we want to show "Chat in <room>". */
1149 if (tpl_entity_get_entity_type (ent_sender
) == TPL_ENTITY_ROOM
||
1150 (ent_receiver
!= NULL
&&
1151 tpl_entity_get_entity_type (ent_receiver
) == TPL_ENTITY_ROOM
))
1152 format
= _("Chat in %s");
1154 format
= _("Chat with %s");
1156 if (tpl_entity_get_entity_type (ent_sender
) == TPL_ENTITY_ROOM
)
1158 else if (ent_receiver
!= NULL
&&
1159 tpl_entity_get_entity_type (ent_receiver
) == TPL_ENTITY_ROOM
)
1161 else if (empathy_contact_is_user (sender
))
1166 return g_markup_printf_escaped (format
, empathy_contact_get_alias (target
));
1170 get_parent_iter_for_message (TplEvent
*event
,
1171 EmpathyMessage
*message
,
1172 GtkTreeIter
*parent
)
1174 GtkTreeStore
*store
;
1175 GtkTreeModel
*model
;
1177 gboolean parent_found
= FALSE
;
1180 store
= log_window
->priv
->store_events
;
1181 model
= GTK_TREE_MODEL (store
);
1183 for (next
= gtk_tree_model_get_iter_first (model
, &iter
);
1185 next
= gtk_tree_model_iter_next (model
, &iter
))
1187 if ((parent_found
= model_is_parent (model
, &iter
, event
)))
1198 gchar
*body
, *pretty_date
;
1200 date
= g_date_time_new_from_unix_local (
1201 tpl_event_get_timestamp (event
));
1203 pretty_date
= g_date_time_format (date
,
1204 C_("A date with the time", "%A, %e %B %Y %X"));
1206 body
= get_display_string_for_chat_message (message
, event
);
1208 gtk_tree_store_append (store
, &iter
, NULL
);
1209 gtk_tree_store_set (store
, &iter
,
1210 COL_EVENTS_TS
, tpl_event_get_timestamp (event
),
1211 COL_EVENTS_PRETTY_DATE
, pretty_date
,
1212 COL_EVENTS_TEXT
, body
,
1213 COL_EVENTS_ICON
, "format-justify-fill",
1214 COL_EVENTS_ACCOUNT
, tpl_event_get_account (event
),
1215 COL_EVENTS_TARGET
, event_get_target (event
),
1216 COL_EVENTS_EVENT
, event
,
1222 g_free (pretty_date
);
1223 g_date_time_unref (date
);
1227 static const gchar
*
1228 get_icon_for_event (TplEvent
*event
)
1230 const gchar
*icon
= NULL
;
1232 if (TPL_IS_TEXT_EVENT (event
))
1234 TplTextEvent
*text
= TPL_TEXT_EVENT (event
);
1236 if (!tp_str_empty (tpl_text_event_get_supersedes_token (text
)))
1237 icon
= EMPATHY_IMAGE_EDIT_MESSAGE
;
1239 else if (TPL_IS_CALL_EVENT (event
))
1241 TplCallEvent
*call
= TPL_CALL_EVENT (event
);
1242 TpCallStateChangeReason reason
= tpl_call_event_get_end_reason (call
);
1243 TplEntity
*sender
= tpl_event_get_sender (event
);
1244 TplEntity
*receiver
= tpl_event_get_receiver (event
);
1246 if (reason
== TP_CALL_STATE_CHANGE_REASON_NO_ANSWER
)
1247 icon
= EMPATHY_IMAGE_CALL_MISSED
;
1248 else if (tpl_entity_get_entity_type (sender
) == TPL_ENTITY_SELF
)
1249 icon
= EMPATHY_IMAGE_CALL_OUTGOING
;
1250 else if (tpl_entity_get_entity_type (receiver
) == TPL_ENTITY_SELF
)
1251 icon
= EMPATHY_IMAGE_CALL_INCOMING
;
1258 log_window_append_chat_message (TplEvent
*event
,
1259 EmpathyMessage
*message
)
1261 GtkTreeStore
*store
= log_window
->priv
->store_events
;
1262 GtkTreeIter iter
, parent
;
1263 gchar
*pretty_date
, *alias
, *body
;
1265 TpawStringParser
*parsers
;
1268 date
= g_date_time_new_from_unix_local (
1269 tpl_event_get_timestamp (event
));
1271 pretty_date
= g_date_time_format (date
, "%X");
1273 get_parent_iter_for_message (event
, message
, &parent
);
1275 alias
= g_markup_escape_text (
1276 tpl_entity_get_alias (tpl_event_get_sender (event
)), -1);
1278 /* escape the text */
1279 parsers
= empathy_webkit_get_string_parser (
1280 g_settings_get_boolean (log_window
->priv
->gsettings_chat
,
1281 EMPATHY_PREFS_CHAT_SHOW_SMILEYS
));
1282 msg
= g_string_new ("");
1284 tpaw_string_parser_substr (empathy_message_get_body (message
), -1,
1287 if (tpl_text_event_get_message_type (TPL_TEXT_EVENT (event
))
1288 == TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION
)
1290 /* Translators: this is an emote: '* Danielle waves' */
1291 body
= g_strdup_printf (_("<i>* %s %s</i>"), alias
, msg
->str
);
1295 /* Translators: this is a message: 'Danielle: hello'
1296 * The string in bold is the sender's name */
1297 body
= g_strdup_printf (_("<b>%s:</b> %s"), alias
, msg
->str
);
1300 gtk_tree_store_append (store
, &iter
, &parent
);
1301 gtk_tree_store_set (store
, &iter
,
1302 COL_EVENTS_TS
, tpl_event_get_timestamp (event
),
1303 COL_EVENTS_PRETTY_DATE
, pretty_date
,
1304 COL_EVENTS_TEXT
, body
,
1305 COL_EVENTS_ICON
, get_icon_for_event (event
),
1306 COL_EVENTS_ACCOUNT
, tpl_event_get_account (event
),
1307 COL_EVENTS_TARGET
, event_get_target (event
),
1308 COL_EVENTS_EVENT
, event
,
1311 g_string_free (msg
, TRUE
);
1314 g_free (pretty_date
);
1315 g_date_time_unref (date
);
1319 log_window_append_call (TplEvent
*event
,
1320 EmpathyMessage
*message
)
1322 TplCallEvent
*call
= TPL_CALL_EVENT (event
);
1323 GtkTreeStore
*store
= log_window
->priv
->store_events
;
1324 GtkTreeIter iter
, child
;
1325 gchar
*pretty_date
, *duration
, *finished
;
1326 GDateTime
*started_date
, *finished_date
;
1329 /* If searching, only add the call if the search string appears anywhere */
1330 if (!TPAW_STR_EMPTY (log_window
->priv
->last_find
))
1332 if (strstr (tpl_entity_get_identifier (tpl_event_get_sender (event
)),
1333 log_window
->priv
->last_find
) == NULL
&&
1334 strstr (tpl_entity_get_identifier (tpl_event_get_receiver (event
)),
1335 log_window
->priv
->last_find
) == NULL
&&
1336 strstr (tpl_call_event_get_detailed_end_reason (call
),
1337 log_window
->priv
->last_find
) == NULL
)
1339 DEBUG ("TplCallEvent doesn't match search string, ignoring");
1344 started_date
= g_date_time_new_from_unix_local (
1345 tpl_event_get_timestamp (event
));
1347 pretty_date
= g_date_time_format (started_date
,
1348 C_("A date with the time", "%A, %e %B %Y %X"));
1350 gtk_tree_store_append (store
, &iter
, NULL
);
1351 gtk_tree_store_set (store
, &iter
,
1352 COL_EVENTS_TS
, tpl_event_get_timestamp (event
),
1353 COL_EVENTS_PRETTY_DATE
, pretty_date
,
1354 COL_EVENTS_TEXT
, empathy_message_get_body (message
),
1355 COL_EVENTS_ICON
, get_icon_for_event (event
),
1356 COL_EVENTS_ACCOUNT
, tpl_event_get_account (event
),
1357 COL_EVENTS_TARGET
, event_get_target (event
),
1358 COL_EVENTS_EVENT
, event
,
1361 if (tpl_call_event_get_end_reason (call
) != TP_CALL_STATE_CHANGE_REASON_NO_ANSWER
)
1366 span
= tpl_call_event_get_duration (TPL_CALL_EVENT (event
));
1370 tmp
= g_strdup_printf ("%" G_GINT64_FORMAT
, span
);
1371 duration
= g_strdup_printf (
1372 ngettext ("%s second", "%s seconds", span
), tmp
);
1377 tmp
= g_strdup_printf ("%" G_GINT64_FORMAT
, span
/ 60);
1378 duration
= g_strdup_printf (
1379 ngettext ("%s minute", "%s minutes", span
/ 60), tmp
);
1383 finished_date
= g_date_time_add (started_date
, -span
);
1384 finished
= g_date_time_format (finished_date
, "%X");
1385 g_date_time_unref (finished_date
);
1387 body
= g_strdup_printf (_("Call took %s, ended at %s"),
1388 duration
, finished
);
1393 gtk_tree_store_append (store
, &child
, &iter
);
1394 gtk_tree_store_set (store
, &child
,
1395 COL_EVENTS_TS
, tpl_event_get_timestamp (event
),
1396 COL_EVENTS_TEXT
, body
,
1397 COL_EVENTS_ACCOUNT
, tpl_event_get_account (event
),
1398 COL_EVENTS_TARGET
, event_get_target (event
),
1399 COL_EVENTS_EVENT
, event
,
1405 g_free (pretty_date
);
1406 g_date_time_unref (started_date
);
1410 log_window_append_message (TplEvent
*event
,
1411 EmpathyMessage
*message
)
1413 if (TPL_IS_TEXT_EVENT (event
))
1414 log_window_append_chat_message (event
, message
);
1415 else if (TPL_IS_CALL_EVENT (event
))
1416 log_window_append_call (event
, message
);
1418 DEBUG ("Message type not handled");
1422 add_all_accounts_and_entities (GList
**accounts
,
1426 GtkTreeModel
*model
;
1429 view
= GTK_TREE_VIEW (log_window
->priv
->treeview_who
);
1430 model
= gtk_tree_view_get_model (view
);
1432 if (!gtk_tree_model_get_iter_first (model
, &iter
))
1441 gtk_tree_model_get (model
, &iter
,
1442 COL_WHO_ACCOUNT
, &account
,
1443 COL_WHO_TARGET
, &entity
,
1444 COL_WHO_TYPE
, &type
,
1447 if (type
!= COL_TYPE_NORMAL
)
1450 if (accounts
!= NULL
)
1451 *accounts
= g_list_append (*accounts
, account
);
1453 if (entities
!= NULL
)
1454 *entities
= g_list_append (*entities
, entity
);
1456 while (gtk_tree_model_iter_next (model
, &iter
));
1460 log_window_get_selected (EmpathyLogWindow
*self
,
1465 TplEventTypeMask
*event_mask
,
1466 EventSubtype
*subtype
)
1469 GtkTreeModel
*model
;
1470 GtkTreeSelection
*selection
;
1472 TplEventTypeMask ev
= 0;
1473 EventSubtype st
= 0;
1477 view
= GTK_TREE_VIEW (self
->priv
->treeview_who
);
1478 model
= gtk_tree_view_get_model (view
);
1479 selection
= gtk_tree_view_get_selection (view
);
1481 paths
= gtk_tree_selection_get_selected_rows (selection
, NULL
);
1485 if (accounts
!= NULL
)
1487 if (entities
!= NULL
)
1492 for (l
= paths
; l
!= NULL
; l
= l
->next
)
1494 GtkTreePath
*path
= l
->data
;
1498 gtk_tree_model_get_iter (model
, &iter
, path
);
1499 gtk_tree_model_get (model
, &iter
,
1500 COL_WHO_ACCOUNT
, &account
,
1501 COL_WHO_TARGET
, &entity
,
1502 COL_WHO_TYPE
, &type
,
1505 if (type
== COL_TYPE_ANY
)
1507 if (accounts
!= NULL
|| entities
!= NULL
)
1508 add_all_accounts_and_entities (accounts
, entities
);
1514 if (accounts
!= NULL
)
1515 *accounts
= g_list_append (*accounts
, g_object_ref (account
));
1517 if (entities
!= NULL
)
1518 *entities
= g_list_append (*entities
, g_object_ref (entity
));
1520 g_object_unref (account
);
1521 g_object_unref (entity
);
1523 g_list_free_full (paths
, (GDestroyNotify
) gtk_tree_path_free
);
1525 view
= GTK_TREE_VIEW (self
->priv
->treeview_what
);
1526 model
= gtk_tree_view_get_model (view
);
1527 selection
= gtk_tree_view_get_selection (view
);
1529 paths
= gtk_tree_selection_get_selected_rows (selection
, NULL
);
1530 for (l
= paths
; l
!= NULL
; l
= l
->next
)
1532 GtkTreePath
*path
= l
->data
;
1533 TplEventTypeMask mask
;
1534 EventSubtype submask
;
1536 gtk_tree_model_get_iter (model
, &iter
, path
);
1537 gtk_tree_model_get (model
, &iter
,
1538 COL_WHAT_TYPE
, &mask
,
1539 COL_WHAT_SUBTYPE
, &submask
,
1545 g_list_free_full (paths
, (GDestroyNotify
) gtk_tree_path_free
);
1547 view
= GTK_TREE_VIEW (self
->priv
->treeview_when
);
1548 model
= gtk_tree_view_get_model (view
);
1549 selection
= gtk_tree_view_get_selection (view
);
1555 paths
= gtk_tree_selection_get_selected_rows (selection
, NULL
);
1556 for (l
= paths
; l
!= NULL
; l
= l
->next
)
1558 GtkTreePath
*path
= l
->data
;
1561 gtk_tree_model_get_iter (model
, &iter
, path
);
1562 gtk_tree_model_get (model
, &iter
,
1563 COL_WHEN_DATE
, &date
,
1566 *dates
= g_list_append (*dates
, date
);
1568 g_list_free_full (paths
, (GDestroyNotify
) gtk_tree_path_free
);
1571 if (event_mask
!= NULL
)
1574 if (subtype
!= NULL
)
1581 model_has_entity (GtkTreeModel
*model
,
1586 TplLogSearchHit
*hit
= data
;
1589 gboolean ret
= FALSE
;
1591 gtk_tree_model_get (model
, iter
,
1593 COL_WHO_ACCOUNT
, &a
,
1596 if (e
!= NULL
&& entity_equal (hit
->target
, e
) &&
1597 a
!= NULL
&& account_equal (hit
->account
, a
))
1599 ret
= has_element
= TRUE
;
1602 tp_clear_object (&e
);
1603 tp_clear_object (&a
);
1609 model_has_date (GtkTreeModel
*model
,
1617 gtk_tree_model_get (model
, iter
,
1621 if (!g_date_compare (date
, d
))
1633 get_events_for_date (TplActionChain
*chain
, gpointer user_data
);
1636 populate_events_from_search_hits (GList
*accounts
,
1640 TplEventTypeMask event_mask
;
1641 EventSubtype subtype
;
1644 gboolean is_anytime
= FALSE
;
1646 if (!log_window_get_selected (log_window
,
1647 NULL
, NULL
, NULL
, NULL
, &event_mask
, &subtype
))
1650 anytime
= g_date_new_dmy (2, 1, -1);
1651 if (g_list_find_custom (dates
, anytime
, (GCompareFunc
) g_date_compare
))
1654 for (l
= log_window
->priv
->hits
; l
!= NULL
; l
= l
->next
)
1656 TplLogSearchHit
*hit
= l
->data
;
1658 gboolean found
= FALSE
;
1660 /* Protect against invalid data (corrupt or old log files). */
1661 if (hit
->account
== NULL
|| hit
->target
== NULL
)
1664 for (acc
= accounts
, targ
= targets
;
1665 acc
!= NULL
&& targ
!= NULL
&& !found
;
1666 acc
= acc
->next
, targ
= targ
->next
)
1668 TpAccount
*account
= acc
->data
;
1669 TplEntity
*target
= targ
->data
;
1671 if (account_equal (hit
->account
, account
) &&
1672 entity_equal (hit
->target
, target
))
1680 g_list_find_custom (dates
, hit
->date
, (GCompareFunc
) g_date_compare
)
1685 ctx
= ctx_new (log_window
, hit
->account
, hit
->target
, hit
->date
,
1686 event_mask
, subtype
, log_window
->priv
->count
);
1687 _tpl_action_chain_append (log_window
->priv
->chain
,
1688 get_events_for_date
, ctx
);
1693 _tpl_action_chain_start (log_window
->priv
->chain
);
1695 g_date_free (anytime
);
1699 format_date_for_display (GDate
*date
)
1705 /* g_date_strftime sucks */
1707 now
= g_date_new ();
1708 g_date_set_time_t (now
, time (NULL
));
1710 days_elapsed
= g_date_days_between (date
, now
);
1712 if (days_elapsed
< 0)
1716 else if (days_elapsed
== 0)
1718 text
= g_strdup (_("Today"));
1720 else if (days_elapsed
== 1)
1722 text
= g_strdup (_("Yesterday"));
1728 dt
= g_date_time_new_utc (g_date_get_year (date
),
1729 g_date_get_month (date
), g_date_get_day (date
),
1732 if (days_elapsed
<= 7)
1733 text
= g_date_time_format (dt
, "%A");
1735 text
= g_date_time_format (dt
,
1736 /* Translators: A date such as '23 May 2010' (strftime format) */
1739 g_date_time_unref (dt
);
1748 add_date_if_needed (EmpathyLogWindow
*self
,
1751 GtkTreeModel
*model
;
1752 GtkListStore
*store
;
1755 model
= gtk_tree_view_get_model (GTK_TREE_VIEW (
1756 log_window
->priv
->treeview_when
));
1757 store
= GTK_LIST_STORE (model
);
1759 /* Add the date if it's not already there */
1760 has_element
= FALSE
;
1761 gtk_tree_model_foreach (model
, model_has_date
, date
);
1765 text
= format_date_for_display (date
);
1767 gtk_list_store_insert_with_values (store
, NULL
, -1,
1768 COL_WHEN_DATE
, date
,
1769 COL_WHEN_TEXT
, text
,
1770 COL_WHEN_ICON
, CALENDAR_ICON
,
1777 populate_dates_from_search_hits (GList
*accounts
,
1782 GtkTreeModel
*model
;
1783 GtkListStore
*store
;
1784 GtkTreeSelection
*selection
;
1787 if (log_window
== NULL
)
1790 view
= GTK_TREE_VIEW (log_window
->priv
->treeview_when
);
1791 model
= gtk_tree_view_get_model (view
);
1792 store
= GTK_LIST_STORE (model
);
1793 selection
= gtk_tree_view_get_selection (view
);
1795 for (l
= log_window
->priv
->hits
; l
!= NULL
; l
= l
->next
)
1797 TplLogSearchHit
*hit
= l
->data
;
1799 gboolean found
= FALSE
;
1801 /* Protect against invalid data (corrupt or old log files). */
1802 if (hit
->account
== NULL
|| hit
->target
== NULL
)
1805 for (acc
= accounts
, targ
= targets
;
1806 acc
!= NULL
&& targ
!= NULL
&& !found
;
1807 acc
= acc
->next
, targ
= targ
->next
)
1809 TpAccount
*account
= acc
->data
;
1810 TplEntity
*target
= targ
->data
;
1812 if (account_equal (hit
->account
, account
) &&
1813 entity_equal (hit
->target
, target
))
1820 add_date_if_needed (log_window
, hit
->date
);
1823 if (gtk_tree_model_get_iter_first (model
, &iter
))
1827 date
= g_date_new_dmy (1, 1, -1),
1829 gtk_list_store_prepend (store
, &iter
);
1830 gtk_list_store_set (store
, &iter
,
1831 COL_WHEN_DATE
, date
,
1832 COL_WHEN_TEXT
, "separator",
1837 date
= g_date_new_dmy (2, 1, -1),
1838 gtk_list_store_prepend (store
, &iter
);
1839 gtk_list_store_set (store
, &iter
,
1840 COL_WHEN_DATE
, date
,
1841 COL_WHEN_TEXT
, _("Anytime"),
1846 if (gtk_tree_model_iter_nth_child (model
, &iter
, NULL
, 2))
1847 gtk_tree_selection_select_iter (selection
, &iter
);
1852 add_event_to_store (EmpathyLogWindow
*self
,
1856 GtkListStore
*store
;
1857 TplEntityType type
= tpl_entity_get_entity_type (entity
);
1858 EmpathyContact
*contact
;
1861 gboolean room
= type
== TPL_ENTITY_ROOM
;
1863 store
= GTK_LIST_STORE (gtk_tree_view_get_model (
1864 GTK_TREE_VIEW (log_window
->priv
->treeview_who
)));
1866 contact
= empathy_contact_from_tpl_contact (account
, entity
);
1868 name
= empathy_contact_get_alias (contact
);
1869 sort_key
= g_utf8_collate_key (name
, -1);
1871 gtk_list_store_insert_with_values (store
, NULL
, -1,
1872 COL_WHO_TYPE
, COL_TYPE_NORMAL
,
1873 COL_WHO_ICON
, room
? EMPATHY_IMAGE_GROUP_MESSAGE
1874 : TPAW_IMAGE_AVATAR_DEFAULT
,
1876 COL_WHO_NAME_SORT_KEY
, sort_key
,
1877 COL_WHO_ID
, tpl_entity_get_identifier (entity
),
1878 COL_WHO_ACCOUNT
, account
,
1879 COL_WHO_TARGET
, entity
,
1883 g_object_unref (contact
);
1887 populate_entities_from_search_hits (void)
1889 EmpathyAccountChooser
*account_chooser
;
1892 GtkTreeModel
*model
;
1893 GtkTreeSelection
*selection
;
1895 GtkListStore
*store
;
1898 view
= GTK_TREE_VIEW (log_window
->priv
->treeview_who
);
1899 model
= gtk_tree_view_get_model (view
);
1900 store
= GTK_LIST_STORE (model
);
1901 selection
= gtk_tree_view_get_selection (view
);
1903 gtk_list_store_clear (store
);
1905 account_chooser
= EMPATHY_ACCOUNT_CHOOSER (log_window
->priv
->account_chooser
);
1906 account
= empathy_account_chooser_get_account (account_chooser
);
1908 for (l
= log_window
->priv
->hits
; l
; l
= l
->next
)
1910 TplLogSearchHit
*hit
= l
->data
;
1912 /* Protect against invalid data (corrupt or old log files). */
1913 if (hit
->account
== NULL
|| hit
->target
== NULL
)
1916 /* Filter based on the selected account */
1917 if (account
!= NULL
&& !account_equal (account
, hit
->account
))
1920 /* Add the entity if it's not already there */
1921 has_element
= FALSE
;
1922 gtk_tree_model_foreach (model
, model_has_entity
, hit
);
1925 add_event_to_store (log_window
, hit
->account
, hit
->target
);
1929 if (gtk_tree_model_get_iter_first (model
, &iter
))
1931 gtk_list_store_prepend (store
, &iter
);
1932 gtk_list_store_set (store
, &iter
,
1933 COL_WHO_TYPE
, COL_TYPE_SEPARATOR
,
1934 COL_WHO_NAME
, "separator",
1937 gtk_list_store_prepend (store
, &iter
);
1938 gtk_list_store_set (store
, &iter
,
1939 COL_WHO_TYPE
, COL_TYPE_ANY
,
1940 COL_WHO_NAME
, _("Anyone"),
1944 /* Select 'Anyone' */
1945 if (gtk_tree_model_get_iter_first (model
, &iter
))
1946 gtk_tree_selection_select_iter (selection
, &iter
);
1950 log_manager_searched_new_cb (GObject
*manager
,
1951 GAsyncResult
*result
,
1956 GtkTreeSelection
*selection
;
1957 GError
*error
= NULL
;
1959 if (log_window
== NULL
)
1962 if (!tpl_log_manager_search_finish (TPL_LOG_MANAGER (manager
),
1963 result
, &hits
, &error
))
1965 DEBUG ("%s. Aborting", error
->message
);
1966 g_error_free (error
);
1970 tp_clear_pointer (&log_window
->priv
->hits
, tpl_log_manager_search_free
);
1971 log_window
->priv
->hits
= hits
;
1973 view
= GTK_TREE_VIEW (log_window
->priv
->treeview_when
);
1974 selection
= gtk_tree_view_get_selection (view
);
1976 g_signal_handlers_unblock_by_func (selection
,
1977 log_window_when_changed_cb
,
1980 populate_entities_from_search_hits ();
1984 log_window_find_populate (EmpathyLogWindow
*self
,
1985 const gchar
*search_criteria
)
1988 GtkTreeModel
*model
;
1989 GtkTreeSelection
*selection
;
1990 GtkListStore
*store
;
1992 gtk_tree_store_clear (self
->priv
->store_events
);
1994 view
= GTK_TREE_VIEW (self
->priv
->treeview_who
);
1995 model
= gtk_tree_view_get_model (view
);
1996 store
= GTK_LIST_STORE (model
);
1998 gtk_list_store_clear (store
);
2000 view
= GTK_TREE_VIEW (self
->priv
->treeview_when
);
2001 model
= gtk_tree_view_get_model (view
);
2002 store
= GTK_LIST_STORE (model
);
2003 selection
= gtk_tree_view_get_selection (view
);
2005 gtk_list_store_clear (store
);
2007 if (TPAW_STR_EMPTY (search_criteria
))
2009 tp_clear_pointer (&self
->priv
->hits
, tpl_log_manager_search_free
);
2010 webkit_web_view_set_highlight_text_matches (
2011 WEBKIT_WEB_VIEW (self
->priv
->webview
), FALSE
);
2012 log_window_who_populate (self
);
2016 g_signal_handlers_block_by_func (selection
,
2017 log_window_when_changed_cb
,
2020 /* highlight the search text */
2021 webkit_web_view_mark_text_matches (WEBKIT_WEB_VIEW (self
->priv
->webview
),
2022 search_criteria
, FALSE
, 0);
2024 tpl_log_manager_search_async (self
->priv
->log_manager
,
2025 search_criteria
, TPL_EVENT_MASK_ANY
,
2026 log_manager_searched_new_cb
, NULL
);
2030 start_find_search (EmpathyLogWindow
*self
)
2034 str
= gtk_entry_get_text (GTK_ENTRY (self
->priv
->search_entry
));
2036 /* Don't find the same crap again */
2037 if (self
->priv
->last_find
&& !tp_strdiff (self
->priv
->last_find
, str
))
2040 g_free (self
->priv
->last_find
);
2041 self
->priv
->last_find
= g_strdup (str
);
2043 log_window_find_populate (self
, str
);
2049 log_window_search_entry_changed_cb (GtkWidget
*entry
,
2050 EmpathyLogWindow
*self
)
2054 str
= gtk_entry_get_text (GTK_ENTRY (self
->priv
->search_entry
));
2056 if (!tp_str_empty (str
))
2058 gtk_entry_set_icon_from_icon_name (GTK_ENTRY (self
->priv
->search_entry
),
2059 GTK_ENTRY_ICON_SECONDARY
, "edit-clear-symbolic");
2060 gtk_entry_set_icon_sensitive (GTK_ENTRY (self
->priv
->search_entry
),
2061 GTK_ENTRY_ICON_SECONDARY
, TRUE
);
2065 gtk_entry_set_icon_from_icon_name (GTK_ENTRY (self
->priv
->search_entry
),
2066 GTK_ENTRY_ICON_SECONDARY
, "edit-find-symbolic");
2067 gtk_entry_set_icon_sensitive (GTK_ENTRY (self
->priv
->search_entry
),
2068 GTK_ENTRY_ICON_SECONDARY
, FALSE
);
2071 if (self
->priv
->source
!= 0)
2072 g_source_remove (self
->priv
->source
);
2073 self
->priv
->source
= g_timeout_add (500, (GSourceFunc
) start_find_search
,
2078 log_window_search_entry_activate_cb (GtkWidget
*entry
,
2079 EmpathyLogWindow
*self
)
2081 start_find_search (self
);
2085 log_window_search_entry_icon_pressed_cb (GtkEntry
*entry
,
2086 GtkEntryIconPosition icon_pos
,
2090 if (icon_pos
!= GTK_ENTRY_ICON_SECONDARY
)
2093 gtk_entry_buffer_set_text (gtk_entry_get_buffer (entry
),
2098 do_update_buttons_sensitivity (EmpathyLogWindow
*self
)
2100 EmpathyCapabilities capabilities
;
2101 gboolean profile
, chat
, call
, video
;
2103 tp_clear_object (&self
->priv
->button_video_binding
);
2105 if (self
->priv
->selected_contact
!= NULL
)
2107 capabilities
= empathy_contact_get_capabilities (
2108 self
->priv
->selected_contact
);
2110 profile
= chat
= TRUE
;
2111 call
= capabilities
& EMPATHY_CAPABILITIES_AUDIO
;
2112 video
= capabilities
& EMPATHY_CAPABILITIES_VIDEO
;
2116 profile
= chat
= call
= video
= FALSE
;
2119 gtk_widget_set_sensitive (self
->priv
->button_profile
, profile
);
2120 gtk_widget_set_sensitive (self
->priv
->button_chat
, chat
);
2121 gtk_widget_set_sensitive (self
->priv
->button_call
, call
);
2125 self
->priv
->button_video_binding
= g_object_bind_property (
2126 self
->priv
->camera_monitor
, "available",
2127 self
->priv
->button_video
, "sensitive",
2128 G_BINDING_SYNC_CREATE
);
2132 /* Don't override the binding */
2133 gtk_widget_set_sensitive (self
->priv
->button_video
, video
);
2138 contact_capabilities_changed_cb (EmpathyContact
*contact
,
2140 EmpathyLogWindow
*self
)
2142 do_update_buttons_sensitivity (self
);
2146 log_window_update_buttons_sensitivity (EmpathyLogWindow
*self
)
2149 GtkTreeModel
*model
;
2150 GtkTreeSelection
*selection
;
2157 if (self
->priv
->selected_contact
!= NULL
)
2159 g_signal_handlers_disconnect_by_func (self
->priv
->selected_contact
,
2160 contact_capabilities_changed_cb
, self
);
2162 tp_clear_object (&self
->priv
->selected_contact
);
2165 view
= GTK_TREE_VIEW (self
->priv
->treeview_who
);
2166 model
= gtk_tree_view_get_model (view
);
2167 selection
= gtk_tree_view_get_selection (view
);
2169 if (!gtk_tree_model_get_iter_first (model
, &iter
))
2172 if (gtk_tree_selection_count_selected_rows (selection
) != 1)
2175 if (gtk_tree_selection_iter_is_selected (selection
, &iter
))
2178 paths
= gtk_tree_selection_get_selected_rows (selection
, &model
);
2179 g_return_if_fail (paths
!= NULL
);
2182 gtk_tree_model_get_iter (model
, &iter
, path
);
2183 gtk_tree_model_get (model
, &iter
,
2184 COL_WHO_ACCOUNT
, &account
,
2185 COL_WHO_TARGET
, &target
,
2188 g_list_free_full (paths
, (GDestroyNotify
) gtk_tree_path_free
);
2190 self
->priv
->selected_contact
= empathy_contact_from_tpl_contact (account
,
2193 g_object_unref (account
);
2194 g_object_unref (target
);
2199 /* If the Who pane doesn't contain a contact (e.g. it has many
2200 * selected, or has 'Anyone', let's try to get the contact from
2201 * the selected event. */
2203 if (self
->priv
->events_contact
!= NULL
)
2204 self
->priv
->selected_contact
= g_object_ref (self
->priv
->events_contact
);
2207 if (self
->priv
->selected_contact
!= NULL
)
2209 tp_g_signal_connect_object (self
->priv
->selected_contact
,
2210 "notify::capabilities", G_CALLBACK (contact_capabilities_changed_cb
),
2214 do_update_buttons_sensitivity (self
);
2218 log_window_update_what_iter_sensitivity (GtkTreeModel
*model
,
2222 GtkTreeStore
*store
= GTK_TREE_STORE (model
);
2226 gtk_tree_store_set (store
, iter
,
2227 COL_WHAT_SENSITIVE
, sensitive
,
2230 for (next
= gtk_tree_model_iter_children (model
, &child
, iter
);
2232 next
= gtk_tree_model_iter_next (model
, &child
))
2234 gtk_tree_store_set (store
, &child
,
2235 COL_WHAT_SENSITIVE
, sensitive
,
2241 log_window_update_what_sensitivity (EmpathyLogWindow
*self
)
2244 GtkTreeModel
*model
;
2246 GList
*accounts
, *targets
, *acc
, *targ
;
2249 if (!log_window_get_selected (self
, &accounts
, &targets
, NULL
, NULL
,
2253 view
= GTK_TREE_VIEW (self
->priv
->treeview_what
);
2254 model
= gtk_tree_view_get_model (view
);
2256 /* For each event type... */
2257 for (next
= gtk_tree_model_get_iter_first (model
, &iter
);
2259 next
= gtk_tree_model_iter_next (model
, &iter
))
2261 TplEventTypeMask type
;
2263 gtk_tree_model_get (model
, &iter
,
2264 COL_WHAT_TYPE
, &type
,
2267 /* ...we set the type and its subtypes (if any) unsensitive... */
2268 log_window_update_what_iter_sensitivity (model
, &iter
, FALSE
);
2270 for (acc
= accounts
, targ
= targets
;
2271 acc
!= NULL
&& targ
!= NULL
;
2272 acc
= acc
->next
, targ
= targ
->next
)
2274 TpAccount
*account
= acc
->data
;
2275 TplEntity
*target
= targ
->data
;
2277 if (tpl_log_manager_exists (self
->priv
->log_manager
,
2278 account
, target
, type
))
2280 /* And then we set it (and its subtypes, again, if any)
2281 * as sensitive if there are logs of that type. */
2282 log_window_update_what_iter_sensitivity (model
, &iter
, TRUE
);
2288 g_list_free_full (accounts
, g_object_unref
);
2289 g_list_free_full (targets
, g_object_unref
);
2293 log_window_who_changed_cb (GtkTreeSelection
*selection
,
2294 EmpathyLogWindow
*self
)
2297 GtkTreeModel
*model
;
2300 DEBUG ("log_window_who_changed_cb");
2302 view
= gtk_tree_selection_get_tree_view (selection
);
2303 model
= gtk_tree_view_get_model (view
);
2305 if (gtk_tree_model_get_iter_first (model
, &iter
))
2307 /* If 'Anyone' is selected, everything else should be deselected */
2308 if (gtk_tree_selection_iter_is_selected (selection
, &iter
))
2310 g_signal_handlers_block_by_func (selection
,
2311 log_window_who_changed_cb
,
2314 gtk_tree_selection_unselect_all (selection
);
2315 gtk_tree_selection_select_iter (selection
, &iter
);
2317 g_signal_handlers_unblock_by_func (selection
,
2318 log_window_who_changed_cb
,
2323 log_window_update_what_sensitivity (self
);
2324 log_window_update_buttons_sensitivity (self
);
2326 /* The contact changed, so the dates need to be updated */
2327 log_window_chats_get_messages (self
, TRUE
);
2331 log_manager_got_entities_cb (GObject
*manager
,
2332 GAsyncResult
*result
,
2335 Ctx
*ctx
= user_data
;
2339 GtkTreeModel
*model
;
2340 GtkTreeSelection
*selection
;
2341 GtkListStore
*store
;
2343 GError
*error
= NULL
;
2344 gboolean select_account
= FALSE
;
2346 if (log_window
== NULL
)
2349 if (log_window
->priv
->count
!= ctx
->count
)
2352 if (!tpl_log_manager_get_entities_finish (TPL_LOG_MANAGER (manager
),
2353 result
, &entities
, &error
))
2355 DEBUG ("%s. Aborting", error
->message
);
2356 g_error_free (error
);
2360 view
= GTK_TREE_VIEW (ctx
->self
->priv
->treeview_who
);
2361 model
= gtk_tree_view_get_model (view
);
2362 selection
= gtk_tree_view_get_selection (view
);
2363 store
= GTK_LIST_STORE (model
);
2365 /* Block signals to stop the logs being retrieved prematurely */
2366 g_signal_handlers_block_by_func (selection
,
2367 log_window_who_changed_cb
, ctx
->self
);
2369 for (l
= entities
; l
; l
= l
->next
)
2371 add_event_to_store (ctx
->self
, ctx
->account
, l
->data
);
2373 if (ctx
->self
->priv
->selected_account
!= NULL
&&
2374 !tp_strdiff (tp_proxy_get_object_path (ctx
->account
),
2375 tp_proxy_get_object_path (ctx
->self
->priv
->selected_account
)))
2376 select_account
= TRUE
;
2378 g_list_free_full (entities
, g_object_unref
);
2380 if (gtk_tree_model_get_iter_first (model
, &iter
))
2384 gtk_tree_model_get (model
, &iter
,
2385 COL_WHO_TYPE
, &type
,
2388 if (type
!= COL_TYPE_ANY
)
2390 gtk_list_store_prepend (store
, &iter
);
2391 gtk_list_store_set (store
, &iter
,
2392 COL_WHO_TYPE
, COL_TYPE_SEPARATOR
,
2393 COL_WHO_NAME
, "separator",
2396 gtk_list_store_prepend (store
, &iter
);
2397 gtk_list_store_set (store
, &iter
,
2398 COL_WHO_TYPE
, COL_TYPE_ANY
,
2399 COL_WHO_NAME
, _("Anyone"),
2404 /* Unblock signals */
2405 g_signal_handlers_unblock_by_func (selection
,
2406 log_window_who_changed_cb
,
2409 /* We display the selected account if we populate the model with chats from
2412 log_window_chats_set_selected (ctx
->self
);
2415 _tpl_action_chain_continue (log_window
->priv
->chain
);
2420 get_entities_for_account (TplActionChain
*chain
, gpointer user_data
)
2422 Ctx
*ctx
= user_data
;
2424 tpl_log_manager_get_entities_async (ctx
->self
->priv
->log_manager
, ctx
->account
,
2425 log_manager_got_entities_cb
, ctx
);
2429 select_first_entity (TplActionChain
*chain
, gpointer user_data
)
2431 EmpathyLogWindow
*self
= user_data
;
2433 GtkTreeModel
*model
;
2434 GtkTreeSelection
*selection
;
2437 view
= GTK_TREE_VIEW (self
->priv
->treeview_who
);
2438 model
= gtk_tree_view_get_model (view
);
2439 selection
= gtk_tree_view_get_selection (view
);
2441 if (gtk_tree_model_get_iter_first (model
, &iter
))
2442 gtk_tree_selection_select_iter (selection
, &iter
);
2444 _tpl_action_chain_continue (self
->priv
->chain
);
2448 log_window_who_populate (EmpathyLogWindow
*self
)
2450 EmpathyAccountChooser
*account_chooser
;
2452 gboolean all_accounts
;
2454 GtkTreeModel
*model
;
2455 GtkTreeSelection
*selection
;
2456 GtkListStore
*store
;
2459 if (self
->priv
->hits
!= NULL
)
2461 populate_entities_from_search_hits ();
2465 account_chooser
= EMPATHY_ACCOUNT_CHOOSER (self
->priv
->account_chooser
);
2466 account
= empathy_account_chooser_dup_account (account_chooser
);
2467 all_accounts
= empathy_account_chooser_has_all_selected (account_chooser
);
2469 view
= GTK_TREE_VIEW (self
->priv
->treeview_who
);
2470 model
= gtk_tree_view_get_model (view
);
2471 selection
= gtk_tree_view_get_selection (view
);
2472 store
= GTK_LIST_STORE (model
);
2474 /* Block signals to stop the logs being retrieved prematurely */
2475 g_signal_handlers_block_by_func (selection
,
2476 log_window_who_changed_cb
,
2479 gtk_list_store_clear (store
);
2481 /* Unblock signals */
2482 g_signal_handlers_unblock_by_func (selection
,
2483 log_window_who_changed_cb
,
2486 _tpl_action_chain_clear (self
->priv
->chain
);
2487 self
->priv
->count
++;
2489 if (!all_accounts
&& account
== NULL
)
2493 else if (!all_accounts
)
2495 ctx
= ctx_new (self
, account
, NULL
, NULL
, 0, 0, self
->priv
->count
);
2496 _tpl_action_chain_append (self
->priv
->chain
, get_entities_for_account
, ctx
);
2500 TpAccountManager
*manager
;
2501 GList
*accounts
, *l
;
2503 manager
= empathy_account_chooser_get_account_manager (account_chooser
);
2504 accounts
= tp_account_manager_dup_valid_accounts (manager
);
2506 for (l
= accounts
; l
!= NULL
; l
= l
->next
)
2510 ctx
= ctx_new (self
, account
, NULL
, NULL
, 0, 0, self
->priv
->count
);
2511 _tpl_action_chain_append (self
->priv
->chain
,
2512 get_entities_for_account
, ctx
);
2515 g_list_free_full (accounts
, g_object_unref
);
2517 _tpl_action_chain_append (self
->priv
->chain
, select_first_entity
, self
);
2518 _tpl_action_chain_start (self
->priv
->chain
);
2522 sort_by_name_key (GtkTreeModel
*model
,
2531 gtk_tree_model_get (model
, a
,
2532 COL_WHO_TYPE
, &type1
,
2533 COL_WHO_NAME_SORT_KEY
, &key1
,
2536 gtk_tree_model_get (model
, b
,
2537 COL_WHO_TYPE
, &type2
,
2538 COL_WHO_NAME_SORT_KEY
, &key2
,
2541 if (type1
== COL_TYPE_ANY
)
2543 else if (type2
== COL_TYPE_ANY
)
2545 else if (type1
== COL_TYPE_SEPARATOR
)
2547 else if (type2
== COL_TYPE_SEPARATOR
)
2550 ret
= g_strcmp0 (key1
, key2
);
2559 who_row_is_separator (GtkTreeModel
*model
,
2565 gtk_tree_model_get (model
, iter
,
2566 COL_WHO_TYPE
, &type
,
2569 return (type
== COL_TYPE_SEPARATOR
);
2573 log_window_find_row (EmpathyLogWindow
*self
,
2574 GdkEventButton
*event
)
2576 WebKitHitTestResult
*hit
= webkit_web_view_get_hit_test_result (
2577 WEBKIT_WEB_VIEW (self
->priv
->webview
), event
);
2578 WebKitDOMNode
*inner_node
;
2580 tp_clear_object (&self
->priv
->events_contact
);
2583 "inner-node", &inner_node
,
2586 if (inner_node
!= NULL
)
2588 GtkTreeModel
*model
= GTK_TREE_MODEL (self
->priv
->store_events
);
2589 WebKitDOMNode
*node
;
2590 const char *path
= NULL
;
2593 /* walk back up the DOM tree looking for a node with empathy:path set */
2594 for (node
= inner_node
; node
!= NULL
;
2595 node
= webkit_dom_node_get_parent_node (node
))
2597 if (!WEBKIT_DOM_IS_ELEMENT (node
))
2600 path
= webkit_dom_element_get_attribute_ns (
2601 WEBKIT_DOM_ELEMENT (node
), EMPATHY_NS
, "path");
2603 if (!tp_str_empty (path
))
2607 /* look up the contact for this path */
2608 if (!tp_str_empty (path
) &&
2609 gtk_tree_model_get_iter_from_string (model
, &iter
, path
))
2614 gtk_tree_model_get (model
, &iter
,
2615 COL_EVENTS_ACCOUNT
, &account
,
2616 COL_EVENTS_TARGET
, &target
,
2619 self
->priv
->events_contact
= empathy_contact_from_tpl_contact (
2622 g_object_unref (account
);
2623 g_object_unref (target
);
2626 g_object_unref (inner_node
);
2629 g_object_unref (hit
);
2631 log_window_update_buttons_sensitivity (self
);
2635 log_window_events_button_press_event (GtkWidget
*webview
,
2636 GdkEventButton
*event
,
2637 EmpathyLogWindow
*self
)
2639 switch (event
->button
)
2642 log_window_find_row (self
, event
);
2646 empathy_webkit_context_menu_for_event (
2647 WEBKIT_WEB_VIEW (webview
), event
, 0);
2658 log_window_events_setup (EmpathyLogWindow
*self
)
2660 GtkTreeSortable
*sortable
;
2661 GtkTreeStore
*store
;
2664 self
->priv
->store_events
= store
= gtk_tree_store_new (COL_EVENTS_COUNT
,
2665 G_TYPE_INT
, /* type */
2666 G_TYPE_INT64
, /* timestamp */
2667 G_TYPE_STRING
, /* stringified date */
2668 G_TYPE_STRING
, /* icon */
2669 G_TYPE_STRING
, /* name */
2670 TP_TYPE_ACCOUNT
, /* account */
2671 TPL_TYPE_ENTITY
, /* target */
2672 TPL_TYPE_EVENT
); /* event */
2674 sortable
= GTK_TREE_SORTABLE (store
);
2676 gtk_tree_sortable_set_sort_column_id (sortable
,
2678 GTK_SORT_ASCENDING
);
2682 log_window_who_setup (EmpathyLogWindow
*self
)
2685 GtkTreeModel
*model
;
2686 GtkTreeSelection
*selection
;
2687 GtkTreeSortable
*sortable
;
2688 GtkTreeViewColumn
*column
;
2689 GtkListStore
*store
;
2690 GtkCellRenderer
*cell
;
2692 view
= GTK_TREE_VIEW (self
->priv
->treeview_who
);
2693 selection
= gtk_tree_view_get_selection (view
);
2696 store
= gtk_list_store_new (COL_WHO_COUNT
,
2697 G_TYPE_INT
, /* type */
2698 G_TYPE_STRING
, /* icon */
2699 G_TYPE_STRING
, /* name */
2700 G_TYPE_STRING
, /* name sort key */
2701 G_TYPE_STRING
, /* id */
2702 TP_TYPE_ACCOUNT
, /* account */
2703 TPL_TYPE_ENTITY
); /* target */
2705 model
= GTK_TREE_MODEL (store
);
2706 sortable
= GTK_TREE_SORTABLE (store
);
2708 gtk_tree_view_set_model (view
, model
);
2711 column
= gtk_tree_view_column_new ();
2712 gtk_tree_view_column_set_title (column
, _("Who"));
2714 cell
= gtk_cell_renderer_pixbuf_new ();
2715 gtk_tree_view_column_pack_start (column
, cell
, FALSE
);
2716 gtk_tree_view_column_add_attribute (column
, cell
,
2720 cell
= gtk_cell_renderer_text_new ();
2721 g_object_set (cell
, "ellipsize", PANGO_ELLIPSIZE_END
, NULL
);
2722 gtk_tree_view_column_pack_start (column
, cell
, TRUE
);
2723 gtk_tree_view_column_add_attribute (column
, cell
,
2727 gtk_tree_view_append_column (view
, column
);
2729 /* set up treeview properties */
2730 gtk_tree_selection_set_mode (selection
, GTK_SELECTION_MULTIPLE
);
2731 gtk_tree_view_set_row_separator_func (view
, who_row_is_separator
,
2734 gtk_tree_sortable_set_sort_column_id (sortable
,
2735 COL_WHO_NAME_SORT_KEY
,
2736 GTK_SORT_ASCENDING
);
2737 gtk_tree_sortable_set_sort_func (sortable
,
2738 COL_WHO_NAME_SORT_KEY
, sort_by_name_key
,
2741 gtk_tree_view_set_search_column (view
, COL_WHO_NAME
);
2742 gtk_tree_view_set_tooltip_column (view
, COL_WHO_ID
);
2744 /* set up signals */
2745 g_signal_connect (selection
, "changed",
2746 G_CALLBACK (log_window_who_changed_cb
), self
);
2748 g_object_unref (store
);
2752 log_window_chats_accounts_changed_cb (GtkWidget
*combobox
,
2753 EmpathyLogWindow
*self
)
2755 /* Clear all current messages shown in the textview */
2756 gtk_tree_store_clear (self
->priv
->store_events
);
2758 log_window_who_populate (self
);
2762 log_window_chats_set_selected (EmpathyLogWindow
*self
)
2765 GtkTreeModel
*model
;
2766 GtkTreeSelection
*selection
;
2771 view
= GTK_TREE_VIEW (self
->priv
->treeview_who
);
2772 model
= gtk_tree_view_get_model (view
);
2773 selection
= gtk_tree_view_get_selection (view
);
2775 for (next
= gtk_tree_model_get_iter_first (model
, &iter
);
2777 next
= gtk_tree_model_iter_next (model
, &iter
))
2779 TpAccount
*this_account
;
2780 TplEntity
*this_target
;
2781 const gchar
*this_chat_id
;
2782 gboolean this_is_chatroom
;
2785 gtk_tree_model_get (model
, &iter
,
2786 COL_WHO_TYPE
, &this_type
,
2787 COL_WHO_ACCOUNT
, &this_account
,
2788 COL_WHO_TARGET
, &this_target
,
2791 if (this_type
!= COL_TYPE_NORMAL
)
2794 this_chat_id
= tpl_entity_get_identifier (this_target
);
2795 this_is_chatroom
= tpl_entity_get_entity_type (this_target
)
2798 if (this_account
== self
->priv
->selected_account
&&
2799 !tp_strdiff (this_chat_id
, self
->priv
->selected_chat_id
) &&
2800 this_is_chatroom
== self
->priv
->selected_is_chatroom
)
2802 gtk_tree_selection_select_iter (selection
, &iter
);
2803 path
= gtk_tree_model_get_path (model
, &iter
);
2804 gtk_tree_view_scroll_to_cell (view
, path
, NULL
, TRUE
, 0.5, 0.0);
2805 gtk_tree_path_free (path
);
2806 g_object_unref (this_account
);
2807 g_object_unref (this_target
);
2811 g_object_unref (this_account
);
2812 g_object_unref (this_target
);
2815 tp_clear_object (&self
->priv
->selected_account
);
2816 tp_clear_pointer (&self
->priv
->selected_chat_id
, g_free
);
2820 sort_by_date (GtkTreeModel
*model
,
2825 GDate
*date1
, *date2
;
2828 gtk_tree_model_get (model
, a
,
2829 COL_WHEN_DATE
, &date1
,
2832 gtk_tree_model_get (model
, b
,
2833 COL_WHEN_DATE
, &date2
,
2836 result
= g_date_compare (date1
, date2
);
2838 g_date_free (date1
);
2839 g_date_free (date2
);
2844 when_row_is_separator (GtkTreeModel
*model
,
2851 gtk_tree_model_get (model
, iter
,
2852 COL_WHEN_TEXT
, &when
,
2855 ret
= !tp_strdiff (when
, "separator");
2861 log_window_when_changed_cb (GtkTreeSelection
*selection
,
2862 EmpathyLogWindow
*self
)
2865 GtkTreeModel
*model
;
2868 DEBUG ("log_window_when_changed_cb");
2870 view
= gtk_tree_selection_get_tree_view (selection
);
2871 model
= gtk_tree_view_get_model (view
);
2873 /* If 'Anytime' is selected, everything else should be deselected */
2874 if (gtk_tree_model_get_iter_first (model
, &iter
))
2876 if (gtk_tree_selection_iter_is_selected (selection
, &iter
))
2878 g_signal_handlers_block_by_func (selection
,
2879 log_window_when_changed_cb
,
2882 gtk_tree_selection_unselect_all (selection
);
2883 gtk_tree_selection_select_iter (selection
, &iter
);
2885 g_signal_handlers_unblock_by_func (selection
,
2886 log_window_when_changed_cb
,
2891 log_window_chats_get_messages (self
, FALSE
);
2895 log_window_when_setup (EmpathyLogWindow
*self
)
2898 GtkTreeModel
*model
;
2899 GtkTreeSelection
*selection
;
2900 GtkTreeSortable
*sortable
;
2901 GtkTreeViewColumn
*column
;
2902 GtkListStore
*store
;
2903 GtkCellRenderer
*cell
;
2905 view
= GTK_TREE_VIEW (self
->priv
->treeview_when
);
2906 selection
= gtk_tree_view_get_selection (view
);
2909 store
= gtk_list_store_new (COL_WHEN_COUNT
,
2910 G_TYPE_DATE
, /* date */
2911 G_TYPE_STRING
, /* stringified date */
2912 G_TYPE_STRING
); /* icon */
2914 model
= GTK_TREE_MODEL (store
);
2915 sortable
= GTK_TREE_SORTABLE (store
);
2917 gtk_tree_view_set_model (view
, model
);
2920 column
= gtk_tree_view_column_new ();
2921 gtk_tree_view_column_set_title (column
, _("When"));
2923 cell
= gtk_cell_renderer_pixbuf_new ();
2924 gtk_tree_view_column_pack_start (column
, cell
, FALSE
);
2925 gtk_tree_view_column_add_attribute (column
, cell
,
2926 "icon-name", COL_WHEN_ICON
);
2928 cell
= gtk_cell_renderer_text_new ();
2929 g_object_set (cell
, "ellipsize", PANGO_ELLIPSIZE_END
, NULL
);
2930 gtk_tree_view_column_pack_start (column
, cell
, TRUE
);
2931 gtk_tree_view_column_add_attribute (column
, cell
,
2935 gtk_tree_view_append_column (view
, column
);
2937 /* set up treeview properties */
2938 gtk_tree_selection_set_mode (selection
, GTK_SELECTION_MULTIPLE
);
2939 gtk_tree_view_set_row_separator_func (view
, when_row_is_separator
,
2941 gtk_tree_sortable_set_sort_column_id (sortable
,
2943 GTK_SORT_DESCENDING
);
2944 gtk_tree_sortable_set_sort_func (sortable
,
2945 COL_WHEN_DATE
, sort_by_date
,
2948 gtk_tree_view_set_search_column (view
, COL_WHEN_TEXT
);
2950 /* set up signals */
2951 g_signal_connect (selection
, "changed",
2952 G_CALLBACK (log_window_when_changed_cb
),
2955 g_object_unref (store
);
2959 what_row_is_separator (GtkTreeModel
*model
,
2965 gtk_tree_model_get (model
, iter
,
2966 COL_WHAT_TYPE
, &type
,
2969 return (type
== WHAT_TYPE_SEPARATOR
);
2973 log_window_what_changed_cb (GtkTreeSelection
*selection
,
2974 EmpathyLogWindow
*self
)
2977 GtkTreeModel
*model
;
2980 DEBUG ("log_window_what_changed_cb");
2982 view
= gtk_tree_selection_get_tree_view (selection
);
2983 model
= gtk_tree_view_get_model (view
);
2985 /* If 'Anything' is selected, everything else should be deselected */
2986 if (gtk_tree_model_get_iter_first (model
, &iter
))
2988 if (gtk_tree_selection_iter_is_selected (selection
, &iter
))
2990 g_signal_handlers_block_by_func (selection
,
2991 log_window_what_changed_cb
,
2994 gtk_tree_selection_unselect_all (selection
);
2995 gtk_tree_selection_select_iter (selection
, &iter
);
2997 g_signal_handlers_unblock_by_func (selection
,
2998 log_window_what_changed_cb
,
3003 /* The dates need to be updated if we're not searching */
3004 log_window_chats_get_messages (self
, self
->priv
->hits
== NULL
);
3008 log_window_what_collapse_row_cb (GtkTreeView
*tree_view
,
3013 /* Reject collapsing */
3020 EventSubtype subtype
;
3026 log_window_what_setup (EmpathyLogWindow
*self
)
3029 GtkTreeModel
*model
;
3030 GtkTreeSelection
*selection
;
3031 GtkTreeViewColumn
*column
;
3033 GtkTreeStore
*store
;
3034 GtkCellRenderer
*cell
;
3038 struct event events
[] = {
3039 { TPL_EVENT_MASK_ANY
, 0, NULL
, _("Anything") },
3040 { WHAT_TYPE_SEPARATOR
, 0, NULL
, "separator" },
3041 { TPL_EVENT_MASK_TEXT
, 0, "format-justify-fill", _("Text chats") },
3042 { TPL_EVENT_MASK_CALL
, EVENT_CALL_ALL
, EMPATHY_IMAGE_CALL
, _("Calls") },
3045 struct event call_events
[] = {
3046 { TPL_EVENT_MASK_CALL
, EVENT_CALL_INCOMING
, EMPATHY_IMAGE_CALL_INCOMING
, _("Incoming calls") },
3047 { TPL_EVENT_MASK_CALL
, EVENT_CALL_OUTGOING
, EMPATHY_IMAGE_CALL_OUTGOING
, _("Outgoing calls") },
3048 { TPL_EVENT_MASK_CALL
, EVENT_CALL_MISSED
, EMPATHY_IMAGE_CALL_MISSED
, _("Missed calls") }
3051 view
= GTK_TREE_VIEW (self
->priv
->treeview_what
);
3052 selection
= gtk_tree_view_get_selection (view
);
3055 store
= gtk_tree_store_new (COL_WHAT_COUNT
,
3056 G_TYPE_INT
, /* history type */
3057 G_TYPE_INT
, /* history subtype */
3058 G_TYPE_BOOLEAN
, /* sensitive */
3059 G_TYPE_STRING
, /* stringified history type */
3060 G_TYPE_STRING
); /* icon */
3062 model
= GTK_TREE_MODEL (store
);
3064 gtk_tree_view_set_model (view
, model
);
3067 column
= gtk_tree_view_column_new ();
3068 gtk_tree_view_column_set_title (column
, _("What"));
3070 cell
= gtk_cell_renderer_pixbuf_new ();
3071 gtk_tree_view_column_pack_start (column
, cell
, FALSE
);
3072 gtk_tree_view_column_add_attribute (column
, cell
,
3073 "icon-name", COL_WHAT_ICON
);
3075 cell
= gtk_cell_renderer_text_new ();
3076 g_object_set (cell
, "ellipsize", PANGO_ELLIPSIZE_END
, NULL
);
3077 gtk_tree_view_column_pack_start (column
, cell
, TRUE
);
3078 gtk_tree_view_column_add_attribute (column
, cell
,
3079 "text", COL_WHAT_TEXT
);
3080 gtk_tree_view_column_add_attribute (column
, cell
,
3081 "sensitive", COL_WHAT_SENSITIVE
);
3083 gtk_tree_view_append_column (view
, column
);
3084 gtk_tree_view_set_search_column (view
, COL_WHAT_TEXT
);
3086 /* set up treeview properties */
3087 gtk_tree_selection_set_mode (selection
, GTK_SELECTION_MULTIPLE
);
3088 gtk_tree_view_set_show_expanders (view
, FALSE
);
3089 gtk_tree_view_set_level_indentation (view
, 12);
3090 gtk_tree_view_expand_all (view
);
3091 gtk_tree_view_set_row_separator_func (view
, what_row_is_separator
,
3095 for (i
= 0; i
< G_N_ELEMENTS (events
); i
++)
3097 gtk_tree_store_append (store
, &iter
, NULL
);
3098 gtk_tree_store_set (store
, &iter
,
3099 COL_WHAT_TYPE
, events
[i
].type
,
3100 COL_WHAT_SUBTYPE
, events
[i
].subtype
,
3101 COL_WHAT_SENSITIVE
, TRUE
,
3102 COL_WHAT_TEXT
, events
[i
].text
,
3103 COL_WHAT_ICON
, events
[i
].icon
,
3107 gtk_tree_model_iter_nth_child (model
, &parent
, NULL
, 3);
3108 for (i
= 0; i
< G_N_ELEMENTS (call_events
); i
++)
3110 gtk_tree_store_append (store
, &iter
, &parent
);
3111 gtk_tree_store_set (store
, &iter
,
3112 COL_WHAT_TYPE
, call_events
[i
].type
,
3113 COL_WHAT_SUBTYPE
, call_events
[i
].subtype
,
3114 COL_WHAT_SENSITIVE
, TRUE
,
3115 COL_WHAT_TEXT
, call_events
[i
].text
,
3116 COL_WHAT_ICON
, call_events
[i
].icon
,
3120 gtk_tree_view_expand_all (view
);
3122 /* select 'Anything' */
3123 if (gtk_tree_model_get_iter_first (model
, &iter
))
3124 gtk_tree_selection_select_iter (selection
, &iter
);
3126 /* set up signals */
3127 g_signal_connect (view
, "test-collapse-row",
3128 G_CALLBACK (log_window_what_collapse_row_cb
),
3130 g_signal_connect (selection
, "changed",
3131 G_CALLBACK (log_window_what_changed_cb
),
3134 g_object_unref (store
);
3138 log_window_maybe_expand_events (void)
3140 GtkTreeModel
*model
= GTK_TREE_MODEL (log_window
->priv
->store_events
);
3142 /* If there's only one result, expand it */
3143 if (gtk_tree_model_iter_n_children (model
, NULL
) == 1)
3144 webkit_web_view_execute_script (
3145 WEBKIT_WEB_VIEW (log_window
->priv
->webview
),
3146 "javascript:expandAll()");
3150 show_spinner (gpointer data
)
3154 if (log_window
== NULL
)
3157 g_object_get (log_window
->priv
->spinner
, "active", &active
, NULL
);
3160 gtk_notebook_set_current_page (GTK_NOTEBOOK (log_window
->priv
->notebook
),
3167 show_events (TplActionChain
*chain
,
3170 log_window_maybe_expand_events ();
3171 gtk_spinner_stop (GTK_SPINNER (log_window
->priv
->spinner
));
3172 gtk_notebook_set_current_page (GTK_NOTEBOOK (log_window
->priv
->notebook
),
3175 _tpl_action_chain_continue (chain
);
3179 start_spinner (void)
3181 gtk_spinner_start (GTK_SPINNER (log_window
->priv
->spinner
));
3182 gtk_notebook_set_current_page (GTK_NOTEBOOK (log_window
->priv
->notebook
),
3185 g_timeout_add (1000, show_spinner
, NULL
);
3186 _tpl_action_chain_append (log_window
->priv
->chain
, show_events
, NULL
);
3190 log_window_got_messages_for_date_cb (GObject
*manager
,
3191 GAsyncResult
*result
,
3194 Ctx
*ctx
= user_data
;
3195 GtkTreeModel
*model
;
3199 GError
*error
= NULL
;
3202 if (log_window
== NULL
)
3208 if (log_window
->priv
->count
!= ctx
->count
)
3211 if (!tpl_log_manager_get_events_for_date_finish (TPL_LOG_MANAGER (manager
),
3212 result
, &events
, &error
))
3214 DEBUG ("Unable to retrieve messages for the selected date: %s. Aborting",
3216 g_error_free (error
);
3220 for (l
= events
; l
; l
= l
->next
)
3222 TplEvent
*event
= l
->data
;
3223 gboolean append
= TRUE
;
3225 if (TPL_IS_CALL_EVENT (l
->data
)
3226 && ctx
->event_mask
& TPL_EVENT_MASK_CALL
3227 && ctx
->event_mask
!= TPL_EVENT_MASK_ANY
)
3229 TplCallEvent
*call
= l
->data
;
3233 if (ctx
->subtype
& EVENT_CALL_ALL
)
3239 TpCallStateChangeReason reason
=
3240 tpl_call_event_get_end_reason (call
);
3241 TplEntity
*sender
= tpl_event_get_sender (event
);
3242 TplEntity
*receiver
= tpl_event_get_receiver (event
);
3244 if (reason
== TP_CALL_STATE_CHANGE_REASON_NO_ANSWER
)
3246 if (ctx
->subtype
& EVENT_CALL_MISSED
)
3249 else if (ctx
->subtype
& EVENT_CALL_OUTGOING
3250 && tpl_entity_get_entity_type (sender
) == TPL_ENTITY_SELF
)
3254 else if (ctx
->subtype
& EVENT_CALL_INCOMING
3255 && tpl_entity_get_entity_type (receiver
) == TPL_ENTITY_SELF
)
3264 EmpathyMessage
*msg
= empathy_message_from_tpl_log_event (event
);
3265 log_window_append_message (event
, msg
);
3266 tp_clear_object (&msg
);
3269 g_object_unref (event
);
3271 g_list_free (events
);
3273 model
= GTK_TREE_MODEL (log_window
->priv
->store_events
);
3274 n
= gtk_tree_model_iter_n_children (model
, NULL
) - 1;
3276 if (n
>= 0 && gtk_tree_model_iter_nth_child (model
, &iter
, NULL
, n
))
3281 path
= gtk_tree_model_get_path (model
, &iter
);
3282 str
= gtk_tree_path_to_string (path
);
3284 script
= g_strdup_printf ("javascript:scrollToRow([%s]);",
3285 g_strdelimit (str
, ":", ','));
3287 webkit_web_view_execute_script (
3288 WEBKIT_WEB_VIEW (log_window
->priv
->webview
),
3291 gtk_tree_path_free (path
);
3299 _tpl_action_chain_continue (log_window
->priv
->chain
);
3303 get_events_for_date (TplActionChain
*chain
, gpointer user_data
)
3305 Ctx
*ctx
= user_data
;
3307 tpl_log_manager_get_events_for_date_async (ctx
->self
->priv
->log_manager
,
3308 ctx
->account
, ctx
->entity
, ctx
->event_mask
,
3310 log_window_got_messages_for_date_cb
,
3315 log_window_get_messages_for_dates (EmpathyLogWindow
*self
,
3318 GList
*accounts
, *targets
, *acc
, *targ
, *l
;
3319 TplEventTypeMask event_mask
;
3320 EventSubtype subtype
;
3321 GDate
*date
, *anytime
, *separator
;
3323 if (!log_window_get_selected (self
,
3324 &accounts
, &targets
, NULL
, NULL
, &event_mask
, &subtype
))
3327 anytime
= g_date_new_dmy (2, 1, -1);
3328 separator
= g_date_new_dmy (1, 1, -1);
3330 _tpl_action_chain_clear (self
->priv
->chain
);
3331 self
->priv
->count
++;
3333 for (acc
= accounts
, targ
= targets
;
3334 acc
!= NULL
&& targ
!= NULL
;
3335 acc
= acc
->next
, targ
= targ
->next
)
3337 TpAccount
*account
= acc
->data
;
3338 TplEntity
*target
= targ
->data
;
3340 for (l
= dates
; l
!= NULL
; l
= l
->next
)
3345 if (g_date_compare (date
, anytime
) != 0)
3349 ctx
= ctx_new (self
, account
, target
, date
, event_mask
, subtype
,
3351 _tpl_action_chain_append (self
->priv
->chain
, get_events_for_date
, ctx
);
3355 GtkTreeView
*view
= GTK_TREE_VIEW (self
->priv
->treeview_when
);
3356 GtkTreeModel
*model
= gtk_tree_view_get_model (view
);
3361 for (next
= gtk_tree_model_get_iter_first (model
, &iter
);
3363 next
= gtk_tree_model_iter_next (model
, &iter
))
3367 gtk_tree_model_get (model
, &iter
,
3371 if (g_date_compare (d
, anytime
) != 0 &&
3372 g_date_compare (d
, separator
) != 0)
3374 ctx
= ctx_new (self
, account
, target
, d
,
3375 event_mask
, subtype
, self
->priv
->count
);
3376 _tpl_action_chain_append (self
->priv
->chain
, get_events_for_date
, ctx
);
3386 _tpl_action_chain_start (self
->priv
->chain
);
3388 g_list_free_full (accounts
, g_object_unref
);
3389 g_list_free_full (targets
, g_object_unref
);
3390 g_date_free (separator
);
3391 g_date_free (anytime
);
3395 log_manager_got_dates_cb (GObject
*manager
,
3396 GAsyncResult
*result
,
3399 Ctx
*ctx
= user_data
;
3401 GtkTreeModel
*model
;
3402 GtkListStore
*store
;
3406 GError
*error
= NULL
;
3408 if (log_window
== NULL
)
3414 if (log_window
->priv
->count
!= ctx
->count
)
3417 if (!tpl_log_manager_get_dates_finish (TPL_LOG_MANAGER (manager
),
3418 result
, &dates
, &error
))
3420 DEBUG ("Unable to retrieve messages' dates: %s. Aborting",
3425 view
= GTK_TREE_VIEW (log_window
->priv
->treeview_when
);
3426 model
= gtk_tree_view_get_model (view
);
3427 store
= GTK_LIST_STORE (model
);
3429 for (l
= dates
; l
!= NULL
; l
= l
->next
)
3431 add_date_if_needed (log_window
, l
->data
);
3434 if (gtk_tree_model_get_iter_first (model
, &iter
))
3436 gchar
*separator
= NULL
;
3438 if (gtk_tree_model_iter_next (model
, &iter
))
3440 gtk_tree_model_get (model
, &iter
,
3441 COL_WHEN_TEXT
, &separator
,
3445 if (g_strcmp0 (separator
, "separator") != 0)
3449 date
= g_date_new_dmy (1, 1, -1);
3451 gtk_list_store_prepend (store
, &iter
);
3452 gtk_list_store_set (store
, &iter
,
3453 COL_WHEN_DATE
, date
,
3454 COL_WHEN_TEXT
, "separator",
3459 date
= g_date_new_dmy (2, 1, -1);
3461 gtk_list_store_prepend (store
, &iter
);
3462 gtk_list_store_set (store
, &iter
,
3463 COL_WHEN_DATE
, date
,
3464 COL_WHEN_TEXT
, _("Anytime"),
3473 g_list_free_full (dates
, g_free
);
3476 _tpl_action_chain_continue (log_window
->priv
->chain
);
3480 select_date (TplActionChain
*chain
, gpointer user_data
)
3483 GtkTreeModel
*model
;
3484 GtkTreeSelection
*selection
;
3487 gboolean selected
= FALSE
;
3489 view
= GTK_TREE_VIEW (log_window
->priv
->treeview_when
);
3490 model
= gtk_tree_view_get_model (view
);
3491 selection
= gtk_tree_view_get_selection (view
);
3493 if (log_window
->priv
->current_dates
!= NULL
)
3495 for (next
= gtk_tree_model_get_iter_first (model
, &iter
);
3497 next
= gtk_tree_model_iter_next (model
, &iter
))
3501 gtk_tree_model_get (model
, &iter
,
3502 COL_WHEN_DATE
, &date
,
3505 if (g_list_find_custom (log_window
->priv
->current_dates
, date
,
3506 (GCompareFunc
) g_date_compare
) != NULL
)
3510 gtk_tree_selection_select_iter (selection
, &iter
);
3511 path
= gtk_tree_model_get_path (model
, &iter
);
3512 gtk_tree_view_scroll_to_cell (view
, path
, NULL
, FALSE
, 0, 0);
3515 gtk_tree_path_free (path
);
3524 /* Show messages of the most recent date */
3525 if (gtk_tree_model_iter_nth_child (model
, &iter
, NULL
, 2))
3526 gtk_tree_selection_select_iter (selection
, &iter
);
3529 _tpl_action_chain_continue (log_window
->priv
->chain
);
3533 get_dates_for_entity (TplActionChain
*chain
, gpointer user_data
)
3535 Ctx
*ctx
= user_data
;
3537 tpl_log_manager_get_dates_async (ctx
->self
->priv
->log_manager
,
3538 ctx
->account
, ctx
->entity
, ctx
->event_mask
,
3539 log_manager_got_dates_cb
, ctx
);
3543 log_window_chats_get_messages (EmpathyLogWindow
*self
,
3544 gboolean force_get_dates
)
3546 GList
*accounts
, *targets
, *dates
;
3547 TplEventTypeMask event_mask
;
3549 GtkTreeModel
*model
;
3550 GtkListStore
*store
;
3551 GtkTreeSelection
*selection
;
3553 if (!log_window_get_selected (self
, &accounts
, &targets
, NULL
,
3554 &dates
, &event_mask
, NULL
))
3557 view
= GTK_TREE_VIEW (self
->priv
->treeview_when
);
3558 selection
= gtk_tree_view_get_selection (view
);
3559 model
= gtk_tree_view_get_model (view
);
3560 store
= GTK_LIST_STORE (model
);
3562 /* Clear all current messages shown in the textview */
3563 gtk_tree_store_clear (self
->priv
->store_events
);
3565 _tpl_action_chain_clear (self
->priv
->chain
);
3566 self
->priv
->count
++;
3568 /* If there's a search use the returned hits */
3569 if (self
->priv
->hits
!= NULL
)
3571 if (force_get_dates
)
3573 g_signal_handlers_block_by_func (selection
,
3574 log_window_when_changed_cb
,
3577 gtk_list_store_clear (store
);
3579 g_signal_handlers_unblock_by_func (selection
,
3580 log_window_when_changed_cb
,
3583 populate_dates_from_search_hits (accounts
, targets
);
3587 populate_events_from_search_hits (accounts
, targets
, dates
);
3590 /* Either use the supplied date or get the last */
3591 else if (force_get_dates
|| dates
== NULL
)
3595 if (self
->priv
->current_dates
!= NULL
)
3597 g_list_free_full (self
->priv
->current_dates
,
3598 (GDestroyNotify
) g_date_free
);
3599 self
->priv
->current_dates
= NULL
;
3602 if (gtk_tree_selection_count_selected_rows (selection
) > 0)
3607 paths
= gtk_tree_selection_get_selected_rows (selection
, NULL
);
3609 for (l
= paths
; l
!= NULL
; l
= l
->next
)
3611 GtkTreePath
*path
= l
->data
;
3614 gtk_tree_model_get_iter (model
, &iter
, path
);
3615 gtk_tree_model_get (model
, &iter
,
3616 COL_WHEN_DATE
, &date
,
3619 /* The list takes ownership of the date. */
3620 self
->priv
->current_dates
=
3621 g_list_prepend (self
->priv
->current_dates
, date
);
3624 g_list_free_full (paths
, (GDestroyNotify
) gtk_tree_path_free
);
3627 g_signal_handlers_block_by_func (selection
,
3628 log_window_when_changed_cb
,
3631 gtk_list_store_clear (store
);
3633 g_signal_handlers_unblock_by_func (selection
,
3634 log_window_when_changed_cb
,
3637 /* Get a list of dates and show them on the treeview */
3638 for (targ
= targets
, acc
= accounts
;
3639 targ
!= NULL
&& acc
!= NULL
;
3640 targ
= targ
->next
, acc
= acc
->next
)
3642 TpAccount
*account
= acc
->data
;
3643 TplEntity
*target
= targ
->data
;
3644 Ctx
*ctx
= ctx_new (self
, account
, target
, NULL
, event_mask
, 0,
3647 _tpl_action_chain_append (self
->priv
->chain
, get_dates_for_entity
, ctx
);
3649 _tpl_action_chain_append (self
->priv
->chain
, select_date
, NULL
);
3650 _tpl_action_chain_start (self
->priv
->chain
);
3654 /* Show messages of the selected date */
3655 log_window_get_messages_for_dates (self
, dates
);
3658 g_list_free_full (accounts
, g_object_unref
);
3659 g_list_free_full (targets
, g_object_unref
);
3660 g_list_free_full (dates
, (GFreeFunc
) g_date_free
);
3664 EmpathyAccountChooserFilterResultCallback callback
;
3666 } FilterCallbackData
;
3669 got_entities (GObject
*manager
,
3670 GAsyncResult
*result
,
3673 FilterCallbackData
*data
= user_data
;
3675 GError
*error
= NULL
;
3677 if (!tpl_log_manager_get_entities_finish (TPL_LOG_MANAGER (manager
),
3678 result
, &entities
, &error
))
3680 DEBUG ("Could not get entities: %s", error
->message
);
3681 g_error_free (error
);
3682 data
->callback (FALSE
, data
->user_data
);
3686 data
->callback (entities
!= NULL
, data
->user_data
);
3688 g_list_free_full (entities
, g_object_unref
);
3691 g_slice_free (FilterCallbackData
, data
);
3695 empathy_account_chooser_filter_has_logs (TpAccount
*account
,
3696 EmpathyAccountChooserFilterResultCallback callback
,
3697 gpointer callback_data
,
3700 TplLogManager
*manager
= tpl_log_manager_dup_singleton ();
3701 FilterCallbackData
*cb_data
= g_slice_new0 (FilterCallbackData
);
3703 cb_data
->callback
= callback
;
3704 cb_data
->user_data
= callback_data
;
3706 tpl_log_manager_get_entities_async (manager
, account
, got_entities
, cb_data
);
3708 g_object_unref (manager
);
3712 log_window_logger_clear_account_cb (TpProxy
*proxy
,
3713 const GError
*error
,
3715 GObject
*weak_object
)
3717 EmpathyLogWindow
*self
= EMPATHY_LOG_WINDOW (user_data
);
3720 g_warning ("Error when clearing logs: %s", error
->message
);
3722 /* Refresh the log viewer so the logs are cleared if the account
3723 * has been deleted */
3724 gtk_tree_store_clear (self
->priv
->store_events
);
3725 log_window_who_populate (self
);
3727 /* Re-filter the account chooser so the accounts without logs get
3729 empathy_account_chooser_refilter (
3730 EMPATHY_ACCOUNT_CHOOSER (self
->priv
->account_chooser
));
3734 log_window_delete_menu_clicked_cb (GtkMenuItem
*menuitem
,
3735 EmpathyLogWindow
*self
)
3737 GtkWidget
*dialog
, *content_area
, *hbox
, *label
;
3738 EmpathyAccountChooser
*account_chooser
;
3742 GError
*error
= NULL
;
3744 account_chooser
= (EmpathyAccountChooser
*) empathy_account_chooser_new ();
3745 empathy_account_chooser_set_has_all_option (account_chooser
, TRUE
);
3747 empathy_account_chooser_refilter (account_chooser
);
3749 /* Select the same account as in the history window */
3750 empathy_account_chooser_set_account (account_chooser
,
3751 empathy_account_chooser_get_account (
3752 EMPATHY_ACCOUNT_CHOOSER (self
->priv
->account_chooser
)));
3754 dialog
= gtk_message_dialog_new_with_markup (GTK_WINDOW (self
),
3755 GTK_DIALOG_MODAL
, GTK_MESSAGE_WARNING
,
3757 _("Are you sure you want to delete all logs of previous conversations?"));
3759 gtk_dialog_add_buttons (GTK_DIALOG (dialog
),
3760 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
,
3761 _("Clear All"), GTK_RESPONSE_APPLY
,
3764 content_area
= gtk_message_dialog_get_message_area (
3765 GTK_MESSAGE_DIALOG (dialog
));
3767 hbox
= gtk_box_new (GTK_ORIENTATION_HORIZONTAL
, 6);
3768 label
= gtk_label_new (_("Delete from:"));
3769 gtk_box_pack_start (GTK_BOX (hbox
), label
,
3771 gtk_box_pack_start (GTK_BOX (hbox
), GTK_WIDGET (account_chooser
),
3773 gtk_box_pack_start (GTK_BOX (content_area
), hbox
,
3776 gtk_widget_show_all (hbox
);
3778 response_id
= gtk_dialog_run (GTK_DIALOG (dialog
));
3780 if (response_id
!= GTK_RESPONSE_APPLY
)
3783 bus
= tp_dbus_daemon_dup (&error
);
3786 g_warning ("Could not delete logs: %s", error
->message
);
3787 g_error_free (error
);
3791 logger
= g_object_new (TP_TYPE_PROXY
,
3792 "bus-name", "org.freedesktop.Telepathy.Logger",
3793 "object-path", "/org/freedesktop/Telepathy/Logger",
3796 g_object_unref (bus
);
3798 tp_proxy_add_interface_by_id (logger
, EMP_IFACE_QUARK_LOGGER
);
3800 if (empathy_account_chooser_has_all_selected (account_chooser
))
3802 DEBUG ("Deleting logs for all the accounts");
3804 emp_cli_logger_call_clear (logger
, -1,
3805 log_window_logger_clear_account_cb
,
3806 self
, NULL
, G_OBJECT (self
));
3812 account
= empathy_account_chooser_get_account (account_chooser
);
3814 DEBUG ("Deleting logs for %s", tp_proxy_get_object_path (account
));
3816 emp_cli_logger_call_clear_account (logger
, -1,
3817 tp_proxy_get_object_path (account
),
3818 log_window_logger_clear_account_cb
,
3819 self
, NULL
, G_OBJECT (self
));
3822 g_object_unref (logger
);
3824 gtk_widget_destroy (dialog
);