I've made a patch to add a new function that retrieves a sorted exe
history. Currently it can sort by date, executable or popularity. If no
one minds, I'll commit it in a few days time.
Index: src/bin/e_exehist.c
===================================================================
--- src/bin/e_exehist.c (revision 39475)
+++ src/bin/e_exehist.c (working copy)
@@ -3,6 +3,8 @@
*/
#include "e.h"
+EAPI int E_EVENT_EXEHIST_UPDATE = 0;
+
/* local subsystem functions */
typedef struct _E_Exehist E_Exehist;
typedef struct _E_Exehist_Item E_Exehist_Item;
@@ -18,6 +20,7 @@
const char *exe;
const char *launch_method;
double exetime;
+ unsigned int count;
};
static void _e_exehist_unload_queue(void);
@@ -26,6 +29,8 @@
static void _e_exehist_unload(void);
static void _e_exehist_limit(void);
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_pop_cb(const void *d1, const void *d2);
/* local subsystem globals */
static E_Config_DD *_e_exehist_config_edd = NULL;
@@ -54,6 +59,9 @@
#define D _e_exehist_config_edd
E_CONFIG_LIST(D, T, history, _e_exehist_config_item_edd);
E_CONFIG_LIST(D, T, mimes, _e_exehist_config_item_edd);
+
+ E_EVENT_EXEHIST_UPDATE = ecore_event_type_new();
+
return 1;
}
@@ -90,6 +98,7 @@
_e_exehist->history = eina_list_append(_e_exehist->history, ei);
_e_exehist_limit();
_e_exehist_changes++;
+ ecore_event_add(E_EVENT_EXEHIST_UPDATE, NULL, NULL, NULL);
_e_exehist_unload_queue();
}
@@ -98,6 +107,7 @@
{
E_Exehist_Item *ei;
Eina_List *l;
+ Eina_Bool ok = EINA_FALSE;
_e_exehist_load();
if (!_e_exehist) return;
@@ -113,8 +123,11 @@
l);
_e_exehist_changes++;
_e_exehist_unload_queue();
+ ok = EINA_TRUE;
}
}
+ if (ok)
+ ecore_event_add(E_EVENT_EXEHIST_UPDATE, NULL, NULL, NULL);
}
EAPI void
@@ -124,6 +137,7 @@
if (!_e_exehist) return;
_e_exehist_clear();
_e_exehist_changes++;
+ ecore_event_add(E_EVENT_EXEHIST_UPDATE, NULL, NULL, NULL);
_e_exehist_unload_queue();
}
@@ -171,37 +185,81 @@
EAPI Eina_List *
e_exehist_list_get(void)
{
- Eina_List *list = NULL, *l, *m;
+ return e_exehist_sorted_list_get(E_EXEHIST_SORT_BY_DATE, 0);
+}
+
+EAPI Eina_List *
+e_exehist_sorted_list_get(E_Exehist_Sort sort_type, int max)
+{
+ Eina_List *list = NULL, *pop = NULL, *l = NULL, *m;
int count = 1;
- int max;
+ E_Exehist_Item *prev = NULL;
- max = e_config->exebuf_max_hist_list;
+ if (!max) max = e_config->exebuf_max_hist_list;
if (!max) max = 20;
_e_exehist_load();
- for (l = eina_list_last(_e_exehist->history); l; l = l->prev)
+ switch(sort_type)
{
+ case E_EXEHIST_SORT_BY_EXE:
+ case E_EXEHIST_SORT_BY_POPULARITY:
+ EINA_LIST_FOREACH(_e_exehist->history, pop, prev)
+ l = eina_list_append(l, prev);
+ l = eina_list_sort(l, 0, _e_exehist_sort_exe_cb);
+ pop = NULL;
+ prev = NULL;
+ break;
+ default:
+ l = eina_list_reverse(_e_exehist->history);
+ break;
+ }
+ for (; l; l = l->next)
+ {
int bad = 0;
E_Exehist_Item *ei;
ei = l->data;
if (!(ei->exe)) continue;
- for (m = list; m; m = m->next)
+ if (sort_type == E_EXEHIST_SORT_BY_POPULARITY)
{
- const char *exe;
+ if (!prev || (strcmp(prev->exe, ei->exe)))
+ {
+ prev = ei;
+ pop = eina_list_append(pop, ei);
+ }
+ prev->count++;
+ }
+ else
+ {
+ for (m = list; m; m = m->next)
+ {
+ const char *exe;
- if (!(exe = m->data)) continue;
- if (!strcmp(exe, ei->exe))
+ if (!(exe = m->data)) continue;
+ if (!strcmp(exe, ei->exe))
+ {
+ bad = 1;
+ break;
+ }
+ }
+ if (!(bad))
{
- bad = 1;
- break;
+ list = eina_list_append(list, ei->exe);
+ count++;
}
}
- if (!(bad))
+ if (count > max) break;
+ }
+ if (sort_type == E_EXEHIST_SORT_BY_POPULARITY)
+ {
+ count = 1;
+ pop = eina_list_sort(pop, 0, _e_exehist_sort_pop_cb);
+ EINA_LIST_FOREACH(pop, l, prev)
{
- list = eina_list_append(list, ei->exe);
+ list = eina_list_append(list, prev->exe);
count++;
+ if (count > max) break;
}
- if (count > max) break;
+ eina_list_free(pop);
}
_e_exehist_unload_queue();
return list;
@@ -380,3 +438,31 @@
_e_exehist_unload();
_e_exehist_unload_defer = NULL;
}
+
+static int
+_e_exehist_sort_exe_cb(const void *d1, const void *d2)
+{
+ const E_Exehist_Item *ei1, *ei2;
+
+ ei1 = d1;
+ ei2 = d2;
+
+ if (!ei1) return 1;
+ if (!ei2) return -1;
+
+ return strcmp(ei1->exe, ei2->exe);
+}
+
+static int
+_e_exehist_sort_pop_cb(const void *d1, const void *d2)
+{
+ const E_Exehist_Item *ei1, *ei2;
+
+ ei1 = d1;
+ ei2 = d2;
+
+ if (!ei1) return 1;
+ if (!ei2) return -1;
+
+ return ei2->count - ei1->count;
+}
Index: src/bin/e_exehist.h
===================================================================
--- src/bin/e_exehist.h (revision 39475)
+++ src/bin/e_exehist.h (working copy)
@@ -7,6 +7,13 @@
#ifndef E_EXEHIST_H
#define E_EXEHIST_H
+typedef enum _E_Exehist_Sort
+{
+ E_EXEHIST_SORT_BY_DATE,
+ E_EXEHIST_SORT_BY_EXE,
+ E_EXEHIST_SORT_BY_POPULARITY
+} E_Exehist_Sort;
+
EAPI int e_exehist_init(void);
EAPI int e_exehist_shutdown(void);
@@ -16,8 +23,11 @@
EAPI int e_exehist_popularity_get(const char *exe);
EAPI double e_exehist_newest_run_get(const char *exe);
EAPI Eina_List *e_exehist_list_get(void);
+EAPI Eina_List *e_exehist_sorted_list_get(E_Exehist_Sort sort_type, int max);
EAPI void e_exehist_mime_desktop_add(const char *mime, Efreet_Desktop *desktop);
EAPI Efreet_Desktop *e_exehist_mime_desktop_get(const char *mime);
+extern EAPI int E_EVENT_EXEHIST_UPDATE;
+
#endif
#endif
------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
enlightenment-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel