aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2005-07-06 03:51:07 +0000
committerChristian Grothoff <christian@grothoff.org>2005-07-06 03:51:07 +0000
commit960dce6066522c8a9147806c7eb23cac6eaf5ff7 (patch)
treea17a0c2f2ab11a6584ce54d9833714ce1c730cfb /src/plugins
parenta16bbf60c55995d61433e45cdc2e51af620b802d (diff)
downloadgnunet-gtk-960dce6066522c8a9147806c7eb23cac6eaf5ff7.tar.gz
gnunet-gtk-960dce6066522c8a9147806c7eb23cac6eaf5ff7.zip
update
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/fs/Makefile.am1
-rw-r--r--src/plugins/fs/collection.c57
-rw-r--r--src/plugins/fs/collection.h34
-rw-r--r--src/plugins/fs/fs.c3
-rw-r--r--src/plugins/fs/namespace.c318
-rw-r--r--src/plugins/fs/upload.c8
6 files changed, 400 insertions, 21 deletions
diff --git a/src/plugins/fs/Makefile.am b/src/plugins/fs/Makefile.am
index 9f3d5831..494a47c9 100644
--- a/src/plugins/fs/Makefile.am
+++ b/src/plugins/fs/Makefile.am
@@ -10,6 +10,7 @@ plugin_LTLIBRARIES = \
10 libgnunetgtkmodule_fs.la 10 libgnunetgtkmodule_fs.la
11 11
12libgnunetgtkmodule_fs_la_SOURCES = \ 12libgnunetgtkmodule_fs_la_SOURCES = \
13 collection.c collection.h \
13 download.c download.h \ 14 download.c download.h \
14 fs.c fs.h \ 15 fs.c fs.h \
15 namespace.c namespace.h \ 16 namespace.c namespace.h \
diff --git a/src/plugins/fs/collection.c b/src/plugins/fs/collection.c
new file mode 100644
index 00000000..df1ca7f6
--- /dev/null
+++ b/src/plugins/fs/collection.c
@@ -0,0 +1,57 @@
1/*
2 This file is part of GNUnet.
3 (C) 2005 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/collection.c
23 * @brief code for operations with collections
24 * @author Christian Grothoff
25 */
26
27#include "platform.h"
28#include "gnunetgtk_common.h"
29#include "fs.h"
30#include "collection.h"
31#include <extractor.h>
32
33void create_collection_clicked(GtkWidget * dummy1,
34 GtkWidget * dummy2) {
35 /*
36 FSUI_startCollection(ctx,
37 unsigned int anonymityLevel,
38 cron_t updateInterval,
39 const char * name,
40 const struct ECRS_MetaData * meta);
41 */
42}
43
44void collectionDelete_clicked(GtkWidget * dummy1,
45 GtkWidget * dummy2) {
46 FSUI_stopCollection(ctx);
47 /* fixme: disable stop collection button,
48 enable start collection button! */
49}
50
51void fs_collection_start() {
52}
53
54void fs_collection_stop() {
55}
56
57/* end of collection.c */
diff --git a/src/plugins/fs/collection.h b/src/plugins/fs/collection.h
new file mode 100644
index 00000000..825db40e
--- /dev/null
+++ b/src/plugins/fs/collection.h
@@ -0,0 +1,34 @@
1/*
2 This file is part of GNUnet.
3 (C) 2005 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/collection.h
23 * @brief code for dealing with collections
24 * @author Christian Grothoff
25 */
26
27#ifndef GTK_COLLECTION_H
28#define GTK_COLLECTION_H
29
30void fs_collection_start(void);
31
32void fs_collection_stop(void);
33
34#endif
diff --git a/src/plugins/fs/fs.c b/src/plugins/fs/fs.c
index 5884d857..b8dcdddb 100644
--- a/src/plugins/fs/fs.c
+++ b/src/plugins/fs/fs.c
@@ -30,6 +30,7 @@
30#include "download.h" 30#include "download.h"
31#include "search.h" 31#include "search.h"
32#include "upload.h" 32#include "upload.h"
33#include "collection.h"
33#include "namespace.h" 34#include "namespace.h"
34#include <GNUnet/gnunet_fsui_lib.h> 35#include <GNUnet/gnunet_fsui_lib.h>
35 36
@@ -140,6 +141,7 @@ void init_fs() {
140 YES, 141 YES,
141 &eventProcessor, 142 &eventProcessor,
142 NULL); 143 NULL);
144 fs_collection_start();
143 fs_search_start(); 145 fs_search_start();
144 fs_download_start(); 146 fs_download_start();
145 fs_upload_start(); 147 fs_upload_start();
@@ -155,6 +157,7 @@ void done_fs() {
155 fs_download_stop(); 157 fs_download_stop();
156 fs_search_stop(); 158 fs_search_stop();
157 fs_namespace_stop(); 159 fs_namespace_stop();
160 fs_collection_stop();
158 sig = SEMAPHORE_NEW(0); 161 sig = SEMAPHORE_NEW(0);
159 if (0 != PTHREAD_CREATE(&doneThread, 162 if (0 != PTHREAD_CREATE(&doneThread,
160 (PThreadMain)&shutdownCode, 163 (PThreadMain)&shutdownCode,
diff --git a/src/plugins/fs/namespace.c b/src/plugins/fs/namespace.c
index 54751c4a..a663883a 100644
--- a/src/plugins/fs/namespace.c
+++ b/src/plugins/fs/namespace.c
@@ -54,7 +54,7 @@ static GtkWidget * makeNamespaceFrame(GtkWidget ** treeview,
54 GtkWidget * child; 54 GtkWidget * child;
55 GtkWidget * resultList; 55 GtkWidget * resultList;
56 GtkCellRenderer * renderer; 56 GtkCellRenderer * renderer;
57 GtkTreeStore * tree; 57 GtkListStore * model;
58 GladeXML * namespaceXML; 58 GladeXML * namespaceXML;
59 59
60 namespaceXML 60 namespaceXML
@@ -70,7 +70,7 @@ static GtkWidget * makeNamespaceFrame(GtkWidget ** treeview,
70 "namespaceAnonymitySpinButton"); 70 "namespaceAnonymitySpinButton");
71 if (treeview != NULL) 71 if (treeview != NULL)
72 (*treeview) = GTK_WIDGET(GTK_TREE_VIEW(resultList)); 72 (*treeview) = GTK_WIDGET(GTK_TREE_VIEW(resultList));
73 tree = 73 model =
74 gtk_list_store_new(IN_NAMESPACE_NUM, 74 gtk_list_store_new(IN_NAMESPACE_NUM,
75 G_TYPE_STRING, /* (file)name */ 75 G_TYPE_STRING, /* (file)name */
76 G_TYPE_UINT64, /* size */ 76 G_TYPE_UINT64, /* size */
@@ -83,7 +83,7 @@ static GtkWidget * makeNamespaceFrame(GtkWidget ** treeview,
83 G_TYPE_POINTER, /* URI */ 83 G_TYPE_POINTER, /* URI */
84 G_TYPE_POINTER); /* META */ 84 G_TYPE_POINTER); /* META */
85 gtk_tree_view_set_model(GTK_TREE_VIEW(resultList), 85 gtk_tree_view_set_model(GTK_TREE_VIEW(resultList),
86 GTK_TREE_MODEL(tree)); 86 GTK_TREE_MODEL(model));
87 renderer = gtk_cell_renderer_text_new(); 87 renderer = gtk_cell_renderer_text_new();
88 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(resultList), 88 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(resultList),
89 -1, 89 -1,
@@ -152,18 +152,61 @@ static GtkWidget * makeNamespaceFrame(GtkWidget ** treeview,
152 return child; 152 return child;
153} 153}
154 154
155
156
157/** 155/**
158 * Add the given content to the globally available 156 * Add the given content to the globally available
159 * content model. 157 * content model. Check that it is not already
158 * present!
160 */ 159 */
161static int updateView(const ECRS_FileInfo * fi, 160static int updateView(const ECRS_FileInfo * fi,
162 const HashCode512 * key, 161 const HashCode512 * key,
163 void * closure) { 162 void * closure) {
164 GtkTreeView * model = GTK_TREE_VIEW(closure); 163 GtkTreeModel * model = GTK_TREE_MODEL(closure);
165 /* model is also a gtk list store! */ 164 struct ECRS_URI * euri;
166 /* FIXME! */ 165 GtkTreeIter iter;
166 char * filename;
167 char * uriString;
168 unsigned long long size;
169
170 if (gtk_tree_model_get_iter_first(model,
171 &iter)) {
172 do {
173 gtk_tree_model_get(model,
174 &iter,
175 NAMESPACE_URI, &euri,
176 -1);
177 if (ECRS_equalsUri(euri,
178 fi->uri))
179 return OK; /* already listed */
180 } while (gtk_tree_model_iter_next(GTK_TREE_MODEL(model),
181 &iter));
182 }
183 filename = ECRS_getFirstFromMetaData(fi->meta,
184 EXTRACTOR_FILENAME,
185 EXTRACTOR_TITLE,
186 EXTRACTOR_DESCRIPTION,
187 EXTRACTOR_SUBJECT,
188 EXTRACTOR_ARTIST,
189 EXTRACTOR_AUTHOR,
190 EXTRACTOR_PUBLISHER,
191 EXTRACTOR_CREATOR,
192 EXTRACTOR_PRODUCER,
193 EXTRACTOR_UNKNOWN,
194 -1);
195 if (filename == NULL)
196 filename = STRDUP(_("no name given"));
197 size = ECRS_fileSize(fi->uri);
198 uriString = ECRS_uriToString(fi->uri);
199 gtk_list_store_append(GTK_LIST_STORE(model),
200 &iter);
201 gtk_list_store_set(GTK_LIST_STORE(model),
202 &iter,
203 NAMESPACE_FILENAME, filename,
204 NAMESPACE_SIZE, size,
205 NAMESPACE_URISTRING, uriString,
206 NAMESPACE_URI, ECRS_dupUri(fi->uri),
207 -1);
208 FREE(filename);
209 FREE(uriString);
167 return OK; 210 return OK;
168} 211}
169 212
@@ -200,13 +243,79 @@ static void updateContentList(void * unused) {
200 * @return OK to continue iteration, SYSERR to abort 243 * @return OK to continue iteration, SYSERR to abort
201 */ 244 */
202static int addNamespaceContentToModel(void * cls, 245static int addNamespaceContentToModel(void * cls,
203 const ECRS_FileInfo * uri, 246 const ECRS_FileInfo * fi,
204 const HashCode512 * lastId, 247 const HashCode512 * lastId,
205 const HashCode512 * nextId, 248 const HashCode512 * nextId,
206 cron_t publicationFrequency, 249 cron_t publicationFrequency,
207 cron_t nextPublicationTime) { 250 cron_t nextPublicationTime) {
208 GtkListStore * model = model; 251 GtkListStore * model = GTK_LIST_STORE(cls);
209 /* FIXME */ 252 GtkTreeIter iter;
253 char * filename;
254 char * desc;
255 char * mime;
256 char * uriString;
257 EncName last;
258 EncName next;
259 char * freq;
260 char * date;
261 unsigned long long size;
262 TIME_T t;
263
264 filename = ECRS_getFirstFromMetaData(fi->meta,
265 EXTRACTOR_FILENAME,
266 EXTRACTOR_TITLE,
267 EXTRACTOR_ARTIST,
268 EXTRACTOR_AUTHOR,
269 EXTRACTOR_PUBLISHER,
270 EXTRACTOR_CREATOR,
271 EXTRACTOR_PRODUCER,
272 EXTRACTOR_UNKNOWN,
273 -1);
274 if (filename == NULL)
275 filename = STRDUP(_("no name given"));
276 desc = ECRS_getFirstFromMetaData(fi->meta,
277 EXTRACTOR_DESCRIPTION,
278 EXTRACTOR_GENRE,
279 EXTRACTOR_ALBUM,
280 EXTRACTOR_COMMENT,
281 EXTRACTOR_SUBJECT,
282 EXTRACTOR_FORMAT,
283 EXTRACTOR_SIZE,
284 EXTRACTOR_KEYWORDS,
285 -1);
286 if (desc == NULL)
287 desc = STRDUP("");
288 mime = ECRS_getFromMetaData(fi->meta,
289 EXTRACTOR_MIMETYPE);
290 if (mime == NULL)
291 mime = STRDUP(_("unknown"));
292 size = ECRS_fileSize(fi->uri);
293 uriString = ECRS_uriToString(fi->uri);
294 hash2enc(lastId, &last);
295 hash2enc(nextId, &next);
296 t = nextPublicationTime / cronSECONDS;
297 date = GN_CTIME(&t);
298 freq = timeIntervalToFancyString(publicationFrequency);
299 gtk_list_store_append(model,
300 &iter);
301 gtk_list_store_set(model,
302 &iter,
303 IN_NAMESPACE_FILENAME, filename,
304 IN_NAMESPACE_SIZE, size,
305 IN_NAMESPACE_DESCRIPTION, desc,
306 IN_NAMESPACE_MIMETYPE, mime,
307 IN_NAMESPACE_LAST_STRING, &last,
308 IN_NAMESPACE_NEXT_STRING, &next,
309 IN_NAMESPACE_PUB_FREQ_STRING, freq,
310 IN_NAMESPACE_PUB_DATE_STRING, date,
311 IN_NAMESPACE_URI, ECRS_dupUri(fi->uri),
312 IN_NAMESPACE_META, ECRS_dupMetaData(fi->meta),
313 -1);
314 FREE(filename);
315 FREE(uriString);
316 FREE(freq);
317 FREE(date);
318 FREE(mime);
210 319
211 return OK; 320 return OK;
212} 321}
@@ -260,13 +369,188 @@ static int addTabForNamespace(void * unused,
260 return OK; 369 return OK;
261} 370}
262 371
372/**
373 * FIXME: refactor code to share keyword/metadata list
374 * and model creation with upload and collection!
375 */
263void create_namespace_clicked(GtkWidget * dummy1, 376void create_namespace_clicked(GtkWidget * dummy1,
264 GtkWidget * dummy2) { 377 GtkWidget * dummy2) {
265 /* FIXME */ 378 const char * namespaceName;
266 /* open dialog to enter namespace meta 379 GladeXML * metaXML;
267 data; then create namespace; finally 380 GtkWidget * nameLine;
268 open tab */ 381 GtkWidget * metaList;
269 382 GtkWidget * keywordList;
383 GtkWidget * dialog;
384 GtkWidget * metaType;
385 GtkWidget * spin;
386 GtkListStore * metamodel;
387 GtkListStore * keymodel;
388 GtkCellRenderer * renderer;
389 GtkListStore * keywordTypeModel;
390 GtkTreeIter iter;
391 struct ECRS_MetaData * meta;
392 EXTRACTOR_KeywordType type;
393 struct ECRS_URI * keywordURI;
394 const char * stype;
395 char * mvalue;
396 char ** keywords;
397 unsigned int kpos;
398 unsigned int ksize;
399 struct ECRS_URI * root;
400 HashCode512 namespaceId;
401 HashCode512 rootEntry;
402
403 metaXML
404 = glade_xml_new(getGladeFileName(),
405 "namespaceMetaDataDialog",
406 NULL);
407 connectGladeWithPlugins(metaXML);
408 dialog = glade_xml_get_widget(metaXML,
409 "namespaceMetaDataDialog");
410 metamodel
411 = gtk_list_store_new(META_NUM,
412 G_TYPE_INT,
413 G_TYPE_STRING,
414 G_TYPE_STRING);
415 metaList = glade_xml_get_widget(metaXML,
416 "namespaceMetaDataDialogMetaDataList");
417 renderer = gtk_cell_renderer_text_new();
418 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(metaList),
419 -1,
420 _("Category"),
421 renderer,
422 "text", META_STYPE,
423 NULL);
424 renderer = gtk_cell_renderer_text_new();
425 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(metaList),
426 -1,
427 _("Value"),
428 renderer,
429 "text", META_VALUE,
430 NULL);
431 gtk_tree_view_set_model(GTK_TREE_VIEW(metaList),
432 GTK_TREE_MODEL(metamodel));
433 keymodel
434 = gtk_list_store_new(1,
435 G_TYPE_STRING);
436 keywordList = glade_xml_get_widget(metaXML,
437 "namespaceMetaDataDialogKeywordList");
438 renderer = gtk_cell_renderer_text_new();
439 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(keywordList),
440 -1,
441 _("Keyword"),
442 renderer,
443 "text", 0,
444 NULL);
445 gtk_tree_view_set_model(GTK_TREE_VIEW(keywordList),
446 GTK_TREE_MODEL(keymodel));
447 keywordTypeModel
448 = gtk_list_store_new(KTYPE_NUM,
449 G_TYPE_STRING,
450 G_TYPE_INT);
451 metaType
452 = glade_xml_get_widget(metaXML,
453 "namespaceMetaDataDialogMetaTypeComboBox");
454 gtk_combo_box_set_model(GTK_COMBO_BOX(metaType),
455 GTK_TREE_MODEL(keywordTypeModel));
456 for (type=0;type<EXTRACTOR_getHighestKeywordTypeNumber();type++) {
457 stype = EXTRACTOR_getKeywordTypeAsString(type);
458 gtk_list_store_append(keywordTypeModel,
459 &iter);
460 gtk_list_store_set(keywordTypeModel,
461 &iter,
462 KTYPE_STRING, stype,
463 KTYPE_TYPE, type,
464 -1);
465 }
466 renderer = gtk_cell_renderer_text_new();
467 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(metaType),
468 renderer,
469 FALSE);
470 gtk_cell_layout_add_attribute(GTK_CELL_LAYOUT(metaType),
471 renderer,
472 "text", KTYPE_STRING);
473 gtk_combo_box_set_active(GTK_COMBO_BOX(metaType),
474 0);
475 gtk_dialog_set_default_response(GTK_DIALOG(dialog),
476 GTK_RESPONSE_OK);
477 if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_CANCEL) {
478 meta = ECRS_createMetaData();
479 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(metamodel),
480 &iter)) {
481 do {
482 gtk_tree_model_get(GTK_TREE_MODEL(metamodel),
483 &iter,
484 META_TYPE, &type,
485 META_VALUE, &mvalue,
486 -1);
487 ECRS_addToMetaData(meta,
488 type,
489 mvalue);
490 } while (gtk_tree_model_iter_next(GTK_TREE_MODEL(metamodel),
491 &iter));
492 }
493 keywords = NULL;
494 ksize = 0;
495 GROW(keywords,
496 ksize,
497 64);
498 kpos = 0;
499 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(keymodel),
500 &iter)) {
501 do {
502 gtk_tree_model_get(GTK_TREE_MODEL(keymodel),
503 &iter,
504 0, &mvalue,
505 -1);
506 keywords[kpos++] = mvalue;
507 if (kpos == ksize)
508 GROW(keywords,
509 ksize,
510 kpos*2);
511 } while (gtk_tree_model_iter_next(GTK_TREE_MODEL(keymodel),
512 &iter));
513 }
514 keywords[kpos] = NULL;
515
516 keywordURI = ECRS_keywordsToUri((const char**)keywords);
517 while (kpos > 0)
518 FREE(keywords[--kpos]);
519 GROW(keywords,
520 ksize,
521 0);
522 spin = glade_xml_get_widget(getMainXML(),
523 "namespaceAnonymityspinbutton");
524 nameLine = glade_xml_get_widget(getMainXML(),
525 "namespaceNameEntry");
526 namespaceName = gtk_entry_get_text(GTK_ENTRY(nameLine));
527 hash("FIXME", 5, &rootEntry); /* FIXME: need to fix glade file! */
528 root = NULL;
529 if (OK == FSUI_createNamespace(ctx,
530 gtk_spin_button_get_value_as_int
531 (GTK_SPIN_BUTTON(spin)),
532 namespaceName,
533 meta,
534 keywordURI,
535 &rootEntry,
536 &root)) {
537 ECRS_getNamespaceId(root,
538 &namespaceId);
539 addTabForNamespace(NULL,
540 namespaceName,
541 &namespaceId,
542 meta,
543 0);
544 } else {
545 /* FIXME: give user feedback on failure! */
546 }
547 ECRS_freeUri(root);
548 ECRS_freeMetaData(meta);
549 ECRS_freeUri(keywordURI);
550 }
551 gtk_widget_destroy(dialog);
552 UNREF(metaXML);
553 metaXML = NULL;
270} 554}
271 555
272void namespaceDelete_clicked(GtkWidget * dummy1, 556void namespaceDelete_clicked(GtkWidget * dummy1,
diff --git a/src/plugins/fs/upload.c b/src/plugins/fs/upload.c
index 140d14cf..a2618809 100644
--- a/src/plugins/fs/upload.c
+++ b/src/plugins/fs/upload.c
@@ -673,7 +673,7 @@ void on_fsinsertuploadbutton_clicked(gpointer dummy,
673 metaXML = NULL; 673 metaXML = NULL;
674} 674}
675 675
676static char *selectFile() { 676static char * selectFile() {
677#ifndef MINGW 677#ifndef MINGW
678 GtkWidget *dialog; 678 GtkWidget *dialog;
679 GladeXML * uploadXML; 679 GladeXML * uploadXML;
@@ -708,14 +708,14 @@ static char *selectFile() {
708 UNREF(uploadXML); 708 UNREF(uploadXML);
709 return ret; 709 return ret;
710#else /* MINGW */ 710#else /* MINGW */
711 return plibc_ChooseDir(_("Choose the file or directory you want to publish."), 711 return plibc_ChooseDir(_("Choose the file or directory you want to publish."),
712 BIF_BROWSEINCLUDEFILES | BIF_USENEWUI | BIF_SHAREABLE | BIF_NONEWFOLDERBUTTON); 712 BIF_BROWSEINCLUDEFILES | BIF_USENEWUI | BIF_SHAREABLE | BIF_NONEWFOLDERBUTTON);
713#endif /* MINGW */ 713#endif /* MINGW */
714} 714}
715 715
716void on_mainFileSharingInsertBrowseButton_clicked(GtkWidget * browseButton, 716void on_mainFileSharingInsertBrowseButton_clicked(GtkWidget * browseButton,
717 gpointer dummy) { 717 gpointer dummy) {
718 char *filename; 718 char *filename;
719 GtkWidget * uploadLine; 719 GtkWidget * uploadLine;
720 GtkWidget * entry; 720 GtkWidget * entry;
721 GtkListStore * model; 721 GtkListStore * model;