2010-05-11 10:24:38 -07:00
|
|
|
#include "e.h"
|
|
|
|
#include "e_mod_main.h"
|
|
|
|
#include "evry_api.h"
|
2010-04-10 13:05:57 -07:00
|
|
|
#include "e_mod_main.h"
|
2009-08-27 13:52:14 -07:00
|
|
|
|
2011-01-23 14:34:28 -08:00
|
|
|
// FIXME clear cache on .desktop chage event
|
|
|
|
|
2011-01-20 16:14:48 -08:00
|
|
|
/* #undef DBG
|
|
|
|
* #define DBG(...) ERR(__VA_ARGS__) */
|
|
|
|
|
|
|
|
#define MAX_ITEMS 200
|
|
|
|
|
2009-08-21 15:42:06 -07:00
|
|
|
typedef struct _Plugin Plugin;
|
2010-04-20 10:48:21 -07:00
|
|
|
typedef struct _Module_Config Module_Config;
|
|
|
|
typedef struct _E_Exe E_Exe;
|
|
|
|
typedef struct _E_Exe_List E_Exe_List;
|
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
|
|
|
{
|
2010-04-29 08:20:12 -07:00
|
|
|
Evry_Plugin base;
|
2010-05-19 07:46:37 -07:00
|
|
|
const char *input;
|
2010-04-29 08:20:12 -07:00
|
|
|
Eina_List *apps_mime;
|
|
|
|
Eina_List *apps_all;
|
|
|
|
Eina_List *apps_hist;
|
|
|
|
|
|
|
|
Eina_Hash *added;
|
2010-04-12 07:01:14 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
Evry_Item_App *command;
|
2009-06-21 03:31:38 -07:00
|
|
|
};
|
|
|
|
|
2009-08-25 02:30:14 -07:00
|
|
|
struct _E_Exe
|
|
|
|
{
|
2010-04-29 08:20:12 -07:00
|
|
|
const char *path;
|
2009-08-25 02:30:14 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _E_Exe_List
|
|
|
|
{
|
2010-04-29 08:20:12 -07:00
|
|
|
Eina_List *list;
|
2009-08-25 02:30:14 -07:00
|
|
|
};
|
|
|
|
|
2010-05-11 10:24:38 -07:00
|
|
|
struct _Module_Config
|
|
|
|
{
|
|
|
|
int version;
|
|
|
|
const char *cmd_terminal;
|
|
|
|
const char *cmd_sudo;
|
|
|
|
|
|
|
|
E_Config_Dialog *cfd;
|
|
|
|
E_Module *module;
|
2010-04-16 18:10:20 -07:00
|
|
|
};
|
|
|
|
|
2010-05-11 10:24:38 -07:00
|
|
|
static const Evry_API *evry = NULL;
|
|
|
|
static Evry_Module *evry_module = NULL;
|
2011-01-23 14:34:28 -08:00
|
|
|
static Eina_List *handlers = NULL;
|
2010-05-11 10:24:38 -07:00
|
|
|
|
2010-04-29 08:20:12 -07:00
|
|
|
static Module_Config *_conf;
|
2010-05-19 07:46:37 -07:00
|
|
|
|
|
|
|
static Eina_List *_plugins = NULL;
|
2010-04-29 08:20:12 -07:00
|
|
|
static Eina_List *_actions = NULL;
|
|
|
|
static Evry_Item *_act_open_with = NULL;
|
|
|
|
static Eina_List *exe_path = NULL;
|
|
|
|
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;
|
2011-01-23 14:34:28 -08:00
|
|
|
static Eina_List *apps_cache = NULL;
|
2010-04-29 08:20:12 -07:00
|
|
|
static void _scan_executables();
|
2010-04-27 20:22:40 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
/***************************************************************************/
|
2009-08-25 02:30:14 -07:00
|
|
|
|
2009-08-24 21:23:11 -07:00
|
|
|
static void _hash_free(void *data)
|
|
|
|
{
|
2010-04-27 20:22:40 -07:00
|
|
|
GET_APP(app, data);
|
2010-05-11 10:24:38 -07:00
|
|
|
EVRY_ITEM_FREE(app);
|
2009-08-24 21:23:11 -07:00
|
|
|
}
|
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
static Evas_Object *
|
|
|
|
_icon_get(Evry_Item *it, Evas *e)
|
2009-06-21 14:16:02 -07:00
|
|
|
{
|
2010-05-19 07:46:37 -07:00
|
|
|
GET_APP(app, it);
|
|
|
|
Evas_Object *o = NULL;
|
2010-05-15 19:37:07 -07:00
|
|
|
|
2011-01-23 14:34:28 -08:00
|
|
|
if (app->desktop && app->desktop->icon)
|
2010-04-30 05:41:10 -07:00
|
|
|
{
|
2011-01-23 14:34:28 -08:00
|
|
|
if (app->desktop->icon[0] == '/')
|
|
|
|
{
|
|
|
|
o = e_icon_add(e);
|
|
|
|
e_icon_preload_set(o, 1);
|
|
|
|
|
|
|
|
if (!e_icon_file_set(o, app->desktop->icon))
|
|
|
|
{
|
|
|
|
evas_object_del(o);
|
|
|
|
o = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!o)
|
|
|
|
o = evry->icon_theme_get(app->desktop->icon, e);
|
2009-07-04 04:10:28 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
if (!o)
|
|
|
|
o = e_util_desktop_icon_add(app->desktop, 128, e);
|
2010-04-30 05:41:10 -07:00
|
|
|
}
|
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
if (!o)
|
|
|
|
o = evry->icon_theme_get("system-run", e);
|
2010-04-30 05:41:10 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
return o;
|
|
|
|
}
|
2009-08-25 02:30:14 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
static int
|
|
|
|
_exec_open_file_action(Evry_Action *act)
|
|
|
|
{
|
|
|
|
return evry->util_exec_app(EVRY_ITEM(act), act->it1.item);
|
|
|
|
}
|
2010-05-15 19:37:07 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
static void
|
|
|
|
_item_free(Evry_Item *item)
|
|
|
|
{
|
|
|
|
GET_APP(app, item);
|
2010-04-08 21:14:09 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
if (app->desktop)
|
|
|
|
efreet_desktop_free(app->desktop);
|
|
|
|
if (app->file)
|
|
|
|
eina_stringshare_del(app->file);
|
2010-05-12 22:11:50 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
E_FREE(app);
|
|
|
|
}
|
2010-04-08 21:14:09 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
static Evry_Item_App *
|
|
|
|
_item_new(Plugin *p, const char *label, const char *id)
|
|
|
|
{
|
|
|
|
Evry_Item_App *app;
|
2010-04-16 18:10:20 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
app = EVRY_ITEM_NEW(Evry_Item_App, p, label, _icon_get, _item_free);
|
|
|
|
EVRY_ACTN(app)->action = &_exec_open_file_action;
|
2011-01-23 08:02:33 -08:00
|
|
|
EVRY_ACTN(app)->it1.type = EVRY_TYPE_FILE;
|
2010-05-19 07:46:37 -07:00
|
|
|
EVRY_ITEM(app)->id = eina_stringshare_add(id);
|
2010-05-11 10:24:38 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
eina_hash_add(p->added, id, app);
|
2010-05-15 19:37:07 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
EVRY_ACTN(app)->remember_context = EINA_TRUE;
|
|
|
|
EVRY_ITEM(app)->subtype = EVRY_TYPE_ACTION;
|
2009-09-02 12:43:16 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
return app;
|
2009-08-25 02:30:14 -07:00
|
|
|
}
|
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
static int
|
|
|
|
_cb_sort(const void *data1, const void *data2)
|
2009-08-25 02:30:14 -07:00
|
|
|
{
|
2010-05-19 07:46:37 -07:00
|
|
|
const Evry_Item *it1 = data1;
|
|
|
|
const Evry_Item *it2 = data2;
|
2010-05-15 19:37:07 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
if (it1->usage && it2->usage)
|
|
|
|
return (it1->usage > it2->usage ? -1 : 1);
|
|
|
|
if (it1->usage && !it2->usage)
|
|
|
|
return -1;
|
|
|
|
if (it2->usage && !it1->usage)
|
|
|
|
return 1;
|
2009-09-02 12:43:16 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
if (it1->fuzzy_match || it2->fuzzy_match)
|
|
|
|
{
|
|
|
|
if (it1->fuzzy_match && !it2->fuzzy_match)
|
|
|
|
return -1;
|
2010-05-11 10:24:38 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
if (!it1->fuzzy_match && it2->fuzzy_match)
|
|
|
|
return 1;
|
2010-04-16 18:10:20 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
if (it1->fuzzy_match - it2->fuzzy_match)
|
|
|
|
return (it1->fuzzy_match - it2->fuzzy_match);
|
|
|
|
}
|
2010-05-11 10:24:38 -07:00
|
|
|
|
2010-05-27 07:38:51 -07:00
|
|
|
return strcasecmp(it1->label, it2->label);
|
2009-06-21 14:16:02 -07:00
|
|
|
}
|
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
/***************************************************************************/
|
2010-04-29 08:20:12 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
static Evry_Item_App *
|
|
|
|
_item_exe_add(Plugin *p, const char *exe, int match)
|
2009-08-13 15:42:40 -07:00
|
|
|
{
|
2010-05-19 07:46:37 -07:00
|
|
|
Evry_Item_App *app = NULL;
|
2010-05-11 10:24:38 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
if ((app = eina_hash_find(p->added, exe)))
|
|
|
|
{
|
|
|
|
if (eina_list_data_find_list(p->base.items, app))
|
|
|
|
return app;
|
|
|
|
}
|
2009-08-27 13:52:14 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
if (!app)
|
|
|
|
{
|
|
|
|
app = _item_new(p, ecore_file_file_get(exe), exe);
|
|
|
|
app->file = eina_stringshare_ref(EVRY_ITEM(app)->id);
|
|
|
|
}
|
2009-08-12 12:00:25 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
EVRY_ITEM(app)->fuzzy_match = match;
|
|
|
|
EVRY_PLUGIN_ITEM_APPEND(p, app);
|
2009-08-25 02:30:14 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
return app;
|
|
|
|
}
|
2010-04-29 08:20:12 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
static Eina_Bool
|
2011-01-23 14:34:28 -08:00
|
|
|
_hist_exe_get_cb(const Eina_Hash *hash __UNUSED__, const void *key, void *data, void *fdata)
|
2010-04-29 08:20:12 -07:00
|
|
|
{
|
2010-05-19 07:46:37 -07:00
|
|
|
History_Entry *he = data;
|
|
|
|
History_Item *hi;
|
|
|
|
Plugin *p = fdata;
|
|
|
|
Eina_List *l;
|
|
|
|
Evry_Item_App *app;
|
|
|
|
int match;
|
2010-05-20 08:41:27 -07:00
|
|
|
const char *exe = key;
|
2010-04-29 08:20:12 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
EINA_LIST_FOREACH(he->items, l, hi)
|
|
|
|
{
|
|
|
|
app = NULL;
|
2010-04-29 08:20:12 -07:00
|
|
|
|
2010-05-21 23:35:46 -07:00
|
|
|
if (strcmp(hi->plugin, EVRY_PLUGIN(p)->name))
|
2010-05-19 07:46:37 -07:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!p->input)
|
|
|
|
{
|
|
|
|
app = _item_exe_add(p, exe, 0);
|
|
|
|
}
|
|
|
|
else if ((match = evry->fuzzy_match(exe, p->input)))
|
|
|
|
{
|
|
|
|
app = _item_exe_add(p, exe, match);
|
|
|
|
}
|
|
|
|
|
2010-05-20 08:41:27 -07:00
|
|
|
if (app)
|
|
|
|
{
|
|
|
|
EVRY_ITEM(app)->hi = hi;
|
|
|
|
evry->history_item_usage_set(EVRY_ITEM(app), p->input, NULL);
|
|
|
|
}
|
2010-05-19 07:46:37 -07:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EINA_TRUE;
|
2010-04-29 08:20:12 -07:00
|
|
|
}
|
|
|
|
|
2010-04-27 20:22:40 -07:00
|
|
|
static int
|
2010-05-19 07:46:37 -07:00
|
|
|
_fetch_exe(Evry_Plugin *plugin, const char *input)
|
2010-04-27 20:22:40 -07:00
|
|
|
{
|
2010-05-19 07:46:37 -07:00
|
|
|
GET_PLUGIN(p, plugin);
|
|
|
|
Eina_List *l;
|
|
|
|
Evry_Item *it;
|
|
|
|
History_Types *ht;
|
2011-01-23 14:34:28 -08:00
|
|
|
unsigned int len = (input ? strlen(input) : 0);
|
2010-05-19 07:46:37 -07:00
|
|
|
double max = 0.0;
|
2010-06-04 17:53:47 -07:00
|
|
|
const char *tmp, *file = NULL;
|
2011-01-23 14:34:28 -08:00
|
|
|
unsigned int min = 0, cnt = 0, end = len, tmp_len;
|
|
|
|
unsigned int query = (len >= (unsigned int)plugin->config->min_query);
|
2010-05-19 07:46:37 -07:00
|
|
|
EVRY_PLUGIN_ITEMS_CLEAR(p);
|
2010-04-27 20:22:40 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
p->input = input;
|
2010-04-27 20:22:40 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
ht = evry->history_types_get(EVRY_TYPE_APP);
|
|
|
|
if (ht) eina_hash_foreach(ht->types, _hist_exe_get_cb, p);
|
2010-04-27 20:22:40 -07:00
|
|
|
|
2010-06-04 17:11:12 -07:00
|
|
|
if (input)
|
|
|
|
{
|
|
|
|
if ((tmp = strchr(input, ' ')))
|
|
|
|
end = tmp - input;
|
|
|
|
|
2011-01-20 16:14:48 -08:00
|
|
|
if ((!exe_list) && (!exe_scan_idler))
|
2010-06-04 17:11:12 -07:00
|
|
|
_scan_executables();
|
|
|
|
|
|
|
|
EINA_LIST_FOREACH(exe_list, l, tmp)
|
|
|
|
{
|
|
|
|
tmp_len = strlen(tmp);
|
|
|
|
|
|
|
|
if ((end < len) && (tmp_len > end))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!strncmp(input, tmp, end))
|
|
|
|
{
|
2011-01-20 16:14:48 -08:00
|
|
|
if (query && (cnt++ < 50) && (len != tmp_len))
|
2010-06-04 17:53:47 -07:00
|
|
|
_item_exe_add(p, tmp, 15);
|
|
|
|
|
2011-01-20 16:14:48 -08:00
|
|
|
if ((!min) || (tmp_len < min))
|
2010-06-04 17:53:47 -07:00
|
|
|
{
|
|
|
|
min = tmp_len;
|
|
|
|
file = tmp;
|
|
|
|
}
|
|
|
|
if ((!query) && (tmp_len == len))
|
2010-06-04 17:11:12 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (file)
|
|
|
|
{
|
|
|
|
GET_ITEM(it, p->command);
|
|
|
|
|
|
|
|
if (strlen(file) < len)
|
|
|
|
file = input;
|
|
|
|
|
|
|
|
EVRY_ITEM_LABEL_SET(it, file);
|
|
|
|
IF_RELEASE(p->command->file);
|
|
|
|
p->command->file = eina_stringshare_ref(it->label);
|
2010-08-04 09:05:02 -07:00
|
|
|
it->fuzzy_match = 11; // prefix match
|
2010-06-04 17:11:12 -07:00
|
|
|
EVRY_PLUGIN_ITEM_APPEND(p, it);
|
|
|
|
evry->item_changed(it, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
EINA_LIST_FOREACH(plugin->items, l, it)
|
|
|
|
{
|
|
|
|
evry->history_item_usage_set(it, input, NULL);
|
|
|
|
if (input && (it->usage > max) && !strncmp(input, it->label, len))
|
|
|
|
max = it->usage;
|
|
|
|
}
|
|
|
|
EVRY_ITEM(p->command)->usage = (max * 2.0);
|
2010-04-27 20:22:40 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
EVRY_PLUGIN_ITEMS_SORT(p, _cb_sort);
|
2010-04-27 20:22:40 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
return !!(plugin->items);
|
2010-04-27 20:22:40 -07:00
|
|
|
}
|
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
static Evry_Plugin *
|
|
|
|
_begin_exe(Evry_Plugin *plugin, const Evry_Item *item)
|
2009-08-10 08:00:41 -07:00
|
|
|
{
|
2010-05-19 07:46:37 -07:00
|
|
|
Plugin *p;
|
2009-08-22 20:12:05 -07:00
|
|
|
Evry_Item_App *app;
|
2010-05-11 10:24:38 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
if (item && (item != _act_open_with))
|
|
|
|
return NULL;
|
2009-08-27 13:52:14 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
EVRY_PLUGIN_INSTANCE(p, plugin)
|
2009-08-27 13:52:14 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
p->added = eina_hash_string_small_new(_hash_free);
|
2009-08-10 08:00:41 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
app = EVRY_ITEM_NEW(Evry_Item_App, p, NULL, _icon_get, _item_free);
|
|
|
|
EVRY_ACTN(app)->action = &_exec_open_file_action;
|
|
|
|
EVRY_ACTN(app)->remember_context = EINA_TRUE;
|
|
|
|
EVRY_ITEM(app)->subtype = EVRY_TYPE_ACTION;
|
|
|
|
p->command = app;
|
2010-05-11 10:24:38 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
return EVRY_PLUGIN(p);
|
|
|
|
}
|
2009-08-25 02:30:14 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
static void
|
|
|
|
_finish_exe(Evry_Plugin *plugin)
|
|
|
|
{
|
|
|
|
GET_PLUGIN(p, plugin);
|
|
|
|
char *str;
|
2009-08-27 13:52:14 -07:00
|
|
|
|
2010-05-30 06:30:13 -07:00
|
|
|
EVRY_PLUGIN_ITEMS_CLEAR(p);
|
|
|
|
EVRY_ITEM_FREE(p->command);
|
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
if (p->added)
|
|
|
|
eina_hash_free(p->added);
|
2010-04-27 20:22:40 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
if (exe_dir)
|
|
|
|
{
|
|
|
|
closedir(exe_dir);
|
|
|
|
exe_dir = NULL;
|
2009-09-24 16:08:59 -07:00
|
|
|
}
|
2010-05-19 07:46:37 -07:00
|
|
|
EINA_LIST_FREE(exe_path, str)
|
|
|
|
free(str);
|
|
|
|
|
|
|
|
if (exe_scan_idler)
|
2009-09-24 16:08:59 -07:00
|
|
|
{
|
2010-05-19 07:46:37 -07:00
|
|
|
ecore_idler_del(exe_scan_idler);
|
|
|
|
exe_scan_idler = NULL;
|
2009-09-24 16:08:59 -07:00
|
|
|
}
|
2010-05-19 07:46:37 -07:00
|
|
|
EINA_LIST_FREE(exe_list, str)
|
|
|
|
free(str);
|
|
|
|
EINA_LIST_FREE(exe_list2, str)
|
|
|
|
free(str);
|
|
|
|
|
|
|
|
E_FREE(p);
|
|
|
|
}
|
2009-08-24 21:23:11 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
/***************************************************************************/
|
2009-08-10 08:00:41 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
static void
|
|
|
|
_item_desktop_add(Plugin *p, Efreet_Desktop *desktop, int match)
|
|
|
|
{
|
|
|
|
Evry_Item_App *app = NULL;
|
2009-08-11 09:07:30 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
if ((app = eina_hash_find(p->added, desktop->exec)))
|
|
|
|
{
|
|
|
|
if (eina_list_data_find_list(p->base.items, app))
|
|
|
|
return;
|
2009-08-25 02:30:14 -07:00
|
|
|
}
|
2010-04-08 15:37:50 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
if (!app)
|
2009-08-25 02:30:14 -07:00
|
|
|
{
|
2010-05-19 07:46:37 -07:00
|
|
|
app = _item_new(p, desktop->name, desktop->exec);
|
2010-05-30 06:30:13 -07:00
|
|
|
efreet_desktop_ref(desktop);
|
2010-05-19 07:46:37 -07:00
|
|
|
app->desktop = desktop;
|
2009-08-27 13:52:14 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
if (desktop->comment)
|
|
|
|
{
|
|
|
|
EVRY_ITEM_DETAIL_SET(app, desktop->comment);
|
|
|
|
}
|
|
|
|
else if (desktop->generic_name)
|
2010-04-08 15:37:50 -07:00
|
|
|
{
|
2010-05-19 07:46:37 -07:00
|
|
|
EVRY_ITEM_DETAIL_SET(app, desktop->generic_name);
|
2010-04-08 15:37:50 -07:00
|
|
|
}
|
|
|
|
}
|
2010-05-15 19:37:07 -07:00
|
|
|
|
2009-08-25 02:30:14 -07:00
|
|
|
EVRY_ITEM(app)->fuzzy_match = match;
|
|
|
|
EVRY_PLUGIN_ITEM_APPEND(p, app);
|
2009-08-10 08:00:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-05-19 07:46:37 -07:00
|
|
|
_desktop_list_add(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;
|
2010-05-15 14:22:06 -07:00
|
|
|
const char *exec, *end;
|
|
|
|
char buf[PATH_MAX];
|
2010-05-15 19:37:07 -07:00
|
|
|
|
2009-08-10 08:00:41 -07:00
|
|
|
EINA_LIST_FOREACH(apps, l, desktop)
|
|
|
|
{
|
2011-01-20 16:14:48 -08:00
|
|
|
if (eina_list_count(p->base.items) >= MAX_ITEMS) break;
|
2010-05-19 07:46:37 -07:00
|
|
|
|
|
|
|
m1 = m2 = 0;
|
2010-05-15 19:37:07 -07:00
|
|
|
|
2010-04-08 15:37:50 -07:00
|
|
|
if (input)
|
|
|
|
{
|
2010-05-15 14:22:06 -07:00
|
|
|
exec = ecore_file_file_get(desktop->exec);
|
|
|
|
if (exec && (end = strchr(exec, '%')))
|
|
|
|
{
|
2010-05-18 08:12:32 -07:00
|
|
|
strncpy(buf, exec, (end - exec) - 1);
|
|
|
|
buf[(end - exec)-1] = '\0';
|
2010-05-15 14:22:06 -07:00
|
|
|
m1 = evry->fuzzy_match(buf, input);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m1 = evry->fuzzy_match(exec, input);
|
|
|
|
}
|
2010-05-15 19:37:07 -07:00
|
|
|
|
2010-05-11 10:24:38 -07:00
|
|
|
m2 = evry->fuzzy_match(desktop->name, input);
|
2009-08-14 11:55:35 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
if (!m1 || (m2 && m2 < m1)) m1 = m2;
|
2010-05-15 14:22:06 -07:00
|
|
|
}
|
2010-05-19 07:46:37 -07:00
|
|
|
|
|
|
|
if (!input || m1) _item_desktop_add(p, desktop, m1);
|
2009-08-10 08:00:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
static Eina_List *
|
|
|
|
_desktop_list_get(void)
|
2009-08-10 08:00:41 -07:00
|
|
|
{
|
2010-05-19 07:46:37 -07:00
|
|
|
Eina_List *apps = NULL;
|
|
|
|
Eina_List *cat_ss;
|
|
|
|
Eina_List *l, *ll;
|
|
|
|
Efreet_Desktop *d;
|
2009-08-10 08:00:41 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
apps = efreet_util_desktop_name_glob_list("*");
|
2009-08-14 11:55:35 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
/* remove screensaver */
|
|
|
|
cat_ss = efreet_util_desktop_category_list("Screensaver");
|
|
|
|
EINA_LIST_FOREACH(cat_ss, l, d)
|
2010-04-09 07:41:37 -07:00
|
|
|
{
|
2010-05-19 07:46:37 -07:00
|
|
|
if ((ll = eina_list_data_find_list(apps, d)))
|
|
|
|
{
|
|
|
|
efreet_desktop_free(d);
|
|
|
|
apps = eina_list_remove_list(apps, ll);
|
|
|
|
}
|
|
|
|
efreet_desktop_free(d);
|
2010-04-09 07:41:37 -07:00
|
|
|
}
|
2010-05-11 10:24:38 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
return apps;
|
2009-08-10 08:00:41 -07:00
|
|
|
}
|
|
|
|
|
2009-09-24 16:08:59 -07:00
|
|
|
static Eina_Bool
|
2011-01-23 14:34:28 -08:00
|
|
|
_hist_items_get_cb(const Eina_Hash *hash __UNUSED__, const void *key, void *data, void *fdata)
|
2009-09-24 16:08:59 -07:00
|
|
|
{
|
2010-04-10 13:05:57 -07:00
|
|
|
History_Entry *he = data;
|
|
|
|
History_Item *hi;
|
|
|
|
Plugin *p = fdata;
|
|
|
|
Efreet_Desktop *d;
|
2010-05-19 07:46:37 -07:00
|
|
|
Eina_List *l, *ll;
|
|
|
|
const char *exec = key;
|
2010-04-10 13:05:57 -07:00
|
|
|
|
|
|
|
EINA_LIST_FOREACH(he->items, l, hi)
|
|
|
|
{
|
2011-01-23 14:34:28 -08:00
|
|
|
d = NULL;
|
|
|
|
|
|
|
|
if (hi->transient)
|
2010-04-17 05:40:28 -07:00
|
|
|
continue;
|
2010-05-11 10:24:38 -07:00
|
|
|
|
2011-01-23 14:34:28 -08:00
|
|
|
if (strcmp(hi->plugin, EVRY_PLUGIN(p)->name))
|
|
|
|
continue;
|
2011-01-20 16:14:48 -08:00
|
|
|
|
2011-01-23 14:34:28 -08:00
|
|
|
EINA_LIST_FOREACH(apps_cache, ll, d)
|
2011-01-23 08:02:33 -08:00
|
|
|
if (d->exec && !strcmp(d->exec, exec)) break;
|
2010-05-11 10:24:38 -07:00
|
|
|
|
2011-01-23 14:34:28 -08:00
|
|
|
if (!d)
|
|
|
|
{
|
|
|
|
if (!p->apps_all)
|
|
|
|
p->apps_all = _desktop_list_get();
|
|
|
|
|
|
|
|
EINA_LIST_FOREACH(p->apps_all, ll, d)
|
|
|
|
if (d->exec && !strcmp(d->exec, exec)) break;
|
|
|
|
|
|
|
|
if (d)
|
|
|
|
{
|
|
|
|
efreet_desktop_ref(d);
|
|
|
|
apps_cache = eina_list_append(apps_cache, d);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* remove from history */
|
2011-02-01 02:35:33 -08:00
|
|
|
/* DBG("no desktop: %s", exec);
|
|
|
|
* hi->transient = 1; */
|
2011-01-23 14:34:28 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-20 16:14:48 -08:00
|
|
|
if (!d)
|
2010-04-10 13:05:57 -07:00
|
|
|
{
|
2011-01-20 16:14:48 -08:00
|
|
|
DBG("app not found %s", exec);
|
2010-05-19 07:46:37 -07:00
|
|
|
break;
|
2010-04-10 13:05:57 -07:00
|
|
|
}
|
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
p->apps_hist = eina_list_append(p->apps_hist, d);
|
|
|
|
break;
|
2010-04-10 13:05:57 -07:00
|
|
|
}
|
2010-05-19 07:46:37 -07:00
|
|
|
|
2010-04-10 13:05:57 -07:00
|
|
|
return EINA_TRUE;
|
2009-09-24 16:08:59 -07:00
|
|
|
}
|
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
static Evry_Plugin *
|
|
|
|
_begin(Evry_Plugin *plugin, const Evry_Item *item)
|
2010-04-14 13:09:38 -07:00
|
|
|
{
|
2010-05-19 07:46:37 -07:00
|
|
|
Plugin *p;
|
2010-04-14 13:09:38 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
if (item && (item != _act_open_with))
|
|
|
|
return NULL;
|
2010-04-14 13:09:38 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
EVRY_PLUGIN_INSTANCE(p, plugin)
|
|
|
|
p->added = eina_hash_string_small_new(_hash_free);
|
2010-05-11 10:24:38 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
return EVRY_PLUGIN(p);
|
|
|
|
}
|
2010-05-11 10:24:38 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
static void
|
|
|
|
_finish(Evry_Plugin *plugin)
|
|
|
|
{
|
|
|
|
GET_PLUGIN(p, plugin);
|
|
|
|
Efreet_Desktop *desktop;
|
2010-05-11 10:24:38 -07:00
|
|
|
|
2010-05-30 06:30:13 -07:00
|
|
|
EVRY_PLUGIN_ITEMS_CLEAR(p);
|
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
if (p->added)
|
|
|
|
eina_hash_free(p->added);
|
2010-05-11 10:24:38 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
EINA_LIST_FREE(p->apps_all, desktop)
|
|
|
|
efreet_desktop_free(desktop);
|
2010-05-11 10:24:38 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
EINA_LIST_FREE(p->apps_hist, desktop);
|
2010-04-14 13:09:38 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
EINA_LIST_FREE(p->apps_mime, desktop)
|
|
|
|
efreet_desktop_free(desktop);
|
|
|
|
|
|
|
|
E_FREE(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
_fetch(Evry_Plugin *plugin, const char *input)
|
|
|
|
{
|
|
|
|
GET_PLUGIN(p, plugin);
|
|
|
|
Eina_List *l;
|
|
|
|
Evry_Item *it;
|
|
|
|
History_Types *ht;
|
2010-04-14 13:09:38 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
EVRY_PLUGIN_ITEMS_CLEAR(p);
|
2010-04-14 13:09:38 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
if (input)
|
|
|
|
{
|
2011-01-23 14:34:28 -08:00
|
|
|
if (!p->apps_all)
|
|
|
|
p->apps_all = _desktop_list_get();
|
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
_desktop_list_add(p, p->apps_all, input);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_desktop_list_add(p, p->apps_mime, input);
|
|
|
|
}
|
2010-04-14 13:09:38 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
if (!input && !(plugin->items))
|
|
|
|
{
|
|
|
|
if (!p->apps_hist)
|
|
|
|
{
|
|
|
|
ht = evry->history_types_get(EVRY_TYPE_APP);
|
|
|
|
if (ht) eina_hash_foreach(ht->types, _hist_items_get_cb, p);
|
2010-04-14 13:09:38 -07:00
|
|
|
}
|
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
_desktop_list_add(p, p->apps_hist, NULL);
|
|
|
|
}
|
2010-05-11 10:24:38 -07:00
|
|
|
|
2010-05-27 07:38:51 -07:00
|
|
|
EINA_LIST_FOREACH(plugin->items, l, it)
|
|
|
|
evry->history_item_usage_set(it, input, NULL);
|
|
|
|
|
|
|
|
EVRY_PLUGIN_ITEMS_SORT(p, _cb_sort);
|
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
return !!(plugin->items);
|
|
|
|
}
|
2010-04-14 13:09:38 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
/***************************************************************************/
|
2010-04-14 13:09:38 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
static Evry_Plugin *
|
|
|
|
_begin_mime(Evry_Plugin *plugin, const Evry_Item *item)
|
|
|
|
{
|
|
|
|
Plugin *p = NULL;
|
2010-10-28 16:07:59 -07:00
|
|
|
Efreet_Desktop *d;
|
2010-05-19 07:46:37 -07:00
|
|
|
const char *mime;
|
|
|
|
const char *path = NULL;
|
|
|
|
Eina_List *l;
|
|
|
|
|
|
|
|
if (CHECK_TYPE(item, EVRY_TYPE_ACTION))
|
|
|
|
{
|
|
|
|
GET_ACTION(act, item);
|
|
|
|
GET_FILE(file, act->it1.item);
|
|
|
|
|
|
|
|
if (!evry->file_path_get(file))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
path = file->path;
|
|
|
|
mime = file->mime;
|
|
|
|
}
|
|
|
|
else if (CHECK_TYPE(item, EVRY_TYPE_FILE))
|
|
|
|
{
|
|
|
|
GET_FILE(file, item);
|
2010-04-14 13:09:38 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
if (!evry->file_path_get(file))
|
|
|
|
return NULL;
|
2010-04-14 13:09:38 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
path = file->path;
|
|
|
|
mime = file->mime;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-04-14 13:09:38 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
if (!path || !mime || !(mime = efreet_mime_type_get(path)))
|
|
|
|
return NULL;
|
2010-04-14 13:09:38 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
EVRY_PLUGIN_INSTANCE(p, plugin);
|
2010-05-11 10:24:38 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
p->apps_mime = efreet_util_desktop_mime_list(mime);
|
2010-04-14 13:09:38 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
if (strcmp(mime, "text/plain") && (!strncmp(mime, "text/", 5)))
|
|
|
|
{
|
|
|
|
l = efreet_util_desktop_mime_list("text/plain");
|
2010-04-14 13:09:38 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
EINA_LIST_FREE(l, d)
|
|
|
|
{
|
|
|
|
if (!eina_list_data_find_list(p->apps_mime, d))
|
|
|
|
p->apps_mime = eina_list_append(p->apps_mime, d);
|
|
|
|
else
|
|
|
|
efreet_desktop_free(d);
|
2010-04-14 13:09:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
if (item->browseable && strcmp(mime, "x-directory/normal"))
|
2010-04-14 13:09:38 -07:00
|
|
|
{
|
2010-05-19 07:46:37 -07:00
|
|
|
l = efreet_util_desktop_mime_list("x-directory/normal");
|
|
|
|
|
|
|
|
EINA_LIST_FREE(l, d)
|
|
|
|
{
|
|
|
|
if (!eina_list_data_find_list(p->apps_mime, d))
|
|
|
|
p->apps_mime = eina_list_append(p->apps_mime, d);
|
|
|
|
else
|
|
|
|
efreet_desktop_free(d);
|
|
|
|
}
|
2010-04-14 13:09:38 -07:00
|
|
|
}
|
2010-05-11 10:24:38 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
if ((d = e_exehist_mime_desktop_get(mime)))
|
2010-04-14 13:09:38 -07:00
|
|
|
{
|
2010-05-30 06:30:13 -07:00
|
|
|
if ((l = eina_list_data_find_list(p->apps_mime, d)))
|
2010-05-19 07:46:37 -07:00
|
|
|
{
|
2010-05-30 06:30:13 -07:00
|
|
|
p->apps_mime = eina_list_promote_list(p->apps_mime, l);
|
|
|
|
efreet_desktop_free(d);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
p->apps_mime = eina_list_prepend(p->apps_mime, d);
|
2010-05-19 07:46:37 -07:00
|
|
|
}
|
2010-04-14 13:09:38 -07:00
|
|
|
}
|
2010-05-19 07:46:37 -07:00
|
|
|
|
|
|
|
p->added = eina_hash_string_small_new(_hash_free);
|
|
|
|
|
|
|
|
return EVRY_PLUGIN(p);
|
2010-04-14 13:09:38 -07:00
|
|
|
}
|
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
static void
|
|
|
|
_finish_mime(Evry_Plugin *plugin)
|
2009-05-06 07:20:45 -07:00
|
|
|
{
|
2010-04-27 20:22:40 -07:00
|
|
|
GET_PLUGIN(p, plugin);
|
2010-05-19 07:46:37 -07:00
|
|
|
Efreet_Desktop *desktop;
|
2010-04-29 08:20:12 -07:00
|
|
|
|
2010-05-30 06:30:13 -07:00
|
|
|
EVRY_PLUGIN_ITEMS_CLEAR(p);
|
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
if (p->added)
|
|
|
|
eina_hash_free(p->added);
|
2009-07-04 04:10:28 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
EINA_LIST_FREE(p->apps_mime, desktop)
|
|
|
|
efreet_desktop_free(desktop);
|
2010-05-30 06:30:13 -07:00
|
|
|
|
|
|
|
E_FREE(p);
|
2010-04-29 08:20:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-05-19 07:46:37 -07:00
|
|
|
_fetch_mime(Evry_Plugin *plugin, const char *input)
|
2010-04-29 08:20:12 -07:00
|
|
|
{
|
|
|
|
GET_PLUGIN(p, plugin);
|
|
|
|
Eina_List *l;
|
|
|
|
Evry_Item *it;
|
|
|
|
|
|
|
|
EVRY_PLUGIN_ITEMS_CLEAR(p);
|
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
/* add apps for a given mimetype */
|
|
|
|
_desktop_list_add(p, p->apps_mime, input);
|
2010-05-06 06:09:14 -07:00
|
|
|
|
|
|
|
EINA_LIST_FOREACH(plugin->items, l, it)
|
2010-05-11 10:24:38 -07:00
|
|
|
evry->history_item_usage_set(it, input, NULL);
|
2010-05-06 06:09:14 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
if (input)
|
|
|
|
EVRY_PLUGIN_ITEMS_SORT(p, _cb_sort);
|
2010-05-11 10:24:38 -07:00
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
return 1;
|
2009-05-06 07:20:45 -07:00
|
|
|
}
|
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
|
2010-04-15 08:46:12 -07:00
|
|
|
static int
|
2011-01-23 14:34:28 -08:00
|
|
|
_complete(Evry_Plugin *plugin __UNUSED__, const Evry_Item *it, char **input)
|
2010-04-15 08:46:12 -07:00
|
|
|
{
|
2010-04-27 20:22:40 -07:00
|
|
|
GET_APP(app, it);
|
2010-05-11 10:24:38 -07:00
|
|
|
|
2010-04-15 08:46:12 -07:00
|
|
|
char buf[128];
|
|
|
|
|
|
|
|
if (app->desktop)
|
|
|
|
{
|
|
|
|
char *space = strchr(app->desktop->exec, ' ');
|
2010-05-11 10:24:38 -07:00
|
|
|
|
2010-06-04 17:53:47 -07:00
|
|
|
snprintf(buf, sizeof(buf), "%s", app->desktop->exec);
|
2010-04-15 08:46:12 -07:00
|
|
|
if (space)
|
|
|
|
buf[1 + space - app->desktop->exec] = '\0';
|
|
|
|
}
|
|
|
|
else
|
2010-06-04 17:53:47 -07:00
|
|
|
snprintf(buf, sizeof(buf), "%s", app->file);
|
2010-04-15 08:46:12 -07:00
|
|
|
|
|
|
|
*input = strdup(buf);
|
2010-05-11 10:24:38 -07:00
|
|
|
|
2010-04-15 08:46:12 -07:00
|
|
|
return EVRY_COMPLETE_INPUT;
|
|
|
|
}
|
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
/***************************************************************************/
|
|
|
|
|
2009-07-15 07:37:01 -07:00
|
|
|
static int
|
2011-01-23 14:34:28 -08:00
|
|
|
_exec_app_check_item(Evry_Action *act __UNUSED__, const Evry_Item *it __UNUSED__)
|
2009-07-15 07:37:01 -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
|
|
|
{
|
2010-05-11 10:24:38 -07:00
|
|
|
return evry->util_exec_app(act->it1.item, act->it2.item);
|
2009-08-14 11:55:35 -07:00
|
|
|
}
|
|
|
|
|
2010-04-29 08:20:12 -07:00
|
|
|
static int
|
|
|
|
_exec_file_action(Evry_Action *act)
|
|
|
|
{
|
2010-05-11 10:24:38 -07:00
|
|
|
return evry->util_exec_app(act->it2.item, act->it1.item);
|
2010-04-29 08:20:12 -07:00
|
|
|
}
|
|
|
|
|
2009-08-25 02:30:14 -07:00
|
|
|
static int
|
|
|
|
_exec_term_action(Evry_Action *act)
|
|
|
|
{
|
2010-04-28 05:58:24 -07:00
|
|
|
GET_APP(app, act->it1.item);
|
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);
|
2010-05-11 10:24:38 -07:00
|
|
|
|
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",
|
2010-05-11 10:24:38 -07:00
|
|
|
_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;
|
2010-05-11 10:24:38 -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);
|
2010-05-11 10:24:38 -07:00
|
|
|
|
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)
|
|
|
|
{
|
2010-04-27 20:22:40 -07:00
|
|
|
GET_APP(app, it);
|
2009-08-25 02:30:14 -07:00
|
|
|
|
|
|
|
if (app->file)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-09-02 12:43:16 -07:00
|
|
|
static int
|
|
|
|
_exec_sudo_action(Evry_Action *act)
|
|
|
|
{
|
2010-04-28 05:58:24 -07:00
|
|
|
GET_APP(app, act->it1.item);
|
2009-09-02 12:43:16 -07:00
|
|
|
Evry_Item_App *tmp;
|
|
|
|
char buf[1024];
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
tmp = E_NEW(Evry_Item_App, 1);
|
|
|
|
snprintf(buf, sizeof(buf), "%s %s",
|
2010-05-11 10:24:38 -07:00
|
|
|
_conf->cmd_sudo,
|
2009-09-02 12:43:16 -07:00
|
|
|
(app->desktop ? app->desktop->exec : app->file));
|
|
|
|
|
|
|
|
tmp->file = buf;
|
2010-05-11 10:24:38 -07:00
|
|
|
ret = evry->util_exec_app(EVRY_ITEM(tmp), NULL);
|
2009-09-02 12:43:16 -07:00
|
|
|
|
|
|
|
E_FREE(tmp);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2010-04-27 20:22:40 -07:00
|
|
|
GET_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;
|
2010-04-28 05:58:24 -07:00
|
|
|
GET_APP(app, act->it1.item);
|
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
|
|
|
{
|
2010-04-27 20:22:40 -07:00
|
|
|
GET_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;
|
|
|
|
|
2010-04-28 05:58:24 -07:00
|
|
|
GET_APP(app, act->it1.item);
|
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;
|
|
|
|
}
|
|
|
|
free(name);
|
2009-08-12 12:00:25 -07:00
|
|
|
|
2010-04-26 11:21:09 -07:00
|
|
|
if (strlen(buf) == 0)
|
2009-08-10 04:36:37 -07:00
|
|
|
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);
|
2010-04-21 03:59:08 -07:00
|
|
|
desktop->exec = (char *)eina_stringshare_add(app->file);
|
2009-08-10 04:36:37 -07:00
|
|
|
}
|
2009-08-12 12:00:25 -07:00
|
|
|
else
|
2009-08-10 04:36:37 -07:00
|
|
|
{
|
2010-04-21 03:59:08 -07:00
|
|
|
desktop = efreet_desktop_empty_new(buf);
|
|
|
|
if (app->desktop->name)
|
|
|
|
desktop->name = strdup(app->desktop->name);
|
|
|
|
if (app->desktop->comment)
|
|
|
|
desktop->comment = strdup(app->desktop->comment);
|
|
|
|
if (app->desktop->generic_name)
|
|
|
|
desktop->generic_name = strdup(app->desktop->generic_name);
|
|
|
|
if (app->desktop->generic_name)
|
|
|
|
desktop->generic_name = strdup(app->desktop->generic_name);
|
|
|
|
if (app->desktop->exec)
|
|
|
|
desktop->exec = strdup(app->desktop->exec);
|
2010-04-30 15:12:02 -07:00
|
|
|
if (app->desktop->icon)
|
|
|
|
desktop->icon = strdup(app->desktop->icon);
|
2010-04-21 03:59:08 -07:00
|
|
|
if (app->desktop->mime_types)
|
2010-05-11 10:24:38 -07:00
|
|
|
desktop->mime_types = eina_list_clone(app->desktop->mime_types);
|
2009-08-10 04:36:37 -07:00
|
|
|
}
|
2010-04-21 03:59:08 -07:00
|
|
|
if (desktop)
|
|
|
|
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-05-11 10:24:38 -07:00
|
|
|
static int
|
|
|
|
_open_term_action(Evry_Action *act)
|
|
|
|
{
|
|
|
|
GET_FILE(file, act->it1.item);
|
|
|
|
Evry_Item_App *tmp;
|
|
|
|
char cwd[4096];
|
|
|
|
char *dir;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (!(evry->file_path_get(file)))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (IS_BROWSEABLE(file))
|
|
|
|
dir = strdup(file->path);
|
|
|
|
else
|
|
|
|
dir = ecore_file_dir_get(file->path);
|
|
|
|
|
|
|
|
if (dir)
|
|
|
|
{
|
|
|
|
if (!getcwd(cwd, sizeof(cwd)))
|
|
|
|
return 0;
|
|
|
|
if (chdir(dir))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
tmp = E_NEW(Evry_Item_App, 1);
|
|
|
|
tmp->file = _conf->cmd_terminal;
|
|
|
|
|
|
|
|
ret = evry->util_exec_app(EVRY_ITEM(tmp), NULL);
|
|
|
|
E_FREE(tmp);
|
|
|
|
E_FREE(dir);
|
|
|
|
if (chdir(cwd))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-01-23 15:37:50 -08:00
|
|
|
static int
|
|
|
|
_check_executable(Evry_Action *act __UNUSED__, const Evry_Item *it)
|
|
|
|
{
|
|
|
|
GET_FILE(file, it);
|
|
|
|
|
|
|
|
return ecore_file_can_exec(evry->file_path_get(file));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
_run_executable(Evry_Action *act)
|
|
|
|
{
|
|
|
|
GET_FILE(file, act->it1.item);
|
|
|
|
|
|
|
|
e_exec(e_util_zone_current_get(e_manager_current_get()), NULL, file->path, NULL, NULL);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
/***************************************************************************/
|
2011-01-23 14:34:28 -08:00
|
|
|
static Eina_Bool
|
|
|
|
_desktop_cache_update(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
|
|
|
|
{
|
|
|
|
Efreet_Desktop *d;
|
|
|
|
|
|
|
|
EINA_LIST_FREE(apps_cache, d)
|
|
|
|
efreet_desktop_unref(d);
|
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
2010-05-19 07:46:37 -07:00
|
|
|
|
2010-05-11 10:24:38 -07:00
|
|
|
static int
|
|
|
|
_plugins_init(const Evry_API *api)
|
2009-08-10 08:00:41 -07:00
|
|
|
{
|
2010-04-24 17:31:11 -07:00
|
|
|
Evry_Plugin *p;
|
2010-04-27 20:22:40 -07:00
|
|
|
int prio = 0;
|
|
|
|
Eina_List *l;
|
|
|
|
Evry_Action *act;
|
2010-05-11 10:24:38 -07:00
|
|
|
|
|
|
|
if (evry_module->active)
|
|
|
|
return EINA_TRUE;
|
|
|
|
|
|
|
|
evry = api;
|
|
|
|
|
|
|
|
if (!evry->api_version_check(EVRY_API_VERSION))
|
2010-04-08 04:55:15 -07:00
|
|
|
return EINA_FALSE;
|
|
|
|
|
2010-05-28 16:02:27 -07:00
|
|
|
p = EVRY_PLUGIN_NEW(Plugin, N_("Applications"),
|
|
|
|
"system-run", EVRY_TYPE_APP,
|
2010-04-27 20:22:40 -07:00
|
|
|
_begin, _finish, _fetch, NULL);
|
2010-04-24 17:31:11 -07:00
|
|
|
p->complete = &_complete;
|
|
|
|
p->config_path = "extensions/everything-apps";
|
2010-05-11 10:24:38 -07:00
|
|
|
evry->plugin_register(p, EVRY_PLUGIN_SUBJECT, 1);
|
2010-05-19 07:46:37 -07:00
|
|
|
_plugins = eina_list_append(_plugins, p);
|
|
|
|
|
|
|
|
|
2010-05-28 16:02:27 -07:00
|
|
|
p = EVRY_PLUGIN_NEW(Plugin, N_("Exebuf"),
|
|
|
|
"system-run", EVRY_TYPE_APP,
|
2010-05-19 07:46:37 -07:00
|
|
|
_begin_exe, _finish_exe, _fetch_exe, NULL);
|
|
|
|
p->complete = &_complete;
|
|
|
|
p->config_path = "extensions/everything-apps";
|
|
|
|
_plugins = eina_list_append(_plugins, p);
|
2010-05-21 23:35:46 -07:00
|
|
|
if (evry->plugin_register(p, EVRY_PLUGIN_SUBJECT, 3))
|
2010-05-19 07:46:37 -07:00
|
|
|
p->config->min_query = 5;
|
2010-04-29 08:20:12 -07:00
|
|
|
|
2010-05-28 16:02:27 -07:00
|
|
|
p = EVRY_PLUGIN_NEW(Plugin, N_("Applications"),
|
|
|
|
"system-run", EVRY_TYPE_APP,
|
2010-05-19 07:46:37 -07:00
|
|
|
_begin_mime, _finish, _fetch, NULL);
|
2010-04-29 08:20:12 -07:00
|
|
|
p->complete = &_complete;
|
|
|
|
p->config_path = "extensions/everything-apps";
|
2010-05-11 10:24:38 -07:00
|
|
|
evry->plugin_register(p, EVRY_PLUGIN_OBJECT, 1);
|
2010-05-19 07:46:37 -07:00
|
|
|
_plugins = eina_list_append(_plugins, p);
|
2010-05-11 10:24:38 -07:00
|
|
|
|
2010-05-28 16:02:27 -07:00
|
|
|
p = EVRY_PLUGIN_NEW(Plugin, N_("Open With..."),
|
|
|
|
"system-run", EVRY_TYPE_APP,
|
2010-05-19 07:46:37 -07:00
|
|
|
_begin_mime, _finish_mime, _fetch_mime, NULL);
|
2010-04-24 17:31:11 -07:00
|
|
|
p->config_path = "extensions/everything-apps";
|
2010-05-11 10:24:38 -07:00
|
|
|
evry->plugin_register(p, EVRY_PLUGIN_ACTION, 1);
|
2010-05-30 06:30:13 -07:00
|
|
|
_plugins = eina_list_append(_plugins, p);
|
2009-08-10 08:00:41 -07:00
|
|
|
|
2010-04-28 06:54:35 -07:00
|
|
|
act = EVRY_ACTION_NEW(N_("Launch"),
|
2010-04-28 09:39:50 -07:00
|
|
|
EVRY_TYPE_APP, 0,
|
2011-01-23 14:34:28 -08:00
|
|
|
"system-run",
|
2010-04-28 06:54:35 -07:00
|
|
|
_exec_app_action,
|
|
|
|
_exec_app_check_item);
|
2010-05-11 10:24:38 -07:00
|
|
|
_actions = eina_list_append(_actions, act);
|
|
|
|
|
2010-04-28 06:54:35 -07:00
|
|
|
act = EVRY_ACTION_NEW(N_("Open File..."),
|
|
|
|
EVRY_TYPE_APP, EVRY_TYPE_FILE,
|
|
|
|
"document-open",
|
|
|
|
_exec_app_action,
|
|
|
|
_exec_app_check_item);
|
2010-05-11 10:24:38 -07:00
|
|
|
_actions = eina_list_append(_actions, act);
|
|
|
|
|
2010-04-28 06:54:35 -07:00
|
|
|
act = EVRY_ACTION_NEW(N_("Run in Terminal"),
|
2010-04-28 09:39:50 -07:00
|
|
|
EVRY_TYPE_APP, 0,
|
2010-04-28 06:54:35 -07:00
|
|
|
"system-run",
|
|
|
|
_exec_term_action,
|
|
|
|
_exec_term_check_item);
|
2010-05-11 10:24:38 -07:00
|
|
|
_actions = eina_list_append(_actions, act);
|
|
|
|
|
2010-04-28 06:54:35 -07:00
|
|
|
act = EVRY_ACTION_NEW(N_("Edit Application Entry"),
|
2010-04-28 09:39:50 -07:00
|
|
|
EVRY_TYPE_APP, 0,
|
2010-04-28 06:54:35 -07:00
|
|
|
"everything-launch",
|
|
|
|
_edit_app_action,
|
|
|
|
_edit_app_check_item);
|
2010-04-27 20:22:40 -07:00
|
|
|
_actions = eina_list_append(_actions, act);
|
2010-05-11 10:24:38 -07:00
|
|
|
|
2010-04-28 06:54:35 -07:00
|
|
|
act = EVRY_ACTION_NEW(N_("New Application Entry"),
|
2010-04-28 09:39:50 -07:00
|
|
|
EVRY_TYPE_APP, 0,
|
2010-04-28 06:54:35 -07:00
|
|
|
"everything-launch",
|
|
|
|
_new_app_action,
|
|
|
|
_new_app_check_item);
|
2010-04-27 20:22:40 -07:00
|
|
|
_actions = eina_list_append(_actions, act);
|
2010-05-11 10:24:38 -07:00
|
|
|
|
2010-04-28 06:54:35 -07:00
|
|
|
act = EVRY_ACTION_NEW(N_("Run with Sudo"),
|
2010-04-28 09:39:50 -07:00
|
|
|
EVRY_TYPE_APP, 0,
|
2010-04-28 06:54:35 -07:00
|
|
|
"system-run",
|
|
|
|
_exec_sudo_action, NULL);
|
2010-04-27 20:22:40 -07:00
|
|
|
_actions = eina_list_append(_actions, act);
|
2010-04-29 08:20:12 -07:00
|
|
|
|
|
|
|
act = EVRY_ACTION_NEW(N_("Open with..."),
|
|
|
|
EVRY_TYPE_FILE, EVRY_TYPE_APP,
|
|
|
|
"everything-launch",
|
|
|
|
_exec_file_action, NULL);
|
|
|
|
_act_open_with = EVRY_ITEM(act);
|
|
|
|
_actions = eina_list_append(_actions, act);
|
2010-05-11 10:24:38 -07:00
|
|
|
|
|
|
|
act = EVRY_ACTION_NEW(N_("Open Terminal here"),
|
|
|
|
EVRY_TYPE_FILE, 0,
|
|
|
|
"system-run",
|
|
|
|
_open_term_action, NULL);
|
|
|
|
_actions = eina_list_append(_actions, act);
|
|
|
|
|
2011-01-23 15:37:50 -08:00
|
|
|
act = EVRY_ACTION_NEW(N_("Run Executable"),
|
|
|
|
EVRY_TYPE_FILE, 0,
|
|
|
|
"system-run",
|
|
|
|
_run_executable,
|
|
|
|
_check_executable);
|
|
|
|
_actions = eina_list_append(_actions, act);
|
|
|
|
|
2010-04-27 20:22:40 -07:00
|
|
|
EINA_LIST_FOREACH(_actions, l, act)
|
2010-05-11 10:24:38 -07:00
|
|
|
evry->action_register(act, prio++);
|
2009-08-27 13:52:14 -07:00
|
|
|
|
2011-01-23 14:34:28 -08:00
|
|
|
handlers = eina_list_append
|
|
|
|
(handlers, ecore_event_handler_add
|
|
|
|
(EFREET_EVENT_DESKTOP_CACHE_UPDATE, _desktop_cache_update, NULL));
|
|
|
|
|
2009-08-10 08:00:41 -07:00
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-04-24 16:07:13 -07:00
|
|
|
_plugins_shutdown(void)
|
2009-08-10 08:00:41 -07:00
|
|
|
{
|
2010-04-27 20:22:40 -07:00
|
|
|
Evry_Action *act;
|
2010-05-19 07:46:37 -07:00
|
|
|
Evry_Plugin *p;
|
2011-01-23 14:34:28 -08:00
|
|
|
Efreet_Desktop *d;
|
|
|
|
Ecore_Event_Handler *h;
|
2010-05-11 10:24:38 -07:00
|
|
|
|
|
|
|
if (!evry_module->active)
|
|
|
|
return;
|
|
|
|
|
2011-01-23 14:34:28 -08:00
|
|
|
EINA_LIST_FREE(apps_cache, d)
|
|
|
|
efreet_desktop_unref(d);
|
|
|
|
|
2010-05-19 07:46:37 -07:00
|
|
|
EINA_LIST_FREE(_plugins, p)
|
|
|
|
EVRY_PLUGIN_FREE(p);
|
2009-08-27 13:52:14 -07:00
|
|
|
|
2010-04-27 20:22:40 -07:00
|
|
|
EINA_LIST_FREE(_actions, act)
|
2010-05-30 06:30:13 -07:00
|
|
|
EVRY_ACTION_FREE(act);
|
2010-05-11 10:24:38 -07:00
|
|
|
|
2011-01-23 14:34:28 -08:00
|
|
|
EINA_LIST_FREE(handlers, h)
|
|
|
|
ecore_event_handler_del(h);
|
|
|
|
|
2010-05-11 10:24:38 -07:00
|
|
|
evry_module->active = EINA_FALSE;
|
2009-08-25 02:30:14 -07:00
|
|
|
}
|
2010-04-10 13:05:57 -07:00
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
|
2010-04-16 18:10:20 -07:00
|
|
|
static E_Config_DD *conf_edd = NULL;
|
|
|
|
|
2010-05-11 10:24:38 -07:00
|
|
|
struct _E_Config_Dialog_Data
|
2010-04-16 18:10:20 -07:00
|
|
|
{
|
2010-05-11 10:24:38 -07:00
|
|
|
char *cmd_terminal;
|
|
|
|
char *cmd_sudo;
|
2010-04-16 18:10:20 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
static void *_create_data(E_Config_Dialog *cfd);
|
|
|
|
static void _free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
|
|
|
|
static void _fill_data(E_Config_Dialog_Data *cfdata);
|
|
|
|
static Evas_Object *_basic_create(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata);
|
|
|
|
static int _basic_apply(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
|
|
|
|
|
2010-04-20 10:48:21 -07:00
|
|
|
static E_Config_Dialog *
|
2011-01-23 14:34:28 -08:00
|
|
|
_conf_dialog(E_Container *con, const char *params __UNUSED__)
|
2010-04-16 18:10:20 -07:00
|
|
|
{
|
|
|
|
E_Config_Dialog *cfd = NULL;
|
|
|
|
E_Config_Dialog_View *v = NULL;
|
|
|
|
char buf[4096];
|
|
|
|
|
2010-04-20 10:48:21 -07:00
|
|
|
if (e_config_dialog_find("everything-apps", "extensions/everything-apps")) return NULL;
|
2010-04-16 18:10:20 -07:00
|
|
|
|
|
|
|
v = E_NEW(E_Config_Dialog_View, 1);
|
|
|
|
if (!v) return NULL;
|
|
|
|
|
|
|
|
v->create_cfdata = _create_data;
|
|
|
|
v->free_cfdata = _free_data;
|
|
|
|
v->basic.create_widgets = _basic_create;
|
|
|
|
v->basic.apply_cfdata = _basic_apply;
|
|
|
|
|
|
|
|
snprintf(buf, sizeof(buf), "%s/e-module.edj", _conf->module->dir);
|
|
|
|
|
2010-05-11 10:24:38 -07:00
|
|
|
cfd = e_config_dialog_new(con, _("Everything Applications"), "everything-apps",
|
|
|
|
"extensions/everything-apps", buf, 0, v, NULL);
|
2010-04-16 18:10:20 -07:00
|
|
|
|
2010-04-20 10:48:21 -07:00
|
|
|
/* e_dialog_resizable_set(cfd->dia, 1); */
|
2010-04-16 18:10:20 -07:00
|
|
|
_conf->cfd = cfd;
|
|
|
|
return cfd;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Local Functions */
|
|
|
|
static void *
|
2011-01-23 14:34:28 -08:00
|
|
|
_create_data(E_Config_Dialog *cfd __UNUSED__)
|
2010-04-16 18:10:20 -07:00
|
|
|
{
|
|
|
|
E_Config_Dialog_Data *cfdata = NULL;
|
|
|
|
|
|
|
|
cfdata = E_NEW(E_Config_Dialog_Data, 1);
|
|
|
|
_fill_data(cfdata);
|
|
|
|
return cfdata;
|
|
|
|
}
|
|
|
|
|
2010-05-11 10:24:38 -07:00
|
|
|
static void
|
2011-01-23 14:34:28 -08:00
|
|
|
_free_data(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata)
|
2010-04-16 18:10:20 -07:00
|
|
|
{
|
|
|
|
_conf->cfd = NULL;
|
|
|
|
E_FREE(cfdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Evas_Object *
|
2011-01-23 14:34:28 -08:00
|
|
|
_basic_create(E_Config_Dialog *cfd __UNUSED__, Evas *e, E_Config_Dialog_Data *cfdata)
|
2010-04-16 18:10:20 -07:00
|
|
|
{
|
|
|
|
Evas_Object *o = NULL, *of = NULL, *ow = NULL;
|
|
|
|
|
2010-05-11 10:24:38 -07:00
|
|
|
o = e_widget_list_add(e, 0, 0);
|
2010-04-16 18:10:20 -07:00
|
|
|
|
2010-05-11 10:24:38 -07:00
|
|
|
of = e_widget_framelist_add(e, _("Commands"), 0);
|
|
|
|
ow = e_widget_label_add(e, _("Terminal Command"));
|
|
|
|
e_widget_framelist_object_append(of, ow);
|
|
|
|
ow = e_widget_entry_add(e, &(cfdata->cmd_terminal), NULL, NULL, NULL);
|
|
|
|
e_widget_framelist_object_append(of, ow);
|
|
|
|
|
|
|
|
ow = e_widget_label_add(e, _("Sudo GUI"));
|
|
|
|
e_widget_framelist_object_append(of, ow);
|
|
|
|
ow = e_widget_entry_add(e, &(cfdata->cmd_sudo), NULL, NULL, NULL);
|
|
|
|
e_widget_framelist_object_append(of, ow);
|
|
|
|
|
2010-04-16 18:10:20 -07:00
|
|
|
e_widget_list_object_append(o, of, 1, 1, 0.5);
|
|
|
|
|
|
|
|
return o;
|
|
|
|
}
|
|
|
|
|
2010-05-11 10:24:38 -07:00
|
|
|
static void
|
|
|
|
_fill_data(E_Config_Dialog_Data *cfdata)
|
|
|
|
{
|
|
|
|
|
|
|
|
#define CP(_name) cfdata->_name = strdup(_conf->_name);
|
|
|
|
#define C(_name) cfdata->_name = _conf->_name;
|
|
|
|
CP(cmd_terminal);
|
|
|
|
CP(cmd_sudo);
|
|
|
|
#undef CP
|
|
|
|
#undef C
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2011-01-23 14:34:28 -08:00
|
|
|
_basic_apply(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata)
|
2010-04-16 18:10:20 -07:00
|
|
|
{
|
2010-05-11 10:24:38 -07:00
|
|
|
#define CP(_name) \
|
|
|
|
if (_conf->_name) \
|
|
|
|
eina_stringshare_del(_conf->_name); \
|
|
|
|
_conf->_name = eina_stringshare_add(cfdata->_name);
|
|
|
|
#define C(_name) _conf->_name = cfdata->_name;
|
|
|
|
CP(cmd_terminal);
|
|
|
|
CP(cmd_sudo);
|
|
|
|
#undef CP
|
|
|
|
#undef C
|
|
|
|
|
2010-04-17 05:40:28 -07:00
|
|
|
e_config_domain_save("module.everything-apps", conf_edd, _conf);
|
|
|
|
|
2010-05-11 10:24:38 -07:00
|
|
|
/* e_config_save_queue(); */
|
2010-04-16 18:10:20 -07:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-05-11 10:24:38 -07:00
|
|
|
static void
|
2010-04-17 05:40:28 -07:00
|
|
|
_conf_new(void)
|
2010-04-16 18:10:20 -07:00
|
|
|
{
|
2010-05-11 10:24:38 -07:00
|
|
|
if (!_conf)
|
|
|
|
{
|
|
|
|
_conf = E_NEW(Module_Config, 1);
|
|
|
|
_conf->version = (MOD_CONFIG_FILE_EPOCH << 16);
|
|
|
|
}
|
2010-04-16 18:10:20 -07:00
|
|
|
|
|
|
|
#define IFMODCFG(v) if ((_conf->version & 0xffff) < v) {
|
|
|
|
#define IFMODCFGEND }
|
|
|
|
|
|
|
|
/* setup defaults */
|
2010-05-11 10:24:38 -07:00
|
|
|
IFMODCFG(0x009d);
|
|
|
|
_conf->cmd_terminal = eina_stringshare_add("/usr/bin/xterm");
|
|
|
|
_conf->cmd_sudo = eina_stringshare_add("/usr/bin/gksudo --preserve-env");
|
|
|
|
IFMODCFGEND;
|
|
|
|
|
2010-04-16 18:10:20 -07:00
|
|
|
_conf->version = MOD_CONFIG_FILE_VERSION;
|
|
|
|
|
2010-05-11 10:24:38 -07:00
|
|
|
/* e_config_save_queue(); */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_conf_free(void)
|
|
|
|
{
|
|
|
|
if (!_conf) return;
|
|
|
|
|
|
|
|
IF_RELEASE(_conf->cmd_sudo);
|
|
|
|
IF_RELEASE(_conf->cmd_terminal);
|
|
|
|
E_FREE(_conf);
|
2010-04-16 18:10:20 -07:00
|
|
|
}
|
|
|
|
|
2010-04-20 10:48:21 -07:00
|
|
|
static void
|
|
|
|
_conf_init(E_Module *m)
|
2010-04-10 13:05:57 -07:00
|
|
|
{
|
2010-04-16 18:10:20 -07:00
|
|
|
char buf[4096];
|
|
|
|
snprintf(buf, sizeof(buf), "%s/e-module.edj", m->dir);
|
|
|
|
|
2010-05-11 10:24:38 -07:00
|
|
|
e_configure_registry_category_add
|
|
|
|
("extensions", 80, _("Extensions"), NULL,
|
|
|
|
"preferences-extensions");
|
2010-04-16 18:10:20 -07:00
|
|
|
|
2010-05-11 10:24:38 -07:00
|
|
|
e_configure_registry_item_add
|
|
|
|
("extensions/everything-apps", 110,
|
|
|
|
_("Everything Applications"),
|
|
|
|
NULL, buf, _conf_dialog);
|
2010-04-16 18:10:20 -07:00
|
|
|
|
|
|
|
conf_edd = E_CONFIG_DD_NEW("Module_Config", Module_Config);
|
|
|
|
|
|
|
|
#undef T
|
|
|
|
#undef D
|
|
|
|
#define T Module_Config
|
|
|
|
#define D conf_edd
|
|
|
|
E_CONFIG_VAL(D, T, version, INT);
|
2010-05-11 10:24:38 -07:00
|
|
|
E_CONFIG_VAL(D, T, cmd_terminal, STR);
|
|
|
|
E_CONFIG_VAL(D, T, cmd_sudo, STR);
|
2010-04-16 18:10:20 -07:00
|
|
|
#undef T
|
|
|
|
#undef D
|
|
|
|
|
|
|
|
_conf = e_config_domain_load("module.everything-apps", conf_edd);
|
|
|
|
|
|
|
|
|
2010-05-11 10:24:38 -07:00
|
|
|
if (_conf && !e_util_module_config_check
|
|
|
|
(_("Everything Applications"), _conf->version,
|
|
|
|
MOD_CONFIG_FILE_EPOCH, MOD_CONFIG_FILE_VERSION))
|
|
|
|
_conf_free();
|
2010-04-16 18:10:20 -07:00
|
|
|
|
2010-05-11 10:24:38 -07:00
|
|
|
_conf_new();
|
2010-04-16 18:10:20 -07:00
|
|
|
_conf->module = m;
|
2010-04-20 10:48:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_conf_shutdown(void)
|
|
|
|
{
|
2010-05-11 10:24:38 -07:00
|
|
|
_conf_free();
|
2010-04-20 10:48:21 -07:00
|
|
|
|
|
|
|
E_CONFIG_DD_FREE(conf_edd);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
|
2010-05-11 10:24:38 -07:00
|
|
|
EAPI E_Module_Api e_modapi =
|
2010-04-20 10:48:21 -07:00
|
|
|
{
|
|
|
|
E_MODULE_API_VERSION,
|
|
|
|
"everything-apps"
|
|
|
|
};
|
|
|
|
|
|
|
|
EAPI void *
|
|
|
|
e_modapi_init(E_Module *m)
|
2010-05-11 10:24:38 -07:00
|
|
|
{
|
2010-04-20 10:48:21 -07:00
|
|
|
_conf_init(m);
|
2010-04-27 20:22:40 -07:00
|
|
|
|
2010-05-11 10:24:38 -07:00
|
|
|
evry_module = E_NEW(Evry_Module, 1);
|
|
|
|
evry_module->init = &_plugins_init;
|
|
|
|
evry_module->shutdown = &_plugins_shutdown;
|
|
|
|
EVRY_MODULE_REGISTER(evry_module);
|
|
|
|
|
|
|
|
if ((evry = e_datastore_get("everything_loaded")))
|
2010-05-11 13:20:56 -07:00
|
|
|
evry_module->active = _plugins_init(evry);
|
2010-05-11 10:24:38 -07:00
|
|
|
|
2010-04-27 20:22:40 -07:00
|
|
|
/* taken from e_exebuf.c */
|
|
|
|
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);
|
|
|
|
|
|
|
|
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);
|
2010-05-11 10:24:38 -07:00
|
|
|
|
|
|
|
e_module_delayed_set(m, 1);
|
2010-04-10 13:05:57 -07:00
|
|
|
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI int
|
2011-01-23 14:34:28 -08:00
|
|
|
e_modapi_shutdown(E_Module *m __UNUSED__)
|
2010-04-10 13:05:57 -07:00
|
|
|
{
|
2010-05-11 10:24:38 -07:00
|
|
|
_plugins_shutdown();
|
|
|
|
|
|
|
|
EVRY_MODULE_UNREGISTER(evry_module);
|
|
|
|
E_FREE(evry_module);
|
2010-04-10 13:05:57 -07:00
|
|
|
|
2010-04-20 10:48:21 -07:00
|
|
|
_conf_shutdown();
|
|
|
|
|
2010-04-10 14:38:36 -07:00
|
|
|
E_CONFIG_DD_FREE(exelist_edd);
|
|
|
|
E_CONFIG_DD_FREE(exelist_exe_edd);
|
2010-04-16 18:10:20 -07:00
|
|
|
|
2010-04-10 13:05:57 -07:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI int
|
2011-01-23 14:34:28 -08:00
|
|
|
e_modapi_save(E_Module *m __UNUSED__)
|
2010-04-10 13:05:57 -07:00
|
|
|
{
|
2010-04-20 10:48:21 -07:00
|
|
|
e_config_domain_save("module.everything-apps", conf_edd, _conf);
|
2010-04-10 13:05:57 -07:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
|
2010-04-27 20:22:40 -07:00
|
|
|
|
|
|
|
/* taken from e_exebuf.c */
|
2010-06-24 09:19:12 -07:00
|
|
|
static Eina_Bool
|
2011-01-23 14:34:28 -08:00
|
|
|
_scan_idler(void *data __UNUSED__)
|
2010-04-27 20:22:40 -07:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
|
|
|
/* FIXME: check wheter they match or not */
|
|
|
|
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;
|
2010-06-24 09:19:12 -07:00
|
|
|
return ECORE_CALLBACK_CANCEL;
|
2010-04-27 20:22:40 -07:00
|
|
|
}
|
|
|
|
/* 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;
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2010-09-08 16:59:07 -07:00
|
|
|
/* we have more scannign to do */
|
2010-06-24 09:19:12 -07:00
|
|
|
return ECORE_CALLBACK_RENEW;
|
2010-04-27 20:22:40 -07:00
|
|
|
}
|
2010-04-29 08:20:12 -07:00
|
|
|
|
|
|
|
static void
|
|
|
|
_scan_executables()
|
|
|
|
{
|
|
|
|
/* taken from exebuf module */
|
|
|
|
char *path, *pp, *last;
|
|
|
|
E_Exe_List *el;
|
|
|
|
|
|
|
|
el = e_config_domain_load("exebuf_exelist_cache", exelist_edd);
|
|
|
|
if (el)
|
|
|
|
{
|
|
|
|
E_Exe *ee;
|
|
|
|
|
|
|
|
EINA_LIST_FREE(el->list, ee)
|
|
|
|
{
|
|
|
|
exe_list = eina_list_append(exe_list, strdup(ee->path));
|
|
|
|
eina_stringshare_del(ee->path);
|
|
|
|
free(ee);
|
|
|
|
}
|
|
|
|
free(el);
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
exe_scan_idler = ecore_idler_add(_scan_idler, NULL);
|
|
|
|
}
|