Exemplo n.º 1
0
 def data(self, index, role):
     if not index.isValid():
         return NONE
     if index.internalId() == 0:
         if role == Qt.DisplayRole:
             category = self.categories[index.row()]
             return QVariant(_("%(plugin_type)s %(plugins)s")%\
                     dict(plugin_type=category, plugins=_('plugins')))
     else:
         plugin = self.index_to_plugin(index)
         if role == Qt.DisplayRole:
             ver = '.'.join(map(str, plugin.version))
             desc = '\n'.join(textwrap.wrap(plugin.description, 100))
             ans='%s (%s) %s %s\n%s'%(plugin.name, ver, _('by'), plugin.author, desc)
             c = plugin_customization(plugin)
             if c:
                 ans += _('\nCustomization: ')+c
             return QVariant(ans)
         if role == Qt.DecorationRole:
             return self.disabled_icon if is_disabled(plugin) else self.icon
         if role == Qt.ForegroundRole and is_disabled(plugin):
             return QVariant(QBrush(Qt.gray))
         if role == Qt.UserRole:
             return plugin
     return NONE
Exemplo n.º 2
0
 def data(self, index, role):
     if not index.isValid():
         return NONE
     if index.internalId() == 0:
         if role == Qt.DisplayRole:
             category = self.categories[index.row()]
             return QVariant(_("%(plugin_type)s %(plugins)s")%\
                     dict(plugin_type=category, plugins=_('plugins')))
     else:
         plugin = self.index_to_plugin(index)
         if role == Qt.DisplayRole:
             ver = '.'.join(map(str, plugin.version))
             desc = '\n'.join(textwrap.wrap(plugin.description, 100))
             ans = '%s (%s) %s %s\n%s' % (plugin.name, ver, _('by'),
                                          plugin.author, desc)
             c = plugin_customization(plugin)
             if c:
                 ans += _('\nCustomization: ') + c
             return QVariant(ans)
         if role == Qt.DecorationRole:
             return self.disabled_icon if is_disabled(plugin) else self.icon
         if role == Qt.ForegroundRole and is_disabled(plugin):
             return QVariant(QBrush(Qt.gray))
         if role == Qt.UserRole:
             return plugin
     return NONE
Exemplo n.º 3
0
 def data(self, index, role):
     row, col = index.row(), index.column()
     result = self.matches[row]
     if role in (Qt.DisplayRole, Qt.EditRole):
         if col == 1:
             return QVariant('<b>%s</b><br><i>%s</i>' %
                             (result.name, result.description))
         elif col == 3:
             return QVariant(result.headquarters)
         elif col == 5:
             return QVariant(', '.join(result.formats).upper())
     elif role == Qt.DecorationRole:
         if col == 2:
             if result.drm_free_only:
                 return QVariant(self.NO_DRM_ICON)
         if col == 4:
             if result.affiliate:
                 return QVariant(self.DONATE_ICON)
     elif role == Qt.CheckStateRole:
         if col == 0:
             if is_disabled(result):
                 return Qt.Unchecked
             return Qt.Checked
     elif role == Qt.ToolTipRole:
         if col == 0:
             if is_disabled(result):
                 return QVariant('<p>' + _(
                     'This store is currently disabled and cannot be used in other parts of calibre.'
                 ) + '</p>')
             else:
                 return QVariant('<p>' + _(
                     'This store is currently enabled and can be used in other parts of calibre.'
                 ) + '</p>')
         elif col == 1:
             return QVariant('<p>%s</p>' % result.description)
         elif col == 2:
             if result.drm_free_only:
                 return QVariant(
                     '<p>' +
                     _('This store only distributes ebooks without DRM.') +
                     '</p>')
             else:
                 return QVariant('<p>' + _(
                     'This store distributes ebooks with DRM. It may have some titles without DRM, but you will need to check on a per title basis.'
                 ) + '</p>')
         elif col == 3:
             return QVariant('<p>' + _(
                 'This store is headquartered in %s. This is a good indication of what market the store caters to. However, this does not necessarily mean that the store is limited to that market only.'
             ) % result.headquarters + '</p>')
         elif col == 4:
             if result.affiliate:
                 return QVariant('<p>' + _(
                     'Buying from this store supports the calibre developer: %s.'
                 ) % result.author + '</p>')
         elif col == 5:
             return QVariant('<p>' + _(
                 'This store distributes ebooks in the following formats: %s'
             ) % ', '.join(result.formats) + '</p>')
     return NONE
Exemplo n.º 4
0
    def data(self, index, role):
        try:
            plugin = self.plugins[index.row()]
        except:
            return NONE
        col = index.column()

        if role == Qt.DisplayRole:
            if col == 0:
                return plugin.name
            elif col == 1:
                orig = msprefs['cover_priorities'].get(plugin.name, 1)
                return self.cover_overrides.get(plugin, orig)
        elif role == Qt.CheckStateRole and col == 0:
            orig = Qt.Unchecked if is_disabled(plugin) else Qt.Checked
            return self.enabled_overrides.get(plugin, orig)
        elif role == Qt.UserRole:
            return plugin
        elif (role == Qt.DecorationRole and col == 0
              and not plugin.is_configured()):
            return QIcon(I('list_remove.png'))
        elif role == Qt.ToolTipRole:
            base = plugin.description + '\n\n'
            if plugin.is_configured():
                return base + _('This source is configured and ready to go')
            return base + _('This source needs configuration')
        return NONE
Exemplo n.º 5
0
 def data(self, index, role):
     if not index.isValid():
         return None
     if index.internalId() == 0:
         if role == Qt.DisplayRole:
             return self.categories[index.row()]
     else:
         plugin = self.index_to_plugin(index)
         disabled = is_disabled(plugin)
         if role == Qt.DisplayRole:
             ver = '.'.join(map(unicode_type, plugin.version))
             desc = '\n'.join(textwrap.wrap(plugin.description, 100))
             ans='%s (%s) %s %s\n%s'%(plugin.name, ver, _('by'), plugin.author, desc)
             c = plugin_customization(plugin)
             if c and not disabled:
                 ans += _('\nCustomization: ')+c
             if disabled:
                 ans += _('\n\nThis plugin has been disabled')
             return (ans)
         if role == Qt.DecorationRole:
             return self.disabled_icon if disabled else self.icon
         if role == Qt.ForegroundRole and disabled:
             return (QBrush(Qt.gray))
         if role == Qt.UserRole:
             return plugin
     return None
Exemplo n.º 6
0
    def data(self, index, role):
        try:
            plugin = self.plugins[index.row()]
        except:
            return NONE
        col = index.column()

        if role == Qt.DisplayRole:
            if col == 0:
                return plugin.name
            elif col == 1:
                orig = msprefs['cover_priorities'].get(plugin.name, 1)
                return self.cover_overrides.get(plugin, orig)
        elif role == Qt.CheckStateRole and col == 0:
            orig = Qt.Unchecked if is_disabled(plugin) else Qt.Checked
            return self.enabled_overrides.get(plugin, orig)
        elif role == Qt.UserRole:
            return plugin
        elif (role == Qt.DecorationRole and col == 0 and not
                    plugin.is_configured()):
            return QIcon(I('list_remove.png'))
        elif role == Qt.ToolTipRole:
            base = plugin.description + '\n\n'
            if plugin.is_configured():
                return base + _('This source is configured and ready to go')
            return base + _('This source needs configuration')
        return NONE
Exemplo n.º 7
0
 def data(self, index, role):
     if not index.isValid():
         return NONE
     if index.internalId() == 0:
         if role == Qt.DisplayRole:
             category = self.categories[index.row()]
             return QVariant(_("%(plugin_type)s %(plugins)s") % dict(plugin_type=category, plugins=_("plugins")))
     else:
         plugin = self.index_to_plugin(index)
         disabled = is_disabled(plugin)
         if role == Qt.DisplayRole:
             ver = ".".join(map(str, plugin.version))
             desc = "\n".join(textwrap.wrap(plugin.description, 100))
             ans = "%s (%s) %s %s\n%s" % (plugin.name, ver, _("by"), plugin.author, desc)
             c = plugin_customization(plugin)
             if c and not disabled:
                 ans += _("\nCustomization: ") + c
             if disabled:
                 ans += _("\n\nThis plugin has been disabled")
             return QVariant(ans)
         if role == Qt.DecorationRole:
             return self.disabled_icon if disabled else self.icon
         if role == Qt.ForegroundRole and disabled:
             return QVariant(QBrush(Qt.gray))
         if role == Qt.UserRole:
             return plugin
     return NONE
