2
Copyright (C) 2008 Christian Dywan <christian@twotoasts.de>
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
See the file COPYING for the full license text.
12
#include "midori-console.h"
15
#include <glib/gi18n.h>
17
G_DEFINE_TYPE (MidoriConsole, midori_console, GTK_TYPE_VBOX)
19
struct _MidoriConsolePrivate
25
#define MIDORI_CONSOLE_GET_PRIVATE(obj) \
26
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
27
MIDORI_TYPE_CONSOLE, MidoriConsolePrivate))
30
midori_console_class_init (MidoriConsoleClass* class)
32
g_type_class_add_private (class, sizeof (MidoriConsolePrivate));
36
midori_console_button_clear_clicked_cb (GtkToolItem* toolitem,
37
MidoriConsole* console)
39
MidoriConsolePrivate* priv = console->priv;
41
GtkTreeModel* model = gtk_tree_view_get_model (
42
GTK_TREE_VIEW (priv->treeview));
43
gtk_tree_store_clear (GTK_TREE_STORE (model));
47
midori_console_treeview_render_icon_cb (GtkTreeViewColumn* column,
48
GtkCellRenderer* renderer,
54
// gtk_tree_model_get (model, iter, 2, &source_id, -1);
56
g_object_set (renderer, "stock-id", GTK_STOCK_DIALOG_WARNING, NULL);
58
// g_free (source_id);
62
midori_console_treeview_render_text_cb (GtkTreeViewColumn* column,
63
GtkCellRenderer* renderer,
71
gtk_tree_model_get (model, iter, 0, &message, 1, &line, 2, &source_id, -1);
73
gchar* text = g_strdup_printf ("%d @ %s\n%s", line, source_id, message);
74
g_object_set (renderer, "text", text, NULL);
82
midori_console_treeview_row_activated_cb (GtkTreeView* treeview,
84
GtkTreeViewColumn* column,
85
MidoriConsole* console)
87
/*GtkTreeModel* model = gtk_tree_view_get_model (treeview);
89
if (gtk_tree_model_get_iter (model, &iter, path))
92
gtk_tree_model_get (model, &iter, 2, &source_id, -1);
98
midori_console_init (MidoriConsole* console)
100
console->priv = MIDORI_CONSOLE_GET_PRIVATE (console);
102
MidoriConsolePrivate* priv = console->priv;
104
// Create the treeview
105
GtkTreeViewColumn* column;
106
GtkCellRenderer* renderer_text;
107
GtkCellRenderer* renderer_pixbuf;
108
GtkTreeStore* treestore = gtk_tree_store_new (3, G_TYPE_STRING,
111
priv->treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (treestore));
112
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->treeview), FALSE);
113
column = gtk_tree_view_column_new ();
114
renderer_pixbuf = gtk_cell_renderer_pixbuf_new ();
115
gtk_tree_view_column_pack_start (column, renderer_pixbuf, FALSE);
116
gtk_tree_view_column_set_cell_data_func (column, renderer_pixbuf,
117
(GtkTreeCellDataFunc)midori_console_treeview_render_icon_cb,
118
priv->treeview, NULL);
119
renderer_text = gtk_cell_renderer_text_new ();
120
gtk_tree_view_column_pack_start (column, renderer_text, FALSE);
121
gtk_tree_view_column_set_cell_data_func (column, renderer_text,
122
(GtkTreeCellDataFunc)midori_console_treeview_render_text_cb,
123
priv->treeview, NULL);
124
gtk_tree_view_append_column (GTK_TREE_VIEW (priv->treeview), column);
125
g_object_unref (treestore);
126
g_signal_connect (priv->treeview, "row-activated",
127
G_CALLBACK (midori_console_treeview_row_activated_cb),
129
gtk_widget_show (priv->treeview);
130
gtk_box_pack_start (GTK_BOX (console), priv->treeview, TRUE, TRUE, 0);
134
* midori_console_new:
136
* Creates a new empty console.
138
* Return value: a new #MidoriConsole
141
midori_console_new (void)
143
MidoriConsole* console = g_object_new (MIDORI_TYPE_CONSOLE,
146
return GTK_WIDGET (console);
150
* midori_console_get_toolbar:
152
* Retrieves the toolbar of the console. A new widget is created on
153
* the first call of this function.
155
* Return value: a new #MidoriConsole
158
midori_console_get_toolbar (MidoriConsole* console)
160
g_return_val_if_fail (MIDORI_IS_CONSOLE (console), NULL);
162
MidoriConsolePrivate* priv = console->priv;
166
GtkWidget* toolbar = gtk_toolbar_new ();
167
gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_BOTH_HORIZ);
168
gtk_toolbar_set_icon_size (GTK_TOOLBAR (toolbar), GTK_ICON_SIZE_BUTTON);
169
GtkToolItem* toolitem = gtk_tool_item_new ();
170
// TODO: What about a find entry here that filters e.g. by url?
171
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), toolitem, -1);
172
gtk_widget_show (GTK_WIDGET (toolitem));
173
toolitem = gtk_separator_tool_item_new ();
174
gtk_separator_tool_item_set_draw (GTK_SEPARATOR_TOOL_ITEM (toolitem),
176
gtk_tool_item_set_expand (toolitem, TRUE);
177
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), toolitem, -1);
178
gtk_widget_show (GTK_WIDGET (toolitem));
179
toolitem = gtk_tool_button_new_from_stock (GTK_STOCK_CLEAR);
180
gtk_tool_item_set_is_important (toolitem, TRUE);
181
g_signal_connect (toolitem, "clicked",
182
G_CALLBACK (midori_console_button_clear_clicked_cb), console);
183
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), toolitem, -1);
184
gtk_widget_show (GTK_WIDGET (toolitem));
185
priv->toolbar = toolbar;
188
return priv->toolbar;
192
* midori_console_add:
193
* @console: a #MidoriConsole
194
* @message: a descriptive message
195
* @line: the line in the source file
196
* @source_id: the source
198
* Adds a new message to the console.
201
midori_console_add (MidoriConsole* console,
202
const gchar* message,
204
const gchar* source_id)
206
g_return_if_fail (MIDORI_IS_CONSOLE (console));
208
MidoriConsolePrivate* priv = console->priv;
210
GtkTreeView* treeview = GTK_TREE_VIEW (priv->treeview);
211
GtkTreeModel* treemodel = gtk_tree_view_get_model (treeview);
212
gtk_tree_store_insert_with_values (GTK_TREE_STORE (treemodel),
213
NULL, NULL, G_MAXINT,
214
0, message, 1, line, 2, source_id, -1);