aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/fs/directory.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/fs/directory.c')
-rw-r--r--src/plugins/fs/directory.c162
1 files changed, 162 insertions, 0 deletions
diff --git a/src/plugins/fs/directory.c b/src/plugins/fs/directory.c
new file mode 100644
index 00000000..1bf2db5d
--- /dev/null
+++ b/src/plugins/fs/directory.c
@@ -0,0 +1,162 @@
1/*
2 This file is part of GNUnet.
3 (C) 2007 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/plugins/fs/directory.c
23 * @brief code for opening directories
24 * @author Christian Grothoff
25 */
26
27#include "platform.h"
28#include "gnunetgtk_common.h"
29#include "fs.h"
30#include "helper.h"
31#include "meta.h"
32#include "search.h"
33#include <GNUnet/gnunet_util_crypto.h>
34#include <GNUnet/gnunet_uritrack_lib.h>
35#include <GNUnet/gnunet_namespace_lib.h>
36#include <extractor.h>
37
38#ifndef MINGW
39static char *
40selectFile() {
41 GladeXML * uploadXML;
42 GtkFileChooser * dialog;
43 char * ret;
44
45 uploadXML
46 = glade_xml_new(getGladeFileName(),
47 "openDirectoryFileDialog",
48 PACKAGE_NAME);
49 connectGladeWithPlugins(uploadXML);
50 dialog = GTK_FILE_CHOOSER(glade_xml_get_widget(uploadXML,
51 "openDirectoryFileDialog"));
52 if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_CANCEL)
53 ret = gtk_file_chooser_get_filename(dialog);
54 else
55 ret = NULL;
56 gtk_widget_destroy(GTK_WIDGET(dialog));
57 UNREF(uploadXML);
58 return ret;
59}
60#else /* MINGW */
61static char *
62selectFile() {
63 return plibc_ChooseFile(_("Choose the directory you want to open."),
64 OFN_FILEMUSTEXIST | OFN_SHAREAWARE);
65}
66#endif /* MINGW */
67
68static int
69spcb(const ECRS_FileInfo * fi,
70 const HashCode512 * key,
71 int isRoot,
72 void * closure) {
73 SearchList * list = closure;
74 fs_search_result_received(list,
75 fi,
76 list->uri);
77 return OK;
78}
79
80
81void on_open_menu_activate_fs(GtkWidget * dummy1,
82 GtkWidget * dummy2) {
83 char * dn;
84 char * directory_data;
85 unsigned long long directory_data_len;
86 size_t dlen;
87 struct ECRS_MetaData * md;
88 int fd;
89 SearchList * list;
90 struct ECRS_URI * uri;
91 const char * kws[2];
92#if 1
93 /* somehow on my system I get this (and only this event)
94 always twice -- not sure why, but this is a workaround
95 for now */
96 static int modulo;
97
98 if (0 == (1 & modulo++))
99 return;
100#endif
101 dn = selectFile();
102 if (dn == NULL)
103 return;
104 if ( (YES != disk_file_test(NULL,
105 dn)) ||
106 (OK != disk_file_size(NULL,
107 dn,
108 &directory_data_len,
109 YES)) ) {
110 addLogEntry(_("Error accessing file `%s'."),
111 dn);
112 FREE(dn);
113 return;
114 }
115 fd = disk_file_open(NULL,
116 dn,
117 O_LARGEFILE | O_RDONLY);
118 if (fd == -1) {
119 addLogEntry(_("Error opening file `%s'."),
120 dn);
121 FREE(dn);
122 return;
123 }
124 dlen = (size_t) directory_data_len;
125 directory_data = MMAP(NULL,
126 dlen,
127 PROT_READ,
128 MAP_SHARED,
129 fd,
130 0);
131 if (directory_data == MAP_FAILED) {
132 addLogEntry(_("Error mapping file `%s' into memory."),
133 dn);
134 CLOSE(fd);
135 FREE(dn);
136 return;
137 }
138 kws[0] = dn;
139 kws[1] = NULL;
140 uri = ECRS_keywordsToUri(kws);
141 md = NULL;
142 list = fs_search_started(NULL,
143 uri,
144 0,
145 0,
146 NULL,
147 FSUI_COMPLETED);
148 ECRS_freeUri(uri);
149 ECRS_listDirectory(NULL,
150 directory_data,
151 directory_data_len,
152 &md,
153 &spcb,
154 list);
155 if (md != NULL)
156 ECRS_freeMetaData(md);
157 MUNMAP(directory_data, dlen);
158 CLOSE(fd);
159 FREE(dn);
160}
161
162/* end of directory.c */