Exemplo n.º 1
0
 def start_content_server(self, check_started=True):
     from calibre.srv.embedded import Server
     if not gprefs.get('server3_warning_done', False):
         gprefs.set('server3_warning_done', True)
         if os.path.exists(os.path.join(config_dir, 'server.py')):
             try:
                 os.remove(os.path.join(config_dir, 'server.py'))
             except EnvironmentError:
                 pass
             warning_dialog(
                 self,
                 _('Content server changed!'),
                 _('calibre 3 comes with a completely re-written content server.'
                   ' As such any custom configuration you have for the content'
                   ' server no longer applies. You should check and refresh your'
                   ' settings in Preferences->Sharing->Sharing over the net'
                   ),
                 show=True)
     self.content_server = Server(
         self.library_broker, Dispatcher(self.handle_changes_from_server))
     self.content_server.state_callback = Dispatcher(
         self.iactions['Connect Share'].content_server_state_changed)
     if check_started:
         self.content_server.start_failure_callback = \
             Dispatcher(self.content_server_start_failed)
     self.content_server.start()
Exemplo n.º 2
0
    def build_menus(self):
        if os.environ.get('CALIBRE_OVERRIDE_DATABASE_PATH', None):
            return
        db = self.gui.library_view.model().db
        locations = list(self.stats.locations(db))

        for ac in self.switch_actions:
            ac.setVisible(False)
        self.quick_menu.clear()
        self.rename_menu.clear()
        self.delete_menu.clear()
        quick_actions, rename_actions, delete_actions = [], [], []
        for name, loc in locations:
            is_prev_lib = name == self.prev_lname
            name = name.replace('&', '&&')
            ac = self.quick_menu.addAction(
                name, Dispatcher(partial(self.switch_requested, loc)))
            ac.setStatusTip(_('Switch to: %s') % loc)
            if is_prev_lib:
                f = ac.font()
                f.setBold(True)
                ac.setFont(f)
            quick_actions.append(ac)
            ac = self.rename_menu.addAction(
                name, Dispatcher(partial(self.rename_requested, name, loc)))
            rename_actions.append(ac)
            ac.setStatusTip(_('Rename: %s') % loc)
            ac = self.delete_menu.addAction(
                name, Dispatcher(partial(self.delete_requested, name, loc)))
            delete_actions.append(ac)
            ac.setStatusTip(_('Remove: %s') % loc)

        qs_actions = []
        locations_by_frequency = locations
        if len(locations) >= tweaks['many_libraries']:
            locations_by_frequency = list(
                self.stats.locations(db, limit=sys.maxsize))
        for i, x in enumerate(
                locations_by_frequency[:len(self.switch_actions)]):
            name, loc = x
            name = name.replace('&', '&&')
            ac = self.switch_actions[i]
            ac.setText(name)
            ac.setStatusTip(_('Switch to: %s') % loc)
            ac.setVisible(True)
            qs_actions.append(ac)
        self.qs_locations = [i[1] for i in locations_by_frequency]

        self.quick_menu_action.setVisible(bool(locations))
        self.rename_menu_action.setVisible(bool(locations))
        self.delete_menu_action.setVisible(bool(locations))
        self.gui.location_manager.set_switch_actions(quick_actions,
                                                     rename_actions,
                                                     delete_actions,
                                                     qs_actions,
                                                     self.action_choose)
        # Allow the cloned actions in the OS X global menubar to update
        for a in (self.qaction, self.menuless_qaction):
            a.changed.emit()
