]> git.0d.be Git - empathy.git/blob - src/empathy-debug-dialog.c
Added a basic UI 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 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyDebugDialog)
40 typedef struct
41 {
42   GtkWidget *filter;
43   GtkWindow *parent;
44   gboolean dispose_run;
45 } EmpathyDebugDialogPriv;
46
47 static GObject *
48 debug_dialog_constructor (GType type,
49                           guint n_construct_params,
50                           GObjectConstructParam *construct_params)
51 {
52   GObject *object;
53   EmpathyDebugDialogPriv *priv;
54   GtkWidget *vbox;
55   GtkWidget *toolbar;
56   GtkWidget *button;
57   GtkWidget *image;
58   GtkToolItem *item;
59
60   object = G_OBJECT_CLASS (empathy_debug_dialog_parent_class)->constructor
61     (type, n_construct_params, construct_params);
62   priv = GET_PRIV (object);
63
64   gtk_window_set_title (GTK_WINDOW (object), _("Debug Window"));
65   gtk_window_set_default_size (GTK_WINDOW (object), 800, 400);
66   gtk_window_set_transient_for (GTK_WINDOW (object), priv->parent);
67
68   vbox = GTK_DIALOG (object)->vbox;
69
70   toolbar = gtk_toolbar_new ();
71   gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_BOTH_HORIZ);
72   gtk_toolbar_set_show_arrow (GTK_TOOLBAR (toolbar), TRUE);
73   gtk_toolbar_set_icon_size (GTK_TOOLBAR (toolbar), GTK_ICON_SIZE_SMALL_TOOLBAR);
74   gtk_widget_show (toolbar);
75
76   gtk_box_pack_start (GTK_BOX (vbox), toolbar, FALSE, FALSE, 0);
77
78   /* Save */
79   item = gtk_tool_button_new_from_stock (GTK_STOCK_SAVE);
80   gtk_widget_show (GTK_WIDGET (item));
81   gtk_tool_item_set_is_important (GTK_TOOL_ITEM (item), TRUE);
82   gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
83
84   /* Clear */
85   item = gtk_tool_button_new_from_stock (GTK_STOCK_CLEAR);
86   gtk_widget_show (GTK_WIDGET (item));
87   gtk_tool_item_set_is_important (GTK_TOOL_ITEM (item), TRUE);
88   gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
89
90   item = gtk_separator_tool_item_new ();
91   gtk_widget_show (GTK_WIDGET (item));
92   gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
93
94   /* Pause */
95   image = gtk_image_new_from_stock (GTK_STOCK_MEDIA_PAUSE, GTK_ICON_SIZE_MENU);
96   gtk_widget_show (image);
97   item = gtk_toggle_tool_button_new ();
98   gtk_widget_show (GTK_WIDGET (item));
99   gtk_tool_item_set_is_important (GTK_TOOL_ITEM (item), TRUE);
100   gtk_tool_button_set_label (GTK_TOOL_BUTTON (item), _("Pause"));
101   gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (item), image);
102   gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
103
104   item = gtk_separator_tool_item_new ();
105   gtk_widget_show (GTK_WIDGET (item));
106   gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
107
108   /* Level */
109   item = gtk_tool_item_new ();
110   gtk_widget_show (GTK_WIDGET (item));
111   gtk_container_add (GTK_CONTAINER (item), gtk_label_new (_("Level ")));
112   gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
113
114   priv->filter = gtk_combo_box_new_text ();
115   gtk_widget_show (priv->filter);
116
117   item = gtk_tool_item_new ();
118   gtk_widget_show (GTK_WIDGET (item));
119   gtk_container_add (GTK_CONTAINER (item), priv->filter);
120   gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
121
122   gtk_combo_box_append_text (GTK_COMBO_BOX (priv->filter), _("All"));
123   gtk_combo_box_append_text (GTK_COMBO_BOX (priv->filter), _("Debug"));
124   gtk_combo_box_append_text (GTK_COMBO_BOX (priv->filter), _("Info"));
125   gtk_combo_box_append_text (GTK_COMBO_BOX (priv->filter), _("Message"));
126   gtk_combo_box_append_text (GTK_COMBO_BOX (priv->filter), _("Warning"));
127   gtk_combo_box_append_text (GTK_COMBO_BOX (priv->filter), _("Critical"));
128   gtk_combo_box_append_text (GTK_COMBO_BOX (priv->filter), _("Error"));
129
130   gtk_combo_box_set_active (GTK_COMBO_BOX (priv->filter), 0);
131   gtk_widget_show (GTK_WIDGET (priv->filter));
132
133   /* Debug treeview */
134   button = gtk_button_new_with_label ("Foo");
135   gtk_widget_show (button);
136
137   gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);
138
139   gtk_widget_show (GTK_WIDGET (object));
140
141   return object;
142 }
143
144 static void
145 empathy_debug_dialog_init (EmpathyDebugDialog *empathy_debug_dialog)
146 {
147   EmpathyDebugDialogPriv *priv =
148       G_TYPE_INSTANCE_GET_PRIVATE (empathy_debug_dialog,
149       EMPATHY_TYPE_DEBUG_DIALOG, EmpathyDebugDialogPriv);
150
151   empathy_debug_dialog->priv = priv;
152
153   priv->dispose_run = FALSE;
154 }
155
156 static void
157 debug_dialog_set_property (GObject *object,
158                            guint prop_id,
159                            const GValue *value,
160                            GParamSpec *pspec)
161 {
162   EmpathyDebugDialogPriv *priv = GET_PRIV (object);
163
164   switch (prop_id)
165     {
166       case PROP_PARENT:
167         priv->parent = GTK_WINDOW (g_value_dup_object (value));
168         break;
169       default:
170         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
171         break;
172     }
173 }
174
175 static void
176 debug_dialog_get_property (GObject *object,
177                            guint prop_id,
178                            GValue *value,
179                            GParamSpec *pspec)
180 {
181   EmpathyDebugDialogPriv *priv = GET_PRIV (object);
182
183   switch (prop_id)
184     {
185       case PROP_PARENT:
186         g_value_set_object (value, priv->parent);
187         break;
188       default:
189         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
190         break;
191     }
192 }
193
194 static void
195 debug_dialog_dispose (GObject *object)
196 {
197   EmpathyDebugDialog *selector = EMPATHY_DEBUG_DIALOG (object);
198   EmpathyDebugDialogPriv *priv = GET_PRIV (selector);
199
200   if (priv->dispose_run)
201     return;
202
203   priv->dispose_run = TRUE;
204
205   g_object_unref (priv->parent);
206
207   (G_OBJECT_CLASS (empathy_debug_dialog_parent_class)->dispose) (object);
208 }
209
210 static void
211 empathy_debug_dialog_class_init (EmpathyDebugDialogClass *klass)
212 {
213   GObjectClass *object_class = G_OBJECT_CLASS (klass);
214   object_class->constructor = debug_dialog_constructor;
215   object_class->dispose = debug_dialog_dispose;
216   object_class->set_property = debug_dialog_set_property;
217   object_class->get_property = debug_dialog_get_property;
218   g_type_class_add_private (klass, sizeof (EmpathyDebugDialogPriv));
219
220   g_object_class_install_property (object_class, PROP_PARENT,
221       g_param_spec_object ("parent", "parent", "parent",
222       GTK_TYPE_WINDOW, G_PARAM_CONSTRUCT_ONLY |
223       G_PARAM_READWRITE | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
224 }
225
226 /* public methods */
227
228 GtkWidget *
229 empathy_debug_dialog_new (GtkWindow *parent)
230 {
231   return GTK_WIDGET (g_object_new (EMPATHY_TYPE_DEBUG_DIALOG,
232       "parent", parent, NULL));
233 }