[Eve] Implement single instance using DBus.
SVN revision: 52256
This commit is contained in:
parent
0f0781eaed
commit
41268c68fb
1
TODO
1
TODO
|
@ -44,5 +44,4 @@ Misc
|
|||
----
|
||||
* documentation: HTML, provided as a fixed bookmark item
|
||||
* download manager?
|
||||
* single instance? export dbus, try to acquire name, if not possible (already exists) send request to open url in the existing window and give it x11-focus
|
||||
* history + bookmark: remember if rss exist, and request it silently to display feedback when new content is available
|
||||
|
|
|
@ -58,6 +58,7 @@ AC_SUBST(ALL_LINGUAS)
|
|||
AM_GNU_GETTEXT_VERSION([0.12.1])
|
||||
AM_GNU_GETTEXT([external])
|
||||
|
||||
PKG_CHECK_MODULES([EDBUS], [edbus])
|
||||
PKG_CHECK_MODULES([ELEMENTARY], [elementary])
|
||||
PKG_CHECK_MODULES([EWEBKIT], [ewebkit ecore-file])
|
||||
|
||||
|
|
|
@ -7,14 +7,15 @@ INCLUDES = \
|
|||
-DGETTEXT_PACKAGE=\"$(PACKAGE)\" \
|
||||
-DLOCALEDIR=\"$(localedir)\" \
|
||||
@ELEMENTARY_CFLAGS@ \
|
||||
@EWEBKIT_CFLAGS@
|
||||
@EWEBKIT_CFLAGS@ \
|
||||
@EDBUS_CFLAGS@
|
||||
|
||||
bin_PROGRAMS = eve
|
||||
if BUILD_QUICKLAUNCH
|
||||
bin_PROGRAMS += eve_ql
|
||||
endif
|
||||
|
||||
eve_LDADD = @ELEMENTARY_LIBS@ @EWEBKIT_LIBS@
|
||||
eve_LDADD = @ELEMENTARY_LIBS@ @EWEBKIT_LIBS@ @EDBUS_LIBS@
|
||||
eve_SOURCES = main.c view.c chrome.c favorite.c history.c prefs.c
|
||||
|
||||
if BUILD_QUICKLAUNCH
|
||||
|
@ -27,7 +28,7 @@ if BUILD_QUICKLAUNCH
|
|||
eve_qldir = $(quicklauncher_libdir)
|
||||
eve_ql_LTLIBRARIES = eve_ql.la
|
||||
eve_ql_la_SOURCES = main.c view.c chrome.c
|
||||
eve_ql_la_LIBADD = @ELEMENTARY_LIBS@ @EWEBKIT_LIBS@
|
||||
eve_ql_la_LIBADD = @ELEMENTARY_LIBS@ @EWEBKIT_LIBS@ @EDBUS_LIBS@
|
||||
eve_ql_la_CFLAGS =
|
||||
eve_ql_la_LDFLAGS = -module -avoid-version -no-undefined
|
||||
eve_ql_SOURCES = main.c
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
|
||||
#include <Ecore_Getopt.h>
|
||||
#include <Ecore_File.h>
|
||||
#include <E_DBus.h>
|
||||
#include <Ecore_X.h>
|
||||
#include <stdlib.h>
|
||||
#include "gettext.h"
|
||||
|
||||
|
@ -32,6 +34,11 @@ struct Cursor {
|
|||
int hot_x, hot_y;
|
||||
};
|
||||
|
||||
struct Eve_DBus_Request_Name_Response {
|
||||
E_DBus_Connection *conn;
|
||||
const char *url;
|
||||
};
|
||||
|
||||
static void
|
||||
del_win(App *app, Evas_Object *win)
|
||||
{
|
||||
|
@ -352,6 +359,63 @@ static const Ecore_Getopt options = {
|
|||
}
|
||||
};
|
||||
|
||||
static DBusMessage *
|
||||
_cb_dbus_open_url(E_DBus_Object *obj __UNUSED__, DBusMessage *msg)
|
||||
{
|
||||
DBusMessage *reply;
|
||||
Browser_Window *win = eina_list_data_get(app.windows);
|
||||
char *new_url;
|
||||
|
||||
dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &new_url, DBUS_TYPE_INVALID);
|
||||
tab_add(win, new_url);
|
||||
ecore_x_window_focus(elm_win_xwindow_get(win->win));
|
||||
|
||||
return dbus_message_new_method_return(msg);
|
||||
}
|
||||
|
||||
static void
|
||||
_cb_dbus_request_name(void *data, DBusMessage *msg __UNUSED__, DBusError *err)
|
||||
{
|
||||
struct Eve_DBus_Request_Name_Response *response = data;
|
||||
DBusError new_err;
|
||||
dbus_uint32_t ret;
|
||||
|
||||
if (dbus_error_is_set(err)) return;
|
||||
|
||||
dbus_error_init(&new_err);
|
||||
dbus_message_get_args(msg, &new_err, DBUS_TYPE_UINT32, &ret, DBUS_TYPE_INVALID);
|
||||
|
||||
switch (ret) {
|
||||
case DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER:
|
||||
case DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER:
|
||||
{
|
||||
E_DBus_Interface *iface;
|
||||
E_DBus_Object *eve_dbus;
|
||||
eve_dbus = e_dbus_object_add(response->conn, "/mobi/profusion/eve", NULL);
|
||||
iface = e_dbus_interface_new("mobi.profusion.eve");
|
||||
e_dbus_interface_method_add(iface, "open_url", "s", "", _cb_dbus_open_url);
|
||||
e_dbus_object_interface_attach(eve_dbus, iface);
|
||||
}
|
||||
break;
|
||||
case DBUS_REQUEST_NAME_REPLY_IN_QUEUE:
|
||||
case DBUS_REQUEST_NAME_REPLY_EXISTS:
|
||||
{
|
||||
DBusMessage *open_url = dbus_message_new_method_call("mobi.profusion.eve",
|
||||
"/mobi/profusion/eve",
|
||||
"mobi.profusion.eve",
|
||||
"open_url");
|
||||
DBusMessageIter iter;
|
||||
dbus_message_iter_init_append(open_url, &iter);
|
||||
dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &response->url);
|
||||
e_dbus_message_send(response->conn, open_url, NULL, -1, NULL);
|
||||
dbus_message_unref(open_url);
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
free(response);
|
||||
}
|
||||
|
||||
EAPI int
|
||||
elm_main(int argc, char **argv)
|
||||
{
|
||||
|
@ -365,6 +429,7 @@ elm_main(int argc, char **argv)
|
|||
Eina_Bool disable_touch_interface = 0xff;
|
||||
char *user_agent_option = NULL;
|
||||
const char *user_agent_str;
|
||||
E_DBus_Connection *conn;
|
||||
|
||||
Ecore_Getopt_Value values[] = {
|
||||
ECORE_GETOPT_VALUE_BOOL(app.is_fullscreen),
|
||||
|
@ -441,6 +506,7 @@ elm_main(int argc, char **argv)
|
|||
favorite_init();
|
||||
history_init();
|
||||
preferences_init();
|
||||
e_dbus_init();
|
||||
|
||||
home = getenv("HOME");
|
||||
if (!home || !home[0])
|
||||
|
@ -534,6 +600,18 @@ elm_main(int argc, char **argv)
|
|||
else
|
||||
url = prefs_home_page_get(prefs);
|
||||
|
||||
conn = e_dbus_bus_get(DBUS_BUS_SESSION);
|
||||
if (conn)
|
||||
{
|
||||
struct Eve_DBus_Request_Name_Response *response = calloc(1, sizeof(*response));
|
||||
if (!response) goto end;
|
||||
|
||||
response->conn = conn;
|
||||
response->url = url;
|
||||
|
||||
e_dbus_request_name(conn, "mobi.profusion.eve", 0, _cb_dbus_request_name, response);
|
||||
}
|
||||
|
||||
if (!add_win(&app, url))
|
||||
{
|
||||
r = -1;
|
||||
|
@ -551,6 +629,8 @@ end:
|
|||
prefs_save(prefs, NULL);
|
||||
prefs_free(prefs);
|
||||
|
||||
if (conn) e_dbus_connection_close(conn);
|
||||
|
||||
eina_log_domain_unregister(_log_domain);
|
||||
_log_domain = -1;
|
||||
elm_shutdown();
|
||||
|
@ -558,6 +638,7 @@ end:
|
|||
favorite_shutdown();
|
||||
history_shutdown();
|
||||
preferences_shutdown();
|
||||
e_dbus_shutdown();
|
||||
return r;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue