~midori/midori/innernodeselect

1 by Christian Dywan
Initial commit
1
/*
2
 Copyright (C) 2007 Christian Dywan <christian@twotoasts.de>
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
 See the file COPYING for the full license text.
10
*/
11
12
#include "webSearch.h"
13
14
#include "global.h"
15
#include "helpers.h"
16
#include "search.h"
17
#include "sokoke.h"
18
19
#include <string.h>
20
#include <gdk/gdkkeysyms.h>
44 by Christian Dywan
Implement localization via Gettext.
21
#include <glib/gi18n.h>
1 by Christian Dywan
Initial commit
22
38 by Christian Dywan
Initial refactoring work, regressions expected
23
void update_searchEngine(guint index, GtkWidget* search)
1 by Christian Dywan
Initial commit
24
{
25
    guint n = g_list_length(searchEngines);
26
    // Display a default icon in case we have no engines
27
    if(!n)
38 by Christian Dywan
Initial refactoring work, regressions expected
28
        sexy_icon_entry_set_icon(SEXY_ICON_ENTRY(search), SEXY_ICON_ENTRY_PRIMARY
1 by Christian Dywan
Initial commit
29
         , GTK_IMAGE(gtk_image_new_from_stock(GTK_STOCK_FIND, GTK_ICON_SIZE_MENU)));
30
    // Change the icon and default text according to the chosen engine
31
    else
32
    {
33
        // Reset in case the index is out of range
34
        if(index >= n)
35
            index = 0;
36
        SearchEngine* engine = (SearchEngine*)g_list_nth_data(searchEngines, index);
37
        GdkPixbuf* pixbuf = load_web_icon(search_engine_get_icon(engine)
38 by Christian Dywan
Initial refactoring work, regressions expected
38
         , GTK_ICON_SIZE_MENU, search);
39
        sexy_icon_entry_set_icon(SEXY_ICON_ENTRY(search)
1 by Christian Dywan
Initial commit
40
         , SEXY_ICON_ENTRY_PRIMARY, GTK_IMAGE(gtk_image_new_from_pixbuf(pixbuf)));
41
        g_object_unref(pixbuf);
38 by Christian Dywan
Initial refactoring work, regressions expected
42
        sokoke_entry_set_default_text(GTK_ENTRY(search)
1 by Christian Dywan
Initial commit
43
         , search_engine_get_short_name(engine));
44
        config->searchEngine = index;
45
    }
46
}
47
38 by Christian Dywan
Initial refactoring work, regressions expected
48
void on_webSearch_engine_activate(GtkWidget* widget, MidoriBrowser* browser)
1 by Christian Dywan
Initial commit
49
{
50
    guint index = GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(widget), "engine"));
38 by Christian Dywan
Initial refactoring work, regressions expected
51
    update_searchEngine(index, widget);
1 by Christian Dywan
Initial commit
52
}
53
54
void on_webSearch_icon_released(GtkWidget* widget, SexyIconEntryPosition* pos
38 by Christian Dywan
Initial refactoring work, regressions expected
55
 , gint button, MidoriBrowser* browser)
1 by Christian Dywan
Initial commit
56
{
57
    GtkWidget* menu = gtk_menu_new();
58
    guint n = g_list_length(searchEngines);
59
    GtkWidget* menuitem;
60
    if(n)
61
    {
62
        guint i;
63
        for(i = 0; i < n; i++)
64
        {
65
            SearchEngine* engine = (SearchEngine*)g_list_nth_data(searchEngines, i);
66
            menuitem = gtk_image_menu_item_new_with_label(
67
             search_engine_get_short_name(engine));
68
            GdkPixbuf* pixbuf = load_web_icon(search_engine_get_icon(engine)
69
             , GTK_ICON_SIZE_MENU, menuitem);
70
            GtkWidget* icon = gtk_image_new_from_pixbuf(pixbuf);
71
            gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), icon);
72
            g_object_unref(pixbuf);
73
            gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
74
            g_object_set_data(G_OBJECT(menuitem), "engine", GUINT_TO_POINTER(i));
75
            g_signal_connect(menuitem, "activate"
76
             , G_CALLBACK(on_webSearch_engine_activate), browser);
77
            gtk_widget_show(menuitem);
78
        }
79
    }
80
    else
81
    {
44 by Christian Dywan
Implement localization via Gettext.
82
        menuitem = gtk_image_menu_item_new_with_label(_("Empty"));
1 by Christian Dywan
Initial commit
83
        gtk_widget_set_sensitive(menuitem, FALSE);
84
        gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
85
        gtk_widget_show(menuitem);
86
    }
87
38 by Christian Dywan
Initial refactoring work, regressions expected
88
    /*menuitem = gtk_separator_menu_item_new();
1 by Christian Dywan
Initial commit
89
    gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
90
    gtk_widget_show(menuitem);
91
    GtkAction* action = gtk_action_group_get_action(
92
     browser->actiongroup, "ManageSearchEngines");
93
    menuitem = gtk_action_create_menu_item(action);
94
    gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
38 by Christian Dywan
Initial refactoring work, regressions expected
95
    gtk_widget_show(menuitem);*/
1 by Christian Dywan
Initial commit
96
    sokoke_widget_popup(widget, GTK_MENU(menu), NULL);
97
}
98
99
static void on_webSearch_engines_render_icon(GtkTreeViewColumn* column
100
 , GtkCellRenderer* renderer, GtkTreeModel* model, GtkTreeIter* iter
101
 , GtkWidget* treeview)
102
{
103
    SearchEngine* searchEngine;
104
    gtk_tree_model_get(model, iter, ENGINES_COL_ENGINE, &searchEngine, -1);
105
106
    // TODO: Would it be better to not do this on every redraw?
107
    const gchar* icon = search_engine_get_icon(searchEngine);
108
    if(icon)
109
    {
110
        GdkPixbuf* pixbuf = load_web_icon(icon, GTK_ICON_SIZE_DND, treeview);
111
        g_object_set(renderer, "pixbuf", pixbuf, NULL);
112
        if(pixbuf)
113
            g_object_unref(pixbuf);
114
    }
115
    else
116
        g_object_set(renderer, "pixbuf", NULL, NULL);
117
}
118
119
static void on_webSearch_engines_render_text(GtkTreeViewColumn* column
120
 , GtkCellRenderer* renderer, GtkTreeModel* model, GtkTreeIter* iter
121
 , GtkWidget* treeview)
122
{
123
    SearchEngine* searchEngine;
124
    gtk_tree_model_get(model, iter, ENGINES_COL_ENGINE, &searchEngine, -1);
125
    const gchar* name = search_engine_get_short_name(searchEngine);
126
    const gchar* description = search_engine_get_description(searchEngine);
27 by Christian Dywan
Escape search engine name and description.
127
    gchar* markup = g_markup_printf_escaped("<b>%s</b>\n%s", name, description);
1 by Christian Dywan
Initial commit
128
    g_object_set(renderer, "markup", markup, NULL);
129
    g_free(markup);
130
}
131
132
static void webSearch_toggle_edit_buttons(gboolean sensitive, CWebSearch* webSearch)
133
{
134
    gtk_widget_set_sensitive(webSearch->edit, sensitive);
135
    gtk_widget_set_sensitive(webSearch->remove, sensitive);
136
}
137
138
static void on_webSearch_shortName_changed(GtkWidget* widget, GtkWidget* dialog)
139
{
140
    const gchar* text = gtk_entry_get_text(GTK_ENTRY(widget));
141
    gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog)
142
     , GTK_RESPONSE_ACCEPT, text && *text);
143
}
144
145
const gchar* STR_NON_NULL(const gchar* string)
146
{
147
    return string ? string : "";
148
}
149
150
static void webSearch_editEngine_dialog_new(gboolean newEngine, CWebSearch* webSearch)
151
{
152
    GtkWidget* dialog = gtk_dialog_new_with_buttons(
44 by Christian Dywan
Implement localization via Gettext.
153
        newEngine ? _("Add search engine") : _("Edit search engine")
1 by Christian Dywan
Initial commit
154
        , GTK_WINDOW(webSearch->window)
155
        , GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR
156
        , GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL
157
        , newEngine ? GTK_STOCK_ADD : GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT
158
        , NULL);
159
    gtk_window_set_icon_name(GTK_WINDOW(dialog)
160
     , newEngine ? GTK_STOCK_ADD : GTK_STOCK_REMOVE);
161
    gtk_container_set_border_width(GTK_CONTAINER(dialog), 5);
162
    gtk_container_set_border_width(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), 5);
163
    GtkSizeGroup* sizegroup =  gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
