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>
34 #include "extensions/extensions.h"
36 #include "empathy-debug-dialog.h"
38 G_DEFINE_TYPE (EmpathyDebugDialog, empathy_debug_dialog,
57 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyDebugDialog)
63 GtkWidget *account_chooser;
65 TpProxySignalConnection *signal_connection;
67 } EmpathyDebugDialogPriv;
70 log_level_to_string (guint level)
74 case EMP_DEBUG_LEVEL_ERROR:
77 case EMP_DEBUG_LEVEL_CRITICAL:
80 case EMP_DEBUG_LEVEL_WARNING:
83 case EMP_DEBUG_LEVEL_MESSAGE:
86 case EMP_DEBUG_LEVEL_INFO:
89 case EMP_DEBUG_LEVEL_DEBUG:
93 g_assert_not_reached ();
99 debug_dialog_add_message (EmpathyDebugDialog *debug_dialog,
101 const gchar *domain_category,
103 const gchar *message)
105 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
106 gchar *domain, *category;
109 if (g_strrstr (domain_category, "/"))
111 gchar **parts = g_strsplit (domain_category, "/", 2);
112 domain = g_strdup (parts[0]);
113 category = g_strdup (parts[1]);
118 domain = g_strdup (domain_category);
122 gtk_list_store_append (priv->store, &iter);
123 gtk_list_store_set (priv->store, &iter,
124 COL_TIMESTAMP, timestamp,
126 COL_CATEGORY, category,
127 COL_LEVEL, log_level_to_string (level),
128 COL_MESSAGE, message,
136 debug_dialog_new_debug_message_cb (TpProxy *proxy,
140 const gchar *message,
142 GObject *weak_object)
144 EmpathyDebugDialog *debug_dialog = (EmpathyDebugDialog *) user_data;
146 debug_dialog_add_message (debug_dialog, timestamp, domain, level,
151 debug_dialog_get_messages_cb (TpProxy *proxy,
152 const GPtrArray *messages,
155 GObject *weak_object)
157 EmpathyDebugDialog *debug_dialog = (EmpathyDebugDialog *) user_data;
158 EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
163 DEBUG ("GetMessages failed: %s", error->message);
167 for (i = 0; i < messages->len; i++)
169 GValueArray *values = g_ptr_array_index (messages, i);
171 debug_dialog_add_message (debug_dialog,
172 g_value_get_double (g_value_array_get_nth (values, 0)),
173 g_value_get_string (g_value_array_get_nth (values, 1)),
174 g_value_get_uint (g_value_array_get_nth (values, 2)),
175 g_value_get_string (g_value_array_get_nth (values, 3)));
178 /* Connect to NewDebugMessage */
179 priv->signal_connection = emp_cli_debug_connect_to_new_debug_message (proxy,
180 debug_dialog_new_debug_message_cb, debug_dialog, NULL, NULL, NULL);
184 debug_dialog_account_chooser_changed_cb (GtkComboBox *account_chooser,
185 EmpathyDebugDialog *debug_dialog)
188 TpConnection *connection;
191 GError *error = NULL;
193 mc = empathy_mission_control_dup_singleton ();
194 account = empathy_account_chooser_get_account (EMPATHY_ACCOUNT_CHOOSER (account_chooser));
195 connection = mission_control_get_tpconnection (mc, account, &error);
199 DEBUG ("Getting the account's TpConnection failed: %s", error->message);
200 g_error_free (error);
204 dbus = g_object_ref (tp_proxy_get_dbus_daemon (connection));
206 /* TODO: Fix this. */
207 connection = tp_connection_new (dbus,
208 "org.freedesktop.Telepathy.ConnectionManager.gabble",
209 "/org/freedesktop/Telepathy/debug",
214 DEBUG ("Getting a new TpConnection failed: %s", error->message);
215 g_error_free (error);
219 emp_cli_debug_call_get_messages (TP_PROXY (connection), -1,
220 debug_dialog_get_messages_cb, debug_dialog, NULL, NULL);
222 g_object_unref (connection);
223 g_object_unref (account);
224 g_object_unref (dbus);
228 debug_dialog_constructor (GType type,
229 guint n_construct_params,
230 GObjectConstructParam *construct_params)
233 EmpathyDebugDialogPriv *priv;
238 GtkCellRenderer *renderer;
239 GtkWidget *scrolled_win;
241 object = G_OBJECT_CLASS (empathy_debug_dialog_parent_class)->constructor
242 (type, n_construct_params, construct_params);
243 priv = GET_PRIV (object);
245 gtk_window_set_title (GTK_WINDOW (object), _("Debug Window"));
246 gtk_window_set_default_size (GTK_WINDOW (object), 800, 400);
247 gtk_window_set_transient_for (GTK_WINDOW (object), priv->parent);
249 vbox = GTK_DIALOG (object)->vbox;
251 toolbar = gtk_toolbar_new ();
252 gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_BOTH_HORIZ);
253 gtk_toolbar_set_show_arrow (GTK_TOOLBAR (toolbar), TRUE);
254 gtk_toolbar_set_icon_size (GTK_TOOLBAR (toolbar), GTK_ICON_SIZE_SMALL_TOOLBAR);
255 gtk_widget_show (toolbar);
257 gtk_box_pack_start (GTK_BOX (vbox), toolbar, FALSE, FALSE, 0);
260 item = gtk_tool_item_new ();
261 gtk_widget_show (GTK_WIDGET (item));
262 gtk_container_add (GTK_CONTAINER (item), gtk_label_new (_("Account ")));
263 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
265 priv->account_chooser = empathy_account_chooser_new ();
266 empathy_account_chooser_set_filter (EMPATHY_ACCOUNT_CHOOSER (priv->account_chooser),
267 (EmpathyAccountChooserFilterFunc) mc_account_is_enabled, NULL);
268 g_signal_connect (priv->account_chooser, "changed",
269 G_CALLBACK (debug_dialog_account_chooser_changed_cb), object);
270 gtk_widget_show (priv->account_chooser);
272 item = gtk_tool_item_new ();
273 gtk_widget_show (GTK_WIDGET (item));
274 gtk_container_add (GTK_CONTAINER (item), priv->account_chooser);
275 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
277 item = gtk_separator_tool_item_new ();
278 gtk_widget_show (GTK_WIDGET (item));
279 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
282 item = gtk_tool_button_new_from_stock (GTK_STOCK_SAVE);
283 gtk_widget_show (GTK_WIDGET (item));
284 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (item), TRUE);
285 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
288 item = gtk_tool_button_new_from_stock (GTK_STOCK_CLEAR);
289 gtk_widget_show (GTK_WIDGET (item));
290 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (item), TRUE);
291 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
293 item = gtk_separator_tool_item_new ();
294 gtk_widget_show (GTK_WIDGET (item));
295 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
298 image = gtk_image_new_from_stock (GTK_STOCK_MEDIA_PAUSE, GTK_ICON_SIZE_MENU);
299 gtk_widget_show (image);
300 item = gtk_toggle_tool_button_new ();
301 gtk_widget_show (GTK_WIDGET (item));
302 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (item), TRUE);
303 gtk_tool_button_set_label (GTK_TOOL_BUTTON (item), _("Pause"));
304 gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (item), image);
305 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
307 item = gtk_separator_tool_item_new ();
308 gtk_widget_show (GTK_WIDGET (item));
309 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
312 item = gtk_tool_item_new ();
313 gtk_widget_show (GTK_WIDGET (item));
314 gtk_container_add (GTK_CONTAINER (item), gtk_label_new (_("Level ")));
315 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
317 priv->filter = gtk_combo_box_new_text ();
318 gtk_widget_show (priv->filter);
320 item = gtk_tool_item_new ();
321 gtk_widget_show (GTK_WIDGET (item));
322 gtk_container_add (GTK_CONTAINER (item), priv->filter);
323 gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
325 gtk_combo_box_append_text (GTK_COMBO_BOX (priv->filter), _("All"));
326 gtk_combo_box_append_text (GTK_COMBO_BOX (priv->filter), _("Debug"));
327 gtk_combo_box_append_text (GTK_COMBO_BOX (priv->filter), _("Info"));
328 gtk_combo_box_append_text (GTK_COMBO_BOX (priv->filter), _("Message"));
329 gtk_combo_box_append_text (GTK_COMBO_BOX (priv->filter), _("Warning"));
330 gtk_combo_box_append_text (GTK_COMBO_BOX (priv->filter), _("Critical"));
331 gtk_combo_box_append_text (GTK_COMBO_BOX (priv->filter), _("Error"));
333 gtk_combo_box_set_active (GTK_COMBO_BOX (priv->filter), 0);
334 gtk_widget_show (GTK_WIDGET (priv->filter));
337 priv->view = gtk_tree_view_new ();
339 renderer = gtk_cell_renderer_text_new ();
341 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
342 -1, _("Time"), renderer, "text", COL_TIMESTAMP, NULL);
343 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
344 -1, _("Domain"), renderer, "text", COL_DOMAIN, NULL);
345 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
346 -1, _("Category"), renderer, "text", COL_CATEGORY, NULL);
347 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
348 -1, _("Level"), renderer, "text", COL_LEVEL, NULL);
349 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
350 -1, _("Message"), renderer, "text", COL_MESSAGE, NULL);
352 priv->store = gtk_list_store_new (NUM_COLS, G_TYPE_DOUBLE,
353 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
356 debug_dialog_account_chooser_changed_cb (GTK_COMBO_BOX (priv->account_chooser),
357 EMPATHY_DEBUG_DIALOG (object));
359 gtk_tree_view_set_model (GTK_TREE_VIEW (priv->view),
360 GTK_TREE_MODEL (priv->store));
362 /* Scrolled window */
363 scrolled_win = gtk_scrolled_window_new (NULL, NULL);
364 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
365 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
367 gtk_widget_show (priv->view);
368 gtk_container_add (GTK_CONTAINER (scrolled_win), priv->view);
370 gtk_widget_show (scrolled_win);
371 gtk_box_pack_start (GTK_BOX (vbox), scrolled_win, TRUE, TRUE, 0);
373 gtk_widget_show (GTK_WIDGET (object));
379 empathy_debug_dialog_init (EmpathyDebugDialog *empathy_debug_dialog)
381 EmpathyDebugDialogPriv *priv =
382 G_TYPE_INSTANCE_GET_PRIVATE (empathy_debug_dialog,
383 EMPATHY_TYPE_DEBUG_DIALOG, EmpathyDebugDialogPriv);
385 empathy_debug_dialog->priv = priv;
387 priv->dispose_run = FALSE;
391 debug_dialog_set_property (GObject *object,
396 EmpathyDebugDialogPriv *priv = GET_PRIV (object);
401 priv->parent = GTK_WINDOW (g_value_dup_object (value));
404 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
410 debug_dialog_get_property (GObject *object,
415 EmpathyDebugDialogPriv *priv = GET_PRIV (object);
420 g_value_set_object (value, priv->parent);
423 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
429 debug_dialog_dispose (GObject *object)
431 EmpathyDebugDialog *selector = EMPATHY_DEBUG_DIALOG (object);
432 EmpathyDebugDialogPriv *priv = GET_PRIV (selector);
434 if (priv->dispose_run)
437 priv->dispose_run = TRUE;
440 g_object_unref (priv->parent);
443 g_object_unref (priv->store);
445 if (priv->signal_connection)
446 tp_proxy_signal_connection_disconnect (priv->signal_connection);
448 (G_OBJECT_CLASS (empathy_debug_dialog_parent_class)->dispose) (object);
452 empathy_debug_dialog_class_init (EmpathyDebugDialogClass *klass)
454 GObjectClass *object_class = G_OBJECT_CLASS (klass);
455 object_class->constructor = debug_dialog_constructor;
456 object_class->dispose = debug_dialog_dispose;
457 object_class->set_property = debug_dialog_set_property;
458 object_class->get_property = debug_dialog_get_property;
459 g_type_class_add_private (klass, sizeof (EmpathyDebugDialogPriv));
461 g_object_class_install_property (object_class, PROP_PARENT,
462 g_param_spec_object ("parent", "parent", "parent",
463 GTK_TYPE_WINDOW, G_PARAM_CONSTRUCT_ONLY |
464 G_PARAM_READWRITE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
470 empathy_debug_dialog_new (GtkWindow *parent)
472 return GTK_WIDGET (g_object_new (EMPATHY_TYPE_DEBUG_DIALOG,
473 "parent", parent, NULL));