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>
26 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
27 #include <libempathy/empathy-debug.h>
28 #include <libempathy/empathy-utils.h>
30 #include <libempathy-gtk/empathy-account-chooser.h>
32 #include <telepathy-glib/dbus.h>
33 #include <telepathy-glib/util.h>
34 #include <telepathy-glib/proxy-subclass.h>
36 #include "extensions/extensions.h"
38 #include "empathy-debug-dialog.h"
40 G_DEFINE_TYPE (EmpathyDebugDialog, empathy_debug_dialog,
66 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyDebugDialog)
72 GtkWidget *cm_chooser;
75 TpProxySignalConnection *signal_connection;
79 } EmpathyDebugDialogPriv;
82 log_level_to_string (guint level)
86 case EMP_DEBUG_LEVEL_ERROR:
89 case EMP_DEBUG_LEVEL_CRITICAL:
92 case EMP_DEBUG_LEVEL_WARNING:
95 case EMP_DEBUG_LEVEL_MESSAGE:
98 case EMP_DEBUG_LEVEL_INFO:
101 case EMP_DEBUG_LEVEL_DEBUG:
105 g_assert_not_reached ();
111 debug_dialog_add_message (EmpathyDebugDialog *debug_dialog,
113 const gchar *domain_category,
115 const gchar *message)
117 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
118 gchar *domain, *category;
121 if (g_strrstr (domain_category, "/"))
123 gchar **parts = g_strsplit (domain_category, "/", 2);
124 domain = g_strdup (parts[0]);
125 category = g_strdup (parts[1]);
130 domain = g_strdup (domain_category);
131 category = g_strdup ("");
134 gtk_list_store_append (priv->store, &iter);
135 gtk_list_store_set (priv->store, &iter,
136 COL_TIMESTAMP, timestamp,
138 COL_CATEGORY, category,
139 COL_LEVEL, log_level_to_string (level),
140 COL_MESSAGE, message,
148 debug_dialog_new_debug_message_cb (TpProxy *proxy,
152 const gchar *message,
154 GObject *weak_object)
156 EmpathyDebugDialog *debug_dialog = (EmpathyDebugDialog *) user_data;
158 debug_dialog_add_message (debug_dialog, timestamp, domain, level,
163 debug_dialog_set_enabled (EmpathyDebugDialog *debug_dialog,
166 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
169 val = tp_g_value_slice_new_boolean (enabled);
171 tp_cli_dbus_properties_call_set (priv->proxy, -1, EMP_IFACE_DEBUG,
172 "Enabled", val, NULL, NULL, NULL, NULL);
174 tp_g_value_slice_free (val);
178 debug_dialog_get_messages_cb (TpProxy *proxy,
179 const GPtrArray *messages,
182 GObject *weak_object)
184 EmpathyDebugDialog *debug_dialog = (EmpathyDebugDialog *) user_data;
185 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
190 DEBUG ("GetMessages failed: %s", error->message);
194 for (i = 0; i < messages->len; i++)
196 GValueArray *values = g_ptr_array_index (messages, i);
198 debug_dialog_add_message (debug_dialog,
199 g_value_get_double (g_value_array_get_nth (values, 0)),
200 g_value_get_string (g_value_array_get_nth (values, 1)),
201 g_value_get_uint (g_value_array_get_nth (values, 2)),
202 g_value_get_string (g_value_array_get_nth (values, 3)));
205 /* Connect to NewDebugMessage */
206 priv->signal_connection = emp_cli_debug_connect_to_new_debug_message (
207 proxy, debug_dialog_new_debug_message_cb, debug_dialog,
210 /* Set Enabled as appropriate */
211 debug_dialog_set_enabled (debug_dialog, !priv->paused);
215 debug_dialog_cm_chooser_changed_cb (GtkComboBox *cm_chooser,
216 EmpathyDebugDialog *debug_dialog)
218 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
221 GError *error = NULL;
223 TpConnection *connection;
226 if (!gtk_combo_box_get_active_iter (cm_chooser, &iter))
228 DEBUG ("No CM is selected");
232 mc = empathy_mission_control_dup_singleton ();
233 dbus = tp_dbus_daemon_dup (&error);
237 DEBUG ("Failed at duping the dbus daemon: %s", error->message);
241 gtk_tree_model_get (GTK_TREE_MODEL (priv->cms), &iter,
242 COL_CM_BUS, &bus_name, -1);
243 connection = tp_connection_new (dbus, bus_name, DEBUG_OBJECT_PATH, &error);
248 DEBUG ("Getting a new TpConnection failed: %s", error->message);
249 g_error_free (error);
250 g_object_unref (dbus);
255 /* Disable debug signalling */
256 if (priv->proxy != NULL)
257 debug_dialog_set_enabled (debug_dialog, FALSE);
259 /* Disconnect from previous NewDebugMessage signal */
260 if (priv->signal_connection)
262 tp_proxy_signal_connection_disconnect (priv->signal_connection);
263 priv->signal_connection = NULL;
267 g_object_unref (priv->proxy);
269 priv->proxy = TP_PROXY (connection);
271 tp_proxy_add_interface_by_id (priv->proxy, emp_iface_quark_debug ());
273 emp_cli_debug_call_get_messages (priv->proxy, -1,
274 debug_dialog_get_messages_cb, debug_dialog, NULL, NULL);
276 g_object_unref (dbus);
281 debug_dialog_list_connection_names_cb (const gchar * const *names,
283 const gchar * const *cms,
284 const gchar * const *protocols,
287 GObject *weak_object)
289 EmpathyDebugDialog *debug_dialog = (EmpathyDebugDialog *) user_data;
290 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
295 DEBUG ("list_connection_names failed: %s", error->message);
299 for (i = 0; cms[i] != NULL; i++)
302 gtk_list_store_append (priv->cms, &iter);
303 gtk_list_store_set (priv->cms, &iter,
305 COL_CM_BUS, names[i],
309 gtk_combo_box_set_active (GTK_COMBO_BOX (priv->cm_chooser), 0);
312 debug_dialog_cm_chooser_changed_cb (GTK_COMBO_BOX (priv->cm_chooser), debug_dialog);
316 debug_dialog_fill_cm_chooser (EmpathyDebugDialog *debug_dialog)
319 GError *error = NULL;
321 dbus = tp_dbus_daemon_dup (&error);
325 DEBUG ("Failed to dup dbus daemon: %s", error->message);
326 g_error_free (error);
330 tp_list_connection_names (dbus, debug_dialog_list_connection_names_cb,
331 debug_dialog, NULL, NULL);
333 g_object_unref (dbus);
337 debug_dialog_pause_toggled_cb (GtkToggleToolButton *pause,
338 EmpathyDebugDialog *debug_dialog)
340 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
342 priv->paused = gtk_toggle_tool_button_get_active (pause);
344 debug_dialog_set_enabled (debug_dialog, !priv->paused);
348 debug_dialog_constructor (GType type,
349 guint n_construct_params,
350 GObjectConstructParam *construct_params)
353 EmpathyDebugDialogPriv *priv;
359 GtkCellRenderer *renderer;
360 GtkWidget *scrolled_win;
362 object = G_OBJECT_CLASS (empathy_debug_dialog_parent_class)->constructor
363 (type, n_construct_params, construct_params);
364 priv = GET_PRIV (object);
366 gtk_window_set_title (GTK_WINDOW (object), _("Debug Window"));
367 gtk_window_set_default_size (GTK_WINDOW (object), 800, 400);
368 gtk_window_set_transient_for (GTK_WINDOW (object), priv->parent);
370 vbox = GTK_DIALOG (object)->vbox;
372 toolbar = gtk_toolbar_new ();
373 gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_BOTH_HORIZ);
374 gtk_toolbar_set_show_arrow (GTK_TOOLBAR (toolbar), TRUE);
375 gtk_toolbar_set_icon_size (GTK_TOOLBAR (toolbar), GTK_ICON_SIZE_SMALL_TOOLBAR);
376 gtk_widget_show (toolbar);
378 gtk_box_pack_start (GTK_BOX (vbox), toolbar, FALSE, FALSE, 0);
381 priv->cm_chooser = gtk_combo_box_new_text ();
382 priv->cms = gtk_list_store_new (NUM_COLS_CM, G_TYPE_STRING, G_TYPE_STRING);
383 gtk_combo_box_set_model (GTK_COMBO_BOX (priv->cm_chooser),
384 GTK_TREE_MODEL (priv->cms));
385 gtk_widget_show (priv->cm_chooser);
387 item = gtk_tool_item_new ();
388 gtk_widget_show (GTK_WIDGET (item));
389 gtk_container_add (GTK_CONTAINER (item), priv->cm_chooser);
390 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
391 debug_dialog_fill_cm_chooser (EMPATHY_DEBUG_DIALOG (object));
392 g_signal_connect (priv->cm_chooser, "changed",
393 G_CALLBACK (debug_dialog_cm_chooser_changed_cb), object);
394 gtk_widget_show (GTK_WIDGET (priv->cm_chooser));
396 item = gtk_separator_tool_item_new ();
397 gtk_widget_show (GTK_WIDGET (item));
398 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
401 item = gtk_tool_button_new_from_stock (GTK_STOCK_SAVE);
402 gtk_widget_show (GTK_WIDGET (item));
403 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (item), TRUE);
404 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
407 item = gtk_tool_button_new_from_stock (GTK_STOCK_CLEAR);
408 gtk_widget_show (GTK_WIDGET (item));
409 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (item), TRUE);
410 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
412 item = gtk_separator_tool_item_new ();
413 gtk_widget_show (GTK_WIDGET (item));
414 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
417 priv->paused = FALSE;
418 image = gtk_image_new_from_stock (GTK_STOCK_MEDIA_PAUSE, GTK_ICON_SIZE_MENU);
419 gtk_widget_show (image);
420 item = gtk_toggle_tool_button_new ();
421 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (item), priv->paused);
422 g_signal_connect (item, "toggled", G_CALLBACK (debug_dialog_pause_toggled_cb),
424 gtk_widget_show (GTK_WIDGET (item));
425 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (item), TRUE);
426 gtk_tool_button_set_label (GTK_TOOL_BUTTON (item), _("Pause"));
427 gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (item), image);
428 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
430 item = gtk_separator_tool_item_new ();
431 gtk_widget_show (GTK_WIDGET (item));
432 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
435 item = gtk_tool_item_new ();
436 gtk_widget_show (GTK_WIDGET (item));
437 label = gtk_label_new (_("Level "));
438 gtk_widget_show (label);
439 gtk_container_add (GTK_CONTAINER (item), label);
440 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
442 priv->filter = gtk_combo_box_new_text ();
443 gtk_widget_show (priv->filter);
445 item = gtk_tool_item_new ();
446 gtk_widget_show (GTK_WIDGET (item));
447 gtk_container_add (GTK_CONTAINER (item), priv->filter);
448 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
450 gtk_combo_box_append_text (GTK_COMBO_BOX (priv->filter), _("All"));
451 gtk_combo_box_append_text (GTK_COMBO_BOX (priv->filter), _("Debug"));
452 gtk_combo_box_append_text (GTK_COMBO_BOX (priv->filter), _("Info"));
453 gtk_combo_box_append_text (GTK_COMBO_BOX (priv->filter), _("Message"));
454 gtk_combo_box_append_text (GTK_COMBO_BOX (priv->filter), _("Warning"));
455 gtk_combo_box_append_text (GTK_COMBO_BOX (priv->filter), _("Critical"));
456 gtk_combo_box_append_text (GTK_COMBO_BOX (priv->filter), _("Error"));
458 gtk_combo_box_set_active (GTK_COMBO_BOX (priv->filter), 0);
459 gtk_widget_show (GTK_WIDGET (priv->filter));
462 priv->view = gtk_tree_view_new ();
463 gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (priv->view), TRUE);
465 renderer = gtk_cell_renderer_text_new ();
467 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
468 -1, _("Time"), renderer, "text", COL_TIMESTAMP, NULL);
469 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
470 -1, _("Domain"), renderer, "text", COL_DOMAIN, NULL);
471 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
472 -1, _("Category"), renderer, "text", COL_CATEGORY, NULL);
473 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
474 -1, _("Level"), renderer, "text", COL_LEVEL, NULL);
475 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
476 -1, _("Message"), renderer, "text", COL_MESSAGE, NULL);
478 priv->store = gtk_list_store_new (NUM_COLS, G_TYPE_DOUBLE,
479 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
480 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->view),
481 GTK_TREE_MODEL (priv->store));
483 /* Scrolled window */
484 scrolled_win = gtk_scrolled_window_new (NULL, NULL);
485 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
486 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
488 gtk_widget_show (priv->view);
489 gtk_container_add (GTK_CONTAINER (scrolled_win), priv->view);
491 gtk_widget_show (scrolled_win);
492 gtk_box_pack_start (GTK_BOX (vbox), scrolled_win, TRUE, TRUE, 0);
494 gtk_widget_show (GTK_WIDGET (object));
500 empathy_debug_dialog_init (EmpathyDebugDialog *empathy_debug_dialog)
502 EmpathyDebugDialogPriv *priv =
503 G_TYPE_INSTANCE_GET_PRIVATE (empathy_debug_dialog,
504 EMPATHY_TYPE_DEBUG_DIALOG, EmpathyDebugDialogPriv);
506 empathy_debug_dialog->priv = priv;
508 priv->dispose_run = FALSE;
512 debug_dialog_set_property (GObject *object,
517 EmpathyDebugDialogPriv *priv = GET_PRIV (object);
522 priv->parent = GTK_WINDOW (g_value_dup_object (value));
525 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
531 debug_dialog_get_property (GObject *object,
536 EmpathyDebugDialogPriv *priv = GET_PRIV (object);
541 g_value_set_object (value, priv->parent);
544 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
550 debug_dialog_dispose (GObject *object)
552 EmpathyDebugDialog *selector = EMPATHY_DEBUG_DIALOG (object);
553 EmpathyDebugDialogPriv *priv = GET_PRIV (selector);
555 if (priv->dispose_run)
558 priv->dispose_run = TRUE;
561 g_object_unref (priv->parent);
564 g_object_unref (priv->store);
568 debug_dialog_set_enabled (EMPATHY_DEBUG_DIALOG (object), FALSE);
569 g_object_unref (priv->proxy);
572 if (priv->signal_connection)
573 tp_proxy_signal_connection_disconnect (priv->signal_connection);
576 g_object_unref (priv->cms);
578 (G_OBJECT_CLASS (empathy_debug_dialog_parent_class)->dispose) (object);
582 empathy_debug_dialog_class_init (EmpathyDebugDialogClass *klass)
584 GObjectClass *object_class = G_OBJECT_CLASS (klass);
585 object_class->constructor = debug_dialog_constructor;
586 object_class->dispose = debug_dialog_dispose;
587 object_class->set_property = debug_dialog_set_property;
588 object_class->get_property = debug_dialog_get_property;
589 g_type_class_add_private (klass, sizeof (EmpathyDebugDialogPriv));
591 g_object_class_install_property (object_class, PROP_PARENT,
592 g_param_spec_object ("parent", "parent", "parent",
593 GTK_TYPE_WINDOW, G_PARAM_CONSTRUCT_ONLY |
594 G_PARAM_READWRITE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
600 empathy_debug_dialog_new (GtkWindow *parent)
602 g_return_val_if_fail (GTK_IS_WINDOW (parent), NULL);
604 return GTK_WIDGET (g_object_new (EMPATHY_TYPE_DEBUG_DIALOG,
605 "parent", parent, NULL));