Exemplo n.º 8
0
 def data(self, index, role):
     row, col = index.row(), index.column()
     result = self.matches[row]
     if role in (Qt.DisplayRole, Qt.EditRole):
         if col == 1:
             return QVariant('<b>%s</b><br><i>%s</i>' % (result.name, result.description))
         elif col == 3:
             return QVariant(result.headquarters)
         elif col == 5:
             return QVariant(', '.join(result.formats).upper())
     elif role == Qt.DecorationRole:
         if col == 2:
             if result.drm_free_only:
                 return QVariant(self.NO_DRM_ICON)
         if col == 4:
             if result.affiliate:
                 return QVariant(self.DONATE_ICON)
     elif role == Qt.CheckStateRole:
         if col == 0:
             if is_disabled(result):
                 return Qt.Unchecked
             return Qt.Checked
     elif role == Qt.ToolTipRole:
         if col == 0:
             if is_disabled(result):
                 return QVariant('<p>' + _('This store is currently disabled and cannot be used in other parts of calibre.') + '</p>')
             else:
                 return QVariant('<p>' + _('This store is currently enabled and can be used in other parts of calibre.') + '</p>')
         elif col == 1:
             return QVariant('<p>%s</p>' % result.description)
         elif col == 2:
             if result.drm_free_only:
                 return QVariant('<p>' + _('This store only distributes ebooks without DRM.') + '</p>')
             else:
                 return QVariant('<p>' + _('This store distributes ebooks with DRM. It may have some titles without DRM, but you will need to check on a per title basis.') + '</p>')
         elif col == 3:
             return QVariant('<p>' + _('This store is headquartered in %s. This is a good indication of what market the store caters to. However, this does not necessarily mean that the store is limited to that market only.') % result.headquarters + '</p>')
         elif col == 4:
             if result.affiliate:
                 return QVariant('<p>' + _('Buying from this store supports the calibre developer: %s.') % result.author + '</p>')
         elif col == 5:
             return QVariant('<p>' + _('This store distributes ebooks in the following formats: %s') % ', '.join(result.formats) + '</p>')
     return NONE
Exemplo n.º 9
0
    def modify_plugin(self, op=''):
        index = self.plugin_view.currentIndex()
        if index.isValid():
            if not index.parent().isValid():
                name = unicode(index.data() or '')
                return error_dialog(self, _('Error'), '<p>'+
                        _('Select an actual plugin under <b>%s</b> to customize')%name,
                        show=True, show_copy_button=False)

            plugin = self._plugin_model.index_to_plugin(index)
            if op == 'toggle':
                if not plugin.can_be_disabled:
                    info_dialog(self, _('Plugin cannot be disabled'),
                                 _('Disabling the plugin %s is not allowed')%plugin.name, show=True, show_copy_button=False)
                    return
                if is_disabled(plugin):
                    enable_plugin(plugin)
                else:
                    disable_plugin(plugin)
                self._plugin_model.refresh_plugin(plugin)
                self.changed_signal.emit()
            if op == 'customize':
                if not plugin.is_customizable():
                    info_dialog(self, _('Plugin not customizable'),
                        _('Plugin: %s does not need customization')%plugin.name).exec_()
                    return
                self.changed_signal.emit()
                from calibre.customize import InterfaceActionBase
                if isinstance(plugin, InterfaceActionBase) and not getattr(plugin,
                        'actual_iaction_plugin_loaded', False):
                    return error_dialog(self, _('Must restart'),
                            _('You must restart calibre before you can'
                                ' configure the <b>%s</b> plugin')%plugin.name, show=True)
                if plugin.do_user_config(self.gui):
                    self._plugin_model.refresh_plugin(plugin)
            elif op == 'remove':
                if not confirm('<p>' +
                    _('Are you sure you want to remove the plugin: %s?')%
                    '<b>{0}</b>'.format(plugin.name),
                    'confirm_plugin_removal_msg', parent=self):
                    return

                msg = _('Plugin <b>{0}</b> successfully removed. You will have'
                        ' to restart calibre for it to be completely removed.').format(plugin.name)
                if remove_plugin(plugin):
                    self._plugin_model.beginResetModel()
                    self._plugin_model.populate()
                    self._plugin_model.endResetModel()
                    self.changed_signal.emit()
                    info_dialog(self, _('Success'), msg, show=True,
                            show_copy_button=False)
                else:
                    error_dialog(self, _('Cannot remove builtin plugin'),
                         plugin.name + _(' cannot be removed. It is a '
                         'builtin plugin. Try disabling it instead.')).exec_()
