def annotations_destination_changed(self, qs_new_destination_name): ''' If the destination field changes, move all existing annotations from old to new ''' self._log_location(str(qs_new_destination_name)) #self._log("self.eligible_annotations_fields: %s" % self.eligible_annotations_fields) old_destination_field = get_cc_mapping('annotations', 'field', None) old_destination_name = get_cc_mapping('annotations', 'combobox', None) self._log("old_destination_field: %s" % old_destination_field) self._log("old_destination_name: %s" % old_destination_name) new_destination_name = unicode(qs_new_destination_name) self._log("new_destination_name: %s" % new_destination_name) if old_destination_name == new_destination_name: self._log_location( "old_destination_name = new_destination_name, no changes") return new_destination_field = self.eligible_annotations_fields[ new_destination_name] if existing_annotations(self.parent, old_destination_field): command = self.launch_new_destination_dialog( old_destination_name, new_destination_name) if command == 'move': set_cc_mapping('annotations', field=new_destination_field, combobox=new_destination_name) if self.annotated_books_scanner.isRunning(): self.annotated_books_scanner.wait() move_annotations(self, self.annotated_books_scanner.annotation_map, old_destination_field, new_destination_field) elif command == 'change': # Keep the updated destination field, but don't move annotations pass elif command == 'cancel': # Restore previous destination self.annotations_field_comboBox.blockSignals(True) old_index = self.annotations_field_comboBox.findText( old_destination_name) self.annotations_field_comboBox.setCurrentIndex(old_index) self.annotations_field_comboBox.blockSignals(False) else: # No existing annotations, just update prefs self._log("no existing annotations, updating destination to '{0}'". format(new_destination_name)) set_cc_mapping('annotations', field=new_destination_field, combobox=new_destination_name)
def annotations_destination_changed(self, qs_new_destination_name): ''' If the destination field changes, move all existing annotations from old to new ''' self._log_location(str(qs_new_destination_name)) #self._log("self.eligible_annotations_fields: %s" % self.eligible_annotations_fields) old_destination_field = get_cc_mapping('annotations', 'field', None) old_destination_name = get_cc_mapping('annotations', 'combobox', None) self._log("old_destination_field: %s" % old_destination_field) self._log("old_destination_name: %s" % old_destination_name) new_destination_name = unicode(qs_new_destination_name) self._log("new_destination_name: %s" % repr(new_destination_name)) if old_destination_name == new_destination_name: self._log_location("old_destination_name = new_destination_name, no changes") return if new_destination_name == '': self._log_location("annotations storage disabled") set_cc_mapping('annotations', field=None, combobox=new_destination_name) return new_destination_field = self.eligible_annotations_fields[new_destination_name] if existing_annotations(self.parent, old_destination_field): command = self.launch_new_destination_dialog(old_destination_name, new_destination_name) if command == 'move': set_cc_mapping('annotations', field=new_destination_field, combobox=new_destination_name) if self.annotated_books_scanner.isRunning(): self.annotated_books_scanner.wait() move_annotations(self, self.annotated_books_scanner.annotation_map, old_destination_field, new_destination_field) elif command == 'change': # Keep the updated destination field, but don't move annotations pass elif command == 'cancel': # Restore previous destination self.annotations_field_comboBox.blockSignals(True) old_index = self.annotations_field_comboBox.findText(old_destination_name) self.annotations_field_comboBox.setCurrentIndex(old_index) self.annotations_field_comboBox.blockSignals(False) else: # No existing annotations, just update prefs self._log("no existing annotations, updating destination to '{0}'".format(new_destination_name)) set_cc_mapping('annotations', field=new_destination_field, combobox=new_destination_name)
def populate_reading_list(self): datatype = self.WIZARD_PROFILES['Reading list']['datatype'] self.eligible_reading_list_fields = self.get_eligible_custom_fields([datatype]) self.reading_list_field_comboBox.addItems(['']) ecf = sorted(self.eligible_reading_list_fields.keys(), key=lambda s: s.lower()) self.reading_list_field_comboBox.addItems(ecf) # Retrieve stored value existing = get_cc_mapping('reading_list', 'combobox') if existing: ci = self.reading_list_field_comboBox.findText(existing) self.reading_list_field_comboBox.setCurrentIndex(ci)
def populate_read(self): datatype = self.WIZARD_PROFILES['Read']['datatype'] self.eligible_read_fields = self.get_eligible_custom_fields([datatype]) self.read_field_comboBox.addItems(['']) ecf = sorted(self.eligible_read_fields.keys(), key=lambda s: s.lower()) self.read_field_comboBox.addItems(ecf) # Retrieve stored value existing = get_cc_mapping('read', 'combobox') if existing: ci = self.read_field_comboBox.findText(existing) self.read_field_comboBox.setCurrentIndex(ci)
def populate_collections(self): datatype = self.WIZARD_PROFILES['Collections']['datatype'] self.eligible_collection_fields = self.get_eligible_custom_fields([datatype], is_multiple=True) self.collection_field_comboBox.addItems(['']) ecf = sorted(self.eligible_collection_fields.keys(), key=lambda s: s.lower()) self.collection_field_comboBox.addItems(ecf) # Retrieve stored value existing = get_cc_mapping('collections', 'combobox') if existing: ci = self.collection_field_comboBox.findText(existing) self.collection_field_comboBox.setCurrentIndex(ci)
def configure_appearance(self): ''' ''' self._log_location() appearance_settings = { 'appearance_css': default_elements, 'appearance_hr_checkbox': False, 'appearance_timestamp_format': default_timestamp } # Save, hash the original settings original_settings = {} osh = hashlib.md5() for setting in appearance_settings: original_settings[setting] = plugin_prefs.get(setting, appearance_settings[setting]) osh.update(repr(plugin_prefs.get(setting, appearance_settings[setting]))) # Display the Annotations appearance dialog aa = AnnotationsAppearance(self, self.annotations_icon, plugin_prefs) cancelled = False if aa.exec_(): # appearance_hr_checkbox and appearance_timestamp_format changed live to prefs during previews plugin_prefs.set('appearance_css', aa.elements_table.get_data()) # Generate a new hash nsh = hashlib.md5() for setting in appearance_settings: nsh.update(repr(plugin_prefs.get(setting, appearance_settings[setting]))) else: for setting in appearance_settings: plugin_prefs.set(setting, original_settings[setting]) nsh = osh # If there were changes, and there are existing annotations, # and there is an active Annotations field, offer to re-render field = get_cc_mapping('annotations', 'field', None) if osh.digest() != nsh.digest() and existing_annotations(self.parent, field): title = 'Update annotations?' msg = '<p>Update existing annotations to new appearance settings?</p>' d = MessageBox(MessageBox.QUESTION, title, msg, show_copy_button=False) self._log_location("QUESTION: %s" % msg) if d.exec_(): self._log_location("Updating existing annotations to modified appearance") # Wait for indexing to complete while not self.annotated_books_scanner.isFinished(): Application.processEvents() move_annotations(self, self.annotated_books_scanner.annotation_map, field, field, window_title="Updating appearance")
def configure_appearance(self): ''' ''' self._log_location() appearance_settings = { 'appearance_css': default_elements, 'appearance_hr_checkbox': False, 'appearance_timestamp_format': default_timestamp } # Save, hash the original settings original_settings = {} osh = hashlib.md5() for setting in appearance_settings: original_settings[setting] = plugin_prefs.get(setting, appearance_settings[setting]) osh.update(repr(plugin_prefs.get(setting, appearance_settings[setting]))) # Display the Annotations appearance dialog aa = AnnotationsAppearance(self, self.annotations_icon, plugin_prefs) cancelled = False if aa.exec_(): # appearance_hr_checkbox and appearance_timestamp_format changed live to prefs during previews plugin_prefs.set('appearance_css', aa.elements_table.get_data()) # Generate a new hash nsh = hashlib.md5() for setting in appearance_settings: nsh.update(repr(plugin_prefs.get(setting, appearance_settings[setting]))) else: for setting in appearance_settings: plugin_prefs.set(setting, original_settings[setting]) nsh = osh # If there were changes, and there are existing annotations, # and there is an active Annotations field, offer to re-render field = get_cc_mapping('annotations', 'field', None) if osh.digest() != nsh.digest() and existing_annotations(self.parent, field): title = 'Update annotations?' msg = '<p>Update existing annotations to new appearance settings?</p>' d = MessageBox(MessageBox.QUESTION, title, msg, show_copy_button=False) self._log_location("QUESTION: %s" % msg) if d.exec_(): self._log_location("Updating existing annotations to modified appearance") # Wait for indexing to complete while not self.annotated_books_scanner.isFinished(): Application.processEvents() move_annotations(self, self.annotated_books_scanner.annotation_map, field, field, window_title="Updating appearance")
def _update_calibre_metadata(self, book, cid): ''' Update cid mapped custom columns from book metadata Annotations comments html annotations Collections text collections Last read datetime date_read *Notes comments html Progress float 50.0 progress *Rating Read bool True|False|None read Reading list bool True|False|None reading_list Word count int 12345 word_count ''' CUSTOM_COLUMN_MAPPINGS = { 'Annotations': { 'attribute': './annotations', 'datatype': 'comments', 'lookup': get_cc_mapping('annotations', 'field', None) }, 'Collections': { 'attribute': './collections/collection', 'datatype': 'text', 'lookup': get_cc_mapping('collections', 'field', None) }, 'Last read': { 'attribute': 'dateopened', 'datatype': 'datetime', 'lookup': get_cc_mapping('date_read', 'field', None) }, 'Progress': { 'attribute': 'progress', 'datatype': 'float', 'lookup': get_cc_mapping('progress', 'field', None) }, 'Read': { 'attribute': 'isread', 'datatype': 'bool', 'lookup': get_cc_mapping('read', 'field', None) }, 'Reading list': { 'attribute': 'readinglist', 'datatype': 'bool', 'lookup': get_cc_mapping('reading_list', 'field', None) }, 'Word count': { 'attribute': 'wordcount', 'datatype': 'int', 'lookup': get_cc_mapping('word_count', 'field', None) } } # Don't show floats less than FLOAT_THRESHOLD FLOAT_THRESHOLD = 1.0 self._log_location(book.attrib['title']) mi = self.db.get_metadata(cid, index_is_id=True) mi_updated = False for ccm in CUSTOM_COLUMN_MAPPINGS: mapping = CUSTOM_COLUMN_MAPPINGS[ccm] lookup = self.prefs.get(mapping['lookup'], None) if lookup: um = mi.metadata_for_field(lookup) datatype = mapping['datatype'] if ccm in ['Annotations']: ''' # Not sure if we'll need this, depends on how Kris returns annotations if re.match(self.UTF_8_BOM, anns): anns = UnicodeDammit(anns).unicode ''' ann_el = book.find(mapping['attribute']) if ann_el is not None: anns = '' for sub_element in ['head', 'body']: el = ann_el.find(sub_element) anns += etree.tostring(el) anns = self._inject_css(anns).encode('utf-8') anns = "<?xml version='1.0' encoding='utf-8'?>" + anns um['#value#'] = anns mi.set_user_metadata(lookup, um) mi_updated = True elif ccm in ['Collections']: cels = book.findall(mapping['attribute']) um['#value#'] = [unicode(cel.text) for cel in cels] mi.set_user_metadata(lookup, um) mi_updated = True else: if datatype == 'bool': um['#value#'] = None if book.attrib[mapping['attribute']] == '1': um['#value#'] = True elif datatype == 'datetime': ts = time.strftime("%Y-%m-%d %H:%M", time.localtime(float(book.attrib[mapping['attribute']]))) um['#value#'] = ts elif datatype == 'float': val = float(book.attrib[mapping['attribute']]) * 100 if val < FLOAT_THRESHOLD: val = None um['#value#'] = val elif datatype == 'int': val = book.attrib[mapping['attribute']] if val > '': um['#value#'] = int(val) else: self._log("*** datatype '{0}' not handled ***".format(datatype)) mi.set_user_metadata(lookup, um) mi_updated = True if mi_updated: self.db.set_metadata(cid, mi, set_title=False, set_authors=False, commit=True, force_changes=True)
def __init__(self, plugin_action): QWidget.__init__(self) self.parent = plugin_action self.gui = get_gui() self.icon = plugin_action.icon self.opts = plugin_action.opts self.prefs = plugin_prefs self.resources_path = plugin_action.resources_path self.verbose = plugin_action.verbose self.restart_required = False self._log_location() self.l = QGridLayout() self.setLayout(self.l) self.column1_layout = QVBoxLayout() self.l.addLayout(self.column1_layout, 0, 0) self.column2_layout = QVBoxLayout() self.l.addLayout(self.column2_layout, 0, 1) # ----------------------------- Column 1 ----------------------------- # ~~~~~~~~ Create the Custom fields options group box ~~~~~~~~ self.cfg_custom_fields_gb = QGroupBox(self) self.cfg_custom_fields_gb.setTitle('Custom column assignments') self.column1_layout.addWidget(self.cfg_custom_fields_gb) self.cfg_custom_fields_qgl = QGridLayout(self.cfg_custom_fields_gb) current_row = 0 # ++++++++ Labels + HLine ++++++++ self.marvin_source_label = QLabel("Marvin source") self.cfg_custom_fields_qgl.addWidget(self.marvin_source_label, current_row, 0) self.calibre_destination_label = QLabel("calibre destination") self.cfg_custom_fields_qgl.addWidget(self.calibre_destination_label, current_row, 1) current_row += 1 self.sd_hl = QFrame(self.cfg_custom_fields_gb) self.sd_hl.setFrameShape(QFrame.HLine) self.sd_hl.setFrameShadow(QFrame.Raised) self.cfg_custom_fields_qgl.addWidget(self.sd_hl, current_row, 0, 1, 3) current_row += 1 # ++++++++ Annotations ++++++++ self.cfg_annotations_label = QLabel('Annotations') self.cfg_annotations_label.setAlignment(Qt.AlignLeft) self.cfg_custom_fields_qgl.addWidget(self.cfg_annotations_label, current_row, 0) self.annotations_field_comboBox = QComboBox(self.cfg_custom_fields_gb) self.annotations_field_comboBox.setObjectName('annotations_field_comboBox') self.annotations_field_comboBox.setToolTip('Select a custom column to store Marvin annotations') self.cfg_custom_fields_qgl.addWidget(self.annotations_field_comboBox, current_row, 1) self.cfg_highlights_wizard = QToolButton() self.cfg_highlights_wizard.setIcon(QIcon(I('wizard.png'))) self.cfg_highlights_wizard.setToolTip("Create a custom column to store Marvin annotations") self.cfg_highlights_wizard.clicked.connect(partial(self.launch_cc_wizard, 'Annotations')) self.cfg_custom_fields_qgl.addWidget(self.cfg_highlights_wizard, current_row, 2) current_row += 1 # ++++++++ Collections ++++++++ self.cfg_collections_label = QLabel('Collections') self.cfg_collections_label.setAlignment(Qt.AlignLeft) self.cfg_custom_fields_qgl.addWidget(self.cfg_collections_label, current_row, 0) self.collection_field_comboBox = QComboBox(self.cfg_custom_fields_gb) self.collection_field_comboBox.setObjectName('collection_field_comboBox') self.collection_field_comboBox.setToolTip('Select a custom column to store Marvin collection assignments') self.cfg_custom_fields_qgl.addWidget(self.collection_field_comboBox, current_row, 1) self.cfg_collections_wizard = QToolButton() self.cfg_collections_wizard.setIcon(QIcon(I('wizard.png'))) self.cfg_collections_wizard.setToolTip("Create a custom column for Marvin collection assignments") self.cfg_collections_wizard.clicked.connect(partial(self.launch_cc_wizard, 'Collections')) self.cfg_custom_fields_qgl.addWidget(self.cfg_collections_wizard, current_row, 2) current_row += 1 # ++++++++ Last read ++++++++ self.cfg_date_read_label = QLabel("Last read") self.cfg_date_read_label.setAlignment(Qt.AlignLeft) self.cfg_custom_fields_qgl.addWidget(self.cfg_date_read_label, current_row, 0) self.date_read_field_comboBox = QComboBox(self.cfg_custom_fields_gb) self.date_read_field_comboBox.setObjectName('date_read_field_comboBox') self.date_read_field_comboBox.setToolTip('Select a custom column to store Last read date') self.cfg_custom_fields_qgl.addWidget(self.date_read_field_comboBox, current_row, 1) self.cfg_collections_wizard = QToolButton() self.cfg_collections_wizard.setIcon(QIcon(I('wizard.png'))) self.cfg_collections_wizard.setToolTip("Create a custom column to store Last read date") self.cfg_collections_wizard.clicked.connect(partial(self.launch_cc_wizard, 'Last read')) self.cfg_custom_fields_qgl.addWidget(self.cfg_collections_wizard, current_row, 2) current_row += 1 # ++++++++ Locked ++++++++ self.cfg_locked_label = QLabel("Locked") self.cfg_locked_label.setAlignment(Qt.AlignLeft) self.cfg_custom_fields_qgl.addWidget(self.cfg_locked_label, current_row, 0) self.locked_field_comboBox = QComboBox(self.cfg_custom_fields_gb) self.locked_field_comboBox.setObjectName('locked_field_comboBox') self.locked_field_comboBox.setToolTip('Select a custom column to store Locked status') self.cfg_custom_fields_qgl.addWidget(self.locked_field_comboBox, current_row, 1) self.cfg_locked_wizard = QToolButton() self.cfg_locked_wizard.setIcon(QIcon(I('wizard.png'))) self.cfg_locked_wizard.setToolTip("Create a custom column to store Locked status") self.cfg_locked_wizard.clicked.connect(partial(self.launch_cc_wizard, 'Locked')) self.cfg_custom_fields_qgl.addWidget(self.cfg_locked_wizard, current_row, 2) current_row += 1 # ++++++++ Progress ++++++++ self.cfg_progress_label = QLabel('Progress') self.cfg_progress_label.setAlignment(Qt.AlignLeft) self.cfg_custom_fields_qgl.addWidget(self.cfg_progress_label, current_row, 0) self.progress_field_comboBox = QComboBox(self.cfg_custom_fields_gb) self.progress_field_comboBox.setObjectName('progress_field_comboBox') self.progress_field_comboBox.setToolTip('Select a custom column to store Marvin reading progress') self.cfg_custom_fields_qgl.addWidget(self.progress_field_comboBox, current_row, 1) self.cfg_progress_wizard = QToolButton() self.cfg_progress_wizard.setIcon(QIcon(I('wizard.png'))) self.cfg_progress_wizard.setToolTip("Create a custom column to store Marvin reading progress") self.cfg_progress_wizard.clicked.connect(partial(self.launch_cc_wizard, 'Progress')) self.cfg_custom_fields_qgl.addWidget(self.cfg_progress_wizard, current_row, 2) current_row += 1 # ++++++++ Read flag ++++++++ self.cfg_read_label = QLabel('Read') self.cfg_read_label.setAlignment(Qt.AlignLeft) self.cfg_custom_fields_qgl.addWidget(self.cfg_read_label, current_row, 0) self.read_field_comboBox = QComboBox(self.cfg_custom_fields_gb) self.read_field_comboBox.setObjectName('read_field_comboBox') self.read_field_comboBox.setToolTip('Select a custom column to store Marvin Read status') self.cfg_custom_fields_qgl.addWidget(self.read_field_comboBox, current_row, 1) self.cfg_read_wizard = QToolButton() self.cfg_read_wizard.setIcon(QIcon(I('wizard.png'))) self.cfg_read_wizard.setToolTip("Create a custom column to store Marvin Read status") self.cfg_read_wizard.clicked.connect(partial(self.launch_cc_wizard, 'Read')) self.cfg_custom_fields_qgl.addWidget(self.cfg_read_wizard, current_row, 2) current_row += 1 # ++++++++ Reading list flag ++++++++ self.cfg_reading_list_label = QLabel('Reading list') self.cfg_reading_list_label.setAlignment(Qt.AlignLeft) self.cfg_custom_fields_qgl.addWidget(self.cfg_reading_list_label, current_row, 0) self.reading_list_field_comboBox = QComboBox(self.cfg_custom_fields_gb) self.reading_list_field_comboBox.setObjectName('reading_list_field_comboBox') self.reading_list_field_comboBox.setToolTip('Select a custom column to store Marvin Reading list status') self.cfg_custom_fields_qgl.addWidget(self.reading_list_field_comboBox, current_row, 1) self.cfg_reading_list_wizard = QToolButton() self.cfg_reading_list_wizard.setIcon(QIcon(I('wizard.png'))) self.cfg_reading_list_wizard.setToolTip("Create a custom column to store Marvin Reading list status") self.cfg_reading_list_wizard.clicked.connect(partial(self.launch_cc_wizard, 'Reading list')) self.cfg_custom_fields_qgl.addWidget(self.cfg_reading_list_wizard, current_row, 2) current_row += 1 # ++++++++ Word count ++++++++ self.cfg_word_count_label = QLabel('Word count') self.cfg_word_count_label.setAlignment(Qt.AlignLeft) self.cfg_custom_fields_qgl.addWidget(self.cfg_word_count_label, current_row, 0) self.word_count_field_comboBox = QComboBox(self.cfg_custom_fields_gb) self.word_count_field_comboBox.setObjectName('word_count_field_comboBox') self.word_count_field_comboBox.setToolTip('Select a custom column to store Marvin word counts') self.cfg_custom_fields_qgl.addWidget(self.word_count_field_comboBox, current_row, 1) self.cfg_word_count_wizard = QToolButton() self.cfg_word_count_wizard.setIcon(QIcon(I('wizard.png'))) self.cfg_word_count_wizard.setToolTip("Create a custom column to store Marvin word counts") self.cfg_word_count_wizard.clicked.connect(partial(self.launch_cc_wizard, 'Word count')) self.cfg_custom_fields_qgl.addWidget(self.cfg_word_count_wizard, current_row, 2) current_row += 1 self.spacerItem1 = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Expanding) self.column1_layout.addItem(self.spacerItem1) # ----------------------------- Column 2 ----------------------------- # ~~~~~~~~ Create the CSS group box ~~~~~~~~ self.cfg_css_options_gb = QGroupBox(self) self.cfg_css_options_gb.setTitle('CSS') self.column2_layout.addWidget(self.cfg_css_options_gb) self.cfg_css_options_qgl = QGridLayout(self.cfg_css_options_gb) current_row = 0 # ++++++++ Annotations appearance ++++++++ self.annotations_icon = QIcon(os.path.join(self.resources_path, 'icons', 'annotations_hiliter.png')) self.cfg_annotations_appearance_toolbutton = QToolButton() self.cfg_annotations_appearance_toolbutton.setIcon(self.annotations_icon) self.cfg_annotations_appearance_toolbutton.clicked.connect(self.configure_appearance) self.cfg_css_options_qgl.addWidget(self.cfg_annotations_appearance_toolbutton, current_row, 0) self.cfg_annotations_label = ClickableQLabel("Book notes, Bookmark notes and Annotations") self.connect(self.cfg_annotations_label, SIGNAL('clicked()'), self.configure_appearance) self.cfg_css_options_qgl.addWidget(self.cfg_annotations_label, current_row, 1) current_row += 1 # ++++++++ Injected CSS ++++++++ self.css_editor_icon = QIcon(I('format-text-heading.png')) self.cfg_css_editor_toolbutton = QToolButton() self.cfg_css_editor_toolbutton.setIcon(self.css_editor_icon) self.cfg_css_editor_toolbutton.clicked.connect(self.edit_css) self.cfg_css_options_qgl.addWidget(self.cfg_css_editor_toolbutton, current_row, 0) self.cfg_css_editor_label = ClickableQLabel("Articles, Vocabulary") self.connect(self.cfg_css_editor_label, SIGNAL('clicked()'), self.edit_css) self.cfg_css_options_qgl.addWidget(self.cfg_css_editor_label, current_row, 1) """ # ~~~~~~~~ Create the Dropbox syncing group box ~~~~~~~~ self.cfg_dropbox_syncing_gb = QGroupBox(self) self.cfg_dropbox_syncing_gb.setTitle('Dropbox') self.column2_layout.addWidget(self.cfg_dropbox_syncing_gb) self.cfg_dropbox_syncing_qgl = QGridLayout(self.cfg_dropbox_syncing_gb) current_row = 0 # ++++++++ Syncing enabled checkbox ++++++++ self.dropbox_syncing_checkbox = QCheckBox('Enable Dropbox updates') self.dropbox_syncing_checkbox.setObjectName('dropbox_syncing') self.dropbox_syncing_checkbox.setToolTip('Refresh custom column content from Marvin metadata') self.cfg_dropbox_syncing_qgl.addWidget(self.dropbox_syncing_checkbox, current_row, 0, 1, 3) current_row += 1 # ++++++++ Dropbox folder picker ++++++++ self.dropbox_folder_icon = QIcon(os.path.join(self.resources_path, 'icons', 'dropbox.png')) self.cfg_dropbox_folder_toolbutton = QToolButton() self.cfg_dropbox_folder_toolbutton.setIcon(self.dropbox_folder_icon) self.cfg_dropbox_folder_toolbutton.setToolTip("Specify Dropbox folder location on your computer") self.cfg_dropbox_folder_toolbutton.clicked.connect(self.select_dropbox_folder) self.cfg_dropbox_syncing_qgl.addWidget(self.cfg_dropbox_folder_toolbutton, current_row, 1) # ++++++++ Dropbox location lineedit ++++++++ self.dropbox_location_lineedit = QLineEdit() self.dropbox_location_lineedit.setPlaceholderText("Dropbox folder location") self.cfg_dropbox_syncing_qgl.addWidget(self.dropbox_location_lineedit, current_row, 2) """ # ~~~~~~~~ Create the General options group box ~~~~~~~~ self.cfg_runtime_options_gb = QGroupBox(self) self.cfg_runtime_options_gb.setTitle('General options') self.column2_layout.addWidget(self.cfg_runtime_options_gb) self.cfg_runtime_options_qvl = QVBoxLayout(self.cfg_runtime_options_gb) # ++++++++ Temporary markers: Duplicates ++++++++ self.duplicate_markers_checkbox = QCheckBox('Apply temporary markers to duplicate books') self.duplicate_markers_checkbox.setObjectName('apply_markers_to_duplicates') self.duplicate_markers_checkbox.setToolTip('Books with identical content will be flagged in the Library window') self.cfg_runtime_options_qvl.addWidget(self.duplicate_markers_checkbox) # ++++++++ Temporary markers: Updated ++++++++ self.updated_markers_checkbox = QCheckBox('Apply temporary markers to books with updated content') self.updated_markers_checkbox.setObjectName('apply_markers_to_updated') self.updated_markers_checkbox.setToolTip('Books with updated content will be flagged in the Library window') self.cfg_runtime_options_qvl.addWidget(self.updated_markers_checkbox) # ++++++++ Auto refresh checkbox ++++++++ self.auto_refresh_checkbox = QCheckBox('Automatically refresh custom column content') self.auto_refresh_checkbox.setObjectName('auto_refresh_at_startup') self.auto_refresh_checkbox.setToolTip('Update calibre custom column when Marvin XD is opened') self.cfg_runtime_options_qvl.addWidget(self.auto_refresh_checkbox) # ++++++++ Progress as percentage checkbox ++++++++ self.reading_progress_checkbox = QCheckBox('Show reading progress as percentage') self.reading_progress_checkbox.setObjectName('show_progress_as_percentage') self.reading_progress_checkbox.setToolTip('Display percentage in Progress column') self.cfg_runtime_options_qvl.addWidget(self.reading_progress_checkbox) # ~~~~~~~~ Create the Debug options group box ~~~~~~~~ self.cfg_debug_options_gb = QGroupBox(self) self.cfg_debug_options_gb.setTitle('Debug options') self.column2_layout.addWidget(self.cfg_debug_options_gb) self.cfg_debug_options_qvl = QVBoxLayout(self.cfg_debug_options_gb) # ++++++++ Debug logging checkboxes ++++++++ self.debug_plugin_checkbox = QCheckBox('Enable debug logging for Marvin XD') self.debug_plugin_checkbox.setObjectName('debug_plugin_checkbox') self.debug_plugin_checkbox.setToolTip('Print plugin diagnostic messages to console') self.cfg_debug_options_qvl.addWidget(self.debug_plugin_checkbox) self.debug_libimobiledevice_checkbox = QCheckBox('Enable debug logging for libiMobileDevice') self.debug_libimobiledevice_checkbox.setObjectName('debug_libimobiledevice_checkbox') self.debug_libimobiledevice_checkbox.setToolTip('Print libiMobileDevice diagnostic messages to console') self.cfg_debug_options_qvl.addWidget(self.debug_libimobiledevice_checkbox) self.spacerItem2 = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Expanding) self.column2_layout.addItem(self.spacerItem2) # ~~~~~~~~ End of construction zone ~~~~~~~~ self.resize(self.sizeHint()) # ~~~~~~~~ Populate/restore config options ~~~~~~~~ # Annotations comboBox self.populate_annotations() self.populate_collections() self.populate_date_read() self.populate_locked() self.populate_progress() self.populate_read() self.populate_reading_list() self.populate_word_count() """ # Restore Dropbox settings, hook changes dropbox_syncing = self.prefs.get('dropbox_syncing', False) self.dropbox_syncing_checkbox.setChecked(dropbox_syncing) self.set_dropbox_syncing(dropbox_syncing) self.dropbox_syncing_checkbox.clicked.connect(partial(self.set_dropbox_syncing)) self.dropbox_location_lineedit.setText(self.prefs.get('dropbox_folder', '')) """ # Restore general settings self.duplicate_markers_checkbox.setChecked(self.prefs.get('apply_markers_to_duplicates', True)) self.updated_markers_checkbox.setChecked(self.prefs.get('apply_markers_to_updated', True)) self.auto_refresh_checkbox.setChecked(self.prefs.get('auto_refresh_at_startup', False)) self.reading_progress_checkbox.setChecked(self.prefs.get('show_progress_as_percentage', False)) # Restore debug settings, hook changes self.debug_plugin_checkbox.setChecked(self.prefs.get('debug_plugin', False)) self.debug_plugin_checkbox.stateChanged.connect(self.set_restart_required) self.debug_libimobiledevice_checkbox.setChecked(self.prefs.get('debug_libimobiledevice', False)) self.debug_libimobiledevice_checkbox.stateChanged.connect(self.set_restart_required) # Hook changes to Annotations comboBox # self.annotations_field_comboBox.currentIndexChanged.connect( # partial(self.save_combobox_setting, 'annotations_field_comboBox')) self.connect(self.annotations_field_comboBox, SIGNAL('currentIndexChanged(const QString &)'), self.annotations_destination_changed) # Launch the annotated_books_scanner field = get_cc_mapping('annotations', 'field', None) self.annotated_books_scanner = InventoryAnnotatedBooks(self.gui, field) self.connect(self.annotated_books_scanner, self.annotated_books_scanner.signal, self.inventory_complete) QTimer.singleShot(1, self.start_inventory)
def initialize(self, parent, book_title, calibre_collections, marvin_collections, connected_device): ''' __init__ is called on SizePersistedDialog() if calibre_collections is None, the book does not exist in calibre library ''' self.setupUi(self) self.calibre_collections = calibre_collections self.calibre_selection = None self.marvin_collections = marvin_collections self.marvin_selection = None self.opts = parent.opts self.parent = parent self.stored_command = None self.verbose = parent.verbose self._log_location(book_title) self.setWindowTitle("Collection assignments") # Subscribe to Marvin driver change events connected_device.marvin_device_signals.reader_app_status_changed.connect( self.marvin_status_changed) # ~~~~~~~~ Export to Marvin button ~~~~~~~~ self.export_to_marvin_tb.setIcon( QIcon( os.path.join(self.opts.resources_path, 'icons', 'from_calibre.png'))) self.export_to_marvin_tb.setToolTip( "Export collection assignments to Marvin") self.export_to_marvin_tb.clicked.connect(self._export_to_marvin) # ~~~~~~~~ Import from Marvin button ~~~~~~~~ self.import_from_marvin_tb.setIcon( QIcon( os.path.join(self.opts.resources_path, 'icons', 'from_marvin.png'))) self.import_from_marvin_tb.setToolTip( "Import collection assignments from Marvin") self.import_from_marvin_tb.clicked.connect(self._import_from_marvin) # ~~~~~~~~ Merge collections button ~~~~~~~~ self.merge_collections_tb.setIcon( QIcon( os.path.join(self.opts.resources_path, 'icons', 'sync_collections.png'))) self.merge_collections_tb.setToolTip("Merge collection assignments") self.merge_collections_tb.clicked.connect(self._merge_collections) if ADD_NEW_COLLECTION_ENABLED: self.add_collection_tb.setIcon(QIcon(I('plus.png'))) self.add_collection_tb.setToolTip("Add a collection assignment") self.add_collection_tb.clicked.connect( self.add_collection_assignment) else: self.add_collection_tb.setVisible(False) # ~~~~~~~~Remove collection assignment button ~~~~~~~~ self.remove_assignment_tb.setIcon(QIcon(I('trash.png'))) self.remove_assignment_tb.setToolTip("Remove a collection assignment") self.remove_assignment_tb.clicked.connect( self._remove_collection_assignment) if RENAMING_ENABLED: # ~~~~~~~~ Rename collection button ~~~~~~~~ self.rename_collection_tb.setIcon(QIcon(I('edit_input.png'))) self.rename_collection_tb.setToolTip("Rename collection") self.rename_collection_tb.clicked.connect(self._rename_collection) else: self.rename_collection_tb.setVisible(False) # ~~~~~~~~ Clear all collections button ~~~~~~~~ self.remove_all_assignments_tb.setIcon( QIcon( os.path.join(self.opts.resources_path, 'icons', 'remove_all_collections.png'))) self.remove_all_assignments_tb.setToolTip( "Remove all collection assignments") self.remove_all_assignments_tb.clicked.connect( self._remove_all_assignments) # Populate collection models self._initialize_collections() # Save initial Marvin state self.initial_marvin_collections = list(self._get_marvin_collections()) self.marvin_gb.setToolTip("Collections assigned in Marvin") if self.calibre_collections is not None: # Save initial state self.initial_calibre_collections = list( self._get_calibre_collections()) # Remind the user of calibre's custom column, disable buttons if no calibre field calibre_cf = get_cc_mapping('collections', 'combobox', '') if calibre_cf: self.calibre_gb.setTitle("calibre ('%s')" % calibre_cf) self.calibre_gb.setToolTip("Collection assignments from '%s'" % calibre_cf) else: self.calibre_gb.setTitle("calibre") self.calibre_gb.setToolTip( "No custom column selected for collection assignments") self.calibre_gb.setEnabled(False) # Disable import/export/sync self.export_to_marvin_tb.setEnabled(False) self.import_from_marvin_tb.setEnabled(False) self.merge_collections_tb.setEnabled(False) if False: # If collections already equal, disable import/export/merge if self.calibre_collections == self.marvin_collections: self.export_to_marvin_tb.setEnabled(False) self.import_from_marvin_tb.setEnabled(False) self.merge_collections_tb.setEnabled(False) else: # No cid, this book is Marvin only # Hide the calibre panel, disable tool buttons self.calibre_gb.setVisible(False) self.export_to_marvin_tb.setEnabled(False) self.import_from_marvin_tb.setEnabled(False) self.merge_collections_tb.setEnabled(False) # Hook the button events self.bb.clicked.connect(self.dispatch_button_click) # Restore position self.resize_dialog()
def initialize(self, parent, book_title, calibre_collections, marvin_collections, connected_device): ''' __init__ is called on SizePersistedDialog() if calibre_collections is None, the book does not exist in calibre library ''' self.setupUi(self) self.calibre_collections = calibre_collections self.calibre_selection = None self.marvin_collections = marvin_collections self.marvin_selection = None self.opts = parent.opts self.parent = parent self.stored_command = None self.verbose = parent.verbose self._log_location(book_title) self.setWindowTitle("Collection assignments") # Subscribe to Marvin driver change events connected_device.marvin_device_signals.reader_app_status_changed.connect( self.marvin_status_changed) # ~~~~~~~~ Export to Marvin button ~~~~~~~~ self.export_to_marvin_tb.setIcon(QIcon(os.path.join(self.opts.resources_path, 'icons', 'from_calibre.png'))) self.export_to_marvin_tb.setToolTip("Export collection assignments to Marvin") self.export_to_marvin_tb.clicked.connect(self._export_to_marvin) # ~~~~~~~~ Import from Marvin button ~~~~~~~~ self.import_from_marvin_tb.setIcon(QIcon(os.path.join(self.opts.resources_path, 'icons', 'from_marvin.png'))) self.import_from_marvin_tb.setToolTip("Import collection assignments from Marvin") self.import_from_marvin_tb.clicked.connect(self._import_from_marvin) # ~~~~~~~~ Merge collections button ~~~~~~~~ self.merge_collections_tb.setIcon(QIcon(os.path.join(self.opts.resources_path, 'icons', 'sync_collections.png'))) self.merge_collections_tb.setToolTip("Merge collection assignments") self.merge_collections_tb.clicked.connect(self._merge_collections) if ADD_NEW_COLLECTION_ENABLED: self.add_collection_tb.setIcon(QIcon(I('plus.png'))) self.add_collection_tb.setToolTip("Add a collection assignment") self.add_collection_tb.clicked.connect(self.add_collection_assignment) else: self.add_collection_tb.setVisible(False) # ~~~~~~~~Remove collection assignment button ~~~~~~~~ self.remove_assignment_tb.setIcon(QIcon(I('trash.png'))) self.remove_assignment_tb.setToolTip("Remove a collection assignment") self.remove_assignment_tb.clicked.connect(self._remove_collection_assignment) if RENAMING_ENABLED: # ~~~~~~~~ Rename collection button ~~~~~~~~ self.rename_collection_tb.setIcon(QIcon(I('edit_input.png'))) self.rename_collection_tb.setToolTip("Rename collection") self.rename_collection_tb.clicked.connect(self._rename_collection) else: self.rename_collection_tb.setVisible(False) # ~~~~~~~~ Clear all collections button ~~~~~~~~ self.remove_all_assignments_tb.setIcon(QIcon(os.path.join(self.opts.resources_path, 'icons', 'remove_all_collections.png'))) self.remove_all_assignments_tb.setToolTip("Remove all collection assignments") self.remove_all_assignments_tb.clicked.connect(self._remove_all_assignments) # Populate collection models self._initialize_collections() # Save initial Marvin state self.initial_marvin_collections = list(self._get_marvin_collections()) self.marvin_gb.setToolTip("Collections assigned in Marvin") if self.calibre_collections is not None: # Save initial state self.initial_calibre_collections = list(self._get_calibre_collections()) # Remind the user of calibre's custom column, disable buttons if no calibre field calibre_cf = get_cc_mapping('collections', 'combobox', '') if calibre_cf: self.calibre_gb.setTitle("calibre ('%s')" % calibre_cf) self.calibre_gb.setToolTip("Collection assignments from '%s'" % calibre_cf) else: self.calibre_gb.setTitle("calibre") self.calibre_gb.setToolTip("No custom column selected for collection assignments") self.calibre_gb.setEnabled(False) # Disable import/export/sync self.export_to_marvin_tb.setEnabled(False) self.import_from_marvin_tb.setEnabled(False) self.merge_collections_tb.setEnabled(False) if False: # If collections already equal, disable import/export/merge if self.calibre_collections == self.marvin_collections: self.export_to_marvin_tb.setEnabled(False) self.import_from_marvin_tb.setEnabled(False) self.merge_collections_tb.setEnabled(False) else: # No cid, this book is Marvin only # Hide the calibre panel, disable tool buttons self.calibre_gb.setVisible(False) self.export_to_marvin_tb.setEnabled(False) self.import_from_marvin_tb.setEnabled(False) self.merge_collections_tb.setEnabled(False) # Hook the button events self.bb.clicked.connect(self.dispatch_button_click) # Restore position self.resize_dialog()
def __init__(self, plugin_action): QWidget.__init__(self) self.parent = plugin_action self.gui = get_gui() self.icon = plugin_action.icon self.opts = plugin_action.opts self.prefs = plugin_prefs self.resources_path = plugin_action.resources_path self.verbose = plugin_action.verbose self.restart_required = False self._log_location() self.l = QGridLayout() self.setLayout(self.l) self.column1_layout = QVBoxLayout() self.l.addLayout(self.column1_layout, 0, 0) self.column2_layout = QVBoxLayout() self.l.addLayout(self.column2_layout, 0, 1) # ----------------------------- Column 1 ----------------------------- # ~~~~~~~~ Create the Custom fields options group box ~~~~~~~~ self.cfg_custom_fields_gb = QGroupBox(self) self.cfg_custom_fields_gb.setTitle('Custom column assignments') self.column1_layout.addWidget(self.cfg_custom_fields_gb) self.cfg_custom_fields_qgl = QGridLayout(self.cfg_custom_fields_gb) current_row = 0 # ++++++++ Labels + HLine ++++++++ self.marvin_source_label = QLabel("Marvin source") self.cfg_custom_fields_qgl.addWidget(self.marvin_source_label, current_row, 0) self.calibre_destination_label = QLabel("calibre destination") self.cfg_custom_fields_qgl.addWidget(self.calibre_destination_label, current_row, 1) current_row += 1 self.sd_hl = QFrame(self.cfg_custom_fields_gb) self.sd_hl.setFrameShape(QFrame.HLine) self.sd_hl.setFrameShadow(QFrame.Raised) self.cfg_custom_fields_qgl.addWidget(self.sd_hl, current_row, 0, 1, 3) current_row += 1 # ++++++++ Annotations ++++++++ self.cfg_annotations_label = QLabel('Annotations') self.cfg_annotations_label.setAlignment(Qt.AlignLeft) self.cfg_custom_fields_qgl.addWidget(self.cfg_annotations_label, current_row, 0) self.annotations_field_comboBox = QComboBox(self.cfg_custom_fields_gb) self.annotations_field_comboBox.setObjectName( 'annotations_field_comboBox') self.annotations_field_comboBox.setToolTip( 'Select a custom column to store Marvin annotations') self.cfg_custom_fields_qgl.addWidget(self.annotations_field_comboBox, current_row, 1) self.cfg_highlights_wizard = QToolButton() self.cfg_highlights_wizard.setIcon(QIcon(I('wizard.png'))) self.cfg_highlights_wizard.setToolTip( "Create a custom column to store Marvin annotations") self.cfg_highlights_wizard.clicked.connect( partial(self.launch_cc_wizard, 'Annotations')) self.cfg_custom_fields_qgl.addWidget(self.cfg_highlights_wizard, current_row, 2) current_row += 1 # ++++++++ Collections ++++++++ self.cfg_collections_label = QLabel('Collections') self.cfg_collections_label.setAlignment(Qt.AlignLeft) self.cfg_custom_fields_qgl.addWidget(self.cfg_collections_label, current_row, 0) self.collection_field_comboBox = QComboBox(self.cfg_custom_fields_gb) self.collection_field_comboBox.setObjectName( 'collection_field_comboBox') self.collection_field_comboBox.setToolTip( 'Select a custom column to store Marvin collection assignments') self.cfg_custom_fields_qgl.addWidget(self.collection_field_comboBox, current_row, 1) self.cfg_collections_wizard = QToolButton() self.cfg_collections_wizard.setIcon(QIcon(I('wizard.png'))) self.cfg_collections_wizard.setToolTip( "Create a custom column for Marvin collection assignments") self.cfg_collections_wizard.clicked.connect( partial(self.launch_cc_wizard, 'Collections')) self.cfg_custom_fields_qgl.addWidget(self.cfg_collections_wizard, current_row, 2) current_row += 1 # ++++++++ Last read ++++++++ self.cfg_date_read_label = QLabel("Last read") self.cfg_date_read_label.setAlignment(Qt.AlignLeft) self.cfg_custom_fields_qgl.addWidget(self.cfg_date_read_label, current_row, 0) self.date_read_field_comboBox = QComboBox(self.cfg_custom_fields_gb) self.date_read_field_comboBox.setObjectName('date_read_field_comboBox') self.date_read_field_comboBox.setToolTip( 'Select a custom column to store Last read date') self.cfg_custom_fields_qgl.addWidget(self.date_read_field_comboBox, current_row, 1) self.cfg_collections_wizard = QToolButton() self.cfg_collections_wizard.setIcon(QIcon(I('wizard.png'))) self.cfg_collections_wizard.setToolTip( "Create a custom column to store Last read date") self.cfg_collections_wizard.clicked.connect( partial(self.launch_cc_wizard, 'Last read')) self.cfg_custom_fields_qgl.addWidget(self.cfg_collections_wizard, current_row, 2) current_row += 1 # ++++++++ Progress ++++++++ self.cfg_progress_label = QLabel('Progress') self.cfg_progress_label.setAlignment(Qt.AlignLeft) self.cfg_custom_fields_qgl.addWidget(self.cfg_progress_label, current_row, 0) self.progress_field_comboBox = QComboBox(self.cfg_custom_fields_gb) self.progress_field_comboBox.setObjectName('progress_field_comboBox') self.progress_field_comboBox.setToolTip( 'Select a custom column to store Marvin reading progress') self.cfg_custom_fields_qgl.addWidget(self.progress_field_comboBox, current_row, 1) self.cfg_progress_wizard = QToolButton() self.cfg_progress_wizard.setIcon(QIcon(I('wizard.png'))) self.cfg_progress_wizard.setToolTip( "Create a custom column to store Marvin reading progress") self.cfg_progress_wizard.clicked.connect( partial(self.launch_cc_wizard, 'Progress')) self.cfg_custom_fields_qgl.addWidget(self.cfg_progress_wizard, current_row, 2) current_row += 1 # ++++++++ Read flag ++++++++ self.cfg_read_label = QLabel('Read') self.cfg_read_label.setAlignment(Qt.AlignLeft) self.cfg_custom_fields_qgl.addWidget(self.cfg_read_label, current_row, 0) self.read_field_comboBox = QComboBox(self.cfg_custom_fields_gb) self.read_field_comboBox.setObjectName('read_field_comboBox') self.read_field_comboBox.setToolTip( 'Select a custom column to store Marvin Read status') self.cfg_custom_fields_qgl.addWidget(self.read_field_comboBox, current_row, 1) self.cfg_read_wizard = QToolButton() self.cfg_read_wizard.setIcon(QIcon(I('wizard.png'))) self.cfg_read_wizard.setToolTip( "Create a custom column to store Marvin Read status") self.cfg_read_wizard.clicked.connect( partial(self.launch_cc_wizard, 'Read')) self.cfg_custom_fields_qgl.addWidget(self.cfg_read_wizard, current_row, 2) current_row += 1 # ++++++++ Reading list flag ++++++++ self.cfg_reading_list_label = QLabel('Reading list') self.cfg_reading_list_label.setAlignment(Qt.AlignLeft) self.cfg_custom_fields_qgl.addWidget(self.cfg_reading_list_label, current_row, 0) self.reading_list_field_comboBox = QComboBox(self.cfg_custom_fields_gb) self.reading_list_field_comboBox.setObjectName( 'reading_list_field_comboBox') self.reading_list_field_comboBox.setToolTip( 'Select a custom column to store Marvin Reading list status') self.cfg_custom_fields_qgl.addWidget(self.reading_list_field_comboBox, current_row, 1) self.cfg_reading_list_wizard = QToolButton() self.cfg_reading_list_wizard.setIcon(QIcon(I('wizard.png'))) self.cfg_reading_list_wizard.setToolTip( "Create a custom column to store Marvin Reading list status") self.cfg_reading_list_wizard.clicked.connect( partial(self.launch_cc_wizard, 'Reading list')) self.cfg_custom_fields_qgl.addWidget(self.cfg_reading_list_wizard, current_row, 2) current_row += 1 # ++++++++ Word count ++++++++ self.cfg_word_count_label = QLabel('Word count') self.cfg_word_count_label.setAlignment(Qt.AlignLeft) self.cfg_custom_fields_qgl.addWidget(self.cfg_word_count_label, current_row, 0) self.word_count_field_comboBox = QComboBox(self.cfg_custom_fields_gb) self.word_count_field_comboBox.setObjectName( 'word_count_field_comboBox') self.word_count_field_comboBox.setToolTip( 'Select a custom column to store Marvin word counts') self.cfg_custom_fields_qgl.addWidget(self.word_count_field_comboBox, current_row, 1) self.cfg_word_count_wizard = QToolButton() self.cfg_word_count_wizard.setIcon(QIcon(I('wizard.png'))) self.cfg_word_count_wizard.setToolTip( "Create a custom column to store Marvin word counts") self.cfg_word_count_wizard.clicked.connect( partial(self.launch_cc_wizard, 'Word count')) self.cfg_custom_fields_qgl.addWidget(self.cfg_word_count_wizard, current_row, 2) current_row += 1 self.spacerItem1 = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Expanding) self.column1_layout.addItem(self.spacerItem1) # ----------------------------- Column 2 ----------------------------- # ~~~~~~~~ Create the CSS group box ~~~~~~~~ self.cfg_css_options_gb = QGroupBox(self) self.cfg_css_options_gb.setTitle('CSS') self.column2_layout.addWidget(self.cfg_css_options_gb) self.cfg_css_options_qgl = QGridLayout(self.cfg_css_options_gb) current_row = 0 # ++++++++ Annotations appearance ++++++++ self.annotations_icon = QIcon( os.path.join(self.resources_path, 'icons', 'annotations_hiliter.png')) self.cfg_annotations_appearance_toolbutton = QToolButton() self.cfg_annotations_appearance_toolbutton.setIcon( self.annotations_icon) self.cfg_annotations_appearance_toolbutton.clicked.connect( self.configure_appearance) self.cfg_css_options_qgl.addWidget( self.cfg_annotations_appearance_toolbutton, current_row, 0) self.cfg_annotations_label = ClickableQLabel("Annotations") self.connect(self.cfg_annotations_label, SIGNAL('clicked()'), self.configure_appearance) self.cfg_css_options_qgl.addWidget(self.cfg_annotations_label, current_row, 1) current_row += 1 # ++++++++ Injected CSS ++++++++ self.css_editor_icon = QIcon(I('format-text-heading.png')) self.cfg_css_editor_toolbutton = QToolButton() self.cfg_css_editor_toolbutton.setIcon(self.css_editor_icon) self.cfg_css_editor_toolbutton.clicked.connect(self.edit_css) self.cfg_css_options_qgl.addWidget(self.cfg_css_editor_toolbutton, current_row, 0) self.cfg_css_editor_label = ClickableQLabel("Articles, Vocabulary") self.connect(self.cfg_css_editor_label, SIGNAL('clicked()'), self.edit_css) self.cfg_css_options_qgl.addWidget(self.cfg_css_editor_label, current_row, 1) """ # ~~~~~~~~ Create the Dropbox syncing group box ~~~~~~~~ self.cfg_dropbox_syncing_gb = QGroupBox(self) self.cfg_dropbox_syncing_gb.setTitle('Dropbox') self.column2_layout.addWidget(self.cfg_dropbox_syncing_gb) self.cfg_dropbox_syncing_qgl = QGridLayout(self.cfg_dropbox_syncing_gb) current_row = 0 # ++++++++ Syncing enabled checkbox ++++++++ self.dropbox_syncing_checkbox = QCheckBox('Enable Dropbox updates') self.dropbox_syncing_checkbox.setObjectName('dropbox_syncing') self.dropbox_syncing_checkbox.setToolTip('Refresh custom column content from Marvin metadata') self.cfg_dropbox_syncing_qgl.addWidget(self.dropbox_syncing_checkbox, current_row, 0, 1, 3) current_row += 1 # ++++++++ Dropbox folder picker ++++++++ self.dropbox_folder_icon = QIcon(os.path.join(self.resources_path, 'icons', 'dropbox.png')) self.cfg_dropbox_folder_toolbutton = QToolButton() self.cfg_dropbox_folder_toolbutton.setIcon(self.dropbox_folder_icon) self.cfg_dropbox_folder_toolbutton.setToolTip("Specify Dropbox folder location on your computer") self.cfg_dropbox_folder_toolbutton.clicked.connect(self.select_dropbox_folder) self.cfg_dropbox_syncing_qgl.addWidget(self.cfg_dropbox_folder_toolbutton, current_row, 1) # ++++++++ Dropbox location lineedit ++++++++ self.dropbox_location_lineedit = QLineEdit() self.dropbox_location_lineedit.setPlaceholderText("Dropbox folder location") self.cfg_dropbox_syncing_qgl.addWidget(self.dropbox_location_lineedit, current_row, 2) """ # ~~~~~~~~ Create the General options group box ~~~~~~~~ self.cfg_runtime_options_gb = QGroupBox(self) self.cfg_runtime_options_gb.setTitle('General options') self.column2_layout.addWidget(self.cfg_runtime_options_gb) self.cfg_runtime_options_qvl = QVBoxLayout(self.cfg_runtime_options_gb) # ++++++++ Auto refresh checkbox ++++++++ self.auto_refresh_checkbox = QCheckBox( 'Automatically refresh custom column content') self.auto_refresh_checkbox.setObjectName('auto_refresh_at_startup') self.auto_refresh_checkbox.setToolTip( 'Update calibre custom column when Marvin XD is opened') self.cfg_runtime_options_qvl.addWidget(self.auto_refresh_checkbox) # ++++++++ Progress as percentage checkbox ++++++++ self.reading_progress_checkbox = QCheckBox( 'Show reading progress as percentage') self.reading_progress_checkbox.setObjectName( 'show_progress_as_percentage') self.reading_progress_checkbox.setToolTip( 'Display percentage in Progress column') self.cfg_runtime_options_qvl.addWidget(self.reading_progress_checkbox) # ~~~~~~~~ Create the Debug options group box ~~~~~~~~ self.cfg_debug_options_gb = QGroupBox(self) self.cfg_debug_options_gb.setTitle('Debug options') self.column2_layout.addWidget(self.cfg_debug_options_gb) self.cfg_debug_options_qvl = QVBoxLayout(self.cfg_debug_options_gb) # ++++++++ Debug logging checkboxes ++++++++ self.debug_plugin_checkbox = QCheckBox( 'Enable debug logging for Marvin XD') self.debug_plugin_checkbox.setObjectName('debug_plugin_checkbox') self.debug_plugin_checkbox.setToolTip( 'Print plugin diagnostic messages to console') self.cfg_debug_options_qvl.addWidget(self.debug_plugin_checkbox) self.debug_libimobiledevice_checkbox = QCheckBox( 'Enable debug logging for libiMobileDevice') self.debug_libimobiledevice_checkbox.setObjectName( 'debug_libimobiledevice_checkbox') self.debug_libimobiledevice_checkbox.setToolTip( 'Print libiMobileDevice diagnostic messages to console') self.cfg_debug_options_qvl.addWidget( self.debug_libimobiledevice_checkbox) self.spacerItem2 = QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Expanding) self.column2_layout.addItem(self.spacerItem2) # ~~~~~~~~ End of construction zone ~~~~~~~~ self.resize(self.sizeHint()) # ~~~~~~~~ Populate/restore config options ~~~~~~~~ # Annotations comboBox self.populate_annotations() self.populate_collections() self.populate_date_read() self.populate_progress() self.populate_read() self.populate_reading_list() self.populate_word_count() """ # Restore Dropbox settings, hook changes dropbox_syncing = self.prefs.get('dropbox_syncing', False) self.dropbox_syncing_checkbox.setChecked(dropbox_syncing) self.set_dropbox_syncing(dropbox_syncing) self.dropbox_syncing_checkbox.clicked.connect(partial(self.set_dropbox_syncing)) self.dropbox_location_lineedit.setText(self.prefs.get('dropbox_folder', '')) """ # Restore general settings self.auto_refresh_checkbox.setChecked( self.prefs.get('auto_refresh_at_startup', False)) self.reading_progress_checkbox.setChecked( self.prefs.get('show_progress_as_percentage', False)) # Restore debug settings, hook changes self.debug_plugin_checkbox.setChecked( self.prefs.get('debug_plugin', False)) self.debug_plugin_checkbox.stateChanged.connect( self.set_restart_required) self.debug_libimobiledevice_checkbox.setChecked( self.prefs.get('debug_libimobiledevice', False)) self.debug_libimobiledevice_checkbox.stateChanged.connect( self.set_restart_required) # Hook changes to Annotations comboBox # self.annotations_field_comboBox.currentIndexChanged.connect( # partial(self.save_combobox_setting, 'annotations_field_comboBox')) self.connect(self.annotations_field_comboBox, SIGNAL('currentIndexChanged(const QString &)'), self.annotations_destination_changed) # Launch the annotated_books_scanner field = get_cc_mapping('annotations', 'field', None) self.annotated_books_scanner = InventoryAnnotatedBooks(self.gui, field) self.connect(self.annotated_books_scanner, self.annotated_books_scanner.signal, self.inventory_complete) QTimer.singleShot(1, self.start_inventory)
def _update_calibre_metadata(self, book, cid): ''' Update cid mapped custom columns from book metadata Annotations comments html annotations Collections text collections Last read datetime date_read *Notes comments html Progress float 50.0 progress *Rating Read bool True|False|None read Reading list bool True|False|None reading_list Word count int 12345 word_count ''' CUSTOM_COLUMN_MAPPINGS = { 'Annotations': { 'attribute': './annotations', 'datatype': 'comments', 'lookup': get_cc_mapping('annotations', 'field', None) }, 'Collections': { 'attribute': './collections/collection', 'datatype': 'text', 'lookup': get_cc_mapping('collections', 'field', None) }, 'Last read': { 'attribute': 'dateopened', 'datatype': 'datetime', 'lookup': get_cc_mapping('date_read', 'field', None) }, 'Progress': { 'attribute': 'progress', 'datatype': 'float', 'lookup': get_cc_mapping('progress', 'field', None) }, 'Read': { 'attribute': 'isread', 'datatype': 'bool', 'lookup': get_cc_mapping('read', 'field', None) }, 'Reading list': { 'attribute': 'readinglist', 'datatype': 'bool', 'lookup': get_cc_mapping('reading_list', 'field', None) }, 'Word count': { 'attribute': 'wordcount', 'datatype': 'int', 'lookup': get_cc_mapping('word_count', 'field', None) } } # Don't show floats less than FLOAT_THRESHOLD FLOAT_THRESHOLD = 1.0 self._log_location(book.attrib['title']) mi = self.db.get_metadata(cid, index_is_id=True) mi_updated = False for ccm in CUSTOM_COLUMN_MAPPINGS: mapping = CUSTOM_COLUMN_MAPPINGS[ccm] lookup = self.prefs.get(mapping['lookup'], None) if lookup: um = mi.metadata_for_field(lookup) datatype = mapping['datatype'] if ccm in ['Annotations']: ''' # Not sure if we'll need this, depends on how Kris returns annotations if re.match(self.UTF_8_BOM, anns): anns = UnicodeDammit(anns).unicode ''' ann_el = book.find(mapping['attribute']) if ann_el is not None: anns = '' for sub_element in ['head', 'body']: el = ann_el.find(sub_element) anns += etree.tostring(el) anns = self._inject_css(anns).encode('utf-8') anns = "<?xml version='1.0' encoding='utf-8'?>" + anns um['#value#'] = anns mi.set_user_metadata(lookup, um) mi_updated = True elif ccm in ['Collections']: cels = book.findall(mapping['attribute']) um['#value#'] = [unicode(cel.text) for cel in cels] mi.set_user_metadata(lookup, um) mi_updated = True else: if datatype == 'bool': um['#value#'] = None if book.attrib[mapping['attribute']] == '1': um['#value#'] = True elif datatype == 'datetime': ts = time.strftime( "%Y-%m-%d %H:%M", time.localtime( float(book.attrib[mapping['attribute']]))) um['#value#'] = ts elif datatype == 'float': val = float(book.attrib[mapping['attribute']]) * 100 if val < FLOAT_THRESHOLD: val = None um['#value#'] = val elif datatype == 'int': val = book.attrib[mapping['attribute']] if val > '': um['#value#'] = int(val) else: self._log("*** datatype '{0}' not handled ***".format( datatype)) mi.set_user_metadata(lookup, um) mi_updated = True if mi_updated: self.db.set_metadata(cid, mi, set_title=False, set_authors=False, commit=True, force_changes=True)