aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-03-13 10:30:03 +0000
committerChristian Grothoff <christian@grothoff.org>2012-03-13 10:30:03 +0000
commitfcc7edc56d78b6df3ed51607604d7621494a2046 (patch)
tree61423dc1c4a29f54112c052a5e9e86680935f190
parentad885ecb7b002eb107ef73011e62db7f856ec150 (diff)
downloadgnunet-gtk-fcc7edc56d78b6df3ed51607604d7621494a2046.tar.gz
gnunet-gtk-fcc7edc56d78b6df3ed51607604d7621494a2046.zip
implementing implicit actions triggered by pasting URIs and keywords
-rw-r--r--src/fs/Makefile.am2
-rw-r--r--src/fs/gnunet-fs-gtk.c63
-rw-r--r--src/fs/gnunet-fs-gtk_common.c6
-rw-r--r--src/fs/gnunet-fs-gtk_common.h8
-rw-r--r--src/fs/gnunet-fs-gtk_event-handler.c2
-rw-r--r--src/fs/gnunet-fs-gtk_open-uri.c69
-rw-r--r--src/fs/gnunet-fs-gtk_open-uri.h41
7 files changed, 145 insertions, 46 deletions
diff --git a/src/fs/Makefile.am b/src/fs/Makefile.am
index a4d590c7..6cd7d69a 100644
--- a/src/fs/Makefile.am
+++ b/src/fs/Makefile.am
@@ -23,7 +23,7 @@ gnunet_fs_gtk_SOURCES = \
23 gnunet-fs-gtk_main-window-search.c \ 23 gnunet-fs-gtk_main-window-search.c \
24 gnunet-fs-gtk_main-window-view-toggles.c \ 24 gnunet-fs-gtk_main-window-view-toggles.c \
25 gnunet-fs-gtk_open-directory.c \ 25 gnunet-fs-gtk_open-directory.c \
26 gnunet-fs-gtk_open-uri.c \ 26 gnunet-fs-gtk_open-uri.c gnunet-fs-gtk_open-uri.h \
27 gnunet-fs-gtk_unindex.c gnunet-fs-gtk_unindex.h \ 27 gnunet-fs-gtk_unindex.c gnunet-fs-gtk_unindex.h \
28 gnunet-fs-gtk_publish-dialog.c \ 28 gnunet-fs-gtk_publish-dialog.c \
29 gnunet-fs-gtk_publish-edit-dialog.c gnunet-fs-gtk_publish-edit-dialog.h \ 29 gnunet-fs-gtk_publish-edit-dialog.c gnunet-fs-gtk_publish-edit-dialog.h \
diff --git a/src/fs/gnunet-fs-gtk.c b/src/fs/gnunet-fs-gtk.c
index b44b970c..b34f0f03 100644
--- a/src/fs/gnunet-fs-gtk.c
+++ b/src/fs/gnunet-fs-gtk.c
@@ -26,7 +26,7 @@
26#include "gnunet-fs-gtk.h" 26#include "gnunet-fs-gtk.h"
27#include "gnunet-fs-gtk_common.h" 27#include "gnunet-fs-gtk_common.h"
28#include "gnunet-fs-gtk_event-handler.h" 28#include "gnunet-fs-gtk_event-handler.h"
29 29#include "gnunet-fs-gtk_open-uri.h"
30 30
31/** 31/**
32 * How many block requests can we have outstanding in parallel at a time by default? 32 * How many block requests can we have outstanding in parallel at a time by default?
@@ -110,7 +110,7 @@ GNUNET_FS_GTK_get_anonymity_level_list_store ()
110 * 110 *
111 * @param main_window main window widget 111 * @param main_window main window widget
112 */ 112 */
113void 113static void
114main_window_save_position (GtkWidget *main_window) 114main_window_save_position (GtkWidget *main_window)
115{ 115{
116 GdkWindow *main_window_gdk; 116 GdkWindow *main_window_gdk;
@@ -249,6 +249,65 @@ GNUNET_FS_GTK_delete_event_cb (GtkWidget *object,
249 249
250 250
251/** 251/**
252 * Text was pasted into the main window. Check if it is a URL
253 * and perform the appropriate action.
254 *
255 * @param cb source clipboard
256 * @param text pasted text
257 * @param data NULL
258 */
259static void
260process_paste (GtkClipboard *cb,
261 const gchar *text,
262 gpointer data)
263{
264 struct GNUNET_FS_Uri *kskuri;
265 char *emsg;
266
267 if (strlen (text) == 0)
268 return;
269 if (GNUNET_OK == GNUNET_FS_GTK_handle_uri_string (text, 1))
270 return;
271 emsg = NULL;
272 kskuri = GNUNET_FS_uri_ksk_create (text, &emsg);
273 if (NULL == kskuri)
274 {
275 GNUNET_free_non_null (emsg);
276 return;
277 }
278 GNUNET_FS_GTK_handle_uri (kskuri, 1);
279 GNUNET_FS_uri_destroy (kskuri);
280}
281
282
283/**
284 * We got an event in the main window. Check for clipboard action.
285 *
286 * @param widget the main window
287 * @param event the event, we only care about button events
288 * @param user_data the 'struct SearchTab' the widget is in
289 * @return FALSE if no menu could be popped up,
290 * TRUE if there is now a pop-up menu
291 */
292gboolean
293GNUNET_FS_GTK_main_window_button_press_event (GtkWidget * widget,
294 GdkEvent * event,
295 gpointer user_data)
296{
297 GdkEventButton *event_button = (GdkEventButton *) event;
298 GtkClipboard *cb;
299
300 if ( (event->type != GDK_BUTTON_PRESS) ||
301 (event_button->button != 2) )
302 return FALSE;
303 cb = gtk_clipboard_get (gdk_atom_intern ("PRIMARY", FALSE));
304 gtk_clipboard_request_text (cb, &process_paste, NULL);
305 return FALSE;
306}
307
308
309
310/**
252 * Actual main function run right after GNUnet's scheduler 311 * Actual main function run right after GNUnet's scheduler
253 * is initialized. Initializes up GTK and Glade. 312 * is initialized. Initializes up GTK and Glade.
254 * 313 *
diff --git a/src/fs/gnunet-fs-gtk_common.c b/src/fs/gnunet-fs-gtk_common.c
index 82d93e8f..27905f25 100644
--- a/src/fs/gnunet-fs-gtk_common.c
+++ b/src/fs/gnunet-fs-gtk_common.c
@@ -302,9 +302,11 @@ GNUNET_FS_GTK_get_description_from_metadata (
302 * the appropriate action. 302 * the appropriate action.
303 * 303 *
304 * @param uri the URI 304 * @param uri the URI
305 * @param anonymity_level anonymity level to use
305 */ 306 */
306void 307void
307GNUNET_FS_GTK_handle_uri (const struct GNUNET_FS_Uri *uri) 308GNUNET_FS_GTK_handle_uri (const struct GNUNET_FS_Uri *uri,
309 guint anonymity_level)
308{ 310{
309 GtkTreeIter iter; 311 GtkTreeIter iter;
310 GtkTreeModel *namespace_treestore; 312 GtkTreeModel *namespace_treestore;
@@ -321,6 +323,7 @@ GNUNET_FS_GTK_handle_uri (const struct GNUNET_FS_Uri *uri)
321 struct DownloadEntry *de; 323 struct DownloadEntry *de;
322 324
323 de = GNUNET_malloc (sizeof (struct DownloadEntry)); 325 de = GNUNET_malloc (sizeof (struct DownloadEntry));
326 de->anonymity = anonymity_level;
324 de->uri = GNUNET_FS_uri_dup (uri); 327 de->uri = GNUNET_FS_uri_dup (uri);
325 GNUNET_FS_GTK_open_download_as_dialog (de); 328 GNUNET_FS_GTK_open_download_as_dialog (de);
326 return; 329 return;
@@ -416,6 +419,7 @@ GNUNET_FS_GTK_handle_uri (const struct GNUNET_FS_Uri *uri)
416 GNUNET_break (0); 419 GNUNET_break (0);
417} 420}
418 421
422
419/* Largest rating value among all namespaces. INT_MIN means "undefined" */ 423/* Largest rating value among all namespaces. INT_MIN means "undefined" */
420static int largest_namespace_rating = INT_MIN; 424static int largest_namespace_rating = INT_MIN;
421 425
diff --git a/src/fs/gnunet-fs-gtk_common.h b/src/fs/gnunet-fs-gtk_common.h
index 30766956..1bf4c258 100644
--- a/src/fs/gnunet-fs-gtk_common.h
+++ b/src/fs/gnunet-fs-gtk_common.h
@@ -143,9 +143,12 @@ GNUNET_FS_GTK_get_description_from_metadata (
143 * the appropriate action. 143 * the appropriate action.
144 * 144 *
145 * @param uri the URI 145 * @param uri the URI
146 * @param anonymity_level anonymity level to use
146 */ 147 */
147void 148void
148GNUNET_FS_GTK_handle_uri (const struct GNUNET_FS_Uri *uri); 149GNUNET_FS_GTK_handle_uri (const struct GNUNET_FS_Uri *uri,
150 guint anonymity_level);
151
149 152
150/** 153/**
151 * Finds largest namespace rating. 154 * Finds largest namespace rating.
@@ -156,7 +159,8 @@ GNUNET_FS_GTK_handle_uri (const struct GNUNET_FS_Uri *uri);
156 * that no namespaces are known. 159 * that no namespaces are known.
157 */ 160 */
158int 161int
159GNUNET_GTK_find_largest_namespace_rating (); 162GNUNET_GTK_find_largest_namespace_rating (void);
163
160 164
161/** 165/**
162 * Sets largest namespace rating. 166 * Sets largest namespace rating.
diff --git a/src/fs/gnunet-fs-gtk_event-handler.c b/src/fs/gnunet-fs-gtk_event-handler.c
index 3643d379..4c588547 100644
--- a/src/fs/gnunet-fs-gtk_event-handler.c
+++ b/src/fs/gnunet-fs-gtk_event-handler.c
@@ -473,7 +473,7 @@ GNUNET_FS_GTK_search_treeview_row_activated (GtkTreeView * tree_view,
473 if (GNUNET_FS_uri_test_ksk (uri) || 473 if (GNUNET_FS_uri_test_ksk (uri) ||
474 GNUNET_FS_uri_test_sks (uri)) 474 GNUNET_FS_uri_test_sks (uri))
475 { 475 {
476 GNUNET_FS_GTK_handle_uri (uri); 476 GNUNET_FS_GTK_handle_uri (uri, 1);
477 return; 477 return;
478 } 478 }
479 /* must be chk/loc URI, start download */ 479 /* must be chk/loc URI, start download */
diff --git a/src/fs/gnunet-fs-gtk_open-uri.c b/src/fs/gnunet-fs-gtk_open-uri.c
index 7c0900fc..93a164cc 100644
--- a/src/fs/gnunet-fs-gtk_open-uri.c
+++ b/src/fs/gnunet-fs-gtk_open-uri.c
@@ -28,11 +28,38 @@
28 */ 28 */
29#include "gnunet-fs-gtk_common.h" 29#include "gnunet-fs-gtk_common.h"
30#include "gnunet-fs-gtk_download-save-as.h" 30#include "gnunet-fs-gtk_download-save-as.h"
31#include "gnunet-fs-gtk_open-uri.h"
31#include "gnunet-fs-gtk.h" 32#include "gnunet-fs-gtk.h"
32#include <gdk/gdkkeysyms.h> 33#include <gdk/gdkkeysyms.h>
33 34
34 35
35/** 36/**
37 * Handle a URI string by running the appropriate action.
38 *
39 * @param uris string we got
40 * @param anonymity_level anonymity level to use
41 * @return GNUNET_OK on success, GNUNET_NO if the URI type is not supported, GNUNET_SYSERR if we failed to
42 * parse the URI
43 */
44int
45GNUNET_FS_GTK_handle_uri_string (const char *uris,
46 guint anonymity_level)
47{
48 struct GNUNET_FS_Uri *uri;
49 char *perr;
50
51 uri = GNUNET_FS_uri_parse (uris, &perr);
52 if (uri == NULL)
53 {
54 GNUNET_free (perr);
55 return GNUNET_SYSERR;
56 }
57 GNUNET_FS_GTK_handle_uri (uri, anonymity_level);
58 return GNUNET_OK;
59}
60
61
62/**
36 * User selected "execute" in the open-URI dialog. 63 * User selected "execute" in the open-URI dialog.
37 * 64 *
38 * @param button the execute button 65 * @param button the execute button
@@ -48,9 +75,7 @@ GNUNET_GTK_open_url_dialog_execute_button_clicked_cb (GtkButton * button,
48 GtkTextIter ti_start; 75 GtkTextIter ti_start;
49 GtkTextIter ti_end; 76 GtkTextIter ti_end;
50 guint anonymity_level; 77 guint anonymity_level;
51 char *perr;
52 char *uris; 78 char *uris;
53 struct GNUNET_FS_Uri *uri;
54 79
55 dialog = 80 dialog =
56 GTK_WIDGET (gtk_builder_get_object 81 GTK_WIDGET (gtk_builder_get_object
@@ -62,7 +87,6 @@ GNUNET_GTK_open_url_dialog_execute_button_clicked_cb (GtkButton * button,
62 gtk_text_buffer_get_iter_at_offset (tb, &ti_end, -1); 87 gtk_text_buffer_get_iter_at_offset (tb, &ti_end, -1);
63 88
64 uris = gtk_text_buffer_get_text (tb, &ti_start, &ti_end, FALSE); 89 uris = gtk_text_buffer_get_text (tb, &ti_start, &ti_end, FALSE);
65
66 if (!GNUNET_GTK_get_selected_anonymity_level 90 if (!GNUNET_GTK_get_selected_anonymity_level
67 (builder, "main_window_search_anonymity_combobox", &anonymity_level)) 91 (builder, "main_window_search_anonymity_combobox", &anonymity_level))
68 { 92 {
@@ -71,42 +95,9 @@ GNUNET_GTK_open_url_dialog_execute_button_clicked_cb (GtkButton * button,
71 g_object_unref (G_OBJECT (builder)); 95 g_object_unref (G_OBJECT (builder));
72 return; 96 return;
73 } 97 }
74 uri = GNUNET_FS_uri_parse (uris, &perr); 98 GNUNET_break (GNUNET_OK ==
75 g_free (uris); 99 GNUNET_FS_GTK_handle_uri_string (uris, anonymity_level));
76 if (uri == NULL) 100 g_free (uris);
77 {
78 /* Why was "execute" button sensitive!? */
79 GNUNET_break (0);
80 GNUNET_free (perr);
81 gtk_widget_destroy (dialog);
82 g_object_unref (G_OBJECT (builder));
83 return;
84 }
85 if (GNUNET_FS_uri_test_sks (uri) || GNUNET_FS_uri_test_ksk (uri))
86 {
87 GNUNET_break (NULL !=
88 GNUNET_FS_search_start (GNUNET_FS_GTK_get_fs_handle (), uri,
89 anonymity_level,
90 GNUNET_FS_SEARCH_OPTION_NONE, NULL));
91 GNUNET_FS_uri_destroy (uri);
92 gtk_widget_destroy (dialog);
93 g_object_unref (G_OBJECT (builder));
94 return;
95 }
96 if (GNUNET_FS_uri_test_chk (uri) || GNUNET_FS_uri_test_loc (uri))
97 {
98 struct DownloadEntry *de;
99
100 de = GNUNET_malloc (sizeof (struct DownloadEntry));
101 de->uri = uri;
102 de->anonymity = anonymity_level;
103 GNUNET_FS_GTK_open_download_as_dialog (de);
104 gtk_widget_destroy (dialog);
105 g_object_unref (G_OBJECT (builder));
106 return;
107 }
108 GNUNET_break (0);
109 GNUNET_FS_uri_destroy (uri);
110 gtk_widget_destroy (dialog); 101 gtk_widget_destroy (dialog);
111 g_object_unref (G_OBJECT (builder)); 102 g_object_unref (G_OBJECT (builder));
112} 103}
diff --git a/src/fs/gnunet-fs-gtk_open-uri.h b/src/fs/gnunet-fs-gtk_open-uri.h
new file mode 100644
index 00000000..d7181b4e
--- /dev/null
+++ b/src/fs/gnunet-fs-gtk_open-uri.h
@@ -0,0 +1,41 @@
1/*
2 This file is part of GNUnet
3 (C) 2005, 2006, 2010, 2012 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @file src/fs/gnunet-fs-gtk_open-uri.h
23 * @author Christian Grothoff
24 * @brief code for the 'Open URI' dialog.
25 */
26#ifndef GNUNET_FS_GTK_OPEN_URI_H
27#define GNUNET_FS_GTK_OPEN_URI_H
28
29/**
30 * Handle a URI string by running the appropriate action.
31 *
32 * @param uris string we got
33 * @param anonymity_level anonymity level to use
34 * @return GNUNET_OK on success, GNUNET_NO if the URI type is not supported, GNUNET_SYSERR if we failed to
35 * parse the URI
36 */
37int
38GNUNET_FS_GTK_handle_uri_string (const char *uris,
39 guint anonymity_level);
40
41#endif