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', '')))
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', '')))
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()
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()