mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix #1334 (Adding Books via Add button in meta-data dialog)
This commit is contained in:
parent
26a1562d48
commit
9902b76b68
@ -14,6 +14,7 @@ from calibre import __author__, islinux, iswindows, isosx
|
|||||||
from calibre.startup import get_lang
|
from calibre.startup import get_lang
|
||||||
from calibre.utils.config import Config, ConfigProxy, dynamic
|
from calibre.utils.config import Config, ConfigProxy, dynamic
|
||||||
import calibre.resources as resources
|
import calibre.resources as resources
|
||||||
|
from calibre.ebooks.html import gui_main as html2oeb
|
||||||
|
|
||||||
NONE = QVariant() #: Null value to return from the data function of item models
|
NONE = QVariant() #: Null value to return from the data function of item models
|
||||||
|
|
||||||
@ -388,6 +389,14 @@ def pixmap_to_data(pixmap, format='JPEG'):
|
|||||||
pixmap.save(buf, format)
|
pixmap.save(buf, format)
|
||||||
return str(ba.data())
|
return str(ba.data())
|
||||||
|
|
||||||
|
html_pat = re.compile(r'\.x{0,1}htm(l{0,1})\s*$', re.IGNORECASE)
|
||||||
|
def import_format(path):
|
||||||
|
if html_pat.search(path) is not None:
|
||||||
|
try:
|
||||||
|
return html2oeb(path), 'zip'
|
||||||
|
except:
|
||||||
|
traceback.print_exc()
|
||||||
|
return None, None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from calibre.utils.single_qt_application import SingleApplication
|
from calibre.utils.single_qt_application import SingleApplication
|
||||||
|
@ -11,7 +11,7 @@ from PyQt4.QtGui import QPixmap, QListWidgetItem, QErrorMessage, QDialog
|
|||||||
|
|
||||||
|
|
||||||
from calibre.gui2 import qstring_to_unicode, error_dialog, file_icon_provider, \
|
from calibre.gui2 import qstring_to_unicode, error_dialog, file_icon_provider, \
|
||||||
choose_files, pixmap_to_data, choose_images
|
choose_files, pixmap_to_data, choose_images, import_format
|
||||||
from calibre.gui2.dialogs.metadata_single_ui import Ui_MetadataSingleDialog
|
from calibre.gui2.dialogs.metadata_single_ui import Ui_MetadataSingleDialog
|
||||||
from calibre.gui2.dialogs.fetch_metadata import FetchMetadata
|
from calibre.gui2.dialogs.fetch_metadata import FetchMetadata
|
||||||
from calibre.gui2.dialogs.tag_editor import TagEditor
|
from calibre.gui2.dialogs.tag_editor import TagEditor
|
||||||
@ -84,6 +84,9 @@ class MetadataSingleDialog(QDialog, Ui_MetadataSingleDialog):
|
|||||||
QErrorMessage(self.window).showMessage("You do not have "+\
|
QErrorMessage(self.window).showMessage("You do not have "+\
|
||||||
"permission to read the file: " + _file)
|
"permission to read the file: " + _file)
|
||||||
continue
|
continue
|
||||||
|
nf = import_format(_file)[0]
|
||||||
|
if nf is not None:
|
||||||
|
_file = nf
|
||||||
size = os.stat(_file).st_size
|
size = os.stat(_file).st_size
|
||||||
ext = os.path.splitext(_file)[1].lower()
|
ext = os.path.splitext(_file)[1].lower()
|
||||||
if '.' in ext:
|
if '.' in ext:
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
import os, sys, textwrap, collections, traceback, time, re
|
import os, sys, textwrap, collections, traceback, time
|
||||||
from xml.parsers.expat import ExpatError
|
from xml.parsers.expat import ExpatError
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from PyQt4.QtCore import Qt, SIGNAL, QObject, QCoreApplication, QUrl, QTimer
|
from PyQt4.QtCore import Qt, SIGNAL, QObject, QCoreApplication, QUrl, QTimer
|
||||||
@ -21,7 +21,7 @@ from calibre.gui2 import APP_UID, warning_dialog, choose_files, error_dialog, \
|
|||||||
pixmap_to_data, choose_dir, ORG_NAME, \
|
pixmap_to_data, choose_dir, ORG_NAME, \
|
||||||
set_sidebar_directories, Dispatcher, \
|
set_sidebar_directories, Dispatcher, \
|
||||||
SingleApplication, Application, available_height, \
|
SingleApplication, Application, available_height, \
|
||||||
max_available_height, config, info_dialog
|
max_available_height, config, info_dialog, import_format
|
||||||
from calibre.gui2.cover_flow import CoverFlow, DatabaseImages, pictureflowerror
|
from calibre.gui2.cover_flow import CoverFlow, DatabaseImages, pictureflowerror
|
||||||
from calibre.library.database import LibraryDatabase
|
from calibre.library.database import LibraryDatabase
|
||||||
from calibre.gui2.dialogs.scheduler import Scheduler
|
from calibre.gui2.dialogs.scheduler import Scheduler
|
||||||
@ -43,7 +43,6 @@ from calibre.gui2.dialogs.choose_format import ChooseFormatDialog
|
|||||||
from calibre.gui2.dialogs.book_info import BookInfo
|
from calibre.gui2.dialogs.book_info import BookInfo
|
||||||
from calibre.ebooks.metadata.meta import set_metadata
|
from calibre.ebooks.metadata.meta import set_metadata
|
||||||
from calibre.ebooks.metadata import MetaInformation
|
from calibre.ebooks.metadata import MetaInformation
|
||||||
from calibre.ebooks.html import gui_main as html2oeb
|
|
||||||
from calibre.ebooks import BOOK_EXTENSIONS
|
from calibre.ebooks import BOOK_EXTENSIONS
|
||||||
from calibre.library.database2 import LibraryDatabase2, CoverCache
|
from calibre.library.database2 import LibraryDatabase2, CoverCache
|
||||||
from calibre.parallel import JobKilled
|
from calibre.parallel import JobKilled
|
||||||
@ -571,19 +570,13 @@ class Main(MainWindow, Ui_MainWindow):
|
|||||||
|
|
||||||
if not to_device:
|
if not to_device:
|
||||||
model = self.library_view.model()
|
model = self.library_view.model()
|
||||||
html_pat = re.compile(r'\.x{0,1}htm(l{0,1})\s*$', re.IGNORECASE)
|
|
||||||
paths = list(paths)
|
paths = list(paths)
|
||||||
for i, path in enumerate(paths):
|
for i, path in enumerate(paths):
|
||||||
if html_pat.search(path) is not None:
|
npath, fmt = import_format(path)
|
||||||
try:
|
if npath is not None:
|
||||||
paths[i] = html2oeb(path)
|
paths[i] = npath
|
||||||
except:
|
formats[i] = fmt
|
||||||
traceback.print_exc()
|
|
||||||
continue
|
|
||||||
if paths[i] is None:
|
|
||||||
paths[i] = path
|
|
||||||
else:
|
|
||||||
formats[i] = 'zip'
|
|
||||||
duplicates, number_added = model.add_books(paths, formats, metadata)
|
duplicates, number_added = model.add_books(paths, formats, metadata)
|
||||||
if duplicates:
|
if duplicates:
|
||||||
files = _('<p>Books with the same title as the following already exist in the database. Add them anyway?<ul>')
|
files = _('<p>Books with the same title as the following already exist in the database. Add them anyway?<ul>')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user