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>
35 #include "extensions/extensions.h"
37 #include "empathy-debug-dialog.h"
39 G_DEFINE_TYPE (EmpathyDebugDialog, empathy_debug_dialog,
58 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyDebugDialog)
64 GtkWidget *account_chooser;
67 TpProxySignalConnection *signal_connection;
70 } EmpathyDebugDialogPriv;
73 log_level_to_string (guint level)
77 case EMP_DEBUG_LEVEL_ERROR:
80 case EMP_DEBUG_LEVEL_CRITICAL:
83 case EMP_DEBUG_LEVEL_WARNING:
86 case EMP_DEBUG_LEVEL_MESSAGE:
89 case EMP_DEBUG_LEVEL_INFO:
92 case EMP_DEBUG_LEVEL_DEBUG:
96 g_assert_not_reached ();
102 debug_dialog_add_message (EmpathyDebugDialog *debug_dialog,
104 const gchar *domain_category,
106 const gchar *message)
108 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
109 gchar *domain, *category;
112 if (g_strrstr (domain_category, "/"))
114 gchar **parts = g_strsplit (domain_category, "/", 2);
115 domain = g_strdup (parts[0]);
116 category = g_strdup (parts[1]);
121 domain = g_strdup (domain_category);
125 gtk_list_store_append (priv->store, &iter);
126 gtk_list_store_set (priv->store, &iter,
127 COL_TIMESTAMP, timestamp,
129 COL_CATEGORY, category,
130 COL_LEVEL, log_level_to_string (level),
131 COL_MESSAGE, message,
139 debug_dialog_new_debug_message_cb (TpProxy *proxy,
143 const gchar *message,
145 GObject *weak_object)
147 EmpathyDebugDialog *debug_dialog = (EmpathyDebugDialog *) user_data;
149 debug_dialog_add_message (debug_dialog, timestamp, domain, level,
154 debug_dialog_set_enabled (EmpathyDebugDialog *debug_dialog,
157 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
160 val = tp_g_value_slice_new_boolean (enabled);
162 tp_cli_dbus_properties_call_set (priv->proxy, -1, EMP_IFACE_DEBUG,
163 "Enabled", val, NULL, NULL, NULL, NULL);
165 tp_g_value_slice_free (val);
169 debug_dialog_get_messages_cb (TpProxy *proxy,
170 const GPtrArray *messages,
173 GObject *weak_object)
175 EmpathyDebugDialog *debug_dialog = (EmpathyDebugDialog *) user_data;
176 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
181 DEBUG ("GetMessages failed: %s", error->message);
185 for (i = 0; i < messages->len; i++)
187 GValueArray *values = g_ptr_array_index (messages, i);
189 debug_dialog_add_message (debug_dialog,
190 g_value_get_double (g_value_array_get_nth (values, 0)),
191 g_value_get_string (g_value_array_get_nth (values, 1)),
192 g_value_get_uint (g_value_array_get_nth (values, 2)),
193 g_value_get_string (g_value_array_get_nth (values, 3)));
196 /* Connect to NewDebugMessage */
197 priv->signal_connection = emp_cli_debug_connect_to_new_debug_message (
198 proxy, debug_dialog_new_debug_message_cb, debug_dialog,
201 /* Set Enabled as appropriate */
202 debug_dialog_set_enabled (debug_dialog, !priv->paused);
206 debug_dialog_account_chooser_changed_cb (GtkComboBox *account_chooser,
207 EmpathyDebugDialog *debug_dialog)
209 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
211 TpConnection *connection;
214 GError *error = NULL;
216 mc = empathy_mission_control_dup_singleton ();
217 account = empathy_account_chooser_get_account (EMPATHY_ACCOUNT_CHOOSER (account_chooser));
218 connection = mission_control_get_tpconnection (mc, account, &error);
222 DEBUG ("Getting the account's TpConnection failed: %s", error->message);
223 g_error_free (error);
227 dbus = g_object_ref (tp_proxy_get_dbus_daemon (connection));
229 /* TODO: Fix this. */
230 connection = tp_connection_new (dbus,
231 "org.freedesktop.Telepathy.ConnectionManager.gabble",
232 "/org/freedesktop/Telepathy/debug",
237 DEBUG ("Getting a new TpConnection failed: %s", error->message);
238 g_error_free (error);
239 g_object_unref (dbus);
243 /* Disable debug signalling */
244 debug_dialog_set_enabled (debug_dialog, FALSE);
246 /* Disconnect from previous NewDebugMessage signal */
247 if (priv->signal_connection)
249 tp_proxy_signal_connection_disconnect (priv->signal_connection);
250 priv->signal_connection = NULL;
254 g_object_unref (priv->proxy);
256 priv->proxy = TP_PROXY (g_object_ref (connection));
258 emp_cli_debug_call_get_messages (priv->proxy, -1,
259 debug_dialog_get_messages_cb, debug_dialog, NULL, NULL);
261 g_object_unref (connection);
262 g_object_unref (account);
263 g_object_unref (dbus);
267 debug_dialog_pause_toggled_cb (GtkToggleToolButton *pause,
268 EmpathyDebugDialog *debug_dialog)
270 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
272 priv->paused = gtk_toggle_tool_button_get_active (pause);
274 debug_dialog_set_enabled (debug_dialog, !priv->paused);
278 debug_dialog_constructor (GType type,
279 guint n_construct_params,
280 GObjectConstructParam *construct_params)
283 EmpathyDebugDialogPriv *priv;
288 GtkCellRenderer *renderer;
289 GtkWidget *scrolled_win;
291 object = G_OBJECT_CLASS (empathy_debug_dialog_parent_class)->constructor
292 (type, n_construct_params, construct_params);
293 priv = GET_PRIV (object);
295 gtk_window_set_title (GTK_WINDOW (object), _("Debug Window"));
296 gtk_window_set_default_size (GTK_WINDOW (object), 800, 400);
297 gtk_window_set_transient_for (GTK_WINDOW (object), priv->parent);
299 vbox = GTK_DIALOG (object)->vbox;
301 toolbar = gtk_toolbar_new ();
302 gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_BOTH_HORIZ);
303 gtk_toolbar_set_show_arrow (GTK_TOOLBAR (toolbar), TRUE);
304 gtk_toolbar_set_icon_size (GTK_TOOLBAR (toolbar), GTK_ICON_SIZE_SMALL_TOOLBAR);
305 gtk_widget_show (toolbar);
307 gtk_box_pack_start (GTK_BOX (vbox), toolbar, FALSE, FALSE, 0);
310 item = gtk_tool_item_new ();
311 gtk_widget_show (GTK_WIDGET (item));
312 gtk_container_add (GTK_CONTAINER (item), gtk_label_new (_("Account ")));
313 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
315 priv->account_chooser = empathy_account_chooser_new ();
316 empathy_account_chooser_set_filter (EMPATHY_ACCOUNT_CHOOSER (priv->account_chooser),
317 (EmpathyAccountChooserFilterFunc) mc_account_is_enabled, NULL);
318 g_signal_connect (priv->account_chooser, "changed",
319 G_CALLBACK (debug_dialog_account_chooser_changed_cb), object);
320 gtk_widget_show (priv->account_chooser);
322 item = gtk_tool_item_new ();
323 gtk_widget_show (GTK_WIDGET (item));
324 gtk_container_add (GTK_CONTAINER (item), priv->account_chooser);
325 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
327 item = gtk_separator_tool_item_new ();
328 gtk_widget_show (GTK_WIDGET (item));
329 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
332 item = gtk_tool_button_new_from_stock (GTK_STOCK_SAVE);
333 gtk_widget_show (GTK_WIDGET (item));
334 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (item), TRUE);
335 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
338 item = gtk_tool_button_new_from_stock (GTK_STOCK_CLEAR);
339 gtk_widget_show (GTK_WIDGET (item));
340 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (item), TRUE);
341 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
343 item = gtk_separator_tool_item_new ();
344 gtk_widget_show (GTK_WIDGET (item));
345 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
348 priv->paused = FALSE;
349 image = gtk_image_new_from_stock (GTK_STOCK_MEDIA_PAUSE, GTK_ICON_SIZE_MENU);
350 gtk_widget_show (image);
351 item = gtk_toggle_tool_button_new ();
352 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (item), priv->paused);
353 g_signal_connect (item, "toggled", G_CALLBACK (debug_dialog_pause_toggled_cb),
355 gtk_widget_show (GTK_WIDGET (item));
356 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (item), TRUE);
357 gtk_tool_button_set_label (GTK_TOOL_BUTTON (item), _("Pause"));
358 gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (item), image);
359 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
361 item = gtk_separator_tool_item_new ();
362 gtk_widget_show (GTK_WIDGET (item));
363 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
366 item = gtk_tool_item_new ();
367 gtk_widget_show (GTK_WIDGET (item));
368 gtk_container_add (GTK_CONTAINER (item), gtk_label_new (_("Level ")));
369 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
371 priv->filter = gtk_combo_box_new_text ();
372 gtk_widget_show (priv->filter);
374 item = gtk_tool_item_new ();
375 gtk_widget_show (GTK_WIDGET (item));
376 gtk_container_add (GTK_CONTAINER (item), priv->filter);
377 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
379 gtk_combo_box_append_text (GTK_COMBO_BOX (priv->filter), _("All"));
380 gtk_combo_box_append_text (GTK_COMBO_BOX (priv->filter), _("Debug"));
381 gtk_combo_box_append_text (GTK_COMBO_BOX (priv->filter), _("Info"));
382 gtk_combo_box_append_text (GTK_COMBO_BOX (priv->filter), _("Message"));
383 gtk_combo_box_append_text (GTK_COMBO_BOX (priv->filter), _("Warning"));
384 gtk_combo_box_append_text (GTK_COMBO_BOX (priv->filter), _("Critical"));
385 gtk_combo_box_append_text (GTK_COMBO_BOX (priv->filter), _("Error"));
387 gtk_combo_box_set_active (GTK_COMBO_BOX (priv->filter), 0);
388 gtk_widget_show (GTK_WIDGET (priv->filter));
391 priv->view = gtk_tree_view_new ();
393 renderer = gtk_cell_renderer_text_new ();
395 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
396 -1, _("Time"), renderer, "text", COL_TIMESTAMP, NULL);
397 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
398 -1, _("Domain"), renderer, "text", COL_DOMAIN, NULL);
399 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
400 -1, _("Category"), renderer, "text", COL_CATEGORY, NULL);
401 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
402 -1, _("Level"), renderer, "text", COL_LEVEL, NULL);
403 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
404 -1, _("Message"), renderer, "text", COL_MESSAGE, NULL);
406 priv->store = gtk_list_store_new (NUM_COLS, G_TYPE_DOUBLE,
407 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
410 debug_dialog_account_chooser_changed_cb (GTK_COMBO_BOX (priv->account_chooser),
411 EMPATHY_DEBUG_DIALOG (object));
413 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->view),
414 GTK_TREE_MODEL (priv->store));
416 /* Scrolled window */
417 scrolled_win = gtk_scrolled_window_new (NULL, NULL);
418 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
419 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
421 gtk_widget_show (priv->view);
422 gtk_container_add (GTK_CONTAINER (scrolled_win), priv->view);
424 gtk_widget_show (scrolled_win);
425 gtk_box_pack_start (GTK_BOX (vbox), scrolled_win, TRUE, TRUE, 0);
427 gtk_widget_show (GTK_WIDGET (object));
433 empathy_debug_dialog_init (EmpathyDebugDialog *empathy_debug_dialog)
435 EmpathyDebugDialogPriv *priv =
436 G_TYPE_INSTANCE_GET_PRIVATE (empathy_debug_dialog,
437 EMPATHY_TYPE_DEBUG_DIALOG, EmpathyDebugDialogPriv);
439 empathy_debug_dialog->priv = priv;
441 priv->dispose_run = FALSE;
445 debug_dialog_set_property (GObject *object,
450 EmpathyDebugDialogPriv *priv = GET_PRIV (object);
455 priv->parent = GTK_WINDOW (g_value_dup_object (value));
458 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
464 debug_dialog_get_property (GObject *object,
469 EmpathyDebugDialogPriv *priv = GET_PRIV (object);
474 g_value_set_object (value, priv->parent);
477 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
483 debug_dialog_dispose (GObject *object)
485 EmpathyDebugDialog *selector = EMPATHY_DEBUG_DIALOG (object);
486 EmpathyDebugDialogPriv *priv = GET_PRIV (selector);
488 if (priv->dispose_run)
491 priv->dispose_run = TRUE;
494 g_object_unref (priv->parent);
497 g_object_unref (priv->store);
499 debug_dialog_set_enabled (EMPATHY_DEBUG_DIALOG (object), FALSE);
502 g_object_unref (priv->proxy);
504 if (priv->signal_connection)
505 tp_proxy_signal_connection_disconnect (priv->signal_connection);
507 (G_OBJECT_CLASS (empathy_debug_dialog_parent_class)->dispose) (object);
511 empathy_debug_dialog_class_init (EmpathyDebugDialogClass *klass)
513 GObjectClass *object_class = G_OBJECT_CLASS (klass);
514 object_class->constructor = debug_dialog_constructor;
515 object_class->dispose = debug_dialog_dispose;
516 object_class->set_property = debug_dialog_set_property;
517 object_class->get_property = debug_dialog_get_property;
518 g_type_class_add_private (klass, sizeof (EmpathyDebugDialogPriv));
520 g_object_class_install_property (object_class, PROP_PARENT,
521 g_param_spec_object ("parent", "parent", "parent",
522 GTK_TYPE_WINDOW, G_PARAM_CONSTRUCT_ONLY |
523 G_PARAM_READWRITE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
529 empathy_debug_dialog_new (GtkWindow *parent)
531 return GTK_WIDGET (g_object_new (EMPATHY_TYPE_DEBUG_DIALOG,
532 "parent", parent, NULL));