aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-02-01 17:29:05 +0000
committerChristian Grothoff <christian@grothoff.org>2012-02-01 17:29:05 +0000
commit1e14dc4228cbfdb63e7df3905031cd0c318372f6 (patch)
tree4dfe23ad942239ae2f1ad4d454d153b4d4bde94d
parent6d84b835ac980f4afa7937578f27eab3b63a41f7 (diff)
downloadgnunet-gtk-1e14dc4228cbfdb63e7df3905031cd0c318372f6.tar.gz
gnunet-gtk-1e14dc4228cbfdb63e7df3905031cd0c318372f6.zip
-moving code around
-rw-r--r--src/fs/Makefile.am3
-rw-r--r--src/fs/gnunet-fs-gtk-main_window_namespace.c25
-rw-r--r--src/fs/gnunet-fs-gtk-main_window_search.c137
3 files changed, 139 insertions, 26 deletions
diff --git a/src/fs/Makefile.am b/src/fs/Makefile.am
index 3db3ffed..6b699c2b 100644
--- a/src/fs/Makefile.am
+++ b/src/fs/Makefile.am
@@ -18,12 +18,13 @@ gnunet_fs_gtk_SOURCES = \
18 gnunet-fs-gtk-anonymity_spin_buttons.c gnunet-fs-gtk-anonymity_spin_buttons.h \ 18 gnunet-fs-gtk-anonymity_spin_buttons.c gnunet-fs-gtk-anonymity_spin_buttons.h \
19 gnunet-fs-gtk-main_window_meta_data_context_menu.c \ 19 gnunet-fs-gtk-main_window_meta_data_context_menu.c \
20 gnunet-fs-gtk.c gnunet-fs-gtk.h \ 20 gnunet-fs-gtk.c gnunet-fs-gtk.h \
21 gnunet-fs-gtk-main_window_adv_pseudonym.c \
21 gnunet-fs-gtk-main_window_create_pseudonym.c \ 22 gnunet-fs-gtk-main_window_create_pseudonym.c \
22 gnunet-fs-gtk-main_window_file_download.c \ 23 gnunet-fs-gtk-main_window_file_download.c \
23 gnunet-fs-gtk-main_window_file_publish.c \ 24 gnunet-fs-gtk-main_window_file_publish.c \
24 gnunet-fs-gtk-main_window_namespace.c \ 25 gnunet-fs-gtk-main_window_namespace.c \
26 gnunet-fs-gtk-main_window_search.c \
25 gnunet-fs-gtk-main_window_open_directory.c \ 27 gnunet-fs-gtk-main_window_open_directory.c \
26 gnunet-fs-gtk-main_window_adv_pseudonym.c \
27 gnunet-fs-gtk-main_window_view_toggles.c 28 gnunet-fs-gtk-main_window_view_toggles.c
28gnunet_fs_gtk_LDADD = \ 29gnunet_fs_gtk_LDADD = \
29 $(top_builddir)/src/lib/libgnunetgtk.la \ 30 $(top_builddir)/src/lib/libgnunetgtk.la \
diff --git a/src/fs/gnunet-fs-gtk-main_window_namespace.c b/src/fs/gnunet-fs-gtk-main_window_namespace.c
index b2ca9b42..3af3845d 100644
--- a/src/fs/gnunet-fs-gtk-main_window_namespace.c
+++ b/src/fs/gnunet-fs-gtk-main_window_namespace.c
@@ -134,31 +134,6 @@ namespace_selector_window_leave_notify_event_cb (GtkWidget * widget,
134} 134}
135 135
136 136
137static gboolean
138GNUNET_GTK_get_tree_string (GtkTreeView * treeview, GtkTreePath * treepath,
139 guint column, gchar ** value)
140{
141 gboolean ok;
142 GtkTreeModel *model;
143
144 model = gtk_tree_view_get_model (treeview);
145 if (!model)
146 return FALSE;
147
148 GtkTreeIter iter;
149
150 ok = gtk_tree_model_get_iter (model, &iter, treepath);
151 if (!ok)
152 return FALSE;
153
154 *value = NULL;
155 gtk_tree_model_get (model, &iter, column, value, -1);
156 if (*value == NULL)
157 return FALSE;
158 return TRUE;
159}
160
161
162 137
163gboolean 138gboolean
164get_selected_namespace_treepath_iter_model_widget (GtkBuilder * builder, 139get_selected_namespace_treepath_iter_model_widget (GtkBuilder * builder,
diff --git a/src/fs/gnunet-fs-gtk-main_window_search.c b/src/fs/gnunet-fs-gtk-main_window_search.c
new file mode 100644
index 00000000..870b5f18
--- /dev/null
+++ b/src/fs/gnunet-fs-gtk-main_window_search.c
@@ -0,0 +1,137 @@
1/*
2 This file is part of GNUnet
3 (C) 2011, 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-main_window_search.c
23 * @author Christian Grothoff
24 * @brief event handlers for the search function in the main window
25 */
26#include "gnunet-fs-gtk-common.h"
27#include <gdk/gdk.h>
28
29
30
31void
32main_window_search_button_clicked_cb (GtkButton * button, gpointer user_data)
33{
34 GtkBuilder *builder;
35 GtkTreePath *namespace_treepath = NULL;
36 GtkTreeModel *namespace_model = NULL;
37 GtkComboBox *mime_combo;
38 GtkTreeModel *mime_model;
39 GtkEntry *query_entry;
40 guint anonymity_level;
41 GtkTreeRowReference *ref = NULL;
42 GtkTreeIter iter;
43 GtkToggleButton *toggle_button;
44 const char *entry_keywords;
45 gchar *keywords;
46 gchar *mime_keyword;
47
48 GNUNET_HashCode *nsid = NULL;
49 struct GNUNET_FS_Uri *uri;
50 char *emsg;
51
52 builder = GTK_BUILDER (user_data);
53
54 toggle_button =
55 GTK_TOGGLE_BUTTON (gtk_builder_get_object
56 (builder,
57 "main_window_search_namespace_dropdown_button"));
58
59 if (!GNUNET_GTK_get_selected_anonymity_level
60 (builder, "main_window_search_anonymity_combobox", &anonymity_level))
61 return;
62
63 mime_combo =
64 GTK_COMBO_BOX (GNUNET_FS_GTK_get_main_window_object
65 ("main_window_search_mime_combobox"));
66 mime_model = gtk_combo_box_get_model (mime_combo);
67 mime_keyword = NULL;
68 if (mime_model && gtk_combo_box_get_active_iter (mime_combo, &iter))
69 gtk_tree_model_get (mime_model, &iter, 0, &mime_keyword, -1);
70 if (strcmp (mime_keyword, " ") == 0)
71 {
72 g_free (mime_keyword);
73 mime_keyword = NULL;
74 }
75
76 ref = g_object_get_data (G_OBJECT (toggle_button), "selected-row-reference");
77 if (ref)
78 {
79 namespace_model = gtk_tree_row_reference_get_model (ref);
80 namespace_treepath = gtk_tree_row_reference_get_path (ref);
81 if ((NULL != namespace_treepath) &&
82 (TRUE ==
83 gtk_tree_model_get_iter (namespace_model, &iter, namespace_treepath)))
84 gtk_tree_model_get (namespace_model, &iter, 1, &nsid, -1);
85 }
86 query_entry =
87 GTK_ENTRY (gtk_builder_get_object (builder, "main_window_search_entry"));
88 entry_keywords = gtk_entry_get_text (query_entry);
89 keywords =
90 g_strdup_printf ("%s %s%s", entry_keywords, mime_keyword ? "+" : "",
91 mime_keyword ? mime_keyword : "");
92 g_free (mime_keyword);
93 if (nsid != NULL)
94 {
95 uri = GNUNET_FS_uri_sks_create_from_nsid (nsid, keywords);
96 GNUNET_assert (uri != NULL);
97 }
98 else
99 {
100 emsg = NULL;
101 uri = GNUNET_FS_uri_ksk_create (keywords, &emsg);
102 if (uri == NULL)
103 {
104 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Invalid keyword string `%s': %s"),
105 keywords, emsg);
106 GNUNET_free_non_null (emsg);
107 return;
108 }
109 }
110 GNUNET_FS_search_start (GNUNET_FS_GTK_get_fs_handle (), uri, anonymity_level,
111 GNUNET_FS_SEARCH_OPTION_NONE, NULL);
112
113 g_free (keywords);
114 GNUNET_FS_uri_destroy (uri);
115}
116
117
118gboolean
119main_window_search_entry_key_press_event_cb (GtkWidget * widget,
120 GdkEventKey * event,
121 gpointer user_data)
122{
123 GtkBuilder *builder;
124
125 builder = GTK_BUILDER (user_data);
126
127 if (event->keyval == GDK_KEY_Return)
128 {
129 GtkWidget *find = GTK_WIDGET (gtk_builder_get_object (builder,
130 "main_window_search_button"));
131
132 main_window_search_button_clicked_cb (GTK_BUTTON (find), user_data);
133 return TRUE;
134 }
135 return FALSE;
136}
137