aboutsummaryrefslogblamecommitdiffstats
path: root/src/ephy-toolbar.c
blob: 729322109acc840ff57754426e91fae4d3abdeab (plain) (tree)
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502










































































                                                                                                                       

                              








































































































































































































































































































































































































































                                                                                                                

                                                 

                                    
                                                     

                                                
                                                                         
                            


    












                                                                         






























































































































                                                                                      
                                                                                               






































































































































































                                                                                             
/*
 *  Copyright (C) 2000-2004 Marco Pesenti Gritti
 *  Copyright (C) 2001, 2002 Jorn Baayen
 *  Copyright (C) 2003, 2004, 2005 Christian Persch
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2, or (at your option)
 *  any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 *  $Id$
 */

#include "config.h"

#include "ephy-toolbar.h"
#include "ephy-link.h"
#include "ephy-go-action.h"
#include "ephy-home-action.h"
#include "ephy-location-entry.h"
#include "ephy-location-action.h"
#include "ephy-navigation-action.h"
#include "ephy-topic-action.h"
#include "ephy-zoom-action.h"
#include "ephy-spinner.h"
#include "ephy-dnd.h"
#include "ephy-shell.h"
#include "ephy-stock-icons.h"
#include "window-commands.h"
#include "eel-gconf-extensions.h"
#include "ephy-debug.h"

#include <glib/gi18n.h>
#include <gtk/gtkstock.h>
#include <gtk/gtkuimanager.h>
#include <gtk/gtktoolitem.h>
#include <gtk/gtktoolbutton.h>
#include <gtk/gtkseparatortoolitem.h>
#include <gtk/gtktoolbar.h>
#include <string.h>

enum
{
    BACK_ACTION,
    FORWARD_ACTION,
    UP_ACTION,
    LOCATION_ACTION,
    ZOOM_ACTION,
    LAST_ACTION
};

#define EPHY_TOOLBAR_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_TOOLBAR, EphyToolbarPrivate))

struct _EphyToolbarPrivate
{
    EphyWindow *window;
    GtkActionGroup *action_group;
    GtkAction *actions[LAST_ACTION];
    gboolean updating_address;
    GtkWidget *fixed_toolbar;
    GtkWidget *spinner;
    GtkToolItem *spinner_item;
    GtkToolItem *sep_item;
    GtkToolItem *exit_button;
    guint disable_arbitrary_url_notifier_id;
    gulong set_focus_handler;
    gboolean show_lock;
    gboolean lock_visible;
    gboolean fullscreen;
    gboolean spinning;
};

static GtkTargetEntry drag_targets[] =
{
    { EGG_TOOLBAR_ITEM_TYPE, GTK_TARGET_SAME_APP, 0 },
    { EPHY_DND_TOPIC_TYPE,   0,        1 },
    { EPHY_DND_URL_TYPE,     0,           2 }
};

#define CONF_LOCKDOWN_DISABLE_ARBITRARY_URL  "/apps/epiphany/lockdown/disable_arbitrary_url"

enum
{
    PROP_0,
    PROP_WINDOW
};

enum
{
    ACTIVATION_FINISHED,
    EXIT_CLICKED,
    LOCK_CLICKED,
    LAST_SIGNAL
};

static guint signals[LAST_SIGNAL] = { 0 };

static GObjectClass *parent_class = NULL;

/* helper functions */

static void
exit_button_clicked_cb (GtkWidget *button,
            EphyToolbar *toolbar)
{
    g_signal_emit (toolbar, signals[EXIT_CLICKED], 0);
}

static void
ephy_toolbar_update_fixed_visibility (EphyToolbar *toolbar)
{
    EphyToolbarPrivate *priv = toolbar->priv;

    g_object_set (priv->sep_item, "visible", priv->fullscreen, NULL);
    g_object_set (priv->exit_button, "visible", priv->fullscreen,
                     "sensitive", priv->fullscreen, NULL);
}

