'everything'

- moved history functions to evry_history.c
- unload history hash when popup is not visible
- TODO cleanup history when it ahs grown too large


SVN revision: 42097
This commit is contained in:
Hannes Janetzek 2009-08-30 12:01:50 +00:00
parent b08b15d677
commit 7fca6dcf82
6 changed files with 271 additions and 249 deletions

View File

@ -31,6 +31,7 @@ module_la_SOURCES = $(EVRYHEADERS) \
evry.c \
evry_config.c \
evry_util.c \
evry_history.c \
evry_plug_aggregator.c \
evry_plug_actions.c \
evry_view_plugin_tabs.c

View File

@ -10,7 +10,6 @@
#include "e_mod_main.h"
#define CONFIG_VERSION 5
#define HISTORY_VERSION 1
/* actual module specifics */
static void _e_mod_action_cb(E_Object *obj, const char *params);
@ -19,8 +18,6 @@ static void _e_mod_run_cb(void *data, E_Menu *m, E_Menu_Item *mi);
static void _e_mod_menu_add(void *data, E_Menu *m);
static void _config_init(void);
static void _config_free(void);
static void _history_init(void);
static void _history_free(void);
static E_Int_Menu_Augmentation *maug = NULL;
static E_Action *act = NULL;
@ -28,13 +25,9 @@ static E_Action *act = NULL;
static Eina_Array *plugins = NULL;
static E_Config_DD *conf_edd = NULL;
static E_Config_DD *conf_item_edd = NULL;
static E_Config_DD *hist_entry_edd = NULL;
static E_Config_DD *hist_item_edd = NULL;
static E_Config_DD *hist_edd = NULL;
Config *evry_conf = NULL;
History *evry_hist = NULL;
/* module setup */
EAPI E_Module_Api e_modapi =
@ -64,7 +57,7 @@ e_modapi_init(E_Module *m)
* ecore_file_mkdir(buf); */
_config_init();
_history_init();
evry_history_init();
/* search for plugins */
eina_module_init();
@ -147,14 +140,11 @@ e_modapi_shutdown(E_Module *m __UNUSED__)
e_configure_registry_category_del("extensions");
_config_free();
_history_free();
evry_history_free();
/* Clean EET */
E_CONFIG_DD_FREE(conf_item_edd);
E_CONFIG_DD_FREE(conf_edd);
E_CONFIG_DD_FREE(hist_item_edd);
E_CONFIG_DD_FREE(hist_entry_edd);
E_CONFIG_DD_FREE(hist_edd);
return 1;
}
@ -166,13 +156,6 @@ e_modapi_save(E_Module *m __UNUSED__)
return 1;
}
void
evry_save_history(void)
{
e_config_domain_save("module.everything.history", hist_edd, evry_hist);
}
static void
_config_init()
{
@ -270,89 +253,6 @@ _config_free(void)
}
static void
_history_init(void)
{
#undef T
#undef D
#define T History_Item
#define D hist_item_edd
hist_item_edd = E_CONFIG_DD_NEW("History_Item", History_Item);
E_CONFIG_VAL(D, T, plugin, STR);
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, count, INT);
#undef T
#undef D
#define T History_Entry
#define D hist_entry_edd
hist_entry_edd = E_CONFIG_DD_NEW("History_Entry", History_Entry);
E_CONFIG_LIST(D, T, items, hist_item_edd);
#undef T
#undef D
#define T History
#define D hist_edd
hist_edd = E_CONFIG_DD_NEW("History_Item", History);
E_CONFIG_VAL(D, T, version, INT);
E_CONFIG_HASH(D, T, subjects, hist_entry_edd);
E_CONFIG_HASH(D, T, actions, hist_entry_edd);
#undef T
#undef D
evry_hist = e_config_domain_load("module.everything.history", hist_edd);
if (evry_hist && evry_hist->version != HISTORY_VERSION)
{
_history_free();
evry_hist = NULL;
}
if (!evry_hist)
{
evry_hist = E_NEW(History, 1);
evry_hist->version = HISTORY_VERSION;
}
if (!evry_hist->subjects)
evry_hist->subjects = eina_hash_string_superfast_new(NULL);
if (!evry_hist->actions)
evry_hist->actions = eina_hash_string_superfast_new(NULL);
}
static Eina_Bool
_hist_free_cb(const Eina_Hash *hash, const void *key, void *data, void *fdata)
{
History_Entry *he = data;
History_Item *hi;
EINA_LIST_FREE(he->items, hi)
{
if (hi->input)
eina_stringshare_del(hi->input);
if (hi->plugin)
eina_stringshare_del(hi->plugin);
if (hi->context)
eina_stringshare_del(hi->context);
E_FREE(hi);
}
E_FREE(he);
return 1;
}
static void
_history_free(void)
{
eina_hash_foreach(evry_hist->subjects, _hist_free_cb, NULL);
eina_hash_foreach(evry_hist->actions, _hist_free_cb, NULL);
E_FREE(evry_hist);
}
/* action callback */
static void
_e_mod_action_cb(E_Object *obj, const char *params)