Exemplo n.º 10
0
 def _toggle_enabled_clicked(self):
     display_plugin = self._selected_display_plugin()
     plugin = display_plugin.plugin
     if not plugin.can_be_disabled:
         return error_dialog(self,_('Plugin cannot be disabled'),
                      _('The plugin: %s cannot be disabled')%plugin.name, show=True)
     if is_disabled(plugin):
         enable_plugin(plugin)
     else:
         disable_plugin(plugin)
     self.model.refresh_plugin(display_plugin)
Exemplo n.º 11
0
    def __init__(self, parent=None):
        QMenu.__init__(self, parent)
        mitem = self.addAction(QIcon(I('devices/folder.png')),
                               _('Connect to folder'))
        mitem.setEnabled(True)
        mitem.triggered.connect(lambda x: self.connect_to_folder.emit())
        self.connect_to_folder_action = mitem
        mitem = self.addAction(QIcon(I('devices/itunes.png')),
                               _('Connect to iTunes'))
        mitem.setEnabled(True)
        mitem.triggered.connect(lambda x: self.connect_to_itunes.emit())
        self.connect_to_itunes_action = mitem
        itunes_ok = iswindows or (isosx and get_osx_version() < (10, 9, 0))
        mitem.setVisible(itunes_ok)
        mitem = self.addAction(QIcon(I('devices/bambook.png')),
                               _('Connect to Bambook'))
        mitem.setEnabled(True)
        mitem.triggered.connect(lambda x: self.connect_to_bambook.emit())
        self.connect_to_bambook_action = mitem
        bambook_visible = False
        if not is_disabled(BAMBOOK):
            device_ip = BAMBOOK.settings().extra_customization
            if device_ip:
                bambook_visible = True
        self.connect_to_bambook_action.setVisible(bambook_visible)

        self.addSeparator()
        self.toggle_server_action = \
            self.addAction(QIcon(I('network-server.png')),
            _('Start Content Server'))
        self.toggle_server_action.triggered.connect(
            lambda x: self.toggle_server.emit())
        self.control_smartdevice_action = \
            self.addAction(QIcon(I('dot_red.png')),
            self.DEVICE_MSGS[0])
        self.control_smartdevice_action.triggered.connect(
            lambda x: self.control_smartdevice.emit())
        self.addSeparator()

        self.email_actions = []

        if hasattr(parent, 'keyboard'):
            r = parent.keyboard.register_shortcut
            prefix = 'Share/Connect Menu '
            gr = ConnectShareAction.action_spec[0]
            for attr in ('folder', 'bambook', 'itunes'):
                if not (iswindows or isosx) and attr == 'itunes':
                    continue
                ac = getattr(self, 'connect_to_%s_action' % attr)
                r(prefix + attr, unicode(ac.text()), action=ac, group=gr)
            r(prefix + ' content server',
              _('Start/stop content server'),
              action=self.toggle_server_action,
              group=gr)
Exemplo n.º 12
0
 def _toggle_enabled_clicked(self):
     display_plugin = self._selected_display_plugin()
     plugin = display_plugin.plugin
     if not plugin.can_be_disabled:
         return error_dialog(self,_('Plugin cannot be disabled'),
                      _('The plugin: %s cannot be disabled')%plugin.name, show=True)
     if is_disabled(plugin):
         enable_plugin(plugin)
     else:
         disable_plugin(plugin)
     self.model.refresh_plugin(display_plugin)
Exemplo n.º 13
0
 def check_if_writer_disabled(self, format_name):
     if format_name in ['device_db', plugboard_any_format_value]:
         return
     show_message = True
     for writer in self.format_to_writers_map[format_name]:
         if not is_disabled(writer):
             show_message = False
     if show_message:
         warning_dialog(self, '',
                  _('That format has no metadata writers enabled. A plugboard '
                    'will probably have no effect.'),
                  show=True)