static void
ephy_toolbar_update_spinner (EphyToolbar *toolbar)
{
    GtkWidget *widget = GTK_WIDGET (toolbar);
    EphyToolbarPrivate *priv = toolbar->priv;

    if (priv->spinning && GTK_WIDGET_VISIBLE (widget))
    {
        ephy_spinner_start (EPHY_SPINNER (priv->spinner));
    }
    else
    {
        ephy_spinner_stop (EPHY_SPINNER (priv->spinner));
    }
}

static void
fixed_toolbar_reconfigured_cb (GtkToolItem *item,
                   EphySpinner *spinner)
{
    GtkToolbarStyle style;
    GtkIconSize size;

    style = gtk_tool_item_get_toolbar_style (item);

    if (style == GTK_TOOLBAR_BOTH)
    {
        size = GTK_ICON_SIZE_INVALID;
    }
    else
    {
        size = GTK_ICON_SIZE_LARGE_TOOLBAR;
    }

    ephy_spinner_set_size (spinner, size);
}

static void
toolbar_added_cb (EggToolbarsModel *model,
          int position,
          EggEditableToolbar *toolbar)
{
    const char *t_name;

    t_name = egg_toolbars_model_toolbar_nth (model, position);
    g_return_if_fail (t_name != NULL);

    egg_editable_toolbar_set_drag_dest
        (toolbar, drag_targets, G_N_ELEMENTS (drag_targets), t_name);
}

static void 
maybe_finish_activation_cb (EphyWindow *window,
                GtkWidget *widget,
                EphyToolbar *toolbar)
{
    EphyToolbarPrivate *priv = toolbar->priv;
    GtkWidget *wtoolbar = GTK_WIDGET (toolbar);

    while (widget != NULL && widget != wtoolbar)
    {
        widget = widget->parent;
    }

    /* if widget == toolbar, the new focus widget is in the toolbar, so we
     * don't deactivate.
     */
    if (widget != wtoolbar)
    {
        g_signal_handler_disconnect (window, priv->set_focus_handler);
        toolbar->priv->set_focus_handler = 0;

        g_signal_emit (toolbar, signals[ACTIVATION_FINISHED], 0);
    }
}

static void
update_location_editable (EphyToolbar *toolbar)
{
    EphyToolbarPrivate *priv = toolbar->priv;
    EphyEmbed *embed;
    char *address;
    gboolean editable;

    editable = !eel_gconf_get_boolean (CONF_LOCKDOWN_DISABLE_ARBITRARY_URL);

    g_object_set (priv->actions[LOCATION_ACTION], "editable", editable, NULL);

    /* Restore the real web page address when disabling entry */
    if (editable == FALSE)
    {
        embed = ephy_window_get_active_embed (priv->window);
        /* embed is NULL on startup */
        if (EPHY_IS_EMBED (embed))
        {
            address = ephy_embed_get_location (embed, TRUE);
            ephy_toolbar_set_location (toolbar, address);
            g_free (address);
        }
    }
}

static void
sync_user_input_cb (EphyLocationAction *action,
            GParamSpec *pspec,
            EphyToolbar *toolbar)
{
    EphyToolbarPrivate *priv = toolbar->priv;
    EphyTab *tab;
    const char *address;

    LOG ("sync_user_input_cb")

    if (priv->updating_address) return;

    tab = ephy_window_get_active_tab (priv->window);
    g_return_if_fail (EPHY_IS_TAB (tab));

    address = ephy_location_action_get_address (action);

    priv->updating_address = TRUE;
    ephy_tab_set_location (tab, address, EPHY_TAB_ADDRESS_EXPIRE_CURRENT);
    priv->updating_address = FALSE;
}

static void
zoom_to_level_cb (GtkAction *action,
          float zoom,
          EphyToolbar *toolbar)
{
    ephy_window_set_zoom (toolbar->priv->window, zoom);
}

