Exemplo n.º 1
0
    def __init__(self, cover_thread_count=2, detail_thread_count=4):
        QAbstractItemModel.__init__(self)

        self.DRM_LOCKED_ICON = QPixmap(I('drm-locked.png')).scaledToHeight(
            64, Qt.SmoothTransformation)
        self.DRM_UNLOCKED_ICON = QPixmap(I('drm-unlocked.png')).scaledToHeight(
            64, Qt.SmoothTransformation)
        self.DRM_UNKNOWN_ICON = QPixmap(
            I('dialog_question.png')).scaledToHeight(64,
                                                     Qt.SmoothTransformation)
        self.DONATE_ICON = QPixmap(I('donate.png')).scaledToHeight(
            16, Qt.SmoothTransformation)
        self.DOWNLOAD_ICON = QPixmap(I('arrow-down.png')).scaledToHeight(
            16, Qt.SmoothTransformation)

        # All matches. Used to determine the order to display
        # self.matches because the SearchFilter returns
        # matches unordered.
        self.all_matches = []
        # Only the showing matches.
        self.matches = []
        self.query = ''
        self.filterable_query = False
        self.search_filter = SearchFilter()
        self.cover_pool = CoverThreadPool(cover_thread_count)
        self.details_pool = DetailsThreadPool(detail_thread_count)

        self.filter_results_dispatcher = FunctionDispatcher(
            self.filter_results)
        self.got_result_details_dispatcher = FunctionDispatcher(
            self.got_result_details)

        self.sort_col = 2
        self.sort_order = Qt.AscendingOrder
Exemplo n.º 2
0
 def __init__(self, db):
     Thread.__init__(self)
     self.daemon = True
     self.db = db
     self.keep_running = True
     from calibre.gui2 import FunctionDispatcher
     self.do_write = FunctionDispatcher(self.write)
     self.get_metadata_for_dump = FunctionDispatcher(db.get_metadata_for_dump)
     self.clear_dirtied = FunctionDispatcher(db.clear_dirtied)
     self.set_dirtied = FunctionDispatcher(db.dirtied)
Exemplo n.º 3
0
    def __init__(self, args, ids, db, refresh_books, cc_widgets, s_r_func, do_sr, sr_calls, parent=None, window_title=_('Working')):
        QDialog.__init__(self, parent)

        self._layout =  l = QVBoxLayout()
        self.setLayout(l)

        self.msg = QLabel(_('Processing %d books, please wait...') % len(ids))
        self.font = QFont()
        self.font.setPointSize(self.font.pointSize() + 8)
        self.msg.setFont(self.font)
        self.pi = ProgressIndicator(self)
        self.pi.setDisplaySize(100)
        self._layout.addWidget(self.pi, 0, Qt.AlignHCenter)
        self._layout.addSpacing(15)
        self._layout.addWidget(self.msg, 0, Qt.AlignHCenter)
        self.setWindowTitle(window_title + '...')
        self.setMinimumWidth(200)
        self.resize(self.sizeHint())
        self.error = None
        self.all_done.connect(self.on_all_done, type=Qt.QueuedConnection)
        self.args, self.ids = args, ids
        self.db, self.cc_widgets = db, cc_widgets
        self.s_r_func = FunctionDispatcher(s_r_func)
        self.do_sr = do_sr
        self.sr_calls = sr_calls
        self.refresh_books = refresh_books
Exemplo n.º 4
0
    def send_files(self, job):
        if job is not None:
            self.device_manager.add_books_to_metadata(
                job.result, [self.mi], self.gui.booklists())
            if not self.gui.set_books_in_library(
                    self.gui.booklists(), reset=True,
                    add_as_step_to_job=job, do_device_sync=False):
                self.gui.upload_booklists(job)
            self.gui.refresh_ondevice()
            view = self.gui.memory_view
            view.model().resort(reset=False)
            view.model().research()

        [has_book, _, _, _, paths] = self.gui.book_on_device(self.book_id)
        device_info = self.device_manager.get_current_device_information()
        # /Volumes/Kindle
        device_path_prefix = device_info['info'][4]['main']['prefix']
        if has_book:
            device_book_path = Path(device_path_prefix)
            device_book_path = device_book_path.joinpath(next(iter(paths)))
            self.move_ll_to_device(device_book_path)
        elif not self.retry:
            # upload book and cover to device
            cover_path = Path(self.book_path).parent.joinpath('cover.jpg')
            self.mi.thumbnail = None, None, cover_path.read_bytes()
            book_name = Path(self.book_path).name
            titles = [i.title for i in [self.mi]]
            plugboards = self.gui.current_db.new_api.pref('plugboards', {})
            self.device_manager.upload_books(
                FunctionDispatcher(self.send_files), [self.book_path],
                [book_name], on_card=None, metadata=[self.mi],
                titles=titles, plugboards=plugboards)
            self.retry = True
