forked from enlightenment/enlightenment
'everything'
- added sudo app action and config option - remove unused item after seven days from history SVN revision: 42189
This commit is contained in:
parent
cb2d0546d4
commit
abc42d6a2a
|
@ -9,7 +9,7 @@
|
|||
|
||||
#include "e_mod_main.h"
|
||||
|
||||
#define CONFIG_VERSION 5
|
||||
#define CONFIG_VERSION 6
|
||||
|
||||
/* actual module specifics */
|
||||
static void _e_mod_action_cb(E_Object *obj, const char *params);
|
||||
|
@ -187,6 +187,7 @@ _config_init()
|
|||
E_CONFIG_VAL(D, T, hide_list, INT);
|
||||
E_CONFIG_VAL(D, T, quick_nav, INT);
|
||||
E_CONFIG_VAL(D, T, cmd_terminal, STR);
|
||||
E_CONFIG_VAL(D, T, cmd_sudo, STR);
|
||||
E_CONFIG_LIST(D, T, conf_subjects, conf_item_edd);
|
||||
E_CONFIG_LIST(D, T, conf_actions, conf_item_edd);
|
||||
E_CONFIG_LIST(D, T, conf_objects, conf_item_edd);
|
||||
|
@ -219,6 +220,7 @@ _config_init()
|
|||
evry_conf->conf_objects = NULL;
|
||||
evry_conf->conf_views = NULL;
|
||||
evry_conf->cmd_terminal = eina_stringshare_add("/usr/bin/xterm");
|
||||
evry_conf->cmd_sudo = eina_stringshare_add("/usr/bin/gksudo --preserve-env");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@ struct _Config
|
|||
int quick_nav;
|
||||
|
||||
const char *cmd_terminal;
|
||||
const char *cmd_sudo;
|
||||
|
||||
/* not saved data */
|
||||
Eina_List *plugins;
|
||||
|
@ -51,6 +52,7 @@ struct _History_Item
|
|||
const char *context;
|
||||
const char *input;
|
||||
double last_used;
|
||||
double usage;
|
||||
int count;
|
||||
int transient;
|
||||
};
|
||||
|
|
|
@ -22,6 +22,7 @@ struct _E_Config_Dialog_Data
|
|||
int scroll_animate;
|
||||
|
||||
char *cmd_terminal;
|
||||
char *cmd_sudo;
|
||||
|
||||
Evas_Object *l_subject;
|
||||
Evas_Object *l_action;
|
||||
|
@ -78,6 +79,9 @@ _fill_data(E_Config_Dialog_Data *cfdata)
|
|||
|
||||
if (evry_conf->cmd_terminal)
|
||||
cfdata->cmd_terminal = strdup(evry_conf->cmd_terminal);
|
||||
|
||||
if (evry_conf->cmd_sudo)
|
||||
cfdata->cmd_sudo = strdup(evry_conf->cmd_sudo);
|
||||
}
|
||||
|
||||
static void *
|
||||
|
@ -97,6 +101,7 @@ _free_data(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata)
|
|||
if (cfdata->p_action) eina_list_free(cfdata->p_action);
|
||||
if (cfdata->p_object) eina_list_free(cfdata->p_object);
|
||||
E_FREE(cfdata->cmd_terminal);
|
||||
E_FREE(cfdata->cmd_sudo);
|
||||
E_FREE(cfdata);
|
||||
}
|
||||
|
||||
|
@ -124,6 +129,9 @@ _basic_apply_data(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata)
|
|||
if (evry_conf->cmd_terminal)
|
||||
eina_stringshare_del(evry_conf->cmd_terminal);
|
||||
evry_conf->cmd_terminal = eina_stringshare_add(cfdata->cmd_terminal);
|
||||
if (evry_conf->cmd_sudo)
|
||||
eina_stringshare_del(evry_conf->cmd_sudo);
|
||||
evry_conf->cmd_sudo = eina_stringshare_add(cfdata->cmd_sudo);
|
||||
|
||||
e_config_save_queue();
|
||||
return 1;
|
||||
|
@ -224,6 +232,11 @@ _basic_create_widgets(E_Config_Dialog *cfd __UNUSED__, Evas *evas, E_Config_Dial
|
|||
ob = e_widget_entry_add(evas, &(cfdata->cmd_terminal), NULL, NULL, NULL);
|
||||
e_widget_framelist_object_append(of, ob);
|
||||
|
||||
ob = e_widget_label_add(evas, _("Sudo GUI"));
|
||||
e_widget_framelist_object_append(of, ob);
|
||||
ob = e_widget_entry_add(evas, &(cfdata->cmd_sudo), NULL, NULL, NULL);
|
||||
e_widget_framelist_object_append(of, ob);
|
||||
|
||||
e_widget_list_object_append(o, of, 1, 1, 0.5);
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
#include "e_mod_main.h"
|
||||
|
||||
#define HISTORY_VERSION 6
|
||||
#define HISTORY_VERSION 7
|
||||
|
||||
#define TIME_NOW (1.0 - (evry_hist->begin / ecore_time_get())) / 1000000000000.0
|
||||
#define SEVEN_DAYS 604800
|
||||
|
||||
#define TIME_FACTOR(_now) (1.0 - (evry_hist->begin / _now)) / 1000000000000000.0
|
||||
|
||||
typedef struct _Cleanup_Data Cleanup_Data;
|
||||
|
||||
|
@ -31,6 +33,7 @@ evry_history_init(void)
|
|||
E_CONFIG_VAL(D, T, context, STR);
|
||||
E_CONFIG_VAL(D, T, input, STR);
|
||||
E_CONFIG_VAL(D, T, last_used, DOUBLE);
|
||||
E_CONFIG_VAL(D, T, usage, DOUBLE);
|
||||
E_CONFIG_VAL(D, T, count, INT);
|
||||
E_CONFIG_VAL(D, T, transient, INT);
|
||||
#undef T
|
||||
|
@ -45,9 +48,9 @@ evry_history_init(void)
|
|||
#define T History
|
||||
#define D hist_edd
|
||||
E_CONFIG_VAL(D, T, version, INT);
|
||||
E_CONFIG_VAL(D, T, begin, DOUBLE);
|
||||
E_CONFIG_HASH(D, T, subjects, hist_entry_edd);
|
||||
E_CONFIG_HASH(D, T, actions, hist_entry_edd);
|
||||
E_CONFIG_VAL(D, T, begin, DOUBLE);
|
||||
#undef T
|
||||
#undef D
|
||||
}
|
||||
|
@ -83,6 +86,12 @@ _hist_cleanup_cb(const Eina_Hash *hash, const void *key, void *data, void *fdata
|
|||
|
||||
EINA_LIST_FOREACH_SAFE(he->items, l, ll, hi)
|
||||
{
|
||||
if (hi->last_used < d->time - SEVEN_DAYS)
|
||||
{
|
||||
hi->count--;
|
||||
hi->last_used = d->time - SEVEN_DAYS/2;
|
||||
}
|
||||
|
||||
/* item is transient or too old */
|
||||
if (!hi->count || hi->transient)
|
||||
{
|
||||
|
@ -117,7 +126,7 @@ evry_history_free(void)
|
|||
if (evry_hist)
|
||||
{
|
||||
d = E_NEW(Cleanup_Data, 1);
|
||||
/* d->time = ecore_time_get() - SOME_YEARS; */
|
||||
d->time = ecore_time_get();
|
||||
|
||||
if (evry_hist->subjects)
|
||||
{
|
||||
|
@ -199,10 +208,7 @@ evry_history_add(Eina_Hash *hist, Evry_State *s)
|
|||
it = s->cur_item;
|
||||
if (!it) return;
|
||||
|
||||
if (it->id)
|
||||
id = it->id;
|
||||
else
|
||||
id = it->label;
|
||||
id = (it->id ? it->id : it->label);
|
||||
|
||||
he = eina_hash_find(hist, id);
|
||||
if (!he)
|
||||
|
@ -212,72 +218,32 @@ evry_history_add(Eina_Hash *hist, Evry_State *s)
|
|||
}
|
||||
else
|
||||
{
|
||||
/* found history entry */
|
||||
EINA_LIST_FOREACH(he->items, l, hi)
|
||||
if (hi->plugin == it->plugin->name) break;
|
||||
|
||||
if (hi)
|
||||
{
|
||||
/* found history item */
|
||||
if (hi->input)
|
||||
{
|
||||
if (!s->input || !strncmp (hi->input, s->input, strlen(s->input)))
|
||||
{
|
||||
/* s->input matches hi->input and is equal or shorter */
|
||||
hi->last_used = TIME_NOW;
|
||||
hi->count++;
|
||||
hi->transient = it->transient;
|
||||
if (it->transient)
|
||||
hi->count++;
|
||||
|
||||
}
|
||||
else if (s->input)
|
||||
{
|
||||
if (!strncmp (hi->input, s->input, strlen(hi->input)))
|
||||
{
|
||||
/* s->input matches hi->input but is longer */
|
||||
eina_stringshare_del(hi->input);
|
||||
hi->input = eina_stringshare_add(s->input);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* s->input is different from hi->input
|
||||
-> create new item */
|
||||
hi = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* remember input for item */
|
||||
hi->count++;
|
||||
|
||||
if (it->transient)
|
||||
hi->count++;
|
||||
|
||||
/* hi->last_used /= 2.0; */
|
||||
hi->last_used = TIME_NOW;
|
||||
|
||||
if (s->input)
|
||||
hi->input = eina_stringshare_add(s->input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!hi)
|
||||
{
|
||||
hi = E_NEW(History_Item, 1);
|
||||
hi->plugin = eina_stringshare_ref(it->plugin->name);
|
||||
hi->last_used = TIME_NOW;
|
||||
he->items = eina_list_append(he->items, hi);
|
||||
}
|
||||
|
||||
hi->count = 1;
|
||||
if (it->transient)
|
||||
hi->count++;
|
||||
if (hi)
|
||||
{
|
||||
hi->last_used = ecore_time_get();
|
||||
hi->usage /= 4.0;
|
||||
hi->usage += TIME_FACTOR(hi->last_used);
|
||||
hi->transient = it->transient;
|
||||
hi->count += (hi->transient ? 2:1);
|
||||
|
||||
if (s->input)
|
||||
hi->input = eina_stringshare_add(s->input);
|
||||
{
|
||||
if (hi->input)
|
||||
eina_stringshare_del(hi->input);
|
||||
|
||||
he->items = eina_list_append(he->items, hi);
|
||||
hi->input = eina_stringshare_add(s->input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -286,18 +252,11 @@ evry_history_item_usage_set(Eina_Hash *hist, Evry_Item *it, const char *input)
|
|||
{
|
||||
History_Entry *he;
|
||||
History_Item *hi;
|
||||
const char *id;
|
||||
Eina_List *l;
|
||||
int cnt;
|
||||
|
||||
if (it->id)
|
||||
id = it->id;
|
||||
else
|
||||
id = it->label;
|
||||
it->usage = 0.0;
|
||||
|
||||
it->usage = 0;
|
||||
|
||||
if (!(he = eina_hash_find(hist, id)))
|
||||
if (!(he = eina_hash_find(hist, (it->id ? it->id : it->label))))
|
||||
return 0;
|
||||
|
||||
EINA_LIST_FOREACH(he->items, l, hi)
|
||||
|
@ -305,28 +264,26 @@ evry_history_item_usage_set(Eina_Hash *hist, Evry_Item *it, const char *input)
|
|||
if (hi->plugin != it->plugin->name)
|
||||
continue;
|
||||
|
||||
cnt = 0;
|
||||
|
||||
if (!input || !hi->input)
|
||||
{
|
||||
cnt = hi->count;
|
||||
it->usage = hi->usage * hi->count;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* higher priority for exact matches */
|
||||
if (!strncmp(input, hi->input, strlen(input)))
|
||||
{
|
||||
cnt += hi->count*2;
|
||||
it->usage += hi->usage * hi->count;
|
||||
}
|
||||
if (!strncmp(input, hi->input, strlen(hi->input)))
|
||||
{
|
||||
cnt += hi->count*2;
|
||||
it->usage += hi->usage * hi->count;
|
||||
}
|
||||
}
|
||||
it->usage += (cnt * hi->last_used);
|
||||
}
|
||||
|
||||
if (it->usage) return 1;
|
||||
if (it->usage > 0.0)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include "Evry.h"
|
||||
#include "e_mod_main.h"
|
||||
|
||||
#define TERM_ACTION_CMD "/usr/bin/xterm -hold -e '%s'"
|
||||
|
||||
|
@ -35,6 +35,7 @@ static Evry_Action *act1 = NULL;
|
|||
static Evry_Action *act2 = NULL;
|
||||
static Evry_Action *act3 = NULL;
|
||||
static Evry_Action *act4 = NULL;
|
||||
static Evry_Action *act5 = NULL;
|
||||
|
||||
static Eina_List *exe_path = NULL;
|
||||
static Ecore_Idler *exe_scan_idler = NULL;
|
||||
|
@ -209,7 +210,7 @@ _cleanup_open_with(Evry_Plugin *plugin)
|
|||
efreet_desktop_free(desktop);
|
||||
}
|
||||
|
||||
static int
|
||||
static Evry_Item_App *
|
||||
_item_add(Plugin *p, Efreet_Desktop *desktop, char *file, int match)
|
||||
{
|
||||
Evry_Item_App *app;
|
||||
|
@ -232,7 +233,7 @@ _item_add(Plugin *p, Efreet_Desktop *desktop, char *file, int match)
|
|||
EVRY_ITEM(app)->plugin = EVRY_PLUGIN(p);
|
||||
EVRY_PLUGIN_ITEM_APPEND(p, app);
|
||||
}
|
||||
return 1;
|
||||
return app;
|
||||
}
|
||||
|
||||
len = strlen(file);
|
||||
|
@ -258,7 +259,7 @@ _item_add(Plugin *p, Efreet_Desktop *desktop, char *file, int match)
|
|||
else
|
||||
exe = file;
|
||||
|
||||
if (!exe) return 0;
|
||||
if (!exe) return NULL;
|
||||
|
||||
if ((app = eina_hash_find(p->added, exe)) &&
|
||||
(!desktop || (desktop == app->desktop)))
|
||||
|
@ -269,7 +270,7 @@ _item_add(Plugin *p, Efreet_Desktop *desktop, char *file, int match)
|
|||
EVRY_ITEM(app)->plugin = EVRY_PLUGIN(p);
|
||||
EVRY_PLUGIN_ITEM_APPEND(p, app);
|
||||
}
|
||||
return 1;
|
||||
return app;
|
||||
}
|
||||
|
||||
if (desktop && !already_refd)
|
||||
|
@ -306,7 +307,7 @@ _item_add(Plugin *p, Efreet_Desktop *desktop, char *file, int match)
|
|||
EVRY_ITEM(app)->fuzzy_match = match;
|
||||
EVRY_PLUGIN_ITEM_APPEND(p, app);
|
||||
|
||||
return 1;
|
||||
return app;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -456,14 +457,32 @@ _fetch(Evry_Plugin *plugin, const char *input)
|
|||
if (input && len > 2)
|
||||
{
|
||||
char *space;
|
||||
|
||||
Evry_Item_App *app;
|
||||
char buf[256];
|
||||
if ((space = strchr(input, ' ')))
|
||||
len = (space - input);
|
||||
|
||||
EINA_LIST_FOREACH(exe_list, l, file)
|
||||
{
|
||||
if (!strncmp(file, input, len))
|
||||
_item_add(p, NULL, file, 100);
|
||||
/* && (!space || (strlen(file) == len))) */
|
||||
{
|
||||
app = _item_add(p, NULL, file, 100);
|
||||
|
||||
if (app)
|
||||
{
|
||||
eina_stringshare_del(EVRY_ITEM(app)->label);
|
||||
if (!space)
|
||||
EVRY_ITEM(app)->label = eina_stringshare_add(file);
|
||||
else
|
||||
{
|
||||
snprintf(buf, sizeof(buf), "%s%s", file, space);
|
||||
EVRY_ITEM(app)->label = eina_stringshare_add(buf);
|
||||
eina_stringshare_del(app->file);
|
||||
app->file = eina_stringshare_add(buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -514,7 +533,6 @@ _exec_app_action(Evry_Action *act)
|
|||
return evry_util_exec_app(act->item1, act->item2);
|
||||
}
|
||||
|
||||
/* TODO config option for terminal and shell! */
|
||||
static int
|
||||
_exec_term_action(Evry_Action *act)
|
||||
{
|
||||
|
@ -524,7 +542,11 @@ _exec_term_action(Evry_Action *act)
|
|||
int ret;
|
||||
|
||||
tmp = E_NEW(Evry_Item_App, 1);
|
||||
snprintf(buf, sizeof(buf), TERM_ACTION_CMD, app->file);
|
||||
snprintf(buf, sizeof(buf), "%s%s %s",
|
||||
evry_conf->cmd_terminal,
|
||||
(strcmp(evry_conf->cmd_terminal, "/usr/bin/xterm") ? "" : " -hold -e"),
|
||||
app->file);
|
||||
|
||||
tmp->file = buf;
|
||||
ret = evry_util_exec_app(EVRY_ITEM(tmp), NULL);
|
||||
|
||||
|
@ -544,6 +566,27 @@ _exec_term_check_item(Evry_Action *act __UNUSED__, const Evry_Item *it)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
_exec_sudo_action(Evry_Action *act)
|
||||
{
|
||||
ITEM_APP(app, act->item1);
|
||||
Evry_Item_App *tmp;
|
||||
char buf[1024];
|
||||
int ret;
|
||||
|
||||
tmp = E_NEW(Evry_Item_App, 1);
|
||||
snprintf(buf, sizeof(buf), "%s %s",
|
||||
evry_conf->cmd_sudo,
|
||||
(app->desktop ? app->desktop->exec : app->file));
|
||||
|
||||
tmp->file = buf;
|
||||
ret = evry_util_exec_app(EVRY_ITEM(tmp), NULL);
|
||||
|
||||
E_FREE(tmp);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
_open_with_action(Evry_Plugin *plugin, const Evry_Item *it)
|
||||
{
|
||||
|
@ -555,8 +598,6 @@ _open_with_action(Evry_Plugin *plugin, const Evry_Item *it)
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int
|
||||
_edit_app_check_item(Evry_Action *act __UNUSED__, const Evry_Item *it)
|
||||
{
|
||||
|
@ -699,15 +740,16 @@ _init(void)
|
|||
_new_app_action, _new_app_check_item,
|
||||
NULL, NULL, NULL);
|
||||
|
||||
act5 = evry_action_new("Run with Sudo", "APPLICATION", NULL, NULL,
|
||||
"system-run",
|
||||
_exec_sudo_action, NULL, NULL, NULL, NULL);
|
||||
|
||||
evry_action_register(act, 0);
|
||||
evry_action_register(act1, 1);
|
||||
evry_action_register(act2, 2);
|
||||
evry_action_register(act3, 3);
|
||||
evry_action_register(act4, 4);
|
||||
|
||||
|
||||
|
||||
|
||||
evry_action_register(act5, 5);
|
||||
|
||||
/* taken from e_exebuf.c */
|
||||
exelist_exe_edd = E_CONFIG_DD_NEW("E_Exe", E_Exe);
|
||||
|
@ -738,6 +780,7 @@ _shutdown(void)
|
|||
evry_action_free(act2);
|
||||
evry_action_free(act3);
|
||||
evry_action_free(act4);
|
||||
evry_action_free(act5);
|
||||
|
||||
E_CONFIG_DD_FREE(exelist_edd);
|
||||
E_CONFIG_DD_FREE(exelist_exe_edd);
|
||||
|
|
Loading…
Reference in New Issue