From 60b5d3853fc41cd17111287bfa2fff9b6bcab096 Mon Sep 17 00:00:00 2001 From: Hiroshi Miura Date: Fri, 14 Jan 2011 07:24:07 +0900 Subject: [PATCH 01/26] fix nikkei_sub economy --- resources/recipes/nikkei_sub_economy.recipe | 3 +++ 1 file changed, 3 insertions(+) diff --git a/resources/recipes/nikkei_sub_economy.recipe b/resources/recipes/nikkei_sub_economy.recipe index 2dd8f1add8..8e7a68dfe7 100644 --- a/resources/recipes/nikkei_sub_economy.recipe +++ b/resources/recipes/nikkei_sub_economy.recipe @@ -27,6 +27,9 @@ class NikkeiNet_sub_economy(BasicNewsRecipe): {'class':"JSID_basePageMove JSID_baseAsyncSubmit cmn-form_area JSID_optForm_utoken"}, {'class':"cmn-article_keyword cmn-clearfix"}, {'class':"cmn-print_headline cmn-clearfix"}, + {'class':"cmn-article_list"}, + dict(id="ABOUT-NIKKEI"), + {'class':"cmn-sub_market"}, ] remove_tags_after = {'class':"cmn-pr_list"} From a21bf30ff8207ec9a4e644d1ffbfcbee58a346c6 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sun, 16 Jan 2011 08:41:16 +0000 Subject: [PATCH 02/26] 1) finish JSON-storage of template function source code 2) fix for #8388. This fix was chosen because it emulates the behavior in 0.7.38, where get_metadata returned empty author lists --- .../gui2/preferences/template_functions.py | 15 +++++++++++++-- src/calibre/library/database2.py | 5 ++++- src/calibre/library/sqlite.py | 2 +- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/calibre/gui2/preferences/template_functions.py b/src/calibre/gui2/preferences/template_functions.py index 2e16b0f4c3..8ffd65b2b5 100644 --- a/src/calibre/gui2/preferences/template_functions.py +++ b/src/calibre/gui2/preferences/template_functions.py @@ -5,7 +5,7 @@ __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' __docformat__ = 'restructuredtext en' -import traceback +import json, traceback from calibre.gui2 import error_dialog from calibre.gui2.preferences import ConfigWidgetBase, test_widget @@ -73,6 +73,12 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): self.textBrowser.setHtml(help_text) def initialize(self): + try: + with open(P('template-functions.json'), 'rb') as f: + self.builtin_source_dict = json.load(f, encoding='utf-8') + except: + self.builtin_source_dict = {} + self.funcs = formatter_functions.get_functions() self.builtins = formatter_functions.get_builtins() @@ -179,8 +185,13 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): func = self.funcs[txt] self.argument_count.setValue(func.arg_count) self.documentation.setText(func.doc) - self.program.setPlainText(func.program_text) if txt in self.builtins: + if hasattr(func, 'program_text'): + self.program.setPlainText(func.program_text) + elif txt in self.builtin_source_dict: + self.program.setPlainText(self.builtin_source_dict[txt]) + else: + self.program.setPlainText(_('function source code not available')) self.documentation.setReadOnly(True) self.argument_count.setReadOnly(True) self.program.setReadOnly(True) diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index 3a2109e01e..df094347b8 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -690,7 +690,10 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): mi = Metadata(None) aut_list = row[fm['au_map']] - aut_list = [p.split(':::') for p in aut_list.split(':#:')] + if not aut_list: + aut_list = [] + else: + aut_list = [p.split(':::') for p in aut_list.split(':#:')] aum = [] aus = {} for (author, author_sort) in aut_list: diff --git a/src/calibre/library/sqlite.py b/src/calibre/library/sqlite.py index 83f19b8711..622d6b8459 100644 --- a/src/calibre/library/sqlite.py +++ b/src/calibre/library/sqlite.py @@ -100,7 +100,7 @@ class AumSortedConcatenate(object): keys = self.ans.keys() l = len(keys) if l == 0: - return 'Unknown:::Unknown' + return None if l == 1: return self.ans[keys[0]] return ':#:'.join([self.ans[v] for v in sorted(keys)]) From e0b2d0b62a6b1f4c4a2f37cdcdffa5e1744b892b Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sun, 16 Jan 2011 10:34:05 +0000 Subject: [PATCH 03/26] Add function documentation to template editing dialog (F2 on a composite column) --- src/calibre/gui2/dialogs/template_dialog.py | 40 +++++++++- src/calibre/gui2/dialogs/template_dialog.ui | 81 ++++++++++++++++----- 2 files changed, 103 insertions(+), 18 deletions(-) diff --git a/src/calibre/gui2/dialogs/template_dialog.py b/src/calibre/gui2/dialogs/template_dialog.py index 60d4025ef9..62accdc842 100644 --- a/src/calibre/gui2/dialogs/template_dialog.py +++ b/src/calibre/gui2/dialogs/template_dialog.py @@ -3,8 +3,11 @@ __copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net' __docformat__ = 'restructuredtext en' __license__ = 'GPL v3' +import json + from PyQt4.Qt import Qt, QDialog, QDialogButtonBox from calibre.gui2.dialogs.template_dialog_ui import Ui_TemplateDialog +from calibre.utils.formatter_functions import formatter_functions class TemplateDialog(QDialog, Ui_TemplateDialog): @@ -17,9 +20,44 @@ class TemplateDialog(QDialog, Ui_TemplateDialog): self.setWindowFlags(self.windowFlags()&(~Qt.WindowContextHelpButtonHint)) self.setWindowIcon(icon) + self.textbox.setTabStopWidth(10) + self.source_code.setTabStopWidth(10) + self.documentation.setReadOnly(True) + self.source_code.setReadOnly(True) + if text is not None: self.textbox.setPlainText(text) - self.textbox.setTabStopWidth(50) self.buttonBox.button(QDialogButtonBox.Ok).setText(_('&OK')) self.buttonBox.button(QDialogButtonBox.Cancel).setText(_('&Cancel')) + try: + with open(P('template-functions.json'), 'rb') as f: + self.builtin_source_dict = json.load(f, encoding='utf-8') + except: + self.builtin_source_dict = {} + + self.funcs = formatter_functions.get_functions() + self.builtins = formatter_functions.get_builtins() + + func_names = sorted(self.funcs) + self.function.clear() + self.function.addItem('') + self.function.addItems(func_names) + self.function.setCurrentIndex(0) + self.function.currentIndexChanged[str].connect(self.function_changed) + + print self.textbox.tabStopWidth() + print self.source_code.tabStopWidth() + + def function_changed(self, toWhat): + name = unicode(toWhat) + self.source_code.clear() + self.documentation.clear() + if name in self.funcs: + self.documentation.setPlainText(self.funcs[name].doc) + if name in self.builtins: + if name in self.builtin_source_dict: + self.source_code.setPlainText(self.builtin_source_dict[name]) + else: + self.source_code.setPlainText(self.funcs[name].program_text) + diff --git a/src/calibre/gui2/dialogs/template_dialog.ui b/src/calibre/gui2/dialogs/template_dialog.ui index a30d6ef273..e1980a8397 100644 --- a/src/calibre/gui2/dialogs/template_dialog.ui +++ b/src/calibre/gui2/dialogs/template_dialog.ui @@ -6,8 +6,8 @@ 0 0 - 500 - 235 + 588 + 546 @@ -19,21 +19,68 @@ Edit Comments - - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + Function name: + + + + + + + + + + Documentation: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + + + Python code: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + + + + 16777215 + 75 + + + + + + + + + + From 4a9e8bcb2fd0d60438e3265defb358891de6bc75 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sun, 16 Jan 2011 10:48:43 +0000 Subject: [PATCH 04/26] Remove some print statements. --- src/calibre/gui2/dialogs/template_dialog.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/calibre/gui2/dialogs/template_dialog.py b/src/calibre/gui2/dialogs/template_dialog.py index 62accdc842..174056ef80 100644 --- a/src/calibre/gui2/dialogs/template_dialog.py +++ b/src/calibre/gui2/dialogs/template_dialog.py @@ -46,9 +46,6 @@ class TemplateDialog(QDialog, Ui_TemplateDialog): self.function.setCurrentIndex(0) self.function.currentIndexChanged[str].connect(self.function_changed) - print self.textbox.tabStopWidth() - print self.source_code.tabStopWidth() - def function_changed(self, toWhat): name = unicode(toWhat) self.source_code.clear() From 5c4154bb0d37a273e4925c2daa4dc15b4e9f752b Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sun, 16 Jan 2011 11:26:34 +0000 Subject: [PATCH 05/26] Make date.format_date render UNDEFINED_DATE as ''. This makes composite columns and templates behave in the same fashion as the GUI has for some time. --- src/calibre/utils/date.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/calibre/utils/date.py b/src/calibre/utils/date.py index f025a0c9bf..2551b90788 100644 --- a/src/calibre/utils/date.py +++ b/src/calibre/utils/date.py @@ -148,6 +148,9 @@ def format_date(dt, format, assume_utc=False, as_utc=False): if len(mo.group(0)) == 2: return '%02d'%(dt.year % 100) return '%04d'%dt.year + if dt == UNDEFINED_DATE: + return '' + format = re.sub('d{1,4}', format_day, format) format = re.sub('M{1,4}', format_month, format) return re.sub('yyyy|yy', format_year, format) From e131f99db8e5a80a68e4e28a152848effb7ece76 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 16 Jan 2011 09:18:37 -0700 Subject: [PATCH 06/26] Cleanup layout of bulk metadata edit dialog --- src/calibre/gui2/dialogs/metadata_bulk.ui | 236 +++++++++++----------- 1 file changed, 115 insertions(+), 121 deletions(-) diff --git a/src/calibre/gui2/dialogs/metadata_bulk.ui b/src/calibre/gui2/dialogs/metadata_bulk.ui index 9240cd1af8..d52bc2cb89 100644 --- a/src/calibre/gui2/dialogs/metadata_bulk.ui +++ b/src/calibre/gui2/dialogs/metadata_bulk.ui @@ -75,13 +75,31 @@ - - - - A&utomatically set author sort + + + + true + + + + + + A&utomatically set author sort + + + + + + + &Swap title and author + + + + + @@ -95,7 +113,7 @@ - + Specify how the author(s) of this book should be sorted. For example Charles Dickens should be sorted as Dickens, Charles. @@ -115,7 +133,7 @@ - + Rating of this book. 0-5 stars @@ -156,7 +174,7 @@ - + true @@ -220,7 +238,7 @@ Check this box to remove all tags from the books. - Remove all + Remove &all @@ -241,52 +259,35 @@ - - - - - List of known series. You can add new series. - - - List of known series. You can add new series. - - - true - - - QComboBox::InsertAlphabetically - - - QComboBox::AdjustToContents - - - - - - - If checked, the series will be cleared - - - Clear series - - - - - - - Qt::Horizontal - - - - 20 - 0 - - - - - + + + List of known series. You can add new series. + + + List of known series. You can add new series. + + + true + + + QComboBox::InsertAlphabetically + + + QComboBox::AdjustToContents + + - + + + + If checked, the series will be cleared + + + &Clear series + + + + @@ -297,7 +298,7 @@ you selected them. So if you selected Book A and then Book B, Book A will have series number 1 and Book B series number 2. - Automatically number books in this series + &Automatically number books in this series @@ -312,7 +313,7 @@ for that series. Checking this box will tell calibre to start numbering from the value in the box - Force numbers to start with + &Force numbers to start with: @@ -332,19 +333,6 @@ from the value in the box - - - - Qt::Horizontal - - - - 20 - 10 - - - - @@ -358,59 +346,56 @@ from the value in the box - - - - - - true - - - - - - - &Swap title and author - - - - - - - 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 - - - - - - - Remove stored conversion settings for the selected books. - -Future conversion of these books will use the default settings. - - - Remove &stored conversion settings for the selected books - - - - - - - Qt::Vertical - - + + - 20 - 40 + 120 + 16777215 - + - + + + + + + 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 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Remove stored conversion settings for the selected books. + +Future conversion of these books will use the default settings. + + + Remove &stored conversion settings for the selected books + + + + + + Change &cover @@ -440,6 +425,19 @@ Future conversion of these books will use the default settings. + + + + Qt::Vertical + + + + 20 + 40 + + + + @@ -902,14 +900,10 @@ not multiple and the destination field is multiple 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 search_field search_mode From b83b89ce7437a8e0b7547cf6ac8a27112ee243ae Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 16 Jan 2011 10:09:14 -0700 Subject: [PATCH 07/26] Fix #7568 (Allow bulk editing of Published date) --- src/calibre/gui2/dialogs/metadata_bulk.py | 31 ++- src/calibre/gui2/dialogs/metadata_bulk.ui | 108 ++++++-- src/calibre/gui2/dialogs/metadata_single.py | 13 +- src/calibre/gui2/dialogs/metadata_single.ui | 287 ++++++++++---------- 4 files changed, 274 insertions(+), 165 deletions(-) diff --git a/src/calibre/gui2/dialogs/metadata_bulk.py b/src/calibre/gui2/dialogs/metadata_bulk.py index 5ea8f00148..da6e92c26a 100644 --- a/src/calibre/gui2/dialogs/metadata_bulk.py +++ b/src/calibre/gui2/dialogs/metadata_bulk.py @@ -15,15 +15,16 @@ from calibre.ebooks.metadata import string_to_authors, authors_to_string from calibre.ebooks.metadata.book.base import composite_formatter from calibre.ebooks.metadata.meta import get_metadata from calibre.gui2.custom_column_widgets import populate_metadata_page -from calibre.gui2 import error_dialog, ResizableDialog +from calibre.gui2 import error_dialog, ResizableDialog, UNDEFINED_QDATE from calibre.gui2.progress_indicator import ProgressIndicator from calibre.utils.config import dynamic from calibre.utils.titlecase import titlecase from calibre.utils.icu import sort_key, capitalize -from calibre.utils.config import prefs +from calibre.utils.config import prefs, tweaks from calibre.utils.magick.draw import identify_data +from calibre.utils.date import qt_to_dt -def get_cover_data(path): +def get_cover_data(path): # {{{ old = prefs['read_file_metadata'] if not old: prefs['read_file_metadata'] = True @@ -46,7 +47,7 @@ def get_cover_data(path): prefs['read_file_metadata'] = old return cdata, area - +# }}} class MyBlockingBusy(QDialog): # {{{ @@ -132,7 +133,8 @@ class MyBlockingBusy(QDialog): # {{{ remove_all, remove, add, au, aus, do_aus, rating, pub, do_series, \ do_autonumber, do_remove_format, remove_format, do_swap_ta, \ do_remove_conv, do_auto_author, series, do_series_restart, \ - series_start_value, do_title_case, cover_action, clear_series = self.args + series_start_value, do_title_case, cover_action, clear_series, \ + pubdate = self.args # first loop: do author and title. These will commit at the end of each @@ -209,6 +211,9 @@ class MyBlockingBusy(QDialog): # {{{ if clear_series: self.db.set_series(id, '', notify=False, commit=False) + if pubdate is not None: + self.db.set_pubdate(id, pubdate, notify=False, commit=False) + if do_series: if do_series_restart: if self.series_start_value is None: @@ -288,6 +293,12 @@ class MetadataBulkDialog(ResizableDialog, Ui_MetadataBulkDialog): self.series.editTextChanged.connect(self.series_changed) self.tag_editor_button.clicked.connect(self.tag_editor) self.autonumber_series.stateChanged[int].connect(self.auto_number_changed) + self.pubdate.setMinimumDate(UNDEFINED_QDATE) + pubdate_format = tweaks['gui_pubdate_display_format'] + if pubdate_format is not None: + self.pubdate.setDisplayFormat(pubdate_format) + self.pubdate.setSpecialValueText(_('Undefined')) + self.clear_pubdate_button.clicked.connect(self.clear_pubdate) if len(self.db.custom_field_keys(include_composites=False)) == 0: self.central_widget.removeTab(1) @@ -304,6 +315,9 @@ class MetadataBulkDialog(ResizableDialog, Ui_MetadataBulkDialog): self.central_widget.setCurrentIndex(tab) self.exec_() + def clear_pubdate(self, *args): + self.pubdate.setDate(UNDEFINED_QDATE) + def button_clicked(self, which): if which == self.button_box.button(QDialogButtonBox.Apply): self.do_again = True @@ -783,6 +797,10 @@ class MetadataBulkDialog(ResizableDialog, Ui_MetadataBulkDialog): do_remove_conv = self.remove_conversion_settings.isChecked() do_auto_author = self.auto_author_sort.isChecked() do_title_case = self.change_title_to_title_case.isChecked() + pubdate = None + if self.apply_pubdate.isChecked(): + pubdate = qt_to_dt(self.pubdate.date()) + cover_action = None if self.cover_remove.isChecked(): cover_action = 'remove' @@ -794,7 +812,8 @@ class MetadataBulkDialog(ResizableDialog, Ui_MetadataBulkDialog): args = (remove_all, remove, add, au, aus, do_aus, rating, pub, do_series, do_autonumber, do_remove_format, remove_format, do_swap_ta, do_remove_conv, do_auto_author, series, do_series_restart, - series_start_value, do_title_case, cover_action, clear_series) + series_start_value, do_title_case, cover_action, clear_series, + pubdate) bb = MyBlockingBusy(_('Applying changes to %d books.\nPhase {0} {1}%%.') %len(self.ids), args, self.db, self.ids, diff --git a/src/calibre/gui2/dialogs/metadata_bulk.ui b/src/calibre/gui2/dialogs/metadata_bulk.ui index d52bc2cb89..b14c31c9d1 100644 --- a/src/calibre/gui2/dialogs/metadata_bulk.ui +++ b/src/calibre/gui2/dialogs/metadata_bulk.ui @@ -220,6 +220,9 @@ &Remove tags: + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + remove_tags @@ -260,6 +263,12 @@ + + + 0 + 0 + + List of known series. You can add new series. @@ -273,7 +282,10 @@ QComboBox::InsertAlphabetically - QComboBox::AdjustToContents + QComboBox::AdjustToMinimumContentsLengthWithIcon + + + 40 @@ -335,27 +347,52 @@ from the value in the box - - + + - Remove &format: + &Published: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - remove_format + pubdate - - - - - 120 - 16777215 - + + + + + + MMM yyyy + + + + + + + Clear published date + + + ... + + + + :/images/trash.png:/images/trash.png + + + + + + + + + &Apply date - + @@ -395,7 +432,7 @@ Future conversion of these books will use the default settings. - + Change &cover @@ -425,7 +462,7 @@ Future conversion of these books will use the default settings. - + Qt::Vertical @@ -438,6 +475,42 @@ Future conversion of these books will use the default settings. + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 15 + + + + + + + + Remove &format: + + + remove_format + + + + + + + + 120 + 16777215 + + + + @@ -798,8 +871,8 @@ not multiple and the destination field is multiple 0 0 - 197 - 60 + 826 + 313 @@ -903,7 +976,6 @@ not multiple and the destination field is multiple autonumber_series series_numbering_restarts series_start_number - remove_format button_box search_field search_mode diff --git a/src/calibre/gui2/dialogs/metadata_single.py b/src/calibre/gui2/dialogs/metadata_single.py index ede605343b..e4efdf0470 100644 --- a/src/calibre/gui2/dialogs/metadata_single.py +++ b/src/calibre/gui2/dialogs/metadata_single.py @@ -16,7 +16,7 @@ from PyQt4.Qt import SIGNAL, QObject, Qt, QTimer, QDate, \ from calibre.gui2 import error_dialog, file_icon_provider, dynamic, \ choose_files, choose_images, ResizableDialog, \ - warning_dialog, question_dialog + warning_dialog, question_dialog, UNDEFINED_QDATE from calibre.gui2.dialogs.metadata_single_ui import Ui_MetadataSingleDialog from calibre.gui2.dialogs.fetch_metadata import FetchMetadata from calibre.gui2.dialogs.tag_editor import TagEditor @@ -491,11 +491,15 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog): self.formats.setAcceptDrops(True) self.cover_changed = False self.cpixmap = None - self.pubdate.setMinimumDate(QDate(100,1,1)) + self.pubdate.setMinimumDate(UNDEFINED_QDATE) pubdate_format = tweaks['gui_pubdate_display_format'] if pubdate_format is not None: self.pubdate.setDisplayFormat(pubdate_format) - self.date.setMinimumDate(QDate(100,1,1)) + self.date.setMinimumDate(UNDEFINED_QDATE) + self.pubdate.setSpecialValueText(_('Undefined')) + self.date.setSpecialValueText(_('Undefined')) + self.clear_pubdate_button.clicked.connect(self.clear_pubdate) + self.connect(self.cover, SIGNAL('cover_changed(PyQt_PyObject)'), self.cover_dropped) QObject.connect(self.cover_button, SIGNAL("clicked(bool)"), \ @@ -615,6 +619,9 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog): self.show() + def clear_pubdate(self, *args): + self.pubdate.setDate(UNDEFINED_QDATE) + def create_custom_column_editors(self): w = self.central_widget.widget(1) layout = w.layout() diff --git a/src/calibre/gui2/dialogs/metadata_single.ui b/src/calibre/gui2/dialogs/metadata_single.ui index 6d31342dcf..60c221be1a 100644 --- a/src/calibre/gui2/dialogs/metadata_single.ui +++ b/src/calibre/gui2/dialogs/metadata_single.ui @@ -100,6 +100,112 @@ + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Automatically create the title sort entry based on the current title entry. +Using this button to create title sort will change title sort from red to green. + + + ... + + + + :/images/auto_author_sort.png:/images/auto_author_sort.png + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Swap the author and title + + + ... + + + + :/images/swap.png:/images/swap.png + + + + 16 + 16 + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Automatically create the author sort entry based on the current author entry. +Using this button to create author sort will change author sort from red to green. + + + ... + + + + :/images/auto_author_sort.png:/images/auto_author_sort.png + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + @@ -226,6 +332,31 @@ If the box is colored green, then text matches the individual author's sort stri + + + + + + Tags categorize the book. This is particularly useful while searching. <br><br>They can be any words or phrases, separated by commas. + + + + + + + + + Open Tag Editor + + + Open Tag Editor + + + + :/images/chapters.png:/images/chapters.png + + + @@ -265,6 +396,20 @@ If the box is colored green, then text matches the individual author's sort stri + + + + Remove unused series (Series that have no books) + + + ... + + + + :/images/trash.png:/images/trash.png + + + @@ -330,7 +475,7 @@ If the box is colored green, then text matches the individual author's sort stri - + MMM yyyy @@ -340,144 +485,10 @@ If the box is colored green, then text matches the individual author's sort stri - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Automatically create the title sort entry based on the current title entry. -Using this button to create title sort will change title sort from red to green. - - - ... - - - - :/images/auto_author_sort.png:/images/auto_author_sort.png - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Swap the author and title - - - ... - - - - :/images/swap.png:/images/swap.png - - - - 16 - 16 - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Automatically create the author sort entry based on the current author entry. -Using this button to create author sort will change author sort from red to green. - - - ... - - - - :/images/auto_author_sort.png:/images/auto_author_sort.png - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - - Tags categorize the book. This is particularly useful while searching. <br><br>They can be any words or phrases, separated by commas. - - - - - - - + + - Open Tag Editor - - - Open Tag Editor - - - - :/images/chapters.png:/images/chapters.png - - - - - - - Remove unused series (Series that have no books) - - - ... + Clear published date From 4e5d5bbce0ed89e1ff33836ac2222243fbb0cb24 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 16 Jan 2011 11:45:18 -0700 Subject: [PATCH 08/26] MOBI Input: SPecial case handling of emptu div tags with a defined height used as paragraph separators. Fixes #8391 (formatting issues when converting from .azw to .mobi. Not duplicating space between paragraphs.) --- src/calibre/ebooks/mobi/reader.py | 12 +++++++++++- src/calibre/manual/faq.rst | 5 +++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/calibre/ebooks/mobi/reader.py b/src/calibre/ebooks/mobi/reader.py index e07418f41c..2f397006a1 100644 --- a/src/calibre/ebooks/mobi/reader.py +++ b/src/calibre/ebooks/mobi/reader.py @@ -542,7 +542,17 @@ class MobiReader(object): elif tag.tag == 'img': tag.set('height', height) else: - styles.append('margin-top: %s' % self.ensure_unit(height)) + if tag.tag == 'div' and not tag.text and \ + (not tag.tail or not tag.tail.strip()) and \ + not len(list(tag.iterdescendants())): + # Paragraph spacer + # Insert nbsp so that the element is never + # discarded by a renderer + tag.text = u'\u00a0' # nbsp + styles.append('height: %s' % + self.ensure_unit(height)) + else: + styles.append('margin-top: %s' % self.ensure_unit(height)) if attrib.has_key('width'): width = attrib.pop('width').strip() if width and re.search(r'\d+', width): diff --git a/src/calibre/manual/faq.rst b/src/calibre/manual/faq.rst index 0e8c101620..ee72bf6fdb 100644 --- a/src/calibre/manual/faq.rst +++ b/src/calibre/manual/faq.rst @@ -450,6 +450,11 @@ How do I use purchased EPUB books with |app|? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Most purchased EPUB books have `DRM `_. This prevents |app| from opening them. You can still use |app| to store and transfer them to your e-book reader. First, you must authorize your reader on a windows machine with Adobe Digital Editions. Once this is done, EPUB books transferred with |app| will work fine on your reader. When you purchase an epub book from a website, you will get an ".acsm" file. This file should be opened with Adobe Digital Editions, which will then download the actual ".epub" e-book. The e-book file will be stored in the folder "My Digital Editions", from where you can add it to |app|. +I am getting a "Permission Denied" error? +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +A permission denied error can occur because of many possible reasons, none of them having anything to do with |app|. You can get permission denied errors if you are using an SD card with write protect enabled. Or if you, or some program you used changed the file permissions of the files in question to read only. Or if there is a filesystem error on the device which caused your operating system to mount the filesystem in read only mode or mark a particular file as read only pending recovery. Or if the files have their owner set to a user other than you. You will need to fix the underlying cause of the permissions error before resuming to use |app|. Read the error message carefully, see what file it points to and fix the permissions on that file. + Can I have the comment metadata show up on my reader? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From 91ccd9ad749a0ef88fff14971312c77d1f3838ae Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 16 Jan 2011 12:31:19 -0700 Subject: [PATCH 09/26] Add AZW to the default list of internall viewed formats --- src/calibre/gui2/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py index 6a9becee50..c94b99f141 100644 --- a/src/calibre/gui2/__init__.py +++ b/src/calibre/gui2/__init__.py @@ -85,7 +85,7 @@ def _config(): c.add_opt('LRF_ebook_viewer_options', default=None, help=_('Options for the LRF ebook viewer')) c.add_opt('internally_viewed_formats', default=['LRF', 'EPUB', 'LIT', - 'MOBI', 'PRC', 'HTML', 'FB2', 'PDB', 'RB', 'SNB'], + 'MOBI', 'PRC', 'AZW', 'HTML', 'FB2', 'PDB', 'RB', 'SNB'], help=_('Formats that are viewed using the internal viewer')) c.add_opt('column_map', default=ALL_COLUMNS, help=_('Columns to be displayed in the book list')) From 4d428dfa9a90023876413cab30f6d38fefdac620 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 16 Jan 2011 12:34:49 -0700 Subject: [PATCH 10/26] Bulk metadata edit: Check apply date automatically whenever user changes the date in the pubdate field --- src/calibre/gui2/dialogs/metadata_bulk.py | 4 ++++ src/calibre/gui2/dialogs/metadata_bulk.ui | 7 +++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/calibre/gui2/dialogs/metadata_bulk.py b/src/calibre/gui2/dialogs/metadata_bulk.py index da6e92c26a..302766a92d 100644 --- a/src/calibre/gui2/dialogs/metadata_bulk.py +++ b/src/calibre/gui2/dialogs/metadata_bulk.py @@ -299,6 +299,7 @@ class MetadataBulkDialog(ResizableDialog, Ui_MetadataBulkDialog): self.pubdate.setDisplayFormat(pubdate_format) self.pubdate.setSpecialValueText(_('Undefined')) self.clear_pubdate_button.clicked.connect(self.clear_pubdate) + self.pubdate.dateChanged.connect(self.do_apply_pubdate) if len(self.db.custom_field_keys(include_composites=False)) == 0: self.central_widget.removeTab(1) @@ -315,6 +316,9 @@ class MetadataBulkDialog(ResizableDialog, Ui_MetadataBulkDialog): self.central_widget.setCurrentIndex(tab) self.exec_() + def do_apply_pubdate(self, *args): + self.apply_pubdate.setChecked(True) + def clear_pubdate(self, *args): self.pubdate.setDate(UNDEFINED_QDATE) diff --git a/src/calibre/gui2/dialogs/metadata_bulk.ui b/src/calibre/gui2/dialogs/metadata_bulk.ui index b14c31c9d1..5690a8e555 100644 --- a/src/calibre/gui2/dialogs/metadata_bulk.ui +++ b/src/calibre/gui2/dialogs/metadata_bulk.ui @@ -367,6 +367,9 @@ from the value in the box MMM yyyy + + true + @@ -871,8 +874,8 @@ not multiple and the destination field is multiple 0 0 - 826 - 313 + 197 + 60 From 497b381bfa8ce1d5c8de65da03cc31b2b109ed10 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 16 Jan 2011 12:45:11 -0700 Subject: [PATCH 11/26] The update found link now opens the update notification dialog instead of going straight to the download page --- src/calibre/gui2/init.py | 14 +++++++++++--- src/calibre/gui2/update.py | 9 ++++----- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/calibre/gui2/init.py b/src/calibre/gui2/init.py index fc70f0579d..95af265856 100644 --- a/src/calibre/gui2/init.py +++ b/src/calibre/gui2/init.py @@ -148,7 +148,6 @@ class StatusBar(QStatusBar): # {{{ self.get_version() + ' ' + _('created by Kovid Goyal') self.device_string = '' self.update_label = QLabel('') - self.update_label.setOpenExternalLinks(True) self.addPermanentWidget(self.update_label) self.update_label.setVisible(False) self._font = QFont() @@ -174,8 +173,9 @@ class StatusBar(QStatusBar): # {{{ self.clearMessage() def new_version_available(self, ver, url): - msg = (u'%s: %s') % ( - _('Update found'), url, ver) + msg = (u'%s: %s') % ( + _('Update found'), ver, ver) self.update_label.setText(msg) self.update_label.setCursor(Qt.PointingHandCursor) self.update_label.setVisible(True) @@ -240,6 +240,14 @@ class LayoutMixin(object): # {{{ self.status_bar.addPermanentWidget(button) self.status_bar.addPermanentWidget(self.jobs_button) self.setStatusBar(self.status_bar) + self.status_bar.update_label.linkActivated.connect(self.update_link_clicked) + + def update_link_clicked(self, url): + print 11111111, url + url = unicode(url) + if url.startswith('update:'): + version = url.partition(':')[-1] + self.update_found(version, force=True) def finalize_layout(self): self.status_bar.initialize(self.system_tray_icon) diff --git a/src/calibre/gui2/update.py b/src/calibre/gui2/update.py index 30cfe8f5e4..9929d50a7e 100644 --- a/src/calibre/gui2/update.py +++ b/src/calibre/gui2/update.py @@ -52,8 +52,7 @@ class UpdateNotification(QDialog): self.label = QLabel('