Exemplo n.º 5
0
    def send_files(self, job):
        if job is not None:
            if job.failed:
                self.gui.job_exception(job, dialog_title='Upload book failed')
                return
            self.gui.books_uploaded(job)

        [has_book, _, _, _, paths] = self.gui.book_on_device(self.book_id)
        # /Volumes/Kindle
        device_prefix = self.device_manager.device._main_prefix
        if has_book:
            device_book_path = Path(device_prefix).joinpath(next(iter(paths)))
            self.move_file_to_device(self.ll_path, device_book_path)
            self.move_file_to_device(self.x_ray_path, device_book_path)
        elif job is None:
            # upload book and cover to device
            self.gui.update_thumbnail(self.mi)
            job = self.device_manager.upload_books(
                FunctionDispatcher(self.send_files), [self.book_path],
                [Path(self.book_path).name],
                on_card=None,
                metadata=[self.mi],
                titles=[i.title for i in [self.mi]],
                plugboards=self.gui.current_db.new_api.pref('plugboards', {}))
            self.gui.upload_memory[job] = ([self.mi], None, None,
                                           [self.book_path])
Exemplo n.º 6
0
    def __init__(self, parent, modelcls=BooksModel, use_edit_metadata_dialog=True):
        QTableView.__init__(self, parent)
        self.default_row_height = self.verticalHeader().defaultSectionSize()
        self.gui = parent
        self.setProperty('highlight_current_item', 150)
        self.row_sizing_done = False
        self.alternate_views = AlternateViews(self)

        if not tweaks['horizontal_scrolling_per_column']:
            self.setHorizontalScrollMode(self.ScrollPerPixel)

        self.setEditTriggers(self.EditKeyPressed)
        if tweaks['doubleclick_on_library_view'] == 'edit_cell':
            self.setEditTriggers(self.DoubleClicked|self.editTriggers())
        elif tweaks['doubleclick_on_library_view'] == 'open_viewer':
            self.setEditTriggers(self.SelectedClicked|self.editTriggers())
            self.doubleClicked.connect(parent.iactions['View'].view_triggered)
        elif tweaks['doubleclick_on_library_view'] == 'edit_metadata':
            # Must not enable single-click to edit, or the field will remain
            # open in edit mode underneath the edit metadata dialog
            if use_edit_metadata_dialog:
                self.doubleClicked.connect(
                        partial(parent.iactions['Edit Metadata'].edit_metadata,
                                checked=False))
            else:
                self.setEditTriggers(self.DoubleClicked|self.editTriggers())

        setup_dnd_interface(self)
        self.setAlternatingRowColors(True)
        self.setShowGrid(False)
        self.setWordWrap(False)

        self.rating_delegate = RatingDelegate(self)
        self.timestamp_delegate = DateDelegate(self)
        self.pubdate_delegate = PubDateDelegate(self)
        self.last_modified_delegate = DateDelegate(self,
                tweak_name='gui_last_modified_display_format')
        self.languages_delegate = LanguagesDelegate(self)
        self.tags_delegate = CompleteDelegate(self, ',', 'all_tag_names')
        self.authors_delegate = CompleteDelegate(self, '&', 'all_author_names', True)
        self.cc_names_delegate = CompleteDelegate(self, '&', 'all_custom', True)
        self.series_delegate = TextDelegate(self)
        self.publisher_delegate = TextDelegate(self)
        self.text_delegate = TextDelegate(self)
        self.cc_text_delegate = CcTextDelegate(self)
        self.cc_enum_delegate = CcEnumDelegate(self)
        self.cc_bool_delegate = CcBoolDelegate(self)
        self.cc_comments_delegate = CcCommentsDelegate(self)
        self.cc_template_delegate = CcTemplateDelegate(self)
        self.cc_number_delegate = CcNumberDelegate(self)
        self.display_parent = parent
        self._model = modelcls(self)
        self.setModel(self._model)
        self._model.count_changed_signal.connect(self.do_row_sizing,
                                                 type=Qt.QueuedConnection)
        self.setSelectionBehavior(QAbstractItemView.SelectRows)
        self.setSortingEnabled(True)
        self.selectionModel().currentRowChanged.connect(self._model.current_changed)
        self.preserve_state = partial(PreserveViewState, self)
        self.marked_changed_listener = FunctionDispatcher(self.marked_changed)

        # {{{ Column Header setup
        self.can_add_columns = True
        self.was_restored = False
        self.column_header = HeaderView(Qt.Horizontal, self)
        self.setHorizontalHeader(self.column_header)
        self.column_header.sortIndicatorChanged.disconnect()
        self.column_header.sortIndicatorChanged.connect(self.user_sort_requested)
        self.column_header.setSectionsMovable(True)
        self.column_header.setSectionsClickable(True)
        self.column_header.sectionMoved.connect(self.save_state)
        self.column_header.setContextMenuPolicy(Qt.CustomContextMenu)
        self.column_header.customContextMenuRequested.connect(self.show_column_header_context_menu)
        self.column_header.sectionResized.connect(self.column_resized, Qt.QueuedConnection)
        self.row_header = HeaderView(Qt.Vertical, self)
        self.row_header.setSectionResizeMode(self.row_header.Fixed)
        self.setVerticalHeader(self.row_header)
        # }}}

        self._model.database_changed.connect(self.database_changed)
        hv = self.verticalHeader()
        hv.setSectionsClickable(True)
        hv.setCursor(Qt.PointingHandCursor)
        self.selected_ids = []
        self._model.about_to_be_sorted.connect(self.about_to_be_sorted)
        self._model.sorting_done.connect(self.sorting_done,
                type=Qt.QueuedConnection)