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>
23 #include <glib/gi18n.h>
27 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
28 #include <libempathy/empathy-debug.h>
29 #include <libempathy/empathy-utils.h>
31 #include <libempathy-gtk/empathy-account-chooser.h>
33 #include <telepathy-glib/dbus.h>
34 #include <telepathy-glib/util.h>
35 #include <telepathy-glib/proxy-subclass.h>
37 #include "extensions/extensions.h"
39 #include "empathy-debug-dialog.h"
41 G_DEFINE_TYPE (EmpathyDebugDialog, empathy_debug_dialog,
46 COL_DEBUG_TIMESTAMP = 0,
49 COL_DEBUG_LEVEL_STRING,
51 COL_DEBUG_LEVEL_VALUE,
69 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyDebugDialog)
73 GtkWidget *cm_chooser;
74 GtkToolItem *save_button;
75 GtkToolItem *copy_button;
76 GtkToolItem *clear_button;
77 GtkToolItem *pause_button;
78 GtkToolItem *level_label;
79 GtkWidget *level_filter;
83 GtkTreeModel *store_filter;
85 GtkWidget *scrolled_win;
86 GtkWidget *not_supported_label;
87 gboolean view_visible;
92 TpProxySignalConnection *new_debug_message_signal;
93 TpProxySignalConnection *name_owner_changed_signal;
95 /* Whether NewDebugMessage will be fired */
98 /* CM chooser store */
102 gboolean dispose_run;
103 } EmpathyDebugDialogPriv;
106 log_level_to_string (guint level)
110 case EMP_DEBUG_LEVEL_ERROR:
113 case EMP_DEBUG_LEVEL_CRITICAL:
114 return _("Critical");
116 case EMP_DEBUG_LEVEL_WARNING:
119 case EMP_DEBUG_LEVEL_MESSAGE:
122 case EMP_DEBUG_LEVEL_INFO:
125 case EMP_DEBUG_LEVEL_DEBUG:
129 g_assert_not_reached ();
135 debug_dialog_add_message (EmpathyDebugDialog *debug_dialog,
137 const gchar *domain_category,
139 const gchar *message)
141 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
142 gchar *domain, *category;
146 if (g_strrstr (domain_category, "/"))
148 gchar **parts = g_strsplit (domain_category, "/", 2);
149 domain = g_strdup (parts[0]);
150 category = g_strdup (parts[1]);
155 domain = g_strdup (domain_category);
156 category = g_strdup ("");
159 if (g_str_has_suffix (message, "\n"))
160 string = g_strchomp (g_strdup (message));
162 string = g_strdup (message);
165 gtk_list_store_append (priv->store, &iter);
166 gtk_list_store_set (priv->store, &iter,
167 COL_DEBUG_TIMESTAMP, timestamp,
168 COL_DEBUG_DOMAIN, domain,
169 COL_DEBUG_CATEGORY, category,
170 COL_DEBUG_LEVEL_STRING, log_level_to_string (level),
171 COL_DEBUG_MESSAGE, string,
172 COL_DEBUG_LEVEL_VALUE, level,
181 debug_dialog_new_debug_message_cb (TpProxy *proxy,
185 const gchar *message,
187 GObject *weak_object)
189 EmpathyDebugDialog *debug_dialog = (EmpathyDebugDialog *) user_data;
191 debug_dialog_add_message (debug_dialog, timestamp, domain, level,
196 debug_dialog_set_enabled (EmpathyDebugDialog *debug_dialog,
199 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
202 val = tp_g_value_slice_new_boolean (enabled);
204 tp_cli_dbus_properties_call_set (priv->proxy, -1, EMP_IFACE_DEBUG,
205 "Enabled", val, NULL, NULL, NULL, NULL);
207 tp_g_value_slice_free (val);
211 debug_dialog_set_toolbar_sensitivity (EmpathyDebugDialog *debug_dialog,
214 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
215 GtkWidget *vbox = GTK_DIALOG (debug_dialog)->vbox;
217 gtk_widget_set_sensitive (GTK_WIDGET (priv->save_button), sensitive);
218 gtk_widget_set_sensitive (GTK_WIDGET (priv->copy_button), sensitive);
219 gtk_widget_set_sensitive (GTK_WIDGET (priv->clear_button), sensitive);
220 gtk_widget_set_sensitive (GTK_WIDGET (priv->pause_button), sensitive);
221 gtk_widget_set_sensitive (GTK_WIDGET (priv->level_label), sensitive);
222 gtk_widget_set_sensitive (GTK_WIDGET (priv->level_filter), sensitive);
223 gtk_widget_set_sensitive (GTK_WIDGET (priv->view), sensitive);
225 if (sensitive && !priv->view_visible)
227 /* Add view and remove label */
228 gtk_container_remove (GTK_CONTAINER (vbox), priv->not_supported_label);
229 gtk_box_pack_start (GTK_BOX (vbox), priv->scrolled_win, TRUE, TRUE, 0);
230 priv->view_visible = TRUE;
232 else if (!sensitive && priv->view_visible)
234 /* Add label and remove view */
235 gtk_container_remove (GTK_CONTAINER (vbox), priv->scrolled_win);
236 gtk_box_pack_start (GTK_BOX (vbox), priv->not_supported_label,
238 priv->view_visible = FALSE;
243 debug_dialog_get_messages_cb (TpProxy *proxy,
244 const GPtrArray *messages,
247 GObject *weak_object)
249 EmpathyDebugDialog *debug_dialog = (EmpathyDebugDialog *) user_data;
250 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
255 DEBUG ("GetMessages failed: %s", error->message);
256 debug_dialog_set_toolbar_sensitivity (debug_dialog, FALSE);
260 debug_dialog_set_toolbar_sensitivity (debug_dialog, TRUE);
262 for (i = 0; i < messages->len; i++)
264 GValueArray *values = g_ptr_array_index (messages, i);
266 debug_dialog_add_message (debug_dialog,
267 g_value_get_double (g_value_array_get_nth (values, 0)),
268 g_value_get_string (g_value_array_get_nth (values, 1)),
269 g_value_get_uint (g_value_array_get_nth (values, 2)),
270 g_value_get_string (g_value_array_get_nth (values, 3)));
273 /* Connect to NewDebugMessage */
274 priv->new_debug_message_signal = emp_cli_debug_connect_to_new_debug_message (
275 proxy, debug_dialog_new_debug_message_cb, debug_dialog,
278 /* Set Enabled as appropriate */
279 debug_dialog_set_enabled (debug_dialog, !priv->paused);
283 debug_dialog_cm_chooser_changed_cb (GtkComboBox *cm_chooser,
284 EmpathyDebugDialog *debug_dialog)
286 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
289 GError *error = NULL;
294 if (!gtk_combo_box_get_active_iter (cm_chooser, &iter))
296 DEBUG ("No CM is selected");
297 if (gtk_tree_model_iter_n_children (
298 GTK_TREE_MODEL (priv->cms), NULL) > 0)
300 gtk_combo_box_set_active (cm_chooser, 0);
305 mc = empathy_mission_control_dup_singleton ();
306 dbus = tp_dbus_daemon_dup (&error);
310 DEBUG ("Failed at duping the dbus daemon: %s", error->message);
314 gtk_tree_model_get (GTK_TREE_MODEL (priv->cms), &iter,
315 COL_CM_UNIQUE_NAME, &bus_name, -1);
316 proxy = g_object_new (TP_TYPE_PROXY,
317 "bus-name", bus_name,
319 "object-path", DEBUG_OBJECT_PATH,
323 gtk_list_store_clear (priv->store);
325 /* Disable debug signalling */
326 if (priv->proxy != NULL)
327 debug_dialog_set_enabled (debug_dialog, FALSE);
329 /* Disconnect from previous NewDebugMessage signal */
330 if (priv->new_debug_message_signal != NULL)
332 tp_proxy_signal_connection_disconnect (priv->new_debug_message_signal);
333 priv->new_debug_message_signal = NULL;
336 if (priv->proxy != NULL)
337 g_object_unref (priv->proxy);
341 tp_proxy_add_interface_by_id (priv->proxy, emp_iface_quark_debug ());
343 emp_cli_debug_call_get_messages (priv->proxy, -1,
344 debug_dialog_get_messages_cb, debug_dialog, NULL, NULL);
346 g_object_unref (dbus);
352 const gchar *unique_name;
354 } CmInModelForeachData;
357 debug_dialog_cms_foreach (GtkTreeModel *model,
362 CmInModelForeachData *data = (CmInModelForeachData *) user_data;
365 gtk_tree_model_get (model, iter,
366 COL_CM_UNIQUE_NAME, &unique_name,
369 if (!tp_strdiff (unique_name, data->unique_name))
372 g_free (unique_name);
378 debug_dialog_cm_is_in_model (EmpathyDebugDialog *debug_dialog,
379 const gchar *unique_name)
381 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
382 CmInModelForeachData *data;
385 data = g_slice_new0 (CmInModelForeachData);
386 data->unique_name = unique_name;
389 gtk_tree_model_foreach (GTK_TREE_MODEL (priv->cms),
390 debug_dialog_cms_foreach, data);
394 g_slice_free (CmInModelForeachData, data);
401 EmpathyDebugDialog *debug_dialog;
406 debug_dialog_get_name_owner_cb (TpDBusDaemon *proxy,
410 GObject *weak_object)
412 FillCmChooserData *data = (FillCmChooserData *) user_data;
413 EmpathyDebugDialogPriv *priv = GET_PRIV (data->debug_dialog);
417 DEBUG ("GetNameOwner failed: %s", error->message);
421 if (!debug_dialog_cm_is_in_model (data->debug_dialog, out))
425 DEBUG ("Adding CM to list: %s at unique name: %s",
428 gtk_list_store_append (priv->cms, &iter);
429 gtk_list_store_set (priv->cms, &iter,
430 COL_CM_NAME, data->cm_name,
431 COL_CM_UNIQUE_NAME, out,
436 g_free (data->cm_name);
437 g_slice_free (FillCmChooserData, data);
441 debug_dialog_list_connection_names_cb (const gchar * const *names,
443 const gchar * const *cms,
444 const gchar * const *protocols,
447 GObject *weak_object)
449 EmpathyDebugDialog *debug_dialog = (EmpathyDebugDialog *) user_data;
452 GError *error2 = NULL;
456 DEBUG ("list_connection_names failed: %s", error->message);
460 dbus = tp_dbus_daemon_dup (&error2);
464 DEBUG ("Failed to dup TpDBusDaemon.");
465 g_error_free (error2);
469 for (i = 0; cms[i] != NULL; i++)
471 FillCmChooserData *data;
473 data = g_slice_new0 (FillCmChooserData);
474 data->debug_dialog = debug_dialog;
475 data->cm_name = g_strdup (cms[i]);
477 tp_cli_dbus_daemon_call_get_name_owner (dbus, -1,
478 names[i], debug_dialog_get_name_owner_cb,
482 g_object_unref (dbus);
486 debug_dialog_remove_cm_foreach (GtkTreeModel *model,
491 const gchar *unique_name_to_remove = (const gchar *) user_data;
493 gboolean found = FALSE;
495 gtk_tree_model_get (model, iter, COL_CM_UNIQUE_NAME, &name, -1);
497 if (!tp_strdiff (name, unique_name_to_remove))
500 gtk_list_store_remove (GTK_LIST_STORE (model), iter);
508 #define CM_WELL_KNOWN_NAME_PREFIX \
509 "org.freedesktop.Telepathy.ConnectionManager."
512 debug_dialog_name_owner_changed_cb (TpDBusDaemon *proxy,
517 GObject *weak_object)
519 EmpathyDebugDialogPriv *priv = GET_PRIV (user_data);
521 /* Wow, I hate all of this code... */
522 if (!g_str_has_prefix (arg0, CM_WELL_KNOWN_NAME_PREFIX))
525 if (EMP_STR_EMPTY (arg1) && !EMP_STR_EMPTY (arg2))
527 /* A connection manager joined -- because it's guaranteed
528 * that the CM just joined (because o.fd.Tp.CM.foo
529 * just joined), we don't need to check whether the unique
530 * name is in the CM model. Hooray.
533 const gchar *name = arg0 + strlen (CM_WELL_KNOWN_NAME_PREFIX);
535 DEBUG ("Adding new CM '%s' at %s.", name, arg2);
537 gtk_list_store_append (priv->cms, &iter);
538 gtk_list_store_set (priv->cms, &iter,
540 COL_CM_UNIQUE_NAME, arg2,
543 else if (!EMP_STR_EMPTY (arg1) && EMP_STR_EMPTY (arg2))
545 /* A connection manager died -- because it's guaranteed
546 * that the CM itself just died (because o.fd.Tp.CM.foo
547 * just died), we don't need to check that it was already
552 /* Can't pass a const into a GtkTreeModelForeachFunc. */
553 to_remove = g_strdup (arg1);
555 DEBUG ("Removing CM from %s.", to_remove);
557 gtk_tree_model_foreach (GTK_TREE_MODEL (priv->cms),
558 debug_dialog_remove_cm_foreach, to_remove);
565 debug_dialog_fill_cm_chooser (EmpathyDebugDialog *debug_dialog)
567 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
568 GError *error = NULL;
571 priv->dbus = tp_dbus_daemon_dup (&error);
575 DEBUG ("Failed to dup dbus daemon: %s", error->message);
576 g_error_free (error);
581 gtk_list_store_append (priv->cms, &iter);
582 gtk_list_store_set (priv->cms, &iter,
583 COL_CM_NAME, "empathy",
584 COL_CM_UNIQUE_NAME, "org.gnome.Empathy",
586 gtk_combo_box_set_active (GTK_COMBO_BOX (priv->cm_chooser), 0);
588 /* Add CMs to list */
589 tp_list_connection_names (priv->dbus, debug_dialog_list_connection_names_cb,
590 debug_dialog, NULL, NULL);
592 priv->name_owner_changed_signal =
593 tp_cli_dbus_daemon_connect_to_name_owner_changed (priv->dbus,
594 debug_dialog_name_owner_changed_cb, debug_dialog, NULL, NULL, NULL);
598 debug_dialog_pause_toggled_cb (GtkToggleToolButton *pause,
599 EmpathyDebugDialog *debug_dialog)
601 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
603 priv->paused = gtk_toggle_tool_button_get_active (pause);
605 debug_dialog_set_enabled (debug_dialog, !priv->paused);
609 debug_dialog_visible_func (GtkTreeModel *model,
613 EmpathyDebugDialog *debug_dialog = (EmpathyDebugDialog *) user_data;
614 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
615 guint filter_value, level;
616 GtkTreeModel *filter_model;
617 GtkTreeIter filter_iter;
619 filter_model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->level_filter));
620 gtk_combo_box_get_active_iter (GTK_COMBO_BOX (priv->level_filter),
623 gtk_tree_model_get (model, iter, COL_DEBUG_LEVEL_VALUE, &level, -1);
624 gtk_tree_model_get (filter_model, &filter_iter,
625 COL_LEVEL_VALUE, &filter_value, -1);
627 if (level <= filter_value)
634 debug_dialog_filter_changed_cb (GtkComboBox *filter,
635 EmpathyDebugDialog *debug_dialog)
637 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
639 gtk_tree_model_filter_refilter (
640 GTK_TREE_MODEL_FILTER (priv->store_filter));
644 debug_dialog_clear_clicked_cb (GtkToolButton *clear_button,
645 EmpathyDebugDialog *debug_dialog)
647 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
649 gtk_list_store_clear (priv->store);
653 debug_dialog_menu_copy_activate_cb (GtkMenuItem *menu_item,
654 EmpathyDebugDialog *debug_dialog)
656 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
658 GtkTreeViewColumn *focus_column;
661 GtkClipboard *clipboard;
663 gtk_tree_view_get_cursor (GTK_TREE_VIEW (priv->view),
664 &path, &focus_column);
668 DEBUG ("No row is in focus");
672 gtk_tree_model_get_iter (priv->store_filter, &iter, path);
674 gtk_tree_model_get (priv->store_filter, &iter,
675 COL_DEBUG_MESSAGE, &message,
678 if (EMP_STR_EMPTY (message))
680 DEBUG ("Log message is empty");
684 clipboard = gtk_clipboard_get_for_display (
685 gtk_widget_get_display (GTK_WIDGET (menu_item)),
686 GDK_SELECTION_CLIPBOARD);
688 gtk_clipboard_set_text (clipboard, message, -1);
695 EmpathyDebugDialog *debug_dialog;
701 debug_dialog_show_menu (gpointer user_data)
703 MenuPopupData *data = (MenuPopupData *) user_data;
704 GtkWidget *menu, *item;
707 menu = gtk_menu_new ();
708 shell = GTK_MENU_SHELL (menu);
710 item = gtk_image_menu_item_new_from_stock (GTK_STOCK_COPY, NULL);
712 g_signal_connect (item, "activate",
713 G_CALLBACK (debug_dialog_menu_copy_activate_cb), data->debug_dialog);
715 gtk_menu_shell_append (shell, item);
716 gtk_widget_show (item);
718 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
719 data->button, data->time);
721 g_slice_free (MenuPopupData, user_data);
727 debug_dialog_button_press_event_cb (GtkTreeView *view,
728 GdkEventButton *event,
731 /* A mouse button was pressed on the tree view. */
733 if (event->button == 3)
735 /* The tree view was right-clicked. (3 == third mouse button) */
737 data = g_slice_new0 (MenuPopupData);
738 data->debug_dialog = user_data;
739 data->button = event->button;
740 data->time = event->time;
741 g_idle_add (debug_dialog_show_menu, data);
748 debug_dialog_store_filter_foreach (GtkTreeModel *model,
753 GFileOutputStream *output_stream = (GFileOutputStream *) user_data;
754 gchar *domain, *category, *message, *level_str, *level_upper;
757 GError *error = NULL;
758 gboolean out = FALSE;
760 gtk_tree_model_get (model, iter,
761 COL_DEBUG_TIMESTAMP, ×tamp,
762 COL_DEBUG_DOMAIN, &domain,
763 COL_DEBUG_CATEGORY, &category,
764 COL_DEBUG_LEVEL_STRING, &level_str,
765 COL_DEBUG_MESSAGE, &message,
768 level_upper = g_ascii_strup (level_str, -1);
770 line = g_strdup_printf ("%s%s%s-%s: %e: %s\n",
771 domain, EMP_STR_EMPTY (category) ? "" : "/",
772 category, level_upper, timestamp, message);
774 g_output_stream_write (G_OUTPUT_STREAM (output_stream), line,
775 strlen (line), NULL, &error);
779 DEBUG ("Failed to write to file: %s", error->message);
780 g_error_free (error);
785 g_free (level_upper);
795 debug_dialog_save_file_chooser_response_cb (GtkDialog *dialog,
797 EmpathyDebugDialog *debug_dialog)
799 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
800 gchar *filename = NULL;
802 GFileOutputStream *output_stream = NULL;
803 GError *error = NULL;
805 if (response_id != GTK_RESPONSE_ACCEPT)
808 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
810 DEBUG ("Saving log as %s", filename);
812 gfile = g_file_new_for_path (filename);
813 output_stream = g_file_replace (gfile, NULL, FALSE,
814 G_FILE_CREATE_NONE, NULL, &error);
818 DEBUG ("Failed to open file for writing: %s", error->message);
819 g_error_free (error);
823 gtk_tree_model_foreach (priv->store_filter,
824 debug_dialog_store_filter_foreach, output_stream);
828 g_object_unref (gfile);
830 if (output_stream != NULL)
831 g_object_unref (output_stream);
833 if (filename != NULL)
836 gtk_widget_destroy (GTK_WIDGET (dialog));
840 debug_dialog_save_clicked_cb (GtkToolButton *tool_button,
841 EmpathyDebugDialog *debug_dialog)
843 GtkWidget *file_chooser;
845 file_chooser = gtk_file_chooser_dialog_new (_("Save"),
846 GTK_WINDOW (debug_dialog), GTK_FILE_CHOOSER_ACTION_SAVE,
847 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
848 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
851 gtk_window_set_modal (GTK_WINDOW (file_chooser), TRUE);
852 gtk_file_chooser_set_do_overwrite_confirmation (
853 GTK_FILE_CHOOSER (file_chooser), TRUE);
855 g_signal_connect (file_chooser, "response",
856 G_CALLBACK (debug_dialog_save_file_chooser_response_cb),
859 gtk_widget_show (file_chooser);
863 debug_dialog_copy_model_foreach (GtkTreeModel *model,
868 gchar **text = (gchar **) user_data;
870 gchar *domain, *category, *message, *level_str, *level_upper;
874 gtk_tree_model_get (model, iter,
875 COL_DEBUG_TIMESTAMP, ×tamp,
876 COL_DEBUG_DOMAIN, &domain,
877 COL_DEBUG_CATEGORY, &category,
878 COL_DEBUG_LEVEL_STRING, &level_str,
879 COL_DEBUG_MESSAGE, &message,
882 level_upper = g_ascii_strup (level_str, -1);
884 line = g_strdup_printf ("%s%s%s-%s: %e: %s\n",
885 domain, EMP_STR_EMPTY (category) ? "" : "/",
886 category, level_upper, timestamp, message);
888 tmp = g_strconcat (*text, line, NULL);
892 g_free (level_upper);
904 debug_dialog_copy_clicked_cb (GtkToolButton *tool_button,
905 EmpathyDebugDialog *debug_dialog)
907 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
908 GtkClipboard *clipboard;
911 text = g_strdup ("");
913 gtk_tree_model_foreach (priv->store_filter,
914 debug_dialog_copy_model_foreach, &text);
916 clipboard = gtk_clipboard_get_for_display (
917 gtk_widget_get_display (GTK_WIDGET (tool_button)),
918 GDK_SELECTION_CLIPBOARD);
920 DEBUG ("Copying text to clipboard (length: %" G_GSIZE_FORMAT ")",
923 gtk_clipboard_set_text (clipboard, text, -1);
929 debug_dialog_constructor (GType type,
930 guint n_construct_params,
931 GObjectConstructParam *construct_params)
934 EmpathyDebugDialogPriv *priv;
940 GtkCellRenderer *renderer;
941 GtkListStore *level_store;
944 object = G_OBJECT_CLASS (empathy_debug_dialog_parent_class)->constructor
945 (type, n_construct_params, construct_params);
946 priv = GET_PRIV (object);
948 gtk_window_set_title (GTK_WINDOW (object), _("Debug Window"));
949 gtk_window_set_default_size (GTK_WINDOW (object), 800, 400);
951 vbox = GTK_DIALOG (object)->vbox;
953 toolbar = gtk_toolbar_new ();
954 gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_BOTH_HORIZ);
955 gtk_toolbar_set_show_arrow (GTK_TOOLBAR (toolbar), TRUE);
956 gtk_toolbar_set_icon_size (GTK_TOOLBAR (toolbar),
957 GTK_ICON_SIZE_SMALL_TOOLBAR);
958 gtk_widget_show (toolbar);
960 gtk_box_pack_start (GTK_BOX (vbox), toolbar, FALSE, FALSE, 0);
963 priv->cm_chooser = gtk_combo_box_new_text ();
964 priv->cms = gtk_list_store_new (NUM_COLS_CM, G_TYPE_STRING, G_TYPE_STRING);
965 gtk_combo_box_set_model (GTK_COMBO_BOX (priv->cm_chooser),
966 GTK_TREE_MODEL (priv->cms));
967 gtk_widget_show (priv->cm_chooser);
969 item = gtk_tool_item_new ();
970 gtk_widget_show (GTK_WIDGET (item));
971 gtk_container_add (GTK_CONTAINER (item), priv->cm_chooser);
972 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
973 g_signal_connect (priv->cm_chooser, "changed",
974 G_CALLBACK (debug_dialog_cm_chooser_changed_cb), object);
975 gtk_widget_show (GTK_WIDGET (priv->cm_chooser));
977 item = gtk_separator_tool_item_new ();
978 gtk_widget_show (GTK_WIDGET (item));
979 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
982 priv->save_button = gtk_tool_button_new_from_stock (GTK_STOCK_SAVE);
983 g_signal_connect (priv->save_button, "clicked",
984 G_CALLBACK (debug_dialog_save_clicked_cb), object);
985 gtk_widget_show (GTK_WIDGET (priv->save_button));
986 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (priv->save_button), TRUE);
987 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->save_button, -1);
990 priv->copy_button = gtk_tool_button_new_from_stock (GTK_STOCK_COPY);
991 g_signal_connect (priv->copy_button, "clicked",
992 G_CALLBACK (debug_dialog_copy_clicked_cb), object);
993 gtk_widget_show (GTK_WIDGET (priv->copy_button));
994 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (priv->copy_button), TRUE);
995 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->copy_button, -1);
998 priv->clear_button = gtk_tool_button_new_from_stock (GTK_STOCK_CLEAR);
999 g_signal_connect (priv->clear_button, "clicked",
1000 G_CALLBACK (debug_dialog_clear_clicked_cb), object);
1001 gtk_widget_show (GTK_WIDGET (priv->clear_button));
1002 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (priv->clear_button), TRUE);
1003 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->clear_button, -1);
1005 item = gtk_separator_tool_item_new ();
1006 gtk_widget_show (GTK_WIDGET (item));
1007 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
1010 priv->paused = FALSE;
1011 image = gtk_image_new_from_stock (GTK_STOCK_MEDIA_PAUSE,
1012 GTK_ICON_SIZE_MENU);
1013 gtk_widget_show (image);
1014 priv->pause_button = gtk_toggle_tool_button_new ();
1015 gtk_toggle_tool_button_set_active (
1016 GTK_TOGGLE_TOOL_BUTTON (priv->pause_button), priv->paused);
1017 g_signal_connect (priv->pause_button, "toggled",
1018 G_CALLBACK (debug_dialog_pause_toggled_cb), object);
1019 gtk_widget_show (GTK_WIDGET (priv->pause_button));
1020 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (priv->pause_button), TRUE);
1021 gtk_tool_button_set_label (GTK_TOOL_BUTTON (priv->pause_button), _("Pause"));
1022 gtk_tool_button_set_icon_widget (
1023 GTK_TOOL_BUTTON (priv->pause_button), image);
1024 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->pause_button, -1);
1026 item = gtk_separator_tool_item_new ();
1027 gtk_widget_show (GTK_WIDGET (item));
1028 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
1031 priv->level_label = gtk_tool_item_new ();
1032 gtk_widget_show (GTK_WIDGET (priv->level_label));
1033 label = gtk_label_new (_("Level "));
1034 gtk_widget_show (label);
1035 gtk_container_add (GTK_CONTAINER (priv->level_label), label);
1036 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->level_label, -1);
1038 priv->level_filter = gtk_combo_box_new_text ();
1039 gtk_widget_show (priv->level_filter);
1041 item = gtk_tool_item_new ();
1042 gtk_widget_show (GTK_WIDGET (item));
1043 gtk_container_add (GTK_CONTAINER (item), priv->level_filter);
1044 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
1046 level_store = gtk_list_store_new (NUM_COLS_LEVEL,
1047 G_TYPE_STRING, G_TYPE_UINT);
1048 gtk_combo_box_set_model (GTK_COMBO_BOX (priv->level_filter),
1049 GTK_TREE_MODEL (level_store));
1051 gtk_list_store_append (level_store, &iter);
1052 gtk_list_store_set (level_store, &iter,
1053 COL_LEVEL_NAME, _("Debug"),
1054 COL_LEVEL_VALUE, EMP_DEBUG_LEVEL_DEBUG,
1057 gtk_list_store_append (level_store, &iter);
1058 gtk_list_store_set (level_store, &iter,
1059 COL_LEVEL_NAME, _("Info"),
1060 COL_LEVEL_VALUE, EMP_DEBUG_LEVEL_INFO,
1063 gtk_list_store_append (level_store, &iter);
1064 gtk_list_store_set (level_store, &iter,
1065 COL_LEVEL_NAME, _("Message"),
1066 COL_LEVEL_VALUE, EMP_DEBUG_LEVEL_MESSAGE,
1069 gtk_list_store_append (level_store, &iter);
1070 gtk_list_store_set (level_store, &iter,
1071 COL_LEVEL_NAME, _("Warning"),
1072 COL_LEVEL_VALUE, EMP_DEBUG_LEVEL_WARNING,
1075 gtk_list_store_append (level_store, &iter);
1076 gtk_list_store_set (level_store, &iter,
1077 COL_LEVEL_NAME, _("Critical"),
1078 COL_LEVEL_VALUE, EMP_DEBUG_LEVEL_CRITICAL,
1081 gtk_list_store_append (level_store, &iter);
1082 gtk_list_store_set (level_store, &iter,
1083 COL_LEVEL_NAME, _("Error"),
1084 COL_LEVEL_VALUE, EMP_DEBUG_LEVEL_ERROR,
1087 gtk_combo_box_set_active (GTK_COMBO_BOX (priv->level_filter), 0);
1088 g_signal_connect (priv->level_filter, "changed",
1089 G_CALLBACK (debug_dialog_filter_changed_cb), object);
1091 /* Debug treeview */
1092 priv->view = gtk_tree_view_new ();
1093 gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (priv->view), TRUE);
1095 g_signal_connect (priv->view, "button-press-event",
1096 G_CALLBACK (debug_dialog_button_press_event_cb), object);
1098 renderer = gtk_cell_renderer_text_new ();
1099 g_object_set (renderer, "yalign", 0, NULL);
1101 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
1102 -1, _("Time"), renderer, "text", COL_DEBUG_TIMESTAMP, NULL);
1103 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
1104 -1, _("Domain"), renderer, "text", COL_DEBUG_DOMAIN, NULL);
1105 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
1106 -1, _("Category"), renderer, "text", COL_DEBUG_CATEGORY, NULL);
1107 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
1108 -1, _("Level"), renderer, "text", COL_DEBUG_LEVEL_STRING, NULL);
1110 renderer = gtk_cell_renderer_text_new ();
1111 g_object_set (renderer, "family", "Monospace", NULL);
1112 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
1113 -1, _("Message"), renderer, "text", COL_DEBUG_MESSAGE, NULL);
1115 priv->store = gtk_list_store_new (NUM_DEBUG_COLS, G_TYPE_DOUBLE,
1116 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
1119 priv->store_filter = gtk_tree_model_filter_new (
1120 GTK_TREE_MODEL (priv->store), NULL);
1122 gtk_tree_model_filter_set_visible_func (
1123 GTK_TREE_MODEL_FILTER (priv->store_filter),
1124 debug_dialog_visible_func, object, NULL);
1126 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->view), priv->store_filter);
1128 /* Scrolled window */
1129 priv->scrolled_win = g_object_ref (gtk_scrolled_window_new (NULL, NULL));
1130 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_win),
1131 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1133 gtk_widget_show (priv->view);
1134 gtk_container_add (GTK_CONTAINER (priv->scrolled_win), priv->view);
1136 gtk_widget_show (priv->scrolled_win);
1138 /* Not supported label */
1139 priv->not_supported_label = g_object_ref (gtk_label_new (
1140 _("The selected connection manager does not support the remote "
1141 "debugging extension.")));
1142 gtk_widget_show (priv->not_supported_label);
1143 gtk_box_pack_start (GTK_BOX (vbox), priv->not_supported_label, TRUE, TRUE, 0);
1145 priv->view_visible = FALSE;
1147 debug_dialog_set_toolbar_sensitivity (EMPATHY_DEBUG_DIALOG (object), FALSE);
1148 debug_dialog_fill_cm_chooser (EMPATHY_DEBUG_DIALOG (object));
1149 gtk_widget_show (GTK_WIDGET (object));
1155 empathy_debug_dialog_init (EmpathyDebugDialog *empathy_debug_dialog)
1157 EmpathyDebugDialogPriv *priv =
1158 G_TYPE_INSTANCE_GET_PRIVATE (empathy_debug_dialog,
1159 EMPATHY_TYPE_DEBUG_DIALOG, EmpathyDebugDialogPriv);
1161 empathy_debug_dialog->priv = priv;
1163 priv->dispose_run = FALSE;
1167 debug_dialog_set_property (GObject *object,
1169 const GValue *value,
1175 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1181 debug_dialog_get_property (GObject *object,
1189 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1195 debug_dialog_dispose (GObject *object)
1197 EmpathyDebugDialog *selector = EMPATHY_DEBUG_DIALOG (object);
1198 EmpathyDebugDialogPriv *priv = GET_PRIV (selector);
1200 if (priv->dispose_run)
1203 priv->dispose_run = TRUE;
1205 if (priv->store != NULL)
1206 g_object_unref (priv->store);
1208 if (priv->name_owner_changed_signal != NULL)
1209 tp_proxy_signal_connection_disconnect (priv->name_owner_changed_signal);
1211 if (priv->proxy != NULL)
1213 debug_dialog_set_enabled (EMPATHY_DEBUG_DIALOG (object), FALSE);
1214 g_object_unref (priv->proxy);
1217 if (priv->new_debug_message_signal != NULL)
1218 tp_proxy_signal_connection_disconnect (priv->new_debug_message_signal);
1220 if (priv->cms != NULL)
1221 g_object_unref (priv->cms);
1223 if (priv->dbus != NULL)
1224 g_object_unref (priv->dbus);
1226 (G_OBJECT_CLASS (empathy_debug_dialog_parent_class)->dispose) (object);
1230 empathy_debug_dialog_class_init (EmpathyDebugDialogClass *klass)
1232 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1233 object_class->constructor = debug_dialog_constructor;
1234 object_class->dispose = debug_dialog_dispose;
1235 object_class->set_property = debug_dialog_set_property;
1236 object_class->get_property = debug_dialog_get_property;
1237 g_type_class_add_private (klass, sizeof (EmpathyDebugDialogPriv));
1240 /* public methods */
1243 empathy_debug_dialog_new (GtkWindow *parent)
1245 g_return_val_if_fail (GTK_IS_WINDOW (parent), NULL);
1247 return GTK_WIDGET (g_object_new (EMPATHY_TYPE_DEBUG_DIALOG,
1248 "transient-for", parent, NULL));