parent
39dc34b158
commit
2cc7506619
|
@ -1951,18 +1951,38 @@ class MyForm(QtGui.QMainWindow):
|
|||
i, 0).setText(unicode(toLabel, 'utf-8'))
|
||||
|
||||
def rerenderAddressBook(self):
|
||||
def addRow (address, label, type):
|
||||
self.ui.tableWidgetAddressBook.insertRow(0)
|
||||
newItem = Ui_AddressBookWidgetItemLabel(address, unicode(label, 'utf-8'), type)
|
||||
self.ui.tableWidgetAddressBook.setItem(0, 0, newItem)
|
||||
newItem = Ui_AddressBookWidgetItemAddress(address, unicode(label, 'utf-8'), type)
|
||||
self.ui.tableWidgetAddressBook.setItem(0, 1, newItem)
|
||||
|
||||
self.ui.tableWidgetAddressBook.setSortingEnabled(False)
|
||||
self.ui.tableWidgetAddressBook.setRowCount(0)
|
||||
|
||||
# subscriptions
|
||||
queryreturn = sqlQuery('SELECT label, address FROM subscriptions WHERE enabled = 1')
|
||||
for row in queryreturn:
|
||||
label, address = row
|
||||
addRow(address, label, 'subscription')
|
||||
|
||||
# chans
|
||||
addresses = getSortedAccounts()
|
||||
for address in addresses:
|
||||
account = accountClass(address)
|
||||
if (account.type == 'chan'):
|
||||
addRow(address, account.getLabel(), 'chan')
|
||||
|
||||
# normal accounts
|
||||
queryreturn = sqlQuery('SELECT * FROM addressbook')
|
||||
for row in queryreturn:
|
||||
label, address = row
|
||||
self.ui.tableWidgetAddressBook.insertRow(0)
|
||||
newItem = QtGui.QTableWidgetItem(unicode(label, 'utf-8'))
|
||||
newItem.setIcon(avatarize(address))
|
||||
self.ui.tableWidgetAddressBook.setItem(0, 0, newItem)
|
||||
newItem = QtGui.QTableWidgetItem(address)
|
||||
newItem.setFlags(
|
||||
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
|
||||
self.ui.tableWidgetAddressBook.setItem(0, 1, newItem)
|
||||
addRow(address, label, 'normal')
|
||||
|
||||
# sort
|
||||
self.ui.tableWidgetAddressBook.sortItems(0, QtCore.Qt.AscendingOrder)
|
||||
self.ui.tableWidgetAddressBook.setSortingEnabled(True)
|
||||
|
||||
def rerenderSubscriptions(self):
|
||||
self.rerenderTabTreeSubscriptions()
|
||||
|
|
|
@ -238,4 +238,48 @@ class Ui_SubscriptionWidget(Ui_AddressWidget):
|
|||
# else:
|
||||
return (not reverse if self.isEnabled else reverse)
|
||||
|
||||
return super(QtGui.QTreeWidgetItem, self).__lt__(other)
|
||||
return super(QtGui.QTreeWidgetItem, self).__lt__(other)
|
||||
|
||||
class Ui_AddressBookWidgetItem(QtGui.QTableWidgetItem):
|
||||
_types = {'normal': 0, 'chan': 1, 'subscription': 2}
|
||||
|
||||
def __init__ (self, text, type = 'normal'):
|
||||
super(QtGui.QTableWidgetItem, self).__init__(text)
|
||||
self.label = text
|
||||
try:
|
||||
self.type = self._types[type]
|
||||
except:
|
||||
self.type = 0
|
||||
if self.type == 2:
|
||||
brush = QtGui.QBrush(QtGui.QColor(137, 04, 177))
|
||||
elif self.type == 1:
|
||||
brush = QtGui.QBrush(QtGui.QColor(216, 119, 0))
|
||||
else:
|
||||
return
|
||||
brush.setStyle(QtCore.Qt.NoBrush)
|
||||
self.setForeground(brush)
|
||||
|
||||
def __lt__ (self, other):
|
||||
if (isinstance(other, Ui_AddressBookWidgetItem)):
|
||||
reverse = False
|
||||
if self.tableWidget().horizontalHeader().sortIndicatorOrder() == QtCore.Qt.DescendingOrder:
|
||||
reverse = True
|
||||
if self.type == other.type:
|
||||
return self.label.decode('utf-8').lower() < other.label.decode('utf-8').lower()
|
||||
else:
|
||||
return (not reverse if self.type < other.type else reverse)
|
||||
return super(QtGui.QTableWidgetItem, self).__lt__(other)
|
||||
|
||||
|
||||
class Ui_AddressBookWidgetItemLabel(Ui_AddressBookWidgetItem):
|
||||
def __init__ (self, address, label, type):
|
||||
Ui_AddressBookWidgetItem.__init__(self, label, type)
|
||||
self.label = label
|
||||
self.setIcon(avatarize(address))
|
||||
|
||||
|
||||
class Ui_AddressBookWidgetItemAddress(Ui_AddressBookWidgetItem):
|
||||
def __init__ (self, address, label, type):
|
||||
Ui_AddressBookWidgetItem.__init__(self, address, type)
|
||||
self.label = label
|
||||
self.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
|
Loading…
Reference in New Issue
Block a user