'+ _('%s has been updated to version %s. ' 'See the new features. Visit the download pa' - 'ge?')%(__appname__, version)) + '">new features.')%(__appname__, version)) self.label.setOpenExternalLinks(True) self.label.setWordWrap(True) self.setWindowTitle(_('Update available!')) @@ -94,13 +93,13 @@ class UpdateMixin(object): type=Qt.QueuedConnection) self.update_checker.start() - def update_found(self, version): + def update_found(self, version, force=False): os = 'windows' if iswindows else 'osx' if isosx else 'linux' url = 'http://calibre-ebook.com/download_%s'%os self.status_bar.new_version_available(version, url) - if config.get('new_version_notification') and \ - dynamic.get('update to version %s'%version, True): + if force or (config.get('new_version_notification') and \ + dynamic.get('update to version %s'%version, True)): self._update_notification__ = UpdateNotification(version, parent=self) self._update_notification__.show() From 69c6ad02110d780f131aa41bf92317b8d82838fe Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 16 Jan 2011 12:49:46 -0700 Subject: [PATCH 12/26] ... --- src/calibre/gui2/init.py | 1 - src/calibre/manual/conversion.rst | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calibre/gui2/init.py b/src/calibre/gui2/init.py index 95af265856..ebd670c8fa 100644 --- a/src/calibre/gui2/init.py +++ b/src/calibre/gui2/init.py @@ -243,7 +243,6 @@ class LayoutMixin(object): # {{{ self.status_bar.update_label.linkActivated.connect(self.update_link_clicked) def update_link_clicked(self, url): - print 11111111, url url = unicode(url) if url.startswith('update:'): version = url.partition(':')[-1] diff --git a/src/calibre/manual/conversion.rst b/src/calibre/manual/conversion.rst index 4b2b169d72..71639ca749 100644 --- a/src/calibre/manual/conversion.rst +++ b/src/calibre/manual/conversion.rst @@ -547,6 +547,7 @@ Some limitations of PDF input are: * Extraction of vector images and tables from within the document is also not supported. * Some PDFs use special glyphs to represent ll or ff or fi, etc. Conversion of these may or may not work depending on just how they are represented internally in the PDF. * Some PDFs store their images upside down with a rotation instruction, |app| currently doesn't support that instruction, so the images will be rotated in the output as well. + * Links and Tables of Contents are not supported To re-iterate **PDF is a really, really bad** format to use as input. If you absolutely must use PDF, then be prepared for an output ranging anywhere from decent to unusable, depending on the input PDF. From 188a96caeb39966d0cc5e9fa1bd91e0ef6a77ac4 Mon Sep 17 00:00:00 2001 From: John Schember Date: Sun, 16 Jan 2011 16:40:27 -0500 Subject: [PATCH 13/26] Make TagsLineEdit into a generic CompleteLineEdit class. Use CompleteLineEdit for Author completion in the main GUI window. --- src/calibre/gui2/convert/metadata.py | 2 +- src/calibre/gui2/convert/metadata.ui | 4 +- src/calibre/gui2/custom_column_widgets.py | 12 ++-- src/calibre/gui2/dialogs/metadata_bulk.py | 8 +-- src/calibre/gui2/dialogs/metadata_bulk.ui | 6 +- src/calibre/gui2/dialogs/metadata_single.py | 4 +- src/calibre/gui2/dialogs/metadata_single.ui | 4 +- src/calibre/gui2/dialogs/search.py | 2 +- src/calibre/gui2/dialogs/search.ui | 4 +- src/calibre/gui2/library/delegates.py | 54 +++++++++++++++++- src/calibre/gui2/library/views.py | 9 ++- src/calibre/gui2/widgets.py | 62 ++++++++++++--------- src/calibre/library/database.py | 3 + 13 files changed, 118 insertions(+), 56 deletions(-) diff --git a/src/calibre/gui2/convert/metadata.py b/src/calibre/gui2/convert/metadata.py index d3744bb614..de03033060 100644 --- a/src/calibre/gui2/convert/metadata.py +++ b/src/calibre/gui2/convert/metadata.py @@ -75,7 +75,7 @@ class MetadataWidget(Widget, Ui_Form): self.publisher.setCurrentIndex(self.publisher.findText(mi.publisher)) self.author_sort.setText(mi.author_sort if mi.author_sort else '') self.tags.setText(', '.join(mi.tags if mi.tags else [])) - self.tags.update_tags_cache(self.db.all_tags()) + self.tags.update_items_cache(self.db.all_tags()) self.comment.setPlainText(mi.comments if mi.comments else '') if mi.series: self.series.setCurrentIndex(self.series.findText(mi.series)) diff --git a/src/calibre/gui2/convert/metadata.ui b/src/calibre/gui2/convert/metadata.ui index a594f47b5d..5735193424 100644 --- a/src/calibre/gui2/convert/metadata.ui +++ b/src/calibre/gui2/convert/metadata.ui @@ -190,7 +190,7 @@ - + Tags categorize the book. This is particularly useful while searching. <br><br>They can be any words or phrases, separated by commas. @@ -310,7 +310,7 @@

