aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/fs/content_tracking.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/fs/content_tracking.c')
-rw-r--r--src/plugins/fs/content_tracking.c178
1 files changed, 178 insertions, 0 deletions
diff --git a/src/plugins/fs/content_tracking.c b/src/plugins/fs/content_tracking.c
new file mode 100644
index 00000000..1767432d
--- /dev/null
+++ b/src/plugins/fs/content_tracking.c
@@ -0,0 +1,178 @@
1
2/*
3 This file is part of GNUnet.
4 (C) 2005, 2006 Christian Grothoff (and other contributing authors)
5
6 GNUnet is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published
8 by the Free Software Foundation; either version 2, or (at your
9 option) any later version.
10
11 GNUnet is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNUnet; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.
20*/
21
22/**
23 * @file src/plugins/fs/content_tracking.c
24 * @brief code for tracking available content
25 * @author Christian Grothoff
26 */
27
28#include "platform.h"
29#include "gnunetgtk_common.h"
30#include "fs.h"
31#include "helper.h"
32#include "meta.h"
33#include "namespace.h"
34#include "content_tracking.h"
35#include <GNUnet/gnunet_util_crypto.h>
36#include <GNUnet/gnunet_uritrack_lib.h>
37#include <GNUnet/gnunet_namespace_lib.h>
38#include <extractor.h>
39
40static void * clearContentList(void * mdl) {
41 GtkTreeModel * model = GTK_TREE_MODEL(mdl);
42 struct ECRS_URI * uri;
43 struct ECRS_MetaData * meta;
44 GtkTreeIter iter;
45
46 DEBUG_BEGIN();
47 if (gtk_tree_model_get_iter_first(model,
48 &iter)) {
49 do {
50 gtk_tree_model_get(model,
51 &iter,
52 NAMESPACE_URI, &uri,
53 NAMESPACE_META, &meta,
54 -1);
55 ECRS_freeUri(uri);
56 ECRS_freeMetaData(meta);
57 gtk_list_store_set(GTK_LIST_STORE(model),
58 &iter,
59 NAMESPACE_URI, NULL,
60 NAMESPACE_META, NULL,
61 -1);
62 } while (gtk_list_store_remove(GTK_LIST_STORE(model),
63 &iter));
64 }
65 DEBUG_END();
66 return NULL;
67}
68
69
70void on_clearAvailableContentButton_clicked_fs(GtkWidget * dummy1,
71 GtkWidget * dummy2) {
72 GtkWidget * contentList;
73 GtkTreeModel * model;
74
75 DEBUG_BEGIN();
76 contentList
77 = glade_xml_get_widget(getMainXML(),
78 "availableContentList");
79 model
80 = gtk_tree_view_get_model(GTK_TREE_VIEW(contentList));
81 URITRACK_clearTrackedURIS(ectx,
82 cfg);
83 gtkSaveCall(&clearContentList, model);
84 DEBUG_END();
85}
86
87void on_trackingCheckButton_toggled_fs(GtkWidget * dummy1,
88 GtkWidget * dummy2) {
89 GtkWidget * trackCheckButton;
90
91 trackCheckButton
92 = glade_xml_get_widget(getMainXML(),
93 "trackingCheckButton");
94 URITRACK_trackURIS(ectx,
95 cfg,
96 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(trackCheckButton)) == TRUE ?
97 YES : NO);
98}
99
100
101
102/**
103 * Add the given content to the globally available
104 * content model. Check that it is not already
105 * present!
106 */
107static void * updateView(void * cls) {
108 const ECRS_FileInfo * fi = cls;
109 GtkTreeIter iter;
110 char * filename;
111 char * uriString;
112 unsigned long long size;
113 char * size_h;
114 GtkWidget * contentList;
115 GtkTreeModel * model;
116
117 contentList
118 = glade_xml_get_widget(getMainXML(),
119 "availableContentList");
120 model
121 = gtk_tree_view_get_model(GTK_TREE_VIEW(contentList));
122 filename = ECRS_getFirstFromMetaData(fi->meta,
123 EXTRACTOR_FILENAME,
124 EXTRACTOR_TITLE,
125 EXTRACTOR_DESCRIPTION,
126 EXTRACTOR_SUBJECT,
127 EXTRACTOR_ARTIST,
128 EXTRACTOR_AUTHOR,
129 EXTRACTOR_PUBLISHER,
130 EXTRACTOR_CREATOR,
131 EXTRACTOR_PRODUCER,
132 EXTRACTOR_UNKNOWN,
133 -1);
134 if (filename == NULL) {
135 filename = STRDUP(_("no name given"));
136 } else {
137 char * dotdot;
138
139 while (NULL != (dotdot = strstr(filename, "..")))
140 dotdot[0] = dotdot[1] = '_';
141 filename = validate_utf8(filename);
142 }
143
144 if (ECRS_isFileUri(fi->uri))
145 size = ECRS_fileSize(fi->uri);
146 else
147 size = 0;
148 uriString = ECRS_uriToString(fi->uri);
149 gtk_list_store_append(GTK_LIST_STORE(model),
150 &iter);
151 size_h = string_get_fancy_byte_size(size);
152 gtk_list_store_set(GTK_LIST_STORE(model),
153 &iter,
154 NAMESPACE_FILENAME, filename,
155 NAMESPACE_SIZE, size,
156 NAMESPACE_HSIZE, size_h,
157 NAMESPACE_URISTRING, uriString,
158 NAMESPACE_URI, ECRS_dupUri(fi->uri),
159 NAMESPACE_META, ECRS_dupMetaData(fi->meta),
160 -1);
161 FREE(size_h);
162 FREE(filename);
163 FREE(uriString);
164 return NULL;
165}
166
167/**
168 * Add the given content to the globally available
169 * content model. Check that it is not already
170 * present!
171 */
172int updateViewSave(const ECRS_FileInfo * fi,
173 const HashCode512 * key,
174 int isRoot,
175 void * closure) {
176 gtkSaveCall(&updateView, (void*) fi);
177 return OK;
178}