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-extensions.h"
14
#include "midori-app.h"
15
#include "midori-extension.h"
16
#include "midori-stock.h"
17
#include "midori-viewable.h"
20
#include <glib/gi18n.h>
22
struct _MidoriExtensions
24
GtkVBox parent_instance;
31
struct _MidoriExtensionsClass
33
GtkVBoxClass parent_class;
37
midori_extensions_viewable_iface_init (MidoriViewableIface* iface);
39
G_DEFINE_TYPE_WITH_CODE (MidoriExtensions, midori_extensions, GTK_TYPE_VBOX,
40
G_IMPLEMENT_INTERFACE (MIDORI_TYPE_VIEWABLE,
41
midori_extensions_viewable_iface_init));
51
midori_extensions_set_property (GObject* object,
57
midori_extensions_get_property (GObject* object,
63
midori_extensions_class_init (MidoriExtensionsClass* class)
65
GObjectClass* gobject_class;
68
gobject_class = G_OBJECT_CLASS (class);
69
gobject_class->set_property = midori_extensions_set_property;
70
gobject_class->get_property = midori_extensions_get_property;
72
flags = G_PARAM_READWRITE | G_PARAM_CONSTRUCT;
74
g_object_class_install_property (gobject_class,
85
midori_extensions_get_label (MidoriViewable* viewable)
87
return _("Extensions");
91
midori_extensions_get_stock_id (MidoriViewable* viewable)
93
return STOCK_EXTENSIONS;
97
midori_extensions_button_status_clicked_cb (GtkToolItem* toolitem,
98
MidoriExtensions* extensions)
100
GtkTreeView* treeview;
103
MidoriExtension* extension;
105
treeview = GTK_TREE_VIEW (extensions->treeview);
107
if (sokoke_tree_view_get_selected_iter (treeview, &model, &iter))
109
GtkToolItem* button_enable = gtk_toolbar_get_nth_item (
110
GTK_TOOLBAR (extensions->toolbar), 1);
111
GtkToolItem* button_disable = gtk_toolbar_get_nth_item (
112
GTK_TOOLBAR (extensions->toolbar), 2);
114
gtk_tree_model_get (model, &iter, 0, &extension, -1);
115
if (toolitem == button_enable)
116
g_signal_emit_by_name (extension, "activate", extensions->app);
117
else if (toolitem == button_disable)
118
midori_extension_deactivate (extension);
120
gtk_widget_set_sensitive (GTK_WIDGET (button_enable),
121
!midori_extension_is_active (extension));
122
gtk_widget_set_sensitive (GTK_WIDGET (button_enable),
123
midori_extension_is_active (extension));
128
midori_extensions_get_toolbar (MidoriViewable* extensions)
130
if (!MIDORI_EXTENSIONS (extensions)->toolbar)
133
GtkToolItem* toolitem;
135
toolbar = gtk_toolbar_new ();
136
gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_BOTH_HORIZ);
137
gtk_toolbar_set_icon_size (GTK_TOOLBAR (toolbar), GTK_ICON_SIZE_BUTTON);
138
toolitem = gtk_tool_item_new ();
139
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), toolitem, -1);
140
gtk_widget_show (GTK_WIDGET (toolitem));
143
toolitem = gtk_tool_button_new_from_stock (GTK_STOCK_YES);
144
gtk_tool_button_set_label (GTK_TOOL_BUTTON (toolitem), _("_Enable"));
145
g_signal_connect (toolitem, "clicked",
146
G_CALLBACK (midori_extensions_button_status_clicked_cb), extensions);
147
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), toolitem, -1);
148
gtk_widget_set_sensitive (GTK_WIDGET (toolitem), FALSE);
149
gtk_widget_show (GTK_WIDGET (toolitem));
152
toolitem = gtk_tool_button_new_from_stock (GTK_STOCK_NO);
153
gtk_tool_button_set_label (GTK_TOOL_BUTTON (toolitem), _("_Disable"));
154
g_signal_connect (toolitem, "clicked",
155
G_CALLBACK (midori_extensions_button_status_clicked_cb), extensions);
156
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), toolitem, -1);
157
gtk_widget_set_sensitive (GTK_WIDGET (toolitem), FALSE);
158
gtk_widget_show (GTK_WIDGET (toolitem));
160
MIDORI_EXTENSIONS (extensions)->toolbar = toolbar;
163
return MIDORI_EXTENSIONS (extensions)->toolbar;
167
midori_extensions_viewable_iface_init (MidoriViewableIface* iface)
169
iface->get_stock_id = midori_extensions_get_stock_id;
170
iface->get_label = midori_extensions_get_label;
171
iface->get_toolbar = midori_extensions_get_toolbar;
175
midori_extensions_add_item_cb (KatzeArray* array,
176
MidoriExtension* extension,
177
MidoriExtensions* extensions)
180
GtkListStore* liststore = GTK_LIST_STORE (gtk_tree_view_get_model (
181
GTK_TREE_VIEW (extensions->treeview)));
182
gtk_list_store_append (liststore, &iter);
183
gtk_list_store_set (liststore, &iter, 0, extension, -1);
187
midori_extensions_set_property (GObject* object,
192
MidoriExtensions* extensions = MIDORI_EXTENSIONS (object);
201
extensions->app = g_value_get_object (value);
202
array = katze_object_get_object (extensions->app, "extensions");
203
g_signal_connect (array, "add-item",
204
G_CALLBACK (midori_extensions_add_item_cb), extensions);
206
if ((n = katze_array_get_length (array)))
207
for (i = 0; i < n; i++)
208
midori_extensions_add_item_cb (array,
209
katze_array_get_nth_item (array, i), extensions);
213
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
219
midori_extensions_get_property (GObject* object,
224
MidoriExtensions* extensions = MIDORI_EXTENSIONS (object);
229
g_value_set_object (value, extensions->app);
232
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
238
midori_extensions_treeview_render_icon_cb (GtkTreeViewColumn* column,
239
GtkCellRenderer* renderer,
244
g_object_set (renderer, "stock-id", GTK_STOCK_EXECUTE, NULL);
248
midori_extensions_treeview_render_text_cb (GtkTreeViewColumn* column,
249
GtkCellRenderer* renderer,
254
MidoriExtension* extension;
257
gtk_tree_model_get (model, iter, 0, &extension, -1);
259
text = g_strdup_printf ("%s\n%s",
260
katze_object_get_string (extension, "name"),
261
katze_object_get_string (extension, "description"));
262
g_object_set (renderer, "text", text, NULL);
267
midori_extensions_treeview_row_activated_cb (GtkTreeView* treeview,
269
GtkTreeViewColumn* column,
270
MidoriExtensions* extensions)
272
GtkTreeModel* model = gtk_tree_view_get_model (treeview);
275
if (gtk_tree_model_get_iter (model, &iter, path))
277
MidoriExtension* extension;
279
gtk_tree_model_get (model, &iter, 0, &extension, -1);
280
if (midori_extension_is_active (extension))
282
midori_extension_deactivate (extension);
283
gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
286
g_signal_emit_by_name (extension, "activate", extensions->app);
291
midori_extensions_init (MidoriExtensions* extensions)
293
/* Create the treeview */
294
GtkTreeViewColumn* column;
295
GtkCellRenderer* renderer_text;
296
GtkCellRenderer* renderer_pixbuf;
297
GtkListStore* liststore = gtk_list_store_new (1, G_TYPE_OBJECT);
298
extensions->treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (liststore));
299
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (extensions->treeview), FALSE);
300
column = gtk_tree_view_column_new ();
301
renderer_pixbuf = gtk_cell_renderer_pixbuf_new ();
302
gtk_tree_view_column_pack_start (column, renderer_pixbuf, FALSE);
303
gtk_tree_view_column_set_cell_data_func (column, renderer_pixbuf,
304
(GtkTreeCellDataFunc)midori_extensions_treeview_render_icon_cb,
305
extensions->treeview, NULL);
306
renderer_text = gtk_cell_renderer_text_new ();
307
gtk_tree_view_column_pack_start (column, renderer_text, FALSE);
308
gtk_tree_view_column_set_cell_data_func (column, renderer_text,
309
(GtkTreeCellDataFunc)midori_extensions_treeview_render_text_cb,
310
extensions->treeview, NULL);
311
gtk_tree_view_append_column (GTK_TREE_VIEW (extensions->treeview), column);
312
g_object_unref (liststore);
313
g_signal_connect (extensions->treeview, "row-activated",
314
G_CALLBACK (midori_extensions_treeview_row_activated_cb),
316
gtk_widget_show (extensions->treeview);
317
gtk_box_pack_start (GTK_BOX (extensions), extensions->treeview, TRUE, TRUE, 0);
321
* midori_extensions_new:
323
* Creates a new empty extensions.
325
* Return value: a new #MidoriExtensions
330
midori_extensions_new (void)
332
MidoriExtensions* extensions = g_object_new (MIDORI_TYPE_EXTENSIONS,
335
return GTK_WIDGET (extensions);