164
165
    SearchEngine* searchEngine;
166
    GtkTreeModel* liststore;
167
    GtkTreeIter iter;
168
    if(newEngine)
169
    {
170
        searchEngine = search_engine_new();
171
        gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog)
172
         , GTK_RESPONSE_ACCEPT, FALSE);
173
    }
174
    else
175
    {
176
        GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(webSearch->treeview));
177
        gtk_tree_selection_get_selected(selection, &liststore, &iter);
178
        gtk_tree_model_get(liststore, &iter, ENGINES_COL_ENGINE, &searchEngine, -1);
179
    }
180
181
    GtkWidget* hbox = gtk_hbox_new(FALSE, 8);
182
    gtk_container_set_border_width(GTK_CONTAINER(hbox), 5);
44 by Christian Dywan
Implement localization via Gettext.
183
    GtkWidget* label = gtk_label_new_with_mnemonic(_("_Name:"));
1 by Christian Dywan
Initial commit
184
    gtk_size_group_add_widget(sizegroup, label);
185
    gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
186
    GtkWidget* entry_shortName = gtk_entry_new();
187
    g_signal_connect(entry_shortName, "changed"
188
     , G_CALLBACK(on_webSearch_shortName_changed), dialog);
189
    gtk_entry_set_activates_default(GTK_ENTRY(entry_shortName), TRUE);
190
    if(!newEngine)
191
        gtk_entry_set_text(GTK_ENTRY(entry_shortName)
192
         , search_engine_get_short_name(searchEngine));
193
    gtk_box_pack_start(GTK_BOX(hbox), entry_shortName, TRUE, TRUE, 0);
194
    gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), hbox);
195
    gtk_widget_show_all(hbox);
196
    
197
    hbox = gtk_hbox_new(FALSE, 8);
198
    gtk_container_set_border_width(GTK_CONTAINER(hbox), 5);
44 by Christian Dywan
Implement localization via Gettext.
199
    label = gtk_label_new_with_mnemonic(_("_Description:"));
1 by Christian Dywan
Initial commit
200
    gtk_size_group_add_widget(sizegroup, label);
201
    gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
202
    GtkWidget* entry_description = gtk_entry_new();
203
    gtk_entry_set_activates_default(GTK_ENTRY(entry_description), TRUE);
204
    if(!newEngine)
205
        gtk_entry_set_text(GTK_ENTRY(entry_description)
206
         , STR_NON_NULL(search_engine_get_description(searchEngine)));
207
    gtk_box_pack_start(GTK_BOX(hbox), entry_description, TRUE, TRUE, 0);
208
    gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), hbox);
209
    gtk_widget_show_all(hbox);
210
    
211
    hbox = gtk_hbox_new(FALSE, 8);
212
    gtk_container_set_border_width(GTK_CONTAINER(hbox), 5);
44 by Christian Dywan
Implement localization via Gettext.
213
    label = gtk_label_new_with_mnemonic(_("_URL:"));
1 by Christian Dywan
Initial commit
214
    gtk_size_group_add_widget(sizegroup, label);
215
    gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
216
    GtkWidget* entry_url = gtk_entry_new();
217
    gtk_entry_set_activates_default(GTK_ENTRY(entry_url), TRUE);
218
    if(!newEngine)
219
        gtk_entry_set_text(GTK_ENTRY(entry_url)
220
         , STR_NON_NULL(search_engine_get_url(searchEngine)));
221
    gtk_box_pack_start(GTK_BOX(hbox), entry_url, TRUE, TRUE, 0);
222
    gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), hbox);
223
    gtk_widget_show_all(hbox);
224
    
225
    hbox = gtk_hbox_new(FALSE, 8);
226
    gtk_container_set_border_width(GTK_CONTAINER(hbox), 5);
44 by Christian Dywan
Implement localization via Gettext.
227
    label = gtk_label_new_with_mnemonic(_("_Icon (name or file):"));
1 by Christian Dywan
Initial commit
228
    gtk_size_group_add_widget(sizegroup, label);
229
    gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
230
    GtkWidget* entry_icon = gtk_entry_new();
231
    gtk_entry_set_activates_default(GTK_ENTRY(entry_icon), TRUE);
232
    if(!newEngine)
233
        gtk_entry_set_text(GTK_ENTRY(entry_icon)
234
         , STR_NON_NULL(search_engine_get_icon(searchEngine)));
235
    gtk_box_pack_start(GTK_BOX(hbox), entry_icon, TRUE, TRUE, 0);
236
    gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), hbox);
237
    gtk_widget_show_all(hbox);
238
    
239
    hbox = gtk_hbox_new(FALSE, 8);
240
    gtk_container_set_border_width(GTK_CONTAINER(hbox), 5);
44 by Christian Dywan
Implement localization via Gettext.
241
    label = gtk_label_new_with_mnemonic(_("_Keyword:"));
1 by Christian Dywan
Initial commit
242
    gtk_size_group_add_widget(sizegroup, label);
243
    gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
244
    GtkWidget* entry_keyword = gtk_entry_new();
245
    gtk_entry_set_activates_default(GTK_ENTRY(entry_keyword), TRUE);
246
    if(!newEngine)
247
        gtk_entry_set_text(GTK_ENTRY(entry_keyword)
248
         , STR_NON_NULL(search_engine_get_keyword(searchEngine)));
249
    gtk_box_pack_start(GTK_BOX(hbox), entry_keyword, TRUE, TRUE, 0);
250
    gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), hbox);
251
    gtk_widget_show_all(hbox);
252
253
    gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
254
    if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
255
    {
256
        search_engine_set_short_name(searchEngine
257
         , gtk_entry_get_text(GTK_ENTRY(entry_shortName)));
258
        search_engine_set_description(searchEngine
259
         , gtk_entry_get_text(GTK_ENTRY(entry_description)));
260
        search_engine_set_url(searchEngine
261
         , gtk_entry_get_text(GTK_ENTRY(entry_url)));
262
        /*search_engine_set_input_encoding(searchEngine
263
         , gtk_entry_get_text(GTK_ENTRY(entry_inputEncoding)));*/
264
        search_engine_set_icon(searchEngine
265
         , gtk_entry_get_text(GTK_ENTRY(entry_icon)));
266
        search_engine_set_keyword(searchEngine
267
         , gtk_entry_get_text(GTK_ENTRY(entry_keyword)));
268
269
        if(newEngine)
270
        {
271
            searchEngines = g_list_append(searchEngines, searchEngine);
272
            liststore = gtk_tree_view_get_model(GTK_TREE_VIEW(webSearch->treeview));
273
            gtk_list_store_append(GTK_LIST_STORE(liststore), &iter);
274
        }
275
        gtk_list_store_set(GTK_LIST_STORE(liststore), &iter
276
             , ENGINES_COL_ENGINE, searchEngine, -1);
277
        webSearch_toggle_edit_buttons(TRUE, webSearch);
278
    }
279
    gtk_widget_destroy(dialog);
280
}
281
282
static void on_webSearch_add(GtkWidget* widget, CWebSearch* webSearch)
283
{
284
    webSearch_editEngine_dialog_new(TRUE, webSearch);
285
}
286
287
static void on_webSearch_edit(GtkWidget* widget, CWebSearch* webSearch)
288
{
289
    webSearch_editEngine_dialog_new(FALSE, webSearch);
290
}
291
292
static void on_webSearch_remove(GtkWidget* widget, CWebSearch* webSearch)
293
{
294
    GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(webSearch->treeview));
295
    GtkTreeModel* liststore;
296
    GtkTreeIter iter;
297
    gtk_tree_selection_get_selected(selection, &liststore, &iter);
298
    SearchEngine* searchEngine;
299
    gtk_tree_model_get(liststore, &iter, ENGINES_COL_ENGINE, &searchEngine, -1);
300
    gtk_list_store_remove(GTK_LIST_STORE(liststore), &iter);
301
    search_engine_free(searchEngine);
302
    searchEngines = g_list_remove(searchEngines, searchEngine);
38 by Christian Dywan
Initial refactoring work, regressions expected
303
    //update_searchEngine(config->searchEngine, webSearch->browser);
1 by Christian Dywan
Initial commit
304
    webSearch_toggle_edit_buttons(g_list_nth(searchEngines, 0) != NULL, webSearch);
305
    // FIXME: we want to allow undo of some kind
