4 #define MOD_CONFIG_FILE_EPOCH 0x0001
5 #define MOD_CONFIG_FILE_GENERATION 0x009d
6 #define MOD_CONFIG_FILE_VERSION \
7 ((MOD_CONFIG_FILE_EPOCH << 16) | MOD_CONFIG_FILE_GENERATION)
9 // FIXME clear cache on .desktop chage event
12 * #define DBG(...) ERR(__VA_ARGS__) */
16 typedef struct _Plugin Plugin;
17 typedef struct _Module_Config Module_Config;
18 typedef struct _E_Exe E_Exe;
19 typedef struct _E_Exe_List E_Exe_List;
31 Evry_Item_App *command;
47 const char *cmd_terminal;
54 static const Evry_API *evry = NULL;
55 static Evry_Module *evry_module = NULL;
56 static Eina_List *handlers = NULL;
58 static Module_Config *_conf;
59 static char _module_icon[] = "system-run";
60 static Eina_List *_plugins = NULL;
61 static Eina_List *_actions = NULL;
62 static Evry_Item *_act_open_with = NULL;
63 static Eina_List *exe_path = NULL;
64 static Ecore_Idler *exe_scan_idler = NULL;
65 static E_Config_DD *exelist_exe_edd = NULL;
66 static E_Config_DD *exelist_edd = NULL;
67 static DIR *exe_dir = NULL;
68 static Eina_List *exe_list = NULL;
69 static Eina_List *exe_list2 = NULL;
70 static Eina_List *apps_cache = NULL;
71 static void _scan_executables();
73 /***************************************************************************/
75 static void _hash_free(void *data)
82 _icon_get(Evry_Item *it, Evas *e)
85 Evas_Object *o = NULL;
87 if (app->desktop && app->desktop->icon)
89 if (app->desktop->icon[0] == '/')
92 e_icon_preload_set(o, 1);
94 if (!e_icon_file_set(o, app->desktop->icon))
102 o = evry->icon_theme_get(app->desktop->icon, e);
105 o = e_util_desktop_icon_add(app->desktop, 128, e);
109 o = evry->icon_theme_get("system-run", e);
115 _exec_open_file_action(Evry_Action *act)
117 return evry->util_exec_app(EVRY_ITEM(act), act->it1.item);
121 _item_free(Evry_Item *item)
126 efreet_desktop_free(app->desktop);
128 eina_stringshare_del(app->file);
133 static Evry_Item_App *
134 _item_new(Plugin *p, const char *label, const char *id)
138 app = EVRY_ITEM_NEW(Evry_Item_App, p, label, _icon_get, _item_free);
139 EVRY_ACTN(app)->action = &_exec_open_file_action;
140 EVRY_ACTN(app)->it1.type = EVRY_TYPE_FILE;
141 EVRY_ITEM(app)->id = eina_stringshare_add(id);
143 eina_hash_add(p->added, id, app);
145 EVRY_ACTN(app)->remember_context = EINA_TRUE;
146 EVRY_ITEM(app)->subtype = EVRY_TYPE_ACTION;
152 _cb_sort(const void *data1, const void *data2)
154 const Evry_Item *it1 = data1;
155 const Evry_Item *it2 = data2;
157 if (it1->usage && it2->usage)
158 return (it1->usage > it2->usage ? -1 : 1);
159 if (it1->usage && !it2->usage)
161 if (it2->usage && !it1->usage)
164 if (it1->fuzzy_match || it2->fuzzy_match)
166 if (it1->fuzzy_match && !it2->fuzzy_match)
169 if (!it1->fuzzy_match && it2->fuzzy_match)
172 if (it1->fuzzy_match - it2->fuzzy_match)
173 return (it1->fuzzy_match - it2->fuzzy_match);
176 return strcasecmp(it1->label, it2->label);
179 /***************************************************************************/
181 static Evry_Item_App *
182 _item_exe_add(Plugin *p, const char *exe, int match)
184 Evry_Item_App *app = NULL;
186 if ((app = eina_hash_find(p->added, exe)))
188 if (eina_list_data_find_list(p->base.items, app))
194 app = _item_new(p, ecore_file_file_get(exe), exe);
195 app->file = eina_stringshare_ref(EVRY_ITEM(app)->id);
198 EVRY_ITEM(app)->fuzzy_match = match;
199 EVRY_PLUGIN_ITEM_APPEND(p, app);
205 _hist_exe_get_cb(const Eina_Hash *hash __UNUSED__, const void *key, void *data, void *fdata)
207 History_Entry *he = data;
213 const char *exe = key;
215 EINA_LIST_FOREACH(he->items, l, hi)
219 if (strcmp(hi->plugin, EVRY_PLUGIN(p)->name))
224 app = _item_exe_add(p, exe, 0);
226 else if ((match = evry->fuzzy_match(exe, p->input)))
228 app = _item_exe_add(p, exe, match);
233 EVRY_ITEM(app)->hi = hi;
234 evry->history_item_usage_set(EVRY_ITEM(app), p->input, NULL);
244 _fetch_exe(Evry_Plugin *plugin, const char *input)
246 GET_PLUGIN(p, plugin);
250 unsigned int len = (input ? strlen(input) : 0);
252 const char *tmp, *file = NULL;
253 unsigned int min = 0, cnt = 0, end = len, tmp_len;
254 unsigned int query = (len >= (unsigned int)plugin->config->min_query);
255 EVRY_PLUGIN_ITEMS_CLEAR(p);
259 ht = evry->history_types_get(EVRY_TYPE_APP);
260 if (ht) eina_hash_foreach(ht->types, _hist_exe_get_cb, p);
264 if ((tmp = strchr(input, ' ')))
267 if ((!exe_list) && (!exe_scan_idler))
270 EINA_LIST_FOREACH(exe_list, l, tmp)
272 tmp_len = strlen(tmp);
274 if ((end < len) && (tmp_len > end))
277 if (!strncmp(input, tmp, end))
279 if (query && (cnt++ < 50) && (len != tmp_len))
280 _item_exe_add(p, tmp, 15);
282 if ((!min) || (tmp_len < min))
287 if ((!query) && (tmp_len == len))
294 GET_ITEM(it, p->command);
296 if (strlen(file) < len)
299 EVRY_ITEM_LABEL_SET(it, file);
300 IF_RELEASE(p->command->file);
301 p->command->file = eina_stringshare_ref(it->label);
302 it->fuzzy_match = 11; // prefix match
303 EVRY_PLUGIN_ITEM_APPEND(p, it);
304 evry->item_changed(it, 0, 0);
308 EINA_LIST_FOREACH(plugin->items, l, it)
310 evry->history_item_usage_set(it, input, NULL);
311 if (input && (it->usage > max) && !strncmp(input, it->label, len))
314 EVRY_ITEM(p->command)->usage = (max * 2.0);
316 EVRY_PLUGIN_ITEMS_SORT(p, _cb_sort);
318 return !!(plugin->items);
322 _begin_exe(Evry_Plugin *plugin, const Evry_Item *item)
327 if (item && (item != _act_open_with))
330 EVRY_PLUGIN_INSTANCE(p, plugin)
332 p->added = eina_hash_string_small_new(_hash_free);
334 app = EVRY_ITEM_NEW(Evry_Item_App, p, NULL, _icon_get, _item_free);
335 EVRY_ACTN(app)->action = &_exec_open_file_action;
336 EVRY_ACTN(app)->remember_context = EINA_TRUE;
337 EVRY_ITEM(app)->subtype = EVRY_TYPE_ACTION;
340 return EVRY_PLUGIN(p);
344 _finish_exe(Evry_Plugin *plugin)
346 GET_PLUGIN(p, plugin);
349 EVRY_PLUGIN_ITEMS_CLEAR(p);
350 EVRY_ITEM_FREE(p->command);
353 eina_hash_free(p->added);
360 EINA_LIST_FREE(exe_path, str)
365 ecore_idler_del(exe_scan_idler);
366 exe_scan_idler = NULL;
368 EINA_LIST_FREE(exe_list, str)
370 EINA_LIST_FREE(exe_list2, str)
376 /***************************************************************************/
379 _item_desktop_add(Plugin *p, Efreet_Desktop *desktop, int match)
381 Evry_Item_App *app = NULL;
383 if ((app = eina_hash_find(p->added, desktop->exec)))
385 if (eina_list_data_find_list(p->base.items, app))
391 app = _item_new(p, desktop->name, desktop->exec);
392 efreet_desktop_ref(desktop);
393 app->desktop = desktop;
395 if (desktop->comment)
397 EVRY_ITEM_DETAIL_SET(app, desktop->comment);
399 else if (desktop->generic_name)
401 EVRY_ITEM_DETAIL_SET(app, desktop->generic_name);
405 EVRY_ITEM(app)->fuzzy_match = match;
406 EVRY_PLUGIN_ITEM_APPEND(p, app);
410 _desktop_list_add(Plugin *p, Eina_List *apps, const char *input)
412 Efreet_Desktop *desktop;
415 const char *exec, *end;
418 EINA_LIST_FOREACH(apps, l, desktop)
420 if (eina_list_count(p->base.items) >= MAX_ITEMS) break;
426 /* strip path and parameter */
427 exec = ecore_file_file_get(desktop->exec);
428 if ((exec) && (end = strchr(exec, '%')) &&
429 ((end - exec) - 1 > 0))
431 strncpy(buf, exec, (end - exec) - 1);
432 buf[(end - exec) - 1] = '\0';
433 m1 = evry->fuzzy_match(buf, input);
437 m1 = evry->fuzzy_match(exec, input);
440 m2 = evry->fuzzy_match(desktop->name, input);
442 if (!m1 || (m2 && m2 < m1)) m1 = m2;
445 if (!input || m1) _item_desktop_add(p, desktop, m1);
450 _desktop_list_get(void)
452 Eina_List *apps = NULL;
457 apps = efreet_util_desktop_name_glob_list("*");
459 /* remove screensaver */
460 cat_ss = efreet_util_desktop_category_list("Screensaver");
461 EINA_LIST_FOREACH(cat_ss, l, d)
463 if ((ll = eina_list_data_find_list(apps, d)))
465 efreet_desktop_free(d);
466 apps = eina_list_remove_list(apps, ll);
468 efreet_desktop_free(d);
475 _hist_items_get_cb(const Eina_Hash *hash __UNUSED__, const void *key, void *data, void *fdata)
477 History_Entry *he = data;
482 const char *exec = key;
484 EINA_LIST_FOREACH(he->items, l, hi)
491 if (strcmp(hi->plugin, EVRY_PLUGIN(p)->name))
494 EINA_LIST_FOREACH(apps_cache, ll, d)
495 if (d->exec && !strcmp(d->exec, exec)) break;
500 p->apps_all = _desktop_list_get();
502 EINA_LIST_FOREACH(p->apps_all, ll, d)
503 if (d->exec && !strcmp(d->exec, exec)) break;
507 efreet_desktop_ref(d);
508 apps_cache = eina_list_append(apps_cache, d);
512 /* remove from history */
513 /* DBG("no desktop: %s", exec);
514 * hi->transient = 1; */
520 DBG("app not found %s", exec);
524 p->apps_hist = eina_list_append(p->apps_hist, d);
532 _begin(Evry_Plugin *plugin, const Evry_Item *item)
536 if (item && (item != _act_open_with))
539 EVRY_PLUGIN_INSTANCE(p, plugin)
540 p->added = eina_hash_string_small_new(_hash_free);
542 return EVRY_PLUGIN(p);
546 _finish(Evry_Plugin *plugin)
548 GET_PLUGIN(p, plugin);
549 Efreet_Desktop *desktop;
551 EVRY_PLUGIN_ITEMS_CLEAR(p);
554 eina_hash_free(p->added);
556 EINA_LIST_FREE(p->apps_all, desktop)
557 efreet_desktop_free(desktop);
559 EINA_LIST_FREE(p->apps_hist, desktop);
561 EINA_LIST_FREE(p->apps_mime, desktop)
562 efreet_desktop_free(desktop);
568 _fetch(Evry_Plugin *plugin, const char *input)
570 GET_PLUGIN(p, plugin);
575 EVRY_PLUGIN_ITEMS_CLEAR(p);
580 p->apps_all = _desktop_list_get();
582 _desktop_list_add(p, p->apps_all, input);
586 _desktop_list_add(p, p->apps_mime, input);
589 if (!input && !(plugin->items))
593 ht = evry->history_types_get(EVRY_TYPE_APP);
594 if (ht) eina_hash_foreach(ht->types, _hist_items_get_cb, p);
597 _desktop_list_add(p, p->apps_hist, NULL);
600 EINA_LIST_FOREACH(plugin->items, l, it)
601 evry->history_item_usage_set(it, input, NULL);
603 EVRY_PLUGIN_ITEMS_SORT(p, _cb_sort);
605 return !!(plugin->items);
608 /***************************************************************************/
611 _begin_mime(Evry_Plugin *plugin, const Evry_Item *item)
616 const char *path = NULL;
619 if (CHECK_TYPE(item, EVRY_TYPE_ACTION))
621 GET_ACTION(act, item);
622 GET_FILE(file, act->it1.item);
624 if (!evry->file_path_get(file))
630 else if (CHECK_TYPE(item, EVRY_TYPE_FILE))
632 GET_FILE(file, item);
634 if (!evry->file_path_get(file))
645 if (!path || !mime || !(mime = efreet_mime_type_get(path)))
648 EVRY_PLUGIN_INSTANCE(p, plugin);
650 p->apps_mime = efreet_util_desktop_mime_list(mime);
652 if (strcmp(mime, "text/plain") && (!strncmp(mime, "text/", 5)))
654 l = efreet_util_desktop_mime_list("text/plain");
658 if (!eina_list_data_find_list(p->apps_mime, d))
659 p->apps_mime = eina_list_append(p->apps_mime, d);
661 efreet_desktop_free(d);
665 if (item->browseable && strcmp(mime, "x-directory/normal"))
667 l = efreet_util_desktop_mime_list("x-directory/normal");
671 if (!eina_list_data_find_list(p->apps_mime, d))
672 p->apps_mime = eina_list_append(p->apps_mime, d);
674 efreet_desktop_free(d);
678 if ((d = e_exehist_mime_desktop_get(mime)))
680 if ((l = eina_list_data_find_list(p->apps_mime, d)))
682 p->apps_mime = eina_list_promote_list(p->apps_mime, l);
683 efreet_desktop_free(d);
687 p->apps_mime = eina_list_prepend(p->apps_mime, d);
691 p->added = eina_hash_string_small_new(_hash_free);
693 return EVRY_PLUGIN(p);
697 _finish_mime(Evry_Plugin *plugin)
699 GET_PLUGIN(p, plugin);
700 Efreet_Desktop *desktop;
702 EVRY_PLUGIN_ITEMS_CLEAR(p);
705 eina_hash_free(p->added);
707 EINA_LIST_FREE(p->apps_mime, desktop)
708 efreet_desktop_free(desktop);
714 _fetch_mime(Evry_Plugin *plugin, const char *input)
716 GET_PLUGIN(p, plugin);
720 EVRY_PLUGIN_ITEMS_CLEAR(p);
722 /* add apps for a given mimetype */
723 _desktop_list_add(p, p->apps_mime, input);
725 EINA_LIST_FOREACH(plugin->items, l, it)
726 evry->history_item_usage_set(it, input, NULL);
729 EVRY_PLUGIN_ITEMS_SORT(p, _cb_sort);
736 _complete(Evry_Plugin *plugin __UNUSED__, const Evry_Item *it, char **input)
744 char *space = strchr(app->desktop->exec, ' ');
746 snprintf(buf, sizeof(buf), "%s", app->desktop->exec);
748 buf[1 + space - app->desktop->exec] = '\0';
751 snprintf(buf, sizeof(buf), "%s", app->file);
753 *input = strdup(buf);
755 return EVRY_COMPLETE_INPUT;
758 /***************************************************************************/
761 _exec_app_check_item(Evry_Action *act __UNUSED__, const Evry_Item *it __UNUSED__)
767 _exec_app_action(Evry_Action *act)
769 return evry->util_exec_app(act->it1.item, act->it2.item);
773 _exec_file_action(Evry_Action *act)
775 return evry->util_exec_app(act->it2.item, act->it1.item);
779 _exec_term_action(Evry_Action *act)
781 GET_APP(app, act->it1.item);
785 char *escaped = ecore_file_escape_name(app->file);
787 tmp = E_NEW(Evry_Item_App, 1);
788 snprintf(buf, sizeof(buf), "%s -hold -e %s",
790 (escaped ? escaped : app->file));
793 ret = evry->util_exec_app(EVRY_ITEM(tmp), NULL);
802 _exec_term_check_item(Evry_Action *act __UNUSED__, const Evry_Item *it)
813 _exec_sudo_action(Evry_Action *act)
815 GET_APP(app, act->it1.item);
820 tmp = E_NEW(Evry_Item_App, 1);
821 snprintf(buf, sizeof(buf), "%s %s",
823 (app->desktop ? app->desktop->exec : app->file));
826 ret = evry->util_exec_app(EVRY_ITEM(tmp), NULL);
834 _edit_app_check_item(Evry_Action *act __UNUSED__, const Evry_Item *it)
845 _edit_app_action(Evry_Action *act)
847 Efreet_Desktop *desktop;
848 GET_APP(app, act->it1.item);
851 desktop = app->desktop;
855 snprintf(buf, 128, "%s/.local/share/applications/%s.desktop",
856 e_user_homedir_get(), app->file);
857 desktop = efreet_desktop_empty_new(eina_stringshare_add(buf));
858 /* XXX check if this is freed by efreet*/
859 desktop->exec = strdup(app->file);
862 e_desktop_edit(e_container_current_get(e_manager_current_get()), desktop);
868 _new_app_check_item(Evry_Action *act __UNUSED__, const Evry_Item *it)
875 if (app->file && strlen(app->file) > 0)
882 _new_app_action(Evry_Action *act)
887 Efreet_Desktop *desktop;
890 GET_APP(app, act->it1.item);
893 name = strdup(app->desktop->name);
895 /* TODO replace '/' and remove other special characters */
896 name = strdup(app->file);
898 if ((end = strchr(name, ' ')))
899 name[end - name] = '\0';
901 for (i = 0; i < 10; i++)
903 snprintf(buf, 4096, "%s/.local/share/applications/%s-%d.desktop",
904 e_user_homedir_get(), name, i);
905 if (ecore_file_exists(buf))
914 if (strlen(buf) == 0)
919 desktop = efreet_desktop_empty_new(buf);
920 desktop->exec = (char *)eina_stringshare_add(app->file);
924 desktop = efreet_desktop_empty_new(buf);
925 if (app->desktop->name)
926 desktop->name = strdup(app->desktop->name);
927 if (app->desktop->comment)
928 desktop->comment = strdup(app->desktop->comment);
929 if (app->desktop->generic_name)
930 desktop->generic_name = strdup(app->desktop->generic_name);
931 if (app->desktop->generic_name)
932 desktop->generic_name = strdup(app->desktop->generic_name);
933 if (app->desktop->exec)
934 desktop->exec = strdup(app->desktop->exec);
935 if (app->desktop->icon)
936 desktop->icon = strdup(app->desktop->icon);
937 if (app->desktop->mime_types)
938 desktop->mime_types = eina_list_clone(app->desktop->mime_types);
941 e_desktop_edit(e_container_current_get(e_manager_current_get()), desktop);
947 _open_term_action(Evry_Action *act)
949 GET_FILE(file, act->it1.item);
955 if (!(evry->file_path_get(file)))
958 if (IS_BROWSEABLE(file))
959 dir = strdup(file->path);
961 dir = ecore_file_dir_get(file->path);
965 if (!getcwd(cwd, sizeof(cwd)))
970 tmp = E_NEW(Evry_Item_App, 1);
971 tmp->file = _conf->cmd_terminal;
973 ret = evry->util_exec_app(EVRY_ITEM(tmp), NULL);
984 _check_executable(Evry_Action *act __UNUSED__, const Evry_Item *it)
988 return ecore_file_can_exec(evry->file_path_get(file));
992 _run_executable(Evry_Action *act)
994 GET_FILE(file, act->it1.item);
996 e_exec(e_util_zone_current_get(e_manager_current_get()), NULL, file->path, NULL, NULL);
1001 /***************************************************************************/
1003 _desktop_cache_update(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
1007 EINA_LIST_FREE(apps_cache, d)
1008 efreet_desktop_unref(d);
1014 _plugins_init(const Evry_API *api)
1021 if (evry_module->active)
1026 if (!evry->api_version_check(EVRY_API_VERSION))
1029 p = EVRY_PLUGIN_NEW(Plugin, N_("Applications"),
1030 _module_icon, EVRY_TYPE_APP,
1031 _begin, _finish, _fetch, NULL);
1032 p->complete = &_complete;
1033 p->config_path = "extensions/everything-apps";
1034 evry->plugin_register(p, EVRY_PLUGIN_SUBJECT, 1);
1035 _plugins = eina_list_append(_plugins, p);
1038 p = EVRY_PLUGIN_NEW(Plugin, N_("Exebuf"),
1039 _module_icon, EVRY_TYPE_APP,
1040 _begin_exe, _finish_exe, _fetch_exe, NULL);
1041 p->complete = &_complete;
1042 p->config_path = "extensions/everything-apps";
1043 _plugins = eina_list_append(_plugins, p);
1044 if (evry->plugin_register(p, EVRY_PLUGIN_SUBJECT, 3))
1045 p->config->min_query = 5;
1047 p = EVRY_PLUGIN_NEW(Plugin, N_("Applications"),
1048 _module_icon, EVRY_TYPE_APP,
1049 _begin_mime, _finish, _fetch, NULL);
1050 p->complete = &_complete;
1051 p->config_path = "extensions/everything-apps";
1052 evry->plugin_register(p, EVRY_PLUGIN_OBJECT, 1);
1053 _plugins = eina_list_append(_plugins, p);
1055 p = EVRY_PLUGIN_NEW(Plugin, N_("Open With..."),
1056 _module_icon, EVRY_TYPE_APP,
1057 _begin_mime, _finish_mime, _fetch_mime, NULL);
1058 p->config_path = "extensions/everything-apps";
1059 evry->plugin_register(p, EVRY_PLUGIN_ACTION, 1);
1060 _plugins = eina_list_append(_plugins, p);
1062 act = EVRY_ACTION_NEW(N_("Launch"),
1066 _exec_app_check_item);
1067 _actions = eina_list_append(_actions, act);
1069 act = EVRY_ACTION_NEW(N_("Open File..."),
1070 EVRY_TYPE_APP, EVRY_TYPE_FILE,
1073 _exec_app_check_item);
1074 _actions = eina_list_append(_actions, act);
1076 act = EVRY_ACTION_NEW(N_("Run in Terminal"),
1080 _exec_term_check_item);
1081 _actions = eina_list_append(_actions, act);
1083 act = EVRY_ACTION_NEW(N_("Edit Application Entry"),
1085 "everything-launch",
1087 _edit_app_check_item);
1088 _actions = eina_list_append(_actions, act);
1090 act = EVRY_ACTION_NEW(N_("New Application Entry"),
1092 "everything-launch",
1094 _new_app_check_item);
1095 _actions = eina_list_append(_actions, act);
1097 act = EVRY_ACTION_NEW(N_("Run with Sudo"),
1100 _exec_sudo_action, NULL);
1101 _actions = eina_list_append(_actions, act);
1103 act = EVRY_ACTION_NEW(N_("Open with..."),
1104 EVRY_TYPE_FILE, EVRY_TYPE_APP,
1105 "everything-launch",
1106 _exec_file_action, NULL);
1107 _act_open_with = EVRY_ITEM(act);
1108 _actions = eina_list_append(_actions, act);
1110 act = EVRY_ACTION_NEW(N_("Open Terminal here"),
1113 _open_term_action, NULL);
1114 _actions = eina_list_append(_actions, act);
1116 act = EVRY_ACTION_NEW(N_("Run Executable"),
1121 _actions = eina_list_append(_actions, act);
1123 EINA_LIST_FOREACH(_actions, l, act)
1124 evry->action_register(act, prio++);
1126 handlers = eina_list_append
1127 (handlers, ecore_event_handler_add
1128 (EFREET_EVENT_DESKTOP_CACHE_UPDATE, _desktop_cache_update, NULL));
1134 _plugins_shutdown(void)
1139 Ecore_Event_Handler *h;
1141 if (!evry_module->active)
1144 EINA_LIST_FREE(apps_cache, d)
1145 efreet_desktop_unref(d);
1147 EINA_LIST_FREE(_plugins, p)
1148 EVRY_PLUGIN_FREE(p);
1150 EINA_LIST_FREE(_actions, act)
1151 EVRY_ACTION_FREE(act);
1153 EINA_LIST_FREE(handlers, h)
1154 ecore_event_handler_del(h);
1156 evry_module->active = EINA_FALSE;
1159 /***************************************************************************/
1161 static E_Config_DD *conf_edd = NULL;
1163 struct _E_Config_Dialog_Data
1169 static void *_create_data(E_Config_Dialog *cfd);
1170 static void _free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
1171 static void _fill_data(E_Config_Dialog_Data *cfdata);
1172 static Evas_Object *_basic_create(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata);
1173 static int _basic_apply(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
1175 static E_Config_Dialog *
1176 _conf_dialog(E_Container *con, const char *params __UNUSED__)
1178 E_Config_Dialog *cfd = NULL;
1179 E_Config_Dialog_View *v = NULL;
1181 if (e_config_dialog_find("everything-apps", "launcher/everything-apps")) return NULL;
1183 v = E_NEW(E_Config_Dialog_View, 1);
1184 if (!v) return NULL;
1186 v->create_cfdata = _create_data;
1187 v->free_cfdata = _free_data;
1188 v->basic.create_widgets = _basic_create;
1189 v->basic.apply_cfdata = _basic_apply;
1191 cfd = e_config_dialog_new(con, _("Everything Applications"), "everything-apps",
1192 "launcher/everything-apps", _module_icon, 0, v, NULL);
1194 /* e_dialog_resizable_set(cfd->dia, 1); */
1199 /* Local Functions */
1201 _create_data(E_Config_Dialog *cfd __UNUSED__)
1203 E_Config_Dialog_Data *cfdata = NULL;
1205 cfdata = E_NEW(E_Config_Dialog_Data, 1);
1211 _free_data(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata)
1217 static Evas_Object *
1218 _basic_create(E_Config_Dialog *cfd __UNUSED__, Evas *e, E_Config_Dialog_Data *cfdata)
1220 Evas_Object *o = NULL, *of = NULL, *ow = NULL;
1222 o = e_widget_list_add(e, 0, 0);
1224 of = e_widget_framelist_add(e, _("Commands"), 0);
1225 ow = e_widget_label_add(e, _("Terminal Command"));
1226 e_widget_framelist_object_append(of, ow);
1227 ow = e_widget_entry_add(e, &(cfdata->cmd_terminal), NULL, NULL, NULL);
1228 e_widget_framelist_object_append(of, ow);
1230 ow = e_widget_label_add(e, _("Sudo GUI"));
1231 e_widget_framelist_object_append(of, ow);
1232 ow = e_widget_entry_add(e, &(cfdata->cmd_sudo), NULL, NULL, NULL);
1233 e_widget_framelist_object_append(of, ow);
1235 e_widget_list_object_append(o, of, 1, 1, 0.5);
1241 _fill_data(E_Config_Dialog_Data *cfdata)
1244 #define CP(_name) cfdata->_name = strdup(_conf->_name);
1245 #define C(_name) cfdata->_name = _conf->_name;
1253 _basic_apply(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata)
1257 eina_stringshare_del(_conf->_name); \
1258 _conf->_name = eina_stringshare_add(cfdata->_name);
1259 #define C(_name) _conf->_name = cfdata->_name;
1265 e_config_domain_save("module.everything-apps", conf_edd, _conf);
1267 /* e_config_save_queue(); */
1276 _conf = E_NEW(Module_Config, 1);
1277 _conf->version = (MOD_CONFIG_FILE_EPOCH << 16);
1280 #define IFMODCFG(v) if ((_conf->version & 0xffff) < v) {
1281 #define IFMODCFGEND }
1283 /* setup defaults */
1285 _conf->cmd_terminal = eina_stringshare_add("/usr/bin/xterm");
1286 _conf->cmd_sudo = eina_stringshare_add("/usr/bin/gksudo --preserve-env");
1289 _conf->version = MOD_CONFIG_FILE_VERSION;
1291 /* e_config_save_queue(); */
1299 IF_RELEASE(_conf->cmd_sudo);
1300 IF_RELEASE(_conf->cmd_terminal);
1305 _conf_init(E_Module *m)
1309 snprintf(title, sizeof(title), "%s: %s", _("Everything Plugin"), _("Applications"));
1311 e_configure_registry_item_add("launcher/everything-apps", 110, title,
1312 NULL, _module_icon, _conf_dialog);
1314 conf_edd = E_CONFIG_DD_NEW("Module_Config", Module_Config);
1318 #define T Module_Config
1320 E_CONFIG_VAL(D, T, version, INT);
1321 E_CONFIG_VAL(D, T, cmd_terminal, STR);
1322 E_CONFIG_VAL(D, T, cmd_sudo, STR);
1326 _conf = e_config_domain_load("module.everything-apps", conf_edd);
1329 if (_conf && !e_util_module_config_check
1330 (_("Everything Applications"), _conf->version,
1331 MOD_CONFIG_FILE_EPOCH, MOD_CONFIG_FILE_VERSION))
1339 _conf_shutdown(void)
1341 e_configure_registry_item_del("launcher/everything-apps");
1345 E_CONFIG_DD_FREE(conf_edd);
1348 /***************************************************************************/
1351 evry_plug_apps_init(E_Module *m)
1355 EVRY_MODULE_NEW(evry_module, evry, _plugins_init, _plugins_shutdown);
1357 /* taken from e_exebuf.c */
1358 exelist_exe_edd = E_CONFIG_DD_NEW("E_Exe", E_Exe);
1362 #define D exelist_exe_edd
1363 E_CONFIG_VAL(D, T, path, STR);
1365 exelist_edd = E_CONFIG_DD_NEW("E_Exe_List", E_Exe_List);
1368 #define T E_Exe_List
1369 #define D exelist_edd
1370 E_CONFIG_LIST(D, T, list, exelist_exe_edd);
1376 evry_plug_apps_shutdown(void)
1378 EVRY_MODULE_FREE(evry_module);
1382 E_CONFIG_DD_FREE(exelist_edd);
1383 E_CONFIG_DD_FREE(exelist_exe_edd);
1387 evry_plug_apps_save(void)
1389 e_config_domain_save("module.everything-apps", conf_edd, _conf);
1392 /***************************************************************************/
1395 /* taken from e_exebuf.c */
1397 _scan_idler(void *data __UNUSED__)
1404 /* no more path items left - stop scanning */
1412 /* FIXME: check wheter they match or not */
1413 for (l = exe_list, l2 = exe_list2; l && l2; l = l->next, l2 = l2->next)
1415 if (strcmp(l->data, l2->data))
1421 if ((l) || (l2)) different = 1;
1426 free(eina_list_data_get(exe_list));
1427 exe_list = eina_list_remove_list(exe_list, exe_list);
1429 exe_list = exe_list2;
1434 el = calloc(1, sizeof(E_Exe_List));
1438 for (l = exe_list; l; l = l->next)
1440 ee = malloc(sizeof(E_Exe));
1443 ee->path = eina_stringshare_add(l->data);
1444 el->list = eina_list_append(el->list, ee);
1447 e_config_domain_save("exebuf_exelist_cache", exelist_edd, el);
1450 ee = eina_list_data_get(el->list);
1451 eina_stringshare_del(ee->path);
1453 el->list = eina_list_remove_list(el->list, el->list);
1458 exe_scan_idler = NULL;
1459 return ECORE_CALLBACK_CANCEL;
1461 /* no dir is open - open the first path item */
1464 dir = exe_path->data;
1465 exe_dir = opendir(dir);
1467 /* if we have an opened dir - scan the next item */
1470 dir = exe_path->data;
1472 dp = readdir(exe_dir);
1475 if ((strcmp(dp->d_name, ".")) && (strcmp(dp->d_name, "..")))
1477 snprintf(buf, sizeof(buf), "%s/%s", dir, dp->d_name);
1478 if ((stat(buf, &st) == 0) &&
1479 ((!S_ISDIR(st.st_mode)) &&
1480 (!access(buf, X_OK))))
1483 exe_list = eina_list_append(exe_list, strdup(dp->d_name));
1485 exe_list2 = eina_list_append(exe_list2, strdup(dp->d_name));
1491 /* we reached the end of a dir - remove the dir at the head
1492 * of the path list so we advance and next loop we will pick up
1493 * the next item, or if null- abort
1497 free(eina_list_data_get(exe_path));
1498 exe_path = eina_list_remove_list(exe_path, exe_path);
1501 /* obviously the dir open failed - so remove the first path item */
1504 free(eina_list_data_get(exe_path));
1505 exe_path = eina_list_remove_list(exe_path, exe_path);
1507 /* we have more scannign to do */
1508 return ECORE_CALLBACK_RENEW;
1514 /* taken from exebuf module */
1515 char *path, *pp, *last;
1518 el = e_config_domain_load("exebuf_exelist_cache", exelist_edd);
1523 EINA_LIST_FREE(el->list, ee)
1525 exe_list = eina_list_append(exe_list, strdup(ee->path));
1526 eina_stringshare_del(ee->path);
1531 path = getenv("PATH");
1534 path = strdup(path);
1536 for (pp = path; pp[0]; pp++)
1538 if (pp[0] == ':') pp[0] = '\0';
1541 exe_path = eina_list_append(exe_path, strdup(last));
1546 exe_path = eina_list_append(exe_path, strdup(last));
1550 exe_scan_idler = ecore_idler_add(_scan_idler, NULL);