[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r19647 - gnunet-gtk/src/fs
From: |
gnunet |
Subject: |
[GNUnet-SVN] r19647 - gnunet-gtk/src/fs |
Date: |
Thu, 2 Feb 2012 19:20:57 +0100 |
Author: grothoff
Date: 2012-02-02 19:20:57 +0100 (Thu, 02 Feb 2012)
New Revision: 19647
Added:
gnunet-gtk/src/fs/gnunet-fs-gtk_open-directory.c
Removed:
gnunet-gtk/src/fs/gnunet-fs-gtk-main_window_open_directory.c
Modified:
gnunet-gtk/src/fs/Makefile.am
gnunet-gtk/src/fs/gnunet-fs-gtk_advertise-pseudonym.c
Log:
-renaming and code simplification
Modified: gnunet-gtk/src/fs/Makefile.am
===================================================================
--- gnunet-gtk/src/fs/Makefile.am 2012-02-02 17:58:18 UTC (rev 19646)
+++ gnunet-gtk/src/fs/Makefile.am 2012-02-02 18:20:57 UTC (rev 19647)
@@ -21,11 +21,11 @@
gnunet-fs-gtk_main-window-meta-data-context-menu.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_publish-dialog.c \
gnunet-fs-gtk_publish-edit-dialog.c gnunet-fs-gtk_publish-edit-dialog.h \
gnunet-fs-gtk-main_window_file_download.c \
- gnunet-fs-gtk-main_window_namespace.c \
- gnunet-fs-gtk-main_window_open_directory.c
+ gnunet-fs-gtk-main_window_namespace.c
gnunet_fs_gtk_LDADD = \
$(top_builddir)/src/lib/libgnunetgtk.la \
@GTK_LIBS@ \
Deleted: gnunet-gtk/src/fs/gnunet-fs-gtk-main_window_open_directory.c
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk-main_window_open_directory.c
2012-02-02 17:58:18 UTC (rev 19646)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk-main_window_open_directory.c
2012-02-02 18:20:57 UTC (rev 19647)
@@ -1,152 +0,0 @@
-/*
- This file is part of GNUnet
- (C) 2005, 2006, 2010 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_open_directory.c
- * @author Christian Grothoff
- */
-#include "gnunet-fs-gtk_common.h"
-#include "gnunet-fs-gtk_event-handler.h"
-
-struct AddChildContext
-{
- const char *filename;
- GtkTreeStore *ts;
- struct SearchTab *tab;
- struct SearchResult *par;
- GtkTreeRowReference *prr;
- GtkTreeIter iter;
-};
-
-
-/**
- * Function used to process entries in a directory.
- *
- * @param cls closure, our 'struct AddChildContext*'
- * @param filename name of the file in the directory
- * @param uri URI of the file
- * @param metadata metadata for the file; metadata for
- * the directory if everything else is NULL/zero
- * @param length length of the available data for the file
- * (of type size_t since data must certainly fit
- * into memory; if files are larger than size_t
- * permits, then they will certainly not be
- * embedded with the directory itself).
- * @param data data available for the file (length bytes)
- */
-static void
-add_child (void *cls, const char *filename, const struct GNUNET_FS_Uri *uri,
- const struct GNUNET_CONTAINER_MetaData *meta, size_t length,
- const void *data)
-{
- struct AddChildContext *acc = cls;
- struct GNUNET_CONTAINER_MetaData *dmeta;
- GtkTreePath *tp;
- GtkTreeIter iter;
-
- if (uri == NULL)
- {
- /* directory meta data itself */
- dmeta = GNUNET_CONTAINER_meta_data_duplicate (meta);
- GNUNET_CONTAINER_meta_data_insert (dmeta, "<user>",
- EXTRACTOR_METATYPE_FILENAME,
- EXTRACTOR_METAFORMAT_UTF8, "text/plain",
- acc->filename,
- strlen (acc->filename) + 1);
- acc->tab = GNUNET_GTK_add_to_uri_tab (&acc->iter, &acc->par, dmeta, NULL);
- tp = gtk_tree_model_get_path (GTK_TREE_MODEL (acc->tab->ts), &acc->iter);
- acc->prr = gtk_tree_row_reference_new (GTK_TREE_MODEL (acc->tab->ts), tp);
- gtk_tree_path_free (tp);
- acc->ts = acc->tab->ts;
- GNUNET_CONTAINER_meta_data_destroy (dmeta);
- return;
- }
- if (acc->ts == NULL)
- return;
- GNUNET_assert (NULL !=
- GNUNET_GTK_add_search_result (acc->tab, &iter, acc->prr, uri,
- meta, NULL, 0));
-}
-
-void
-GNUNET_GTK_open_directory_dialog_response_cb (GtkDialog * dialog,
- gint response_id,
- gpointer user_data)
-{
- GtkBuilder *builder;
- GtkWidget *ad;
- char *filename;
- struct AddChildContext acc;
-
- builder = GTK_BUILDER (user_data);
- ad = GTK_WIDGET (gtk_builder_get_object
- (builder, "GNUNET_GTK_open_directory_dialog"));
-
- if (response_id != -5)
- {
- gtk_widget_destroy (ad);
- g_object_unref (G_OBJECT (builder));
- return;
- }
-
- filename = GNUNET_GTK_filechooser_get_filename_utf8 (GTK_FILE_CHOOSER (ad));
- gtk_widget_destroy (ad);
- g_object_unref (G_OBJECT (builder));
- acc.filename = filename;
- acc.ts = NULL;
- GNUNET_FS_GTK_mmap_and_scan (filename, &add_child, &acc);
- g_free (filename);
-}
-
-/**
- * User selected "Open directory" in menu. Display dialog, open
- * file and then display a new tab with its contents.
- */
-void
-GNUNET_GTK_main_menu_file_open_gnunet_directory_activate_cb (GtkWidget * dummy,
- gpointer data)
-{
- GtkWidget *ad;
- GtkBuilder *builder;
- GtkWidget *toplevel;
- GtkFileFilter *ff;
-
-
- builder =
- GNUNET_GTK_get_new_builder ("gnunet_fs_gtk_open_directory_dialog.glade",
NULL);
- if (builder == NULL)
- {
- GNUNET_break (0);
- return;
- }
- ad = GTK_WIDGET (gtk_builder_get_object
- (builder, "GNUNET_GTK_open_directory_dialog"));
- ff = GTK_FILE_FILTER (gtk_builder_get_object
- (builder, "gnunet_directory_filter"));
- /* FIXME: some day, write a custom file filter for gnunet-directories... */
- gtk_file_filter_add_pattern (ff, "*" GNUNET_FS_DIRECTORY_EXT);
-
- toplevel = gtk_widget_get_toplevel (dummy);
- if (GTK_IS_WINDOW (toplevel))
- gtk_window_set_transient_for (GTK_WINDOW (ad), GTK_WINDOW (toplevel));
- gtk_window_present (GTK_WINDOW (ad));
-}
-
-/* end of gnunet-fs-gtk-main_window_open_directory.c */
Modified: gnunet-gtk/src/fs/gnunet-fs-gtk_advertise-pseudonym.c
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk_advertise-pseudonym.c 2012-02-02
17:58:18 UTC (rev 19646)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk_advertise-pseudonym.c 2012-02-02
18:20:57 UTC (rev 19647)
@@ -306,7 +306,11 @@
GtkBuilder *builder;
builder = GNUNET_GTK_get_new_builder
("gnunet_fs_gtk_select_pseudonym_dialog.glade", NULL);
-
+ if (NULL == builder)
+ {
+ GNUNET_break (0);
+ return;
+ }
ad = GTK_WIDGET (gtk_builder_get_object
(builder, "GNUNET_GTK_select_pseudonym_dialog"));
ls = GTK_LIST_STORE (gtk_builder_get_object
Copied: gnunet-gtk/src/fs/gnunet-fs-gtk_open-directory.c (from rev 19630,
gnunet-gtk/src/fs/gnunet-fs-gtk-main_window_open_directory.c)
===================================================================
--- gnunet-gtk/src/fs/gnunet-fs-gtk_open-directory.c
(rev 0)
+++ gnunet-gtk/src/fs/gnunet-fs-gtk_open-directory.c 2012-02-02 18:20:57 UTC
(rev 19647)
@@ -0,0 +1,180 @@
+/*
+ This file is part of GNUnet
+ (C) 2005, 2006, 2010 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-directory.c
+ * @author Christian Grothoff
+ */
+#include "gnunet-fs-gtk_common.h"
+#include "gnunet-fs-gtk_event-handler.h"
+
+
+/**
+ * Closure for 'add_child' function.
+ */
+struct AddChildContext
+{
+ /**
+ * Name of the directory file.
+ */
+ const char *filename;
+
+ /**
+ * Tree store where we will add entries.
+ */
+ GtkTreeStore *ts;
+
+ /**
+ * Tab we've opened for the directory.
+ */
+ struct SearchTab *tab;
+
+ /**
+ * Row reference to the directorie's parent entry.
+ */
+ GtkTreeRowReference *prr;
+
+};
+
+
+/**
+ * Function used to process entries in a directory. Adds each
+ * entry to our tab.
+ *
+ * @param cls closure, our 'struct AddChildContext*'
+ * @param filename name of the file in the directory
+ * @param uri URI of the file
+ * @param metadata metadata for the file; metadata for
+ * the directory if everything else is NULL/zero
+ * @param length length of the available data for the file
+ * (of type size_t since data must certainly fit
+ * into memory; if files are larger than size_t
+ * permits, then they will certainly not be
+ * embedded with the directory itself).
+ * @param data data available for the file (length bytes)
+ */
+static void
+add_child (void *cls, const char *filename, const struct GNUNET_FS_Uri *uri,
+ const struct GNUNET_CONTAINER_MetaData *meta, size_t length,
+ const void *data)
+{
+ struct AddChildContext *acc = cls;
+ GtkTreeIter iter;
+
+ if (NULL == uri)
+ {
+ /* directory meta data itself, create parent entry */
+ struct GNUNET_CONTAINER_MetaData *dmeta;
+ GtkTreePath *tp;
+
+ dmeta = GNUNET_CONTAINER_meta_data_duplicate (meta);
+ GNUNET_CONTAINER_meta_data_insert (dmeta, "<user>",
+ EXTRACTOR_METATYPE_FILENAME,
+ EXTRACTOR_METAFORMAT_UTF8, "text/plain",
+ acc->filename,
+ strlen (acc->filename) + 1);
+ acc->tab = GNUNET_GTK_add_to_uri_tab (&iter, NULL, dmeta, NULL);
+ tp = gtk_tree_model_get_path (GTK_TREE_MODEL (acc->tab->ts), &iter);
+ acc->prr = gtk_tree_row_reference_new (GTK_TREE_MODEL (acc->tab->ts), tp);
+ gtk_tree_path_free (tp);
+ acc->ts = acc->tab->ts;
+ GNUNET_CONTAINER_meta_data_destroy (dmeta);
+ return;
+ }
+ if (NULL == acc->ts)
+ {
+ GNUNET_break (0);
+ return;
+ }
+ GNUNET_assert (NULL !=
+ GNUNET_GTK_add_search_result (acc->tab, &iter, acc->prr, uri,
+ meta, NULL, 0));
+}
+
+
+/**
+ * Function called from the open-directory dialog upon completion.
+ *
+ * @param dialog the pseudonym selection dialog
+ * @param response_id response code from the dialog
+ * @param user_data the builder of the dialog
+ */
+void
+GNUNET_GTK_open_directory_dialog_response_cb (GtkDialog * dialog,
+ gint response_id,
+ gpointer user_data)
+{
+ GtkBuilder *builder = GTK_BUILDER (user_data);
+ char *filename;
+ struct AddChildContext acc;
+
+ if (-5 != response_id)
+ {
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+ g_object_unref (G_OBJECT (builder));
+ return;
+ }
+ filename = GNUNET_GTK_filechooser_get_filename_utf8 (GTK_FILE_CHOOSER
(dialog));
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+ g_object_unref (G_OBJECT (builder));
+ acc.filename = filename;
+ acc.ts = NULL;
+ GNUNET_FS_GTK_mmap_and_scan (filename, &add_child, &acc);
+ g_free (filename);
+}
+
+
+/**
+ * User selected "Open directory" in menu. Display dialog, open
+ * file and then display a new tab with its contents.
+ *
+ * @param dummy the menu entry
+ * @param user_data the main dialog builder, unused
+ */
+void
+GNUNET_GTK_main_menu_file_open_gnunet_directory_activate_cb (GtkWidget * dummy,
+ gpointer data)
+{
+ GtkWidget *ad;
+ GtkBuilder *builder;
+ GtkWidget *toplevel;
+ GtkFileFilter *ff;
+
+ builder =
+ GNUNET_GTK_get_new_builder ("gnunet_fs_gtk_open_directory_dialog.glade",
NULL);
+ if (NULL == builder)
+ {
+ GNUNET_break (0);
+ return;
+ }
+ ad = GTK_WIDGET (gtk_builder_get_object
+ (builder, "GNUNET_GTK_open_directory_dialog"));
+ ff = GTK_FILE_FILTER (gtk_builder_get_object
+ (builder, "gnunet_directory_filter"));
+ /* FIXME: some day, write a custom file filter for gnunet-directories... */
+ gtk_file_filter_add_pattern (ff, "*" GNUNET_FS_DIRECTORY_EXT);
+
+ toplevel = gtk_widget_get_toplevel (dummy);
+ if (GTK_IS_WINDOW (toplevel))
+ gtk_window_set_transient_for (GTK_WINDOW (ad), GTK_WINDOW (toplevel));
+ gtk_window_present (GTK_WINDOW (ad));
+}
+
+/* end of gnunet-fs-gtk_open-directory.c */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r19647 - gnunet-gtk/src/fs,
gnunet <=