1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
/*
This file is part of GNUnet
Copyright (C) 2005, 2006, 2010 GNUnet e.V.
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 3, 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., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, 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;
/**
* Reference to the directorie's search result.
*/
struct SearchResult *sr;
/**
* Anonymity level to use for probes in the directory.
*/
uint32_t anonymity;
};
/**
* 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 meta 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 (@a length bytes)
*/
static void
add_child (void *cls,
const char *filename,
const struct GNUNET_FS_Uri *uri,
const struct GNUNET_FS_MetaData *meta,
size_t length,
const void *data)
{
struct AddChildContext *acc = cls;
if (NULL == uri)
{
/* directory meta data itself, create parent entry */
struct GNUNET_FS_MetaData *dmeta;
dmeta = GNUNET_FS_meta_data_duplicate (meta);
GNUNET_FS_meta_data_insert (dmeta,
"<user>",
EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME,
EXTRACTOR_METAFORMAT_UTF8,
"text/plain",
acc->filename,
strlen (acc->filename) + 1);
acc->sr = GNUNET_GTK_add_to_uri_tab (acc->anonymity, dmeta, NULL);
GNUNET_FS_meta_data_destroy (dmeta);
return;
}
if (NULL == acc->sr)
{
GNUNET_break (0);
return;
}
GNUNET_assert (NULL != GNUNET_GTK_add_search_result (acc->sr->tab,
acc->anonymity,
acc->sr->rr,
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 (GTK_RESPONSE_OK != 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.sr = NULL;
acc.anonymity =
1; // FIXME, might want to add this to dialog to allow user to set it.
GNUNET_FS_GTK_mmap_and_scan (filename, &add_child, &acc);
GNUNET_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 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-FEATURE: 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 */
|