svnno****@sourc*****
svnno****@sourc*****
Thu Oct 4 09:39:21 JST 2007
Revision: 3256 http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=kazehakase&view=rev&rev=3256 Author: ikezoe Date: 2007-10-04 09:39:20 +0900 (Thu, 04 Oct 2007) Log Message: ----------- * src/kz-notebook.[ch]: Add kz_notebook_get_dragged_page(). (kz_notebook_new): Set group property for dropping tab from KzNotebook to KzNotebook. (kz_notebook_init): Use gtk_drag_dest_set() for opening a new tab from dropped URI. * src/bookmarks/kz-bookmark-bar.c: Use kz_notebook_get_dragged_page() for getting URI and title of dropped notebook tab. Modified Paths: -------------- kazehakase/trunk/ChangeLog kazehakase/trunk/src/bookmarks/kz-bookmark-bar.c kazehakase/trunk/src/kz-notebook.c kazehakase/trunk/src/kz-notebook.h Modified: kazehakase/trunk/ChangeLog =================================================================== --- kazehakase/trunk/ChangeLog 2007-10-03 22:24:55 UTC (rev 3255) +++ kazehakase/trunk/ChangeLog 2007-10-04 00:39:20 UTC (rev 3256) @@ -1,6 +1,13 @@ 2007-10-04 Hiroyuki Ikezoe <poinc****@ikezo*****> * src/kz-tab-label.c: GTK_TARGET_OTHER_APP -> 0. + * src/kz-notebook.[ch]: Add kz_notebook_get_dragged_page(). + (kz_notebook_new): Set group property for dropping tab from KzNotebook + to KzNotebook. + (kz_notebook_init): Use gtk_drag_dest_set() for opening a new tab from + dropped URI. + * src/bookmarks/kz-bookmark-bar.c: Use kz_notebook_get_dragged_page() + for getting URI and title of dropped notebook tab. 2007-10-03 Kouhei Sutou <kou****@cozmi*****> Modified: kazehakase/trunk/src/bookmarks/kz-bookmark-bar.c =================================================================== --- kazehakase/trunk/src/bookmarks/kz-bookmark-bar.c 2007-10-03 22:24:55 UTC (rev 3255) +++ kazehakase/trunk/src/bookmarks/kz-bookmark-bar.c 2007-10-04 00:39:20 UTC (rev 3256) @@ -36,6 +36,7 @@ #include "kz-bookmark.h" #include "kz-bookmark-file.h" #include "kz-actions.h" +#include "kz-notebook.h" #include "utils.h" #include "glib-utils.h" @@ -56,15 +57,19 @@ TARGET_GTK_NOTEBOOK_TAB, TARGET_KAZEHAKASE_BOOKMARKS, TARGET_NETSCAPE_URL, - TARGET_TEXT_URI_LIST + TARGET_TEXT_URI_LIST, + TARGET_TEXT_PLAIN, + TARGET_STRING }; static GtkTargetEntry url_drag_types [] = { {"GTK_NOTEBOOK_TAB", GTK_TARGET_SAME_APP, TARGET_GTK_NOTEBOOK_TAB}, - {"_KAZEHAKASE_BOOKMARKS", 0, TARGET_KAZEHAKASE_BOOKMARKS}, + {"_KAZEHAKASE_BOOKMARKS", GTK_TARGET_SAME_APP, TARGET_KAZEHAKASE_BOOKMARKS}, { "_NETSCAPE_URL", 0, TARGET_NETSCAPE_URL}, - { "text/uri-list", 0, TARGET_TEXT_URI_LIST} + { "text/uri-list", 0, TARGET_TEXT_URI_LIST}, + { "text/plain", 0, TARGET_TEXT_PLAIN}, + { "STRING", 0, TARGET_STRING} }; static const guint n_url_drag_types = G_N_ELEMENTS (url_drag_types); @@ -386,6 +391,54 @@ } +static KzBookmark * +create_bookmark_from_selection_data (GtkSelectionData *seldata) +{ + KzBookmark *bookmark; + gchar **strings = NULL; + gchar *utf8_title = NULL; + const gchar *title; + + if (seldata->length < 0) + return NULL; + + strings = g_strsplit((const gchar*)seldata->data, "\n", 2); + if (!strings) + return NULL; + + if (strings[1] != NULL) + { + utf8_title = g_locale_to_utf8(strings[1], + strlen(strings[1]), + NULL, + NULL, + NULL); + } + if (utf8_title && g_utf8_validate(utf8_title, -1, NULL)) + title = utf8_title; + else + title = _("title"); + + /* FIXME! we should also add normal bookmark. */ + /* Create New KzBookmark */ + if (strstr(strings[0], "xml") || + strstr(strings[0], "rss") || + strstr(strings[0], "rdf")) + { + bookmark = KZ_BOOKMARK(kz_bookmark_file_new(strings[0], + title, + NULL)); + } + else + { + bookmark = kz_bookmark_new_with_attrs(title, strings[0], NULL); + } + g_strfreev(strings); + if (utf8_title) + g_free(utf8_title); + return bookmark; +} + static void drag_data_received (GtkWidget *widget, GdkDragContext *context, @@ -395,13 +448,11 @@ guint time) { KzBookmarkBar *bar; - KzBookmark *bookmark, *sibling, *parent; - gchar **strings = NULL; + KzBookmark *bookmark = NULL, *sibling, *parent; GtkWidget *src_widget; - const gchar *title; - gchar *utf8_title = NULL; GList *children; gint index; + gboolean moved = FALSE, success = FALSE; bar = KZ_BOOKMARK_BAR(widget); index = gtk_toolbar_get_drop_index(GTK_TOOLBAR(bar->toolbar), @@ -413,6 +464,19 @@ switch (info) { + case TARGET_GTK_NOTEBOOK_TAB: + { + KzEmbed *kzembed; + const gchar *uri, *title; + src_widget = gtk_drag_get_source_widget(context); + if (!KZ_IS_NOTEBOOK(src_widget)) + break; + kzembed = KZ_EMBED(kz_notebook_get_dragged_page(KZ_NOTEBOOK(src_widget))); + uri = kz_embed_get_location(kzembed); + title = kz_embed_get_title(kzembed); + bookmark = KZ_BOOKMARK(kz_bookmark_new_with_attrs(title, uri, NULL)); + break; + } case TARGET_KAZEHAKASE_BOOKMARKS: src_widget = gtk_drag_get_source_widget(context); @@ -421,61 +485,26 @@ bookmark = KZ_BOOKMARK_ITEM(src_widget)->bookmark; if (bookmark == sibling) + { + bookmark = NULL; break; + } g_object_ref(bookmark); - parent = kz_bookmark_get_parent(bookmark); kz_bookmark_remove(parent, bookmark); - - if (sibling) - { - kz_bookmark_insert_before(bar->folder, - bookmark, - sibling); - } - else - { - kz_bookmark_append(bar->folder, bookmark); - } - kz_bookmark_file_save(KZ_BOOKMARK_FILE(bar->folder)); - gtk_drag_finish(context, TRUE, TRUE, time); + moved = TRUE; break; case TARGET_NETSCAPE_URL: case TARGET_TEXT_URI_LIST: - case TARGET_GTK_NOTEBOOK_TAB: - if (data->length < 0) return; - strings = g_strsplit((const gchar*)data->data, "\n", 2); - if (!strings) return; - if (strings[1] != NULL) - { - utf8_title = g_locale_to_utf8(strings[1], - strlen(strings[1]), - NULL, - NULL, - NULL); - } - if (utf8_title && g_utf8_validate(utf8_title, -1, NULL)) - title = utf8_title; - else - title = _("title"); - - /* FIXME! we should also add normal bookmark. */ - /* Create New KzBookmark */ - if (strstr(strings[0], "xml") || - strstr(strings[0], "rss") || - strstr(strings[0], "rdf")) - { - bookmark = KZ_BOOKMARK(kz_bookmark_file_new(strings[0], - title, - NULL)); - } - else - { - bookmark = kz_bookmark_new_with_attrs(title, - strings[0], - NULL); - } + bookmark = create_bookmark_from_selection_data(data); + break; + default: + break; + } + + if (bookmark) + { if (sibling) { kz_bookmark_insert_before(bar->folder, @@ -486,17 +515,12 @@ { kz_bookmark_append(bar->folder, bookmark); } - g_strfreev(strings); - if (utf8_title) - g_free(utf8_title); g_object_unref(bookmark); kz_bookmark_file_save(KZ_BOOKMARK_FILE(bar->folder)); - gtk_drag_finish(context, TRUE, FALSE, time); - break; - default: - gtk_drag_finish(context, FALSE, FALSE, time); - break; + success = TRUE; } + + gtk_drag_finish(context, success, moved, time); } static void Modified: kazehakase/trunk/src/kz-notebook.c =================================================================== --- kazehakase/trunk/src/kz-notebook.c 2007-10-03 22:24:55 UTC (rev 3255) +++ kazehakase/trunk/src/kz-notebook.c 2007-10-04 00:39:20 UTC (rev 3256) @@ -27,6 +27,8 @@ #include "kz-notebook.h" #include "kz-actions.h" +static const gpointer KZ_NOTEBOOK_GROUP = "KzNotebookGroup"; + enum { PROP_0, PROP_KZ_WINDOW @@ -44,6 +46,24 @@ GtkWidget *dragged_page; }; +enum { + TARGET_GTK_NOTEBOOK_TAB, + TARGET_NETSCAPE_URL, + TARGET_TEXT_URI_LIST, + TARGET_TEXT_PLAIN, + TARGET_STRING +}; + +static GtkTargetEntry url_drag_types [] = +{ + { "GTK_NOTEBOOK_TAB", GTK_TARGET_SAME_APP, TARGET_GTK_NOTEBOOK_TAB}, + { "_NETSCAPE_URL", 0, TARGET_NETSCAPE_URL}, + { "text/uri-list", 0, TARGET_TEXT_URI_LIST}, + { "text/plain", 0, TARGET_TEXT_PLAIN}, + { "STRING", 0, TARGET_STRING} +}; +static guint n_url_drag_types = G_N_ELEMENTS (url_drag_types); + #define KZ_NOTEBOOK_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), KZ_TYPE_NOTEBOOK, KzNotebookPrivate)) static void dispose (GObject *object); @@ -63,11 +83,6 @@ GdkDragContext *context); static void drag_end (GtkWidget *widget, GdkDragContext *context); -static void drag_data_get (GtkWidget *widget, - GdkDragContext *context, - GtkSelectionData *seldata, - guint info, - guint time); static void drag_data_received (GtkWidget *widget, GdkDragContext *context, @@ -106,7 +121,6 @@ widget_class->scroll_event = scroll_event; widget_class->drag_begin = drag_begin; widget_class->drag_end = drag_end; - widget_class->drag_data_get = drag_data_get; widget_class->drag_data_received = drag_data_received; notebook_class->switch_page = switch_page; @@ -136,6 +150,11 @@ g_signal_connect(notebook, "page-reordered", G_CALLBACK(cb_page_reordered), NULL); + + gtk_drag_dest_set(GTK_WIDGET(notebook), + GTK_DEST_DEFAULT_ALL, + url_drag_types,n_url_drag_types, + GDK_ACTION_MOVE | GDK_ACTION_LINK); } @@ -183,6 +202,7 @@ "kz-window", kz, "scrollable", TRUE, "show-tabs", TRUE, + "group", KZ_NOTEBOOK_GROUP, NULL); return GTK_WIDGET(notebook); @@ -270,68 +290,6 @@ } static void -drag_data_get (GtkWidget *widget, - GdkDragContext *context, - GtkSelectionData *seldata, - guint info, - guint time) -{ - KzEmbed *kzembed; - const gchar *uri, *title; - KzNotebookPrivate *priv = KZ_NOTEBOOK_GET_PRIVATE(widget); - - if (!priv->dragged_page) - return; - - g_return_if_fail (KZ_IS_EMBED(priv->dragged_page)); - - kzembed = KZ_EMBED(priv->dragged_page); - uri = kz_embed_get_location(kzembed); - title = kz_embed_get_title(kzembed); - if (!uri || !*uri) return; - - if (seldata->target == gdk_atom_intern_static_string ("GTK_NOTEBOOK_TAB")) - { - gchar *str; - if (title && *title) - { - gchar *title_locale; - gsize bytes_read, bytes_written; - GError *error = NULL; - - title_locale = g_locale_from_utf8(title, -1, - &bytes_read, - &bytes_written, - &error); - if (error) - { - g_warning("kz_tab_label_drag_data_get(): %s", - error->message); - g_error_free(error); - } - if (title_locale && *title_locale) - { - str = g_strconcat(uri, "\n", title_locale, - NULL); - g_free(title_locale); - } - else - { - str = g_strdup (uri); - } - } - else - { - str = g_strdup (uri); - } - gtk_selection_data_set(seldata, seldata->target, - 8, (const guchar*)str, strlen(str)); - g_free(str); - } -} - - -static void drag_data_received (GtkWidget *widget, GdkDragContext *context, gint x, gint y, @@ -339,17 +297,40 @@ guint info, guint time) { - if (seldata->target == gdk_atom_intern_static_string ("GTK_NOTEBOOK_TAB")) + switch (info) { + case TARGET_GTK_NOTEBOOK_TAB: + { GtkWidget *src_notebook; GtkWidget **child; src_notebook = gtk_drag_get_source_widget(context); child = (void*) seldata->data; gtk_container_remove(GTK_CONTAINER(src_notebook), *child); + break; } + case TARGET_NETSCAPE_URL: + case TARGET_TEXT_URI_LIST: + case TARGET_TEXT_PLAIN: + case TARGET_STRING: + { + KzWindow *kz = KZ_NOTEBOOK_GET_PRIVATE(widget)->kz; + gchar **strings; + + if (seldata->length < 0) return; + + strings = g_strsplit((const gchar*)seldata->data, "\n", 2); + kz_window_open_new_tab(kz, strings[0]); + g_strfreev(strings); + break; + } + + default: + break; + } } + static gboolean idle_focus_location_entry(gpointer data) { @@ -816,3 +797,10 @@ else return NULL; } + +GtkWidget * +kz_notebook_get_dragged_page (KzNotebook *notebook) +{ + return KZ_NOTEBOOK_GET_PRIVATE(notebook)->dragged_page; +} + Modified: kazehakase/trunk/src/kz-notebook.h =================================================================== --- kazehakase/trunk/src/kz-notebook.h 2007-10-03 22:24:55 UTC (rev 3255) +++ kazehakase/trunk/src/kz-notebook.h 2007-10-04 00:39:20 UTC (rev 3256) @@ -68,6 +68,7 @@ KzEmbed *embed); KzTabLabel *kz_notebook_get_sibling_tab_label (KzNotebook *notebook, KzTabLabel *label); +GtkWidget *kz_notebook_get_dragged_page (KzNotebook *notebook); G_END_DECLS