Exemplo n.º 14
0
 def check_if_writer_disabled(self, format_name):
     if format_name in ['device_db', plugboard_any_format_value]:
         return
     show_message = True
     for writer in self.format_to_writers_map[format_name]:
         if not is_disabled(writer):
             show_message = False
     if show_message:
         warning_dialog(self, '',
                  _('That format has no metadata writers enabled. A plugboard '
                    'will probably have no effect.'),
                  show=True)
Exemplo n.º 15
0
 def data_as_text(self, match, col):
     text = ''
     if col == 0:
         text = 'b' if is_disabled(match) else 'a'
     elif col == 1:
         text = match.name
     elif col == 2:
         text = 'a' if getattr(match, 'drm_free_only', True) else 'b'
     elif col == 3:
         text = getattr(match, 'headquarters', '')
     elif col == 4:
         text = 'a' if getattr(match, 'affiliate', False) else 'b'
     return text
Exemplo n.º 16
0
    def __init__(self, parent=None):
        QMenu.__init__(self, parent)
        mitem = self.addAction(QIcon(I('devices/folder.png')), _('Connect to folder'))
        mitem.setEnabled(True)
        mitem.triggered.connect(lambda x : self.connect_to_folder.emit())
        self.connect_to_folder_action = mitem
        mitem = self.addAction(QIcon(I('devices/itunes.png')),
                _('Connect to iTunes'))
        mitem.setEnabled(True)
        mitem.triggered.connect(lambda x : self.connect_to_itunes.emit())
        self.connect_to_itunes_action = mitem
        itunes_ok = iswindows or (isosx and get_osx_version() < (10, 9, 0))
        mitem.setVisible(itunes_ok)
        mitem = self.addAction(QIcon(I('devices/bambook.png')), _('Connect to Bambook'))
        mitem.setEnabled(True)
        mitem.triggered.connect(lambda x : self.connect_to_bambook.emit())
        self.connect_to_bambook_action = mitem
        bambook_visible = False
        if not is_disabled(BAMBOOK):
            device_ip = BAMBOOK.settings().extra_customization
            if device_ip:
                bambook_visible = True
        self.connect_to_bambook_action.setVisible(bambook_visible)

        self.addSeparator()
        self.toggle_server_action = \
            self.addAction(QIcon(I('network-server.png')),
            _('Start Content Server'))
        self.toggle_server_action.triggered.connect(lambda x:
                self.toggle_server.emit())
        self.control_smartdevice_action = \
            self.addAction(QIcon(I('dot_red.png')),
            self.DEVICE_MSGS[0])
        self.control_smartdevice_action.triggered.connect(lambda x:
                self.control_smartdevice.emit())
        self.addSeparator()

        self.email_actions = []

        if hasattr(parent, 'keyboard'):
            r = parent.keyboard.register_shortcut
            prefix = 'Share/Connect Menu '
            gr = ConnectShareAction.action_spec[0]
            for attr in ('folder', 'bambook', 'itunes'):
                if not (iswindows or isosx) and attr == 'itunes':
                    continue
                ac = getattr(self, 'connect_to_%s_action'%attr)
                r(prefix + attr, unicode(ac.text()), action=ac,
                        group=gr)
            r(prefix+' content server', _('Start/stop content server'),
                    action=self.toggle_server_action, group=gr)
Exemplo n.º 17
0
    def __init__(self, parent=None):
        QMenu.__init__(self, parent)
        mitem = self.addAction(QIcon(I("devices/folder.png")), _("Connect to folder"))
        mitem.setEnabled(True)
        mitem.triggered.connect(lambda x: self.connect_to_folder.emit())
        self.connect_to_folder_action = mitem
        mitem = self.addAction(QIcon(I("devices/itunes.png")), _("Connect to iTunes"))
        mitem.setEnabled(True)
        mitem.triggered.connect(lambda x: self.connect_to_itunes.emit())
        self.connect_to_itunes_action = mitem
        if not (iswindows or isosx):
            mitem.setVisible(False)
        mitem = self.addAction(QIcon(I("devices/bambook.png")), _("Connect to Bambook"))
        mitem.setEnabled(True)
        mitem.triggered.connect(lambda x: self.connect_to_bambook.emit())
        self.connect_to_bambook_action = mitem
        bambook_visible = False
        if not is_disabled(BAMBOOK):
            device_ip = BAMBOOK.settings().extra_customization
            if device_ip:
                bambook_visible = True
        self.connect_to_bambook_action.setVisible(bambook_visible)

        self.addSeparator()
        self.toggle_server_action = self.addAction(QIcon(I("network-server.png")), _("Start Content Server"))
        self.toggle_server_action.triggered.connect(lambda x: self.toggle_server.emit())
        self.control_smartdevice_action = self.addAction(QIcon(I("dot_red.png")), self.DEVICE_MSGS[0])
        self.control_smartdevice_action.triggered.connect(lambda x: self.control_smartdevice.emit())
        self.addSeparator()

        self.email_actions = []

        if hasattr(parent, "keyboard"):
            r = parent.keyboard.register_shortcut
            prefix = "Share/Connect Menu "
            gr = ConnectShareAction.action_spec[0]
            for attr in ("folder", "bambook", "itunes"):
                if not (iswindows or isosx) and attr == "itunes":
                    continue
                ac = getattr(self, "connect_to_%s_action" % attr)
                r(prefix + attr, unicode(ac.text()), action=ac, group=gr)
            r(prefix + " content server", _("Start/stop content server"), action=self.toggle_server_action, group=gr)