static void
arbitrary_url_notifier (GConfClient *client,
            guint cnxn_id,
            GConfEntry *entry,
            EphyToolbar *toolbar)
{
    update_location_editable (toolbar);
}

static void
ephy_toolbar_set_window (EphyToolbar *toolbar,
             EphyWindow *window)
{
    EphyToolbarPrivate *priv = toolbar->priv;
    GtkUIManager *manager;
    GtkAction *action;

    priv->window = window;
    manager = GTK_UI_MANAGER (ephy_window_get_ui_manager (window));

    priv->action_group = gtk_action_group_new ("SpecialToolbarActions");
    gtk_ui_manager_insert_action_group (manager, priv->action_group, -1);
    g_object_unref (priv->action_group);

    action = priv->actions[BACK_ACTION] =
        g_object_new (EPHY_TYPE_NAVIGATION_ACTION,
                  "name", "NavigationBack",
                  "label", _("Back"),
                  "stock_id", GTK_STOCK_GO_BACK,
                  "tooltip", _("Go back"),
                  /* this is the tooltip on the Back button's drop-down arrow, which will show
                   * a menu with all sites you can go 'back' to
                   */
                  "arrow-tooltip", _("Back history"),
                  "window", priv->window,
                  "direction", EPHY_NAVIGATION_DIRECTION_BACK,
                  "is_important", TRUE,
                  NULL);
    g_signal_connect (action, "activate",
              G_CALLBACK (window_cmd_go_back), priv->window);
    gtk_action_group_add_action (priv->action_group, action);
    g_object_unref (action);

    action = priv->actions[FORWARD_ACTION] =
        g_object_new (EPHY_TYPE_NAVIGATION_ACTION,
                  "name", "NavigationForward",
                  "label", _("Forward"),
                  "stock_id", GTK_STOCK_GO_FORWARD,
                  "tooltip", _("Go forward"),
                  /* this is the tooltip on the Forward button's drop-down arrow, which will show
                   * a menu with all sites you can go 'forward' to
                   */
                  "arrow-tooltip", _("Forward history"),
                  "window", priv->window,
                  "direction", EPHY_NAVIGATION_DIRECTION_FORWARD,
                  NULL);
    g_signal_connect (action, "activate",
              G_CALLBACK (window_cmd_go_forward), priv->window);
    gtk_action_group_add_action (priv->action_group, action);
    g_object_unref (action);

    action = priv->actions[UP_ACTION] =
        g_object_new (EPHY_TYPE_NAVIGATION_ACTION,
                  "name", "NavigationUp",
                  "label", _("Up"),
                  "stock_id", GTK_STOCK_GO_UP,
                  "tooltip", _("Go up one level"),
                  /* this is the tooltip on the Up button's drop-down arrow, which will show
                   * a menu with al sites you can go 'up' to
                   */
                  "arrow-tooltip", _("List of upper levels"),
                  "window", priv->window,
                  "direction", EPHY_NAVIGATION_DIRECTION_UP,
                  NULL);
    g_signal_connect (action, "activate",
              G_CALLBACK (window_cmd_go_up), priv->window);
    g_signal_connect_swapped (action, "open-link",
                  G_CALLBACK (ephy_link_open), toolbar);
    gtk_action_group_add_action (priv->action_group, action);
    g_object_unref (action);

    /* FIXME: I'm still waiting for the exact term to 
     * user here from the docs team.
     */
    action = priv->actions[LOCATION_ACTION] =
        g_object_new (EPHY_TYPE_LOCATION_ACTION,
                  "name", "Location",
                  "label", _("Address Entry"),
                  "stock_id", EPHY_STOCK_ENTRY,
                  "tooltip", _("Enter a web address to open, or a phrase to search for on the web"),
                  "visible-overflown", FALSE,
                  "window", priv->window,
                  NULL);
    g_signal_connect_swapped (action, "open-link",
                  G_CALLBACK (ephy_link_open), toolbar);
    g_signal_connect (action, "notify::address",
              G_CALLBACK (sync_user_input_cb), toolbar);
    gtk_action_group_add_action (priv->action_group, action);
    update_location_editable (toolbar);
    g_object_unref (action);

    action = priv->actions[ZOOM_ACTION] =
        g_object_new (EPHY_TYPE_ZOOM_ACTION,
                  "name", "Zoom",
                  "label", _("Zoom"),
                  "stock_id", GTK_STOCK_ZOOM_IN,
                  "tooltip", _("Adjust the text size"),
                  "zoom", 1.0,
                  NULL);
    g_signal_connect (action, "zoom_to_level",
              G_CALLBACK (zoom_to_level_cb), toolbar);
    gtk_action_group_add_action (priv->action_group, action);
    g_object_unref (action);

    action = g_object_new (EPHY_TYPE_GO_ACTION,
                   "name", "ToolbarGo",
                   "label", _("Go"),
                   "stock_id", GTK_STOCK_JUMP_TO,
                   "tooltip", _("Go to the address entered in the address entry"),
                   NULL);
    g_signal_connect (action, "activate",
              G_CALLBACK (window_cmd_load_location), priv->window);
    gtk_action_group_add_action (priv->action_group, action);
    g_object_unref (action);

    action = g_object_new (EPHY_TYPE_HOME_ACTION,
                   "name", "GoHome",
                   "label", _("_Home"),
                   "stock_id", GTK_STOCK_HOME,
                   "tooltip", _("Go to the home page"),
                   "is_important", TRUE,
                   NULL);
    g_signal_connect_swapped (action, "open-link",
                  G_CALLBACK (ephy_link_open), toolbar);
    gtk_action_group_add_action_with_accel (priv->action_group, action, "<alt>Home");
    g_object_unref (action);

    priv->disable_arbitrary_url_notifier_id = eel_gconf_notification_add
        (CONF_LOCKDOWN_DISABLE_ARBITRARY_URL,
         (GConfClientNotifyFunc) arbitrary_url_notifier, toolbar);
}

