From 6cd33e110eb00074e67e899a156e44e3edd31bdc Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 18 Dec 2017 08:00:18 +0530 Subject: [PATCH] Add a tweak in Preferences->Tweaks to exclude some fields when using the Edit metadata->Copy metadata/paste actions --- resources/default_tweaks.py | 7 +++++++ src/calibre/ebooks/metadata/book/base.py | 4 ++++ src/calibre/gui2/actions/edit_metadata.py | 8 +++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/resources/default_tweaks.py b/resources/default_tweaks.py index 3941cc5663..3233797037 100644 --- a/resources/default_tweaks.py +++ b/resources/default_tweaks.py @@ -560,3 +560,10 @@ cover_drop_exclude = () # new Saved search is shown in the Search bar. If you would like to have the # old Saved searches box with its two buttons back, set this tweak to True. show_saved_search_box = False + +#: Exclude fields when copy/pasting metadata +# You can ask calibre to not paste some metadata fields when using the +# Edit metadata->Copy metadata/Paste metadata actions. For example, +# exclude_fields_on_paste = ['cover', 'timestamp', '#mycolumn'] +# to prevent pasting of the cover, Date and custom column, mycolumn. +exclude_fields_on_paste = [] diff --git a/src/calibre/ebooks/metadata/book/base.py b/src/calibre/ebooks/metadata/book/base.py index 2c7e84f104..6983637e91 100644 --- a/src/calibre/ebooks/metadata/book/base.py +++ b/src/calibre/ebooks/metadata/book/base.py @@ -117,6 +117,10 @@ class Metadata(object): except: return True + def set_null(self, field): + null_val = copy.copy(NULL_VALUES.get(field)) + setattr(self, field, null_val) + def __getattribute__(self, field): _data = object.__getattribute__(self, '_data') if field in SIMPLE_GET: diff --git a/src/calibre/gui2/actions/edit_metadata.py b/src/calibre/gui2/actions/edit_metadata.py index 4ae0fcc2f7..ecd703df32 100644 --- a/src/calibre/gui2/actions/edit_metadata.py +++ b/src/calibre/gui2/actions/edit_metadata.py @@ -19,6 +19,7 @@ from calibre.gui2.actions import InterfaceAction from calibre.ebooks.metadata import authors_to_string from calibre.ebooks.metadata.book.base import Metadata from calibre.ebooks.metadata.opf2 import OPF, metadata_to_opf +from calibre.utils.config import tweaks from calibre.utils.date import is_date_undefined from calibre.utils.icu import sort_key from calibre.db.errors import NoSuchFormat @@ -141,7 +142,12 @@ class EditMetadataAction(InterfaceAction): data = bytes(md.data('application/calibre-book-metadata')) mi = OPF(BytesIO(data), populate_spine=False, read_toc=False, try_to_guess_cover=False).to_book_metadata() mi.application_id = mi.uuid_id = None - cover = md.imageData() + exclude = set(tweaks['exclude_fields_on_paste']) + paste_cover = 'cover' not in exclude + cover = md.imageData() if paste_cover else None + exclude.discard('cover') + for field in exclude: + mi.set_null(field) db = self.gui.current_db book_ids = {db.id(r.row()) for r in rows} for book_id in book_ids: