Got rid of wildcard imports in bitmessageqt.__init__

This commit is contained in:
Dmitri Bogomolov 2018-01-22 18:52:28 +02:00
parent 641db73614
commit c699f6d872
Signed by untrusted user: g1itch
GPG Key ID: 720A756F18DEED13

View File

@ -1,32 +1,31 @@
from debug import logger from debug import logger
import sys
try: try:
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtNetwork import QLocalSocket, QLocalServer from PyQt4.QtNetwork import QLocalSocket, QLocalServer
except Exception as err: except Exception as err:
logmsg = 'PyBitmessage requires PyQt unless you want to run it as a daemon and interact with it using the API. You can download it from http://www.riverbankcomputing.com/software/pyqt/download or by searching Google for \'PyQt Download\' (without quotes).' logmsg = 'PyBitmessage requires PyQt unless you want to run it as a daemon and interact with it using the API. You can download it from http://www.riverbankcomputing.com/software/pyqt/download or by searching Google for \'PyQt Download\' (without quotes).'
logger.critical(logmsg, exc_info=True) logger.critical(logmsg, exc_info=True)
import sys
sys.exit() sys.exit()
from tr import _translate from tr import _translate
from addresses import * from addresses import decodeAddress, addBMIfNotPresent
import shared import shared
from bitmessageui import * from bitmessageui import Ui_MainWindow
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser
import defaults import defaults
from namecoin import namecoinConnection from namecoin import namecoinConnection
from messageview import MessageView from messageview import MessageView
from migrationwizard import * from migrationwizard import Ui_MigrationWizard
from foldertree import * from foldertree import (
from safehtmlparser import * AccountMixin, Ui_FolderWidget, Ui_AddressWidget, Ui_SubscriptionWidget,
from settings import * MessageList_AddressWidget, MessageList_SubjectWidget,
Ui_AddressBookWidgetItemLabel, Ui_AddressBookWidgetItemAddress)
from settings import Ui_settingsDialog
import settingsmixin import settingsmixin
import support import support
import locale import locale
import sys
import time import time
import os import os
import hashlib import hashlib
@ -42,7 +41,9 @@ import helper_search
import l10n import l10n
import openclpow import openclpow
from utils import str_broadcast_subscribers, avatarize from utils import str_broadcast_subscribers, avatarize
from account import * from account import (
getSortedAccounts, getSortedSubscriptions, accountClass, BMAccount,
GatewayAccount, MailchuckAccount, AccountColor)
import dialogs import dialogs
from helper_generic import powQueueSize from helper_generic import powQueueSize
from inventory import ( from inventory import (
@ -378,7 +379,8 @@ class MyForm(settingsmixin.SMainWindow):
# sort ascending when creating # sort ascending when creating
if treeWidget.topLevelItemCount() == 0: if treeWidget.topLevelItemCount() == 0:
treeWidget.header().setSortIndicator(0, Qt.AscendingOrder) treeWidget.header().setSortIndicator(
0, QtCore.Qt.AscendingOrder)
# init dictionary # init dictionary
db = getSortedSubscriptions(True) db = getSortedSubscriptions(True)
@ -463,7 +465,8 @@ class MyForm(settingsmixin.SMainWindow):
# sort ascending when creating # sort ascending when creating
if treeWidget.topLevelItemCount() == 0: if treeWidget.topLevelItemCount() == 0:
treeWidget.header().setSortIndicator(0, Qt.AscendingOrder) treeWidget.header().setSortIndicator(
0, QtCore.Qt.AscendingOrder)
# init dictionary # init dictionary
db = {} db = {}
enabled = {} enabled = {}
@ -691,7 +694,8 @@ class MyForm(settingsmixin.SMainWindow):
self.pushButtonStatusIcon = QtGui.QPushButton(self) self.pushButtonStatusIcon = QtGui.QPushButton(self)
self.pushButtonStatusIcon.setText('') self.pushButtonStatusIcon.setText('')
self.pushButtonStatusIcon.setIcon(QIcon(':/newPrefix/images/redicon.png')) self.pushButtonStatusIcon.setIcon(
QtGui.QIcon(':/newPrefix/images/redicon.png'))
self.pushButtonStatusIcon.setFlat(True) self.pushButtonStatusIcon.setFlat(True)
self.statusbar.insertPermanentWidget(0, self.pushButtonStatusIcon) self.statusbar.insertPermanentWidget(0, self.pushButtonStatusIcon)
QtCore.QObject.connect(self.pushButtonStatusIcon, QtCore.SIGNAL( QtCore.QObject.connect(self.pushButtonStatusIcon, QtCore.SIGNAL(
@ -1021,7 +1025,7 @@ class MyForm(settingsmixin.SMainWindow):
l10n.formatTimestamp(lastactiontime)) l10n.formatTimestamp(lastactiontime))
newItem = myTableWidgetItem(statusText) newItem = myTableWidgetItem(statusText)
newItem.setToolTip(statusText) newItem.setToolTip(statusText)
newItem.setData(Qt.UserRole, QByteArray(ackdata)) newItem.setData(QtCore.Qt.UserRole, QtCore.QByteArray(ackdata))
newItem.setData(33, int(lastactiontime)) newItem.setData(33, int(lastactiontime))
newItem.setFlags( newItem.setFlags(
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
@ -1030,7 +1034,7 @@ class MyForm(settingsmixin.SMainWindow):
return acct return acct
def addMessageListItemInbox(self, tableWidget, msgfolder, msgid, toAddress, fromAddress, subject, received, read): def addMessageListItemInbox(self, tableWidget, msgfolder, msgid, toAddress, fromAddress, subject, received, read):
font = QFont() font = QtGui.QFont()
font.setBold(True) font.setBold(True)
if toAddress == str_broadcast_subscribers: if toAddress == str_broadcast_subscribers:
acct = accountClass(fromAddress) acct = accountClass(fromAddress)
@ -1052,7 +1056,7 @@ class MyForm(settingsmixin.SMainWindow):
# time received # time received
time_item = myTableWidgetItem(l10n.formatTimestamp(received)) time_item = myTableWidgetItem(l10n.formatTimestamp(received))
time_item.setToolTip(l10n.formatTimestamp(received)) time_item.setToolTip(l10n.formatTimestamp(received))
time_item.setData(Qt.UserRole, QByteArray(msgid)) time_item.setData(QtCore.Qt.UserRole, QtCore.QByteArray(msgid))
time_item.setData(33, int(received)) time_item.setData(33, int(received))
time_item.setFlags( time_item.setFlags(
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
@ -1089,7 +1093,8 @@ class MyForm(settingsmixin.SMainWindow):
toAddress, fromAddress, subject, status, ackdata, lastactiontime = row toAddress, fromAddress, subject, status, ackdata, lastactiontime = row
self.addMessageListItemSent(tableWidget, toAddress, fromAddress, subject, status, ackdata, lastactiontime) self.addMessageListItemSent(tableWidget, toAddress, fromAddress, subject, status, ackdata, lastactiontime)
tableWidget.horizontalHeader().setSortIndicator(3, Qt.DescendingOrder) tableWidget.horizontalHeader().setSortIndicator(
3, QtCore.Qt.DescendingOrder)
tableWidget.setSortingEnabled(True) tableWidget.setSortingEnabled(True)
tableWidget.horizontalHeaderItem(3).setText(_translate("MainWindow", "Sent", None)) tableWidget.horizontalHeaderItem(3).setText(_translate("MainWindow", "Sent", None))
tableWidget.setUpdatesEnabled(True) tableWidget.setUpdatesEnabled(True)
@ -1121,7 +1126,8 @@ class MyForm(settingsmixin.SMainWindow):
msgfolder, msgid, toAddress, fromAddress, subject, received, read = row msgfolder, msgid, toAddress, fromAddress, subject, received, read = row
self.addMessageListItemInbox(tableWidget, msgfolder, msgid, toAddress, fromAddress, subject, received, read) self.addMessageListItemInbox(tableWidget, msgfolder, msgid, toAddress, fromAddress, subject, received, read)
tableWidget.horizontalHeader().setSortIndicator(3, Qt.DescendingOrder) tableWidget.horizontalHeader().setSortIndicator(
3, QtCore.Qt.DescendingOrder)
tableWidget.setSortingEnabled(True) tableWidget.setSortingEnabled(True)
tableWidget.selectRow(0) tableWidget.selectRow(0)
tableWidget.horizontalHeaderItem(3).setText(_translate("MainWindow", "Received", None)) tableWidget.horizontalHeaderItem(3).setText(_translate("MainWindow", "Received", None))
@ -1134,7 +1140,7 @@ class MyForm(settingsmixin.SMainWindow):
QtCore.QObject.connect(self.tray, QtCore.SIGNAL( QtCore.QObject.connect(self.tray, QtCore.SIGNAL(
traySignal), self.__icon_activated) traySignal), self.__icon_activated)
m = QMenu() m = QtGui.QMenu()
self.actionStatus = QtGui.QAction(_translate( self.actionStatus = QtGui.QAction(_translate(
"MainWindow", "Not Connected"), m, checkable=False) "MainWindow", "Not Connected"), m, checkable=False)
@ -1397,11 +1403,11 @@ class MyForm(settingsmixin.SMainWindow):
# the same directory as this program. It is important that you # the same directory as this program. It is important that you
# back up this file.', QMessageBox.Ok) # back up this file.', QMessageBox.Ok)
reply = QtGui.QMessageBox.information(self, 'keys.dat?', _translate( reply = QtGui.QMessageBox.information(self, 'keys.dat?', _translate(
"MainWindow", "You may manage your keys by editing the keys.dat file stored in the same directory as this program. It is important that you back up this file."), QMessageBox.Ok) "MainWindow", "You may manage your keys by editing the keys.dat file stored in the same directory as this program. It is important that you back up this file."), QtGui.QMessageBox.Ok)
else: else:
QtGui.QMessageBox.information(self, 'keys.dat?', _translate( QtGui.QMessageBox.information(self, 'keys.dat?', _translate(
"MainWindow", "You may manage your keys by editing the keys.dat file stored in\n %1 \nIt is important that you back up this file.").arg(state.appdata), QMessageBox.Ok) "MainWindow", "You may manage your keys by editing the keys.dat file stored in\n %1 \nIt is important that you back up this file.").arg(state.appdata), QtGui.QMessageBox.Ok)
elif sys.platform == 'win32' or sys.platform == 'win64': elif sys.platform == 'win32' or sys.platform == 'win64':
if state.appdata == '': if state.appdata == '':
reply = QtGui.QMessageBox.question(self, _translate("MainWindow", "Open keys.dat?"), _translate( reply = QtGui.QMessageBox.question(self, _translate("MainWindow", "Open keys.dat?"), _translate(
@ -1432,7 +1438,7 @@ class MyForm(settingsmixin.SMainWindow):
dialog = dialogs.RegenerateAddressesDialog(self) dialog = dialogs.RegenerateAddressesDialog(self)
if dialog.exec_(): if dialog.exec_():
if dialog.lineEditPassphrase.text() == "": if dialog.lineEditPassphrase.text() == "":
QMessageBox.about( QtGui.QMessageBox.about(
self, _translate("MainWindow", "bad passphrase"), self, _translate("MainWindow", "bad passphrase"),
_translate( _translate(
"MainWindow", "MainWindow",
@ -1445,7 +1451,7 @@ class MyForm(settingsmixin.SMainWindow):
addressVersionNumber = int( addressVersionNumber = int(
dialog.lineEditAddressVersionNumber.text()) dialog.lineEditAddressVersionNumber.text())
except: except:
QMessageBox.about( QtGui.QMessageBox.about(
self, self,
_translate("MainWindow", "Bad address version number"), _translate("MainWindow", "Bad address version number"),
_translate( _translate(
@ -1455,7 +1461,7 @@ class MyForm(settingsmixin.SMainWindow):
)) ))
return return
if addressVersionNumber < 3 or addressVersionNumber > 4: if addressVersionNumber < 3 or addressVersionNumber > 4:
QMessageBox.about( QtGui.QMessageBox.about(
self, self,
_translate("MainWindow", "Bad address version number"), _translate("MainWindow", "Bad address version number"),
_translate( _translate(
@ -1509,7 +1515,7 @@ class MyForm(settingsmixin.SMainWindow):
if event.type() == QtCore.QEvent.WindowStateChange: if event.type() == QtCore.QEvent.WindowStateChange:
if self.windowState() & QtCore.Qt.WindowMinimized: if self.windowState() & QtCore.Qt.WindowMinimized:
if BMConfigParser().getboolean('bitmessagesettings', 'minimizetotray') and not 'darwin' in sys.platform: if BMConfigParser().getboolean('bitmessagesettings', 'minimizetotray') and not 'darwin' in sys.platform:
QTimer.singleShot(0, self.appIndicatorHide) QtCore.QTimer.singleShot(0, self.appIndicatorHide)
elif event.oldState() & QtCore.Qt.WindowMinimized: elif event.oldState() & QtCore.Qt.WindowMinimized:
# The window state has just been changed to # The window state has just been changed to
# Normal/Maximised/FullScreen # Normal/Maximised/FullScreen
@ -1531,7 +1537,7 @@ class MyForm(settingsmixin.SMainWindow):
'bitmessagesettings', 'hidetrayconnectionnotifications') 'bitmessagesettings', 'hidetrayconnectionnotifications')
if color == 'red': if color == 'red':
self.pushButtonStatusIcon.setIcon( self.pushButtonStatusIcon.setIcon(
QIcon(":/newPrefix/images/redicon.png")) QtGui.QIcon(":/newPrefix/images/redicon.png"))
shared.statusIconColor = 'red' shared.statusIconColor = 'red'
# if the connection is lost then show a notification # if the connection is lost then show a notification
if self.connected and _notifications_enabled: if self.connected and _notifications_enabled:
@ -1552,8 +1558,8 @@ class MyForm(settingsmixin.SMainWindow):
if color == 'yellow': if color == 'yellow':
if self.statusBar().currentMessage() == 'Warning: You are currently not connected. Bitmessage will do the work necessary to send the message but it won\'t send until you connect.': if self.statusBar().currentMessage() == 'Warning: You are currently not connected. Bitmessage will do the work necessary to send the message but it won\'t send until you connect.':
self.statusBar().clearMessage() self.statusBar().clearMessage()
self.pushButtonStatusIcon.setIcon(QIcon( self.pushButtonStatusIcon.setIcon(
":/newPrefix/images/yellowicon.png")) QtGui.QIcon(":/newPrefix/images/yellowicon.png"))
shared.statusIconColor = 'yellow' shared.statusIconColor = 'yellow'
# if a new connection has been established then show a notification # if a new connection has been established then show a notification
if not self.connected and _notifications_enabled: if not self.connected and _notifications_enabled:
@ -1571,7 +1577,7 @@ class MyForm(settingsmixin.SMainWindow):
if self.statusBar().currentMessage() == 'Warning: You are currently not connected. Bitmessage will do the work necessary to send the message but it won\'t send until you connect.': if self.statusBar().currentMessage() == 'Warning: You are currently not connected. Bitmessage will do the work necessary to send the message but it won\'t send until you connect.':
self.statusBar().clearMessage() self.statusBar().clearMessage()
self.pushButtonStatusIcon.setIcon( self.pushButtonStatusIcon.setIcon(
QIcon(":/newPrefix/images/greenicon.png")) QtGui.QIcon(":/newPrefix/images/greenicon.png"))
shared.statusIconColor = 'green' shared.statusIconColor = 'green'
if not self.connected and _notifications_enabled: if not self.connected and _notifications_enabled:
self.notifierShow( self.notifierShow(
@ -1587,7 +1593,7 @@ class MyForm(settingsmixin.SMainWindow):
def initTrayIcon(self, iconFileName, app): def initTrayIcon(self, iconFileName, app):
self.currentTrayIconFileName = iconFileName self.currentTrayIconFileName = iconFileName
self.tray = QSystemTrayIcon( self.tray = QtGui.QSystemTrayIcon(
self.calcTrayIcon(iconFileName, self.findInboxUnreadCount()), app) self.calcTrayIcon(iconFileName, self.findInboxUnreadCount()), app)
def setTrayIconFile(self, iconFileName): def setTrayIconFile(self, iconFileName):
@ -1616,9 +1622,10 @@ class MyForm(settingsmixin.SMainWindow):
fontMetrics = QtGui.QFontMetrics(font) fontMetrics = QtGui.QFontMetrics(font)
rect = fontMetrics.boundingRect(txt) rect = fontMetrics.boundingRect(txt)
# draw text # draw text
painter = QPainter() painter = QtGui.QPainter()
painter.begin(pixmap) painter.begin(pixmap)
painter.setPen(QtGui.QPen(QtGui.QColor(255, 0, 0), Qt.SolidPattern)) painter.setPen(
QtGui.QPen(QtGui.QColor(255, 0, 0), QtCore.Qt.SolidPattern))
painter.setFont(font) painter.setFont(font)
painter.drawText(24-rect.right()-marginX, -rect.top()+marginY, txt) painter.drawText(24-rect.right()-marginX, -rect.top()+marginY, txt)
painter.end() painter.end()
@ -1628,7 +1635,8 @@ class MyForm(settingsmixin.SMainWindow):
self.tray.setIcon(self.calcTrayIcon(iconFileName, inboxUnreadCount)) self.tray.setIcon(self.calcTrayIcon(iconFileName, inboxUnreadCount))
def changedInboxUnread(self, row=None): def changedInboxUnread(self, row=None):
self.drawTrayIcon(self.currentTrayIconFileName, self.findInboxUnreadCount()) self.drawTrayIcon(
self.currentTrayIconFileName, self.findInboxUnreadCount())
self.rerenderTabTreeMessages() self.rerenderTabTreeMessages()
self.rerenderTabTreeSubscriptions() self.rerenderTabTreeSubscriptions()
self.rerenderTabTreeChans() self.rerenderTabTreeChans()
@ -1653,8 +1661,7 @@ class MyForm(settingsmixin.SMainWindow):
continue continue
for i in range(sent.rowCount()): for i in range(sent.rowCount()):
rowAddress = sent.item( rowAddress = sent.item(i, 0).data(QtCore.Qt.UserRole)
i, 0).data(Qt.UserRole)
if toAddress == rowAddress: if toAddress == rowAddress:
sent.item(i, 3).setToolTip(textToDisplay) sent.item(i, 3).setToolTip(textToDisplay)
try: try:
@ -1674,9 +1681,9 @@ class MyForm(settingsmixin.SMainWindow):
continue continue
for i in range(sent.rowCount()): for i in range(sent.rowCount()):
toAddress = sent.item( toAddress = sent.item(
i, 0).data(Qt.UserRole) i, 0).data(QtCore.Qt.UserRole)
tableAckdata = sent.item( tableAckdata = sent.item(
i, 3).data(Qt.UserRole).toPyObject() i, 3).data(QtCore.Qt.UserRole).toPyObject()
status, addressVersionNumber, streamNumber, ripe = decodeAddress( status, addressVersionNumber, streamNumber, ripe = decodeAddress(
toAddress) toAddress)
if ackdata == tableAckdata: if ackdata == tableAckdata:
@ -1697,11 +1704,11 @@ class MyForm(settingsmixin.SMainWindow):
self.ui.tableWidgetInboxSubscriptions, self.ui.tableWidgetInboxSubscriptions,
self.ui.tableWidgetInboxChans]): self.ui.tableWidgetInboxChans]):
for i in range(inbox.rowCount()): for i in range(inbox.rowCount()):
if msgid == str(inbox.item(i, 3).data(Qt.UserRole).toPyObject()): if msgid == str(inbox.item(i, 3).data(QtCore.Qt.UserRole).toPyObject()):
self.statusBar().showMessage(_translate( self.statusBar().showMessage(_translate(
"MainWindow", "Message trashed"), 10000) "MainWindow", "Message trashed"), 10000)
treeWidget = self.widgetConvert(inbox) treeWidget = self.widgetConvert(inbox)
self.propagateUnreadCount(inbox.item(i, 1 if inbox.item(i, 1).type == AccountMixin.SUBSCRIPTION else 0).data(Qt.UserRole), self.getCurrentFolder(treeWidget), treeWidget, 0) self.propagateUnreadCount(inbox.item(i, 1 if inbox.item(i, 1).type == AccountMixin.SUBSCRIPTION else 0).data(QtCore.Qt.UserRole), self.getCurrentFolder(treeWidget), treeWidget, 0)
inbox.removeRow(i) inbox.removeRow(i)
break break
@ -1711,7 +1718,7 @@ class MyForm(settingsmixin.SMainWindow):
def displayAlert(self, title, text, exitAfterUserClicksOk): def displayAlert(self, title, text, exitAfterUserClicksOk):
self.statusBar().showMessage(text) self.statusBar().showMessage(text)
QtGui.QMessageBox.critical(self, title, text, QMessageBox.Ok) QtGui.QMessageBox.critical(self, title, text, QtGui.QMessageBox.Ok)
if exitAfterUserClicksOk: if exitAfterUserClicksOk:
os._exit(0) os._exit(0)
@ -1739,7 +1746,7 @@ class MyForm(settingsmixin.SMainWindow):
oldRows[item.address] = [item.label, item.type, i] oldRows[item.address] = [item.label, item.type, i]
if self.ui.tableWidgetAddressBook.rowCount() == 0: if self.ui.tableWidgetAddressBook.rowCount() == 0:
self.ui.tableWidgetAddressBook.horizontalHeader().setSortIndicator(0, Qt.AscendingOrder) self.ui.tableWidgetAddressBook.horizontalHeader().setSortIndicator(0, QtCore.Qt.AscendingOrder)
if self.ui.tableWidgetAddressBook.isSortingEnabled(): if self.ui.tableWidgetAddressBook.isSortingEnabled():
self.ui.tableWidgetAddressBook.setSortingEnabled(False) self.ui.tableWidgetAddressBook.setSortingEnabled(False)
@ -1773,7 +1780,8 @@ class MyForm(settingsmixin.SMainWindow):
completerList.append(unicode(newRows[address][0], encoding="UTF-8") + " <" + address + ">") completerList.append(unicode(newRows[address][0], encoding="UTF-8") + " <" + address + ">")
# sort # sort
self.ui.tableWidgetAddressBook.sortByColumn(0, Qt.AscendingOrder) self.ui.tableWidgetAddressBook.sortByColumn(
0, QtCore.Qt.AscendingOrder)
self.ui.tableWidgetAddressBook.setSortingEnabled(True) self.ui.tableWidgetAddressBook.setSortingEnabled(True)
self.ui.lineEditTo.completer().model().setStringList(completerList) self.ui.lineEditTo.completer().model().setStringList(completerList)
@ -1786,7 +1794,7 @@ class MyForm(settingsmixin.SMainWindow):
"MainWindow", """The TTL, or Time-To-Live is the length of time that the network will hold the message. "MainWindow", """The TTL, or Time-To-Live is the length of time that the network will hold the message.
The recipient must get it during this time. If your Bitmessage client does not hear an acknowledgement, it The recipient must get it during this time. If your Bitmessage client does not hear an acknowledgement, it
will resend the message automatically. The longer the Time-To-Live, the will resend the message automatically. The longer the Time-To-Live, the
more work your computer must do to send the message. A Time-To-Live of four or five days is often appropriate."""), QMessageBox.Ok) more work your computer must do to send the message. A Time-To-Live of four or five days is often appropriate."""), QtGui.QMessageBox.Ok)
def click_pushButtonSend(self): def click_pushButtonSend(self):
encoding = 3 if QtGui.QApplication.queryKeyboardModifiers() & QtCore.Qt.ShiftModifier else 2 encoding = 3 if QtGui.QApplication.queryKeyboardModifiers() & QtCore.Qt.ShiftModifier else 2
@ -1799,7 +1807,7 @@ class MyForm(settingsmixin.SMainWindow):
sendMessageToPeople = True sendMessageToPeople = True
fromAddress = str(self.ui.comboBoxSendFrom.itemData( fromAddress = str(self.ui.comboBoxSendFrom.itemData(
self.ui.comboBoxSendFrom.currentIndex(), self.ui.comboBoxSendFrom.currentIndex(),
Qt.UserRole).toString()) QtCore.Qt.UserRole).toString())
toAddresses = str(self.ui.lineEditTo.text().toUtf8()) toAddresses = str(self.ui.lineEditTo.text().toUtf8())
subject = str(self.ui.lineEditSubject.text().toUtf8()) subject = str(self.ui.lineEditSubject.text().toUtf8())
message = str( message = str(
@ -1809,20 +1817,26 @@ class MyForm(settingsmixin.SMainWindow):
sendMessageToPeople = False sendMessageToPeople = False
fromAddress = str(self.ui.comboBoxSendFromBroadcast.itemData( fromAddress = str(self.ui.comboBoxSendFromBroadcast.itemData(
self.ui.comboBoxSendFromBroadcast.currentIndex(), self.ui.comboBoxSendFromBroadcast.currentIndex(),
Qt.UserRole).toString()) QtCore.Qt.UserRole).toString())
subject = str(self.ui.lineEditSubjectBroadcast.text().toUtf8()) subject = str(self.ui.lineEditSubjectBroadcast.text().toUtf8())
message = str( message = str(
self.ui.textEditMessageBroadcast.document().toPlainText().toUtf8()) self.ui.textEditMessageBroadcast.document().toPlainText().toUtf8())
""" """
The whole network message must fit in 2^18 bytes. Let's assume 500 The whole network message must fit in 2^18 bytes.
bytes of overhead. If someone wants to get that too an exact Let's assume 500 bytes of overhead. If someone wants to get that
number you are welcome to but I think that it would be a better too an exact number you are welcome to but I think that it would
use of time to support message continuation so that users can be a better use of time to support message continuation so that
send messages of any length. users can send messages of any length.
""" """
if len(message) > (2 ** 18 - 500): if len(message) > (2 ** 18 - 500):
QMessageBox.about(self, _translate("MainWindow", "Message too long"), _translate( QtGui.QMessageBox.about(
"MainWindow", "The message that you are trying to send is too long by %1 bytes. (The maximum is 261644 bytes). Please cut it down before sending.").arg(len(message) - (2 ** 18 - 500))) self, _translate("MainWindow", "Message too long"),
_translate(
"MainWindow",
"The message that you are trying to send is too long"
" by %1 bytes. (The maximum is 261644 bytes). Please"
" cut it down before sending."
).arg(len(message) - (2 ** 18 - 500)))
return return
acct = accountClass(fromAddress) acct = accountClass(fromAddress)
@ -1900,11 +1914,11 @@ class MyForm(settingsmixin.SMainWindow):
toAddress = addBMIfNotPresent(toAddress) toAddress = addBMIfNotPresent(toAddress)
if addressVersionNumber > 4 or addressVersionNumber <= 1: if addressVersionNumber > 4 or addressVersionNumber <= 1:
QMessageBox.about(self, _translate("MainWindow", "Address version number"), _translate( QtGui.QMessageBox.about(self, _translate("MainWindow", "Address version number"), _translate(
"MainWindow", "Concerning the address %1, Bitmessage cannot understand address version numbers of %2. Perhaps upgrade Bitmessage to the latest version.").arg(toAddress).arg(str(addressVersionNumber))) "MainWindow", "Concerning the address %1, Bitmessage cannot understand address version numbers of %2. Perhaps upgrade Bitmessage to the latest version.").arg(toAddress).arg(str(addressVersionNumber)))
continue continue
if streamNumber > 1 or streamNumber == 0: if streamNumber > 1 or streamNumber == 0:
QMessageBox.about(self, _translate("MainWindow", "Stream number"), _translate( QtGui.QMessageBox.about(self, _translate("MainWindow", "Stream number"), _translate(
"MainWindow", "Concerning the address %1, Bitmessage cannot handle stream numbers of %2. Perhaps upgrade Bitmessage to the latest version.").arg(toAddress).arg(str(streamNumber))) "MainWindow", "Concerning the address %1, Bitmessage cannot handle stream numbers of %2. Perhaps upgrade Bitmessage to the latest version.").arg(toAddress).arg(str(streamNumber)))
continue continue
self.statusBar().clearMessage() self.statusBar().clearMessage()
@ -2050,8 +2064,11 @@ class MyForm(settingsmixin.SMainWindow):
self.ui.comboBoxSendFrom.addItem(avatarize(addressInKeysFile), label, addressInKeysFile) self.ui.comboBoxSendFrom.addItem(avatarize(addressInKeysFile), label, addressInKeysFile)
# self.ui.comboBoxSendFrom.model().sort(1, Qt.AscendingOrder) # self.ui.comboBoxSendFrom.model().sort(1, Qt.AscendingOrder)
for i in range(self.ui.comboBoxSendFrom.count()): for i in range(self.ui.comboBoxSendFrom.count()):
address = str(self.ui.comboBoxSendFrom.itemData(i, Qt.UserRole).toString()) address = str(self.ui.comboBoxSendFrom.itemData(
self.ui.comboBoxSendFrom.setItemData(i, AccountColor(address).accountColor(), Qt.ForegroundRole) i, QtCore.Qt.UserRole).toString())
self.ui.comboBoxSendFrom.setItemData(
i, AccountColor(address).accountColor(),
QtCore.Qt.ForegroundRole)
self.ui.comboBoxSendFrom.insertItem(0, '', '') self.ui.comboBoxSendFrom.insertItem(0, '', '')
if(self.ui.comboBoxSendFrom.count() == 2): if(self.ui.comboBoxSendFrom.count() == 2):
self.ui.comboBoxSendFrom.setCurrentIndex(1) self.ui.comboBoxSendFrom.setCurrentIndex(1)
@ -2070,8 +2087,11 @@ class MyForm(settingsmixin.SMainWindow):
label = addressInKeysFile label = addressInKeysFile
self.ui.comboBoxSendFromBroadcast.addItem(avatarize(addressInKeysFile), label, addressInKeysFile) self.ui.comboBoxSendFromBroadcast.addItem(avatarize(addressInKeysFile), label, addressInKeysFile)
for i in range(self.ui.comboBoxSendFromBroadcast.count()): for i in range(self.ui.comboBoxSendFromBroadcast.count()):
address = str(self.ui.comboBoxSendFromBroadcast.itemData(i, Qt.UserRole).toString()) address = str(self.ui.comboBoxSendFromBroadcast.itemData(
self.ui.comboBoxSendFromBroadcast.setItemData(i, AccountColor(address).accountColor(), Qt.ForegroundRole) i, QtCore.Qt.UserRole).toString())
self.ui.comboBoxSendFromBroadcast.setItemData(
i, AccountColor(address).accountColor(),
QtCore.Qt.ForegroundRole)
self.ui.comboBoxSendFromBroadcast.insertItem(0, '', '') self.ui.comboBoxSendFromBroadcast.insertItem(0, '', '')
if(self.ui.comboBoxSendFromBroadcast.count() == 2): if(self.ui.comboBoxSendFromBroadcast.count() == 2):
self.ui.comboBoxSendFromBroadcast.setCurrentIndex(1) self.ui.comboBoxSendFromBroadcast.setCurrentIndex(1)
@ -2285,7 +2305,7 @@ class MyForm(settingsmixin.SMainWindow):
if int(BMConfigParser().get('bitmessagesettings', 'port')) != int(self.settingsDialogInstance.ui.lineEditTCPPort.text()): if int(BMConfigParser().get('bitmessagesettings', 'port')) != int(self.settingsDialogInstance.ui.lineEditTCPPort.text()):
if not BMConfigParser().safeGetBoolean('bitmessagesettings', 'dontconnect'): if not BMConfigParser().safeGetBoolean('bitmessagesettings', 'dontconnect'):
QMessageBox.about(self, _translate("MainWindow", "Restart"), _translate( QtGui.QMessageBox.about(self, _translate("MainWindow", "Restart"), _translate(
"MainWindow", "You must restart Bitmessage for the port number change to take effect.")) "MainWindow", "You must restart Bitmessage for the port number change to take effect."))
BMConfigParser().set('bitmessagesettings', 'port', str( BMConfigParser().set('bitmessagesettings', 'port', str(
self.settingsDialogInstance.ui.lineEditTCPPort.text())) self.settingsDialogInstance.ui.lineEditTCPPort.text()))
@ -2299,7 +2319,7 @@ class MyForm(settingsmixin.SMainWindow):
#print 'self.settingsDialogInstance.ui.comboBoxProxyType.currentText())[0:5]', self.settingsDialogInstance.ui.comboBoxProxyType.currentText()[0:5] #print 'self.settingsDialogInstance.ui.comboBoxProxyType.currentText())[0:5]', self.settingsDialogInstance.ui.comboBoxProxyType.currentText()[0:5]
if BMConfigParser().get('bitmessagesettings', 'socksproxytype') == 'none' and self.settingsDialogInstance.ui.comboBoxProxyType.currentText()[0:5] == 'SOCKS': if BMConfigParser().get('bitmessagesettings', 'socksproxytype') == 'none' and self.settingsDialogInstance.ui.comboBoxProxyType.currentText()[0:5] == 'SOCKS':
if shared.statusIconColor != 'red': if shared.statusIconColor != 'red':
QMessageBox.about(self, _translate("MainWindow", "Restart"), _translate( QtGui.QMessageBox.about(self, _translate("MainWindow", "Restart"), _translate(
"MainWindow", "Bitmessage will use your proxy from now on but you may want to manually restart Bitmessage now to close existing connections (if any).")) "MainWindow", "Bitmessage will use your proxy from now on but you may want to manually restart Bitmessage now to close existing connections (if any)."))
if BMConfigParser().get('bitmessagesettings', 'socksproxytype')[0:5] == 'SOCKS' and self.settingsDialogInstance.ui.comboBoxProxyType.currentText()[0:5] != 'SOCKS': if BMConfigParser().get('bitmessagesettings', 'socksproxytype')[0:5] == 'SOCKS' and self.settingsDialogInstance.ui.comboBoxProxyType.currentText()[0:5] != 'SOCKS':
self.statusBar().clearMessage() self.statusBar().clearMessage()
@ -2328,7 +2348,7 @@ class MyForm(settingsmixin.SMainWindow):
BMConfigParser().set('bitmessagesettings', 'maxuploadrate', str( BMConfigParser().set('bitmessagesettings', 'maxuploadrate', str(
int(float(self.settingsDialogInstance.ui.lineEditMaxUploadRate.text())))) int(float(self.settingsDialogInstance.ui.lineEditMaxUploadRate.text()))))
except ValueError: except ValueError:
QMessageBox.about(self, _translate("MainWindow", "Number needed"), _translate( QtGui.QMessageBox.about(self, _translate("MainWindow", "Number needed"), _translate(
"MainWindow", "Your maximum download and upload rate must be numbers. Ignoring what you typed.")) "MainWindow", "Your maximum download and upload rate must be numbers. Ignoring what you typed."))
else: else:
set_rates(BMConfigParser().safeGetInt("bitmessagesettings", "maxdownloadrate"), set_rates(BMConfigParser().safeGetInt("bitmessagesettings", "maxdownloadrate"),
@ -2408,7 +2428,7 @@ class MyForm(settingsmixin.SMainWindow):
if (float(self.settingsDialogInstance.ui.lineEditDays.text()) >=0 and float(self.settingsDialogInstance.ui.lineEditMonths.text()) >=0): if (float(self.settingsDialogInstance.ui.lineEditDays.text()) >=0 and float(self.settingsDialogInstance.ui.lineEditMonths.text()) >=0):
shared.maximumLengthOfTimeToBotherResendingMessages = (float(str(self.settingsDialogInstance.ui.lineEditDays.text())) * 24 * 60 * 60) + (float(str(self.settingsDialogInstance.ui.lineEditMonths.text())) * (60 * 60 * 24 *365)/12) shared.maximumLengthOfTimeToBotherResendingMessages = (float(str(self.settingsDialogInstance.ui.lineEditDays.text())) * 24 * 60 * 60) + (float(str(self.settingsDialogInstance.ui.lineEditMonths.text())) * (60 * 60 * 24 *365)/12)
if shared.maximumLengthOfTimeToBotherResendingMessages < 432000: # If the time period is less than 5 hours, we give zero values to all fields. No message will be sent again. if shared.maximumLengthOfTimeToBotherResendingMessages < 432000: # If the time period is less than 5 hours, we give zero values to all fields. No message will be sent again.
QMessageBox.about(self, _translate("MainWindow", "Will not resend ever"), _translate( QtGui.QMessageBox.about(self, _translate("MainWindow", "Will not resend ever"), _translate(
"MainWindow", "Note that the time limit you entered is less than the amount of time Bitmessage waits for the first resend attempt therefore your messages will never be resent.")) "MainWindow", "Note that the time limit you entered is less than the amount of time Bitmessage waits for the first resend attempt therefore your messages will never be resent."))
BMConfigParser().set('bitmessagesettings', 'stopresendingafterxdays', '0') BMConfigParser().set('bitmessagesettings', 'stopresendingafterxdays', '0')
BMConfigParser().set('bitmessagesettings', 'stopresendingafterxmonths', '0') BMConfigParser().set('bitmessagesettings', 'stopresendingafterxmonths', '0')
@ -2508,7 +2528,8 @@ class MyForm(settingsmixin.SMainWindow):
_translate( _translate(
"MainWindow", "MainWindow",
"Are you sure you would like to mark all messages read?" "Are you sure you would like to mark all messages read?"
), QMessageBox.Yes | QMessageBox.No) != QMessageBox.Yes: ), QtGui.QMessageBox.Yes | QtGui.QMessageBox.No
) != QtGui.QMessageBox.Yes:
return return
addressAtCurrentRow = self.getCurrentAccount() addressAtCurrentRow = self.getCurrentAccount()
tableWidget = self.getCurrentMessagelist() tableWidget = self.getCurrentMessagelist()
@ -2517,13 +2538,13 @@ class MyForm(settingsmixin.SMainWindow):
if idCount == 0: if idCount == 0:
return return
font = QFont() font = QtGui.QFont()
font.setBold(False) font.setBold(False)
msgids = [] msgids = []
for i in range(0, idCount): for i in range(0, idCount):
msgids.append(str(tableWidget.item( msgids.append(str(tableWidget.item(
i, 3).data(Qt.UserRole).toPyObject())) i, 3).data(QtCore.Qt.UserRole).toPyObject()))
tableWidget.item(i, 0).setUnread(False) tableWidget.item(i, 0).setUnread(False)
tableWidget.item(i, 1).setUnread(False) tableWidget.item(i, 1).setUnread(False)
tableWidget.item(i, 2).setUnread(False) tableWidget.item(i, 2).setUnread(False)
@ -2564,7 +2585,7 @@ class MyForm(settingsmixin.SMainWindow):
else: else:
if dialog.lineEditPassphrase.text() != \ if dialog.lineEditPassphrase.text() != \
dialog.lineEditPassphraseAgain.text(): dialog.lineEditPassphraseAgain.text():
QMessageBox.about( QtGui.QMessageBox.about(
self, _translate("MainWindow", "Passphrase mismatch"), self, _translate("MainWindow", "Passphrase mismatch"),
_translate( _translate(
"MainWindow", "MainWindow",
@ -2572,7 +2593,7 @@ class MyForm(settingsmixin.SMainWindow):
" match. Try again.") " match. Try again.")
) )
elif dialog.lineEditPassphrase.text() == "": elif dialog.lineEditPassphrase.text() == "":
QMessageBox.about( QtGui.QMessageBox.about(
self, _translate("MainWindow", "Choose a passphrase"), self, _translate("MainWindow", "Choose a passphrase"),
_translate( _translate(
"MainWindow", "You really do need a passphrase.") "MainWindow", "You really do need a passphrase.")
@ -2780,14 +2801,14 @@ class MyForm(settingsmixin.SMainWindow):
tableWidget = self.getCurrentMessagelist() tableWidget = self.getCurrentMessagelist()
if not tableWidget: if not tableWidget:
return return
font = QFont() font = QtGui.QFont()
font.setBold(True) font.setBold(True)
inventoryHashesToMarkUnread = [] inventoryHashesToMarkUnread = []
modified = 0 modified = 0
for row in tableWidget.selectedIndexes(): for row in tableWidget.selectedIndexes():
currentRow = row.row() currentRow = row.row()
inventoryHashToMarkUnread = str(tableWidget.item( inventoryHashToMarkUnread = str(tableWidget.item(
currentRow, 3).data(Qt.UserRole).toPyObject()) currentRow, 3).data(QtCore.Qt.UserRole).toPyObject())
if inventoryHashToMarkUnread in inventoryHashesToMarkUnread: if inventoryHashToMarkUnread in inventoryHashesToMarkUnread:
# it returns columns as separate items, so we skip dupes # it returns columns as separate items, so we skip dupes
continue continue
@ -2807,9 +2828,9 @@ class MyForm(settingsmixin.SMainWindow):
if rowcount == 1: if rowcount == 1:
# performance optimisation # performance optimisation
self.propagateUnreadCount(tableWidget.item(currentRow, 1 if tableWidget.item(currentRow, 1).type == AccountMixin.SUBSCRIPTION else 0).data(Qt.UserRole), self.getCurrentFolder()) self.propagateUnreadCount(tableWidget.item(currentRow, 1 if tableWidget.item(currentRow, 1).type == AccountMixin.SUBSCRIPTION else 0).data(QtCore.Qt.UserRole), self.getCurrentFolder())
else: else:
self.propagateUnreadCount(tableWidget.item(currentRow, 1 if tableWidget.item(currentRow, 1).type == AccountMixin.SUBSCRIPTION else 0).data(Qt.UserRole), self.getCurrentFolder(), self.getCurrentTreeWidget(), 0) self.propagateUnreadCount(tableWidget.item(currentRow, 1 if tableWidget.item(currentRow, 1).type == AccountMixin.SUBSCRIPTION else 0).data(QtCore.Qt.UserRole), self.getCurrentFolder(), self.getCurrentTreeWidget(), 0)
# tableWidget.selectRow(currentRow + 1) # tableWidget.selectRow(currentRow + 1)
# This doesn't de-select the last message if you try to mark it unread, but that doesn't interfere. Might not be necessary. # This doesn't de-select the last message if you try to mark it unread, but that doesn't interfere. Might not be necessary.
# We could also select upwards, but then our problem would be with the topmost message. # We could also select upwards, but then our problem would be with the topmost message.
@ -2873,7 +2894,7 @@ class MyForm(settingsmixin.SMainWindow):
fromAddressAtCurrentInboxRow = tableWidget.item( fromAddressAtCurrentInboxRow = tableWidget.item(
currentInboxRow, 1).address currentInboxRow, 1).address
msgid = str(tableWidget.item( msgid = str(tableWidget.item(
currentInboxRow, 3).data(Qt.UserRole).toPyObject()) currentInboxRow, 3).data(QtCore.Qt.UserRole).toPyObject())
queryreturn = sqlQuery( queryreturn = sqlQuery(
'''select message from inbox where msgid=?''', msgid) '''select message from inbox where msgid=?''', msgid)
if queryreturn != []: if queryreturn != []:
@ -2892,10 +2913,10 @@ class MyForm(settingsmixin.SMainWindow):
# toAddressAtCurrentInboxRow = fromAddressAtCurrentInboxRow # toAddressAtCurrentInboxRow = fromAddressAtCurrentInboxRow
elif not BMConfigParser().has_section(toAddressAtCurrentInboxRow): elif not BMConfigParser().has_section(toAddressAtCurrentInboxRow):
QtGui.QMessageBox.information(self, _translate("MainWindow", "Address is gone"), _translate( QtGui.QMessageBox.information(self, _translate("MainWindow", "Address is gone"), _translate(
"MainWindow", "Bitmessage cannot find your address %1. Perhaps you removed it?").arg(toAddressAtCurrentInboxRow), QMessageBox.Ok) "MainWindow", "Bitmessage cannot find your address %1. Perhaps you removed it?").arg(toAddressAtCurrentInboxRow), QtGui.QMessageBox.Ok)
elif not BMConfigParser().getboolean(toAddressAtCurrentInboxRow, 'enabled'): elif not BMConfigParser().getboolean(toAddressAtCurrentInboxRow, 'enabled'):
QtGui.QMessageBox.information(self, _translate("MainWindow", "Address disabled"), _translate( QtGui.QMessageBox.information(self, _translate("MainWindow", "Address disabled"), _translate(
"MainWindow", "Error: The address from which you are trying to send is disabled. You\'ll have to enable it on the \'Your Identities\' tab before using it."), QMessageBox.Ok) "MainWindow", "Error: The address from which you are trying to send is disabled. You\'ll have to enable it on the \'Your Identities\' tab before using it."), QtGui.QMessageBox.Ok)
else: else:
self.setBroadcastEnablementDependingOnWhetherThisIsAMailingListAddress(toAddressAtCurrentInboxRow) self.setBroadcastEnablementDependingOnWhetherThisIsAMailingListAddress(toAddressAtCurrentInboxRow)
broadcast_tab_index = self.ui.tabWidgetSend.indexOf( broadcast_tab_index = self.ui.tabWidgetSend.indexOf(
@ -2943,7 +2964,7 @@ class MyForm(settingsmixin.SMainWindow):
currentInboxRow = tableWidget.currentRow() currentInboxRow = tableWidget.currentRow()
# tableWidget.item(currentRow,1).data(Qt.UserRole).toPyObject() # tableWidget.item(currentRow,1).data(Qt.UserRole).toPyObject()
addressAtCurrentInboxRow = tableWidget.item( addressAtCurrentInboxRow = tableWidget.item(
currentInboxRow, 1).data(Qt.UserRole) currentInboxRow, 1).data(QtCore.Qt.UserRole)
self.ui.tabWidget.setCurrentIndex( self.ui.tabWidget.setCurrentIndex(
self.ui.tabWidget.indexOf(self.ui.send) self.ui.tabWidget.indexOf(self.ui.send)
) )
@ -2958,9 +2979,9 @@ class MyForm(settingsmixin.SMainWindow):
currentInboxRow = tableWidget.currentRow() currentInboxRow = tableWidget.currentRow()
# tableWidget.item(currentRow,1).data(Qt.UserRole).toPyObject() # tableWidget.item(currentRow,1).data(Qt.UserRole).toPyObject()
addressAtCurrentInboxRow = tableWidget.item( addressAtCurrentInboxRow = tableWidget.item(
currentInboxRow, 1).data(Qt.UserRole) currentInboxRow, 1).data(QtCore.Qt.UserRole)
recipientAddress = tableWidget.item( recipientAddress = tableWidget.item(
currentInboxRow, 0).data(Qt.UserRole) currentInboxRow, 0).data(QtCore.Qt.UserRole)
# Let's make sure that it isn't already in the address book # Let's make sure that it isn't already in the address book
queryreturn = sqlQuery('''select * from blacklist where address=?''', queryreturn = sqlQuery('''select * from blacklist where address=?''',
addressAtCurrentInboxRow) addressAtCurrentInboxRow)
@ -2983,15 +3004,16 @@ class MyForm(settingsmixin.SMainWindow):
messageLists = (messageLists) messageLists = (messageLists)
for messageList in messageLists: for messageList in messageLists:
if row is not None: if row is not None:
inventoryHash = str(messageList.item(row, 3).data(Qt.UserRole).toPyObject()) inventoryHash = str(messageList.item(row, 3).data(
QtCore.Qt.UserRole).toPyObject())
messageList.removeRow(row) messageList.removeRow(row)
elif inventoryHash is not None: elif inventoryHash is not None:
for i in range(messageList.rowCount() - 1, -1, -1): for i in range(messageList.rowCount() - 1, -1, -1):
if messageList.item(i, 3).data(Qt.UserRole).toPyObject() == inventoryHash: if messageList.item(i, 3).data(QtCore.Qt.UserRole).toPyObject() == inventoryHash:
messageList.removeRow(i) messageList.removeRow(i)
elif ackData is not None: elif ackData is not None:
for i in range(messageList.rowCount() - 1, -1, -1): for i in range(messageList.rowCount() - 1, -1, -1):
if messageList.item(i, 3).data(Qt.UserRole).toPyObject() == ackData: if messageList.item(i, 3).data(QtCore.Qt.UserRole).toPyObject() == ackData:
messageList.removeRow(i) messageList.removeRow(i)
# Send item on the Inbox tab to trash # Send item on the Inbox tab to trash
@ -3065,13 +3087,14 @@ class MyForm(settingsmixin.SMainWindow):
return return
currentInboxRow = tableWidget.currentRow() currentInboxRow = tableWidget.currentRow()
try: try:
subjectAtCurrentInboxRow = str(tableWidget.item(currentInboxRow,2).data(Qt.UserRole)) subjectAtCurrentInboxRow = str(tableWidget.item(
currentInboxRow, 2).data(QtCore.Qt.UserRole))
except: except:
subjectAtCurrentInboxRow = '' subjectAtCurrentInboxRow = ''
# Retrieve the message data out of the SQL database # Retrieve the message data out of the SQL database
msgid = str(tableWidget.item( msgid = str(tableWidget.item(
currentInboxRow, 3).data(Qt.UserRole).toPyObject()) currentInboxRow, 3).data(QtCore.Qt.UserRole).toPyObject())
queryreturn = sqlQuery( queryreturn = sqlQuery(
'''select message from inbox where msgid=?''', msgid) '''select message from inbox where msgid=?''', msgid)
if queryreturn != []: if queryreturn != []:
@ -3079,7 +3102,7 @@ class MyForm(settingsmixin.SMainWindow):
message, = row message, = row
defaultFilename = "".join(x for x in subjectAtCurrentInboxRow if x.isalnum()) + '.txt' defaultFilename = "".join(x for x in subjectAtCurrentInboxRow if x.isalnum()) + '.txt'
filename = QFileDialog.getSaveFileName(self, _translate("MainWindow","Save As..."), defaultFilename, "Text files (*.txt);;All files (*.*)") filename = QtGui.QFileDialog.getSaveFileName(self, _translate("MainWindow","Save As..."), defaultFilename, "Text files (*.txt);;All files (*.*)")
if filename == '': if filename == '':
return return
try: try:
@ -3102,13 +3125,13 @@ class MyForm(settingsmixin.SMainWindow):
while tableWidget.selectedIndexes() != []: while tableWidget.selectedIndexes() != []:
currentRow = tableWidget.selectedIndexes()[0].row() currentRow = tableWidget.selectedIndexes()[0].row()
ackdataToTrash = str(tableWidget.item( ackdataToTrash = str(tableWidget.item(
currentRow, 3).data(Qt.UserRole).toPyObject()) currentRow, 3).data(QtCore.Qt.UserRole).toPyObject())
if folder == "trash" or shifted: if folder == "trash" or shifted:
sqlExecute('''DELETE FROM sent WHERE ackdata=?''', ackdataToTrash) sqlExecute('''DELETE FROM sent WHERE ackdata=?''', ackdataToTrash)
else: else:
sqlExecute('''UPDATE sent SET folder='trash' WHERE ackdata=?''', ackdataToTrash) sqlExecute('''UPDATE sent SET folder='trash' WHERE ackdata=?''', ackdataToTrash)
if tableWidget.item(currentRow, 0).unread: if tableWidget.item(currentRow, 0).unread:
self.propagateUnreadCount(tableWidget.item(currentRow, 1 if tableWidget.item(currentRow, 1).type == AccountMixin.SUBSCRIPTION else 0).data(Qt.UserRole), folder, self.getCurrentTreeWidget(), -1) self.propagateUnreadCount(tableWidget.item(currentRow, 1 if tableWidget.item(currentRow, 1).type == AccountMixin.SUBSCRIPTION else 0).data(QtCore.Qt.UserRole), folder, self.getCurrentTreeWidget(), -1)
self.getCurrentMessageTextedit().setPlainText("") self.getCurrentMessageTextedit().setPlainText("")
tableWidget.removeRow(currentRow) tableWidget.removeRow(currentRow)
self.statusBar().showMessage(_translate( self.statusBar().showMessage(_translate(
@ -3121,7 +3144,7 @@ class MyForm(settingsmixin.SMainWindow):
def on_action_ForceSend(self): def on_action_ForceSend(self):
currentRow = self.ui.tableWidgetInbox.currentRow() currentRow = self.ui.tableWidgetInbox.currentRow()
addressAtCurrentRow = self.ui.tableWidgetInbox.item( addressAtCurrentRow = self.ui.tableWidgetInbox.item(
currentRow, 0).data(Qt.UserRole) currentRow, 0).data(QtCore.Qt.UserRole)
toRipe = decodeAddress(addressAtCurrentRow)[3] toRipe = decodeAddress(addressAtCurrentRow)[3]
sqlExecute( sqlExecute(
'''UPDATE sent SET status='forcepow' WHERE toripe=? AND status='toodifficult' and folder='sent' ''', '''UPDATE sent SET status='forcepow' WHERE toripe=? AND status='toodifficult' and folder='sent' ''',
@ -3136,7 +3159,7 @@ class MyForm(settingsmixin.SMainWindow):
def on_action_SentClipboard(self): def on_action_SentClipboard(self):
currentRow = self.ui.tableWidgetInbox.currentRow() currentRow = self.ui.tableWidgetInbox.currentRow()
addressAtCurrentRow = self.ui.tableWidgetInbox.item( addressAtCurrentRow = self.ui.tableWidgetInbox.item(
currentRow, 0).data(Qt.UserRole) currentRow, 0).data(QtCore.Qt.UserRole)
clipboard = QtGui.QApplication.clipboard() clipboard = QtGui.QApplication.clipboard()
clipboard.setText(str(addressAtCurrentRow)) clipboard.setText(str(addressAtCurrentRow))
@ -3207,7 +3230,11 @@ class MyForm(settingsmixin.SMainWindow):
addressAtCurrentRow = str(self.ui.tableWidgetAddressBook.item(currentRow,1).text()) addressAtCurrentRow = str(self.ui.tableWidgetAddressBook.item(currentRow,1).text())
# Then subscribe to it... provided it's not already in the address book # Then subscribe to it... provided it's not already in the address book
if shared.isAddressInMySubscriptionsList(addressAtCurrentRow): if shared.isAddressInMySubscriptionsList(addressAtCurrentRow):
self.statusBar().showMessage(QtGui.QApplication.translate("MainWindow", "Error: You cannot add the same address to your subscriptions twice. Perhaps rename the existing one if you want."), 10000) self.statusBar().showMessage(_translate(
"MainWindow",
"Error: You cannot add the same address to your"
" subscriptions twice. Perhaps rename the existing"
" one if you want."), 10000)
continue continue
labelAtCurrentRow = self.ui.tableWidgetAddressBook.item(currentRow,0).text().toUtf8() labelAtCurrentRow = self.ui.tableWidgetAddressBook.item(currentRow,0).text().toUtf8()
self.addSubscription(addressAtCurrentRow, labelAtCurrentRow) self.addSubscription(addressAtCurrentRow, labelAtCurrentRow)
@ -3242,7 +3269,19 @@ class MyForm(settingsmixin.SMainWindow):
self.click_pushButtonAddSubscription() self.click_pushButtonAddSubscription()
def on_action_SubscriptionsDelete(self): def on_action_SubscriptionsDelete(self):
if QtGui.QMessageBox.question(self, "Delete subscription?", _translate("MainWindow", "If you delete the subscription, messages that you already received will become inaccessible. Maybe you can consider disabling the subscription instead. Disabled subscriptions will not receive new messages, but you can still view messages you already received.\n\nAre you sure you want to delete the subscription?"), QMessageBox.Yes|QMessageBox.No) != QMessageBox.Yes: if QtGui.QMessageBox.question(
self, "Delete subscription?",
_translate(
"MainWindow",
"If you delete the subscription, messages that you"
" already received will become inaccessible. Maybe"
" you can consider disabling the subscription instead."
" Disabled subscriptions will not receive new"
" messages, but you can still view messages you"
" already received.\n\nAre you sure you want to"
" delete the subscription?"
), QtGui.QMessageBox.Yes | QtGui.QMessageBox.No
) != QtGui.QMessageBox.Yes:
return return
address = self.getCurrentAccount() address = self.getCurrentAccount()
sqlExecute('''DELETE FROM subscriptions WHERE address=?''', sqlExecute('''DELETE FROM subscriptions WHERE address=?''',
@ -3366,12 +3405,13 @@ class MyForm(settingsmixin.SMainWindow):
currentRow = messagelist.currentRow() currentRow = messagelist.currentRow()
if currentRow >= 0: if currentRow >= 0:
msgid = str(messagelist.item( msgid = str(messagelist.item(
currentRow, 3).data(Qt.UserRole).toPyObject()) # data is saved at the 4. column of the table... currentRow, 3).data(QtCore.Qt.UserRole).toPyObject())
# data is saved at the 4. column of the table...
return msgid return msgid
return False return False
def getCurrentMessageTextedit(self): def getCurrentMessageTextedit(self):
currentIndex = self.ui.tabWidget.currentIndex(); currentIndex = self.ui.tabWidget.currentIndex()
messagelistList = [ messagelistList = [
self.ui.textEditInboxMessage, self.ui.textEditInboxMessage,
False, False,
@ -3396,7 +3436,7 @@ class MyForm(settingsmixin.SMainWindow):
def getCurrentSearchLine(self, currentIndex=None, retObj=False): def getCurrentSearchLine(self, currentIndex=None, retObj=False):
if currentIndex is None: if currentIndex is None:
currentIndex = self.ui.tabWidget.currentIndex(); currentIndex = self.ui.tabWidget.currentIndex()
messagelistList = [ messagelistList = [
self.ui.inboxSearchLineEdit, self.ui.inboxSearchLineEdit,
False, False,
@ -3413,7 +3453,7 @@ class MyForm(settingsmixin.SMainWindow):
def getCurrentSearchOption(self, currentIndex=None): def getCurrentSearchOption(self, currentIndex=None):
if currentIndex is None: if currentIndex is None:
currentIndex = self.ui.tabWidget.currentIndex(); currentIndex = self.ui.tabWidget.currentIndex()
messagelistList = [ messagelistList = [
self.ui.inboxSearchOption, self.ui.inboxSearchOption,
False, False,
@ -3472,7 +3512,19 @@ class MyForm(settingsmixin.SMainWindow):
if account.type == AccountMixin.NORMAL: if account.type == AccountMixin.NORMAL:
return # maybe in the future return # maybe in the future
elif account.type == AccountMixin.CHAN: elif account.type == AccountMixin.CHAN:
if QtGui.QMessageBox.question(self, "Delete channel?", _translate("MainWindow", "If you delete the channel, messages that you already received will become inaccessible. Maybe you can consider disabling the channel instead. Disabled channels will not receive new messages, but you can still view messages you already received.\n\nAre you sure you want to delete the channel?"), QMessageBox.Yes|QMessageBox.No) == QMessageBox.Yes: if QtGui.QMessageBox.question(
self, "Delete channel?",
_translate(
"MainWindow",
"If you delete the channel, messages that you"
" already received will become inaccessible."
" Maybe you can consider disabling the channel"
" instead. Disabled channels will not receive new"
" messages, but you can still view messages you"
" already received.\n\nAre you sure you want to"
" delete the channel?"
), QtGui.QMessageBox.Yes | QtGui.QMessageBox.No
) == QtGui.QMessageBox.Yes:
BMConfigParser().remove_section(str(account.address)) BMConfigParser().remove_section(str(account.address))
else: else:
return return
@ -3526,18 +3578,18 @@ class MyForm(settingsmixin.SMainWindow):
else: else:
currentColumn = 1 currentColumn = 1
if self.getCurrentFolder() == "sent": if self.getCurrentFolder() == "sent":
myAddress = tableWidget.item(currentRow, 1).data(Qt.UserRole) myAddress = tableWidget.item(currentRow, 1).data(QtCore.Qt.UserRole)
otherAddress = tableWidget.item(currentRow, 0).data(Qt.UserRole) otherAddress = tableWidget.item(currentRow, 0).data(QtCore.Qt.UserRole)
else: else:
myAddress = tableWidget.item(currentRow, 0).data(Qt.UserRole) myAddress = tableWidget.item(currentRow, 0).data(QtCore.Qt.UserRole)
otherAddress = tableWidget.item(currentRow, 1).data(Qt.UserRole) otherAddress = tableWidget.item(currentRow, 1).data(QtCore.Qt.UserRole)
account = accountClass(myAddress) account = accountClass(myAddress)
if isinstance(account, GatewayAccount) and otherAddress == account.relayAddress and ( if isinstance(account, GatewayAccount) and otherAddress == account.relayAddress and (
(currentColumn in [0, 2] and self.getCurrentFolder() == "sent") or (currentColumn in [0, 2] and self.getCurrentFolder() == "sent") or
(currentColumn in [1, 2] and self.getCurrentFolder() != "sent")): (currentColumn in [1, 2] and self.getCurrentFolder() != "sent")):
text = str(tableWidget.item(currentRow, currentColumn).label) text = str(tableWidget.item(currentRow, currentColumn).label)
else: else:
text = tableWidget.item(currentRow, currentColumn).data(Qt.UserRole) text = tableWidget.item(currentRow, currentColumn).data(QtCore.Qt.UserRole)
text = unicode(str(text), 'utf-8', 'ignore') text = unicode(str(text), 'utf-8', 'ignore')
clipboard = QtGui.QApplication.clipboard() clipboard = QtGui.QApplication.clipboard()
clipboard.setText(text) clipboard.setText(text)
@ -3580,7 +3632,10 @@ class MyForm(settingsmixin.SMainWindow):
current_files += [upper] current_files += [upper]
filters[0:0] = ['Image files (' + ' '.join(all_images_filter) + ')'] filters[0:0] = ['Image files (' + ' '.join(all_images_filter) + ')']
filters[1:1] = ['All files (*.*)'] filters[1:1] = ['All files (*.*)']
sourcefile = QFileDialog.getOpenFileName(self, _translate("MainWindow","Set avatar..."), filter = ';;'.join(filters)) sourcefile = QtGui.QFileDialog.getOpenFileName(
self, _translate("MainWindow", "Set avatar..."),
filter = ';;'.join(filters)
)
# determine the correct filename (note that avatars don't use the suffix) # determine the correct filename (note that avatars don't use the suffix)
destination = state.appdata + 'avatars/' + hash + '.' + sourcefile.split('.')[-1] destination = state.appdata + 'avatars/' + hash + '.' + sourcefile.split('.')[-1]
exists = QtCore.QFile.exists(destination) exists = QtCore.QFile.exists(destination)
@ -3730,7 +3785,7 @@ class MyForm(settingsmixin.SMainWindow):
self.popMenuInbox.addAction(self.actionMarkUnread) self.popMenuInbox.addAction(self.actionMarkUnread)
self.popMenuInbox.addSeparator() self.popMenuInbox.addSeparator()
address = tableWidget.item( address = tableWidget.item(
tableWidget.currentRow(), 0).data(Qt.UserRole) tableWidget.currentRow(), 0).data(QtCore.Qt.UserRole)
account = accountClass(address) account = accountClass(address)
if account.type == AccountMixin.CHAN: if account.type == AccountMixin.CHAN:
self.popMenuInbox.addAction(self.actionReplyChan) self.popMenuInbox.addAction(self.actionReplyChan)
@ -3762,7 +3817,7 @@ class MyForm(settingsmixin.SMainWindow):
currentRow = self.ui.tableWidgetInbox.currentRow() currentRow = self.ui.tableWidgetInbox.currentRow()
if currentRow >= 0: if currentRow >= 0:
ackData = str(self.ui.tableWidgetInbox.item( ackData = str(self.ui.tableWidgetInbox.item(
currentRow, 3).data(Qt.UserRole).toPyObject()) currentRow, 3).data(QtCore.Qt.UserRole).toPyObject())
queryreturn = sqlQuery('''SELECT status FROM sent where ackdata=?''', ackData) queryreturn = sqlQuery('''SELECT status FROM sent where ackdata=?''', ackData)
for row in queryreturn: for row in queryreturn:
status, = row status, = row
@ -3799,7 +3854,7 @@ class MyForm(settingsmixin.SMainWindow):
searchOption = self.getCurrentSearchOption() searchOption = self.getCurrentSearchOption()
messageTextedit = self.getCurrentMessageTextedit() messageTextedit = self.getCurrentMessageTextedit()
if messageTextedit: if messageTextedit:
messageTextedit.setPlainText(QString("")) messageTextedit.setPlainText(QtCore.QString(""))
messagelist = self.getCurrentMessagelist() messagelist = self.getCurrentMessagelist()
if messagelist: if messagelist:
account = self.getCurrentAccount() account = self.getCurrentAccount()
@ -3885,7 +3940,7 @@ class MyForm(settingsmixin.SMainWindow):
if refresh: if refresh:
if not tableWidget: if not tableWidget:
return return
font = QFont() font = QtGui.QFont()
font.setBold(False) font.setBold(False)
# inventoryHashesToMarkRead = [] # inventoryHashesToMarkRead = []
# inventoryHashToMarkRead = str(tableWidget.item( # inventoryHashToMarkRead = str(tableWidget.item(
@ -3896,7 +3951,7 @@ class MyForm(settingsmixin.SMainWindow):
tableWidget.item(currentRow, 2).setUnread(False) tableWidget.item(currentRow, 2).setUnread(False)
tableWidget.item(currentRow, 3).setFont(font) tableWidget.item(currentRow, 3).setFont(font)
if propagate: if propagate:
self.propagateUnreadCount(tableWidget.item(currentRow, 1 if tableWidget.item(currentRow, 1).type == AccountMixin.SUBSCRIPTION else 0).data(Qt.UserRole), folder, self.getCurrentTreeWidget(), -1) self.propagateUnreadCount(tableWidget.item(currentRow, 1 if tableWidget.item(currentRow, 1).type == AccountMixin.SUBSCRIPTION else 0).data(QtCore.Qt.UserRole), folder, self.getCurrentTreeWidget(), -1)
else: else:
data = self.getCurrentMessageId() data = self.getCurrentMessageId()
@ -4188,7 +4243,7 @@ class settingsDialog(QtGui.QDialog):
# In order for the time columns on the Inbox and Sent tabs to be sorted # In order for the time columns on the Inbox and Sent tabs to be sorted
# correctly (rather than alphabetically), we need to overload the < # correctly (rather than alphabetically), we need to overload the <
# operator and use this class instead of QTableWidgetItem. # operator and use this class instead of QTableWidgetItem.
class myTableWidgetItem(QTableWidgetItem): class myTableWidgetItem(QtGui.QTableWidgetItem):
def __lt__(self, other): def __lt__(self, other):
return int(self.data(33).toPyObject()) < int(other.data(33).toPyObject()) return int(self.data(33).toPyObject()) < int(other.data(33).toPyObject())
@ -4197,7 +4252,8 @@ class myTableWidgetItem(QTableWidgetItem):
app = None app = None
myapp = None myapp = None
class MySingleApplication(QApplication):
class MySingleApplication(QtGui.QApplication):
""" """
Listener to allow our Qt form to get focus when another instance of the Listener to allow our Qt form to get focus when another instance of the
application is open. application is open.
@ -4247,12 +4303,14 @@ class MySingleApplication(QApplication):
if myapp: if myapp:
myapp.appIndicatorShow() myapp.appIndicatorShow()
def init(): def init():
global app global app
if not app: if not app:
app = MySingleApplication(sys.argv) app = MySingleApplication(sys.argv)
return app return app
def run(): def run():
global myapp global myapp
app = init() app = init()