Exemplo n.º 3
0
    def copy_to_library(self, loc, delete_after=False):
        rows = self.gui.library_view.selectionModel().selectedRows()
        if not rows or len(rows) == 0:
            return error_dialog(self.gui, _('Cannot copy'),
                    _('No books selected'), show=True)
        ids = list(map(self.gui.library_view.model().id, rows))
        db = self.gui.library_view.model().db
        if not db.exists_at(loc):
            return error_dialog(self.gui, _('No library'),
                    _('No library found at %s')%loc, show=True)

        aname = _('Moving to') if delete_after else _('Copying to')
        dtitle = '%s %s'%(aname, os.path.basename(loc))

        self.pd = ProgressDialog(dtitle, min=0, max=len(ids)-1,
                parent=self.gui, cancelable=False)

        def progress(idx, title):
            self.pd.set_msg(title)
            self.pd.set_value(idx)

        self.worker = Worker(ids, db, loc, Dispatcher(progress),
                             Dispatcher(self.pd.accept), delete_after)
        self.worker.start()

        self.pd.exec_()

        donemsg = _('Copied %(num)d books to %(loc)s')
        if delete_after:
            donemsg = _('Moved %(num)d books to %(loc)s')

        if self.worker.error is not None:
            e, tb = self.worker.error
            error_dialog(self.gui, _('Failed'), _('Could not copy books: ') + e,
                    det_msg=tb, show=True)
        else:
            self.gui.status_bar.show_message(donemsg %
                    dict(num=len(ids), loc=loc), 2000)
            if self.worker.auto_merged_ids:
                books = '\n'.join(self.worker.auto_merged_ids.itervalues())
                info_dialog(self.gui, _('Auto merged'),
                        _('Some books were automatically merged into existing '
                            'records in the target library. Click Show '
                            'details to see which ones. This behavior is '
                            'controlled by the Auto merge option in '
                            'Preferences->Adding books.'), det_msg=books,
                        show=True)
            if delete_after and self.worker.processed:
                v = self.gui.library_view
                ci = v.currentIndex()
                row = None
                if ci.isValid():
                    row = ci.row()

                v.model().delete_books_by_id(self.worker.processed,
                        permanent=True)
                self.gui.iactions['Remove Books'].library_ids_deleted(
                        self.worker.processed, row)
Exemplo n.º 4
0
 def start_content_server(self, check_started=True):
     from calibre.library.server.main import start_threaded_server
     from calibre.library.server import server_config
     self.content_server = start_threaded_server(
             self.library_view.model().db, server_config().parse())
     self.content_server.state_callback = Dispatcher(
             self.iactions['Connect Share'].content_server_state_changed)
     if check_started:
         self.content_server.start_failure_callback = \
             Dispatcher(self.content_server_start_failed)
Exemplo n.º 5
0
 def start_content_server(self, check_started=True):
     from calibre.srv.embedded import Server
     self.content_server = Server(
         self.library_broker, Dispatcher(self.handle_changes_from_server))
     self.content_server.state_callback = Dispatcher(
         self.iactions['Connect Share'].content_server_state_changed)
     if check_started:
         self.content_server.start_failure_callback = \
             Dispatcher(self.content_server_start_failed)
     self.content_server.start()
Exemplo n.º 6
0
    def save_to_disk(self, checked, single_dir=False, single_format=None):
        rows = self.gui.current_view().selectionModel().selectedRows()
        if not rows or len(rows) == 0:
            return error_dialog(self.gui,
                                _('Cannot save to disk'),
                                _('No books selected'),
                                show=True)
        path = choose_dir(self.gui, 'save to disk dialog',
                          _('Choose destination directory'))
        if not path:
            return
        dpath = os.path.abspath(path).replace('/', os.sep) + os.sep
        lpath = self.gui.library_view.model().db.library_path.replace(
            '/', os.sep) + os.sep
        if dpath.startswith(lpath):
            return error_dialog(
                self.gui,
                _('Not allowed'),
                _('You are trying to save files into the calibre '
                  'library. This can cause corruption of your '
                  'library. Save to disk is meant to export '
                  'files from your calibre library elsewhere.'),
                show=True)

        if self.gui.current_view() is self.gui.library_view:
            from calibre.gui2.add import Saver
            from calibre.library.save_to_disk import config
            opts = config().parse()
            if single_format is not None:
                opts.formats = single_format
                # Special case for Kindle annotation files
                if single_format.lower() in ['mbp', 'pdr', 'tan']:
                    opts.to_lowercase = False
                    opts.save_cover = False
                    opts.write_opf = False
                    opts.template = opts.send_template
            opts.single_dir = single_dir
            self._saver = Saver(self.gui,
                                self.gui.library_view.model().db,
                                Dispatcher(self._books_saved),
                                rows,
                                path,
                                opts,
                                spare_server=self.gui.spare_server)

        else:
            paths = self.gui.current_view().model().paths(rows)
            self.gui.device_manager.save_books(Dispatcher(self.books_saved),
                                               paths, path)
