Beispiel #1
0
 def __init__(self, accounts, subjects):
     QAbstractTableModel.__init__(self)
     self.accounts = accounts
     self.subjects = subjects
     self.account_order = sorted(self.accounts.keys())
     self.headers = map(QVariant, [_("Email"), _("Formats"), _("Subject"), _("Auto send")])
     self.default_font = QFont()
     self.default_font.setBold(True)
     self.default_font = QVariant(self.default_font)
     self.tooltips = [NONE] + list(
         map(
             QVariant,
             map(
                 textwrap.fill,
                 [
                     _("Formats to email. The first matching format will be sent."),
                     _(
                         "Subject of the email to use when sending. When left blank "
                         "the title will be used for the subject. Also, the same "
                         'templates used for "Save to disk" such as {title} and '
                         "{author_sort} can be used here."
                     ),
                     "<p>"
                     + _(
                         "If checked, downloaded news will be automatically "
                         "mailed <br>to this email address "
                         "(provided it is in one of the listed formats)."
                     ),
                 ],
             ),
         )
     )
 def data(self, index, role):
     profile = self.profiles[index.row()]
     if role == Qt.DisplayRole:
         return QVariant(profile.name)
     if role in (Qt.ToolTipRole, Qt.StatusTipRole, Qt.WhatsThisRole):
         return QVariant(profile.description)
     return NONE
 def headerData(self, section, orientation, role):
     if role != Qt.DisplayRole:
         return NONE
     if orientation == Qt.Horizontal:
         return QVariant(self.headers[section])
     else:
         return QVariant(section+1)
Beispiel #4
0
class NewsCategory(NewsTreeItem):

    def __init__(self, category, builtin, custom, scheduler_config, parent):
        NewsTreeItem.__init__(self, builtin, custom, scheduler_config, parent)
        self.category = category
        self.cdata = get_language(self.category)
        self.bold_font = QFont()
        self.bold_font.setBold(True)
        self.bold_font = QVariant(self.bold_font)

    def data(self, role):
        if role == Qt.DisplayRole:
            return QVariant(self.cdata + ' [%d]'%len(self.children))
        elif role == Qt.FontRole:
            return self.bold_font
        elif role == Qt.ForegroundRole and self.category == _('Scheduled'):
            return QVariant(QColor(0, 255, 0))
        return NONE

    def flags(self):
        return Qt.ItemIsEnabled

    def __cmp__(self, other):
        def decorate(x):
            if x == _('Scheduled'):
                x = '0' + x
            elif x == _('Custom'):
                x = '1' + x
            else:
                x = '2' + x
            return x

        return cmp(decorate(self.cdata), decorate(getattr(other, 'cdata', '')))
Beispiel #5
0
class NewsCategory(NewsTreeItem):
    def __init__(self, category, builtin, custom, scheduler_config, parent):
        NewsTreeItem.__init__(self, builtin, custom, scheduler_config, parent)
        self.category = category
        self.cdata = get_language(self.category)
        self.bold_font = QFont()
        self.bold_font.setBold(True)
        self.bold_font = QVariant(self.bold_font)

    def data(self, role):
        if role == Qt.DisplayRole:
            return QVariant(self.cdata + ' [%d]' % len(self.children))
        elif role == Qt.FontRole:
            return self.bold_font
        elif role == Qt.ForegroundRole and self.category == _('Scheduled'):
            return QVariant(QColor(0, 255, 0))
        return NONE

    def flags(self):
        return Qt.ItemIsEnabled

    def __cmp__(self, other):
        def decorate(x):
            if x == _('Scheduled'):
                x = '0' + x
            elif x == _('Custom'):
                x = '1' + x
            else:
                x = '2' + x
            return x

        return cmp(decorate(self.cdata), decorate(getattr(other, 'cdata', '')))
Beispiel #6
0
    def init_languages(self):
        self.language.blockSignals(True)
        self.language.clear()
        from calibre.utils.localization import (available_translations,
                                                get_language, get_lang,
                                                get_lc_messages_path)
        lang = get_lang()
        lang = get_lc_messages_path(lang) if lang else lang
        if lang is None or lang not in available_translations():
            lang = 'en'

        def get_esc_lang(l):
            if l == 'en':
                return 'English'
            return get_language(l)

        self.language.addItem(get_esc_lang(lang), QVariant(lang))
        items = [(l, get_esc_lang(l)) for l in available_translations()
                 if l != lang]
        if lang != 'en':
            items.append(('en', get_esc_lang('en')))
        items.sort(cmp=lambda x, y: cmp(x[1], y[1]))
        for item in items:
            self.language.addItem(item[1], QVariant(item[0]))
        self.language.blockSignals(False)
        prefs['language'] = str(
            self.language.itemData(self.language.currentIndex()).toString())
