Example #1
0
    def do_library_delete(self, to_delete_ids):
        view = self.gui.current_view()
        next_id = view.next_id
        # Ask the user if they want to delete the book from the library or device if it is in both.
        if self.gui.device_manager.is_device_present:
            on_device = False
            on_device_ids = self._get_selected_ids()
            for id in on_device_ids:
                res = self.gui.book_on_device(id)
                if res[0] or res[1] or res[2]:
                    on_device = True
                if on_device:
                    break
            if on_device:
                loc = confirm_location('<p>' + _('Some of the selected books are on the attached device. '
                                            '<b>Where</b> do you want the selected files deleted from?'),
                            self.gui)
                if not loc:
                    return
                elif loc == 'dev':
                    self.remove_matching_books_from_device()
                    return
                elif loc == 'both':
                    self.remove_matching_books_from_device()
        # The following will run if the selected books are not on a connected device.
        # The user has selected to delete from the library or the device and library.
        if not confirm('<p>'+ngettext(
                'The selected book will be <b>permanently deleted</b> and the files '
                'removed from your calibre library. Are you sure?',
                'The {} selected books will be <b>permanently deleted</b> and the files '
                'removed from your calibre library. Are you sure?', len(to_delete_ids)).format(len(to_delete_ids)),
                'library_delete_books', self.gui):
            return
        if len(to_delete_ids) < 5:
            try:
                view.model().delete_books_by_id(to_delete_ids)
            except IOError as err:
                if err.errno == errno.EACCES:
                    import traceback
                    fname = getattr(err, 'filename', 'file') or 'file'
                    return error_dialog(self.gui, _('Permission denied'),
                            _('Could not access %s. Is it being used by another'
                            ' program? Click "Show details" for more information.')%fname, det_msg=traceback.format_exc(),
                            show=True)

            self.library_ids_deleted2(to_delete_ids, next_id=next_id)
        else:
            self.__md = MultiDeleter(self.gui, to_delete_ids,
                    partial(self.library_ids_deleted2, next_id=next_id))
Example #2
0
 def do_library_delete(self, to_delete_ids):
     view = self.gui.current_view()
     # Ask the user if they want to delete the book from the library or device if it is in both.
     if self.gui.device_manager.is_device_present:
         on_device = False
         on_device_ids = self._get_selected_ids()
         for id in on_device_ids:
             res = self.gui.book_on_device(id)
             if res[0] or res[1] or res[2]:
                 on_device = True
             if on_device:
                 break
         if on_device:
             loc = confirm_location('<p>' + _('Some of the selected books are on the attached device. '
                                         '<b>Where</b> do you want the selected files deleted from?'),
                         self.gui)
             if not loc:
                 return
             elif loc == 'dev':
                 self.remove_matching_books_from_device()
                 return
             elif loc == 'both':
                 self.remove_matching_books_from_device()
     # The following will run if the selected books are not on a connected device.
     # The user has selected to delete from the library or the device and library.
     if not confirm('<p>'+_('The %d selected book(s) will be '
                             '<b>permanently deleted</b> and the files '
                             'removed from your calibre library. Are you sure?')%len(to_delete_ids)
                         +'</p>', 'library_delete_books', self.gui):
         return
     next_id = view.next_id
     if len(to_delete_ids) < 5:
         view.model().delete_books_by_id(to_delete_ids)
         self.library_ids_deleted2(to_delete_ids, next_id=next_id)
     else:
         self.__md = MultiDeleter(self.gui, to_delete_ids,
                 partial(self.library_ids_deleted2, next_id=next_id))
Example #3
0
 def delete_books(self, *args):
     '''
     Delete selected books from device or library.
     '''
     view = self.gui.current_view()
     rows = view.selectionModel().selectedRows()
     if not rows or len(rows) == 0:
         return
     # Library view is visible.
     if self.gui.stack.currentIndex() == 0:
         to_delete_ids = [view.model().id(r) for r in rows]
         # Ask the user if they want to delete the book from the library or device if it is in both.
         if self.gui.device_manager.is_device_connected:
             on_device = False
             on_device_ids = self._get_selected_ids()
             for id in on_device_ids:
                 res = self.gui.book_on_device(id)
                 if res[0] or res[1] or res[2]:
                     on_device = True
                 if on_device:
                     break
             if on_device:
                 loc = confirm_location('<p>' + _('Some of the selected books are on the attached device. '
                                            '<b>Where</b> do you want the selected files deleted from?'),
                             self.gui)
                 if not loc:
                     return
                 elif loc == 'dev':
                     self.remove_matching_books_from_device()
                     return
                 elif loc == 'both':
                     self.remove_matching_books_from_device()
         # The following will run if the selected books are not on a connected device.
         # The user has selected to delete from the library or the device and library.
         if not confirm('<p>'+_('The selected books will be '
                                '<b>permanently deleted</b> and the files '
                                'removed from your calibre library. Are you sure?')
                             +'</p>', 'library_delete_books', self.gui):
             return
         next_id = view.next_id
         if len(rows) < 5:
             view.model().delete_books_by_id(to_delete_ids)
             self.library_ids_deleted2(to_delete_ids, next_id=next_id)
         else:
             self.__md = MultiDeleter(self.gui, to_delete_ids,
                     partial(self.library_ids_deleted2, next_id=next_id))
     # Device view is visible.
     else:
         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>'+_('The selected books will be '
                                '<b>permanently deleted</b> '
                                'from your device. Are you sure?')
                             +'</p>', '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)