2010-04-10 13:05:57 -07:00
|
|
|
/*
|
|
|
|
* vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
|
|
|
|
*/
|
2009-05-06 07:20:45 -07:00
|
|
|
|
2010-04-10 13:05:57 -07:00
|
|
|
#include "Evry.h"
|
|
|
|
#include "e_mod_main.h"
|
2009-08-27 13:52:14 -07:00
|
|
|
|
2009-08-21 15:42:06 -07:00
|
|
|
typedef struct _Plugin Plugin;
|
2009-05-06 07:20:45 -07:00
|
|
|
|
2009-08-21 15:42:06 -07:00
|
|
|
struct _Plugin
|
2009-06-21 03:31:38 -07:00
|
|
|
{
|
2009-08-21 15:42:06 -07:00
|
|
|
Evry_Plugin base;
|
2009-08-11 09:07:30 -07:00
|
|
|
Eina_List *apps_mime;
|
|
|
|
Eina_List *apps_all;
|
2010-04-08 15:37:50 -07:00
|
|
|
Eina_List *apps_hist;
|
2009-08-12 05:17:43 -07:00
|
|
|
const Evry_Item *candidate;
|
2009-08-30 01:51:15 -07:00
|
|
|
Eina_Hash *added;
|
2010-04-12 07:01:14 -07:00
|
|
|
|
2010-04-12 09:43:57 -07:00
|
|
|
Evry_Item_App *app_command;
|
|
|
|
Evry_Item_App *app_parameter;
|
2009-06-21 03:31:38 -07:00
|
|
|
};
|
|
|
|
|
2009-08-25 02:30:14 -07:00
|
|
|
/* taken from exebuf module */
|
|
|
|
typedef struct _E_Exe E_Exe;
|
|
|
|
typedef struct _E_Exe_List E_Exe_List;
|
|
|
|
|
|
|
|
struct _E_Exe
|
|
|
|
{
|
|
|
|
const char *path;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _E_Exe_List
|
|
|
|
{
|
|
|
|
Eina_List *list;
|
|
|
|
};
|
|
|
|
|
|
|
|
static Plugin *p1 = NULL;
|
|
|
|
static Plugin *p2 = NULL;
|
|
|
|
static Evry_Action *act = NULL;
|
|
|
|
static Evry_Action *act1 = NULL;
|
|
|
|
static Evry_Action *act2 = NULL;
|
|
|
|
static Evry_Action *act3 = NULL;
|
|
|
|
static Evry_Action *act4 = NULL;
|
2009-09-02 12:43:16 -07:00
|
|
|
static Evry_Action *act5 = NULL;
|
2009-08-25 02:30:14 -07:00
|
|
|
|
2009-08-10 04:36:37 -07:00
|
|
|
static Eina_List *exe_path = NULL;
|
2009-08-25 02:30:14 -07:00
|
|
|
static Ecore_Idler *exe_scan_idler = NULL;
|
|
|
|
static E_Config_DD *exelist_exe_edd = NULL;
|
|
|
|
static E_Config_DD *exelist_edd = NULL;
|
|
|
|
static DIR *exe_dir = NULL;
|
|
|
|
static Eina_List *exe_list = NULL;
|
|
|
|
static Eina_List *exe_list2 = NULL;
|
|
|
|
|
|
|
|
static int _scan_idler(void *data);
|
|
|
|
|
2009-08-24 21:23:11 -07:00
|
|
|
static void _hash_free(void *data)
|
|
|
|
{
|
|
|
|
ITEM_APP(app, data);
|
|
|
|
evry_item_free(EVRY_ITEM(app));
|
|
|
|
}
|
|
|
|
|
2009-06-21 03:31:38 -07:00
|
|
|
|
2009-08-21 15:42:06 -07:00
|
|
|
static Evry_Plugin *
|
2009-08-25 02:30:14 -07:00
|
|
|
_begin_open_with(Evry_Plugin *plugin, const Evry_Item *item)
|
2009-06-21 14:16:02 -07:00
|
|
|
{
|
2009-08-22 20:12:05 -07:00
|
|
|
PLUGIN(p, plugin);
|
2009-08-27 13:52:14 -07:00
|
|
|
|
2009-06-21 14:16:02 -07:00
|
|
|
const char *mime;
|
2009-08-12 12:00:25 -07:00
|
|
|
|
2009-08-25 02:30:14 -07:00
|
|
|
if (!item) return 0;
|
2009-08-11 07:00:51 -07:00
|
|
|
|
2009-08-25 02:30:14 -07:00
|
|
|
ITEM_FILE(file, item);
|
2010-04-09 07:41:37 -07:00
|
|
|
Efreet_Desktop *d, *d2;
|
2009-07-04 04:10:28 -07:00
|
|
|
|
2010-04-07 08:03:27 -07:00
|
|
|
if (!file->path) return NULL;
|
2009-07-04 04:10:28 -07:00
|
|
|
|
2009-08-25 02:30:14 -07:00
|
|
|
if (!file->mime)
|
2010-04-07 08:03:27 -07:00
|
|
|
mime = efreet_mime_type_get(file->path);
|
2009-08-25 02:30:14 -07:00
|
|
|
else
|
|
|
|
mime = file->mime;
|
2009-07-04 04:10:28 -07:00
|
|
|
|
2009-08-25 02:30:14 -07:00
|
|
|
if (!mime) return NULL;
|
|
|
|
|
2009-08-27 13:52:14 -07:00
|
|
|
p->candidate = item;
|
2010-04-08 15:37:50 -07:00
|
|
|
|
2009-08-25 02:30:14 -07:00
|
|
|
p->apps_mime = efreet_util_desktop_mime_list(mime);
|
2010-04-08 21:14:09 -07:00
|
|
|
|
|
|
|
if (strcmp(mime, "text/plain") &&
|
|
|
|
!strncmp(mime, "text/", 5))
|
|
|
|
{
|
|
|
|
Eina_List *tmp;
|
|
|
|
tmp = efreet_util_desktop_mime_list("text/plain");
|
|
|
|
|
2010-04-09 07:41:37 -07:00
|
|
|
EINA_LIST_FREE(tmp, d)
|
2010-04-08 21:14:09 -07:00
|
|
|
{
|
2010-04-09 07:41:37 -07:00
|
|
|
if (!eina_list_data_find_list(p->apps_mime, d))
|
|
|
|
p->apps_mime = eina_list_append(p->apps_mime, d);
|
2010-04-08 21:14:09 -07:00
|
|
|
else
|
2010-04-09 07:41:37 -07:00
|
|
|
efreet_desktop_free(d);
|
2010-04-08 21:14:09 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-09 07:41:37 -07:00
|
|
|
d = e_exehist_mime_desktop_get(mime);
|
|
|
|
if (d)
|
|
|
|
{
|
|
|
|
if (d2 = eina_list_data_find(p->apps_mime, d))
|
|
|
|
{
|
|
|
|
p->apps_mime = eina_list_remove(p->apps_mime, d2);
|
|
|
|
efreet_desktop_free(d2);
|
|
|
|
}
|
|
|
|
|
|
|
|
p->apps_mime = eina_list_prepend(p->apps_mime, d);
|
|
|
|
}
|
|
|
|
|
2010-04-08 15:37:50 -07:00
|
|
|
p->added = eina_hash_string_small_new(_hash_free);
|
2009-09-02 12:43:16 -07:00
|
|
|
|
2009-08-27 13:52:14 -07:00
|
|
|
return plugin;
|
2009-08-25 02:30:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static Evry_Plugin *
|
|
|
|
_begin(Evry_Plugin *plugin, const Evry_Item *item)
|
|
|
|
{
|
2009-08-30 01:51:15 -07:00
|
|
|
PLUGIN(p, plugin);
|
2009-09-02 12:43:16 -07:00
|
|
|
|
2009-08-25 02:30:14 -07:00
|
|
|
/* taken from exebuf module */
|
|
|
|
char *path, *pp, *last;
|
|
|
|
E_Exe_List *el;
|
2009-08-27 13:52:14 -07:00
|
|
|
|
2009-08-25 02:30:14 -07:00
|
|
|
el = e_config_domain_load("exebuf_exelist_cache", exelist_edd);
|
|
|
|
if (el)
|
|
|
|
{
|
|
|
|
E_Exe *ee;
|
2009-08-27 13:52:14 -07:00
|
|
|
|
2009-08-25 02:30:14 -07:00
|
|
|
EINA_LIST_FREE(el->list, ee)
|
2009-07-08 15:06:14 -07:00
|
|
|
{
|
2009-08-25 02:30:14 -07:00
|
|
|
exe_list = eina_list_append(exe_list, strdup(ee->path));
|
|
|
|
eina_stringshare_del(ee->path);
|
|
|
|
free(ee);
|
2009-07-08 15:06:14 -07:00
|
|
|
}
|
2009-08-25 02:30:14 -07:00
|
|
|
free(el);
|
2009-06-24 13:02:37 -07:00
|
|
|
}
|
2009-08-25 02:30:14 -07:00
|
|
|
path = getenv("PATH");
|
|
|
|
if (path)
|
|
|
|
{
|
|
|
|
path = strdup(path);
|
|
|
|
last = path;
|
|
|
|
for (pp = path; pp[0]; pp++)
|
|
|
|
{
|
|
|
|
if (pp[0] == ':') pp[0] = '\0';
|
|
|
|
if (pp[0] == 0)
|
|
|
|
{
|
|
|
|
exe_path = eina_list_append(exe_path, strdup(last));
|
|
|
|
last = pp + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pp > last)
|
|
|
|
exe_path = eina_list_append(exe_path, strdup(last));
|
|
|
|
free(path);
|
|
|
|
}
|
2009-08-27 13:52:14 -07:00
|
|
|
|
2009-08-25 02:30:14 -07:00
|
|
|
exe_scan_idler = ecore_idler_add(_scan_idler, NULL);
|
2009-08-12 12:00:25 -07:00
|
|
|
|
2009-08-30 01:51:15 -07:00
|
|
|
p->added = eina_hash_string_small_new(_hash_free);
|
2009-08-27 13:52:14 -07:00
|
|
|
|
|
|
|
return plugin;
|
2009-06-21 14:16:02 -07:00
|
|
|
}
|
|
|
|
|
2009-08-13 15:42:40 -07:00
|
|
|
static void
|
2009-08-22 20:12:05 -07:00
|
|
|
_item_free(Evry_Item *item)
|
2009-08-13 15:42:40 -07:00
|
|
|
{
|
2009-08-22 20:12:05 -07:00
|
|
|
ITEM_APP(app, item);
|
2009-08-13 15:42:40 -07:00
|
|
|
|
2009-08-24 21:23:11 -07:00
|
|
|
if (app->desktop)
|
|
|
|
efreet_desktop_free(app->desktop);
|
|
|
|
if (app->file)
|
|
|
|
eina_stringshare_del(app->file);
|
2009-08-22 20:12:05 -07:00
|
|
|
|
2009-08-13 15:42:40 -07:00
|
|
|
E_FREE(app);
|
2009-05-06 07:20:45 -07:00
|
|
|
}
|
|
|
|
|
2009-06-24 13:02:37 -07:00
|
|
|
static void
|
2009-08-21 15:42:06 -07:00
|
|
|
_cleanup(Evry_Plugin *plugin)
|
2009-06-24 13:02:37 -07:00
|
|
|
{
|
2009-08-22 20:12:05 -07:00
|
|
|
PLUGIN(p, plugin);
|
2009-08-21 15:42:06 -07:00
|
|
|
Efreet_Desktop *desktop;
|
2009-08-30 04:07:10 -07:00
|
|
|
|
|
|
|
if (p->added)
|
|
|
|
eina_hash_free(p->added);
|
2009-08-27 13:52:14 -07:00
|
|
|
|
2009-08-24 21:23:11 -07:00
|
|
|
EVRY_PLUGIN_ITEMS_CLEAR(p);
|
2009-08-12 12:00:25 -07:00
|
|
|
|
2009-08-25 02:30:14 -07:00
|
|
|
EINA_LIST_FREE(p->apps_all, desktop)
|
|
|
|
efreet_desktop_free(desktop);
|
|
|
|
|
2010-04-08 15:37:50 -07:00
|
|
|
EINA_LIST_FREE(p->apps_hist, desktop)
|
|
|
|
efreet_desktop_free(desktop);
|
|
|
|
|
|
|
|
if (plugin->type == type_action)
|
2009-08-25 02:30:14 -07:00
|
|
|
{
|
2010-04-08 15:37:50 -07:00
|
|
|
EINA_LIST_FREE(p->apps_mime, desktop)
|
|
|
|
efreet_desktop_free(desktop);
|
2009-08-25 02:30:14 -07:00
|
|
|
}
|
2010-04-08 15:37:50 -07:00
|
|
|
else
|
2009-08-25 02:30:14 -07:00
|
|
|
{
|
2010-04-08 15:37:50 -07:00
|
|
|
char *str;
|
|
|
|
|
|
|
|
if (exe_dir)
|
|
|
|
{
|
|
|
|
closedir(exe_dir);
|
|
|
|
exe_dir = NULL;
|
|
|
|
}
|
|
|
|
EINA_LIST_FREE(exe_path, str)
|
|
|
|
free(str);
|
2009-07-04 04:10:28 -07:00
|
|
|
|
2010-04-08 15:37:50 -07:00
|
|
|
if (exe_scan_idler)
|
|
|
|
{
|
|
|
|
ecore_idler_del(exe_scan_idler);
|
|
|
|
exe_scan_idler = NULL;
|
|
|
|
}
|
|
|
|
EINA_LIST_FREE(exe_list, str)
|
|
|
|
free(str);
|
|
|
|
EINA_LIST_FREE(exe_list2, str)
|
|
|
|
free(str);
|
|
|
|
}
|
2010-04-12 07:01:14 -07:00
|
|
|
|
2010-04-12 09:43:57 -07:00
|
|
|
if (p->app_command)
|
|
|
|
evry_item_free(EVRY_ITEM(p->app_command));
|
|
|
|
p->app_command = NULL;
|
|
|
|
if (p->app_parameter)
|
|
|
|
evry_item_free(EVRY_ITEM(p->app_parameter));
|
|
|
|
p->app_parameter = NULL;
|
|
|
|
|
2009-06-24 13:02:37 -07:00
|
|
|
}
|
|
|
|
|
2009-09-02 12:43:16 -07:00
|
|
|
static Evry_Item_App *
|
2010-04-12 07:01:14 -07:00
|
|
|
_item_add(Plugin *p, Efreet_Desktop *desktop, const char *file, int match)
|
2009-08-10 08:00:41 -07:00
|
|
|
{
|
2009-08-22 20:12:05 -07:00
|
|
|
Evry_Item_App *app;
|
2009-08-10 11:39:11 -07:00
|
|
|
Efreet_Desktop *d2;
|
2009-08-11 09:07:30 -07:00
|
|
|
int already_refd = 0;
|
2010-04-12 07:01:14 -07:00
|
|
|
const char *exe;
|
2010-04-09 07:41:37 -07:00
|
|
|
|
2009-08-25 02:30:14 -07:00
|
|
|
if (file)
|
2009-08-10 08:00:41 -07:00
|
|
|
{
|
|
|
|
Eina_List *l;
|
|
|
|
int len;
|
2009-08-25 02:30:14 -07:00
|
|
|
char buf[1024];
|
2009-08-10 08:00:41 -07:00
|
|
|
char *tmp;
|
2009-08-27 13:52:14 -07:00
|
|
|
|
2009-08-30 01:51:15 -07:00
|
|
|
if ((app = eina_hash_find(p->added, file)))
|
2009-08-25 02:30:14 -07:00
|
|
|
{
|
|
|
|
if (!eina_list_data_find_list(EVRY_PLUGIN(p)->items, app))
|
|
|
|
{
|
|
|
|
EVRY_ITEM(app)->fuzzy_match = match;
|
2009-08-27 13:52:14 -07:00
|
|
|
EVRY_ITEM(app)->plugin = EVRY_PLUGIN(p);
|
2009-08-25 02:30:14 -07:00
|
|
|
EVRY_PLUGIN_ITEM_APPEND(p, app);
|
|
|
|
}
|
2009-09-02 12:43:16 -07:00
|
|
|
return app;
|
2009-08-25 02:30:14 -07:00
|
|
|
}
|
2009-08-27 13:52:14 -07:00
|
|
|
|
2009-08-10 08:00:41 -07:00
|
|
|
len = strlen(file);
|
|
|
|
tmp = ecore_file_app_exe_get(file);
|
2009-08-25 02:30:14 -07:00
|
|
|
snprintf(buf, sizeof(buf), "%s*", tmp);
|
|
|
|
l = efreet_util_desktop_exec_glob_list(buf);
|
2009-08-10 08:00:41 -07:00
|
|
|
|
2009-08-10 11:39:11 -07:00
|
|
|
EINA_LIST_FREE(l, d2)
|
|
|
|
{
|
|
|
|
if (!desktop && d2->exec && !strncmp(file, d2->exec, len))
|
|
|
|
{
|
|
|
|
desktop = d2;
|
2009-08-11 09:07:30 -07:00
|
|
|
already_refd = 1;
|
2009-08-10 11:39:11 -07:00
|
|
|
efreet_desktop_ref(desktop);
|
|
|
|
}
|
|
|
|
efreet_desktop_free(d2);
|
|
|
|
}
|
2009-08-10 08:00:41 -07:00
|
|
|
free(tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (desktop)
|
2009-08-25 02:30:14 -07:00
|
|
|
exe = desktop->exec;
|
|
|
|
else
|
|
|
|
exe = file;
|
2009-08-27 13:52:14 -07:00
|
|
|
|
2009-09-02 12:43:16 -07:00
|
|
|
if (!exe) return NULL;
|
2009-08-25 02:30:14 -07:00
|
|
|
|
2010-03-13 12:37:24 -08:00
|
|
|
if (app = eina_hash_find(p->added, exe))
|
2009-08-10 08:00:41 -07:00
|
|
|
{
|
2010-03-13 12:37:24 -08:00
|
|
|
if (!desktop || (!app->desktop) ||
|
|
|
|
(desktop == app->desktop) ||
|
|
|
|
(!strcmp(desktop->exec, app->desktop->exec)))
|
2009-08-25 02:30:14 -07:00
|
|
|
{
|
2010-03-13 12:37:24 -08:00
|
|
|
if (!eina_list_data_find_list(EVRY_PLUGIN(p)->items, app))
|
|
|
|
{
|
|
|
|
EVRY_ITEM(app)->fuzzy_match = match;
|
|
|
|
EVRY_ITEM(app)->plugin = EVRY_PLUGIN(p);
|
|
|
|
EVRY_PLUGIN_ITEM_APPEND(p, app);
|
|
|
|
}
|
|
|
|
return app;
|
2009-08-25 02:30:14 -07:00
|
|
|
}
|
2009-08-10 08:00:41 -07:00
|
|
|
}
|
2009-08-25 02:30:14 -07:00
|
|
|
if (desktop && !already_refd)
|
|
|
|
efreet_desktop_ref(desktop);
|
2009-08-27 13:52:14 -07:00
|
|
|
|
2009-08-22 20:12:05 -07:00
|
|
|
app = E_NEW(Evry_Item_App, 1);
|
2010-04-08 15:37:50 -07:00
|
|
|
|
2009-08-10 08:00:41 -07:00
|
|
|
if (desktop)
|
2009-09-24 16:08:59 -07:00
|
|
|
{
|
2010-04-10 13:05:57 -07:00
|
|
|
evry_item_new(EVRY_ITEM(app), EVRY_PLUGIN(p), desktop->name, _item_free);
|
|
|
|
EVRY_ITEM(app)->id = eina_stringshare_add(desktop->exec);
|
2009-09-24 16:08:59 -07:00
|
|
|
}
|
2009-08-10 08:00:41 -07:00
|
|
|
else
|
2009-09-24 16:08:59 -07:00
|
|
|
{
|
2010-04-10 13:05:57 -07:00
|
|
|
evry_item_new(EVRY_ITEM(app), EVRY_PLUGIN(p), file, _item_free);
|
|
|
|
EVRY_ITEM(app)->id = eina_stringshare_add(file);
|
2009-09-24 16:08:59 -07:00
|
|
|
}
|
|
|
|
|
2009-08-10 08:00:41 -07:00
|
|
|
app->desktop = desktop;
|
2009-08-24 21:23:11 -07:00
|
|
|
|
2009-08-30 01:51:15 -07:00
|
|
|
eina_hash_add(p->added, exe, app);
|
2009-08-10 08:00:41 -07:00
|
|
|
|
2009-08-25 02:30:14 -07:00
|
|
|
if (desktop)
|
|
|
|
{
|
|
|
|
const char *tmp = ecore_file_file_get(desktop->exec);
|
2009-08-11 09:07:30 -07:00
|
|
|
|
2009-08-25 02:30:14 -07:00
|
|
|
if (tmp && strcmp(exe, tmp))
|
|
|
|
{
|
2009-08-27 13:52:14 -07:00
|
|
|
evry_item_ref(EVRY_ITEM(app));
|
2009-08-30 01:51:15 -07:00
|
|
|
eina_hash_add(p->added, tmp, app);
|
2009-08-25 02:30:14 -07:00
|
|
|
}
|
|
|
|
}
|
2010-04-08 15:37:50 -07:00
|
|
|
|
|
|
|
if (file)
|
2009-08-25 02:30:14 -07:00
|
|
|
{
|
2010-04-08 15:37:50 -07:00
|
|
|
app->file = eina_stringshare_add(file);
|
2009-08-27 13:52:14 -07:00
|
|
|
|
2010-04-08 15:37:50 -07:00
|
|
|
if (strcmp(exe, file))
|
|
|
|
{
|
|
|
|
evry_item_ref(EVRY_ITEM(app));
|
|
|
|
eina_hash_add(p->added, file, app);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-25 02:30:14 -07:00
|
|
|
EVRY_ITEM(app)->fuzzy_match = match;
|
|
|
|
EVRY_PLUGIN_ITEM_APPEND(p, app);
|
2009-08-27 13:52:14 -07:00
|
|
|
|
2009-09-02 12:43:16 -07:00
|
|
|
return app;
|
2009-08-10 08:00:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-08-21 15:42:06 -07:00
|
|
|
_add_desktop_list(Plugin *p, Eina_List *apps, const char *input)
|
2009-08-10 08:00:41 -07:00
|
|
|
{
|
|
|
|
Efreet_Desktop *desktop;
|
|
|
|
Eina_List *l;
|
2009-08-15 17:13:56 -07:00
|
|
|
int m1, m2;
|
2009-08-12 12:00:25 -07:00
|
|
|
|
2009-08-10 08:00:41 -07:00
|
|
|
EINA_LIST_FOREACH(apps, l, desktop)
|
|
|
|
{
|
2010-04-08 15:37:50 -07:00
|
|
|
if (eina_list_count(EVRY_PLUGIN(p)->items) > 199) break;
|
2009-08-14 11:55:35 -07:00
|
|
|
if (!desktop->name || !desktop->exec) continue;
|
2009-08-12 12:00:25 -07:00
|
|
|
|
2010-04-08 15:37:50 -07:00
|
|
|
if (input)
|
|
|
|
{
|
|
|
|
char *exec = strrchr(desktop->exec, '/');
|
|
|
|
if (!exec++ || !exec) exec = desktop->exec;
|
2009-08-14 11:55:35 -07:00
|
|
|
|
2010-04-08 15:37:50 -07:00
|
|
|
m1 = evry_fuzzy_match(exec, input);
|
|
|
|
m2 = evry_fuzzy_match(desktop->name, input);
|
2009-08-14 11:55:35 -07:00
|
|
|
|
2010-04-08 15:37:50 -07:00
|
|
|
if (!m1 || (m2 && m2 < m1))
|
|
|
|
m1 = m2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!input || m1) _item_add(p, desktop, NULL, m1);
|
2009-08-10 08:00:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
_cb_sort(const void *data1, const void *data2)
|
|
|
|
{
|
2009-08-14 11:55:35 -07:00
|
|
|
const Evry_Item *it1 = data1;
|
|
|
|
const Evry_Item *it2 = data2;
|
2009-08-10 08:00:41 -07:00
|
|
|
|
2010-04-09 07:41:37 -07:00
|
|
|
if (it1->usage && it2->usage)
|
|
|
|
return (it1->usage > it2->usage ? -1 : 1);
|
|
|
|
if (it1->usage && !it2->usage)
|
2009-08-14 11:55:35 -07:00
|
|
|
return -1;
|
2010-04-09 07:41:37 -07:00
|
|
|
if (it2->usage && !it1->usage)
|
2009-08-14 11:55:35 -07:00
|
|
|
return 1;
|
|
|
|
|
2010-04-09 07:41:37 -07:00
|
|
|
if (it1->fuzzy_match || it2->fuzzy_match)
|
|
|
|
{
|
|
|
|
if (it1->fuzzy_match && !it2->fuzzy_match)
|
|
|
|
return -1;
|
2009-08-14 16:30:54 -07:00
|
|
|
|
2010-04-09 07:41:37 -07:00
|
|
|
if (!it1->fuzzy_match && it2->fuzzy_match)
|
|
|
|
return 1;
|
2009-08-14 11:55:35 -07:00
|
|
|
|
2010-04-09 07:41:37 -07:00
|
|
|
if (it1->fuzzy_match - it2->fuzzy_match)
|
|
|
|
return (it1->fuzzy_match - it2->fuzzy_match);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2009-08-10 08:00:41 -07:00
|
|
|
}
|
|
|
|
|
2009-09-24 16:08:59 -07:00
|
|
|
static Eina_Bool
|
|
|
|
_hist_items_add_cb(const Eina_Hash *hash, const void *key, void *data, void *fdata)
|
|
|
|
{
|
2010-04-10 13:05:57 -07:00
|
|
|
History_Entry *he = data;
|
|
|
|
History_Item *hi;
|
|
|
|
Plugin *p = fdata;
|
|
|
|
Efreet_Desktop *d;
|
|
|
|
Eina_List *l;
|
|
|
|
Evry_Item_App *app;
|
|
|
|
|
|
|
|
EINA_LIST_FOREACH(he->items, l, hi)
|
|
|
|
{
|
|
|
|
if (hi->plugin != p->base.name)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ((d = efreet_util_desktop_exec_find(key)))
|
|
|
|
{
|
|
|
|
app = _item_add(p, d, NULL, 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
app = _item_add(p, NULL, (char *) key, 1);
|
|
|
|
if (app && app->desktop)
|
|
|
|
efreet_desktop_ref(app->desktop);
|
|
|
|
}
|
2010-04-08 15:37:50 -07:00
|
|
|
|
2010-04-10 13:05:57 -07:00
|
|
|
if (app && app->desktop)
|
|
|
|
{
|
|
|
|
p->apps_hist = eina_list_append(p->apps_hist, app->desktop);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (app) break;
|
|
|
|
}
|
|
|
|
return EINA_TRUE;
|
2009-09-24 16:08:59 -07:00
|
|
|
}
|
|
|
|
|
2010-04-12 07:01:14 -07:00
|
|
|
static void
|
|
|
|
_cb_free_item_changed(void *data, void *event)
|
|
|
|
{
|
|
|
|
Evry_Event_Item_Changed *ev = event;
|
|
|
|
|
|
|
|
evry_item_free(ev->item);
|
|
|
|
E_FREE(ev);
|
|
|
|
}
|
|
|
|
|
2009-05-06 07:20:45 -07:00
|
|
|
static int
|
2009-08-21 15:42:06 -07:00
|
|
|
_fetch(Evry_Plugin *plugin, const char *input)
|
2009-05-06 07:20:45 -07:00
|
|
|
{
|
2009-08-22 20:12:05 -07:00
|
|
|
PLUGIN(p, plugin);
|
2009-06-21 14:16:02 -07:00
|
|
|
Eina_List *l;
|
2009-05-06 07:20:45 -07:00
|
|
|
Efreet_Desktop *desktop;
|
2009-08-22 21:02:36 -07:00
|
|
|
Evry_Item *it;
|
2009-05-06 07:20:45 -07:00
|
|
|
char *file;
|
2009-08-22 21:02:36 -07:00
|
|
|
int prio = 0;
|
2009-08-25 02:30:14 -07:00
|
|
|
int len = input ? strlen(input) : 0;
|
2009-08-11 09:07:30 -07:00
|
|
|
|
2009-08-24 21:23:11 -07:00
|
|
|
EVRY_PLUGIN_ITEMS_CLEAR(p);
|
2009-08-27 13:52:14 -07:00
|
|
|
|
2009-08-10 08:00:41 -07:00
|
|
|
/* add apps for a given mimetype */
|
2009-08-22 20:12:05 -07:00
|
|
|
if (plugin->type == type_action)
|
2010-04-08 15:37:50 -07:00
|
|
|
_add_desktop_list(p, p->apps_mime, input);
|
2009-07-04 04:10:28 -07:00
|
|
|
|
2009-08-10 08:00:41 -07:00
|
|
|
/* add apps matching input */
|
2009-08-11 09:07:30 -07:00
|
|
|
if (input)
|
2009-08-11 10:03:36 -07:00
|
|
|
{
|
2009-08-21 15:42:06 -07:00
|
|
|
if (!p->apps_all)
|
2009-08-14 07:44:18 -07:00
|
|
|
{
|
|
|
|
Eina_List *apps = NULL;
|
2009-08-25 04:19:04 -07:00
|
|
|
Eina_List *cat_ss, *cat_app, *cat_sys, *cat_set;
|
2009-08-14 07:44:18 -07:00
|
|
|
Eina_List *l, *ll;
|
|
|
|
|
|
|
|
apps = efreet_util_desktop_name_glob_list("*");
|
|
|
|
|
2010-03-30 06:32:44 -07:00
|
|
|
/* remove screensaver */
|
|
|
|
cat_ss = efreet_util_desktop_category_list("Screensaver");
|
2009-08-25 04:19:04 -07:00
|
|
|
EINA_LIST_FOREACH(cat_ss, l, desktop)
|
2009-08-14 07:44:18 -07:00
|
|
|
{
|
2010-03-30 06:32:44 -07:00
|
|
|
if ((ll = eina_list_data_find_list(apps, desktop)))
|
2009-08-25 04:19:04 -07:00
|
|
|
{
|
|
|
|
efreet_desktop_free(desktop);
|
|
|
|
apps = eina_list_remove_list(apps, ll);
|
|
|
|
}
|
2010-04-08 15:37:50 -07:00
|
|
|
efreet_desktop_free(desktop);
|
2009-08-25 04:19:04 -07:00
|
|
|
}
|
2009-08-10 08:57:38 -07:00
|
|
|
|
2009-08-21 15:42:06 -07:00
|
|
|
p->apps_all = apps;
|
2009-08-14 07:44:18 -07:00
|
|
|
}
|
|
|
|
|
2009-08-21 15:42:06 -07:00
|
|
|
_add_desktop_list(p, p->apps_all, input);
|
2009-08-11 10:03:36 -07:00
|
|
|
}
|
2009-08-10 08:57:38 -07:00
|
|
|
/* add exe history items */
|
2009-08-21 15:42:06 -07:00
|
|
|
else if (!plugin->items)
|
2009-07-15 16:14:53 -07:00
|
|
|
{
|
2010-04-08 15:37:50 -07:00
|
|
|
if (!p->apps_hist)
|
|
|
|
eina_hash_foreach(evry_hist->subjects, _hist_items_add_cb, p);
|
|
|
|
else
|
|
|
|
_add_desktop_list(p, p->apps_hist, NULL);
|
2009-07-15 16:14:53 -07:00
|
|
|
}
|
2009-07-04 04:10:28 -07:00
|
|
|
|
2009-08-25 02:30:14 -07:00
|
|
|
/* add executables */
|
2010-04-12 07:01:14 -07:00
|
|
|
if (input && len > 3)
|
2009-08-25 02:30:14 -07:00
|
|
|
{
|
|
|
|
char *space;
|
2009-09-02 12:43:16 -07:00
|
|
|
Evry_Item_App *app;
|
|
|
|
char buf[256];
|
2009-08-25 02:30:14 -07:00
|
|
|
if ((space = strchr(input, ' ')))
|
|
|
|
len = (space - input);
|
2009-08-27 13:52:14 -07:00
|
|
|
|
2009-08-25 02:30:14 -07:00
|
|
|
EINA_LIST_FOREACH(exe_list, l, file)
|
|
|
|
{
|
|
|
|
if (!strncmp(file, input, len))
|
2009-09-02 12:43:16 -07:00
|
|
|
{
|
2010-04-12 09:43:57 -07:00
|
|
|
if ((app = _item_add(p, NULL, file, 100)))
|
2010-04-12 07:01:14 -07:00
|
|
|
{
|
2010-04-12 09:43:57 -07:00
|
|
|
Evry_Item_App *app2;
|
|
|
|
|
|
|
|
if (!app->desktop) continue;
|
|
|
|
|
|
|
|
if (!space) continue;
|
|
|
|
|
|
|
|
if (!(EVRY_ITEM(app)->selected ||
|
|
|
|
EVRY_ITEM(p->app_parameter)->selected))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!p->app_parameter)
|
|
|
|
{
|
|
|
|
app2 = E_NEW(Evry_Item_App, 1);
|
|
|
|
snprintf(buf, sizeof(buf), "%s: %s", app->desktop->name, space);
|
|
|
|
evry_item_new(EVRY_ITEM(app2), EVRY_PLUGIN(p), buf, _item_free);
|
|
|
|
|
|
|
|
app2->desktop = app->desktop;
|
|
|
|
efreet_desktop_ref(app2->desktop);
|
|
|
|
|
|
|
|
app2->file = eina_stringshare_add(space);
|
|
|
|
|
|
|
|
EVRY_ITEM(app2)->transient = 1;
|
|
|
|
EVRY_ITEM(app2)->priority = -1;
|
|
|
|
EVRY_PLUGIN_ITEM_APPEND(p, app2);
|
|
|
|
p->app_parameter = app2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Evry_Event_Item_Changed *ev;
|
|
|
|
app2 = p->app_parameter;
|
|
|
|
efreet_desktop_free(app2->desktop);
|
|
|
|
eina_stringshare_del(app2->file);
|
|
|
|
eina_stringshare_del(EVRY_ITEM(app2)->label);
|
|
|
|
|
|
|
|
snprintf(buf, sizeof(buf), "%s: %s", app->desktop->name, space);
|
|
|
|
EVRY_ITEM(app2)->label = eina_stringshare_add(buf);
|
|
|
|
|
|
|
|
app2->desktop = app->desktop;
|
|
|
|
efreet_desktop_ref(app2->desktop);
|
|
|
|
|
|
|
|
app2->file = eina_stringshare_add(space);
|
|
|
|
|
|
|
|
if (!eina_list_data_find(p->base.items, app2))
|
|
|
|
EVRY_PLUGIN_ITEM_APPEND(p, app2);
|
|
|
|
|
|
|
|
ev = E_NEW(Evry_Event_Item_Changed, 1);
|
|
|
|
evry_item_ref(EVRY_ITEM(app2));
|
|
|
|
ev->item = EVRY_ITEM(app2);
|
|
|
|
ecore_event_add(EVRY_EVENT_ITEM_CHANGED, ev, _cb_free_item_changed, NULL);
|
|
|
|
}
|
2010-04-12 07:01:14 -07:00
|
|
|
}
|
2010-04-12 09:43:57 -07:00
|
|
|
|
|
|
|
if (!p->app_command)
|
2010-04-12 07:01:14 -07:00
|
|
|
{
|
|
|
|
app = E_NEW(Evry_Item_App, 1);
|
2009-09-02 12:46:12 -07:00
|
|
|
|
2010-04-12 09:43:57 -07:00
|
|
|
snprintf(buf, sizeof(buf), "%s %s", file, space);
|
|
|
|
evry_item_new(EVRY_ITEM(app), EVRY_PLUGIN(p), buf, _item_free);
|
2010-04-12 07:01:14 -07:00
|
|
|
EVRY_ITEM(app)->id = eina_stringshare_add(input);
|
2010-04-12 09:43:57 -07:00
|
|
|
EVRY_ITEM(app)->transient = 1;
|
2010-04-12 07:01:14 -07:00
|
|
|
EVRY_ITEM(app)->priority = -1;
|
|
|
|
EVRY_PLUGIN_ITEM_APPEND(p, app);
|
2010-04-12 09:43:57 -07:00
|
|
|
p->app_command = app;
|
2010-04-12 07:01:14 -07:00
|
|
|
}
|
|
|
|
else
|
2009-09-02 12:43:16 -07:00
|
|
|
{
|
2010-04-12 07:01:14 -07:00
|
|
|
Evry_Event_Item_Changed *ev;
|
2010-04-12 09:43:57 -07:00
|
|
|
app = p->app_command;
|
2010-02-15 05:32:34 -08:00
|
|
|
eina_stringshare_del(EVRY_ITEM(app)->label);
|
2010-04-12 09:43:57 -07:00
|
|
|
snprintf(buf, sizeof(buf), "%s %s", file, space);
|
|
|
|
EVRY_ITEM(app)->label = eina_stringshare_add(buf);
|
2009-09-02 12:46:12 -07:00
|
|
|
eina_stringshare_del(app->file);
|
2010-04-12 07:01:14 -07:00
|
|
|
app->file = eina_stringshare_add(input);
|
2010-04-12 08:34:21 -07:00
|
|
|
if (!eina_list_data_find(p->base.items, app))
|
|
|
|
EVRY_PLUGIN_ITEM_APPEND(p, app);
|
2010-04-12 07:01:14 -07:00
|
|
|
|
|
|
|
ev = E_NEW(Evry_Event_Item_Changed, 1);
|
|
|
|
evry_item_ref(EVRY_ITEM(app));
|
|
|
|
ev->item = EVRY_ITEM(app);
|
|
|
|
ecore_event_add(EVRY_EVENT_ITEM_CHANGED, ev, _cb_free_item_changed, NULL);
|
2009-09-02 12:43:16 -07:00
|
|
|
}
|
|
|
|
}
|
2009-08-25 02:30:14 -07:00
|
|
|
}
|
|
|
|
}
|
2009-07-04 04:10:28 -07:00
|
|
|
|
2009-08-22 21:02:36 -07:00
|
|
|
if (!plugin->items) return 0;
|
2009-08-21 15:42:06 -07:00
|
|
|
|
2010-04-09 07:41:37 -07:00
|
|
|
if (plugin->type == type_action)
|
|
|
|
{
|
|
|
|
EINA_LIST_FOREACH(plugin->items, l, it)
|
|
|
|
evry_history_item_usage_set(evry_hist->actions, it, input, NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
EINA_LIST_FOREACH(plugin->items, l, it)
|
|
|
|
evry_history_item_usage_set(evry_hist->subjects, it, input, NULL);
|
|
|
|
}
|
|
|
|
|
2009-08-30 01:51:15 -07:00
|
|
|
if (plugin->type != type_action || input)
|
|
|
|
EVRY_PLUGIN_ITEMS_SORT(plugin, _cb_sort);
|
2009-08-14 07:44:18 -07:00
|
|
|
|
2009-08-22 21:02:36 -07:00
|
|
|
return 1;
|
2009-05-06 07:20:45 -07:00
|
|
|
}
|
|
|
|
|
2009-08-10 04:36:37 -07:00
|
|
|
static Evas_Object *
|
2009-08-18 07:29:30 -07:00
|
|
|
_icon_get(Evry_Plugin *p __UNUSED__, const Evry_Item *it, Evas *e)
|
2009-05-06 07:20:45 -07:00
|
|
|
{
|
2009-08-22 20:12:05 -07:00
|
|
|
ITEM_APP(app, it);
|
2009-08-10 04:36:37 -07:00
|
|
|
Evas_Object *o = NULL;
|
2009-08-22 20:12:05 -07:00
|
|
|
|
2009-05-06 07:20:45 -07:00
|
|
|
if (app->desktop)
|
2009-08-10 04:36:37 -07:00
|
|
|
o = e_util_desktop_icon_add(app->desktop, 64, e);
|
2009-06-21 16:25:39 -07:00
|
|
|
|
2009-08-10 04:36:37 -07:00
|
|
|
if (!o)
|
2009-08-18 07:29:30 -07:00
|
|
|
o = evry_icon_theme_get("system-run", e);
|
2009-05-06 07:20:45 -07:00
|
|
|
|
2009-08-10 08:00:41 -07:00
|
|
|
return o;
|
2009-05-06 07:20:45 -07:00
|
|
|
}
|
2009-06-24 13:02:37 -07:00
|
|
|
|
2009-07-15 07:37:01 -07:00
|
|
|
static int
|
2009-08-12 05:17:43 -07:00
|
|
|
_exec_app_check_item(Evry_Action *act __UNUSED__, const Evry_Item *it)
|
2009-07-15 07:37:01 -07:00
|
|
|
{
|
2009-09-17 23:33:33 -07:00
|
|
|
/* ITEM_APP(app, it); */
|
2009-08-22 20:12:05 -07:00
|
|
|
|
2009-09-15 10:19:53 -07:00
|
|
|
/* if (app->desktop)
|
|
|
|
* return 1; */
|
2009-07-15 07:37:01 -07:00
|
|
|
|
2009-08-25 02:30:14 -07:00
|
|
|
/* run in terminal or do a .desktop entry! it's easy now */
|
|
|
|
/* if (app->file && strlen(app->file) > 0)
|
|
|
|
* return 1; */
|
2009-08-14 16:30:54 -07:00
|
|
|
|
2009-09-15 10:19:53 -07:00
|
|
|
return 1;
|
2009-08-14 11:55:35 -07:00
|
|
|
}
|
|
|
|
|
2009-08-10 08:00:41 -07:00
|
|
|
static int
|
2009-08-21 18:15:21 -07:00
|
|
|
_exec_app_action(Evry_Action *act)
|
2009-08-14 11:55:35 -07:00
|
|
|
{
|
2009-08-27 19:25:13 -07:00
|
|
|
return evry_util_exec_app(act->item1, act->item2);
|
2009-08-14 11:55:35 -07:00
|
|
|
}
|
|
|
|
|
2009-08-25 02:30:14 -07:00
|
|
|
static int
|
|
|
|
_exec_term_action(Evry_Action *act)
|
|
|
|
{
|
|
|
|
ITEM_APP(app, act->item1);
|
2009-08-27 03:35:32 -07:00
|
|
|
Evry_Item_App *tmp;
|
2009-08-25 02:30:14 -07:00
|
|
|
char buf[1024];
|
2009-08-27 03:35:32 -07:00
|
|
|
int ret;
|
2009-09-17 23:33:33 -07:00
|
|
|
char *escaped = ecore_file_escape_name(app->file);
|
|
|
|
|
2009-08-27 03:35:32 -07:00
|
|
|
tmp = E_NEW(Evry_Item_App, 1);
|
2009-09-17 23:33:33 -07:00
|
|
|
snprintf(buf, sizeof(buf), "%s -hold -e %s",
|
2009-09-02 12:43:16 -07:00
|
|
|
evry_conf->cmd_terminal,
|
2009-09-17 23:33:33 -07:00
|
|
|
(escaped ? escaped : app->file));
|
2009-09-02 12:43:16 -07:00
|
|
|
|
2009-08-27 03:35:32 -07:00
|
|
|
tmp->file = buf;
|
2009-08-27 19:25:13 -07:00
|
|
|
ret = evry_util_exec_app(EVRY_ITEM(tmp), NULL);
|
2009-08-25 02:30:14 -07:00
|
|
|
|
2009-08-27 03:35:32 -07:00
|
|
|
E_FREE(tmp);
|
2009-09-17 23:33:33 -07:00
|
|
|
E_FREE(escaped);
|
|
|
|
|
2009-08-27 03:35:32 -07:00
|
|
|
return ret;
|
2009-08-25 02:30:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
_exec_term_check_item(Evry_Action *act __UNUSED__, const Evry_Item *it)
|
|
|
|
{
|
|
|
|
ITEM_APP(app, it);
|
|
|
|
|
|
|
|
if (app->file)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-09-02 12:43:16 -07:00
|
|
|
static int
|
|
|
|
_exec_sudo_action(Evry_Action *act)
|
|
|
|
{
|
|
|
|
ITEM_APP(app, act->item1);
|
|
|
|
Evry_Item_App *tmp;
|
|
|
|
char buf[1024];
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
tmp = E_NEW(Evry_Item_App, 1);
|
|
|
|
snprintf(buf, sizeof(buf), "%s %s",
|
|
|
|
evry_conf->cmd_sudo,
|
|
|
|
(app->desktop ? app->desktop->exec : app->file));
|
|
|
|
|
|
|
|
tmp->file = buf;
|
|
|
|
ret = evry_util_exec_app(EVRY_ITEM(tmp), NULL);
|
|
|
|
|
|
|
|
E_FREE(tmp);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-08-10 08:00:41 -07:00
|
|
|
static int
|
2009-08-21 18:15:21 -07:00
|
|
|
_open_with_action(Evry_Plugin *plugin, const Evry_Item *it)
|
2009-08-10 08:00:41 -07:00
|
|
|
{
|
2009-08-22 20:12:05 -07:00
|
|
|
PLUGIN(p, plugin);
|
2009-08-21 15:42:06 -07:00
|
|
|
|
|
|
|
if (p->candidate)
|
2009-08-27 19:25:13 -07:00
|
|
|
return evry_util_exec_app(it, p->candidate);
|
2009-08-15 17:13:56 -07:00
|
|
|
|
|
|
|
return 0;
|
2009-07-15 05:22:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-08-12 05:17:43 -07:00
|
|
|
_edit_app_check_item(Evry_Action *act __UNUSED__, const Evry_Item *it)
|
2009-07-15 05:22:42 -07:00
|
|
|
{
|
2009-08-22 20:12:05 -07:00
|
|
|
ITEM_APP(app, it);
|
2009-08-24 21:23:11 -07:00
|
|
|
|
2009-07-15 05:22:42 -07:00
|
|
|
if (app->desktop)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2009-07-04 04:10:28 -07:00
|
|
|
|
2009-07-15 05:22:42 -07:00
|
|
|
static int
|
2009-08-21 18:15:21 -07:00
|
|
|
_edit_app_action(Evry_Action *act)
|
2009-07-15 05:22:42 -07:00
|
|
|
{
|
2009-08-10 04:36:37 -07:00
|
|
|
Efreet_Desktop *desktop;
|
2009-08-22 20:12:05 -07:00
|
|
|
ITEM_APP(app, act->item1);
|
2009-08-10 04:36:37 -07:00
|
|
|
|
|
|
|
if (app->desktop)
|
|
|
|
desktop = app->desktop;
|
|
|
|
else
|
2009-07-15 05:22:42 -07:00
|
|
|
{
|
2009-08-10 04:36:37 -07:00
|
|
|
char buf[128];
|
2009-08-10 08:00:41 -07:00
|
|
|
snprintf(buf, 128, "%s/.local/share/applications/%s.desktop",
|
|
|
|
e_user_homedir_get(), app->file);
|
2009-08-10 04:36:37 -07:00
|
|
|
desktop = efreet_desktop_empty_new(eina_stringshare_add(buf));
|
2009-08-24 21:23:11 -07:00
|
|
|
/* XXX check if this is freed by efreet*/
|
2009-08-12 12:00:25 -07:00
|
|
|
desktop->exec = strdup(app->file);
|
2009-08-10 04:36:37 -07:00
|
|
|
}
|
2009-07-15 05:22:42 -07:00
|
|
|
|
2009-08-10 04:36:37 -07:00
|
|
|
e_desktop_edit(e_container_current_get(e_manager_current_get()), desktop);
|
2009-08-12 12:00:25 -07:00
|
|
|
|
2009-08-10 04:36:37 -07:00
|
|
|
return 1;
|
2009-07-15 05:22:42 -07:00
|
|
|
}
|
2009-07-04 04:10:28 -07:00
|
|
|
|
2009-07-15 07:37:01 -07:00
|
|
|
static int
|
2009-08-12 05:17:43 -07:00
|
|
|
_new_app_check_item(Evry_Action *act __UNUSED__, const Evry_Item *it)
|
2009-07-15 07:37:01 -07:00
|
|
|
{
|
2009-08-22 20:12:05 -07:00
|
|
|
ITEM_APP(app, it);
|
2009-08-24 21:23:11 -07:00
|
|
|
|
2009-07-15 07:37:01 -07:00
|
|
|
if (app->desktop)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (app->file && strlen(app->file) > 0)
|
|
|
|
return 1;
|
2009-08-12 12:00:25 -07:00
|
|
|
|
2009-07-15 07:37:01 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-07-15 05:22:42 -07:00
|
|
|
static int
|
2009-08-21 18:15:21 -07:00
|
|
|
_new_app_action(Evry_Action *act)
|
2009-07-15 05:22:42 -07:00
|
|
|
{
|
2009-08-10 04:36:37 -07:00
|
|
|
char *name;
|
|
|
|
char buf[4096];
|
|
|
|
char *end;
|
|
|
|
Efreet_Desktop *desktop;
|
|
|
|
int i;
|
|
|
|
|
2009-08-22 20:12:05 -07:00
|
|
|
ITEM_APP(app, act->item1);
|
2009-08-12 12:00:25 -07:00
|
|
|
|
2009-08-10 04:36:37 -07:00
|
|
|
if (app->desktop)
|
|
|
|
name = strdup(app->desktop->name);
|
|
|
|
else
|
|
|
|
/* TODO replace '/' and remove other special characters */
|
|
|
|
name = strdup(app->file);
|
2009-07-15 05:22:42 -07:00
|
|
|
|
2009-08-10 04:36:37 -07:00
|
|
|
if ((end = strchr(name, ' ')))
|
|
|
|
name[end - name] = '\0';
|
2009-08-12 12:00:25 -07:00
|
|
|
|
2009-08-10 04:36:37 -07:00
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
{
|
2009-08-10 08:00:41 -07:00
|
|
|
snprintf(buf, 4096, "%s/.local/share/applications/%s-%d.desktop",
|
|
|
|
e_user_homedir_get(), name, i);
|
2009-08-10 04:36:37 -07:00
|
|
|
if (ecore_file_exists(buf))
|
2009-07-15 05:22:42 -07:00
|
|
|
{
|
2009-08-10 04:36:37 -07:00
|
|
|
buf[0] = '\0';
|
|
|
|
continue;
|
2009-07-15 05:22:42 -07:00
|
|
|
}
|
2009-08-10 04:36:37 -07:00
|
|
|
else break;
|
|
|
|
}
|
2009-07-15 05:22:42 -07:00
|
|
|
|
2009-08-10 04:36:37 -07:00
|
|
|
free(name);
|
2009-08-12 12:00:25 -07:00
|
|
|
|
2009-08-10 04:36:37 -07:00
|
|
|
if (strlen(buf) == 0)
|
|
|
|
return 0;
|
2009-08-12 12:00:25 -07:00
|
|
|
|
2009-08-10 04:36:37 -07:00
|
|
|
if (!app->desktop)
|
|
|
|
{
|
|
|
|
desktop = efreet_desktop_empty_new(buf);
|
|
|
|
desktop->exec = strdup(app->file);
|
|
|
|
}
|
2009-08-12 12:00:25 -07:00
|
|
|
else
|
2009-08-10 04:36:37 -07:00
|
|
|
{
|
|
|
|
efreet_desktop_save_as(app->desktop, buf);
|
|
|
|
desktop = efreet_desktop_new(buf);
|
|
|
|
}
|
2009-08-12 12:00:25 -07:00
|
|
|
|
2009-08-10 04:36:37 -07:00
|
|
|
e_desktop_edit(e_container_current_get(e_manager_current_get()), desktop);
|
2009-07-15 05:22:42 -07:00
|
|
|
|
2009-08-10 04:36:37 -07:00
|
|
|
return 1;
|
2009-06-24 13:02:37 -07:00
|
|
|
}
|
2009-07-15 05:22:42 -07:00
|
|
|
|
2010-02-15 05:32:34 -08:00
|
|
|
//#define TIME_FACTOR(_now) (1.0 - (evry_hist->begin / _now)) / 1000000000000000.0
|
2009-08-21 18:15:21 -07:00
|
|
|
|
2010-04-10 15:38:05 -07:00
|
|
|
static void
|
|
|
|
_free_plugin(Evry_Plugin *plugin)
|
|
|
|
{
|
|
|
|
PLUGIN(p, plugin);
|
|
|
|
|
|
|
|
E_FREE(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-10 08:00:41 -07:00
|
|
|
static Eina_Bool
|
2010-04-10 13:05:57 -07:00
|
|
|
module_init(void)
|
2009-08-10 08:00:41 -07:00
|
|
|
{
|
2010-04-08 04:55:15 -07:00
|
|
|
if (!evry_api_version_check(EVRY_API_VERSION))
|
|
|
|
return EINA_FALSE;
|
|
|
|
|
2009-08-21 15:42:06 -07:00
|
|
|
p1 = E_NEW(Plugin, 1);
|
2009-08-22 20:12:05 -07:00
|
|
|
evry_plugin_new(EVRY_PLUGIN(p1), "Applications", type_subject, "", "APPLICATION", 0, NULL, NULL,
|
2010-04-10 15:38:05 -07:00
|
|
|
_begin, _cleanup, _fetch, NULL, _icon_get, _free_plugin);
|
2009-08-18 12:10:13 -07:00
|
|
|
|
2009-08-21 15:42:06 -07:00
|
|
|
p2 = E_NEW(Plugin, 1);
|
2009-08-22 20:12:05 -07:00
|
|
|
evry_plugin_new(EVRY_PLUGIN(p2), "Open With...", type_action, "FILE", "", 0, NULL, NULL,
|
2010-04-08 15:37:50 -07:00
|
|
|
_begin_open_with, _cleanup, _fetch, _open_with_action,
|
2010-04-10 15:38:05 -07:00
|
|
|
_icon_get, _free_plugin);
|
2009-08-10 08:00:41 -07:00
|
|
|
|
2009-08-22 20:12:05 -07:00
|
|
|
evry_plugin_register(EVRY_PLUGIN(p1), 1);
|
2009-08-27 19:25:13 -07:00
|
|
|
evry_plugin_register(EVRY_PLUGIN(p2), 1);
|
2009-08-10 08:00:41 -07:00
|
|
|
|
2009-08-21 15:42:06 -07:00
|
|
|
act = evry_action_new("Launch", "APPLICATION", NULL, NULL,
|
|
|
|
"everything-launch",
|
2009-08-21 18:15:21 -07:00
|
|
|
_exec_app_action, _exec_app_check_item,
|
2010-04-10 15:38:05 -07:00
|
|
|
NULL, NULL, NULL, NULL);
|
2009-09-02 12:43:16 -07:00
|
|
|
|
2009-08-21 15:42:06 -07:00
|
|
|
act1 = evry_action_new("Open File...", "APPLICATION", "FILE", "APPLICATION",
|
|
|
|
"document-open",
|
2009-08-21 18:15:21 -07:00
|
|
|
_exec_app_action, _exec_app_check_item,
|
2010-04-10 15:38:05 -07:00
|
|
|
NULL, NULL, NULL, NULL);
|
2009-08-18 12:10:13 -07:00
|
|
|
|
2009-08-27 19:25:13 -07:00
|
|
|
act2 = evry_action_new("Run in Terminal", "APPLICATION", NULL, NULL,
|
|
|
|
"system-run",
|
|
|
|
_exec_term_action, _exec_term_check_item,
|
2010-04-10 15:38:05 -07:00
|
|
|
NULL, NULL, NULL, NULL);
|
2009-08-12 12:00:25 -07:00
|
|
|
|
2009-08-27 19:25:13 -07:00
|
|
|
act3 = evry_action_new("Edit Application Entry", "APPLICATION", NULL, NULL,
|
2009-08-21 15:42:06 -07:00
|
|
|
"everything-launch",
|
2009-08-27 19:25:13 -07:00
|
|
|
_edit_app_action, _edit_app_check_item,
|
2010-04-10 15:38:05 -07:00
|
|
|
NULL, NULL, NULL, NULL);
|
2009-09-02 12:43:16 -07:00
|
|
|
|
2009-08-27 19:25:13 -07:00
|
|
|
act4 = evry_action_new("New Application Entry", "APPLICATION", NULL, NULL,
|
2009-08-21 15:42:06 -07:00
|
|
|
"everything-launch",
|
2009-08-27 19:25:13 -07:00
|
|
|
_new_app_action, _new_app_check_item,
|
2010-04-10 15:38:05 -07:00
|
|
|
NULL, NULL, NULL, NULL);
|
2009-08-27 13:52:14 -07:00
|
|
|
|
2009-09-02 12:43:16 -07:00
|
|
|
act5 = evry_action_new("Run with Sudo", "APPLICATION", NULL, NULL,
|
|
|
|
"system-run",
|
2010-04-10 15:38:05 -07:00
|
|
|
_exec_sudo_action, NULL, NULL, NULL, NULL, NULL);
|
2009-09-02 12:43:16 -07:00
|
|
|
|
|
|
|
evry_action_register(act, 0);
|
2009-08-27 19:25:13 -07:00
|
|
|
evry_action_register(act1, 1);
|
|
|
|
evry_action_register(act2, 2);
|
|
|
|
evry_action_register(act3, 3);
|
|
|
|
evry_action_register(act4, 4);
|
2009-09-02 12:43:16 -07:00
|
|
|
evry_action_register(act5, 5);
|
2009-08-27 13:52:14 -07:00
|
|
|
|
2010-03-06 06:09:05 -08:00
|
|
|
/*
|
2010-04-10 13:05:57 -07:00
|
|
|
Eina_List *l, *ll;
|
|
|
|
const char *file, *name;
|
|
|
|
History_Entry *he;
|
|
|
|
History_Item *hi;
|
|
|
|
name = EVRY_PLUGIN(p1)->name;
|
|
|
|
double t;
|
|
|
|
int found = 0;
|
|
|
|
|
|
|
|
evry_history_load();
|
2009-09-24 20:40:18 -07:00
|
|
|
|
2010-04-10 13:05:57 -07:00
|
|
|
EINA_LIST_FOREACH(e_exehist_list_get(), l, file)
|
2009-09-24 20:40:18 -07:00
|
|
|
{
|
2010-04-10 13:05:57 -07:00
|
|
|
t = e_exehist_newest_run_get(file);
|
|
|
|
he = eina_hash_find(evry_hist->subjects, file);
|
2009-09-24 20:40:18 -07:00
|
|
|
|
2010-04-10 13:05:57 -07:00
|
|
|
if (!he)
|
|
|
|
{
|
|
|
|
he = E_NEW(History_Entry, 1);
|
|
|
|
eina_hash_add(evry_hist->subjects, file, he);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
EINA_LIST_FOREACH(he->items, ll, hi)
|
|
|
|
{
|
|
|
|
if (hi->plugin != name) continue;
|
2009-09-24 20:40:18 -07:00
|
|
|
|
2010-04-10 13:05:57 -07:00
|
|
|
if (t > hi->last_used - 1.0)
|
|
|
|
{
|
|
|
|
hi->last_used = t;
|
|
|
|
hi->usage += TIME_FACTOR(hi->last_used);
|
|
|
|
hi->count = e_exehist_popularity_get(file);
|
|
|
|
}
|
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
}
|
2009-09-24 20:40:18 -07:00
|
|
|
|
2010-04-10 13:05:57 -07:00
|
|
|
}
|
2009-09-24 20:40:18 -07:00
|
|
|
|
2010-04-10 13:05:57 -07:00
|
|
|
if (!found)
|
|
|
|
{
|
|
|
|
hi = E_NEW(History_Item, 1);
|
|
|
|
hi->plugin = eina_stringshare_ref(name);
|
|
|
|
hi->last_used = t;
|
|
|
|
hi->count = e_exehist_popularity_get(file);
|
|
|
|
hi->usage += TIME_FACTOR(hi->last_used);
|
|
|
|
he->items = eina_list_append(he->items, hi);
|
2009-09-24 20:40:18 -07:00
|
|
|
}
|
2010-04-10 13:05:57 -07:00
|
|
|
found = 0;
|
|
|
|
}
|
|
|
|
evry_history_unload();
|
2010-02-15 05:32:34 -08:00
|
|
|
*/
|
2009-08-10 08:00:41 -07:00
|
|
|
/* taken from e_exebuf.c */
|
2009-08-25 02:30:14 -07:00
|
|
|
exelist_exe_edd = E_CONFIG_DD_NEW("E_Exe", E_Exe);
|
|
|
|
#undef T
|
|
|
|
#undef D
|
|
|
|
#define T E_Exe
|
|
|
|
#define D exelist_exe_edd
|
|
|
|
E_CONFIG_VAL(D, T, path, STR);
|
2009-08-27 13:52:14 -07:00
|
|
|
|
2009-08-25 02:30:14 -07:00
|
|
|
exelist_edd = E_CONFIG_DD_NEW("E_Exe_List", E_Exe_List);
|
|
|
|
#undef T
|
|
|
|
#undef D
|
|
|
|
#define T E_Exe_List
|
|
|
|
#define D exelist_edd
|
|
|
|
E_CONFIG_LIST(D, T, list, exelist_exe_edd);
|
2009-08-27 13:52:14 -07:00
|
|
|
|
2009-08-10 08:00:41 -07:00
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-04-10 13:05:57 -07:00
|
|
|
module_shutdown(void)
|
2009-08-10 08:00:41 -07:00
|
|
|
{
|
2009-08-22 20:12:05 -07:00
|
|
|
EVRY_PLUGIN_FREE(p1);
|
|
|
|
EVRY_PLUGIN_FREE(p2);
|
2009-08-21 15:42:06 -07:00
|
|
|
|
2009-08-18 07:29:30 -07:00
|
|
|
evry_action_free(act);
|
|
|
|
evry_action_free(act1);
|
|
|
|
evry_action_free(act2);
|
|
|
|
evry_action_free(act3);
|
|
|
|
evry_action_free(act4);
|
2009-09-02 12:43:16 -07:00
|
|
|
evry_action_free(act5);
|
2009-08-10 08:00:41 -07:00
|
|
|
}
|
|
|
|
|
2009-08-25 02:30:14 -07:00
|
|
|
/* taken from e_exebuf.c */
|
|
|
|
static int
|
|
|
|
_scan_idler(void *data)
|
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
struct dirent *dp;
|
|
|
|
char *dir;
|
|
|
|
char buf[4096];
|
|
|
|
|
|
|
|
/* no more path items left - stop scanning */
|
|
|
|
if (!exe_path)
|
|
|
|
{
|
|
|
|
Eina_List *l, *l2;
|
|
|
|
E_Exe_List *el;
|
|
|
|
E_Exe *ee;
|
|
|
|
int different = 0;
|
2009-08-27 13:52:14 -07:00
|
|
|
|
2009-09-24 16:08:59 -07:00
|
|
|
/* FIXME: check wheter they match or not */
|
2009-08-25 02:30:14 -07:00
|
|
|
for (l = exe_list, l2 = exe_list2; l && l2; l = l->next, l2 = l2->next)
|
|
|
|
{
|
|
|
|
if (strcmp(l->data, l2->data))
|
|
|
|
{
|
|
|
|
different = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((l) || (l2)) different = 1;
|
|
|
|
if (exe_list2)
|
|
|
|
{
|
|
|
|
while (exe_list)
|
|
|
|
{
|
|
|
|
free(eina_list_data_get(exe_list));
|
|
|
|
exe_list = eina_list_remove_list(exe_list, exe_list);
|
|
|
|
}
|
|
|
|
exe_list = exe_list2;
|
|
|
|
exe_list2 = NULL;
|
|
|
|
}
|
|
|
|
if (different)
|
|
|
|
{
|
|
|
|
el = calloc(1, sizeof(E_Exe_List));
|
|
|
|
if (el)
|
|
|
|
{
|
|
|
|
el->list = NULL;
|
|
|
|
for (l = exe_list; l; l = l->next)
|
|
|
|
{
|
|
|
|
ee = malloc(sizeof(E_Exe));
|
|
|
|
if (ee)
|
|
|
|
{
|
|
|
|
ee->path = eina_stringshare_add(l->data);
|
|
|
|
el->list = eina_list_append(el->list, ee);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
e_config_domain_save("exebuf_exelist_cache", exelist_edd, el);
|
|
|
|
while (el->list)
|
|
|
|
{
|
|
|
|
ee = eina_list_data_get(el->list);
|
|
|
|
eina_stringshare_del(ee->path);
|
|
|
|
free(ee);
|
|
|
|
el->list = eina_list_remove_list(el->list, el->list);
|
|
|
|
}
|
|
|
|
free(el);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
exe_scan_idler = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* no dir is open - open the first path item */
|
|
|
|
if (!exe_dir)
|
|
|
|
{
|
|
|
|
dir = exe_path->data;
|
|
|
|
exe_dir = opendir(dir);
|
|
|
|
}
|
|
|
|
/* if we have an opened dir - scan the next item */
|
|
|
|
if (exe_dir)
|
|
|
|
{
|
|
|
|
dir = exe_path->data;
|
2009-08-27 13:52:14 -07:00
|
|
|
|
2009-08-25 02:30:14 -07:00
|
|
|
dp = readdir(exe_dir);
|
|
|
|
if (dp)
|
|
|
|
{
|
|
|
|
if ((strcmp(dp->d_name, ".")) && (strcmp(dp->d_name, "..")))
|
|
|
|
{
|
|
|
|
snprintf(buf, sizeof(buf), "%s/%s", dir, dp->d_name);
|
|
|
|
if ((stat(buf, &st) == 0) &&
|
|
|
|
((!S_ISDIR(st.st_mode)) &&
|
|
|
|
(!access(buf, X_OK))))
|
|
|
|
{
|
|
|
|
if (!exe_list)
|
|
|
|
exe_list = eina_list_append(exe_list, strdup(dp->d_name));
|
|
|
|
else
|
|
|
|
exe_list2 = eina_list_append(exe_list2, strdup(dp->d_name));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* we reached the end of a dir - remove the dir at the head
|
|
|
|
* of the path list so we advance and next loop we will pick up
|
|
|
|
* the next item, or if null- abort
|
|
|
|
*/
|
|
|
|
closedir(exe_dir);
|
|
|
|
exe_dir = NULL;
|
|
|
|
free(eina_list_data_get(exe_path));
|
|
|
|
exe_path = eina_list_remove_list(exe_path, exe_path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* obviously the dir open failed - so remove the first path item */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
free(eina_list_data_get(exe_path));
|
|
|
|
exe_path = eina_list_remove_list(exe_path, exe_path);
|
|
|
|
}
|
|
|
|
/* we have mroe scannign to do */
|
|
|
|
return 1;
|
|
|
|
}
|
2010-04-10 13:05:57 -07:00
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
/**/
|
|
|
|
/* actual module specifics */
|
|
|
|
|
|
|
|
static E_Module *module = NULL;
|
|
|
|
static Eina_Bool active = EINA_FALSE;
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
/**/
|
|
|
|
/* module setup */
|
|
|
|
EAPI E_Module_Api e_modapi =
|
|
|
|
{
|
|
|
|
E_MODULE_API_VERSION,
|
|
|
|
"everything-apps"
|
|
|
|
};
|
|
|
|
|
|
|
|
EAPI void *
|
|
|
|
e_modapi_init(E_Module *m)
|
|
|
|
{
|
|
|
|
module = m;
|
|
|
|
|
|
|
|
if (e_datastore_get("everything_loaded"))
|
|
|
|
active = module_init();
|
|
|
|
|
|
|
|
e_module_delayed_set(m, 1);
|
|
|
|
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI int
|
|
|
|
e_modapi_shutdown(E_Module *m)
|
|
|
|
{
|
|
|
|
if (active && e_datastore_get("everything_loaded"))
|
|
|
|
module_shutdown();
|
|
|
|
|
2010-04-10 14:38:36 -07:00
|
|
|
E_CONFIG_DD_FREE(exelist_edd);
|
|
|
|
E_CONFIG_DD_FREE(exelist_exe_edd);
|
|
|
|
|
2010-04-10 13:05:57 -07:00
|
|
|
module = NULL;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI int
|
|
|
|
e_modapi_save(E_Module *m)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**/
|
|
|
|
/***************************************************************************/
|
|
|
|
|