/* public functions */

void
ephy_toolbar_set_favicon (EphyToolbar *toolbar,
              const char *icon)
{
    EphyToolbarPrivate *priv = toolbar->priv;

    g_object_set (priv->actions[LOCATION_ACTION], "icon", icon, NULL);
}

void
ephy_toolbar_set_fullscreen_mode (EphyToolbar *toolbar,
                  gboolean fullscreen)
{
    EphyToolbarPrivate *priv = toolbar->priv;

    priv->fullscreen = fullscreen;

    ephy_toolbar_update_fixed_visibility (toolbar);
}

void
ephy_toolbar_activate_location (EphyToolbar *toolbar)
{
    EphyToolbarPrivate *priv = toolbar->priv;
    GSList *proxies;
    GtkWidget *entry = NULL;
    gboolean visible;

    proxies = gtk_action_get_proxies (priv->actions[LOCATION_ACTION]);

    if (proxies != NULL && EPHY_IS_LOCATION_ENTRY (proxies->data))
    {
        entry = GTK_WIDGET (proxies->data);
    }

    if (entry == NULL)
    {
        /* happens when the user has removed the location entry from
         * the toolbars.
         */
        return;
    }

    g_object_get (G_OBJECT (toolbar), "visible", &visible, NULL);
    if (visible == FALSE)
    {
        gtk_widget_show (GTK_WIDGET (toolbar));
        toolbar->priv->set_focus_handler =
            g_signal_connect (toolbar->priv->window, "set-focus",
                      G_CALLBACK (maybe_finish_activation_cb),
                      toolbar);
    }

    ephy_location_entry_activate (EPHY_LOCATION_ENTRY (entry));
}

const char *
ephy_toolbar_get_location (EphyToolbar *toolbar)
{
    EphyToolbarPrivate *priv = toolbar->priv;
    EphyLocationAction *action = EPHY_LOCATION_ACTION (priv->actions[LOCATION_ACTION]);

    return ephy_location_action_get_address (action);
}

void
ephy_toolbar_set_location (EphyToolbar *toolbar,
               const char *address)
{
    EphyToolbarPrivate *priv = toolbar->priv;
    EphyLocationAction *action = EPHY_LOCATION_ACTION (priv->actions[LOCATION_ACTION]);
    
    if (priv->updating_address) return;

    priv->updating_address = TRUE;
    ephy_location_action_set_address (action, address);
    priv->updating_address = FALSE;
}

void
ephy_toolbar_set_navigation_actions (EphyToolbar *toolbar,
                     gboolean back,
                     gboolean forward,
                     gboolean up)
{
    EphyToolbarPrivate *priv = toolbar->priv;

    g_object_set (priv->actions[BACK_ACTION], "sensitive", back, NULL);
    g_object_set (priv->actions[FORWARD_ACTION], "sensitive", forward, NULL);
    g_object_set (priv->actions[UP_ACTION], "sensitive", up, NULL);
}

void
ephy_toolbar_set_security_state (EphyToolbar *toolbar,
                 gboolean show_lock,
                 const char *stock_id,
                 const char *tooltip)
{
    EphyToolbarPrivate *priv = toolbar->priv;

    priv->show_lock = show_lock;

    g_object_set (priv->actions[LOCATION_ACTION],
              "lock-stock-id", stock_id,
              "lock-tooltip", tooltip,
              "show-lock", priv->lock_visible && priv->show_lock,
              NULL);
}

void
ephy_toolbar_set_lock_visibility (EphyToolbar *toolbar,
                  gboolean visible)
{
    EphyToolbarPrivate *priv = toolbar->priv;

    priv->lock_visible = visible;

    g_object_set (priv->actions[LOCATION_ACTION],
              "show-lock", priv->lock_visible && priv->show_lock,
              NULL);
}
                
void
ephy_toolbar_set_spinning (EphyToolbar *toolbar,
               gboolean spinning)
{
    EphyToolbarPrivate *priv = toolbar->priv;

    priv->spinning = spinning;

    ephy_toolbar_update_spinner (toolbar);
}

void
ephy_toolbar_set_zoom (EphyToolbar *toolbar,
               gboolean can_zoom,
               float zoom)
{
    EphyToolbarPrivate *priv = toolbar->priv;

    g_object_set (priv->actions[ZOOM_ACTION],
              "zoom", can_zoom ? zoom : 1.0,
              "sensitive", can_zoom,
              NULL);
}

/* Class implementation */

static void
ephy_toolbar_realize (GtkWidget *widget)
{
    EggEditableToolbar *etoolbar = EGG_EDITABLE_TOOLBAR (widget);
    EphyToolbar *toolbar = EPHY_TOOLBAR (widget);
    EggToolbarsModel *model = egg_editable_toolbar_get_model (etoolbar);
    int i, n_toolbars;

    GTK_WIDGET_CLASS (parent_class)->realize (widget);

    g_signal_connect_after (model, "toolbar_added",
                G_CALLBACK (toolbar_added_cb), toolbar);

    /* now that the toolbar has been constructed, set drag dests */
    n_toolbars = egg_toolbars_model_n_toolbars (model);
    for (i = 0; i < n_toolbars; i++)
    {
        const char *t_name;

        t_name = egg_toolbars_model_toolbar_nth (model, i);
        g_return_if_fail (t_name != NULL);

        egg_editable_toolbar_set_drag_dest
            (etoolbar, drag_targets, G_N_ELEMENTS (drag_targets), t_name);
    }   
}

static void
ephy_toolbar_unrealize (GtkWidget *widget)
{
    EggEditableToolbar *eggtoolbar = EGG_EDITABLE_TOOLBAR (widget);
    EphyToolbar *toolbar = EPHY_TOOLBAR (widget);
    EggToolbarsModel *model;
 
    model = egg_editable_toolbar_get_model (eggtoolbar);

    g_signal_handlers_disconnect_by_func
        (model, G_CALLBACK (toolbar_added_cb), toolbar);

    GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
}

