e order - bring back handling desktop files in dirs as well as .order

This commit is contained in:
Carsten Haitzler 2020-05-03 19:41:26 +01:00
parent 7b93ab2a38
commit ead3991e3f
2 changed files with 110 additions and 53 deletions

View File

@ -65,6 +65,14 @@ e_order_new(const char *path)
eo = E_OBJECT_ALLOC(E_Order, E_ORDER_TYPE, _e_order_free);
if (!eo) return NULL;
if (!path)
{
ERR("null order");
}
if (path[0] != '/')
{
ERR("not full");
}
if (path) eo->path = eina_stringshare_add(path);
_e_order_read(eo);
eo->monitor = ecore_file_monitor_add(path, _e_order_cb_monitor, eo);
@ -257,48 +265,81 @@ _e_order_cb_monitor(void *data, Ecore_File_Monitor *em EINA_UNUSED, Ecore_File_E
static void
_e_order_read(E_Order *eo)
{
char *dir, *s, *s2, buf[4096], buf2[8192];
Efreet_Desktop *desktop;
Eina_List *files, *l;
size_t len;
FILE *f;
char *dir;
E_FREE_LIST(eo->desktops, efreet_desktop_free);
if (!eo->path) return;
// eo->path = /path/to/dir/.order ...
dir = ecore_file_dir_get(eo->path);
if (!dir) return;
files = ecore_file_ls(dir);
f = fopen(eo->path, "rb");
if (f)
{
char buf[4096];
if (!f) goto err;
while (fgets(buf, sizeof(buf), f))
{
int len;
len = strlen(buf);
if (len > 0)
{
if (len == 0) continue;
if (buf[len - 1] == '\n')
{
buf[len - 1] = 0;
len--;
}
if (len > 0)
{
Efreet_Desktop *desktop = NULL;
if (len == 0) continue;
// if full path - use that first
desktop = NULL;
if (buf[0] == '/')
desktop = efreet_desktop_get(buf);
else
{
// /path/to/dir/filename.desktop (buf)
snprintf(buf2, sizeof(buf2), "%s/%s", dir, buf);
// remove file if its in the dir already
EINA_LIST_FOREACH(files, l, s)
{
if ((!strcmp(s, buf)) || (!strcmp(s, buf2)))
{
files = eina_list_remove_list(files, l);
free(s);
break;
}
}
// desktop file in the order dir first
if (!desktop)
desktop = efreet_desktop_get(buf2);
// ignore any path elements and look up just filename
if (!desktop)
desktop = efreet_desktop_get(ecore_file_file_get(buf));
// look uop by id
if (!desktop)
desktop = efreet_util_desktop_file_id_find(ecore_file_file_get(buf));
}
// if we found it - append.
if (desktop)
eo->desktops = eina_list_append(eo->desktops, desktop);
}
}
}
fclose(f);
err:
EINA_LIST_FOREACH(files, l, s)
{
if (s[0] == '.') continue;
s2 = strchr(s, '.');
if (!s2) continue;
if (!(!strcasecmp(s2, ".desktop"))) continue;
snprintf(buf2, sizeof(buf2), "%s/%s", dir, s);
desktop = efreet_desktop_get(buf2);
if (desktop)
eo->desktops = eina_list_append(eo->desktops, desktop);
}
if (dir) free(dir);
free(dir);
EINA_LIST_FREE(files, s) free(s);
}
static void

View File

@ -18,6 +18,7 @@ static Ecore_Event_Handler *desktop_cache_update_handler = NULL;
static Ecore_Timer *timer = NULL;
static Eina_Bool desktop_cache_update = EINA_FALSE;
static Eina_Bool started = EINA_FALSE;
static E_Startup_Mode startup_mode = 0;
/* externally accessible functions */
@ -25,24 +26,10 @@ static Eina_Bool started = EINA_FALSE;
E_API void
e_startup_mode_set(E_Startup_Mode mode)
{
char buf[PATH_MAX];
if (mode == E_STARTUP_START)
{
e_user_dir_concat_static(buf, "applications/startup/.order");
if (!ecore_file_exists(buf))
e_prefix_data_concat_static(buf, "data/applications/startup/.order");
}
else if (mode == E_STARTUP_RESTART)
{
e_user_dir_concat_static(buf, "applications/restart/.order");
if (!ecore_file_exists(buf))
e_prefix_data_concat_static(buf, "data/applications/restart/.order");
}
startup_mode = mode;
desktop_cache_update_handler =
ecore_event_handler_add(EFREET_EVENT_DESKTOP_CACHE_BUILD,
_e_startup_event_cb,
strdup(buf));
_e_startup_event_cb, NULL);
if (timer) ecore_timer_del(timer);
timer = ecore_timer_add(10.0, _e_startup_time_exceeded, NULL);
e_init_undone();
@ -155,10 +142,23 @@ _e_startup_error_dialog(const char *msg)
e_dialog_show(dia);
}
static Eina_Bool
_e_startup_event_cb(void *data, int ev_type EINA_UNUSED, void *ev)
static E_Order *
_e_startup_load(const char *file)
{
char *buf;
E_Order *o = e_order_new(file);
if (!o) return NULL;
if (!o->desktops)
{
e_object_del(E_OBJECT(o));
o = NULL;
}
return o;
}
static Eina_Bool
_e_startup_event_cb(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *ev)
{
char buf[PATH_MAX];
Efreet_Event_Cache_Update *e;
if (timer) ecore_timer_del(timer);
@ -179,13 +179,29 @@ _e_startup_event_cb(void *data, int ev_type EINA_UNUSED, void *ev)
}
desktop_cache_update = EINA_TRUE;
E_FREE_FUNC(desktop_cache_update_handler, ecore_event_handler_del);
buf = data;
if (startup_mode == E_STARTUP_START)
{
e_user_dir_concat_static(buf, "applications/startup/.order");
startup_apps = _e_startup_load(buf);
if (!startup_apps)
{
e_prefix_data_concat_static(buf, "data/applications/startup/.order");
startup_apps = e_order_new(buf);
if (startup_apps)
start_app_pos = 0;
free(buf);
if (started)
_e_startup();
}
}
else if (startup_mode == E_STARTUP_RESTART)
{
e_user_dir_concat_static(buf, "applications/restart/.order");
startup_apps = _e_startup_load(buf);
if (!startup_apps)
{
e_prefix_data_concat_static(buf, "data/applications/restart/.order");
startup_apps = e_order_new(buf);
}
}
if (startup_apps) start_app_pos = 0;
if (started) _e_startup();
return ECORE_CALLBACK_PASS_ON;
}