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 GtkWidget *level_filter;
82 GtkTreeModel *store_filter;
88 TpProxySignalConnection *new_debug_message_signal;
89 TpProxySignalConnection *name_owner_changed_signal;
91 /* Whether NewDebugMessage will be fired */
94 /* CM chooser store */
99 } EmpathyDebugDialogPriv;
102 log_level_to_string (guint level)
106 case EMP_DEBUG_LEVEL_ERROR:
109 case EMP_DEBUG_LEVEL_CRITICAL:
110 return _("Critical");
112 case EMP_DEBUG_LEVEL_WARNING:
115 case EMP_DEBUG_LEVEL_MESSAGE:
118 case EMP_DEBUG_LEVEL_INFO:
121 case EMP_DEBUG_LEVEL_DEBUG:
125 g_assert_not_reached ();
131 debug_dialog_add_message (EmpathyDebugDialog *debug_dialog,
133 const gchar *domain_category,
135 const gchar *message)
137 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
138 gchar *domain, *category;
142 if (g_strrstr (domain_category, "/"))
144 gchar **parts = g_strsplit (domain_category, "/", 2);
145 domain = g_strdup (parts[0]);
146 category = g_strdup (parts[1]);
151 domain = g_strdup (domain_category);
152 category = g_strdup ("");
155 if (g_str_has_suffix (message, "\n"))
156 string = g_strchomp (g_strdup (message));
158 string = g_strdup (message);
161 gtk_list_store_append (priv->store, &iter);
162 gtk_list_store_set (priv->store, &iter,
163 COL_DEBUG_TIMESTAMP, timestamp,
164 COL_DEBUG_DOMAIN, domain,
165 COL_DEBUG_CATEGORY, category,
166 COL_DEBUG_LEVEL_STRING, log_level_to_string (level),
167 COL_DEBUG_MESSAGE, string,
168 COL_DEBUG_LEVEL_VALUE, level,
177 debug_dialog_new_debug_message_cb (TpProxy *proxy,
181 const gchar *message,
183 GObject *weak_object)
185 EmpathyDebugDialog *debug_dialog = (EmpathyDebugDialog *) user_data;
187 debug_dialog_add_message (debug_dialog, timestamp, domain, level,
192 debug_dialog_set_enabled (EmpathyDebugDialog *debug_dialog,
195 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
198 val = tp_g_value_slice_new_boolean (enabled);
200 tp_cli_dbus_properties_call_set (priv->proxy, -1, EMP_IFACE_DEBUG,
201 "Enabled", val, NULL, NULL, NULL, NULL);
203 tp_g_value_slice_free (val);
207 debug_dialog_get_messages_cb (TpProxy *proxy,
208 const GPtrArray *messages,
211 GObject *weak_object)
213 EmpathyDebugDialog *debug_dialog = (EmpathyDebugDialog *) user_data;
214 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
219 DEBUG ("GetMessages failed: %s", error->message);
223 for (i = 0; i < messages->len; i++)
225 GValueArray *values = g_ptr_array_index (messages, i);
227 debug_dialog_add_message (debug_dialog,
228 g_value_get_double (g_value_array_get_nth (values, 0)),
229 g_value_get_string (g_value_array_get_nth (values, 1)),
230 g_value_get_uint (g_value_array_get_nth (values, 2)),
231 g_value_get_string (g_value_array_get_nth (values, 3)));
234 /* Connect to NewDebugMessage */
235 priv->new_debug_message_signal = emp_cli_debug_connect_to_new_debug_message (
236 proxy, debug_dialog_new_debug_message_cb, debug_dialog,
239 /* Set Enabled as appropriate */
240 debug_dialog_set_enabled (debug_dialog, !priv->paused);
244 debug_dialog_cm_chooser_changed_cb (GtkComboBox *cm_chooser,
245 EmpathyDebugDialog *debug_dialog)
247 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
250 GError *error = NULL;
255 if (!gtk_combo_box_get_active_iter (cm_chooser, &iter))
257 DEBUG ("No CM is selected");
258 if (gtk_tree_model_iter_n_children (
259 GTK_TREE_MODEL (priv->cms), NULL) > 0)
261 gtk_combo_box_set_active (cm_chooser, 0);
266 mc = empathy_mission_control_dup_singleton ();
267 dbus = tp_dbus_daemon_dup (&error);
271 DEBUG ("Failed at duping the dbus daemon: %s", error->message);
275 gtk_tree_model_get (GTK_TREE_MODEL (priv->cms), &iter,
276 COL_CM_UNIQUE_NAME, &bus_name, -1);
277 proxy = g_object_new (TP_TYPE_PROXY,
278 "bus-name", bus_name,
280 "object-path", DEBUG_OBJECT_PATH,
284 gtk_list_store_clear (priv->store);
286 /* Disable debug signalling */
287 if (priv->proxy != NULL)
288 debug_dialog_set_enabled (debug_dialog, FALSE);
290 /* Disconnect from previous NewDebugMessage signal */
291 if (priv->new_debug_message_signal != NULL)
293 tp_proxy_signal_connection_disconnect (priv->new_debug_message_signal);
294 priv->new_debug_message_signal = NULL;
297 if (priv->proxy != NULL)
298 g_object_unref (priv->proxy);
302 tp_proxy_add_interface_by_id (priv->proxy, emp_iface_quark_debug ());
304 emp_cli_debug_call_get_messages (priv->proxy, -1,
305 debug_dialog_get_messages_cb, debug_dialog, NULL, NULL);
307 g_object_unref (dbus);
313 const gchar *unique_name;
315 } CmInModelForeachData;
318 debug_dialog_cms_foreach (GtkTreeModel *model,
323 CmInModelForeachData *data = (CmInModelForeachData *) user_data;
326 gtk_tree_model_get (model, iter,
327 COL_CM_UNIQUE_NAME, &unique_name,
330 if (!tp_strdiff (unique_name, data->unique_name))
333 g_free (unique_name);
339 debug_dialog_cm_is_in_model (EmpathyDebugDialog *debug_dialog,
340 const gchar *unique_name)
342 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
343 CmInModelForeachData *data;
346 data = g_slice_new0 (CmInModelForeachData);
347 data->unique_name = unique_name;
350 gtk_tree_model_foreach (GTK_TREE_MODEL (priv->cms),
351 debug_dialog_cms_foreach, data);
355 g_slice_free (CmInModelForeachData, data);
362 EmpathyDebugDialog *debug_dialog;
367 debug_dialog_get_name_owner_cb (TpDBusDaemon *proxy,
371 GObject *weak_object)
373 FillCmChooserData *data = (FillCmChooserData *) user_data;
374 EmpathyDebugDialogPriv *priv = GET_PRIV (data->debug_dialog);
378 DEBUG ("GetNameOwner failed: %s", error->message);
382 if (!debug_dialog_cm_is_in_model (data->debug_dialog, out))
386 DEBUG ("Adding CM to list: %s at unique name: %s",
389 gtk_list_store_append (priv->cms, &iter);
390 gtk_list_store_set (priv->cms, &iter,
391 COL_CM_NAME, data->cm_name,
392 COL_CM_UNIQUE_NAME, out,
395 gtk_combo_box_set_active (GTK_COMBO_BOX (priv->cm_chooser), 0);
399 g_free (data->cm_name);
400 g_slice_free (FillCmChooserData, data);
404 debug_dialog_list_connection_names_cb (const gchar * const *names,
406 const gchar * const *cms,
407 const gchar * const *protocols,
410 GObject *weak_object)
412 EmpathyDebugDialog *debug_dialog = (EmpathyDebugDialog *) user_data;
415 GError *error2 = NULL;
419 DEBUG ("list_connection_names failed: %s", error->message);
423 dbus = tp_dbus_daemon_dup (&error2);
427 DEBUG ("Failed to dup TpDBusDaemon.");
431 for (i = 0; cms[i] != NULL; i++)
433 FillCmChooserData *data;
435 data = g_slice_new0 (FillCmChooserData);
436 data->debug_dialog = debug_dialog;
437 data->cm_name = g_strdup (cms[i]);
439 tp_cli_dbus_daemon_call_get_name_owner (dbus, -1,
440 names[i], debug_dialog_get_name_owner_cb,
444 g_object_unref (dbus);
448 debug_dialog_remove_cm_foreach (GtkTreeModel *model,
453 const gchar *unique_name_to_remove = (const gchar *) user_data;
455 gboolean found = FALSE;
457 gtk_tree_model_get (model, iter, COL_CM_UNIQUE_NAME, &name, -1);
459 if (!tp_strdiff (name, unique_name_to_remove))
462 gtk_list_store_remove (GTK_LIST_STORE (model), iter);
470 #define CM_WELL_KNOWN_NAME_PREFIX \
471 "org.freedesktop.Telepathy.ConnectionManager."
474 debug_dialog_name_owner_changed_cb (TpDBusDaemon *proxy,
479 GObject *weak_object)
481 EmpathyDebugDialogPriv *priv = GET_PRIV (user_data);
483 /* Wow, I hate all of this code... */
484 if (!g_str_has_prefix (arg0, CM_WELL_KNOWN_NAME_PREFIX))
487 if (EMP_STR_EMPTY (arg1) && !EMP_STR_EMPTY (arg2))
489 /* A connection manager joined -- because it's guaranteed
490 * that the CM just joined (because o.fd.Tp.CM.foo
491 * just joined), we don't need to check whether the unique
492 * name is in the CM model. Hooray.
495 const gchar *name = arg0 + strlen (CM_WELL_KNOWN_NAME_PREFIX);
497 DEBUG ("Adding new CM '%s' at %s.", name, arg2);
499 gtk_list_store_append (priv->cms, &iter);
500 gtk_list_store_set (priv->cms, &iter,
502 COL_CM_UNIQUE_NAME, arg2,
505 else if (!EMP_STR_EMPTY (arg1) && EMP_STR_EMPTY (arg2))
507 /* A connection manager died -- because it's guaranteed
508 * that the CM itself just died (because o.fd.Tp.CM.foo
509 * just died), we don't need to check that it was already
514 /* Can't pass a const into a GtkTreeModelForeachFunc. */
515 to_remove = g_strdup (arg1);
517 DEBUG ("Removing CM from %s.", to_remove);
519 gtk_tree_model_foreach (GTK_TREE_MODEL (priv->cms),
520 debug_dialog_remove_cm_foreach, to_remove);
527 debug_dialog_fill_cm_chooser (EmpathyDebugDialog *debug_dialog)
529 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
530 GError *error = NULL;
532 priv->dbus = tp_dbus_daemon_dup (&error);
536 DEBUG ("Failed to dup dbus daemon: %s", error->message);
537 g_error_free (error);
541 tp_list_connection_names (priv->dbus, debug_dialog_list_connection_names_cb,
542 debug_dialog, NULL, NULL);
544 priv->name_owner_changed_signal =
545 tp_cli_dbus_daemon_connect_to_name_owner_changed (priv->dbus,
546 debug_dialog_name_owner_changed_cb, debug_dialog, NULL, NULL, NULL);
550 debug_dialog_pause_toggled_cb (GtkToggleToolButton *pause,
551 EmpathyDebugDialog *debug_dialog)
553 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
555 priv->paused = gtk_toggle_tool_button_get_active (pause);
557 debug_dialog_set_enabled (debug_dialog, !priv->paused);
561 debug_dialog_visible_func (GtkTreeModel *model,
565 EmpathyDebugDialog *debug_dialog = (EmpathyDebugDialog *) user_data;
566 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
567 guint filter_value, level;
568 GtkTreeModel *filter_model;
569 GtkTreeIter filter_iter;
571 filter_model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->level_filter));
572 gtk_combo_box_get_active_iter (GTK_COMBO_BOX (priv->level_filter),
575 gtk_tree_model_get (model, iter, COL_DEBUG_LEVEL_VALUE, &level, -1);
576 gtk_tree_model_get (filter_model, &filter_iter,
577 COL_LEVEL_VALUE, &filter_value, -1);
579 if (level <= filter_value)
586 debug_dialog_filter_changed_cb (GtkComboBox *filter,
587 EmpathyDebugDialog *debug_dialog)
589 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
591 gtk_tree_model_filter_refilter (
592 GTK_TREE_MODEL_FILTER (priv->store_filter));
596 debug_dialog_clear_clicked_cb (GtkToolButton *clear_button,
597 EmpathyDebugDialog *debug_dialog)
599 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
601 gtk_list_store_clear (priv->store);
605 debug_dialog_menu_copy_activate_cb (GtkMenuItem *menu_item,
606 EmpathyDebugDialog *debug_dialog)
608 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
610 GtkTreeViewColumn *focus_column;
613 GtkClipboard *clipboard;
615 gtk_tree_view_get_cursor (GTK_TREE_VIEW (priv->view),
616 &path, &focus_column);
620 DEBUG ("No row is in focus");
624 gtk_tree_model_get_iter (priv->store_filter, &iter, path);
626 gtk_tree_model_get (priv->store_filter, &iter,
627 COL_DEBUG_MESSAGE, &message,
630 if (EMP_STR_EMPTY (message))
632 DEBUG ("Log message is empty");
636 clipboard = gtk_clipboard_get_for_display (
637 gtk_widget_get_display (GTK_WIDGET (menu_item)),
638 GDK_SELECTION_CLIPBOARD);
640 gtk_clipboard_set_text (clipboard, message, -1);
647 EmpathyDebugDialog *debug_dialog;
653 debug_dialog_show_menu (gpointer user_data)
655 MenuPopupData *data = (MenuPopupData *) user_data;
656 GtkWidget *menu, *item;
659 menu = gtk_menu_new ();
660 shell = GTK_MENU_SHELL (menu);
662 item = gtk_image_menu_item_new_from_stock (GTK_STOCK_COPY, NULL);
664 g_signal_connect (item, "activate",
665 G_CALLBACK (debug_dialog_menu_copy_activate_cb), data->debug_dialog);
667 gtk_menu_shell_append (shell, item);
668 gtk_widget_show (item);
670 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
671 data->button, data->time);
673 g_slice_free (MenuPopupData, user_data);
679 debug_dialog_button_press_event_cb (GtkTreeView *view,
680 GdkEventButton *event,
683 /* A mouse button was pressed on the tree view. */
685 if (event->button == 3)
687 /* The tree view was right-clicked. (3 == third mouse button) */
689 data = g_slice_new0 (MenuPopupData);
690 data->debug_dialog = user_data;
691 data->button = event->button;
692 data->time = event->time;
693 g_idle_add (debug_dialog_show_menu, data);
700 debug_dialog_store_filter_foreach (GtkTreeModel *model,
705 GFileOutputStream *output_stream = (GFileOutputStream *) user_data;
706 gchar *domain, *category, *message, *level_str, *level_upper;
709 GError *error = NULL;
710 gboolean out = FALSE;
712 gtk_tree_model_get (model, iter,
713 COL_DEBUG_TIMESTAMP, ×tamp,
714 COL_DEBUG_DOMAIN, &domain,
715 COL_DEBUG_CATEGORY, &category,
716 COL_DEBUG_LEVEL_STRING, &level_str,
717 COL_DEBUG_MESSAGE, &message,
720 level_upper = g_ascii_strup (level_str, -1);
722 line = g_strdup_printf ("%s%s%s-%s: %e: %s\n",
723 domain, EMP_STR_EMPTY (category) ? "" : "/",
724 category, level_upper, timestamp, message);
726 g_output_stream_write (G_OUTPUT_STREAM (output_stream), line,
727 strlen (line), NULL, &error);
731 DEBUG ("Failed to write to file: %s", error->message);
732 g_error_free (error);
737 g_free (level_upper);
747 debug_dialog_save_file_chooser_response_cb (GtkDialog *dialog,
749 EmpathyDebugDialog *debug_dialog)
751 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
752 gchar *filename = NULL;
754 GFileOutputStream *output_stream = NULL;
755 GError *error = NULL;
757 if (response_id != GTK_RESPONSE_ACCEPT)
760 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
762 DEBUG ("Saving log as %s", filename);
764 gfile = g_file_new_for_path (filename);
765 output_stream = g_file_replace (gfile, NULL, FALSE,
766 G_FILE_CREATE_NONE, NULL, &error);
770 DEBUG ("Failed to open file for writing: %s", error->message);
771 g_error_free (error);
775 gtk_tree_model_foreach (priv->store_filter,
776 debug_dialog_store_filter_foreach, output_stream);
780 g_object_unref (gfile);
782 if (output_stream != NULL)
783 g_object_unref (output_stream);
785 if (filename != NULL)
788 gtk_widget_destroy (GTK_WIDGET (dialog));
792 debug_dialog_save_clicked_cb (GtkToolButton *tool_button,
793 EmpathyDebugDialog *debug_dialog)
795 GtkWidget *file_chooser;
797 file_chooser = gtk_file_chooser_dialog_new (_("Save"),
798 GTK_WINDOW (debug_dialog), GTK_FILE_CHOOSER_ACTION_SAVE,
799 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
800 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
803 gtk_window_set_modal (GTK_WINDOW (file_chooser), TRUE);
804 gtk_file_chooser_set_do_overwrite_confirmation (
805 GTK_FILE_CHOOSER (file_chooser), TRUE);
807 g_signal_connect (file_chooser, "response",
808 G_CALLBACK (debug_dialog_save_file_chooser_response_cb),
811 gtk_widget_show (file_chooser);
815 debug_dialog_copy_model_foreach (GtkTreeModel *model,
820 gchar **text = (gchar **) user_data;
822 gchar *domain, *category, *message, *level_str, *level_upper;
826 gtk_tree_model_get (model, iter,
827 COL_DEBUG_TIMESTAMP, ×tamp,
828 COL_DEBUG_DOMAIN, &domain,
829 COL_DEBUG_CATEGORY, &category,
830 COL_DEBUG_LEVEL_STRING, &level_str,
831 COL_DEBUG_MESSAGE, &message,
834 level_upper = g_ascii_strup (level_str, -1);
836 line = g_strdup_printf ("%s%s%s-%s: %e: %s\n",
837 domain, EMP_STR_EMPTY (category) ? "" : "/",
838 category, level_upper, timestamp, message);
840 tmp = g_strconcat (*text, line, NULL);
844 g_free (level_upper);
856 debug_dialog_copy_clicked_cb (GtkToolButton *tool_button,
857 EmpathyDebugDialog *debug_dialog)
859 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
860 GtkClipboard *clipboard;
863 text = g_strdup ("");
865 gtk_tree_model_foreach (priv->store_filter,
866 debug_dialog_copy_model_foreach, &text);
868 clipboard = gtk_clipboard_get_for_display (
869 gtk_widget_get_display (GTK_WIDGET (tool_button)),
870 GDK_SELECTION_CLIPBOARD);
872 DEBUG ("Copying text to clipboard (length: %" G_GSIZE_FORMAT ")",
875 gtk_clipboard_set_text (clipboard, text, -1);
881 debug_dialog_constructor (GType type,
882 guint n_construct_params,
883 GObjectConstructParam *construct_params)
886 EmpathyDebugDialogPriv *priv;
892 GtkCellRenderer *renderer;
893 GtkWidget *scrolled_win;
894 GtkListStore *level_store;
897 object = G_OBJECT_CLASS (empathy_debug_dialog_parent_class)->constructor
898 (type, n_construct_params, construct_params);
899 priv = GET_PRIV (object);
901 gtk_window_set_title (GTK_WINDOW (object), _("Debug Window"));
902 gtk_window_set_default_size (GTK_WINDOW (object), 800, 400);
904 vbox = GTK_DIALOG (object)->vbox;
906 toolbar = gtk_toolbar_new ();
907 gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_BOTH_HORIZ);
908 gtk_toolbar_set_show_arrow (GTK_TOOLBAR (toolbar), TRUE);
909 gtk_toolbar_set_icon_size (GTK_TOOLBAR (toolbar),
910 GTK_ICON_SIZE_SMALL_TOOLBAR);
911 gtk_widget_show (toolbar);
913 gtk_box_pack_start (GTK_BOX (vbox), toolbar, FALSE, FALSE, 0);
916 priv->cm_chooser = gtk_combo_box_new_text ();
917 priv->cms = gtk_list_store_new (NUM_COLS_CM, G_TYPE_STRING, G_TYPE_STRING);
918 gtk_combo_box_set_model (GTK_COMBO_BOX (priv->cm_chooser),
919 GTK_TREE_MODEL (priv->cms));
920 gtk_widget_show (priv->cm_chooser);
922 item = gtk_tool_item_new ();
923 gtk_widget_show (GTK_WIDGET (item));
924 gtk_container_add (GTK_CONTAINER (item), priv->cm_chooser);
925 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
926 debug_dialog_fill_cm_chooser (EMPATHY_DEBUG_DIALOG (object));
927 g_signal_connect (priv->cm_chooser, "changed",
928 G_CALLBACK (debug_dialog_cm_chooser_changed_cb), object);
929 gtk_widget_show (GTK_WIDGET (priv->cm_chooser));
931 item = gtk_separator_tool_item_new ();
932 gtk_widget_show (GTK_WIDGET (item));
933 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
936 priv->save_button = gtk_tool_button_new_from_stock (GTK_STOCK_SAVE);
937 g_signal_connect (priv->save_button, "clicked",
938 G_CALLBACK (debug_dialog_save_clicked_cb), object);
939 gtk_widget_show (GTK_WIDGET (priv->save_button));
940 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (priv->save_button), TRUE);
941 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->save_button, -1);
944 priv->copy_button = gtk_tool_button_new_from_stock (GTK_STOCK_COPY);
945 g_signal_connect (priv->copy_button, "clicked",
946 G_CALLBACK (debug_dialog_copy_clicked_cb), object);
947 gtk_widget_show (GTK_WIDGET (priv->copy_button));
948 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (priv->copy_button), TRUE);
949 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->copy_button, -1);
952 priv->clear_button = gtk_tool_button_new_from_stock (GTK_STOCK_CLEAR);
953 g_signal_connect (priv->clear_button, "clicked",
954 G_CALLBACK (debug_dialog_clear_clicked_cb), object);
955 gtk_widget_show (GTK_WIDGET (priv->clear_button));
956 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (priv->clear_button), TRUE);
957 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->clear_button, -1);
959 item = gtk_separator_tool_item_new ();
960 gtk_widget_show (GTK_WIDGET (item));
961 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
964 priv->paused = FALSE;
965 image = gtk_image_new_from_stock (GTK_STOCK_MEDIA_PAUSE,
967 gtk_widget_show (image);
968 priv->pause_button = gtk_toggle_tool_button_new ();
969 gtk_toggle_tool_button_set_active (
970 GTK_TOGGLE_TOOL_BUTTON (priv->pause_button), priv->paused);
971 g_signal_connect (priv->pause_button, "toggled",
972 G_CALLBACK (debug_dialog_pause_toggled_cb), object);
973 gtk_widget_show (GTK_WIDGET (priv->pause_button));
974 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (priv->pause_button), TRUE);
975 gtk_tool_button_set_label (GTK_TOOL_BUTTON (priv->pause_button), _("Pause"));
976 gtk_tool_button_set_icon_widget (
977 GTK_TOOL_BUTTON (priv->pause_button), image);
978 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), priv->pause_button, -1);
980 item = gtk_separator_tool_item_new ();
981 gtk_widget_show (GTK_WIDGET (item));
982 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
985 item = gtk_tool_item_new ();
986 gtk_widget_show (GTK_WIDGET (item));
987 label = gtk_label_new (_("Level "));
988 gtk_widget_show (label);
989 gtk_container_add (GTK_CONTAINER (item), label);
990 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
992 priv->level_filter = gtk_combo_box_new_text ();
993 gtk_widget_show (priv->level_filter);
995 item = gtk_tool_item_new ();
996 gtk_widget_show (GTK_WIDGET (item));
997 gtk_container_add (GTK_CONTAINER (item), priv->level_filter);
998 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
1000 level_store = gtk_list_store_new (NUM_COLS_LEVEL,
1001 G_TYPE_STRING, G_TYPE_UINT);
1002 gtk_combo_box_set_model (GTK_COMBO_BOX (priv->level_filter),
1003 GTK_TREE_MODEL (level_store));
1005 gtk_list_store_append (level_store, &iter);
1006 gtk_list_store_set (level_store, &iter,
1007 COL_LEVEL_NAME, _("Debug"),
1008 COL_LEVEL_VALUE, EMP_DEBUG_LEVEL_DEBUG,
1011 gtk_list_store_append (level_store, &iter);
1012 gtk_list_store_set (level_store, &iter,
1013 COL_LEVEL_NAME, _("Info"),
1014 COL_LEVEL_VALUE, EMP_DEBUG_LEVEL_INFO,
1017 gtk_list_store_append (level_store, &iter);
1018 gtk_list_store_set (level_store, &iter,
1019 COL_LEVEL_NAME, _("Message"),
1020 COL_LEVEL_VALUE, EMP_DEBUG_LEVEL_MESSAGE,
1023 gtk_list_store_append (level_store, &iter);
1024 gtk_list_store_set (level_store, &iter,
1025 COL_LEVEL_NAME, _("Warning"),
1026 COL_LEVEL_VALUE, EMP_DEBUG_LEVEL_WARNING,
1029 gtk_list_store_append (level_store, &iter);
1030 gtk_list_store_set (level_store, &iter,
1031 COL_LEVEL_NAME, _("Critical"),
1032 COL_LEVEL_VALUE, EMP_DEBUG_LEVEL_CRITICAL,
1035 gtk_list_store_append (level_store, &iter);
1036 gtk_list_store_set (level_store, &iter,
1037 COL_LEVEL_NAME, _("Error"),
1038 COL_LEVEL_VALUE, EMP_DEBUG_LEVEL_ERROR,
1041 gtk_combo_box_set_active (GTK_COMBO_BOX (priv->level_filter), 0);
1042 g_signal_connect (priv->level_filter, "changed",
1043 G_CALLBACK (debug_dialog_filter_changed_cb), object);
1045 /* Debug treeview */
1046 priv->view = gtk_tree_view_new ();
1047 gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (priv->view), TRUE);
1049 g_signal_connect (priv->view, "button-press-event",
1050 G_CALLBACK (debug_dialog_button_press_event_cb), object);
1052 renderer = gtk_cell_renderer_text_new ();
1053 g_object_set (renderer, "yalign", 0, NULL);
1055 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
1056 -1, _("Time"), renderer, "text", COL_DEBUG_TIMESTAMP, NULL);
1057 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
1058 -1, _("Domain"), renderer, "text", COL_DEBUG_DOMAIN, NULL);
1059 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
1060 -1, _("Category"), renderer, "text", COL_DEBUG_CATEGORY, NULL);
1061 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
1062 -1, _("Level"), renderer, "text", COL_DEBUG_LEVEL_STRING, NULL);
1064 renderer = gtk_cell_renderer_text_new ();
1065 g_object_set (renderer, "family", "Monospace", NULL);
1066 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
1067 -1, _("Message"), renderer, "text", COL_DEBUG_MESSAGE, NULL);
1069 priv->store = gtk_list_store_new (NUM_DEBUG_COLS, G_TYPE_DOUBLE,
1070 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
1073 priv->store_filter = gtk_tree_model_filter_new (
1074 GTK_TREE_MODEL (priv->store), NULL);
1076 gtk_tree_model_filter_set_visible_func (
1077 GTK_TREE_MODEL_FILTER (priv->store_filter),
1078 debug_dialog_visible_func, object, NULL);
1080 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->view), priv->store_filter);
1082 /* Scrolled window */
1083 scrolled_win = gtk_scrolled_window_new (NULL, NULL);
1084 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
1085 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1087 gtk_widget_show (priv->view);
1088 gtk_container_add (GTK_CONTAINER (scrolled_win), priv->view);
1090 gtk_widget_show (scrolled_win);
1091 gtk_box_pack_start (GTK_BOX (vbox), scrolled_win, TRUE, TRUE, 0);
1093 gtk_widget_show (GTK_WIDGET (object));
1099 empathy_debug_dialog_init (EmpathyDebugDialog *empathy_debug_dialog)
1101 EmpathyDebugDialogPriv *priv =
1102 G_TYPE_INSTANCE_GET_PRIVATE (empathy_debug_dialog,
1103 EMPATHY_TYPE_DEBUG_DIALOG, EmpathyDebugDialogPriv);
1105 empathy_debug_dialog->priv = priv;
1107 priv->dispose_run = FALSE;
1111 debug_dialog_set_property (GObject *object,
1113 const GValue *value,
1119 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1125 debug_dialog_get_property (GObject *object,
1133 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1139 debug_dialog_dispose (GObject *object)
1141 EmpathyDebugDialog *selector = EMPATHY_DEBUG_DIALOG (object);
1142 EmpathyDebugDialogPriv *priv = GET_PRIV (selector);
1144 if (priv->dispose_run)
1147 priv->dispose_run = TRUE;
1149 if (priv->store != NULL)
1150 g_object_unref (priv->store);
1152 if (priv->name_owner_changed_signal != NULL)
1153 tp_proxy_signal_connection_disconnect (priv->name_owner_changed_signal);
1155 if (priv->proxy != NULL)
1157 debug_dialog_set_enabled (EMPATHY_DEBUG_DIALOG (object), FALSE);
1158 g_object_unref (priv->proxy);
1161 if (priv->new_debug_message_signal != NULL)
1162 tp_proxy_signal_connection_disconnect (priv->new_debug_message_signal);
1164 if (priv->cms != NULL)
1165 g_object_unref (priv->cms);
1167 if (priv->dbus != NULL)
1168 g_object_unref (priv->dbus);
1170 (G_OBJECT_CLASS (empathy_debug_dialog_parent_class)->dispose) (object);
1174 empathy_debug_dialog_class_init (EmpathyDebugDialogClass *klass)
1176 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1177 object_class->constructor = debug_dialog_constructor;
1178 object_class->dispose = debug_dialog_dispose;
1179 object_class->set_property = debug_dialog_set_property;
1180 object_class->get_property = debug_dialog_get_property;
1181 g_type_class_add_private (klass, sizeof (EmpathyDebugDialogPriv));
1184 /* public methods */
1187 empathy_debug_dialog_new (GtkWindow *parent)
1189 g_return_val_if_fail (GTK_IS_WINDOW (parent), NULL);
1191 return GTK_WIDGET (g_object_new (EMPATHY_TYPE_DEBUG_DIALOG,
1192 "transient-for", parent, NULL));