Beispiel #7
0
 def __init__(self, category, builtin, custom, scheduler_config, parent):
     NewsTreeItem.__init__(self, builtin, custom, scheduler_config, parent)
     self.category = category
     self.cdata = get_language(self.category)
     self.bold_font = QFont()
     self.bold_font.setBold(True)
     self.bold_font = QVariant(self.bold_font)
Beispiel #8
0
    def __init__(self):
        QWidget.__init__(self)
        self.ui = Ui_KeyboardWidget()
        self.ui.setupUi(self)

        index = 0  # comboBox.addItem doesn't increase the currentIndex
        self.default_layout_index = None
        locales = sorted([(country, data)
                          for country, data in yali.localedata.locales.items()
                          ])
        for country, data in locales:
            if data["xkbvariant"]:
                i = 0
                for variant in data["xkbvariant"]:
                    _d = dict(data)
                    _d["xkbvariant"] = variant[0]
                    _d["name"] = variant[1]
                    _d["consolekeymap"] = data["consolekeymap"][i]
                    self.ui.keyboard_list.addItem(_d["name"], QVariant(_d))
                    i += 1
            else:
                self.ui.keyboard_list.addItem(data["name"], QVariant(data))
            if ctx.consts.lang == country:
                if ctx.consts.lang == "tr":
                    self.default_layout_index = index + 1
                else:
                    self.default_layout_index = index
            index += 1

        self.ui.keyboard_list.setCurrentIndex(self.default_layout_index)

        self.connect(self.ui.keyboard_list, SIGNAL("currentIndexChanged(int)"),
                     self.slotLayoutChanged)
Beispiel #9
0
    def data(self, index, role):
        row, col = index.row(), index.column()
        try:
            book = self.results[row]
        except:
            return NONE
        if role == Qt.DisplayRole and col not in self.ICON_COLS:
            res = self.data_as_text(book, col)
            if res:
                return QVariant(res)
            return NONE
        elif role == Qt.DecorationRole and col in self.ICON_COLS:
            if col == 3 and getattr(book, 'has_cached_cover_url', False):
                return self.yes_icon
            if col == 4 and book.comments:
                return self.yes_icon
        elif role == Qt.UserRole:
            return book
        elif role == Qt.ToolTipRole and col == 3:
            return QVariant(
                _('The has cover indication is not fully\n'
                  'reliable. Sometimes results marked as not\n'
                  'having a cover will find a cover in the download\n'
                  'cover stage, and vice versa.'))

        return NONE
Beispiel #10
0
 def data(self, index, role):
     row, col = index.row(), index.column()
     if row < 0 or row >= self.rowCount():
         return NONE
     account = self.account_order[row]
     if account not in self.accounts:
         return NONE
     if role == Qt.UserRole:
         return (account, self.accounts[account])
     if role == Qt.ToolTipRole:
         return self.tooltips[col]
     if role in [Qt.DisplayRole, Qt.EditRole]:
         if col == 0:
             return QVariant(account)
         if col == 1:
             return QVariant(self.accounts[account][0])
         if col == 2:
             return QVariant(self.subjects.get(account, ''))
         if col == 4:
             return QVariant(self.aliases.get(account, ''))
     if role == Qt.FontRole and self.accounts[account][2]:
         return self.default_font
     if role == Qt.CheckStateRole and col == 3:
         return QVariant(
             Qt.Checked if self.accounts[account][1] else Qt.Unchecked)
     return NONE
Beispiel #11
0
 def create_widgets(self, opt):
     val = self.plugin.prefs[opt.name]
     if opt.type == 'number':
         c = QSpinBox if isinstance(opt.default, int) else QDoubleSpinBox
         widget = c(self)
         widget.setValue(val)
     elif opt.type == 'string':
         widget = QLineEdit(self)
         widget.setText(val if val else '')
     elif opt.type == 'bool':
         widget = QCheckBox(opt.label, self)
         widget.setChecked(bool(val))
     elif opt.type == 'choices':
         widget = QComboBox(self)
         for key, label in opt.choices.iteritems():
             widget.addItem(label, QVariant(key))
         idx = widget.findData(QVariant(val))
         widget.setCurrentIndex(idx)
     widget.opt = opt
     widget.setToolTip(textwrap.fill(opt.desc))
     self.widgets.append(widget)
     r = self.l.rowCount()
     if opt.type == 'bool':
         self.l.addWidget(widget, r, 0, 1, self.l.columnCount())
     else:
         l = QLabel(opt.label)
         l.setToolTip(widget.toolTip())
         self.memory.append(l)
         l.setBuddy(widget)
         self.l.addWidget(l, r, 0, 1, 1)
         self.l.addWidget(widget, r, 1, 1, 1)
