summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/modules/everything-files/e_mod_main.c172
1 files changed, 83 insertions, 89 deletions
diff --git a/src/modules/everything-files/e_mod_main.c b/src/modules/everything-files/e_mod_main.c
index 09f2d6d40..d4d7d1e59 100644
--- a/src/modules/everything-files/e_mod_main.c
+++ b/src/modules/everything-files/e_mod_main.c
@@ -177,10 +177,8 @@ _scan_func(Ecore_Thread *thread __UNUSED__, void *data)
177 char buf[4096]; 177 char buf[4096];
178 Eina_Bool is_dir; 178 Eina_Bool is_dir;
179 179
180 if (!d->directory) 180 if (!(d->dirp = opendir(d->directory)))
181 return; 181 return;
182 d->dirp = opendir(d->directory);
183 if (!d->dirp) return;
184 182
185 while ((dp = readdir(d->dirp))) 183 while ((dp = readdir(d->dirp)))
186 { 184 {
@@ -332,25 +330,70 @@ _scan_cancel_func(void *data)
332 else 330 else
333 { 331 {
334 EINA_LIST_FREE(d->files, file) 332 EINA_LIST_FREE(d->files, file)
335 { 333 EVRY_ITEM_FREE(file);
336 if (file->path)
337 eina_stringshare_del(file->path);
338 if (EVRY_ITEM(file)->label)
339 eina_stringshare_del(EVRY_ITEM(file)->label);
340 if (EVRY_ITEM(file)->detail)
341 eina_stringshare_del(EVRY_ITEM(file)->detail);
342 free(file);
343 }
344 } 334 }
345 335
336 if (p->wait_finish)
337 E_FREE(p);
338 else
339 p->thread = NULL;
340
346 free(d->directory); 341 free(d->directory);
347 d->directory = NULL;
348 E_FREE(d); 342 E_FREE(d);
349 343
350 p->thread = NULL; 344}
351 345
352 if (p->wait_finish) 346static void
353 E_FREE(p); 347_cache_mime_get(History_Types *ht, Evry_Item_File *file)
348{
349 History_Entry *he;
350 History_Item *hi;
351 Eina_List *l;
352
353 if (he = eina_hash_find(ht->types, file->path))
354 {
355 EINA_LIST_FOREACH(he->items, l, hi)
356 {
357 if (!hi->data)
358 continue;
359
360 if (!file->mime)
361 file->mime = eina_stringshare_ref(hi->data);
362
363 hi->transient = 0;
364 EVRY_ITEM(file)->hi = hi;
365 break;
366 }
367 }
368}
369
370static void
371_cache_dir_add(Eina_List *files)
372{
373 Eina_List *l;
374 Evry_Item *item;
375 History_Item *hi;
376 int cnt = 0;
377
378 EINA_LIST_REVERSE_FOREACH(files, l, item)
379 {
380 GET_FILE(file, item);
381
382 if (!(item->hi) &&
383 (hi = evry->history_item_add(item, NULL, NULL)))
384 {
385 hi->last_used = SIX_DAYS_AGO;
386 hi->usage = MIN_USAGE * (double) cnt++;
387 hi->data = eina_stringshare_ref(file->mime);
388 item->hi = hi;
389 }
390 else if (item->hi && (item->hi->count == 1) &&
391 (item->hi->last_used < SIX_DAYS_AGO))
392 {
393 item->hi->last_used = SIX_DAYS_AGO;
394 item->hi->usage = MIN_USAGE * (double) cnt++;
395 }
396 }
354} 397}
355 398
356static void 399static void
@@ -360,16 +403,13 @@ _scan_end_func(void *data)
360 Plugin *p = d->plugin; 403 Plugin *p = d->plugin;
361 Evry_Item *item; 404 Evry_Item *item;
362 char *filename, *path, *mime; 405 char *filename, *path, *mime;
363 Eina_List *l, *ll, *lll; 406 Eina_List *l, *ll;
364 History_Item *hi;
365 History_Entry *he;
366 History_Types *ht = NULL; 407 History_Types *ht = NULL;
367 int cnt = 0;
368 408
369 if (_conf->cache_dirs) 409 if (_conf->cache_dirs)
370 ht = evry->history_types_get(EVRY_TYPE_FILE); 410 ht = evry->history_types_get(EVRY_TYPE_FILE);
371 411
372 if (!d->run_cnt) 412 if (!d->run_cnt) /* _scan_func finished */
373 { 413 {
374 EINA_LIST_FOREACH_SAFE(d->files, l, ll, item) 414 EINA_LIST_FOREACH_SAFE(d->files, l, ll, item)
375 { 415 {
@@ -387,23 +427,8 @@ _scan_end_func(void *data)
387 file->mime = eina_stringshare_ref(_mime_dir); 427 file->mime = eina_stringshare_ref(_mime_dir);
388 428
389 /* check if we can grab the mimetype from history */ 429 /* check if we can grab the mimetype from history */
390 if ((_conf->cache_dirs && ht) && 430 if (ht) _cache_mime_get(ht, file);
391 (he = eina_hash_find(ht->types, file->path))) 431
392 {
393 EINA_LIST_FOREACH(he->items, lll, hi)
394 {
395 if (!hi->data)
396 continue;
397
398 if (!file->mime)
399 file->mime = eina_stringshare_ref(hi->data);
400
401 hi->transient = 0;
402 item->hi = hi;
403 break;
404 }
405 }
406
407 if (file->mime) 432 if (file->mime)
408 { 433 {
409 item->context = eina_stringshare_ref(file->mime); 434 item->context = eina_stringshare_ref(file->mime);
@@ -427,21 +452,11 @@ _scan_end_func(void *data)
427 E_FREE(path); 452 E_FREE(path);
428 } 453 }
429 454
455 /* sort files by name for mimetypes scan */
430 if (d->files) 456 if (d->files)
431 { 457 d->files = eina_list_sort(d->files, -1, _cb_sort);
432 d->run_cnt++;
433 d->files = eina_list_sort(d->files, -1, _cb_sort);
434 p->thread = ecore_thread_run(_scan_mime_func,
435 _scan_end_func,
436 _scan_cancel_func, d);
437 return;
438 }
439 else
440 {
441 p->files = eina_list_sort(p->files, -1, _cb_sort);
442 }
443 } 458 }
444 else 459 else /* _scan_mime_func finished */
445 { 460 {
446 EINA_LIST_FREE(d->files, item) 461 EINA_LIST_FREE(d->files, item)
447 { 462 {
@@ -454,52 +469,30 @@ _scan_end_func(void *data)
454 469
455 p->files = eina_list_append(p->files, file); 470 p->files = eina_list_append(p->files, file);
456 } 471 }
457
458 if (d->files && d->run_cnt < 100)
459 {
460 d->run_cnt++;
461 p->thread = ecore_thread_run(_scan_mime_func,
462 _scan_end_func,
463 _scan_cancel_func, d);
464 }
465 else
466 {
467 EINA_LIST_FREE(d->files, item)
468 EVRY_ITEM_FREE(item);
469 }
470 } 472 }
471 473
472 if (!d->files) 474 if (d->files) /* scan mimetypes */
473 { 475 {
474 if (!(p->command == CMD_SHOW_HIDDEN) && _conf->cache_dirs) 476 d->run_cnt++;
475 { 477 p->thread = ecore_thread_run(_scan_mime_func,
476 EINA_LIST_REVERSE_FOREACH(p->files, l, item) 478 _scan_end_func,
477 { 479 _scan_cancel_func, d);
478 GET_FILE(file, item);
479
480 if (!(item->hi) &&
481 (hi = evry->history_item_add(item, NULL, NULL)))
482 {
483 hi->last_used = SIX_DAYS_AGO;
484 hi->usage = MIN_USAGE * (double) cnt++;
485 hi->data = eina_stringshare_ref(file->mime);
486 item->hi = hi;
487 }
488 else if (item->hi && (item->hi->count == 1) &&
489 (item->hi->last_used < SIX_DAYS_AGO))
490 {
491 item->hi->last_used = SIX_DAYS_AGO;
492 item->hi->usage = MIN_USAGE * (double) cnt++;
493 }
494 }
495 }
496 480
481 /* wait for first mime scan to finish */
482 if (d->run_cnt == 1) return;
483 }
484 else /* finished all file/mime scan */
485 {
497 free(d->directory); 486 free(d->directory);
498 d->directory = NULL;
499 E_FREE(d); 487 E_FREE(d);
500 p->thread = NULL; 488 p->thread = NULL;
489
490 if (_conf->cache_dirs && !(p->command == CMD_SHOW_HIDDEN))
491 _cache_dir_add(p->files);
501 } 492 }
502 493
494 p->files = eina_list_sort(p->files, -1, _cb_sort);
495
503 _append_files(p); 496 _append_files(p);
504 497
505 EVRY_PLUGIN_UPDATE(p, EVRY_UPDATE_ADD); 498 EVRY_PLUGIN_UPDATE(p, EVRY_UPDATE_ADD);
@@ -566,7 +559,8 @@ _read_directory(Plugin *p)
566 Data *d = E_NEW(Data, 1); 559 Data *d = E_NEW(Data, 1);
567 d->plugin = p; 560 d->plugin = p;
568 d->directory = strdup(p->directory); 561 d->directory = strdup(p->directory);
569 562 d->run_cnt = 0;
563
570 p->thread = ecore_thread_run(_scan_func, _scan_end_func, _scan_cancel_func, d); 564 p->thread = ecore_thread_run(_scan_func, _scan_end_func, _scan_cancel_func, d);
571 565
572 if (p->dir_mon) 566 if (p->dir_mon)