'Called when a device is connected to the computer.'

def device_detected(self, connected, device_kind):

    if (connected and (not self.device_manager.is_device_connected)):
        connected = False
    self.set_device_menu_items_state(connected)
    if connected:
        self.device_connected = device_kind
        self.device_manager.get_device_information(FunctionDispatcher(self.info_read))
        self.set_default_thumbnail(self.device_manager.device.THUMBNAIL_HEIGHT)
        self.status_bar.show_message(((_('Device:    ') + self.device_manager.device.get_gui_name()) + _('    detected.')), 3000)
        self.library_view.set_device_connected(self.device_connected)
        self.refresh_ondevice(reset_only=True)
    else:
        self.device_connected = None
        self.status_bar.device_disconnected()
        dviews = (self.memory_view, self.card_a_view, self.card_b_view)
        for v in dviews:
            v.save_state()
        if (self.current_view() != self.library_view):
            self.book_details.reset_info()
        self.location_manager.update_devices()
        self.bars_manager.update_bars(reveal_bar=True)
        self.library_view.set_device_connected(self.device_connected)
        for v in dviews:
            v.set_database([])
        self.refresh_ondevice()
    device_signals.device_connection_changed.emit(connected)
