Ejemplo n.º 1
0
EAPI Efreet_Desktop *
efreet_desktop_get(const char *file)
{
    Efreet_Desktop *desktop;

    desktop = efreet_desktop_new(file);
    if (!desktop) return NULL;

    /* If we didn't find this file in the eet cache, add path to search path */
    if (!desktop->eet)
    {
        /* Check whether the desktop type is a system type,
         * and therefor known by the cache builder */
        Efreet_Desktop_Type_Info *info;

        info = eina_list_nth(efreet_desktop_types, desktop->type);
        if (info && (
                info->id == EFREET_DESKTOP_TYPE_APPLICATION ||
                info->id == EFREET_DESKTOP_TYPE_LINK ||
                info->id == EFREET_DESKTOP_TYPE_DIRECTORY
                ))
            efreet_cache_desktop_add(desktop);
    }

    return desktop;
}
Ejemplo n.º 2
0
/**
 * @param file: The file to get the Efreet_Desktop from
 * @return Returns a reference to a cached Efreet_Desktop on success, NULL
 * on failure. This reference should not be freed.
 * @brief Gets a reference to an Efreet_Desktop structure representing the
 * contents of @a file or NULL if @a file is not a valid .desktop file.
 *
 * By using efreet_desktop_get the Efreet_Desktop will be saved in an internal
 * cache, and changes will be signalled by events.
 *
 * Efreet will also try to save all files fetched by efreet_desktop_get in a
 * cache to speed up further requests.
 */
EAPI Efreet_Desktop *
efreet_desktop_get(const char *file)
{
    /* TODO: Check if we need to differentiate between desktop_new and desktop_get */
    Efreet_Desktop *desktop;

    if (!file) return NULL;
    if (efreet_desktop_cache)
    {
        char rp[PATH_MAX];

        if (!realpath(file, rp)) return NULL;
        desktop = eina_hash_find(efreet_desktop_cache, rp);
        if (desktop)
        {
            if (efreet_desktop_cache_check(desktop))
            {
                desktop->ref++;
                return desktop;
            }

            desktop->cached = 0;
            eina_hash_del_by_key(efreet_desktop_cache, rp);
        }
    }

    desktop = efreet_desktop_new(file);
    if (!desktop) return NULL;

    if (!desktop->eet)
    {
        char buf[PATH_MAX];
        char *p;

        /*
         * Read file from disk, save path in cache so it will be included in next
         * cache update
         */
        strncpy(buf, desktop->orig_path, PATH_MAX);
        buf[PATH_MAX - 1] = '\0';
        p = dirname(buf);
        if (!eina_list_search_unsorted(efreet_desktop_dirs, EINA_COMPARE_CB(strcmp), p))
            efreet_desktop_dirs = eina_list_append(efreet_desktop_dirs, eina_stringshare_add(p));
        efreet_desktop_update_cache();
    }

    if (efreet_desktop_cache) eina_hash_add(efreet_desktop_cache, desktop->orig_path, desktop);
    desktop->cached = 1;
    return desktop;
}
Ejemplo n.º 3
0
/* Profile chooser */
#include "e_wizard.h"

static const char *profile = NULL;
static Evas_Object *textblock = NULL;

static void
_profile_change(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED)
{
   char buf[PATH_MAX], buf2[PATH_MAX];
   Efreet_Desktop *desk = NULL;

   e_prefix_data_snprintf(buf2, sizeof(buf2), "data/config/%s", profile);
   snprintf(buf, sizeof(buf), "%s/profile.desktop", buf2);
   desk = efreet_desktop_new(buf);
   if (desk)
     {
        e_widget_textblock_markup_set(textblock, desk->comment);
        efreet_desktop_free(desk);
     }
   else
     e_widget_textblock_markup_set(textblock, _("Unknown"));

   // enable next once you choose a profile
   e_wizard_button_next_enable_set(1);
}
/*
E_API int
wizard_page_init(E_Wizard_Page *pg EINA_UNUSED, Eina_Bool *need_xdg_desktops EINA_UNUSED, Eina_Bool *need_xdg_icons EINA_UNUSED)
{
   return 1;
Ejemplo n.º 4
0
static int
cache_add(const char *path, const char *file_id, int priority EINA_UNUSED, int *changed)
{
    Efreet_Desktop *desk;
    char *ext;

    INF("FOUND: %s", path);
    if (file_id) INF(" (id): %s", file_id);
    ext = strrchr(path, '.');
    if (!ext || (strcmp(ext, ".desktop") && strcmp(ext, ".directory"))) return 1;
    desk = efreet_desktop_new(path);
    if (desk) INF("  OK");
    else      INF("  FAIL");
    if (!desk) return 1;
    if (!desk->eet)
    {
        /* This file isn't in cache */
        *changed = 1;
        INF("  NEW");
    }
    else if (ecore_file_mod_time(desk->orig_path) != desk->load_time)
    {
        efreet_desktop_free(desk);
        *changed = 1;
        desk = efreet_desktop_uncached_new(path);
        if (desk) INF("  CHANGED");
        else      INF("  NO UNCACHED");
    }
    if (!desk) return 1;
    if (file_id && old_file_ids && !eina_hash_find(old_file_ids->hash, file_id))
    {
        *changed = 1;
        INF("  NOT IN UTILS");
    }
    if (!eina_hash_find(paths, desk->orig_path))
    {
        if (!eet_data_write(ef, edd, desk->orig_path, desk, 0))
            return 0;
        eina_hash_add(paths, desk->orig_path, (void *)1);
    }
    /* TODO: We should check priority, and not just hope we search in right order */
    /* TODO: We need to find out if prioritized file id has changed because of
     * changed search order. */
    if (!desk->hidden && desk->type == EFREET_DESKTOP_TYPE_APPLICATION &&
        file_id && !eina_hash_find(file_ids, file_id))
    {
        Eina_List *l;
        char *data;
        Efreet_Cache_Array_String *array;

#define ADD_LIST(list, hash) \
        EINA_LIST_FOREACH((list), l, data) \
        { \
            array = eina_hash_find((hash), data); \
            if (!array) \
                array = NEW(Efreet_Cache_Array_String, 1); \
            array->array = realloc(array->array, sizeof (char *) * (array->array_count + 1)); \
            array->array[array->array_count++] = desk->orig_path; \
            eina_hash_set((hash), data, array); \
        }
#define ADD_ELEM(elem, hash) \
        if ((elem)) \
        { \
            data = (elem); \
            array = eina_hash_find((hash), data); \
            if (!array) \
                array = NEW(Efreet_Cache_Array_String, 1); \
            array->array = realloc(array->array, sizeof (char *) * (array->array_count + 1)); \
            array->array[array->array_count++] = desk->orig_path; \
            eina_hash_set((hash), data, array); \
        }
        ADD_LIST(desk->mime_types, mime_types);
        ADD_LIST(desk->categories, categories);
        ADD_ELEM(desk->startup_wm_class, startup_wm_class);
        ADD_ELEM(desk->name, name);
        ADD_ELEM(desk->generic_name, generic_name);
        ADD_ELEM(desk->comment, comment);
        ADD_ELEM(desk->exec, exec);
        eina_hash_add(file_ids, file_id, desk->orig_path);
        eina_hash_add(desktops, desk->orig_path, desk);
    }
    else
        efreet_desktop_free(desk);
    return 1;
}