306
}
307
38 by Christian Dywan
Initial refactoring work, regressions expected
308
GtkWidget* webSearch_manageSearchEngines_dialog_new(MidoriBrowser* browser)
1 by Christian Dywan
Initial commit
309
{
44 by Christian Dywan
Implement localization via Gettext.
310
    const gchar* dialogTitle = _("Manage search engines");
1 by Christian Dywan
Initial commit
311
    GtkWidget* dialog = gtk_dialog_new_with_buttons(dialogTitle
38 by Christian Dywan
Initial refactoring work, regressions expected
312
        , GTK_WINDOW(browser)
1 by Christian Dywan
Initial commit
313
        , GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR
314
        , GTK_STOCK_HELP
315
        , GTK_RESPONSE_HELP
316
        , GTK_STOCK_CLOSE
317
        , GTK_RESPONSE_CLOSE
318
        , NULL);
319
    gtk_window_set_icon_name(GTK_WINDOW(dialog), GTK_STOCK_PROPERTIES);
320
    // TODO: Implement some kind of help function
321
    gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog)
322
     , GTK_RESPONSE_HELP, FALSE); //...
323
    gint iWidth, iHeight;
324
    sokoke_widget_get_text_size(dialog, "M", &iWidth, &iHeight);
325
    gtk_window_set_default_size(GTK_WINDOW(dialog), iWidth * 45, -1);
326
    g_signal_connect(dialog, "response", G_CALLBACK(gtk_widget_destroy), dialog);
327
    // TODO: Do we want tooltips for explainations or can we omit that?
328
    // TODO: We need mnemonics
329
    // TODO: Take multiple windows into account when applying changes
330
    GtkWidget* xfce_heading;
331
    if((xfce_heading = sokoke_xfce_header_new(
332
     gtk_window_get_icon_name(GTK_WINDOW(dialog)), dialogTitle)))
333
        gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), xfce_heading, FALSE, FALSE, 0);
334
    GtkWidget* hbox = gtk_hbox_new(FALSE, 0);
335
    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox, TRUE, TRUE, 12);
336
    GtkTreeViewColumn* column;
337
    GtkCellRenderer* renderer_text; GtkCellRenderer* renderer_pixbuf;
338
    GtkListStore* liststore = gtk_list_store_new(ENGINES_COL_N
339
     , G_TYPE_SEARCH_ENGINE);
340
    GtkWidget* treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(liststore));
341
    gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), FALSE);
342
    column = gtk_tree_view_column_new();
343
    renderer_pixbuf = gtk_cell_renderer_pixbuf_new();
344
    gtk_tree_view_column_pack_start(column, renderer_pixbuf, FALSE);
345
    gtk_tree_view_column_set_cell_data_func(column, renderer_pixbuf
346
    , (GtkTreeCellDataFunc)on_webSearch_engines_render_icon, treeview, NULL);
347
    renderer_text = gtk_cell_renderer_text_new();
348
    gtk_tree_view_column_pack_start(column, renderer_text, TRUE);
349
    gtk_tree_view_column_set_cell_data_func(column, renderer_text
350
    , (GtkTreeCellDataFunc)on_webSearch_engines_render_text, treeview, NULL);
351
    gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
352
    GtkWidget* scrolled = gtk_scrolled_window_new(NULL, NULL);
353
    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled)
354
    , GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
355
    gtk_container_add(GTK_CONTAINER(scrolled), treeview);
356
    gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN);
357
    gtk_box_pack_start(GTK_BOX(hbox), scrolled, TRUE, TRUE, 5);
358
    guint n = g_list_length(searchEngines);
359
    guint i;
360
    for(i = 0; i < n; i++)
361
    {
362
        SearchEngine* searchEngine = (SearchEngine*)g_list_nth_data(searchEngines, i);
363
        gtk_list_store_insert_with_values(GTK_LIST_STORE(liststore), NULL, i
364
         , ENGINES_COL_ENGINE, searchEngine, -1);
365
    }
366
    g_object_unref(liststore);
367
    CWebSearch* webSearch = g_new0(CWebSearch, 1);
368
    webSearch->browser = browser;
369
    webSearch->window = dialog;
370
    webSearch->treeview = treeview;
371
    g_signal_connect(dialog, "response", G_CALLBACK(g_free), webSearch);
372
    GtkWidget* vbox = gtk_vbox_new(FALSE, 4);
373
    gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 4);
374
    GtkWidget* button = gtk_button_new_from_stock(GTK_STOCK_ADD);
375
    g_signal_connect(button, "clicked", G_CALLBACK(on_webSearch_add), webSearch);
376
    gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0);