Exemplo n.º 7
0
 def download_custom_recipe(self, title, urn):
     arg = {'title': title, 'urn': urn, 'username': None, 'password': None}
     func, args, desc, fmt, temp_files = fetch_scheduled_recipe(arg)
     job = self.gui.job_manager.run_job(
             Dispatcher(self.custom_recipe_fetched), func, args=args, description=desc)
     self.conversion_jobs[job] = (temp_files, fmt, arg)
     self.gui.status_bar.show_message(_('Fetching news from ')+arg['title'], 2000)
Exemplo n.º 8
0
def email_news(mi, remove, get_fmts, done, job_manager):
    opts = email_config().parse()
    accounts = [(account, [x.strip().lower() for x in x[0].split(',')])
                for account, x in opts.accounts.items() if x[1]]
    sent_mails = []
    for i, x in enumerate(accounts):
        account, fmts = x
        files = get_fmts(fmts)
        files = [f for f in files if f is not None]
        if not files:
            continue
        attachment = files[0]
        to_s = [account]
        subjects = [_('News:') + ' ' + mi.title]
        texts = [
            _('Attached is the %s periodical downloaded by calibre.') %
            (mi.title, )
        ]
        attachment_names = [
            ascii_filename(mi.title) + os.path.splitext(attachment)[1]
        ]
        attachments = [attachment]
        jobnames = [mi.title]
        do_remove = []
        if i == len(accounts) - 1:
            do_remove = remove
        send_mails(jobnames, Dispatcher(partial(done, remove=do_remove)),
                   attachments, to_s, subjects, texts, attachment_names,
                   job_manager)
        sent_mails.append(to_s[0])
    return sent_mails
Exemplo n.º 9
0
    def download_ebook(self, book_id, di=None):
        # Get the current metadata for this book from the db
        mi = self.db.get_metadata(book_id,
                                  index_is_id=True,
                                  get_cover=True,
                                  cover_as_data=True)

        # get save directory & filename
        try:
            path_to_book = self.gui.library_view.model().db.abspath(
                mi.id, True)
            book_file_name = self.gui.library_view.model(
            ).db.construct_file_name(mi.id)
        except Exception as e:
            print('Failed to get path and filename from book metadata')
            raise e

        if not di:
            try:
                # @todo: fix this line to get the base id part
                casanova_id = mi.identifiers['casanova']
            except AttributeError:
                print('There is no aaaarg attribute for this book')
            # download detail from site
            di = self.get_first_download_info(casanova_id)
        if di:
            book_file_name = book_file_name + di['type']
            start_casanova_download(Dispatcher(self.downloaded_ebook),
                                    self.gui.job_manager, self.gui, di['href'],
                                    book_file_name, path_to_book, mi.id)
            self.gui.status_bar.show_message(
                _('Downloading') + ' ' +
                book_file_name.decode('utf-8', 'ignore')
                if book_file_name else url.decode('utf-8', 'ignore'), 3000)
Exemplo n.º 10
0
 def download_scheduled_recipe(self, arg):
     func, args, desc, fmt, temp_files = \
             fetch_scheduled_recipe(arg)
     job = self.gui.job_manager.run_job(
             Dispatcher(self.scheduled_recipe_fetched), func, args=args, description=desc)
     self.conversion_jobs[job] = (temp_files, fmt, arg)
     self.gui.status_bar.show_message(_('Fetching news from ')+arg['title'], 2000)
Exemplo n.º 11
0
 def _start(self):
     start_casanova_upload(Dispatcher(self.added), self.gui.job_manager,
                           self.gui, self.title, self.authors,
                           self.description, self.one_liner, self.issues,
                           self.opf, self.file, self.mi, self.book_id)
     self.gui.status_bar.show_message(
         _('Adding') + ' ' + unicode(self.title), 3000)
