summaryrefslogtreecommitdiff
path: root/src/bin/e_bg.c
diff options
context:
space:
mode:
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>2012-08-09 13:58:51 +0000
committerMike Blumenkrantz <michael.blumenkrantz@gmail.com>2012-08-09 13:58:51 +0000
commitf6af7bd8d2c9ca31c9539928f80b98f434812218 (patch)
tree909af0e3ced91a00e100426a0a14d373bdec0d9d /src/bin/e_bg.c
parent516ff07701996aa5f62978d227441b0de1bb4ff8 (diff)
remove all traces of old and unused bg import dialog. whoever put a separate import dialog into e_utils.c, and the person who committed r44556 with the id "barbieri" on 2009-12-18 shall indeed remain nameless, decided to leave the other one hanging around. as a result, the one that he copied from the original sat around without being modified, and now ended up being removed instead of being properly integrated
SVN revision: 75052
Diffstat (limited to 'src/bin/e_bg.c')
-rw-r--r--src/bin/e_bg.c251
1 files changed, 40 insertions, 211 deletions
diff --git a/src/bin/e_bg.c b/src/bin/e_bg.c
index f6509b6..bc2bfbb 100644
--- a/src/bin/e_bg.c
+++ b/src/bin/e_bg.c
@@ -4,26 +4,12 @@
4static void _e_bg_signal(void *data, Evas_Object *obj, const char *emission, const char *source); 4static void _e_bg_signal(void *data, Evas_Object *obj, const char *emission, const char *source);
5static void _e_bg_event_bg_update_free(void *data, void *event); 5static void _e_bg_event_bg_update_free(void *data, void *event);
6 6
7static void _e_bg_image_import_dialog_done(void *data, const char *path, Eina_Bool ok, Eina_Bool external, int quality, E_Image_Import_Mode mode); 7static void _e_bg_handler_image_imported(const char *image_path, void *data);
8static void _e_bg_image_import_done(void *data, Eina_Bool ok, const char *image_path, const char *edje_path);
9static void _e_bg_handler_image_imported(void *data, const char *image_path);
10 8
11/* local subsystem globals */ 9/* local subsystem globals */
12EAPI int E_EVENT_BG_UPDATE = 0; 10EAPI int E_EVENT_BG_UPDATE = 0;
13static E_Fm2_Mime_Handler *bg_hdl = NULL; 11static E_Fm2_Mime_Handler *bg_hdl = NULL;
14 12
15struct _E_Bg_Image_Import_Handle
16{
17 struct
18 {
19 void (*func)(void *data, const char *edje_file);
20 void *data;
21 } cb;
22 E_Dialog *dia;
23 E_Util_Image_Import_Handle *importer;
24 Eina_Bool canceled : 1;
25};
26
27/* externally accessible functions */ 13/* externally accessible functions */
28EINTERN int 14EINTERN int
29e_bg_init(void) 15e_bg_init(void)
@@ -451,105 +437,6 @@ e_bg_update(void)
451 } 437 }
452} 438}
453 439
454static inline Eina_Bool
455_e_bg_file_edje_check(const char *path)
456{
457 const char *ext;
458 const size_t extlen = sizeof(".edj") - 1;
459 size_t len;
460
461 if (!path) return EINA_FALSE;
462
463 len = strlen(path);
464 if (len <= extlen) return EINA_FALSE;
465 ext = path + len - extlen;
466 return memcmp(ext, ".edj", extlen) == 0;
467}
468
469/**
470 * Go through process of importing an image as E background.
471 *
472 * This will go through process of importing an image as E
473 * background. It will ask fill/tile mode of the image, as well as
474 * quality to use.
475 *
476 * User can cancel operation at any time, and in this case callback is
477 * called with @c NULL as second parameter.
478 *
479 * The operation can be canceled by application/module as well using
480 * e_bg_image_import_cancel(). Even in this case the callback is called so user
481 * can free possibly allocated data.
482 *
483 * @param image_file source file to use, must be supported by Evas.
484 * @param cb callback to call when import process is done. The first
485 * argument is the given data, while the second is the path to
486 * the imported background file (edje) that can be used with
487 * e_bg_add() or e_bg_default_set(). Note that if @a edje_file
488 * is @c NULL, then the import process was canceled!
489 * This function is @b always called and after it returns
490 * E_Bg_Image_Import_Handle is deleted.
491 * @param data pointer to data to be given to callback.
492 *
493 * @return handle to the import process. It will die automatically
494 * when user cancels the process or when code automatically
495 * calls e_bg_image_import_cancel(). Before dying, callback
496 * will always be called.
497 */
498EAPI E_Bg_Image_Import_Handle *
499e_bg_image_import(const char *image_file, void (*cb)(void *data, const char *edje_file), const void *data)
500{
501 E_Bg_Image_Import_Handle *handle;
502
503 if (!image_file) return NULL;
504 if (!cb) return NULL;
505
506 handle = E_NEW(E_Bg_Image_Import_Handle, 1);
507 if (!handle) return NULL;
508 handle->cb.func = cb;
509 handle->cb.data = (void *)data;
510
511 handle->dia = e_util_image_import_settings_new
512 (image_file, _e_bg_image_import_dialog_done, handle);
513 if (!handle->dia)
514 {
515 free(handle);
516 return NULL;
517 }
518 e_dialog_show(handle->dia);
519
520 return handle;
521}
522
523/**
524 * Cancels previously started import process.
525 *
526 * Note that his handle will be deleted when process import, so don't
527 * call it after your callback is called!
528 */
529EAPI void
530e_bg_image_import_cancel(E_Bg_Image_Import_Handle *handle)
531{
532 if (!handle) return;
533
534 handle->canceled = EINA_TRUE;
535
536 if (handle->cb.func)
537 {
538 handle->cb.func(handle->cb.data, NULL);
539 handle->cb.func = NULL;
540 }
541 if (handle->dia)
542 {
543 e_object_del(E_OBJECT(handle->dia));
544 handle->dia = NULL;
545 }
546 else if (handle->importer)
547 {
548 e_util_image_import_cancel(handle->importer);
549 handle->importer = NULL;
550 }
551 E_FREE(handle);
552}
553 440
554/** 441/**
555 * Set background to image, as required in e_fm2_mime_handler_new() 442 * Set background to image, as required in e_fm2_mime_handler_new()
@@ -557,55 +444,57 @@ e_bg_image_import_cancel(E_Bg_Image_Import_Handle *handle)
557EAPI void 444EAPI void
558e_bg_handler_set(Evas_Object *obj __UNUSED__, const char *path, void *data __UNUSED__) 445e_bg_handler_set(Evas_Object *obj __UNUSED__, const char *path, void *data __UNUSED__)
559{ 446{
447 E_Container *con;
448 char buf[PATH_MAX];
449 int copy = 1;
450 E_Zone *zone;
451 E_Desk *desk;
452
560 if (!path) return; 453 if (!path) return;
561 454
562 if (_e_bg_file_edje_check(path)) 455 con = e_container_current_get(e_manager_current_get());
456 if (!eina_str_has_extension(path, "edj"))
563 { 457 {
564 char buf[PATH_MAX]; 458 e_import_config_dialog_show(con, path, (Ecore_End_Cb)_e_bg_handler_image_imported, NULL);
565 int copy = 1; 459 return;
566 460 }
567 E_Container *con = e_container_current_get(e_manager_current_get()); 461 zone = e_zone_current_get(con);
568 E_Zone *zone = e_zone_current_get(con); 462 desk = e_desk_current_get(zone);
569 E_Desk *desk = e_desk_current_get(zone);
570 463
571 /* if not in system dir or user dir, copy to user dir */ 464 /* if not in system dir or user dir, copy to user dir */
572 e_prefix_data_concat_static(buf, "data/backgrounds"); 465 e_prefix_data_concat_static(buf, "data/backgrounds");
466 if (!strncmp(buf, path, strlen(buf)))
467 copy = 0;
468 if (copy)
469 {
470 e_user_dir_concat_static(buf, "backgrounds");
573 if (!strncmp(buf, path, strlen(buf))) 471 if (!strncmp(buf, path, strlen(buf)))
574 copy = 0; 472 copy = 0;
575 if (copy) 473 }
576 { 474 if (copy)
577 e_user_dir_concat_static(buf, "backgrounds"); 475 {
578 if (!strncmp(buf, path, strlen(buf))) 476 const char *file;
579 copy = 0; 477 char *name;
580 }
581 if (copy)
582 {
583 const char *file;
584 char *name;
585 478
586 file = ecore_file_file_get(path); 479 file = ecore_file_file_get(path);
587 name = ecore_file_strip_ext(file); 480 name = ecore_file_strip_ext(file);
588 481
589 e_user_dir_snprintf(buf, sizeof(buf), "backgrounds/%s-%f.edj", name, ecore_time_unix_get()); 482 e_user_dir_snprintf(buf, sizeof(buf), "backgrounds/%s-%f.edj", name, ecore_time_unix_get());
590 free(name); 483 free(name);
591 484
592 if (!ecore_file_exists(buf)) 485 if (!ecore_file_exists(buf))
593 { 486 {
594 ecore_file_cp(path, buf); 487 ecore_file_cp(path, buf);
595 e_bg_add(con->num, zone->num, desk->x, desk->y, buf); 488 e_bg_add(con->num, zone->num, desk->x, desk->y, buf);
596 }
597 else
598 e_bg_add(con->num, zone->num, desk->x, desk->y, path);
599 } 489 }
600 else 490 else
601 e_bg_add(con->num, zone->num, desk->x, desk->y, path); 491 e_bg_add(con->num, zone->num, desk->x, desk->y, path);
602
603 e_bg_update();
604 e_config_save_queue();
605 return;
606 } 492 }
493 else
494 e_bg_add(con->num, zone->num, desk->x, desk->y, path);
607 495
608 e_bg_image_import(path, _e_bg_handler_image_imported, NULL); 496 e_bg_update();
497 e_config_save_queue();
609} 498}
610 499
611/** 500/**
@@ -625,7 +514,7 @@ e_bg_handler_test(Evas_Object *obj __UNUSED__, const char *path, void *data __UN
625{ 514{
626 if (!path) return 0; 515 if (!path) return 0;
627 516
628 if (_e_bg_file_edje_check(path)) 517 if (eina_str_has_extension(path, "edj"))
629 { 518 {
630 if (edje_file_group_exists(path, "e/desktop/background")) return 1; 519 if (edje_file_group_exists(path, "e/desktop/background")) return 1;
631 return 0; 520 return 0;
@@ -665,72 +554,12 @@ _e_bg_event_bg_update_free(void *data __UNUSED__, void *event)
665} 554}
666 555
667static void 556static void
668_e_bg_image_import_dialog_done(void *data, const char *path, Eina_Bool ok, Eina_Bool external, int quality, E_Image_Import_Mode mode) 557_e_bg_handler_image_imported(const char *image_path, void *data __UNUSED__)
669{
670 E_Bg_Image_Import_Handle *handle = data;
671 const char *file;
672 char *name;
673 char buf[PATH_MAX];
674 size_t used, off;
675 unsigned num;
676
677 if (!ok) goto aborted;
678
679 file = ecore_file_file_get(path);
680 if (!file) goto aborted;
681 name = ecore_file_strip_ext(file);
682 if (!name) goto aborted;
683
684 used = e_user_dir_snprintf(buf, sizeof(buf), "backgrounds/%s.edj", name);
685 free(name);
686 if (used >= sizeof(buf)) goto aborted;
687
688 off = used - (sizeof(".edj") - 1);
689
690 for (num = 0; ecore_file_exists(buf); num++)
691 snprintf(buf + off, sizeof(buf) - off, "-%u.edj", num);
692
693 handle->importer = e_util_image_import
694 (path, buf, "e/desktop/background", external, quality, mode,
695 _e_bg_image_import_done, handle);
696 if (!handle->importer) goto aborted;
697
698 return;
699
700aborted:
701 if (handle->cb.func)
702 {
703 handle->cb.func(handle->cb.data, NULL);
704 handle->cb.func = NULL;
705 }
706 if (!handle->canceled) E_FREE(handle);
707}
708
709static void
710_e_bg_image_import_done(void *data, Eina_Bool ok, const char *image_path __UNUSED__, const char *edje_path)
711{
712 E_Bg_Image_Import_Handle *handle = data;
713
714 if (!ok) edje_path = NULL;
715
716 if (handle->cb.func)
717 {
718 handle->cb.func(handle->cb.data, edje_path);
719 handle->cb.func = NULL;
720 }
721
722 if (!handle->canceled) E_FREE(handle);
723}
724
725static void
726_e_bg_handler_image_imported(void *data __UNUSED__, const char *image_path)
727{ 558{
728 E_Container *con = e_container_current_get(e_manager_current_get()); 559 E_Container *con = e_container_current_get(e_manager_current_get());
729 E_Zone *zone = e_zone_current_get(con); 560 E_Zone *zone = e_zone_current_get(con);
730 E_Desk *desk = e_desk_current_get(zone); 561 E_Desk *desk = e_desk_current_get(zone);
731 562
732 if (!image_path) return;
733
734 e_bg_add(con->num, zone->num, desk->x, desk->y, image_path); 563 e_bg_add(con->num, zone->num, desk->x, desk->y, image_path);
735 e_bg_update(); 564 e_bg_update();
736 e_config_save_queue(); 565 e_config_save_queue();