summaryrefslogtreecommitdiff
path: root/src/lib/efreet/efreet_menu.c
diff options
context:
space:
mode:
authorSebastian Dransfeld <sebastian.dransfeld@sintef.no>2013-06-20 11:56:15 +0200
committerSebastian Dransfeld <sebastian.dransfeld@sintef.no>2013-06-20 11:56:46 +0200
commit5b3cd4cde17731a71020f48b13e2e9dab511e294 (patch)
treed0184ce8548446dd3a93eed37e010443d5c2996b /src/lib/efreet/efreet_menu.c
parent0c317eaca288a546124677247952f3962a7117fb (diff)
efreet: Add async menu parsing
Diffstat (limited to 'src/lib/efreet/efreet_menu.c')
-rw-r--r--src/lib/efreet/efreet_menu.c129
1 files changed, 101 insertions, 28 deletions
diff --git a/src/lib/efreet/efreet_menu.c b/src/lib/efreet/efreet_menu.c
index dc0389985b..d4bbeb6a4d 100644
--- a/src/lib/efreet/efreet_menu.c
+++ b/src/lib/efreet/efreet_menu.c
@@ -2,6 +2,7 @@
2# include <config.h> 2# include <config.h>
3#endif 3#endif
4 4
5#include <Ecore.h>
5#include <Ecore_File.h> 6#include <Ecore_File.h>
6 7
7/* define macros and variable for using the eina logging system */ 8/* define macros and variable for using the eina logging system */
@@ -154,6 +155,14 @@ struct Efreet_Menu_Desktop
154 unsigned char allocated:1; /**< If this desktop has been allocated */ 155 unsigned char allocated:1; /**< If this desktop has been allocated */
155}; 156};
156 157
158typedef struct Efreet_Menu_Async Efreet_Menu_Async;
159
160struct Efreet_Menu_Async
161{
162 Efreet_Menu_Cb func;
163 Eina_Stringshare *path;
164};
165
157static const char *efreet_menu_prefix = NULL; /**< The $XDG_MENU_PREFIX env var */ 166static const char *efreet_menu_prefix = NULL; /**< The $XDG_MENU_PREFIX env var */
158Eina_List *efreet_menu_kde_legacy_dirs = NULL; /**< The directories to use for KDELegacy entries */ 167Eina_List *efreet_menu_kde_legacy_dirs = NULL; /**< The directories to use for KDELegacy entries */
159static const char *efreet_tag_menu = NULL; 168static const char *efreet_tag_menu = NULL;
@@ -164,6 +173,8 @@ static Eina_Hash *efreet_menu_filter_cbs = NULL;
164static Eina_Hash *efreet_menu_move_cbs = NULL; 173static Eina_Hash *efreet_menu_move_cbs = NULL;
165static Eina_Hash *efreet_menu_layout_cbs = NULL; 174static Eina_Hash *efreet_menu_layout_cbs = NULL;
166 175
176static Efreet_Menu *efreet_menu_internal_get(Efreet_Menu_Cb func);
177
167static Efreet_Menu_Internal *efreet_menu_by_name_find(Efreet_Menu_Internal *internal, 178static Efreet_Menu_Internal *efreet_menu_by_name_find(Efreet_Menu_Internal *internal,
168 const char *name, 179 const char *name,
169 Efreet_Menu_Internal **parent); 180 Efreet_Menu_Internal **parent);
@@ -305,6 +316,8 @@ static void efreet_menu_path_set(Efreet_Menu_Internal *internal, const char *pat
305static int efreet_menu_save_menu(Efreet_Menu *menu, FILE *f, int indent); 316static int efreet_menu_save_menu(Efreet_Menu *menu, FILE *f, int indent);
306static int efreet_menu_save_indent(FILE *f, int indent); 317static int efreet_menu_save_indent(FILE *f, int indent);
307 318
319static void _efreet_menu_async_parse_cb(void *data, Ecore_Thread *thread);
320
308int 321int
309efreet_menu_init(void) 322efreet_menu_init(void)
310{ 323{
@@ -507,39 +520,27 @@ efreet_menu_file_set(const char *file)
507 if (file) efreet_menu_file = eina_stringshare_add(file); 520 if (file) efreet_menu_file = eina_stringshare_add(file);
508} 521}
509 522
523EAPI void
524efreet_menu_async_get(Efreet_Menu_Cb func)
525{
526 efreet_menu_internal_get(func);
527}
528
510EAPI Efreet_Menu * 529EAPI Efreet_Menu *
511efreet_menu_get(void) 530efreet_menu_get(void)
512{ 531{
513 char menu[PATH_MAX]; 532 return efreet_menu_internal_get(NULL);
514 const char *dir; 533}
515 Eina_List *config_dirs, *l;
516
517#ifndef STRICT_SPEC
518 /* prefer user set menu */
519 if (efreet_menu_file)
520 {
521 if (ecore_file_exists(efreet_menu_file))
522 return efreet_menu_parse(efreet_menu_file);
523 }
524#endif
525
526 /* check the users config directory first */
527 snprintf(menu, sizeof(menu), "%s/menus/%sapplications.menu",
528 efreet_config_home_get(), efreet_menu_prefix);
529 if (ecore_file_exists(menu))
530 return efreet_menu_parse(menu);
531 534
532 /* fallback to the XDG_CONFIG_DIRS */ 535EAPI void
533 config_dirs = efreet_config_dirs_get(); 536efreet_menu_async_parse(const char *path, Efreet_Menu_Cb func)
534 EINA_LIST_FOREACH(config_dirs, l, dir) 537{
535 { 538 Efreet_Menu_Async *async;
536 snprintf(menu, sizeof(menu), "%s/menus/%sapplications.menu",
537 dir, efreet_menu_prefix);
538 if (ecore_file_exists(menu))
539 return efreet_menu_parse(menu);
540 }
541 539
542 return NULL; 540 async = NEW(Efreet_Menu_Async, 1);
541 async->func = func;
542 async->path = eina_stringshare_add(path);
543 ecore_thread_run(_efreet_menu_async_parse_cb, NULL, NULL, async);
543} 544}
544 545
545EAPI Efreet_Menu * 546EAPI Efreet_Menu *
@@ -720,6 +721,65 @@ efreet_menu_dump(Efreet_Menu *menu, const char *indent)
720 } 721 }
721} 722}
722 723
724static Efreet_Menu *
725efreet_menu_internal_get(Efreet_Menu_Cb func)
726{
727 char menu[PATH_MAX];
728 const char *dir;
729 Eina_List *config_dirs, *l;
730
731#ifndef STRICT_SPEC
732 /* prefer user set menu */
733 if (efreet_menu_file)
734 {
735 if (ecore_file_exists(efreet_menu_file))
736 {
737 if (func)
738 {
739 efreet_menu_async_parse(efreet_menu_file, func);
740 return NULL;
741 }
742 else
743 return efreet_menu_parse(efreet_menu_file);
744 }
745 }
746#endif
747
748 /* check the users config directory first */
749 snprintf(menu, sizeof(menu), "%s/menus/%sapplications.menu",
750 efreet_config_home_get(), efreet_menu_prefix);
751 if (ecore_file_exists(menu))
752 {
753 if (func)
754 {
755 efreet_menu_async_parse(menu, func);
756 return NULL;
757 }
758 else
759 return efreet_menu_parse(menu);
760 }
761
762 /* fallback to the XDG_CONFIG_DIRS */
763 config_dirs = efreet_config_dirs_get();
764 EINA_LIST_FOREACH(config_dirs, l, dir)
765 {
766 snprintf(menu, sizeof(menu), "%s/menus/%sapplications.menu",
767 dir, efreet_menu_prefix);
768 if (ecore_file_exists(menu))
769 {
770 if (func)
771 {
772 efreet_menu_async_parse(menu, func);
773 return NULL;
774 }
775 else
776 return efreet_menu_parse(menu);
777 }
778 }
779
780 return NULL;
781}
782
723/** 783/**
724 * @internal 784 * @internal
725 * @return Returns a new Efreet_Menu_Internal struct 785 * @return Returns a new Efreet_Menu_Internal struct
@@ -3798,3 +3858,16 @@ efreet_menu_save_indent(FILE *f, int indent)
3798 return 1; 3858 return 1;
3799} 3859}
3800 3860
3861static void
3862_efreet_menu_async_parse_cb(void *data, Ecore_Thread *thread EINA_UNUSED)
3863{
3864 Efreet_Menu_Async *async = data;
3865 Efreet_Menu *menu;
3866
3867 menu = efreet_menu_parse(async->path);
3868 ecore_thread_main_loop_begin();
3869 async->func(menu);
3870 ecore_thread_main_loop_end();
3871 eina_stringshare_del(async->path);
3872 free(async);
3873}