[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r19649 - gnunet-gtk/src/fs
From: |
gnunet |
Subject: |
[GNUnet-SVN] r19649 - gnunet-gtk/src/fs |
Date: |
Thu, 2 Feb 2012 19:33:27 +0100 |
Author: grothoff
Date: 2012-02-02 19:33:27 +0100 (Thu, 02 Feb 2012)
New Revision: 19649
Added:
gnunet-gtk/src/fs/gnunet-fs-gtk_main-window-namespace-dropdown.c
Removed:
gnunet-gtk/src/fs/gnunet-fs-gtk-main_window_namespace.c
Modified:
gnunet-gtk/src/fs/Makefile.am
Log:
-finishing file renaming fiesta
Modified: gnunet-gtk/src/fs/Makefile.am
===================================================================
--- gnunet-gtk/src/fs/Makefile.am 2012-02-02 18:29:18 UTC (rev 19648)
+++ gnunet-gtk/src/fs/Makefile.am 2012-02-02 18:33:27 UTC (rev 19649)
@@ -19,13 +19,13 @@
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-meta-data-context-menu.c \
+ gnunet-fs-gtk_main-window-namespace-dropdown.c \
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_publish-dialog.c \
- gnunet-fs-gtk_publish-edit-dialog.c gnunet-fs-gtk_publish-edit-dialog.h \
- gnunet-fs-gtk-main_window_namespace.c
+ gnunet-fs-gtk_publish-edit-dialog.c gnunet-fs-gtk_publish-edit-dialog.h
gnunet_fs_gtk_LDADD = \
$(top_builddir)/src/lib/libgnunetgtk.la \
@GTK_LIBS@ \
Deleted: gnunet-gtk/src/fs/gnunet-fs-gtk-main_window_namespace.c
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk-main_window_namespace.c 2012-02-02
18:29:18 UTC (rev 19648)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk-main_window_namespace.c 2012-02-02
18:33:27 UTC (rev 19649)
@@ -1,476 +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_namespace.c
- * @author Christian Grothoff
- * @brief event handlers for the namespace selection dropdown box in the main
window
- */
-#include "gnunet-fs-gtk_common.h"
-#include "gnunet-fs-gtk.h"
-
-
-static guint namespace_selector_window_leave_timeout_source;
-
-
-void
-main_window_search_namespace_dropdown_button_toggled_cb (GtkToggleButton *
- togglebutton,
- gpointer user_data)
-{
- GtkBuilder *builder = GTK_BUILDER (user_data);
- gboolean active;
- GtkWidget *namespace_selector_window;
- GtkWidget *namespace_selector_treeview;
-
- namespace_selector_window =
- GTK_WIDGET (gtk_builder_get_object
- (builder, "namespace_selector_window"));
- namespace_selector_treeview =
- GTK_WIDGET (gtk_builder_get_object
- (builder, "namespace_selector_treeview"));
- g_object_get (G_OBJECT (togglebutton), "active", &active, NULL);
- if (active)
- {
- GtkAllocation togglebutton_allocation;
- GdkWindow *main_window_gdk;
- gint mwg_x, mwg_y, tgb_x, tgb_y, popup_x, popup_y;
-
- gtk_widget_get_allocation (GTK_WIDGET (togglebutton),
- &togglebutton_allocation);
-
- main_window_gdk = gtk_widget_get_window (GTK_WIDGET (togglebutton));
-
- gdk_window_get_origin (main_window_gdk, &mwg_x, &mwg_y);
-
- /* FIXME: this might become a problem in other window managers,
- * where reference point is not in the top-left corner.
- * We want to show the window below the button.
- */
- tgb_x = mwg_x + togglebutton_allocation.x;
- tgb_y = mwg_y + togglebutton_allocation.y;
- popup_x = tgb_x;
- popup_y = tgb_y + togglebutton_allocation.height;
-
- gtk_window_move (GTK_WINDOW (namespace_selector_window), popup_x, popup_y);
-
- gtk_widget_show_all (namespace_selector_window);
- gtk_widget_grab_focus (namespace_selector_treeview);
- }
- else
- {
- gtk_widget_hide (namespace_selector_window);
- gtk_widget_grab_focus (GTK_WIDGET (togglebutton));
- }
-}
-
-
-gboolean
-namespace_selector_window_leave_timeout_cb (gpointer user_data)
-{
- GtkToggleButton *toggle_button = GTK_TOGGLE_BUTTON (user_data);
-
- /* This will eventually hide the namespace selector */
- gtk_toggle_button_set_active (toggle_button, FALSE);
- return FALSE;
-}
-
-
-gboolean
-main_window_search_namespace_dropdown_button_enter_notify_event_cb (GtkWidget *
- widget,
- GdkEvent *
- event,
- gpointer
- user_data)
-{
- if (namespace_selector_window_leave_timeout_source > 0)
- g_source_remove (namespace_selector_window_leave_timeout_source);
- return FALSE;
-}
-
-
-gboolean
-namespace_selector_window_leave_notify_event_cb (GtkWidget * widget,
- GdkEvent * event,
- gpointer user_data)
-{
- GtkBuilder *builder;
- GtkToggleButton *toggle_button;
- guint timeout_id;
-
- builder = GTK_BUILDER (user_data);
-
- toggle_button =
- GTK_TOGGLE_BUTTON (gtk_builder_get_object
- (builder,
- "main_window_search_namespace_dropdown_button"));
-
- /* Place a timeout to hide the window. It will be cancelled if the cursor
- * enters the namespace selector window or the toggle button within 100ms.
- */
- timeout_id =
- g_timeout_add (100, &namespace_selector_window_leave_timeout_cb,
- toggle_button);
- if (namespace_selector_window_leave_timeout_source > 0)
- g_source_remove (namespace_selector_window_leave_timeout_source);
- namespace_selector_window_leave_timeout_source = timeout_id;
-
- return FALSE;
-}
-
-
-
-gboolean
-get_selected_namespace_treepath_iter_model_widget (GtkBuilder * builder,
- GtkTreePath ** p_treepath,
- GtkTreeIter * p_iter,
- GtkTreeModel ** p_model,
- GtkWidget ** p_widget)
-{
- GtkTreeSelection *selection;
- GtkTreeModel *model;
- GList *selected;
- GtkTreePath *treepath;
- GtkWidget *widget;
-
- widget =
- GTK_WIDGET (gtk_builder_get_object
- (builder, "namespace_selector_treeview"));
- if (!widget)
- return FALSE;
-
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
- model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
- if (!selection || !model)
- return FALSE;
-
- selected = gtk_tree_selection_get_selected_rows (selection, NULL);
- if (!selected)
- return FALSE;
- if (selected->data == NULL)
- {
- g_list_foreach (selected, (GFunc) gtk_tree_path_free, NULL);
- g_list_free (selected);
- return FALSE;
- }
- /* Free everything except the first path, keep it */
- treepath = (GtkTreePath *) selected->data;
- selected = g_list_remove (selected, selected->data);
- g_list_foreach (selected, (GFunc) gtk_tree_path_free, NULL);
- g_list_free (selected);
-
- if (p_iter && !gtk_tree_model_get_iter (model, p_iter, treepath))
- {
- gtk_tree_path_free (treepath);
- return FALSE;
- }
- *p_treepath = treepath;
- if (p_model)
- *p_model = model;
- if (p_widget)
- *p_widget = widget;
- return TRUE;
-}
-
-void
-namespace_selector_treeview_cursor_changed_cb (GtkWidget * widget,
- gpointer user_data)
-{
- GtkBuilder *builder;
- GtkToggleButton *toggle_button;
- GtkLabel *sel_namespace_label;
- GtkTreeModel *model;
- gchar *value;
- GtkTreePath *treepath;
- GtkEntry *search_entry;
- GtkTreeRowReference *ref, *old;
-
- builder = GTK_BUILDER (user_data);
-
- toggle_button =
- GTK_TOGGLE_BUTTON (gtk_builder_get_object
- (builder,
- "main_window_search_namespace_dropdown_button"));
- if (!toggle_button)
- return;
-
- search_entry =
- GTK_ENTRY (gtk_builder_get_object (builder, "main_window_search_entry"));
- if (!search_entry)
- return;
-
- if (!get_selected_namespace_treepath_iter_model_widget
- (builder, &treepath, NULL, &model, NULL))
- return;
- ref = gtk_tree_row_reference_new (model, treepath);
- old = g_object_get_data (G_OBJECT (toggle_button), "selected-row-reference");
- if (old)
- gtk_tree_row_reference_free (old);
- g_object_set_data (G_OBJECT (toggle_button), "selected-row-reference", ref);
-
-
- sel_namespace_label =
- GTK_LABEL (gtk_builder_get_object
- (builder, "main_window_search_selected_namespace_label"));
- if (!sel_namespace_label)
- return;
-
- if (GNUNET_GTK_get_tree_string (GTK_TREE_VIEW (widget), treepath, 0, &value)
- && value != NULL)
- {
- gtk_label_set_text (sel_namespace_label, value);
- g_free (value);
- }
- if (GNUNET_GTK_get_tree_string (GTK_TREE_VIEW (widget), treepath, 2, &value)
- && value != NULL)
- {
- gtk_entry_set_text (search_entry, value);
- g_free (value);
- }
-
- gtk_tree_path_free (treepath);
-
- /* This will eventually hide the namespace selector */
- gtk_toggle_button_set_active (toggle_button, FALSE);
-}
-
-GtkTreeRowReference *
-get_ns_selected_row (GtkTreeView * tree)
-{
- GtkTreeSelection *sel;
- GList *rows, *row;
- GtkTreeModel *model;
- GtkTreeRowReference *ref = NULL;
-
- sel = gtk_tree_view_get_selection (tree);
- rows = gtk_tree_selection_get_selected_rows (sel, &model);
- for (row = rows; row; row = row->next)
- {
- ref = gtk_tree_row_reference_new (model, row->data);
- if (ref != NULL)
- break;
- }
- g_list_foreach (rows, (GFunc) gtk_tree_path_free, NULL);
- g_list_free (rows);
- return ref;
-}
-
-gboolean
-namespace_selector_treeview_button_press_event_cb (GtkWidget * widget,
- GdkEvent * event,
- gpointer user_data)
-{
- GtkTreeRowReference *ref = NULL;
-
- ref = get_ns_selected_row (GTK_TREE_VIEW (widget));
- if (ref != NULL)
- {
- gpointer old = g_object_get_data (G_OBJECT (widget),
"pushed-rowreference");
-
- if (old)
- gtk_tree_row_reference_free (old);
- g_object_set_data (G_OBJECT (widget), "pushed-rowreference", ref);
- }
- return FALSE;
-}
-
-gboolean
-namespace_selector_treeview_button_release_event_cb (GtkWidget * widget,
- GdkEvent * event,
- gpointer user_data)
-{
- GtkTreeRowReference *ref = NULL;
- gpointer old = g_object_get_data (G_OBJECT (widget), "pushed-rowreference");
-
- ref = get_ns_selected_row (GTK_TREE_VIEW (widget));
- if (ref && old)
- {
- GtkTreePath *path_ref, *path_old;
-
- path_ref = gtk_tree_row_reference_get_path (ref);
- path_old = gtk_tree_row_reference_get_path (old);
- if (gtk_tree_path_compare (path_ref, path_old) == 0)
- namespace_selector_treeview_cursor_changed_cb (widget, user_data);
- if (path_ref)
- gtk_tree_path_free (path_ref);
- if (path_old)
- gtk_tree_path_free (path_old);
- }
- if (ref)
- gtk_tree_row_reference_free (ref);
- if (old)
- gtk_tree_row_reference_free (old);
- g_object_set_data (G_OBJECT (widget), "pushed-rowreference", NULL);
- return FALSE;
-}
-
-
-
-/**
- * Add pseudonym data to tree store
- *
- * @param cls closure (the 'GtkListStore')
- * @param pseudonym hash code of public key of pseudonym
- * @param md meta data known about the pseudonym
- * @param rating the local rating of the pseudonym
- * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort
- */
-static int
-add_namespace_to_ts (void *cls, const GNUNET_HashCode * pseudonym,
- const struct GNUNET_CONTAINER_MetaData *md, int rating)
-{
- GtkTreeStore *ts = cls;
- char *root;
- char *ns_name;
- GNUNET_HashCode *nsid;
- char *description;
- char *uris;
- char *emsg;
- struct GNUNET_FS_Uri *uri;
- GtkTreeIter iter;
-
- ns_name =
- GNUNET_PSEUDONYM_id_to_name (GNUNET_FS_GTK_get_configuration (),
- pseudonym);
- nsid = GNUNET_malloc (sizeof (GNUNET_HashCode));
- *nsid = *pseudonym;
- root = NULL;
- uris = GNUNET_CONTAINER_meta_data_get_by_type (md, EXTRACTOR_METATYPE_URI);
- if (uris != NULL)
- {
- emsg = NULL;
- uri = GNUNET_FS_uri_parse (uris, &emsg);
- if (uri == NULL)
- GNUNET_free (emsg);
- root = GNUNET_FS_uri_sks_get_content_id (uri);
- GNUNET_FS_uri_destroy (uri);
- }
- description =
- GNUNET_CONTAINER_meta_data_get_first_by_types (md,
- EXTRACTOR_METATYPE_TITLE,
-
EXTRACTOR_METATYPE_BOOK_TITLE,
-
EXTRACTOR_METATYPE_DESCRIPTION,
-
EXTRACTOR_METATYPE_SUMMARY,
- EXTRACTOR_METATYPE_ALBUM,
-
EXTRACTOR_METATYPE_COMMENT,
-
EXTRACTOR_METATYPE_SUBJECT,
-
EXTRACTOR_METATYPE_KEYWORDS,
- -1);
- if (description == NULL)
- description = g_strdup (_("no description supplied"));
- else
- {
- char *utf8_desc = NULL;
-
- utf8_desc =
- GNUNET_FS_GTK_dubious_meta_to_utf8 (EXTRACTOR_METAFORMAT_UTF8,
- description, strlen (description));
- GNUNET_free (description);
- if (utf8_desc != NULL)
- description = utf8_desc;
- else
- description = NULL;
- }
- gtk_tree_store_insert_with_values (ts, &iter, NULL, G_MAXINT, 0, ns_name, 1,
- nsid, 2, root, 3, description, -1);
- GNUNET_free (ns_name);
- GNUNET_free_non_null (root);
- GNUNET_free_non_null (description);
- return GNUNET_OK;
-}
-
-
-void
-GNUNET_GTK_main_window_realize_cb (GtkWidget * widget, gpointer user_data)
-{
- GtkTreeIter iter;
- GtkTreeView *namespace_tree;
- GtkTreeStore *namespace_treestore;
- GtkBuilder *builder;
- GtkWidget *namespace_selector_window;
-
- builder = GTK_BUILDER (user_data);
-
- /* Make sure button class is realized */
- g_type_class_unref (g_type_class_ref (GTK_TYPE_BUTTON));
- /* GNUnet main window assumes that images on buttons are visible,
- * override the theme's gtkrc setting
- */
- g_object_set (gtk_settings_get_default (), "gtk-button-images", TRUE, NULL);
-
- namespace_treestore =
- GTK_TREE_STORE (GNUNET_FS_GTK_get_main_window_object
- ("main_window_search_namespace_treestore"));
- namespace_tree =
- GTK_TREE_VIEW (GNUNET_FS_GTK_get_main_window_object
- ("namespace_selector_treeview"));
-
- /* FIXME: find a way to manage pseudonyms.
- * Right now the list will be filled with ALL and ANY pseudonyms that we
- * find, these are held as files in a special directory.
- * I don't see an easy way to ignore certain pseudonyms in that directory,
- * and that require for pseudonym management. Also, pseudonyms are presented
- * in arbitrary order. We must either sort them (by name?) or let the user
- * drag them around to change the order in which they appear in the list.
- * All that is not possible with a simple "files in a directory" concept.
- */
- gtk_tree_store_insert_with_values (namespace_treestore, &iter, NULL,
G_MAXINT,
- 0, "Any", 1, NULL, 2, "", 3,
- "Do not search in any particular
namespace",
- -1);
- /*
- * GNUNET_PSEUDONYM_list_all (GNUNET_FS_GTK_get_configuration (),
- * &add_namespace_to_ts, namespace_treestore);
- */
- /* FIXME: when do we unregister? */
- GNUNET_PSEUDONYM_discovery_callback_register
(GNUNET_FS_GTK_get_configuration (),
- &add_namespace_to_ts,
- namespace_treestore);
-
- /* FIXME: read currently selected namespace from somewhere instead of
selecting 0th item */
- if (gtk_tree_model_get_iter_first
- (GTK_TREE_MODEL (namespace_treestore), &iter))
- {
- gchar *value;
- GtkLabel *sel_namespace_label;
- GtkTreePath *treepath = gtk_tree_path_new_first ();
-
- gtk_tree_selection_select_iter (gtk_tree_view_get_selection
- (namespace_tree), &iter);
- sel_namespace_label =
- GTK_LABEL (gtk_builder_get_object
- (builder, "main_window_search_selected_namespace_label"));
- if (GNUNET_GTK_get_tree_string (namespace_tree, treepath, 0, &value))
- gtk_label_set_text (sel_namespace_label, value);
- gtk_tree_path_free (treepath);
- }
-
- /* How the window (to trigger certain events) and immediately hide it */
- namespace_selector_window =
- GTK_WIDGET (gtk_builder_get_object
- (builder, "namespace_selector_window"));
- gtk_widget_show (namespace_selector_window);
- gtk_widget_hide (namespace_selector_window);
-
-}
-
-
-/* end of gnunet-fs-gtk-main_window_namespace.c */
Copied: gnunet-gtk/src/fs/gnunet-fs-gtk_main-window-namespace-dropdown.c (from
rev 19630, gnunet-gtk/src/fs/gnunet-fs-gtk-main_window_namespace.c)
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk_main-window-namespace-dropdown.c
(rev 0)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk_main-window-namespace-dropdown.c
2012-02-02 18:33:27 UTC (rev 19649)
@@ -0,0 +1,476 @@
+/*
+ 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-namespace-dropdown.c
+ * @author LRN
+ * @brief event handlers for the namespace selection dropdown box in the main
window
+ */
+#include "gnunet-fs-gtk_common.h"
+#include "gnunet-fs-gtk.h"
+
+
+static guint namespace_selector_window_leave_timeout_source;
+
+
+void
+main_window_search_namespace_dropdown_button_toggled_cb (GtkToggleButton *
+ togglebutton,
+ gpointer user_data)
+{
+ GtkBuilder *builder = GTK_BUILDER (user_data);
+ gboolean active;
+ GtkWidget *namespace_selector_window;
+ GtkWidget *namespace_selector_treeview;
+
+ namespace_selector_window =
+ GTK_WIDGET (gtk_builder_get_object
+ (builder, "namespace_selector_window"));
+ namespace_selector_treeview =
+ GTK_WIDGET (gtk_builder_get_object
+ (builder, "namespace_selector_treeview"));
+ g_object_get (G_OBJECT (togglebutton), "active", &active, NULL);
+ if (active)
+ {
+ GtkAllocation togglebutton_allocation;
+ GdkWindow *main_window_gdk;
+ gint mwg_x, mwg_y, tgb_x, tgb_y, popup_x, popup_y;
+
+ gtk_widget_get_allocation (GTK_WIDGET (togglebutton),
+ &togglebutton_allocation);
+
+ main_window_gdk = gtk_widget_get_window (GTK_WIDGET (togglebutton));
+
+ gdk_window_get_origin (main_window_gdk, &mwg_x, &mwg_y);
+
+ /* FIXME: this might become a problem in other window managers,
+ * where reference point is not in the top-left corner.
+ * We want to show the window below the button.
+ */
+ tgb_x = mwg_x + togglebutton_allocation.x;
+ tgb_y = mwg_y + togglebutton_allocation.y;
+ popup_x = tgb_x;
+ popup_y = tgb_y + togglebutton_allocation.height;
+
+ gtk_window_move (GTK_WINDOW (namespace_selector_window), popup_x, popup_y);
+
+ gtk_widget_show_all (namespace_selector_window);
+ gtk_widget_grab_focus (namespace_selector_treeview);
+ }
+ else
+ {
+ gtk_widget_hide (namespace_selector_window);
+ gtk_widget_grab_focus (GTK_WIDGET (togglebutton));
+ }
+}
+
+
+gboolean
+namespace_selector_window_leave_timeout_cb (gpointer user_data)
+{
+ GtkToggleButton *toggle_button = GTK_TOGGLE_BUTTON (user_data);
+
+ /* This will eventually hide the namespace selector */
+ gtk_toggle_button_set_active (toggle_button, FALSE);
+ return FALSE;
+}
+
+
+gboolean
+main_window_search_namespace_dropdown_button_enter_notify_event_cb (GtkWidget *
+ widget,
+ GdkEvent *
+ event,
+ gpointer
+ user_data)
+{
+ if (namespace_selector_window_leave_timeout_source > 0)
+ g_source_remove (namespace_selector_window_leave_timeout_source);
+ return FALSE;
+}
+
+
+gboolean
+namespace_selector_window_leave_notify_event_cb (GtkWidget * widget,
+ GdkEvent * event,
+ gpointer user_data)
+{
+ GtkBuilder *builder;
+ GtkToggleButton *toggle_button;
+ guint timeout_id;
+
+ builder = GTK_BUILDER (user_data);
+
+ toggle_button =
+ GTK_TOGGLE_BUTTON (gtk_builder_get_object
+ (builder,
+ "main_window_search_namespace_dropdown_button"));
+
+ /* Place a timeout to hide the window. It will be cancelled if the cursor
+ * enters the namespace selector window or the toggle button within 100ms.
+ */
+ timeout_id =
+ g_timeout_add (100, &namespace_selector_window_leave_timeout_cb,
+ toggle_button);
+ if (namespace_selector_window_leave_timeout_source > 0)
+ g_source_remove (namespace_selector_window_leave_timeout_source);
+ namespace_selector_window_leave_timeout_source = timeout_id;
+
+ return FALSE;
+}
+
+
+
+gboolean
+get_selected_namespace_treepath_iter_model_widget (GtkBuilder * builder,
+ GtkTreePath ** p_treepath,
+ GtkTreeIter * p_iter,
+ GtkTreeModel ** p_model,
+ GtkWidget ** p_widget)
+{
+ GtkTreeSelection *selection;
+ GtkTreeModel *model;
+ GList *selected;
+ GtkTreePath *treepath;
+ GtkWidget *widget;
+
+ widget =
+ GTK_WIDGET (gtk_builder_get_object
+ (builder, "namespace_selector_treeview"));
+ if (!widget)
+ return FALSE;
+
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
+ if (!selection || !model)
+ return FALSE;
+
+ selected = gtk_tree_selection_get_selected_rows (selection, NULL);
+ if (!selected)
+ return FALSE;
+ if (selected->data == NULL)
+ {
+ g_list_foreach (selected, (GFunc) gtk_tree_path_free, NULL);
+ g_list_free (selected);
+ return FALSE;
+ }
+ /* Free everything except the first path, keep it */
+ treepath = (GtkTreePath *) selected->data;
+ selected = g_list_remove (selected, selected->data);
+ g_list_foreach (selected, (GFunc) gtk_tree_path_free, NULL);
+ g_list_free (selected);
+
+ if (p_iter && !gtk_tree_model_get_iter (model, p_iter, treepath))
+ {
+ gtk_tree_path_free (treepath);
+ return FALSE;
+ }
+ *p_treepath = treepath;
+ if (p_model)
+ *p_model = model;
+ if (p_widget)
+ *p_widget = widget;
+ return TRUE;
+}
+
+void
+namespace_selector_treeview_cursor_changed_cb (GtkWidget * widget,
+ gpointer user_data)
+{
+ GtkBuilder *builder;
+ GtkToggleButton *toggle_button;
+ GtkLabel *sel_namespace_label;
+ GtkTreeModel *model;
+ gchar *value;
+ GtkTreePath *treepath;
+ GtkEntry *search_entry;
+ GtkTreeRowReference *ref, *old;
+
+ builder = GTK_BUILDER (user_data);
+
+ toggle_button =
+ GTK_TOGGLE_BUTTON (gtk_builder_get_object
+ (builder,
+ "main_window_search_namespace_dropdown_button"));
+ if (!toggle_button)
+ return;
+
+ search_entry =
+ GTK_ENTRY (gtk_builder_get_object (builder, "main_window_search_entry"));
+ if (!search_entry)
+ return;
+
+ if (!get_selected_namespace_treepath_iter_model_widget
+ (builder, &treepath, NULL, &model, NULL))
+ return;
+ ref = gtk_tree_row_reference_new (model, treepath);
+ old = g_object_get_data (G_OBJECT (toggle_button), "selected-row-reference");
+ if (old)
+ gtk_tree_row_reference_free (old);
+ g_object_set_data (G_OBJECT (toggle_button), "selected-row-reference", ref);
+
+
+ sel_namespace_label =
+ GTK_LABEL (gtk_builder_get_object
+ (builder, "main_window_search_selected_namespace_label"));
+ if (!sel_namespace_label)
+ return;
+
+ if (GNUNET_GTK_get_tree_string (GTK_TREE_VIEW (widget), treepath, 0, &value)
+ && value != NULL)
+ {
+ gtk_label_set_text (sel_namespace_label, value);
+ g_free (value);
+ }
+ if (GNUNET_GTK_get_tree_string (GTK_TREE_VIEW (widget), treepath, 2, &value)
+ && value != NULL)
+ {
+ gtk_entry_set_text (search_entry, value);
+ g_free (value);
+ }
+
+ gtk_tree_path_free (treepath);
+
+ /* This will eventually hide the namespace selector */
+ gtk_toggle_button_set_active (toggle_button, FALSE);
+}
+
+GtkTreeRowReference *
+get_ns_selected_row (GtkTreeView * tree)
+{
+ GtkTreeSelection *sel;
+ GList *rows, *row;
+ GtkTreeModel *model;
+ GtkTreeRowReference *ref = NULL;
+
+ sel = gtk_tree_view_get_selection (tree);
+ rows = gtk_tree_selection_get_selected_rows (sel, &model);
+ for (row = rows; row; row = row->next)
+ {
+ ref = gtk_tree_row_reference_new (model, row->data);
+ if (ref != NULL)
+ break;
+ }
+ g_list_foreach (rows, (GFunc) gtk_tree_path_free, NULL);
+ g_list_free (rows);
+ return ref;
+}
+
+gboolean
+namespace_selector_treeview_button_press_event_cb (GtkWidget * widget,
+ GdkEvent * event,
+ gpointer user_data)
+{
+ GtkTreeRowReference *ref = NULL;
+
+ ref = get_ns_selected_row (GTK_TREE_VIEW (widget));
+ if (ref != NULL)
+ {
+ gpointer old = g_object_get_data (G_OBJECT (widget),
"pushed-rowreference");
+
+ if (old)
+ gtk_tree_row_reference_free (old);
+ g_object_set_data (G_OBJECT (widget), "pushed-rowreference", ref);
+ }
+ return FALSE;
+}
+
+gboolean
+namespace_selector_treeview_button_release_event_cb (GtkWidget * widget,
+ GdkEvent * event,
+ gpointer user_data)
+{
+ GtkTreeRowReference *ref = NULL;
+ gpointer old = g_object_get_data (G_OBJECT (widget), "pushed-rowreference");
+
+ ref = get_ns_selected_row (GTK_TREE_VIEW (widget));
+ if (ref && old)
+ {
+ GtkTreePath *path_ref, *path_old;
+
+ path_ref = gtk_tree_row_reference_get_path (ref);
+ path_old = gtk_tree_row_reference_get_path (old);
+ if (gtk_tree_path_compare (path_ref, path_old) == 0)
+ namespace_selector_treeview_cursor_changed_cb (widget, user_data);
+ if (path_ref)
+ gtk_tree_path_free (path_ref);
+ if (path_old)
+ gtk_tree_path_free (path_old);
+ }
+ if (ref)
+ gtk_tree_row_reference_free (ref);
+ if (old)
+ gtk_tree_row_reference_free (old);
+ g_object_set_data (G_OBJECT (widget), "pushed-rowreference", NULL);
+ return FALSE;
+}
+
+
+
+/**
+ * Add pseudonym data to tree store
+ *
+ * @param cls closure (the 'GtkListStore')
+ * @param pseudonym hash code of public key of pseudonym
+ * @param md meta data known about the pseudonym
+ * @param rating the local rating of the pseudonym
+ * @return GNUNET_OK to continue iteration, GNUNET_SYSERR to abort
+ */
+static int
+add_namespace_to_ts (void *cls, const GNUNET_HashCode * pseudonym,
+ const struct GNUNET_CONTAINER_MetaData *md, int rating)
+{
+ GtkTreeStore *ts = cls;
+ char *root;
+ char *ns_name;
+ GNUNET_HashCode *nsid;
+ char *description;
+ char *uris;
+ char *emsg;
+ struct GNUNET_FS_Uri *uri;
+ GtkTreeIter iter;
+
+ ns_name =
+ GNUNET_PSEUDONYM_id_to_name (GNUNET_FS_GTK_get_configuration (),
+ pseudonym);
+ nsid = GNUNET_malloc (sizeof (GNUNET_HashCode));
+ *nsid = *pseudonym;
+ root = NULL;
+ uris = GNUNET_CONTAINER_meta_data_get_by_type (md, EXTRACTOR_METATYPE_URI);
+ if (uris != NULL)
+ {
+ emsg = NULL;
+ uri = GNUNET_FS_uri_parse (uris, &emsg);
+ if (uri == NULL)
+ GNUNET_free (emsg);
+ root = GNUNET_FS_uri_sks_get_content_id (uri);
+ GNUNET_FS_uri_destroy (uri);
+ }
+ description =
+ GNUNET_CONTAINER_meta_data_get_first_by_types (md,
+ EXTRACTOR_METATYPE_TITLE,
+
EXTRACTOR_METATYPE_BOOK_TITLE,
+
EXTRACTOR_METATYPE_DESCRIPTION,
+
EXTRACTOR_METATYPE_SUMMARY,
+ EXTRACTOR_METATYPE_ALBUM,
+
EXTRACTOR_METATYPE_COMMENT,
+
EXTRACTOR_METATYPE_SUBJECT,
+
EXTRACTOR_METATYPE_KEYWORDS,
+ -1);
+ if (description == NULL)
+ description = g_strdup (_("no description supplied"));
+ else
+ {
+ char *utf8_desc = NULL;
+
+ utf8_desc =
+ GNUNET_FS_GTK_dubious_meta_to_utf8 (EXTRACTOR_METAFORMAT_UTF8,
+ description, strlen (description));
+ GNUNET_free (description);
+ if (utf8_desc != NULL)
+ description = utf8_desc;
+ else
+ description = NULL;
+ }
+ gtk_tree_store_insert_with_values (ts, &iter, NULL, G_MAXINT, 0, ns_name, 1,
+ nsid, 2, root, 3, description, -1);
+ GNUNET_free (ns_name);
+ GNUNET_free_non_null (root);
+ GNUNET_free_non_null (description);
+ return GNUNET_OK;
+}
+
+
+void
+GNUNET_GTK_main_window_realize_cb (GtkWidget * widget, gpointer user_data)
+{
+ GtkTreeIter iter;
+ GtkTreeView *namespace_tree;
+ GtkTreeStore *namespace_treestore;
+ GtkBuilder *builder;
+ GtkWidget *namespace_selector_window;
+
+ builder = GTK_BUILDER (user_data);
+
+ /* Make sure button class is realized */
+ g_type_class_unref (g_type_class_ref (GTK_TYPE_BUTTON));
+ /* GNUnet main window assumes that images on buttons are visible,
+ * override the theme's gtkrc setting
+ */
+ g_object_set (gtk_settings_get_default (), "gtk-button-images", TRUE, NULL);
+
+ namespace_treestore =
+ GTK_TREE_STORE (GNUNET_FS_GTK_get_main_window_object
+ ("main_window_search_namespace_treestore"));
+ namespace_tree =
+ GTK_TREE_VIEW (GNUNET_FS_GTK_get_main_window_object
+ ("namespace_selector_treeview"));
+
+ /* FIXME: find a way to manage pseudonyms.
+ * Right now the list will be filled with ALL and ANY pseudonyms that we
+ * find, these are held as files in a special directory.
+ * I don't see an easy way to ignore certain pseudonyms in that directory,
+ * and that require for pseudonym management. Also, pseudonyms are presented
+ * in arbitrary order. We must either sort them (by name?) or let the user
+ * drag them around to change the order in which they appear in the list.
+ * All that is not possible with a simple "files in a directory" concept.
+ */
+ gtk_tree_store_insert_with_values (namespace_treestore, &iter, NULL,
G_MAXINT,
+ 0, "Any", 1, NULL, 2, "", 3,
+ "Do not search in any particular
namespace",
+ -1);
+ /*
+ * GNUNET_PSEUDONYM_list_all (GNUNET_FS_GTK_get_configuration (),
+ * &add_namespace_to_ts, namespace_treestore);
+ */
+ /* FIXME: when do we unregister? */
+ GNUNET_PSEUDONYM_discovery_callback_register
(GNUNET_FS_GTK_get_configuration (),
+ &add_namespace_to_ts,
+ namespace_treestore);
+
+ /* FIXME: read currently selected namespace from somewhere instead of
selecting 0th item */
+ if (gtk_tree_model_get_iter_first
+ (GTK_TREE_MODEL (namespace_treestore), &iter))
+ {
+ gchar *value;
+ GtkLabel *sel_namespace_label;
+ GtkTreePath *treepath = gtk_tree_path_new_first ();
+
+ gtk_tree_selection_select_iter (gtk_tree_view_get_selection
+ (namespace_tree), &iter);
+ sel_namespace_label =
+ GTK_LABEL (gtk_builder_get_object
+ (builder, "main_window_search_selected_namespace_label"));
+ if (GNUNET_GTK_get_tree_string (namespace_tree, treepath, 0, &value))
+ gtk_label_set_text (sel_namespace_label, value);
+ gtk_tree_path_free (treepath);
+ }
+
+ /* How the window (to trigger certain events) and immediately hide it */
+ namespace_selector_window =
+ GTK_WIDGET (gtk_builder_get_object
+ (builder, "namespace_selector_window"));
+ gtk_widget_show (namespace_selector_window);
+ gtk_widget_hide (namespace_selector_window);
+
+}
+
+
+/* end of gnunet-fs-gtk_main-window-namespace-dropdown.c */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r19649 - gnunet-gtk/src/fs,
gnunet <=