diff options
author | Christian Grothoff <christian@grothoff.org> | 2005-08-18 06:26:31 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2005-08-18 06:26:31 +0000 |
commit | d2c6d0251c1161da66345924a6c69b6db920ec79 (patch) | |
tree | 7a6ef7a73bbf90a5b2243f165e2d8e32da1ab564 | |
parent | cdeeaedbca63cbc5f3d030f09963f8056c6e5e67 (diff) | |
download | gnunet-gtk-d2c6d0251c1161da66345924a6c69b6db920ec79.tar.gz gnunet-gtk-d2c6d0251c1161da66345924a6c69b6db920ec79.zip |
various bugfixes, including mantis 867
-rw-r--r-- | src/common/helper.c | 4 | ||||
-rw-r--r-- | src/plugins/fs/download.c | 190 | ||||
-rw-r--r-- | src/plugins/fs/fs.c | 4 | ||||
-rw-r--r-- | src/plugins/fs/fs.h | 1 | ||||
-rw-r--r-- | src/plugins/fs/meta.c | 2 | ||||
-rw-r--r-- | src/plugins/fs/search.c | 1 | ||||
-rw-r--r-- | src/plugins/stats/functions.c | 3 |
7 files changed, 121 insertions, 84 deletions
diff --git a/src/common/helper.c b/src/common/helper.c index 5dba8ad3..f311f7cd 100644 --- a/src/common/helper.c +++ b/src/common/helper.c | |||
@@ -416,7 +416,7 @@ void doneGNUnetGTKCommon() { | |||
416 | Plugin * next; | 416 | Plugin * next; |
417 | 417 | ||
418 | next = plugin->next; | 418 | next = plugin->next; |
419 | unloadPlugin(plugin); | 419 | unloadPlugin(plugin); |
420 | plugin = next; | 420 | plugin = next; |
421 | } | 421 | } |
422 | 422 | ||
@@ -434,7 +434,7 @@ void doneGNUnetGTKCommon() { | |||
434 | for (i=0;i<pscCount;i++) | 434 | for (i=0;i<pscCount;i++) |
435 | psc[i]->func(psc[i]); | 435 | psc[i]->func(psc[i]); |
436 | i = pscCount; | 436 | i = pscCount; |
437 | MUTEX_UNLOCK(&sclock); | 437 | MUTEX_UNLOCK(&sclock); |
438 | /* wait until all PSC-jobs have left | 438 | /* wait until all PSC-jobs have left |
439 | the gtkSaveCall method before destroying | 439 | the gtkSaveCall method before destroying |
440 | the mutex! */ | 440 | the mutex! */ |
diff --git a/src/plugins/fs/download.c b/src/plugins/fs/download.c index f627dfb1..ab03525a 100644 --- a/src/plugins/fs/download.c +++ b/src/plugins/fs/download.c | |||
@@ -71,6 +71,7 @@ static int addFilesToDirectory | |||
71 | gtk_tree_model_get_iter(GTK_TREE_MODEL(pos->model), | 71 | gtk_tree_model_get_iter(GTK_TREE_MODEL(pos->model), |
72 | &iter, | 72 | &iter, |
73 | path); | 73 | path); |
74 | gtk_tree_path_free(path); | ||
74 | for (i=gtk_tree_model_iter_n_children(pos->model, | 75 | for (i=gtk_tree_model_iter_n_children(pos->model, |
75 | &iter)-1;i>=0;i--) { | 76 | &iter)-1;i>=0;i--) { |
76 | if (TRUE == gtk_tree_model_iter_nth_child(pos->model, | 77 | if (TRUE == gtk_tree_model_iter_nth_child(pos->model, |
@@ -108,11 +109,12 @@ static void initiateDownload(GtkTreeModel * model, | |||
108 | struct ECRS_MetaData * meta; | 109 | struct ECRS_MetaData * meta; |
109 | char * filename; | 110 | char * filename; |
110 | char * pfx; | 111 | char * pfx; |
112 | char * lnk; | ||
111 | char * fn; | 113 | char * fn; |
112 | DownloadList * list; | 114 | DownloadList * list; |
113 | GtkTreeIter iiter; | 115 | GtkTreeIter iiter; |
114 | GtkWidget * spin; | 116 | GtkWidget * spin; |
115 | char * name; | 117 | const char * name; |
116 | struct stat sbuf; | 118 | struct stat sbuf; |
117 | unsigned int anon; | 119 | unsigned int anon; |
118 | 120 | ||
@@ -127,7 +129,6 @@ static void initiateDownload(GtkTreeModel * model, | |||
127 | -1); | 129 | -1); |
128 | if (uri == NULL) { | 130 | if (uri == NULL) { |
129 | BREAK(); | 131 | BREAK(); |
130 | FREENONNULL(name); | ||
131 | return; | 132 | return; |
132 | } | 133 | } |
133 | filename = ECRS_uriToString(uri); | 134 | filename = ECRS_uriToString(uri); |
@@ -136,17 +137,16 @@ static void initiateDownload(GtkTreeModel * model, | |||
136 | strlen(ECRS_URI_PREFIX) + | 137 | strlen(ECRS_URI_PREFIX) + |
137 | strlen(ECRS_FILE_INFIX)) ) { | 138 | strlen(ECRS_FILE_INFIX)) ) { |
138 | BREAK(); | 139 | BREAK(); |
139 | FREENONNULL(name); | ||
140 | FREENONNULL(filename); | 140 | FREENONNULL(filename); |
141 | return; | 141 | return; |
142 | } | 142 | } |
143 | if (name == NULL) | 143 | if (name == NULL) |
144 | name = STRDUP(_("unnamed")); | 144 | name = filename; |
145 | list = MALLOC(sizeof(DownloadList)); | 145 | list = MALLOC(sizeof(DownloadList)); |
146 | list->next = head; | 146 | list->next = head; |
147 | list->rr = NULL; | 147 | list->rr = NULL; |
148 | list->model = NULL; | 148 | list->model = NULL; |
149 | if (ECRS_isDirectory(meta)) { | 149 | if (YES == ECRS_isDirectory(meta)) { |
150 | list->rr = gtk_tree_row_reference_new(model, path); | 150 | list->rr = gtk_tree_row_reference_new(model, path); |
151 | list->model = model; | 151 | list->model = model; |
152 | } | 152 | } |
@@ -157,53 +157,41 @@ static void initiateDownload(GtkTreeModel * model, | |||
157 | " in section '%s' under '%s'.")); | 157 | " in section '%s' under '%s'.")); |
158 | mkdirp(fn); | 158 | mkdirp(fn); |
159 | pfx = MALLOC(strlen(fn) + 2 + | 159 | pfx = MALLOC(strlen(fn) + 2 + |
160 | strlen(filename) + strlen(name)); | 160 | strlen(name)); |
161 | lnk = MALLOC(strlen(fn) + 2 + | ||
162 | strlen(filename)); | ||
161 | strcpy(pfx, fn); | 163 | strcpy(pfx, fn); |
162 | strcat(pfx, | 164 | if (pfx[strlen(pfx)-1] != DIR_SEPARATOR) |
163 | DIR_SEPARATOR_STR); | 165 | strcat(pfx, |
166 | DIR_SEPARATOR_STR); | ||
167 | strcpy(lnk, fn); | ||
168 | FREE(fn); | ||
169 | if (lnk[strlen(lnk)-1] != DIR_SEPARATOR) | ||
170 | strcat(lnk, | ||
171 | DIR_SEPARATOR_STR); | ||
164 | strcat(pfx, | 172 | strcat(pfx, |
165 | name); | 173 | name); |
166 | while ( (strlen(pfx) > 0) && | 174 | strcat(lnk, |
167 | (pfx[strlen(pfx)-1] == DIR_SEPARATOR) ) | 175 | &filename[strlen(ECRS_URI_PREFIX) + |
168 | pfx[strlen(pfx)-1] = '\0'; | 176 | strlen(ECRS_FILE_INFIX)]); |
169 | if (0 == STAT(pfx, | 177 | if (0 != STAT(pfx, |
170 | &sbuf)) { | 178 | &sbuf)) { |
171 | GtkWidget * dialog; | 179 | if (0 != SYMLINK(lnk, pfx)) |
172 | 180 | LOG_FILE_STRERROR(LOG_ERROR, "symlink", pfx); | |
173 | dialog = gtk_message_dialog_new | 181 | } else { |
174 | (NULL, | 182 | FREE(pfx); |
175 | GTK_DIALOG_MODAL, | 183 | pfx = STRDUP(lnk); |
176 | GTK_MESSAGE_WARNING, | ||
177 | GTK_BUTTONS_CLOSE, | ||
178 | _("File '%s' exists in '%s',\n" | ||
179 | "will store download under its" | ||
180 | " GNUnet URI '%s' instead.\n"), | ||
181 | name, | ||
182 | fn, | ||
183 | &filename[strlen(ECRS_URI_PREFIX) + | ||
184 | strlen(ECRS_FILE_INFIX)]); | ||
185 | gtk_dialog_run(GTK_DIALOG(dialog)); | ||
186 | gtk_widget_destroy(dialog); | ||
187 | strcpy(pfx, fn); | ||
188 | strcat(pfx, | ||
189 | DIR_SEPARATOR_STR); | ||
190 | strcat(pfx, | ||
191 | &filename[strlen(ECRS_URI_PREFIX) + | ||
192 | strlen(ECRS_FILE_INFIX)]); | ||
193 | } | 184 | } |
194 | FREE(fn); | ||
195 | |||
196 | |||
197 | list->filename = pfx; | 185 | list->filename = pfx; |
198 | head = list; | 186 | head = list; |
199 | |||
200 | gtk_tree_store_insert(summary, | 187 | gtk_tree_store_insert(summary, |
201 | &iiter, | 188 | &iiter, |
202 | NULL, | 189 | NULL, |
203 | 0); | 190 | 0); |
204 | gtk_tree_store_set(summary, | 191 | gtk_tree_store_set(summary, |
205 | &iiter, | 192 | &iiter, |
206 | DOWNLOAD_FILENAME, name, | 193 | DOWNLOAD_FILENAME, lnk, |
194 | DOWNLOAD_LINKNAME, pfx, | ||
207 | DOWNLOAD_SIZE, ECRS_fileSize(uri), | 195 | DOWNLOAD_SIZE, ECRS_fileSize(uri), |
208 | DOWNLOAD_PROGRESS, 0, /* progress */ | 196 | DOWNLOAD_PROGRESS, 0, /* progress */ |
209 | DOWNLOAD_URISTRING, filename, | 197 | DOWNLOAD_URISTRING, filename, |
@@ -212,7 +200,6 @@ static void initiateDownload(GtkTreeModel * model, | |||
212 | /* internal: row reference! */ | 200 | /* internal: row reference! */ |
213 | -1); | 201 | -1); |
214 | FREE(filename); | 202 | FREE(filename); |
215 | FREE(name); | ||
216 | spin = getAnonymityButtonFromTM(model); | 203 | spin = getAnonymityButtonFromTM(model); |
217 | if (spin == NULL) { | 204 | if (spin == NULL) { |
218 | BREAK(); | 205 | BREAK(); |
@@ -220,12 +207,12 @@ static void initiateDownload(GtkTreeModel * model, | |||
220 | } else { | 207 | } else { |
221 | anon = gtk_spin_button_get_value_as_int | 208 | anon = gtk_spin_button_get_value_as_int |
222 | (GTK_SPIN_BUTTON(spin)); | 209 | (GTK_SPIN_BUTTON(spin)); |
223 | } | 210 | } |
224 | |||
225 | FSUI_startDownload(ctx, | 211 | FSUI_startDownload(ctx, |
226 | anon, | 212 | anon, |
227 | uri, | 213 | uri, |
228 | pfx); | 214 | lnk); |
215 | FREE(lnk); | ||
229 | } | 216 | } |
230 | 217 | ||
231 | void on_downloadButton_clicked(GtkWidget * treeview, | 218 | void on_downloadButton_clicked(GtkWidget * treeview, |
@@ -290,12 +277,17 @@ void displayDownloadUpdate(const struct ECRS_URI * uri, | |||
290 | void displayDownloadComplete(const struct ECRS_URI * uri, | 277 | void displayDownloadComplete(const struct ECRS_URI * uri, |
291 | const char * filename) { | 278 | const char * filename) { |
292 | char * ren; | 279 | char * ren; |
280 | const char * fn; | ||
281 | const char * ln; | ||
293 | unsigned long long size; | 282 | unsigned long long size; |
294 | char * data; | 283 | char * data; |
295 | int fd; | 284 | int fd; |
296 | struct ECRS_MetaData * meta; | 285 | struct ECRS_MetaData * meta; |
297 | DownloadList * pos; | 286 | DownloadList * pos; |
298 | 287 | GtkTreeIter iter; | |
288 | GtkTreePath * path; | ||
289 | struct ECRS_URI * u; | ||
290 | |||
299 | pos = head; | 291 | pos = head; |
300 | while (pos != NULL) { | 292 | while (pos != NULL) { |
301 | if (ECRS_equalsUri(uri, | 293 | if (ECRS_equalsUri(uri, |
@@ -303,40 +295,80 @@ void displayDownloadComplete(const struct ECRS_URI * uri, | |||
303 | break; | 295 | break; |
304 | pos = pos->next; | 296 | pos = pos->next; |
305 | } | 297 | } |
306 | 298 | if (pos == NULL) | |
307 | ren = ECRS_suggestFilename(filename); | ||
308 | if (ren == NULL) | ||
309 | return; | 299 | return; |
310 | if (0 != strcmp(ren, | 300 | if ( (pos->rr != NULL) && |
311 | filename)) { | 301 | (gtk_tree_row_reference_valid(pos->rr)) ) { |
312 | /* fixme: ask user for confirmation? */ | 302 | |
313 | /* rename(filename, ren); */ | 303 | /* update directory view (if applicable!) */ |
314 | } | 304 | if (OK == getFileSize(filename, &size)) { |
315 | FREE(ren); | 305 | fd = fileopen(filename, O_RDONLY); |
316 | /* fixme: also update download model? */ | 306 | data = MMAP(NULL, |
317 | /* update directory view (if applicable!) */ | 307 | size, |
318 | if ( (pos != NULL) && | 308 | PROT_READ, |
319 | (pos->rr != NULL) && | 309 | MAP_SHARED, |
320 | (OK == getFileSize(filename, &size)) ) { | 310 | fd, |
321 | fd = fileopen(filename, O_RDONLY); | 311 | 0); |
322 | data = MMAP(NULL, | 312 | meta = NULL; |
323 | size, | 313 | if (data != NULL) { |
324 | PROT_READ, | 314 | ECRS_listDirectory(data, |
325 | MAP_SHARED, | 315 | size, |
326 | fd, | 316 | &meta, |
327 | 0); | 317 | &addFilesToDirectory, |
328 | meta = NULL; | 318 | (void*)uri); |
329 | if (data != NULL) { | 319 | MUNMAP(data, size); |
330 | ECRS_listDirectory(data, | 320 | } |
331 | size, | 321 | CLOSE(fd); |
332 | &meta, | 322 | if (meta != NULL) |
333 | &addFilesToDirectory, | 323 | ECRS_freeMetaData(meta); |
334 | (void*)uri); | ||
335 | MUNMAP(data, size); | ||
336 | } | 324 | } |
337 | CLOSE(fd); | 325 | |
338 | if (meta != NULL) | 326 | path = gtk_tree_row_reference_get_path(pos->rr); |
339 | ECRS_freeMetaData(meta); | 327 | if (gtk_tree_path_get_depth(path) > 1) { |
328 | gtk_tree_path_free(path); | ||
329 | return; | ||
330 | } | ||
331 | gtk_tree_path_free(path); | ||
332 | } | ||
333 | |||
334 | /* only rename top-level files, not files inside of directories! */ | ||
335 | if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(summary), | ||
336 | &iter)) { | ||
337 | do { | ||
338 | ln = NULL; | ||
339 | fn = NULL; | ||
340 | gtk_tree_model_get(GTK_TREE_MODEL(summary), | ||
341 | &iter, | ||
342 | DOWNLOAD_URI, &u, | ||
343 | DOWNLOAD_FILENAME, &fn, | ||
344 | DOWNLOAD_LINKNAME, &ln, | ||
345 | -1); | ||
346 | if (ECRS_equalsUri(u, uri)) { | ||
347 | ren = ECRS_suggestFilename(ln); | ||
348 | if (ren != NULL) { | ||
349 | gtk_tree_store_set(summary, | ||
350 | &iter, | ||
351 | DOWNLOAD_LINKNAME, ren, | ||
352 | -1); | ||
353 | if (0 == strcmp(fn, ln)) { | ||
354 | /* keep the actual data under the URI name | ||
355 | and create a symlink */ | ||
356 | if (0 != RENAME(ren, fn)) | ||
357 | LOG(LOG_ERROR, | ||
358 | _("Renaming of file '%s' to '%s' failed: %s\n"), | ||
359 | ren, | ||
360 | fn, | ||
361 | STRERROR(errno)); | ||
362 | else | ||
363 | if (0 != SYMLINK(fn, ren)) | ||
364 | LOG_FILE_STRERROR(LOG_ERROR, "symlink", ren); | ||
365 | } | ||
366 | FREE(ren); | ||
367 | } | ||
368 | break; | ||
369 | } | ||
370 | } while (gtk_tree_model_iter_next(GTK_TREE_MODEL(summary), | ||
371 | &iter)); | ||
340 | } | 372 | } |
341 | 373 | ||
342 | } | 374 | } |
@@ -440,6 +472,7 @@ static int addDownloadView(void * cls, | |||
440 | gtk_tree_store_set(summary, | 472 | gtk_tree_store_set(summary, |
441 | &iiter, | 473 | &iiter, |
442 | DOWNLOAD_FILENAME, filename, | 474 | DOWNLOAD_FILENAME, filename, |
475 | DOWNLOAD_LINKNAME, filename, | ||
443 | DOWNLOAD_SIZE, filesize, | 476 | DOWNLOAD_SIZE, filesize, |
444 | DOWNLOAD_PROGRESS, progress, | 477 | DOWNLOAD_PROGRESS, progress, |
445 | DOWNLOAD_URISTRING, uriname, | 478 | DOWNLOAD_URISTRING, uriname, |
@@ -460,7 +493,8 @@ void fs_download_start() { | |||
460 | "activeDownloadsList"); | 493 | "activeDownloadsList"); |
461 | summary = | 494 | summary = |
462 | gtk_tree_store_new(DOWNLOAD_NUM, | 495 | gtk_tree_store_new(DOWNLOAD_NUM, |
463 | G_TYPE_STRING, /* name */ | 496 | G_TYPE_STRING, /* name (URI as string) */ |
497 | G_TYPE_STRING, /* name (user-friendly name) */ | ||
464 | G_TYPE_UINT64, /* size */ | 498 | G_TYPE_UINT64, /* size */ |
465 | G_TYPE_INT, /* progress */ | 499 | G_TYPE_INT, /* progress */ |
466 | G_TYPE_STRING, /* uri */ | 500 | G_TYPE_STRING, /* uri */ |
@@ -474,7 +508,7 @@ void fs_download_start() { | |||
474 | _("Name"), | 508 | _("Name"), |
475 | renderer, | 509 | renderer, |
476 | "value", DOWNLOAD_PROGRESS, | 510 | "value", DOWNLOAD_PROGRESS, |
477 | "text", DOWNLOAD_FILENAME, | 511 | "text", DOWNLOAD_LINKNAME, |
478 | NULL); | 512 | NULL); |
479 | renderer = gtk_cell_renderer_text_new(); | 513 | renderer = gtk_cell_renderer_text_new(); |
480 | gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(downloadList), | 514 | gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(downloadList), |
diff --git a/src/plugins/fs/fs.c b/src/plugins/fs/fs.c index 4e4b779f..1f68b36e 100644 --- a/src/plugins/fs/fs.c +++ b/src/plugins/fs/fs.c | |||
@@ -58,14 +58,10 @@ static void saveEventProcessor(void * arg) { | |||
58 | event->data.DownloadProgress.completed, | 58 | event->data.DownloadProgress.completed, |
59 | event->data.DownloadProgress.last_block, | 59 | event->data.DownloadProgress.last_block, |
60 | event->data.DownloadProgress.last_size); | 60 | event->data.DownloadProgress.last_size); |
61 | /* FIXME: | ||
62 | if directory, also update search view! */ | ||
63 | break; | 61 | break; |
64 | case FSUI_download_complete: | 62 | case FSUI_download_complete: |
65 | displayDownloadComplete(event->data.DownloadProgress.uri, | 63 | displayDownloadComplete(event->data.DownloadProgress.uri, |
66 | event->data.DownloadProgress.filename); | 64 | event->data.DownloadProgress.filename); |
67 | /* FIXME: | ||
68 | if directory, also update search view! */ | ||
69 | break; | 65 | break; |
70 | case FSUI_download_error: | 66 | case FSUI_download_error: |
71 | BREAK(); | 67 | BREAK(); |
diff --git a/src/plugins/fs/fs.h b/src/plugins/fs/fs.h index 896fb659..7e9b4064 100644 --- a/src/plugins/fs/fs.h +++ b/src/plugins/fs/fs.h | |||
@@ -51,6 +51,7 @@ enum { | |||
51 | 51 | ||
52 | enum { | 52 | enum { |
53 | DOWNLOAD_FILENAME = 0, | 53 | DOWNLOAD_FILENAME = 0, |
54 | DOWNLOAD_LINKNAME, | ||
54 | DOWNLOAD_SIZE, | 55 | DOWNLOAD_SIZE, |
55 | DOWNLOAD_PROGRESS, | 56 | DOWNLOAD_PROGRESS, |
56 | DOWNLOAD_URISTRING, | 57 | DOWNLOAD_URISTRING, |
diff --git a/src/plugins/fs/meta.c b/src/plugins/fs/meta.c index fdb07351..f5361266 100644 --- a/src/plugins/fs/meta.c +++ b/src/plugins/fs/meta.c | |||
@@ -106,6 +106,7 @@ void createMetaDataListTreeView(GladeXML * xml, | |||
106 | ts, | 106 | ts, |
107 | NULL); | 107 | NULL); |
108 | pixbuf = gdk_pixbuf_loader_get_pixbuf(loader); | 108 | pixbuf = gdk_pixbuf_loader_get_pixbuf(loader); |
109 | g_object_ref(pixbuf); | ||
109 | gdk_pixbuf_loader_close(loader, | 110 | gdk_pixbuf_loader_close(loader, |
110 | NULL); | 111 | NULL); |
111 | if (pixbuf != NULL) { | 112 | if (pixbuf != NULL) { |
@@ -113,6 +114,7 @@ void createMetaDataListTreeView(GladeXML * xml, | |||
113 | pixbuf); | 114 | pixbuf); |
114 | g_object_unref(pixbuf); | 115 | g_object_unref(pixbuf); |
115 | } | 116 | } |
117 | UNREF(loader); | ||
116 | } | 118 | } |
117 | } | 119 | } |
118 | 120 | ||
diff --git a/src/plugins/fs/search.c b/src/plugins/fs/search.c index a01d1387..aae676e3 100644 --- a/src/plugins/fs/search.c +++ b/src/plugins/fs/search.c | |||
@@ -111,6 +111,7 @@ void addEntryToSearchTree(GtkTreeStore * model, | |||
111 | pixbuf = gdk_pixbuf_loader_get_pixbuf(loader); | 111 | pixbuf = gdk_pixbuf_loader_get_pixbuf(loader); |
112 | gdk_pixbuf_loader_close(loader, | 112 | gdk_pixbuf_loader_close(loader, |
113 | NULL); | 113 | NULL); |
114 | g_object_ref(pixbuf); | ||
114 | UNREF(loader); | 115 | UNREF(loader); |
115 | } else { | 116 | } else { |
116 | pixbuf = NULL; | 117 | pixbuf = NULL; |
diff --git a/src/plugins/stats/functions.c b/src/plugins/stats/functions.c index b54780df..84d03aa6 100644 --- a/src/plugins/stats/functions.c +++ b/src/plugins/stats/functions.c | |||
@@ -405,6 +405,9 @@ void done_functions() { | |||
405 | NULL); | 405 | NULL); |
406 | MUTEX_DESTROY(&lock); | 406 | MUTEX_DESTROY(&lock); |
407 | releaseClientSocket(sock); | 407 | releaseClientSocket(sock); |
408 | GROW(lastStatValues, | ||
409 | lsv_size, | ||
410 | 0); | ||
408 | sock = NULL; | 411 | sock = NULL; |
409 | } | 412 | } |
410 | 413 | ||