forked from enlightenment/enlightenment
parent
726a01f5c4
commit
9cc54e74c7
|
@ -4,7 +4,7 @@
|
||||||
EAPI int E_EVENT_EXEHIST_UPDATE = 0;
|
EAPI int E_EVENT_EXEHIST_UPDATE = 0;
|
||||||
|
|
||||||
/* local subsystem functions */
|
/* local subsystem functions */
|
||||||
typedef struct _E_Exehist E_Exehist;
|
typedef struct _E_Exehist E_Exehist;
|
||||||
typedef struct _E_Exehist_Item E_Exehist_Item;
|
typedef struct _E_Exehist_Item E_Exehist_Item;
|
||||||
|
|
||||||
struct _E_Exehist
|
struct _E_Exehist
|
||||||
|
@ -15,22 +15,22 @@ struct _E_Exehist
|
||||||
|
|
||||||
struct _E_Exehist_Item
|
struct _E_Exehist_Item
|
||||||
{
|
{
|
||||||
const char *exe;
|
const char *exe;
|
||||||
const char *normalized_exe;
|
const char *normalized_exe;
|
||||||
const char *launch_method;
|
const char *launch_method;
|
||||||
double exetime;
|
double exetime;
|
||||||
unsigned int count;
|
unsigned int count;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void _e_exehist_unload_queue(void);
|
static void _e_exehist_unload_queue(void);
|
||||||
static void _e_exehist_load(void);
|
static void _e_exehist_load(void);
|
||||||
static void _e_exehist_clear(void);
|
static void _e_exehist_clear(void);
|
||||||
static void _e_exehist_unload(void);
|
static void _e_exehist_unload(void);
|
||||||
static void _e_exehist_limit(void);
|
static void _e_exehist_limit(void);
|
||||||
static const char *_e_exehist_normalize_exe(const char *exe);
|
static const char *_e_exehist_normalize_exe(const char *exe);
|
||||||
static void _e_exehist_cb_unload(void *data);
|
static void _e_exehist_cb_unload(void *data);
|
||||||
static int _e_exehist_sort_exe_cb(const void *d1, const void *d2);
|
static int _e_exehist_sort_exe_cb(const void *d1, const void *d2);
|
||||||
static int _e_exehist_sort_pop_cb(const void *d1, const void *d2);
|
static int _e_exehist_sort_pop_cb(const void *d1, const void *d2);
|
||||||
|
|
||||||
/* local subsystem globals */
|
/* local subsystem globals */
|
||||||
static E_Config_DD *_e_exehist_config_edd = NULL;
|
static E_Config_DD *_e_exehist_config_edd = NULL;
|
||||||
|
@ -71,8 +71,8 @@ e_exehist_shutdown(void)
|
||||||
{
|
{
|
||||||
if (_e_exehist_unload_defer)
|
if (_e_exehist_unload_defer)
|
||||||
{
|
{
|
||||||
e_powersave_deferred_action_del(_e_exehist_unload_defer);
|
e_powersave_deferred_action_del(_e_exehist_unload_defer);
|
||||||
_e_exehist_unload_defer = NULL;
|
_e_exehist_unload_defer = NULL;
|
||||||
}
|
}
|
||||||
_e_exehist_cb_unload(NULL);
|
_e_exehist_cb_unload(NULL);
|
||||||
E_CONFIG_DD_FREE(_e_exehist_config_item_edd);
|
E_CONFIG_DD_FREE(_e_exehist_config_item_edd);
|
||||||
|
@ -90,8 +90,8 @@ e_exehist_add(const char *launch_method, const char *exe)
|
||||||
ei = E_NEW(E_Exehist_Item, 1);
|
ei = E_NEW(E_Exehist_Item, 1);
|
||||||
if (!ei)
|
if (!ei)
|
||||||
{
|
{
|
||||||
_e_exehist_unload_queue();
|
_e_exehist_unload_queue();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ei->launch_method = eina_stringshare_add(launch_method);
|
ei->launch_method = eina_stringshare_add(launch_method);
|
||||||
ei->exe = eina_stringshare_add(exe);
|
ei->exe = eina_stringshare_add(exe);
|
||||||
|
@ -115,18 +115,18 @@ e_exehist_del(const char *exe)
|
||||||
if (!_e_exehist) return;
|
if (!_e_exehist) return;
|
||||||
EINA_LIST_FOREACH(_e_exehist->history, l, ei)
|
EINA_LIST_FOREACH(_e_exehist->history, l, ei)
|
||||||
{
|
{
|
||||||
if ((ei->exe) && (!strcmp(exe, ei->exe)))
|
if ((ei->exe) && (!strcmp(exe, ei->exe)))
|
||||||
{
|
{
|
||||||
eina_stringshare_del(ei->exe);
|
eina_stringshare_del(ei->exe);
|
||||||
eina_stringshare_del(ei->normalized_exe);
|
eina_stringshare_del(ei->normalized_exe);
|
||||||
eina_stringshare_del(ei->launch_method);
|
eina_stringshare_del(ei->launch_method);
|
||||||
free(ei);
|
free(ei);
|
||||||
_e_exehist->history = eina_list_remove_list(_e_exehist->history,
|
_e_exehist->history = eina_list_remove_list(_e_exehist->history,
|
||||||
l);
|
l);
|
||||||
_e_exehist_changes++;
|
_e_exehist_changes++;
|
||||||
_e_exehist_unload_queue();
|
_e_exehist_unload_queue();
|
||||||
ok = EINA_TRUE;
|
ok = EINA_TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ok)
|
if (ok)
|
||||||
ecore_event_add(E_EVENT_EXEHIST_UPDATE, NULL, NULL, NULL);
|
ecore_event_add(E_EVENT_EXEHIST_UPDATE, NULL, NULL, NULL);
|
||||||
|
@ -157,8 +157,8 @@ e_exehist_popularity_get(const char *exe)
|
||||||
if (!normal) return 0;
|
if (!normal) return 0;
|
||||||
EINA_LIST_FOREACH(_e_exehist->history, l, ei)
|
EINA_LIST_FOREACH(_e_exehist->history, l, ei)
|
||||||
{
|
{
|
||||||
if ((ei->normalized_exe) && (!strcmp(normal, ei->normalized_exe)))
|
if ((ei->normalized_exe) && (!strcmp(normal, ei->normalized_exe)))
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
eina_stringshare_del(normal);
|
eina_stringshare_del(normal);
|
||||||
_e_exehist_unload_queue();
|
_e_exehist_unload_queue();
|
||||||
|
@ -178,12 +178,12 @@ e_exehist_newest_run_get(const char *exe)
|
||||||
if (!normal) return 0.0;
|
if (!normal) return 0.0;
|
||||||
EINA_LIST_REVERSE_FOREACH(_e_exehist->history, l, ei)
|
EINA_LIST_REVERSE_FOREACH(_e_exehist->history, l, ei)
|
||||||
{
|
{
|
||||||
if ((ei->normalized_exe) && (!strcmp(normal, ei->normalized_exe)))
|
if ((ei->normalized_exe) && (!strcmp(normal, ei->normalized_exe)))
|
||||||
{
|
{
|
||||||
eina_stringshare_del(normal);
|
eina_stringshare_del(normal);
|
||||||
_e_exehist_unload_queue();
|
_e_exehist_unload_queue();
|
||||||
return ei->exetime;
|
return ei->exetime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
eina_stringshare_del(normal);
|
eina_stringshare_del(normal);
|
||||||
_e_exehist_unload_queue();
|
_e_exehist_unload_queue();
|
||||||
|
@ -207,64 +207,65 @@ e_exehist_sorted_list_get(E_Exehist_Sort sort_type, int max)
|
||||||
|
|
||||||
if (!max) max = 20;
|
if (!max) max = 20;
|
||||||
_e_exehist_load();
|
_e_exehist_load();
|
||||||
switch(sort_type)
|
switch (sort_type)
|
||||||
{
|
{
|
||||||
case E_EXEHIST_SORT_BY_EXE:
|
case E_EXEHIST_SORT_BY_EXE:
|
||||||
case E_EXEHIST_SORT_BY_POPULARITY:
|
case E_EXEHIST_SORT_BY_POPULARITY:
|
||||||
l = eina_list_clone(_e_exehist->history);
|
l = eina_list_clone(_e_exehist->history);
|
||||||
l = eina_list_sort(l, 0, _e_exehist_sort_exe_cb);
|
l = eina_list_sort(l, 0, _e_exehist_sort_exe_cb);
|
||||||
iter = eina_list_iterator_new(l);
|
iter = eina_list_iterator_new(l);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
iter = eina_list_iterator_reversed_new(_e_exehist->history);
|
iter = eina_list_iterator_reversed_new(_e_exehist->history);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
EINA_ITERATOR_FOREACH(iter, ei)
|
EINA_ITERATOR_FOREACH(iter, ei)
|
||||||
{
|
{
|
||||||
int bad = 0;
|
int bad = 0;
|
||||||
|
|
||||||
if (!(ei->normalized_exe)) continue;
|
if (!(ei->normalized_exe)) continue;
|
||||||
if (sort_type == E_EXEHIST_SORT_BY_POPULARITY)
|
if (sort_type == E_EXEHIST_SORT_BY_POPULARITY)
|
||||||
{
|
{
|
||||||
if (!prev || (strcmp(prev->normalized_exe, ei->normalized_exe)))
|
if (!prev || (strcmp(prev->normalized_exe, ei->normalized_exe)))
|
||||||
{
|
{
|
||||||
prev = ei;
|
prev = ei;
|
||||||
pop = eina_list_append(pop, ei);
|
pop = eina_list_append(pop, ei);
|
||||||
}
|
}
|
||||||
prev->count++;
|
prev->count++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const char *exe;
|
const char *exe;
|
||||||
|
|
||||||
EINA_LIST_FOREACH(list, m, exe)
|
EINA_LIST_FOREACH(list, m, exe)
|
||||||
{
|
{
|
||||||
if (!exe) continue;
|
if (!exe) continue;
|
||||||
if (!strcmp(exe, ei->exe))
|
if (!strcmp(exe, ei->exe))
|
||||||
{
|
{
|
||||||
bad = 1;
|
bad = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!(bad))
|
if (!(bad))
|
||||||
{
|
{
|
||||||
list = eina_list_append(list, ei->exe);
|
list = eina_list_append(list, ei->exe);
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (count > max) break;
|
if (count > max) break;
|
||||||
}
|
}
|
||||||
if (sort_type == E_EXEHIST_SORT_BY_POPULARITY)
|
if (sort_type == E_EXEHIST_SORT_BY_POPULARITY)
|
||||||
{
|
{
|
||||||
count = 1;
|
count = 1;
|
||||||
pop = eina_list_sort(pop, 0, _e_exehist_sort_pop_cb);
|
pop = eina_list_sort(pop, 0, _e_exehist_sort_pop_cb);
|
||||||
EINA_LIST_FOREACH(pop, l, prev)
|
EINA_LIST_FOREACH(pop, l, prev)
|
||||||
{
|
{
|
||||||
list = eina_list_append(list, prev->exe);
|
list = eina_list_append(list, prev->exe);
|
||||||
count++;
|
count++;
|
||||||
if (count > max) break;
|
if (count > max) break;
|
||||||
}
|
}
|
||||||
eina_list_free(pop);
|
eina_list_free(pop);
|
||||||
}
|
}
|
||||||
eina_list_free(l);
|
eina_list_free(l);
|
||||||
eina_iterator_free(iter);
|
eina_iterator_free(iter);
|
||||||
|
@ -309,26 +310,26 @@ e_exehist_mime_desktop_add(const char *mime, Efreet_Desktop *desktop)
|
||||||
|
|
||||||
EINA_LIST_FOREACH(_e_exehist->mimes, l, ei)
|
EINA_LIST_FOREACH(_e_exehist->mimes, l, ei)
|
||||||
{
|
{
|
||||||
if ((ei->launch_method) && (!strcmp(mime, ei->launch_method)))
|
if ((ei->launch_method) && (!strcmp(mime, ei->launch_method)))
|
||||||
{
|
{
|
||||||
if ((ei->exe) && (!strcmp(f, ei->exe)))
|
if ((ei->exe) && (!strcmp(f, ei->exe)))
|
||||||
{
|
{
|
||||||
_e_exehist_unload_queue();
|
_e_exehist_unload_queue();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (ei->exe) eina_stringshare_del(ei->exe);
|
if (ei->exe) eina_stringshare_del(ei->exe);
|
||||||
if (ei->launch_method) eina_stringshare_del(ei->launch_method);
|
if (ei->launch_method) eina_stringshare_del(ei->launch_method);
|
||||||
free(ei);
|
free(ei);
|
||||||
_e_exehist->mimes = eina_list_remove_list(_e_exehist->mimes, l);
|
_e_exehist->mimes = eina_list_remove_list(_e_exehist->mimes, l);
|
||||||
_e_exehist_changes++;
|
_e_exehist_changes++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ei = E_NEW(E_Exehist_Item, 1);
|
ei = E_NEW(E_Exehist_Item, 1);
|
||||||
if (!ei)
|
if (!ei)
|
||||||
{
|
{
|
||||||
_e_exehist_unload_queue();
|
_e_exehist_unload_queue();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ei->launch_method = eina_stringshare_add(mime);
|
ei->launch_method = eina_stringshare_add(mime);
|
||||||
ei->exe = eina_stringshare_add(f);
|
ei->exe = eina_stringshare_add(f);
|
||||||
|
@ -354,17 +355,17 @@ e_exehist_mime_desktop_get(const char *mime)
|
||||||
EINA_LIST_FOREACH(_e_exehist->mimes, l, ei)
|
EINA_LIST_FOREACH(_e_exehist->mimes, l, ei)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "look for %s == %s\n", mime, ei->launch_method);
|
fprintf(stderr, "look for %s == %s\n", mime, ei->launch_method);
|
||||||
if ((ei->launch_method) && (!strcmp(mime, ei->launch_method)))
|
if ((ei->launch_method) && (!strcmp(mime, ei->launch_method)))
|
||||||
{
|
{
|
||||||
desktop = NULL;
|
desktop = NULL;
|
||||||
if (ei->exe) desktop = efreet_util_desktop_file_id_find(ei->exe);
|
if (ei->exe) desktop = efreet_util_desktop_file_id_find(ei->exe);
|
||||||
fprintf(stderr, " desk = %p\n", desktop);
|
fprintf(stderr, " desk = %p\n", desktop);
|
||||||
if (desktop)
|
if (desktop)
|
||||||
{
|
{
|
||||||
_e_exehist_unload_queue();
|
_e_exehist_unload_queue();
|
||||||
return desktop;
|
return desktop;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_e_exehist_unload_queue();
|
_e_exehist_unload_queue();
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -394,20 +395,20 @@ _e_exehist_clear(void)
|
||||||
{
|
{
|
||||||
if (_e_exehist)
|
if (_e_exehist)
|
||||||
{
|
{
|
||||||
E_Exehist_Item *ei;
|
E_Exehist_Item *ei;
|
||||||
EINA_LIST_FREE(_e_exehist->history, ei)
|
EINA_LIST_FREE(_e_exehist->history, ei)
|
||||||
{
|
{
|
||||||
eina_stringshare_del(ei->exe);
|
eina_stringshare_del(ei->exe);
|
||||||
eina_stringshare_del(ei->normalized_exe);
|
eina_stringshare_del(ei->normalized_exe);
|
||||||
eina_stringshare_del(ei->launch_method);
|
eina_stringshare_del(ei->launch_method);
|
||||||
free(ei);
|
free(ei);
|
||||||
}
|
}
|
||||||
EINA_LIST_FREE(_e_exehist->mimes, ei)
|
EINA_LIST_FREE(_e_exehist->mimes, ei)
|
||||||
{
|
{
|
||||||
eina_stringshare_del(ei->exe);
|
eina_stringshare_del(ei->exe);
|
||||||
eina_stringshare_del(ei->launch_method);
|
eina_stringshare_del(ei->launch_method);
|
||||||
free(ei);
|
free(ei);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -428,27 +429,27 @@ _e_exehist_limit(void)
|
||||||
*/
|
*/
|
||||||
if (_e_exehist)
|
if (_e_exehist)
|
||||||
{
|
{
|
||||||
while (eina_list_count(_e_exehist->history) > 500)
|
while (eina_list_count(_e_exehist->history) > 500)
|
||||||
{
|
{
|
||||||
E_Exehist_Item *ei;
|
E_Exehist_Item *ei;
|
||||||
|
|
||||||
ei = eina_list_data_get(_e_exehist->history);
|
ei = eina_list_data_get(_e_exehist->history);
|
||||||
eina_stringshare_del(ei->exe);
|
eina_stringshare_del(ei->exe);
|
||||||
eina_stringshare_del(ei->normalized_exe);
|
eina_stringshare_del(ei->normalized_exe);
|
||||||
eina_stringshare_del(ei->launch_method);
|
eina_stringshare_del(ei->launch_method);
|
||||||
free(ei);
|
free(ei);
|
||||||
_e_exehist->history = eina_list_remove_list(_e_exehist->history, _e_exehist->history);
|
_e_exehist->history = eina_list_remove_list(_e_exehist->history, _e_exehist->history);
|
||||||
}
|
}
|
||||||
while (eina_list_count(_e_exehist->mimes) > 500)
|
while (eina_list_count(_e_exehist->mimes) > 500)
|
||||||
{
|
{
|
||||||
E_Exehist_Item *ei;
|
E_Exehist_Item *ei;
|
||||||
|
|
||||||
ei = eina_list_data_get(_e_exehist->mimes);
|
ei = eina_list_data_get(_e_exehist->mimes);
|
||||||
eina_stringshare_del(ei->exe);
|
eina_stringshare_del(ei->exe);
|
||||||
eina_stringshare_del(ei->launch_method);
|
eina_stringshare_del(ei->launch_method);
|
||||||
free(ei);
|
free(ei);
|
||||||
_e_exehist->mimes = eina_list_remove_list(_e_exehist->mimes, _e_exehist->mimes);
|
_e_exehist->mimes = eina_list_remove_list(_e_exehist->mimes, _e_exehist->mimes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -463,32 +464,32 @@ _e_exehist_normalize_exe(const char *exe)
|
||||||
base = basename(buf);
|
base = basename(buf);
|
||||||
if ((base[0] == '.') && (base[1] == '\0'))
|
if ((base[0] == '.') && (base[1] == '\0'))
|
||||||
{
|
{
|
||||||
free(buf);
|
free(buf);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
cp = base;
|
cp = base;
|
||||||
while (*cp)
|
while (*cp)
|
||||||
{
|
{
|
||||||
if (isspace(*cp))
|
if (isspace(*cp))
|
||||||
{
|
{
|
||||||
if (!space) space = cp;
|
if (!space) space = cp;
|
||||||
if (flag) flag = EINA_FALSE;
|
if (flag) flag = EINA_FALSE;
|
||||||
}
|
}
|
||||||
else if (!flag)
|
else if (!flag)
|
||||||
{
|
{
|
||||||
/* usually a variable in the desktop exe field */
|
/* usually a variable in the desktop exe field */
|
||||||
if (space && *cp == '%')
|
if (space && *cp == '%')
|
||||||
flag = EINA_TRUE;
|
flag = EINA_TRUE;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
char lower = tolower(*cp);
|
char lower = tolower(*cp);
|
||||||
|
|
||||||
space = NULL;
|
space = NULL;
|
||||||
if (lower != *cp) *cp = lower;
|
if (lower != *cp) *cp = lower;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cp++;
|
cp++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (space) *space = '\0';
|
if (space) *space = '\0';
|
||||||
|
@ -504,8 +505,8 @@ _e_exehist_cb_unload(void *data __UNUSED__)
|
||||||
{
|
{
|
||||||
if (_e_exehist_changes)
|
if (_e_exehist_changes)
|
||||||
{
|
{
|
||||||
e_config_domain_save("exehist", _e_exehist_config_edd, _e_exehist);
|
e_config_domain_save("exehist", _e_exehist_config_edd, _e_exehist);
|
||||||
_e_exehist_changes = 0;
|
_e_exehist_changes = 0;
|
||||||
}
|
}
|
||||||
_e_exehist_unload();
|
_e_exehist_unload();
|
||||||
_e_exehist_unload_defer = NULL;
|
_e_exehist_unload_defer = NULL;
|
||||||
|
@ -535,3 +536,4 @@ _e_exehist_sort_pop_cb(const void *d1, const void *d2)
|
||||||
|
|
||||||
return ei2->count - ei1->count;
|
return ei2->count - ei1->count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue