]> git.0d.be Git - empathy.git/blob - src/empathy-debug-dialog.c
Add GtkTreeView to debug dialog.
[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 #include <libempathy/empathy-utils.h>
27
28 #include "empathy-debug-dialog.h"
29
30 G_DEFINE_TYPE (EmpathyDebugDialog, empathy_debug_dialog,
31     GTK_TYPE_DIALOG)
32
33 enum
34 {
35   PROP_0,
36   PROP_PARENT
37 };
38
39 enum
40 {
41   COL_TIMESTAMP = 0,
42   COL_DOMAIN,
43   COL_CATEGORY,
44   COL_LEVEL,
45   COL_MESSAGE,
46   NUM_COLS
47 };
48
49 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyDebugDialog)
50 typedef struct
51 {
52   GtkWidget *filter;
53   GtkWindow *parent;
54   GtkWidget *view;
55   GtkListStore *store;
56   gboolean dispose_run;
57 } EmpathyDebugDialogPriv;
58
59 static GObject *
60 debug_dialog_constructor (GType type,
61                           guint n_construct_params,
62                           GObjectConstructParam *construct_params)
63 {
64   GObject *object;
65   EmpathyDebugDialogPriv *priv;
66   GtkWidget *vbox;
67   GtkWidget *toolbar;
68   GtkWidget *image;
69   GtkToolItem *item;
70   GtkCellRenderer *renderer;
71   GtkWidget *scrolled_win;
72
73   /* tmp */
74   GtkTreeIter iter;
75
76   object = G_OBJECT_CLASS (empathy_debug_dialog_parent_class)->constructor
77     (type, n_construct_params, construct_params);
78   priv = GET_PRIV (object);
79
80   gtk_window_set_title (GTK_WINDOW (object), _("Debug Window"));
81   gtk_window_set_default_size (GTK_WINDOW (object), 800, 400);
82   gtk_window_set_transient_for (GTK_WINDOW (object), priv->parent);
83
84   vbox = GTK_DIALOG (object)->vbox;
85
86   toolbar = gtk_toolbar_new ();
87   gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_BOTH_HORIZ);
88   gtk_toolbar_set_show_arrow (GTK_TOOLBAR (toolbar), TRUE);
89   gtk_toolbar_set_icon_size (GTK_TOOLBAR (toolbar), GTK_ICON_SIZE_SMALL_TOOLBAR);
90   gtk_widget_show (toolbar);
91
92   gtk_box_pack_start (GTK_BOX (vbox), toolbar, FALSE, FALSE, 0);
93
94   /* Save */
95   item = gtk_tool_button_new_from_stock (GTK_STOCK_SAVE);
96   gtk_widget_show (GTK_WIDGET (item));
97   gtk_tool_item_set_is_important (GTK_TOOL_ITEM (item), TRUE);
98   gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
99
100   /* Clear */
101   item = gtk_tool_button_new_from_stock (GTK_STOCK_CLEAR);
102   gtk_widget_show (GTK_WIDGET (item));
103   gtk_tool_item_set_is_important (GTK_TOOL_ITEM (item), TRUE);
104   gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
105
106   item = gtk_separator_tool_item_new ();
107   gtk_widget_show (GTK_WIDGET (item));
108   gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
109
110   /* Pause */
111   image = gtk_image_new_from_stock (GTK_STOCK_MEDIA_PAUSE, GTK_ICON_SIZE_MENU);
112   gtk_widget_show (image);
113   item = gtk_toggle_tool_button_new ();
114   gtk_widget_show (GTK_WIDGET (item));
115   gtk_tool_item_set_is_important (GTK_TOOL_ITEM (item), TRUE);
116   gtk_tool_button_set_label (GTK_TOOL_BUTTON (item), _("Pause"));
117   gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (item), image);
118   gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
119
120   item = gtk_separator_tool_item_new ();
121   gtk_widget_show (GTK_WIDGET (item));
122   gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
123
124   /* Level */
125   item = gtk_tool_item_new ();
126   gtk_widget_show (GTK_WIDGET (item));
127   gtk_container_add (GTK_CONTAINER (item), gtk_label_new (_("Level ")));
128   gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
129
130   priv->filter = gtk_combo_box_new_text ();
131   gtk_widget_show (priv->filter);
132
133   item = gtk_tool_item_new ();
134   gtk_widget_show (GTK_WIDGET (item));
135   gtk_container_add (GTK_CONTAINER (item), priv->filter);
136   gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
137
138   gtk_combo_box_append_text (GTK_COMBO_BOX (priv->filter), _("All"));
139   gtk_combo_box_append_text (GTK_COMBO_BOX (priv->filter), _("Debug"));
140   gtk_combo_box_append_text (GTK_COMBO_BOX (priv->filter), _("Info"));
141   gtk_combo_box_append_text (GTK_COMBO_BOX (priv->filter), _("Message"));
142   gtk_combo_box_append_text (GTK_COMBO_BOX (priv->filter), _("Warning"));
143   gtk_combo_box_append_text (GTK_COMBO_BOX (priv->filter), _("Critical"));
144   gtk_combo_box_append_text (GTK_COMBO_BOX (priv->filter), _("Error"));
145
146   gtk_combo_box_set_active (GTK_COMBO_BOX (priv->filter), 0);
147   gtk_widget_show (GTK_WIDGET (priv->filter));
148
149   /* Debug treeview */
150   priv->view = gtk_tree_view_new ();
151
152   renderer = gtk_cell_renderer_text_new ();
153
154   gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
155       -1, _("Time"), renderer, "text", COL_TIMESTAMP, NULL);
156   gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
157       -1, _("Domain"), renderer, "text", COL_DOMAIN, NULL);
158   gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
159       -1, _("Category"), renderer, "text", COL_CATEGORY, NULL);
160   gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
161       -1, _("Level"), renderer, "text", COL_LEVEL, NULL);
162   gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->view),
163       -1, _("Message"), renderer, "text", COL_MESSAGE, NULL);
164
165   priv->store = gtk_list_store_new (NUM_COLS, G_TYPE_DOUBLE,
166       G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
167
168   gtk_list_store_append (priv->store, &iter);
169   gtk_list_store_set (priv->store, &iter,
170       COL_TIMESTAMP, 2.0,
171       COL_DOMAIN, "domain",
172       COL_CATEGORY, "category",
173       COL_LEVEL, "level",
174       COL_MESSAGE, "message",
175       -1);
176
177   gtk_tree_view_set_model (GTK_TREE_VIEW (priv->view),
178       GTK_TREE_MODEL (priv->store));
179
180   scrolled_win = gtk_scrolled_window_new (NULL, NULL);
181   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
182       GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
183
184   gtk_widget_show (priv->view);
185   gtk_container_add (GTK_CONTAINER (scrolled_win), priv->view);
186
187   gtk_widget_show (scrolled_win);
188   gtk_box_pack_start (GTK_BOX (vbox), scrolled_win, TRUE, TRUE, 0);
189
190   gtk_widget_show (GTK_WIDGET (object));
191
192   return object;
193 }
194
195 static void
196 empathy_debug_dialog_init (EmpathyDebugDialog *empathy_debug_dialog)
197 {
198   EmpathyDebugDialogPriv *priv =
199       G_TYPE_INSTANCE_GET_PRIVATE (empathy_debug_dialog,
200       EMPATHY_TYPE_DEBUG_DIALOG, EmpathyDebugDialogPriv);
201
202   empathy_debug_dialog->priv = priv;
203
204   priv->dispose_run = FALSE;
205 }
206
207 static void
208 debug_dialog_set_property (GObject *object,
209                            guint prop_id,
210                            const GValue *value,
211                            GParamSpec *pspec)
212 {
213   EmpathyDebugDialogPriv *priv = GET_PRIV (object);
214
215   switch (prop_id)
216     {
217       case PROP_PARENT:
218         priv->parent = GTK_WINDOW (g_value_dup_object (value));
219         break;
220       default:
221         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
222         break;
223     }
224 }
225
226 static void
227 debug_dialog_get_property (GObject *object,
228                            guint prop_id,
229                            GValue *value,
230                            GParamSpec *pspec)
231 {
232   EmpathyDebugDialogPriv *priv = GET_PRIV (object);
233
234   switch (prop_id)
235     {
236       case PROP_PARENT:
237         g_value_set_object (value, priv->parent);
238         break;
239       default:
240         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
241         break;
242     }
243 }
244
245 static void
246 debug_dialog_dispose (GObject *object)
247 {
248   EmpathyDebugDialog *selector = EMPATHY_DEBUG_DIALOG (object);
249   EmpathyDebugDialogPriv *priv = GET_PRIV (selector);
250
251   if (priv->dispose_run)
252     return;
253
254   priv->dispose_run = TRUE;
255
256   if (priv->parent)
257     g_object_unref (priv->parent);
258
259   if (priv->store)
260     g_object_unref (priv->store);
261
262   (G_OBJECT_CLASS (empathy_debug_dialog_parent_class)->dispose) (object);
263 }
264
265 static void
266 empathy_debug_dialog_class_init (EmpathyDebugDialogClass *klass)
267 {
268   GObjectClass *object_class = G_OBJECT_CLASS (klass);
269   object_class->constructor = debug_dialog_constructor;
270   object_class->dispose = debug_dialog_dispose;
271   object_class->set_property = debug_dialog_set_property;
272   object_class->get_property = debug_dialog_get_property;
273   g_type_class_add_private (klass, sizeof (EmpathyDebugDialogPriv));
274
275   g_object_class_install_property (object_class, PROP_PARENT,
276       g_param_spec_object ("parent", "parent", "parent",
277       GTK_TYPE_WINDOW, G_PARAM_CONSTRUCT_ONLY |
278       G_PARAM_READWRITE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
279 }
280
281 /* public methods */
282
283 GtkWidget *
284 empathy_debug_dialog_new (GtkWindow *parent)
285 {
286   return GTK_WIDGET (g_object_new (EMPATHY_TYPE_DEBUG_DIALOG,
287       "parent", parent, NULL));
288 }