View File

@ -115,11 +115,13 @@ EAPI int e_modapi_shutdown (E_Module *m);
EAPI int e_modapi_save (E_Module *m);
EAPI E_Config_Dialog *evry_config_dialog(E_Container *con, const char *params);
EAPI Tab_View *evry_tab_view_new(const Evry_State *s, Evas *e);
EAPI void evry_tab_view_free(Tab_View *v);
int evry_init(void);
int evry_shutdown(void);
int evry_show(E_Zone *zone, const char *params);
void evry_hide(void);
void evry_save_history(void);
Evry_Plugin *evry_plug_aggregator_new(Evry_Selector *selector);
void evry_plug_aggregator_free(Evry_Plugin *plugin);
@ -127,8 +129,12 @@ void evry_plug_aggregator_free(Evry_Plugin *plugin);
Evry_Plugin *evry_plug_actions_new(void);
void evry_plug_actions_free(Evry_Plugin *plugin);
EAPI Tab_View *evry_tab_view_new(const Evry_State *s, Evas *e);
EAPI void evry_tab_view_free(Tab_View *v);
void evry_history_init(void);
void evry_history_free(void);
void evry_history_load(void);
void evry_history_unload(void);
void evry_history_add(Eina_Hash *hist, Evry_State *s);
int evry_history_item_usage_set(Eina_Hash *hist, Evry_Item *it, const char *input);
extern Config *evry_conf;
extern History *evry_hist;

View File

