Account in treeWidget more like a QT class
It behaves more like a QT class is supposed to now, it's somewhat cleaner. Fixes #122
This commit is contained in:
parent
d69c2e097f
commit
f9a7a5b6f2
|
@ -3921,14 +3921,10 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
return
|
return
|
||||||
|
|
||||||
newLabel = str(item.text(0))
|
newLabel = str(item.text(0))
|
||||||
newLabel = newLabel.replace("(" + str(item.address) + ")", '')
|
|
||||||
newLabel = newLabel.rstrip()
|
|
||||||
if item.type == "subscription":
|
if item.type == "subscription":
|
||||||
oldLabel = item.label
|
oldLabel = item.label
|
||||||
else:
|
else:
|
||||||
oldLabel = shared.config.get(str(item.address), 'label')
|
oldLabel = shared.config.get(str(item.address), 'label')
|
||||||
oldLabel = oldLabel.replace("(" + str(item.address) + ")", '')
|
|
||||||
oldLabel = oldLabel.rstrip()
|
|
||||||
# unchanged, do not do anything either
|
# unchanged, do not do anything either
|
||||||
if newLabel == oldLabel:
|
if newLabel == oldLabel:
|
||||||
return
|
return
|
||||||
|
@ -3938,14 +3934,7 @@ class MyForm(settingsmixin.SMainWindow):
|
||||||
return
|
return
|
||||||
|
|
||||||
self.recurDepth += 1
|
self.recurDepth += 1
|
||||||
if item.type == "subscription":
|
item.setData(0, QtCore.Qt.EditRole, newLabel)
|
||||||
sqlExecute(
|
|
||||||
'''UPDATE subscriptions SET label=? WHERE address=?''',
|
|
||||||
newLabel, item.address)
|
|
||||||
item.setLabel(newLabel)
|
|
||||||
else:
|
|
||||||
shared.config.set(str(item.address), 'label', newLabel)
|
|
||||||
shared.writeKeysFile()
|
|
||||||
item.updateText()
|
item.updateText()
|
||||||
if item.type == 'mailinglist':
|
if item.type == 'mailinglist':
|
||||||
self.rerenderComboBoxSendFromBroadcast()
|
self.rerenderComboBoxSendFromBroadcast()
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
from PyQt4 import QtCore, QtGui
|
from PyQt4 import QtCore, QtGui
|
||||||
|
|
||||||
|
from helper_sql import *
|
||||||
from utils import *
|
from utils import *
|
||||||
import shared
|
import shared
|
||||||
from settingsmixin import SettingsMixin
|
from settingsmixin import SettingsMixin
|
||||||
|
@ -130,6 +131,34 @@ class Ui_AddressWidget(QtGui.QTreeWidgetItem, AccountMixin, SettingsMixin):
|
||||||
self.initialised = True
|
self.initialised = True
|
||||||
self.setType() # does updateText
|
self.setType() # does updateText
|
||||||
|
|
||||||
|
def data(self, column, role):
|
||||||
|
if column == 0:
|
||||||
|
if role == QtCore.Qt.DisplayRole:
|
||||||
|
if self.unreadCount > 0 and not self.isExpanded():
|
||||||
|
return unicode(shared.config.get(self.address, 'label'), 'utf-8)') + ' (' + str(self.unreadCount) + ') (' + self.address + ')'
|
||||||
|
else:
|
||||||
|
return unicode(shared.config.get(self.address, 'label'), 'utf-8)') + ' (' + self.address + ')'
|
||||||
|
elif role == QtCore.Qt.EditRole:
|
||||||
|
return unicode(shared.config.get(self.address, 'label'), 'utf-8')
|
||||||
|
elif role == QtCore.Qt.ToolTipRole:
|
||||||
|
return unicode(shared.config.get(self.address, 'label'), 'utf-8)') + ' (' + self.address + ')'
|
||||||
|
elif role == QtCore.Qt.DecorationRole:
|
||||||
|
return avatarize(self.address)
|
||||||
|
elif role == QtCore.Qt.FontRole:
|
||||||
|
font = QtGui.QFont()
|
||||||
|
font.setBold(self.unreadCount > 0)
|
||||||
|
return font
|
||||||
|
elif role == QtCore.Qt.ForegroundRole:
|
||||||
|
return self.accountBrush()
|
||||||
|
return super(Ui_AddressWidget, self).data(column, role)
|
||||||
|
|
||||||
|
def setData(self, column, role, value):
|
||||||
|
if role == QtCore.Qt.EditRole:
|
||||||
|
shared.config.set(str(self.address), 'label', str(value.toString()))
|
||||||
|
shared.writeKeysFile()
|
||||||
|
return
|
||||||
|
return super(Ui_AddressWidget, self).setData(column, role, value)
|
||||||
|
|
||||||
def setAddress(self, address):
|
def setAddress(self, address):
|
||||||
super(Ui_AddressWidget, self).setAddress(address)
|
super(Ui_AddressWidget, self).setAddress(address)
|
||||||
self.setData(0, QtCore.Qt.UserRole, self.address)
|
self.setData(0, QtCore.Qt.UserRole, self.address)
|
||||||
|
@ -137,34 +166,12 @@ class Ui_AddressWidget(QtGui.QTreeWidgetItem, AccountMixin, SettingsMixin):
|
||||||
def updateText(self):
|
def updateText(self):
|
||||||
if not self.initialised:
|
if not self.initialised:
|
||||||
return
|
return
|
||||||
text = unicode(shared.config.get(self.address, 'label'), 'utf-8)') + ' (' + self.address + ')'
|
self.emitDataChanged()
|
||||||
|
|
||||||
font = QtGui.QFont()
|
|
||||||
if self.unreadCount > 0:
|
|
||||||
# only show message count if the child doesn't show
|
|
||||||
if not self.isExpanded():
|
|
||||||
text += " (" + str(self.unreadCount) + ")"
|
|
||||||
font.setBold(True)
|
|
||||||
else:
|
|
||||||
font.setBold(False)
|
|
||||||
self.setFont(0, font)
|
|
||||||
|
|
||||||
#set text color
|
|
||||||
self.setForeground(0, self.accountBrush())
|
|
||||||
|
|
||||||
self.setIcon(0, avatarize(self.address))
|
|
||||||
self.setText(0, text)
|
|
||||||
self.setToolTip(0, text)
|
|
||||||
# self.setData(0, QtCore.Qt.UserRole, [self.address, "inbox"])
|
|
||||||
|
|
||||||
def setExpanded(self, expand):
|
def setExpanded(self, expand):
|
||||||
super(Ui_AddressWidget, self).setExpanded(expand)
|
super(Ui_AddressWidget, self).setExpanded(expand)
|
||||||
self.updateText()
|
self.updateText()
|
||||||
|
|
||||||
def edit(self):
|
|
||||||
self.setText(0, shared.config.get(self.address, 'label'))
|
|
||||||
super(QtGui.QAbstractItemView, self).edit()
|
|
||||||
|
|
||||||
# label (or address) alphabetically, disabled at the end
|
# label (or address) alphabetically, disabled at the end
|
||||||
def __lt__(self, other):
|
def __lt__(self, other):
|
||||||
if (isinstance(other, Ui_AddressWidget)):
|
if (isinstance(other, Ui_AddressWidget)):
|
||||||
|
@ -210,32 +217,40 @@ class Ui_SubscriptionWidget(Ui_AddressWidget, AccountMixin):
|
||||||
def setType(self):
|
def setType(self):
|
||||||
self.type = "subscription"
|
self.type = "subscription"
|
||||||
|
|
||||||
def edit(self):
|
def data(self, column, role):
|
||||||
self.setText(0, self.label)
|
if column == 0:
|
||||||
super(QtGui.QAbstractItemView, self).edit()
|
if role == QtCore.Qt.DisplayRole:
|
||||||
|
if self.unreadCount > 0 and not self.isExpanded():
|
||||||
|
return unicode(self.label, 'utf-8)') + ' (' + str(self.unreadCount) + ') (' + self.address + ')'
|
||||||
|
else:
|
||||||
|
return unicode(self.label, 'utf-8)') + ' (' + self.address + ')'
|
||||||
|
elif role == QtCore.Qt.EditRole:
|
||||||
|
return unicode(self.label, 'utf-8')
|
||||||
|
elif role == QtCore.Qt.ToolTipRole:
|
||||||
|
return unicode(self.label, 'utf-8)') + ' (' + self.address + ')'
|
||||||
|
elif role == QtCore.Qt.DecorationRole:
|
||||||
|
return avatarize(self.address)
|
||||||
|
elif role == QtCore.Qt.FontRole:
|
||||||
|
font = QtGui.QFont()
|
||||||
|
font.setBold(self.unreadCount > 0)
|
||||||
|
return font
|
||||||
|
elif role == QtCore.Qt.ForegroundRole:
|
||||||
|
return self.accountBrush()
|
||||||
|
return super(Ui_SubscriptionWidget, self).data(column, role)
|
||||||
|
|
||||||
|
def setData(self, column, role, value):
|
||||||
|
if role == QtCore.Qt.EditRole:
|
||||||
|
self.setLabel(str(value.toString()))
|
||||||
|
sqlExecute(
|
||||||
|
'''UPDATE subscriptions SET label=? WHERE address=?''',
|
||||||
|
self.label, self.address)
|
||||||
|
return
|
||||||
|
return super(Ui_SubscriptionWidget, self).setData(column, role, value)
|
||||||
|
|
||||||
def updateText(self):
|
def updateText(self):
|
||||||
if not self.initialised:
|
if not self.initialised:
|
||||||
return
|
return
|
||||||
text = unicode(self.label, 'utf-8)') + ' (' + self.address + ')'
|
self.emitDataChanged()
|
||||||
|
|
||||||
font = QtGui.QFont()
|
|
||||||
if self.unreadCount > 0:
|
|
||||||
# only show message count if the child doesn't show
|
|
||||||
if not self.isExpanded():
|
|
||||||
text += " (" + str(self.unreadCount) + ")"
|
|
||||||
font.setBold(True)
|
|
||||||
else:
|
|
||||||
font.setBold(False)
|
|
||||||
self.setFont(0, font)
|
|
||||||
|
|
||||||
#set text color
|
|
||||||
self.setForeground(0, self.accountBrush())
|
|
||||||
|
|
||||||
self.setIcon(0, avatarize(self.address))
|
|
||||||
self.setText(0, text)
|
|
||||||
self.setToolTip(0, text)
|
|
||||||
# self.setData(0, QtCore.Qt.UserRole, [self.address, "inbox"])
|
|
||||||
|
|
||||||
# label (or address) alphabetically, disabled at the end
|
# label (or address) alphabetically, disabled at the end
|
||||||
def __lt__(self, other):
|
def __lt__(self, other):
|
||||||
|
|
Reference in New Issue
Block a user