static void
ephy_toolbar_show (GtkWidget *widget)
{
    EphyToolbar *toolbar = EPHY_TOOLBAR (widget);

    GTK_WIDGET_CLASS (parent_class)->show (widget);

    ephy_toolbar_update_spinner (toolbar);
}

static void
ephy_toolbar_hide (GtkWidget *widget)
{
    EphyToolbar *toolbar = EPHY_TOOLBAR (widget);

    GTK_WIDGET_CLASS (parent_class)->hide (widget);

    ephy_toolbar_update_spinner (toolbar);
}

static void
ephy_toolbar_init (EphyToolbar *toolbar)
{
    toolbar->priv = EPHY_TOOLBAR_GET_PRIVATE (toolbar);
}

static GObject *
ephy_toolbar_constructor (GType type,
              guint n_construct_properties,
              GObjectConstructParam *construct_params)
{
    GObject *object;
    EphyToolbar *toolbar;
    EphyToolbarPrivate *priv;
    GtkToolbar *gtoolbar;

    object = parent_class->constructor (type, n_construct_properties,
                        construct_params);

    toolbar = EPHY_TOOLBAR (object);
    priv = toolbar->priv;

    priv->fixed_toolbar = gtk_toolbar_new ();
    gtoolbar = GTK_TOOLBAR (priv->fixed_toolbar);
    gtk_toolbar_set_show_arrow (gtoolbar, FALSE);

    priv->spinner = ephy_spinner_new ();
    gtk_widget_show (priv->spinner);

    priv->spinner_item = gtk_tool_item_new ();
    g_signal_connect (priv->spinner_item, "toolbar-reconfigured",
              G_CALLBACK (fixed_toolbar_reconfigured_cb), priv->spinner);
    gtk_container_add (GTK_CONTAINER (priv->spinner_item), priv->spinner);
    gtk_toolbar_insert (gtoolbar, priv->spinner_item, -1);
    gtk_widget_show (GTK_WIDGET (priv->spinner_item));

    priv->sep_item = gtk_separator_tool_item_new ();
    gtk_toolbar_insert (gtoolbar, priv->sep_item, -1);

    priv->exit_button = gtk_tool_button_new_from_stock (GTK_STOCK_QUIT);
    gtk_tool_button_set_label (GTK_TOOL_BUTTON (priv->exit_button), _("Leave Fullscreen"));
    gtk_tool_item_set_is_important (priv->exit_button, TRUE);
    g_signal_connect (priv->exit_button, "clicked",
              G_CALLBACK (exit_button_clicked_cb), toolbar);
    gtk_toolbar_insert (gtoolbar, priv->exit_button, -1);
    
    egg_editable_toolbar_set_fixed (EGG_EDITABLE_TOOLBAR (toolbar), gtoolbar);

    ephy_toolbar_update_fixed_visibility (toolbar);

    return object;
}

static void
ephy_toolbar_finalize (GObject *object)
{
    EphyToolbar *toolbar = EPHY_TOOLBAR (object);
    EphyToolbarPrivate *priv = toolbar->priv;
    EggEditableToolbar *etoolbar = EGG_EDITABLE_TOOLBAR (object);

    if (priv->set_focus_handler != 0)
    {
        g_signal_handler_disconnect (priv->window,
                         priv->set_focus_handler);
    }

    eel_gconf_notification_remove (priv->disable_arbitrary_url_notifier_id);

    g_signal_handlers_disconnect_by_func
        (egg_editable_toolbar_get_model (etoolbar),
         G_CALLBACK (toolbar_added_cb), toolbar);

    G_OBJECT_CLASS (parent_class)->finalize (object);
}