Beispiel #12
0
 def __init__(self, category, builtin, custom, scheduler_config, parent):
     NewsTreeItem.__init__(self, builtin, custom, scheduler_config, parent)
     self.category = category
     self.cdata = get_language(self.category)
     self.bold_font = QFont()
     self.bold_font.setBold(True)
     self.bold_font = QVariant(self.bold_font)
Beispiel #13
0
 def headerData(self, section, orientation, role=Qt.DisplayRole):
     if orientation == Qt.Horizontal and role == Qt.DisplayRole:
         if section == 0:
             return QVariant("Pref Name")
         if section == 1:
             return QVariant("Pref Value")
     return QVariant()
Beispiel #14
0
 def data(self, index, role):
     if not index.isValid():
         return QVariant()
     if role != Qt.DisplayRole:
         return QVariant()
     item = index.internalPointer()
     return QVariant(item.node.name)
Beispiel #15
0
    def createSubitem(self, parentItem, parentGroup, groupname):
        if groupname != 'data':
            attributes = parentGroup[groupname].attrs
            subItem = QtGui.QTreeWidgetItem()
            subItem.setText(0, groupname)
            filenameData = QVariant(
                str(parentItem.data(0, QtCore.Qt.UserRole).toString()))
            parentPath = str(
                parentItem.data(1, QtCore.Qt.UserRole).toString()).replace(
                    '/data', '')  # The possible data has to be stripped!
            if 'data' in parentGroup[groupname]:
                subgroupData = QVariant(parentPath + '/' + groupname + '/data')
            else:
                subgroupData = QVariant(parentPath + '/' + groupname)
            subItem.setData(0, QtCore.Qt.UserRole, filenameData)
            subItem.setData(1, QtCore.Qt.UserRole, subgroupData)
            subItem.setExpanded(True)

            try:
                subItem.setData(2, QtCore.Qt.UserRole, attributes)
                if 'Description' in attributes:
                    subItem.setToolTip(0, attributes['Description'])
            except:
                pass

            return subItem
Beispiel #16
0
 def headerData(self, section, orientation, role=Qt.DisplayRole):
     if orientation == Qt.Horizontal and role == Qt.DisplayRole:
         if section == 0:
             return QVariant('Config Key')
         if section == 1:
             return QVariant('Config Value')
     return QVariant()
Beispiel #17
0
 def __init__(self, accounts, subjects):
     QAbstractTableModel.__init__(self)
     self.accounts = accounts
     self.subjects = subjects
     self.account_order = sorted(self.accounts.keys())
     self.headers = map(
         QVariant, [_('Email'),
                    _('Formats'),
                    _('Subject'),
                    _('Auto send')])
     self.default_font = QFont()
     self.default_font.setBold(True)
     self.default_font = QVariant(self.default_font)
     self.tooltips = [NONE] + list(
         map(
             QVariant,
             map(textwrap.fill, [
                 _('Formats to email. The first matching format will be sent.'
                   ),
                 _('Subject of the email to use when sending. When left blank '
                   'the title will be used for the subject. Also, the same '
                   'templates used for "Save to disk" such as {title} and '
                   '{author_sort} can be used here.'), '<p>' +
                 _('If checked, downloaded news will be automatically '
                   'mailed <br>to this email address '
                   '(provided it is in one of the listed formats).')
             ])))
Beispiel #18
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
Beispiel #19
0
 def closeEvent(self, QCloseEvent):
     settings = QSettings()
     settings.setValue('width', QVariant(self.settings['width']))
     settings.setValue('color', QVariant(self.settings['color']))
     settings.setValue('x_grid', QVariant(self.settings['x_grid']))
     settings.setValue('y_grid', QVariant(self.settings['y_grid']))
     settings.setValue('grid_opacity',
                       QVariant(self.settings['grid_opacity']))
Beispiel #20
0
 def data(self, role):
     if role == Qt.DisplayRole:
         return QVariant(self.cdata + ' [%d]' % len(self.children))
     elif role == Qt.FontRole:
         return self.bold_font
     elif role == Qt.ForegroundRole and self.category == _('Scheduled'):
         return QVariant(QColor(0, 255, 0))
     return NONE
