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_get_content_area (GTK_DIALOG (debug_dialog));
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);
288 GError *error = NULL;
293 if (!gtk_combo_box_get_active_iter (cm_chooser, &iter))
295 DEBUG ("No CM is selected");
296 if (gtk_tree_model_iter_n_children (
297 GTK_TREE_MODEL (priv->cms), NULL) > 0)
299 gtk_combo_box_set_active (cm_chooser, 0);
304 dbus = tp_dbus_daemon_dup (&error);
308 DEBUG ("Failed at duping the dbus daemon: %s", error->message);
311 gtk_tree_model_get (GTK_TREE_MODEL (priv->cms), &iter,
312 COL_CM_UNIQUE_NAME, &bus_name, -1);
313 proxy = g_object_new (TP_TYPE_PROXY,
314 "bus-name", bus_name,
316 "object-path", DEBUG_OBJECT_PATH,
320 gtk_list_store_clear (priv->store);
322 /* Disable debug signalling */
323 if (priv->proxy != NULL)
324 debug_dialog_set_enabled (debug_dialog, FALSE);
326 /* Disconnect from previous NewDebugMessage signal */
327 if (priv->new_debug_message_signal != NULL)
329 tp_proxy_signal_connection_disconnect (priv->new_debug_message_signal);
330 priv->new_debug_message_signal = NULL;
333 if (priv->proxy != NULL)
334 g_object_unref (priv->proxy);
338 tp_proxy_add_interface_by_id (priv->proxy, emp_iface_quark_debug ());
340 emp_cli_debug_call_get_messages (priv->proxy, -1,
341 debug_dialog_get_messages_cb, debug_dialog, NULL, NULL);
343 g_object_unref (dbus);
348 const gchar *unique_name;
350 } CmInModelForeachData;
353 debug_dialog_cms_foreach (GtkTreeModel *model,
358 CmInModelForeachData *data = (CmInModelForeachData *) user_data;
361 gtk_tree_model_get (model, iter,
362 COL_CM_UNIQUE_NAME, &unique_name,
365 if (!tp_strdiff (unique_name, data->unique_name))
368 g_free (unique_name);
374 debug_dialog_cm_is_in_model (EmpathyDebugDialog *debug_dialog,
375 const gchar *unique_name)
377 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
378 CmInModelForeachData *data;
381 data = g_slice_new0 (CmInModelForeachData);
382 data->unique_name = unique_name;
385 gtk_tree_model_foreach (GTK_TREE_MODEL (priv->cms),
386 debug_dialog_cms_foreach, data);
390 g_slice_free (CmInModelForeachData, data);
397 EmpathyDebugDialog *debug_dialog;
402 debug_dialog_get_name_owner_cb (TpDBusDaemon *proxy,
406 GObject *weak_object)
408 FillCmChooserData *data = (FillCmChooserData *) user_data;
409 EmpathyDebugDialogPriv *priv = GET_PRIV (data->debug_dialog);
413 DEBUG ("GetNameOwner failed: %s", error->message);
417 if (!debug_dialog_cm_is_in_model (data->debug_dialog, out))
421 DEBUG ("Adding CM to list: %s at unique name: %s",
424 gtk_list_store_append (priv->cms, &iter);
425 gtk_list_store_set (priv->cms, &iter,
426 COL_CM_NAME, data->cm_name,
427 COL_CM_UNIQUE_NAME, out,
432 g_free (data->cm_name);
433 g_slice_free (FillCmChooserData, data);
437 debug_dialog_list_connection_names_cb (const gchar * const *names,
439 const gchar * const *cms,
440 const gchar * const *protocols,
443 GObject *weak_object)
445 EmpathyDebugDialog *debug_dialog = (EmpathyDebugDialog *) user_data;
448 GError *error2 = NULL;
452 DEBUG ("list_connection_names failed: %s", error->message);
456 dbus = tp_dbus_daemon_dup (&error2);
460 DEBUG ("Failed to dup TpDBusDaemon.");
461 g_error_free (error2);
465 for (i = 0; cms[i] != NULL; i++)
467 FillCmChooserData *data;
469 data = g_slice_new0 (FillCmChooserData);
470 data->debug_dialog = debug_dialog;
471 data->cm_name = g_strdup (cms[i]);
473 tp_cli_dbus_daemon_call_get_name_owner (dbus, -1,
474 names[i], debug_dialog_get_name_owner_cb,
478 g_object_unref (dbus);
482 debug_dialog_remove_cm_foreach (GtkTreeModel *model,
487 const gchar *unique_name_to_remove = (const gchar *) user_data;
489 gboolean found = FALSE;
491 gtk_tree_model_get (model, iter, COL_CM_UNIQUE_NAME, &name, -1);
493 if (!tp_strdiff (name, unique_name_to_remove))
496 gtk_list_store_remove (GTK_LIST_STORE (model), iter);
504 #define CM_WELL_KNOWN_NAME_PREFIX \
505 "org.freedesktop.Telepathy.ConnectionManager."
508 debug_dialog_name_owner_changed_cb (TpDBusDaemon *proxy,
513 GObject *weak_object)
515 EmpathyDebugDialogPriv *priv = GET_PRIV (user_data);
517 /* Wow, I hate all of this code... */
518 if (!g_str_has_prefix (arg0, CM_WELL_KNOWN_NAME_PREFIX))
521 if (EMP_STR_EMPTY (arg1) && !EMP_STR_EMPTY (arg2))
523 /* A connection manager joined -- because it's guaranteed
524 * that the CM just joined (because o.fd.Tp.CM.foo
525 * just joined), we don't need to check whether the unique
526 * name is in the CM model. Hooray.
529 const gchar *name = arg0 + strlen (CM_WELL_KNOWN_NAME_PREFIX);
531 DEBUG ("Adding new CM '%s' at %s.", name, arg2);
533 gtk_list_store_append (priv->cms, &iter);
534 gtk_list_store_set (priv->cms, &iter,
536 COL_CM_UNIQUE_NAME, arg2,
539 else if (!EMP_STR_EMPTY (arg1) && EMP_STR_EMPTY (arg2))
541 /* A connection manager died -- because it's guaranteed
542 * that the CM itself just died (because o.fd.Tp.CM.foo
543 * just died), we don't need to check that it was already
548 /* Can't pass a const into a GtkTreeModelForeachFunc. */
549 to_remove = g_strdup (arg1);
551 DEBUG ("Removing CM from %s.", to_remove);
553 gtk_tree_model_foreach (GTK_TREE_MODEL (priv->cms),
554 debug_dialog_remove_cm_foreach, to_remove);
561 debug_dialog_fill_cm_chooser (EmpathyDebugDialog *debug_dialog)
563 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
564 GError *error = NULL;
567 priv->dbus = tp_dbus_daemon_dup (&error);
571 DEBUG ("Failed to dup dbus daemon: %s", error->message);
572 g_error_free (error);
577 gtk_list_store_append (priv->cms, &iter);
578 gtk_list_store_set (priv->cms, &iter,
579 COL_CM_NAME, "empathy",
580 COL_CM_UNIQUE_NAME, "org.gnome.Empathy",
582 gtk_combo_box_set_active (GTK_COMBO_BOX (priv->cm_chooser), 0);
584 /* Add CMs to list */
585 tp_list_connection_names (priv->dbus, debug_dialog_list_connection_names_cb,
586 debug_dialog, NULL, NULL);
588 priv->name_owner_changed_signal =
589 tp_cli_dbus_daemon_connect_to_name_owner_changed (priv->dbus,
590 debug_dialog_name_owner_changed_cb, debug_dialog, NULL, NULL, NULL);
594 debug_dialog_pause_toggled_cb (GtkToggleToolButton *pause,
595 EmpathyDebugDialog *debug_dialog)
597 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
599 priv->paused = gtk_toggle_tool_button_get_active (pause);
601 debug_dialog_set_enabled (debug_dialog, !priv->paused);
605 debug_dialog_visible_func (GtkTreeModel *model,
609 EmpathyDebugDialog *debug_dialog = (EmpathyDebugDialog *) user_data;
610 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
611 guint filter_value, level;
612 GtkTreeModel *filter_model;
613 GtkTreeIter filter_iter;
615 filter_model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->level_filter));
616 gtk_combo_box_get_active_iter (GTK_COMBO_BOX (priv->level_filter),
619 gtk_tree_model_get (model, iter, COL_DEBUG_LEVEL_VALUE, &level, -1);
620 gtk_tree_model_get (filter_model, &filter_iter,
621 COL_LEVEL_VALUE, &filter_value, -1);
623 if (level <= filter_value)
630 debug_dialog_filter_changed_cb (GtkComboBox *filter,
631 EmpathyDebugDialog *debug_dialog)
633 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
635 gtk_tree_model_filter_refilter (
636 GTK_TREE_MODEL_FILTER (priv->store_filter));
640 debug_dialog_clear_clicked_cb (GtkToolButton *clear_button,
641 EmpathyDebugDialog *debug_dialog)
643 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
645 gtk_list_store_clear (priv->store);
649 debug_dialog_menu_copy_activate_cb (GtkMenuItem *menu_item,
650 EmpathyDebugDialog *debug_dialog)
652 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
654 GtkTreeViewColumn *focus_column;
657 GtkClipboard *clipboard;
659 gtk_tree_view_get_cursor (GTK_TREE_VIEW (priv->view),
660 &path, &focus_column);
664 DEBUG ("No row is in focus");
668 gtk_tree_model_get_iter (priv->store_filter, &iter, path);
670 gtk_tree_model_get (priv->store_filter, &iter,
671 COL_DEBUG_MESSAGE, &message,
674 if (EMP_STR_EMPTY (message))
676 DEBUG ("Log message is empty");
680 clipboard = gtk_clipboard_get_for_display (
681 gtk_widget_get_display (GTK_WIDGET (menu_item)),
682 GDK_SELECTION_CLIPBOARD);
684 gtk_clipboard_set_text (clipboard, message, -1);
691 EmpathyDebugDialog *debug_dialog;
697 debug_dialog_show_menu (gpointer user_data)
699 MenuPopupData *data = (MenuPopupData *) user_data;
700 GtkWidget *menu, *item;
703 menu = gtk_menu_new ();
704 shell = GTK_MENU_SHELL (menu);
706 item = gtk_image_menu_item_new_from_stock (GTK_STOCK_COPY, NULL);
708 g_signal_connect (item, "activate",
709 G_CALLBACK (debug_dialog_menu_copy_activate_cb), data->debug_dialog);
711 gtk_menu_shell_append (shell, item);
712 gtk_widget_show (item);
714 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
715 data->button, data->time);
717 g_slice_free (MenuPopupData, user_data);
723 debug_dialog_button_press_event_cb (GtkTreeView *view,
724 GdkEventButton *event,
727 /* A mouse button was pressed on the tree view. */
729 if (event->button == 3)
731 /* The tree view was right-clicked. (3 == third mouse button) */
733 data = g_slice_new0 (MenuPopupData);
734 data->debug_dialog = user_data;
735 data->button = event->button;
736 data->time = event->time;
737 g_idle_add (debug_dialog_show_menu, data);
744 debug_dialog_store_filter_foreach (GtkTreeModel *model,
749 GFileOutputStream *output_stream = (GFileOutputStream *) user_data;
750 gchar *domain, *category, *message, *level_str, *level_upper;
753 GError *error = NULL;
754 gboolean out = FALSE;
756 gtk_tree_model_get (model, iter,
757 COL_DEBUG_TIMESTAMP, ×tamp,
758 COL_DEBUG_DOMAIN, &domain,
759 COL_DEBUG_CATEGORY, &category,
760 COL_DEBUG_LEVEL_STRING, &level_str,
761 COL_DEBUG_MESSAGE, &message,
764 level_upper = g_ascii_strup (level_str, -1);
766 line = g_strdup_printf ("%s%s%s-%s: %e: %s\n",
767 domain, EMP_STR_EMPTY (category) ? "" : "/",
768 category, level_upper, timestamp, message);
770 g_output_stream_write (G_OUTPUT_STREAM (output_stream), line,
771 strlen (line), NULL, &error);
775 DEBUG ("Failed to write to file: %s", error->message);
776 g_error_free (error);
781 g_free (level_upper);
791 debug_dialog_save_file_chooser_response_cb (GtkDialog *dialog,
793 EmpathyDebugDialog *debug_dialog)
795 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
796 gchar *filename = NULL;
798 GFileOutputStream *output_stream = NULL;
799 GError *error = NULL;
801 if (response_id != GTK_RESPONSE_ACCEPT)
804 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
806 DEBUG ("Saving log as %s", filename);
808 gfile = g_file_new_for_path (filename);
809 output_stream = g_file_replace (gfile, NULL, FALSE,
810 G_FILE_CREATE_NONE, NULL, &error);
814 DEBUG ("Failed to open file for writing: %s", error->message);
815 g_error_free (error);
819 gtk_tree_model_foreach (priv->store_filter,
820 debug_dialog_store_filter_foreach, output_stream);
824 g_object_unref (gfile);
826 if (output_stream != NULL)
827 g_object_unref (output_stream);
829 if (filename != NULL)
832 gtk_widget_destroy (GTK_WIDGET (dialog));
836 debug_dialog_save_clicked_cb (GtkToolButton *tool_button,
837 EmpathyDebugDialog *debug_dialog)
839 GtkWidget *file_chooser;
841 file_chooser = gtk_file_chooser_dialog_new (_("Save"),
842 GTK_WINDOW (debug_dialog), GTK_FILE_CHOOSER_ACTION_SAVE,
843 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
844 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
847 gtk_window_set_modal (GTK_WINDOW (file_chooser), TRUE);
848 gtk_file_chooser_set_do_overwrite_confirmation (
849 GTK_FILE_CHOOSER (file_chooser), TRUE);
851 g_signal_connect (file_chooser, "response",
852 G_CALLBACK (debug_dialog_save_file_chooser_response_cb),
855 gtk_widget_show (file_chooser);
859 debug_dialog_copy_model_foreach (GtkTreeModel *model,
864 gchar **text = (gchar **) user_data;
866 gchar *domain, *category, *message, *level_str, *level_upper;
870 gtk_tree_model_get (model, iter,
871 COL_DEBUG_TIMESTAMP, ×tamp,
872 COL_DEBUG_DOMAIN, &domain,
873 COL_DEBUG_CATEGORY, &category,
874 COL_DEBUG_LEVEL_STRING, &level_str,
875 COL_DEBUG_MESSAGE, &message,
878 level_upper = g_ascii_strup (level_str, -1);
880 line = g_strdup_printf ("%s%s%s-%s: %e: %s\n",
881 domain, EMP_STR_EMPTY (category) ? "" : "/",
882 category, level_upper, timestamp, message);
884 tmp = g_strconcat (*text, line, NULL);
888 g_free (level_upper);
900 debug_dialog_copy_clicked_cb (GtkToolButton *tool_button,
901 EmpathyDebugDialog *debug_dialog)
903 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
904 GtkClipboard *clipboard;
907 text = g_strdup ("");
909 gtk_tree_model_foreach (priv->store_filter,
910 debug_dialog_copy_model_foreach, &text);
912 clipboard = gtk_clipboard_get_for_display (
913 gtk_widget_get_display (GTK_WIDGET (tool_button)),
914 GDK_SELECTION_CLIPBOARD);
916 DEBUG ("Copying text to clipboard (length: %" G_GSIZE_FORMAT ")",
919 gtk_clipboard_set_text (clipboard, text, -1);
925 debug_dialog_constructor (GType type,
926 guint n_construct_params,
927 GObjectConstructParam *construct_params)
930 EmpathyDebugDialogPriv *priv;
936 GtkCellRenderer *renderer;
937 GtkListStore *level_store;
940 object = G_OBJECT_CLASS (empathy_debug_dialog_parent_class)->constructor
941 (type, n_construct_params, construct_params);
942 priv = GET_PRIV (object);
944 gtk_window_set_title (GTK_WINDOW (object), _("Debug Window"));
945 gtk_window_set_default_size (GTK_WINDOW (object), 800, 400);
947 vbox = gtk_dialog_get_content_area (GTK_DIALOG (object));
949 toolbar = gtk_toolbar_new ();
950 gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_BOTH_HORIZ);
951 gtk_toolbar_set_show_arrow (GTK_TOOLBAR (toolbar), TRUE);
952 gtk_toolbar_set_icon_size (GTK_TOOLBAR (toolbar),
953 GTK_ICON_SIZE_SMALL_TOOLBAR);
954 gtk_widget_show (toolbar);
956 gtk_box_pack_start (GTK_BOX (vbox), toolbar, FALSE, FALSE, 0);
959 priv->cm_chooser = gtk_combo_box_new_text ();
960 priv->cms = gtk_list_store_new (NUM_COLS_CM, G_TYPE_STRING, G_TYPE_STRING);
961 gtk_combo_box_set_model (GTK_COMBO_BOX (priv->cm_chooser),
962 GTK_TREE_MODEL (priv->cms));
963 gtk_widget_show (priv->cm_chooser);
965 item = gtk_tool_item_new ();
966 gtk_widget_show (GTK_WIDGET (item));
967 gtk_container_add (GTK_CONTAINER (item), priv->cm_chooser);
968 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
969 g_signal_connect (priv->cm_chooser, "changed",
970 G_CALLBACK (debug_dialog_cm_chooser_changed_cb), object);
971 gtk_widget_show (GTK_WIDGET (priv->cm_chooser));
973 item = gtk_separator_tool_item_new ();
974 gtk_widget_show (GTK_WIDGET (item));
975 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
978 priv->save_button = gtk_tool_button_new_from_stock (GTK_STOCK_SAVE);
979 g_signal_connect (priv->save_button, "clicked",
980 G_CALLBACK (debug_dialog_save_clicked_cb), object);
981 gtk_widget_show (GTK_WIDGET (priv->save_button));
982 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (priv->save_button), TRUE);
983 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->save_button, -1);
986 priv->copy_button = gtk_tool_button_new_from_stock (GTK_STOCK_COPY);
987 g_signal_connect (priv->copy_button, "clicked",
988 G_CALLBACK (debug_dialog_copy_clicked_cb), object);
989 gtk_widget_show (GTK_WIDGET (priv->copy_button));
990 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (priv->copy_button), TRUE);
991 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->copy_button, -1);
994 priv->clear_button = gtk_tool_button_new_from_stock (GTK_STOCK_CLEAR);
995 g_signal_connect (priv->clear_button, "clicked",
996 G_CALLBACK (debug_dialog_clear_clicked_cb), object);
997 gtk_widget_show (GTK_WIDGET (priv->clear_button));
998 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (priv->clear_button), TRUE);
999 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->clear_button, -1);
1001 item = gtk_separator_tool_item_new ();
1002 gtk_widget_show (GTK_WIDGET (item));
1003 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
1006 priv->paused = FALSE;
1007 image = gtk_image_new_from_stock (GTK_STOCK_MEDIA_PAUSE,
1008 GTK_ICON_SIZE_MENU);
1009 gtk_widget_show (image);
1010 priv->pause_button = gtk_toggle_tool_button_new ();
1011 gtk_toggle_tool_button_set_active (
1012 GTK_TOGGLE_TOOL_BUTTON (priv->pause_button), priv->paused);
1013 g_signal_connect (priv->pause_button, "toggled",
1014 G_CALLBACK (debug_dialog_pause_toggled_cb), object);
1015 gtk_widget_show (GTK_WIDGET (priv->pause_button));
1016 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (priv->pause_button), TRUE);
1017 gtk_tool_button_set_label (GTK_TOOL_BUTTON (priv->pause_button), _("Pause"));
1018 gtk_tool_button_set_icon_widget (
1019 GTK_TOOL_BUTTON (priv->pause_button), image);
1020 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->pause_button, -1);
1022 item = gtk_separator_tool_item_new ();
1023 gtk_widget_show (GTK_WIDGET (item));
1024 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
1027 priv->level_label = gtk_tool_item_new ();
1028 gtk_widget_show (GTK_WIDGET (priv->level_label));
1029 label = gtk_label_new (_("Level "));
1030 gtk_widget_show (label);
1031 gtk_container_add (GTK_CONTAINER (priv->level_label), label);
1032 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->level_label, -1);
1034 priv->level_filter = gtk_combo_box_new_text ();
1035 gtk_widget_show (priv->level_filter);
1037 item = gtk_tool_item_new ();
1038 gtk_widget_show (GTK_WIDGET (item));
1039 gtk_container_add (GTK_CONTAINER (item), priv->level_filter);
1040 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
1042 level_store = gtk_list_store_new (NUM_COLS_LEVEL,
1043 G_TYPE_STRING, G_TYPE_UINT);
1044 gtk_combo_box_set_model (GTK_COMBO_BOX (priv->level_filter),
1045 GTK_TREE_MODEL (level_store));
1047 gtk_list_store_append (level_store, &iter);
1048 gtk_list_store_set (level_store, &iter,
1049 COL_LEVEL_NAME, _("Debug"),
1050 COL_LEVEL_VALUE, EMP_DEBUG_LEVEL_DEBUG,
1053 gtk_list_store_append (level_store, &iter);
1054 gtk_list_store_set (level_store, &iter,
1055 COL_LEVEL_NAME, _("Info"),
1056 COL_LEVEL_VALUE, EMP_DEBUG_LEVEL_INFO,
1059 gtk_list_store_append (level_store, &iter);
1060 gtk_list_store_set (level_store, &iter,
1061 COL_LEVEL_NAME, _("Message"),
1062 COL_LEVEL_VALUE, EMP_DEBUG_LEVEL_MESSAGE,
1065 gtk_list_store_append (level_store, &iter);
1066 gtk_list_store_set (level_store, &iter,
1067 COL_LEVEL_NAME, _("Warning"),
1068 COL_LEVEL_VALUE, EMP_DEBUG_LEVEL_WARNING,
1071 gtk_list_store_append (level_store, &iter);
1072 gtk_list_store_set (level_store, &iter,
1073 COL_LEVEL_NAME, _("Critical"),
1074 COL_LEVEL_VALUE, EMP_DEBUG_LEVEL_CRITICAL,
1077 gtk_list_store_append (level_store, &iter);
1078 gtk_list_store_set (level_store, &iter,
1079 COL_LEVEL_NAME, _("Error"),
1080 COL_LEVEL_VALUE, EMP_DEBUG_LEVEL_ERROR,
1083 gtk_combo_box_set_active (GTK_COMBO_BOX (priv->level_filter), 0);
1084 g_signal_connect (priv->level_filter, "changed",
1085 G_CALLBACK (debug_dialog_filter_changed_cb), object);
1087 /* Debug treeview */
1088 priv->view = gtk_tree_view_new ();
1089 gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (priv->view), TRUE);
1091 g_signal_connect (priv->view, "button-press-event",
1092 G_CALLBACK (debug_dialog_button_press_event_cb), object);
1094 renderer = gtk_cell_renderer_text_new ();
1095 g_object_set (renderer, "yalign", 0, NULL);
1097 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
1098 -1, _("Time"), renderer, "text", COL_DEBUG_TIMESTAMP, NULL);
1099 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
1100 -1, _("Domain"), renderer, "text", COL_DEBUG_DOMAIN, NULL);
1101 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
1102 -1, _("Category"), renderer, "text", COL_DEBUG_CATEGORY, NULL);
1103 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
1104 -1, _("Level"), renderer, "text", COL_DEBUG_LEVEL_STRING, NULL);
1106 renderer = gtk_cell_renderer_text_new ();
1107 g_object_set (renderer, "family", "Monospace", NULL);
1108 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
1109 -1, _("Message"), renderer, "text", COL_DEBUG_MESSAGE, NULL);
1111 priv->store = gtk_list_store_new (NUM_DEBUG_COLS, G_TYPE_DOUBLE,
1112 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
1115 priv->store_filter = gtk_tree_model_filter_new (
1116 GTK_TREE_MODEL (priv->store), NULL);
1118 gtk_tree_model_filter_set_visible_func (
1119 GTK_TREE_MODEL_FILTER (priv->store_filter),
1120 debug_dialog_visible_func, object, NULL);
1122 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->view), priv->store_filter);
1124 /* Scrolled window */
1125 priv->scrolled_win = g_object_ref (gtk_scrolled_window_new (NULL, NULL));
1126 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_win),
1127 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1129 gtk_widget_show (priv->view);
1130 gtk_container_add (GTK_CONTAINER (priv->scrolled_win), priv->view);
1132 gtk_widget_show (priv->scrolled_win);
1134 /* Not supported label */
1135 priv->not_supported_label = g_object_ref (gtk_label_new (
1136 _("The selected connection manager does not support the remote "
1137 "debugging extension.")));
1138 gtk_widget_show (priv->not_supported_label);
1139 gtk_box_pack_start (GTK_BOX (vbox), priv->not_supported_label, TRUE, TRUE, 0);
1141 priv->view_visible = FALSE;
1143 debug_dialog_set_toolbar_sensitivity (EMPATHY_DEBUG_DIALOG (object), FALSE);
1144 debug_dialog_fill_cm_chooser (EMPATHY_DEBUG_DIALOG (object));
1145 gtk_widget_show (GTK_WIDGET (object));
1151 empathy_debug_dialog_init (EmpathyDebugDialog *empathy_debug_dialog)
1153 EmpathyDebugDialogPriv *priv =
1154 G_TYPE_INSTANCE_GET_PRIVATE (empathy_debug_dialog,
1155 EMPATHY_TYPE_DEBUG_DIALOG, EmpathyDebugDialogPriv);
1157 empathy_debug_dialog->priv = priv;
1159 priv->dispose_run = FALSE;
1163 debug_dialog_set_property (GObject *object,
1165 const GValue *value,
1171 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1177 debug_dialog_get_property (GObject *object,
1185 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1191 debug_dialog_dispose (GObject *object)
1193 EmpathyDebugDialog *selector = EMPATHY_DEBUG_DIALOG (object);
1194 EmpathyDebugDialogPriv *priv = GET_PRIV (selector);
1196 if (priv->dispose_run)
1199 priv->dispose_run = TRUE;
1201 if (priv->store != NULL)
1202 g_object_unref (priv->store);
1204 if (priv->name_owner_changed_signal != NULL)
1205 tp_proxy_signal_connection_disconnect (priv->name_owner_changed_signal);
1207 if (priv->proxy != NULL)
1209 debug_dialog_set_enabled (EMPATHY_DEBUG_DIALOG (object), FALSE);
1210 g_object_unref (priv->proxy);
1213 if (priv->new_debug_message_signal != NULL)
1214 tp_proxy_signal_connection_disconnect (priv->new_debug_message_signal);
1216 if (priv->cms != NULL)
1217 g_object_unref (priv->cms);
1219 if (priv->dbus != NULL)
1220 g_object_unref (priv->dbus);
1222 (G_OBJECT_CLASS (empathy_debug_dialog_parent_class)->dispose) (object);
1226 empathy_debug_dialog_class_init (EmpathyDebugDialogClass *klass)
1228 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1229 object_class->constructor = debug_dialog_constructor;
1230 object_class->dispose = debug_dialog_dispose;
1231 object_class->set_property = debug_dialog_set_property;
1232 object_class->get_property = debug_dialog_get_property;
1233 g_type_class_add_private (klass, sizeof (EmpathyDebugDialogPriv));
1236 /* public methods */
1239 empathy_debug_dialog_new (GtkWindow *parent)
1241 g_return_val_if_fail (GTK_IS_WINDOW (parent), NULL);
1243 return GTK_WIDGET (g_object_new (EMPATHY_TYPE_DEBUG_DIALOG,
1244 "transient-for", parent, NULL));