377
    button = gtk_button_new_from_stock(GTK_STOCK_EDIT);
378
    g_signal_connect(button, "clicked", G_CALLBACK(on_webSearch_edit), webSearch);
379
    gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0);
380
    webSearch->edit = button;
381
    button = gtk_button_new_from_stock(GTK_STOCK_REMOVE);
382
    g_signal_connect(button, "clicked", G_CALLBACK(on_webSearch_remove), webSearch);
383
    gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0);
384
    webSearch->remove = button;
385
    button = gtk_label_new(""); // This is an invisible separator
386
    gtk_box_pack_start(GTK_BOX(vbox), button, TRUE, TRUE, 12);
387
    button = gtk_button_new_from_stock(GTK_STOCK_GO_DOWN);
388
    gtk_widget_set_sensitive(button, FALSE); //...
389
    gtk_box_pack_end(GTK_BOX(vbox), button, FALSE, FALSE, 0);
390
    button = gtk_button_new_from_stock(GTK_STOCK_GO_UP);
391
    gtk_widget_set_sensitive(button, FALSE); //...
392
    gtk_box_pack_end(GTK_BOX(vbox), button, FALSE, FALSE, 0);
393
    webSearch_toggle_edit_buttons(n > 0, webSearch);
394
    gtk_widget_show_all(GTK_DIALOG(dialog)->vbox);
395
    return dialog;
396
}
397
38 by Christian Dywan
Initial refactoring work, regressions expected
398
gboolean on_webSearch_key_down(GtkWidget* widget, GdkEventKey* event, MidoriBrowser* browser)
1 by Christian Dywan
Initial commit
399
{
400
    GdkModifierType state = (GdkModifierType)0;
401
    gint x, y; gdk_window_get_pointer(NULL, &x, &y, &state);
402
    if(!(state & GDK_CONTROL_MASK))
403
        return FALSE;
404
    switch(event->keyval)
405
    {
406
    case GDK_Up:
38 by Christian Dywan
Initial refactoring work, regressions expected
407
        //update_searchEngine(config->searchEngine - 1, browser);
1 by Christian Dywan
Initial commit
408
        return TRUE;
409
    case GDK_Down:
38 by Christian Dywan
Initial refactoring work, regressions expected
410
        //update_searchEngine(config->searchEngine + 1, browser);
1 by Christian Dywan
Initial commit
411
        return TRUE;
412
    }
413
    return FALSE;
414
}
415
38 by Christian Dywan
Initial refactoring work, regressions expected
416
gboolean on_webSearch_scroll(GtkWidget* webView, GdkEventScroll* event, MidoriBrowser* browser)
1 by Christian Dywan
Initial commit
417
{
418
    if(event->direction == GDK_SCROLL_DOWN)
38 by Christian Dywan
Initial refactoring work, regressions expected
419
        ;//update_searchEngine(config->searchEngine + 1, browser);
1 by Christian Dywan
Initial commit
420
    else if(event->direction == GDK_SCROLL_UP)
38 by Christian Dywan
Initial refactoring work, regressions expected
421
        ;//update_searchEngine(config->searchEngine - 1, browser);
1 by Christian Dywan
Initial commit
422
    return TRUE;
423
}
424
38 by Christian Dywan
Initial refactoring work, regressions expected
425
void on_webSearch_activate(GtkWidget* widget, MidoriBrowser* browser)
1 by Christian Dywan
Initial commit
426
{
427
    const gchar* keywords = gtk_entry_get_text(GTK_ENTRY(widget));
428
    gchar* url;
429
    SearchEngine* searchEngine = (SearchEngine*)g_list_nth_data(searchEngines, config->searchEngine);
430
    if(searchEngine)
431
        url = searchEngine->url;
432
    else // The location search is our fallback
433
     url = config->locationSearch;
434
    gchar* search;
435
    if(strstr(url, "%s"))
436
     search = g_strdup_printf(url, keywords);
437
    else
438
     search = g_strconcat(url, " ", keywords, NULL);
439
    entry_completion_append(GTK_ENTRY(widget), keywords);
38 by Christian Dywan
Initial refactoring work, regressions expected
440
    GtkWidget* webView = midori_browser_get_current_web_view(browser);
441
    webkit_web_view_open(WEBKIT_WEB_VIEW(webView), search);
1 by Christian Dywan
Initial commit
442
    g_free(search);
443
}