'Delete selected books from device or library.'

def delete_books(self, *args):

    view = self.gui.current_view()
    rows = view.selectionModel().selectedRows()
    if ((not rows) or (len(rows) == 0)):
        return
    if (self.gui.stack.currentIndex() == 0):
        to_delete_ids = [view.model().id(r) for r in rows]
        self.do_library_delete(to_delete_ids)
    else:
        (cv, row) = (self.gui.current_view(), (-1))
        if (cv is not self.gui.library_view):
            row = cv.currentIndex().row()
        if (self.gui.stack.currentIndex() == 1):
            view = self.gui.memory_view
        elif (self.gui.stack.currentIndex() == 2):
            view = self.gui.card_a_view
        else:
            view = self.gui.card_b_view
        paths = view.model().paths(rows)
        ids = view.model().indices(rows)
        if (not confirm(('<p>' + ngettext('The    selected    book    will    be    <b>permanently    deleted</b>    from    your    device.    Are    you    sure?', 'The    {}    selected    books    will    be    <b>permanently    deleted</b>    from    your    device.    Are    you    sure?', len(paths)).format(len(paths))), 'device_delete_books', self.gui)):
            return
        job = self.gui.remove_paths(paths)
        self.delete_memory[job] = (paths, view.model())
        view.model().mark_for_deletion(job, ids, rows_are_ids=True)
        self.gui.status_bar.show_message(_('Deleting    books    from    device.'), 1000)
        if (row > (-1)):
            nrow = ((row - 1) if (row > 0) else (row + 1))
            cv.set_current_row(min(cv.model().rowCount(None), max(0, nrow)))