@ -81,8 +81,6 @@ static void _evry_item_sel(Evry_State *s, Evry_Item *it);
static int _evry_cb_key_down(void *data, int type, void *event);
static int _evry_cb_selection_notify(void *data, int type, void *event);
static void _evry_history_item_add(Eina_Hash *hist, Evry_State *s);
/* local subsystem globals */
static Evry_Window *win = NULL;
@ -139,6 +137,8 @@ evry_show(E_Zone *zone, const char *params)
list->visible = EINA_FALSE;
evry_history_load();
selectors = E_NEW(Evry_Selector*, 3);
selectors[0] = _evry_selector_new(type_subject);
selectors[1] = _evry_selector_new(type_action);
@ -147,6 +147,7 @@ evry_show(E_Zone *zone, const char *params)
if (params)
win->plugin_dedicated = EINA_TRUE;
_evry_selector_subjects_get(params);
_evry_selector_activate(selectors[0]);
@ -242,6 +243,8 @@ evry_hide(void)
ecore_x_window_free(input_window);
e_grabinput_release(input_window, input_window);
input_window = 0;
evry_history_unload();
}
EAPI void
@ -1060,7 +1063,7 @@ _evry_browse_item(Evry_Selector *sel)
if (!plugins) return 1;
_evry_history_item_add(sel->history, s);
evry_history_add(sel->history, s);
if (s->view)
{
@ -1362,102 +1365,6 @@ _evry_clear(Evry_State *s)
return 0;
}
static void
_evry_history_item_add(Eina_Hash *hist, Evry_State *s)
{
History_Entry *he;
History_Item *hi;
Evry_Item *it;
Eina_List *l;
const char *id;
if (!s) return;
it = s->cur_item;
if (!it) return;
if (it->plugin->item_id)
id = it->plugin->item_id(it->plugin, it);
else
id = it->label;
he = eina_hash_find(hist, id);
if (he)
{
/* 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->count++;
hi->last_used /= 1000.0;
hi->last_used += ecore_time_get();
}
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++;
hi->last_used /= 2.0;
hi->last_used += ecore_time_get();
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 = ecore_time_get();
hi->count = 1;
if (s->input)
hi->input = eina_stringshare_add(s->input);
he->items = eina_list_append(he->items, hi);
}
}
else
{
he = E_NEW(History_Entry, 1);
hi = E_NEW(History_Item, 1);
hi->plugin = eina_stringshare_ref(it->plugin->name);
hi->last_used = ecore_time_get();
hi->count = 1;
if (s->input)
hi->input = eina_stringshare_add(s->input);
he->items = eina_list_append(he->items, hi);
eina_hash_add(hist, id, he);
}
evry_save_history();
}
static void
_evry_plugin_action(Evry_Selector *sel, int finished)
{
@ -1506,10 +1413,9 @@ _evry_plugin_action(Evry_Selector *sel, int finished)
}
else return;
_evry_history_item_add(evry_hist->subjects, s_subject);
_evry_history_item_add(evry_hist->actions, s_action);
_evry_history_item_add(evry_hist->subjects, s_object);
evry_history_add(evry_hist->subjects, s_subject);
evry_history_add(evry_hist->actions, s_action);
evry_history_add(evry_hist->subjects, s_object);
/* let subject and object plugin know that an action was performed */
if (s_subject->plugin->action)

View File

@ -0,0 +1,242 @@
#include "e_mod_main.h"
#define HISTORY_VERSION 2
static E_Config_DD *hist_entry_edd = NULL;
static E_Config_DD *hist_item_edd = NULL;
static E_Config_DD *hist_edd = NULL;
History *evry_hist = NULL;
void
evry_history_init(void)
{
#undef T
#undef D
hist_item_edd = E_CONFIG_DD_NEW("History_Item", History_Item);
#define T History_Item
#define D hist_item_edd
E_CONFIG_VAL(D, T, plugin, STR);
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, count, INT);
#undef T
#undef D
hist_entry_edd = E_CONFIG_DD_NEW("History_Entry", History_Entry);
#define T History_Entry
#define D hist_entry_edd
E_CONFIG_LIST(D, T, items, hist_item_edd);
#undef T
#undef D
hist_edd = E_CONFIG_DD_NEW("History_Item", History);
#define T History
#define D hist_edd
E_CONFIG_VAL(D, T, version, INT);
E_CONFIG_HASH(D, T, subjects, hist_entry_edd);
E_CONFIG_HASH(D, T, actions, hist_entry_edd);
#undef T
#undef D
}
static Eina_Bool
_hist_free_cb(const Eina_Hash *hash, const void *key, void *data, void *fdata)
{
History_Entry *he = data;
History_Item *hi;
EINA_LIST_FREE(he->items, hi)
{
if (hi->input)
eina_stringshare_del(hi->input);
if (hi->plugin)
eina_stringshare_del(hi->plugin);
if (hi->context)
eina_stringshare_del(hi->context);
E_FREE(hi);
}
E_FREE(he);
return 1;
}
void
evry_history_free(void)
{
E_CONFIG_DD_FREE(hist_item_edd);
E_CONFIG_DD_FREE(hist_entry_edd);
E_CONFIG_DD_FREE(hist_edd);
}
void
evry_history_load(void)
{
evry_hist = e_config_domain_load("module.everything.history", hist_edd);
if (evry_hist && evry_hist->version != HISTORY_VERSION)
{
eina_hash_foreach(evry_hist->subjects, _hist_free_cb, NULL);
eina_hash_foreach(evry_hist->actions, _hist_free_cb, NULL);
E_FREE(evry_hist);
evry_hist = NULL;
}
if (!evry_hist)
{
evry_hist = E_NEW(History, 1);
evry_hist->version = HISTORY_VERSION;
}
if (!evry_hist->subjects)
evry_hist->subjects = eina_hash_string_superfast_new(NULL);
if (!evry_hist->actions)
evry_hist->actions = eina_hash_string_superfast_new(NULL);
}
void
evry_history_unload(void)
{
if (!evry_hist) return;
e_config_domain_save("module.everything.history", hist_edd, evry_hist);
eina_hash_foreach(evry_hist->subjects, _hist_free_cb, NULL);
eina_hash_foreach(evry_hist->actions, _hist_free_cb, NULL);
E_FREE(evry_hist);
evry_hist = NULL;
}
void
evry_history_add(Eina_Hash *hist, Evry_State *s)
{
History_Entry *he;
History_Item *hi;
Evry_Item *it;
Eina_List *l;
const char *id;
if (!s) return;
it = s->cur_item;
if (!it) return;
if (it->plugin->item_id)
id = it->plugin->item_id(it->plugin, it);
else
id = it->label;
he = eina_hash_find(hist, id);
if (he)
{
/* 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->count++;
hi->last_used /= 1000.0;
hi->last_used += ecore_time_get();
}
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++;
hi->last_used /= 2.0;
hi->last_used += ecore_time_get();
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 = ecore_time_get();
hi->count = 1;
if (s->input)
hi->input = eina_stringshare_add(s->input);
he->items = eina_list_append(he->items, hi);
}
}
else
{
he = E_NEW(History_Entry, 1);
hi = E_NEW(History_Item, 1);
hi->plugin = eina_stringshare_ref(it->plugin->name);
hi->last_used = ecore_time_get();
hi->count = 1;
if (s->input)
hi->input = eina_stringshare_add(s->input);
he->items = eina_list_append(he->items, hi);
eina_hash_add(hist, id, he);
}
}
int
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 = 1;
if (it->plugin->item_id)
id = it->plugin->item_id(it->plugin, it);
else
id = it->label;
it->usage = 0;
if ((he = eina_hash_find(hist, id)))
{
EINA_LIST_FOREACH(he->items, l, hi)
{
if ((hi->plugin == it->plugin->name) &&
((!input[0]) || (!input[0] && !hi->input) ||
(!strncmp(input, hi->input, strlen(input))) ||
(!strncmp(input, hi->input, strlen(hi->input)))))
{
cnt++;
it->usage += hi->last_used;
}
}
if (it->usage)
{
it->usage /= (double)cnt;
return 1;
}
}
return 0;
}

View File

@ -97,13 +97,10 @@ _fetch(Evry_Plugin *plugin, const char *input)
Plugin *p = (Plugin *) plugin;
Evry_Plugin *pp;
Evry_State *s;
Eina_List *l, *ll, *lll, *lp;
Eina_List *l, *ll, *lp;
Evry_Item *it;
int cnt = 0;
Eina_List *items = NULL;
History_Entry *he;
History_Item *hi;
const char *id;
EVRY_PLUGIN_ITEMS_FREE(p);
@ -138,12 +135,12 @@ _fetch(Evry_Plugin *plugin, const char *input)
{
for (cnt = 0, ll = pp->items; ll && cnt < 50; ll = ll->next, cnt++)
{
if (!items || !eina_list_data_find_list(items, ll->data))
if (!eina_list_data_find_list(items, ll->data))
{
it = ll->data;
evry_item_ref(it);
it->fuzzy_match = 0;
items = eina_list_append(items, it);
EVRY_PLUGIN_ITEM_APPEND(p, it);
}
}
@ -154,11 +151,11 @@ _fetch(Evry_Plugin *plugin, const char *input)
{
EINA_LIST_FOREACH(pp->items, ll, it)
{
cnt = 1;
if (it->usage == 0)
continue;
/* if (it->usage == 0)
* continue; */
if ((it->usage > 0) && (!eina_list_data_find_list(items, it)))
if (evry_history_item_usage_set(p->selector->history, it, input) &&
(!eina_list_data_find_list(items, it)))
{
evry_item_ref(it);
it->fuzzy_match = 0;
@ -166,36 +163,6 @@ _fetch(Evry_Plugin *plugin, const char *input)
EVRY_PLUGIN_ITEM_APPEND(p, it);
continue;
}
if (it->plugin->item_id)
id = it->plugin->item_id(it->plugin, it);
else
id = it->label;
if ((he = eina_hash_find(p->selector->history, id)))
{
EINA_LIST_FOREACH(he->items, lll, hi)
{
if ((hi->plugin == it->plugin->name) &&
((!input[0]) || (!input[0] && !hi->input) ||
(!strncmp(input, hi->input, strlen(input))) ||
(!strncmp(input, hi->input, strlen(hi->input)))))
{
cnt++;
it->usage += hi->last_used;
}
}
it->usage /= (double)cnt;
if (!eina_list_data_find_list(items, it))
{
evry_item_ref(it);
it->fuzzy_match = 0;
items = eina_list_append(items, it);
EVRY_PLUGIN_ITEM_APPEND(p, it);
}
}
else it->usage = 0;
}
}