2012-10-20 21:53:23 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2012-11-02 13:12:41 -07:00
|
|
|
#include <Ecore.h>
|
2012-10-20 21:53:23 -07:00
|
|
|
#include <EDBus.h>
|
|
|
|
|
|
|
|
#include "efreetd.h"
|
|
|
|
#include "efreetd_cache.h"
|
|
|
|
|
2012-11-01 18:46:44 -07:00
|
|
|
#define BUS "org.enlightenment.Efreet"
|
|
|
|
#define PATH "/org/enlightenment/Efreet"
|
2012-10-20 21:53:23 -07:00
|
|
|
#define INTERFACE "org.enlightenment.Efreet"
|
|
|
|
|
|
|
|
/* internal */
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
EFREET_SIGNAL_ICON_CACHE_UPDATE = 0,
|
|
|
|
EFREET_SIGNAL_DESKTOP_CACHE_UPDATE
|
|
|
|
};
|
|
|
|
|
|
|
|
static EDBus_Connection *conn;
|
|
|
|
static EDBus_Service_Interface *iface;
|
|
|
|
|
2012-11-02 13:12:41 -07:00
|
|
|
static Ecore_Timer *shutdown = NULL;
|
|
|
|
static int clients = 0;
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
do_shutdown(void *data __UNUSED__)
|
|
|
|
{
|
|
|
|
quit();
|
|
|
|
return ECORE_CALLBACK_CANCEL;
|
|
|
|
}
|
|
|
|
|
2012-11-11 12:59:03 -08:00
|
|
|
static void
|
2012-12-14 06:27:05 -08:00
|
|
|
disconnected(void *context __UNUSED__, EDBus_Connection *connection __UNUSED__, void *event_info __UNUSED__)
|
2012-11-11 12:59:03 -08:00
|
|
|
{
|
|
|
|
INF("disconnected");
|
|
|
|
quit();
|
|
|
|
}
|
|
|
|
|
2012-10-20 21:53:23 -07:00
|
|
|
static EDBus_Message *
|
2012-11-02 13:12:41 -07:00
|
|
|
do_register(const EDBus_Service_Interface *ifc __UNUSED__, const EDBus_Message *message)
|
2012-10-20 21:53:23 -07:00
|
|
|
{
|
2012-11-01 18:47:06 -07:00
|
|
|
EDBus_Message *reply;
|
2012-11-26 08:07:55 -08:00
|
|
|
const char *lang;
|
|
|
|
|
|
|
|
if (!edbus_message_arguments_get(message, "s", &lang))
|
|
|
|
{
|
|
|
|
ERR("Error getting arguments.");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
setenv("LANG", lang, 1);
|
2012-11-01 18:47:06 -07:00
|
|
|
|
2012-11-02 13:12:41 -07:00
|
|
|
clients++;
|
|
|
|
if (shutdown) ecore_timer_del(shutdown);
|
|
|
|
shutdown = NULL;
|
2012-11-01 18:47:06 -07:00
|
|
|
reply = edbus_message_method_return_new(message);
|
|
|
|
edbus_message_arguments_set(reply, "b", cache_desktop_exists());
|
|
|
|
return reply;
|
2012-10-20 21:53:23 -07:00
|
|
|
}
|
2012-11-01 18:46:44 -07:00
|
|
|
|
2012-11-02 13:12:41 -07:00
|
|
|
static EDBus_Message *
|
|
|
|
do_unregister(const EDBus_Service_Interface *ifc __UNUSED__, const EDBus_Message *message __UNUSED__)
|
|
|
|
{
|
|
|
|
clients--;
|
|
|
|
if (clients <= 0)
|
|
|
|
{
|
|
|
|
clients = 0;
|
|
|
|
if (shutdown) ecore_timer_del(shutdown);
|
|
|
|
shutdown = ecore_timer_add(10.0, do_shutdown, NULL);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-10-20 21:53:23 -07:00
|
|
|
static EDBus_Message *
|
|
|
|
add_desktop_dirs(const EDBus_Service_Interface *ifc __UNUSED__, const EDBus_Message *message)
|
|
|
|
{
|
|
|
|
EDBus_Message_Iter *array = NULL;
|
|
|
|
const char *dir;
|
|
|
|
|
|
|
|
if (!edbus_message_arguments_get(message, "as", &array))
|
|
|
|
{
|
|
|
|
ERR("Error getting arguments.");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (edbus_message_iter_get_and_next(array, 's', &dir))
|
|
|
|
{
|
|
|
|
cache_desktop_dir_add(dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static EDBus_Message *
|
|
|
|
add_icon_dirs(const EDBus_Service_Interface *ifc __UNUSED__, const EDBus_Message *message)
|
|
|
|
{
|
|
|
|
EDBus_Message_Iter *array = NULL;
|
|
|
|
const char *dir;
|
|
|
|
|
|
|
|
if (!edbus_message_arguments_get(message, "as", &array))
|
|
|
|
{
|
|
|
|
ERR("Error getting arguments.");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (edbus_message_iter_get_and_next(array, 's', &dir))
|
|
|
|
{
|
|
|
|
cache_icon_dir_add(dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-11-01 18:46:44 -07:00
|
|
|
static EDBus_Message *
|
|
|
|
build_desktop_cache(const EDBus_Service_Interface *ifc __UNUSED__, const EDBus_Message *message __UNUSED__)
|
|
|
|
{
|
2012-11-26 08:07:55 -08:00
|
|
|
const char *lang;
|
|
|
|
|
|
|
|
if (!edbus_message_arguments_get(message, "s", &lang))
|
|
|
|
{
|
|
|
|
ERR("Error getting arguments.");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
setenv("LANG", lang, 1);
|
|
|
|
|
2012-11-01 18:46:44 -07:00
|
|
|
cache_desktop_update();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-10-20 21:53:23 -07:00
|
|
|
static EDBus_Message *
|
|
|
|
add_icon_exts(const EDBus_Service_Interface *ifc __UNUSED__, const EDBus_Message *message)
|
|
|
|
{
|
|
|
|
EDBus_Message_Iter *array = NULL;
|
|
|
|
const char *ext;
|
|
|
|
|
|
|
|
if (!edbus_message_arguments_get(message, "as", &array))
|
|
|
|
{
|
|
|
|
ERR("Error getting arguments.");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (edbus_message_iter_get_and_next(array, 's', &ext))
|
|
|
|
{
|
|
|
|
cache_icon_ext_add(ext);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const EDBus_Signal signals[] = {
|
|
|
|
[EFREET_SIGNAL_ICON_CACHE_UPDATE] = {"IconCacheUpdate", EDBUS_ARGS({ "b", "update" }), 0},
|
|
|
|
[EFREET_SIGNAL_DESKTOP_CACHE_UPDATE] = {"DesktopCacheUpdate", EDBUS_ARGS({ "b", "update" }), 0},
|
|
|
|
{ NULL, NULL, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const EDBus_Method methods[] = {
|
|
|
|
{
|
2012-11-26 08:07:55 -08:00
|
|
|
"Register", EDBUS_ARGS({"s", "lang info"}), EDBUS_ARGS({"b", "cache exists"}),
|
2012-11-02 13:12:41 -07:00
|
|
|
do_register, 0
|
|
|
|
},
|
|
|
|
{
|
2012-11-03 14:44:11 -07:00
|
|
|
"Unregister", NULL, NULL,
|
2012-11-02 13:12:41 -07:00
|
|
|
do_unregister, 0
|
2012-10-20 21:53:23 -07:00
|
|
|
},
|
|
|
|
{
|
2012-11-01 18:46:44 -07:00
|
|
|
"AddDesktopDirs", EDBUS_ARGS({"as", "dirs"}), NULL,
|
2012-10-20 21:53:23 -07:00
|
|
|
add_desktop_dirs, EDBUS_METHOD_FLAG_NOREPLY
|
|
|
|
},
|
|
|
|
{
|
2012-11-26 08:07:55 -08:00
|
|
|
"BuildDesktopCache", EDBUS_ARGS({"s", "lang info"}), NULL,
|
2012-11-01 18:46:44 -07:00
|
|
|
build_desktop_cache, EDBUS_METHOD_FLAG_NOREPLY
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"AddIconDirs", EDBUS_ARGS({"as", "dirs"}), NULL,
|
2012-10-20 21:53:23 -07:00
|
|
|
add_icon_dirs, EDBUS_METHOD_FLAG_NOREPLY
|
|
|
|
},
|
|
|
|
{
|
2012-11-01 18:46:44 -07:00
|
|
|
"AddIconExts", EDBUS_ARGS({"as", "exts"}), NULL,
|
2012-10-20 21:53:23 -07:00
|
|
|
add_icon_exts, EDBUS_METHOD_FLAG_NOREPLY
|
|
|
|
},
|
|
|
|
{ NULL, NULL, NULL, NULL, 0 }
|
|
|
|
};
|
|
|
|
|
2012-11-01 18:46:44 -07:00
|
|
|
static const EDBus_Service_Interface_Desc desc = {
|
2012-11-02 13:12:41 -07:00
|
|
|
INTERFACE, methods, signals, NULL, NULL, NULL
|
2012-11-01 09:41:35 -07:00
|
|
|
};
|
|
|
|
|
2012-10-20 21:53:23 -07:00
|
|
|
static void
|
|
|
|
on_name_request(void *data __UNUSED__, const EDBus_Message *msg, EDBus_Pending *pending __UNUSED__)
|
|
|
|
{
|
2012-11-11 12:59:03 -08:00
|
|
|
unsigned int reply;
|
2012-10-20 21:53:23 -07:00
|
|
|
|
|
|
|
if (edbus_message_error_get(msg, NULL, NULL))
|
|
|
|
{
|
|
|
|
ERR("error on on_name_request");
|
2012-11-11 12:59:03 -08:00
|
|
|
quit();
|
2012-10-20 21:53:23 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-11-11 12:59:03 -08:00
|
|
|
if (!edbus_message_arguments_get(msg, "u", &reply))
|
2012-10-20 21:53:23 -07:00
|
|
|
{
|
|
|
|
ERR("error getting arguments on on_name_request");
|
2012-11-11 12:59:03 -08:00
|
|
|
quit();
|
2012-10-20 21:53:23 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-11-11 12:59:03 -08:00
|
|
|
if (reply != EDBUS_NAME_REQUEST_REPLY_PRIMARY_OWNER)
|
2012-10-20 21:53:23 -07:00
|
|
|
{
|
|
|
|
ERR("error name already in use");
|
2012-11-11 12:59:03 -08:00
|
|
|
quit();
|
2012-10-20 21:53:23 -07:00
|
|
|
return;
|
|
|
|
}
|
2012-11-11 12:59:03 -08:00
|
|
|
INF("name requested");
|
2012-10-20 21:53:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* external */
|
|
|
|
void
|
|
|
|
send_signal_icon_cache_update(Eina_Bool update)
|
|
|
|
{
|
|
|
|
edbus_service_signal_emit(iface, EFREET_SIGNAL_ICON_CACHE_UPDATE, update);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
send_signal_desktop_cache_update(Eina_Bool update)
|
|
|
|
{
|
|
|
|
edbus_service_signal_emit(iface, EFREET_SIGNAL_DESKTOP_CACHE_UPDATE, update);
|
|
|
|
}
|
|
|
|
|
|
|
|
Eina_Bool
|
|
|
|
dbus_init(void)
|
|
|
|
{
|
|
|
|
if (!edbus_init()) return EINA_FALSE;
|
|
|
|
|
|
|
|
conn = edbus_connection_get(EDBUS_CONNECTION_TYPE_SESSION);
|
|
|
|
if (!conn) goto conn_error;
|
|
|
|
|
2012-12-14 06:27:05 -08:00
|
|
|
edbus_connection_event_callback_add(conn, EDBUS_CONNECTION_DISCONNECTED,
|
|
|
|
disconnected, NULL);
|
2012-11-01 18:47:00 -07:00
|
|
|
iface = edbus_service_interface_register(conn, PATH, &desc);
|
2012-10-20 21:53:23 -07:00
|
|
|
edbus_name_request(conn, BUS, EDBUS_NAME_REQUEST_FLAG_DO_NOT_QUEUE,
|
|
|
|
on_name_request, NULL);
|
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
conn_error:
|
|
|
|
edbus_shutdown();
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
Eina_Bool
|
|
|
|
dbus_shutdown(void)
|
|
|
|
{
|
|
|
|
edbus_connection_unref(conn);
|
|
|
|
edbus_shutdown();
|
|
|
|
return EINA_TRUE;
|
|
|
|
|
|
|
|
}
|