static void
ephy_toolbar_get_property (GObject *object,
               guint prop_id,
               GValue *value,
               GParamSpec *pspec)
{
    /* no readable properties */
    g_assert_not_reached ();
}

static void
ephy_toolbar_set_property (GObject *object,
               guint prop_id,
               const GValue *value,
               GParamSpec *pspec)
{
    EphyToolbar *toolbar = EPHY_TOOLBAR (object);

    switch (prop_id)
    {
        case PROP_WINDOW:
            ephy_toolbar_set_window (toolbar, g_value_get_object (value));
            break;
    }
}

static void
ephy_toolbar_class_init (EphyToolbarClass *klass)
{
    GObjectClass *object_class = G_OBJECT_CLASS (klass);
    GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);

    parent_class = g_type_class_peek_parent (klass);

    object_class->constructor = ephy_toolbar_constructor;
    object_class->finalize = ephy_toolbar_finalize;
    object_class->set_property = ephy_toolbar_set_property;
    object_class->get_property = ephy_toolbar_get_property;

    widget_class->realize = ephy_toolbar_realize;
    widget_class->unrealize = ephy_toolbar_unrealize;
    widget_class->show = ephy_toolbar_show;
    widget_class->hide = ephy_toolbar_hide;

    signals[ACTIVATION_FINISHED] =
        g_signal_new ("activation-finished",
                  G_OBJECT_CLASS_TYPE (object_class),
                  G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST,
                  G_STRUCT_OFFSET (EphyToolbarClass, activation_finished),
                  NULL, NULL,
                  g_cclosure_marshal_VOID__VOID,
                  G_TYPE_NONE,
                  0);

    signals[EXIT_CLICKED] =
        g_signal_new
            ("exit-clicked",
             EPHY_TYPE_TOOLBAR,
             G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST,
             G_STRUCT_OFFSET (EphyToolbarClass, exit_clicked),
             NULL, NULL,
             g_cclosure_marshal_VOID__VOID,
             G_TYPE_NONE,
             0);

    signals[LOCK_CLICKED] =
        g_signal_new
            ("lock-clicked",
             EPHY_TYPE_TOOLBAR,
             G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST,
             G_STRUCT_OFFSET (EphyToolbarClass, lock_clicked),
             NULL, NULL,
             g_cclosure_marshal_VOID__VOID,
             G_TYPE_NONE,
             0);

    g_object_class_install_property (object_class,
                     PROP_WINDOW,
                     g_param_spec_object ("window",
                                  "Window",
                                  "Parent window",
                                  EPHY_TYPE_WINDOW,
                                  G_PARAM_WRITABLE |
                                  G_PARAM_CONSTRUCT_ONLY));

    g_type_class_add_private (object_class, sizeof(EphyToolbarPrivate));
}

GType
ephy_toolbar_get_type (void)
{
    static GType type = 0;

    if (G_UNLIKELY (type == 0))
    {
        static const GTypeInfo our_info =
        {
            sizeof (EphyToolbarClass),
            NULL, /* base_init */
            NULL, /* base_finalize */
            (GClassInitFunc) ephy_toolbar_class_init,
            NULL,
            NULL, /* class_data */
            sizeof (EphyToolbar),
            0, /* n_preallocs */
            (GInstanceInitFunc) ephy_toolbar_init
        };
        static const GInterfaceInfo link_info = 
        {
            NULL,
            NULL,
            NULL
        };

        type = g_type_register_static (EGG_TYPE_EDITABLE_TOOLBAR,
                           "EphyToolbar",
                           &our_info, 0);
        g_type_add_interface_static (type,
                         EPHY_TYPE_LINK,
                         &link_info);
    }

    return type;
}

EphyToolbar *
ephy_toolbar_new (EphyWindow *window)
{
    return EPHY_TOOLBAR (g_object_new (EPHY_TYPE_TOOLBAR,
                       "window", window,
                       "ui-manager", ephy_window_get_ui_manager (window),
                       NULL));
}