From 534847a80a61a1e4a8c8ea43a337c506700f837e Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 17 Jun 2010 08:01:40 -0600 Subject: [PATCH 1/4] ... --- src/calibre/gui2/search_box.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calibre/gui2/search_box.py b/src/calibre/gui2/search_box.py index 853472050e..35bf7374a0 100644 --- a/src/calibre/gui2/search_box.py +++ b/src/calibre/gui2/search_box.py @@ -23,7 +23,7 @@ class SearchLineEdit(QLineEdit): focus_out = pyqtSignal(object) def keyPressEvent(self, event): - self.key_pressed.emit(object) + self.key_pressed.emit(event) QLineEdit.keyPressEvent(self, event) def mouseReleaseEvent(self, event): From f712c3cc3bb768038f0e77a27945ba2c1b12c097 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 17 Jun 2010 08:40:20 -0600 Subject: [PATCH 2/4] Fix #5855 (Import of ePub book with multiple entries on a single Subject Meta line needs cleanup) --- src/calibre/ebooks/metadata/opf2.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/calibre/ebooks/metadata/opf2.py b/src/calibre/ebooks/metadata/opf2.py index 3367ab14f6..46924cad1f 100644 --- a/src/calibre/ebooks/metadata/opf2.py +++ b/src/calibre/ebooks/metadata/opf2.py @@ -736,7 +736,9 @@ class OPF(object): def fget(self): ans = [] for tag in self.tags_path(self.metadata): - ans.append(self.get_text(tag)) + text = self.get_text(tag) + if text and text.strip(): + ans.extend([x.strip() for x in text.split(',')]) return ans def fset(self, val): From 54af6259bc6b7efa2d2daae4e2840e90ce565bd1 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 17 Jun 2010 10:01:48 -0600 Subject: [PATCH 3/4] Make author sort changes backward compatible --- src/calibre/ebooks/metadata/__init__.py | 4 ++++ src/calibre/library/database2.py | 17 +++++++++++++++++ src/calibre/library/schema_upgrades.py | 25 +------------------------ src/calibre/library/sqlite.py | 5 ++++- 4 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/calibre/ebooks/metadata/__init__.py b/src/calibre/ebooks/metadata/__init__.py index 8caca1f261..88d971ce4d 100644 --- a/src/calibre/ebooks/metadata/__init__.py +++ b/src/calibre/ebooks/metadata/__init__.py @@ -28,10 +28,14 @@ def authors_to_string(authors): else: return '' +_bracket_pat = re.compile(r'[\[({].*?[})\]]') def author_to_author_sort(author): + if not author: + return '' method = tweaks['author_sort_copy_method'] if method == 'copy' or (method == 'comma' and ',' in author): return author + author = _bracket_pat.sub('', author).strip() tokens = author.split() tokens = tokens[-1:] + tokens[:-1] if len(tokens) > 1: diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index c7830187df..fe4aac12b5 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -136,6 +136,23 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): self.initialize_dynamic() def initialize_dynamic(self): + self.conn.executescript(''' + DROP TRIGGER IF EXISTS author_insert_trg; + CREATE TEMP TRIGGER author_insert_trg + AFTER INSERT ON authors + BEGIN + UPDATE authors SET sort=author_to_author_sort(NEW.name) WHERE id=NEW.id; + END; + DROP TRIGGER IF EXISTS author_update_trg; + CREATE TEMP TRIGGER author_update_trg + BEFORE UPDATE ON authors + BEGIN + UPDATE authors SET sort=author_to_author_sort(NEW.name) + WHERE id=NEW.id AND name <> NEW.name; + END; + ''') + self.conn.execute( + 'UPDATE authors SET sort=author_to_author_sort(name) WHERE sort IS NULL') self.conn.executescript(u''' CREATE TEMP VIEW IF NOT EXISTS tag_browser_news AS SELECT DISTINCT id, diff --git a/src/calibre/library/schema_upgrades.py b/src/calibre/library/schema_upgrades.py index a8ffd9cde4..1ba650f6fd 100644 --- a/src/calibre/library/schema_upgrades.py +++ b/src/calibre/library/schema_upgrades.py @@ -385,28 +385,5 @@ class SchemaUpgrade(object): if table.startswith('custom_column_') and link_table in tables: create_cust_tag_browser_view(table, link_table) - from calibre.ebooks.metadata import author_to_author_sort + self.conn.execute('UPDATE authors SET sort=author_to_author_sort(name)') - aut = self.conn.get('SELECT id, name FROM authors'); - records = [] - for (id, author) in aut: - records.append((id, author.replace('|', ','))) - for id,author in records: - self.conn.execute('UPDATE authors SET sort=? WHERE id=?', - (author_to_author_sort(author.replace('|', ',')).strip(), id)) - self.conn.commit() - self.conn.executescript(''' - DROP TRIGGER IF EXISTS author_insert_trg; - CREATE TRIGGER author_insert_trg - AFTER INSERT ON authors - BEGIN - UPDATE authors SET sort=author_to_author_sort(NEW.name) WHERE id=NEW.id; - END; - DROP TRIGGER IF EXISTS author_update_trg; - CREATE TRIGGER author_update_trg - BEFORE UPDATE ON authors - BEGIN - UPDATE authors SET sort=author_to_author_sort(NEW.name) - WHERE id=NEW.id AND name <> NEW.name; - END; - ''') diff --git a/src/calibre/library/sqlite.py b/src/calibre/library/sqlite.py index 7e0458fba4..85954f6e0f 100644 --- a/src/calibre/library/sqlite.py +++ b/src/calibre/library/sqlite.py @@ -94,6 +94,9 @@ class Connection(sqlite.Connection): return ans[0] return ans.fetchall() +def _author_to_author_sort(x): + if not x: return '' + return author_to_author_sort(x.replace('|', ',')) class DBThread(Thread): @@ -121,7 +124,7 @@ class DBThread(Thread): else: self.conn.create_function('title_sort', 1, title_sort) self.conn.create_function('author_to_author_sort', 1, - lambda x: author_to_author_sort(x.replace('|', ','))) + _author_to_author_sort) self.conn.create_function('uuid4', 0, lambda : str(uuid.uuid4())) # Dummy functions for dynamically created filters self.conn.create_function('books_list_filter', 1, lambda x: 1) From 8974401532a7b3345e101bac39d947b96f65b0d6 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 17 Jun 2010 10:44:46 -0600 Subject: [PATCH 4/4] Fix #5858 (Can not access preferences in version 0.7.2) --- src/calibre/gui2/init.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/calibre/gui2/init.py b/src/calibre/gui2/init.py index a3c51c287f..699978a92f 100644 --- a/src/calibre/gui2/init.py +++ b/src/calibre/gui2/init.py @@ -163,8 +163,7 @@ class ToolbarMixin(object): # {{{ self.convert_menu = cm pm = QMenu() - ap = self.action_preferences - pm.addAction(ap) + pm.addAction(QIcon(I('config.svg')), _('Preferences'), self.do_config) pm.addAction(QIcon(I('wizard.svg')), _('Run welcome wizard'), self.run_wizard) self.action_preferences.setMenu(pm)