aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/fs/collection.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/fs/collection.c')
-rw-r--r--src/plugins/fs/collection.c231
1 files changed, 219 insertions, 12 deletions
diff --git a/src/plugins/fs/collection.c b/src/plugins/fs/collection.c
index df1ca7f6..144840ac 100644
--- a/src/plugins/fs/collection.c
+++ b/src/plugins/fs/collection.c
@@ -30,25 +30,232 @@
30#include "collection.h" 30#include "collection.h"
31#include <extractor.h> 31#include <extractor.h>
32 32
33void create_collection_clicked(GtkWidget * dummy1, 33static GladeXML * metaXML;
34 GtkWidget * dummy2) { 34
35 /* 35
36 FSUI_startCollection(ctx, 36
37 unsigned int anonymityLevel, 37/**
38 cron_t updateInterval, 38 * FIXME: somehow this function is not called
39 const char * name, 39 * when the button is clicked.
40 const struct ECRS_MetaData * meta);
41 */ 40 */
41void
42on_collectionDialogMetaDataAddButton_clicked(gpointer dummy,
43 GtkWidget * uploadButton) {
44 GtkWidget * metaList;
45 GtkWidget * entryLine;
46 GtkWidget * typeCB;
47 const char * value;
48 EXTRACTOR_KeywordType type;
49 GtkListStore * metamodel;
50 GtkListStore * typemodel;
51 GtkTreeIter iter;
52 char * stype;
53
54 metaList = glade_xml_get_widget(metaXML,
55 "collectionMetaDataTreeView");
56 metamodel
57 = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(metaList)));
58
59 entryLine = glade_xml_get_widget(metaXML,
60 "collectionMetaDataValueEntry");
61 value = gtk_entry_get_text(GTK_ENTRY(entryLine));
62 typeCB = glade_xml_get_widget(metaXML,
63 "collectionMetaDataTypeComboBox");
64 typemodel
65 = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(typeCB)));
66 if (! gtk_combo_box_get_active_iter(GTK_COMBO_BOX(typeCB),
67 &iter))
68 return; /* oops */
69 gtk_tree_model_get(GTK_TREE_MODEL(typemodel),
70 &iter,
71 META_STYPE, &stype,
72 META_TYPE, &type,
73 -1);
74 gtk_list_store_append(metamodel,
75 &iter);
76 gtk_list_store_set(metamodel,
77 &iter,
78 META_TYPE, type,
79 META_STYPE, stype,
80 META_VALUE, value,
81 -1);
82 gtk_entry_set_text(GTK_ENTRY(entryLine), "");
42} 83}
43 84
44void collectionDelete_clicked(GtkWidget * dummy1, 85
86void createCollection_clicked(GtkWidget * dummy1,
87 GtkWidget * dummy2) {
88 GtkWidget * w;
89 const char * collectionName;
90 GtkWidget * nameLine;
91 GtkWidget * metaList;
92 GtkWidget * dialog;
93 GtkWidget * metaType;
94 GtkWidget * spin;
95 GtkListStore * metamodel;
96 GtkCellRenderer * renderer;
97 GtkListStore * keywordTypeModel;
98 GtkTreeIter iter;
99 struct ECRS_MetaData * meta;
100 EXTRACTOR_KeywordType type;
101 const char * stype;
102 char * mvalue;
103 struct ECRS_URI * root;
104 cron_t updateInterval;
105 const char * updateIntervalString;
106
107 metaXML
108 = glade_xml_new(getGladeFileName(),
109 "createCollectionDialog",
110 NULL);
111 connectGladeWithPlugins(metaXML);
112 dialog = glade_xml_get_widget(metaXML,
113 "createCollectionDialog");
114 metamodel
115 = gtk_list_store_new(META_NUM,
116 G_TYPE_INT,
117 G_TYPE_STRING,
118 G_TYPE_STRING);
119 metaList = glade_xml_get_widget(metaXML,
120 "collectionMetaDataTreeView");
121 renderer = gtk_cell_renderer_text_new();
122 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(metaList),
123 -1,
124 _("Category"),
125 renderer,
126 "text", META_STYPE,
127 NULL);
128 renderer = gtk_cell_renderer_text_new();
129 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(metaList),
130 -1,
131 _("Value"),
132 renderer,
133 "text", META_VALUE,
134 NULL);
135 gtk_tree_view_set_model(GTK_TREE_VIEW(metaList),
136 GTK_TREE_MODEL(metamodel));
137 keywordTypeModel
138 = gtk_list_store_new(KTYPE_NUM,
139 G_TYPE_STRING,
140 G_TYPE_INT);
141 metaType
142 = glade_xml_get_widget(metaXML,
143 "collectionMetaTypeComboBox");
144 gtk_combo_box_set_model(GTK_COMBO_BOX(metaType),
145 GTK_TREE_MODEL(keywordTypeModel));
146 for (type=0;type<EXTRACTOR_getHighestKeywordTypeNumber();type++) {
147 stype = EXTRACTOR_getKeywordTypeAsString(type);
148 gtk_list_store_append(keywordTypeModel,
149 &iter);
150 gtk_list_store_set(keywordTypeModel,
151 &iter,
152 KTYPE_STRING, stype,
153 KTYPE_TYPE, type,
154 -1);
155 }
156 renderer = gtk_cell_renderer_text_new();
157 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(metaType),
158 renderer,
159 FALSE);
160 gtk_cell_layout_add_attribute(GTK_CELL_LAYOUT(metaType),
161 renderer,
162 "text", KTYPE_STRING);
163 gtk_combo_box_set_active(GTK_COMBO_BOX(metaType),
164 0);
165 gtk_dialog_set_default_response(GTK_DIALOG(dialog),
166 GTK_RESPONSE_OK);
167 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) {
168 meta = ECRS_createMetaData();
169 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(metamodel),
170 &iter)) {
171 do {
172 gtk_tree_model_get(GTK_TREE_MODEL(metamodel),
173 &iter,
174 META_TYPE, &type,
175 META_VALUE, &mvalue,
176 -1);
177 ECRS_addToMetaData(meta,
178 type,
179 mvalue);
180 } while (gtk_tree_model_iter_next(GTK_TREE_MODEL(metamodel),
181 &iter));
182 }
183 spin = glade_xml_get_widget(metaXML,
184 "collectionAnonymityLevel");
185 nameLine
186 = glade_xml_get_widget(metaXML,
187 "collectionUpdateIntervalComboBoxEntry");
188 nameLine
189 = gtk_bin_get_child(GTK_BIN(nameLine));
190 updateIntervalString
191 = gtk_entry_get_text(GTK_ENTRY(nameLine));
192 updateInterval = 0; /* FIXME */
193 nameLine = glade_xml_get_widget(metaXML,
194 "collectionIdentifierEntry");
195 collectionName
196 = gtk_entry_get_text(GTK_ENTRY(nameLine));
197 root = NULL;
198 if (OK == FSUI_startCollection(ctx,
199 gtk_spin_button_get_value_as_int
200 (GTK_SPIN_BUTTON(spin)),
201 updateInterval,
202 collectionName,
203 meta)) {
204 w = glade_xml_get_widget(getMainXML(),
205 "createCollection");
206 gtk_widget_set_sensitive(w, FALSE);
207 w = glade_xml_get_widget(getMainXML(),
208 "deleteCollection");
209 gtk_widget_set_sensitive(w, TRUE);
210 } else {
211 GtkWidget * dialog;
212
213 dialog = gtk_message_dialog_new
214 (NULL,
215 GTK_DIALOG_MODAL,
216 GTK_MESSAGE_ERROR,
217 GTK_BUTTONS_CLOSE,
218 _("Failed to start collection '%s' (consult logs)."),
219 collectionName);
220 gtk_dialog_run(GTK_DIALOG(dialog));
221 gtk_widget_destroy(dialog);
222 }
223 ECRS_freeMetaData(meta);
224 }
225 gtk_widget_destroy(dialog);
226 UNREF(metaXML);
227 metaXML = NULL;
228}
229
230void deleteCollection_clicked(GtkWidget * dummy1,
45 GtkWidget * dummy2) { 231 GtkWidget * dummy2) {
46 FSUI_stopCollection(ctx); 232 GtkWidget * w;
47 /* fixme: disable stop collection button, 233
48 enable start collection button! */ 234 if (OK == FSUI_stopCollection(ctx)) {
235 w = glade_xml_get_widget(getMainXML(),
236 "createCollection");
237 gtk_widget_set_sensitive(w, TRUE);
238 w = glade_xml_get_widget(getMainXML(),
239 "deleteCollection");
240 gtk_widget_set_sensitive(w, FALSE);
241 infoMessage(NO,
242 _("Collection stopped.\n"));
243 } else {
244 infoMessage(YES,
245 _("Failed to stop collection (consult logs).\n"));
246 }
49} 247}
50 248
51void fs_collection_start() { 249void fs_collection_start() {
250 GtkWidget * w;
251
252 if (NULL != FSUI_getCollection(ctx))
253 w = glade_xml_get_widget(getMainXML(),
254 "createCollection");
255 else
256 w = glade_xml_get_widget(getMainXML(),
257 "deleteCollection");
258 gtk_widget_set_sensitive(w, FALSE);
52} 259}
53 260
54void fs_collection_stop() { 261void fs_collection_stop() {