2 * Copyright (C) 2009 Collabora Ltd.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 * Authors: Jonny Lamb <jonny.lamb@collabora.co.uk>
19 * Cosimo Cecchi <cosimo.cecchi@collabora.co.uk>
26 #include <glib/gi18n.h>
29 #include <gdk/gdkkeysyms.h>
30 #include <libsoup/soup.h>
32 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
33 #include <libempathy/empathy-debug.h>
34 #include <libempathy/empathy-utils.h>
36 #include <libempathy-gtk/empathy-account-chooser.h>
37 #include <libempathy-gtk/empathy-geometry.h>
38 #include <libempathy-gtk/empathy-ui-utils.h>
40 #include <telepathy-glib/dbus.h>
41 #include <telepathy-glib/interfaces.h>
42 #include <telepathy-glib/util.h>
43 #include <telepathy-glib/proxy-subclass.h>
44 #include <telepathy-glib/account-manager.h>
46 #include "extensions/extensions.h"
48 #include "empathy-debug-window.h"
50 G_DEFINE_TYPE (EmpathyDebugWindow, empathy_debug_window,
61 COL_DEBUG_TIMESTAMP = 0,
64 COL_DEBUG_LEVEL_STRING,
66 COL_DEBUG_LEVEL_VALUE,
88 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyDebugWindow)
93 GtkToolItem *save_button;
94 GtkToolItem *send_to_pastebin;
95 GtkToolItem *copy_button;
96 GtkToolItem *clear_button;
97 GtkToolItem *pause_button;
98 GtkToolItem *level_label;
99 GtkWidget *level_filter;
102 GtkTreeModel *store_filter;
104 GtkWidget *scrolled_win;
105 GtkWidget *not_supported_label;
106 gboolean view_visible;
110 TpProxySignalConnection *name_owner_changed_signal;
112 /* Whether NewDebugMessage will be fired */
115 /* Service (CM, Client) chooser store */
116 GtkListStore *service_store;
118 /* Counters on services detected and added */
119 guint services_detected;
120 guint name_owner_cb_count;
122 /* Debug to show upon creation */
126 gboolean dispose_run;
127 TpAccountManager *am;
128 GtkListStore *all_active_buffer;
129 } EmpathyDebugWindowPriv;
132 log_level_to_string (guint level)
136 case TP_DEBUG_LEVEL_ERROR:
139 case TP_DEBUG_LEVEL_CRITICAL:
142 case TP_DEBUG_LEVEL_WARNING:
145 case TP_DEBUG_LEVEL_MESSAGE:
148 case TP_DEBUG_LEVEL_INFO:
151 case TP_DEBUG_LEVEL_DEBUG:
155 g_assert_not_reached ();
161 get_active_service_name (EmpathyDebugWindow *self)
163 EmpathyDebugWindowPriv *priv = GET_PRIV (self);
167 if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (priv->chooser), &iter))
170 gtk_tree_model_get (GTK_TREE_MODEL (priv->service_store), &iter,
171 COL_NAME, &name, -1);
177 copy_buffered_messages (GtkTreeModel *buffer,
182 GtkListStore *active_buffer = data;
183 GtkTreeIter active_buffer_iter;
185 gchar *domain, *category, *message, *level_string;
188 gtk_tree_model_get (buffer, iter,
189 COL_DEBUG_TIMESTAMP, ×tamp,
190 COL_DEBUG_DOMAIN, &domain,
191 COL_DEBUG_CATEGORY, &category,
192 COL_DEBUG_LEVEL_STRING, &level_string,
193 COL_DEBUG_MESSAGE, &message,
194 COL_DEBUG_LEVEL_VALUE, &level,
196 gtk_list_store_insert_with_values (active_buffer, &active_buffer_iter, -1,
197 COL_DEBUG_TIMESTAMP, timestamp,
198 COL_DEBUG_DOMAIN, domain,
199 COL_DEBUG_CATEGORY, category,
200 COL_DEBUG_LEVEL_STRING, level_string,
201 COL_DEBUG_MESSAGE, message,
202 COL_DEBUG_LEVEL_VALUE, level,
207 g_free (level_string);
214 insert_values_in_buffer (GtkListStore *store,
217 const gchar *category,
223 gtk_list_store_insert_with_values (store, &iter, -1,
224 COL_DEBUG_TIMESTAMP, timestamp,
225 COL_DEBUG_DOMAIN, domain,
226 COL_DEBUG_CATEGORY, category,
227 COL_DEBUG_LEVEL_STRING, log_level_to_string (level),
228 COL_DEBUG_MESSAGE, string,
229 COL_DEBUG_LEVEL_VALUE, level,
234 debug_window_add_message (EmpathyDebugWindow *debug_window,
237 const gchar *domain_category,
239 const gchar *message)
241 EmpathyDebugWindowPriv *priv = GET_PRIV (debug_window);
242 gchar *domain, *category;
244 GtkListStore *active_buffer, *pause_buffer;
246 if (g_strrstr (domain_category, "/"))
248 gchar **parts = g_strsplit (domain_category, "/", 2);
249 domain = g_strdup (parts[0]);
250 category = g_strdup (parts[1]);
255 domain = g_strdup (domain_category);
256 category = g_strdup ("");
259 if (g_str_has_suffix (message, "\n"))
260 string = g_strchomp (g_strdup (message));
262 string = g_strdup (message);
264 pause_buffer = g_object_get_data (G_OBJECT (proxy), "pause-buffer");
265 active_buffer = g_object_get_data (G_OBJECT (proxy), "active-buffer");
269 insert_values_in_buffer (pause_buffer, timestamp,
270 domain, category, level,
275 /* Append 'this' message to this service's and All's active-buffers */
276 insert_values_in_buffer (active_buffer, timestamp,
277 domain, category, level,
280 insert_values_in_buffer (priv->all_active_buffer, timestamp,
281 domain, category, level,
291 debug_window_new_debug_message_cb (TpProxy *proxy,
295 const gchar *message,
297 GObject *weak_object)
299 EmpathyDebugWindow *debug_window = (EmpathyDebugWindow *) user_data;
301 debug_window_add_message (debug_window, proxy, timestamp, domain, level,
306 debug_window_set_enabled (TpProxy *proxy,
311 g_return_if_fail (proxy != NULL);
313 val = tp_g_value_slice_new_boolean (enabled);
315 tp_cli_dbus_properties_call_set (proxy, -1, TP_IFACE_DEBUG,
316 "Enabled", val, NULL, NULL, NULL, NULL);
318 tp_g_value_slice_free (val);
322 debug_window_set_toolbar_sensitivity (EmpathyDebugWindow *debug_window,
325 EmpathyDebugWindowPriv *priv = GET_PRIV (debug_window);
326 GtkWidget *vbox = gtk_bin_get_child (GTK_BIN (debug_window));
328 gtk_widget_set_sensitive (GTK_WIDGET (priv->save_button), sensitive);
329 gtk_widget_set_sensitive (GTK_WIDGET (priv->send_to_pastebin), sensitive);
330 gtk_widget_set_sensitive (GTK_WIDGET (priv->copy_button), sensitive);
331 gtk_widget_set_sensitive (GTK_WIDGET (priv->clear_button), sensitive);
332 gtk_widget_set_sensitive (GTK_WIDGET (priv->pause_button), sensitive);
333 gtk_widget_set_sensitive (GTK_WIDGET (priv->level_label), sensitive);
334 gtk_widget_set_sensitive (GTK_WIDGET (priv->level_filter), sensitive);
335 gtk_widget_set_sensitive (GTK_WIDGET (priv->view), sensitive);
337 if (sensitive && !priv->view_visible)
339 /* Add view and remove label */
340 gtk_container_remove (GTK_CONTAINER (vbox), priv->not_supported_label);
341 gtk_box_pack_start (GTK_BOX (vbox), priv->scrolled_win, TRUE, TRUE, 0);
342 priv->view_visible = TRUE;
344 else if (!sensitive && priv->view_visible)
346 /* Add label and remove view */
347 gtk_container_remove (GTK_CONTAINER (vbox), priv->scrolled_win);
348 gtk_box_pack_start (GTK_BOX (vbox), priv->not_supported_label,
350 priv->view_visible = FALSE;
355 debug_window_get_iter_for_active_buffer (GtkListStore *active_buffer,
357 EmpathyDebugWindow *debug_window)
359 EmpathyDebugWindowPriv *priv = GET_PRIV (debug_window);
361 GtkTreeModel *model = GTK_TREE_MODEL (priv->service_store);
363 gtk_tree_model_get_iter_first (model, iter);
364 for (valid_iter = gtk_tree_model_iter_next (model, iter);
366 valid_iter = gtk_tree_model_iter_next (model, iter))
368 GtkListStore *stored_active_buffer;
370 gtk_tree_model_get (model, iter,
371 COL_ACTIVE_BUFFER, &stored_active_buffer,
373 if (active_buffer == stored_active_buffer)
375 g_object_unref (stored_active_buffer);
378 g_object_unref (stored_active_buffer);
384 static void refresh_all_buffer (EmpathyDebugWindow *debug_window);
387 proxy_invalidated_cb (TpProxy *proxy,
393 EmpathyDebugWindow *self = (EmpathyDebugWindow *) user_data;
394 EmpathyDebugWindowPriv *priv = GET_PRIV (self);
395 GtkTreeModel *service_store = GTK_TREE_MODEL (priv->service_store);
396 TpProxy *stored_proxy;
400 /* Proxy has been invalidated so we find and set it to NULL
401 * in service store */
402 gtk_tree_model_get_iter_first (service_store, &iter);
403 for (valid_iter = gtk_tree_model_iter_next (service_store, &iter);
405 valid_iter = gtk_tree_model_iter_next (service_store, &iter))
407 gtk_tree_model_get (service_store, &iter,
408 COL_PROXY, &stored_proxy,
411 if (proxy == stored_proxy)
412 gtk_list_store_set (priv->service_store, &iter,
417 /* Also, we refresh "All" selection's active buffer since it should not
418 * show messages obtained from the proxy getting destroyed above */
419 refresh_all_buffer (self);
423 debug_window_get_messages_cb (TpProxy *proxy,
424 const GPtrArray *messages,
427 GObject *weak_object)
429 EmpathyDebugWindow *debug_window = (EmpathyDebugWindow *) user_data;
430 EmpathyDebugWindowPriv *priv = GET_PRIV (debug_window);
431 gchar *active_service_name;
433 GtkListStore *active_buffer;
436 gchar *proxy_service_name;
438 active_buffer = g_object_get_data (G_OBJECT (proxy), "active-buffer");
439 valid_iter = debug_window_get_iter_for_active_buffer (active_buffer, &iter,
441 gtk_tree_model_get (GTK_TREE_MODEL (priv->service_store), &iter,
442 COL_NAME, &proxy_service_name,
445 active_service_name = get_active_service_name (debug_window);
448 DEBUG ("GetMessages failed: %s", error->message);
450 /* We want to set the window sensitivity to false only when proxy for the
451 * selected service is unable to fetch debug messages */
452 if (!tp_strdiff (active_service_name, proxy_service_name))
453 debug_window_set_toolbar_sensitivity (debug_window, FALSE);
455 /* We created the proxy for GetMessages call. Now destroy it. */
456 tp_clear_object (&proxy);
460 DEBUG ("Retrieved debug messages for %s", active_service_name);
461 g_free (active_service_name);
462 debug_window_set_toolbar_sensitivity (debug_window, TRUE);
465 for (i = 0; i < messages->len; i++)
467 GValueArray *values = g_ptr_array_index (messages, i);
469 debug_window_add_message (debug_window, proxy,
470 g_value_get_double (g_value_array_get_nth (values, 0)),
471 g_value_get_string (g_value_array_get_nth (values, 1)),
472 g_value_get_uint (g_value_array_get_nth (values, 2)),
473 g_value_get_string (g_value_array_get_nth (values, 3)));
476 /* Now we save this precious proxy in the service_store along its service */
479 DEBUG ("Proxy for service: %s was successful in fetching debug"
480 " messages. Saving it.", proxy_service_name);
482 gtk_list_store_set (priv->service_store, &iter,
487 g_free (proxy_service_name);
489 /* Connect to "invalidated" signal */
490 g_signal_connect (proxy, "invalidated",
491 G_CALLBACK (proxy_invalidated_cb), debug_window);
493 /* Connect to NewDebugMessage */
494 emp_cli_debug_connect_to_new_debug_message (
495 proxy, debug_window_new_debug_message_cb, debug_window,
498 /* Now that active-buffer is up to date, we can see which messages are
500 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->store_filter));
502 /* Set the proxy to signal for new debug messages */
503 debug_window_set_enabled (proxy, TRUE);
507 create_proxy_to_get_messages (EmpathyDebugWindow *debug_window,
511 EmpathyDebugWindowPriv *priv = GET_PRIV (debug_window);
512 gchar *bus_name, *name = NULL;
513 TpProxy *new_proxy, *stored_proxy = NULL;
514 GtkTreeModel *pause_buffer, *active_buffer;
517 gtk_tree_model_get (GTK_TREE_MODEL (priv->service_store), iter,
520 COL_ACTIVE_BUFFER, &active_buffer,
521 COL_PAUSE_BUFFER, &pause_buffer,
522 COL_PROXY, &stored_proxy,
525 /* If the stored_proxy is not NULL then messages have been obtained and
526 * new-debug-message-signal has been set on it. Also, the proxy is valid.
527 * If the service is gone, we still display the messages-cached till now. */
529 (!gone && stored_proxy != NULL))
531 /* Nothing needs to be done. The associated active-buffer has already
532 * been set as view's model */
536 DEBUG ("Preparing proxy to obtain messages for service %s", name);
538 gtk_tree_model_get (GTK_TREE_MODEL (priv->service_store), iter,
539 COL_UNIQUE_NAME, &bus_name, -1);
540 new_proxy = g_object_new (TP_TYPE_PROXY,
541 "bus-name", bus_name,
543 "object-path", DEBUG_OBJECT_PATH,
547 g_object_set_data (G_OBJECT (new_proxy), "active-buffer", active_buffer);
548 g_object_set_data (G_OBJECT (new_proxy), "pause-buffer", pause_buffer);
550 /* Now we call GetMessages with fresh proxy.
551 * The old proxy is NULL due to one of the following -
552 * * Wasn't saved as last GetMessages call failed
553 * * The service has newly arrived and no proxy has been prepared yet for it
554 * * A service with the same name has reappeared but the owner maybe new */
555 tp_proxy_add_interface_by_id (new_proxy, emp_iface_quark_debug ());
557 emp_cli_debug_call_get_messages (new_proxy, -1,
558 debug_window_get_messages_cb, debug_window, NULL, NULL);
562 tp_clear_object (&stored_proxy);
563 g_object_unref (active_buffer);
564 g_object_unref (pause_buffer);
567 static GtkListStore *
568 new_list_store_for_service (void)
570 return gtk_list_store_new (NUM_DEBUG_COLS,
571 G_TYPE_DOUBLE, /* COL_DEBUG_TIMESTAMP */
572 G_TYPE_STRING, /* COL_DEBUG_DOMAIN */
573 G_TYPE_STRING, /* COL_DEBUG_CATEGORY */
574 G_TYPE_STRING, /* COL_DEBUG_LEVEL_STRING */
575 G_TYPE_STRING, /* COL_DEBUG_MESSAGE */
576 G_TYPE_UINT); /* COL_DEBUG_LEVEL_VALUE */
580 debug_window_visible_func (GtkTreeModel *model,
584 EmpathyDebugWindow *debug_window = (EmpathyDebugWindow *) user_data;
585 EmpathyDebugWindowPriv *priv = GET_PRIV (debug_window);
586 guint filter_value, level;
587 GtkTreeModel *filter_model;
588 GtkTreeIter filter_iter;
590 filter_model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->level_filter));
591 gtk_combo_box_get_active_iter (GTK_COMBO_BOX (priv->level_filter),
594 gtk_tree_model_get (model, iter, COL_DEBUG_LEVEL_VALUE, &level, -1);
595 gtk_tree_model_get (filter_model, &filter_iter,
596 COL_LEVEL_VALUE, &filter_value, -1);
598 if (level <= filter_value)
605 tree_view_search_equal_func_cb (GtkTreeModel *model,
609 gpointer search_data)
615 gboolean ret = TRUE; /* The return value is counter-intuitive */
617 gtk_tree_model_get (model, iter, column, &str, -1);
619 key_len = strlen (key);
620 len = strlen (str) - key_len;
622 for (i = 0; i <= len; ++i)
624 if (!g_ascii_strncasecmp (key, str + i, key_len))
636 update_store_filter (EmpathyDebugWindow *debug_window,
637 GtkListStore *active_buffer)
639 EmpathyDebugWindowPriv *priv = GET_PRIV (debug_window);
640 debug_window_set_toolbar_sensitivity (debug_window, FALSE);
642 tp_clear_object (&priv->store_filter);
643 priv->store_filter = gtk_tree_model_filter_new (
644 GTK_TREE_MODEL (active_buffer), NULL);
646 gtk_tree_model_filter_set_visible_func (
647 GTK_TREE_MODEL_FILTER (priv->store_filter),
648 debug_window_visible_func, debug_window, NULL);
649 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->view),
652 /* Since view's model has changed, reset the search column and
653 * search_equal_func */
654 gtk_tree_view_set_search_column (GTK_TREE_VIEW (priv->view),
656 gtk_tree_view_set_search_equal_func (GTK_TREE_VIEW (priv->view),
657 tree_view_search_equal_func_cb, NULL, NULL);
659 debug_window_set_toolbar_sensitivity (debug_window, TRUE);
663 refresh_all_buffer (EmpathyDebugWindow *debug_window)
665 EmpathyDebugWindowPriv *priv = GET_PRIV (debug_window);
668 GtkTreeModel *service_store = GTK_TREE_MODEL (priv->service_store);
670 /* Clear All's active-buffer */
671 gtk_list_store_clear (priv->all_active_buffer);
673 /* Skipping the first service store iter which is reserved for "All" */
674 gtk_tree_model_get_iter_first (service_store, &iter);
675 for (valid_iter = gtk_tree_model_iter_next (service_store, &iter);
677 valid_iter = gtk_tree_model_iter_next (service_store, &iter))
679 TpProxy *proxy = NULL;
680 GtkListStore *service_active_buffer;
683 gtk_tree_model_get (service_store, &iter,
686 COL_ACTIVE_BUFFER, &service_active_buffer,
691 gtk_tree_model_foreach (GTK_TREE_MODEL (service_active_buffer),
692 copy_buffered_messages, priv->all_active_buffer);
698 if (service_active_buffer == NULL)
701 /* Copy the debug messages to all_active_buffer */
702 gtk_tree_model_foreach (GTK_TREE_MODEL (service_active_buffer),
703 copy_buffered_messages, priv->all_active_buffer);
707 GError *error = NULL;
708 TpDBusDaemon *dbus = tp_dbus_daemon_dup (&error);
712 DEBUG ("Failed at duping the dbus daemon: %s", error->message);
713 g_error_free (error);
716 create_proxy_to_get_messages (debug_window, &iter, dbus);
718 g_object_unref (dbus);
722 g_object_unref (service_active_buffer);
723 tp_clear_object (&proxy);
728 debug_window_service_chooser_changed_cb (GtkComboBox *chooser,
729 EmpathyDebugWindow *debug_window)
731 EmpathyDebugWindowPriv *priv = GET_PRIV (debug_window);
733 GError *error = NULL;
734 GtkListStore *stored_active_buffer = NULL;
739 if (!gtk_combo_box_get_active_iter (chooser, &iter))
741 DEBUG ("No CM is selected");
742 if (gtk_tree_model_iter_n_children (
743 GTK_TREE_MODEL (priv->service_store), NULL) > 0)
745 gtk_combo_box_set_active (chooser, 0);
750 debug_window_set_toolbar_sensitivity (debug_window, TRUE);
752 gtk_tree_model_get (GTK_TREE_MODEL (priv->service_store), &iter,
755 COL_ACTIVE_BUFFER, &stored_active_buffer,
758 DEBUG ("Service chosen: %s", name);
760 if (tp_strdiff (name, "All") && stored_active_buffer == NULL)
762 DEBUG ("No list store assigned to service %s", name);
766 if (!tp_strdiff (name, "All"))
768 update_store_filter (debug_window, priv->all_active_buffer);
772 update_store_filter (debug_window, stored_active_buffer);
774 dbus = tp_dbus_daemon_dup (&error);
778 DEBUG ("Failed at duping the dbus daemon: %s", error->message);
781 create_proxy_to_get_messages (debug_window, &iter, dbus);
783 g_object_unref (dbus);
787 tp_clear_object (&stored_active_buffer);
795 GtkTreeIter **found_iter;
796 } CmInModelForeachData;
799 debug_window_service_foreach (GtkTreeModel *model,
804 CmInModelForeachData *data = (CmInModelForeachData *) user_data;
807 gtk_tree_model_get (model, iter,
808 (data->use_name ? COL_NAME : COL_UNIQUE_NAME),
812 if (!tp_strdiff (store_name, data->name))
816 if (data->found_iter != NULL)
817 *(data->found_iter) = gtk_tree_iter_copy (iter);
826 debug_window_service_is_in_model (EmpathyDebugWindow *debug_window,
831 EmpathyDebugWindowPriv *priv = GET_PRIV (debug_window);
832 CmInModelForeachData *data;
835 data = g_slice_new0 (CmInModelForeachData);
838 data->found_iter = iter;
839 data->use_name = use_name;
841 gtk_tree_model_foreach (GTK_TREE_MODEL (priv->service_store),
842 debug_window_service_foreach, data);
846 g_slice_free (CmInModelForeachData, data);
852 get_cm_display_name (EmpathyDebugWindow *self,
855 EmpathyDebugWindowPriv *priv = GET_PRIV (self);
856 GHashTable *protocols = g_hash_table_new (g_str_hash, g_str_equal);
857 GList *accounts, *ptr;
860 accounts = tp_account_manager_get_valid_accounts (priv->am);
862 for (ptr = accounts; ptr != NULL; ptr = ptr->next)
864 TpAccount *account = TP_ACCOUNT (ptr->data);
866 if (!tp_strdiff (tp_account_get_connection_manager (account), cm_name))
868 g_hash_table_insert (protocols,
869 (char *) tp_account_get_protocol (account),
870 GUINT_TO_POINTER (TRUE));
874 g_list_free (accounts);
876 if (g_hash_table_size (protocols) > 0)
883 protocolsv = g_new0 (char *, g_hash_table_size (protocols) + 1);
885 g_hash_table_iter_init (&iter, protocols);
886 for (i = 0; g_hash_table_iter_next (&iter, (gpointer) &key, NULL); i++)
891 str = g_strjoinv (", ", protocolsv);
892 retval = g_strdup_printf ("%s (%s)", cm_name, str);
899 retval = g_strdup (cm_name);
902 g_hash_table_unref (protocols);
909 EmpathyDebugWindow *debug_window;
912 } FillServiceChooserData;
914 static FillServiceChooserData *
915 fill_service_chooser_data_new (EmpathyDebugWindow *window,
919 FillServiceChooserData * data = g_slice_new (FillServiceChooserData);
921 data->debug_window = window;
922 data->name = g_strdup (name);
923 data->type = SERVICE_TYPE_CM;
928 fill_service_chooser_data_free (FillServiceChooserData *data)
931 g_slice_free (FillServiceChooserData, data);
935 debug_window_get_name_owner_cb (TpDBusDaemon *proxy,
939 GObject *weak_object)
941 FillServiceChooserData *data = (FillServiceChooserData *) user_data;
942 EmpathyDebugWindow *self = EMPATHY_DEBUG_WINDOW (data->debug_window);
943 EmpathyDebugWindowPriv *priv = GET_PRIV (data->debug_window);
946 priv->name_owner_cb_count++;
950 DEBUG ("GetNameOwner failed: %s", error->message);
954 if (!debug_window_service_is_in_model (data->debug_window, out, NULL, FALSE))
957 GtkListStore *active_buffer, *pause_buffer;
959 DEBUG ("Adding %s to list: %s at unique name: %s",
960 data->type == SERVICE_TYPE_CM? "CM": "Client",
963 if (data->type == SERVICE_TYPE_CM)
964 name = get_cm_display_name (self, data->name);
966 name = g_strdup (data->name);
968 active_buffer = new_list_store_for_service ();
969 pause_buffer = new_list_store_for_service ();
971 gtk_list_store_insert_with_values (priv->service_store, &iter, -1,
973 COL_UNIQUE_NAME, out,
975 COL_ACTIVE_BUFFER, active_buffer,
976 COL_PAUSE_BUFFER, pause_buffer,
980 g_object_unref (active_buffer);
981 g_object_unref (pause_buffer);
983 if (priv->select_name != NULL &&
984 !tp_strdiff (name, priv->select_name))
986 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (priv->chooser), &iter);
987 tp_clear_pointer (&priv->select_name, g_free);
993 if (priv->services_detected == priv->name_owner_cb_count)
995 /* Time to add "All" selection to service_store */
996 gtk_list_store_insert_with_values (priv->service_store, &iter, 0,
998 COL_ACTIVE_BUFFER, NULL,
1001 priv->all_active_buffer = new_list_store_for_service ();
1003 /* Populate active buffers for all services */
1004 refresh_all_buffer (self);
1006 gtk_combo_box_set_active (GTK_COMBO_BOX (priv->chooser), 0);
1010 fill_service_chooser_data_free (data);
1014 debug_window_list_connection_names_cb (const gchar * const *names,
1016 const gchar * const *cms,
1017 const gchar * const *protocols,
1018 const GError *error,
1020 GObject *weak_object)
1022 EmpathyDebugWindow *debug_window = (EmpathyDebugWindow *) user_data;
1023 EmpathyDebugWindowPriv *priv = GET_PRIV (debug_window);
1026 GError *error2 = NULL;
1030 DEBUG ("list_connection_names failed: %s", error->message);
1034 dbus = tp_dbus_daemon_dup (&error2);
1038 DEBUG ("Failed to dup TpDBusDaemon.");
1039 g_error_free (error2);
1043 for (i = 0; cms[i] != NULL; i++)
1045 FillServiceChooserData *data = fill_service_chooser_data_new (
1046 debug_window, cms[i], SERVICE_TYPE_CM);
1048 tp_cli_dbus_daemon_call_get_name_owner (dbus, -1,
1049 names[i], debug_window_get_name_owner_cb,
1052 priv->services_detected ++;
1055 g_object_unref (dbus);
1059 debug_window_name_owner_changed_cb (TpDBusDaemon *proxy,
1064 GObject *weak_object)
1066 EmpathyDebugWindow *self = EMPATHY_DEBUG_WINDOW (user_data);
1067 EmpathyDebugWindowPriv *priv = GET_PRIV (user_data);
1071 if (g_str_has_prefix (arg0, TP_CM_BUS_NAME_BASE))
1073 type = SERVICE_TYPE_CM;
1074 name = arg0 + strlen (TP_CM_BUS_NAME_BASE);
1076 else if (g_str_has_prefix (arg0, TP_CLIENT_BUS_NAME_BASE))
1078 type = SERVICE_TYPE_CLIENT;
1079 name = arg0 + strlen (TP_CLIENT_BUS_NAME_BASE);
1086 if (EMP_STR_EMPTY (arg1) && !EMP_STR_EMPTY (arg2))
1088 GtkTreeIter *found_at_iter = NULL;
1089 gchar *display_name;
1091 if (type == SERVICE_TYPE_CM)
1092 display_name = get_cm_display_name (self, name);
1094 display_name = g_strdup (name);
1096 /* A service joined */
1097 if (!debug_window_service_is_in_model (user_data, display_name,
1098 &found_at_iter, TRUE))
1101 GtkListStore *active_buffer, *pause_buffer;
1103 DEBUG ("Adding new service '%s' at %s.", name, arg2);
1105 active_buffer = new_list_store_for_service ();
1106 pause_buffer = new_list_store_for_service ();
1108 gtk_list_store_insert_with_values (priv->service_store, &iter, -1,
1109 COL_NAME, display_name,
1110 COL_UNIQUE_NAME, arg2,
1112 COL_ACTIVE_BUFFER, active_buffer,
1113 COL_PAUSE_BUFFER, pause_buffer,
1117 g_object_unref (active_buffer);
1118 g_object_unref (pause_buffer);
1122 /* a service with the same name is already in the service_store,
1123 * update it and set it as re-enabled.
1125 GtkListStore *active_buffer, *pause_buffer;
1126 TpProxy *stored_proxy;
1128 DEBUG ("Refreshing CM '%s' at '%s'.", name, arg2);
1130 active_buffer= new_list_store_for_service ();
1131 pause_buffer = new_list_store_for_service ();
1133 gtk_tree_model_get (GTK_TREE_MODEL (priv->service_store),
1134 found_at_iter, COL_PROXY, &stored_proxy, -1);
1136 tp_clear_object (&stored_proxy);
1138 gtk_list_store_set (priv->service_store, found_at_iter,
1139 COL_NAME, display_name,
1140 COL_UNIQUE_NAME, arg2,
1142 COL_ACTIVE_BUFFER, active_buffer,
1143 COL_PAUSE_BUFFER, pause_buffer,
1147 g_object_unref (active_buffer);
1148 g_object_unref (pause_buffer);
1150 gtk_tree_iter_free (found_at_iter);
1152 debug_window_service_chooser_changed_cb
1153 (GTK_COMBO_BOX (priv->chooser), user_data);
1156 /* If a new service arrives when "All" is selected, the view will
1157 * not show its messages which we do not want. So we refresh All's
1159 * Similarly for when a service with an already seen service name
1161 refresh_all_buffer (self);
1163 g_free (display_name);
1165 else if (!EMP_STR_EMPTY (arg1) && EMP_STR_EMPTY (arg2))
1167 /* A service died */
1168 GtkTreeIter *iter = NULL;
1170 DEBUG ("Setting service disabled from %s.", arg1);
1172 /* set the service as disabled in the model */
1173 if (debug_window_service_is_in_model (user_data, arg1, &iter, FALSE))
1175 gtk_list_store_set (priv->service_store,
1176 iter, COL_GONE, TRUE, -1);
1177 gtk_tree_iter_free (iter);
1180 /* Refresh all's active buffer */
1181 refresh_all_buffer (self);
1186 add_client (EmpathyDebugWindow *self,
1189 EmpathyDebugWindowPriv *priv = GET_PRIV (self);
1190 const gchar *suffix;
1191 FillServiceChooserData *data;
1193 suffix = name + strlen (TP_CLIENT_BUS_NAME_BASE);
1195 data = fill_service_chooser_data_new (self, suffix, SERVICE_TYPE_CLIENT);
1197 tp_cli_dbus_daemon_call_get_name_owner (priv->dbus, -1,
1198 name, debug_window_get_name_owner_cb, data, NULL, NULL);
1200 priv->services_detected ++;
1204 list_names_cb (TpDBusDaemon *bus_daemon,
1205 const gchar * const *names,
1206 const GError *error,
1208 GObject *weak_object)
1210 EmpathyDebugWindow *self = EMPATHY_DEBUG_WINDOW (weak_object);
1215 DEBUG ("Failed to list names: %s", error->message);
1219 for (i = 0; names[i] != NULL; i++)
1221 if (g_str_has_prefix (names[i], TP_CLIENT_BUS_NAME_BASE))
1223 add_client (self, names[i]);
1229 debug_window_fill_service_chooser (EmpathyDebugWindow *debug_window)
1231 EmpathyDebugWindowPriv *priv = GET_PRIV (debug_window);
1232 GError *error = NULL;
1234 GtkListStore *active_buffer, *pause_buffer;
1236 priv->dbus = tp_dbus_daemon_dup (&error);
1240 DEBUG ("Failed to dup dbus daemon: %s", error->message);
1241 g_error_free (error);
1245 /* Keep a count of the services detected and added */
1246 priv->services_detected = 0;
1247 priv->name_owner_cb_count = 0;
1249 /* Add CMs to list */
1250 tp_list_connection_names (priv->dbus, debug_window_list_connection_names_cb,
1251 debug_window, NULL, NULL);
1253 /* add Mission Control */
1254 active_buffer= new_list_store_for_service ();
1255 pause_buffer = new_list_store_for_service ();
1257 gtk_list_store_insert_with_values (priv->service_store, &iter, -1,
1258 COL_NAME, "mission-control",
1259 COL_UNIQUE_NAME, "org.freedesktop.Telepathy.MissionControl5",
1261 COL_ACTIVE_BUFFER, active_buffer,
1262 COL_PAUSE_BUFFER, pause_buffer,
1265 g_object_unref (active_buffer);
1266 g_object_unref (pause_buffer);
1269 tp_dbus_daemon_list_names (priv->dbus, 2000,
1270 list_names_cb, NULL, NULL, G_OBJECT (debug_window));
1272 priv->name_owner_changed_signal =
1273 tp_cli_dbus_daemon_connect_to_name_owner_changed (priv->dbus,
1274 debug_window_name_owner_changed_cb, debug_window, NULL, NULL, NULL);
1278 debug_window_pause_toggled_cb (GtkToggleToolButton *pause_,
1279 EmpathyDebugWindow *debug_window)
1281 EmpathyDebugWindowPriv *priv = GET_PRIV (debug_window);
1283 gboolean valid_iter;
1284 GtkTreeModel *model = GTK_TREE_MODEL (priv->service_store);
1286 priv->paused = gtk_toggle_tool_button_get_active (pause_);
1290 /* Pause has been released - flush all pause buffers */
1291 GtkTreeModel *service_store = GTK_TREE_MODEL (priv->service_store);
1293 /* Skipping the first iter which is reserved for "All" */
1294 gtk_tree_model_get_iter_first (model, &iter);
1295 for (valid_iter = gtk_tree_model_iter_next (model, &iter);
1297 valid_iter = gtk_tree_model_iter_next (model, &iter))
1299 GtkListStore *pause_buffer, *active_buffer;
1301 gtk_tree_model_get (service_store, &iter,
1302 COL_PAUSE_BUFFER, &pause_buffer,
1303 COL_ACTIVE_BUFFER, &active_buffer,
1306 gtk_tree_model_foreach (GTK_TREE_MODEL (pause_buffer),
1307 copy_buffered_messages, active_buffer);
1308 gtk_tree_model_foreach (GTK_TREE_MODEL (pause_buffer),
1309 copy_buffered_messages, priv->all_active_buffer);
1311 gtk_list_store_clear (pause_buffer);
1313 g_object_unref (active_buffer);
1314 g_object_unref (pause_buffer);
1320 debug_window_filter_changed_cb (GtkComboBox *filter,
1321 EmpathyDebugWindow *debug_window)
1323 EmpathyDebugWindowPriv *priv = GET_PRIV (debug_window);
1325 gtk_tree_model_filter_refilter (
1326 GTK_TREE_MODEL_FILTER (priv->store_filter));
1330 debug_window_clear_clicked_cb (GtkToolButton *clear_button,
1331 EmpathyDebugWindow *debug_window)
1333 EmpathyDebugWindowPriv *priv = GET_PRIV (debug_window);
1335 GtkListStore *active_buffer;
1337 /* "All" is the first choice in the service chooser and it's buffer is
1338 * not saved in the service-store but is accessed using a private
1340 if (gtk_combo_box_get_active (GTK_COMBO_BOX (priv->chooser)) == 0)
1342 gtk_list_store_clear (priv->all_active_buffer);
1346 gtk_combo_box_get_active_iter (GTK_COMBO_BOX (priv->chooser), &iter);
1347 gtk_tree_model_get (GTK_TREE_MODEL (priv->service_store), &iter,
1348 COL_ACTIVE_BUFFER, &active_buffer, -1);
1350 gtk_list_store_clear (active_buffer);
1352 g_object_unref (active_buffer);
1356 debug_window_menu_copy_activate_cb (GtkMenuItem *menu_item,
1357 EmpathyDebugWindow *debug_window)
1359 EmpathyDebugWindowPriv *priv = GET_PRIV (debug_window);
1361 GtkTreeViewColumn *focus_column;
1364 GtkClipboard *clipboard;
1366 gtk_tree_view_get_cursor (GTK_TREE_VIEW (priv->view),
1367 &path, &focus_column);
1371 DEBUG ("No row is in focus");
1375 gtk_tree_model_get_iter (priv->store_filter, &iter, path);
1377 gtk_tree_model_get (priv->store_filter, &iter,
1378 COL_DEBUG_MESSAGE, &message,
1381 if (EMP_STR_EMPTY (message))
1383 DEBUG ("Log message is empty");
1387 clipboard = gtk_clipboard_get_for_display (
1388 gtk_widget_get_display (GTK_WIDGET (menu_item)),
1389 GDK_SELECTION_CLIPBOARD);
1391 gtk_clipboard_set_text (clipboard, message, -1);
1398 EmpathyDebugWindow *debug_window;
1404 debug_window_show_menu (gpointer user_data)
1406 MenuPopupData *data = (MenuPopupData *) user_data;
1407 GtkWidget *menu, *item;
1408 GtkMenuShell *shell;
1410 menu = empathy_context_menu_new (GTK_WIDGET (data->debug_window));
1411 shell = GTK_MENU_SHELL (menu);
1413 item = gtk_image_menu_item_new_from_stock (GTK_STOCK_COPY, NULL);
1415 g_signal_connect (item, "activate",
1416 G_CALLBACK (debug_window_menu_copy_activate_cb), data->debug_window);
1418 gtk_menu_shell_append (shell, item);
1419 gtk_widget_show (item);
1421 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
1422 data->button, data->time);
1424 g_slice_free (MenuPopupData, user_data);
1430 debug_window_button_press_event_cb (GtkTreeView *view,
1431 GdkEventButton *event,
1434 /* A mouse button was pressed on the tree view. */
1436 if (event->button == 3)
1438 /* The tree view was right-clicked. (3 == third mouse button) */
1439 MenuPopupData *data;
1440 data = g_slice_new0 (MenuPopupData);
1441 data->debug_window = user_data;
1442 data->button = event->button;
1443 data->time = event->time;
1444 g_idle_add (debug_window_show_menu, data);
1451 debug_window_format_timestamp (gdouble timestamp)
1459 ms = (int) ((timestamp - (int) timestamp)*1e6);
1460 sec = (long) timestamp;
1461 tstruct = localtime ((time_t *) &sec);
1462 if (!strftime (time_str, sizeof (time_str), "%x %T", tstruct))
1464 DEBUG ("Failed to format timestamp: %e", timestamp);
1468 text = g_strdup_printf ("%s.%d", time_str, ms);
1474 debug_window_time_formatter (GtkTreeViewColumn *tree_column,
1475 GtkCellRenderer *cell,
1476 GtkTreeModel *tree_model,
1483 gtk_tree_model_get (tree_model, iter, COL_DEBUG_TIMESTAMP, ×tamp, -1);
1485 time_str = debug_window_format_timestamp (timestamp);
1487 g_object_set (G_OBJECT (cell), "text", time_str, NULL);
1493 debug_window_store_filter_foreach (GtkTreeModel *model,
1498 gchar **debug_data = (gchar **)user_data;
1499 gchar *domain, *category, *message, *level_str, *level_upper;
1501 gchar *line, *time_str, *tmp;
1503 gtk_tree_model_get (model, iter,
1504 COL_DEBUG_TIMESTAMP, ×tamp,
1505 COL_DEBUG_DOMAIN, &domain,
1506 COL_DEBUG_CATEGORY, &category,
1507 COL_DEBUG_LEVEL_STRING, &level_str,
1508 COL_DEBUG_MESSAGE, &message,
1511 level_upper = g_ascii_strup (level_str, -1);
1513 time_str = debug_window_format_timestamp (timestamp);
1515 line = g_strdup_printf ("%s%s%s-%s: %s: %s\n",
1516 domain, EMP_STR_EMPTY (category) ? "" : "/",
1517 category, level_upper, time_str, message);
1521 /* Compact all message lines in the out parameter debug_data */
1522 if (!tp_str_empty (*debug_data))
1523 tmp = g_strconcat (*debug_data, line, NULL);
1525 tmp = g_strdup (line);
1527 g_free (*debug_data);
1531 g_free (level_upper);
1541 debug_window_save_file_chooser_response_cb (GtkDialog *dialog,
1543 EmpathyDebugWindow *debug_window)
1545 EmpathyDebugWindowPriv *priv = GET_PRIV (debug_window);
1546 gchar *filename = NULL;
1547 GFile *gfile = NULL;
1548 gchar *debug_data = NULL;
1549 GFileOutputStream *output_stream = NULL;
1550 GError *file_open_error = NULL;
1551 GError *file_write_error = NULL;
1553 if (response_id != GTK_RESPONSE_ACCEPT)
1556 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
1558 DEBUG ("Saving log as %s", filename);
1560 gfile = g_file_new_for_path (filename);
1561 output_stream = g_file_replace (gfile, NULL, FALSE,
1562 G_FILE_CREATE_NONE, NULL, &file_open_error);
1564 if (file_open_error != NULL)
1566 DEBUG ("Failed to open file for writing: %s", file_open_error->message);
1567 g_error_free (file_open_error);
1571 gtk_tree_model_foreach (priv->store_filter,
1572 debug_window_store_filter_foreach, &debug_data);
1574 g_output_stream_write (G_OUTPUT_STREAM (output_stream), debug_data,
1575 strlen (debug_data), NULL, &file_write_error);
1576 g_free (debug_data);
1578 if (file_write_error != NULL)
1580 DEBUG ("Failed to write to file: %s", file_write_error->message);
1581 g_error_free (file_write_error);
1586 g_object_unref (gfile);
1588 if (output_stream != NULL)
1589 g_object_unref (output_stream);
1591 if (filename != NULL)
1594 gtk_widget_destroy (GTK_WIDGET (dialog));
1598 debug_window_save_clicked_cb (GtkToolButton *tool_button,
1599 EmpathyDebugWindow *debug_window)
1601 GtkWidget *file_chooser;
1602 gchar *name, *tmp = NULL;
1607 file_chooser = gtk_file_chooser_dialog_new (_("Save"),
1608 GTK_WINDOW (debug_window), GTK_FILE_CHOOSER_ACTION_SAVE,
1609 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1610 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
1613 gtk_window_set_modal (GTK_WINDOW (file_chooser), TRUE);
1614 gtk_file_chooser_set_do_overwrite_confirmation (
1615 GTK_FILE_CHOOSER (file_chooser), TRUE);
1617 gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (file_chooser),
1620 name = get_active_service_name (debug_window);
1623 tm_s = localtime (&t);
1626 if (strftime (time_str, sizeof (time_str), "%d-%m-%y_%H-%M-%S", tm_s))
1627 tmp = g_strdup_printf ("%s-%s.log", name, time_str);
1631 tmp = g_strdup_printf ("%s.log", name);
1634 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (file_chooser), tmp);
1637 g_signal_connect (file_chooser, "response",
1638 G_CALLBACK (debug_window_save_file_chooser_response_cb),
1641 gtk_widget_show (file_chooser);
1645 debug_window_pastebin_response_dialog_closed_cb (GtkDialog *dialog,
1649 soup_buffer_free (buffer);
1651 gtk_widget_destroy (GTK_WIDGET (dialog));
1655 debug_window_pastebin_callback (SoupSession *session,
1657 gpointer debug_window)
1662 buffer = soup_message_body_flatten (msg->response_body);
1663 if (g_str_has_prefix (buffer->data, "http://pastebin.com/"))
1665 dialog = gtk_message_dialog_new (GTK_WINDOW (debug_window),
1666 GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE,
1667 _("Pastebin link"));
1669 gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (dialog),
1670 "<a href=\"%s\">%s</a>", buffer->data, buffer->data);
1674 dialog = gtk_message_dialog_new (GTK_WINDOW (debug_window),
1675 GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE,
1676 _("Pastebin response"));
1678 if (!tp_str_empty (buffer->data))
1679 gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (dialog),
1680 _("%s"), buffer->data);
1682 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
1683 _("Data too large for a single paste. Please save logs to file."));
1686 g_object_unref (session);
1688 gtk_window_set_transient_for (GTK_WINDOW (dialog), debug_window);
1690 gtk_widget_show_all (GTK_WIDGET (dialog));
1692 g_signal_connect_after (dialog, "response", G_CALLBACK (
1693 debug_window_pastebin_response_dialog_closed_cb), buffer);
1697 debug_window_message_dialog (EmpathyDebugWindow *debug_window,
1698 const gchar *primary_text,
1699 const gchar *secondary_text)
1703 dialog = gtk_message_dialog_new (GTK_WINDOW (debug_window),
1704 GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_OK,
1705 "%s", _(primary_text));
1706 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
1707 "%s", _(secondary_text));
1708 gtk_window_set_transient_for (GTK_WINDOW (dialog),
1709 GTK_WINDOW (debug_window));
1711 gtk_dialog_run (GTK_DIALOG (dialog));
1712 gtk_widget_destroy (dialog);
1716 debug_window_send_to_pastebin (EmpathyDebugWindow *debug_window,
1719 SoupSession *session;
1721 gchar *api_dev_key, *api_paste_code, *api_paste_name, *formdata;
1723 if (tp_str_empty (debug_data))
1725 debug_window_message_dialog (debug_window, "Error", "No data to send");
1729 /* Constructing a valid URL for http post. See http://pastebin.com/api#2 */
1731 /* The api_dev_key is the author's developer key to access the Pastebin API
1732 * This developer key is published here with the autorization of pastebin;
1733 * see PASTEBIN-API-KEY.txt */
1734 api_dev_key = soup_uri_encode ("f6ccfabfdcd4b77b825ee38a30d11d52", NULL);
1735 api_paste_code = soup_uri_encode (debug_data, NULL);
1736 api_paste_name = soup_uri_encode ("Empathy debug data", NULL);
1737 formdata = g_strdup_printf ("api_dev_key=%s&api_paste_code=%s"
1738 "&api_paste_name=%s&api_paste_format=text&api_option=paste",
1739 api_dev_key, api_paste_code, api_paste_name);
1741 session = soup_session_async_new ();
1743 msg = soup_message_new ("POST", "http://pastebin.com/api/api_post.php");
1744 soup_message_set_request (msg,
1745 "application/x-www-form-urlencoded;charset=UTF-8", SOUP_MEMORY_COPY,
1746 formdata, strlen (formdata));
1748 g_free (api_dev_key);
1749 g_free (api_paste_code);
1750 g_free (api_paste_name);
1753 soup_session_queue_message (session, msg, debug_window_pastebin_callback,
1758 debug_window_send_to_pastebin_cb (GtkToolButton *tool_button,
1759 EmpathyDebugWindow *debug_window)
1761 EmpathyDebugWindowPriv *priv = GET_PRIV (debug_window);
1762 gchar *debug_data = NULL;
1764 DEBUG ("Preparing debug data for sending to pastebin.");
1766 gtk_tree_model_foreach (priv->store_filter,
1767 debug_window_store_filter_foreach, &debug_data);
1769 debug_window_send_to_pastebin (debug_window, debug_data);
1770 g_free (debug_data);
1774 debug_window_copy_model_foreach (GtkTreeModel *model,
1779 gchar **text = (gchar **) user_data;
1781 gchar *domain, *category, *message, *level_str, *level_upper;
1783 gchar *line, *time_str;
1785 gtk_tree_model_get (model, iter,
1786 COL_DEBUG_TIMESTAMP, ×tamp,
1787 COL_DEBUG_DOMAIN, &domain,
1788 COL_DEBUG_CATEGORY, &category,
1789 COL_DEBUG_LEVEL_STRING, &level_str,
1790 COL_DEBUG_MESSAGE, &message,
1793 level_upper = g_ascii_strup (level_str, -1);
1795 time_str = debug_window_format_timestamp (timestamp);
1797 line = g_strdup_printf ("%s%s%s-%s: %s: %s\n",
1798 domain, EMP_STR_EMPTY (category) ? "" : "/",
1799 category, level_upper, time_str, message);
1803 tmp = g_strconcat (*text, line, NULL);
1807 g_free (level_upper);
1819 debug_window_copy_clicked_cb (GtkToolButton *tool_button,
1820 EmpathyDebugWindow *debug_window)
1822 EmpathyDebugWindowPriv *priv = GET_PRIV (debug_window);
1823 GtkClipboard *clipboard;
1826 text = g_strdup ("");
1828 gtk_tree_model_foreach (priv->store_filter,
1829 debug_window_copy_model_foreach, &text);
1831 clipboard = gtk_clipboard_get_for_display (
1832 gtk_widget_get_display (GTK_WIDGET (tool_button)),
1833 GDK_SELECTION_CLIPBOARD);
1835 DEBUG ("Copying text to clipboard (length: %" G_GSIZE_FORMAT ")",
1838 gtk_clipboard_set_text (clipboard, text, -1);
1844 debug_window_key_press_event_cb (GtkWidget *widget,
1848 if ((event->state & GDK_CONTROL_MASK && event->keyval == GDK_KEY_w)
1849 || event->keyval == GDK_KEY_Escape)
1851 gtk_widget_destroy (widget);
1859 empathy_debug_window_select_name (EmpathyDebugWindow *self,
1862 EmpathyDebugWindowPriv *priv = GET_PRIV (self);
1863 GtkTreeModel *model = GTK_TREE_MODEL (priv->service_store);
1866 gboolean valid, found = FALSE;
1868 for (valid = gtk_tree_model_get_iter_first (model, &iter);
1870 valid = gtk_tree_model_iter_next (model, &iter))
1872 gtk_tree_model_get (model, &iter,
1873 COL_NAME, &iter_name,
1876 if (!tp_strdiff (name, iter_name))
1886 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (priv->chooser), &iter);
1890 am_prepared_cb (GObject *am,
1894 GObject *object = user_data;
1895 EmpathyDebugWindowPriv *priv = GET_PRIV (object);
1901 GtkCellRenderer *renderer;
1902 GtkListStore *level_store;
1904 GError *error = NULL;
1906 if (!tp_proxy_prepare_finish (am, res, &error))
1908 g_warning ("Failed to prepare AM: %s", error->message);
1909 g_clear_error (&error);
1912 gtk_window_set_title (GTK_WINDOW (object), _("Debug Window"));
1913 gtk_window_set_default_size (GTK_WINDOW (object), 800, 400);
1914 empathy_geometry_bind (GTK_WINDOW (object), "debug-window");
1916 g_signal_connect (object, "key-press-event",
1917 G_CALLBACK (debug_window_key_press_event_cb), NULL);
1919 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
1920 gtk_container_add (GTK_CONTAINER (object), vbox);
1921 gtk_widget_show (vbox);
1923 toolbar = gtk_toolbar_new ();
1924 gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_BOTH_HORIZ);
1925 gtk_toolbar_set_show_arrow (GTK_TOOLBAR (toolbar), TRUE);
1926 gtk_toolbar_set_icon_size (GTK_TOOLBAR (toolbar),
1927 GTK_ICON_SIZE_SMALL_TOOLBAR);
1928 gtk_style_context_add_class (gtk_widget_get_style_context (toolbar),
1929 GTK_STYLE_CLASS_PRIMARY_TOOLBAR);
1930 gtk_widget_show (toolbar);
1932 gtk_box_pack_start (GTK_BOX (vbox), toolbar, FALSE, FALSE, 0);
1935 priv->chooser = gtk_combo_box_text_new ();
1936 priv->service_store = gtk_list_store_new (NUM_COLS,
1937 G_TYPE_STRING, /* COL_NAME */
1938 G_TYPE_STRING, /* COL_UNIQUE_NAME */
1939 G_TYPE_BOOLEAN, /* COL_GONE */
1940 G_TYPE_OBJECT, /* COL_ACTIVE_BUFFER */
1941 G_TYPE_OBJECT, /* COL_PAUSE_BUFFER */
1942 TP_TYPE_PROXY); /* COL_PROXY */
1943 gtk_combo_box_set_model (GTK_COMBO_BOX (priv->chooser),
1944 GTK_TREE_MODEL (priv->service_store));
1945 gtk_widget_show (priv->chooser);
1947 item = gtk_tool_item_new ();
1948 gtk_widget_show (GTK_WIDGET (item));
1949 gtk_container_add (GTK_CONTAINER (item), priv->chooser);
1950 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
1951 g_signal_connect (priv->chooser, "changed",
1952 G_CALLBACK (debug_window_service_chooser_changed_cb), object);
1953 gtk_widget_show (GTK_WIDGET (priv->chooser));
1955 item = gtk_separator_tool_item_new ();
1956 gtk_widget_show (GTK_WIDGET (item));
1957 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
1960 priv->save_button = gtk_tool_button_new_from_stock (GTK_STOCK_SAVE);
1961 g_signal_connect (priv->save_button, "clicked",
1962 G_CALLBACK (debug_window_save_clicked_cb), object);
1963 gtk_widget_show (GTK_WIDGET (priv->save_button));
1964 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (priv->save_button), TRUE);
1965 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->save_button, -1);
1967 /* Send to pastebin */
1968 priv->send_to_pastebin = gtk_tool_button_new_from_stock (GTK_STOCK_PASTE);
1969 gtk_tool_button_set_label (GTK_TOOL_BUTTON (priv->send_to_pastebin),
1970 _("Send to pastebin"));
1971 g_signal_connect (priv->send_to_pastebin, "clicked",
1972 G_CALLBACK (debug_window_send_to_pastebin_cb), object);
1973 gtk_widget_show (GTK_WIDGET (priv->send_to_pastebin));
1974 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (priv->send_to_pastebin), TRUE);
1975 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->send_to_pastebin, -1);
1978 priv->copy_button = gtk_tool_button_new_from_stock (GTK_STOCK_COPY);
1979 g_signal_connect (priv->copy_button, "clicked",
1980 G_CALLBACK (debug_window_copy_clicked_cb), object);
1981 gtk_widget_show (GTK_WIDGET (priv->copy_button));
1982 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (priv->copy_button), TRUE);
1983 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->copy_button, -1);
1986 priv->clear_button = gtk_tool_button_new_from_stock (GTK_STOCK_CLEAR);
1987 g_signal_connect (priv->clear_button, "clicked",
1988 G_CALLBACK (debug_window_clear_clicked_cb), object);
1989 gtk_widget_show (GTK_WIDGET (priv->clear_button));
1990 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (priv->clear_button), TRUE);
1991 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->clear_button, -1);
1993 item = gtk_separator_tool_item_new ();
1994 gtk_widget_show (GTK_WIDGET (item));
1995 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
1998 priv->paused = FALSE;
1999 image = gtk_image_new_from_stock (GTK_STOCK_MEDIA_PAUSE,
2000 GTK_ICON_SIZE_MENU);
2001 gtk_widget_show (image);
2002 priv->pause_button = gtk_toggle_tool_button_new ();
2003 gtk_toggle_tool_button_set_active (
2004 GTK_TOGGLE_TOOL_BUTTON (priv->pause_button), priv->paused);
2005 g_signal_connect (priv->pause_button, "toggled",
2006 G_CALLBACK (debug_window_pause_toggled_cb), object);
2007 gtk_widget_show (GTK_WIDGET (priv->pause_button));
2008 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (priv->pause_button), TRUE);
2009 gtk_tool_button_set_label (GTK_TOOL_BUTTON (priv->pause_button), _("Pause"));
2010 gtk_tool_button_set_icon_widget (
2011 GTK_TOOL_BUTTON (priv->pause_button), image);
2012 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->pause_button, -1);
2014 item = gtk_separator_tool_item_new ();
2015 gtk_widget_show (GTK_WIDGET (item));
2016 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
2019 priv->level_label = gtk_tool_item_new ();
2020 gtk_widget_show (GTK_WIDGET (priv->level_label));
2021 label = gtk_label_new (_("Level "));
2022 gtk_widget_show (label);
2023 gtk_container_add (GTK_CONTAINER (priv->level_label), label);
2024 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->level_label, -1);
2026 priv->level_filter = gtk_combo_box_text_new ();
2027 gtk_widget_show (priv->level_filter);
2029 item = gtk_tool_item_new ();
2030 gtk_widget_show (GTK_WIDGET (item));
2031 gtk_container_add (GTK_CONTAINER (item), priv->level_filter);
2032 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
2034 level_store = gtk_list_store_new (NUM_COLS_LEVEL,
2035 G_TYPE_STRING, G_TYPE_UINT);
2036 gtk_combo_box_set_model (GTK_COMBO_BOX (priv->level_filter),
2037 GTK_TREE_MODEL (level_store));
2039 gtk_list_store_insert_with_values (level_store, &iter, -1,
2040 COL_LEVEL_NAME, _("Debug"),
2041 COL_LEVEL_VALUE, TP_DEBUG_LEVEL_DEBUG,
2044 gtk_list_store_insert_with_values (level_store, &iter, -1,
2045 COL_LEVEL_NAME, _("Info"),
2046 COL_LEVEL_VALUE, TP_DEBUG_LEVEL_INFO,
2049 gtk_list_store_insert_with_values (level_store, &iter, -1,
2050 COL_LEVEL_NAME, _("Message"),
2051 COL_LEVEL_VALUE, TP_DEBUG_LEVEL_MESSAGE,
2054 gtk_list_store_insert_with_values (level_store, &iter, -1,
2055 COL_LEVEL_NAME, _("Warning"),
2056 COL_LEVEL_VALUE, TP_DEBUG_LEVEL_WARNING,
2059 gtk_list_store_insert_with_values (level_store, &iter, -1,
2060 COL_LEVEL_NAME, _("Critical"),
2061 COL_LEVEL_VALUE, TP_DEBUG_LEVEL_CRITICAL,
2064 gtk_list_store_insert_with_values (level_store, &iter, -1,
2065 COL_LEVEL_NAME, _("Error"),
2066 COL_LEVEL_VALUE, TP_DEBUG_LEVEL_ERROR,
2069 gtk_combo_box_set_active (GTK_COMBO_BOX (priv->level_filter), 0);
2070 g_signal_connect (priv->level_filter, "changed",
2071 G_CALLBACK (debug_window_filter_changed_cb), object);
2073 /* Debug treeview */
2074 priv->view = gtk_tree_view_new ();
2075 gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (priv->view), TRUE);
2077 g_signal_connect (priv->view, "button-press-event",
2078 G_CALLBACK (debug_window_button_press_event_cb), object);
2080 renderer = gtk_cell_renderer_text_new ();
2081 g_object_set (renderer, "yalign", 0, NULL);
2083 gtk_tree_view_insert_column_with_data_func (GTK_TREE_VIEW (priv->view),
2084 -1, _("Time"), renderer,
2085 (GtkTreeCellDataFunc) debug_window_time_formatter, NULL, NULL);
2086 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
2087 -1, _("Domain"), renderer, "text", COL_DEBUG_DOMAIN, NULL);
2088 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
2089 -1, _("Category"), renderer, "text", COL_DEBUG_CATEGORY, NULL);
2090 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
2091 -1, _("Level"), renderer, "text", COL_DEBUG_LEVEL_STRING, NULL);
2093 renderer = gtk_cell_renderer_text_new ();
2094 g_object_set (renderer, "family", "Monospace", NULL);
2095 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
2096 -1, _("Message"), renderer, "text", COL_DEBUG_MESSAGE, NULL);
2098 priv->store_filter = NULL;
2100 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->view), priv->store_filter);
2102 /* Scrolled window */
2103 priv->scrolled_win = g_object_ref (gtk_scrolled_window_new (NULL, NULL));
2104 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_win),
2105 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
2107 gtk_widget_show (priv->view);
2108 gtk_container_add (GTK_CONTAINER (priv->scrolled_win), priv->view);
2110 gtk_widget_show (priv->scrolled_win);
2112 /* Not supported label */
2113 priv->not_supported_label = g_object_ref (gtk_label_new (
2114 _("The selected connection manager does not support the remote "
2115 "debugging extension.")));
2116 gtk_widget_show (priv->not_supported_label);
2117 gtk_box_pack_start (GTK_BOX (vbox), priv->not_supported_label,
2120 priv->view_visible = FALSE;
2122 priv->all_active_buffer = NULL;
2124 debug_window_set_toolbar_sensitivity (EMPATHY_DEBUG_WINDOW (object), FALSE);
2125 debug_window_fill_service_chooser (EMPATHY_DEBUG_WINDOW (object));
2126 gtk_widget_show (GTK_WIDGET (object));
2130 debug_window_constructed (GObject *object)
2132 EmpathyDebugWindowPriv *priv = GET_PRIV (object);
2134 priv->am = tp_account_manager_dup ();
2135 tp_proxy_prepare_async (priv->am, NULL, am_prepared_cb, object);
2139 empathy_debug_window_init (EmpathyDebugWindow *empathy_debug_window)
2141 EmpathyDebugWindowPriv *priv =
2142 G_TYPE_INSTANCE_GET_PRIVATE (empathy_debug_window,
2143 EMPATHY_TYPE_DEBUG_WINDOW, EmpathyDebugWindowPriv);
2145 empathy_debug_window->priv = priv;
2147 priv->dispose_run = FALSE;
2151 debug_window_set_property (GObject *object,
2153 const GValue *value,
2159 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2165 debug_window_get_property (GObject *object,
2173 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2179 debug_window_finalize (GObject *object)
2181 EmpathyDebugWindowPriv *priv = GET_PRIV (object);
2183 g_free (priv->select_name);
2185 (G_OBJECT_CLASS (empathy_debug_window_parent_class)->finalize) (object);
2189 debug_window_dispose (GObject *object)
2191 EmpathyDebugWindow *selector = EMPATHY_DEBUG_WINDOW (object);
2192 EmpathyDebugWindowPriv *priv = GET_PRIV (selector);
2194 if (priv->dispose_run)
2197 priv->dispose_run = TRUE;
2199 if (priv->name_owner_changed_signal != NULL)
2200 tp_proxy_signal_connection_disconnect (priv->name_owner_changed_signal);
2202 if (priv->service_store != NULL)
2203 g_object_unref (priv->service_store);
2205 if (priv->dbus != NULL)
2206 g_object_unref (priv->dbus);
2208 if (priv->am != NULL)
2210 g_object_unref (priv->am);
2214 tp_clear_object (&priv->all_active_buffer);
2216 (G_OBJECT_CLASS (empathy_debug_window_parent_class)->dispose) (object);
2220 empathy_debug_window_class_init (EmpathyDebugWindowClass *klass)
2222 GObjectClass *object_class = G_OBJECT_CLASS (klass);
2223 object_class->constructed = debug_window_constructed;
2224 object_class->dispose = debug_window_dispose;
2225 object_class->finalize = debug_window_finalize;
2226 object_class->set_property = debug_window_set_property;
2227 object_class->get_property = debug_window_get_property;
2228 g_type_class_add_private (klass, sizeof (EmpathyDebugWindowPriv));
2231 /* public methods */
2234 empathy_debug_window_new (GtkWindow *parent)
2236 g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), NULL);
2238 return GTK_WIDGET (g_object_new (EMPATHY_TYPE_DEBUG_WINDOW,
2239 "transient-for", parent, NULL));
2243 empathy_debug_window_show (EmpathyDebugWindow *self,
2246 EmpathyDebugWindowPriv *priv = GET_PRIV (self);
2248 if (priv->service_store != NULL)
2250 empathy_debug_window_select_name (self, name);
2254 g_free (priv->select_name);
2255 priv->select_name = g_strdup (name);