widgets.h
- TagsLineEdit + CompleteLineEdit QLineEdit
widgets.h
diff --git a/src/calibre/gui2/custom_column_widgets.py b/src/calibre/gui2/custom_column_widgets.py index ec18675359..d80909c4bb 100644 --- a/src/calibre/gui2/custom_column_widgets.py +++ b/src/calibre/gui2/custom_column_widgets.py @@ -14,7 +14,7 @@ from PyQt4.Qt import QComboBox, QLabel, QSpinBox, QDoubleSpinBox, QDateEdit, \ QPushButton from calibre.utils.date import qt_to_dt, now -from calibre.gui2.widgets import TagsLineEdit, EnComboBox +from calibre.gui2.widgets import CompleteLineEdit, EnComboBox from calibre.gui2.comments_editor import Editor as CommentsEditor from calibre.gui2 import UNDEFINED_QDATE, error_dialog from calibre.utils.config import tweaks @@ -212,7 +212,7 @@ class Text(Base): values = self.all_values = list(self.db.all_custom(num=self.col_id)) values.sort(key=sort_key) if self.col_metadata['is_multiple']: - w = TagsLineEdit(parent, values) + w = CompleteLineEdit(parent, values) w.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Preferred) else: w = EnComboBox(parent) @@ -226,7 +226,7 @@ class Text(Base): val = self.normalize_db_val(val) if self.col_metadata['is_multiple']: self.setter(val) - self.widgets[1].update_tags_cache(self.all_values) + self.widgets[1].update_items_cache(self.all_values) else: idx = None for i, c in enumerate(self.all_values): @@ -656,7 +656,7 @@ class RemoveTags(QWidget): layout.setSpacing(5) layout.setContentsMargins(0, 0, 0, 0) - self.tags_box = TagsLineEdit(parent, values) + self.tags_box = CompleteLineEdit(parent, values) layout.addWidget(self.tags_box, stretch = 1) # self.tags_box.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Preferred) @@ -678,7 +678,7 @@ class BulkText(BulkBase): values = self.all_values = list(self.db.all_custom(num=self.col_id)) values.sort(key=sort_key) if self.col_metadata['is_multiple']: - w = TagsLineEdit(parent, values) + w = CompleteLineEdit(parent, values) w.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Preferred) self.widgets = [QLabel('&'+self.col_metadata['name']+': ' + _('tags to add'), parent), w] @@ -697,7 +697,7 @@ class BulkText(BulkBase): def initialize(self, book_ids): if self.col_metadata['is_multiple']: - self.widgets[1].update_tags_cache(self.all_values) + self.widgets[1].update_items_cache(self.all_values) else: val = self.get_initial_value(book_ids) self.initial_val = val = self.normalize_db_val(val) diff --git a/src/calibre/gui2/dialogs/metadata_bulk.py b/src/calibre/gui2/dialogs/metadata_bulk.py index 302766a92d..c7d5add912 100644 --- a/src/calibre/gui2/dialogs/metadata_bulk.py +++ b/src/calibre/gui2/dialogs/metadata_bulk.py @@ -279,8 +279,8 @@ class MetadataBulkDialog(ResizableDialog, Ui_MetadataBulkDialog): self.changed = False all_tags = self.db.all_tags() - self.tags.update_tags_cache(all_tags) - self.remove_tags.update_tags_cache(all_tags) + self.tags.update_items_cache(all_tags) + self.remove_tags.update_items_cache(all_tags) self.initialize_combos() @@ -751,8 +751,8 @@ class MetadataBulkDialog(ResizableDialog, Ui_MetadataBulkDialog): if d.result() == QDialog.Accepted: tag_string = ', '.join(d.tags) self.tags.setText(tag_string) - self.tags.update_tags_cache(self.db.all_tags()) - self.remove_tags.update_tags_cache(self.db.all_tags()) + self.tags.update_items_cache(self.db.all_tags()) + self.remove_tags.update_items_cache(self.db.all_tags()) def auto_number_changed(self, state): if state: diff --git a/src/calibre/gui2/dialogs/metadata_bulk.ui b/src/calibre/gui2/dialogs/metadata_bulk.ui index 5690a8e555..b826f8d48d 100644 --- a/src/calibre/gui2/dialogs/metadata_bulk.ui +++ b/src/calibre/gui2/dialogs/metadata_bulk.ui @@ -195,7 +195,7 @@
- + Tags categorize the book. This is particularly useful while searching. <br><br>They can be any words or phrases, separated by commas. @@ -229,7 +229,7 @@ - + Comma separated list of tags to remove from the books. @@ -955,7 +955,7 @@ not multiple and the destination field is multiple
widgets.h
- TagsLineEdit + CompleteLineEdit QLineEdit
widgets.h
diff --git a/src/calibre/gui2/dialogs/metadata_single.py b/src/calibre/gui2/dialogs/metadata_single.py index e4efdf0470..139b8a2ebe 100644 --- a/src/calibre/gui2/dialogs/metadata_single.py +++ b/src/calibre/gui2/dialogs/metadata_single.py @@ -556,7 +556,7 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog): tags = self.db.tags(row) self.original_tags = ', '.join(tags.split(',')) if tags else '' self.tags.setText(self.original_tags) - self.tags.update_tags_cache(self.db.all_tags()) + self.tags.update_items_cache(self.db.all_tags()) rating = self.db.rating(row) if rating > 0: self.rating.setValue(int(rating/2.)) @@ -776,7 +776,7 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog): if d.result() == QDialog.Accepted: tag_string = ', '.join(d.tags) self.tags.setText(tag_string) - self.tags.update_tags_cache(self.db.all_tags()) + self.tags.update_items_cache(self.db.all_tags()) def fetch_metadata(self): diff --git a/src/calibre/gui2/dialogs/metadata_single.ui b/src/calibre/gui2/dialogs/metadata_single.ui index 60c221be1a..b95267a618 100644 --- a/src/calibre/gui2/dialogs/metadata_single.ui +++ b/src/calibre/gui2/dialogs/metadata_single.ui @@ -335,7 +335,7 @@ If the box is colored green, then text matches the individual author's sort stri - + Tags categorize the book. This is particularly useful while searching. <br><br>They can be any words or phrases, separated by commas. @@ -842,7 +842,7 @@ If the box is colored green, then text matches the individual author's sort stri
widgets.h
- TagsLineEdit + CompleteLineEdit QLineEdit
widgets.h
diff --git a/src/calibre/gui2/dialogs/search.py b/src/calibre/gui2/dialogs/search.py index 62a0f8a9f1..4f72fa915e 100644 --- a/src/calibre/gui2/dialogs/search.py +++ b/src/calibre/gui2/dialogs/search.py @@ -42,7 +42,7 @@ class SearchDialog(QDialog, Ui_Dialog): self.series_box.setAutoCompletionCaseSensitivity(Qt.CaseInsensitive) all_tags = db.all_tags() - self.tags_box.update_tags_cache(all_tags) + self.tags_box.update_items_cache(all_tags) self.box_last_values = copy.deepcopy(box_values) if self.box_last_values: diff --git a/src/calibre/gui2/dialogs/search.ui b/src/calibre/gui2/dialogs/search.ui index 6848a45506..519ae8c462 100644 --- a/src/calibre/gui2/dialogs/search.ui +++ b/src/calibre/gui2/dialogs/search.ui @@ -279,7 +279,7 @@
- + Enter tags separated by spaces @@ -360,7 +360,7 @@
widgets.h
- TagsLineEdit + CompleteLineEdit QLineEdit
widgets.h
diff --git a/src/calibre/gui2/library/delegates.py b/src/calibre/gui2/library/delegates.py index b41fd78dc3..af8f9c4d8a 100644 --- a/src/calibre/gui2/library/delegates.py +++ b/src/calibre/gui2/library/delegates.py @@ -16,7 +16,7 @@ from PyQt4.Qt import QColor, Qt, QModelIndex, QSize, \ QComboBox, QTextDocument from calibre.gui2 import UNDEFINED_QDATE, error_dialog -from calibre.gui2.widgets import EnLineEdit, TagsLineEdit +from calibre.gui2.widgets import EnLineEdit, CompleteLineEdit from calibre.utils.date import now, format_date from calibre.utils.config import tweaks from calibre.utils.formatter import validation_formatter @@ -173,9 +173,9 @@ class TagsDelegate(QStyledItemDelegate): # {{{ if self.db: col = index.model().column_map[index.column()] if not index.model().is_custom_column(col): - editor = TagsLineEdit(parent, self.db.all_tags()) + editor = CompleteLineEdit(parent, self.db.all_tags()) else: - editor = TagsLineEdit(parent, + editor = CompleteLineEdit(parent, sorted(list(self.db.all_custom(label=self.db.field_metadata.key_to_label(col))), key=sort_key)) return editor @@ -184,6 +184,54 @@ class TagsDelegate(QStyledItemDelegate): # {{{ return editor # }}} +class AuthorsDelegate(QStyledItemDelegate): # {{{ + def __init__(self, parent): + QStyledItemDelegate.__init__(self, parent) + self.db = None + + def set_database(self, db): + self.db = db + + def createEditor(self, parent, option, index): + if self.db: + col = index.model().column_map[index.column()] + if not index.model().is_custom_column(col): + editor = CompleteLineEdit(parent, self.db.all_author_names(), '&', True) + else: + editor = CompleteLineEdit(parent, + sorted(list(self.db.all_custom(label=self.db.field_metadata.key_to_label(col))), + key=sort_key), '&', True) + return editor + else: + editor = EnLineEdit(parent) + return editor +# }}} + +class CompleteDelegate(QStyledItemDelegate): # {{{ + def __init__(self, parent, sep, items_func_name, space_before_sep=False): + QStyledItemDelegate.__init__(self, parent) + self.sep = sep + self.items_func_name = items_func_name + self.space_before_sep = space_before_sep + + def set_database(self, db): + self.db = db + + def createEditor(self, parent, option, index): + if self.db and hasattr(self.db, self.items_func_name): + col = index.model().column_map[index.column()] + if not index.model().is_custom_column(col): + editor = CompleteLineEdit(parent, getattr(self.db, self.items_func_name)(), + self.sep, self.space_before_sep) + else: + editor = CompleteLineEdit(parent, + sorted(list(self.db.all_custom(label=self.db.field_metadata.key_to_label(col))), + key=sort_key), self.sep, self.space_before_sep) + else: + editor = EnLineEdit(parent) + return editor +# }}} + class CcDateDelegate(QStyledItemDelegate): # {{{ ''' Delegate for custom columns dates. Because this delegate stores the diff --git a/src/calibre/gui2/library/views.py b/src/calibre/gui2/library/views.py index 3ff0fc3cd7..61161cd5e6 100644 --- a/src/calibre/gui2/library/views.py +++ b/src/calibre/gui2/library/views.py @@ -13,7 +13,7 @@ from PyQt4.Qt import QTableView, Qt, QAbstractItemView, QMenu, pyqtSignal, \ QPoint, QPixmap, QUrl, QImage, QPainter, QColor, QRect from calibre.gui2.library.delegates import RatingDelegate, PubDateDelegate, \ - TextDelegate, DateDelegate, TagsDelegate, CcTextDelegate, \ + TextDelegate, DateDelegate, CompleteDelegate, CcTextDelegate, \ CcBoolDelegate, CcCommentsDelegate, CcDateDelegate, CcTemplateDelegate, \ CcEnumDelegate from calibre.gui2.library.models import BooksModel, DeviceBooksModel @@ -76,8 +76,8 @@ class BooksView(QTableView): # {{{ self.rating_delegate = RatingDelegate(self) self.timestamp_delegate = DateDelegate(self) self.pubdate_delegate = PubDateDelegate(self) - self.tags_delegate = TagsDelegate(self) - self.authors_delegate = TextDelegate(self) + self.tags_delegate = CompleteDelegate(self, ',', 'all_tags') + self.authors_delegate = CompleteDelegate(self, '&', 'all_author_names', True) self.series_delegate = TextDelegate(self) self.publisher_delegate = TextDelegate(self) self.text_delegate = TextDelegate(self) @@ -410,8 +410,7 @@ class BooksView(QTableView): # {{{ self.save_state() self._model.set_database(db) self.tags_delegate.set_database(db) - self.authors_delegate.set_auto_complete_function( - lambda: [(x, y.replace('|', ',')) for (x, y) in db.all_authors()]) + self.authors_delegate.set_database(db) self.series_delegate.set_auto_complete_function(db.all_series) self.publisher_delegate.set_auto_complete_function(db.all_publishers) diff --git a/src/calibre/gui2/widgets.py b/src/calibre/gui2/widgets.py index f2ff783a76..6e2d52f835 100644 --- a/src/calibre/gui2/widgets.py +++ b/src/calibre/gui2/widgets.py @@ -426,46 +426,47 @@ class EnLineEdit(LineEditECM, QLineEdit): pass -class TagsCompleter(QCompleter): +class ItemsCompleter(QCompleter): ''' A completer object that completes a list of tags. It is used in conjunction with a CompleterLineEdit. ''' - def __init__(self, parent, all_tags): - QCompleter.__init__(self, all_tags, parent) - self.all_tags = set(all_tags) + def __init__(self, parent, all_items): + QCompleter.__init__(self, all_items, parent) + self.all_items = set(all_items) - def update(self, text_tags, completion_prefix): - tags = list(self.all_tags.difference(text_tags)) - model = QStringListModel(tags, self) + def update(self, text_items, completion_prefix): + items = list(self.all_items.difference(text_items)) + model = QStringListModel(items, self) self.setModel(model) self.setCompletionPrefix(completion_prefix) if completion_prefix.strip() != '': self.complete() - def update_tags_cache(self, tags): - self.all_tags = set(tags) - model = QStringListModel(tags, self) + def update_items_cache(self, items): + self.all_items = set(items) + model = QStringListModel(items, self) self.setModel(model) -class TagsLineEdit(EnLineEdit): +class CompleteLineEdit(EnLineEdit): ''' A QLineEdit that can complete parts of text separated by separator. ''' - def __init__(self, parent=0, tags=[]): + def __init__(self, parent=0, complete_items=[], sep=',', space_before_sep=False): EnLineEdit.__init__(self, parent) - self.separator = ',' + self.separator = sep + self.space_before_sep = space_before_sep self.connect(self, SIGNAL('textChanged(QString)'), self.text_changed) - self.completer = TagsCompleter(self, tags) + self.completer = ItemsCompleter(self, complete_items) self.completer.setCaseSensitivity(Qt.CaseInsensitive) self.connect(self, @@ -476,32 +477,43 @@ class TagsLineEdit(EnLineEdit): self.completer.setWidget(self) - def update_tags_cache(self, tags): - self.completer.update_tags_cache(tags) + def update_items_cache(self, complete_items): + self.completer.update_items_cache(complete_items) + + def set_separator(self, sep): + self.separator = sep + + def set_space_before_sep(self, space_before): + self.space_before_sep = space_before def text_changed(self, text): all_text = unicode(text) text = all_text[:self.cursorPosition()] - prefix = text.split(',')[-1].strip() + prefix = text.split(self.separator)[-1].strip() - text_tags = [] + text_items = [] for t in all_text.split(self.separator): t1 = unicode(t).strip() if t1 != '': - text_tags.append(t) - text_tags = list(set(text_tags)) + text_items.append(t) + text_items = list(set(text_items)) self.emit(SIGNAL('text_changed(PyQt_PyObject, PyQt_PyObject)'), - text_tags, prefix) + text_items, prefix) def complete_text(self, text): cursor_pos = self.cursorPosition() before_text = unicode(self.text())[:cursor_pos] after_text = unicode(self.text())[cursor_pos:] - prefix_len = len(before_text.split(',')[-1].strip()) - self.setText('%s%s%s %s' % (before_text[:cursor_pos - prefix_len], - text, self.separator, after_text)) - self.setCursorPosition(cursor_pos - prefix_len + len(text) + 2) + prefix_len = len(before_text.split(self.separator)[-1].strip()) + if self.space_before_sep: + complete_text_pat = '%s%s %s %s' + len_extra = 3 + else: + complete_text_pat = '%s%s%s %s' + len_extra = 2 + self.setText(complete_text_pat % (before_text[:cursor_pos - prefix_len], text, self.separator, after_text)) + self.setCursorPosition(cursor_pos - prefix_len + len(text) + len_extra) class EnComboBox(QComboBox): diff --git a/src/calibre/library/database.py b/src/calibre/library/database.py index 6016dbd03e..e2ad8796a0 100644 --- a/src/calibre/library/database.py +++ b/src/calibre/library/database.py @@ -1059,6 +1059,9 @@ ALTER TABLE books ADD COLUMN isbn TEXT DEFAULT "" COLLATE NOCASE; def all_authors(self): return [ (i[0], i[1]) for i in \ self.conn.get('SELECT id, name FROM authors')] + + def all_author_names(self): + return [i[0].strip() for i in self.conn.get('SELECT name FROM authors') if i[0].strip()] def all_publishers(self): return [ (i[0], i[1]) for i in \ From cfa57f63df7e4fe8d683082e780b7df31c52fabb Mon Sep 17 00:00:00 2001 From: John Schember Date: Sun, 16 Jan 2011 17:14:26 -0500 Subject: [PATCH 14/26] GUI: Have Authors combo boxes use completion using & just like tags use completion with , --- src/calibre/gui2/convert/metadata.py | 3 + src/calibre/gui2/convert/metadata.ui | 69 +++++++++------------ src/calibre/gui2/dialogs/metadata_bulk.py | 4 ++ src/calibre/gui2/dialogs/metadata_bulk.ui | 19 +++--- src/calibre/gui2/dialogs/metadata_single.py | 4 ++ src/calibre/gui2/dialogs/metadata_single.ui | 51 +++++++-------- src/calibre/gui2/dialogs/search.py | 3 + src/calibre/gui2/dialogs/search.ui | 13 ++-- src/calibre/gui2/widgets.py | 16 +++++ 9 files changed, 104 insertions(+), 78 deletions(-) diff --git a/src/calibre/gui2/convert/metadata.py b/src/calibre/gui2/convert/metadata.py index de03033060..5f39202e26 100644 --- a/src/calibre/gui2/convert/metadata.py +++ b/src/calibre/gui2/convert/metadata.py @@ -68,6 +68,9 @@ class MetadataWidget(Widget, Ui_Form): def initialize_metadata_options(self): self.initialize_combos() self.author.editTextChanged.connect(self.deduce_author_sort) + self.author.set_separator('&') + self.author.set_space_before_sep(True) + self.author.update_items_cache(self.db.all_author_names()) mi = self.db.get_metadata(self.book_id, index_is_id=True) self.title.setText(mi.title) diff --git a/src/calibre/gui2/convert/metadata.ui b/src/calibre/gui2/convert/metadata.ui index 5735193424..24b7c0904a 100644 --- a/src/calibre/gui2/convert/metadata.ui +++ b/src/calibre/gui2/convert/metadata.ui @@ -20,38 +20,8 @@ Book Cover - - - - - - - 0 - 0 - - - - - - - - - - Use cover from &source file - - - true - - - - - 6 - - - 0 - @@ -64,12 +34,6 @@ - - 6 - - - 0 - @@ -86,7 +50,7 @@ ... - + :/images/document_open.png:/images/document_open.png @@ -95,6 +59,30 @@ + + + + Use cover from &source file + + + true + + + + + + + + + + 0 + 0 + + + + + + opt_prefer_metadata_cover @@ -255,7 +243,7 @@
- + true @@ -320,6 +308,11 @@
calibre/gui2/widgets.h
1 + + CompleteComboBox + QComboBox +
widgets.h
+
title diff --git a/src/calibre/gui2/dialogs/metadata_bulk.py b/src/calibre/gui2/dialogs/metadata_bulk.py index c7d5add912..2b3a319663 100644 --- a/src/calibre/gui2/dialogs/metadata_bulk.py +++ b/src/calibre/gui2/dialogs/metadata_bulk.py @@ -726,6 +726,10 @@ class MetadataBulkDialog(ResizableDialog, Ui_MetadataBulkDialog): name = name.strip().replace('|', ',') self.authors.addItem(name) self.authors.setEditText('') + + self.authors.set_separator('&') + self.authors.set_space_before_sep(True) + self.authors.update_items_cache(self.db.all_author_names()) def initialize_series(self): all_series = self.db.all_series() diff --git a/src/calibre/gui2/dialogs/metadata_bulk.ui b/src/calibre/gui2/dialogs/metadata_bulk.ui index b826f8d48d..3950026325 100644 --- a/src/calibre/gui2/dialogs/metadata_bulk.ui +++ b/src/calibre/gui2/dialogs/metadata_bulk.ui @@ -14,7 +14,7 @@ Edit Meta information - + :/images/edit_input.png:/images/edit_input.png @@ -45,7 +45,7 @@ 0 0 842 - 589 + 553 @@ -76,7 +76,7 @@
- + true @@ -210,7 +210,7 @@ Open Tag Editor - + :/images/chapters.png:/images/chapters.png @@ -381,7 +381,7 @@ from the value in the box ... - + :/images/trash.png:/images/trash.png @@ -874,8 +874,8 @@ not multiple and the destination field is multiple 0 0 - 197 - 60 + 231 + 82 @@ -964,6 +964,11 @@ not multiple and the destination field is multiple QLineEdit
widgets.h
+ + CompleteComboBox + QComboBox +
widgets.h
+
authors diff --git a/src/calibre/gui2/dialogs/metadata_single.py b/src/calibre/gui2/dialogs/metadata_single.py index 139b8a2ebe..4ca2072317 100644 --- a/src/calibre/gui2/dialogs/metadata_single.py +++ b/src/calibre/gui2/dialogs/metadata_single.py @@ -724,6 +724,10 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog): au = _('Unknown') au = ' & '.join([a.strip().replace('|', ',') for a in au.split(',')]) self.authors.setEditText(au) + + self.authors.set_separator('&') + self.authors.set_space_before_sep(True) + self.authors.update_items_cache(self.db.all_author_names()) def initialize_series(self): self.series.setSizeAdjustPolicy(self.series.AdjustToContentsOnFirstShow) diff --git a/src/calibre/gui2/dialogs/metadata_single.ui b/src/calibre/gui2/dialogs/metadata_single.ui index b95267a618..b2f42937da 100644 --- a/src/calibre/gui2/dialogs/metadata_single.ui +++ b/src/calibre/gui2/dialogs/metadata_single.ui @@ -20,7 +20,7 @@ Edit Meta Information - + :/images/edit_input.png:/images/edit_input.png @@ -43,8 +43,8 @@ 0 0 - 986 - 677 + 955 + 665 @@ -125,7 +125,7 @@ Using this button to create title sort will change title sort from red to green. ... - + :/images/auto_author_sort.png:/images/auto_author_sort.png
@@ -152,7 +152,7 @@ Using this button to create title sort will change title sort from red to green. ... - + :/images/swap.png:/images/swap.png @@ -186,7 +186,7 @@ Using this button to create author sort will change author sort from red to gree ... - + :/images/auto_author_sort.png:/images/auto_author_sort.png
@@ -240,7 +240,7 @@ Using this button to create author sort will change author sort from red to gree
- + true @@ -352,7 +352,7 @@ If the box is colored green, then text matches the individual author's sort stri Open Tag Editor - + :/images/chapters.png:/images/chapters.png @@ -405,7 +405,7 @@ If the box is colored green, then text matches the individual author's sort stri ... - + :/images/trash.png:/images/trash.png @@ -491,7 +491,7 @@ If the box is colored green, then text matches the individual author's sort stri Clear published date - + :/images/trash.png:/images/trash.png @@ -550,15 +550,9 @@ If the box is colored green, then text matches the individual author's sort stri - - 6 - QLayout::SetMaximumSize - - 0 - @@ -571,19 +565,13 @@ If the box is colored green, then text matches the individual author's sort stri - - 6 - - - 0 - &Browse - + :/images/document_open.png:/images/document_open.png @@ -597,7 +585,7 @@ If the box is colored green, then text matches the individual author's sort stri T&rim - + :/images/trim.png:/images/trim.png @@ -611,7 +599,7 @@ If the box is colored green, then text matches the individual author's sort stri &Remove - + :/images/trash.png:/images/trash.png @@ -702,7 +690,7 @@ If the box is colored green, then text matches the individual author's sort stri ... - + :/images/add_book.png:/images/add_book.png @@ -722,7 +710,7 @@ If the box is colored green, then text matches the individual author's sort stri ... - + :/images/trash.png:/images/trash.png @@ -742,7 +730,7 @@ If the box is colored green, then text matches the individual author's sort stri ... - + :/images/book.png:/images/book.png @@ -762,7 +750,7 @@ If the box is colored green, then text matches the individual author's sort stri - + :/images/edit_input.png:/images/edit_input.png @@ -863,6 +851,11 @@ If the box is colored green, then text matches the individual author's sort stri
calibre/gui2/comments_editor.h
1 + + CompleteComboBox + QComboBox +
widgets.h
+
title diff --git a/src/calibre/gui2/dialogs/search.py b/src/calibre/gui2/dialogs/search.py index 4f72fa915e..95c7cf9225 100644 --- a/src/calibre/gui2/dialogs/search.py +++ b/src/calibre/gui2/dialogs/search.py @@ -31,6 +31,9 @@ class SearchDialog(QDialog, Ui_Dialog): self.authors_box.setEditText('') self.authors_box.completer().setCompletionMode(QCompleter.PopupCompletion) self.authors_box.setAutoCompletionCaseSensitivity(Qt.CaseInsensitive) + self.authors_box.set_separator('&') + self.authors_box.set_space_before_sep(True) + self.authors_box.update_items_cache(self.db.all_author_names()) all_series = db.all_series() all_series.sort(key=lambda x : sort_key(x[1])) diff --git a/src/calibre/gui2/dialogs/search.ui b/src/calibre/gui2/dialogs/search.ui index 519ae8c462..06ea9de379 100644 --- a/src/calibre/gui2/dialogs/search.ui +++ b/src/calibre/gui2/dialogs/search.ui @@ -6,15 +6,15 @@ 0 0 - 731 - 411 + 752 + 472
Advanced Search - + :/images/search.png:/images/search.png @@ -265,7 +265,7 @@
- + Enter an author's name. Only one author can be used. @@ -364,6 +364,11 @@ QLineEdit
widgets.h
+ + CompleteComboBox + QComboBox +
widgets.h
+
all diff --git a/src/calibre/gui2/widgets.py b/src/calibre/gui2/widgets.py index 6e2d52f835..0bb5ee7634 100644 --- a/src/calibre/gui2/widgets.py +++ b/src/calibre/gui2/widgets.py @@ -540,6 +540,22 @@ class EnComboBox(QComboBox): idx = 0 self.setCurrentIndex(idx) +class CompleteComboBox(EnComboBox): + + def __init__(self, *args): + EnComboBox.__init__(self, *args) + self.setLineEdit(CompleteLineEdit(self)) + + def update_items_cache(self, complete_items): + self.lineEdit().update_items_cache(complete_items) + + def set_separator(self, sep): + self.lineEdit().set_separator(sep) + + def set_space_before_sep(self, space_before): + self.lineEdit().set_space_before_sep(space_before) + + class HistoryLineEdit(QComboBox): lost_focus = pyqtSignal() From ca0e545253e3d4b5a6bf641cac78e9b816f10d81 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 16 Jan 2011 16:51:26 -0700 Subject: [PATCH 15/26] E-book viewer: Display cover when viewing FB2 files --- src/calibre/ebooks/fb2/input.py | 18 +++++++++++------- src/calibre/ebooks/oeb/iterator.py | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/calibre/ebooks/fb2/input.py b/src/calibre/ebooks/fb2/input.py index b019873d39..3d3ec69833 100644 --- a/src/calibre/ebooks/fb2/input.py +++ b/src/calibre/ebooks/fb2/input.py @@ -104,13 +104,17 @@ class FB2Input(InputFormatPlugin): entries = [(f, guess_type(f)[0]) for f in os.listdir('.')] opf.create_manifest(entries) opf.create_spine(['index.xhtml']) - - for img in doc.xpath('//f:coverpage/f:image', namespaces=NAMESPACES): - href = img.get('{%s}href'%XLINK_NS, img.get('href', None)) - if href is not None: - if href.startswith('#'): - href = href[1:] - opf.guide.set_cover(os.path.abspath(href)) + if mi.cover_data and mi.cover_data[1]: + with open('fb2_cover_calibre_mi.jpg', 'wb') as f: + f.write(mi.cover_data[1]) + opf.guide.set_cover(os.path.abspath('fb2_cover_calibre_mi.jpg')) + else: + for img in doc.xpath('//f:coverpage/f:image', namespaces=NAMESPACES): + href = img.get('{%s}href'%XLINK_NS, img.get('href', None)) + if href is not None: + if href.startswith('#'): + href = href[1:] + opf.guide.set_cover(os.path.abspath(href)) opf.render(open('metadata.opf', 'wb')) return os.path.join(os.getcwd(), 'metadata.opf') diff --git a/src/calibre/ebooks/oeb/iterator.py b/src/calibre/ebooks/oeb/iterator.py index 6820709b3e..08b4369078 100644 --- a/src/calibre/ebooks/oeb/iterator.py +++ b/src/calibre/ebooks/oeb/iterator.py @@ -227,7 +227,7 @@ class EbookIterator(object): self.log.warn('Missing spine item:', repr(spath)) cover = self.opf.cover - if self.ebook_ext in ('lit', 'mobi', 'prc', 'opf') and cover: + if self.ebook_ext in ('lit', 'mobi', 'prc', 'opf', 'fb2') and cover: cfile = os.path.join(self.base, 'calibre_iterator_cover.html') chtml = (TITLEPAGE%os.path.relpath(cover, self.base).replace(os.sep, '/')).encode('utf-8') From 7a79f8d98d2556803177769797e5b51e169e48a1 Mon Sep 17 00:00:00 2001 From: Shixin Zeng Date: Sun, 16 Jan 2011 19:43:13 -0600 Subject: [PATCH 16/26] make use_embedded_content settable per feed --- src/calibre/web/feeds/news.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/calibre/web/feeds/news.py b/src/calibre/web/feeds/news.py index ee5b11c5f6..dd32d3749f 100644 --- a/src/calibre/web/feeds/news.py +++ b/src/calibre/web/feeds/news.py @@ -901,10 +901,7 @@ class BasicNewsRecipe(Recipe): if self.test: feeds = feeds[:2] self.has_single_feed = len(feeds) == 1 - - if self.use_embedded_content is None: - self.use_embedded_content = feeds[0].has_embedded_content() - + index = os.path.join(self.output_dir, 'index.html') html = self.feeds2index(feeds) @@ -939,7 +936,9 @@ class BasicNewsRecipe(Recipe): url = None if not url: continue - func, arg = (self.fetch_embedded_article, article) if self.use_embedded_content else \ + func, arg = (self.fetch_embedded_article, article) \ + if self.use_embedded_content or (self.use_embedded_content == None and feed.has_embedded_content()) \ + else \ ((self.fetch_obfuscated_article if self.articles_are_obfuscated \ else self.fetch_article), url) req = WorkRequest(func, (arg, art_dir, f, a, len(feed)), From 34da8b73ccf55b846c6e612f923682f1abe3f09c Mon Sep 17 00:00:00 2001 From: John Schember Date: Sun, 16 Jan 2011 21:35:53 -0500 Subject: [PATCH 17/26] Fix bug #8381: reference \t and \T PML indents properly. --- src/calibre/ebooks/pml/pmlconverter.py | 35 ++++++++++++++++++-------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/src/calibre/ebooks/pml/pmlconverter.py b/src/calibre/ebooks/pml/pmlconverter.py index 10e5871d31..a0814ee0dd 100644 --- a/src/calibre/ebooks/pml/pmlconverter.py +++ b/src/calibre/ebooks/pml/pmlconverter.py @@ -34,18 +34,15 @@ class PML_HTMLizer(object): 'ra', 'c', 'r', - 't', 's', 'l', 'k', - 'T', 'FN', 'SB', ] STATES_VALUE_REQ = [ 'a', - 'T', 'FN', 'SB', ] @@ -96,8 +93,6 @@ class PML_HTMLizer(object): 'Sb': 'sb', 'c': 'c', 'r': 'r', - 't': 't', - 'T': 'T', 'i': 'i', 'I': 'i', 'u': 'u', @@ -133,8 +128,6 @@ class PML_HTMLizer(object): DIV_STATES = [ 'c', 'r', - 't', - 'T', 'FN', 'SB', ] @@ -255,8 +248,6 @@ class PML_HTMLizer(object): for key, val in self.state.items(): if val[0]: - if key == 'T': - self.state['T'][0] = False if key in self.DIV_STATES: div.append(key) elif key in self.SPAN_STATES: @@ -506,6 +497,9 @@ class PML_HTMLizer(object): self.toc = TOC() self.file_name = file_name + indent_state = {'t': False, 'T': False} + adv_indent_val = '' + for s in self.STATES: self.state[s] = [False, '']; @@ -515,6 +509,8 @@ class PML_HTMLizer(object): parsed = [] empty = True + basic_indent = indent_state['t'] + adv_indent = indent_state['T'] # Must use StringIO, cStringIO does not support unicode line = StringIO.StringIO(line) @@ -527,7 +523,7 @@ class PML_HTMLizer(object): if c == '\\': c = line.read(1) - if c in 'qcrtTiIuobBlk': + if c in 'qcriIuobBlk': text = self.process_code(c, line) elif c in 'FS': l = line.read(1) @@ -574,6 +570,15 @@ class PML_HTMLizer(object): elif c == 'w': empty = False text = '
' % self.code_value(line) + elif c == 't': + indent_state[c] = not indent_state[c] + if indent_state[c]: + basic_indent = True + elif c == 'T': + indent_state[c] = not indent_state[c] + if indent_state[c]: + adv_indent = True + adv_indent_val = self.code_value(line) elif c == '-': empty = False text = '­' @@ -590,6 +595,16 @@ class PML_HTMLizer(object): if not empty: text = self.end_line() parsed.append(text) + + if basic_indent: + parsed.insert(0, self.STATES_TAGS['t'][0]) + parsed.append(self.STATES_TAGS['t'][1]) + elif adv_indent: + parsed.insert(0, self.STATES_TAGS['T'][0] % adv_indent_val) + parsed.append(self.STATES_TAGS['T'][1]) + indent_state['T'] = False + adv_indent_val = '' + output.append(u''.join(parsed)) line.close() From 899263f3b34febbe3f7c1fc435017b14b502a802 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 16 Jan 2011 20:37:04 -0700 Subject: [PATCH 18/26] Updated Nature News --- resources/recipes/freenature.recipe | 66 +++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 3 deletions(-) diff --git a/resources/recipes/freenature.recipe b/resources/recipes/freenature.recipe index cf06e7163d..0b287842ec 100644 --- a/resources/recipes/freenature.recipe +++ b/resources/recipes/freenature.recipe @@ -1,4 +1,5 @@ from calibre.web.feeds.news import BasicNewsRecipe +from calibre.ebooks.BeautifulSoup import Tag import re class NatureNews(BasicNewsRecipe): @@ -10,17 +11,76 @@ class NatureNews(BasicNewsRecipe): max_articles_per_feed = 50 no_stylesheets = True - remove_tags_before = dict(name='h1', attrs={'class':'heading entry-title'}) - remove_tags_after = dict(name='h2', attrs={'id':'comments'}) + keep_only_tags = [dict(name='div', attrs={'id':'content'})] +# remove_tags_before = dict(name='h1', attrs={'class':'heading entry-title'}) +# remove_tags_after = dict(name='h2', attrs={'id':'comments'}) remove_tags = [ dict(name='h2', attrs={'id':'comments'}), dict(attrs={'alt':'Advertisement'}), dict(name='div', attrs={'class':'ad'}), - ] + dict(attrs={'class':'Z3988'}), + dict(attrs={'class':['formatpublished','type-of-article','cleardiv','disclaimer','buttons','comments xoxo']}), + dict(name='a', attrs={'href':'#comments'}), + dict(name='h2',attrs={'class':'subheading plusicon icon-add-comment'}) + ] preprocess_regexps = [ (re.compile(r'

ADVERTISEMENT

', re.DOTALL|re.IGNORECASE), lambda match: ''), ] + extra_css = ''' + .author { text-align: right; font-size: small; line-height:1em; margin-top:0px; margin-left:0; margin-right:0; margin-bottom: 0; } + .imagedescription { font-size: small; font-style:italic; line-height:1em; margin-top:5px; margin-left:0; margin-right:0; margin-bottom: 0; } + .imagecredit { font-size: x-small; font-style: normal; font-weight: bold} + ''' + feeds = [('Nature News', 'http://feeds.nature.com/news/rss/most_recent')] + def preprocess_html(self,soup): + # The author name is slightly buried - dig it up + author = soup.find('p', {'class':'byline'}) + if author: + # Find out the author's name + authornamediv = author.find('span',{'class':'author fn'}) + authornamelink = authornamediv.find('a') + if authornamelink: + authorname = authornamelink.contents[0] + else: + authorname = authornamediv.contents[0] + # Stick the author's name in the byline tag + tag = Tag(soup,'div') + tag['class'] = 'author' + tag.insert(0,authorname.strip()) + author.replaceWith(tag) + + # Change the intro from a p to a div + intro = soup.find('p',{'class':'intro'}) + if intro: + tag = Tag(soup,'div') + tag['class'] = 'intro' + tag.insert(0,intro.contents[0]) + intro.replaceWith(tag) + + # Change span class=imagedescription to div + descr = soup.find('span',{'class':'imagedescription'}) + if descr: + tag = Tag(soup,'div') + tag['class'] = 'imagedescription' + tag.insert(0,descr.renderContents()) + descr.replaceWith(tag) + + # The references are in a list, let's make them simpler + reflistcont = soup.find('ul',{'id':'article-refrences'}) + if reflistcont: + reflist = reflistcont.li.renderContents() + tag = Tag(soup,'div') + tag['class'] = 'article-references' + tag.insert(0,reflist) + reflistcont.replaceWith(tag) + + # Within the id=content div, we need to remove all the stuff after the end of the class=entry-content + entrycontent = soup.find('div',{'class':'entry-content'}) + for nextSibling in entrycontent.findNextSiblings(): + nextSibling.extract() + + return soup From a661a17f1f027ab2cbf9b006e85a2a366d4e4c37 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Mon, 17 Jan 2011 11:27:10 +0000 Subject: [PATCH 19/26] Change formatter to show an error if an unknown function is used. --- src/calibre/utils/formatter.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/calibre/utils/formatter.py b/src/calibre/utils/formatter.py index 49b807ff1c..740e67bee8 100644 --- a/src/calibre/utils/formatter.py +++ b/src/calibre/utils/formatter.py @@ -274,9 +274,9 @@ class TemplateFormatter(string.Formatter): colon += 1 funcs = formatter_functions.get_functions() - if fmt[colon:p] in funcs: - field = fmt[colon:p] - func = funcs[field] + fname = fmt[colon:p] + if fname in funcs: + func = funcs[fname] if func.arg_count == 2: # only one arg expected. Don't bother to scan. Avoids need # for escaping characters @@ -292,6 +292,8 @@ class TemplateFormatter(string.Formatter): else: val = func.eval_(self, self.kwargs, self.book, self.locals, val, *args).strip() + else: + return _('%s: unknown function')%fname if val: val = self._do_format(val, dispfmt) if not val: From 20d8d908ee70d69c68bba1bb221e8e850fb51da7 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 17 Jan 2011 08:37:07 -0700 Subject: [PATCH 20/26] ... --- src/calibre/devices/sne/driver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calibre/devices/sne/driver.py b/src/calibre/devices/sne/driver.py index 04e5cd0d76..bb8d34c59c 100644 --- a/src/calibre/devices/sne/driver.py +++ b/src/calibre/devices/sne/driver.py @@ -33,6 +33,6 @@ class SNE(USBMS): STORAGE_CARD_VOLUME_LABEL = 'SNE Storage Card' EBOOK_DIR_MAIN = EBOOK_DIR_CARD_A = 'Books' - SUPPORTS_SUB_DIRS = False + SUPPORTS_SUB_DIRS = True From 30922f75f20b0c9e96adc53e0951574057ace50e Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 17 Jan 2011 09:26:45 -0700 Subject: [PATCH 21/26] Fix #8430 (Economist Print Edition no longer requires a password) --- resources/recipes/economist.recipe | 9 +++++---- resources/recipes/economist_free.recipe | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/resources/recipes/economist.recipe b/resources/recipes/economist.recipe index 01ee8e0baf..95b4a2ae05 100644 --- a/resources/recipes/economist.recipe +++ b/resources/recipes/economist.recipe @@ -9,7 +9,7 @@ from calibre.web.feeds.news import BasicNewsRecipe from calibre.ebooks.BeautifulSoup import BeautifulSoup from calibre.ebooks.BeautifulSoup import Tag, NavigableString -import mechanize, string, urllib, time, re +import string, time, re class Economist(BasicNewsRecipe): @@ -18,19 +18,19 @@ class Economist(BasicNewsRecipe): __author__ = "Kovid Goyal" INDEX = 'http://www.economist.com/printedition' - description = ('Global news and current affairs from a European perspective.' - ' Needs a subscription from ')+INDEX + description = 'Global news and current affairs from a European perspective.' oldest_article = 7.0 cover_url = 'http://www.economist.com/images/covers/currentcoverus_large.jpg' remove_tags = [dict(name=['script', 'noscript', 'title', 'iframe', 'cf_floatingcontent']), dict(attrs={'class':['dblClkTrk', 'ec-article-info']})] keep_only_tags = [dict(id='ec-article-body')] - needs_subscription = True + needs_subscription = False no_stylesheets = True preprocess_regexps = [(re.compile('.*', re.DOTALL), lambda x:'')] + ''' def get_browser(self): br = BasicNewsRecipe.get_browser() br.open('http://www.economist.com') @@ -50,6 +50,7 @@ class Economist(BasicNewsRecipe): })) br.open(req).read() return br + ''' def parse_index(self): try: diff --git a/resources/recipes/economist_free.recipe b/resources/recipes/economist_free.recipe index 1a783521f6..321c7d29ce 100644 --- a/resources/recipes/economist_free.recipe +++ b/resources/recipes/economist_free.recipe @@ -7,12 +7,12 @@ from lxml import html class Economist(BasicNewsRecipe): - title = 'The Economist (free)' + title = 'The Economist (RSS)' language = 'en' __author__ = "Kovid Goyal" description = ('Global news and current affairs from a European perspective.' - ' Much slower than the subscription based version.') + ' Much slower than the print edition based version.') oldest_article = 7.0 cover_url = 'http://www.economist.com/images/covers/currentcoverus_large.jpg' From 0d91ea7055c24b98b9117517abf669cae3f6f53a Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 17 Jan 2011 09:39:06 -0700 Subject: [PATCH 22/26] When auto converting books and the device is unplugged, do not raise an error. Fixes #8426 (Exception when attempting to send books to a Kindle that was sleeping) --- src/calibre/gui2/device.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/device.py b/src/calibre/gui2/device.py index 944ce03305..734d8cd56c 100644 --- a/src/calibre/gui2/device.py +++ b/src/calibre/gui2/device.py @@ -1018,7 +1018,8 @@ class DeviceMixin(object): # {{{ ids = [self.library_view.model().id(r) \ for r in self.library_view.selectionModel().selectedRows()] \ if send_ids is None else send_ids - if not self.device_manager or not ids or len(ids) == 0: + if not self.device_manager or not ids or len(ids) == 0 or \ + not self.device_manager.is_device_connected: return settings = self.device_manager.device.settings() From 1d24b14bc21a933067cc140760b59af0c4d709b2 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 17 Jan 2011 09:59:50 -0700 Subject: [PATCH 23/26] ... --- src/calibre/manual/faq.rst | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/calibre/manual/faq.rst b/src/calibre/manual/faq.rst index ee72bf6fdb..b473893673 100644 --- a/src/calibre/manual/faq.rst +++ b/src/calibre/manual/faq.rst @@ -101,6 +101,17 @@ We just need some information from you: Once you send us the output for a particular operating system, support for the device in that operating system will appear in the next release of |app|. +My device is not being detected by |app|? +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Follow these steps to find the problem: + + * Make sure that you are connecting only a single device to your computer at a time. Do not have another |app| supported device like an iPhone/iPad etc. at the same time. + * Make sure you are running the latest version of |app|. The latest version can always be downloaded from `http://calibre-ebook.com/download`_. + * Ensure your operating system is seeing the device. That is, the device should be mounted as a disk that you can access using Windows explorer or whatever the file management program on your computer is + * In calibre, go to Preferences->Plugins->Device Interface plugin and make sure the plugin for your device is enabled. + * If all the above steps fail, go to Preferences->Miscellaneous and click debug device detection with your device attached and post the output as a ticket on `http://bugs.calibre-ebook.com`_. + How does |app| manage collections on my SONY reader? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From 5e2a2d71a61bfdb85d191461a2d7be5a252436e6 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 17 Jan 2011 10:11:22 -0700 Subject: [PATCH 24/26] Better error message in debug log when failed to fetch a news article --- src/calibre/web/feeds/news.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/calibre/web/feeds/news.py b/src/calibre/web/feeds/news.py index dd32d3749f..6215132e4b 100644 --- a/src/calibre/web/feeds/news.py +++ b/src/calibre/web/feeds/news.py @@ -839,7 +839,13 @@ class BasicNewsRecipe(Recipe): fetcher.image_url_processor = self.image_url_processor res, path, failures = fetcher.start_fetch(url), fetcher.downloaded_paths, fetcher.failed_links if not res or not os.path.exists(res): - raise Exception(_('Could not fetch article. Run with -vv to see the reason')) + msg = _('Could not fetch article.') + ' ' + if self.debug: + msg += _('The debug traceback is available earlier in this log') + else: + msg += _('Run with -vv to see the reason') + raise Exception(msg) + return res, path, failures def fetch_article(self, url, dir, f, a, num_of_feeds): @@ -901,7 +907,7 @@ class BasicNewsRecipe(Recipe): if self.test: feeds = feeds[:2] self.has_single_feed = len(feeds) == 1 - + index = os.path.join(self.output_dir, 'index.html') html = self.feeds2index(feeds) From 46ab37e98f310c8134c44c79bf2da14422ec0bd7 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 17 Jan 2011 10:17:34 -0700 Subject: [PATCH 25/26] iHNed by Karel Bilek --- resources/recipes/ihned.recipe | 182 +++++++++++++++++++++++++++++++++ 1 file changed, 182 insertions(+) create mode 100644 resources/recipes/ihned.recipe diff --git a/resources/recipes/ihned.recipe b/resources/recipes/ihned.recipe new file mode 100644 index 0000000000..daf63e19ed --- /dev/null +++ b/resources/recipes/ihned.recipe @@ -0,0 +1,182 @@ +import re, time +from calibre import strftime +from calibre.web.feeds.recipes import BasicNewsRecipe + +class IHNed(BasicNewsRecipe): + + + stahnout_vsechny = False + #True = stahuje vsechny z homepage + #False = stahuje pouze dnesni clanky (ze dne, kdy je skript spusten) + + title = 'iHNed' + __author__ = 'Karel Bílek' + language = 'cs' + description = 'Zprávy z iHNed.cz' + timefmt = ' [%a, %d %b, %Y]' + needs_subscription = False + remove_tags = [dict(attrs={'class':['borderbottom', 'web', 'foot', 'reklama', 'd-elm d-rellinks', 'd-elm']}), + dict(style=['text-align: center;']), + dict(id=['r-bfull']), + dict(name=['script', 'noscript', 'style'])] + encoding = 'windows-1250' + no_stylesheets = True + remove_tags_before = dict(attrs={'class':'d-nadtit'}) + remove_tags_after = dict(attrs={'class':'like'}) + + conversion_options = { + 'linearize_tables' : True, + } + + + + def preprocess_html(self, soup): + + def makeurl(wat): + return "http://ihned.cz"+wat; + + for h1 in soup.findAll('h1'): + a = h1.find('a') + if a: + string = a.string + if string: + soup.a.replaceWith(string) + for a in soup.findAll('a', href=True) : + cil = str(a['href']) + if cil.startswith("/") or cil.startswith("index"): + a['href'] = makeurl(cil) + return soup + + + def parse_index(self): + + def makeurl(wat): + if wat.startswith("/") or wat.startswith("index"): + return "http://ihned.cz"+wat; + else: + return wat + + + articles = {} #vysledek, asi + key = None #soucasna sekce + ans = [] #vsechny sekce + + articles["Hlavní"] = [] + ans.append("Hlavní") + + was = {} + + def parse_subpage(url, name): + articles[name] = [] + ans.append(name) + + + soup = self.index_to_soup(url) + otvirak = soup.find(True, attrs={'class':['otv']}) + if otvirak: + + #the code is copypasted here because I don't know python. simple as that. + a = otvirak.find('a', href=True) + title = self.tag_to_string(a, use_alt=True).strip() + txt = otvirak.find(True, attrs={'class':['txt']}) + description = '' + if txt: + match = re.match(r'
\s*([^<]*)\s*\s*([^<]*)\s*\s*([^<]*)\s* Date: Mon, 17 Jan 2011 10:34:38 -0700 Subject: [PATCH 26/26] kath.net bu Bobus --- resources/recipes/kath_net.recipe | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 resources/recipes/kath_net.recipe diff --git a/resources/recipes/kath_net.recipe b/resources/recipes/kath_net.recipe new file mode 100644 index 0000000000..7c469adbe8 --- /dev/null +++ b/resources/recipes/kath_net.recipe @@ -0,0 +1,16 @@ +from calibre.web.feeds.news import BasicNewsRecipe + +class AdvancedUserRecipe1295262156(BasicNewsRecipe): + title = u'kath.net' + __author__ = 'Bobus' + oldest_article = 7 + max_articles_per_feed = 100 + + feeds = [(u'kath.net', u'http://www.kath.net/2005/xml/index.xml')] + + + def print_version(self, url): + return url+"&print=yes" + + extra_css = 'td.textb {font-size: medium;}' +