2015-10-02 22:24:46 +02:00
|
|
|
from PyQt4 import QtCore, QtGui
|
2016-04-29 02:03:48 +02:00
|
|
|
from string import find, rfind, rstrip, lstrip
|
2015-10-02 22:24:46 +02:00
|
|
|
|
2015-11-25 00:18:31 +01:00
|
|
|
from helper_sql import *
|
2015-10-02 22:24:46 +02:00
|
|
|
from utils import *
|
|
|
|
import shared
|
2015-11-12 00:33:57 +01:00
|
|
|
from settingsmixin import SettingsMixin
|
2015-10-02 22:24:46 +02:00
|
|
|
|
2015-10-27 19:24:29 +01:00
|
|
|
class AccountMixin (object):
|
2015-11-26 19:41:20 +01:00
|
|
|
ALL = 0
|
|
|
|
NORMAL = 1
|
|
|
|
CHAN = 2
|
|
|
|
MAILINGLIST = 3
|
|
|
|
SUBSCRIPTION = 4
|
2015-11-27 02:10:27 +01:00
|
|
|
BROADCAST = 5
|
2015-11-26 19:41:20 +01:00
|
|
|
|
2015-10-27 19:24:29 +01:00
|
|
|
def accountColor (self):
|
|
|
|
if not self.isEnabled:
|
2015-10-31 10:12:12 +01:00
|
|
|
return QtGui.QColor(128, 128, 128)
|
2015-11-26 19:41:20 +01:00
|
|
|
elif self.type == self.CHAN:
|
2015-10-31 10:12:12 +01:00
|
|
|
return QtGui.QColor(216, 119, 0)
|
2015-11-26 19:41:20 +01:00
|
|
|
elif self.type in [self.MAILINGLIST, self.SUBSCRIPTION]:
|
2015-10-31 10:12:12 +01:00
|
|
|
return QtGui.QColor(137, 04, 177)
|
2015-10-27 19:24:29 +01:00
|
|
|
else:
|
2015-10-31 10:12:12 +01:00
|
|
|
return QtGui.QApplication.palette().text().color()
|
|
|
|
|
2015-11-09 18:58:27 +01:00
|
|
|
def folderColor (self):
|
2016-01-24 18:21:15 +01:00
|
|
|
if not self.parent().isEnabled:
|
2015-11-09 18:58:27 +01:00
|
|
|
return QtGui.QColor(128, 128, 128)
|
|
|
|
else:
|
|
|
|
return QtGui.QApplication.palette().text().color()
|
|
|
|
|
2015-10-31 10:12:12 +01:00
|
|
|
def accountBrush(self):
|
2015-11-01 08:29:13 +01:00
|
|
|
brush = QtGui.QBrush(self.accountColor())
|
|
|
|
brush.setStyle(QtCore.Qt.NoBrush)
|
|
|
|
return brush
|
2015-11-09 18:58:27 +01:00
|
|
|
|
|
|
|
def folderBrush(self):
|
|
|
|
brush = QtGui.QBrush(self.folderColor())
|
|
|
|
brush.setStyle(QtCore.Qt.NoBrush)
|
|
|
|
return brush
|
2015-10-02 22:24:46 +02:00
|
|
|
|
|
|
|
def setAddress(self, address):
|
2015-11-27 00:56:25 +01:00
|
|
|
if address is None:
|
|
|
|
self.address = None
|
|
|
|
else:
|
|
|
|
self.address = str(address)
|
2015-10-02 22:24:46 +02:00
|
|
|
|
|
|
|
def setUnreadCount(self, cnt):
|
2016-01-24 21:26:42 +01:00
|
|
|
if hasattr(self, "unreadCount") and self.unreadCount == int(cnt):
|
|
|
|
return
|
2015-10-02 22:24:46 +02:00
|
|
|
self.unreadCount = int(cnt)
|
2016-01-24 21:26:42 +01:00
|
|
|
if isinstance(self, QtGui.QTreeWidgetItem):
|
|
|
|
self.emitDataChanged()
|
2015-10-02 22:24:46 +02:00
|
|
|
|
2015-10-27 19:24:29 +01:00
|
|
|
def setEnabled(self, enabled):
|
|
|
|
self.isEnabled = enabled
|
2015-11-09 18:45:35 +01:00
|
|
|
if hasattr(self, "setExpanded"):
|
|
|
|
self.setExpanded(enabled)
|
2015-11-11 01:02:23 +01:00
|
|
|
if isinstance(self, Ui_AddressWidget):
|
|
|
|
for i in range(self.childCount()):
|
|
|
|
if isinstance(self.child(i), Ui_FolderWidget):
|
|
|
|
self.child(i).setEnabled(enabled)
|
2016-01-24 18:50:38 +01:00
|
|
|
if isinstance(self, QtGui.QTreeWidgetItem):
|
2016-01-24 18:21:15 +01:00
|
|
|
self.emitDataChanged()
|
2015-10-27 19:24:29 +01:00
|
|
|
|
|
|
|
def setType(self):
|
2016-01-10 17:45:49 +01:00
|
|
|
self.setFlags(self.flags() | QtCore.Qt.ItemIsEditable)
|
2015-11-26 19:41:20 +01:00
|
|
|
if self.address is None:
|
|
|
|
self.type = self.ALL
|
2016-01-10 17:45:49 +01:00
|
|
|
self.setFlags(self.flags() & ~QtCore.Qt.ItemIsEditable)
|
2015-11-26 19:41:20 +01:00
|
|
|
elif shared.safeConfigGetBoolean(self.address, 'chan'):
|
|
|
|
self.type = self.CHAN
|
2015-10-27 19:24:29 +01:00
|
|
|
elif shared.safeConfigGetBoolean(self.address, 'mailinglist'):
|
2015-11-26 19:41:20 +01:00
|
|
|
self.type = self.MAILINGLIST
|
2016-01-23 10:14:12 +01:00
|
|
|
elif sqlQuery(
|
|
|
|
'''select label from subscriptions where address=?''', self.address):
|
|
|
|
self.type = AccountMixin.SUBSCRIPTION
|
2015-10-27 19:24:29 +01:00
|
|
|
else:
|
2015-11-26 19:41:20 +01:00
|
|
|
self.type = self.NORMAL
|
2016-01-23 22:18:07 +01:00
|
|
|
|
|
|
|
def defaultLabel(self):
|
|
|
|
queryreturn = None
|
|
|
|
retval = None
|
|
|
|
if self.type in (AccountMixin.NORMAL, AccountMixin.CHAN, AccountMixin.MAILINGLIST):
|
|
|
|
try:
|
|
|
|
retval = unicode(shared.config.get(self.address, 'label'), 'utf-8')
|
|
|
|
except Exception as e:
|
|
|
|
queryreturn = sqlQuery(
|
|
|
|
'''select label from addressbook where address=?''', self.address)
|
|
|
|
elif self.type == AccountMixin.SUBSCRIPTION:
|
|
|
|
queryreturn = sqlQuery(
|
|
|
|
'''select label from subscriptions where address=?''', self.address)
|
|
|
|
if queryreturn is not None:
|
|
|
|
if queryreturn != []:
|
|
|
|
for row in queryreturn:
|
|
|
|
retval, = row
|
|
|
|
retval = unicode(retval, 'utf-8')
|
|
|
|
elif self.address is None or self.type == AccountMixin.ALL:
|
|
|
|
return unicode(str(QtGui.QApplication.translate("MainWindow", "All accounts")), 'utf-8')
|
|
|
|
if retval is None:
|
|
|
|
return unicode(self.address, 'utf-8')
|
|
|
|
else:
|
|
|
|
return retval
|
2015-10-27 19:24:29 +01:00
|
|
|
|
2015-10-31 15:27:07 +01:00
|
|
|
|
2015-10-27 19:24:29 +01:00
|
|
|
class Ui_FolderWidget(QtGui.QTreeWidgetItem, AccountMixin):
|
2015-11-27 00:56:25 +01:00
|
|
|
folderWeight = {"inbox": 1, "new": 2, "sent": 3, "trash": 4}
|
2015-10-27 19:24:29 +01:00
|
|
|
def __init__(self, parent, pos = 0, address = "", folderName = "", unreadCount = 0):
|
|
|
|
super(QtGui.QTreeWidgetItem, self).__init__()
|
|
|
|
self.setAddress(address)
|
|
|
|
self.setFolderName(folderName)
|
|
|
|
self.setUnreadCount(unreadCount)
|
|
|
|
parent.insertChild(pos, self)
|
|
|
|
|
2015-10-02 22:24:46 +02:00
|
|
|
def setFolderName(self, fname):
|
|
|
|
self.folderName = str(fname)
|
|
|
|
|
2016-01-24 18:21:15 +01:00
|
|
|
def data(self, column, role):
|
|
|
|
if column == 0:
|
|
|
|
if role == QtCore.Qt.DisplayRole:
|
|
|
|
return QtGui.QApplication.translate("MainWindow", self.folderName) + (" (" + str(self.unreadCount) + ")" if self.unreadCount > 0 else "")
|
|
|
|
elif role == QtCore.Qt.EditRole:
|
|
|
|
return QtGui.QApplication.translate("MainWindow", self.folderName)
|
|
|
|
elif role == QtCore.Qt.ToolTipRole:
|
|
|
|
return QtGui.QApplication.translate("MainWindow", self.folderName)
|
|
|
|
elif role == QtCore.Qt.DecorationRole:
|
|
|
|
pass
|
|
|
|
elif role == QtCore.Qt.FontRole:
|
|
|
|
font = QtGui.QFont()
|
|
|
|
font.setBold(self.unreadCount > 0)
|
|
|
|
return font
|
|
|
|
elif role == QtCore.Qt.ForegroundRole:
|
|
|
|
return self.folderBrush()
|
|
|
|
return super(Ui_FolderWidget, self).data(column, role)
|
2015-10-02 22:24:46 +02:00
|
|
|
|
|
|
|
# inbox, sent, thrash first, rest alphabetically
|
|
|
|
def __lt__(self, other):
|
|
|
|
if (isinstance(other, Ui_FolderWidget)):
|
|
|
|
if self.folderName in self.folderWeight:
|
|
|
|
x = self.folderWeight[self.folderName]
|
|
|
|
else:
|
2015-11-27 00:56:25 +01:00
|
|
|
x = 99
|
2015-10-02 22:24:46 +02:00
|
|
|
if other.folderName in self.folderWeight:
|
|
|
|
y = self.folderWeight[other.folderName]
|
|
|
|
else:
|
2015-11-27 00:56:25 +01:00
|
|
|
y = 99
|
2015-10-03 12:12:18 +02:00
|
|
|
reverse = False
|
|
|
|
if self.treeWidget().header().sortIndicatorOrder() == QtCore.Qt.DescendingOrder:
|
|
|
|
reverse = True
|
2015-10-02 22:24:46 +02:00
|
|
|
if x == y:
|
2015-10-03 12:12:18 +02:00
|
|
|
return self.folderName < other.folderName
|
2015-10-02 22:24:46 +02:00
|
|
|
else:
|
2015-10-03 12:12:18 +02:00
|
|
|
return (x >= y if reverse else x < y)
|
2015-10-02 22:24:46 +02:00
|
|
|
|
|
|
|
return super(QtGui.QTreeWidgetItem, self).__lt__(other)
|
|
|
|
|
|
|
|
|
2015-11-12 00:33:57 +01:00
|
|
|
class Ui_AddressWidget(QtGui.QTreeWidgetItem, AccountMixin, SettingsMixin):
|
2015-11-26 19:41:20 +01:00
|
|
|
def __init__(self, parent, pos = 0, address = None, unreadCount = 0, enabled = True):
|
2015-10-02 22:24:46 +02:00
|
|
|
super(QtGui.QTreeWidgetItem, self).__init__()
|
|
|
|
parent.insertTopLevelItem(pos, self)
|
|
|
|
# only set default when creating
|
|
|
|
#super(QtGui.QTreeWidgetItem, self).setExpanded(shared.config.getboolean(self.address, 'enabled'))
|
2015-10-05 10:32:56 +02:00
|
|
|
self.setAddress(address)
|
2015-10-27 19:24:29 +01:00
|
|
|
self.setEnabled(enabled)
|
|
|
|
self.setUnreadCount(unreadCount)
|
2016-01-24 18:21:15 +01:00
|
|
|
self.setType()
|
2015-10-31 15:27:07 +01:00
|
|
|
|
2015-11-26 19:41:20 +01:00
|
|
|
def _getLabel(self):
|
|
|
|
if self.address is None:
|
2016-03-24 14:04:00 +01:00
|
|
|
return unicode(QtGui.QApplication.translate("MainWindow", "All accounts").toUtf8(), 'utf-8', 'ignore')
|
2015-11-26 19:41:20 +01:00
|
|
|
else:
|
|
|
|
try:
|
2016-03-12 10:58:48 +01:00
|
|
|
return unicode(shared.config.get(self.address, 'label'), 'utf-8', 'ignore')
|
2015-11-26 19:41:20 +01:00
|
|
|
except:
|
2015-11-27 00:56:25 +01:00
|
|
|
return unicode(self.address, 'utf-8')
|
2015-11-26 19:41:20 +01:00
|
|
|
|
|
|
|
def _getAddressBracket(self, unreadCount = False):
|
|
|
|
ret = ""
|
|
|
|
if unreadCount:
|
|
|
|
ret += " (" + str(self.unreadCount) + ")"
|
|
|
|
if self.address is not None:
|
|
|
|
ret += " (" + self.address + ")"
|
|
|
|
return ret
|
|
|
|
|
2015-11-25 00:18:31 +01:00
|
|
|
def data(self, column, role):
|
|
|
|
if column == 0:
|
|
|
|
if role == QtCore.Qt.DisplayRole:
|
|
|
|
if self.unreadCount > 0 and not self.isExpanded():
|
2015-11-26 19:41:20 +01:00
|
|
|
return self._getLabel() + self._getAddressBracket(True)
|
2015-11-25 00:18:31 +01:00
|
|
|
else:
|
2015-11-26 19:41:20 +01:00
|
|
|
return self._getLabel() + self._getAddressBracket(False)
|
2015-11-25 00:18:31 +01:00
|
|
|
elif role == QtCore.Qt.EditRole:
|
2015-11-26 19:41:20 +01:00
|
|
|
return self._getLabel()
|
2015-11-25 00:18:31 +01:00
|
|
|
elif role == QtCore.Qt.ToolTipRole:
|
2015-11-26 19:41:20 +01:00
|
|
|
return self._getLabel() + self._getAddressBracket(False)
|
2015-11-25 00:18:31 +01:00
|
|
|
elif role == QtCore.Qt.DecorationRole:
|
2015-11-26 19:41:20 +01:00
|
|
|
if self.address is None:
|
2016-03-24 14:04:00 +01:00
|
|
|
return avatarize(self._getLabel().encode('utf8'))
|
2015-11-26 19:41:20 +01:00
|
|
|
else:
|
|
|
|
return avatarize(self.address)
|
2015-11-25 00:18:31 +01:00
|
|
|
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):
|
2016-01-23 20:24:50 +01:00
|
|
|
if role == QtCore.Qt.EditRole and self.type != AccountMixin.SUBSCRIPTION:
|
|
|
|
if isinstance(value, QtCore.QVariant):
|
2016-03-12 10:58:48 +01:00
|
|
|
shared.config.set(str(self.address), 'label', str(value.toString().toUtf8()))
|
2016-01-23 20:24:50 +01:00
|
|
|
else:
|
|
|
|
shared.config.set(str(self.address), 'label', str(value))
|
2015-11-25 00:18:31 +01:00
|
|
|
shared.writeKeysFile()
|
|
|
|
return super(Ui_AddressWidget, self).setData(column, role, value)
|
|
|
|
|
2015-10-31 15:27:07 +01:00
|
|
|
def setAddress(self, address):
|
|
|
|
super(Ui_AddressWidget, self).setAddress(address)
|
|
|
|
self.setData(0, QtCore.Qt.UserRole, self.address)
|
2015-10-05 10:32:56 +02:00
|
|
|
|
2015-10-02 22:24:46 +02:00
|
|
|
def setExpanded(self, expand):
|
|
|
|
super(Ui_AddressWidget, self).setExpanded(expand)
|
2015-11-26 19:41:20 +01:00
|
|
|
|
|
|
|
def _getSortRank(self):
|
|
|
|
ret = self.type
|
|
|
|
if not self.isEnabled:
|
2015-11-27 02:10:27 +01:00
|
|
|
ret += 100
|
2015-11-26 19:41:20 +01:00
|
|
|
return ret
|
2015-10-02 22:24:46 +02:00
|
|
|
|
|
|
|
# label (or address) alphabetically, disabled at the end
|
|
|
|
def __lt__(self, other):
|
|
|
|
if (isinstance(other, Ui_AddressWidget)):
|
2015-10-03 12:12:18 +02:00
|
|
|
reverse = False
|
|
|
|
if self.treeWidget().header().sortIndicatorOrder() == QtCore.Qt.DescendingOrder:
|
|
|
|
reverse = True
|
2015-11-26 19:41:20 +01:00
|
|
|
if self._getSortRank() == other._getSortRank():
|
2016-03-12 10:58:48 +01:00
|
|
|
x = self._getLabel().lower()
|
|
|
|
y = other._getLabel().lower()
|
2015-11-26 19:41:20 +01:00
|
|
|
return x < y
|
|
|
|
return (not reverse if self._getSortRank() < other._getSortRank() else reverse)
|
2015-10-02 22:24:46 +02:00
|
|
|
|
|
|
|
return super(QtGui.QTreeWidgetItem, self).__lt__(other)
|
2015-10-10 19:58:01 +02:00
|
|
|
|
|
|
|
|
2015-10-27 19:24:29 +01:00
|
|
|
class Ui_SubscriptionWidget(Ui_AddressWidget, AccountMixin):
|
|
|
|
def __init__(self, parent, pos = 0, address = "", unreadCount = 0, label = "", enabled = True):
|
2015-10-10 19:58:01 +02:00
|
|
|
super(QtGui.QTreeWidgetItem, self).__init__()
|
|
|
|
parent.insertTopLevelItem(pos, self)
|
|
|
|
# only set default when creating
|
|
|
|
#super(QtGui.QTreeWidgetItem, self).setExpanded(shared.config.getboolean(self.address, 'enabled'))
|
2015-10-27 19:24:29 +01:00
|
|
|
self.setAddress(address)
|
2015-10-10 19:58:01 +02:00
|
|
|
self.setEnabled(enabled)
|
2015-10-27 19:24:29 +01:00
|
|
|
self.setType()
|
2016-01-24 18:21:15 +01:00
|
|
|
self.setUnreadCount(unreadCount)
|
2015-10-10 19:58:01 +02:00
|
|
|
|
2015-11-26 19:41:20 +01:00
|
|
|
def _getLabel(self):
|
2016-01-23 22:18:07 +01:00
|
|
|
queryreturn = sqlQuery(
|
|
|
|
'''select label from subscriptions where address=?''', self.address)
|
|
|
|
if queryreturn != []:
|
|
|
|
for row in queryreturn:
|
|
|
|
retval, = row
|
2016-03-12 10:58:48 +01:00
|
|
|
return unicode(retval, 'utf-8', 'ignore')
|
2016-01-23 22:18:07 +01:00
|
|
|
return unicode(self.address, 'utf-8')
|
2015-10-10 19:58:01 +02:00
|
|
|
|
|
|
|
def setType(self):
|
2016-01-10 17:45:49 +01:00
|
|
|
super(Ui_SubscriptionWidget, self).setType() # sets it editable
|
2016-01-23 20:24:50 +01:00
|
|
|
self.type = AccountMixin.SUBSCRIPTION # overrides type
|
2015-11-25 00:18:31 +01:00
|
|
|
|
|
|
|
def setData(self, column, role, value):
|
|
|
|
if role == QtCore.Qt.EditRole:
|
2016-03-12 10:58:48 +01:00
|
|
|
from debug import logger
|
2016-01-23 20:24:50 +01:00
|
|
|
if isinstance(value, QtCore.QVariant):
|
2016-03-12 10:58:48 +01:00
|
|
|
label = str(value.toString().toUtf8()).decode('utf-8', 'ignore')
|
2016-01-23 20:24:50 +01:00
|
|
|
else:
|
2016-03-12 10:58:48 +01:00
|
|
|
label = unicode(value, 'utf-8', 'ignore')
|
2015-11-25 00:18:31 +01:00
|
|
|
sqlExecute(
|
|
|
|
'''UPDATE subscriptions SET label=? WHERE address=?''',
|
2016-01-23 22:18:07 +01:00
|
|
|
label, self.address)
|
2015-11-25 00:18:31 +01:00
|
|
|
return super(Ui_SubscriptionWidget, self).setData(column, role, value)
|
2015-12-20 01:01:11 +01:00
|
|
|
|
|
|
|
|
|
|
|
class MessageList_AddressWidget(QtGui.QTableWidgetItem, AccountMixin, SettingsMixin):
|
|
|
|
def __init__(self, parent, address = None, label = None, unread = False):
|
|
|
|
super(QtGui.QTableWidgetItem, self).__init__()
|
|
|
|
#parent.insertTopLevelItem(pos, self)
|
|
|
|
# only set default when creating
|
|
|
|
#super(QtGui.QTreeWidgetItem, self).setExpanded(shared.config.getboolean(self.address, 'enabled'))
|
|
|
|
self.isEnabled = True
|
|
|
|
self.setAddress(address)
|
|
|
|
self.setLabel(label)
|
|
|
|
self.setUnread(unread)
|
|
|
|
self.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
|
2016-01-24 18:21:15 +01:00
|
|
|
self.setType()
|
2015-12-20 01:01:11 +01:00
|
|
|
parent.append(self)
|
|
|
|
|
|
|
|
def setLabel(self, label = None):
|
2016-01-23 20:24:50 +01:00
|
|
|
newLabel = self.address
|
2015-12-20 01:01:11 +01:00
|
|
|
if label is None:
|
2016-01-23 20:24:50 +01:00
|
|
|
queryreturn = None
|
|
|
|
if self.type in (AccountMixin.NORMAL, AccountMixin.CHAN, AccountMixin.MAILINGLIST):
|
|
|
|
try:
|
2016-03-12 10:58:48 +01:00
|
|
|
newLabel = unicode(shared.config.get(self.address, 'label'), 'utf-8', 'ignore')
|
2016-01-23 20:24:50 +01:00
|
|
|
except:
|
|
|
|
queryreturn = sqlQuery(
|
|
|
|
'''select label from addressbook where address=?''', self.address)
|
|
|
|
elif self.type == AccountMixin.SUBSCRIPTION:
|
|
|
|
queryreturn = sqlQuery(
|
|
|
|
'''select label from subscriptions where address=?''', self.address)
|
|
|
|
if queryreturn is not None:
|
|
|
|
if queryreturn != []:
|
|
|
|
for row in queryreturn:
|
|
|
|
newLabel, = row
|
2015-12-20 01:01:11 +01:00
|
|
|
else:
|
2016-01-23 20:24:50 +01:00
|
|
|
newLabel = label
|
|
|
|
if hasattr(self, 'label') and newLabel == self.label:
|
|
|
|
return
|
|
|
|
self.label = newLabel
|
2015-12-20 01:21:54 +01:00
|
|
|
|
2015-12-20 01:01:11 +01:00
|
|
|
def setUnread(self, unread):
|
|
|
|
self.unread = unread
|
|
|
|
|
|
|
|
def data(self, role):
|
|
|
|
if role == QtCore.Qt.DisplayRole:
|
|
|
|
return self.label
|
|
|
|
elif role == QtCore.Qt.EditRole:
|
|
|
|
return self.label
|
|
|
|
elif role == QtCore.Qt.ToolTipRole:
|
|
|
|
return self.label + " (" + self.address + ")"
|
|
|
|
elif role == QtCore.Qt.DecorationRole:
|
|
|
|
if shared.safeConfigGetBoolean('bitmessagesettings', 'useidenticons'):
|
|
|
|
if self.address is None:
|
|
|
|
return avatarize(self.label)
|
|
|
|
else:
|
|
|
|
return avatarize(self.address)
|
|
|
|
elif role == QtCore.Qt.FontRole:
|
|
|
|
font = QtGui.QFont()
|
|
|
|
font.setBold(self.unread)
|
|
|
|
return font
|
|
|
|
elif role == QtCore.Qt.ForegroundRole:
|
|
|
|
return self.accountBrush()
|
|
|
|
elif role == QtCore.Qt.UserRole:
|
|
|
|
return self.address
|
|
|
|
return super(MessageList_AddressWidget, self).data(role)
|
2015-11-26 19:41:20 +01:00
|
|
|
|
2015-12-20 01:01:11 +01:00
|
|
|
def setData(self, role, value):
|
|
|
|
if role == QtCore.Qt.EditRole:
|
|
|
|
self.setLabel()
|
|
|
|
return super(MessageList_AddressWidget, self).setData(role, value)
|
|
|
|
|
|
|
|
# label (or address) alphabetically, disabled at the end
|
|
|
|
def __lt__(self, other):
|
|
|
|
if (isinstance(other, MessageList_AddressWidget)):
|
|
|
|
return self.label.lower() < other.label.lower()
|
|
|
|
return super(QtGui.QTableWidgetItem, self).__lt__(other)
|
|
|
|
|
|
|
|
|
2015-12-21 21:08:28 +01:00
|
|
|
class MessageList_SubjectWidget(QtGui.QTableWidgetItem, SettingsMixin):
|
|
|
|
def __init__(self, parent, subject = None, label = None, unread = False):
|
|
|
|
super(QtGui.QTableWidgetItem, self).__init__()
|
|
|
|
#parent.insertTopLevelItem(pos, self)
|
|
|
|
# only set default when creating
|
|
|
|
#super(QtGui.QTreeWidgetItem, self).setExpanded(shared.config.getboolean(self.address, 'enabled'))
|
|
|
|
self.setSubject(subject)
|
|
|
|
self.setLabel(label)
|
|
|
|
self.setUnread(unread)
|
|
|
|
self.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
|
|
|
|
parent.append(self)
|
|
|
|
|
|
|
|
def setLabel(self, label):
|
|
|
|
self.label = label
|
|
|
|
|
|
|
|
def setSubject(self, subject):
|
|
|
|
self.subject = subject
|
|
|
|
|
|
|
|
def setUnread(self, unread):
|
|
|
|
self.unread = unread
|
|
|
|
|
|
|
|
def data(self, role):
|
|
|
|
if role == QtCore.Qt.DisplayRole:
|
|
|
|
return self.label
|
|
|
|
elif role == QtCore.Qt.EditRole:
|
|
|
|
return self.label
|
|
|
|
elif role == QtCore.Qt.ToolTipRole:
|
|
|
|
return self.label
|
|
|
|
elif role == QtCore.Qt.FontRole:
|
|
|
|
font = QtGui.QFont()
|
|
|
|
font.setBold(self.unread)
|
|
|
|
return font
|
|
|
|
elif role == QtCore.Qt.UserRole:
|
|
|
|
return self.subject
|
|
|
|
return super(MessageList_SubjectWidget, self).data(role)
|
|
|
|
|
|
|
|
def setData(self, role, value):
|
|
|
|
return super(MessageList_SubjectWidget, self).setData(role, value)
|
|
|
|
|
|
|
|
# label (or address) alphabetically, disabled at the end
|
|
|
|
def __lt__(self, other):
|
|
|
|
if (isinstance(other, MessageList_SubjectWidget)):
|
|
|
|
return self.label.lower() < other.label.lower()
|
|
|
|
return super(QtGui.QTableWidgetItem, self).__lt__(other)
|
|
|
|
|
|
|
|
|
2015-10-27 19:24:29 +01:00
|
|
|
class Ui_AddressBookWidgetItem(QtGui.QTableWidgetItem, AccountMixin):
|
2015-11-26 19:41:20 +01:00
|
|
|
def __init__ (self, text, type = AccountMixin.NORMAL):
|
2015-10-23 19:14:01 +02:00
|
|
|
super(QtGui.QTableWidgetItem, self).__init__(text)
|
|
|
|
self.label = text
|
2015-10-27 19:24:29 +01:00
|
|
|
self.type = type
|
|
|
|
self.setEnabled(True)
|
2016-01-23 20:24:50 +01:00
|
|
|
|
|
|
|
def data(self, role):
|
|
|
|
if role == QtCore.Qt.DisplayRole:
|
|
|
|
return self.label
|
|
|
|
elif role == QtCore.Qt.EditRole:
|
|
|
|
return self.label
|
|
|
|
elif role == QtCore.Qt.ToolTipRole:
|
|
|
|
return self.label + " (" + self.address + ")"
|
|
|
|
elif role == QtCore.Qt.DecorationRole:
|
|
|
|
if shared.safeConfigGetBoolean('bitmessagesettings', 'useidenticons'):
|
|
|
|
if self.address is None:
|
|
|
|
return avatarize(self.label)
|
|
|
|
else:
|
|
|
|
return avatarize(self.address)
|
|
|
|
elif role == QtCore.Qt.FontRole:
|
|
|
|
font = QtGui.QFont()
|
|
|
|
return font
|
|
|
|
elif role == QtCore.Qt.ForegroundRole:
|
|
|
|
return self.accountBrush()
|
|
|
|
elif role == QtCore.Qt.UserRole:
|
|
|
|
return self.type
|
|
|
|
return super(Ui_AddressBookWidgetItem, self).data(role)
|
|
|
|
|
|
|
|
def setData(self, role, value):
|
2016-01-23 22:18:07 +01:00
|
|
|
if role == QtCore.Qt.EditRole:
|
2016-01-23 20:24:50 +01:00
|
|
|
if isinstance(value, QtCore.QVariant):
|
2016-03-12 11:03:08 +01:00
|
|
|
self.label = str(value.toString().toUtf8())
|
2016-01-23 20:24:50 +01:00
|
|
|
else:
|
|
|
|
self.label = str(value)
|
2016-01-23 22:18:07 +01:00
|
|
|
if self.type in (AccountMixin.NORMAL, AccountMixin.MAILINGLIST, AccountMixin.CHAN):
|
|
|
|
try:
|
|
|
|
a = shared.config.get(self.address, 'label')
|
|
|
|
shared.config.set(self.address, 'label', self.label)
|
|
|
|
except:
|
|
|
|
sqlExecute('''UPDATE addressbook set label=? WHERE address=?''', self.label, self.address)
|
2016-01-23 20:24:50 +01:00
|
|
|
elif self.type == AccountMixin.SUBSCRIPTION:
|
2016-01-23 22:18:07 +01:00
|
|
|
from debug import logger
|
|
|
|
sqlExecute('''UPDATE subscriptions set label=? WHERE address=?''', self.label, self.address)
|
2016-01-23 20:24:50 +01:00
|
|
|
else:
|
|
|
|
pass
|
|
|
|
return super(Ui_AddressBookWidgetItem, self).setData(role, value)
|
2015-10-23 19:14:01 +02:00
|
|
|
|
|
|
|
def __lt__ (self, other):
|
|
|
|
if (isinstance(other, Ui_AddressBookWidgetItem)):
|
|
|
|
reverse = False
|
|
|
|
if self.tableWidget().horizontalHeader().sortIndicatorOrder() == QtCore.Qt.DescendingOrder:
|
|
|
|
reverse = True
|
2015-11-26 19:41:20 +01:00
|
|
|
if self.type == other.type:
|
2016-03-12 10:58:48 +01:00
|
|
|
return self.label.lower() < other.label.lower()
|
2015-10-23 19:14:01 +02:00
|
|
|
else:
|
2015-11-26 19:41:20 +01:00
|
|
|
return (not reverse if self.type < other.type else reverse)
|
2015-10-23 19:14:01 +02:00
|
|
|
return super(QtGui.QTableWidgetItem, self).__lt__(other)
|
|
|
|
|
|
|
|
|
|
|
|
class Ui_AddressBookWidgetItemLabel(Ui_AddressBookWidgetItem):
|
|
|
|
def __init__ (self, address, label, type):
|
|
|
|
Ui_AddressBookWidgetItem.__init__(self, label, type)
|
2015-11-13 14:31:22 +01:00
|
|
|
self.address = address
|
|
|
|
self.label = label
|
2015-10-23 19:14:01 +02:00
|
|
|
|
2016-01-23 22:18:07 +01:00
|
|
|
def data(self, role):
|
|
|
|
self.label = self.defaultLabel()
|
|
|
|
return super(Ui_AddressBookWidgetItemLabel, self).data(role)
|
2015-11-13 14:31:22 +01:00
|
|
|
|
2015-10-23 19:14:01 +02:00
|
|
|
|
|
|
|
class Ui_AddressBookWidgetItemAddress(Ui_AddressBookWidgetItem):
|
|
|
|
def __init__ (self, address, label, type):
|
|
|
|
Ui_AddressBookWidgetItem.__init__(self, address, type)
|
2016-04-28 23:05:07 +02:00
|
|
|
self.address = address
|
2016-03-24 14:04:00 +01:00
|
|
|
self.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
|
2016-04-29 02:03:48 +02:00
|
|
|
|
|
|
|
class AddressBookCompleter(QtGui.QCompleter):
|
|
|
|
def __init__(self):
|
|
|
|
super(QtGui.QCompleter, self).__init__()
|
|
|
|
self.cursorPos = -1
|
|
|
|
|
|
|
|
def onCursorPositionChanged(self, oldPos, newPos):
|
|
|
|
if oldPos != self.cursorPos:
|
|
|
|
self.cursorPos = -1
|
|
|
|
|
|
|
|
def splitPath(self, path):
|
|
|
|
stringList = []
|
|
|
|
text = unicode(path.toUtf8())
|
|
|
|
splitIndex = rfind(text[0:self.widget().cursorPosition()], ";") + 1
|
|
|
|
str = text[splitIndex:self.widget().cursorPosition()]
|
|
|
|
str = rstrip(lstrip(str))
|
|
|
|
stringList.append(str)
|
|
|
|
return stringList
|
|
|
|
|
|
|
|
def pathFromIndex(self, index):
|
|
|
|
autoString = unicode(index.data(QtCore.Qt.EditRole).toString())
|
|
|
|
text = unicode(self.widget().text().toUtf8())
|
|
|
|
|
|
|
|
# If cursor position was saved, restore it, else save it
|
|
|
|
if self.cursorPos != -1:
|
|
|
|
self.widget().setCursorPosition(self.cursorPos)
|
|
|
|
else:
|
|
|
|
self.cursorPos = self.widget().cursorPosition()
|
|
|
|
|
|
|
|
# Get current prosition
|
|
|
|
curIndex = self.widget().cursorPosition()
|
|
|
|
|
|
|
|
# prev_delimiter_index should actually point at final white space AFTER the delimiter
|
|
|
|
# Get index of last delimiter before current position
|
|
|
|
prevDelimiterIndex = rfind(text[0:curIndex], ";")
|
|
|
|
while text[prevDelimiterIndex + 1] == " ":
|
|
|
|
prevDelimiterIndex += 1
|
|
|
|
|
|
|
|
# Get index of first delimiter after current position (or EOL if no delimiter after cursor)
|
|
|
|
nextDelimiterIndex = find(text, ";", curIndex)
|
|
|
|
if nextDelimiterIndex == -1:
|
|
|
|
nextDelimiterIndex = len(text)
|
|
|
|
|
|
|
|
# Get part of string that occurs before cursor
|
|
|
|
part1 = text[0:prevDelimiterIndex + 1]
|
|
|
|
|
|
|
|
# Get string value from before auto finished string is selected
|
|
|
|
pre = text[prevDelimiterIndex + 1:curIndex - 1];
|
|
|
|
|
|
|
|
# Get part of string that occurs AFTER cursor
|
|
|
|
part2 = text[nextDelimiterIndex:]
|
|
|
|
|
|
|
|
return part1 + autoString + part2;
|