Exemplo n.º 18
0
    def modify_plugin(self, op=""):
        index = self.plugin_view.currentIndex()
        if index.isValid():
            if not index.parent().isValid():
                name = unicode(index.data().toString())
                return error_dialog(
                    self,
                    _("Error"),
                    "<p>" + _("Select an actual plugin under <b>%s</b> to customize") % name,
                    show=True,
                    show_copy_button=False,
                )

            plugin = self._plugin_model.index_to_plugin(index)
            if op == "toggle":
                if not plugin.can_be_disabled:
                    info_dialog(
                        self,
                        _("Plugin cannot be disabled"),
                        _("Disabling the plugin %s is not allowed") % plugin.name,
                        show=True,
                        show_copy_button=False,
                    )
                    return
                if is_disabled(plugin):
                    enable_plugin(plugin)
                else:
                    disable_plugin(plugin)
                self._plugin_model.refresh_plugin(plugin)
                self.changed_signal.emit()
            if op == "customize":
                if not plugin.is_customizable():
                    info_dialog(
                        self, _("Plugin not customizable"), _("Plugin: %s does not need customization") % plugin.name
                    ).exec_()
                    return
                self.changed_signal.emit()
                from calibre.customize import InterfaceActionBase

                if isinstance(plugin, InterfaceActionBase) and not getattr(
                    plugin, "actual_iaction_plugin_loaded", False
                ):
                    return error_dialog(
                        self,
                        _("Must restart"),
                        _("You must restart calibre before you can" " configure the <b>%s</b> plugin") % plugin.name,
                        show=True,
                    )
                if plugin.do_user_config(self.gui):
                    self._plugin_model.refresh_plugin(plugin)
            elif op == "remove":
                if not confirm(
                    "<p>" + _("Are you sure you want to remove the plugin: %s?") % "<b>{0}</b>".format(plugin.name),
                    "confirm_plugin_removal_msg",
                    parent=self,
                ):
                    return

                msg = _("Plugin <b>{0}</b> successfully removed").format(plugin.name)
                if remove_plugin(plugin):
                    self._plugin_model.populate()
                    self._plugin_model.reset()
                    self.changed_signal.emit()
                    info_dialog(self, _("Success"), msg, show=True, show_copy_button=False)
                else:
                    error_dialog(
                        self,
                        _("Cannot remove builtin plugin"),
                        plugin.name + _(" cannot be removed. It is a " "builtin plugin. Try disabling it instead."),
                    ).exec_()
Exemplo n.º 19
0
 def is_disabled(self):
     if self.plugin is None:
         return False
     return is_disabled(self.plugin)
