diff options
author | Christian Grothoff <christian@grothoff.org> | 2007-07-10 09:01:06 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2007-07-10 09:01:06 +0000 |
commit | ce124c66c8aff19abaa695a16127a742050d01b4 (patch) | |
tree | ec813c1b394f5566655fa6ff52cfba45a14847d7 | |
parent | b2f6fe964b05c6995bcb50ebe29cf25f1c185f84 (diff) | |
download | gnunet-gtk-ce124c66c8aff19abaa695a16127a742050d01b4.tar.gz gnunet-gtk-ce124c66c8aff19abaa695a16127a742050d01b4.zip |
indent
41 files changed, 8870 insertions, 9504 deletions
diff --git a/libltdl/ltdl.c b/libltdl/ltdl.c index 60feb043..8ad947dc 100644 --- a/libltdl/ltdl.c +++ b/libltdl/ltdl.c | |||
@@ -131,10 +131,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | |||
131 | #if WITH_DMALLOC | 131 | #if WITH_DMALLOC |
132 | # include <dmalloc.h> | 132 | # include <dmalloc.h> |
133 | #endif | 133 | #endif |
134 | |||
134 | 135 | ||
135 | 136 | ||
136 | 137 | ||
137 | |||
138 | /* --- WINDOWS SUPPORT --- */ | 138 | /* --- WINDOWS SUPPORT --- */ |
139 | 139 | ||
140 | 140 | ||
@@ -162,7 +162,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | |||
162 | struct dirent | 162 | struct dirent |
163 | { | 163 | { |
164 | char d_name[2048]; | 164 | char d_name[2048]; |
165 | int d_namlen; | 165 | int d_namlen; |
166 | }; | 166 | }; |
167 | 167 | ||
168 | typedef struct _DIR | 168 | typedef struct _DIR |
@@ -174,8 +174,8 @@ typedef struct _DIR | |||
174 | } DIR; | 174 | } DIR; |
175 | 175 | ||
176 | #endif /* LT_USE_WINDOWS_DIRENT_EMULATION */ | 176 | #endif /* LT_USE_WINDOWS_DIRENT_EMULATION */ |
177 | |||
178 | 177 | ||
178 | |||
179 | /* --- MANIFEST CONSTANTS --- */ | 179 | /* --- MANIFEST CONSTANTS --- */ |
180 | 180 | ||
181 | 181 | ||
@@ -199,30 +199,32 @@ typedef struct _DIR | |||
199 | /* This accounts for the _LTX_ separator */ | 199 | /* This accounts for the _LTX_ separator */ |
200 | #undef LT_SYMBOL_OVERHEAD | 200 | #undef LT_SYMBOL_OVERHEAD |
201 | #define LT_SYMBOL_OVERHEAD 5 | 201 | #define LT_SYMBOL_OVERHEAD 5 |
202 | |||
202 | 203 | ||
203 | 204 | ||
204 | 205 | ||
205 | |||
206 | /* --- MEMORY HANDLING --- */ | 206 | /* --- MEMORY HANDLING --- */ |
207 | 207 | ||
208 | 208 | ||
209 | /* These are the functions used internally. In addition to making | 209 | /* These are the functions used internally. In addition to making |
210 | use of the associated function pointers above, they also perform | 210 | use of the associated function pointers above, they also perform |
211 | error handling. */ | 211 | error handling. */ |
212 | static char *lt_estrdup LT_PARAMS((const char *str)); | 212 | static char *lt_estrdup LT_PARAMS ((const char *str)); |
213 | static lt_ptr lt_emalloc LT_PARAMS((size_t size)); | 213 | static lt_ptr lt_emalloc LT_PARAMS ((size_t size)); |
214 | static lt_ptr lt_erealloc LT_PARAMS((lt_ptr addr, size_t size)); | 214 | static lt_ptr lt_erealloc LT_PARAMS ((lt_ptr addr, size_t size)); |
215 | 215 | ||
216 | /* static lt_ptr rpl_realloc LT_PARAMS((lt_ptr ptr, size_t size)); */ | 216 | /* static lt_ptr rpl_realloc LT_PARAMS((lt_ptr ptr, size_t size)); */ |
217 | #define rpl_realloc realloc | 217 | #define rpl_realloc realloc |
218 | 218 | ||
219 | /* These are the pointers that can be changed by the caller: */ | 219 | /* These are the pointers that can be changed by the caller: */ |
220 | LT_GLOBAL_DATA lt_ptr (*lt_dlmalloc) LT_PARAMS((size_t size)) | 220 | LT_GLOBAL_DATA |
221 | = (lt_ptr (*) LT_PARAMS((size_t))) malloc; | 221 | lt_ptr (*lt_dlmalloc) |
222 | LT_GLOBAL_DATA lt_ptr (*lt_dlrealloc) LT_PARAMS((lt_ptr ptr, size_t size)) | 222 | LT_PARAMS ((size_t size)) = (lt_ptr (*)LT_PARAMS ((size_t))) malloc; |
223 | = (lt_ptr (*) LT_PARAMS((lt_ptr, size_t))) rpl_realloc; | 223 | LT_GLOBAL_DATA lt_ptr (*lt_dlrealloc) |
224 | LT_GLOBAL_DATA void (*lt_dlfree) LT_PARAMS((lt_ptr ptr)) | 224 | LT_PARAMS ((lt_ptr ptr, size_t size)) = |
225 | = (void (*) LT_PARAMS((lt_ptr))) free; | 225 | (lt_ptr (*)LT_PARAMS ((lt_ptr, size_t))) rpl_realloc; |
226 | LT_GLOBAL_DATA void (*lt_dlfree) LT_PARAMS ((lt_ptr ptr)) = | ||
227 | (void (*)LT_PARAMS ((lt_ptr))) free; | ||
226 | 228 | ||
227 | /* The following macros reduce the amount of typing needed to cast | 229 | /* The following macros reduce the amount of typing needed to cast |
228 | assigned memory. */ | 230 | assigned memory. */ |
@@ -251,29 +253,28 @@ LT_GLOBAL_DATA void (*lt_dlfree) LT_PARAMS((lt_ptr ptr)) | |||
251 | #define LT_DLMEM_REASSIGN(p, q) LT_STMT_START { \ | 253 | #define LT_DLMEM_REASSIGN(p, q) LT_STMT_START { \ |
252 | if ((p) != (q)) { if (p) lt_dlfree (p); (p) = (q); (q) = 0; } \ | 254 | if ((p) != (q)) { if (p) lt_dlfree (p); (p) = (q); (q) = 0; } \ |
253 | } LT_STMT_END | 255 | } LT_STMT_END |
254 | |||
255 | 256 | ||
257 | |||
256 | /* --- REPLACEMENT FUNCTIONS --- */ | 258 | /* --- REPLACEMENT FUNCTIONS --- */ |
257 | 259 | ||
258 | 260 | ||
259 | #undef strdup | 261 | #undef strdup |
260 | #define strdup rpl_strdup | 262 | #define strdup rpl_strdup |
261 | 263 | ||
262 | static char *strdup LT_PARAMS((const char *str)); | 264 | static char *strdup LT_PARAMS ((const char *str)); |
263 | 265 | ||
264 | static char * | 266 | static char *strdup (str) |
265 | strdup(str) | ||
266 | const char *str; | 267 | const char *str; |
267 | { | 268 | { |
268 | char *tmp = 0; | 269 | char *tmp = 0; |
269 | 270 | ||
270 | if (str) | 271 | if (str) |
271 | { | 272 | { |
272 | tmp = LT_DLMALLOC (char, 1+ strlen (str)); | 273 | tmp = LT_DLMALLOC (char, 1 + strlen (str)); |
273 | if (tmp) | 274 | if (tmp) |
274 | { | 275 | { |
275 | strcpy(tmp, str); | 276 | strcpy (tmp, str); |
276 | } | 277 | } |
277 | } | 278 | } |
278 | 279 | ||
279 | return tmp; | 280 | return tmp; |
@@ -285,7 +286,7 @@ strdup(str) | |||
285 | #undef strcmp | 286 | #undef strcmp |
286 | #define strcmp rpl_strcmp | 287 | #define strcmp rpl_strcmp |
287 | 288 | ||
288 | static int strcmp LT_PARAMS((const char *str1, const char *str2)); | 289 | static int strcmp LT_PARAMS ((const char *str1, const char *str2)); |
289 | 290 | ||
290 | static int | 291 | static int |
291 | strcmp (str1, str2) | 292 | strcmp (str1, str2) |
@@ -299,13 +300,13 @@ strcmp (str1, str2) | |||
299 | if (str2 == 0) | 300 | if (str2 == 0) |
300 | return 1; | 301 | return 1; |
301 | 302 | ||
302 | for (;*str1 && *str2; ++str1, ++str2) | 303 | for (; *str1 && *str2; ++str1, ++str2) |
303 | { | 304 | { |
304 | if (*str1 != *str2) | 305 | if (*str1 != *str2) |
305 | break; | 306 | break; |
306 | } | 307 | } |
307 | 308 | ||
308 | return (int)(*str1 - *str2); | 309 | return (int) (*str1 - *str2); |
309 | } | 310 | } |
310 | #endif | 311 | #endif |
311 | 312 | ||
@@ -317,19 +318,19 @@ strcmp (str1, str2) | |||
317 | # else | 318 | # else |
318 | # define strchr rpl_strchr | 319 | # define strchr rpl_strchr |
319 | 320 | ||
320 | static const char *strchr LT_PARAMS((const char *str, int ch)); | 321 | static const char *strchr LT_PARAMS ((const char *str, int ch)); |
321 | 322 | ||
322 | static const char* | 323 | static const char * |
323 | strchr(str, ch) | 324 | strchr (str, ch) |
324 | const char *str; | 325 | const char *str; |
325 | int ch; | 326 | int ch; |
326 | { | 327 | { |
327 | const char *p; | 328 | const char *p; |
328 | 329 | ||
329 | for (p = str; *p != (char)ch && *p != LT_EOS_CHAR; ++p) | 330 | for (p = str; *p != (char) ch && *p != LT_EOS_CHAR; ++p) |
330 | /*NOWORK*/; | 331 | /*NOWORK*/; |
331 | 332 | ||
332 | return (*p == (char)ch) ? p : 0; | 333 | return (*p == (char) ch) ? p : 0; |
333 | } | 334 | } |
334 | 335 | ||
335 | # endif | 336 | # endif |
@@ -343,10 +344,10 @@ strchr(str, ch) | |||
343 | # else | 344 | # else |
344 | # define strrchr rpl_strrchr | 345 | # define strrchr rpl_strrchr |
345 | 346 | ||
346 | static const char *strrchr LT_PARAMS((const char *str, int ch)); | 347 | static const char *strrchr LT_PARAMS ((const char *str, int ch)); |
347 | 348 | ||
348 | static const char* | 349 | static const char * |
349 | strrchr(str, ch) | 350 | strrchr (str, ch) |
350 | const char *str; | 351 | const char *str; |
351 | int ch; | 352 | int ch; |
352 | { | 353 | { |
@@ -355,9 +356,9 @@ strrchr(str, ch) | |||
355 | for (p = str; *p != LT_EOS_CHAR; ++p) | 356 | for (p = str; *p != LT_EOS_CHAR; ++p) |
356 | { | 357 | { |
357 | if (*p == (char) ch) | 358 | if (*p == (char) ch) |
358 | { | 359 | { |
359 | q = p; | 360 | q = p; |
360 | } | 361 | } |
361 | } | 362 | } |
362 | 363 | ||
363 | return q; | 364 | return q; |
@@ -377,7 +378,7 @@ strrchr(str, ch) | |||
377 | # else | 378 | # else |
378 | # define memcpy rpl_memcpy | 379 | # define memcpy rpl_memcpy |
379 | 380 | ||
380 | static lt_ptr memcpy LT_PARAMS((lt_ptr dest, const lt_ptr src, size_t size)); | 381 | static lt_ptr memcpy LT_PARAMS ((lt_ptr dest, const lt_ptr src, size_t size)); |
381 | 382 | ||
382 | static lt_ptr | 383 | static lt_ptr |
383 | memcpy (dest, src, size) | 384 | memcpy (dest, src, size) |
@@ -396,12 +397,13 @@ memcpy (dest, src, size) | |||
396 | } | 397 | } |
397 | 398 | ||
398 | # endif /* !HAVE_BCOPY */ | 399 | # endif /* !HAVE_BCOPY */ |
399 | #endif /* !HAVE_MEMCPY */ | 400 | #endif /* !HAVE_MEMCPY */ |
400 | 401 | ||
401 | #if ! HAVE_MEMMOVE | 402 | #if ! HAVE_MEMMOVE |
402 | # define memmove rpl_memmove | 403 | # define memmove rpl_memmove |
403 | 404 | ||
404 | static lt_ptr memmove LT_PARAMS((lt_ptr dest, const lt_ptr src, size_t size)); | 405 | static lt_ptr memmove |
406 | LT_PARAMS ((lt_ptr dest, const lt_ptr src, size_t size)); | ||
405 | 407 | ||
406 | static lt_ptr | 408 | static lt_ptr |
407 | memmove (dest, src, size) | 409 | memmove (dest, src, size) |
@@ -414,12 +416,12 @@ memmove (dest, src, size) | |||
414 | if (dest < src) | 416 | if (dest < src) |
415 | for (i = 0; i < size; ++i) | 417 | for (i = 0; i < size; ++i) |
416 | { | 418 | { |
417 | dest[i] = src[i]; | 419 | dest[i] = src[i]; |
418 | } | 420 | } |
419 | else if (dest > src) | 421 | else if (dest > src) |
420 | for (i = size -1; i >= 0; --i) | 422 | for (i = size - 1; i >= 0; --i) |
421 | { | 423 | { |
422 | dest[i] = src[i]; | 424 | dest[i] = src[i]; |
423 | } | 425 | } |
424 | 426 | ||
425 | return dest; | 427 | return dest; |
@@ -429,71 +431,73 @@ memmove (dest, src, size) | |||
429 | 431 | ||
430 | #ifdef LT_USE_WINDOWS_DIRENT_EMULATION | 432 | #ifdef LT_USE_WINDOWS_DIRENT_EMULATION |
431 | 433 | ||
432 | static void closedir LT_PARAMS((DIR *entry)); | 434 | static void closedir LT_PARAMS ((DIR * entry)); |
433 | 435 | ||
434 | static void | 436 | static void |
435 | closedir(entry) | 437 | closedir (entry) |
436 | DIR *entry; | 438 | DIR *entry; |
437 | { | 439 | { |
438 | assert(entry != (DIR *) NULL); | 440 | assert (entry != (DIR *) NULL); |
439 | FindClose(entry->hSearch); | 441 | FindClose (entry->hSearch); |
440 | lt_dlfree((lt_ptr)entry); | 442 | lt_dlfree ((lt_ptr) entry); |
441 | } | 443 | } |
442 | 444 | ||
443 | 445 | ||
444 | static DIR * opendir LT_PARAMS((const char *path)); | 446 | static DIR *opendir LT_PARAMS ((const char *path)); |
445 | 447 | ||
446 | static DIR* | 448 | static DIR * |
447 | opendir (path) | 449 | opendir (path) |
448 | const char *path; | 450 | const char *path; |
449 | { | 451 | { |
450 | char file_specification[LT_FILENAME_MAX]; | 452 | char file_specification[LT_FILENAME_MAX]; |
451 | DIR *entry; | 453 | DIR *entry; |
452 | 454 | ||
453 | assert(path != (char *) NULL); | 455 | assert (path != (char *) NULL); |
454 | (void) strncpy(file_specification,path,LT_FILENAME_MAX-1); | 456 | (void) strncpy (file_specification, path, LT_FILENAME_MAX - 1); |
455 | (void) strcat(file_specification,"\\"); | 457 | (void) strcat (file_specification, "\\"); |
456 | entry = LT_DLMALLOC (DIR,sizeof(DIR)); | 458 | entry = LT_DLMALLOC (DIR, sizeof (DIR)); |
457 | if (entry != (DIR *) 0) | 459 | if (entry != (DIR *) 0) |
458 | { | 460 | { |
459 | entry->firsttime = TRUE; | 461 | entry->firsttime = TRUE; |
460 | entry->hSearch = FindFirstFile(file_specification,&entry->Win32FindData); | 462 | entry->hSearch = |
463 | FindFirstFile (file_specification, &entry->Win32FindData); | ||
461 | } | 464 | } |
462 | if (entry->hSearch == INVALID_HANDLE_VALUE) | 465 | if (entry->hSearch == INVALID_HANDLE_VALUE) |
463 | { | 466 | { |
464 | (void) strcat(file_specification,"\\*.*"); | 467 | (void) strcat (file_specification, "\\*.*"); |
465 | entry->hSearch = FindFirstFile(file_specification,&entry->Win32FindData); | 468 | entry->hSearch = |
469 | FindFirstFile (file_specification, &entry->Win32FindData); | ||
466 | if (entry->hSearch == INVALID_HANDLE_VALUE) | 470 | if (entry->hSearch == INVALID_HANDLE_VALUE) |
467 | { | 471 | { |
468 | LT_DLFREE (entry); | 472 | LT_DLFREE (entry); |
469 | return (DIR *) 0; | 473 | return (DIR *) 0; |
470 | } | 474 | } |
471 | } | 475 | } |
472 | return(entry); | 476 | return (entry); |
473 | } | 477 | } |
474 | 478 | ||
475 | 479 | ||
476 | static struct dirent *readdir LT_PARAMS((DIR *entry)); | 480 | static struct dirent *readdir LT_PARAMS ((DIR * entry)); |
477 | 481 | ||
478 | static struct dirent *readdir(entry) | 482 | static struct dirent * |
479 | DIR *entry; | 483 | readdir (entry) |
484 | DIR *entry; | ||
480 | { | 485 | { |
481 | int | 486 | int status; |
482 | status; | ||
483 | 487 | ||
484 | if (entry == (DIR *) 0) | 488 | if (entry == (DIR *) 0) |
485 | return((struct dirent *) 0); | 489 | return ((struct dirent *) 0); |
486 | if (!entry->firsttime) | 490 | if (!entry->firsttime) |
487 | { | 491 | { |
488 | status = FindNextFile(entry->hSearch,&entry->Win32FindData); | 492 | status = FindNextFile (entry->hSearch, &entry->Win32FindData); |
489 | if (status == 0) | 493 | if (status == 0) |
490 | return((struct dirent *) 0); | 494 | return ((struct dirent *) 0); |
491 | } | 495 | } |
492 | entry->firsttime = FALSE; | 496 | entry->firsttime = FALSE; |
493 | (void) strncpy(entry->file_info.d_name,entry->Win32FindData.cFileName, | 497 | (void) strncpy (entry->file_info.d_name, entry->Win32FindData.cFileName, |
494 | LT_FILENAME_MAX-1); | 498 | LT_FILENAME_MAX - 1); |
495 | entry->file_info.d_namlen = strlen(entry->file_info.d_name); | 499 | entry->file_info.d_namlen = strlen (entry->file_info.d_name); |
496 | return(&entry->file_info); | 500 | return (&entry->file_info); |
497 | } | 501 | } |
498 | 502 | ||
499 | #endif /* LT_USE_WINDOWS_DIRENT_EMULATION */ | 503 | #endif /* LT_USE_WINDOWS_DIRENT_EMULATION */ |
@@ -524,9 +528,9 @@ realloc (ptr, size) | |||
524 | { | 528 | { |
525 | /* For zero or less bytes, free the original memory */ | 529 | /* For zero or less bytes, free the original memory */ |
526 | if (ptr != 0) | 530 | if (ptr != 0) |
527 | { | 531 | { |
528 | lt_dlfree (ptr); | 532 | lt_dlfree (ptr); |
529 | } | 533 | } |
530 | 534 | ||
531 | return (lt_ptr) 0; | 535 | return (lt_ptr) 0; |
532 | } | 536 | } |
@@ -541,13 +545,13 @@ realloc (ptr, size) | |||
541 | lt_ptr mem = lt_dlmalloc (size); | 545 | lt_ptr mem = lt_dlmalloc (size); |
542 | 546 | ||
543 | if (mem) | 547 | if (mem) |
544 | { | 548 | { |
545 | memcpy (mem, ptr, size); | 549 | memcpy (mem, ptr, size); |
546 | lt_dlfree (ptr); | 550 | lt_dlfree (ptr); |
547 | } | 551 | } |
548 | 552 | ||
549 | /* Note that the contents of PTR are not damaged if there is | 553 | /* Note that the contents of PTR are not damaged if there is |
550 | insufficient memory to realloc. */ | 554 | insufficient memory to realloc. */ |
551 | return mem; | 555 | return mem; |
552 | } | 556 | } |
553 | } | 557 | } |
@@ -557,8 +561,8 @@ realloc (ptr, size) | |||
557 | #if ! HAVE_ARGZ_APPEND | 561 | #if ! HAVE_ARGZ_APPEND |
558 | # define argz_append rpl_argz_append | 562 | # define argz_append rpl_argz_append |
559 | 563 | ||
560 | static error_t argz_append LT_PARAMS((char **pargz, size_t *pargz_len, | 564 | static error_t argz_append LT_PARAMS ((char **pargz, size_t * pargz_len, |
561 | const char *buf, size_t buf_len)); | 565 | const char *buf, size_t buf_len)); |
562 | 566 | ||
563 | static error_t | 567 | static error_t |
564 | argz_append (pargz, pargz_len, buf, buf_len) | 568 | argz_append (pargz, pargz_len, buf, buf_len) |
@@ -568,7 +572,7 @@ argz_append (pargz, pargz_len, buf, buf_len) | |||
568 | size_t buf_len; | 572 | size_t buf_len; |
569 | { | 573 | { |
570 | size_t argz_len; | 574 | size_t argz_len; |
571 | char *argz; | 575 | char *argz; |
572 | 576 | ||
573 | assert (pargz); | 577 | assert (pargz); |
574 | assert (pargz_len); | 578 | assert (pargz_len); |
@@ -599,8 +603,8 @@ argz_append (pargz, pargz_len, buf, buf_len) | |||
599 | #if ! HAVE_ARGZ_CREATE_SEP | 603 | #if ! HAVE_ARGZ_CREATE_SEP |
600 | # define argz_create_sep rpl_argz_create_sep | 604 | # define argz_create_sep rpl_argz_create_sep |
601 | 605 | ||
602 | static error_t argz_create_sep LT_PARAMS((const char *str, int delim, | 606 | static error_t argz_create_sep LT_PARAMS ((const char *str, int delim, |
603 | char **pargz, size_t *pargz_len)); | 607 | char **pargz, size_t * pargz_len)); |
604 | 608 | ||
605 | static error_t | 609 | static error_t |
606 | argz_create_sep (str, delim, pargz, pargz_len) | 610 | argz_create_sep (str, delim, pargz, pargz_len) |
@@ -618,7 +622,7 @@ argz_create_sep (str, delim, pargz, pargz_len) | |||
618 | 622 | ||
619 | /* Make a copy of STR, but replacing each occurence of | 623 | /* Make a copy of STR, but replacing each occurence of |
620 | DELIM with '\0'. */ | 624 | DELIM with '\0'. */ |
621 | argz_len = 1+ LT_STRLEN (str); | 625 | argz_len = 1 + LT_STRLEN (str); |
622 | if (argz_len) | 626 | if (argz_len) |
623 | { | 627 | { |
624 | const char *p; | 628 | const char *p; |
@@ -626,22 +630,22 @@ argz_create_sep (str, delim, pargz, pargz_len) | |||
626 | 630 | ||
627 | argz = LT_DLMALLOC (char, argz_len); | 631 | argz = LT_DLMALLOC (char, argz_len); |
628 | if (!argz) | 632 | if (!argz) |
629 | return ENOMEM; | 633 | return ENOMEM; |
630 | 634 | ||
631 | for (p = str, q = argz; *p != LT_EOS_CHAR; ++p) | 635 | for (p = str, q = argz; *p != LT_EOS_CHAR; ++p) |
632 | { | 636 | { |
633 | if (*p == delim) | 637 | if (*p == delim) |
634 | { | 638 | { |
635 | /* Ignore leading delimiters, and fold consecutive | 639 | /* Ignore leading delimiters, and fold consecutive |
636 | delimiters in STR into a single '\0' in ARGZ. */ | 640 | delimiters in STR into a single '\0' in ARGZ. */ |
637 | if ((q > argz) && (q[-1] != LT_EOS_CHAR)) | 641 | if ((q > argz) && (q[-1] != LT_EOS_CHAR)) |
638 | *q++ = LT_EOS_CHAR; | 642 | *q++ = LT_EOS_CHAR; |
639 | else | 643 | else |
640 | --argz_len; | 644 | --argz_len; |
641 | } | 645 | } |
642 | else | 646 | else |
643 | *q++ = *p; | 647 | *q++ = *p; |
644 | } | 648 | } |
645 | /* Copy terminating LT_EOS_CHAR. */ | 649 | /* Copy terminating LT_EOS_CHAR. */ |
646 | *q = *p; | 650 | *q = *p; |
647 | } | 651 | } |
@@ -662,8 +666,8 @@ argz_create_sep (str, delim, pargz, pargz_len) | |||
662 | #if ! HAVE_ARGZ_INSERT | 666 | #if ! HAVE_ARGZ_INSERT |
663 | # define argz_insert rpl_argz_insert | 667 | # define argz_insert rpl_argz_insert |
664 | 668 | ||
665 | static error_t argz_insert LT_PARAMS((char **pargz, size_t *pargz_len, | 669 | static error_t argz_insert LT_PARAMS ((char **pargz, size_t * pargz_len, |
666 | char *before, const char *entry)); | 670 | char *before, const char *entry)); |
667 | 671 | ||
668 | static error_t | 672 | static error_t |
669 | argz_insert (pargz, pargz_len, before, entry) | 673 | argz_insert (pargz, pargz_len, before, entry) |
@@ -679,7 +683,7 @@ argz_insert (pargz, pargz_len, before, entry) | |||
679 | /* No BEFORE address indicates ENTRY should be inserted after the | 683 | /* No BEFORE address indicates ENTRY should be inserted after the |
680 | current last element. */ | 684 | current last element. */ |
681 | if (!before) | 685 | if (!before) |
682 | return argz_append (pargz, pargz_len, entry, 1+ LT_STRLEN (entry)); | 686 | return argz_append (pargz, pargz_len, entry, 1 + LT_STRLEN (entry)); |
683 | 687 | ||
684 | /* This probably indicates a programmer error, but to preserve | 688 | /* This probably indicates a programmer error, but to preserve |
685 | semantics, scan back to the start of an entry if BEFORE points | 689 | semantics, scan back to the start of an entry if BEFORE points |
@@ -688,10 +692,10 @@ argz_insert (pargz, pargz_len, before, entry) | |||
688 | --before; | 692 | --before; |
689 | 693 | ||
690 | { | 694 | { |
691 | size_t entry_len = 1+ LT_STRLEN (entry); | 695 | size_t entry_len = 1 + LT_STRLEN (entry); |
692 | size_t argz_len = *pargz_len + entry_len; | 696 | size_t argz_len = *pargz_len + entry_len; |
693 | size_t offset = before - *pargz; | 697 | size_t offset = before - *pargz; |
694 | char *argz = LT_DLREALLOC (char, *pargz, argz_len); | 698 | char *argz = LT_DLREALLOC (char, *pargz, argz_len); |
695 | 699 | ||
696 | if (!argz) | 700 | if (!argz) |
697 | return ENOMEM; | 701 | return ENOMEM; |
@@ -704,7 +708,7 @@ argz_insert (pargz, pargz_len, before, entry) | |||
704 | space at the end -- making room to copy ENTRY into the | 708 | space at the end -- making room to copy ENTRY into the |
705 | resulting gap. */ | 709 | resulting gap. */ |
706 | memmove (before + entry_len, before, *pargz_len - offset); | 710 | memmove (before + entry_len, before, *pargz_len - offset); |
707 | memcpy (before, entry, entry_len); | 711 | memcpy (before, entry, entry_len); |
708 | 712 | ||
709 | /* Assign new values. */ | 713 | /* Assign new values. */ |
710 | *pargz = argz; | 714 | *pargz = argz; |
@@ -719,8 +723,8 @@ argz_insert (pargz, pargz_len, before, entry) | |||
719 | #if ! HAVE_ARGZ_NEXT | 723 | #if ! HAVE_ARGZ_NEXT |
720 | # define argz_next rpl_argz_next | 724 | # define argz_next rpl_argz_next |
721 | 725 | ||
722 | static char *argz_next LT_PARAMS((char *argz, size_t argz_len, | 726 | static char *argz_next LT_PARAMS ((char *argz, size_t argz_len, |
723 | const char *entry)); | 727 | const char *entry)); |
724 | 728 | ||
725 | static char * | 729 | static char * |
726 | argz_next (argz, argz_len, entry) | 730 | argz_next (argz, argz_len, entry) |
@@ -733,28 +737,28 @@ argz_next (argz, argz_len, entry) | |||
733 | if (entry) | 737 | if (entry) |
734 | { | 738 | { |
735 | /* Either ARGZ/ARGZ_LEN is empty, or ENTRY points into an address | 739 | /* Either ARGZ/ARGZ_LEN is empty, or ENTRY points into an address |
736 | within the ARGZ vector. */ | 740 | within the ARGZ vector. */ |
737 | assert ((!argz && !argz_len) | 741 | assert ((!argz && !argz_len) |
738 | || ((argz <= entry) && (entry < (argz + argz_len)))); | 742 | || ((argz <= entry) && (entry < (argz + argz_len)))); |
739 | 743 | ||
740 | /* Move to the char immediately after the terminating | 744 | /* Move to the char immediately after the terminating |
741 | '\0' of ENTRY. */ | 745 | '\0' of ENTRY. */ |
742 | entry = 1+ strchr (entry, LT_EOS_CHAR); | 746 | entry = 1 + strchr (entry, LT_EOS_CHAR); |
743 | 747 | ||
744 | /* Return either the new ENTRY, or else NULL if ARGZ is | 748 | /* Return either the new ENTRY, or else NULL if ARGZ is |
745 | exhausted. */ | 749 | exhausted. */ |
746 | return (entry >= argz + argz_len) ? 0 : (char *) entry; | 750 | return (entry >= argz + argz_len) ? 0 : (char *) entry; |
747 | } | 751 | } |
748 | else | 752 | else |
749 | { | 753 | { |
750 | /* This should probably be flagged as a programmer error, | 754 | /* This should probably be flagged as a programmer error, |
751 | since starting an argz_next loop with the iterator set | 755 | since starting an argz_next loop with the iterator set |
752 | to ARGZ is safer. To preserve semantics, handle the NULL | 756 | to ARGZ is safer. To preserve semantics, handle the NULL |
753 | case by returning the start of ARGZ (if any). */ | 757 | case by returning the start of ARGZ (if any). */ |
754 | if (argz_len > 0) | 758 | if (argz_len > 0) |
755 | return argz; | 759 | return argz; |
756 | else | 760 | else |
757 | return 0; | 761 | return 0; |
758 | } | 762 | } |
759 | } | 763 | } |
760 | #endif /* !HAVE_ARGZ_NEXT */ | 764 | #endif /* !HAVE_ARGZ_NEXT */ |
@@ -764,8 +768,7 @@ argz_next (argz, argz_len, entry) | |||
764 | #if ! HAVE_ARGZ_STRINGIFY | 768 | #if ! HAVE_ARGZ_STRINGIFY |
765 | # define argz_stringify rpl_argz_stringify | 769 | # define argz_stringify rpl_argz_stringify |
766 | 770 | ||
767 | static void argz_stringify LT_PARAMS((char *argz, size_t argz_len, | 771 | static void argz_stringify LT_PARAMS ((char *argz, size_t argz_len, int sep)); |
768 | int sep)); | ||
769 | 772 | ||
770 | static void | 773 | static void |
771 | argz_stringify (argz, argz_len, sep) | 774 | argz_stringify (argz, argz_len, sep) |
@@ -777,68 +780,69 @@ argz_stringify (argz, argz_len, sep) | |||
777 | 780 | ||
778 | if (sep) | 781 | if (sep) |
779 | { | 782 | { |
780 | --argz_len; /* don't stringify the terminating EOS */ | 783 | --argz_len; /* don't stringify the terminating EOS */ |
781 | while (--argz_len > 0) | 784 | while (--argz_len > 0) |
782 | { | 785 | { |
783 | if (argz[argz_len] == LT_EOS_CHAR) | 786 | if (argz[argz_len] == LT_EOS_CHAR) |
784 | argz[argz_len] = sep; | 787 | argz[argz_len] = sep; |
785 | } | 788 | } |
786 | } | 789 | } |
787 | } | 790 | } |
788 | #endif /* !HAVE_ARGZ_STRINGIFY */ | 791 | #endif /* !HAVE_ARGZ_STRINGIFY */ |
792 | |||
789 | 793 | ||
790 | 794 | ||
791 | 795 | ||
792 | |||
793 | /* --- TYPE DEFINITIONS -- */ | 796 | /* --- TYPE DEFINITIONS -- */ |
794 | 797 | ||
795 | 798 | ||
796 | /* This type is used for the array of caller data sets in each handler. */ | 799 | /* This type is used for the array of caller data sets in each handler. */ |
797 | typedef struct { | 800 | typedef struct |
798 | lt_dlcaller_id key; | 801 | { |
799 | lt_ptr data; | 802 | lt_dlcaller_id key; |
803 | lt_ptr data; | ||
800 | } lt_caller_data; | 804 | } lt_caller_data; |
805 | |||
801 | 806 | ||
802 | 807 | ||
803 | 808 | ||
804 | |||
805 | /* --- OPAQUE STRUCTURES DECLARED IN LTDL.H --- */ | 809 | /* --- OPAQUE STRUCTURES DECLARED IN LTDL.H --- */ |
806 | 810 | ||
807 | 811 | ||
808 | /* Extract the diagnostic strings from the error table macro in the same | 812 | /* Extract the diagnostic strings from the error table macro in the same |
809 | order as the enumerated indices in ltdl.h. */ | 813 | order as the enumerated indices in ltdl.h. */ |
810 | 814 | ||
811 | static const char *lt_dlerror_strings[] = | 815 | static const char *lt_dlerror_strings[] = { |
812 | { | ||
813 | #define LT_ERROR(name, diagnostic) (diagnostic), | 816 | #define LT_ERROR(name, diagnostic) (diagnostic), |
814 | lt_dlerror_table | 817 | lt_dlerror_table |
815 | #undef LT_ERROR | 818 | #undef LT_ERROR |
816 | 819 | 0 | |
817 | 0 | 820 | }; |
818 | }; | ||
819 | 821 | ||
820 | /* This structure is used for the list of registered loaders. */ | 822 | /* This structure is used for the list of registered loaders. */ |
821 | struct lt_dlloader { | 823 | struct lt_dlloader |
822 | struct lt_dlloader *next; | 824 | { |
823 | const char *loader_name; /* identifying name for each loader */ | 825 | struct lt_dlloader *next; |
824 | const char *sym_prefix; /* prefix for symbols */ | 826 | const char *loader_name; /* identifying name for each loader */ |
825 | lt_module_open *module_open; | 827 | const char *sym_prefix; /* prefix for symbols */ |
826 | lt_module_close *module_close; | 828 | lt_module_open *module_open; |
827 | lt_find_sym *find_sym; | 829 | lt_module_close *module_close; |
828 | lt_dlloader_exit *dlloader_exit; | 830 | lt_find_sym *find_sym; |
829 | lt_user_data dlloader_data; | 831 | lt_dlloader_exit *dlloader_exit; |
832 | lt_user_data dlloader_data; | ||
830 | }; | 833 | }; |
831 | 834 | ||
832 | struct lt_dlhandle_struct { | 835 | struct lt_dlhandle_struct |
833 | struct lt_dlhandle_struct *next; | 836 | { |
834 | lt_dlloader *loader; /* dlopening interface */ | 837 | struct lt_dlhandle_struct *next; |
835 | lt_dlinfo info; | 838 | lt_dlloader *loader; /* dlopening interface */ |
836 | int depcount; /* number of dependencies */ | 839 | lt_dlinfo info; |
837 | lt_dlhandle *deplibs; /* dependencies */ | 840 | int depcount; /* number of dependencies */ |
838 | lt_module module; /* system module handle */ | 841 | lt_dlhandle *deplibs; /* dependencies */ |
839 | lt_ptr system; /* system specific data */ | 842 | lt_module module; /* system module handle */ |
840 | lt_caller_data *caller_data; /* per caller associated data */ | 843 | lt_ptr system; /* system specific data */ |
841 | int flags; /* various boolean stats */ | 844 | lt_caller_data *caller_data; /* per caller associated data */ |
845 | int flags; /* various boolean stats */ | ||
842 | }; | 846 | }; |
843 | 847 | ||
844 | /* Various boolean flags can be stored in the flags field of an | 848 | /* Various boolean flags can be stored in the flags field of an |
@@ -854,18 +858,18 @@ struct lt_dlhandle_struct { | |||
854 | 858 | ||
855 | #define LT_DLSTRERROR(name) lt_dlerror_strings[LT_CONC(LT_ERROR_,name)] | 859 | #define LT_DLSTRERROR(name) lt_dlerror_strings[LT_CONC(LT_ERROR_,name)] |
856 | 860 | ||
857 | static const char objdir[] = LTDL_OBJDIR; | 861 | static const char objdir[] = LTDL_OBJDIR; |
858 | static const char archive_ext[] = LTDL_ARCHIVE_EXT; | 862 | static const char archive_ext[] = LTDL_ARCHIVE_EXT; |
859 | #ifdef LTDL_SHLIB_EXT | 863 | #ifdef LTDL_SHLIB_EXT |
860 | static const char shlib_ext[] = LTDL_SHLIB_EXT; | 864 | static const char shlib_ext[] = LTDL_SHLIB_EXT; |
861 | #endif | 865 | #endif |
862 | #ifdef LTDL_SYSSEARCHPATH | 866 | #ifdef LTDL_SYSSEARCHPATH |
863 | static const char sys_search_path[] = LTDL_SYSSEARCHPATH; | 867 | static const char sys_search_path[] = LTDL_SYSSEARCHPATH; |
864 | #endif | 868 | #endif |
869 | |||
865 | 870 | ||
866 | 871 | ||
867 | 872 | ||
868 | |||
869 | /* --- MUTEX LOCKING --- */ | 873 | /* --- MUTEX LOCKING --- */ |
870 | 874 | ||
871 | 875 | ||
@@ -891,11 +895,11 @@ static const char sys_search_path[] = LTDL_SYSSEARCHPATH; | |||
891 | 895 | ||
892 | /* The mutex functions stored here are global, and are necessarily the | 896 | /* The mutex functions stored here are global, and are necessarily the |
893 | same for all threads that wish to share access to libltdl. */ | 897 | same for all threads that wish to share access to libltdl. */ |
894 | static lt_dlmutex_lock *lt_dlmutex_lock_func = 0; | 898 | static lt_dlmutex_lock *lt_dlmutex_lock_func = 0; |
895 | static lt_dlmutex_unlock *lt_dlmutex_unlock_func = 0; | 899 | static lt_dlmutex_unlock *lt_dlmutex_unlock_func = 0; |
896 | static lt_dlmutex_seterror *lt_dlmutex_seterror_func = 0; | 900 | static lt_dlmutex_seterror *lt_dlmutex_seterror_func = 0; |
897 | static lt_dlmutex_geterror *lt_dlmutex_geterror_func = 0; | 901 | static lt_dlmutex_geterror *lt_dlmutex_geterror_func = 0; |
898 | static const char *lt_dllast_error = 0; | 902 | static const char *lt_dllast_error = 0; |
899 | 903 | ||
900 | 904 | ||
901 | /* Either set or reset the mutex functions. Either all the arguments must | 905 | /* Either set or reset the mutex functions. Either all the arguments must |
@@ -910,7 +914,7 @@ lt_dlmutex_register (lock, unlock, seterror, geterror) | |||
910 | lt_dlmutex_geterror *geterror; | 914 | lt_dlmutex_geterror *geterror; |
911 | { | 915 | { |
912 | lt_dlmutex_unlock *old_unlock = unlock; | 916 | lt_dlmutex_unlock *old_unlock = unlock; |
913 | int errors = 0; | 917 | int errors = 0; |
914 | 918 | ||
915 | /* Lock using the old lock() callback, if any. */ | 919 | /* Lock using the old lock() callback, if any. */ |
916 | LT_DLMUTEX_LOCK (); | 920 | LT_DLMUTEX_LOCK (); |
@@ -918,8 +922,8 @@ lt_dlmutex_register (lock, unlock, seterror, geterror) | |||
918 | if ((lock && unlock && seterror && geterror) | 922 | if ((lock && unlock && seterror && geterror) |
919 | || !(lock || unlock || seterror || geterror)) | 923 | || !(lock || unlock || seterror || geterror)) |
920 | { | 924 | { |
921 | lt_dlmutex_lock_func = lock; | 925 | lt_dlmutex_lock_func = lock; |
922 | lt_dlmutex_unlock_func = unlock; | 926 | lt_dlmutex_unlock_func = unlock; |
923 | lt_dlmutex_geterror_func = geterror; | 927 | lt_dlmutex_geterror_func = geterror; |
924 | } | 928 | } |
925 | else | 929 | else |
@@ -937,23 +941,23 @@ lt_dlmutex_register (lock, unlock, seterror, geterror) | |||
937 | this function. */ | 941 | this function. */ |
938 | return errors; | 942 | return errors; |
939 | } | 943 | } |
944 | |||
940 | 945 | ||
941 | 946 | ||
942 | 947 | ||
943 | |||
944 | /* --- ERROR HANDLING --- */ | 948 | /* --- ERROR HANDLING --- */ |
945 | 949 | ||
946 | 950 | ||
947 | static const char **user_error_strings = 0; | 951 | static const char **user_error_strings = 0; |
948 | static int errorcount = LT_ERROR_MAX; | 952 | static int errorcount = LT_ERROR_MAX; |
949 | 953 | ||
950 | int | 954 | int |
951 | lt_dladderror (diagnostic) | 955 | lt_dladderror (diagnostic) |
952 | const char *diagnostic; | 956 | const char *diagnostic; |
953 | { | 957 | { |
954 | int errindex = 0; | 958 | int errindex = 0; |
955 | int result = -1; | 959 | int result = -1; |
956 | const char **temp = (const char **) 0; | 960 | const char **temp = (const char **) 0; |
957 | 961 | ||
958 | assert (diagnostic); | 962 | assert (diagnostic); |
959 | 963 | ||
@@ -963,9 +967,9 @@ lt_dladderror (diagnostic) | |||
963 | temp = LT_EREALLOC (const char *, user_error_strings, 1 + errindex); | 967 | temp = LT_EREALLOC (const char *, user_error_strings, 1 + errindex); |
964 | if (temp) | 968 | if (temp) |
965 | { | 969 | { |
966 | user_error_strings = temp; | 970 | user_error_strings = temp; |
967 | user_error_strings[errindex] = diagnostic; | 971 | user_error_strings[errindex] = diagnostic; |
968 | result = errorcount++; | 972 | result = errorcount++; |
969 | } | 973 | } |
970 | 974 | ||
971 | LT_DLMUTEX_UNLOCK (); | 975 | LT_DLMUTEX_UNLOCK (); |
@@ -977,7 +981,7 @@ int | |||
977 | lt_dlseterror (errindex) | 981 | lt_dlseterror (errindex) |
978 | int errindex; | 982 | int errindex; |
979 | { | 983 | { |
980 | int errors = 0; | 984 | int errors = 0; |
981 | 985 | ||
982 | LT_DLMUTEX_LOCK (); | 986 | LT_DLMUTEX_LOCK (); |
983 | 987 | ||
@@ -1033,10 +1037,10 @@ lt_estrdup (str) | |||
1033 | LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY)); | 1037 | LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY)); |
1034 | return copy; | 1038 | return copy; |
1035 | } | 1039 | } |
1040 | |||
1036 | 1041 | ||
1037 | 1042 | ||
1038 | 1043 | ||
1039 | |||
1040 | /* --- DLOPEN() INTERFACE LOADER --- */ | 1044 | /* --- DLOPEN() INTERFACE LOADER --- */ |
1041 | 1045 | ||
1042 | 1046 | ||
@@ -1087,7 +1091,7 @@ sys_dl_open (loader_data, filename) | |||
1087 | lt_user_data loader_data; | 1091 | lt_user_data loader_data; |
1088 | const char *filename; | 1092 | const char *filename; |
1089 | { | 1093 | { |
1090 | lt_module module = dlopen (filename, LT_LAZY_OR_NOW); | 1094 | lt_module module = dlopen (filename, LT_LAZY_OR_NOW); |
1091 | 1095 | ||
1092 | if (!module) | 1096 | if (!module) |
1093 | { | 1097 | { |
@@ -1129,20 +1133,20 @@ sys_dl_sym (loader_data, module, symbol) | |||
1129 | return address; | 1133 | return address; |
1130 | } | 1134 | } |
1131 | 1135 | ||
1132 | static struct lt_user_dlloader sys_dl = | 1136 | static struct lt_user_dlloader sys_dl = { |
1133 | { | ||
1134 | # ifdef NEED_USCORE | 1137 | # ifdef NEED_USCORE |
1135 | "_", | 1138 | "_", |
1136 | # else | 1139 | # else |
1137 | 0, | 1140 | 0, |
1138 | # endif | 1141 | # endif |
1139 | sys_dl_open, sys_dl_close, sys_dl_sym, 0, 0 }; | 1142 | sys_dl_open, sys_dl_close, sys_dl_sym, 0, 0 |
1143 | }; | ||
1140 | 1144 | ||
1141 | 1145 | ||
1142 | #endif /* HAVE_LIBDL */ | 1146 | #endif /* HAVE_LIBDL */ |
1147 | |||
1143 | 1148 | ||
1144 | 1149 | ||
1145 | |||
1146 | /* --- SHL_LOAD() INTERFACE LOADER --- */ | 1150 | /* --- SHL_LOAD() INTERFACE LOADER --- */ |
1147 | 1151 | ||
1148 | #if HAVE_SHL_LOAD | 1152 | #if HAVE_SHL_LOAD |
@@ -1220,9 +1224,9 @@ sys_shl_open (loader_data, filename) | |||
1220 | module = shl_load (filename, LT_BIND_FLAGS, 0L); | 1224 | module = shl_load (filename, LT_BIND_FLAGS, 0L); |
1221 | 1225 | ||
1222 | if (!module) | 1226 | if (!module) |
1223 | { | 1227 | { |
1224 | LT_DLMUTEX_SETERROR (LT_DLSTRERROR (CANNOT_OPEN)); | 1228 | LT_DLMUTEX_SETERROR (LT_DLSTRERROR (CANNOT_OPEN)); |
1225 | } | 1229 | } |
1226 | } | 1230 | } |
1227 | 1231 | ||
1228 | return module; | 1232 | return module; |
@@ -1254,15 +1258,16 @@ sys_shl_sym (loader_data, module, symbol) | |||
1254 | 1258 | ||
1255 | /* sys_shl_open should never return a NULL module handle */ | 1259 | /* sys_shl_open should never return a NULL module handle */ |
1256 | if (module == (lt_module) 0) | 1260 | if (module == (lt_module) 0) |
1257 | { | 1261 | { |
1258 | LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INVALID_HANDLE)); | 1262 | LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INVALID_HANDLE)); |
1259 | } | 1263 | } |
1260 | else if (!shl_findsym((shl_t*) &module, symbol, TYPE_UNDEFINED, &address)) | 1264 | else |
1265 | if (!shl_findsym ((shl_t *) & module, symbol, TYPE_UNDEFINED, &address)) | ||
1261 | { | 1266 | { |
1262 | if (!address) | 1267 | if (!address) |
1263 | { | 1268 | { |
1264 | LT_DLMUTEX_SETERROR (LT_DLSTRERROR (SYMBOL_NOT_FOUND)); | 1269 | LT_DLMUTEX_SETERROR (LT_DLSTRERROR (SYMBOL_NOT_FOUND)); |
1265 | } | 1270 | } |
1266 | } | 1271 | } |
1267 | 1272 | ||
1268 | return address; | 1273 | return address; |
@@ -1273,10 +1278,10 @@ static struct lt_user_dlloader sys_shl = { | |||
1273 | }; | 1278 | }; |
1274 | 1279 | ||
1275 | #endif /* HAVE_SHL_LOAD */ | 1280 | #endif /* HAVE_SHL_LOAD */ |
1281 | |||
1276 | 1282 | ||
1277 | 1283 | ||
1278 | 1284 | ||
1279 | |||
1280 | /* --- LOADLIBRARY() INTERFACE LOADER --- */ | 1285 | /* --- LOADLIBRARY() INTERFACE LOADER --- */ |
1281 | 1286 | ||
1282 | #ifdef __WINDOWS__ | 1287 | #ifdef __WINDOWS__ |
@@ -1293,12 +1298,12 @@ sys_wll_open (loader_data, filename) | |||
1293 | lt_user_data loader_data; | 1298 | lt_user_data loader_data; |
1294 | const char *filename; | 1299 | const char *filename; |
1295 | { | 1300 | { |
1296 | lt_dlhandle cur; | 1301 | lt_dlhandle cur; |
1297 | lt_module module = 0; | 1302 | lt_module module = 0; |
1298 | const char *errormsg = 0; | 1303 | const char *errormsg = 0; |
1299 | char *searchname = 0; | 1304 | char *searchname = 0; |
1300 | char *ext; | 1305 | char *ext; |
1301 | char self_name_buf[MAX_PATH]; | 1306 | char self_name_buf[MAX_PATH]; |
1302 | 1307 | ||
1303 | if (!filename) | 1308 | if (!filename) |
1304 | { | 1309 | { |
@@ -1320,10 +1325,10 @@ sys_wll_open (loader_data, filename) | |||
1320 | else | 1325 | else |
1321 | { | 1326 | { |
1322 | /* Append a `.' to stop Windows from adding an | 1327 | /* Append a `.' to stop Windows from adding an |
1323 | implicit `.dll' extension. */ | 1328 | implicit `.dll' extension. */ |
1324 | searchname = LT_EMALLOC (char, 2+ LT_STRLEN (filename)); | 1329 | searchname = LT_EMALLOC (char, 2 + LT_STRLEN (filename)); |
1325 | if (searchname) | 1330 | if (searchname) |
1326 | sprintf (searchname, "%s.", filename); | 1331 | sprintf (searchname, "%s.", filename); |
1327 | } | 1332 | } |
1328 | if (!searchname) | 1333 | if (!searchname) |
1329 | return 0; | 1334 | return 0; |
@@ -1331,8 +1336,8 @@ sys_wll_open (loader_data, filename) | |||
1331 | #if __CYGWIN__ | 1336 | #if __CYGWIN__ |
1332 | { | 1337 | { |
1333 | char wpath[MAX_PATH]; | 1338 | char wpath[MAX_PATH]; |
1334 | cygwin_conv_to_full_win32_path(searchname, wpath); | 1339 | cygwin_conv_to_full_win32_path (searchname, wpath); |
1335 | module = LoadLibrary(wpath); | 1340 | module = LoadLibrary (wpath); |
1336 | } | 1341 | } |
1337 | #else | 1342 | #else |
1338 | module = LoadLibrary (searchname); | 1343 | module = LoadLibrary (searchname); |
@@ -1352,18 +1357,18 @@ sys_wll_open (loader_data, filename) | |||
1352 | while (cur) | 1357 | while (cur) |
1353 | { | 1358 | { |
1354 | if (!cur->module) | 1359 | if (!cur->module) |
1355 | { | 1360 | { |
1356 | cur = 0; | 1361 | cur = 0; |
1357 | break; | 1362 | break; |
1358 | } | 1363 | } |
1359 | 1364 | ||
1360 | if (cur->module == module) | 1365 | if (cur->module == module) |
1361 | { | 1366 | { |
1362 | break; | 1367 | break; |
1363 | } | 1368 | } |
1364 | 1369 | ||
1365 | cur = cur->next; | 1370 | cur = cur->next; |
1366 | } | 1371 | } |
1367 | LT_DLMUTEX_UNLOCK (); | 1372 | LT_DLMUTEX_UNLOCK (); |
1368 | 1373 | ||
1369 | if (cur || !module) | 1374 | if (cur || !module) |
@@ -1380,9 +1385,9 @@ sys_wll_close (loader_data, module) | |||
1380 | lt_user_data loader_data; | 1385 | lt_user_data loader_data; |
1381 | lt_module module; | 1386 | lt_module module; |
1382 | { | 1387 | { |
1383 | int errors = 0; | 1388 | int errors = 0; |
1384 | 1389 | ||
1385 | if (FreeLibrary(module) == 0) | 1390 | if (FreeLibrary (module) == 0) |
1386 | { | 1391 | { |
1387 | LT_DLMUTEX_SETERROR (LT_DLSTRERROR (CANNOT_CLOSE)); | 1392 | LT_DLMUTEX_SETERROR (LT_DLSTRERROR (CANNOT_CLOSE)); |
1388 | ++errors; | 1393 | ++errors; |
@@ -1397,7 +1402,7 @@ sys_wll_sym (loader_data, module, symbol) | |||
1397 | lt_module module; | 1402 | lt_module module; |
1398 | const char *symbol; | 1403 | const char *symbol; |
1399 | { | 1404 | { |
1400 | lt_ptr address = GetProcAddress (module, symbol); | 1405 | lt_ptr address = GetProcAddress (module, symbol); |
1401 | 1406 | ||
1402 | if (!address) | 1407 | if (!address) |
1403 | { | 1408 | { |
@@ -1412,10 +1417,10 @@ static struct lt_user_dlloader sys_wll = { | |||
1412 | }; | 1417 | }; |
1413 | 1418 | ||
1414 | #endif /* __WINDOWS__ */ | 1419 | #endif /* __WINDOWS__ */ |
1420 | |||
1415 | 1421 | ||
1416 | 1422 | ||
1417 | 1423 | ||
1418 | |||
1419 | /* --- LOAD_ADD_ON() INTERFACE LOADER --- */ | 1424 | /* --- LOAD_ADD_ON() INTERFACE LOADER --- */ |
1420 | 1425 | ||
1421 | 1426 | ||
@@ -1441,7 +1446,7 @@ sys_bedl_open (loader_data, filename) | |||
1441 | image_info info; | 1446 | image_info info; |
1442 | int32 cookie = 0; | 1447 | int32 cookie = 0; |
1443 | if (get_next_image_info (0, &cookie, &info) == B_OK) | 1448 | if (get_next_image_info (0, &cookie, &info) == B_OK) |
1444 | image = load_add_on (info.name); | 1449 | image = load_add_on (info.name); |
1445 | } | 1450 | } |
1446 | 1451 | ||
1447 | if (image <= 0) | 1452 | if (image <= 0) |
@@ -1492,10 +1497,10 @@ static struct lt_user_dlloader sys_bedl = { | |||
1492 | }; | 1497 | }; |
1493 | 1498 | ||
1494 | #endif /* __BEOS__ */ | 1499 | #endif /* __BEOS__ */ |
1500 | |||
1495 | 1501 | ||
1496 | 1502 | ||
1497 | 1503 | ||
1498 | |||
1499 | /* --- DLD_LINK() INTERFACE LOADER --- */ | 1504 | /* --- DLD_LINK() INTERFACE LOADER --- */ |
1500 | 1505 | ||
1501 | 1506 | ||
@@ -1531,7 +1536,7 @@ sys_dld_close (loader_data, module) | |||
1531 | { | 1536 | { |
1532 | int errors = 0; | 1537 | int errors = 0; |
1533 | 1538 | ||
1534 | if (dld_unlink_by_file ((char*)(module), 1) != 0) | 1539 | if (dld_unlink_by_file ((char *) (module), 1) != 0) |
1535 | { | 1540 | { |
1536 | LT_DLMUTEX_SETERROR (LT_DLSTRERROR (CANNOT_CLOSE)); | 1541 | LT_DLMUTEX_SETERROR (LT_DLSTRERROR (CANNOT_CLOSE)); |
1537 | ++errors; | 1542 | ++errors; |
@@ -1584,10 +1589,11 @@ static struct lt_user_dlloader sys_dld = { | |||
1584 | # define ENUM_DYLD_BOOL | 1589 | # define ENUM_DYLD_BOOL |
1585 | # undef FALSE | 1590 | # undef FALSE |
1586 | # undef TRUE | 1591 | # undef TRUE |
1587 | enum DYLD_BOOL { | 1592 | enum DYLD_BOOL |
1588 | FALSE, | 1593 | { |
1589 | TRUE | 1594 | FALSE, |
1590 | }; | 1595 | TRUE |
1596 | }; | ||
1591 | #endif | 1597 | #endif |
1592 | #ifndef LC_REQ_DYLD | 1598 | #ifndef LC_REQ_DYLD |
1593 | # define LC_REQ_DYLD 0x80000000 | 1599 | # define LC_REQ_DYLD 0x80000000 |
@@ -1595,10 +1601,18 @@ static struct lt_user_dlloader sys_dld = { | |||
1595 | #ifndef LC_LOAD_WEAK_DYLIB | 1601 | #ifndef LC_LOAD_WEAK_DYLIB |
1596 | # define LC_LOAD_WEAK_DYLIB (0x18 | LC_REQ_DYLD) | 1602 | # define LC_LOAD_WEAK_DYLIB (0x18 | LC_REQ_DYLD) |
1597 | #endif | 1603 | #endif |
1598 | static const struct mach_header * (*ltdl_NSAddImage)(const char *image_name, unsigned long options) = 0; | 1604 | static const struct mach_header *(*ltdl_NSAddImage) (const char *image_name, |
1599 | static NSSymbol (*ltdl_NSLookupSymbolInImage)(const struct mach_header *image,const char *symbolName, unsigned long options) = 0; | 1605 | unsigned long options) = |
1600 | static enum DYLD_BOOL (*ltdl_NSIsSymbolNameDefinedInImage)(const struct mach_header *image, const char *symbolName) = 0; | 1606 | 0; |
1601 | static enum DYLD_BOOL (*ltdl_NSMakePrivateModulePublic)(NSModule module) = 0; | 1607 | static NSSymbol (*ltdl_NSLookupSymbolInImage) (const struct mach_header * |
1608 | image, const char *symbolName, | ||
1609 | unsigned long options) = 0; | ||
1610 | static enum DYLD_BOOL (*ltdl_NSIsSymbolNameDefinedInImage) (const struct | ||
1611 | mach_header * | ||
1612 | image, | ||
1613 | const char | ||
1614 | *symbolName) = 0; | ||
1615 | static enum DYLD_BOOL (*ltdl_NSMakePrivateModulePublic) (NSModule module) = 0; | ||
1602 | 1616 | ||
1603 | #ifndef NSADDIMAGE_OPTION_NONE | 1617 | #ifndef NSADDIMAGE_OPTION_NONE |
1604 | #define NSADDIMAGE_OPTION_NONE 0x0 | 1618 | #define NSADDIMAGE_OPTION_NONE 0x0 |
@@ -1630,144 +1644,170 @@ static enum DYLD_BOOL (*ltdl_NSMakePrivateModulePublic)(NSModule module) = 0; | |||
1630 | 1644 | ||
1631 | 1645 | ||
1632 | static const char * | 1646 | static const char * |
1633 | lt_int_dyld_error(othererror) | 1647 | lt_int_dyld_error (othererror) |
1634 | char* othererror; | 1648 | char *othererror; |
1635 | { | 1649 | { |
1636 | /* return the dyld error string, or the passed in error string if none */ | 1650 | /* return the dyld error string, or the passed in error string if none */ |
1637 | NSLinkEditErrors ler; | 1651 | NSLinkEditErrors ler; |
1638 | int lerno; | 1652 | int lerno; |
1639 | const char *errstr; | 1653 | const char *errstr; |
1640 | const char *file; | 1654 | const char *file; |
1641 | NSLinkEditError(&ler,&lerno,&file,&errstr); | 1655 | NSLinkEditError (&ler, &lerno, &file, &errstr); |
1642 | if (!errstr || !strlen(errstr)) errstr = othererror; | 1656 | if (!errstr || !strlen (errstr)) |
1643 | return errstr; | 1657 | errstr = othererror; |
1658 | return errstr; | ||
1644 | } | 1659 | } |
1645 | 1660 | ||
1646 | static const struct mach_header * | 1661 | static const struct mach_header * |
1647 | lt_int_dyld_get_mach_header_from_nsmodule(module) | 1662 | lt_int_dyld_get_mach_header_from_nsmodule (module) |
1648 | NSModule module; | 1663 | NSModule module; |
1649 | { | 1664 | { |
1650 | /* There should probably be an apple dyld api for this */ | 1665 | /* There should probably be an apple dyld api for this */ |
1651 | int i=_dyld_image_count(); | 1666 | int i = _dyld_image_count (); |
1652 | int j; | 1667 | int j; |
1653 | const char *modname=NSNameOfModule(module); | 1668 | const char *modname = NSNameOfModule (module); |
1654 | const struct mach_header *mh=NULL; | 1669 | const struct mach_header *mh = NULL; |
1655 | if (!modname) return NULL; | 1670 | if (!modname) |
1656 | for (j = 0; j < i; j++) | 1671 | return NULL; |
1657 | { | 1672 | for (j = 0; j < i; j++) |
1658 | if (!strcmp(_dyld_get_image_name(j),modname)) | 1673 | { |
1659 | { | 1674 | if (!strcmp (_dyld_get_image_name (j), modname)) |
1660 | mh=_dyld_get_image_header(j); | 1675 | { |
1661 | break; | 1676 | mh = _dyld_get_image_header (j); |
1662 | } | 1677 | break; |
1663 | } | 1678 | } |
1664 | return mh; | 1679 | } |
1680 | return mh; | ||
1665 | } | 1681 | } |
1666 | 1682 | ||
1667 | static const char* lt_int_dyld_lib_install_name(mh) | 1683 | static const char * |
1668 | const struct mach_header *mh; | 1684 | lt_int_dyld_lib_install_name (mh) |
1685 | const struct mach_header *mh; | ||
1669 | { | 1686 | { |
1670 | /* NSAddImage is also used to get the loaded image, but it only works if the lib | 1687 | /* NSAddImage is also used to get the loaded image, but it only works if the lib |
1671 | is installed, for uninstalled libs we need to check the install_names against | 1688 | is installed, for uninstalled libs we need to check the install_names against |
1672 | each other. Note that this is still broken if DYLD_IMAGE_SUFFIX is set and a | 1689 | each other. Note that this is still broken if DYLD_IMAGE_SUFFIX is set and a |
1673 | different lib was loaded as a result | 1690 | different lib was loaded as a result |
1674 | */ | 1691 | */ |
1675 | int j; | 1692 | int j; |
1676 | struct load_command *lc; | 1693 | struct load_command *lc; |
1677 | unsigned long offset = sizeof(struct mach_header); | 1694 | unsigned long offset = sizeof (struct mach_header); |
1678 | const char* retStr=NULL; | 1695 | const char *retStr = NULL; |
1679 | for (j = 0; j < mh->ncmds; j++) | 1696 | for (j = 0; j < mh->ncmds; j++) |
1680 | { | 1697 | { |
1681 | lc = (struct load_command*)(((unsigned long)mh) + offset); | 1698 | lc = (struct load_command *) (((unsigned long) mh) + offset); |
1682 | if (LC_ID_DYLIB == lc->cmd) | 1699 | if (LC_ID_DYLIB == lc->cmd) |
1683 | { | 1700 | { |
1684 | retStr=(char*)(((struct dylib_command*)lc)->dylib.name.offset + | 1701 | retStr = |
1685 | (unsigned long)lc); | 1702 | (char *) (((struct dylib_command *) lc)->dylib.name.offset + |
1686 | } | 1703 | (unsigned long) lc); |
1687 | offset += lc->cmdsize; | 1704 | } |
1688 | } | 1705 | offset += lc->cmdsize; |
1689 | return retStr; | 1706 | } |
1707 | return retStr; | ||
1690 | } | 1708 | } |
1691 | 1709 | ||
1692 | static const struct mach_header * | 1710 | static const struct mach_header * |
1693 | lt_int_dyld_match_loaded_lib_by_install_name(const char *name) | 1711 | lt_int_dyld_match_loaded_lib_by_install_name (const char *name) |
1694 | { | 1712 | { |
1695 | int i=_dyld_image_count(); | 1713 | int i = _dyld_image_count (); |
1696 | int j; | 1714 | int j; |
1697 | const struct mach_header *mh=NULL; | 1715 | const struct mach_header *mh = NULL; |
1698 | const char *id=NULL; | 1716 | const char *id = NULL; |
1699 | for (j = 0; j < i; j++) | 1717 | for (j = 0; j < i; j++) |
1700 | { | 1718 | { |
1701 | id=lt_int_dyld_lib_install_name(_dyld_get_image_header(j)); | 1719 | id = lt_int_dyld_lib_install_name (_dyld_get_image_header (j)); |
1702 | if ((id) && (!strcmp(id,name))) | 1720 | if ((id) && (!strcmp (id, name))) |
1703 | { | 1721 | { |
1704 | mh=_dyld_get_image_header(j); | 1722 | mh = _dyld_get_image_header (j); |
1705 | break; | 1723 | break; |
1706 | } | 1724 | } |
1707 | } | 1725 | } |
1708 | return mh; | 1726 | return mh; |
1709 | } | 1727 | } |
1710 | 1728 | ||
1711 | static NSSymbol | 1729 | static NSSymbol |
1712 | lt_int_dyld_NSlookupSymbolInLinkedLibs(symbol,mh) | 1730 | lt_int_dyld_NSlookupSymbolInLinkedLibs (symbol, mh) |
1713 | const char *symbol; | 1731 | const char *symbol; |
1714 | const struct mach_header *mh; | 1732 | const struct mach_header *mh; |
1715 | { | 1733 | { |
1716 | /* Safe to assume our mh is good */ | 1734 | /* Safe to assume our mh is good */ |
1717 | int j; | 1735 | int j; |
1718 | struct load_command *lc; | 1736 | struct load_command *lc; |
1719 | unsigned long offset = sizeof(struct mach_header); | 1737 | unsigned long offset = sizeof (struct mach_header); |
1720 | NSSymbol retSym = 0; | 1738 | NSSymbol retSym = 0; |
1721 | const struct mach_header *mh1; | 1739 | const struct mach_header *mh1; |
1722 | if ((ltdl_NSLookupSymbolInImage) && NSIsSymbolNameDefined(symbol) ) | 1740 | if ((ltdl_NSLookupSymbolInImage) && NSIsSymbolNameDefined (symbol)) |
1723 | { | 1741 | { |
1724 | for (j = 0; j < mh->ncmds; j++) | 1742 | for (j = 0; j < mh->ncmds; j++) |
1725 | { | 1743 | { |
1726 | lc = (struct load_command*)(((unsigned long)mh) + offset); | 1744 | lc = (struct load_command *) (((unsigned long) mh) + offset); |
1727 | if ((LC_LOAD_DYLIB == lc->cmd) || (LC_LOAD_WEAK_DYLIB == lc->cmd)) | 1745 | if ((LC_LOAD_DYLIB == lc->cmd) || (LC_LOAD_WEAK_DYLIB == lc->cmd)) |
1728 | { | 1746 | { |
1729 | mh1=lt_int_dyld_match_loaded_lib_by_install_name((char*)(((struct dylib_command*)lc)->dylib.name.offset + | 1747 | mh1 = |
1730 | (unsigned long)lc)); | 1748 | lt_int_dyld_match_loaded_lib_by_install_name ((char |
1731 | if (!mh1) | 1749 | *) (((struct |
1732 | { | 1750 | dylib_command |
1733 | /* Maybe NSAddImage can find it */ | 1751 | *) lc)-> |
1734 | mh1=ltdl_NSAddImage((char*)(((struct dylib_command*)lc)->dylib.name.offset + | 1752 | dylib.name. |
1735 | (unsigned long)lc), | 1753 | offset + |
1736 | NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED + | 1754 | (unsigned |
1737 | NSADDIMAGE_OPTION_WITH_SEARCHING + | 1755 | long) |
1738 | NSADDIMAGE_OPTION_RETURN_ON_ERROR ); | 1756 | lc)); |
1739 | } | 1757 | if (!mh1) |
1740 | if (mh1) | 1758 | { |
1741 | { | 1759 | /* Maybe NSAddImage can find it */ |
1742 | retSym = ltdl_NSLookupSymbolInImage(mh1, | 1760 | mh1 = |
1743 | symbol, | 1761 | ltdl_NSAddImage ((char *) (((struct dylib_command *) lc)-> |
1744 | NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_NOW | 1762 | dylib.name.offset + |
1745 | | NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR | 1763 | (unsigned long) lc), |
1746 | ); | 1764 | NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED + |
1747 | if (retSym) break; | 1765 | NSADDIMAGE_OPTION_WITH_SEARCHING + |
1748 | } | 1766 | NSADDIMAGE_OPTION_RETURN_ON_ERROR); |
1749 | } | 1767 | } |
1750 | offset += lc->cmdsize; | 1768 | if (mh1) |
1751 | } | 1769 | { |
1752 | } | 1770 | retSym = ltdl_NSLookupSymbolInImage (mh1, |
1753 | return retSym; | 1771 | symbol, |
1772 | NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_NOW | ||
1773 | | | ||
1774 | NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR); | ||
1775 | if (retSym) | ||
1776 | break; | ||
1777 | } | ||
1778 | } | ||
1779 | offset += lc->cmdsize; | ||
1780 | } | ||
1781 | } | ||
1782 | return retSym; | ||
1754 | } | 1783 | } |
1755 | 1784 | ||
1756 | static int | 1785 | static int |
1757 | sys_dyld_init() | 1786 | sys_dyld_init () |
1758 | { | 1787 | { |
1759 | int retCode = 0; | 1788 | int retCode = 0; |
1760 | int err = 0; | 1789 | int err = 0; |
1761 | if (!_dyld_present()) { | 1790 | if (!_dyld_present ()) |
1762 | retCode=1; | 1791 | { |
1763 | } | 1792 | retCode = 1; |
1764 | else { | 1793 | } |
1765 | err = _dyld_func_lookup("__dyld_NSAddImage",(unsigned long*)<dl_NSAddImage); | 1794 | else |
1766 | err = _dyld_func_lookup("__dyld_NSLookupSymbolInImage",(unsigned long*)<dl_NSLookupSymbolInImage); | 1795 | { |
1767 | err = _dyld_func_lookup("__dyld_NSIsSymbolNameDefinedInImage",(unsigned long*)<dl_NSIsSymbolNameDefinedInImage); | 1796 | err = |
1768 | err = _dyld_func_lookup("__dyld_NSMakePrivateModulePublic",(unsigned long*)<dl_NSMakePrivateModulePublic); | 1797 | _dyld_func_lookup ("__dyld_NSAddImage", |
1769 | } | 1798 | (unsigned long *) <dl_NSAddImage); |
1770 | return retCode; | 1799 | err = |
1800 | _dyld_func_lookup ("__dyld_NSLookupSymbolInImage", | ||
1801 | (unsigned long *) <dl_NSLookupSymbolInImage); | ||
1802 | err = | ||
1803 | _dyld_func_lookup ("__dyld_NSIsSymbolNameDefinedInImage", | ||
1804 | (unsigned long *) | ||
1805 | <dl_NSIsSymbolNameDefinedInImage); | ||
1806 | err = | ||
1807 | _dyld_func_lookup ("__dyld_NSMakePrivateModulePublic", | ||
1808 | (unsigned long *) <dl_NSMakePrivateModulePublic); | ||
1809 | } | ||
1810 | return retCode; | ||
1771 | } | 1811 | } |
1772 | 1812 | ||
1773 | static lt_module | 1813 | static lt_module |
@@ -1775,35 +1815,38 @@ sys_dyld_open (loader_data, filename) | |||
1775 | lt_user_data loader_data; | 1815 | lt_user_data loader_data; |
1776 | const char *filename; | 1816 | const char *filename; |
1777 | { | 1817 | { |
1778 | lt_module module = 0; | 1818 | lt_module module = 0; |
1779 | NSObjectFileImage ofi = 0; | 1819 | NSObjectFileImage ofi = 0; |
1780 | NSObjectFileImageReturnCode ofirc; | 1820 | NSObjectFileImageReturnCode ofirc; |
1781 | 1821 | ||
1782 | if (!filename) | 1822 | if (!filename) |
1783 | return (lt_module)-1; | 1823 | return (lt_module) - 1; |
1784 | ofirc = NSCreateObjectFileImageFromFile(filename, &ofi); | 1824 | ofirc = NSCreateObjectFileImageFromFile (filename, &ofi); |
1785 | switch (ofirc) | 1825 | switch (ofirc) |
1786 | { | 1826 | { |
1787 | case NSObjectFileImageSuccess: | 1827 | case NSObjectFileImageSuccess: |
1788 | module = NSLinkModule(ofi, filename, | 1828 | module = NSLinkModule (ofi, filename, |
1789 | NSLINKMODULE_OPTION_RETURN_ON_ERROR | 1829 | NSLINKMODULE_OPTION_RETURN_ON_ERROR |
1790 | | NSLINKMODULE_OPTION_PRIVATE | 1830 | | NSLINKMODULE_OPTION_PRIVATE |
1791 | | NSLINKMODULE_OPTION_BINDNOW); | 1831 | | NSLINKMODULE_OPTION_BINDNOW); |
1792 | NSDestroyObjectFileImage(ofi); | 1832 | NSDestroyObjectFileImage (ofi); |
1793 | if (module) | 1833 | if (module) |
1794 | ltdl_NSMakePrivateModulePublic(module); | 1834 | ltdl_NSMakePrivateModulePublic (module); |
1795 | break; | 1835 | break; |
1796 | case NSObjectFileImageInappropriateFile: | 1836 | case NSObjectFileImageInappropriateFile: |
1797 | if (ltdl_NSIsSymbolNameDefinedInImage && ltdl_NSLookupSymbolInImage) | 1837 | if (ltdl_NSIsSymbolNameDefinedInImage && ltdl_NSLookupSymbolInImage) |
1798 | { | 1838 | { |
1799 | module = (lt_module)ltdl_NSAddImage(filename, NSADDIMAGE_OPTION_RETURN_ON_ERROR); | 1839 | module = |
1800 | break; | 1840 | (lt_module) ltdl_NSAddImage (filename, |
1801 | } | 1841 | NSADDIMAGE_OPTION_RETURN_ON_ERROR); |
1802 | default: | 1842 | break; |
1803 | LT_DLMUTEX_SETERROR (lt_int_dyld_error(LT_DLSTRERROR(CANNOT_OPEN))); | 1843 | } |
1804 | return 0; | 1844 | default: |
1805 | } | 1845 | LT_DLMUTEX_SETERROR (lt_int_dyld_error (LT_DLSTRERROR (CANNOT_OPEN))); |
1806 | if (!module) LT_DLMUTEX_SETERROR (lt_int_dyld_error(LT_DLSTRERROR(CANNOT_OPEN))); | 1846 | return 0; |
1847 | } | ||
1848 | if (!module) | ||
1849 | LT_DLMUTEX_SETERROR (lt_int_dyld_error (LT_DLSTRERROR (CANNOT_OPEN))); | ||
1807 | return module; | 1850 | return module; |
1808 | } | 1851 | } |
1809 | 1852 | ||
@@ -1812,43 +1855,45 @@ sys_dyld_close (loader_data, module) | |||
1812 | lt_user_data loader_data; | 1855 | lt_user_data loader_data; |
1813 | lt_module module; | 1856 | lt_module module; |
1814 | { | 1857 | { |
1815 | int retCode = 0; | 1858 | int retCode = 0; |
1816 | int flags = 0; | 1859 | int flags = 0; |
1817 | if (module == (lt_module)-1) return 0; | 1860 | if (module == (lt_module) - 1) |
1861 | return 0; | ||
1818 | #ifdef __BIG_ENDIAN__ | 1862 | #ifdef __BIG_ENDIAN__ |
1819 | if (((struct mach_header *)module)->magic == MH_MAGIC) | 1863 | if (((struct mach_header *) module)->magic == MH_MAGIC) |
1820 | #else | 1864 | #else |
1821 | if (((struct mach_header *)module)->magic == MH_CIGAM) | 1865 | if (((struct mach_header *) module)->magic == MH_CIGAM) |
1822 | #endif | 1866 | #endif |
1823 | { | 1867 | { |
1824 | LT_DLMUTEX_SETERROR("Can not close a dylib"); | 1868 | LT_DLMUTEX_SETERROR ("Can not close a dylib"); |
1825 | retCode = 1; | 1869 | retCode = 1; |
1826 | } | 1870 | } |
1827 | else | 1871 | else |
1828 | { | 1872 | { |
1829 | #if 1 | 1873 | #if 1 |
1830 | /* Currently, if a module contains c++ static destructors and it is unloaded, we | 1874 | /* Currently, if a module contains c++ static destructors and it is unloaded, we |
1831 | get a segfault in atexit(), due to compiler and dynamic loader differences of | 1875 | get a segfault in atexit(), due to compiler and dynamic loader differences of |
1832 | opinion, this works around that. | 1876 | opinion, this works around that. |
1833 | */ | 1877 | */ |
1834 | if ((const struct section *)NULL != | 1878 | if ((const struct section *) NULL != |
1835 | getsectbynamefromheader(lt_int_dyld_get_mach_header_from_nsmodule(module), | 1879 | getsectbynamefromheader (lt_int_dyld_get_mach_header_from_nsmodule |
1836 | "__DATA","__mod_term_func")) | 1880 | (module), "__DATA", "__mod_term_func")) |
1837 | { | 1881 | { |
1838 | flags += NSUNLINKMODULE_OPTION_KEEP_MEMORY_MAPPED; | 1882 | flags += NSUNLINKMODULE_OPTION_KEEP_MEMORY_MAPPED; |
1839 | } | 1883 | } |
1840 | #endif | 1884 | #endif |
1841 | #ifdef __ppc__ | 1885 | #ifdef __ppc__ |
1842 | flags += NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES; | 1886 | flags += NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES; |
1843 | #endif | 1887 | #endif |
1844 | if (!NSUnLinkModule(module,flags)) | 1888 | if (!NSUnLinkModule (module, flags)) |
1845 | { | 1889 | { |
1846 | retCode=1; | 1890 | retCode = 1; |
1847 | LT_DLMUTEX_SETERROR (lt_int_dyld_error(LT_DLSTRERROR(CANNOT_CLOSE))); | 1891 | LT_DLMUTEX_SETERROR (lt_int_dyld_error |
1848 | } | 1892 | (LT_DLSTRERROR (CANNOT_CLOSE))); |
1849 | } | 1893 | } |
1850 | 1894 | } | |
1851 | return retCode; | 1895 | |
1896 | return retCode; | ||
1852 | } | 1897 | } |
1853 | 1898 | ||
1854 | static lt_ptr | 1899 | static lt_ptr |
@@ -1857,52 +1902,57 @@ sys_dyld_sym (loader_data, module, symbol) | |||
1857 | lt_module module; | 1902 | lt_module module; |
1858 | const char *symbol; | 1903 | const char *symbol; |
1859 | { | 1904 | { |
1860 | lt_ptr address = 0; | 1905 | lt_ptr address = 0; |
1861 | NSSymbol *nssym = 0; | 1906 | NSSymbol *nssym = 0; |
1862 | void *unused; | 1907 | void *unused; |
1863 | const struct mach_header *mh=NULL; | 1908 | const struct mach_header *mh = NULL; |
1864 | char saveError[256] = "Symbol not found"; | 1909 | char saveError[256] = "Symbol not found"; |
1865 | if (module == (lt_module)-1) | 1910 | if (module == (lt_module) - 1) |
1866 | { | 1911 | { |
1867 | _dyld_lookup_and_bind(symbol,(unsigned long*)&address,&unused); | 1912 | _dyld_lookup_and_bind (symbol, (unsigned long *) &address, &unused); |
1868 | return address; | 1913 | return address; |
1869 | } | 1914 | } |
1870 | #ifdef __BIG_ENDIAN__ | 1915 | #ifdef __BIG_ENDIAN__ |
1871 | if (((struct mach_header *)module)->magic == MH_MAGIC) | 1916 | if (((struct mach_header *) module)->magic == MH_MAGIC) |
1872 | #else | 1917 | #else |
1873 | if (((struct mach_header *)module)->magic == MH_CIGAM) | 1918 | if (((struct mach_header *) module)->magic == MH_CIGAM) |
1874 | #endif | 1919 | #endif |
1875 | { | 1920 | { |
1876 | if (ltdl_NSIsSymbolNameDefinedInImage && ltdl_NSLookupSymbolInImage) | 1921 | if (ltdl_NSIsSymbolNameDefinedInImage && ltdl_NSLookupSymbolInImage) |
1877 | { | 1922 | { |
1878 | mh=module; | 1923 | mh = module; |
1879 | if (ltdl_NSIsSymbolNameDefinedInImage((struct mach_header*)module,symbol)) | 1924 | if (ltdl_NSIsSymbolNameDefinedInImage |
1880 | { | 1925 | ((struct mach_header *) module, symbol)) |
1881 | nssym = ltdl_NSLookupSymbolInImage((struct mach_header*)module, | 1926 | { |
1882 | symbol, | 1927 | nssym = |
1883 | NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_NOW | 1928 | ltdl_NSLookupSymbolInImage ((struct mach_header *) module, |
1884 | | NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR | 1929 | symbol, |
1885 | ); | 1930 | NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_NOW |
1886 | } | 1931 | | |
1887 | } | 1932 | NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR); |
1888 | 1933 | } | |
1889 | } | 1934 | } |
1890 | else { | 1935 | |
1891 | nssym = NSLookupSymbolInModule(module, symbol); | 1936 | } |
1892 | } | 1937 | else |
1893 | if (!nssym) | 1938 | { |
1894 | { | 1939 | nssym = NSLookupSymbolInModule (module, symbol); |
1895 | strncpy(saveError, lt_int_dyld_error(LT_DLSTRERROR(SYMBOL_NOT_FOUND)), 255); | 1940 | } |
1896 | saveError[255] = 0; | 1941 | if (!nssym) |
1897 | if (!mh) mh=lt_int_dyld_get_mach_header_from_nsmodule(module); | 1942 | { |
1898 | nssym = lt_int_dyld_NSlookupSymbolInLinkedLibs(symbol,mh); | 1943 | strncpy (saveError, |
1899 | } | 1944 | lt_int_dyld_error (LT_DLSTRERROR (SYMBOL_NOT_FOUND)), 255); |
1900 | if (!nssym) | 1945 | saveError[255] = 0; |
1901 | { | 1946 | if (!mh) |
1902 | LT_DLMUTEX_SETERROR (saveError); | 1947 | mh = lt_int_dyld_get_mach_header_from_nsmodule (module); |
1903 | return NULL; | 1948 | nssym = lt_int_dyld_NSlookupSymbolInLinkedLibs (symbol, mh); |
1904 | } | 1949 | } |
1905 | return NSAddressOfSymbol(nssym); | 1950 | if (!nssym) |
1951 | { | ||
1952 | LT_DLMUTEX_SETERROR (saveError); | ||
1953 | return NULL; | ||
1954 | } | ||
1955 | return NSAddressOfSymbol (nssym); | ||
1906 | } | 1956 | } |
1907 | 1957 | ||
1908 | static struct lt_user_dlloader sys_dyld = | 1958 | static struct lt_user_dlloader sys_dyld = |
@@ -1910,8 +1960,8 @@ static struct lt_user_dlloader sys_dyld = | |||
1910 | 1960 | ||
1911 | 1961 | ||
1912 | #endif /* HAVE_DYLD */ | 1962 | #endif /* HAVE_DYLD */ |
1913 | |||
1914 | 1963 | ||
1964 | |||
1915 | /* --- DLPREOPEN() INTERFACE LOADER --- */ | 1965 | /* --- DLPREOPEN() INTERFACE LOADER --- */ |
1916 | 1966 | ||
1917 | 1967 | ||
@@ -1919,12 +1969,12 @@ static struct lt_user_dlloader sys_dyld = | |||
1919 | 1969 | ||
1920 | typedef struct lt_dlsymlists_t | 1970 | typedef struct lt_dlsymlists_t |
1921 | { | 1971 | { |
1922 | struct lt_dlsymlists_t *next; | 1972 | struct lt_dlsymlists_t *next; |
1923 | const lt_dlsymlist *syms; | 1973 | const lt_dlsymlist *syms; |
1924 | } lt_dlsymlists_t; | 1974 | } lt_dlsymlists_t; |
1925 | 1975 | ||
1926 | static const lt_dlsymlist *default_preloaded_symbols = 0; | 1976 | static const lt_dlsymlist *default_preloaded_symbols = 0; |
1927 | static lt_dlsymlists_t *preloaded_symbols = 0; | 1977 | static lt_dlsymlists_t *preloaded_symbols = 0; |
1928 | 1978 | ||
1929 | static int | 1979 | static int |
1930 | presym_init (loader_data) | 1980 | presym_init (loader_data) |
@@ -1955,7 +2005,7 @@ presym_free_symlists () | |||
1955 | lists = preloaded_symbols; | 2005 | lists = preloaded_symbols; |
1956 | while (lists) | 2006 | while (lists) |
1957 | { | 2007 | { |
1958 | lt_dlsymlists_t *tmp = lists; | 2008 | lt_dlsymlists_t *tmp = lists; |
1959 | 2009 | ||
1960 | lists = lists->next; | 2010 | lists = lists->next; |
1961 | LT_DLFREE (tmp); | 2011 | LT_DLFREE (tmp); |
@@ -1981,7 +2031,7 @@ presym_add_symlist (preloaded) | |||
1981 | { | 2031 | { |
1982 | lt_dlsymlists_t *tmp; | 2032 | lt_dlsymlists_t *tmp; |
1983 | lt_dlsymlists_t *lists; | 2033 | lt_dlsymlists_t *lists; |
1984 | int errors = 0; | 2034 | int errors = 0; |
1985 | 2035 | ||
1986 | LT_DLMUTEX_LOCK (); | 2036 | LT_DLMUTEX_LOCK (); |
1987 | 2037 | ||
@@ -1989,16 +2039,16 @@ presym_add_symlist (preloaded) | |||
1989 | while (lists) | 2039 | while (lists) |
1990 | { | 2040 | { |
1991 | if (lists->syms == preloaded) | 2041 | if (lists->syms == preloaded) |
1992 | { | 2042 | { |
1993 | goto done; | 2043 | goto done; |
1994 | } | 2044 | } |
1995 | lists = lists->next; | 2045 | lists = lists->next; |
1996 | } | 2046 | } |
1997 | 2047 | ||
1998 | tmp = LT_EMALLOC (lt_dlsymlists_t, 1); | 2048 | tmp = LT_EMALLOC (lt_dlsymlists_t, 1); |
1999 | if (tmp) | 2049 | if (tmp) |
2000 | { | 2050 | { |
2001 | memset (tmp, 0, sizeof(lt_dlsymlists_t)); | 2051 | memset (tmp, 0, sizeof (lt_dlsymlists_t)); |
2002 | tmp->syms = preloaded; | 2052 | tmp->syms = preloaded; |
2003 | tmp->next = preloaded_symbols; | 2053 | tmp->next = preloaded_symbols; |
2004 | preloaded_symbols = tmp; | 2054 | preloaded_symbols = tmp; |
@@ -2008,7 +2058,7 @@ presym_add_symlist (preloaded) | |||
2008 | ++errors; | 2058 | ++errors; |
2009 | } | 2059 | } |
2010 | 2060 | ||
2011 | done: | 2061 | done: |
2012 | LT_DLMUTEX_UNLOCK (); | 2062 | LT_DLMUTEX_UNLOCK (); |
2013 | return errors; | 2063 | return errors; |
2014 | } | 2064 | } |
@@ -2019,7 +2069,7 @@ presym_open (loader_data, filename) | |||
2019 | const char *filename; | 2069 | const char *filename; |
2020 | { | 2070 | { |
2021 | lt_dlsymlists_t *lists; | 2071 | lt_dlsymlists_t *lists; |
2022 | lt_module module = (lt_module) 0; | 2072 | lt_module module = (lt_module) 0; |
2023 | 2073 | ||
2024 | LT_DLMUTEX_LOCK (); | 2074 | LT_DLMUTEX_LOCK (); |
2025 | lists = preloaded_symbols; | 2075 | lists = preloaded_symbols; |
@@ -2044,21 +2094,21 @@ presym_open (loader_data, filename) | |||
2044 | const lt_dlsymlist *syms = lists->syms; | 2094 | const lt_dlsymlist *syms = lists->syms; |
2045 | 2095 | ||
2046 | while (syms->name) | 2096 | while (syms->name) |
2047 | { | 2097 | { |
2048 | if (!syms->address && strcmp(syms->name, filename) == 0) | 2098 | if (!syms->address && strcmp (syms->name, filename) == 0) |
2049 | { | 2099 | { |
2050 | module = (lt_module) syms; | 2100 | module = (lt_module) syms; |
2051 | goto done; | 2101 | goto done; |
2052 | } | 2102 | } |
2053 | ++syms; | 2103 | ++syms; |
2054 | } | 2104 | } |
2055 | 2105 | ||
2056 | lists = lists->next; | 2106 | lists = lists->next; |
2057 | } | 2107 | } |
2058 | 2108 | ||
2059 | LT_DLMUTEX_SETERROR (LT_DLSTRERROR (FILE_NOT_FOUND)); | 2109 | LT_DLMUTEX_SETERROR (LT_DLSTRERROR (FILE_NOT_FOUND)); |
2060 | 2110 | ||
2061 | done: | 2111 | done: |
2062 | LT_DLMUTEX_UNLOCK (); | 2112 | LT_DLMUTEX_UNLOCK (); |
2063 | return module; | 2113 | return module; |
2064 | } | 2114 | } |
@@ -2079,18 +2129,18 @@ presym_sym (loader_data, module, symbol) | |||
2079 | lt_module module; | 2129 | lt_module module; |
2080 | const char *symbol; | 2130 | const char *symbol; |
2081 | { | 2131 | { |
2082 | lt_dlsymlist *syms = (lt_dlsymlist*) module; | 2132 | lt_dlsymlist *syms = (lt_dlsymlist *) module; |
2083 | 2133 | ||
2084 | ++syms; | 2134 | ++syms; |
2085 | while (syms->address) | 2135 | while (syms->address) |
2086 | { | 2136 | { |
2087 | if (strcmp(syms->name, symbol) == 0) | 2137 | if (strcmp (syms->name, symbol) == 0) |
2088 | { | 2138 | { |
2089 | return syms->address; | 2139 | return syms->address; |
2090 | } | 2140 | } |
2091 | 2141 | ||
2092 | ++syms; | 2142 | ++syms; |
2093 | } | 2143 | } |
2094 | 2144 | ||
2095 | LT_DLMUTEX_SETERROR (LT_DLSTRERROR (SYMBOL_NOT_FOUND)); | 2145 | LT_DLMUTEX_SETERROR (LT_DLSTRERROR (SYMBOL_NOT_FOUND)); |
2096 | 2146 | ||
@@ -2100,88 +2150,80 @@ presym_sym (loader_data, module, symbol) | |||
2100 | static struct lt_user_dlloader presym = { | 2150 | static struct lt_user_dlloader presym = { |
2101 | 0, presym_open, presym_close, presym_sym, presym_exit, 0 | 2151 | 0, presym_open, presym_close, presym_sym, presym_exit, 0 |
2102 | }; | 2152 | }; |
2153 | |||
2103 | 2154 | ||
2104 | 2155 | ||
2105 | 2156 | ||
2106 | 2157 | ||
2107 | |||
2108 | /* --- DYNAMIC MODULE LOADING --- */ | 2158 | /* --- DYNAMIC MODULE LOADING --- */ |
2109 | 2159 | ||
2110 | 2160 | ||
2111 | /* The type of a function used at each iteration of foreach_dirinpath(). */ | 2161 | /* The type of a function used at each iteration of foreach_dirinpath(). */ |
2112 | typedef int foreach_callback_func LT_PARAMS((char *filename, lt_ptr data1, | 2162 | typedef int foreach_callback_func LT_PARAMS ((char *filename, lt_ptr data1, |
2113 | lt_ptr data2)); | 2163 | lt_ptr data2)); |
2114 | 2164 | ||
2115 | static int foreach_dirinpath LT_PARAMS((const char *search_path, | 2165 | static int foreach_dirinpath LT_PARAMS ((const char *search_path, |
2116 | const char *base_name, | 2166 | const char *base_name, |
2117 | foreach_callback_func *func, | 2167 | foreach_callback_func * func, |
2118 | lt_ptr data1, lt_ptr data2)); | 2168 | lt_ptr data1, lt_ptr data2)); |
2119 | 2169 | ||
2120 | static int find_file_callback LT_PARAMS((char *filename, lt_ptr data, | 2170 | static int find_file_callback LT_PARAMS ((char *filename, lt_ptr data, |
2121 | lt_ptr ignored)); | 2171 | lt_ptr ignored)); |
2122 | static int find_handle_callback LT_PARAMS((char *filename, lt_ptr data, | 2172 | static int find_handle_callback LT_PARAMS ((char *filename, lt_ptr data, |
2123 | lt_ptr ignored)); | 2173 | lt_ptr ignored)); |
2124 | static int foreachfile_callback LT_PARAMS((char *filename, lt_ptr data1, | 2174 | static int foreachfile_callback LT_PARAMS ((char *filename, lt_ptr data1, |
2125 | lt_ptr data2)); | 2175 | lt_ptr data2)); |
2126 | 2176 | ||
2127 | 2177 | ||
2128 | static int canonicalize_path LT_PARAMS((const char *path, | 2178 | static int canonicalize_path LT_PARAMS ((const char *path, |
2129 | char **pcanonical)); | 2179 | char **pcanonical)); |
2130 | static int argzize_path LT_PARAMS((const char *path, | 2180 | static int argzize_path LT_PARAMS ((const char *path, |
2131 | char **pargz, | 2181 | char **pargz, size_t * pargz_len)); |
2132 | size_t *pargz_len)); | 2182 | static FILE *find_file LT_PARAMS ((const char *search_path, |
2133 | static FILE *find_file LT_PARAMS((const char *search_path, | 2183 | const char *base_name, char **pdir)); |
2134 | const char *base_name, | 2184 | static lt_dlhandle *find_handle LT_PARAMS ((const char *search_path, |
2135 | char **pdir)); | 2185 | const char *base_name, |
2136 | static lt_dlhandle *find_handle LT_PARAMS((const char *search_path, | 2186 | lt_dlhandle * handle)); |
2137 | const char *base_name, | 2187 | static int find_module LT_PARAMS ((lt_dlhandle * handle, |
2138 | lt_dlhandle *handle)); | 2188 | const char *dir, |
2139 | static int find_module LT_PARAMS((lt_dlhandle *handle, | 2189 | const char *libdir, |
2140 | const char *dir, | 2190 | const char *dlname, |
2141 | const char *libdir, | 2191 | const char *old_name, int installed)); |
2142 | const char *dlname, | 2192 | static int free_vars LT_PARAMS ((char *dlname, char *oldname, |
2143 | const char *old_name, | 2193 | char *libdir, char *deplibs)); |
2144 | int installed)); | 2194 | static int load_deplibs LT_PARAMS ((lt_dlhandle handle, char *deplibs)); |
2145 | static int free_vars LT_PARAMS((char *dlname, char *oldname, | 2195 | static int trim LT_PARAMS ((char **dest, const char *str)); |
2146 | char *libdir, char *deplibs)); | 2196 | static int try_dlopen LT_PARAMS ((lt_dlhandle * handle, |
2147 | static int load_deplibs LT_PARAMS((lt_dlhandle handle, | 2197 | const char *filename)); |
2148 | char *deplibs)); | 2198 | static int tryall_dlopen LT_PARAMS ((lt_dlhandle * handle, |
2149 | static int trim LT_PARAMS((char **dest, | 2199 | const char *filename)); |
2150 | const char *str)); | 2200 | static int unload_deplibs LT_PARAMS ((lt_dlhandle handle)); |
2151 | static int try_dlopen LT_PARAMS((lt_dlhandle *handle, | 2201 | static int lt_argz_insert LT_PARAMS ((char **pargz, |
2152 | const char *filename)); | 2202 | size_t * pargz_len, |
2153 | static int tryall_dlopen LT_PARAMS((lt_dlhandle *handle, | 2203 | char *before, const char *entry)); |
2154 | const char *filename)); | 2204 | static int lt_argz_insertinorder LT_PARAMS ((char **pargz, |
2155 | static int unload_deplibs LT_PARAMS((lt_dlhandle handle)); | 2205 | size_t * pargz_len, |
2156 | static int lt_argz_insert LT_PARAMS((char **pargz, | 2206 | const char *entry)); |
2157 | size_t *pargz_len, | 2207 | static int lt_argz_insertdir LT_PARAMS ((char **pargz, |
2158 | char *before, | 2208 | size_t * pargz_len, |
2159 | const char *entry)); | 2209 | const char *dirnam, |
2160 | static int lt_argz_insertinorder LT_PARAMS((char **pargz, | 2210 | struct dirent * dp)); |
2161 | size_t *pargz_len, | 2211 | static int lt_dlpath_insertdir LT_PARAMS ((char **ppath, |
2162 | const char *entry)); | 2212 | char *before, const char *dir)); |
2163 | static int lt_argz_insertdir LT_PARAMS((char **pargz, | 2213 | static int list_files_by_dir LT_PARAMS ((const char *dirnam, |
2164 | size_t *pargz_len, | 2214 | char **pargz, size_t * pargz_len)); |
2165 | const char *dirnam, | 2215 | static int file_not_found LT_PARAMS ((void)); |
2166 | struct dirent *dp)); | 2216 | |
2167 | static int lt_dlpath_insertdir LT_PARAMS((char **ppath, | 2217 | static char *user_search_path = 0; |
2168 | char *before, | 2218 | static lt_dlloader *loaders = 0; |
2169 | const char *dir)); | 2219 | static lt_dlhandle handles = 0; |
2170 | static int list_files_by_dir LT_PARAMS((const char *dirnam, | 2220 | static int initialized = 0; |
2171 | char **pargz, | ||
2172 | size_t *pargz_len)); | ||
2173 | static int file_not_found LT_PARAMS((void)); | ||
2174 | |||
2175 | static char *user_search_path= 0; | ||
2176 | static lt_dlloader *loaders = 0; | ||
2177 | static lt_dlhandle handles = 0; | ||
2178 | static int initialized = 0; | ||
2179 | 2221 | ||
2180 | /* Initialize libltdl. */ | 2222 | /* Initialize libltdl. */ |
2181 | int | 2223 | int |
2182 | lt_dlinit () | 2224 | lt_dlinit () |
2183 | { | 2225 | { |
2184 | int errors = 0; | 2226 | int errors = 0; |
2185 | 2227 | ||
2186 | LT_DLMUTEX_LOCK (); | 2228 | LT_DLMUTEX_LOCK (); |
2187 | 2229 | ||
@@ -2189,7 +2231,7 @@ lt_dlinit () | |||
2189 | if (++initialized == 1) | 2231 | if (++initialized == 1) |
2190 | { | 2232 | { |
2191 | handles = 0; | 2233 | handles = 0; |
2192 | user_search_path = 0; /* empty search path */ | 2234 | user_search_path = 0; /* empty search path */ |
2193 | 2235 | ||
2194 | #if HAVE_LIBDL | 2236 | #if HAVE_LIBDL |
2195 | errors += lt_dlloader_add (lt_dlloader_next (0), &sys_dl, "dlopen"); | 2237 | errors += lt_dlloader_add (lt_dlloader_next (0), &sys_dl, "dlopen"); |
@@ -2207,21 +2249,21 @@ lt_dlinit () | |||
2207 | errors += lt_dlloader_add (lt_dlloader_next (0), &sys_dld, "dld"); | 2249 | errors += lt_dlloader_add (lt_dlloader_next (0), &sys_dld, "dld"); |
2208 | #endif | 2250 | #endif |
2209 | #if HAVE_DYLD | 2251 | #if HAVE_DYLD |
2210 | errors += lt_dlloader_add (lt_dlloader_next (0), &sys_dyld, "dyld"); | 2252 | errors += lt_dlloader_add (lt_dlloader_next (0), &sys_dyld, "dyld"); |
2211 | errors += sys_dyld_init(); | 2253 | errors += sys_dyld_init (); |
2212 | #endif | 2254 | #endif |
2213 | errors += lt_dlloader_add (lt_dlloader_next (0), &presym, "dlpreload"); | 2255 | errors += lt_dlloader_add (lt_dlloader_next (0), &presym, "dlpreload"); |
2214 | 2256 | ||
2215 | if (presym_init (presym.dlloader_data)) | 2257 | if (presym_init (presym.dlloader_data)) |
2216 | { | 2258 | { |
2217 | LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INIT_LOADER)); | 2259 | LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INIT_LOADER)); |
2218 | ++errors; | 2260 | ++errors; |
2219 | } | 2261 | } |
2220 | else if (errors != 0) | 2262 | else if (errors != 0) |
2221 | { | 2263 | { |
2222 | LT_DLMUTEX_SETERROR (LT_DLSTRERROR (DLOPEN_NOT_SUPPORTED)); | 2264 | LT_DLMUTEX_SETERROR (LT_DLSTRERROR (DLOPEN_NOT_SUPPORTED)); |
2223 | ++errors; | 2265 | ++errors; |
2224 | } | 2266 | } |
2225 | } | 2267 | } |
2226 | 2268 | ||
2227 | LT_DLMUTEX_UNLOCK (); | 2269 | LT_DLMUTEX_UNLOCK (); |
@@ -2241,13 +2283,13 @@ lt_dlpreload (preloaded) | |||
2241 | } | 2283 | } |
2242 | else | 2284 | else |
2243 | { | 2285 | { |
2244 | presym_free_symlists(); | 2286 | presym_free_symlists (); |
2245 | 2287 | ||
2246 | LT_DLMUTEX_LOCK (); | 2288 | LT_DLMUTEX_LOCK (); |
2247 | if (default_preloaded_symbols) | 2289 | if (default_preloaded_symbols) |
2248 | { | 2290 | { |
2249 | errors = lt_dlpreload (default_preloaded_symbols); | 2291 | errors = lt_dlpreload (default_preloaded_symbols); |
2250 | } | 2292 | } |
2251 | LT_DLMUTEX_UNLOCK (); | 2293 | LT_DLMUTEX_UNLOCK (); |
2252 | } | 2294 | } |
2253 | 2295 | ||
@@ -2269,7 +2311,7 @@ lt_dlexit () | |||
2269 | { | 2311 | { |
2270 | /* shut down libltdl */ | 2312 | /* shut down libltdl */ |
2271 | lt_dlloader *loader; | 2313 | lt_dlloader *loader; |
2272 | int errors = 0; | 2314 | int errors = 0; |
2273 | 2315 | ||
2274 | LT_DLMUTEX_LOCK (); | 2316 | LT_DLMUTEX_LOCK (); |
2275 | loader = loaders; | 2317 | loader = loaders; |
@@ -2284,54 +2326,54 @@ lt_dlexit () | |||
2284 | /* shut down only at last call. */ | 2326 | /* shut down only at last call. */ |
2285 | if (--initialized == 0) | 2327 | if (--initialized == 0) |
2286 | { | 2328 | { |
2287 | int level; | 2329 | int level; |
2288 | 2330 | ||
2289 | while (handles && LT_DLIS_RESIDENT (handles)) | 2331 | while (handles && LT_DLIS_RESIDENT (handles)) |
2290 | { | 2332 | { |
2291 | handles = handles->next; | 2333 | handles = handles->next; |
2292 | } | 2334 | } |
2293 | 2335 | ||
2294 | /* close all modules */ | 2336 | /* close all modules */ |
2295 | for (level = 1; handles; ++level) | 2337 | for (level = 1; handles; ++level) |
2296 | { | 2338 | { |
2297 | lt_dlhandle cur = handles; | 2339 | lt_dlhandle cur = handles; |
2298 | int saw_nonresident = 0; | 2340 | int saw_nonresident = 0; |
2299 | 2341 | ||
2300 | while (cur) | 2342 | while (cur) |
2301 | { | 2343 | { |
2302 | lt_dlhandle tmp = cur; | 2344 | lt_dlhandle tmp = cur; |
2303 | cur = cur->next; | 2345 | cur = cur->next; |
2304 | if (!LT_DLIS_RESIDENT (tmp)) | 2346 | if (!LT_DLIS_RESIDENT (tmp)) |
2305 | saw_nonresident = 1; | 2347 | saw_nonresident = 1; |
2306 | if (!LT_DLIS_RESIDENT (tmp) && tmp->info.ref_count <= level) | 2348 | if (!LT_DLIS_RESIDENT (tmp) && tmp->info.ref_count <= level) |
2307 | { | 2349 | { |
2308 | if (lt_dlclose (tmp)) | 2350 | if (lt_dlclose (tmp)) |
2309 | { | 2351 | { |
2310 | ++errors; | 2352 | ++errors; |
2311 | } | 2353 | } |
2312 | } | 2354 | } |
2313 | } | 2355 | } |
2314 | /* done if only resident modules are left */ | 2356 | /* done if only resident modules are left */ |
2315 | if (!saw_nonresident) | 2357 | if (!saw_nonresident) |
2316 | break; | 2358 | break; |
2317 | } | 2359 | } |
2318 | 2360 | ||
2319 | /* close all loaders */ | 2361 | /* close all loaders */ |
2320 | while (loader) | 2362 | while (loader) |
2321 | { | 2363 | { |
2322 | lt_dlloader *next = loader->next; | 2364 | lt_dlloader *next = loader->next; |
2323 | lt_user_data data = loader->dlloader_data; | 2365 | lt_user_data data = loader->dlloader_data; |
2324 | if (loader->dlloader_exit && loader->dlloader_exit (data)) | 2366 | if (loader->dlloader_exit && loader->dlloader_exit (data)) |
2325 | { | 2367 | { |
2326 | ++errors; | 2368 | ++errors; |
2327 | } | 2369 | } |
2328 | 2370 | ||
2329 | LT_DLMEM_REASSIGN (loader, next); | 2371 | LT_DLMEM_REASSIGN (loader, next); |
2330 | } | 2372 | } |
2331 | loaders = 0; | 2373 | loaders = 0; |
2332 | } | 2374 | } |
2333 | 2375 | ||
2334 | done: | 2376 | done: |
2335 | LT_DLMUTEX_UNLOCK (); | 2377 | LT_DLMUTEX_UNLOCK (); |
2336 | return errors; | 2378 | return errors; |
2337 | } | 2379 | } |
@@ -2341,15 +2383,15 @@ tryall_dlopen (handle, filename) | |||
2341 | lt_dlhandle *handle; | 2383 | lt_dlhandle *handle; |
2342 | const char *filename; | 2384 | const char *filename; |
2343 | { | 2385 | { |
2344 | lt_dlhandle cur; | 2386 | lt_dlhandle cur; |
2345 | lt_dlloader *loader; | 2387 | lt_dlloader *loader; |
2346 | const char *saved_error; | 2388 | const char *saved_error; |
2347 | int errors = 0; | 2389 | int errors = 0; |
2348 | 2390 | ||
2349 | LT_DLMUTEX_GETERROR (saved_error); | 2391 | LT_DLMUTEX_GETERROR (saved_error); |
2350 | LT_DLMUTEX_LOCK (); | 2392 | LT_DLMUTEX_LOCK (); |
2351 | 2393 | ||
2352 | cur = handles; | 2394 | cur = handles; |
2353 | loader = loaders; | 2395 | loader = loaders; |
2354 | 2396 | ||
2355 | /* check whether the module was already opened */ | 2397 | /* check whether the module was already opened */ |
@@ -2357,15 +2399,15 @@ tryall_dlopen (handle, filename) | |||
2357 | { | 2399 | { |
2358 | /* try to dlopen the program itself? */ | 2400 | /* try to dlopen the program itself? */ |
2359 | if (!cur->info.filename && !filename) | 2401 | if (!cur->info.filename && !filename) |
2360 | { | 2402 | { |
2361 | break; | 2403 | break; |
2362 | } | 2404 | } |
2363 | 2405 | ||
2364 | if (cur->info.filename && filename | 2406 | if (cur->info.filename && filename |
2365 | && strcmp (cur->info.filename, filename) == 0) | 2407 | && strcmp (cur->info.filename, filename) == 0) |
2366 | { | 2408 | { |
2367 | break; | 2409 | break; |
2368 | } | 2410 | } |
2369 | 2411 | ||
2370 | cur = cur->next; | 2412 | cur = cur->next; |
2371 | } | 2413 | } |
@@ -2381,23 +2423,23 @@ tryall_dlopen (handle, filename) | |||
2381 | if (filename) | 2423 | if (filename) |
2382 | { | 2424 | { |
2383 | /* Comment out the check of file permissions using access. | 2425 | /* Comment out the check of file permissions using access. |
2384 | This call seems to always return -1 with error EACCES. | 2426 | This call seems to always return -1 with error EACCES. |
2385 | */ | 2427 | */ |
2386 | /* We need to catch missing file errors early so that | 2428 | /* We need to catch missing file errors early so that |
2387 | file_not_found() can detect what happened. | 2429 | file_not_found() can detect what happened. |
2388 | if (access (filename, R_OK) != 0) | 2430 | if (access (filename, R_OK) != 0) |
2389 | { | 2431 | { |
2390 | LT_DLMUTEX_SETERROR (LT_DLSTRERROR (FILE_NOT_FOUND)); | 2432 | LT_DLMUTEX_SETERROR (LT_DLSTRERROR (FILE_NOT_FOUND)); |
2391 | ++errors; | 2433 | ++errors; |
2392 | goto done; | 2434 | goto done; |
2393 | } */ | 2435 | } */ |
2394 | 2436 | ||
2395 | cur->info.filename = lt_estrdup (filename); | 2437 | cur->info.filename = lt_estrdup (filename); |
2396 | if (!cur->info.filename) | 2438 | if (!cur->info.filename) |
2397 | { | 2439 | { |
2398 | ++errors; | 2440 | ++errors; |
2399 | goto done; | 2441 | goto done; |
2400 | } | 2442 | } |
2401 | } | 2443 | } |
2402 | else | 2444 | else |
2403 | { | 2445 | { |
@@ -2411,9 +2453,9 @@ tryall_dlopen (handle, filename) | |||
2411 | cur->module = loader->module_open (data, filename); | 2453 | cur->module = loader->module_open (data, filename); |
2412 | 2454 | ||
2413 | if (cur->module != 0) | 2455 | if (cur->module != 0) |
2414 | { | 2456 | { |
2415 | break; | 2457 | break; |
2416 | } | 2458 | } |
2417 | loader = loader->next; | 2459 | loader = loader->next; |
2418 | } | 2460 | } |
2419 | 2461 | ||
@@ -2424,10 +2466,10 @@ tryall_dlopen (handle, filename) | |||
2424 | goto done; | 2466 | goto done; |
2425 | } | 2467 | } |
2426 | 2468 | ||
2427 | cur->loader = loader; | 2469 | cur->loader = loader; |
2428 | LT_DLMUTEX_SETERROR (saved_error); | 2470 | LT_DLMUTEX_SETERROR (saved_error); |
2429 | 2471 | ||
2430 | done: | 2472 | done: |
2431 | LT_DLMUTEX_UNLOCK (); | 2473 | LT_DLMUTEX_UNLOCK (); |
2432 | 2474 | ||
2433 | return errors; | 2475 | return errors; |
@@ -2440,10 +2482,10 @@ tryall_dlopen_module (handle, prefix, dirname, dlname) | |||
2440 | const char *dirname; | 2482 | const char *dirname; |
2441 | const char *dlname; | 2483 | const char *dlname; |
2442 | { | 2484 | { |
2443 | int error = 0; | 2485 | int error = 0; |
2444 | char *filename = 0; | 2486 | char *filename = 0; |
2445 | size_t filename_len = 0; | 2487 | size_t filename_len = 0; |
2446 | size_t dirname_len = LT_STRLEN (dirname); | 2488 | size_t dirname_len = LT_STRLEN (dirname); |
2447 | 2489 | ||
2448 | assert (handle); | 2490 | assert (handle); |
2449 | assert (dirname); | 2491 | assert (dirname); |
@@ -2455,13 +2497,13 @@ tryall_dlopen_module (handle, prefix, dirname, dlname) | |||
2455 | #endif | 2497 | #endif |
2456 | 2498 | ||
2457 | if (dirname_len > 0) | 2499 | if (dirname_len > 0) |
2458 | if (dirname[dirname_len -1] == '/') | 2500 | if (dirname[dirname_len - 1] == '/') |
2459 | --dirname_len; | 2501 | --dirname_len; |
2460 | filename_len = dirname_len + 1 + LT_STRLEN (dlname); | 2502 | filename_len = dirname_len + 1 + LT_STRLEN (dlname); |
2461 | 2503 | ||
2462 | /* Allocate memory, and combine DIRNAME and MODULENAME into it. | 2504 | /* Allocate memory, and combine DIRNAME and MODULENAME into it. |
2463 | The PREFIX (if any) is handled below. */ | 2505 | The PREFIX (if any) is handled below. */ |
2464 | filename = LT_EMALLOC (char, dirname_len + 1 + filename_len + 1); | 2506 | filename = LT_EMALLOC (char, dirname_len + 1 + filename_len + 1); |
2465 | if (!filename) | 2507 | if (!filename) |
2466 | return 1; | 2508 | return 1; |
2467 | 2509 | ||
@@ -2473,7 +2515,7 @@ tryall_dlopen_module (handle, prefix, dirname, dlname) | |||
2473 | if (prefix) | 2515 | if (prefix) |
2474 | { | 2516 | { |
2475 | error += tryall_dlopen_module (handle, | 2517 | error += tryall_dlopen_module (handle, |
2476 | (const char *) 0, prefix, filename); | 2518 | (const char *) 0, prefix, filename); |
2477 | } | 2519 | } |
2478 | else if (tryall_dlopen (handle, filename) != 0) | 2520 | else if (tryall_dlopen (handle, filename) != 0) |
2479 | { | 2521 | { |
@@ -2506,24 +2548,23 @@ find_module (handle, dir, libdir, dlname, old_name, installed) | |||
2506 | { | 2548 | { |
2507 | /* try to open the installed module */ | 2549 | /* try to open the installed module */ |
2508 | if (installed && libdir) | 2550 | if (installed && libdir) |
2509 | { | 2551 | { |
2510 | if (tryall_dlopen_module (handle, | 2552 | if (tryall_dlopen_module (handle, |
2511 | (const char *) 0, libdir, dlname) == 0) | 2553 | (const char *) 0, libdir, dlname) == 0) |
2512 | return 0; | 2554 | return 0; |
2513 | } | 2555 | } |
2514 | 2556 | ||
2515 | /* try to open the not-installed module */ | 2557 | /* try to open the not-installed module */ |
2516 | if (!installed) | 2558 | if (!installed) |
2517 | { | 2559 | { |
2518 | if (tryall_dlopen_module (handle, dir, objdir, dlname) == 0) | 2560 | if (tryall_dlopen_module (handle, dir, objdir, dlname) == 0) |
2519 | return 0; | 2561 | return 0; |
2520 | } | 2562 | } |
2521 | 2563 | ||
2522 | /* maybe it was moved to another directory */ | 2564 | /* maybe it was moved to another directory */ |
2523 | { | 2565 | { |
2524 | if (tryall_dlopen_module (handle, | 2566 | if (tryall_dlopen_module (handle, (const char *) 0, dir, dlname) == 0) |
2525 | (const char *) 0, dir, dlname) == 0) | 2567 | return 0; |
2526 | return 0; | ||
2527 | } | 2568 | } |
2528 | } | 2569 | } |
2529 | 2570 | ||
@@ -2541,7 +2582,7 @@ canonicalize_path (path, pcanonical) | |||
2541 | assert (path && *path); | 2582 | assert (path && *path); |
2542 | assert (pcanonical); | 2583 | assert (pcanonical); |
2543 | 2584 | ||
2544 | canonical = LT_EMALLOC (char, 1+ LT_STRLEN (path)); | 2585 | canonical = LT_EMALLOC (char, 1 + LT_STRLEN (path)); |
2545 | if (!canonical) | 2586 | if (!canonical) |
2546 | return 1; | 2587 | return 1; |
2547 | 2588 | ||
@@ -2550,38 +2591,38 @@ canonicalize_path (path, pcanonical) | |||
2550 | size_t src; | 2591 | size_t src; |
2551 | for (src = 0; path[src] != LT_EOS_CHAR; ++src) | 2592 | for (src = 0; path[src] != LT_EOS_CHAR; ++src) |
2552 | { | 2593 | { |
2553 | /* Path separators are not copied to the beginning or end of | 2594 | /* Path separators are not copied to the beginning or end of |
2554 | the destination, or if another separator would follow | 2595 | the destination, or if another separator would follow |
2555 | immediately. */ | 2596 | immediately. */ |
2556 | if (path[src] == LT_PATHSEP_CHAR) | 2597 | if (path[src] == LT_PATHSEP_CHAR) |
2557 | { | 2598 | { |
2558 | if ((dest == 0) | 2599 | if ((dest == 0) |
2559 | || (path[1+ src] == LT_PATHSEP_CHAR) | 2600 | || (path[1 + src] == LT_PATHSEP_CHAR) |
2560 | || (path[1+ src] == LT_EOS_CHAR)) | 2601 | || (path[1 + src] == LT_EOS_CHAR)) |
2561 | continue; | 2602 | continue; |
2562 | } | 2603 | } |
2563 | 2604 | ||
2564 | /* Anything other than a directory separator is copied verbatim. */ | 2605 | /* Anything other than a directory separator is copied verbatim. */ |
2565 | if ((path[src] != '/') | 2606 | if ((path[src] != '/') |
2566 | #ifdef LT_DIRSEP_CHAR | 2607 | #ifdef LT_DIRSEP_CHAR |
2567 | && (path[src] != LT_DIRSEP_CHAR) | 2608 | && (path[src] != LT_DIRSEP_CHAR) |
2568 | #endif | 2609 | #endif |
2569 | ) | 2610 | ) |
2570 | { | 2611 | { |
2571 | canonical[dest++] = path[src]; | 2612 | canonical[dest++] = path[src]; |
2572 | } | 2613 | } |
2573 | /* Directory separators are converted and copied only if they are | 2614 | /* Directory separators are converted and copied only if they are |
2574 | not at the end of a path -- i.e. before a path separator or | 2615 | not at the end of a path -- i.e. before a path separator or |
2575 | NULL terminator. */ | 2616 | NULL terminator. */ |
2576 | else if ((path[1+ src] != LT_PATHSEP_CHAR) | 2617 | else if ((path[1 + src] != LT_PATHSEP_CHAR) |
2577 | && (path[1+ src] != LT_EOS_CHAR) | 2618 | && (path[1 + src] != LT_EOS_CHAR) |
2578 | #ifdef LT_DIRSEP_CHAR | 2619 | #ifdef LT_DIRSEP_CHAR |
2579 | && (path[1+ src] != LT_DIRSEP_CHAR) | 2620 | && (path[1 + src] != LT_DIRSEP_CHAR) |
2580 | #endif | 2621 | #endif |
2581 | && (path[1+ src] != '/')) | 2622 | && (path[1 + src] != '/')) |
2582 | { | 2623 | { |
2583 | canonical[dest++] = '/'; | 2624 | canonical[dest++] = '/'; |
2584 | } | 2625 | } |
2585 | } | 2626 | } |
2586 | 2627 | ||
2587 | /* Add an end-of-string marker at the end. */ | 2628 | /* Add an end-of-string marker at the end. */ |
@@ -2609,14 +2650,14 @@ argzize_path (path, pargz, pargz_len) | |||
2609 | if ((error = argz_create_sep (path, LT_PATHSEP_CHAR, pargz, pargz_len))) | 2650 | if ((error = argz_create_sep (path, LT_PATHSEP_CHAR, pargz, pargz_len))) |
2610 | { | 2651 | { |
2611 | switch (error) | 2652 | switch (error) |
2612 | { | 2653 | { |
2613 | case ENOMEM: | 2654 | case ENOMEM: |
2614 | LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY)); | 2655 | LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY)); |
2615 | break; | 2656 | break; |
2616 | default: | 2657 | default: |
2617 | LT_DLMUTEX_SETERROR (LT_DLSTRERROR (UNKNOWN)); | 2658 | LT_DLMUTEX_SETERROR (LT_DLSTRERROR (UNKNOWN)); |
2618 | break; | 2659 | break; |
2619 | } | 2660 | } |
2620 | 2661 | ||
2621 | return 1; | 2662 | return 1; |
2622 | } | 2663 | } |
@@ -2636,13 +2677,13 @@ foreach_dirinpath (search_path, base_name, func, data1, data2) | |||
2636 | lt_ptr data1; | 2677 | lt_ptr data1; |
2637 | lt_ptr data2; | 2678 | lt_ptr data2; |
2638 | { | 2679 | { |
2639 | int result = 0; | 2680 | int result = 0; |
2640 | int filenamesize = 0; | 2681 | int filenamesize = 0; |
2641 | size_t lenbase = LT_STRLEN (base_name); | 2682 | size_t lenbase = LT_STRLEN (base_name); |
2642 | size_t argz_len = 0; | 2683 | size_t argz_len = 0; |
2643 | char *argz = 0; | 2684 | char *argz = 0; |
2644 | char *filename = 0; | 2685 | char *filename = 0; |
2645 | char *canonical = 0; | 2686 | char *canonical = 0; |
2646 | 2687 | ||
2647 | LT_DLMUTEX_LOCK (); | 2688 | LT_DLMUTEX_LOCK (); |
2648 | 2689 | ||
@@ -2662,35 +2703,35 @@ foreach_dirinpath (search_path, base_name, func, data1, data2) | |||
2662 | char *dir_name = 0; | 2703 | char *dir_name = 0; |
2663 | while ((dir_name = argz_next (argz, argz_len, dir_name))) | 2704 | while ((dir_name = argz_next (argz, argz_len, dir_name))) |
2664 | { | 2705 | { |
2665 | size_t lendir = LT_STRLEN (dir_name); | 2706 | size_t lendir = LT_STRLEN (dir_name); |
2666 | 2707 | ||
2667 | if (lendir +1 +lenbase >= filenamesize) | 2708 | if (lendir + 1 + lenbase >= filenamesize) |
2668 | { | 2709 | { |
2669 | LT_DLFREE (filename); | 2710 | LT_DLFREE (filename); |
2670 | filenamesize = lendir +1 +lenbase +1; /* "/d" + '/' + "f" + '\0' */ | 2711 | filenamesize = lendir + 1 + lenbase + 1; /* "/d" + '/' + "f" + '\0' */ |
2671 | filename = LT_EMALLOC (char, filenamesize); | 2712 | filename = LT_EMALLOC (char, filenamesize); |
2672 | if (!filename) | 2713 | if (!filename) |
2673 | goto cleanup; | 2714 | goto cleanup; |
2674 | } | 2715 | } |
2675 | 2716 | ||
2676 | assert (filenamesize > lendir); | 2717 | assert (filenamesize > lendir); |
2677 | strcpy (filename, dir_name); | 2718 | strcpy (filename, dir_name); |
2678 | 2719 | ||
2679 | if (base_name && *base_name) | 2720 | if (base_name && *base_name) |
2680 | { | 2721 | { |
2681 | if (filename[lendir -1] != '/') | 2722 | if (filename[lendir - 1] != '/') |
2682 | filename[lendir++] = '/'; | 2723 | filename[lendir++] = '/'; |
2683 | strcpy (filename +lendir, base_name); | 2724 | strcpy (filename + lendir, base_name); |
2684 | } | 2725 | } |
2685 | 2726 | ||
2686 | if ((result = (*func) (filename, data1, data2))) | 2727 | if ((result = (*func) (filename, data1, data2))) |
2687 | { | 2728 | { |
2688 | break; | 2729 | break; |
2689 | } | 2730 | } |
2690 | } | 2731 | } |
2691 | } | 2732 | } |
2692 | 2733 | ||
2693 | cleanup: | 2734 | cleanup: |
2694 | LT_DLFREE (argz); | 2735 | LT_DLFREE (argz); |
2695 | LT_DLFREE (canonical); | 2736 | LT_DLFREE (canonical); |
2696 | LT_DLFREE (filename); | 2737 | LT_DLFREE (filename); |
@@ -2709,9 +2750,9 @@ find_file_callback (filename, data1, data2) | |||
2709 | lt_ptr data1; | 2750 | lt_ptr data1; |
2710 | lt_ptr data2; | 2751 | lt_ptr data2; |
2711 | { | 2752 | { |
2712 | char **pdir = (char **) data1; | 2753 | char **pdir = (char **) data1; |
2713 | FILE **pfile = (FILE **) data2; | 2754 | FILE **pfile = (FILE **) data2; |
2714 | int is_done = 0; | 2755 | int is_done = 0; |
2715 | 2756 | ||
2716 | assert (filename && *filename); | 2757 | assert (filename && *filename); |
2717 | assert (pdir); | 2758 | assert (pdir); |
@@ -2722,10 +2763,10 @@ find_file_callback (filename, data1, data2) | |||
2722 | char *dirend = strrchr (filename, '/'); | 2763 | char *dirend = strrchr (filename, '/'); |
2723 | 2764 | ||
2724 | if (dirend > filename) | 2765 | if (dirend > filename) |
2725 | *dirend = LT_EOS_CHAR; | 2766 | *dirend = LT_EOS_CHAR; |
2726 | 2767 | ||
2727 | LT_DLFREE (*pdir); | 2768 | LT_DLFREE (*pdir); |
2728 | *pdir = lt_estrdup (filename); | 2769 | *pdir = lt_estrdup (filename); |
2729 | is_done = (*pdir == 0) ? -1 : 1; | 2770 | is_done = (*pdir == 0) ? -1 : 1; |
2730 | } | 2771 | } |
2731 | 2772 | ||
@@ -2751,8 +2792,8 @@ find_handle_callback (filename, data, ignored) | |||
2751 | lt_ptr data; | 2792 | lt_ptr data; |
2752 | lt_ptr ignored; | 2793 | lt_ptr ignored; |
2753 | { | 2794 | { |
2754 | lt_dlhandle *handle = (lt_dlhandle *) data; | 2795 | lt_dlhandle *handle = (lt_dlhandle *) data; |
2755 | int notfound = access (filename, R_OK); | 2796 | int notfound = access (filename, R_OK); |
2756 | 2797 | ||
2757 | /* Bail out if file cannot be read... */ | 2798 | /* Bail out if file cannot be read... */ |
2758 | if (notfound) | 2799 | if (notfound) |
@@ -2778,7 +2819,7 @@ find_handle (search_path, base_name, handle) | |||
2778 | return 0; | 2819 | return 0; |
2779 | 2820 | ||
2780 | if (!foreach_dirinpath (search_path, base_name, find_handle_callback, | 2821 | if (!foreach_dirinpath (search_path, base_name, find_handle_callback, |
2781 | handle, 0)) | 2822 | handle, 0)) |
2782 | return 0; | 2823 | return 0; |
2783 | 2824 | ||
2784 | return handle; | 2825 | return handle; |
@@ -2790,12 +2831,12 @@ load_deplibs (handle, deplibs) | |||
2790 | char *deplibs; | 2831 | char *deplibs; |
2791 | { | 2832 | { |
2792 | #if LTDL_DLOPEN_DEPLIBS | 2833 | #if LTDL_DLOPEN_DEPLIBS |
2793 | char *p, *save_search_path = 0; | 2834 | char *p, *save_search_path = 0; |
2794 | int depcount = 0; | 2835 | int depcount = 0; |
2795 | int i; | 2836 | int i; |
2796 | char **names = 0; | 2837 | char **names = 0; |
2797 | #endif | 2838 | #endif |
2798 | int errors = 0; | 2839 | int errors = 0; |
2799 | 2840 | ||
2800 | handle->depcount = 0; | 2841 | handle->depcount = 0; |
2801 | 2842 | ||
@@ -2811,7 +2852,7 @@ load_deplibs (handle, deplibs) | |||
2811 | { | 2852 | { |
2812 | save_search_path = lt_estrdup (user_search_path); | 2853 | save_search_path = lt_estrdup (user_search_path); |
2813 | if (!save_search_path) | 2854 | if (!save_search_path) |
2814 | goto cleanup; | 2855 | goto cleanup; |
2815 | } | 2856 | } |
2816 | 2857 | ||
2817 | /* extract search paths and count deplibs */ | 2858 | /* extract search paths and count deplibs */ |
@@ -2819,34 +2860,34 @@ load_deplibs (handle, deplibs) | |||
2819 | while (*p) | 2860 | while (*p) |
2820 | { | 2861 | { |
2821 | if (!isspace ((int) *p)) | 2862 | if (!isspace ((int) *p)) |
2822 | { | 2863 | { |
2823 | char *end = p+1; | 2864 | char *end = p + 1; |
2824 | while (*end && !isspace((int) *end)) | 2865 | while (*end && !isspace ((int) *end)) |
2825 | { | 2866 | { |
2826 | ++end; | 2867 | ++end; |
2827 | } | 2868 | } |
2828 | 2869 | ||
2829 | if (strncmp(p, "-L", 2) == 0 || strncmp(p, "-R", 2) == 0) | 2870 | if (strncmp (p, "-L", 2) == 0 || strncmp (p, "-R", 2) == 0) |
2830 | { | 2871 | { |
2831 | char save = *end; | 2872 | char save = *end; |
2832 | *end = 0; /* set a temporary string terminator */ | 2873 | *end = 0; /* set a temporary string terminator */ |
2833 | if (lt_dladdsearchdir(p+2)) | 2874 | if (lt_dladdsearchdir (p + 2)) |
2834 | { | 2875 | { |
2835 | goto cleanup; | 2876 | goto cleanup; |
2836 | } | 2877 | } |
2837 | *end = save; | 2878 | *end = save; |
2838 | } | 2879 | } |
2839 | else | 2880 | else |
2840 | { | 2881 | { |
2841 | ++depcount; | 2882 | ++depcount; |
2842 | } | 2883 | } |
2843 | 2884 | ||
2844 | p = end; | 2885 | p = end; |
2845 | } | 2886 | } |
2846 | else | 2887 | else |
2847 | { | 2888 | { |
2848 | ++p; | 2889 | ++p; |
2849 | } | 2890 | } |
2850 | } | 2891 | } |
2851 | 2892 | ||
2852 | /* restore the old search path */ | 2893 | /* restore the old search path */ |
@@ -2861,7 +2902,7 @@ load_deplibs (handle, deplibs) | |||
2861 | goto cleanup; | 2902 | goto cleanup; |
2862 | } | 2903 | } |
2863 | 2904 | ||
2864 | names = LT_EMALLOC (char *, depcount * sizeof (char*)); | 2905 | names = LT_EMALLOC (char *, depcount * sizeof (char *)); |
2865 | if (!names) | 2906 | if (!names) |
2866 | goto cleanup; | 2907 | goto cleanup; |
2867 | 2908 | ||
@@ -2871,40 +2912,40 @@ load_deplibs (handle, deplibs) | |||
2871 | while (*p) | 2912 | while (*p) |
2872 | { | 2913 | { |
2873 | if (isspace ((int) *p)) | 2914 | if (isspace ((int) *p)) |
2874 | { | 2915 | { |
2875 | ++p; | 2916 | ++p; |
2876 | } | 2917 | } |
2877 | else | 2918 | else |
2878 | { | 2919 | { |
2879 | char *end = p+1; | 2920 | char *end = p + 1; |
2880 | while (*end && !isspace ((int) *end)) | 2921 | while (*end && !isspace ((int) *end)) |
2881 | { | 2922 | { |
2882 | ++end; | 2923 | ++end; |
2883 | } | 2924 | } |
2884 | 2925 | ||
2885 | if (strncmp(p, "-L", 2) != 0 && strncmp(p, "-R", 2) != 0) | 2926 | if (strncmp (p, "-L", 2) != 0 && strncmp (p, "-R", 2) != 0) |
2886 | { | 2927 | { |
2887 | char *name; | 2928 | char *name; |
2888 | char save = *end; | 2929 | char save = *end; |
2889 | *end = 0; /* set a temporary string terminator */ | 2930 | *end = 0; /* set a temporary string terminator */ |
2890 | if (strncmp(p, "-l", 2) == 0) | 2931 | if (strncmp (p, "-l", 2) == 0) |
2891 | { | 2932 | { |
2892 | size_t name_len = 3+ /* "lib" */ LT_STRLEN (p + 2); | 2933 | size_t name_len = 3 + /* "lib" */ LT_STRLEN (p + 2); |
2893 | name = LT_EMALLOC (char, 1+ name_len); | 2934 | name = LT_EMALLOC (char, 1 + name_len); |
2894 | if (name) | 2935 | if (name) |
2895 | sprintf (name, "lib%s", p+2); | 2936 | sprintf (name, "lib%s", p + 2); |
2896 | } | 2937 | } |
2897 | else | 2938 | else |
2898 | name = lt_estrdup(p); | 2939 | name = lt_estrdup (p); |
2899 | 2940 | ||
2900 | if (!name) | 2941 | if (!name) |
2901 | goto cleanup_names; | 2942 | goto cleanup_names; |
2902 | 2943 | ||
2903 | names[depcount++] = name; | 2944 | names[depcount++] = name; |
2904 | *end = save; | 2945 | *end = save; |
2905 | } | 2946 | } |
2906 | p = end; | 2947 | p = end; |
2907 | } | 2948 | } |
2908 | } | 2949 | } |
2909 | 2950 | ||
2910 | /* load the deplibs (in reverse order) | 2951 | /* load the deplibs (in reverse order) |
@@ -2914,32 +2955,32 @@ load_deplibs (handle, deplibs) | |||
2914 | later on if the loaded module cannot resolve all of its symbols. */ | 2955 | later on if the loaded module cannot resolve all of its symbols. */ |
2915 | if (depcount) | 2956 | if (depcount) |
2916 | { | 2957 | { |
2917 | int j = 0; | 2958 | int j = 0; |
2918 | 2959 | ||
2919 | handle->deplibs = (lt_dlhandle*) LT_EMALLOC (lt_dlhandle *, depcount); | 2960 | handle->deplibs = (lt_dlhandle *) LT_EMALLOC (lt_dlhandle *, depcount); |
2920 | if (!handle->deplibs) | 2961 | if (!handle->deplibs) |
2921 | goto cleanup; | 2962 | goto cleanup; |
2922 | 2963 | ||
2923 | for (i = 0; i < depcount; ++i) | 2964 | for (i = 0; i < depcount; ++i) |
2924 | { | 2965 | { |
2925 | handle->deplibs[j] = lt_dlopenext(names[depcount-1-i]); | 2966 | handle->deplibs[j] = lt_dlopenext (names[depcount - 1 - i]); |
2926 | if (handle->deplibs[j]) | 2967 | if (handle->deplibs[j]) |
2927 | { | 2968 | { |
2928 | ++j; | 2969 | ++j; |
2929 | } | 2970 | } |
2930 | } | 2971 | } |
2931 | 2972 | ||
2932 | handle->depcount = j; /* Number of successfully loaded deplibs */ | 2973 | handle->depcount = j; /* Number of successfully loaded deplibs */ |
2933 | errors = 0; | 2974 | errors = 0; |
2934 | } | 2975 | } |
2935 | 2976 | ||
2936 | cleanup_names: | 2977 | cleanup_names: |
2937 | for (i = 0; i < depcount; ++i) | 2978 | for (i = 0; i < depcount; ++i) |
2938 | { | 2979 | { |
2939 | LT_DLFREE (names[i]); | 2980 | LT_DLFREE (names[i]); |
2940 | } | 2981 | } |
2941 | 2982 | ||
2942 | cleanup: | 2983 | cleanup: |
2943 | LT_DLFREE (names); | 2984 | LT_DLFREE (names); |
2944 | #endif | 2985 | #endif |
2945 | 2986 | ||
@@ -2956,12 +2997,12 @@ unload_deplibs (handle) | |||
2956 | if (handle->depcount) | 2997 | if (handle->depcount) |
2957 | { | 2998 | { |
2958 | for (i = 0; i < handle->depcount; ++i) | 2999 | for (i = 0; i < handle->depcount; ++i) |
2959 | { | 3000 | { |
2960 | if (!LT_DLIS_RESIDENT (handle->deplibs[i])) | 3001 | if (!LT_DLIS_RESIDENT (handle->deplibs[i])) |
2961 | { | 3002 | { |
2962 | errors += lt_dlclose (handle->deplibs[i]); | 3003 | errors += lt_dlclose (handle->deplibs[i]); |
2963 | } | 3004 | } |
2964 | } | 3005 | } |
2965 | } | 3006 | } |
2966 | 3007 | ||
2967 | return errors; | 3008 | return errors; |
@@ -2974,8 +3015,8 @@ trim (dest, str) | |||
2974 | { | 3015 | { |
2975 | /* remove the leading and trailing "'" from str | 3016 | /* remove the leading and trailing "'" from str |
2976 | and store the result in dest */ | 3017 | and store the result in dest */ |
2977 | const char *end = strrchr (str, '\''); | 3018 | const char *end = strrchr (str, '\''); |
2978 | size_t len = LT_STRLEN (str); | 3019 | size_t len = LT_STRLEN (str); |
2979 | char *tmp; | 3020 | char *tmp; |
2980 | 3021 | ||
2981 | LT_DLFREE (*dest); | 3022 | LT_DLFREE (*dest); |
@@ -2984,10 +3025,10 @@ trim (dest, str) | |||
2984 | { | 3025 | { |
2985 | tmp = LT_EMALLOC (char, end - str); | 3026 | tmp = LT_EMALLOC (char, end - str); |
2986 | if (!tmp) | 3027 | if (!tmp) |
2987 | return 1; | 3028 | return 1; |
2988 | 3029 | ||
2989 | strncpy(tmp, &str[1], (end - str) - 1); | 3030 | strncpy (tmp, &str[1], (end - str) - 1); |
2990 | tmp[len-3] = LT_EOS_CHAR; | 3031 | tmp[len - 3] = LT_EOS_CHAR; |
2991 | *dest = tmp; | 3032 | *dest = tmp; |
2992 | } | 3033 | } |
2993 | else | 3034 | else |
@@ -3018,14 +3059,14 @@ try_dlopen (phandle, filename) | |||
3018 | lt_dlhandle *phandle; | 3059 | lt_dlhandle *phandle; |
3019 | const char *filename; | 3060 | const char *filename; |
3020 | { | 3061 | { |
3021 | const char * ext = 0; | 3062 | const char *ext = 0; |
3022 | const char * saved_error = 0; | 3063 | const char *saved_error = 0; |
3023 | char * canonical = 0; | 3064 | char *canonical = 0; |
3024 | char * base_name = 0; | 3065 | char *base_name = 0; |
3025 | char * dir = 0; | 3066 | char *dir = 0; |
3026 | char * name = 0; | 3067 | char *name = 0; |
3027 | int errors = 0; | 3068 | int errors = 0; |
3028 | lt_dlhandle newhandle; | 3069 | lt_dlhandle newhandle; |
3029 | 3070 | ||
3030 | assert (phandle); | 3071 | assert (phandle); |
3031 | assert (*phandle == 0); | 3072 | assert (*phandle == 0); |
@@ -3037,19 +3078,19 @@ try_dlopen (phandle, filename) | |||
3037 | { | 3078 | { |
3038 | *phandle = (lt_dlhandle) LT_EMALLOC (struct lt_dlhandle_struct, 1); | 3079 | *phandle = (lt_dlhandle) LT_EMALLOC (struct lt_dlhandle_struct, 1); |
3039 | if (*phandle == 0) | 3080 | if (*phandle == 0) |
3040 | return 1; | 3081 | return 1; |
3041 | 3082 | ||
3042 | memset (*phandle, 0, sizeof(struct lt_dlhandle_struct)); | 3083 | memset (*phandle, 0, sizeof (struct lt_dlhandle_struct)); |
3043 | newhandle = *phandle; | 3084 | newhandle = *phandle; |
3044 | 3085 | ||
3045 | /* lt_dlclose()ing yourself is very bad! Disallow it. */ | 3086 | /* lt_dlclose()ing yourself is very bad! Disallow it. */ |
3046 | LT_DLSET_FLAG (*phandle, LT_DLRESIDENT_FLAG); | 3087 | LT_DLSET_FLAG (*phandle, LT_DLRESIDENT_FLAG); |
3047 | 3088 | ||
3048 | if (tryall_dlopen (&newhandle, 0) != 0) | 3089 | if (tryall_dlopen (&newhandle, 0) != 0) |
3049 | { | 3090 | { |
3050 | LT_DLFREE (*phandle); | 3091 | LT_DLFREE (*phandle); |
3051 | return 1; | 3092 | return 1; |
3052 | } | 3093 | } |
3053 | 3094 | ||
3054 | goto register_handle; | 3095 | goto register_handle; |
3055 | } | 3096 | } |
@@ -3069,14 +3110,14 @@ try_dlopen (phandle, filename) | |||
3069 | base_name = strrchr (canonical, '/'); | 3110 | base_name = strrchr (canonical, '/'); |
3070 | if (base_name) | 3111 | if (base_name) |
3071 | { | 3112 | { |
3072 | size_t dirlen = (1+ base_name) - canonical; | 3113 | size_t dirlen = (1 + base_name) - canonical; |
3073 | 3114 | ||
3074 | dir = LT_EMALLOC (char, 1+ dirlen); | 3115 | dir = LT_EMALLOC (char, 1 + dirlen); |
3075 | if (!dir) | 3116 | if (!dir) |
3076 | { | 3117 | { |
3077 | ++errors; | 3118 | ++errors; |
3078 | goto cleanup; | 3119 | goto cleanup; |
3079 | } | 3120 | } |
3080 | 3121 | ||
3081 | strncpy (dir, canonical, dirlen); | 3122 | strncpy (dir, canonical, dirlen); |
3082 | dir[dirlen] = LT_EOS_CHAR; | 3123 | dir[dirlen] = LT_EOS_CHAR; |
@@ -3093,41 +3134,41 @@ try_dlopen (phandle, filename) | |||
3093 | if (ext && strcmp (ext, archive_ext) == 0) | 3134 | if (ext && strcmp (ext, archive_ext) == 0) |
3094 | { | 3135 | { |
3095 | /* this seems to be a libtool module */ | 3136 | /* this seems to be a libtool module */ |
3096 | FILE * file = 0; | 3137 | FILE *file = 0; |
3097 | char * dlname = 0; | 3138 | char *dlname = 0; |
3098 | char * old_name = 0; | 3139 | char *old_name = 0; |
3099 | char * libdir = 0; | 3140 | char *libdir = 0; |
3100 | char * deplibs = 0; | 3141 | char *deplibs = 0; |
3101 | char * line = 0; | 3142 | char *line = 0; |
3102 | size_t line_len; | 3143 | size_t line_len; |
3103 | 3144 | ||
3104 | /* if we can't find the installed flag, it is probably an | 3145 | /* if we can't find the installed flag, it is probably an |
3105 | installed libtool archive, produced with an old version | 3146 | installed libtool archive, produced with an old version |
3106 | of libtool */ | 3147 | of libtool */ |
3107 | int installed = 1; | 3148 | int installed = 1; |
3108 | 3149 | ||
3109 | /* extract the module name from the file name */ | 3150 | /* extract the module name from the file name */ |
3110 | name = LT_EMALLOC (char, ext - base_name + 1); | 3151 | name = LT_EMALLOC (char, ext - base_name + 1); |
3111 | if (!name) | 3152 | if (!name) |
3112 | { | 3153 | { |
3113 | ++errors; | 3154 | ++errors; |
3114 | goto cleanup; | 3155 | goto cleanup; |
3115 | } | 3156 | } |
3116 | 3157 | ||
3117 | /* canonicalize the module name */ | 3158 | /* canonicalize the module name */ |
3118 | { | 3159 | { |
3119 | size_t i; | 3160 | size_t i; |
3120 | for (i = 0; i < ext - base_name; ++i) | 3161 | for (i = 0; i < ext - base_name; ++i) |
3121 | { | 3162 | { |
3122 | if (isalnum ((int)(base_name[i]))) | 3163 | if (isalnum ((int) (base_name[i]))) |
3123 | { | 3164 | { |
3124 | name[i] = base_name[i]; | 3165 | name[i] = base_name[i]; |
3125 | } | 3166 | } |
3126 | else | 3167 | else |
3127 | { | 3168 | { |
3128 | name[i] = '_'; | 3169 | name[i] = '_'; |
3129 | } | 3170 | } |
3130 | } | 3171 | } |
3131 | name[ext - base_name] = LT_EOS_CHAR; | 3172 | name[ext - base_name] = LT_EOS_CHAR; |
3132 | } | 3173 | } |
3133 | 3174 | ||
@@ -3136,146 +3177,145 @@ try_dlopen (phandle, filename) | |||
3136 | prescribed paths. Otherwise (or in any case if the module was not | 3177 | prescribed paths. Otherwise (or in any case if the module was not |
3137 | yet found) try opening just the module name as passed. */ | 3178 | yet found) try opening just the module name as passed. */ |
3138 | if (!dir) | 3179 | if (!dir) |
3139 | { | 3180 | { |
3140 | const char *search_path; | 3181 | const char *search_path; |
3141 | 3182 | ||
3142 | LT_DLMUTEX_LOCK (); | 3183 | LT_DLMUTEX_LOCK (); |
3143 | search_path = user_search_path; | 3184 | search_path = user_search_path; |
3144 | if (search_path) | 3185 | if (search_path) |
3145 | file = find_file (user_search_path, base_name, &dir); | 3186 | file = find_file (user_search_path, base_name, &dir); |
3146 | LT_DLMUTEX_UNLOCK (); | 3187 | LT_DLMUTEX_UNLOCK (); |
3147 | 3188 | ||
3148 | if (!file) | 3189 | if (!file) |
3149 | { | 3190 | { |
3150 | search_path = getenv (LTDL_SEARCHPATH_VAR); | 3191 | search_path = getenv (LTDL_SEARCHPATH_VAR); |
3151 | if (search_path) | 3192 | if (search_path) |
3152 | file = find_file (search_path, base_name, &dir); | 3193 | file = find_file (search_path, base_name, &dir); |
3153 | } | 3194 | } |
3154 | 3195 | ||
3155 | #ifdef LTDL_SHLIBPATH_VAR | 3196 | #ifdef LTDL_SHLIBPATH_VAR |
3156 | if (!file) | 3197 | if (!file) |
3157 | { | 3198 | { |
3158 | search_path = getenv (LTDL_SHLIBPATH_VAR); | 3199 | search_path = getenv (LTDL_SHLIBPATH_VAR); |
3159 | if (search_path) | 3200 | if (search_path) |
3160 | file = find_file (search_path, base_name, &dir); | 3201 | file = find_file (search_path, base_name, &dir); |
3161 | } | 3202 | } |
3162 | #endif | 3203 | #endif |
3163 | #ifdef LTDL_SYSSEARCHPATH | 3204 | #ifdef LTDL_SYSSEARCHPATH |
3164 | if (!file && sys_search_path) | 3205 | if (!file && sys_search_path) |
3165 | { | 3206 | { |
3166 | file = find_file (sys_search_path, base_name, &dir); | 3207 | file = find_file (sys_search_path, base_name, &dir); |
3167 | } | 3208 | } |
3168 | #endif | 3209 | #endif |
3169 | } | 3210 | } |
3170 | if (!file) | 3211 | if (!file) |
3171 | { | 3212 | { |
3172 | file = fopen (filename, LT_READTEXT_MODE); | 3213 | file = fopen (filename, LT_READTEXT_MODE); |
3173 | } | 3214 | } |
3174 | 3215 | ||
3175 | /* If we didn't find the file by now, it really isn't there. Set | 3216 | /* If we didn't find the file by now, it really isn't there. Set |
3176 | the status flag, and bail out. */ | 3217 | the status flag, and bail out. */ |
3177 | if (!file) | 3218 | if (!file) |
3178 | { | 3219 | { |
3179 | LT_DLMUTEX_SETERROR (LT_DLSTRERROR (FILE_NOT_FOUND)); | 3220 | LT_DLMUTEX_SETERROR (LT_DLSTRERROR (FILE_NOT_FOUND)); |
3180 | ++errors; | 3221 | ++errors; |
3181 | goto cleanup; | 3222 | goto cleanup; |
3182 | } | 3223 | } |
3183 | 3224 | ||
3184 | line_len = LT_FILENAME_MAX; | 3225 | line_len = LT_FILENAME_MAX; |
3185 | line = LT_EMALLOC (char, line_len); | 3226 | line = LT_EMALLOC (char, line_len); |
3186 | if (!line) | 3227 | if (!line) |
3187 | { | 3228 | { |
3188 | fclose (file); | 3229 | fclose (file); |
3189 | ++errors; | 3230 | ++errors; |
3190 | goto cleanup; | 3231 | goto cleanup; |
3191 | } | 3232 | } |
3192 | 3233 | ||
3193 | /* read the .la file */ | 3234 | /* read the .la file */ |
3194 | while (!feof (file)) | 3235 | while (!feof (file)) |
3195 | { | 3236 | { |
3196 | if (!fgets (line, (int) line_len, file)) | 3237 | if (!fgets (line, (int) line_len, file)) |
3197 | { | 3238 | { |
3198 | break; | 3239 | break; |
3199 | } | 3240 | } |
3200 | 3241 | ||
3201 | /* Handle the case where we occasionally need to read a line | 3242 | /* Handle the case where we occasionally need to read a line |
3202 | that is longer than the initial buffer size. */ | 3243 | that is longer than the initial buffer size. */ |
3203 | while ((line[LT_STRLEN(line) -1] != '\n') && (!feof (file))) | 3244 | while ((line[LT_STRLEN (line) - 1] != '\n') && (!feof (file))) |
3204 | { | 3245 | { |
3205 | line = LT_DLREALLOC (char, line, line_len *2); | 3246 | line = LT_DLREALLOC (char, line, line_len * 2); |
3206 | if (!fgets (&line[line_len -1], (int) line_len +1, file)) | 3247 | if (!fgets (&line[line_len - 1], (int) line_len + 1, file)) |
3207 | { | 3248 | { |
3208 | break; | 3249 | break; |
3209 | } | 3250 | } |
3210 | line_len *= 2; | 3251 | line_len *= 2; |
3211 | } | 3252 | } |
3212 | 3253 | ||
3213 | if (line[0] == '\n' || line[0] == '#') | 3254 | if (line[0] == '\n' || line[0] == '#') |
3214 | { | 3255 | { |
3215 | continue; | 3256 | continue; |
3216 | } | 3257 | } |
3217 | 3258 | ||
3218 | #undef STR_DLNAME | 3259 | #undef STR_DLNAME |
3219 | #define STR_DLNAME "dlname=" | 3260 | #define STR_DLNAME "dlname=" |
3220 | if (strncmp (line, STR_DLNAME, sizeof (STR_DLNAME) - 1) == 0) | 3261 | if (strncmp (line, STR_DLNAME, sizeof (STR_DLNAME) - 1) == 0) |
3221 | { | 3262 | { |
3222 | errors += trim (&dlname, &line[sizeof (STR_DLNAME) - 1]); | 3263 | errors += trim (&dlname, &line[sizeof (STR_DLNAME) - 1]); |
3223 | } | 3264 | } |
3224 | 3265 | ||
3225 | #undef STR_OLD_LIBRARY | 3266 | #undef STR_OLD_LIBRARY |
3226 | #define STR_OLD_LIBRARY "old_library=" | 3267 | #define STR_OLD_LIBRARY "old_library=" |
3227 | else if (strncmp (line, STR_OLD_LIBRARY, | 3268 | else if (strncmp (line, STR_OLD_LIBRARY, |
3228 | sizeof (STR_OLD_LIBRARY) - 1) == 0) | 3269 | sizeof (STR_OLD_LIBRARY) - 1) == 0) |
3229 | { | 3270 | { |
3230 | errors += trim (&old_name, &line[sizeof (STR_OLD_LIBRARY) - 1]); | 3271 | errors += trim (&old_name, &line[sizeof (STR_OLD_LIBRARY) - 1]); |
3231 | } | 3272 | } |
3232 | #undef STR_LIBDIR | 3273 | #undef STR_LIBDIR |
3233 | #define STR_LIBDIR "libdir=" | 3274 | #define STR_LIBDIR "libdir=" |
3234 | else if (strncmp (line, STR_LIBDIR, sizeof (STR_LIBDIR) - 1) == 0) | 3275 | else if (strncmp (line, STR_LIBDIR, sizeof (STR_LIBDIR) - 1) == 0) |
3235 | { | 3276 | { |
3236 | errors += trim (&libdir, &line[sizeof(STR_LIBDIR) - 1]); | 3277 | errors += trim (&libdir, &line[sizeof (STR_LIBDIR) - 1]); |
3237 | } | 3278 | } |
3238 | 3279 | ||
3239 | #undef STR_DL_DEPLIBS | 3280 | #undef STR_DL_DEPLIBS |
3240 | #define STR_DL_DEPLIBS "dependency_libs=" | 3281 | #define STR_DL_DEPLIBS "dependency_libs=" |
3241 | else if (strncmp (line, STR_DL_DEPLIBS, | 3282 | else if (strncmp (line, STR_DL_DEPLIBS, |
3242 | sizeof (STR_DL_DEPLIBS) - 1) == 0) | 3283 | sizeof (STR_DL_DEPLIBS) - 1) == 0) |
3243 | { | 3284 | { |
3244 | errors += trim (&deplibs, &line[sizeof (STR_DL_DEPLIBS) - 1]); | 3285 | errors += trim (&deplibs, &line[sizeof (STR_DL_DEPLIBS) - 1]); |
3245 | } | 3286 | } |
3246 | else if (strcmp (line, "installed=yes\n") == 0) | 3287 | else if (strcmp (line, "installed=yes\n") == 0) |
3247 | { | 3288 | { |
3248 | installed = 1; | 3289 | installed = 1; |
3249 | } | 3290 | } |
3250 | else if (strcmp (line, "installed=no\n") == 0) | 3291 | else if (strcmp (line, "installed=no\n") == 0) |
3251 | { | 3292 | { |
3252 | installed = 0; | 3293 | installed = 0; |
3253 | } | 3294 | } |
3254 | 3295 | ||
3255 | #undef STR_LIBRARY_NAMES | 3296 | #undef STR_LIBRARY_NAMES |
3256 | #define STR_LIBRARY_NAMES "library_names=" | 3297 | #define STR_LIBRARY_NAMES "library_names=" |
3257 | else if (! dlname && strncmp (line, STR_LIBRARY_NAMES, | 3298 | else if (!dlname && strncmp (line, STR_LIBRARY_NAMES, |
3258 | sizeof (STR_LIBRARY_NAMES) - 1) == 0) | 3299 | sizeof (STR_LIBRARY_NAMES) - 1) == 0) |
3259 | { | 3300 | { |
3260 | char *last_libname; | 3301 | char *last_libname; |
3261 | errors += trim (&dlname, &line[sizeof (STR_LIBRARY_NAMES) - 1]); | 3302 | errors += trim (&dlname, &line[sizeof (STR_LIBRARY_NAMES) - 1]); |
3262 | if (!errors | 3303 | if (!errors |
3263 | && dlname | 3304 | && dlname && (last_libname = strrchr (dlname, ' ')) != 0) |
3264 | && (last_libname = strrchr (dlname, ' ')) != 0) | 3305 | { |
3265 | { | 3306 | last_libname = lt_estrdup (last_libname + 1); |
3266 | last_libname = lt_estrdup (last_libname + 1); | 3307 | if (!last_libname) |
3267 | if (!last_libname) | 3308 | { |
3268 | { | 3309 | ++errors; |
3269 | ++errors; | 3310 | goto cleanup; |
3270 | goto cleanup; | 3311 | } |
3271 | } | 3312 | LT_DLMEM_REASSIGN (dlname, last_libname); |
3272 | LT_DLMEM_REASSIGN (dlname, last_libname); | 3313 | } |
3273 | } | 3314 | } |
3274 | } | 3315 | |
3275 | 3316 | if (errors) | |
3276 | if (errors) | 3317 | break; |
3277 | break; | 3318 | } |
3278 | } | ||
3279 | 3319 | ||
3280 | fclose (file); | 3320 | fclose (file); |
3281 | LT_DLFREE (line); | 3321 | LT_DLFREE (line); |
@@ -3283,105 +3323,106 @@ try_dlopen (phandle, filename) | |||
3283 | /* allocate the handle */ | 3323 | /* allocate the handle */ |
3284 | *phandle = (lt_dlhandle) LT_EMALLOC (struct lt_dlhandle_struct, 1); | 3324 | *phandle = (lt_dlhandle) LT_EMALLOC (struct lt_dlhandle_struct, 1); |
3285 | if (*phandle == 0) | 3325 | if (*phandle == 0) |
3286 | ++errors; | 3326 | ++errors; |
3287 | 3327 | ||
3288 | if (errors) | 3328 | if (errors) |
3289 | { | 3329 | { |
3290 | free_vars (dlname, old_name, libdir, deplibs); | 3330 | free_vars (dlname, old_name, libdir, deplibs); |
3291 | LT_DLFREE (*phandle); | 3331 | LT_DLFREE (*phandle); |
3292 | goto cleanup; | 3332 | goto cleanup; |
3293 | } | 3333 | } |
3294 | 3334 | ||
3295 | assert (*phandle); | 3335 | assert (*phandle); |
3296 | 3336 | ||
3297 | memset (*phandle, 0, sizeof(struct lt_dlhandle_struct)); | 3337 | memset (*phandle, 0, sizeof (struct lt_dlhandle_struct)); |
3298 | if (load_deplibs (*phandle, deplibs) == 0) | 3338 | if (load_deplibs (*phandle, deplibs) == 0) |
3299 | { | 3339 | { |
3300 | newhandle = *phandle; | 3340 | newhandle = *phandle; |
3301 | /* find_module may replace newhandle */ | 3341 | /* find_module may replace newhandle */ |
3302 | if (find_module (&newhandle, dir, libdir, dlname, old_name, installed)) | 3342 | if (find_module |
3303 | { | 3343 | (&newhandle, dir, libdir, dlname, old_name, installed)) |
3304 | unload_deplibs (*phandle); | 3344 | { |
3305 | ++errors; | 3345 | unload_deplibs (*phandle); |
3306 | } | 3346 | ++errors; |
3307 | } | 3347 | } |
3348 | } | ||
3308 | else | 3349 | else |
3309 | { | 3350 | { |
3310 | ++errors; | 3351 | ++errors; |
3311 | } | 3352 | } |
3312 | 3353 | ||
3313 | free_vars (dlname, old_name, libdir, deplibs); | 3354 | free_vars (dlname, old_name, libdir, deplibs); |
3314 | if (errors) | 3355 | if (errors) |
3315 | { | 3356 | { |
3316 | LT_DLFREE (*phandle); | 3357 | LT_DLFREE (*phandle); |
3317 | goto cleanup; | 3358 | goto cleanup; |
3318 | } | 3359 | } |
3319 | 3360 | ||
3320 | if (*phandle != newhandle) | 3361 | if (*phandle != newhandle) |
3321 | { | 3362 | { |
3322 | unload_deplibs (*phandle); | 3363 | unload_deplibs (*phandle); |
3323 | } | 3364 | } |
3324 | } | 3365 | } |
3325 | else | 3366 | else |
3326 | { | 3367 | { |
3327 | /* not a libtool module */ | 3368 | /* not a libtool module */ |
3328 | *phandle = (lt_dlhandle) LT_EMALLOC (struct lt_dlhandle_struct, 1); | 3369 | *phandle = (lt_dlhandle) LT_EMALLOC (struct lt_dlhandle_struct, 1); |
3329 | if (*phandle == 0) | 3370 | if (*phandle == 0) |
3330 | { | 3371 | { |
3331 | ++errors; | 3372 | ++errors; |
3332 | goto cleanup; | 3373 | goto cleanup; |
3333 | } | 3374 | } |
3334 | 3375 | ||
3335 | memset (*phandle, 0, sizeof (struct lt_dlhandle_struct)); | 3376 | memset (*phandle, 0, sizeof (struct lt_dlhandle_struct)); |
3336 | newhandle = *phandle; | 3377 | newhandle = *phandle; |
3337 | 3378 | ||
3338 | /* If the module has no directory name component, try to find it | 3379 | /* If the module has no directory name component, try to find it |
3339 | first in user_search_path and then other prescribed paths. | 3380 | first in user_search_path and then other prescribed paths. |
3340 | Otherwise (or in any case if the module was not yet found) try | 3381 | Otherwise (or in any case if the module was not yet found) try |
3341 | opening just the module name as passed. */ | 3382 | opening just the module name as passed. */ |
3342 | if ((dir || (!find_handle (user_search_path, base_name, &newhandle) | 3383 | if ((dir || (!find_handle (user_search_path, base_name, &newhandle) |
3343 | && !find_handle (getenv (LTDL_SEARCHPATH_VAR), base_name, | 3384 | && !find_handle (getenv (LTDL_SEARCHPATH_VAR), base_name, |
3344 | &newhandle) | 3385 | &newhandle) |
3345 | #ifdef LTDL_SHLIBPATH_VAR | 3386 | #ifdef LTDL_SHLIBPATH_VAR |
3346 | && !find_handle (getenv (LTDL_SHLIBPATH_VAR), base_name, | 3387 | && !find_handle (getenv (LTDL_SHLIBPATH_VAR), base_name, |
3347 | &newhandle) | 3388 | &newhandle) |
3348 | #endif | 3389 | #endif |
3349 | #ifdef LTDL_SYSSEARCHPATH | 3390 | #ifdef LTDL_SYSSEARCHPATH |
3350 | && !find_handle (sys_search_path, base_name, &newhandle) | 3391 | && !find_handle (sys_search_path, base_name, &newhandle) |
3351 | #endif | 3392 | #endif |
3352 | ))) | 3393 | ))) |
3353 | { | 3394 | { |
3354 | if (tryall_dlopen (&newhandle, filename) != 0) | 3395 | if (tryall_dlopen (&newhandle, filename) != 0) |
3355 | { | 3396 | { |
3356 | newhandle = NULL; | 3397 | newhandle = NULL; |
3357 | } | 3398 | } |
3358 | } | 3399 | } |
3359 | 3400 | ||
3360 | if (!newhandle) | 3401 | if (!newhandle) |
3361 | { | 3402 | { |
3362 | LT_DLFREE (*phandle); | 3403 | LT_DLFREE (*phandle); |
3363 | ++errors; | 3404 | ++errors; |
3364 | goto cleanup; | 3405 | goto cleanup; |
3365 | } | 3406 | } |
3366 | } | 3407 | } |
3367 | 3408 | ||
3368 | register_handle: | 3409 | register_handle: |
3369 | LT_DLMEM_REASSIGN (*phandle, newhandle); | 3410 | LT_DLMEM_REASSIGN (*phandle, newhandle); |
3370 | 3411 | ||
3371 | if ((*phandle)->info.ref_count == 0) | 3412 | if ((*phandle)->info.ref_count == 0) |
3372 | { | 3413 | { |
3373 | (*phandle)->info.ref_count = 1; | 3414 | (*phandle)->info.ref_count = 1; |
3374 | LT_DLMEM_REASSIGN ((*phandle)->info.name, name); | 3415 | LT_DLMEM_REASSIGN ((*phandle)->info.name, name); |
3375 | 3416 | ||
3376 | LT_DLMUTEX_LOCK (); | 3417 | LT_DLMUTEX_LOCK (); |
3377 | (*phandle)->next = handles; | 3418 | (*phandle)->next = handles; |
3378 | handles = *phandle; | 3419 | handles = *phandle; |
3379 | LT_DLMUTEX_UNLOCK (); | 3420 | LT_DLMUTEX_UNLOCK (); |
3380 | } | 3421 | } |
3381 | 3422 | ||
3382 | LT_DLMUTEX_SETERROR (saved_error); | 3423 | LT_DLMUTEX_SETERROR (saved_error); |
3383 | 3424 | ||
3384 | cleanup: | 3425 | cleanup: |
3385 | LT_DLFREE (dir); | 3426 | LT_DLFREE (dir); |
3386 | LT_DLFREE (name); | 3427 | LT_DLFREE (name); |
3387 | LT_DLFREE (canonical); | 3428 | LT_DLFREE (canonical); |
@@ -3425,11 +3466,11 @@ lt_dlhandle | |||
3425 | lt_dlopenext (filename) | 3466 | lt_dlopenext (filename) |
3426 | const char *filename; | 3467 | const char *filename; |
3427 | { | 3468 | { |
3428 | lt_dlhandle handle = 0; | 3469 | lt_dlhandle handle = 0; |
3429 | char * tmp = 0; | 3470 | char *tmp = 0; |
3430 | char * ext = 0; | 3471 | char *ext = 0; |
3431 | size_t len; | 3472 | size_t len; |
3432 | int errors = 0; | 3473 | int errors = 0; |
3433 | 3474 | ||
3434 | if (!filename) | 3475 | if (!filename) |
3435 | { | 3476 | { |
@@ -3445,7 +3486,7 @@ lt_dlopenext (filename) | |||
3445 | to try appending additional extensions. */ | 3486 | to try appending additional extensions. */ |
3446 | if (ext && ((strcmp (ext, archive_ext) == 0) | 3487 | if (ext && ((strcmp (ext, archive_ext) == 0) |
3447 | #ifdef LTDL_SHLIB_EXT | 3488 | #ifdef LTDL_SHLIB_EXT |
3448 | || (strcmp (ext, shlib_ext) == 0) | 3489 | || (strcmp (ext, shlib_ext) == 0) |
3449 | #endif | 3490 | #endif |
3450 | )) | 3491 | )) |
3451 | { | 3492 | { |
@@ -3479,7 +3520,7 @@ lt_dlopenext (filename) | |||
3479 | LT_DLFREE (tmp); | 3520 | LT_DLFREE (tmp); |
3480 | tmp = LT_EMALLOC (char, len + LT_STRLEN (shlib_ext) + 1); | 3521 | tmp = LT_EMALLOC (char, len + LT_STRLEN (shlib_ext) + 1); |
3481 | if (!tmp) | 3522 | if (!tmp) |
3482 | return 0; | 3523 | return 0; |
3483 | 3524 | ||
3484 | strcpy (tmp, filename); | 3525 | strcpy (tmp, filename); |
3485 | } | 3526 | } |
@@ -3488,7 +3529,7 @@ lt_dlopenext (filename) | |||
3488 | tmp[len] = LT_EOS_CHAR; | 3529 | tmp[len] = LT_EOS_CHAR; |
3489 | } | 3530 | } |
3490 | 3531 | ||
3491 | strcat(tmp, shlib_ext); | 3532 | strcat (tmp, shlib_ext); |
3492 | errors = try_dlopen (&handle, tmp); | 3533 | errors = try_dlopen (&handle, tmp); |
3493 | 3534 | ||
3494 | /* As before, if the file was found but loading failed, return now | 3535 | /* As before, if the file was found but loading failed, return now |
@@ -3520,14 +3561,14 @@ lt_argz_insert (pargz, pargz_len, before, entry) | |||
3520 | if ((error = argz_insert (pargz, pargz_len, before, entry))) | 3561 | if ((error = argz_insert (pargz, pargz_len, before, entry))) |
3521 | { | 3562 | { |
3522 | switch (error) | 3563 | switch (error) |
3523 | { | 3564 | { |
3524 | case ENOMEM: | 3565 | case ENOMEM: |
3525 | LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY)); | 3566 | LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY)); |
3526 | break; | 3567 | break; |
3527 | default: | 3568 | default: |
3528 | LT_DLMUTEX_SETERROR (LT_DLSTRERROR (UNKNOWN)); | 3569 | LT_DLMUTEX_SETERROR (LT_DLSTRERROR (UNKNOWN)); |
3529 | break; | 3570 | break; |
3530 | } | 3571 | } |
3531 | return 1; | 3572 | return 1; |
3532 | } | 3573 | } |
3533 | 3574 | ||
@@ -3549,10 +3590,12 @@ lt_argz_insertinorder (pargz, pargz_len, entry) | |||
3549 | if (*pargz) | 3590 | if (*pargz) |
3550 | while ((before = argz_next (*pargz, *pargz_len, before))) | 3591 | while ((before = argz_next (*pargz, *pargz_len, before))) |
3551 | { | 3592 | { |
3552 | int cmp = strcmp (entry, before); | 3593 | int cmp = strcmp (entry, before); |
3553 | 3594 | ||
3554 | if (cmp < 0) break; | 3595 | if (cmp < 0) |
3555 | if (cmp == 0) return 0; /* No duplicates! */ | 3596 | break; |
3597 | if (cmp == 0) | ||
3598 | return 0; /* No duplicates! */ | ||
3556 | } | 3599 | } |
3557 | 3600 | ||
3558 | return lt_argz_insert (pargz, pargz_len, before, entry); | 3601 | return lt_argz_insert (pargz, pargz_len, before, entry); |
@@ -3565,26 +3608,26 @@ lt_argz_insertdir (pargz, pargz_len, dirnam, dp) | |||
3565 | const char *dirnam; | 3608 | const char *dirnam; |
3566 | struct dirent *dp; | 3609 | struct dirent *dp; |
3567 | { | 3610 | { |
3568 | char *buf = 0; | 3611 | char *buf = 0; |
3569 | size_t buf_len = 0; | 3612 | size_t buf_len = 0; |
3570 | char *end = 0; | 3613 | char *end = 0; |
3571 | size_t end_offset = 0; | 3614 | size_t end_offset = 0; |
3572 | size_t dir_len = 0; | 3615 | size_t dir_len = 0; |
3573 | int errors = 0; | 3616 | int errors = 0; |
3574 | 3617 | ||
3575 | assert (pargz); | 3618 | assert (pargz); |
3576 | assert (pargz_len); | 3619 | assert (pargz_len); |
3577 | assert (dp); | 3620 | assert (dp); |
3578 | 3621 | ||
3579 | dir_len = LT_STRLEN (dirnam); | 3622 | dir_len = LT_STRLEN (dirnam); |
3580 | end = dp->d_name + LT_D_NAMLEN(dp); | 3623 | end = dp->d_name + LT_D_NAMLEN (dp); |
3581 | 3624 | ||
3582 | /* Ignore version numbers. */ | 3625 | /* Ignore version numbers. */ |
3583 | { | 3626 | { |
3584 | char *p; | 3627 | char *p; |
3585 | for (p = end; p -1 > dp->d_name; --p) | 3628 | for (p = end; p - 1 > dp->d_name; --p) |
3586 | if (strchr (".0123456789", p[-1]) == 0) | 3629 | if (strchr (".0123456789", p[-1]) == 0) |
3587 | break; | 3630 | break; |
3588 | 3631 | ||
3589 | if (*p == '.') | 3632 | if (*p == '.') |
3590 | end = p; | 3633 | end = p; |
@@ -3593,25 +3636,25 @@ lt_argz_insertdir (pargz, pargz_len, dirnam, dp) | |||
3593 | /* Ignore filename extension. */ | 3636 | /* Ignore filename extension. */ |
3594 | { | 3637 | { |
3595 | char *p; | 3638 | char *p; |
3596 | for (p = end -1; p > dp->d_name; --p) | 3639 | for (p = end - 1; p > dp->d_name; --p) |
3597 | if (*p == '.') | 3640 | if (*p == '.') |
3598 | { | 3641 | { |
3599 | end = p; | 3642 | end = p; |
3600 | break; | 3643 | break; |
3601 | } | 3644 | } |
3602 | } | 3645 | } |
3603 | 3646 | ||
3604 | /* Prepend the directory name. */ | 3647 | /* Prepend the directory name. */ |
3605 | end_offset = end - dp->d_name; | 3648 | end_offset = end - dp->d_name; |
3606 | buf_len = dir_len + 1+ end_offset; | 3649 | buf_len = dir_len + 1 + end_offset; |
3607 | buf = LT_EMALLOC (char, 1+ buf_len); | 3650 | buf = LT_EMALLOC (char, 1 + buf_len); |
3608 | if (!buf) | 3651 | if (!buf) |
3609 | return ++errors; | 3652 | return ++errors; |
3610 | 3653 | ||
3611 | assert (buf); | 3654 | assert (buf); |
3612 | 3655 | ||
3613 | strcpy (buf, dirnam); | 3656 | strcpy (buf, dirnam); |
3614 | strcat (buf, "/"); | 3657 | strcat (buf, "/"); |
3615 | strncat (buf, dp->d_name, end_offset); | 3658 | strncat (buf, dp->d_name, end_offset); |
3616 | buf[buf_len] = LT_EOS_CHAR; | 3659 | buf[buf_len] = LT_EOS_CHAR; |
3617 | 3660 | ||
@@ -3630,26 +3673,26 @@ list_files_by_dir (dirnam, pargz, pargz_len) | |||
3630 | char **pargz; | 3673 | char **pargz; |
3631 | size_t *pargz_len; | 3674 | size_t *pargz_len; |
3632 | { | 3675 | { |
3633 | DIR *dirp = 0; | 3676 | DIR *dirp = 0; |
3634 | int errors = 0; | 3677 | int errors = 0; |
3635 | 3678 | ||
3636 | assert (dirnam && *dirnam); | 3679 | assert (dirnam && *dirnam); |
3637 | assert (pargz); | 3680 | assert (pargz); |
3638 | assert (pargz_len); | 3681 | assert (pargz_len); |
3639 | assert (dirnam[LT_STRLEN(dirnam) -1] != '/'); | 3682 | assert (dirnam[LT_STRLEN (dirnam) - 1] != '/'); |
3640 | 3683 | ||
3641 | dirp = opendir (dirnam); | 3684 | dirp = opendir (dirnam); |
3642 | if (dirp) | 3685 | if (dirp) |
3643 | { | 3686 | { |
3644 | struct dirent *dp = 0; | 3687 | struct dirent *dp = 0; |
3645 | 3688 | ||
3646 | while ((dp = readdir (dirp))) | 3689 | while ((dp = readdir (dirp))) |
3647 | if (dp->d_name[0] != '.') | 3690 | if (dp->d_name[0] != '.') |
3648 | if (lt_argz_insertdir (pargz, pargz_len, dirnam, dp)) | 3691 | if (lt_argz_insertdir (pargz, pargz_len, dirnam, dp)) |
3649 | { | 3692 | { |
3650 | ++errors; | 3693 | ++errors; |
3651 | break; | 3694 | break; |
3652 | } | 3695 | } |
3653 | 3696 | ||
3654 | closedir (dirp); | 3697 | closedir (dirp); |
3655 | } | 3698 | } |
@@ -3668,12 +3711,12 @@ foreachfile_callback (dirname, data1, data2) | |||
3668 | lt_ptr data1; | 3711 | lt_ptr data1; |
3669 | lt_ptr data2; | 3712 | lt_ptr data2; |
3670 | { | 3713 | { |
3671 | int (*func) LT_PARAMS((const char *filename, lt_ptr data)) | 3714 | int (*func) LT_PARAMS ((const char *filename, lt_ptr data)) |
3672 | = (int (*) LT_PARAMS((const char *filename, lt_ptr data))) data1; | 3715 | = (int (*)LT_PARAMS ((const char *filename, lt_ptr data))) data1; |
3673 | 3716 | ||
3674 | int is_done = 0; | 3717 | int is_done = 0; |
3675 | char *argz = 0; | 3718 | char *argz = 0; |
3676 | size_t argz_len = 0; | 3719 | size_t argz_len = 0; |
3677 | 3720 | ||
3678 | if (list_files_by_dir (dirname, &argz, &argz_len) != 0) | 3721 | if (list_files_by_dir (dirname, &argz, &argz_len) != 0) |
3679 | goto cleanup; | 3722 | goto cleanup; |
@@ -3684,10 +3727,10 @@ foreachfile_callback (dirname, data1, data2) | |||
3684 | char *filename = 0; | 3727 | char *filename = 0; |
3685 | while ((filename = argz_next (argz, argz_len, filename))) | 3728 | while ((filename = argz_next (argz, argz_len, filename))) |
3686 | if ((is_done = (*func) (filename, data2))) | 3729 | if ((is_done = (*func) (filename, data2))) |
3687 | break; | 3730 | break; |
3688 | } | 3731 | } |
3689 | 3732 | ||
3690 | cleanup: | 3733 | cleanup: |
3691 | LT_DLFREE (argz); | 3734 | LT_DLFREE (argz); |
3692 | 3735 | ||
3693 | return is_done; | 3736 | return is_done; |
@@ -3711,34 +3754,34 @@ lt_dlforeachfile (search_path, func, data) | |||
3711 | if (search_path) | 3754 | if (search_path) |
3712 | { | 3755 | { |
3713 | /* If a specific path was passed, search only the directories | 3756 | /* If a specific path was passed, search only the directories |
3714 | listed in it. */ | 3757 | listed in it. */ |
3715 | is_done = foreach_dirinpath (search_path, 0, | 3758 | is_done = foreach_dirinpath (search_path, 0, |
3716 | foreachfile_callback, func, data); | 3759 | foreachfile_callback, func, data); |
3717 | } | 3760 | } |
3718 | else | 3761 | else |
3719 | { | 3762 | { |
3720 | /* Otherwise search the default paths. */ | 3763 | /* Otherwise search the default paths. */ |
3721 | is_done = foreach_dirinpath (user_search_path, 0, | 3764 | is_done = foreach_dirinpath (user_search_path, 0, |
3722 | foreachfile_callback, func, data); | 3765 | foreachfile_callback, func, data); |
3723 | if (!is_done) | 3766 | if (!is_done) |
3724 | { | 3767 | { |
3725 | is_done = foreach_dirinpath (getenv("LTDL_LIBRARY_PATH"), 0, | 3768 | is_done = foreach_dirinpath (getenv ("LTDL_LIBRARY_PATH"), 0, |
3726 | foreachfile_callback, func, data); | 3769 | foreachfile_callback, func, data); |
3727 | } | 3770 | } |
3728 | 3771 | ||
3729 | #ifdef LTDL_SHLIBPATH_VAR | 3772 | #ifdef LTDL_SHLIBPATH_VAR |
3730 | if (!is_done) | 3773 | if (!is_done) |
3731 | { | 3774 | { |
3732 | is_done = foreach_dirinpath (getenv(LTDL_SHLIBPATH_VAR), 0, | 3775 | is_done = foreach_dirinpath (getenv (LTDL_SHLIBPATH_VAR), 0, |
3733 | foreachfile_callback, func, data); | 3776 | foreachfile_callback, func, data); |
3734 | } | 3777 | } |
3735 | #endif | 3778 | #endif |
3736 | #ifdef LTDL_SYSSEARCHPATH | 3779 | #ifdef LTDL_SYSSEARCHPATH |
3737 | if (!is_done) | 3780 | if (!is_done) |
3738 | { | 3781 | { |
3739 | is_done = foreach_dirinpath (getenv(LTDL_SYSSEARCHPATH), 0, | 3782 | is_done = foreach_dirinpath (getenv (LTDL_SYSSEARCHPATH), 0, |
3740 | foreachfile_callback, func, data); | 3783 | foreachfile_callback, func, data); |
3741 | } | 3784 | } |
3742 | #endif | 3785 | #endif |
3743 | } | 3786 | } |
3744 | 3787 | ||
@@ -3780,16 +3823,16 @@ lt_dlclose (handle) | |||
3780 | lt_user_data data = handle->loader->dlloader_data; | 3823 | lt_user_data data = handle->loader->dlloader_data; |
3781 | 3824 | ||
3782 | if (handle != handles) | 3825 | if (handle != handles) |
3783 | { | 3826 | { |
3784 | last->next = handle->next; | 3827 | last->next = handle->next; |
3785 | } | 3828 | } |
3786 | else | 3829 | else |
3787 | { | 3830 | { |
3788 | handles = handle->next; | 3831 | handles = handle->next; |
3789 | } | 3832 | } |
3790 | 3833 | ||
3791 | errors += handle->loader->module_close (data, handle->module); | 3834 | errors += handle->loader->module_close (data, handle->module); |
3792 | errors += unload_deplibs(handle); | 3835 | errors += unload_deplibs (handle); |
3793 | 3836 | ||
3794 | /* It is up to the callers to free the data itself. */ | 3837 | /* It is up to the callers to free the data itself. */ |
3795 | LT_DLFREE (handle->caller_data); | 3838 | LT_DLFREE (handle->caller_data); |
@@ -3807,7 +3850,7 @@ lt_dlclose (handle) | |||
3807 | ++errors; | 3850 | ++errors; |
3808 | } | 3851 | } |
3809 | 3852 | ||
3810 | done: | 3853 | done: |
3811 | LT_DLMUTEX_UNLOCK (); | 3854 | LT_DLMUTEX_UNLOCK (); |
3812 | 3855 | ||
3813 | return errors; | 3856 | return errors; |
@@ -3819,8 +3862,8 @@ lt_dlsym (handle, symbol) | |||
3819 | const char *symbol; | 3862 | const char *symbol; |
3820 | { | 3863 | { |
3821 | size_t lensym; | 3864 | size_t lensym; |
3822 | char lsym[LT_SYMBOL_LENGTH]; | 3865 | char lsym[LT_SYMBOL_LENGTH]; |
3823 | char *sym; | 3866 | char *sym; |
3824 | lt_ptr address; | 3867 | lt_ptr address; |
3825 | lt_user_data data; | 3868 | lt_user_data data; |
3826 | 3869 | ||
@@ -3837,7 +3880,7 @@ lt_dlsym (handle, symbol) | |||
3837 | } | 3880 | } |
3838 | 3881 | ||
3839 | lensym = LT_STRLEN (symbol) + LT_STRLEN (handle->loader->sym_prefix) | 3882 | lensym = LT_STRLEN (symbol) + LT_STRLEN (handle->loader->sym_prefix) |
3840 | + LT_STRLEN (handle->info.name); | 3883 | + LT_STRLEN (handle->info.name); |
3841 | 3884 | ||
3842 | if (lensym + LT_SYMBOL_OVERHEAD < LT_SYMBOL_LENGTH) | 3885 | if (lensym + LT_SYMBOL_OVERHEAD < LT_SYMBOL_LENGTH) |
3843 | { | 3886 | { |
@@ -3847,10 +3890,10 @@ lt_dlsym (handle, symbol) | |||
3847 | { | 3890 | { |
3848 | sym = LT_EMALLOC (char, lensym + LT_SYMBOL_OVERHEAD + 1); | 3891 | sym = LT_EMALLOC (char, lensym + LT_SYMBOL_OVERHEAD + 1); |
3849 | if (!sym) | 3892 | if (!sym) |
3850 | { | 3893 | { |
3851 | LT_DLMUTEX_SETERROR (LT_DLSTRERROR (BUFFER_OVERFLOW)); | 3894 | LT_DLMUTEX_SETERROR (LT_DLSTRERROR (BUFFER_OVERFLOW)); |
3852 | return 0; | 3895 | return 0; |
3853 | } | 3896 | } |
3854 | } | 3897 | } |
3855 | 3898 | ||
3856 | data = handle->loader->dlloader_data; | 3899 | data = handle->loader->dlloader_data; |
@@ -3862,40 +3905,40 @@ lt_dlsym (handle, symbol) | |||
3862 | 3905 | ||
3863 | /* this is a libtool module */ | 3906 | /* this is a libtool module */ |
3864 | if (handle->loader->sym_prefix) | 3907 | if (handle->loader->sym_prefix) |
3865 | { | 3908 | { |
3866 | strcpy(sym, handle->loader->sym_prefix); | 3909 | strcpy (sym, handle->loader->sym_prefix); |
3867 | strcat(sym, handle->info.name); | 3910 | strcat (sym, handle->info.name); |
3868 | } | 3911 | } |
3869 | else | 3912 | else |
3870 | { | 3913 | { |
3871 | strcpy(sym, handle->info.name); | 3914 | strcpy (sym, handle->info.name); |
3872 | } | 3915 | } |
3873 | 3916 | ||
3874 | strcat(sym, "_LTX_"); | 3917 | strcat (sym, "_LTX_"); |
3875 | strcat(sym, symbol); | 3918 | strcat (sym, symbol); |
3876 | 3919 | ||
3877 | /* try "modulename_LTX_symbol" */ | 3920 | /* try "modulename_LTX_symbol" */ |
3878 | address = handle->loader->find_sym (data, handle->module, sym); | 3921 | address = handle->loader->find_sym (data, handle->module, sym); |
3879 | if (address) | 3922 | if (address) |
3880 | { | 3923 | { |
3881 | if (sym != lsym) | 3924 | if (sym != lsym) |
3882 | { | 3925 | { |
3883 | LT_DLFREE (sym); | 3926 | LT_DLFREE (sym); |
3884 | } | 3927 | } |
3885 | return address; | 3928 | return address; |
3886 | } | 3929 | } |
3887 | LT_DLMUTEX_SETERROR (saved_error); | 3930 | LT_DLMUTEX_SETERROR (saved_error); |
3888 | } | 3931 | } |
3889 | 3932 | ||
3890 | /* otherwise try "symbol" */ | 3933 | /* otherwise try "symbol" */ |
3891 | if (handle->loader->sym_prefix) | 3934 | if (handle->loader->sym_prefix) |
3892 | { | 3935 | { |
3893 | strcpy(sym, handle->loader->sym_prefix); | 3936 | strcpy (sym, handle->loader->sym_prefix); |
3894 | strcat(sym, symbol); | 3937 | strcat (sym, symbol); |
3895 | } | 3938 | } |
3896 | else | 3939 | else |
3897 | { | 3940 | { |
3898 | strcpy(sym, symbol); | 3941 | strcpy (sym, symbol); |
3899 | } | 3942 | } |
3900 | 3943 | ||
3901 | address = handle->loader->find_sym (data, handle->module, sym); | 3944 | address = handle->loader->find_sym (data, handle->module, sym); |
@@ -3924,10 +3967,10 @@ lt_dlpath_insertdir (ppath, before, dir) | |||
3924 | char *before; | 3967 | char *before; |
3925 | const char *dir; | 3968 | const char *dir; |
3926 | { | 3969 | { |
3927 | int errors = 0; | 3970 | int errors = 0; |
3928 | char *canonical = 0; | 3971 | char *canonical = 0; |
3929 | char *argz = 0; | 3972 | char *argz = 0; |
3930 | size_t argz_len = 0; | 3973 | size_t argz_len = 0; |
3931 | 3974 | ||
3932 | assert (ppath); | 3975 | assert (ppath); |
3933 | assert (dir && *dir); | 3976 | assert (dir && *dir); |
@@ -3943,12 +3986,12 @@ lt_dlpath_insertdir (ppath, before, dir) | |||
3943 | /* If *PPATH is empty, set it to DIR. */ | 3986 | /* If *PPATH is empty, set it to DIR. */ |
3944 | if (*ppath == 0) | 3987 | if (*ppath == 0) |
3945 | { | 3988 | { |
3946 | assert (!before); /* BEFORE cannot be set without PPATH. */ | 3989 | assert (!before); /* BEFORE cannot be set without PPATH. */ |
3947 | assert (dir); /* Without DIR, don't call this function! */ | 3990 | assert (dir); /* Without DIR, don't call this function! */ |
3948 | 3991 | ||
3949 | *ppath = lt_estrdup (dir); | 3992 | *ppath = lt_estrdup (dir); |
3950 | if (*ppath == 0) | 3993 | if (*ppath == 0) |
3951 | ++errors; | 3994 | ++errors; |
3952 | 3995 | ||
3953 | return errors; | 3996 | return errors; |
3954 | } | 3997 | } |
@@ -3981,9 +4024,9 @@ lt_dlpath_insertdir (ppath, before, dir) | |||
3981 | } | 4024 | } |
3982 | 4025 | ||
3983 | argz_stringify (argz, argz_len, LT_PATHSEP_CHAR); | 4026 | argz_stringify (argz, argz_len, LT_PATHSEP_CHAR); |
3984 | LT_DLMEM_REASSIGN (*ppath, argz); | 4027 | LT_DLMEM_REASSIGN (*ppath, argz); |
3985 | 4028 | ||
3986 | cleanup: | 4029 | cleanup: |
3987 | LT_DLFREE (canonical); | 4030 | LT_DLFREE (canonical); |
3988 | LT_DLFREE (argz); | 4031 | LT_DLFREE (argz); |
3989 | 4032 | ||
@@ -4000,7 +4043,7 @@ lt_dladdsearchdir (search_dir) | |||
4000 | { | 4043 | { |
4001 | LT_DLMUTEX_LOCK (); | 4044 | LT_DLMUTEX_LOCK (); |
4002 | if (lt_dlpath_insertdir (&user_search_path, 0, search_dir) != 0) | 4045 | if (lt_dlpath_insertdir (&user_search_path, 0, search_dir) != 0) |
4003 | ++errors; | 4046 | ++errors; |
4004 | LT_DLMUTEX_UNLOCK (); | 4047 | LT_DLMUTEX_UNLOCK (); |
4005 | } | 4048 | } |
4006 | 4049 | ||
@@ -4018,12 +4061,12 @@ lt_dlinsertsearchdir (before, search_dir) | |||
4018 | { | 4061 | { |
4019 | LT_DLMUTEX_LOCK (); | 4062 | LT_DLMUTEX_LOCK (); |
4020 | if ((before < user_search_path) | 4063 | if ((before < user_search_path) |
4021 | || (before >= user_search_path + LT_STRLEN (user_search_path))) | 4064 | || (before >= user_search_path + LT_STRLEN (user_search_path))) |
4022 | { | 4065 | { |
4023 | LT_DLMUTEX_UNLOCK (); | 4066 | LT_DLMUTEX_UNLOCK (); |
4024 | LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INVALID_POSITION)); | 4067 | LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INVALID_POSITION)); |
4025 | return 1; | 4068 | return 1; |
4026 | } | 4069 | } |
4027 | LT_DLMUTEX_UNLOCK (); | 4070 | LT_DLMUTEX_UNLOCK (); |
4028 | } | 4071 | } |
4029 | 4072 | ||
@@ -4031,10 +4074,10 @@ lt_dlinsertsearchdir (before, search_dir) | |||
4031 | { | 4074 | { |
4032 | LT_DLMUTEX_LOCK (); | 4075 | LT_DLMUTEX_LOCK (); |
4033 | if (lt_dlpath_insertdir (&user_search_path, | 4076 | if (lt_dlpath_insertdir (&user_search_path, |
4034 | (char *) before, search_dir) != 0) | 4077 | (char *) before, search_dir) != 0) |
4035 | { | 4078 | { |
4036 | ++errors; | 4079 | ++errors; |
4037 | } | 4080 | } |
4038 | LT_DLMUTEX_UNLOCK (); | 4081 | LT_DLMUTEX_UNLOCK (); |
4039 | } | 4082 | } |
4040 | 4083 | ||
@@ -4045,7 +4088,7 @@ int | |||
4045 | lt_dlsetsearchpath (search_path) | 4088 | lt_dlsetsearchpath (search_path) |
4046 | const char *search_path; | 4089 | const char *search_path; |
4047 | { | 4090 | { |
4048 | int errors = 0; | 4091 | int errors = 0; |
4049 | 4092 | ||
4050 | LT_DLMUTEX_LOCK (); | 4093 | LT_DLMUTEX_LOCK (); |
4051 | LT_DLFREE (user_search_path); | 4094 | LT_DLFREE (user_search_path); |
@@ -4096,7 +4139,7 @@ lt_dlmakeresident (handle) | |||
4096 | } | 4139 | } |
4097 | 4140 | ||
4098 | int | 4141 | int |
4099 | lt_dlisresident (handle) | 4142 | lt_dlisresident (handle) |
4100 | lt_dlhandle handle; | 4143 | lt_dlhandle handle; |
4101 | { | 4144 | { |
4102 | if (!handle) | 4145 | if (!handle) |
@@ -4107,10 +4150,10 @@ lt_dlisresident (handle) | |||
4107 | 4150 | ||
4108 | return LT_DLIS_RESIDENT (handle); | 4151 | return LT_DLIS_RESIDENT (handle); |
4109 | } | 4152 | } |
4153 | |||
4110 | 4154 | ||
4111 | 4155 | ||
4112 | 4156 | ||
4113 | |||
4114 | /* --- MODULE INFORMATION --- */ | 4157 | /* --- MODULE INFORMATION --- */ |
4115 | 4158 | ||
4116 | const lt_dlinfo * | 4159 | const lt_dlinfo * |
@@ -4135,7 +4178,7 @@ lt_dlhandle_next (place) | |||
4135 | 4178 | ||
4136 | int | 4179 | int |
4137 | lt_dlforeach (func, data) | 4180 | lt_dlforeach (func, data) |
4138 | int (*func) LT_PARAMS((lt_dlhandle handle, lt_ptr data)); | 4181 | int (*func) LT_PARAMS ((lt_dlhandle handle, lt_ptr data)); |
4139 | lt_ptr data; | 4182 | lt_ptr data; |
4140 | { | 4183 | { |
4141 | int errors = 0; | 4184 | int errors = 0; |
@@ -4150,10 +4193,10 @@ lt_dlforeach (func, data) | |||
4150 | 4193 | ||
4151 | cur = cur->next; | 4194 | cur = cur->next; |
4152 | if ((*func) (tmp, data)) | 4195 | if ((*func) (tmp, data)) |
4153 | { | 4196 | { |
4154 | ++errors; | 4197 | ++errors; |
4155 | break; | 4198 | break; |
4156 | } | 4199 | } |
4157 | } | 4200 | } |
4158 | 4201 | ||
4159 | LT_DLMUTEX_UNLOCK (); | 4202 | LT_DLMUTEX_UNLOCK (); |
@@ -4195,10 +4238,10 @@ lt_dlcaller_set_data (key, handle, data) | |||
4195 | for (i = 0; i < n_elements; ++i) | 4238 | for (i = 0; i < n_elements; ++i) |
4196 | { | 4239 | { |
4197 | if (handle->caller_data[i].key == key) | 4240 | if (handle->caller_data[i].key == key) |
4198 | { | 4241 | { |
4199 | stale = handle->caller_data[i].data; | 4242 | stale = handle->caller_data[i].data; |
4200 | break; | 4243 | break; |
4201 | } | 4244 | } |
4202 | } | 4245 | } |
4203 | 4246 | ||
4204 | /* Ensure that there is enough room in this handle's caller_data | 4247 | /* Ensure that there is enough room in this handle's caller_data |
@@ -4206,31 +4249,31 @@ lt_dlcaller_set_data (key, handle, data) | |||
4206 | if (i == n_elements) | 4249 | if (i == n_elements) |
4207 | { | 4250 | { |
4208 | lt_caller_data *temp | 4251 | lt_caller_data *temp |
4209 | = LT_DLREALLOC (lt_caller_data, handle->caller_data, 2+ n_elements); | 4252 | = LT_DLREALLOC (lt_caller_data, handle->caller_data, 2 + n_elements); |
4210 | 4253 | ||
4211 | if (!temp) | 4254 | if (!temp) |
4212 | { | 4255 | { |
4213 | stale = 0; | 4256 | stale = 0; |
4214 | goto done; | 4257 | goto done; |
4215 | } | 4258 | } |
4216 | 4259 | ||
4217 | handle->caller_data = temp; | 4260 | handle->caller_data = temp; |
4218 | 4261 | ||
4219 | /* We only need this if we needed to allocate a new caller_data. */ | 4262 | /* We only need this if we needed to allocate a new caller_data. */ |
4220 | handle->caller_data[i].key = key; | 4263 | handle->caller_data[i].key = key; |
4221 | handle->caller_data[1+ i].key = 0; | 4264 | handle->caller_data[1 + i].key = 0; |
4222 | } | 4265 | } |
4223 | 4266 | ||
4224 | handle->caller_data[i].data = data; | 4267 | handle->caller_data[i].data = data; |
4225 | 4268 | ||
4226 | done: | 4269 | done: |
4227 | LT_DLMUTEX_UNLOCK (); | 4270 | LT_DLMUTEX_UNLOCK (); |
4228 | 4271 | ||
4229 | return stale; | 4272 | return stale; |
4230 | } | 4273 | } |
4231 | 4274 | ||
4232 | lt_ptr | 4275 | lt_ptr |
4233 | lt_dlcaller_get_data (key, handle) | 4276 | lt_dlcaller_get_data (key, handle) |
4234 | lt_dlcaller_id key; | 4277 | lt_dlcaller_id key; |
4235 | lt_dlhandle handle; | 4278 | lt_dlhandle handle; |
4236 | { | 4279 | { |
@@ -4245,11 +4288,11 @@ lt_dlcaller_get_data (key, handle) | |||
4245 | int i; | 4288 | int i; |
4246 | for (i = 0; handle->caller_data[i].key; ++i) | 4289 | for (i = 0; handle->caller_data[i].key; ++i) |
4247 | { | 4290 | { |
4248 | if (handle->caller_data[i].key == key) | 4291 | if (handle->caller_data[i].key == key) |
4249 | { | 4292 | { |
4250 | result = handle->caller_data[i].data; | 4293 | result = handle->caller_data[i].data; |
4251 | break; | 4294 | break; |
4252 | } | 4295 | } |
4253 | } | 4296 | } |
4254 | } | 4297 | } |
4255 | 4298 | ||
@@ -4257,9 +4300,9 @@ lt_dlcaller_get_data (key, handle) | |||
4257 | 4300 | ||
4258 | return result; | 4301 | return result; |
4259 | } | 4302 | } |
4303 | |||
4260 | 4304 | ||
4261 | 4305 | ||
4262 | |||
4263 | /* --- USER MODULE LOADER API --- */ | 4306 | /* --- USER MODULE LOADER API --- */ |
4264 | 4307 | ||
4265 | 4308 | ||
@@ -4272,10 +4315,9 @@ lt_dlloader_add (place, dlloader, loader_name) | |||
4272 | int errors = 0; | 4315 | int errors = 0; |
4273 | lt_dlloader *node = 0, *ptr = 0; | 4316 | lt_dlloader *node = 0, *ptr = 0; |
4274 | 4317 | ||
4275 | if ((dlloader == 0) /* diagnose null parameters */ | 4318 | if ((dlloader == 0) /* diagnose null parameters */ |
4276 | || (dlloader->module_open == 0) | 4319 | || (dlloader->module_open == 0) |
4277 | || (dlloader->module_close == 0) | 4320 | || (dlloader->module_close == 0) || (dlloader->find_sym == 0)) |
4278 | || (dlloader->find_sym == 0)) | ||
4279 | { | 4321 | { |
4280 | LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INVALID_LOADER)); | 4322 | LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INVALID_LOADER)); |
4281 | return 1; | 4323 | return 1; |
@@ -4286,14 +4328,14 @@ lt_dlloader_add (place, dlloader, loader_name) | |||
4286 | if (!node) | 4328 | if (!node) |
4287 | return 1; | 4329 | return 1; |
4288 | 4330 | ||
4289 | node->next = 0; | 4331 | node->next = 0; |
4290 | node->loader_name = loader_name; | 4332 | node->loader_name = loader_name; |
4291 | node->sym_prefix = dlloader->sym_prefix; | 4333 | node->sym_prefix = dlloader->sym_prefix; |
4292 | node->dlloader_exit = dlloader->dlloader_exit; | 4334 | node->dlloader_exit = dlloader->dlloader_exit; |
4293 | node->module_open = dlloader->module_open; | 4335 | node->module_open = dlloader->module_open; |
4294 | node->module_close = dlloader->module_close; | 4336 | node->module_close = dlloader->module_close; |
4295 | node->find_sym = dlloader->find_sym; | 4337 | node->find_sym = dlloader->find_sym; |
4296 | node->dlloader_data = dlloader->dlloader_data; | 4338 | node->dlloader_data = dlloader->dlloader_data; |
4297 | 4339 | ||
4298 | LT_DLMUTEX_LOCK (); | 4340 | LT_DLMUTEX_LOCK (); |
4299 | if (!loaders) | 4341 | if (!loaders) |
@@ -4304,11 +4346,11 @@ lt_dlloader_add (place, dlloader, loader_name) | |||
4304 | else if (!place) | 4346 | else if (!place) |
4305 | { | 4347 | { |
4306 | /* If PLACE is not set, add NODE to the end of the | 4348 | /* If PLACE is not set, add NODE to the end of the |
4307 | LOADERS list. */ | 4349 | LOADERS list. */ |
4308 | for (ptr = loaders; ptr->next; ptr = ptr->next) | 4350 | for (ptr = loaders; ptr->next; ptr = ptr->next) |
4309 | { | 4351 | { |
4310 | /*NOWORK*/; | 4352 | /*NOWORK*/; |
4311 | } | 4353 | } |
4312 | 4354 | ||
4313 | ptr->next = node; | 4355 | ptr->next = node; |
4314 | } | 4356 | } |
@@ -4322,21 +4364,21 @@ lt_dlloader_add (place, dlloader, loader_name) | |||
4322 | { | 4364 | { |
4323 | /* Find the node immediately preceding PLACE. */ | 4365 | /* Find the node immediately preceding PLACE. */ |
4324 | for (ptr = loaders; ptr->next != place; ptr = ptr->next) | 4366 | for (ptr = loaders; ptr->next != place; ptr = ptr->next) |
4325 | { | 4367 | { |
4326 | /*NOWORK*/; | 4368 | /*NOWORK*/; |
4327 | } | 4369 | } |
4328 | 4370 | ||
4329 | if (ptr->next != place) | 4371 | if (ptr->next != place) |
4330 | { | 4372 | { |
4331 | LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INVALID_LOADER)); | 4373 | LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INVALID_LOADER)); |
4332 | ++errors; | 4374 | ++errors; |
4333 | } | 4375 | } |
4334 | else | 4376 | else |
4335 | { | 4377 | { |
4336 | /* Insert NODE between PTR and PLACE. */ | 4378 | /* Insert NODE between PTR and PLACE. */ |
4337 | node->next = place; | 4379 | node->next = place; |
4338 | ptr->next = node; | 4380 | ptr->next = node; |
4339 | } | 4381 | } |
4340 | } | 4382 | } |
4341 | 4383 | ||
4342 | LT_DLMUTEX_UNLOCK (); | 4384 | LT_DLMUTEX_UNLOCK (); |
@@ -4361,14 +4403,14 @@ lt_dlloader_remove (loader_name) | |||
4361 | LT_DLMUTEX_LOCK (); | 4403 | LT_DLMUTEX_LOCK (); |
4362 | 4404 | ||
4363 | /* Fail if there are any open modules which use this loader. */ | 4405 | /* Fail if there are any open modules which use this loader. */ |
4364 | for (handle = handles; handle; handle = handle->next) | 4406 | for (handle = handles; handle; handle = handle->next) |
4365 | { | 4407 | { |
4366 | if (handle->loader == place) | 4408 | if (handle->loader == place) |
4367 | { | 4409 | { |
4368 | LT_DLMUTEX_SETERROR (LT_DLSTRERROR (REMOVE_LOADER)); | 4410 | LT_DLMUTEX_SETERROR (LT_DLSTRERROR (REMOVE_LOADER)); |
4369 | ++errors; | 4411 | ++errors; |
4370 | goto done; | 4412 | goto done; |
4371 | } | 4413 | } |
4372 | } | 4414 | } |
4373 | 4415 | ||
4374 | if (place == loaders) | 4416 | if (place == loaders) |
@@ -4381,12 +4423,12 @@ lt_dlloader_remove (loader_name) | |||
4381 | /* Find the loader before the one being removed. */ | 4423 | /* Find the loader before the one being removed. */ |
4382 | lt_dlloader *prev; | 4424 | lt_dlloader *prev; |
4383 | for (prev = loaders; prev->next; prev = prev->next) | 4425 | for (prev = loaders; prev->next; prev = prev->next) |
4384 | { | 4426 | { |
4385 | if (!strcmp (prev->next->loader_name, loader_name)) | 4427 | if (!strcmp (prev->next->loader_name, loader_name)) |
4386 | { | 4428 | { |
4387 | break; | 4429 | break; |
4388 | } | 4430 | } |
4389 | } | 4431 | } |
4390 | 4432 | ||
4391 | place = prev->next; | 4433 | place = prev->next; |
4392 | prev->next = prev->next->next; | 4434 | prev->next = prev->next->next; |
@@ -4399,7 +4441,7 @@ lt_dlloader_remove (loader_name) | |||
4399 | 4441 | ||
4400 | LT_DLFREE (place); | 4442 | LT_DLFREE (place); |
4401 | 4443 | ||
4402 | done: | 4444 | done: |
4403 | LT_DLMUTEX_UNLOCK (); | 4445 | LT_DLMUTEX_UNLOCK (); |
4404 | 4446 | ||
4405 | return errors; | 4447 | return errors; |
@@ -4468,9 +4510,9 @@ lt_dlloader_find (loader_name) | |||
4468 | for (place = loaders; place; place = place->next) | 4510 | for (place = loaders; place; place = place->next) |
4469 | { | 4511 | { |
4470 | if (strcmp (place->loader_name, loader_name) == 0) | 4512 | if (strcmp (place->loader_name, loader_name) == 0) |
4471 | { | 4513 | { |
4472 | break; | 4514 | break; |
4473 | } | 4515 | } |
4474 | } | 4516 | } |
4475 | LT_DLMUTEX_UNLOCK (); | 4517 | LT_DLMUTEX_UNLOCK (); |
4476 | 4518 | ||
diff --git a/libltdl/ltdl.h b/libltdl/ltdl.h index 995d4038..2e246515 100644 --- a/libltdl/ltdl.h +++ b/libltdl/ltdl.h | |||
@@ -28,9 +28,9 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | |||
28 | #ifndef LTDL_H | 28 | #ifndef LTDL_H |
29 | #define LTDL_H 1 | 29 | #define LTDL_H 1 |
30 | 30 | ||
31 | #include <sys/types.h> /* for size_t declaration */ | 31 | #include <sys/types.h> /* for size_t declaration */ |
32 | |||
33 | 32 | ||
33 | |||
34 | /* --- MACROS FOR PORTABILITY --- */ | 34 | /* --- MACROS FOR PORTABILITY --- */ |
35 | 35 | ||
36 | 36 | ||
@@ -44,13 +44,11 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | |||
44 | # define LT_BEGIN_C_DECLS extern "C" { | 44 | # define LT_BEGIN_C_DECLS extern "C" { |
45 | # define LT_END_C_DECLS } | 45 | # define LT_END_C_DECLS } |
46 | #else | 46 | #else |
47 | # define LT_BEGIN_C_DECLS /* empty */ | 47 | # define LT_BEGIN_C_DECLS /* empty */ |
48 | # define LT_END_C_DECLS /* empty */ | 48 | # define LT_END_C_DECLS /* empty */ |
49 | #endif | 49 | #endif |
50 | 50 | ||
51 | LT_BEGIN_C_DECLS | 51 | LT_BEGIN_C_DECLS |
52 | |||
53 | |||
54 | /* LT_PARAMS is a macro used to wrap function prototypes, so that compilers | 52 | /* LT_PARAMS is a macro used to wrap function prototypes, so that compilers |
55 | that don't understand ANSI C prototypes still work, and ANSI C | 53 | that don't understand ANSI C prototypes still work, and ANSI C |
56 | compilers can issue warnings about type mismatches. */ | 54 | compilers can issue warnings about type mismatches. */ |
@@ -61,7 +59,6 @@ LT_BEGIN_C_DECLS | |||
61 | # define LT_PARAMS(protos) () | 59 | # define LT_PARAMS(protos) () |
62 | # define lt_ptr char* | 60 | # define lt_ptr char* |
63 | #endif | 61 | #endif |
64 | |||
65 | /* LT_STMT_START/END are used to create macros which expand to a | 62 | /* LT_STMT_START/END are used to create macros which expand to a |
66 | a single compound statement in a portable way. */ | 63 | a single compound statement in a portable way. */ |
67 | #if defined (__GNUC__) && !defined (__STRICT_ANSI__) && !defined (__cplusplus) | 64 | #if defined (__GNUC__) && !defined (__STRICT_ANSI__) && !defined (__cplusplus) |
@@ -76,7 +73,6 @@ LT_BEGIN_C_DECLS | |||
76 | # define LT_STMT_END while (0) | 73 | # define LT_STMT_END while (0) |
77 | # endif | 74 | # endif |
78 | #endif | 75 | #endif |
79 | |||
80 | /* LT_CONC creates a new concatenated symbol for the compiler | 76 | /* LT_CONC creates a new concatenated symbol for the compiler |
81 | in a portable way. */ | 77 | in a portable way. */ |
82 | #if defined(__STDC__) || defined(__cplusplus) || defined(_MSC_VER) | 78 | #if defined(__STDC__) || defined(__cplusplus) || defined(_MSC_VER) |
@@ -84,15 +80,9 @@ LT_BEGIN_C_DECLS | |||
84 | #else | 80 | #else |
85 | # define LT_CONC(s,t) s/**/t | 81 | # define LT_CONC(s,t) s/**/t |
86 | #endif | 82 | #endif |
87 | |||
88 | /* LT_STRLEN can be used safely on NULL pointers. */ | 83 | /* LT_STRLEN can be used safely on NULL pointers. */ |
89 | #define LT_STRLEN(s) (((s) && (s)[0]) ? strlen (s) : 0) | 84 | #define LT_STRLEN(s) (((s) && (s)[0]) ? strlen (s) : 0) |
90 | 85 | /* --- WINDOWS SUPPORT --- */ | |
91 | |||
92 | |||
93 | /* --- WINDOWS SUPPORT --- */ | ||
94 | |||
95 | |||
96 | /* Canonicalise Windows and Cygwin recognition macros. */ | 86 | /* Canonicalise Windows and Cygwin recognition macros. */ |
97 | #ifdef __CYGWIN32__ | 87 | #ifdef __CYGWIN32__ |
98 | # ifndef __CYGWIN__ | 88 | # ifndef __CYGWIN__ |
@@ -110,8 +100,6 @@ LT_BEGIN_C_DECLS | |||
110 | # endif | 100 | # endif |
111 | # endif | 101 | # endif |
112 | #endif | 102 | #endif |
113 | |||
114 | |||
115 | #ifdef __WINDOWS__ | 103 | #ifdef __WINDOWS__ |
116 | # ifndef __CYGWIN__ | 104 | # ifndef __CYGWIN__ |
117 | /* LT_DIRSEP_CHAR is accepted *in addition* to '/' as a directory | 105 | /* LT_DIRSEP_CHAR is accepted *in addition* to '/' as a directory |
@@ -123,81 +111,72 @@ LT_BEGIN_C_DECLS | |||
123 | #ifndef LT_PATHSEP_CHAR | 111 | #ifndef LT_PATHSEP_CHAR |
124 | # define LT_PATHSEP_CHAR ':' | 112 | # define LT_PATHSEP_CHAR ':' |
125 | #endif | 113 | #endif |
126 | |||
127 | /* DLL building support on win32 hosts; mostly to workaround their | 114 | /* DLL building support on win32 hosts; mostly to workaround their |
128 | ridiculous implementation of data symbol exporting. */ | 115 | ridiculous implementation of data symbol exporting. */ |
129 | #ifndef LT_SCOPE | 116 | #ifndef LT_SCOPE |
130 | # ifdef __WINDOWS__ | 117 | # ifdef __WINDOWS__ |
131 | # ifdef DLL_EXPORT /* defined by libtool (if required) */ | 118 | # ifdef DLL_EXPORT /* defined by libtool (if required) */ |
132 | # define LT_SCOPE __declspec(dllexport) | 119 | # define LT_SCOPE __declspec(dllexport) |
133 | # endif | 120 | # endif |
134 | # ifdef LIBLTDL_DLL_IMPORT /* define if linking with this dll */ | 121 | # ifdef LIBLTDL_DLL_IMPORT /* define if linking with this dll */ |
135 | # define LT_SCOPE extern __declspec(dllimport) | 122 | # define LT_SCOPE extern __declspec(dllimport) |
136 | # endif | 123 | # endif |
137 | # endif | 124 | # endif |
138 | # ifndef LT_SCOPE /* static linking or !__WINDOWS__ */ | 125 | # ifndef LT_SCOPE /* static linking or !__WINDOWS__ */ |
139 | # define LT_SCOPE extern | 126 | # define LT_SCOPE extern |
140 | # endif | 127 | # endif |
141 | #endif | 128 | #endif |
142 | 129 | #if defined(_MSC_VER) /* Visual Studio */ | |
143 | |||
144 | #if defined(_MSC_VER) /* Visual Studio */ | ||
145 | # define R_OK 4 | 130 | # define R_OK 4 |
146 | #endif | 131 | #endif |
147 | 132 | /* --- DYNAMIC MODULE LOADING API --- */ | |
148 | 133 | typedef struct lt_dlhandle_struct *lt_dlhandle; /* A loaded module. */ | |
149 | |||
150 | /* --- DYNAMIC MODULE LOADING API --- */ | ||
151 | |||
152 | |||
153 | typedef struct lt_dlhandle_struct *lt_dlhandle; /* A loaded module. */ | ||
154 | 134 | ||
155 | /* Initialisation and finalisation functions for libltdl. */ | 135 | /* Initialisation and finalisation functions for libltdl. */ |
156 | LT_SCOPE int lt_dlinit LT_PARAMS((void)); | 136 | LT_SCOPE int lt_dlinit LT_PARAMS ((void)); |
157 | LT_SCOPE int lt_dlexit LT_PARAMS((void)); | 137 | LT_SCOPE int lt_dlexit LT_PARAMS ((void)); |
158 | 138 | ||
159 | /* Module search path manipulation. */ | 139 | /* Module search path manipulation. */ |
160 | LT_SCOPE int lt_dladdsearchdir LT_PARAMS((const char *search_dir)); | 140 | LT_SCOPE int lt_dladdsearchdir LT_PARAMS ((const char *search_dir)); |
161 | LT_SCOPE int lt_dlinsertsearchdir LT_PARAMS((const char *before, | 141 | LT_SCOPE int lt_dlinsertsearchdir LT_PARAMS ((const char *before, |
162 | const char *search_dir)); | 142 | const char *search_dir)); |
163 | LT_SCOPE int lt_dlsetsearchpath LT_PARAMS((const char *search_path)); | 143 | LT_SCOPE int lt_dlsetsearchpath LT_PARAMS ((const char *search_path)); |
164 | LT_SCOPE const char *lt_dlgetsearchpath LT_PARAMS((void)); | 144 | LT_SCOPE const char *lt_dlgetsearchpath LT_PARAMS ((void)); |
165 | LT_SCOPE int lt_dlforeachfile LT_PARAMS(( | 145 | LT_SCOPE int lt_dlforeachfile LT_PARAMS ((const char *search_path, |
166 | const char *search_path, | 146 | int (*func) (const char *filename, |
167 | int (*func) (const char *filename, lt_ptr data), | 147 | lt_ptr data), |
168 | lt_ptr data)); | 148 | lt_ptr data)); |
169 | 149 | ||
170 | /* Portable libltdl versions of the system dlopen() API. */ | 150 | /* Portable libltdl versions of the system dlopen() API. */ |
171 | LT_SCOPE lt_dlhandle lt_dlopen LT_PARAMS((const char *filename)); | 151 | LT_SCOPE lt_dlhandle lt_dlopen LT_PARAMS ((const char *filename)); |
172 | LT_SCOPE lt_dlhandle lt_dlopenext LT_PARAMS((const char *filename)); | 152 | LT_SCOPE lt_dlhandle lt_dlopenext LT_PARAMS ((const char *filename)); |
173 | LT_SCOPE lt_ptr lt_dlsym LT_PARAMS((lt_dlhandle handle, | 153 | LT_SCOPE lt_ptr lt_dlsym LT_PARAMS ((lt_dlhandle handle, const char *name)); |
174 | const char *name)); | 154 | LT_SCOPE const char *lt_dlerror LT_PARAMS ((void)); |
175 | LT_SCOPE const char *lt_dlerror LT_PARAMS((void)); | 155 | LT_SCOPE int lt_dlclose LT_PARAMS ((lt_dlhandle handle)); |
176 | LT_SCOPE int lt_dlclose LT_PARAMS((lt_dlhandle handle)); | ||
177 | 156 | ||
178 | /* Module residency management. */ | 157 | /* Module residency management. */ |
179 | LT_SCOPE int lt_dlmakeresident LT_PARAMS((lt_dlhandle handle)); | 158 | LT_SCOPE int lt_dlmakeresident LT_PARAMS ((lt_dlhandle handle)); |
180 | LT_SCOPE int lt_dlisresident LT_PARAMS((lt_dlhandle handle)); | 159 | LT_SCOPE int lt_dlisresident LT_PARAMS ((lt_dlhandle handle)); |
160 | |||
181 | 161 | ||
182 | 162 | ||
183 | 163 | ||
184 | |||
185 | /* --- MUTEX LOCKING --- */ | 164 | /* --- MUTEX LOCKING --- */ |
186 | 165 | ||
187 | 166 | ||
188 | typedef void lt_dlmutex_lock LT_PARAMS((void)); | 167 | typedef void lt_dlmutex_lock LT_PARAMS ((void)); |
189 | typedef void lt_dlmutex_unlock LT_PARAMS((void)); | 168 | typedef void lt_dlmutex_unlock LT_PARAMS ((void)); |
190 | typedef void lt_dlmutex_seterror LT_PARAMS((const char *errmsg)); | 169 | typedef void lt_dlmutex_seterror LT_PARAMS ((const char *errmsg)); |
191 | typedef const char *lt_dlmutex_geterror LT_PARAMS((void)); | 170 | typedef const char *lt_dlmutex_geterror LT_PARAMS ((void)); |
192 | 171 | ||
193 | LT_SCOPE int lt_dlmutex_register LT_PARAMS((lt_dlmutex_lock *lock, | 172 | LT_SCOPE int lt_dlmutex_register LT_PARAMS ((lt_dlmutex_lock * lock, |
194 | lt_dlmutex_unlock *unlock, | 173 | lt_dlmutex_unlock * unlock, |
195 | lt_dlmutex_seterror *seterror, | 174 | lt_dlmutex_seterror * seterror, |
196 | lt_dlmutex_geterror *geterror)); | 175 | lt_dlmutex_geterror * geterror)); |
176 | |||
197 | 177 | ||
198 | 178 | ||
199 | 179 | ||
200 | |||
201 | /* --- MEMORY HANDLING --- */ | 180 | /* --- MEMORY HANDLING --- */ |
202 | 181 | ||
203 | 182 | ||
@@ -206,103 +185,109 @@ LT_SCOPE int lt_dlmutex_register LT_PARAMS((lt_dlmutex_lock *lock, | |||
206 | libltdl relies on a featureful realloc, but if you are sure yours | 185 | libltdl relies on a featureful realloc, but if you are sure yours |
207 | has the right semantics then you can assign it directly. Generally, | 186 | has the right semantics then you can assign it directly. Generally, |
208 | it is safe to assign just a malloc() and a free() function. */ | 187 | it is safe to assign just a malloc() and a free() function. */ |
209 | LT_SCOPE lt_ptr (*lt_dlmalloc) LT_PARAMS((size_t size)); | 188 | LT_SCOPE |
210 | LT_SCOPE lt_ptr (*lt_dlrealloc) LT_PARAMS((lt_ptr ptr, size_t size)); | 189 | lt_ptr (*lt_dlmalloc) |
211 | LT_SCOPE void (*lt_dlfree) LT_PARAMS((lt_ptr ptr)); | 190 | LT_PARAMS ((size_t size)); |
191 | LT_SCOPE lt_ptr (*lt_dlrealloc) LT_PARAMS ((lt_ptr ptr, size_t size)); | ||
192 | LT_SCOPE void (*lt_dlfree) LT_PARAMS ((lt_ptr ptr)); | ||
193 | |||
212 | 194 | ||
213 | 195 | ||
214 | 196 | ||
215 | |||
216 | /* --- PRELOADED MODULE SUPPORT --- */ | 197 | /* --- PRELOADED MODULE SUPPORT --- */ |
217 | 198 | ||
218 | 199 | ||
219 | /* A preopened symbol. Arrays of this type comprise the exported | 200 | /* A preopened symbol. Arrays of this type comprise the exported |
220 | symbols for a dlpreopened module. */ | 201 | symbols for a dlpreopened module. */ |
221 | typedef struct { | 202 | typedef struct |
222 | const char *name; | 203 | { |
223 | lt_ptr address; | 204 | const char *name; |
224 | } lt_dlsymlist; | 205 | lt_ptr address; |
206 | } lt_dlsymlist; | ||
225 | 207 | ||
226 | LT_SCOPE int lt_dlpreload LT_PARAMS((const lt_dlsymlist *preloaded)); | 208 | LT_SCOPE int lt_dlpreload LT_PARAMS ((const lt_dlsymlist * preloaded)); |
227 | LT_SCOPE int lt_dlpreload_default | 209 | LT_SCOPE int lt_dlpreload_default |
228 | LT_PARAMS((const lt_dlsymlist *preloaded)); | 210 | LT_PARAMS ((const lt_dlsymlist * preloaded)); |
229 | 211 | ||
230 | #define LTDL_SET_PRELOADED_SYMBOLS() LT_STMT_START{ \ | 212 | #define LTDL_SET_PRELOADED_SYMBOLS() LT_STMT_START{ \ |
231 | extern const lt_dlsymlist lt_preloaded_symbols[]; \ | 213 | extern const lt_dlsymlist lt_preloaded_symbols[]; \ |
232 | lt_dlpreload_default(lt_preloaded_symbols); \ | 214 | lt_dlpreload_default(lt_preloaded_symbols); \ |
233 | }LT_STMT_END | 215 | }LT_STMT_END |
216 | |||
234 | 217 | ||
235 | 218 | ||
236 | 219 | ||
237 | |||
238 | /* --- MODULE INFORMATION --- */ | 220 | /* --- MODULE INFORMATION --- */ |
239 | 221 | ||
240 | 222 | ||
241 | /* Read only information pertaining to a loaded module. */ | 223 | /* Read only information pertaining to a loaded module. */ |
242 | typedef struct { | 224 | typedef struct |
243 | char *filename; /* file name */ | 225 | { |
244 | char *name; /* module name */ | 226 | char *filename; /* file name */ |
245 | int ref_count; /* number of times lt_dlopened minus | 227 | char *name; /* module name */ |
246 | number of times lt_dlclosed. */ | 228 | int ref_count; /* number of times lt_dlopened minus |
247 | } lt_dlinfo; | 229 | number of times lt_dlclosed. */ |
248 | 230 | } lt_dlinfo; | |
249 | LT_SCOPE const lt_dlinfo *lt_dlgetinfo LT_PARAMS((lt_dlhandle handle)); | 231 | |
250 | LT_SCOPE lt_dlhandle lt_dlhandle_next LT_PARAMS((lt_dlhandle place)); | 232 | LT_SCOPE const lt_dlinfo *lt_dlgetinfo LT_PARAMS ((lt_dlhandle handle)); |
251 | LT_SCOPE int lt_dlforeach LT_PARAMS(( | 233 | LT_SCOPE lt_dlhandle lt_dlhandle_next LT_PARAMS ((lt_dlhandle place)); |
252 | int (*func) (lt_dlhandle handle, lt_ptr data), | 234 | LT_SCOPE int lt_dlforeach |
253 | lt_ptr data)); | 235 | LT_PARAMS ((int (*func) (lt_dlhandle handle, lt_ptr data), |
236 | lt_ptr data)); | ||
254 | 237 | ||
255 | /* Associating user data with loaded modules. */ | 238 | /* Associating user data with loaded modules. */ |
256 | typedef unsigned lt_dlcaller_id; | 239 | typedef unsigned lt_dlcaller_id; |
257 | 240 | ||
258 | LT_SCOPE lt_dlcaller_id lt_dlcaller_register LT_PARAMS((void)); | 241 | LT_SCOPE lt_dlcaller_id lt_dlcaller_register LT_PARAMS ((void)); |
259 | LT_SCOPE lt_ptr lt_dlcaller_set_data LT_PARAMS((lt_dlcaller_id key, | 242 | LT_SCOPE lt_ptr lt_dlcaller_set_data LT_PARAMS ((lt_dlcaller_id key, |
260 | lt_dlhandle handle, | 243 | lt_dlhandle handle, |
261 | lt_ptr data)); | 244 | lt_ptr data)); |
262 | LT_SCOPE lt_ptr lt_dlcaller_get_data LT_PARAMS((lt_dlcaller_id key, | 245 | LT_SCOPE lt_ptr lt_dlcaller_get_data LT_PARAMS ((lt_dlcaller_id key, |
263 | lt_dlhandle handle)); | 246 | lt_dlhandle handle)); |
247 | |||
264 | 248 | ||
265 | 249 | ||
266 | |||
267 | /* --- USER MODULE LOADER API --- */ | 250 | /* --- USER MODULE LOADER API --- */ |
268 | 251 | ||
269 | 252 | ||
270 | typedef struct lt_dlloader lt_dlloader; | 253 | typedef struct lt_dlloader lt_dlloader; |
271 | typedef lt_ptr lt_user_data; | 254 | typedef lt_ptr lt_user_data; |
272 | typedef lt_ptr lt_module; | 255 | typedef lt_ptr lt_module; |
273 | 256 | ||
274 | /* Function pointer types for creating user defined module loaders. */ | 257 | /* Function pointer types for creating user defined module loaders. */ |
275 | typedef lt_module lt_module_open LT_PARAMS((lt_user_data loader_data, | 258 | typedef lt_module lt_module_open LT_PARAMS ((lt_user_data loader_data, |
276 | const char *filename)); | 259 | const char *filename)); |
277 | typedef int lt_module_close LT_PARAMS((lt_user_data loader_data, | 260 | typedef int lt_module_close LT_PARAMS ((lt_user_data loader_data, |
278 | lt_module handle)); | 261 | lt_module handle)); |
279 | typedef lt_ptr lt_find_sym LT_PARAMS((lt_user_data loader_data, | 262 | typedef lt_ptr lt_find_sym LT_PARAMS ((lt_user_data loader_data, |
280 | lt_module handle, | 263 | lt_module handle, |
281 | const char *symbol)); | 264 | const char *symbol)); |
282 | typedef int lt_dlloader_exit LT_PARAMS((lt_user_data loader_data)); | 265 | typedef int lt_dlloader_exit LT_PARAMS ((lt_user_data loader_data)); |
283 | 266 | ||
284 | struct lt_user_dlloader { | 267 | struct lt_user_dlloader |
285 | const char *sym_prefix; | 268 | { |
286 | lt_module_open *module_open; | 269 | const char *sym_prefix; |
287 | lt_module_close *module_close; | 270 | lt_module_open *module_open; |
288 | lt_find_sym *find_sym; | 271 | lt_module_close *module_close; |
289 | lt_dlloader_exit *dlloader_exit; | 272 | lt_find_sym *find_sym; |
290 | lt_user_data dlloader_data; | 273 | lt_dlloader_exit *dlloader_exit; |
291 | }; | 274 | lt_user_data dlloader_data; |
292 | 275 | }; | |
293 | LT_SCOPE lt_dlloader *lt_dlloader_next LT_PARAMS((lt_dlloader *place)); | 276 | |
294 | LT_SCOPE lt_dlloader *lt_dlloader_find LT_PARAMS(( | 277 | LT_SCOPE lt_dlloader *lt_dlloader_next LT_PARAMS ((lt_dlloader * place)); |
295 | const char *loader_name)); | 278 | LT_SCOPE lt_dlloader *lt_dlloader_find |
296 | LT_SCOPE const char *lt_dlloader_name LT_PARAMS((lt_dlloader *place)); | 279 | LT_PARAMS ((const char *loader_name)); |
297 | LT_SCOPE lt_user_data *lt_dlloader_data LT_PARAMS((lt_dlloader *place)); | 280 | LT_SCOPE const char *lt_dlloader_name LT_PARAMS ((lt_dlloader * place)); |
298 | LT_SCOPE int lt_dlloader_add LT_PARAMS((lt_dlloader *place, | 281 | LT_SCOPE lt_user_data *lt_dlloader_data |
299 | const struct lt_user_dlloader *dlloader, | 282 | LT_PARAMS ((lt_dlloader * place)); |
300 | const char *loader_name)); | 283 | LT_SCOPE int lt_dlloader_add |
301 | LT_SCOPE int lt_dlloader_remove LT_PARAMS(( | 284 | LT_PARAMS ((lt_dlloader * place, |
302 | const char *loader_name)); | 285 | const struct lt_user_dlloader * dlloader, |
286 | const char *loader_name)); | ||
287 | LT_SCOPE int lt_dlloader_remove LT_PARAMS ((const char *loader_name)); | ||
288 | |||
303 | 289 | ||
304 | 290 | ||
305 | |||
306 | /* --- ERROR MESSAGE HANDLING --- */ | 291 | /* --- ERROR MESSAGE HANDLING --- */ |
307 | 292 | ||
308 | 293 | ||
@@ -332,21 +317,21 @@ LT_SCOPE int lt_dlloader_remove LT_PARAMS(( | |||
332 | LT_ERROR(INVALID_POSITION, "invalid search path insert position") | 317 | LT_ERROR(INVALID_POSITION, "invalid search path insert position") |
333 | 318 | ||
334 | /* Enumerate the symbolic error names. */ | 319 | /* Enumerate the symbolic error names. */ |
335 | enum { | 320 | enum |
321 | { | ||
336 | #define LT_ERROR(name, diagnostic) LT_CONC(LT_ERROR_, name), | 322 | #define LT_ERROR(name, diagnostic) LT_CONC(LT_ERROR_, name), |
337 | lt_dlerror_table | 323 | lt_dlerror_table |
338 | #undef LT_ERROR | 324 | #undef LT_ERROR |
339 | 325 | LT_ERROR_MAX | |
340 | LT_ERROR_MAX | 326 | }; |
341 | }; | ||
342 | 327 | ||
343 | /* These functions are only useful from inside custom module loaders. */ | 328 | /* These functions are only useful from inside custom module loaders. */ |
344 | LT_SCOPE int lt_dladderror LT_PARAMS((const char *diagnostic)); | 329 | LT_SCOPE int lt_dladderror LT_PARAMS ((const char *diagnostic)); |
345 | LT_SCOPE int lt_dlseterror LT_PARAMS((int errorcode)); | 330 | LT_SCOPE int lt_dlseterror LT_PARAMS ((int errorcode)); |
331 | |||
346 | 332 | ||
347 | 333 | ||
348 | 334 | ||
349 | |||
350 | /* --- SOURCE COMPATIBILITY WITH OLD LIBLTDL --- */ | 335 | /* --- SOURCE COMPATIBILITY WITH OLD LIBLTDL --- */ |
351 | 336 | ||
352 | 337 | ||
@@ -362,5 +347,4 @@ LT_SCOPE int lt_dlseterror LT_PARAMS((int errorcode)); | |||
362 | #endif | 347 | #endif |
363 | 348 | ||
364 | LT_END_C_DECLS | 349 | LT_END_C_DECLS |
365 | |||
366 | #endif /* !LTDL_H */ | 350 | #endif /* !LTDL_H */ |
diff --git a/src/common/helper.c b/src/common/helper.c index 4483f41e..73d794d4 100644 --- a/src/common/helper.c +++ b/src/common/helper.c | |||
@@ -43,76 +43,83 @@ | |||
43 | * and these headers are not really useful for us */ | 43 | * and these headers are not really useful for us */ |
44 | #endif | 44 | #endif |
45 | 45 | ||
46 | typedef struct { | 46 | typedef struct |
47 | struct SEMAPHORE * sem; | 47 | { |
48 | void * args; | 48 | struct SEMAPHORE *sem; |
49 | void *args; | ||
49 | PThreadMain func; | 50 | PThreadMain func; |
50 | int destroyed; | 51 | int destroyed; |
51 | void * rval; | 52 | void *rval; |
52 | } SaveCall; | 53 | } SaveCall; |
53 | 54 | ||
54 | typedef struct Plugin { | 55 | typedef struct Plugin |
55 | struct Plugin * next; | 56 | { |
56 | char * name; | 57 | struct Plugin *next; |
57 | void * library; | 58 | char *name; |
59 | void *library; | ||
58 | } Plugin; | 60 | } Plugin; |
59 | 61 | ||
60 | static GladeXML * mainXML; | 62 | static GladeXML *mainXML; |
61 | 63 | ||
62 | static char * gladeFile; | 64 | static char *gladeFile; |
63 | 65 | ||
64 | static GdkWindowState main_window_state; | 66 | static GdkWindowState main_window_state; |
65 | 67 | ||
66 | /** | 68 | /** |
67 | * the main thread | 69 | * the main thread |
68 | */ | 70 | */ |
69 | static struct PTHREAD * mainThread; | 71 | static struct PTHREAD *mainThread; |
70 | 72 | ||
71 | static SaveCall ** psc; | 73 | static SaveCall **psc; |
72 | 74 | ||
73 | static unsigned int pscCount; | 75 | static unsigned int pscCount; |
74 | 76 | ||
75 | static struct MUTEX * sclock; | 77 | static struct MUTEX *sclock; |
76 | 78 | ||
77 | static int saveCallsUp; | 79 | static int saveCallsUp; |
78 | 80 | ||
79 | static Plugin * plugin; | 81 | static Plugin *plugin; |
80 | 82 | ||
81 | static void * shutdown_function; | 83 | static void *shutdown_function; |
82 | 84 | ||
83 | static struct GE_Context * ectx; | 85 | static struct GE_Context *ectx; |
84 | 86 | ||
85 | static struct GC_Configuration * cfg; | 87 | static struct GC_Configuration *cfg; |
86 | 88 | ||
87 | static struct CronManager * cron; | 89 | static struct CronManager *cron; |
88 | 90 | ||
89 | struct CronManager * gnunet_gtk_get_cron() { | 91 | struct CronManager * |
92 | gnunet_gtk_get_cron () | ||
93 | { | ||
90 | return cron; | 94 | return cron; |
91 | } | 95 | } |
92 | 96 | ||
93 | static gboolean saveCallWrapper(gpointer data) { | 97 | static gboolean |
94 | SaveCall * call = data; | 98 | saveCallWrapper (gpointer data) |
99 | { | ||
100 | SaveCall *call = data; | ||
95 | int i; | 101 | int i; |
96 | 102 | ||
97 | /* clearly, we are no longer pending, | 103 | /* clearly, we are no longer pending, |
98 | so remove from psc */ | 104 | so remove from psc */ |
99 | if (call->sem != NULL) { | 105 | if (call->sem != NULL) |
100 | MUTEX_LOCK(sclock); | 106 | { |
101 | for (i=0;i<pscCount;i++) { | 107 | MUTEX_LOCK (sclock); |
102 | if (psc[i] == call) { | 108 | for (i = 0; i < pscCount; i++) |
103 | psc[i] = psc[pscCount-1]; | 109 | { |
104 | break; | 110 | if (psc[i] == call) |
105 | } | 111 | { |
112 | psc[i] = psc[pscCount - 1]; | ||
113 | break; | ||
114 | } | ||
115 | } | ||
116 | GE_ASSERT (NULL, i != pscCount); | ||
117 | GROW (psc, pscCount, pscCount - 1); | ||
118 | MUTEX_UNLOCK (sclock); | ||
106 | } | 119 | } |
107 | GE_ASSERT(NULL, i != pscCount); | 120 | call->rval = call->func (call->args); |
108 | GROW(psc, | ||
109 | pscCount, | ||
110 | pscCount-1); | ||
111 | MUTEX_UNLOCK(sclock); | ||
112 | } | ||
113 | call->rval = call->func(call->args); | ||
114 | if (call->sem != NULL) | 121 | if (call->sem != NULL) |
115 | SEMAPHORE_UP(call->sem); | 122 | SEMAPHORE_UP (call->sem); |
116 | return FALSE; | 123 | return FALSE; |
117 | } | 124 | } |
118 | 125 | ||
@@ -121,318 +128,330 @@ static gboolean saveCallWrapper(gpointer data) { | |||
121 | * Since GTK doesn't work with multi-threaded applications under Windows, | 128 | * Since GTK doesn't work with multi-threaded applications under Windows, |
122 | * all GTK operations have to be done in the main thread | 129 | * all GTK operations have to be done in the main thread |
123 | */ | 130 | */ |
124 | void * gtkSaveCall(PThreadMain func, | 131 | void * |
125 | void * args) { | 132 | gtkSaveCall (PThreadMain func, void *args) |
133 | { | ||
126 | SaveCall call; | 134 | SaveCall call; |
127 | 135 | ||
128 | MUTEX_LOCK(sclock); | 136 | MUTEX_LOCK (sclock); |
129 | if ( (saveCallsUp == NO) || | 137 | if ((saveCallsUp == NO) || (!PTHREAD_TEST_SELF (mainThread))) |
130 | (! PTHREAD_TEST_SELF(mainThread)) ) { | 138 | { |
131 | call.args = args; | 139 | call.args = args; |
132 | call.func = func; | 140 | call.func = func; |
133 | call.sem = SEMAPHORE_CREATE(0); | 141 | call.sem = SEMAPHORE_CREATE (0); |
134 | call.destroyed = 0; | 142 | call.destroyed = 0; |
135 | call.rval = NULL; | 143 | call.rval = NULL; |
136 | GROW(psc, | 144 | GROW (psc, pscCount, pscCount + 1); |
137 | pscCount, | 145 | psc[pscCount - 1] = &call; |
138 | pscCount+1); | 146 | gtk_idle_add (&saveCallWrapper, &call); |
139 | psc[pscCount-1] = &call; | 147 | MUTEX_UNLOCK (sclock); |
140 | gtk_idle_add(&saveCallWrapper, | 148 | PTHREAD_STOP_SLEEP (mainThread); |
141 | &call); | 149 | SEMAPHORE_DOWN (call.sem, YES); |
142 | MUTEX_UNLOCK(sclock); | 150 | SEMAPHORE_DESTROY (call.sem); |
143 | PTHREAD_STOP_SLEEP(mainThread); | 151 | return call.rval; |
144 | SEMAPHORE_DOWN(call.sem, YES); | 152 | } |
145 | SEMAPHORE_DESTROY(call.sem); | 153 | else |
146 | return call.rval; | 154 | { |
147 | } else { | 155 | MUTEX_UNLOCK (sclock); |
148 | MUTEX_UNLOCK(sclock); | 156 | return func (args); |
149 | return func(args); | 157 | } |
150 | } | ||
151 | } | 158 | } |
152 | 159 | ||
153 | /** | 160 | /** |
154 | * Simple accessor method. | 161 | * Simple accessor method. |
155 | */ | 162 | */ |
156 | const char * getGladeFileName() { | 163 | const char * |
164 | getGladeFileName () | ||
165 | { | ||
157 | return gladeFile; | 166 | return gladeFile; |
158 | } | 167 | } |
159 | 168 | ||
160 | /** | 169 | /** |
161 | * Simple accessor method. | 170 | * Simple accessor method. |
162 | */ | 171 | */ |
163 | GladeXML * getMainXML() { | 172 | GladeXML * |
173 | getMainXML () | ||
174 | { | ||
164 | return mainXML; | 175 | return mainXML; |
165 | } | 176 | } |
166 | 177 | ||
167 | static void connector(const gchar *handler_name, | 178 | static void |
168 | GObject *object, | 179 | connector (const gchar * handler_name, |
169 | const gchar *signal_name, | 180 | GObject * object, |
170 | const gchar *signal_data, | 181 | const gchar * signal_name, |
171 | GObject *connect_object, | 182 | const gchar * signal_data, |
172 | gboolean after, | 183 | GObject * connect_object, gboolean after, gpointer user_data) |
173 | gpointer user_data) { | 184 | { |
174 | GModule * module; | 185 | GModule *module; |
175 | GladeXML * xml = user_data; | 186 | GladeXML *xml = user_data; |
176 | Plugin * plug; | 187 | Plugin *plug; |
177 | void * method; | 188 | void *method; |
178 | 189 | ||
179 | plug = plugin; | 190 | plug = plugin; |
180 | method = NULL; | 191 | method = NULL; |
181 | while (plug != NULL) { | 192 | while (plug != NULL) |
182 | method = os_plugin_resolve_function(plug->library, | 193 | { |
183 | handler_name, | 194 | method = os_plugin_resolve_function (plug->library, handler_name, NO); |
184 | NO); | 195 | if (method != NULL) |
185 | if (method != NULL) | 196 | break; |
186 | break; | 197 | plug = plug->next; |
187 | plug = plug->next; | 198 | } |
188 | } | 199 | if (0 == strcmp (handler_name, "gnunet_gtk_main_quit")) |
189 | if (0 == strcmp(handler_name, | ||
190 | "gnunet_gtk_main_quit")) | ||
191 | method = shutdown_function; | 200 | method = shutdown_function; |
192 | if (method == NULL) { | 201 | if (method == NULL) |
193 | module = g_module_open(NULL, 0); | 202 | { |
194 | if ( (module == NULL) || | 203 | module = g_module_open (NULL, 0); |
195 | (TRUE != g_module_symbol(module, | 204 | if ((module == NULL) || |
196 | handler_name, | 205 | (TRUE != g_module_symbol (module, handler_name, &method))) |
197 | &method)) ) { | 206 | { |
198 | GE_LOG(ectx, | 207 | GE_LOG (ectx, |
199 | GE_WARNING | GE_DEVELOPER | GE_IMMEDIATE, | 208 | GE_WARNING | GE_DEVELOPER | GE_IMMEDIATE, |
200 | _("Failed to find handler for `%s'\n"), | 209 | _("Failed to find handler for `%s'\n"), handler_name); |
201 | handler_name); | 210 | g_module_close (module); |
202 | g_module_close(module); | 211 | return; |
203 | return; | 212 | } |
213 | g_module_close (module); | ||
204 | } | 214 | } |
205 | g_module_close(module); | 215 | glade_xml_signal_connect (xml, handler_name, (GCallback) method); |
206 | } | ||
207 | glade_xml_signal_connect(xml, | ||
208 | handler_name, | ||
209 | (GCallback) method); | ||
210 | } | 216 | } |
211 | 217 | ||
212 | void connectGladeWithPlugins(GladeXML * xml) { | 218 | void |
213 | glade_xml_signal_autoconnect_full(xml, | 219 | connectGladeWithPlugins (GladeXML * xml) |
214 | &connector, | 220 | { |
215 | xml); | 221 | glade_xml_signal_autoconnect_full (xml, &connector, xml); |
216 | } | 222 | } |
217 | 223 | ||
218 | typedef void (*InitCall)(struct GE_Context * ectx, | 224 | typedef void (*InitCall) (struct GE_Context * ectx, |
219 | struct GC_Configuration * cfg); | 225 | struct GC_Configuration * cfg); |
220 | 226 | ||
221 | typedef void (*PlainCall)(void); | 227 | typedef void (*PlainCall) (void); |
222 | 228 | ||
223 | static void loadPlugin(const char * name) { | 229 | static void |
224 | Plugin * p; | 230 | loadPlugin (const char *name) |
225 | struct PluginHandle * lib; | 231 | { |
232 | Plugin *p; | ||
233 | struct PluginHandle *lib; | ||
226 | InitCall init; | 234 | InitCall init; |
227 | 235 | ||
228 | lib = os_plugin_load(ectx, | 236 | lib = os_plugin_load (ectx, "libgnunetgtkmodule_", name); |
229 | "libgnunetgtkmodule_", | ||
230 | name); | ||
231 | if (lib == NULL) | 237 | if (lib == NULL) |
232 | return; | 238 | return; |
233 | p = MALLOC(sizeof(Plugin)); | 239 | p = MALLOC (sizeof (Plugin)); |
234 | p->name = STRDUP(name); | 240 | p->name = STRDUP (name); |
235 | p->next = plugin; | 241 | p->next = plugin; |
236 | p->library = lib; | 242 | p->library = lib; |
237 | plugin = p; | 243 | plugin = p; |
238 | init = os_plugin_resolve_function(lib, | 244 | init = os_plugin_resolve_function (lib, "init_", NO); |
239 | "init_", | ||
240 | NO); | ||
241 | if (init != NULL) | 245 | if (init != NULL) |
242 | init(ectx, cfg); | 246 | init (ectx, cfg); |
243 | } | 247 | } |
244 | 248 | ||
245 | static void loadPlugins(const char * names) { | 249 | static void |
246 | char * dup; | 250 | loadPlugins (const char *names) |
247 | char * next; | 251 | { |
248 | const char * pos; | 252 | char *dup; |
253 | char *next; | ||
254 | const char *pos; | ||
249 | 255 | ||
250 | if (names == NULL) | 256 | if (names == NULL) |
251 | return; | 257 | return; |
252 | 258 | ||
253 | dup = STRDUP(names); | 259 | dup = STRDUP (names); |
254 | next = dup; | 260 | next = dup; |
255 | do { | 261 | do |
256 | while (*next == ' ') | 262 | { |
257 | next++; | 263 | while (*next == ' ') |
258 | pos = next; | 264 | next++; |
259 | while ( (*next != '\0') && | 265 | pos = next; |
260 | (*next != ' ') ) | 266 | while ((*next != '\0') && (*next != ' ')) |
261 | next++; | 267 | next++; |
262 | if (*next == '\0') { | 268 | if (*next == '\0') |
263 | next = NULL; /* terminate! */ | 269 | { |
264 | } else { | 270 | next = NULL; /* terminate! */ |
265 | *next = '\0'; /* add 0-termination for pos */ | 271 | } |
266 | next++; | 272 | else |
273 | { | ||
274 | *next = '\0'; /* add 0-termination for pos */ | ||
275 | next++; | ||
276 | } | ||
277 | if (strlen (pos) > 0) | ||
278 | loadPlugin (pos); | ||
267 | } | 279 | } |
268 | if (strlen(pos) > 0) | 280 | while (next != NULL); |
269 | loadPlugin(pos); | 281 | FREE (dup); |
270 | } while (next != NULL); | ||
271 | FREE(dup); | ||
272 | } | 282 | } |
273 | 283 | ||
274 | static void *unloadPlugin(void *p) { | 284 | static void * |
285 | unloadPlugin (void *p) | ||
286 | { | ||
275 | PlainCall done; | 287 | PlainCall done; |
276 | Plugin * plug = (Plugin *) p; | 288 | Plugin *plug = (Plugin *) p; |
277 | 289 | ||
278 | done = os_plugin_resolve_function(plug->library, | 290 | done = os_plugin_resolve_function (plug->library, "done_", NO); |
279 | "done_", | ||
280 | NO); | ||
281 | if (done != NULL) | 291 | if (done != NULL) |
282 | done(); | 292 | done (); |
283 | os_plugin_unload(plug->library); | 293 | os_plugin_unload (plug->library); |
284 | FREE(plug->name); | 294 | FREE (plug->name); |
285 | FREE(plug); | 295 | FREE (plug); |
286 | 296 | ||
287 | return NULL; | 297 | return NULL; |
288 | } | 298 | } |
289 | 299 | ||
290 | void initGNUnetGTKCommon(struct GE_Context * e, | 300 | void |
291 | struct GC_Configuration * c, | 301 | initGNUnetGTKCommon (struct GE_Context *e, |
292 | void * callback) { | 302 | struct GC_Configuration *c, void *callback) |
293 | char * load; | 303 | { |
294 | char * path; | 304 | char *load; |
295 | char * filename; | 305 | char *path; |
306 | char *filename; | ||
296 | 307 | ||
297 | ectx = e; | 308 | ectx = e; |
298 | cfg = c; | 309 | cfg = c; |
299 | shutdown_function = callback; | 310 | shutdown_function = callback; |
300 | sclock = MUTEX_CREATE(YES); | 311 | sclock = MUTEX_CREATE (YES); |
301 | mainThread = PTHREAD_GET_SELF(); | 312 | mainThread = PTHREAD_GET_SELF (); |
302 | saveCallsUp = YES; | 313 | saveCallsUp = YES; |
303 | cron = cron_create(ectx); | 314 | cron = cron_create (ectx); |
304 | 315 | ||
305 | /* load the interface */ | 316 | /* load the interface */ |
306 | path = os_get_installation_path(IPK_DATADIR); | 317 | path = os_get_installation_path (IPK_DATADIR); |
307 | filename = MALLOC(strlen(path) + strlen("/../gnunet-gtk/gnunet-gtk.glade") + 2); | 318 | filename = |
308 | strcpy(filename, path); | 319 | MALLOC (strlen (path) + strlen ("/../gnunet-gtk/gnunet-gtk.glade") + 2); |
309 | FREE(path); | 320 | strcpy (filename, path); |
310 | strcat(filename, "/../gnunet-gtk/gnunet-gtk.glade"); | 321 | FREE (path); |
322 | strcat (filename, "/../gnunet-gtk/gnunet-gtk.glade"); | ||
311 | #if MINGW | 323 | #if MINGW |
312 | gladeFile = MALLOC(_MAX_PATH + 1); | 324 | gladeFile = MALLOC (_MAX_PATH + 1); |
313 | plibc_conv_to_win_path(filename, | 325 | plibc_conv_to_win_path (filename, gladeFile); |
314 | gladeFile); | ||
315 | #else | 326 | #else |
316 | gladeFile = STRDUP(filename); | 327 | gladeFile = STRDUP (filename); |
317 | #endif | 328 | #endif |
318 | FREE(filename); | 329 | FREE (filename); |
319 | 330 | ||
320 | mainXML = glade_xml_new(gladeFile, | 331 | mainXML = glade_xml_new (gladeFile, "mainWindow", PACKAGE_NAME); |
321 | "mainWindow", | ||
322 | PACKAGE_NAME); | ||
323 | if (mainXML == NULL) | 332 | if (mainXML == NULL) |
324 | GE_DIE_STRERROR_FILE(ectx, | 333 | GE_DIE_STRERROR_FILE (ectx, |
325 | GE_FATAL | GE_USER | GE_IMMEDIATE, | 334 | GE_FATAL | GE_USER | GE_IMMEDIATE, |
326 | "glade_xml_new", | 335 | "glade_xml_new", gladeFile); |
327 | gladeFile); | ||
328 | /* load the plugins */ | 336 | /* load the plugins */ |
329 | GC_get_configuration_value_string(cfg, | 337 | GC_get_configuration_value_string (cfg, |
330 | "GNUNET-GTK", | 338 | "GNUNET-GTK", |
331 | "PLUGINS", | 339 | "PLUGINS", |
332 | "about daemon fs stats", | 340 | "about daemon fs stats", &load); |
333 | &load); | 341 | loadPlugins (load); |
334 | loadPlugins(load); | 342 | FREE (load); |
335 | FREE(load); | 343 | connectGladeWithPlugins (mainXML); |
336 | connectGladeWithPlugins(mainXML); | 344 | cron_start (cron); |
337 | cron_start(cron); | ||
338 | } | 345 | } |
339 | 346 | ||
340 | void shutdownPlugins() { | 347 | void |
348 | shutdownPlugins () | ||
349 | { | ||
341 | int i; | 350 | int i; |
342 | 351 | ||
343 | cron_stop(cron); | 352 | cron_stop (cron); |
344 | /* unload the plugins */ | 353 | /* unload the plugins */ |
345 | while (plugin != NULL) { | 354 | while (plugin != NULL) |
346 | Plugin * next; | 355 | { |
347 | 356 | Plugin *next; | |
348 | next = plugin->next; | 357 | |
349 | unloadPlugin(plugin); | 358 | next = plugin->next; |
350 | plugin = next; | 359 | unloadPlugin (plugin); |
351 | } | 360 | plugin = next; |
352 | UNREF(mainXML); | 361 | } |
362 | UNREF (mainXML); | ||
353 | mainXML = NULL; | 363 | mainXML = NULL; |
354 | FREE(gladeFile); | 364 | FREE (gladeFile); |
355 | gladeFile = NULL; | 365 | gladeFile = NULL; |
356 | 366 | ||
357 | saveCallsUp = NO; | 367 | saveCallsUp = NO; |
358 | MUTEX_LOCK(sclock); | 368 | MUTEX_LOCK (sclock); |
359 | for (i=0;i<pscCount;i++) | 369 | for (i = 0; i < pscCount; i++) |
360 | psc[i]->func(psc[i]); | 370 | psc[i]->func (psc[i]); |
361 | i = pscCount; | 371 | i = pscCount; |
362 | MUTEX_UNLOCK(sclock); | 372 | MUTEX_UNLOCK (sclock); |
363 | /* wait until all PSC-jobs have left | 373 | /* wait until all PSC-jobs have left |
364 | the gtkSaveCall method before destroying | 374 | the gtkSaveCall method before destroying |
365 | the mutex! */ | 375 | the mutex! */ |
366 | while (i != 0) { | 376 | while (i != 0) |
367 | PTHREAD_SLEEP(50 * cronMILLIS); | 377 | { |
368 | MUTEX_LOCK(sclock); | 378 | PTHREAD_SLEEP (50 * cronMILLIS); |
369 | i = pscCount; | 379 | MUTEX_LOCK (sclock); |
370 | MUTEX_UNLOCK(sclock); | 380 | i = pscCount; |
371 | } | 381 | MUTEX_UNLOCK (sclock); |
382 | } | ||
372 | } | 383 | } |
373 | 384 | ||
374 | void doneGNUnetGTKCommon() { | 385 | void |
375 | cron_destroy(cron); | 386 | doneGNUnetGTKCommon () |
376 | PTHREAD_REL_SELF(mainThread); | 387 | { |
377 | MUTEX_DESTROY(sclock); | 388 | cron_destroy (cron); |
389 | PTHREAD_REL_SELF (mainThread); | ||
390 | MUTEX_DESTROY (sclock); | ||
378 | } | 391 | } |
379 | 392 | ||
380 | struct rwsc_closure { | 393 | struct rwsc_closure |
381 | struct SEMAPHORE * sig; | 394 | { |
395 | struct SEMAPHORE *sig; | ||
382 | PThreadMain realMain; | 396 | PThreadMain realMain; |
383 | void * arg; | 397 | void *arg; |
384 | }; | 398 | }; |
385 | 399 | ||
386 | static void * shutdownCode(void * arg) { | 400 | static void * |
387 | struct rwsc_closure * cls = arg; | 401 | shutdownCode (void *arg) |
388 | void * ret; | 402 | { |
403 | struct rwsc_closure *cls = arg; | ||
404 | void *ret; | ||
389 | 405 | ||
390 | ret = cls->realMain(cls->arg); | 406 | ret = cls->realMain (cls->arg); |
391 | SEMAPHORE_UP(cls->sig); | 407 | SEMAPHORE_UP (cls->sig); |
392 | PTHREAD_STOP_SLEEP(mainThread); | 408 | PTHREAD_STOP_SLEEP (mainThread); |
393 | return ret; | 409 | return ret; |
394 | } | 410 | } |
395 | 411 | ||
396 | void * run_with_save_calls(PThreadMain cb, | 412 | void * |
397 | void * arg) { | 413 | run_with_save_calls (PThreadMain cb, void *arg) |
398 | struct PTHREAD * doneThread; | 414 | { |
399 | void * retval; | 415 | struct PTHREAD *doneThread; |
416 | void *retval; | ||
400 | struct rwsc_closure cls; | 417 | struct rwsc_closure cls; |
401 | int i; | 418 | int i; |
402 | 419 | ||
403 | cls.sig = SEMAPHORE_CREATE(0); | 420 | cls.sig = SEMAPHORE_CREATE (0); |
404 | cls.realMain = cb; | 421 | cls.realMain = cb; |
405 | cls.arg = arg; | 422 | cls.arg = arg; |
406 | doneThread = PTHREAD_CREATE(&shutdownCode, | 423 | doneThread = PTHREAD_CREATE (&shutdownCode, &cls, 64 * 1024); |
407 | &cls, | ||
408 | 64*1024); | ||
409 | if (doneThread == NULL) | 424 | if (doneThread == NULL) |
410 | GE_DIE_STRERROR(ectx, | 425 | GE_DIE_STRERROR (ectx, GE_FATAL | GE_ADMIN | GE_BULK, "pthread_create"); |
411 | GE_FATAL | GE_ADMIN | GE_BULK, | 426 | if (!PTHREAD_TEST_SELF (mainThread)) |
412 | "pthread_create"); | 427 | { |
413 | if (! PTHREAD_TEST_SELF(mainThread)) { | 428 | /* another thread will run the save calls */ |
414 | /* another thread will run the save calls */ | 429 | SEMAPHORE_DOWN (cls.sig, YES); |
415 | SEMAPHORE_DOWN(cls.sig, YES); | 430 | } |
416 | } else { | 431 | else |
417 | while (SYSERR == SEMAPHORE_DOWN(cls.sig, NO)) { | 432 | { |
418 | MUTEX_LOCK(sclock); | 433 | while (SYSERR == SEMAPHORE_DOWN (cls.sig, NO)) |
419 | if (pscCount > 0) { | 434 | { |
420 | i = weak_randomi(pscCount); | 435 | MUTEX_LOCK (sclock); |
421 | if (TRUE == g_idle_remove_by_data(psc[i])) | 436 | if (pscCount > 0) |
422 | saveCallWrapper(psc[i]); | 437 | { |
423 | } else { | 438 | i = weak_randomi (pscCount); |
424 | i = -1; | 439 | if (TRUE == g_idle_remove_by_data (psc[i])) |
425 | } | 440 | saveCallWrapper (psc[i]); |
426 | MUTEX_UNLOCK(sclock); | 441 | } |
427 | if ( (i == -1) && | 442 | else |
428 | (OK != SEMAPHORE_DOWN(cls.sig, NO)) ) { | 443 | { |
429 | PTHREAD_SLEEP(50 * cronMILLIS); | 444 | i = -1; |
430 | } | 445 | } |
446 | MUTEX_UNLOCK (sclock); | ||
447 | if ((i == -1) && (OK != SEMAPHORE_DOWN (cls.sig, NO))) | ||
448 | { | ||
449 | PTHREAD_SLEEP (50 * cronMILLIS); | ||
450 | } | ||
451 | } | ||
431 | } | 452 | } |
432 | } | 453 | PTHREAD_JOIN (doneThread, &retval); |
433 | PTHREAD_JOIN(doneThread, | 454 | SEMAPHORE_DESTROY (cls.sig); |
434 | &retval); | ||
435 | SEMAPHORE_DESTROY(cls.sig); | ||
436 | return retval; | 455 | return retval; |
437 | } | 456 | } |
438 | 457 | ||
@@ -440,62 +459,67 @@ void * run_with_save_calls(PThreadMain cb, | |||
440 | * Simple glue to libnotify, and others? | 459 | * Simple glue to libnotify, and others? |
441 | * | 460 | * |
442 | */ | 461 | */ |
443 | void gnunetgtk_notify(int type, | 462 | void |
444 | const char *message, | 463 | gnunetgtk_notify (int type, const char *message, ...) |
445 | ...) { | 464 | { |
446 | #ifdef WITH_LIBNOTIFY | 465 | #ifdef WITH_LIBNOTIFY |
447 | static int once; | 466 | static int once; |
448 | char * msg; | 467 | char *msg; |
449 | size_t size; | 468 | size_t size; |
450 | va_list arg; | 469 | va_list arg; |
451 | GtkWidget * root; | 470 | GtkWidget *root; |
452 | NotifyNotification *libnotify; | 471 | NotifyNotification *libnotify; |
453 | NotifyUrgency libnotify_urgency = NOTIFY_URGENCY_NORMAL; | 472 | NotifyUrgency libnotify_urgency = NOTIFY_URGENCY_NORMAL; |
454 | long libnotify_expire_timeout = NOTIFY_EXPIRES_DEFAULT; | 473 | long libnotify_expire_timeout = NOTIFY_EXPIRES_DEFAULT; |
455 | 474 | ||
456 | if (! notify_is_initted()){ | 475 | if (!notify_is_initted ()) |
457 | if (once == 1) | 476 | { |
458 | return; | 477 | if (once == 1) |
459 | if (! notify_init ("gnunet-gtk")) { | 478 | return; |
460 | once = 1; | 479 | if (!notify_init ("gnunet-gtk")) |
461 | GE_LOG(ectx, | 480 | { |
462 | GE_WARNING | GE_BULK | GE_USER | GE_ADMIN, | 481 | once = 1; |
463 | _("Could not initialize libnotify\n")); | 482 | GE_LOG (ectx, |
464 | return; | 483 | GE_WARNING | GE_BULK | GE_USER | GE_ADMIN, |
484 | _("Could not initialize libnotify\n")); | ||
485 | return; | ||
486 | } | ||
465 | } | 487 | } |
466 | } | 488 | |
467 | 489 | root = glade_xml_get_widget (getMainXML (), "mainWindow"); | |
468 | root = glade_xml_get_widget(getMainXML(),"mainWindow"); | 490 | if (gtk_window_is_active (GTK_WINDOW (root)) == FALSE) |
469 | if (gtk_window_is_active(GTK_WINDOW(root)) == FALSE) { | 491 | { |
470 | if (type == NOTIFY_LOW) | 492 | if (type == NOTIFY_LOW) |
471 | libnotify_urgency = NOTIFY_URGENCY_LOW; | 493 | libnotify_urgency = NOTIFY_URGENCY_LOW; |
472 | else if( type == NOTIFY_NORMAL) | 494 | else if (type == NOTIFY_NORMAL) |
473 | libnotify_urgency = NOTIFY_URGENCY_NORMAL; | 495 | libnotify_urgency = NOTIFY_URGENCY_NORMAL; |
474 | else | 496 | else |
475 | libnotify_urgency = NOTIFY_URGENCY_CRITICAL; | 497 | libnotify_urgency = NOTIFY_URGENCY_CRITICAL; |
476 | va_start(arg, message); | 498 | va_start (arg, message); |
477 | size = vsnprintf(NULL, 0, message, arg); | 499 | size = vsnprintf (NULL, 0, message, arg); |
478 | va_end(arg); | 500 | va_end (arg); |
479 | msg = MALLOC(size+1); | 501 | msg = MALLOC (size + 1); |
480 | va_start(arg, message); | 502 | va_start (arg, message); |
481 | vsnprintf(msg, size, message, arg); | 503 | vsnprintf (msg, size, message, arg); |
482 | va_end(arg); | 504 | va_end (arg); |
483 | libnotify = notify_notification_new("gnunet-gtk", | 505 | libnotify = notify_notification_new ("gnunet-gtk", |
484 | msg, | 506 | msg, |
485 | PACKAGE_DATA "/gnunet-gtk/gnunet-gtk-notify.png", | 507 | PACKAGE_DATA |
486 | NULL); | 508 | "/gnunet-gtk/gnunet-gtk-notify.png", |
487 | FREE(msg); | 509 | NULL); |
488 | notify_notification_set_timeout(libnotify, libnotify_expire_timeout); | 510 | FREE (msg); |
489 | notify_notification_set_urgency(libnotify, libnotify_urgency); | 511 | notify_notification_set_timeout (libnotify, libnotify_expire_timeout); |
490 | if (! notify_notification_show (libnotify, NULL)) { | 512 | notify_notification_set_urgency (libnotify, libnotify_urgency); |
491 | once = 1; | 513 | if (!notify_notification_show (libnotify, NULL)) |
492 | GE_LOG(ectx, | 514 | { |
493 | GE_WARNING | GE_USER | GE_ADMIN | GE_BULK, | 515 | once = 1; |
494 | _("Could not send notification via libnotify\n")); | 516 | GE_LOG (ectx, |
517 | GE_WARNING | GE_USER | GE_ADMIN | GE_BULK, | ||
518 | _("Could not send notification via libnotify\n")); | ||
519 | } | ||
520 | g_object_unref (G_OBJECT (libnotify)); | ||
521 | notify_uninit (); | ||
495 | } | 522 | } |
496 | g_object_unref(G_OBJECT(libnotify)); | ||
497 | notify_uninit(); | ||
498 | } | ||
499 | #endif | 523 | #endif |
500 | } | 524 | } |
501 | 525 | ||
@@ -504,41 +528,35 @@ void gnunetgtk_notify(int type, | |||
504 | * If validation fails, msg is freed and a valid | 528 | * If validation fails, msg is freed and a valid |
505 | * Utf-8 string is returned. | 529 | * Utf-8 string is returned. |
506 | */ | 530 | */ |
507 | char * validate_utf8(char * msg) { | 531 | char * |
508 | const gchar * end; | 532 | validate_utf8 (char *msg) |
509 | char * ret; | 533 | { |
534 | const gchar *end; | ||
535 | char *ret; | ||
510 | gsize send; | 536 | gsize send; |
511 | 537 | ||
512 | end = NULL; | 538 | end = NULL; |
513 | if (TRUE == g_utf8_validate(msg, | 539 | if (TRUE == g_utf8_validate (msg, -1, &end)) |
514 | -1, | ||
515 | &end)) | ||
516 | return msg; | 540 | return msg; |
517 | /* hope that it is ISO8859-1 */ | 541 | /* hope that it is ISO8859-1 */ |
518 | ret = g_convert_with_fallback(msg, | 542 | ret = g_convert_with_fallback (msg, |
519 | -1, | 543 | -1, |
520 | "UTF-8", | 544 | "UTF-8", |
521 | "ISO8859-1", | 545 | "ISO8859-1", ".", NULL, &send, NULL); |
522 | ".", | 546 | FREE (msg); |
523 | NULL, | 547 | msg = STRDUP (ret); |
524 | &send, | 548 | g_free (ret); |
525 | NULL); | 549 | GE_BREAK (NULL, TRUE == g_utf8_validate (msg, -1, &end)); |
526 | FREE(msg); | ||
527 | msg = STRDUP(ret); | ||
528 | g_free(ret); | ||
529 | GE_BREAK(NULL, | ||
530 | TRUE == g_utf8_validate(msg, | ||
531 | -1, | ||
532 | &end)); | ||
533 | return msg; | 550 | return msg; |
534 | } | 551 | } |
535 | 552 | ||
536 | /** | 553 | /** |
537 | * Gtk callback to save the main window state (tray icon use) | 554 | * Gtk callback to save the main window state (tray icon use) |
538 | */ | 555 | */ |
539 | void saveMainWindowState(GtkWidget *main_window, | 556 | void |
540 | GdkEventWindowState *event, | 557 | saveMainWindowState (GtkWidget * main_window, |
541 | gpointer user_data) { | 558 | GdkEventWindowState * event, gpointer user_data) |
559 | { | ||
542 | main_window_state = (*event).new_window_state; | 560 | main_window_state = (*event).new_window_state; |
543 | return; | 561 | return; |
544 | } | 562 | } |
@@ -546,55 +564,70 @@ void saveMainWindowState(GtkWidget *main_window, | |||
546 | /** | 564 | /** |
547 | * Get the last main window state when restoring (tray icon use) | 565 | * Get the last main window state when restoring (tray icon use) |
548 | */ | 566 | */ |
549 | GdkWindowState getMainWindowState() { | 567 | GdkWindowState |
568 | getMainWindowState () | ||
569 | { | ||
550 | return main_window_state; | 570 | return main_window_state; |
551 | } | 571 | } |
552 | 572 | ||
553 | /** | 573 | /** |
554 | * Start gnunet-setup, asking for a password if needed | 574 | * Start gnunet-setup, asking for a password if needed |
555 | */ | 575 | */ |
556 | gboolean startGNUnetSetup (gboolean run_wizard) { | 576 | gboolean |
557 | GtkWidget * mainWindow; | 577 | startGNUnetSetup (gboolean run_wizard) |
558 | GtkWidget * messageDialog; | 578 | { |
579 | GtkWidget *mainWindow; | ||
580 | GtkWidget *messageDialog; | ||
559 | int code; | 581 | int code; |
560 | char *error_message; | 582 | char *error_message; |
561 | #ifdef WITH_LIBGKSU2 | 583 | #ifdef WITH_LIBGKSU2 |
562 | GError *gerror = NULL; | 584 | GError *gerror = NULL; |
563 | if(run_wizard) { | 585 | if (run_wizard) |
564 | code = gksu_run("gnunet-setup -d wizard-gtk", | 586 | { |
565 | &gerror); | 587 | code = gksu_run ("gnunet-setup -d wizard-gtk", &gerror); |
566 | } else { | 588 | } |
567 | code = gksu_run("gnunet-setup -d", | 589 | else |
568 | &gerror); | 590 | { |
569 | } | 591 | code = gksu_run ("gnunet-setup -d", &gerror); |
570 | if (code && !gerror) { | 592 | } |
571 | error_message = STRDUP(_("GKSu encountered an unknown error running the configuration tool (gnunet-setup).")); | 593 | if (code && !gerror) |
572 | } else if (code && gerror) { | 594 | { |
573 | error_message = g_strdup_printf(_("GKSu returned:\n%s"), | 595 | error_message = |
574 | gerror->message); | 596 | STRDUP (_ |
575 | g_error_free(gerror); | 597 | ("GKSu encountered an unknown error running the configuration tool (gnunet-setup).")); |
576 | } else { | 598 | } |
577 | error_message = NULL; | 599 | else if (code && gerror) |
578 | } | 600 | { |
601 | error_message = g_strdup_printf (_("GKSu returned:\n%s"), | ||
602 | gerror->message); | ||
603 | g_error_free (gerror); | ||
604 | } | ||
605 | else | ||
606 | { | ||
607 | error_message = NULL; | ||
608 | } | ||
579 | #elif defined(WINDOWS) | 609 | #elif defined(WINDOWS) |
580 | /* FIXME: run gnunet-setup, assuming we can get the needed rights */ | 610 | /* FIXME: run gnunet-setup, assuming we can get the needed rights */ |
581 | error_message = STRDUP(_("Not implemented yet!")); | 611 | error_message = STRDUP (_("Not implemented yet!")); |
582 | code = TRUE; | 612 | code = TRUE; |
583 | #else | 613 | #else |
584 | error_message = STRDUP(_("GKSu support is not enabled, impossible to get the needed rights. You should build gnunet-gtk with the --enable-libgksu2 option, or get the right binary package. Note you can still start the configuration tool (gnunet-setup) manually.")); | 614 | error_message = |
615 | STRDUP (_ | ||
616 | ("GKSu support is not enabled, impossible to get the needed rights. You should build gnunet-gtk with the --enable-libgksu2 option, or get the right binary package. Note you can still start the configuration tool (gnunet-setup) manually.")); | ||
585 | code = TRUE; | 617 | code = TRUE; |
586 | #endif | 618 | #endif |
587 | mainWindow = glade_xml_get_widget(getMainXML(), | 619 | mainWindow = glade_xml_get_widget (getMainXML (), "mainWindow"); |
588 | "mainWindow"); | 620 | messageDialog = gtk_message_dialog_new (GTK_WINDOW (mainWindow), |
589 | messageDialog = gtk_message_dialog_new(GTK_WINDOW(mainWindow), | 621 | GTK_DIALOG_MODAL | |
590 | GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, | 622 | GTK_DIALOG_DESTROY_WITH_PARENT, |
591 | GTK_MESSAGE_WARNING, | 623 | GTK_MESSAGE_WARNING, |
592 | GTK_BUTTONS_CLOSE, | 624 | GTK_BUTTONS_CLOSE, |
593 | _("Failed to run the configuration tool (gnunet-setup): %s"), | 625 | _ |
594 | error_message); | 626 | ("Failed to run the configuration tool (gnunet-setup): %s"), |
595 | gtk_dialog_run(GTK_DIALOG(messageDialog)); | 627 | error_message); |
596 | gtk_widget_destroy(messageDialog); | 628 | gtk_dialog_run (GTK_DIALOG (messageDialog)); |
597 | FREE(error_message); | 629 | gtk_widget_destroy (messageDialog); |
630 | FREE (error_message); | ||
598 | return code; | 631 | return code; |
599 | } | 632 | } |
600 | 633 | ||
diff --git a/src/common/iterators.c b/src/common/iterators.c index 920072b6..4d8d72b3 100644 --- a/src/common/iterators.c +++ b/src/common/iterators.c | |||
@@ -33,105 +33,84 @@ | |||
33 | * except that modifications of the underlying model | 33 | * except that modifications of the underlying model |
34 | * during the iteration are tolerated. | 34 | * during the iteration are tolerated. |
35 | */ | 35 | */ |
36 | void ggc_tree_selection_selected_foreach(GtkTreeSelection *selection, | 36 | void |
37 | GtkTreeSelectionForeachFunc func, | 37 | ggc_tree_selection_selected_foreach (GtkTreeSelection * selection, |
38 | gpointer data) { | 38 | GtkTreeSelectionForeachFunc func, |
39 | gpointer data) | ||
40 | { | ||
39 | unsigned int i; | 41 | unsigned int i; |
40 | unsigned int size; | 42 | unsigned int size; |
41 | GList * selected; | 43 | GList *selected; |
42 | GtkTreeRowReference ** refs; | 44 | GtkTreeRowReference **refs; |
43 | GtkTreeModel * model; | 45 | GtkTreeModel *model; |
44 | GtkTreePath * path; | 46 | GtkTreePath *path; |
45 | GtkTreeIter iter; | 47 | GtkTreeIter iter; |
46 | 48 | ||
47 | selected = gtk_tree_selection_get_selected_rows(selection, | 49 | selected = gtk_tree_selection_get_selected_rows (selection, &model); |
48 | &model); | ||
49 | 50 | ||
50 | i = g_list_length(selected); | 51 | i = g_list_length (selected); |
51 | size = 0; | 52 | size = 0; |
52 | refs = NULL; | 53 | refs = NULL; |
53 | GROW(refs, | 54 | GROW (refs, size, i); |
54 | size, | 55 | for (i = 0; i < size; i++) |
55 | i); | 56 | refs[i] = gtk_tree_row_reference_new (model, |
56 | for (i=0;i<size;i++) | 57 | g_list_nth_data (selected, i)); |
57 | refs[i] = gtk_tree_row_reference_new(model, | 58 | g_list_foreach (selected, (GFunc) & gtk_tree_path_free, NULL); |
58 | g_list_nth_data(selected, i)); | 59 | g_list_free (selected); |
59 | g_list_foreach(selected, | 60 | for (i = 0; i < size; i++) |
60 | (GFunc) >k_tree_path_free, | 61 | { |
61 | NULL); | 62 | path = gtk_tree_row_reference_get_path (refs[i]); |
62 | g_list_free(selected); | 63 | gtk_tree_row_reference_free (refs[i]); |
63 | for (i=0;i<size;i++) { | 64 | if (TRUE == gtk_tree_model_get_iter (model, &iter, path)) |
64 | path = gtk_tree_row_reference_get_path(refs[i]); | 65 | func (model, path, &iter, data); |
65 | gtk_tree_row_reference_free(refs[i]); | 66 | gtk_tree_path_free (path); |
66 | if (TRUE == gtk_tree_model_get_iter(model, | 67 | } |
67 | &iter, | 68 | GROW (refs, size, 0); |
68 | path)) | ||
69 | func(model, | ||
70 | path, | ||
71 | &iter, | ||
72 | data); | ||
73 | gtk_tree_path_free(path); | ||
74 | } | ||
75 | GROW(refs, | ||
76 | size, | ||
77 | 0); | ||
78 | } | 69 | } |
79 | 70 | ||
80 | typedef struct { | 71 | typedef struct |
81 | GtkTreeRowReference ** refs; | 72 | { |
73 | GtkTreeRowReference **refs; | ||
82 | unsigned int pos; | 74 | unsigned int pos; |
83 | unsigned int size; | 75 | unsigned int size; |
84 | } CollectData; | 76 | } CollectData; |
85 | 77 | ||
86 | static gboolean | 78 | static gboolean |
87 | collectAllRows(GtkTreeModel * model, | 79 | collectAllRows (GtkTreeModel * model, |
88 | GtkTreePath * path, | 80 | GtkTreePath * path, GtkTreeIter * iter, gpointer cls) |
89 | GtkTreeIter * iter, | 81 | { |
90 | gpointer cls) { | 82 | CollectData *cd = cls; |
91 | CollectData * cd = cls; | ||
92 | 83 | ||
93 | if (cd->size == cd->pos) | 84 | if (cd->size == cd->pos) |
94 | GROW(cd->refs, | 85 | GROW (cd->refs, cd->size, cd->size * 2 + 4); |
95 | cd->size, | 86 | cd->refs[cd->pos++] = gtk_tree_row_reference_new (model, path); |
96 | cd->size * 2 + 4); | ||
97 | cd->refs[cd->pos++] = gtk_tree_row_reference_new(model, | ||
98 | path); | ||
99 | return FALSE; | 87 | return FALSE; |
100 | } | 88 | } |
101 | 89 | ||
102 | 90 | ||
103 | /** | 91 | /** |
104 | * Identical to "gtk_tree_model_foreach", | 92 | * Identical to "gtk_tree_model_foreach", |
105 | * except that modifications of the underlying model | 93 | * except that modifications of the underlying model |
106 | * during the iteration are tolerated. | 94 | * during the iteration are tolerated. |
107 | */ | 95 | */ |
108 | void ggc_tree_model_foreach(GtkTreeModel * model, | 96 | void |
109 | GtkTreeSelectionForeachFunc func, | 97 | ggc_tree_model_foreach (GtkTreeModel * model, |
110 | gpointer data) { | 98 | GtkTreeSelectionForeachFunc func, gpointer data) |
99 | { | ||
111 | int i; | 100 | int i; |
112 | GtkTreePath * path; | 101 | GtkTreePath *path; |
113 | GtkTreeIter iter; | 102 | GtkTreeIter iter; |
114 | CollectData cd; | 103 | CollectData cd; |
115 | 104 | ||
116 | memset(&cd, | 105 | memset (&cd, 0, sizeof (CollectData)); |
117 | 0, | 106 | gtk_tree_model_foreach (model, &collectAllRows, &cd); |
118 | sizeof(CollectData)); | 107 | for (i = cd.pos - 1; i >= 0; i--) |
119 | gtk_tree_model_foreach(model, | 108 | { |
120 | &collectAllRows, | 109 | path = gtk_tree_row_reference_get_path (cd.refs[i]); |
121 | &cd); | 110 | gtk_tree_row_reference_free (cd.refs[i]); |
122 | for (i=cd.pos-1;i>=0;i--) { | 111 | if (TRUE == gtk_tree_model_get_iter (model, &iter, path)) |
123 | path = gtk_tree_row_reference_get_path(cd.refs[i]); | 112 | func (model, path, &iter, data); |
124 | gtk_tree_row_reference_free(cd.refs[i]); | 113 | gtk_tree_path_free (path); |
125 | if (TRUE == gtk_tree_model_get_iter(model, | 114 | } |
126 | &iter, | 115 | GROW (cd.refs, cd.size, 0); |
127 | path)) | ||
128 | func(model, | ||
129 | path, | ||
130 | &iter, | ||
131 | data); | ||
132 | gtk_tree_path_free(path); | ||
133 | } | ||
134 | GROW(cd.refs, | ||
135 | cd.size, | ||
136 | 0); | ||
137 | } | 116 | } |
diff --git a/src/common/logging.c b/src/common/logging.c index 426d6d69..93c6833c 100644 --- a/src/common/logging.c +++ b/src/common/logging.c | |||
@@ -30,52 +30,44 @@ | |||
30 | #include <glib.h> | 30 | #include <glib.h> |
31 | #include <gmodule.h> | 31 | #include <gmodule.h> |
32 | 32 | ||
33 | static GtkWidget * infoWindow; | 33 | static GtkWidget *infoWindow; |
34 | 34 | ||
35 | static GtkWidget * infoWindowTextView; | 35 | static GtkWidget *infoWindowTextView; |
36 | 36 | ||
37 | static GladeXML * statusXML; | 37 | static GladeXML *statusXML; |
38 | 38 | ||
39 | static void init() { | 39 | static void |
40 | GtkWidget * button; | 40 | init () |
41 | { | ||
42 | GtkWidget *button; | ||
41 | 43 | ||
42 | if (statusXML != NULL) | 44 | if (statusXML != NULL) |
43 | return; | 45 | return; |
44 | statusXML | 46 | statusXML |
45 | = glade_xml_new(getGladeFileName(), | 47 | = glade_xml_new (getGladeFileName (), "statusWindow", PACKAGE_NAME); |
46 | "statusWindow", | 48 | infoWindow = glade_xml_get_widget (statusXML, "statusWindow"); |
47 | PACKAGE_NAME); | ||
48 | infoWindow | ||
49 | = glade_xml_get_widget(statusXML, | ||
50 | "statusWindow"); | ||
51 | infoWindowTextView | 49 | infoWindowTextView |
52 | = glade_xml_get_widget(statusXML, | 50 | = glade_xml_get_widget (statusXML, "messageWindowTextView"); |
53 | "messageWindowTextView"); | 51 | button = glade_xml_get_widget (statusXML, "messageWindowCloseButton"); |
54 | button | 52 | connectGladeWithPlugins (statusXML); |
55 | = glade_xml_get_widget(statusXML, | 53 | |
56 | "messageWindowCloseButton"); | 54 | g_signal_connect_data (infoWindow, |
57 | connectGladeWithPlugins(statusXML); | 55 | "delete-event", |
58 | 56 | G_CALLBACK (>k_widget_hide_on_delete), | |
59 | g_signal_connect_data(infoWindow, | 57 | NULL, NULL, 0); |
60 | "delete-event", | 58 | g_signal_connect_data (button, |
61 | G_CALLBACK(>k_widget_hide_on_delete), | 59 | "clicked", |
62 | NULL, | 60 | G_CALLBACK (>k_widget_hide_on_delete), |
63 | NULL, | 61 | infoWindow, NULL, G_CONNECT_SWAPPED); |
64 | 0); | ||
65 | g_signal_connect_data(button, | ||
66 | "clicked", | ||
67 | G_CALLBACK(>k_widget_hide_on_delete), | ||
68 | infoWindow, | ||
69 | NULL, | ||
70 | G_CONNECT_SWAPPED); | ||
71 | } | 62 | } |
72 | 63 | ||
73 | /** | 64 | /** |
74 | * Closure for doInfoMessage. | 65 | * Closure for doInfoMessage. |
75 | */ | 66 | */ |
76 | typedef struct { | 67 | typedef struct |
68 | { | ||
77 | int doPopup; | 69 | int doPopup; |
78 | char * note; | 70 | char *note; |
79 | } InfoMessage; | 71 | } InfoMessage; |
80 | 72 | ||
81 | /** | 73 | /** |
@@ -86,27 +78,26 @@ typedef struct { | |||
86 | /** | 78 | /** |
87 | * Callback for infoMessage() | 79 | * Callback for infoMessage() |
88 | */ | 80 | */ |
89 | static void * doInfoMessage(void * args) { | 81 | static void * |
90 | const InfoMessage * info = args; | 82 | doInfoMessage (void *args) |
83 | { | ||
84 | const InfoMessage *info = args; | ||
91 | GtkTextIter iter; | 85 | GtkTextIter iter; |
92 | GtkTextBuffer * buffer; | 86 | GtkTextBuffer *buffer; |
93 | GtkTextIter end; | 87 | GtkTextIter end; |
94 | 88 | ||
95 | init(); | 89 | init (); |
96 | if (info->doPopup==YES) | 90 | if (info->doPopup == YES) |
97 | gtk_widget_show(infoWindow); | 91 | gtk_widget_show (infoWindow); |
98 | buffer | 92 | buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (infoWindowTextView)); |
99 | = gtk_text_view_get_buffer(GTK_TEXT_VIEW(infoWindowTextView)); | 93 | gtk_text_buffer_get_iter_at_offset (buffer, &iter, -1); |
100 | gtk_text_buffer_get_iter_at_offset(buffer, &iter, -1); | 94 | gtk_text_buffer_insert (buffer, &iter, info->note, -1); |
101 | gtk_text_buffer_insert(buffer, | 95 | if (gtk_text_buffer_get_line_count (buffer) >= MAX_LINES) |
102 | &iter, | 96 | { |
103 | info->note, | 97 | gtk_text_buffer_get_iter_at_line (buffer, &iter, MAX_LINES - 1); |
104 | -1); | 98 | gtk_text_buffer_get_iter_at_line (buffer, &end, MAX_LINES); |
105 | if (gtk_text_buffer_get_line_count(buffer) >= MAX_LINES) { | 99 | gtk_text_buffer_delete (buffer, &iter, &end); |
106 | gtk_text_buffer_get_iter_at_line(buffer, &iter, MAX_LINES-1); | 100 | } |
107 | gtk_text_buffer_get_iter_at_line(buffer, &end, MAX_LINES); | ||
108 | gtk_text_buffer_delete(buffer, &iter, &end); | ||
109 | } | ||
110 | return NULL; | 101 | return NULL; |
111 | } | 102 | } |
112 | 103 | ||
@@ -115,39 +106,37 @@ static void * doInfoMessage(void * args) { | |||
115 | * | 106 | * |
116 | * @param doPopup do we open the window, YES or NO | 107 | * @param doPopup do we open the window, YES or NO |
117 | */ | 108 | */ |
118 | void infoMessage(int doPopup, | 109 | void |
119 | const char * format, | 110 | infoMessage (int doPopup, const char *format, ...) |
120 | ...) { | 111 | { |
121 | va_list args; | 112 | va_list args; |
122 | InfoMessage info; | 113 | InfoMessage info; |
123 | 114 | ||
124 | va_start(args, format); | 115 | va_start (args, format); |
125 | info.note = g_strdup_vprintf(format, args); | 116 | info.note = g_strdup_vprintf (format, args); |
126 | va_end(args); | 117 | va_end (args); |
127 | info.doPopup = doPopup; | 118 | info.doPopup = doPopup; |
128 | gtkSaveCall(&doInfoMessage, | 119 | gtkSaveCall (&doInfoMessage, &info); |
129 | &info); | 120 | g_free (info.note); |
130 | g_free(info.note); | ||
131 | } | 121 | } |
132 | 122 | ||
133 | static void * saveAddLogEntry(void * args) { | 123 | static void * |
134 | static GtkWidget * s = NULL; | 124 | saveAddLogEntry (void *args) |
125 | { | ||
126 | static GtkWidget *s = NULL; | ||
135 | static int once = 1; | 127 | static int once = 1; |
136 | static guint id; | 128 | static guint id; |
137 | 129 | ||
138 | init(); | 130 | init (); |
139 | if (once) { | 131 | if (once) |
140 | once = 0; | 132 | { |
141 | s = glade_xml_get_widget(getMainXML(), | 133 | once = 0; |
142 | "statusbar"); | 134 | s = glade_xml_get_widget (getMainXML (), "statusbar"); |
143 | id = gtk_statusbar_get_context_id(GTK_STATUSBAR(s), | 135 | id = gtk_statusbar_get_context_id (GTK_STATUSBAR (s), "LOG"); |
144 | "LOG"); | 136 | } |
145 | } else | 137 | else |
146 | gtk_statusbar_pop(GTK_STATUSBAR(s), | 138 | gtk_statusbar_pop (GTK_STATUSBAR (s), id); |
147 | id); | 139 | gtk_statusbar_push (GTK_STATUSBAR (s), id, (const char *) args); |
148 | gtk_statusbar_push(GTK_STATUSBAR(s), | ||
149 | id, | ||
150 | (const char*) args); | ||
151 | return NULL; | 140 | return NULL; |
152 | } | 141 | } |
153 | 142 | ||
@@ -157,51 +146,49 @@ static void * saveAddLogEntry(void * args) { | |||
157 | * @param txt the log entry | 146 | * @param txt the log entry |
158 | * | 147 | * |
159 | */ | 148 | */ |
160 | void addLogEntry(const char * txt, | 149 | void |
161 | ...) { | 150 | addLogEntry (const char *txt, ...) |
151 | { | ||
162 | va_list args; | 152 | va_list args; |
163 | gchar * note; | 153 | gchar *note; |
164 | 154 | ||
165 | va_start(args, txt); | 155 | va_start (args, txt); |
166 | note = g_strdup_vprintf(txt, args); | 156 | note = g_strdup_vprintf (txt, args); |
167 | va_end(args); | 157 | va_end (args); |
168 | infoMessage(NO, note); | 158 | infoMessage (NO, note); |
169 | gtkSaveCall(&saveAddLogEntry, | 159 | gtkSaveCall (&saveAddLogEntry, (void *) note); |
170 | (void*) note); | 160 | g_free (note); |
171 | g_free(note); | ||
172 | } | 161 | } |
173 | 162 | ||
174 | static void ge_gtk_log_handler(void * ctx, | 163 | static void |
175 | GE_KIND kind, | 164 | ge_gtk_log_handler (void *ctx, |
176 | const char * date, | 165 | GE_KIND kind, const char *date, const char *msg) |
177 | const char * msg) { | 166 | { |
178 | int popUp; | 167 | int popUp; |
179 | 168 | ||
180 | popUp = NO; | 169 | popUp = NO; |
181 | if ( (kind & (GE_FATAL | GE_ERROR | GE_WARNING)) > 0) | 170 | if ((kind & (GE_FATAL | GE_ERROR | GE_WARNING)) > 0) |
182 | popUp = YES; | 171 | popUp = YES; |
183 | infoMessage(popUp, | 172 | infoMessage (popUp, "%s: %s", date, msg); |
184 | "%s: %s", | ||
185 | date, | ||
186 | msg); | ||
187 | } | 173 | } |
188 | 174 | ||
189 | struct GE_Context * createGtkLogger(GE_KIND mask) { | 175 | struct GE_Context * |
190 | struct GE_Context * myLog; | 176 | createGtkLogger (GE_KIND mask) |
177 | { | ||
178 | struct GE_Context *myLog; | ||
191 | 179 | ||
192 | myLog = GE_create_context_callback(mask, | 180 | myLog = GE_create_context_callback (mask, |
193 | &ge_gtk_log_handler, | 181 | &ge_gtk_log_handler, NULL, NULL, NULL); |
194 | NULL, | ||
195 | NULL, | ||
196 | NULL); | ||
197 | return myLog; | 182 | return myLog; |
198 | } | 183 | } |
199 | 184 | ||
200 | void __attribute__ ((destructor)) gnunet_gtk_common_ltdl_fini() { | 185 | void __attribute__ ((destructor)) gnunet_gtk_common_ltdl_fini () |
201 | if (statusXML != NULL) { | 186 | { |
202 | gtk_widget_destroy(infoWindow); | 187 | if (statusXML != NULL) |
203 | infoWindow = NULL; | 188 | { |
204 | UNREF(statusXML); | 189 | gtk_widget_destroy (infoWindow); |
205 | statusXML = NULL; | 190 | infoWindow = NULL; |
206 | } | 191 | UNREF (statusXML); |
192 | statusXML = NULL; | ||
193 | } | ||
207 | } | 194 | } |
diff --git a/src/core/eggtrayicon.c b/src/core/eggtrayicon.c index 6d7a02f7..da2ee0e4 100644 --- a/src/core/eggtrayicon.c +++ b/src/core/eggtrayicon.c | |||
@@ -55,16 +55,14 @@ | |||
55 | #include <X11/Xatom.h> | 55 | #include <X11/Xatom.h> |
56 | 56 | ||
57 | G_BEGIN_DECLS | 57 | G_BEGIN_DECLS |
58 | |||
59 | #define EGG_TYPE_TRAY_ICON (egg_tray_icon_get_type ()) | 58 | #define EGG_TYPE_TRAY_ICON (egg_tray_icon_get_type ()) |
60 | #define EGG_TRAY_ICON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EGG_TYPE_TRAY_ICON, EggTrayIcon)) | 59 | #define EGG_TRAY_ICON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EGG_TYPE_TRAY_ICON, EggTrayIcon)) |
61 | #define EGG_TRAY_ICON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EGG_TYPE_TRAY_ICON, EggTrayIconClass)) | 60 | #define EGG_TRAY_ICON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EGG_TYPE_TRAY_ICON, EggTrayIconClass)) |
62 | #define EGG_IS_TRAY_ICON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EGG_TYPE_TRAY_ICON)) | 61 | #define EGG_IS_TRAY_ICON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EGG_TYPE_TRAY_ICON)) |
63 | #define EGG_IS_TRAY_ICON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EGG_TYPE_TRAY_ICON)) | 62 | #define EGG_IS_TRAY_ICON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EGG_TYPE_TRAY_ICON)) |
64 | #define EGG_TRAY_ICON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EGG_TYPE_TRAY_ICON, EggTrayIconClass)) | 63 | #define EGG_TRAY_ICON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EGG_TYPE_TRAY_ICON, EggTrayIconClass)) |
65 | 64 | typedef struct _EggTrayIcon EggTrayIcon; | |
66 | typedef struct _EggTrayIcon EggTrayIcon; | 65 | typedef struct _EggTrayIconClass EggTrayIconClass; |
67 | typedef struct _EggTrayIconClass EggTrayIconClass; | ||
68 | 66 | ||
69 | struct _EggTrayIcon | 67 | struct _EggTrayIcon |
70 | { | 68 | { |
@@ -86,73 +84,74 @@ struct _EggTrayIconClass | |||
86 | GtkPlugClass parent_class; | 84 | GtkPlugClass parent_class; |
87 | }; | 85 | }; |
88 | 86 | ||
89 | GType egg_tray_icon_get_type (void); | 87 | GType egg_tray_icon_get_type (void); |
90 | 88 | ||
91 | #if GTK_CHECK_VERSION(2,1,0) | 89 | #if GTK_CHECK_VERSION(2,1,0) |
92 | EggTrayIcon *egg_tray_icon_new_for_screen (GdkScreen *screen, | 90 | EggTrayIcon *egg_tray_icon_new_for_screen (GdkScreen * screen, |
93 | const gchar *name); | 91 | const gchar * name); |
94 | #endif | 92 | #endif |
95 | 93 | ||
96 | EggTrayIcon *egg_tray_icon_new (const gchar *name); | 94 | EggTrayIcon *egg_tray_icon_new (const gchar * name); |
97 | 95 | ||
98 | guint egg_tray_icon_send_message (EggTrayIcon *icon, | 96 | guint egg_tray_icon_send_message (EggTrayIcon * icon, |
99 | gint timeout, | 97 | gint timeout, |
100 | const char *message, | 98 | const char *message, gint len); |
101 | gint len); | 99 | void egg_tray_icon_cancel_message (EggTrayIcon * icon, guint id); |
102 | void egg_tray_icon_cancel_message (EggTrayIcon *icon, | ||
103 | guint id); | ||
104 | 100 | ||
105 | GtkOrientation egg_tray_icon_get_orientation (EggTrayIcon *icon); | 101 | GtkOrientation egg_tray_icon_get_orientation (EggTrayIcon * icon); |
106 | 102 | ||
107 | 103 | ||
108 | static gboolean tray_clicked (GtkWidget *trayContextMenu, GdkEvent *event); | 104 | static gboolean tray_clicked (GtkWidget * trayContextMenu, GdkEvent * event); |
109 | static gboolean on_tray_quit_activate(GtkWidget *widget, GdkEvent *event, gpointer data); | 105 | static gboolean on_tray_quit_activate (GtkWidget * widget, GdkEvent * event, |
110 | 106 | gpointer data); | |
111 | G_END_DECLS | ||
112 | 107 | ||
108 | G_END_DECLS | ||
113 | #define SYSTEM_TRAY_REQUEST_DOCK 0 | 109 | #define SYSTEM_TRAY_REQUEST_DOCK 0 |
114 | #define SYSTEM_TRAY_BEGIN_MESSAGE 1 | 110 | #define SYSTEM_TRAY_BEGIN_MESSAGE 1 |
115 | #define SYSTEM_TRAY_CANCEL_MESSAGE 2 | 111 | #define SYSTEM_TRAY_CANCEL_MESSAGE 2 |
116 | |||
117 | #define SYSTEM_TRAY_ORIENTATION_HORZ 0 | 112 | #define SYSTEM_TRAY_ORIENTATION_HORZ 0 |
118 | #define SYSTEM_TRAY_ORIENTATION_VERT 1 | 113 | #define SYSTEM_TRAY_ORIENTATION_VERT 1 |
119 | 114 | enum | |
120 | enum { | 115 | { |
121 | PROP_0, | 116 | PROP_0, |
122 | PROP_ORIENTATION | 117 | PROP_ORIENTATION |
123 | }; | 118 | }; |
124 | 119 | ||
125 | static GtkPlugClass *parent_class = NULL; | 120 | static GtkPlugClass *parent_class = NULL; |
126 | 121 | ||
127 | static void egg_tray_icon_init (EggTrayIcon *icon); | 122 | static void egg_tray_icon_init (EggTrayIcon * icon); |
128 | static void egg_tray_icon_class_init (EggTrayIconClass *klass); | 123 | static void egg_tray_icon_class_init (EggTrayIconClass * klass); |
129 | 124 | ||
130 | static void egg_tray_icon_get_property (GObject *object, | 125 | static void egg_tray_icon_get_property (GObject * object, |
131 | guint prop_id, | 126 | guint prop_id, |
132 | GValue *value, | 127 | GValue * value, GParamSpec * pspec); |
133 | GParamSpec *pspec); | ||
134 | 128 | ||
135 | static void egg_tray_icon_realize (GtkWidget *widget); | 129 | static void egg_tray_icon_realize (GtkWidget * widget); |
136 | static void egg_tray_icon_unrealize (GtkWidget *widget); | 130 | static void egg_tray_icon_unrealize (GtkWidget * widget); |
137 | 131 | ||
138 | static void egg_tray_icon_update_manager_window (EggTrayIcon *icon, | 132 | static void egg_tray_icon_update_manager_window (EggTrayIcon * icon, |
139 | gboolean dock_if_realized); | 133 | gboolean dock_if_realized); |
140 | static void egg_tray_icon_manager_window_destroyed (EggTrayIcon *icon); | 134 | static void egg_tray_icon_manager_window_destroyed (EggTrayIcon * icon); |
141 | 135 | ||
142 | static Display * getDisplay(GtkWidget * w) { | 136 | static Display * |
137 | getDisplay (GtkWidget * w) | ||
138 | { | ||
143 | #if GTK_CHECK_VERSION(2,1,0) | 139 | #if GTK_CHECK_VERSION(2,1,0) |
144 | return GDK_DISPLAY_XDISPLAY (gtk_widget_get_display (w)); | 140 | return GDK_DISPLAY_XDISPLAY (gtk_widget_get_display (w)); |
145 | #else | 141 | #else |
146 | return gdk_display; | 142 | return gdk_display; |
147 | #endif | 143 | #endif |
148 | } | 144 | } |
149 | 145 | ||
150 | static GdkWindow * getWindow(EggTrayIcon * icon) { | 146 | static GdkWindow * |
147 | getWindow (EggTrayIcon * icon) | ||
148 | { | ||
151 | #if GTK_CHECK_VERSION(2,1,0) | 149 | #if GTK_CHECK_VERSION(2,1,0) |
152 | return gdk_window_lookup_for_display (gtk_widget_get_display(GTK_WIDGET(icon)), | 150 | return |
153 | icon->manager_window); | 151 | gdk_window_lookup_for_display (gtk_widget_get_display (GTK_WIDGET (icon)), |
152 | icon->manager_window); | ||
154 | #else | 153 | #else |
155 | return gdk_window_lookup(icon->manager_window); | 154 | return gdk_window_lookup (icon->manager_window); |
156 | #endif | 155 | #endif |
157 | } | 156 | } |
158 | 157 | ||
@@ -163,30 +162,32 @@ egg_tray_icon_get_type (void) | |||
163 | 162 | ||
164 | if (our_type == 0) | 163 | if (our_type == 0) |
165 | { | 164 | { |
166 | our_type = g_type_from_name("EggTrayIcon"); | 165 | our_type = g_type_from_name ("EggTrayIcon"); |
167 | 166 | ||
168 | if (our_type == 0) | 167 | if (our_type == 0) |
169 | { | 168 | { |
170 | static const GTypeInfo our_info = | 169 | static const GTypeInfo our_info = { |
171 | { | 170 | sizeof (EggTrayIconClass), |
172 | sizeof (EggTrayIconClass), | 171 | (GBaseInitFunc) NULL, |
173 | (GBaseInitFunc) NULL, | 172 | (GBaseFinalizeFunc) NULL, |
174 | (GBaseFinalizeFunc) NULL, | 173 | (GClassInitFunc) egg_tray_icon_class_init, |
175 | (GClassInitFunc) egg_tray_icon_class_init, | 174 | NULL, /* class_finalize */ |
176 | NULL, /* class_finalize */ | 175 | NULL, /* class_data */ |
177 | NULL, /* class_data */ | 176 | sizeof (EggTrayIcon), |
178 | sizeof (EggTrayIcon), | 177 | 0, /* n_preallocs */ |
179 | 0, /* n_preallocs */ | 178 | (GInstanceInitFunc) egg_tray_icon_init, |
180 | (GInstanceInitFunc) egg_tray_icon_init, | 179 | NULL /* value_table */ |
181 | NULL /* value_table */ | 180 | }; |
182 | }; | 181 | |
183 | 182 | our_type = | |
184 | our_type = g_type_register_static (GTK_TYPE_PLUG, "EggTrayIcon", &our_info, 0); | 183 | g_type_register_static (GTK_TYPE_PLUG, "EggTrayIcon", &our_info, |
184 | 0); | ||
185 | } | 185 | } |
186 | else if (parent_class == NULL) | 186 | else if (parent_class == NULL) |
187 | { | 187 | { |
188 | /* we're reheating the old class from a previous instance - engage ugly hack =( */ | 188 | /* we're reheating the old class from a previous instance - engage ugly hack =( */ |
189 | egg_tray_icon_class_init((EggTrayIconClass *)g_type_class_peek(our_type)); | 189 | egg_tray_icon_class_init ((EggTrayIconClass *) |
190 | g_type_class_peek (our_type)); | ||
190 | } | 191 | } |
191 | } | 192 | } |
192 | 193 | ||
@@ -194,7 +195,7 @@ egg_tray_icon_get_type (void) | |||
194 | } | 195 | } |
195 | 196 | ||
196 | static void | 197 | static void |
197 | egg_tray_icon_init (EggTrayIcon *icon) | 198 | egg_tray_icon_init (EggTrayIcon * icon) |
198 | { | 199 | { |
199 | icon->stamp = 1; | 200 | icon->stamp = 1; |
200 | icon->orientation = GTK_ORIENTATION_HORIZONTAL; | 201 | icon->orientation = GTK_ORIENTATION_HORIZONTAL; |
@@ -203,33 +204,32 @@ egg_tray_icon_init (EggTrayIcon *icon) | |||
203 | } | 204 | } |
204 | 205 | ||
205 | static void | 206 | static void |
206 | egg_tray_icon_class_init (EggTrayIconClass *klass) | 207 | egg_tray_icon_class_init (EggTrayIconClass * klass) |
207 | { | 208 | { |
208 | GObjectClass *gobject_class = (GObjectClass *)klass; | 209 | GObjectClass *gobject_class = (GObjectClass *) klass; |
209 | GtkWidgetClass *widget_class = (GtkWidgetClass *)klass; | 210 | GtkWidgetClass *widget_class = (GtkWidgetClass *) klass; |
210 | 211 | ||
211 | parent_class = g_type_class_peek_parent (klass); | 212 | parent_class = g_type_class_peek_parent (klass); |
212 | 213 | ||
213 | gobject_class->get_property = egg_tray_icon_get_property; | 214 | gobject_class->get_property = egg_tray_icon_get_property; |
214 | 215 | ||
215 | widget_class->realize = egg_tray_icon_realize; | 216 | widget_class->realize = egg_tray_icon_realize; |
216 | widget_class->unrealize = egg_tray_icon_unrealize; | 217 | widget_class->unrealize = egg_tray_icon_unrealize; |
217 | 218 | ||
218 | g_object_class_install_property (gobject_class, | 219 | g_object_class_install_property (gobject_class, |
219 | PROP_ORIENTATION, | 220 | PROP_ORIENTATION, |
220 | g_param_spec_enum ("orientation", | 221 | g_param_spec_enum ("orientation", |
221 | _("Orientation"), | 222 | _("Orientation"), |
222 | _("The orientation of the tray."), | 223 | _ |
223 | GTK_TYPE_ORIENTATION, | 224 | ("The orientation of the tray."), |
224 | GTK_ORIENTATION_HORIZONTAL, | 225 | GTK_TYPE_ORIENTATION, |
225 | G_PARAM_READABLE)); | 226 | GTK_ORIENTATION_HORIZONTAL, |
227 | G_PARAM_READABLE)); | ||
226 | } | 228 | } |
227 | 229 | ||
228 | static void | 230 | static void |
229 | egg_tray_icon_get_property (GObject *object, | 231 | egg_tray_icon_get_property (GObject * object, |
230 | guint prop_id, | 232 | guint prop_id, GValue * value, GParamSpec * pspec) |
231 | GValue *value, | ||
232 | GParamSpec *pspec) | ||
233 | { | 233 | { |
234 | EggTrayIcon *icon = EGG_TRAY_ICON (object); | 234 | EggTrayIcon *icon = EGG_TRAY_ICON (object); |
235 | 235 | ||
@@ -245,32 +245,35 @@ egg_tray_icon_get_property (GObject *object, | |||
245 | } | 245 | } |
246 | 246 | ||
247 | static void | 247 | static void |
248 | egg_tray_icon_get_orientation_property (EggTrayIcon *icon) | 248 | egg_tray_icon_get_orientation_property (EggTrayIcon * icon) |
249 | { | 249 | { |
250 | Display *xdisplay; | 250 | Display *xdisplay; |
251 | Atom type; | 251 | Atom type; |
252 | int format; | 252 | int format; |
253 | union { | 253 | union |
254 | gulong *prop; | 254 | { |
255 | guchar *prop_ch; | 255 | gulong *prop; |
256 | } prop = { NULL }; | 256 | guchar *prop_ch; |
257 | } prop = | ||
258 | { | ||
259 | NULL}; | ||
257 | gulong nitems; | 260 | gulong nitems; |
258 | gulong bytes_after; | 261 | gulong bytes_after; |
259 | int error, result; | 262 | int error, result; |
260 | 263 | ||
261 | g_return_if_fail(icon->manager_window != None); | 264 | g_return_if_fail (icon->manager_window != None); |
262 | 265 | ||
263 | xdisplay = getDisplay(GTK_WIDGET (icon)); | 266 | xdisplay = getDisplay (GTK_WIDGET (icon)); |
264 | 267 | ||
265 | gdk_error_trap_push (); | 268 | gdk_error_trap_push (); |
266 | type = None; | 269 | type = None; |
267 | result = XGetWindowProperty (xdisplay, | 270 | result = XGetWindowProperty (xdisplay, |
268 | icon->manager_window, | 271 | icon->manager_window, |
269 | icon->orientation_atom, | 272 | icon->orientation_atom, |
270 | 0, G_MAXLONG, FALSE, | 273 | 0, G_MAXLONG, FALSE, |
271 | XA_CARDINAL, | 274 | XA_CARDINAL, |
272 | &type, &format, &nitems, | 275 | &type, &format, &nitems, |
273 | &bytes_after, &(prop.prop_ch)); | 276 | &bytes_after, &(prop.prop_ch)); |
274 | error = gdk_error_trap_pop (); | 277 | error = gdk_error_trap_pop (); |
275 | 278 | ||
276 | if (error || result != Success) | 279 | if (error || result != Success) |
@@ -280,16 +283,15 @@ egg_tray_icon_get_orientation_property (EggTrayIcon *icon) | |||
280 | { | 283 | { |
281 | GtkOrientation orientation; | 284 | GtkOrientation orientation; |
282 | 285 | ||
283 | orientation = (prop.prop [0] == SYSTEM_TRAY_ORIENTATION_HORZ) ? | 286 | orientation = (prop.prop[0] == SYSTEM_TRAY_ORIENTATION_HORZ) ? |
284 | GTK_ORIENTATION_HORIZONTAL : | 287 | GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL; |
285 | GTK_ORIENTATION_VERTICAL; | ||
286 | 288 | ||
287 | if (icon->orientation != orientation) | 289 | if (icon->orientation != orientation) |
288 | { | 290 | { |
289 | icon->orientation = orientation; | 291 | icon->orientation = orientation; |
290 | 292 | ||
291 | g_object_notify (G_OBJECT (icon), "orientation"); | 293 | g_object_notify (G_OBJECT (icon), "orientation"); |
292 | } | 294 | } |
293 | } | 295 | } |
294 | 296 | ||
295 | if (prop.prop) | 297 | if (prop.prop) |
@@ -297,10 +299,11 @@ egg_tray_icon_get_orientation_property (EggTrayIcon *icon) | |||
297 | } | 299 | } |
298 | 300 | ||
299 | static GdkFilterReturn | 301 | static GdkFilterReturn |
300 | egg_tray_icon_manager_filter (GdkXEvent *xevent, GdkEvent *event, gpointer user_data) | 302 | egg_tray_icon_manager_filter (GdkXEvent * xevent, GdkEvent * event, |
303 | gpointer user_data) | ||
301 | { | 304 | { |
302 | EggTrayIcon *icon = user_data; | 305 | EggTrayIcon *icon = user_data; |
303 | XEvent *xev = (XEvent *)xevent; | 306 | XEvent *xev = (XEvent *) xevent; |
304 | 307 | ||
305 | if (xev->xany.type == ClientMessage && | 308 | if (xev->xany.type == ClientMessage && |
306 | xev->xclient.message_type == icon->manager_atom && | 309 | xev->xclient.message_type == icon->manager_atom && |
@@ -311,21 +314,21 @@ egg_tray_icon_manager_filter (GdkXEvent *xevent, GdkEvent *event, gpointer user_ | |||
311 | else if (xev->xany.window == icon->manager_window) | 314 | else if (xev->xany.window == icon->manager_window) |
312 | { | 315 | { |
313 | if (xev->xany.type == PropertyNotify && | 316 | if (xev->xany.type == PropertyNotify && |
314 | xev->xproperty.atom == icon->orientation_atom) | 317 | xev->xproperty.atom == icon->orientation_atom) |
315 | { | 318 | { |
316 | egg_tray_icon_get_orientation_property (icon); | 319 | egg_tray_icon_get_orientation_property (icon); |
317 | } | 320 | } |
318 | if (xev->xany.type == DestroyNotify) | 321 | if (xev->xany.type == DestroyNotify) |
319 | { | 322 | { |
320 | egg_tray_icon_manager_window_destroyed (icon); | 323 | egg_tray_icon_manager_window_destroyed (icon); |
321 | } | 324 | } |
322 | } | 325 | } |
323 | 326 | ||
324 | return GDK_FILTER_CONTINUE; | 327 | return GDK_FILTER_CONTINUE; |
325 | } | 328 | } |
326 | 329 | ||
327 | static void | 330 | static void |
328 | egg_tray_icon_unrealize (GtkWidget *widget) | 331 | egg_tray_icon_unrealize (GtkWidget * widget) |
329 | { | 332 | { |
330 | EggTrayIcon *icon = EGG_TRAY_ICON (widget); | 333 | EggTrayIcon *icon = EGG_TRAY_ICON (widget); |
331 | GdkWindow *root_window; | 334 | GdkWindow *root_window; |
@@ -334,7 +337,7 @@ egg_tray_icon_unrealize (GtkWidget *widget) | |||
334 | { | 337 | { |
335 | GdkWindow *gdkwin; | 338 | GdkWindow *gdkwin; |
336 | 339 | ||
337 | gdkwin = getWindow(icon); | 340 | gdkwin = getWindow (icon); |
338 | gdk_window_remove_filter (gdkwin, egg_tray_icon_manager_filter, icon); | 341 | gdk_window_remove_filter (gdkwin, egg_tray_icon_manager_filter, icon); |
339 | } | 342 | } |
340 | 343 | ||
@@ -347,16 +350,14 @@ egg_tray_icon_unrealize (GtkWidget *widget) | |||
347 | gdk_window_remove_filter (root_window, egg_tray_icon_manager_filter, icon); | 350 | gdk_window_remove_filter (root_window, egg_tray_icon_manager_filter, icon); |
348 | 351 | ||
349 | if (GTK_WIDGET_CLASS (parent_class)->unrealize) | 352 | if (GTK_WIDGET_CLASS (parent_class)->unrealize) |
350 | (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget); | 353 | (*GTK_WIDGET_CLASS (parent_class)->unrealize) (widget); |
351 | } | 354 | } |
352 | 355 | ||
353 | static void | 356 | static void |
354 | egg_tray_icon_send_manager_message (EggTrayIcon *icon, | 357 | egg_tray_icon_send_manager_message (EggTrayIcon * icon, |
355 | long message, | 358 | long message, |
356 | Window window, | 359 | Window window, |
357 | long data1, | 360 | long data1, long data2, long data3) |
358 | long data2, | ||
359 | long data3) | ||
360 | { | 361 | { |
361 | XClientMessageEvent ev; | 362 | XClientMessageEvent ev; |
362 | Display *display; | 363 | Display *display; |
@@ -371,43 +372,43 @@ egg_tray_icon_send_manager_message (EggTrayIcon *icon, | |||
371 | ev.data.l[3] = data2; | 372 | ev.data.l[3] = data2; |
372 | ev.data.l[4] = data3; | 373 | ev.data.l[4] = data3; |
373 | 374 | ||
374 | display = getDisplay(GTK_WIDGET (icon)); | 375 | display = getDisplay (GTK_WIDGET (icon)); |
375 | 376 | ||
376 | gdk_error_trap_push (); | 377 | gdk_error_trap_push (); |
377 | XSendEvent (display, | 378 | XSendEvent (display, |
378 | icon->manager_window, False, NoEventMask, (XEvent *)&ev); | 379 | icon->manager_window, False, NoEventMask, (XEvent *) & ev); |
379 | XSync (display, False); | 380 | XSync (display, False); |
380 | gdk_error_trap_pop (); | 381 | gdk_error_trap_pop (); |
381 | } | 382 | } |
382 | 383 | ||
383 | static void | 384 | static void |
384 | egg_tray_icon_send_dock_request (EggTrayIcon *icon) | 385 | egg_tray_icon_send_dock_request (EggTrayIcon * icon) |
385 | { | 386 | { |
386 | egg_tray_icon_send_manager_message (icon, | 387 | egg_tray_icon_send_manager_message (icon, |
387 | SYSTEM_TRAY_REQUEST_DOCK, | 388 | SYSTEM_TRAY_REQUEST_DOCK, |
388 | icon->manager_window, | 389 | icon->manager_window, |
389 | gtk_plug_get_id (GTK_PLUG (icon)), | 390 | gtk_plug_get_id (GTK_PLUG (icon)), |
390 | 0, 0); | 391 | 0, 0); |
391 | } | 392 | } |
392 | 393 | ||
393 | static void | 394 | static void |
394 | egg_tray_icon_update_manager_window (EggTrayIcon *icon, | 395 | egg_tray_icon_update_manager_window (EggTrayIcon * icon, |
395 | gboolean dock_if_realized) | 396 | gboolean dock_if_realized) |
396 | { | 397 | { |
397 | Display *xdisplay; | 398 | Display *xdisplay; |
398 | 399 | ||
399 | if (icon->manager_window != None) | 400 | if (icon->manager_window != None) |
400 | return; | 401 | return; |
401 | 402 | ||
402 | xdisplay = getDisplay(GTK_WIDGET (icon)); | 403 | xdisplay = getDisplay (GTK_WIDGET (icon)); |
403 | XGrabServer (xdisplay); | 404 | XGrabServer (xdisplay); |
404 | 405 | ||
405 | icon->manager_window = XGetSelectionOwner (xdisplay, | 406 | icon->manager_window = XGetSelectionOwner (xdisplay, icon->selection_atom); |
406 | icon->selection_atom); | ||
407 | 407 | ||
408 | if (icon->manager_window != None) | 408 | if (icon->manager_window != None) |
409 | XSelectInput (xdisplay, | 409 | XSelectInput (xdisplay, |
410 | icon->manager_window, StructureNotifyMask|PropertyChangeMask); | 410 | icon->manager_window, |
411 | StructureNotifyMask | PropertyChangeMask); | ||
411 | 412 | ||
412 | XUngrabServer (xdisplay); | 413 | XUngrabServer (xdisplay); |
413 | XFlush (xdisplay); | 414 | XFlush (xdisplay); |
@@ -416,24 +417,24 @@ egg_tray_icon_update_manager_window (EggTrayIcon *icon, | |||
416 | { | 417 | { |
417 | GdkWindow *gdkwin; | 418 | GdkWindow *gdkwin; |
418 | 419 | ||
419 | gdkwin = getWindow(icon); | 420 | gdkwin = getWindow (icon); |
420 | gdk_window_add_filter (gdkwin, egg_tray_icon_manager_filter, icon); | 421 | gdk_window_add_filter (gdkwin, egg_tray_icon_manager_filter, icon); |
421 | 422 | ||
422 | if (dock_if_realized && GTK_WIDGET_REALIZED (icon)) | 423 | if (dock_if_realized && GTK_WIDGET_REALIZED (icon)) |
423 | egg_tray_icon_send_dock_request (icon); | 424 | egg_tray_icon_send_dock_request (icon); |
424 | 425 | ||
425 | egg_tray_icon_get_orientation_property (icon); | 426 | egg_tray_icon_get_orientation_property (icon); |
426 | } | 427 | } |
427 | } | 428 | } |
428 | 429 | ||
429 | static void | 430 | static void |
430 | egg_tray_icon_manager_window_destroyed (EggTrayIcon *icon) | 431 | egg_tray_icon_manager_window_destroyed (EggTrayIcon * icon) |
431 | { | 432 | { |
432 | GdkWindow *gdkwin; | 433 | GdkWindow *gdkwin; |
433 | 434 | ||
434 | g_return_if_fail (icon->manager_window != None); | 435 | g_return_if_fail (icon->manager_window != None); |
435 | 436 | ||
436 | gdkwin = getWindow(icon); | 437 | gdkwin = getWindow (icon); |
437 | gdk_window_remove_filter (gdkwin, egg_tray_icon_manager_filter, icon); | 438 | gdk_window_remove_filter (gdkwin, egg_tray_icon_manager_filter, icon); |
438 | 439 | ||
439 | icon->manager_window = None; | 440 | icon->manager_window = None; |
@@ -442,7 +443,7 @@ egg_tray_icon_manager_window_destroyed (EggTrayIcon *icon) | |||
442 | } | 443 | } |
443 | 444 | ||
444 | static void | 445 | static void |
445 | egg_tray_icon_realize (GtkWidget *widget) | 446 | egg_tray_icon_realize (GtkWidget * widget) |
446 | { | 447 | { |
447 | EggTrayIcon *icon = EGG_TRAY_ICON (widget); | 448 | EggTrayIcon *icon = EGG_TRAY_ICON (widget); |
448 | gint screen; | 449 | gint screen; |
@@ -462,21 +463,19 @@ egg_tray_icon_realize (GtkWidget *widget) | |||
462 | #endif | 463 | #endif |
463 | 464 | ||
464 | /* Now see if there's a manager window around */ | 465 | /* Now see if there's a manager window around */ |
465 | g_snprintf (buffer, sizeof (buffer), | 466 | g_snprintf (buffer, sizeof (buffer), "_NET_SYSTEM_TRAY_S%d", screen); |
466 | "_NET_SYSTEM_TRAY_S%d", | ||
467 | screen); | ||
468 | 467 | ||
469 | icon->selection_atom = XInternAtom (xdisplay, buffer, False); | 468 | icon->selection_atom = XInternAtom (xdisplay, buffer, False); |
470 | 469 | ||
471 | icon->manager_atom = XInternAtom (xdisplay, "MANAGER", False); | 470 | icon->manager_atom = XInternAtom (xdisplay, "MANAGER", False); |
472 | 471 | ||
473 | icon->system_tray_opcode_atom = XInternAtom (xdisplay, | 472 | icon->system_tray_opcode_atom = XInternAtom (xdisplay, |
474 | "_NET_SYSTEM_TRAY_OPCODE", | 473 | "_NET_SYSTEM_TRAY_OPCODE", |
475 | False); | 474 | False); |
476 | 475 | ||
477 | icon->orientation_atom = XInternAtom (xdisplay, | 476 | icon->orientation_atom = XInternAtom (xdisplay, |
478 | "_NET_SYSTEM_TRAY_ORIENTATION", | 477 | "_NET_SYSTEM_TRAY_ORIENTATION", |
479 | False); | 478 | False); |
480 | 479 | ||
481 | egg_tray_icon_update_manager_window (icon, FALSE); | 480 | egg_tray_icon_update_manager_window (icon, FALSE); |
482 | egg_tray_icon_send_dock_request (icon); | 481 | egg_tray_icon_send_dock_request (icon); |
@@ -488,38 +487,36 @@ egg_tray_icon_realize (GtkWidget *widget) | |||
488 | #endif | 487 | #endif |
489 | 488 | ||
490 | /* Add a root window filter so that we get changes on MANAGER */ | 489 | /* Add a root window filter so that we get changes on MANAGER */ |
491 | gdk_window_add_filter (root_window, | 490 | gdk_window_add_filter (root_window, egg_tray_icon_manager_filter, icon); |
492 | egg_tray_icon_manager_filter, icon); | ||
493 | } | 491 | } |
494 | 492 | ||
495 | #if GTK_CHECK_VERSION(2,1,0) | 493 | #if GTK_CHECK_VERSION(2,1,0) |
496 | EggTrayIcon * | 494 | EggTrayIcon * |
497 | egg_tray_icon_new_for_screen (GdkScreen *screen, const char *name) | 495 | egg_tray_icon_new_for_screen (GdkScreen * screen, const char *name) |
498 | { | 496 | { |
499 | g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL); | 497 | g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL); |
500 | 498 | ||
501 | return g_object_new (EGG_TYPE_TRAY_ICON, "screen", screen, "title", name, NULL); | 499 | return g_object_new (EGG_TYPE_TRAY_ICON, "screen", screen, "title", name, |
500 | NULL); | ||
502 | } | 501 | } |
503 | #endif | 502 | #endif |
504 | 503 | ||
505 | EggTrayIcon* | 504 | EggTrayIcon * |
506 | egg_tray_icon_new (const gchar *name) | 505 | egg_tray_icon_new (const gchar * name) |
507 | { | 506 | { |
508 | return g_object_new (EGG_TYPE_TRAY_ICON, "title", name, NULL); | 507 | return g_object_new (EGG_TYPE_TRAY_ICON, "title", name, NULL); |
509 | } | 508 | } |
510 | 509 | ||
511 | guint | 510 | guint |
512 | egg_tray_icon_send_message (EggTrayIcon *icon, | 511 | egg_tray_icon_send_message (EggTrayIcon * icon, |
513 | gint timeout, | 512 | gint timeout, const gchar * message, gint len) |
514 | const gchar *message, | ||
515 | gint len) | ||
516 | { | 513 | { |
517 | guint stamp; | 514 | guint stamp; |
518 | 515 | ||
519 | g_return_val_if_fail (EGG_IS_TRAY_ICON (icon), 0); | 516 | g_return_val_if_fail (EGG_IS_TRAY_ICON (icon), 0); |
520 | g_return_val_if_fail (timeout >= 0, 0); | 517 | g_return_val_if_fail (timeout >= 0, 0); |
521 | g_return_val_if_fail (message != NULL, 0); | 518 | g_return_val_if_fail (message != NULL, 0); |
522 | 519 | ||
523 | if (icon->manager_window == None) | 520 | if (icon->manager_window == None) |
524 | return 0; | 521 | return 0; |
525 | 522 | ||
@@ -530,8 +527,9 @@ egg_tray_icon_send_message (EggTrayIcon *icon, | |||
530 | 527 | ||
531 | /* Get ready to send the message */ | 528 | /* Get ready to send the message */ |
532 | egg_tray_icon_send_manager_message (icon, SYSTEM_TRAY_BEGIN_MESSAGE, | 529 | egg_tray_icon_send_manager_message (icon, SYSTEM_TRAY_BEGIN_MESSAGE, |
533 | (Window)gtk_plug_get_id (GTK_PLUG (icon)), | 530 | (Window) |
534 | timeout, len, stamp); | 531 | gtk_plug_get_id (GTK_PLUG (icon)), |
532 | timeout, len, stamp); | ||
535 | 533 | ||
536 | /* Now to send the actual message */ | 534 | /* Now to send the actual message */ |
537 | gdk_error_trap_push (); | 535 | gdk_error_trap_push (); |
@@ -540,27 +538,28 @@ egg_tray_icon_send_message (EggTrayIcon *icon, | |||
540 | XClientMessageEvent ev; | 538 | XClientMessageEvent ev; |
541 | Display *xdisplay; | 539 | Display *xdisplay; |
542 | 540 | ||
543 | xdisplay = getDisplay(GTK_WIDGET (icon)); | 541 | xdisplay = getDisplay (GTK_WIDGET (icon)); |
544 | 542 | ||
545 | ev.type = ClientMessage; | 543 | ev.type = ClientMessage; |
546 | ev.window = (Window)gtk_plug_get_id (GTK_PLUG (icon)); | 544 | ev.window = (Window) gtk_plug_get_id (GTK_PLUG (icon)); |
547 | ev.format = 8; | 545 | ev.format = 8; |
548 | ev.message_type = XInternAtom (xdisplay, | 546 | ev.message_type = XInternAtom (xdisplay, |
549 | "_NET_SYSTEM_TRAY_MESSAGE_DATA", False); | 547 | "_NET_SYSTEM_TRAY_MESSAGE_DATA", False); |
550 | if (len > 20) | 548 | if (len > 20) |
551 | { | 549 | { |
552 | memcpy (&ev.data, message, 20); | 550 | memcpy (&ev.data, message, 20); |
553 | len -= 20; | 551 | len -= 20; |
554 | message += 20; | 552 | message += 20; |
555 | } | 553 | } |
556 | else | 554 | else |
557 | { | 555 | { |
558 | memcpy (&ev.data, message, len); | 556 | memcpy (&ev.data, message, len); |
559 | len = 0; | 557 | len = 0; |
560 | } | 558 | } |
561 | 559 | ||
562 | XSendEvent (xdisplay, | 560 | XSendEvent (xdisplay, |
563 | icon->manager_window, False, StructureNotifyMask, (XEvent *)&ev); | 561 | icon->manager_window, False, StructureNotifyMask, |
562 | (XEvent *) & ev); | ||
564 | XSync (xdisplay, False); | 563 | XSync (xdisplay, False); |
565 | } | 564 | } |
566 | gdk_error_trap_pop (); | 565 | gdk_error_trap_pop (); |
@@ -569,19 +568,19 @@ egg_tray_icon_send_message (EggTrayIcon *icon, | |||
569 | } | 568 | } |
570 | 569 | ||
571 | void | 570 | void |
572 | egg_tray_icon_cancel_message (EggTrayIcon *icon, | 571 | egg_tray_icon_cancel_message (EggTrayIcon * icon, guint id) |
573 | guint id) | ||
574 | { | 572 | { |
575 | g_return_if_fail (EGG_IS_TRAY_ICON (icon)); | 573 | g_return_if_fail (EGG_IS_TRAY_ICON (icon)); |
576 | g_return_if_fail (id > 0); | 574 | g_return_if_fail (id > 0); |
577 | 575 | ||
578 | egg_tray_icon_send_manager_message (icon, SYSTEM_TRAY_CANCEL_MESSAGE, | 576 | egg_tray_icon_send_manager_message (icon, SYSTEM_TRAY_CANCEL_MESSAGE, |
579 | (Window)gtk_plug_get_id (GTK_PLUG (icon)), | 577 | (Window) |
580 | id, 0, 0); | 578 | gtk_plug_get_id (GTK_PLUG (icon)), id, |
579 | 0, 0); | ||
581 | } | 580 | } |
582 | 581 | ||
583 | GtkOrientation | 582 | GtkOrientation |
584 | egg_tray_icon_get_orientation (EggTrayIcon *icon) | 583 | egg_tray_icon_get_orientation (EggTrayIcon * icon) |
585 | { | 584 | { |
586 | g_return_val_if_fail (EGG_IS_TRAY_ICON (icon), GTK_ORIENTATION_HORIZONTAL); | 585 | g_return_val_if_fail (EGG_IS_TRAY_ICON (icon), GTK_ORIENTATION_HORIZONTAL); |
587 | 586 | ||
@@ -590,75 +589,86 @@ egg_tray_icon_get_orientation (EggTrayIcon *icon) | |||
590 | 589 | ||
591 | 590 | ||
592 | /* Callback for the "Quit" element on the tray icon menu */ | 591 | /* Callback for the "Quit" element on the tray icon menu */ |
593 | static gboolean on_tray_quit_activate(GtkWidget *widget, GdkEvent *event, gpointer data) { | 592 | static gboolean |
594 | gnunet_gtk_main_quit(); | 593 | on_tray_quit_activate (GtkWidget * widget, GdkEvent * event, gpointer data) |
595 | return TRUE; | 594 | { |
595 | gnunet_gtk_main_quit (); | ||
596 | return TRUE; | ||
596 | } | 597 | } |
597 | 598 | ||
598 | /* Function activated when the user clicks the tray icon */ | 599 | /* Function activated when the user clicks the tray icon */ |
599 | static gboolean tray_clicked(GtkWidget *widget, GdkEvent *event) { | 600 | static gboolean |
600 | if(event->type == GDK_BUTTON_PRESS) { | 601 | tray_clicked (GtkWidget * widget, GdkEvent * event) |
601 | GdkEventButton *event_button; | 602 | { |
602 | event_button = (GdkEventButton *) event; | 603 | if (event->type == GDK_BUTTON_PRESS) |
603 | if(event_button->button == 1) { | 604 | { |
604 | GtkWidget *root; | 605 | GdkEventButton *event_button; |
605 | root = glade_xml_get_widget(getMainXML(), | 606 | event_button = (GdkEventButton *) event; |
606 | "mainWindow"); | 607 | if (event_button->button == 1) |
607 | GdkWindowState main_window_state; | 608 | { |
608 | if (gtk_window_is_active (GTK_WINDOW(root))) | 609 | GtkWidget *root; |
609 | gtk_widget_hide (root); | 610 | root = glade_xml_get_widget (getMainXML (), "mainWindow"); |
610 | else | 611 | GdkWindowState main_window_state; |
611 | gtk_window_present (GTK_WINDOW(root)); | 612 | if (gtk_window_is_active (GTK_WINDOW (root))) |
612 | main_window_state = getMainWindowState(); | 613 | gtk_widget_hide (root); |
613 | if(main_window_state & GDK_WINDOW_STATE_MAXIMIZED) | 614 | else |
614 | gtk_window_maximize (GTK_WINDOW(root)); | 615 | gtk_window_present (GTK_WINDOW (root)); |
615 | return TRUE; | 616 | main_window_state = getMainWindowState (); |
616 | } | 617 | if (main_window_state & GDK_WINDOW_STATE_MAXIMIZED) |
617 | else if(event_button->button == 3) { | 618 | gtk_window_maximize (GTK_WINDOW (root)); |
618 | GtkMenu *trayContextMenu; | 619 | return TRUE; |
619 | trayContextMenu = GTK_MENU (widget); | 620 | } |
620 | g_return_val_if_fail (GTK_IS_MENU (trayContextMenu), FALSE); | 621 | else if (event_button->button == 3) |
621 | gtk_menu_popup(trayContextMenu, NULL, NULL, NULL, NULL, | 622 | { |
622 | event_button->button, event_button->time); | 623 | GtkMenu *trayContextMenu; |
623 | return TRUE; | 624 | trayContextMenu = GTK_MENU (widget); |
625 | g_return_val_if_fail (GTK_IS_MENU (trayContextMenu), FALSE); | ||
626 | gtk_menu_popup (trayContextMenu, NULL, NULL, NULL, NULL, | ||
627 | event_button->button, event_button->time); | ||
628 | return TRUE; | ||
629 | } | ||
624 | } | 630 | } |
625 | } | ||
626 | return FALSE; | 631 | return FALSE; |
627 | } | 632 | } |
628 | 633 | ||
629 | /* Initiate the system tray icon */ | 634 | /* Initiate the system tray icon */ |
630 | void initTrayIcon() { | 635 | void |
631 | static EggTrayIcon *tray_icon; | 636 | initTrayIcon () |
632 | static GtkWidget *tray_icon_image; | 637 | { |
633 | static GtkTooltips *tray_icon_tooltip; | 638 | static EggTrayIcon *tray_icon; |
634 | GtkWidget *eventbox, *trayContextMenu, *tray_quit; | 639 | static GtkWidget *tray_icon_image; |
635 | GdkPixbuf *pixbuf; | 640 | static GtkTooltips *tray_icon_tooltip; |
636 | GladeXML *trayContextMenuXML; | 641 | GtkWidget *eventbox, *trayContextMenu, *tray_quit; |
637 | char * instDir; | 642 | GdkPixbuf *pixbuf; |
638 | char * iconPath; | 643 | GladeXML *trayContextMenuXML; |
639 | 644 | char *instDir; | |
640 | trayContextMenuXML = glade_xml_new (getGladeFileName(), "trayContextMenu", PACKAGE_NAME); | 645 | char *iconPath; |
641 | trayContextMenu = glade_xml_get_widget (trayContextMenuXML, "trayContextMenu"); | 646 | |
642 | tray_quit = glade_xml_get_widget (trayContextMenuXML, "tray_quit"); | 647 | trayContextMenuXML = |
643 | 648 | glade_xml_new (getGladeFileName (), "trayContextMenu", PACKAGE_NAME); | |
644 | tray_icon = egg_tray_icon_new (_("GNU's p2p network")); | 649 | trayContextMenu = |
645 | instDir = os_get_installation_path(IPK_DATADIR); | 650 | glade_xml_get_widget (trayContextMenuXML, "trayContextMenu"); |
646 | iconPath = MALLOC(strlen(instDir) + 40); | 651 | tray_quit = glade_xml_get_widget (trayContextMenuXML, "tray_quit"); |
647 | strcpy(iconPath, instDir); | 652 | |
648 | strcat(iconPath, "/../gnunet-gtk/gnunet-gtk-tray.png"); | 653 | tray_icon = egg_tray_icon_new (_("GNU's p2p network")); |
649 | FREE(instDir); | 654 | instDir = os_get_installation_path (IPK_DATADIR); |
650 | pixbuf = gdk_pixbuf_new_from_file (iconPath, NULL); | 655 | iconPath = MALLOC (strlen (instDir) + 40); |
651 | FREE(iconPath); | 656 | strcpy (iconPath, instDir); |
652 | tray_icon_image = gtk_image_new_from_pixbuf (pixbuf); | 657 | strcat (iconPath, "/../gnunet-gtk/gnunet-gtk-tray.png"); |
653 | eventbox = gtk_event_box_new (); | 658 | FREE (instDir); |
654 | gtk_container_add (GTK_CONTAINER (eventbox), tray_icon_image); | 659 | pixbuf = gdk_pixbuf_new_from_file (iconPath, NULL); |
655 | gtk_container_add (GTK_CONTAINER (tray_icon), eventbox); | 660 | FREE (iconPath); |
656 | g_signal_connect(G_OBJECT(tray_quit), "activate", G_CALLBACK(on_tray_quit_activate), NULL); | 661 | tray_icon_image = gtk_image_new_from_pixbuf (pixbuf); |
657 | g_signal_connect_swapped (G_OBJECT (eventbox), "button_press_event", G_CALLBACK (tray_clicked), trayContextMenu); | 662 | eventbox = gtk_event_box_new (); |
658 | tray_icon_tooltip = gtk_tooltips_new (); | 663 | gtk_container_add (GTK_CONTAINER (eventbox), tray_icon_image); |
659 | gtk_tooltips_set_tip (tray_icon_tooltip, GTK_WIDGET (tray_icon), _("GNU's p2p network"), NULL); | 664 | gtk_container_add (GTK_CONTAINER (tray_icon), eventbox); |
660 | gtk_widget_show (eventbox); | 665 | g_signal_connect (G_OBJECT (tray_quit), "activate", |
661 | gtk_widget_show_all (GTK_WIDGET (tray_icon)); | 666 | G_CALLBACK (on_tray_quit_activate), NULL); |
667 | g_signal_connect_swapped (G_OBJECT (eventbox), "button_press_event", | ||
668 | G_CALLBACK (tray_clicked), trayContextMenu); | ||
669 | tray_icon_tooltip = gtk_tooltips_new (); | ||
670 | gtk_tooltips_set_tip (tray_icon_tooltip, GTK_WIDGET (tray_icon), | ||
671 | _("GNU's p2p network"), NULL); | ||
672 | gtk_widget_show (eventbox); | ||
673 | gtk_widget_show_all (GTK_WIDGET (tray_icon)); | ||
662 | } | 674 | } |
663 | |||
664 | |||
diff --git a/src/core/eggtrayicon.h b/src/core/eggtrayicon.h index 55dc8664..33d687f1 100644 --- a/src/core/eggtrayicon.h +++ b/src/core/eggtrayicon.h | |||
@@ -47,6 +47,6 @@ | |||
47 | #ifndef __EGG_TRAY_ICON_H__ | 47 | #ifndef __EGG_TRAY_ICON_H__ |
48 | #define __EGG_TRAY_ICON_H__ | 48 | #define __EGG_TRAY_ICON_H__ |
49 | 49 | ||
50 | void initTrayIcon(); | 50 | void initTrayIcon (); |
51 | 51 | ||
52 | #endif /* __EGG_TRAY_ICON_H__ */ | 52 | #endif /* __EGG_TRAY_ICON_H__ */ |
diff --git a/src/core/main.c b/src/core/main.c index e6628cd0..1bf128c1 100644 --- a/src/core/main.c +++ b/src/core/main.c | |||
@@ -34,130 +34,125 @@ | |||
34 | static int debug_mode = NO; | 34 | static int debug_mode = NO; |
35 | #endif | 35 | #endif |
36 | 36 | ||
37 | static char * cfgFilename = DEFAULT_CLIENT_CONFIG_FILE; | 37 | static char *cfgFilename = DEFAULT_CLIENT_CONFIG_FILE; |
38 | 38 | ||
39 | /** | 39 | /** |
40 | * All gnunet-gtk command line options | 40 | * All gnunet-gtk command line options |
41 | */ | 41 | */ |
42 | static struct CommandLineOption gnunetgtkOptions[] = { | 42 | static struct CommandLineOption gnunetgtkOptions[] = { |
43 | COMMAND_LINE_OPTION_CFG_FILE(&cfgFilename), /* -c */ | 43 | COMMAND_LINE_OPTION_CFG_FILE (&cfgFilename), /* -c */ |
44 | #ifdef WINDOWS | 44 | #ifdef WINDOWS |
45 | { 'd', "debug", NULL, | 45 | {'d', "debug", NULL, |
46 | gettext_noop("run in debug mode"), | 46 | gettext_noop ("run in debug mode"), |
47 | 0, &gnunet_getopt_configure_set_one, &debug_mode }, | 47 | 0, &gnunet_getopt_configure_set_one, &debug_mode}, |
48 | #endif | 48 | #endif |
49 | COMMAND_LINE_OPTION_HELP(gettext_noop("GNUnet GTK user interface.")), /* -h */ | 49 | COMMAND_LINE_OPTION_HELP (gettext_noop ("GNUnet GTK user interface.")), /* -h */ |
50 | COMMAND_LINE_OPTION_HOSTNAME, /* -H */ | 50 | COMMAND_LINE_OPTION_HOSTNAME, /* -H */ |
51 | COMMAND_LINE_OPTION_LOGGING, /* -L */ | 51 | COMMAND_LINE_OPTION_LOGGING, /* -L */ |
52 | COMMAND_LINE_OPTION_VERSION(VERSION), /* -v */ | 52 | COMMAND_LINE_OPTION_VERSION (VERSION), /* -v */ |
53 | COMMAND_LINE_OPTION_VERBOSE, | 53 | COMMAND_LINE_OPTION_VERBOSE, |
54 | COMMAND_LINE_OPTION_END, | 54 | COMMAND_LINE_OPTION_END, |
55 | }; | 55 | }; |
56 | 56 | ||
57 | static void * shutdownCode(void * unused) { | 57 | static void * |
58 | shutdownPlugins(); | 58 | shutdownCode (void *unused) |
59 | { | ||
60 | shutdownPlugins (); | ||
59 | return NULL; | 61 | return NULL; |
60 | } | 62 | } |
61 | 63 | ||
62 | void gnunet_gtk_main_quit() { | 64 | void |
63 | GE_setDefaultContext(NULL); | 65 | gnunet_gtk_main_quit () |
64 | run_with_save_calls(&shutdownCode, | 66 | { |
65 | NULL); | 67 | GE_setDefaultContext (NULL); |
66 | gtk_main_quit(); | 68 | run_with_save_calls (&shutdownCode, NULL); |
69 | gtk_main_quit (); | ||
67 | } | 70 | } |
68 | 71 | ||
69 | #if 0 | 72 | #if 0 |
70 | static void customLog(const char * msg) { | 73 | static void |
71 | addLogEntry("%s", msg); | 74 | customLog (const char *msg) |
75 | { | ||
76 | addLogEntry ("%s", msg); | ||
72 | } | 77 | } |
73 | #endif | 78 | #endif |
74 | 79 | ||
75 | int main(int argc, | 80 | int |
76 | char * const * argv) { | 81 | main (int argc, char *const *argv) |
77 | GtkWidget * root; | 82 | { |
83 | GtkWidget *root; | ||
78 | int i; | 84 | int i; |
79 | struct GE_Context * ectx; | 85 | struct GE_Context *ectx; |
80 | struct GE_Context * my_ctx; | 86 | struct GE_Context *my_ctx; |
81 | struct GC_Configuration * cfg; | 87 | struct GC_Configuration *cfg; |
82 | char * log; | 88 | char *log; |
83 | GE_KIND mask; | 89 | GE_KIND mask; |
84 | #if ENABLE_NLS | 90 | #if ENABLE_NLS |
85 | char * path; | 91 | char *path; |
86 | #endif | 92 | #endif |
87 | 93 | ||
88 | #ifdef WINDOWS | 94 | #ifdef WINDOWS |
89 | SetCursor(LoadCursor(NULL, IDC_APPSTARTING)); | 95 | SetCursor (LoadCursor (NULL, IDC_APPSTARTING)); |
90 | #endif | 96 | #endif |
91 | 97 | ||
92 | g_thread_init(NULL); | 98 | g_thread_init (NULL); |
93 | gtk_init(&argc, (char***) &argv); | 99 | gtk_init (&argc, (char ***) &argv); |
94 | i = GNUNET_init(argc, | 100 | i = GNUNET_init (argc, |
95 | argv, | 101 | argv, |
96 | "gnunet-gtk", | 102 | "gnunet-gtk", &cfgFilename, gnunetgtkOptions, &ectx, &cfg); |
97 | &cfgFilename, | 103 | if (i == -1) |
98 | gnunetgtkOptions, | 104 | { |
99 | &ectx, | 105 | GNUNET_fini (ectx, cfg); |
100 | &cfg); | 106 | return -1; |
101 | if (i == -1) { | 107 | } |
102 | GNUNET_fini(ectx, cfg); | ||
103 | return -1; | ||
104 | } | ||
105 | #ifdef WINDOWS | 108 | #ifdef WINDOWS |
106 | if (!debug_mode) | 109 | if (!debug_mode) |
107 | FreeConsole(); | 110 | FreeConsole (); |
108 | #endif | 111 | #endif |
109 | 112 | ||
110 | #if ENABLE_NLS | 113 | #if ENABLE_NLS |
111 | setlocale (LC_ALL, ""); | 114 | setlocale (LC_ALL, ""); |
112 | path = os_get_installation_path(IPK_LOCALEDIR); | 115 | path = os_get_installation_path (IPK_LOCALEDIR); |
113 | BINDTEXTDOMAIN("gnunet-gtk", path); | 116 | BINDTEXTDOMAIN ("gnunet-gtk", path); |
114 | FREE(path); | 117 | FREE (path); |
115 | textdomain("gnunet-gtk"); | 118 | textdomain ("gnunet-gtk"); |
116 | bind_textdomain_codeset("GNUnet", "UTF-8"); | 119 | bind_textdomain_codeset ("GNUnet", "UTF-8"); |
117 | bind_textdomain_codeset("gnunet-gtk", "UTF-8"); | 120 | bind_textdomain_codeset ("gnunet-gtk", "UTF-8"); |
118 | #endif | 121 | #endif |
119 | initGNUnetGTKCommon(ectx, | 122 | initGNUnetGTKCommon (ectx, cfg, &gnunet_gtk_main_quit); |
120 | cfg, | ||
121 | &gnunet_gtk_main_quit); | ||
122 | /* configure GTK logging */ | 123 | /* configure GTK logging */ |
123 | GC_get_configuration_value_string(cfg, | 124 | GC_get_configuration_value_string (cfg, |
124 | "LOGGING", | 125 | "LOGGING", |
125 | "USER-LEVEL", | 126 | "USER-LEVEL", "WARNING", &log); |
126 | "WARNING", | 127 | mask = GE_getKIND (log); |
127 | &log); | 128 | FREE (log); |
128 | mask = GE_getKIND(log); | 129 | mask |= mask - 1; /* set all bits... */ |
129 | FREE(log); | ||
130 | mask |= mask-1; /* set all bits... */ | ||
131 | mask |= GE_USER | GE_BULK | GE_IMMEDIATE; | 130 | mask |= GE_USER | GE_BULK | GE_IMMEDIATE; |
132 | if (YES == GC_get_configuration_value_yesno(cfg, | 131 | if (YES == GC_get_configuration_value_yesno (cfg, |
133 | "LOGGING", | 132 | "LOGGING", "DEVELOPER", NO)) |
134 | "DEVELOPER", | ||
135 | NO)) | ||
136 | mask |= GE_DEVELOPER | GE_REQUEST; | 133 | mask |= GE_DEVELOPER | GE_REQUEST; |
137 | my_ctx = createGtkLogger(mask); | 134 | my_ctx = createGtkLogger (mask); |
138 | GE_setDefaultContext(my_ctx); | 135 | GE_setDefaultContext (my_ctx); |
139 | root | 136 | root = glade_xml_get_widget (getMainXML (), "mainWindow"); |
140 | = glade_xml_get_widget(getMainXML(), | 137 | gtk_window_maximize (GTK_WINDOW (root)); |
141 | "mainWindow"); | ||
142 | gtk_window_maximize(GTK_WINDOW(root)); | ||
143 | #ifndef WINDOWS | 138 | #ifndef WINDOWS |
144 | initTrayIcon(); | 139 | initTrayIcon (); |
145 | #endif | 140 | #endif |
146 | gtk_widget_show(root); | 141 | gtk_widget_show (root); |
147 | 142 | ||
148 | /* start the event loop */ | 143 | /* start the event loop */ |
149 | gdk_threads_enter(); | 144 | gdk_threads_enter (); |
150 | 145 | ||
151 | #ifdef WINDOWS | 146 | #ifdef WINDOWS |
152 | SetCursor(LoadCursor(NULL, IDC_ARROW)); | 147 | SetCursor (LoadCursor (NULL, IDC_ARROW)); |
153 | #endif | 148 | #endif |
154 | 149 | ||
155 | gtk_main(); | 150 | gtk_main (); |
156 | gdk_threads_leave(); | 151 | gdk_threads_leave (); |
157 | GE_setDefaultContext(ectx); | 152 | GE_setDefaultContext (ectx); |
158 | GE_free_context(my_ctx); | 153 | GE_free_context (my_ctx); |
159 | doneGNUnetGTKCommon(); | 154 | doneGNUnetGTKCommon (); |
160 | GNUNET_fini(ectx, cfg); | 155 | GNUNET_fini (ectx, cfg); |
161 | return 0; | 156 | return 0; |
162 | } | 157 | } |
163 | 158 | ||
diff --git a/src/include/gnunetgtk_common.h b/src/include/gnunetgtk_common.h index 0b85e239..2fbde8f7 100644 --- a/src/include/gnunetgtk_common.h +++ b/src/include/gnunetgtk_common.h | |||
@@ -43,32 +43,29 @@ | |||
43 | #define DEBUG_END() | 43 | #define DEBUG_END() |
44 | #endif | 44 | #endif |
45 | 45 | ||
46 | void initGNUnetGTKCommon(struct GE_Context * ectx, | 46 | void initGNUnetGTKCommon (struct GE_Context *ectx, |
47 | struct GC_Configuration * cfg, | 47 | struct GC_Configuration *cfg, void *callback); |
48 | void * callback); | ||
49 | 48 | ||
50 | void shutdownPlugins(void); | 49 | void shutdownPlugins (void); |
51 | 50 | ||
52 | void doneGNUnetGTKCommon(void); | 51 | void doneGNUnetGTKCommon (void); |
53 | 52 | ||
54 | /** | 53 | /** |
55 | * Get the name of the main glade file for gnunet-gtk. | 54 | * Get the name of the main glade file for gnunet-gtk. |
56 | */ | 55 | */ |
57 | const char * getGladeFileName(void); | 56 | const char *getGladeFileName (void); |
58 | 57 | ||
59 | /** | 58 | /** |
60 | * Get the GladeXML for the main window of gnunet-gtk. | 59 | * Get the GladeXML for the main window of gnunet-gtk. |
61 | */ | 60 | */ |
62 | GladeXML * getMainXML(void); | 61 | GladeXML *getMainXML (void); |
63 | 62 | ||
64 | /** | 63 | /** |
65 | * Appends a message to the info window | 64 | * Appends a message to the info window |
66 | * @param doPopup if YES, the info window will | 65 | * @param doPopup if YES, the info window will |
67 | * be opened | 66 | * be opened |
68 | */ | 67 | */ |
69 | void infoMessage(int doPopup, | 68 | void infoMessage (int doPopup, const char *format, ...); |
70 | const char * format, | ||
71 | ...); | ||
72 | 69 | ||
73 | /** | 70 | /** |
74 | * Appends a log entry to the info window | 71 | * Appends a log entry to the info window |
@@ -77,17 +74,16 @@ void infoMessage(int doPopup, | |||
77 | * | 74 | * |
78 | * @param txt the log entry | 75 | * @param txt the log entry |
79 | */ | 76 | */ |
80 | void addLogEntry(const char * txt, ...); | 77 | void addLogEntry (const char *txt, ...); |
78 | |||
79 | struct GE_Context *createGtkLogger (GE_KIND mask); | ||
81 | 80 | ||
82 | struct GE_Context * createGtkLogger(GE_KIND mask); | ||
83 | |||
84 | /** | 81 | /** |
85 | * Call a callback function from the mainloop/main thread ("SaveCall"). | 82 | * Call a callback function from the mainloop/main thread ("SaveCall"). |
86 | * Since GTK doesn't work with multi-threaded applications under Windows, | 83 | * Since GTK doesn't work with multi-threaded applications under Windows, |
87 | * all GTK operations have to be done in the main thread | 84 | * all GTK operations have to be done in the main thread |
88 | */ | 85 | */ |
89 | void * gtkSaveCall(PThreadMain func, | 86 | void *gtkSaveCall (PThreadMain func, void *arg); |
90 | void * arg); | ||
91 | 87 | ||
92 | /** | 88 | /** |
93 | * Run the given "cb" function and save calls | 89 | * Run the given "cb" function and save calls |
@@ -95,15 +91,14 @@ void * gtkSaveCall(PThreadMain func, | |||
95 | * keep save calls going while something else | 91 | * keep save calls going while something else |
96 | * happens). | 92 | * happens). |
97 | */ | 93 | */ |
98 | void * run_with_save_calls(PThreadMain cb, | 94 | void *run_with_save_calls (PThreadMain cb, void *arg); |
99 | void * arg); | ||
100 | 95 | ||
101 | /** | 96 | /** |
102 | * Bind handlers defined by the various | 97 | * Bind handlers defined by the various |
103 | * plugins to the signals defined by the | 98 | * plugins to the signals defined by the |
104 | * Glade XML. | 99 | * Glade XML. |
105 | */ | 100 | */ |
106 | void connectGladeWithPlugins(GladeXML * xml); | 101 | void connectGladeWithPlugins (GladeXML * xml); |
107 | 102 | ||
108 | #define NOTIFY_LOW 0 | 103 | #define NOTIFY_LOW 0 |
109 | #define NOTIFY_NORMAL 1 | 104 | #define NOTIFY_NORMAL 1 |
@@ -112,30 +107,27 @@ void connectGladeWithPlugins(GladeXML * xml); | |||
112 | /** | 107 | /** |
113 | * Sends a message to libnotify | 108 | * Sends a message to libnotify |
114 | */ | 109 | */ |
115 | void gnunetgtk_notify(int type, | 110 | void gnunetgtk_notify (int type, const char *message, ...); |
116 | const char * message, | ||
117 | ...); | ||
118 | 111 | ||
119 | /** | 112 | /** |
120 | * Validate that a string is a Utf-8 string. | 113 | * Validate that a string is a Utf-8 string. |
121 | * If validation fails, msg is freed and a valid | 114 | * If validation fails, msg is freed and a valid |
122 | * Utf-8 string is returned. | 115 | * Utf-8 string is returned. |
123 | */ | 116 | */ |
124 | char * validate_utf8(char * msg); | 117 | char *validate_utf8 (char *msg); |
125 | 118 | ||
126 | /** | 119 | /** |
127 | * Gtk callback to save the main window state (tray icon use) | 120 | * Gtk callback to save the main window state (tray icon use) |
128 | */ | 121 | */ |
129 | void saveMainWindowState(GtkWidget *main_window, | 122 | void saveMainWindowState (GtkWidget * main_window, |
130 | GdkEventWindowState *event, | 123 | GdkEventWindowState * event, gpointer user_data); |
131 | gpointer user_data); | ||
132 | 124 | ||
133 | /** | 125 | /** |
134 | * Get the last main window state when restoring (tray icon use) | 126 | * Get the last main window state when restoring (tray icon use) |
135 | */ | 127 | */ |
136 | GdkWindowState getMainWindowState(void); | 128 | GdkWindowState getMainWindowState (void); |
137 | 129 | ||
138 | void gnunet_gtk_main_quit(void); | 130 | void gnunet_gtk_main_quit (void); |
139 | 131 | ||
140 | /** | 132 | /** |
141 | * Start gnunet-setup, asking for a password if needed | 133 | * Start gnunet-setup, asking for a password if needed |
@@ -149,20 +141,19 @@ gboolean startGNUnetSetup (gboolean run_wizard); | |||
149 | * except that modifications of the underlying model | 141 | * except that modifications of the underlying model |
150 | * during the iteration are tolerated. | 142 | * during the iteration are tolerated. |
151 | */ | 143 | */ |
152 | void ggc_tree_selection_selected_foreach(GtkTreeSelection *selection, | 144 | void ggc_tree_selection_selected_foreach (GtkTreeSelection * selection, |
153 | GtkTreeSelectionForeachFunc func, | 145 | GtkTreeSelectionForeachFunc func, |
154 | gpointer data); | 146 | gpointer data); |
155 | 147 | ||
156 | /** | 148 | /** |
157 | * Identical to "gtk_tree_model_foreach", | 149 | * Identical to "gtk_tree_model_foreach", |
158 | * except that modifications of the underlying model | 150 | * except that modifications of the underlying model |
159 | * during the iteration are tolerated. | 151 | * during the iteration are tolerated. |
160 | */ | 152 | */ |
161 | void ggc_tree_model_foreach(GtkTreeModel * model, | 153 | void ggc_tree_model_foreach (GtkTreeModel * model, |
162 | GtkTreeSelectionForeachFunc func, | 154 | GtkTreeSelectionForeachFunc func, gpointer data); |
163 | gpointer data); | ||
164 | 155 | ||
165 | 156 | ||
166 | struct CronManager * gnunet_gtk_get_cron(void); | 157 | struct CronManager *gnunet_gtk_get_cron (void); |
167 | 158 | ||
168 | #endif | 159 | #endif |
diff --git a/src/include/platform.h b/src/include/platform.h index 3958ae74..e93c60dc 100644 --- a/src/include/platform.h +++ b/src/include/platform.h | |||
@@ -54,27 +54,27 @@ | |||
54 | #define VERBOSE_STATS 0 | 54 | #define VERBOSE_STATS 0 |
55 | 55 | ||
56 | #ifdef CYGWIN | 56 | #ifdef CYGWIN |
57 | #include <sys/reent.h> | 57 | #include <sys/reent.h> |
58 | #define _REENT_ONLY | 58 | #define _REENT_ONLY |
59 | #endif | 59 | #endif |
60 | 60 | ||
61 | #include <pthread.h> | 61 | #include <pthread.h> |
62 | #ifdef CYGWIN | 62 | #ifdef CYGWIN |
63 | #undef _REENT_ONLY | 63 | #undef _REENT_ONLY |
64 | #endif | 64 | #endif |
65 | 65 | ||
66 | #ifdef _MSC_VER | 66 | #ifdef _MSC_VER |
67 | #include <Winsock2.h> | 67 | #include <Winsock2.h> |
68 | #else | 68 | #else |
69 | #ifndef MINGW | 69 | #ifndef MINGW |
70 | #include <netdb.h> | 70 | #include <netdb.h> |
71 | #include <sys/socket.h> | 71 | #include <sys/socket.h> |
72 | #include <netinet/in.h> | 72 | #include <netinet/in.h> |
73 | #include <arpa/inet.h> | 73 | #include <arpa/inet.h> |
74 | #include <netinet/tcp.h> | 74 | #include <netinet/tcp.h> |
75 | #include <netinet/in.h> | 75 | #include <netinet/in.h> |
76 | #include <pwd.h> | 76 | #include <pwd.h> |
77 | #include <sys/ioctl.h> | 77 | #include <sys/ioctl.h> |
78 | #endif | 78 | #endif |
79 | #endif | 79 | #endif |
80 | 80 | ||
@@ -83,47 +83,47 @@ | |||
83 | #include <stdlib.h> | 83 | #include <stdlib.h> |
84 | #include <stdarg.h> | 84 | #include <stdarg.h> |
85 | #ifndef _MSC_VER | 85 | #ifndef _MSC_VER |
86 | #include <ltdl.h> /* KLB_FIX */ | 86 | #include <ltdl.h> /* KLB_FIX */ |
87 | #endif | 87 | #endif |
88 | #include <errno.h> | 88 | #include <errno.h> |
89 | #include <signal.h> | 89 | #include <signal.h> |
90 | #ifndef _MSC_VER | 90 | #ifndef _MSC_VER |
91 | #include <unistd.h> /* KLB_FIX */ | 91 | #include <unistd.h> /* KLB_FIX */ |
92 | #endif | 92 | #endif |
93 | #include <sys/stat.h> | 93 | #include <sys/stat.h> |
94 | #include <sys/types.h> | 94 | #include <sys/types.h> |
95 | #ifndef _MSC_VER | 95 | #ifndef _MSC_VER |
96 | #include <dirent.h> /* KLB_FIX */ | 96 | #include <dirent.h> /* KLB_FIX */ |
97 | #endif | 97 | #endif |
98 | #include <fcntl.h> | 98 | #include <fcntl.h> |
99 | #include <math.h> | 99 | #include <math.h> |
100 | 100 | ||
101 | #if TIME_WITH_SYS_TIME | 101 | #if TIME_WITH_SYS_TIME |
102 | #include <sys/time.h> | 102 | #include <sys/time.h> |
103 | #include <time.h> | 103 | #include <time.h> |
104 | #else | 104 | #else |
105 | #if HAVE_SYS_TIME_H | 105 | #if HAVE_SYS_TIME_H |
106 | #include <sys/time.h> | 106 | #include <sys/time.h> |
107 | #else | 107 | #else |
108 | #include <time.h> | 108 | #include <time.h> |
109 | #endif | 109 | #endif |
110 | #endif | 110 | #endif |
111 | 111 | ||
112 | /* if we have both openssl & libgcrypt, stick | 112 | /* if we have both openssl & libgcrypt, stick |
113 | to openssl for now (who has the obscure | 113 | to openssl for now (who has the obscure |
114 | libgcrypt CVS version that works for us!?...) */ | 114 | libgcrypt CVS version that works for us!?...) */ |
115 | #if USE_OPENSSL | 115 | #if USE_OPENSSL |
116 | #if USE_GCRYPT | 116 | #if USE_GCRYPT |
117 | #undef USE_GCRYPT | 117 | #undef USE_GCRYPT |
118 | #define USE_GCRYPT 0 | 118 | #define USE_GCRYPT 0 |
119 | #endif | 119 | #endif |
120 | #endif | 120 | #endif |
121 | 121 | ||
122 | #ifdef SOMEBSD | 122 | #ifdef SOMEBSD |
123 | #include <net/if.h> | 123 | #include <net/if.h> |
124 | #endif | 124 | #endif |
125 | #ifdef FREEBSD | 125 | #ifdef FREEBSD |
126 | #include <semaphore.h> | 126 | #include <semaphore.h> |
127 | #endif | 127 | #endif |
128 | #ifdef OSX | 128 | #ifdef OSX |
129 | #include <semaphore.h> | 129 | #include <semaphore.h> |
@@ -153,9 +153,9 @@ | |||
153 | 153 | ||
154 | 154 | ||
155 | #ifdef CYGWIN | 155 | #ifdef CYGWIN |
156 | #define SIOCGIFCONF _IOW('s', 100, struct ifconf) /* get if list */ | 156 | #define SIOCGIFCONF _IOW('s', 100, struct ifconf) /* get if list */ |
157 | #define SIOCGIFFLAGS _IOW('s', 101, struct ifreq) /* Get if flags */ | 157 | #define SIOCGIFFLAGS _IOW('s', 101, struct ifreq) /* Get if flags */ |
158 | #define SIOCGIFADDR _IOW('s', 102, struct ifreq) /* Get if addr */ | 158 | #define SIOCGIFADDR _IOW('s', 102, struct ifreq) /* Get if addr */ |
159 | #endif | 159 | #endif |
160 | 160 | ||
161 | #ifndef MINGW | 161 | #ifndef MINGW |
@@ -163,15 +163,15 @@ | |||
163 | #endif | 163 | #endif |
164 | 164 | ||
165 | #ifdef OSX | 165 | #ifdef OSX |
166 | #define socklen_t unsigned int | 166 | #define socklen_t unsigned int |
167 | #endif | 167 | #endif |
168 | 168 | ||
169 | #if !HAVE_ATOLL | 169 | #if !HAVE_ATOLL |
170 | long long atoll(const char *nptr); | 170 | long long atoll (const char *nptr); |
171 | #endif | 171 | #endif |
172 | 172 | ||
173 | #if ENABLE_NLS | 173 | #if ENABLE_NLS |
174 | #include "langinfo.h" | 174 | #include "langinfo.h" |
175 | #endif | 175 | #endif |
176 | 176 | ||
177 | #include <GNUnet/gnunet_util.h> | 177 | #include <GNUnet/gnunet_util.h> |
diff --git a/src/include/plibc.h b/src/include/plibc.h index 7118c69d..2178dc76 100644 --- a/src/include/plibc.h +++ b/src/include/plibc.h | |||
@@ -29,17 +29,18 @@ | |||
29 | #define _PLIBC_H_ | 29 | #define _PLIBC_H_ |
30 | 30 | ||
31 | #ifndef SIGALRM | 31 | #ifndef SIGALRM |
32 | #define SIGALRM 14 | 32 | #define SIGALRM 14 |
33 | #endif | 33 | #endif |
34 | 34 | ||
35 | #ifdef __cplusplus | 35 | #ifdef __cplusplus |
36 | extern "C" { | 36 | extern "C" |
37 | { | ||
37 | #endif | 38 | #endif |
38 | 39 | ||
39 | #ifdef WINDOWS | 40 | #ifdef WINDOWS |
40 | 41 | ||
41 | #if ENABLE_NLS | 42 | #if ENABLE_NLS |
42 | #include "langinfo.h" | 43 | #include "langinfo.h" |
43 | #endif | 44 | #endif |
44 | 45 | ||
45 | #include <windows.h> | 46 | #include <windows.h> |
@@ -71,109 +72,109 @@ extern "C" { | |||
71 | #define int32_t long | 72 | #define int32_t long |
72 | 73 | ||
73 | #ifndef pid_t | 74 | #ifndef pid_t |
74 | #define pid_t int | 75 | #define pid_t int |
75 | #endif | 76 | #endif |
76 | 77 | ||
77 | #ifndef WEXITSTATUS | 78 | #ifndef WEXITSTATUS |
78 | #define WEXITSTATUS(status) (((status) & 0xff00) >> 8) | 79 | #define WEXITSTATUS(status) (((status) & 0xff00) >> 8) |
79 | #endif | 80 | #endif |
80 | 81 | ||
81 | /* Thanks to the Cygwin project */ | 82 | /* Thanks to the Cygwin project */ |
82 | #define ENOCSI 43 /* No CSI structure available */ | 83 | #define ENOCSI 43 /* No CSI structure available */ |
83 | #define EL2HLT 44 /* Level 2 halted */ | 84 | #define EL2HLT 44 /* Level 2 halted */ |
84 | #ifndef EDEADLK | 85 | #ifndef EDEADLK |
85 | #define EDEADLK 45 /* Deadlock condition */ | 86 | #define EDEADLK 45 /* Deadlock condition */ |
86 | #endif | 87 | #endif |
87 | #ifndef ENOLCK | 88 | #ifndef ENOLCK |
88 | #define ENOLCK 46 /* No record locks available */ | 89 | #define ENOLCK 46 /* No record locks available */ |
89 | #endif | 90 | #endif |
90 | #define EBADE 50 /* Invalid exchange */ | 91 | #define EBADE 50 /* Invalid exchange */ |
91 | #define EBADR 51 /* Invalid request descriptor */ | 92 | #define EBADR 51 /* Invalid request descriptor */ |
92 | #define EXFULL 52 /* Exchange full */ | 93 | #define EXFULL 52 /* Exchange full */ |
93 | #define ENOANO 53 /* No anode */ | 94 | #define ENOANO 53 /* No anode */ |
94 | #define EBADRQC 54 /* Invalid request code */ | 95 | #define EBADRQC 54 /* Invalid request code */ |
95 | #define EBADSLT 55 /* Invalid slot */ | 96 | #define EBADSLT 55 /* Invalid slot */ |
96 | #ifndef EDEADLOCK | 97 | #ifndef EDEADLOCK |
97 | #define EDEADLOCK EDEADLK /* File locking deadlock error */ | 98 | #define EDEADLOCK EDEADLK /* File locking deadlock error */ |
98 | #endif | 99 | #endif |
99 | #define EBFONT 57 /* Bad font file fmt */ | 100 | #define EBFONT 57 /* Bad font file fmt */ |
100 | #define ENOSTR 60 /* Device not a stream */ | 101 | #define ENOSTR 60 /* Device not a stream */ |
101 | #define ENODATA 61 /* No data (for no delay io) */ | 102 | #define ENODATA 61 /* No data (for no delay io) */ |
102 | #define ETIME 62 /* Timer expired */ | 103 | #define ETIME 62 /* Timer expired */ |
103 | #define ENOSR 63 /* Out of streams resources */ | 104 | #define ENOSR 63 /* Out of streams resources */ |
104 | #define ENONET 64 /* Machine is not on the network */ | 105 | #define ENONET 64 /* Machine is not on the network */ |
105 | #define ENOPKG 65 /* Package not installed */ | 106 | #define ENOPKG 65 /* Package not installed */ |
106 | #define EREMOTE 66 /* The object is remote */ | 107 | #define EREMOTE 66 /* The object is remote */ |
107 | #define ENOLINK 67 /* The link has been severed */ | 108 | #define ENOLINK 67 /* The link has been severed */ |
108 | #define EADV 68 /* Advertise error */ | 109 | #define EADV 68 /* Advertise error */ |
109 | #define ESRMNT 69 /* Srmount error */ | 110 | #define ESRMNT 69 /* Srmount error */ |
110 | #define ECOMM 70 /* Communication error on send */ | 111 | #define ECOMM 70 /* Communication error on send */ |
111 | #define EPROTO 71 /* Protocol error */ | 112 | #define EPROTO 71 /* Protocol error */ |
112 | #define EMULTIHOP 74 /* Multihop attempted */ | 113 | #define EMULTIHOP 74 /* Multihop attempted */ |
113 | #define ELBIN 75 /* Inode is remote (not really error) */ | 114 | #define ELBIN 75 /* Inode is remote (not really error) */ |
114 | #define EDOTDOT 76 /* Cross mount point (not really error) */ | 115 | #define EDOTDOT 76 /* Cross mount point (not really error) */ |
115 | #define EBADMSG 77 /* Trying to read unreadable message */ | 116 | #define EBADMSG 77 /* Trying to read unreadable message */ |
116 | #define ENOTUNIQ 80 /* Given log. name not unique */ | 117 | #define ENOTUNIQ 80 /* Given log. name not unique */ |
117 | #define EBADFD 81 /* f.d. invalid for this operation */ | 118 | #define EBADFD 81 /* f.d. invalid for this operation */ |
118 | #define EREMCHG 82 /* Remote address changed */ | 119 | #define EREMCHG 82 /* Remote address changed */ |
119 | #define ELIBACC 83 /* Can't access a needed shared lib */ | 120 | #define ELIBACC 83 /* Can't access a needed shared lib */ |
120 | #define ELIBBAD 84 /* Accessing a corrupted shared lib */ | 121 | #define ELIBBAD 84 /* Accessing a corrupted shared lib */ |
121 | #define ELIBSCN 85 /* .lib section in a.out corrupted */ | 122 | #define ELIBSCN 85 /* .lib section in a.out corrupted */ |
122 | #define ELIBMAX 86 /* Attempting to link in too many libs */ | 123 | #define ELIBMAX 86 /* Attempting to link in too many libs */ |
123 | #define ELIBEXEC 87 /* Attempting to exec a shared library */ | 124 | #define ELIBEXEC 87 /* Attempting to exec a shared library */ |
124 | #ifndef ENOSYS | 125 | #ifndef ENOSYS |
125 | #define ENOSYS 88 /* Function not implemented */ | 126 | #define ENOSYS 88 /* Function not implemented */ |
126 | #endif | 127 | #endif |
127 | #define ENMFILE 89 /* No more files */ | 128 | #define ENMFILE 89 /* No more files */ |
128 | #ifndef ENOTEMPTY | 129 | #ifndef ENOTEMPTY |
129 | #define ENOTEMPTY 90 /* Directory not empty */ | 130 | #define ENOTEMPTY 90 /* Directory not empty */ |
130 | #endif | 131 | #endif |
131 | #ifndef ENAMETOOLONG | 132 | #ifndef ENAMETOOLONG |
132 | #define ENAMETOOLONG 91 /* File or path name too long */ | 133 | #define ENAMETOOLONG 91 /* File or path name too long */ |
133 | #endif | 134 | #endif |
134 | #define ELOOP 92 /* Too many symbolic links */ | 135 | #define ELOOP 92 /* Too many symbolic links */ |
135 | #define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */ | 136 | #define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */ |
136 | #define EPFNOSUPPORT 96 /* Protocol family not supported */ | 137 | #define EPFNOSUPPORT 96 /* Protocol family not supported */ |
137 | #define ECONNRESET 104 /* Connection reset by peer */ | 138 | #define ECONNRESET 104 /* Connection reset by peer */ |
138 | #define ENOBUFS 105 /* No buffer space available */ | 139 | #define ENOBUFS 105 /* No buffer space available */ |
139 | #define EAFNOSUPPORT 106 /* Address family not supported by protocol family */ | 140 | #define EAFNOSUPPORT 106 /* Address family not supported by protocol family */ |
140 | #define EPROTOTYPE 107 /* Protocol wrong type for socket */ | 141 | #define EPROTOTYPE 107 /* Protocol wrong type for socket */ |
141 | #define ENOTSOCK 108 /* Socket operation on non-socket */ | 142 | #define ENOTSOCK 108 /* Socket operation on non-socket */ |
142 | #define ENOPROTOOPT 109 /* Protocol not available */ | 143 | #define ENOPROTOOPT 109 /* Protocol not available */ |
143 | #define ESHUTDOWN 110 /* Can't send after socket shutdown */ | 144 | #define ESHUTDOWN 110 /* Can't send after socket shutdown */ |
144 | #define ECONNREFUSED 111 /* Connection refused */ | 145 | #define ECONNREFUSED 111 /* Connection refused */ |
145 | #define EADDRINUSE 112 /* Address already in use */ | 146 | #define EADDRINUSE 112 /* Address already in use */ |
146 | #define ECONNABORTED 113 /* Connection aborted */ | 147 | #define ECONNABORTED 113 /* Connection aborted */ |
147 | #define ENETUNREACH 114 /* Network is unreachable */ | 148 | #define ENETUNREACH 114 /* Network is unreachable */ |
148 | #define ENETDOWN 115 /* Network interface is not configured */ | 149 | #define ENETDOWN 115 /* Network interface is not configured */ |
149 | #ifndef ETIMEDOUT | 150 | #ifndef ETIMEDOUT |
150 | #define ETIMEDOUT 116 /* Connection timed out */ | 151 | #define ETIMEDOUT 116 /* Connection timed out */ |
151 | #endif | 152 | #endif |
152 | #define EHOSTDOWN 117 /* Host is down */ | 153 | #define EHOSTDOWN 117 /* Host is down */ |
153 | #define EHOSTUNREACH 118 /* Host is unreachable */ | 154 | #define EHOSTUNREACH 118 /* Host is unreachable */ |
154 | #define EINPROGRESS 119 /* Connection already in progress */ | 155 | #define EINPROGRESS 119 /* Connection already in progress */ |
155 | #define EALREADY 120 /* Socket already connected */ | 156 | #define EALREADY 120 /* Socket already connected */ |
156 | #define EDESTADDRREQ 121 /* Destination address required */ | 157 | #define EDESTADDRREQ 121 /* Destination address required */ |
157 | #define EMSGSIZE 122 /* Message too long */ | 158 | #define EMSGSIZE 122 /* Message too long */ |
158 | #define EPROTONOSUPPORT 123 /* Unknown protocol */ | 159 | #define EPROTONOSUPPORT 123 /* Unknown protocol */ |
159 | #define ESOCKTNOSUPPORT 124 /* Socket type not supported */ | 160 | #define ESOCKTNOSUPPORT 124 /* Socket type not supported */ |
160 | #define EADDRNOTAVAIL 125 /* Address not available */ | 161 | #define EADDRNOTAVAIL 125 /* Address not available */ |
161 | #define ENETRESET 126 /* Connection aborted by network */ | 162 | #define ENETRESET 126 /* Connection aborted by network */ |
162 | #define EISCONN 127 /* Socket is already connected */ | 163 | #define EISCONN 127 /* Socket is already connected */ |
163 | #define ENOTCONN 128 /* Socket is not connected */ | 164 | #define ENOTCONN 128 /* Socket is not connected */ |
164 | #define ETOOMANYREFS 129 /* Too many references: cannot splice */ | 165 | #define ETOOMANYREFS 129 /* Too many references: cannot splice */ |
165 | #define EPROCLIM 130 /* Too many processes */ | 166 | #define EPROCLIM 130 /* Too many processes */ |
166 | #define EUSERS 131 /* Too many users */ | 167 | #define EUSERS 131 /* Too many users */ |
167 | #define EDQUOT 132 /* Disk quota exceeded */ | 168 | #define EDQUOT 132 /* Disk quota exceeded */ |
168 | #define ESTALE 133 /* Unknown error */ | 169 | #define ESTALE 133 /* Unknown error */ |
169 | #ifndef ENOTSUP | 170 | #ifndef ENOTSUP |
170 | #define ENOTSUP 134 /* Not supported */ | 171 | #define ENOTSUP 134 /* Not supported */ |
171 | #endif | 172 | #endif |
172 | #define ENOMEDIUM 135 /* No medium (in tape drive) */ | 173 | #define ENOMEDIUM 135 /* No medium (in tape drive) */ |
173 | #define ENOSHARE 136 /* No such host or network path */ | 174 | #define ENOSHARE 136 /* No such host or network path */ |
174 | #define ECASECLASH 137 /* Filename exists with different case */ | 175 | #define ECASECLASH 137 /* Filename exists with different case */ |
175 | #define EWOULDBLOCK EAGAIN /* Operation would block */ | 176 | #define EWOULDBLOCK EAGAIN /* Operation would block */ |
176 | #define EOVERFLOW 139 /* Value too large for defined data type */ | 177 | #define EOVERFLOW 139 /* Value too large for defined data type */ |
177 | 178 | ||
178 | #undef HOST_NOT_FOUND | 179 | #undef HOST_NOT_FOUND |
179 | #define HOST_NOT_FOUND 1 | 180 | #define HOST_NOT_FOUND 1 |
@@ -187,65 +188,65 @@ extern "C" { | |||
187 | #define PROT_READ 0x1 | 188 | #define PROT_READ 0x1 |
188 | #define PROT_WRITE 0x2 | 189 | #define PROT_WRITE 0x2 |
189 | #define MAP_SHARED 0x1 | 190 | #define MAP_SHARED 0x1 |
190 | #define MAP_PRIVATE 0x2 /* unsupported */ | 191 | #define MAP_PRIVATE 0x2 /* unsupported */ |
191 | #define MAP_FIXED 0x10 | 192 | #define MAP_FIXED 0x10 |
192 | #define MAP_FAILED ((void *)-1) | 193 | #define MAP_FAILED ((void *)-1) |
193 | 194 | ||
194 | struct statfs | 195 | struct statfs |
195 | { | 196 | { |
196 | long f_type; /* type of filesystem (see below) */ | 197 | long f_type; /* type of filesystem (see below) */ |
197 | long f_bsize; /* optimal transfer block size */ | 198 | long f_bsize; /* optimal transfer block size */ |
198 | long f_blocks; /* total data blocks in file system */ | 199 | long f_blocks; /* total data blocks in file system */ |
199 | long f_bfree; /* free blocks in fs */ | 200 | long f_bfree; /* free blocks in fs */ |
200 | long f_bavail; /* free blocks avail to non-superuser */ | 201 | long f_bavail; /* free blocks avail to non-superuser */ |
201 | long f_files; /* total file nodes in file system */ | 202 | long f_files; /* total file nodes in file system */ |
202 | long f_ffree; /* free file nodes in fs */ | 203 | long f_ffree; /* free file nodes in fs */ |
203 | long f_fsid; /* file system id */ | 204 | long f_fsid; /* file system id */ |
204 | long f_namelen; /* maximum length of filenames */ | 205 | long f_namelen; /* maximum length of filenames */ |
205 | long f_spare[6]; /* spare for later */ | 206 | long f_spare[6]; /* spare for later */ |
206 | }; | 207 | }; |
207 | 208 | ||
208 | /* Taken from the Wine project <http://www.winehq.org> | 209 | /* Taken from the Wine project <http://www.winehq.org> |
209 | /wine/include/winternl.h */ | 210 | /wine/include/winternl.h */ |
210 | enum SYSTEM_INFORMATION_CLASS | 211 | enum SYSTEM_INFORMATION_CLASS |
211 | { | 212 | { |
212 | SystemBasicInformation = 0, | 213 | SystemBasicInformation = 0, |
213 | Unknown1, | 214 | Unknown1, |
214 | SystemPerformanceInformation = 2, | 215 | SystemPerformanceInformation = 2, |
215 | SystemTimeOfDayInformation = 3, /* was SystemTimeInformation */ | 216 | SystemTimeOfDayInformation = 3, /* was SystemTimeInformation */ |
216 | Unknown4, | 217 | Unknown4, |
217 | SystemProcessInformation = 5, | 218 | SystemProcessInformation = 5, |
218 | Unknown6, | 219 | Unknown6, |
219 | Unknown7, | 220 | Unknown7, |
220 | SystemProcessorPerformanceInformation = 8, | 221 | SystemProcessorPerformanceInformation = 8, |
221 | Unknown9, | 222 | Unknown9, |
222 | Unknown10, | 223 | Unknown10, |
223 | SystemDriverInformation, | 224 | SystemDriverInformation, |
224 | Unknown12, | 225 | Unknown12, |
225 | Unknown13, | 226 | Unknown13, |
226 | Unknown14, | 227 | Unknown14, |
227 | Unknown15, | 228 | Unknown15, |
228 | SystemHandleList, | 229 | SystemHandleList, |
229 | Unknown17, | 230 | Unknown17, |
230 | Unknown18, | 231 | Unknown18, |
231 | Unknown19, | 232 | Unknown19, |
232 | Unknown20, | 233 | Unknown20, |
233 | SystemCacheInformation, | 234 | SystemCacheInformation, |
234 | Unknown22, | 235 | Unknown22, |
235 | SystemInterruptInformation = 23, | 236 | SystemInterruptInformation = 23, |
236 | SystemExceptionInformation = 33, | 237 | SystemExceptionInformation = 33, |
237 | SystemRegistryQuotaInformation = 37, | 238 | SystemRegistryQuotaInformation = 37, |
238 | SystemLookasideInformation = 45 | 239 | SystemLookasideInformation = 45 |
239 | }; | 240 | }; |
240 | 241 | ||
241 | typedef struct | 242 | typedef struct |
242 | { | 243 | { |
243 | LARGE_INTEGER IdleTime; | 244 | LARGE_INTEGER IdleTime; |
244 | LARGE_INTEGER KernelTime; | 245 | LARGE_INTEGER KernelTime; |
245 | LARGE_INTEGER UserTime; | 246 | LARGE_INTEGER UserTime; |
246 | LARGE_INTEGER Reserved1[2]; | 247 | LARGE_INTEGER Reserved1[2]; |
247 | ULONG Reserved2; | 248 | ULONG Reserved2; |
248 | } SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION; | 249 | } SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION; |
249 | 250 | ||
250 | #define sleep(secs) (Sleep(secs * 1000)) | 251 | #define sleep(secs) (Sleep(secs * 1000)) |
251 | 252 | ||
@@ -262,11 +263,11 @@ typedef struct | |||
262 | #define SHUT_RDWR SD_BOTH | 263 | #define SHUT_RDWR SD_BOTH |
263 | 264 | ||
264 | /* Operations for flock() */ | 265 | /* Operations for flock() */ |
265 | #define LOCK_SH 1 /* shared lock */ | 266 | #define LOCK_SH 1 /* shared lock */ |
266 | #define LOCK_EX 2 /* exclusive lock */ | 267 | #define LOCK_EX 2 /* exclusive lock */ |
267 | #define LOCK_NB 4 /* or'd with one of the above to prevent | 268 | #define LOCK_NB 4 /* or'd with one of the above to prevent |
268 | blocking */ | 269 | blocking */ |
269 | #define LOCK_UN 8 /* remove lock */ | 270 | #define LOCK_UN 8 /* remove lock */ |
270 | 271 | ||
271 | /* Not supported under MinGW */ | 272 | /* Not supported under MinGW */ |
272 | #define S_IRGRP 0 | 273 | #define S_IRGRP 0 |
@@ -288,258 +289,259 @@ typedef struct | |||
288 | */ | 289 | */ |
289 | #define index(s, c) strchr(s, c) | 290 | #define index(s, c) strchr(s, c) |
290 | 291 | ||
291 | BOOL _plibc_CreateShortcut(const char *pszSrc, const char *pszDest); | 292 | BOOL _plibc_CreateShortcut (const char *pszSrc, const char *pszDest); |
292 | BOOL _plibc_DereferenceShortcut(char *pszShortcut); | 293 | BOOL _plibc_DereferenceShortcut (char *pszShortcut); |
293 | char *plibc_ChooseDir(char *pszTitle, unsigned long ulFlags); | 294 | char *plibc_ChooseDir (char *pszTitle, unsigned long ulFlags); |
294 | char *plibc_ChooseFile(char *pszTitle, unsigned long ulFlags); | 295 | char *plibc_ChooseFile (char *pszTitle, unsigned long ulFlags); |
295 | long QueryRegistry(HKEY hMainKey, char *pszKey, char *pszSubKey, | 296 | long QueryRegistry (HKEY hMainKey, char *pszKey, char *pszSubKey, |
296 | char *pszBuffer, long *pdLength); | 297 | char *pszBuffer, long *pdLength); |
297 | 298 | ||
298 | BOOL __win_IsHandleMarkedAsBlocking(SOCKET hHandle); | 299 | BOOL __win_IsHandleMarkedAsBlocking (SOCKET hHandle); |
299 | void __win_SetHandleBlockingMode(SOCKET s, BOOL bBlocking); | 300 | void __win_SetHandleBlockingMode (SOCKET s, BOOL bBlocking); |
300 | void __win_DiscardHandleBlockingMode(SOCKET s); | 301 | void __win_DiscardHandleBlockingMode (SOCKET s); |
301 | int _win_isSocketValid(int s); | 302 | int _win_isSocketValid (int s); |
302 | int plibc_conv_to_win_path(const char *pszUnix, char *pszWindows); | 303 | int plibc_conv_to_win_path (const char *pszUnix, char *pszWindows); |
303 | 304 | ||
304 | typedef void (*TPanicProc) (int, char *); | 305 | typedef void (*TPanicProc) (int, char *); |
305 | void plibc_set_panic_proc(TPanicProc proc); | 306 | void plibc_set_panic_proc (TPanicProc proc); |
306 | 307 | ||
307 | int flock(int fd, int operation); | 308 | int flock (int fd, int operation); |
308 | int fsync(int fildes); | 309 | int fsync (int fildes); |
309 | int inet_pton(int af, const char *src, void *dst); | 310 | int inet_pton (int af, const char *src, void *dst); |
310 | int inet_pton4(const char *src, u_char *dst, int pton); | 311 | int inet_pton4 (const char *src, u_char * dst, int pton); |
311 | #if USE_IPV6 | 312 | #if USE_IPV6 |
312 | int inet_pton6(const char *src, u_char *dst); | 313 | int inet_pton6 (const char *src, u_char * dst); |
313 | #endif | 314 | #endif |
314 | int truncate(const char *fname, int distance); | 315 | int truncate (const char *fname, int distance); |
315 | int statfs(const char *path, struct statfs *buf); | 316 | int statfs (const char *path, struct statfs *buf); |
316 | const char *hstrerror(int err); | 317 | const char *hstrerror (int err); |
317 | void gettimeofday(struct timeval *tp, void *tzp); | 318 | void gettimeofday (struct timeval *tp, void *tzp); |
318 | int mkstemp(char *tmplate); | 319 | int mkstemp (char *tmplate); |
319 | char *strptime (const char *buf, const char *format, struct tm *tm); | 320 | char *strptime (const char *buf, const char *format, struct tm *tm); |
320 | char *ctime(const time_t *clock); | 321 | char *ctime (const time_t * clock); |
321 | char *ctime_r(const time_t *clock, char *buf); | 322 | char *ctime_r (const time_t * clock, char *buf); |
322 | int plibc_init(char *pszOrg, char *pszApp); | 323 | int plibc_init (char *pszOrg, char *pszApp); |
323 | void plibc_shutdown(); | 324 | void plibc_shutdown (); |
324 | int plibc_conv_to_win_path_ex(const char *pszUnix, char *pszWindows, int derefLinks); | 325 | int plibc_conv_to_win_path_ex (const char *pszUnix, char *pszWindows, |
325 | void _SetErrnoFromWinError(long lWinError, char *pszCaller, int iLine); | 326 | int derefLinks); |
326 | void SetErrnoFromWinsockError(long lWinError); | 327 | void _SetErrnoFromWinError (long lWinError, char *pszCaller, int iLine); |
327 | void SetHErrnoFromWinError(long lWinError); | 328 | void SetErrnoFromWinsockError (long lWinError); |
328 | void SetErrnoFromHRESULT(HRESULT hRes); | 329 | void SetHErrnoFromWinError (long lWinError); |
329 | FILE *_win_fopen(const char *filename, const char *mode); | 330 | void SetErrnoFromHRESULT (HRESULT hRes); |
330 | DIR *_win_opendir(const char *dirname); | 331 | FILE *_win_fopen (const char *filename, const char *mode); |
331 | int _win_open(const char *filename, int oflag, ...); | 332 | DIR *_win_opendir (const char *dirname); |
333 | int _win_open (const char *filename, int oflag, ...); | ||
332 | #ifdef ENABLE_NLS | 334 | #ifdef ENABLE_NLS |
333 | char *_win_bindtextdomain(const char *domainname, const char *dirname); | 335 | char *_win_bindtextdomain (const char *domainname, const char *dirname); |
334 | #endif | 336 | #endif |
335 | int _win_chdir(const char *path); | 337 | int _win_chdir (const char *path); |
336 | int _win_close(int fd); | 338 | int _win_close (int fd); |
337 | int _win_creat(const char *path, mode_t mode); | 339 | int _win_creat (const char *path, mode_t mode); |
338 | int _win_fstat(int handle, struct stat *buffer); | 340 | int _win_fstat (int handle, struct stat *buffer); |
339 | int _win_pipe(int *phandles); | 341 | int _win_pipe (int *phandles); |
340 | int _win_rmdir(const char *path); | 342 | int _win_rmdir (const char *path); |
341 | int _win_access( const char *path, int mode ); | 343 | int _win_access (const char *path, int mode); |
342 | int _win_chmod(const char *filename, int pmode); | 344 | int _win_chmod (const char *filename, int pmode); |
343 | char *realpath(const char *file_name, char *resolved_name); | 345 | char *realpath (const char *file_name, char *resolved_name); |
344 | long _win_random(void); | 346 | long _win_random (void); |
345 | int _win_remove(const char *path); | 347 | int _win_remove (const char *path); |
346 | int _win_rename(const char *oldname, const char *newname); | 348 | int _win_rename (const char *oldname, const char *newname); |
347 | int _win_stat(const char *path, struct stat *buffer); | 349 | int _win_stat (const char *path, struct stat *buffer); |
348 | int _win_unlink(const char *filename); | 350 | int _win_unlink (const char *filename); |
349 | int _win_write(int fildes, const void *buf, size_t nbyte); | 351 | int _win_write (int fildes, const void *buf, size_t nbyte); |
350 | int _win_read(int fildes, void *buf, size_t nbyte); | 352 | int _win_read (int fildes, void *buf, size_t nbyte); |
351 | size_t _win_fwrite(const void *buffer, size_t size, size_t count, FILE *stream); | 353 | size_t _win_fwrite (const void *buffer, size_t size, size_t count, |
352 | size_t _win_fread( void *buffer, size_t size, size_t count, FILE *stream ); | 354 | FILE * stream); |
353 | int _win_symlink(const char *path1, const char *path2); | 355 | size_t _win_fread (void *buffer, size_t size, size_t count, FILE * stream); |
354 | void *_win_mmap(void *start, size_t len, int access, int flags, int fd, | 356 | int _win_symlink (const char *path1, const char *path2); |
355 | unsigned long long offset); | 357 | void *_win_mmap (void *start, size_t len, int access, int flags, int fd, |
356 | int _win_munmap(void *start, size_t length); | 358 | unsigned long long offset); |
357 | int _win_lstat(const char *path, struct stat *buf); | 359 | int _win_munmap (void *start, size_t length); |
358 | int _win_readlink(const char *path, char *buf, size_t bufsize); | 360 | int _win_lstat (const char *path, struct stat *buf); |
359 | int _win_accept(SOCKET s, struct sockaddr *addr, int *addrlen); | 361 | int _win_readlink (const char *path, char *buf, size_t bufsize); |
360 | int _win_printf(const char *format,...); | 362 | int _win_accept (SOCKET s, struct sockaddr *addr, int *addrlen); |
361 | int _win_fprintf(FILE *f,const char *format,...); | 363 | int _win_printf (const char *format, ...); |
362 | int _win_vprintf(const char *format, va_list ap); | 364 | int _win_fprintf (FILE * f, const char *format, ...); |
363 | int _win_vfprintf(FILE *stream, const char *format, va_list arg_ptr); | 365 | int _win_vprintf (const char *format, va_list ap); |
364 | int _win_vsprintf(char *dest,const char *format, va_list arg_ptr); | 366 | int _win_vfprintf (FILE * stream, const char *format, va_list arg_ptr); |
365 | int _win_vsnprintf(char* str, size_t size, const char *format, va_list arg_ptr); | 367 | int _win_vsprintf (char *dest, const char *format, va_list arg_ptr); |
366 | int _win_snprintf(char *str,size_t size,const char *format,...); | 368 | int _win_vsnprintf (char *str, size_t size, const char *format, |
367 | int _win_sprintf(char *dest,const char *format,...); | 369 | va_list arg_ptr); |
368 | int _win_vsscanf(const char* str, const char* format, va_list arg_ptr); | 370 | int _win_snprintf (char *str, size_t size, const char *format, ...); |
369 | int _win_sscanf(const char *str, const char *format, ...); | 371 | int _win_sprintf (char *dest, const char *format, ...); |
370 | int _win_vfscanf(FILE *stream, const char *format, va_list arg_ptr); | 372 | int _win_vsscanf (const char *str, const char *format, va_list arg_ptr); |
371 | int _win_vscanf(const char *format, va_list arg_ptr); | 373 | int _win_sscanf (const char *str, const char *format, ...); |
372 | int _win_scanf(const char *format, ...); | 374 | int _win_vfscanf (FILE * stream, const char *format, va_list arg_ptr); |
373 | int _win_fscanf(FILE *stream, const char *format, ...); | 375 | int _win_vscanf (const char *format, va_list arg_ptr); |
374 | pid_t _win_waitpid(pid_t pid, int *stat_loc, int options); | 376 | int _win_scanf (const char *format, ...); |
375 | int _win_bind(SOCKET s, const struct sockaddr *name, int namelen); | 377 | int _win_fscanf (FILE * stream, const char *format, ...); |
376 | int _win_connect(SOCKET s,const struct sockaddr *name, int namelen); | 378 | pid_t _win_waitpid (pid_t pid, int *stat_loc, int options); |
377 | int _win_getpeername(SOCKET s, struct sockaddr *name, | 379 | int _win_bind (SOCKET s, const struct sockaddr *name, int namelen); |
378 | int *namelen); | 380 | int _win_connect (SOCKET s, const struct sockaddr *name, int namelen); |
379 | int _win_getsockname(SOCKET s, struct sockaddr *name, | 381 | int _win_getpeername (SOCKET s, struct sockaddr *name, int *namelen); |
380 | int *namelen); | 382 | int _win_getsockname (SOCKET s, struct sockaddr *name, int *namelen); |
381 | int _win_getsockopt(SOCKET s, int level, int optname, char *optval, | 383 | int _win_getsockopt (SOCKET s, int level, int optname, char *optval, |
382 | int *optlen); | 384 | int *optlen); |
383 | int _win_listen(SOCKET s, int backlog); | 385 | int _win_listen (SOCKET s, int backlog); |
384 | int _win_recv(SOCKET s, char *buf, int len, int flags); | 386 | int _win_recv (SOCKET s, char *buf, int len, int flags); |
385 | int _win_recvfrom(SOCKET s, void *buf, int len, int flags, | 387 | int _win_recvfrom (SOCKET s, void *buf, int len, int flags, |
386 | struct sockaddr *from, int *fromlen); | 388 | struct sockaddr *from, int *fromlen); |
387 | int _win_select(int max_fd, fd_set * rfds, fd_set * wfds, fd_set * efds, | 389 | int _win_select (int max_fd, fd_set * rfds, fd_set * wfds, fd_set * efds, |
388 | const struct timeval *tv); | 390 | const struct timeval *tv); |
389 | int _win_send(SOCKET s, const char *buf, int len, int flags); | 391 | int _win_send (SOCKET s, const char *buf, int len, int flags); |
390 | int _win_sendto(SOCKET s, const char *buf, int len, int flags, | 392 | int _win_sendto (SOCKET s, const char *buf, int len, int flags, |
391 | const struct sockaddr *to, int tolen); | 393 | const struct sockaddr *to, int tolen); |
392 | int _win_setsockopt(SOCKET s, int level, int optname, const void *optval, | 394 | int _win_setsockopt (SOCKET s, int level, int optname, const void *optval, |
393 | int optlen); | 395 | int optlen); |
394 | int _win_shutdown(SOCKET s, int how); | 396 | int _win_shutdown (SOCKET s, int how); |
395 | SOCKET _win_socket(int af, int type, int protocol); | 397 | SOCKET _win_socket (int af, int type, int protocol); |
396 | struct hostent *_win_gethostbyaddr(const char *addr, int len, int type); | 398 | struct hostent *_win_gethostbyaddr (const char *addr, int len, int type); |
397 | struct hostent *_win_gethostbyname(const char *name); | 399 | struct hostent *_win_gethostbyname (const char *name); |
398 | char *_win_strerror(int errnum); | 400 | char *_win_strerror (int errnum); |
399 | int IsWinNT(); | 401 | int IsWinNT (); |
400 | 402 | ||
401 | #if !HAVE_STRNDUP | 403 | #if !HAVE_STRNDUP |
402 | char *strndup (const char *s, size_t n); | 404 | char *strndup (const char *s, size_t n); |
403 | #endif | 405 | #endif |
404 | #if !HAVE_STRNLEN | 406 | #if !HAVE_STRNLEN |
405 | size_t strnlen (const char *str, size_t maxlen); | 407 | size_t strnlen (const char *str, size_t maxlen); |
406 | #endif | 408 | #endif |
407 | 409 | ||
408 | #endif /* WINDOWS */ | 410 | #endif /* WINDOWS */ |
409 | 411 | ||
410 | #ifndef WINDOWS | 412 | #ifndef WINDOWS |
411 | #define DIR_SEPARATOR '/' | 413 | #define DIR_SEPARATOR '/' |
412 | #define DIR_SEPARATOR_STR "/" | 414 | #define DIR_SEPARATOR_STR "/" |
413 | #define NEWLINE "\n" | 415 | #define NEWLINE "\n" |
414 | 416 | ||
415 | #ifdef ENABLE_NLS | 417 | #ifdef ENABLE_NLS |
416 | #define BINDTEXTDOMAIN(d, n) bindtextdomain(d, n) | 418 | #define BINDTEXTDOMAIN(d, n) bindtextdomain(d, n) |
417 | #endif | 419 | #endif |
418 | #define CREAT(p, m) creat(p, m) | 420 | #define CREAT(p, m) creat(p, m) |
419 | #undef FOPEN | 421 | #undef FOPEN |
420 | #define FOPEN(f, m) fopen(f, m) | 422 | #define FOPEN(f, m) fopen(f, m) |
421 | #define OPENDIR(d) opendir(d) | 423 | #define OPENDIR(d) opendir(d) |
422 | #define OPEN(f) open(f) | 424 | #define OPEN(f) open(f) |
423 | #define CHDIR(d) chdir(d) | 425 | #define CHDIR(d) chdir(d) |
424 | #define CLOSE(f) close(f) | 426 | #define CLOSE(f) close(f) |
425 | #define RMDIR(f) rmdir(f) | 427 | #define RMDIR(f) rmdir(f) |
426 | #define ACCESS(p, m) access(p, m) | 428 | #define ACCESS(p, m) access(p, m) |
427 | #define CHMOD(f, p) chmod(f, p) | 429 | #define CHMOD(f, p) chmod(f, p) |
428 | #define FSTAT(h, b) fstat(h, b) | 430 | #define FSTAT(h, b) fstat(h, b) |
429 | #define PIPE(h) pipe(h) | 431 | #define PIPE(h) pipe(h) |
430 | #define REMOVE(p) remove(p) | 432 | #define REMOVE(p) remove(p) |
431 | #define RENAME(o, n) rename(o, n) | 433 | #define RENAME(o, n) rename(o, n) |
432 | #define STAT(p, b) stat(p, b) | 434 | #define STAT(p, b) stat(p, b) |
433 | #define UNLINK(f) unlink(f) | 435 | #define UNLINK(f) unlink(f) |
434 | #define WRITE(f, b, n) write(f, b, n) | 436 | #define WRITE(f, b, n) write(f, b, n) |
435 | #define READ(f, b, n) read(f, b, n) | 437 | #define READ(f, b, n) read(f, b, n) |
436 | #define GN_FREAD(b, s, c, f) fread(b, s, c, f) | 438 | #define GN_FREAD(b, s, c, f) fread(b, s, c, f) |
437 | #define GN_FWRITE(b, s, c, f) fwrite(b, s, c, f) | 439 | #define GN_FWRITE(b, s, c, f) fwrite(b, s, c, f) |
438 | #define SYMLINK(a, b) symlink(a, b) | 440 | #define SYMLINK(a, b) symlink(a, b) |
439 | #define MMAP(s, l, p, f, d, o) mmap(s, l, p, f, d, o) | 441 | #define MMAP(s, l, p, f, d, o) mmap(s, l, p, f, d, o) |
440 | #define MUNMAP(s, l) munmap(s, l) | 442 | #define MUNMAP(s, l) munmap(s, l) |
441 | #define STRERROR(i) strerror(i) | 443 | #define STRERROR(i) strerror(i) |
442 | #define RANDOM() random() | 444 | #define RANDOM() random() |
443 | #define READLINK(p, b, s) readlink(p, b, s) | 445 | #define READLINK(p, b, s) readlink(p, b, s) |
444 | #define LSTAT(p, b) lstat(p, b) | 446 | #define LSTAT(p, b) lstat(p, b) |
445 | #define PRINTF printf | 447 | #define PRINTF printf |
446 | #define FPRINTF fprintf | 448 | #define FPRINTF fprintf |
447 | #define VPRINTF(f, a) vprintf(f, a) | 449 | #define VPRINTF(f, a) vprintf(f, a) |
448 | #define VFPRINTF(s, f, a) vfprintf(s, f, a) | 450 | #define VFPRINTF(s, f, a) vfprintf(s, f, a) |
449 | #define VSPRINTF(d, f, a) vsprintf(d, f, a) | 451 | #define VSPRINTF(d, f, a) vsprintf(d, f, a) |
450 | #define VSNPRINTF(str, size, fmt, a) vsnprintf(str, size, fmt, a) | 452 | #define VSNPRINTF(str, size, fmt, a) vsnprintf(str, size, fmt, a) |
451 | #define _REAL_SNPRINTF snprintf | 453 | #define _REAL_SNPRINTF snprintf |
452 | #define SPRINTF sprintf | 454 | #define SPRINTF sprintf |
453 | #define VSSCANF(s, f, a) vsscanf(s, f, a) | 455 | #define VSSCANF(s, f, a) vsscanf(s, f, a) |
454 | #define SSCANF sscanf | 456 | #define SSCANF sscanf |
455 | #define VFSCANF(s, f, a) vfscanf(s, f, a) | 457 | #define VFSCANF(s, f, a) vfscanf(s, f, a) |
456 | #define VSCANF(f, a) vscanf(f, a) | 458 | #define VSCANF(f, a) vscanf(f, a) |
457 | #define SCANF scanf | 459 | #define SCANF scanf |
458 | #define FSCANF fscanf | 460 | #define FSCANF fscanf |
459 | #define WAITPID(p, s, o) waitpid(p, s, o) | 461 | #define WAITPID(p, s, o) waitpid(p, s, o) |
460 | #define ACCEPT(s, a, l) accept(s, a, l) | 462 | #define ACCEPT(s, a, l) accept(s, a, l) |
461 | #define BIND(s, n, l) bind(s, n, l) | 463 | #define BIND(s, n, l) bind(s, n, l) |
462 | #define CONNECT(s, n, l) connect(s, n, l) | 464 | #define CONNECT(s, n, l) connect(s, n, l) |
463 | #define GETPEERNAME(s, n, l) getpeername(s, n, l) | 465 | #define GETPEERNAME(s, n, l) getpeername(s, n, l) |
464 | #define GETSOCKNAME(s, n, l) getsockname(s, n, l) | 466 | #define GETSOCKNAME(s, n, l) getsockname(s, n, l) |
465 | #define GETSOCKOPT(s, l, o, v, p) getsockopt(s, l, o, v, p) | 467 | #define GETSOCKOPT(s, l, o, v, p) getsockopt(s, l, o, v, p) |
466 | #define LISTEN(s, b) listen(s, b) | 468 | #define LISTEN(s, b) listen(s, b) |
467 | #define RECV(s, b, l, f) recv(s, b, l, f) | 469 | #define RECV(s, b, l, f) recv(s, b, l, f) |
468 | #define RECVFROM(s, b, l, f, r, o) recvfrom(s, b, l, f, r, o) | 470 | #define RECVFROM(s, b, l, f, r, o) recvfrom(s, b, l, f, r, o) |
469 | #define SELECT(n, r, w, e, t) select(n, r, w, e, t) | 471 | #define SELECT(n, r, w, e, t) select(n, r, w, e, t) |
470 | #define SEND(s, b, l, f) send(s, b, l, f) | 472 | #define SEND(s, b, l, f) send(s, b, l, f) |
471 | #define SENDTO(s, b, l, f, o, n) sendto(s, b, l, f, o, n) | 473 | #define SENDTO(s, b, l, f, o, n) sendto(s, b, l, f, o, n) |
472 | #define SETSOCKOPT(s, l, o, v, n) setsockopt(s, l, o, v, n) | 474 | #define SETSOCKOPT(s, l, o, v, n) setsockopt(s, l, o, v, n) |
473 | #define SHUTDOWN(s, h) shutdown(s, h) | 475 | #define SHUTDOWN(s, h) shutdown(s, h) |
474 | #define SOCKET(a, t, p) socket(a, t, p) | 476 | #define SOCKET(a, t, p) socket(a, t, p) |
475 | #define GETHOSTBYADDR(a, l, t) gethostbyname(a, l, t) | 477 | #define GETHOSTBYADDR(a, l, t) gethostbyname(a, l, t) |
476 | #define GETHOSTBYNAME(n) gethostbyname(n) | 478 | #define GETHOSTBYNAME(n) gethostbyname(n) |
477 | #else | 479 | #else |
478 | #define DIR_SEPARATOR '\\' | 480 | #define DIR_SEPARATOR '\\' |
479 | #define DIR_SEPARATOR_STR "\\" | 481 | #define DIR_SEPARATOR_STR "\\" |
480 | #define NEWLINE "\r\n" | 482 | #define NEWLINE "\r\n" |
481 | 483 | ||
482 | #ifdef ENABLE_NLS | 484 | #ifdef ENABLE_NLS |
483 | #define BINDTEXTDOMAIN(d, n) _win_bindtextdomain(d, n) | 485 | #define BINDTEXTDOMAIN(d, n) _win_bindtextdomain(d, n) |
484 | #endif | 486 | #endif |
485 | #define CREAT(p, m) _win_creat(p, m) | 487 | #define CREAT(p, m) _win_creat(p, m) |
486 | #define FOPEN(f, m) _win_fopen(f, m) | 488 | #define FOPEN(f, m) _win_fopen(f, m) |
487 | #define OPENDIR(d) _win_opendir(d) | 489 | #define OPENDIR(d) _win_opendir(d) |
488 | #define OPEN(f) _win_open(f) | 490 | #define OPEN(f) _win_open(f) |
489 | #define CHDIR(d) _win_chdir(d) | 491 | #define CHDIR(d) _win_chdir(d) |
490 | #define CLOSE(f) _win_close(f) | 492 | #define CLOSE(f) _win_close(f) |
491 | #define FSTAT(h, b) _win_fstat(h, b) | 493 | #define FSTAT(h, b) _win_fstat(h, b) |
492 | #define RMDIR(f) _win_rmdir(f) | 494 | #define RMDIR(f) _win_rmdir(f) |
493 | #define ACCESS(p, m) _win_access(p, m) | 495 | #define ACCESS(p, m) _win_access(p, m) |
494 | #define CHMOD(f, p) _win_chmod(f, p) | 496 | #define CHMOD(f, p) _win_chmod(f, p) |
495 | #define PIPE(h) _win_pipe(h) | 497 | #define PIPE(h) _win_pipe(h) |
496 | #define RANDOM() _win_random() | 498 | #define RANDOM() _win_random() |
497 | #define REMOVE(p) _win_remove(p) | 499 | #define REMOVE(p) _win_remove(p) |
498 | #define RENAME(o, n) _win_rename(o, n) | 500 | #define RENAME(o, n) _win_rename(o, n) |
499 | #define STAT(p, b) _win_stat(p, b) | 501 | #define STAT(p, b) _win_stat(p, b) |
500 | #define UNLINK(f) _win_unlink(f) | 502 | #define UNLINK(f) _win_unlink(f) |
501 | #define WRITE(f, b, n) _win_write(f, b, n) | 503 | #define WRITE(f, b, n) _win_write(f, b, n) |
502 | #define READ(f, b, n) _win_read(f, b, n) | 504 | #define READ(f, b, n) _win_read(f, b, n) |
503 | #define GN_FREAD(b, s, c, f) _win_fread(b, s, c, f) | 505 | #define GN_FREAD(b, s, c, f) _win_fread(b, s, c, f) |
504 | #define GN_FWRITE(b, s, c, f) _win_fwrite(b, s, c, f) | 506 | #define GN_FWRITE(b, s, c, f) _win_fwrite(b, s, c, f) |
505 | #define SYMLINK(a, b) _win_symlink(a, b) | 507 | #define SYMLINK(a, b) _win_symlink(a, b) |
506 | #define MMAP(s, l, p, f, d, o) _win_mmap(s, l, p, f, d, o) | 508 | #define MMAP(s, l, p, f, d, o) _win_mmap(s, l, p, f, d, o) |
507 | #define MUNMAP(s, l) _win_munmap(s, l) | 509 | #define MUNMAP(s, l) _win_munmap(s, l) |
508 | #define STRERROR(i) _win_strerror(i) | 510 | #define STRERROR(i) _win_strerror(i) |
509 | #define READLINK(p, b, s) _win_readlink(p, b, s) | 511 | #define READLINK(p, b, s) _win_readlink(p, b, s) |
510 | #define LSTAT(p, b) _win_lstat(p, b) | 512 | #define LSTAT(p, b) _win_lstat(p, b) |
511 | #define PRINTF(f, ...) _win_printf(f , __VA_ARGS__) | 513 | #define PRINTF(f, ...) _win_printf(f , __VA_ARGS__) |
512 | #define FPRINTF(fil, fmt, ...) _win_fprintf(fil, fmt, __VA_ARGS__) | 514 | #define FPRINTF(fil, fmt, ...) _win_fprintf(fil, fmt, __VA_ARGS__) |
513 | #define VPRINTF(f, a) _win_vprintf(f, a) | 515 | #define VPRINTF(f, a) _win_vprintf(f, a) |
514 | #define VFPRINTF(s, f, a) _win_vfprintf(s, f, a) | 516 | #define VFPRINTF(s, f, a) _win_vfprintf(s, f, a) |
515 | #define VSPRINTF(d, f, a) _win_vsprintf(d, f, a) | 517 | #define VSPRINTF(d, f, a) _win_vsprintf(d, f, a) |
516 | #define VSNPRINTF(str, size, fmt, a) _win_vsnprintf(str, size, fmt, a) | 518 | #define VSNPRINTF(str, size, fmt, a) _win_vsnprintf(str, size, fmt, a) |
517 | #define _REAL_SNPRINTF(str, size, fmt, ...) _win_snprintf(str, size, fmt, __VA_ARGS__) | 519 | #define _REAL_SNPRINTF(str, size, fmt, ...) _win_snprintf(str, size, fmt, __VA_ARGS__) |
518 | #define SPRINTF(d, f, ...) _win_sprintf(d, f, __VA_ARGS__) | 520 | #define SPRINTF(d, f, ...) _win_sprintf(d, f, __VA_ARGS__) |
519 | #define VSSCANF(s, f, a) _win_vsscanf(s, f, a) | 521 | #define VSSCANF(s, f, a) _win_vsscanf(s, f, a) |
520 | #define SSCANF(s, f, ...) _win_sscanf(s, f, __VA_ARGS__) | 522 | #define SSCANF(s, f, ...) _win_sscanf(s, f, __VA_ARGS__) |
521 | #define VFSCANF(s, f, a) _win_vfscanf(s, f, a) | 523 | #define VFSCANF(s, f, a) _win_vfscanf(s, f, a) |
522 | #define VSCANF(f, a) _win_vscanf(f, a) | 524 | #define VSCANF(f, a) _win_vscanf(f, a) |
523 | #define SCANF(f, ...) _win_scanf(f, __VA_ARGS__) | 525 | #define SCANF(f, ...) _win_scanf(f, __VA_ARGS__) |
524 | #define FSCANF(s, f, ...) _win_fscanf(s, f, __VA_ARGS__) | 526 | #define FSCANF(s, f, ...) _win_fscanf(s, f, __VA_ARGS__) |
525 | #define WAITPID(p, s, o) _win_waitpid(p, s, o) | 527 | #define WAITPID(p, s, o) _win_waitpid(p, s, o) |
526 | #define ACCEPT(s, a, l) _win_accept(s, a, l) | 528 | #define ACCEPT(s, a, l) _win_accept(s, a, l) |
527 | #define BIND(s, n, l) _win_bind(s, n, l) | 529 | #define BIND(s, n, l) _win_bind(s, n, l) |
528 | #define CONNECT(s, n, l) _win_connect(s, n, l) | 530 | #define CONNECT(s, n, l) _win_connect(s, n, l) |
529 | #define GETPEERNAME(s, n, l) _win_getpeername(s, n, l) | 531 | #define GETPEERNAME(s, n, l) _win_getpeername(s, n, l) |
530 | #define GETSOCKNAME(s, n, l) _win_getsockname(s, n, l) | 532 | #define GETSOCKNAME(s, n, l) _win_getsockname(s, n, l) |
531 | #define GETSOCKOPT(s, l, o, v, p) _win_getsockopt(s, l, o, v, p) | 533 | #define GETSOCKOPT(s, l, o, v, p) _win_getsockopt(s, l, o, v, p) |
532 | #define LISTEN(s, b) _win_listen(s, b) | 534 | #define LISTEN(s, b) _win_listen(s, b) |
533 | #define RECV(s, b, l, f) _win_recv(s, b, l, f) | 535 | #define RECV(s, b, l, f) _win_recv(s, b, l, f) |
534 | #define RECVFROM(s, b, l, f, r, o) _win_recvfrom(s, b, l, f, r, o) | 536 | #define RECVFROM(s, b, l, f, r, o) _win_recvfrom(s, b, l, f, r, o) |
535 | #define SELECT(n, r, w, e, t) _win_select(n, r, w, e, t) | 537 | #define SELECT(n, r, w, e, t) _win_select(n, r, w, e, t) |
536 | #define SEND(s, b, l, f) _win_send(s, b, l, f) | 538 | #define SEND(s, b, l, f) _win_send(s, b, l, f) |
537 | #define SENDTO(s, b, l, f, o, n) _win_sendto(s, b, l, f, o, n) | 539 | #define SENDTO(s, b, l, f, o, n) _win_sendto(s, b, l, f, o, n) |
538 | #define SETSOCKOPT(s, l, o, v, n) _win_setsockopt(s, l, o, v, n) | 540 | #define SETSOCKOPT(s, l, o, v, n) _win_setsockopt(s, l, o, v, n) |
539 | #define SHUTDOWN(s, h) _win_shutdown(s, h) | 541 | #define SHUTDOWN(s, h) _win_shutdown(s, h) |
540 | #define SOCKET(a, t, p) _win_socket(a, t, p) | 542 | #define SOCKET(a, t, p) _win_socket(a, t, p) |
541 | #define GETHOSTBYADDR(a, l, t) _win_gethostbyname(a, l, t) | 543 | #define GETHOSTBYADDR(a, l, t) _win_gethostbyname(a, l, t) |
542 | #define GETHOSTBYNAME(n) _win_gethostbyname(n) | 544 | #define GETHOSTBYNAME(n) _win_gethostbyname(n) |
543 | #endif | 545 | #endif |
544 | 546 | ||
545 | 547 | ||
@@ -548,6 +550,6 @@ size_t strnlen (const char *str, size_t maxlen); | |||
548 | #endif | 550 | #endif |
549 | 551 | ||
550 | 552 | ||
551 | #endif //_PLIBC_H_ | 553 | #endif //_PLIBC_H_ |
552 | 554 | ||
553 | /* end of plibc.h */ | 555 | /* end of plibc.h */ |
diff --git a/src/plugins/about/about.c b/src/plugins/about/about.c index 333397e7..c59b5b67 100644 --- a/src/plugins/about/about.c +++ b/src/plugins/about/about.c | |||
@@ -32,30 +32,26 @@ | |||
32 | /** | 32 | /** |
33 | * This displays an about window | 33 | * This displays an about window |
34 | */ | 34 | */ |
35 | void on_about_clicked_about(GtkWidget *dummy, | 35 | void |
36 | gpointer data) { | 36 | on_about_clicked_about (GtkWidget * dummy, gpointer data) |
37 | GtkWidget * ad; | 37 | { |
38 | GladeXML * axml; | 38 | GtkWidget *ad; |
39 | 39 | GladeXML *axml; | |
40 | axml | 40 | |
41 | = glade_xml_new(getGladeFileName(), | 41 | axml = glade_xml_new (getGladeFileName (), "aboutDialog", PACKAGE_NAME); |
42 | "aboutDialog", | 42 | ad = glade_xml_get_widget (axml, "aboutDialog"); |
43 | PACKAGE_NAME); | 43 | gtk_dialog_run (GTK_DIALOG (ad)); |
44 | ad | 44 | gtk_widget_destroy (ad); |
45 | = glade_xml_get_widget(axml, | 45 | g_object_unref (axml); |
46 | "aboutDialog"); | ||
47 | gtk_dialog_run(GTK_DIALOG(ad)); | ||
48 | gtk_widget_destroy(ad); | ||
49 | g_object_unref(axml); | ||
50 | } | 46 | } |
51 | 47 | ||
52 | void init_about() { | 48 | void |
53 | GtkWidget * tab; | 49 | init_about () |
50 | { | ||
51 | GtkWidget *tab; | ||
54 | 52 | ||
55 | tab | 53 | tab = glade_xml_get_widget (getMainXML (), "aboutButton"); |
56 | = glade_xml_get_widget(getMainXML(), | 54 | gtk_widget_show (tab); |
57 | "aboutButton"); | ||
58 | gtk_widget_show(tab); | ||
59 | } | 55 | } |
60 | 56 | ||
61 | /* end of about.c */ | 57 | /* end of about.c */ |
diff --git a/src/plugins/daemon/daemon.c b/src/plugins/daemon/daemon.c index 1898d979..4b0d20e8 100644 --- a/src/plugins/daemon/daemon.c +++ b/src/plugins/daemon/daemon.c | |||
@@ -33,367 +33,360 @@ | |||
33 | #include <GNUnet/gnunet_util_network_client.h> | 33 | #include <GNUnet/gnunet_util_network_client.h> |
34 | #include <gtk/gtk.h> | 34 | #include <gtk/gtk.h> |
35 | 35 | ||
36 | static struct CronManager * cron; | 36 | static struct CronManager *cron; |
37 | 37 | ||
38 | static struct GE_Context * ectx; | 38 | static struct GE_Context *ectx; |
39 | 39 | ||
40 | static struct GC_Configuration * cfg; | 40 | static struct GC_Configuration *cfg; |
41 | 41 | ||
42 | /** | 42 | /** |
43 | * cron job that periodically updates the model for the | 43 | * cron job that periodically updates the model for the |
44 | * application list. | 44 | * application list. |
45 | */ | 45 | */ |
46 | static void * updateAppModelSafe(void * unused) { | 46 | static void * |
47 | struct ClientServerConnection * sock; | 47 | updateAppModelSafe (void *unused) |
48 | GtkWidget * w; | 48 | { |
49 | GtkListStore * model; | 49 | struct ClientServerConnection *sock; |
50 | GtkWidget *w; | ||
51 | GtkListStore *model; | ||
50 | GtkTreeIter iter; | 52 | GtkTreeIter iter; |
51 | char * apps; | 53 | char *apps; |
52 | char * next; | 54 | char *next; |
53 | char * pos; | 55 | char *pos; |
54 | char * desc; | 56 | char *desc; |
55 | 57 | ||
56 | model = gtk_list_store_new(2, | 58 | model = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING); |
57 | G_TYPE_STRING, | ||
58 | G_TYPE_STRING); | ||
59 | apps = NULL; | 59 | apps = NULL; |
60 | sock = client_connection_create(ectx, cfg); | 60 | sock = client_connection_create (ectx, cfg); |
61 | if (sock != NULL) | 61 | if (sock != NULL) |
62 | apps = getConfigurationOptionValue(sock, | 62 | apps = getConfigurationOptionValue (sock, "GNUNETD", "APPLICATIONS"); |
63 | "GNUNETD", | 63 | if (apps != NULL) |
64 | "APPLICATIONS"); | 64 | { |
65 | if (apps != NULL) { | 65 | next = apps; |
66 | next = apps; | 66 | do |
67 | do { | 67 | { |
68 | while (*next == ' ') | 68 | while (*next == ' ') |
69 | next++; | 69 | next++; |
70 | pos = next; | 70 | pos = next; |
71 | while ( (*next != '\0') && | 71 | while ((*next != '\0') && (*next != ' ')) |
72 | (*next != ' ') ) | 72 | next++; |
73 | next++; | 73 | if (*next == '\0') |
74 | if (*next == '\0') { | 74 | { |
75 | next = NULL; /* terminate! */ | 75 | next = NULL; /* terminate! */ |
76 | } else { | 76 | } |
77 | *next = '\0'; /* add 0-termination for pos */ | 77 | else |
78 | next++; | 78 | { |
79 | } | 79 | *next = '\0'; /* add 0-termination for pos */ |
80 | if (strlen(pos) > 0) { | 80 | next++; |
81 | desc | 81 | } |
82 | = getConfigurationOptionValue(sock, | 82 | if (strlen (pos) > 0) |
83 | "ABOUT", | 83 | { |
84 | pos); | 84 | desc = getConfigurationOptionValue (sock, "ABOUT", pos); |
85 | 85 | ||
86 | gtk_list_store_append(model, | 86 | gtk_list_store_append (model, &iter); |
87 | &iter); | 87 | gtk_list_store_set (model, |
88 | gtk_list_store_set(model, | 88 | &iter, |
89 | &iter, | 89 | 0, pos, 1, dgettext ("GNUnet", desc), -1); |
90 | 0, pos, | 90 | FREENONNULL (desc); |
91 | 1, dgettext("GNUnet", desc), | 91 | } |
92 | -1); | 92 | } |
93 | FREENONNULL(desc); | 93 | while (next != NULL); |
94 | } | 94 | FREE (apps); |
95 | } while (next != NULL); | 95 | } |
96 | FREE(apps); | 96 | w = glade_xml_get_widget (getMainXML (), "applicationList"); |
97 | } | 97 | gtk_tree_view_set_model (GTK_TREE_VIEW (w), GTK_TREE_MODEL (model)); |
98 | w = glade_xml_get_widget(getMainXML(), | 98 | gtk_tree_selection_set_mode (gtk_tree_view_get_selection |
99 | "applicationList"); | 99 | (GTK_TREE_VIEW (w)), GTK_SELECTION_NONE); |
100 | gtk_tree_view_set_model(GTK_TREE_VIEW(w), | 100 | connection_destroy (sock); |
101 | GTK_TREE_MODEL(model)); | ||
102 | gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(w)), | ||
103 | GTK_SELECTION_NONE); | ||
104 | connection_destroy(sock); | ||
105 | return NULL; | 101 | return NULL; |
106 | } | 102 | } |
107 | 103 | ||
108 | static void updateAppModel(void * dummy) { | 104 | static void |
109 | gtkSaveCall(&updateAppModelSafe, NULL); | 105 | updateAppModel (void *dummy) |
106 | { | ||
107 | gtkSaveCall (&updateAppModelSafe, NULL); | ||
110 | } | 108 | } |
111 | 109 | ||
112 | 110 | ||
113 | static void * doUpdateMenus(void * arg) { | 111 | static void * |
114 | int ret = *(int*) arg; | 112 | doUpdateMenus (void *arg) |
115 | static GtkWidget * killEntry = NULL; | 113 | { |
116 | static GtkWidget * launchEntry = NULL; | 114 | int ret = *(int *) arg; |
117 | static GtkWidget * statsEntryYes = NULL; | 115 | static GtkWidget *killEntry = NULL; |
118 | static GtkWidget * statsEntryNo = NULL; | 116 | static GtkWidget *launchEntry = NULL; |
119 | static GtkWidget * statsEntryError = NULL; | 117 | static GtkWidget *statsEntryYes = NULL; |
120 | static GtkWidget * chooser = NULL; | 118 | static GtkWidget *statsEntryNo = NULL; |
119 | static GtkWidget *statsEntryError = NULL; | ||
120 | static GtkWidget *chooser = NULL; | ||
121 | static int once = 1; | 121 | static int once = 1; |
122 | static int isLocal; | 122 | static int isLocal; |
123 | char * host; | 123 | char *host; |
124 | int canStart; | 124 | int canStart; |
125 | struct GC_Configuration * dcfg; | 125 | struct GC_Configuration *dcfg; |
126 | char * fn; | 126 | char *fn; |
127 | char * user; | 127 | char *user; |
128 | struct passwd * pws; | 128 | struct passwd *pws; |
129 | 129 | ||
130 | if (once) { | 130 | if (once) |
131 | once = 0; | 131 | { |
132 | killEntry | 132 | once = 0; |
133 | = glade_xml_get_widget(getMainXML(), | 133 | killEntry = glade_xml_get_widget (getMainXML (), "stopDaemon"); |
134 | "stopDaemon"); | 134 | launchEntry = glade_xml_get_widget (getMainXML (), "startDaemon"); |
135 | launchEntry | 135 | statsEntryYes = glade_xml_get_widget (getMainXML (), "statusPixmapYes"); |
136 | = glade_xml_get_widget(getMainXML(), | 136 | statsEntryNo = glade_xml_get_widget (getMainXML (), "statusPixmapNo"); |
137 | "startDaemon"); | 137 | statsEntryError |
138 | statsEntryYes | 138 | = glade_xml_get_widget (getMainXML (), "statusPixmapError"); |
139 | = glade_xml_get_widget(getMainXML(), | 139 | chooser |
140 | "statusPixmapYes"); | 140 | = glade_xml_get_widget (getMainXML (), |
141 | statsEntryNo | 141 | "gnunetdconfigFileChooserButton"); |
142 | = glade_xml_get_widget(getMainXML(), | 142 | GC_get_configuration_value_string (cfg, |
143 | "statusPixmapNo"); | 143 | "NETWORK", |
144 | statsEntryError | 144 | "HOST", "localhost", &host); |
145 | = glade_xml_get_widget(getMainXML(), | 145 | if (strcmp (host, "localhost") == 0) |
146 | "statusPixmapError"); | 146 | isLocal = TRUE; |
147 | chooser | 147 | else |
148 | = glade_xml_get_widget(getMainXML(), | 148 | isLocal = FALSE; |
149 | "gnunetdconfigFileChooserButton"); | 149 | FREE (host); |
150 | GC_get_configuration_value_string(cfg, | 150 | } |
151 | "NETWORK", | 151 | updateAppModelSafe (NULL); |
152 | "HOST", | 152 | if (ret == 0) |
153 | "localhost", | 153 | { |
154 | &host); | 154 | canStart = 0; |
155 | if (strcmp(host, "localhost")==0) | 155 | if ((isLocal) && |
156 | isLocal = TRUE; | 156 | (NULL != |
157 | else | 157 | (fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser))))) |
158 | isLocal = FALSE; | 158 | { |
159 | FREE(host); | 159 | if (disk_file_test (ectx, fn) == YES) |
160 | } | 160 | { |
161 | updateAppModelSafe(NULL); | 161 | dcfg = GC_create_C_impl (); |
162 | if (ret == 0) { | 162 | canStart = 1; |
163 | canStart = 0; | 163 | if (0 != GC_parse_configuration (dcfg, fn)) |
164 | if ( (isLocal) && | 164 | canStart = 0; |
165 | (NULL != (fn = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(chooser)))) ) { | 165 | user = NULL; |
166 | if (disk_file_test(ectx, fn) == YES) { | 166 | GC_get_configuration_value_string (dcfg, |
167 | dcfg = GC_create_C_impl(); | 167 | "GNUNETD", |
168 | canStart = 1; | 168 | "USER", "", &user); |
169 | if (0 != GC_parse_configuration(dcfg, fn)) | 169 | if (strlen (user) > 0) |
170 | canStart = 0; | 170 | { |
171 | user = NULL; | ||
172 | GC_get_configuration_value_string(dcfg, | ||
173 | "GNUNETD", | ||
174 | "USER", | ||
175 | "", | ||
176 | &user); | ||
177 | if (strlen(user) > 0) { | ||
178 | #ifndef WINDOWS | 171 | #ifndef WINDOWS |
179 | if (NULL == (pws = getpwnam(user))) { | 172 | if (NULL == (pws = getpwnam (user))) |
180 | canStart = 0; | 173 | { |
181 | } else { | 174 | canStart = 0; |
182 | if (pws->pw_uid != getuid()) | 175 | } |
183 | canStart = (geteuid() == 0); | 176 | else |
184 | else | 177 | { |
185 | canStart = 1; | 178 | if (pws->pw_uid != getuid ()) |
186 | } | 179 | canStart = (geteuid () == 0); |
180 | else | ||
181 | canStart = 1; | ||
182 | } | ||
187 | #else | 183 | #else |
188 | canStart = 1; | 184 | canStart = 1; |
189 | #endif | 185 | #endif |
190 | } | 186 | } |
191 | FREE(user); | 187 | FREE (user); |
192 | GC_free(dcfg); | 188 | GC_free (dcfg); |
193 | } | 189 | } |
194 | g_free(fn); | 190 | g_free (fn); |
191 | } | ||
192 | gtk_widget_hide (statsEntryYes); | ||
193 | gtk_widget_set_sensitive (killEntry, FALSE); | ||
194 | if (canStart && isLocal) | ||
195 | { | ||
196 | gtk_widget_set_sensitive (launchEntry, TRUE); | ||
197 | gtk_widget_show_all (statsEntryNo); | ||
198 | gtk_widget_hide (statsEntryError); | ||
199 | } | ||
200 | else | ||
201 | { | ||
202 | gtk_widget_set_sensitive (launchEntry, FALSE); | ||
203 | gtk_widget_show_all (statsEntryError); | ||
204 | gtk_widget_hide (statsEntryNo); | ||
205 | } | ||
195 | } | 206 | } |
196 | gtk_widget_hide(statsEntryYes); | 207 | else |
197 | gtk_widget_set_sensitive(killEntry, FALSE); | 208 | { |
198 | if (canStart && isLocal) { | 209 | gtk_widget_hide (statsEntryNo); |
199 | gtk_widget_set_sensitive(launchEntry, TRUE); | 210 | gtk_widget_hide (statsEntryError); |
200 | gtk_widget_show_all(statsEntryNo); | 211 | gtk_widget_show_all (statsEntryYes); |
201 | gtk_widget_hide(statsEntryError); | 212 | gtk_widget_set_sensitive (killEntry, TRUE); |
202 | } else { | 213 | gtk_widget_set_sensitive (launchEntry, FALSE); |
203 | gtk_widget_set_sensitive(launchEntry, FALSE); | ||
204 | gtk_widget_show_all(statsEntryError); | ||
205 | gtk_widget_hide(statsEntryNo); | ||
206 | } | 214 | } |
207 | } else { | ||
208 | gtk_widget_hide(statsEntryNo); | ||
209 | gtk_widget_hide(statsEntryError); | ||
210 | gtk_widget_show_all(statsEntryYes); | ||
211 | gtk_widget_set_sensitive(killEntry, TRUE); | ||
212 | gtk_widget_set_sensitive(launchEntry, FALSE); | ||
213 | } | ||
214 | return NULL; | 215 | return NULL; |
215 | } | 216 | } |
216 | 217 | ||
217 | static void cronCheckDaemon(void * dummy) { | 218 | static void |
219 | cronCheckDaemon (void *dummy) | ||
220 | { | ||
218 | int ret; | 221 | int ret; |
219 | 222 | ||
220 | if (OK == connection_test_running(ectx, | 223 | if (OK == connection_test_running (ectx, cfg)) |
221 | cfg)) | ||
222 | ret = 1; | 224 | ret = 1; |
223 | else | 225 | else |
224 | ret = 0; | 226 | ret = 0; |
225 | gtkSaveCall(&doUpdateMenus, &ret); | 227 | gtkSaveCall (&doUpdateMenus, &ret); |
226 | } | 228 | } |
227 | 229 | ||
228 | 230 | ||
229 | /** | 231 | /** |
230 | * Launch gnunetd w/ checks | 232 | * Launch gnunetd w/ checks |
231 | */ | 233 | */ |
232 | void on_startDaemon_clicked_daemon(GtkWidget * widget, | 234 | void |
233 | gpointer data) { | 235 | on_startDaemon_clicked_daemon (GtkWidget * widget, gpointer data) |
234 | GtkWidget * launchEntry; | 236 | { |
235 | GtkWidget * chooser; | 237 | GtkWidget *launchEntry; |
236 | char * fn; | 238 | GtkWidget *chooser; |
237 | 239 | char *fn; | |
238 | launchEntry | 240 | |
239 | = glade_xml_get_widget(getMainXML(), | 241 | launchEntry = glade_xml_get_widget (getMainXML (), "startDaemon"); |
240 | "startDaemon"); | 242 | gtk_widget_set_sensitive (launchEntry, FALSE); |
241 | gtk_widget_set_sensitive(launchEntry, FALSE); | 243 | if (OK == connection_test_running (ectx, cfg)) |
242 | if (OK == connection_test_running(ectx, | 244 | { |
243 | cfg) ) { | 245 | cronCheckDaemon (NULL); |
244 | cronCheckDaemon(NULL); | 246 | return; |
245 | return; | 247 | } |
246 | } else { | 248 | else |
247 | addLogEntry(_("Launching gnunetd...")); | 249 | { |
248 | chooser | 250 | addLogEntry (_("Launching gnunetd...")); |
249 | = glade_xml_get_widget(getMainXML(), | 251 | chooser |
250 | "gnunetdconfigFileChooserButton"); | 252 | = glade_xml_get_widget (getMainXML (), |
251 | fn = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(chooser)); | 253 | "gnunetdconfigFileChooserButton"); |
252 | GE_BREAK(ectx, fn != NULL); | 254 | fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser)); |
253 | if (SYSERR != os_daemon_start(ectx, | 255 | GE_BREAK (ectx, fn != NULL); |
254 | cfg, | 256 | if (SYSERR != os_daemon_start (ectx, cfg, fn, YES)) |
255 | fn, | 257 | { |
256 | YES)) { | 258 | addLogEntry (_("Launched gnunetd")); |
257 | addLogEntry(_("Launched gnunetd")); | 259 | } |
258 | } else { | 260 | else |
259 | addLogEntry(_("Launching gnunetd failed")); | 261 | { |
262 | addLogEntry (_("Launching gnunetd failed")); | ||
263 | } | ||
264 | if (fn != NULL) | ||
265 | g_free (fn); | ||
260 | } | 266 | } |
261 | if (fn != NULL) | ||
262 | g_free(fn); | ||
263 | } | ||
264 | } | 267 | } |
265 | 268 | ||
266 | /** | 269 | /** |
267 | * Kill gnunetd | 270 | * Kill gnunetd |
268 | */ | 271 | */ |
269 | void on_stopDaemon_clicked_daemon(GtkWidget * widget, | 272 | void |
270 | gpointer data) { | 273 | on_stopDaemon_clicked_daemon (GtkWidget * widget, gpointer data) |
271 | GtkWidget * killEntry = NULL; | 274 | { |
272 | struct ClientServerConnection * sock; | 275 | GtkWidget *killEntry = NULL; |
273 | 276 | struct ClientServerConnection *sock; | |
274 | killEntry | 277 | |
275 | = glade_xml_get_widget(getMainXML(), | 278 | killEntry = glade_xml_get_widget (getMainXML (), "stopDaemon"); |
276 | "stopDaemon"); | 279 | gtk_widget_set_sensitive (killEntry, FALSE); |
277 | gtk_widget_set_sensitive(killEntry, FALSE); | 280 | |
278 | 281 | if (OK == connection_test_running (ectx, cfg)) | |
279 | if (OK == connection_test_running(ectx, | 282 | { |
280 | cfg) ) { | 283 | sock = client_connection_create (ectx, cfg); |
281 | sock = client_connection_create(ectx, | 284 | if (OK != connection_request_shutdown (sock)) |
282 | cfg); | 285 | { |
283 | if (OK != connection_request_shutdown(sock)) { | 286 | GtkWidget *dialog; |
284 | GtkWidget * dialog; | 287 | |
285 | 288 | dialog = gtk_message_dialog_new | |
286 | dialog = gtk_message_dialog_new | 289 | (NULL, |
287 | (NULL, | 290 | GTK_DIALOG_MODAL, |
288 | GTK_DIALOG_MODAL, | 291 | GTK_MESSAGE_ERROR, |
289 | GTK_MESSAGE_ERROR, | 292 | GTK_BUTTONS_CLOSE, _("Error requesting shutdown of gnunetd.")); |
290 | GTK_BUTTONS_CLOSE, | 293 | gtk_dialog_run (GTK_DIALOG (dialog)); |
291 | _("Error requesting shutdown of gnunetd.")); | 294 | gtk_widget_destroy (dialog); |
292 | gtk_dialog_run(GTK_DIALOG(dialog)); | 295 | } |
293 | gtk_widget_destroy(dialog); | 296 | else |
294 | } else { | 297 | { |
295 | addLogEntry(_("Terminating gnunetd...")); | 298 | addLogEntry (_("Terminating gnunetd...")); |
299 | } | ||
300 | connection_destroy (sock); | ||
296 | } | 301 | } |
297 | connection_destroy(sock); | 302 | cronCheckDaemon (NULL); |
298 | } | ||
299 | cronCheckDaemon(NULL); | ||
300 | } | 303 | } |
301 | 304 | ||
302 | void init_daemon(struct GE_Context * e, | 305 | void |
303 | struct GC_Configuration * c) { | 306 | init_daemon (struct GE_Context *e, struct GC_Configuration *c) |
304 | GtkWidget * tab; | 307 | { |
305 | GtkWidget * apps; | 308 | GtkWidget *tab; |
306 | GtkListStore * model; | 309 | GtkWidget *apps; |
307 | GtkCellRenderer * renderer; | 310 | GtkListStore *model; |
311 | GtkCellRenderer *renderer; | ||
308 | int col; | 312 | int col; |
309 | char * daemon_config; | 313 | char *daemon_config; |
310 | 314 | ||
311 | ectx = e; | 315 | ectx = e; |
312 | cfg = c; | 316 | cfg = c; |
313 | apps | 317 | apps = glade_xml_get_widget (getMainXML (), "applicationList"); |
314 | = glade_xml_get_widget(getMainXML(), | 318 | model = gtk_list_store_new (1, G_TYPE_STRING); |
315 | "applicationList"); | 319 | gtk_tree_view_set_model (GTK_TREE_VIEW (apps), GTK_TREE_MODEL (model)); |
316 | model = gtk_list_store_new(1, G_TYPE_STRING); | 320 | renderer = gtk_cell_renderer_text_new (); |
317 | gtk_tree_view_set_model(GTK_TREE_VIEW(apps), | 321 | col = gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (apps), |
318 | GTK_TREE_MODEL(model)); | 322 | -1, |
319 | renderer = gtk_cell_renderer_text_new(); | 323 | _("Application"), |
320 | col = gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(apps), | 324 | renderer, |
321 | -1, | 325 | "text", 0, NULL); |
322 | _("Application"), | 326 | gtk_tree_view_column_set_resizable (gtk_tree_view_get_column |
323 | renderer, | 327 | (GTK_TREE_VIEW (apps), col - 1), TRUE); |
324 | "text", 0, | 328 | renderer = gtk_cell_renderer_text_new (); |
325 | NULL); | 329 | col = gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (apps), |
326 | gtk_tree_view_column_set_resizable(gtk_tree_view_get_column(GTK_TREE_VIEW(apps), | 330 | -1, |
327 | col - 1), | 331 | _("Description"), |
328 | TRUE); | 332 | renderer, |
329 | renderer = gtk_cell_renderer_text_new(); | 333 | "text", 1, NULL); |
330 | col = gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(apps), | 334 | gtk_tree_view_column_set_resizable (gtk_tree_view_get_column |
331 | -1, | 335 | (GTK_TREE_VIEW (apps), col - 1), TRUE); |
332 | _("Description"), | 336 | |
333 | renderer, | 337 | tab = glade_xml_get_widget (getMainXML (), "daemonScrolledWindow"); |
334 | "text", 1, | 338 | gtk_widget_show (tab); |
335 | NULL); | ||
336 | gtk_tree_view_column_set_resizable(gtk_tree_view_get_column(GTK_TREE_VIEW(apps), | ||
337 | col - 1), | ||
338 | TRUE); | ||
339 | |||
340 | tab | ||
341 | = glade_xml_get_widget(getMainXML(), | ||
342 | "daemonScrolledWindow"); | ||
343 | gtk_widget_show(tab); | ||
344 | daemon_config = NULL; | 339 | daemon_config = NULL; |
345 | GC_get_configuration_value_filename(cfg, | 340 | GC_get_configuration_value_filename (cfg, |
346 | "DAEMON", | 341 | "DAEMON", |
347 | "CONFIGFILE", | 342 | "CONFIGFILE", |
348 | DEFAULT_DAEMON_CONFIG_FILE, | 343 | DEFAULT_DAEMON_CONFIG_FILE, |
349 | &daemon_config); | 344 | &daemon_config); |
350 | if (YES == disk_file_test(NULL, daemon_config)) { | 345 | if (YES == disk_file_test (NULL, daemon_config)) |
351 | gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(glade_xml_get_widget(getMainXML(), | 346 | { |
352 | "gnunetdconfigFileChooserButton")), | 347 | gtk_file_chooser_set_filename (GTK_FILE_CHOOSER |
353 | daemon_config); | 348 | (glade_xml_get_widget |
354 | } else { | 349 | (getMainXML (), |
355 | addLogEntry(_("Configuration file for GNUnet daemon `%s' does not exist! Run `gnunet-setup -d'."), | 350 | "gnunetdconfigFileChooserButton")), |
356 | daemon_config); | 351 | daemon_config); |
357 | } | 352 | } |
358 | FREE(daemon_config); | 353 | else |
359 | 354 | { | |
360 | cron = gnunet_gtk_get_cron(); | 355 | addLogEntry (_ |
361 | cron_add_job(cron, | 356 | ("Configuration file for GNUnet daemon `%s' does not exist! Run `gnunet-setup -d'."), |
362 | &cronCheckDaemon, | 357 | daemon_config); |
363 | 0, | 358 | } |
364 | 15 * cronSECONDS, | 359 | FREE (daemon_config); |
365 | NULL); | 360 | |
366 | cron_add_job(cron, | 361 | cron = gnunet_gtk_get_cron (); |
367 | &updateAppModel, | 362 | cron_add_job (cron, &cronCheckDaemon, 0, 15 * cronSECONDS, NULL); |
368 | 5 * cronMINUTES, | 363 | cron_add_job (cron, |
369 | 5 * cronMINUTES, | 364 | &updateAppModel, 5 * cronMINUTES, 5 * cronMINUTES, NULL); |
370 | NULL); | ||
371 | } | 365 | } |
372 | 366 | ||
373 | void done_daemon() { | 367 | void |
374 | cron_del_job(cron, | 368 | done_daemon () |
375 | &cronCheckDaemon, | 369 | { |
376 | 15 * cronSECONDS, | 370 | cron_del_job (cron, &cronCheckDaemon, 15 * cronSECONDS, NULL); |
377 | NULL); | 371 | cron_del_job (cron, &updateAppModel, 5 * cronMINUTES, NULL); |
378 | cron_del_job(cron, | ||
379 | &updateAppModel, | ||
380 | 5 * cronMINUTES, | ||
381 | NULL); | ||
382 | } | 372 | } |
383 | 373 | ||
384 | /** | 374 | /** |
385 | * Launch 'gnunet-setup -d wizard-gtk' with needed rights | 375 | * Launch 'gnunet-setup -d wizard-gtk' with needed rights |
386 | */ | 376 | */ |
387 | void on_startDaemonConfWizard_clicked_daemon(GtkWidget * widget, | 377 | void |
388 | gpointer data) { | 378 | on_startDaemonConfWizard_clicked_daemon (GtkWidget * widget, gpointer data) |
389 | startGNUnetSetup(TRUE); | 379 | { |
380 | startGNUnetSetup (TRUE); | ||
390 | } | 381 | } |
391 | 382 | ||
392 | /** | 383 | /** |
393 | * Launch 'gnunet-setup -d gconfig' with needed rights | 384 | * Launch 'gnunet-setup -d gconfig' with needed rights |
394 | */ | 385 | */ |
395 | void on_startDaemonConfTool_clicked_daemon(GtkWidget * widget, | 386 | void |
396 | gpointer data) { | 387 | on_startDaemonConfTool_clicked_daemon (GtkWidget * widget, gpointer data) |
397 | startGNUnetSetup(FALSE); | 388 | { |
389 | startGNUnetSetup (FALSE); | ||
398 | } | 390 | } |
391 | |||
399 | /* end of daemon.c */ | 392 | /* end of daemon.c */ |
diff --git a/src/plugins/fs/collection.c b/src/plugins/fs/collection.c index efcb1b98..05cc566a 100644 --- a/src/plugins/fs/collection.c +++ b/src/plugins/fs/collection.c | |||
@@ -33,143 +33,133 @@ | |||
33 | #include <GNUnet/gnunet_collection_lib.h> | 33 | #include <GNUnet/gnunet_collection_lib.h> |
34 | #include <extractor.h> | 34 | #include <extractor.h> |
35 | 35 | ||
36 | static GladeXML * metaXML; | 36 | static GladeXML *metaXML; |
37 | 37 | ||
38 | void on_collectionDialogMetaDataAddButton_clicked_fs(gpointer dummy, | 38 | void |
39 | GtkWidget * uploadButton) { | 39 | on_collectionDialogMetaDataAddButton_clicked_fs (gpointer dummy, |
40 | handleMetaDataListUpdate(metaXML, | 40 | GtkWidget * uploadButton) |
41 | "collectionMetaDataTypeComboBox", | 41 | { |
42 | "collectionMetaDataValueEntry", | 42 | handleMetaDataListUpdate (metaXML, |
43 | "collectionMetaDataTreeView"); | 43 | "collectionMetaDataTypeComboBox", |
44 | "collectionMetaDataValueEntry", | ||
45 | "collectionMetaDataTreeView"); | ||
44 | } | 46 | } |
45 | 47 | ||
46 | 48 | ||
47 | void createCollection_clicked_fs(GtkWidget * dummy1, | 49 | void |
48 | GtkWidget * dummy2) { | 50 | createCollection_clicked_fs (GtkWidget * dummy1, GtkWidget * dummy2) |
49 | const char * collectionName; | 51 | { |
50 | const char * updateIntervalString; | 52 | const char *collectionName; |
51 | GtkWidget * w; | 53 | const char *updateIntervalString; |
52 | GtkWidget * nameLine; | 54 | GtkWidget *w; |
53 | GtkWidget * dialog; | 55 | GtkWidget *nameLine; |
54 | GtkWidget * spin; | 56 | GtkWidget *dialog; |
55 | struct ECRS_MetaData * meta; | 57 | GtkWidget *spin; |
56 | struct ECRS_URI * root; | 58 | struct ECRS_MetaData *meta; |
59 | struct ECRS_URI *root; | ||
57 | TIME_T updateInterval; | 60 | TIME_T updateInterval; |
58 | 61 | ||
59 | metaXML | 62 | metaXML |
60 | = glade_xml_new(getGladeFileName(), | 63 | = glade_xml_new (getGladeFileName (), |
61 | "createCollectionDialog", | 64 | "createCollectionDialog", PACKAGE_NAME); |
62 | PACKAGE_NAME); | 65 | connectGladeWithPlugins (metaXML); |
63 | connectGladeWithPlugins(metaXML); | 66 | dialog = glade_xml_get_widget (metaXML, "createCollectionDialog"); |
64 | dialog = glade_xml_get_widget(metaXML, | 67 | createMetaDataListTreeView (metaXML, |
65 | "createCollectionDialog"); | 68 | "collectionMetaDataTreeView", NULL, NULL); |
66 | createMetaDataListTreeView(metaXML, | 69 | createMetaTypeComboBox (metaXML, "collectionMetaDataTypeComboBox"); |
67 | "collectionMetaDataTreeView", | 70 | gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); |
68 | NULL, | 71 | if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) |
69 | NULL); | 72 | { |
70 | createMetaTypeComboBox(metaXML, | 73 | updateIntervalString |
71 | "collectionMetaDataTypeComboBox"); | 74 | = getEntryLineValue (metaXML, |
72 | gtk_dialog_set_default_response(GTK_DIALOG(dialog), | 75 | "collectionUpdateIntervalComboBoxEntry"); |
73 | GTK_RESPONSE_OK); | 76 | if (0 == strcmp (_("--sporadic update--"), updateIntervalString)) |
74 | if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) { | 77 | updateInterval = ECRS_SBLOCK_UPDATE_SPORADIC; |
75 | updateIntervalString | 78 | else if (0 == strcmp (_("--no update--"), updateIntervalString)) |
76 | = getEntryLineValue(metaXML, | 79 | updateInterval = ECRS_SBLOCK_UPDATE_NONE; |
77 | "collectionUpdateIntervalComboBoxEntry"); | 80 | else if (OK != parseTime (updateIntervalString, &updateInterval)) |
78 | if (0 == strcmp(_("--sporadic update--"), | 81 | { |
79 | updateIntervalString)) | 82 | gtk_widget_destroy (dialog); |
80 | updateInterval = ECRS_SBLOCK_UPDATE_SPORADIC; | 83 | UNREF (metaXML); |
81 | else if (0 == strcmp(_("--no update--"), | 84 | metaXML = NULL; |
82 | updateIntervalString)) | 85 | dialog = gtk_message_dialog_new |
83 | updateInterval = ECRS_SBLOCK_UPDATE_NONE; | 86 | (NULL, |
84 | else if (OK != parseTime(updateIntervalString, | 87 | GTK_DIALOG_MODAL, |
85 | &updateInterval)) { | 88 | GTK_MESSAGE_ERROR, |
86 | gtk_widget_destroy(dialog); | 89 | GTK_BUTTONS_CLOSE, _("Failed to parse given time interval!")); |
87 | UNREF(metaXML); | 90 | gtk_dialog_run (GTK_DIALOG (dialog)); |
88 | metaXML = NULL; | 91 | gtk_widget_destroy (dialog); |
89 | dialog = gtk_message_dialog_new | 92 | return; |
90 | (NULL, | 93 | } |
91 | GTK_DIALOG_MODAL, | 94 | meta = getMetaDataFromList (metaXML, |
92 | GTK_MESSAGE_ERROR, | 95 | "collectionMetaDataTreeView", NULL); |
93 | GTK_BUTTONS_CLOSE, | 96 | spin = glade_xml_get_widget (metaXML, "collectionAnonymityLevel"); |
94 | _("Failed to parse given time interval!")); | 97 | nameLine = glade_xml_get_widget (metaXML, "collectionIdentifierEntry"); |
95 | gtk_dialog_run(GTK_DIALOG(dialog)); | 98 | collectionName = gtk_entry_get_text (GTK_ENTRY (nameLine)); |
96 | gtk_widget_destroy(dialog); | 99 | root = NULL; |
97 | return; | 100 | if (OK == CO_startCollection (gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (spin)), 1000, /* priority */ |
101 | updateInterval, collectionName, meta)) | ||
102 | { | ||
103 | w = glade_xml_get_widget (getMainXML (), "createCollection"); | ||
104 | gtk_widget_set_sensitive (w, FALSE); | ||
105 | w = glade_xml_get_widget (getMainXML (), "deleteCollection"); | ||
106 | gtk_widget_set_sensitive (w, TRUE); | ||
107 | } | ||
108 | else | ||
109 | { | ||
110 | GtkWidget *dialog; | ||
111 | |||
112 | dialog = gtk_message_dialog_new | ||
113 | (NULL, | ||
114 | GTK_DIALOG_MODAL, | ||
115 | GTK_MESSAGE_ERROR, | ||
116 | GTK_BUTTONS_CLOSE, | ||
117 | _("Failed to start collection `%s' (consult logs)."), | ||
118 | collectionName); | ||
119 | gtk_dialog_run (GTK_DIALOG (dialog)); | ||
120 | gtk_widget_destroy (dialog); | ||
121 | } | ||
122 | ECRS_freeMetaData (meta); | ||
98 | } | 123 | } |
99 | meta = getMetaDataFromList(metaXML, | 124 | gtk_widget_destroy (dialog); |
100 | "collectionMetaDataTreeView", | 125 | UNREF (metaXML); |
101 | NULL); | ||
102 | spin = glade_xml_get_widget(metaXML, | ||
103 | "collectionAnonymityLevel"); | ||
104 | nameLine = glade_xml_get_widget(metaXML, | ||
105 | "collectionIdentifierEntry"); | ||
106 | collectionName | ||
107 | = gtk_entry_get_text(GTK_ENTRY(nameLine)); | ||
108 | root = NULL; | ||
109 | if (OK == CO_startCollection(gtk_spin_button_get_value_as_int | ||
110 | (GTK_SPIN_BUTTON(spin)), | ||
111 | 1000, /* priority */ | ||
112 | updateInterval, | ||
113 | collectionName, | ||
114 | meta)) { | ||
115 | w = glade_xml_get_widget(getMainXML(), | ||
116 | "createCollection"); | ||
117 | gtk_widget_set_sensitive(w, FALSE); | ||
118 | w = glade_xml_get_widget(getMainXML(), | ||
119 | "deleteCollection"); | ||
120 | gtk_widget_set_sensitive(w, TRUE); | ||
121 | } else { | ||
122 | GtkWidget * dialog; | ||
123 | |||
124 | dialog = gtk_message_dialog_new | ||
125 | (NULL, | ||
126 | GTK_DIALOG_MODAL, | ||
127 | GTK_MESSAGE_ERROR, | ||
128 | GTK_BUTTONS_CLOSE, | ||
129 | _("Failed to start collection `%s' (consult logs)."), | ||
130 | collectionName); | ||
131 | gtk_dialog_run(GTK_DIALOG(dialog)); | ||
132 | gtk_widget_destroy(dialog); | ||
133 | } | ||
134 | ECRS_freeMetaData(meta); | ||
135 | } | ||
136 | gtk_widget_destroy(dialog); | ||
137 | UNREF(metaXML); | ||
138 | metaXML = NULL; | 126 | metaXML = NULL; |
139 | } | 127 | } |
140 | 128 | ||
141 | void deleteCollection_clicked_fs(GtkWidget * dummy1, | 129 | void |
142 | GtkWidget * dummy2) { | 130 | deleteCollection_clicked_fs (GtkWidget * dummy1, GtkWidget * dummy2) |
143 | GtkWidget * w; | 131 | { |
144 | 132 | GtkWidget *w; | |
145 | if (OK == CO_stopCollection()) { | 133 | |
146 | w = glade_xml_get_widget(getMainXML(), | 134 | if (OK == CO_stopCollection ()) |
147 | "createCollection"); | 135 | { |
148 | gtk_widget_set_sensitive(w, TRUE); | 136 | w = glade_xml_get_widget (getMainXML (), "createCollection"); |
149 | w = glade_xml_get_widget(getMainXML(), | 137 | gtk_widget_set_sensitive (w, TRUE); |
150 | "deleteCollection"); | 138 | w = glade_xml_get_widget (getMainXML (), "deleteCollection"); |
151 | gtk_widget_set_sensitive(w, FALSE); | 139 | gtk_widget_set_sensitive (w, FALSE); |
152 | infoMessage(NO, | 140 | infoMessage (NO, _("Collection stopped.\n")); |
153 | _("Collection stopped.\n")); | 141 | } |
154 | } else { | 142 | else |
155 | infoMessage(YES, | 143 | { |
156 | _("Failed to stop collection (consult logs).\n")); | 144 | infoMessage (YES, _("Failed to stop collection (consult logs).\n")); |
157 | } | 145 | } |
158 | } | 146 | } |
159 | 147 | ||
160 | void fs_collection_start() { | 148 | void |
161 | GtkWidget * w; | 149 | fs_collection_start () |
162 | char * h; | 150 | { |
163 | 151 | GtkWidget *w; | |
164 | h = CO_getCollection(); | 152 | char *h; |
165 | if (NULL != h) { | 153 | |
166 | w = glade_xml_get_widget(getMainXML(), | 154 | h = CO_getCollection (); |
167 | "createCollection"); | 155 | if (NULL != h) |
168 | FREE(h); | 156 | { |
169 | } else | 157 | w = glade_xml_get_widget (getMainXML (), "createCollection"); |
170 | w = glade_xml_get_widget(getMainXML(), | 158 | FREE (h); |
171 | "deleteCollection"); | 159 | } |
172 | gtk_widget_set_sensitive(w, FALSE); | 160 | else |
161 | w = glade_xml_get_widget (getMainXML (), "deleteCollection"); | ||
162 | gtk_widget_set_sensitive (w, FALSE); | ||
173 | } | 163 | } |
174 | 164 | ||
175 | /* end of collection.c */ | 165 | /* end of collection.c */ |
diff --git a/src/plugins/fs/collection.h b/src/plugins/fs/collection.h index 0e4ba1e7..c236c4dc 100644 --- a/src/plugins/fs/collection.h +++ b/src/plugins/fs/collection.h | |||
@@ -29,6 +29,6 @@ | |||
29 | 29 | ||
30 | #include <GNUnet/gnunet_util.h> | 30 | #include <GNUnet/gnunet_util.h> |
31 | 31 | ||
32 | void fs_collection_start(void); | 32 | void fs_collection_start (void); |
33 | 33 | ||
34 | #endif | 34 | #endif |
diff --git a/src/plugins/fs/content_tracking.c b/src/plugins/fs/content_tracking.c index 1767432d..d61b343b 100644 --- a/src/plugins/fs/content_tracking.c +++ b/src/plugins/fs/content_tracking.c | |||
@@ -37,64 +37,62 @@ | |||
37 | #include <GNUnet/gnunet_namespace_lib.h> | 37 | #include <GNUnet/gnunet_namespace_lib.h> |
38 | #include <extractor.h> | 38 | #include <extractor.h> |
39 | 39 | ||
40 | static void * clearContentList(void * mdl) { | 40 | static void * |
41 | GtkTreeModel * model = GTK_TREE_MODEL(mdl); | 41 | clearContentList (void *mdl) |
42 | struct ECRS_URI * uri; | 42 | { |
43 | struct ECRS_MetaData * meta; | 43 | GtkTreeModel *model = GTK_TREE_MODEL (mdl); |
44 | struct ECRS_URI *uri; | ||
45 | struct ECRS_MetaData *meta; | ||
44 | GtkTreeIter iter; | 46 | GtkTreeIter iter; |
45 | 47 | ||
46 | DEBUG_BEGIN(); | 48 | DEBUG_BEGIN (); |
47 | if (gtk_tree_model_get_iter_first(model, | 49 | if (gtk_tree_model_get_iter_first (model, &iter)) |
48 | &iter)) { | 50 | { |
49 | do { | 51 | do |
50 | gtk_tree_model_get(model, | 52 | { |
51 | &iter, | 53 | gtk_tree_model_get (model, |
52 | NAMESPACE_URI, &uri, | 54 | &iter, |
53 | NAMESPACE_META, &meta, | 55 | NAMESPACE_URI, &uri, NAMESPACE_META, &meta, -1); |
54 | -1); | 56 | ECRS_freeUri (uri); |
55 | ECRS_freeUri(uri); | 57 | ECRS_freeMetaData (meta); |
56 | ECRS_freeMetaData(meta); | 58 | gtk_list_store_set (GTK_LIST_STORE (model), |
57 | gtk_list_store_set(GTK_LIST_STORE(model), | 59 | &iter, |
58 | &iter, | 60 | NAMESPACE_URI, NULL, NAMESPACE_META, NULL, -1); |
59 | NAMESPACE_URI, NULL, | 61 | } |
60 | NAMESPACE_META, NULL, | 62 | while (gtk_list_store_remove (GTK_LIST_STORE (model), &iter)); |
61 | -1); | 63 | } |
62 | } while (gtk_list_store_remove(GTK_LIST_STORE(model), | 64 | DEBUG_END (); |
63 | &iter)); | ||
64 | } | ||
65 | DEBUG_END(); | ||
66 | return NULL; | 65 | return NULL; |
67 | } | 66 | } |
68 | 67 | ||
69 | 68 | ||
70 | void on_clearAvailableContentButton_clicked_fs(GtkWidget * dummy1, | 69 | void |
71 | GtkWidget * dummy2) { | 70 | on_clearAvailableContentButton_clicked_fs (GtkWidget * dummy1, |
72 | GtkWidget * contentList; | 71 | GtkWidget * dummy2) |
73 | GtkTreeModel * model; | 72 | { |
74 | 73 | GtkWidget *contentList; | |
75 | DEBUG_BEGIN(); | 74 | GtkTreeModel *model; |
76 | contentList | 75 | |
77 | = glade_xml_get_widget(getMainXML(), | 76 | DEBUG_BEGIN (); |
78 | "availableContentList"); | 77 | contentList = glade_xml_get_widget (getMainXML (), "availableContentList"); |
79 | model | 78 | model = gtk_tree_view_get_model (GTK_TREE_VIEW (contentList)); |
80 | = gtk_tree_view_get_model(GTK_TREE_VIEW(contentList)); | 79 | URITRACK_clearTrackedURIS (ectx, cfg); |
81 | URITRACK_clearTrackedURIS(ectx, | 80 | gtkSaveCall (&clearContentList, model); |
82 | cfg); | 81 | DEBUG_END (); |
83 | gtkSaveCall(&clearContentList, model); | ||
84 | DEBUG_END(); | ||
85 | } | 82 | } |
86 | 83 | ||
87 | void on_trackingCheckButton_toggled_fs(GtkWidget * dummy1, | 84 | void |
88 | GtkWidget * dummy2) { | 85 | on_trackingCheckButton_toggled_fs (GtkWidget * dummy1, GtkWidget * dummy2) |
89 | GtkWidget * trackCheckButton; | 86 | { |
87 | GtkWidget *trackCheckButton; | ||
90 | 88 | ||
91 | trackCheckButton | 89 | trackCheckButton |
92 | = glade_xml_get_widget(getMainXML(), | 90 | = glade_xml_get_widget (getMainXML (), "trackingCheckButton"); |
93 | "trackingCheckButton"); | 91 | URITRACK_trackURIS (ectx, |
94 | URITRACK_trackURIS(ectx, | 92 | cfg, |
95 | cfg, | 93 | gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON |
96 | gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(trackCheckButton)) == TRUE ? | 94 | (trackCheckButton)) == |
97 | YES : NO); | 95 | TRUE ? YES : NO); |
98 | } | 96 | } |
99 | 97 | ||
100 | 98 | ||
@@ -104,63 +102,62 @@ void on_trackingCheckButton_toggled_fs(GtkWidget * dummy1, | |||
104 | * content model. Check that it is not already | 102 | * content model. Check that it is not already |
105 | * present! | 103 | * present! |
106 | */ | 104 | */ |
107 | static void * updateView(void * cls) { | 105 | static void * |
108 | const ECRS_FileInfo * fi = cls; | 106 | updateView (void *cls) |
107 | { | ||
108 | const ECRS_FileInfo *fi = cls; | ||
109 | GtkTreeIter iter; | 109 | GtkTreeIter iter; |
110 | char * filename; | 110 | char *filename; |
111 | char * uriString; | 111 | char *uriString; |
112 | unsigned long long size; | 112 | unsigned long long size; |
113 | char * size_h; | 113 | char *size_h; |
114 | GtkWidget * contentList; | 114 | GtkWidget *contentList; |
115 | GtkTreeModel * model; | 115 | GtkTreeModel *model; |
116 | 116 | ||
117 | contentList | 117 | contentList = glade_xml_get_widget (getMainXML (), "availableContentList"); |
118 | = glade_xml_get_widget(getMainXML(), | 118 | model = gtk_tree_view_get_model (GTK_TREE_VIEW (contentList)); |
119 | "availableContentList"); | 119 | filename = ECRS_getFirstFromMetaData (fi->meta, |
120 | model | 120 | EXTRACTOR_FILENAME, |
121 | = gtk_tree_view_get_model(GTK_TREE_VIEW(contentList)); | 121 | EXTRACTOR_TITLE, |
122 | filename = ECRS_getFirstFromMetaData(fi->meta, | 122 | EXTRACTOR_DESCRIPTION, |
123 | EXTRACTOR_FILENAME, | 123 | EXTRACTOR_SUBJECT, |
124 | EXTRACTOR_TITLE, | 124 | EXTRACTOR_ARTIST, |
125 | EXTRACTOR_DESCRIPTION, | 125 | EXTRACTOR_AUTHOR, |
126 | EXTRACTOR_SUBJECT, | 126 | EXTRACTOR_PUBLISHER, |
127 | EXTRACTOR_ARTIST, | 127 | EXTRACTOR_CREATOR, |
128 | EXTRACTOR_AUTHOR, | 128 | EXTRACTOR_PRODUCER, |
129 | EXTRACTOR_PUBLISHER, | 129 | EXTRACTOR_UNKNOWN, -1); |
130 | EXTRACTOR_CREATOR, | 130 | if (filename == NULL) |
131 | EXTRACTOR_PRODUCER, | 131 | { |
132 | EXTRACTOR_UNKNOWN, | 132 | filename = STRDUP (_("no name given")); |
133 | -1); | 133 | } |
134 | if (filename == NULL) { | 134 | else |
135 | filename = STRDUP(_("no name given")); | 135 | { |
136 | } else { | 136 | char *dotdot; |
137 | char * dotdot; | 137 | |
138 | 138 | while (NULL != (dotdot = strstr (filename, ".."))) | |
139 | while (NULL != (dotdot = strstr(filename, ".."))) | 139 | dotdot[0] = dotdot[1] = '_'; |
140 | dotdot[0] = dotdot[1] = '_'; | 140 | filename = validate_utf8 (filename); |
141 | filename = validate_utf8(filename); | 141 | } |
142 | } | 142 | |
143 | 143 | if (ECRS_isFileUri (fi->uri)) | |
144 | if (ECRS_isFileUri(fi->uri)) | 144 | size = ECRS_fileSize (fi->uri); |
145 | size = ECRS_fileSize(fi->uri); | ||
146 | else | 145 | else |
147 | size = 0; | 146 | size = 0; |
148 | uriString = ECRS_uriToString(fi->uri); | 147 | uriString = ECRS_uriToString (fi->uri); |
149 | gtk_list_store_append(GTK_LIST_STORE(model), | 148 | gtk_list_store_append (GTK_LIST_STORE (model), &iter); |
150 | &iter); | 149 | size_h = string_get_fancy_byte_size (size); |
151 | size_h = string_get_fancy_byte_size(size); | 150 | gtk_list_store_set (GTK_LIST_STORE (model), |
152 | gtk_list_store_set(GTK_LIST_STORE(model), | 151 | &iter, |
153 | &iter, | 152 | NAMESPACE_FILENAME, filename, |
154 | NAMESPACE_FILENAME, filename, | 153 | NAMESPACE_SIZE, size, |
155 | NAMESPACE_SIZE, size, | 154 | NAMESPACE_HSIZE, size_h, |
156 | NAMESPACE_HSIZE, size_h, | 155 | NAMESPACE_URISTRING, uriString, |
157 | NAMESPACE_URISTRING, uriString, | 156 | NAMESPACE_URI, ECRS_dupUri (fi->uri), |
158 | NAMESPACE_URI, ECRS_dupUri(fi->uri), | 157 | NAMESPACE_META, ECRS_dupMetaData (fi->meta), -1); |
159 | NAMESPACE_META, ECRS_dupMetaData(fi->meta), | 158 | FREE (size_h); |
160 | -1); | 159 | FREE (filename); |
161 | FREE(size_h); | 160 | FREE (uriString); |
162 | FREE(filename); | ||
163 | FREE(uriString); | ||
164 | return NULL; | 161 | return NULL; |
165 | } | 162 | } |
166 | 163 | ||
@@ -169,10 +166,10 @@ static void * updateView(void * cls) { | |||
169 | * content model. Check that it is not already | 166 | * content model. Check that it is not already |
170 | * present! | 167 | * present! |
171 | */ | 168 | */ |
172 | int updateViewSave(const ECRS_FileInfo * fi, | 169 | int |
173 | const HashCode512 * key, | 170 | updateViewSave (const ECRS_FileInfo * fi, |
174 | int isRoot, | 171 | const HashCode512 * key, int isRoot, void *closure) |
175 | void * closure) { | 172 | { |
176 | gtkSaveCall(&updateView, (void*) fi); | 173 | gtkSaveCall (&updateView, (void *) fi); |
177 | return OK; | 174 | return OK; |
178 | } | 175 | } |
diff --git a/src/plugins/fs/content_tracking.h b/src/plugins/fs/content_tracking.h index 075810aa..44e7d92b 100644 --- a/src/plugins/fs/content_tracking.h +++ b/src/plugins/fs/content_tracking.h | |||
@@ -34,9 +34,7 @@ | |||
34 | * content model. Check that it is not already | 34 | * content model. Check that it is not already |
35 | * present! | 35 | * present! |
36 | */ | 36 | */ |
37 | int updateViewSave(const ECRS_FileInfo * fi, | 37 | int updateViewSave (const ECRS_FileInfo * fi, |
38 | const HashCode512 * key, | 38 | const HashCode512 * key, int isRoot, void *closure); |
39 | int isRoot, | ||
40 | void * closure); | ||
41 | 39 | ||
42 | #endif | 40 | #endif |
diff --git a/src/plugins/fs/directory.c b/src/plugins/fs/directory.c index ecaf34b8..12ca0bff 100644 --- a/src/plugins/fs/directory.c +++ b/src/plugins/fs/directory.c | |||
@@ -37,135 +37,114 @@ | |||
37 | 37 | ||
38 | #ifndef MINGW | 38 | #ifndef MINGW |
39 | static char * | 39 | static char * |
40 | selectFile() { | 40 | selectFile () |
41 | GladeXML * uploadXML; | 41 | { |
42 | GtkFileChooser * dialog; | 42 | GladeXML *uploadXML; |
43 | char * ret; | 43 | GtkFileChooser *dialog; |
44 | char *ret; | ||
44 | 45 | ||
45 | uploadXML | 46 | uploadXML |
46 | = glade_xml_new(getGladeFileName(), | 47 | = glade_xml_new (getGladeFileName (), |
47 | "openDirectoryFileDialog", | 48 | "openDirectoryFileDialog", PACKAGE_NAME); |
48 | PACKAGE_NAME); | 49 | connectGladeWithPlugins (uploadXML); |
49 | connectGladeWithPlugins(uploadXML); | 50 | dialog = GTK_FILE_CHOOSER (glade_xml_get_widget (uploadXML, |
50 | dialog = GTK_FILE_CHOOSER(glade_xml_get_widget(uploadXML, | 51 | "openDirectoryFileDialog")); |
51 | "openDirectoryFileDialog")); | 52 | if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_CANCEL) |
52 | if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_CANCEL) | 53 | ret = gtk_file_chooser_get_filename (dialog); |
53 | ret = gtk_file_chooser_get_filename(dialog); | ||
54 | else | 54 | else |
55 | ret = NULL; | 55 | ret = NULL; |
56 | gtk_widget_destroy(GTK_WIDGET(dialog)); | 56 | gtk_widget_destroy (GTK_WIDGET (dialog)); |
57 | UNREF(uploadXML); | 57 | UNREF (uploadXML); |
58 | return ret; | 58 | return ret; |
59 | } | 59 | } |
60 | #else /* MINGW */ | 60 | #else /* MINGW */ |
61 | static char * | 61 | static char * |
62 | selectFile() { | 62 | selectFile () |
63 | return plibc_ChooseFile(_("Choose the directory you want to open."), | 63 | { |
64 | OFN_FILEMUSTEXIST | OFN_SHAREAWARE); | 64 | return plibc_ChooseFile (_("Choose the directory you want to open."), |
65 | OFN_FILEMUSTEXIST | OFN_SHAREAWARE); | ||
65 | } | 66 | } |
66 | #endif /* MINGW */ | 67 | #endif /* MINGW */ |
67 | 68 | ||
68 | static int | 69 | static int |
69 | spcb(const ECRS_FileInfo * fi, | 70 | spcb (const ECRS_FileInfo * fi, |
70 | const HashCode512 * key, | 71 | const HashCode512 * key, int isRoot, void *closure) |
71 | int isRoot, | 72 | { |
72 | void * closure) { | 73 | SearchList *list = closure; |
73 | SearchList * list = closure; | 74 | fs_search_result_received (list, fi, list->uri); |
74 | fs_search_result_received(list, | ||
75 | fi, | ||
76 | list->uri); | ||
77 | return OK; | 75 | return OK; |
78 | } | 76 | } |
79 | 77 | ||
80 | 78 | ||
81 | void on_open_menu_activate_fs(GtkWidget * dummy1, | 79 | void |
82 | GtkWidget * dummy2) { | 80 | on_open_menu_activate_fs (GtkWidget * dummy1, GtkWidget * dummy2) |
83 | char * dn; | 81 | { |
84 | char * directory_data; | 82 | char *dn; |
83 | char *directory_data; | ||
85 | unsigned long long directory_data_len; | 84 | unsigned long long directory_data_len; |
86 | size_t dlen; | 85 | size_t dlen; |
87 | struct ECRS_MetaData * md; | 86 | struct ECRS_MetaData *md; |
88 | int fd; | 87 | int fd; |
89 | SearchList * list; | 88 | SearchList *list; |
90 | struct ECRS_URI * uri; | 89 | struct ECRS_URI *uri; |
91 | const char * kws[2]; | 90 | const char *kws[2]; |
92 | GtkNotebook * notebook; | 91 | GtkNotebook *notebook; |
93 | 92 | ||
94 | dn = selectFile(); | 93 | dn = selectFile (); |
95 | if (dn == NULL) | 94 | if (dn == NULL) |
96 | return; | 95 | return; |
97 | if ( (YES != disk_file_test(NULL, | 96 | if ((YES != disk_file_test (NULL, |
98 | dn)) || | 97 | dn)) || |
99 | (OK != disk_file_size(NULL, | 98 | (OK != disk_file_size (NULL, dn, &directory_data_len, YES))) |
100 | dn, | 99 | { |
101 | &directory_data_len, | 100 | addLogEntry (_("Error accessing file `%s'."), dn); |
102 | YES)) ) { | 101 | FREE (dn); |
103 | addLogEntry(_("Error accessing file `%s'."), | 102 | return; |
104 | dn); | 103 | } |
105 | FREE(dn); | 104 | fd = disk_file_open (NULL, dn, O_LARGEFILE | O_RDONLY); |
106 | return; | 105 | if (fd == -1) |
107 | } | 106 | { |
108 | fd = disk_file_open(NULL, | 107 | addLogEntry (_("Error opening file `%s'."), dn); |
109 | dn, | 108 | FREE (dn); |
110 | O_LARGEFILE | O_RDONLY); | 109 | return; |
111 | if (fd == -1) { | 110 | } |
112 | addLogEntry(_("Error opening file `%s'."), | ||
113 | dn); | ||
114 | FREE(dn); | ||
115 | return; | ||
116 | } | ||
117 | dlen = (size_t) directory_data_len; | 111 | dlen = (size_t) directory_data_len; |
118 | directory_data = MMAP(NULL, | 112 | directory_data = MMAP (NULL, dlen, PROT_READ, MAP_SHARED, fd, 0); |
119 | dlen, | 113 | if (directory_data == MAP_FAILED) |
120 | PROT_READ, | 114 | { |
121 | MAP_SHARED, | 115 | addLogEntry (_("Error mapping file `%s' into memory."), dn); |
122 | fd, | 116 | CLOSE (fd); |
123 | 0); | 117 | FREE (dn); |
124 | if (directory_data == MAP_FAILED) { | 118 | return; |
125 | addLogEntry(_("Error mapping file `%s' into memory."), | 119 | } |
126 | dn); | ||
127 | CLOSE(fd); | ||
128 | FREE(dn); | ||
129 | return; | ||
130 | } | ||
131 | kws[0] = dn; | 120 | kws[0] = dn; |
132 | kws[1] = NULL; | 121 | kws[1] = NULL; |
133 | uri = ECRS_keywordsToUri(kws); | 122 | uri = ECRS_keywordsToUri (kws); |
134 | md = NULL; | 123 | md = NULL; |
135 | list = fs_search_started(NULL, | 124 | list = fs_search_started (NULL, uri, 0, 0, NULL, FSUI_COMPLETED); |
136 | uri, | 125 | ECRS_freeUri (uri); |
137 | 0, | 126 | ECRS_listDirectory (NULL, |
138 | 0, | 127 | directory_data, directory_data_len, &md, &spcb, list); |
139 | NULL, | ||
140 | FSUI_COMPLETED); | ||
141 | ECRS_freeUri(uri); | ||
142 | ECRS_listDirectory(NULL, | ||
143 | directory_data, | ||
144 | directory_data_len, | ||
145 | &md, | ||
146 | &spcb, | ||
147 | list); | ||
148 | if (md != NULL) | 128 | if (md != NULL) |
149 | ECRS_freeMetaData(md); | 129 | ECRS_freeMetaData (md); |
150 | MUNMAP(directory_data, dlen); | 130 | MUNMAP (directory_data, dlen); |
151 | CLOSE(fd); | 131 | CLOSE (fd); |
152 | FREE(dn); | 132 | FREE (dn); |
153 | 133 | ||
154 | /* switch view -- select directory */ | 134 | /* switch view -- select directory */ |
155 | notebook | 135 | notebook |
156 | = GTK_NOTEBOOK(glade_xml_get_widget(getMainXML(), | 136 | = GTK_NOTEBOOK (glade_xml_get_widget (getMainXML (), "downloadNotebook")); |
157 | "downloadNotebook")); | 137 | gtk_notebook_set_current_page (notebook, |
158 | gtk_notebook_set_current_page(notebook, | 138 | gtk_notebook_page_num (notebook, |
159 | gtk_notebook_page_num(notebook, | 139 | list->searchpage)); |
160 | list->searchpage)); | ||
161 | 140 | ||
162 | notebook | 141 | notebook |
163 | = GTK_NOTEBOOK(glade_xml_get_widget(getMainXML(), | 142 | = GTK_NOTEBOOK (glade_xml_get_widget (getMainXML (), "fsnotebook")); |
164 | "fsnotebook")); | 143 | gtk_notebook_set_current_page (notebook, |
165 | gtk_notebook_set_current_page(notebook, | 144 | gtk_notebook_page_num (notebook, |
166 | gtk_notebook_page_num(notebook, | 145 | glade_xml_get_widget |
167 | glade_xml_get_widget(getMainXML(), | 146 | (getMainXML (), |
168 | "fsdownloadvbox"))); | 147 | "fsdownloadvbox"))); |
169 | } | 148 | } |
170 | 149 | ||
171 | /* end of directory.c */ | 150 | /* end of directory.c */ |
diff --git a/src/plugins/fs/download.c b/src/plugins/fs/download.c index 2d825f71..c58a18e4 100644 --- a/src/plugins/fs/download.c +++ b/src/plugins/fs/download.c | |||
@@ -39,136 +39,113 @@ | |||
39 | * by the download list. | 39 | * by the download list. |
40 | */ | 40 | */ |
41 | static int | 41 | static int |
42 | addFilesToDirectory(const ECRS_FileInfo * fi, | 42 | addFilesToDirectory (const ECRS_FileInfo * fi, |
43 | const HashCode512 * key, | 43 | const HashCode512 * key, int isRoot, void *closure) |
44 | int isRoot, | 44 | { |
45 | void * closure) { | 45 | DownloadList *list = closure; |
46 | DownloadList * list = closure; | ||
47 | GtkTreeIter iter; | 46 | GtkTreeIter iter; |
48 | GtkTreeIter child; | 47 | GtkTreeIter child; |
49 | int i; | 48 | int i; |
50 | GtkTreePath * path; | 49 | GtkTreePath *path; |
51 | GtkTreeModel * model; | 50 | GtkTreeModel *model; |
52 | 51 | ||
53 | if (isRoot == YES) | 52 | if (isRoot == YES) |
54 | return OK; | 53 | return OK; |
55 | if (! gtk_tree_row_reference_valid(list->searchViewRowReference)) | 54 | if (!gtk_tree_row_reference_valid (list->searchViewRowReference)) |
56 | return SYSERR; | 55 | return SYSERR; |
57 | model = GTK_TREE_MODEL(list->searchList->tree); | 56 | model = GTK_TREE_MODEL (list->searchList->tree); |
58 | path = gtk_tree_row_reference_get_path(list->searchViewRowReference); | 57 | path = gtk_tree_row_reference_get_path (list->searchViewRowReference); |
59 | if (path == NULL) { | 58 | if (path == NULL) |
60 | GE_BREAK(ectx, 0); | 59 | { |
61 | return SYSERR; | 60 | GE_BREAK (ectx, 0); |
62 | } | 61 | return SYSERR; |
63 | gtk_tree_model_get_iter(model, | 62 | } |
64 | &iter, | 63 | gtk_tree_model_get_iter (model, &iter, path); |
65 | path); | 64 | gtk_tree_path_free (path); |
66 | gtk_tree_path_free(path); | ||
67 | /* check for existing entry -- this function maybe called multiple | 65 | /* check for existing entry -- this function maybe called multiple |
68 | times for the same directory entry */ | 66 | times for the same directory entry */ |
69 | for (i=gtk_tree_model_iter_n_children(model, | 67 | for (i = gtk_tree_model_iter_n_children (model, &iter) - 1; i >= 0; i--) |
70 | &iter)-1;i>=0;i--) { | 68 | { |
71 | if (TRUE == gtk_tree_model_iter_nth_child(model, | 69 | if (TRUE == gtk_tree_model_iter_nth_child (model, &child, &iter, i)) |
72 | &child, | 70 | { |
73 | &iter, | 71 | struct ECRS_URI *uri; |
74 | i)) { | 72 | uri = NULL; |
75 | struct ECRS_URI * uri; | 73 | gtk_tree_model_get (model, &child, SEARCH_URI, &uri, -1); |
76 | uri = NULL; | 74 | if ((uri != NULL) && (ECRS_equalsUri (uri, fi->uri))) |
77 | gtk_tree_model_get(model, | 75 | return OK; |
78 | &child, | 76 | } |
79 | SEARCH_URI, &uri, | 77 | } |
80 | -1); | 78 | gtk_tree_store_append (GTK_TREE_STORE (model), &child, &iter); |
81 | if ( (uri != NULL) && | 79 | addEntryToSearchTree (list->searchList, list, fi, &child); |
82 | (ECRS_equalsUri(uri, | ||
83 | fi->uri)) ) | ||
84 | return OK; | ||
85 | } | ||
86 | } | ||
87 | gtk_tree_store_append(GTK_TREE_STORE(model), | ||
88 | &child, | ||
89 | &iter); | ||
90 | addEntryToSearchTree(list->searchList, | ||
91 | list, | ||
92 | fi, | ||
93 | &child); | ||
94 | return OK; | 80 | return OK; |
95 | } | 81 | } |
96 | 82 | ||
97 | static void | 83 | static void |
98 | refreshDirectoryViewFromDisk(DownloadList * list) { | 84 | refreshDirectoryViewFromDisk (DownloadList * list) |
85 | { | ||
99 | unsigned long long size; | 86 | unsigned long long size; |
100 | char * data; | 87 | char *data; |
101 | int fd; | 88 | int fd; |
102 | char * fn; | 89 | char *fn; |
103 | struct ECRS_MetaData * meta; | 90 | struct ECRS_MetaData *meta; |
104 | struct stat buf; | 91 | struct stat buf; |
105 | const char * f; | 92 | const char *f; |
106 | 93 | ||
107 | if ( (list->is_directory != YES) || | 94 | if ((list->is_directory != YES) || |
108 | (list->searchList == NULL) || | 95 | (list->searchList == NULL) || |
109 | (list->searchViewRowReference == NULL) || | 96 | (list->searchViewRowReference == NULL) || |
110 | (! gtk_tree_row_reference_valid(list->searchViewRowReference)) ) | 97 | (!gtk_tree_row_reference_valid (list->searchViewRowReference))) |
111 | return; | 98 | return; |
112 | 99 | ||
113 | if (0 != stat(list->filename, | 100 | if (0 != stat (list->filename, &buf)) |
114 | &buf)) | ||
115 | return; | 101 | return; |
116 | if (S_ISDIR(buf.st_mode)) { | 102 | if (S_ISDIR (buf.st_mode)) |
117 | fn = MALLOC(strlen(list->filename) + strlen(GNUNET_DIRECTORY_EXT) + 1); | 103 | { |
118 | strcpy(fn, list->filename); | 104 | fn = |
119 | if (fn[strlen(fn)-1] == '/') | 105 | MALLOC (strlen (list->filename) + strlen (GNUNET_DIRECTORY_EXT) + 1); |
120 | fn[strlen(fn)-1] = '\0'; | 106 | strcpy (fn, list->filename); |
121 | strcat(fn, GNUNET_DIRECTORY_EXT); | 107 | if (fn[strlen (fn) - 1] == '/') |
122 | if (0 != stat(list->filename, | 108 | fn[strlen (fn) - 1] = '\0'; |
123 | &buf)) { | 109 | strcat (fn, GNUNET_DIRECTORY_EXT); |
124 | FREE(fn); | 110 | if (0 != stat (list->filename, &buf)) |
125 | return; | 111 | { |
112 | FREE (fn); | ||
113 | return; | ||
114 | } | ||
115 | f = fn; | ||
116 | } | ||
117 | else | ||
118 | { | ||
119 | fn = NULL; | ||
120 | f = list->filename; | ||
126 | } | 121 | } |
127 | f = fn; | ||
128 | } else { | ||
129 | fn = NULL; | ||
130 | f = list->filename; | ||
131 | } | ||
132 | size = buf.st_size; | 122 | size = buf.st_size; |
133 | if (size == 0) { | 123 | if (size == 0) |
134 | FREENONNULL(fn); | 124 | { |
135 | return; | 125 | FREENONNULL (fn); |
136 | } | 126 | return; |
137 | fd = disk_file_open(ectx, | 127 | } |
138 | list->filename, | 128 | fd = disk_file_open (ectx, list->filename, O_RDONLY); |
139 | O_RDONLY); | 129 | if (fd == -1) |
140 | if (fd == -1) { | 130 | { |
141 | FREENONNULL(fn); | 131 | FREENONNULL (fn); |
142 | return; | 132 | return; |
143 | } | 133 | } |
144 | data = MMAP(NULL, | 134 | data = MMAP (NULL, size, PROT_READ, MAP_SHARED, fd, 0); |
145 | size, | 135 | if ((data == MAP_FAILED) || (data == NULL)) |
146 | PROT_READ, | 136 | { |
147 | MAP_SHARED, | 137 | GE_LOG_STRERROR_FILE (ectx, GE_ERROR | GE_ADMIN | GE_BULK, "mmap", f); |
148 | fd, | 138 | CLOSE (fd); |
149 | 0); | 139 | FREENONNULL (fn); |
150 | if ( (data == MAP_FAILED) || | 140 | return; |
151 | (data == NULL) ) { | 141 | } |
152 | GE_LOG_STRERROR_FILE(ectx, | 142 | FREENONNULL (fn); |
153 | GE_ERROR | GE_ADMIN | GE_BULK, | ||
154 | "mmap", | ||
155 | f); | ||
156 | CLOSE(fd); | ||
157 | FREENONNULL(fn); | ||
158 | return; | ||
159 | } | ||
160 | FREENONNULL(fn); | ||
161 | meta = NULL; | 143 | meta = NULL; |
162 | ECRS_listDirectory(ectx, | 144 | ECRS_listDirectory (ectx, data, size, &meta, &addFilesToDirectory, list); |
163 | data, | 145 | MUNMAP (data, size); |
164 | size, | 146 | CLOSE (fd); |
165 | &meta, | ||
166 | &addFilesToDirectory, | ||
167 | list); | ||
168 | MUNMAP(data, size); | ||
169 | CLOSE(fd); | ||
170 | if (meta != NULL) | 147 | if (meta != NULL) |
171 | ECRS_freeMetaData(meta); | 148 | ECRS_freeMetaData (meta); |
172 | } | 149 | } |
173 | 150 | ||
174 | /** | 151 | /** |
@@ -177,162 +154,158 @@ refreshDirectoryViewFromDisk(DownloadList * list) { | |||
177 | * the download summary. | 154 | * the download summary. |
178 | */ | 155 | */ |
179 | DownloadList * | 156 | DownloadList * |
180 | fs_download_started(struct FSUI_DownloadList * fsui_dl, | 157 | fs_download_started (struct FSUI_DownloadList *fsui_dl, |
181 | DownloadList * dl_parent, | 158 | DownloadList * dl_parent, |
182 | SearchList * sl_parent, | 159 | SearchList * sl_parent, |
183 | unsigned long long total, | 160 | unsigned long long total, |
184 | unsigned int anonymityLevel, | 161 | unsigned int anonymityLevel, |
185 | const ECRS_FileInfo * fi, | 162 | const ECRS_FileInfo * fi, |
186 | const char * filename, | 163 | const char *filename, |
187 | unsigned long long completed, | 164 | unsigned long long completed, |
188 | cron_t eta, | 165 | cron_t eta, FSUI_State state) |
189 | FSUI_State state) { | 166 | { |
190 | DownloadList * list; | 167 | DownloadList *list; |
191 | GtkTreeIter iter; | 168 | GtkTreeIter iter; |
192 | GtkTreeIter piter; | 169 | GtkTreeIter piter; |
193 | GtkTreePath * path; | 170 | GtkTreePath *path; |
194 | unsigned long long size; | 171 | unsigned long long size; |
195 | char * size_h; | 172 | char *size_h; |
196 | const char * sname; | 173 | const char *sname; |
197 | int progress; | 174 | int progress; |
198 | char * uri_name; | 175 | char *uri_name; |
199 | gboolean valid; | 176 | gboolean valid; |
200 | struct ECRS_URI * u; | 177 | struct ECRS_URI *u; |
201 | GtkTreeModel * model; | 178 | GtkTreeModel *model; |
202 | 179 | ||
203 | /* setup visualization */ | 180 | /* setup visualization */ |
204 | list = MALLOC(sizeof(DownloadList)); | 181 | list = MALLOC (sizeof (DownloadList)); |
205 | memset(list, | 182 | memset (list, 0, sizeof (DownloadList)); |
206 | 0, | 183 | list->uri = ECRS_dupUri (fi->uri); |
207 | sizeof(DownloadList)); | 184 | list->filename = STRDUP (filename); |
208 | list->uri = ECRS_dupUri(fi->uri); | 185 | if ((dl_parent != NULL) && |
209 | list->filename = STRDUP(filename); | 186 | (NULL != |
210 | if ( (dl_parent != NULL) && | 187 | (path = |
211 | (NULL != (path = gtk_tree_row_reference_get_path(dl_parent->summaryViewRowReference) ) ) ) { | 188 | gtk_tree_row_reference_get_path (dl_parent-> |
212 | valid = gtk_tree_model_get_iter(GTK_TREE_MODEL(download_summary), | 189 | summaryViewRowReference)))) |
213 | &piter, | 190 | { |
214 | path); | 191 | valid = gtk_tree_model_get_iter (GTK_TREE_MODEL (download_summary), |
215 | if (valid) { | 192 | &piter, path); |
216 | gtk_tree_store_append(download_summary, | 193 | if (valid) |
217 | &iter, | 194 | { |
218 | &piter); | 195 | gtk_tree_store_append (download_summary, &iter, &piter); |
219 | } else { | 196 | } |
220 | gtk_tree_store_append(download_summary, | 197 | else |
221 | &iter, | 198 | { |
222 | NULL); | 199 | gtk_tree_store_append (download_summary, &iter, NULL); |
223 | } | 200 | } |
224 | gtk_tree_path_free(path); | 201 | gtk_tree_path_free (path); |
225 | } else { | 202 | } |
226 | gtk_tree_store_append(download_summary, | 203 | else |
227 | &iter, | 204 | { |
228 | NULL); | 205 | gtk_tree_store_append (download_summary, &iter, NULL); |
229 | } | 206 | } |
230 | size = ECRS_fileSize(fi->uri); | 207 | size = ECRS_fileSize (fi->uri); |
231 | size_h = string_get_fancy_byte_size(size); | 208 | size_h = string_get_fancy_byte_size (size); |
232 | sname = &filename[strlen(filename)-1]; | 209 | sname = &filename[strlen (filename) - 1]; |
233 | while ( (sname > filename) && | 210 | while ((sname > filename) && (sname[-1] != '/') && (sname[-1] != '\\')) |
234 | (sname[-1] != '/') && | ||
235 | (sname[-1] != '\\') ) | ||
236 | sname--; | 211 | sname--; |
237 | if (size != 0) | 212 | if (size != 0) |
238 | progress = completed * 100 / size; | 213 | progress = completed * 100 / size; |
239 | else | 214 | else |
240 | progress = 100; | 215 | progress = 100; |
241 | uri_name = ECRS_uriToString(fi->uri); | 216 | uri_name = ECRS_uriToString (fi->uri); |
242 | gtk_tree_store_set(download_summary, | 217 | gtk_tree_store_set (download_summary, |
243 | &iter, | 218 | &iter, |
244 | DOWNLOAD_FILENAME, filename, | 219 | DOWNLOAD_FILENAME, filename, |
245 | DOWNLOAD_SHORTNAME, sname, | 220 | DOWNLOAD_SHORTNAME, sname, |
246 | DOWNLOAD_SIZE, size, | 221 | DOWNLOAD_SIZE, size, |
247 | DOWNLOAD_HSIZE, size_h, | 222 | DOWNLOAD_HSIZE, size_h, |
248 | DOWNLOAD_PROGRESS, progress, | 223 | DOWNLOAD_PROGRESS, progress, |
249 | DOWNLOAD_URISTRING, uri_name, | 224 | DOWNLOAD_URISTRING, uri_name, |
250 | DOWNLOAD_INTERNAL, list, | 225 | DOWNLOAD_INTERNAL, list, -1); |
251 | -1); | 226 | FREE (uri_name); |
252 | FREE(uri_name); | 227 | FREE (size_h); |
253 | FREE(size_h); | 228 | path = gtk_tree_model_get_path (GTK_TREE_MODEL (download_summary), &iter); |
254 | path = gtk_tree_model_get_path(GTK_TREE_MODEL(download_summary), | ||
255 | &iter); | ||
256 | list->summaryViewRowReference | 229 | list->summaryViewRowReference |
257 | = gtk_tree_row_reference_new(GTK_TREE_MODEL(download_summary), | 230 | = gtk_tree_row_reference_new (GTK_TREE_MODEL (download_summary), path); |
258 | path); | 231 | gtk_tree_path_free (path); |
259 | gtk_tree_path_free(path); | ||
260 | list->searchList = sl_parent; | 232 | list->searchList = sl_parent; |
261 | list->searchViewRowReference = NULL; | 233 | list->searchViewRowReference = NULL; |
262 | if (sl_parent != NULL) { | 234 | if (sl_parent != NULL) |
263 | model = GTK_TREE_MODEL(sl_parent->tree); | 235 | { |
264 | if (dl_parent != NULL) { | 236 | model = GTK_TREE_MODEL (sl_parent->tree); |
265 | /* have parent, must be download from | 237 | if (dl_parent != NULL) |
266 | directory inside of search */ | 238 | { |
267 | /* FIXME: this requires GTK 2.8. Since it doesn't support Win9x, the quick | 239 | /* have parent, must be download from |
268 | solution is to #ifndef it */ | 240 | directory inside of search */ |
241 | /* FIXME: this requires GTK 2.8. Since it doesn't support Win9x, the quick | ||
242 | solution is to #ifndef it */ | ||
269 | #ifndef MINGW | 243 | #ifndef MINGW |
270 | GE_BREAK(ectx, | 244 | GE_BREAK (ectx, |
271 | gtk_tree_row_reference_get_model(dl_parent->searchViewRowReference) | 245 | gtk_tree_row_reference_get_model (dl_parent-> |
272 | == model); | 246 | searchViewRowReference) |
247 | == model); | ||
273 | #endif | 248 | #endif |
274 | path = gtk_tree_row_reference_get_path(dl_parent->searchViewRowReference); | 249 | path = |
275 | if (path != NULL) { | 250 | gtk_tree_row_reference_get_path (dl_parent-> |
276 | valid = gtk_tree_model_get_iter(model, | 251 | searchViewRowReference); |
277 | &piter, | 252 | if (path != NULL) |
278 | path); | 253 | { |
279 | GE_BREAK(ectx, valid == TRUE); | 254 | valid = gtk_tree_model_get_iter (model, &piter, path); |
280 | if (valid == TRUE) { | 255 | GE_BREAK (ectx, valid == TRUE); |
281 | valid = gtk_tree_model_iter_children(model, | 256 | if (valid == TRUE) |
282 | &iter, | 257 | { |
283 | &piter); | 258 | valid = gtk_tree_model_iter_children (model, &iter, &piter); |
284 | GE_BREAK(ectx, valid == TRUE); | 259 | GE_BREAK (ectx, valid == TRUE); |
285 | } | 260 | } |
286 | } else { | 261 | } |
287 | GE_BREAK(ectx, 0); | 262 | else |
288 | valid = FALSE; | 263 | { |
289 | } | 264 | GE_BREAK (ectx, 0); |
290 | } else { | 265 | valid = FALSE; |
291 | /* no download-parent, must be top-level entry in search */ | 266 | } |
292 | valid = gtk_tree_model_get_iter_first(model, | 267 | } |
293 | &iter); | 268 | else |
294 | GE_BREAK(ectx, valid == TRUE); | 269 | { |
295 | } | 270 | /* no download-parent, must be top-level entry in search */ |
296 | while (valid == TRUE) { | 271 | valid = gtk_tree_model_get_iter_first (model, &iter); |
297 | /* find matching entry */ | 272 | GE_BREAK (ectx, valid == TRUE); |
298 | gtk_tree_model_get(model, | 273 | } |
299 | &iter, | 274 | while (valid == TRUE) |
300 | SEARCH_URI, &u, | 275 | { |
301 | -1); | 276 | /* find matching entry */ |
302 | if (ECRS_equalsUri(u, | 277 | gtk_tree_model_get (model, &iter, SEARCH_URI, &u, -1); |
303 | fi->uri)) { | 278 | if (ECRS_equalsUri (u, fi->uri)) |
304 | path = gtk_tree_model_get_path(model, | 279 | { |
305 | &iter); | 280 | path = gtk_tree_model_get_path (model, &iter); |
306 | list->searchViewRowReference | 281 | list->searchViewRowReference |
307 | = gtk_tree_row_reference_new(model, | 282 | = gtk_tree_row_reference_new (model, path); |
308 | path); | 283 | gtk_tree_path_free (path); |
309 | gtk_tree_path_free(path); | 284 | gtk_tree_store_set (sl_parent->tree, |
310 | gtk_tree_store_set(sl_parent->tree, | 285 | &iter, |
311 | &iter, | 286 | SEARCH_CELL_BG_COLOR, |
312 | SEARCH_CELL_BG_COLOR, getColorCode(URITRACK_DOWNLOAD_STARTED), | 287 | getColorCode (URITRACK_DOWNLOAD_STARTED), |
313 | -1); | 288 | -1); |
314 | break; | 289 | break; |
315 | } | 290 | } |
316 | valid = gtk_tree_model_iter_next(model, | 291 | valid = gtk_tree_model_iter_next (model, &iter); |
317 | &iter); | 292 | } |
318 | } | 293 | if (valid == FALSE) |
319 | if (valid == FALSE) { | 294 | { |
320 | /* did not find matching entry in search list -- bug! Continue | 295 | /* did not find matching entry in search list -- bug! Continue |
321 | without adding to to search list! */ | 296 | without adding to to search list! */ |
322 | GE_BREAK(ectx, 0); | 297 | GE_BREAK (ectx, 0); |
323 | list->searchList = NULL; | 298 | list->searchList = NULL; |
324 | } | 299 | } |
325 | } | 300 | } |
326 | list->fsui_list = fsui_dl; | 301 | list->fsui_list = fsui_dl; |
327 | list->total = total; | 302 | list->total = total; |
328 | list->is_directory = ECRS_isDirectory(fi->meta); | 303 | list->is_directory = ECRS_isDirectory (fi->meta); |
329 | list->has_terminated = ( (state != FSUI_ACTIVE) && | 304 | list->has_terminated = ((state != FSUI_ACTIVE) && (state != FSUI_PENDING)); |
330 | (state != FSUI_PENDING) ); | ||
331 | list->next = download_head; | 305 | list->next = download_head; |
332 | download_head = list; | 306 | download_head = list; |
333 | if ( (list->is_directory == YES) && | 307 | if ((list->is_directory == YES) && (completed != 0)) |
334 | (completed != 0) ) | 308 | refreshDirectoryViewFromDisk (list); |
335 | refreshDirectoryViewFromDisk(list); | ||
336 | return list; | 309 | return list; |
337 | } | 310 | } |
338 | 311 | ||
@@ -341,158 +314,166 @@ fs_download_started(struct FSUI_DownloadList * fsui_dl, | |||
341 | * summary and the preview of the directory | 314 | * summary and the preview of the directory |
342 | * contents in the search page (if applicable). | 315 | * contents in the search page (if applicable). |
343 | */ | 316 | */ |
344 | void fs_download_update(DownloadList * list, | 317 | void |
345 | unsigned long long completed, | 318 | fs_download_update (DownloadList * list, |
346 | const char * data, | 319 | unsigned long long completed, |
347 | unsigned int size) { | 320 | const char *data, unsigned int size) |
321 | { | ||
348 | GtkTreeIter iter; | 322 | GtkTreeIter iter; |
349 | GtkTreePath * path; | 323 | GtkTreePath *path; |
350 | unsigned int val; | 324 | unsigned int val; |
351 | struct ECRS_MetaData * meta; | 325 | struct ECRS_MetaData *meta; |
352 | 326 | ||
353 | path = gtk_tree_row_reference_get_path(list->summaryViewRowReference); | 327 | path = gtk_tree_row_reference_get_path (list->summaryViewRowReference); |
354 | if (path == NULL) { | 328 | if (path == NULL) |
355 | GE_BREAK(ectx, 0); | 329 | { |
356 | return; | 330 | GE_BREAK (ectx, 0); |
357 | } | 331 | return; |
358 | gtk_tree_model_get_iter(GTK_TREE_MODEL(download_summary), | 332 | } |
359 | &iter, | 333 | gtk_tree_model_get_iter (GTK_TREE_MODEL (download_summary), &iter, path); |
360 | path); | 334 | gtk_tree_path_free (path); |
361 | gtk_tree_path_free(path); | ||
362 | if (list->total != 0) | 335 | if (list->total != 0) |
363 | val = completed * 100 / list->total; | 336 | val = completed * 100 / list->total; |
364 | else | 337 | else |
365 | val = 100; | 338 | val = 100; |
366 | gtk_tree_store_set(download_summary, | 339 | gtk_tree_store_set (download_summary, &iter, DOWNLOAD_PROGRESS, val, -1); |
367 | &iter, | 340 | if ((list->is_directory == YES) && |
368 | DOWNLOAD_PROGRESS, val, | 341 | (list->searchList != NULL) && (list->searchViewRowReference != NULL)) |
369 | -1); | 342 | { |
370 | if ( (list->is_directory == YES) && | 343 | meta = NULL; |
371 | (list->searchList != NULL) && | 344 | ECRS_listDirectory (ectx, |
372 | (list->searchViewRowReference != NULL) ) { | 345 | data, size, &meta, &addFilesToDirectory, list); |
373 | meta = NULL; | 346 | if (meta != NULL) |
374 | ECRS_listDirectory(ectx, | 347 | ECRS_freeMetaData (meta); |
375 | data, | 348 | } |
376 | size, | ||
377 | &meta, | ||
378 | &addFilesToDirectory, | ||
379 | list); | ||
380 | if (meta != NULL) | ||
381 | ECRS_freeMetaData(meta); | ||
382 | } | ||
383 | } | 349 | } |
384 | 350 | ||
385 | /** | 351 | /** |
386 | * A download has terminated successfully. Update summary and | 352 | * A download has terminated successfully. Update summary and |
387 | * possibly refresh directory listing. | 353 | * possibly refresh directory listing. |
388 | */ | 354 | */ |
389 | void fs_download_completed(DownloadList * downloadContext) { | 355 | void |
356 | fs_download_completed (DownloadList * downloadContext) | ||
357 | { | ||
390 | GtkTreeIter iter; | 358 | GtkTreeIter iter; |
391 | GtkTreePath * path; | 359 | GtkTreePath *path; |
392 | 360 | ||
393 | if (downloadContext->searchViewRowReference != NULL) { | 361 | if (downloadContext->searchViewRowReference != NULL) |
394 | path = gtk_tree_row_reference_get_path(downloadContext->searchViewRowReference); | 362 | { |
395 | gtk_tree_model_get_iter(GTK_TREE_MODEL(downloadContext->searchList->tree), | 363 | path = |
396 | &iter, | 364 | gtk_tree_row_reference_get_path (downloadContext-> |
397 | path); | 365 | searchViewRowReference); |
398 | gtk_tree_path_free(path); | 366 | gtk_tree_model_get_iter (GTK_TREE_MODEL |
399 | gtk_tree_store_set(downloadContext->searchList->tree, | 367 | (downloadContext->searchList->tree), &iter, |
400 | &iter, | 368 | path); |
401 | SEARCH_CELL_BG_COLOR, getColorCode(URITRACK_DOWNLOAD_COMPLETED), | 369 | gtk_tree_path_free (path); |
402 | -1); | 370 | gtk_tree_store_set (downloadContext->searchList->tree, |
403 | } | 371 | &iter, |
372 | SEARCH_CELL_BG_COLOR, | ||
373 | getColorCode (URITRACK_DOWNLOAD_COMPLETED), -1); | ||
374 | } | ||
404 | downloadContext->has_terminated = YES; | 375 | downloadContext->has_terminated = YES; |
405 | refreshDirectoryViewFromDisk(downloadContext); | 376 | refreshDirectoryViewFromDisk (downloadContext); |
406 | } | 377 | } |
407 | 378 | ||
408 | /** | 379 | /** |
409 | * A download has been aborted. Update summary and | 380 | * A download has been aborted. Update summary and |
410 | * possibly refresh directory listing. | 381 | * possibly refresh directory listing. |
411 | */ | 382 | */ |
412 | void fs_download_aborted(DownloadList * downloadContext) { | 383 | void |
384 | fs_download_aborted (DownloadList * downloadContext) | ||
385 | { | ||
413 | GtkTreeIter iter; | 386 | GtkTreeIter iter; |
414 | GtkTreePath * path; | 387 | GtkTreePath *path; |
415 | 388 | ||
416 | if (downloadContext->searchViewRowReference != NULL) { | 389 | if (downloadContext->searchViewRowReference != NULL) |
417 | path = gtk_tree_row_reference_get_path(downloadContext->searchViewRowReference); | 390 | { |
418 | gtk_tree_model_get_iter(GTK_TREE_MODEL(downloadContext->searchList->tree), | 391 | path = |
419 | &iter, | 392 | gtk_tree_row_reference_get_path (downloadContext-> |
420 | path); | 393 | searchViewRowReference); |
421 | gtk_tree_path_free(path); | 394 | gtk_tree_model_get_iter (GTK_TREE_MODEL |
422 | gtk_tree_store_set(downloadContext->searchList->tree, | 395 | (downloadContext->searchList->tree), &iter, |
423 | &iter, | 396 | path); |
424 | SEARCH_CELL_BG_COLOR, getColorCode(URITRACK_DOWNLOAD_ABORTED), | 397 | gtk_tree_path_free (path); |
425 | -1); | 398 | gtk_tree_store_set (downloadContext->searchList->tree, |
426 | } | 399 | &iter, |
400 | SEARCH_CELL_BG_COLOR, | ||
401 | getColorCode (URITRACK_DOWNLOAD_ABORTED), -1); | ||
402 | } | ||
427 | downloadContext->has_terminated = YES; | 403 | downloadContext->has_terminated = YES; |
428 | refreshDirectoryViewFromDisk(downloadContext); | 404 | refreshDirectoryViewFromDisk (downloadContext); |
429 | } | 405 | } |
430 | 406 | ||
431 | /** | 407 | /** |
432 | * A download has been stopped. Remove from summary | 408 | * A download has been stopped. Remove from summary |
433 | * and free associated resources. | 409 | * and free associated resources. |
434 | */ | 410 | */ |
435 | void fs_download_stopped(DownloadList * list) { | 411 | void |
412 | fs_download_stopped (DownloadList * list) | ||
413 | { | ||
436 | GtkTreeIter iter; | 414 | GtkTreeIter iter; |
437 | GtkTreeIter piter; | 415 | GtkTreeIter piter; |
438 | GtkTreePath * path; | 416 | GtkTreePath *path; |
439 | DownloadList * prev; | 417 | DownloadList *prev; |
440 | int valid; | 418 | int valid; |
441 | GtkTreeModel * model; | 419 | GtkTreeModel *model; |
442 | 420 | ||
443 | path = gtk_tree_row_reference_get_path(list->summaryViewRowReference); | 421 | path = gtk_tree_row_reference_get_path (list->summaryViewRowReference); |
444 | if (path == NULL) { | 422 | if (path == NULL) |
445 | GE_BREAK(ectx, 0); | 423 | { |
446 | } else { | 424 | GE_BREAK (ectx, 0); |
447 | gtk_tree_model_get_iter(GTK_TREE_MODEL(download_summary), | 425 | } |
448 | &iter, | 426 | else |
449 | path); | 427 | { |
450 | gtk_tree_path_free(path); | 428 | gtk_tree_model_get_iter (GTK_TREE_MODEL (download_summary), |
451 | gtk_tree_row_reference_free(list->summaryViewRowReference); | 429 | &iter, path); |
452 | list->summaryViewRowReference = NULL; | 430 | gtk_tree_path_free (path); |
453 | gtk_tree_store_remove(download_summary, | 431 | gtk_tree_row_reference_free (list->summaryViewRowReference); |
454 | &iter); | 432 | list->summaryViewRowReference = NULL; |
455 | } | 433 | gtk_tree_store_remove (download_summary, &iter); |
456 | FREE(list->filename); | 434 | } |
457 | ECRS_freeUri(list->uri); | 435 | FREE (list->filename); |
436 | ECRS_freeUri (list->uri); | ||
458 | 437 | ||
459 | /* if we have child-results in view, remove them! */ | 438 | /* if we have child-results in view, remove them! */ |
460 | if (list->searchList != NULL) { | 439 | if (list->searchList != NULL) |
461 | path = gtk_tree_row_reference_get_path(list->searchViewRowReference); | 440 | { |
462 | if (path == NULL) { | 441 | path = gtk_tree_row_reference_get_path (list->searchViewRowReference); |
463 | GE_BREAK(ectx, 0); | 442 | if (path == NULL) |
464 | } else { | 443 | { |
465 | model = GTK_TREE_MODEL(list->searchList->tree); | 444 | GE_BREAK (ectx, 0); |
466 | gtk_tree_model_get_iter(model, | 445 | } |
467 | &piter, | 446 | else |
468 | path); | 447 | { |
469 | gtk_tree_path_free(path); | 448 | model = GTK_TREE_MODEL (list->searchList->tree); |
470 | valid = gtk_tree_model_iter_children(model, | 449 | gtk_tree_model_get_iter (model, &piter, path); |
471 | &iter, | 450 | gtk_tree_path_free (path); |
472 | &piter); | 451 | valid = gtk_tree_model_iter_children (model, &iter, &piter); |
473 | while (TRUE == valid) | 452 | while (TRUE == valid) |
474 | valid = gtk_tree_store_remove(GTK_TREE_STORE(model), | 453 | valid = gtk_tree_store_remove (GTK_TREE_STORE (model), &iter); |
475 | &iter); | 454 | } |
476 | } | 455 | } |
477 | } | 456 | if (list->searchViewRowReference != NULL) |
478 | if (list->searchViewRowReference != NULL) { | 457 | { |
479 | gtk_tree_row_reference_free(list->searchViewRowReference); | 458 | gtk_tree_row_reference_free (list->searchViewRowReference); |
480 | list->searchViewRowReference = NULL; | 459 | list->searchViewRowReference = NULL; |
481 | } | 460 | } |
482 | 461 | ||
483 | if (download_head == list) { | 462 | if (download_head == list) |
484 | download_head = list->next; | 463 | { |
485 | } else { | 464 | download_head = list->next; |
486 | prev = download_head; | 465 | } |
487 | while ( (prev != NULL) && | 466 | else |
488 | (prev->next != list) ) | 467 | { |
489 | prev = prev->next; | 468 | prev = download_head; |
490 | if (prev != NULL) | 469 | while ((prev != NULL) && (prev->next != list)) |
491 | prev->next = list->next; | 470 | prev = prev->next; |
492 | else | 471 | if (prev != NULL) |
493 | GE_BREAK(ectx, 0); | 472 | prev->next = list->next; |
494 | } | 473 | else |
495 | FREE(list); | 474 | GE_BREAK (ectx, 0); |
475 | } | ||
476 | FREE (list); | ||
496 | } | 477 | } |
497 | 478 | ||
498 | 479 | ||
@@ -506,59 +487,60 @@ void fs_download_stopped(DownloadList * list) { | |||
506 | * such a download is already active. | 487 | * such a download is already active. |
507 | */ | 488 | */ |
508 | static int | 489 | static int |
509 | check_pending(const char * filename, | 490 | check_pending (const char *filename, GtkTreeIter * parent) |
510 | GtkTreeIter * parent) { | 491 | { |
511 | GtkTreeModel * model; | 492 | GtkTreeModel *model; |
512 | GtkTreeIter iter; | 493 | GtkTreeIter iter; |
513 | char * name; | 494 | char *name; |
514 | 495 | ||
515 | model = GTK_TREE_MODEL(download_summary); | 496 | model = GTK_TREE_MODEL (download_summary); |
516 | if (gtk_tree_model_iter_children(model, | 497 | if (gtk_tree_model_iter_children (model, &iter, parent)) |
517 | &iter, | 498 | { |
518 | parent)) { | 499 | do |
519 | do { | 500 | { |
520 | gtk_tree_model_get(model, | 501 | gtk_tree_model_get (model, &iter, DOWNLOAD_FILENAME, &name, -1); |
521 | &iter, | 502 | if ((name != NULL) && (0 == strcmp (name, filename))) |
522 | DOWNLOAD_FILENAME, &name, | 503 | { |
523 | -1); | 504 | free (name); |
524 | if ( (name != NULL) && | 505 | return SYSERR; |
525 | (0 == strcmp(name, filename)) ) { | 506 | } |
526 | free(name); | 507 | if (name != NULL) |
527 | return SYSERR; | 508 | free (name); |
528 | } | 509 | if (SYSERR == check_pending (filename, &iter)) |
529 | if (name != NULL) | 510 | return SYSERR; |
530 | free(name); | 511 | } |
531 | if (SYSERR == check_pending(filename, | 512 | while (gtk_tree_model_iter_next (model, &iter)); |
532 | &iter)) | 513 | } |
533 | return SYSERR; | ||
534 | } while (gtk_tree_model_iter_next(model, | ||
535 | &iter)); | ||
536 | } | ||
537 | return OK; | 514 | return OK; |
538 | } | 515 | } |
539 | 516 | ||
540 | typedef struct { | 517 | typedef struct |
541 | char * uri_name; | 518 | { |
542 | struct ECRS_URI * idc_uri; | 519 | char *uri_name; |
543 | struct ECRS_MetaData * idc_meta; | 520 | struct ECRS_URI *idc_uri; |
544 | char * idc_final_download_destination; | 521 | struct ECRS_MetaData *idc_meta; |
545 | SearchList * searchContext; | 522 | char *idc_final_download_destination; |
546 | DownloadList * parentContext; | 523 | SearchList *searchContext; |
524 | DownloadList *parentContext; | ||
547 | unsigned int anonymity; | 525 | unsigned int anonymity; |
548 | int recursive; | 526 | int recursive; |
549 | } SDC; | 527 | } SDC; |
550 | 528 | ||
551 | static void * init_download_helper(void * cls) { | 529 | static void * |
552 | SDC * sdc = cls; | 530 | init_download_helper (void *cls) |
553 | 531 | { | |
554 | FSUI_startDownload(ctx, | 532 | SDC *sdc = cls; |
555 | sdc->anonymity, | 533 | |
556 | sdc->recursive, | 534 | FSUI_startDownload (ctx, |
557 | sdc->idc_uri, | 535 | sdc->anonymity, |
558 | sdc->idc_meta, | 536 | sdc->recursive, |
559 | sdc->idc_final_download_destination, | 537 | sdc->idc_uri, |
560 | (sdc->searchContext != NULL) ? sdc->searchContext->fsui_list : NULL, | 538 | sdc->idc_meta, |
561 | (sdc->parentContext != NULL) ? sdc->parentContext->fsui_list : NULL); | 539 | sdc->idc_final_download_destination, |
540 | (sdc->searchContext != | ||
541 | NULL) ? sdc->searchContext->fsui_list : NULL, | ||
542 | (sdc->parentContext != | ||
543 | NULL) ? sdc->parentContext->fsui_list : NULL); | ||
562 | return NULL; | 544 | return NULL; |
563 | } | 545 | } |
564 | 546 | ||
@@ -567,21 +549,20 @@ static void * init_download_helper(void * cls) { | |||
567 | * Start the download of the selected entry. | 549 | * Start the download of the selected entry. |
568 | */ | 550 | */ |
569 | static void | 551 | static void |
570 | initiateDownload(GtkTreeModel * model, | 552 | initiateDownload (GtkTreeModel * model, |
571 | GtkTreePath * path, | 553 | GtkTreePath * path, GtkTreeIter * iter, gpointer unused) |
572 | GtkTreeIter * iter, | 554 | { |
573 | gpointer unused) { | ||
574 | SDC sdc; | 555 | SDC sdc; |
575 | char * final_download_dir; | 556 | char *final_download_dir; |
576 | GtkTreeIter iiter; | 557 | GtkTreeIter iiter; |
577 | char * tmp; | 558 | char *tmp; |
578 | char * cname; | 559 | char *cname; |
579 | char * dname; | 560 | char *dname; |
580 | GtkTreePath *dirTreePath; | 561 | GtkTreePath *dirTreePath; |
581 | char *dirPath; | 562 | char *dirPath; |
582 | unsigned int dirPathLen; | 563 | unsigned int dirPathLen; |
583 | char * idc_name; | 564 | char *idc_name; |
584 | char * idc_mime; | 565 | char *idc_mime; |
585 | 566 | ||
586 | sdc.idc_uri = NULL; | 567 | sdc.idc_uri = NULL; |
587 | sdc.idc_meta = NULL; | 568 | sdc.idc_meta = NULL; |
@@ -589,178 +570,183 @@ initiateDownload(GtkTreeModel * model, | |||
589 | idc_mime = NULL; | 570 | idc_mime = NULL; |
590 | sdc.searchContext = NULL; | 571 | sdc.searchContext = NULL; |
591 | sdc.parentContext = NULL; | 572 | sdc.parentContext = NULL; |
592 | gtk_tree_model_get(model, | 573 | gtk_tree_model_get (model, |
593 | iter, | 574 | iter, |
594 | SEARCH_NAME, &idc_name, | 575 | SEARCH_NAME, &idc_name, |
595 | SEARCH_URI, &sdc.idc_uri, | 576 | SEARCH_URI, &sdc.idc_uri, |
596 | SEARCH_META, &sdc.idc_meta, | 577 | SEARCH_META, &sdc.idc_meta, |
597 | SEARCH_MIME, &idc_mime, | 578 | SEARCH_MIME, &idc_mime, |
598 | SEARCH_INTERNAL, &sdc.searchContext, | 579 | SEARCH_INTERNAL, &sdc.searchContext, |
599 | SEARCH_INTERNAL_PARENT, &sdc.parentContext, | 580 | SEARCH_INTERNAL_PARENT, &sdc.parentContext, -1); |
600 | -1); | 581 | if ((sdc.idc_uri == NULL) || |
601 | if ( (sdc.idc_uri == NULL) || | 582 | (!(ECRS_isFileUri (sdc.idc_uri) || ECRS_isLocationUri (sdc.idc_uri)))) |
602 | (! (ECRS_isFileUri(sdc.idc_uri) || | 583 | { |
603 | ECRS_isLocationUri(sdc.idc_uri) ) ) ) { | 584 | GE_BREAK (ectx, 0); |
604 | GE_BREAK(ectx, 0); | 585 | FREENONNULL (idc_name); |
605 | FREENONNULL(idc_name); | 586 | FREENONNULL (idc_mime); |
606 | FREENONNULL(idc_mime); | 587 | return; |
607 | return; | 588 | } |
608 | } | 589 | sdc.uri_name = ECRS_uriToString (sdc.idc_uri); |
609 | sdc.uri_name = ECRS_uriToString(sdc.idc_uri); | 590 | if ((sdc.uri_name == NULL) || |
610 | if ( (sdc.uri_name == NULL) || | 591 | (strlen (sdc.uri_name) < |
611 | (strlen(sdc.uri_name) < | 592 | strlen (ECRS_URI_PREFIX) + strlen (ECRS_FILE_INFIX))) |
612 | strlen(ECRS_URI_PREFIX) + | 593 | { |
613 | strlen(ECRS_FILE_INFIX)) ) { | 594 | GE_BREAK (ectx, 0); |
614 | GE_BREAK(ectx, 0); | 595 | FREENONNULL (sdc.uri_name); |
615 | FREENONNULL(sdc.uri_name); | 596 | FREENONNULL (idc_name); |
616 | FREENONNULL(idc_name); | 597 | FREENONNULL (idc_mime); |
617 | FREENONNULL(idc_mime); | 598 | return; |
618 | return; | 599 | } |
619 | } | ||
620 | /* reduce "//" to "/" */ | 600 | /* reduce "//" to "/" */ |
621 | if (idc_name != NULL) { | 601 | if (idc_name != NULL) |
622 | while (strstr(idc_name, "//") != NULL) | 602 | { |
623 | memcpy(strstr(idc_name, "//"), | 603 | while (strstr (idc_name, "//") != NULL) |
624 | strstr(idc_name, "//") + 1, | 604 | memcpy (strstr (idc_name, "//"), |
625 | strlen(strstr(idc_name, "//"))); | 605 | strstr (idc_name, "//") + 1, |
626 | } | 606 | strlen (strstr (idc_name, "//"))); |
607 | } | ||
627 | /* if no name given or just "/", produce better name */ | 608 | /* if no name given or just "/", produce better name */ |
628 | if ( (idc_name == NULL) || | 609 | if ((idc_name == NULL) || (0 == strcmp ("/", idc_name))) |
629 | (0 == strcmp("/", idc_name)) ) { | 610 | { |
630 | #ifdef WINDOWS | 611 | #ifdef WINDOWS |
631 | char * filehash; | 612 | char *filehash; |
632 | 613 | ||
633 | GE_ASSERT(NULL, | 614 | GE_ASSERT (NULL, |
634 | strlen(sdc.uri_name) > strlen(ECRS_URI_PREFIX) + strlen(ECRS_FILE_INFIX)); | 615 | strlen (sdc.uri_name) > |
635 | FREENONNULL(idc_name); | 616 | strlen (ECRS_URI_PREFIX) + strlen (ECRS_FILE_INFIX)); |
636 | filehash = STRDUP(&sdc.uri_name[strlen(ECRS_URI_PREFIX) + strlen(ECRS_FILE_INFIX)]); | 617 | FREENONNULL (idc_name); |
637 | filehash[16] = 0; | 618 | filehash = |
638 | idc_name = STRDUP(filehash); | 619 | STRDUP (&sdc. |
639 | FREENONNULL(filehash); | 620 | uri_name[strlen (ECRS_URI_PREFIX) + |
621 | strlen (ECRS_FILE_INFIX)]); | ||
622 | filehash[16] = 0; | ||
623 | idc_name = STRDUP (filehash); | ||
624 | FREENONNULL (filehash); | ||
640 | #else | 625 | #else |
641 | GE_ASSERT(NULL, | 626 | GE_ASSERT (NULL, |
642 | strlen(sdc.uri_name) > strlen(ECRS_URI_PREFIX) + strlen(ECRS_FILE_INFIX)); | 627 | strlen (sdc.uri_name) > |
643 | FREENONNULL(idc_name); | 628 | strlen (ECRS_URI_PREFIX) + strlen (ECRS_FILE_INFIX)); |
644 | idc_name = STRDUP(&sdc.uri_name[strlen(ECRS_URI_PREFIX) + strlen(ECRS_FILE_INFIX)]); | 629 | FREENONNULL (idc_name); |
630 | idc_name = | ||
631 | STRDUP (&sdc. | ||
632 | uri_name[strlen (ECRS_URI_PREFIX) + | ||
633 | strlen (ECRS_FILE_INFIX)]); | ||
645 | #endif | 634 | #endif |
646 | } | 635 | } |
647 | 636 | ||
648 | /* dname = directory portion of idc_name */ | 637 | /* dname = directory portion of idc_name */ |
649 | cname = idc_name; | 638 | cname = idc_name; |
650 | dname = STRDUP(idc_name); | 639 | dname = STRDUP (idc_name); |
651 | cname = &dname[strlen(dname)-1]; | 640 | cname = &dname[strlen (dname) - 1]; |
652 | if (cname != dname) | 641 | if (cname != dname) |
653 | cname--; /* ignore tailing '/' */ | 642 | cname--; /* ignore tailing '/' */ |
654 | while ( (cname != dname) && | 643 | while ((cname != dname) && (*cname != DIR_SEPARATOR)) |
655 | (*cname != DIR_SEPARATOR) ) | ||
656 | cname--; | 644 | cname--; |
657 | if (*cname == DIR_SEPARATOR) { | 645 | if (*cname == DIR_SEPARATOR) |
658 | *cname = '\0'; | 646 | { |
659 | FREE(idc_name); | 647 | *cname = '\0'; |
660 | idc_name = STRDUP(cname + 1); | 648 | FREE (idc_name); |
661 | } else { | 649 | idc_name = STRDUP (cname + 1); |
662 | *cname = '\0'; | 650 | } |
663 | } | 651 | else |
652 | { | ||
653 | *cname = '\0'; | ||
654 | } | ||
664 | cname = NULL; | 655 | cname = NULL; |
665 | 656 | ||
666 | GC_get_configuration_value_filename(cfg, | 657 | GC_get_configuration_value_filename (cfg, |
667 | "FS", | 658 | "FS", |
668 | "INCOMINGDIR", | 659 | "INCOMINGDIR", |
669 | "$HOME/gnunet-downloads/", | 660 | "$HOME/gnunet-downloads/", |
670 | &final_download_dir); | 661 | &final_download_dir); |
671 | if (strlen(dname) > 0) { | 662 | if (strlen (dname) > 0) |
672 | tmp = MALLOC(strlen(final_download_dir) + strlen(dname) + 2); | 663 | { |
673 | strcpy(tmp, final_download_dir); | 664 | tmp = MALLOC (strlen (final_download_dir) + strlen (dname) + 2); |
674 | if (tmp[strlen(tmp)] != DIR_SEPARATOR) | 665 | strcpy (tmp, final_download_dir); |
675 | strcat(tmp, DIR_SEPARATOR_STR); | 666 | if (tmp[strlen (tmp)] != DIR_SEPARATOR) |
676 | if (dname[0] == DIR_SEPARATOR) | 667 | strcat (tmp, DIR_SEPARATOR_STR); |
677 | strcat(tmp, &dname[1]); | 668 | if (dname[0] == DIR_SEPARATOR) |
678 | else | 669 | strcat (tmp, &dname[1]); |
679 | strcat(tmp, dname); | 670 | else |
680 | FREE(final_download_dir); | 671 | strcat (tmp, dname); |
681 | final_download_dir = tmp; | 672 | FREE (final_download_dir); |
682 | } | 673 | final_download_dir = tmp; |
683 | FREE(dname); | 674 | } |
675 | FREE (dname); | ||
684 | dname = NULL; | 676 | dname = NULL; |
685 | /* If file is inside a directory, get the full path */ | 677 | /* If file is inside a directory, get the full path */ |
686 | dirTreePath = gtk_tree_path_copy(path); | 678 | dirTreePath = gtk_tree_path_copy (path); |
687 | dirPath = MALLOC(1); | 679 | dirPath = MALLOC (1); |
688 | dirPath[0] = '\0'; | 680 | dirPath[0] = '\0'; |
689 | dirPathLen = 0; | 681 | dirPathLen = 0; |
690 | while (gtk_tree_path_get_depth(dirTreePath) > 1) { | 682 | while (gtk_tree_path_get_depth (dirTreePath) > 1) |
691 | char * dirname; | 683 | { |
692 | char * newPath; | 684 | char *dirname; |
693 | 685 | char *newPath; | |
694 | if (! gtk_tree_path_up(dirTreePath)) | 686 | |
695 | break; | 687 | if (!gtk_tree_path_up (dirTreePath)) |
696 | if (! gtk_tree_model_get_iter(model, | 688 | break; |
697 | &iiter, | 689 | if (!gtk_tree_model_get_iter (model, &iiter, dirTreePath)) |
698 | dirTreePath)) | 690 | break; |
699 | break; | 691 | gtk_tree_model_get (model, &iiter, SEARCH_NAME, &dirname, -1); |
700 | gtk_tree_model_get(model, | 692 | dirPathLen = |
701 | &iiter, | 693 | strlen (dirPath) + strlen (dirname) + strlen (DIR_SEPARATOR_STR) + 1; |
702 | SEARCH_NAME, &dirname, | 694 | newPath = MALLOC (dirPathLen + 1); |
703 | -1); | 695 | strcpy (newPath, dirname); |
704 | dirPathLen = strlen(dirPath) + strlen(dirname) + strlen(DIR_SEPARATOR_STR) + 1; | 696 | if (newPath[strlen (newPath) - 1] != DIR_SEPARATOR) |
705 | newPath = MALLOC(dirPathLen + 1); | 697 | strcat (newPath, DIR_SEPARATOR_STR); |
706 | strcpy(newPath, dirname); | 698 | strcat (newPath, dirPath); |
707 | if (newPath[strlen(newPath)-1] != DIR_SEPARATOR) | 699 | FREE (dirPath); |
708 | strcat(newPath, DIR_SEPARATOR_STR); | 700 | dirPath = newPath; |
709 | strcat(newPath, dirPath); | 701 | free (dirname); |
710 | FREE(dirPath); | 702 | } |
711 | dirPath = newPath; | 703 | gtk_tree_path_free (dirTreePath); |
712 | free(dirname); | ||
713 | } | ||
714 | gtk_tree_path_free(dirTreePath); | ||
715 | 704 | ||
716 | /* construct completed/directory/real-filename */ | 705 | /* construct completed/directory/real-filename */ |
717 | sdc.idc_final_download_destination = MALLOC(strlen(final_download_dir) + 2 + | 706 | sdc.idc_final_download_destination = |
718 | strlen(idc_name) + strlen(GNUNET_DIRECTORY_EXT) + | 707 | MALLOC (strlen (final_download_dir) + 2 + strlen (idc_name) + |
719 | strlen(dirPath)); | 708 | strlen (GNUNET_DIRECTORY_EXT) + strlen (dirPath)); |
720 | strcpy(sdc.idc_final_download_destination, | 709 | strcpy (sdc.idc_final_download_destination, final_download_dir); |
721 | final_download_dir); | 710 | if (sdc. |
722 | if (sdc.idc_final_download_destination[strlen(sdc.idc_final_download_destination)-1] != DIR_SEPARATOR) | 711 | idc_final_download_destination[strlen |
723 | strcat(sdc.idc_final_download_destination, | 712 | (sdc.idc_final_download_destination) - |
724 | DIR_SEPARATOR_STR); | 713 | 1] != DIR_SEPARATOR) |
725 | strcat(sdc.idc_final_download_destination, | 714 | strcat (sdc.idc_final_download_destination, DIR_SEPARATOR_STR); |
726 | dirPath); | 715 | strcat (sdc.idc_final_download_destination, dirPath); |
727 | strcat(sdc.idc_final_download_destination, | 716 | strcat (sdc.idc_final_download_destination, idc_name); |
728 | idc_name); | 717 | sdc.anonymity = getSpinButtonValue (sdc.searchContext->searchXML, |
729 | sdc.anonymity = getSpinButtonValue(sdc.searchContext->searchXML, | 718 | "downloadAnonymitySpinButton"); |
730 | "downloadAnonymitySpinButton"); | 719 | sdc.recursive = getToggleButtonValue (sdc.searchContext->searchXML, |
731 | sdc.recursive = getToggleButtonValue(sdc.searchContext->searchXML, | 720 | "downloadRecursiveCheckButton"); |
732 | "downloadRecursiveCheckButton"); | 721 | if (OK == check_pending (idc_name, NULL)) |
733 | if (OK == check_pending(idc_name, | 722 | { |
734 | NULL)) { | 723 | addLogEntry (_("Downloading `%s'\n"), idc_name); |
735 | addLogEntry(_("Downloading `%s'\n"), | 724 | run_with_save_calls (&init_download_helper, &sdc); |
736 | idc_name); | 725 | } |
737 | run_with_save_calls(&init_download_helper, | 726 | else |
738 | &sdc); | 727 | { |
739 | } else { | 728 | addLogEntry (_("ERROR: already downloading `%s'"), idc_name); |
740 | addLogEntry(_("ERROR: already downloading `%s'"), | 729 | } |
741 | idc_name); | 730 | FREE (sdc.uri_name); |
742 | } | 731 | FREE (dirPath); |
743 | FREE(sdc.uri_name); | 732 | FREE (sdc.idc_final_download_destination); |
744 | FREE(dirPath); | 733 | FREENONNULL (final_download_dir); |
745 | FREE(sdc.idc_final_download_destination); | 734 | FREENONNULL (idc_name); |
746 | FREENONNULL(final_download_dir); | 735 | FREENONNULL (idc_mime); |
747 | FREENONNULL(idc_name); | ||
748 | FREENONNULL(idc_mime); | ||
749 | } | 736 | } |
750 | 737 | ||
751 | /** | 738 | /** |
752 | * The download button in the search dialog was | 739 | * The download button in the search dialog was |
753 | * clicked. Download all selected entries. | 740 | * clicked. Download all selected entries. |
754 | */ | 741 | */ |
755 | void on_downloadButton_clicked_fs(GtkWidget * treeview, | 742 | void |
756 | GtkWidget * downloadButton) { | 743 | on_downloadButton_clicked_fs (GtkWidget * treeview, |
757 | GtkTreeSelection * selection; | 744 | GtkWidget * downloadButton) |
758 | 745 | { | |
759 | selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); | 746 | GtkTreeSelection *selection; |
760 | ggc_tree_selection_selected_foreach | 747 | |
761 | (selection, | 748 | selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)); |
762 | &initiateDownload, | 749 | ggc_tree_selection_selected_foreach (selection, &initiateDownload, NULL); |
763 | NULL); | ||
764 | } | 750 | } |
765 | 751 | ||
766 | 752 | ||
@@ -773,161 +759,151 @@ void on_downloadButton_clicked_fs(GtkWidget * treeview, | |||
773 | * - support for user-specified filename | 759 | * - support for user-specified filename |
774 | * - enable button only if valid URI is entered | 760 | * - enable button only if valid URI is entered |
775 | */ | 761 | */ |
776 | void on_statusDownloadURIEntry_editing_done_fs(GtkWidget * entry, | 762 | void |
777 | GtkWidget * downloadButton) { | 763 | on_statusDownloadURIEntry_editing_done_fs (GtkWidget * entry, |
778 | const char * uris; | 764 | GtkWidget * downloadButton) |
779 | char * urid; | 765 | { |
780 | char * final_download_dir; | 766 | const char *uris; |
781 | const char * dname; | 767 | char *urid; |
768 | char *final_download_dir; | ||
769 | const char *dname; | ||
782 | SDC sdc; | 770 | SDC sdc; |
783 | 771 | ||
784 | uris = gtk_entry_get_text(GTK_ENTRY(entry)); | 772 | uris = gtk_entry_get_text (GTK_ENTRY (entry)); |
785 | urid = STRDUP(uris); | 773 | urid = STRDUP (uris); |
786 | gtk_entry_set_text(GTK_ENTRY(entry), | 774 | gtk_entry_set_text (GTK_ENTRY (entry), ECRS_URI_PREFIX); |
787 | ECRS_URI_PREFIX); | 775 | sdc.idc_uri = ECRS_stringToUri (ectx, urid); |
788 | sdc.idc_uri = ECRS_stringToUri(ectx, urid); | 776 | if (sdc.idc_uri == NULL) |
789 | if (sdc.idc_uri == NULL) { | 777 | { |
790 | addLogEntry(_("Invalid URI `%s'"), urid); | 778 | addLogEntry (_("Invalid URI `%s'"), urid); |
791 | FREE(urid); | 779 | FREE (urid); |
792 | return; | 780 | return; |
793 | } | 781 | } |
794 | if (ECRS_isKeywordUri(sdc.idc_uri)) { | 782 | if (ECRS_isKeywordUri (sdc.idc_uri)) |
795 | addLogEntry(_("Please use the search function for keyword (KSK) URIs!")); | 783 | { |
796 | FREE(urid); | 784 | addLogEntry (_ |
797 | ECRS_freeUri(sdc.idc_uri); | 785 | ("Please use the search function for keyword (KSK) URIs!")); |
798 | return; | 786 | FREE (urid); |
799 | } else if (ECRS_isLocationUri(sdc.idc_uri)) { | 787 | ECRS_freeUri (sdc.idc_uri); |
800 | addLogEntry(_("Location URIs are not yet supported")); | 788 | return; |
801 | FREE(urid); | 789 | } |
802 | ECRS_freeUri(sdc.idc_uri); | 790 | else if (ECRS_isLocationUri (sdc.idc_uri)) |
803 | return; | 791 | { |
804 | } | 792 | addLogEntry (_("Location URIs are not yet supported")); |
805 | GC_get_configuration_value_filename(cfg, | 793 | FREE (urid); |
806 | "FS", | 794 | ECRS_freeUri (sdc.idc_uri); |
807 | "INCOMINGDIR", | 795 | return; |
808 | "$HOME/gnunet-downloads/", | 796 | } |
809 | &final_download_dir); | 797 | GC_get_configuration_value_filename (cfg, |
810 | disk_directory_create(ectx, final_download_dir); | 798 | "FS", |
811 | dname = &uris[strlen(ECRS_URI_PREFIX) + strlen(ECRS_FILE_INFIX)]; | 799 | "INCOMINGDIR", |
812 | sdc.idc_final_download_destination = MALLOC(strlen(final_download_dir) + strlen(dname) + 2); | 800 | "$HOME/gnunet-downloads/", |
813 | strcpy(sdc.idc_final_download_destination, | 801 | &final_download_dir); |
814 | final_download_dir); | 802 | disk_directory_create (ectx, final_download_dir); |
815 | FREE(final_download_dir); | 803 | dname = &uris[strlen (ECRS_URI_PREFIX) + strlen (ECRS_FILE_INFIX)]; |
816 | if (sdc.idc_final_download_destination[strlen(sdc.idc_final_download_destination)] != DIR_SEPARATOR) | 804 | sdc.idc_final_download_destination = |
817 | strcat(sdc.idc_final_download_destination, | 805 | MALLOC (strlen (final_download_dir) + strlen (dname) + 2); |
818 | DIR_SEPARATOR_STR); | 806 | strcpy (sdc.idc_final_download_destination, final_download_dir); |
819 | strcat(sdc.idc_final_download_destination, | 807 | FREE (final_download_dir); |
820 | dname); | 808 | if (sdc. |
821 | 809 | idc_final_download_destination[strlen | |
822 | addLogEntry(_("Downloading `%s'\n"), | 810 | (sdc.idc_final_download_destination)] != |
823 | uris); | 811 | DIR_SEPARATOR) |
824 | sdc.idc_meta = ECRS_createMetaData(); | 812 | strcat (sdc.idc_final_download_destination, DIR_SEPARATOR_STR); |
825 | sdc.anonymity = getSpinButtonValue(getMainXML(), | 813 | strcat (sdc.idc_final_download_destination, dname); |
826 | "fsstatusAnonymitySpin"); | 814 | |
815 | addLogEntry (_("Downloading `%s'\n"), uris); | ||
816 | sdc.idc_meta = ECRS_createMetaData (); | ||
817 | sdc.anonymity = getSpinButtonValue (getMainXML (), "fsstatusAnonymitySpin"); | ||
827 | sdc.recursive = NO; | 818 | sdc.recursive = NO; |
828 | sdc.searchContext = NULL; | 819 | sdc.searchContext = NULL; |
829 | sdc.parentContext = NULL; | 820 | sdc.parentContext = NULL; |
830 | run_with_save_calls(&init_download_helper, | 821 | run_with_save_calls (&init_download_helper, &sdc); |
831 | &sdc); | 822 | ECRS_freeMetaData (sdc.idc_meta); |
832 | ECRS_freeMetaData(sdc.idc_meta); | 823 | FREE (sdc.idc_final_download_destination); |
833 | FREE(sdc.idc_final_download_destination); | 824 | FREE (urid); |
834 | FREE(urid); | ||
835 | } | 825 | } |
836 | 826 | ||
837 | struct FCBC { | 827 | struct FCBC |
838 | int (*method)(struct FSUI_Context * ctx, | 828 | { |
839 | struct FSUI_DownloadList * list); | 829 | int (*method) (struct FSUI_Context * ctx, struct FSUI_DownloadList * list); |
840 | struct FSUI_DownloadList * argument; | 830 | struct FSUI_DownloadList *argument; |
841 | }; | 831 | }; |
842 | 832 | ||
843 | static void * fsui_callback(void * cls) { | 833 | static void * |
844 | struct FCBC * fcbc = cls; | 834 | fsui_callback (void *cls) |
845 | fcbc->method(ctx, | 835 | { |
846 | fcbc->argument); | 836 | struct FCBC *fcbc = cls; |
837 | fcbc->method (ctx, fcbc->argument); | ||
847 | return NULL; | 838 | return NULL; |
848 | } | 839 | } |
849 | 840 | ||
850 | static void | 841 | static void |
851 | clearCompletedDownloadCallback(GtkTreeModel * model, | 842 | clearCompletedDownloadCallback (GtkTreeModel * model, |
852 | GtkTreePath * path, | 843 | GtkTreePath * path, |
853 | GtkTreeIter * iter, | 844 | GtkTreeIter * iter, gpointer unused) |
854 | gpointer unused) { | 845 | { |
855 | DownloadList * dl; | 846 | DownloadList *dl; |
856 | struct FCBC fcbc; | 847 | struct FCBC fcbc; |
857 | 848 | ||
858 | GE_ASSERT(ectx, | 849 | GE_ASSERT (ectx, model == GTK_TREE_MODEL (download_summary)); |
859 | model == GTK_TREE_MODEL(download_summary)); | 850 | gtk_tree_model_get (model, iter, DOWNLOAD_INTERNAL, &dl, -1); |
860 | gtk_tree_model_get(model, | 851 | if ((FALSE == gtk_tree_model_iter_has_child (model, |
861 | iter, | 852 | iter)) && (dl->has_terminated)) |
862 | DOWNLOAD_INTERNAL, &dl, | 853 | { |
863 | -1); | 854 | fcbc.method = &FSUI_stopDownload; |
864 | if ( (FALSE == gtk_tree_model_iter_has_child(model, | 855 | fcbc.argument = dl->fsui_list; |
865 | iter)) && | 856 | run_with_save_calls (&fsui_callback, &fcbc); |
866 | (dl->has_terminated) ) { | 857 | } |
867 | fcbc.method = &FSUI_stopDownload; | ||
868 | fcbc.argument = dl->fsui_list; | ||
869 | run_with_save_calls(&fsui_callback, | ||
870 | &fcbc); | ||
871 | } | ||
872 | } | 858 | } |
873 | 859 | ||
874 | void on_clearCompletedDownloadsButton_clicked_fs(void * unused, | 860 | void |
875 | GtkWidget * clearButton) { | 861 | on_clearCompletedDownloadsButton_clicked_fs (void *unused, |
876 | ggc_tree_model_foreach(GTK_TREE_MODEL(download_summary), | 862 | GtkWidget * clearButton) |
877 | &clearCompletedDownloadCallback, | 863 | { |
878 | NULL); | 864 | ggc_tree_model_foreach (GTK_TREE_MODEL (download_summary), |
865 | &clearCompletedDownloadCallback, NULL); | ||
879 | } | 866 | } |
880 | 867 | ||
881 | static void | 868 | static void |
882 | fsuiCallDownloadCallback(GtkTreeModel * model, | 869 | fsuiCallDownloadCallback (GtkTreeModel * model, |
883 | GtkTreePath * path, | 870 | GtkTreePath * path, |
884 | GtkTreeIter * iter, | 871 | GtkTreeIter * iter, gpointer fsui_call) |
885 | gpointer fsui_call) { | 872 | { |
886 | DownloadList * dl; | 873 | DownloadList *dl; |
887 | struct FCBC fcbc; | 874 | struct FCBC fcbc; |
888 | 875 | ||
889 | GE_ASSERT(ectx, | 876 | GE_ASSERT (ectx, model == GTK_TREE_MODEL (download_summary)); |
890 | model == GTK_TREE_MODEL(download_summary)); | 877 | gtk_tree_model_get (model, iter, DOWNLOAD_INTERNAL, &dl, -1); |
891 | gtk_tree_model_get(model, | ||
892 | iter, | ||
893 | DOWNLOAD_INTERNAL, &dl, | ||
894 | -1); | ||
895 | fcbc.method = fsui_call; | 878 | fcbc.method = fsui_call; |
896 | fcbc.argument = dl->fsui_list; | 879 | fcbc.argument = dl->fsui_list; |
897 | run_with_save_calls(&fsui_callback, | 880 | run_with_save_calls (&fsui_callback, &fcbc); |
898 | &fcbc); | ||
899 | } | 881 | } |
900 | 882 | ||
901 | void on_abortDownloadButton_clicked_fs(void * unused, | 883 | void |
902 | GtkWidget * abortButton) { | 884 | on_abortDownloadButton_clicked_fs (void *unused, GtkWidget * abortButton) |
903 | GtkTreeSelection * selection; | 885 | { |
904 | GtkWidget * downloadList; | 886 | GtkTreeSelection *selection; |
887 | GtkWidget *downloadList; | ||
905 | 888 | ||
906 | downloadList = glade_xml_get_widget(getMainXML(), | 889 | downloadList = glade_xml_get_widget (getMainXML (), "activeDownloadsList"); |
907 | "activeDownloadsList"); | 890 | selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (downloadList)); |
908 | selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(downloadList)); | ||
909 | ggc_tree_selection_selected_foreach | 891 | ggc_tree_selection_selected_foreach |
910 | (selection, | 892 | (selection, &fsuiCallDownloadCallback, &FSUI_abortDownload); |
911 | &fsuiCallDownloadCallback, | ||
912 | &FSUI_abortDownload); | ||
913 | } | 893 | } |
914 | 894 | ||
915 | void on_stopDownloadButton_clicked_fs(void * unused, | 895 | void |
916 | GtkWidget * stopButton) { | 896 | on_stopDownloadButton_clicked_fs (void *unused, GtkWidget * stopButton) |
917 | GtkTreeSelection * selection; | 897 | { |
918 | GtkWidget * downloadList; | 898 | GtkTreeSelection *selection; |
899 | GtkWidget *downloadList; | ||
919 | 900 | ||
920 | downloadList = glade_xml_get_widget(getMainXML(), | 901 | downloadList = glade_xml_get_widget (getMainXML (), "activeDownloadsList"); |
921 | "activeDownloadsList"); | 902 | selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (downloadList)); |
922 | selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(downloadList)); | ||
923 | ggc_tree_selection_selected_foreach | 903 | ggc_tree_selection_selected_foreach |
924 | (selection, | 904 | (selection, &fsuiCallDownloadCallback, &FSUI_abortDownload); |
925 | &fsuiCallDownloadCallback, | ||
926 | &FSUI_abortDownload); | ||
927 | ggc_tree_selection_selected_foreach | 905 | ggc_tree_selection_selected_foreach |
928 | (selection, | 906 | (selection, &fsuiCallDownloadCallback, &FSUI_stopDownload); |
929 | &fsuiCallDownloadCallback, | ||
930 | &FSUI_stopDownload); | ||
931 | } | 907 | } |
932 | 908 | ||
933 | /* end of download.c */ | 909 | /* end of download.c */ |
diff --git a/src/plugins/fs/download.h b/src/plugins/fs/download.h index d03be966..9f09f263 100644 --- a/src/plugins/fs/download.h +++ b/src/plugins/fs/download.h | |||
@@ -31,27 +31,24 @@ | |||
31 | #include <GNUnet/gnunet_fsui_lib.h> | 31 | #include <GNUnet/gnunet_fsui_lib.h> |
32 | #include "fs.h" | 32 | #include "fs.h" |
33 | 33 | ||
34 | DownloadList * | 34 | DownloadList *fs_download_started (struct FSUI_DownloadList *fsui_dl, |
35 | fs_download_started(struct FSUI_DownloadList * fsui_dl, | 35 | DownloadList * dl_parent, |
36 | DownloadList * dl_parent, | 36 | SearchList * sl_parent, |
37 | SearchList * sl_parent, | 37 | unsigned long long total, |
38 | unsigned long long total, | 38 | unsigned int anonymityLevel, |
39 | unsigned int anonymityLevel, | 39 | const ECRS_FileInfo * fi, |
40 | const ECRS_FileInfo * fi, | 40 | const char *filename, |
41 | const char * filename, | 41 | unsigned long long completed, |
42 | unsigned long long completed, | 42 | cron_t eta, FSUI_State state); |
43 | cron_t eta, | 43 | |
44 | FSUI_State state); | 44 | void fs_download_update (DownloadList * downloadContext, |
45 | 45 | unsigned long long completed, | |
46 | void fs_download_update(DownloadList * downloadContext, | 46 | const char *data, unsigned int size); |
47 | unsigned long long completed, | 47 | |
48 | const char * data, | 48 | void fs_download_completed (DownloadList * downloadContext); |
49 | unsigned int size); | 49 | |
50 | 50 | void fs_download_aborted (DownloadList * downloadContext); | |
51 | void fs_download_completed(DownloadList * downloadContext); | 51 | |
52 | 52 | void fs_download_stopped (DownloadList * downloadContext); | |
53 | void fs_download_aborted(DownloadList * downloadContext); | ||
54 | |||
55 | void fs_download_stopped(DownloadList * downloadContext); | ||
56 | 53 | ||
57 | #endif | 54 | #endif |
diff --git a/src/plugins/fs/extensions/musicinsert.c b/src/plugins/fs/extensions/musicinsert.c index a586e362..0e5798f5 100644 --- a/src/plugins/fs/extensions/musicinsert.c +++ b/src/plugins/fs/extensions/musicinsert.c | |||
@@ -56,7 +56,7 @@ EXTRACTOR_ExtractorList *Extractors; | |||
56 | GtkWidget *musicinsertdialog; | 56 | GtkWidget *musicinsertdialog; |
57 | 57 | ||
58 | GtkTreeViewColumn *filename_list_col, *title_list_col, *artist_list_col, | 58 | GtkTreeViewColumn *filename_list_col, *title_list_col, *artist_list_col, |
59 | *album_list_col, *type_list_col, *format_list_col, *keywords_list_col; | 59 | *album_list_col, *type_list_col, *format_list_col, *keywords_list_col; |
60 | 60 | ||
61 | GtkWidget *filelist_popup; | 61 | GtkWidget *filelist_popup; |
62 | 62 | ||
@@ -66,260 +66,236 @@ main (int argc, char *argv[]) | |||
66 | 66 | ||
67 | 67 | ||
68 | 68 | ||
69 | gtk_init (&argc, &argv); | 69 | gtk_init (&argc, &argv); |
70 | 70 | ||
71 | show_musicinsertdialog (); | 71 | show_musicinsertdialog (); |
72 | 72 | ||
73 | gtk_main (); | 73 | gtk_main (); |
74 | return 0; | 74 | return 0; |
75 | } | 75 | } |
76 | 76 | ||
77 | void | 77 | void |
78 | show_musicinsertdialog () | 78 | show_musicinsertdialog () |
79 | { | 79 | { |
80 | musicinsertXML = | 80 | musicinsertXML = |
81 | glade_xml_new (MUSICINSERTXMLFILE, "musicinsertdialog", | 81 | glade_xml_new (MUSICINSERTXMLFILE, "musicinsertdialog", PACKAGE_NAME); |
82 | PACKAGE_NAME); | 82 | glade_xml_signal_autoconnect (musicinsertXML); |
83 | glade_xml_signal_autoconnect (musicinsertXML); | ||
84 | /* libglade*/ | 83 | /* libglade*/ |
85 | 84 | ||
86 | 85 | ||
87 | gtk_set_locale (); | 86 | gtk_set_locale (); |
88 | 87 | ||
89 | musicinsertdialog = | 88 | musicinsertdialog = |
90 | glade_xml_get_widget (musicinsertXML, "musicinsertdialog"); | 89 | glade_xml_get_widget (musicinsertXML, "musicinsertdialog"); |
91 | 90 | ||
92 | /* | 91 | /* |
93 | * Create the 3 ComboBoxEntry manually (libglade doesn't handle this well : | 92 | * Create the 3 ComboBoxEntry manually (libglade doesn't handle this well : |
94 | * should use gtk_combo_box_entry_new_text instead of gtk_combo_box_entry_new) | 93 | * should use gtk_combo_box_entry_new_text instead of gtk_combo_box_entry_new) |
95 | */ | 94 | */ |
96 | artistcombobox = | 95 | artistcombobox = GTK_COMBO_BOX_ENTRY (gtk_combo_box_entry_new_text ()); |
97 | GTK_COMBO_BOX_ENTRY (gtk_combo_box_entry_new_text ()); | 96 | albumcombobox = GTK_COMBO_BOX_ENTRY (gtk_combo_box_entry_new_text ()); |
98 | albumcombobox = GTK_COMBO_BOX_ENTRY (gtk_combo_box_entry_new_text ()); | 97 | typecombobox = GTK_COMBO_BOX_ENTRY (gtk_combo_box_entry_new_text ()); |
99 | typecombobox = GTK_COMBO_BOX_ENTRY (gtk_combo_box_entry_new_text ()); | 98 | |
100 | 99 | gtk_combo_box_append_text (GTK_COMBO_BOX (typecombobox), | |
101 | gtk_combo_box_append_text (GTK_COMBO_BOX (typecombobox), | 100 | "Ogg (application/ogg)"); |
102 | "Ogg (application/ogg)"); | 101 | gtk_combo_box_append_text (GTK_COMBO_BOX (typecombobox), |
103 | gtk_combo_box_append_text (GTK_COMBO_BOX (typecombobox), | 102 | "MP3 (audio/mpeg)"); |
104 | "MP3 (audio/mpeg)"); | 103 | gtk_combo_box_append_text (GTK_COMBO_BOX (typecombobox), |
105 | gtk_combo_box_append_text (GTK_COMBO_BOX (typecombobox), | 104 | "MPC (application/x-musepack)"); |
106 | "MPC (application/x-musepack)"); | 105 | gtk_combo_box_append_text (GTK_COMBO_BOX (typecombobox), "AAC"); |
107 | gtk_combo_box_append_text (GTK_COMBO_BOX (typecombobox), "AAC"); | 106 | gtk_combo_box_append_text (GTK_COMBO_BOX (typecombobox), |
108 | gtk_combo_box_append_text (GTK_COMBO_BOX (typecombobox), | 107 | "WMA (audio/x-ms-wma)"); |
109 | "WMA (audio/x-ms-wma)"); | 108 | gtk_combo_box_append_text (GTK_COMBO_BOX (typecombobox), |
110 | gtk_combo_box_append_text (GTK_COMBO_BOX (typecombobox), | 109 | "FLAC (audio/flac)"); |
111 | "FLAC (audio/flac)"); | 110 | gtk_combo_box_append_text (GTK_COMBO_BOX (typecombobox), "APE"); |
112 | gtk_combo_box_append_text (GTK_COMBO_BOX (typecombobox), "APE"); | 111 | gtk_combo_box_append_text (GTK_COMBO_BOX (typecombobox), |
113 | gtk_combo_box_append_text (GTK_COMBO_BOX (typecombobox), | 112 | "WAV (application/x-wav)"); |
114 | "WAV (application/x-wav)"); | 113 | gtk_combo_box_append_text (GTK_COMBO_BOX (typecombobox), |
115 | gtk_combo_box_append_text (GTK_COMBO_BOX (typecombobox), | 114 | "REAL (audio/vnd.rn-realaudio)"); |
116 | "REAL (audio/vnd.rn-realaudio)"); | 115 | gtk_combo_box_append_text (GTK_COMBO_BOX (typecombobox), |
117 | gtk_combo_box_append_text (GTK_COMBO_BOX (typecombobox), | 116 | "MIDI (audio/x-midi)"); |
118 | "MIDI (audio/x-midi)"); | 117 | |
119 | 118 | GtkWidget *globaltable = | |
120 | GtkWidget *globaltable = | 119 | glade_xml_get_widget (musicinsertXML, "globaltable"); |
121 | glade_xml_get_widget (musicinsertXML, "globaltable"); | 120 | gtk_table_attach (GTK_TABLE (globaltable), |
122 | gtk_table_attach (GTK_TABLE (globaltable), | 121 | GTK_WIDGET (artistcombobox), 1, 3, 1, 2, |
123 | GTK_WIDGET (artistcombobox), 1, 3, 1, 2, | 122 | GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0); |
124 | GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0); | 123 | gtk_table_attach (GTK_TABLE (globaltable), GTK_WIDGET (albumcombobox), |
125 | gtk_table_attach (GTK_TABLE (globaltable), GTK_WIDGET (albumcombobox), | 124 | 1, 3, 2, 3, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0); |
126 | 1, 3, 2, 3, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, | 125 | gtk_table_attach (GTK_TABLE (globaltable), GTK_WIDGET (typecombobox), |
127 | 0); | 126 | 1, 3, 3, 4, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0); |
128 | gtk_table_attach (GTK_TABLE (globaltable), GTK_WIDGET (typecombobox), | 127 | |
129 | 1, 3, 3, 4, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, | 128 | gtk_widget_show (GTK_WIDGET (artistcombobox)); |
130 | 0); | 129 | gtk_widget_show (GTK_WIDGET (albumcombobox)); |
131 | 130 | gtk_widget_show (GTK_WIDGET (typecombobox)); | |
132 | gtk_widget_show (GTK_WIDGET (artistcombobox)); | 131 | |
133 | gtk_widget_show (GTK_WIDGET (albumcombobox)); | 132 | /* |
134 | gtk_widget_show (GTK_WIDGET (typecombobox)); | 133 | * treeview creation |
135 | 134 | */ | |
136 | /* | 135 | |
137 | * treeview creation | 136 | /* liststore model */ |
138 | */ | 137 | filelist_store = |
139 | 138 | gtk_list_store_new (COLS_NUMBER, G_TYPE_STRING, G_TYPE_STRING, | |
140 | /* liststore model */ | 139 | G_TYPE_STRING, G_TYPE_STRING, |
141 | filelist_store = | 140 | G_TYPE_STRING, G_TYPE_STRING, |
142 | gtk_list_store_new (COLS_NUMBER, G_TYPE_STRING, G_TYPE_STRING, | 141 | G_TYPE_STRING, G_TYPE_STRING); |
143 | G_TYPE_STRING, G_TYPE_STRING, | 142 | |
144 | G_TYPE_STRING, G_TYPE_STRING, | 143 | /* view */ |
145 | G_TYPE_STRING, G_TYPE_STRING); | 144 | GtkWidget *filelist = glade_xml_get_widget (musicinsertXML, "filelist"); |
146 | 145 | gtk_tree_view_set_model (GTK_TREE_VIEW (filelist), | |
147 | /* view */ | 146 | GTK_TREE_MODEL (filelist_store)); |
148 | GtkWidget *filelist = | 147 | |
149 | glade_xml_get_widget (musicinsertXML, "filelist"); | 148 | /* cells definition */ |
150 | gtk_tree_view_set_model (GTK_TREE_VIEW (filelist), | 149 | GtkCellRenderer *filename_renderer = gtk_cell_renderer_text_new (); |
151 | GTK_TREE_MODEL (filelist_store)); | 150 | g_object_set (filename_renderer, "editable", TRUE, NULL); |
152 | 151 | GtkCellRenderer *title_renderer = gtk_cell_renderer_text_new (); | |
153 | /* cells definition */ | 152 | g_object_set (title_renderer, "editable", TRUE, NULL); |
154 | GtkCellRenderer *filename_renderer = gtk_cell_renderer_text_new (); | 153 | GtkCellRenderer *artist_renderer = gtk_cell_renderer_text_new (); |
155 | g_object_set (filename_renderer, "editable", TRUE, NULL); | 154 | g_object_set (artist_renderer, "editable", TRUE, NULL); |
156 | GtkCellRenderer *title_renderer = gtk_cell_renderer_text_new (); | 155 | GtkCellRenderer *album_renderer = gtk_cell_renderer_text_new (); |
157 | g_object_set (title_renderer, "editable", TRUE, NULL); | 156 | g_object_set (album_renderer, "editable", TRUE, NULL); |
158 | GtkCellRenderer *artist_renderer = gtk_cell_renderer_text_new (); | 157 | GtkCellRenderer *type_renderer = gtk_cell_renderer_text_new (); |
159 | g_object_set (artist_renderer, "editable", TRUE, NULL); | 158 | g_object_set (type_renderer, "editable", TRUE, NULL); |
160 | GtkCellRenderer *album_renderer = gtk_cell_renderer_text_new (); | 159 | GtkCellRenderer *format_renderer = gtk_cell_renderer_text_new (); |
161 | g_object_set (album_renderer, "editable", TRUE, NULL); | 160 | g_object_set (format_renderer, "editable", TRUE, NULL); |
162 | GtkCellRenderer *type_renderer = gtk_cell_renderer_text_new (); | 161 | GtkCellRenderer *keywords_renderer = gtk_cell_renderer_text_new (); |
163 | g_object_set (type_renderer, "editable", TRUE, NULL); | 162 | g_object_set (keywords_renderer, "editable", TRUE, NULL); |
164 | GtkCellRenderer *format_renderer = gtk_cell_renderer_text_new (); | 163 | |
165 | g_object_set (format_renderer, "editable", TRUE, NULL); | 164 | |
166 | GtkCellRenderer *keywords_renderer = gtk_cell_renderer_text_new (); | 165 | g_signal_connect ((gpointer) filename_renderer, "edited", |
167 | g_object_set (keywords_renderer, "editable", TRUE, NULL); | 166 | G_CALLBACK (on_renderer_edited), |
168 | 167 | (gpointer) & filename_col_num); | |
169 | 168 | g_signal_connect ((gpointer) title_renderer, "edited", | |
170 | g_signal_connect ((gpointer) filename_renderer, "edited", | 169 | G_CALLBACK (on_renderer_edited), |
171 | G_CALLBACK (on_renderer_edited), | 170 | (gpointer) & title_col_num); |
172 | (gpointer) & filename_col_num); | 171 | g_signal_connect ((gpointer) artist_renderer, "edited", |
173 | g_signal_connect ((gpointer) title_renderer, "edited", | 172 | G_CALLBACK (on_renderer_edited), |
174 | G_CALLBACK (on_renderer_edited), | 173 | (gpointer) & artist_col_num); |
175 | (gpointer) & title_col_num); | 174 | g_signal_connect ((gpointer) album_renderer, "edited", |
176 | g_signal_connect ((gpointer) artist_renderer, "edited", | 175 | G_CALLBACK (on_renderer_edited), |
177 | G_CALLBACK (on_renderer_edited), | 176 | (gpointer) & album_col_num); |
178 | (gpointer) & artist_col_num); | 177 | g_signal_connect ((gpointer) type_renderer, "edited", |
179 | g_signal_connect ((gpointer) album_renderer, "edited", | 178 | G_CALLBACK (on_renderer_edited), |
180 | G_CALLBACK (on_renderer_edited), | 179 | (gpointer) & type_col_num); |
181 | (gpointer) & album_col_num); | 180 | g_signal_connect ((gpointer) format_renderer, "edited", |
182 | g_signal_connect ((gpointer) type_renderer, "edited", | 181 | G_CALLBACK (on_renderer_edited), |
183 | G_CALLBACK (on_renderer_edited), | 182 | (gpointer) & format_col_num); |
184 | (gpointer) & type_col_num); | 183 | g_signal_connect ((gpointer) keywords_renderer, "edited", |
185 | g_signal_connect ((gpointer) format_renderer, "edited", | 184 | G_CALLBACK (on_renderer_edited), |
186 | G_CALLBACK (on_renderer_edited), | 185 | (gpointer) & keywords_col_num); |
187 | (gpointer) & format_col_num); | 186 | |
188 | g_signal_connect ((gpointer) keywords_renderer, "edited", | 187 | /* columns definition */ |
189 | G_CALLBACK (on_renderer_edited), | 188 | filename_list_col = |
190 | (gpointer) & keywords_col_num); | 189 | gtk_tree_view_column_new_with_attributes (_ |
191 | 190 | ("Published filename"), | |
192 | /* columns definition */ | 191 | filename_renderer, |
193 | filename_list_col = | 192 | "text", FILENAME_COL, NULL); |
194 | gtk_tree_view_column_new_with_attributes (_ | 193 | title_list_col = |
195 | ("Published filename"), | 194 | gtk_tree_view_column_new_with_attributes (_("Title"), |
196 | filename_renderer, | 195 | title_renderer, |
197 | "text", | 196 | "text", TITLE_COL, NULL); |
198 | FILENAME_COL, NULL); | 197 | artist_list_col = |
199 | title_list_col = | 198 | gtk_tree_view_column_new_with_attributes (_("Artist"), |
200 | gtk_tree_view_column_new_with_attributes (_("Title"), | 199 | artist_renderer, |
201 | title_renderer, | 200 | "text", ARTIST_COL, NULL); |
202 | "text", TITLE_COL, | 201 | album_list_col = |
203 | NULL); | 202 | gtk_tree_view_column_new_with_attributes (_("Album"), |
204 | artist_list_col = | 203 | album_renderer, |
205 | gtk_tree_view_column_new_with_attributes (_("Artist"), | 204 | "text", ALBUM_COL, NULL); |
206 | artist_renderer, | 205 | type_list_col = |
207 | "text", ARTIST_COL, | 206 | gtk_tree_view_column_new_with_attributes (_("Type"), |
208 | NULL); | 207 | type_renderer, |
209 | album_list_col = | 208 | "text", TYPE_COL, NULL); |
210 | gtk_tree_view_column_new_with_attributes (_("Album"), | 209 | format_list_col = |
211 | album_renderer, | 210 | gtk_tree_view_column_new_with_attributes (_("Format"), |
212 | "text", ALBUM_COL, | 211 | format_renderer, |
213 | NULL); | 212 | "text", FORMAT_COL, NULL); |
214 | type_list_col = | 213 | keywords_list_col = |
215 | gtk_tree_view_column_new_with_attributes (_("Type"), | 214 | gtk_tree_view_column_new_with_attributes (_("Keywords"), |
216 | type_renderer, | 215 | keywords_renderer, |
217 | "text", TYPE_COL, | 216 | "text", KEYWORDS_COL, NULL); |
218 | NULL); | ||
219 | format_list_col = | ||
220 | gtk_tree_view_column_new_with_attributes (_("Format"), | ||
221 | format_renderer, | ||
222 | "text", FORMAT_COL, | ||
223 | NULL); | ||
224 | keywords_list_col = | ||
225 | gtk_tree_view_column_new_with_attributes (_("Keywords"), | ||
226 | keywords_renderer, | ||
227 | "text", | ||
228 | KEYWORDS_COL, NULL); | ||
229 | 217 | ||
230 | /* Allow sorting for all columns */ | 218 | /* Allow sorting for all columns */ |
231 | gtk_tree_view_column_set_sort_column_id (filename_list_col, | 219 | gtk_tree_view_column_set_sort_column_id (filename_list_col, FILENAME_COL); |
232 | FILENAME_COL); | 220 | gtk_tree_view_column_set_sort_column_id (title_list_col, TITLE_COL); |
233 | gtk_tree_view_column_set_sort_column_id (title_list_col, TITLE_COL); | 221 | gtk_tree_view_column_set_sort_column_id (artist_list_col, ARTIST_COL); |
234 | gtk_tree_view_column_set_sort_column_id (artist_list_col, ARTIST_COL); | 222 | gtk_tree_view_column_set_sort_column_id (album_list_col, ALBUM_COL); |
235 | gtk_tree_view_column_set_sort_column_id (album_list_col, ALBUM_COL); | 223 | gtk_tree_view_column_set_sort_column_id (type_list_col, TYPE_COL); |
236 | gtk_tree_view_column_set_sort_column_id (type_list_col, TYPE_COL); | 224 | gtk_tree_view_column_set_sort_column_id (format_list_col, FORMAT_COL); |
237 | gtk_tree_view_column_set_sort_column_id (format_list_col, FORMAT_COL); | 225 | gtk_tree_view_column_set_sort_column_id (keywords_list_col, KEYWORDS_COL); |
238 | gtk_tree_view_column_set_sort_column_id (keywords_list_col, | 226 | |
239 | KEYWORDS_COL); | 227 | /* Allow to resize all columns */ |
240 | 228 | gtk_tree_view_column_set_resizable (filename_list_col, TRUE); | |
241 | /* Allow to resize all columns */ | 229 | gtk_tree_view_column_set_resizable (title_list_col, TRUE); |
242 | gtk_tree_view_column_set_resizable (filename_list_col, TRUE); | 230 | gtk_tree_view_column_set_resizable (artist_list_col, TRUE); |
243 | gtk_tree_view_column_set_resizable (title_list_col, TRUE); | 231 | gtk_tree_view_column_set_resizable (album_list_col, TRUE); |
244 | gtk_tree_view_column_set_resizable (artist_list_col, TRUE); | 232 | gtk_tree_view_column_set_resizable (type_list_col, TRUE); |
245 | gtk_tree_view_column_set_resizable (album_list_col, TRUE); | 233 | gtk_tree_view_column_set_resizable (format_list_col, TRUE); |
246 | gtk_tree_view_column_set_resizable (type_list_col, TRUE); | 234 | gtk_tree_view_column_set_resizable (keywords_list_col, TRUE); |
247 | gtk_tree_view_column_set_resizable (format_list_col, TRUE); | 235 | |
248 | gtk_tree_view_column_set_resizable (keywords_list_col, TRUE); | 236 | /* Hide unedeed columns */ |
249 | 237 | gtk_tree_view_column_set_visible (artist_list_col, FALSE); | |
250 | /* Hide unedeed columns */ | 238 | gtk_tree_view_column_set_visible (album_list_col, FALSE); |
251 | gtk_tree_view_column_set_visible (artist_list_col, FALSE); | 239 | gtk_tree_view_column_set_visible (type_list_col, FALSE); |
252 | gtk_tree_view_column_set_visible (album_list_col, FALSE); | 240 | gtk_tree_view_column_set_visible (keywords_list_col, FALSE); |
253 | gtk_tree_view_column_set_visible (type_list_col, FALSE); | 241 | |
254 | gtk_tree_view_column_set_visible (keywords_list_col, FALSE); | 242 | /* Set a smart option */ |
255 | 243 | gtk_tree_view_get_hover_expand (GTK_TREE_VIEW (filelist)); | |
256 | /* Set a smart option */ | 244 | |
257 | gtk_tree_view_get_hover_expand (GTK_TREE_VIEW (filelist)); | 245 | /* add columns to view */ |
258 | 246 | gtk_tree_view_append_column (GTK_TREE_VIEW (filelist), filename_list_col); | |
259 | /* add columns to view */ | 247 | gtk_tree_view_append_column (GTK_TREE_VIEW (filelist), title_list_col); |
260 | gtk_tree_view_append_column (GTK_TREE_VIEW (filelist), | 248 | gtk_tree_view_append_column (GTK_TREE_VIEW (filelist), artist_list_col); |
261 | filename_list_col); | 249 | gtk_tree_view_append_column (GTK_TREE_VIEW (filelist), album_list_col); |
262 | gtk_tree_view_append_column (GTK_TREE_VIEW (filelist), | 250 | gtk_tree_view_append_column (GTK_TREE_VIEW (filelist), type_list_col); |
263 | title_list_col); | 251 | gtk_tree_view_append_column (GTK_TREE_VIEW (filelist), format_list_col); |
264 | gtk_tree_view_append_column (GTK_TREE_VIEW (filelist), | 252 | gtk_tree_view_append_column (GTK_TREE_VIEW (filelist), keywords_list_col); |
265 | artist_list_col); | 253 | |
266 | gtk_tree_view_append_column (GTK_TREE_VIEW (filelist), | 254 | /* Expand columns */ |
267 | album_list_col); | 255 | gtk_tree_view_column_set_expand (filename_list_col, TRUE); |
268 | gtk_tree_view_append_column (GTK_TREE_VIEW (filelist), type_list_col); | 256 | gtk_tree_view_column_set_expand (artist_list_col, TRUE); |
269 | gtk_tree_view_append_column (GTK_TREE_VIEW (filelist), | 257 | gtk_tree_view_column_set_expand (album_list_col, TRUE); |
270 | format_list_col); | 258 | gtk_tree_view_column_set_expand (type_list_col, TRUE); |
271 | gtk_tree_view_append_column (GTK_TREE_VIEW (filelist), | 259 | gtk_tree_view_column_set_expand (format_list_col, TRUE); |
272 | keywords_list_col); | 260 | gtk_tree_view_column_set_expand (keywords_list_col, TRUE); |
273 | 261 | ||
274 | /* Expand columns */ | 262 | /* Allow multiple selections */ |
275 | gtk_tree_view_column_set_expand (filename_list_col, TRUE); | 263 | GtkTreeSelection *filelist_selection = |
276 | gtk_tree_view_column_set_expand (artist_list_col, TRUE); | 264 | gtk_tree_view_get_selection (GTK_TREE_VIEW (filelist)); |
277 | gtk_tree_view_column_set_expand (album_list_col, TRUE); | 265 | gtk_tree_selection_set_mode (filelist_selection, GTK_SELECTION_MULTIPLE); |
278 | gtk_tree_view_column_set_expand (type_list_col, TRUE); | 266 | |
279 | gtk_tree_view_column_set_expand (format_list_col, TRUE); | 267 | |
280 | gtk_tree_view_column_set_expand (keywords_list_col, TRUE); | 268 | |
281 | 269 | AlbumList = NULL; | |
282 | /* Allow multiple selections */ | 270 | ArtistList = NULL; |
283 | GtkTreeSelection *filelist_selection = | 271 | |
284 | gtk_tree_view_get_selection (GTK_TREE_VIEW (filelist)); | 272 | Extractors = EXTRACTOR_loadDefaultLibraries (); |
285 | gtk_tree_selection_set_mode (filelist_selection, | 273 | Extractors = |
286 | GTK_SELECTION_MULTIPLE); | 274 | EXTRACTOR_loadConfigLibraries (Extractors, "libextractor_filename"); |
287 | |||
288 | |||
289 | |||
290 | AlbumList = NULL; | ||
291 | ArtistList = NULL; | ||
292 | |||
293 | Extractors = EXTRACTOR_loadDefaultLibraries (); | ||
294 | Extractors = | ||
295 | EXTRACTOR_loadConfigLibraries (Extractors, | ||
296 | "libextractor_filename"); | ||
297 | 275 | ||
298 | /* Create the popup menu */ | 276 | /* Create the popup menu */ |
299 | filelist_popup = gtk_menu_new (); | 277 | filelist_popup = gtk_menu_new (); |
300 | GtkWidget *select_all_menu_item = | 278 | GtkWidget *select_all_menu_item = |
301 | gtk_menu_item_new_with_label (_("Select all files")); | 279 | gtk_menu_item_new_with_label (_("Select all files")); |
302 | GtkWidget *delete_menu_item = | 280 | GtkWidget *delete_menu_item = |
303 | gtk_menu_item_new_with_label (_("Remove selected files")); | 281 | gtk_menu_item_new_with_label (_("Remove selected files")); |
304 | gtk_menu_attach (GTK_MENU (filelist_popup), select_all_menu_item, 0, | 282 | gtk_menu_attach (GTK_MENU (filelist_popup), select_all_menu_item, 0, |
305 | 1, 0, 1); | 283 | 1, 0, 1); |
306 | gtk_menu_attach (GTK_MENU (filelist_popup), delete_menu_item, 0, 1, 1, | 284 | gtk_menu_attach (GTK_MENU (filelist_popup), delete_menu_item, 0, 1, 1, 2); |
307 | 2); | 285 | gtk_widget_show (select_all_menu_item); |
308 | gtk_widget_show (select_all_menu_item); | 286 | gtk_widget_show (delete_menu_item); |
309 | gtk_widget_show (delete_menu_item); | 287 | gtk_signal_connect (GTK_OBJECT (filelist), "button-press-event", |
310 | gtk_signal_connect (GTK_OBJECT (filelist), "button-press-event", | 288 | GTK_SIGNAL_FUNC (popup_delete), (gpointer) NULL); |
311 | GTK_SIGNAL_FUNC (popup_delete), (gpointer) NULL); | 289 | gtk_signal_connect (GTK_OBJECT (select_all_menu_item), "activate", |
312 | gtk_signal_connect (GTK_OBJECT (select_all_menu_item), "activate", | 290 | GTK_SIGNAL_FUNC (select_all_files), (gpointer) TRUE); |
313 | GTK_SIGNAL_FUNC (select_all_files), | 291 | gtk_signal_connect (GTK_OBJECT (delete_menu_item), "activate", |
314 | (gpointer) TRUE); | 292 | GTK_SIGNAL_FUNC (remove_file_from_list), |
315 | gtk_signal_connect (GTK_OBJECT (delete_menu_item), "activate", | 293 | (gpointer) NULL); |
316 | GTK_SIGNAL_FUNC (remove_file_from_list), | 294 | |
317 | (gpointer) NULL); | 295 | /* |
318 | 296 | * show the main window | |
319 | /* | 297 | */ |
320 | * show the main window | 298 | gtk_widget_show (musicinsertdialog); |
321 | */ | ||
322 | gtk_widget_show (musicinsertdialog); | ||
323 | } | 299 | } |
324 | 300 | ||
325 | /** | 301 | /** |
@@ -329,18 +305,17 @@ show_musicinsertdialog () | |||
329 | */ | 305 | */ |
330 | EXTRACTOR_KeywordList * | 306 | EXTRACTOR_KeywordList * |
331 | get_EXTRACTORKeywords (const EXTRACTOR_ExtractorList | 307 | get_EXTRACTORKeywords (const EXTRACTOR_ExtractorList |
332 | * exList, const char *filename) | 308 | * exList, const char *filename) |
333 | { | 309 | { |
334 | EXTRACTOR_KeywordList *keyList; | 310 | EXTRACTOR_KeywordList *keyList; |
335 | 311 | ||
336 | keyList = | 312 | keyList = |
337 | EXTRACTOR_getKeywords ((EXTRACTOR_ExtractorList *) exList, | 313 | EXTRACTOR_getKeywords ((EXTRACTOR_ExtractorList *) exList, filename); |
338 | filename); | 314 | keyList = |
339 | keyList = | 315 | EXTRACTOR_removeDuplicateKeywords (keyList, |
340 | EXTRACTOR_removeDuplicateKeywords (keyList, | 316 | EXTRACTOR_DUPLICATES_REMOVE_UNKNOWN); |
341 | EXTRACTOR_DUPLICATES_REMOVE_UNKNOWN); | 317 | keyList = EXTRACTOR_removeEmptyKeywords (keyList); |
342 | keyList = EXTRACTOR_removeEmptyKeywords (keyList); | 318 | return keyList; |
343 | return keyList; | ||
344 | } | 319 | } |
345 | 320 | ||
346 | 321 | ||
@@ -352,90 +327,75 @@ get_EXTRACTORKeywords (const EXTRACTOR_ExtractorList | |||
352 | void | 327 | void |
353 | set_File_Keywords (const gchar * filename) | 328 | set_File_Keywords (const gchar * filename) |
354 | { | 329 | { |
355 | char *keywords[7]; | 330 | char *keywords[7]; |
356 | GtkTreeIter pIter; | 331 | GtkTreeIter pIter; |
357 | 332 | ||
358 | EXTRACTOR_KeywordList *KeywordList = | 333 | EXTRACTOR_KeywordList *KeywordList = |
359 | get_EXTRACTORKeywords (Extractors, filename); | 334 | get_EXTRACTORKeywords (Extractors, filename); |
360 | 335 | ||
361 | 336 | ||
362 | keywords[0] = | 337 | keywords[0] = |
363 | (char *) EXTRACTOR_extractLast (EXTRACTOR_FILENAME, | 338 | (char *) EXTRACTOR_extractLast (EXTRACTOR_FILENAME, KeywordList); |
364 | KeywordList); | 339 | |
365 | 340 | keywords[1] = | |
366 | keywords[1] = | 341 | (char *) EXTRACTOR_extractLast (EXTRACTOR_FILENAME, KeywordList); |
367 | (char *) EXTRACTOR_extractLast (EXTRACTOR_FILENAME, | 342 | |
368 | KeywordList); | 343 | keywords[2] = (char *) EXTRACTOR_extractLast (EXTRACTOR_TITLE, KeywordList); |
369 | 344 | ||
370 | keywords[2] = | 345 | keywords[3] = |
371 | (char *) EXTRACTOR_extractLast (EXTRACTOR_TITLE, KeywordList); | 346 | (char *) EXTRACTOR_extractLast (EXTRACTOR_ARTIST, KeywordList); |
372 | 347 | if (keywords[3] != '\0' | |
373 | keywords[3] = | 348 | && |
374 | (char *) EXTRACTOR_extractLast (EXTRACTOR_ARTIST, | 349 | (g_list_find_custom |
375 | KeywordList); | 350 | (ArtistList, keywords[3], (GCompareFunc) strcmp) == NULL)) |
376 | if (keywords[3] != '\0' | 351 | { |
377 | && | 352 | ArtistList = g_list_append (ArtistList, STRDUP (keywords[3])); |
378 | (g_list_find_custom | 353 | gtk_combo_box_append_text (GTK_COMBO_BOX (artistcombobox), keywords[3]); |
379 | (ArtistList, keywords[3], (GCompareFunc) strcmp) == NULL)) | 354 | } |
380 | { | 355 | |
381 | ArtistList = g_list_append (ArtistList, STRDUP (keywords[3])); | 356 | keywords[4] = (char *) EXTRACTOR_extractLast (EXTRACTOR_ALBUM, KeywordList); |
382 | gtk_combo_box_append_text (GTK_COMBO_BOX | 357 | if (keywords[4] != '\0' |
383 | (artistcombobox), keywords[3]); | 358 | && |
384 | } | 359 | (g_list_find_custom |
385 | 360 | (AlbumList, keywords[4], (GCompareFunc) strcmp)) == NULL) | |
386 | keywords[4] = | 361 | { |
387 | (char *) EXTRACTOR_extractLast (EXTRACTOR_ALBUM, KeywordList); | 362 | AlbumList = g_list_append (AlbumList, STRDUP (keywords[4])); |
388 | if (keywords[4] != '\0' | 363 | gtk_combo_box_append_text (GTK_COMBO_BOX (albumcombobox), keywords[4]); |
389 | && | 364 | } |
390 | (g_list_find_custom | 365 | |
391 | (AlbumList, keywords[4], (GCompareFunc) strcmp)) == NULL) | 366 | keywords[5] = |
392 | { | 367 | (char *) EXTRACTOR_extractLast (EXTRACTOR_MIMETYPE, KeywordList); |
393 | AlbumList = g_list_append (AlbumList, STRDUP (keywords[4])); | 368 | if (keywords[5] != '\0') |
394 | gtk_combo_box_append_text (GTK_COMBO_BOX | 369 | { |
395 | (albumcombobox), keywords[4]); | 370 | if ((g_list_find_custom |
396 | } | 371 | (TypeList, keywords[5], (GCompareFunc) strcmp)) == NULL) |
397 | 372 | TypeList = g_list_append (TypeList, STRDUP (keywords[5])); | |
398 | keywords[5] = | 373 | |
399 | (char *) EXTRACTOR_extractLast (EXTRACTOR_MIMETYPE, | 374 | if (strcmp (keywords[5], "application/ogg") == 0) |
400 | KeywordList); | 375 | gtk_combo_box_set_active (GTK_COMBO_BOX (typecombobox), FORMAT_OGG); |
401 | if (keywords[5] != '\0') | 376 | else if (strcmp (keywords[5], "audio/mpeg") == 0) |
402 | { | 377 | gtk_combo_box_set_active (GTK_COMBO_BOX (typecombobox), FORMAT_MP3); |
403 | if ((g_list_find_custom | 378 | else if (strcmp (keywords[5], "application/x-wav") == 0) |
404 | (TypeList, keywords[5], (GCompareFunc) strcmp)) == NULL) | 379 | gtk_combo_box_set_active (GTK_COMBO_BOX (typecombobox), FORMAT_WAV); |
405 | TypeList = | 380 | else if (strcmp (keywords[5], "audio/vnd.rn-realaudio") == 0) |
406 | g_list_append (TypeList, | 381 | gtk_combo_box_set_active (GTK_COMBO_BOX (typecombobox), FORMAT_REAL); |
407 | STRDUP (keywords[5])); | 382 | } |
408 | 383 | else | |
409 | if (strcmp (keywords[5], "application/ogg") == 0) | 384 | { |
410 | gtk_combo_box_set_active (GTK_COMBO_BOX | 385 | TypeList = g_list_append (TypeList, STRDUP ("unspecified")); |
411 | (typecombobox), FORMAT_OGG); | 386 | } |
412 | else if (strcmp (keywords[5], "audio/mpeg") == 0) | 387 | |
413 | gtk_combo_box_set_active | 388 | keywords[6] = |
414 | (GTK_COMBO_BOX (typecombobox), FORMAT_MP3); | 389 | (char *) EXTRACTOR_extractLast (EXTRACTOR_FORMAT, KeywordList); |
415 | else if (strcmp (keywords[5], "application/x-wav") == 0) | 390 | |
416 | gtk_combo_box_set_active | 391 | gtk_list_store_append (filelist_store, &pIter); |
417 | (GTK_COMBO_BOX (typecombobox), FORMAT_WAV); | 392 | gtk_list_store_set (filelist_store, &pIter, REAL_FILENAME_COL, |
418 | else if (strcmp (keywords[5], "audio/vnd.rn-realaudio") == 0) | 393 | keywords[0], FILENAME_COL, keywords[1], TITLE_COL, |
419 | gtk_combo_box_set_active | 394 | keywords[2], ARTIST_COL, keywords[3], ALBUM_COL, |
420 | (GTK_COMBO_BOX (typecombobox), FORMAT_REAL); | 395 | keywords[4], TYPE_COL, keywords[5], FORMAT_COL, |
421 | } | 396 | keywords[6], KEYWORDS_COL, "", -1); |
422 | else | 397 | EXTRACTOR_freeKeywords (KeywordList); |
423 | { | 398 | return; |
424 | TypeList = g_list_append (TypeList, STRDUP ("unspecified")); | ||
425 | } | ||
426 | |||
427 | keywords[6] = | ||
428 | (char *) EXTRACTOR_extractLast (EXTRACTOR_FORMAT, | ||
429 | KeywordList); | ||
430 | |||
431 | gtk_list_store_append (filelist_store, &pIter); | ||
432 | gtk_list_store_set (filelist_store, &pIter, REAL_FILENAME_COL, | ||
433 | keywords[0], FILENAME_COL, keywords[1], TITLE_COL, | ||
434 | keywords[2], ARTIST_COL, keywords[3], ALBUM_COL, | ||
435 | keywords[4], TYPE_COL, keywords[5], FORMAT_COL, | ||
436 | keywords[6], KEYWORDS_COL, "", -1); | ||
437 | EXTRACTOR_freeKeywords (KeywordList); | ||
438 | return; | ||
439 | } | 399 | } |
440 | 400 | ||
441 | /** | 401 | /** |
@@ -445,28 +405,28 @@ void | |||
445 | activateComboBoxes () | 405 | activateComboBoxes () |
446 | { | 406 | { |
447 | 407 | ||
448 | if (gtk_combo_box_get_active (GTK_COMBO_BOX (albumcombobox)) < 0 | 408 | if (gtk_combo_box_get_active (GTK_COMBO_BOX (albumcombobox)) < 0 |
449 | && | 409 | && |
450 | gtk_tree_model_iter_n_children (gtk_combo_box_get_model | 410 | gtk_tree_model_iter_n_children (gtk_combo_box_get_model |
451 | (GTK_COMBO_BOX (albumcombobox)), | 411 | (GTK_COMBO_BOX (albumcombobox)), |
452 | NULL) != 0) | 412 | NULL) != 0) |
453 | gtk_combo_box_set_active (GTK_COMBO_BOX (albumcombobox), 0); | 413 | gtk_combo_box_set_active (GTK_COMBO_BOX (albumcombobox), 0); |
454 | 414 | ||
455 | if (gtk_combo_box_get_active (GTK_COMBO_BOX (artistcombobox)) < 0 | 415 | if (gtk_combo_box_get_active (GTK_COMBO_BOX (artistcombobox)) < 0 |
456 | && | 416 | && |
457 | gtk_tree_model_iter_n_children (gtk_combo_box_get_model | 417 | gtk_tree_model_iter_n_children (gtk_combo_box_get_model |
458 | (GTK_COMBO_BOX (artistcombobox)), | 418 | (GTK_COMBO_BOX (artistcombobox)), |
459 | NULL) != 0) | 419 | NULL) != 0) |
460 | gtk_combo_box_set_active (GTK_COMBO_BOX (artistcombobox), 0); | 420 | gtk_combo_box_set_active (GTK_COMBO_BOX (artistcombobox), 0); |
461 | 421 | ||
462 | if (gtk_combo_box_get_active (GTK_COMBO_BOX (typecombobox)) < 0 | 422 | if (gtk_combo_box_get_active (GTK_COMBO_BOX (typecombobox)) < 0 |
463 | && | 423 | && |
464 | gtk_tree_model_iter_n_children (gtk_combo_box_get_model | 424 | gtk_tree_model_iter_n_children (gtk_combo_box_get_model |
465 | (GTK_COMBO_BOX (typecombobox)), | 425 | (GTK_COMBO_BOX (typecombobox)), |
466 | NULL) != 0) | 426 | NULL) != 0) |
467 | gtk_combo_box_set_active (GTK_COMBO_BOX (typecombobox), 0); | 427 | gtk_combo_box_set_active (GTK_COMBO_BOX (typecombobox), 0); |
468 | 428 | ||
469 | return; | 429 | return; |
470 | } | 430 | } |
471 | 431 | ||
472 | /** | 432 | /** |
@@ -475,205 +435,198 @@ activateComboBoxes () | |||
475 | void | 435 | void |
476 | updateColumns () | 436 | updateColumns () |
477 | { | 437 | { |
478 | if (g_list_length (ArtistList) > 1) | 438 | if (g_list_length (ArtistList) > 1) |
479 | gtk_tree_view_column_set_visible (type_list_col, TRUE); | 439 | gtk_tree_view_column_set_visible (type_list_col, TRUE); |
480 | else | 440 | else |
481 | gtk_tree_view_column_set_visible (type_list_col, FALSE); | 441 | gtk_tree_view_column_set_visible (type_list_col, FALSE); |
482 | 442 | ||
483 | if (g_list_length (AlbumList) > 1) | 443 | if (g_list_length (AlbumList) > 1) |
484 | gtk_tree_view_column_set_visible (type_list_col, TRUE); | 444 | gtk_tree_view_column_set_visible (type_list_col, TRUE); |
485 | else | 445 | else |
486 | gtk_tree_view_column_set_visible (type_list_col, FALSE); | 446 | gtk_tree_view_column_set_visible (type_list_col, FALSE); |
487 | 447 | ||
488 | if (g_list_length (TypeList) > 1) | 448 | if (g_list_length (TypeList) > 1) |
489 | gtk_tree_view_column_set_visible (type_list_col, TRUE); | 449 | gtk_tree_view_column_set_visible (type_list_col, TRUE); |
490 | else | 450 | else |
491 | gtk_tree_view_column_set_visible (type_list_col, FALSE); | 451 | gtk_tree_view_column_set_visible (type_list_col, FALSE); |
492 | 452 | ||
493 | gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE | 453 | gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE |
494 | (filelist_store), FILENAME_COL, | 454 | (filelist_store), FILENAME_COL, |
495 | GTK_SORT_ASCENDING); | 455 | GTK_SORT_ASCENDING); |
496 | } | 456 | } |
497 | 457 | ||
498 | gboolean | 458 | gboolean |
499 | insertfiles () | 459 | insertfiles () |
500 | { | 460 | { |
501 | struct ECRS_MetaData *dirmetadata; | 461 | struct ECRS_MetaData *dirmetadata; |
502 | struct ECRS_MetaData *tempmetadata; | 462 | struct ECRS_MetaData *tempmetadata; |
503 | GArray *filesmetadatas, *files; | 463 | GArray *filesmetadatas, *files; |
504 | gchar *temptext; | 464 | gchar *temptext; |
505 | gchar **dirkeywords; | 465 | gchar **dirkeywords; |
506 | gchararray *tempkeywords; | 466 | gchararray *tempkeywords; |
507 | gchar **tempmetas, *dirmetas[8]; | 467 | gchar **tempmetas, *dirmetas[8]; |
508 | gchar *separator = ";"; | 468 | gchar *separator = ";"; |
509 | int i, n; | 469 | int i, n; |
510 | guint useforallflags; | 470 | guint useforallflags; |
511 | GtkWidget *keywordsentry; | 471 | GtkWidget *keywordsentry; |
512 | GtkTreeIter fileiter; | 472 | GtkTreeIter fileiter; |
513 | GtkToggleButton *artisttogglebutton; | 473 | GtkToggleButton *artisttogglebutton; |
514 | GtkToggleButton *albumtogglebutton; | 474 | GtkToggleButton *albumtogglebutton; |
515 | GtkToggleButton *keywordstogglebutton; | 475 | GtkToggleButton *keywordstogglebutton; |
516 | GtkToggleButton *commentstogglebutton; | 476 | GtkToggleButton *commentstogglebutton; |
517 | 477 | ||
518 | /* Test if files are present */ | 478 | /* Test if files are present */ |
519 | if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (filelist_store), | 479 | if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (filelist_store), |
520 | &fileiter)) | 480 | &fileiter)) |
521 | { | 481 | { |
522 | gchar *error_message = | 482 | gchar *error_message = |
523 | STRDUP (_ | 483 | STRDUP (_ |
524 | ("No files to insert ! Please add files to the list before validating.")); | 484 | ("No files to insert ! Please add files to the list before validating.")); |
525 | GtkWidget *message_dialog = | 485 | GtkWidget *message_dialog = |
526 | gtk_message_dialog_new (GTK_WINDOW | 486 | gtk_message_dialog_new (GTK_WINDOW (musicinsertdialog), |
527 | (musicinsertdialog), | 487 | GTK_DIALOG_DESTROY_WITH_PARENT, |
528 | GTK_DIALOG_DESTROY_WITH_PARENT, | 488 | GTK_MESSAGE_ERROR, |
529 | GTK_MESSAGE_ERROR, | 489 | GTK_BUTTONS_CLOSE, |
530 | GTK_BUTTONS_CLOSE, | 490 | "%s", error_message); |
531 | "%s", error_message); | 491 | gtk_dialog_run (GTK_DIALOG (message_dialog)); |
532 | gtk_dialog_run (GTK_DIALOG (message_dialog)); | 492 | gtk_widget_destroy (message_dialog); |
533 | gtk_widget_destroy (message_dialog); | 493 | FREE (error_message); |
534 | FREE (error_message); | 494 | return FALSE; |
535 | return FALSE; | 495 | } |
536 | } | 496 | |
537 | 497 | ||
538 | 498 | /* Manage album metadatas */ | |
539 | /* Manage album metadatas */ | 499 | |
540 | 500 | dirmetadata = ECRS_createMetaData (); | |
541 | dirmetadata = ECRS_createMetaData (); | 501 | |
542 | 502 | dirmetas[0] = | |
543 | dirmetas[0] = | 503 | gtk_combo_box_get_active_text (GTK_COMBO_BOX (artistcombobox)); |
544 | gtk_combo_box_get_active_text (GTK_COMBO_BOX | 504 | if (dirmetas[0]) |
545 | (artistcombobox)); | 505 | ECRS_addToMetaData (dirmetadata, EXTRACTOR_ARTIST, dirmetas[0]); |
546 | if (dirmetas[0]) | 506 | |
547 | ECRS_addToMetaData (dirmetadata, EXTRACTOR_ARTIST, dirmetas[0]); | 507 | dirmetas[1] = gtk_combo_box_get_active_text (GTK_COMBO_BOX (albumcombobox)); |
548 | 508 | if (dirmetas[1]) | |
549 | dirmetas[1] = | 509 | ECRS_addToMetaData (dirmetadata, EXTRACTOR_ALBUM, dirmetas[1]); |
550 | gtk_combo_box_get_active_text (GTK_COMBO_BOX (albumcombobox)); | 510 | |
551 | if (dirmetas[1]) | 511 | keywordsentry = glade_xml_get_widget (musicinsertXML, "keywordsentry"); |
552 | ECRS_addToMetaData (dirmetadata, EXTRACTOR_ALBUM, dirmetas[1]); | 512 | temptext = (gchar *) gtk_entry_get_text (GTK_ENTRY (keywordsentry)); |
553 | 513 | dirkeywords = NULL; | |
554 | keywordsentry = | 514 | if (temptext) |
555 | glade_xml_get_widget (musicinsertXML, "keywordsentry"); | 515 | dirkeywords = g_strsplit (temptext, separator, 255); |
556 | temptext = (gchar *) gtk_entry_get_text (GTK_ENTRY (keywordsentry)); | 516 | n = 0; |
557 | dirkeywords = NULL; | 517 | while (dirkeywords[n]) |
558 | if (temptext) | 518 | { |
559 | dirkeywords = g_strsplit (temptext, separator, 255); | 519 | ECRS_addToMetaData (dirmetadata, EXTRACTOR_KEYWORDS, dirkeywords[n]); |
560 | n = 0; | 520 | n++; |
561 | while (dirkeywords[n]) | 521 | } |
562 | { | 522 | /* Add a standard keyword to allow finding all available music albums |
563 | ECRS_addToMetaData (dirmetadata, EXTRACTOR_KEYWORDS, dirkeywords[n]); | 523 | * on AFS in one search */ |
564 | n++; | 524 | ECRS_addToMetaData (dirmetadata, EXTRACTOR_KEYWORDS, "music album"); |
565 | } | 525 | |
566 | /* Add a standard keyword to allow finding all available music albums | 526 | |
567 | * on AFS in one search */ | 527 | /* Manage files metadatas */ |
568 | ECRS_addToMetaData (dirmetadata, | 528 | artisttogglebutton = |
569 | EXTRACTOR_KEYWORDS, | 529 | GTK_TOGGLE_BUTTON (glade_xml_get_widget |
570 | "music album"); | 530 | (musicinsertXML, "artisttogglebutton")); |
571 | 531 | albumtogglebutton = | |
572 | 532 | GTK_TOGGLE_BUTTON (glade_xml_get_widget | |
573 | /* Manage files metadatas */ | 533 | (musicinsertXML, "albumtogglebutton")); |
574 | artisttogglebutton = GTK_TOGGLE_BUTTON(glade_xml_get_widget (musicinsertXML, "artisttogglebutton")); | 534 | keywordstogglebutton = |
575 | albumtogglebutton = GTK_TOGGLE_BUTTON(glade_xml_get_widget (musicinsertXML, "albumtogglebutton")); | 535 | GTK_TOGGLE_BUTTON (glade_xml_get_widget |
576 | keywordstogglebutton = GTK_TOGGLE_BUTTON(glade_xml_get_widget (musicinsertXML, "keywordstogglebutton")); | 536 | (musicinsertXML, "keywordstogglebutton")); |
577 | commentstogglebutton = GTK_TOGGLE_BUTTON(glade_xml_get_widget (musicinsertXML, "commentstogglebutton")); | 537 | commentstogglebutton = |
578 | 538 | GTK_TOGGLE_BUTTON (glade_xml_get_widget | |
579 | useforallflags = 0; | 539 | (musicinsertXML, "commentstogglebutton")); |
580 | useforallflags = gtk_toggle_button_get_active (artisttogglebutton) << 0; | 540 | |
581 | useforallflags = gtk_toggle_button_get_active (albumtogglebutton) << 1; | 541 | useforallflags = 0; |
582 | useforallflags = gtk_toggle_button_get_active (keywordstogglebutton) << 2; | 542 | useforallflags = gtk_toggle_button_get_active (artisttogglebutton) << 0; |
583 | useforallflags = gtk_toggle_button_get_active (commentstogglebutton) << 3; | 543 | useforallflags = gtk_toggle_button_get_active (albumtogglebutton) << 1; |
584 | 544 | useforallflags = gtk_toggle_button_get_active (keywordstogglebutton) << 2; | |
585 | filesmetadatas = g_array_sized_new (FALSE, FALSE, sizeof (struct ECRS_MetaData *), 20); | 545 | useforallflags = gtk_toggle_button_get_active (commentstogglebutton) << 3; |
586 | files = g_array_sized_new (FALSE, FALSE, sizeof (gchar *), 20); | 546 | |
587 | i = 0; | 547 | filesmetadatas = |
588 | do | 548 | g_array_sized_new (FALSE, FALSE, sizeof (struct ECRS_MetaData *), 20); |
589 | { | 549 | files = g_array_sized_new (FALSE, FALSE, sizeof (gchar *), 20); |
590 | tempmetadata = ECRS_createMetaData(); | 550 | i = 0; |
591 | tempmetas = malloc (sizeof(gchar *) * 8); | 551 | do |
592 | g_array_append_val (filesmetadatas, tempmetadata); | 552 | { |
593 | gtk_tree_model_get (GTK_TREE_MODEL (filelist_store), | 553 | tempmetadata = ECRS_createMetaData (); |
594 | &fileiter, | 554 | tempmetas = malloc (sizeof (gchar *) * 8); |
595 | REAL_FILENAME_COL, &tempmetas[0], | 555 | g_array_append_val (filesmetadatas, tempmetadata); |
596 | FILENAME_COL, &tempmetas[1], | 556 | gtk_tree_model_get (GTK_TREE_MODEL (filelist_store), |
597 | TITLE_COL, &tempmetas[2], | 557 | &fileiter, |
598 | ARTIST_COL, &tempmetas[3], | 558 | REAL_FILENAME_COL, &tempmetas[0], |
599 | ALBUM_COL, &tempmetas[4], | 559 | FILENAME_COL, &tempmetas[1], |
600 | TYPE_COL, &tempmetas[5], | 560 | TITLE_COL, &tempmetas[2], |
601 | FORMAT_COL, &tempmetas[6], | 561 | ARTIST_COL, &tempmetas[3], |
602 | KEYWORDS_COL, &tempmetas[7], | 562 | ALBUM_COL, &tempmetas[4], |
603 | -1); | 563 | TYPE_COL, &tempmetas[5], |
604 | g_array_append_val (files, tempmetas[0]); | 564 | FORMAT_COL, &tempmetas[6], |
605 | 565 | KEYWORDS_COL, &tempmetas[7], -1); | |
606 | 566 | g_array_append_val (files, tempmetas[0]); | |
607 | if (tempmetas[1]) | 567 | |
608 | ECRS_addToMetaData (tempmetadata, EXTRACTOR_FILENAME, | 568 | |
609 | tempmetas[1]); | 569 | if (tempmetas[1]) |
610 | if ((useforallflags & 0x1) && dirmetas[0]) | 570 | ECRS_addToMetaData (tempmetadata, EXTRACTOR_FILENAME, tempmetas[1]); |
611 | ECRS_addToMetaData (tempmetadata, EXTRACTOR_FILENAME, | 571 | if ((useforallflags & 0x1) && dirmetas[0]) |
612 | dirmetas[0]); | 572 | ECRS_addToMetaData (tempmetadata, EXTRACTOR_FILENAME, dirmetas[0]); |
613 | else if (!(useforallflags & 0x1) && tempmetas[2]) | 573 | else if (!(useforallflags & 0x1) && tempmetas[2]) |
614 | ECRS_addToMetaData (tempmetadata, EXTRACTOR_TITLE, | 574 | ECRS_addToMetaData (tempmetadata, EXTRACTOR_TITLE, tempmetas[2]); |
615 | tempmetas[2]); | 575 | if ((useforallflags & 0x2) && dirmetas[1]) |
616 | if ((useforallflags & 0x2) && dirmetas[1]) | 576 | ECRS_addToMetaData (tempmetadata, EXTRACTOR_ARTIST, dirmetas[1]); |
617 | ECRS_addToMetaData (tempmetadata, EXTRACTOR_ARTIST, | 577 | else if (!(useforallflags & 0x2) && tempmetas[3]) |
618 | dirmetas[1]); | 578 | ECRS_addToMetaData (tempmetadata, EXTRACTOR_FILENAME, tempmetas[3]); |
619 | else if (!(useforallflags & 0x2)&& tempmetas[3]) | 579 | if (tempmetas[4]) |
620 | ECRS_addToMetaData (tempmetadata, EXTRACTOR_FILENAME, | 580 | ECRS_addToMetaData (tempmetadata, EXTRACTOR_ALBUM, tempmetas[4]); |
621 | tempmetas[3]); | 581 | if (tempmetas[5]) |
622 | if (tempmetas[4]) | 582 | ECRS_addToMetaData (tempmetadata, EXTRACTOR_MIMETYPE, tempmetas[5]); |
623 | ECRS_addToMetaData (tempmetadata, EXTRACTOR_ALBUM, | 583 | if (tempmetas[6]) |
624 | tempmetas[4]); | 584 | ECRS_addToMetaData (tempmetadata, EXTRACTOR_FORMAT, tempmetas[6]); |
625 | if (tempmetas[5]) | 585 | |
626 | ECRS_addToMetaData (tempmetadata, EXTRACTOR_MIMETYPE, | 586 | if (!(useforallflags & 0x1)) |
627 | tempmetas[5]); | 587 | { |
628 | if (tempmetas[6]) | 588 | n = 0; |
629 | ECRS_addToMetaData (tempmetadata, EXTRACTOR_FORMAT, | 589 | while (dirkeywords[n]) |
630 | tempmetas[6]); | 590 | { |
631 | 591 | ECRS_addToMetaData (tempmetadata, EXTRACTOR_KEYWORDS, | |
632 | if (!(useforallflags & 0x1)) | 592 | dirkeywords[n]); |
633 | { | 593 | n++; |
634 | n = 0; | 594 | } |
635 | while (dirkeywords[n]) | 595 | } |
636 | { | 596 | else if (tempmetas[7]) |
637 | ECRS_addToMetaData (tempmetadata, EXTRACTOR_KEYWORDS, dirkeywords[n]); | 597 | { |
638 | n++; | 598 | tempkeywords = g_strsplit (temptext, separator, 255); |
639 | } | 599 | n = 0; |
640 | } | 600 | while (tempkeywords[n]) |
641 | else if (tempmetas[7]) | 601 | { |
642 | { | 602 | ECRS_addToMetaData (tempmetadata, |
643 | tempkeywords = g_strsplit (temptext, separator, 255); | 603 | EXTRACTOR_KEYWORDS, tempkeywords[n]); |
644 | n = 0; | 604 | n++; |
645 | while (tempkeywords[n]) | 605 | } |
646 | { | 606 | g_strfreev (tempkeywords); |
647 | ECRS_addToMetaData (tempmetadata, | 607 | /* Add a standard keyword to allow finding all available music files |
648 | EXTRACTOR_KEYWORDS, | 608 | * on AFS in one search */ |
649 | tempkeywords[n]); | 609 | ECRS_addToMetaData (tempmetadata, EXTRACTOR_KEYWORDS, "music"); |
650 | n++; | 610 | } |
651 | } | 611 | |
652 | g_strfreev (tempkeywords); | 612 | FREE (tempmetas); |
653 | /* Add a standard keyword to allow finding all available music files | 613 | i++; |
654 | * on AFS in one search */ | 614 | } |
655 | ECRS_addToMetaData (tempmetadata, | 615 | while (gtk_tree_model_iter_next |
656 | EXTRACTOR_KEYWORDS, | 616 | (GTK_TREE_MODEL (filelist_store), &fileiter)); |
657 | "music"); | 617 | |
658 | } | 618 | g_strfreev (dirkeywords); |
659 | 619 | ||
660 | FREE (tempmetas); | 620 | /* TODO : take care of the 'Insert as an album'/'Insert files separately' options |
661 | i++; | 621 | * and create or not a gnunet directory containing the files |
662 | } | 622 | * |
663 | while (gtk_tree_model_iter_next (GTK_TREE_MODEL(filelist_store), &fileiter)); | 623 | * TODO : Create a file and album description from metadatas - an idea : |
664 | 624 | * Artist: Song (Album) - Type and Format # for files | |
665 | g_strfreev (dirkeywords); | 625 | * Artist: Album - Type and number of the files # or album |
666 | 626 | * | |
667 | /* TODO : take care of the 'Insert as an album'/'Insert files separately' options | 627 | * TODO : really call FSUI_upload() to insert these files */ |
668 | * and create or not a gnunet directory containing the files | 628 | |
669 | * | 629 | return TRUE; |
670 | * TODO : Create a file and album description from metadatas - an idea : | ||
671 | * Artist: Song (Album) - Type and Format # for files | ||
672 | * Artist: Album - Type and number of the files # or album | ||
673 | * | ||
674 | * TODO : really call FSUI_upload() to insert these files */ | ||
675 | |||
676 | return TRUE; | ||
677 | } | 630 | } |
678 | 631 | ||
679 | /* Callback functions */ | 632 | /* Callback functions */ |
@@ -684,9 +637,9 @@ insertfiles () | |||
684 | void | 637 | void |
685 | on_musicinsertdialog_destroy (GtkObject * object, gpointer user_data) | 638 | on_musicinsertdialog_destroy (GtkObject * object, gpointer user_data) |
686 | { | 639 | { |
687 | EXTRACTOR_removeAll (Extractors); | 640 | EXTRACTOR_removeAll (Extractors); |
688 | UNREF (musicinsertXML); | 641 | UNREF (musicinsertXML); |
689 | musicinsertXML = NULL; | 642 | musicinsertXML = NULL; |
690 | } | 643 | } |
691 | 644 | ||
692 | /** | 645 | /** |
@@ -695,8 +648,8 @@ on_musicinsertdialog_destroy (GtkObject * object, gpointer user_data) | |||
695 | void | 648 | void |
696 | on_cancelbutton_clicked (GtkButton * button, gpointer user_data) | 649 | on_cancelbutton_clicked (GtkButton * button, gpointer user_data) |
697 | { | 650 | { |
698 | gtk_widget_destroy (musicinsertdialog); | 651 | gtk_widget_destroy (musicinsertdialog); |
699 | return; | 652 | return; |
700 | } | 653 | } |
701 | 654 | ||
702 | /** | 655 | /** |
@@ -705,9 +658,9 @@ on_cancelbutton_clicked (GtkButton * button, gpointer user_data) | |||
705 | void | 658 | void |
706 | on_okbutton_clicked (GtkButton * button, gpointer user_data) | 659 | on_okbutton_clicked (GtkButton * button, gpointer user_data) |
707 | { | 660 | { |
708 | if (insertfiles ()) | 661 | if (insertfiles ()) |
709 | gtk_widget_destroy (musicinsertdialog); | 662 | gtk_widget_destroy (musicinsertdialog); |
710 | return ; | 663 | return; |
711 | } | 664 | } |
712 | 665 | ||
713 | /** | 666 | /** |
@@ -716,112 +669,98 @@ on_okbutton_clicked (GtkButton * button, gpointer user_data) | |||
716 | void | 669 | void |
717 | on_diraddbutton_clicked (GtkButton * button, gpointer user_data) | 670 | on_diraddbutton_clicked (GtkButton * button, gpointer user_data) |
718 | { | 671 | { |
719 | gchar *path; | 672 | gchar *path; |
720 | GtkWidget *musicinsertdialog = | 673 | GtkWidget *musicinsertdialog = |
721 | glade_xml_get_widget (musicinsertXML, "musicinsertdialog"); | 674 | glade_xml_get_widget (musicinsertXML, "musicinsertdialog"); |
722 | /* choose the directory to list */ | 675 | /* choose the directory to list */ |
723 | GtkWidget *filechooser = | 676 | GtkWidget *filechooser = |
724 | gtk_file_chooser_dialog_new (_ | 677 | gtk_file_chooser_dialog_new (_("Choose the directory to insert..."), |
725 | ("Choose the directory to insert..."), | 678 | GTK_WINDOW (musicinsertdialog), |
726 | GTK_WINDOW (musicinsertdialog), | 679 | GTK_FILE_CHOOSER_ACTION_OPEN, |
727 | GTK_FILE_CHOOSER_ACTION_OPEN, | 680 | GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, |
728 | GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, | 681 | GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, |
729 | GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, | 682 | NULL); |
730 | NULL); | 683 | gtk_file_chooser_set_action (GTK_FILE_CHOOSER (filechooser), |
731 | gtk_file_chooser_set_action (GTK_FILE_CHOOSER (filechooser), | 684 | GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER); |
732 | GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER); | 685 | gtk_window_set_modal (GTK_WINDOW (filechooser), TRUE); |
733 | gtk_window_set_modal (GTK_WINDOW (filechooser), TRUE); | 686 | switch (gtk_dialog_run (GTK_DIALOG (filechooser))) |
734 | switch (gtk_dialog_run (GTK_DIALOG (filechooser))) | 687 | { |
735 | { | 688 | case GTK_RESPONSE_ACCEPT: |
736 | case GTK_RESPONSE_ACCEPT: | 689 | /* get the path */ |
737 | /* get the path */ | 690 | path = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filechooser)); |
738 | path = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER | 691 | gtk_widget_destroy (filechooser); |
739 | (filechooser)); | 692 | break; |
740 | gtk_widget_destroy (filechooser); | 693 | default: |
741 | break; | 694 | gtk_widget_destroy (filechooser); |
742 | default: | 695 | return; |
743 | gtk_widget_destroy (filechooser); | 696 | } |
744 | return; | 697 | |
745 | } | 698 | /* list directory and fill the fields */ |
746 | 699 | GDir *directory; | |
747 | /* list directory and fill the fields */ | 700 | GString *long_filename; |
748 | GDir *directory; | 701 | GError *dir_opening_error; |
749 | GString *long_filename; | 702 | GSList *file_error_list = NULL; |
750 | GError *dir_opening_error; | 703 | gchar *filename; |
751 | GSList *file_error_list = NULL; | 704 | if ((directory = g_dir_open (path, 0, &dir_opening_error))) |
752 | gchar *filename; | 705 | { |
753 | if ((directory = g_dir_open (path, 0, &dir_opening_error))) | 706 | while ((filename = (gchar *) g_dir_read_name (directory))) |
754 | { | 707 | { |
755 | while ((filename = (gchar *) g_dir_read_name (directory))) | 708 | long_filename = g_string_new (path); |
756 | { | 709 | g_string_append_c (long_filename, DIR_SEPARATOR); |
757 | long_filename = g_string_new (path); | 710 | g_string_append (long_filename, filename); |
758 | g_string_append_c (long_filename, DIR_SEPARATOR); | 711 | if (!(ACCESS (long_filename->str, F_OK | R_OK))) |
759 | g_string_append (long_filename, filename); | 712 | { |
760 | if (!(ACCESS (long_filename->str, F_OK | R_OK))) | 713 | if (!(g_file_test (long_filename->str, G_FILE_TEST_IS_DIR))) |
761 | { | 714 | set_File_Keywords (long_filename->str); |
762 | if (! | 715 | } |
763 | (g_file_test | 716 | else |
764 | (long_filename->str, | 717 | { |
765 | G_FILE_TEST_IS_DIR))) | 718 | file_error_list = g_slist_append (file_error_list, filename); |
766 | set_File_Keywords (long_filename-> | 719 | g_string_free (long_filename, TRUE); |
767 | str); | 720 | } |
768 | } | 721 | } |
769 | else | 722 | |
770 | { | 723 | g_free (path); |
771 | file_error_list = | 724 | activateComboBoxes (); |
772 | g_slist_append (file_error_list, | 725 | updateColumns (); |
773 | filename); | 726 | if (g_slist_length (file_error_list) > 0) |
774 | g_string_free (long_filename, TRUE); | 727 | { |
775 | } | 728 | GString *file_error_message = |
776 | } | 729 | g_string_new (_ |
777 | 730 | ("The following files won't be added for I could not read them :")); | |
778 | g_free (path); | 731 | while ((file_error_list = g_slist_next (file_error_list))) |
779 | activateComboBoxes (); | 732 | { |
780 | updateColumns (); | 733 | g_string_append_c (file_error_message, '\n'); |
781 | if (g_slist_length (file_error_list) > 0) | 734 | g_string_append (file_error_message, |
782 | { | 735 | (gchar *) file_error_list->data); |
783 | GString *file_error_message = | 736 | } |
784 | g_string_new (_ | 737 | GtkWidget *file_error_dialog = |
785 | ("The following files won't be added for I could not read them :")); | 738 | gtk_message_dialog_new (GTK_WINDOW (musicinsertdialog), |
786 | while ((file_error_list = | 739 | GTK_DIALOG_DESTROY_WITH_PARENT, |
787 | g_slist_next (file_error_list))) | 740 | GTK_MESSAGE_ERROR, |
788 | { | 741 | GTK_BUTTONS_CLOSE, |
789 | g_string_append_c (file_error_message, '\n'); | 742 | file_error_message->str); |
790 | g_string_append (file_error_message, | 743 | gtk_dialog_run (GTK_DIALOG (file_error_dialog)); |
791 | (gchar *) file_error_list-> | 744 | gtk_widget_destroy (file_error_dialog); |
792 | data); | 745 | g_string_free (file_error_message, TRUE); |
793 | } | 746 | } |
794 | GtkWidget *file_error_dialog = | 747 | g_dir_close (directory); |
795 | gtk_message_dialog_new (GTK_WINDOW | 748 | } |
796 | (musicinsertdialog), | 749 | else |
797 | GTK_DIALOG_DESTROY_WITH_PARENT, | 750 | { |
798 | GTK_MESSAGE_ERROR, | 751 | gchar *error_message = STRDUP (_("Could not open the directory :\n")); |
799 | GTK_BUTTONS_CLOSE, | 752 | GtkWidget *message_dialog = |
800 | file_error_message-> | 753 | gtk_message_dialog_new (GTK_WINDOW (musicinsertdialog), |
801 | str); | 754 | GTK_DIALOG_DESTROY_WITH_PARENT, |
802 | gtk_dialog_run (GTK_DIALOG (file_error_dialog)); | 755 | GTK_MESSAGE_ERROR, |
803 | gtk_widget_destroy (file_error_dialog); | 756 | GTK_BUTTONS_CLOSE, |
804 | g_string_free (file_error_message, TRUE); | 757 | "%s%s", error_message, |
805 | } | 758 | dir_opening_error->message); |
806 | g_dir_close (directory); | 759 | gtk_dialog_run (GTK_DIALOG (message_dialog)); |
807 | } | 760 | gtk_widget_destroy (message_dialog); |
808 | else | 761 | g_free (error_message); |
809 | { | 762 | g_error_free (dir_opening_error); |
810 | gchar *error_message = | 763 | } |
811 | STRDUP (_("Could not open the directory :\n")); | ||
812 | GtkWidget *message_dialog = | ||
813 | gtk_message_dialog_new (GTK_WINDOW | ||
814 | (musicinsertdialog), | ||
815 | GTK_DIALOG_DESTROY_WITH_PARENT, | ||
816 | GTK_MESSAGE_ERROR, | ||
817 | GTK_BUTTONS_CLOSE, | ||
818 | "%s%s", error_message, | ||
819 | dir_opening_error->message); | ||
820 | gtk_dialog_run (GTK_DIALOG (message_dialog)); | ||
821 | gtk_widget_destroy (message_dialog); | ||
822 | g_free (error_message); | ||
823 | g_error_free (dir_opening_error); | ||
824 | } | ||
825 | } | 764 | } |
826 | 765 | ||
827 | /** | 766 | /** |
@@ -830,82 +769,75 @@ NULL); | |||
830 | void | 769 | void |
831 | on_fileaddbutton_clicked (GtkButton * button, gpointer user_data) | 770 | on_fileaddbutton_clicked (GtkButton * button, gpointer user_data) |
832 | { | 771 | { |
833 | GSList *pathlist; | 772 | GSList *pathlist; |
834 | GtkWidget *musicinsertdialog = | 773 | GtkWidget *musicinsertdialog = |
835 | glade_xml_get_widget (musicinsertXML, "musicinsertdialog"); | 774 | glade_xml_get_widget (musicinsertXML, "musicinsertdialog"); |
836 | /* choose the file to add */ | 775 | /* choose the file to add */ |
837 | GtkWidget *filechooser = | 776 | GtkWidget *filechooser = |
838 | gtk_file_chooser_dialog_new (_("Choose files to insert..."), | 777 | gtk_file_chooser_dialog_new (_("Choose files to insert..."), |
839 | GTK_WINDOW (musicinsertdialog), | 778 | GTK_WINDOW (musicinsertdialog), |
840 | GTK_FILE_CHOOSER_ACTION_OPEN, | 779 | GTK_FILE_CHOOSER_ACTION_OPEN, |
841 | GTK_STOCK_CANCEL, | 780 | GTK_STOCK_CANCEL, |
842 | GTK_RESPONSE_CANCEL, | 781 | GTK_RESPONSE_CANCEL, |
843 | GTK_STOCK_OPEN, | 782 | GTK_STOCK_OPEN, |
844 | GTK_RESPONSE_ACCEPT, NULL); | 783 | GTK_RESPONSE_ACCEPT, NULL); |
845 | gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (filechooser), | 784 | gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (filechooser), TRUE); |
846 | TRUE); | 785 | gtk_window_set_modal (GTK_WINDOW (filechooser), TRUE); |
847 | gtk_window_set_modal (GTK_WINDOW (filechooser), TRUE); | 786 | |
848 | 787 | if (gtk_dialog_run (GTK_DIALOG (filechooser)) == GTK_RESPONSE_ACCEPT) | |
849 | if (gtk_dialog_run (GTK_DIALOG (filechooser)) == GTK_RESPONSE_ACCEPT) | 788 | { |
850 | { | 789 | GSList *file_error_list = NULL; |
851 | GSList *file_error_list = NULL; | 790 | /* get the path */ |
852 | /* get the path */ | 791 | pathlist = |
853 | pathlist = | 792 | gtk_file_chooser_get_filenames (GTK_FILE_CHOOSER (filechooser)); |
854 | gtk_file_chooser_get_filenames (GTK_FILE_CHOOSER | 793 | gtk_widget_destroy (filechooser); |
855 | (filechooser)); | 794 | do |
856 | gtk_widget_destroy (filechooser); | 795 | { |
857 | do | 796 | if (!(ACCESS (pathlist->data, F_OK | R_OK))) |
858 | { | 797 | { |
859 | if (!(ACCESS (pathlist->data, F_OK | R_OK))) | 798 | set_File_Keywords (pathlist->data); |
860 | { | 799 | } |
861 | set_File_Keywords (pathlist->data); | 800 | else |
862 | } | 801 | { |
863 | else | 802 | file_error_list = |
864 | { | 803 | g_slist_append (file_error_list, pathlist->data); |
865 | file_error_list = | 804 | } |
866 | g_slist_append (file_error_list, | 805 | } |
867 | pathlist->data); | 806 | while ((pathlist = g_slist_next (pathlist))); |
868 | } | 807 | g_slist_free (pathlist); |
869 | } | 808 | |
870 | while ((pathlist = g_slist_next (pathlist))); | 809 | activateComboBoxes (); |
871 | g_slist_free (pathlist); | 810 | updateColumns (); |
872 | 811 | ||
873 | activateComboBoxes (); | 812 | if (g_slist_length (file_error_list) > 0) |
874 | updateColumns (); | 813 | { |
875 | 814 | GString *file_error_message = | |
876 | if (g_slist_length (file_error_list) > 0) | 815 | g_string_new (_ |
877 | { | 816 | ("The following files won't be added for I could not read them :")); |
878 | GString *file_error_message = | 817 | while ((file_error_list = g_slist_next (file_error_list))) |
879 | g_string_new (_ | 818 | { |
880 | ("The following files won't be added for I could not read them :")); | 819 | g_string_append_c (file_error_message, '\n'); |
881 | while ((file_error_list = | 820 | g_string_append (file_error_message, |
882 | g_slist_next (file_error_list))) | 821 | (gchar *) file_error_list->data); |
883 | { | 822 | } |
884 | g_string_append_c (file_error_message, '\n'); | 823 | |
885 | g_string_append (file_error_message, | 824 | GtkWidget *file_error_dialog = |
886 | (gchar *) file_error_list-> | 825 | gtk_message_dialog_new (GTK_WINDOW (musicinsertdialog), |
887 | data); | 826 | GTK_DIALOG_DESTROY_WITH_PARENT, |
888 | } | 827 | GTK_MESSAGE_ERROR, |
889 | 828 | GTK_BUTTONS_CLOSE, | |
890 | GtkWidget *file_error_dialog = | 829 | file_error_message->str); |
891 | gtk_message_dialog_new (GTK_WINDOW | 830 | gtk_dialog_run (GTK_DIALOG (file_error_dialog)); |
892 | (musicinsertdialog), | 831 | g_string_free (file_error_message, TRUE); |
893 | GTK_DIALOG_DESTROY_WITH_PARENT, | 832 | gtk_widget_destroy (file_error_dialog); |
894 | GTK_MESSAGE_ERROR, | 833 | } |
895 | GTK_BUTTONS_CLOSE, | 834 | return; |
896 | file_error_message-> | 835 | } |
897 | str); | 836 | else |
898 | gtk_dialog_run (GTK_DIALOG (file_error_dialog)); | 837 | { |
899 | g_string_free (file_error_message, TRUE); | 838 | gtk_widget_destroy (filechooser); |
900 | gtk_widget_destroy (file_error_dialog); | 839 | return; |
901 | } | 840 | } |
902 | return; | ||
903 | } | ||
904 | else | ||
905 | { | ||
906 | gtk_widget_destroy (filechooser); | ||
907 | return; | ||
908 | } | ||
909 | } | 841 | } |
910 | 842 | ||
911 | /** | 843 | /** |
@@ -914,10 +846,9 @@ on_fileaddbutton_clicked (GtkButton * button, gpointer user_data) | |||
914 | void | 846 | void |
915 | on_radioinsert_toggled (GtkRadioButton * radiobutton, gpointer user_data) | 847 | on_radioinsert_toggled (GtkRadioButton * radiobutton, gpointer user_data) |
916 | { | 848 | { |
917 | gtk_widget_set_sensitive (GTK_WIDGET | 849 | gtk_widget_set_sensitive (GTK_WIDGET |
918 | (glade_xml_get_widget | 850 | (glade_xml_get_widget |
919 | (musicinsertXML, "copyfilesbutton")), | 851 | (musicinsertXML, "copyfilesbutton")), FALSE); |
920 | FALSE); | ||
921 | } | 852 | } |
922 | 853 | ||
923 | /** | 854 | /** |
@@ -926,75 +857,73 @@ on_radioinsert_toggled (GtkRadioButton * radiobutton, gpointer user_data) | |||
926 | void | 857 | void |
927 | on_radioindex_toggled (GtkRadioButton * radiobutton, gpointer user_data) | 858 | on_radioindex_toggled (GtkRadioButton * radiobutton, gpointer user_data) |
928 | { | 859 | { |
929 | gtk_widget_set_sensitive | 860 | gtk_widget_set_sensitive |
930 | (GTK_WIDGET | 861 | (GTK_WIDGET |
931 | (glade_xml_get_widget (musicinsertXML, "copyfilesbutton")), | 862 | (glade_xml_get_widget (musicinsertXML, "copyfilesbutton")), TRUE); |
932 | TRUE); | ||
933 | } | 863 | } |
934 | 864 | ||
935 | /** | 865 | /** |
936 | * @brief Hide or show the album column when needed | 866 | * @brief Hide or show the album column when needed |
937 | */ | 867 | */ |
938 | void on_albumtogglebutton_toggled | 868 | void on_albumtogglebutton_toggled |
939 | (GtkToggleButton * togglebutton, gpointer user_data) | 869 | (GtkToggleButton * togglebutton, gpointer user_data) |
940 | { | 870 | { |
941 | if (gtk_toggle_button_get_active (togglebutton)) | 871 | if (gtk_toggle_button_get_active (togglebutton)) |
942 | gtk_tree_view_column_set_visible (album_list_col, FALSE); | 872 | gtk_tree_view_column_set_visible (album_list_col, FALSE); |
943 | else | 873 | else |
944 | gtk_tree_view_column_set_visible (album_list_col, TRUE); | 874 | gtk_tree_view_column_set_visible (album_list_col, TRUE); |
945 | } | 875 | } |
946 | 876 | ||
947 | /** | 877 | /** |
948 | * @brief Hide or show the artist column when needed | 878 | * @brief Hide or show the artist column when needed |
949 | */ | 879 | */ |
950 | void on_artisttogglebutton_toggled | 880 | void on_artisttogglebutton_toggled |
951 | (GtkToggleButton * togglebutton, gpointer user_data) | 881 | (GtkToggleButton * togglebutton, gpointer user_data) |
952 | { | 882 | { |
953 | if (gtk_toggle_button_get_active (togglebutton)) | 883 | if (gtk_toggle_button_get_active (togglebutton)) |
954 | gtk_tree_view_column_set_visible (artist_list_col, FALSE); | 884 | gtk_tree_view_column_set_visible (artist_list_col, FALSE); |
955 | else | 885 | else |
956 | gtk_tree_view_column_set_visible (artist_list_col, TRUE); | 886 | gtk_tree_view_column_set_visible (artist_list_col, TRUE); |
957 | } | 887 | } |
958 | 888 | ||
959 | /** | 889 | /** |
960 | * @brief Hide or show the keywords column when needed | 890 | * @brief Hide or show the keywords column when needed |
961 | */ | 891 | */ |
962 | void on_keywordstogglebutton_toggled | 892 | void on_keywordstogglebutton_toggled |
963 | (GtkToggleButton * togglebutton, gpointer user_data) | 893 | (GtkToggleButton * togglebutton, gpointer user_data) |
964 | { | 894 | { |
965 | if (gtk_toggle_button_get_active (togglebutton)) | 895 | if (gtk_toggle_button_get_active (togglebutton)) |
966 | gtk_tree_view_column_set_visible (keywords_list_col, FALSE); | 896 | gtk_tree_view_column_set_visible (keywords_list_col, FALSE); |
967 | else | 897 | else |
968 | gtk_tree_view_column_set_visible (keywords_list_col, TRUE); | 898 | gtk_tree_view_column_set_visible (keywords_list_col, TRUE); |
969 | } | 899 | } |
970 | 900 | ||
971 | /** | 901 | /** |
972 | * @brief Make to user able to modify the per-file data | 902 | * @brief Make to user able to modify the per-file data |
973 | */ | 903 | */ |
974 | void on_renderer_edited | 904 | void on_renderer_edited |
975 | (GtkCellRendererText * | 905 | (GtkCellRendererText * |
976 | cellrenderertext, | 906 | cellrenderertext, |
977 | gchar * path_string, gchar * new_text, gpointer user_data) | 907 | gchar * path_string, gchar * new_text, gpointer user_data) |
978 | { | 908 | { |
979 | GtkTreePath *path = gtk_tree_path_new_from_string (path_string); | 909 | GtkTreePath *path = gtk_tree_path_new_from_string (path_string); |
980 | GtkTreeIter iter; | 910 | GtkTreeIter iter; |
981 | gtk_tree_model_get_iter (GTK_TREE_MODEL (filelist_store), &iter, | 911 | gtk_tree_model_get_iter (GTK_TREE_MODEL (filelist_store), &iter, path); |
982 | path); | 912 | gtk_list_store_set (filelist_store, &iter, |
983 | gtk_list_store_set (filelist_store, &iter, | 913 | (gint) * ((gint *) user_data), new_text, -1); |
984 | (gint) * ((gint *) user_data), new_text, -1); | 914 | gtk_tree_path_free (path); |
985 | gtk_tree_path_free (path); | ||
986 | } | 915 | } |
987 | 916 | ||
988 | gboolean | 917 | gboolean |
989 | popup_delete (GtkWidget * widget, GdkEventButton * event, gpointer user_data) | 918 | popup_delete (GtkWidget * widget, GdkEventButton * event, gpointer user_data) |
990 | { | 919 | { |
991 | if ((event->type == GDK_BUTTON_PRESS) && (event->button == 3)) | 920 | if ((event->type == GDK_BUTTON_PRESS) && (event->button == 3)) |
992 | { | 921 | { |
993 | gtk_menu_popup (GTK_MENU (filelist_popup), NULL, NULL, NULL, | 922 | gtk_menu_popup (GTK_MENU (filelist_popup), NULL, NULL, NULL, |
994 | NULL, event->button, event->time); | 923 | NULL, event->button, event->time); |
995 | return TRUE; | 924 | return TRUE; |
996 | } | 925 | } |
997 | return FALSE; | 926 | return FALSE; |
998 | } | 927 | } |
999 | 928 | ||
1000 | /** | 929 | /** |
@@ -1003,43 +932,40 @@ popup_delete (GtkWidget * widget, GdkEventButton * event, gpointer user_data) | |||
1003 | void | 932 | void |
1004 | remove_file_from_list (gpointer user_data) | 933 | remove_file_from_list (gpointer user_data) |
1005 | { | 934 | { |
1006 | GtkTreeIter iter; | 935 | GtkTreeIter iter; |
1007 | GtkWidget *filelist = | 936 | GtkWidget *filelist = glade_xml_get_widget (musicinsertXML, "filelist"); |
1008 | glade_xml_get_widget (musicinsertXML, "filelist"); | 937 | GtkTreeSelection *selection = |
1009 | GtkTreeSelection *selection = | 938 | gtk_tree_view_get_selection (GTK_TREE_VIEW (filelist)); |
1010 | gtk_tree_view_get_selection (GTK_TREE_VIEW (filelist)); | 939 | GList *selected_paths = gtk_tree_selection_get_selected_rows (selection, |
1011 | GList *selected_paths = | 940 | (GtkTreeModel |
1012 | gtk_tree_selection_get_selected_rows (selection, | 941 | **) & |
1013 | (GtkTreeModel **) | 942 | filelist_store); |
1014 | &filelist_store); | 943 | GList *selected_refs = NULL; |
1015 | GList *selected_refs = NULL; | 944 | GtkTreePath *path; |
1016 | GtkTreePath *path; | ||
1017 | /* Get static references from paths */ | 945 | /* Get static references from paths */ |
1018 | while (selected_paths) | 946 | while (selected_paths) |
1019 | { | 947 | { |
1020 | selected_refs = g_list_append (selected_refs, | 948 | selected_refs = g_list_append (selected_refs, |
1021 | gtk_tree_row_reference_new | 949 | gtk_tree_row_reference_new |
1022 | (GTK_TREE_MODEL | 950 | (GTK_TREE_MODEL |
1023 | (filelist_store), | 951 | (filelist_store), |
1024 | selected_paths->data)); | 952 | selected_paths->data)); |
1025 | selected_paths = g_list_next (selected_paths); | 953 | selected_paths = g_list_next (selected_paths); |
1026 | } | 954 | } |
1027 | g_list_foreach (selected_paths, (GFunc) gtk_tree_path_free, NULL); | 955 | g_list_foreach (selected_paths, (GFunc) gtk_tree_path_free, NULL); |
1028 | g_list_free (selected_paths); | 956 | g_list_free (selected_paths); |
1029 | 957 | ||
1030 | /* Remove items from references */ | 958 | /* Remove items from references */ |
1031 | while (selected_refs) | 959 | while (selected_refs) |
1032 | { | 960 | { |
1033 | path = gtk_tree_row_reference_get_path (selected_refs->data); | 961 | path = gtk_tree_row_reference_get_path (selected_refs->data); |
1034 | gtk_tree_model_get_iter (GTK_TREE_MODEL (filelist_store), | 962 | gtk_tree_model_get_iter (GTK_TREE_MODEL (filelist_store), &iter, path); |
1035 | &iter, path); | 963 | gtk_list_store_remove (filelist_store, &iter); |
1036 | gtk_list_store_remove (filelist_store, &iter); | 964 | gtk_tree_path_free (path); |
1037 | gtk_tree_path_free (path); | 965 | selected_refs = g_list_next (selected_refs); |
1038 | selected_refs = g_list_next (selected_refs); | 966 | } |
1039 | } | 967 | g_list_foreach (selected_paths, (GFunc) gtk_tree_row_reference_free, NULL); |
1040 | g_list_foreach (selected_paths, (GFunc) gtk_tree_row_reference_free, | 968 | g_list_free (selected_paths); |
1041 | NULL); | ||
1042 | g_list_free (selected_paths); | ||
1043 | } | 969 | } |
1044 | 970 | ||
1045 | /** | 971 | /** |
@@ -1048,9 +974,8 @@ remove_file_from_list (gpointer user_data) | |||
1048 | void | 974 | void |
1049 | select_all_files (gpointer user_data) | 975 | select_all_files (gpointer user_data) |
1050 | { | 976 | { |
1051 | GtkWidget *filelist = | 977 | GtkWidget *filelist = glade_xml_get_widget (musicinsertXML, "filelist"); |
1052 | glade_xml_get_widget (musicinsertXML, "filelist"); | 978 | GtkTreeSelection *selection = |
1053 | GtkTreeSelection *selection = | 979 | gtk_tree_view_get_selection (GTK_TREE_VIEW (filelist)); |
1054 | gtk_tree_view_get_selection (GTK_TREE_VIEW (filelist)); | 980 | gtk_tree_selection_select_all (selection); |
1055 | gtk_tree_selection_select_all (selection); | ||
1056 | } | 981 | } |
diff --git a/src/plugins/fs/extensions/musicinsert.h b/src/plugins/fs/extensions/musicinsert.h index fcfb07c1..40d6ef55 100644 --- a/src/plugins/fs/extensions/musicinsert.h +++ b/src/plugins/fs/extensions/musicinsert.h | |||
@@ -76,7 +76,7 @@ const gint keywords_col_num = KEYWORDS_COL; | |||
76 | 76 | ||
77 | 77 | ||
78 | EXTRACTOR_KeywordList *get_EXTRACTORKeywords (const EXTRACTOR_ExtractorList * | 78 | EXTRACTOR_KeywordList *get_EXTRACTORKeywords (const EXTRACTOR_ExtractorList * |
79 | exList, const gchar * filename); | 79 | exList, const gchar * filename); |
80 | void set_File_Keywords (const gchar * filename); | 80 | void set_File_Keywords (const gchar * filename); |
81 | void activateComboBoxes (); | 81 | void activateComboBoxes (); |
82 | void updateColumns (); | 82 | void updateColumns (); |
@@ -101,26 +101,26 @@ void on_radioindex_toggled (GtkRadioButton * radiobutton, gpointer user_data); | |||
101 | 101 | ||
102 | void | 102 | void |
103 | on_albumtogglebutton_toggled (GtkToggleButton * togglebutton, | 103 | on_albumtogglebutton_toggled (GtkToggleButton * togglebutton, |
104 | gpointer user_data); | 104 | gpointer user_data); |
105 | 105 | ||
106 | void | 106 | void |
107 | on_artisttogglebutton_toggled (GtkToggleButton * togglebutton, | 107 | on_artisttogglebutton_toggled (GtkToggleButton * togglebutton, |
108 | gpointer user_data); | 108 | gpointer user_data); |
109 | 109 | ||
110 | void | 110 | void |
111 | on_typetogglebutton_toggled (GtkToggleButton * togglebutton, | 111 | on_typetogglebutton_toggled (GtkToggleButton * togglebutton, |
112 | gpointer user_data); | 112 | gpointer user_data); |
113 | 113 | ||
114 | void | 114 | void |
115 | on_keywordstogglebutton_toggled (GtkToggleButton * togglebutton, | 115 | on_keywordstogglebutton_toggled (GtkToggleButton * togglebutton, |
116 | gpointer user_data); | 116 | gpointer user_data); |
117 | 117 | ||
118 | void | 118 | void |
119 | on_renderer_edited (GtkCellRendererText * cellrenderertext, | 119 | on_renderer_edited (GtkCellRendererText * cellrenderertext, |
120 | gchar * arg1, gchar * arg2, gpointer user_data); | 120 | gchar * arg1, gchar * arg2, gpointer user_data); |
121 | 121 | ||
122 | gboolean popup_delete (GtkWidget * widget, | 122 | gboolean popup_delete (GtkWidget * widget, |
123 | GdkEventButton * event, gpointer user_data); | 123 | GdkEventButton * event, gpointer user_data); |
124 | 124 | ||
125 | void remove_file_from_list (gpointer user_data); | 125 | void remove_file_from_list (gpointer user_data); |
126 | 126 | ||
diff --git a/src/plugins/fs/fs.c b/src/plugins/fs/fs.c index 6661cae5..aae21346 100644 --- a/src/plugins/fs/fs.c +++ b/src/plugins/fs/fs.c | |||
@@ -35,23 +35,23 @@ | |||
35 | #include "collection.h" | 35 | #include "collection.h" |
36 | #include "namespace.h" | 36 | #include "namespace.h" |
37 | 37 | ||
38 | struct FSUI_Context * ctx; | 38 | struct FSUI_Context *ctx; |
39 | 39 | ||
40 | struct GE_Context * ectx; | 40 | struct GE_Context *ectx; |
41 | 41 | ||
42 | struct GC_Configuration * cfg; | 42 | struct GC_Configuration *cfg; |
43 | 43 | ||
44 | SearchList * search_head; | 44 | SearchList *search_head; |
45 | 45 | ||
46 | DownloadList * download_head; | 46 | DownloadList *download_head; |
47 | 47 | ||
48 | UploadList * upload_head; | 48 | UploadList *upload_head; |
49 | 49 | ||
50 | GtkListStore * search_summary; | 50 | GtkListStore *search_summary; |
51 | 51 | ||
52 | GtkTreeStore * download_summary; | 52 | GtkTreeStore *download_summary; |
53 | 53 | ||
54 | GtkTreeStore * upload_summary; | 54 | GtkTreeStore *upload_summary; |
55 | 55 | ||
56 | /** | 56 | /** |
57 | * Last right-click event coordinates in summary. | 57 | * Last right-click event coordinates in summary. |
@@ -64,22 +64,24 @@ static unsigned int last_x; | |||
64 | static unsigned int last_y; | 64 | static unsigned int last_y; |
65 | 65 | ||
66 | 66 | ||
67 | void on_updateIntervalComboEntry_changed_fs(GtkWidget * button, | 67 | void |
68 | GtkWidget * entryBox) { | 68 | on_updateIntervalComboEntry_changed_fs (GtkWidget * button, |
69 | const char * time; | 69 | GtkWidget * entryBox) |
70 | { | ||
71 | const char *time; | ||
70 | TIME_T t; | 72 | TIME_T t; |
71 | GtkEntry * entry; | 73 | GtkEntry *entry; |
72 | 74 | ||
73 | entry = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(entryBox))); | 75 | entry = GTK_ENTRY (gtk_bin_get_child (GTK_BIN (entryBox))); |
74 | time = gtk_entry_get_text(entry); | 76 | time = gtk_entry_get_text (entry); |
75 | if (OK != parseTimeInterval(time, | 77 | if (OK != parseTimeInterval (time, &t)) |
76 | &t)) { | 78 | { |
77 | gtk_widget_set_sensitive(button, | 79 | gtk_widget_set_sensitive (button, FALSE); |
78 | FALSE); | 80 | } |
79 | } else { | 81 | else |
80 | gtk_widget_set_sensitive(button, | 82 | { |
81 | TRUE); | 83 | gtk_widget_set_sensitive (button, TRUE); |
82 | } | 84 | } |
83 | } | 85 | } |
84 | 86 | ||
85 | 87 | ||
@@ -87,305 +89,295 @@ void on_updateIntervalComboEntry_changed_fs(GtkWidget * button, | |||
87 | * The selection of the download summary changed. | 89 | * The selection of the download summary changed. |
88 | * Update button status. | 90 | * Update button status. |
89 | */ | 91 | */ |
90 | void on_anonymity_spin_changed_fs(GtkWidget * w, | 92 | void |
91 | gpointer dummy) { | 93 | on_anonymity_spin_changed_fs (GtkWidget * w, gpointer dummy) |
94 | { | ||
92 | gint val; | 95 | gint val; |
93 | GdkColor color; | 96 | GdkColor color; |
94 | GtkSpinButton * spin; | 97 | GtkSpinButton *spin; |
95 | 98 | ||
96 | spin = GTK_SPIN_BUTTON(w); | 99 | spin = GTK_SPIN_BUTTON (w); |
97 | if (spin == NULL) { | 100 | if (spin == NULL) |
98 | GE_BREAK(NULL, 0); | 101 | { |
99 | return; | 102 | GE_BREAK (NULL, 0); |
100 | } | 103 | return; |
101 | val = gtk_spin_button_get_value_as_int(spin); | 104 | } |
102 | if (val == 0) { | 105 | val = gtk_spin_button_get_value_as_int (spin); |
103 | if ( (TRUE == gdk_color_parse("red", | 106 | if (val == 0) |
104 | &color)) && | 107 | { |
105 | (TRUE == gdk_colormap_alloc_color(gdk_colormap_get_system(), | 108 | if ((TRUE == gdk_color_parse ("red", |
106 | &color, | 109 | &color)) && |
107 | FALSE, | 110 | (TRUE == gdk_colormap_alloc_color (gdk_colormap_get_system (), |
108 | TRUE)) ) | 111 | &color, FALSE, TRUE))) |
109 | gtk_widget_modify_base(w, | 112 | gtk_widget_modify_base (w, GTK_STATE_NORMAL, &color); |
110 | GTK_STATE_NORMAL, | 113 | } |
111 | &color); | 114 | else |
112 | } else | 115 | gtk_widget_modify_base (w, GTK_STATE_NORMAL, NULL); |
113 | gtk_widget_modify_base(w, | ||
114 | GTK_STATE_NORMAL, | ||
115 | NULL); | ||
116 | 116 | ||
117 | 117 | ||
118 | } | 118 | } |
119 | 119 | ||
120 | static void * | 120 | static void * |
121 | saveEventProcessor(void * cls) { | 121 | saveEventProcessor (void *cls) |
122 | const FSUI_Event * event = cls; | 122 | { |
123 | void * ret; | 123 | const FSUI_Event *event = cls; |
124 | void *ret; | ||
124 | 125 | ||
125 | ret = NULL; | 126 | ret = NULL; |
126 | switch (event->type) { | 127 | switch (event->type) |
127 | /* search events */ | 128 | { |
128 | case FSUI_search_started: | 129 | /* search events */ |
129 | ret = fs_search_started(event->data.SearchStarted.sc.pos, | 130 | case FSUI_search_started: |
130 | event->data.SearchStarted.searchURI, | 131 | ret = fs_search_started (event->data.SearchStarted.sc.pos, |
131 | event->data.SearchStarted.anonymityLevel, | 132 | event->data.SearchStarted.searchURI, |
132 | 0, | 133 | event->data.SearchStarted.anonymityLevel, |
133 | NULL, | 134 | 0, NULL, FSUI_ACTIVE); |
134 | FSUI_ACTIVE); | 135 | break; |
135 | break; | 136 | case FSUI_search_result: |
136 | case FSUI_search_result: | 137 | fs_search_result_received (event->data.SearchResult.sc.cctx, |
137 | fs_search_result_received(event->data.SearchResult.sc.cctx, | 138 | &event->data.SearchResult.fi, |
138 | &event->data.SearchResult.fi, | 139 | event->data.SearchResult.searchURI); |
139 | event->data.SearchResult.searchURI); | 140 | break; |
140 | break; | 141 | case FSUI_search_error: |
141 | case FSUI_search_error: | 142 | fs_search_aborted (event->data.SearchError.sc.cctx); |
142 | fs_search_aborted(event->data.SearchError.sc.cctx); | 143 | break; |
143 | break; | 144 | case FSUI_search_aborted: |
144 | case FSUI_search_aborted: | 145 | fs_search_aborted (event->data.SearchAborted.sc.cctx); |
145 | fs_search_aborted(event->data.SearchAborted.sc.cctx); | 146 | break; |
146 | break; | 147 | case FSUI_search_completed: |
147 | case FSUI_search_completed: | 148 | // FIXME... |
148 | // FIXME... | 149 | fs_search_aborted (event->data.SearchCompleted.sc.cctx); |
149 | fs_search_aborted(event->data.SearchCompleted.sc.cctx); | 150 | break; |
150 | break; | 151 | case FSUI_search_suspended: |
151 | case FSUI_search_suspended: | 152 | fs_search_aborted (event->data.SearchSuspended.sc.cctx); |
152 | fs_search_aborted(event->data.SearchSuspended.sc.cctx); | 153 | break; |
153 | break; | 154 | case FSUI_search_resumed: |
154 | case FSUI_search_resumed: | 155 | ret = fs_search_started (event->data.SearchResumed.sc.pos, |
155 | ret = fs_search_started(event->data.SearchResumed.sc.pos, | 156 | event->data.SearchResumed.searchURI, |
156 | event->data.SearchResumed.searchURI, | 157 | event->data.SearchResumed.anonymityLevel, |
157 | event->data.SearchResumed.anonymityLevel, | 158 | event->data.SearchResumed.fisSize, |
158 | event->data.SearchResumed.fisSize, | 159 | event->data.SearchResumed.fis, |
159 | event->data.SearchResumed.fis, | 160 | event->data.SearchResumed.state); |
160 | event->data.SearchResumed.state); | 161 | break; |
161 | break; | 162 | case FSUI_search_stopped: |
162 | case FSUI_search_stopped: | 163 | fs_search_stopped (event->data.SearchStopped.sc.cctx); |
163 | fs_search_stopped(event->data.SearchStopped.sc.cctx); | 164 | break; |
164 | break; | 165 | |
165 | 166 | /* download events */ | |
166 | /* download events */ | 167 | case FSUI_download_aborted: |
167 | case FSUI_download_aborted: | 168 | fs_download_aborted (event->data.DownloadAborted.dc.cctx); |
168 | fs_download_aborted(event->data.DownloadAborted.dc.cctx); | 169 | break; |
169 | break; | 170 | case FSUI_download_error: |
170 | case FSUI_download_error: | 171 | fs_download_aborted (event->data.DownloadError.dc.cctx); |
171 | fs_download_aborted(event->data.DownloadError.dc.cctx); | 172 | break; |
172 | break; | 173 | case FSUI_download_suspended: |
173 | case FSUI_download_suspended: | 174 | fs_download_stopped (event->data.DownloadSuspended.dc.cctx); |
174 | fs_download_stopped(event->data.DownloadSuspended.dc.cctx); | 175 | break; |
175 | break; | 176 | case FSUI_download_progress: |
176 | case FSUI_download_progress: | 177 | fs_download_update (event->data.DownloadProgress.dc.cctx, |
177 | fs_download_update(event->data.DownloadProgress.dc.cctx, | 178 | event->data.DownloadProgress.completed, |
178 | event->data.DownloadProgress.completed, | 179 | event->data.DownloadProgress.last_block, |
179 | event->data.DownloadProgress.last_block, | 180 | event->data.DownloadProgress.last_size); |
180 | event->data.DownloadProgress.last_size); | 181 | break; |
181 | break; | 182 | case FSUI_download_completed: |
182 | case FSUI_download_completed: | 183 | fs_download_completed (event->data.DownloadCompleted.dc.cctx); |
183 | fs_download_completed(event->data.DownloadCompleted.dc.cctx); | 184 | break; |
184 | break; | 185 | case FSUI_download_stopped: |
185 | case FSUI_download_stopped: | 186 | fs_download_stopped (event->data.DownloadStopped.dc.cctx); |
186 | fs_download_stopped(event->data.DownloadStopped.dc.cctx); | 187 | break; |
187 | break; | 188 | case FSUI_download_started: |
188 | case FSUI_download_started: | 189 | ret = fs_download_started (event->data.DownloadStarted.dc.pos, |
189 | ret = fs_download_started(event->data.DownloadStarted.dc.pos, | 190 | event->data.DownloadStarted.dc.pcctx, |
190 | event->data.DownloadStarted.dc.pcctx, | 191 | event->data.DownloadStarted.dc.sctx, |
191 | event->data.DownloadStarted.dc.sctx, | 192 | event->data.DownloadStarted.total, |
192 | event->data.DownloadStarted.total, | 193 | event->data.DownloadStarted.anonymityLevel, |
193 | event->data.DownloadStarted.anonymityLevel, | 194 | &event->data.DownloadStarted.fi, |
194 | &event->data.DownloadStarted.fi, | 195 | event->data.DownloadStarted.filename, |
195 | event->data.DownloadStarted.filename, | 196 | 0, get_time (), FSUI_ACTIVE); |
196 | 0, | 197 | break; |
197 | get_time(), | 198 | case FSUI_download_resumed: |
198 | FSUI_ACTIVE); | 199 | ret = fs_download_started (event->data.DownloadResumed.dc.pos, |
199 | break; | 200 | event->data.DownloadResumed.dc.pcctx, |
200 | case FSUI_download_resumed: | 201 | event->data.DownloadResumed.dc.sctx, |
201 | ret = fs_download_started(event->data.DownloadResumed.dc.pos, | 202 | event->data.DownloadResumed.total, |
202 | event->data.DownloadResumed.dc.pcctx, | 203 | event->data.DownloadResumed.anonymityLevel, |
203 | event->data.DownloadResumed.dc.sctx, | 204 | &event->data.DownloadResumed.fi, |
204 | event->data.DownloadResumed.total, | 205 | event->data.DownloadResumed.filename, |
205 | event->data.DownloadResumed.anonymityLevel, | 206 | event->data.DownloadResumed.completed, |
206 | &event->data.DownloadResumed.fi, | 207 | event->data.DownloadResumed.eta, |
207 | event->data.DownloadResumed.filename, | 208 | event->data.DownloadResumed.state); |
208 | event->data.DownloadResumed.completed, | 209 | break; |
209 | event->data.DownloadResumed.eta, | 210 | |
210 | event->data.DownloadResumed.state); | 211 | /* upload events */ |
211 | break; | 212 | case FSUI_upload_progress: |
212 | 213 | fs_upload_update (event->data.UploadProgress.uc.cctx, | |
213 | /* upload events */ | 214 | event->data.UploadProgress.completed); |
214 | case FSUI_upload_progress: | 215 | break; |
215 | fs_upload_update(event->data.UploadProgress.uc.cctx, | 216 | case FSUI_upload_completed: |
216 | event->data.UploadProgress.completed); | 217 | fs_upload_complete (event->data.UploadCompleted.uc.cctx, |
217 | break; | 218 | event->data.UploadCompleted.uri); |
218 | case FSUI_upload_completed: | 219 | break; |
219 | fs_upload_complete(event->data.UploadCompleted.uc.cctx, | 220 | case FSUI_upload_error: |
220 | event->data.UploadCompleted.uri); | 221 | fs_upload_error (event->data.UploadError.uc.cctx); |
221 | break; | 222 | break; |
222 | case FSUI_upload_error: | 223 | case FSUI_upload_aborted: |
223 | fs_upload_error(event->data.UploadError.uc.cctx); | 224 | fs_upload_error (event->data.UploadAborted.uc.cctx); |
224 | break; | 225 | break; |
225 | case FSUI_upload_aborted: | 226 | case FSUI_upload_stopped: |
226 | fs_upload_error(event->data.UploadAborted.uc.cctx); | 227 | fs_upload_stopped (event->data.UploadStopped.uc.cctx); |
227 | break; | 228 | break; |
228 | case FSUI_upload_stopped: | 229 | case FSUI_upload_suspended: |
229 | fs_upload_stopped(event->data.UploadStopped.uc.cctx); | 230 | fs_upload_stopped (event->data.UploadSuspended.uc.cctx); |
230 | break; | 231 | break; |
231 | case FSUI_upload_suspended: | 232 | case FSUI_upload_started: |
232 | fs_upload_stopped(event->data.UploadSuspended.uc.cctx); | 233 | ret = fs_upload_started (event->data.UploadStarted.uc.pos, |
233 | break; | 234 | event->data.UploadStarted.uc.pcctx, |
234 | case FSUI_upload_started: | 235 | event->data.UploadStarted.filename, |
235 | ret = fs_upload_started(event->data.UploadStarted.uc.pos, | 236 | NULL, |
236 | event->data.UploadStarted.uc.pcctx, | 237 | event->data.UploadStarted.total, |
237 | event->data.UploadStarted.filename, | 238 | 0, FSUI_ACTIVE); |
238 | NULL, | 239 | break; |
239 | event->data.UploadStarted.total, | 240 | case FSUI_upload_resumed: |
240 | 0, | 241 | ret = fs_upload_started (event->data.UploadResumed.uc.pos, |
241 | FSUI_ACTIVE); | 242 | event->data.UploadResumed.uc.pcctx, |
242 | break; | 243 | event->data.UploadResumed.filename, |
243 | case FSUI_upload_resumed: | 244 | event->data.UploadResumed.uri, |
244 | ret = fs_upload_started(event->data.UploadResumed.uc.pos, | 245 | event->data.UploadResumed.total, |
245 | event->data.UploadResumed.uc.pcctx, | 246 | event->data.UploadResumed.completed, |
246 | event->data.UploadResumed.filename, | 247 | event->data.UploadResumed.state); |
247 | event->data.UploadResumed.uri, | 248 | break; |
248 | event->data.UploadResumed.total, | 249 | /* TODO: unindex events */ |
249 | event->data.UploadResumed.completed, | 250 | default: |
250 | event->data.UploadResumed.state); | 251 | GE_BREAK (ectx, 0); |
251 | break; | 252 | GE_LOG (ectx, |
252 | /* TODO: unindex events */ | 253 | GE_ERROR, |
253 | default: | 254 | _("Unhandled (unknown) FSUI event: %u.\n"), event->type); |
254 | GE_BREAK(ectx, 0); | 255 | break; |
255 | GE_LOG(ectx, | 256 | } |
256 | GE_ERROR, | ||
257 | _("Unhandled (unknown) FSUI event: %u.\n"), | ||
258 | event->type); | ||
259 | break; | ||
260 | } | ||
261 | return ret; | 257 | return ret; |
262 | } | 258 | } |
263 | 259 | ||
264 | static void * | 260 | static void * |
265 | eventProcessor(void * unused, | 261 | eventProcessor (void *unused, const FSUI_Event * event) |
266 | const FSUI_Event * event) { | 262 | { |
267 | return gtkSaveCall(&saveEventProcessor, | 263 | return gtkSaveCall (&saveEventProcessor, (void *) event); |
268 | (void*) event); | ||
269 | } | 264 | } |
270 | 265 | ||
271 | /** | 266 | /** |
272 | * The selection of the upload summary changed. | 267 | * The selection of the upload summary changed. |
273 | * Update button status. | 268 | * Update button status. |
274 | */ | 269 | */ |
275 | static void on_upload_summary_selection_changed(gpointer signal, | 270 | static void |
276 | gpointer cls) { | 271 | on_upload_summary_selection_changed (gpointer signal, gpointer cls) |
277 | GtkTreeSelection * selection; | 272 | { |
278 | GtkWidget * button; | 273 | GtkTreeSelection *selection; |
279 | 274 | GtkWidget *button; | |
280 | selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(glade_xml_get_widget(getMainXML(), | 275 | |
281 | "activeUploadsList"))); | 276 | selection = |
282 | button | 277 | gtk_tree_view_get_selection (GTK_TREE_VIEW |
283 | = glade_xml_get_widget(getMainXML(), | 278 | (glade_xml_get_widget |
284 | "cancelUploadButton"); | 279 | (getMainXML (), "activeUploadsList"))); |
285 | gtk_widget_set_sensitive(button, | 280 | button = glade_xml_get_widget (getMainXML (), "cancelUploadButton"); |
286 | gtk_tree_selection_count_selected_rows(selection) > 0); | 281 | gtk_widget_set_sensitive (button, |
287 | button | 282 | gtk_tree_selection_count_selected_rows (selection) |
288 | = glade_xml_get_widget(getMainXML(), | 283 | > 0); |
289 | "stopUploadButton"); | 284 | button = glade_xml_get_widget (getMainXML (), "stopUploadButton"); |
290 | gtk_widget_set_sensitive(button, | 285 | gtk_widget_set_sensitive (button, |
291 | gtk_tree_selection_count_selected_rows(selection) > 0); | 286 | gtk_tree_selection_count_selected_rows (selection) |
287 | > 0); | ||
292 | } | 288 | } |
293 | 289 | ||
294 | /** | 290 | /** |
295 | * The selection of the download summary changed. | 291 | * The selection of the download summary changed. |
296 | * Update button status. | 292 | * Update button status. |
297 | */ | 293 | */ |
298 | static void on_download_summary_selection_changed(gpointer signal, | 294 | static void |
299 | gpointer cls) { | 295 | on_download_summary_selection_changed (gpointer signal, gpointer cls) |
300 | GtkTreeSelection * selection; | 296 | { |
301 | GtkWidget * button; | 297 | GtkTreeSelection *selection; |
302 | 298 | GtkWidget *button; | |
303 | selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(glade_xml_get_widget(getMainXML(), | 299 | |
304 | "activeDownloadsList"))); | 300 | selection = |
305 | button | 301 | gtk_tree_view_get_selection (GTK_TREE_VIEW |
306 | = glade_xml_get_widget(getMainXML(), | 302 | (glade_xml_get_widget |
307 | "abortDownloadButton"); | 303 | (getMainXML (), "activeDownloadsList"))); |
308 | gtk_widget_set_sensitive(button, | 304 | button = glade_xml_get_widget (getMainXML (), "abortDownloadButton"); |
309 | gtk_tree_selection_count_selected_rows(selection) > 0); | 305 | gtk_widget_set_sensitive (button, |
310 | button | 306 | gtk_tree_selection_count_selected_rows (selection) |
311 | = glade_xml_get_widget(getMainXML(), | 307 | > 0); |
312 | "stopDownloadButton"); | 308 | button = glade_xml_get_widget (getMainXML (), "stopDownloadButton"); |
313 | gtk_widget_set_sensitive(button, | 309 | gtk_widget_set_sensitive (button, |
314 | gtk_tree_selection_count_selected_rows(selection) > 0); | 310 | gtk_tree_selection_count_selected_rows (selection) |
311 | > 0); | ||
315 | } | 312 | } |
316 | 313 | ||
317 | /** | 314 | /** |
318 | * The selection of the download summary changed. | 315 | * The selection of the download summary changed. |
319 | * Update button status. | 316 | * Update button status. |
320 | */ | 317 | */ |
321 | static void on_search_summary_selection_changed(gpointer signal, | 318 | static void |
322 | gpointer cls) { | 319 | on_search_summary_selection_changed (gpointer signal, gpointer cls) |
323 | GtkTreeSelection * selection; | 320 | { |
324 | GtkWidget * button; | 321 | GtkTreeSelection *selection; |
325 | 322 | GtkWidget *button; | |
326 | selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(glade_xml_get_widget(getMainXML(), | 323 | |
327 | "activeSearchesSummary"))); | 324 | selection = |
328 | button | 325 | gtk_tree_view_get_selection (GTK_TREE_VIEW |
329 | = glade_xml_get_widget(getMainXML(), | 326 | (glade_xml_get_widget |
330 | "cancelSearchButton"); | 327 | (getMainXML (), "activeSearchesSummary"))); |
331 | gtk_widget_set_sensitive(button, | 328 | button = glade_xml_get_widget (getMainXML (), "cancelSearchButton"); |
332 | gtk_tree_selection_count_selected_rows(selection) > 0); | 329 | gtk_widget_set_sensitive (button, |
333 | button | 330 | gtk_tree_selection_count_selected_rows (selection) |
334 | = glade_xml_get_widget(getMainXML(), | 331 | > 0); |
335 | "stopSearchButton"); | 332 | button = glade_xml_get_widget (getMainXML (), "stopSearchButton"); |
336 | gtk_widget_set_sensitive(button, | 333 | gtk_widget_set_sensitive (button, |
337 | gtk_tree_selection_count_selected_rows(selection) > 0); | 334 | gtk_tree_selection_count_selected_rows (selection) |
335 | > 0); | ||
338 | } | 336 | } |
339 | 337 | ||
340 | static int | 338 | static int |
341 | on_upload_copy_uri_activate(void * cls, | 339 | on_upload_copy_uri_activate (void *cls, GtkWidget * searchEntry) |
342 | GtkWidget * searchEntry) { | 340 | { |
343 | GtkTreeView * uploadList = cls; | 341 | GtkTreeView *uploadList = cls; |
344 | GtkTreePath *path; | 342 | GtkTreePath *path; |
345 | GtkTreeIter iter; | 343 | GtkTreeIter iter; |
346 | struct ECRS_URI * uri; | 344 | struct ECRS_URI *uri; |
347 | char * str; | 345 | char *str; |
348 | GtkClipboard * clip; | 346 | GtkClipboard *clip; |
349 | 347 | ||
350 | path = NULL; | 348 | path = NULL; |
351 | if (FALSE == gtk_tree_view_get_path_at_pos(uploadList, | 349 | if (FALSE == gtk_tree_view_get_path_at_pos (uploadList, |
352 | last_x, | 350 | last_x, |
353 | last_y, | 351 | last_y, |
354 | &path, | 352 | &path, NULL, NULL, NULL)) |
355 | NULL, | 353 | { |
356 | NULL, | 354 | GE_BREAK (NULL, 0); |
357 | NULL)) { | 355 | return FALSE; |
358 | GE_BREAK(NULL, 0); | 356 | } |
359 | return FALSE; | 357 | if (FALSE == gtk_tree_model_get_iter (GTK_TREE_MODEL (upload_summary), |
360 | } | 358 | &iter, path)) |
361 | if (FALSE == gtk_tree_model_get_iter(GTK_TREE_MODEL(upload_summary), | 359 | { |
362 | &iter, | 360 | GE_BREAK (NULL, 0); |
363 | path)) { | 361 | gtk_tree_path_free (path); |
364 | GE_BREAK(NULL, 0); | 362 | return FALSE; |
365 | gtk_tree_path_free(path); | 363 | } |
366 | return FALSE; | 364 | gtk_tree_path_free (path); |
367 | } | ||
368 | gtk_tree_path_free(path); | ||
369 | uri = NULL; | 365 | uri = NULL; |
370 | gtk_tree_model_get(GTK_TREE_MODEL(upload_summary), | 366 | gtk_tree_model_get (GTK_TREE_MODEL (upload_summary), |
371 | &iter, | 367 | &iter, UPLOAD_URISTRING, &str, -1); |
372 | UPLOAD_URISTRING, &str, | 368 | clip = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD); |
373 | -1); | 369 | gtk_clipboard_set_text (clip, str, strlen (str)); |
374 | clip = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); | 370 | FREE (str); |
375 | gtk_clipboard_set_text(clip, | ||
376 | str, | ||
377 | strlen(str)); | ||
378 | FREE(str); | ||
379 | return FALSE; | 371 | return FALSE; |
380 | } | 372 | } |
381 | 373 | ||
382 | static gint | 374 | static gint |
383 | upload_click_handler(void * cls, | 375 | upload_click_handler (void *cls, GdkEvent * event) |
384 | GdkEvent *event) { | 376 | { |
385 | GtkTreeView * uploadList = cls; | 377 | GtkTreeView *uploadList = cls; |
386 | GtkMenu * menu; | 378 | GtkMenu *menu; |
387 | GtkWidget * entry; | 379 | GtkWidget *entry; |
388 | GdkEventButton * event_button; | 380 | GdkEventButton *event_button; |
389 | 381 | ||
390 | g_return_val_if_fail (event != NULL, FALSE); | 382 | g_return_val_if_fail (event != NULL, FALSE); |
391 | if (event->type != GDK_BUTTON_PRESS) | 383 | if (event->type != GDK_BUTTON_PRESS) |
@@ -395,24 +387,19 @@ upload_click_handler(void * cls, | |||
395 | return FALSE; | 387 | return FALSE; |
396 | last_x = event_button->x; | 388 | last_x = event_button->x; |
397 | last_y = event_button->y; | 389 | last_y = event_button->y; |
398 | entry = gtk_menu_item_new_with_label(_("_Copy URI to Clipboard")); | 390 | entry = gtk_menu_item_new_with_label (_("_Copy URI to Clipboard")); |
399 | g_signal_connect_swapped (entry, | 391 | g_signal_connect_swapped (entry, |
400 | "activate", | 392 | "activate", |
401 | G_CALLBACK(on_upload_copy_uri_activate), | 393 | G_CALLBACK (on_upload_copy_uri_activate), |
402 | uploadList); | 394 | uploadList); |
403 | gtk_label_set_use_underline(GTK_LABEL(gtk_bin_get_child(GTK_BIN(entry))), | 395 | gtk_label_set_use_underline (GTK_LABEL |
404 | TRUE); | 396 | (gtk_bin_get_child (GTK_BIN (entry))), TRUE); |
405 | gtk_widget_show(entry); | 397 | gtk_widget_show (entry); |
406 | menu = GTK_MENU(gtk_menu_new()); | 398 | menu = GTK_MENU (gtk_menu_new ()); |
407 | gtk_menu_shell_append(GTK_MENU_SHELL(menu), | 399 | gtk_menu_shell_append (GTK_MENU_SHELL (menu), entry); |
408 | entry); | ||
409 | gtk_menu_popup (menu, | 400 | gtk_menu_popup (menu, |
410 | NULL, | 401 | NULL, |
411 | NULL, | 402 | NULL, NULL, NULL, event_button->button, event_button->time); |
412 | NULL, | ||
413 | NULL, | ||
414 | event_button->button, | ||
415 | event_button->time); | ||
416 | return TRUE; | 403 | return TRUE; |
417 | } | 404 | } |
418 | 405 | ||
@@ -420,328 +407,297 @@ upload_click_handler(void * cls, | |||
420 | * Setup the summary views (in particular the models | 407 | * Setup the summary views (in particular the models |
421 | * and the renderers). | 408 | * and the renderers). |
422 | */ | 409 | */ |
423 | static void fs_summary_start() { | 410 | static void |
424 | GtkComboBoxEntry * searchCB; | 411 | fs_summary_start () |
425 | GtkWidget * uploadEntry; | 412 | { |
426 | GtkTreeView * searchList; | 413 | GtkComboBoxEntry *searchCB; |
427 | GtkTreeView * downloadList; | 414 | GtkWidget *uploadEntry; |
428 | GtkTreeView * uploadList; | 415 | GtkTreeView *searchList; |
429 | GtkListStore * model; | 416 | GtkTreeView *downloadList; |
430 | GtkCellRenderer * renderer; | 417 | GtkTreeView *uploadList; |
431 | GtkTreeViewColumn * column; | 418 | GtkListStore *model; |
419 | GtkCellRenderer *renderer; | ||
420 | GtkTreeViewColumn *column; | ||
432 | int col; | 421 | int col; |
433 | 422 | ||
434 | /* keyword list setup */ | 423 | /* keyword list setup */ |
435 | searchCB | 424 | searchCB |
436 | = GTK_COMBO_BOX_ENTRY(glade_xml_get_widget(getMainXML(), | 425 | = GTK_COMBO_BOX_ENTRY (glade_xml_get_widget (getMainXML (), |
437 | "fssearchKeywordComboBoxEntry")); | 426 | "fssearchKeywordComboBoxEntry")); |
438 | model = gtk_list_store_new(1, | 427 | model = gtk_list_store_new (1, G_TYPE_STRING /* search string */ ); |
439 | G_TYPE_STRING /* search string*/ ); | 428 | gtk_combo_box_set_model (GTK_COMBO_BOX (searchCB), GTK_TREE_MODEL (model)); |
440 | gtk_combo_box_set_model(GTK_COMBO_BOX(searchCB), | 429 | gtk_combo_box_entry_set_text_column (searchCB, 0); |
441 | GTK_TREE_MODEL(model)); | ||
442 | gtk_combo_box_entry_set_text_column(searchCB, | ||
443 | 0); | ||
444 | 430 | ||
445 | /* search namespace selection setup */ | 431 | /* search namespace selection setup */ |
446 | searchCB | 432 | searchCB |
447 | = GTK_COMBO_BOX_ENTRY(glade_xml_get_widget(getMainXML(), | 433 | = GTK_COMBO_BOX_ENTRY (glade_xml_get_widget (getMainXML (), |
448 | "searchNamespaceComboBoxEntry")); | 434 | "searchNamespaceComboBoxEntry")); |
449 | 435 | ||
450 | model = gtk_list_store_new(NS_SEARCH_NUM, | 436 | model = gtk_list_store_new (NS_SEARCH_NUM, G_TYPE_STRING, /* what we show */ |
451 | G_TYPE_STRING, /* what we show */ | 437 | G_TYPE_STRING, /* EncName of namespace */ |
452 | G_TYPE_STRING, /* EncName of namespace */ | 438 | G_TYPE_POINTER, /* ECRS MetaData */ |
453 | G_TYPE_POINTER, /* ECRS MetaData */ | 439 | G_TYPE_INT); /* Meta-data about namespace */ |
454 | G_TYPE_INT); /* Meta-data about namespace */ | 440 | gtk_combo_box_set_model (GTK_COMBO_BOX (searchCB), GTK_TREE_MODEL (model)); |
455 | gtk_combo_box_set_model(GTK_COMBO_BOX(searchCB), | 441 | gtk_combo_box_entry_set_text_column (searchCB, NS_SEARCH_DESCRIPTION); |
456 | GTK_TREE_MODEL(model)); | ||
457 | gtk_combo_box_entry_set_text_column(searchCB, | ||
458 | NS_SEARCH_DESCRIPTION); | ||
459 | 442 | ||
460 | /* search summary setup */ | 443 | /* search summary setup */ |
461 | searchList = GTK_TREE_VIEW(glade_xml_get_widget(getMainXML(), | 444 | searchList = GTK_TREE_VIEW (glade_xml_get_widget (getMainXML (), |
462 | "activeSearchesSummary")); | 445 | "activeSearchesSummary")); |
463 | search_summary = | 446 | search_summary = gtk_list_store_new (SEARCH_SUMMARY_NUM, G_TYPE_STRING, /* name */ |
464 | gtk_list_store_new(SEARCH_SUMMARY_NUM, | 447 | G_TYPE_INT, /* # results */ |
465 | G_TYPE_STRING, /* name */ | 448 | G_TYPE_POINTER); /* internal: search list */ |
466 | G_TYPE_INT, /* # results */ | 449 | gtk_tree_view_set_model (searchList, GTK_TREE_MODEL (search_summary)); |
467 | G_TYPE_POINTER); /* internal: search list */ | 450 | gtk_tree_selection_set_mode (gtk_tree_view_get_selection (searchList), |
468 | gtk_tree_view_set_model(searchList, | 451 | GTK_SELECTION_MULTIPLE); |
469 | GTK_TREE_MODEL(search_summary)); | 452 | g_signal_connect_data (gtk_tree_view_get_selection (searchList), |
470 | gtk_tree_selection_set_mode(gtk_tree_view_get_selection(searchList), | 453 | "changed", |
471 | GTK_SELECTION_MULTIPLE); | 454 | G_CALLBACK (&on_search_summary_selection_changed), |
472 | g_signal_connect_data(gtk_tree_view_get_selection(searchList), | 455 | NULL, NULL, 0); |
473 | "changed", | 456 | |
474 | G_CALLBACK(&on_search_summary_selection_changed), | 457 | renderer = gtk_cell_renderer_text_new (); |
475 | NULL, | 458 | col = gtk_tree_view_insert_column_with_attributes (searchList, |
476 | NULL, | 459 | -1, |
477 | 0); | 460 | _("Query"), |
478 | 461 | renderer, | |
479 | renderer = gtk_cell_renderer_text_new(); | 462 | "text", |
480 | col = gtk_tree_view_insert_column_with_attributes(searchList, | 463 | SEARCH_SUMMARY_NAME, |
481 | -1, | 464 | NULL); |
482 | _("Query"), | 465 | column = gtk_tree_view_get_column (searchList, col - 1); |
483 | renderer, | 466 | gtk_tree_view_column_set_resizable (column, TRUE); |
484 | "text", SEARCH_SUMMARY_NAME, | 467 | gtk_tree_view_column_set_clickable (column, TRUE); |
485 | NULL); | 468 | gtk_tree_view_column_set_reorderable (column, TRUE); |
486 | column = gtk_tree_view_get_column(searchList, | 469 | gtk_tree_view_column_set_sort_column_id (column, SEARCH_SUMMARY_NAME); |
487 | col - 1); | 470 | gtk_tree_view_column_set_resizable (column, TRUE); |
488 | gtk_tree_view_column_set_resizable(column, TRUE); | 471 | renderer = gtk_cell_renderer_text_new (); |
489 | gtk_tree_view_column_set_clickable(column, TRUE); | 472 | col = gtk_tree_view_insert_column_with_attributes (searchList, |
490 | gtk_tree_view_column_set_reorderable(column, TRUE); | 473 | -1, |
491 | gtk_tree_view_column_set_sort_column_id(column, SEARCH_SUMMARY_NAME); | 474 | _("Results"), |
492 | gtk_tree_view_column_set_resizable(column, TRUE); | 475 | renderer, |
493 | renderer = gtk_cell_renderer_text_new(); | 476 | "text", |
494 | col = gtk_tree_view_insert_column_with_attributes(searchList, | 477 | SEARCH_SUMMARY_RESULT_COUNT, |
495 | -1, | 478 | NULL); |
496 | _("Results"), | 479 | column = gtk_tree_view_get_column (searchList, col - 1); |
497 | renderer, | 480 | gtk_tree_view_column_set_resizable (column, TRUE); |
498 | "text", SEARCH_SUMMARY_RESULT_COUNT, | 481 | gtk_tree_view_column_set_clickable (column, TRUE); |
499 | NULL); | 482 | gtk_tree_view_column_set_reorderable (column, TRUE); |
500 | column = gtk_tree_view_get_column(searchList, | 483 | gtk_tree_view_column_set_sort_column_id (column, |
501 | col - 1); | 484 | SEARCH_SUMMARY_RESULT_COUNT); |
502 | gtk_tree_view_column_set_resizable(column, TRUE); | 485 | gtk_tree_view_column_set_resizable (column, TRUE); |
503 | gtk_tree_view_column_set_clickable(column, TRUE); | ||
504 | gtk_tree_view_column_set_reorderable(column, TRUE); | ||
505 | gtk_tree_view_column_set_sort_column_id(column, SEARCH_SUMMARY_RESULT_COUNT); | ||
506 | gtk_tree_view_column_set_resizable(column, TRUE); | ||
507 | 486 | ||
508 | /* download summary setup */ | 487 | /* download summary setup */ |
509 | downloadList = GTK_TREE_VIEW(glade_xml_get_widget(getMainXML(), | 488 | downloadList = GTK_TREE_VIEW (glade_xml_get_widget (getMainXML (), |
510 | "activeDownloadsList")); | 489 | "activeDownloadsList")); |
511 | download_summary = | 490 | download_summary = gtk_tree_store_new (DOWNLOAD_NUM, G_TYPE_STRING, /* name (full-path file name) */ |
512 | gtk_tree_store_new(DOWNLOAD_NUM, | 491 | G_TYPE_STRING, /* name (user-friendly name) */ |
513 | G_TYPE_STRING, /* name (full-path file name) */ | 492 | G_TYPE_UINT64, /* size */ |
514 | G_TYPE_STRING, /* name (user-friendly name) */ | 493 | G_TYPE_STRING, /* human readable size */ |
515 | G_TYPE_UINT64, /* size */ | 494 | G_TYPE_INT, /* progress */ |
516 | G_TYPE_STRING, /* human readable size */ | 495 | G_TYPE_STRING, /* uri as string */ |
517 | G_TYPE_INT, /* progress */ | 496 | G_TYPE_POINTER); /* internal download list ptr */ |
518 | G_TYPE_STRING, /* uri as string */ | 497 | gtk_tree_view_set_model (downloadList, GTK_TREE_MODEL (download_summary)); |
519 | G_TYPE_POINTER); /* internal download list ptr */ | 498 | gtk_tree_selection_set_mode (gtk_tree_view_get_selection (downloadList), |
520 | gtk_tree_view_set_model(downloadList, | 499 | GTK_SELECTION_MULTIPLE); |
521 | GTK_TREE_MODEL(download_summary)); | 500 | g_signal_connect_data (gtk_tree_view_get_selection (downloadList), |
522 | gtk_tree_selection_set_mode(gtk_tree_view_get_selection(downloadList), | 501 | "changed", |
523 | GTK_SELECTION_MULTIPLE); | 502 | G_CALLBACK (&on_download_summary_selection_changed), |
524 | g_signal_connect_data(gtk_tree_view_get_selection(downloadList), | 503 | NULL, NULL, 0); |
525 | "changed", | 504 | |
526 | G_CALLBACK(&on_download_summary_selection_changed), | 505 | renderer = gtk_cell_renderer_text_new (); |
527 | NULL, | ||
528 | NULL, | ||
529 | 0); | ||
530 | |||
531 | renderer = gtk_cell_renderer_text_new(); | ||
532 | g_object_set (renderer, "xalign", 1.00, NULL); | 506 | g_object_set (renderer, "xalign", 1.00, NULL); |
533 | col = gtk_tree_view_insert_column_with_attributes(downloadList, | 507 | col = gtk_tree_view_insert_column_with_attributes (downloadList, |
534 | -1, | 508 | -1, |
535 | _("Size"), | 509 | _("Size"), |
536 | renderer, | 510 | renderer, |
537 | "text", DOWNLOAD_HSIZE, | 511 | "text", DOWNLOAD_HSIZE, |
538 | NULL); | 512 | NULL); |
539 | 513 | ||
540 | column = gtk_tree_view_get_column(downloadList, | 514 | column = gtk_tree_view_get_column (downloadList, col - 1); |
541 | col - 1); | 515 | gtk_tree_view_column_set_resizable (column, TRUE); |
542 | gtk_tree_view_column_set_resizable(column, TRUE); | 516 | gtk_tree_view_column_set_clickable (column, TRUE); |
543 | gtk_tree_view_column_set_clickable(column, TRUE); | 517 | gtk_tree_view_column_set_reorderable (column, TRUE); |
544 | gtk_tree_view_column_set_reorderable(column, TRUE); | 518 | gtk_tree_view_column_set_sort_column_id (column, DOWNLOAD_SIZE); |
545 | gtk_tree_view_column_set_sort_column_id(column, DOWNLOAD_SIZE); | 519 | gtk_tree_view_column_set_resizable (column, TRUE); |
546 | gtk_tree_view_column_set_resizable(column, TRUE); | 520 | |
547 | 521 | renderer = gtk_cell_renderer_progress_new (); | |
548 | renderer = gtk_cell_renderer_progress_new(); | 522 | col = gtk_tree_view_insert_column_with_attributes (downloadList, |
549 | col = gtk_tree_view_insert_column_with_attributes(downloadList, | 523 | -1, |
550 | -1, | 524 | _("Name"), |
551 | _("Name"), | 525 | renderer, |
552 | renderer, | 526 | "value", |
553 | "value", DOWNLOAD_PROGRESS, | 527 | DOWNLOAD_PROGRESS, |
554 | "text", DOWNLOAD_SHORTNAME, | 528 | "text", |
555 | NULL); | 529 | DOWNLOAD_SHORTNAME, |
556 | g_object_set(G_OBJECT(renderer), | 530 | NULL); |
557 | "width", 400, | 531 | g_object_set (G_OBJECT (renderer), "width", 400, NULL); |
558 | NULL); | 532 | column = gtk_tree_view_get_column (downloadList, col - 1); |
559 | column = gtk_tree_view_get_column(downloadList, | 533 | gtk_tree_view_column_set_resizable (column, TRUE); |
560 | col - 1); | 534 | gtk_tree_view_column_set_clickable (column, TRUE); |
561 | gtk_tree_view_column_set_resizable(column, TRUE); | 535 | gtk_tree_view_column_set_reorderable (column, TRUE); |
562 | gtk_tree_view_column_set_clickable(column, TRUE); | 536 | gtk_tree_view_column_set_sort_column_id (column, DOWNLOAD_PROGRESS); |
563 | gtk_tree_view_column_set_reorderable(column, TRUE); | 537 | gtk_tree_view_column_set_resizable (column, TRUE); |
564 | gtk_tree_view_column_set_sort_column_id(column, DOWNLOAD_PROGRESS); | 538 | |
565 | gtk_tree_view_column_set_resizable(column, TRUE); | 539 | renderer = gtk_cell_renderer_text_new (); |
566 | 540 | col = gtk_tree_view_insert_column_with_attributes (downloadList, | |
567 | renderer = gtk_cell_renderer_text_new(); | 541 | -1, |
568 | col = gtk_tree_view_insert_column_with_attributes(downloadList, | 542 | _("URI"), |
569 | -1, | 543 | renderer, |
570 | _("URI"), | 544 | "text", |
571 | renderer, | 545 | DOWNLOAD_URISTRING, |
572 | "text", DOWNLOAD_URISTRING, | 546 | NULL); |
573 | NULL); | 547 | g_object_set (G_OBJECT (renderer), "wrap-width", 30, "width-chars", 30, |
574 | g_object_set(G_OBJECT(renderer), | 548 | "ellipsize", PANGO_ELLIPSIZE_END, NULL); |
575 | "wrap-width", 30, | 549 | column = gtk_tree_view_get_column (downloadList, col - 1); |
576 | "width-chars", 30, | 550 | gtk_tree_view_column_set_resizable (column, TRUE); |
577 | "ellipsize", PANGO_ELLIPSIZE_END, | 551 | gtk_tree_view_column_set_reorderable (column, TRUE); |
578 | NULL); | 552 | gtk_tree_view_column_set_resizable (column, TRUE); |
579 | column = gtk_tree_view_get_column(downloadList, | ||
580 | col - 1); | ||
581 | gtk_tree_view_column_set_resizable(column, TRUE); | ||
582 | gtk_tree_view_column_set_reorderable(column, TRUE); | ||
583 | gtk_tree_view_column_set_resizable(column, TRUE); | ||
584 | 553 | ||
585 | /* upload summary setup */ | 554 | /* upload summary setup */ |
586 | uploadList = GTK_TREE_VIEW(glade_xml_get_widget(getMainXML(), | 555 | uploadList = GTK_TREE_VIEW (glade_xml_get_widget (getMainXML (), |
587 | "activeUploadsList")); | 556 | "activeUploadsList")); |
588 | g_signal_connect_swapped (uploadList, | 557 | g_signal_connect_swapped (uploadList, |
589 | "button-press-event", | 558 | "button-press-event", |
590 | G_CALLBACK(upload_click_handler), | 559 | G_CALLBACK (upload_click_handler), uploadList); |
591 | uploadList); | 560 | upload_summary = gtk_tree_store_new (UPLOAD_NUM, G_TYPE_STRING, /* filename */ |
592 | upload_summary = | 561 | G_TYPE_INT, /* progress */ |
593 | gtk_tree_store_new(UPLOAD_NUM, | 562 | G_TYPE_STRING, /* URI as string */ |
594 | G_TYPE_STRING, /* filename */ | 563 | G_TYPE_POINTER); /* UploadList */ |
595 | G_TYPE_INT, /* progress */ | 564 | gtk_tree_view_set_model (uploadList, GTK_TREE_MODEL (upload_summary)); |
596 | G_TYPE_STRING, /* URI as string */ | 565 | gtk_tree_selection_set_mode (gtk_tree_view_get_selection (uploadList), |
597 | G_TYPE_POINTER); /* UploadList */ | 566 | GTK_SELECTION_MULTIPLE); |
598 | gtk_tree_view_set_model(uploadList, | 567 | g_signal_connect_data (gtk_tree_view_get_selection (uploadList), |
599 | GTK_TREE_MODEL(upload_summary)); | 568 | "changed", |
600 | gtk_tree_selection_set_mode(gtk_tree_view_get_selection(uploadList), | 569 | G_CALLBACK (&on_upload_summary_selection_changed), |
601 | GTK_SELECTION_MULTIPLE); | 570 | NULL, NULL, 0); |
602 | g_signal_connect_data(gtk_tree_view_get_selection(uploadList), | 571 | |
603 | "changed", | 572 | renderer = gtk_cell_renderer_progress_new (); |
604 | G_CALLBACK(&on_upload_summary_selection_changed), | 573 | col = gtk_tree_view_insert_column_with_attributes (uploadList, |
605 | NULL, | 574 | -1, |
606 | NULL, | 575 | _("Filename"), |
607 | 0); | 576 | renderer, |
608 | 577 | "text", UPLOAD_FILENAME, | |
609 | renderer = gtk_cell_renderer_progress_new(); | 578 | "value", UPLOAD_PROGRESS, |
610 | col = gtk_tree_view_insert_column_with_attributes(uploadList, | 579 | NULL); |
611 | -1, | 580 | gtk_tree_view_column_set_resizable (gtk_tree_view_get_column (uploadList, |
612 | _("Filename"), | 581 | col - 1), |
613 | renderer, | 582 | TRUE); |
614 | "text", UPLOAD_FILENAME, | 583 | |
615 | "value", UPLOAD_PROGRESS, | 584 | renderer = gtk_cell_renderer_text_new (); |
616 | NULL); | 585 | col = gtk_tree_view_insert_column_with_attributes (uploadList, |
617 | gtk_tree_view_column_set_resizable(gtk_tree_view_get_column(uploadList, | 586 | -1, |
618 | col - 1), | 587 | _("URI"), |
619 | TRUE); | 588 | renderer, |
620 | 589 | "text", UPLOAD_URISTRING, | |
621 | renderer = gtk_cell_renderer_text_new(); | 590 | NULL); |
622 | col = gtk_tree_view_insert_column_with_attributes(uploadList, | 591 | gtk_tree_view_column_set_resizable (gtk_tree_view_get_column (uploadList, |
623 | -1, | 592 | col - 1), |
624 | _("URI"), | 593 | TRUE); |
625 | renderer, | ||
626 | "text", UPLOAD_URISTRING, | ||
627 | NULL); | ||
628 | gtk_tree_view_column_set_resizable(gtk_tree_view_get_column(uploadList, | ||
629 | col - 1), | ||
630 | TRUE); | ||
631 | /* upload entry setup */ | 594 | /* upload entry setup */ |
632 | uploadEntry | 595 | uploadEntry |
633 | = glade_xml_get_widget(getMainXML(), | 596 | = glade_xml_get_widget (getMainXML (), "uploadFilenameComboBoxEntry"); |
634 | "uploadFilenameComboBoxEntry"); | 597 | |
635 | 598 | model = gtk_list_store_new (1, G_TYPE_STRING); | |
636 | model = gtk_list_store_new(1, G_TYPE_STRING); | 599 | gtk_combo_box_set_model (GTK_COMBO_BOX (uploadEntry), |
637 | gtk_combo_box_set_model(GTK_COMBO_BOX(uploadEntry), | 600 | GTK_TREE_MODEL (model)); |
638 | GTK_TREE_MODEL(model)); | 601 | gtk_combo_box_entry_set_text_column (GTK_COMBO_BOX_ENTRY (uploadEntry), 0); |
639 | gtk_combo_box_entry_set_text_column(GTK_COMBO_BOX_ENTRY(uploadEntry), | ||
640 | 0); | ||
641 | } | 602 | } |
642 | 603 | ||
643 | /** | 604 | /** |
644 | * Shutdown the summary dialogs. | 605 | * Shutdown the summary dialogs. |
645 | */ | 606 | */ |
646 | static void fs_summary_stop() { | 607 | static void |
647 | struct ECRS_MetaData * meta; | 608 | fs_summary_stop () |
648 | GtkComboBox * searchCB; | 609 | { |
649 | GtkTreeModel * model; | 610 | struct ECRS_MetaData *meta; |
611 | GtkComboBox *searchCB; | ||
612 | GtkTreeModel *model; | ||
650 | GtkTreeIter iter; | 613 | GtkTreeIter iter; |
651 | 614 | ||
652 | searchCB | 615 | searchCB |
653 | = GTK_COMBO_BOX(glade_xml_get_widget(getMainXML(), | 616 | = GTK_COMBO_BOX (glade_xml_get_widget (getMainXML (), |
654 | "searchNamespaceComboBoxEntry")); | 617 | "searchNamespaceComboBoxEntry")); |
655 | model = gtk_combo_box_get_model(searchCB); | 618 | model = gtk_combo_box_get_model (searchCB); |
656 | if (gtk_tree_model_get_iter_first(model, | 619 | if (gtk_tree_model_get_iter_first (model, &iter)) |
657 | &iter)) { | 620 | { |
658 | do { | 621 | do |
659 | gtk_tree_model_get(model, | 622 | { |
660 | &iter, | 623 | gtk_tree_model_get (model, &iter, NS_SEARCH_METADATA, &meta, -1); |
661 | NS_SEARCH_METADATA, &meta, | 624 | gtk_list_store_set (GTK_LIST_STORE (model), |
662 | -1); | 625 | &iter, NS_SEARCH_METADATA, NULL, -1); |
663 | gtk_list_store_set(GTK_LIST_STORE(model), | 626 | if (meta != NULL) |
664 | &iter, | 627 | ECRS_freeMetaData (meta); |
665 | NS_SEARCH_METADATA, NULL, | 628 | } |
666 | -1); | 629 | while (gtk_list_store_remove (GTK_LIST_STORE (model), &iter)); |
667 | if (meta != NULL) | 630 | } |
668 | ECRS_freeMetaData(meta); | ||
669 | } while (gtk_list_store_remove(GTK_LIST_STORE(model), | ||
670 | &iter)); | ||
671 | } | ||
672 | 631 | ||
673 | } | 632 | } |
674 | 633 | ||
675 | void init_fs(struct GE_Context * e, | 634 | void |
676 | struct GC_Configuration * c) { | 635 | init_fs (struct GE_Context *e, struct GC_Configuration *c) |
677 | GtkWidget * tab; | 636 | { |
678 | GtkWidget * book; | 637 | GtkWidget *tab; |
638 | GtkWidget *book; | ||
679 | gint num; | 639 | gint num; |
680 | 640 | ||
681 | ectx = e; | 641 | ectx = e; |
682 | cfg = c; | 642 | cfg = c; |
683 | CO_init(ectx, cfg); | 643 | CO_init (ectx, cfg); |
684 | tab | 644 | tab = glade_xml_get_widget (getMainXML (), "fsnotebook"); |
685 | = glade_xml_get_widget(getMainXML(), | 645 | gtk_widget_show (tab); |
686 | "fsnotebook"); | 646 | book = glade_xml_get_widget (getMainXML (), "mainnotebook"); |
687 | gtk_widget_show(tab); | 647 | num = gtk_notebook_get_current_page (GTK_NOTEBOOK (book)); |
688 | book | 648 | gtk_notebook_set_current_page (GTK_NOTEBOOK (book), 1); |
689 | = glade_xml_get_widget(getMainXML(), "mainnotebook"); | 649 | gtk_notebook_set_current_page (GTK_NOTEBOOK (book), num); |
690 | num = gtk_notebook_get_current_page(GTK_NOTEBOOK(book)); | 650 | fs_summary_start (); |
691 | gtk_notebook_set_current_page(GTK_NOTEBOOK(book), 1); | 651 | fs_collection_start (); |
692 | gtk_notebook_set_current_page(GTK_NOTEBOOK(book), num); | 652 | fs_namespace_start (); |
693 | fs_summary_start(); | 653 | ctx = FSUI_start (ectx, cfg, "gnunet-gtk", 8, /* FIXME: allow user to configure download parallelism */ |
694 | fs_collection_start(); | 654 | YES, &eventProcessor, NULL); |
695 | fs_namespace_start(); | ||
696 | ctx = FSUI_start(ectx, | ||
697 | cfg, | ||
698 | "gnunet-gtk", | ||
699 | 8, /* FIXME: allow user to configure download parallelism */ | ||
700 | YES, | ||
701 | &eventProcessor, | ||
702 | NULL); | ||
703 | } | 655 | } |
704 | 656 | ||
705 | static void * hide_save_call(void * arg) { | 657 | static void * |
706 | GtkWidget * tab; | 658 | hide_save_call (void *arg) |
659 | { | ||
660 | GtkWidget *tab; | ||
707 | 661 | ||
708 | tab | 662 | tab = glade_xml_get_widget (getMainXML (), "fsnotebook"); |
709 | = glade_xml_get_widget(getMainXML(), | 663 | gtk_widget_hide (tab); |
710 | "fsnotebook"); | ||
711 | gtk_widget_hide(tab); | ||
712 | return NULL; | 664 | return NULL; |
713 | } | 665 | } |
714 | 666 | ||
715 | static void * cleanup_save_call(void * arg) { | 667 | static void * |
716 | fs_summary_stop(); | 668 | cleanup_save_call (void *arg) |
717 | fs_namespace_stop(); | 669 | { |
670 | fs_summary_stop (); | ||
671 | fs_namespace_stop (); | ||
718 | return NULL; | 672 | return NULL; |
719 | } | 673 | } |
720 | 674 | ||
721 | void done_fs() { | 675 | void |
722 | gtkSaveCall(&hide_save_call, NULL); | 676 | done_fs () |
723 | FSUI_stop(ctx); | 677 | { |
724 | gtkSaveCall(&cleanup_save_call, NULL); | 678 | gtkSaveCall (&hide_save_call, NULL); |
725 | CO_done(); | 679 | FSUI_stop (ctx); |
680 | gtkSaveCall (&cleanup_save_call, NULL); | ||
681 | CO_done (); | ||
726 | } | 682 | } |
727 | 683 | ||
728 | 684 | ||
729 | const char * getColorCode(enum URITRACK_STATE state) { | 685 | const char * |
686 | getColorCode (enum URITRACK_STATE state) | ||
687 | { | ||
730 | if (state & (URITRACK_DIRECTORY_ADDED)) | 688 | if (state & (URITRACK_DIRECTORY_ADDED)) |
731 | return "blue"; | 689 | return "blue"; |
732 | if (state & (URITRACK_INSERTED || URITRACK_INDEXED)) | 690 | if (state & (URITRACK_INSERTED || URITRACK_INDEXED)) |
733 | return "cyan"; | 691 | return "cyan"; |
734 | if ( (state & URITRACK_DOWNLOAD_STARTED) && | 692 | if ((state & URITRACK_DOWNLOAD_STARTED) && |
735 | (0 == (state & | 693 | (0 == (state & |
736 | (URITRACK_DOWNLOAD_COMPLETED | | 694 | (URITRACK_DOWNLOAD_COMPLETED | URITRACK_DOWNLOAD_ABORTED)))) |
737 | URITRACK_DOWNLOAD_ABORTED)) ) ) | ||
738 | return "yellow"; | 695 | return "yellow"; |
739 | if (state & URITRACK_DOWNLOAD_COMPLETED) | 696 | if (state & URITRACK_DOWNLOAD_COMPLETED) |
740 | return "springgreen"; | 697 | return "springgreen"; |
741 | if (state & URITRACK_DOWNLOAD_ABORTED) | 698 | if (state & URITRACK_DOWNLOAD_ABORTED) |
742 | return "red"; | 699 | return "red"; |
743 | if (state & (URITRACK_SEARCH_RESULT | | 700 | if (state & (URITRACK_SEARCH_RESULT | URITRACK_DIRECTORY_FOUND)) |
744 | URITRACK_DIRECTORY_FOUND) ) | ||
745 | return "gray"; | 701 | return "gray"; |
746 | return "white"; | 702 | return "white"; |
747 | } | 703 | } |
diff --git a/src/plugins/fs/fs.h b/src/plugins/fs/fs.h index 2e54415b..14b691e0 100644 --- a/src/plugins/fs/fs.h +++ b/src/plugins/fs/fs.h | |||
@@ -36,7 +36,8 @@ | |||
36 | * On search box, for namespace selection | 36 | * On search box, for namespace selection |
37 | * (for input of search URI; lists known namespaces). | 37 | * (for input of search URI; lists known namespaces). |
38 | */ | 38 | */ |
39 | enum { | 39 | enum |
40 | { | ||
40 | NS_SEARCH_DESCRIPTION = 0, | 41 | NS_SEARCH_DESCRIPTION = 0, |
41 | NS_SEARCH_ENCNAME, | 42 | NS_SEARCH_ENCNAME, |
42 | NS_SEARCH_METADATA, | 43 | NS_SEARCH_METADATA, |
@@ -48,7 +49,8 @@ enum { | |||
48 | * For listing of search results for main search. | 49 | * For listing of search results for main search. |
49 | * Represents a search result. | 50 | * Represents a search result. |
50 | */ | 51 | */ |
51 | enum { | 52 | enum |
53 | { | ||
52 | SEARCH_NAME = 0, | 54 | SEARCH_NAME = 0, |
53 | SEARCH_SIZE, | 55 | SEARCH_SIZE, |
54 | SEARCH_HSIZE, | 56 | SEARCH_HSIZE, |
@@ -68,7 +70,8 @@ enum { | |||
68 | * Search entry in search summary list. | 70 | * Search entry in search summary list. |
69 | * Represents a search process. | 71 | * Represents a search process. |
70 | */ | 72 | */ |
71 | enum { | 73 | enum |
74 | { | ||
72 | SEARCH_SUMMARY_NAME = 0, | 75 | SEARCH_SUMMARY_NAME = 0, |
73 | SEARCH_SUMMARY_RESULT_COUNT, | 76 | SEARCH_SUMMARY_RESULT_COUNT, |
74 | SEARCH_SUMMARY_INTERNAL, | 77 | SEARCH_SUMMARY_INTERNAL, |
@@ -78,18 +81,20 @@ enum { | |||
78 | /** | 81 | /** |
79 | * Entry in download summary. | 82 | * Entry in download summary. |
80 | */ | 83 | */ |
81 | enum { | 84 | enum |
85 | { | ||
82 | DOWNLOAD_FILENAME = 0, | 86 | DOWNLOAD_FILENAME = 0, |
83 | DOWNLOAD_SHORTNAME, | 87 | DOWNLOAD_SHORTNAME, |
84 | DOWNLOAD_SIZE, | 88 | DOWNLOAD_SIZE, |
85 | DOWNLOAD_HSIZE, | 89 | DOWNLOAD_HSIZE, |
86 | DOWNLOAD_PROGRESS, | 90 | DOWNLOAD_PROGRESS, |
87 | DOWNLOAD_URISTRING, | 91 | DOWNLOAD_URISTRING, |
88 | DOWNLOAD_INTERNAL, /* struct DL */ | 92 | DOWNLOAD_INTERNAL, /* struct DL */ |
89 | DOWNLOAD_NUM | 93 | DOWNLOAD_NUM |
90 | }; | 94 | }; |
91 | 95 | ||
92 | enum { | 96 | enum |
97 | { | ||
93 | NAMESPACE_FILENAME = 0, | 98 | NAMESPACE_FILENAME = 0, |
94 | NAMESPACE_SIZE, | 99 | NAMESPACE_SIZE, |
95 | NAMESPACE_HSIZE, | 100 | NAMESPACE_HSIZE, |
@@ -99,7 +104,8 @@ enum { | |||
99 | NAMESPACE_NUM | 104 | NAMESPACE_NUM |
100 | }; | 105 | }; |
101 | 106 | ||
102 | enum { | 107 | enum |
108 | { | ||
103 | IN_NAMESPACE_FILENAME = 0, | 109 | IN_NAMESPACE_FILENAME = 0, |
104 | IN_NAMESPACE_SIZE, | 110 | IN_NAMESPACE_SIZE, |
105 | IN_NAMESPACE_HSIZE, | 111 | IN_NAMESPACE_HSIZE, |
@@ -117,7 +123,8 @@ enum { | |||
117 | /** | 123 | /** |
118 | * Entry in upload summary. | 124 | * Entry in upload summary. |
119 | */ | 125 | */ |
120 | enum { | 126 | enum |
127 | { | ||
121 | UPLOAD_FILENAME = 0, | 128 | UPLOAD_FILENAME = 0, |
122 | UPLOAD_PROGRESS, | 129 | UPLOAD_PROGRESS, |
123 | UPLOAD_URISTRING, | 130 | UPLOAD_URISTRING, |
@@ -125,14 +132,16 @@ enum { | |||
125 | UPLOAD_NUM | 132 | UPLOAD_NUM |
126 | }; | 133 | }; |
127 | 134 | ||
128 | enum { | 135 | enum |
136 | { | ||
129 | META_TYPE = 0, | 137 | META_TYPE = 0, |
130 | META_STYPE, | 138 | META_STYPE, |
131 | META_VALUE, | 139 | META_VALUE, |
132 | META_NUM, | 140 | META_NUM, |
133 | }; | 141 | }; |
134 | 142 | ||
135 | enum { | 143 | enum |
144 | { | ||
136 | KTYPE_STRING = 0, | 145 | KTYPE_STRING = 0, |
137 | KTYPE_TYPE, | 146 | KTYPE_TYPE, |
138 | KTYPE_NUM, | 147 | KTYPE_NUM, |
@@ -142,62 +151,63 @@ enum { | |||
142 | /** | 151 | /** |
143 | * @brief linked list of pages in the search notebook | 152 | * @brief linked list of pages in the search notebook |
144 | */ | 153 | */ |
145 | typedef struct SL { | 154 | typedef struct SL |
146 | struct SL * next; | 155 | { |
156 | struct SL *next; | ||
147 | /** | 157 | /** |
148 | * Reference to the glade XML context that was | 158 | * Reference to the glade XML context that was |
149 | * used to create the search page. | 159 | * used to create the search page. |
150 | */ | 160 | */ |
151 | GladeXML * searchXML; | 161 | GladeXML *searchXML; |
152 | 162 | ||
153 | /** | 163 | /** |
154 | * Reference to the glade XML context that was | 164 | * Reference to the glade XML context that was |
155 | * used to create the search label. | 165 | * used to create the search label. |
156 | */ | 166 | */ |
157 | GladeXML * labelXML; | 167 | GladeXML *labelXML; |
158 | 168 | ||
159 | /** | 169 | /** |
160 | * Tree view widget that is used to display the | 170 | * Tree view widget that is used to display the |
161 | * search results. | 171 | * search results. |
162 | */ | 172 | */ |
163 | GtkTreeView * treeview; | 173 | GtkTreeView *treeview; |
164 | 174 | ||
165 | /** | 175 | /** |
166 | * Model of the tree view. | 176 | * Model of the tree view. |
167 | */ | 177 | */ |
168 | GtkTreeStore * tree; | 178 | GtkTreeStore *tree; |
169 | 179 | ||
170 | /** | 180 | /** |
171 | * The label used in the notebook page. | 181 | * The label used in the notebook page. |
172 | */ | 182 | */ |
173 | GtkWidget * tab_label; | 183 | GtkWidget *tab_label; |
174 | 184 | ||
175 | /** | 185 | /** |
176 | * The notebook page that is associated with this | 186 | * The notebook page that is associated with this |
177 | * search. | 187 | * search. |
178 | */ | 188 | */ |
179 | GtkWidget * searchpage; | 189 | GtkWidget *searchpage; |
180 | 190 | ||
181 | /** | 191 | /** |
182 | * Path to the entry in the summary list | 192 | * Path to the entry in the summary list |
183 | * for this search. | 193 | * for this search. |
184 | */ | 194 | */ |
185 | GtkTreeRowReference * summaryViewRowReference; | 195 | GtkTreeRowReference *summaryViewRowReference; |
186 | 196 | ||
187 | /** | 197 | /** |
188 | * URI for this search. | 198 | * URI for this search. |
189 | */ | 199 | */ |
190 | struct ECRS_URI * uri; | 200 | struct ECRS_URI *uri; |
191 | 201 | ||
192 | /** | 202 | /** |
193 | * String describing the search. | 203 | * String describing the search. |
194 | */ | 204 | */ |
195 | char * searchString; | 205 | char *searchString; |
196 | 206 | ||
197 | /** | 207 | /** |
198 | * FSUI search handle. | 208 | * FSUI search handle. |
199 | */ | 209 | */ |
200 | struct FSUI_SearchList * fsui_list; | 210 | struct FSUI_SearchList *fsui_list; |
201 | 211 | ||
202 | /** | 212 | /** |
203 | * Number of results received so far. | 213 | * Number of results received so far. |
@@ -217,29 +227,30 @@ typedef struct SL { | |||
217 | } SearchList; | 227 | } SearchList; |
218 | 228 | ||
219 | 229 | ||
220 | typedef struct DL { | 230 | typedef struct DL |
221 | struct DL * next; | 231 | { |
232 | struct DL *next; | ||
222 | 233 | ||
223 | /** | 234 | /** |
224 | * URI of the download. | 235 | * URI of the download. |
225 | */ | 236 | */ |
226 | struct ECRS_URI * uri; | 237 | struct ECRS_URI *uri; |
227 | 238 | ||
228 | /** | 239 | /** |
229 | * Where is the download being saved to? | 240 | * Where is the download being saved to? |
230 | */ | 241 | */ |
231 | char * filename; | 242 | char *filename; |
232 | 243 | ||
233 | /** | 244 | /** |
234 | * Path in the summary view for this download. | 245 | * Path in the summary view for this download. |
235 | */ | 246 | */ |
236 | GtkTreeRowReference * summaryViewRowReference; | 247 | GtkTreeRowReference *summaryViewRowReference; |
237 | 248 | ||
238 | /** | 249 | /** |
239 | * Search that this download belongs to. | 250 | * Search that this download belongs to. |
240 | * Maybe NULL. | 251 | * Maybe NULL. |
241 | */ | 252 | */ |
242 | struct SL * searchList; | 253 | struct SL *searchList; |
243 | 254 | ||
244 | /** | 255 | /** |
245 | * Path in the search view that this | 256 | * Path in the search view that this |
@@ -247,12 +258,12 @@ typedef struct DL { | |||
247 | * if search has been closed or if download | 258 | * if search has been closed or if download |
248 | * was initiated from URI without search. | 259 | * was initiated from URI without search. |
249 | */ | 260 | */ |
250 | GtkTreeRowReference * searchViewRowReference; | 261 | GtkTreeRowReference *searchViewRowReference; |
251 | 262 | ||
252 | /** | 263 | /** |
253 | * FSUI reference for the download. | 264 | * FSUI reference for the download. |
254 | */ | 265 | */ |
255 | struct FSUI_DownloadList * fsui_list; | 266 | struct FSUI_DownloadList *fsui_list; |
256 | 267 | ||
257 | /** | 268 | /** |
258 | * Total size of the download. | 269 | * Total size of the download. |
@@ -268,25 +279,26 @@ typedef struct DL { | |||
268 | 279 | ||
269 | } DownloadList; | 280 | } DownloadList; |
270 | 281 | ||
271 | typedef struct UL { | 282 | typedef struct UL |
272 | struct UL * next; | 283 | { |
284 | struct UL *next; | ||
273 | 285 | ||
274 | /** | 286 | /** |
275 | * Which file or directory are we uploading? | 287 | * Which file or directory are we uploading? |
276 | */ | 288 | */ |
277 | char * filename; | 289 | char *filename; |
278 | 290 | ||
279 | /** | 291 | /** |
280 | * Path in the summary view for this download. | 292 | * Path in the summary view for this download. |
281 | */ | 293 | */ |
282 | GtkTreeRowReference * summaryViewRowReference; | 294 | GtkTreeRowReference *summaryViewRowReference; |
283 | 295 | ||
284 | struct FSUI_UploadList * fsui_list; | 296 | struct FSUI_UploadList *fsui_list; |
285 | 297 | ||
286 | /** | 298 | /** |
287 | * Set to final URI upon successful completion. | 299 | * Set to final URI upon successful completion. |
288 | */ | 300 | */ |
289 | struct ECRS_URI * uri; | 301 | struct ECRS_URI *uri; |
290 | 302 | ||
291 | /** | 303 | /** |
292 | * Total size of the upload. | 304 | * Total size of the upload. |
@@ -299,25 +311,25 @@ typedef struct UL { | |||
299 | 311 | ||
300 | } UploadList; | 312 | } UploadList; |
301 | 313 | ||
302 | extern struct FSUI_Context * ctx; | 314 | extern struct FSUI_Context *ctx; |
303 | 315 | ||
304 | extern struct GE_Context * ectx; | 316 | extern struct GE_Context *ectx; |
305 | 317 | ||
306 | extern struct GC_Configuration * cfg; | 318 | extern struct GC_Configuration *cfg; |
307 | 319 | ||
308 | extern SearchList * search_head; | 320 | extern SearchList *search_head; |
309 | 321 | ||
310 | extern DownloadList * download_head; | 322 | extern DownloadList *download_head; |
311 | 323 | ||
312 | extern UploadList * upload_head; | 324 | extern UploadList *upload_head; |
313 | 325 | ||
314 | extern GtkListStore * search_summary; | 326 | extern GtkListStore *search_summary; |
315 | 327 | ||
316 | extern GtkTreeStore * download_summary; | 328 | extern GtkTreeStore *download_summary; |
317 | 329 | ||
318 | extern GtkTreeStore * upload_summary; | 330 | extern GtkTreeStore *upload_summary; |
319 | 331 | ||
320 | const char * getColorCode(enum URITRACK_STATE state); | 332 | const char *getColorCode (enum URITRACK_STATE state); |
321 | 333 | ||
322 | 334 | ||
323 | #endif | 335 | #endif |
diff --git a/src/plugins/fs/helper.c b/src/plugins/fs/helper.c index f371505e..a0957628 100644 --- a/src/plugins/fs/helper.c +++ b/src/plugins/fs/helper.c | |||
@@ -37,91 +37,64 @@ | |||
37 | * @param val set to the computed time | 37 | * @param val set to the computed time |
38 | * @return OK on success, SYSERR on error | 38 | * @return OK on success, SYSERR on error |
39 | */ | 39 | */ |
40 | int parseTime(const char * t, | 40 | int |
41 | TIME_T * param) { | 41 | parseTime (const char *t, TIME_T * param) |
42 | { | ||
42 | int pos; | 43 | int pos; |
43 | int start; | 44 | int start; |
44 | unsigned int val; | 45 | unsigned int val; |
45 | char * tmp; | 46 | char *tmp; |
46 | cron_t ret; | 47 | cron_t ret; |
47 | 48 | ||
48 | ret = 0; | 49 | ret = 0; |
49 | pos = 0; | 50 | pos = 0; |
50 | 51 | ||
51 | while (t[pos] != '\0') { | 52 | while (t[pos] != '\0') |
52 | start = pos; | 53 | { |
53 | while ( (isdigit(t[pos])) && | 54 | start = pos; |
54 | (t[pos] != '\0') ) | 55 | while ((isdigit (t[pos])) && (t[pos] != '\0')) |
55 | pos++; | 56 | pos++; |
56 | tmp = STRNDUP(&t[start], | 57 | tmp = STRNDUP (&t[start], pos - start); |
57 | pos - start); | 58 | if (1 != sscanf (tmp, "%u", &val)) |
58 | if (1 != sscanf(tmp, | 59 | return -1; /* parse error */ |
59 | "%u", | 60 | FREE (tmp); |
60 | &val) ) | 61 | while (t[pos] == ' ') |
61 | return -1; /* parse error */ | 62 | pos++; |
62 | FREE(tmp); | 63 | start = pos; |
63 | while ( t[pos] == ' ') | 64 | while ((t[pos] != ' ') && (t[pos] != '\0')) |
64 | pos++; | 65 | pos++; |
65 | start = pos; | 66 | if (0 == strncasecmp (&t[start], _("ms"), strlen (_("ms")))) |
66 | while ( (t[pos] != ' ') && | 67 | ret += cronMILLIS * val; |
67 | (t[pos] != '\0') ) | 68 | if (0 == strncasecmp (&t[start], _("minutes"), strlen (_("minutes")))) |
68 | pos++; | 69 | ret += cronMINUTES * val; |
69 | if (0 == strncasecmp(&t[start], | 70 | else if (0 == strncasecmp (&t[start], |
70 | _("ms"), | 71 | _("seconds"), strlen (_("seconds")))) |
71 | strlen(_("ms")))) | 72 | ret += cronSECONDS * val; |
72 | ret += cronMILLIS * val; | 73 | else if (0 == strncasecmp (&t[start], _("hours"), strlen (_("hours")))) |
73 | if (0 == strncasecmp(&t[start], | 74 | ret += cronHOURS * val; |
74 | _("minutes"), | 75 | else if (0 == strncasecmp (&t[start], _("days"), strlen (_("days")))) |
75 | strlen(_("minutes")))) | 76 | ret += cronDAYS * val; |
76 | ret += cronMINUTES * val; | 77 | else |
77 | else if (0 == strncasecmp(&t[start], | 78 | if (0 == strncasecmp (&t[start], _("minute"), strlen (_("minute")))) |
78 | _("seconds"), | 79 | ret += cronMINUTES * val; |
79 | strlen(_("seconds")))) | 80 | else if (0 == strncasecmp (&t[start], |
80 | ret += cronSECONDS * val; | 81 | _("second"), strlen (_("second")))) |
81 | else if (0 == strncasecmp(&t[start], | 82 | ret += cronSECONDS * val; |
82 | _("hours"), | 83 | else if (0 == strncasecmp (&t[start], _("hour"), strlen (_("hour")))) |
83 | strlen(_("hours")))) | 84 | ret += cronHOURS * val; |
84 | ret += cronHOURS * val; | 85 | else if (0 == strncasecmp (&t[start], _("day"), strlen (_("day")))) |
85 | else if (0 == strncasecmp(&t[start], | 86 | ret += cronDAYS * val; |
86 | _("days"), | 87 | else if (0 == strncasecmp (&t[start], "m", strlen ("m"))) |
87 | strlen(_("days")))) | 88 | ret += cronMINUTES * val; |
88 | ret += cronDAYS * val; | 89 | else if (0 == strncasecmp (&t[start], "s", strlen ("s"))) |
89 | else | 90 | ret += cronSECONDS * val; |
90 | if (0 == strncasecmp(&t[start], | 91 | else if (0 == strncasecmp (&t[start], "h", strlen ("h"))) |
91 | _("minute"), | 92 | ret += cronHOURS * val; |
92 | strlen(_("minute")))) | 93 | else |
93 | ret += cronMINUTES * val; | 94 | return SYSERR; /* parse error */ |
94 | else if (0 == strncasecmp(&t[start], | 95 | while (t[pos] == ' ') |
95 | _("second"), | 96 | pos++; |
96 | strlen(_("second")))) | 97 | } |
97 | ret += cronSECONDS * val; | ||
98 | else if (0 == strncasecmp(&t[start], | ||
99 | _("hour"), | ||
100 | strlen(_("hour")))) | ||
101 | ret += cronHOURS * val; | ||
102 | else if (0 == strncasecmp(&t[start], | ||
103 | _("day"), | ||
104 | strlen(_("day")))) | ||
105 | ret += cronDAYS * val; | ||
106 | else if (0 == strncasecmp(&t[start], | ||
107 | "m", | ||
108 | strlen("m"))) | ||
109 | ret += cronMINUTES * val; | ||
110 | else if (0 == strncasecmp(&t[start], | ||
111 | "s", | ||
112 | strlen("s"))) | ||
113 | ret += cronSECONDS * val; | ||
114 | else if (0 == strncasecmp(&t[start], | ||
115 | "h", | ||
116 | strlen("h"))) | ||
117 | ret += cronHOURS * val; | ||
118 | else | ||
119 | return SYSERR; /* parse error */ | ||
120 | while ( t[pos] == ' ') | ||
121 | pos++; | ||
122 | } | ||
123 | *param = ret / cronSECONDS; | 98 | *param = ret / cronSECONDS; |
124 | return OK; | 99 | return OK; |
125 | } | 100 | } |
126 | |||
127 | |||
diff --git a/src/plugins/fs/helper.h b/src/plugins/fs/helper.h index f91940a8..9fa44a69 100644 --- a/src/plugins/fs/helper.h +++ b/src/plugins/fs/helper.h | |||
@@ -35,15 +35,12 @@ | |||
35 | * @param the title of the new label | 35 | * @param the title of the new label |
36 | * @returns the created widget to pack into the page header | 36 | * @returns the created widget to pack into the page header |
37 | */ | 37 | */ |
38 | GtkWidget * | 38 | GtkWidget *buildSearchTabLabel (GtkWidget * searchPage, const char *title); |
39 | buildSearchTabLabel(GtkWidget *searchPage, | ||
40 | const char *title); | ||
41 | 39 | ||
42 | 40 | ||
43 | GtkWidget * | 41 | GtkWidget *makeSearchResultFrame (struct GC_Configuration *cfg, |
44 | makeSearchResultFrame(struct GC_Configuration * cfg, | 42 | GtkWidget ** treeview, |
45 | GtkWidget ** treeview, | 43 | GtkWidget ** anonSpin); |
46 | GtkWidget ** anonSpin); | ||
47 | 44 | ||
48 | /** | 45 | /** |
49 | * Parse a time given in the form | 46 | * Parse a time given in the form |
@@ -52,7 +49,6 @@ makeSearchResultFrame(struct GC_Configuration * cfg, | |||
52 | * @param val set to the computed time | 49 | * @param val set to the computed time |
53 | * @return OK on success, SYSERR on error | 50 | * @return OK on success, SYSERR on error |
54 | */ | 51 | */ |
55 | int parseTime(const char * t, | 52 | int parseTime (const char *t, TIME_T * val); |
56 | TIME_T * val); | ||
57 | 53 | ||
58 | #endif | 54 | #endif |
diff --git a/src/plugins/fs/meta.c b/src/plugins/fs/meta.c index c1665251..b5861ebf 100644 --- a/src/plugins/fs/meta.c +++ b/src/plugins/fs/meta.c | |||
@@ -31,602 +31,541 @@ | |||
31 | #include "fs.h" | 31 | #include "fs.h" |
32 | #include <extractor.h> | 32 | #include <extractor.h> |
33 | 33 | ||
34 | static int publishMetaData(EXTRACTOR_KeywordType type, | 34 | static int |
35 | const char * data, | 35 | publishMetaData (EXTRACTOR_KeywordType type, const char *data, void *cls) |
36 | void * cls) { | 36 | { |
37 | GtkListStore * store = cls; | 37 | GtkListStore *store = cls; |
38 | const char * stype; | 38 | const char *stype; |
39 | GtkTreeIter iter; | 39 | GtkTreeIter iter; |
40 | 40 | ||
41 | stype = EXTRACTOR_getKeywordTypeAsString(type); | 41 | stype = EXTRACTOR_getKeywordTypeAsString (type); |
42 | if (stype == NULL) /* wrong LE version!? */ | 42 | if (stype == NULL) /* wrong LE version!? */ |
43 | stype = _("unknown"); | 43 | stype = _("unknown"); |
44 | gtk_list_store_append(store, | 44 | gtk_list_store_append (store, &iter); |
45 | &iter); | 45 | gtk_list_store_set (store, |
46 | gtk_list_store_set(store, | 46 | &iter, |
47 | &iter, | 47 | META_TYPE, type, |
48 | META_TYPE, type, | 48 | META_STYPE, stype, META_VALUE, data, -1); |
49 | META_STYPE, stype, | ||
50 | META_VALUE, data, | ||
51 | -1); | ||
52 | return OK; | 49 | return OK; |
53 | } | 50 | } |
54 | 51 | ||
55 | void createMetaDataListTreeView(GladeXML * xml, | 52 | void |
56 | const char * name, | 53 | createMetaDataListTreeView (GladeXML * xml, |
57 | const char * previewName, | 54 | const char *name, |
58 | const struct ECRS_MetaData * init) { | 55 | const char *previewName, |
59 | GtkTreeView * metaList; | 56 | const struct ECRS_MetaData *init) |
60 | GtkListStore * metamodel; | 57 | { |
61 | GtkCellRenderer * renderer; | 58 | GtkTreeView *metaList; |
62 | GtkWidget * preview; | 59 | GtkListStore *metamodel; |
63 | GdkPixbuf * pixbuf; | 60 | GtkCellRenderer *renderer; |
64 | GdkPixbufLoader * loader; | 61 | GtkWidget *preview; |
65 | unsigned char * thumb; | 62 | GdkPixbuf *pixbuf; |
63 | GdkPixbufLoader *loader; | ||
64 | unsigned char *thumb; | ||
66 | size_t ts; | 65 | size_t ts; |
67 | GtkTreeViewColumn * column; | 66 | GtkTreeViewColumn *column; |
68 | int col; | 67 | int col; |
69 | 68 | ||
70 | DEBUG_BEGIN(); | 69 | DEBUG_BEGIN (); |
71 | metamodel | 70 | metamodel |
72 | = gtk_list_store_new(META_NUM, | 71 | = gtk_list_store_new (META_NUM, G_TYPE_INT, G_TYPE_STRING, G_TYPE_STRING); |
73 | G_TYPE_INT, | 72 | metaList = GTK_TREE_VIEW (glade_xml_get_widget (xml, name)); |
74 | G_TYPE_STRING, | 73 | gtk_tree_selection_set_mode (gtk_tree_view_get_selection (metaList), |
75 | G_TYPE_STRING); | 74 | GTK_SELECTION_MULTIPLE); |
76 | metaList = GTK_TREE_VIEW(glade_xml_get_widget(xml, | 75 | renderer = gtk_cell_renderer_text_new (); |
77 | name)); | 76 | col = gtk_tree_view_insert_column_with_attributes (metaList, |
78 | gtk_tree_selection_set_mode(gtk_tree_view_get_selection(metaList), | 77 | -1, |
79 | GTK_SELECTION_MULTIPLE); | 78 | _("Category"), |
80 | renderer = gtk_cell_renderer_text_new(); | 79 | renderer, |
81 | col = gtk_tree_view_insert_column_with_attributes(metaList, | 80 | "text", META_STYPE, |
82 | -1, | 81 | NULL); |
83 | _("Category"), | 82 | column = gtk_tree_view_get_column (metaList, col - 1); |
84 | renderer, | 83 | gtk_tree_view_column_set_resizable (column, TRUE); |
85 | "text", META_STYPE, | 84 | gtk_tree_view_column_set_clickable (column, TRUE); |
86 | NULL); | 85 | gtk_tree_view_column_set_reorderable (column, TRUE); |
87 | column = gtk_tree_view_get_column(metaList, | 86 | gtk_tree_view_column_set_sort_column_id (column, META_STYPE); |
88 | col - 1); | 87 | renderer = gtk_cell_renderer_text_new (); |
89 | gtk_tree_view_column_set_resizable(column, TRUE); | 88 | col = gtk_tree_view_insert_column_with_attributes (metaList, |
90 | gtk_tree_view_column_set_clickable(column, TRUE); | 89 | -1, |
91 | gtk_tree_view_column_set_reorderable(column, TRUE); | 90 | _("Value"), |
92 | gtk_tree_view_column_set_sort_column_id(column, META_STYPE); | 91 | renderer, |
93 | renderer = gtk_cell_renderer_text_new(); | 92 | "text", META_VALUE, |
94 | col = gtk_tree_view_insert_column_with_attributes(metaList, | 93 | NULL); |
95 | -1, | 94 | column = gtk_tree_view_get_column (metaList, col - 1); |
96 | _("Value"), | 95 | gtk_tree_view_column_set_resizable (column, TRUE); |
97 | renderer, | 96 | gtk_tree_view_column_set_clickable (column, TRUE); |
98 | "text", META_VALUE, | 97 | gtk_tree_view_column_set_reorderable (column, TRUE); |
99 | NULL); | 98 | gtk_tree_view_column_set_sort_column_id (column, META_VALUE); |
100 | column = gtk_tree_view_get_column(metaList, | 99 | gtk_tree_view_set_model (metaList, GTK_TREE_MODEL (metamodel)); |
101 | col - 1); | ||
102 | gtk_tree_view_column_set_resizable(column, TRUE); | ||
103 | gtk_tree_view_column_set_clickable(column, TRUE); | ||
104 | gtk_tree_view_column_set_reorderable(column, TRUE); | ||
105 | gtk_tree_view_column_set_sort_column_id(column, META_VALUE); | ||
106 | gtk_tree_view_set_model(metaList, | ||
107 | GTK_TREE_MODEL(metamodel)); | ||
108 | 100 | ||
109 | if (init != NULL) | 101 | if (init != NULL) |
110 | ECRS_getMetaData(init, | 102 | ECRS_getMetaData (init, &publishMetaData, metamodel); |
111 | &publishMetaData, | 103 | if ((previewName == NULL) || (init == NULL)) |
112 | metamodel); | ||
113 | if ( (previewName == NULL) || | ||
114 | (init == NULL) ) | ||
115 | return; | 104 | return; |
116 | preview = glade_xml_get_widget(xml, | 105 | preview = glade_xml_get_widget (xml, previewName); |
117 | previewName); | ||
118 | 106 | ||
119 | thumb = NULL; | 107 | thumb = NULL; |
120 | ts = ECRS_getThumbnailFromMetaData(init, | 108 | ts = ECRS_getThumbnailFromMetaData (init, &thumb); |
121 | &thumb); | 109 | preview = glade_xml_get_widget (xml, previewName); |
122 | preview = glade_xml_get_widget(xml, | 110 | if (ts != 0) |
123 | previewName); | 111 | { |
124 | if (ts != 0) { | 112 | loader = gdk_pixbuf_loader_new (); |
125 | loader = gdk_pixbuf_loader_new(); | 113 | gdk_pixbuf_loader_write (loader, (const guchar *) thumb, ts, NULL); |
126 | gdk_pixbuf_loader_write(loader, | 114 | pixbuf = gdk_pixbuf_loader_get_pixbuf (loader); |
127 | (const guchar*) thumb, | 115 | g_object_ref (pixbuf); |
128 | ts, | 116 | gdk_pixbuf_loader_close (loader, NULL); |
129 | NULL); | 117 | if (pixbuf != NULL) |
130 | pixbuf = gdk_pixbuf_loader_get_pixbuf(loader); | 118 | { |
131 | g_object_ref(pixbuf); | 119 | gtk_image_set_from_pixbuf (GTK_IMAGE (preview), pixbuf); |
132 | gdk_pixbuf_loader_close(loader, | 120 | g_object_unref (pixbuf); |
133 | NULL); | 121 | } |
134 | if (pixbuf != NULL) { | 122 | UNREF (loader); |
135 | gtk_image_set_from_pixbuf(GTK_IMAGE(preview), | ||
136 | pixbuf); | ||
137 | g_object_unref(pixbuf); | ||
138 | } | 123 | } |
139 | UNREF(loader); | 124 | DEBUG_END (); |
140 | } | ||
141 | DEBUG_END(); | ||
142 | } | 125 | } |
143 | 126 | ||
144 | static int publishKeyword(const char * data, | 127 | static int |
145 | void * cls) { | 128 | publishKeyword (const char *data, void *cls) |
146 | GtkListStore * store = cls; | 129 | { |
130 | GtkListStore *store = cls; | ||
147 | GtkTreeIter iter; | 131 | GtkTreeIter iter; |
148 | 132 | ||
149 | DEBUG_BEGIN(); | 133 | DEBUG_BEGIN (); |
150 | gtk_list_store_append(store, | 134 | gtk_list_store_append (store, &iter); |
151 | &iter); | 135 | gtk_list_store_set (store, &iter, 0, data, -1); |
152 | gtk_list_store_set(store, | 136 | DEBUG_END (); |
153 | &iter, | ||
154 | 0, data, | ||
155 | -1); | ||
156 | DEBUG_END(); | ||
157 | return OK; | 137 | return OK; |
158 | } | 138 | } |
159 | 139 | ||
160 | void createKeywordListTreeView(GladeXML * xml, | 140 | void |
161 | const char * name, | 141 | createKeywordListTreeView (GladeXML * xml, |
162 | const struct ECRS_URI * init) { | 142 | const char *name, const struct ECRS_URI *init) |
163 | GtkTreeView * keywordList; | 143 | { |
164 | GtkListStore * keymodel; | 144 | GtkTreeView *keywordList; |
165 | GtkCellRenderer * renderer; | 145 | GtkListStore *keymodel; |
166 | GtkTreeViewColumn * column; | 146 | GtkCellRenderer *renderer; |
167 | 147 | GtkTreeViewColumn *column; | |
168 | DEBUG_BEGIN(); | 148 | |
169 | keymodel | 149 | DEBUG_BEGIN (); |
170 | = gtk_list_store_new(1, | 150 | keymodel = gtk_list_store_new (1, G_TYPE_STRING); |
171 | G_TYPE_STRING); | 151 | keywordList = GTK_TREE_VIEW (glade_xml_get_widget (xml, name)); |
172 | keywordList = GTK_TREE_VIEW(glade_xml_get_widget(xml, | 152 | gtk_tree_selection_set_mode (gtk_tree_view_get_selection (keywordList), |
173 | name)); | 153 | GTK_SELECTION_MULTIPLE); |
174 | gtk_tree_selection_set_mode(gtk_tree_view_get_selection(keywordList), | 154 | renderer = gtk_cell_renderer_text_new (); |
175 | GTK_SELECTION_MULTIPLE); | 155 | gtk_tree_view_insert_column_with_attributes (keywordList, |
176 | renderer = gtk_cell_renderer_text_new(); | 156 | -1, |
177 | gtk_tree_view_insert_column_with_attributes(keywordList, | 157 | _("Keyword"), |
178 | -1, | 158 | renderer, "text", 0, NULL); |
179 | _("Keyword"), | 159 | column = gtk_tree_view_get_column (keywordList, 0); |
180 | renderer, | 160 | gtk_tree_view_column_set_resizable (column, TRUE); |
181 | "text", 0, | 161 | gtk_tree_view_column_set_clickable (column, TRUE); |
182 | NULL); | 162 | gtk_tree_view_column_set_reorderable (column, TRUE); |
183 | column = gtk_tree_view_get_column(keywordList, | 163 | gtk_tree_view_column_set_sort_column_id (column, 0); |
184 | 0); | 164 | gtk_tree_view_set_model (keywordList, GTK_TREE_MODEL (keymodel)); |
185 | gtk_tree_view_column_set_resizable(column, TRUE); | ||
186 | gtk_tree_view_column_set_clickable(column, TRUE); | ||
187 | gtk_tree_view_column_set_reorderable(column, TRUE); | ||
188 | gtk_tree_view_column_set_sort_column_id(column, 0); | ||
189 | gtk_tree_view_set_model(keywordList, | ||
190 | GTK_TREE_MODEL(keymodel)); | ||
191 | if (init != NULL) | 165 | if (init != NULL) |
192 | ECRS_getKeywordsFromUri(init, | 166 | ECRS_getKeywordsFromUri (init, &publishKeyword, keymodel); |
193 | &publishKeyword, | 167 | DEBUG_END (); |
194 | keymodel); | ||
195 | DEBUG_END(); | ||
196 | } | 168 | } |
197 | 169 | ||
198 | void createMetaTypeComboBox(GladeXML * xml, | 170 | void |
199 | const char * name) { | 171 | createMetaTypeComboBox (GladeXML * xml, const char *name) |
200 | const char * stype; | 172 | { |
201 | GtkWidget * metaType; | 173 | const char *stype; |
202 | GtkCellRenderer * renderer; | 174 | GtkWidget *metaType; |
203 | GtkListStore * keywordTypeModel; | 175 | GtkCellRenderer *renderer; |
176 | GtkListStore *keywordTypeModel; | ||
204 | GtkTreeIter iter; | 177 | GtkTreeIter iter; |
205 | EXTRACTOR_KeywordType type; | 178 | EXTRACTOR_KeywordType type; |
206 | 179 | ||
207 | DEBUG_BEGIN(); | 180 | DEBUG_BEGIN (); |
208 | keywordTypeModel | 181 | keywordTypeModel |
209 | = gtk_list_store_new(KTYPE_NUM, | 182 | = gtk_list_store_new (KTYPE_NUM, G_TYPE_STRING, G_TYPE_INT); |
210 | G_TYPE_STRING, | 183 | metaType = glade_xml_get_widget (xml, name); |
211 | G_TYPE_INT); | 184 | gtk_combo_box_set_model (GTK_COMBO_BOX (metaType), |
212 | metaType = glade_xml_get_widget(xml, | 185 | GTK_TREE_MODEL (keywordTypeModel)); |
213 | name); | 186 | for (type = 0; type < EXTRACTOR_getHighestKeywordTypeNumber (); type++) |
214 | gtk_combo_box_set_model(GTK_COMBO_BOX(metaType), | 187 | { |
215 | GTK_TREE_MODEL(keywordTypeModel)); | 188 | stype = EXTRACTOR_getKeywordTypeAsString (type); |
216 | for (type=0;type<EXTRACTOR_getHighestKeywordTypeNumber();type++) { | 189 | gtk_list_store_append (keywordTypeModel, &iter); |
217 | stype = EXTRACTOR_getKeywordTypeAsString(type); | 190 | gtk_list_store_set (keywordTypeModel, |
218 | gtk_list_store_append(keywordTypeModel, | 191 | &iter, KTYPE_STRING, stype, KTYPE_TYPE, type, -1); |
219 | &iter); | 192 | } |
220 | gtk_list_store_set(keywordTypeModel, | 193 | renderer = gtk_cell_renderer_text_new (); |
221 | &iter, | 194 | gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (metaType), renderer, FALSE); |
222 | KTYPE_STRING, stype, | 195 | gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (metaType), |
223 | KTYPE_TYPE, type, | 196 | renderer, "text", KTYPE_STRING); |
224 | -1); | 197 | gtk_combo_box_set_active (GTK_COMBO_BOX (metaType), 0); |
225 | } | 198 | DEBUG_END (); |
226 | renderer = gtk_cell_renderer_text_new(); | ||
227 | gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(metaType), | ||
228 | renderer, | ||
229 | FALSE); | ||
230 | gtk_cell_layout_add_attribute(GTK_CELL_LAYOUT(metaType), | ||
231 | renderer, | ||
232 | "text", KTYPE_STRING); | ||
233 | gtk_combo_box_set_active(GTK_COMBO_BOX(metaType), | ||
234 | 0); | ||
235 | DEBUG_END(); | ||
236 | } | 199 | } |
237 | 200 | ||
238 | void handleKeywordListUpdate(GladeXML * xml, | 201 | void |
239 | const char * inputLineName, | 202 | handleKeywordListUpdate (GladeXML * xml, |
240 | const char * keywordListName) { | 203 | const char *inputLineName, |
241 | const char * keyword; | 204 | const char *keywordListName) |
242 | GtkWidget * keywordList; | 205 | { |
243 | GtkWidget * entryLine; | 206 | const char *keyword; |
244 | GtkListStore * keymodel; | 207 | GtkWidget *keywordList; |
208 | GtkWidget *entryLine; | ||
209 | GtkListStore *keymodel; | ||
245 | GtkTreeIter iter; | 210 | GtkTreeIter iter; |
246 | 211 | ||
247 | DEBUG_BEGIN(); | 212 | DEBUG_BEGIN (); |
248 | keywordList = glade_xml_get_widget(xml, | 213 | keywordList = glade_xml_get_widget (xml, keywordListName); |
249 | keywordListName); | ||
250 | keymodel | 214 | keymodel |
251 | = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(keywordList))); | 215 | = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (keywordList))); |
252 | 216 | ||
253 | entryLine = glade_xml_get_widget(xml, | 217 | entryLine = glade_xml_get_widget (xml, inputLineName); |
254 | inputLineName); | 218 | keyword = gtk_entry_get_text (GTK_ENTRY (entryLine)); |
255 | keyword = gtk_entry_get_text(GTK_ENTRY(entryLine)); | 219 | gtk_list_store_append (keymodel, &iter); |
256 | gtk_list_store_append(keymodel, | 220 | gtk_list_store_set (keymodel, &iter, 0, keyword, -1); |
257 | &iter); | 221 | gtk_entry_set_text (GTK_ENTRY (entryLine), ""); |
258 | gtk_list_store_set(keymodel, | 222 | DEBUG_END (); |
259 | &iter, | ||
260 | 0, keyword, | ||
261 | -1); | ||
262 | gtk_entry_set_text(GTK_ENTRY(entryLine), ""); | ||
263 | DEBUG_END(); | ||
264 | } | 223 | } |
265 | 224 | ||
266 | void handleMetaDataListUpdate(GladeXML * xml, | 225 | void |
267 | const char * typeInputLineName, | 226 | handleMetaDataListUpdate (GladeXML * xml, |
268 | const char * valueInputLineName, | 227 | const char *typeInputLineName, |
269 | const char * metaDataListName) { | 228 | const char *valueInputLineName, |
270 | const char * value; | 229 | const char *metaDataListName) |
271 | GtkWidget * metaList; | 230 | { |
272 | GtkWidget * entryLine; | 231 | const char *value; |
273 | GtkWidget * typeCB; | 232 | GtkWidget *metaList; |
233 | GtkWidget *entryLine; | ||
234 | GtkWidget *typeCB; | ||
274 | EXTRACTOR_KeywordType type; | 235 | EXTRACTOR_KeywordType type; |
275 | GtkListStore * metamodel; | 236 | GtkListStore *metamodel; |
276 | GtkListStore * typemodel; | 237 | GtkListStore *typemodel; |
277 | GtkTreeIter iter; | 238 | GtkTreeIter iter; |
278 | char * stype; | 239 | char *stype; |
279 | 240 | ||
280 | DEBUG_BEGIN(); | 241 | DEBUG_BEGIN (); |
281 | metaList = glade_xml_get_widget(xml, | 242 | metaList = glade_xml_get_widget (xml, metaDataListName); |
282 | metaDataListName); | ||
283 | metamodel | 243 | metamodel |
284 | = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(metaList))); | 244 | = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (metaList))); |
285 | 245 | ||
286 | entryLine = glade_xml_get_widget(xml, | 246 | entryLine = glade_xml_get_widget (xml, valueInputLineName); |
287 | valueInputLineName); | 247 | value = gtk_entry_get_text (GTK_ENTRY (entryLine)); |
288 | value = gtk_entry_get_text(GTK_ENTRY(entryLine)); | 248 | if ((value == NULL) || (strlen (value) == 0)) |
289 | if ( (value == NULL) || (strlen(value) == 0) ) | ||
290 | return; | 249 | return; |
291 | typeCB = glade_xml_get_widget(xml, | 250 | typeCB = glade_xml_get_widget (xml, typeInputLineName); |
292 | typeInputLineName); | ||
293 | typemodel | 251 | typemodel |
294 | = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(typeCB))); | 252 | = GTK_LIST_STORE (gtk_combo_box_get_model (GTK_COMBO_BOX (typeCB))); |
295 | if (! gtk_combo_box_get_active_iter(GTK_COMBO_BOX(typeCB), | 253 | if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (typeCB), &iter)) |
296 | &iter)) | 254 | return; /* oops */ |
297 | return; /* oops */ | 255 | gtk_tree_model_get (GTK_TREE_MODEL (typemodel), |
298 | gtk_tree_model_get(GTK_TREE_MODEL(typemodel), | 256 | &iter, KTYPE_STRING, &stype, KTYPE_TYPE, &type, -1); |
299 | &iter, | 257 | gtk_list_store_append (metamodel, &iter); |
300 | KTYPE_STRING, &stype, | 258 | gtk_list_store_set (metamodel, |
301 | KTYPE_TYPE, &type, | 259 | &iter, |
302 | -1); | 260 | META_TYPE, type, |
303 | gtk_list_store_append(metamodel, | 261 | META_STYPE, stype, META_VALUE, value, -1); |
304 | &iter); | 262 | gtk_entry_set_text (GTK_ENTRY (entryLine), ""); |
305 | gtk_list_store_set(metamodel, | 263 | FREENONNULL (stype); |
306 | &iter, | 264 | DEBUG_END (); |
307 | META_TYPE, type, | ||
308 | META_STYPE, stype, | ||
309 | META_VALUE, value, | ||
310 | -1); | ||
311 | gtk_entry_set_text(GTK_ENTRY(entryLine), ""); | ||
312 | FREENONNULL(stype); | ||
313 | DEBUG_END(); | ||
314 | } | 265 | } |
315 | 266 | ||
316 | static void removeRow(GtkTreeModel * model, | 267 | static void |
317 | GtkTreePath * path, | 268 | removeRow (GtkTreeModel * model, |
318 | GtkTreeIter * iter, | 269 | GtkTreePath * path, GtkTreeIter * iter, gpointer unused) |
319 | gpointer unused) { | 270 | { |
320 | gtk_list_store_remove(GTK_LIST_STORE(model), | 271 | gtk_list_store_remove (GTK_LIST_STORE (model), iter); |
321 | iter); | ||
322 | } | 272 | } |
323 | 273 | ||
324 | void handleListRemove(GladeXML * xml, | 274 | void |
325 | const char * listName) { | 275 | handleListRemove (GladeXML * xml, const char *listName) |
326 | GtkWidget * list; | 276 | { |
277 | GtkWidget *list; | ||
327 | 278 | ||
328 | list = glade_xml_get_widget(xml, | 279 | list = glade_xml_get_widget (xml, listName); |
329 | listName); | ||
330 | ggc_tree_selection_selected_foreach | 280 | ggc_tree_selection_selected_foreach |
331 | (gtk_tree_view_get_selection(GTK_TREE_VIEW(list)), | 281 | (gtk_tree_view_get_selection (GTK_TREE_VIEW (list)), &removeRow, NULL); |
332 | &removeRow, | ||
333 | NULL); | ||
334 | } | 282 | } |
335 | 283 | ||
336 | #define THUMBSIZE 128 | 284 | #define THUMBSIZE 128 |
337 | 285 | ||
338 | 286 | ||
339 | struct ECRS_MetaData * getMetaDataFromList(GladeXML * xml, | 287 | struct ECRS_MetaData * |
340 | const char * name, | 288 | getMetaDataFromList (GladeXML * xml, |
341 | const char * previewName) { | 289 | const char *name, const char *previewName) |
342 | GtkWidget * metaList; | 290 | { |
343 | GtkWidget * preview; | 291 | GtkWidget *metaList; |
344 | GtkTreeModel * metamodel; | 292 | GtkWidget *preview; |
293 | GtkTreeModel *metamodel; | ||
345 | GtkTreeIter iter; | 294 | GtkTreeIter iter; |
346 | struct ECRS_MetaData * meta; | 295 | struct ECRS_MetaData *meta; |
347 | EXTRACTOR_KeywordType type; | 296 | EXTRACTOR_KeywordType type; |
348 | GdkPixbuf * pixbuf; | 297 | GdkPixbuf *pixbuf; |
349 | GdkPixbuf * out; | 298 | GdkPixbuf *out; |
350 | char * mvalue; | 299 | char *mvalue; |
351 | size_t length; | 300 | size_t length; |
352 | unsigned long width; | 301 | unsigned long width; |
353 | unsigned long height; | 302 | unsigned long height; |
354 | char * thumb; | 303 | char *thumb; |
355 | 304 | ||
356 | metaList = glade_xml_get_widget(xml, | 305 | metaList = glade_xml_get_widget (xml, name); |
357 | name); | 306 | metamodel = gtk_tree_view_get_model (GTK_TREE_VIEW (metaList)); |
358 | metamodel = gtk_tree_view_get_model(GTK_TREE_VIEW(metaList)); | 307 | meta = ECRS_createMetaData (); |
359 | meta = ECRS_createMetaData(); | 308 | if (gtk_tree_model_get_iter_first (metamodel, &iter)) |
360 | if (gtk_tree_model_get_iter_first(metamodel, | 309 | { |
361 | &iter)) { | 310 | do |
362 | do { | 311 | { |
363 | gtk_tree_model_get(metamodel, | 312 | gtk_tree_model_get (metamodel, |
364 | &iter, | 313 | &iter, |
365 | META_TYPE, &type, | 314 | META_TYPE, &type, META_VALUE, &mvalue, -1); |
366 | META_VALUE, &mvalue, | 315 | ECRS_addToMetaData (meta, type, mvalue); |
367 | -1); | 316 | FREENONNULL (mvalue); |
368 | ECRS_addToMetaData(meta, | 317 | } |
369 | type, | 318 | while (gtk_tree_model_iter_next (metamodel, &iter)); |
370 | mvalue); | 319 | } |
371 | FREENONNULL(mvalue); | ||
372 | } while (gtk_tree_model_iter_next(metamodel, | ||
373 | &iter)); | ||
374 | } | ||
375 | if (previewName == NULL) | 320 | if (previewName == NULL) |
376 | return meta; | 321 | return meta; |
377 | 322 | ||
378 | preview = glade_xml_get_widget(xml, | 323 | preview = glade_xml_get_widget (xml, previewName); |
379 | previewName); | 324 | |
380 | 325 | if (GTK_IMAGE_PIXBUF == gtk_image_get_storage_type (GTK_IMAGE (preview))) | |
381 | if (GTK_IMAGE_PIXBUF == | 326 | { |
382 | gtk_image_get_storage_type(GTK_IMAGE(preview))) { | 327 | pixbuf = gtk_image_get_pixbuf (GTK_IMAGE (preview)); |
383 | pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(preview)); | 328 | if (pixbuf == NULL) |
384 | if (pixbuf == NULL) | 329 | return meta; |
385 | return meta; | 330 | height = gdk_pixbuf_get_height (pixbuf); |
386 | height = gdk_pixbuf_get_height(pixbuf); | 331 | width = gdk_pixbuf_get_width (pixbuf); |
387 | width = gdk_pixbuf_get_width(pixbuf); | 332 | if ((height > THUMBSIZE) || (width > THUMBSIZE)) |
388 | if ( (height > THUMBSIZE) || | 333 | { |
389 | (width > THUMBSIZE) ) { | 334 | if (height > THUMBSIZE) |
390 | if (height > THUMBSIZE) { | 335 | { |
391 | width = width * THUMBSIZE / height; | 336 | width = width * THUMBSIZE / height; |
392 | height = THUMBSIZE; | 337 | height = THUMBSIZE; |
393 | } | 338 | } |
394 | if (width > THUMBSIZE) { | 339 | if (width > THUMBSIZE) |
395 | height = height * THUMBSIZE / width; | 340 | { |
396 | width = THUMBSIZE; | 341 | height = height * THUMBSIZE / width; |
397 | } | 342 | width = THUMBSIZE; |
398 | out = gdk_pixbuf_scale_simple(pixbuf, | 343 | } |
399 | width, | 344 | out = gdk_pixbuf_scale_simple (pixbuf, |
400 | height, | 345 | width, height, GDK_INTERP_BILINEAR); |
401 | GDK_INTERP_BILINEAR); | 346 | g_object_unref (pixbuf); |
402 | g_object_unref(pixbuf); | 347 | pixbuf = out; |
403 | pixbuf = out; | 348 | } |
349 | if (pixbuf != NULL) | ||
350 | { | ||
351 | thumb = NULL; | ||
352 | if (gdk_pixbuf_save_to_buffer (pixbuf, | ||
353 | &thumb, &length, "png", NULL, NULL)) | ||
354 | { | ||
355 | char *binary; | ||
356 | |||
357 | binary = EXTRACTOR_binaryEncode ((const unsigned char *) thumb, | ||
358 | length); | ||
359 | free (thumb); | ||
360 | ECRS_addToMetaData (meta, EXTRACTOR_THUMBNAIL_DATA, binary); | ||
361 | FREE (binary); | ||
362 | } | ||
363 | } | ||
404 | } | 364 | } |
405 | if (pixbuf != NULL) { | ||
406 | thumb = NULL; | ||
407 | if (gdk_pixbuf_save_to_buffer(pixbuf, | ||
408 | &thumb, | ||
409 | &length, | ||
410 | "png", | ||
411 | NULL, | ||
412 | NULL)) { | ||
413 | char * binary; | ||
414 | |||
415 | binary = EXTRACTOR_binaryEncode((const unsigned char*)thumb, | ||
416 | length); | ||
417 | free(thumb); | ||
418 | ECRS_addToMetaData(meta, | ||
419 | EXTRACTOR_THUMBNAIL_DATA, | ||
420 | binary); | ||
421 | FREE(binary); | ||
422 | } | ||
423 | } | ||
424 | } | ||
425 | return meta; | 365 | return meta; |
426 | } | 366 | } |
427 | 367 | ||
428 | struct ECRS_URI * getKeywordURIFromList(GladeXML * xml, | 368 | struct ECRS_URI * |
429 | const char * name) { | 369 | getKeywordURIFromList (GladeXML * xml, const char *name) |
430 | GtkTreeModel * keymodel; | 370 | { |
431 | GtkTreeView * keyList; | 371 | GtkTreeModel *keymodel; |
372 | GtkTreeView *keyList; | ||
432 | GtkTreeIter iter; | 373 | GtkTreeIter iter; |
433 | struct ECRS_URI * keywordURI; | 374 | struct ECRS_URI *keywordURI; |
434 | char * mvalue; | 375 | char *mvalue; |
435 | char ** keywords; | 376 | char **keywords; |
436 | unsigned int kpos; | 377 | unsigned int kpos; |
437 | unsigned int ksize; | 378 | unsigned int ksize; |
438 | 379 | ||
439 | DEBUG_BEGIN(); | 380 | DEBUG_BEGIN (); |
440 | keyList = GTK_TREE_VIEW(glade_xml_get_widget(xml, | 381 | keyList = GTK_TREE_VIEW (glade_xml_get_widget (xml, name)); |
441 | name)); | 382 | keymodel = gtk_tree_view_get_model (keyList); |
442 | keymodel = gtk_tree_view_get_model(keyList); | ||
443 | 383 | ||
444 | keywords = NULL; | 384 | keywords = NULL; |
445 | ksize = 0; | 385 | ksize = 0; |
446 | GROW(keywords, | 386 | GROW (keywords, ksize, 64); |
447 | ksize, | ||
448 | 64); | ||
449 | kpos = 0; | 387 | kpos = 0; |
450 | if (gtk_tree_model_get_iter_first(keymodel, | 388 | if (gtk_tree_model_get_iter_first (keymodel, &iter)) |
451 | &iter)) { | 389 | { |
452 | do { | 390 | do |
453 | gtk_tree_model_get(keymodel, | 391 | { |
454 | &iter, | 392 | gtk_tree_model_get (keymodel, &iter, 0, &mvalue, -1); |
455 | 0, &mvalue, | 393 | keywords[kpos++] = mvalue; |
456 | -1); | 394 | if (kpos == ksize) |
457 | keywords[kpos++] = mvalue; | 395 | GROW (keywords, ksize, kpos * 2); |
458 | if (kpos == ksize) | 396 | } |
459 | GROW(keywords, | 397 | while (gtk_tree_model_iter_next (keymodel, &iter)); |
460 | ksize, | 398 | } |
461 | kpos*2); | ||
462 | } while (gtk_tree_model_iter_next(keymodel, | ||
463 | &iter)); | ||
464 | } | ||
465 | keywords[kpos] = NULL; | 399 | keywords[kpos] = NULL; |
466 | 400 | ||
467 | keywordURI = ECRS_keywordsToUri((const char**)keywords); | 401 | keywordURI = ECRS_keywordsToUri ((const char **) keywords); |
468 | while (kpos > 0) | 402 | while (kpos > 0) |
469 | FREE(keywords[--kpos]); | 403 | FREE (keywords[--kpos]); |
470 | GROW(keywords, | 404 | GROW (keywords, ksize, 0); |
471 | ksize, | 405 | DEBUG_END (); |
472 | 0); | ||
473 | DEBUG_END(); | ||
474 | return keywordURI; | 406 | return keywordURI; |
475 | } | 407 | } |
476 | 408 | ||
477 | char * updateIntervalToString(TIME_T interval) { | 409 | char * |
410 | updateIntervalToString (TIME_T interval) | ||
411 | { | ||
478 | if (interval == ECRS_SBLOCK_UPDATE_SPORADIC) | 412 | if (interval == ECRS_SBLOCK_UPDATE_SPORADIC) |
479 | return strdup(_("--sporadic update--")); | 413 | return strdup (_("--sporadic update--")); |
480 | if (interval == ECRS_SBLOCK_UPDATE_NONE) | 414 | if (interval == ECRS_SBLOCK_UPDATE_NONE) |
481 | return strdup(_("--no update--")); | 415 | return strdup (_("--no update--")); |
482 | return string_get_fancy_time_interval(interval * cronSECONDS); | 416 | return string_get_fancy_time_interval (interval * cronSECONDS); |
483 | } | 417 | } |
484 | 418 | ||
485 | int parseTimeInterval(const char * timeSpec, | 419 | int |
486 | TIME_T * interval) { | 420 | parseTimeInterval (const char *timeSpec, TIME_T * interval) |
421 | { | ||
487 | if (timeSpec == NULL) | 422 | if (timeSpec == NULL) |
488 | return SYSERR; | 423 | return SYSERR; |
489 | if (0 == strcmp(_("--sporadic update--"), | 424 | if (0 == strcmp (_("--sporadic update--"), timeSpec)) |
490 | timeSpec)) | ||
491 | *interval = ECRS_SBLOCK_UPDATE_SPORADIC; | 425 | *interval = ECRS_SBLOCK_UPDATE_SPORADIC; |
492 | else if (0 == strcmp(_("--no update--"), | 426 | else if (0 == strcmp (_("--no update--"), timeSpec)) |
493 | timeSpec)) | ||
494 | *interval = ECRS_SBLOCK_UPDATE_NONE; | 427 | *interval = ECRS_SBLOCK_UPDATE_NONE; |
495 | else | 428 | else |
496 | return parseTime(timeSpec, | 429 | return parseTime (timeSpec, interval); |
497 | interval); | ||
498 | return OK; | 430 | return OK; |
499 | } | 431 | } |
500 | 432 | ||
501 | int tryParseTimeInterval(GladeXML * xml, | 433 | int |
502 | const char * intervalComboBoxEntry, | 434 | tryParseTimeInterval (GladeXML * xml, |
503 | TIME_T * interval) { | 435 | const char *intervalComboBoxEntry, TIME_T * interval) |
504 | return parseTimeInterval(getEntryLineValue(xml, | 436 | { |
505 | intervalComboBoxEntry), | 437 | return parseTimeInterval (getEntryLineValue (xml, |
506 | interval); | 438 | intervalComboBoxEntry), |
439 | interval); | ||
507 | } | 440 | } |
508 | 441 | ||
509 | unsigned int getSpinButtonValue(GladeXML * xml, | 442 | unsigned int |
510 | const char * spinButtonName) { | 443 | getSpinButtonValue (GladeXML * xml, const char *spinButtonName) |
511 | GtkWidget * spin; | 444 | { |
445 | GtkWidget *spin; | ||
512 | 446 | ||
513 | spin = glade_xml_get_widget(xml, | 447 | spin = glade_xml_get_widget (xml, spinButtonName); |
514 | spinButtonName); | 448 | return gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (spin)); |
515 | return gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spin)); | ||
516 | } | 449 | } |
517 | 450 | ||
518 | 451 | ||
519 | 452 | ||
520 | char * getMimeTypeFromMetaData(const struct ECRS_MetaData * meta) { | 453 | char * |
521 | char * mime; | 454 | getMimeTypeFromMetaData (const struct ECRS_MetaData *meta) |
455 | { | ||
456 | char *mime; | ||
522 | 457 | ||
523 | mime = ECRS_getFromMetaData(meta, | 458 | mime = ECRS_getFromMetaData (meta, EXTRACTOR_MIMETYPE); |
524 | EXTRACTOR_MIMETYPE); | ||
525 | if (mime == NULL) | 459 | if (mime == NULL) |
526 | mime = STRDUP(_("unknown")); | 460 | mime = STRDUP (_("unknown")); |
527 | return validate_utf8(mime); | 461 | return validate_utf8 (mime); |
528 | } | 462 | } |
529 | 463 | ||
530 | char * getFileNameFromMetaData(const struct ECRS_MetaData * meta) { | 464 | char * |
531 | char * name; | 465 | getFileNameFromMetaData (const struct ECRS_MetaData *meta) |
532 | 466 | { | |
533 | name = ECRS_getFirstFromMetaData(meta, | 467 | char *name; |
534 | EXTRACTOR_FILENAME, | 468 | |
535 | EXTRACTOR_TITLE, | 469 | name = ECRS_getFirstFromMetaData (meta, |
536 | EXTRACTOR_ARTIST, | 470 | EXTRACTOR_FILENAME, |
537 | EXTRACTOR_AUTHOR, | 471 | EXTRACTOR_TITLE, |
538 | EXTRACTOR_PUBLISHER, | 472 | EXTRACTOR_ARTIST, |
539 | EXTRACTOR_CREATOR, | 473 | EXTRACTOR_AUTHOR, |
540 | EXTRACTOR_PRODUCER, | 474 | EXTRACTOR_PUBLISHER, |
541 | EXTRACTOR_UNKNOWN, | 475 | EXTRACTOR_CREATOR, |
542 | -1); | 476 | EXTRACTOR_PRODUCER, |
543 | if (name == NULL) { | 477 | EXTRACTOR_UNKNOWN, -1); |
544 | name = STRDUP(_("no name given")); | 478 | if (name == NULL) |
545 | } else { | 479 | { |
546 | char * dotdot; | 480 | name = STRDUP (_("no name given")); |
547 | 481 | } | |
548 | while (NULL != (dotdot = strstr(name, ".."))) | 482 | else |
549 | dotdot[0] = dotdot[1] = '_'; | 483 | { |
550 | } | 484 | char *dotdot; |
551 | return validate_utf8(name); | 485 | |
486 | while (NULL != (dotdot = strstr (name, ".."))) | ||
487 | dotdot[0] = dotdot[1] = '_'; | ||
488 | } | ||
489 | return validate_utf8 (name); | ||
552 | } | 490 | } |
553 | 491 | ||
554 | char * getDescriptionFromMetaData(const struct ECRS_MetaData * meta) { | 492 | char * |
555 | char * desc; | 493 | getDescriptionFromMetaData (const struct ECRS_MetaData *meta) |
556 | 494 | { | |
557 | desc = ECRS_getFirstFromMetaData(meta, | 495 | char *desc; |
558 | EXTRACTOR_DESCRIPTION, | 496 | |
559 | EXTRACTOR_GENRE, | 497 | desc = ECRS_getFirstFromMetaData (meta, |
560 | EXTRACTOR_ALBUM, | 498 | EXTRACTOR_DESCRIPTION, |
561 | EXTRACTOR_COMMENT, | 499 | EXTRACTOR_GENRE, |
562 | EXTRACTOR_SUBJECT, | 500 | EXTRACTOR_ALBUM, |
563 | EXTRACTOR_FORMAT, | 501 | EXTRACTOR_COMMENT, |
564 | EXTRACTOR_SIZE, | 502 | EXTRACTOR_SUBJECT, |
565 | EXTRACTOR_KEYWORDS, | 503 | EXTRACTOR_FORMAT, |
566 | -1); | 504 | EXTRACTOR_SIZE, EXTRACTOR_KEYWORDS, -1); |
567 | if (desc == NULL) | 505 | if (desc == NULL) |
568 | desc = STRDUP(""); | 506 | desc = STRDUP (""); |
569 | return validate_utf8(desc); | 507 | return validate_utf8 (desc); |
570 | } | 508 | } |
571 | 509 | ||
572 | GdkPixbuf * getThumbnailFromMetaData(const struct ECRS_MetaData * meta) { | 510 | GdkPixbuf * |
573 | GdkPixbuf * pixbuf; | 511 | getThumbnailFromMetaData (const struct ECRS_MetaData * meta) |
574 | GdkPixbufLoader * loader; | 512 | { |
513 | GdkPixbuf *pixbuf; | ||
514 | GdkPixbufLoader *loader; | ||
575 | size_t ts; | 515 | size_t ts; |
576 | unsigned char * thumb; | 516 | unsigned char *thumb; |
577 | 517 | ||
578 | thumb = NULL; | 518 | thumb = NULL; |
579 | ts = ECRS_getThumbnailFromMetaData(meta, | 519 | ts = ECRS_getThumbnailFromMetaData (meta, &thumb); |
580 | &thumb); | 520 | if (ts != 0) |
581 | if (ts != 0) { | 521 | { |
582 | loader = gdk_pixbuf_loader_new(); | 522 | loader = gdk_pixbuf_loader_new (); |
583 | gdk_pixbuf_loader_write(loader, | 523 | gdk_pixbuf_loader_write (loader, (const guchar *) thumb, ts, NULL); |
584 | (const guchar*) thumb, | 524 | pixbuf = gdk_pixbuf_loader_get_pixbuf (loader); |
585 | ts, | 525 | gdk_pixbuf_loader_close (loader, NULL); |
586 | NULL); | 526 | if (pixbuf != NULL) |
587 | pixbuf = gdk_pixbuf_loader_get_pixbuf(loader); | 527 | g_object_ref (pixbuf); |
588 | gdk_pixbuf_loader_close(loader, | 528 | UNREF (loader); |
589 | NULL); | 529 | } |
590 | if (pixbuf != NULL) | 530 | else |
591 | g_object_ref(pixbuf); | 531 | { |
592 | UNREF(loader); | 532 | pixbuf = NULL; |
593 | } else { | 533 | } |
594 | pixbuf = NULL; | 534 | FREENONNULL (thumb); |
595 | } | ||
596 | FREENONNULL(thumb); | ||
597 | return pixbuf; | 535 | return pixbuf; |
598 | } | 536 | } |
599 | 537 | ||
600 | GtkWidget * | 538 | GtkWidget * |
601 | extractMainWidgetFromWindow(GladeXML * xml, | 539 | extractMainWidgetFromWindow (GladeXML * xml, const char *windowName) |
602 | const char * windowName) { | 540 | { |
603 | GtkContainer * window; | 541 | GtkContainer *window; |
604 | GtkWidget * ret; | 542 | GtkWidget *ret; |
605 | 543 | ||
606 | window = GTK_CONTAINER(glade_xml_get_widget(xml, | 544 | window = GTK_CONTAINER (glade_xml_get_widget (xml, windowName)); |
607 | windowName)); | 545 | ret = gtk_bin_get_child (GTK_BIN (window)); |
608 | ret = gtk_bin_get_child(GTK_BIN(window)); | 546 | gtk_widget_ref (ret); |
609 | gtk_widget_ref(ret); | 547 | gtk_container_remove (window, ret); |
610 | gtk_container_remove(window, ret); | 548 | gtk_widget_destroy (GTK_WIDGET (window)); |
611 | gtk_widget_destroy(GTK_WIDGET(window)); | ||
612 | return ret; | 549 | return ret; |
613 | } | 550 | } |
614 | 551 | ||
615 | int getToggleButtonValue(GladeXML * xml, | 552 | int |
616 | const char * widgetName) { | 553 | getToggleButtonValue (GladeXML * xml, const char *widgetName) |
617 | return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(xml, | 554 | { |
618 | widgetName))); | 555 | return |
556 | gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON | ||
557 | (glade_xml_get_widget (xml, widgetName))); | ||
619 | } | 558 | } |
620 | 559 | ||
621 | const char * getEntryLineValue(GladeXML * xml, | 560 | const char * |
622 | const char * widgetName) { | 561 | getEntryLineValue (GladeXML * xml, const char *widgetName) |
623 | GtkBin * line; | 562 | { |
624 | GtkEntry * entry; | 563 | GtkBin *line; |
564 | GtkEntry *entry; | ||
625 | 565 | ||
626 | line = GTK_BIN(glade_xml_get_widget(xml, | 566 | line = GTK_BIN (glade_xml_get_widget (xml, widgetName)); |
627 | widgetName)); | 567 | entry = GTK_ENTRY (gtk_bin_get_child (line)); |
628 | entry = GTK_ENTRY(gtk_bin_get_child(line)); | 568 | return gtk_entry_get_text (entry); |
629 | return gtk_entry_get_text(entry); | ||
630 | } | 569 | } |
631 | 570 | ||
632 | /* end of meta.c */ | 571 | /* end of meta.c */ |
diff --git a/src/plugins/fs/meta.h b/src/plugins/fs/meta.h index d9a0e01d..ead38bc6 100644 --- a/src/plugins/fs/meta.h +++ b/src/plugins/fs/meta.h | |||
@@ -30,67 +30,58 @@ | |||
30 | #include "gnunetgtk_common.h" | 30 | #include "gnunetgtk_common.h" |
31 | #include <GNUnet/gnunet_ecrs_lib.h> | 31 | #include <GNUnet/gnunet_ecrs_lib.h> |
32 | 32 | ||
33 | void createMetaDataListTreeView(GladeXML * xml, | 33 | void createMetaDataListTreeView (GladeXML * xml, |
34 | const char * name, | 34 | const char *name, |
35 | const char * previewName, | 35 | const char *previewName, |
36 | const struct ECRS_MetaData * init); | 36 | const struct ECRS_MetaData *init); |
37 | 37 | ||
38 | void createKeywordListTreeView(GladeXML * xml, | 38 | void createKeywordListTreeView (GladeXML * xml, |
39 | const char * name, | 39 | const char *name, |
40 | const struct ECRS_URI * init); | 40 | const struct ECRS_URI *init); |
41 | 41 | ||
42 | void createMetaTypeComboBox(GladeXML * xml, | 42 | void createMetaTypeComboBox (GladeXML * xml, const char *name); |
43 | const char * name); | ||
44 | 43 | ||
45 | void handleKeywordListUpdate(GladeXML * xml, | 44 | void handleKeywordListUpdate (GladeXML * xml, |
46 | const char * inputLineName, | 45 | const char *inputLineName, |
47 | const char * keywordListName); | 46 | const char *keywordListName); |
48 | 47 | ||
49 | void handleMetaDataListUpdate(GladeXML * xml, | 48 | void handleMetaDataListUpdate (GladeXML * xml, |
50 | const char * typeInputLineName, | 49 | const char *typeInputLineName, |
51 | const char * valueInputLineName, | 50 | const char *valueInputLineName, |
52 | const char * metaDataListName); | 51 | const char *metaDataListName); |
53 | 52 | ||
54 | void handleListRemove(GladeXML * xml, | 53 | void handleListRemove (GladeXML * xml, const char *listName); |
55 | const char * listName); | ||
56 | 54 | ||
57 | struct ECRS_MetaData * | 55 | struct ECRS_MetaData *getMetaDataFromList (GladeXML * xml, |
58 | getMetaDataFromList(GladeXML * xml, | 56 | const char *name, |
59 | const char * name, | 57 | const char *preview); |
60 | const char * preview); | ||
61 | 58 | ||
62 | struct ECRS_URI * | 59 | struct ECRS_URI *getKeywordURIFromList (GladeXML * xml, const char *name); |
63 | getKeywordURIFromList(GladeXML * xml, | ||
64 | const char * name); | ||
65 | 60 | ||
66 | char * updateIntervalToString(TIME_T interval); | 61 | char *updateIntervalToString (TIME_T interval); |
67 | 62 | ||
68 | int tryParseTimeInterval(GladeXML * xml, | 63 | int tryParseTimeInterval (GladeXML * xml, |
69 | const char * intervalComboBoxEntry, | 64 | const char *intervalComboBoxEntry, |
70 | TIME_T * interval); | 65 | TIME_T * interval); |
71 | 66 | ||
72 | int parseTimeInterval(const char * frequency, | 67 | int parseTimeInterval (const char *frequency, TIME_T * interval); |
73 | TIME_T * interval); | ||
74 | 68 | ||
75 | char * getMimeTypeFromMetaData(const struct ECRS_MetaData * meta); | 69 | char *getMimeTypeFromMetaData (const struct ECRS_MetaData *meta); |
76 | 70 | ||
77 | char * getFileNameFromMetaData(const struct ECRS_MetaData * meta); | 71 | char *getFileNameFromMetaData (const struct ECRS_MetaData *meta); |
78 | 72 | ||
79 | char * getDescriptionFromMetaData(const struct ECRS_MetaData * meta); | 73 | char *getDescriptionFromMetaData (const struct ECRS_MetaData *meta); |
80 | 74 | ||
81 | unsigned int getSpinButtonValue(GladeXML * xml, | 75 | unsigned int getSpinButtonValue (GladeXML * xml, const char *spinButtonName); |
82 | const char * spinButtonName); | ||
83 | 76 | ||
84 | int getToggleButtonValue(GladeXML * xml, | 77 | int getToggleButtonValue (GladeXML * xml, const char *widgetName); |
85 | const char * widgetName); | ||
86 | 78 | ||
87 | const char * getEntryLineValue(GladeXML * xml, | 79 | const char *getEntryLineValue (GladeXML * xml, const char *widgetName); |
88 | const char * widgetName); | ||
89 | 80 | ||
90 | GdkPixbuf * getThumbnailFromMetaData(const struct ECRS_MetaData * meta); | 81 | GdkPixbuf *getThumbnailFromMetaData (const struct ECRS_MetaData *meta); |
91 | 82 | ||
92 | GtkWidget * extractMainWidgetFromWindow(GladeXML * xml, | 83 | GtkWidget *extractMainWidgetFromWindow (GladeXML * xml, |
93 | const char * windowName); | 84 | const char *windowName); |
94 | 85 | ||
95 | 86 | ||
96 | /* end of meta.h */ | 87 | /* end of meta.h */ |
diff --git a/src/plugins/fs/namespace.c b/src/plugins/fs/namespace.c index b9145a9b..425efefe 100644 --- a/src/plugins/fs/namespace.c +++ b/src/plugins/fs/namespace.c | |||
@@ -40,259 +40,245 @@ | |||
40 | /** | 40 | /** |
41 | * @brief linked list of pages in the namespace notebook | 41 | * @brief linked list of pages in the namespace notebook |
42 | */ | 42 | */ |
43 | typedef struct NL { | 43 | typedef struct NL |
44 | struct NL * next; | 44 | { |
45 | GtkWidget * treeview; | 45 | struct NL *next; |
46 | GtkWidget * namespacepage; | 46 | GtkWidget *treeview; |
47 | GtkWidget * addButton; | 47 | GtkWidget *namespacepage; |
48 | GtkWidget * updateButton; | 48 | GtkWidget *addButton; |
49 | GtkTreeModel * model; | 49 | GtkWidget *updateButton; |
50 | char * name; | 50 | GtkTreeModel *model; |
51 | char *name; | ||
51 | HashCode512 id; | 52 | HashCode512 id; |
52 | struct ECRS_MetaData * meta; | 53 | struct ECRS_MetaData *meta; |
53 | } NamespaceList; | 54 | } NamespaceList; |
54 | 55 | ||
55 | /** | 56 | /** |
56 | * Content selection in main list of available content. | 57 | * Content selection in main list of available content. |
57 | */ | 58 | */ |
58 | static GtkTreeSelection * content_selection; | 59 | static GtkTreeSelection *content_selection; |
59 | 60 | ||
60 | static NamespaceList * head; | 61 | static NamespaceList *head; |
61 | 62 | ||
62 | static GladeXML * metaXML; | 63 | static GladeXML *metaXML; |
63 | 64 | ||
64 | /** | 65 | /** |
65 | * The user has changed the selection either in the | 66 | * The user has changed the selection either in the |
66 | * namespace content list or the global content list. | 67 | * namespace content list or the global content list. |
67 | * Update search button status values (add/change). | 68 | * Update search button status values (add/change). |
68 | */ | 69 | */ |
69 | static void on_namespaceContentSelectionChanged(gpointer signal, | 70 | static void |
70 | gpointer cls) { | 71 | on_namespaceContentSelectionChanged (gpointer signal, gpointer cls) |
71 | NamespaceList * list = head; | 72 | { |
73 | NamespaceList *list = head; | ||
72 | int count; | 74 | int count; |
73 | int ncount; | 75 | int ncount; |
74 | GtkTreeSelection * ns; | 76 | GtkTreeSelection *ns; |
75 | GtkTreeIter iter; | 77 | GtkTreeIter iter; |
76 | char * freq; | 78 | char *freq; |
77 | int ok; | 79 | int ok; |
78 | 80 | ||
79 | count = gtk_tree_selection_count_selected_rows(content_selection); | 81 | count = gtk_tree_selection_count_selected_rows (content_selection); |
80 | while (list != NULL) { | 82 | while (list != NULL) |
81 | ns = gtk_tree_view_get_selection(GTK_TREE_VIEW(list->treeview)); | 83 | { |
82 | ncount = gtk_tree_selection_count_selected_rows(ns); | 84 | ns = gtk_tree_view_get_selection (GTK_TREE_VIEW (list->treeview)); |
83 | gtk_widget_set_sensitive(list->addButton, | 85 | ncount = gtk_tree_selection_count_selected_rows (ns); |
84 | count > 0); | 86 | gtk_widget_set_sensitive (list->addButton, count > 0); |
85 | /* now check if update is legal */ | 87 | /* now check if update is legal */ |
86 | ok = 0; | 88 | ok = 0; |
87 | if ( (count == 1) && | 89 | if ((count == 1) && |
88 | (ncount == 1) && | 90 | (ncount == 1) && |
89 | (TRUE == gtk_tree_selection_get_selected(ns, | 91 | (TRUE == gtk_tree_selection_get_selected (ns, NULL, &iter))) |
90 | NULL, | 92 | { |
91 | &iter)) ) { | 93 | freq = NULL; |
92 | freq = NULL; | 94 | gtk_tree_model_get (list->model, |
93 | gtk_tree_model_get(list->model, | 95 | &iter, IN_NAMESPACE_PUB_DATE_STRING, &freq, -1); |
94 | &iter, | 96 | if ((freq != NULL) && (0 != strcmp (freq, _("never")))) |
95 | IN_NAMESPACE_PUB_DATE_STRING, &freq, | 97 | ok = 1; |
96 | -1); | 98 | FREENONNULL (freq); |
97 | if ( (freq != NULL) && | 99 | } |
98 | (0 != strcmp(freq, _("never"))) ) | 100 | gtk_widget_set_sensitive (list->updateButton, ok); |
99 | ok = 1; | 101 | list = list->next; |
100 | FREENONNULL(freq); | ||
101 | } | 102 | } |
102 | gtk_widget_set_sensitive(list->updateButton, | ||
103 | ok); | ||
104 | list = list->next; | ||
105 | } | ||
106 | } | 103 | } |
107 | 104 | ||
108 | 105 | ||
109 | static void makeNamespaceFrame(NamespaceList * entry) { | 106 | static void |
110 | GtkWidget * child; | 107 | makeNamespaceFrame (NamespaceList * entry) |
111 | GtkWidget * resultList; | 108 | { |
112 | GtkCellRenderer * renderer; | 109 | GtkWidget *child; |
113 | GtkListStore * model; | 110 | GtkWidget *resultList; |
114 | GladeXML * namespaceXML; | 111 | GtkCellRenderer *renderer; |
115 | GtkTreeViewColumn * column; | 112 | GtkListStore *model; |
113 | GladeXML *namespaceXML; | ||
114 | GtkTreeViewColumn *column; | ||
116 | int col; | 115 | int col; |
117 | 116 | ||
118 | DEBUG_BEGIN(); | 117 | DEBUG_BEGIN (); |
119 | namespaceXML | 118 | namespaceXML |
120 | = glade_xml_new(getGladeFileName(), | 119 | = glade_xml_new (getGladeFileName (), |
121 | "namespaceContentFrame", | 120 | "namespaceContentFrame", PACKAGE_NAME); |
122 | PACKAGE_NAME); | 121 | connectGladeWithPlugins (namespaceXML); |
123 | connectGladeWithPlugins(namespaceXML); | 122 | child = extractMainWidgetFromWindow (namespaceXML, "namespaceContentFrame"); |
124 | child = extractMainWidgetFromWindow(namespaceXML, | 123 | resultList = glade_xml_get_widget (namespaceXML, |
125 | "namespaceContentFrame"); | 124 | "namespaceContentFrameTreeView"); |
126 | resultList = glade_xml_get_widget(namespaceXML, | 125 | entry->addButton = glade_xml_get_widget (namespaceXML, "addButton"); |
127 | "namespaceContentFrameTreeView"); | 126 | entry->updateButton = glade_xml_get_widget (namespaceXML, |
128 | entry->addButton = glade_xml_get_widget(namespaceXML, | 127 | "namespaceUpdateButton"); |
129 | "addButton"); | 128 | entry->treeview = GTK_WIDGET (GTK_TREE_VIEW (resultList)); |
130 | entry->updateButton = glade_xml_get_widget(namespaceXML, | 129 | model = gtk_list_store_new (IN_NAMESPACE_NUM, G_TYPE_STRING, /* (file)name */ |
131 | "namespaceUpdateButton"); | 130 | G_TYPE_UINT64, /* size */ |
132 | entry->treeview = GTK_WIDGET(GTK_TREE_VIEW(resultList)); | 131 | G_TYPE_STRING, /* human-readable size */ |
133 | model = | 132 | G_TYPE_STRING, /* description */ |
134 | gtk_list_store_new(IN_NAMESPACE_NUM, | 133 | G_TYPE_STRING, /* mime-type */ |
135 | G_TYPE_STRING, /* (file)name */ | 134 | G_TYPE_STRING, /* last-ID */ |
136 | G_TYPE_UINT64, /* size */ | 135 | G_TYPE_STRING, /* next-ID */ |
137 | G_TYPE_STRING, /* human-readable size */ | 136 | G_TYPE_STRING, /* pub-freq */ |
138 | G_TYPE_STRING, /* description */ | 137 | G_TYPE_STRING, /* next pub date */ |
139 | G_TYPE_STRING, /* mime-type */ | 138 | G_TYPE_POINTER, /* URI */ |
140 | G_TYPE_STRING, /* last-ID */ | 139 | G_TYPE_POINTER); /* META */ |
141 | G_TYPE_STRING, /* next-ID */ | 140 | entry->model = GTK_TREE_MODEL (model); |
142 | G_TYPE_STRING, /* pub-freq */ | 141 | gtk_tree_view_set_model (GTK_TREE_VIEW (resultList), |
143 | G_TYPE_STRING, /* next pub date */ | 142 | GTK_TREE_MODEL (model)); |
144 | G_TYPE_POINTER, /* URI */ | 143 | gtk_tree_selection_set_mode (gtk_tree_view_get_selection |
145 | G_TYPE_POINTER); /* META */ | 144 | (GTK_TREE_VIEW (resultList)), |
146 | entry->model = GTK_TREE_MODEL(model); | 145 | GTK_SELECTION_SINGLE); |
147 | gtk_tree_view_set_model(GTK_TREE_VIEW(resultList), | 146 | g_signal_connect_data (gtk_tree_view_get_selection |
148 | GTK_TREE_MODEL(model)); | 147 | (GTK_TREE_VIEW (resultList)), "changed", |
149 | gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(resultList)), | 148 | G_CALLBACK (&on_namespaceContentSelectionChanged), |
150 | GTK_SELECTION_SINGLE); | 149 | NULL, NULL, 0); |
151 | g_signal_connect_data(gtk_tree_view_get_selection(GTK_TREE_VIEW(resultList)), | 150 | |
152 | "changed", | 151 | |
153 | G_CALLBACK(&on_namespaceContentSelectionChanged), | 152 | |
154 | NULL, | 153 | renderer = gtk_cell_renderer_text_new (); |
155 | NULL, | 154 | col = |
156 | 0); | 155 | gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (resultList), |
157 | 156 | -1, _("Filename"), renderer, | |
158 | 157 | "text", | |
159 | 158 | IN_NAMESPACE_FILENAME, NULL); | |
160 | renderer = gtk_cell_renderer_text_new(); | 159 | column = gtk_tree_view_get_column (GTK_TREE_VIEW (resultList), col - 1); |
161 | col = gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(resultList), | 160 | gtk_tree_view_column_set_resizable (column, TRUE); |
162 | -1, | 161 | gtk_tree_view_column_set_clickable (column, TRUE); |
163 | _("Filename"), | 162 | gtk_tree_view_column_set_reorderable (column, TRUE); |
164 | renderer, | 163 | gtk_tree_view_column_set_sort_column_id (column, IN_NAMESPACE_FILENAME); |
165 | "text", IN_NAMESPACE_FILENAME, | 164 | /*gtk_tree_view_column_set_sort_indicator(column, TRUE); */ |
166 | NULL); | 165 | |
167 | column = gtk_tree_view_get_column(GTK_TREE_VIEW(resultList), | 166 | gtk_tree_view_column_set_resizable (gtk_tree_view_get_column |
168 | col - 1); | 167 | (GTK_TREE_VIEW (resultList), col - 1), |
169 | gtk_tree_view_column_set_resizable(column, TRUE); | 168 | TRUE); |
170 | gtk_tree_view_column_set_clickable(column, TRUE); | 169 | renderer = gtk_cell_renderer_text_new (); |
171 | gtk_tree_view_column_set_reorderable(column, TRUE); | ||
172 | gtk_tree_view_column_set_sort_column_id(column, IN_NAMESPACE_FILENAME); | ||
173 | /*gtk_tree_view_column_set_sort_indicator(column, TRUE);*/ | ||
174 | |||
175 | gtk_tree_view_column_set_resizable(gtk_tree_view_get_column(GTK_TREE_VIEW(resultList), | ||
176 | col - 1), | ||
177 | TRUE); | ||
178 | renderer = gtk_cell_renderer_text_new(); | ||
179 | g_object_set (renderer, "xalign", 1.00, NULL); | 170 | g_object_set (renderer, "xalign", 1.00, NULL); |
180 | col = gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(resultList), | 171 | col = |
181 | -1, | 172 | gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (resultList), |
182 | _("Filesize"), | 173 | -1, _("Filesize"), renderer, |
183 | renderer, | 174 | "text", IN_NAMESPACE_HSIZE, |
184 | "text", IN_NAMESPACE_HSIZE, | 175 | NULL); |
185 | NULL); | 176 | column = gtk_tree_view_get_column (GTK_TREE_VIEW (resultList), col - 1); |
186 | column = gtk_tree_view_get_column(GTK_TREE_VIEW(resultList), | 177 | gtk_tree_view_column_set_resizable (column, TRUE); |
187 | col - 1); | 178 | gtk_tree_view_column_set_clickable (column, TRUE); |
188 | gtk_tree_view_column_set_resizable(column, TRUE); | 179 | gtk_tree_view_column_set_reorderable (column, TRUE); |
189 | gtk_tree_view_column_set_clickable(column, TRUE); | 180 | gtk_tree_view_column_set_sort_column_id (column, IN_NAMESPACE_SIZE); |
190 | gtk_tree_view_column_set_reorderable(column, TRUE); | 181 | /*gtk_tree_view_column_set_sort_indicator(column, TRUE); */ |
191 | gtk_tree_view_column_set_sort_column_id(column, IN_NAMESPACE_SIZE); | 182 | gtk_tree_view_column_set_resizable (gtk_tree_view_get_column |
192 | /*gtk_tree_view_column_set_sort_indicator(column, TRUE);*/ | 183 | (GTK_TREE_VIEW (resultList), col - 1), |
193 | gtk_tree_view_column_set_resizable(gtk_tree_view_get_column(GTK_TREE_VIEW(resultList), | 184 | TRUE); |
194 | col - 1), | 185 | renderer = gtk_cell_renderer_text_new (); |
195 | TRUE); | 186 | col = |
196 | renderer = gtk_cell_renderer_text_new(); | 187 | gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (resultList), |
197 | col = gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(resultList), | 188 | -1, _("Description"), |
198 | -1, | 189 | renderer, "text", |
199 | _("Description"), | 190 | IN_NAMESPACE_DESCRIPTION, |
200 | renderer, | 191 | NULL); |
201 | "text", IN_NAMESPACE_DESCRIPTION, | 192 | column = gtk_tree_view_get_column (GTK_TREE_VIEW (resultList), col - 1); |
202 | NULL); | 193 | gtk_tree_view_column_set_resizable (column, TRUE); |
203 | column = gtk_tree_view_get_column(GTK_TREE_VIEW(resultList), | 194 | gtk_tree_view_column_set_clickable (column, TRUE); |
204 | col - 1); | 195 | gtk_tree_view_column_set_reorderable (column, TRUE); |
205 | gtk_tree_view_column_set_resizable(column, TRUE); | 196 | gtk_tree_view_column_set_sort_column_id (column, IN_NAMESPACE_DESCRIPTION); |
206 | gtk_tree_view_column_set_clickable(column, TRUE); | 197 | /*gtk_tree_view_column_set_sort_indicator(column, TRUE); */ |
207 | gtk_tree_view_column_set_reorderable(column, TRUE); | 198 | gtk_tree_view_column_set_resizable (gtk_tree_view_get_column |
208 | gtk_tree_view_column_set_sort_column_id(column, IN_NAMESPACE_DESCRIPTION); | 199 | (GTK_TREE_VIEW (resultList), col - 1), |
209 | /*gtk_tree_view_column_set_sort_indicator(column, TRUE);*/ | 200 | TRUE); |
210 | gtk_tree_view_column_set_resizable(gtk_tree_view_get_column(GTK_TREE_VIEW(resultList), | 201 | renderer = gtk_cell_renderer_text_new (); |
211 | col - 1), | 202 | col = |
212 | TRUE); | 203 | gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (resultList), |
213 | renderer = gtk_cell_renderer_text_new(); | 204 | -1, _("Mime-type"), renderer, |
214 | col = gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(resultList), | 205 | "text", |
215 | -1, | 206 | IN_NAMESPACE_MIMETYPE, NULL); |
216 | _("Mime-type"), | 207 | column = gtk_tree_view_get_column (GTK_TREE_VIEW (resultList), col - 1); |
217 | renderer, | 208 | gtk_tree_view_column_set_resizable (column, TRUE); |
218 | "text", IN_NAMESPACE_MIMETYPE, | 209 | gtk_tree_view_column_set_clickable (column, TRUE); |
219 | NULL); | 210 | gtk_tree_view_column_set_reorderable (column, TRUE); |
220 | column = gtk_tree_view_get_column(GTK_TREE_VIEW(resultList), | 211 | gtk_tree_view_column_set_sort_column_id (column, IN_NAMESPACE_MIMETYPE); |
221 | col - 1); | 212 | /*gtk_tree_view_column_set_sort_indicator(column, TRUE); */ |
222 | gtk_tree_view_column_set_resizable(column, TRUE); | 213 | gtk_tree_view_column_set_resizable (gtk_tree_view_get_column |
223 | gtk_tree_view_column_set_clickable(column, TRUE); | 214 | (GTK_TREE_VIEW (resultList), col - 1), |
224 | gtk_tree_view_column_set_reorderable(column, TRUE); | 215 | TRUE); |
225 | gtk_tree_view_column_set_sort_column_id(column, IN_NAMESPACE_MIMETYPE); | 216 | renderer = gtk_cell_renderer_text_new (); |
226 | /*gtk_tree_view_column_set_sort_indicator(column, TRUE);*/ | 217 | col = |
227 | gtk_tree_view_column_set_resizable(gtk_tree_view_get_column(GTK_TREE_VIEW(resultList), | 218 | gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (resultList), |
228 | col - 1), | 219 | -1, |
229 | TRUE); | 220 | _("Publication Frequency"), |
230 | renderer = gtk_cell_renderer_text_new(); | 221 | renderer, "text", |
231 | col = gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(resultList), | 222 | IN_NAMESPACE_PUB_FREQ_STRING, |
232 | -1, | 223 | NULL); |
233 | _("Publication Frequency"), | 224 | column = gtk_tree_view_get_column (GTK_TREE_VIEW (resultList), col - 1); |
234 | renderer, | 225 | gtk_tree_view_column_set_resizable (column, TRUE); |
235 | "text", IN_NAMESPACE_PUB_FREQ_STRING, | 226 | gtk_tree_view_column_set_clickable (column, TRUE); |
236 | NULL); | 227 | gtk_tree_view_column_set_reorderable (column, TRUE); |
237 | column = gtk_tree_view_get_column(GTK_TREE_VIEW(resultList), | 228 | gtk_tree_view_column_set_sort_column_id (column, |
238 | col - 1); | 229 | IN_NAMESPACE_PUB_FREQ_STRING); |
239 | gtk_tree_view_column_set_resizable(column, TRUE); | 230 | /*gtk_tree_view_column_set_sort_indicator(column, TRUE); */ |
240 | gtk_tree_view_column_set_clickable(column, TRUE); | 231 | gtk_tree_view_column_set_resizable (gtk_tree_view_get_column |
241 | gtk_tree_view_column_set_reorderable(column, TRUE); | 232 | (GTK_TREE_VIEW (resultList), col - 1), |
242 | gtk_tree_view_column_set_sort_column_id(column, IN_NAMESPACE_PUB_FREQ_STRING); | 233 | TRUE); |
243 | /*gtk_tree_view_column_set_sort_indicator(column, TRUE);*/ | 234 | renderer = gtk_cell_renderer_text_new (); |
244 | gtk_tree_view_column_set_resizable(gtk_tree_view_get_column(GTK_TREE_VIEW(resultList), | 235 | col = |
245 | col - 1), | 236 | gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (resultList), |
246 | TRUE); | 237 | -1, |
247 | renderer = gtk_cell_renderer_text_new(); | 238 | _("Next Publication Date"), |
248 | col = gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(resultList), | 239 | renderer, "text", |
249 | -1, | 240 | IN_NAMESPACE_PUB_DATE_STRING, |
250 | _("Next Publication Date"), | 241 | NULL); |
251 | renderer, | 242 | column = gtk_tree_view_get_column (GTK_TREE_VIEW (resultList), col - 1); |
252 | "text", IN_NAMESPACE_PUB_DATE_STRING, | 243 | gtk_tree_view_column_set_reorderable (column, TRUE); |
253 | NULL); | 244 | gtk_tree_view_column_set_resizable (column, TRUE); |
254 | column = gtk_tree_view_get_column(GTK_TREE_VIEW(resultList), | 245 | gtk_tree_view_column_set_clickable (column, TRUE); |
255 | col - 1); | 246 | gtk_tree_view_column_set_sort_column_id (column, |
256 | gtk_tree_view_column_set_reorderable(column, TRUE); | 247 | IN_NAMESPACE_PUB_DATE_STRING); |
257 | gtk_tree_view_column_set_resizable(column, TRUE); | 248 | /*gtk_tree_view_column_set_sort_indicator(column, TRUE); */ |
258 | gtk_tree_view_column_set_clickable(column, TRUE); | 249 | gtk_tree_view_column_set_resizable (gtk_tree_view_get_column |
259 | gtk_tree_view_column_set_sort_column_id(column, IN_NAMESPACE_PUB_DATE_STRING); | 250 | (GTK_TREE_VIEW (resultList), col - 1), |
260 | /*gtk_tree_view_column_set_sort_indicator(column, TRUE);*/ | 251 | TRUE); |
261 | gtk_tree_view_column_set_resizable(gtk_tree_view_get_column(GTK_TREE_VIEW(resultList), | 252 | renderer = gtk_cell_renderer_text_new (); |
262 | col - 1), | 253 | col = |
263 | TRUE); | 254 | gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (resultList), |
264 | renderer = gtk_cell_renderer_text_new(); | 255 | -1, _("Last ID"), renderer, |
265 | col = gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(resultList), | 256 | "text", |
266 | -1, | 257 | IN_NAMESPACE_LAST_STRING, |
267 | _("Last ID"), | 258 | NULL); |
268 | renderer, | 259 | column = gtk_tree_view_get_column (GTK_TREE_VIEW (resultList), col - 1); |
269 | "text", IN_NAMESPACE_LAST_STRING, | 260 | gtk_tree_view_column_set_reorderable (column, TRUE); |
270 | NULL); | 261 | gtk_tree_view_column_set_resizable (column, TRUE); |
271 | column = gtk_tree_view_get_column(GTK_TREE_VIEW(resultList), | 262 | gtk_tree_view_column_set_resizable (gtk_tree_view_get_column |
272 | col - 1); | 263 | (GTK_TREE_VIEW (resultList), col - 1), |
273 | gtk_tree_view_column_set_reorderable(column, TRUE); | 264 | TRUE); |
274 | gtk_tree_view_column_set_resizable(column, TRUE); | 265 | renderer = gtk_cell_renderer_text_new (); |
275 | gtk_tree_view_column_set_resizable(gtk_tree_view_get_column(GTK_TREE_VIEW(resultList), | 266 | col = |
276 | col - 1), | 267 | gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (resultList), |
277 | TRUE); | 268 | -1, _("Next ID"), renderer, |
278 | renderer = gtk_cell_renderer_text_new(); | 269 | "text", |
279 | col = gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(resultList), | 270 | IN_NAMESPACE_NEXT_STRING, |
280 | -1, | 271 | NULL); |
281 | _("Next ID"), | 272 | column = gtk_tree_view_get_column (GTK_TREE_VIEW (resultList), col - 1); |
282 | renderer, | 273 | gtk_tree_view_column_set_reorderable (column, TRUE); |
283 | "text", IN_NAMESPACE_NEXT_STRING, | 274 | gtk_tree_view_column_set_resizable (column, TRUE); |
284 | NULL); | 275 | gtk_tree_view_column_set_resizable (gtk_tree_view_get_column |
285 | column = gtk_tree_view_get_column(GTK_TREE_VIEW(resultList), | 276 | (GTK_TREE_VIEW (resultList), col - 1), |
286 | col - 1); | 277 | TRUE); |
287 | gtk_tree_view_column_set_reorderable(column, TRUE); | 278 | |
288 | gtk_tree_view_column_set_resizable(column, TRUE); | 279 | |
289 | gtk_tree_view_column_set_resizable(gtk_tree_view_get_column(GTK_TREE_VIEW(resultList), | 280 | UNREF (namespaceXML); |
290 | col - 1), | 281 | DEBUG_END (); |
291 | TRUE); | ||
292 | |||
293 | |||
294 | UNREF(namespaceXML); | ||
295 | DEBUG_END(); | ||
296 | 282 | ||
297 | entry->namespacepage = child; | 283 | entry->namespacepage = child; |
298 | } | 284 | } |
@@ -311,263 +297,245 @@ static void makeNamespaceFrame(NamespaceList * entry) { | |||
311 | * next update (0 for sporadic updates) | 297 | * next update (0 for sporadic updates) |
312 | * @return OK to continue iteration, SYSERR to abort | 298 | * @return OK to continue iteration, SYSERR to abort |
313 | */ | 299 | */ |
314 | static int addNamespaceContentToModel(void * cls, | 300 | static int |
315 | const ECRS_FileInfo * fi, | 301 | addNamespaceContentToModel (void *cls, |
316 | const HashCode512 * lastId, | 302 | const ECRS_FileInfo * fi, |
317 | const HashCode512 * nextId, | 303 | const HashCode512 * lastId, |
318 | TIME_T publicationFrequency, | 304 | const HashCode512 * nextId, |
319 | TIME_T nextPublicationTime) { | 305 | TIME_T publicationFrequency, |
320 | GtkListStore * model = GTK_LIST_STORE(cls); | 306 | TIME_T nextPublicationTime) |
307 | { | ||
308 | GtkListStore *model = GTK_LIST_STORE (cls); | ||
321 | GtkTreeIter iter; | 309 | GtkTreeIter iter; |
322 | char * filename; | 310 | char *filename; |
323 | char * desc; | 311 | char *desc; |
324 | char * mime; | 312 | char *mime; |
325 | char * uriString; | 313 | char *uriString; |
326 | EncName last; | 314 | EncName last; |
327 | EncName next; | 315 | EncName next; |
328 | char * freq; | 316 | char *freq; |
329 | char * date; | 317 | char *date; |
330 | unsigned long long size; | 318 | unsigned long long size; |
331 | char * size_h; | 319 | char *size_h; |
332 | 320 | ||
333 | DEBUG_BEGIN(); | 321 | DEBUG_BEGIN (); |
334 | filename = ECRS_getFirstFromMetaData(fi->meta, | 322 | filename = ECRS_getFirstFromMetaData (fi->meta, |
335 | EXTRACTOR_FILENAME, | 323 | EXTRACTOR_FILENAME, |
336 | EXTRACTOR_TITLE, | 324 | EXTRACTOR_TITLE, |
337 | EXTRACTOR_ARTIST, | 325 | EXTRACTOR_ARTIST, |
338 | EXTRACTOR_AUTHOR, | 326 | EXTRACTOR_AUTHOR, |
339 | EXTRACTOR_PUBLISHER, | 327 | EXTRACTOR_PUBLISHER, |
340 | EXTRACTOR_CREATOR, | 328 | EXTRACTOR_CREATOR, |
341 | EXTRACTOR_PRODUCER, | 329 | EXTRACTOR_PRODUCER, |
342 | EXTRACTOR_UNKNOWN, | 330 | EXTRACTOR_UNKNOWN, -1); |
343 | -1); | ||
344 | if (filename == NULL) | 331 | if (filename == NULL) |
345 | filename = STRDUP(_("no name given")); | 332 | filename = STRDUP (_("no name given")); |
346 | else { | 333 | else |
347 | char *dotdot; | 334 | { |
348 | 335 | char *dotdot; | |
349 | while (NULL != (dotdot = strstr(filename, ".."))) | 336 | |
350 | dotdot[0] = dotdot[1] = '_'; | 337 | while (NULL != (dotdot = strstr (filename, ".."))) |
351 | } | 338 | dotdot[0] = dotdot[1] = '_'; |
352 | desc = ECRS_getFirstFromMetaData(fi->meta, | 339 | } |
353 | EXTRACTOR_DESCRIPTION, | 340 | desc = ECRS_getFirstFromMetaData (fi->meta, |
354 | EXTRACTOR_GENRE, | 341 | EXTRACTOR_DESCRIPTION, |
355 | EXTRACTOR_ALBUM, | 342 | EXTRACTOR_GENRE, |
356 | EXTRACTOR_COMMENT, | 343 | EXTRACTOR_ALBUM, |
357 | EXTRACTOR_SUBJECT, | 344 | EXTRACTOR_COMMENT, |
358 | EXTRACTOR_FORMAT, | 345 | EXTRACTOR_SUBJECT, |
359 | EXTRACTOR_SIZE, | 346 | EXTRACTOR_FORMAT, |
360 | EXTRACTOR_KEYWORDS, | 347 | EXTRACTOR_SIZE, EXTRACTOR_KEYWORDS, -1); |
361 | -1); | ||
362 | if (desc == NULL) | 348 | if (desc == NULL) |
363 | desc = STRDUP(""); | 349 | desc = STRDUP (""); |
364 | mime = ECRS_getFromMetaData(fi->meta, | 350 | mime = ECRS_getFromMetaData (fi->meta, EXTRACTOR_MIMETYPE); |
365 | EXTRACTOR_MIMETYPE); | ||
366 | if (mime == NULL) | 351 | if (mime == NULL) |
367 | mime = STRDUP(_("unknown")); | 352 | mime = STRDUP (_("unknown")); |
368 | if (ECRS_isFileUri(fi->uri)) | 353 | if (ECRS_isFileUri (fi->uri)) |
369 | size = ECRS_fileSize(fi->uri); | 354 | size = ECRS_fileSize (fi->uri); |
370 | else | 355 | else |
371 | size = 0; | 356 | size = 0; |
372 | uriString = ECRS_uriToString(fi->uri); | 357 | uriString = ECRS_uriToString (fi->uri); |
373 | hash2enc(lastId, &last); | 358 | hash2enc (lastId, &last); |
374 | if (nextId != NULL) | 359 | if (nextId != NULL) |
375 | hash2enc(nextId, &next); | 360 | hash2enc (nextId, &next); |
376 | else | 361 | else |
377 | memset(&next, 0, sizeof(EncName)); | 362 | memset (&next, 0, sizeof (EncName)); |
378 | if (publicationFrequency == ECRS_SBLOCK_UPDATE_SPORADIC) | 363 | if (publicationFrequency == ECRS_SBLOCK_UPDATE_SPORADIC) |
379 | date = STRDUP(_("unspecified")); | 364 | date = STRDUP (_("unspecified")); |
380 | else if (publicationFrequency == ECRS_SBLOCK_UPDATE_NONE) | 365 | else if (publicationFrequency == ECRS_SBLOCK_UPDATE_NONE) |
381 | date = STRDUP(_("never")); | 366 | date = STRDUP (_("never")); |
382 | else | 367 | else |
383 | date = GN_CTIME(&nextPublicationTime); | 368 | date = GN_CTIME (&nextPublicationTime); |
384 | if (date[strlen(date)-1] == '\n') | 369 | if (date[strlen (date) - 1] == '\n') |
385 | date[strlen(date)-1] = '\0'; | 370 | date[strlen (date) - 1] = '\0'; |
386 | 371 | ||
387 | freq = updateIntervalToString(publicationFrequency); | 372 | freq = updateIntervalToString (publicationFrequency); |
388 | size_h = string_get_fancy_byte_size(size); | 373 | size_h = string_get_fancy_byte_size (size); |
389 | gtk_list_store_append(model, | 374 | gtk_list_store_append (model, &iter); |
390 | &iter); | 375 | gtk_list_store_set (model, |
391 | gtk_list_store_set(model, | 376 | &iter, |
392 | &iter, | 377 | IN_NAMESPACE_FILENAME, filename, |
393 | IN_NAMESPACE_FILENAME, filename, | 378 | IN_NAMESPACE_SIZE, size, |
394 | IN_NAMESPACE_SIZE, size, | 379 | IN_NAMESPACE_HSIZE, size_h, |
395 | IN_NAMESPACE_HSIZE, size_h, | 380 | IN_NAMESPACE_DESCRIPTION, desc, |
396 | IN_NAMESPACE_DESCRIPTION, desc, | 381 | IN_NAMESPACE_MIMETYPE, mime, |
397 | IN_NAMESPACE_MIMETYPE, mime, | 382 | IN_NAMESPACE_LAST_STRING, &last, |
398 | IN_NAMESPACE_LAST_STRING, &last, | 383 | IN_NAMESPACE_NEXT_STRING, &next, |
399 | IN_NAMESPACE_NEXT_STRING, &next, | 384 | IN_NAMESPACE_PUB_FREQ_STRING, freq, |
400 | IN_NAMESPACE_PUB_FREQ_STRING, freq, | 385 | IN_NAMESPACE_PUB_DATE_STRING, date, |
401 | IN_NAMESPACE_PUB_DATE_STRING, date, | 386 | IN_NAMESPACE_URI, ECRS_dupUri (fi->uri), |
402 | IN_NAMESPACE_URI, ECRS_dupUri(fi->uri), | 387 | IN_NAMESPACE_META, ECRS_dupMetaData (fi->meta), -1); |
403 | IN_NAMESPACE_META, ECRS_dupMetaData(fi->meta), | 388 | FREE (size_h); |
404 | -1); | 389 | FREE (filename); |
405 | FREE(size_h); | 390 | FREE (uriString); |
406 | FREE(filename); | 391 | FREE (freq); |
407 | FREE(uriString); | 392 | FREE (date); |
408 | FREE(freq); | 393 | FREE (mime); |
409 | FREE(date); | 394 | DEBUG_END (); |
410 | FREE(mime); | ||
411 | DEBUG_END(); | ||
412 | return OK; | 395 | return OK; |
413 | } | 396 | } |
414 | 397 | ||
415 | /** | 398 | /** |
416 | * Add a tab for the given namespace. | 399 | * Add a tab for the given namespace. |
417 | */ | 400 | */ |
418 | int addTabForNamespace(void * unused, | 401 | int |
419 | const char * namespaceName, | 402 | addTabForNamespace (void *unused, |
420 | const HashCode512 * namespaceId, | 403 | const char *namespaceName, |
421 | const struct ECRS_MetaData * md, | 404 | const HashCode512 * namespaceId, |
422 | int rating) { | 405 | const struct ECRS_MetaData *md, int rating) |
423 | NamespaceList * list; | 406 | { |
424 | GtkWidget * label; | 407 | NamespaceList *list; |
425 | GtkWidget * notebook; | 408 | GtkWidget *label; |
426 | GtkWidget * del_menu; | 409 | GtkWidget *notebook; |
427 | 410 | GtkWidget *del_menu; | |
428 | if (OK != ECRS_testNamespaceExists(NULL, | 411 | |
429 | cfg, | 412 | if (OK != ECRS_testNamespaceExists (NULL, cfg, namespaceName, namespaceId)) |
430 | namespaceName, | ||
431 | namespaceId)) | ||
432 | return OK; | 413 | return OK; |
433 | DEBUG_BEGIN(); | 414 | DEBUG_BEGIN (); |
434 | label = gtk_label_new(namespaceName); | 415 | label = gtk_label_new (namespaceName); |
435 | list = MALLOC(sizeof(NamespaceList)); | 416 | list = MALLOC (sizeof (NamespaceList)); |
436 | list->name = STRDUP(namespaceName); | 417 | list->name = STRDUP (namespaceName); |
437 | list->id = *namespaceId; | 418 | list->id = *namespaceId; |
438 | list->meta = ECRS_dupMetaData(md); | 419 | list->meta = ECRS_dupMetaData (md); |
439 | makeNamespaceFrame(list); | 420 | makeNamespaceFrame (list); |
440 | list->next | 421 | list->next = head; |
441 | = head; | ||
442 | head = list; | 422 | head = list; |
443 | /* update sensitivity of add button */ | 423 | /* update sensitivity of add button */ |
444 | on_namespaceContentSelectionChanged(NULL, NULL); | 424 | on_namespaceContentSelectionChanged (NULL, NULL); |
445 | notebook | 425 | notebook = glade_xml_get_widget (getMainXML (), "localNamespacesNotebook"); |
446 | = glade_xml_get_widget(getMainXML(), | 426 | gtk_notebook_append_page (GTK_NOTEBOOK (notebook), |
447 | "localNamespacesNotebook"); | 427 | list->namespacepage, label); |
448 | gtk_notebook_append_page(GTK_NOTEBOOK(notebook), | 428 | gtk_widget_show (notebook); |
449 | list->namespacepage, | ||
450 | label); | ||
451 | gtk_widget_show(notebook); | ||
452 | NS_listNamespaceContent | 429 | NS_listNamespaceContent |
453 | (ectx, | 430 | (ectx, cfg, namespaceName, &addNamespaceContentToModel, list->model); |
454 | cfg, | 431 | DEBUG_END (); |
455 | namespaceName, | ||
456 | &addNamespaceContentToModel, | ||
457 | list->model); | ||
458 | DEBUG_END(); | ||
459 | /* enable "delete" menu entry */ | 432 | /* enable "delete" menu entry */ |
460 | 433 | ||
461 | del_menu = glade_xml_get_widget(getMainXML(), | 434 | del_menu = glade_xml_get_widget (getMainXML (), "namespaceDelete"); |
462 | "namespaceDelete"); | 435 | gtk_widget_set_sensitive (del_menu, TRUE); |
463 | gtk_widget_set_sensitive(del_menu, | ||
464 | TRUE); | ||
465 | return OK; | 436 | return OK; |
466 | } | 437 | } |
467 | 438 | ||
468 | 439 | ||
469 | static void frame_destroy(GtkWidget * tree) { | 440 | static void |
441 | frame_destroy (GtkWidget * tree) | ||
442 | { | ||
470 | GtkTreeIter iter; | 443 | GtkTreeIter iter; |
471 | struct ECRS_URI * u; | 444 | struct ECRS_URI *u; |
472 | struct ECRS_MetaData * m; | 445 | struct ECRS_MetaData *m; |
473 | NamespaceList * prev; | 446 | NamespaceList *prev; |
474 | NamespaceList * pos; | 447 | NamespaceList *pos; |
475 | NamespaceList * next; | 448 | NamespaceList *next; |
476 | GtkWidget * del_menu; | 449 | GtkWidget *del_menu; |
477 | 450 | ||
478 | pos = head; | 451 | pos = head; |
479 | prev = NULL; | 452 | prev = NULL; |
480 | while (pos != NULL) { | 453 | while (pos != NULL) |
481 | next = pos->next; | 454 | { |
482 | if (pos->treeview == tree) | 455 | next = pos->next; |
483 | break; | 456 | if (pos->treeview == tree) |
484 | prev = pos; | 457 | break; |
485 | pos = next; | 458 | prev = pos; |
486 | } | 459 | pos = next; |
487 | if (pos == NULL) { | 460 | } |
488 | GE_BREAK(NULL, 0); | 461 | if (pos == NULL) |
489 | return; | 462 | { |
490 | } | 463 | GE_BREAK (NULL, 0); |
464 | return; | ||
465 | } | ||
491 | if (prev == NULL) | 466 | if (prev == NULL) |
492 | head = pos->next; | 467 | head = pos->next; |
493 | else | 468 | else |
494 | prev->next = pos->next; | 469 | prev->next = pos->next; |
495 | FREE(pos->name); | 470 | FREE (pos->name); |
496 | ECRS_freeMetaData(pos->meta); | 471 | ECRS_freeMetaData (pos->meta); |
497 | if (gtk_tree_model_get_iter_first(pos->model, | 472 | if (gtk_tree_model_get_iter_first (pos->model, &iter)) |
498 | &iter)) { | 473 | { |
499 | do { | 474 | do |
500 | gtk_tree_model_get(pos->model, | 475 | { |
501 | &iter, | 476 | gtk_tree_model_get (pos->model, |
502 | IN_NAMESPACE_URI, &u, | 477 | &iter, |
503 | IN_NAMESPACE_META, &m, | 478 | IN_NAMESPACE_URI, &u, |
504 | -1); | 479 | IN_NAMESPACE_META, &m, -1); |
505 | gtk_list_store_set(GTK_LIST_STORE(pos->model), | 480 | gtk_list_store_set (GTK_LIST_STORE (pos->model), |
506 | &iter, | 481 | &iter, |
507 | IN_NAMESPACE_URI, NULL, | 482 | IN_NAMESPACE_URI, NULL, |
508 | IN_NAMESPACE_META, NULL, | 483 | IN_NAMESPACE_META, NULL, -1); |
509 | -1); | 484 | if (u != NULL) |
510 | if (u != NULL) | 485 | ECRS_freeUri (u); |
511 | ECRS_freeUri(u); | 486 | if (m != NULL) |
512 | if (m != NULL) | 487 | ECRS_freeMetaData (m); |
513 | ECRS_freeMetaData(m); | 488 | } |
514 | } while (gtk_tree_model_iter_next(pos->model, | 489 | while (gtk_tree_model_iter_next (pos->model, &iter)); |
515 | &iter)); | 490 | } |
516 | } | 491 | FREE (pos); |
517 | FREE(pos); | 492 | del_menu = glade_xml_get_widget (getMainXML (), "namespaceDelete"); |
518 | del_menu = glade_xml_get_widget(getMainXML(), | 493 | gtk_widget_set_sensitive (del_menu, head != NULL); |
519 | "namespaceDelete"); | ||
520 | gtk_widget_set_sensitive(del_menu, | ||
521 | head != NULL); | ||
522 | } | 494 | } |
523 | 495 | ||
524 | 496 | ||
525 | 497 | ||
526 | void namespaceDelete_clicked_fs(GtkWidget * dummy1, | 498 | void |
527 | GtkWidget * dummy2) { | 499 | namespaceDelete_clicked_fs (GtkWidget * dummy1, GtkWidget * dummy2) |
528 | GtkWidget * notebook; | 500 | { |
529 | NamespaceList * list; | 501 | GtkWidget *notebook; |
530 | NamespaceList * prev; | 502 | NamespaceList *list; |
503 | NamespaceList *prev; | ||
531 | gint num; | 504 | gint num; |
532 | GtkWidget * page; | 505 | GtkWidget *page; |
533 | GtkWidget * dialog; | 506 | GtkWidget *dialog; |
534 | gint ret; | 507 | gint ret; |
535 | 508 | ||
536 | DEBUG_BEGIN(); | 509 | DEBUG_BEGIN (); |
537 | notebook | 510 | notebook = glade_xml_get_widget (getMainXML (), "localNamespacesNotebook"); |
538 | = glade_xml_get_widget(getMainXML(), | 511 | num = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook)); |
539 | "localNamespacesNotebook"); | 512 | if (num == -1) |
540 | num | 513 | { |
541 | = gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook)); | 514 | /* IMPROVE-ME: disable the menu item |
542 | if (num == -1) { | 515 | as long as this may happen! */ |
543 | /* IMPROVE-ME: disable the menu item | 516 | dialog = gtk_message_dialog_new |
544 | as long as this may happen! */ | 517 | (NULL, |
545 | dialog = gtk_message_dialog_new | 518 | GTK_DIALOG_MODAL, |
546 | (NULL, | 519 | GTK_MESSAGE_ERROR, |
547 | GTK_DIALOG_MODAL, | 520 | GTK_BUTTONS_CLOSE, |
548 | GTK_MESSAGE_ERROR, | 521 | _("No local namespaces available that could be deleted!")); |
549 | GTK_BUTTONS_CLOSE, | 522 | gtk_dialog_run (GTK_DIALOG (dialog)); |
550 | _("No local namespaces available that could be deleted!")); | 523 | gtk_widget_destroy (dialog); |
551 | gtk_dialog_run(GTK_DIALOG(dialog)); | 524 | return; |
552 | gtk_widget_destroy(dialog); | 525 | } |
553 | return; | 526 | page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), num); |
554 | } | 527 | list = head; |
555 | page | 528 | prev = NULL; |
556 | = gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebook), | 529 | while ((list != NULL) && (list->namespacepage != page)) |
557 | num); | 530 | { |
558 | list | 531 | prev = list; |
559 | = head; | 532 | list = list->next; |
560 | prev | 533 | } |
561 | = NULL; | 534 | if (list == NULL) |
562 | while ( (list != NULL) && | 535 | { |
563 | (list->namespacepage != page) ) { | 536 | GE_BREAK (ectx, 0); |
564 | prev = list; | 537 | return; |
565 | list = list->next; | 538 | } |
566 | } | ||
567 | if (list == NULL) { | ||
568 | GE_BREAK(ectx, 0); | ||
569 | return; | ||
570 | } | ||
571 | /* open window to ask for confirmation, | 539 | /* open window to ask for confirmation, |
572 | only then delete */ | 540 | only then delete */ |
573 | 541 | ||
@@ -576,102 +544,98 @@ void namespaceDelete_clicked_fs(GtkWidget * dummy1, | |||
576 | GTK_DIALOG_MODAL, | 544 | GTK_DIALOG_MODAL, |
577 | GTK_MESSAGE_ERROR, | 545 | GTK_MESSAGE_ERROR, |
578 | GTK_BUTTONS_YES_NO, | 546 | GTK_BUTTONS_YES_NO, |
579 | _("Should the namespace `%s' really be deleted?"), | 547 | _("Should the namespace `%s' really be deleted?"), list->name); |
580 | list->name); | 548 | ret = gtk_dialog_run (GTK_DIALOG (dialog)); |
581 | ret = gtk_dialog_run(GTK_DIALOG(dialog)); | 549 | gtk_widget_destroy (dialog); |
582 | gtk_widget_destroy(dialog); | ||
583 | if (GTK_RESPONSE_YES != ret) | 550 | if (GTK_RESPONSE_YES != ret) |
584 | return; | 551 | return; |
585 | gtk_notebook_remove_page(GTK_NOTEBOOK(notebook), | 552 | gtk_notebook_remove_page (GTK_NOTEBOOK (notebook), num); |
586 | num); | 553 | NS_deleteNamespace (ectx, cfg, list->name); |
587 | NS_deleteNamespace(ectx, | 554 | frame_destroy (list->treeview); |
588 | cfg, | 555 | DEBUG_END (); |
589 | list->name); | ||
590 | frame_destroy(list->treeview); | ||
591 | DEBUG_END(); | ||
592 | } | 556 | } |
593 | 557 | ||
594 | typedef struct { | 558 | typedef struct |
559 | { | ||
595 | unsigned int anonymityLevel; | 560 | unsigned int anonymityLevel; |
596 | char * namespaceName; | 561 | char *namespaceName; |
597 | TIME_T updateInterval; | 562 | TIME_T updateInterval; |
598 | HashCode512 * lastId; | 563 | HashCode512 *lastId; |
599 | HashCode512 thisId; | 564 | HashCode512 thisId; |
600 | HashCode512 * nextId; | 565 | HashCode512 *nextId; |
601 | } IUC; | 566 | } IUC; |
602 | 567 | ||
603 | /** | 568 | /** |
604 | * Publish the selected file in the | 569 | * Publish the selected file in the |
605 | * selected namespace. | 570 | * selected namespace. |
606 | */ | 571 | */ |
607 | static void addToNamespaceCB(GtkTreeModel * model, | 572 | static void |
608 | GtkTreePath * path, | 573 | addToNamespaceCB (GtkTreeModel * model, |
609 | GtkTreeIter * iter, | 574 | GtkTreePath * path, GtkTreeIter * iter, gpointer data) |
610 | gpointer data) { | 575 | { |
611 | IUC * cls = data; | 576 | IUC *cls = data; |
612 | struct ECRS_URI * resultURI; | 577 | struct ECRS_URI *resultURI; |
613 | struct ECRS_URI * dst; | 578 | struct ECRS_URI *dst; |
614 | struct ECRS_MetaData * meta; | 579 | struct ECRS_MetaData *meta; |
615 | NamespaceList * list; | 580 | NamespaceList *list; |
616 | ECRS_FileInfo fi; | 581 | ECRS_FileInfo fi; |
617 | 582 | ||
618 | DEBUG_BEGIN(); | 583 | DEBUG_BEGIN (); |
619 | dst = NULL; | 584 | dst = NULL; |
620 | gtk_tree_model_get(model, | 585 | gtk_tree_model_get (model, |
621 | iter, | 586 | iter, NAMESPACE_URI, &dst, NAMESPACE_META, &meta, -1); |
622 | NAMESPACE_URI, &dst, | 587 | if (dst == NULL) |
623 | NAMESPACE_META, &meta, | 588 | { |
624 | -1); | 589 | GE_BREAK (ectx, 0); |
625 | if (dst == NULL) { | 590 | return; |
626 | GE_BREAK(ectx, 0); | 591 | } |
627 | return; | 592 | resultURI = NS_addToNamespace (ectx, cfg, cls->anonymityLevel, 1000, /* FIXME: priority */ |
628 | } | 593 | get_time () + 2 * cronYEARS, /* FIXME: expiration */ |
629 | resultURI = NS_addToNamespace(ectx, | 594 | cls->namespaceName, |
630 | cfg, | 595 | cls->updateInterval, |
631 | cls->anonymityLevel, | 596 | cls->lastId, |
632 | 1000, /* FIXME: priority */ | 597 | &cls->thisId, cls->nextId, dst, meta); |
633 | get_time() + 2 * cronYEARS, /* FIXME: expiration */ | 598 | if (resultURI != NULL) |
634 | cls->namespaceName, | 599 | { |
635 | cls->updateInterval, | 600 | list = head; |
636 | cls->lastId, | 601 | while ((list != NULL) && (0 != strcmp (cls->namespaceName, list->name))) |
637 | &cls->thisId, | 602 | list = list->next; |
638 | cls->nextId, | 603 | if (list == NULL) |
639 | dst, | 604 | { |
640 | meta); | 605 | GE_BREAK (ectx, 0); |
641 | if (resultURI != NULL) { | 606 | } |
642 | list = head; | 607 | else |
643 | while ( (list != NULL) && | 608 | { |
644 | (0 != strcmp(cls->namespaceName, | 609 | /* update namespace content list! */ |
645 | list->name)) ) | 610 | fi.uri = dst; |
646 | list = list->next; | 611 | fi.meta = meta; |
647 | if (list == NULL) { | 612 | addNamespaceContentToModel (list->model, |
648 | GE_BREAK(ectx, 0); | 613 | &fi, |
649 | } else { | 614 | &cls->thisId, |
650 | /* update namespace content list! */ | 615 | cls->nextId, |
651 | fi.uri = dst; | 616 | cls->updateInterval, |
652 | fi.meta = meta; | 617 | cls->updateInterval + TIME (NULL)); |
653 | addNamespaceContentToModel(list->model, | 618 | } |
654 | &fi, | 619 | ECRS_freeUri (resultURI); |
655 | &cls->thisId, | 620 | } |
656 | cls->nextId, | 621 | else |
657 | cls->updateInterval, | 622 | { |
658 | cls->updateInterval + TIME(NULL)); | 623 | infoMessage (YES, |
624 | _("Failed to insert content into namespace " | ||
625 | "(consult logs).\n")); | ||
659 | } | 626 | } |
660 | ECRS_freeUri(resultURI); | 627 | DEBUG_END (); |
661 | } else { | ||
662 | infoMessage(YES, | ||
663 | _("Failed to insert content into namespace " | ||
664 | "(consult logs).\n")); | ||
665 | } | ||
666 | DEBUG_END(); | ||
667 | } | 628 | } |
668 | 629 | ||
669 | void on_namespaceInsertMetaDataDialogMetaDataAddButton_clicked_fs(GtkWidget * dummy1, | 630 | void |
670 | GtkWidget * dummy2) { | 631 | on_namespaceInsertMetaDataDialogMetaDataAddButton_clicked_fs (GtkWidget * |
671 | handleMetaDataListUpdate(metaXML, | 632 | dummy1, |
672 | "namespaceInsertMetaTypeComboBox", | 633 | GtkWidget * |
673 | "metaDataValueEntry", | 634 | dummy2) |
674 | "metaDataTreeView"); | 635 | { |
636 | handleMetaDataListUpdate (metaXML, | ||
637 | "namespaceInsertMetaTypeComboBox", | ||
638 | "metaDataValueEntry", "metaDataTreeView"); | ||
675 | } | 639 | } |
676 | 640 | ||
677 | /** | 641 | /** |
@@ -679,104 +643,93 @@ void on_namespaceInsertMetaDataDialogMetaDataAddButton_clicked_fs(GtkWidget * du | |||
679 | * available content list to the currently selected | 643 | * available content list to the currently selected |
680 | * namespace. | 644 | * namespace. |
681 | */ | 645 | */ |
682 | void on_namespaceInsertButton_clicked_fs(GtkWidget * dummy1, | 646 | void |
683 | GtkWidget * dummy2) { | 647 | on_namespaceInsertButton_clicked_fs (GtkWidget * dummy1, GtkWidget * dummy2) |
684 | 648 | { | |
685 | const char * identifierName; | 649 | |
686 | NamespaceList * list; | 650 | const char *identifierName; |
687 | GtkWidget * nameLine; | 651 | NamespaceList *list; |
688 | GtkWidget * page; | 652 | GtkWidget *nameLine; |
689 | GtkWidget * notebook; | 653 | GtkWidget *page; |
690 | GtkWidget * dialog; | 654 | GtkWidget *notebook; |
691 | GtkWidget * updateIntervalComboBox; | 655 | GtkWidget *dialog; |
656 | GtkWidget *updateIntervalComboBox; | ||
692 | HashCode512 nextId; | 657 | HashCode512 nextId; |
693 | IUC cls; | 658 | IUC cls; |
694 | gint num; | 659 | gint num; |
695 | 660 | ||
696 | notebook | 661 | notebook = glade_xml_get_widget (getMainXML (), "localNamespacesNotebook"); |
697 | = glade_xml_get_widget(getMainXML(), | 662 | num = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook)); |
698 | "localNamespacesNotebook"); | 663 | GE_ASSERT (ectx, num != -1); |
699 | num = gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook)); | 664 | page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), num); |
700 | GE_ASSERT(ectx, num != -1); | ||
701 | page =gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebook), | ||
702 | num); | ||
703 | list = head; | 665 | list = head; |
704 | while ( (list != NULL) && | 666 | while ((list != NULL) && (list->namespacepage != page)) |
705 | (list->namespacepage != page) ) | ||
706 | list = list->next; | 667 | list = list->next; |
707 | if (list == NULL) { | 668 | if (list == NULL) |
708 | GE_BREAK(ectx, 0); | 669 | { |
709 | return; | 670 | GE_BREAK (ectx, 0); |
710 | } | 671 | return; |
672 | } | ||
711 | cls.namespaceName = list->name; | 673 | cls.namespaceName = list->name; |
712 | 674 | ||
713 | metaXML | 675 | metaXML |
714 | = glade_xml_new(getGladeFileName(), | 676 | = glade_xml_new (getGladeFileName (), |
715 | "namespaceInsertDialog", | 677 | "namespaceInsertDialog", PACKAGE_NAME); |
716 | PACKAGE_NAME); | 678 | connectGladeWithPlugins (metaXML); |
717 | connectGladeWithPlugins(metaXML); | 679 | dialog = glade_xml_get_widget (metaXML, "namespaceInsertDialog"); |
718 | dialog = glade_xml_get_widget(metaXML, | 680 | gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); |
719 | "namespaceInsertDialog"); | 681 | |
720 | gtk_dialog_set_default_response(GTK_DIALOG(dialog), | 682 | updateIntervalComboBox = glade_xml_get_widget (metaXML, |
721 | GTK_RESPONSE_OK); | 683 | "updateIntervalComboBoxEntry"); |
722 | 684 | gtk_combo_box_set_active (GTK_COMBO_BOX (updateIntervalComboBox), 0); | |
723 | updateIntervalComboBox = glade_xml_get_widget(metaXML, | 685 | |
724 | "updateIntervalComboBoxEntry"); | 686 | |
725 | gtk_combo_box_set_active(GTK_COMBO_BOX(updateIntervalComboBox), | 687 | if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) |
726 | 0); | 688 | { |
727 | 689 | if (OK != tryParseTimeInterval (metaXML, | |
728 | 690 | "updateIntervalComboBoxEntry", | |
729 | if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) { | 691 | &cls.updateInterval)) |
730 | if (OK != tryParseTimeInterval(metaXML, | 692 | { |
731 | "updateIntervalComboBoxEntry", | 693 | /* this should be impossible - OK button is |
732 | &cls.updateInterval)) { | 694 | deactivated while parse errors are there */ |
733 | /* this should be impossible - OK button is | 695 | gtk_widget_destroy (dialog); |
734 | deactivated while parse errors are there */ | 696 | UNREF (metaXML); |
735 | gtk_widget_destroy(dialog); | 697 | metaXML = NULL; |
736 | UNREF(metaXML); | 698 | dialog = gtk_message_dialog_new |
737 | metaXML = NULL; | 699 | (NULL, |
738 | dialog = gtk_message_dialog_new | 700 | GTK_DIALOG_MODAL, |
739 | (NULL, | 701 | GTK_MESSAGE_ERROR, |
740 | GTK_DIALOG_MODAL, | 702 | GTK_BUTTONS_CLOSE, _("Failed to parse given time interval!")); |
741 | GTK_MESSAGE_ERROR, | 703 | gtk_dialog_run (GTK_DIALOG (dialog)); |
742 | GTK_BUTTONS_CLOSE, | 704 | gtk_widget_destroy (dialog); |
743 | _("Failed to parse given time interval!")); | 705 | return; |
744 | gtk_dialog_run(GTK_DIALOG(dialog)); | 706 | } |
745 | gtk_widget_destroy(dialog); | 707 | cls.anonymityLevel |
746 | return; | 708 | = getSpinButtonValue (metaXML, "anonymitySpinButton"); |
709 | nameLine = glade_xml_get_widget (metaXML, | ||
710 | "namespaceContentIdentifierEntry"); | ||
711 | identifierName = gtk_entry_get_text (GTK_ENTRY (nameLine)); | ||
712 | if (identifierName == NULL) | ||
713 | identifierName = ""; | ||
714 | hash (identifierName, strlen (identifierName), &cls.thisId); | ||
715 | cls.lastId = NULL; | ||
716 | |||
717 | nameLine = glade_xml_get_widget (metaXML, "nextIdentifierEntry"); | ||
718 | identifierName = gtk_entry_get_text (GTK_ENTRY (nameLine)); | ||
719 | if ((identifierName == NULL) || (strlen (identifierName) == 0)) | ||
720 | { | ||
721 | cls.nextId = NULL; | ||
722 | } | ||
723 | else | ||
724 | { | ||
725 | hash (identifierName, strlen (identifierName), &nextId); | ||
726 | cls.nextId = &nextId; | ||
727 | } | ||
728 | ggc_tree_selection_selected_foreach | ||
729 | (content_selection, &addToNamespaceCB, &cls); | ||
747 | } | 730 | } |
748 | cls.anonymityLevel | 731 | gtk_widget_destroy (dialog); |
749 | = getSpinButtonValue(metaXML, | 732 | UNREF (metaXML); |
750 | "anonymitySpinButton"); | ||
751 | nameLine = glade_xml_get_widget(metaXML, | ||
752 | "namespaceContentIdentifierEntry"); | ||
753 | identifierName = gtk_entry_get_text(GTK_ENTRY(nameLine)); | ||
754 | if (identifierName == NULL) | ||
755 | identifierName = ""; | ||
756 | hash(identifierName, | ||
757 | strlen(identifierName), | ||
758 | &cls.thisId); | ||
759 | cls.lastId = NULL; | ||
760 | |||
761 | nameLine = glade_xml_get_widget(metaXML, | ||
762 | "nextIdentifierEntry"); | ||
763 | identifierName = gtk_entry_get_text(GTK_ENTRY(nameLine)); | ||
764 | if ( (identifierName == NULL) || | ||
765 | (strlen(identifierName) == 0)) { | ||
766 | cls.nextId = NULL; | ||
767 | } else { | ||
768 | hash(identifierName, | ||
769 | strlen(identifierName), | ||
770 | &nextId); | ||
771 | cls.nextId = &nextId; | ||
772 | } | ||
773 | ggc_tree_selection_selected_foreach | ||
774 | (content_selection, | ||
775 | &addToNamespaceCB, | ||
776 | &cls); | ||
777 | } | ||
778 | gtk_widget_destroy(dialog); | ||
779 | UNREF(metaXML); | ||
780 | metaXML = NULL; | 733 | metaXML = NULL; |
781 | } | 734 | } |
782 | 735 | ||
@@ -785,288 +738,243 @@ void on_namespaceInsertButton_clicked_fs(GtkWidget * dummy1, | |||
785 | * User clicked on update; launch update dialog | 738 | * User clicked on update; launch update dialog |
786 | * and perform namespace content update. | 739 | * and perform namespace content update. |
787 | */ | 740 | */ |
788 | void on_namespaceUpdateButton_clicked_fs(GtkWidget * dummy1, | 741 | void |
789 | GtkWidget * dummy2) { | 742 | on_namespaceUpdateButton_clicked_fs (GtkWidget * dummy1, GtkWidget * dummy2) |
790 | NamespaceList * list; | 743 | { |
744 | NamespaceList *list; | ||
791 | GtkTreeIter iter; | 745 | GtkTreeIter iter; |
792 | HashCode512 nextId; | 746 | HashCode512 nextId; |
793 | HashCode512 lastId; | 747 | HashCode512 lastId; |
794 | GtkTreeSelection * selection; | 748 | GtkTreeSelection *selection; |
795 | IUC cls; | 749 | IUC cls; |
796 | char * last; | 750 | char *last; |
797 | char * next; | 751 | char *next; |
798 | char * freq; | 752 | char *freq; |
799 | EncName nextnext; | 753 | EncName nextnext; |
800 | GtkWidget * nextEntryLine; | 754 | GtkWidget *nextEntryLine; |
801 | GtkWidget * identifierLabel; | 755 | GtkWidget *identifierLabel; |
802 | GtkWidget * updateIntervalComboBox; | 756 | GtkWidget *updateIntervalComboBox; |
803 | GtkWidget * dialog; | 757 | GtkWidget *dialog; |
804 | GtkWidget * mdialog; | 758 | GtkWidget *mdialog; |
805 | GtkWidget * notebook; | 759 | GtkWidget *notebook; |
806 | GtkWidget * page; | 760 | GtkWidget *page; |
807 | GtkTreeModel * model; | 761 | GtkTreeModel *model; |
808 | gint num; | 762 | gint num; |
809 | const char * nn_str; | 763 | const char *nn_str; |
810 | 764 | ||
811 | DEBUG_BEGIN(); | 765 | DEBUG_BEGIN (); |
812 | /* find out which namespace this is about */ | 766 | /* find out which namespace this is about */ |
813 | notebook | 767 | notebook = glade_xml_get_widget (getMainXML (), "localNamespacesNotebook"); |
814 | = glade_xml_get_widget(getMainXML(), | 768 | num = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook)); |
815 | "localNamespacesNotebook"); | 769 | GE_ASSERT (ectx, num != -1); |
816 | num = gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook)); | 770 | page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), num); |
817 | GE_ASSERT(ectx, num != -1); | ||
818 | page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebook), | ||
819 | num); | ||
820 | list = head; | 771 | list = head; |
821 | while ( (list != NULL) && | 772 | while ((list != NULL) && (list->namespacepage != page)) |
822 | (list->namespacepage != page) ) | ||
823 | list = list->next; | 773 | list = list->next; |
824 | if (list == NULL) { | 774 | if (list == NULL) |
825 | GE_BREAK(ectx, 0); | 775 | { |
826 | return; | 776 | GE_BREAK (ectx, 0); |
827 | } | 777 | return; |
778 | } | ||
828 | cls.namespaceName = list->name; | 779 | cls.namespaceName = list->name; |
829 | 780 | ||
830 | /* find out what we are updating */ | 781 | /* find out what we are updating */ |
831 | selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(list->treeview)); | 782 | selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (list->treeview)); |
832 | if (TRUE != gtk_tree_selection_get_selected(selection, | 783 | if (TRUE != gtk_tree_selection_get_selected (selection, NULL, &iter)) |
833 | NULL, | 784 | { |
834 | &iter)) { | 785 | GE_BREAK (ectx, 0); |
835 | GE_BREAK(ectx, 0); | 786 | return; |
836 | return; | 787 | } |
837 | } | 788 | gtk_tree_model_get (list->model, |
838 | gtk_tree_model_get(list->model, | 789 | &iter, |
839 | &iter, | 790 | IN_NAMESPACE_LAST_STRING, &last, |
840 | IN_NAMESPACE_LAST_STRING, &last, | 791 | IN_NAMESPACE_NEXT_STRING, &next, |
841 | IN_NAMESPACE_NEXT_STRING, &next, | 792 | IN_NAMESPACE_PUB_FREQ_STRING, &freq, -1); |
842 | IN_NAMESPACE_PUB_FREQ_STRING, &freq, | 793 | if ((last == NULL) || (next == NULL) || (freq == NULL)) |
843 | -1); | 794 | { |
844 | if ( (last == NULL) || | 795 | GE_BREAK (NULL, 0); |
845 | (next == NULL) || | 796 | return; |
846 | (freq == NULL) ) { | 797 | } |
847 | GE_BREAK(NULL, 0); | 798 | if (OK != parseTimeInterval (freq, &cls.updateInterval)) |
848 | return; | 799 | { |
849 | } | 800 | GE_BREAK (ectx, 0); |
850 | if (OK != parseTimeInterval(freq, | 801 | cls.updateInterval = ECRS_SBLOCK_UPDATE_SPORADIC; |
851 | &cls.updateInterval)) { | 802 | } |
852 | GE_BREAK(ectx, 0); | ||
853 | cls.updateInterval = ECRS_SBLOCK_UPDATE_SPORADIC; | ||
854 | } | ||
855 | 803 | ||
856 | /* create update dialog */ | 804 | /* create update dialog */ |
857 | metaXML | 805 | metaXML |
858 | = glade_xml_new(getGladeFileName(), | 806 | = glade_xml_new (getGladeFileName (), |
859 | "namespaceUpdateDialog", | 807 | "namespaceUpdateDialog", PACKAGE_NAME); |
860 | PACKAGE_NAME); | 808 | connectGladeWithPlugins (metaXML); |
861 | connectGladeWithPlugins(metaXML); | 809 | dialog = glade_xml_get_widget (metaXML, "namespaceUpdateDialog"); |
862 | dialog = glade_xml_get_widget(metaXML, | 810 | gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); |
863 | "namespaceUpdateDialog"); | 811 | identifierLabel = glade_xml_get_widget (metaXML, "identifierLabel"); |
864 | gtk_dialog_set_default_response(GTK_DIALOG(dialog), | 812 | gtk_label_set_text (GTK_LABEL (identifierLabel), next); |
865 | GTK_RESPONSE_OK); | 813 | enc2hash (last, &lastId); |
866 | identifierLabel = glade_xml_get_widget(metaXML, | ||
867 | "identifierLabel"); | ||
868 | gtk_label_set_text(GTK_LABEL(identifierLabel), | ||
869 | next); | ||
870 | enc2hash(last, &lastId); | ||
871 | cls.lastId = &lastId; | 814 | cls.lastId = &lastId; |
872 | enc2hash(next, &cls.thisId); | 815 | enc2hash (next, &cls.thisId); |
873 | 816 | ||
874 | nextEntryLine = glade_xml_get_widget(metaXML, | 817 | nextEntryLine = glade_xml_get_widget (metaXML, "nextIdentifierEntry"); |
875 | "nextIdentifierEntry"); | 818 | if ((cls.updateInterval != ECRS_SBLOCK_UPDATE_SPORADIC) && |
876 | if ( (cls.updateInterval != ECRS_SBLOCK_UPDATE_SPORADIC) && | 819 | (OK == NS_computeNextId (NULL, |
877 | (OK == NS_computeNextId(NULL, | 820 | cfg, |
878 | cfg, | 821 | cls.namespaceName, |
879 | cls.namespaceName, | 822 | &lastId, |
880 | &lastId, | 823 | &cls.thisId, cls.updateInterval, &nextId))) |
881 | &cls.thisId, | 824 | { |
882 | cls.updateInterval, | 825 | hash2enc (&nextId, &nextnext); |
883 | &nextId)) ) { | 826 | gtk_entry_set_text (GTK_ENTRY (nextEntryLine), (char *) &nextnext); |
884 | hash2enc(&nextId, | 827 | gtk_widget_set_sensitive (nextEntryLine, FALSE); |
885 | &nextnext); | 828 | } |
886 | gtk_entry_set_text(GTK_ENTRY(nextEntryLine), | ||
887 | (char*) &nextnext); | ||
888 | gtk_widget_set_sensitive(nextEntryLine, | ||
889 | FALSE); | ||
890 | } | ||
891 | /* set update interval in dialog to | 829 | /* set update interval in dialog to |
892 | the existing update interval */ | 830 | the existing update interval */ |
893 | updateIntervalComboBox = glade_xml_get_widget(metaXML, | 831 | updateIntervalComboBox = glade_xml_get_widget (metaXML, |
894 | "namespaceUpdateIntervalComboBoxEntry"); | 832 | "namespaceUpdateIntervalComboBoxEntry"); |
895 | model = gtk_combo_box_get_model(GTK_COMBO_BOX(updateIntervalComboBox)); | 833 | model = gtk_combo_box_get_model (GTK_COMBO_BOX (updateIntervalComboBox)); |
896 | gtk_list_store_insert(GTK_LIST_STORE(model), | 834 | gtk_list_store_insert (GTK_LIST_STORE (model), &iter, 0); |
897 | &iter, | 835 | gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, freq, -1); |
898 | 0); | 836 | gtk_combo_box_set_active (GTK_COMBO_BOX (updateIntervalComboBox), 0); |
899 | gtk_list_store_set(GTK_LIST_STORE(model), | ||
900 | &iter, | ||
901 | 0, freq, | ||
902 | -1); | ||
903 | gtk_combo_box_set_active(GTK_COMBO_BOX(updateIntervalComboBox), | ||
904 | 0); | ||
905 | 837 | ||
906 | /* run update dialog */ | 838 | /* run update dialog */ |
907 | if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_OK) | 839 | if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_OK) |
908 | goto CLEANUP; | 840 | goto CLEANUP; |
909 | gtk_widget_hide(dialog); | 841 | gtk_widget_hide (dialog); |
910 | 842 | ||
911 | /* get data from update dialog */ | 843 | /* get data from update dialog */ |
912 | nn_str = gtk_entry_get_text(GTK_ENTRY(nextEntryLine)); | 844 | nn_str = gtk_entry_get_text (GTK_ENTRY (nextEntryLine)); |
913 | if (nn_str == NULL) | 845 | if (nn_str == NULL) |
914 | nn_str = ""; | 846 | nn_str = ""; |
915 | hash(nn_str, | 847 | hash (nn_str, strlen (nn_str), &nextId); |
916 | strlen(nn_str), | ||
917 | &nextId); | ||
918 | cls.nextId = &nextId; | 848 | cls.nextId = &nextId; |
919 | 849 | ||
920 | if (OK != tryParseTimeInterval(metaXML, | 850 | if (OK != tryParseTimeInterval (metaXML, |
921 | "namespaceUpdateIntervalComboBoxEntry", | 851 | "namespaceUpdateIntervalComboBoxEntry", |
922 | &cls.updateInterval)) { | 852 | &cls.updateInterval)) |
923 | /* This should be impossible since the | 853 | { |
924 | the OK button is deactivated while parse errors are present */ | 854 | /* This should be impossible since the |
925 | mdialog = gtk_message_dialog_new | 855 | the OK button is deactivated while parse errors are present */ |
926 | (NULL, | 856 | mdialog = gtk_message_dialog_new |
927 | GTK_DIALOG_MODAL, | 857 | (NULL, |
928 | GTK_MESSAGE_ERROR, | 858 | GTK_DIALOG_MODAL, |
929 | GTK_BUTTONS_CLOSE, | 859 | GTK_MESSAGE_ERROR, |
930 | _("Failed to parse given time interval!")); | 860 | GTK_BUTTONS_CLOSE, _("Failed to parse given time interval!")); |
931 | gtk_dialog_run(GTK_DIALOG(mdialog)); | 861 | gtk_dialog_run (GTK_DIALOG (mdialog)); |
932 | gtk_widget_destroy(mdialog); | 862 | gtk_widget_destroy (mdialog); |
933 | goto CLEANUP; | 863 | goto CLEANUP; |
934 | } | 864 | } |
935 | cls.anonymityLevel | 865 | cls.anonymityLevel |
936 | = getSpinButtonValue(metaXML, | 866 | = getSpinButtonValue (metaXML, "namespaceUpdateAnonymitySpinButton"); |
937 | "namespaceUpdateAnonymitySpinButton"); | ||
938 | 867 | ||
939 | /* run actual update */ | 868 | /* run actual update */ |
940 | ggc_tree_selection_selected_foreach | 869 | ggc_tree_selection_selected_foreach |
941 | (content_selection, | 870 | (content_selection, &addToNamespaceCB, &cls); |
942 | &addToNamespaceCB, | 871 | CLEANUP: |
943 | &cls); | 872 | gtk_widget_destroy (dialog); |
944 | CLEANUP: | 873 | UNREF (metaXML); |
945 | gtk_widget_destroy(dialog); | ||
946 | UNREF(metaXML); | ||
947 | metaXML = NULL; | 874 | metaXML = NULL; |
948 | free(last); | 875 | free (last); |
949 | free(next); | 876 | free (next); |
950 | free(freq); | 877 | free (freq); |
951 | DEBUG_END(); | 878 | DEBUG_END (); |
952 | } | 879 | } |
953 | 880 | ||
954 | 881 | ||
955 | 882 | ||
956 | void fs_namespace_start() { | 883 | void |
957 | GtkWidget * contentList; | 884 | fs_namespace_start () |
958 | GtkListStore * model; | 885 | { |
959 | GtkCellRenderer * renderer; | 886 | GtkWidget *contentList; |
960 | GtkWidget * trackCheckButton; | 887 | GtkListStore *model; |
961 | GtkTreeViewColumn * column; | 888 | GtkCellRenderer *renderer; |
889 | GtkWidget *trackCheckButton; | ||
890 | GtkTreeViewColumn *column; | ||
962 | int col; | 891 | int col; |
963 | 892 | ||
964 | DEBUG_BEGIN(); | 893 | DEBUG_BEGIN (); |
965 | trackCheckButton | 894 | trackCheckButton |
966 | = glade_xml_get_widget(getMainXML(), | 895 | = glade_xml_get_widget (getMainXML (), "trackingCheckButton"); |
967 | "trackingCheckButton"); | 896 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (trackCheckButton), |
968 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(trackCheckButton), | 897 | URITRACK_trackStatus (ectx, |
969 | URITRACK_trackStatus(ectx, | 898 | cfg) == |
970 | cfg) == YES ? TRUE : FALSE); | 899 | YES ? TRUE : FALSE); |
971 | 900 | ||
972 | contentList | 901 | contentList = glade_xml_get_widget (getMainXML (), "availableContentList"); |
973 | = glade_xml_get_widget(getMainXML(), | 902 | |
974 | "availableContentList"); | 903 | model = gtk_list_store_new (NAMESPACE_NUM, G_TYPE_STRING, /* name */ |
975 | 904 | G_TYPE_UINT64, /* size */ | |
976 | model = gtk_list_store_new(NAMESPACE_NUM, | 905 | G_TYPE_STRING, /* human-readable size */ |
977 | G_TYPE_STRING, /* name */ | 906 | G_TYPE_STRING, /* uri-string */ |
978 | G_TYPE_UINT64, /* size */ | 907 | G_TYPE_POINTER, G_TYPE_POINTER); /* uri */ |
979 | G_TYPE_STRING, /* human-readable size */ | 908 | gtk_tree_view_set_model (GTK_TREE_VIEW (contentList), |
980 | G_TYPE_STRING, /* uri-string */ | 909 | GTK_TREE_MODEL (model)); |
981 | G_TYPE_POINTER, | 910 | content_selection = |
982 | G_TYPE_POINTER); /* uri */ | 911 | gtk_tree_view_get_selection (GTK_TREE_VIEW (contentList)); |
983 | gtk_tree_view_set_model(GTK_TREE_VIEW(contentList), | 912 | gtk_tree_selection_set_mode (content_selection, GTK_SELECTION_MULTIPLE); |
984 | GTK_TREE_MODEL(model)); | 913 | |
985 | content_selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(contentList)); | 914 | g_signal_connect_data (content_selection, |
986 | gtk_tree_selection_set_mode(content_selection, | 915 | "changed", |
987 | GTK_SELECTION_MULTIPLE); | 916 | G_CALLBACK (&on_namespaceContentSelectionChanged), |
988 | 917 | NULL, NULL, 0); | |
989 | g_signal_connect_data(content_selection, | 918 | |
990 | "changed", | 919 | |
991 | G_CALLBACK(&on_namespaceContentSelectionChanged), | 920 | renderer = gtk_cell_renderer_text_new (); |
992 | NULL, | 921 | col = |
993 | NULL, | 922 | gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (contentList), |
994 | 0); | 923 | -1, _("Filename"), renderer, |
995 | 924 | "text", NAMESPACE_FILENAME, | |
996 | 925 | NULL); | |
997 | renderer = gtk_cell_renderer_text_new(); | 926 | column = gtk_tree_view_get_column (GTK_TREE_VIEW (contentList), col - 1); |
998 | col = gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(contentList), | 927 | gtk_tree_view_column_set_resizable (column, TRUE); |
999 | -1, | 928 | gtk_tree_view_column_set_clickable (column, TRUE); |
1000 | _("Filename"), | 929 | gtk_tree_view_column_set_reorderable (column, TRUE); |
1001 | renderer, | 930 | gtk_tree_view_column_set_sort_column_id (column, NAMESPACE_FILENAME); |
1002 | "text", NAMESPACE_FILENAME, | 931 | /*gtk_tree_view_column_set_sort_indicator(column, TRUE); */ |
1003 | NULL); | 932 | |
1004 | column = gtk_tree_view_get_column(GTK_TREE_VIEW(contentList), | 933 | gtk_tree_view_column_set_resizable (gtk_tree_view_get_column |
1005 | col - 1); | 934 | (GTK_TREE_VIEW (contentList), col - 1), |
1006 | gtk_tree_view_column_set_resizable(column, TRUE); | 935 | TRUE); |
1007 | gtk_tree_view_column_set_clickable(column, TRUE); | 936 | renderer = gtk_cell_renderer_text_new (); |
1008 | gtk_tree_view_column_set_reorderable(column, TRUE); | ||
1009 | gtk_tree_view_column_set_sort_column_id(column, NAMESPACE_FILENAME); | ||
1010 | /*gtk_tree_view_column_set_sort_indicator(column, TRUE);*/ | ||
1011 | |||
1012 | gtk_tree_view_column_set_resizable(gtk_tree_view_get_column(GTK_TREE_VIEW(contentList), | ||
1013 | col - 1), | ||
1014 | TRUE); | ||
1015 | renderer = gtk_cell_renderer_text_new(); | ||
1016 | g_object_set (renderer, "xalign", 1.00, NULL); | 937 | g_object_set (renderer, "xalign", 1.00, NULL); |
1017 | col = gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(contentList), | 938 | col = |
1018 | -1, | 939 | gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (contentList), |
1019 | _("Filesize"), | 940 | -1, _("Filesize"), renderer, |
1020 | renderer, | 941 | "text", NAMESPACE_HSIZE, |
1021 | "text", NAMESPACE_HSIZE, | 942 | NULL); |
1022 | NULL); | 943 | column = gtk_tree_view_get_column (GTK_TREE_VIEW (contentList), col - 1); |
1023 | column = gtk_tree_view_get_column(GTK_TREE_VIEW(contentList), | 944 | gtk_tree_view_column_set_resizable (column, TRUE); |
1024 | col - 1); | 945 | gtk_tree_view_column_set_clickable (column, TRUE); |
1025 | gtk_tree_view_column_set_resizable(column, TRUE); | 946 | gtk_tree_view_column_set_reorderable (column, TRUE); |
1026 | gtk_tree_view_column_set_clickable(column, TRUE); | 947 | gtk_tree_view_column_set_sort_column_id (column, NAMESPACE_SIZE); |
1027 | gtk_tree_view_column_set_reorderable(column, TRUE); | 948 | /*gtk_tree_view_column_set_sort_indicator(column, TRUE); */ |
1028 | gtk_tree_view_column_set_sort_column_id(column, NAMESPACE_SIZE); | 949 | gtk_tree_view_column_set_resizable (gtk_tree_view_get_column |
1029 | /*gtk_tree_view_column_set_sort_indicator(column, TRUE);*/ | 950 | (GTK_TREE_VIEW (contentList), col - 1), |
1030 | gtk_tree_view_column_set_resizable(gtk_tree_view_get_column(GTK_TREE_VIEW(contentList), | 951 | TRUE); |
1031 | col - 1), | 952 | renderer = gtk_cell_renderer_text_new (); |
1032 | TRUE); | 953 | col = |
1033 | renderer = gtk_cell_renderer_text_new(); | 954 | gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (contentList), |
1034 | col = gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(contentList), | 955 | -1, _("URI"), renderer, |
1035 | -1, | 956 | "text", NAMESPACE_URISTRING, |
1036 | _("URI"), | 957 | NULL); |
1037 | renderer, | 958 | column = gtk_tree_view_get_column (GTK_TREE_VIEW (contentList), col - 1); |
1038 | "text", NAMESPACE_URISTRING, | 959 | gtk_tree_view_column_set_reorderable (column, TRUE); |
1039 | NULL); | 960 | gtk_tree_view_column_set_resizable (column, TRUE); |
1040 | column = gtk_tree_view_get_column(GTK_TREE_VIEW(contentList), | 961 | gtk_tree_view_column_set_resizable (gtk_tree_view_get_column |
1041 | col - 1); | 962 | (GTK_TREE_VIEW (contentList), col - 1), |
1042 | gtk_tree_view_column_set_reorderable(column, TRUE); | 963 | TRUE); |
1043 | gtk_tree_view_column_set_resizable(column, TRUE); | 964 | URITRACK_registerTrackCallback (ectx, cfg, &updateViewSave, NULL); |
1044 | gtk_tree_view_column_set_resizable(gtk_tree_view_get_column(GTK_TREE_VIEW(contentList), | 965 | NS_listNamespaces (ectx, cfg, &addTabForNamespace, NULL); |
1045 | col - 1), | 966 | NS_registerDiscoveryCallback (ectx, cfg, &namespace_discovered_cb, NULL); |
1046 | TRUE); | 967 | DEBUG_END (); |
1047 | URITRACK_registerTrackCallback(ectx, | ||
1048 | cfg, | ||
1049 | &updateViewSave, | ||
1050 | NULL); | ||
1051 | NS_listNamespaces(ectx, | ||
1052 | cfg, | ||
1053 | &addTabForNamespace, | ||
1054 | NULL); | ||
1055 | NS_registerDiscoveryCallback(ectx, | ||
1056 | cfg, | ||
1057 | &namespace_discovered_cb, | ||
1058 | NULL); | ||
1059 | DEBUG_END(); | ||
1060 | } | 968 | } |
1061 | 969 | ||
1062 | 970 | ||
1063 | void fs_namespace_stop() { | 971 | void |
1064 | NS_unregisterDiscoveryCallback(&namespace_discovered_cb, | 972 | fs_namespace_stop () |
1065 | NULL); | 973 | { |
974 | NS_unregisterDiscoveryCallback (&namespace_discovered_cb, NULL); | ||
1066 | while (head != NULL) | 975 | while (head != NULL) |
1067 | frame_destroy(head->treeview); | 976 | frame_destroy (head->treeview); |
1068 | URITRACK_unregisterTrackCallback(&updateViewSave, | 977 | URITRACK_unregisterTrackCallback (&updateViewSave, NULL); |
1069 | NULL); | ||
1070 | } | 978 | } |
1071 | 979 | ||
1072 | /* end of namespace.c */ | 980 | /* end of namespace.c */ |
diff --git a/src/plugins/fs/namespace.h b/src/plugins/fs/namespace.h index f0a251f5..3343e561 100644 --- a/src/plugins/fs/namespace.h +++ b/src/plugins/fs/namespace.h | |||
@@ -30,15 +30,14 @@ | |||
30 | /** | 30 | /** |
31 | * Add a tab for the given namespace. | 31 | * Add a tab for the given namespace. |
32 | */ | 32 | */ |
33 | int addTabForNamespace(void * unused, | 33 | int addTabForNamespace (void *unused, |
34 | const char * namespaceName, | 34 | const char *namespaceName, |
35 | const HashCode512 * namespaceId, | 35 | const HashCode512 * namespaceId, |
36 | const struct ECRS_MetaData * md, | 36 | const struct ECRS_MetaData *md, int rating); |
37 | int rating); | ||
38 | 37 | ||
39 | 38 | ||
40 | void fs_namespace_start(void); | 39 | void fs_namespace_start (void); |
41 | 40 | ||
42 | void fs_namespace_stop(void); | 41 | void fs_namespace_stop (void); |
43 | 42 | ||
44 | #endif | 43 | #endif |
diff --git a/src/plugins/fs/namespace_create.c b/src/plugins/fs/namespace_create.c index cdd24912..1182c0a6 100644 --- a/src/plugins/fs/namespace_create.c +++ b/src/plugins/fs/namespace_create.c | |||
@@ -37,224 +37,220 @@ | |||
37 | #include <extractor.h> | 37 | #include <extractor.h> |
38 | 38 | ||
39 | 39 | ||
40 | static GladeXML * metaXML; | 40 | static GladeXML *metaXML; |
41 | 41 | ||
42 | 42 | ||
43 | void on_namespacemetaDataDialogKeywordRemoveButton_clicked_fs(gpointer dummy, | 43 | void |
44 | GtkWidget * uploadButton) { | 44 | on_namespacemetaDataDialogKeywordRemoveButton_clicked_fs (gpointer dummy, |
45 | handleListRemove(metaXML, | 45 | GtkWidget * |
46 | "namespaceMetaDataDialogKeywordList"); | 46 | uploadButton) |
47 | { | ||
48 | handleListRemove (metaXML, "namespaceMetaDataDialogKeywordList"); | ||
47 | } | 49 | } |
48 | 50 | ||
49 | void on_namespacemetaDataDialogMetaDataRemoveButton_clicked_fs(gpointer dummy, | 51 | void |
50 | GtkWidget * uploadButton) { | 52 | on_namespacemetaDataDialogMetaDataRemoveButton_clicked_fs (gpointer dummy, |
51 | handleListRemove(metaXML, | 53 | GtkWidget * |
52 | "namespaceMetaDataDialogMetaDataList"); | 54 | uploadButton) |
55 | { | ||
56 | handleListRemove (metaXML, "namespaceMetaDataDialogMetaDataList"); | ||
53 | } | 57 | } |
54 | 58 | ||
55 | void on_namespacemetaDataDialogKeywordAddButton_clicked_fs(gpointer dummy, | 59 | void |
56 | GtkWidget * uploadButton) { | 60 | on_namespacemetaDataDialogKeywordAddButton_clicked_fs (gpointer dummy, |
57 | handleKeywordListUpdate(metaXML, | 61 | GtkWidget * |
58 | "namespaceKeywordEntry", | 62 | uploadButton) |
59 | "namespaceMetaDataDialogKeywordList"); | 63 | { |
64 | handleKeywordListUpdate (metaXML, | ||
65 | "namespaceKeywordEntry", | ||
66 | "namespaceMetaDataDialogKeywordList"); | ||
60 | } | 67 | } |
61 | 68 | ||
62 | void on_namespacemetaDataDialogMetaDataAddButton_clicked_fs(gpointer dummy, | 69 | void |
63 | GtkWidget * uploadButton) { | 70 | on_namespacemetaDataDialogMetaDataAddButton_clicked_fs (gpointer dummy, |
64 | handleMetaDataListUpdate(metaXML, | 71 | GtkWidget * |
65 | "namespaceMetaDataDialogMetaTypeComboBox", | 72 | uploadButton) |
66 | "namespaceMetaDataValueEntry", | 73 | { |
67 | "namespaceMetaDataDialogMetaDataList"); | 74 | handleMetaDataListUpdate (metaXML, |
75 | "namespaceMetaDataDialogMetaTypeComboBox", | ||
76 | "namespaceMetaDataValueEntry", | ||
77 | "namespaceMetaDataDialogMetaDataList"); | ||
68 | } | 78 | } |
69 | 79 | ||
70 | /** | 80 | /** |
71 | * The selection of the keyword list changed. | 81 | * The selection of the keyword list changed. |
72 | * Update button status. | 82 | * Update button status. |
73 | */ | 83 | */ |
74 | static void on_keyword_list_selection_changed(gpointer signal, | 84 | static void |
75 | gpointer cls) { | 85 | on_keyword_list_selection_changed (gpointer signal, gpointer cls) |
76 | GtkTreeSelection * selection; | 86 | { |
77 | GtkWidget * button; | 87 | GtkTreeSelection *selection; |
88 | GtkWidget *button; | ||
78 | 89 | ||
79 | selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(glade_xml_get_widget(metaXML, | 90 | selection = |
80 | "namespaceMetaDataDialogKeywordList"))); | 91 | gtk_tree_view_get_selection (GTK_TREE_VIEW |
81 | button | 92 | (glade_xml_get_widget |
82 | = glade_xml_get_widget(metaXML, | 93 | (metaXML, |
83 | "nsMetaDataDialogKeywordRemoveButton"); | 94 | "namespaceMetaDataDialogKeywordList"))); |
84 | gtk_widget_set_sensitive(button, | 95 | button = |
85 | gtk_tree_selection_count_selected_rows(selection) > 0); | 96 | glade_xml_get_widget (metaXML, "nsMetaDataDialogKeywordRemoveButton"); |
97 | gtk_widget_set_sensitive (button, | ||
98 | gtk_tree_selection_count_selected_rows (selection) | ||
99 | > 0); | ||
86 | } | 100 | } |
87 | 101 | ||
88 | /** | 102 | /** |
89 | * The selection of the metadata list changed. | 103 | * The selection of the metadata list changed. |
90 | * Update button status. | 104 | * Update button status. |
91 | */ | 105 | */ |
92 | static void on_metadata_list_selection_changed(gpointer signal, | 106 | static void |
93 | gpointer cls) { | 107 | on_metadata_list_selection_changed (gpointer signal, gpointer cls) |
94 | GtkTreeSelection * selection; | 108 | { |
95 | GtkWidget * button; | 109 | GtkTreeSelection *selection; |
110 | GtkWidget *button; | ||
96 | 111 | ||
97 | selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(glade_xml_get_widget(metaXML, | 112 | selection = |
98 | "namespaceMetaDataDialogMetaDataList"))); | 113 | gtk_tree_view_get_selection (GTK_TREE_VIEW |
99 | button | 114 | (glade_xml_get_widget |
100 | = glade_xml_get_widget(metaXML, | 115 | (metaXML, |
101 | "nsMetaDataDialogMetaDataRemoveButton"); | 116 | "namespaceMetaDataDialogMetaDataList"))); |
102 | gtk_widget_set_sensitive(button, | 117 | button = |
103 | gtk_tree_selection_count_selected_rows(selection) > 0); | 118 | glade_xml_get_widget (metaXML, "nsMetaDataDialogMetaDataRemoveButton"); |
119 | gtk_widget_set_sensitive (button, | ||
120 | gtk_tree_selection_count_selected_rows (selection) | ||
121 | > 0); | ||
104 | } | 122 | } |
105 | 123 | ||
106 | /** | 124 | /** |
107 | * The user has edited the metadata entry. | 125 | * The user has edited the metadata entry. |
108 | * Update add button status. | 126 | * Update add button status. |
109 | */ | 127 | */ |
110 | void on_namespaceMetaDataValueEntry_changed_fs(gpointer dummy2, | 128 | void |
111 | GtkWidget * searchEntry) { | 129 | on_namespaceMetaDataValueEntry_changed_fs (gpointer dummy2, |
112 | const char * input; | 130 | GtkWidget * searchEntry) |
113 | GtkWidget * button; | 131 | { |
132 | const char *input; | ||
133 | GtkWidget *button; | ||
114 | 134 | ||
115 | input = gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(metaXML, | 135 | input = gtk_entry_get_text (GTK_ENTRY (glade_xml_get_widget (metaXML, |
116 | "namespaceMetaDataValueEntry"))); | 136 | "namespaceMetaDataValueEntry"))); |
117 | if (input == NULL) | 137 | if (input == NULL) |
118 | return; | 138 | return; |
119 | button | 139 | button |
120 | = glade_xml_get_widget(metaXML, | 140 | = glade_xml_get_widget (metaXML, "nsMetaDataDialogMetaDataAddButton"); |
121 | "nsMetaDataDialogMetaDataAddButton"); | 141 | gtk_widget_set_sensitive (button, strlen (input) > 0); |
122 | gtk_widget_set_sensitive(button, | ||
123 | strlen(input) > 0); | ||
124 | } | 142 | } |
125 | 143 | ||
126 | /** | 144 | /** |
127 | * The user has edited the keyword entry. | 145 | * The user has edited the keyword entry. |
128 | * Update add button status. | 146 | * Update add button status. |
129 | */ | 147 | */ |
130 | void on_namespaceKeywordEntry_changed_fs(gpointer dummy2, | 148 | void |
131 | GtkWidget * searchEntry) { | 149 | on_namespaceKeywordEntry_changed_fs (gpointer dummy2, GtkWidget * searchEntry) |
132 | const char * input; | 150 | { |
133 | GtkWidget * button; | 151 | const char *input; |
152 | GtkWidget *button; | ||
134 | 153 | ||
135 | input = gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(metaXML, | 154 | input = gtk_entry_get_text (GTK_ENTRY (glade_xml_get_widget (metaXML, |
136 | "namespaceKeywordEntry"))); | 155 | "namespaceKeywordEntry"))); |
137 | if (input == NULL) | 156 | if (input == NULL) |
138 | return; | 157 | return; |
139 | button | 158 | button = glade_xml_get_widget (metaXML, "nsMetaDataDialogKeywordAddButton"); |
140 | = glade_xml_get_widget(metaXML, | 159 | gtk_widget_set_sensitive (button, strlen (input) > 0); |
141 | "nsMetaDataDialogKeywordAddButton"); | ||
142 | gtk_widget_set_sensitive(button, | ||
143 | strlen(input) > 0); | ||
144 | } | 160 | } |
145 | 161 | ||
146 | 162 | ||
147 | void create_namespace_clicked_fs(GtkWidget * dummy1, | 163 | void |
148 | GtkWidget * dummy2) { | 164 | create_namespace_clicked_fs (GtkWidget * dummy1, GtkWidget * dummy2) |
149 | const char * namespaceName; | 165 | { |
150 | GtkWidget * nameLine; | 166 | const char *namespaceName; |
151 | GtkWidget * dialog; | 167 | GtkWidget *nameLine; |
152 | GtkWidget * spin; | 168 | GtkWidget *dialog; |
153 | struct ECRS_MetaData * meta; | 169 | GtkWidget *spin; |
154 | struct ECRS_URI * keywordURI; | 170 | struct ECRS_MetaData *meta; |
155 | struct ECRS_URI * root; | 171 | struct ECRS_URI *keywordURI; |
172 | struct ECRS_URI *root; | ||
156 | HashCode512 namespaceId; | 173 | HashCode512 namespaceId; |
157 | HashCode512 rootEntry; | 174 | HashCode512 rootEntry; |
158 | 175 | ||
159 | DEBUG_BEGIN(); | 176 | DEBUG_BEGIN (); |
160 | metaXML | 177 | metaXML |
161 | = glade_xml_new(getGladeFileName(), | 178 | = glade_xml_new (getGladeFileName (), |
162 | "namespaceMetaDataDialog", | 179 | "namespaceMetaDataDialog", PACKAGE_NAME); |
163 | PACKAGE_NAME); | 180 | connectGladeWithPlugins (metaXML); |
164 | connectGladeWithPlugins(metaXML); | 181 | dialog = glade_xml_get_widget (metaXML, "namespaceMetaDataDialog"); |
165 | dialog = glade_xml_get_widget(metaXML, | 182 | createMetaDataListTreeView (metaXML, |
166 | "namespaceMetaDataDialog"); | 183 | "namespaceMetaDataDialogMetaDataList", |
167 | createMetaDataListTreeView(metaXML, | 184 | NULL, NULL); |
168 | "namespaceMetaDataDialogMetaDataList", | 185 | g_signal_connect_data (gtk_tree_view_get_selection |
169 | NULL, | 186 | (GTK_TREE_VIEW |
170 | NULL); | 187 | (glade_xml_get_widget |
171 | g_signal_connect_data(gtk_tree_view_get_selection(GTK_TREE_VIEW(glade_xml_get_widget(metaXML, | 188 | (metaXML, "namespaceMetaDataDialogMetaDataList"))), |
172 | "namespaceMetaDataDialogMetaDataList"))), | 189 | "changed", |
173 | "changed", | 190 | G_CALLBACK (&on_metadata_list_selection_changed), |
174 | G_CALLBACK(&on_metadata_list_selection_changed), | 191 | NULL, NULL, 0); |
175 | NULL, | 192 | createKeywordListTreeView (metaXML, "namespaceMetaDataDialogKeywordList", |
176 | NULL, | 193 | NULL); |
177 | 0); | 194 | g_signal_connect_data (gtk_tree_view_get_selection |
178 | createKeywordListTreeView(metaXML, | 195 | (GTK_TREE_VIEW |
179 | "namespaceMetaDataDialogKeywordList", | 196 | (glade_xml_get_widget |
180 | NULL); | 197 | (metaXML, "namespaceMetaDataDialogKeywordList"))), |
181 | g_signal_connect_data(gtk_tree_view_get_selection(GTK_TREE_VIEW(glade_xml_get_widget(metaXML, | 198 | "changed", |
182 | "namespaceMetaDataDialogKeywordList"))), | 199 | G_CALLBACK (&on_keyword_list_selection_changed), |
183 | "changed", | 200 | NULL, NULL, 0); |
184 | G_CALLBACK(&on_keyword_list_selection_changed), | ||
185 | NULL, | ||
186 | NULL, | ||
187 | 0); | ||
188 | 201 | ||
189 | createMetaTypeComboBox(metaXML, | 202 | createMetaTypeComboBox (metaXML, "namespaceMetaDataDialogMetaTypeComboBox"); |
190 | "namespaceMetaDataDialogMetaTypeComboBox"); | 203 | gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); |
191 | gtk_dialog_set_default_response(GTK_DIALOG(dialog), | 204 | if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) |
192 | GTK_RESPONSE_OK); | 205 | { |
193 | if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) { | 206 | meta |
194 | meta | 207 | = getMetaDataFromList (metaXML, |
195 | = getMetaDataFromList(metaXML, | 208 | "namespaceMetaDataDialogMetaDataList", NULL); |
196 | "namespaceMetaDataDialogMetaDataList", | 209 | keywordURI |
197 | NULL); | 210 | = getKeywordURIFromList (metaXML, |
198 | keywordURI | 211 | "namespaceMetaDataDialogKeywordList"); |
199 | = getKeywordURIFromList(metaXML, | 212 | spin = glade_xml_get_widget (metaXML, "namespaceAnonymityspinbutton"); |
200 | "namespaceMetaDataDialogKeywordList"); | 213 | nameLine = glade_xml_get_widget (metaXML, "namespaceRootEntry"); |
201 | spin = glade_xml_get_widget(metaXML, | 214 | namespaceName = gtk_entry_get_text (GTK_ENTRY (nameLine)); |
202 | "namespaceAnonymityspinbutton"); | 215 | if (namespaceName == NULL) |
203 | nameLine = glade_xml_get_widget(metaXML, | 216 | namespaceName = "root"; /* do NOT translate "root"! */ |
204 | "namespaceRootEntry"); | 217 | hash (namespaceName, strlen (namespaceName), &rootEntry); |
205 | namespaceName = gtk_entry_get_text(GTK_ENTRY(nameLine)); | 218 | nameLine = glade_xml_get_widget (metaXML, "namespaceNameEntry"); |
206 | if (namespaceName == NULL) | 219 | namespaceName = gtk_entry_get_text (GTK_ENTRY (nameLine)); |
207 | namespaceName = "root"; /* do NOT translate "root"! */ | 220 | root = NS_createNamespace (ectx, cfg, gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (spin)), 1000, /* FIXME: priority */ |
208 | hash(namespaceName, | 221 | get_time () + 2 * cronYEARS, /* FIXME: expiration */ |
209 | strlen(namespaceName), | 222 | namespaceName, meta, keywordURI, &rootEntry); |
210 | &rootEntry); | 223 | if (root != NULL) |
211 | nameLine = glade_xml_get_widget(metaXML, | 224 | { |
212 | "namespaceNameEntry"); | 225 | ECRS_getNamespaceId (root, &namespaceId); |
213 | namespaceName = gtk_entry_get_text(GTK_ENTRY(nameLine)); | 226 | addTabForNamespace (NULL, namespaceName, &namespaceId, meta, 0); |
214 | root = NS_createNamespace(ectx, | 227 | ECRS_freeUri (root); |
215 | cfg, | 228 | } |
216 | gtk_spin_button_get_value_as_int | 229 | else |
217 | (GTK_SPIN_BUTTON(spin)), | 230 | { |
218 | 1000, /* FIXME: priority */ | 231 | GtkWidget *dialog; |
219 | get_time() + 2 * cronYEARS, /* FIXME: expiration */ | ||
220 | namespaceName, | ||
221 | meta, | ||
222 | keywordURI, | ||
223 | &rootEntry); | ||
224 | if (root != NULL) { | ||
225 | ECRS_getNamespaceId(root, | ||
226 | &namespaceId); | ||
227 | addTabForNamespace(NULL, | ||
228 | namespaceName, | ||
229 | &namespaceId, | ||
230 | meta, | ||
231 | 0); | ||
232 | ECRS_freeUri(root); | ||
233 | } else { | ||
234 | GtkWidget * dialog; | ||
235 | 232 | ||
236 | /* IMPROVE-ME: we could check if the | 233 | /* IMPROVE-ME: we could check if the |
237 | namespace exists as the user | 234 | namespace exists as the user |
238 | enters its name and disable the | 235 | enters its name and disable the |
239 | "Ok" button unless the name is unique */ | 236 | "Ok" button unless the name is unique */ |
240 | dialog = gtk_message_dialog_new | 237 | dialog = gtk_message_dialog_new |
241 | (NULL, | 238 | (NULL, |
242 | GTK_DIALOG_MODAL, | 239 | GTK_DIALOG_MODAL, |
243 | GTK_MESSAGE_ERROR, | 240 | GTK_MESSAGE_ERROR, |
244 | GTK_BUTTONS_CLOSE, | 241 | GTK_BUTTONS_CLOSE, |
245 | _("Failed to create namespace `%s'." | 242 | _("Failed to create namespace `%s'." |
246 | "Consult logs, most likely error is" | 243 | "Consult logs, most likely error is" |
247 | " that a namespace with that name " | 244 | " that a namespace with that name " |
248 | "already exists."), | 245 | "already exists."), namespaceName); |
249 | namespaceName); | 246 | gtk_dialog_run (GTK_DIALOG (dialog)); |
250 | gtk_dialog_run(GTK_DIALOG(dialog)); | 247 | gtk_widget_destroy (dialog); |
251 | gtk_widget_destroy(dialog); | 248 | } |
249 | ECRS_freeMetaData (meta); | ||
250 | ECRS_freeUri (keywordURI); | ||
252 | } | 251 | } |
253 | ECRS_freeMetaData(meta); | 252 | gtk_widget_destroy (dialog); |
254 | ECRS_freeUri(keywordURI); | 253 | UNREF (metaXML); |
255 | } | ||
256 | gtk_widget_destroy(dialog); | ||
257 | UNREF(metaXML); | ||
258 | metaXML = NULL; | 254 | metaXML = NULL; |
259 | DEBUG_END(); | 255 | DEBUG_END (); |
260 | } | 256 | } |
diff --git a/src/plugins/fs/namespace_search.c b/src/plugins/fs/namespace_search.c index 5a15194b..d89297f6 100644 --- a/src/plugins/fs/namespace_search.c +++ b/src/plugins/fs/namespace_search.c | |||
@@ -39,73 +39,67 @@ | |||
39 | * The spin button giving the rating for a particular namespace | 39 | * The spin button giving the rating for a particular namespace |
40 | * has been changed. Store the new rating for the namespace. | 40 | * has been changed. Store the new rating for the namespace. |
41 | */ | 41 | */ |
42 | void on_namespaceRatingSpinButton_changed_fs(GtkWidget * dummy, | 42 | void |
43 | GtkWidget * dummy2) { | 43 | on_namespaceRatingSpinButton_changed_fs (GtkWidget * dummy, |
44 | GtkWidget * spin; | 44 | GtkWidget * dummy2) |
45 | GtkWidget * ncbe; | 45 | { |
46 | GtkTreeModel * model; | 46 | GtkWidget *spin; |
47 | GtkWidget *ncbe; | ||
48 | GtkTreeModel *model; | ||
47 | GtkTreeIter iter; | 49 | GtkTreeIter iter; |
48 | char * encStr; | 50 | char *encStr; |
49 | char * description; | 51 | char *description; |
50 | int rating; | 52 | int rating; |
51 | int newrating; | 53 | int newrating; |
52 | 54 | ||
53 | DEBUG_BEGIN(); | 55 | DEBUG_BEGIN (); |
54 | spin | 56 | spin = glade_xml_get_widget (getMainXML (), "namespaceRatingSpinButton"); |
55 | = glade_xml_get_widget(getMainXML(), | 57 | ncbe = glade_xml_get_widget (getMainXML (), "searchNamespaceComboBoxEntry"); |
56 | "namespaceRatingSpinButton"); | 58 | model = gtk_combo_box_get_model (GTK_COMBO_BOX (ncbe)); |
57 | ncbe | ||
58 | = glade_xml_get_widget(getMainXML(), | ||
59 | "searchNamespaceComboBoxEntry"); | ||
60 | model = gtk_combo_box_get_model(GTK_COMBO_BOX(ncbe)); | ||
61 | description = NULL; | 59 | description = NULL; |
62 | encStr = NULL; | 60 | encStr = NULL; |
63 | if (TRUE == gtk_combo_box_get_active_iter(GTK_COMBO_BOX(ncbe), | 61 | if (TRUE == gtk_combo_box_get_active_iter (GTK_COMBO_BOX (ncbe), &iter)) |
64 | &iter)) { | 62 | { |
65 | gtk_tree_model_get(model, | 63 | gtk_tree_model_get (model, |
66 | &iter, | 64 | &iter, |
67 | NS_SEARCH_DESCRIPTION, &description, | 65 | NS_SEARCH_DESCRIPTION, &description, |
68 | NS_SEARCH_ENCNAME, &encStr, | 66 | NS_SEARCH_ENCNAME, &encStr, |
69 | NS_SEARCH_RATING, &rating, | 67 | NS_SEARCH_RATING, &rating, -1); |
70 | -1); | 68 | if ((description != NULL) && (0 == strcmp (description, _("globally")))) |
71 | if ( (description != NULL) && | 69 | { |
72 | (0 == strcmp(description, | 70 | /* just to be sure */ |
73 | _("globally"))) ) { | 71 | gtk_widget_set_sensitive (spin, FALSE); |
74 | /* just to be sure */ | 72 | } |
75 | gtk_widget_set_sensitive(spin, | 73 | else |
76 | FALSE); | 74 | { |
77 | } else { | 75 | if (encStr != NULL) |
78 | if (encStr != NULL) { | 76 | { |
79 | newrating = gtk_spin_button_get_value(GTK_SPIN_BUTTON(spin)); | 77 | newrating = gtk_spin_button_get_value (GTK_SPIN_BUTTON (spin)); |
80 | rating = NS_rankNamespace(ectx, | 78 | rating = NS_rankNamespace (ectx, |
81 | cfg, | 79 | cfg, encStr, newrating - rating); |
82 | encStr, | 80 | if (rating != newrating) |
83 | newrating - rating); | 81 | { |
84 | if (rating != newrating) { | 82 | /* concurrent modification? */ |
85 | /* concurrent modification? */ | 83 | gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin), rating); |
86 | gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin), | 84 | GE_BREAK (ectx, 0); |
87 | rating); | 85 | } |
88 | GE_BREAK(ectx, 0); | 86 | gtk_list_store_set (GTK_LIST_STORE (model), |
89 | } | 87 | &iter, NS_SEARCH_RATING, rating, -1); |
90 | gtk_list_store_set(GTK_LIST_STORE(model), | 88 | } |
91 | &iter, | 89 | } |
92 | NS_SEARCH_RATING, rating, | 90 | } |
93 | -1); | 91 | else |
94 | } | 92 | { |
93 | /* FIXME: if enc2hash succeeds, we may want to keep this | ||
94 | active */ | ||
95 | gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin), 0); | ||
96 | gtk_widget_set_sensitive (spin, FALSE); | ||
95 | } | 97 | } |
96 | } else { | ||
97 | /* FIXME: if enc2hash succeeds, we may want to keep this | ||
98 | active */ | ||
99 | gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin), | ||
100 | 0); | ||
101 | gtk_widget_set_sensitive(spin, | ||
102 | FALSE); | ||
103 | } | ||
104 | if (description != NULL) | 98 | if (description != NULL) |
105 | free(description); | 99 | free (description); |
106 | if (encStr != NULL) | 100 | if (encStr != NULL) |
107 | free(encStr); | 101 | free (encStr); |
108 | DEBUG_END(); | 102 | DEBUG_END (); |
109 | } | 103 | } |
110 | 104 | ||
111 | 105 | ||
@@ -114,175 +108,159 @@ void on_namespaceRatingSpinButton_changed_fs(GtkWidget * dummy, | |||
114 | * Update the trust level (possibly changing sensitivity) | 108 | * Update the trust level (possibly changing sensitivity) |
115 | * and set the search string to the root (if available). | 109 | * and set the search string to the root (if available). |
116 | */ | 110 | */ |
117 | void on_searchNamespaceComboBoxEntry_changed_fs(GtkWidget * dummy, | 111 | void |
118 | GtkWidget * dummy2) { | 112 | on_searchNamespaceComboBoxEntry_changed_fs (GtkWidget * dummy, |
119 | GtkWidget * keyword; | 113 | GtkWidget * dummy2) |
120 | GtkWidget * spin; | 114 | { |
121 | GtkWidget * ncbe; | 115 | GtkWidget *keyword; |
122 | GtkTreeModel * model; | 116 | GtkWidget *spin; |
117 | GtkWidget *ncbe; | ||
118 | GtkTreeModel *model; | ||
123 | GtkTreeIter iter; | 119 | GtkTreeIter iter; |
124 | int rating; | 120 | int rating; |
125 | char * encStr; | 121 | char *encStr; |
126 | char * descStr; | 122 | char *descStr; |
127 | HashCode512 ns; | 123 | HashCode512 ns; |
128 | HashCode512 root; | 124 | HashCode512 root; |
129 | EncName enc; | 125 | EncName enc; |
130 | 126 | ||
131 | DEBUG_BEGIN(); | 127 | DEBUG_BEGIN (); |
132 | spin | 128 | spin = glade_xml_get_widget (getMainXML (), "namespaceRatingSpinButton"); |
133 | = glade_xml_get_widget(getMainXML(), | 129 | ncbe = glade_xml_get_widget (getMainXML (), "searchNamespaceComboBoxEntry"); |
134 | "namespaceRatingSpinButton"); | 130 | model = gtk_combo_box_get_model (GTK_COMBO_BOX (ncbe)); |
135 | ncbe | ||
136 | = glade_xml_get_widget(getMainXML(), | ||
137 | "searchNamespaceComboBoxEntry"); | ||
138 | model = gtk_combo_box_get_model(GTK_COMBO_BOX(ncbe)); | ||
139 | descStr = NULL; | 131 | descStr = NULL; |
140 | encStr = NULL; | 132 | encStr = NULL; |
141 | if (TRUE == gtk_combo_box_get_active_iter(GTK_COMBO_BOX(ncbe), | 133 | if (TRUE == gtk_combo_box_get_active_iter (GTK_COMBO_BOX (ncbe), &iter)) |
142 | &iter)) { | 134 | { |
143 | gtk_tree_model_get(model, | 135 | gtk_tree_model_get (model, |
144 | &iter, | 136 | &iter, |
145 | NS_SEARCH_DESCRIPTION, &descStr, | 137 | NS_SEARCH_DESCRIPTION, &descStr, |
146 | NS_SEARCH_ENCNAME, &encStr, | 138 | NS_SEARCH_ENCNAME, &encStr, |
147 | NS_SEARCH_RATING, &rating, | 139 | NS_SEARCH_RATING, &rating, -1); |
148 | -1); | 140 | if ((descStr != NULL) && (0 == strcmp (descStr, _("globally")))) |
149 | if ( (descStr != NULL) && | 141 | { |
150 | (0 == strcmp(descStr, | 142 | gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin), 0); |
151 | _("globally"))) ) { | 143 | gtk_widget_set_sensitive (spin, FALSE); |
152 | gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin), | 144 | } |
153 | 0); | 145 | else if (encStr != NULL) |
154 | gtk_widget_set_sensitive(spin, | 146 | { |
155 | FALSE); | 147 | enc2hash (encStr, &ns); |
156 | } else if (encStr != NULL) { | 148 | gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin), rating); |
157 | enc2hash(encStr, | 149 | gtk_widget_set_sensitive (spin, TRUE); |
158 | &ns); | 150 | keyword |
159 | gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin), | 151 | = glade_xml_get_widget (getMainXML (), |
160 | rating); | 152 | "fssearchKeywordComboBoxEntry"); |
161 | gtk_widget_set_sensitive(spin, | 153 | if (OK == NS_getNamespaceRoot (ectx, cfg, encStr, &root)) |
162 | TRUE); | 154 | { |
163 | keyword | 155 | hash2enc (&root, &enc); |
164 | = glade_xml_get_widget(getMainXML(), | 156 | gtk_entry_set_text (GTK_ENTRY |
165 | "fssearchKeywordComboBoxEntry"); | 157 | (gtk_bin_get_child (GTK_BIN (keyword))), |
166 | if (OK == NS_getNamespaceRoot(ectx, | 158 | (const gchar *) &enc); |
167 | cfg, | 159 | } |
168 | encStr, | 160 | else |
169 | &root)) { | 161 | { |
170 | hash2enc(&root, | 162 | gtk_entry_set_text (GTK_ENTRY |
171 | &enc); | 163 | (gtk_bin_get_child (GTK_BIN (keyword))), |
172 | gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(keyword))), | 164 | ""); |
173 | (const gchar*) &enc); | 165 | } |
174 | } else { | 166 | } |
175 | gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(keyword))), | 167 | } |
176 | ""); | 168 | else |
177 | } | 169 | { |
170 | gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin), 0); | ||
171 | gtk_widget_set_sensitive (spin, FALSE); | ||
178 | } | 172 | } |
179 | } else { | ||
180 | gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin), | ||
181 | 0); | ||
182 | gtk_widget_set_sensitive(spin, | ||
183 | FALSE); | ||
184 | } | ||
185 | if (descStr != NULL) | 173 | if (descStr != NULL) |
186 | free(descStr); | 174 | free (descStr); |
187 | if (encStr != NULL) | 175 | if (encStr != NULL) |
188 | free(encStr); | 176 | free (encStr); |
189 | DEBUG_END(); | 177 | DEBUG_END (); |
190 | } | 178 | } |
191 | 179 | ||
192 | struct NewNamespaceInfo { | 180 | struct NewNamespaceInfo |
193 | const char * namespaceName; | 181 | { |
194 | const HashCode512 * namespaceId; | 182 | const char *namespaceName; |
195 | const struct ECRS_MetaData * md; | 183 | const HashCode512 *namespaceId; |
184 | const struct ECRS_MetaData *md; | ||
196 | int rating; | 185 | int rating; |
197 | }; | 186 | }; |
198 | 187 | ||
199 | static void * saveDiscovery(void * cls) { | 188 | static void * |
200 | struct NewNamespaceInfo * nni = cls; | 189 | saveDiscovery (void *cls) |
190 | { | ||
191 | struct NewNamespaceInfo *nni = cls; | ||
201 | 192 | ||
202 | GtkListStore * model; | 193 | GtkListStore *model; |
203 | GtkTreeIter iter; | 194 | GtkTreeIter iter; |
204 | EncName enc; | 195 | EncName enc; |
205 | char * name; | 196 | char *name; |
206 | struct ECRS_MetaData * dmd; | 197 | struct ECRS_MetaData *dmd; |
207 | GtkWidget * ncbe; | 198 | GtkWidget *ncbe; |
208 | char * desc; | 199 | char *desc; |
209 | size_t n; | 200 | size_t n; |
210 | int found; | 201 | int found; |
211 | char * encName; | 202 | char *encName; |
212 | 203 | ||
213 | DEBUG_BEGIN(); | 204 | DEBUG_BEGIN (); |
214 | ncbe | 205 | ncbe = glade_xml_get_widget (getMainXML (), "searchNamespaceComboBoxEntry"); |
215 | = glade_xml_get_widget(getMainXML(), | 206 | model = GTK_LIST_STORE (gtk_combo_box_get_model (GTK_COMBO_BOX (ncbe))); |
216 | "searchNamespaceComboBoxEntry"); | 207 | hash2enc (nni->namespaceId, &enc); |
217 | model = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(ncbe))); | 208 | if (nni->md == NULL) |
218 | hash2enc(nni->namespaceId, | 209 | { |
219 | &enc); | 210 | dmd = NULL; |
220 | if (nni->md == NULL) { | 211 | desc = STRDUP (""); |
221 | dmd = NULL; | 212 | } |
222 | desc = STRDUP(""); | 213 | else |
223 | } else { | 214 | { |
224 | dmd = ECRS_dupMetaData(nni->md); | 215 | dmd = ECRS_dupMetaData (nni->md); |
225 | desc = ECRS_getFirstFromMetaData(dmd, | 216 | desc = ECRS_getFirstFromMetaData (dmd, |
226 | EXTRACTOR_DESCRIPTION, | 217 | EXTRACTOR_DESCRIPTION, |
227 | EXTRACTOR_TITLE, | 218 | EXTRACTOR_TITLE, |
228 | EXTRACTOR_AUTHOR, | 219 | EXTRACTOR_AUTHOR, |
229 | EXTRACTOR_GENRE, | 220 | EXTRACTOR_GENRE, |
230 | EXTRACTOR_SUBJECT, | 221 | EXTRACTOR_SUBJECT, |
231 | EXTRACTOR_CREATOR, | 222 | EXTRACTOR_CREATOR, |
232 | EXTRACTOR_PRODUCER, | 223 | EXTRACTOR_PRODUCER, |
233 | EXTRACTOR_GROUP, | 224 | EXTRACTOR_GROUP, |
234 | EXTRACTOR_CREATED_FOR, | 225 | EXTRACTOR_CREATED_FOR, |
235 | EXTRACTOR_SUMMARY, | 226 | EXTRACTOR_SUMMARY, |
236 | EXTRACTOR_OWNER, | 227 | EXTRACTOR_OWNER, -1); |
237 | -1); | 228 | if (desc == NULL) |
238 | if (desc == NULL) | 229 | desc = STRDUP (""); |
239 | desc = STRDUP(""); | 230 | } |
240 | } | ||
241 | 231 | ||
242 | n = strlen(desc) + 64; | 232 | n = strlen (desc) + 64; |
243 | name = MALLOC(n); | 233 | name = MALLOC (n); |
244 | SNPRINTF(name, | 234 | SNPRINTF (name, n, "%s: %.*s", desc, 20, &enc); |
245 | n, | ||
246 | "%s: %.*s", | ||
247 | desc, | ||
248 | 20, | ||
249 | &enc); | ||
250 | /* check if present! */ | 235 | /* check if present! */ |
251 | found = NO; | 236 | found = NO; |
252 | if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model), | 237 | if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (model), &iter)) |
253 | &iter)) { | 238 | { |
254 | do { | 239 | do |
255 | gtk_tree_model_get(GTK_TREE_MODEL(model), | 240 | { |
256 | &iter, | 241 | gtk_tree_model_get (GTK_TREE_MODEL (model), |
257 | NS_SEARCH_ENCNAME, &encName, | 242 | &iter, NS_SEARCH_ENCNAME, &encName, -1); |
258 | -1); | 243 | if ((encName != NULL) && |
259 | if ( (encName != NULL) && | 244 | (0 == strcmp (encName, (const char *) &enc))) |
260 | (0 == strcmp(encName, | 245 | found = YES; |
261 | (const char*) &enc)) ) | 246 | FREENONNULL (encName); |
262 | found =YES; | 247 | } |
263 | FREENONNULL(encName); | 248 | while ((found == NO) && |
264 | } while ( (found == NO) && | 249 | (gtk_tree_model_iter_next (GTK_TREE_MODEL (model), &iter))); |
265 | (gtk_tree_model_iter_next(GTK_TREE_MODEL(model), | 250 | } |
266 | &iter)) ); | 251 | if (found == NO) |
267 | } | 252 | { |
268 | if (found == NO) { | 253 | infoMessage (YES, _("Namespace found: %s - %.*s\n"), desc, 20, &enc); |
269 | infoMessage(YES, | 254 | gtk_list_store_append (model, &iter); |
270 | _("Namespace found: %s - %.*s\n"), | 255 | gtk_list_store_set (model, |
271 | desc, | 256 | &iter, |
272 | 20, | 257 | NS_SEARCH_DESCRIPTION, name, |
273 | &enc); | 258 | NS_SEARCH_ENCNAME, &enc, |
274 | gtk_list_store_append(model, | 259 | NS_SEARCH_METADATA, dmd, |
275 | &iter); | 260 | NS_SEARCH_RATING, nni->rating, -1); |
276 | gtk_list_store_set(model, | 261 | } |
277 | &iter, | 262 | FREE (name); |
278 | NS_SEARCH_DESCRIPTION, name, | 263 | DEBUG_END (); |
279 | NS_SEARCH_ENCNAME, &enc, | ||
280 | NS_SEARCH_METADATA, dmd, | ||
281 | NS_SEARCH_RATING, nni->rating, | ||
282 | -1); | ||
283 | } | ||
284 | FREE(name); | ||
285 | DEBUG_END(); | ||
286 | 264 | ||
287 | return NULL; | 265 | return NULL; |
288 | } | 266 | } |
@@ -299,17 +277,17 @@ static void * saveDiscovery(void * cls) { | |||
299 | * @param rating the local rating of the namespace | 277 | * @param rating the local rating of the namespace |
300 | * @return OK (always) | 278 | * @return OK (always) |
301 | */ | 279 | */ |
302 | int namespace_discovered_cb(void * cls, | 280 | int |
303 | const char * namespaceName, | 281 | namespace_discovered_cb (void *cls, |
304 | const HashCode512 * namespaceId, | 282 | const char *namespaceName, |
305 | const struct ECRS_MetaData * md, | 283 | const HashCode512 * namespaceId, |
306 | int rating) { | 284 | const struct ECRS_MetaData *md, int rating) |
285 | { | ||
307 | struct NewNamespaceInfo nni; | 286 | struct NewNamespaceInfo nni; |
308 | nni.namespaceName = namespaceName; | 287 | nni.namespaceName = namespaceName; |
309 | nni.namespaceId = namespaceId; | 288 | nni.namespaceId = namespaceId; |
310 | nni.md = md; | 289 | nni.md = md; |
311 | nni.rating = rating; | 290 | nni.rating = rating; |
312 | gtkSaveCall(&saveDiscovery, | 291 | gtkSaveCall (&saveDiscovery, &nni); |
313 | &nni); | ||
314 | return OK; | 292 | return OK; |
315 | } | 293 | } |
diff --git a/src/plugins/fs/namespace_search.h b/src/plugins/fs/namespace_search.h index d2b7e463..fd85bb6c 100644 --- a/src/plugins/fs/namespace_search.h +++ b/src/plugins/fs/namespace_search.h | |||
@@ -36,11 +36,10 @@ | |||
36 | * @param rating the local rating of the namespace | 36 | * @param rating the local rating of the namespace |
37 | * @return OK (always) | 37 | * @return OK (always) |
38 | */ | 38 | */ |
39 | int namespace_discovered_cb(void * cls, | 39 | int namespace_discovered_cb (void *cls, |
40 | const char * namespaceName, | 40 | const char *namespaceName, |
41 | const HashCode512 * namespaceId, | 41 | const HashCode512 * namespaceId, |
42 | const struct ECRS_MetaData * md, | 42 | const struct ECRS_MetaData *md, int rating); |
43 | int rating); | ||
44 | 43 | ||
45 | 44 | ||
46 | 45 | ||
diff --git a/src/plugins/fs/search.c b/src/plugins/fs/search.c index bd28425e..dc9600f7 100644 --- a/src/plugins/fs/search.c +++ b/src/plugins/fs/search.c | |||
@@ -39,18 +39,18 @@ | |||
39 | * The user has edited the search entry. | 39 | * The user has edited the search entry. |
40 | * Update search button status. | 40 | * Update search button status. |
41 | */ | 41 | */ |
42 | static void on_fssearchSelectionChanged(gpointer signal, | 42 | static void |
43 | gpointer cls) { | 43 | on_fssearchSelectionChanged (gpointer signal, gpointer cls) |
44 | SearchList * list = cls; | 44 | { |
45 | GtkTreeSelection * selection; | 45 | SearchList *list = cls; |
46 | GtkWidget * downloadButton; | 46 | GtkTreeSelection *selection; |
47 | 47 | GtkWidget *downloadButton; | |
48 | selection = gtk_tree_view_get_selection(list->treeview); | 48 | |
49 | downloadButton | 49 | selection = gtk_tree_view_get_selection (list->treeview); |
50 | = glade_xml_get_widget(list->searchXML, | 50 | downloadButton = glade_xml_get_widget (list->searchXML, "downloadButton"); |
51 | "downloadButton"); | 51 | gtk_widget_set_sensitive (downloadButton, |
52 | gtk_widget_set_sensitive(downloadButton, | 52 | gtk_tree_selection_count_selected_rows (selection) |
53 | gtk_tree_selection_count_selected_rows(selection) > 0); | 53 | > 0); |
54 | } | 54 | } |
55 | 55 | ||
56 | 56 | ||
@@ -60,84 +60,86 @@ static void on_fssearchSelectionChanged(gpointer signal, | |||
60 | * Update the number of results received for the given | 60 | * Update the number of results received for the given |
61 | * search in the summary and in the label of the tab. | 61 | * search in the summary and in the label of the tab. |
62 | */ | 62 | */ |
63 | static void updateSearchSummary(SearchList * searchContext) { | 63 | static void |
64 | GtkTreePath * path; | 64 | updateSearchSummary (SearchList * searchContext) |
65 | { | ||
66 | GtkTreePath *path; | ||
65 | GtkTreeIter iter; | 67 | GtkTreeIter iter; |
66 | char * new_title; | 68 | char *new_title; |
67 | GtkLabel * label; | 69 | GtkLabel *label; |
68 | 70 | ||
69 | path = gtk_tree_row_reference_get_path(searchContext->summaryViewRowReference); | 71 | path = |
70 | if (TRUE != gtk_tree_model_get_iter(GTK_TREE_MODEL(search_summary), | 72 | gtk_tree_row_reference_get_path (searchContext->summaryViewRowReference); |
71 | &iter, | 73 | if (TRUE != |
72 | path)) { | 74 | gtk_tree_model_get_iter (GTK_TREE_MODEL (search_summary), &iter, path)) |
73 | GE_BREAK(ectx, 0); | 75 | { |
74 | return; | 76 | GE_BREAK (ectx, 0); |
75 | } | 77 | return; |
76 | gtk_tree_path_free(path); | 78 | } |
77 | gtk_list_store_set(search_summary, | 79 | gtk_tree_path_free (path); |
78 | &iter, | 80 | gtk_list_store_set (search_summary, |
79 | SEARCH_SUMMARY_RESULT_COUNT, searchContext->resultsReceived, | 81 | &iter, |
80 | -1); | 82 | SEARCH_SUMMARY_RESULT_COUNT, |
83 | searchContext->resultsReceived, -1); | ||
84 | |||
81 | 85 | ||
82 | |||
83 | 86 | ||
84 | /* update tab title with the number of results */ | 87 | /* update tab title with the number of results */ |
85 | new_title = | 88 | new_title = |
86 | g_strdup_printf("%.*s%s (%u)", | 89 | g_strdup_printf ("%.*s%s (%u)", |
87 | 20, | 90 | 20, |
88 | searchContext->searchString, | 91 | searchContext->searchString, |
89 | strlen(searchContext->searchString) > 20 ? "..." : "", | 92 | strlen (searchContext->searchString) > 20 ? "..." : "", |
90 | searchContext->resultsReceived); | 93 | searchContext->resultsReceived); |
91 | label = GTK_LABEL(glade_xml_get_widget(searchContext->labelXML, | 94 | label = GTK_LABEL (glade_xml_get_widget (searchContext->labelXML, |
92 | "searchTabLabel")); | 95 | "searchTabLabel")); |
93 | gtk_label_set(label, new_title); | 96 | gtk_label_set (label, new_title); |
94 | FREE(new_title); | 97 | FREE (new_title); |
95 | } | 98 | } |
96 | 99 | ||
97 | /** | 100 | /** |
98 | * Add the given search result to the search | 101 | * Add the given search result to the search |
99 | * tree at the specified position. | 102 | * tree at the specified position. |
100 | */ | 103 | */ |
101 | void addEntryToSearchTree(SearchList * searchContext, | 104 | void |
102 | DownloadList * downloadParent, | 105 | addEntryToSearchTree (SearchList * searchContext, |
103 | const ECRS_FileInfo * info, | 106 | DownloadList * downloadParent, |
104 | GtkTreeIter * iter) { | 107 | const ECRS_FileInfo * info, GtkTreeIter * iter) |
105 | char * name; | 108 | { |
106 | char * mime; | 109 | char *name; |
107 | char * desc; | 110 | char *mime; |
111 | char *desc; | ||
108 | unsigned long long size; | 112 | unsigned long long size; |
109 | char * size_h; | 113 | char *size_h; |
110 | GdkPixbuf * pixbuf; | 114 | GdkPixbuf *pixbuf; |
111 | enum URITRACK_STATE state; | 115 | enum URITRACK_STATE state; |
112 | 116 | ||
113 | state = URITRACK_getState(ectx, | 117 | state = URITRACK_getState (ectx, cfg, info->uri); |
114 | cfg, | 118 | mime = getMimeTypeFromMetaData (info->meta); |
115 | info->uri); | 119 | desc = getDescriptionFromMetaData (info->meta); |
116 | mime = getMimeTypeFromMetaData(info->meta); | 120 | name = getFileNameFromMetaData (info->meta); |
117 | desc = getDescriptionFromMetaData(info->meta); | 121 | size = ECRS_isFileUri (info->uri) |
118 | name = getFileNameFromMetaData(info->meta); | 122 | || ECRS_isLocationUri (info->uri) ? ECRS_fileSize (info->uri) : 0; |
119 | size = ECRS_isFileUri(info->uri) || ECRS_isLocationUri(info->uri) ? ECRS_fileSize(info->uri) : 0; | 123 | pixbuf = getThumbnailFromMetaData (info->meta); |
120 | pixbuf = getThumbnailFromMetaData(info->meta); | 124 | size_h = string_get_fancy_byte_size (size); |
121 | size_h = string_get_fancy_byte_size(size); | 125 | gtk_tree_store_set (searchContext->tree, |
122 | gtk_tree_store_set(searchContext->tree, | 126 | iter, |
123 | iter, | 127 | SEARCH_NAME, name, |
124 | SEARCH_NAME, name, | 128 | SEARCH_SIZE, size, |
125 | SEARCH_SIZE, size, | 129 | SEARCH_HSIZE, size_h, |
126 | SEARCH_HSIZE, size_h, | 130 | SEARCH_MIME, mime, |
127 | SEARCH_MIME, mime, | 131 | SEARCH_DESC, desc, |
128 | SEARCH_DESC, desc, | 132 | SEARCH_PIXBUF, pixbuf, |
129 | SEARCH_PIXBUF, pixbuf, | 133 | SEARCH_URI, ECRS_dupUri (info->uri), |
130 | SEARCH_URI, ECRS_dupUri(info->uri), | 134 | SEARCH_META, ECRS_dupMetaData (info->meta), |
131 | SEARCH_META, ECRS_dupMetaData(info->meta), | 135 | SEARCH_CELL_BG_COLOR, getColorCode (state), |
132 | SEARCH_CELL_BG_COLOR, getColorCode(state), | 136 | SEARCH_CELL_FG_COLOR, "black", |
133 | SEARCH_CELL_FG_COLOR, "black", | 137 | SEARCH_INTERNAL, searchContext, |
134 | SEARCH_INTERNAL, searchContext, | 138 | SEARCH_INTERNAL_PARENT, downloadParent, -1); |
135 | SEARCH_INTERNAL_PARENT, downloadParent, | 139 | FREE (size_h); |
136 | -1); | 140 | FREE (name); |
137 | FREE(size_h); | 141 | FREE (desc); |
138 | FREE(name); | 142 | FREE (mime); |
139 | FREE(desc); | ||
140 | FREE(mime); | ||
141 | } | 143 | } |
142 | 144 | ||
143 | /** | 145 | /** |
@@ -148,202 +150,173 @@ void addEntryToSearchTree(SearchList * searchContext, | |||
148 | * @param uri the search URI | 150 | * @param uri the search URI |
149 | * @param searchContext identifies the search page | 151 | * @param searchContext identifies the search page |
150 | */ | 152 | */ |
151 | void fs_search_result_received(SearchList * searchContext, | 153 | void |
152 | const ECRS_FileInfo * info, | 154 | fs_search_result_received (SearchList * searchContext, |
153 | const struct ECRS_URI * uri) { | 155 | const ECRS_FileInfo * info, |
154 | GtkTreeStore * model; | 156 | const struct ECRS_URI *uri) |
157 | { | ||
158 | GtkTreeStore *model; | ||
155 | GtkTreeIter iter; | 159 | GtkTreeIter iter; |
156 | enum URITRACK_STATE state; | 160 | enum URITRACK_STATE state; |
157 | 161 | ||
158 | state = URITRACK_getState(ectx, | 162 | state = URITRACK_getState (ectx, cfg, info->uri); |
159 | cfg, | 163 | if ((state & (URITRACK_INSERTED | |
160 | info->uri); | 164 | URITRACK_INDEXED)) && |
161 | if ( (state & (URITRACK_INSERTED | | 165 | (YES == GC_get_configuration_value_yesno (cfg, |
162 | URITRACK_INDEXED) ) && | 166 | "GNUNET-GTK", |
163 | (YES == GC_get_configuration_value_yesno(cfg, | 167 | "DISABLE-OWN", YES))) |
164 | "GNUNET-GTK", | ||
165 | "DISABLE-OWN", | ||
166 | YES)) ) | ||
167 | return; | 168 | return; |
168 | model = GTK_TREE_STORE(gtk_tree_view_get_model(searchContext->treeview)); | 169 | model = GTK_TREE_STORE (gtk_tree_view_get_model (searchContext->treeview)); |
169 | gtk_tree_store_append(model, | 170 | gtk_tree_store_append (model, &iter, NULL); |
170 | &iter, | 171 | addEntryToSearchTree (searchContext, NULL, info, &iter); |
171 | NULL); | ||
172 | addEntryToSearchTree(searchContext, | ||
173 | NULL, | ||
174 | info, | ||
175 | &iter); | ||
176 | searchContext->resultsReceived++; | 172 | searchContext->resultsReceived++; |
177 | updateSearchSummary(searchContext); | 173 | updateSearchSummary (searchContext); |
178 | } | 174 | } |
179 | 175 | ||
180 | static int | 176 | static int |
181 | on_search_copy_uri_activate(void * cls, | 177 | on_search_copy_uri_activate (void *cls, GtkWidget * searchEntry) |
182 | GtkWidget * searchEntry) { | 178 | { |
183 | SearchList * list = cls; | 179 | SearchList *list = cls; |
184 | GtkTreePath *path; | 180 | GtkTreePath *path; |
185 | GtkTreeIter iter; | 181 | GtkTreeIter iter; |
186 | struct ECRS_URI * uri; | 182 | struct ECRS_URI *uri; |
187 | char * str; | 183 | char *str; |
188 | GtkClipboard * clip; | 184 | GtkClipboard *clip; |
189 | 185 | ||
190 | path = NULL; | 186 | path = NULL; |
191 | if (FALSE == gtk_tree_view_get_path_at_pos(list->treeview, | 187 | if (FALSE == gtk_tree_view_get_path_at_pos (list->treeview, |
192 | list->last_x, | 188 | list->last_x, |
193 | list->last_y, | 189 | list->last_y, |
194 | &path, | 190 | &path, NULL, NULL, NULL)) |
195 | NULL, | 191 | { |
196 | NULL, | 192 | GE_BREAK (NULL, 0); |
197 | NULL)) { | 193 | return FALSE; |
198 | GE_BREAK(NULL, 0); | 194 | } |
199 | return FALSE; | 195 | if (FALSE == gtk_tree_model_get_iter (GTK_TREE_MODEL (list->tree), |
200 | } | 196 | &iter, path)) |
201 | if (FALSE == gtk_tree_model_get_iter(GTK_TREE_MODEL(list->tree), | 197 | { |
202 | &iter, | 198 | GE_BREAK (NULL, 0); |
203 | path)) { | 199 | gtk_tree_path_free (path); |
204 | GE_BREAK(NULL, 0); | 200 | return FALSE; |
205 | gtk_tree_path_free(path); | 201 | } |
206 | return FALSE; | 202 | gtk_tree_path_free (path); |
207 | } | ||
208 | gtk_tree_path_free(path); | ||
209 | uri = NULL; | 203 | uri = NULL; |
210 | gtk_tree_model_get(GTK_TREE_MODEL(list->tree), | 204 | gtk_tree_model_get (GTK_TREE_MODEL (list->tree), |
211 | &iter, | 205 | &iter, SEARCH_URI, &uri, -1); |
212 | SEARCH_URI, &uri, | 206 | str = ECRS_uriToString (uri); |
213 | -1); | 207 | clip = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD); |
214 | str = ECRS_uriToString(uri); | 208 | gtk_clipboard_set_text (clip, str, strlen (str)); |
215 | clip = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); | 209 | FREE (str); |
216 | gtk_clipboard_set_text(clip, | ||
217 | str, | ||
218 | strlen(str)); | ||
219 | FREE(str); | ||
220 | return FALSE; | 210 | return FALSE; |
221 | } | 211 | } |
222 | 212 | ||
223 | 213 | ||
224 | #ifndef MINGW | 214 | #ifndef MINGW |
225 | static char * | 215 | static char * |
226 | selectFile() { | 216 | selectFile () |
227 | GladeXML * uploadXML; | 217 | { |
228 | GtkFileChooser * dialog; | 218 | GladeXML *uploadXML; |
229 | char * ret; | 219 | GtkFileChooser *dialog; |
220 | char *ret; | ||
230 | 221 | ||
231 | uploadXML | 222 | uploadXML |
232 | = glade_xml_new(getGladeFileName(), | 223 | = glade_xml_new (getGladeFileName (), |
233 | "directorySaveDialog", | 224 | "directorySaveDialog", PACKAGE_NAME); |
234 | PACKAGE_NAME); | 225 | connectGladeWithPlugins (uploadXML); |
235 | connectGladeWithPlugins(uploadXML); | 226 | dialog = GTK_FILE_CHOOSER (glade_xml_get_widget (uploadXML, |
236 | dialog = GTK_FILE_CHOOSER(glade_xml_get_widget(uploadXML, | 227 | "directorySaveDialog")); |
237 | "directorySaveDialog")); | 228 | if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_CANCEL) |
238 | if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_CANCEL) | 229 | ret = gtk_file_chooser_get_filename (dialog); |
239 | ret = gtk_file_chooser_get_filename(dialog); | ||
240 | else | 230 | else |
241 | ret = NULL; | 231 | ret = NULL; |
242 | gtk_widget_destroy(GTK_WIDGET(dialog)); | 232 | gtk_widget_destroy (GTK_WIDGET (dialog)); |
243 | UNREF(uploadXML); | 233 | UNREF (uploadXML); |
244 | return ret; | 234 | return ret; |
245 | } | 235 | } |
246 | 236 | ||
247 | #else /* MINGW */ | 237 | #else /* MINGW */ |
248 | 238 | ||
249 | static char * | 239 | static char * |
250 | selectFile() { | 240 | selectFile () |
251 | return plibc_ChooseFile(_("Choose the name under which you want to save the search results."), | 241 | { |
252 | OFN_SHAREAWARE); | 242 | return |
243 | plibc_ChooseFile (_ | ||
244 | ("Choose the name under which you want to save the search results."), | ||
245 | OFN_SHAREAWARE); | ||
253 | } | 246 | } |
254 | #endif /* MINGW */ | 247 | #endif /* MINGW */ |
255 | 248 | ||
256 | static int | 249 | static int |
257 | on_save_search_activate(void * cls, | 250 | on_save_search_activate (void *cls, GtkWidget * searchEntry) |
258 | GtkWidget * searchEntry) { | 251 | { |
259 | SearchList * list = cls; | 252 | SearchList *list = cls; |
260 | char * name; | 253 | char *name; |
261 | char * directory; | 254 | char *directory; |
262 | unsigned long long dir_len; | 255 | unsigned long long dir_len; |
263 | unsigned int fis_size; | 256 | unsigned int fis_size; |
264 | ECRS_FileInfo * fis; | 257 | ECRS_FileInfo *fis; |
265 | struct ECRS_MetaData * meta; | 258 | struct ECRS_MetaData *meta; |
266 | GtkTreeModel * model; | 259 | GtkTreeModel *model; |
267 | GtkTreeIter iter; | 260 | GtkTreeIter iter; |
268 | unsigned int pos; | 261 | unsigned int pos; |
269 | 262 | ||
270 | model = gtk_tree_view_get_model(list->treeview); | 263 | model = gtk_tree_view_get_model (list->treeview); |
271 | if (TRUE != gtk_tree_model_get_iter_first(model, &iter)) { | 264 | if (TRUE != gtk_tree_model_get_iter_first (model, &iter)) |
272 | addLogEntry(_("No search results yet, cannot save!")); | 265 | { |
273 | return FALSE; | 266 | addLogEntry (_("No search results yet, cannot save!")); |
274 | } | 267 | return FALSE; |
268 | } | ||
275 | 269 | ||
276 | name = selectFile(""); | 270 | name = selectFile (""); |
277 | if (name == NULL) | 271 | if (name == NULL) |
278 | return FALSE; | 272 | return FALSE; |
279 | fis = NULL; | 273 | fis = NULL; |
280 | fis_size = 0; | 274 | fis_size = 0; |
281 | GROW(fis, | 275 | GROW (fis, fis_size, list->resultsReceived); |
282 | fis_size, | ||
283 | list->resultsReceived); | ||
284 | pos = 0; | 276 | pos = 0; |
285 | do { | 277 | do |
286 | if (pos == fis_size) | 278 | { |
287 | GROW(fis, | 279 | if (pos == fis_size) |
288 | fis_size, | 280 | GROW (fis, fis_size, pos + 1); |
289 | pos + 1); | 281 | gtk_tree_model_get (model, |
290 | gtk_tree_model_get(model, | 282 | &iter, |
291 | &iter, | 283 | SEARCH_URI, &fis[pos].uri, |
292 | SEARCH_URI, &fis[pos].uri, | 284 | SEARCH_META, &fis[pos].meta, -1); |
293 | SEARCH_META, &fis[pos].meta, | 285 | pos++; |
294 | -1); | 286 | } |
295 | pos++; | 287 | while (gtk_tree_model_iter_next (model, &iter)); |
296 | } while (gtk_tree_model_iter_next(model, | 288 | meta = ECRS_createMetaData (); |
297 | &iter)); | 289 | ECRS_addToMetaData (meta, EXTRACTOR_KEYWORDS, list->searchString); |
298 | meta = ECRS_createMetaData(); | 290 | ECRS_addToMetaData (meta, EXTRACTOR_DESCRIPTION, _("Saved search results")); |
299 | ECRS_addToMetaData(meta, | 291 | ECRS_addToMetaData (meta, EXTRACTOR_SOFTWARE, "gnunet-gtk"); |
300 | EXTRACTOR_KEYWORDS, | 292 | if (OK != ECRS_createDirectory (NULL, |
301 | list->searchString); | 293 | &directory, &dir_len, fis_size, fis, meta)) |
302 | ECRS_addToMetaData(meta, | 294 | { |
303 | EXTRACTOR_DESCRIPTION, | 295 | addLogEntry (_("Internal error.")); |
304 | _("Saved search results")); | 296 | GE_BREAK (NULL, 0); |
305 | ECRS_addToMetaData(meta, | 297 | ECRS_freeMetaData (meta); |
306 | EXTRACTOR_SOFTWARE, | 298 | GROW (fis, fis_size, 0); |
307 | "gnunet-gtk"); | 299 | FREE (name); |
308 | if (OK != ECRS_createDirectory(NULL, | 300 | return FALSE; |
309 | &directory, | 301 | } |
310 | &dir_len, | 302 | ECRS_freeMetaData (meta); |
311 | fis_size, | 303 | GROW (fis, fis_size, 0); |
312 | fis, | 304 | if (OK != disk_file_write (NULL, name, directory, dir_len, "644")) |
313 | meta)) { | 305 | { |
314 | addLogEntry(_("Internal error.")); | 306 | addLogEntry (_("Error writing file `%s'."), name); |
315 | GE_BREAK(NULL, 0); | 307 | } |
316 | ECRS_freeMetaData(meta); | 308 | FREE (directory); |
317 | GROW(fis, | 309 | FREE (name); |
318 | fis_size, | ||
319 | 0); | ||
320 | FREE(name); | ||
321 | return FALSE; | ||
322 | } | ||
323 | ECRS_freeMetaData(meta); | ||
324 | GROW(fis, | ||
325 | fis_size, | ||
326 | 0); | ||
327 | if (OK != disk_file_write(NULL, | ||
328 | name, | ||
329 | directory, | ||
330 | dir_len, | ||
331 | "644")) { | ||
332 | addLogEntry(_("Error writing file `%s'."), | ||
333 | name); | ||
334 | } | ||
335 | FREE(directory); | ||
336 | FREE(name); | ||
337 | return FALSE; | 310 | return FALSE; |
338 | } | 311 | } |
339 | 312 | ||
340 | static gint | 313 | static gint |
341 | search_click_handler(void * cls, | 314 | search_click_handler (void *cls, GdkEvent * event) |
342 | GdkEvent *event) { | 315 | { |
343 | SearchList * list = cls; | 316 | SearchList *list = cls; |
344 | GtkMenu * menu; | 317 | GtkMenu *menu; |
345 | GtkWidget * entry; | 318 | GtkWidget *entry; |
346 | GdkEventButton * event_button; | 319 | GdkEventButton *event_button; |
347 | 320 | ||
348 | g_return_val_if_fail (event != NULL, FALSE); | 321 | g_return_val_if_fail (event != NULL, FALSE); |
349 | 322 | ||
@@ -354,34 +327,26 @@ search_click_handler(void * cls, | |||
354 | return FALSE; | 327 | return FALSE; |
355 | list->last_x = event_button->x; | 328 | list->last_x = event_button->x; |
356 | list->last_y = event_button->y; | 329 | list->last_y = event_button->y; |
357 | menu = GTK_MENU(gtk_menu_new()); | 330 | menu = GTK_MENU (gtk_menu_new ()); |
358 | entry = gtk_menu_item_new_with_label(_("_Copy URI to Clipboard")); | 331 | entry = gtk_menu_item_new_with_label (_("_Copy URI to Clipboard")); |
359 | g_signal_connect_swapped (entry, | 332 | g_signal_connect_swapped (entry, |
360 | "activate", | 333 | "activate", |
361 | G_CALLBACK(on_search_copy_uri_activate), | 334 | G_CALLBACK (on_search_copy_uri_activate), list); |
362 | list); | 335 | gtk_label_set_use_underline (GTK_LABEL |
363 | gtk_label_set_use_underline(GTK_LABEL(gtk_bin_get_child(GTK_BIN(entry))), | 336 | (gtk_bin_get_child (GTK_BIN (entry))), TRUE); |
364 | TRUE); | 337 | gtk_widget_show (entry); |
365 | gtk_widget_show(entry); | 338 | gtk_menu_shell_append (GTK_MENU_SHELL (menu), entry); |
366 | gtk_menu_shell_append(GTK_MENU_SHELL(menu), | 339 | entry = gtk_menu_item_new_with_label (_("_Save results as directory")); |
367 | entry); | ||
368 | entry = gtk_menu_item_new_with_label(_("_Save results as directory")); | ||
369 | g_signal_connect_swapped (entry, | 340 | g_signal_connect_swapped (entry, |
370 | "activate", | 341 | "activate", |
371 | G_CALLBACK(on_save_search_activate), | 342 | G_CALLBACK (on_save_search_activate), list); |
372 | list); | 343 | gtk_label_set_use_underline (GTK_LABEL |
373 | gtk_label_set_use_underline(GTK_LABEL(gtk_bin_get_child(GTK_BIN(entry))), | 344 | (gtk_bin_get_child (GTK_BIN (entry))), TRUE); |
374 | TRUE); | 345 | gtk_widget_show (entry); |
375 | gtk_widget_show(entry); | 346 | gtk_menu_shell_append (GTK_MENU_SHELL (menu), entry); |
376 | gtk_menu_shell_append(GTK_MENU_SHELL(menu), | ||
377 | entry); | ||
378 | gtk_menu_popup (menu, | 347 | gtk_menu_popup (menu, |
379 | NULL, | 348 | NULL, |
380 | NULL, | 349 | NULL, NULL, NULL, event_button->button, event_button->time); |
381 | NULL, | ||
382 | NULL, | ||
383 | event_button->button, | ||
384 | event_button->time); | ||
385 | return TRUE; | 350 | return TRUE; |
386 | } | 351 | } |
387 | 352 | ||
@@ -390,234 +355,195 @@ search_click_handler(void * cls, | |||
390 | * tab and add an entry to the summary. | 355 | * tab and add an entry to the summary. |
391 | */ | 356 | */ |
392 | SearchList * | 357 | SearchList * |
393 | fs_search_started(struct FSUI_SearchList * fsui_list, | 358 | fs_search_started (struct FSUI_SearchList * fsui_list, |
394 | const struct ECRS_URI * uri, | 359 | const struct ECRS_URI * uri, |
395 | unsigned int anonymityLevel, | 360 | unsigned int anonymityLevel, |
396 | unsigned int resultCount, | 361 | unsigned int resultCount, |
397 | const ECRS_FileInfo * results, | 362 | const ECRS_FileInfo * results, FSUI_State state) |
398 | FSUI_State state) { | 363 | { |
399 | SearchList * list; | 364 | SearchList *list; |
400 | gint pages; | 365 | gint pages; |
401 | char * description; | 366 | char *description; |
402 | const char * dhead; | 367 | const char *dhead; |
403 | GtkTreeViewColumn * column; | 368 | GtkTreeViewColumn *column; |
404 | GtkCellRenderer * renderer; | 369 | GtkCellRenderer *renderer; |
405 | GtkNotebook * notebook; | 370 | GtkNotebook *notebook; |
406 | GtkTreePath * path; | 371 | GtkTreePath *path; |
407 | GtkTreeIter iter; | 372 | GtkTreeIter iter; |
408 | int col; | 373 | int col; |
409 | int i; | 374 | int i; |
410 | 375 | ||
411 | description = ECRS_uriToString(uri); | 376 | description = ECRS_uriToString (uri); |
412 | if (description == NULL) { | 377 | if (description == NULL) |
413 | GE_BREAK(ectx, 0); | 378 | { |
414 | return NULL; | 379 | GE_BREAK (ectx, 0); |
415 | } | 380 | return NULL; |
416 | GE_ASSERT(ectx, | 381 | } |
417 | strlen(description) >= strlen(ECRS_URI_PREFIX)); | 382 | GE_ASSERT (ectx, strlen (description) >= strlen (ECRS_URI_PREFIX)); |
418 | dhead = &description[strlen(ECRS_URI_PREFIX)]; | 383 | dhead = &description[strlen (ECRS_URI_PREFIX)]; |
419 | if (0 == strncmp(dhead, | 384 | if (0 == strncmp (dhead, ECRS_SEARCH_INFIX, strlen (ECRS_SEARCH_INFIX))) |
420 | ECRS_SEARCH_INFIX, | 385 | dhead = &dhead[strlen (ECRS_SEARCH_INFIX)]; |
421 | strlen(ECRS_SEARCH_INFIX))) | 386 | else if (0 == strncmp (dhead, |
422 | dhead = &dhead[strlen(ECRS_SEARCH_INFIX)]; | 387 | ECRS_SUBSPACE_INFIX, strlen (ECRS_SUBSPACE_INFIX))) |
423 | else if (0 == strncmp(dhead, | 388 | dhead = &dhead[strlen (ECRS_SUBSPACE_INFIX)]; |
424 | ECRS_SUBSPACE_INFIX, | 389 | list = MALLOC (sizeof (SearchList)); |
425 | strlen(ECRS_SUBSPACE_INFIX))) | 390 | memset (list, 0, sizeof (SearchList)); |
426 | dhead = &dhead[strlen(ECRS_SUBSPACE_INFIX)]; | 391 | list->searchString = STRDUP (dhead); |
427 | list | 392 | list->uri = ECRS_dupUri (uri); |
428 | = MALLOC(sizeof(SearchList)); | 393 | list->fsui_list = fsui_list; |
429 | memset(list, | 394 | list->next = search_head; |
430 | 0, | ||
431 | sizeof(SearchList)); | ||
432 | list->searchString | ||
433 | = STRDUP(dhead); | ||
434 | list->uri | ||
435 | = ECRS_dupUri(uri); | ||
436 | list->fsui_list | ||
437 | = fsui_list; | ||
438 | list->next | ||
439 | = search_head; | ||
440 | search_head = list; | 395 | search_head = list; |
441 | list->searchXML | 396 | list->searchXML |
442 | = glade_xml_new(getGladeFileName(), | 397 | = glade_xml_new (getGladeFileName (), "searchResultsFrame", PACKAGE_NAME); |
443 | "searchResultsFrame", | 398 | connectGladeWithPlugins (list->searchXML); |
444 | PACKAGE_NAME); | ||
445 | connectGladeWithPlugins(list->searchXML); | ||
446 | list->searchpage | 399 | list->searchpage |
447 | = extractMainWidgetFromWindow(list->searchXML, | 400 | = extractMainWidgetFromWindow (list->searchXML, "searchResultsFrame"); |
448 | "searchResultsFrame"); | ||
449 | /* setup tree view and renderers */ | 401 | /* setup tree view and renderers */ |
450 | list->treeview = GTK_TREE_VIEW(glade_xml_get_widget(list->searchXML, | 402 | list->treeview = GTK_TREE_VIEW (glade_xml_get_widget (list->searchXML, |
451 | "searchResults")); | 403 | "searchResults")); |
452 | g_signal_connect_swapped (list->treeview, | 404 | g_signal_connect_swapped (list->treeview, |
453 | "button-press-event", | 405 | "button-press-event", |
454 | G_CALLBACK(search_click_handler), | 406 | G_CALLBACK (search_click_handler), list); |
455 | list); | 407 | list->tree = gtk_tree_store_new (SEARCH_NUM, G_TYPE_STRING, /* name */ |
456 | list->tree = | 408 | G_TYPE_UINT64, /* size */ |
457 | gtk_tree_store_new(SEARCH_NUM, | 409 | G_TYPE_STRING, /* human-readable size */ |
458 | G_TYPE_STRING, /* name */ | 410 | G_TYPE_STRING, /* mime-type */ |
459 | G_TYPE_UINT64, /* size */ | 411 | G_TYPE_STRING, /* meta-data (some) */ |
460 | G_TYPE_STRING, /* human-readable size */ | 412 | GDK_TYPE_PIXBUF, /* preview */ |
461 | G_TYPE_STRING, /* mime-type */ | 413 | G_TYPE_POINTER, /* url */ |
462 | G_TYPE_STRING, /* meta-data (some) */ | 414 | G_TYPE_POINTER, /* meta */ |
463 | GDK_TYPE_PIXBUF, /* preview */ | 415 | G_TYPE_STRING, /* bg-color */ |
464 | G_TYPE_POINTER, /* url */ | 416 | G_TYPE_STRING, /* fg-color */ |
465 | G_TYPE_POINTER, /* meta */ | 417 | G_TYPE_POINTER, /* internal: search list */ |
466 | G_TYPE_STRING, /* bg-color */ | 418 | G_TYPE_POINTER); /* internal: download parent list */ |
467 | G_TYPE_STRING, /* fg-color */ | 419 | |
468 | G_TYPE_POINTER, /* internal: search list */ | 420 | gtk_tree_view_set_model (list->treeview, GTK_TREE_MODEL (list->tree)); |
469 | G_TYPE_POINTER); /* internal: download parent list */ | 421 | gtk_tree_selection_set_mode (gtk_tree_view_get_selection (list->treeview), |
470 | 422 | GTK_SELECTION_MULTIPLE); | |
471 | gtk_tree_view_set_model(list->treeview, | 423 | |
472 | GTK_TREE_MODEL(list->tree)); | 424 | g_signal_connect_data (gtk_tree_view_get_selection (list->treeview), |
473 | gtk_tree_selection_set_mode(gtk_tree_view_get_selection(list->treeview), | 425 | "changed", |
474 | GTK_SELECTION_MULTIPLE); | 426 | G_CALLBACK (&on_fssearchSelectionChanged), |
475 | 427 | list, NULL, 0); | |
476 | g_signal_connect_data(gtk_tree_view_get_selection(list->treeview), | 428 | renderer = gtk_cell_renderer_text_new (); |
477 | "changed", | 429 | col = gtk_tree_view_insert_column_with_attributes (list->treeview, |
478 | G_CALLBACK(&on_fssearchSelectionChanged), | 430 | -1, |
479 | list, | 431 | _("Name"), |
480 | NULL, | 432 | renderer, |
481 | 0); | 433 | "text", SEARCH_NAME, |
482 | renderer = gtk_cell_renderer_text_new(); | 434 | NULL); |
483 | col = gtk_tree_view_insert_column_with_attributes(list->treeview, | 435 | g_object_set (G_OBJECT (renderer), |
484 | -1, | 436 | "wrap-width", 45, |
485 | _("Name"), | 437 | "width-chars", 45, "ellipsize", PANGO_ELLIPSIZE_END, NULL); |
486 | renderer, | 438 | column = gtk_tree_view_get_column (list->treeview, col - 1); |
487 | "text", SEARCH_NAME, | 439 | gtk_tree_view_column_set_resizable (column, TRUE); |
488 | NULL); | 440 | gtk_tree_view_column_set_clickable (column, TRUE); |
489 | g_object_set(G_OBJECT(renderer), | 441 | gtk_tree_view_column_set_reorderable (column, TRUE); |
490 | "wrap-width", 45, | 442 | gtk_tree_view_column_set_sort_column_id (column, SEARCH_NAME); |
491 | "width-chars", 45, | 443 | |
492 | "ellipsize", PANGO_ELLIPSIZE_END, | 444 | renderer = gtk_cell_renderer_text_new (); |
493 | NULL); | ||
494 | column = gtk_tree_view_get_column(list->treeview, | ||
495 | col - 1); | ||
496 | gtk_tree_view_column_set_resizable(column, TRUE); | ||
497 | gtk_tree_view_column_set_clickable(column, TRUE); | ||
498 | gtk_tree_view_column_set_reorderable(column, TRUE); | ||
499 | gtk_tree_view_column_set_sort_column_id(column, SEARCH_NAME); | ||
500 | |||
501 | renderer = gtk_cell_renderer_text_new(); | ||
502 | g_object_set (renderer, "xalign", 1.00, NULL); | 445 | g_object_set (renderer, "xalign", 1.00, NULL); |
503 | col = gtk_tree_view_insert_column_with_attributes(list->treeview, | 446 | col = gtk_tree_view_insert_column_with_attributes (list->treeview, |
504 | -1, | 447 | -1, |
505 | _("Size"), | 448 | _("Size"), |
506 | renderer, | 449 | renderer, |
507 | "text", SEARCH_HSIZE, | 450 | "text", SEARCH_HSIZE, |
508 | "cell-background", SEARCH_CELL_BG_COLOR, | 451 | "cell-background", |
509 | "foreground", SEARCH_CELL_FG_COLOR, | 452 | SEARCH_CELL_BG_COLOR, |
510 | NULL); | 453 | "foreground", |
511 | column = gtk_tree_view_get_column(list->treeview, | 454 | SEARCH_CELL_FG_COLOR, |
512 | col - 1); | 455 | NULL); |
513 | gtk_tree_view_column_set_resizable(column, TRUE); | 456 | column = gtk_tree_view_get_column (list->treeview, col - 1); |
514 | gtk_tree_view_column_set_clickable(column, TRUE); | 457 | gtk_tree_view_column_set_resizable (column, TRUE); |
515 | gtk_tree_view_column_set_reorderable(column, TRUE); | 458 | gtk_tree_view_column_set_clickable (column, TRUE); |
516 | gtk_tree_view_column_set_sort_column_id(column, SEARCH_SIZE); | 459 | gtk_tree_view_column_set_reorderable (column, TRUE); |
517 | 460 | gtk_tree_view_column_set_sort_column_id (column, SEARCH_SIZE); | |
518 | renderer = gtk_cell_renderer_text_new(); | 461 | |
519 | col = gtk_tree_view_insert_column_with_attributes(list->treeview, | 462 | renderer = gtk_cell_renderer_text_new (); |
520 | -1, | 463 | col = gtk_tree_view_insert_column_with_attributes (list->treeview, |
521 | _("Mime-type"), | 464 | -1, |
522 | renderer, | 465 | _("Mime-type"), |
523 | "text", SEARCH_MIME, | 466 | renderer, |
524 | NULL); | 467 | "text", SEARCH_MIME, |
525 | g_object_set(G_OBJECT(renderer), | 468 | NULL); |
526 | "wrap-width", 30, | 469 | g_object_set (G_OBJECT (renderer), |
527 | "width-chars", 30, | 470 | "wrap-width", 30, |
528 | "ellipsize", PANGO_ELLIPSIZE_END, | 471 | "width-chars", 30, "ellipsize", PANGO_ELLIPSIZE_END, NULL); |
529 | NULL); | 472 | column = gtk_tree_view_get_column (list->treeview, col - 1); |
530 | column = gtk_tree_view_get_column(list->treeview, | 473 | gtk_tree_view_column_set_resizable (column, TRUE); |
531 | col - 1); | 474 | gtk_tree_view_column_set_clickable (column, TRUE); |
532 | gtk_tree_view_column_set_resizable(column, TRUE); | 475 | gtk_tree_view_column_set_reorderable (column, TRUE); |
533 | gtk_tree_view_column_set_clickable(column, TRUE); | 476 | gtk_tree_view_column_set_sort_column_id (column, SEARCH_MIME); |
534 | gtk_tree_view_column_set_reorderable(column, TRUE); | 477 | |
535 | gtk_tree_view_column_set_sort_column_id(column, SEARCH_MIME); | 478 | if (YES != GC_get_configuration_value_yesno (cfg, |
536 | 479 | "GNUNET-GTK", | |
537 | if (YES != GC_get_configuration_value_yesno(cfg, | 480 | "DISABLE-PREVIEWS", NO)) |
538 | "GNUNET-GTK", | 481 | { |
539 | "DISABLE-PREVIEWS", | 482 | renderer = gtk_cell_renderer_pixbuf_new (); |
540 | NO)) { | 483 | col = gtk_tree_view_insert_column_with_attributes (list->treeview, |
541 | renderer = gtk_cell_renderer_pixbuf_new(); | 484 | -1, |
542 | col = gtk_tree_view_insert_column_with_attributes(list->treeview, | 485 | _("Preview"), |
543 | -1, | 486 | renderer, |
544 | _("Preview"), | 487 | "pixbuf", |
545 | renderer, | 488 | SEARCH_PIXBUF, NULL); |
546 | "pixbuf", SEARCH_PIXBUF, | 489 | column = gtk_tree_view_get_column (list->treeview, col - 1); |
547 | NULL); | 490 | gtk_tree_view_column_set_resizable (column, TRUE); |
548 | column = gtk_tree_view_get_column(list->treeview, | 491 | gtk_tree_view_column_set_reorderable (column, TRUE); |
549 | col - 1); | 492 | gtk_tree_view_column_set_resizable (column, TRUE); |
550 | gtk_tree_view_column_set_resizable(column, TRUE); | 493 | } |
551 | gtk_tree_view_column_set_reorderable(column, TRUE); | 494 | |
552 | gtk_tree_view_column_set_resizable(column, TRUE); | 495 | renderer = gtk_cell_renderer_text_new (); |
553 | } | 496 | col = gtk_tree_view_insert_column_with_attributes (list->treeview, |
554 | 497 | -1, | |
555 | renderer = gtk_cell_renderer_text_new(); | 498 | _("Meta-data"), |
556 | col = gtk_tree_view_insert_column_with_attributes(list->treeview, | 499 | renderer, |
557 | -1, | 500 | "text", SEARCH_DESC, |
558 | _("Meta-data"), | 501 | NULL); |
559 | renderer, | 502 | column = gtk_tree_view_get_column (list->treeview, col - 1); |
560 | "text", SEARCH_DESC, | 503 | g_object_set (G_OBJECT (renderer), |
561 | NULL); | 504 | "wrap-width", 60, |
562 | column = gtk_tree_view_get_column(list->treeview, | 505 | "width-chars", 60, |
563 | col - 1); | 506 | "wrap-mode", PANGO_WRAP_WORD_CHAR, |
564 | g_object_set(G_OBJECT(renderer), | 507 | "ellipsize", PANGO_ELLIPSIZE_END, |
565 | "wrap-width", 60, | 508 | "ellipsize-set", TRUE, NULL); |
566 | "width-chars", 60, | 509 | gtk_tree_view_column_set_resizable (column, TRUE); |
567 | "wrap-mode", PANGO_WRAP_WORD_CHAR, | 510 | gtk_tree_view_column_set_clickable (column, TRUE); |
568 | "ellipsize", PANGO_ELLIPSIZE_END, | 511 | gtk_tree_view_column_set_reorderable (column, TRUE); |
569 | "ellipsize-set", TRUE, | 512 | gtk_tree_view_column_set_sort_column_id (column, SEARCH_DESC); |
570 | NULL); | ||
571 | gtk_tree_view_column_set_resizable(column, TRUE); | ||
572 | gtk_tree_view_column_set_clickable(column, TRUE); | ||
573 | gtk_tree_view_column_set_reorderable(column, TRUE); | ||
574 | gtk_tree_view_column_set_sort_column_id(column, SEARCH_DESC); | ||
575 | 513 | ||
576 | /* add entry in search summary */ | 514 | /* add entry in search summary */ |
577 | gtk_list_store_append(search_summary, | 515 | gtk_list_store_append (search_summary, &iter); |
578 | &iter); | 516 | gtk_list_store_set (search_summary, |
579 | gtk_list_store_set(search_summary, | 517 | &iter, |
580 | &iter, | 518 | SEARCH_SUMMARY_NAME, dhead, |
581 | SEARCH_SUMMARY_NAME, dhead, | 519 | SEARCH_SUMMARY_RESULT_COUNT, 0, |
582 | SEARCH_SUMMARY_RESULT_COUNT, 0, | 520 | SEARCH_SUMMARY_INTERNAL, list, -1); |
583 | SEARCH_SUMMARY_INTERNAL, list, | 521 | FREE (description); |
584 | -1); | 522 | path = gtk_tree_model_get_path (GTK_TREE_MODEL (search_summary), &iter); |
585 | FREE(description); | ||
586 | path = gtk_tree_model_get_path(GTK_TREE_MODEL(search_summary), | ||
587 | &iter); | ||
588 | list->summaryViewRowReference | 523 | list->summaryViewRowReference |
589 | = gtk_tree_row_reference_new(GTK_TREE_MODEL(search_summary), | 524 | = gtk_tree_row_reference_new (GTK_TREE_MODEL (search_summary), path); |
590 | path); | 525 | gtk_tree_path_free (path); |
591 | gtk_tree_path_free(path); | ||
592 | 526 | ||
593 | /* load label */ | 527 | /* load label */ |
594 | list->labelXML | 528 | list->labelXML |
595 | = glade_xml_new(getGladeFileName(), | 529 | = glade_xml_new (getGladeFileName (), |
596 | "searchTabLabelWindow", | 530 | "searchTabLabelWindow", PACKAGE_NAME); |
597 | PACKAGE_NAME); | 531 | connectGladeWithPlugins (list->labelXML); |
598 | connectGladeWithPlugins(list->labelXML); | ||
599 | list->tab_label | 532 | list->tab_label |
600 | = extractMainWidgetFromWindow(list->labelXML, | 533 | = extractMainWidgetFromWindow (list->labelXML, "searchTabLabelWindow"); |
601 | "searchTabLabelWindow"); | ||
602 | /* process existing results */ | 534 | /* process existing results */ |
603 | for (i=0;i<resultCount;i++) | 535 | for (i = 0; i < resultCount; i++) |
604 | fs_search_result_received(list, | 536 | fs_search_result_received (list, &results[i], uri); |
605 | &results[i], | 537 | if (resultCount == 0) /* otherwise already done! */ |
606 | uri); | 538 | updateSearchSummary (list); |
607 | if (resultCount == 0) /* otherwise already done! */ | ||
608 | updateSearchSummary(list); | ||
609 | 539 | ||
610 | /* insert new page into search notebook */ | 540 | /* insert new page into search notebook */ |
611 | notebook | 541 | notebook |
612 | = GTK_NOTEBOOK(glade_xml_get_widget(getMainXML(), | 542 | = GTK_NOTEBOOK (glade_xml_get_widget (getMainXML (), "downloadNotebook")); |
613 | "downloadNotebook")); | 543 | pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook)); |
614 | pages = gtk_notebook_get_n_pages(GTK_NOTEBOOK(notebook)); | 544 | gtk_notebook_append_page (notebook, list->searchpage, list->tab_label); |
615 | gtk_notebook_append_page(notebook, | 545 | gtk_notebook_set_current_page (notebook, pages); |
616 | list->searchpage, | 546 | gtk_widget_show (GTK_WIDGET (notebook)); /* may have been hidden! */ |
617 | list->tab_label); | ||
618 | gtk_notebook_set_current_page(notebook, | ||
619 | pages); | ||
620 | gtk_widget_show(GTK_WIDGET(notebook)); /* may have been hidden! */ | ||
621 | 547 | ||
622 | return list; | 548 | return list; |
623 | } | 549 | } |
@@ -626,42 +552,38 @@ fs_search_started(struct FSUI_SearchList * fsui_list, | |||
626 | * Recursively free the (internal) model data fields | 552 | * Recursively free the (internal) model data fields |
627 | * (uri and meta) from the search tree model. | 553 | * (uri and meta) from the search tree model. |
628 | */ | 554 | */ |
629 | static void freeIterSubtree(GtkTreeModel * tree, | 555 | static void |
630 | GtkTreeIter * iter) { | 556 | freeIterSubtree (GtkTreeModel * tree, GtkTreeIter * iter) |
557 | { | ||
631 | GtkTreeIter child; | 558 | GtkTreeIter child; |
632 | struct ECRS_URI * uri; | 559 | struct ECRS_URI *uri; |
633 | struct ECRS_MetaData * meta; | 560 | struct ECRS_MetaData *meta; |
634 | 561 | ||
635 | do { | 562 | do |
636 | uri = NULL; | 563 | { |
637 | meta = NULL; | 564 | uri = NULL; |
638 | gtk_tree_model_get(tree, | 565 | meta = NULL; |
639 | iter, | 566 | gtk_tree_model_get (tree, |
640 | SEARCH_URI, &uri, | 567 | iter, SEARCH_URI, &uri, SEARCH_META, &meta, -1); |
641 | SEARCH_META, &meta, | 568 | if (uri != NULL) |
642 | -1); | 569 | ECRS_freeUri (uri); |
643 | if (uri != NULL) | 570 | if (meta != NULL) |
644 | ECRS_freeUri(uri); | 571 | ECRS_freeMetaData (meta); |
645 | if (meta != NULL) | 572 | gtk_tree_store_set (GTK_TREE_STORE (tree), |
646 | ECRS_freeMetaData(meta); | 573 | iter, SEARCH_URI, NULL, SEARCH_META, NULL, -1); |
647 | gtk_tree_store_set(GTK_TREE_STORE(tree), | 574 | if (gtk_tree_model_iter_children (tree, &child, iter)) |
648 | iter, | 575 | freeIterSubtree (tree, &child); |
649 | SEARCH_URI, NULL, | 576 | } |
650 | SEARCH_META, NULL, | 577 | while (gtk_tree_model_iter_next (tree, iter)); |
651 | -1); | ||
652 | if (gtk_tree_model_iter_children(tree, | ||
653 | &child, | ||
654 | iter)) | ||
655 | freeIterSubtree(tree, &child); | ||
656 | } while (gtk_tree_model_iter_next(tree, | ||
657 | iter)); | ||
658 | } | 578 | } |
659 | 579 | ||
660 | /** | 580 | /** |
661 | * FSUI event: a search was aborted. | 581 | * FSUI event: a search was aborted. |
662 | * Update views accordingly. | 582 | * Update views accordingly. |
663 | */ | 583 | */ |
664 | void fs_search_aborted(SearchList * list) { | 584 | void |
585 | fs_search_aborted (SearchList * list) | ||
586 | { | ||
665 | /* FIXME: show aborted status somehow! */ | 587 | /* FIXME: show aborted status somehow! */ |
666 | } | 588 | } |
667 | 589 | ||
@@ -669,69 +591,68 @@ void fs_search_aborted(SearchList * list) { | |||
669 | * FSUI event: a search was stopped. Remove the | 591 | * FSUI event: a search was stopped. Remove the |
670 | * respective tab and its entry in the summary. | 592 | * respective tab and its entry in the summary. |
671 | */ | 593 | */ |
672 | void fs_search_stopped(SearchList * list) { | 594 | void |
673 | GtkNotebook * notebook; | 595 | fs_search_stopped (SearchList * list) |
596 | { | ||
597 | GtkNotebook *notebook; | ||
674 | GtkTreeIter iter; | 598 | GtkTreeIter iter; |
675 | SearchList * prev; | 599 | SearchList *prev; |
676 | DownloadList * downloads; | 600 | DownloadList *downloads; |
677 | GtkTreePath * path; | 601 | GtkTreePath *path; |
678 | int index; | 602 | int index; |
679 | int i; | 603 | int i; |
680 | 604 | ||
681 | /* remove from linked list */ | 605 | /* remove from linked list */ |
682 | if (search_head == list) { | 606 | if (search_head == list) |
683 | search_head = search_head->next; | 607 | { |
684 | } else { | 608 | search_head = search_head->next; |
685 | prev = search_head; | 609 | } |
686 | while (prev->next != list) | 610 | else |
687 | prev = prev->next; | 611 | { |
688 | prev->next = list->next; | 612 | prev = search_head; |
689 | } | 613 | while (prev->next != list) |
614 | prev = prev->next; | ||
615 | prev->next = list->next; | ||
616 | } | ||
690 | 617 | ||
691 | /* remove links from download views */ | 618 | /* remove links from download views */ |
692 | downloads = download_head; | 619 | downloads = download_head; |
693 | while (downloads != NULL) { | 620 | while (downloads != NULL) |
694 | if (downloads->searchList == list) { | 621 | { |
695 | gtk_tree_row_reference_free(downloads->searchViewRowReference); | 622 | if (downloads->searchList == list) |
696 | downloads->searchViewRowReference = NULL; | 623 | { |
697 | downloads->searchList = NULL; | 624 | gtk_tree_row_reference_free (downloads->searchViewRowReference); |
625 | downloads->searchViewRowReference = NULL; | ||
626 | downloads->searchList = NULL; | ||
627 | } | ||
628 | downloads = downloads->next; | ||
698 | } | 629 | } |
699 | downloads = downloads->next; | ||
700 | } | ||
701 | 630 | ||
702 | /* remove page from notebook */ | 631 | /* remove page from notebook */ |
703 | notebook | 632 | notebook |
704 | = GTK_NOTEBOOK(glade_xml_get_widget(getMainXML(), | 633 | = GTK_NOTEBOOK (glade_xml_get_widget (getMainXML (), "downloadNotebook")); |
705 | "downloadNotebook")); | ||
706 | index = -1; | 634 | index = -1; |
707 | for (i=gtk_notebook_get_n_pages(notebook)-1;i>=0;i--) | 635 | for (i = gtk_notebook_get_n_pages (notebook) - 1; i >= 0; i--) |
708 | if (list->searchpage == gtk_notebook_get_nth_page(notebook, | 636 | if (list->searchpage == gtk_notebook_get_nth_page (notebook, i)) |
709 | i)) | ||
710 | index = i; | 637 | index = i; |
711 | GE_BREAK(ectx, index != -1); | 638 | GE_BREAK (ectx, index != -1); |
712 | gtk_notebook_remove_page(notebook, | 639 | gtk_notebook_remove_page (notebook, index); |
713 | index); | ||
714 | /* recursively free search model */ | 640 | /* recursively free search model */ |
715 | if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(list->tree), | 641 | if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list->tree), &iter)) |
716 | &iter)) | 642 | freeIterSubtree (GTK_TREE_MODEL (list->tree), &iter); |
717 | freeIterSubtree(GTK_TREE_MODEL(list->tree), | ||
718 | &iter); | ||
719 | 643 | ||
720 | /* destroy entry in summary */ | 644 | /* destroy entry in summary */ |
721 | path = gtk_tree_row_reference_get_path(list->summaryViewRowReference); | 645 | path = gtk_tree_row_reference_get_path (list->summaryViewRowReference); |
722 | gtk_tree_model_get_iter(GTK_TREE_MODEL(search_summary), | 646 | gtk_tree_model_get_iter (GTK_TREE_MODEL (search_summary), &iter, path); |
723 | &iter, | 647 | gtk_tree_path_free (path); |
724 | path); | 648 | gtk_list_store_remove (search_summary, &iter); |
725 | gtk_tree_path_free(path); | ||
726 | gtk_list_store_remove(search_summary, | ||
727 | &iter); | ||
728 | /* free list state itself */ | 649 | /* free list state itself */ |
729 | UNREF(list->searchXML); | 650 | UNREF (list->searchXML); |
730 | UNREF(list->labelXML); | 651 | UNREF (list->labelXML); |
731 | gtk_tree_row_reference_free(list->summaryViewRowReference); | 652 | gtk_tree_row_reference_free (list->summaryViewRowReference); |
732 | FREE(list->searchString); | 653 | FREE (list->searchString); |
733 | ECRS_freeUri(list->uri); | 654 | ECRS_freeUri (list->uri); |
734 | FREE(list); | 655 | FREE (list); |
735 | } | 656 | } |
736 | 657 | ||
737 | /* ****************** User event handling ************* */ | 658 | /* ****************** User event handling ************* */ |
@@ -741,34 +662,32 @@ void fs_search_stopped(SearchList * list) { | |||
741 | * The user has edited the search entry. | 662 | * The user has edited the search entry. |
742 | * Update search button status. | 663 | * Update search button status. |
743 | */ | 664 | */ |
744 | void on_fssearchKeywordComboBoxEntry_changed_fs(gpointer dummy2, | 665 | void |
745 | GtkWidget * searchEntry) { | 666 | on_fssearchKeywordComboBoxEntry_changed_fs (gpointer dummy2, |
746 | const char * searchString; | 667 | GtkWidget * searchEntry) |
747 | GtkWidget * searchButton; | 668 | { |
748 | 669 | const char *searchString; | |
749 | searchString = getEntryLineValue(getMainXML(), | 670 | GtkWidget *searchButton; |
750 | "fssearchKeywordComboBoxEntry"); | 671 | |
751 | searchButton | 672 | searchString = getEntryLineValue (getMainXML (), |
752 | = glade_xml_get_widget(getMainXML(), | 673 | "fssearchKeywordComboBoxEntry"); |
753 | "fssearchbutton"); | 674 | searchButton = glade_xml_get_widget (getMainXML (), "fssearchbutton"); |
754 | gtk_widget_set_sensitive(searchButton, | 675 | gtk_widget_set_sensitive (searchButton, strlen (searchString) > 0); |
755 | strlen(searchString) > 0); | ||
756 | } | 676 | } |
757 | 677 | ||
758 | typedef struct { | 678 | typedef struct |
679 | { | ||
759 | unsigned int anonymity; | 680 | unsigned int anonymity; |
760 | unsigned int max; | 681 | unsigned int max; |
761 | cron_t delay; | 682 | cron_t delay; |
762 | struct ECRS_URI * uri; | 683 | struct ECRS_URI *uri; |
763 | } FSSS; | 684 | } FSSS; |
764 | 685 | ||
765 | static void * search_start_helper(void * cls) { | 686 | static void * |
766 | FSSS * fsss = cls; | 687 | search_start_helper (void *cls) |
767 | FSUI_startSearch(ctx, | 688 | { |
768 | fsss->anonymity, | 689 | FSSS *fsss = cls; |
769 | fsss->max, | 690 | FSUI_startSearch (ctx, fsss->anonymity, fsss->max, fsss->delay, fsss->uri); |
770 | fsss->delay, | ||
771 | fsss->uri); | ||
772 | return NULL; | 691 | return NULL; |
773 | } | 692 | } |
774 | 693 | ||
@@ -776,147 +695,146 @@ static void * search_start_helper(void * cls) { | |||
776 | * The user has clicked the "SEARCH" button. | 695 | * The user has clicked the "SEARCH" button. |
777 | * Initiate a search. | 696 | * Initiate a search. |
778 | */ | 697 | */ |
779 | void on_fssearchbutton_clicked_fs(gpointer dummy2, | 698 | void |
780 | GtkWidget * searchButton) { | 699 | on_fssearchbutton_clicked_fs (gpointer dummy2, GtkWidget * searchButton) |
700 | { | ||
781 | FSSS fsss; | 701 | FSSS fsss; |
782 | const char * searchString; | 702 | const char *searchString; |
783 | gint pages; | 703 | gint pages; |
784 | gint i; | 704 | gint i; |
785 | SearchList * list; | 705 | SearchList *list; |
786 | GtkTreeIter iter; | 706 | GtkTreeIter iter; |
787 | GtkComboBox * searchKeywordGtkCB; | 707 | GtkComboBox *searchKeywordGtkCB; |
788 | GtkWidget * searchNamespaceGtkCB; | 708 | GtkWidget *searchNamespaceGtkCB; |
789 | GtkNotebook * notebook; | 709 | GtkNotebook *notebook; |
790 | 710 | ||
791 | searchString = getEntryLineValue(getMainXML(), | 711 | searchString = getEntryLineValue (getMainXML (), |
792 | "fssearchKeywordComboBoxEntry"); | 712 | "fssearchKeywordComboBoxEntry"); |
793 | if ( (searchString == NULL) || | 713 | if ((searchString == NULL) || (strlen (searchString) == 0)) |
794 | (strlen(searchString) == 0) ) { | 714 | { |
795 | GE_LOG(ectx, | 715 | GE_LOG (ectx, |
796 | GE_ERROR | GE_USER | GE_IMMEDIATE, | 716 | GE_ERROR | GE_USER | GE_IMMEDIATE, |
797 | _("Need a keyword to search!\n")); | 717 | _("Need a keyword to search!\n")); |
798 | return; | 718 | return; |
799 | } | 719 | } |
800 | /* add the keyword to the list of keywords that have | 720 | /* add the keyword to the list of keywords that have |
801 | been used so far */ | 721 | been used so far */ |
802 | searchKeywordGtkCB | 722 | searchKeywordGtkCB |
803 | = GTK_COMBO_BOX(glade_xml_get_widget(getMainXML(), | 723 | = GTK_COMBO_BOX (glade_xml_get_widget (getMainXML (), |
804 | "fssearchKeywordComboBoxEntry")); | 724 | "fssearchKeywordComboBoxEntry")); |
805 | i = gtk_combo_box_get_active(searchKeywordGtkCB); | 725 | i = gtk_combo_box_get_active (searchKeywordGtkCB); |
806 | if (i == -1) { | 726 | if (i == -1) |
807 | GtkListStore * model; | 727 | { |
808 | 728 | GtkListStore *model; | |
809 | model = GTK_LIST_STORE(gtk_combo_box_get_model(searchKeywordGtkCB)); | 729 | |
810 | gtk_list_store_prepend(model, | 730 | model = GTK_LIST_STORE (gtk_combo_box_get_model (searchKeywordGtkCB)); |
811 | &iter); | 731 | gtk_list_store_prepend (model, &iter); |
812 | gtk_list_store_set(model, | 732 | gtk_list_store_set (model, &iter, 0, searchString, -1); |
813 | &iter, | 733 | } |
814 | 0, searchString, | ||
815 | -1); | ||
816 | } | ||
817 | fsss.uri = NULL; | 734 | fsss.uri = NULL; |
818 | /* check for namespace search */ | 735 | /* check for namespace search */ |
819 | searchNamespaceGtkCB | 736 | searchNamespaceGtkCB |
820 | = glade_xml_get_widget(getMainXML(), | 737 | = glade_xml_get_widget (getMainXML (), "searchNamespaceComboBoxEntry"); |
821 | "searchNamespaceComboBoxEntry"); | 738 | if (TRUE == |
822 | if (TRUE == gtk_combo_box_get_active_iter(GTK_COMBO_BOX(searchNamespaceGtkCB), | 739 | gtk_combo_box_get_active_iter (GTK_COMBO_BOX (searchNamespaceGtkCB), |
823 | &iter)) { | 740 | &iter)) |
824 | char * descStr; | 741 | { |
825 | char * ns; | 742 | char *descStr; |
826 | 743 | char *ns; | |
827 | ns = NULL; | 744 | |
828 | descStr = NULL; | ||
829 | gtk_tree_model_get(gtk_combo_box_get_model(GTK_COMBO_BOX(searchNamespaceGtkCB)), | ||
830 | &iter, | ||
831 | NS_SEARCH_DESCRIPTION, &descStr, | ||
832 | NS_SEARCH_ENCNAME, &ns, | ||
833 | -1); | ||
834 | |||
835 | if ( (descStr != NULL) && | ||
836 | (0 == strcmp(descStr, | ||
837 | _("globally"))) ) { | ||
838 | ns = NULL; | 745 | ns = NULL; |
839 | } else { | 746 | descStr = NULL; |
840 | GE_ASSERT(ectx, strlen(ns) == sizeof(EncName) - 1); | 747 | gtk_tree_model_get (gtk_combo_box_get_model |
841 | if ( (descStr == NULL) && | 748 | (GTK_COMBO_BOX (searchNamespaceGtkCB)), &iter, |
842 | (ns != NULL) ) | 749 | NS_SEARCH_DESCRIPTION, &descStr, NS_SEARCH_ENCNAME, |
843 | descStr = STRDUP(ns); | 750 | &ns, -1); |
751 | |||
752 | if ((descStr != NULL) && (0 == strcmp (descStr, _("globally")))) | ||
753 | { | ||
754 | ns = NULL; | ||
755 | } | ||
756 | else | ||
757 | { | ||
758 | GE_ASSERT (ectx, strlen (ns) == sizeof (EncName) - 1); | ||
759 | if ((descStr == NULL) && (ns != NULL)) | ||
760 | descStr = STRDUP (ns); | ||
761 | } | ||
762 | if (ns != NULL) | ||
763 | { | ||
764 | char *ustring; | ||
765 | |||
766 | ustring = MALLOC (strlen (searchString) + sizeof (EncName) + | ||
767 | strlen (ECRS_URI_PREFIX) + | ||
768 | strlen (ECRS_SUBSPACE_INFIX) + 10); | ||
769 | strcpy (ustring, ECRS_URI_PREFIX); | ||
770 | strcat (ustring, ECRS_SUBSPACE_INFIX); | ||
771 | strcat (ustring, ns); | ||
772 | strcat (ustring, "/"); | ||
773 | strcat (ustring, searchString); | ||
774 | fsss.uri = ECRS_stringToUri (ectx, ustring); | ||
775 | if (fsss.uri == NULL) | ||
776 | { | ||
777 | GE_LOG (ectx, | ||
778 | GE_ERROR | GE_BULK | GE_USER, | ||
779 | _("Failed to create namespace URI from `%s'.\n"), | ||
780 | ustring); | ||
781 | } | ||
782 | FREE (ustring); | ||
783 | } | ||
784 | if (descStr != NULL) | ||
785 | free (descStr); | ||
786 | if (ns != NULL) | ||
787 | free (ns); | ||
844 | } | 788 | } |
845 | if (ns != NULL) { | ||
846 | char * ustring; | ||
847 | |||
848 | ustring = MALLOC(strlen(searchString) + sizeof(EncName) + | ||
849 | strlen(ECRS_URI_PREFIX) + | ||
850 | strlen(ECRS_SUBSPACE_INFIX) + 10); | ||
851 | strcpy(ustring, ECRS_URI_PREFIX); | ||
852 | strcat(ustring, ECRS_SUBSPACE_INFIX); | ||
853 | strcat(ustring, ns); | ||
854 | strcat(ustring, "/"); | ||
855 | strcat(ustring, searchString); | ||
856 | fsss.uri = ECRS_stringToUri(ectx, ustring); | ||
857 | if (fsss.uri == NULL) { | ||
858 | GE_LOG(ectx, | ||
859 | GE_ERROR | GE_BULK | GE_USER, | ||
860 | _("Failed to create namespace URI from `%s'.\n"), | ||
861 | ustring); | ||
862 | } | ||
863 | FREE(ustring); | ||
864 | } | ||
865 | if (descStr != NULL) | ||
866 | free(descStr); | ||
867 | if (ns != NULL) | ||
868 | free(ns); | ||
869 | } | ||
870 | if (fsss.uri == NULL) | 789 | if (fsss.uri == NULL) |
871 | fsss.uri = ECRS_parseCharKeywordURI(ectx, searchString); | 790 | fsss.uri = ECRS_parseCharKeywordURI (ectx, searchString); |
872 | if (fsss.uri == NULL) { | 791 | if (fsss.uri == NULL) |
873 | GE_BREAK(ectx, 0); | 792 | { |
874 | return; | 793 | GE_BREAK (ectx, 0); |
875 | } | 794 | return; |
795 | } | ||
876 | /* check if search is already running */ | 796 | /* check if search is already running */ |
877 | notebook | 797 | notebook |
878 | = GTK_NOTEBOOK(glade_xml_get_widget(getMainXML(), | 798 | = GTK_NOTEBOOK (glade_xml_get_widget (getMainXML (), "downloadNotebook")); |
879 | "downloadNotebook")); | 799 | pages = gtk_notebook_get_n_pages (notebook); |
880 | pages = gtk_notebook_get_n_pages(notebook); | ||
881 | list = search_head; | 800 | list = search_head; |
882 | while (list != NULL) { | 801 | while (list != NULL) |
883 | if (ECRS_equalsUri(list->uri, | 802 | { |
884 | fsss.uri)) { | 803 | if (ECRS_equalsUri (list->uri, fsss.uri)) |
885 | for (i=0;i<pages;i++) { | 804 | { |
886 | if (gtk_notebook_get_nth_page(notebook, | 805 | for (i = 0; i < pages; i++) |
887 | i) | 806 | { |
888 | == list->searchpage) { | 807 | if (gtk_notebook_get_nth_page (notebook, i) == list->searchpage) |
889 | gtk_notebook_set_current_page(notebook, | 808 | { |
890 | i); | 809 | gtk_notebook_set_current_page (notebook, i); |
891 | ECRS_freeUri(fsss.uri); | 810 | ECRS_freeUri (fsss.uri); |
892 | return; | 811 | return; |
893 | } | 812 | } |
894 | } | 813 | } |
895 | GE_BREAK(ectx, 0); | 814 | GE_BREAK (ectx, 0); |
815 | } | ||
816 | list = list->next; | ||
896 | } | 817 | } |
897 | list = list->next; | 818 | fsss.anonymity = getSpinButtonValue (getMainXML (), |
898 | } | 819 | "searchAnonymitySelectionSpinButton"); |
899 | fsss.anonymity = getSpinButtonValue(getMainXML(), | 820 | fsss.max = getSpinButtonValue (getMainXML (), "maxResultsSpinButton"); |
900 | "searchAnonymitySelectionSpinButton"); | 821 | fsss.delay = getSpinButtonValue (getMainXML (), |
901 | fsss.max = getSpinButtonValue(getMainXML(), | 822 | "searchDelaySpinButton") * cronSECONDS; |
902 | "maxResultsSpinButton"); | 823 | run_with_save_calls (search_start_helper, &fsss); |
903 | fsss.delay = getSpinButtonValue(getMainXML(), | 824 | ECRS_freeUri (fsss.uri); |
904 | "searchDelaySpinButton") * cronSECONDS; | ||
905 | run_with_save_calls(search_start_helper, | ||
906 | &fsss); | ||
907 | ECRS_freeUri(fsss.uri); | ||
908 | } | 825 | } |
909 | 826 | ||
910 | struct FCBC { | 827 | struct FCBC |
911 | int (*method)(struct FSUI_Context * ctx, | 828 | { |
912 | struct FSUI_SearchList * list); | 829 | int (*method) (struct FSUI_Context * ctx, struct FSUI_SearchList * list); |
913 | struct FSUI_SearchList * argument; | 830 | struct FSUI_SearchList *argument; |
914 | }; | 831 | }; |
915 | 832 | ||
916 | static void * fsui_callback(void * cls) { | 833 | static void * |
917 | struct FCBC * fcbc = cls; | 834 | fsui_callback (void *cls) |
918 | fcbc->method(ctx, | 835 | { |
919 | fcbc->argument); | 836 | struct FCBC *fcbc = cls; |
837 | fcbc->method (ctx, fcbc->argument); | ||
920 | return NULL; | 838 | return NULL; |
921 | } | 839 | } |
922 | 840 | ||
@@ -928,132 +846,131 @@ static void * fsui_callback(void * cls) { | |||
928 | * either refer to the main page in the tab or to the | 846 | * either refer to the main page in the tab or to the |
929 | * main entry of the tab label. | 847 | * main entry of the tab label. |
930 | */ | 848 | */ |
931 | void on_closeSearchButton_clicked_fs(GtkWidget * searchPage, | 849 | void |
932 | GtkWidget * closeButton) { | 850 | on_closeSearchButton_clicked_fs (GtkWidget * searchPage, |
933 | SearchList * list; | 851 | GtkWidget * closeButton) |
852 | { | ||
853 | SearchList *list; | ||
934 | struct FCBC fcbc; | 854 | struct FCBC fcbc; |
935 | 855 | ||
936 | list = search_head; | 856 | list = search_head; |
937 | while (list != NULL) { | 857 | while (list != NULL) |
938 | if ( (list->searchpage == searchPage) || | 858 | { |
939 | (list->tab_label == searchPage) ) | 859 | if ((list->searchpage == searchPage) || (list->tab_label == searchPage)) |
940 | break; | 860 | break; |
941 | list = list->next; | 861 | list = list->next; |
942 | } | 862 | } |
943 | GE_ASSERT(ectx, list != NULL); | 863 | GE_ASSERT (ectx, list != NULL); |
944 | if (list->fsui_list == NULL) { | 864 | if (list->fsui_list == NULL) |
945 | /* open directory - close directly */ | 865 | { |
946 | fs_search_stopped(list); | 866 | /* open directory - close directly */ |
947 | } else { | 867 | fs_search_stopped (list); |
948 | /* actual search - close via FSUI */ | 868 | } |
949 | fcbc.method = &FSUI_abortSearch; | 869 | else |
950 | fcbc.argument = list->fsui_list; | 870 | { |
951 | run_with_save_calls(&fsui_callback, | 871 | /* actual search - close via FSUI */ |
952 | &fcbc); | 872 | fcbc.method = &FSUI_abortSearch; |
953 | fcbc.method = &FSUI_stopSearch; | 873 | fcbc.argument = list->fsui_list; |
954 | run_with_save_calls(&fsui_callback, | 874 | run_with_save_calls (&fsui_callback, &fcbc); |
955 | &fcbc); | 875 | fcbc.method = &FSUI_stopSearch; |
956 | } | 876 | run_with_save_calls (&fsui_callback, &fcbc); |
877 | } | ||
957 | } | 878 | } |
958 | 879 | ||
959 | /** | 880 | /** |
960 | * The abort button was clicked. Abort the search. | 881 | * The abort button was clicked. Abort the search. |
961 | */ | 882 | */ |
962 | void on_abortSearchButton_clicked_fs(GtkWidget * searchPage, | 883 | void |
963 | GtkWidget * closeButton) { | 884 | on_abortSearchButton_clicked_fs (GtkWidget * searchPage, |
964 | SearchList * list; | 885 | GtkWidget * closeButton) |
886 | { | ||
887 | SearchList *list; | ||
965 | struct FCBC fcbc; | 888 | struct FCBC fcbc; |
966 | 889 | ||
967 | list = search_head; | 890 | list = search_head; |
968 | while (list != NULL) { | 891 | while (list != NULL) |
969 | if (list->searchpage == searchPage) | 892 | { |
970 | break; | 893 | if (list->searchpage == searchPage) |
971 | list = list->next; | 894 | break; |
972 | } | 895 | list = list->next; |
973 | GE_ASSERT(ectx, list != NULL); | 896 | } |
974 | if (list->fsui_list != NULL) { | 897 | GE_ASSERT (ectx, list != NULL); |
975 | fcbc.method = &FSUI_abortSearch; | 898 | if (list->fsui_list != NULL) |
976 | fcbc.argument = list->fsui_list; | 899 | { |
977 | run_with_save_calls(&fsui_callback, | 900 | fcbc.method = &FSUI_abortSearch; |
978 | &fcbc); | 901 | fcbc.argument = list->fsui_list; |
979 | } | 902 | run_with_save_calls (&fsui_callback, &fcbc); |
903 | } | ||
980 | } | 904 | } |
981 | 905 | ||
982 | static void stopSearch(GtkTreeModel * model, | 906 | static void |
983 | GtkTreePath * path, | 907 | stopSearch (GtkTreeModel * model, |
984 | GtkTreeIter * iter, | 908 | GtkTreePath * path, GtkTreeIter * iter, gpointer unused) |
985 | gpointer unused) { | 909 | { |
986 | SearchList * s; | 910 | SearchList *s; |
987 | struct FCBC fcbc; | 911 | struct FCBC fcbc; |
988 | 912 | ||
989 | s = NULL; | 913 | s = NULL; |
990 | gtk_tree_model_get(model, | 914 | gtk_tree_model_get (model, iter, SEARCH_SUMMARY_INTERNAL, &s, -1); |
991 | iter, | 915 | if (s != NULL) |
992 | SEARCH_SUMMARY_INTERNAL, &s, | 916 | { |
993 | -1); | 917 | if (s->fsui_list == NULL) |
994 | if (s != NULL) { | 918 | { |
995 | if (s->fsui_list == NULL) { | 919 | /* open directory - close directly */ |
996 | /* open directory - close directly */ | 920 | fs_search_stopped (s); |
997 | fs_search_stopped(s); | 921 | } |
998 | } else { | 922 | else |
999 | fcbc.method = &FSUI_abortSearch; | 923 | { |
1000 | fcbc.argument = s->fsui_list; | 924 | fcbc.method = &FSUI_abortSearch; |
1001 | run_with_save_calls(&fsui_callback, | 925 | fcbc.argument = s->fsui_list; |
1002 | &fcbc); | 926 | run_with_save_calls (&fsui_callback, &fcbc); |
1003 | fcbc.method = &FSUI_stopSearch; | 927 | fcbc.method = &FSUI_stopSearch; |
1004 | run_with_save_calls(&fsui_callback, | 928 | run_with_save_calls (&fsui_callback, &fcbc); |
1005 | &fcbc); | 929 | } |
1006 | } | 930 | } |
1007 | } | ||
1008 | } | 931 | } |
1009 | 932 | ||
1010 | /** | 933 | /** |
1011 | * The stop button in the search summary was clicked. | 934 | * The stop button in the search summary was clicked. |
1012 | */ | 935 | */ |
1013 | void on_closeSearchSummaryButton_clicked_fs(GtkWidget * treeview, | 936 | void |
1014 | GtkWidget * closeButton) { | 937 | on_closeSearchSummaryButton_clicked_fs (GtkWidget * treeview, |
1015 | GtkTreeSelection * selection; | 938 | GtkWidget * closeButton) |
1016 | 939 | { | |
1017 | selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); | 940 | GtkTreeSelection *selection; |
1018 | ggc_tree_selection_selected_foreach | 941 | |
1019 | (selection, | 942 | selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)); |
1020 | &stopSearch, | 943 | ggc_tree_selection_selected_foreach (selection, &stopSearch, NULL); |
1021 | NULL); | ||
1022 | } | 944 | } |
1023 | 945 | ||
1024 | static void abortSearch(GtkTreeModel * model, | 946 | static void |
1025 | GtkTreePath * path, | 947 | abortSearch (GtkTreeModel * model, |
1026 | GtkTreeIter * iter, | 948 | GtkTreePath * path, GtkTreeIter * iter, gpointer unused) |
1027 | gpointer unused) { | 949 | { |
1028 | SearchList * s; | 950 | SearchList *s; |
1029 | struct FCBC fcbc; | 951 | struct FCBC fcbc; |
1030 | 952 | ||
1031 | s = NULL; | 953 | s = NULL; |
1032 | gtk_tree_model_get(model, | 954 | gtk_tree_model_get (model, iter, SEARCH_SUMMARY_INTERNAL, &s, -1); |
1033 | iter, | 955 | if ((s != NULL) && (s->fsui_list != NULL)) |
1034 | SEARCH_SUMMARY_INTERNAL, &s, | 956 | { |
1035 | -1); | 957 | fcbc.method = &FSUI_abortSearch; |
1036 | if ( (s != NULL) && | 958 | fcbc.argument = s->fsui_list; |
1037 | (s->fsui_list != NULL) ) { | 959 | run_with_save_calls (&fsui_callback, &fcbc); |
1038 | fcbc.method = &FSUI_abortSearch; | 960 | } |
1039 | fcbc.argument = s->fsui_list; | ||
1040 | run_with_save_calls(&fsui_callback, | ||
1041 | &fcbc); | ||
1042 | } | ||
1043 | } | 961 | } |
1044 | 962 | ||
1045 | /** | 963 | /** |
1046 | * The abort button in the search summary was clicked. | 964 | * The abort button in the search summary was clicked. |
1047 | */ | 965 | */ |
1048 | void on_abortSearchSummaryButton_clicked_fs(GtkWidget * treeview, | 966 | void |
1049 | GtkWidget * closeButton) { | 967 | on_abortSearchSummaryButton_clicked_fs (GtkWidget * treeview, |
1050 | GtkTreeSelection * selection; | 968 | GtkWidget * closeButton) |
1051 | 969 | { | |
1052 | selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); | 970 | GtkTreeSelection *selection; |
1053 | ggc_tree_selection_selected_foreach | 971 | |
1054 | (selection, | 972 | selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)); |
1055 | &abortSearch, | 973 | ggc_tree_selection_selected_foreach (selection, &abortSearch, NULL); |
1056 | NULL); | ||
1057 | } | 974 | } |
1058 | 975 | ||
1059 | /* end of search.c */ | 976 | /* end of search.c */ |
diff --git a/src/plugins/fs/search.h b/src/plugins/fs/search.h index 4afc1496..82d7a8f3 100644 --- a/src/plugins/fs/search.h +++ b/src/plugins/fs/search.h | |||
@@ -36,10 +36,9 @@ | |||
36 | * Add the given search result to the search | 36 | * Add the given search result to the search |
37 | * tree at the specified position. | 37 | * tree at the specified position. |
38 | */ | 38 | */ |
39 | void addEntryToSearchTree(SearchList * searchContext, | 39 | void addEntryToSearchTree (SearchList * searchContext, |
40 | DownloadList * downloadParent, | 40 | DownloadList * downloadParent, |
41 | const ECRS_FileInfo * info, | 41 | const ECRS_FileInfo * info, GtkTreeIter * iter); |
42 | GtkTreeIter * iter); | ||
43 | 42 | ||
44 | /** | 43 | /** |
45 | * Add the given result to the model (search result | 44 | * Add the given result to the model (search result |
@@ -49,31 +48,30 @@ void addEntryToSearchTree(SearchList * searchContext, | |||
49 | * @param path the tree path that selects where to add | 48 | * @param path the tree path that selects where to add |
50 | * the information, NULL for top-level | 49 | * the information, NULL for top-level |
51 | */ | 50 | */ |
52 | void fs_search_result_received(SearchList * searchContext, | 51 | void fs_search_result_received (SearchList * searchContext, |
53 | const ECRS_FileInfo * info, | 52 | const ECRS_FileInfo * info, |
54 | const struct ECRS_URI * uri); | 53 | const struct ECRS_URI *uri); |
55 | 54 | ||
56 | /** | 55 | /** |
57 | * A search has been started. Open tab. | 56 | * A search has been started. Open tab. |
58 | * | 57 | * |
59 | * @return internal search context | 58 | * @return internal search context |
60 | */ | 59 | */ |
61 | SearchList * | 60 | SearchList *fs_search_started (struct FSUI_SearchList *list, |
62 | fs_search_started(struct FSUI_SearchList * list, | 61 | const struct ECRS_URI *uri, |
63 | const struct ECRS_URI * uri, | 62 | unsigned int anonymityLevel, |
64 | unsigned int anonymityLevel, | 63 | unsigned int resultCount, |
65 | unsigned int resultCount, | 64 | const ECRS_FileInfo * results, |
66 | const ECRS_FileInfo * results, | 65 | FSUI_State state); |
67 | FSUI_State state); | ||
68 | 66 | ||
69 | /** | 67 | /** |
70 | * A search process has been aborted. Update display. | 68 | * A search process has been aborted. Update display. |
71 | */ | 69 | */ |
72 | void fs_search_aborted(SearchList * searchContext); | 70 | void fs_search_aborted (SearchList * searchContext); |
73 | 71 | ||
74 | /** | 72 | /** |
75 | * A search process has stopped. Clean up. | 73 | * A search process has stopped. Clean up. |
76 | */ | 74 | */ |
77 | void fs_search_stopped(SearchList * searchContext); | 75 | void fs_search_stopped (SearchList * searchContext); |
78 | 76 | ||
79 | #endif | 77 | #endif |
diff --git a/src/plugins/fs/upload.c b/src/plugins/fs/upload.c index 8a19adb1..071d64f1 100644 --- a/src/plugins/fs/upload.c +++ b/src/plugins/fs/upload.c | |||
@@ -44,145 +44,128 @@ | |||
44 | * (there can only be one at a time; | 44 | * (there can only be one at a time; |
45 | * maybe NULL at times where there is no dialog) | 45 | * maybe NULL at times where there is no dialog) |
46 | */ | 46 | */ |
47 | static GladeXML * metaXML; | 47 | static GladeXML *metaXML; |
48 | 48 | ||
49 | /* ************ FSUI event handlers ************ */ | 49 | /* ************ FSUI event handlers ************ */ |
50 | 50 | ||
51 | void fs_upload_update(UploadList * list, | 51 | void |
52 | unsigned long long completed) { | 52 | fs_upload_update (UploadList * list, unsigned long long completed) |
53 | { | ||
53 | GtkTreeIter iter; | 54 | GtkTreeIter iter; |
54 | GtkTreePath * path; | 55 | GtkTreePath *path; |
55 | int progress; | 56 | int progress; |
56 | 57 | ||
57 | if (list->total != 0) | 58 | if (list->total != 0) |
58 | progress = 100 * completed / list->total; | 59 | progress = 100 * completed / list->total; |
59 | else | 60 | else |
60 | progress = 100; | 61 | progress = 100; |
61 | path = gtk_tree_row_reference_get_path(list->summaryViewRowReference); | 62 | path = gtk_tree_row_reference_get_path (list->summaryViewRowReference); |
62 | gtk_tree_model_get_iter(GTK_TREE_MODEL(upload_summary), | 63 | gtk_tree_model_get_iter (GTK_TREE_MODEL (upload_summary), &iter, path); |
63 | &iter, | 64 | gtk_tree_path_free (path); |
64 | path); | 65 | gtk_tree_store_set (upload_summary, &iter, UPLOAD_PROGRESS, progress, -1); |
65 | gtk_tree_path_free(path); | ||
66 | gtk_tree_store_set(upload_summary, | ||
67 | &iter, | ||
68 | UPLOAD_PROGRESS, progress, | ||
69 | -1); | ||
70 | } | 66 | } |
71 | 67 | ||
72 | void fs_upload_complete(UploadList * list, | 68 | void |
73 | struct ECRS_URI * uri) { | 69 | fs_upload_complete (UploadList * list, struct ECRS_URI *uri) |
70 | { | ||
74 | GtkTreeIter iter; | 71 | GtkTreeIter iter; |
75 | GtkTreePath * path; | 72 | GtkTreePath *path; |
76 | char * us; | 73 | char *us; |
77 | 74 | ||
78 | list->has_terminated = YES; | 75 | list->has_terminated = YES; |
79 | list->uri = ECRS_dupUri(uri); | 76 | list->uri = ECRS_dupUri (uri); |
80 | us = ECRS_uriToString(uri); | 77 | us = ECRS_uriToString (uri); |
81 | path = gtk_tree_row_reference_get_path(list->summaryViewRowReference); | 78 | path = gtk_tree_row_reference_get_path (list->summaryViewRowReference); |
82 | gtk_tree_model_get_iter(GTK_TREE_MODEL(upload_summary), | 79 | gtk_tree_model_get_iter (GTK_TREE_MODEL (upload_summary), &iter, path); |
83 | &iter, | 80 | gtk_tree_path_free (path); |
84 | path); | 81 | gtk_tree_store_set (upload_summary, &iter, UPLOAD_URISTRING, us, -1); |
85 | gtk_tree_path_free(path); | 82 | FREE (us); |
86 | gtk_tree_store_set(upload_summary, | ||
87 | &iter, | ||
88 | UPLOAD_URISTRING, us, | ||
89 | -1); | ||
90 | FREE(us); | ||
91 | } | 83 | } |
92 | 84 | ||
93 | void fs_upload_error(UploadList * list) { | 85 | void |
86 | fs_upload_error (UploadList * list) | ||
87 | { | ||
94 | /* FIXME: indicate error in summary dialog! */ | 88 | /* FIXME: indicate error in summary dialog! */ |
95 | list->has_terminated = YES; | 89 | list->has_terminated = YES; |
96 | } | 90 | } |
97 | 91 | ||
98 | void fs_upload_stopped(UploadList * list) { | 92 | void |
93 | fs_upload_stopped (UploadList * list) | ||
94 | { | ||
99 | GtkTreeIter iter; | 95 | GtkTreeIter iter; |
100 | GtkTreePath * path; | 96 | GtkTreePath *path; |
101 | UploadList * prev; | 97 | UploadList *prev; |
102 | 98 | ||
103 | path = gtk_tree_row_reference_get_path(list->summaryViewRowReference); | 99 | path = gtk_tree_row_reference_get_path (list->summaryViewRowReference); |
104 | gtk_tree_model_get_iter(GTK_TREE_MODEL(upload_summary), | 100 | gtk_tree_model_get_iter (GTK_TREE_MODEL (upload_summary), &iter, path); |
105 | &iter, | 101 | gtk_tree_path_free (path); |
106 | path); | 102 | gtk_tree_row_reference_free (list->summaryViewRowReference); |
107 | gtk_tree_path_free(path); | ||
108 | gtk_tree_row_reference_free(list->summaryViewRowReference); | ||
109 | list->summaryViewRowReference = NULL; | 103 | list->summaryViewRowReference = NULL; |
110 | gtk_tree_store_remove(upload_summary, | 104 | gtk_tree_store_remove (upload_summary, &iter); |
111 | &iter); | 105 | FREE (list->filename); |
112 | FREE(list->filename); | 106 | if (list->uri != NULL) |
113 | if (list->uri != NULL) { | 107 | { |
114 | ECRS_freeUri(list->uri); | 108 | ECRS_freeUri (list->uri); |
115 | list->uri = NULL; | 109 | list->uri = NULL; |
116 | } | 110 | } |
117 | if (upload_head == list) | 111 | if (upload_head == list) |
118 | upload_head = list->next; | 112 | upload_head = list->next; |
119 | else { | 113 | else |
120 | prev = upload_head; | 114 | { |
121 | while ( (prev != NULL) && | 115 | prev = upload_head; |
122 | (prev->next != list) ) | 116 | while ((prev != NULL) && (prev->next != list)) |
123 | prev = prev->next; | 117 | prev = prev->next; |
124 | if (prev != NULL) | 118 | if (prev != NULL) |
125 | prev->next = list->next; | 119 | prev->next = list->next; |
126 | else | 120 | else |
127 | GE_BREAK(ectx, 0); | 121 | GE_BREAK (ectx, 0); |
128 | } | 122 | } |
129 | FREE(list); | 123 | FREE (list); |
130 | } | 124 | } |
131 | 125 | ||
132 | UploadList * | 126 | UploadList * |
133 | fs_upload_started(struct FSUI_UploadList * fsui, | 127 | fs_upload_started (struct FSUI_UploadList *fsui, |
134 | UploadList * parent, | 128 | UploadList * parent, |
135 | const char * filename, | 129 | const char *filename, |
136 | struct ECRS_URI * uri, | 130 | struct ECRS_URI *uri, |
137 | unsigned long long total, | 131 | unsigned long long total, |
138 | unsigned long long completed, | 132 | unsigned long long completed, FSUI_State state) |
139 | FSUI_State state) { | 133 | { |
140 | UploadList * ret; | 134 | UploadList *ret; |
141 | GtkTreeIter iter; | 135 | GtkTreeIter iter; |
142 | GtkTreePath * path; | 136 | GtkTreePath *path; |
143 | int progress; | 137 | int progress; |
144 | GtkTreeIter par; | 138 | GtkTreeIter par; |
145 | 139 | ||
146 | ret = MALLOC(sizeof(UploadList)); | 140 | ret = MALLOC (sizeof (UploadList)); |
147 | memset(ret, | 141 | memset (ret, 0, sizeof (UploadList)); |
148 | 0, | 142 | ret->filename = STRDUP (filename); |
149 | sizeof(UploadList)); | ||
150 | ret->filename = STRDUP(filename); | ||
151 | ret->fsui_list = fsui; | 143 | ret->fsui_list = fsui; |
152 | ret->total = total; | 144 | ret->total = total; |
153 | ret->is_top = parent == NULL; | 145 | ret->is_top = parent == NULL; |
154 | if ( (parent != NULL) && | 146 | if ((parent != NULL) && |
155 | (NULL != (path = gtk_tree_row_reference_get_path(parent->summaryViewRowReference))) ) { | 147 | (NULL != |
156 | gtk_tree_model_get_iter(GTK_TREE_MODEL(upload_summary), | 148 | (path = |
157 | &par, | 149 | gtk_tree_row_reference_get_path (parent->summaryViewRowReference)))) |
158 | path); | 150 | { |
159 | gtk_tree_path_free(path); | 151 | gtk_tree_model_get_iter (GTK_TREE_MODEL (upload_summary), &par, path); |
160 | gtk_tree_store_append(upload_summary, | 152 | gtk_tree_path_free (path); |
161 | &iter, | 153 | gtk_tree_store_append (upload_summary, &iter, &par); |
162 | &par); | 154 | } |
163 | } else { | 155 | else |
164 | gtk_tree_store_append(upload_summary, | 156 | { |
165 | &iter, | 157 | gtk_tree_store_append (upload_summary, &iter, NULL); |
166 | NULL); | 158 | } |
167 | } | ||
168 | if (total != 0) | 159 | if (total != 0) |
169 | progress = 100 * completed / total; | 160 | progress = 100 * completed / total; |
170 | else | 161 | else |
171 | progress = 100; | 162 | progress = 100; |
172 | gtk_tree_store_set(upload_summary, | 163 | gtk_tree_store_set (upload_summary, &iter, UPLOAD_FILENAME, filename, UPLOAD_PROGRESS, progress, UPLOAD_URISTRING, "", /* FIXME: set if URI != NULL! */ |
173 | &iter, | 164 | UPLOAD_INTERNAL, ret, -1); |
174 | UPLOAD_FILENAME, filename, | 165 | path = gtk_tree_model_get_path (GTK_TREE_MODEL (upload_summary), &iter); |
175 | UPLOAD_PROGRESS, progress, | ||
176 | UPLOAD_URISTRING, "", /* FIXME: set if URI != NULL! */ | ||
177 | UPLOAD_INTERNAL, ret, | ||
178 | -1); | ||
179 | path = gtk_tree_model_get_path(GTK_TREE_MODEL(upload_summary), | ||
180 | &iter); | ||
181 | ret->summaryViewRowReference | 166 | ret->summaryViewRowReference |
182 | = gtk_tree_row_reference_new(GTK_TREE_MODEL(upload_summary), | 167 | = gtk_tree_row_reference_new (GTK_TREE_MODEL (upload_summary), path); |
183 | path); | 168 | ret->has_terminated = ((state != FSUI_ACTIVE) && (state != FSUI_PENDING)); |
184 | ret->has_terminated = ( (state != FSUI_ACTIVE) && | ||
185 | (state != FSUI_PENDING) ); | ||
186 | 169 | ||
187 | ret->next = upload_head; | 170 | ret->next = upload_head; |
188 | upload_head = ret; | 171 | upload_head = ret; |
@@ -192,476 +175,452 @@ fs_upload_started(struct FSUI_UploadList * fsui, | |||
192 | /* *************** user upload event handling ************** */ | 175 | /* *************** user upload event handling ************** */ |
193 | 176 | ||
194 | 177 | ||
195 | void on_selectAlternativePreviewButton_selection_changed_fs(GtkWidget * preview, | 178 | void |
196 | GtkWidget * fileChooser) { | 179 | on_selectAlternativePreviewButton_selection_changed_fs (GtkWidget * preview, |
197 | char * fn; | 180 | GtkWidget * |
198 | 181 | fileChooser) | |
199 | fn = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(fileChooser)); | 182 | { |
200 | if (fn == NULL) { | 183 | char *fn; |
201 | gtk_image_set_from_pixbuf(GTK_IMAGE(preview), | 184 | |
202 | NULL); | 185 | fn = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (fileChooser)); |
203 | } else { | 186 | if (fn == NULL) |
204 | GdkPixbuf * buf; | 187 | { |
205 | 188 | gtk_image_set_from_pixbuf (GTK_IMAGE (preview), NULL); | |
206 | buf = gdk_pixbuf_new_from_file(fn, | 189 | } |
207 | NULL); | 190 | else |
208 | gtk_image_set_from_pixbuf(GTK_IMAGE(preview), | 191 | { |
209 | buf); | 192 | GdkPixbuf *buf; |
210 | g_object_unref(buf); | 193 | |
211 | free(fn); | 194 | buf = gdk_pixbuf_new_from_file (fn, NULL); |
212 | } | 195 | gtk_image_set_from_pixbuf (GTK_IMAGE (preview), buf); |
196 | g_object_unref (buf); | ||
197 | free (fn); | ||
198 | } | ||
213 | } | 199 | } |
214 | 200 | ||
215 | void on_metaDataDialogKeywordAddButton_clicked_fs(gpointer dummy, | 201 | void |
216 | GtkWidget * button) { | 202 | on_metaDataDialogKeywordAddButton_clicked_fs (gpointer dummy, |
217 | handleKeywordListUpdate(metaXML, | 203 | GtkWidget * button) |
218 | "fileInformationKeywordEntry", | 204 | { |
219 | "metaDataDialogKeywordList"); | 205 | handleKeywordListUpdate (metaXML, |
206 | "fileInformationKeywordEntry", | ||
207 | "metaDataDialogKeywordList"); | ||
220 | } | 208 | } |
221 | 209 | ||
222 | void on_metaDataDialogMetaDataAddButton_clicked_fs(gpointer dummy, | 210 | void |
223 | GtkWidget * button) { | 211 | on_metaDataDialogMetaDataAddButton_clicked_fs (gpointer dummy, |
224 | handleMetaDataListUpdate(metaXML, | 212 | GtkWidget * button) |
225 | "metaDataDialogMetaTypeComboBox", | 213 | { |
226 | "metaDataDialogValueEntry", | 214 | handleMetaDataListUpdate (metaXML, |
227 | "metaDataDialogMetaDataList"); | 215 | "metaDataDialogMetaTypeComboBox", |
216 | "metaDataDialogValueEntry", | ||
217 | "metaDataDialogMetaDataList"); | ||
228 | } | 218 | } |
229 | 219 | ||
230 | void on_metaDataDialogKeywordRemoveButton_clicked_fs(gpointer dummy, | 220 | void |
231 | GtkWidget * button) { | 221 | on_metaDataDialogKeywordRemoveButton_clicked_fs (gpointer dummy, |
232 | handleListRemove(metaXML, | 222 | GtkWidget * button) |
233 | "metaDataDialogKeywordList"); | 223 | { |
224 | handleListRemove (metaXML, "metaDataDialogKeywordList"); | ||
234 | } | 225 | } |
235 | 226 | ||
236 | void on_metaDataDialogMetaDataRemoveButton_clicked_fs(gpointer dummy, | 227 | void |
237 | GtkWidget * button) { | 228 | on_metaDataDialogMetaDataRemoveButton_clicked_fs (gpointer dummy, |
238 | handleListRemove(metaXML, | 229 | GtkWidget * button) |
239 | "metaDataDialogMetaDataList"); | 230 | { |
231 | handleListRemove (metaXML, "metaDataDialogMetaDataList"); | ||
240 | } | 232 | } |
241 | 233 | ||
242 | /** | 234 | /** |
243 | * The selection of the keyword list changed. | 235 | * The selection of the keyword list changed. |
244 | * Update button status. | 236 | * Update button status. |
245 | */ | 237 | */ |
246 | static void on_keyword_list_selection_changed(gpointer signal, | 238 | static void |
247 | gpointer cls) { | 239 | on_keyword_list_selection_changed (gpointer signal, gpointer cls) |
248 | GtkTreeSelection * selection; | 240 | { |
249 | GtkWidget * button; | 241 | GtkTreeSelection *selection; |
250 | 242 | GtkWidget *button; | |
251 | selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(glade_xml_get_widget(metaXML, | 243 | |
252 | "metaDataDialogKeywordList"))); | 244 | selection = |
253 | button | 245 | gtk_tree_view_get_selection (GTK_TREE_VIEW |
254 | = glade_xml_get_widget(metaXML, | 246 | (glade_xml_get_widget |
255 | "metaDataDialogKeywordRemoveButton"); | 247 | (metaXML, "metaDataDialogKeywordList"))); |
256 | gtk_widget_set_sensitive(button, | 248 | button = |
257 | gtk_tree_selection_count_selected_rows(selection) > 0); | 249 | glade_xml_get_widget (metaXML, "metaDataDialogKeywordRemoveButton"); |
250 | gtk_widget_set_sensitive (button, | ||
251 | gtk_tree_selection_count_selected_rows (selection) | ||
252 | > 0); | ||
258 | } | 253 | } |
259 | 254 | ||
260 | /** | 255 | /** |
261 | * The selection of the metadata list changed. | 256 | * The selection of the metadata list changed. |
262 | * Update button status. | 257 | * Update button status. |
263 | */ | 258 | */ |
264 | static void on_metadata_list_selection_changed(gpointer signal, | 259 | static void |
265 | gpointer cls) { | 260 | on_metadata_list_selection_changed (gpointer signal, gpointer cls) |
266 | GtkTreeSelection * selection; | 261 | { |
267 | GtkWidget * button; | 262 | GtkTreeSelection *selection; |
268 | 263 | GtkWidget *button; | |
269 | selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(glade_xml_get_widget(metaXML, | 264 | |
270 | "metaDataDialogMetaDataList"))); | 265 | selection = |
271 | button | 266 | gtk_tree_view_get_selection (GTK_TREE_VIEW |
272 | = glade_xml_get_widget(metaXML, | 267 | (glade_xml_get_widget |
273 | "metaDataDialogMetaDataRemoveButton"); | 268 | (metaXML, "metaDataDialogMetaDataList"))); |
274 | gtk_widget_set_sensitive(button, | 269 | button = |
275 | gtk_tree_selection_count_selected_rows(selection) > 0); | 270 | glade_xml_get_widget (metaXML, "metaDataDialogMetaDataRemoveButton"); |
271 | gtk_widget_set_sensitive (button, | ||
272 | gtk_tree_selection_count_selected_rows (selection) | ||
273 | > 0); | ||
276 | } | 274 | } |
277 | 275 | ||
278 | /** | 276 | /** |
279 | * The user has edited the metadata entry. | 277 | * The user has edited the metadata entry. |
280 | * Update add button status. | 278 | * Update add button status. |
281 | */ | 279 | */ |
282 | void on_metaDataDialogValueEntry_changed_fs(gpointer dummy2, | 280 | void |
283 | GtkWidget * searchEntry) { | 281 | on_metaDataDialogValueEntry_changed_fs (gpointer dummy2, |
284 | const char * input; | 282 | GtkWidget * searchEntry) |
285 | GtkWidget * button; | 283 | { |
286 | 284 | const char *input; | |
287 | input = gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(metaXML, | 285 | GtkWidget *button; |
288 | "metaDataDialogValueEntry"))); | 286 | |
287 | input = gtk_entry_get_text (GTK_ENTRY (glade_xml_get_widget (metaXML, | ||
288 | "metaDataDialogValueEntry"))); | ||
289 | if (input == NULL) | 289 | if (input == NULL) |
290 | return; | 290 | return; |
291 | button | 291 | button = glade_xml_get_widget (metaXML, "metaDataDialogMetaDataAddButton"); |
292 | = glade_xml_get_widget(metaXML, | 292 | gtk_widget_set_sensitive (button, strlen (input) > 0); |
293 | "metaDataDialogMetaDataAddButton"); | ||
294 | gtk_widget_set_sensitive(button, | ||
295 | strlen(input) > 0); | ||
296 | } | 293 | } |
297 | 294 | ||
298 | /** | 295 | /** |
299 | * The user has edited the keyword entry. | 296 | * The user has edited the keyword entry. |
300 | * Update add button status. | 297 | * Update add button status. |
301 | */ | 298 | */ |
302 | void on_fileInformationKeywordEntry_changed_fs(gpointer dummy2, | 299 | void |
303 | GtkWidget * searchEntry) { | 300 | on_fileInformationKeywordEntry_changed_fs (gpointer dummy2, |
304 | const char * input; | 301 | GtkWidget * searchEntry) |
305 | GtkWidget * button; | 302 | { |
306 | 303 | const char *input; | |
307 | input = gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(metaXML, | 304 | GtkWidget *button; |
308 | "fileInformationKeywordEntry"))); | 305 | |
306 | input = gtk_entry_get_text (GTK_ENTRY (glade_xml_get_widget (metaXML, | ||
307 | "fileInformationKeywordEntry"))); | ||
309 | if (input == NULL) | 308 | if (input == NULL) |
310 | return; | 309 | return; |
311 | button | 310 | button = glade_xml_get_widget (metaXML, "metaDataDialogKeywordAddButton"); |
312 | = glade_xml_get_widget(metaXML, | 311 | gtk_widget_set_sensitive (button, strlen (input) > 0); |
313 | "metaDataDialogKeywordAddButton"); | ||
314 | gtk_widget_set_sensitive(button, | ||
315 | strlen(input) > 0); | ||
316 | } | 312 | } |
317 | 313 | ||
318 | typedef struct { | 314 | typedef struct |
319 | char * filename; | 315 | { |
316 | char *filename; | ||
320 | unsigned int anonymity; | 317 | unsigned int anonymity; |
321 | unsigned int priority; | 318 | unsigned int priority; |
322 | int index; | 319 | int index; |
323 | int extract; | 320 | int extract; |
324 | int deep_index; | 321 | int deep_index; |
325 | cron_t expire; | 322 | cron_t expire; |
326 | struct ECRS_MetaData * meta; | 323 | struct ECRS_MetaData *meta; |
327 | struct ECRS_URI * gkeywordURI; | 324 | struct ECRS_URI *gkeywordURI; |
328 | struct ECRS_URI * keywordURI; | 325 | struct ECRS_URI *keywordURI; |
329 | } FSUC; | 326 | } FSUC; |
330 | 327 | ||
331 | static void * start_upload_helper(void * cls) { | 328 | static void * |
332 | FSUC * fsuc = cls; | 329 | start_upload_helper (void *cls) |
333 | 330 | { | |
334 | FSUI_startUpload(ctx, | 331 | FSUC *fsuc = cls; |
335 | fsuc->filename, | 332 | |
336 | (DirectoryScanCallback) &disk_directory_scan, | 333 | FSUI_startUpload (ctx, |
337 | ectx, | 334 | fsuc->filename, |
338 | fsuc->anonymity, | 335 | (DirectoryScanCallback) & disk_directory_scan, |
339 | fsuc->priority, | 336 | ectx, |
340 | fsuc->index, | 337 | fsuc->anonymity, |
341 | fsuc->extract, | 338 | fsuc->priority, |
342 | fsuc->deep_index, | 339 | fsuc->index, |
343 | fsuc->expire, | 340 | fsuc->extract, |
344 | fsuc->meta, | 341 | fsuc->deep_index, |
345 | fsuc->gkeywordURI, | 342 | fsuc->expire, |
346 | fsuc->keywordURI); | 343 | fsuc->meta, fsuc->gkeywordURI, fsuc->keywordURI); |
347 | return NULL; | 344 | return NULL; |
348 | } | 345 | } |
349 | 346 | ||
350 | void on_fsinsertuploadbutton_clicked_fs(gpointer dummy, | 347 | void |
351 | GtkWidget * uploadButton) { | 348 | on_fsinsertuploadbutton_clicked_fs (gpointer dummy, GtkWidget * uploadButton) |
349 | { | ||
352 | FSUC fsuc; | 350 | FSUC fsuc; |
353 | const char * filename; | 351 | const char *filename; |
354 | const char * filenamerest; | 352 | const char *filenamerest; |
355 | GtkWidget * dialog; | 353 | GtkWidget *dialog; |
356 | EXTRACTOR_ExtractorList * extractors; | 354 | EXTRACTOR_ExtractorList *extractors; |
357 | char * config; | 355 | char *config; |
358 | struct ECRS_MetaData * meta; | 356 | struct ECRS_MetaData *meta; |
359 | struct ECRS_URI * keywordURI; | 357 | struct ECRS_URI *keywordURI; |
360 | 358 | ||
361 | extractors = EXTRACTOR_loadDefaultLibraries(); | 359 | extractors = EXTRACTOR_loadDefaultLibraries (); |
362 | config = NULL; | 360 | config = NULL; |
363 | GC_get_configuration_value_string(cfg, | 361 | GC_get_configuration_value_string (cfg, "FS", "EXTRACTORS", "", &config); |
364 | "FS", | 362 | if (strlen (config) > 0) |
365 | "EXTRACTORS", | 363 | extractors = EXTRACTOR_loadConfigLibraries (extractors, config); |
366 | "", | 364 | FREE (config); |
367 | &config); | 365 | filename = getEntryLineValue (getMainXML (), "uploadFilenameComboBoxEntry"); |
368 | if (strlen(config) > 0) | ||
369 | extractors = EXTRACTOR_loadConfigLibraries(extractors, | ||
370 | config); | ||
371 | FREE(config); | ||
372 | filename = getEntryLineValue(getMainXML(), | ||
373 | "uploadFilenameComboBoxEntry"); | ||
374 | metaXML | 366 | metaXML |
375 | = glade_xml_new(getGladeFileName(), | 367 | = glade_xml_new (getGladeFileName (), "metaDataDialog", PACKAGE_NAME); |
376 | "metaDataDialog", | 368 | connectGladeWithPlugins (metaXML); |
377 | PACKAGE_NAME); | 369 | dialog = glade_xml_get_widget (metaXML, "metaDataDialog"); |
378 | connectGladeWithPlugins(metaXML); | 370 | meta = ECRS_createMetaData (); |
379 | dialog = glade_xml_get_widget(metaXML, | 371 | ECRS_extractMetaData (ectx, meta, filename, extractors); |
380 | "metaDataDialog"); | 372 | EXTRACTOR_removeAll (extractors); |
381 | meta = ECRS_createMetaData(); | 373 | filenamerest = &filename[strlen (filename) - 1]; |
382 | ECRS_extractMetaData(ectx, | 374 | while ((filenamerest > filename) && (filenamerest[-1] != DIR_SEPARATOR)) |
383 | meta, | ||
384 | filename, | ||
385 | extractors); | ||
386 | EXTRACTOR_removeAll(extractors); | ||
387 | filenamerest = &filename[strlen(filename)-1]; | ||
388 | while ( (filenamerest > filename) && | ||
389 | (filenamerest[-1] != DIR_SEPARATOR) ) | ||
390 | filenamerest--; | 375 | filenamerest--; |
391 | ECRS_addToMetaData(meta, | 376 | ECRS_addToMetaData (meta, EXTRACTOR_FILENAME, filenamerest); |
392 | EXTRACTOR_FILENAME, | 377 | createMetaDataListTreeView (metaXML, |
393 | filenamerest); | 378 | "metaDataDialogMetaDataList", |
394 | createMetaDataListTreeView(metaXML, | 379 | "previewImage", meta); |
395 | "metaDataDialogMetaDataList", | 380 | keywordURI = ECRS_metaDataToUri (meta); |
396 | "previewImage", | 381 | ECRS_freeMetaData (meta); |
397 | meta); | 382 | createKeywordListTreeView (metaXML, |
398 | keywordURI = ECRS_metaDataToUri(meta); | 383 | "metaDataDialogKeywordList", keywordURI); |
399 | ECRS_freeMetaData(meta); | 384 | ECRS_freeUri (keywordURI); |
400 | createKeywordListTreeView(metaXML, | 385 | createMetaTypeComboBox (metaXML, "metaDataDialogMetaTypeComboBox"); |
401 | "metaDataDialogKeywordList", | 386 | g_signal_connect_data (gtk_tree_view_get_selection |
402 | keywordURI); | 387 | (GTK_TREE_VIEW |
403 | ECRS_freeUri(keywordURI); | 388 | (glade_xml_get_widget |
404 | createMetaTypeComboBox(metaXML, | 389 | (metaXML, "metaDataDialogKeywordList"))), |
405 | "metaDataDialogMetaTypeComboBox"); | 390 | "changed", |
406 | g_signal_connect_data(gtk_tree_view_get_selection(GTK_TREE_VIEW(glade_xml_get_widget(metaXML, | 391 | G_CALLBACK (&on_keyword_list_selection_changed), |
407 | "metaDataDialogKeywordList"))), | 392 | NULL, NULL, 0); |
408 | "changed", | 393 | g_signal_connect_data (gtk_tree_view_get_selection |
409 | G_CALLBACK(&on_keyword_list_selection_changed), | 394 | (GTK_TREE_VIEW |
410 | NULL, | 395 | (glade_xml_get_widget |
411 | NULL, | 396 | (metaXML, "metaDataDialogMetaDataList"))), |
412 | 0); | 397 | "changed", |
413 | g_signal_connect_data(gtk_tree_view_get_selection(GTK_TREE_VIEW(glade_xml_get_widget(metaXML, | 398 | G_CALLBACK (&on_metadata_list_selection_changed), |
414 | "metaDataDialogMetaDataList"))), | 399 | NULL, NULL, 0); |
415 | "changed", | 400 | gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); |
416 | G_CALLBACK(&on_metadata_list_selection_changed), | 401 | if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_CANCEL) |
417 | NULL, | 402 | { |
418 | NULL, | 403 | fsuc.anonymity = getSpinButtonValue (getMainXML (), |
419 | 0); | 404 | "uploadAnonymityLevelSpinButton"); |
420 | gtk_dialog_set_default_response(GTK_DIALOG(dialog), | 405 | fsuc.priority = getSpinButtonValue (getMainXML (), |
421 | GTK_RESPONSE_OK); | 406 | "contentPrioritySpinButton"); |
422 | if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_CANCEL) { | 407 | fsuc.index = getToggleButtonValue (getMainXML (), "indexbutton"); |
423 | fsuc.anonymity = getSpinButtonValue(getMainXML(), | 408 | fsuc.extract = getToggleButtonValue (getMainXML (), |
424 | "uploadAnonymityLevelSpinButton"); | 409 | "doExtractCheckButton"); |
425 | fsuc.priority = getSpinButtonValue(getMainXML(), | 410 | fsuc.deep_index = getToggleButtonValue (getMainXML (), |
426 | "contentPrioritySpinButton"); | 411 | "deepIndexCheckButton"); |
427 | fsuc.index = getToggleButtonValue(getMainXML(), | 412 | fsuc.expire = get_time () + 2 * cronYEARS; |
428 | "indexbutton"); | 413 | fsuc.meta = getMetaDataFromList (metaXML, |
429 | fsuc.extract = getToggleButtonValue(getMainXML(), | 414 | "metaDataDialogMetaDataList", |
430 | "doExtractCheckButton"); | 415 | "previewImage"); |
431 | fsuc.deep_index = getToggleButtonValue(getMainXML(), | 416 | fsuc.keywordURI = getKeywordURIFromList (metaXML, |
432 | "deepIndexCheckButton"); | 417 | "metaDataDialogKeywordList"); |
433 | fsuc.expire = get_time() + 2 * cronYEARS; | 418 | fsuc.gkeywordURI = ECRS_stringToUri (ectx, |
434 | fsuc.meta = getMetaDataFromList(metaXML, | 419 | ECRS_URI_PREFIX ECRS_SEARCH_INFIX); |
435 | "metaDataDialogMetaDataList", | 420 | fsuc.filename = STRDUP (filename); |
436 | "previewImage"); | 421 | run_with_save_calls (&start_upload_helper, &fsuc); |
437 | fsuc.keywordURI = getKeywordURIFromList(metaXML, | 422 | FREE (fsuc.filename); |
438 | "metaDataDialogKeywordList"); | 423 | ECRS_freeMetaData (fsuc.meta); |
439 | fsuc.gkeywordURI = ECRS_stringToUri(ectx, | 424 | ECRS_freeUri (fsuc.gkeywordURI); |
440 | ECRS_URI_PREFIX | 425 | ECRS_freeUri (fsuc.keywordURI); |
441 | ECRS_SEARCH_INFIX); | 426 | } |
442 | fsuc.filename = STRDUP(filename); | ||
443 | run_with_save_calls(&start_upload_helper, | ||
444 | &fsuc); | ||
445 | FREE(fsuc.filename); | ||
446 | ECRS_freeMetaData(fsuc.meta); | ||
447 | ECRS_freeUri(fsuc.gkeywordURI); | ||
448 | ECRS_freeUri(fsuc.keywordURI); | ||
449 | } | ||
450 | gtk_widget_destroy (dialog); | 427 | gtk_widget_destroy (dialog); |
451 | UNREF(metaXML); | 428 | UNREF (metaXML); |
452 | metaXML = NULL; | 429 | metaXML = NULL; |
453 | } | 430 | } |
454 | 431 | ||
455 | #ifndef MINGW | 432 | #ifndef MINGW |
456 | static char * | 433 | static char * |
457 | selectFile(const char * oldfilename) { | 434 | selectFile (const char *oldfilename) |
458 | GladeXML * uploadXML; | 435 | { |
459 | GtkFileChooser * dialog; | 436 | GladeXML *uploadXML; |
460 | char * ret; | 437 | GtkFileChooser *dialog; |
438 | char *ret; | ||
461 | 439 | ||
462 | uploadXML | 440 | uploadXML |
463 | = glade_xml_new(getGladeFileName(), | 441 | = glade_xml_new (getGladeFileName (), |
464 | "uploadfilechooserdialog", | 442 | "uploadfilechooserdialog", PACKAGE_NAME); |
465 | PACKAGE_NAME); | 443 | connectGladeWithPlugins (uploadXML); |
466 | connectGladeWithPlugins(uploadXML); | 444 | dialog = GTK_FILE_CHOOSER (glade_xml_get_widget (uploadXML, |
467 | dialog = GTK_FILE_CHOOSER(glade_xml_get_widget(uploadXML, | 445 | "uploadfilechooserdialog")); |
468 | "uploadfilechooserdialog")); | 446 | gtk_file_chooser_set_filename (dialog, oldfilename); |
469 | gtk_file_chooser_set_filename(dialog, | 447 | if (getToggleButtonValue (getMainXML (), "scopeRecursiveButton")) |
470 | oldfilename); | 448 | gtk_file_chooser_set_action (dialog, |
471 | if (getToggleButtonValue(getMainXML(), | 449 | GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER); |
472 | "scopeRecursiveButton")) | 450 | if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_CANCEL) |
473 | gtk_file_chooser_set_action(dialog, | 451 | ret = gtk_file_chooser_get_filename (dialog); |
474 | GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER); | ||
475 | if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_CANCEL) | ||
476 | ret = gtk_file_chooser_get_filename(dialog); | ||
477 | else | 452 | else |
478 | ret = NULL; | 453 | ret = NULL; |
479 | gtk_widget_destroy(GTK_WIDGET(dialog)); | 454 | gtk_widget_destroy (GTK_WIDGET (dialog)); |
480 | UNREF(uploadXML); | 455 | UNREF (uploadXML); |
481 | return ret; | 456 | return ret; |
482 | } | 457 | } |
483 | 458 | ||
484 | #else /* MINGW */ | 459 | #else /* MINGW */ |
485 | 460 | ||
486 | static char * | 461 | static char * |
487 | selectFile(const char * oldfilename) { | 462 | selectFile (const char *oldfilename) |
488 | if (getToggleButtonValue(getMainXML(), | 463 | { |
489 | "scopeFileOnlyButton")) | 464 | if (getToggleButtonValue (getMainXML (), "scopeFileOnlyButton")) |
490 | return plibc_ChooseFile(_("Choose the file you want to publish."), | 465 | return plibc_ChooseFile (_("Choose the file you want to publish."), |
491 | OFN_FILEMUSTEXIST | OFN_SHAREAWARE); | 466 | OFN_FILEMUSTEXIST | OFN_SHAREAWARE); |
492 | return plibc_ChooseDir(_("Choose the directory you want to publish."), | 467 | return plibc_ChooseDir (_("Choose the directory you want to publish."), |
493 | BIF_USENEWUI | BIF_SHAREABLE | BIF_NONEWFOLDERBUTTON); | 468 | BIF_USENEWUI | BIF_SHAREABLE | |
469 | BIF_NONEWFOLDERBUTTON); | ||
494 | } | 470 | } |
495 | #endif /* MINGW */ | 471 | #endif /* MINGW */ |
496 | 472 | ||
497 | void on_mainFileSharingInsertBrowseButton_clicked_fs(GtkWidget * browseButton, | 473 | void |
498 | gpointer dummy) { | 474 | on_mainFileSharingInsertBrowseButton_clicked_fs (GtkWidget * browseButton, |
499 | char * filename; | 475 | gpointer dummy) |
500 | char * ofn; | 476 | { |
477 | char *filename; | ||
478 | char *ofn; | ||
501 | const char *oldfilename; | 479 | const char *oldfilename; |
502 | GtkWidget * uploadLine; | 480 | GtkWidget *uploadLine; |
503 | GtkEntry * entry; | 481 | GtkEntry *entry; |
504 | GtkListStore * model; | 482 | GtkListStore *model; |
505 | GtkTreeIter iter; | 483 | GtkTreeIter iter; |
506 | 484 | ||
507 | uploadLine = glade_xml_get_widget(getMainXML(), | 485 | uploadLine = glade_xml_get_widget (getMainXML (), |
508 | "uploadFilenameComboBoxEntry"); | 486 | "uploadFilenameComboBoxEntry"); |
509 | entry = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(uploadLine))); | 487 | entry = GTK_ENTRY (gtk_bin_get_child (GTK_BIN (uploadLine))); |
510 | oldfilename = gtk_entry_get_text(entry); | 488 | oldfilename = gtk_entry_get_text (entry); |
511 | if (oldfilename == NULL) | 489 | if (oldfilename == NULL) |
512 | oldfilename = getenv("PWD"); | 490 | oldfilename = getenv ("PWD"); |
513 | if (oldfilename == NULL) | 491 | if (oldfilename == NULL) |
514 | oldfilename = getenv("HOME"); | 492 | oldfilename = getenv ("HOME"); |
515 | if (oldfilename == NULL) | 493 | if (oldfilename == NULL) |
516 | oldfilename = "/"; | 494 | oldfilename = "/"; |
517 | ofn = string_expandFileName(ectx, oldfilename); | 495 | ofn = string_expandFileName (ectx, oldfilename); |
518 | filename = selectFile(ofn); | 496 | filename = selectFile (ofn); |
519 | FREE(ofn); | 497 | FREE (ofn); |
520 | if (NULL == filename) | 498 | if (NULL == filename) |
521 | return; | 499 | return; |
522 | gtk_entry_set_text(entry, | 500 | gtk_entry_set_text (entry, filename); |
523 | filename); | 501 | model = |
524 | model = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(uploadLine))); | 502 | GTK_LIST_STORE (gtk_combo_box_get_model (GTK_COMBO_BOX (uploadLine))); |
525 | gtk_list_store_prepend(model, | 503 | gtk_list_store_prepend (model, &iter); |
526 | &iter); | 504 | gtk_list_store_set (model, &iter, 0, filename, -1); |
527 | gtk_list_store_set(model, | 505 | free (filename); |
528 | &iter, | ||
529 | 0, | ||
530 | filename, | ||
531 | -1); | ||
532 | free(filename); | ||
533 | } | 506 | } |
534 | 507 | ||
535 | struct FCBC { | 508 | struct FCBC |
536 | int (*method)(struct FSUI_Context * ctx, | 509 | { |
537 | struct FSUI_UploadList * list); | 510 | int (*method) (struct FSUI_Context * ctx, struct FSUI_UploadList * list); |
538 | struct FSUI_UploadList * argument; | 511 | struct FSUI_UploadList *argument; |
539 | }; | 512 | }; |
540 | 513 | ||
541 | static void * fsui_callback(void * cls) { | 514 | static void * |
542 | struct FCBC * fcbc = cls; | 515 | fsui_callback (void *cls) |
543 | fcbc->method(ctx, | 516 | { |
544 | fcbc->argument); | 517 | struct FCBC *fcbc = cls; |
518 | fcbc->method (ctx, fcbc->argument); | ||
545 | return NULL; | 519 | return NULL; |
546 | } | 520 | } |
547 | 521 | ||
548 | static void | 522 | static void |
549 | clearCompletedUploadCallback(GtkTreeModel * model, | 523 | clearCompletedUploadCallback (GtkTreeModel * model, |
550 | GtkTreePath * path, | 524 | GtkTreePath * path, |
551 | GtkTreeIter * iter, | 525 | GtkTreeIter * iter, gpointer unused) |
552 | gpointer unused) { | 526 | { |
553 | UploadList * ul; | 527 | UploadList *ul; |
554 | struct FCBC fcbc; | 528 | struct FCBC fcbc; |
555 | 529 | ||
556 | GE_ASSERT(ectx, | 530 | GE_ASSERT (ectx, model == GTK_TREE_MODEL (upload_summary)); |
557 | model == GTK_TREE_MODEL(upload_summary)); | 531 | gtk_tree_model_get (model, iter, UPLOAD_INTERNAL, &ul, -1); |
558 | gtk_tree_model_get(model, | 532 | if ((ul->has_terminated) && (ul->is_top)) |
559 | iter, | 533 | { |
560 | UPLOAD_INTERNAL, &ul, | 534 | fcbc.method = &FSUI_stopUpload; |
561 | -1); | 535 | fcbc.argument = ul->fsui_list; |
562 | if ( (ul->has_terminated) && | 536 | run_with_save_calls (&fsui_callback, &fcbc); |
563 | (ul->is_top) ) { | 537 | } |
564 | fcbc.method = &FSUI_stopUpload; | ||
565 | fcbc.argument = ul->fsui_list; | ||
566 | run_with_save_calls(&fsui_callback, | ||
567 | &fcbc); | ||
568 | } | ||
569 | } | 538 | } |
570 | 539 | ||
571 | /** | 540 | /** |
572 | * The user has edited the search entry. | 541 | * The user has edited the search entry. |
573 | * Update search button status. | 542 | * Update search button status. |
574 | */ | 543 | */ |
575 | void on_uploadFilenameComboBoxEntry_changed_fs(gpointer dummy2, | 544 | void |
576 | GtkWidget * searchEntry) { | 545 | on_uploadFilenameComboBoxEntry_changed_fs (gpointer dummy2, |
577 | const char * filename; | 546 | GtkWidget * searchEntry) |
578 | GtkWidget * uploadButton; | 547 | { |
548 | const char *filename; | ||
549 | GtkWidget *uploadButton; | ||
579 | struct stat buf; | 550 | struct stat buf; |
580 | int ok; | 551 | int ok; |
581 | GtkWidget * toggle; | 552 | GtkWidget *toggle; |
582 | 553 | ||
583 | filename = getEntryLineValue(getMainXML(), | 554 | filename = getEntryLineValue (getMainXML (), "uploadFilenameComboBoxEntry"); |
584 | "uploadFilenameComboBoxEntry"); | 555 | ok = (0 == stat (filename, &buf)); |
585 | ok = (0 == stat(filename, &buf)); | 556 | if (ok) |
557 | ok = (0 == ACCESS (filename, R_OK)); | ||
586 | if (ok) | 558 | if (ok) |
587 | ok = (0 == ACCESS(filename, R_OK)); | 559 | { |
588 | if (ok) { | 560 | if (S_ISDIR (buf.st_mode)) |
589 | if (S_ISDIR(buf.st_mode)) { | 561 | { |
590 | toggle = glade_xml_get_widget(getMainXML(), | 562 | toggle = glade_xml_get_widget (getMainXML (), |
591 | "scopeRecursiveButton"); | 563 | "scopeRecursiveButton"); |
592 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), | 564 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), 1); |
593 | 1); | 565 | } |
594 | } else { | 566 | else |
595 | toggle = glade_xml_get_widget(getMainXML(), | 567 | { |
596 | "scopeFileOnlyButton"); | 568 | toggle = glade_xml_get_widget (getMainXML (), |
597 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), | 569 | "scopeFileOnlyButton"); |
598 | 1); | 570 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), 1); |
571 | } | ||
599 | } | 572 | } |
600 | } | 573 | uploadButton = glade_xml_get_widget (getMainXML (), "fsinsertuploadbutton"); |
601 | uploadButton | 574 | gtk_widget_set_sensitive (uploadButton, ok); |
602 | = glade_xml_get_widget(getMainXML(), | ||
603 | "fsinsertuploadbutton"); | ||
604 | gtk_widget_set_sensitive(uploadButton, | ||
605 | ok); | ||
606 | } | 575 | } |
607 | 576 | ||
608 | void on_clearCompletedUploadsButton_clicked_fs(void * unused, | 577 | void |
609 | GtkWidget * clearButton) { | 578 | on_clearCompletedUploadsButton_clicked_fs (void *unused, |
610 | ggc_tree_model_foreach(GTK_TREE_MODEL(upload_summary), | 579 | GtkWidget * clearButton) |
611 | &clearCompletedUploadCallback, | 580 | { |
612 | NULL); | 581 | ggc_tree_model_foreach (GTK_TREE_MODEL (upload_summary), |
582 | &clearCompletedUploadCallback, NULL); | ||
613 | } | 583 | } |
614 | 584 | ||
615 | static void | 585 | static void |
616 | fsuiCallUploadCallback(GtkTreeModel * model, | 586 | fsuiCallUploadCallback (GtkTreeModel * model, |
617 | GtkTreePath * path, | 587 | GtkTreePath * path, |
618 | GtkTreeIter * iter, | 588 | GtkTreeIter * iter, gpointer fsui_call) |
619 | gpointer fsui_call) { | 589 | { |
620 | UploadList * ul; | 590 | UploadList *ul; |
621 | struct FCBC fcbc; | 591 | struct FCBC fcbc; |
622 | 592 | ||
623 | GE_ASSERT(ectx, | 593 | GE_ASSERT (ectx, model == GTK_TREE_MODEL (upload_summary)); |
624 | model == GTK_TREE_MODEL(upload_summary)); | 594 | gtk_tree_model_get (model, iter, UPLOAD_INTERNAL, &ul, -1); |
625 | gtk_tree_model_get(model, | ||
626 | iter, | ||
627 | UPLOAD_INTERNAL, &ul, | ||
628 | -1); | ||
629 | fcbc.method = fsui_call; | 595 | fcbc.method = fsui_call; |
630 | fcbc.argument = ul->fsui_list; | 596 | fcbc.argument = ul->fsui_list; |
631 | run_with_save_calls(&fsui_callback, | 597 | run_with_save_calls (&fsui_callback, &fcbc); |
632 | &fcbc); | ||
633 | } | 598 | } |
634 | 599 | ||
635 | void on_abortUploadButton_clicked_fs(void * unused, | 600 | void |
636 | GtkWidget * clearButton) { | 601 | on_abortUploadButton_clicked_fs (void *unused, GtkWidget * clearButton) |
637 | GtkTreeSelection * selection; | 602 | { |
638 | GtkWidget * uploadList; | 603 | GtkTreeSelection *selection; |
604 | GtkWidget *uploadList; | ||
639 | 605 | ||
640 | uploadList = glade_xml_get_widget(getMainXML(), | 606 | uploadList = glade_xml_get_widget (getMainXML (), "activeUploadsList"); |
641 | "activeUploadsList"); | 607 | selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (uploadList)); |
642 | selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(uploadList)); | ||
643 | ggc_tree_selection_selected_foreach | 608 | ggc_tree_selection_selected_foreach |
644 | (selection, | 609 | (selection, &fsuiCallUploadCallback, &FSUI_abortUpload); |
645 | &fsuiCallUploadCallback, | ||
646 | &FSUI_abortUpload); | ||
647 | } | 610 | } |
648 | 611 | ||
649 | void on_stopUploadButton_clicked_fs(void * unused, | 612 | void |
650 | GtkWidget * clearButton) { | 613 | on_stopUploadButton_clicked_fs (void *unused, GtkWidget * clearButton) |
651 | GtkTreeSelection * selection; | 614 | { |
652 | GtkWidget * uploadList; | 615 | GtkTreeSelection *selection; |
616 | GtkWidget *uploadList; | ||
653 | 617 | ||
654 | uploadList = glade_xml_get_widget(getMainXML(), | 618 | uploadList = glade_xml_get_widget (getMainXML (), "activeUploadsList"); |
655 | "activeUploadsList"); | 619 | selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (uploadList)); |
656 | selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(uploadList)); | ||
657 | ggc_tree_selection_selected_foreach | 620 | ggc_tree_selection_selected_foreach |
658 | (selection, | 621 | (selection, &fsuiCallUploadCallback, &FSUI_abortUpload); |
659 | &fsuiCallUploadCallback, | ||
660 | &FSUI_abortUpload); | ||
661 | ggc_tree_selection_selected_foreach | 622 | ggc_tree_selection_selected_foreach |
662 | (selection, | 623 | (selection, &fsuiCallUploadCallback, &FSUI_stopUpload); |
663 | &fsuiCallUploadCallback, | ||
664 | &FSUI_stopUpload); | ||
665 | } | 624 | } |
666 | 625 | ||
667 | 626 | ||
diff --git a/src/plugins/fs/upload.h b/src/plugins/fs/upload.h index 69e2e49d..b88f05d1 100644 --- a/src/plugins/fs/upload.h +++ b/src/plugins/fs/upload.h | |||
@@ -29,26 +29,23 @@ | |||
29 | 29 | ||
30 | #include "fs.h" | 30 | #include "fs.h" |
31 | 31 | ||
32 | void fs_upload_update(UploadList * list, | 32 | void fs_upload_update (UploadList * list, unsigned long long completed); |
33 | unsigned long long completed); | ||
34 | 33 | ||
35 | void fs_upload_complete(UploadList * list, | 34 | void fs_upload_complete (UploadList * list, struct ECRS_URI *uri); |
36 | struct ECRS_URI * uri); | ||
37 | 35 | ||
38 | void fs_upload_error(UploadList * list); | 36 | void fs_upload_error (UploadList * list); |
39 | 37 | ||
40 | void fs_upload_stopped(UploadList * list); | 38 | void fs_upload_stopped (UploadList * list); |
41 | 39 | ||
42 | /** | 40 | /** |
43 | * @param uri NULL if upload is not yet finished | 41 | * @param uri NULL if upload is not yet finished |
44 | */ | 42 | */ |
45 | UploadList * | 43 | UploadList *fs_upload_started (struct FSUI_UploadList *fsui, |
46 | fs_upload_started(struct FSUI_UploadList * fsui, | 44 | UploadList * parent, |
47 | UploadList * parent, | 45 | const char *filename, |
48 | const char * filename, | 46 | struct ECRS_URI *uri, |
49 | struct ECRS_URI * uri, | 47 | unsigned long long total, |
50 | unsigned long long total, | 48 | unsigned long long completed, |
51 | unsigned long long completed, | 49 | FSUI_State state); |
52 | FSUI_State state); | ||
53 | 50 | ||
54 | #endif | 51 | #endif |
diff --git a/src/plugins/peers/peers.c b/src/plugins/peers/peers.c index ae8dee56..9e5cbac0 100644 --- a/src/plugins/peers/peers.c +++ b/src/plugins/peers/peers.c | |||
@@ -36,121 +36,118 @@ | |||
36 | 36 | ||
37 | #define REFRESH_RATE (15 * cronSECONDS) | 37 | #define REFRESH_RATE (15 * cronSECONDS) |
38 | 38 | ||
39 | static struct CronManager * cron; | 39 | static struct CronManager *cron; |
40 | 40 | ||
41 | static struct GE_Context * ectx; | 41 | static struct GE_Context *ectx; |
42 | 42 | ||
43 | static struct GC_Configuration * cfg; | 43 | static struct GC_Configuration *cfg; |
44 | 44 | ||
45 | static GdkPixbuf * green; | 45 | static GdkPixbuf *green; |
46 | 46 | ||
47 | static GdkPixbuf * yellow; | 47 | static GdkPixbuf *yellow; |
48 | 48 | ||
49 | static GdkPixbuf * red; | 49 | static GdkPixbuf *red; |
50 | 50 | ||
51 | static GdkPixbuf * black; | 51 | static GdkPixbuf *black; |
52 | 52 | ||
53 | static int collector(void * data, | 53 | static int |
54 | const PeerIdentity * identity, | 54 | collector (void *data, |
55 | const void * address, | 55 | const PeerIdentity * identity, |
56 | unsigned int addr_len, | 56 | const void *address, |
57 | cron_t last_message, | 57 | unsigned int addr_len, |
58 | unsigned int trust, | 58 | cron_t last_message, unsigned int trust, unsigned int bpmFromPeer) |
59 | unsigned int bpmFromPeer) { | 59 | { |
60 | GtkListStore * model = data; | 60 | GtkListStore *model = data; |
61 | GtkTreeIter iter; | 61 | GtkTreeIter iter; |
62 | EncName enc; | 62 | EncName enc; |
63 | GdkPixbuf * ledBuf; | 63 | GdkPixbuf *ledBuf; |
64 | GdkPixbuf * flagBuf; | 64 | GdkPixbuf *flagBuf; |
65 | char * cc; | 65 | char *cc; |
66 | char * dir; | 66 | char *dir; |
67 | char * fn; | 67 | char *fn; |
68 | char * prefix; | 68 | char *prefix; |
69 | char * have; | 69 | char *have; |
70 | char * haddress; | 70 | char *haddress; |
71 | char * hostname; | 71 | char *hostname; |
72 | cron_t now; | 72 | cron_t now; |
73 | int i; | 73 | int i; |
74 | int found; | 74 | int found; |
75 | 75 | ||
76 | hash2enc(&identity->hashPubKey, | 76 | hash2enc (&identity->hashPubKey, &enc); |
77 | &enc); | ||
78 | /* check if same peer is already in model! */ | 77 | /* check if same peer is already in model! */ |
79 | found = NO; | 78 | found = NO; |
80 | if (TRUE == gtk_tree_model_get_iter_first(GTK_TREE_MODEL(model), | 79 | if (TRUE == gtk_tree_model_get_iter_first (GTK_TREE_MODEL (model), &iter)) |
81 | &iter)) { | 80 | { |
82 | do { | 81 | do |
83 | gtk_tree_model_get(GTK_TREE_MODEL(model), | 82 | { |
84 | &iter, | 83 | gtk_tree_model_get (GTK_TREE_MODEL (model), |
85 | 0, &haddress, | 84 | &iter, 0, &haddress, 3, &have, -1); |
86 | 3, &have, | 85 | if (have != NULL) |
87 | -1); | 86 | { |
88 | if (have != NULL) { | 87 | if (0 == strcmp (have, (char *) &enc)) |
89 | if (0 == strcmp(have, (char*) &enc)) { | 88 | { |
90 | if (strlen(haddress) > 0) { | 89 | if (strlen (haddress) > 0) |
91 | FREE(have); | 90 | { |
92 | FREE(haddress); | 91 | FREE (have); |
93 | return OK; | 92 | FREE (haddress); |
94 | } | 93 | return OK; |
95 | found = YES; | 94 | } |
96 | } | 95 | found = YES; |
97 | FREENONNULL(haddress); | 96 | } |
98 | FREE(have); | 97 | FREENONNULL (haddress); |
99 | } | 98 | FREE (have); |
100 | } while ( (found == NO) && | 99 | } |
101 | (TRUE == gtk_tree_model_iter_next(GTK_TREE_MODEL(model), | 100 | } |
102 | &iter)) ); | 101 | while ((found == NO) && |
103 | } | 102 | (TRUE == gtk_tree_model_iter_next (GTK_TREE_MODEL (model), |
104 | 103 | &iter))); | |
105 | hostname = network_get_ip_as_string(address, | 104 | } |
106 | addr_len, | 105 | |
107 | YES); | 106 | hostname = network_get_ip_as_string (address, addr_len, YES); |
108 | if (hostname == NULL) | 107 | if (hostname == NULL) |
109 | hostname = STRDUP("NAT"); | 108 | hostname = STRDUP ("NAT"); |
110 | /* get flag */ | 109 | /* get flag */ |
111 | flagBuf = NULL; | 110 | flagBuf = NULL; |
112 | ledBuf = NULL; | 111 | ledBuf = NULL; |
113 | cc = NULL; | 112 | cc = NULL; |
114 | prefix = STRDUP(hostname); | 113 | prefix = STRDUP (hostname); |
115 | if (strstr(prefix, " ") != NULL) | 114 | if (strstr (prefix, " ") != NULL) |
116 | *strstr(prefix, " ") = '\0'; | 115 | *strstr (prefix, " ") = '\0'; |
117 | cc = prefix; | 116 | cc = prefix; |
118 | while (strstr(cc, ".") != NULL) | 117 | while (strstr (cc, ".") != NULL) |
119 | cc = strstr(cc, ".") + 1; | 118 | cc = strstr (cc, ".") + 1; |
120 | if (strstr(hostname, ".") == NULL) | 119 | if (strstr (hostname, ".") == NULL) |
121 | cc = NULL; | 120 | cc = NULL; |
122 | else if ( (0 == strcasecmp(cc, "edu")) || | 121 | else if ((0 == strcasecmp (cc, "edu")) || |
123 | (0 == strcasecmp(cc, "com")) || | 122 | (0 == strcasecmp (cc, "com")) || |
124 | (0 == strcasecmp(cc, "net")) || | 123 | (0 == strcasecmp (cc, "net")) || |
125 | (0 == strcasecmp(cc, "org")) || | 124 | (0 == strcasecmp (cc, "org")) || |
126 | (0 == strcasecmp(cc, "gov")) || | 125 | (0 == strcasecmp (cc, "gov")) || (0 == strcasecmp (cc, "mil"))) |
127 | (0 == strcasecmp(cc, "mil")) ) | ||
128 | cc = "us"; | 126 | cc = "us"; |
129 | if ( (cc != NULL) && | 127 | if ((cc != NULL) && (strlen (cc) > 2)) |
130 | (strlen(cc) > 2) ) | ||
131 | cc = NULL; | 128 | cc = NULL; |
132 | if (cc != NULL) { | 129 | if (cc != NULL) |
133 | cc = STRDUP(cc); | 130 | { |
134 | for (i=0;i<strlen(cc);i++) | 131 | cc = STRDUP (cc); |
135 | cc[i] = tolower(cc[i]); | 132 | for (i = 0; i < strlen (cc); i++) |
136 | dir = os_get_installation_path(IPK_DATADIR); | 133 | cc[i] = tolower (cc[i]); |
137 | fn = MALLOC(strlen(dir) + 32); | 134 | dir = os_get_installation_path (IPK_DATADIR); |
138 | strcpy(fn, dir); | 135 | fn = MALLOC (strlen (dir) + 32); |
139 | strcat(fn, | 136 | strcpy (fn, dir); |
140 | DIR_SEPARATOR_STR ".." | 137 | strcat (fn, |
141 | DIR_SEPARATOR_STR "gnunet-gtk" | 138 | DIR_SEPARATOR_STR ".." |
142 | DIR_SEPARATOR_STR "flags" | 139 | DIR_SEPARATOR_STR "gnunet-gtk" |
143 | DIR_SEPARATOR_STR); | 140 | DIR_SEPARATOR_STR "flags" DIR_SEPARATOR_STR); |
144 | strcat(fn, cc); | 141 | strcat (fn, cc); |
145 | strcat(fn, ".png"); | 142 | strcat (fn, ".png"); |
146 | FREE(dir); | 143 | FREE (dir); |
147 | flagBuf = gdk_pixbuf_new_from_file(fn, NULL); | 144 | flagBuf = gdk_pixbuf_new_from_file (fn, NULL); |
148 | FREE(fn); | 145 | FREE (fn); |
149 | } | 146 | } |
150 | FREE(prefix); | 147 | FREE (prefix); |
151 | 148 | ||
152 | /* get LED */ | 149 | /* get LED */ |
153 | now = get_time(); | 150 | now = get_time (); |
154 | if (last_message + 150 * cronSECONDS > now) | 151 | if (last_message + 150 * cronSECONDS > now) |
155 | ledBuf = green; | 152 | ledBuf = green; |
156 | else if (last_message + 5 * cronMINUTES > now) | 153 | else if (last_message + 5 * cronMINUTES > now) |
@@ -160,25 +157,20 @@ static int collector(void * data, | |||
160 | else | 157 | else |
161 | ledBuf = black; | 158 | ledBuf = black; |
162 | if (ledBuf != NULL) | 159 | if (ledBuf != NULL) |
163 | g_object_ref(ledBuf); | 160 | g_object_ref (ledBuf); |
164 | 161 | ||
165 | /* add to model */ | 162 | /* add to model */ |
166 | if (found == NO) | 163 | if (found == NO) |
167 | gtk_list_store_append(model, | 164 | gtk_list_store_append (model, &iter); |
168 | &iter); | 165 | gtk_list_store_set (model, |
169 | gtk_list_store_set(model, | 166 | &iter, |
170 | &iter, | 167 | 0, hostname, |
171 | 0, hostname, | 168 | 1, trust, |
172 | 1, trust, | 169 | 2, bpmFromPeer, |
173 | 2, bpmFromPeer, | 170 | 3, (const char *) &enc, |
174 | 3, (const char*) &enc, | 171 | 4, ledBuf, 5, flagBuf, 6, cc, 7, last_message, -1); |
175 | 4, ledBuf, | 172 | FREENONNULL (cc); |
176 | 5, flagBuf, | 173 | FREE (hostname); |
177 | 6, cc, | ||
178 | 7, last_message, | ||
179 | -1); | ||
180 | FREENONNULL(cc); | ||
181 | FREE(hostname); | ||
182 | return OK; | 174 | return OK; |
183 | } | 175 | } |
184 | 176 | ||
@@ -187,26 +179,26 @@ static int collector(void * data, | |||
187 | /** | 179 | /** |
188 | * Compute an updated peer model. | 180 | * Compute an updated peer model. |
189 | */ | 181 | */ |
190 | static void * getPeerModel() { | 182 | static void * |
191 | struct ClientServerConnection * sock; | 183 | getPeerModel () |
192 | GtkListStore * model; | 184 | { |
193 | 185 | struct ClientServerConnection *sock; | |
194 | model = gtk_list_store_new(8, | 186 | GtkListStore *model; |
195 | G_TYPE_STRING, /* address */ | 187 | |
196 | G_TYPE_UINT, /* trust */ | 188 | model = gtk_list_store_new (8, G_TYPE_STRING, /* address */ |
197 | G_TYPE_UINT, /* bpm */ | 189 | G_TYPE_UINT, /* trust */ |
198 | G_TYPE_STRING, /* identity */ | 190 | G_TYPE_UINT, /* bpm */ |
199 | GDK_TYPE_PIXBUF, /* LED */ | 191 | G_TYPE_STRING, /* identity */ |
200 | GDK_TYPE_PIXBUF, /* flag */ | 192 | GDK_TYPE_PIXBUF, /* LED */ |
201 | G_TYPE_STRING, /* country name */ | 193 | GDK_TYPE_PIXBUF, /* flag */ |
202 | G_TYPE_UINT64); /* last time seen */ | 194 | G_TYPE_STRING, /* country name */ |
203 | sock = client_connection_create(ectx, cfg); | 195 | G_TYPE_UINT64); /* last time seen */ |
204 | if (sock != NULL) { | 196 | sock = client_connection_create (ectx, cfg); |
205 | gnunet_identity_request_peer_infos(sock, | 197 | if (sock != NULL) |
206 | &collector, | 198 | { |
207 | model); | 199 | gnunet_identity_request_peer_infos (sock, &collector, model); |
208 | connection_destroy(sock); | 200 | connection_destroy (sock); |
209 | } | 201 | } |
210 | return model; | 202 | return model; |
211 | } | 203 | } |
212 | 204 | ||
@@ -214,197 +206,175 @@ static void * getPeerModel() { | |||
214 | /** | 206 | /** |
215 | * Update the model for the peers list. | 207 | * Update the model for the peers list. |
216 | */ | 208 | */ |
217 | static void * updatePeerInfoSafe(void * m) { | 209 | static void * |
218 | GtkListStore * model = m; | 210 | updatePeerInfoSafe (void *m) |
219 | GtkTreeModel * old_model; | 211 | { |
220 | GtkWidget * w; | 212 | GtkListStore *model = m; |
213 | GtkTreeModel *old_model; | ||
214 | GtkWidget *w; | ||
221 | GtkSortType order; | 215 | GtkSortType order; |
222 | gint sort_column; | 216 | gint sort_column; |
223 | 217 | ||
224 | w = glade_xml_get_widget(getMainXML(), | 218 | w = glade_xml_get_widget (getMainXML (), "peersTreeView"); |
225 | "peersTreeView"); | 219 | old_model = gtk_tree_view_get_model (GTK_TREE_VIEW (w)); |
226 | old_model = gtk_tree_view_get_model(GTK_TREE_VIEW(w)); | 220 | if (old_model != NULL) |
227 | if (old_model != NULL) { | 221 | { |
228 | if (TRUE == gtk_tree_sortable_get_sort_column_id(GTK_TREE_SORTABLE(old_model), | 222 | if (TRUE == |
229 | &sort_column, | 223 | gtk_tree_sortable_get_sort_column_id (GTK_TREE_SORTABLE (old_model), |
230 | &order)) | 224 | &sort_column, &order)) |
231 | gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(model), | 225 | gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (model), |
232 | sort_column, | 226 | sort_column, order); |
233 | order); | 227 | } |
234 | } | 228 | gtk_tree_view_set_model (GTK_TREE_VIEW (w), GTK_TREE_MODEL (model)); |
235 | gtk_tree_view_set_model(GTK_TREE_VIEW(w), | 229 | gtk_tree_selection_set_mode (gtk_tree_view_get_selection |
236 | GTK_TREE_MODEL(model)); | 230 | (GTK_TREE_VIEW (w)), GTK_SELECTION_NONE); |
237 | gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(w)), | ||
238 | GTK_SELECTION_NONE); | ||
239 | return NULL; | 231 | return NULL; |
240 | } | 232 | } |
241 | 233 | ||
242 | static void updatePeerInfo(void * dummy) { | 234 | static void |
243 | GtkListStore * model; | 235 | updatePeerInfo (void *dummy) |
236 | { | ||
237 | GtkListStore *model; | ||
244 | 238 | ||
245 | model = getPeerModel(); | 239 | model = getPeerModel (); |
246 | gtkSaveCall(&updatePeerInfoSafe, model); | 240 | gtkSaveCall (&updatePeerInfoSafe, model); |
247 | } | 241 | } |
248 | 242 | ||
249 | 243 | ||
250 | void init_peers(struct GE_Context * e, | 244 | void |
251 | struct GC_Configuration * c) { | 245 | init_peers (struct GE_Context *e, struct GC_Configuration *c) |
252 | GtkWidget * tab; | 246 | { |
253 | GtkWidget * peers; | 247 | GtkWidget *tab; |
254 | GtkCellRenderer * renderer; | 248 | GtkWidget *peers; |
249 | GtkCellRenderer *renderer; | ||
255 | int col; | 250 | int col; |
256 | GtkTreeViewColumn * column; | 251 | GtkTreeViewColumn *column; |
257 | char * dir; | 252 | char *dir; |
258 | char * fn; | 253 | char *fn; |
259 | 254 | ||
260 | ectx = e; | 255 | ectx = e; |
261 | cfg = c; | 256 | cfg = c; |
262 | peers | 257 | peers = glade_xml_get_widget (getMainXML (), "peersTreeView"); |
263 | = glade_xml_get_widget(getMainXML(), | 258 | renderer = gtk_cell_renderer_text_new (); |
264 | "peersTreeView"); | 259 | col = gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (peers), |
265 | renderer = gtk_cell_renderer_text_new(); | 260 | -1, |
266 | col = gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(peers), | 261 | _("Address"), |
267 | -1, | 262 | renderer, |
268 | _("Address"), | 263 | "text", 0, NULL); |
269 | renderer, | 264 | column = gtk_tree_view_get_column (GTK_TREE_VIEW (peers), col - 1); |
270 | "text", 0, | 265 | gtk_tree_view_column_set_resizable (column, TRUE); |
271 | NULL); | 266 | gtk_tree_view_column_set_clickable (column, TRUE); |
272 | column = gtk_tree_view_get_column(GTK_TREE_VIEW(peers), | 267 | gtk_tree_view_column_set_reorderable (column, TRUE); |
273 | col - 1); | 268 | gtk_tree_view_column_set_sort_column_id (column, 0); |
274 | gtk_tree_view_column_set_resizable(column, TRUE); | 269 | |
275 | gtk_tree_view_column_set_clickable(column, TRUE); | 270 | renderer = gtk_cell_renderer_text_new (); |
276 | gtk_tree_view_column_set_reorderable(column, TRUE); | 271 | col = gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (peers), |
277 | gtk_tree_view_column_set_sort_column_id(column, 0); | 272 | -1, |
278 | 273 | _("Trust"), | |
279 | renderer = gtk_cell_renderer_text_new(); | 274 | renderer, |
280 | col = gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(peers), | 275 | "text", 1, NULL); |
281 | -1, | 276 | column = gtk_tree_view_get_column (GTK_TREE_VIEW (peers), col - 1); |
282 | _("Trust"), | 277 | gtk_tree_view_column_set_resizable (column, TRUE); |
283 | renderer, | 278 | gtk_tree_view_column_set_clickable (column, TRUE); |
284 | "text", 1, | 279 | gtk_tree_view_column_set_reorderable (column, TRUE); |
285 | NULL); | 280 | gtk_tree_view_column_set_sort_column_id (column, 1); |
286 | column = gtk_tree_view_get_column(GTK_TREE_VIEW(peers), | 281 | |
287 | col - 1); | 282 | renderer = gtk_cell_renderer_text_new (); |
288 | gtk_tree_view_column_set_resizable(column, TRUE); | 283 | col = gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (peers), |
289 | gtk_tree_view_column_set_clickable(column, TRUE); | 284 | -1, |
290 | gtk_tree_view_column_set_reorderable(column, TRUE); | 285 | _("Bandwidth"), |
291 | gtk_tree_view_column_set_sort_column_id(column, 1); | 286 | renderer, |
292 | 287 | "text", 2, NULL); | |
293 | renderer = gtk_cell_renderer_text_new(); | 288 | column = gtk_tree_view_get_column (GTK_TREE_VIEW (peers), col - 1); |
294 | col = gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(peers), | 289 | gtk_tree_view_column_set_resizable (column, TRUE); |
295 | -1, | 290 | gtk_tree_view_column_set_clickable (column, TRUE); |
296 | _("Bandwidth"), | 291 | gtk_tree_view_column_set_reorderable (column, TRUE); |
297 | renderer, | 292 | gtk_tree_view_column_set_sort_column_id (column, 2); |
298 | "text", 2, | 293 | |
299 | NULL); | 294 | |
300 | column = gtk_tree_view_get_column(GTK_TREE_VIEW(peers), | 295 | renderer = gtk_cell_renderer_pixbuf_new (); |
301 | col - 1); | 296 | col = gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (peers), |
302 | gtk_tree_view_column_set_resizable(column, TRUE); | 297 | -1, |
303 | gtk_tree_view_column_set_clickable(column, TRUE); | 298 | _("Country"), |
304 | gtk_tree_view_column_set_reorderable(column, TRUE); | 299 | renderer, |
305 | gtk_tree_view_column_set_sort_column_id(column, 2); | 300 | "pixbuf", 5, NULL); |
306 | 301 | column = gtk_tree_view_get_column (GTK_TREE_VIEW (peers), col - 1); | |
307 | 302 | gtk_tree_view_column_set_resizable (column, FALSE); | |
308 | renderer = gtk_cell_renderer_pixbuf_new(); | 303 | gtk_tree_view_column_set_clickable (column, TRUE); |
309 | col = gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(peers), | 304 | gtk_tree_view_column_set_reorderable (column, TRUE); |
310 | -1, | 305 | gtk_tree_view_column_set_sort_column_id (column, 6); |
311 | _("Country"), | 306 | |
312 | renderer, | 307 | renderer = gtk_cell_renderer_pixbuf_new (); |
313 | "pixbuf", 5, | 308 | col = gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (peers), |
314 | NULL); | 309 | -1, |
315 | column = gtk_tree_view_get_column(GTK_TREE_VIEW(peers), | 310 | _("Status"), |
316 | col - 1); | 311 | renderer, |
317 | gtk_tree_view_column_set_resizable(column, FALSE); | 312 | "pixbuf", 4, NULL); |
318 | gtk_tree_view_column_set_clickable(column, TRUE); | 313 | column = gtk_tree_view_get_column (GTK_TREE_VIEW (peers), col - 1); |
319 | gtk_tree_view_column_set_reorderable(column, TRUE); | 314 | gtk_tree_view_column_set_clickable (column, TRUE); |
320 | gtk_tree_view_column_set_sort_column_id(column, 6); | 315 | gtk_tree_view_column_set_reorderable (column, TRUE); |
321 | 316 | gtk_tree_view_column_set_sort_column_id (column, 7); | |
322 | renderer = gtk_cell_renderer_pixbuf_new(); | 317 | gtk_tree_view_column_set_resizable (column, FALSE); |
323 | col = gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(peers), | 318 | |
324 | -1, | 319 | renderer = gtk_cell_renderer_text_new (); |
325 | _("Status"), | 320 | col = gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (peers), |
326 | renderer, | 321 | -1, |
327 | "pixbuf", 4, | 322 | _("Identity"), |
328 | NULL); | 323 | renderer, |
329 | column = gtk_tree_view_get_column(GTK_TREE_VIEW(peers), | 324 | "text", 3, NULL); |
330 | col - 1); | 325 | column = gtk_tree_view_get_column (GTK_TREE_VIEW (peers), col - 1); |
331 | gtk_tree_view_column_set_clickable(column, TRUE); | 326 | gtk_tree_view_column_set_resizable (column, TRUE); |
332 | gtk_tree_view_column_set_reorderable(column, TRUE); | 327 | gtk_tree_view_column_set_clickable (column, TRUE); |
333 | gtk_tree_view_column_set_sort_column_id(column, 7); | 328 | gtk_tree_view_column_set_reorderable (column, TRUE); |
334 | gtk_tree_view_column_set_resizable(column, FALSE); | 329 | gtk_tree_view_column_set_sort_column_id (column, 3); |
335 | 330 | ||
336 | renderer = gtk_cell_renderer_text_new(); | 331 | |
337 | col = gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(peers), | 332 | dir = os_get_installation_path (IPK_DATADIR); |
338 | -1, | 333 | fn = MALLOC (strlen (dir) + 32); |
339 | _("Identity"), | 334 | strcpy (fn, dir); |
340 | renderer, | 335 | strcat (fn, |
341 | "text", 3, | 336 | DIR_SEPARATOR_STR ".." |
342 | NULL); | 337 | DIR_SEPARATOR_STR "gnunet-gtk" DIR_SEPARATOR_STR "red.png"); |
343 | column = gtk_tree_view_get_column(GTK_TREE_VIEW(peers), | 338 | red = gdk_pixbuf_new_from_file (fn, NULL); |
344 | col - 1); | 339 | |
345 | gtk_tree_view_column_set_resizable(column, TRUE); | 340 | strcpy (fn, dir); |
346 | gtk_tree_view_column_set_clickable(column, TRUE); | 341 | strcat (fn, |
347 | gtk_tree_view_column_set_reorderable(column, TRUE); | 342 | DIR_SEPARATOR_STR ".." |
348 | gtk_tree_view_column_set_sort_column_id(column, 3); | 343 | DIR_SEPARATOR_STR "gnunet-gtk" DIR_SEPARATOR_STR "yellow.png"); |
349 | 344 | yellow = gdk_pixbuf_new_from_file (fn, NULL); | |
350 | 345 | ||
351 | dir = os_get_installation_path(IPK_DATADIR); | 346 | strcpy (fn, dir); |
352 | fn = MALLOC(strlen(dir) + 32); | 347 | strcat (fn, |
353 | strcpy(fn, dir); | 348 | DIR_SEPARATOR_STR ".." |
354 | strcat(fn, | 349 | DIR_SEPARATOR_STR "gnunet-gtk" DIR_SEPARATOR_STR "green.png"); |
355 | DIR_SEPARATOR_STR ".." | 350 | green = gdk_pixbuf_new_from_file (fn, NULL); |
356 | DIR_SEPARATOR_STR "gnunet-gtk" | 351 | |
357 | DIR_SEPARATOR_STR "red.png"); | 352 | strcpy (fn, dir); |
358 | red = gdk_pixbuf_new_from_file(fn, NULL); | 353 | strcat (fn, |
359 | 354 | DIR_SEPARATOR_STR ".." | |
360 | strcpy(fn, dir); | 355 | DIR_SEPARATOR_STR "gnunet-gtk" DIR_SEPARATOR_STR "black.png"); |
361 | strcat(fn, | 356 | black = gdk_pixbuf_new_from_file (fn, NULL); |
362 | DIR_SEPARATOR_STR ".." | 357 | FREE (fn); |
363 | DIR_SEPARATOR_STR "gnunet-gtk" | 358 | FREE (dir); |
364 | DIR_SEPARATOR_STR "yellow.png"); | 359 | |
365 | yellow = gdk_pixbuf_new_from_file(fn, NULL); | 360 | tab = glade_xml_get_widget (getMainXML (), "peersScrolledWindow"); |
366 | 361 | gtk_widget_show (tab); | |
367 | strcpy(fn, dir); | 362 | cron = gnunet_gtk_get_cron (); |
368 | strcat(fn, | 363 | cron_add_job (cron, &updatePeerInfo, REFRESH_RATE, REFRESH_RATE, NULL); |
369 | DIR_SEPARATOR_STR ".." | ||
370 | DIR_SEPARATOR_STR "gnunet-gtk" | ||
371 | DIR_SEPARATOR_STR "green.png"); | ||
372 | green = gdk_pixbuf_new_from_file(fn, NULL); | ||
373 | |||
374 | strcpy(fn, dir); | ||
375 | strcat(fn, | ||
376 | DIR_SEPARATOR_STR ".." | ||
377 | DIR_SEPARATOR_STR "gnunet-gtk" | ||
378 | DIR_SEPARATOR_STR "black.png"); | ||
379 | black = gdk_pixbuf_new_from_file(fn, NULL); | ||
380 | FREE(fn); | ||
381 | FREE(dir); | ||
382 | |||
383 | tab | ||
384 | = glade_xml_get_widget(getMainXML(), | ||
385 | "peersScrolledWindow"); | ||
386 | gtk_widget_show(tab); | ||
387 | cron = gnunet_gtk_get_cron(); | ||
388 | cron_add_job(cron, | ||
389 | &updatePeerInfo, | ||
390 | REFRESH_RATE, | ||
391 | REFRESH_RATE, | ||
392 | NULL); | ||
393 | } | 364 | } |
394 | 365 | ||
395 | void done_peers() { | 366 | void |
396 | cron_del_job(cron, | 367 | done_peers () |
397 | &updatePeerInfo, | 368 | { |
398 | REFRESH_RATE, | 369 | cron_del_job (cron, &updatePeerInfo, REFRESH_RATE, NULL); |
399 | NULL); | ||
400 | if (red != NULL) | 370 | if (red != NULL) |
401 | g_object_unref(red); | 371 | g_object_unref (red); |
402 | if (green != NULL) | 372 | if (green != NULL) |
403 | g_object_unref(green); | 373 | g_object_unref (green); |
404 | if (black != NULL) | 374 | if (black != NULL) |
405 | g_object_unref(black); | 375 | g_object_unref (black); |
406 | if (yellow != NULL) | 376 | if (yellow != NULL) |
407 | g_object_unref(yellow); | 377 | g_object_unref (yellow); |
408 | } | 378 | } |
409 | 379 | ||
410 | 380 | ||
diff --git a/src/plugins/stats/functions.c b/src/plugins/stats/functions.c index 5b6e2542..9c5e90db 100644 --- a/src/plugins/stats/functions.c +++ b/src/plugins/stats/functions.c | |||
@@ -29,13 +29,13 @@ | |||
29 | 29 | ||
30 | #define FUNCTIONS_DEBUG NO | 30 | #define FUNCTIONS_DEBUG NO |
31 | 31 | ||
32 | static StatPair * lastStatValues; | 32 | static StatPair *lastStatValues; |
33 | 33 | ||
34 | static unsigned int lsv_size; | 34 | static unsigned int lsv_size; |
35 | 35 | ||
36 | static struct ClientServerConnection * sock; | 36 | static struct ClientServerConnection *sock; |
37 | 37 | ||
38 | static struct MUTEX * lock; | 38 | static struct MUTEX *lock; |
39 | 39 | ||
40 | static long connectionGoal; | 40 | static long connectionGoal; |
41 | 41 | ||
@@ -43,126 +43,106 @@ static long long banddown; | |||
43 | 43 | ||
44 | static long long bandup; | 44 | static long long bandup; |
45 | 45 | ||
46 | static struct GE_Context * ectx; | 46 | static struct GE_Context *ectx; |
47 | 47 | ||
48 | static struct GC_Configuration * cfg; | 48 | static struct GC_Configuration *cfg; |
49 | 49 | ||
50 | static struct CronManager * cron; | 50 | static struct CronManager *cron; |
51 | 51 | ||
52 | static int getStatValue(long long * value, | 52 | static int |
53 | long long * lvalue, | 53 | getStatValue (long long *value, |
54 | cron_t * dtime, | 54 | long long *lvalue, |
55 | const char * optName, | 55 | cron_t * dtime, const char *optName, int monotone) |
56 | int monotone) { | 56 | { |
57 | unsigned int i; | 57 | unsigned int i; |
58 | 58 | ||
59 | *value = 0; | 59 | *value = 0; |
60 | if (lvalue != NULL) | 60 | if (lvalue != NULL) |
61 | *lvalue = 0; | 61 | *lvalue = 0; |
62 | for (i=0;i<lsv_size;i++) { | 62 | for (i = 0; i < lsv_size; i++) |
63 | if (0 == strcmp(optName, | 63 | { |
64 | lastStatValues[i].statName)) { | 64 | if (0 == strcmp (optName, lastStatValues[i].statName)) |
65 | *value = lastStatValues[i].value; | 65 | { |
66 | if (lvalue != NULL) | 66 | *value = lastStatValues[i].value; |
67 | *lvalue = lastStatValues[i].lvalue; | 67 | if (lvalue != NULL) |
68 | if (dtime != NULL) | 68 | *lvalue = lastStatValues[i].lvalue; |
69 | *dtime = lastStatValues[i].delta; | 69 | if (dtime != NULL) |
70 | if ( (monotone == YES) && | 70 | *dtime = lastStatValues[i].delta; |
71 | (lvalue != NULL) && | 71 | if ((monotone == YES) && (lvalue != NULL) && (*lvalue > *value)) |
72 | (*lvalue > *value) ) | 72 | return SYSERR; /* gnunetd restart? */ |
73 | return SYSERR; /* gnunetd restart? */ | 73 | return OK; |
74 | return OK; | 74 | } |
75 | } | 75 | } |
76 | } | ||
77 | #if FUNCTIONS_DEBUG | 76 | #if FUNCTIONS_DEBUG |
78 | GE_LOG(ectx, | 77 | GE_LOG (ectx, |
79 | GE_DEBUG | GE_DEVELOPER | GE_REQUEST, | 78 | GE_DEBUG | GE_DEVELOPER | GE_REQUEST, |
80 | "Statistic not found: `%s'\n", | 79 | "Statistic not found: `%s'\n", optName); |
81 | optName); | ||
82 | #endif | 80 | #endif |
83 | return SYSERR; | 81 | return SYSERR; |
84 | } | 82 | } |
85 | 83 | ||
86 | static void updateConnectionGoal(void * unused) { | 84 | static void |
87 | char * cmh; | 85 | updateConnectionGoal (void *unused) |
88 | char * availableDown; | 86 | { |
89 | char * availableUp; | 87 | char *cmh; |
90 | 88 | char *availableDown; | |
91 | MUTEX_LOCK(lock); | 89 | char *availableUp; |
92 | cmh = getConfigurationOptionValue(sock, | 90 | |
93 | "gnunetd", | 91 | MUTEX_LOCK (lock); |
94 | "connection-max-hosts"); | 92 | cmh = getConfigurationOptionValue (sock, "gnunetd", "connection-max-hosts"); |
95 | availableDown = getConfigurationOptionValue(sock, | 93 | availableDown = getConfigurationOptionValue (sock, |
96 | "LOAD", | 94 | "LOAD", "MAXNETDOWNBPSTOTAL"); |
97 | "MAXNETDOWNBPSTOTAL"); | 95 | availableUp = getConfigurationOptionValue (sock, |
98 | availableUp = getConfigurationOptionValue(sock, | 96 | "LOAD", "MAXNETUPBPSTOTAL"); |
99 | "LOAD", | 97 | MUTEX_UNLOCK (lock); |
100 | "MAXNETUPBPSTOTAL"); | ||
101 | MUTEX_UNLOCK(lock); | ||
102 | if (cmh == NULL) | 98 | if (cmh == NULL) |
103 | connectionGoal = 0; | 99 | connectionGoal = 0; |
104 | else | 100 | else |
105 | connectionGoal = atol(cmh); | 101 | connectionGoal = atol (cmh); |
106 | if (availableDown == NULL) | 102 | if (availableDown == NULL) |
107 | banddown = 0; | 103 | banddown = 0; |
108 | else | 104 | else |
109 | banddown = atol(availableDown); | 105 | banddown = atol (availableDown); |
110 | if (availableUp == NULL) | 106 | if (availableUp == NULL) |
111 | bandup = 0; | 107 | bandup = 0; |
112 | else | 108 | else |
113 | bandup = atol(availableUp); | 109 | bandup = atol (availableUp); |
114 | 110 | ||
115 | FREENONNULL(cmh); | 111 | FREENONNULL (cmh); |
116 | FREENONNULL(availableDown); | 112 | FREENONNULL (availableDown); |
117 | FREENONNULL(availableUp); | 113 | FREENONNULL (availableUp); |
118 | } | 114 | } |
119 | 115 | ||
120 | static int getConnectedNodesStat(const void * closure, | 116 | static int |
121 | gfloat ** data) { | 117 | getConnectedNodesStat (const void *closure, gfloat ** data) |
118 | { | ||
122 | long long val; | 119 | long long val; |
123 | 120 | ||
124 | if (connectionGoal == 0) | 121 | if (connectionGoal == 0) |
125 | return SYSERR; | 122 | return SYSERR; |
126 | if (OK != getStatValue(&val, | 123 | if (OK != getStatValue (&val, NULL, NULL, "# of connected peers", NO)) |
127 | NULL, | ||
128 | NULL, | ||
129 | "# of connected peers", | ||
130 | NO)) | ||
131 | return SYSERR; | 124 | return SYSERR; |
132 | data[0][0] = ((gfloat) val) / connectionGoal; | 125 | data[0][0] = ((gfloat) val) / connectionGoal; |
133 | return OK; | 126 | return OK; |
134 | } | 127 | } |
135 | 128 | ||
136 | static int getLoadStat(const void * closure, | 129 | static int |
137 | gfloat ** data) { | 130 | getLoadStat (const void *closure, gfloat ** data) |
131 | { | ||
138 | long long valc; | 132 | long long valc; |
139 | long long vali; | 133 | long long vali; |
140 | long long valu; | 134 | long long valu; |
141 | long long vald; | 135 | long long vald; |
142 | 136 | ||
143 | if (OK != getStatValue(&valc, | 137 | if (OK != getStatValue (&valc, NULL, NULL, "% of allowed cpu load", NO)) |
144 | NULL, | ||
145 | NULL, | ||
146 | "% of allowed cpu load", | ||
147 | NO)) | ||
148 | return SYSERR; | 138 | return SYSERR; |
149 | if (OK != getStatValue(&vali, | 139 | if (OK != getStatValue (&vali, NULL, NULL, "% of allowed io load", NO)) |
150 | NULL, | ||
151 | NULL, | ||
152 | "% of allowed io load", | ||
153 | NO)) | ||
154 | return SYSERR; | 140 | return SYSERR; |
155 | if (OK != getStatValue(&valu, | 141 | if (OK != getStatValue (&valu, |
156 | NULL, | 142 | NULL, NULL, "% of allowed network load (up)", NO)) |
157 | NULL, | ||
158 | "% of allowed network load (up)", | ||
159 | NO)) | ||
160 | return SYSERR; | 143 | return SYSERR; |
161 | if (OK != getStatValue(&vald, | 144 | if (OK != getStatValue (&vald, |
162 | NULL, | 145 | NULL, NULL, "% of allowed network load (down)", NO)) |
163 | NULL, | ||
164 | "% of allowed network load (down)", | ||
165 | NO)) | ||
166 | return SYSERR; | 146 | return SYSERR; |
167 | data[0][0] = (gfloat) valc / 100.0; | 147 | data[0][0] = (gfloat) valc / 100.0; |
168 | data[0][1] = (gfloat) vali / 100.0; | 148 | data[0][1] = (gfloat) vali / 100.0; |
@@ -171,31 +151,26 @@ static int getLoadStat(const void * closure, | |||
171 | return OK; | 151 | return OK; |
172 | } | 152 | } |
173 | 153 | ||
174 | static int getQuotaStat(const void * closure, | 154 | static int |
175 | gfloat ** data) { | 155 | getQuotaStat (const void *closure, gfloat ** data) |
156 | { | ||
176 | long long allowed; | 157 | long long allowed; |
177 | long long have; | 158 | long long have; |
178 | 159 | ||
179 | if (OK != getStatValue(&allowed, | 160 | if (OK != getStatValue (&allowed, |
180 | NULL, | 161 | NULL, NULL, "# bytes allowed in datastore", NO)) |
181 | NULL, | ||
182 | "# bytes allowed in datastore", | ||
183 | NO)) | ||
184 | return SYSERR; | 162 | return SYSERR; |
185 | if (allowed == 0) | 163 | if (allowed == 0) |
186 | return SYSERR; | 164 | return SYSERR; |
187 | if (OK != getStatValue(&have, | 165 | if (OK != getStatValue (&have, NULL, NULL, "# bytes in datastore", NO)) |
188 | NULL, | ||
189 | NULL, | ||
190 | "# bytes in datastore", | ||
191 | NO)) | ||
192 | return SYSERR; | 166 | return SYSERR; |
193 | data[0][0] = ((gfloat) have) / allowed; | 167 | data[0][0] = ((gfloat) have) / allowed; |
194 | return OK; | 168 | return OK; |
195 | } | 169 | } |
196 | 170 | ||
197 | static int getTrafficRecvStats(const void * closure, | 171 | static int |
198 | gfloat ** data) { | 172 | getTrafficRecvStats (const void *closure, gfloat ** data) |
173 | { | ||
199 | long long total; | 174 | long long total; |
200 | long long noise; | 175 | long long noise; |
201 | long long content; | 176 | long long content; |
@@ -209,66 +184,40 @@ static int getTrafficRecvStats(const void * closure, | |||
209 | long long lhellos; | 184 | long long lhellos; |
210 | long long lrlimit; | 185 | long long lrlimit; |
211 | cron_t dtime; | 186 | cron_t dtime; |
212 | char * buffer; | 187 | char *buffer; |
213 | 188 | ||
214 | if (OK != getStatValue(&total, | 189 | if (OK != getStatValue (&total, <otal, &dtime, "# bytes received", YES)) |
215 | <otal, | ||
216 | &dtime, | ||
217 | "# bytes received", | ||
218 | YES)) | ||
219 | return SYSERR; | 190 | return SYSERR; |
220 | if (OK != getStatValue(&noise, | 191 | if (OK != getStatValue (&noise, |
221 | &lnoise, | 192 | &lnoise, NULL, "# bytes of noise received", YES)) |
222 | NULL, | ||
223 | "# bytes of noise received", | ||
224 | YES)) | ||
225 | return SYSERR; | 193 | return SYSERR; |
226 | buffer = MALLOC(512); | 194 | buffer = MALLOC (512); |
227 | SNPRINTF(buffer, | 195 | SNPRINTF (buffer, 512, "# bytes received of type %d", P2P_PROTO_gap_RESULT); |
228 | 512, | 196 | if (OK != getStatValue (&content, &lcontent, NULL, buffer, YES)) |
229 | "# bytes received of type %d", | 197 | { |
230 | P2P_PROTO_gap_RESULT); | 198 | content = 0; |
231 | if (OK != getStatValue(&content, | 199 | lcontent = 0; |
232 | &lcontent, | 200 | } |
233 | NULL, | 201 | SNPRINTF (buffer, 512, "# bytes received of type %d", p2p_PROTO_hello); |
234 | buffer, | 202 | if (OK != getStatValue (&hellos, &lhellos, NULL, buffer, YES)) |
235 | YES)) { | 203 | { |
236 | content = 0; | 204 | hellos = 0; |
237 | lcontent = 0; | 205 | lhellos = 0; |
238 | } | 206 | } |
239 | SNPRINTF(buffer, | 207 | SNPRINTF (buffer, 512, "# bytes received of type %d", P2P_PROTO_gap_QUERY); |
240 | 512, | 208 | if (OK != getStatValue (&queries, &lqueries, NULL, buffer, YES)) |
241 | "# bytes received of type %d", | 209 | { |
242 | p2p_PROTO_hello); | 210 | queries = 0; |
243 | if (OK != getStatValue(&hellos, | 211 | lqueries = 0; |
244 | &lhellos, | 212 | } |
245 | NULL, | 213 | if (OK != getStatValue (&rlimit, |
246 | buffer, | 214 | &lrlimit, |
247 | YES)) { | 215 | NULL, "# total bytes per second receive limit", NO)) |
248 | hellos = 0; | 216 | { |
249 | lhellos = 0; | 217 | rlimit = 0; |
250 | } | 218 | lrlimit = 0; |
251 | SNPRINTF(buffer, | 219 | } |
252 | 512, | 220 | FREE (buffer); |
253 | "# bytes received of type %d", | ||
254 | P2P_PROTO_gap_QUERY); | ||
255 | if (OK != getStatValue(&queries, | ||
256 | &lqueries, | ||
257 | NULL, | ||
258 | buffer, | ||
259 | YES)) { | ||
260 | queries = 0; | ||
261 | lqueries = 0; | ||
262 | } | ||
263 | if (OK != getStatValue(&rlimit, | ||
264 | &lrlimit, | ||
265 | NULL, | ||
266 | "# total bytes per second receive limit", | ||
267 | NO)) { | ||
268 | rlimit = 0; | ||
269 | lrlimit = 0; | ||
270 | } | ||
271 | FREE(buffer); | ||
272 | if (banddown == 0) | 221 | if (banddown == 0) |
273 | return SYSERR; | 222 | return SYSERR; |
274 | 223 | ||
@@ -277,32 +226,31 @@ static int getTrafficRecvStats(const void * closure, | |||
277 | queries -= lqueries; | 226 | queries -= lqueries; |
278 | content -= lcontent; | 227 | content -= lcontent; |
279 | hellos -= lhellos; | 228 | hellos -= lhellos; |
280 | if (banddown < 0) { | 229 | if (banddown < 0) |
281 | data[0][0] = 0.0; | 230 | { |
282 | data[0][1] = 0.0; | 231 | data[0][0] = 0.0; |
283 | data[0][2] = 0.0; | 232 | data[0][1] = 0.0; |
284 | data[0][3] = 0.0; | 233 | data[0][2] = 0.0; |
285 | data[0][4] = 0.0; | 234 | data[0][3] = 0.0; |
286 | data[0][5] = 0.0; | 235 | data[0][4] = 0.0; |
287 | return OK; | 236 | data[0][5] = 0.0; |
288 | } | 237 | return OK; |
289 | data[0][0] = ((gfloat) noise) / (banddown * dtime / cronSECONDS); /* red */ | 238 | } |
290 | data[0][1] = ((gfloat) (content+noise)) / (banddown * dtime / cronSECONDS); /* green */ | 239 | data[0][0] = ((gfloat) noise) / (banddown * dtime / cronSECONDS); /* red */ |
291 | data[0][2] = ((gfloat)(queries+content+noise)) / (banddown * dtime / cronSECONDS); /* yellow */ | 240 | data[0][1] = ((gfloat) (content + noise)) / (banddown * dtime / cronSECONDS); /* green */ |
292 | data[0][3] = ((gfloat)(queries+content+noise+hellos)) / (banddown * dtime / cronSECONDS); /* blue */ | 241 | data[0][2] = ((gfloat) (queries + content + noise)) / (banddown * dtime / cronSECONDS); /* yellow */ |
293 | data[0][4] = ((gfloat) total) / (banddown * dtime / cronSECONDS); /* gray */ | 242 | data[0][3] = ((gfloat) (queries + content + noise + hellos)) / (banddown * dtime / cronSECONDS); /* blue */ |
294 | data[0][5] = (gfloat) rlimit / banddown; /* magenta */ | 243 | data[0][4] = ((gfloat) total) / (banddown * dtime / cronSECONDS); /* gray */ |
244 | data[0][5] = (gfloat) rlimit / banddown; /* magenta */ | ||
295 | #if 0 | 245 | #if 0 |
296 | printf("I: %f %f %f %f\n", | 246 | printf ("I: %f %f %f %f\n", data[0][0], data[0][1], data[0][2]); |
297 | data[0][0], | ||
298 | data[0][1], | ||
299 | data[0][2]); | ||
300 | #endif | 247 | #endif |
301 | return OK; | 248 | return OK; |
302 | } | 249 | } |
303 | 250 | ||
304 | static int getTrafficSendStats(const void * closure, | 251 | static int |
305 | gfloat ** data) { | 252 | getTrafficSendStats (const void *closure, gfloat ** data) |
253 | { | ||
306 | long long total; | 254 | long long total; |
307 | long long noise; | 255 | long long noise; |
308 | long long content; | 256 | long long content; |
@@ -316,66 +264,42 @@ static int getTrafficSendStats(const void * closure, | |||
316 | long long lhellos; | 264 | long long lhellos; |
317 | long long lslimit; | 265 | long long lslimit; |
318 | cron_t dtime; | 266 | cron_t dtime; |
319 | char * buffer; | 267 | char *buffer; |
320 | 268 | ||
321 | if (OK != getStatValue(&total, | 269 | if (OK != getStatValue (&total, |
322 | <otal, | 270 | <otal, &dtime, "# bytes transmitted", YES)) |
323 | &dtime, | ||
324 | "# bytes transmitted", | ||
325 | YES)) | ||
326 | return SYSERR; | 271 | return SYSERR; |
327 | if (OK != getStatValue(&noise, | 272 | if (OK != getStatValue (&noise, &lnoise, NULL, "# bytes noise sent", YES)) |
328 | &lnoise, | ||
329 | NULL, | ||
330 | "# bytes noise sent", | ||
331 | YES)) | ||
332 | return SYSERR; | 273 | return SYSERR; |
333 | buffer = MALLOC(512); | 274 | buffer = MALLOC (512); |
334 | SNPRINTF(buffer, | 275 | SNPRINTF (buffer, |
335 | 512, | 276 | 512, "# bytes transmitted of type %d", P2P_PROTO_gap_RESULT); |
336 | "# bytes transmitted of type %d", | 277 | if (OK != getStatValue (&content, &lcontent, NULL, buffer, YES)) |
337 | P2P_PROTO_gap_RESULT); | 278 | { |
338 | if (OK != getStatValue(&content, | 279 | content = 0; |
339 | &lcontent, | 280 | lcontent = 0; |
340 | NULL, | 281 | } |
341 | buffer, | 282 | SNPRINTF (buffer, |
342 | YES)) { | 283 | 512, "# bytes transmitted of type %d", P2P_PROTO_gap_QUERY); |
343 | content = 0; | 284 | if (OK != getStatValue (&queries, &lqueries, NULL, buffer, YES)) |
344 | lcontent = 0; | 285 | { |
345 | } | 286 | queries = 0; |
346 | SNPRINTF(buffer, | 287 | lqueries = 0; |
347 | 512, | 288 | } |
348 | "# bytes transmitted of type %d", | 289 | SNPRINTF (buffer, 512, "# bytes transmitted of type %d", p2p_PROTO_hello); |
349 | P2P_PROTO_gap_QUERY); | 290 | if (OK != getStatValue (&hellos, &lhellos, NULL, buffer, YES)) |
350 | if (OK != getStatValue(&queries, | 291 | { |
351 | &lqueries, | 292 | queries = 0; |
352 | NULL, | 293 | lqueries = 0; |
353 | buffer, | 294 | } |
354 | YES)) { | 295 | if (OK != getStatValue (&slimit, |
355 | queries = 0; | 296 | &lslimit, |
356 | lqueries = 0; | 297 | NULL, "# total bytes per second send limit", NO)) |
357 | } | 298 | { |
358 | SNPRINTF(buffer, | 299 | slimit = 0; |
359 | 512, | 300 | lslimit = 0; |
360 | "# bytes transmitted of type %d", | 301 | } |
361 | p2p_PROTO_hello); | 302 | FREE (buffer); |
362 | if (OK != getStatValue(&hellos, | ||
363 | &lhellos, | ||
364 | NULL, | ||
365 | buffer, | ||
366 | YES)) { | ||
367 | queries = 0; | ||
368 | lqueries = 0; | ||
369 | } | ||
370 | if (OK != getStatValue(&slimit, | ||
371 | &lslimit, | ||
372 | NULL, | ||
373 | "# total bytes per second send limit", | ||
374 | NO)) { | ||
375 | slimit = 0; | ||
376 | lslimit = 0; | ||
377 | } | ||
378 | FREE(buffer); | ||
379 | if (bandup == 0) | 303 | if (bandup == 0) |
380 | return SYSERR; | 304 | return SYSERR; |
381 | total -= ltotal; | 305 | total -= ltotal; |
@@ -383,34 +307,32 @@ static int getTrafficSendStats(const void * closure, | |||
383 | queries -= lqueries; | 307 | queries -= lqueries; |
384 | content -= lcontent; | 308 | content -= lcontent; |
385 | hellos -= lhellos; | 309 | hellos -= lhellos; |
386 | if (bandup < 0) { | 310 | if (bandup < 0) |
387 | data[0][0] = 0.0; | 311 | { |
388 | data[0][1] = 0.0; | 312 | data[0][0] = 0.0; |
389 | data[0][2] = 0.0; | 313 | data[0][1] = 0.0; |
390 | data[0][3] = 0.0; | 314 | data[0][2] = 0.0; |
391 | data[0][4] = 0.0; | 315 | data[0][3] = 0.0; |
392 | data[0][5] = 0.0; | 316 | data[0][4] = 0.0; |
393 | return OK; | 317 | data[0][5] = 0.0; |
394 | } | 318 | return OK; |
395 | data[0][0] = ((gfloat) noise) / (bandup * dtime / cronSECONDS); /* red */ | 319 | } |
396 | data[0][1] = ((gfloat) (noise + content)) / (bandup*dtime / cronSECONDS); /* green */ | 320 | data[0][0] = ((gfloat) noise) / (bandup * dtime / cronSECONDS); /* red */ |
397 | data[0][2] = ((gfloat) (noise + content + queries)) / (bandup*dtime / cronSECONDS); /* yellow */ | 321 | data[0][1] = ((gfloat) (noise + content)) / (bandup * dtime / cronSECONDS); /* green */ |
398 | data[0][3] = ((gfloat) (noise + content + queries + hellos)) / (bandup*dtime / cronSECONDS); /* blue */ | 322 | data[0][2] = ((gfloat) (noise + content + queries)) / (bandup * dtime / cronSECONDS); /* yellow */ |
399 | data[0][4] = ((gfloat) total) / (bandup*dtime / cronSECONDS); /* grey */ | 323 | data[0][3] = ((gfloat) (noise + content + queries + hellos)) / (bandup * dtime / cronSECONDS); /* blue */ |
400 | data[0][5] = ((gfloat) slimit) / bandup ; /* magenta */ | 324 | data[0][4] = ((gfloat) total) / (bandup * dtime / cronSECONDS); /* grey */ |
325 | data[0][5] = ((gfloat) slimit) / bandup; /* magenta */ | ||
401 | #if 0 | 326 | #if 0 |
402 | printf("O: %f %f %f %f\n", | 327 | printf ("O: %f %f %f %f\n", data[0][0], data[0][1], data[0][2], data[0][3]); |
403 | data[0][0], | ||
404 | data[0][1], | ||
405 | data[0][2], | ||
406 | data[0][3]); | ||
407 | #endif | 328 | #endif |
408 | return OK; | 329 | return OK; |
409 | } | 330 | } |
410 | 331 | ||
411 | 332 | ||
412 | static int getEffectivenessStats(const void * closure, | 333 | static int |
413 | gfloat ** data) { | 334 | getEffectivenessStats (const void *closure, gfloat ** data) |
335 | { | ||
414 | static cron_t last; | 336 | static cron_t last; |
415 | static double lastdata; | 337 | static double lastdata; |
416 | static double lastavg; | 338 | static double lastavg; |
@@ -422,39 +344,41 @@ static int getEffectivenessStats(const void * closure, | |||
422 | long long llocal; | 344 | long long llocal; |
423 | cron_t now; | 345 | cron_t now; |
424 | 346 | ||
425 | now = get_time(); | 347 | now = get_time (); |
426 | if (now < last + 2 * cronMINUTES) { | 348 | if (now < last + 2 * cronMINUTES) |
427 | data[0][0] = lastdata; | 349 | { |
428 | data[0][1] = lastavg; | 350 | data[0][0] = lastdata; |
429 | return OK; | 351 | data[0][1] = lastavg; |
430 | } | 352 | return OK; |
353 | } | ||
431 | last = now; | 354 | last = now; |
432 | if (OK != getStatValue(&total, | 355 | if (OK != getStatValue (&total, |
433 | <otal, | 356 | <otal, |
434 | NULL, | 357 | NULL, |
435 | "# gap requests forwarded (counting each peer)", | 358 | "# gap requests forwarded (counting each peer)", |
436 | YES)) | 359 | YES)) |
437 | return SYSERR; | 360 | return SYSERR; |
438 | if (OK != getStatValue(&success, | 361 | if (OK != getStatValue (&success, |
439 | &lsuccess, | 362 | &lsuccess, |
440 | NULL, | 363 | NULL, "# gap routing successes (total)", YES)) |
441 | "# gap routing successes (total)", | ||
442 | YES)) | ||
443 | return SYSERR; | 364 | return SYSERR; |
444 | if (OK != getStatValue(&local, | 365 | if (OK != getStatValue (&local, |
445 | &llocal, | 366 | &llocal, |
446 | NULL, | 367 | NULL, |
447 | "# gap requests processed: local result", | 368 | "# gap requests processed: local result", YES)) |
448 | YES)) | ||
449 | return SYSERR; | 369 | return SYSERR; |
450 | total -= ltotal; | 370 | total -= ltotal; |
451 | data[0][0] = 0.0; | 371 | data[0][0] = 0.0; |
452 | if (ltotal + total > 0) { | 372 | if (ltotal + total > 0) |
453 | data[0][1] = lastavg = 1.0 * (success + lsuccess - local - llocal) / (total + ltotal); | 373 | { |
454 | } else { | 374 | data[0][1] = lastavg = |
455 | data[0][1] = 0.0; | 375 | 1.0 * (success + lsuccess - local - llocal) / (total + ltotal); |
456 | return OK; | 376 | } |
457 | } | 377 | else |
378 | { | ||
379 | data[0][1] = 0.0; | ||
380 | return OK; | ||
381 | } | ||
458 | if (total == 0) | 382 | if (total == 0) |
459 | return OK; | 383 | return OK; |
460 | success -= lsuccess; | 384 | success -= lsuccess; |
@@ -467,9 +391,9 @@ static int getEffectivenessStats(const void * closure, | |||
467 | return OK; | 391 | return OK; |
468 | } | 392 | } |
469 | 393 | ||
470 | static int statsProcessor(const char * optName, | 394 | static int |
471 | unsigned long long value, | 395 | statsProcessor (const char *optName, unsigned long long value, void *data) |
472 | void * data) { | 396 | { |
473 | /** | 397 | /** |
474 | * Keep track of last match (or, more precisely, position | 398 | * Keep track of last match (or, more precisely, position |
475 | * of next expected match) since 99.99% of the time we | 399 | * of next expected match) since 99.99% of the time we |
@@ -477,7 +401,7 @@ static int statsProcessor(const char * optName, | |||
477 | * this will predict correctly). | 401 | * this will predict correctly). |
478 | */ | 402 | */ |
479 | static unsigned int last; | 403 | static unsigned int last; |
480 | cron_t * delta = data; | 404 | cron_t *delta = data; |
481 | int j; | 405 | int j; |
482 | int found; | 406 | int found; |
483 | 407 | ||
@@ -485,33 +409,28 @@ static int statsProcessor(const char * optName, | |||
485 | last = 0; | 409 | last = 0; |
486 | j = last; | 410 | j = last; |
487 | found = -1; | 411 | found = -1; |
488 | if ( (j < lsv_size) && | 412 | if ((j < lsv_size) && (0 == strcmp (optName, lastStatValues[j].statName))) |
489 | (0 == strcmp(optName, | ||
490 | lastStatValues[j].statName)) ) | ||
491 | found = j; | 413 | found = j; |
492 | if (found == -1) { | 414 | if (found == -1) |
493 | for (j=0;j<lsv_size;j++) { | 415 | { |
494 | if (0 == strcmp(optName, | 416 | for (j = 0; j < lsv_size; j++) |
495 | lastStatValues[j].statName)) { | 417 | { |
496 | found = j; | 418 | if (0 == strcmp (optName, lastStatValues[j].statName)) |
497 | break; | 419 | { |
498 | } | 420 | found = j; |
421 | break; | ||
422 | } | ||
423 | } | ||
424 | } | ||
425 | if (found == -1) | ||
426 | { | ||
427 | found = lsv_size; | ||
428 | GROW (lastStatValues, lsv_size, lsv_size + 1); | ||
429 | lastStatValues[found].statName = STRDUP (optName); | ||
499 | } | 430 | } |
500 | } | 431 | lastStatValues[found].lvalue = lastStatValues[found].value; |
501 | if (found == -1) { | 432 | lastStatValues[found].value = value; |
502 | found = lsv_size; | 433 | lastStatValues[found].delta = *delta; |
503 | GROW(lastStatValues, | ||
504 | lsv_size, | ||
505 | lsv_size+1); | ||
506 | lastStatValues[found].statName | ||
507 | = STRDUP(optName); | ||
508 | } | ||
509 | lastStatValues[found].lvalue | ||
510 | = lastStatValues[found].value; | ||
511 | lastStatValues[found].value | ||
512 | = value; | ||
513 | lastStatValues[found].delta | ||
514 | = *delta; | ||
515 | last = found + 1; | 434 | last = found + 1; |
516 | return OK; | 435 | return OK; |
517 | } | 436 | } |
@@ -519,129 +438,127 @@ static int statsProcessor(const char * optName, | |||
519 | /** | 438 | /** |
520 | * Cron-job that updates all stat values. | 439 | * Cron-job that updates all stat values. |
521 | */ | 440 | */ |
522 | static void updateStatValues(void * unused) { | 441 | static void |
442 | updateStatValues (void *unused) | ||
443 | { | ||
523 | static cron_t lastUpdate; | 444 | static cron_t lastUpdate; |
524 | cron_t now; | 445 | cron_t now; |
525 | cron_t delta; | 446 | cron_t delta; |
526 | 447 | ||
527 | now = get_time(); | 448 | now = get_time (); |
528 | delta = now - lastUpdate; | 449 | delta = now - lastUpdate; |
529 | MUTEX_LOCK(lock); | 450 | MUTEX_LOCK (lock); |
530 | if (OK == STATS_getStatistics(ectx, | 451 | if (OK == STATS_getStatistics (ectx, sock, &statsProcessor, &delta)) |
531 | sock, | ||
532 | &statsProcessor, | ||
533 | &delta)) | ||
534 | lastUpdate = now; | 452 | lastUpdate = now; |
535 | MUTEX_UNLOCK(lock); | 453 | MUTEX_UNLOCK (lock); |
536 | } | 454 | } |
537 | 455 | ||
538 | 456 | ||
539 | StatEntry stats[] = { | 457 | StatEntry stats[] = { |
540 | { | 458 | { |
541 | gettext_noop("Connectivity"), | 459 | gettext_noop ("Connectivity"), |
542 | gettext_noop("# connected nodes (100% = connection table size)"), | 460 | gettext_noop ("# connected nodes (100% = connection table size)"), |
543 | &getConnectedNodesStat, | 461 | &getConnectedNodesStat, |
544 | NULL, | 462 | NULL, |
545 | 1, | 463 | 1, |
546 | NO, | 464 | NO, |
547 | }, | 465 | } |
466 | , | ||
548 | { | 467 | { |
549 | gettext_noop("System load"), | 468 | gettext_noop ("System load"), |
550 | gettext_noop("CPU load (red), IO load (green), Network upload (yellow), Network download (blue)"), | 469 | gettext_noop |
551 | &getLoadStat, | 470 | ("CPU load (red), IO load (green), Network upload (yellow), Network download (blue)"), |
552 | NULL, | 471 | &getLoadStat, |
553 | 4, | 472 | NULL, |
554 | NO, | 473 | 4, |
555 | }, | 474 | NO, |
475 | } | ||
476 | , | ||
556 | { | 477 | { |
557 | gettext_noop("Datastore capacity"), | 478 | gettext_noop ("Datastore capacity"), |
558 | gettext_noop("Data in datastore (in percent of allowed quota)"), | 479 | gettext_noop ("Data in datastore (in percent of allowed quota)"), |
559 | &getQuotaStat, | 480 | &getQuotaStat, |
560 | NULL, | 481 | NULL, |
561 | 1, | 482 | 1, |
562 | NO, | 483 | NO, |
563 | }, | 484 | } |
485 | , | ||
564 | { | 486 | { |
565 | gettext_noop("Inbound Traffic"), | 487 | gettext_noop ("Inbound Traffic"), |
566 | gettext_noop("Noise (red), Content (green), Queries (yellow), Hellos (blue), other (gray), limit (magenta)"), | 488 | gettext_noop |
567 | &getTrafficRecvStats, | 489 | ("Noise (red), Content (green), Queries (yellow), Hellos (blue), other (gray), limit (magenta)"), |
568 | NULL, | 490 | &getTrafficRecvStats, |
569 | 6, | 491 | NULL, |
570 | 5, | 492 | 6, |
571 | }, | 493 | 5, |
494 | } | ||
495 | , | ||
572 | { | 496 | { |
573 | gettext_noop("Outbound Traffic"), | 497 | gettext_noop ("Outbound Traffic"), |
574 | gettext_noop("Noise (red), Content (green), Queries (yellow), Hellos (blue), other (gray), limit (magenta)"), | 498 | gettext_noop |
575 | &getTrafficSendStats, | 499 | ("Noise (red), Content (green), Queries (yellow), Hellos (blue), other (gray), limit (magenta)"), |
576 | NULL, | 500 | &getTrafficSendStats, |
577 | 6, | 501 | NULL, |
578 | 5, | 502 | 6, |
579 | }, | 503 | 5, |
504 | } | ||
505 | , | ||
580 | { | 506 | { |
581 | gettext_noop("Routing Effectiveness"), | 507 | gettext_noop ("Routing Effectiveness"), |
582 | gettext_noop("Current (red) and average (green) effectiveness (100% = perfect)"), | 508 | gettext_noop |
583 | &getEffectivenessStats, | 509 | ("Current (red) and average (green) effectiveness (100% = perfect)"), |
584 | NULL, | 510 | &getEffectivenessStats, |
585 | 2, | 511 | NULL, |
586 | NO, | 512 | 2, |
587 | }, | 513 | NO, |
514 | } | ||
515 | , | ||
588 | { | 516 | { |
589 | NULL, | 517 | NULL, |
590 | NULL, | 518 | NULL, |
591 | NULL, | 519 | NULL, |
592 | NULL, | 520 | NULL, |
593 | 0, | 521 | 0, |
594 | NO, | 522 | NO, |
595 | }, | 523 | } |
524 | , | ||
596 | }; | 525 | }; |
597 | 526 | ||
598 | static unsigned long long UPDATE_INTERVAL; | 527 | static unsigned long long UPDATE_INTERVAL; |
599 | 528 | ||
600 | void init_functions(struct GE_Context * e, | 529 | void |
601 | struct GC_Configuration * c) { | 530 | init_functions (struct GE_Context *e, struct GC_Configuration *c) |
531 | { | ||
602 | ectx = e; | 532 | ectx = e; |
603 | cfg = c; | 533 | cfg = c; |
604 | GC_get_configuration_value_number(cfg, | 534 | GC_get_configuration_value_number (cfg, |
605 | "GNUNET-GTK", | 535 | "GNUNET-GTK", |
606 | "STATS-INTERVAL", | 536 | "STATS-INTERVAL", |
607 | 1, | 537 | 1, |
608 | 99 * cronYEARS, | 538 | 99 * cronYEARS, |
609 | 30 * cronSECONDS, | 539 | 30 * cronSECONDS, &UPDATE_INTERVAL); |
610 | &UPDATE_INTERVAL); | 540 | sock = client_connection_create (ectx, cfg); |
611 | sock = client_connection_create(ectx, | 541 | lock = MUTEX_CREATE (NO); |
612 | cfg); | 542 | cron = gnunet_gtk_get_cron (); |
613 | lock = MUTEX_CREATE(NO); | 543 | cron_add_job (cron, |
614 | cron = gnunet_gtk_get_cron(); | 544 | &updateStatValues, UPDATE_INTERVAL, UPDATE_INTERVAL, NULL); |
615 | cron_add_job(cron, | 545 | cron_add_job (cron, |
616 | &updateStatValues, | 546 | &updateConnectionGoal, |
617 | UPDATE_INTERVAL, | 547 | 5 * cronMINUTES, 5 * cronMINUTES, NULL); |
618 | UPDATE_INTERVAL, | ||
619 | NULL); | ||
620 | cron_add_job(cron, | ||
621 | &updateConnectionGoal, | ||
622 | 5 * cronMINUTES, | ||
623 | 5 * cronMINUTES, | ||
624 | NULL); | ||
625 | } | 548 | } |
626 | 549 | ||
627 | void done_functions() { | 550 | void |
551 | done_functions () | ||
552 | { | ||
628 | int i; | 553 | int i; |
629 | 554 | ||
630 | cron_del_job(cron, | 555 | cron_del_job (cron, &updateConnectionGoal, 5 * cronMINUTES, NULL); |
631 | &updateConnectionGoal, | 556 | cron_del_job (cron, &updateStatValues, UPDATE_INTERVAL, NULL); |
632 | 5 * cronMINUTES, | 557 | MUTEX_DESTROY (lock); |
633 | NULL); | 558 | connection_destroy (sock); |
634 | cron_del_job(cron, | 559 | for (i = 0; i < lsv_size; i++) |
635 | &updateStatValues, | 560 | FREE (lastStatValues[i].statName); |
636 | UPDATE_INTERVAL, | 561 | GROW (lastStatValues, lsv_size, 0); |
637 | NULL); | ||
638 | MUTEX_DESTROY(lock); | ||
639 | connection_destroy(sock); | ||
640 | for (i=0;i<lsv_size;i++) | ||
641 | FREE(lastStatValues[i].statName); | ||
642 | GROW(lastStatValues, | ||
643 | lsv_size, | ||
644 | 0); | ||
645 | sock = NULL; | 562 | sock = NULL; |
646 | } | 563 | } |
647 | 564 | ||
diff --git a/src/plugins/stats/functions.h b/src/plugins/stats/functions.h index ebd54cf1..a02ac4fa 100644 --- a/src/plugins/stats/functions.h +++ b/src/plugins/stats/functions.h | |||
@@ -24,8 +24,9 @@ | |||
24 | 24 | ||
25 | #include <GNUnet/gnunet_util.h> | 25 | #include <GNUnet/gnunet_util.h> |
26 | 26 | ||
27 | typedef struct { | 27 | typedef struct |
28 | char * statName; | 28 | { |
29 | char *statName; | ||
29 | long long value; | 30 | long long value; |
30 | long long lvalue; | 31 | long long lvalue; |
31 | cron_t delta; | 32 | cron_t delta; |
@@ -35,24 +36,23 @@ typedef struct { | |||
35 | * Callback function to obtain the latest stats | 36 | * Callback function to obtain the latest stats |
36 | * data for this stat display. | 37 | * data for this stat display. |
37 | */ | 38 | */ |
38 | typedef int (*UpdateData)(const void * closure, | 39 | typedef int (*UpdateData) (const void *closure, gfloat ** data); |
39 | gfloat ** data); | ||
40 | 40 | ||
41 | 41 | ||
42 | typedef struct SE_ { | 42 | typedef struct SE_ |
43 | char * paneName; | 43 | { |
44 | char * frameName; | 44 | char *paneName; |
45 | char *frameName; | ||
45 | UpdateData getData; | 46 | UpdateData getData; |
46 | void * get_closure; | 47 | void *get_closure; |
47 | unsigned int count; | 48 | unsigned int count; |
48 | int fill; /* fill first "fill" entries */ | 49 | int fill; /* fill first "fill" entries */ |
49 | } StatEntry; | 50 | } StatEntry; |
50 | 51 | ||
51 | extern StatEntry stats[]; | 52 | extern StatEntry stats[]; |
52 | 53 | ||
53 | void init_functions(struct GE_Context * e, | 54 | void init_functions (struct GE_Context *e, struct GC_Configuration *c); |
54 | struct GC_Configuration * c); | ||
55 | 55 | ||
56 | void done_functions(void); | 56 | void done_functions (void); |
57 | 57 | ||
58 | #endif | 58 | #endif |
diff --git a/src/plugins/stats/statistics.c b/src/plugins/stats/statistics.c index d1da9422..4f8c34b1 100644 --- a/src/plugins/stats/statistics.c +++ b/src/plugins/stats/statistics.c | |||
@@ -32,7 +32,8 @@ | |||
32 | #define FRAME_WIDTH 0 | 32 | #define FRAME_WIDTH 0 |
33 | 33 | ||
34 | 34 | ||
35 | typedef struct { | 35 | typedef struct |
36 | { | ||
36 | gint type; | 37 | gint type; |
37 | guint count; | 38 | guint count; |
38 | guint speed; | 39 | guint speed; |
@@ -54,10 +55,11 @@ typedef struct { | |||
54 | int statIdx; | 55 | int statIdx; |
55 | } LoadGraph; | 56 | } LoadGraph; |
56 | 57 | ||
57 | typedef struct { | 58 | typedef struct |
58 | GdkColor bg_color; | 59 | { |
59 | GdkColor frame_color; | 60 | GdkColor bg_color; |
60 | GdkColor mem_color[MAX_COLOR]; | 61 | GdkColor frame_color; |
62 | GdkColor mem_color[MAX_COLOR]; | ||
61 | } ProcConfig; | 63 | } ProcConfig; |
62 | 64 | ||
63 | static unsigned long long UPDATE_INTERVAL; | 65 | static unsigned long long UPDATE_INTERVAL; |
@@ -65,13 +67,15 @@ static unsigned long long UPDATE_INTERVAL; | |||
65 | /** | 67 | /** |
66 | * Redraws the backing pixmap for the load graph and updates the window | 68 | * Redraws the backing pixmap for the load graph and updates the window |
67 | */ | 69 | */ |
68 | static void load_graph_draw(LoadGraph *g) { | 70 | static void |
71 | load_graph_draw (LoadGraph * g) | ||
72 | { | ||
69 | guint i; | 73 | guint i; |
70 | guint j; | 74 | guint j; |
71 | gint dely; | 75 | gint dely; |
72 | float delx; | 76 | float delx; |
73 | float max; | 77 | float max; |
74 | GdkFont * font; | 78 | GdkFont *font; |
75 | 79 | ||
76 | if (!g->disp->window) | 80 | if (!g->disp->window) |
77 | return; | 81 | return; |
@@ -81,345 +85,342 @@ static void load_graph_draw(LoadGraph *g) { | |||
81 | 85 | ||
82 | if (!g->pixmap) | 86 | if (!g->pixmap) |
83 | g->pixmap = gdk_pixmap_new (g->disp->window, | 87 | g->pixmap = gdk_pixmap_new (g->disp->window, |
84 | g->draw_width, g->draw_height, | 88 | g->draw_width, g->draw_height, |
85 | gtk_widget_get_visual (g->disp)->depth); | 89 | gtk_widget_get_visual (g->disp)->depth); |
86 | 90 | ||
87 | /* Create GC if necessary. */ | 91 | /* Create GC if necessary. */ |
88 | if (!g->gc) { | 92 | if (!g->gc) |
89 | g->gc = gdk_gc_new (g->disp->window); | 93 | { |
90 | gdk_gc_copy (g->gc, g->disp->style->white_gc); | 94 | g->gc = gdk_gc_new (g->disp->window); |
91 | } | 95 | gdk_gc_copy (g->gc, g->disp->style->white_gc); |
96 | } | ||
92 | 97 | ||
93 | /* Allocate colors. */ | 98 | /* Allocate colors. */ |
94 | if (!g->colors_allocated) { | 99 | if (!g->colors_allocated) |
95 | GdkColormap *colormap; | 100 | { |
101 | GdkColormap *colormap; | ||
96 | 102 | ||
97 | colormap = gdk_window_get_colormap (g->disp->window); | 103 | colormap = gdk_window_get_colormap (g->disp->window); |
98 | for (i=0;i<2+g->count;i++) | 104 | for (i = 0; i < 2 + g->count; i++) |
99 | gdk_color_alloc (colormap, &(g->colors [i])); | 105 | gdk_color_alloc (colormap, &(g->colors[i])); |
100 | 106 | ||
101 | g->colors_allocated = 1; | 107 | g->colors_allocated = 1; |
102 | } | 108 | } |
103 | /* Erase Rectangle */ | 109 | /* Erase Rectangle */ |
104 | gdk_gc_set_foreground (g->gc, &(g->colors [0])); | 110 | gdk_gc_set_foreground (g->gc, &(g->colors[0])); |
105 | gdk_draw_rectangle (g->pixmap, | 111 | gdk_draw_rectangle (g->pixmap, |
106 | g->gc, | 112 | g->gc, |
107 | TRUE, 0, 0, | 113 | TRUE, 0, 0, |
108 | g->disp->allocation.width, | 114 | g->disp->allocation.width, g->disp->allocation.height); |
109 | g->disp->allocation.height); | ||
110 | 115 | ||
111 | /* draw frame */ | 116 | /* draw frame */ |
112 | gdk_gc_set_foreground (g->gc, &(g->colors [1])); | 117 | gdk_gc_set_foreground (g->gc, &(g->colors[1])); |
113 | gdk_draw_rectangle (g->pixmap, | 118 | gdk_draw_rectangle (g->pixmap, |
114 | g->gc, | 119 | g->gc, |
115 | FALSE, 0, 0, | 120 | FALSE, 0, 0, g->draw_width, g->disp->allocation.height); |
116 | g->draw_width, | ||
117 | g->disp->allocation.height); | ||
118 | 121 | ||
119 | max = 0.26; /* force showing at least the 25% line */ | 122 | max = 0.26; /* force showing at least the 25% line */ |
120 | for (i = 0; i < g->num_points - 1; i++) | 123 | for (i = 0; i < g->num_points - 1; i++) |
121 | for (j=0;j<g->count;j++) | 124 | for (j = 0; j < g->count; j++) |
122 | if (g->data[i][j] > max) | 125 | if (g->data[i][j] > max) |
123 | max = g->data[i][j]; | 126 | max = g->data[i][j]; |
124 | max = max * 1.01; /* leave top 1% free */ | 127 | max = max * 1.01; /* leave top 1% free */ |
125 | 128 | ||
126 | font = gdk_font_load("fixed"); /* deprecated, but pango is far more than | 129 | font = gdk_font_load ("fixed"); /* deprecated, but pango is far more than |
127 | what we need here -- fix later? */ | 130 | what we need here -- fix later? */ |
128 | /* draw lines at 25%, 50%, 75% and 100% of max */ | 131 | /* draw lines at 25%, 50%, 75% and 100% of max */ |
129 | dely = g->draw_height / max / 4; | 132 | dely = g->draw_height / max / 4; |
130 | for (i = 1; i < 5; i++) { | 133 | for (i = 1; i < 5; i++) |
131 | gint y1 = g->draw_height + 1 - i * dely; | 134 | { |
132 | if ( (dely < 30) && (i != 4) ) | 135 | gint y1 = g->draw_height + 1 - i * dely; |
133 | continue; /* only print additional | 136 | if ((dely < 30) && (i != 4)) |
134 | lines if there is enough space! */ | 137 | continue; /* only print additional |
135 | if (y1 > 0) { | 138 | lines if there is enough space! */ |
136 | const gchar * label[] = { | 139 | if (y1 > 0) |
137 | NULL, | 140 | { |
138 | " 25%", | 141 | const gchar *label[] = { |
139 | " 50%", | 142 | NULL, |
140 | " 75%", | 143 | " 25%", |
141 | "100%", | 144 | " 50%", |
142 | }; | 145 | " 75%", |
143 | gdk_draw_string(g->pixmap, | 146 | "100%", |
144 | font, | 147 | }; |
145 | g->gc, | 148 | gdk_draw_string (g->pixmap, font, g->gc, 10, y1 - 8, label[i]); |
146 | 10, | 149 | gdk_draw_line (g->pixmap, g->gc, 0, y1, g->draw_width, y1); |
147 | y1 - 8, | 150 | if (i == 4) |
148 | label[i]); | 151 | { |
149 | gdk_draw_line (g->pixmap, g->gc, | 152 | /* extra-thick line at 100% */ |
150 | 0, y1, g->draw_width, y1); | 153 | gdk_draw_line (g->pixmap, g->gc, |
151 | if (i == 4) { | 154 | 0, y1 - 1, g->draw_width, y1 - 1); |
152 | /* extra-thick line at 100% */ | 155 | gdk_draw_line (g->pixmap, g->gc, |
153 | gdk_draw_line (g->pixmap, g->gc, | 156 | 0, y1 + 1, g->draw_width, y1 + 1); |
154 | 0, y1 - 1, g->draw_width, y1 - 1); | 157 | |
155 | gdk_draw_line (g->pixmap, g->gc, | 158 | } |
156 | 0, y1 + 1, g->draw_width, y1 + 1); | 159 | } |
157 | |||
158 | } | ||
159 | } | 160 | } |
160 | } | 161 | gdk_gc_set_line_attributes (g->gc, |
161 | gdk_gc_set_line_attributes(g->gc, | 162 | 2, |
162 | 2, | 163 | GDK_LINE_SOLID, GDK_CAP_ROUND, GDK_JOIN_MITER); |
163 | GDK_LINE_SOLID, | 164 | delx = (float) g->draw_width / (g->num_points - 1); |
164 | GDK_CAP_ROUND, | 165 | |
165 | GDK_JOIN_MITER); | 166 | for (j = 0; j < g->count; j++) |
166 | delx = (float)g->draw_width / ( g->num_points - 1); | 167 | { |
167 | 168 | gdk_gc_set_foreground (g->gc, &(g->colors[j + 2])); | |
168 | for (j=0;j<g->count;j++) { | 169 | for (i = 0; i < g->num_points - 1; i++) |
169 | gdk_gc_set_foreground (g->gc, &(g->colors [j + 2])); | 170 | { |
170 | for (i = 0; i < g->num_points - 1; i++) { | 171 | gint x1 = i * delx; |
171 | gint x1 = i * delx; | 172 | gint x2 = (i + 1) * delx; |
172 | gint x2 = (i + 1) * delx; | 173 | gint y1 = g->data[i][j] / max * g->draw_height - 1; |
173 | gint y1 = g->data[i][j] / max * g->draw_height - 1; | 174 | gint y2 = g->data[i + 1][j] / max * g->draw_height - 1; |
174 | gint y2 = g->data[i+1][j] / max * g->draw_height - 1; | 175 | |
175 | 176 | if ((g->data[i][j] != -1) && (g->data[i + 1][j] != -1)) | |
176 | if ((g->data[i][j] != -1) && (g->data[i+1][j] != -1)) { | 177 | { |
177 | if (stats[g->statIdx].fill <= j) { | 178 | if (stats[g->statIdx].fill <= j) |
178 | gdk_draw_line(g->pixmap, g->gc, | 179 | { |
179 | g->draw_width - x2, | 180 | gdk_draw_line (g->pixmap, g->gc, |
180 | g->draw_height - y2, | 181 | g->draw_width - x2, |
181 | g->draw_width - x1, | 182 | g->draw_height - y2, |
182 | g->draw_height - y1); | 183 | g->draw_width - x1, g->draw_height - y1); |
183 | } else { | 184 | } |
184 | GdkPoint points[4]; | 185 | else |
185 | 186 | { | |
186 | points[0].x = g->draw_width - x2; | 187 | GdkPoint points[4]; |
187 | points[0].y = g->draw_height - y2; | 188 | |
188 | points[1].x = g->draw_width - x1; | 189 | points[0].x = g->draw_width - x2; |
189 | points[1].y = g->draw_height - y1; | 190 | points[0].y = g->draw_height - y2; |
190 | points[2].x = g->draw_width - x1; | 191 | points[1].x = g->draw_width - x1; |
191 | points[3].x = g->draw_width - x2; | 192 | points[1].y = g->draw_height - y1; |
192 | if (j == 0) { | 193 | points[2].x = g->draw_width - x1; |
193 | points[2].y = g->draw_height; | 194 | points[3].x = g->draw_width - x2; |
194 | points[3].y = g->draw_height; | 195 | if (j == 0) |
195 | } else { | 196 | { |
196 | gint ly1 = g->data[i][j-1] / max * g->draw_height - 1; | 197 | points[2].y = g->draw_height; |
197 | gint ly2 = g->data[i+1][j-1] / max * g->draw_height - 1; | 198 | points[3].y = g->draw_height; |
198 | points[2].y = g->draw_height - ly1; | 199 | } |
199 | points[3].y = g->draw_height - ly2; | 200 | else |
200 | } | 201 | { |
201 | gdk_draw_polygon(g->pixmap, | 202 | gint ly1 = g->data[i][j - 1] / max * g->draw_height - 1; |
202 | g->gc, | 203 | gint ly2 = |
203 | 1, | 204 | g->data[i + 1][j - 1] / max * g->draw_height - 1; |
204 | points, | 205 | points[2].y = g->draw_height - ly1; |
205 | 4); | 206 | points[3].y = g->draw_height - ly2; |
206 | } | 207 | } |
207 | } | 208 | gdk_draw_polygon (g->pixmap, g->gc, 1, points, 4); |
209 | } | ||
210 | } | ||
211 | } | ||
208 | } | 212 | } |
209 | } | ||
210 | 213 | ||
211 | gdk_gc_set_line_attributes (g->gc, 1, | 214 | gdk_gc_set_line_attributes (g->gc, 1, |
212 | GDK_LINE_SOLID, | 215 | GDK_LINE_SOLID, GDK_CAP_ROUND, GDK_JOIN_MITER); |
213 | GDK_CAP_ROUND, | ||
214 | GDK_JOIN_MITER ); | ||
215 | 216 | ||
216 | gdk_draw_pixmap (g->disp->window, | 217 | gdk_draw_pixmap (g->disp->window, |
217 | g->disp->style->fg_gc [GTK_WIDGET_STATE(g->disp)], | 218 | g->disp->style->fg_gc[GTK_WIDGET_STATE (g->disp)], |
218 | g->pixmap, | 219 | g->pixmap, |
219 | 0, 0, | 220 | 0, 0, |
220 | 0, 0, | 221 | 0, 0, |
221 | g->disp->allocation.width, | 222 | g->disp->allocation.width, g->disp->allocation.height); |
222 | g->disp->allocation.height); | ||
223 | } | 223 | } |
224 | 224 | ||
225 | 225 | ||
226 | /* Updates the load graph when the timeout expires */ | 226 | /* Updates the load graph when the timeout expires */ |
227 | static gboolean load_graph_update(gpointer ptr) { | 227 | static gboolean |
228 | load_graph_update (gpointer ptr) | ||
229 | { | ||
228 | LoadGraph *g = ptr; | 230 | LoadGraph *g = ptr; |
229 | guint i; | 231 | guint i; |
230 | guint j; | 232 | guint j; |
231 | 233 | ||
232 | for (i=0;i<g->num_points;i++) | 234 | for (i = 0; i < g->num_points; i++) |
233 | memcpy(g->odata[i], | 235 | memcpy (g->odata[i], g->data[i], g->data_size * g->count); |
234 | g->data[i], | 236 | stats[g->statIdx].getData (stats[g->statIdx].get_closure, g->data); |
235 | g->data_size * g->count); | 237 | for (i = 0; i < g->num_points - 1; i++) |
236 | stats[g->statIdx].getData(stats[g->statIdx].get_closure, | 238 | for (j = 0; j < g->count; j++) |
237 | g->data); | 239 | g->data[i + 1][j] = g->odata[i][j]; |
238 | for (i=0;i<g->num_points-1;i++) | ||
239 | for (j=0;j<g->count;j++) | ||
240 | g->data[i+1][j] = g->odata[i][j]; | ||
241 | if (g->draw) | 240 | if (g->draw) |
242 | load_graph_draw (g); | 241 | load_graph_draw (g); |
243 | return TRUE; | 242 | return TRUE; |
244 | } | 243 | } |
245 | 244 | ||
246 | static void load_graph_unalloc(LoadGraph *g) { | 245 | static void |
246 | load_graph_unalloc (LoadGraph * g) | ||
247 | { | ||
247 | int i; | 248 | int i; |
248 | if (!g->allocated) | 249 | if (!g->allocated) |
249 | return; | 250 | return; |
250 | for (i = 0; i < g->num_points; i++) { | 251 | for (i = 0; i < g->num_points; i++) |
251 | FREE(g->data[i]); | 252 | { |
252 | FREE(g->odata[i]); | 253 | FREE (g->data[i]); |
253 | } | 254 | FREE (g->odata[i]); |
254 | FREE(g->data); | 255 | } |
255 | FREE(g->odata); | 256 | FREE (g->data); |
257 | FREE (g->odata); | ||
256 | g->data = g->odata = NULL; | 258 | g->data = g->odata = NULL; |
257 | if (g->pixmap) { | 259 | if (g->pixmap) |
258 | gdk_pixmap_unref(g->pixmap); | 260 | { |
259 | g->pixmap = NULL; | 261 | gdk_pixmap_unref (g->pixmap); |
260 | } | 262 | g->pixmap = NULL; |
263 | } | ||
261 | g->allocated = FALSE; | 264 | g->allocated = FALSE; |
262 | } | 265 | } |
263 | 266 | ||
264 | static void load_graph_alloc (LoadGraph *g) { | 267 | static void |
268 | load_graph_alloc (LoadGraph * g) | ||
269 | { | ||
265 | int i; | 270 | int i; |
266 | int j; | 271 | int j; |
267 | 272 | ||
268 | if (g->allocated) | 273 | if (g->allocated) |
269 | return; | 274 | return; |
270 | 275 | ||
271 | g->data = MALLOC(sizeof(gfloat *) * g->num_points); | 276 | g->data = MALLOC (sizeof (gfloat *) * g->num_points); |
272 | g->odata = MALLOC(sizeof(gfloat*) * g->num_points); | 277 | g->odata = MALLOC (sizeof (gfloat *) * g->num_points); |
273 | g->data_size = sizeof (gfloat); | 278 | g->data_size = sizeof (gfloat); |
274 | for (i = 0; i < g->num_points; i++) { | 279 | for (i = 0; i < g->num_points; i++) |
275 | g->data[i] = MALLOC(g->data_size * g->count); | 280 | { |
276 | g->odata[i] = MALLOC(g->data_size * g->count); | 281 | g->data[i] = MALLOC (g->data_size * g->count); |
277 | } | 282 | g->odata[i] = MALLOC (g->data_size * g->count); |
278 | for (i=0;i<g->num_points;i++) | 283 | } |
279 | for (j=0;j<g->count;j++) | 284 | for (i = 0; i < g->num_points; i++) |
285 | for (j = 0; j < g->count; j++) | ||
280 | g->data[i][j] = -1; | 286 | g->data[i][j] = -1; |
281 | g->allocated = TRUE; | 287 | g->allocated = TRUE; |
282 | } | 288 | } |
283 | 289 | ||
284 | static gint load_graph_configure(GtkWidget *widget, | 290 | static gint |
285 | GdkEventConfigure *event, | 291 | load_graph_configure (GtkWidget * widget, |
286 | gpointer data_ptr) { | 292 | GdkEventConfigure * event, gpointer data_ptr) |
293 | { | ||
287 | LoadGraph *c = (LoadGraph *) data_ptr; | 294 | LoadGraph *c = (LoadGraph *) data_ptr; |
288 | 295 | ||
289 | if (c->pixmap) { | 296 | if (c->pixmap) |
290 | gdk_pixmap_unref (c->pixmap); | 297 | { |
291 | c->pixmap = NULL; | 298 | gdk_pixmap_unref (c->pixmap); |
292 | } | 299 | c->pixmap = NULL; |
300 | } | ||
293 | 301 | ||
294 | if (!c->pixmap) | 302 | if (!c->pixmap) |
295 | c->pixmap = gdk_pixmap_new(widget->window, | 303 | c->pixmap = gdk_pixmap_new (widget->window, |
296 | widget->allocation.width, | 304 | widget->allocation.width, |
297 | widget->allocation.height, | 305 | widget->allocation.height, |
298 | gtk_widget_get_visual (c->disp)->depth); | 306 | gtk_widget_get_visual (c->disp)->depth); |
299 | gdk_draw_rectangle(c->pixmap, | 307 | gdk_draw_rectangle (c->pixmap, |
300 | widget->style->black_gc, | 308 | widget->style->black_gc, |
301 | TRUE, 0,0, | 309 | TRUE, 0, 0, |
302 | widget->allocation.width, | 310 | widget->allocation.width, widget->allocation.height); |
303 | widget->allocation.height); | 311 | gdk_draw_pixmap (widget->window, |
304 | gdk_draw_pixmap(widget->window, | 312 | c->disp->style->fg_gc[GTK_WIDGET_STATE (widget)], |
305 | c->disp->style->fg_gc[GTK_WIDGET_STATE(widget)], | 313 | c->pixmap, |
306 | c->pixmap, | 314 | 0, 0, |
307 | 0, 0, | 315 | 0, 0, |
308 | 0, 0, | 316 | c->disp->allocation.width, c->disp->allocation.height); |
309 | c->disp->allocation.width, | 317 | |
310 | c->disp->allocation.height); | 318 | load_graph_draw (c); |
311 | |||
312 | load_graph_draw(c); | ||
313 | return TRUE; | 319 | return TRUE; |
314 | } | 320 | } |
315 | 321 | ||
316 | static gint load_graph_expose(GtkWidget *widget, | 322 | static gint |
317 | GdkEventExpose *event, | 323 | load_graph_expose (GtkWidget * widget, |
318 | gpointer data_ptr) { | 324 | GdkEventExpose * event, gpointer data_ptr) |
325 | { | ||
319 | LoadGraph *g = (LoadGraph *) data_ptr; | 326 | LoadGraph *g = (LoadGraph *) data_ptr; |
320 | 327 | ||
321 | gdk_draw_pixmap(widget->window, | 328 | gdk_draw_pixmap (widget->window, |
322 | widget->style->fg_gc [GTK_WIDGET_STATE(widget)], | 329 | widget->style->fg_gc[GTK_WIDGET_STATE (widget)], |
323 | g->pixmap, | 330 | g->pixmap, |
324 | event->area.x, event->area.y, | 331 | event->area.x, event->area.y, |
325 | event->area.x, event->area.y, | 332 | event->area.x, event->area.y, |
326 | event->area.width, event->area.height); | 333 | event->area.width, event->area.height); |
327 | return FALSE; | 334 | return FALSE; |
328 | } | 335 | } |
329 | 336 | ||
330 | static void load_graph_stop (LoadGraph *g) { | 337 | static void |
338 | load_graph_stop (LoadGraph * g) | ||
339 | { | ||
331 | if (!g) | 340 | if (!g) |
332 | return; | 341 | return; |
333 | if (g->timer_index != -1) { | 342 | if (g->timer_index != -1) |
334 | gtk_timeout_remove(g->timer_index); | 343 | { |
335 | g->timer_index = -1; | 344 | gtk_timeout_remove (g->timer_index); |
336 | } | 345 | g->timer_index = -1; |
346 | } | ||
337 | g->draw = FALSE; | 347 | g->draw = FALSE; |
338 | } | 348 | } |
339 | 349 | ||
340 | static void load_graph_destroy(GtkWidget *widget, | 350 | static void |
341 | gpointer data_ptr) { | 351 | load_graph_destroy (GtkWidget * widget, gpointer data_ptr) |
352 | { | ||
342 | LoadGraph *g = (LoadGraph *) data_ptr; | 353 | LoadGraph *g = (LoadGraph *) data_ptr; |
343 | load_graph_stop(g); | 354 | load_graph_stop (g); |
344 | if (g->timer_index != -1) | 355 | if (g->timer_index != -1) |
345 | gtk_timeout_remove (g->timer_index); | 356 | gtk_timeout_remove (g->timer_index); |
346 | load_graph_unalloc(g); | 357 | load_graph_unalloc (g); |
347 | FREE(g->colors); | 358 | FREE (g->colors); |
348 | FREE(g); | 359 | FREE (g); |
349 | } | 360 | } |
350 | 361 | ||
351 | static LoadGraph * load_graph_new(int statIdx, | 362 | static LoadGraph * |
352 | const ProcConfig * config) { | 363 | load_graph_new (int statIdx, const ProcConfig * config) |
364 | { | ||
353 | LoadGraph *g; | 365 | LoadGraph *g; |
354 | unsigned int i; | 366 | unsigned int i; |
355 | 367 | ||
356 | if (stats[statIdx].count > MAX_COLOR) { | 368 | if (stats[statIdx].count > MAX_COLOR) |
357 | GE_BREAK(NULL, 0); | 369 | { |
358 | return NULL; | 370 | GE_BREAK (NULL, 0); |
359 | } | 371 | return NULL; |
372 | } | ||
360 | 373 | ||
361 | g = MALLOC(sizeof(LoadGraph)); | 374 | g = MALLOC (sizeof (LoadGraph)); |
362 | g->statIdx = statIdx; | 375 | g->statIdx = statIdx; |
363 | g->count = stats[statIdx].count; | 376 | g->count = stats[statIdx].count; |
364 | g->speed = UPDATE_INTERVAL / cronMILLIS; | 377 | g->speed = UPDATE_INTERVAL / cronMILLIS; |
365 | g->num_points = 600; | 378 | g->num_points = 600; |
366 | g->colors = MALLOC(sizeof(GdkColor) * (2+g->count)); | 379 | g->colors = MALLOC (sizeof (GdkColor) * (2 + g->count)); |
367 | g->colors[0] = config->bg_color; | 380 | g->colors[0] = config->bg_color; |
368 | g->colors[1] = config->frame_color; | 381 | g->colors[1] = config->frame_color; |
369 | for (i=0;i<g->count;i++) | 382 | for (i = 0; i < g->count; i++) |
370 | g->colors[2+i] = config->mem_color[i]; | 383 | g->colors[2 + i] = config->mem_color[i]; |
371 | g->timer_index = -1; | 384 | g->timer_index = -1; |
372 | g->draw = FALSE; | 385 | g->draw = FALSE; |
373 | g->main_widget = gtk_vbox_new (FALSE, FALSE); | 386 | g->main_widget = gtk_vbox_new (FALSE, FALSE); |
374 | gtk_widget_show(g->main_widget); | 387 | gtk_widget_show (g->main_widget); |
375 | g->disp = gtk_drawing_area_new(); | 388 | g->disp = gtk_drawing_area_new (); |
376 | gtk_widget_show (g->disp); | 389 | gtk_widget_show (g->disp); |
377 | gtk_signal_connect(GTK_OBJECT (g->disp), | 390 | gtk_signal_connect (GTK_OBJECT (g->disp), |
378 | "expose_event", | 391 | "expose_event", GTK_SIGNAL_FUNC (load_graph_expose), g); |
379 | GTK_SIGNAL_FUNC (load_graph_expose), g); | 392 | gtk_signal_connect (GTK_OBJECT (g->disp), |
380 | gtk_signal_connect(GTK_OBJECT(g->disp), | 393 | "configure_event", |
381 | "configure_event", | 394 | GTK_SIGNAL_FUNC (load_graph_configure), g); |
382 | GTK_SIGNAL_FUNC (load_graph_configure), g); | 395 | gtk_signal_connect (GTK_OBJECT (g->disp), |
383 | gtk_signal_connect(GTK_OBJECT(g->disp), | 396 | "destroy", GTK_SIGNAL_FUNC (load_graph_destroy), g); |
384 | "destroy", | 397 | gtk_widget_add_events (g->disp, GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK); |
385 | GTK_SIGNAL_FUNC (load_graph_destroy), g); | 398 | gtk_box_pack_start (GTK_BOX (g->main_widget), g->disp, TRUE, TRUE, 0); |
386 | gtk_widget_add_events(g->disp, | 399 | load_graph_alloc (g); |
387 | GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK); | 400 | gtk_widget_show_all (g->main_widget); |
388 | gtk_box_pack_start(GTK_BOX(g->main_widget), | 401 | g->timer_index = gtk_timeout_add (g->speed, &load_graph_update, g); |
389 | g->disp, | ||
390 | TRUE, | ||
391 | TRUE, | ||
392 | 0); | ||
393 | load_graph_alloc(g); | ||
394 | gtk_widget_show_all(g->main_widget); | ||
395 | g->timer_index = gtk_timeout_add(g->speed, | ||
396 | &load_graph_update, g); | ||
397 | 402 | ||
398 | return g; | 403 | return g; |
399 | } | 404 | } |
400 | 405 | ||
401 | static GtkWidget * create_sys_view(int statIdx, | 406 | static GtkWidget * |
402 | const ProcConfig * config) { | 407 | create_sys_view (int statIdx, const ProcConfig * config) |
403 | GtkWidget * mem_frame; | 408 | { |
404 | LoadGraph * mem_graph; | 409 | GtkWidget *mem_frame; |
410 | LoadGraph *mem_graph; | ||
405 | 411 | ||
406 | mem_graph = load_graph_new(statIdx, | 412 | mem_graph = load_graph_new (statIdx, config); |
407 | config); | ||
408 | if (mem_graph == NULL) | 413 | if (mem_graph == NULL) |
409 | return NULL; /* oops */ | 414 | return NULL; /* oops */ |
410 | mem_frame = gtk_frame_new(_(stats[statIdx].frameName)); | 415 | mem_frame = gtk_frame_new (_(stats[statIdx].frameName)); |
411 | gtk_container_add(GTK_CONTAINER(mem_frame), | 416 | gtk_container_add (GTK_CONTAINER (mem_frame), mem_graph->main_widget); |
412 | mem_graph->main_widget); | 417 | gtk_container_set_border_width (GTK_CONTAINER (mem_graph->main_widget), |
413 | gtk_container_set_border_width(GTK_CONTAINER(mem_graph->main_widget), | 418 | GNOME_PAD_SMALL); |
414 | GNOME_PAD_SMALL); | 419 | gtk_container_set_border_width (GTK_CONTAINER (mem_frame), GNOME_PAD_SMALL); |
415 | gtk_container_set_border_width(GTK_CONTAINER(mem_frame), | 420 | gtk_widget_show (mem_frame); |
416 | GNOME_PAD_SMALL); | ||
417 | gtk_widget_show(mem_frame); | ||
418 | if (mem_graph->timer_index == -1) | 421 | if (mem_graph->timer_index == -1) |
419 | mem_graph->timer_index | 422 | mem_graph->timer_index |
420 | = gtk_timeout_add(mem_graph->speed, | 423 | = gtk_timeout_add (mem_graph->speed, &load_graph_update, mem_graph); |
421 | &load_graph_update, | ||
422 | mem_graph); | ||
423 | mem_graph->draw = TRUE; | 424 | mem_graph->draw = TRUE; |
424 | return mem_frame; | 425 | return mem_frame; |
425 | } | 426 | } |
@@ -428,64 +429,50 @@ static GtkWidget * create_sys_view(int statIdx, | |||
428 | 429 | ||
429 | 430 | ||
430 | 431 | ||
431 | void init_stats(struct GE_Context * ectx, | 432 | void |
432 | struct GC_Configuration * cfg) { | 433 | init_stats (struct GE_Context *ectx, struct GC_Configuration *cfg) |
433 | GtkWidget * sys_box; | 434 | { |
434 | GtkWidget * label; | 435 | GtkWidget *sys_box; |
435 | GtkWidget * notebook; | 436 | GtkWidget *label; |
437 | GtkWidget *notebook; | ||
436 | ProcConfig config; | 438 | ProcConfig config; |
437 | int i; | 439 | int i; |
438 | 440 | ||
439 | GC_get_configuration_value_number(cfg, | 441 | GC_get_configuration_value_number (cfg, |
440 | "GNUNET-GTK", | 442 | "GNUNET-GTK", |
441 | "STATS-INTERVAL", | 443 | "STATS-INTERVAL", |
442 | 1, | 444 | 1, |
443 | 99 * cronYEARS, | 445 | 99 * cronYEARS, |
444 | 30 * cronSECONDS, | 446 | 30 * cronSECONDS, &UPDATE_INTERVAL); |
445 | &UPDATE_INTERVAL); | 447 | init_functions (ectx, cfg); |
446 | init_functions(ectx, | 448 | notebook = glade_xml_get_widget (getMainXML (), "statsNotebook"); |
447 | cfg); | 449 | memset (&config, 0, sizeof (ProcConfig)); |
448 | notebook | 450 | gdk_color_parse ("black", &config.bg_color); |
449 | = glade_xml_get_widget(getMainXML(), | 451 | gdk_color_parse ("gray", &config.frame_color); |
450 | "statsNotebook"); | 452 | gdk_color_parse ("red", &config.mem_color[0]); |
451 | memset(&config, | 453 | gdk_color_parse ("green", &config.mem_color[1]); |
452 | 0, | 454 | gdk_color_parse ("yellow", &config.mem_color[2]); |
453 | sizeof(ProcConfig)); | 455 | gdk_color_parse ("blue", &config.mem_color[3]); |
454 | gdk_color_parse("black", | 456 | gdk_color_parse ("gray", &config.mem_color[4]); |
455 | &config.bg_color); | 457 | gdk_color_parse ("magenta", &config.mem_color[5]); |
456 | gdk_color_parse("gray", | 458 | GE_ASSERT (ectx, MAX_COLOR == 6); |
457 | &config.frame_color); | ||
458 | gdk_color_parse("red", | ||
459 | &config.mem_color[0]); | ||
460 | gdk_color_parse("green", | ||
461 | &config.mem_color[1]); | ||
462 | gdk_color_parse("yellow", | ||
463 | &config.mem_color[2]); | ||
464 | gdk_color_parse("blue", | ||
465 | &config.mem_color[3]); | ||
466 | gdk_color_parse("gray", | ||
467 | &config.mem_color[4]); | ||
468 | gdk_color_parse("magenta", | ||
469 | &config.mem_color[5]); | ||
470 | GE_ASSERT(ectx, | ||
471 | MAX_COLOR == 6); | ||
472 | i = -1; | 459 | i = -1; |
473 | while (stats[++i].paneName != NULL) { | 460 | while (stats[++i].paneName != NULL) |
474 | sys_box = create_sys_view(i, | 461 | { |
475 | &config); | 462 | sys_box = create_sys_view (i, &config); |
476 | if (sys_box == NULL) | 463 | if (sys_box == NULL) |
477 | continue; /* oops */ | 464 | continue; /* oops */ |
478 | 465 | ||
479 | label = gtk_label_new(gettext(stats[i].paneName)); | 466 | label = gtk_label_new (gettext (stats[i].paneName)); |
480 | gtk_notebook_append_page(GTK_NOTEBOOK(notebook), | 467 | gtk_notebook_append_page (GTK_NOTEBOOK (notebook), sys_box, label); |
481 | sys_box, | 468 | } |
482 | label); | 469 | gtk_widget_show (notebook); |
483 | } | ||
484 | gtk_widget_show(notebook); | ||
485 | } | 470 | } |
486 | 471 | ||
487 | void done_stats() { | 472 | void |
488 | done_functions(); | 473 | done_stats () |
474 | { | ||
475 | done_functions (); | ||
489 | } | 476 | } |
490 | 477 | ||
491 | 478 | ||