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