Beispiel #21
0
 def __init__(self, show_only_user_plugins=False):
     QAbstractItemModel.__init__(self)
     SearchQueryParser.__init__(self, ['all'])
     self.show_only_user_plugins = show_only_user_plugins
     self.icon = QVariant(QIcon(I('plugins.png')))
     p = QIcon(self.icon).pixmap(64, 64, QIcon.Disabled, QIcon.On)
     self.disabled_icon = QVariant(QIcon(p))
     self._p = p
     self.populate()
Beispiel #22
0
 def data(self, index, role=Qt.DisplayRole):
     '''Returns the data stored under the given role 
     for the item referred to by the index.'''
     if not index.isValid():
         return QVariant()
     if role != Qt.DisplayRole and role != Qt.EditRole:
         return QVariant()
     nodePref = self.index2Pref(index)
     return QVariant(nodePref.qt_get_data(index.column()))
Beispiel #23
0
 def data(self, index, role=Qt.DisplayRole):
     if role == Qt.DisplayRole:
         return QVariant(self.label_for_row(index.row()))
     if role == Qt.FontRole and index.row() == self.pos:
         f = QApplication.instance().font()
         f.setBold(True)
         return QVariant(f)
     if role == Qt.UserRole:
         return QVariant(self.states[index.row()])
     return NONE
Beispiel #24
0
 def headerData(self, section, orientation, role):
     if role != Qt.DisplayRole:
         return NONE
     text = ''
     if orientation == Qt.Horizontal:
         if section < len(self.HEADERS):
             text = self.HEADERS[section]
         return QVariant(text)
     else:
         return QVariant(section + 1)
Beispiel #25
0
 def _populate_combo_box(self):
     # diagnostic datasets can have only diagnostic outcomes
     if self.is_diag:
         self.datatype_cbo_box.addItem(QString("Diagnostic"),
                                       QVariant(DIAGNOSTIC))
     else:
         for name, type_id in zip(
             [QString(s) for s in ["Binary", "Continuous"]],
             [QVariant(i) for i in range(2)]):
             self.datatype_cbo_box.addItem(name, type_id)
Beispiel #26
0
 def headerData(self, section, orientation, role):
     if role != Qt.DisplayRole:
         return NONE
     if orientation == Qt.Horizontal:
         if section == 0: text = _('Job')
         elif section == 1: text = _('Status')
         elif section == 2: text = _('Progress')
         elif section == 3: text = _('Running time')
         return QVariant(text)
     else:
         return QVariant(section + 1)
Beispiel #27
0
 def data(self, index, role):
     row, col = index.row(), index.column()
     result = self.books[row]
     if role == Qt.DisplayRole:
         if col == 0:
             return QVariant(result.title)
         elif col == 1:
             return QVariant(result.author)
         elif col == 2:
             return QVariant(result.formats)
     return NONE
Beispiel #28
0
 def data(self, index, role):
     if not index.isValid():
         return NONE
     row, col = index.row(), index.column()
     if row < 0 or row >= self.rowCount():
         return NONE
     display_plugin = self.display_plugins[row]
     if role in [Qt.DisplayRole, Qt.UserRole]:
         if col == 0:
             return QVariant(display_plugin.name)
         if col == 1:
             if display_plugin.donation_link:
                 return QVariant(_('PayPal'))
         if col == 2:
             return self._get_status(display_plugin)
         if col == 3:
             return QVariant(
                 self._get_display_version(
                     display_plugin.installed_version))
         if col == 4:
             return QVariant(
                 self._get_display_version(
                     display_plugin.available_version))
         if col == 5:
             if role == Qt.UserRole:
                 return self._get_display_release_date(
                     display_plugin.release_date, 'yyyyMMdd')
             else:
                 return self._get_display_release_date(
                     display_plugin.release_date)
         if col == 6:
             return QVariant(
                 self._get_display_version(
                     display_plugin.calibre_required_version))
         if col == 7:
             return QVariant(display_plugin.author)
     elif role == Qt.DecorationRole:
         if col == 0:
             return self._get_status_icon(display_plugin)
         if col == 1:
             if display_plugin.donation_link:
                 return QIcon(I('donate.png'))
     elif role == Qt.ToolTipRole:
         if col == 1 and display_plugin.donation_link:
             return QVariant(
                 _('This plugin is FREE but you can reward the developer for their effort\n'
                   'by donating to them via PayPal.\n\n'
                   'Right-click and choose Donate to reward: ') +
                 display_plugin.author)
         else:
             return self._get_status_tooltip(display_plugin)
     elif role == Qt.ForegroundRole:
         if col != 1:  # Never change colour of the donation column
             if display_plugin.is_deprecated:
                 return QVariant(QBrush(Qt.blue))
             if display_plugin.is_disabled():
                 return QVariant(QBrush(Qt.gray))
     return NONE
Beispiel #29
0
 def headerData(self, section, orientation, role):
     if role != Qt.DisplayRole:
         return NONE
     if orientation == Qt.Horizontal:
         return QVariant({
             0: _('Job'),
             1: _('Status'),
             2: _('Progress'),
             3: _('Running time'),
             4: _('Start time'),
         }.get(section, ''))
     else:
         return QVariant(section + 1)
Beispiel #30
0
 def data(self, index, role):
     profile = self.profiles[index.row()]
     if role == Qt.DisplayRole:
         return QVariant(profile.name)
     if role in (Qt.ToolTipRole, Qt.StatusTipRole, Qt.WhatsThisRole):
         w, h = profile.screen_size
         if w >= 10000:
             ss = _('unlimited')
         else:
             ss = _('%(width)d x %(height)d pixels') % dict(width=w, height=h)
         ss = _('Screen size: %s') % ss
         return QVariant('%s [%s]' % (profile.description, ss))
     return NONE
Beispiel #31
0
 def data(self, index, role):
     try:
         widget = self.widgets[index.row()]
     except:
         return NONE
     if role == Qt.DisplayRole:
         return QVariant(widget.config_title())
     if role == Qt.DecorationRole:
         return QVariant(widget.config_icon())
     if role == Qt.FontRole:
         f = QFont()
         f.setBold(True)
         return QVariant(f)
     return NONE
Beispiel #32
0
 def data(self, index, role):
     try:
         family = self.families[index.row()]
     except:
         traceback.print_exc()
         return NONE
     if role == Qt.DisplayRole:
         return QVariant(family)
     if role == Qt.FontRole:
         # If a user chooses some non standard font as the interface font,
         # rendering some font names causes Qt to crash, so return what is
         # hopefully a "safe" font
         return QVariant(self.font)
     return NONE
Beispiel #33
0
    def data(self, index, role=Qt.DisplayRole):
        row, col = index.row(), index.column()
        txout = self.dustTxOutlist[row]
        addrStr = script_to_addrStr(txout.getScript())
        pyAddr = self.wlt.addrMap[addrStr_to_hash160(addrStr)[1]]
        chainIndex = pyAddr.chainIndex + 1
        if role == Qt.DisplayRole:
            if col == DUSTCOLS.chainIndex: return QVariant(chainIndex)
            if col == DUSTCOLS.AddrStr: return QVariant(addrStr)
            if col == DUSTCOLS.Btc:
                return QVariant(coin2str(txout.getValue(), maxZeros=8))
        elif role == Qt.TextAlignmentRole:
            if col == DUSTCOLS.chainIndex:
                return QVariant(int(Qt.AlignLeft | Qt.AlignVCenter))
            if col == DUSTCOLS.AddrStr:
                return QVariant(int(Qt.AlignLeft | Qt.AlignVCenter))
            if col == DUSTCOLS.Btc:
                return QVariant(int(Qt.AlignRight | Qt.AlignVCenter))
        elif role == Qt.ForegroundRole:
            return QVariant(Colors.Foreground)
        elif role == Qt.FontRole:
            if col == DUSTCOLS.Btc:
                return GETFONT('Fixed')

        return QVariant()
Beispiel #34
0
 def __init__(self, accounts, subjects, aliases={}):
     QAbstractTableModel.__init__(self)
     self.accounts = accounts
     self.subjects = subjects
     self.aliases = aliases
     self.account_order = sorted(self.accounts.keys())
     self.headers  = map(QVariant, [_('Email'), _('Formats'), _('Subject'),
         _('Auto send'), _('Alias')])
     self.default_font = QFont()
     self.default_font.setBold(True)
     self.default_font = QVariant(self.default_font)
     self.tooltips =[NONE] + list(map(QVariant, map(textwrap.fill,
         [_('Formats to email. The first matching format will be sent.'),
          _('Subject of the email to use when sending. When left blank '
            'the title will be used for the subject. Also, the same '
            'templates used for "Save to disk" such as {title} and '
            '{author_sort} can be used here.'),
          '<p>'+_('If checked, downloaded news will be automatically '
                  'mailed <br>to this email address '
                  '(provided it is in one of the listed formats).'),
          _('Friendly name to use for this email address')
          ])))
