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>
24 #include <glib/gi18n.h>
27 #include <gdk/gdkkeysyms.h>
29 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
30 #include <libempathy/empathy-debug.h>
31 #include <libempathy/empathy-utils.h>
33 #include <libempathy-gtk/empathy-account-chooser.h>
34 #include <libempathy-gtk/empathy-geometry.h>
35 #include <libempathy-gtk/empathy-ui-utils.h>
37 #include <telepathy-glib/dbus.h>
38 #include <telepathy-glib/interfaces.h>
39 #include <telepathy-glib/util.h>
40 #include <telepathy-glib/proxy-subclass.h>
41 #include <telepathy-glib/account-manager.h>
43 #include "extensions/extensions.h"
45 #include "empathy-debug-window.h"
47 G_DEFINE_TYPE (EmpathyDebugWindow, empathy_debug_window,
58 COL_DEBUG_TIMESTAMP = 0,
61 COL_DEBUG_LEVEL_STRING,
63 COL_DEBUG_LEVEL_VALUE,
85 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyDebugWindow)
90 GtkToolItem *save_button;
91 GtkToolItem *copy_button;
92 GtkToolItem *clear_button;
93 GtkToolItem *pause_button;
94 GtkToolItem *level_label;
95 GtkWidget *level_filter;
98 GtkTreeModel *store_filter;
100 GtkWidget *scrolled_win;
101 GtkWidget *not_supported_label;
102 gboolean view_visible;
106 TpProxySignalConnection *name_owner_changed_signal;
108 /* Whether NewDebugMessage will be fired */
111 /* Service (CM, Client) chooser store */
112 GtkListStore *service_store;
114 /* Debug to show upon creation */
118 gboolean dispose_run;
119 TpAccountManager *am;
120 } EmpathyDebugWindowPriv;
123 log_level_to_string (guint level)
127 case TP_DEBUG_LEVEL_ERROR:
130 case TP_DEBUG_LEVEL_CRITICAL:
133 case TP_DEBUG_LEVEL_WARNING:
136 case TP_DEBUG_LEVEL_MESSAGE:
139 case TP_DEBUG_LEVEL_INFO:
142 case TP_DEBUG_LEVEL_DEBUG:
146 g_assert_not_reached ();
152 get_active_service_name (EmpathyDebugWindow *self)
154 EmpathyDebugWindowPriv *priv = GET_PRIV (self);
158 if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (priv->chooser), &iter))
161 gtk_tree_model_get (GTK_TREE_MODEL (priv->service_store), &iter,
162 COL_NAME, &name, -1);
168 flush_buffered_messages_to_list_store (GtkTreeModel *pause_buffer,
173 GtkListStore *active_buffer = data;
174 GtkTreeIter active_buffer_iter;
176 gchar *domain, *category, *message, *level_string;
179 gtk_tree_model_get (pause_buffer, iter,
180 COL_DEBUG_TIMESTAMP, ×tamp,
181 COL_DEBUG_DOMAIN, &domain,
182 COL_DEBUG_CATEGORY, &category,
183 COL_DEBUG_LEVEL_STRING, &level_string,
184 COL_DEBUG_MESSAGE, &message,
185 COL_DEBUG_LEVEL_VALUE, &level,
187 gtk_list_store_append (active_buffer, &active_buffer_iter);
188 gtk_list_store_set (active_buffer, &active_buffer_iter,
189 COL_DEBUG_TIMESTAMP, timestamp,
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,
199 g_free (level_string);
206 debug_window_add_message (EmpathyDebugWindow *debug_window,
209 const gchar *domain_category,
211 const gchar *message)
213 EmpathyDebugWindowPriv *priv = GET_PRIV (debug_window);
214 gchar *domain, *category;
217 GtkListStore *active_buffer, *pause_buffer;
219 if (g_strrstr (domain_category, "/"))
221 gchar **parts = g_strsplit (domain_category, "/", 2);
222 domain = g_strdup (parts[0]);
223 category = g_strdup (parts[1]);
228 domain = g_strdup (domain_category);
229 category = g_strdup ("");
232 if (g_str_has_suffix (message, "\n"))
233 string = g_strchomp (g_strdup (message));
235 string = g_strdup (message);
237 pause_buffer = g_object_get_data (G_OBJECT (proxy), "pause-buffer");
238 active_buffer = g_object_get_data (G_OBJECT (proxy), "active-buffer");
240 gtk_list_store_append (priv->paused ? pause_buffer : active_buffer,
242 gtk_list_store_set (priv->paused ? pause_buffer : active_buffer, &iter,
243 COL_DEBUG_TIMESTAMP, timestamp,
244 COL_DEBUG_DOMAIN, domain,
245 COL_DEBUG_CATEGORY, category,
246 COL_DEBUG_LEVEL_STRING, log_level_to_string (level),
247 COL_DEBUG_MESSAGE, string,
248 COL_DEBUG_LEVEL_VALUE, level,
257 debug_window_new_debug_message_cb (TpProxy *proxy,
261 const gchar *message,
263 GObject *weak_object)
265 EmpathyDebugWindow *debug_window = (EmpathyDebugWindow *) user_data;
267 debug_window_add_message (debug_window, proxy, timestamp, domain, level,
272 debug_window_set_enabled (TpProxy *proxy,
277 g_return_if_fail (proxy != NULL);
279 val = tp_g_value_slice_new_boolean (enabled);
281 tp_cli_dbus_properties_call_set (proxy, -1, TP_IFACE_DEBUG,
282 "Enabled", val, NULL, NULL, NULL, NULL);
284 tp_g_value_slice_free (val);
288 debug_window_set_toolbar_sensitivity (EmpathyDebugWindow *debug_window,
291 EmpathyDebugWindowPriv *priv = GET_PRIV (debug_window);
292 GtkWidget *vbox = gtk_bin_get_child (GTK_BIN (debug_window));
294 gtk_widget_set_sensitive (GTK_WIDGET (priv->save_button), sensitive);
295 gtk_widget_set_sensitive (GTK_WIDGET (priv->copy_button), sensitive);
296 gtk_widget_set_sensitive (GTK_WIDGET (priv->clear_button), sensitive);
297 gtk_widget_set_sensitive (GTK_WIDGET (priv->pause_button), sensitive);
298 gtk_widget_set_sensitive (GTK_WIDGET (priv->level_label), sensitive);
299 gtk_widget_set_sensitive (GTK_WIDGET (priv->level_filter), sensitive);
300 gtk_widget_set_sensitive (GTK_WIDGET (priv->view), sensitive);
302 if (sensitive && !priv->view_visible)
304 /* Add view and remove label */
305 gtk_container_remove (GTK_CONTAINER (vbox), priv->not_supported_label);
306 gtk_box_pack_start (GTK_BOX (vbox), priv->scrolled_win, TRUE, TRUE, 0);
307 priv->view_visible = TRUE;
309 else if (!sensitive && priv->view_visible)
311 /* Add label and remove view */
312 gtk_container_remove (GTK_CONTAINER (vbox), priv->scrolled_win);
313 gtk_box_pack_start (GTK_BOX (vbox), priv->not_supported_label,
315 priv->view_visible = FALSE;
320 proxy_invalidated_cb (TpProxy *proxy,
326 /* Proxy has been invalidated so we destroy it */
327 tp_clear_object (&proxy);
331 debug_window_get_messages_cb (TpProxy *proxy,
332 const GPtrArray *messages,
335 GObject *weak_object)
337 EmpathyDebugWindow *debug_window = (EmpathyDebugWindow *) user_data;
338 EmpathyDebugWindowPriv *priv = GET_PRIV (debug_window);
342 GtkTreeModel *pause_buffer, *active_buffer;
346 DEBUG ("GetMessages failed: %s", error->message);
347 debug_window_set_toolbar_sensitivity (debug_window, FALSE);
349 /* We created the proxy for GetMessages call. Now destroy it. */
350 tp_clear_object (&proxy);
354 name = get_active_service_name (debug_window);
355 DEBUG ("Retrieved debug messages for %s", name);
358 gtk_combo_box_get_active_iter (GTK_COMBO_BOX (priv->chooser), &iter);
359 gtk_tree_model_get (GTK_TREE_MODEL (priv->service_store), &iter,
360 COL_ACTIVE_BUFFER, &active_buffer,
361 COL_PAUSE_BUFFER, &pause_buffer,
364 g_object_set_data (G_OBJECT (proxy), "active-buffer", active_buffer);
365 g_object_set_data (G_OBJECT (proxy), "pause-buffer", pause_buffer);
366 g_object_unref (active_buffer);
367 g_object_unref (pause_buffer);
369 for (i = 0; i < messages->len; i++)
371 GValueArray *values = g_ptr_array_index (messages, i);
373 debug_window_add_message (debug_window, proxy,
374 g_value_get_double (g_value_array_get_nth (values, 0)),
375 g_value_get_string (g_value_array_get_nth (values, 1)),
376 g_value_get_uint (g_value_array_get_nth (values, 2)),
377 g_value_get_string (g_value_array_get_nth (values, 3)));
380 /* Now we save this precious proxy in the service_store along its service */
381 gtk_list_store_set (priv->service_store, &iter, COL_PROXY, proxy, -1);
383 /* Connect to "invalidated" signal */
384 g_signal_connect (proxy, "invalidated",
385 G_CALLBACK (proxy_invalidated_cb), NULL);
387 /* Connect to NewDebugMessage */
388 emp_cli_debug_connect_to_new_debug_message (
389 proxy, debug_window_new_debug_message_cb, debug_window,
392 /* Now that active-buffer is up to date, we can see which messages are
394 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->store_filter));
396 /* Set the proxy to signal for new debug messages */
397 debug_window_set_enabled (proxy, TRUE);
401 debug_window_visible_func (GtkTreeModel *model,
405 EmpathyDebugWindow *debug_window = (EmpathyDebugWindow *) user_data;
406 EmpathyDebugWindowPriv *priv = GET_PRIV (debug_window);
407 guint filter_value, level;
408 GtkTreeModel *filter_model;
409 GtkTreeIter filter_iter;
411 filter_model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->level_filter));
412 gtk_combo_box_get_active_iter (GTK_COMBO_BOX (priv->level_filter),
415 gtk_tree_model_get (model, iter, COL_DEBUG_LEVEL_VALUE, &level, -1);
416 gtk_tree_model_get (filter_model, &filter_iter,
417 COL_LEVEL_VALUE, &filter_value, -1);
419 if (level <= filter_value)
426 tree_view_search_equal_func_cb (GtkTreeModel *model,
430 gpointer search_data)
436 gboolean ret = TRUE; /* The return value is counter-intuitive */
438 gtk_tree_model_get (model, iter, column, &str, -1);
440 key_len = strlen (key);
441 len = strlen (str) - key_len;
443 for (i = 0; i <= len; ++i)
445 if (!g_ascii_strncasecmp (key, str + i, key_len))
457 debug_window_service_chooser_changed_cb (GtkComboBox *chooser,
458 EmpathyDebugWindow *debug_window)
460 EmpathyDebugWindowPriv *priv = GET_PRIV (debug_window);
462 GError *error = NULL;
463 gchar *bus_name, *name = NULL;
464 TpProxy *new_proxy, *stored_proxy = NULL;
465 GtkListStore *stored_active_buffer = NULL;
469 if (!gtk_combo_box_get_active_iter (chooser, &iter))
471 DEBUG ("No CM is selected");
472 if (gtk_tree_model_iter_n_children (
473 GTK_TREE_MODEL (priv->service_store), NULL) > 0)
475 gtk_combo_box_set_active (chooser, 0);
480 gtk_tree_model_get (GTK_TREE_MODEL (priv->service_store), &iter,
483 COL_ACTIVE_BUFFER, &stored_active_buffer,
484 COL_PROXY, &stored_proxy,
487 if (stored_active_buffer == NULL)
489 DEBUG ("No list store assigned to service %s", name);
493 debug_window_set_toolbar_sensitivity (debug_window, TRUE);
495 tp_clear_object (&priv->store_filter);
496 priv->store_filter = gtk_tree_model_filter_new (
497 GTK_TREE_MODEL (stored_active_buffer), NULL);
499 gtk_tree_model_filter_set_visible_func (
500 GTK_TREE_MODEL_FILTER (priv->store_filter),
501 debug_window_visible_func, debug_window, NULL);
503 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->view), priv->store_filter);
505 /* Since view's model has changed, reset the search column and
506 * search_equal_func */
507 gtk_tree_view_set_search_column (GTK_TREE_VIEW (priv->view),
509 gtk_tree_view_set_search_equal_func (GTK_TREE_VIEW (priv->view),
510 tree_view_search_equal_func_cb, NULL, NULL);
512 /* If the stored_proxy is not NULL then messages have been obtained and
513 * new-debug-message-signal has been set on it. Also, the proxy is valid.
514 * If the service is gone, we still display the messages-cached till now. */
516 (!gone && stored_proxy != NULL))
518 /* Nothing needs to be done. The associated active-buffer has already
519 * been set as view's model */
523 dbus = tp_dbus_daemon_dup (&error);
527 DEBUG ("Failed at duping the dbus daemon: %s", error->message);
530 gtk_tree_model_get (GTK_TREE_MODEL (priv->service_store), &iter,
531 COL_UNIQUE_NAME, &bus_name, -1);
532 new_proxy = g_object_new (TP_TYPE_PROXY,
533 "bus-name", bus_name,
535 "object-path", DEBUG_OBJECT_PATH,
539 /* Now we call GetMessages with fresh proxy.
540 * The old proxy is NULL due to one of the following -
541 * * Wasn't saved as last GetMessages call failed
542 * * The service has newly arrived and no proxy has been prepared yet for it
543 * * A service with the same name has reappeared but the owner maybe new */
544 tp_proxy_add_interface_by_id (new_proxy, emp_iface_quark_debug ());
546 emp_cli_debug_call_get_messages (new_proxy, -1,
547 debug_window_get_messages_cb, debug_window, NULL, NULL);
549 g_object_unref (dbus);
553 tp_clear_object (&stored_active_buffer);
554 tp_clear_object (&stored_proxy);
562 GtkTreeIter **found_iter;
563 } CmInModelForeachData;
566 debug_window_service_foreach (GtkTreeModel *model,
571 CmInModelForeachData *data = (CmInModelForeachData *) user_data;
574 gtk_tree_model_get (model, iter,
575 (data->use_name ? COL_NAME : COL_UNIQUE_NAME),
579 if (!tp_strdiff (store_name, data->name))
583 if (data->found_iter != NULL)
584 *(data->found_iter) = gtk_tree_iter_copy (iter);
593 debug_window_service_is_in_model (EmpathyDebugWindow *debug_window,
598 EmpathyDebugWindowPriv *priv = GET_PRIV (debug_window);
599 CmInModelForeachData *data;
602 data = g_slice_new0 (CmInModelForeachData);
605 data->found_iter = iter;
606 data->use_name = use_name;
608 gtk_tree_model_foreach (GTK_TREE_MODEL (priv->service_store),
609 debug_window_service_foreach, data);
613 g_slice_free (CmInModelForeachData, data);
619 get_cm_display_name (EmpathyDebugWindow *self,
622 EmpathyDebugWindowPriv *priv = GET_PRIV (self);
623 GHashTable *protocols = g_hash_table_new (g_str_hash, g_str_equal);
624 GList *accounts, *ptr;
627 accounts = tp_account_manager_get_valid_accounts (priv->am);
629 for (ptr = accounts; ptr != NULL; ptr = ptr->next)
631 TpAccount *account = TP_ACCOUNT (ptr->data);
633 if (!tp_strdiff (tp_account_get_connection_manager (account), cm_name))
635 g_hash_table_insert (protocols,
636 (char *) tp_account_get_protocol (account),
637 GUINT_TO_POINTER (TRUE));
641 g_list_free (accounts);
643 if (g_hash_table_size (protocols) > 0)
650 protocolsv = g_new0 (char *, g_hash_table_size (protocols) + 1);
652 g_hash_table_iter_init (&iter, protocols);
653 for (i = 0; g_hash_table_iter_next (&iter, (gpointer) &key, NULL); i++)
658 str = g_strjoinv (", ", protocolsv);
659 retval = g_strdup_printf ("%s (%s)", cm_name, str);
666 retval = g_strdup (cm_name);
669 g_hash_table_unref (protocols);
676 EmpathyDebugWindow *debug_window;
679 } FillServiceChooserData;
681 static FillServiceChooserData *
682 fill_service_chooser_data_new (EmpathyDebugWindow *window,
686 FillServiceChooserData * data = g_slice_new (FillServiceChooserData);
688 data->debug_window = window;
689 data->name = g_strdup (name);
690 data->type = SERVICE_TYPE_CM;
695 fill_service_chooser_data_free (FillServiceChooserData *data)
698 g_slice_free (FillServiceChooserData, data);
702 new_list_store_for_service (void)
704 return gtk_list_store_new (NUM_DEBUG_COLS,
705 G_TYPE_DOUBLE, /* COL_DEBUG_TIMESTAMP */
706 G_TYPE_STRING, /* COL_DEBUG_DOMAIN */
707 G_TYPE_STRING, /* COL_DEBUG_CATEGORY */
708 G_TYPE_STRING, /* COL_DEBUG_LEVEL_STRING */
709 G_TYPE_STRING, /* COL_DEBUG_MESSAGE */
710 G_TYPE_UINT); /* COL_DEBUG_LEVEL_VALUE */
714 debug_window_get_name_owner_cb (TpDBusDaemon *proxy,
718 GObject *weak_object)
720 FillServiceChooserData *data = (FillServiceChooserData *) user_data;
721 EmpathyDebugWindow *self = EMPATHY_DEBUG_WINDOW (data->debug_window);
722 EmpathyDebugWindowPriv *priv = GET_PRIV (data->debug_window);
726 DEBUG ("GetNameOwner failed: %s", error->message);
730 if (!debug_window_service_is_in_model (data->debug_window, out, NULL, FALSE))
734 GtkListStore *active_buffer, *pause_buffer;
736 DEBUG ("Adding %s to list: %s at unique name: %s",
737 data->type == SERVICE_TYPE_CM? "CM": "Client",
740 if (data->type == SERVICE_TYPE_CM)
741 name = get_cm_display_name (self, data->name);
743 name = g_strdup (data->name);
745 active_buffer = new_list_store_for_service ();
746 pause_buffer = new_list_store_for_service ();
748 gtk_list_store_append (priv->service_store, &iter);
749 gtk_list_store_set (priv->service_store, &iter,
751 COL_UNIQUE_NAME, out,
753 COL_ACTIVE_BUFFER, active_buffer,
754 COL_PAUSE_BUFFER, pause_buffer,
758 g_object_unref (active_buffer);
759 g_object_unref (pause_buffer);
761 if (priv->select_name != NULL &&
762 !tp_strdiff (name, priv->select_name))
764 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (priv->chooser), &iter);
765 tp_clear_pointer (&priv->select_name, g_free);
772 fill_service_chooser_data_free (data);
776 debug_window_list_connection_names_cb (const gchar * const *names,
778 const gchar * const *cms,
779 const gchar * const *protocols,
782 GObject *weak_object)
784 EmpathyDebugWindow *debug_window = (EmpathyDebugWindow *) user_data;
787 GError *error2 = NULL;
791 DEBUG ("list_connection_names failed: %s", error->message);
795 dbus = tp_dbus_daemon_dup (&error2);
799 DEBUG ("Failed to dup TpDBusDaemon.");
800 g_error_free (error2);
804 for (i = 0; cms[i] != NULL; i++)
806 FillServiceChooserData *data = fill_service_chooser_data_new (
807 debug_window, cms[i], SERVICE_TYPE_CM);
809 tp_cli_dbus_daemon_call_get_name_owner (dbus, -1,
810 names[i], debug_window_get_name_owner_cb,
814 g_object_unref (dbus);
818 debug_window_name_owner_changed_cb (TpDBusDaemon *proxy,
823 GObject *weak_object)
825 EmpathyDebugWindow *self = EMPATHY_DEBUG_WINDOW (user_data);
826 EmpathyDebugWindowPriv *priv = GET_PRIV (user_data);
830 if (g_str_has_prefix (arg0, TP_CM_BUS_NAME_BASE))
832 type = SERVICE_TYPE_CM;
833 name = arg0 + strlen (TP_CM_BUS_NAME_BASE);
835 else if (g_str_has_prefix (arg0, TP_CLIENT_BUS_NAME_BASE))
837 type = SERVICE_TYPE_CLIENT;
838 name = arg0 + strlen (TP_CLIENT_BUS_NAME_BASE);
845 if (EMP_STR_EMPTY (arg1) && !EMP_STR_EMPTY (arg2))
847 GtkTreeIter *found_at_iter = NULL;
850 if (type == SERVICE_TYPE_CM)
851 display_name = get_cm_display_name (self, name);
853 display_name = g_strdup (name);
855 /* A service joined */
856 if (!debug_window_service_is_in_model (user_data, display_name,
857 &found_at_iter, TRUE))
860 GtkListStore *active_buffer, *pause_buffer;
862 DEBUG ("Adding new service '%s' at %s.", name, arg2);
864 active_buffer = new_list_store_for_service ();
865 pause_buffer = new_list_store_for_service ();
867 gtk_list_store_append (priv->service_store, &iter);
868 gtk_list_store_set (priv->service_store, &iter,
869 COL_NAME, display_name,
870 COL_UNIQUE_NAME, arg2,
872 COL_ACTIVE_BUFFER, active_buffer,
873 COL_PAUSE_BUFFER, pause_buffer,
877 g_object_unref (active_buffer);
878 g_object_unref (pause_buffer);
882 /* a service with the same name is already in the service_store,
883 * update it and set it as re-enabled.
885 GtkListStore *active_buffer, *pause_buffer;
886 TpProxy *stored_proxy;
888 DEBUG ("Refreshing CM '%s' at '%s'.", name, arg2);
890 active_buffer= new_list_store_for_service ();
891 pause_buffer = new_list_store_for_service ();
893 gtk_tree_model_get (GTK_TREE_MODEL (priv->service_store),
894 found_at_iter, COL_PROXY, &stored_proxy, -1);
896 tp_clear_object (&stored_proxy);
898 gtk_list_store_set (priv->service_store, found_at_iter,
899 COL_NAME, display_name,
900 COL_UNIQUE_NAME, arg2,
902 COL_ACTIVE_BUFFER, active_buffer,
903 COL_PAUSE_BUFFER, pause_buffer,
907 g_object_unref (active_buffer);
908 g_object_unref (pause_buffer);
910 gtk_tree_iter_free (found_at_iter);
912 debug_window_service_chooser_changed_cb
913 (GTK_COMBO_BOX (priv->chooser), user_data);
916 g_free (display_name);
918 else if (!EMP_STR_EMPTY (arg1) && EMP_STR_EMPTY (arg2))
921 GtkTreeIter *iter = NULL;
923 DEBUG ("Setting service disabled from %s.", arg1);
925 /* set the service as disabled in the model */
926 if (debug_window_service_is_in_model (user_data, arg1, &iter, FALSE))
928 gtk_list_store_set (priv->service_store,
929 iter, COL_GONE, TRUE, -1);
930 gtk_tree_iter_free (iter);
936 add_client (EmpathyDebugWindow *self,
939 EmpathyDebugWindowPriv *priv = GET_PRIV (self);
941 FillServiceChooserData *data;
943 suffix = name + strlen (TP_CLIENT_BUS_NAME_BASE);
945 data = fill_service_chooser_data_new (self, suffix, SERVICE_TYPE_CLIENT);
947 tp_cli_dbus_daemon_call_get_name_owner (priv->dbus, -1,
948 name, debug_window_get_name_owner_cb, data, NULL, NULL);
952 list_names_cb (TpDBusDaemon *bus_daemon,
953 const gchar * const *names,
956 GObject *weak_object)
958 EmpathyDebugWindow *self = EMPATHY_DEBUG_WINDOW (weak_object);
963 DEBUG ("Failed to list names: %s", error->message);
967 for (i = 0; names[i] != NULL; i++)
969 if (g_str_has_prefix (names[i], TP_CLIENT_BUS_NAME_BASE))
971 add_client (self, names[i]);
977 debug_window_fill_service_chooser (EmpathyDebugWindow *debug_window)
979 EmpathyDebugWindowPriv *priv = GET_PRIV (debug_window);
980 GError *error = NULL;
982 GtkListStore *active_buffer, *pause_buffer;
984 priv->dbus = tp_dbus_daemon_dup (&error);
988 DEBUG ("Failed to dup dbus daemon: %s", error->message);
989 g_error_free (error);
993 /* Add CMs to list */
994 tp_list_connection_names (priv->dbus, debug_window_list_connection_names_cb,
995 debug_window, NULL, NULL);
997 /* add Mission Control */
998 active_buffer= new_list_store_for_service ();
999 pause_buffer = new_list_store_for_service ();
1001 gtk_list_store_append (priv->service_store, &iter);
1002 gtk_list_store_set (priv->service_store, &iter,
1003 COL_NAME, "mission-control",
1004 COL_UNIQUE_NAME, "org.freedesktop.Telepathy.MissionControl5",
1006 COL_ACTIVE_BUFFER, active_buffer,
1007 COL_PAUSE_BUFFER, pause_buffer,
1010 g_object_unref (active_buffer);
1011 g_object_unref (pause_buffer);
1013 gtk_combo_box_set_active (GTK_COMBO_BOX (priv->chooser), 0);
1016 tp_dbus_daemon_list_names (priv->dbus, 2000,
1017 list_names_cb, NULL, NULL, G_OBJECT (debug_window));
1019 priv->name_owner_changed_signal =
1020 tp_cli_dbus_daemon_connect_to_name_owner_changed (priv->dbus,
1021 debug_window_name_owner_changed_cb, debug_window, NULL, NULL, NULL);
1025 debug_window_pause_toggled_cb (GtkToggleToolButton *pause_,
1026 EmpathyDebugWindow *debug_window)
1028 EmpathyDebugWindowPriv *priv = GET_PRIV (debug_window);
1030 gboolean valid_iter;
1031 GtkTreeModel *model = GTK_TREE_MODEL (priv->service_store);
1033 priv->paused = gtk_toggle_tool_button_get_active (pause_);
1037 /* Pause has been released - flush all pause buffers */
1039 for (valid_iter = gtk_tree_model_get_iter_first (model, &iter);
1041 valid_iter = gtk_tree_model_iter_next (model, &iter))
1043 GtkTreeModel *service_store = GTK_TREE_MODEL (priv->service_store);
1044 GtkListStore *pause_buffer, *active_buffer;
1046 gtk_tree_model_get (service_store, &iter,
1047 COL_PAUSE_BUFFER, &pause_buffer,
1048 COL_ACTIVE_BUFFER, &active_buffer,
1051 gtk_tree_model_foreach (GTK_TREE_MODEL (pause_buffer),
1052 flush_buffered_messages_to_list_store, active_buffer);
1053 gtk_list_store_clear (pause_buffer);
1055 g_object_unref (active_buffer);
1056 g_object_unref (pause_buffer);
1062 debug_window_filter_changed_cb (GtkComboBox *filter,
1063 EmpathyDebugWindow *debug_window)
1065 EmpathyDebugWindowPriv *priv = GET_PRIV (debug_window);
1067 gtk_tree_model_filter_refilter (
1068 GTK_TREE_MODEL_FILTER (priv->store_filter));
1072 debug_window_clear_clicked_cb (GtkToolButton *clear_button,
1073 EmpathyDebugWindow *debug_window)
1075 EmpathyDebugWindowPriv *priv = GET_PRIV (debug_window);
1077 GtkListStore *active_buffer;
1079 gtk_combo_box_get_active_iter (GTK_COMBO_BOX (priv->chooser), &iter);
1080 gtk_tree_model_get (GTK_TREE_MODEL (priv->service_store), &iter,
1081 COL_ACTIVE_BUFFER, &active_buffer, -1);
1083 gtk_list_store_clear (active_buffer);
1085 g_object_unref (active_buffer);
1089 debug_window_menu_copy_activate_cb (GtkMenuItem *menu_item,
1090 EmpathyDebugWindow *debug_window)
1092 EmpathyDebugWindowPriv *priv = GET_PRIV (debug_window);
1094 GtkTreeViewColumn *focus_column;
1097 GtkClipboard *clipboard;
1099 gtk_tree_view_get_cursor (GTK_TREE_VIEW (priv->view),
1100 &path, &focus_column);
1104 DEBUG ("No row is in focus");
1108 gtk_tree_model_get_iter (priv->store_filter, &iter, path);
1110 gtk_tree_model_get (priv->store_filter, &iter,
1111 COL_DEBUG_MESSAGE, &message,
1114 if (EMP_STR_EMPTY (message))
1116 DEBUG ("Log message is empty");
1120 clipboard = gtk_clipboard_get_for_display (
1121 gtk_widget_get_display (GTK_WIDGET (menu_item)),
1122 GDK_SELECTION_CLIPBOARD);
1124 gtk_clipboard_set_text (clipboard, message, -1);
1131 EmpathyDebugWindow *debug_window;
1137 debug_window_show_menu (gpointer user_data)
1139 MenuPopupData *data = (MenuPopupData *) user_data;
1140 GtkWidget *menu, *item;
1141 GtkMenuShell *shell;
1143 menu = empathy_context_menu_new (GTK_WIDGET (data->debug_window));
1144 shell = GTK_MENU_SHELL (menu);
1146 item = gtk_image_menu_item_new_from_stock (GTK_STOCK_COPY, NULL);
1148 g_signal_connect (item, "activate",
1149 G_CALLBACK (debug_window_menu_copy_activate_cb), data->debug_window);
1151 gtk_menu_shell_append (shell, item);
1152 gtk_widget_show (item);
1154 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
1155 data->button, data->time);
1157 g_slice_free (MenuPopupData, user_data);
1163 debug_window_button_press_event_cb (GtkTreeView *view,
1164 GdkEventButton *event,
1167 /* A mouse button was pressed on the tree view. */
1169 if (event->button == 3)
1171 /* The tree view was right-clicked. (3 == third mouse button) */
1172 MenuPopupData *data;
1173 data = g_slice_new0 (MenuPopupData);
1174 data->debug_window = user_data;
1175 data->button = event->button;
1176 data->time = event->time;
1177 g_idle_add (debug_window_show_menu, data);
1184 debug_window_format_timestamp (gdouble timestamp)
1192 ms = (int) ((timestamp - (int) timestamp)*1e6);
1193 sec = (long) timestamp;
1194 tstruct = localtime ((time_t *) &sec);
1195 if (!strftime (time_str, sizeof (time_str), "%x %T", tstruct))
1197 DEBUG ("Failed to format timestamp: %e", timestamp);
1201 text = g_strdup_printf ("%s.%d", time_str, ms);
1207 debug_window_time_formatter (GtkTreeViewColumn *tree_column,
1208 GtkCellRenderer *cell,
1209 GtkTreeModel *tree_model,
1216 gtk_tree_model_get (tree_model, iter, COL_DEBUG_TIMESTAMP, ×tamp, -1);
1218 time_str = debug_window_format_timestamp (timestamp);
1220 g_object_set (G_OBJECT (cell), "text", time_str, NULL);
1226 debug_window_store_filter_foreach (GtkTreeModel *model,
1231 GFileOutputStream *output_stream = (GFileOutputStream *) user_data;
1232 gchar *domain, *category, *message, *level_str, *level_upper;
1234 gchar *line, *time_str;
1235 GError *error = NULL;
1236 gboolean out = FALSE;
1238 gtk_tree_model_get (model, iter,
1239 COL_DEBUG_TIMESTAMP, ×tamp,
1240 COL_DEBUG_DOMAIN, &domain,
1241 COL_DEBUG_CATEGORY, &category,
1242 COL_DEBUG_LEVEL_STRING, &level_str,
1243 COL_DEBUG_MESSAGE, &message,
1246 level_upper = g_ascii_strup (level_str, -1);
1248 time_str = debug_window_format_timestamp (timestamp);
1250 line = g_strdup_printf ("%s%s%s-%s: %s: %s\n",
1251 domain, EMP_STR_EMPTY (category) ? "" : "/",
1252 category, level_upper, time_str, message);
1256 g_output_stream_write (G_OUTPUT_STREAM (output_stream), line,
1257 strlen (line), NULL, &error);
1261 DEBUG ("Failed to write to file: %s", error->message);
1262 g_error_free (error);
1267 g_free (level_upper);
1277 debug_window_save_file_chooser_response_cb (GtkDialog *dialog,
1279 EmpathyDebugWindow *debug_window)
1281 EmpathyDebugWindowPriv *priv = GET_PRIV (debug_window);
1282 gchar *filename = NULL;
1283 GFile *gfile = NULL;
1284 GFileOutputStream *output_stream = NULL;
1285 GError *error = NULL;
1287 if (response_id != GTK_RESPONSE_ACCEPT)
1290 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
1292 DEBUG ("Saving log as %s", filename);
1294 gfile = g_file_new_for_path (filename);
1295 output_stream = g_file_replace (gfile, NULL, FALSE,
1296 G_FILE_CREATE_NONE, NULL, &error);
1300 DEBUG ("Failed to open file for writing: %s", error->message);
1301 g_error_free (error);
1305 gtk_tree_model_foreach (priv->store_filter,
1306 debug_window_store_filter_foreach, output_stream);
1310 g_object_unref (gfile);
1312 if (output_stream != NULL)
1313 g_object_unref (output_stream);
1315 if (filename != NULL)
1318 gtk_widget_destroy (GTK_WIDGET (dialog));
1322 debug_window_save_clicked_cb (GtkToolButton *tool_button,
1323 EmpathyDebugWindow *debug_window)
1325 GtkWidget *file_chooser;
1326 gchar *name, *tmp = NULL;
1331 file_chooser = gtk_file_chooser_dialog_new (_("Save"),
1332 GTK_WINDOW (debug_window), GTK_FILE_CHOOSER_ACTION_SAVE,
1333 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1334 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
1337 gtk_window_set_modal (GTK_WINDOW (file_chooser), TRUE);
1338 gtk_file_chooser_set_do_overwrite_confirmation (
1339 GTK_FILE_CHOOSER (file_chooser), TRUE);
1341 gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (file_chooser),
1344 name = get_active_service_name (debug_window);
1347 tm_s = localtime (&t);
1350 if (strftime(time_str, sizeof (time_str), "%d-%m-%y_%H-%M-%S", tm_s))
1351 tmp = g_strdup_printf ("%s-%s.log", name, time_str);
1355 tmp = g_strdup_printf ("%s.log", name);
1358 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (file_chooser), tmp);
1361 g_signal_connect (file_chooser, "response",
1362 G_CALLBACK (debug_window_save_file_chooser_response_cb),
1365 gtk_widget_show (file_chooser);
1369 debug_window_copy_model_foreach (GtkTreeModel *model,
1374 gchar **text = (gchar **) user_data;
1376 gchar *domain, *category, *message, *level_str, *level_upper;
1378 gchar *line, *time_str;
1380 gtk_tree_model_get (model, iter,
1381 COL_DEBUG_TIMESTAMP, ×tamp,
1382 COL_DEBUG_DOMAIN, &domain,
1383 COL_DEBUG_CATEGORY, &category,
1384 COL_DEBUG_LEVEL_STRING, &level_str,
1385 COL_DEBUG_MESSAGE, &message,
1388 level_upper = g_ascii_strup (level_str, -1);
1390 time_str = debug_window_format_timestamp (timestamp);
1392 line = g_strdup_printf ("%s%s%s-%s: %s: %s\n",
1393 domain, EMP_STR_EMPTY (category) ? "" : "/",
1394 category, level_upper, time_str, message);
1398 tmp = g_strconcat (*text, line, NULL);
1402 g_free (level_upper);
1414 debug_window_copy_clicked_cb (GtkToolButton *tool_button,
1415 EmpathyDebugWindow *debug_window)
1417 EmpathyDebugWindowPriv *priv = GET_PRIV (debug_window);
1418 GtkClipboard *clipboard;
1421 text = g_strdup ("");
1423 gtk_tree_model_foreach (priv->store_filter,
1424 debug_window_copy_model_foreach, &text);
1426 clipboard = gtk_clipboard_get_for_display (
1427 gtk_widget_get_display (GTK_WIDGET (tool_button)),
1428 GDK_SELECTION_CLIPBOARD);
1430 DEBUG ("Copying text to clipboard (length: %" G_GSIZE_FORMAT ")",
1433 gtk_clipboard_set_text (clipboard, text, -1);
1439 debug_window_key_press_event_cb (GtkWidget *widget,
1443 if ((event->state & GDK_CONTROL_MASK && event->keyval == GDK_KEY_w)
1444 || event->keyval == GDK_KEY_Escape)
1446 gtk_widget_destroy (widget);
1454 empathy_debug_window_select_name (EmpathyDebugWindow *self,
1457 EmpathyDebugWindowPriv *priv = GET_PRIV (self);
1458 GtkTreeModel *model = GTK_TREE_MODEL (priv->service_store);
1461 gboolean valid, found = FALSE;
1463 for (valid = gtk_tree_model_get_iter_first (model, &iter);
1465 valid = gtk_tree_model_iter_next (model, &iter))
1467 gtk_tree_model_get (model, &iter,
1468 COL_NAME, &iter_name,
1471 if (!tp_strdiff (name, iter_name))
1481 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (priv->chooser), &iter);
1485 am_prepared_cb (GObject *am,
1489 GObject *object = user_data;
1490 EmpathyDebugWindowPriv *priv = GET_PRIV (object);
1496 GtkCellRenderer *renderer;
1497 GtkListStore *level_store;
1499 GError *error = NULL;
1501 if (!tp_proxy_prepare_finish (am, res, &error))
1503 g_warning ("Failed to prepare AM: %s", error->message);
1504 g_clear_error (&error);
1507 gtk_window_set_title (GTK_WINDOW (object), _("Debug Window"));
1508 gtk_window_set_default_size (GTK_WINDOW (object), 800, 400);
1509 empathy_geometry_bind (GTK_WINDOW (object), "debug-window");
1511 g_signal_connect (object, "key-press-event",
1512 G_CALLBACK (debug_window_key_press_event_cb), NULL);
1514 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
1515 gtk_container_add (GTK_CONTAINER (object), vbox);
1516 gtk_widget_show (vbox);
1518 toolbar = gtk_toolbar_new ();
1519 gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_BOTH_HORIZ);
1520 gtk_toolbar_set_show_arrow (GTK_TOOLBAR (toolbar), TRUE);
1521 gtk_toolbar_set_icon_size (GTK_TOOLBAR (toolbar),
1522 GTK_ICON_SIZE_SMALL_TOOLBAR);
1523 gtk_style_context_add_class (gtk_widget_get_style_context (toolbar),
1524 GTK_STYLE_CLASS_PRIMARY_TOOLBAR);
1525 gtk_widget_show (toolbar);
1527 gtk_box_pack_start (GTK_BOX (vbox), toolbar, FALSE, FALSE, 0);
1530 priv->chooser = gtk_combo_box_text_new ();
1531 priv->service_store = gtk_list_store_new (NUM_COLS,
1532 G_TYPE_STRING, /* COL_NAME */
1533 G_TYPE_STRING, /* COL_UNIQUE_NAME */
1534 G_TYPE_BOOLEAN, /* COL_GONE */
1535 G_TYPE_OBJECT, /* COL_ACTIVE_BUFFER */
1536 G_TYPE_OBJECT, /* COL_PAUSE_BUFFER */
1537 TP_TYPE_PROXY); /* COL_PROXY */
1538 gtk_combo_box_set_model (GTK_COMBO_BOX (priv->chooser),
1539 GTK_TREE_MODEL (priv->service_store));
1540 gtk_widget_show (priv->chooser);
1542 item = gtk_tool_item_new ();
1543 gtk_widget_show (GTK_WIDGET (item));
1544 gtk_container_add (GTK_CONTAINER (item), priv->chooser);
1545 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
1546 g_signal_connect (priv->chooser, "changed",
1547 G_CALLBACK (debug_window_service_chooser_changed_cb), object);
1548 gtk_widget_show (GTK_WIDGET (priv->chooser));
1550 item = gtk_separator_tool_item_new ();
1551 gtk_widget_show (GTK_WIDGET (item));
1552 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
1555 priv->save_button = gtk_tool_button_new_from_stock (GTK_STOCK_SAVE);
1556 g_signal_connect (priv->save_button, "clicked",
1557 G_CALLBACK (debug_window_save_clicked_cb), object);
1558 gtk_widget_show (GTK_WIDGET (priv->save_button));
1559 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (priv->save_button), TRUE);
1560 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->save_button, -1);
1563 priv->copy_button = gtk_tool_button_new_from_stock (GTK_STOCK_COPY);
1564 g_signal_connect (priv->copy_button, "clicked",
1565 G_CALLBACK (debug_window_copy_clicked_cb), object);
1566 gtk_widget_show (GTK_WIDGET (priv->copy_button));
1567 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (priv->copy_button), TRUE);
1568 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->copy_button, -1);
1571 priv->clear_button = gtk_tool_button_new_from_stock (GTK_STOCK_CLEAR);
1572 g_signal_connect (priv->clear_button, "clicked",
1573 G_CALLBACK (debug_window_clear_clicked_cb), object);
1574 gtk_widget_show (GTK_WIDGET (priv->clear_button));
1575 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (priv->clear_button), TRUE);
1576 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->clear_button, -1);
1578 item = gtk_separator_tool_item_new ();
1579 gtk_widget_show (GTK_WIDGET (item));
1580 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
1583 priv->paused = FALSE;
1584 image = gtk_image_new_from_stock (GTK_STOCK_MEDIA_PAUSE,
1585 GTK_ICON_SIZE_MENU);
1586 gtk_widget_show (image);
1587 priv->pause_button = gtk_toggle_tool_button_new ();
1588 gtk_toggle_tool_button_set_active (
1589 GTK_TOGGLE_TOOL_BUTTON (priv->pause_button), priv->paused);
1590 g_signal_connect (priv->pause_button, "toggled",
1591 G_CALLBACK (debug_window_pause_toggled_cb), object);
1592 gtk_widget_show (GTK_WIDGET (priv->pause_button));
1593 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (priv->pause_button), TRUE);
1594 gtk_tool_button_set_label (GTK_TOOL_BUTTON (priv->pause_button), _("Pause"));
1595 gtk_tool_button_set_icon_widget (
1596 GTK_TOOL_BUTTON (priv->pause_button), image);
1597 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->pause_button, -1);
1599 item = gtk_separator_tool_item_new ();
1600 gtk_widget_show (GTK_WIDGET (item));
1601 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
1604 priv->level_label = gtk_tool_item_new ();
1605 gtk_widget_show (GTK_WIDGET (priv->level_label));
1606 label = gtk_label_new (_("Level "));
1607 gtk_widget_show (label);
1608 gtk_container_add (GTK_CONTAINER (priv->level_label), label);
1609 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->level_label, -1);
1611 priv->level_filter = gtk_combo_box_text_new ();
1612 gtk_widget_show (priv->level_filter);
1614 item = gtk_tool_item_new ();
1615 gtk_widget_show (GTK_WIDGET (item));
1616 gtk_container_add (GTK_CONTAINER (item), priv->level_filter);
1617 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
1619 level_store = gtk_list_store_new (NUM_COLS_LEVEL,
1620 G_TYPE_STRING, G_TYPE_UINT);
1621 gtk_combo_box_set_model (GTK_COMBO_BOX (priv->level_filter),
1622 GTK_TREE_MODEL (level_store));
1624 gtk_list_store_append (level_store, &iter);
1625 gtk_list_store_set (level_store, &iter,
1626 COL_LEVEL_NAME, _("Debug"),
1627 COL_LEVEL_VALUE, TP_DEBUG_LEVEL_DEBUG,
1630 gtk_list_store_append (level_store, &iter);
1631 gtk_list_store_set (level_store, &iter,
1632 COL_LEVEL_NAME, _("Info"),
1633 COL_LEVEL_VALUE, TP_DEBUG_LEVEL_INFO,
1636 gtk_list_store_append (level_store, &iter);
1637 gtk_list_store_set (level_store, &iter,
1638 COL_LEVEL_NAME, _("Message"),
1639 COL_LEVEL_VALUE, TP_DEBUG_LEVEL_MESSAGE,
1642 gtk_list_store_append (level_store, &iter);
1643 gtk_list_store_set (level_store, &iter,
1644 COL_LEVEL_NAME, _("Warning"),
1645 COL_LEVEL_VALUE, TP_DEBUG_LEVEL_WARNING,
1648 gtk_list_store_append (level_store, &iter);
1649 gtk_list_store_set (level_store, &iter,
1650 COL_LEVEL_NAME, _("Critical"),
1651 COL_LEVEL_VALUE, TP_DEBUG_LEVEL_CRITICAL,
1654 gtk_list_store_append (level_store, &iter);
1655 gtk_list_store_set (level_store, &iter,
1656 COL_LEVEL_NAME, _("Error"),
1657 COL_LEVEL_VALUE, TP_DEBUG_LEVEL_ERROR,
1660 gtk_combo_box_set_active (GTK_COMBO_BOX (priv->level_filter), 0);
1661 g_signal_connect (priv->level_filter, "changed",
1662 G_CALLBACK (debug_window_filter_changed_cb), object);
1664 /* Debug treeview */
1665 priv->view = gtk_tree_view_new ();
1666 gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (priv->view), TRUE);
1668 g_signal_connect (priv->view, "button-press-event",
1669 G_CALLBACK (debug_window_button_press_event_cb), object);
1671 renderer = gtk_cell_renderer_text_new ();
1672 g_object_set (renderer, "yalign", 0, NULL);
1674 gtk_tree_view_insert_column_with_data_func (GTK_TREE_VIEW (priv->view),
1675 -1, _("Time"), renderer,
1676 (GtkTreeCellDataFunc) debug_window_time_formatter, NULL, NULL);
1677 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
1678 -1, _("Domain"), renderer, "text", COL_DEBUG_DOMAIN, NULL);
1679 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
1680 -1, _("Category"), renderer, "text", COL_DEBUG_CATEGORY, NULL);
1681 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
1682 -1, _("Level"), renderer, "text", COL_DEBUG_LEVEL_STRING, NULL);
1684 renderer = gtk_cell_renderer_text_new ();
1685 g_object_set (renderer, "family", "Monospace", NULL);
1686 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
1687 -1, _("Message"), renderer, "text", COL_DEBUG_MESSAGE, NULL);
1689 priv->store_filter = NULL;
1691 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->view), priv->store_filter);
1693 /* Scrolled window */
1694 priv->scrolled_win = g_object_ref (gtk_scrolled_window_new (NULL, NULL));
1695 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_win),
1696 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1698 gtk_widget_show (priv->view);
1699 gtk_container_add (GTK_CONTAINER (priv->scrolled_win), priv->view);
1701 gtk_widget_show (priv->scrolled_win);
1703 /* Not supported label */
1704 priv->not_supported_label = g_object_ref (gtk_label_new (
1705 _("The selected connection manager does not support the remote "
1706 "debugging extension.")));
1707 gtk_widget_show (priv->not_supported_label);
1708 gtk_box_pack_start (GTK_BOX (vbox), priv->not_supported_label,
1711 priv->view_visible = FALSE;
1713 debug_window_set_toolbar_sensitivity (EMPATHY_DEBUG_WINDOW (object), FALSE);
1714 debug_window_fill_service_chooser (EMPATHY_DEBUG_WINDOW (object));
1715 gtk_widget_show (GTK_WIDGET (object));
1719 debug_window_constructed (GObject *object)
1721 EmpathyDebugWindowPriv *priv = GET_PRIV (object);
1723 priv->am = tp_account_manager_dup ();
1724 tp_proxy_prepare_async (priv->am, NULL, am_prepared_cb, object);
1728 empathy_debug_window_init (EmpathyDebugWindow *empathy_debug_window)
1730 EmpathyDebugWindowPriv *priv =
1731 G_TYPE_INSTANCE_GET_PRIVATE (empathy_debug_window,
1732 EMPATHY_TYPE_DEBUG_WINDOW, EmpathyDebugWindowPriv);
1734 empathy_debug_window->priv = priv;
1736 priv->dispose_run = FALSE;
1740 debug_window_set_property (GObject *object,
1742 const GValue *value,
1748 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1754 debug_window_get_property (GObject *object,
1762 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1768 debug_window_finalize (GObject *object)
1770 EmpathyDebugWindowPriv *priv = GET_PRIV (object);
1772 g_free (priv->select_name);
1774 (G_OBJECT_CLASS (empathy_debug_window_parent_class)->finalize) (object);
1778 debug_window_dispose (GObject *object)
1780 EmpathyDebugWindow *selector = EMPATHY_DEBUG_WINDOW (object);
1781 EmpathyDebugWindowPriv *priv = GET_PRIV (selector);
1783 if (priv->dispose_run)
1786 priv->dispose_run = TRUE;
1788 if (priv->name_owner_changed_signal != NULL)
1789 tp_proxy_signal_connection_disconnect (priv->name_owner_changed_signal);
1791 if (priv->service_store != NULL)
1792 g_object_unref (priv->service_store);
1794 if (priv->dbus != NULL)
1795 g_object_unref (priv->dbus);
1797 if (priv->am != NULL)
1799 g_object_unref (priv->am);
1803 (G_OBJECT_CLASS (empathy_debug_window_parent_class)->dispose) (object);
1807 empathy_debug_window_class_init (EmpathyDebugWindowClass *klass)
1809 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1810 object_class->constructed = debug_window_constructed;
1811 object_class->dispose = debug_window_dispose;
1812 object_class->finalize = debug_window_finalize;
1813 object_class->set_property = debug_window_set_property;
1814 object_class->get_property = debug_window_get_property;
1815 g_type_class_add_private (klass, sizeof (EmpathyDebugWindowPriv));
1818 /* public methods */
1821 empathy_debug_window_new (GtkWindow *parent)
1823 g_return_val_if_fail (parent == NULL || GTK_IS_WINDOW (parent), NULL);
1825 return GTK_WIDGET (g_object_new (EMPATHY_TYPE_DEBUG_WINDOW,
1826 "transient-for", parent, NULL));
1830 empathy_debug_window_show (EmpathyDebugWindow *self,
1833 EmpathyDebugWindowPriv *priv = GET_PRIV (self);
1835 if (priv->service_store != NULL)
1837 empathy_debug_window_select_name (self, name);
1841 g_free (priv->select_name);
1842 priv->select_name = g_strdup (name);