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,
59 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyDebugDialog)
65 GtkWidget *cm_chooser;
68 TpProxySignalConnection *signal_connection;
72 } EmpathyDebugDialogPriv;
75 log_level_to_string (guint level)
79 case EMP_DEBUG_LEVEL_ERROR:
82 case EMP_DEBUG_LEVEL_CRITICAL:
85 case EMP_DEBUG_LEVEL_WARNING:
88 case EMP_DEBUG_LEVEL_MESSAGE:
91 case EMP_DEBUG_LEVEL_INFO:
94 case EMP_DEBUG_LEVEL_DEBUG:
98 g_assert_not_reached ();
104 debug_dialog_add_message (EmpathyDebugDialog *debug_dialog,
106 const gchar *domain_category,
108 const gchar *message)
110 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
111 gchar *domain, *category;
114 if (g_strrstr (domain_category, "/"))
116 gchar **parts = g_strsplit (domain_category, "/", 2);
117 domain = g_strdup (parts[0]);
118 category = g_strdup (parts[1]);
123 domain = g_strdup (domain_category);
124 category = g_strdup ("");
127 gtk_list_store_append (priv->store, &iter);
128 gtk_list_store_set (priv->store, &iter,
129 COL_TIMESTAMP, timestamp,
131 COL_CATEGORY, category,
132 COL_LEVEL, log_level_to_string (level),
133 COL_MESSAGE, message,
141 debug_dialog_new_debug_message_cb (TpProxy *proxy,
145 const gchar *message,
147 GObject *weak_object)
149 EmpathyDebugDialog *debug_dialog = (EmpathyDebugDialog *) user_data;
151 debug_dialog_add_message (debug_dialog, timestamp, domain, level,
156 debug_dialog_set_enabled (EmpathyDebugDialog *debug_dialog,
159 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
162 val = tp_g_value_slice_new_boolean (enabled);
164 tp_cli_dbus_properties_call_set (priv->proxy, -1, EMP_IFACE_DEBUG,
165 "Enabled", val, NULL, NULL, NULL, NULL);
167 tp_g_value_slice_free (val);
171 debug_dialog_get_messages_cb (TpProxy *proxy,
172 const GPtrArray *messages,
175 GObject *weak_object)
177 EmpathyDebugDialog *debug_dialog = (EmpathyDebugDialog *) user_data;
178 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
183 DEBUG ("GetMessages failed: %s", error->message);
187 for (i = 0; i < messages->len; i++)
189 GValueArray *values = g_ptr_array_index (messages, i);
191 debug_dialog_add_message (debug_dialog,
192 g_value_get_double (g_value_array_get_nth (values, 0)),
193 g_value_get_string (g_value_array_get_nth (values, 1)),
194 g_value_get_uint (g_value_array_get_nth (values, 2)),
195 g_value_get_string (g_value_array_get_nth (values, 3)));
198 /* Connect to NewDebugMessage */
199 priv->signal_connection = emp_cli_debug_connect_to_new_debug_message (
200 proxy, debug_dialog_new_debug_message_cb, debug_dialog,
203 /* Set Enabled as appropriate */
204 debug_dialog_set_enabled (debug_dialog, !priv->paused);
208 debug_dialog_cm_chooser_changed_cb (GtkComboBox *cm_chooser,
209 EmpathyDebugDialog *debug_dialog)
211 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
214 GError *error = NULL;
215 const gchar *bus_name;
216 TpConnection *connection;
218 if (gtk_combo_box_get_active (cm_chooser) == -1)
220 DEBUG ("No CM is selected");
224 mc = empathy_mission_control_dup_singleton ();
225 dbus = tp_dbus_daemon_dup (&error);
229 DEBUG ("Failed at duping the dbus daemon: %s", error->message);
233 bus_name = g_list_nth_data (priv->bus_names, gtk_combo_box_get_active (cm_chooser));
234 connection = tp_connection_new (dbus, bus_name, DEBUG_OBJECT_PATH, &error);
238 DEBUG ("Getting a new TpConnection failed: %s", error->message);
239 g_error_free (error);
240 g_object_unref (dbus);
245 /* Disable debug signalling */
246 if (priv->proxy != NULL)
247 debug_dialog_set_enabled (debug_dialog, FALSE);
249 /* Disconnect from previous NewDebugMessage signal */
250 if (priv->signal_connection)
252 tp_proxy_signal_connection_disconnect (priv->signal_connection);
253 priv->signal_connection = NULL;
257 g_object_unref (priv->proxy);
259 priv->proxy = TP_PROXY (connection);
261 tp_proxy_add_interface_by_id (priv->proxy, emp_iface_quark_debug ());
263 emp_cli_debug_call_get_messages (priv->proxy, -1,
264 debug_dialog_get_messages_cb, debug_dialog, NULL, NULL);
266 g_object_unref (dbus);
271 debug_dialog_list_connection_names_cb (const gchar * const *names,
273 const gchar * const *cms,
274 const gchar * const *protocols,
277 GObject *weak_object)
279 EmpathyDebugDialog *debug_dialog = (EmpathyDebugDialog *) user_data;
280 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
285 DEBUG ("list_connection_names failed: %s", error->message);
289 for (i = 0; cms[i] != NULL; i++)
290 gtk_combo_box_append_text (GTK_COMBO_BOX (priv->cm_chooser), cms[i]);
292 for (i = 0; names[i] != NULL; i++)
293 priv->bus_names = g_list_append (priv->bus_names, g_strdup (names[i]));
295 gtk_combo_box_set_active (GTK_COMBO_BOX (priv->cm_chooser), 0);
298 debug_dialog_cm_chooser_changed_cb (GTK_COMBO_BOX (priv->cm_chooser), debug_dialog);
302 debug_dialog_fill_cm_chooser (EmpathyDebugDialog *debug_dialog)
305 GError *error = NULL;
307 dbus = tp_dbus_daemon_dup (&error);
311 DEBUG ("Failed to dup dbus daemon: %s", error->message);
312 g_error_free (error);
316 tp_list_connection_names (dbus, debug_dialog_list_connection_names_cb,
317 debug_dialog, NULL, NULL);
319 g_object_unref (dbus);
323 debug_dialog_pause_toggled_cb (GtkToggleToolButton *pause,
324 EmpathyDebugDialog *debug_dialog)
326 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
328 priv->paused = gtk_toggle_tool_button_get_active (pause);
330 debug_dialog_set_enabled (debug_dialog, !priv->paused);
334 debug_dialog_constructor (GType type,
335 guint n_construct_params,
336 GObjectConstructParam *construct_params)
339 EmpathyDebugDialogPriv *priv;
345 GtkCellRenderer *renderer;
346 GtkWidget *scrolled_win;
348 object = G_OBJECT_CLASS (empathy_debug_dialog_parent_class)->constructor
349 (type, n_construct_params, construct_params);
350 priv = GET_PRIV (object);
352 gtk_window_set_title (GTK_WINDOW (object), _("Debug Window"));
353 gtk_window_set_default_size (GTK_WINDOW (object), 800, 400);
354 gtk_window_set_transient_for (GTK_WINDOW (object), priv->parent);
356 vbox = GTK_DIALOG (object)->vbox;
358 toolbar = gtk_toolbar_new ();
359 gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_BOTH_HORIZ);
360 gtk_toolbar_set_show_arrow (GTK_TOOLBAR (toolbar), TRUE);
361 gtk_toolbar_set_icon_size (GTK_TOOLBAR (toolbar), GTK_ICON_SIZE_SMALL_TOOLBAR);
362 gtk_widget_show (toolbar);
364 gtk_box_pack_start (GTK_BOX (vbox), toolbar, FALSE, FALSE, 0);
367 priv->cm_chooser = gtk_combo_box_new_text ();
368 gtk_widget_show (priv->cm_chooser);
370 item = gtk_tool_item_new ();
371 gtk_widget_show (GTK_WIDGET (item));
372 gtk_container_add (GTK_CONTAINER (item), priv->cm_chooser);
373 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
374 debug_dialog_fill_cm_chooser (EMPATHY_DEBUG_DIALOG (object));
375 g_signal_connect (priv->cm_chooser, "changed",
376 G_CALLBACK (debug_dialog_cm_chooser_changed_cb), object);
377 gtk_widget_show (GTK_WIDGET (priv->cm_chooser));
379 item = gtk_separator_tool_item_new ();
380 gtk_widget_show (GTK_WIDGET (item));
381 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
384 item = gtk_tool_button_new_from_stock (GTK_STOCK_SAVE);
385 gtk_widget_show (GTK_WIDGET (item));
386 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (item), TRUE);
387 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
390 item = gtk_tool_button_new_from_stock (GTK_STOCK_CLEAR);
391 gtk_widget_show (GTK_WIDGET (item));
392 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (item), TRUE);
393 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
395 item = gtk_separator_tool_item_new ();
396 gtk_widget_show (GTK_WIDGET (item));
397 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
400 priv->paused = FALSE;
401 image = gtk_image_new_from_stock (GTK_STOCK_MEDIA_PAUSE, GTK_ICON_SIZE_MENU);
402 gtk_widget_show (image);
403 item = gtk_toggle_tool_button_new ();
404 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (item), priv->paused);
405 g_signal_connect (item, "toggled", G_CALLBACK (debug_dialog_pause_toggled_cb),
407 gtk_widget_show (GTK_WIDGET (item));
408 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (item), TRUE);
409 gtk_tool_button_set_label (GTK_TOOL_BUTTON (item), _("Pause"));
410 gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (item), image);
411 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
413 item = gtk_separator_tool_item_new ();
414 gtk_widget_show (GTK_WIDGET (item));
415 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
418 item = gtk_tool_item_new ();
419 gtk_widget_show (GTK_WIDGET (item));
420 label = gtk_label_new (_("Level "));
421 gtk_widget_show (label);
422 gtk_container_add (GTK_CONTAINER (item), label);
423 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
425 priv->filter = gtk_combo_box_new_text ();
426 gtk_widget_show (priv->filter);
428 item = gtk_tool_item_new ();
429 gtk_widget_show (GTK_WIDGET (item));
430 gtk_container_add (GTK_CONTAINER (item), priv->filter);
431 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
433 gtk_combo_box_append_text (GTK_COMBO_BOX (priv->filter), _("All"));
434 gtk_combo_box_append_text (GTK_COMBO_BOX (priv->filter), _("Debug"));
435 gtk_combo_box_append_text (GTK_COMBO_BOX (priv->filter), _("Info"));
436 gtk_combo_box_append_text (GTK_COMBO_BOX (priv->filter), _("Message"));
437 gtk_combo_box_append_text (GTK_COMBO_BOX (priv->filter), _("Warning"));
438 gtk_combo_box_append_text (GTK_COMBO_BOX (priv->filter), _("Critical"));
439 gtk_combo_box_append_text (GTK_COMBO_BOX (priv->filter), _("Error"));
441 gtk_combo_box_set_active (GTK_COMBO_BOX (priv->filter), 0);
442 gtk_widget_show (GTK_WIDGET (priv->filter));
445 priv->view = gtk_tree_view_new ();
446 gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (priv->view), TRUE);
448 renderer = gtk_cell_renderer_text_new ();
450 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
451 -1, _("Time"), renderer, "text", COL_TIMESTAMP, NULL);
452 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
453 -1, _("Domain"), renderer, "text", COL_DOMAIN, NULL);
454 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
455 -1, _("Category"), renderer, "text", COL_CATEGORY, NULL);
456 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
457 -1, _("Level"), renderer, "text", COL_LEVEL, NULL);
458 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
459 -1, _("Message"), renderer, "text", COL_MESSAGE, NULL);
461 priv->store = gtk_list_store_new (NUM_COLS, G_TYPE_DOUBLE,
462 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
463 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->view),
464 GTK_TREE_MODEL (priv->store));
466 /* Scrolled window */
467 scrolled_win = gtk_scrolled_window_new (NULL, NULL);
468 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
469 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
471 gtk_widget_show (priv->view);
472 gtk_container_add (GTK_CONTAINER (scrolled_win), priv->view);
474 gtk_widget_show (scrolled_win);
475 gtk_box_pack_start (GTK_BOX (vbox), scrolled_win, TRUE, TRUE, 0);
477 gtk_widget_show (GTK_WIDGET (object));
483 empathy_debug_dialog_init (EmpathyDebugDialog *empathy_debug_dialog)
485 EmpathyDebugDialogPriv *priv =
486 G_TYPE_INSTANCE_GET_PRIVATE (empathy_debug_dialog,
487 EMPATHY_TYPE_DEBUG_DIALOG, EmpathyDebugDialogPriv);
489 empathy_debug_dialog->priv = priv;
491 priv->dispose_run = FALSE;
495 debug_dialog_set_property (GObject *object,
500 EmpathyDebugDialogPriv *priv = GET_PRIV (object);
505 priv->parent = GTK_WINDOW (g_value_dup_object (value));
508 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
514 debug_dialog_get_property (GObject *object,
519 EmpathyDebugDialogPriv *priv = GET_PRIV (object);
524 g_value_set_object (value, priv->parent);
527 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
533 debug_dialog_dispose (GObject *object)
535 EmpathyDebugDialog *selector = EMPATHY_DEBUG_DIALOG (object);
536 EmpathyDebugDialogPriv *priv = GET_PRIV (selector);
538 if (priv->dispose_run)
541 priv->dispose_run = TRUE;
544 g_object_unref (priv->parent);
547 g_object_unref (priv->store);
551 debug_dialog_set_enabled (EMPATHY_DEBUG_DIALOG (object), FALSE);
552 g_object_unref (priv->proxy);
555 if (priv->signal_connection)
556 tp_proxy_signal_connection_disconnect (priv->signal_connection);
560 g_list_foreach (priv->bus_names, (GFunc) g_free, NULL);
561 g_list_free (priv->bus_names);
564 (G_OBJECT_CLASS (empathy_debug_dialog_parent_class)->dispose) (object);
568 empathy_debug_dialog_class_init (EmpathyDebugDialogClass *klass)
570 GObjectClass *object_class = G_OBJECT_CLASS (klass);
571 object_class->constructor = debug_dialog_constructor;
572 object_class->dispose = debug_dialog_dispose;
573 object_class->set_property = debug_dialog_set_property;
574 object_class->get_property = debug_dialog_get_property;
575 g_type_class_add_private (klass, sizeof (EmpathyDebugDialogPriv));
577 g_object_class_install_property (object_class, PROP_PARENT,
578 g_param_spec_object ("parent", "parent", "parent",
579 GTK_TYPE_WINDOW, G_PARAM_CONSTRUCT_ONLY |
580 G_PARAM_READWRITE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
586 empathy_debug_dialog_new (GtkWindow *parent)
588 g_return_val_if_fail (GTK_IS_WINDOW (parent), NULL);
590 return GTK_WIDGET (g_object_new (EMPATHY_TYPE_DEBUG_DIALOG,
591 "parent", parent, NULL));