Exemplo n.º 12
0
 def create_files(self):
     '''Creates files depending on user's settings'''
     xray_creator = self._get_books('Cannot create Files')
     if xray_creator:
         job = ThreadedJob('create_files', 'Creating Files', xray_creator.create_files_event,
                           ((self.gui.current_db.new_api,)), {}, Dispatcher(self.created_files))
         self.gui.job_manager.run_threaded_job(job)
Exemplo n.º 13
0
 def send_files(self):
     '''Sends files depending on user's settings'''
     xray_creator = self._get_books('Cannot send Files')
     if xray_creator:
         job = ThreadedJob('send_files', 'Sending Files to Device', xray_creator.send_files_event,
                           ((self.gui.current_db.new_api,)), {}, Dispatcher(self.sent_files))
         self.gui.job_manager.run_threaded_job(job)
Exemplo n.º 14
0
 def view_device_book(self, path):
     pt = PersistentTemporaryFile('_view_device_book' +
                                  os.path.splitext(path)[1])
     self.persistent_files.append(pt)
     pt.close()
     self.gui.device_manager.view_book(
         Dispatcher(self.book_downloaded_for_viewing), path, pt.name)
Exemplo n.º 15
0
    def queue_convert_jobs(self, jobs, changed, bad, rows, previous,
            converted_func, extra_job_args=[], rows_are_ids=False):
        for func, args, desc, fmt, id, temp_files in jobs:
            func, _, parts = func.partition(':')
            parts = {x for x in parts.split(';')}
            input_file = args[0]
            input_fmt = os.path.splitext(input_file)[1]
            core_usage = 1
            if input_fmt:
                input_fmt = input_fmt[1:]
                plugin = plugin_for_input_format(input_fmt)
                if plugin is not None:
                    core_usage = plugin.core_usage

            if id not in bad:
                job = self.gui.job_manager.run_job(Dispatcher(converted_func),
                                            func, args=args, description=desc,
                                            core_usage=core_usage)
                job.conversion_of_same_fmt = 'same_fmt' in parts
                job.manually_fine_tune_toc = 'manually_fine_tune_toc' in parts
                args = [temp_files, fmt, id]+extra_job_args
                self.conversion_jobs[job] = tuple(args)

        if changed:
            m = self.gui.library_view.model()
            if rows_are_ids:
                m.refresh_ids(rows)
            else:
                m.refresh_rows(rows)
            current = self.gui.library_view.currentIndex()
            self.gui.library_view.model().current_changed(current, previous)
Exemplo n.º 16
0
    def build_menus(self):
        if os.environ.get('CALIBRE_OVERRIDE_DATABASE_PATH', None):
            return
        db = self.gui.library_view.model().db
        locations = list(self.stats.locations(db))

        for ac in self.switch_actions:
            ac.setVisible(False)
        self.quick_menu.clear()
        self.qs_locations = [i[1] for i in locations]
        self.rename_menu.clear()
        self.delete_menu.clear()
        quick_actions, rename_actions, delete_actions = [], [], []
        for name, loc in locations:
            ac = self.quick_menu.addAction(
                name, Dispatcher(partial(self.switch_requested, loc)))
            ac.setStatusTip(_('Switch to: %s') % loc)
            quick_actions.append(ac)
            ac = self.rename_menu.addAction(
                name, Dispatcher(partial(self.rename_requested, name, loc)))
            rename_actions.append(ac)
            ac.setStatusTip(_('Rename: %s') % loc)
            ac = self.delete_menu.addAction(
                name, Dispatcher(partial(self.delete_requested, name, loc)))
            delete_actions.append(ac)
            ac.setStatusTip(_('Remove: %s') % loc)

        qs_actions = []
        for i, x in enumerate(locations[:len(self.switch_actions)]):
            name, loc = x
            ac = self.switch_actions[i]
            ac.setText(name)
            ac.setStatusTip(_('Switch to: %s') % loc)
            ac.setVisible(True)
            qs_actions.append(ac)

        self.quick_menu_action.setVisible(bool(locations))
        self.rename_menu_action.setVisible(bool(locations))
        self.delete_menu_action.setVisible(bool(locations))
        self.gui.location_manager.set_switch_actions(quick_actions,
                                                     rename_actions,
                                                     delete_actions,
                                                     qs_actions,
                                                     self.action_choose)
        # Allow the cloned actions in the OS X global menubar to update
        for a in (self.qaction, self.menuless_qaction):
            a.changed.emit()
