diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py index 8912df9db4..732c5dbc76 100644 --- a/src/calibre/customize/builtins.py +++ b/src/calibre/customize/builtins.py @@ -739,8 +739,17 @@ class OutputOptions(PreferencesPlugin): name_order = 3 config_widget = 'calibre.gui2.preferences.conversion:OutputOptions' +class Adding(PreferencesPlugin): + name = 'Adding' + gui_name = _('Adding books') + category = 'Import/Export' + gui_category = _('Import/Export') + category_order = 3 + name_order = 1 + config_widget = 'calibre.gui2.preferences.adding' + plugins += [LookAndFeel, Behavior, Columns, Toolbar, InputOptions, - CommonOptions, OutputOptions] + CommonOptions, OutputOptions, Adding] #}}} diff --git a/src/calibre/gui2/preferences/adding.py b/src/calibre/gui2/preferences/adding.py new file mode 100644 index 0000000000..7a27ed8f2d --- /dev/null +++ b/src/calibre/gui2/preferences/adding.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python +# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai + +__license__ = 'GPL v3' +__copyright__ = '2010, Kovid Goyal ' +__docformat__ = 'restructuredtext en' + + + +from calibre.gui2.preferences import ConfigWidgetBase, test_widget +from calibre.gui2.preferences.adding_ui import Ui_Form +from calibre.utils.config import prefs +from calibre.gui2.widgets import FilenamePattern + +class ConfigWidget(ConfigWidgetBase, Ui_Form): + + def genesis(self, gui): + self.gui = gui + + r = self.register + + r('read_file_metadata', prefs) + r('swap_author_names', prefs) + r('add_formats_to_existing', prefs) + + self.filename_pattern = FilenamePattern(self) + self.metadata_box.layout().insertWidget(0, self.filename_pattern) + self.filename_pattern.changed_signal.connect(self.changed_signal.emit) + + + def initialize(self): + ConfigWidgetBase.initialize(self) + self.filename_pattern.blockSignals(True) + self.filename_pattern.initialize() + self.filename_pattern.blockSignals(False) + + def restore_defaults(self): + ConfigWidgetBase.restore_defaults(self) + self.filename_pattern.initialize(defaults=True) + + def commit(self): + pattern = self.filename_pattern.commit() + prefs['filename_pattern'] = pattern + return ConfigWidgetBase.commit(self) + +if __name__ == '__main__': + from PyQt4.Qt import QApplication + app = QApplication([]) + test_widget('Import/Export', 'Adding') + diff --git a/src/calibre/gui2/preferences/adding.ui b/src/calibre/gui2/preferences/adding.ui new file mode 100644 index 0000000000..062c45e1ad --- /dev/null +++ b/src/calibre/gui2/preferences/adding.ui @@ -0,0 +1,83 @@ + + + Form + + + + 0 + 0 + 1010 + 339 + + + + Form + + + + + + Here you can control how calibre will read metadata from the files you add to it. calibre can either read metadata from the contents of the file, or from the filename. + + + true + + + + + + + Read metadata from &file contents rather than file name + + + + + + + If an existing book with a similar title and author is found that does not have the format being added, the format is added +to the existing book, instead of creating a new entry. If the existing book already has the format, then it is silently ignored. + +Title match ignores leading indefinite articles ("the", "a", "an"), punctuation, case, etc. Author match is exact. + + + If books with similar titles and authors found, &merge the new files automatically + + + + + + + &Configure metadata from file name + + + + + + Qt::Vertical + + + + 20 + 363 + + + + + + + + + + + Swap the firstname and lastname of the author. This affects only metadata read from file names. + + + &Swap author firstname and lastname + + + + + + + + diff --git a/src/calibre/gui2/widgets.py b/src/calibre/gui2/widgets.py index ae7f8d259e..0237da0a09 100644 --- a/src/calibre/gui2/widgets.py +++ b/src/calibre/gui2/widgets.py @@ -61,13 +61,24 @@ class ProgressIndicator(QWidget): class FilenamePattern(QWidget, Ui_Form): + changed_signal = pyqtSignal() + def __init__(self, parent): QWidget.__init__(self, parent) self.setupUi(self) self.connect(self.test_button, SIGNAL('clicked()'), self.do_test) self.connect(self.re, SIGNAL('returnPressed()'), self.do_test) - self.re.setText(prefs['filename_pattern']) + self.initialize() + self.re.textChanged.connect(lambda x: self.changed_signal.emit()) + + def initialize(self, defaults=False): + if defaults: + val = prefs.defaults['filename_pattern'] + else: + val = prefs['filename_pattern'] + self.re.setText(val) + def do_test(self): try: