2009-05-06 07:20:45 -07:00
|
|
|
#include "e.h"
|
|
|
|
#include "e_mod_main.h"
|
|
|
|
|
2009-06-21 03:31:38 -07:00
|
|
|
typedef struct _Inst Inst;
|
2009-05-06 07:20:45 -07:00
|
|
|
|
2009-06-21 03:31:38 -07:00
|
|
|
struct _Inst
|
|
|
|
{
|
|
|
|
Eina_Hash *added;
|
2009-06-21 14:16:02 -07:00
|
|
|
Eina_List *apps;
|
|
|
|
Evry_Item *candidate;
|
2009-06-21 03:31:38 -07:00
|
|
|
};
|
|
|
|
|
2009-06-24 13:02:37 -07:00
|
|
|
static int _begin(Evry_Item *item);
|
|
|
|
static int _fetch(const char *input);
|
|
|
|
static int _action(Evry_Item *item, const char *input);
|
|
|
|
static void _cleanup(void);
|
|
|
|
static void _item_add(Efreet_Desktop *desktop, char *file, int prio);
|
2009-06-21 14:16:02 -07:00
|
|
|
static int _cb_sort(const void *data1, const void *data2);
|
2009-06-24 13:02:37 -07:00
|
|
|
static void _item_icon_get(Evry_Item *it, Evas *e);
|
|
|
|
static int _exec_action(void);
|
2009-05-06 07:20:45 -07:00
|
|
|
|
2009-06-24 13:02:37 -07:00
|
|
|
static Evry_Plugin *p;
|
|
|
|
static Evry_Action *act;
|
|
|
|
static Inst *inst;
|
2009-05-06 07:20:45 -07:00
|
|
|
|
2009-06-21 14:16:02 -07:00
|
|
|
|
2009-05-06 07:20:45 -07:00
|
|
|
EAPI int
|
2009-06-24 13:02:37 -07:00
|
|
|
evry_plug_apps_init(void)
|
2009-06-21 14:16:02 -07:00
|
|
|
{
|
2009-06-24 13:02:37 -07:00
|
|
|
p = E_NEW(Evry_Plugin, 1);
|
|
|
|
p->type_in = "NONE|FILE";
|
|
|
|
p->type_out = "NONE";
|
|
|
|
p->need_query = 0;
|
2009-06-21 14:16:02 -07:00
|
|
|
p->begin = &_begin;
|
|
|
|
p->fetch = &_fetch;
|
|
|
|
p->action = &_action;
|
|
|
|
p->cleanup = &_cleanup;
|
|
|
|
p->icon_get = &_item_icon_get;
|
2009-06-24 13:02:37 -07:00
|
|
|
evry_plugin_register(p);
|
2009-06-21 03:31:38 -07:00
|
|
|
|
2009-06-24 13:02:37 -07:00
|
|
|
act = E_NEW(Evry_Action, 1);
|
|
|
|
act->name = "Open File...";
|
|
|
|
act->type_in1 = "APPLICATION";
|
|
|
|
act->type_in2 = "FILE";
|
|
|
|
act->type_out = "NONE";
|
|
|
|
act->action =_exec_action;
|
|
|
|
evry_action_register(act);
|
2009-06-21 03:31:38 -07:00
|
|
|
|
2009-06-24 13:02:37 -07:00
|
|
|
inst = NULL;
|
2009-07-04 04:10:28 -07:00
|
|
|
|
2009-06-24 13:02:37 -07:00
|
|
|
return 1;
|
2009-06-21 03:31:38 -07:00
|
|
|
}
|
|
|
|
|
2009-06-24 13:02:37 -07:00
|
|
|
EAPI int
|
|
|
|
evry_plug_apps_shutdown(void)
|
2009-06-21 03:31:38 -07:00
|
|
|
{
|
2009-06-24 13:02:37 -07:00
|
|
|
evry_plugin_unregister(p);
|
|
|
|
evry_action_unregister(act);
|
|
|
|
|
|
|
|
return 1;
|
2009-06-21 03:31:38 -07:00
|
|
|
}
|
|
|
|
|
2009-05-06 07:20:45 -07:00
|
|
|
static int
|
2009-06-24 13:02:37 -07:00
|
|
|
_begin(Evry_Item *it)
|
2009-06-21 14:16:02 -07:00
|
|
|
{
|
|
|
|
const char *mime;
|
2009-07-04 04:10:28 -07:00
|
|
|
|
2009-06-24 13:02:37 -07:00
|
|
|
if (inst) return 0;
|
2009-06-21 14:16:02 -07:00
|
|
|
|
2009-06-24 13:02:37 -07:00
|
|
|
if (it)
|
|
|
|
{
|
|
|
|
p->name = "Open With...";
|
|
|
|
p->type_out = "NONE";
|
|
|
|
p->prio = 3;
|
|
|
|
|
|
|
|
if (!it->uri) return 0;
|
2009-07-04 04:10:28 -07:00
|
|
|
|
2009-06-24 13:02:37 -07:00
|
|
|
if (!it->mime)
|
|
|
|
mime = efreet_mime_type_get(it->uri);
|
|
|
|
else
|
|
|
|
mime = it->mime;
|
2009-07-04 04:10:28 -07:00
|
|
|
|
2009-06-24 13:02:37 -07:00
|
|
|
if (!mime) return 0;
|
2009-07-04 04:10:28 -07:00
|
|
|
|
2009-06-24 13:02:37 -07:00
|
|
|
inst = E_NEW(Inst, 1);
|
|
|
|
inst->candidate = it;
|
|
|
|
inst->apps = efreet_util_desktop_mime_list(mime);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
p->name = "Applications";
|
|
|
|
p->type_out = "APPLICATION";
|
|
|
|
p->prio = 1;
|
2009-07-04 04:10:28 -07:00
|
|
|
|
2009-06-24 13:02:37 -07:00
|
|
|
inst = E_NEW(Inst, 1);
|
|
|
|
}
|
2009-07-04 04:10:28 -07:00
|
|
|
|
2009-06-21 14:16:02 -07:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-06-24 13:02:37 -07:00
|
|
|
_action(Evry_Item *it, const char *input)
|
2009-05-06 07:20:45 -07:00
|
|
|
{
|
|
|
|
E_Zone *zone;
|
2009-06-22 11:33:17 -07:00
|
|
|
Evry_App *app = NULL;
|
2009-07-04 04:10:28 -07:00
|
|
|
Efreet_Desktop *desktop = NULL;
|
2009-06-21 14:16:02 -07:00
|
|
|
Eina_List *files = NULL;
|
2009-05-06 07:20:45 -07:00
|
|
|
|
2009-06-22 11:33:17 -07:00
|
|
|
if (it) app = it->data[0];
|
2009-07-04 04:10:28 -07:00
|
|
|
|
2009-06-22 11:33:17 -07:00
|
|
|
if (app && app->desktop)
|
2009-06-21 14:16:02 -07:00
|
|
|
{
|
|
|
|
desktop = app->desktop;
|
|
|
|
}
|
2009-06-22 11:33:17 -07:00
|
|
|
else
|
2009-06-21 14:16:02 -07:00
|
|
|
{
|
2009-06-22 11:33:17 -07:00
|
|
|
if (app && app->file)
|
2009-06-21 14:16:02 -07:00
|
|
|
input = app->file;
|
2009-07-04 04:10:28 -07:00
|
|
|
|
2009-06-21 14:16:02 -07:00
|
|
|
desktop = efreet_desktop_empty_new("");
|
|
|
|
if (strchr(input, '%'))
|
|
|
|
{
|
|
|
|
desktop->exec = strdup(input);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int len = strlen(input) + 4;
|
|
|
|
desktop->exec = malloc(len);
|
|
|
|
if (desktop->exec)
|
|
|
|
snprintf(desktop->exec, len, "%s %%U", input);
|
|
|
|
}
|
|
|
|
}
|
2009-05-06 07:20:45 -07:00
|
|
|
|
2009-06-21 14:16:02 -07:00
|
|
|
if (desktop)
|
|
|
|
{
|
2009-06-24 13:02:37 -07:00
|
|
|
if (inst->candidate)
|
|
|
|
files = eina_list_append(files, inst->candidate->uri);
|
|
|
|
|
2009-06-22 11:33:17 -07:00
|
|
|
zone = e_util_zone_current_get(e_manager_current_get());
|
2009-06-21 14:16:02 -07:00
|
|
|
e_exec(zone, desktop, NULL, files, NULL /*"everything"*/);
|
|
|
|
|
|
|
|
if (!it)
|
|
|
|
efreet_desktop_free(desktop);
|
2009-06-24 13:02:37 -07:00
|
|
|
|
|
|
|
eina_list_free(files);
|
|
|
|
|
2009-07-03 06:37:54 -07:00
|
|
|
return EVRY_ACTION_FINISHED;
|
2009-06-21 14:16:02 -07:00
|
|
|
}
|
2009-07-04 04:10:28 -07:00
|
|
|
|
2009-07-03 06:37:54 -07:00
|
|
|
return EVRY_ACTION_CONTINUE;
|
2009-05-06 07:20:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-06-24 13:02:37 -07:00
|
|
|
_list_free(void)
|
2009-05-06 07:20:45 -07:00
|
|
|
{
|
|
|
|
Evry_Item *it;
|
|
|
|
Evry_App *app;
|
2009-07-04 04:10:28 -07:00
|
|
|
|
2009-06-21 03:31:38 -07:00
|
|
|
EINA_LIST_FREE(p->items, it)
|
2009-05-06 07:20:45 -07:00
|
|
|
{
|
|
|
|
if (it->label) eina_stringshare_del(it->label);
|
2009-06-21 03:31:38 -07:00
|
|
|
app = it->data[0];
|
2009-07-03 06:37:54 -07:00
|
|
|
E_FREE(app);
|
|
|
|
E_FREE(it);
|
2009-05-06 07:20:45 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-24 13:02:37 -07:00
|
|
|
static void
|
|
|
|
_cleanup(void)
|
|
|
|
{
|
|
|
|
_list_free();
|
|
|
|
|
|
|
|
if (inst)
|
|
|
|
{
|
|
|
|
eina_list_free(inst->apps);
|
|
|
|
E_FREE(inst);
|
|
|
|
}
|
2009-07-04 04:10:28 -07:00
|
|
|
|
2009-06-24 13:02:37 -07:00
|
|
|
inst = NULL;
|
|
|
|
}
|
|
|
|
|
2009-05-06 07:20:45 -07:00
|
|
|
static int
|
2009-06-24 13:02:37 -07:00
|
|
|
_fetch(const char *input)
|
2009-05-06 07:20:45 -07:00
|
|
|
{
|
2009-06-21 14:16:02 -07:00
|
|
|
Eina_List *l;
|
2009-05-06 07:20:45 -07:00
|
|
|
Efreet_Desktop *desktop;
|
|
|
|
char *file;
|
2009-06-21 14:16:02 -07:00
|
|
|
char match1[4096];
|
|
|
|
char match2[4096];
|
2009-07-04 04:10:28 -07:00
|
|
|
|
|
|
|
_list_free();
|
2009-06-21 14:16:02 -07:00
|
|
|
|
|
|
|
if (inst->apps)
|
|
|
|
{
|
|
|
|
if (!input)
|
|
|
|
{
|
|
|
|
EINA_LIST_FOREACH(inst->apps, l, desktop)
|
2009-06-24 13:02:37 -07:00
|
|
|
_item_add(desktop, NULL, 1);
|
2009-06-21 14:16:02 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
snprintf(match1, sizeof(match1), "%s*", input);
|
|
|
|
snprintf(match2, sizeof(match2), "*%s*", input);
|
2009-05-06 07:20:45 -07:00
|
|
|
|
2009-06-21 14:16:02 -07:00
|
|
|
EINA_LIST_FOREACH(inst->apps, l, desktop)
|
|
|
|
{
|
2009-06-24 13:02:37 -07:00
|
|
|
if (e_util_glob_case_match(desktop->exec, match1))
|
|
|
|
_item_add(desktop, NULL, 1);
|
|
|
|
else if (e_util_glob_case_match(desktop->exec, match2))
|
|
|
|
_item_add(desktop, NULL, 2);
|
|
|
|
else if (e_util_glob_case_match(desktop->name, match1))
|
|
|
|
_item_add(desktop, NULL, 1);
|
|
|
|
else if (e_util_glob_case_match(desktop->name, match2))
|
|
|
|
_item_add(desktop, NULL, 2);
|
|
|
|
else if (desktop->comment)
|
|
|
|
{
|
|
|
|
if (e_util_glob_case_match(desktop->comment, match1))
|
|
|
|
_item_add(desktop, NULL, 3);
|
|
|
|
else if (e_util_glob_case_match(desktop->comment, match2))
|
|
|
|
_item_add(desktop, NULL, 4);
|
2009-06-21 14:16:02 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-07-04 04:10:28 -07:00
|
|
|
|
|
|
|
|
2009-06-21 14:16:02 -07:00
|
|
|
if (!p->items && input)
|
2009-05-06 07:20:45 -07:00
|
|
|
{
|
2009-06-21 14:16:02 -07:00
|
|
|
snprintf(match1, sizeof(match1), "%s*", input);
|
|
|
|
l = efreet_util_desktop_exec_glob_list(match1);
|
|
|
|
EINA_LIST_FREE(l, desktop)
|
2009-06-24 13:02:37 -07:00
|
|
|
_item_add(desktop, NULL, 1);
|
2009-07-04 04:10:28 -07:00
|
|
|
|
2009-06-21 14:16:02 -07:00
|
|
|
snprintf(match1, sizeof(match1), "*%s*", input);
|
|
|
|
l = efreet_util_desktop_name_glob_list(match1);
|
|
|
|
EINA_LIST_FREE(l, desktop)
|
2009-07-04 04:10:28 -07:00
|
|
|
_item_add(desktop, NULL, 2);
|
2009-05-06 07:20:45 -07:00
|
|
|
|
|
|
|
// TODO make these optional/configurable
|
2009-06-21 14:16:02 -07:00
|
|
|
l = efreet_util_desktop_generic_name_glob_list(match1);
|
|
|
|
EINA_LIST_FREE(l, desktop)
|
2009-07-04 04:10:28 -07:00
|
|
|
_item_add(desktop, NULL, 3);
|
2009-06-21 14:16:02 -07:00
|
|
|
|
|
|
|
l = efreet_util_desktop_comment_glob_list(match1);
|
|
|
|
EINA_LIST_FREE(l, desktop)
|
2009-06-24 13:02:37 -07:00
|
|
|
_item_add(desktop, NULL, 3);
|
2009-05-06 07:20:45 -07:00
|
|
|
}
|
2009-06-21 14:16:02 -07:00
|
|
|
else if (!p->items)
|
2009-05-06 07:20:45 -07:00
|
|
|
{
|
|
|
|
// TODO option for popular/recent
|
2009-06-21 14:16:02 -07:00
|
|
|
l = e_exehist_list_get();
|
|
|
|
EINA_LIST_FREE(l, file)
|
2009-06-24 13:02:37 -07:00
|
|
|
_item_add(NULL, file, 1);
|
2009-05-06 07:20:45 -07:00
|
|
|
}
|
2009-07-04 04:10:28 -07:00
|
|
|
|
2009-06-21 03:31:38 -07:00
|
|
|
if (inst->added)
|
2009-05-06 07:20:45 -07:00
|
|
|
{
|
2009-06-21 03:31:38 -07:00
|
|
|
eina_hash_free(inst->added);
|
|
|
|
inst->added = NULL;
|
2009-06-21 14:16:02 -07:00
|
|
|
}
|
2009-07-04 04:10:28 -07:00
|
|
|
|
2009-06-21 14:16:02 -07:00
|
|
|
if (p->items)
|
|
|
|
{
|
|
|
|
if (input)
|
2009-06-24 13:02:37 -07:00
|
|
|
p->items = eina_list_sort(p->items, eina_list_count(p->items), _cb_sort);
|
2009-05-06 07:20:45 -07:00
|
|
|
return 1;
|
|
|
|
}
|
2009-07-04 04:10:28 -07:00
|
|
|
|
2009-05-06 07:20:45 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-06-24 13:02:37 -07:00
|
|
|
_item_add(Efreet_Desktop *desktop, char *file, int prio)
|
2009-05-06 07:20:45 -07:00
|
|
|
{
|
|
|
|
Evry_Item *it;
|
|
|
|
Evry_App *app;
|
2009-06-21 14:16:02 -07:00
|
|
|
Efreet_Desktop *desktop2;
|
2009-06-22 11:33:17 -07:00
|
|
|
|
2009-05-06 07:20:45 -07:00
|
|
|
if (desktop)
|
2009-06-24 13:02:37 -07:00
|
|
|
{
|
|
|
|
Eina_List *l;
|
|
|
|
char *cat;
|
2009-05-06 07:20:45 -07:00
|
|
|
|
2009-06-24 13:02:37 -07:00
|
|
|
/* ignore screensaver.. */
|
|
|
|
EINA_LIST_FOREACH(desktop->categories, l, cat)
|
|
|
|
{
|
|
|
|
if (cat && !strcmp(cat, "Screensaver"))
|
|
|
|
return;
|
|
|
|
}
|
2009-07-04 04:10:28 -07:00
|
|
|
|
2009-06-24 13:02:37 -07:00
|
|
|
file = desktop->exec;
|
|
|
|
}
|
2009-07-04 04:10:28 -07:00
|
|
|
|
2009-05-06 07:20:45 -07:00
|
|
|
if (!file) return;
|
2009-06-21 14:16:02 -07:00
|
|
|
|
2009-06-21 03:31:38 -07:00
|
|
|
if (!inst->added)
|
|
|
|
inst->added = eina_hash_string_superfast_new(NULL);
|
2009-05-06 07:20:45 -07:00
|
|
|
|
2009-06-22 11:33:17 -07:00
|
|
|
|
|
|
|
if (!desktop)
|
|
|
|
{
|
|
|
|
char match[4096];
|
|
|
|
Eina_List *l;
|
|
|
|
int len;
|
|
|
|
char *tmp;
|
|
|
|
int found = 0;
|
2009-07-04 04:10:28 -07:00
|
|
|
|
2009-06-22 11:33:17 -07:00
|
|
|
if (eina_hash_find(inst->added, file))
|
|
|
|
return;
|
|
|
|
|
|
|
|
len = strlen(file);
|
|
|
|
tmp = ecore_file_app_exe_get(file);
|
2009-07-04 04:10:28 -07:00
|
|
|
snprintf(match, sizeof(match), "%s*", tmp);
|
2009-06-22 11:33:17 -07:00
|
|
|
l = efreet_util_desktop_exec_glob_list(match);
|
|
|
|
|
|
|
|
EINA_LIST_FREE(l, desktop)
|
|
|
|
{
|
|
|
|
if (desktop->exec && !strncmp(file, desktop->exec, len))
|
|
|
|
{
|
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
eina_list_free(l);
|
|
|
|
free(tmp);
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
eina_hash_add(inst->added, file, file);
|
|
|
|
}
|
2009-05-06 07:20:45 -07:00
|
|
|
|
|
|
|
if (desktop)
|
|
|
|
{
|
2009-06-22 11:33:17 -07:00
|
|
|
if ((desktop2 = eina_hash_find(inst->added, file)))
|
|
|
|
if (desktop == desktop2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
eina_hash_add(inst->added, file, desktop);
|
2009-05-06 07:20:45 -07:00
|
|
|
file = NULL;
|
|
|
|
}
|
2009-07-04 04:10:28 -07:00
|
|
|
|
2009-07-03 06:37:54 -07:00
|
|
|
it = E_NEW(Evry_Item, 1);
|
|
|
|
app = E_NEW(Evry_App, 1);
|
2009-05-06 07:20:45 -07:00
|
|
|
app->desktop = desktop;
|
|
|
|
app->file = file;
|
2009-06-21 03:31:38 -07:00
|
|
|
it->data[0] = app;
|
2009-05-06 07:20:45 -07:00
|
|
|
it->priority = prio;
|
|
|
|
if (desktop)
|
|
|
|
it->label = eina_stringshare_add(desktop->name);
|
|
|
|
else
|
|
|
|
it->label = eina_stringshare_add(file);
|
|
|
|
it->o_icon = NULL;
|
|
|
|
|
2009-06-21 03:31:38 -07:00
|
|
|
p->items = eina_list_append(p->items, it);
|
2009-05-06 07:20:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-06-24 13:02:37 -07:00
|
|
|
_item_icon_get(Evry_Item *it, Evas *e)
|
2009-05-06 07:20:45 -07:00
|
|
|
{
|
2009-06-21 03:31:38 -07:00
|
|
|
Evry_App *app = it->data[0];
|
2009-07-04 04:10:28 -07:00
|
|
|
|
2009-05-06 07:20:45 -07:00
|
|
|
if (app->desktop)
|
|
|
|
it->o_icon = e_util_desktop_icon_add(app->desktop, 24, e);
|
2009-06-21 16:25:39 -07:00
|
|
|
|
|
|
|
if (!it->o_icon)
|
|
|
|
{
|
|
|
|
it->o_icon = edje_object_add(e);
|
|
|
|
/* e_util_icon_theme_set(it->o_icon, "system-run") */
|
|
|
|
e_theme_edje_object_set(it->o_icon, "base/theme/fileman", "e/icons/system-run");
|
|
|
|
}
|
2009-05-06 07:20:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-06-21 14:16:02 -07:00
|
|
|
_cb_sort(const void *data1, const void *data2)
|
2009-05-06 07:20:45 -07:00
|
|
|
{
|
|
|
|
const Evry_Item *it1, *it2;
|
|
|
|
Evry_App *app1, *app2;
|
|
|
|
const char *e1, *e2;
|
|
|
|
double t1, t2;
|
2009-07-04 04:10:28 -07:00
|
|
|
|
2009-05-06 07:20:45 -07:00
|
|
|
it1 = data1;
|
|
|
|
it2 = data2;
|
2009-06-21 03:31:38 -07:00
|
|
|
app1 = it1->data[0];
|
|
|
|
app2 = it2->data[0];
|
2009-05-06 07:20:45 -07:00
|
|
|
e1 = efreet_util_path_to_file_id(app1->desktop->orig_path);
|
|
|
|
e2 = efreet_util_path_to_file_id(app2->desktop->orig_path);
|
|
|
|
t1 = e_exehist_newest_run_get(e1);
|
|
|
|
t2 = e_exehist_newest_run_get(e2);
|
|
|
|
|
|
|
|
if ((int)(t1 - t2))
|
|
|
|
return (int)(t1 - t2);
|
|
|
|
else if (it1->priority - it2->priority)
|
|
|
|
return (it1->priority - it2->priority);
|
|
|
|
// TODO compare exe strings?
|
|
|
|
else return 0;
|
|
|
|
}
|
2009-06-24 13:02:37 -07:00
|
|
|
|
|
|
|
static int
|
|
|
|
_exec_action(void)
|
|
|
|
{
|
|
|
|
if (act->thing1 && act->thing2)
|
|
|
|
{
|
|
|
|
inst = E_NEW(Inst, 1);
|
|
|
|
inst->candidate = act->thing2;
|
|
|
|
|
|
|
|
_action(act->thing1, NULL);
|
2009-07-04 04:10:28 -07:00
|
|
|
|
2009-06-24 13:02:37 -07:00
|
|
|
E_FREE(inst);
|
|
|
|
inst = NULL;
|
2009-07-04 04:10:28 -07:00
|
|
|
|
2009-06-24 13:02:37 -07:00
|
|
|
return 1;
|
|
|
|
}
|
2009-07-04 04:10:28 -07:00
|
|
|
|
2009-06-24 13:02:37 -07:00
|
|
|
return 0;
|
|
|
|
}
|