]> git.0d.be Git - empathy.git/blob - src/empathy-debug-dialog.c
Clear the store when changing CM.
[empathy.git] / src / empathy-debug-dialog.c
1 /*
2 *  Copyright (C) 2009 Collabora Ltd.
3 *
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.
8 *
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.
13 *
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
17 *
18 *  Authors: Jonny Lamb <jonny.lamb@collabora.co.uk>
19 */
20
21 #include "config.h"
22
23 #include <glib/gi18n.h>
24 #include <gtk/gtk.h>
25
26 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
27 #include <libempathy/empathy-debug.h>
28 #include <libempathy/empathy-utils.h>
29
30 #include <libempathy-gtk/empathy-account-chooser.h>
31
32 #include <telepathy-glib/dbus.h>
33 #include <telepathy-glib/util.h>
34 #include <telepathy-glib/proxy-subclass.h>
35
36 #include "extensions/extensions.h"
37
38 #include "empathy-debug-dialog.h"
39
40 G_DEFINE_TYPE (EmpathyDebugDialog, empathy_debug_dialog,
41     GTK_TYPE_DIALOG)
42
43 enum
44 {
45   PROP_0,
46   PROP_PARENT
47 };
48
49 enum
50 {
51   COL_DEBUG_TIMESTAMP = 0,
52   COL_DEBUG_DOMAIN,
53   COL_DEBUG_CATEGORY,
54   COL_DEBUG_LEVEL_STRING,
55   COL_DEBUG_MESSAGE,
56   COL_DEBUG_LEVEL_VALUE,
57   NUM_DEBUG_COLS
58 };
59
60 enum
61 {
62   COL_CM_NAME = 0,
63   COL_CM_BUS,
64   NUM_COLS_CM
65 };
66
67 enum
68 {
69   COL_LEVEL_NAME,
70   COL_LEVEL_VALUE,
71   NUM_COLS_LEVEL
72 };
73
74 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyDebugDialog)
75 typedef struct
76 {
77   GtkWidget *filter;
78   GtkWindow *parent;
79   GtkWidget *view;
80   GtkWidget *cm_chooser;
81   GtkListStore *store;
82   GtkTreeModel *store_filter;
83   TpProxy *proxy;
84   TpProxySignalConnection *signal_connection;
85   gboolean paused;
86   GtkListStore *cms;
87   gboolean dispose_run;
88 } EmpathyDebugDialogPriv;
89
90 static const gchar *
91 log_level_to_string (guint level)
92 {
93   switch (level)
94     {
95     case EMP_DEBUG_LEVEL_ERROR:
96       return _("Error");
97       break;
98     case EMP_DEBUG_LEVEL_CRITICAL:
99       return _("Critical");
100       break;
101     case EMP_DEBUG_LEVEL_WARNING:
102       return _("Warning");
103       break;
104     case EMP_DEBUG_LEVEL_MESSAGE:
105       return _("Message");
106       break;
107     case EMP_DEBUG_LEVEL_INFO:
108       return _("Info");
109       break;
110     case EMP_DEBUG_LEVEL_DEBUG:
111       return _("Debug");
112       break;
113     default:
114       g_assert_not_reached ();
115       break;
116     }
117 }
118
119 static void
120 debug_dialog_add_message (EmpathyDebugDialog *debug_dialog,
121                           gdouble timestamp,
122                           const gchar *domain_category,
123                           guint level,
124                           const gchar *message)
125 {
126   EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
127   gchar *domain, *category;
128   GtkTreeIter iter;
129   gchar *string;
130
131   if (g_strrstr (domain_category, "/"))
132     {
133       gchar **parts = g_strsplit (domain_category, "/", 2);
134       domain = g_strdup (parts[0]);
135       category = g_strdup (parts[1]);
136       g_strfreev (parts);
137     }
138   else
139     {
140       domain = g_strdup (domain_category);
141       category = g_strdup ("");
142     }
143
144   if (g_str_has_suffix (message, "\n"))
145     string = g_strchomp (g_strdup (message));
146   else
147     string = g_strdup (message);
148
149
150   gtk_list_store_append (priv->store, &iter);
151   gtk_list_store_set (priv->store, &iter,
152       COL_DEBUG_TIMESTAMP, timestamp,
153       COL_DEBUG_DOMAIN, domain,
154       COL_DEBUG_CATEGORY, category,
155       COL_DEBUG_LEVEL_STRING, log_level_to_string (level),
156       COL_DEBUG_MESSAGE, string,
157       COL_DEBUG_LEVEL_VALUE, level,
158       -1);
159
160   g_free (string);
161   g_free (domain);
162   g_free (category);
163 }
164
165 static void
166 debug_dialog_new_debug_message_cb (TpProxy *proxy,
167                                    gdouble timestamp,
168                                    const gchar *domain,
169                                    guint level,
170                                    const gchar *message,
171                                    gpointer user_data,
172                                    GObject *weak_object)
173 {
174   EmpathyDebugDialog *debug_dialog = (EmpathyDebugDialog *) user_data;
175
176   debug_dialog_add_message (debug_dialog, timestamp, domain, level,
177       message);
178 }
179
180 static void
181 debug_dialog_set_enabled (EmpathyDebugDialog *debug_dialog,
182                           gboolean enabled)
183 {
184   EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
185   GValue *val;
186
187   val = tp_g_value_slice_new_boolean (enabled);
188
189   tp_cli_dbus_properties_call_set (priv->proxy, -1, EMP_IFACE_DEBUG,
190       "Enabled", val, NULL, NULL, NULL, NULL);
191
192   tp_g_value_slice_free (val);
193 }
194
195 static void
196 debug_dialog_get_messages_cb (TpProxy *proxy,
197                               const GPtrArray *messages,
198                               const GError *error,
199                               gpointer user_data,
200                               GObject *weak_object)
201 {
202   EmpathyDebugDialog *debug_dialog = (EmpathyDebugDialog *) user_data;
203   EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
204   gint i;
205
206   if (error != NULL)
207     {
208       DEBUG ("GetMessages failed: %s", error->message);
209       return;
210     }
211
212   for (i = 0; i < messages->len; i++)
213     {
214       GValueArray *values = g_ptr_array_index (messages, i);
215
216       debug_dialog_add_message (debug_dialog,
217           g_value_get_double (g_value_array_get_nth (values, 0)),
218           g_value_get_string (g_value_array_get_nth (values, 1)),
219           g_value_get_uint (g_value_array_get_nth (values, 2)),
220           g_value_get_string (g_value_array_get_nth (values, 3)));
221     }
222
223   /* Connect to NewDebugMessage */
224   priv->signal_connection = emp_cli_debug_connect_to_new_debug_message (
225       proxy, debug_dialog_new_debug_message_cb, debug_dialog,
226       NULL, NULL, NULL);
227
228   /* Set Enabled as appropriate */
229   debug_dialog_set_enabled (debug_dialog, !priv->paused);
230 }
231
232 static void
233 debug_dialog_cm_chooser_changed_cb (GtkComboBox *cm_chooser,
234                                     EmpathyDebugDialog *debug_dialog)
235 {
236   EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
237   MissionControl *mc;
238   TpDBusDaemon *dbus;
239   GError *error = NULL;
240   gchar *bus_name;
241   TpConnection *connection;
242   GtkTreeIter iter;
243
244   if (!gtk_combo_box_get_active_iter (cm_chooser, &iter))
245     {
246       DEBUG ("No CM is selected");
247       return;
248     }
249
250   mc = empathy_mission_control_dup_singleton ();
251   dbus = tp_dbus_daemon_dup (&error);
252
253   if (error != NULL)
254     {
255       DEBUG ("Failed at duping the dbus daemon: %s", error->message);
256       g_object_unref (mc);
257     }
258
259   gtk_tree_model_get (GTK_TREE_MODEL (priv->cms), &iter,
260       COL_CM_BUS, &bus_name, -1);
261   connection = tp_connection_new (dbus, bus_name, DEBUG_OBJECT_PATH, &error);
262   g_free (bus_name);
263
264   if (error != NULL)
265     {
266       DEBUG ("Getting a new TpConnection failed: %s", error->message);
267       g_error_free (error);
268       g_object_unref (dbus);
269       g_object_unref (mc);
270       return;
271     }
272
273   gtk_list_store_clear (priv->store);
274
275   /* Disable debug signalling */
276   if (priv->proxy != NULL)
277     debug_dialog_set_enabled (debug_dialog, FALSE);
278
279   /* Disconnect from previous NewDebugMessage signal */
280   if (priv->signal_connection)
281     {
282       tp_proxy_signal_connection_disconnect (priv->signal_connection);
283       priv->signal_connection = NULL;
284     }
285
286   if (priv->proxy)
287     g_object_unref (priv->proxy);
288
289   priv->proxy = TP_PROXY (connection);
290
291   tp_proxy_add_interface_by_id (priv->proxy, emp_iface_quark_debug ());
292
293   emp_cli_debug_call_get_messages (priv->proxy, -1,
294       debug_dialog_get_messages_cb, debug_dialog, NULL, NULL);
295
296   g_object_unref (dbus);
297   g_object_unref (mc);
298 }
299
300 static void
301 debug_dialog_list_connection_names_cb (const gchar * const *names,
302                                        gsize n,
303                                        const gchar * const *cms,
304                                        const gchar * const *protocols,
305                                        const GError *error,
306                                        gpointer user_data,
307                                        GObject *weak_object)
308 {
309   EmpathyDebugDialog *debug_dialog = (EmpathyDebugDialog *) user_data;
310   EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
311   int i;
312
313   if (error != NULL)
314     {
315       DEBUG ("list_connection_names failed: %s", error->message);
316       return;
317     }
318
319   for (i = 0; cms[i] != NULL; i++)
320     {
321       GtkTreeIter iter;
322       gtk_list_store_append (priv->cms, &iter);
323       gtk_list_store_set (priv->cms, &iter,
324                           COL_CM_NAME, cms[i],
325                           COL_CM_BUS, names[i],
326                           -1);
327     }
328
329   gtk_combo_box_set_active (GTK_COMBO_BOX (priv->cm_chooser), 0);
330
331   /* Fill treeview */
332   debug_dialog_cm_chooser_changed_cb (GTK_COMBO_BOX (priv->cm_chooser), debug_dialog);
333 }
334
335 static void
336 debug_dialog_fill_cm_chooser (EmpathyDebugDialog *debug_dialog)
337 {
338   TpDBusDaemon *dbus;
339   GError *error = NULL;
340
341   dbus = tp_dbus_daemon_dup (&error);
342
343   if (error != NULL)
344     {
345       DEBUG ("Failed to dup dbus daemon: %s", error->message);
346       g_error_free (error);
347       return;
348     }
349
350   tp_list_connection_names (dbus, debug_dialog_list_connection_names_cb,
351       debug_dialog, NULL, NULL);
352
353   g_object_unref (dbus);
354 }
355
356 static void
357 debug_dialog_pause_toggled_cb (GtkToggleToolButton *pause,
358                                EmpathyDebugDialog *debug_dialog)
359 {
360   EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
361
362   priv->paused = gtk_toggle_tool_button_get_active (pause);
363
364   debug_dialog_set_enabled (debug_dialog, !priv->paused);
365 }
366
367 static gboolean
368 debug_dialog_visible_func (GtkTreeModel *model,
369                            GtkTreeIter *iter,
370                            gpointer user_data)
371 {
372   EmpathyDebugDialog *debug_dialog = (EmpathyDebugDialog *) user_data;
373   EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
374   guint filter_value, level;
375   GtkTreeModel *filter_model;
376   GtkTreeIter filter_iter;
377
378   filter_model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->filter));
379   gtk_combo_box_get_active_iter (GTK_COMBO_BOX (priv->filter),
380       &filter_iter);
381
382   gtk_tree_model_get (model, iter, COL_DEBUG_LEVEL_VALUE, &level, -1);
383   gtk_tree_model_get (filter_model, &filter_iter,
384       COL_LEVEL_VALUE, &filter_value, -1);
385
386   if (level <= filter_value)
387     return TRUE;
388
389   return FALSE;
390 }
391
392 static void
393 debug_dialog_filter_changed_cb (GtkComboBox *filter,
394                                 EmpathyDebugDialog *debug_dialog)
395 {
396   EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
397
398   gtk_tree_model_filter_refilter (
399       GTK_TREE_MODEL_FILTER (priv->store_filter));
400 }
401
402 static void
403 debug_dialog_clear_clicked_cb (GtkToolButton *clear_button,
404                                EmpathyDebugDialog *debug_dialog)
405 {
406   EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
407
408   gtk_list_store_clear (priv->store);
409 }
410
411 static void
412 debug_dialog_menu_copy_activate_cb (GtkMenuItem *menu_item,
413                                     EmpathyDebugDialog *debug_dialog)
414 {
415   EmpathyDebugDialogPriv *priv = GET_PRIV (debug_dialog);
416   GtkTreePath *path;
417   GtkTreeViewColumn *focus_column;
418   GtkTreeIter iter;
419   gchar *message;
420   GtkClipboard *clipboard;
421
422   gtk_tree_view_get_cursor (GTK_TREE_VIEW (priv->view),
423       &path, &focus_column);
424
425   if (path == NULL)
426     {
427       DEBUG ("No row is in focus");
428       return;
429     }
430
431   gtk_tree_model_get_iter (priv->store_filter, &iter, path);
432
433   gtk_tree_model_get (priv->store_filter, &iter,
434       COL_DEBUG_MESSAGE, &message,
435       -1);
436
437   if (EMP_STR_EMPTY (message))
438     {
439       DEBUG ("Log message is empty");
440       return;
441     }
442
443   clipboard = gtk_clipboard_get_for_display (
444       gtk_widget_get_display (GTK_WIDGET (menu_item)),
445       GDK_SELECTION_CLIPBOARD);
446
447   gtk_clipboard_set_text (clipboard, message, -1);
448
449   g_free (message);
450 }
451
452 typedef struct
453 {
454   EmpathyDebugDialog *debug_dialog;
455   guint button;
456   guint32 time;
457 } MenuPopupData;
458
459 static gboolean
460 debug_dialog_show_menu (gpointer user_data)
461 {
462   MenuPopupData *data = (MenuPopupData *) user_data;
463   GtkWidget *menu, *item;
464   GtkMenuShell *shell;
465
466   menu = gtk_menu_new ();
467   shell = GTK_MENU_SHELL (menu);
468
469   item = gtk_image_menu_item_new_from_stock (GTK_STOCK_COPY, NULL);
470
471   g_signal_connect (item, "activate",
472       G_CALLBACK (debug_dialog_menu_copy_activate_cb), data->debug_dialog);
473
474   gtk_menu_shell_append (shell, item);
475   gtk_widget_show (item);
476
477   gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
478      data->button, data->time);
479
480   g_slice_free (MenuPopupData, user_data);
481
482   return FALSE;
483 }
484
485 static gboolean
486 debug_dialog_button_press_event_cb (GtkTreeView *view,
487                                     GdkEventButton *event,
488                                     gpointer user_data)
489 {
490   if (event->button == 3)
491     {
492       MenuPopupData *data;
493       data = g_slice_new0 (MenuPopupData);
494       data->debug_dialog = user_data;
495       data->button = event->button;
496       data->time = event->time;
497       g_idle_add (debug_dialog_show_menu, data);
498     }
499
500   return FALSE;
501 }
502
503 static GObject *
504 debug_dialog_constructor (GType type,
505                           guint n_construct_params,
506                           GObjectConstructParam *construct_params)
507 {
508   GObject *object;
509   EmpathyDebugDialogPriv *priv;
510   GtkWidget *vbox;
511   GtkWidget *toolbar;
512   GtkWidget *image;
513   GtkWidget *label;
514   GtkToolItem *item;
515   GtkCellRenderer *renderer;
516   GtkWidget *scrolled_win;
517   GtkListStore *level_store;
518   GtkTreeIter iter;
519
520   object = G_OBJECT_CLASS (empathy_debug_dialog_parent_class)->constructor
521     (type, n_construct_params, construct_params);
522   priv = GET_PRIV (object);
523
524   gtk_window_set_title (GTK_WINDOW (object), _("Debug Window"));
525   gtk_window_set_default_size (GTK_WINDOW (object), 800, 400);
526   gtk_window_set_transient_for (GTK_WINDOW (object), priv->parent);
527
528   vbox = GTK_DIALOG (object)->vbox;
529
530   toolbar = gtk_toolbar_new ();
531   gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_BOTH_HORIZ);
532   gtk_toolbar_set_show_arrow (GTK_TOOLBAR (toolbar), TRUE);
533   gtk_toolbar_set_icon_size (GTK_TOOLBAR (toolbar), GTK_ICON_SIZE_SMALL_TOOLBAR);
534   gtk_widget_show (toolbar);
535
536   gtk_box_pack_start (GTK_BOX (vbox), toolbar, FALSE, FALSE, 0);
537
538   /* CM */
539   priv->cm_chooser = gtk_combo_box_new_text ();
540   priv->cms = gtk_list_store_new (NUM_COLS_CM, G_TYPE_STRING, G_TYPE_STRING);
541   gtk_combo_box_set_model (GTK_COMBO_BOX (priv->cm_chooser),
542       GTK_TREE_MODEL (priv->cms));
543   gtk_widget_show (priv->cm_chooser);
544
545   item = gtk_tool_item_new ();
546   gtk_widget_show (GTK_WIDGET (item));
547   gtk_container_add (GTK_CONTAINER (item), priv->cm_chooser);
548   gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
549   debug_dialog_fill_cm_chooser (EMPATHY_DEBUG_DIALOG (object));
550   g_signal_connect (priv->cm_chooser, "changed",
551       G_CALLBACK (debug_dialog_cm_chooser_changed_cb), object);
552   gtk_widget_show (GTK_WIDGET (priv->cm_chooser));
553
554   item = gtk_separator_tool_item_new ();
555   gtk_widget_show (GTK_WIDGET (item));
556   gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
557
558   /* Save */
559   item = gtk_tool_button_new_from_stock (GTK_STOCK_SAVE);
560   gtk_widget_show (GTK_WIDGET (item));
561   gtk_tool_item_set_is_important (GTK_TOOL_ITEM (item), TRUE);
562   gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
563
564   /* Clear */
565   item = gtk_tool_button_new_from_stock (GTK_STOCK_CLEAR);
566   g_signal_connect (item, "clicked",
567       G_CALLBACK (debug_dialog_clear_clicked_cb), object);
568   gtk_widget_show (GTK_WIDGET (item));
569   gtk_tool_item_set_is_important (GTK_TOOL_ITEM (item), TRUE);
570   gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
571
572   item = gtk_separator_tool_item_new ();
573   gtk_widget_show (GTK_WIDGET (item));
574   gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
575
576   /* Pause */
577   priv->paused = FALSE;
578   image = gtk_image_new_from_stock (GTK_STOCK_MEDIA_PAUSE, GTK_ICON_SIZE_MENU);
579   gtk_widget_show (image);
580   item = gtk_toggle_tool_button_new ();
581   gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (item), priv->paused);
582   g_signal_connect (item, "toggled", G_CALLBACK (debug_dialog_pause_toggled_cb),
583       object);
584   gtk_widget_show (GTK_WIDGET (item));
585   gtk_tool_item_set_is_important (GTK_TOOL_ITEM (item), TRUE);
586   gtk_tool_button_set_label (GTK_TOOL_BUTTON (item), _("Pause"));
587   gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (item), image);
588   gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
589
590   item = gtk_separator_tool_item_new ();
591   gtk_widget_show (GTK_WIDGET (item));
592   gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
593
594   /* Level */
595   item = gtk_tool_item_new ();
596   gtk_widget_show (GTK_WIDGET (item));
597   label = gtk_label_new (_("Level "));
598   gtk_widget_show (label);
599   gtk_container_add (GTK_CONTAINER (item), label);
600   gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
601
602   priv->filter = gtk_combo_box_new_text ();
603   gtk_widget_show (priv->filter);
604
605   item = gtk_tool_item_new ();
606   gtk_widget_show (GTK_WIDGET (item));
607   gtk_container_add (GTK_CONTAINER (item), priv->filter);
608   gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
609
610   level_store = gtk_list_store_new (NUM_COLS_LEVEL,
611       G_TYPE_STRING, G_TYPE_UINT);
612   gtk_combo_box_set_model (GTK_COMBO_BOX (priv->filter),
613       GTK_TREE_MODEL (level_store));
614
615   gtk_list_store_append (level_store, &iter);
616   gtk_list_store_set (level_store, &iter,
617       COL_LEVEL_NAME, _("Debug"),
618       COL_LEVEL_VALUE, EMP_DEBUG_LEVEL_DEBUG,
619       -1);
620
621   gtk_list_store_append (level_store, &iter);
622   gtk_list_store_set (level_store, &iter,
623       COL_LEVEL_NAME, _("Info"),
624       COL_LEVEL_VALUE, EMP_DEBUG_LEVEL_INFO,
625       -1);
626
627   gtk_list_store_append (level_store, &iter);
628   gtk_list_store_set (level_store, &iter,
629       COL_LEVEL_NAME, _("Message"),
630       COL_LEVEL_VALUE, EMP_DEBUG_LEVEL_MESSAGE,
631       -1);
632
633   gtk_list_store_append (level_store, &iter);
634   gtk_list_store_set (level_store, &iter,
635       COL_LEVEL_NAME, _("Warning"),
636       COL_LEVEL_VALUE, EMP_DEBUG_LEVEL_WARNING,
637       -1);
638
639   gtk_list_store_append (level_store, &iter);
640   gtk_list_store_set (level_store, &iter,
641       COL_LEVEL_NAME, _("Critical"),
642       COL_LEVEL_VALUE, EMP_DEBUG_LEVEL_CRITICAL,
643       -1);
644
645   gtk_list_store_append (level_store, &iter);
646   gtk_list_store_set (level_store, &iter,
647       COL_LEVEL_NAME, _("Error"),
648       COL_LEVEL_VALUE, EMP_DEBUG_LEVEL_ERROR,
649       -1);
650
651   gtk_combo_box_set_active (GTK_COMBO_BOX (priv->filter), 0);
652   g_signal_connect (priv->filter, "changed",
653       G_CALLBACK (debug_dialog_filter_changed_cb), object);
654
655   /* Debug treeview */
656   priv->view = gtk_tree_view_new ();
657   gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (priv->view), TRUE);
658
659   g_signal_connect (priv->view, "button-press-event",
660       G_CALLBACK (debug_dialog_button_press_event_cb), object);
661
662   renderer = gtk_cell_renderer_text_new ();
663   g_object_set (renderer, "yalign", 0, NULL);
664
665   gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
666       -1, _("Time"), renderer, "text", COL_DEBUG_TIMESTAMP, NULL);
667   gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
668       -1, _("Domain"), renderer, "text", COL_DEBUG_DOMAIN, NULL);
669   gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
670       -1, _("Category"), renderer, "text", COL_DEBUG_CATEGORY, NULL);
671   gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
672       -1, _("Level"), renderer, "text", COL_DEBUG_LEVEL_STRING, NULL);
673
674   renderer = gtk_cell_renderer_text_new ();
675   g_object_set (renderer, "family", "Monospace", NULL);
676   gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
677       -1, _("Message"), renderer, "text", COL_DEBUG_MESSAGE, NULL);
678
679   priv->store = gtk_list_store_new (NUM_DEBUG_COLS, G_TYPE_DOUBLE,
680       G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
681       G_TYPE_UINT);
682
683   priv->store_filter = gtk_tree_model_filter_new (
684       GTK_TREE_MODEL (priv->store), NULL);
685
686   gtk_tree_model_filter_set_visible_func (
687       GTK_TREE_MODEL_FILTER (priv->store_filter),
688       debug_dialog_visible_func, object, NULL);
689
690   gtk_tree_view_set_model (GTK_TREE_VIEW (priv->view), priv->store_filter);
691
692   /* Scrolled window */
693   scrolled_win = gtk_scrolled_window_new (NULL, NULL);
694   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
695       GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
696
697   gtk_widget_show (priv->view);
698   gtk_container_add (GTK_CONTAINER (scrolled_win), priv->view);
699
700   gtk_widget_show (scrolled_win);
701   gtk_box_pack_start (GTK_BOX (vbox), scrolled_win, TRUE, TRUE, 0);
702
703   gtk_widget_show (GTK_WIDGET (object));
704
705   return object;
706 }
707
708 static void
709 empathy_debug_dialog_init (EmpathyDebugDialog *empathy_debug_dialog)
710 {
711   EmpathyDebugDialogPriv *priv =
712       G_TYPE_INSTANCE_GET_PRIVATE (empathy_debug_dialog,
713       EMPATHY_TYPE_DEBUG_DIALOG, EmpathyDebugDialogPriv);
714
715   empathy_debug_dialog->priv = priv;
716
717   priv->dispose_run = FALSE;
718 }
719
720 static void
721 debug_dialog_set_property (GObject *object,
722                            guint prop_id,
723                            const GValue *value,
724                            GParamSpec *pspec)
725 {
726   EmpathyDebugDialogPriv *priv = GET_PRIV (object);
727
728   switch (prop_id)
729     {
730       case PROP_PARENT:
731         priv->parent = GTK_WINDOW (g_value_dup_object (value));
732         break;
733       default:
734         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
735         break;
736     }
737 }
738
739 static void
740 debug_dialog_get_property (GObject *object,
741                            guint prop_id,
742                            GValue *value,
743                            GParamSpec *pspec)
744 {
745   EmpathyDebugDialogPriv *priv = GET_PRIV (object);
746
747   switch (prop_id)
748     {
749       case PROP_PARENT:
750         g_value_set_object (value, priv->parent);
751         break;
752       default:
753         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
754         break;
755     }
756 }
757
758 static void
759 debug_dialog_dispose (GObject *object)
760 {
761   EmpathyDebugDialog *selector = EMPATHY_DEBUG_DIALOG (object);
762   EmpathyDebugDialogPriv *priv = GET_PRIV (selector);
763
764   if (priv->dispose_run)
765     return;
766
767   priv->dispose_run = TRUE;
768
769   if (priv->parent)
770     g_object_unref (priv->parent);
771
772   if (priv->store)
773     g_object_unref (priv->store);
774
775   if (priv->proxy)
776     {
777       debug_dialog_set_enabled (EMPATHY_DEBUG_DIALOG (object), FALSE);
778       g_object_unref (priv->proxy);
779     }
780
781   if (priv->signal_connection)
782     tp_proxy_signal_connection_disconnect (priv->signal_connection);
783
784   if (priv->cms)
785     g_object_unref (priv->cms);
786
787   (G_OBJECT_CLASS (empathy_debug_dialog_parent_class)->dispose) (object);
788 }
789
790 static void
791 empathy_debug_dialog_class_init (EmpathyDebugDialogClass *klass)
792 {
793   GObjectClass *object_class = G_OBJECT_CLASS (klass);
794   object_class->constructor = debug_dialog_constructor;
795   object_class->dispose = debug_dialog_dispose;
796   object_class->set_property = debug_dialog_set_property;
797   object_class->get_property = debug_dialog_get_property;
798   g_type_class_add_private (klass, sizeof (EmpathyDebugDialogPriv));
799
800   g_object_class_install_property (object_class, PROP_PARENT,
801       g_param_spec_object ("parent", "parent", "parent",
802       GTK_TYPE_WINDOW, G_PARAM_CONSTRUCT_ONLY |
803       G_PARAM_READWRITE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
804 }
805
806 /* public methods */
807
808 GtkWidget *
809 empathy_debug_dialog_new (GtkWindow *parent)
810 {
811   g_return_val_if_fail (GTK_IS_WINDOW (parent), NULL);
812
813   return GTK_WIDGET (g_object_new (EMPATHY_TYPE_DEBUG_DIALOG,
814       "parent", parent, NULL));
815 }