Exemplo n.º 17
0
 def __call__(self, name, user_text, callback, function, *args, **kwargs):
     ' Run a job that blocks the GUI providing some feedback to the user '
     self.set_msg(user_text)
     job = LongJob(name, user_text,
                   Dispatcher(partial(self.job_done, callback)), function,
                   *args, **kwargs)
     job.start()
     self.start()
Exemplo n.º 18
0
    def create_jobs(self, job=None, install=False):
        if self.job_failed(job):
            return

        for data in self.metadata_list:
            title = data[-1].get('title')
            job = ThreadedJob(
                "WordDumb's dumb job", f'Generating Word Wise for {title}',
                do_job, (data, install), {},
                Dispatcher(partial(self.done, data=data, title=title)))
            self.gui.job_manager.run_threaded_job(job)
Exemplo n.º 19
0
 def download_metadata(self, ids=None, ensure_fields=None):
     if ids is None:
         rows = self.gui.library_view.selectionModel().selectedRows()
         if not rows or len(rows) == 0:
             return error_dialog(self.gui, _('Cannot download metadata'),
                         _('No books selected'), show=True)
         db = self.gui.library_view.model().db
         ids = [db.id(row.row()) for row in rows]
     from calibre.gui2.metadata.bulk_download import start_download
     start_download(self.gui, ids,
             Dispatcher(self.metadata_downloaded),
             ensure_fields=ensure_fields)
Exemplo n.º 20
0
    def build_menus(self):
        if os.environ.get('CALIBRE_OVERRIDE_DATABASE_PATH', None):
            return
        db = self.gui.library_view.model().db
        locations = list(self.stats.locations(db))

        for ac in self.switch_actions:
            ac.setVisible(False)
        self.quick_menu.clear()
        self.qs_locations = [i[1] for i in locations]
        self.rename_menu.clear()
        self.delete_menu.clear()
        quick_actions, rename_actions, delete_actions = [], [], []
        for name, loc in locations:
            ac = self.quick_menu.addAction(
                name, Dispatcher(partial(self.switch_requested, loc)))
            quick_actions.append(ac)
            ac = self.rename_menu.addAction(
                name, Dispatcher(partial(self.rename_requested, name, loc)))
            rename_actions.append(ac)
            ac = self.delete_menu.addAction(
                name, Dispatcher(partial(self.delete_requested, name, loc)))
            delete_actions.append(ac)

        qs_actions = []
        for i, x in enumerate(locations[:len(self.switch_actions)]):
            name, loc = x
            ac = self.switch_actions[i]
            ac.setText(name)
            ac.setVisible(True)
            qs_actions.append(ac)

        self.quick_menu_action.setVisible(bool(locations))
        self.rename_menu_action.setVisible(bool(locations))
        self.delete_menu_action.setVisible(bool(locations))
        self.gui.location_manager.set_switch_actions(quick_actions,
                                                     rename_actions,
                                                     delete_actions,
                                                     qs_actions,
                                                     self.action_choose)
Exemplo n.º 21
0
 def do_polish(self, book_id_map):
     d = Polish(self.gui.library_view.model().db, book_id_map, parent=self.gui)
     if d.exec_() == d.Accepted and d.jobs:
         show_reports = bool(d.show_reports.isChecked())
         for desc, data, book_id, base, is_orig in reversed(d.jobs):
             job = self.gui.job_manager.run_job(
                 Dispatcher(self.book_polished), 'gui_polish', args=(data,),
                 description=desc)
             job.polish_args = (book_id, base, data['files'], show_reports, is_orig)
         if d.jobs:
             self.gui.jobs_pointer.start()
             self.gui.status_bar.show_message(
                 _('Start polishing of %d book(s)') % len(d.jobs), 2000)
Exemplo n.º 22
0
    def parse(self):
        # get currently selected books
        rows = self.gui.library_view.selectionModel().selectedRows()
        if not rows or len(rows) == 0:
            return
        self.ids = list(map(self.gui.library_view.model().id, rows))
        if len(self.ids) == 0:
            return

        job = ThreadedJob('Generating Word Wise', 'Generating Word Wise',
                          do_job, (self.gui.current_db.new_api,
                                   self.ids, self.plugin_path), {},
                          Dispatcher(self.done))

        self.gui.job_manager.run_threaded_job(job)
        self.gui.status_bar.show_message("Generating Word Wise")
Exemplo n.º 23
0
 def download_ebook(self,
                    url='',
                    cookie_file=None,
                    filename='',
                    save_loc='',
                    add_to_lib=True,
                    tags=[]):
     if tags:
         if isinstance(tags, basestring):
             tags = tags.split(',')
     start_ebook_download(Dispatcher(self.downloaded_ebook),
                          self.job_manager, self, cookie_file, url,
                          filename, save_loc, add_to_lib, tags)
     self.status_bar.show_message(
         _('Downloading') + ' ' + filename.decode('utf-8', 'ignore')
         if filename else url.decode('utf-8', 'ignore'), 3000)
Exemplo n.º 24
0
    def scan_for_isbns(self):
        rows = self.gui.library_view.selectionModel().selectedRows()
        if not rows or len(rows) == 0:
            return error_dialog(self.gui, 'No rows selected',
                                'You must select one or more books to perform this action.', show=True)
        book_ids = self.gui.library_view.get_selected_ids()
        db = self.gui.library_view.model().db

        c = cfg.plugin_prefs[cfg.STORE_NAME]
        worker_threshold = c.get(cfg.KEY_WORKER_THRESHOLD, cfg.DEFAULT_STORE_VALUES[cfg.KEY_WORKER_THRESHOLD])
        if len(book_ids) > worker_threshold:
            # Run the extraction as a background job with workers
            QueueProgressDialog(self.gui, book_ids, self._queue_job, db)
        else:
            # For performance reasons, still do single book extraction as a threaded
            # job in-process
            start_extract_threaded(self.gui, book_ids, Dispatcher(self._scan_for_isbns_complete))
Exemplo n.º 25
0
 def download_ebook(self,
                    url='',
                    cookie_file=None,
                    filename='',
                    save_loc='',
                    add_to_lib=True,
                    tags=[],
                    create_browser=None):
     if tags:
         if isinstance(tags, string_or_bytes):
             tags = tags.split(',')
     start_ebook_download(Dispatcher(self.downloaded_ebook),
                          self.job_manager, self, cookie_file, url,
                          filename, save_loc, add_to_lib, tags,
                          create_browser)
     self.status_bar.show_message(
         _('Downloading') + ' ' +
         as_unicode(filename or url, errors='replace'), 3000)
Exemplo n.º 26
0
    def __init__(self):
        QAbstractTableModel.__init__(self)
        SearchQueryParser.__init__(self, ['all'])

        self.wait_icon = (QIcon(I('jobs.png')))
        self.running_icon = (QIcon(I('exec.png')))
        self.error_icon = (QIcon(I('dialog_error.png')))
        self.done_icon = (QIcon(I('ok.png')))

        self.jobs = []
        self.add_job = Dispatcher(self._add_job)
        self.server = Server(limit=int(config['worker_limit'] / 2.0),
                             enforce_cpu_limit=config['enforce_cpu_limit'])
        self.threaded_server = ThreadedJobServer()
        self.changed_queue = Queue()

        self.timer = QTimer(self)
        self.timer.timeout.connect(self.update, type=Qt.QueuedConnection)
        self.timer.start(1000)
Exemplo n.º 27
0
class ParseBook():
    def __init__(self, gui):
        self.gui = gui
        self.metadata_list = []

    def parse(self, create_ww=True, create_x=True):
        # get currently selected books
        rows = self.gui.library_view.selectionModel().selectedRows()
        if not rows or len(rows) == 0:
            return
        ids = list(map(self.gui.library_view.model().id, rows))
        if len(ids) == 0:
            return

        for book_id in ids:
            if (data := check_metadata(self.gui.current_db.new_api,
                                       book_id)) is None:
                continue
            self.metadata_list.append(data)

        if len(self.metadata_list) == 0:
            return

        for data in self.metadata_list:
            if data[-1]['wiki'] != 'en':
                create_ww = False
            title = data[-2].get('title')
            notif = []
            if create_ww:
                notif.append('Word Wise')
            if create_x:
                notif.append('X-Ray')
            notif = ' and '.join(notif)

            job = ThreadedJob(
                "WordDumb's dumb job", f'Generating {notif} for {title}',
                do_job, (data, create_ww, create_x), {},
                Dispatcher(partial(self.done, data=data,
                                   notif=f'{notif} generated for {title}')))
            self.gui.job_manager.run_threaded_job(job)

        self.gui.jobs_pointer.start()
Exemplo n.º 28
0
    def _view_books(self, rows):
        if not rows or len(rows) == 0:
            self._launch_viewer()
            return

        if not self._view_check(len(rows)):
            return

        if self.gui.current_view() is self.gui.library_view:
            ids = list(map(self.gui.library_view.model().id, rows))
            self._view_calibre_books(ids)
        else:
            paths = self.gui.current_view().model().paths(rows)
            for path in paths:
                pt = PersistentTemporaryFile('_viewer_'+\
                        os.path.splitext(path)[1])
                self.persistent_files.append(pt)
                pt.close()
                self.gui.device_manager.view_book(\
                        Dispatcher(self.book_downloaded_for_viewing),
                                              path, pt.name)
Exemplo n.º 29
0
    def convert_vtt_files(self):
        main_lang = self.main_lang_combo.currentData()
        if main_lang == '-':
            QMessageBox.about(self, 'Information',
                              'Select the main language before conversion.')
            return

        sub_lang = str(self.sub_lang_combo.currentData())
        # if user does not select sub_lang, set it to main_lang, so that when converting, it won't generate sub language.
        if sub_lang == '-':
            sub_lang = main_lang

        # convert to html
        if hasattr(self, 'cover_file_path'):
            cover_file_path = self.cover_file_path
        else:
            cover_file_path = None

        self.book_id = self.convert_to_html_add_to_library(
            self.vtt_dir, main_lang, sub_lang, cover_file_path)

        # add html to epub conversion job
        self.jobs, changed, bad = convert_single_ebook(
            self.gui,
            self.gui.library_view.model().db, [self.book_id], True,
            self.outputFmt)
        func, args, desc, fmt, id, temp_files = self.jobs[0]

        core_usage = 1
        plugin = plugin_for_input_format('html')
        if plugin is not None:
            core_usage = plugin.core_usage

        self.gui.job_manager.run_job(Dispatcher(self.converted_func),
                                     func,
                                     args=args,
                                     description=desc,
                                     core_usage=core_usage)

        self.close()
    def enqueue(self, account, downloader):
        prefs = self.prefs

        self.notify("Account: '%s'" % account[prefs.USERNAME])
        # downloader.login(account)

        func = 'arbitrary_n'
        # func = 'arbitrary'
        cpus = self.gui.job_manager.server.pool_size
        print "CPUs: %s" % (cpus)
        args = [
            'calibre_plugins.beam_ebooks_downloader.jobs',
            'do_obtain_new_books', (cpus, account)
        ]
        desc = 'Beam EBooks Downloader'
        job = self.gui.job_manager.run_job(Dispatcher(self._done),
                                           func,
                                           args=args,
                                           description=desc)
        print "Job: %s" % (job)

        self.notify("  Start parsing OPDS catalog")