diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/bookmarks/Makefile.am | 4 | ||||
-rw-r--r-- | src/bookmarks/ephy-bookmark-properties.c | 14 | ||||
-rw-r--r-- | src/bookmarks/ephy-bookmarks-editor.c | 43 | ||||
-rw-r--r-- | src/bookmarks/ephy-bookmarks.c | 115 | ||||
-rw-r--r-- | src/bookmarks/ephy-bookmarks.h | 114 | ||||
-rwxr-xr-x | src/bookmarks/ephy-bookmarksbar-model.c | 114 | ||||
-rwxr-xr-x | src/bookmarks/ephy-bookmarksbar-model.h | 26 | ||||
-rw-r--r-- | src/bookmarks/ephy-bookmarksbar.c | 60 | ||||
-rw-r--r-- | src/ephy-shell.c | 29 | ||||
-rw-r--r-- | src/ephy-shell.h | 7 | ||||
-rwxr-xr-x | src/ephy-toolbars-model.c | 551 | ||||
-rwxr-xr-x | src/ephy-toolbars-model.h | 29 | ||||
-rw-r--r-- | src/ephy-window.c | 95 | ||||
-rw-r--r-- | src/ephy-window.h | 2 | ||||
-rwxr-xr-x | src/toolbar.c | 407 | ||||
-rw-r--r-- | src/toolbar.h | 8 | ||||
-rw-r--r-- | src/window-commands.c | 42 |
18 files changed, 605 insertions, 1056 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 906a6a579..3c765c7cc 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -94,7 +94,6 @@ libephymain_la_SOURCES = \ ephy-tab.h \ ephy-tabs-menu.c \ ephy-toolbars-model.c \ - ephy-toolbars-model.h \ ephy-window.c \ pdm-dialog.c \ popup-commands.c \ diff --git a/src/bookmarks/Makefile.am b/src/bookmarks/Makefile.am index 104254cbf..3b2b130ae 100644 --- a/src/bookmarks/Makefile.am +++ b/src/bookmarks/Makefile.am @@ -29,6 +29,8 @@ NOINST_H_FILES = \ ephy-bookmarks-export.h \ ephy-bookmarks-import.h \ ephy-bookmarks-menu.h \ + ephy-bookmarksbar-model.h \ + ephy-bookmarksbar.h \ ephy-bookmark-properties.h \ ephy-new-bookmark.h \ ephy-topic-action.h \ @@ -41,6 +43,8 @@ libephybookmarks_la_SOURCES = \ ephy-bookmarks-export.c \ ephy-bookmarks-import.c \ ephy-bookmarks-menu.c \ + ephy-bookmarksbar-model.c \ + ephy-bookmarksbar.c \ ephy-bookmark-properties.c \ ephy-new-bookmark.c \ ephy-topic-action.c \ diff --git a/src/bookmarks/ephy-bookmark-properties.c b/src/bookmarks/ephy-bookmark-properties.c index 2b6325add..f984124b8 100644 --- a/src/bookmarks/ephy-bookmark-properties.c +++ b/src/bookmarks/ephy-bookmark-properties.c @@ -22,7 +22,7 @@ #include "config.h" #endif -#include "ephy-toolbars-model.h" +#include "ephy-bookmarksbar-model.h" #include "ephy-bookmark-properties.h" #include "ephy-topics-selector.h" #include "ephy-debug.h" @@ -64,7 +64,7 @@ struct EphyBookmarkPropertiesPrivate GtkWidget *location_entry; GtkWidget *topics_selector; - EphyToolbarsModel *tb_model; + EphyBookmarksBarModel *tb_model; }; enum @@ -155,6 +155,8 @@ ephy_bookmark_properties_set_property (GObject *object, { case PROP_BOOKMARKS: selector->priv->bookmarks = g_value_get_object (value); + selector->priv->tb_model = EPHY_BOOKMARKSBAR_MODEL + (ephy_bookmarks_get_toolbars_model (selector->priv->bookmarks)); break; case PROP_BOOKMARK: ephy_bookmark_properties_set_bookmark @@ -260,12 +262,12 @@ toolbar_checkbox_changed_cb (GtkWidget *checkbox, EphyBookmarkProperties *props) if (state) { - ephy_toolbars_model_add_bookmark + ephy_bookmarksbar_model_add_bookmark (props->priv->tb_model, FALSE, id); } else { - ephy_toolbars_model_remove_bookmark + ephy_bookmarksbar_model_remove_bookmark (props->priv->tb_model, id); } } @@ -402,7 +404,7 @@ build_ui (EphyBookmarkProperties *editor) checkbox = gtk_check_button_new_with_mnemonic (_("_Show in bookmarks bar")); id = ephy_node_get_id (editor->priv->bookmark); - state = ephy_toolbars_model_has_bookmark (editor->priv->tb_model, id); + state = ephy_bookmarksbar_model_has_bookmark (editor->priv->tb_model, id); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbox), state); g_signal_connect (checkbox, "toggled", G_CALLBACK (toolbar_checkbox_changed_cb), editor); @@ -427,8 +429,6 @@ ephy_bookmark_properties_init (EphyBookmarkProperties *editor) editor->priv = EPHY_BOOKMARK_PROPERTIES_GET_PRIVATE (editor); editor->priv->bookmark = NULL; - editor->priv->tb_model = EPHY_TOOLBARS_MODEL - (ephy_shell_get_toolbars_model (ephy_shell, FALSE)); } GtkWidget * diff --git a/src/bookmarks/ephy-bookmarks-editor.c b/src/bookmarks/ephy-bookmarks-editor.c index 5a8b71976..0cc0158a0 100644 --- a/src/bookmarks/ephy-bookmarks-editor.c +++ b/src/bookmarks/ephy-bookmarks-editor.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003 Marco Pesenti Gritti <mpeseng@tin.it> + * Copyright (C) 2003, 2004 Marco Pesenti Gritti <mpeseng@tin.it> * * 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 @@ -56,7 +56,7 @@ #include "ephy-gui.h" #include "ephy-stock-icons.h" #include "ephy-search-entry.h" -#include "ephy-toolbars-model.h" +#include "ephy-bookmarksbar-model.h" #include "ephy-favicon-cache.h" #include "eel-gconf-extensions.h" #include "ephy-debug.h" @@ -141,7 +141,7 @@ struct EphyBookmarksEditorPrivate GtkUIManager *ui_merge; GtkActionGroup *action_group; int priority_col; - EphyToolbarsModel *tb_model; + EphyBookmarksBarModel *tb_model; GHashTable *props_dialogs; GtkTreeViewColumn *title_col; @@ -322,6 +322,15 @@ get_target_window (EphyBookmarksEditor *editor) } static void +toolbar_items_changed_cb (EggToolbarsModel *model, + int toolbar_position, + int position, + EphyBookmarksEditor *editor) +{ + ephy_bookmarks_editor_update_menu (editor); +} + +static void cmd_show_in_bookmarks_bar (GtkAction *action, EphyBookmarksEditor *editor) { @@ -353,13 +362,19 @@ cmd_show_in_bookmarks_bar (GtkAction *action, if (state) { - ephy_toolbars_model_add_bookmark + ephy_bookmarksbar_model_add_bookmark (editor->priv->tb_model, topic, id); } else { - ephy_toolbars_model_remove_bookmark + g_signal_handlers_block_by_func + (editor->priv->tb_model, + G_CALLBACK (toolbar_items_changed_cb), editor); + ephy_bookmarksbar_model_remove_bookmark (editor->priv->tb_model, id); + g_signal_handlers_unblock_by_func + (editor->priv->tb_model, + G_CALLBACK (toolbar_items_changed_cb), editor); } g_list_free (selection); @@ -981,7 +996,7 @@ ephy_bookmarks_editor_update_menu (EphyBookmarksEditor *editor) gulong id; id = ephy_node_get_id (node); - show_in_bookmarks_bar = ephy_toolbars_model_has_bookmark + show_in_bookmarks_bar = ephy_bookmarksbar_model_has_bookmark (editor->priv->tb_model, id); priority = ephy_node_get_property_int @@ -1001,7 +1016,7 @@ ephy_bookmarks_editor_update_menu (EphyBookmarksEditor *editor) g_return_if_fail (node != NULL); id = ephy_node_get_id (node); - show_in_bookmarks_bar = ephy_toolbars_model_has_bookmark + show_in_bookmarks_bar = ephy_bookmarksbar_model_has_bookmark (editor->priv->tb_model, id); g_list_free (selected); @@ -1653,23 +1668,15 @@ ephy_bookmarks_editor_get_property (GObject *object, } static void -toolbar_items_changed_cb (EphyToolbarsModel *model, - int toolbar_position, - int position, - EphyBookmarksEditor *editor) -{ - ephy_bookmarks_editor_update_menu (editor); -} - -static void ephy_bookmarks_editor_init (EphyBookmarksEditor *editor) { editor->priv = EPHY_BOOKMARKS_EDITOR_GET_PRIVATE (editor); editor->priv->props_dialogs = g_hash_table_new (g_direct_hash, g_direct_equal); - editor->priv->tb_model = EPHY_TOOLBARS_MODEL - (ephy_shell_get_toolbars_model (ephy_shell, FALSE)); + editor->priv->tb_model = EPHY_BOOKMARKSBAR_MODEL + (ephy_bookmarks_get_toolbars_model + (ephy_shell_get_bookmarks (ephy_shell))); g_signal_connect (editor->priv->tb_model, "item_added", G_CALLBACK (toolbar_items_changed_cb), editor); diff --git a/src/bookmarks/ephy-bookmarks.c b/src/bookmarks/ephy-bookmarks.c index 6e765e6d6..be9884956 100644 --- a/src/bookmarks/ephy-bookmarks.c +++ b/src/bookmarks/ephy-bookmarks.c @@ -1,5 +1,6 @@ /* * Copyright (C) 2002-2004 Marco Pesenti Gritti + * Copyright (C) 2003, 2004 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 @@ -30,7 +31,7 @@ #include "ephy-debug.h" #include "ephy-tree-model-node.h" #include "ephy-node-common.h" -#include "ephy-toolbars-model.h" +#include "ephy-bookmarksbar-model.h" #include "ephy-bookmarks-export.h" #include "ephy-bookmarks-import.h" #include "ephy-prefs.h" @@ -50,7 +51,7 @@ struct EphyBookmarksPrivate { - EphyToolbarsModel *toolbars_model; + EphyBookmarksBarModel *toolbars_model; gboolean init_defaults; gboolean dirty; guint save_timeout_id; @@ -160,22 +161,84 @@ ephy_bookmarks_init_defaults (EphyBookmarks *eb) bmk = ephy_bookmarks_add (eb, _(default_bookmarks[i].title), _(default_bookmarks[i].location)); - ephy_toolbars_model_add_bookmark (eb->priv->toolbars_model, FALSE, - ephy_node_get_id (bmk)); + ephy_bookmarksbar_model_add_bookmark (eb->priv->toolbars_model, FALSE, + ephy_node_get_id (bmk)); } } -static void -ephy_bookmarks_set_toolbars_model (EphyBookmarks *eb, EphyToolbarsModel *model) +static char * +get_item_type_forward_cb (EggToolbarsModel *model, + GdkAtom type, + EggToolbarsModel *bookmarksbar_model) +{ + char *retval; + + g_signal_emit_by_name (bookmarksbar_model, "get_item_type", + type, &retval); + + return retval; +} + +static char * +get_item_id_forward_cb (EggToolbarsModel *model, + const char *type, + const char *name, + EggToolbarsModel *bookmarksbar_model) +{ + char *retval; + + g_signal_emit_by_name (bookmarksbar_model, "get_item_id", + type, name, &retval); + + return retval; +} + +static char * +get_item_data_forward_cb (EggToolbarsModel *model, + const char *type, + const char *id, + EggToolbarsModel *bookmarksbar_model) +{ + char *retval; + + g_signal_emit_by_name (bookmarksbar_model, "get_item_data", + type, id, &retval); + + return retval; +} + +EggToolbarsModel * +ephy_bookmarks_get_toolbars_model (EphyBookmarks *eb) { - eb->priv->toolbars_model = model; - g_object_add_weak_pointer (G_OBJECT(eb->priv->toolbars_model), - (gpointer *)&eb->priv->toolbars_model); + g_return_val_if_fail (EPHY_IS_BOOKMARKS (eb), NULL); - if (eb->priv->init_defaults) + if (eb->priv->toolbars_model == NULL) { - ephy_bookmarks_init_defaults (eb); + GObject *toolbars_model; + + eb->priv->toolbars_model = EPHY_BOOKMARKSBAR_MODEL + (ephy_bookmarksbar_model_new (eb)); + + /* forward those signals, so that bookmarks can also be on the main model */ + toolbars_model = ephy_shell_get_toolbars_model (ephy_shell, FALSE); + + g_signal_connect_after (toolbars_model, "get_item_type", + G_CALLBACK (get_item_type_forward_cb), + eb->priv->toolbars_model); + g_signal_connect_after (toolbars_model, "get_item_id", + G_CALLBACK (get_item_id_forward_cb), + eb->priv->toolbars_model); + g_signal_connect_after (toolbars_model, "get_item_data", + G_CALLBACK (get_item_data_forward_cb), + eb->priv->toolbars_model); + + if (eb->priv->init_defaults) + { + ephy_bookmarks_init_defaults (eb); + } } + + return EGG_TOOLBARS_MODEL (eb->priv->toolbars_model); } static void @@ -184,16 +247,8 @@ ephy_bookmarks_set_property (GObject *object, const GValue *value, GParamSpec *pspec) { - EphyBookmarks *eb; - - eb = EPHY_BOOKMARKS (object); - - switch (prop_id) - { - case PROP_TOOLBARS_MODEL: - ephy_bookmarks_set_toolbars_model (eb, g_value_get_object (value)); - break; - } + /* no writable properties */ + g_assert_not_reached (); } static void @@ -202,14 +257,12 @@ ephy_bookmarks_get_property (GObject *object, GValue *value, GParamSpec *pspec) { - EphyBookmarks *eb; - - eb = EPHY_BOOKMARKS (object); + EphyBookmarks *eb = EPHY_BOOKMARKS (object); switch (prop_id) { case PROP_TOOLBARS_MODEL: - g_value_set_object (value, eb->priv->toolbars_model); + g_value_set_object (value, ephy_bookmarks_get_toolbars_model (eb)); break; } } @@ -238,11 +291,11 @@ ephy_bookmarks_class_init (EphyBookmarksClass *klass) g_object_class_install_property (object_class, PROP_TOOLBARS_MODEL, - g_param_spec_object ("toolbars_model", + g_param_spec_object ("toolbars-model", "Toolbars model", "Toolbars model", - EPHY_TYPE_TOOLBARS_MODEL, - G_PARAM_READWRITE)); + EPHY_TYPE_BOOKMARKSBAR_MODEL, + G_PARAM_READABLE)); g_type_class_add_private (object_class, sizeof(EphyBookmarksPrivate)); } @@ -763,10 +816,10 @@ ephy_bookmarks_finalize (GObject *object) g_object_unref (eb->priv->db); - if (eb->priv->toolbars_model) + LOG ("Unref bookmarks toolbars model") + if (eb->priv->toolbars_model != NULL) { - g_object_remove_weak_pointer (G_OBJECT(eb->priv->toolbars_model), - (gpointer *)&eb->priv->toolbars_model); + g_object_unref (eb->priv->toolbars_model); } g_free (eb->priv->xml_file); diff --git a/src/bookmarks/ephy-bookmarks.h b/src/bookmarks/ephy-bookmarks.h index 14b352e0a..26c83832e 100644 --- a/src/bookmarks/ephy-bookmarks.h +++ b/src/bookmarks/ephy-bookmarks.h @@ -1,5 +1,6 @@ /* - * Copyright (C) 2000, 2001, 2002 Marco Pesenti Gritti + * Copyright (C) 2000-2004 Marco Pesenti Gritti + * Copyright (C) 2003, 2004 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 @@ -24,6 +25,7 @@ #include <glib-object.h> #include "ephy-node.h" +#include "egg-toolbars-model.h" G_BEGIN_DECLS @@ -34,103 +36,105 @@ G_BEGIN_DECLS #define EPHY_IS_BOOKMARKS_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EPHY_TYPE_BOOKMARKS)) #define EPHY_BOOKMARKS_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EPHY_TYPE_BOOKMARKS, EphyBookmarksClass)) -typedef struct EphyBookmarksClass EphyBookmarksClass; -typedef struct EphyBookmarks EphyBookmarks; -typedef struct EphyBookmarksPrivate EphyBookmarksPrivate; +typedef struct EphyBookmarksClass EphyBookmarksClass; +typedef struct EphyBookmarks EphyBookmarks; +typedef struct EphyBookmarksPrivate EphyBookmarksPrivate; enum { - EPHY_NODE_BMK_PROP_TITLE = 2, - EPHY_NODE_BMK_PROP_LOCATION = 3, - EPHY_NODE_BMK_PROP_KEYWORDS = 4, - EPHY_NODE_KEYWORD_PROP_NAME = 5, - EPHY_NODE_BMK_PROP_ICON = 7, - EPHY_NODE_KEYWORD_PROP_PRIORITY = 8 + EPHY_NODE_BMK_PROP_TITLE = 2, + EPHY_NODE_BMK_PROP_LOCATION = 3, + EPHY_NODE_BMK_PROP_KEYWORDS = 4, + EPHY_NODE_KEYWORD_PROP_NAME = 5, + EPHY_NODE_BMK_PROP_ICON = 7, + EPHY_NODE_KEYWORD_PROP_PRIORITY = 8 }; struct EphyBookmarks { - GObject parent; + GObject parent; /*< private >*/ - EphyBookmarksPrivate *priv; + EphyBookmarksPrivate *priv; }; struct EphyBookmarksClass { - GObjectClass parent_class; + GObjectClass parent_class; - void (* tree_changed) (EphyBookmarks *eb); + void (* tree_changed) (EphyBookmarks *eb); }; -GType ephy_bookmarks_get_type (void); +GType ephy_bookmarks_get_type (void); -EphyBookmarks *ephy_bookmarks_new (void); +EphyBookmarks *ephy_bookmarks_new (void); -EphyNode *ephy_bookmarks_get_from_id (EphyBookmarks *eb, - long id); +EphyNode *ephy_bookmarks_get_from_id (EphyBookmarks *eb, + long id); + +EggToolbarsModel *ephy_bookmarks_get_toolbars_model (EphyBookmarks *eb); /* Bookmarks */ -EphyNode *ephy_bookmarks_add (EphyBookmarks *eb, - const char *title, - const char *url); +EphyNode *ephy_bookmarks_add (EphyBookmarks *eb, + const char *title, + const char *url); -EphyNode* ephy_bookmarks_find_bookmark (EphyBookmarks *eb, - const char *url); +EphyNode* ephy_bookmarks_find_bookmark (EphyBookmarks *eb, + const char *url); -void ephy_bookmarks_set_icon (EphyBookmarks *eb, - const char *url, - const char *icon); +void ephy_bookmarks_set_icon (EphyBookmarks *eb, + const char *url, + const char *icon); -void ephy_bookmarks_set_address (EphyBookmarks *eb, - EphyNode *bookmark, - const char *address); +void ephy_bookmarks_set_address (EphyBookmarks *eb, + EphyNode *bookmark, + const char *address); -char *ephy_bookmarks_solve_smart_url (EphyBookmarks *eb, - const char *smart_url, - const char *content); +char *ephy_bookmarks_solve_smart_url (EphyBookmarks *eb, + const char *smart_url, + const char *content); /* Keywords */ -EphyNode *ephy_bookmarks_add_keyword (EphyBookmarks *eb, - const char *name); +EphyNode *ephy_bookmarks_add_keyword (EphyBookmarks *eb, + const char *name); -EphyNode *ephy_bookmarks_find_keyword (EphyBookmarks *eb, - const char *name, - gboolean partial_match); +EphyNode *ephy_bookmarks_find_keyword (EphyBookmarks *eb, + const char *name, + gboolean partial_match); -void ephy_bookmarks_remove_keyword (EphyBookmarks *eb, - EphyNode *keyword); +void ephy_bookmarks_remove_keyword (EphyBookmarks *eb, + EphyNode *keyword); -gboolean ephy_bookmarks_has_keyword (EphyBookmarks *eb, - EphyNode *keyword, - EphyNode *bookmark); +gboolean ephy_bookmarks_has_keyword (EphyBookmarks *eb, + EphyNode *keyword, + EphyNode *bookmark); -void ephy_bookmarks_set_keyword (EphyBookmarks *eb, - EphyNode *keyword, - EphyNode *bookmark); +void ephy_bookmarks_set_keyword (EphyBookmarks *eb, + EphyNode *keyword, + EphyNode *bookmark); -void ephy_bookmarks_unset_keyword (EphyBookmarks *eb, - EphyNode *keyword, - EphyNode *bookmark); +void ephy_bookmarks_unset_keyword (EphyBookmarks *eb, + EphyNode *keyword, + EphyNode *bookmark); -char *ephy_bookmarks_get_topic_uri (EphyBookmarks *eb, - EphyNode *node); +char *ephy_bookmarks_get_topic_uri (EphyBookmarks *eb, + EphyNode *node); /* Favorites */ -EphyNode *ephy_bookmarks_get_favorites (EphyBookmarks *eb); +EphyNode *ephy_bookmarks_get_favorites (EphyBookmarks *eb); /* Root */ -EphyNode *ephy_bookmarks_get_keywords (EphyBookmarks *eb); +EphyNode *ephy_bookmarks_get_keywords (EphyBookmarks *eb); -EphyNode *ephy_bookmarks_get_bookmarks (EphyBookmarks *eb); +EphyNode *ephy_bookmarks_get_bookmarks (EphyBookmarks *eb); -EphyNode *ephy_bookmarks_get_not_categorized (EphyBookmarks *eb); +EphyNode *ephy_bookmarks_get_not_categorized (EphyBookmarks *eb); -EphyNode *ephy_bookmarks_get_smart_bookmarks (EphyBookmarks *eb); +EphyNode *ephy_bookmarks_get_smart_bookmarks (EphyBookmarks *eb); G_END_DECLS diff --git a/src/bookmarks/ephy-bookmarksbar-model.c b/src/bookmarks/ephy-bookmarksbar-model.c index cc5bdf773..fc969fddc 100755 --- a/src/bookmarks/ephy-bookmarksbar-model.c +++ b/src/bookmarks/ephy-bookmarksbar-model.c @@ -188,9 +188,9 @@ ephy_bookmarksbar_model_add_bookmark (EphyBookmarksBarModel *model, name = ephy_bookmarksbar_model_get_action_name (model, id); egg_toolbars_model_add_item (EGG_TOOLBARS_MODEL (model), - toolbar_position, -1, name, - topic ? EPHY_DND_TOPIC_TYPE : - EPHY_DND_URL_TYPE); + toolbar_position, -1, name, + topic ? EPHY_DND_TOPIC_TYPE : + EPHY_DND_URL_TYPE); g_free (name); } @@ -198,19 +198,19 @@ void ephy_bookmarksbar_model_remove_bookmark (EphyBookmarksBarModel *model, long id) { -/* char *action_name; + char *action_name; int toolbar, position; action_name = ephy_bookmarksbar_model_get_action_name (model, id); g_return_if_fail (action_name != NULL); - if (get_toolbar_and_item_pos (model, action_name, &toolbar, &position)) + while (get_toolbar_and_item_pos (model, action_name, &toolbar, &position)) { egg_toolbars_model_remove_item (EGG_TOOLBARS_MODEL (model), toolbar, position); } - g_free (action_name);*/ + g_free (action_name); } gboolean @@ -285,74 +285,27 @@ update_flags_and_save_changes (EphyBookmarksBarModel *model) } static void -bookmark_destroy_cb (EphyNode *node, - EphyBookmarksBarModel *model) -{ - long id; - - id = ephy_node_get_id (node); - ephy_bookmarksbar_model_remove_bookmark (model, id); -} - -static void item_added_cb (EphyBookmarksBarModel *model, int toolbar_position, int position) { - EphyNode *node; - const char *i_name; - gboolean is_separator; - - egg_toolbars_model_item_nth (EGG_TOOLBARS_MODEL (model), toolbar_position, - position, &is_separator, &i_name, NULL); - if (!is_separator && g_str_has_prefix (i_name, "GoBookmark-")) - { - node = ephy_bookmarksbar_model_get_node (model, i_name); - g_return_if_fail (node != NULL); - - ephy_node_signal_connect_object (node, - EPHY_NODE_DESTROY, - (EphyNodeCallback) bookmark_destroy_cb, - G_OBJECT (model)); - } - save_changes (model); } static char * -impl_get_item_name (EggToolbarsModel *eggmodel, - const char *type, - const char *id) +impl_get_item_type (EggToolbarsModel *model, + GdkAtom type) { - EphyBookmarksBarModel *model = EPHY_BOOKMARKSBAR_MODEL (eggmodel); - EphyNode *node; - - if (strcmp (type, EPHY_DND_TOPIC_TYPE) == 0) + if (gdk_atom_intern (EPHY_DND_TOPIC_TYPE, FALSE) == type) { - char *uri; - - node = ephy_bookmarksbar_model_get_node (model, id); - g_return_val_if_fail (node != NULL, NULL); - - uri = ephy_bookmarks_get_topic_uri - (model->priv->bookmarks, node); - - return uri; + return g_strdup (EPHY_DND_TOPIC_TYPE); } - else if (strcmp (type, EPHY_DND_URL_TYPE) == 0) + else if (gdk_atom_intern (EPHY_DND_URL_TYPE, FALSE) == type) { - const char *name; - - node = ephy_bookmarksbar_model_get_node (model, id); - g_return_val_if_fail (node != NULL, NULL); - - name = ephy_node_get_property_string - (node, EPHY_NODE_BMK_PROP_LOCATION); - - return g_strdup (name); + return g_strdup (EPHY_DND_URL_TYPE); } - return EGG_TOOLBARS_MODEL_CLASS (parent_class)->get_item_name (eggmodel, type, id); + return EGG_TOOLBARS_MODEL_CLASS (parent_class)->get_item_type (model, type); } static char * @@ -422,19 +375,39 @@ impl_get_item_id (EggToolbarsModel *eggmodel, } static char * -impl_get_item_type (EggToolbarsModel *model, - GdkAtom type) +impl_get_item_data (EggToolbarsModel *eggmodel, + const char *type, + const char *id) { - if (gdk_atom_intern (EPHY_DND_TOPIC_TYPE, FALSE) == type) + EphyBookmarksBarModel *model = EPHY_BOOKMARKSBAR_MODEL (eggmodel); + EphyNode *node; + + if (strcmp (type, EPHY_DND_TOPIC_TYPE) == 0) { - return g_strdup (EPHY_DND_TOPIC_TYPE); + char *uri; + + node = ephy_bookmarksbar_model_get_node (model, id); + g_return_val_if_fail (node != NULL, NULL); + + uri = ephy_bookmarks_get_topic_uri + (model->priv->bookmarks, node); + + return uri; } - else if (gdk_atom_intern (EPHY_DND_URL_TYPE, FALSE) == type) + else if (strcmp (type, EPHY_DND_URL_TYPE) == 0) { - return g_strdup (EPHY_DND_URL_TYPE); + const char *name; + + node = ephy_bookmarksbar_model_get_node (model, id); + g_return_val_if_fail (node != NULL, NULL); + + name = ephy_node_get_property_string + (node, EPHY_NODE_BMK_PROP_LOCATION); + + return g_strdup (name); } - return EGG_TOOLBARS_MODEL_CLASS (parent_class)->get_item_type (model, type); + return EGG_TOOLBARS_MODEL_CLASS (parent_class)->get_item_data (eggmodel, type, id); } static void @@ -527,6 +500,9 @@ ephy_bookmarksbar_model_finalize (GObject *object) model->priv->timeout = 0; } + /* FIXME: instead of saving on exit, we should detect when items data changes */ + save_changes_idle (model); + g_free (model->priv->xml_file); G_OBJECT_CLASS (parent_class)->finalize (object); @@ -572,9 +548,9 @@ ephy_bookmarksbar_model_class_init (EphyBookmarksBarModelClass *klass) object_class->set_property = ephy_bookmarksbar_model_set_property; object_class->get_property = ephy_bookmarksbar_model_get_property; - eggclass->get_item_name = impl_get_item_name; - eggclass->get_item_id = impl_get_item_id; eggclass->get_item_type = impl_get_item_type; + eggclass->get_item_id = impl_get_item_id; + eggclass->get_item_data = impl_get_item_data; g_object_class_install_property (object_class, PROP_BOOKMARKS, diff --git a/src/bookmarks/ephy-bookmarksbar-model.h b/src/bookmarks/ephy-bookmarksbar-model.h index ac39f9325..41c7efef3 100755 --- a/src/bookmarks/ephy-bookmarksbar-model.h +++ b/src/bookmarks/ephy-bookmarksbar-model.h @@ -51,25 +51,25 @@ struct EphyBookmarksBarModelClass EggToolbarsModelClass parent_class; }; -GType ephy_bookmarksbar_model_get_type (void); +GType ephy_bookmarksbar_model_get_type (void); -EggToolbarsModel *ephy_bookmarksbar_model_new (EphyBookmarks *bookmarks); +EggToolbarsModel *ephy_bookmarksbar_model_new (EphyBookmarks *bookmarks); -char *ephy_bookmarksbar_model_get_action_name (EphyBookmarksBarModel *model, - long id); +char *ephy_bookmarksbar_model_get_action_name (EphyBookmarksBarModel *model, + long id); -EphyNode *ephy_bookmarksbar_model_get_node (EphyBookmarksBarModel *model, - const char *action_name); +EphyNode *ephy_bookmarksbar_model_get_node (EphyBookmarksBarModel *model, + const char *action_name); -void ephy_bookmarksbar_model_add_bookmark (EphyBookmarksBarModel *model, - gboolean topic, - long id); +void ephy_bookmarksbar_model_add_bookmark (EphyBookmarksBarModel *model, + gboolean topic, + long id); -void ephy_bookmarksbar_model_remove_bookmark (EphyBookmarksBarModel *model, - long id); +void ephy_bookmarksbar_model_remove_bookmark (EphyBookmarksBarModel *model, + long id); -gboolean ephy_bookmarksbar_model_has_bookmark (EphyBookmarksBarModel *model, - long id); +gboolean ephy_bookmarksbar_model_has_bookmark (EphyBookmarksBarModel *model, + long id); G_END_DECLS diff --git a/src/bookmarks/ephy-bookmarksbar.c b/src/bookmarks/ephy-bookmarksbar.c index 144d7c25e..511b635fa 100644 --- a/src/bookmarks/ephy-bookmarksbar.c +++ b/src/bookmarks/ephy-bookmarksbar.c @@ -42,9 +42,8 @@ static GtkTargetEntry drag_targets[] = { - { EGG_TOOLBAR_ITEM_TYPE, 0, 0 }, - { EPHY_DND_TOPIC_TYPE, 0, 1 }, - { EPHY_DND_URL_TYPE, 0, 2 } + { EPHY_DND_TOPIC_TYPE, 0, 0 }, + { EPHY_DND_URL_TYPE, 0, 1 } }; static int n_drag_targets = G_N_ELEMENTS (drag_targets); @@ -145,30 +144,73 @@ go_location_cb (GtkAction *action, } } +static gboolean +remove_action_from_model (EggToolbarsModel *model, const char *name) +{ + int n_toolbars, n_items, t, i; + + n_toolbars = egg_toolbars_model_n_toolbars (model); + + for (t = 0; t < n_toolbars; t++) + { + n_items = egg_toolbars_model_n_items (model, t); + + for (i = 0; i < n_items; i++) + { + const char *i_name; + gboolean is_separator; + + egg_toolbars_model_item_nth (model, t , i, &is_separator, + &i_name, NULL); + g_return_val_if_fail (i_name != NULL, FALSE); + + if (strcmp (i_name, name) == 0) + { + egg_toolbars_model_remove_item (model, t, i); + + if (!remove_action_from_model (model, name)) + { + return FALSE; + } + } + } + } + + return FALSE; +} + static void bookmark_destroy_cb (EphyNode *node, EphyBookmarksBar *toolbar) { + EggToolbarsModel *model; GtkAction *action; char *name; long id; + + model = toolbar->priv->toolbars_model; id = ephy_node_get_id (node); name = ephy_bookmarksbar_model_get_action_name - (EPHY_BOOKMARKSBAR_MODEL (toolbar->priv->toolbars_model), - id); + (EPHY_BOOKMARKSBAR_MODEL (model), id); + remove_action_from_model (model, name); - action = gtk_action_group_get_action (toolbar->priv->action_group, name); - g_return_if_fail (action != NULL); + model = EGG_TOOLBARS_MODEL (ephy_shell_get_toolbars_model + (ephy_shell, FALSE)); + remove_action_from_model (model, name); - gtk_action_group_remove_action (toolbar->priv->action_group, action); + action = gtk_action_group_get_action (toolbar->priv->action_group, name); + if (action) + { + gtk_action_group_remove_action (toolbar->priv->action_group, action); + } g_free (name); } static void ephy_bookmarksbar_action_request (EggEditableToolbar *eggtoolbar, - const char *name) + const char *name) { EphyBookmarksBar *toolbar = EPHY_BOOKMARKSBAR (eggtoolbar); GtkAction *action = NULL; diff --git a/src/ephy-shell.c b/src/ephy-shell.c index 78060acf6..d61f6075a 100644 --- a/src/ephy-shell.c +++ b/src/ephy-shell.c @@ -1,5 +1,6 @@ /* - * Copyright (C) 2000-2003 Marco Pesenti Gritti + * Copyright (C) 2000-2004 Marco Pesenti Gritti + * Copyright (C) 2003, 2004 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 @@ -39,6 +40,7 @@ #include "toolbar.h" #include "ephy-session.h" #include "downloader-view.h" +#include "egg-toolbars-model.h" #include "ephy-toolbars-model.h" #include "ephy-automation.h" #include "print-dialog.h" @@ -63,7 +65,7 @@ struct EphyShellPrivate BonoboGenericFactory *automation_factory; EphySession *session; EphyBookmarks *bookmarks; - EphyToolbarsModel *toolbars_model; + EggToolbarsModel *toolbars_model; EggToolbarsModel *fs_toolbars_model; EphyExtensionsManager *extensions_manager; GtkWidget *bme; @@ -664,11 +666,16 @@ ephy_shell_get_toolbars_model (EphyShell *shell, gboolean fullscreen) { if (shell->priv->fs_toolbars_model == NULL) { + gboolean success; const char *xml; shell->priv->fs_toolbars_model = egg_toolbars_model_new (); xml = ephy_file ("epiphany-fs-toolbar.xml"); - egg_toolbars_model_load (shell->priv->fs_toolbars_model, xml); + g_return_val_if_fail (xml != NULL, NULL); + + success = egg_toolbars_model_load + (shell->priv->fs_toolbars_model, xml); + g_return_val_if_fail (success, NULL); } return G_OBJECT (shell->priv->fs_toolbars_model); @@ -678,16 +685,22 @@ ephy_shell_get_toolbars_model (EphyShell *shell, gboolean fullscreen) if (shell->priv->toolbars_model == NULL) { EphyBookmarks *bookmarks; + EggToolbarsModel *bookmarksbar_model; - bookmarks = ephy_shell_get_bookmarks (shell); + shell->priv->toolbars_model = ephy_toolbars_model_new (); - shell->priv->toolbars_model = ephy_toolbars_model_new (bookmarks); + /* get the bookmarks toolbars model. we have to do this + * before loading the toolbars model from disk, since + * this will connect the get_item_* signals + */ + bookmarks = ephy_shell_get_bookmarks (shell); + bookmarksbar_model = ephy_bookmarks_get_toolbars_model (bookmarks); - g_object_set (bookmarks, "toolbars_model", - shell->priv->toolbars_model, NULL); + /* ok, now we can load the model */ + ephy_toolbars_model_load + (EPHY_TOOLBARS_MODEL (shell->priv->toolbars_model)); } - return G_OBJECT (shell->priv->toolbars_model); } } diff --git a/src/ephy-shell.h b/src/ephy-shell.h index 1c5e07a05..d3d9233c3 100644 --- a/src/ephy-shell.h +++ b/src/ephy-shell.h @@ -1,5 +1,6 @@ /* - * Copyright (C) 2000-2003 Marco Pesenti Gritti + * Copyright (C) 2000-2004 Marco Pesenti Gritti + * Copyright (C) 2003, 2004 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 @@ -117,11 +118,11 @@ EphyTab *ephy_shell_new_tab (EphyShell *shell, const char *url, EphyNewTabFlags flags); -GObject *ephy_shell_get_session (EphyShell *shell); +GObject *ephy_shell_get_session (EphyShell *shell); EphyBookmarks *ephy_shell_get_bookmarks (EphyShell *shell); -GObject *ephy_shell_get_toolbars_model (EphyShell *shell, +GObject *ephy_shell_get_toolbars_model (EphyShell *shell, gboolean fullscreen); GObject *ephy_shell_get_extensions_manager (EphyShell *shell); diff --git a/src/ephy-toolbars-model.c b/src/ephy-toolbars-model.c index 0df59cb0a..b730b93e2 100755 --- a/src/ephy-toolbars-model.c +++ b/src/ephy-toolbars-model.c @@ -1,5 +1,6 @@ /* - * Copyright (C) 2002 Marco Pesenti Gritti + * Copyright (C) 2002-2004 Marco Pesenti Gritti + * Copyright (C) 2003, 2004 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 @@ -23,54 +24,27 @@ #endif #include "ephy-toolbars-model.h" -#include "ephy-dnd.h" -#include "ephy-bookmarks.h" -#include "ephy-node-common.h" #include "ephy-file-helpers.h" -#include "ephy-history.h" -#include "ephy-embed-shell.h" -#include "ephy-shell.h" #include "ephy-debug.h" -#include "ephy-string.h" #include <string.h> -#include <glib/gi18n.h> -static void ephy_toolbars_model_class_init (EphyToolbarsModelClass *klass); -static void ephy_toolbars_model_init (EphyToolbarsModel *t); -static void ephy_toolbars_model_finalize (GObject *object); - -#define EPHY_TOOLBARS_XML_VERSION "1.0" - -enum -{ - ACTION_ADDED, - LAST_SIGNAL -}; - -enum -{ - PROP_0, - PROP_BOOKMARKS -}; - -enum -{ - URL, - NAME -}; - -static GObjectClass *parent_class = NULL; +#define EPHY_TOOLBARS_XML_FILE "epiphany-toolbars-2.xml" +#define EPHY_TOOLBARS_XML_VERSION "1.0" #define EPHY_TOOLBARS_MODEL_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_TOOLBARS_MODEL, EphyToolbarsModelPrivate)) struct EphyToolbarsModelPrivate { - EphyBookmarks *bookmarks; char *xml_file; - gboolean loading; + guint timeout; }; +static void ephy_toolbars_model_class_init (EphyToolbarsModelClass *klass); +static void ephy_toolbars_model_init (EphyToolbarsModel *model); + +static GObjectClass *parent_class = NULL; + GType ephy_toolbars_model_get_type (void) { @@ -98,207 +72,75 @@ ephy_toolbars_model_get_type (void) return type; } -char * -ephy_toolbars_model_get_action_name (EphyToolbarsModel *model, - long id) +static gboolean +save_changes_idle (EphyToolbarsModel *model) { - return g_strdup_printf ("GoBookmark-%ld", id); -} + LOG ("Saving toolbars model") -EphyNode * -ephy_toolbars_model_get_node (EphyToolbarsModel *model, - const char *action_name) -{ - EphyBookmarks *bookmarks = EPHY_TOOLBARS_MODEL (model)->priv->bookmarks; - long node_id; + egg_toolbars_model_save + (EGG_TOOLBARS_MODEL (model), + model->priv->xml_file, + EPHY_TOOLBARS_XML_VERSION); - if (!ephy_string_to_int (action_name + strlen ("GoBookmark-"), &node_id)) - { - return NULL; - } + model->priv->timeout = 0; - return ephy_bookmarks_get_from_id (bookmarks, node_id); + /* don't run again */ + return FALSE; } static void -bookmark_destroy_cb (EphyNode *node, - EphyToolbarsModel *model) -{ - long id; - - id = ephy_node_get_id (node); - ephy_toolbars_model_remove_bookmark (model, id); -} - -static char * -impl_get_item_data (EggToolbarsModel *t, - const char *type, - const char *id) +save_changes (EphyToolbarsModel *model) { - EphyToolbarsModel *model = EPHY_TOOLBARS_MODEL (t); - EphyNode *node; - - if (strcmp (type, EPHY_DND_TOPIC_TYPE) == 0) - { - char *uri; - - node = ephy_toolbars_model_get_node (model, id); - g_return_val_if_fail (node != NULL, NULL); - - uri = ephy_bookmarks_get_topic_uri - (model->priv->bookmarks, node); - - return uri; - } - else if (strcmp (type, EPHY_DND_URL_TYPE) == 0) + if (model->priv->timeout == 0) { - const char *name; - - node = ephy_toolbars_model_get_node (model, id); - g_return_val_if_fail (node != NULL, NULL); - - name = ephy_node_get_property_string - (node, EPHY_NODE_BMK_PROP_LOCATION); - - return g_strdup (name); + model->priv->timeout = + g_idle_add ((GSourceFunc) save_changes_idle, model); } - - return EGG_TOOLBARS_MODEL_CLASS (parent_class)->get_item_data (t, type, id); } -static char * -impl_get_item_id (EggToolbarsModel *t, - const char *type, - const char *name) +static void +update_flags_and_save_changes (EphyToolbarsModel *model) { - EphyToolbarsModel *model = EPHY_TOOLBARS_MODEL (t); - EphyBookmarks *bookmarks = model->priv->bookmarks; - - if (strcmp (type, EPHY_DND_TOPIC_TYPE) == 0) - { - EphyNode *topic; - - topic = ephy_bookmarks_find_keyword (bookmarks, name, FALSE); - if (topic == NULL) return NULL; - - return ephy_toolbars_model_get_action_name - (model, ephy_node_get_id (topic)); - } - else if (strcmp (type, EPHY_DND_URL_TYPE) == 0) - { - EphyNode *node = NULL; - gchar **netscape_url; - - netscape_url = g_strsplit (name, "\n", 2); - node = ephy_bookmarks_find_bookmark (bookmarks, netscape_url[URL]); - - if (!node) - { - /* Create the bookmark, it does not exist */ - EphyHistory *gh; - const char *icon; - const char *title; - - title = netscape_url[NAME]; - if (title == NULL || *title == '\0') - { - title = _("Untitled"); - } - - node = ephy_bookmarks_add (bookmarks, title, netscape_url[URL]); - - if (node != NULL) - { - gh = EPHY_HISTORY (ephy_embed_shell_get_global_history (embed_shell)); - icon = ephy_history_get_icon (gh, netscape_url[URL]); - - if (icon) - { - ephy_bookmarks_set_icon (bookmarks, netscape_url[URL], icon); - } - } - } - - g_strfreev (netscape_url); - - if (node == NULL) return NULL; - - return ephy_toolbars_model_get_action_name - (model, ephy_node_get_id (node)); - } + EggToolbarsModel *eggmodel = EGG_TOOLBARS_MODEL (model); + int i, n_toolbars; + int flag = EGG_TB_MODEL_ACCEPT_ITEMS_ONLY; - return EGG_TOOLBARS_MODEL_CLASS (parent_class)->get_item_data (t, type, name); -} + n_toolbars = egg_toolbars_model_n_toolbars (eggmodel); -static char * -impl_get_item_type (EggToolbarsModel *t, - GdkAtom type) -{ - if (gdk_atom_intern (EPHY_DND_TOPIC_TYPE, FALSE) == type) - { - return g_strdup (EPHY_DND_TOPIC_TYPE); - } - else if (gdk_atom_intern (EPHY_DND_URL_TYPE, FALSE) == type) + if (n_toolbars <= 1) { - return g_strdup (EPHY_DND_URL_TYPE); + flag |= EGG_TB_MODEL_NOT_REMOVABLE; } - return EGG_TOOLBARS_MODEL_CLASS (parent_class)->get_item_type (t, type); -} - -static gboolean -get_toolbar_and_item_pos (EphyToolbarsModel *model, - const char *action_name, - int *toolbar, - int *position) -{ - int n_toolbars, n_items; - int t,i; - - n_toolbars = egg_toolbars_model_n_toolbars (EGG_TOOLBARS_MODEL (model)); - - for (t = 0; t < n_toolbars; t++) + for (i = 0; i < n_toolbars; i++) { - n_items = egg_toolbars_model_n_items - (EGG_TOOLBARS_MODEL (model), t); - - for (i = 0; i < n_items; i++) - { - const char *i_name; - gboolean is_separator; - - egg_toolbars_model_item_nth (EGG_TOOLBARS_MODEL (model), - t, i, &is_separator, &i_name, NULL); - g_return_val_if_fail (i_name != NULL, FALSE); + const char *t_name; + EggTbModelFlags flags; - if (strcmp (i_name, action_name) == 0) - { - if (toolbar) *toolbar = t; - if (position) *position = i; + t_name = egg_toolbars_model_toolbar_nth (eggmodel, i); + g_return_if_fail (t_name != NULL); - return TRUE; - } - } + flags = egg_toolbars_model_get_flags (eggmodel, i); + egg_toolbars_model_set_flags (eggmodel, flags | flag, i); } - return FALSE; + save_changes (model); } static int -get_toolbar_pos (EphyToolbarsModel *model, +get_toolbar_pos (EggToolbarsModel *model, const char *name) { int i, n_toolbars; - n_toolbars = egg_toolbars_model_n_toolbars - (EGG_TOOLBARS_MODEL (model)); + 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 - (EGG_TOOLBARS_MODEL (model), i); + t_name = egg_toolbars_model_toolbar_nth (model, i); + g_return_val_if_fail (t_name != NULL, -1); if (strcmp (name, t_name) == 0) { return i; @@ -308,289 +150,108 @@ get_toolbar_pos (EphyToolbarsModel *model, return -1; } -static void -connect_item (EphyToolbarsModel *model, - const char *name) -{ - EphyNode *node; - - if (g_str_has_prefix (name, "GoBookmark-")) - { - node = ephy_toolbars_model_get_node (model, name); - g_return_if_fail (node != NULL); - - ephy_node_signal_connect_object (node, - EPHY_NODE_DESTROY, - (EphyNodeCallback) bookmark_destroy_cb, - G_OBJECT (model)); - } -} - -static void -update_toolbar_removeable_flag (EggToolbarsModel *model) +void +ephy_toolbars_model_load (EphyToolbarsModel *model) { - int i, n_toolbars; - int flag = 0; + EggToolbarsModel *eggmodel = EGG_TOOLBARS_MODEL (model); + gboolean success; - n_toolbars = egg_toolbars_model_n_toolbars (model); - - /* If there is only one toolbar and the bookmarks bar */ - if (n_toolbars <= 2) - { - flag = EGG_TB_MODEL_NOT_REMOVABLE; - } + success = egg_toolbars_model_load (eggmodel, model->priv->xml_file); + LOG ("Loading the toolbars was %ssuccessful", success ? "" : "un") - for (i = 0; i < n_toolbars; i++) + /* maybe an old format, try to migrate: load the old layout, and + * remove the BookmarksBar toolbar + */ + if (success == FALSE) { - const char *t_name; + char *old_xml; + int toolbar; - t_name = egg_toolbars_model_toolbar_nth (model, i); - g_return_if_fail (t_name != NULL); + old_xml = g_build_filename (ephy_dot_dir (), + "epiphany-toolbars.xml", + NULL); + success = egg_toolbars_model_load (eggmodel, old_xml); + g_free (old_xml); - if (!(strcmp (t_name, "BookmarksBar") == 0)) + if (success) { - egg_toolbars_model_set_flags (model, flag, i); + toolbar = get_toolbar_pos (eggmodel, "BookmarksBar"); + if (toolbar != -1) + { + egg_toolbars_model_remove_toolbar (eggmodel, toolbar); + } } - } -} - -static void -ephy_toolbars_model_set_bookmarks (EphyToolbarsModel *model, EphyBookmarks *bookmarks) -{ - EggToolbarsModel *egg_model = EGG_TOOLBARS_MODEL (model); - gboolean success = FALSE; - - model->priv->bookmarks = g_object_ref (bookmarks); - - model->priv->loading = TRUE; - if (g_file_test (model->priv->xml_file, G_FILE_TEST_EXISTS)) - { - success = egg_toolbars_model_load (egg_model, - model->priv->xml_file); + LOG ("Migration was %ssuccessful", success ? "" : "un") } + /* Still no success, load the default toolbars */ if (success == FALSE) { - const char *default_xml; - - default_xml = ephy_file ("epiphany-toolbar.xml"); - egg_toolbars_model_load (egg_model, default_xml); + success = egg_toolbars_model_load + (eggmodel, ephy_file ("epiphany-toolbar.xml")); + LOG ("Loading the default toolbars was %ssuccessful", success ? "" : "un") } - /* ensure that we have a BookmarksBar */ - if (get_toolbar_pos (model, "BookmarksBar") == -1) + /* Ensure we have at least 1 toolbar */ + if (egg_toolbars_model_n_toolbars (eggmodel) < 1) { - egg_toolbars_model_add_toolbar - (EGG_TOOLBARS_MODEL (model), -1, "BookmarksBar"); + egg_toolbars_model_add_toolbar (eggmodel, 0, "DefaultToolbar"); } - - model->priv->loading = FALSE; } static void -ephy_toolbars_model_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) +ephy_toolbars_model_init (EphyToolbarsModel *model) { - EphyToolbarsModel *model; - - model = EPHY_TOOLBARS_MODEL (object); - - switch (prop_id) - { - case PROP_BOOKMARKS: - ephy_toolbars_model_set_bookmarks (model, g_value_get_object (value)); - break; - } + model->priv = EPHY_TOOLBARS_MODEL_GET_PRIVATE (model); + + model->priv->xml_file = g_build_filename (ephy_dot_dir (), + EPHY_TOOLBARS_XML_FILE, + NULL); + + g_signal_connect_after (model, "item_added", + G_CALLBACK (save_changes), NULL); + g_signal_connect_after (model, "item_removed", + G_CALLBACK (save_changes), NULL); + g_signal_connect_after (model, "toolbar_added", + G_CALLBACK (update_flags_and_save_changes), NULL); + g_signal_connect_after (model, "toolbar_removed", + G_CALLBACK (update_flags_and_save_changes), NULL); } static void -ephy_toolbars_model_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) +ephy_toolbars_model_finalize (GObject *object) { - EphyToolbarsModel *model; - - model = EPHY_TOOLBARS_MODEL (object); + EphyToolbarsModel *model = EPHY_TOOLBARS_MODEL (object); - switch (prop_id) + if (model->priv->timeout != 0) { - case PROP_BOOKMARKS: - g_value_set_object (value, model->priv->bookmarks); - break; + g_source_remove (model->priv->timeout); + model->priv->timeout = 0; } + + /* FIXME: we should detect when item data changes, and save then instead */ + save_changes_idle (model); + + g_free (model->priv->xml_file); + + G_OBJECT_CLASS (parent_class)->finalize (object); } static void ephy_toolbars_model_class_init (EphyToolbarsModelClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - EggToolbarsModelClass *etm_class; - - etm_class = EGG_TOOLBARS_MODEL_CLASS (klass); parent_class = g_type_class_peek_parent (klass); object_class->finalize = ephy_toolbars_model_finalize; - object_class->set_property = ephy_toolbars_model_set_property; - object_class->get_property = ephy_toolbars_model_get_property; - - etm_class->get_item_id = impl_get_item_id; - etm_class->get_item_data = impl_get_item_data; - etm_class->get_item_type = impl_get_item_type; - - g_object_class_install_property (object_class, - PROP_BOOKMARKS, - g_param_spec_object ("bookmarks", - "Bookmarks", - "Bookmarks", - EPHY_TYPE_BOOKMARKS, - G_PARAM_READWRITE)); - - g_type_class_add_private (object_class, sizeof(EphyToolbarsModelPrivate)); -} - -static void -save_changes (EphyToolbarsModel *model) -{ - if (!model->priv->loading) - { - egg_toolbars_model_save (EGG_TOOLBARS_MODEL (model), - model->priv->xml_file, - EPHY_TOOLBARS_XML_VERSION); - } -} - -static void -item_added (EphyToolbarsModel *model, int toolbar_position, int position) -{ - const char *i_name; - gboolean is_separator; - - egg_toolbars_model_item_nth (EGG_TOOLBARS_MODEL (model), toolbar_position, - position, &is_separator, &i_name, NULL); - if (!is_separator) - { - connect_item (model, i_name); - } - - save_changes (model); -} - -static void -item_removed (EphyToolbarsModel *model, int toolbar_position, int position) -{ - save_changes (model); -} - -static void -toolbar_added (EphyToolbarsModel *model, int position) -{ - save_changes (model); - update_toolbar_removeable_flag (EGG_TOOLBARS_MODEL (model)); -} - -static void -toolbar_removed (EphyToolbarsModel *model, int position) -{ - save_changes (model); - update_toolbar_removeable_flag (EGG_TOOLBARS_MODEL (model)); -} - -static void -ephy_toolbars_model_init (EphyToolbarsModel *t) -{ - t->priv = EPHY_TOOLBARS_MODEL_GET_PRIVATE (t); - - t->priv->bookmarks = NULL; - t->priv->loading = FALSE; - t->priv->xml_file = g_build_filename (ephy_dot_dir (), - "epiphany-toolbars.xml", - NULL); - - g_signal_connect (t, "item_added", G_CALLBACK (item_added), NULL); - g_signal_connect (t, "item_removed", G_CALLBACK (item_removed), NULL); - g_signal_connect (t, "toolbar_added", G_CALLBACK (toolbar_added), NULL); - g_signal_connect (t, "toolbar_removed", G_CALLBACK (toolbar_removed), NULL); -} - -static void -ephy_toolbars_model_finalize (GObject *object) -{ - EphyToolbarsModel *t = EPHY_TOOLBARS_MODEL (object); - save_changes (t); - - g_object_unref (t->priv->bookmarks); - - g_free (t->priv->xml_file); - - G_OBJECT_CLASS (parent_class)->finalize (object); -} - -EphyToolbarsModel * -ephy_toolbars_model_new (EphyBookmarks *bookmarks) -{ - return EPHY_TOOLBARS_MODEL (g_object_new (EPHY_TYPE_TOOLBARS_MODEL, - "bookmarks", bookmarks, - NULL)); -} - -void -ephy_toolbars_model_remove_bookmark (EphyToolbarsModel *model, - long id) -{ - char *action_name; - int toolbar, position; - - action_name = ephy_toolbars_model_get_action_name (model, id); - g_return_if_fail (action_name != NULL); - - if (get_toolbar_and_item_pos (model, action_name, &toolbar, &position)) - { - egg_toolbars_model_remove_item (EGG_TOOLBARS_MODEL (model), - toolbar, position); - } - - g_free (action_name); -} - -void -ephy_toolbars_model_add_bookmark (EphyToolbarsModel *model, - gboolean topic, - long id) -{ - char *name; - int toolbar_position; - - toolbar_position = get_toolbar_pos (model, "BookmarksBar"); - g_return_if_fail (toolbar_position != -1); - - name = ephy_toolbars_model_get_action_name (model, id); - egg_toolbars_model_add_item (EGG_TOOLBARS_MODEL (model), - toolbar_position, -1, name, - topic ? EPHY_DND_TOPIC_TYPE : - EPHY_DND_URL_TYPE); - g_free (name); + g_type_class_add_private (object_class, sizeof (EphyToolbarsModelPrivate)); } -gboolean -ephy_toolbars_model_has_bookmark (EphyToolbarsModel *model, - long id) +EggToolbarsModel * +ephy_toolbars_model_new (void) { - char *action_name; - gboolean found; - int toolbar, pos; - - action_name = ephy_toolbars_model_get_action_name (model, id); - g_return_val_if_fail (action_name != NULL, FALSE); - - found = get_toolbar_and_item_pos (model, action_name, &toolbar, &pos); - - g_free (action_name); - - return found; + return EGG_TOOLBARS_MODEL (g_object_new (EPHY_TYPE_TOOLBARS_MODEL, NULL)); } diff --git a/src/ephy-toolbars-model.h b/src/ephy-toolbars-model.h index 09f2aed55..8c71f0c98 100755 --- a/src/ephy-toolbars-model.h +++ b/src/ephy-toolbars-model.h @@ -1,5 +1,6 @@ /* - * Copyright (C) 2003 Marco Pesenti Gritti + * Copyright (C) 2003, 2004 Marco Pesenti Gritti + * Copyright (C) 2003, 2004 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 @@ -33,9 +34,9 @@ G_BEGIN_DECLS #define EPHY_IS_TOOLBARS_MODEL_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EPHY_TYPE_TOOLBARS_MODEL)) #define EPHY_TOOLBARS_MODEL_GET_CLASS(o)(G_TYPE_INSTANCE_GET_CLASS ((o), EPHY_TYPE_TOOLBARS_MODEL, EphyToolbarsModelClass)) -typedef struct EphyToolbarsModelClass EphyToolbarsModelClass; -typedef struct EphyToolbarsModel EphyToolbarsModel; -typedef struct EphyToolbarsModelPrivate EphyToolbarsModelPrivate; +typedef struct EphyToolbarsModelClass EphyToolbarsModelClass; +typedef struct EphyToolbarsModel EphyToolbarsModel; +typedef struct EphyToolbarsModelPrivate EphyToolbarsModelPrivate; struct EphyToolbarsModel { @@ -50,25 +51,11 @@ struct EphyToolbarsModelClass EggToolbarsModelClass parent_class; }; -GType ephy_toolbars_model_get_type (void); +GType ephy_toolbars_model_get_type (void); -EphyToolbarsModel *ephy_toolbars_model_new (EphyBookmarks *bookmarks); +EggToolbarsModel *ephy_toolbars_model_new (void); -void ephy_toolbars_model_add_bookmark (EphyToolbarsModel *model, - gboolean topic, - long id); - -gboolean ephy_toolbars_model_has_bookmark (EphyToolbarsModel *model, - long id); - -void ephy_toolbars_model_remove_bookmark (EphyToolbarsModel *model, - long id); - -char *ephy_toolbars_model_get_action_name (EphyToolbarsModel *model, - long id); - -EphyNode *ephy_toolbars_model_get_node (EphyToolbarsModel *model, - const char *action_name); +void ephy_toolbars_model_load (EphyToolbarsModel *model); G_END_DECLS diff --git a/src/ephy-window.c b/src/ephy-window.c index d9f241fa1..9de3366ae 100644 --- a/src/ephy-window.c +++ b/src/ephy-window.c @@ -1,6 +1,7 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* - * Copyright (C) 2000, 2001, 2002, 2003 Marco Pesenti Gritti + * Copyright (C) 2000, 2001, 2002, 2003, 2004 Marco Pesenti Gritti + * Copyright (C) 2003, 2004 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 @@ -40,7 +41,9 @@ #include "ephy-debug.h" #include "ephy-file-helpers.h" #include "ephy-statusbar.h" +#include "egg-editable-toolbar.h" #include "toolbar.h" +#include "ephy-bookmarksbar.h" #include "popup-commands.h" #include "ephy-encoding-menu.h" #include "ephy-tabs-menu.h" @@ -318,6 +321,7 @@ struct EphyWindowPrivate GtkWidget *menu_dock; GtkWidget *exit_fullscreen_popup; Toolbar *toolbar; + GtkWidget *bookmarksbar; GtkWidget *statusbar; GtkActionGroup *action_group; GtkActionGroup *popups_action_group; @@ -472,13 +476,13 @@ get_chromes_visibility (EphyWindow *window, gboolean *show_menubar, switch (window->priv->mode) { case EPHY_WINDOW_MODE_NORMAL: - *show_menubar = flags & EPHY_EMBED_CHROME_MENUBAR; - *show_statusbar = flags & EPHY_EMBED_CHROME_STATUSBAR; - *show_toolbar = flags & EPHY_EMBED_CHROME_TOOLBAR; - *show_bookmarksbar = flags & EPHY_EMBED_CHROME_BOOKMARKSBAR; + *show_menubar = (flags & EPHY_EMBED_CHROME_MENUBAR) != 0; + *show_statusbar = (flags & EPHY_EMBED_CHROME_STATUSBAR) != 0; + *show_toolbar = (flags & EPHY_EMBED_CHROME_TOOLBAR) != 0; + *show_bookmarksbar = (flags & EPHY_EMBED_CHROME_BOOKMARKSBAR) != 0; break; case EPHY_WINDOW_MODE_FULLSCREEN: - *show_toolbar = flags & EPHY_EMBED_CHROME_TOOLBAR; + *show_toolbar = (flags & EPHY_EMBED_CHROME_TOOLBAR) != 0; *show_menubar = *show_statusbar = *show_bookmarksbar = FALSE; break; default: @@ -500,27 +504,10 @@ sync_chromes_visibility (EphyWindow *window) (GTK_UI_MANAGER (window->ui_merge), "/menubar"); g_assert (menubar != NULL); - if (show_menubar) - { - gtk_widget_show (menubar); - } - else - { - gtk_widget_hide (menubar); - } - - toolbar_set_visibility (window->priv->toolbar, show_toolbar, - show_bookmarksbar); - - - if (show_statusbar) - { - gtk_widget_show (window->priv->statusbar); - } - else - { - gtk_widget_hide (window->priv->statusbar); - } + g_object_set (G_OBJECT (menubar), "visible", show_menubar, NULL); + g_object_set (G_OBJECT (window->priv->toolbar), "visible", show_toolbar, NULL); + g_object_set (G_OBJECT (window->priv->bookmarksbar), "visible", show_bookmarksbar, NULL); + g_object_set (G_OBJECT (window->priv->statusbar), "visible", show_statusbar, NULL); } static void @@ -560,6 +547,9 @@ ephy_window_fullscreen (EphyWindow *window) "size-changed", G_CALLBACK (size_changed_cb), window); + g_object_set (G_OBJECT (window->priv->toolbar), "ToolbarsModel", + ephy_shell_get_toolbars_model (ephy_shell, TRUE), NULL); + sync_chromes_visibility (window); } @@ -575,6 +565,9 @@ ephy_window_unfullscreen (EphyWindow *window) gtk_widget_destroy (window->priv->exit_fullscreen_popup); window->priv->exit_fullscreen_popup = NULL; + g_object_set (G_OBJECT (window->priv->toolbar), "ToolbarsModel", + ephy_shell_get_toolbars_model (ephy_shell, FALSE), NULL); + sync_chromes_visibility (window); } @@ -1917,6 +1910,14 @@ browse_with_caret_notifier (GConfClient *client, } static void +action_request_forward_cb (GObject *toolbar, + const char *name, + GObject *bookmarksbar) +{ + g_signal_emit_by_name (bookmarksbar, "action_request", name); +} + +static void ephy_window_init (EphyWindow *window) { EphyExtension *manager; @@ -1945,6 +1946,7 @@ ephy_window_init (EphyWindow *window) gtk_box_pack_start (GTK_BOX (window->priv->main_vbox), GTK_WIDGET (window->priv->notebook), TRUE, TRUE, 0); + gtk_widget_show (GTK_WIDGET (window->priv->notebook)); window->priv->statusbar = ephy_statusbar_new (); gtk_box_pack_start (GTK_BOX (window->priv->main_vbox), @@ -1961,8 +1963,21 @@ ephy_window_init (EphyWindow *window) window->priv->enc_menu = ephy_encoding_menu_new (window); window->priv->bmk_menu = ephy_bookmarks_menu_new (window); - /* create the toolbar */ + /* create the toolbars */ window->priv->toolbar = toolbar_new (window); + window->priv->bookmarksbar = ephy_bookmarksbar_new (window); + + /* forward the toolbar's action_request signal to the bookmarks toolbar, + * so the user can also have bookmarks on the normal toolbar + */ + g_signal_connect (window->priv->toolbar, "action_request", + G_CALLBACK (action_request_forward_cb), + window->priv->bookmarksbar); + + /* Add the toolbars to the window */ + gtk_box_pack_end (GTK_BOX (window->priv->menu_dock), + window->priv->bookmarksbar, + FALSE, FALSE, 0); gtk_box_pack_end (GTK_BOX (window->priv->menu_dock), GTK_WIDGET (window->priv->toolbar), FALSE, FALSE, 0); @@ -1973,10 +1988,6 @@ ephy_window_init (EphyWindow *window) manager = EPHY_EXTENSION (ephy_shell_get_extensions_manager (ephy_shell)); ephy_extension_attach_window (manager, window); - /* show widgets */ - gtk_widget_show (GTK_WIDGET (window->priv->toolbar)); - gtk_widget_show (GTK_WIDGET (window->priv->notebook)); - g_signal_connect (window, "window-state-event", G_CALLBACK (ephy_window_state_event_cb), window); @@ -2150,9 +2161,7 @@ ephy_window_set_print_preview (EphyWindow *window, gboolean enabled) * ephy_window_get_toolbar: * @window: an #EphyWindow * - * Returns this window's toolbar as an #EggEditableToolbar. Note that this - * toolbar is uneditable outside of Epiphany itself (i.e., extensions should not - * access it). + * Returns this window's toolbar as an #EggEditableToolbar. * * Return value: an #EggEditableToolbar **/ @@ -2165,6 +2174,22 @@ ephy_window_get_toolbar (EphyWindow *window) } /** + * ephy_window_get_bookmarksbar: + * @window: an #EphyWindow + * + * Returns this window's bookmarks toolbar, which is an #EggEditableToolbar. + * + * Return value: an #EggEditableToolbar + **/ +GtkWidget * +ephy_window_get_bookmarksbar (EphyWindow *window) +{ + g_return_val_if_fail (EPHY_IS_WINDOW (window), NULL); + + return GTK_WIDGET (window->priv->bookmarksbar); +} + +/** * ephy_window_get_notebook: * @window: an #EphyWindow * diff --git a/src/ephy-window.h b/src/ephy-window.h index 4370c8081..e1c6f4261 100644 --- a/src/ephy-window.h +++ b/src/ephy-window.h @@ -71,6 +71,8 @@ void ephy_window_set_print_preview (EphyWindow *window, GtkWidget *ephy_window_get_toolbar (EphyWindow *window); +GtkWidget *ephy_window_get_bookmarksbar (EphyWindow *window); + GtkWidget *ephy_window_get_notebook (EphyWindow *window); GtkWidget *ephy_window_get_statusbar (EphyWindow *window); diff --git a/src/toolbar.c b/src/toolbar.c index 2a24815bd..d2a0d79e5 100755 --- a/src/toolbar.c +++ b/src/toolbar.c @@ -1,6 +1,7 @@ /* - * Copyright (C) 2000 Marco Pesenti Gritti + * Copyright (C) 2000-2004 Marco Pesenti Gritti * Copyright (C) 2001, 2002 Jorn Baayen + * Copyright (C) 2003, 2004 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 @@ -24,57 +25,42 @@ #endif #include "toolbar.h" -#include "ephy-file-helpers.h" -#include "ephy-shell.h" -#include "ephy-location-entry.h" -#include "ephy-dnd.h" -#include "ephy-spinner.h" -#include "ephy-location-action.h" #include "ephy-favicon-action.h" -#include "ephy-topic-action.h" #include "ephy-go-action.h" +#include "ephy-location-entry.h" +#include "ephy-location-action.h" #include "ephy-navigation-action.h" -#include "ephy-bookmark-action.h" +#include "ephy-spinner.h" +#include "ephy-dnd.h" +#include "ephy-topic-action.h" #include "ephy-zoom-action.h" -#include "window-commands.h" -#include "ephy-string.h" -#include "ephy-debug.h" -#include "ephy-new-bookmark.h" +#include "ephy-shell.h" #include "ephy-stock-icons.h" -#include "ephy-toolbars-model.h" +#include "window-commands.h" #include "eel-gconf-extensions.h" +#include "ephy-debug.h" #include <string.h> #include <glib/gi18n.h> #include <gtk/gtkuimanager.h> -#include <gtk/gtktoolbar.h> static void toolbar_class_init (ToolbarClass *klass); static void toolbar_init (Toolbar *t); static void toolbar_finalize (GObject *object); static void toolbar_set_window (Toolbar *t, EphyWindow *window); -static void -toolbar_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec); -static void -toolbar_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec); -static GtkTargetEntry drag_targets[] = { - { EGG_TOOLBAR_ITEM_TYPE, 0, 0 }, - { EPHY_DND_TOPIC_TYPE, 0, 1 }, - { EPHY_DND_URL_TYPE, 0, 2 }, +static GtkTargetEntry drag_targets[] = +{ + { EGG_TOOLBAR_ITEM_TYPE, 0, 0 }, + { EPHY_DND_TOPIC_TYPE, 0, 1 }, + { EPHY_DND_URL_TYPE, 0, 2 } }; static int n_drag_targets = G_N_ELEMENTS (drag_targets); enum { PROP_0, - PROP_EPHY_WINDOW + PROP_WINDOW }; static GObjectClass *parent_class = NULL; @@ -86,13 +72,9 @@ static GObjectClass *parent_class = NULL; struct ToolbarPrivate { EphyWindow *window; - GtkUIManager *ui_merge; GtkActionGroup *action_group; - gboolean visibility; gboolean updating_address; GtkWidget *spinner; - GtkWidget *favicon; - GtkWidget *go; guint disable_arbitrary_url_notifier_id; }; @@ -166,43 +148,7 @@ arbitrary_url_notifier (GConfClient *client, static void go_location_cb (GtkAction *action, char *location, EphyWindow *window) { - GdkEvent *event; - gboolean new_tab = FALSE; - - event = gtk_get_current_event (); - if (event != NULL) - { - if (event->type == GDK_BUTTON_RELEASE) - { - guint modifiers, button, state; - - modifiers = gtk_accelerator_get_default_mod_mask (); - button = event->button.button; - state = event->button.state; - - /* middle-click or control-click */ - if ((button == 1 && ((state & modifiers) == GDK_CONTROL_MASK)) || - (button == 2)) - { - new_tab = TRUE; - } - } - - gdk_event_free (event); - } - - if (new_tab) - { - ephy_shell_new_tab (ephy_shell, window, - ephy_window_get_active_tab (window), - location, - EPHY_NEW_TAB_OPEN_PAGE | - EPHY_NEW_TAB_IN_EXISTING_WINDOW); - } - else - { - ephy_window_load_url (window, location); - } + ephy_window_load_url (window, location); } static void @@ -212,131 +158,112 @@ zoom_to_level_cb (GtkAction *action, float zoom, EphyWindow *window) } static void -bookmark_destroy_cb (EphyNode *node, - Toolbar *t) +toolbar_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) { - GtkAction *action; - char *name; - EphyToolbarsModel *model; - long id; + Toolbar *t = EPHY_TOOLBAR (object); - model = EPHY_TOOLBARS_MODEL - (ephy_shell_get_toolbars_model (ephy_shell, FALSE)); + switch (prop_id) + { + case PROP_WINDOW: + toolbar_set_window (t, g_value_get_object (value)); + break; + } +} - id = ephy_node_get_id (node); - name = ephy_toolbars_model_get_action_name (model, id); - action = gtk_action_group_get_action (t->priv->action_group, name); - if (action) - { - gtk_action_group_remove_action (t->priv->action_group, action); - } +static void +toolbar_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + /* no readable properties */ + g_assert_not_reached (); +} + +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); - g_free (name); + egg_editable_toolbar_set_drag_dest + (toolbar, drag_targets, n_drag_targets, t_name); } static void -toolbar_ensure_action (Toolbar *t, - const char *name) +toolbar_realize (GtkWidget *widget) { - GtkAction *action = NULL; - EphyToolbarsModel *model; - EphyBookmarks *bookmarks; - EphyNode *bmks, *topics; + EggEditableToolbar *eggtoolbar = EGG_EDITABLE_TOOLBAR (widget); + Toolbar *toolbar = EPHY_TOOLBAR (widget); + EggToolbarsModel *model = egg_editable_toolbar_get_model (eggtoolbar); + int i, n_toolbars; - model = EPHY_TOOLBARS_MODEL - (ephy_shell_get_toolbars_model (ephy_shell, FALSE)); - bookmarks = ephy_shell_get_bookmarks (ephy_shell); - bmks = ephy_bookmarks_get_bookmarks (bookmarks); - topics = ephy_bookmarks_get_keywords (bookmarks); + GTK_WIDGET_CLASS (parent_class)->realize (widget); - LOG ("Ensure action %s", name) + g_signal_connect (model, "toolbar_added", + G_CALLBACK (toolbar_added_cb), toolbar); - if (g_str_has_prefix (name, "GoBookmark-")) + /* 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++) { - EphyNode *node; + const char *t_name; - node = ephy_toolbars_model_get_node (model,name); - g_return_if_fail (node != NULL); + t_name = egg_toolbars_model_toolbar_nth (model, i); + g_return_if_fail (t_name != NULL); - if (ephy_node_has_child (topics, node)) - { - action = ephy_topic_action_new (name, ephy_node_get_id (node)); - } - else if (ephy_node_has_child (bmks, node)) - { - action = ephy_bookmark_action_new (name, ephy_node_get_id (node)); - } + egg_editable_toolbar_set_drag_dest + (eggtoolbar, drag_targets, n_drag_targets, t_name); + } +} - g_return_if_fail (action != NULL); +static void +toolbar_unrealize (GtkWidget *widget) +{ + EggEditableToolbar *eggtoolbar = EGG_EDITABLE_TOOLBAR (widget); + Toolbar *toolbar = EPHY_TOOLBAR (widget); + EggToolbarsModel *model = egg_editable_toolbar_get_model (eggtoolbar); - g_signal_connect (action, "go_location", - G_CALLBACK (go_location_cb), t->priv->window); - gtk_action_group_add_action (t->priv->action_group, action); - g_object_unref (action); + g_signal_handlers_disconnect_by_func + (model, G_CALLBACK (toolbar_added_cb), toolbar); - ephy_node_signal_connect_object (node, - EPHY_NODE_DESTROY, - (EphyNodeCallback) bookmark_destroy_cb, - G_OBJECT (t)); - } + GTK_WIDGET_CLASS (parent_class)->unrealize (widget); } static void toolbar_class_init (ToolbarClass *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->finalize = toolbar_finalize; object_class->set_property = toolbar_set_property; object_class->get_property = toolbar_get_property; + widget_class->realize = toolbar_realize; + widget_class->unrealize = toolbar_unrealize; g_object_class_install_property (object_class, - PROP_EPHY_WINDOW, + PROP_WINDOW, g_param_spec_object ("window", "Window", "Parent window", EPHY_TYPE_WINDOW, - G_PARAM_READWRITE | + G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); g_type_class_add_private (object_class, sizeof(ToolbarPrivate)); } static void -toolbar_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - Toolbar *t = EPHY_TOOLBAR (object); - - switch (prop_id) - { - case PROP_EPHY_WINDOW: - toolbar_set_window (t, g_value_get_object (value)); - break; - } -} - -static void -toolbar_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - Toolbar *t = EPHY_TOOLBAR (object); - - switch (prop_id) - { - case PROP_EPHY_WINDOW: - g_value_set_object (value, t->priv->window); - break; - } -} - -static void sync_user_input_cb (EphyLocationAction *action, GParamSpec *pspec, Toolbar *t) { EphyTab *tab; @@ -453,120 +380,22 @@ toolbar_setup_actions (Toolbar *t) } static void -action_request_cb (EggEditableToolbar *etoolbar, - char *action_name, - gpointer data) -{ - toolbar_ensure_action (EPHY_TOOLBAR (etoolbar), action_name); -} - -static void -init_bookmarks_toolbar (Toolbar *t) -{ - EphyToolbarsModel *model; - int i, n_toolbars; - - model = EPHY_TOOLBARS_MODEL - (ephy_shell_get_toolbars_model (ephy_shell, FALSE)); - n_toolbars = egg_toolbars_model_n_toolbars - (EGG_TOOLBARS_MODEL (model)); - - for (i = 0; i < n_toolbars; i++) - { - const char *t_name; - - t_name = egg_toolbars_model_toolbar_nth - (EGG_TOOLBARS_MODEL (model), i); - g_return_if_fail (t_name != NULL); - - if (strcmp (t_name, "BookmarksBar") == 0) - { - egg_editable_toolbar_set_drag_dest - (EGG_EDITABLE_TOOLBAR (t), - drag_targets, n_drag_targets, - t_name); - egg_toolbars_model_set_flags - (EGG_TOOLBARS_MODEL (model), - EGG_TB_MODEL_NOT_REMOVABLE, i); - } - } -} - -static void -init_normal_mode (Toolbar *t) -{ - EphyToolbarsModel *model; - - model = EPHY_TOOLBARS_MODEL - (ephy_shell_get_toolbars_model (ephy_shell, FALSE)); - - g_object_set (G_OBJECT (t), - "ToolbarsModel", model, - NULL); - init_bookmarks_toolbar (t); -} - -static void -init_fullscreen_mode (Toolbar *t) -{ - EggToolbarsModel *model; - - model = EGG_TOOLBARS_MODEL - (ephy_shell_get_toolbars_model (ephy_shell, TRUE)); - - g_object_set (G_OBJECT (t), - "ToolbarsModel", model, - NULL); -} - -static gboolean -window_state_event_cb (GtkWidget *widget, GdkEventWindowState *event, Toolbar *t) -{ - if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN) - { - gboolean fullscreen; - - fullscreen = event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN; - if (fullscreen) - { - init_fullscreen_mode (t); - } - else - { - init_normal_mode (t); - } - } - - return FALSE; -} - -static void toolbar_set_window (Toolbar *t, EphyWindow *window) { + GtkUIManager *manager; + g_return_if_fail (t->priv->window == NULL); t->priv->window = window; - t->priv->ui_merge = GTK_UI_MANAGER (window->ui_merge); + manager = GTK_UI_MANAGER (window->ui_merge); toolbar_setup_actions (t); - gtk_ui_manager_insert_action_group (t->priv->ui_merge, + gtk_ui_manager_insert_action_group (manager, t->priv->action_group, 1); - g_signal_connect (t, "action_request", - G_CALLBACK (action_request_cb), - NULL); - g_signal_connect_object (window, "window-state-event", - G_CALLBACK (window_state_event_cb), - t, 0); t->priv->disable_arbitrary_url_notifier_id = eel_gconf_notification_add (CONF_LOCKDOWN_DISABLE_ARBITRARY_URL, (GConfClientNotifyFunc)arbitrary_url_notifier, t); - - g_object_set (G_OBJECT (t), - "MenuMerge", t->priv->ui_merge, - NULL); - - init_normal_mode (t); } static void @@ -604,11 +433,6 @@ toolbar_init (Toolbar *t) { t->priv = EPHY_TOOLBAR_GET_PRIVATE (t); - t->priv->window = NULL; - t->priv->ui_merge = NULL; - t->priv->visibility = TRUE; - t->priv->updating_address = FALSE; - create_spinner (t); } @@ -616,10 +440,15 @@ static void toolbar_finalize (GObject *object) { Toolbar *t = EPHY_TOOLBAR (object); + EggEditableToolbar *eggtoolbar = EGG_EDITABLE_TOOLBAR (object); eel_gconf_notification_remove (t->priv->disable_arbitrary_url_notifier_id); + g_signal_handlers_disconnect_by_func + (egg_editable_toolbar_get_model (eggtoolbar), + G_CALLBACK (toolbar_added_cb), t); + g_object_unref (t->priv->action_group); G_OBJECT_CLASS (parent_class)->finalize (object); @@ -632,6 +461,8 @@ toolbar_new (EphyWindow *window) { return EPHY_TOOLBAR (g_object_new (EPHY_TYPE_TOOLBAR, "window", window, + "MenuMerge", window->ui_merge, + "ToolbarsModel", ephy_shell_get_toolbars_model (ephy_shell, FALSE), NULL)); } @@ -666,9 +497,6 @@ toolbar_set_location (Toolbar *t, GtkActionGroup *action_group; GtkAction *action; - LOG ("toolbar set location %s", address) - LOG ("updating is %d", t->priv->updating_address) - if (t->priv->updating_address) return; action_group = t->priv->action_group; @@ -722,55 +550,6 @@ toolbar_update_navigation_actions (Toolbar *t, gboolean back, gboolean forward, } void -toolbar_set_visibility (Toolbar *t, - gboolean normal_toolbars, - gboolean bmk_toolbars) -{ - EphyToolbarsModel *model; - int i, n_toolbars; - - model = EPHY_TOOLBARS_MODEL - (ephy_shell_get_toolbars_model (ephy_shell, FALSE)); - n_toolbars = egg_toolbars_model_n_toolbars - (EGG_TOOLBARS_MODEL (model)); - - for (i = 0; i < n_toolbars; i++) - { - const char *t_name; - - t_name = egg_toolbars_model_toolbar_nth - (EGG_TOOLBARS_MODEL (model), i); - g_return_if_fail (t_name != NULL); - if (strcmp (t_name, "BookmarksBar") == 0) - { - if (bmk_toolbars) - { - egg_editable_toolbar_show - (EGG_EDITABLE_TOOLBAR (t), t_name); - } - else - { - egg_editable_toolbar_hide - (EGG_EDITABLE_TOOLBAR (t), t_name); - } - } - else - { - if (normal_toolbars) - { - egg_editable_toolbar_show - (EGG_EDITABLE_TOOLBAR (t), t_name); - } - else - { - egg_editable_toolbar_hide - (EGG_EDITABLE_TOOLBAR (t), t_name); - } - } - } -} - -void toolbar_update_zoom (Toolbar *t, float zoom) { GtkActionGroup *action_group; diff --git a/src/toolbar.h b/src/toolbar.h index ff58e3f35..8ed3a52a3 100644 --- a/src/toolbar.h +++ b/src/toolbar.h @@ -1,6 +1,8 @@ /* * Copyright (C) 2002 Jorn Baayen - * + * Copyright (C) 2003-2004 Marco Pesenti Gritti + * Copyright (C) 2003-2004 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) @@ -78,10 +80,6 @@ void toolbar_update_navigation_actions (Toolbar *t, void toolbar_update_zoom (Toolbar *t, float zoom); -void toolbar_set_visibility (Toolbar *t, - gboolean normal_toolbars, - gboolean bmk_toolbars); - G_END_DECLS #endif diff --git a/src/window-commands.c b/src/window-commands.c index 266e9e405..83d5aeae7 100644 --- a/src/window-commands.c +++ b/src/window-commands.c @@ -42,7 +42,7 @@ #include "ephy-state.h" #include "ephy-gui.h" #include "ephy-zoom.h" -#include "ephy-toolbars-model.h" +#include "egg-toolbars-model.h" #include "egg-editable-toolbar.h" #include "egg-toolbar-editor.h" @@ -592,6 +592,9 @@ void window_cmd_view_fullscreen (GtkAction *action, EphyWindow *window) { + /* Otherwise the other toolbar layout shows briefly while switching */ + gtk_widget_hide (ephy_window_get_toolbar (window)); + if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))) { gtk_window_fullscreen (GTK_WINDOW (window)); @@ -806,30 +809,26 @@ window_cmd_edit_prefs (GtkAction *action, static void toolbar_editor_destroy_cb (GtkWidget *tbe, - Toolbar *t) + EphyWindow *window) { - egg_editable_toolbar_set_edit_mode (EGG_EDITABLE_TOOLBAR (t), FALSE); + egg_editable_toolbar_set_edit_mode (EGG_EDITABLE_TOOLBAR + (ephy_window_get_toolbar (window)), FALSE); + egg_editable_toolbar_set_edit_mode (EGG_EDITABLE_TOOLBAR + (ephy_window_get_bookmarksbar (window)), FALSE); } static void toolbar_editor_response_cb (GtkDialog *dialog, gint response_id, - gpointer data) + EggToolbarsModel *model) { - EphyToolbarsModel *model; - int n; - switch (response_id) { case GTK_RESPONSE_CLOSE: gtk_widget_destroy (GTK_WIDGET (dialog)); break; case RESPONSE_ADD_TOOLBAR: - model = EPHY_TOOLBARS_MODEL - (ephy_shell_get_toolbars_model (ephy_shell, FALSE)); - n = egg_toolbars_model_n_toolbars (EGG_TOOLBARS_MODEL (model)); - egg_toolbars_model_add_toolbar (EGG_TOOLBARS_MODEL (model), - n - 1, "UserCreated"); + egg_toolbars_model_add_toolbar (model, -1, "UserCreated"); break; case GTK_RESPONSE_HELP: ephy_gui_help (GTK_WINDOW (dialog), "epiphany", "to-edit-toolbars"); @@ -842,31 +841,28 @@ window_cmd_edit_toolbar (GtkAction *action, EphyWindow *window) { GtkWidget *editor; - EphyToolbarsModel *model; + EggToolbarsModel *model; GtkWidget *t; GtkWidget *dialog; - model = EPHY_TOOLBARS_MODEL + model = EGG_TOOLBARS_MODEL (ephy_shell_get_toolbars_model (ephy_shell, FALSE)); t = ephy_window_get_toolbar (window); dialog = gtk_dialog_new (); gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE); gtk_window_set_title (GTK_WINDOW (dialog), _("Toolbar Editor")); - gtk_window_set_transient_for (GTK_WINDOW (dialog), - GTK_WINDOW (window)); + gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (window)); + gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE); - editor = egg_toolbar_editor_new - (GTK_UI_MANAGER (window->ui_merge), - EGG_TOOLBARS_MODEL (model)); + editor = egg_toolbar_editor_new (GTK_UI_MANAGER (window->ui_merge), model); egg_toolbar_editor_load_actions (EGG_TOOLBAR_EDITOR (editor), ephy_file ("epiphany-toolbar.xml")); gtk_container_set_border_width (GTK_CONTAINER (EGG_TOOLBAR_EDITOR (editor)), 5); gtk_box_set_spacing (GTK_BOX (EGG_TOOLBAR_EDITOR (editor)), 5); gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), editor); g_signal_connect (editor, "destroy", - G_CALLBACK (toolbar_editor_destroy_cb), - t); + G_CALLBACK (toolbar_editor_destroy_cb), window); gtk_widget_show (editor); gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 2); @@ -881,7 +877,7 @@ window_cmd_edit_toolbar (GtkAction *action, GTK_STOCK_HELP, GTK_RESPONSE_HELP); g_signal_connect (G_OBJECT (dialog), "response", - G_CALLBACK (toolbar_editor_response_cb), NULL); + G_CALLBACK (toolbar_editor_response_cb), model); ephy_state_add_window (dialog, "toolbar_editor", 500, 330, @@ -889,6 +885,8 @@ window_cmd_edit_toolbar (GtkAction *action, gtk_widget_show (dialog); egg_editable_toolbar_set_edit_mode (EGG_EDITABLE_TOOLBAR (t), TRUE); + egg_editable_toolbar_set_edit_mode + (EGG_EDITABLE_TOOLBAR (ephy_window_get_bookmarksbar (window)), TRUE); } void |