[gthumb/ext] added ability to specify the bookmark menu item name
- From: Paolo Bacchilega <paobac src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gthumb/ext] added ability to specify the bookmark menu item name
- Date: Wed, 4 Nov 2009 22:50:42 +0000 (UTC)
commit 977ff06a90bb7992afeb2e9498bd9b736b260f88
Author: Paolo Bacchilega <paobac src gnome org>
Date: Wed Nov 4 23:45:12 2009 +0100
added ability to specify the bookmark menu item name
extensions/bookmarks/callbacks.c | 4 +
extensions/bookmarks/data/ui/bookmarks.ui | 113 ++++++++++++++++++++-
extensions/bookmarks/dlg-bookmarks.c | 160 ++++++++++++++++++++++++----
gthumb/glib-utils.c | 2 +-
gthumb/gth-browser.c | 9 ++-
gthumb/gth-browser.h | 1 +
gthumb/gth-uri-list.c | 91 ++++++++++++++++
gthumb/gth-uri-list.h | 20 ++--
8 files changed, 363 insertions(+), 37 deletions(-)
---
diff --git a/extensions/bookmarks/callbacks.c b/extensions/bookmarks/callbacks.c
index 9b7401d..eea77e2 100644
--- a/extensions/bookmarks/callbacks.c
+++ b/extensions/bookmarks/callbacks.c
@@ -256,14 +256,18 @@ _gth_browser_update_bookmark_list (GthBrowser *browser)
for (i = 0; uris[i] != NULL; i++) {
GFile *file;
+ char *name;
file = g_file_new_for_uri (uris[i]);
+ name = g_bookmark_file_get_title (bookmarks, uris[i], NULL);
_gth_browser_add_file_menu_item (browser,
menu,
file,
+ name,
GTH_ACTION_GO_TO,
i);
+ g_free (name);
g_object_unref (file);
}
diff --git a/extensions/bookmarks/data/ui/bookmarks.ui b/extensions/bookmarks/data/ui/bookmarks.ui
index 54c627d..4adf5bb 100644
--- a/extensions/bookmarks/data/ui/bookmarks.ui
+++ b/extensions/bookmarks/data/ui/bookmarks.ui
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<interface>
- <requires lib="gtk+" version="2.14"/>
+ <requires lib="gtk+" version="2.16"/>
<!-- interface-naming-policy project-wide -->
<object class="GtkDialog" id="bookmarks_dialog">
<property name="height_request">300</property>
@@ -11,13 +11,16 @@
<child internal-child="vbox">
<object class="GtkVBox" id="dialog-vbox7">
<property name="visible">True</property>
+ <property name="orientation">vertical</property>
<child>
<object class="GtkHBox" id="hbox57">
<property name="visible">True</property>
<property name="border_width">6</property>
+ <property name="spacing">24</property>
<child>
<object class="GtkVBox" id="vbox47">
<property name="visible">True</property>
+ <property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<object class="GtkLabel" id="bm_bookmarks_label">
@@ -37,6 +40,7 @@
<property name="visible">True</property>
<child>
<object class="GtkScrolledWindow" id="bm_list_container">
+ <property name="width_request">250</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">automatic</property>
@@ -61,6 +65,109 @@
<property name="position">0</property>
</packing>
</child>
+ <child>
+ <object class="GtkVBox" id="vbox1">
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">12</property>
+ <child>
+ <object class="GtkVBox" id="vbox2">
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">6</property>
+ <child>
+ <object class="GtkLabel" id="label1">
+ <property name="visible">True</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">_Name</property>
+ <property name="use_underline">True</property>
+ <property name="mnemonic_widget">entry_name</property>
+ <attributes>
+ <attribute name="weight" value="bold"/>
+ </attributes>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkAlignment" id="alignment1">
+ <property name="visible">True</property>
+ <property name="left_padding">12</property>
+ <child>
+ <object class="GtkEntry" id="entry_name">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="invisible_char">●</property>
+ <property name="width_chars">30</property>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkVBox" id="vbox3">
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">6</property>
+ <child>
+ <object class="GtkLabel" id="label2">
+ <property name="visible">True</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">_Location</property>
+ <property name="use_underline">True</property>
+ <property name="mnemonic_widget">entry_location</property>
+ <attributes>
+ <attribute name="weight" value="bold"/>
+ </attributes>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkAlignment" id="alignment2">
+ <property name="visible">True</property>
+ <property name="left_padding">12</property>
+ <child>
+ <object class="GtkEntry" id="entry_location">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="invisible_char">●</property>
+ <property name="width_chars">30</property>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="position">1</property>
+ </packing>
+ </child>
</object>
<packing>
<property name="position">1</property>
@@ -72,7 +179,7 @@
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="bm_go_to_button">
- <property name="label" translatable="yes">gtk-jump-to</property>
+ <property name="label">gtk-jump-to</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
@@ -100,7 +207,7 @@
</child>
<child>
<object class="GtkButton" id="bm_close_button">
- <property name="label" translatable="yes">gtk-close</property>
+ <property name="label">gtk-close</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
diff --git a/extensions/bookmarks/dlg-bookmarks.c b/extensions/bookmarks/dlg-bookmarks.c
index fa5a7c7..a48fd67 100644
--- a/extensions/bookmarks/dlg-bookmarks.c
+++ b/extensions/bookmarks/dlg-bookmarks.c
@@ -25,6 +25,9 @@
#include <gthumb.h>
+#define UPDATE_DELAY 200
+
+
typedef struct {
GthBrowser *browser;
GtkBuilder *builder;
@@ -32,6 +35,7 @@ typedef struct {
GtkWidget *uri_list;
gboolean do_not_update;
gulong bookmarks_changed_id;
+ gulong update_from_entry_id;
} DialogData;
@@ -40,6 +44,8 @@ static void
destroy_cb (GtkWidget *widget,
DialogData *data)
{
+ if (data->update_from_entry_id != 0)
+ g_source_remove (data->update_from_entry_id);
gth_browser_set_dialog (data->browser, "bookmarks", NULL);
g_signal_handler_disconnect (gth_main_get_default_monitor (), data->bookmarks_changed_id);
@@ -93,13 +99,10 @@ static void
bookmarks_changed_cb (GthMonitor *monitor,
DialogData *data)
{
- GBookmarkFile *bookmarks;
- char **uris;
+ GBookmarkFile *bookmarks;
bookmarks = gth_main_get_default_bookmarks ();
- uris = g_bookmark_file_get_uris (bookmarks, NULL);
- gth_uri_list_set_uris (GTH_URI_LIST (data->uri_list), uris);
- g_strfreev (uris);
+ gth_uri_list_set_bookmarks (GTH_URI_LIST (data->uri_list), bookmarks);
}
@@ -108,13 +111,9 @@ uri_list_order_changed_cb (GthUriList *uri_list,
DialogData *data)
{
GBookmarkFile *bookmarks;
- GList *uris;
-
- uris = gth_uri_list_get_uris (GTH_URI_LIST (data->uri_list));
+
bookmarks = gth_main_get_default_bookmarks ();
- _g_bookmark_file_set_uris (bookmarks, uris);
- _g_string_list_free (uris);
-
+ gth_uri_list_update_bookmarks (GTH_URI_LIST (data->uri_list), bookmarks);
gth_main_bookmarks_changed ();
}
@@ -147,17 +146,119 @@ uri_list_row_activated_cb (GtkTreeView *tree_view,
}
+static gboolean
+save_bookmarks_cb (gpointer user_data)
+{
+ DialogData *data = user_data;
+ const char *name;
+ const char *location;
+ GFile *file;
+ char *uri;
+ GBookmarkFile *bookmarks;
+
+ if (data->update_from_entry_id != 0) {
+ g_source_remove (data->update_from_entry_id);
+ data->update_from_entry_id = 0;
+ }
+
+ name = gtk_entry_get_text (GTK_ENTRY (_gtk_builder_get_widget (data->builder, "entry_name")));
+ location = gtk_entry_get_text (GTK_ENTRY (_gtk_builder_get_widget (data->builder, "entry_location")));
+ file = g_file_parse_name (location);
+ uri = g_file_get_uri (file);
+
+ bookmarks = gth_main_get_default_bookmarks ();
+ g_bookmark_file_set_title (bookmarks, uri, name);
+ gth_main_bookmarks_changed ();
+
+ g_free (uri);
+ g_object_unref (file);
+
+ return FALSE;
+}
+
+
+static void
+entry_changed_cb (GtkEditable *editable,
+ DialogData *data)
+{
+ if (data->update_from_entry_id != 0) {
+ g_source_remove (data->update_from_entry_id);
+ data->update_from_entry_id = 0;
+ }
+
+ data->update_from_entry_id = gdk_threads_add_timeout (UPDATE_DELAY, save_bookmarks_cb, data);
+}
+
+
+static void
+update_dialog_from_bookmark_file (DialogData *data,
+ const char *uri)
+{
+ GBookmarkFile *bookmarks;
+ GFile *file;
+ char *location;
+ char *name;
+
+ bookmarks = gth_main_get_default_bookmarks ();
+
+ file = g_file_new_for_uri (uri);
+ location = g_file_get_parse_name (file);
+
+ name = g_bookmark_file_get_title (bookmarks, uri, NULL);
+ if (name == NULL)
+ name = g_strdup (location);
+
+ g_signal_handlers_block_by_func (_gtk_builder_get_widget (data->builder, "entry_name"), entry_changed_cb, data);
+ g_signal_handlers_block_by_func (_gtk_builder_get_widget (data->builder, "entry_location"), entry_changed_cb, data);
+ gtk_entry_set_text (GTK_ENTRY (_gtk_builder_get_widget (data->builder, "entry_name")), name);
+ gtk_entry_set_text (GTK_ENTRY (_gtk_builder_get_widget (data->builder, "entry_location")), location);
+ g_signal_handlers_unblock_by_func (_gtk_builder_get_widget (data->builder, "entry_location"), entry_changed_cb, data);
+ g_signal_handlers_unblock_by_func (_gtk_builder_get_widget (data->builder, "entry_name"), entry_changed_cb, data);
+
+ g_free (name);
+ g_free (location);
+ g_object_unref (file);
+}
+
+
+static void
+uri_list_selection_changed_cb (GtkTreeSelection *treeselection,
+ gpointer user_data)
+{
+ DialogData *data = user_data;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ char *uri;
+
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (data->uri_list));
+ if (! gtk_tree_selection_get_selected (treeselection,
+ &model,
+ &iter))
+ {
+ return;
+ }
+
+ uri = gth_uri_list_get_uri (GTH_URI_LIST (data->uri_list), &iter);
+ if (uri == NULL)
+ return;
+
+ update_dialog_from_bookmark_file (data, uri);
+
+ g_free (uri);
+}
+
+
void
dlg_bookmarks (GthBrowser *browser)
{
- DialogData *data;
- GtkWidget *bm_list_container;
- GtkWidget *bm_bookmarks_label;
- GtkWidget *bm_remove_button;
- GtkWidget *bm_close_button;
- GtkWidget *bm_go_to_button;
- GBookmarkFile *bookmarks;
- char **uris;
+ DialogData *data;
+ GtkWidget *bm_list_container;
+ GtkWidget *bm_bookmarks_label;
+ GtkWidget *bm_remove_button;
+ GtkWidget *bm_close_button;
+ GtkWidget *bm_go_to_button;
+ GBookmarkFile *bookmarks;
+ GtkTreeSelection *selection;
if (gth_browser_get_dialog (browser, "bookmarks") != NULL) {
gtk_window_present (GTK_WINDOW (gth_browser_get_dialog (browser, "bookmarks")));
@@ -168,6 +269,7 @@ dlg_bookmarks (GthBrowser *browser)
data->browser = browser;
data->do_not_update = FALSE;
data->builder = _gtk_builder_new_from_file ("bookmarks.ui", "bookmarks");
+ data->update_from_entry_id = 0;
/* Get the widgets. */
@@ -189,9 +291,7 @@ dlg_bookmarks (GthBrowser *browser)
/* Set widgets data. */
bookmarks = gth_main_get_default_bookmarks ();
- uris = g_bookmark_file_get_uris (bookmarks, NULL);
- gth_uri_list_set_uris (GTH_URI_LIST (data->uri_list), uris);
- g_strfreev (uris);
+ gth_uri_list_set_bookmarks (GTH_URI_LIST (data->uri_list), bookmarks);
data->bookmarks_changed_id = g_signal_connect (gth_main_get_default_monitor (),
"bookmarks-changed",
@@ -224,7 +324,21 @@ dlg_bookmarks (GthBrowser *browser)
"row-activated",
G_CALLBACK (uri_list_row_activated_cb),
data);
-
+ g_signal_connect (_gtk_builder_get_widget (data->builder, "entry_location"),
+ "changed",
+ G_CALLBACK (entry_changed_cb),
+ data);
+ g_signal_connect (_gtk_builder_get_widget (data->builder, "entry_name"),
+ "changed",
+ G_CALLBACK (entry_changed_cb),
+ data);
+
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (data->uri_list));
+ g_signal_connect (selection,
+ "changed",
+ G_CALLBACK (uri_list_selection_changed_cb),
+ data);
+
/* run dialog. */
gtk_window_set_transient_for (GTK_WINDOW (data->dialog),
diff --git a/gthumb/glib-utils.c b/gthumb/glib-utils.c
index c9167b5..15f7766 100644
--- a/gthumb/glib-utils.c
+++ b/gthumb/glib-utils.c
@@ -487,7 +487,7 @@ void
_g_bookmark_file_add_uri (GBookmarkFile *bookmark,
const char *uri)
{
- g_bookmark_file_set_is_private (bookmark, uri,TRUE);
+ g_bookmark_file_set_is_private (bookmark, uri, TRUE);
g_bookmark_file_add_application (bookmark, uri, NULL, NULL);
}
diff --git a/gthumb/gth-browser.c b/gthumb/gth-browser.c
index d60b7db..c9f3101 100644
--- a/gthumb/gth-browser.c
+++ b/gthumb/gth-browser.c
@@ -362,6 +362,7 @@ void
_gth_browser_add_file_menu_item (GthBrowser *browser,
GtkWidget *menu,
GFile *file,
+ const char *display_name,
GthAction action,
int steps)
{
@@ -375,7 +376,7 @@ _gth_browser_add_file_menu_item (GthBrowser *browser,
menu,
file,
g_file_info_get_icon (info),
- g_file_info_get_display_name (info),
+ (display_name != NULL) ? display_name : g_file_info_get_display_name (info),
action,
steps,
-1);
@@ -391,7 +392,7 @@ _gth_browser_add_file_menu_item (GthBrowser *browser,
menu,
file,
icon,
- name,
+ (display_name != NULL) ? display_name : name,
action,
steps,
-1);
@@ -427,6 +428,7 @@ _gth_browser_update_parent_list (GthBrowser *browser)
_gth_browser_add_file_menu_item (browser,
menu,
parent,
+ NULL,
GTH_ACTION_GO_UP,
++i);
@@ -634,6 +636,7 @@ _gth_browser_update_history_list (GthBrowser *browser)
_gth_browser_add_file_menu_item (browser,
menu,
scan->data,
+ NULL,
GTH_ACTION_GO_BACK,
++i);
}
@@ -658,6 +661,7 @@ _gth_browser_update_history_list (GthBrowser *browser)
_gth_browser_add_file_menu_item (browser,
menu,
scan->data,
+ NULL,
GTH_ACTION_GO_FORWARD,
++i);
}
@@ -682,6 +686,7 @@ _gth_browser_update_history_list (GthBrowser *browser)
_gth_browser_add_file_menu_item (browser,
menu,
scan->data,
+ NULL,
GTH_ACTION_GO_TO,
++i);
}
diff --git a/gthumb/gth-browser.h b/gthumb/gth-browser.h
index 7b089e8..c04b818 100644
--- a/gthumb/gth-browser.h
+++ b/gthumb/gth-browser.h
@@ -175,6 +175,7 @@ void gth_browser_file_menu_popup (GthBrowser *browser,
void _gth_browser_add_file_menu_item (GthBrowser *browser,
GtkWidget *menu,
GFile *file,
+ const char *display_name,
GthAction action,
int steps);
void _gth_browser_add_file_menu_item_full (GthBrowser *browser,
diff --git a/gthumb/gth-uri-list.c b/gthumb/gth-uri-list.c
index d7ad569..97c80cb 100644
--- a/gthumb/gth-uri-list.c
+++ b/gthumb/gth-uri-list.c
@@ -287,6 +287,68 @@ gth_uri_list_set_uris (GthUriList *uri_list,
}
+void
+gth_uri_list_set_bookmarks (GthUriList *uri_list,
+ GBookmarkFile *bookmarks)
+{
+ char **uris;
+ int i;
+
+ uris = g_bookmark_file_get_uris (bookmarks, NULL);
+
+ g_return_if_fail (uri_list != NULL);
+
+ g_signal_handlers_block_by_func (uri_list->priv->list_store, row_deleted_cb, uri_list);
+ g_signal_handlers_block_by_func (uri_list->priv->list_store, row_inserted_cb, uri_list);
+
+ gtk_list_store_clear (uri_list->priv->list_store);
+
+ for (i = 0; uris[i] != NULL; i++) {
+ char *uri = uris[i];
+ GFile *file;
+ GthFileSource *file_source;
+ GFileInfo *info;
+ char *display_name;
+ GIcon *icon;
+ GdkPixbuf *pixbuf;
+ GtkTreeIter iter;
+
+ file = g_file_new_for_uri (uri);
+ file_source = gth_main_get_file_source (file);
+ info = gth_file_source_get_file_info (file_source, file, GFILE_DISPLAY_ATTRIBUTES);
+ display_name = g_bookmark_file_get_title (bookmarks, uris[i], NULL);
+
+ if (info != NULL) {
+ if (display_name == NULL)
+ display_name = g_strdup (g_file_info_get_display_name (info));
+ icon = g_file_info_get_icon (info);
+ }
+ else {
+ if (display_name == NULL)
+ display_name = g_strdup (_g_file_get_display_name (file));
+ icon = _g_file_get_icon (file);
+ }
+ pixbuf = gth_icon_cache_get_pixbuf (uri_list->priv->icon_cache, icon);
+
+ gtk_list_store_append (uri_list->priv->list_store, &iter);
+ gtk_list_store_set (uri_list->priv->list_store, &iter,
+ URI_LIST_COLUMN_ICON, pixbuf,
+ URI_LIST_COLUMN_NAME, display_name,
+ URI_LIST_COLUMN_URI, uri,
+ -1);
+
+ g_object_unref (pixbuf);
+ g_object_unref (file_source);
+ g_object_unref (file);
+ }
+
+ g_signal_handlers_unblock_by_func (uri_list->priv->list_store, row_deleted_cb, uri_list);
+ g_signal_handlers_unblock_by_func (uri_list->priv->list_store, row_inserted_cb, uri_list);
+
+ g_strfreev (uris);
+}
+
+
char *
gth_uri_list_get_uri (GthUriList *uri_list,
GtkTreeIter *iter)
@@ -345,3 +407,32 @@ gth_uri_list_get_uris (GthUriList *uri_list)
return g_list_reverse (uris);
}
+
+
+void
+gth_uri_list_update_bookmarks (GthUriList *uri_list,
+ GBookmarkFile *bookmarks)
+{
+ GtkTreeModel *model = GTK_TREE_MODEL (uri_list->priv->list_store);
+ GtkTreeIter iter;
+
+ if (! gtk_tree_model_get_iter_first (model, &iter))
+ return;
+
+ _g_bookmark_file_clear (bookmarks);
+
+ do {
+ char *uri;
+ char *name;
+
+ gtk_tree_model_get (model, &iter,
+ URI_LIST_COLUMN_URI, &uri,
+ URI_LIST_COLUMN_NAME, &name,
+ -1);
+
+ g_bookmark_file_set_is_private (bookmarks, uri, TRUE);
+ g_bookmark_file_add_application (bookmarks, uri, NULL, NULL);
+ g_bookmark_file_set_title (bookmarks, uri, name);
+ }
+ while (gtk_tree_model_iter_next (model, &iter));
+}
diff --git a/gthumb/gth-uri-list.h b/gthumb/gth-uri-list.h
index 216c3a8..6bf58bd 100644
--- a/gthumb/gth-uri-list.h
+++ b/gthumb/gth-uri-list.h
@@ -53,14 +53,18 @@ struct _GthUriListClass {
void (*order_changed) (GthUriList *uri_list);
};
-GType gth_uri_list_get_type (void);
-GtkWidget * gth_uri_list_new (void);
-void gth_uri_list_set_uris (GthUriList *uri_list,
- char **uris);
-char * gth_uri_list_get_uri (GthUriList *uri_list,
- GtkTreeIter *iter);
-char * gth_uri_list_get_selected (GthUriList *uri_list);
-GList * gth_uri_list_get_uris (GthUriList *uri_list);
+GType gth_uri_list_get_type (void);
+GtkWidget * gth_uri_list_new (void);
+void gth_uri_list_set_uris (GthUriList *uri_list,
+ char **uris);
+void gth_uri_list_set_bookmarks (GthUriList *uri_list,
+ GBookmarkFile *bookmarks);
+char * gth_uri_list_get_uri (GthUriList *uri_list,
+ GtkTreeIter *iter);
+char * gth_uri_list_get_selected (GthUriList *uri_list);
+GList * gth_uri_list_get_uris (GthUriList *uri_list);
+void gth_uri_list_update_bookmarks (GthUriList *uri_list,
+ GBookmarkFile *bookmarks);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]