From ac1c9d52cb8ef0b034837ece1edcdbcd4574e0a9 Mon Sep 17 00:00:00 2001 From: GRiker Date: Sat, 9 Oct 2010 06:04:48 -0700 Subject: [PATCH 1/8] GwR patch adding get_all_user_metadata() --- src/calibre/ebooks/metadata/opf2.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/calibre/ebooks/metadata/opf2.py b/src/calibre/ebooks/metadata/opf2.py index 5c2477c3dc..dadca610ae 100644 --- a/src/calibre/ebooks/metadata/opf2.py +++ b/src/calibre/ebooks/metadata/opf2.py @@ -529,6 +529,14 @@ class OPF(object): # {{{ self.find_toc() self.read_user_metadata() + def get_all_user_metadata(self, make_copy): + ''' + return a dict containing all the custom field metadata associated with + the book. + ''' + self.read_user_metadata() + return self._user_metadata_ + def read_user_metadata(self): self._user_metadata_ = {} temp = Metadata('x', ['x']) From f99359a1628895d2dbd1e2ede7642b3c8166e1a5 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 11 Oct 2010 08:33:24 -0600 Subject: [PATCH 2/8] Use the title_sort tweak when sorting the books in the device view as well --- src/calibre/devices/usbms/books.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/calibre/devices/usbms/books.py b/src/calibre/devices/usbms/books.py index a267d18584..c8b2638690 100644 --- a/src/calibre/devices/usbms/books.py +++ b/src/calibre/devices/usbms/books.py @@ -6,6 +6,7 @@ __docformat__ = 'restructuredtext en' import os, re, time, sys +from calibre.ebooks.metadata import title_sort from calibre.ebooks.metadata.book.base import Metadata from calibre.devices.mime import mime_type_ext from calibre.devices.interface import BookList as _BookList @@ -54,7 +55,7 @@ class Book(Metadata): def title_sorter(self): doc = '''String to sort the title. If absent, title is returned''' def fget(self): - return re.sub('^\s*A\s+|^\s*The\s+|^\s*An\s+', '', self.title).rstrip() + return title_sort(self.title) return property(doc=doc, fget=fget) @dynamic_property From d6ec8fe01866faef77be9c1e0cabb69a98df8fe2 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 11 Oct 2010 08:35:20 -0600 Subject: [PATCH 3/8] Fix #7139 (error when I try to connect to iTunes device) --- src/calibre/devices/apple/driver.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/calibre/devices/apple/driver.py b/src/calibre/devices/apple/driver.py index 9465b789ae..6864570d52 100644 --- a/src/calibre/devices/apple/driver.py +++ b/src/calibre/devices/apple/driver.py @@ -13,7 +13,8 @@ from calibre.devices.errors import UserFeedback from calibre.devices.usbms.deviceconfig import DeviceConfig from calibre.devices.interface import DevicePlugin from calibre.ebooks.BeautifulSoup import BeautifulSoup -from calibre.ebooks.metadata import authors_to_string, MetaInformation +from calibre.ebooks.metadata import authors_to_string, MetaInformation, \ + title_sort from calibre.ebooks.metadata.book.base import Metadata from calibre.ebooks.metadata.epub import set_metadata from calibre.library.server.utils import strftime @@ -3128,6 +3129,9 @@ class Book(Metadata): See ebooks.metadata.book.base ''' def __init__(self,title,author): - Metadata.__init__(self, title, authors=[author]) + @property + def title_sorter(self): + return title_sort(self.title) + From 6d8acbb5c91f77f43b112030757bd77735d79e95 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 11 Oct 2010 08:49:59 -0600 Subject: [PATCH 4/8] Allow device driver to pass an error message to GUI when they dont support backloading --- src/calibre/devices/interface.py | 4 ++-- src/calibre/devices/usbms/device.py | 2 +- src/calibre/gui2/actions/add.py | 4 ++++ src/calibre/gui2/actions/add_to_library.py | 7 +------ src/calibre/gui2/device.py | 9 ++++++--- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/calibre/devices/interface.py b/src/calibre/devices/interface.py index 9c10de7d6c..75453c74b9 100644 --- a/src/calibre/devices/interface.py +++ b/src/calibre/devices/interface.py @@ -39,9 +39,9 @@ class DevicePlugin(Plugin): #: Whether the metadata on books can be set via the GUI. CAN_SET_METADATA = ['title', 'authors', 'collections'] - # Set this to True if the books on the device are files that the GUI can + # Set this to None if the books on the device are files that the GUI can # access in order to add the books from the device to the library - SUPPORTS_BACKLOADING = False + BACKLOADING_ERROR_MESSAGE = _('Cannot get files from this device') #: Path separator for paths to books on device path_sep = os.sep diff --git a/src/calibre/devices/usbms/device.py b/src/calibre/devices/usbms/device.py index cb26f6a50c..6fcfb9e7f0 100644 --- a/src/calibre/devices/usbms/device.py +++ b/src/calibre/devices/usbms/device.py @@ -96,7 +96,7 @@ class Device(DeviceConfig, DevicePlugin): # USB disk-based devices can see the book files on the device, so can # copy these back to the library - SUPPORTS_BACKLOADING = True + BACKLOADING_ERROR_MESSAGE = None def reset(self, key='-1', log_packets=False, report_progress=None, detected_device=None): diff --git a/src/calibre/gui2/actions/add.py b/src/calibre/gui2/actions/add.py index be1f8f4eaf..9eb197984e 100644 --- a/src/calibre/gui2/actions/add.py +++ b/src/calibre/gui2/actions/add.py @@ -235,6 +235,10 @@ class AddAction(InterfaceAction): self.gui.refresh_ondevice() def add_books_from_device(self, view, paths=None): + backloading_err = self.gui.device_manager.device.BACKLOADING_ERROR_MESSAGE + if backloading_err is not None: + return error_dialog(self.gui, _('Add to library'), backloading_err, + show=True) if paths is None: rows = view.selectionModel().selectedRows() if not rows or len(rows) == 0: diff --git a/src/calibre/gui2/actions/add_to_library.py b/src/calibre/gui2/actions/add_to_library.py index efdf645acb..05aea8f1dd 100644 --- a/src/calibre/gui2/actions/add_to_library.py +++ b/src/calibre/gui2/actions/add_to_library.py @@ -19,12 +19,7 @@ class AddToLibraryAction(InterfaceAction): self.qaction.triggered.connect(self.add_books_to_library) def location_selected(self, loc): - enabled = False - if loc != 'library': - if self.gui.device_manager.is_device_connected: - device = self.gui.device_manager.connected_device - if device is not None: - enabled = getattr(device, 'SUPPORTS_BACKLOADING', False) + enabled = loc != 'library' self.qaction.setEnabled(enabled) def add_books_to_library(self, *args): diff --git a/src/calibre/gui2/device.py b/src/calibre/gui2/device.py index 49bc5c0016..e662c6a5cc 100644 --- a/src/calibre/gui2/device.py +++ b/src/calibre/gui2/device.py @@ -794,13 +794,16 @@ class DeviceMixin(object): # {{{ mainlist, cardalist, cardblist = job.result self.memory_view.set_database(mainlist) self.memory_view.set_editable(self.device_manager.device.CAN_SET_METADATA, - self.device_manager.device.SUPPORTS_BACKLOADING) + self.device_manager.device.BACKLOADING_ERROR_MESSAGE + is None) self.card_a_view.set_database(cardalist) self.card_a_view.set_editable(self.device_manager.device.CAN_SET_METADATA, - self.device_manager.device.SUPPORTS_BACKLOADING) + self.device_manager.device.BACKLOADING_ERROR_MESSAGE + is None) self.card_b_view.set_database(cardblist) self.card_b_view.set_editable(self.device_manager.device.CAN_SET_METADATA, - self.device_manager.device.SUPPORTS_BACKLOADING) + self.device_manager.device.BACKLOADING_ERROR_MESSAGE + is None) self.sync_news() self.sync_catalogs() self.refresh_ondevice() From 645507516b2b1d972eeebb7eb38565e89b9f22c0 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 11 Oct 2010 08:59:33 -0600 Subject: [PATCH 5/8] Fix #7137 (Mail attachment) --- src/calibre/utils/smtp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calibre/utils/smtp.py b/src/calibre/utils/smtp.py index 230a983b74..77914bca3b 100644 --- a/src/calibre/utils/smtp.py +++ b/src/calibre/utils/smtp.py @@ -26,7 +26,7 @@ def create_mail(from_, to, subject, text=None, attachment_data=None, if text is not None: from email.mime.text import MIMEText - msg = MIMEText(text) + msg = MIMEText(text, 'plain', 'utf-8') outer.attach(msg) if attachment_data is not None: From 4def2fe4a202656aa4b028d7b667859a46e9c2ee Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 11 Oct 2010 09:45:39 -0600 Subject: [PATCH 6/8] Fix tab order in bulk edit metadata dialog --- resources/content_server/browse/browse.js | 1 - src/calibre/gui2/dialogs/metadata_bulk.ui | 43 ++++++++++++++++++----- 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/resources/content_server/browse/browse.js b/resources/content_server/browse/browse.js index 20b85df915..e2a8dc934a 100644 --- a/resources/content_server/browse/browse.js +++ b/resources/content_server/browse/browse.js @@ -105,7 +105,6 @@ function init_sort_combobox() { // }}} - function init() { $("#container").corner("30px"); $("#header").corner("30px"); diff --git a/src/calibre/gui2/dialogs/metadata_bulk.ui b/src/calibre/gui2/dialogs/metadata_bulk.ui index 60e24dbceb..3897d6dbf9 100644 --- a/src/calibre/gui2/dialogs/metadata_bulk.ui +++ b/src/calibre/gui2/dialogs/metadata_bulk.ui @@ -263,7 +263,7 @@ 20 - 00 + 0 @@ -357,13 +357,13 @@ from the value in the box - - Change title to title case - Force the title to be in title case. If both this and swap authors are checked, title and author are swapped before the title case is set + + Change title to title case + @@ -486,15 +486,15 @@ Future conversion of these books will use the default settings. - - Enter the what you are looking for, either plain text or a regular expression, depending on the mode - 100 0 + + Enter the what you are looking for, either plain text or a regular expression, depending on the mode + @@ -656,6 +656,14 @@ nothing should be put between the original text and the inserted text true + + + 0 + 0 + 122 + 34 + + @@ -733,14 +741,33 @@ nothing should be put between the original text and the inserted text author_sort rating publisher - tag_editor_button tags + tag_editor_button remove_tags + remove_all_tags series + clear_series autonumber_series + series_numbering_restarts + series_start_number remove_format + remove_conversion_settings swap_title_and_author + change_title_to_title_case button_box + central_widget + search_field + search_mode + search_for + case_sensitive + replace_with + replace_func + destination_field + replace_mode + comma_separated + scrollArea11 + test_text + test_result From bd9d9ecceb05fad77566d8662b1b09ffc60e77ff Mon Sep 17 00:00:00 2001 From: GRiker Date: Mon, 11 Oct 2010 08:50:37 -0700 Subject: [PATCH 7/8] GwR add custom BACKLOADING_ERROR_MESSAGE --- src/calibre/devices/apple/driver.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/calibre/devices/apple/driver.py b/src/calibre/devices/apple/driver.py index 6864570d52..9ad3cf3e08 100644 --- a/src/calibre/devices/apple/driver.py +++ b/src/calibre/devices/apple/driver.py @@ -97,6 +97,9 @@ class ITUNES(DriverBase): OPEN_FEEDBACK_MESSAGE = _( 'Apple device detected, launching iTunes, please wait ...') + BACKLOADING_ERROR_MESSAGE = _( + "Cannot copy books directly from iDevice. " + "Drag from iTunes Library to desktop, then add to calibre's Library window.") # Product IDs: # 0x1291 iPod Touch From 310b5c34b74a24c495359cc2b35c061abd21e580 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 11 Oct 2010 10:18:47 -0600 Subject: [PATCH 8/8] ... --- src/calibre/utils/smtp.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/calibre/utils/smtp.py b/src/calibre/utils/smtp.py index 77914bca3b..b8b46a96cb 100644 --- a/src/calibre/utils/smtp.py +++ b/src/calibre/utils/smtp.py @@ -11,6 +11,7 @@ This module implements a simple commandline SMTP client that supports: import sys, traceback, os from email import encoders +from calibre import isbytestring def create_mail(from_, to, subject, text=None, attachment_data=None, attachment_type=None, attachment_name=None): @@ -26,7 +27,10 @@ def create_mail(from_, to, subject, text=None, attachment_data=None, if text is not None: from email.mime.text import MIMEText - msg = MIMEText(text, 'plain', 'utf-8') + if isbytestring(text): + msg = MIMEText(text) + else: + msg = MIMEText(text, 'plain', 'utf-8') outer.attach(msg) if attachment_data is not None: