[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r20473 - gnunet-gtk/src/fs
From: |
gnunet |
Subject: |
[GNUnet-SVN] r20473 - gnunet-gtk/src/fs |
Date: |
Tue, 13 Mar 2012 11:30:03 +0100 |
Author: grothoff
Date: 2012-03-13 11:30:03 +0100 (Tue, 13 Mar 2012)
New Revision: 20473
Added:
gnunet-gtk/src/fs/gnunet-fs-gtk_open-uri.h
Modified:
gnunet-gtk/src/fs/Makefile.am
gnunet-gtk/src/fs/gnunet-fs-gtk.c
gnunet-gtk/src/fs/gnunet-fs-gtk_common.c
gnunet-gtk/src/fs/gnunet-fs-gtk_common.h
gnunet-gtk/src/fs/gnunet-fs-gtk_event-handler.c
gnunet-gtk/src/fs/gnunet-fs-gtk_open-uri.c
Log:
implementing implicit actions triggered by pasting URIs and keywords
Modified: gnunet-gtk/src/fs/Makefile.am
===================================================================
--- gnunet-gtk/src/fs/Makefile.am 2012-03-13 10:13:51 UTC (rev 20472)
+++ gnunet-gtk/src/fs/Makefile.am 2012-03-13 10:30:03 UTC (rev 20473)
@@ -23,7 +23,7 @@
gnunet-fs-gtk_main-window-search.c \
gnunet-fs-gtk_main-window-view-toggles.c \
gnunet-fs-gtk_open-directory.c \
- gnunet-fs-gtk_open-uri.c \
+ gnunet-fs-gtk_open-uri.c gnunet-fs-gtk_open-uri.h \
gnunet-fs-gtk_unindex.c gnunet-fs-gtk_unindex.h \
gnunet-fs-gtk_publish-dialog.c \
gnunet-fs-gtk_publish-edit-dialog.c gnunet-fs-gtk_publish-edit-dialog.h \
Modified: gnunet-gtk/src/fs/gnunet-fs-gtk.c
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk.c 2012-03-13 10:13:51 UTC (rev 20472)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk.c 2012-03-13 10:30:03 UTC (rev 20473)
@@ -26,8 +26,8 @@
#include "gnunet-fs-gtk.h"
#include "gnunet-fs-gtk_common.h"
#include "gnunet-fs-gtk_event-handler.h"
+#include "gnunet-fs-gtk_open-uri.h"
-
/**
* How many block requests can we have outstanding in parallel at a time by
default?
*/
@@ -110,7 +110,7 @@
*
* @param main_window main window widget
*/
-void
+static void
main_window_save_position (GtkWidget *main_window)
{
GdkWindow *main_window_gdk;
@@ -249,6 +249,65 @@
/**
+ * Text was pasted into the main window. Check if it is a URL
+ * and perform the appropriate action.
+ *
+ * @param cb source clipboard
+ * @param text pasted text
+ * @param data NULL
+ */
+static void
+process_paste (GtkClipboard *cb,
+ const gchar *text,
+ gpointer data)
+{
+ struct GNUNET_FS_Uri *kskuri;
+ char *emsg;
+
+ if (strlen (text) == 0)
+ return;
+ if (GNUNET_OK == GNUNET_FS_GTK_handle_uri_string (text, 1))
+ return;
+ emsg = NULL;
+ kskuri = GNUNET_FS_uri_ksk_create (text, &emsg);
+ if (NULL == kskuri)
+ {
+ GNUNET_free_non_null (emsg);
+ return;
+ }
+ GNUNET_FS_GTK_handle_uri (kskuri, 1);
+ GNUNET_FS_uri_destroy (kskuri);
+}
+
+
+/**
+ * We got an event in the main window. Check for clipboard action.
+ *
+ * @param widget the main window
+ * @param event the event, we only care about button events
+ * @param user_data the 'struct SearchTab' the widget is in
+ * @return FALSE if no menu could be popped up,
+ * TRUE if there is now a pop-up menu
+ */
+gboolean
+GNUNET_FS_GTK_main_window_button_press_event (GtkWidget * widget,
+ GdkEvent * event,
+ gpointer user_data)
+{
+ GdkEventButton *event_button = (GdkEventButton *) event;
+ GtkClipboard *cb;
+
+ if ( (event->type != GDK_BUTTON_PRESS) ||
+ (event_button->button != 2) )
+ return FALSE;
+ cb = gtk_clipboard_get (gdk_atom_intern ("PRIMARY", FALSE));
+ gtk_clipboard_request_text (cb, &process_paste, NULL);
+ return FALSE;
+}
+
+
+
+/**
* Actual main function run right after GNUnet's scheduler
* is initialized. Initializes up GTK and Glade.
*
Modified: gnunet-gtk/src/fs/gnunet-fs-gtk_common.c
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk_common.c 2012-03-13 10:13:51 UTC (rev
20472)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk_common.c 2012-03-13 10:30:03 UTC (rev
20473)
@@ -302,9 +302,11 @@
* the appropriate action.
*
* @param uri the URI
+ * @param anonymity_level anonymity level to use
*/
void
-GNUNET_FS_GTK_handle_uri (const struct GNUNET_FS_Uri *uri)
+GNUNET_FS_GTK_handle_uri (const struct GNUNET_FS_Uri *uri,
+ guint anonymity_level)
{
GtkTreeIter iter;
GtkTreeModel *namespace_treestore;
@@ -321,6 +323,7 @@
struct DownloadEntry *de;
de = GNUNET_malloc (sizeof (struct DownloadEntry));
+ de->anonymity = anonymity_level;
de->uri = GNUNET_FS_uri_dup (uri);
GNUNET_FS_GTK_open_download_as_dialog (de);
return;
@@ -416,6 +419,7 @@
GNUNET_break (0);
}
+
/* Largest rating value among all namespaces. INT_MIN means "undefined" */
static int largest_namespace_rating = INT_MIN;
Modified: gnunet-gtk/src/fs/gnunet-fs-gtk_common.h
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk_common.h 2012-03-13 10:13:51 UTC (rev
20472)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk_common.h 2012-03-13 10:30:03 UTC (rev
20473)
@@ -143,10 +143,13 @@
* the appropriate action.
*
* @param uri the URI
+ * @param anonymity_level anonymity level to use
*/
void
-GNUNET_FS_GTK_handle_uri (const struct GNUNET_FS_Uri *uri);
+GNUNET_FS_GTK_handle_uri (const struct GNUNET_FS_Uri *uri,
+ guint anonymity_level);
+
/**
* Finds largest namespace rating.
* Used to calculate a rating for newly discovered namespaces.
@@ -156,8 +159,9 @@
* that no namespaces are known.
*/
int
-GNUNET_GTK_find_largest_namespace_rating ();
+GNUNET_GTK_find_largest_namespace_rating (void);
+
/**
* Sets largest namespace rating.
* Used to change cached largest namespace rating, when namespace list
Modified: gnunet-gtk/src/fs/gnunet-fs-gtk_event-handler.c
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk_event-handler.c 2012-03-13 10:13:51 UTC
(rev 20472)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk_event-handler.c 2012-03-13 10:30:03 UTC
(rev 20473)
@@ -473,7 +473,7 @@
if (GNUNET_FS_uri_test_ksk (uri) ||
GNUNET_FS_uri_test_sks (uri))
{
- GNUNET_FS_GTK_handle_uri (uri);
+ GNUNET_FS_GTK_handle_uri (uri, 1);
return;
}
/* must be chk/loc URI, start download */
Modified: gnunet-gtk/src/fs/gnunet-fs-gtk_open-uri.c
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk_open-uri.c 2012-03-13 10:13:51 UTC (rev
20472)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk_open-uri.c 2012-03-13 10:30:03 UTC (rev
20473)
@@ -28,11 +28,38 @@
*/
#include "gnunet-fs-gtk_common.h"
#include "gnunet-fs-gtk_download-save-as.h"
+#include "gnunet-fs-gtk_open-uri.h"
#include "gnunet-fs-gtk.h"
#include <gdk/gdkkeysyms.h>
/**
+ * Handle a URI string by running the appropriate action.
+ *
+ * @param uris string we got
+ * @param anonymity_level anonymity level to use
+ * @return GNUNET_OK on success, GNUNET_NO if the URI type is not supported,
GNUNET_SYSERR if we failed to
+ * parse the URI
+ */
+int
+GNUNET_FS_GTK_handle_uri_string (const char *uris,
+ guint anonymity_level)
+{
+ struct GNUNET_FS_Uri *uri;
+ char *perr;
+
+ uri = GNUNET_FS_uri_parse (uris, &perr);
+ if (uri == NULL)
+ {
+ GNUNET_free (perr);
+ return GNUNET_SYSERR;
+ }
+ GNUNET_FS_GTK_handle_uri (uri, anonymity_level);
+ return GNUNET_OK;
+}
+
+
+/**
* User selected "execute" in the open-URI dialog.
*
* @param button the execute button
@@ -48,9 +75,7 @@
GtkTextIter ti_start;
GtkTextIter ti_end;
guint anonymity_level;
- char *perr;
char *uris;
- struct GNUNET_FS_Uri *uri;
dialog =
GTK_WIDGET (gtk_builder_get_object
@@ -62,7 +87,6 @@
gtk_text_buffer_get_iter_at_offset (tb, &ti_end, -1);
uris = gtk_text_buffer_get_text (tb, &ti_start, &ti_end, FALSE);
-
if (!GNUNET_GTK_get_selected_anonymity_level
(builder, "main_window_search_anonymity_combobox", &anonymity_level))
{
@@ -71,42 +95,9 @@
g_object_unref (G_OBJECT (builder));
return;
}
- uri = GNUNET_FS_uri_parse (uris, &perr);
- g_free (uris);
- if (uri == NULL)
- {
- /* Why was "execute" button sensitive!? */
- GNUNET_break (0);
- GNUNET_free (perr);
- gtk_widget_destroy (dialog);
- g_object_unref (G_OBJECT (builder));
- return;
- }
- if (GNUNET_FS_uri_test_sks (uri) || GNUNET_FS_uri_test_ksk (uri))
- {
- GNUNET_break (NULL !=
- GNUNET_FS_search_start (GNUNET_FS_GTK_get_fs_handle (), uri,
- anonymity_level,
- GNUNET_FS_SEARCH_OPTION_NONE, NULL));
- GNUNET_FS_uri_destroy (uri);
- gtk_widget_destroy (dialog);
- g_object_unref (G_OBJECT (builder));
- return;
- }
- if (GNUNET_FS_uri_test_chk (uri) || GNUNET_FS_uri_test_loc (uri))
- {
- struct DownloadEntry *de;
-
- de = GNUNET_malloc (sizeof (struct DownloadEntry));
- de->uri = uri;
- de->anonymity = anonymity_level;
- GNUNET_FS_GTK_open_download_as_dialog (de);
- gtk_widget_destroy (dialog);
- g_object_unref (G_OBJECT (builder));
- return;
- }
- GNUNET_break (0);
- GNUNET_FS_uri_destroy (uri);
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_FS_GTK_handle_uri_string (uris, anonymity_level));
+ g_free (uris);
gtk_widget_destroy (dialog);
g_object_unref (G_OBJECT (builder));
}
Added: gnunet-gtk/src/fs/gnunet-fs-gtk_open-uri.h
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk_open-uri.h (rev 0)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk_open-uri.h 2012-03-13 10:30:03 UTC (rev
20473)
@@ -0,0 +1,41 @@
+/*
+ This file is part of GNUnet
+ (C) 2005, 2006, 2010, 2012 Christian Grothoff (and other contributing
authors)
+
+ GNUnet is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 2, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file src/fs/gnunet-fs-gtk_open-uri.h
+ * @author Christian Grothoff
+ * @brief code for the 'Open URI' dialog.
+ */
+#ifndef GNUNET_FS_GTK_OPEN_URI_H
+#define GNUNET_FS_GTK_OPEN_URI_H
+
+/**
+ * Handle a URI string by running the appropriate action.
+ *
+ * @param uris string we got
+ * @param anonymity_level anonymity level to use
+ * @return GNUNET_OK on success, GNUNET_NO if the URI type is not supported,
GNUNET_SYSERR if we failed to
+ * parse the URI
+ */
+int
+GNUNET_FS_GTK_handle_uri_string (const char *uris,
+ guint anonymity_level);
+
+#endif
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r20473 - gnunet-gtk/src/fs,
gnunet <=