Initial module written by Gustavo F. Padovan, I changed it quite a lot to change some issues... but still many pending, see TODO at the start of e_mod_main.c SVN revision: 47160devs/princeamd/enlightenment-0.17-elive
parent
4bafaa704d
commit
abb50ef416
13 changed files with 1992 additions and 0 deletions
After Width: | Height: | Size: 19 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 17 KiB |
@ -0,0 +1,33 @@ |
||||
MAINTAINERCLEANFILES = Makefile.in
|
||||
MODULE = bluez
|
||||
|
||||
# data files for the module
|
||||
filesdir = $(libdir)/enlightenment/modules/$(MODULE)
|
||||
files_DATA = \
|
||||
e-module-$(MODULE).edj module.desktop |
||||
|
||||
EXTRA_DIST = $(files_DATA)
|
||||
|
||||
# the module .so file
|
||||
INCLUDES = -I. \
|
||||
-I$(top_srcdir) \
|
||||
-I$(top_srcdir)/src/modules/$(MODULE) \
|
||||
-I$(top_srcdir)/src/bin \
|
||||
-I$(top_srcdir)/src/lib \
|
||||
-I$(top_srcdir)/src/modules \
|
||||
@e_cflags@ @EBLUEZ_CFLAGS@
|
||||
|
||||
pkgdir = $(libdir)/enlightenment/modules/$(MODULE)/$(MODULE_ARCH)
|
||||
|
||||
pkg_LTLIBRARIES = module.la
|
||||
|
||||
module_la_SOURCES = e_mod_main.h \
|
||||
e_mod_main.c \
|
||||
e_mod_config.c
|
||||
|
||||
module_la_LIBADD = @e_libs@ @dlopen_libs@ @EBLUEZ_LIBS@
|
||||
module_la_LDFLAGS = -module -avoid-version
|
||||
module_la_DEPENDENCIES = $(top_builddir)/config.h
|
||||
|
||||
uninstall: |
||||
rm -rf $(DESTDIR)$(libdir)/enlightenment/modules/$(MODULE)
|
Binary file not shown.
@ -0,0 +1,173 @@ |
||||
#include "e_mod_main.h" |
||||
|
||||
extern const char _e_bluez_Name[]; |
||||
|
||||
struct _E_Config_Dialog_Data |
||||
{ |
||||
E_Bluez_Instance *inst; |
||||
const char *name; |
||||
Eina_Bool mode; |
||||
unsigned int timeout; |
||||
struct { |
||||
Evas_Object *label; |
||||
Evas_Object *slider; |
||||
Evas_Object *help; |
||||
} gui; |
||||
}; |
||||
|
||||
/* Local Function Prototypes */ |
||||
static void *_create_data(E_Config_Dialog *dialog); |
||||
static void _free_data(E_Config_Dialog *dialog, E_Config_Dialog_Data *cfdata); |
||||
static Evas_Object *_basic_create(E_Config_Dialog *dialog, Evas *evas, E_Config_Dialog_Data *cfdata); |
||||
static int _basic_apply(E_Config_Dialog *dialog, E_Config_Dialog_Data *cfdata); |
||||
|
||||
E_Config_Dialog * |
||||
e_bluez_config_dialog_new(E_Container *con, E_Bluez_Instance *inst) |
||||
{ |
||||
E_Config_Dialog *dialog; |
||||
E_Config_Dialog_View *view; |
||||
|
||||
if (inst->conf_dialog) |
||||
return inst->conf_dialog; |
||||
|
||||
view = E_NEW(E_Config_Dialog_View, 1); |
||||
if (!view) |
||||
return NULL; |
||||
|
||||
view->create_cfdata = _create_data; |
||||
view->free_cfdata = _free_data; |
||||
view->basic.create_widgets = _basic_create; |
||||
view->basic.apply_cfdata = _basic_apply; |
||||
|
||||
dialog = e_config_dialog_new(con, _("Bluetooth Settings"), |
||||
_e_bluez_Name, "e_bluez_config_dialog_new", |
||||
e_bluez_theme_path(), 0, view, inst); |
||||
|
||||
return dialog; |
||||
} |
||||
|
||||
static void * |
||||
_create_data(E_Config_Dialog *dialog) |
||||
{ |
||||
E_Config_Dialog_Data *cfdata; |
||||
E_Bluez_Instance *inst; |
||||
|
||||
cfdata = E_NEW(E_Config_Dialog_Data, 1); |
||||
if (!cfdata) |
||||
return NULL; |
||||
|
||||
cfdata->inst = dialog->data; |
||||
inst = cfdata->inst; |
||||
if (!e_bluez_adapter_discoverable_get(inst->adapter, &cfdata->mode)) |
||||
cfdata->mode = 0; |
||||
|
||||
if (!e_bluez_adapter_discoverable_timeout_get |
||||
(inst->adapter, &cfdata->timeout)) |
||||
cfdata->timeout = 0; |
||||
cfdata->timeout /= 60; |
||||
|
||||
if (!e_bluez_adapter_name_get(inst->adapter, &cfdata->name)) |
||||
cfdata->name = NULL; |
||||
cfdata->name = strdup(cfdata->name); |
||||
|
||||
return cfdata; |
||||
} |
||||
|
||||
static void |
||||
_free_data(E_Config_Dialog *dialog, E_Config_Dialog_Data *cfdata) |
||||
{ |
||||
E_Bluez_Instance *inst = dialog->data; |
||||
|
||||
inst->conf_dialog = NULL; |
||||
E_FREE(cfdata); |
||||
} |
||||
|
||||
static void |
||||
_cb_disable_timeout(void *data, Evas_Object *obj __UNUSED__) |
||||
{ |
||||
E_Config_Dialog_Data *cfdata = data; |
||||
Eina_Bool disable = !cfdata->mode; |
||||
|
||||
e_widget_disabled_set(cfdata->gui.label, disable); |
||||
e_widget_disabled_set(cfdata->gui.slider, disable); |
||||
e_widget_disabled_set(cfdata->gui.help, disable); |
||||
} |
||||
|
||||
static Evas_Object * |
||||
_basic_create(E_Config_Dialog *dialog __UNUSED__, Evas *evas, E_Config_Dialog_Data *cfdata) |
||||
{ |
||||
Evas_Object *o, *ob; |
||||
Evas_Object *check; |
||||
char buf[48]; |
||||
const char *address; |
||||
|
||||
o = e_widget_list_add(evas, 0, 0); |
||||
|
||||
if (!e_bluez_adapter_address_get(cfdata->inst->adapter, &address)) |
||||
address = NULL; |
||||
|
||||
ob = e_widget_label_add(evas, _("Name")); |
||||
e_widget_list_object_append(o, ob, 1, 1, 0.5); |
||||
|
||||
ob = e_widget_entry_add(evas, (char **)&cfdata->name, NULL, NULL, NULL); |
||||
e_widget_list_object_append(o, ob, 1, 1, 0.5); |
||||
|
||||
check = e_widget_check_add |
||||
(evas, _("Discoverable mode"), (int *)&cfdata->mode); |
||||
e_widget_list_object_append(o, check, 1, 1, 0.5); |
||||
|
||||
ob = e_widget_label_add(evas, _("Discovarable Timeout")); |
||||
cfdata->gui.label = ob; |
||||
e_widget_list_object_append(o, ob, 1, 1, 0.5); |
||||
|
||||
ob = e_widget_slider_add(evas, 1, 0, _("%1.0f minutes"), 0, 30, 1, 0, |
||||
NULL, (int*)&cfdata->timeout, 100); |
||||
e_widget_slider_special_value_add(ob, 0.0, 0.0, _("Forever")); |
||||
cfdata->gui.slider = ob; |
||||
e_widget_list_object_append(o, ob, 1, 1, 0.5); |
||||
|
||||
e_widget_on_change_hook_set(check, _cb_disable_timeout, cfdata); |
||||
_cb_disable_timeout(cfdata, NULL); |
||||
|
||||
snprintf(buf, sizeof(buf), _("MAC Address: %s"), address); |
||||
ob = e_widget_label_add(evas, buf); |
||||
e_widget_list_object_append(o, ob, 1, 1, 0.5); |
||||
|
||||
return o; |
||||
} |
||||
|
||||
static void |
||||
_method_success_check(void *data, DBusMessage *msg __UNUSED__, DBusError *error) |
||||
{ |
||||
const char *name = data; |
||||
|
||||
if ((!error) || (!dbus_error_is_set(error))) |
||||
return; |
||||
|
||||
ERR("method %s() finished with error: %s %s\n", |
||||
name, error->name, error->message); |
||||
dbus_error_free(error); |
||||
} |
||||
|
||||
static int |
||||
_basic_apply(E_Config_Dialog *dialog __UNUSED__, E_Config_Dialog_Data *cfdata) |
||||
{ |
||||
E_Bluez_Instance *inst = cfdata->inst; |
||||
|
||||
if (!e_bluez_adapter_discoverable_set |
||||
(inst->adapter, cfdata->mode, |
||||
_method_success_check, "e_bluez_adapter_discoverable_get")) |
||||
ERR("Can't set Discoverable on adapter"); |
||||
|
||||
if (!e_bluez_adapter_discoverable_timeout_set |
||||
(inst->adapter, cfdata->timeout * 60, |
||||
_method_success_check, "e_bluez_adapter_discoverable_timeout_get")) |
||||
ERR("Can't set DiscoverableTimeout on adapter"); |
||||
|
||||
if (!e_bluez_adapter_name_set |
||||
(inst->adapter, cfdata->name, |
||||
_method_success_check, "e_bluez_adapter_name_get")) |
||||
ERR("Can't set Name on adapter"); |
||||
|
||||
return 1; |
||||
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,146 @@ |
||||
/*
|
||||
* vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2 |
||||
*/ |
||||
#ifndef E_MOD_MAIN_H |
||||
#define E_MOD_MAIN_H |
||||
|
||||
#include "config.h" |
||||
#include <e.h> |
||||
#include <E_Bluez.h> |
||||
#include <eina_log.h> |
||||
|
||||
#define MOD_CONF_VERSION 2 |
||||
|
||||
extern int _e_bluez_log_dom; |
||||
#define DBG(...) EINA_LOG_DOM_DBG(_e_bluez_log_dom, __VA_ARGS__) |
||||
#define WRN(...) EINA_LOG_DOM_WARN(_e_bluez_log_dom, __VA_ARGS__) |
||||
#define ERR(...) EINA_LOG_DOM_ERR(_e_bluez_log_dom, __VA_ARGS__) |
||||
|
||||
typedef struct E_Bluez_Instance E_Bluez_Instance; |
||||
typedef struct E_Bluez_Instance_Device E_Bluez_Instance_Device; |
||||
typedef struct E_Bluez_Module_Context E_Bluez_Module_Context; |
||||
|
||||
struct E_Bluez_Instance |
||||
{ |
||||
E_Bluez_Module_Context *ctxt; |
||||
E_Gadcon_Client *gcc; |
||||
E_Gadcon_Popup *popup; |
||||
E_Menu *menu; |
||||
|
||||
/* used by popup */ |
||||
int powered; |
||||
Eina_Bool first_selection; |
||||
const char *address; |
||||
const char *alias; |
||||
|
||||
Eina_List *devices; |
||||
E_Bluez_Element *adapter; |
||||
double last_scan; |
||||
Eina_Bool discovering:1; |
||||
Eina_Bool powered_pending:1; |
||||
Eina_Bool discoverable:1; |
||||
|
||||
struct |
||||
{ |
||||
Evas_Object *gadget; |
||||
Evas_Object *list; |
||||
Evas_Object *powered; |
||||
Evas_Object *button; |
||||
Evas_Object *control; |
||||
struct |
||||
{ |
||||
Ecore_X_Window win; |
||||
Ecore_Event_Handler *mouse_up; |
||||
Ecore_Event_Handler *key_down; |
||||
} input; |
||||
} ui; |
||||
|
||||
E_Gadcon_Popup *tip; |
||||
Evas_Object *o_tip; |
||||
|
||||
E_Config_Dialog *conf_dialog; |
||||
}; |
||||
|
||||
struct E_Bluez_Instance_Device |
||||
{ |
||||
const char *address; |
||||
const char *alias; |
||||
// TODO (and also show list icon!): Eina_Bool paired:1;
|
||||
// TODO (and also show list icon!): Eina_Bool trusted:1;
|
||||
// TODO (and also show list icon!): Eina_Bool connected:1;
|
||||
// TODO ... class, icon
|
||||
}; |
||||
|
||||
struct E_Bluez_Module_Context |
||||
{ |
||||
Eina_List *instances; |
||||
E_Bluez_Instance *default_instance; |
||||
const char *default_adapter; |
||||
|
||||
struct { |
||||
E_DBus_Connection *conn; |
||||
E_DBus_Interface *iface; |
||||
E_DBus_Object *obj; |
||||
Eina_List *pending; |
||||
} agent; |
||||
|
||||
struct |
||||
{ |
||||
E_Action *toggle_powered; |
||||
} actions; |
||||
|
||||
struct |
||||
{ |
||||
Ecore_Event_Handler *manager_in; |
||||
Ecore_Event_Handler *manager_out; |
||||
Ecore_Event_Handler *device_found; |
||||
Ecore_Event_Handler *element_updated; |
||||
} event; |
||||
|
||||
struct |
||||
{ |
||||
Ecore_Poller *manager_changed; |
||||
} poller; |
||||
|
||||
Eina_Bool has_manager:1; |
||||
}; |
||||
|
||||
EAPI extern E_Module_Api e_modapi; |
||||
EAPI void *e_modapi_init (E_Module *m); |
||||
EAPI int e_modapi_shutdown (E_Module *m); |
||||
EAPI int e_modapi_save (E_Module *m); |
||||
|
||||
const char *e_bluez_theme_path(void); |
||||
E_Config_Dialog *e_bluez_config_dialog_new(E_Container *con, E_Bluez_Instance *inst); |
||||
void _bluez_toggle_powered(E_Bluez_Instance *inst); |
||||
|
||||
|
||||
static inline void |
||||
_bluez_dbus_error_show(const char *msg, const DBusError *error) |
||||
{ |
||||
const char *name; |
||||
|
||||
if ((!error) || (!dbus_error_is_set(error))) |
||||
return; |
||||
|
||||
name = error->name; |
||||
if (strncmp(name, "org.bluez.Error.", |
||||
sizeof("org.bluez.Error.") - 1) == 0) |
||||
name += sizeof("org.bluez.Error.") - 1; |
||||
|
||||
e_util_dialog_show(_("Bluez Server Operation Failed"), |
||||
_("Could not execute remote operation:<br>" |
||||
"%s<br>" |
||||
"Server Error <hilight>%s:</hilight> %s"), |
||||
msg, name, error->message); |
||||
} |
||||
|
||||
static inline void |
||||
_bluez_operation_error_show(const char *msg) |
||||
{ |
||||
e_util_dialog_show(_("Bluez Operation Failed"), |
||||
_("Could not execute local operation:<br>%s"), |
||||
msg); |
||||
} |
||||
|
||||
#endif |
@ -0,0 +1,6 @@ |
||||
[Desktop Entry] |
||||
Type=Link |
||||
Name=Bluetooth Manager |
||||
Icon=e-module-bluez |
||||
Comment=<title>Bluetooth Management.</title> |
||||
X-Enlightenment-ModuleType=system |
Loading…
Reference in new issue