Mercurial > geeqie
comparison src/collect.c @ 816:cf5bbd0beaae
collection_from_dnd_data(): simplify and optimize.
author | zas_ |
---|---|
date | Tue, 10 Jun 2008 11:55:18 +0000 |
parents | 7daea970a89a |
children | 9962b24b6b43 |
comparison
equal
deleted
inserted
replaced
815:7daea970a89a | 816:cf5bbd0beaae |
---|---|
425 } | 425 } |
426 | 426 |
427 CollectionData *collection_from_dnd_data(const gchar *data, GList **list, GList **info_list) | 427 CollectionData *collection_from_dnd_data(const gchar *data, GList **list, GList **info_list) |
428 { | 428 { |
429 CollectionData *cd; | 429 CollectionData *cd; |
430 gint n; | 430 gint collection_number; |
431 const gchar *ptr; | |
432 | |
433 if (list) *list = NULL; | |
434 if (info_list) *info_list = NULL; | |
431 | 435 |
432 if (strncmp(data, "COLLECTION:", 11) != 0) return NULL; | 436 if (strncmp(data, "COLLECTION:", 11) != 0) return NULL; |
433 | 437 |
434 n = (gint)strtol(data + 11, NULL, 10); | 438 ptr = data + 11; |
435 cd = collection_from_number(n); | 439 |
436 | 440 collection_number = atoi(ptr); |
437 if (!cd || (!list && !info_list)) | 441 cd = collection_from_number(collection_number); |
438 { | 442 if (!cd) return NULL; |
439 return cd; | 443 |
440 } | 444 if (!list && !info_list) return cd; |
441 else | 445 |
442 { | 446 while (*ptr != '\0' && *ptr != '\n' ) ptr++; |
443 GList *work = NULL; | 447 if (*ptr == '\0') return cd; |
444 GList *infol = NULL; | 448 ptr++; |
445 gint b, e; | 449 |
446 | 450 while (*ptr != '\0') |
447 b = 0; | 451 { |
448 while (data[b] != '\0' && data[b] != '\n' ) b++; | 452 guint item_number; |
449 b++; | 453 CollectInfo *info; |
450 e = b; | 454 |
451 | 455 item_number = (guint) atoi(ptr); |
452 while (data[b] != '\0') | 456 while (*ptr != '\n' && *ptr != '\0') ptr++; |
453 { | 457 if (*ptr == '\0') |
454 CollectInfo *info; | 458 break; |
455 | 459 else |
456 while (data[e] != '\n' && data[e] != '\0') e++; | 460 while (*ptr == '\n') ptr++; |
457 n = (gint)strtol(data + b, NULL, 10); | 461 |
458 | 462 info = g_list_nth_data(cd->list, item_number); |
459 info = g_list_nth_data(cd->list, n); | 463 if (!info) continue; |
460 if (info && list) work = g_list_append(work, file_data_ref(info->fd)); | 464 |
461 if (info && info_list) infol = g_list_append(infol, info); | 465 if (list) *list = g_list_append(*list, file_data_ref(info->fd)); |
462 | 466 if (info_list) *info_list = g_list_append(*info_list, info); |
463 while (data[e] == '\n') e++; | 467 } |
464 b = e; | 468 |
465 } | |
466 if (list) *list = work; | |
467 if (info_list) *info_list = infol; | |
468 } | |
469 | |
470 return cd; | 469 return cd; |
471 } | 470 } |
472 | 471 |
473 gchar *collection_info_list_to_dnd_data(CollectionData *cd, GList *list, gint *length) | 472 gchar *collection_info_list_to_dnd_data(CollectionData *cd, GList *list, gint *length) |
474 { | 473 { |