Exemplo n.º 20
0
    def initialize(self):
        def field_cmp(x, y):
            if x.startswith('#'):
                if y.startswith('#'):
                    return cmp(x.lower(), y.lower())
                else:
                    return 1
            elif y.startswith('#'):
                return -1
            else:
                return cmp(x.lower(), y.lower())

        ConfigWidgetBase.initialize(self)

        self.current_plugboards = copy.deepcopy(
            self.db.prefs.get('plugboards', {}))
        self.current_device = None
        self.current_format = None

        if self.gui.device_manager.connected_device is not None:
            self.device_label.setText(
                _('Device currently connected: ') +
                self.gui.device_manager.connected_device.__class__.__name__)
        else:
            self.device_label.setText(_('Device currently connected: None'))

        self.devices = ['', 'APPLE', 'FOLDER_DEVICE']
        self.device_to_formats_map = {}
        for device in device_plugins():
            n = device_name_for_plugboards(device)
            self.device_to_formats_map[n] = set(device.settings().format_map)
            if getattr(device, 'CAN_DO_DEVICE_DB_PLUGBOARD', False):
                self.device_to_formats_map[n].add('device_db')
            if n not in self.devices:
                self.devices.append(n)
        self.devices.sort(cmp=lambda x, y: cmp(x.lower(), y.lower()))
        self.devices.insert(1, plugboard_save_to_disk_value)
        self.devices.insert(1, plugboard_content_server_value)
        self.device_to_formats_map[plugboard_content_server_value] = \
                        plugboard_content_server_formats
        self.devices.insert(1, plugboard_email_value)
        self.device_to_formats_map[plugboard_email_value] = \
                        plugboard_email_formats
        self.devices.insert(1, plugboard_any_device_value)
        self.new_device.addItems(self.devices)

        self.formats = ['']
        for w in metadata_writers():
            if not is_disabled(w):
                for f in w.file_types:
                    if not f in self.formats:
                        self.formats.append(f)
        self.formats.append('device_db')
        self.formats.sort()
        self.formats.insert(1, plugboard_any_format_value)
        self.new_format.addItems(self.formats)

        self.dest_fields = [
            '', 'authors', 'author_sort', 'language', 'publisher', 'tags',
            'title', 'title_sort'
        ]

        self.source_widgets = []
        self.dest_widgets = []
        for i in range(0, len(self.dest_fields) - 1):
            w = TemplateLineEditor(self)
            self.source_widgets.append(w)
            self.fields_layout.addWidget(w, 5 + i, 0, 1, 1)
            w = QComboBox(self)
            self.dest_widgets.append(w)
            self.fields_layout.addWidget(w, 5 + i, 1, 1, 1)

        self.edit_device.currentIndexChanged[str].connect(
            self.edit_device_changed)
        self.edit_format.currentIndexChanged[str].connect(
            self.edit_format_changed)
        self.new_device.currentIndexChanged[str].connect(
            self.new_device_changed)
        self.new_format.currentIndexChanged[str].connect(
            self.new_format_changed)
        self.existing_plugboards.itemClicked.connect(self.existing_pb_clicked)
        self.ok_button.clicked.connect(self.ok_clicked)
        self.del_button.clicked.connect(self.del_clicked)

        self.refilling = False
        self.refill_all_boxes()
Exemplo n.º 21
0
 def toggle_plugin(self, index):
     new_index = self.createIndex(index.row(), 0)
     data = QVariant(is_disabled(self.get_plugin(index)))
     self.setData(new_index, data, Qt.CheckStateRole)
Exemplo n.º 22
0
    def get_matches(self, location, query):
        location = location.lower().strip()
        if location == 'formats':
            location = 'format'

        matchkind = CONTAINS_MATCH
        if len(query) > 1:
            if query.startswith('\\'):
                query = query[1:]
            elif query.startswith('='):
                matchkind = EQUALS_MATCH
                query = query[1:]
            elif query.startswith('~'):
                matchkind = REGEXP_MATCH
                query = query[1:]
        if matchkind != REGEXP_MATCH: ### leave case in regexps because it can be significant e.g. \S \W \D
            query = query.lower()

        if location not in self.USABLE_LOCATIONS:
            return set([])
        matches = set([])
        all_locs = set(self.USABLE_LOCATIONS) - set(['all'])
        locations = all_locs if location == 'all' else [location]
        q = {
             'affiliate': lambda x: x.affiliate,
             'description': lambda x: x.description.lower(),
             'drm': lambda x: not x.drm_free_only,
             'enabled': lambda x: not is_disabled(x),
             'format': lambda x: ','.join(x.formats).lower(),
             'headquarters': lambda x: x.headquarters.lower(),
             'name': lambda x : x.name.lower(),
        }
        q['formats'] = q['format']
        for sr in self.srs:
            for locvalue in locations:
                accessor = q[locvalue]
                if query == 'true':
                    if locvalue in ('affiliate', 'drm', 'enabled'):
                        if accessor(sr) == True:
                            matches.add(sr)
                    elif accessor(sr) is not None:
                        matches.add(sr)
                    continue
                if query == 'false':
                    if locvalue in ('affiliate', 'drm', 'enabled'):
                        if accessor(sr) == False:
                            matches.add(sr)
                    elif accessor(sr) is None:
                        matches.add(sr)
                    continue
                # this is bool, so can't match below
                if locvalue in ('affiliate', 'drm', 'enabled'):
                    continue
                try:
                    ### Can't separate authors because comma is used for name sep and author sep
                    ### Exact match might not get what you want. For that reason, turn author
                    ### exactmatch searches into contains searches.
                    if locvalue == 'name' and matchkind == EQUALS_MATCH:
                        m = CONTAINS_MATCH
                    else:
                        m = matchkind

                    if locvalue == 'format':
                        vals = accessor(sr).split(',')
                    else:
                        vals = [accessor(sr)]
                    if _match(query, vals, m):
                        matches.add(sr)
                        break
                except ValueError: # Unicode errors
                    import traceback
                    traceback.print_exc()
        return matches
