2010-05-18 00:59:33 -07:00
|
|
|
#include "e.h"
|
2010-10-31 04:30:31 -07:00
|
|
|
#include "e_fm_device.h"
|
2010-05-18 00:59:33 -07:00
|
|
|
#include "e_mod_main.h"
|
|
|
|
#include "evry_api.h"
|
|
|
|
|
2010-05-22 12:42:06 -07:00
|
|
|
#define ACT_MOUNT 0
|
|
|
|
#define ACT_UNMOUNT 1
|
2010-05-18 00:59:33 -07:00
|
|
|
/* #undef DBG
|
|
|
|
* #define DBG(...) ERR(__VA_ARGS__) */
|
|
|
|
|
|
|
|
typedef struct _Plugin Plugin;
|
|
|
|
|
|
|
|
struct _Plugin
|
|
|
|
{
|
|
|
|
Evry_Plugin base;
|
|
|
|
const char *input;
|
|
|
|
|
|
|
|
Eina_List *files;
|
|
|
|
};
|
|
|
|
|
|
|
|
static Evry_Module *evry_module = NULL;
|
2010-05-30 06:31:08 -07:00
|
|
|
static Eina_List *_plugins = NULL;
|
2010-05-18 00:59:33 -07:00
|
|
|
static const char _module_icon[] = "find";
|
2010-05-18 05:33:17 -07:00
|
|
|
static const char *_mime_dir;
|
2010-05-19 21:37:23 -07:00
|
|
|
static const char *_mime_mount;
|
|
|
|
static Evry_Action *act_mount;
|
|
|
|
static Evry_Action *act_umount;
|
2010-05-18 00:59:33 -07:00
|
|
|
|
2010-05-18 05:19:44 -07:00
|
|
|
/***************************************************************************/
|
|
|
|
|
2010-05-18 00:59:33 -07:00
|
|
|
static void
|
|
|
|
_item_free(Evry_Item *it)
|
|
|
|
{
|
|
|
|
GET_FILE(file, it);
|
|
|
|
|
|
|
|
IF_RELEASE(file->url);
|
|
|
|
IF_RELEASE(file->path);
|
|
|
|
IF_RELEASE(file->mime);
|
|
|
|
|
|
|
|
E_FREE(file);
|
|
|
|
}
|
|
|
|
|
2010-05-19 21:37:23 -07:00
|
|
|
static Evry_Item *
|
|
|
|
_item_add(Plugin *p, const char *label, const char *path, const char *mime, const char *icon)
|
|
|
|
{
|
|
|
|
Evry_Item_File *file;
|
|
|
|
|
|
|
|
file = EVRY_ITEM_NEW(Evry_Item_File, p, label, NULL, _item_free);
|
|
|
|
|
|
|
|
if (!path) path = "";
|
|
|
|
file->path = eina_stringshare_add(path);
|
|
|
|
file->mime = eina_stringshare_ref(mime);
|
|
|
|
if (icon) EVRY_ITEM_ICON_SET(file, icon);
|
|
|
|
EVRY_ITEM(file)->id = eina_stringshare_ref(file->path);
|
|
|
|
EVRY_ITEM(file)->context = eina_stringshare_ref(file->mime);
|
|
|
|
EVRY_ITEM(file)->browseable = EINA_TRUE;
|
|
|
|
p->files = eina_list_append(p->files, file);
|
|
|
|
|
|
|
|
return EVRY_ITEM(file);
|
|
|
|
}
|
|
|
|
|
2010-05-18 05:19:44 -07:00
|
|
|
/* taken from fileman module */
|
|
|
|
static void
|
2010-05-19 21:37:23 -07:00
|
|
|
_gtk_bookmarks_add(Plugin *p)
|
2010-05-18 05:19:44 -07:00
|
|
|
{
|
|
|
|
char line[PATH_MAX];
|
|
|
|
char buf[PATH_MAX];
|
|
|
|
Efreet_Uri *uri;
|
|
|
|
char *alias;
|
|
|
|
FILE* fp;
|
|
|
|
|
|
|
|
snprintf(buf, sizeof(buf), "%s/.gtk-bookmarks", e_user_homedir_get());
|
|
|
|
fp = fopen(buf, "r");
|
|
|
|
if (!fp) return;
|
|
|
|
|
|
|
|
while(fgets(line, sizeof(line), fp))
|
|
|
|
{
|
2011-04-07 11:33:37 -07:00
|
|
|
if (strncmp(line, "file://", 7))
|
|
|
|
continue;
|
|
|
|
|
2010-05-18 05:19:44 -07:00
|
|
|
alias = NULL;
|
|
|
|
line[strlen(line) - 1] = '\0';
|
|
|
|
alias = strchr(line, ' ');
|
|
|
|
if (alias)
|
|
|
|
{
|
|
|
|
line[alias-line] = '\0';
|
|
|
|
alias++;
|
|
|
|
}
|
|
|
|
uri = efreet_uri_decode(line);
|
|
|
|
if (!(uri) || !(uri->path))
|
|
|
|
{
|
|
|
|
if (uri) efreet_uri_free(uri);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ecore_file_exists(uri->path))
|
|
|
|
{
|
|
|
|
efreet_uri_free(uri);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-05-19 21:37:23 -07:00
|
|
|
_item_add(p, ecore_file_file_get(uri->path), uri->path, _mime_dir, NULL);
|
2010-05-18 05:19:44 -07:00
|
|
|
|
|
|
|
efreet_uri_free(uri);
|
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-05-19 21:37:23 -07:00
|
|
|
static void
|
|
|
|
_volume_list_add(Plugin *p)
|
|
|
|
{
|
|
|
|
const Eina_List *l;
|
|
|
|
Evry_Item *it;
|
|
|
|
E_Volume *vol;
|
2010-10-12 19:53:28 -07:00
|
|
|
EINA_LIST_FOREACH(e_fm2_device_volume_list_get(), l, vol)
|
2010-05-19 21:37:23 -07:00
|
|
|
{
|
2010-05-22 12:42:06 -07:00
|
|
|
if (vol->mount_point && !strcmp(vol->mount_point, "/"))
|
|
|
|
continue;
|
2010-05-19 21:37:23 -07:00
|
|
|
|
|
|
|
it = _item_add(p, vol->label, vol->mount_point, _mime_mount, vol->icon);
|
2010-05-22 12:42:06 -07:00
|
|
|
if (!it) continue;
|
2010-05-19 21:37:23 -07:00
|
|
|
|
2010-05-22 12:42:06 -07:00
|
|
|
it->browseable = vol->mounted;
|
|
|
|
it->data = vol;
|
2010-05-19 21:37:23 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-18 00:59:33 -07:00
|
|
|
static Evry_Plugin *
|
|
|
|
_begin(Evry_Plugin *plugin, const Evry_Item *item)
|
|
|
|
{
|
2010-05-20 08:48:01 -07:00
|
|
|
Plugin *p;
|
2010-05-18 00:59:33 -07:00
|
|
|
char path[PATH_MAX];
|
|
|
|
|
2010-05-20 08:48:01 -07:00
|
|
|
EVRY_PLUGIN_INSTANCE(p, plugin);
|
2010-05-18 00:59:33 -07:00
|
|
|
|
2010-05-22 12:42:06 -07:00
|
|
|
_item_add(p, N_("Home"), e_user_homedir_get(), _mime_dir, NULL);
|
|
|
|
|
2010-05-18 00:59:33 -07:00
|
|
|
e_user_dir_concat_static(path, "backgrounds");
|
2010-05-19 21:37:23 -07:00
|
|
|
_item_add(p, N_("Wallpaper"), path, _mime_dir, NULL);
|
|
|
|
|
|
|
|
_gtk_bookmarks_add(p);
|
2010-05-18 00:59:33 -07:00
|
|
|
|
2010-05-19 21:37:23 -07:00
|
|
|
_volume_list_add(p);
|
2010-05-18 05:19:44 -07:00
|
|
|
|
2010-05-18 00:59:33 -07:00
|
|
|
return EVRY_PLUGIN(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_finish(Evry_Plugin *plugin)
|
|
|
|
{
|
|
|
|
Evry_Item_File *file;
|
|
|
|
|
|
|
|
GET_PLUGIN(p, plugin);
|
|
|
|
|
|
|
|
EVRY_PLUGIN_ITEMS_CLEAR(p);
|
|
|
|
|
|
|
|
EINA_LIST_FREE(p->files, file)
|
|
|
|
EVRY_ITEM_FREE(file);
|
|
|
|
|
|
|
|
IF_RELEASE(p->input);
|
2010-05-20 08:48:01 -07:00
|
|
|
|
|
|
|
E_FREE(p);
|
2010-05-18 00:59:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
_fetch(Evry_Plugin *plugin, const char *input)
|
|
|
|
{
|
2010-05-18 05:19:44 -07:00
|
|
|
int len = (input ? strlen(input) : 0);
|
|
|
|
|
2010-05-18 00:59:33 -07:00
|
|
|
GET_PLUGIN(p, plugin);
|
|
|
|
|
2010-05-18 05:19:44 -07:00
|
|
|
EVRY_PLUGIN_ITEMS_CLEAR(p);
|
|
|
|
|
|
|
|
if (len >= plugin->config->min_query)
|
|
|
|
EVRY_PLUGIN_ITEMS_ADD(p, p->files, input, 0, 0);
|
2010-05-18 00:59:33 -07:00
|
|
|
|
|
|
|
return !!(p->base.items);
|
|
|
|
}
|
|
|
|
|
2010-05-22 12:42:06 -07:00
|
|
|
static int
|
|
|
|
_check_mount(Evry_Action *act __UNUSED__, const Evry_Item *it)
|
|
|
|
{
|
|
|
|
GET_FILE(file, it);
|
|
|
|
if (file->mime == _mime_mount)
|
|
|
|
{
|
|
|
|
E_Volume *vol = it->data;
|
|
|
|
if (!vol) return 0;
|
|
|
|
|
|
|
|
if (!vol->mounted && (EVRY_ITEM_DATA_INT_GET(act) == ACT_MOUNT))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (vol->mounted && (EVRY_ITEM_DATA_INT_GET(act) == ACT_UNMOUNT))
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cb_mount_ok(void *data)
|
|
|
|
{
|
|
|
|
E_Volume *vol;
|
|
|
|
|
|
|
|
GET_ITEM(it, data);
|
|
|
|
|
|
|
|
vol = it->data;
|
|
|
|
it->browseable = vol->mounted;
|
|
|
|
evry->item_changed(it, 1, 0);
|
|
|
|
|
|
|
|
EVRY_ITEM_FREE(it);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cb_mount_fail(void *data)
|
|
|
|
{
|
|
|
|
GET_ITEM(it, data);
|
|
|
|
EVRY_ITEM_FREE(it);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
_act_mount(Evry_Action *act)
|
|
|
|
{
|
|
|
|
GET_ITEM(it, act->it1.item);
|
|
|
|
|
|
|
|
E_Volume *vol = it->data;
|
|
|
|
E_Fm2_Mount *mount;
|
|
|
|
|
|
|
|
if (!vol)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!vol->mounted && EVRY_ITEM_DATA_INT_GET(act) == ACT_MOUNT)
|
|
|
|
{
|
|
|
|
EVRY_ITEM_REF(it);
|
2010-10-12 19:53:28 -07:00
|
|
|
mount = e_fm2_device_mount(vol, _cb_mount_ok, _cb_mount_fail,
|
2010-05-22 12:42:06 -07:00
|
|
|
_cb_mount_ok, _cb_mount_fail, it);
|
|
|
|
/* XXX needs mount to be freed ? */
|
|
|
|
}
|
|
|
|
else if (vol->mounted && EVRY_ITEM_DATA_INT_GET(act) == ACT_UNMOUNT)
|
|
|
|
{
|
|
|
|
/* if (!(mount = eina_list_data_get(vol->mounts))) */
|
2010-10-12 19:53:28 -07:00
|
|
|
if (!(mount = e_fm2_device_mount_find(vol->mount_point)))
|
2010-05-22 12:42:06 -07:00
|
|
|
{
|
|
|
|
ERR("unmount: no mount point: %s", vol->mount_point);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
EVRY_ITEM_REF(it);
|
2010-10-12 19:53:28 -07:00
|
|
|
e_fm2_device_unmount(mount);
|
2010-05-22 12:42:06 -07:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2010-05-19 21:37:23 -07:00
|
|
|
|
2010-05-18 00:59:33 -07:00
|
|
|
static int
|
2011-08-12 04:01:12 -07:00
|
|
|
_plugins_init(void)
|
2010-05-18 00:59:33 -07:00
|
|
|
{
|
|
|
|
Evry_Plugin *p;
|
|
|
|
|
|
|
|
if (evry_module->active)
|
|
|
|
return EINA_TRUE;
|
|
|
|
|
|
|
|
if (!evry->api_version_check(EVRY_API_VERSION))
|
|
|
|
return EINA_FALSE;
|
|
|
|
|
2010-05-18 05:33:17 -07:00
|
|
|
_mime_dir = eina_stringshare_add("inode/directory");
|
2010-05-19 21:37:23 -07:00
|
|
|
_mime_mount = eina_stringshare_add("inode/mount-point");
|
2010-05-18 05:33:17 -07:00
|
|
|
|
2010-05-30 06:31:08 -07:00
|
|
|
p = EVRY_PLUGIN_NEW(Plugin, N_("Places"), "drive-harddisk",
|
|
|
|
EVRY_TYPE_FILE,
|
|
|
|
_begin, _finish, _fetch, NULL);
|
|
|
|
_plugins = eina_list_append(_plugins, p);
|
2010-05-18 00:59:33 -07:00
|
|
|
|
2010-05-30 06:31:08 -07:00
|
|
|
if (evry->plugin_register(p, EVRY_PLUGIN_SUBJECT, 3))
|
2010-05-18 00:59:33 -07:00
|
|
|
{
|
|
|
|
/* p->config->top_level = EINA_FALSE;
|
|
|
|
* p->config->min_query = 3; */
|
|
|
|
}
|
|
|
|
|
2010-05-30 06:31:08 -07:00
|
|
|
p = EVRY_PLUGIN_NEW(Plugin, N_("Places"), "drive-harddisk",
|
|
|
|
EVRY_TYPE_FILE,
|
|
|
|
_begin, _finish, _fetch, NULL);
|
|
|
|
_plugins = eina_list_append(_plugins, p);
|
2010-05-20 08:48:01 -07:00
|
|
|
|
2010-05-30 06:31:08 -07:00
|
|
|
if (evry->plugin_register(p, EVRY_PLUGIN_OBJECT, 1))
|
2010-05-20 08:48:01 -07:00
|
|
|
{
|
|
|
|
/* p->config->top_level = EINA_FALSE;
|
|
|
|
* p->config->min_query = 3; */
|
|
|
|
}
|
|
|
|
|
2010-05-22 12:42:06 -07:00
|
|
|
act_mount = EVRY_ACTION_NEW(N_("Mount Drive"), EVRY_TYPE_FILE, 0,
|
|
|
|
"drive-harddisk", _act_mount, _check_mount);
|
|
|
|
EVRY_ITEM_DATA_INT_SET(act_mount, ACT_MOUNT);
|
|
|
|
evry->action_register(act_mount, 1);
|
|
|
|
|
|
|
|
act_umount = EVRY_ACTION_NEW(N_("Unmount Drive"), EVRY_TYPE_FILE, 0,
|
|
|
|
"hdd_unmount", _act_mount, _check_mount);
|
2010-05-27 05:23:39 -07:00
|
|
|
act_mount->remember_context = EINA_TRUE;
|
2010-05-22 12:42:06 -07:00
|
|
|
EVRY_ITEM_DATA_INT_SET(act_umount, ACT_UNMOUNT);
|
|
|
|
evry->action_register(act_umount, 2);
|
2010-05-19 21:37:23 -07:00
|
|
|
|
2010-05-18 00:59:33 -07:00
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_plugins_shutdown(void)
|
|
|
|
{
|
|
|
|
Plugin *p;
|
|
|
|
|
|
|
|
if (!evry_module->active) return;
|
|
|
|
|
2010-05-18 05:33:17 -07:00
|
|
|
eina_stringshare_del(_mime_dir);
|
2010-05-19 21:37:23 -07:00
|
|
|
eina_stringshare_del(_mime_mount);
|
2010-05-18 05:33:17 -07:00
|
|
|
|
2010-05-30 06:31:08 -07:00
|
|
|
EINA_LIST_FREE(_plugins, p)
|
|
|
|
EVRY_PLUGIN_FREE(p);
|
|
|
|
|
2010-05-22 12:42:06 -07:00
|
|
|
EVRY_ACTION_FREE(act_mount);
|
|
|
|
EVRY_ACTION_FREE(act_umount);
|
2010-05-18 00:59:33 -07:00
|
|
|
|
|
|
|
evry_module->active = EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
|
|
|
|
EAPI E_Module_Api e_modapi =
|
|
|
|
{
|
|
|
|
E_MODULE_API_VERSION,
|
|
|
|
PACKAGE
|
|
|
|
};
|
|
|
|
|
|
|
|
EAPI void *
|
|
|
|
e_modapi_init(E_Module *m)
|
|
|
|
{
|
|
|
|
char buf[4096];
|
|
|
|
|
|
|
|
/* Location of message catalogs for localization */
|
|
|
|
snprintf(buf, sizeof(buf), "%s/locale", e_module_dir_get(m));
|
|
|
|
bindtextdomain(PACKAGE, buf);
|
|
|
|
bind_textdomain_codeset(PACKAGE, "UTF-8");
|
|
|
|
|
2011-08-12 04:01:12 -07:00
|
|
|
EVRY_MODULE_NEW(evry_module, _plugins_init, _plugins_shutdown);
|
2010-05-18 00:59:33 -07:00
|
|
|
|
|
|
|
e_module_delayed_set(m, 1);
|
|
|
|
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI int
|
|
|
|
e_modapi_shutdown(E_Module *m)
|
|
|
|
{
|
2011-04-01 05:47:07 -07:00
|
|
|
EVRY_MODULE_FREE(evry_module);
|
2010-05-18 00:59:33 -07:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI int
|
|
|
|
e_modapi_save(E_Module *m)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************/
|