[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r11972 - gnunet-gtk/src
From: |
gnunet |
Subject: |
[GNUnet-SVN] r11972 - gnunet-gtk/src |
Date: |
Sun, 27 Jun 2010 13:52:12 +0200 |
Author: grothoff
Date: 2010-06-27 13:52:12 +0200 (Sun, 27 Jun 2010)
New Revision: 11972
Modified:
gnunet-gtk/src/fs_event_handler.c
gnunet-gtk/src/main_window_open_directory.c
Log:
towards open directory implementation
Modified: gnunet-gtk/src/fs_event_handler.c
===================================================================
--- gnunet-gtk/src/fs_event_handler.c 2010-06-27 11:50:00 UTC (rev 11971)
+++ gnunet-gtk/src/fs_event_handler.c 2010-06-27 11:52:12 UTC (rev 11972)
@@ -770,7 +770,8 @@
char *uris;
GdkPixbuf *pixbuf;
- if ( (!GNUNET_FS_uri_test_loc (uri)) &&
+ if ( (uri != NULL) &&
+ (!GNUNET_FS_uri_test_loc (uri)) &&
(!GNUNET_FS_uri_test_chk (uri)) )
{
/* SKS support not implemented yet */
@@ -791,7 +792,10 @@
-1);
if (desc == NULL)
desc = GNUNET_strdup (_("no description supplied"));
- uris = GNUNET_FS_uri_to_string (uri);
+ if (uri == NULL)
+ uris = GNUNET_strdup (_("no URI"));
+ else
+ uris = GNUNET_FS_uri_to_string (uri);
mime = GNUNET_CONTAINER_meta_data_get_first_by_types (meta,
EXTRACTOR_METATYPE_MIMETYPE,
EXTRACTOR_METATYPE_FORMAT,
@@ -807,8 +811,8 @@
NULL,
G_MAXINT,
0, GNUNET_CONTAINER_meta_data_duplicate
(meta),
- 1, GNUNET_FS_uri_dup (uri),
- 2, GNUNET_FS_uri_chk_get_file_size (uri),
+ 1, (uri == NULL) ? NULL :
GNUNET_FS_uri_dup (uri),
+ 2, (uri == NULL) ? 0 :
GNUNET_FS_uri_chk_get_file_size (uri),
3, pixbuf /* preview */,
4, 0 /* percent progress */,
5, 0 /* percent availability */,
Modified: gnunet-gtk/src/main_window_open_directory.c
===================================================================
--- gnunet-gtk/src/main_window_open_directory.c 2010-06-27 11:50:00 UTC (rev
11971)
+++ gnunet-gtk/src/main_window_open_directory.c 2010-06-27 11:52:12 UTC (rev
11972)
@@ -23,8 +23,68 @@
* @author Christian Grothoff
*/
#include "common.h"
+#include "fs_event_handler.h"
+struct AddChildContext
+{
+ const char *filename;
+ GtkTreeStore *ts;
+ 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;
+
+ 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_C_STRING,
+ "text/plain",
+ acc->filename,
+ strlen (acc->filename) + 1);
+ acc->ts = GNUNET_GTK_add_to_uri_tab (&acc->iter,
+ dmeta,
+ NULL);
+ GNUNET_CONTAINER_meta_data_destroy (dmeta);
+ return;
+ }
+ if (acc->ts == NULL)
+ return;
+ /* FIXME */
+ GNUNET_break (0);
+ acc = NULL;
+}
+
+
+/**
* User selected "Open directory" in menu. Display dialog, open
* file and then display a new tab with its contents.
*/
@@ -32,9 +92,14 @@
GNUNET_GTK_main_menu_file_open_gnunet_directory_activate_cb (GtkWidget *
dummy,
gpointer data)
{
+ struct AddChildContext acc;
GtkWidget *ad;
GtkBuilder *builder;
char *filename;
+ struct GNUNET_DISK_FileHandle *fh;
+ struct GNUNET_DISK_MapHandle *mh;
+ uint64_t fsize;
+ void * ddata;
builder = GNUNET_GTK_get_new_builder ("open_directory_dialog.glade");
if (builder == NULL)
@@ -53,19 +118,54 @@
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(ad));
gtk_widget_destroy (ad);
g_object_unref (G_OBJECT (builder));
-#if 0
- open_directory;
- uri = compute_uri_from_file (filename);
- meta = new;
- meta_make_directory ();
- meta_add (filename);
- ts = setup_entry_in_uri_tab (&iter,
- meta,
- uri);
- directory_iterate (add_child, ts, &iter);
- GNUNET_break (0);
-#endif
+ if (GNUNET_OK !=
+ GNUNET_DISK_file_size (filename,
+ &fsize,
+ GNUNET_YES))
+ {
+ GNUNET_break (0);
+ g_free (filename);
+ return;
+ }
+ fh = GNUNET_DISK_file_open (filename,
+ GNUNET_DISK_OPEN_READ,
+ GNUNET_DISK_PERM_NONE);
+ if (fh == NULL)
+ {
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", filename);
+ g_free (filename);
+ return;
+ }
+ ddata = GNUNET_DISK_file_map (fh,
+ &mh,
+ GNUNET_DISK_MAP_TYPE_READ,
+ (size_t) fsize);
+ if (ddata == NULL)
+ {
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "mmap", filename);
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_DISK_file_close (fh));
+ g_free (filename);
+ return;
+ }
+ acc.filename = filename;
+ acc.ts = NULL;
+ if (GNUNET_SYSERR ==
+ GNUNET_FS_directory_list_contents ((size_t) fsize,
+ ddata,
+ 0,
+ &add_child,
+ &acc))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Selected file `%s' is not a GNUnet directory!\n"),
+ filename);
+ }
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_DISK_file_unmap (mh));
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_DISK_file_close (fh));
g_free (filename);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r11972 - gnunet-gtk/src,
gnunet <=