[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r19641 - gnunet-gtk/src/fs
From: |
gnunet |
Subject: |
[GNUnet-SVN] r19641 - gnunet-gtk/src/fs |
Date: |
Thu, 2 Feb 2012 17:59:57 +0100 |
Author: grothoff
Date: 2012-02-02 17:59:57 +0100 (Thu, 02 Feb 2012)
New Revision: 19641
Added:
gnunet-gtk/src/fs/gnunet-fs-gtk_main-window-search.c
Removed:
gnunet-gtk/src/fs/gnunet-fs-gtk-main_window_search.c
Modified:
gnunet-gtk/src/fs/Makefile.am
Log:
-renaming and cleaning up search code
Modified: gnunet-gtk/src/fs/Makefile.am
===================================================================
--- gnunet-gtk/src/fs/Makefile.am 2012-02-02 16:45:51 UTC (rev 19640)
+++ gnunet-gtk/src/fs/Makefile.am 2012-02-02 16:59:57 UTC (rev 19641)
@@ -16,6 +16,7 @@
gnunet-fs-gtk_common.c gnunet-fs-gtk_common.h \
gnunet-fs-gtk_download-save-as.c gnunet-fs-gtk_download-save-as.h \
gnunet-fs-gtk_event-handler.c gnunet-fs-gtk_event-handler.h \
+ gnunet-fs-gtk_main-window-search.c \
gnunet-fs-gtk_main-window-view-toggles.c \
gnunet-fs-gtk_publish-dialog.c \
gnunet-fs-gtk_publish-edit-dialog.c gnunet-fs-gtk_publish-edit-dialog.h \
@@ -24,7 +25,6 @@
gnunet-fs-gtk-main_window_create_pseudonym.c \
gnunet-fs-gtk-main_window_file_download.c \
gnunet-fs-gtk-main_window_namespace.c \
- gnunet-fs-gtk-main_window_search.c \
gnunet-fs-gtk-main_window_open_directory.c
gnunet_fs_gtk_LDADD = \
$(top_builddir)/src/lib/libgnunetgtk.la \
Deleted: gnunet-gtk/src/fs/gnunet-fs-gtk-main_window_search.c
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk-main_window_search.c 2012-02-02
16:45:51 UTC (rev 19640)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk-main_window_search.c 2012-02-02
16:59:57 UTC (rev 19641)
@@ -1,137 +0,0 @@
-/*
- This file is part of GNUnet
- (C) 2011, 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-main_window_search.c
- * @author Christian Grothoff
- * @brief event handlers for the search function in the main window
- */
-#include "gnunet-fs-gtk_common.h"
-#include "gnunet-fs-gtk.h"
-#include "gnunet-fs-gtk_anonymity-widgets.h"
-
-
-void
-main_window_search_button_clicked_cb (GtkButton * button, gpointer user_data)
-{
- GtkBuilder *builder;
- GtkTreePath *namespace_treepath = NULL;
- GtkTreeModel *namespace_model = NULL;
- GtkComboBox *mime_combo;
- GtkTreeModel *mime_model;
- GtkEntry *query_entry;
- guint anonymity_level;
- GtkTreeRowReference *ref = NULL;
- GtkTreeIter iter;
- GtkToggleButton *toggle_button;
- const char *entry_keywords;
- gchar *keywords;
- gchar *mime_keyword;
-
- GNUNET_HashCode *nsid = NULL;
- struct GNUNET_FS_Uri *uri;
- char *emsg;
-
- builder = GTK_BUILDER (user_data);
-
- toggle_button =
- GTK_TOGGLE_BUTTON (gtk_builder_get_object
- (builder,
- "main_window_search_namespace_dropdown_button"));
-
- if (!GNUNET_GTK_get_selected_anonymity_level
- (builder, "main_window_search_anonymity_combobox", &anonymity_level))
- return;
-
- mime_combo =
- GTK_COMBO_BOX (GNUNET_FS_GTK_get_main_window_object
- ("main_window_search_mime_combobox"));
- mime_model = gtk_combo_box_get_model (mime_combo);
- mime_keyword = NULL;
- if (mime_model && gtk_combo_box_get_active_iter (mime_combo, &iter))
- gtk_tree_model_get (mime_model, &iter, 0, &mime_keyword, -1);
- if (strcmp (mime_keyword, " ") == 0)
- {
- g_free (mime_keyword);
- mime_keyword = NULL;
- }
-
- ref = g_object_get_data (G_OBJECT (toggle_button), "selected-row-reference");
- if (ref)
- {
- namespace_model = gtk_tree_row_reference_get_model (ref);
- namespace_treepath = gtk_tree_row_reference_get_path (ref);
- if ((NULL != namespace_treepath) &&
- (TRUE ==
- gtk_tree_model_get_iter (namespace_model, &iter, namespace_treepath)))
- gtk_tree_model_get (namespace_model, &iter, 1, &nsid, -1);
- }
- query_entry =
- GTK_ENTRY (gtk_builder_get_object (builder, "main_window_search_entry"));
- entry_keywords = gtk_entry_get_text (query_entry);
- keywords =
- g_strdup_printf ("%s %s%s", entry_keywords, mime_keyword ? "+" : "",
- mime_keyword ? mime_keyword : "");
- g_free (mime_keyword);
- if (nsid != NULL)
- {
- uri = GNUNET_FS_uri_sks_create_from_nsid (nsid, keywords);
- GNUNET_assert (uri != NULL);
- }
- else
- {
- emsg = NULL;
- uri = GNUNET_FS_uri_ksk_create (keywords, &emsg);
- if (uri == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Invalid keyword string `%s':
%s"),
- keywords, emsg);
- GNUNET_free_non_null (emsg);
- return;
- }
- }
- GNUNET_FS_search_start (GNUNET_FS_GTK_get_fs_handle (), uri, anonymity_level,
- GNUNET_FS_SEARCH_OPTION_NONE, NULL);
-
- g_free (keywords);
- GNUNET_FS_uri_destroy (uri);
-}
-
-
-gboolean
-main_window_search_entry_key_press_event_cb (GtkWidget * widget,
- GdkEventKey * event,
- gpointer user_data)
-{
- GtkBuilder *builder;
-
- builder = GTK_BUILDER (user_data);
-
- if (event->keyval == GDK_KEY_Return)
- {
- GtkWidget *find = GTK_WIDGET (gtk_builder_get_object (builder,
-
"main_window_search_button"));
-
- main_window_search_button_clicked_cb (GTK_BUTTON (find), user_data);
- return TRUE;
- }
- return FALSE;
-}
-
Copied: gnunet-gtk/src/fs/gnunet-fs-gtk_main-window-search.c (from rev 19630,
gnunet-gtk/src/fs/gnunet-fs-gtk-main_window_search.c)
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk_main-window-search.c
(rev 0)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk_main-window-search.c 2012-02-02
16:59:57 UTC (rev 19641)
@@ -0,0 +1,189 @@
+/*
+ This file is part of GNUnet
+ (C) 2011, 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_main-window-search.c
+ * @author Christian Grothoff
+ * @brief event handlers for the search function in the main window
+ */
+#include "gnunet-fs-gtk_common.h"
+#include "gnunet-fs-gtk.h"
+#include "gnunet-fs-gtk_anonymity-widgets.h"
+
+
+/**
+ * Start a search.
+ *
+ * @param builder the main dialog builder
+ */
+static void
+start_search (GtkBuilder *builder)
+{
+ guint anonymity_level;
+ gchar *keywords;
+ gchar *mime_keyword;
+ GNUNET_HashCode *nsid;
+ struct GNUNET_FS_Uri *uri;
+
+ /* get anonymity level */
+ if (!GNUNET_GTK_get_selected_anonymity_level
+ (builder, "main_window_search_anonymity_combobox", &anonymity_level))
+ {
+ GNUNET_break (0);
+ return;
+ }
+
+ /* get selected mime type */
+ {
+ GtkComboBox *mime_combo;
+ GtkTreeModel *mime_model;
+ GtkTreeIter iter;
+
+ mime_combo = GTK_COMBO_BOX (GNUNET_FS_GTK_get_main_window_object
+ ("main_window_search_mime_combobox"));
+ mime_model = gtk_combo_box_get_model (mime_combo);
+ mime_keyword = NULL;
+ if ( (NULL != mime_model) &&
+ gtk_combo_box_get_active_iter (mime_combo, &iter))
+ gtk_tree_model_get (mime_model, &iter, 0, &mime_keyword, -1);
+ if (0 == strcmp (mime_keyword, " "))
+ {
+ g_free (mime_keyword);
+ mime_keyword = NULL;
+ }
+ }
+
+ /* get selected namespace */
+ {
+ GtkTreeRowReference *ref;
+ GtkToggleButton *toggle_button;
+ GtkTreeIter iter;
+
+ nsid = NULL;
+ toggle_button =
+ GTK_TOGGLE_BUTTON (gtk_builder_get_object
+ (builder,
+ "main_window_search_namespace_dropdown_button"));
+ ref = g_object_get_data (G_OBJECT (toggle_button),
"selected-row-reference");
+ if (NULL != ref)
+ {
+ GtkTreePath *namespace_treepath;
+ GtkTreeModel *namespace_model;
+
+ namespace_model = gtk_tree_row_reference_get_model (ref);
+ namespace_treepath = gtk_tree_row_reference_get_path (ref);
+ if ( (NULL != namespace_treepath) &&
+ (gtk_tree_model_get_iter (namespace_model, &iter,
namespace_treepath)))
+ gtk_tree_model_get (namespace_model, &iter, 1, &nsid, -1);
+ }
+ }
+
+ /* get keywords and compose keyword string */
+ {
+ GtkEntry *query_entry;
+ const char *entry_keywords;
+
+ query_entry = GTK_ENTRY (gtk_builder_get_object (builder,
+
"main_window_search_entry"));
+ entry_keywords = gtk_entry_get_text (query_entry);
+ if (NULL != mime_keyword)
+ {
+ keywords = g_strdup_printf ("%s +%s",
+ entry_keywords,
+ mime_keyword);
+ g_free (mime_keyword);
+ }
+ else
+ {
+ keywords = g_strdup (entry_keywords);
+ }
+ }
+
+ /* build KSK/SKS URI */
+ if (NULL != nsid)
+ {
+ uri = GNUNET_FS_uri_sks_create_from_nsid (nsid, keywords);
+ GNUNET_assert (uri != NULL);
+ }
+ else
+ {
+ char *emsg = NULL;
+
+ uri = GNUNET_FS_uri_ksk_create (keywords, &emsg);
+ if (NULL == uri)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Invalid keyword string `%s':
%s"),
+ keywords, emsg);
+ g_free (keywords);
+ GNUNET_free_non_null (emsg);
+ return;
+ }
+ }
+ g_free (keywords);
+
+ /* start search */
+ GNUNET_FS_search_start (GNUNET_FS_GTK_get_fs_handle (),
+ uri, anonymity_level,
+ GNUNET_FS_SEARCH_OPTION_NONE, NULL);
+ GNUNET_FS_uri_destroy (uri);
+}
+
+
+/**
+ * User clicked on the 'search' button in the main window.
+ *
+ * @param button the search button
+ * @param user_data the main dialog builder
+ */
+void
+main_window_search_button_clicked_cb (GtkButton * button,
+ gpointer user_data)
+{
+ GtkBuilder *builder = GTK_BUILDER (user_data);
+
+ start_search (builder);
+}
+
+
+/**
+ * User pushed a key (possibly ENTER) in the search entry widget.
+ * Start the search if it was ENTER.
+ *
+ * @param widget the entry widget
+ * @param event the key stroke
+ * @param user_data the builder of the main window
+ * @return FALSE if this was not ENTER, TRUE if it was
+ */
+gboolean
+main_window_search_entry_key_press_event_cb (GtkWidget * widget,
+ GdkEventKey * event,
+ gpointer user_data)
+{
+ GtkBuilder *builder = GTK_BUILDER (user_data);
+
+ if (event->keyval == GDK_KEY_Return)
+ {
+ start_search (builder);
+ return TRUE;
+ }
+ return FALSE;
+}
+
+/* end of gnunet-fs-gtk_main-window-search.c */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r19641 - gnunet-gtk/src/fs,
gnunet <=