fix when there is no adaptor for an instance.
authorGustavo Sverzut Barbieri <barbieri@gmail.com>
Sat, 27 Mar 2010 14:23:37 +0000 (14:23 +0000)
committerGustavo Sverzut Barbieri <barbieri@gmail.com>
Sat, 27 Mar 2010 14:23:37 +0000 (14:23 +0000)
PS: I couldn't test it as my machine does not have a hw switch to turn
bluetooth off... and I'm lazy to search how to disable it using
software (hciconfig hci0 down does not do it, just put the adapter in
offline mode and my btusb is not modular, so I can't remove the
module) :-)

SVN revision: 47505

src/modules/bluez/e_mod_main.c
src/modules/bluez/e_mod_main.h

index 8b24ee5..33c06a7 100644 (file)
@@ -150,10 +150,15 @@ _bluez_toggle_powered(E_Bluez_Instance *inst)
        return;
      }
 
+   if (!inst->adapter)
+     {
+       _bluez_operation_error_show(_("No bluetooth adapter."));
+       return;
+     }
+
    if (!e_bluez_adapter_powered_get(inst->adapter, &powered))
      {
-       _bluez_operation_error_show
-         (_("Query adapter's powered."));
+       _bluez_operation_error_show(_("Query adapter's powered."));
        return;
      }
 
@@ -171,13 +176,15 @@ static void
 _bluez_cb_toggle_powered(E_Object *obj __UNUSED__, const char *params __UNUSED__)
 {
    E_Bluez_Module_Context *ctxt;
+   const Eina_List *l;
+   E_Bluez_Instance *inst;
 
    if (!bluez_mod)
      return;
 
    ctxt = bluez_mod->data;
-   if (ctxt->default_instance)
-     _bluez_toggle_powered(ctxt->default_instance);
+   EINA_LIST_FOREACH(ctxt->instances, l, inst)
+     if (inst->adapter) _bluez_toggle_powered(inst);
 }
 
 static void _bluez_popup_del(E_Bluez_Instance *inst);
@@ -267,6 +274,12 @@ _bluez_popup_cb_powered_changed(void *data, Evas_Object *obj)
        return;
      }
 
+   if (!inst->adapter)
+     {
+       _bluez_operation_error_show(_("No bluetooth adapter."));
+       return;
+     }
+
    if (!e_bluez_adapter_powered_set
        (inst->adapter, powered, _bluez_toggle_powered_cb, inst))
      {
@@ -457,7 +470,9 @@ _bluez_popup_cb_scan(void *data, void *data2 __UNUSED__)
    E_Bluez_Instance *inst = data;
    int ret;
 
-   if (inst->discovering)
+   if (!inst->adapter)
+     ret = 0;
+   else if (inst->discovering)
      ret = e_bluez_adapter_stop_discovery
        (inst->adapter, _bluez_discovery_cb, inst);
    else
@@ -484,6 +499,8 @@ _bluez_popup_cb_controls(void *data, void *data2 __UNUSED__)
      _bluez_popup_del(inst);
    if (inst->conf_dialog)
      return;
+   if (!inst->adapter)
+     return;
    inst->conf_dialog = e_bluez_config_dialog_new(NULL, inst);
 }
 
@@ -647,6 +664,12 @@ _bluez_popup_new(E_Bluez_Instance *inst)
        return;
      }
 
+   if (!inst->adapter)
+     {
+       _bluez_operation_error_show(_("No bluetooth adapter."));
+       return;
+     }
+
    if (!e_bluez_adapter_discovering_get(inst->adapter, &b))
      {
        _bluez_operation_error_show(_("Can't get Discovering property"));
@@ -722,6 +745,8 @@ _bluez_menu_cb_cfg(void *data, E_Menu *menu __UNUSED__, E_Menu_Item *mi __UNUSED
      _bluez_popup_del(inst);
    if (inst->conf_dialog)
      return;
+   if (!inst->adapter)
+     return;
    inst->conf_dialog = e_bluez_config_dialog_new(NULL, inst);
 }
 
@@ -834,12 +859,16 @@ _bluez_edje_view_update(E_Bluez_Instance *inst, Evas_Object *o)
    E_Bluez_Module_Context *ctxt = inst->ctxt;
    const char *name;
 
-   if (!ctxt->has_manager)
+   if ((!ctxt->has_manager) || (!inst->adapter))
      {
        edje_object_part_text_set(o, "e.text.powered", "");
        edje_object_part_text_set(o, "e.text.status", "");
        edje_object_signal_emit(o, "e,changed,off", "e");
-       edje_object_part_text_set(o, "e.text.name", _("No Bluetooth daemon"));
+       if (!ctxt->has_manager)
+         edje_object_part_text_set(o, "e.text.name", _("No Bluetooth daemon"));
+       else
+         edje_object_part_text_set(o, "e.text.name",
+                                   _("No Bluetooth adapter"));
        edje_object_signal_emit(o, "e,changed,name", "e");
        return;
      }
@@ -868,8 +897,7 @@ _bluez_edje_view_update(E_Bluez_Instance *inst, Evas_Object *o)
    else
      {
        edje_object_signal_emit(o, "e,changed,off", "e");
-       edje_object_part_text_set(o, "e.text.status",
-                                 _("Bluetooth is off."));
+       edje_object_part_text_set(o, "e.text.status", _("Bluetooth is off."));
      }
 }
 
@@ -884,7 +912,7 @@ _bluez_gadget_update(E_Bluez_Instance *inst)
 {
    E_Bluez_Module_Context *ctxt = inst->ctxt;
 
-   if (!ctxt->has_manager && inst->popup)
+   if (inst->popup && ((!ctxt->has_manager) || (!inst->adapter)))
      _bluez_popup_del(inst);
 
    if (inst->popup)
@@ -926,7 +954,11 @@ _gc_init(E_Gadcon *gc, const char *name, const char *id, const char *style)
 
    // TODO: instead of getting the default adapter, get the adapter for
    // each instance. See the mixer module.
-   inst->adapter = e_bluez_adapter_get(ctxt->default_adapter);
+   if (ctxt->default_adapter)
+     inst->adapter = e_bluez_adapter_get(ctxt->default_adapter);
+   else
+     inst->adapter = NULL;
+
    if (inst->adapter)
      {
        Eina_Bool powered, discoverable, discovering;
@@ -941,9 +973,6 @@ _gc_init(E_Gadcon *gc, const char *name, const char *id, const char *style)
          inst->discovering = discovering;
      }
 
-   if (!ctxt->default_instance)
-     ctxt->default_instance = inst;
-
    _bluez_gadget_update(inst);
 
    ctxt->instances = eina_list_append(ctxt->instances, inst);
@@ -979,9 +1008,6 @@ _gc_shutdown(E_Gadcon_Client *gcc)
 
    ctxt->instances = eina_list_remove(ctxt->instances, inst);
 
-   if (ctxt->default_instance == inst)
-     ctxt->default_instance = NULL;
-
    E_FREE(inst);
 }
 
index 7a3dd7e..05b0702 100644 (file)
@@ -74,7 +74,6 @@ struct E_Bluez_Instance_Device
 struct E_Bluez_Module_Context
 {
    Eina_List *instances;
-   E_Bluez_Instance *default_instance;
    const char *default_adapter;
 
    struct {