Ejemplo n.º 1
0
    def download(self):
        rows = self.table.rowCount()

        progress = QProgressDialog("Downloading books...", "Abort download", 0,
                                   rows, self)
        progress.setWindowModality(Qt.WindowModal)
        progress.show()

        to_download = [self.table.item(row, 2).text() for row in range(rows) if
                       self.table.item(row, 0).checkState() == Qt.Checked]

        for i, book in enumerate(to_download):
            progress.setValue(i)
            book_id = self.feed.download(str(book))
            if not book_id:
                QMessageBox.critical(self, 'Error', 'Could not download the '
                                     'book')
            elif book_id != -1:
                book = Book(book_id)
                insert_library(book)

            if progress.wasCanceled():
                break

        progress.setValue(rows)
        progress.close()
        self.parent().library.refresh()
Ejemplo n.º 2
0
    def open_book(self):
        book_path = QFileDialog.getOpenFileName(self, u'打开Epub格式电子书', ".",
                                                "(*.epub)")

        print u"in open_book, book_name is:" + str(book_path)
        print u"in open_book, bookdata path:" + str(LIBRARY_DIR)
        print os.path.dirname(str(book_path))

        if os.path.dirname(str(book_path)) + os.sep != str(LIBRARY_DIR):
            shutil.copy(str(book_path), LIBRARY_DIR)

        file_name = os.path.basename(str(book_path))
        book_id = file_name.split('.epub')[0]
        book = Book(book_id)
        insert_library(book)
        self.library.refresh()
Ejemplo n.º 3
0
    def link_clicked(self, url):
        surl = str(url.toString())
        if surl.endswith('.epub'):
            progress = QProgressDialog("Downloding the book...", "Abort", 0, -1,
                                       self)
            progress.show()
            book_id = FeedBooks().download(surl[:-5])
            progress.close()
            if not book_id:
                QMessageBox.critical(self, 'Error', 'Could not download the '
                                     'book')
            elif book_id != -1:
                book = Book(book_id)
                insert_library(book)
                self.parent().library.refresh()
            else:
                book_id = surl[surl.rfind('/')+1:-5]

            if book_id:
                self.load_book(book_id)
        else:
            webbrowser.open_new_tab(surl)