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;
78 GtkTreeModel *store_filter;
83 TpProxySignalConnection *new_debug_message_signal;
84 TpProxySignalConnection *name_owner_changed_signal;
86 /* Whether NewDebugMessage will be fired */
89 /* CM chooser store */
94 } EmpathyDebugDialogPriv;
97 log_level_to_string (guint level)
101 case EMP_DEBUG_LEVEL_ERROR:
104 case EMP_DEBUG_LEVEL_CRITICAL:
105 return _("Critical");
107 case EMP_DEBUG_LEVEL_WARNING:
110 case EMP_DEBUG_LEVEL_MESSAGE:
113 case EMP_DEBUG_LEVEL_INFO:
116 case EMP_DEBUG_LEVEL_DEBUG:
120 g_assert_not_reached ();
126 debug_dialog_add_message (EmpathyDebugDialog *debug_dialog,
128 const gchar *domain_category,
130 const gchar *message)
132 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
133 gchar *domain, *category;
137 if (g_strrstr (domain_category, "/"))
139 gchar **parts = g_strsplit (domain_category, "/", 2);
140 domain = g_strdup (parts[0]);
141 category = g_strdup (parts[1]);
146 domain = g_strdup (domain_category);
147 category = g_strdup ("");
150 if (g_str_has_suffix (message, "\n"))
151 string = g_strchomp (g_strdup (message));
153 string = g_strdup (message);
156 gtk_list_store_append (priv->store, &iter);
157 gtk_list_store_set (priv->store, &iter,
158 COL_DEBUG_TIMESTAMP, timestamp,
159 COL_DEBUG_DOMAIN, domain,
160 COL_DEBUG_CATEGORY, category,
161 COL_DEBUG_LEVEL_STRING, log_level_to_string (level),
162 COL_DEBUG_MESSAGE, string,
163 COL_DEBUG_LEVEL_VALUE, level,
172 debug_dialog_new_debug_message_cb (TpProxy *proxy,
176 const gchar *message,
178 GObject *weak_object)
180 EmpathyDebugDialog *debug_dialog = (EmpathyDebugDialog *) user_data;
182 debug_dialog_add_message (debug_dialog, timestamp, domain, level,
187 debug_dialog_set_enabled (EmpathyDebugDialog *debug_dialog,
190 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
193 val = tp_g_value_slice_new_boolean (enabled);
195 tp_cli_dbus_properties_call_set (priv->proxy, -1, EMP_IFACE_DEBUG,
196 "Enabled", val, NULL, NULL, NULL, NULL);
198 tp_g_value_slice_free (val);
202 debug_dialog_get_messages_cb (TpProxy *proxy,
203 const GPtrArray *messages,
206 GObject *weak_object)
208 EmpathyDebugDialog *debug_dialog = (EmpathyDebugDialog *) user_data;
209 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
214 DEBUG ("GetMessages failed: %s", error->message);
218 for (i = 0; i < messages->len; i++)
220 GValueArray *values = g_ptr_array_index (messages, i);
222 debug_dialog_add_message (debug_dialog,
223 g_value_get_double (g_value_array_get_nth (values, 0)),
224 g_value_get_string (g_value_array_get_nth (values, 1)),
225 g_value_get_uint (g_value_array_get_nth (values, 2)),
226 g_value_get_string (g_value_array_get_nth (values, 3)));
229 /* Connect to NewDebugMessage */
230 priv->new_debug_message_signal = emp_cli_debug_connect_to_new_debug_message (
231 proxy, debug_dialog_new_debug_message_cb, debug_dialog,
234 /* Set Enabled as appropriate */
235 debug_dialog_set_enabled (debug_dialog, !priv->paused);
239 debug_dialog_cm_chooser_changed_cb (GtkComboBox *cm_chooser,
240 EmpathyDebugDialog *debug_dialog)
242 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
245 GError *error = NULL;
250 if (!gtk_combo_box_get_active_iter (cm_chooser, &iter))
252 DEBUG ("No CM is selected");
253 if (gtk_tree_model_iter_n_children (
254 GTK_TREE_MODEL (priv->cms), NULL) > 0)
256 gtk_combo_box_set_active (cm_chooser, 0);
261 mc = empathy_mission_control_dup_singleton ();
262 dbus = tp_dbus_daemon_dup (&error);
266 DEBUG ("Failed at duping the dbus daemon: %s", error->message);
270 gtk_tree_model_get (GTK_TREE_MODEL (priv->cms), &iter,
271 COL_CM_UNIQUE_NAME, &bus_name, -1);
272 proxy = g_object_new (TP_TYPE_PROXY,
273 "bus-name", bus_name,
275 "object-path", DEBUG_OBJECT_PATH,
279 gtk_list_store_clear (priv->store);
281 /* Disable debug signalling */
282 if (priv->proxy != NULL)
283 debug_dialog_set_enabled (debug_dialog, FALSE);
285 /* Disconnect from previous NewDebugMessage signal */
286 if (priv->new_debug_message_signal != NULL)
288 tp_proxy_signal_connection_disconnect (priv->new_debug_message_signal);
289 priv->new_debug_message_signal = NULL;
292 if (priv->proxy != NULL)
293 g_object_unref (priv->proxy);
297 tp_proxy_add_interface_by_id (priv->proxy, emp_iface_quark_debug ());
299 emp_cli_debug_call_get_messages (priv->proxy, -1,
300 debug_dialog_get_messages_cb, debug_dialog, NULL, NULL);
302 g_object_unref (dbus);
308 const gchar *unique_name;
310 } CmInModelForeachData;
313 debug_dialog_cms_foreach (GtkTreeModel *model,
318 CmInModelForeachData *data = (CmInModelForeachData *) user_data;
321 gtk_tree_model_get (model, iter,
322 COL_CM_UNIQUE_NAME, &unique_name,
325 if (!tp_strdiff (unique_name, data->unique_name))
328 g_free (unique_name);
334 debug_dialog_cm_is_in_model (EmpathyDebugDialog *debug_dialog,
335 const gchar *unique_name)
337 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
338 CmInModelForeachData *data;
341 data = g_slice_new0 (CmInModelForeachData);
342 data->unique_name = unique_name;
345 gtk_tree_model_foreach (GTK_TREE_MODEL (priv->cms),
346 debug_dialog_cms_foreach, data);
350 g_slice_free (CmInModelForeachData, data);
357 EmpathyDebugDialog *debug_dialog;
362 debug_dialog_get_name_owner_cb (TpDBusDaemon *proxy,
366 GObject *weak_object)
368 FillCmChooserData *data = (FillCmChooserData *) user_data;
369 EmpathyDebugDialogPriv *priv = GET_PRIV (data->debug_dialog);
373 DEBUG ("GetNameOwner failed: %s", error->message);
377 if (!debug_dialog_cm_is_in_model (data->debug_dialog, out))
381 DEBUG ("Adding CM to list: %s at unique name: %s",
384 gtk_list_store_append (priv->cms, &iter);
385 gtk_list_store_set (priv->cms, &iter,
386 COL_CM_NAME, data->cm_name,
387 COL_CM_UNIQUE_NAME, out,
390 gtk_combo_box_set_active (GTK_COMBO_BOX (priv->cm_chooser), 0);
394 g_free (data->cm_name);
395 g_slice_free (FillCmChooserData, data);
399 debug_dialog_list_connection_names_cb (const gchar * const *names,
401 const gchar * const *cms,
402 const gchar * const *protocols,
405 GObject *weak_object)
407 EmpathyDebugDialog *debug_dialog = (EmpathyDebugDialog *) user_data;
410 GError *error2 = NULL;
414 DEBUG ("list_connection_names failed: %s", error->message);
418 dbus = tp_dbus_daemon_dup (&error2);
422 DEBUG ("Failed to dup TpDBusDaemon.");
426 for (i = 0; cms[i] != NULL; i++)
428 FillCmChooserData *data;
430 data = g_slice_new0 (FillCmChooserData);
431 data->debug_dialog = debug_dialog;
432 data->cm_name = g_strdup (cms[i]);
434 tp_cli_dbus_daemon_call_get_name_owner (dbus, -1,
435 names[i], debug_dialog_get_name_owner_cb,
439 g_object_unref (dbus);
443 debug_dialog_remove_cm_foreach (GtkTreeModel *model,
448 const gchar *unique_name_to_remove = (const gchar *) user_data;
450 gboolean found = FALSE;
452 gtk_tree_model_get (model, iter, COL_CM_UNIQUE_NAME, &name, -1);
454 if (!tp_strdiff (name, unique_name_to_remove))
457 gtk_list_store_remove (GTK_LIST_STORE (model), iter);
465 #define CM_WELL_KNOWN_NAME_PREFIX \
466 "org.freedesktop.Telepathy.ConnectionManager."
469 debug_dialog_name_owner_changed_cb (TpDBusDaemon *proxy,
474 GObject *weak_object)
476 EmpathyDebugDialogPriv *priv = GET_PRIV (user_data);
478 /* Wow, I hate all of this code... */
479 if (!g_str_has_prefix (arg0, CM_WELL_KNOWN_NAME_PREFIX))
482 if (EMP_STR_EMPTY (arg1) && !EMP_STR_EMPTY (arg2))
484 /* A connection manager joined -- because it's guaranteed
485 * that the CM just joined (because o.fd.Tp.CM.foo
486 * just joined), we don't need to check whether the unique
487 * name is in the CM model. Hooray.
490 const gchar *name = arg0 + strlen (CM_WELL_KNOWN_NAME_PREFIX);
492 DEBUG ("Adding new CM '%s' at %s.", name, arg2);
494 gtk_list_store_append (priv->cms, &iter);
495 gtk_list_store_set (priv->cms, &iter,
497 COL_CM_UNIQUE_NAME, arg2,
500 else if (!EMP_STR_EMPTY (arg1) && EMP_STR_EMPTY (arg2))
502 /* A connection manager died -- because it's guaranteed
503 * that the CM itself just died (because o.fd.Tp.CM.foo
504 * just died), we don't need to check that it was already
509 /* Can't pass a const into a GtkTreeModelForeachFunc. */
510 to_remove = g_strdup (arg1);
512 DEBUG ("Removing CM from %s.", to_remove);
514 gtk_tree_model_foreach (GTK_TREE_MODEL (priv->cms),
515 debug_dialog_remove_cm_foreach, to_remove);
522 debug_dialog_fill_cm_chooser (EmpathyDebugDialog *debug_dialog)
524 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
526 GError *error = NULL;
528 dbus = tp_dbus_daemon_dup (&error);
532 DEBUG ("Failed to dup dbus daemon: %s", error->message);
533 g_error_free (error);
537 tp_list_connection_names (dbus, debug_dialog_list_connection_names_cb,
538 debug_dialog, NULL, NULL);
540 priv->name_owner_changed_signal =
541 tp_cli_dbus_daemon_connect_to_name_owner_changed (dbus,
542 debug_dialog_name_owner_changed_cb, debug_dialog, NULL, NULL, NULL);
544 g_object_unref (dbus);
548 debug_dialog_pause_toggled_cb (GtkToggleToolButton *pause,
549 EmpathyDebugDialog *debug_dialog)
551 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
553 priv->paused = gtk_toggle_tool_button_get_active (pause);
555 debug_dialog_set_enabled (debug_dialog, !priv->paused);
559 debug_dialog_visible_func (GtkTreeModel *model,
563 EmpathyDebugDialog *debug_dialog = (EmpathyDebugDialog *) user_data;
564 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
565 guint filter_value, level;
566 GtkTreeModel *filter_model;
567 GtkTreeIter filter_iter;
569 filter_model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->filter));
570 gtk_combo_box_get_active_iter (GTK_COMBO_BOX (priv->filter),
573 gtk_tree_model_get (model, iter, COL_DEBUG_LEVEL_VALUE, &level, -1);
574 gtk_tree_model_get (filter_model, &filter_iter,
575 COL_LEVEL_VALUE, &filter_value, -1);
577 if (level <= filter_value)
584 debug_dialog_filter_changed_cb (GtkComboBox *filter,
585 EmpathyDebugDialog *debug_dialog)
587 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
589 gtk_tree_model_filter_refilter (
590 GTK_TREE_MODEL_FILTER (priv->store_filter));
594 debug_dialog_clear_clicked_cb (GtkToolButton *clear_button,
595 EmpathyDebugDialog *debug_dialog)
597 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
599 gtk_list_store_clear (priv->store);
603 debug_dialog_menu_copy_activate_cb (GtkMenuItem *menu_item,
604 EmpathyDebugDialog *debug_dialog)
606 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
608 GtkTreeViewColumn *focus_column;
611 GtkClipboard *clipboard;
613 gtk_tree_view_get_cursor (GTK_TREE_VIEW (priv->view),
614 &path, &focus_column);
618 DEBUG ("No row is in focus");
622 gtk_tree_model_get_iter (priv->store_filter, &iter, path);
624 gtk_tree_model_get (priv->store_filter, &iter,
625 COL_DEBUG_MESSAGE, &message,
628 if (EMP_STR_EMPTY (message))
630 DEBUG ("Log message is empty");
634 clipboard = gtk_clipboard_get_for_display (
635 gtk_widget_get_display (GTK_WIDGET (menu_item)),
636 GDK_SELECTION_CLIPBOARD);
638 gtk_clipboard_set_text (clipboard, message, -1);
645 EmpathyDebugDialog *debug_dialog;
651 debug_dialog_show_menu (gpointer user_data)
653 MenuPopupData *data = (MenuPopupData *) user_data;
654 GtkWidget *menu, *item;
657 menu = gtk_menu_new ();
658 shell = GTK_MENU_SHELL (menu);
660 item = gtk_image_menu_item_new_from_stock (GTK_STOCK_COPY, NULL);
662 g_signal_connect (item, "activate",
663 G_CALLBACK (debug_dialog_menu_copy_activate_cb), data->debug_dialog);
665 gtk_menu_shell_append (shell, item);
666 gtk_widget_show (item);
668 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
669 data->button, data->time);
671 g_slice_free (MenuPopupData, user_data);
677 debug_dialog_button_press_event_cb (GtkTreeView *view,
678 GdkEventButton *event,
681 /* A mouse button was pressed on the tree view. */
683 if (event->button == 3)
685 /* The tree view was right-clicked. (3 == third mouse button) */
687 data = g_slice_new0 (MenuPopupData);
688 data->debug_dialog = user_data;
689 data->button = event->button;
690 data->time = event->time;
691 g_idle_add (debug_dialog_show_menu, data);
698 debug_dialog_store_filter_foreach (GtkTreeModel *model,
703 GFileOutputStream *output_stream = (GFileOutputStream *) user_data;
704 gchar *domain, *category, *message, *level_str, *level_upper;
707 GError *error = NULL;
708 gboolean out = FALSE;
710 gtk_tree_model_get (model, iter,
711 COL_DEBUG_TIMESTAMP, ×tamp,
712 COL_DEBUG_DOMAIN, &domain,
713 COL_DEBUG_CATEGORY, &category,
714 COL_DEBUG_LEVEL_STRING, &level_str,
715 COL_DEBUG_MESSAGE, &message,
718 level_upper = g_ascii_strup (level_str, -1);
720 line = g_strdup_printf ("%s%s%s-%s: %e: %s\n",
721 domain, EMP_STR_EMPTY (category) ? "" : "/",
722 category, level_upper, timestamp, message);
724 g_output_stream_write (G_OUTPUT_STREAM (output_stream), line,
725 strlen (line), NULL, &error);
729 DEBUG ("Failed to write to file: %s", error->message);
730 g_error_free (error);
735 g_free (level_upper);
745 debug_dialog_save_file_chooser_response_cb (GtkDialog *dialog,
747 EmpathyDebugDialog *debug_dialog)
749 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
750 gchar *filename = NULL;
752 GFileOutputStream *output_stream = NULL;
753 GError *error = NULL;
755 if (response_id != GTK_RESPONSE_ACCEPT)
758 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
760 DEBUG ("Saving log as %s", filename);
762 gfile = g_file_new_for_path (filename);
763 output_stream = g_file_replace (gfile, NULL, FALSE,
764 G_FILE_CREATE_NONE, NULL, &error);
768 DEBUG ("Failed to open file for writing: %s", error->message);
769 g_error_free (error);
773 gtk_tree_model_foreach (priv->store_filter,
774 debug_dialog_store_filter_foreach, output_stream);
778 g_object_unref (gfile);
780 if (output_stream != NULL)
781 g_object_unref (output_stream);
783 if (filename != NULL)
786 gtk_widget_destroy (GTK_WIDGET (dialog));
790 debug_dialog_save_clicked_cb (GtkToolButton *tool_button,
791 EmpathyDebugDialog *debug_dialog)
793 GtkWidget *file_chooser;
795 file_chooser = gtk_file_chooser_dialog_new (_("Save"),
796 GTK_WINDOW (debug_dialog), GTK_FILE_CHOOSER_ACTION_SAVE,
797 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
798 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
801 gtk_window_set_modal (GTK_WINDOW (file_chooser), TRUE);
802 gtk_file_chooser_set_do_overwrite_confirmation (
803 GTK_FILE_CHOOSER (file_chooser), TRUE);
805 g_signal_connect (file_chooser, "response",
806 G_CALLBACK (debug_dialog_save_file_chooser_response_cb),
809 gtk_widget_show (file_chooser);
813 debug_dialog_copy_model_foreach (GtkTreeModel *model,
818 gchar **text = (gchar **) user_data;
820 gchar *domain, *category, *message, *level_str, *level_upper;
824 gtk_tree_model_get (model, iter,
825 COL_DEBUG_TIMESTAMP, ×tamp,
826 COL_DEBUG_DOMAIN, &domain,
827 COL_DEBUG_CATEGORY, &category,
828 COL_DEBUG_LEVEL_STRING, &level_str,
829 COL_DEBUG_MESSAGE, &message,
832 level_upper = g_ascii_strup (level_str, -1);
834 line = g_strdup_printf ("%s%s%s-%s: %e: %s\n",
835 domain, EMP_STR_EMPTY (category) ? "" : "/",
836 category, level_upper, timestamp, message);
838 tmp = g_strconcat (*text, line, NULL);
842 g_free (level_upper);
854 debug_dialog_copy_clicked_cb (GtkToolButton *tool_button,
855 EmpathyDebugDialog *debug_dialog)
857 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
858 GtkClipboard *clipboard;
861 text = g_strdup ("");
863 gtk_tree_model_foreach (priv->store_filter,
864 debug_dialog_copy_model_foreach, &text);
866 clipboard = gtk_clipboard_get_for_display (
867 gtk_widget_get_display (GTK_WIDGET (tool_button)),
868 GDK_SELECTION_CLIPBOARD);
870 DEBUG ("Copying text to clipboard (length: %" G_GSIZE_FORMAT ")",
873 gtk_clipboard_set_text (clipboard, text, -1);
879 debug_dialog_constructor (GType type,
880 guint n_construct_params,
881 GObjectConstructParam *construct_params)
884 EmpathyDebugDialogPriv *priv;
890 GtkCellRenderer *renderer;
891 GtkWidget *scrolled_win;
892 GtkListStore *level_store;
895 object = G_OBJECT_CLASS (empathy_debug_dialog_parent_class)->constructor
896 (type, n_construct_params, construct_params);
897 priv = GET_PRIV (object);
899 gtk_window_set_title (GTK_WINDOW (object), _("Debug Window"));
900 gtk_window_set_default_size (GTK_WINDOW (object), 800, 400);
902 vbox = GTK_DIALOG (object)->vbox;
904 toolbar = gtk_toolbar_new ();
905 gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_BOTH_HORIZ);
906 gtk_toolbar_set_show_arrow (GTK_TOOLBAR (toolbar), TRUE);
907 gtk_toolbar_set_icon_size (GTK_TOOLBAR (toolbar),
908 GTK_ICON_SIZE_SMALL_TOOLBAR);
909 gtk_widget_show (toolbar);
911 gtk_box_pack_start (GTK_BOX (vbox), toolbar, FALSE, FALSE, 0);
914 priv->cm_chooser = gtk_combo_box_new_text ();
915 priv->cms = gtk_list_store_new (NUM_COLS_CM, G_TYPE_STRING, G_TYPE_STRING);
916 gtk_combo_box_set_model (GTK_COMBO_BOX (priv->cm_chooser),
917 GTK_TREE_MODEL (priv->cms));
918 gtk_widget_show (priv->cm_chooser);
920 item = gtk_tool_item_new ();
921 gtk_widget_show (GTK_WIDGET (item));
922 gtk_container_add (GTK_CONTAINER (item), priv->cm_chooser);
923 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
924 debug_dialog_fill_cm_chooser (EMPATHY_DEBUG_DIALOG (object));
925 g_signal_connect (priv->cm_chooser, "changed",
926 G_CALLBACK (debug_dialog_cm_chooser_changed_cb), object);
927 gtk_widget_show (GTK_WIDGET (priv->cm_chooser));
929 item = gtk_separator_tool_item_new ();
930 gtk_widget_show (GTK_WIDGET (item));
931 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
934 item = gtk_tool_button_new_from_stock (GTK_STOCK_SAVE);
935 g_signal_connect (item, "clicked",
936 G_CALLBACK (debug_dialog_save_clicked_cb), object);
937 gtk_widget_show (GTK_WIDGET (item));
938 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (item), TRUE);
939 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
942 item = gtk_tool_button_new_from_stock (GTK_STOCK_COPY);
943 g_signal_connect (item, "clicked",
944 G_CALLBACK (debug_dialog_copy_clicked_cb), object);
945 gtk_widget_show (GTK_WIDGET (item));
946 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (item), TRUE);
947 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
950 item = gtk_tool_button_new_from_stock (GTK_STOCK_CLEAR);
951 g_signal_connect (item, "clicked",
952 G_CALLBACK (debug_dialog_clear_clicked_cb), object);
953 gtk_widget_show (GTK_WIDGET (item));
954 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (item), TRUE);
955 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
957 item = gtk_separator_tool_item_new ();
958 gtk_widget_show (GTK_WIDGET (item));
959 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
962 priv->paused = FALSE;
963 image = gtk_image_new_from_stock (GTK_STOCK_MEDIA_PAUSE,
965 gtk_widget_show (image);
966 item = gtk_toggle_tool_button_new ();
967 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (item),
969 g_signal_connect (item, "toggled",
970 G_CALLBACK (debug_dialog_pause_toggled_cb), object);
971 gtk_widget_show (GTK_WIDGET (item));
972 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (item), TRUE);
973 gtk_tool_button_set_label (GTK_TOOL_BUTTON (item), _("Pause"));
974 gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (item), image);
975 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
977 item = gtk_separator_tool_item_new ();
978 gtk_widget_show (GTK_WIDGET (item));
979 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
982 item = gtk_tool_item_new ();
983 gtk_widget_show (GTK_WIDGET (item));
984 label = gtk_label_new (_("Level "));
985 gtk_widget_show (label);
986 gtk_container_add (GTK_CONTAINER (item), label);
987 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
989 priv->filter = gtk_combo_box_new_text ();
990 gtk_widget_show (priv->filter);
992 item = gtk_tool_item_new ();
993 gtk_widget_show (GTK_WIDGET (item));
994 gtk_container_add (GTK_CONTAINER (item), priv->filter);
995 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
997 level_store = gtk_list_store_new (NUM_COLS_LEVEL,
998 G_TYPE_STRING, G_TYPE_UINT);
999 gtk_combo_box_set_model (GTK_COMBO_BOX (priv->filter),
1000 GTK_TREE_MODEL (level_store));
1002 gtk_list_store_append (level_store, &iter);
1003 gtk_list_store_set (level_store, &iter,
1004 COL_LEVEL_NAME, _("Debug"),
1005 COL_LEVEL_VALUE, EMP_DEBUG_LEVEL_DEBUG,
1008 gtk_list_store_append (level_store, &iter);
1009 gtk_list_store_set (level_store, &iter,
1010 COL_LEVEL_NAME, _("Info"),
1011 COL_LEVEL_VALUE, EMP_DEBUG_LEVEL_INFO,
1014 gtk_list_store_append (level_store, &iter);
1015 gtk_list_store_set (level_store, &iter,
1016 COL_LEVEL_NAME, _("Message"),
1017 COL_LEVEL_VALUE, EMP_DEBUG_LEVEL_MESSAGE,
1020 gtk_list_store_append (level_store, &iter);
1021 gtk_list_store_set (level_store, &iter,
1022 COL_LEVEL_NAME, _("Warning"),
1023 COL_LEVEL_VALUE, EMP_DEBUG_LEVEL_WARNING,
1026 gtk_list_store_append (level_store, &iter);
1027 gtk_list_store_set (level_store, &iter,
1028 COL_LEVEL_NAME, _("Critical"),
1029 COL_LEVEL_VALUE, EMP_DEBUG_LEVEL_CRITICAL,
1032 gtk_list_store_append (level_store, &iter);
1033 gtk_list_store_set (level_store, &iter,
1034 COL_LEVEL_NAME, _("Error"),
1035 COL_LEVEL_VALUE, EMP_DEBUG_LEVEL_ERROR,
1038 gtk_combo_box_set_active (GTK_COMBO_BOX (priv->filter), 0);
1039 g_signal_connect (priv->filter, "changed",
1040 G_CALLBACK (debug_dialog_filter_changed_cb), object);
1042 /* Debug treeview */
1043 priv->view = gtk_tree_view_new ();
1044 gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (priv->view), TRUE);
1046 g_signal_connect (priv->view, "button-press-event",
1047 G_CALLBACK (debug_dialog_button_press_event_cb), object);
1049 renderer = gtk_cell_renderer_text_new ();
1050 g_object_set (renderer, "yalign", 0, NULL);
1052 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
1053 -1, _("Time"), renderer, "text", COL_DEBUG_TIMESTAMP, NULL);
1054 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
1055 -1, _("Domain"), renderer, "text", COL_DEBUG_DOMAIN, NULL);
1056 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
1057 -1, _("Category"), renderer, "text", COL_DEBUG_CATEGORY, NULL);
1058 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
1059 -1, _("Level"), renderer, "text", COL_DEBUG_LEVEL_STRING, NULL);
1061 renderer = gtk_cell_renderer_text_new ();
1062 g_object_set (renderer, "family", "Monospace", NULL);
1063 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
1064 -1, _("Message"), renderer, "text", COL_DEBUG_MESSAGE, NULL);
1066 priv->store = gtk_list_store_new (NUM_DEBUG_COLS, G_TYPE_DOUBLE,
1067 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
1070 priv->store_filter = gtk_tree_model_filter_new (
1071 GTK_TREE_MODEL (priv->store), NULL);
1073 gtk_tree_model_filter_set_visible_func (
1074 GTK_TREE_MODEL_FILTER (priv->store_filter),
1075 debug_dialog_visible_func, object, NULL);
1077 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->view), priv->store_filter);
1079 /* Scrolled window */
1080 scrolled_win = gtk_scrolled_window_new (NULL, NULL);
1081 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
1082 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1084 gtk_widget_show (priv->view);
1085 gtk_container_add (GTK_CONTAINER (scrolled_win), priv->view);
1087 gtk_widget_show (scrolled_win);
1088 gtk_box_pack_start (GTK_BOX (vbox), scrolled_win, TRUE, TRUE, 0);
1090 gtk_widget_show (GTK_WIDGET (object));
1096 empathy_debug_dialog_init (EmpathyDebugDialog *empathy_debug_dialog)
1098 EmpathyDebugDialogPriv *priv =
1099 G_TYPE_INSTANCE_GET_PRIVATE (empathy_debug_dialog,
1100 EMPATHY_TYPE_DEBUG_DIALOG, EmpathyDebugDialogPriv);
1102 empathy_debug_dialog->priv = priv;
1104 priv->dispose_run = FALSE;
1108 debug_dialog_set_property (GObject *object,
1110 const GValue *value,
1116 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1122 debug_dialog_get_property (GObject *object,
1130 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1136 debug_dialog_dispose (GObject *object)
1138 EmpathyDebugDialog *selector = EMPATHY_DEBUG_DIALOG (object);
1139 EmpathyDebugDialogPriv *priv = GET_PRIV (selector);
1141 if (priv->dispose_run)
1144 priv->dispose_run = TRUE;
1146 if (priv->store != NULL)
1147 g_object_unref (priv->store);
1149 if (priv->name_owner_changed_signal != NULL)
1150 tp_proxy_signal_connection_disconnect (priv->name_owner_changed_signal);
1152 if (priv->proxy != NULL)
1154 debug_dialog_set_enabled (EMPATHY_DEBUG_DIALOG (object), FALSE);
1155 g_object_unref (priv->proxy);
1158 if (priv->new_debug_message_signal != NULL)
1159 tp_proxy_signal_connection_disconnect (priv->new_debug_message_signal);
1161 if (priv->cms != NULL)
1162 g_object_unref (priv->cms);
1164 (G_OBJECT_CLASS (empathy_debug_dialog_parent_class)->dispose) (object);
1168 empathy_debug_dialog_class_init (EmpathyDebugDialogClass *klass)
1170 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1171 object_class->constructor = debug_dialog_constructor;
1172 object_class->dispose = debug_dialog_dispose;
1173 object_class->set_property = debug_dialog_set_property;
1174 object_class->get_property = debug_dialog_get_property;
1175 g_type_class_add_private (klass, sizeof (EmpathyDebugDialogPriv));
1178 /* public methods */
1181 empathy_debug_dialog_new (GtkWindow *parent)
1183 g_return_val_if_fail (GTK_IS_WINDOW (parent), NULL);
1185 return GTK_WIDGET (g_object_new (EMPATHY_TYPE_DEBUG_DIALOG,
1186 "transient-for", parent, NULL));