Exemplo n.º 23
0
    def initialize(self):
        def field_cmp(x, y):
            if x.startswith('#'):
                if y.startswith('#'):
                    return cmp(x.lower(), y.lower())
                else:
                    return 1
            elif y.startswith('#'):
                return -1
            else:
                return cmp(x.lower(), y.lower())

        ConfigWidgetBase.initialize(self)

        self.current_plugboards = copy.deepcopy(self.db.prefs.get('plugboards',{}))
        self.current_device = None
        self.current_format = None

        if self.gui.device_manager.connected_device is not None:
            self.device_label.setText(_('Device currently connected: ') +
                    self.gui.device_manager.connected_device.__class__.__name__)
        else:
            self.device_label.setText(_('Device currently connected: None'))

        self.devices = ['', 'APPLE', 'FOLDER_DEVICE']
        self.device_to_formats_map = {}
        for device in device_plugins():
            n = device_name_for_plugboards(device)
            self.device_to_formats_map[n] = set(device.settings().format_map)
            if getattr(device, 'CAN_DO_DEVICE_DB_PLUGBOARD', False):
                self.device_to_formats_map[n].add('device_db')
            if n not in self.devices:
                self.devices.append(n)
        self.devices.sort(cmp=lambda x, y: cmp(x.lower(), y.lower()))
        self.devices.insert(1, plugboard_save_to_disk_value)
        self.devices.insert(1, plugboard_content_server_value)
        self.device_to_formats_map[plugboard_content_server_value] = \
                        plugboard_content_server_formats
        self.devices.insert(1, plugboard_email_value)
        self.device_to_formats_map[plugboard_email_value] = \
                        plugboard_email_formats
        self.devices.insert(1, plugboard_any_device_value)
        self.new_device.addItems(self.devices)

        self.formats = ['']
        for w in metadata_writers():
            if not is_disabled(w):
                for f in w.file_types:
                    if not f in self.formats:
                        self.formats.append(f)
        self.formats.append('device_db')
        self.formats.sort()
        self.formats.insert(1, plugboard_any_format_value)
        self.new_format.addItems(self.formats)

        self.dest_fields = ['',
                            'authors', 'author_sort', 'language', 'publisher',
                            'tags', 'title', 'title_sort']

        self.source_widgets = []
        self.dest_widgets = []
        for i in range(0, len(self.dest_fields)-1):
            w = TemplateLineEditor(self)
            self.source_widgets.append(w)
            self.fields_layout.addWidget(w, 5+i, 0, 1, 1)
            w = QComboBox(self)
            self.dest_widgets.append(w)
            self.fields_layout.addWidget(w, 5+i, 1, 1, 1)

        self.edit_device.currentIndexChanged[str].connect(self.edit_device_changed)
        self.edit_format.currentIndexChanged[str].connect(self.edit_format_changed)
        self.new_device.currentIndexChanged[str].connect(self.new_device_changed)
        self.new_format.currentIndexChanged[str].connect(self.new_format_changed)
        self.existing_plugboards.itemClicked.connect(self.existing_pb_clicked)
        self.ok_button.clicked.connect(self.ok_clicked)
        self.del_button.clicked.connect(self.del_clicked)

        self.refilling = False
        self.refill_all_boxes()