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-08-11 09:07:30 -07:00
|
|
|
Eina_List *apps_mime;
|
|
|
|
Eina_List *apps_all;
|
2009-08-12 05:17:43 -07:00
|
|
|
const Evry_Item *candidate;
|
2009-06-21 03:31:38 -07:00
|
|
|
};
|
|
|
|
|
2009-07-07 09:30:11 -07:00
|
|
|
static Evry_Plugin *p1;
|
|
|
|
static Evry_Plugin *p2;
|
2009-06-24 13:02:37 -07:00
|
|
|
static Evry_Action *act;
|
2009-08-10 04:36:37 -07:00
|
|
|
static Evry_Action *act1;
|
2009-07-15 05:22:42 -07:00
|
|
|
static Evry_Action *act2;
|
|
|
|
static Evry_Action *act3;
|
2009-08-10 04:36:37 -07:00
|
|
|
static Eina_List *exe_path = NULL;
|
2009-06-21 14:16:02 -07:00
|
|
|
|
2009-06-21 03:31:38 -07:00
|
|
|
|
2009-05-06 07:20:45 -07:00
|
|
|
static int
|
2009-08-12 05:17:43 -07:00
|
|
|
_begin(Evry_Plugin *p, const Evry_Item *it)
|
2009-06-21 14:16:02 -07:00
|
|
|
{
|
|
|
|
const char *mime;
|
2009-08-10 04:36:37 -07:00
|
|
|
Inst *inst = NULL;
|
2009-08-12 12:00:25 -07:00
|
|
|
|
2009-06-24 13:02:37 -07:00
|
|
|
if (it)
|
|
|
|
{
|
2009-08-11 07:00:51 -07:00
|
|
|
Eina_List *l;
|
|
|
|
Efreet_Desktop *desktop;
|
|
|
|
|
2009-06-24 13:02:37 -07:00
|
|
|
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-08-11 09:07:30 -07:00
|
|
|
/* TODO show plugin for items without mimetype ? */
|
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;
|
2009-08-11 09:07:30 -07:00
|
|
|
inst->apps_mime = efreet_util_desktop_mime_list(mime);
|
2009-08-11 07:00:51 -07:00
|
|
|
desktop = e_exehist_mime_desktop_get(mime);
|
|
|
|
if (desktop)
|
2009-07-08 15:06:14 -07:00
|
|
|
{
|
2009-08-11 07:00:51 -07:00
|
|
|
efreet_desktop_ref(desktop);
|
2009-08-11 09:07:30 -07:00
|
|
|
inst->apps_mime = eina_list_prepend(inst->apps_mime, desktop);
|
2009-07-08 15:06:14 -07:00
|
|
|
}
|
2009-06-24 13:02:37 -07:00
|
|
|
}
|
2009-08-11 09:07:30 -07:00
|
|
|
else
|
|
|
|
{
|
|
|
|
inst = E_NEW(Inst, 1);
|
|
|
|
}
|
2009-08-12 12:00:25 -07:00
|
|
|
|
2009-08-10 04:36:37 -07:00
|
|
|
p->private = inst;
|
2009-08-12 12:00:25 -07:00
|
|
|
|
2009-06-21 14:16:02 -07:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-05-06 07:20:45 -07:00
|
|
|
static void
|
2009-07-07 09:30:11 -07:00
|
|
|
_list_free(Evry_Plugin *p)
|
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
|
|
|
{
|
2009-06-21 03:31:38 -07:00
|
|
|
app = it->data[0];
|
2009-08-10 04:36:37 -07:00
|
|
|
if (app->file) eina_stringshare_del(app->file);
|
2009-08-10 11:39:11 -07:00
|
|
|
if (app->desktop) efreet_desktop_free(app->desktop);
|
2009-07-03 06:37:54 -07:00
|
|
|
E_FREE(app);
|
2009-08-10 04:36:37 -07:00
|
|
|
evry_item_free(it);
|
2009-05-06 07:20:45 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-24 13:02:37 -07:00
|
|
|
static void
|
2009-07-07 09:30:11 -07:00
|
|
|
_cleanup(Evry_Plugin *p)
|
2009-06-24 13:02:37 -07:00
|
|
|
{
|
2009-08-10 04:36:37 -07:00
|
|
|
Inst *inst = p->private;
|
2009-08-12 12:00:25 -07:00
|
|
|
|
2009-07-07 09:30:11 -07:00
|
|
|
_list_free(p);
|
2009-06-24 13:02:37 -07:00
|
|
|
|
|
|
|
if (inst)
|
|
|
|
{
|
2009-08-11 09:07:30 -07:00
|
|
|
Efreet_Desktop *desktop;
|
|
|
|
EINA_LIST_FREE(inst->apps_mime, desktop)
|
|
|
|
efreet_desktop_free(desktop);
|
|
|
|
EINA_LIST_FREE(inst->apps_all, desktop)
|
|
|
|
efreet_desktop_free(desktop);
|
2009-08-12 12:00:25 -07:00
|
|
|
|
2009-06-24 13:02:37 -07:00
|
|
|
E_FREE(inst);
|
|
|
|
}
|
2009-07-04 04:10:28 -07:00
|
|
|
|
2009-08-10 04:36:37 -07:00
|
|
|
p->private = NULL;
|
2009-06-24 13:02:37 -07:00
|
|
|
}
|
|
|
|
|
2009-08-11 09:07:30 -07:00
|
|
|
static int
|
2009-08-10 08:00:41 -07:00
|
|
|
_item_add(Evry_Plugin *p, Efreet_Desktop *desktop, char *file, int prio)
|
|
|
|
{
|
|
|
|
Evry_Item *it;
|
|
|
|
Evry_App *app;
|
2009-08-10 11:39:11 -07:00
|
|
|
Efreet_Desktop *d2;
|
2009-08-10 08:00:41 -07:00
|
|
|
Inst *inst = p->private;
|
2009-08-11 09:07:30 -07:00
|
|
|
int already_refd = 0;
|
2009-08-12 12:00:25 -07:00
|
|
|
|
2009-08-10 08:00:41 -07:00
|
|
|
if (desktop)
|
|
|
|
file = desktop->exec;
|
|
|
|
|
2009-08-11 09:07:30 -07:00
|
|
|
if (!file) return 0;
|
2009-08-12 12:00:25 -07:00
|
|
|
|
2009-08-10 08:00:41 -07:00
|
|
|
if (!desktop)
|
|
|
|
{
|
|
|
|
char match[4096];
|
|
|
|
Eina_List *l;
|
|
|
|
int len;
|
|
|
|
char *tmp;
|
|
|
|
|
2009-08-10 09:31:22 -07:00
|
|
|
if (eina_hash_find(inst->added, file))
|
2009-08-11 09:07:30 -07:00
|
|
|
return 0;
|
2009-08-10 08:00:41 -07:00
|
|
|
|
|
|
|
len = strlen(file);
|
|
|
|
tmp = ecore_file_app_exe_get(file);
|
|
|
|
snprintf(match, sizeof(match), "%s*", tmp);
|
|
|
|
l = efreet_util_desktop_exec_glob_list(match);
|
|
|
|
|
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);
|
|
|
|
|
2009-08-10 11:39:11 -07:00
|
|
|
if (!desktop)
|
2009-08-10 08:00:41 -07:00
|
|
|
eina_hash_add(inst->added, file, file);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (desktop)
|
|
|
|
{
|
2009-08-10 11:39:11 -07:00
|
|
|
if ((d2 = eina_hash_find(inst->added, file)) &&
|
|
|
|
((desktop == d2) ||
|
|
|
|
(!strcmp(desktop->exec, d2->exec))))
|
2009-08-11 09:07:30 -07:00
|
|
|
return 0;
|
2009-08-10 09:31:22 -07:00
|
|
|
|
2009-08-11 09:07:30 -07:00
|
|
|
if (!already_refd)
|
|
|
|
efreet_desktop_ref(desktop);
|
2009-08-10 08:00:41 -07:00
|
|
|
eina_hash_add(inst->added, file, desktop);
|
|
|
|
file = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (desktop)
|
|
|
|
it = evry_item_new(p, desktop->name);
|
|
|
|
else
|
|
|
|
it = evry_item_new(p, file);
|
2009-08-12 12:00:25 -07:00
|
|
|
|
2009-08-10 08:00:41 -07:00
|
|
|
app = E_NEW(Evry_App, 1);
|
|
|
|
app->desktop = desktop;
|
|
|
|
app->file = file;
|
|
|
|
it->data[0] = app;
|
|
|
|
it->priority = prio;
|
|
|
|
|
|
|
|
p->items = eina_list_append(p->items, it);
|
2009-08-11 09:07:30 -07:00
|
|
|
|
|
|
|
return 1;
|
2009-08-10 08:00:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_add_desktop_list(Evry_Plugin *p, Eina_List *apps, char *m1, char *m2)
|
|
|
|
{
|
|
|
|
Efreet_Desktop *desktop;
|
|
|
|
Eina_List *l;
|
2009-08-12 12:00:25 -07:00
|
|
|
|
2009-08-10 08:00:41 -07:00
|
|
|
EINA_LIST_FOREACH(apps, l, desktop)
|
|
|
|
{
|
|
|
|
if (eina_list_count(p->items) > 99) continue;
|
|
|
|
if (!desktop || !desktop->name || !desktop->exec) continue;
|
2009-08-12 12:00:25 -07:00
|
|
|
|
2009-08-10 08:00:41 -07:00
|
|
|
if (e_util_glob_case_match(desktop->exec, m1))
|
|
|
|
_item_add(p, desktop, NULL, 1);
|
|
|
|
else if (e_util_glob_case_match(desktop->name, m1))
|
|
|
|
_item_add(p, desktop, NULL, 1);
|
2009-08-11 06:31:38 -07:00
|
|
|
}
|
|
|
|
EINA_LIST_FOREACH(apps, l, desktop)
|
|
|
|
{
|
|
|
|
if (eina_list_count(p->items) > 99) continue;
|
|
|
|
if (!desktop || !desktop->name || !desktop->exec) continue;
|
2009-08-12 12:00:25 -07:00
|
|
|
|
2009-08-11 06:31:38 -07:00
|
|
|
if (e_util_glob_case_match(desktop->exec, m2))
|
|
|
|
_item_add(p, desktop, NULL, 2);
|
2009-08-10 08:00:41 -07:00
|
|
|
else if (e_util_glob_case_match(desktop->name, m2))
|
|
|
|
_item_add(p, desktop, NULL, 2);
|
|
|
|
/* else if (desktop->comment)
|
|
|
|
* {
|
|
|
|
* if (e_util_glob_case_match(desktop->comment, m1))
|
|
|
|
* _item_add(p, desktop, NULL, 3);
|
|
|
|
* else if (e_util_glob_case_match(desktop->comment, m2))
|
|
|
|
* _item_add(p, desktop, NULL, 4);
|
|
|
|
* } */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
_cb_sort(const void *data1, const void *data2)
|
|
|
|
{
|
|
|
|
const Evry_Item *it1, *it2;
|
|
|
|
Evry_App *app1, *app2;
|
|
|
|
const char *e1, *e2;
|
|
|
|
double t1, t2;
|
|
|
|
|
|
|
|
it1 = data1;
|
|
|
|
it2 = data2;
|
2009-08-11 06:31:38 -07:00
|
|
|
|
|
|
|
if (it1->priority - it2->priority)
|
|
|
|
return (it1->priority - it2->priority);
|
|
|
|
|
2009-08-10 08:00:41 -07:00
|
|
|
app1 = it1->data[0];
|
|
|
|
app2 = it2->data[0];
|
|
|
|
|
|
|
|
if (app1->desktop)
|
|
|
|
e1 = app1->desktop->exec;
|
|
|
|
else
|
|
|
|
e1 = app1->file;
|
|
|
|
|
|
|
|
if (app2->desktop)
|
|
|
|
e2 = app2->desktop->exec;
|
|
|
|
else
|
|
|
|
e2 = app2->file;
|
|
|
|
|
|
|
|
t1 = e_exehist_newest_run_get(e1);
|
|
|
|
t2 = e_exehist_newest_run_get(e2);
|
|
|
|
|
|
|
|
if ((int)(t2 - t1))
|
|
|
|
return (int)(t2 - t1);
|
2009-08-12 12:00:25 -07:00
|
|
|
|
2009-08-10 08:00:41 -07:00
|
|
|
// TODO compare exe strings?
|
|
|
|
else return 0;
|
|
|
|
}
|
|
|
|
|
2009-05-06 07:20:45 -07:00
|
|
|
static int
|
2009-07-07 09:30:11 -07:00
|
|
|
_fetch(Evry_Plugin *p, 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-15 05:22:42 -07:00
|
|
|
Evry_Item *it;
|
|
|
|
Evry_App *app;
|
2009-08-10 04:36:37 -07:00
|
|
|
Inst *inst = p->private;
|
2009-08-11 09:07:30 -07:00
|
|
|
|
|
|
|
inst->added = eina_hash_string_small_new(NULL);
|
2009-08-12 12:00:25 -07:00
|
|
|
|
2009-07-07 09:30:11 -07:00
|
|
|
_list_free(p);
|
2009-06-21 14:16:02 -07:00
|
|
|
|
2009-08-10 08:00:41 -07:00
|
|
|
if (input)
|
|
|
|
{
|
|
|
|
snprintf(match1, sizeof(match1), "%s*", input);
|
|
|
|
snprintf(match2, sizeof(match2), "*%s*", input);
|
|
|
|
}
|
2009-08-10 04:36:37 -07:00
|
|
|
|
2009-08-10 08:00:41 -07:00
|
|
|
/* add apps for a given mimetype */
|
2009-08-11 09:07:30 -07:00
|
|
|
if (p->type == type_action)
|
2009-06-21 14:16:02 -07:00
|
|
|
{
|
2009-08-11 09:07:30 -07:00
|
|
|
if (input)
|
2009-06-21 14:16:02 -07:00
|
|
|
{
|
2009-08-11 09:07:30 -07:00
|
|
|
_add_desktop_list(p, inst->apps_mime, match1, match2);
|
2009-06-21 14:16:02 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-08-11 09:07:30 -07:00
|
|
|
EINA_LIST_FOREACH(inst->apps_mime, l, desktop)
|
|
|
|
_item_add(p, desktop, NULL, 1);
|
2009-06-21 14:16:02 -07:00
|
|
|
}
|
2009-08-11 09:07:30 -07:00
|
|
|
|
|
|
|
if (input)
|
|
|
|
EINA_LIST_FOREACH(p->items, l, it)
|
|
|
|
it->priority += 2;
|
2009-06-21 14:16:02 -07:00
|
|
|
}
|
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
|
|
|
{
|
|
|
|
if (!inst->apps_all)
|
2009-08-12 12:00:25 -07:00
|
|
|
inst->apps_all = efreet_util_desktop_name_glob_list("*");
|
2009-08-10 08:57:38 -07:00
|
|
|
|
2009-08-12 12:00:25 -07:00
|
|
|
_add_desktop_list(p, inst->apps_all, match1, match2);
|
2009-08-11 10:03:36 -07:00
|
|
|
}
|
2009-08-10 08:57:38 -07:00
|
|
|
/* add exe history items */
|
2009-07-15 16:14:53 -07:00
|
|
|
else if (!p->items)
|
|
|
|
{
|
|
|
|
l = e_exehist_list_get();
|
|
|
|
EINA_LIST_FREE(l, file)
|
2009-08-12 12:00:25 -07:00
|
|
|
_item_add(p, NULL, file, 1);
|
2009-07-15 16:14:53 -07:00
|
|
|
}
|
2009-07-04 04:10:28 -07:00
|
|
|
|
2009-08-10 08:57:38 -07:00
|
|
|
/* show 'Run Command' item */
|
|
|
|
if (input || p == p2)
|
2009-08-10 04:36:37 -07:00
|
|
|
{
|
|
|
|
int found = 0;
|
|
|
|
char *path;
|
2009-08-10 09:31:22 -07:00
|
|
|
char *end;
|
|
|
|
|
|
|
|
if (input)
|
2009-08-10 04:36:37 -07:00
|
|
|
{
|
2009-08-10 09:31:22 -07:00
|
|
|
snprintf(match2, 4096, "%s", input);
|
2009-08-12 12:00:25 -07:00
|
|
|
|
2009-08-10 09:31:22 -07:00
|
|
|
if (end = strchr(input, ' '))
|
2009-08-10 04:36:37 -07:00
|
|
|
{
|
2009-08-10 09:31:22 -07:00
|
|
|
int len = (end - input) - 1;
|
|
|
|
if (len >= 0)
|
|
|
|
snprintf(match2, len, "%s", input);
|
|
|
|
}
|
2009-08-12 12:00:25 -07:00
|
|
|
|
2009-08-10 09:31:22 -07:00
|
|
|
EINA_LIST_FOREACH(exe_path, l, path)
|
|
|
|
{
|
|
|
|
snprintf(match1, 4096, "%s/%s", path, match2);
|
|
|
|
if (ecore_file_exists(match1))
|
|
|
|
{
|
|
|
|
found = 1;
|
|
|
|
break;
|
2009-08-12 12:00:25 -07:00
|
|
|
}
|
2009-08-10 04:36:37 -07:00
|
|
|
}
|
|
|
|
}
|
2009-08-12 12:00:25 -07:00
|
|
|
|
2009-08-10 04:36:37 -07:00
|
|
|
if (found || p == p2)
|
|
|
|
{
|
2009-08-10 08:57:38 -07:00
|
|
|
it = evry_item_new(p, _("Run Command"));
|
|
|
|
app = E_NEW(Evry_App, 1);
|
2009-08-10 09:31:22 -07:00
|
|
|
if (input)
|
|
|
|
app->file = eina_stringshare_add(input);
|
|
|
|
else
|
|
|
|
app->file = eina_stringshare_add("");
|
2009-08-10 08:57:38 -07:00
|
|
|
it->data[0] = app;
|
2009-08-10 09:31:22 -07:00
|
|
|
it->priority = 99;
|
2009-08-10 08:57:38 -07:00
|
|
|
p->items = eina_list_append(p->items, it);
|
|
|
|
|
2009-08-10 04:36:37 -07:00
|
|
|
snprintf(match1, 4096, "xterm -hold -e %s", input);
|
2009-08-10 08:57:38 -07:00
|
|
|
it = evry_item_new(p, _("Run in Terminal"));
|
2009-08-10 04:36:37 -07:00
|
|
|
app = E_NEW(Evry_App, 1);
|
2009-08-10 09:31:22 -07:00
|
|
|
if (input)
|
2009-08-10 11:39:11 -07:00
|
|
|
app->file = eina_stringshare_add(match1);
|
2009-08-10 09:31:22 -07:00
|
|
|
else
|
|
|
|
app->file = eina_stringshare_add("");
|
2009-08-10 04:36:37 -07:00
|
|
|
it->data[0] = app;
|
|
|
|
it->priority = 100;
|
|
|
|
p->items = eina_list_append(p->items, it);
|
|
|
|
}
|
|
|
|
}
|
2009-05-06 07:20:45 -07:00
|
|
|
|
2009-08-11 09:07:30 -07:00
|
|
|
eina_hash_free(inst->added);
|
2009-07-04 04:10:28 -07:00
|
|
|
|
2009-08-10 08:00:41 -07:00
|
|
|
if (p->items)
|
2009-05-06 07:20:45 -07:00
|
|
|
{
|
2009-08-10 08:00:41 -07:00
|
|
|
p->items = eina_list_sort(p->items, eina_list_count(p->items), _cb_sort);
|
|
|
|
return 1;
|
2009-05-06 07:20:45 -07:00
|
|
|
}
|
2009-07-04 04:10:28 -07:00
|
|
|
|
2009-08-10 08:00:41 -07:00
|
|
|
return 0;
|
2009-05-06 07:20:45 -07:00
|
|
|
}
|
|
|
|
|
2009-08-10 04:36:37 -07:00
|
|
|
static Evas_Object *
|
2009-08-12 05:17:43 -07:00
|
|
|
_item_icon_get(Evry_Plugin *p __UNUSED__, const Evry_Item *it, Evas *e)
|
2009-05-06 07:20:45 -07:00
|
|
|
{
|
2009-08-10 04:36:37 -07:00
|
|
|
Evas_Object *o = NULL;
|
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)
|
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-06-21 16:25:39 -07:00
|
|
|
{
|
2009-08-10 04:36:37 -07:00
|
|
|
o = e_icon_add(e);
|
|
|
|
evry_icon_theme_set(o, "system-run");
|
2009-06-21 16:25:39 -07:00
|
|
|
}
|
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
|
|
|
{
|
|
|
|
Evry_App *app = it->data[0];
|
|
|
|
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-06-24 13:02:37 -07:00
|
|
|
static int
|
2009-08-12 05:17:43 -07:00
|
|
|
_app_action(const Evry_Item *it_app, const Evry_Item *it_file)
|
2009-06-24 13:02:37 -07:00
|
|
|
{
|
2009-08-10 04:36:37 -07:00
|
|
|
E_Zone *zone;
|
|
|
|
Evry_App *app = NULL;
|
|
|
|
Efreet_Desktop *desktop = NULL;
|
|
|
|
Eina_List *files = NULL;
|
2009-08-10 08:57:38 -07:00
|
|
|
char *exe = NULL;
|
2009-08-12 12:00:25 -07:00
|
|
|
|
2009-08-10 08:00:41 -07:00
|
|
|
if (!it_app) return 0;
|
2009-08-12 12:00:25 -07:00
|
|
|
|
2009-08-10 08:00:41 -07:00
|
|
|
app = it_app->data[0];
|
2009-08-10 08:57:38 -07:00
|
|
|
if (!app) return 0;
|
2009-08-12 12:00:25 -07:00
|
|
|
|
2009-08-10 08:00:41 -07:00
|
|
|
zone = e_util_zone_current_get(e_manager_current_get());
|
2009-08-12 12:00:25 -07:00
|
|
|
|
2009-08-10 08:00:41 -07:00
|
|
|
if (app->desktop)
|
2009-08-10 04:36:37 -07:00
|
|
|
{
|
2009-08-10 08:57:38 -07:00
|
|
|
if (it_file && it_file->uri)
|
|
|
|
files = eina_list_append(files, it_file->uri);
|
|
|
|
|
|
|
|
e_exec(zone, app->desktop, NULL, files, "everything");
|
2009-08-12 12:00:25 -07:00
|
|
|
|
2009-08-10 08:00:41 -07:00
|
|
|
if (it_file && it_file->mime)
|
2009-08-10 08:57:38 -07:00
|
|
|
e_exehist_mime_desktop_add(it_file->mime, app->desktop);
|
|
|
|
|
|
|
|
if (files) eina_list_free(files);
|
2009-08-10 08:00:41 -07:00
|
|
|
}
|
2009-08-10 08:57:38 -07:00
|
|
|
else if (app->file)
|
|
|
|
{
|
|
|
|
if (it_file && it_file->uri)
|
|
|
|
{
|
|
|
|
int len;
|
2009-07-15 05:22:42 -07:00
|
|
|
|
2009-08-10 08:57:38 -07:00
|
|
|
len = strlen(app->file) + strlen(it_file->uri) + 2;
|
|
|
|
exe = malloc(len);
|
|
|
|
snprintf(exe, len, "%s %s", app->file, it_file->uri);
|
|
|
|
}
|
|
|
|
else exe = (char *) app->file;
|
2009-08-12 12:00:25 -07:00
|
|
|
|
2009-08-10 08:57:38 -07:00
|
|
|
e_exec(zone, NULL, exe, NULL, NULL);
|
2009-07-15 05:22:42 -07:00
|
|
|
|
2009-08-10 08:57:38 -07:00
|
|
|
if (it_file && it_file->uri)
|
|
|
|
free(exe);
|
|
|
|
}
|
2009-07-15 05:22:42 -07:00
|
|
|
|
2009-08-10 08:00:41 -07:00
|
|
|
return 1;
|
|
|
|
}
|
2009-07-15 05:22:42 -07:00
|
|
|
|
2009-08-10 08:00:41 -07:00
|
|
|
static int
|
2009-08-12 05:17:43 -07:00
|
|
|
_exec_app_action(Evry_Action *act, const Evry_Item *it1, const Evry_Item *it2, const char *input)
|
2009-08-10 08:00:41 -07:00
|
|
|
{
|
|
|
|
return _app_action(it1, it2);
|
|
|
|
}
|
2009-07-15 05:22:42 -07:00
|
|
|
|
2009-08-10 08:00:41 -07:00
|
|
|
static int
|
2009-08-12 05:17:43 -07:00
|
|
|
_open_with_action(Evry_Plugin *p, const Evry_Item *it, const char *input __UNUSED__)
|
2009-08-10 08:00:41 -07:00
|
|
|
{
|
|
|
|
Inst *inst = p->private;
|
|
|
|
if (inst->candidate)
|
2009-08-12 12:00:25 -07:00
|
|
|
return _app_action(it, inst->candidate);
|
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
|
|
|
{
|
|
|
|
Evry_App *app = it->data[0];
|
|
|
|
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-12 05:17:43 -07:00
|
|
|
_edit_app_action(Evry_Action *act, const Evry_Item *it1, const Evry_Item *it2, const char *input)
|
2009-07-15 05:22:42 -07:00
|
|
|
{
|
2009-08-10 04:36:37 -07:00
|
|
|
Evry_App *app;
|
|
|
|
Efreet_Desktop *desktop;
|
|
|
|
|
|
|
|
if (!it1) return 0;
|
|
|
|
|
|
|
|
app = it1->data[0];
|
|
|
|
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));
|
|
|
|
/* XXX check if this gets 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 05:22:42 -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
|
|
|
{
|
|
|
|
Evry_App *app = it->data[0];
|
|
|
|
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-12 05:17:43 -07:00
|
|
|
_new_app_action(Evry_Action *act, const Evry_Item *it1, const Evry_Item *it2, const char *input)
|
2009-07-15 05:22:42 -07:00
|
|
|
{
|
2009-08-10 04:36:37 -07:00
|
|
|
Evry_App *app;
|
|
|
|
char *name;
|
|
|
|
char buf[4096];
|
|
|
|
char *end;
|
|
|
|
Efreet_Desktop *desktop;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!it1) return 0;
|
|
|
|
|
|
|
|
app = it1->data[0];
|
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);
|
|
|
|
/*XXX hackish - desktop is removed on save_as..*/
|
|
|
|
efreet_desktop_new(app->desktop->orig_path);
|
2009-08-12 12:00:25 -07:00
|
|
|
|
2009-08-10 04:36:37 -07:00
|
|
|
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
|
|
|
|
2009-08-10 08:00:41 -07:00
|
|
|
static Eina_Bool
|
|
|
|
_init(void)
|
|
|
|
{
|
|
|
|
char *path, *p, *last;
|
2009-08-12 12:00:25 -07:00
|
|
|
|
2009-08-10 08:00:41 -07:00
|
|
|
p1 = E_NEW(Evry_Plugin, 1);
|
|
|
|
p1->name = "Applications";
|
|
|
|
p1->type = type_subject;
|
|
|
|
p1->type_in = "NONE";
|
|
|
|
p1->type_out = "APPLICATION";
|
|
|
|
p1->need_query = 0;
|
|
|
|
p1->begin = &_begin;
|
|
|
|
p1->fetch = &_fetch;
|
|
|
|
p1->cleanup = &_cleanup;
|
|
|
|
p1->icon_get = &_item_icon_get;
|
|
|
|
evry_plugin_register(p1);
|
|
|
|
|
|
|
|
p2 = E_NEW(Evry_Plugin, 1);
|
|
|
|
p2->name = "Open With...";
|
|
|
|
p2->type = type_action;
|
|
|
|
p2->type_in = "FILE";
|
|
|
|
p2->type_out = "NONE";
|
|
|
|
p2->need_query = 0;
|
|
|
|
p2->begin = &_begin;
|
|
|
|
p2->fetch = &_fetch;
|
|
|
|
p2->action = &_open_with_action;
|
|
|
|
p2->cleanup = &_cleanup;
|
|
|
|
p2->icon_get = &_item_icon_get;
|
|
|
|
evry_plugin_register(p2);
|
|
|
|
|
|
|
|
act = E_NEW(Evry_Action, 1);
|
|
|
|
act->name = "Launch";
|
|
|
|
act->is_default = EINA_TRUE;
|
|
|
|
act->type_in1 = "APPLICATION";
|
|
|
|
act->action = &_exec_app_action;
|
|
|
|
act->check_item = &_exec_app_check_item;
|
|
|
|
act->icon = "everything-launch";
|
|
|
|
evry_action_register(act);
|
2009-08-12 12:00:25 -07:00
|
|
|
|
2009-08-10 08:00:41 -07:00
|
|
|
act1 = E_NEW(Evry_Action, 1);
|
|
|
|
act1->name = "Open File...";
|
|
|
|
act1->type_in1 = "APPLICATION";
|
|
|
|
act1->type_in2 = "FILE";
|
|
|
|
act1->action = &_exec_app_action;
|
|
|
|
act1->check_item = &_exec_app_check_item;
|
|
|
|
act1->icon = "everything-launch";
|
|
|
|
evry_action_register(act1);
|
|
|
|
|
|
|
|
act2 = E_NEW(Evry_Action, 1);
|
|
|
|
act2->name = "Edit Application Entry";
|
|
|
|
act2->type_in1 = "APPLICATION";
|
|
|
|
act2->action = &_edit_app_action;
|
|
|
|
act2->check_item = &_edit_app_check_item;
|
|
|
|
act2->icon = "everything-launch";
|
|
|
|
evry_action_register(act2);
|
|
|
|
|
|
|
|
act3 = E_NEW(Evry_Action, 1);
|
|
|
|
act3->name = "New Application Entry";
|
|
|
|
act3->type_in1 = "APPLICATION";
|
|
|
|
act3->action = &_new_app_action;
|
|
|
|
act3->check_item = &_new_app_check_item;
|
|
|
|
act3->icon = "everything-launch";
|
|
|
|
evry_action_register(act3);
|
|
|
|
|
|
|
|
/* taken from e_exebuf.c */
|
|
|
|
path = getenv("PATH");
|
|
|
|
if (path)
|
|
|
|
{
|
|
|
|
path = strdup(path);
|
|
|
|
last = path;
|
|
|
|
for (p = path; p[0]; p++)
|
|
|
|
{
|
|
|
|
if (p[0] == ':') p[0] = '\0';
|
|
|
|
if (p[0] == 0)
|
|
|
|
{
|
|
|
|
exe_path = eina_list_append(exe_path, strdup(last));
|
|
|
|
last = p + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (p > last)
|
|
|
|
exe_path = eina_list_append(exe_path, strdup(last));
|
|
|
|
free(path);
|
|
|
|
}
|
2009-08-12 12:00:25 -07:00
|
|
|
|
2009-08-10 08:00:41 -07:00
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_shutdown(void)
|
|
|
|
{
|
|
|
|
char *str;
|
2009-08-12 12:00:25 -07:00
|
|
|
|
2009-08-10 08:00:41 -07:00
|
|
|
evry_plugin_unregister(p1);
|
|
|
|
evry_plugin_unregister(p2);
|
|
|
|
evry_action_unregister(act);
|
|
|
|
evry_action_unregister(act1);
|
|
|
|
evry_action_unregister(act2);
|
|
|
|
evry_action_unregister(act3);
|
|
|
|
E_FREE(p1);
|
|
|
|
E_FREE(p2);
|
|
|
|
E_FREE(act);
|
|
|
|
E_FREE(act1);
|
|
|
|
E_FREE(act2);
|
|
|
|
E_FREE(act3);
|
|
|
|
|
|
|
|
EINA_LIST_FREE(exe_path, str)
|
|
|
|
free(str);
|
|
|
|
}
|
|
|
|
|
2009-08-10 04:36:37 -07:00
|
|
|
EINA_MODULE_INIT(_init);
|
|
|
|
EINA_MODULE_SHUTDOWN(_shutdown);
|