Beispiel #35
0
class EmailAccounts(QAbstractTableModel):  # {{{
    def __init__(self, accounts, subjects):
        QAbstractTableModel.__init__(self)
        self.accounts = accounts
        self.subjects = subjects
        self.account_order = sorted(self.accounts.keys())
        self.headers = map(QVariant, [_("Email"), _("Formats"), _("Subject"), _("Auto send")])
        self.default_font = QFont()
        self.default_font.setBold(True)
        self.default_font = QVariant(self.default_font)
        self.tooltips = [NONE] + list(
            map(
                QVariant,
                map(
                    textwrap.fill,
                    [
                        _("Formats to email. The first matching format will be sent."),
                        _(
                            "Subject of the email to use when sending. When left blank "
                            "the title will be used for the subject. Also, the same "
                            'templates used for "Save to disk" such as {title} and '
                            "{author_sort} can be used here."
                        ),
                        "<p>"
                        + _(
                            "If checked, downloaded news will be automatically "
                            "mailed <br>to this email address "
                            "(provided it is in one of the listed formats)."
                        ),
                    ],
                ),
            )
        )

    def rowCount(self, *args):
        return len(self.account_order)

    def columnCount(self, *args):
        return len(self.headers)

    def headerData(self, section, orientation, role):
        if role == Qt.DisplayRole and orientation == Qt.Horizontal:
            return self.headers[section]
        return NONE

    def data(self, index, role):
        row, col = index.row(), index.column()
        if row < 0 or row >= self.rowCount():
            return NONE
        account = self.account_order[row]
        if role == Qt.UserRole:
            return (account, self.accounts[account])
        if role == Qt.ToolTipRole:
            return self.tooltips[col]
        if role in [Qt.DisplayRole, Qt.EditRole]:
            if col == 0:
                return QVariant(account)
            if col == 1:
                return QVariant(self.accounts[account][0])
            if col == 2:
                return QVariant(self.subjects.get(account, ""))
        if role == Qt.FontRole and self.accounts[account][2]:
            return self.default_font
        if role == Qt.CheckStateRole and col == 3:
            return QVariant(Qt.Checked if self.accounts[account][1] else Qt.Unchecked)
        return NONE

    def flags(self, index):
        if index.column() == 3:
            return QAbstractTableModel.flags(self, index) | Qt.ItemIsUserCheckable
        else:
            return QAbstractTableModel.flags(self, index) | Qt.ItemIsEditable

    def setData(self, index, value, role):
        if not index.isValid():
            return False
        row, col = index.row(), index.column()
        account = self.account_order[row]
        if col == 3:
            self.accounts[account][1] ^= True
        elif col == 2:
            self.subjects[account] = unicode(value.toString())
        elif col == 1:
            self.accounts[account][0] = unicode(value.toString()).upper()
        elif col == 0:
            na = unicode(value.toString())
            from email.utils import parseaddr

            addr = parseaddr(na)[-1]
            if not addr:
                return False
            self.accounts[na] = self.accounts.pop(account)
            self.account_order[row] = na
            if "@kindle.com" in addr:
                self.accounts[na][0] = "AZW, MOBI, TPZ, PRC, AZW1"

        self.dataChanged.emit(self.index(index.row(), 0), self.index(index.row(), 3))
        return True

    def make_default(self, index):
        if index.isValid():
            row = index.row()
            for x in self.accounts.values():
                x[2] = False
            self.accounts[self.account_order[row]][2] = True
            self.reset()

    def add(self):
        x = _("new email address")
        y = x
        c = 0
        while y in self.accounts:
            c += 1
            y = x + str(c)
        auto_send = len(self.accounts) < 1
        self.accounts[y] = ["MOBI, EPUB", auto_send, len(self.account_order) == 0]
        self.account_order = sorted(self.accounts.keys())
        self.reset()
        return self.index(self.account_order.index(y), 0)

    def remove(self, index):
        if index.isValid():
            row = index.row()
            account = self.account_order[row]
            self.accounts.pop(account)
            self.account_order = sorted(self.accounts.keys())
            has_default = False
            for account in self.account_order:
                if self.accounts[account][2]:
                    has_default = True
                    break
            if not has_default and self.account_order:
                self.accounts[self.account_order[0]][2] = True

            self.reset()