aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/plugins/fs/Makefile.am1
-rw-r--r--src/plugins/fs/directory.c162
-rw-r--r--src/plugins/fs/namespace.c5
-rw-r--r--src/plugins/fs/search.c55
-rw-r--r--src/plugins/fs/upload.c1
5 files changed, 197 insertions, 27 deletions
diff --git a/src/plugins/fs/Makefile.am b/src/plugins/fs/Makefile.am
index 2d07659f..17bd42ac 100644
--- a/src/plugins/fs/Makefile.am
+++ b/src/plugins/fs/Makefile.am
@@ -11,6 +11,7 @@ plugin_LTLIBRARIES = \
11 11
12libgnunetgtkmodule_fs_la_SOURCES = \ 12libgnunetgtkmodule_fs_la_SOURCES = \
13 collection.c collection.h \ 13 collection.c collection.h \
14 directory.c \
14 fs.c fs.h \ 15 fs.c fs.h \
15 helper.c helper.h \ 16 helper.c helper.h \
16 meta.c meta.h \ 17 meta.c meta.h \
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 */
diff --git a/src/plugins/fs/namespace.c b/src/plugins/fs/namespace.c
index 0b257c68..c81cbaa6 100644
--- a/src/plugins/fs/namespace.c
+++ b/src/plugins/fs/namespace.c
@@ -1439,11 +1439,6 @@ void fs_namespace_start() {
1439 DEBUG_END(); 1439 DEBUG_END();
1440} 1440}
1441 1441
1442void on_open_menu_activate_fs(GtkWidget * dummy1,
1443 GtkWidget * dummy2) {
1444 printf("Not implemented\n");
1445}
1446
1447#if 0 1442#if 0
1448void on_availableContentList_destroy_fs(GtkWidget * dummy1, 1443void on_availableContentList_destroy_fs(GtkWidget * dummy1,
1449 GtkWidget * dummy2) { 1444 GtkWidget * dummy2) {
diff --git a/src/plugins/fs/search.c b/src/plugins/fs/search.c
index a851b6cb..5c2b0df7 100644
--- a/src/plugins/fs/search.c
+++ b/src/plugins/fs/search.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2005, 2006 Christian Grothoff (and other contributing authors) 3 (C) 2005, 2006, 2007 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published
@@ -908,13 +908,19 @@ void on_closeSearchButton_clicked_fs(GtkWidget * searchPage,
908 list = list->next; 908 list = list->next;
909 } 909 }
910 GE_ASSERT(ectx, list != NULL); 910 GE_ASSERT(ectx, list != NULL);
911 fcbc.method = &FSUI_abortSearch; 911 if (list->fsui_list == NULL) {
912 fcbc.argument = list->fsui_list; 912 /* open directory - close directly */
913 run_with_save_calls(&fsui_callback, 913 fs_search_stopped(list);
914 &fcbc); 914 } else {
915 fcbc.method = &FSUI_stopSearch; 915 /* actual search - close via FSUI */
916 run_with_save_calls(&fsui_callback, 916 fcbc.method = &FSUI_abortSearch;
917 &fcbc); 917 fcbc.argument = list->fsui_list;
918 run_with_save_calls(&fsui_callback,
919 &fcbc);
920 fcbc.method = &FSUI_stopSearch;
921 run_with_save_calls(&fsui_callback,
922 &fcbc);
923 }
918} 924}
919 925
920/** 926/**
@@ -932,11 +938,12 @@ void on_abortSearchButton_clicked_fs(GtkWidget * searchPage,
932 list = list->next; 938 list = list->next;
933 } 939 }
934 GE_ASSERT(ectx, list != NULL); 940 GE_ASSERT(ectx, list != NULL);
935 941 if (list->fsui_list != NULL) {
936 fcbc.method = &FSUI_abortSearch; 942 fcbc.method = &FSUI_abortSearch;
937 fcbc.argument = list->fsui_list; 943 fcbc.argument = list->fsui_list;
938 run_with_save_calls(&fsui_callback, 944 run_with_save_calls(&fsui_callback,
939 &fcbc); 945 &fcbc);
946 }
940} 947}
941 948
942static void stopSearch(GtkTreeModel * model, 949static void stopSearch(GtkTreeModel * model,
@@ -952,13 +959,18 @@ static void stopSearch(GtkTreeModel * model,
952 SEARCH_SUMMARY_INTERNAL, &s, 959 SEARCH_SUMMARY_INTERNAL, &s,
953 -1); 960 -1);
954 if (s != NULL) { 961 if (s != NULL) {
955 fcbc.method = &FSUI_abortSearch; 962 if (s->fsui_list == NULL) {
956 fcbc.argument = s->fsui_list; 963 /* open directory - close directly */
957 run_with_save_calls(&fsui_callback, 964 fs_search_stopped(s);
958 &fcbc); 965 } else {
959 fcbc.method = &FSUI_stopSearch; 966 fcbc.method = &FSUI_abortSearch;
960 run_with_save_calls(&fsui_callback, 967 fcbc.argument = s->fsui_list;
961 &fcbc); 968 run_with_save_calls(&fsui_callback,
969 &fcbc);
970 fcbc.method = &FSUI_stopSearch;
971 run_with_save_calls(&fsui_callback,
972 &fcbc);
973 }
962 } 974 }
963} 975}
964 976
@@ -988,7 +1000,8 @@ static void abortSearch(GtkTreeModel * model,
988 iter, 1000 iter,
989 SEARCH_SUMMARY_INTERNAL, &s, 1001 SEARCH_SUMMARY_INTERNAL, &s,
990 -1); 1002 -1);
991 if (s != NULL) { 1003 if ( (s != NULL) &&
1004 (s->fsui_list != NULL) ) {
992 fcbc.method = &FSUI_abortSearch; 1005 fcbc.method = &FSUI_abortSearch;
993 fcbc.argument = s->fsui_list; 1006 fcbc.argument = s->fsui_list;
994 run_with_save_calls(&fsui_callback, 1007 run_with_save_calls(&fsui_callback,
diff --git a/src/plugins/fs/upload.c b/src/plugins/fs/upload.c
index e8d91b2e..971c1bb9 100644
--- a/src/plugins/fs/upload.c
+++ b/src/plugins/fs/upload.c
@@ -452,7 +452,6 @@ void on_fsinsertuploadbutton_clicked_fs(gpointer dummy,
452} 452}
453 453
454#ifndef MINGW 454#ifndef MINGW
455
456static char * 455static char *
457selectFile(const char * oldfilename) { 456selectFile(const char * oldfilename) {
458 GladeXML * uploadXML; 457 GladeXML * uploadXML;