2013-06-12 10:05:20 +02:00
try :
import locale
except :
pass
2013-05-11 18:33:16 +02:00
withMessagingMenu = False
2013-05-10 21:47:01 +02:00
try :
from gi . repository import MessagingMenu
2013-05-11 18:33:16 +02:00
from gi . repository import Notify
withMessagingMenu = True
2013-05-10 21:47:01 +02:00
except ImportError :
MessagingMenu = None
2013-05-02 17:53:54 +02:00
from addresses import *
import shared
from bitmessageui import *
2013-07-07 17:34:43 +02:00
from namecoin import namecoinConnection , ensureNamecoinOptions
2013-05-02 17:53:54 +02:00
from newaddressdialog import *
from newsubscriptiondialog import *
from regenerateaddresses import *
from specialaddressbehavior import *
from settings import *
from about import *
from help import *
from iconglossary import *
import sys
from time import strftime , localtime , gmtime
import time
import os
from pyelliptic . openssl import OpenSSL
2013-05-03 21:53:38 +02:00
import pickle
2013-05-14 17:44:51 +02:00
import platform
2013-05-02 17:53:54 +02:00
2013-06-25 22:26:12 +02:00
try :
from PyQt4 import QtCore , QtGui
from PyQt4 . QtCore import *
from PyQt4 . QtGui import *
except Exception as err :
print ' 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). '
print ' Error message: ' , err
sys . exit ( )
try :
_encoding = QtGui . QApplication . UnicodeUTF8
except AttributeError :
print ' QtGui.QApplication.UnicodeUTF8 error: ' , err
def _translate ( context , text ) :
return QtGui . QApplication . translate ( context , text )
2013-05-02 17:53:54 +02:00
class MyForm ( QtGui . QMainWindow ) :
2013-05-10 21:47:01 +02:00
2013-05-14 17:06:01 +02:00
str_broadcast_subscribers = ' [Broadcast subscribers] '
2013-05-02 17:53:54 +02:00
def __init__ ( self , parent = None ) :
QtGui . QWidget . __init__ ( self , parent )
self . ui = Ui_MainWindow ( )
self . ui . setupUi ( self )
2013-06-12 23:12:32 +02:00
# Ask the user if we may delete their old version 1 addresses if they
# have any.
2013-05-02 17:53:54 +02:00
configSections = shared . config . sections ( )
for addressInKeysFile in configSections :
2013-06-12 23:12:32 +02:00
if addressInKeysFile != ' bitmessagesettings ' :
status , addressVersionNumber , streamNumber , hash = decodeAddress (
addressInKeysFile )
2013-05-02 17:53:54 +02:00
if addressVersionNumber == 1 :
2013-06-13 09:59:40 +02:00
displayMsg = _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " One of your addresses, % 1, is an old version 1 address. Version 1 addresses are no longer supported. "
+ " May we delete it now? " ) . arg ( addressInKeysFile )
reply = QtGui . QMessageBox . question (
self , ' Message ' , displayMsg , QtGui . QMessageBox . Yes , QtGui . QMessageBox . No )
2013-05-02 17:53:54 +02:00
if reply == QtGui . QMessageBox . Yes :
shared . config . remove_section ( addressInKeysFile )
with open ( shared . appdata + ' keys.dat ' , ' wb ' ) as configfile :
shared . config . write ( configfile )
2013-06-12 23:12:32 +02:00
# Configure Bitmessage to start on startup (or remove the
# configuration) based on the setting in the keys.dat file
2013-05-02 17:53:54 +02:00
if ' win32 ' in sys . platform or ' win64 ' in sys . platform :
2013-06-12 23:12:32 +02:00
# Auto-startup for Windows
2013-05-02 17:53:54 +02:00
RUN_PATH = " HKEY_CURRENT_USER \\ Software \\ Microsoft \\ Windows \\ CurrentVersion \\ Run "
self . settings = QSettings ( RUN_PATH , QSettings . NativeFormat )
2013-06-12 23:12:32 +02:00
self . settings . remove (
" PyBitmessage " ) # In case the user moves the program and the registry entry is no longer valid, this will delete the old registry entry.
2013-05-02 17:53:54 +02:00
if shared . config . getboolean ( ' bitmessagesettings ' , ' startonlogon ' ) :
2013-06-12 23:12:32 +02:00
self . settings . setValue ( " PyBitmessage " , sys . argv [ 0 ] )
2013-05-02 17:53:54 +02:00
elif ' darwin ' in sys . platform :
2013-06-12 23:12:32 +02:00
# startup for mac
2013-05-02 17:53:54 +02:00
pass
elif ' linux ' in sys . platform :
2013-06-12 23:12:32 +02:00
# startup for linux
2013-05-02 17:53:54 +02:00
pass
self . ui . labelSendBroadcastWarning . setVisible ( False )
2013-06-12 23:12:32 +02:00
# FILE MENU and other buttons
QtCore . QObject . connect ( self . ui . actionExit , QtCore . SIGNAL (
" triggered() " ) , self . quit )
QtCore . QObject . connect ( self . ui . actionManageKeys , QtCore . SIGNAL (
" triggered() " ) , self . click_actionManageKeys )
QtCore . QObject . connect ( self . ui . actionDeleteAllTrashedMessages , QtCore . SIGNAL (
" triggered() " ) , self . click_actionDeleteAllTrashedMessages )
QtCore . QObject . connect ( self . ui . actionRegenerateDeterministicAddresses , QtCore . SIGNAL (
" triggered() " ) , self . click_actionRegenerateDeterministicAddresses )
QtCore . QObject . connect ( self . ui . pushButtonNewAddress , QtCore . SIGNAL (
" clicked() " ) , self . click_NewAddressDialog )
QtCore . QObject . connect ( self . ui . comboBoxSendFrom , QtCore . SIGNAL (
" activated(int) " ) , self . redrawLabelFrom )
QtCore . QObject . connect ( self . ui . pushButtonAddAddressBook , QtCore . SIGNAL (
" clicked() " ) , self . click_pushButtonAddAddressBook )
QtCore . QObject . connect ( self . ui . pushButtonAddSubscription , QtCore . SIGNAL (
" clicked() " ) , self . click_pushButtonAddSubscription )
QtCore . QObject . connect ( self . ui . pushButtonAddBlacklist , QtCore . SIGNAL (
" clicked() " ) , self . click_pushButtonAddBlacklist )
QtCore . QObject . connect ( self . ui . pushButtonSend , QtCore . SIGNAL (
" clicked() " ) , self . click_pushButtonSend )
QtCore . QObject . connect ( self . ui . pushButtonLoadFromAddressBook , QtCore . SIGNAL (
" clicked() " ) , self . click_pushButtonLoadFromAddressBook )
2013-07-04 22:06:30 +02:00
QtCore . QObject . connect ( self . ui . pushButtonFetchNamecoinID , QtCore . SIGNAL (
" clicked() " ) , self . click_pushButtonFetchNamecoinID )
2013-06-12 23:12:32 +02:00
QtCore . QObject . connect ( self . ui . radioButtonBlacklist , QtCore . SIGNAL (
" clicked() " ) , self . click_radioButtonBlacklist )
QtCore . QObject . connect ( self . ui . radioButtonWhitelist , QtCore . SIGNAL (
" clicked() " ) , self . click_radioButtonWhitelist )
QtCore . QObject . connect ( self . ui . pushButtonStatusIcon , QtCore . SIGNAL (
" clicked() " ) , self . click_pushButtonStatusIcon )
QtCore . QObject . connect ( self . ui . actionSettings , QtCore . SIGNAL (
" triggered() " ) , self . click_actionSettings )
QtCore . QObject . connect ( self . ui . actionAbout , QtCore . SIGNAL (
" triggered() " ) , self . click_actionAbout )
QtCore . QObject . connect ( self . ui . actionHelp , QtCore . SIGNAL (
" triggered() " ) , self . click_actionHelp )
# Popup menu for the Inbox tab
2013-05-02 17:53:54 +02:00
self . ui . inboxContextMenuToolbar = QtGui . QToolBar ( )
# Actions
2013-06-13 09:59:40 +02:00
self . actionReply = self . ui . inboxContextMenuToolbar . addAction ( _translate (
" MainWindow " , " Reply " ) , self . on_action_InboxReply )
self . actionAddSenderToAddressBook = self . ui . inboxContextMenuToolbar . addAction ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Add sender to your Address Book " ) , self . on_action_InboxAddSenderToAddressBook )
self . actionTrashInboxMessage = self . ui . inboxContextMenuToolbar . addAction (
2013-06-13 09:59:40 +02:00
_translate ( " MainWindow " , " Move to Trash " ) , self . on_action_InboxTrash )
self . actionForceHtml = self . ui . inboxContextMenuToolbar . addAction ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " View HTML code as formatted text " ) , self . on_action_InboxMessageForceHtml )
2013-06-19 22:49:31 +02:00
self . actionSaveMessageAs = self . ui . inboxContextMenuToolbar . addAction ( _translate (
" MainWindow " , " Save message as... " ) , self . on_action_InboxSaveMessageAs )
2013-06-12 23:12:32 +02:00
self . ui . tableWidgetInbox . setContextMenuPolicy (
QtCore . Qt . CustomContextMenu )
self . connect ( self . ui . tableWidgetInbox , QtCore . SIGNAL (
' customContextMenuRequested(const QPoint&) ' ) , self . on_context_menuInbox )
self . popMenuInbox = QtGui . QMenu ( self )
self . popMenuInbox . addAction ( self . actionForceHtml )
2013-05-02 17:53:54 +02:00
self . popMenuInbox . addSeparator ( )
2013-06-12 23:12:32 +02:00
self . popMenuInbox . addAction ( self . actionReply )
self . popMenuInbox . addAction ( self . actionAddSenderToAddressBook )
2013-05-02 17:53:54 +02:00
self . popMenuInbox . addSeparator ( )
2013-06-17 00:28:18 +02:00
self . popMenuInbox . addAction ( self . actionSaveMessageAs )
2013-05-02 17:53:54 +02:00
self . popMenuInbox . addAction ( self . actionTrashInboxMessage )
2013-06-12 23:12:32 +02:00
# Popup menu for the Your Identities tab
2013-05-02 17:53:54 +02:00
self . ui . addressContextMenuToolbar = QtGui . QToolBar ( )
# Actions
2013-06-13 09:59:40 +02:00
self . actionNew = self . ui . addressContextMenuToolbar . addAction ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " New " ) , self . on_action_YourIdentitiesNew )
2013-06-13 09:59:40 +02:00
self . actionEnable = self . ui . addressContextMenuToolbar . addAction ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Enable " ) , self . on_action_YourIdentitiesEnable )
2013-06-13 09:59:40 +02:00
self . actionDisable = self . ui . addressContextMenuToolbar . addAction ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Disable " ) , self . on_action_YourIdentitiesDisable )
2013-06-13 09:59:40 +02:00
self . actionClipboard = self . ui . addressContextMenuToolbar . addAction ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Copy address to clipboard " ) , self . on_action_YourIdentitiesClipboard )
2013-06-13 09:59:40 +02:00
self . actionSpecialAddressBehavior = self . ui . addressContextMenuToolbar . addAction ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Special address behavior... " ) , self . on_action_SpecialAddressBehaviorDialog )
self . ui . tableWidgetYourIdentities . setContextMenuPolicy (
QtCore . Qt . CustomContextMenu )
self . connect ( self . ui . tableWidgetYourIdentities , QtCore . SIGNAL (
' customContextMenuRequested(const QPoint&) ' ) , self . on_context_menuYourIdentities )
self . popMenu = QtGui . QMenu ( self )
self . popMenu . addAction ( self . actionNew )
2013-05-02 17:53:54 +02:00
self . popMenu . addSeparator ( )
2013-06-12 23:12:32 +02:00
self . popMenu . addAction ( self . actionClipboard )
2013-05-02 17:53:54 +02:00
self . popMenu . addSeparator ( )
2013-06-12 23:12:32 +02:00
self . popMenu . addAction ( self . actionEnable )
self . popMenu . addAction ( self . actionDisable )
self . popMenu . addAction ( self . actionSpecialAddressBehavior )
2013-05-02 17:53:54 +02:00
2013-06-12 23:12:32 +02:00
# Popup menu for the Address Book page
2013-05-02 17:53:54 +02:00
self . ui . addressBookContextMenuToolbar = QtGui . QToolBar ( )
# Actions
2013-06-13 09:59:40 +02:00
self . actionAddressBookSend = self . ui . addressBookContextMenuToolbar . addAction ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Send message to this address " ) , self . on_action_AddressBookSend )
2013-06-13 09:59:40 +02:00
self . actionAddressBookClipboard = self . ui . addressBookContextMenuToolbar . addAction ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Copy address to clipboard " ) , self . on_action_AddressBookClipboard )
2013-06-19 18:19:07 +02:00
self . actionAddressBookSubscribe = self . ui . addressBookContextMenuToolbar . addAction ( _translate (
" MainWindow " , " Subscribe to this address " ) , self . on_action_AddressBookSubscribe )
2013-06-13 09:59:40 +02:00
self . actionAddressBookNew = self . ui . addressBookContextMenuToolbar . addAction ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Add New Address " ) , self . on_action_AddressBookNew )
2013-06-13 09:59:40 +02:00
self . actionAddressBookDelete = self . ui . addressBookContextMenuToolbar . addAction ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Delete " ) , self . on_action_AddressBookDelete )
self . ui . tableWidgetAddressBook . setContextMenuPolicy (
QtCore . Qt . CustomContextMenu )
self . connect ( self . ui . tableWidgetAddressBook , QtCore . SIGNAL (
' customContextMenuRequested(const QPoint&) ' ) , self . on_context_menuAddressBook )
self . popMenuAddressBook = QtGui . QMenu ( self )
self . popMenuAddressBook . addAction ( self . actionAddressBookSend )
self . popMenuAddressBook . addAction ( self . actionAddressBookClipboard )
2013-06-14 03:55:38 +02:00
self . popMenuAddressBook . addAction ( self . actionAddressBookSubscribe )
2013-05-02 17:53:54 +02:00
self . popMenuAddressBook . addSeparator ( )
2013-06-12 23:12:32 +02:00
self . popMenuAddressBook . addAction ( self . actionAddressBookNew )
self . popMenuAddressBook . addAction ( self . actionAddressBookDelete )
2013-05-02 17:53:54 +02:00
2013-06-12 23:12:32 +02:00
# Popup menu for the Subscriptions page
2013-05-02 17:53:54 +02:00
self . ui . subscriptionsContextMenuToolbar = QtGui . QToolBar ( )
# Actions
2013-06-12 23:12:32 +02:00
self . actionsubscriptionsNew = self . ui . subscriptionsContextMenuToolbar . addAction (
2013-06-13 09:59:40 +02:00
_translate ( " MainWindow " , " New " ) , self . on_action_SubscriptionsNew )
2013-06-12 23:12:32 +02:00
self . actionsubscriptionsDelete = self . ui . subscriptionsContextMenuToolbar . addAction (
2013-06-13 09:59:40 +02:00
_translate ( " MainWindow " , " Delete " ) , self . on_action_SubscriptionsDelete )
2013-06-12 23:12:32 +02:00
self . actionsubscriptionsClipboard = self . ui . subscriptionsContextMenuToolbar . addAction (
2013-06-13 09:59:40 +02:00
_translate ( " MainWindow " , " Copy address to clipboard " ) , self . on_action_SubscriptionsClipboard )
2013-06-12 23:12:32 +02:00
self . actionsubscriptionsEnable = self . ui . subscriptionsContextMenuToolbar . addAction (
2013-06-13 09:59:40 +02:00
_translate ( " MainWindow " , " Enable " ) , self . on_action_SubscriptionsEnable )
2013-06-12 23:12:32 +02:00
self . actionsubscriptionsDisable = self . ui . subscriptionsContextMenuToolbar . addAction (
2013-06-13 09:59:40 +02:00
_translate ( " MainWindow " , " Disable " ) , self . on_action_SubscriptionsDisable )
2013-06-12 23:12:32 +02:00
self . ui . tableWidgetSubscriptions . setContextMenuPolicy (
QtCore . Qt . CustomContextMenu )
self . connect ( self . ui . tableWidgetSubscriptions , QtCore . SIGNAL (
' customContextMenuRequested(const QPoint&) ' ) , self . on_context_menuSubscriptions )
self . popMenuSubscriptions = QtGui . QMenu ( self )
self . popMenuSubscriptions . addAction ( self . actionsubscriptionsNew )
self . popMenuSubscriptions . addAction ( self . actionsubscriptionsDelete )
2013-05-02 17:53:54 +02:00
self . popMenuSubscriptions . addSeparator ( )
2013-06-12 23:12:32 +02:00
self . popMenuSubscriptions . addAction ( self . actionsubscriptionsEnable )
self . popMenuSubscriptions . addAction ( self . actionsubscriptionsDisable )
2013-05-02 17:53:54 +02:00
self . popMenuSubscriptions . addSeparator ( )
2013-06-12 23:12:32 +02:00
self . popMenuSubscriptions . addAction ( self . actionsubscriptionsClipboard )
2013-05-02 17:53:54 +02:00
2013-06-12 23:12:32 +02:00
# Popup menu for the Sent page
2013-05-02 17:53:54 +02:00
self . ui . sentContextMenuToolbar = QtGui . QToolBar ( )
# Actions
2013-06-13 09:59:40 +02:00
self . actionTrashSentMessage = self . ui . sentContextMenuToolbar . addAction ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Move to Trash " ) , self . on_action_SentTrash )
2013-06-13 09:59:40 +02:00
self . actionSentClipboard = self . ui . sentContextMenuToolbar . addAction ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Copy destination address to clipboard " ) , self . on_action_SentClipboard )
2013-06-13 09:59:40 +02:00
self . actionForceSend = self . ui . sentContextMenuToolbar . addAction ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Force send " ) , self . on_action_ForceSend )
self . ui . tableWidgetSent . setContextMenuPolicy (
QtCore . Qt . CustomContextMenu )
self . connect ( self . ui . tableWidgetSent , QtCore . SIGNAL (
' customContextMenuRequested(const QPoint&) ' ) , self . on_context_menuSent )
# self.popMenuSent = QtGui.QMenu( self )
# self.popMenuSent.addAction( self.actionSentClipboard )
# self.popMenuSent.addAction( self.actionTrashSentMessage )
# Popup menu for the Blacklist page
2013-05-02 17:53:54 +02:00
self . ui . blacklistContextMenuToolbar = QtGui . QToolBar ( )
# Actions
2013-06-13 09:59:40 +02:00
self . actionBlacklistNew = self . ui . blacklistContextMenuToolbar . addAction ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Add new entry " ) , self . on_action_BlacklistNew )
2013-06-13 09:59:40 +02:00
self . actionBlacklistDelete = self . ui . blacklistContextMenuToolbar . addAction ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Delete " ) , self . on_action_BlacklistDelete )
2013-06-13 09:59:40 +02:00
self . actionBlacklistClipboard = self . ui . blacklistContextMenuToolbar . addAction ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Copy address to clipboard " ) , self . on_action_BlacklistClipboard )
2013-06-13 09:59:40 +02:00
self . actionBlacklistEnable = self . ui . blacklistContextMenuToolbar . addAction ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Enable " ) , self . on_action_BlacklistEnable )
2013-06-13 09:59:40 +02:00
self . actionBlacklistDisable = self . ui . blacklistContextMenuToolbar . addAction ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Disable " ) , self . on_action_BlacklistDisable )
self . ui . tableWidgetBlacklist . setContextMenuPolicy (
QtCore . Qt . CustomContextMenu )
self . connect ( self . ui . tableWidgetBlacklist , QtCore . SIGNAL (
' customContextMenuRequested(const QPoint&) ' ) , self . on_context_menuBlacklist )
self . popMenuBlacklist = QtGui . QMenu ( self )
# self.popMenuBlacklist.addAction( self.actionBlacklistNew )
self . popMenuBlacklist . addAction ( self . actionBlacklistDelete )
2013-05-02 17:53:54 +02:00
self . popMenuBlacklist . addSeparator ( )
2013-06-12 23:12:32 +02:00
self . popMenuBlacklist . addAction ( self . actionBlacklistClipboard )
2013-05-02 17:53:54 +02:00
self . popMenuBlacklist . addSeparator ( )
2013-06-12 23:12:32 +02:00
self . popMenuBlacklist . addAction ( self . actionBlacklistEnable )
self . popMenuBlacklist . addAction ( self . actionBlacklistDisable )
2013-05-02 17:53:54 +02:00
2013-06-12 23:12:32 +02:00
# Initialize the user's list of addresses on the 'Your Identities' tab.
2013-05-02 17:53:54 +02:00
configSections = shared . config . sections ( )
for addressInKeysFile in configSections :
2013-06-12 23:12:32 +02:00
if addressInKeysFile != ' bitmessagesettings ' :
isEnabled = shared . config . getboolean (
addressInKeysFile , ' enabled ' )
newItem = QtGui . QTableWidgetItem ( unicode (
shared . config . get ( addressInKeysFile , ' label ' ) , ' utf-8) ' ) )
2013-05-02 17:53:54 +02:00
if not isEnabled :
2013-06-12 23:12:32 +02:00
newItem . setTextColor ( QtGui . QColor ( 128 , 128 , 128 ) )
2013-05-02 17:53:54 +02:00
self . ui . tableWidgetYourIdentities . insertRow ( 0 )
self . ui . tableWidgetYourIdentities . setItem ( 0 , 0 , newItem )
newItem = QtGui . QTableWidgetItem ( addressInKeysFile )
2013-06-12 23:12:32 +02:00
newItem . setFlags (
QtCore . Qt . ItemIsSelectable | QtCore . Qt . ItemIsEnabled )
2013-05-02 17:53:54 +02:00
if not isEnabled :
2013-06-12 23:12:32 +02:00
newItem . setTextColor ( QtGui . QColor ( 128 , 128 , 128 ) )
if shared . safeConfigGetBoolean ( addressInKeysFile , ' mailinglist ' ) :
newItem . setTextColor ( QtGui . QColor ( 137 , 04 , 177 ) ) # magenta
2013-05-02 17:53:54 +02:00
self . ui . tableWidgetYourIdentities . setItem ( 0 , 1 , newItem )
2013-06-12 23:12:32 +02:00
newItem = QtGui . QTableWidgetItem ( str (
addressStream ( addressInKeysFile ) ) )
newItem . setFlags (
QtCore . Qt . ItemIsSelectable | QtCore . Qt . ItemIsEnabled )
2013-05-02 17:53:54 +02:00
if not isEnabled :
2013-06-12 23:12:32 +02:00
newItem . setTextColor ( QtGui . QColor ( 128 , 128 , 128 ) )
2013-05-02 17:53:54 +02:00
self . ui . tableWidgetYourIdentities . setItem ( 0 , 2 , newItem )
if isEnabled :
2013-06-12 23:12:32 +02:00
status , addressVersionNumber , streamNumber , hash = decodeAddress (
addressInKeysFile )
2013-05-02 17:53:54 +02:00
2013-06-12 23:12:32 +02:00
# Load inbox from messages database file
2013-05-02 17:53:54 +02:00
font = QFont ( )
font . setBold ( True )
2013-05-02 20:18:24 +02:00
shared . sqlLock . acquire ( )
2013-06-12 23:12:32 +02:00
shared . sqlSubmitQueue . put (
''' SELECT msgid, toaddress, fromaddress, subject, received, message, read FROM inbox where folder= ' inbox ' ORDER BY received ''' )
2013-05-02 17:53:54 +02:00
shared . sqlSubmitQueue . put ( ' ' )
queryreturn = shared . sqlReturnQueue . get ( )
2013-05-02 20:18:24 +02:00
shared . sqlLock . release ( )
2013-05-02 17:53:54 +02:00
for row in queryreturn :
msgid , toAddress , fromAddress , subject , received , message , read = row
2013-06-11 00:53:15 +02:00
subject = shared . fixPotentiallyInvalidUTF8Data ( subject )
message = shared . fixPotentiallyInvalidUTF8Data ( message )
2013-05-02 17:53:54 +02:00
try :
2013-05-14 17:06:01 +02:00
if toAddress == self . str_broadcast_subscribers :
toLabel = self . str_broadcast_subscribers
2013-05-02 17:53:54 +02:00
else :
toLabel = shared . config . get ( toAddress , ' label ' )
except :
toLabel = ' '
if toLabel == ' ' :
toLabel = toAddress
fromLabel = ' '
t = ( fromAddress , )
2013-05-02 20:18:24 +02:00
shared . sqlLock . acquire ( )
2013-06-12 23:12:32 +02:00
shared . sqlSubmitQueue . put (
''' select label from addressbook where address=? ''' )
2013-05-02 17:53:54 +02:00
shared . sqlSubmitQueue . put ( t )
queryreturn = shared . sqlReturnQueue . get ( )
2013-05-02 20:18:24 +02:00
shared . sqlLock . release ( )
2013-05-02 17:53:54 +02:00
2013-06-12 23:12:32 +02:00
if queryreturn != [ ] :
2013-05-02 17:53:54 +02:00
for row in queryreturn :
fromLabel , = row
2013-06-12 23:12:32 +02:00
if fromLabel == ' ' : # If this address wasn't in our address book...
2013-05-02 17:53:54 +02:00
t = ( fromAddress , )
2013-05-02 20:18:24 +02:00
shared . sqlLock . acquire ( )
2013-06-12 23:12:32 +02:00
shared . sqlSubmitQueue . put (
''' select label from subscriptions where address=? ''' )
2013-05-02 17:53:54 +02:00
shared . sqlSubmitQueue . put ( t )
queryreturn = shared . sqlReturnQueue . get ( )
2013-05-02 20:18:24 +02:00
shared . sqlLock . release ( )
2013-05-02 17:53:54 +02:00
2013-06-12 23:12:32 +02:00
if queryreturn != [ ] :
2013-05-02 17:53:54 +02:00
for row in queryreturn :
fromLabel , = row
self . ui . tableWidgetInbox . insertRow ( 0 )
2013-06-12 23:12:32 +02:00
newItem = QtGui . QTableWidgetItem ( unicode ( toLabel , ' utf-8 ' ) )
newItem . setToolTip ( unicode ( toLabel , ' utf-8 ' ) )
newItem . setFlags (
QtCore . Qt . ItemIsSelectable | QtCore . Qt . ItemIsEnabled )
2013-05-02 17:53:54 +02:00
if not read :
newItem . setFont ( font )
2013-06-12 23:12:32 +02:00
newItem . setData ( Qt . UserRole , str ( toAddress ) )
if shared . safeConfigGetBoolean ( toAddress , ' mailinglist ' ) :
newItem . setTextColor ( QtGui . QColor ( 137 , 04 , 177 ) )
self . ui . tableWidgetInbox . setItem ( 0 , 0 , newItem )
2013-05-02 17:53:54 +02:00
if fromLabel == ' ' :
2013-06-12 23:12:32 +02:00
newItem = QtGui . QTableWidgetItem (
unicode ( fromAddress , ' utf-8 ' ) )
newItem . setToolTip ( unicode ( fromAddress , ' utf-8 ' ) )
2013-05-02 17:53:54 +02:00
else :
2013-06-12 23:12:32 +02:00
newItem = QtGui . QTableWidgetItem ( unicode ( fromLabel , ' utf-8 ' ) )
newItem . setToolTip ( unicode ( fromLabel , ' utf-8 ' ) )
newItem . setFlags (
QtCore . Qt . ItemIsSelectable | QtCore . Qt . ItemIsEnabled )
2013-05-02 17:53:54 +02:00
if not read :
newItem . setFont ( font )
2013-06-12 23:12:32 +02:00
newItem . setData ( Qt . UserRole , str ( fromAddress ) )
self . ui . tableWidgetInbox . setItem ( 0 , 1 , newItem )
newItem = QtGui . QTableWidgetItem ( unicode ( subject , ' utf-8 ' ) )
newItem . setToolTip ( unicode ( subject , ' utf-8 ' ) )
newItem . setData ( Qt . UserRole , unicode ( message , ' utf-8) ' ) )
newItem . setFlags (
QtCore . Qt . ItemIsSelectable | QtCore . Qt . ItemIsEnabled )
2013-05-02 17:53:54 +02:00
if not read :
newItem . setFont ( font )
2013-06-12 23:12:32 +02:00
self . ui . tableWidgetInbox . setItem ( 0 , 2 , newItem )
newItem = myTableWidgetItem ( unicode ( strftime ( shared . config . get (
' bitmessagesettings ' , ' timeformat ' ) , localtime ( int ( received ) ) ) , ' utf-8 ' ) )
newItem . setToolTip ( unicode ( strftime ( shared . config . get (
' bitmessagesettings ' , ' timeformat ' ) , localtime ( int ( received ) ) ) , ' utf-8 ' ) )
newItem . setData ( Qt . UserRole , QByteArray ( msgid ) )
newItem . setData ( 33 , int ( received ) )
newItem . setFlags (
QtCore . Qt . ItemIsSelectable | QtCore . Qt . ItemIsEnabled )
2013-05-02 17:53:54 +02:00
if not read :
newItem . setFont ( font )
2013-06-12 23:12:32 +02:00
self . ui . tableWidgetInbox . setItem ( 0 , 3 , newItem )
self . ui . tableWidgetInbox . sortItems ( 3 , Qt . DescendingOrder )
2013-05-02 17:53:54 +02:00
self . ui . tableWidgetInbox . keyPressEvent = self . tableWidgetInboxKeyPressEvent
2013-06-11 00:53:15 +02:00
2013-06-12 23:12:32 +02:00
# Load Sent items from database
2013-05-02 20:18:24 +02:00
shared . sqlLock . acquire ( )
2013-06-12 23:12:32 +02:00
shared . sqlSubmitQueue . put (
''' SELECT toaddress, fromaddress, subject, message, status, ackdata, lastactiontime FROM sent where folder = ' sent ' ORDER BY lastactiontime ''' )
2013-05-02 17:53:54 +02:00
shared . sqlSubmitQueue . put ( ' ' )
queryreturn = shared . sqlReturnQueue . get ( )
2013-05-02 20:18:24 +02:00
shared . sqlLock . release ( )
2013-05-02 17:53:54 +02:00
for row in queryreturn :
toAddress , fromAddress , subject , message , status , ackdata , lastactiontime = row
2013-06-11 00:53:15 +02:00
subject = shared . fixPotentiallyInvalidUTF8Data ( subject )
message = shared . fixPotentiallyInvalidUTF8Data ( message )
2013-05-02 17:53:54 +02:00
try :
fromLabel = shared . config . get ( fromAddress , ' label ' )
except :
fromLabel = ' '
if fromLabel == ' ' :
fromLabel = fromAddress
toLabel = ' '
t = ( toAddress , )
2013-05-02 20:18:24 +02:00
shared . sqlLock . acquire ( )
2013-06-12 23:12:32 +02:00
shared . sqlSubmitQueue . put (
''' select label from addressbook where address=? ''' )
2013-05-02 17:53:54 +02:00
shared . sqlSubmitQueue . put ( t )
queryreturn = shared . sqlReturnQueue . get ( )
2013-05-02 20:18:24 +02:00
shared . sqlLock . release ( )
2013-05-02 17:53:54 +02:00
2013-06-12 23:12:32 +02:00
if queryreturn != [ ] :
2013-05-02 17:53:54 +02:00
for row in queryreturn :
toLabel , = row
self . ui . tableWidgetSent . insertRow ( 0 )
if toLabel == ' ' :
2013-06-12 23:12:32 +02:00
newItem = QtGui . QTableWidgetItem ( unicode ( toAddress , ' utf-8 ' ) )
newItem . setToolTip ( unicode ( toAddress , ' utf-8 ' ) )
2013-05-02 17:53:54 +02:00
else :
2013-06-12 23:12:32 +02:00
newItem = QtGui . QTableWidgetItem ( unicode ( toLabel , ' utf-8 ' ) )
newItem . setToolTip ( unicode ( toLabel , ' utf-8 ' ) )
newItem . setData ( Qt . UserRole , str ( toAddress ) )
newItem . setFlags (
QtCore . Qt . ItemIsSelectable | QtCore . Qt . ItemIsEnabled )
self . ui . tableWidgetSent . setItem ( 0 , 0 , newItem )
2013-05-02 17:53:54 +02:00
if fromLabel == ' ' :
2013-06-12 23:12:32 +02:00
newItem = QtGui . QTableWidgetItem (
unicode ( fromAddress , ' utf-8 ' ) )
newItem . setToolTip ( unicode ( fromAddress , ' utf-8 ' ) )
2013-05-02 17:53:54 +02:00
else :
2013-06-12 23:12:32 +02:00
newItem = QtGui . QTableWidgetItem ( unicode ( fromLabel , ' utf-8 ' ) )
newItem . setToolTip ( unicode ( fromLabel , ' utf-8 ' ) )
newItem . setData ( Qt . UserRole , str ( fromAddress ) )
newItem . setFlags (
QtCore . Qt . ItemIsSelectable | QtCore . Qt . ItemIsEnabled )
self . ui . tableWidgetSent . setItem ( 0 , 1 , newItem )
newItem = QtGui . QTableWidgetItem ( unicode ( subject , ' utf-8 ' ) )
newItem . setToolTip ( unicode ( subject , ' utf-8 ' ) )
newItem . setData ( Qt . UserRole , unicode ( message , ' utf-8) ' ) )
newItem . setFlags (
QtCore . Qt . ItemIsSelectable | QtCore . Qt . ItemIsEnabled )
self . ui . tableWidgetSent . setItem ( 0 , 2 , newItem )
2013-05-29 23:18:44 +02:00
if status == ' awaitingpubkey ' :
2013-06-13 09:59:40 +02:00
statusText = _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Waiting on their encryption key. Will request it again soon. " )
2013-05-29 23:18:44 +02:00
elif status == ' doingpowforpubkey ' :
2013-06-13 09:59:40 +02:00
statusText = _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Encryption key request queued. " )
2013-05-29 23:18:44 +02:00
elif status == ' msgqueued ' :
2013-06-13 09:59:40 +02:00
statusText = _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Queued. " )
2013-05-29 23:18:44 +02:00
elif status == ' msgsent ' :
2013-06-13 09:59:40 +02:00
statusText = _translate ( " MainWindow " , " Message sent. Waiting on acknowledgement. Sent at % 1 " ) . arg (
2013-06-18 19:11:30 +02:00
unicode ( strftime ( shared . config . get ( ' bitmessagesettings ' , ' timeformat ' ) , localtime ( lastactiontime ) ) , ' utf-8 ' ) )
2013-05-29 23:18:44 +02:00
elif status == ' doingmsgpow ' :
2013-06-13 09:59:40 +02:00
statusText = _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Need to do work to send message. Work is queued. " )
2013-05-02 17:53:54 +02:00
elif status == ' ackreceived ' :
2013-06-13 09:59:40 +02:00
statusText = _translate ( " MainWindow " , " Acknowledgement of the message received % 1 " ) . arg (
2013-06-18 19:11:30 +02:00
unicode ( strftime ( shared . config . get ( ' bitmessagesettings ' , ' timeformat ' ) , localtime ( lastactiontime ) ) , ' utf-8 ' ) )
2013-05-29 23:18:44 +02:00
elif status == ' broadcastqueued ' :
2013-06-13 09:59:40 +02:00
statusText = _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Broadcast queued. " )
2013-05-02 17:53:54 +02:00
elif status == ' broadcastsent ' :
2013-06-13 09:59:40 +02:00
statusText = _translate ( " MainWindow " , " Broadcast on % 1 " ) . arg ( unicode ( strftime (
2013-06-18 19:11:30 +02:00
shared . config . get ( ' bitmessagesettings ' , ' timeformat ' ) , localtime ( lastactiontime ) ) , ' utf-8 ' ) )
2013-06-10 15:40:51 +02:00
elif status == ' toodifficult ' :
2013-06-13 09:59:40 +02:00
statusText = _translate ( " MainWindow " , " Problem: The work demanded by the recipient is more difficult than you are willing to do. % 1 " ) . arg (
2013-06-18 19:11:30 +02:00
unicode ( strftime ( shared . config . get ( ' bitmessagesettings ' , ' timeformat ' ) , localtime ( lastactiontime ) ) , ' utf-8 ' ) )
2013-06-13 21:15:22 +02:00
elif status == ' badkey ' :
2013-06-17 23:49:06 +02:00
statusText = _translate ( " MainWindow " , " Problem: The recipient \' s encryption key is no good. Could not encrypt message. % 1 " ) . arg (
2013-06-18 19:11:30 +02:00
unicode ( strftime ( shared . config . get ( ' bitmessagesettings ' , ' timeformat ' ) , localtime ( lastactiontime ) ) , ' utf-8 ' ) )
2013-06-11 00:53:15 +02:00
elif status == ' forcepow ' :
2013-06-13 09:59:40 +02:00
statusText = _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Forced difficulty override. Send should start soon. " )
2013-05-02 17:53:54 +02:00
else :
2013-06-13 09:59:40 +02:00
statusText = _translate ( " MainWindow " , " Unknown status: % 1 % 2 " ) . arg ( status ) . arg ( unicode (
2013-06-18 19:11:30 +02:00
strftime ( shared . config . get ( ' bitmessagesettings ' , ' timeformat ' ) , localtime ( lastactiontime ) ) , ' utf-8 ' ) )
2013-06-12 23:12:32 +02:00
newItem = myTableWidgetItem ( statusText )
2013-06-11 00:53:15 +02:00
newItem . setToolTip ( statusText )
2013-06-12 23:12:32 +02:00
newItem . setData ( Qt . UserRole , QByteArray ( ackdata ) )
newItem . setData ( 33 , int ( lastactiontime ) )
newItem . setFlags (
QtCore . Qt . ItemIsSelectable | QtCore . Qt . ItemIsEnabled )
self . ui . tableWidgetSent . setItem ( 0 , 3 , newItem )
self . ui . tableWidgetSent . sortItems ( 3 , Qt . DescendingOrder )
2013-06-11 00:53:15 +02:00
self . ui . tableWidgetSent . keyPressEvent = self . tableWidgetSentKeyPressEvent
2013-05-02 17:53:54 +02:00
2013-06-12 23:12:32 +02:00
# Initialize the address book
2013-05-02 20:18:24 +02:00
shared . sqlLock . acquire ( )
2013-05-02 17:53:54 +02:00
shared . sqlSubmitQueue . put ( ' SELECT * FROM addressbook ' )
shared . sqlSubmitQueue . put ( ' ' )
queryreturn = shared . sqlReturnQueue . get ( )
2013-05-02 20:18:24 +02:00
shared . sqlLock . release ( )
2013-05-02 17:53:54 +02:00
for row in queryreturn :
label , address = row
self . ui . tableWidgetAddressBook . insertRow ( 0 )
2013-06-12 23:12:32 +02:00
newItem = QtGui . QTableWidgetItem ( unicode ( label , ' utf-8 ' ) )
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 )
# Initialize the Subscriptions
2013-05-24 22:12:16 +02:00
self . rerenderSubscriptions ( )
2013-05-02 17:53:54 +02:00
2013-06-12 23:12:32 +02:00
# Initialize the Blacklist or Whitelist
2013-05-02 17:53:54 +02:00
if shared . config . get ( ' bitmessagesettings ' , ' blackwhitelist ' ) == ' black ' :
self . loadBlackWhiteList ( )
else :
2013-06-12 23:12:32 +02:00
self . ui . tabWidget . setTabText ( 6 , ' Whitelist ' )
2013-05-02 17:53:54 +02:00
self . ui . radioButtonWhitelist . click ( )
self . loadBlackWhiteList ( )
2013-06-12 23:12:32 +02:00
QtCore . QObject . connect ( self . ui . tableWidgetYourIdentities , QtCore . SIGNAL (
" itemChanged(QTableWidgetItem *) " ) , self . tableWidgetYourIdentitiesItemChanged )
QtCore . QObject . connect ( self . ui . tableWidgetAddressBook , QtCore . SIGNAL (
" itemChanged(QTableWidgetItem *) " ) , self . tableWidgetAddressBookItemChanged )
QtCore . QObject . connect ( self . ui . tableWidgetSubscriptions , QtCore . SIGNAL (
" itemChanged(QTableWidgetItem *) " ) , self . tableWidgetSubscriptionsItemChanged )
QtCore . QObject . connect ( self . ui . tableWidgetInbox , QtCore . SIGNAL (
" itemSelectionChanged () " ) , self . tableWidgetInboxItemClicked )
QtCore . QObject . connect ( self . ui . tableWidgetSent , QtCore . SIGNAL (
" itemSelectionChanged () " ) , self . tableWidgetSentItemClicked )
# Put the colored icon on the status bar
# self.ui.pushButtonStatusIcon.setIcon(QIcon(":/newPrefix/images/yellowicon.png"))
2013-05-02 17:53:54 +02:00
self . statusbar = self . statusBar ( )
2013-06-12 23:12:32 +02:00
self . statusbar . insertPermanentWidget ( 0 , self . ui . pushButtonStatusIcon )
2013-06-13 09:59:40 +02:00
self . ui . labelStartupTime . setText ( _translate ( " MainWindow " , " Since startup on % 1 " ) . arg (
2013-06-18 19:11:30 +02:00
unicode ( strftime ( shared . config . get ( ' bitmessagesettings ' , ' timeformat ' ) , localtime ( int ( time . time ( ) ) ) ) , ' utf-8 ' ) ) )
2013-05-02 17:53:54 +02:00
self . numberOfMessagesProcessed = 0
self . numberOfBroadcastsProcessed = 0
self . numberOfPubkeysProcessed = 0
self . UISignalThread = UISignaler ( )
2013-06-12 23:12:32 +02:00
QtCore . QObject . connect ( self . UISignalThread , QtCore . SIGNAL (
" writeNewAddressToTable(PyQt_PyObject,PyQt_PyObject,PyQt_PyObject) " ) , self . writeNewAddressToTable )
QtCore . QObject . connect ( self . UISignalThread , QtCore . SIGNAL (
" updateStatusBar(PyQt_PyObject) " ) , self . updateStatusBar )
QtCore . QObject . connect ( self . UISignalThread , QtCore . SIGNAL (
" updateSentItemStatusByHash(PyQt_PyObject,PyQt_PyObject) " ) , self . updateSentItemStatusByHash )
QtCore . QObject . connect ( self . UISignalThread , QtCore . SIGNAL (
" updateSentItemStatusByAckdata(PyQt_PyObject,PyQt_PyObject) " ) , self . updateSentItemStatusByAckdata )
QtCore . QObject . connect ( self . UISignalThread , QtCore . SIGNAL (
" displayNewInboxMessage(PyQt_PyObject,PyQt_PyObject,PyQt_PyObject,PyQt_PyObject,PyQt_PyObject) " ) , self . displayNewInboxMessage )
QtCore . QObject . connect ( self . UISignalThread , QtCore . SIGNAL (
" displayNewSentMessage(PyQt_PyObject,PyQt_PyObject,PyQt_PyObject,PyQt_PyObject,PyQt_PyObject,PyQt_PyObject) " ) , self . displayNewSentMessage )
QtCore . QObject . connect ( self . UISignalThread , QtCore . SIGNAL (
" updateNetworkStatusTab() " ) , self . updateNetworkStatusTab )
QtCore . QObject . connect ( self . UISignalThread , QtCore . SIGNAL (
" incrementNumberOfMessagesProcessed() " ) , self . incrementNumberOfMessagesProcessed )
QtCore . QObject . connect ( self . UISignalThread , QtCore . SIGNAL (
" incrementNumberOfPubkeysProcessed() " ) , self . incrementNumberOfPubkeysProcessed )
QtCore . QObject . connect ( self . UISignalThread , QtCore . SIGNAL (
" incrementNumberOfBroadcastsProcessed() " ) , self . incrementNumberOfBroadcastsProcessed )
QtCore . QObject . connect ( self . UISignalThread , QtCore . SIGNAL (
" setStatusIcon(PyQt_PyObject) " ) , self . setStatusIcon )
QtCore . QObject . connect ( self . UISignalThread , QtCore . SIGNAL (
" rerenderInboxFromLabels() " ) , self . rerenderInboxFromLabels )
QtCore . QObject . connect ( self . UISignalThread , QtCore . SIGNAL (
" rerenderSubscriptions() " ) , self . rerenderSubscriptions )
QtCore . QObject . connect ( self . UISignalThread , QtCore . SIGNAL (
" removeInboxRowByMsgid(PyQt_PyObject) " ) , self . removeInboxRowByMsgid )
2013-05-02 17:53:54 +02:00
self . UISignalThread . start ( )
2013-06-12 23:12:32 +02:00
# Below this point, it would be good if all of the necessary global data
# structures were initialized.
2013-05-02 17:53:54 +02:00
2013-05-08 22:42:28 +02:00
self . rerenderComboBoxSendFrom ( )
2013-05-02 17:53:54 +02:00
2013-06-12 23:12:32 +02:00
# Show or hide the application window after clicking an item within the
# tray icon or, on Windows, the try icon itself.
2013-05-08 22:42:28 +02:00
def appIndicatorShowOrHideWindow ( self ) :
if not self . actionShow . isChecked ( ) :
self . hide ( )
else :
if sys . platform [ 0 : 3 ] == ' win ' :
self . setWindowFlags ( Qt . Window )
2013-06-12 23:12:32 +02:00
# else:
# self.showMaximized()
2013-05-25 19:59:00 +02:00
self . show ( )
2013-06-12 23:12:32 +02:00
self . setWindowState (
self . windowState ( ) & ~ QtCore . Qt . WindowMinimized | QtCore . Qt . WindowActive )
2013-05-15 18:36:30 +02:00
self . activateWindow ( )
2013-05-07 23:22:34 +02:00
2013-05-10 00:57:46 +02:00
# pointer to the application
2013-06-12 23:12:32 +02:00
# app = None
2013-05-14 17:06:01 +02:00
# The most recent message
newMessageItem = None
# The most recent broadcast
newBroadcastItem = None
2013-05-07 23:22:34 +02:00
# show the application window
def appIndicatorShow ( self ) :
2013-06-12 23:12:32 +02:00
if self . actionShow is None :
2013-05-07 23:22:34 +02:00
return
2013-05-14 17:44:51 +02:00
if not self . actionShow . isChecked ( ) :
self . actionShow . setChecked ( True )
self . appIndicatorShowOrHideWindow ( )
2013-05-07 23:22:34 +02:00
2013-05-13 13:20:29 +02:00
# unchecks the show item on the application indicator
def appIndicatorHide ( self ) :
2013-06-12 23:12:32 +02:00
if self . actionShow is None :
2013-05-13 13:20:29 +02:00
return
2013-05-14 17:44:51 +02:00
if self . actionShow . isChecked ( ) :
self . actionShow . setChecked ( False )
self . appIndicatorShowOrHideWindow ( )
2013-05-13 13:20:29 +02:00
2013-05-07 23:22:34 +02:00
# application indicator show or hide
2013-05-08 22:42:28 +02:00
""" # application indicator show or hide
2013-05-07 23:22:34 +02:00
def appIndicatorShowBitmessage ( self ) :
2013-05-08 22:42:28 +02:00
#if self.actionShow == None:
# return
print self . actionShow . isChecked ( )
2013-05-07 23:22:34 +02:00
if not self . actionShow . isChecked ( ) :
self . hide ( )
2013-05-08 22:42:28 +02:00
#self.setWindowState(self.windowState() & QtCore.Qt.WindowMinimized)
2013-05-07 23:22:34 +02:00
else :
2013-05-08 22:42:28 +02:00
self . appIndicatorShowOrHideWindow ( ) """
2013-05-07 23:22:34 +02:00
2013-05-10 21:47:01 +02:00
# Show the program window and select inbox tab
2013-05-11 19:30:49 +02:00
def appIndicatorInbox ( self , mm_app , source_id ) :
2013-05-10 21:47:01 +02:00
self . appIndicatorShow ( )
2013-05-13 23:34:08 +02:00
# select inbox
2013-05-10 21:47:01 +02:00
self . ui . tabWidget . setCurrentIndex ( 0 )
2013-05-14 17:06:01 +02:00
selectedItem = None
if source_id == ' Subscriptions ' :
# select unread broadcast
if self . newBroadcastItem is not None :
selectedItem = self . newBroadcastItem
self . newBroadcastItem = None
else :
# select unread message
if self . newMessageItem is not None :
selectedItem = self . newMessageItem
self . newMessageItem = None
# make it the current item
if selectedItem is not None :
try :
self . ui . tableWidgetInbox . setCurrentItem ( selectedItem )
except Exception :
2013-06-12 23:12:32 +02:00
self . ui . tableWidgetInbox . setCurrentCell ( 0 , 0 )
2013-05-14 17:06:01 +02:00
self . tableWidgetInboxItemClicked ( )
else :
# just select the first item
2013-06-12 23:12:32 +02:00
self . ui . tableWidgetInbox . setCurrentCell ( 0 , 0 )
2013-05-14 17:06:01 +02:00
self . tableWidgetInboxItemClicked ( )
2013-05-10 21:47:01 +02:00
2013-05-07 23:52:17 +02:00
# Show the program window and select send tab
2013-05-07 23:22:34 +02:00
def appIndicatorSend ( self ) :
self . appIndicatorShow ( )
2013-05-07 23:52:17 +02:00
self . ui . tabWidget . setCurrentIndex ( 1 )
2013-05-07 23:22:34 +02:00
2013-05-07 23:52:17 +02:00
# Show the program window and select subscriptions tab
2013-05-07 23:22:34 +02:00
def appIndicatorSubscribe ( self ) :
self . appIndicatorShow ( )
2013-05-07 23:52:17 +02:00
self . ui . tabWidget . setCurrentIndex ( 4 )
2013-05-07 23:22:34 +02:00
2013-05-07 23:52:17 +02:00
# Show the program window and select the address book tab
2013-05-07 23:22:34 +02:00
def appIndicatorAddressBook ( self ) :
self . appIndicatorShow ( )
2013-05-07 23:52:17 +02:00
self . ui . tabWidget . setCurrentIndex ( 5 )
2013-05-07 23:22:34 +02:00
# create application indicator
2013-06-12 23:12:32 +02:00
def appIndicatorInit ( self , app ) :
self . tray = QSystemTrayIcon ( QtGui . QIcon (
" :/newPrefix/images/can-icon-24px-red.png " ) , app )
2013-05-08 22:42:28 +02:00
if sys . platform [ 0 : 3 ] == ' win ' :
traySignal = " activated(QSystemTrayIcon::ActivationReason) "
2013-06-12 23:12:32 +02:00
QtCore . QObject . connect ( self . tray , QtCore . SIGNAL (
traySignal ) , self . __icon_activated )
2013-05-14 17:44:51 +02:00
2013-05-07 23:22:34 +02:00
m = QMenu ( )
2013-06-13 09:59:40 +02:00
self . actionStatus = QtGui . QAction ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Not Connected " ) , m , checkable = False )
2013-05-07 23:22:34 +02:00
m . addAction ( self . actionStatus )
2013-05-07 23:58:47 +02:00
# separator
2013-06-12 23:12:32 +02:00
actionSeparator = QtGui . QAction ( ' ' , m , checkable = False )
2013-05-07 23:58:47 +02:00
actionSeparator . setSeparator ( True )
m . addAction ( actionSeparator )
2013-05-07 23:22:34 +02:00
# show bitmessage
2013-06-13 09:59:40 +02:00
self . actionShow = QtGui . QAction ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Show Bitmessage " ) , m , checkable = True )
self . actionShow . setChecked ( not shared . config . getboolean (
' bitmessagesettings ' , ' startintray ' ) )
2013-05-08 22:42:28 +02:00
self . actionShow . triggered . connect ( self . appIndicatorShowOrHideWindow )
if not sys . platform [ 0 : 3 ] == ' win ' :
2013-06-12 23:12:32 +02:00
m . addAction ( self . actionShow )
2013-05-07 23:22:34 +02:00
# Send
2013-06-13 09:59:40 +02:00
actionSend = QtGui . QAction ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Send " ) , m , checkable = False )
2013-05-07 23:22:34 +02:00
actionSend . triggered . connect ( self . appIndicatorSend )
m . addAction ( actionSend )
# Subscribe
2013-06-13 09:59:40 +02:00
actionSubscribe = QtGui . QAction ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Subscribe " ) , m , checkable = False )
2013-05-07 23:22:34 +02:00
actionSubscribe . triggered . connect ( self . appIndicatorSubscribe )
m . addAction ( actionSubscribe )
# Address book
2013-06-13 09:59:40 +02:00
actionAddressBook = QtGui . QAction ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Address Book " ) , m , checkable = False )
2013-05-07 23:22:34 +02:00
actionAddressBook . triggered . connect ( self . appIndicatorAddressBook )
m . addAction ( actionAddressBook )
2013-05-07 23:58:47 +02:00
# separator
2013-06-12 23:12:32 +02:00
actionSeparator = QtGui . QAction ( ' ' , m , checkable = False )
2013-05-07 23:58:47 +02:00
actionSeparator . setSeparator ( True )
m . addAction ( actionSeparator )
# Quit
2013-06-13 09:59:40 +02:00
m . addAction ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Quit " ) , self . quit )
2013-05-14 17:44:51 +02:00
2013-05-08 22:42:28 +02:00
self . tray . setContextMenu ( m )
self . tray . show ( )
2013-05-07 23:22:34 +02:00
2013-05-10 21:47:01 +02:00
# Ubuntu Messaging menu object
mmapp = None
# is the operating system Ubuntu?
def isUbuntu ( self ) :
2013-05-14 17:44:51 +02:00
for entry in platform . uname ( ) :
2013-05-12 00:16:04 +02:00
if " Ubuntu " in entry :
return True
2013-05-10 21:47:01 +02:00
return False
2013-05-14 17:06:01 +02:00
# When an unread inbox row is selected on then clear the messaging menu
def ubuntuMessagingMenuClear ( self , inventoryHash ) :
global withMessagingMenu
# if this isn't ubuntu then don't do anything
if not self . isUbuntu ( ) :
return
# has messageing menu been installed
if not withMessagingMenu :
return
2013-05-14 18:32:10 +02:00
# if there are no items on the messaging menu then
# the subsequent query can be avoided
if not ( self . mmapp . has_source ( " Subscriptions " ) or self . mmapp . has_source ( " Messages " ) ) :
return
2013-05-14 17:06:01 +02:00
shared . sqlLock . acquire ( )
2013-06-12 23:12:32 +02:00
shared . sqlSubmitQueue . put (
''' SELECT toaddress, read FROM inbox WHERE msgid=? ''' )
2013-05-14 17:06:01 +02:00
shared . sqlSubmitQueue . put ( inventoryHash )
queryreturn = shared . sqlReturnQueue . get ( )
shared . sqlLock . release ( )
for row in queryreturn :
toAddress , read = row
if not read :
if toAddress == self . str_broadcast_subscribers :
if self . mmapp . has_source ( " Subscriptions " ) :
self . mmapp . remove_source ( " Subscriptions " )
else :
if self . mmapp . has_source ( " Messages " ) :
self . mmapp . remove_source ( " Messages " )
2013-05-10 21:47:01 +02:00
# returns the number of unread messages and subscriptions
def getUnread ( self ) :
unreadMessages = 0
unreadSubscriptions = 0
shared . sqlLock . acquire ( )
2013-06-12 23:12:32 +02:00
shared . sqlSubmitQueue . put (
''' SELECT msgid, toaddress, read FROM inbox where folder= ' inbox ' ''' )
2013-05-10 21:47:01 +02:00
shared . sqlSubmitQueue . put ( ' ' )
queryreturn = shared . sqlReturnQueue . get ( )
shared . sqlLock . release ( )
for row in queryreturn :
msgid , toAddress , read = row
try :
2013-05-14 17:06:01 +02:00
if toAddress == self . str_broadcast_subscribers :
toLabel = self . str_broadcast_subscribers
2013-05-10 21:47:01 +02:00
else :
toLabel = shared . config . get ( toAddress , ' label ' )
except :
toLabel = ' '
if toLabel == ' ' :
toLabel = toAddress
if not read :
2013-05-14 17:06:01 +02:00
if toLabel == self . str_broadcast_subscribers :
2013-05-10 21:47:01 +02:00
# increment the unread subscriptions
unreadSubscriptions = unreadSubscriptions + 1
else :
# increment the unread messages
unreadMessages = unreadMessages + 1
return unreadMessages , unreadSubscriptions
2013-06-12 23:12:32 +02:00
# show the number of unread messages and subscriptions on the messaging
# menu
2013-05-10 21:47:01 +02:00
def ubuntuMessagingMenuUnread ( self , drawAttention ) :
unreadMessages , unreadSubscriptions = self . getUnread ( )
# unread messages
if unreadMessages > 0 :
2013-06-12 23:12:32 +02:00
self . mmapp . append_source (
" Messages " , None , " Messages ( " + str ( unreadMessages ) + " ) " )
2013-05-10 21:47:01 +02:00
if drawAttention :
self . mmapp . draw_attention ( " Messages " )
# unread subscriptions
if unreadSubscriptions > 0 :
2013-06-12 23:12:32 +02:00
self . mmapp . append_source ( " Subscriptions " , None , " Subscriptions ( " + str (
unreadSubscriptions ) + " ) " )
2013-05-10 21:47:01 +02:00
if drawAttention :
self . mmapp . draw_attention ( " Subscriptions " )
2013-06-12 23:12:32 +02:00
2013-05-10 21:47:01 +02:00
# initialise the Ubuntu messaging menu
def ubuntuMessagingMenuInit ( self ) :
2013-05-11 18:33:16 +02:00
global withMessagingMenu
2013-05-10 21:47:01 +02:00
# if this isn't ubuntu then don't do anything
if not self . isUbuntu ( ) :
return
# has messageing menu been installed
2013-05-11 18:33:16 +02:00
if not withMessagingMenu :
2013-06-12 23:12:32 +02:00
print ' WARNING: MessagingMenu is not available. Is libmessaging-menu-dev installed? '
2013-05-10 21:47:01 +02:00
return
# create the menu server
2013-05-11 18:33:16 +02:00
if withMessagingMenu :
try :
2013-06-12 23:12:32 +02:00
self . mmapp = MessagingMenu . App (
desktop_id = ' pybitmessage.desktop ' )
2013-05-11 18:33:16 +02:00
self . mmapp . register ( )
self . mmapp . connect ( ' activate-source ' , self . appIndicatorInbox )
self . ubuntuMessagingMenuUnread ( True )
except Exception :
withMessagingMenu = False
print ' WARNING: messaging menu disabled '
2013-05-10 21:47:01 +02:00
# update the Ubuntu messaging menu
2013-05-14 17:06:01 +02:00
def ubuntuMessagingMenuUpdate ( self , drawAttention , newItem , toLabel ) :
2013-05-11 18:33:16 +02:00
global withMessagingMenu
2013-05-10 21:47:01 +02:00
# if this isn't ubuntu then don't do anything
if not self . isUbuntu ( ) :
return
# has messageing menu been installed
2013-05-11 18:33:16 +02:00
if not withMessagingMenu :
2013-06-12 23:12:32 +02:00
print ' WARNING: messaging menu disabled or libmessaging-menu-dev not installed '
2013-05-10 21:47:01 +02:00
return
2013-05-14 17:06:01 +02:00
# remember this item to that the messaging menu can find it
if toLabel == self . str_broadcast_subscribers :
self . newBroadcastItem = newItem
else :
self . newMessageItem = newItem
2013-05-10 21:47:01 +02:00
# Remove previous messages and subscriptions entries, then recreate them
# There might be a better way to do it than this
if self . mmapp . has_source ( " Messages " ) :
self . mmapp . remove_source ( " Messages " )
if self . mmapp . has_source ( " Subscriptions " ) :
self . mmapp . remove_source ( " Subscriptions " )
# update the menu entries
self . ubuntuMessagingMenuUnread ( drawAttention )
2013-05-11 18:33:16 +02:00
# initialise the message notifier
def notifierInit ( self ) :
global withMessagingMenu
if withMessagingMenu :
Notify . init ( ' pybitmessage ' )
# shows a notification
def notifierShow ( self , title , subtitle ) :
global withMessagingMenu
if withMessagingMenu :
2013-06-12 23:12:32 +02:00
n = Notify . Notification . new (
title , subtitle , ' notification-message-email ' )
2013-05-11 18:33:16 +02:00
n . show ( )
return
2013-05-14 19:06:29 +02:00
else :
self . tray . showMessage ( title , subtitle , 1 , 2000 )
2013-05-11 18:33:16 +02:00
2013-06-12 23:12:32 +02:00
def tableWidgetInboxKeyPressEvent ( self , event ) :
2013-05-02 17:53:54 +02:00
if event . key ( ) == QtCore . Qt . Key_Delete :
self . on_action_InboxTrash ( )
return QtGui . QTableWidget . keyPressEvent ( self . ui . tableWidgetInbox , event )
2013-06-12 23:12:32 +02:00
def tableWidgetSentKeyPressEvent ( self , event ) :
2013-05-02 17:53:54 +02:00
if event . key ( ) == QtCore . Qt . Key_Delete :
self . on_action_SentTrash ( )
return QtGui . QTableWidget . keyPressEvent ( self . ui . tableWidgetSent , event )
def click_actionManageKeys ( self ) :
if ' darwin ' in sys . platform or ' linux ' in sys . platform :
if shared . appdata == ' ' :
2013-06-12 23:12:32 +02:00
# reply = QtGui.QMessageBox.information(self, 'keys.dat?','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)
2013-06-13 09:59:40 +02:00
reply = QtGui . QMessageBox . information ( self , ' keys.dat? ' , _translate (
2013-06-12 23:12:32 +02:00
" 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 )
2013-06-12 14:22:04 +02:00
2013-05-02 17:53:54 +02:00
else :
2013-06-13 09:59:40 +02:00
QtGui . QMessageBox . information ( self , ' keys.dat? ' , _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " You may manage your keys by editing the keys.dat file stored in \n % 1 \n It is important that you back up this file. " ) . arg ( shared . appdata ) , QMessageBox . Ok )
2013-05-02 17:53:54 +02:00
elif sys . platform == ' win32 ' or sys . platform == ' win64 ' :
if shared . appdata == ' ' :
2013-06-13 09:59:40 +02:00
reply = QtGui . QMessageBox . question ( self , _translate ( " MainWindow " , " Open keys.dat? " ) , _translate (
2013-06-12 23:12:32 +02:00
" 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. Would you like to open the file now? (Be sure to close Bitmessage before making any changes.) " ) , QtGui . QMessageBox . Yes , QtGui . QMessageBox . No )
2013-05-02 17:53:54 +02:00
else :
2013-06-13 09:59:40 +02:00
reply = QtGui . QMessageBox . question ( self , _translate ( " MainWindow " , " Open keys.dat? " ) , _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " You may manage your keys by editing the keys.dat file stored in \n % 1 \n It is important that you back up this file. Would you like to open the file now? (Be sure to close Bitmessage before making any changes.) " ) . arg ( shared . appdata ) , QtGui . QMessageBox . Yes , QtGui . QMessageBox . No )
2013-05-02 17:53:54 +02:00
if reply == QtGui . QMessageBox . Yes :
self . openKeysFile ( )
2013-05-28 22:50:09 +02:00
def click_actionDeleteAllTrashedMessages ( self ) :
2013-06-13 09:59:40 +02:00
if QtGui . QMessageBox . question ( self , _translate ( " MainWindow " , " Delete trash? " ) , _translate ( " MainWindow " , " Are you sure you want to delete all trashed messages? " ) , QtGui . QMessageBox . Yes , QtGui . QMessageBox . No ) == QtGui . QMessageBox . No :
2013-05-28 22:50:09 +02:00
return
shared . sqlLock . acquire ( )
2013-06-11 00:53:15 +02:00
shared . sqlSubmitQueue . put ( ' deleteandvacuume ' )
2013-05-28 22:50:09 +02:00
shared . sqlLock . release ( )
2013-05-02 17:53:54 +02:00
def click_actionRegenerateDeterministicAddresses ( self ) :
2013-06-12 23:12:32 +02:00
self . regenerateAddressesDialogInstance = regenerateAddressesDialog (
self )
2013-05-02 17:53:54 +02:00
if self . regenerateAddressesDialogInstance . exec_ ( ) :
if self . regenerateAddressesDialogInstance . ui . lineEditPassphrase . text ( ) == " " :
2013-06-13 09:59:40 +02:00
QMessageBox . about ( self , _translate ( " MainWindow " , " bad passphrase " ) , _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " You must type your passphrase. If you don \' t have one then this is not the form for you. " ) )
2013-05-02 17:53:54 +02:00
else :
2013-06-12 23:12:32 +02:00
streamNumberForAddress = int (
self . regenerateAddressesDialogInstance . ui . lineEditStreamNumber . text ( ) )
addressVersionNumber = int (
self . regenerateAddressesDialogInstance . ui . lineEditAddressVersionNumber . text ( ) )
# self.addressGenerator = addressGenerator()
# self.addressGenerator.setup(addressVersionNumber,streamNumberForAddress,"unused address",self.regenerateAddressesDialogInstance.ui.spinBoxNumberOfAddressesToMake.value(),self.regenerateAddressesDialogInstance.ui.lineEditPassphrase.text().toUtf8(),self.regenerateAddressesDialogInstance.ui.checkBoxEighteenByteRipe.isChecked())
# QtCore.QObject.connect(self.addressGenerator, SIGNAL("writeNewAddressToTable(PyQt_PyObject,PyQt_PyObject,PyQt_PyObject)"), self.writeNewAddressToTable)
# QtCore.QObject.connect(self.addressGenerator, QtCore.SIGNAL("updateStatusBar(PyQt_PyObject)"), self.updateStatusBar)
# self.addressGenerator.start()
shared . addressGeneratorQueue . put ( ( ' createDeterministicAddresses ' , addressVersionNumber , streamNumberForAddress , " regenerated deterministic address " , self . regenerateAddressesDialogInstance . ui . spinBoxNumberOfAddressesToMake . value (
) , self . regenerateAddressesDialogInstance . ui . lineEditPassphrase . text ( ) . toUtf8 ( ) , self . regenerateAddressesDialogInstance . ui . checkBoxEighteenByteRipe . isChecked ( ) ) )
2013-05-02 17:53:54 +02:00
self . ui . tabWidget . setCurrentIndex ( 3 )
def openKeysFile ( self ) :
if ' linux ' in sys . platform :
subprocess . call ( [ " xdg-open " , shared . appdata + ' keys.dat ' ] )
else :
os . startfile ( shared . appdata + ' keys.dat ' )
def changeEvent ( self , event ) :
2013-05-08 22:42:28 +02:00
if event . type ( ) == QtCore . QEvent . WindowStateChange :
if self . windowState ( ) & QtCore . Qt . WindowMinimized :
self . actionShow . setChecked ( False )
2013-05-02 17:53:54 +02:00
if shared . config . getboolean ( ' bitmessagesettings ' , ' minimizetotray ' ) and not ' darwin ' in sys . platform :
if event . type ( ) == QtCore . QEvent . WindowStateChange :
if self . windowState ( ) & QtCore . Qt . WindowMinimized :
2013-05-13 13:20:29 +02:00
self . appIndicatorHide ( )
2013-05-02 17:53:54 +02:00
if ' win32 ' in sys . platform or ' win64 ' in sys . platform :
self . setWindowFlags ( Qt . ToolTip )
elif event . oldState ( ) & QtCore . Qt . WindowMinimized :
2013-06-12 23:12:32 +02:00
# The window state has just been changed to
# Normal/Maximised/FullScreen
2013-05-02 17:53:54 +02:00
pass
2013-06-12 23:12:32 +02:00
# QtGui.QWidget.changeEvent(self, event)
2013-05-02 17:53:54 +02:00
def __icon_activated ( self , reason ) :
if reason == QtGui . QSystemTrayIcon . Trigger :
2013-05-08 22:42:28 +02:00
self . actionShow . setChecked ( not self . actionShow . isChecked ( ) )
self . appIndicatorShowOrHideWindow ( )
2013-05-02 17:53:54 +02:00
def incrementNumberOfMessagesProcessed ( self ) :
self . numberOfMessagesProcessed + = 1
2013-06-13 09:59:40 +02:00
self . ui . labelMessageCount . setText ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Processed % 1 person-to-person messages. " ) . arg ( str ( self . numberOfMessagesProcessed ) ) )
2013-05-02 17:53:54 +02:00
def incrementNumberOfBroadcastsProcessed ( self ) :
self . numberOfBroadcastsProcessed + = 1
2013-06-13 09:59:40 +02:00
self . ui . labelBroadcastCount . setText ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Processed % 1 broadcast messages. " ) . arg ( str ( self . numberOfBroadcastsProcessed ) ) )
2013-05-02 17:53:54 +02:00
def incrementNumberOfPubkeysProcessed ( self ) :
self . numberOfPubkeysProcessed + = 1
2013-06-13 09:59:40 +02:00
self . ui . labelPubkeyCount . setText ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Processed % 1 public keys. " ) . arg ( str ( self . numberOfPubkeysProcessed ) ) )
2013-05-02 17:53:54 +02:00
2013-05-03 18:05:57 +02:00
def updateNetworkStatusTab ( self ) :
2013-06-12 23:12:32 +02:00
# print 'updating network status tab'
totalNumberOfConnectionsFromAllStreams = 0 # One would think we could use len(sendDataQueues) for this but the number doesn't always match: just because we have a sendDataThread running doesn't mean that the connection has been fully established (with the exchange of version messages).
2013-05-03 18:05:57 +02:00
streamNumberTotals = { }
for host , streamNumber in shared . connectedHostsList . items ( ) :
if not streamNumber in streamNumberTotals :
streamNumberTotals [ streamNumber ] = 1
else :
streamNumberTotals [ streamNumber ] + = 1
while self . ui . tableWidgetConnectionCount . rowCount ( ) > 0 :
self . ui . tableWidgetConnectionCount . removeRow ( 0 )
for streamNumber , connectionCount in streamNumberTotals . items ( ) :
self . ui . tableWidgetConnectionCount . insertRow ( 0 )
2013-05-03 18:24:47 +02:00
if streamNumber == 0 :
2013-06-12 23:12:32 +02:00
newItem = QtGui . QTableWidgetItem ( " ? " )
2013-05-03 18:24:47 +02:00
else :
2013-06-12 23:12:32 +02:00
newItem = QtGui . QTableWidgetItem ( str ( streamNumber ) )
newItem . setFlags (
QtCore . Qt . ItemIsSelectable | QtCore . Qt . ItemIsEnabled )
self . ui . tableWidgetConnectionCount . setItem ( 0 , 0 , newItem )
newItem = QtGui . QTableWidgetItem ( str ( connectionCount ) )
newItem . setFlags (
QtCore . Qt . ItemIsSelectable | QtCore . Qt . ItemIsEnabled )
self . ui . tableWidgetConnectionCount . setItem ( 0 , 1 , newItem )
2013-05-03 18:05:57 +02:00
""" for currentRow in range(self.ui.tableWidgetConnectionCount.rowCount()):
2013-05-02 17:53:54 +02:00
rowStreamNumber = int ( self . ui . tableWidgetConnectionCount . item ( currentRow , 0 ) . text ( ) )
if streamNumber == rowStreamNumber :
foundTheRowThatNeedsUpdating = True
self . ui . tableWidgetConnectionCount . item ( currentRow , 1 ) . setText ( str ( connectionCount ) )
2013-05-03 18:05:57 +02:00
#totalNumberOfConnectionsFromAllStreams += connectionCount
2013-05-02 17:53:54 +02:00
if foundTheRowThatNeedsUpdating == False :
#Add a line to the table for this stream number and update its count with the current connection count.
self . ui . tableWidgetConnectionCount . insertRow ( 0 )
newItem = QtGui . QTableWidgetItem ( str ( streamNumber ) )
newItem . setFlags ( QtCore . Qt . ItemIsSelectable | QtCore . Qt . ItemIsEnabled )
self . ui . tableWidgetConnectionCount . setItem ( 0 , 0 , newItem )
newItem = QtGui . QTableWidgetItem ( str ( connectionCount ) )
newItem . setFlags ( QtCore . Qt . ItemIsSelectable | QtCore . Qt . ItemIsEnabled )
self . ui . tableWidgetConnectionCount . setItem ( 0 , 1 , newItem )
2013-05-03 18:05:57 +02:00
totalNumberOfConnectionsFromAllStreams + = connectionCount """
2013-06-13 09:59:40 +02:00
self . ui . labelTotalConnections . setText ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Total Connections: % 1 " ) . arg ( str ( len ( shared . connectedHostsList ) ) ) )
if len ( shared . connectedHostsList ) > 0 and shared . statusIconColor == ' red ' : # FYI: The 'singlelistener' thread sets the icon color to green when it receives an incoming connection, meaning that the user's firewall is configured correctly.
2013-05-02 17:53:54 +02:00
self . setStatusIcon ( ' yellow ' )
2013-05-03 18:05:57 +02:00
elif len ( shared . connectedHostsList ) == 0 :
2013-05-02 17:53:54 +02:00
self . setStatusIcon ( ' red ' )
2013-05-11 18:46:21 +02:00
# Indicates whether or not there is a connection to the Bitmessage network
connected = False
2013-06-12 23:12:32 +02:00
def setStatusIcon ( self , color ) :
2013-05-11 18:46:21 +02:00
global withMessagingMenu
2013-06-12 23:12:32 +02:00
# print 'setting status icon color'
2013-05-02 17:53:54 +02:00
if color == ' red ' :
2013-06-12 23:12:32 +02:00
self . ui . pushButtonStatusIcon . setIcon (
QIcon ( " :/newPrefix/images/redicon.png " ) )
2013-05-02 17:53:54 +02:00
shared . statusIconColor = ' red '
2013-05-11 18:46:21 +02:00
# if the connection is lost then show a notification
if self . connected :
2013-06-20 22:41:14 +02:00
self . notifierShow ( ' Bitmessage ' , unicode ( _translate (
" MainWindow " , " Connection lost " ) . toUtf8 ( ) , ' utf-8 ' ) )
2013-05-11 18:46:21 +02:00
self . connected = False
2013-06-12 23:12:32 +02:00
if self . actionStatus is not None :
2013-06-13 09:59:40 +02:00
self . actionStatus . setText ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Not Connected " ) )
self . tray . setIcon ( QtGui . QIcon (
" :/newPrefix/images/can-icon-24px-red.png " ) )
2013-05-02 17:53:54 +02:00
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. ' :
self . statusBar ( ) . showMessage ( ' ' )
2013-06-12 23:12:32 +02:00
self . ui . pushButtonStatusIcon . setIcon ( QIcon (
" :/newPrefix/images/yellowicon.png " ) )
2013-05-02 17:53:54 +02:00
shared . statusIconColor = ' yellow '
2013-05-11 18:46:21 +02:00
# if a new connection has been established then show a notification
if not self . connected :
2013-06-20 13:51:02 +02:00
self . notifierShow ( ' Bitmessage ' , unicode ( _translate (
" MainWindow " , " Connected " ) . toUtf8 ( ) , ' utf-8 ' ) )
2013-05-11 18:46:21 +02:00
self . connected = True
2013-06-12 23:12:32 +02:00
if self . actionStatus is not None :
2013-06-13 09:59:40 +02:00
self . actionStatus . setText ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Connected " ) )
self . tray . setIcon ( QtGui . QIcon (
" :/newPrefix/images/can-icon-24px-yellow.png " ) )
2013-05-02 17:53:54 +02:00
if color == ' green ' :
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 ( ) . showMessage ( ' ' )
2013-06-12 23:12:32 +02:00
self . ui . pushButtonStatusIcon . setIcon (
QIcon ( " :/newPrefix/images/greenicon.png " ) )
2013-05-02 17:53:54 +02:00
shared . statusIconColor = ' green '
2013-05-14 18:02:56 +02:00
if not self . connected :
2013-06-20 22:41:14 +02:00
self . notifierShow ( ' Bitmessage ' , unicode ( _translate (
" MainWindow " , " Connected " ) . toUtf8 ( ) , ' utf-8 ' ) )
2013-05-11 18:46:21 +02:00
self . connected = True
2013-06-12 23:12:32 +02:00
if self . actionStatus is not None :
2013-06-13 09:59:40 +02:00
self . actionStatus . setText ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Connected " ) )
self . tray . setIcon ( QtGui . QIcon (
" :/newPrefix/images/can-icon-24px-green.png " ) )
2013-05-02 17:53:54 +02:00
2013-06-12 23:12:32 +02:00
def updateSentItemStatusByHash ( self , toRipe , textToDisplay ) :
2013-05-02 17:53:54 +02:00
for i in range ( self . ui . tableWidgetSent . rowCount ( ) ) :
2013-06-12 23:12:32 +02:00
toAddress = str ( self . ui . tableWidgetSent . item (
i , 0 ) . data ( Qt . UserRole ) . toPyObject ( ) )
status , addressVersionNumber , streamNumber , ripe = decodeAddress (
toAddress )
2013-05-02 17:53:54 +02:00
if ripe == toRipe :
2013-06-12 23:12:32 +02:00
self . ui . tableWidgetSent . item ( i , 3 ) . setToolTip ( textToDisplay )
2013-06-18 17:30:42 +02:00
try :
newlinePosition = textToDisplay . indexOf ( ' \n ' )
except : # If someone misses adding a "_translate" to a string before passing it to this function, this function won't receive a qstring which will cause an exception.
newlinePosition = 0
2013-06-17 22:42:30 +02:00
if newlinePosition > 1 :
2013-06-12 23:12:32 +02:00
self . ui . tableWidgetSent . item ( i , 3 ) . setText (
2013-06-17 22:42:30 +02:00
textToDisplay [ : newlinePosition ] )
2013-06-11 20:15:17 +02:00
else :
2013-06-12 23:12:32 +02:00
self . ui . tableWidgetSent . item ( i , 3 ) . setText ( textToDisplay )
2013-05-02 17:53:54 +02:00
2013-06-12 23:12:32 +02:00
def updateSentItemStatusByAckdata ( self , ackdata , textToDisplay ) :
2013-05-02 17:53:54 +02:00
for i in range ( self . ui . tableWidgetSent . rowCount ( ) ) :
2013-06-12 23:12:32 +02:00
toAddress = str ( self . ui . tableWidgetSent . item (
i , 0 ) . data ( Qt . UserRole ) . toPyObject ( ) )
tableAckdata = self . ui . tableWidgetSent . item (
i , 3 ) . data ( Qt . UserRole ) . toPyObject ( )
status , addressVersionNumber , streamNumber , ripe = decodeAddress (
toAddress )
2013-05-02 17:53:54 +02:00
if ackdata == tableAckdata :
2013-06-12 23:12:32 +02:00
self . ui . tableWidgetSent . item ( i , 3 ) . setToolTip ( textToDisplay )
2013-06-18 17:30:42 +02:00
try :
newlinePosition = textToDisplay . indexOf ( ' \n ' )
except : # If someone misses adding a "_translate" to a string before passing it to this function, this function won't receive a qstring which will cause an exception.
newlinePosition = 0
2013-06-14 21:58:46 +02:00
if newlinePosition > 1 :
2013-06-12 23:12:32 +02:00
self . ui . tableWidgetSent . item ( i , 3 ) . setText (
2013-06-14 21:58:46 +02:00
textToDisplay [ : newlinePosition ] )
2013-06-11 20:15:17 +02:00
else :
2013-06-12 23:12:32 +02:00
self . ui . tableWidgetSent . item ( i , 3 ) . setText ( textToDisplay )
2013-05-02 17:53:54 +02:00
2013-06-12 23:12:32 +02:00
def removeInboxRowByMsgid ( self , msgid ) : # msgid and inventoryHash are the same thing
2013-06-05 23:15:26 +02:00
for i in range ( self . ui . tableWidgetInbox . rowCount ( ) ) :
2013-06-12 23:12:32 +02:00
if msgid == str ( self . ui . tableWidgetInbox . item ( i , 3 ) . data ( Qt . UserRole ) . toPyObject ( ) ) :
2013-06-13 09:59:40 +02:00
self . statusBar ( ) . showMessage ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Message trashed " ) )
2013-06-05 23:15:26 +02:00
self . ui . tableWidgetInbox . removeRow ( i )
break
2013-05-02 17:53:54 +02:00
def rerenderInboxFromLabels ( self ) :
for i in range ( self . ui . tableWidgetInbox . rowCount ( ) ) :
2013-06-12 23:12:32 +02:00
addressToLookup = str ( self . ui . tableWidgetInbox . item (
i , 1 ) . data ( Qt . UserRole ) . toPyObject ( ) )
2013-05-02 17:53:54 +02:00
fromLabel = ' '
t = ( addressToLookup , )
shared . sqlLock . acquire ( )
2013-06-12 23:12:32 +02:00
shared . sqlSubmitQueue . put (
''' select label from addressbook where address=? ''' )
2013-05-02 17:53:54 +02:00
shared . sqlSubmitQueue . put ( t )
queryreturn = shared . sqlReturnQueue . get ( )
shared . sqlLock . release ( )
2013-06-12 23:12:32 +02:00
if queryreturn != [ ] :
2013-05-02 17:53:54 +02:00
for row in queryreturn :
fromLabel , = row
2013-06-12 23:12:32 +02:00
self . ui . tableWidgetInbox . item (
i , 1 ) . setText ( unicode ( fromLabel , ' utf-8 ' ) )
2013-05-02 17:53:54 +02:00
else :
2013-06-12 23:12:32 +02:00
# It might be a broadcast message. We should check for that
# label.
2013-05-02 17:53:54 +02:00
shared . sqlLock . acquire ( )
2013-06-12 23:12:32 +02:00
shared . sqlSubmitQueue . put (
''' select label from subscriptions where address=? ''' )
2013-05-02 17:53:54 +02:00
shared . sqlSubmitQueue . put ( t )
queryreturn = shared . sqlReturnQueue . get ( )
shared . sqlLock . release ( )
2013-06-12 23:12:32 +02:00
if queryreturn != [ ] :
2013-05-02 17:53:54 +02:00
for row in queryreturn :
fromLabel , = row
2013-06-12 23:12:32 +02:00
self . ui . tableWidgetInbox . item (
i , 1 ) . setText ( unicode ( fromLabel , ' utf-8 ' ) )
2013-05-02 17:53:54 +02:00
def rerenderInboxToLabels ( self ) :
for i in range ( self . ui . tableWidgetInbox . rowCount ( ) ) :
2013-06-12 23:12:32 +02:00
toAddress = str ( self . ui . tableWidgetInbox . item (
i , 0 ) . data ( Qt . UserRole ) . toPyObject ( ) )
2013-05-02 17:53:54 +02:00
try :
toLabel = shared . config . get ( toAddress , ' label ' )
except :
toLabel = ' '
if toLabel == ' ' :
toLabel = toAddress
2013-06-12 23:12:32 +02:00
self . ui . tableWidgetInbox . item (
i , 0 ) . setText ( unicode ( toLabel , ' utf-8 ' ) )
# Set the color according to whether it is the address of a mailing
# list or not.
if shared . safeConfigGetBoolean ( toAddress , ' mailinglist ' ) :
self . ui . tableWidgetInbox . item ( i , 0 ) . setTextColor ( QtGui . QColor ( 137 , 04 , 177 ) )
2013-05-02 17:53:54 +02:00
else :
2013-06-12 23:12:32 +02:00
self . ui . tableWidgetInbox . item (
i , 0 ) . setTextColor ( QtGui . QColor ( 0 , 0 , 0 ) )
2013-05-02 17:53:54 +02:00
def rerenderSentFromLabels ( self ) :
for i in range ( self . ui . tableWidgetSent . rowCount ( ) ) :
2013-06-12 23:12:32 +02:00
fromAddress = str ( self . ui . tableWidgetSent . item (
i , 1 ) . data ( Qt . UserRole ) . toPyObject ( ) )
2013-05-02 17:53:54 +02:00
try :
fromLabel = shared . config . get ( fromAddress , ' label ' )
except :
fromLabel = ' '
if fromLabel == ' ' :
fromLabel = fromAddress
2013-06-12 23:12:32 +02:00
self . ui . tableWidgetSent . item (
i , 1 ) . setText ( unicode ( fromLabel , ' utf-8 ' ) )
2013-05-02 17:53:54 +02:00
def rerenderSentToLabels ( self ) :
for i in range ( self . ui . tableWidgetSent . rowCount ( ) ) :
2013-06-12 23:12:32 +02:00
addressToLookup = str ( self . ui . tableWidgetSent . item (
i , 0 ) . data ( Qt . UserRole ) . toPyObject ( ) )
2013-05-02 17:53:54 +02:00
toLabel = ' '
t = ( addressToLookup , )
2013-05-02 20:18:24 +02:00
shared . sqlLock . acquire ( )
2013-06-12 23:12:32 +02:00
shared . sqlSubmitQueue . put (
''' select label from addressbook where address=? ''' )
2013-05-02 17:53:54 +02:00
shared . sqlSubmitQueue . put ( t )
queryreturn = shared . sqlReturnQueue . get ( )
2013-05-02 20:18:24 +02:00
shared . sqlLock . release ( )
2013-05-02 17:53:54 +02:00
2013-06-12 23:12:32 +02:00
if queryreturn != [ ] :
2013-05-02 17:53:54 +02:00
for row in queryreturn :
toLabel , = row
2013-06-12 23:12:32 +02:00
self . ui . tableWidgetSent . item (
i , 0 ) . setText ( unicode ( toLabel , ' utf-8 ' ) )
2013-05-02 17:53:54 +02:00
2013-05-24 22:12:16 +02:00
def rerenderSubscriptions ( self ) :
self . ui . tableWidgetSubscriptions . setRowCount ( 0 )
shared . sqlLock . acquire ( )
2013-06-12 23:12:32 +02:00
shared . sqlSubmitQueue . put (
' SELECT label, address, enabled FROM subscriptions ' )
2013-05-24 22:12:16 +02:00
shared . sqlSubmitQueue . put ( ' ' )
queryreturn = shared . sqlReturnQueue . get ( )
shared . sqlLock . release ( )
for row in queryreturn :
label , address , enabled = row
self . ui . tableWidgetSubscriptions . insertRow ( 0 )
2013-06-12 23:12:32 +02:00
newItem = QtGui . QTableWidgetItem ( unicode ( label , ' utf-8 ' ) )
2013-05-24 22:12:16 +02:00
if not enabled :
2013-06-12 23:12:32 +02:00
newItem . setTextColor ( QtGui . QColor ( 128 , 128 , 128 ) )
self . ui . tableWidgetSubscriptions . setItem ( 0 , 0 , newItem )
newItem = QtGui . QTableWidgetItem ( address )
newItem . setFlags (
QtCore . Qt . ItemIsSelectable | QtCore . Qt . ItemIsEnabled )
2013-05-24 22:12:16 +02:00
if not enabled :
2013-06-12 23:12:32 +02:00
newItem . setTextColor ( QtGui . QColor ( 128 , 128 , 128 ) )
self . ui . tableWidgetSubscriptions . setItem ( 0 , 1 , newItem )
2013-05-24 22:12:16 +02:00
2013-05-02 17:53:54 +02:00
def click_pushButtonSend ( self ) :
self . statusBar ( ) . showMessage ( ' ' )
toAddresses = str ( self . ui . lineEditTo . text ( ) )
fromAddress = str ( self . ui . labelFrom . text ( ) )
subject = str ( self . ui . lineEditSubject . text ( ) . toUtf8 ( ) )
2013-06-12 23:12:32 +02:00
message = str (
self . ui . textEditMessage . document ( ) . toPlainText ( ) . toUtf8 ( ) )
if self . ui . radioButtonSpecific . isChecked ( ) : # To send a message to specific people (rather than broadcast)
toAddressesList = [ s . strip ( )
for s in toAddresses . replace ( ' , ' , ' ; ' ) . split ( ' ; ' ) ]
toAddressesList = list ( set (
toAddressesList ) ) # remove duplicate addresses. If the user has one address with a BM- and the same address without the BM-, this will not catch it. They'll send the message to the person twice.
2013-05-02 17:53:54 +02:00
for toAddress in toAddressesList :
2013-06-12 23:12:32 +02:00
if toAddress != ' ' :
status , addressVersionNumber , streamNumber , ripe = decodeAddress (
toAddress )
if status != ' success ' :
2013-06-29 19:29:35 +02:00
with shared . printLock :
print ' Error: Could not decode ' , toAddress , ' : ' , status
2013-05-02 17:53:54 +02:00
if status == ' missingbm ' :
2013-06-13 09:59:40 +02:00
self . statusBar ( ) . showMessage ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Error: Bitmessage addresses start with BM- Please check % 1 " ) . arg ( toAddress ) )
2013-05-02 17:53:54 +02:00
elif status == ' checksumfailed ' :
2013-06-13 09:59:40 +02:00
self . statusBar ( ) . showMessage ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Error: The address % 1 is not typed or copied correctly. Please check it. " ) . arg ( toAddress ) )
2013-05-02 17:53:54 +02:00
elif status == ' invalidcharacters ' :
2013-06-13 09:59:40 +02:00
self . statusBar ( ) . showMessage ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Error: The address % 1 contains invalid characters. Please check it. " ) . arg ( toAddress ) )
2013-05-02 17:53:54 +02:00
elif status == ' versiontoohigh ' :
2013-06-13 09:59:40 +02:00
self . statusBar ( ) . showMessage ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Error: The address version in % 1 is too high. Either you need to upgrade your Bitmessage software or your acquaintance is being clever. " ) . arg ( toAddress ) )
2013-05-02 17:53:54 +02:00
elif status == ' ripetooshort ' :
2013-06-13 09:59:40 +02:00
self . statusBar ( ) . showMessage ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Error: Some data encoded in the address % 1 is too short. There might be something wrong with the software of your acquaintance. " ) . arg ( toAddress ) )
2013-05-02 17:53:54 +02:00
elif status == ' ripetoolong ' :
2013-06-13 09:59:40 +02:00
self . statusBar ( ) . showMessage ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Error: Some data encoded in the address % 1 is too long. There might be something wrong with the software of your acquaintance. " ) . arg ( toAddress ) )
2013-05-02 17:53:54 +02:00
else :
2013-06-13 09:59:40 +02:00
self . statusBar ( ) . showMessage ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Error: Something is wrong with the address % 1. " ) . arg ( toAddress ) )
2013-05-02 17:53:54 +02:00
elif fromAddress == ' ' :
2013-06-13 09:59:40 +02:00
self . statusBar ( ) . showMessage ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Error: You must specify a From address. If you don \' t have one, go to the \' Your Identities \' tab. " ) )
2013-05-02 17:53:54 +02:00
else :
toAddress = addBMIfNotPresent ( toAddress )
try :
shared . config . get ( toAddress , ' enabled ' )
2013-06-12 23:12:32 +02:00
# The toAddress is one owned by me. We cannot send
# messages to ourselves without significant changes
# to the codebase.
2013-06-13 09:59:40 +02:00
QMessageBox . about ( self , _translate ( " MainWindow " , " Sending to your address " ) , _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Error: One of the addresses to which you are sending a message, % 1, is yours. Unfortunately the Bitmessage client cannot process its own messages. Please try running a second client on a different computer or within a VM. " ) . arg ( toAddress ) )
2013-05-02 17:53:54 +02:00
continue
except :
pass
2013-06-11 00:53:15 +02:00
if addressVersionNumber > 3 or addressVersionNumber < = 1 :
2013-06-13 09:59:40 +02:00
QMessageBox . about ( self , _translate ( " MainWindow " , " Address version number " ) , _translate (
2013-06-12 23:12:32 +02:00
" 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 ) ) )
2013-05-02 17:53:54 +02:00
continue
if streamNumber > 1 or streamNumber == 0 :
2013-06-13 09:59:40 +02:00
QMessageBox . about ( self , _translate ( " MainWindow " , " Stream number " ) , _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Concerning the address % 1, Bitmessage cannot handle stream numbers of % 2. Perhaps upgrade Bitmessage to the latest version. " ) . arg ( toAddress ) . arg ( str ( streamNumber ) ) )
2013-05-02 17:53:54 +02:00
continue
self . statusBar ( ) . showMessage ( ' ' )
if shared . statusIconColor == ' red ' :
2013-06-13 09:59:40 +02:00
self . statusBar ( ) . showMessage ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Warning: You are currently not connected. Bitmessage will do the work necessary to send the message but it won \' t send until you connect. " ) )
2013-05-02 17:53:54 +02:00
ackdata = OpenSSL . rand ( 32 )
shared . sqlLock . acquire ( )
2013-06-12 23:12:32 +02:00
t = ( ' ' , toAddress , ripe , fromAddress , subject , message , ackdata , int (
time . time ( ) ) , ' msgqueued ' , 1 , 1 , ' sent ' , 2 )
shared . sqlSubmitQueue . put (
''' INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?) ''' )
2013-05-02 17:53:54 +02:00
shared . sqlSubmitQueue . put ( t )
shared . sqlReturnQueue . get ( )
shared . sqlSubmitQueue . put ( ' commit ' )
shared . sqlLock . release ( )
toLabel = ' '
t = ( toAddress , )
shared . sqlLock . acquire ( )
2013-06-12 23:12:32 +02:00
shared . sqlSubmitQueue . put (
''' select label from addressbook where address=? ''' )
2013-05-02 17:53:54 +02:00
shared . sqlSubmitQueue . put ( t )
queryreturn = shared . sqlReturnQueue . get ( )
shared . sqlLock . release ( )
2013-06-12 23:12:32 +02:00
if queryreturn != [ ] :
2013-05-02 17:53:54 +02:00
for row in queryreturn :
toLabel , = row
2013-06-12 23:12:32 +02:00
self . displayNewSentMessage (
toAddress , toLabel , fromAddress , subject , message , ackdata )
shared . workerQueue . put ( ( ' sendmessage ' , toAddress ) )
2013-05-02 17:53:54 +02:00
self . ui . comboBoxSendFrom . setCurrentIndex ( 0 )
self . ui . labelFrom . setText ( ' ' )
self . ui . lineEditTo . setText ( ' ' )
self . ui . lineEditSubject . setText ( ' ' )
self . ui . textEditMessage . setText ( ' ' )
self . ui . tabWidget . setCurrentIndex ( 2 )
2013-06-12 23:12:32 +02:00
self . ui . tableWidgetSent . setCurrentCell ( 0 , 0 )
2013-05-02 17:53:54 +02:00
else :
2013-06-13 09:59:40 +02:00
self . statusBar ( ) . showMessage ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Your \' To \' field is empty. " ) )
else : # User selected 'Broadcast'
2013-05-02 17:53:54 +02:00
if fromAddress == ' ' :
2013-06-13 09:59:40 +02:00
self . statusBar ( ) . showMessage ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Error: You must specify a From address. If you don \' t have one, go to the \' Your Identities \' tab. " ) )
2013-05-02 17:53:54 +02:00
else :
self . statusBar ( ) . showMessage ( ' ' )
2013-06-12 23:12:32 +02:00
# We don't actually need the ackdata for acknowledgement since
# this is a broadcast message, but we can use it to update the
# user interface when the POW is done generating.
2013-05-02 17:53:54 +02:00
ackdata = OpenSSL . rand ( 32 )
2013-05-14 17:06:01 +02:00
toAddress = self . str_broadcast_subscribers
2013-05-02 17:53:54 +02:00
ripe = ' '
shared . sqlLock . acquire ( )
2013-06-12 23:12:32 +02:00
t = ( ' ' , toAddress , ripe , fromAddress , subject , message , ackdata , int (
time . time ( ) ) , ' broadcastqueued ' , 1 , 1 , ' sent ' , 2 )
shared . sqlSubmitQueue . put (
''' INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?) ''' )
2013-05-02 17:53:54 +02:00
shared . sqlSubmitQueue . put ( t )
shared . sqlReturnQueue . get ( )
shared . sqlSubmitQueue . put ( ' commit ' )
shared . sqlLock . release ( )
2013-06-12 23:12:32 +02:00
shared . workerQueue . put ( ( ' sendbroadcast ' , ' ' ) )
2013-05-02 17:53:54 +02:00
try :
fromLabel = shared . config . get ( fromAddress , ' label ' )
except :
fromLabel = ' '
if fromLabel == ' ' :
fromLabel = fromAddress
2013-05-14 17:06:01 +02:00
toLabel = self . str_broadcast_subscribers
2013-05-02 17:53:54 +02:00
self . ui . tableWidgetSent . insertRow ( 0 )
2013-06-12 23:12:32 +02:00
newItem = QtGui . QTableWidgetItem ( unicode ( toLabel , ' utf-8 ' ) )
newItem . setData ( Qt . UserRole , str ( toAddress ) )
self . ui . tableWidgetSent . setItem ( 0 , 0 , newItem )
2013-05-02 17:53:54 +02:00
if fromLabel == ' ' :
2013-06-12 23:12:32 +02:00
newItem = QtGui . QTableWidgetItem (
unicode ( fromAddress , ' utf-8 ' ) )
2013-05-02 17:53:54 +02:00
else :
2013-06-12 23:12:32 +02:00
newItem = QtGui . QTableWidgetItem (
unicode ( fromLabel , ' utf-8 ' ) )
newItem . setData ( Qt . UserRole , str ( fromAddress ) )
self . ui . tableWidgetSent . setItem ( 0 , 1 , newItem )
newItem = QtGui . QTableWidgetItem ( unicode ( subject , ' utf-8) ' ) )
newItem . setData ( Qt . UserRole , unicode ( message , ' utf-8) ' ) )
self . ui . tableWidgetSent . setItem ( 0 , 2 , newItem )
# newItem = QtGui.QTableWidgetItem('Doing work necessary to
# send broadcast...'+
# unicode(strftime(config.get('bitmessagesettings',
# 'timeformat'),localtime(int(time.time()))),'utf-8'))
2013-06-13 23:14:03 +02:00
newItem = myTableWidgetItem ( _translate ( " MainWindow " , " Work is queued. " ) )
2013-06-12 23:12:32 +02:00
newItem . setData ( Qt . UserRole , QByteArray ( ackdata ) )
newItem . setData ( 33 , int ( time . time ( ) ) )
self . ui . tableWidgetSent . setItem ( 0 , 3 , newItem )
self . ui . textEditSentMessage . setPlainText (
self . ui . tableWidgetSent . item ( 0 , 2 ) . data ( Qt . UserRole ) . toPyObject ( ) )
2013-05-02 17:53:54 +02:00
self . ui . comboBoxSendFrom . setCurrentIndex ( 0 )
self . ui . labelFrom . setText ( ' ' )
self . ui . lineEditTo . setText ( ' ' )
self . ui . lineEditSubject . setText ( ' ' )
self . ui . textEditMessage . setText ( ' ' )
self . ui . tabWidget . setCurrentIndex ( 2 )
2013-06-12 23:12:32 +02:00
self . ui . tableWidgetSent . setCurrentCell ( 0 , 0 )
2013-05-02 17:53:54 +02:00
def click_pushButtonLoadFromAddressBook ( self ) :
self . ui . tabWidget . setCurrentIndex ( 5 )
for i in range ( 4 ) :
time . sleep ( 0.1 )
self . statusBar ( ) . showMessage ( ' ' )
time . sleep ( 0.1 )
2013-06-13 09:59:40 +02:00
self . statusBar ( ) . showMessage ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Right click one or more entries in your address book and select \' Send message to this address \' . " ) )
2013-05-02 17:53:54 +02:00
2013-07-04 22:06:30 +02:00
def click_pushButtonFetchNamecoinID ( self ) :
2013-07-05 17:29:49 +02:00
nc = namecoinConnection ( )
2013-07-05 18:14:47 +02:00
err , addr = nc . query ( str ( self . ui . lineEditTo . text ( ) ) )
2013-07-05 17:29:49 +02:00
if err is not None :
self . statusBar ( ) . showMessage ( _translate (
" MainWindow " , " Error: " + err ) )
else :
self . ui . lineEditTo . setText ( addr )
2013-07-04 22:06:30 +02:00
2013-06-12 23:12:32 +02:00
def redrawLabelFrom ( self , index ) :
self . ui . labelFrom . setText (
self . ui . comboBoxSendFrom . itemData ( index ) . toPyObject ( ) )
2013-05-02 17:53:54 +02:00
def rerenderComboBoxSendFrom ( self ) :
self . ui . comboBoxSendFrom . clear ( )
self . ui . labelFrom . setText ( ' ' )
configSections = shared . config . sections ( )
for addressInKeysFile in configSections :
2013-06-12 23:12:32 +02:00
if addressInKeysFile != ' bitmessagesettings ' :
isEnabled = shared . config . getboolean (
addressInKeysFile , ' enabled ' ) # I realize that this is poor programming practice but I don't care. It's easier for others to read.
2013-05-02 17:53:54 +02:00
if isEnabled :
2013-06-12 23:12:32 +02:00
self . ui . comboBoxSendFrom . insertItem ( 0 , unicode ( shared . config . get (
addressInKeysFile , ' label ' ) , ' utf-8 ' ) , addressInKeysFile )
self . ui . comboBoxSendFrom . insertItem ( 0 , ' ' , ' ' )
2013-05-02 17:53:54 +02:00
if ( self . ui . comboBoxSendFrom . count ( ) == 2 ) :
self . ui . comboBoxSendFrom . setCurrentIndex ( 1 )
self . redrawLabelFrom ( self . ui . comboBoxSendFrom . currentIndex ( ) )
else :
self . ui . comboBoxSendFrom . setCurrentIndex ( 0 )
2013-06-12 23:12:32 +02:00
# This function is called by the processmsg function when that function
# receives a message to an address that is acting as a
# pseudo-mailing-list. The message will be broadcast out. This function
# puts the message on the 'Sent' tab.
def displayNewSentMessage ( self , toAddress , toLabel , fromAddress , subject , message , ackdata ) :
2013-06-11 00:53:15 +02:00
subject = shared . fixPotentiallyInvalidUTF8Data ( subject )
message = shared . fixPotentiallyInvalidUTF8Data ( message )
2013-05-02 17:53:54 +02:00
try :
fromLabel = shared . config . get ( fromAddress , ' label ' )
except :
fromLabel = ' '
if fromLabel == ' ' :
fromLabel = fromAddress
self . ui . tableWidgetSent . setSortingEnabled ( False )
self . ui . tableWidgetSent . insertRow ( 0 )
if toLabel == ' ' :
2013-06-12 23:12:32 +02:00
newItem = QtGui . QTableWidgetItem ( unicode ( toAddress , ' utf-8 ' ) )
newItem . setToolTip ( unicode ( toAddress , ' utf-8 ' ) )
2013-05-02 17:53:54 +02:00
else :
2013-06-12 23:12:32 +02:00
newItem = QtGui . QTableWidgetItem ( unicode ( toLabel , ' utf-8 ' ) )
newItem . setToolTip ( unicode ( toLabel , ' utf-8 ' ) )
newItem . setData ( Qt . UserRole , str ( toAddress ) )
self . ui . tableWidgetSent . setItem ( 0 , 0 , newItem )
2013-05-02 17:53:54 +02:00
if fromLabel == ' ' :
2013-06-12 23:12:32 +02:00
newItem = QtGui . QTableWidgetItem ( unicode ( fromAddress , ' utf-8 ' ) )
newItem . setToolTip ( unicode ( fromAddress , ' utf-8 ' ) )
2013-05-02 17:53:54 +02:00
else :
2013-06-12 23:12:32 +02:00
newItem = QtGui . QTableWidgetItem ( unicode ( fromLabel , ' utf-8 ' ) )
newItem . setToolTip ( unicode ( fromLabel , ' utf-8 ' ) )
newItem . setData ( Qt . UserRole , str ( fromAddress ) )
self . ui . tableWidgetSent . setItem ( 0 , 1 , newItem )
newItem = QtGui . QTableWidgetItem ( unicode ( subject , ' utf-8) ' ) )
newItem . setToolTip ( unicode ( subject , ' utf-8) ' ) )
newItem . setData ( Qt . UserRole , unicode ( message , ' utf-8) ' ) )
self . ui . tableWidgetSent . setItem ( 0 , 2 , newItem )
# newItem = QtGui.QTableWidgetItem('Doing work necessary to send
# broadcast...'+
# unicode(strftime(shared.config.get('bitmessagesettings',
# 'timeformat'),localtime(int(time.time()))),'utf-8'))
2013-06-13 23:14:03 +02:00
newItem = myTableWidgetItem ( _translate ( " MainWindow " , " Work is queued. % 1 " ) . arg ( unicode ( strftime ( shared . config . get (
' bitmessagesettings ' , ' timeformat ' ) , localtime ( int ( time . time ( ) ) ) ) , ' utf-8 ' ) ) )
newItem . setToolTip ( _translate ( " MainWindow " , " Work is queued. % 1 " ) . arg ( unicode ( strftime ( shared . config . get (
' bitmessagesettings ' , ' timeformat ' ) , localtime ( int ( time . time ( ) ) ) ) , ' utf-8 ' ) ) )
2013-06-12 23:12:32 +02:00
newItem . setData ( Qt . UserRole , QByteArray ( ackdata ) )
newItem . setData ( 33 , int ( time . time ( ) ) )
self . ui . tableWidgetSent . setItem ( 0 , 3 , newItem )
self . ui . textEditSentMessage . setPlainText (
self . ui . tableWidgetSent . item ( 0 , 2 ) . data ( Qt . UserRole ) . toPyObject ( ) )
2013-05-02 17:53:54 +02:00
self . ui . tableWidgetSent . setSortingEnabled ( True )
2013-06-12 23:12:32 +02:00
def displayNewInboxMessage ( self , inventoryHash , toAddress , fromAddress , subject , message ) :
2013-06-11 00:53:15 +02:00
subject = shared . fixPotentiallyInvalidUTF8Data ( subject )
message = shared . fixPotentiallyInvalidUTF8Data ( message )
2013-05-02 17:53:54 +02:00
fromLabel = ' '
shared . sqlLock . acquire ( )
t = ( fromAddress , )
2013-06-12 23:12:32 +02:00
shared . sqlSubmitQueue . put (
''' select label from addressbook where address=? ''' )
2013-05-02 17:53:54 +02:00
shared . sqlSubmitQueue . put ( t )
queryreturn = shared . sqlReturnQueue . get ( )
shared . sqlLock . release ( )
2013-06-12 23:12:32 +02:00
if queryreturn != [ ] :
2013-05-02 17:53:54 +02:00
for row in queryreturn :
fromLabel , = row
else :
2013-06-12 23:12:32 +02:00
# There might be a label in the subscriptions table
2013-05-02 17:53:54 +02:00
shared . sqlLock . acquire ( )
t = ( fromAddress , )
2013-06-12 23:12:32 +02:00
shared . sqlSubmitQueue . put (
''' select label from subscriptions where address=? ''' )
2013-05-02 17:53:54 +02:00
shared . sqlSubmitQueue . put ( t )
queryreturn = shared . sqlReturnQueue . get ( )
shared . sqlLock . release ( )
2013-06-12 23:12:32 +02:00
if queryreturn != [ ] :
2013-05-02 17:53:54 +02:00
for row in queryreturn :
fromLabel , = row
try :
2013-05-14 17:06:01 +02:00
if toAddress == self . str_broadcast_subscribers :
toLabel = self . str_broadcast_subscribers
2013-05-02 17:53:54 +02:00
else :
toLabel = shared . config . get ( toAddress , ' label ' )
except :
toLabel = ' '
if toLabel == ' ' :
toLabel = toAddress
font = QFont ( )
font . setBold ( True )
self . ui . tableWidgetInbox . setSortingEnabled ( False )
2013-06-12 23:12:32 +02:00
newItem = QtGui . QTableWidgetItem ( unicode ( toLabel , ' utf-8 ' ) )
newItem . setToolTip ( unicode ( toLabel , ' utf-8 ' ) )
2013-05-02 17:53:54 +02:00
newItem . setFont ( font )
2013-06-12 23:12:32 +02:00
newItem . setData ( Qt . UserRole , str ( toAddress ) )
if shared . safeConfigGetBoolean ( str ( toAddress ) , ' mailinglist ' ) :
newItem . setTextColor ( QtGui . QColor ( 137 , 04 , 177 ) )
2013-05-02 17:53:54 +02:00
self . ui . tableWidgetInbox . insertRow ( 0 )
2013-06-12 23:12:32 +02:00
self . ui . tableWidgetInbox . setItem ( 0 , 0 , newItem )
2013-05-02 17:53:54 +02:00
if fromLabel == ' ' :
2013-06-12 23:12:32 +02:00
newItem = QtGui . QTableWidgetItem ( unicode ( fromAddress , ' utf-8 ' ) )
newItem . setToolTip ( unicode ( fromAddress , ' utf-8 ' ) )
2013-05-02 17:53:54 +02:00
if shared . config . getboolean ( ' bitmessagesettings ' , ' showtraynotifications ' ) :
2013-06-20 22:41:14 +02:00
self . notifierShow ( unicode ( _translate ( " MainWindow " , ' New Message ' ) . toUtf8 ( ) , ' utf-8 ' ) , unicode ( _translate ( " MainWindow " , ' From ' ) . toUtf8 ( ) , ' utf-8 ' ) + unicode ( fromAddress , ' utf-8 ' ) )
2013-05-02 17:53:54 +02:00
else :
2013-06-12 23:12:32 +02:00
newItem = QtGui . QTableWidgetItem ( unicode ( fromLabel , ' utf-8 ' ) )
newItem . setToolTip ( unicode ( unicode ( fromLabel , ' utf-8 ' ) ) )
2013-05-02 17:53:54 +02:00
if shared . config . getboolean ( ' bitmessagesettings ' , ' showtraynotifications ' ) :
2013-06-20 22:41:14 +02:00
self . notifierShow ( unicode ( _translate ( " MainWindow " , ' New Message ' ) . toUtf8 ( ) , ' utf-8 ' ) , unicode ( _translate ( " MainWindow " , ' From ' ) . toUtf8 ( ) , ' utf-8 ' ) + unicode ( fromLabel , ' utf-8 ' ) )
2013-06-12 23:12:32 +02:00
newItem . setData ( Qt . UserRole , str ( fromAddress ) )
2013-05-02 17:53:54 +02:00
newItem . setFont ( font )
2013-06-12 23:12:32 +02:00
self . ui . tableWidgetInbox . setItem ( 0 , 1 , newItem )
newItem = QtGui . QTableWidgetItem ( unicode ( subject , ' utf-8) ' ) )
newItem . setToolTip ( unicode ( subject , ' utf-8) ' ) )
newItem . setData ( Qt . UserRole , unicode ( message , ' utf-8) ' ) )
2013-05-02 17:53:54 +02:00
newItem . setFont ( font )
2013-06-12 23:12:32 +02:00
self . ui . tableWidgetInbox . setItem ( 0 , 2 , newItem )
newItem = myTableWidgetItem ( unicode ( strftime ( shared . config . get (
' bitmessagesettings ' , ' timeformat ' ) , localtime ( int ( time . time ( ) ) ) ) , ' utf-8 ' ) )
newItem . setToolTip ( unicode ( strftime ( shared . config . get (
' bitmessagesettings ' , ' timeformat ' ) , localtime ( int ( time . time ( ) ) ) ) , ' utf-8 ' ) )
newItem . setData ( Qt . UserRole , QByteArray ( inventoryHash ) )
newItem . setData ( 33 , int ( time . time ( ) ) )
2013-05-02 17:53:54 +02:00
newItem . setFont ( font )
2013-06-12 23:12:32 +02:00
self . ui . tableWidgetInbox . setItem ( 0 , 3 , newItem )
2013-05-02 17:53:54 +02:00
self . ui . tableWidgetInbox . setSortingEnabled ( True )
2013-05-14 17:06:01 +02:00
self . ubuntuMessagingMenuUpdate ( True , newItem , toLabel )
2013-05-02 17:53:54 +02:00
def click_pushButtonAddAddressBook ( self ) :
self . NewSubscriptionDialogInstance = NewSubscriptionDialog ( self )
if self . NewSubscriptionDialogInstance . exec_ ( ) :
2013-06-13 23:52:24 +02:00
if self . NewSubscriptionDialogInstance . ui . labelSubscriptionAddressCheck . text ( ) == _translate ( " MainWindow " , " Address is valid. " ) :
2013-06-12 23:12:32 +02:00
# First we must check to see if the address is already in the
# address book. The user cannot add it again or else it will
# cause problems when updating and deleting the entry.
2013-05-02 17:53:54 +02:00
shared . sqlLock . acquire ( )
2013-06-12 23:12:32 +02:00
t = ( addBMIfNotPresent ( str (
self . NewSubscriptionDialogInstance . ui . lineEditSubscriptionAddress . text ( ) ) ) , )
shared . sqlSubmitQueue . put (
''' select * from addressbook where address=? ''' )
2013-05-02 17:53:54 +02:00
shared . sqlSubmitQueue . put ( t )
queryreturn = shared . sqlReturnQueue . get ( )
shared . sqlLock . release ( )
if queryreturn == [ ] :
self . ui . tableWidgetAddressBook . setSortingEnabled ( False )
self . ui . tableWidgetAddressBook . insertRow ( 0 )
2013-06-12 23:12:32 +02:00
newItem = QtGui . QTableWidgetItem ( unicode (
self . NewSubscriptionDialogInstance . ui . newsubscriptionlabel . text ( ) . toUtf8 ( ) , ' utf-8 ' ) )
self . ui . tableWidgetAddressBook . setItem ( 0 , 0 , newItem )
newItem = QtGui . QTableWidgetItem ( addBMIfNotPresent (
self . NewSubscriptionDialogInstance . ui . lineEditSubscriptionAddress . text ( ) ) )
newItem . setFlags (
QtCore . Qt . ItemIsSelectable | QtCore . Qt . ItemIsEnabled )
self . ui . tableWidgetAddressBook . setItem ( 0 , 1 , newItem )
2013-05-02 17:53:54 +02:00
self . ui . tableWidgetAddressBook . setSortingEnabled ( True )
2013-06-12 23:12:32 +02:00
t = ( str ( self . NewSubscriptionDialogInstance . ui . newsubscriptionlabel . text ( ) . toUtf8 ( ) ) , addBMIfNotPresent (
str ( self . NewSubscriptionDialogInstance . ui . lineEditSubscriptionAddress . text ( ) ) ) )
2013-05-02 17:53:54 +02:00
shared . sqlLock . acquire ( )
2013-06-12 23:12:32 +02:00
shared . sqlSubmitQueue . put (
''' INSERT INTO addressbook VALUES (?,?) ''' )
2013-05-02 17:53:54 +02:00
shared . sqlSubmitQueue . put ( t )
queryreturn = shared . sqlReturnQueue . get ( )
shared . sqlSubmitQueue . put ( ' commit ' )
shared . sqlLock . release ( )
self . rerenderInboxFromLabels ( )
self . rerenderSentToLabels ( )
else :
2013-06-13 09:59:40 +02:00
self . statusBar ( ) . showMessage ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Error: You cannot add the same address to your address book twice. Try renaming the existing one if you want. " ) )
2013-05-02 17:53:54 +02:00
else :
2013-06-13 09:59:40 +02:00
self . statusBar ( ) . showMessage ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " The address you entered was invalid. Ignoring it. " ) )
2013-05-02 17:53:54 +02:00
2013-06-14 03:55:38 +02:00
def addSubscription ( self , label , address ) :
address = addBMIfNotPresent ( address )
#This should be handled outside of this function, for error displaying and such, but it must also be checked here.
if shared . isAddressInMySubscriptionsList ( address ) :
return
#Add to UI list
self . ui . tableWidgetSubscriptions . setSortingEnabled ( False )
self . ui . tableWidgetSubscriptions . insertRow ( 0 )
newItem = QtGui . QTableWidgetItem ( unicode ( label , ' utf-8 ' ) )
self . ui . tableWidgetSubscriptions . setItem ( 0 , 0 , newItem )
newItem = QtGui . QTableWidgetItem ( address )
newItem . setFlags ( QtCore . Qt . ItemIsSelectable | QtCore . Qt . ItemIsEnabled )
self . ui . tableWidgetSubscriptions . setItem ( 0 , 1 , newItem )
self . ui . tableWidgetSubscriptions . setSortingEnabled ( True )
#Add to database (perhaps this should be separated from the MyForm class)
t = ( str ( label ) , address , True )
shared . sqlLock . acquire ( )
shared . sqlSubmitQueue . put ( ''' INSERT INTO subscriptions VALUES (?,?,?) ''' )
shared . sqlSubmitQueue . put ( t )
queryreturn = shared . sqlReturnQueue . get ( )
shared . sqlSubmitQueue . put ( ' commit ' )
shared . sqlLock . release ( )
self . rerenderInboxFromLabels ( )
shared . reloadBroadcastSendersForWhichImWatching ( )
2013-05-02 17:53:54 +02:00
def click_pushButtonAddSubscription ( self ) :
self . NewSubscriptionDialogInstance = NewSubscriptionDialog ( self )
if self . NewSubscriptionDialogInstance . exec_ ( ) :
2013-06-19 18:19:07 +02:00
if self . NewSubscriptionDialogInstance . ui . labelSubscriptionAddressCheck . text ( ) != _translate ( " MainWindow " , " Address is valid. " ) :
self . statusBar ( ) . showMessage ( _translate ( " MainWindow " , " The address you entered was invalid. Ignoring it. " ) )
return
address = addBMIfNotPresent ( str ( self . NewSubscriptionDialogInstance . ui . lineEditSubscriptionAddress . text ( ) ) )
# We must check to see if the address is already in the subscriptions list. The user cannot add it again or else it will cause problems when updating and deleting the entry.
if shared . isAddressInMySubscriptionsList ( address ) :
self . statusBar ( ) . showMessage ( _translate ( " MainWindow " , " Error: You cannot add the same address to your subsciptions twice. Perhaps rename the existing one if you want. " ) )
return
label = self . NewSubscriptionDialogInstance . ui . newsubscriptionlabel . text ( ) . toUtf8 ( )
self . addSubscription ( label , address )
2013-05-02 17:53:54 +02:00
def loadBlackWhiteList ( self ) :
2013-06-12 23:12:32 +02:00
# Initialize the Blacklist or Whitelist table
2013-05-02 17:53:54 +02:00
listType = shared . config . get ( ' bitmessagesettings ' , ' blackwhitelist ' )
2013-05-02 20:18:24 +02:00
shared . sqlLock . acquire ( )
2013-05-02 17:53:54 +02:00
if listType == ' black ' :
2013-06-12 23:12:32 +02:00
shared . sqlSubmitQueue . put (
''' SELECT label, address, enabled FROM blacklist ''' )
2013-05-02 17:53:54 +02:00
else :
2013-06-12 23:12:32 +02:00
shared . sqlSubmitQueue . put (
''' SELECT label, address, enabled FROM whitelist ''' )
2013-05-02 17:53:54 +02:00
shared . sqlSubmitQueue . put ( ' ' )
queryreturn = shared . sqlReturnQueue . get ( )
2013-05-02 20:18:24 +02:00
shared . sqlLock . release ( )
2013-05-02 17:53:54 +02:00
for row in queryreturn :
label , address , enabled = row
self . ui . tableWidgetBlacklist . insertRow ( 0 )
2013-06-12 23:12:32 +02:00
newItem = QtGui . QTableWidgetItem ( unicode ( label , ' utf-8 ' ) )
2013-05-02 17:53:54 +02:00
if not enabled :
2013-06-12 23:12:32 +02:00
newItem . setTextColor ( QtGui . QColor ( 128 , 128 , 128 ) )
self . ui . tableWidgetBlacklist . setItem ( 0 , 0 , newItem )
newItem = QtGui . QTableWidgetItem ( address )
newItem . setFlags (
QtCore . Qt . ItemIsSelectable | QtCore . Qt . ItemIsEnabled )
2013-05-02 17:53:54 +02:00
if not enabled :
2013-06-12 23:12:32 +02:00
newItem . setTextColor ( QtGui . QColor ( 128 , 128 , 128 ) )
self . ui . tableWidgetBlacklist . setItem ( 0 , 1 , newItem )
2013-05-02 17:53:54 +02:00
def click_pushButtonStatusIcon ( self ) :
print ' click_pushButtonStatusIcon '
self . iconGlossaryInstance = iconGlossaryDialog ( self )
if self . iconGlossaryInstance . exec_ ( ) :
pass
def click_actionHelp ( self ) :
self . helpDialogInstance = helpDialog ( self )
self . helpDialogInstance . exec_ ( )
def click_actionAbout ( self ) :
self . aboutDialogInstance = aboutDialog ( self )
self . aboutDialogInstance . exec_ ( )
def click_actionSettings ( self ) :
self . settingsDialogInstance = settingsDialog ( self )
if self . settingsDialogInstance . exec_ ( ) :
2013-06-12 23:12:32 +02:00
shared . config . set ( ' bitmessagesettings ' , ' startonlogon ' , str (
self . settingsDialogInstance . ui . checkBoxStartOnLogon . isChecked ( ) ) )
shared . config . set ( ' bitmessagesettings ' , ' minimizetotray ' , str (
self . settingsDialogInstance . ui . checkBoxMinimizeToTray . isChecked ( ) ) )
shared . config . set ( ' bitmessagesettings ' , ' showtraynotifications ' , str (
self . settingsDialogInstance . ui . checkBoxShowTrayNotifications . isChecked ( ) ) )
shared . config . set ( ' bitmessagesettings ' , ' startintray ' , str (
self . settingsDialogInstance . ui . checkBoxStartInTray . isChecked ( ) ) )
if int ( shared . config . get ( ' bitmessagesettings ' , ' port ' ) ) != int ( self . settingsDialogInstance . ui . lineEditTCPPort . text ( ) ) :
2013-06-13 09:59:40 +02:00
QMessageBox . about ( self , _translate ( " MainWindow " , " Restart " ) , _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " You must restart Bitmessage for the port number change to take effect. " ) )
shared . config . set ( ' bitmessagesettings ' , ' port ' , str (
self . settingsDialogInstance . ui . lineEditTCPPort . text ( ) ) )
2013-05-02 17:53:54 +02:00
if shared . config . get ( ' bitmessagesettings ' , ' socksproxytype ' ) == ' none ' and str ( self . settingsDialogInstance . ui . comboBoxProxyType . currentText ( ) ) [ 0 : 5 ] == ' SOCKS ' :
if shared . statusIconColor != ' red ' :
2013-06-13 09:59:40 +02:00
QMessageBox . about ( self , _translate ( " MainWindow " , " Restart " ) , _translate (
2013-06-13 01:11:01 +02:00
" MainWindow " , " Bitmessage will use your proxy from now on but you may want to manually restart Bitmessage now to close existing connections. " ) )
2013-05-02 17:53:54 +02:00
if shared . config . get ( ' bitmessagesettings ' , ' socksproxytype ' ) [ 0 : 5 ] == ' SOCKS ' and str ( self . settingsDialogInstance . ui . comboBoxProxyType . currentText ( ) ) == ' none ' :
self . statusBar ( ) . showMessage ( ' ' )
2013-06-12 23:12:32 +02:00
shared . config . set ( ' bitmessagesettings ' , ' socksproxytype ' , str (
self . settingsDialogInstance . ui . comboBoxProxyType . currentText ( ) ) )
shared . config . set ( ' bitmessagesettings ' , ' socksauthentication ' , str (
self . settingsDialogInstance . ui . checkBoxAuthentication . isChecked ( ) ) )
shared . config . set ( ' bitmessagesettings ' , ' sockshostname ' , str (
self . settingsDialogInstance . ui . lineEditSocksHostname . text ( ) ) )
shared . config . set ( ' bitmessagesettings ' , ' socksport ' , str (
self . settingsDialogInstance . ui . lineEditSocksPort . text ( ) ) )
shared . config . set ( ' bitmessagesettings ' , ' socksusername ' , str (
self . settingsDialogInstance . ui . lineEditSocksUsername . text ( ) ) )
shared . config . set ( ' bitmessagesettings ' , ' sockspassword ' , str (
self . settingsDialogInstance . ui . lineEditSocksPassword . text ( ) ) )
2013-07-07 17:34:43 +02:00
shared . config . set ( ' bitmessagesettings ' , ' namecoinrpchost ' , str (
self . settingsDialogInstance . ui . lineEditNamecoinHost . text ( ) ) )
shared . config . set ( ' bitmessagesettings ' , ' namecoinrpcport ' , str (
self . settingsDialogInstance . ui . lineEditNamecoinPort . text ( ) ) )
shared . config . set ( ' bitmessagesettings ' , ' namecoinrpcuser ' , str (
self . settingsDialogInstance . ui . lineEditNamecoinUser . text ( ) ) )
shared . config . set ( ' bitmessagesettings ' , ' namecoinrpcpassword ' , str (
self . settingsDialogInstance . ui . lineEditNamecoinPassword . text ( ) ) )
2013-05-02 17:53:54 +02:00
if float ( self . settingsDialogInstance . ui . lineEditTotalDifficulty . text ( ) ) > = 1 :
2013-06-12 23:12:32 +02:00
shared . config . set ( ' bitmessagesettings ' , ' defaultnoncetrialsperbyte ' , str ( int ( float (
self . settingsDialogInstance . ui . lineEditTotalDifficulty . text ( ) ) * shared . networkDefaultProofOfWorkNonceTrialsPerByte ) ) )
2013-05-02 17:53:54 +02:00
if float ( self . settingsDialogInstance . ui . lineEditSmallMessageDifficulty . text ( ) ) > = 1 :
2013-06-12 23:12:32 +02:00
shared . config . set ( ' bitmessagesettings ' , ' defaultpayloadlengthextrabytes ' , str ( int ( float (
self . settingsDialogInstance . ui . lineEditSmallMessageDifficulty . text ( ) ) * shared . networkDefaultPayloadLengthExtraBytes ) ) )
2013-06-11 00:53:15 +02:00
if float ( self . settingsDialogInstance . ui . lineEditMaxAcceptableTotalDifficulty . text ( ) ) > = 1 or float ( self . settingsDialogInstance . ui . lineEditMaxAcceptableTotalDifficulty . text ( ) ) == 0 :
2013-06-12 23:12:32 +02:00
shared . config . set ( ' bitmessagesettings ' , ' maxacceptablenoncetrialsperbyte ' , str ( int ( float (
self . settingsDialogInstance . ui . lineEditMaxAcceptableTotalDifficulty . text ( ) ) * shared . networkDefaultProofOfWorkNonceTrialsPerByte ) ) )
2013-06-11 00:53:15 +02:00
if float ( self . settingsDialogInstance . ui . lineEditMaxAcceptableSmallMessageDifficulty . text ( ) ) > = 1 or float ( self . settingsDialogInstance . ui . lineEditMaxAcceptableSmallMessageDifficulty . text ( ) ) == 0 :
2013-06-12 23:12:32 +02:00
shared . config . set ( ' bitmessagesettings ' , ' maxacceptablepayloadlengthextrabytes ' , str ( int ( float (
self . settingsDialogInstance . ui . lineEditMaxAcceptableSmallMessageDifficulty . text ( ) ) * shared . networkDefaultPayloadLengthExtraBytes ) ) )
# if str(self.settingsDialogInstance.ui.comboBoxMaxCores.currentText()) == 'All':
2013-06-04 05:14:24 +02:00
# shared.config.set('bitmessagesettings', 'maxcores', '99999')
2013-06-12 23:12:32 +02:00
# else:
# shared.config.set('bitmessagesettings', 'maxcores',
# str(self.settingsDialogInstance.ui.comboBoxMaxCores.currentText()))
2013-05-02 17:53:54 +02:00
with open ( shared . appdata + ' keys.dat ' , ' wb ' ) as configfile :
shared . config . write ( configfile )
if ' win32 ' in sys . platform or ' win64 ' in sys . platform :
2013-06-12 23:12:32 +02:00
# Auto-startup for Windows
2013-05-02 17:53:54 +02:00
RUN_PATH = " HKEY_CURRENT_USER \\ Software \\ Microsoft \\ Windows \\ CurrentVersion \\ Run "
self . settings = QSettings ( RUN_PATH , QSettings . NativeFormat )
if shared . config . getboolean ( ' bitmessagesettings ' , ' startonlogon ' ) :
2013-06-12 23:12:32 +02:00
self . settings . setValue ( " PyBitmessage " , sys . argv [ 0 ] )
2013-05-02 17:53:54 +02:00
else :
self . settings . remove ( " PyBitmessage " )
elif ' darwin ' in sys . platform :
2013-06-12 23:12:32 +02:00
# startup for mac
2013-05-02 17:53:54 +02:00
pass
elif ' linux ' in sys . platform :
2013-06-12 23:12:32 +02:00
# startup for linux
2013-05-02 17:53:54 +02:00
pass
2013-06-12 23:12:32 +02:00
if shared . appdata != ' ' and self . settingsDialogInstance . ui . checkBoxPortableMode . isChecked ( ) : # If we are NOT using portable mode now but the user selected that we should...
# Write the keys.dat file to disk in the new location
2013-05-03 21:53:38 +02:00
shared . sqlLock . acquire ( )
shared . sqlSubmitQueue . put ( ' movemessagstoprog ' )
shared . sqlLock . release ( )
2013-05-02 17:53:54 +02:00
with open ( ' keys.dat ' , ' wb ' ) as configfile :
shared . config . write ( configfile )
2013-06-12 23:12:32 +02:00
# Write the knownnodes.dat file to disk in the new location
2013-05-02 17:53:54 +02:00
shared . knownNodesLock . acquire ( )
output = open ( ' knownnodes.dat ' , ' wb ' )
pickle . dump ( shared . knownNodes , output )
output . close ( )
shared . knownNodesLock . release ( )
os . remove ( shared . appdata + ' keys.dat ' )
os . remove ( shared . appdata + ' knownnodes.dat ' )
shared . appdata = ' '
2013-06-12 23:12:32 +02:00
if shared . appdata == ' ' and not self . settingsDialogInstance . ui . checkBoxPortableMode . isChecked ( ) : # If we ARE using portable mode now but the user selected that we shouldn't...
2013-05-02 17:53:54 +02:00
shared . appdata = shared . lookupAppdataFolder ( )
if not os . path . exists ( shared . appdata ) :
os . makedirs ( shared . appdata )
2013-05-03 21:53:38 +02:00
shared . sqlLock . acquire ( )
shared . sqlSubmitQueue . put ( ' movemessagstoappdata ' )
shared . sqlLock . release ( )
2013-06-12 23:12:32 +02:00
# Write the keys.dat file to disk in the new location
2013-05-02 17:53:54 +02:00
with open ( shared . appdata + ' keys.dat ' , ' wb ' ) as configfile :
shared . config . write ( configfile )
2013-06-12 23:12:32 +02:00
# Write the knownnodes.dat file to disk in the new location
2013-05-02 17:53:54 +02:00
shared . knownNodesLock . acquire ( )
output = open ( shared . appdata + ' knownnodes.dat ' , ' wb ' )
pickle . dump ( shared . knownNodes , output )
output . close ( )
shared . knownNodesLock . release ( )
os . remove ( ' keys.dat ' )
os . remove ( ' knownnodes.dat ' )
def click_radioButtonBlacklist ( self ) :
if shared . config . get ( ' bitmessagesettings ' , ' blackwhitelist ' ) == ' white ' :
2013-06-12 23:12:32 +02:00
shared . config . set ( ' bitmessagesettings ' , ' blackwhitelist ' , ' black ' )
2013-05-02 17:53:54 +02:00
with open ( shared . appdata + ' keys.dat ' , ' wb ' ) as configfile :
shared . config . write ( configfile )
2013-06-12 23:12:32 +02:00
# self.ui.tableWidgetBlacklist.clearContents()
2013-05-02 17:53:54 +02:00
self . ui . tableWidgetBlacklist . setRowCount ( 0 )
self . loadBlackWhiteList ( )
2013-06-12 23:12:32 +02:00
self . ui . tabWidget . setTabText ( 6 , ' Blacklist ' )
2013-05-02 17:53:54 +02:00
def click_radioButtonWhitelist ( self ) :
if shared . config . get ( ' bitmessagesettings ' , ' blackwhitelist ' ) == ' black ' :
2013-06-12 23:12:32 +02:00
shared . config . set ( ' bitmessagesettings ' , ' blackwhitelist ' , ' white ' )
2013-05-02 17:53:54 +02:00
with open ( shared . appdata + ' keys.dat ' , ' wb ' ) as configfile :
shared . config . write ( configfile )
2013-06-12 23:12:32 +02:00
# self.ui.tableWidgetBlacklist.clearContents()
2013-05-02 17:53:54 +02:00
self . ui . tableWidgetBlacklist . setRowCount ( 0 )
self . loadBlackWhiteList ( )
2013-06-12 23:12:32 +02:00
self . ui . tabWidget . setTabText ( 6 , ' Whitelist ' )
2013-05-02 17:53:54 +02:00
def click_pushButtonAddBlacklist ( self ) :
self . NewBlacklistDialogInstance = NewSubscriptionDialog ( self )
if self . NewBlacklistDialogInstance . exec_ ( ) :
2013-06-14 12:47:46 +02:00
if self . NewBlacklistDialogInstance . ui . labelSubscriptionAddressCheck . text ( ) == _translate ( " MainWindow " , " Address is valid. " ) :
2013-06-12 23:12:32 +02:00
# First we must check to see if the address is already in the
# address book. The user cannot add it again or else it will
# cause problems when updating and deleting the entry.
2013-05-02 17:53:54 +02:00
shared . sqlLock . acquire ( )
2013-06-12 23:12:32 +02:00
t = ( addBMIfNotPresent ( str (
self . NewBlacklistDialogInstance . ui . lineEditSubscriptionAddress . text ( ) ) ) , )
2013-05-02 17:53:54 +02:00
if shared . config . get ( ' bitmessagesettings ' , ' blackwhitelist ' ) == ' black ' :
2013-06-12 23:12:32 +02:00
shared . sqlSubmitQueue . put (
''' select * from blacklist where address=? ''' )
2013-05-02 17:53:54 +02:00
else :
2013-06-12 23:12:32 +02:00
shared . sqlSubmitQueue . put (
''' select * from whitelist where address=? ''' )
2013-05-02 17:53:54 +02:00
shared . sqlSubmitQueue . put ( t )
queryreturn = shared . sqlReturnQueue . get ( )
shared . sqlLock . release ( )
if queryreturn == [ ] :
self . ui . tableWidgetBlacklist . setSortingEnabled ( False )
self . ui . tableWidgetBlacklist . insertRow ( 0 )
2013-06-12 23:12:32 +02:00
newItem = QtGui . QTableWidgetItem ( unicode (
self . NewBlacklistDialogInstance . ui . newsubscriptionlabel . text ( ) . toUtf8 ( ) , ' utf-8 ' ) )
self . ui . tableWidgetBlacklist . setItem ( 0 , 0 , newItem )
newItem = QtGui . QTableWidgetItem ( addBMIfNotPresent (
self . NewBlacklistDialogInstance . ui . lineEditSubscriptionAddress . text ( ) ) )
newItem . setFlags (
QtCore . Qt . ItemIsSelectable | QtCore . Qt . ItemIsEnabled )
self . ui . tableWidgetBlacklist . setItem ( 0 , 1 , newItem )
2013-05-02 17:53:54 +02:00
self . ui . tableWidgetBlacklist . setSortingEnabled ( True )
2013-06-12 23:12:32 +02:00
t = ( str ( self . NewBlacklistDialogInstance . ui . newsubscriptionlabel . text ( ) . toUtf8 ( ) ) , addBMIfNotPresent (
str ( self . NewBlacklistDialogInstance . ui . lineEditSubscriptionAddress . text ( ) ) ) , True )
2013-05-02 17:53:54 +02:00
shared . sqlLock . acquire ( )
if shared . config . get ( ' bitmessagesettings ' , ' blackwhitelist ' ) == ' black ' :
2013-06-12 23:12:32 +02:00
shared . sqlSubmitQueue . put (
''' INSERT INTO blacklist VALUES (?,?,?) ''' )
2013-05-02 17:53:54 +02:00
else :
2013-06-12 23:12:32 +02:00
shared . sqlSubmitQueue . put (
''' INSERT INTO whitelist VALUES (?,?,?) ''' )
2013-05-02 17:53:54 +02:00
shared . sqlSubmitQueue . put ( t )
queryreturn = shared . sqlReturnQueue . get ( )
shared . sqlSubmitQueue . put ( ' commit ' )
shared . sqlLock . release ( )
else :
2013-06-13 09:59:40 +02:00
self . statusBar ( ) . showMessage ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Error: You cannot add the same address to your list twice. Perhaps rename the existing one if you want. " ) )
2013-05-02 17:53:54 +02:00
else :
2013-06-13 09:59:40 +02:00
self . statusBar ( ) . showMessage ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " The address you entered was invalid. Ignoring it. " ) )
2013-05-02 17:53:54 +02:00
def on_action_SpecialAddressBehaviorDialog ( self ) :
self . dialog = SpecialAddressBehaviorDialog ( self )
# For Modal dialogs
if self . dialog . exec_ ( ) :
currentRow = self . ui . tableWidgetYourIdentities . currentRow ( )
2013-06-12 23:12:32 +02:00
addressAtCurrentRow = str (
self . ui . tableWidgetYourIdentities . item ( currentRow , 1 ) . text ( ) )
2013-05-02 17:53:54 +02:00
if self . dialog . ui . radioButtonBehaveNormalAddress . isChecked ( ) :
2013-06-12 23:12:32 +02:00
shared . config . set ( str (
addressAtCurrentRow ) , ' mailinglist ' , ' false ' )
# Set the color to either black or grey
if shared . config . getboolean ( addressAtCurrentRow , ' enabled ' ) :
self . ui . tableWidgetYourIdentities . item (
currentRow , 1 ) . setTextColor ( QtGui . QColor ( 0 , 0 , 0 ) )
2013-05-02 17:53:54 +02:00
else :
2013-06-12 23:12:32 +02:00
self . ui . tableWidgetYourIdentities . item (
currentRow , 1 ) . setTextColor ( QtGui . QColor ( 128 , 128 , 128 ) )
2013-05-02 17:53:54 +02:00
else :
2013-06-12 23:12:32 +02:00
shared . config . set ( str (
addressAtCurrentRow ) , ' mailinglist ' , ' true ' )
shared . config . set ( str ( addressAtCurrentRow ) , ' mailinglistname ' , str (
self . dialog . ui . lineEditMailingListName . text ( ) . toUtf8 ( ) ) )
self . ui . tableWidgetYourIdentities . item ( currentRow , 1 ) . setTextColor ( QtGui . QColor ( 137 , 04 , 177 ) )
2013-05-02 17:53:54 +02:00
with open ( shared . appdata + ' keys.dat ' , ' wb ' ) as configfile :
shared . config . write ( configfile )
self . rerenderInboxToLabels ( )
def click_NewAddressDialog ( self ) :
self . dialog = NewAddressDialog ( self )
# For Modal dialogs
if self . dialog . exec_ ( ) :
2013-06-12 23:12:32 +02:00
# self.dialog.ui.buttonBox.enabled = False
2013-05-02 17:53:54 +02:00
if self . dialog . ui . radioButtonRandomAddress . isChecked ( ) :
if self . dialog . ui . radioButtonMostAvailable . isChecked ( ) :
streamNumberForAddress = 1
else :
2013-06-12 23:12:32 +02:00
# User selected 'Use the same stream as an existing
# address.'
streamNumberForAddress = addressStream (
self . dialog . ui . comboBoxExisting . currentText ( ) )
# self.addressGenerator = addressGenerator()
# self.addressGenerator.setup(3,streamNumberForAddress,str(self.dialog.ui.newaddresslabel.text().toUtf8()),1,"",self.dialog.ui.checkBoxEighteenByteRipe.isChecked())
# QtCore.QObject.connect(self.addressGenerator, SIGNAL("writeNewAddressToTable(PyQt_PyObject,PyQt_PyObject,PyQt_PyObject)"), self.writeNewAddressToTable)
# QtCore.QObject.connect(self.addressGenerator, QtCore.SIGNAL("updateStatusBar(PyQt_PyObject)"), self.updateStatusBar)
# self.addressGenerator.start()
shared . addressGeneratorQueue . put ( ( ' createRandomAddress ' , 3 , streamNumberForAddress , str (
self . dialog . ui . newaddresslabel . text ( ) . toUtf8 ( ) ) , 1 , " " , self . dialog . ui . checkBoxEighteenByteRipe . isChecked ( ) ) )
2013-05-02 17:53:54 +02:00
else :
if self . dialog . ui . lineEditPassphrase . text ( ) != self . dialog . ui . lineEditPassphraseAgain . text ( ) :
2013-06-13 09:59:40 +02:00
QMessageBox . about ( self , _translate ( " MainWindow " , " Passphrase mismatch " ) , _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " The passphrase you entered twice doesn \' t match. Try again. " ) )
2013-05-02 17:53:54 +02:00
elif self . dialog . ui . lineEditPassphrase . text ( ) == " " :
2013-06-13 09:59:40 +02:00
QMessageBox . about ( self , _translate (
" MainWindow " , " Choose a passphrase " ) , _translate ( " MainWindow " , " You really do need a passphrase. " ) )
2013-05-02 17:53:54 +02:00
else :
2013-06-12 23:12:32 +02:00
streamNumberForAddress = 1 # this will eventually have to be replaced by logic to determine the most available stream number.
# self.addressGenerator = addressGenerator()
# self.addressGenerator.setup(3,streamNumberForAddress,"unused address",self.dialog.ui.spinBoxNumberOfAddressesToMake.value(),self.dialog.ui.lineEditPassphrase.text().toUtf8(),self.dialog.ui.checkBoxEighteenByteRipe.isChecked())
# QtCore.QObject.connect(self.addressGenerator, SIGNAL("writeNewAddressToTable(PyQt_PyObject,PyQt_PyObject,PyQt_PyObject)"), self.writeNewAddressToTable)
# QtCore.QObject.connect(self.addressGenerator, QtCore.SIGNAL("updateStatusBar(PyQt_PyObject)"), self.updateStatusBar)
# self.addressGenerator.start()
shared . addressGeneratorQueue . put ( ( ' createDeterministicAddresses ' , 3 , streamNumberForAddress , " unused deterministic address " , self . dialog . ui . spinBoxNumberOfAddressesToMake . value (
) , self . dialog . ui . lineEditPassphrase . text ( ) . toUtf8 ( ) , self . dialog . ui . checkBoxEighteenByteRipe . isChecked ( ) ) )
2013-05-02 17:53:54 +02:00
else :
print ' new address dialog box rejected '
2013-05-13 15:02:10 +02:00
# Quit selected from menu or application indicator
def quit ( self ) :
2013-05-02 17:53:54 +02:00
''' quit_msg = " Are you sure you want to exit Bitmessage? "
reply = QtGui . QMessageBox . question ( self , ' Message ' ,
quit_msg , QtGui . QMessageBox . Yes , QtGui . QMessageBox . No )
2013-05-13 15:02:10 +02:00
if reply is QtGui . QMessageBox . No :
return
'''
2013-05-02 17:53:54 +02:00
shared . doCleanShutdown ( )
2013-05-08 22:42:28 +02:00
self . tray . hide ( )
2013-05-11 19:18:43 +02:00
# unregister the messaging system
if self . mmapp is not None :
self . mmapp . unregister ( )
2013-06-13 09:59:40 +02:00
self . statusBar ( ) . showMessage ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " All done. Closing user interface... " ) )
2013-05-02 17:53:54 +02:00
os . _exit ( 0 )
2013-05-13 15:02:10 +02:00
# window close event
def closeEvent ( self , event ) :
self . appIndicatorHide ( )
2013-05-14 17:44:51 +02:00
minimizeonclose = False
2013-05-13 15:02:10 +02:00
try :
2013-06-12 23:12:32 +02:00
minimizeonclose = shared . config . getboolean (
' bitmessagesettings ' , ' minimizeonclose ' )
2013-05-13 15:02:10 +02:00
except Exception :
2013-05-14 17:44:51 +02:00
pass
2013-05-13 15:02:10 +02:00
if minimizeonclose :
# minimize the application
event . ignore ( )
else :
# quit the application
event . accept ( )
self . quit ( )
2013-05-02 17:53:54 +02:00
def on_action_InboxMessageForceHtml ( self ) :
currentInboxRow = self . ui . tableWidgetInbox . currentRow ( )
2013-06-12 23:12:32 +02:00
lines = self . ui . tableWidgetInbox . item (
currentInboxRow , 2 ) . data ( Qt . UserRole ) . toPyObject ( ) . split ( ' \n ' )
2013-05-02 17:53:54 +02:00
for i in xrange ( len ( lines ) ) :
if lines [ i ] . contains ( ' Message ostensibly from ' ) :
2013-06-12 23:12:32 +02:00
lines [ i ] = ' <p style= " font-size: 12px; color: grey; " > %s </span></p> ' % (
lines [ i ] )
2013-05-02 17:53:54 +02:00
elif lines [ i ] == ' ------------------------------------------------------ ' :
lines [ i ] = ' <hr> '
content = ' '
for i in xrange ( len ( lines ) ) :
content + = lines [ i ]
content = content . replace ( ' \n \n ' , ' <br><br> ' )
self . ui . textEditInboxMessage . setHtml ( QtCore . QString ( content ) )
def on_action_InboxReply ( self ) :
currentInboxRow = self . ui . tableWidgetInbox . currentRow ( )
2013-06-12 23:12:32 +02:00
toAddressAtCurrentInboxRow = str ( self . ui . tableWidgetInbox . item (
currentInboxRow , 0 ) . data ( Qt . UserRole ) . toPyObject ( ) )
fromAddressAtCurrentInboxRow = str ( self . ui . tableWidgetInbox . item (
currentInboxRow , 1 ) . data ( Qt . UserRole ) . toPyObject ( ) )
2013-05-14 17:06:01 +02:00
if toAddressAtCurrentInboxRow == self . str_broadcast_subscribers :
2013-05-02 17:53:54 +02:00
self . ui . labelFrom . setText ( ' ' )
2013-06-10 15:40:51 +02:00
elif not shared . config . has_section ( toAddressAtCurrentInboxRow ) :
2013-06-13 09:59:40 +02:00
QtGui . QMessageBox . information ( self , _translate ( " MainWindow " , " Address is gone " ) , _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Bitmessage cannot find your address % 1. Perhaps you removed it? " ) . arg ( toAddressAtCurrentInboxRow ) , QMessageBox . Ok )
2013-06-10 15:40:51 +02:00
self . ui . labelFrom . setText ( ' ' )
2013-06-12 23:12:32 +02:00
elif not shared . config . getboolean ( toAddressAtCurrentInboxRow , ' enabled ' ) :
2013-06-13 09:59:40 +02:00
QtGui . QMessageBox . information ( self , _translate ( " MainWindow " , " Address disabled " ) , _translate (
2013-06-12 23:12:32 +02:00
" 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 )
2013-06-10 15:40:51 +02:00
self . ui . labelFrom . setText ( ' ' )
2013-05-02 17:53:54 +02:00
else :
self . ui . labelFrom . setText ( toAddressAtCurrentInboxRow )
self . ui . lineEditTo . setText ( str ( fromAddressAtCurrentInboxRow ) )
self . ui . comboBoxSendFrom . setCurrentIndex ( 0 )
2013-06-12 23:12:32 +02:00
# self.ui.comboBoxSendFrom.setEditText(str(self.ui.tableWidgetInbox.item(currentInboxRow,0).text))
self . ui . textEditMessage . setText ( ' \n \n ------------------------------------------------------ \n ' + self . ui . tableWidgetInbox . item (
currentInboxRow , 2 ) . data ( Qt . UserRole ) . toPyObject ( ) )
if self . ui . tableWidgetInbox . item ( currentInboxRow , 2 ) . text ( ) [ 0 : 3 ] == ' Re: ' :
self . ui . lineEditSubject . setText (
self . ui . tableWidgetInbox . item ( currentInboxRow , 2 ) . text ( ) )
2013-05-02 17:53:54 +02:00
else :
2013-06-12 23:12:32 +02:00
self . ui . lineEditSubject . setText (
' Re: ' + self . ui . tableWidgetInbox . item ( currentInboxRow , 2 ) . text ( ) )
2013-05-02 17:53:54 +02:00
self . ui . radioButtonSpecific . setChecked ( True )
self . ui . tabWidget . setCurrentIndex ( 1 )
def on_action_InboxAddSenderToAddressBook ( self ) :
currentInboxRow = self . ui . tableWidgetInbox . currentRow ( )
2013-06-12 23:12:32 +02:00
# self.ui.tableWidgetInbox.item(currentRow,1).data(Qt.UserRole).toPyObject()
addressAtCurrentInboxRow = str ( self . ui . tableWidgetInbox . item (
currentInboxRow , 1 ) . data ( Qt . UserRole ) . toPyObject ( ) )
# Let's make sure that it isn't already in the address book
2013-05-02 17:53:54 +02:00
shared . sqlLock . acquire ( )
t = ( addressAtCurrentInboxRow , )
2013-06-12 23:12:32 +02:00
shared . sqlSubmitQueue . put (
''' select * from addressbook where address=? ''' )
2013-05-02 17:53:54 +02:00
shared . sqlSubmitQueue . put ( t )
queryreturn = shared . sqlReturnQueue . get ( )
shared . sqlLock . release ( )
if queryreturn == [ ] :
self . ui . tableWidgetAddressBook . insertRow ( 0 )
2013-06-12 23:12:32 +02:00
newItem = QtGui . QTableWidgetItem (
' --New entry. Change label in Address Book.-- ' )
self . ui . tableWidgetAddressBook . setItem ( 0 , 0 , newItem )
newItem = QtGui . QTableWidgetItem ( addressAtCurrentInboxRow )
newItem . setFlags (
QtCore . Qt . ItemIsSelectable | QtCore . Qt . ItemIsEnabled )
self . ui . tableWidgetAddressBook . setItem ( 0 , 1 , newItem )
t = ( ' --New entry. Change label in Address Book.-- ' ,
addressAtCurrentInboxRow )
2013-05-02 17:53:54 +02:00
shared . sqlLock . acquire ( )
2013-06-12 23:12:32 +02:00
shared . sqlSubmitQueue . put (
''' INSERT INTO addressbook VALUES (?,?) ''' )
2013-05-02 17:53:54 +02:00
shared . sqlSubmitQueue . put ( t )
queryreturn = shared . sqlReturnQueue . get ( )
shared . sqlSubmitQueue . put ( ' commit ' )
shared . sqlLock . release ( )
self . ui . tabWidget . setCurrentIndex ( 5 )
2013-06-12 23:12:32 +02:00
self . ui . tableWidgetAddressBook . setCurrentCell ( 0 , 0 )
2013-06-13 09:59:40 +02:00
self . statusBar ( ) . showMessage ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Entry added to the Address Book. Edit the label to your liking. " ) )
2013-05-02 17:53:54 +02:00
else :
2013-06-13 09:59:40 +02:00
self . statusBar ( ) . showMessage ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Error: You cannot add the same address to your address book twice. Try renaming the existing one if you want. " ) )
2013-05-02 17:53:54 +02:00
2013-06-12 23:12:32 +02:00
# Send item on the Inbox tab to trash
2013-05-02 17:53:54 +02:00
def on_action_InboxTrash ( self ) :
while self . ui . tableWidgetInbox . selectedIndexes ( ) != [ ] :
currentRow = self . ui . tableWidgetInbox . selectedIndexes ( ) [ 0 ] . row ( )
2013-06-12 23:12:32 +02:00
inventoryHashToTrash = str ( self . ui . tableWidgetInbox . item (
currentRow , 3 ) . data ( Qt . UserRole ) . toPyObject ( ) )
2013-05-02 17:53:54 +02:00
t = ( inventoryHashToTrash , )
shared . sqlLock . acquire ( )
2013-06-12 23:12:32 +02:00
shared . sqlSubmitQueue . put (
''' UPDATE inbox SET folder= ' trash ' WHERE msgid=? ''' )
2013-05-02 17:53:54 +02:00
shared . sqlSubmitQueue . put ( t )
shared . sqlReturnQueue . get ( )
shared . sqlLock . release ( )
self . ui . textEditInboxMessage . setText ( " " )
self . ui . tableWidgetInbox . removeRow ( currentRow )
2013-06-13 09:59:40 +02:00
self . statusBar ( ) . showMessage ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Moved items to trash. There is no user interface to view your trash, but it is still on disk if you are desperate to get it back. " ) )
2013-05-16 18:41:04 +02:00
shared . sqlLock . acquire ( )
2013-05-02 17:53:54 +02:00
shared . sqlSubmitQueue . put ( ' commit ' )
2013-05-16 18:41:04 +02:00
shared . sqlLock . release ( )
2013-05-02 17:53:54 +02:00
if currentRow == 0 :
self . ui . tableWidgetInbox . selectRow ( currentRow )
else :
2013-06-12 23:12:32 +02:00
self . ui . tableWidgetInbox . selectRow ( currentRow - 1 )
2013-05-02 17:53:54 +02:00
2013-06-17 00:28:18 +02:00
def on_action_InboxSaveMessageAs ( self ) :
currentInboxRow = self . ui . tableWidgetInbox . currentRow ( )
2013-06-19 22:49:31 +02:00
try :
subjectAtCurrentInboxRow = str ( self . ui . tableWidgetInbox . item ( currentInboxRow , 2 ) . text ( ) )
except :
subjectAtCurrentInboxRow = ' '
2013-06-17 00:28:18 +02:00
defaultFilename = " " . join ( x for x in subjectAtCurrentInboxRow if x . isalnum ( ) ) + ' .txt '
data = self . ui . tableWidgetInbox . item ( currentInboxRow , 2 ) . data ( Qt . UserRole ) . toPyObject ( )
2013-06-19 22:49:31 +02:00
filename = QFileDialog . getSaveFileName ( self , _translate ( " MainWindow " , " Save As... " ) , defaultFilename , " Text files (*.txt);;All files (*.*) " )
2013-06-17 00:28:18 +02:00
if filename == ' ' :
return
try :
f = open ( filename , ' w ' )
2013-06-17 00:38:27 +02:00
f . write ( self . ui . tableWidgetInbox . item ( currentInboxRow , 2 ) . data ( Qt . UserRole ) . toPyObject ( ) )
2013-06-17 00:28:18 +02:00
f . close ( )
except Exception , e :
2013-06-19 22:49:31 +02:00
sys . stderr . write ( ' Write error: ' + e )
self . statusBar ( ) . showMessage ( _translate ( " MainWindow " , " Write error. " ) )
2013-06-17 00:28:18 +02:00
2013-06-12 23:12:32 +02:00
# Send item on the Sent tab to trash
2013-05-02 17:53:54 +02:00
def on_action_SentTrash ( self ) :
while self . ui . tableWidgetSent . selectedIndexes ( ) != [ ] :
currentRow = self . ui . tableWidgetSent . selectedIndexes ( ) [ 0 ] . row ( )
2013-06-12 23:12:32 +02:00
ackdataToTrash = str ( self . ui . tableWidgetSent . item (
currentRow , 3 ) . data ( Qt . UserRole ) . toPyObject ( ) )
2013-05-02 17:53:54 +02:00
t = ( ackdataToTrash , )
shared . sqlLock . acquire ( )
2013-06-12 23:12:32 +02:00
shared . sqlSubmitQueue . put (
''' UPDATE sent SET folder= ' trash ' WHERE ackdata=? ''' )
2013-05-02 17:53:54 +02:00
shared . sqlSubmitQueue . put ( t )
shared . sqlReturnQueue . get ( )
shared . sqlLock . release ( )
self . ui . textEditSentMessage . setPlainText ( " " )
self . ui . tableWidgetSent . removeRow ( currentRow )
2013-06-13 09:59:40 +02:00
self . statusBar ( ) . showMessage ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Moved items to trash. There is no user interface to view your trash, but it is still on disk if you are desperate to get it back. " ) )
2013-05-16 18:41:04 +02:00
shared . sqlLock . acquire ( )
2013-05-02 17:53:54 +02:00
shared . sqlSubmitQueue . put ( ' commit ' )
2013-05-16 18:41:04 +02:00
shared . sqlLock . release ( )
2013-05-02 17:53:54 +02:00
if currentRow == 0 :
self . ui . tableWidgetSent . selectRow ( currentRow )
else :
2013-06-12 23:12:32 +02:00
self . ui . tableWidgetSent . selectRow ( currentRow - 1 )
2013-05-02 17:53:54 +02:00
2013-06-11 00:53:15 +02:00
def on_action_ForceSend ( self ) :
currentRow = self . ui . tableWidgetSent . currentRow ( )
2013-06-12 23:12:32 +02:00
addressAtCurrentRow = str ( self . ui . tableWidgetSent . item (
currentRow , 0 ) . data ( Qt . UserRole ) . toPyObject ( ) )
2013-06-11 00:53:15 +02:00
toRipe = decodeAddress ( addressAtCurrentRow ) [ 3 ]
t = ( toRipe , )
shared . sqlLock . acquire ( )
2013-06-12 23:12:32 +02:00
shared . sqlSubmitQueue . put (
''' UPDATE sent SET status= ' forcepow ' WHERE toripe=? AND status= ' toodifficult ' and folder= ' sent ' ''' )
2013-06-11 00:53:15 +02:00
shared . sqlSubmitQueue . put ( t )
shared . sqlReturnQueue . get ( )
shared . sqlSubmitQueue . put ( ' commit ' )
2013-06-12 23:12:32 +02:00
shared . sqlSubmitQueue . put (
''' select ackdata FROM sent WHERE status= ' forcepow ' ''' )
2013-06-11 00:53:15 +02:00
shared . sqlSubmitQueue . put ( ' ' )
queryreturn = shared . sqlReturnQueue . get ( )
shared . sqlLock . release ( )
for row in queryreturn :
ackdata , = row
2013-06-12 23:12:32 +02:00
shared . UISignalQueue . put ( ( ' updateSentItemStatusByAckdata ' , (
ackdata , ' Overriding maximum-difficulty setting. Work queued. ' ) ) )
shared . workerQueue . put ( ( ' sendmessage ' , ' ' ) )
2013-06-11 00:53:15 +02:00
2013-05-02 17:53:54 +02:00
def on_action_SentClipboard ( self ) :
currentRow = self . ui . tableWidgetSent . currentRow ( )
2013-06-12 23:12:32 +02:00
addressAtCurrentRow = str ( self . ui . tableWidgetSent . item (
currentRow , 0 ) . data ( Qt . UserRole ) . toPyObject ( ) )
2013-05-02 17:53:54 +02:00
clipboard = QtGui . QApplication . clipboard ( )
clipboard . setText ( str ( addressAtCurrentRow ) )
2013-06-12 23:12:32 +02:00
# Group of functions for the Address Book dialog box
2013-05-02 17:53:54 +02:00
def on_action_AddressBookNew ( self ) :
self . click_pushButtonAddAddressBook ( )
2013-06-12 23:12:32 +02:00
2013-05-02 17:53:54 +02:00
def on_action_AddressBookDelete ( self ) :
while self . ui . tableWidgetAddressBook . selectedIndexes ( ) != [ ] :
2013-06-12 23:12:32 +02:00
currentRow = self . ui . tableWidgetAddressBook . selectedIndexes ( ) [
0 ] . row ( )
labelAtCurrentRow = self . ui . tableWidgetAddressBook . item (
currentRow , 0 ) . text ( ) . toUtf8 ( )
addressAtCurrentRow = self . ui . tableWidgetAddressBook . item (
currentRow , 1 ) . text ( )
t = ( str ( labelAtCurrentRow ) , str ( addressAtCurrentRow ) )
2013-05-02 17:53:54 +02:00
shared . sqlLock . acquire ( )
2013-06-12 23:12:32 +02:00
shared . sqlSubmitQueue . put (
''' DELETE FROM addressbook WHERE label=? AND address=? ''' )
2013-05-02 17:53:54 +02:00
shared . sqlSubmitQueue . put ( t )
queryreturn = shared . sqlReturnQueue . get ( )
shared . sqlSubmitQueue . put ( ' commit ' )
shared . sqlLock . release ( )
self . ui . tableWidgetAddressBook . removeRow ( currentRow )
self . rerenderInboxFromLabels ( )
self . rerenderSentToLabels ( )
2013-06-12 23:12:32 +02:00
2013-05-02 17:53:54 +02:00
def on_action_AddressBookClipboard ( self ) :
fullStringOfAddresses = ' '
listOfSelectedRows = { }
for i in range ( len ( self . ui . tableWidgetAddressBook . selectedIndexes ( ) ) ) :
2013-06-12 23:12:32 +02:00
listOfSelectedRows [
self . ui . tableWidgetAddressBook . selectedIndexes ( ) [ i ] . row ( ) ] = 0
2013-05-02 17:53:54 +02:00
for currentRow in listOfSelectedRows :
2013-06-12 23:12:32 +02:00
addressAtCurrentRow = self . ui . tableWidgetAddressBook . item (
currentRow , 1 ) . text ( )
2013-05-02 17:53:54 +02:00
if fullStringOfAddresses == ' ' :
fullStringOfAddresses = addressAtCurrentRow
else :
2013-06-12 23:12:32 +02:00
fullStringOfAddresses + = ' , ' + str ( addressAtCurrentRow )
2013-05-02 17:53:54 +02:00
clipboard = QtGui . QApplication . clipboard ( )
clipboard . setText ( fullStringOfAddresses )
2013-06-12 23:12:32 +02:00
2013-05-02 17:53:54 +02:00
def on_action_AddressBookSend ( self ) :
listOfSelectedRows = { }
for i in range ( len ( self . ui . tableWidgetAddressBook . selectedIndexes ( ) ) ) :
2013-06-12 23:12:32 +02:00
listOfSelectedRows [
self . ui . tableWidgetAddressBook . selectedIndexes ( ) [ i ] . row ( ) ] = 0
2013-05-02 17:53:54 +02:00
for currentRow in listOfSelectedRows :
2013-06-12 23:12:32 +02:00
addressAtCurrentRow = self . ui . tableWidgetAddressBook . item (
currentRow , 1 ) . text ( )
2013-05-02 17:53:54 +02:00
if self . ui . lineEditTo . text ( ) == ' ' :
self . ui . lineEditTo . setText ( str ( addressAtCurrentRow ) )
else :
2013-06-12 23:12:32 +02:00
self . ui . lineEditTo . setText ( str (
self . ui . lineEditTo . text ( ) ) + ' ; ' + str ( addressAtCurrentRow ) )
2013-05-02 17:53:54 +02:00
if listOfSelectedRows == { } :
2013-06-13 09:59:40 +02:00
self . statusBar ( ) . showMessage ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " No addresses selected. " ) )
2013-05-02 17:53:54 +02:00
else :
self . statusBar ( ) . showMessage ( ' ' )
self . ui . tabWidget . setCurrentIndex ( 1 )
2013-06-14 03:55:38 +02:00
def on_action_AddressBookSubscribe ( self ) :
listOfSelectedRows = { }
for i in range ( len ( self . ui . tableWidgetAddressBook . selectedIndexes ( ) ) ) :
listOfSelectedRows [ self . ui . tableWidgetAddressBook . selectedIndexes ( ) [ i ] . row ( ) ] = 0
for currentRow in listOfSelectedRows :
2013-06-14 04:28:33 +02:00
addressAtCurrentRow = str ( self . ui . tableWidgetAddressBook . item ( currentRow , 1 ) . text ( ) )
2013-06-14 03:55:38 +02:00
# Then subscribe to it... provided it's not already in the address book
if shared . isAddressInMySubscriptionsList ( addressAtCurrentRow ) :
2013-06-14 04:27:52 +02:00
self . statusBar ( ) . showMessage ( QtGui . QApplication . translate ( " MainWindow " , " Error: You cannot add the same address to your subsciptions twice. Perhaps rename the existing one if you want. " ) )
continue
2013-06-19 19:10:43 +02:00
labelAtCurrentRow = self . ui . tableWidgetAddressBook . item ( currentRow , 0 ) . text ( ) . toUtf8 ( )
2013-06-14 03:55:38 +02:00
self . addSubscription ( labelAtCurrentRow , addressAtCurrentRow )
2013-06-19 18:19:07 +02:00
self . ui . tabWidget . setCurrentIndex ( 4 )
2013-05-02 17:53:54 +02:00
2013-06-12 23:12:32 +02:00
def on_context_menuAddressBook ( self , point ) :
self . popMenuAddressBook . exec_ (
self . ui . tableWidgetAddressBook . mapToGlobal ( point ) )
2013-05-02 17:53:54 +02:00
2013-06-12 23:12:32 +02:00
# Group of functions for the Subscriptions dialog box
2013-05-02 17:53:54 +02:00
def on_action_SubscriptionsNew ( self ) :
self . click_pushButtonAddSubscription ( )
2013-06-19 18:19:07 +02:00
2013-05-02 17:53:54 +02:00
def on_action_SubscriptionsDelete ( self ) :
print ' clicked Delete '
currentRow = self . ui . tableWidgetSubscriptions . currentRow ( )
2013-06-12 23:12:32 +02:00
labelAtCurrentRow = self . ui . tableWidgetSubscriptions . item (
currentRow , 0 ) . text ( ) . toUtf8 ( )
addressAtCurrentRow = self . ui . tableWidgetSubscriptions . item (
currentRow , 1 ) . text ( )
t = ( str ( labelAtCurrentRow ) , str ( addressAtCurrentRow ) )
2013-05-02 17:53:54 +02:00
shared . sqlLock . acquire ( )
2013-06-12 23:12:32 +02:00
shared . sqlSubmitQueue . put (
''' DELETE FROM subscriptions WHERE label=? AND address=? ''' )
2013-05-02 17:53:54 +02:00
shared . sqlSubmitQueue . put ( t )
shared . sqlReturnQueue . get ( )
shared . sqlSubmitQueue . put ( ' commit ' )
shared . sqlLock . release ( )
self . ui . tableWidgetSubscriptions . removeRow ( currentRow )
self . rerenderInboxFromLabels ( )
shared . reloadBroadcastSendersForWhichImWatching ( )
2013-06-12 23:12:32 +02:00
2013-05-02 17:53:54 +02:00
def on_action_SubscriptionsClipboard ( self ) :
currentRow = self . ui . tableWidgetSubscriptions . currentRow ( )
2013-06-12 23:12:32 +02:00
addressAtCurrentRow = self . ui . tableWidgetSubscriptions . item (
currentRow , 1 ) . text ( )
2013-05-02 17:53:54 +02:00
clipboard = QtGui . QApplication . clipboard ( )
clipboard . setText ( str ( addressAtCurrentRow ) )
2013-06-12 23:12:32 +02:00
2013-05-02 17:53:54 +02:00
def on_action_SubscriptionsEnable ( self ) :
currentRow = self . ui . tableWidgetSubscriptions . currentRow ( )
2013-06-12 23:12:32 +02:00
labelAtCurrentRow = self . ui . tableWidgetSubscriptions . item (
currentRow , 0 ) . text ( ) . toUtf8 ( )
addressAtCurrentRow = self . ui . tableWidgetSubscriptions . item (
currentRow , 1 ) . text ( )
t = ( str ( labelAtCurrentRow ) , str ( addressAtCurrentRow ) )
2013-05-02 17:53:54 +02:00
shared . sqlLock . acquire ( )
2013-06-12 23:12:32 +02:00
shared . sqlSubmitQueue . put (
''' update subscriptions set enabled=1 WHERE label=? AND address=? ''' )
2013-05-02 17:53:54 +02:00
shared . sqlSubmitQueue . put ( t )
shared . sqlReturnQueue . get ( )
shared . sqlSubmitQueue . put ( ' commit ' )
shared . sqlLock . release ( )
2013-06-12 23:12:32 +02:00
self . ui . tableWidgetSubscriptions . item (
currentRow , 0 ) . setTextColor ( QtGui . QColor ( 0 , 0 , 0 ) )
self . ui . tableWidgetSubscriptions . item (
currentRow , 1 ) . setTextColor ( QtGui . QColor ( 0 , 0 , 0 ) )
2013-05-02 17:53:54 +02:00
shared . reloadBroadcastSendersForWhichImWatching ( )
2013-06-12 23:12:32 +02:00
2013-05-02 17:53:54 +02:00
def on_action_SubscriptionsDisable ( self ) :
currentRow = self . ui . tableWidgetSubscriptions . currentRow ( )
2013-06-12 23:12:32 +02:00
labelAtCurrentRow = self . ui . tableWidgetSubscriptions . item (
currentRow , 0 ) . text ( ) . toUtf8 ( )
addressAtCurrentRow = self . ui . tableWidgetSubscriptions . item (
currentRow , 1 ) . text ( )
t = ( str ( labelAtCurrentRow ) , str ( addressAtCurrentRow ) )
2013-05-02 17:53:54 +02:00
shared . sqlLock . acquire ( )
2013-06-12 23:12:32 +02:00
shared . sqlSubmitQueue . put (
''' update subscriptions set enabled=0 WHERE label=? AND address=? ''' )
2013-05-02 17:53:54 +02:00
shared . sqlSubmitQueue . put ( t )
shared . sqlReturnQueue . get ( )
shared . sqlSubmitQueue . put ( ' commit ' )
shared . sqlLock . release ( )
2013-06-12 23:12:32 +02:00
self . ui . tableWidgetSubscriptions . item (
currentRow , 0 ) . setTextColor ( QtGui . QColor ( 128 , 128 , 128 ) )
self . ui . tableWidgetSubscriptions . item (
currentRow , 1 ) . setTextColor ( QtGui . QColor ( 128 , 128 , 128 ) )
2013-05-02 17:53:54 +02:00
shared . reloadBroadcastSendersForWhichImWatching ( )
2013-06-12 23:12:32 +02:00
2013-05-02 17:53:54 +02:00
def on_context_menuSubscriptions ( self , point ) :
2013-06-12 23:12:32 +02:00
self . popMenuSubscriptions . exec_ (
self . ui . tableWidgetSubscriptions . mapToGlobal ( point ) )
2013-05-02 17:53:54 +02:00
2013-06-12 23:12:32 +02:00
# Group of functions for the Blacklist dialog box
2013-05-02 17:53:54 +02:00
def on_action_BlacklistNew ( self ) :
self . click_pushButtonAddBlacklist ( )
2013-06-12 23:12:32 +02:00
2013-05-02 17:53:54 +02:00
def on_action_BlacklistDelete ( self ) :
currentRow = self . ui . tableWidgetBlacklist . currentRow ( )
2013-06-12 23:12:32 +02:00
labelAtCurrentRow = self . ui . tableWidgetBlacklist . item (
currentRow , 0 ) . text ( ) . toUtf8 ( )
addressAtCurrentRow = self . ui . tableWidgetBlacklist . item (
currentRow , 1 ) . text ( )
t = ( str ( labelAtCurrentRow ) , str ( addressAtCurrentRow ) )
2013-05-02 17:53:54 +02:00
shared . sqlLock . acquire ( )
if shared . config . get ( ' bitmessagesettings ' , ' blackwhitelist ' ) == ' black ' :
2013-06-12 23:12:32 +02:00
shared . sqlSubmitQueue . put (
''' DELETE FROM blacklist WHERE label=? AND address=? ''' )
2013-05-02 17:53:54 +02:00
shared . sqlSubmitQueue . put ( t )
shared . sqlReturnQueue . get ( )
else :
2013-06-12 23:12:32 +02:00
shared . sqlSubmitQueue . put (
''' DELETE FROM whitelist WHERE label=? AND address=? ''' )
2013-05-02 17:53:54 +02:00
shared . sqlSubmitQueue . put ( t )
shared . sqlReturnQueue . get ( )
shared . sqlSubmitQueue . put ( ' commit ' )
shared . sqlLock . release ( )
self . ui . tableWidgetBlacklist . removeRow ( currentRow )
2013-06-12 23:12:32 +02:00
2013-05-02 17:53:54 +02:00
def on_action_BlacklistClipboard ( self ) :
currentRow = self . ui . tableWidgetBlacklist . currentRow ( )
2013-06-12 23:12:32 +02:00
addressAtCurrentRow = self . ui . tableWidgetBlacklist . item (
currentRow , 1 ) . text ( )
2013-05-02 17:53:54 +02:00
clipboard = QtGui . QApplication . clipboard ( )
clipboard . setText ( str ( addressAtCurrentRow ) )
2013-06-12 23:12:32 +02:00
2013-05-02 17:53:54 +02:00
def on_context_menuBlacklist ( self , point ) :
2013-06-12 23:12:32 +02:00
self . popMenuBlacklist . exec_ (
self . ui . tableWidgetBlacklist . mapToGlobal ( point ) )
2013-05-02 17:53:54 +02:00
def on_action_BlacklistEnable ( self ) :
currentRow = self . ui . tableWidgetBlacklist . currentRow ( )
2013-06-12 23:12:32 +02:00
addressAtCurrentRow = self . ui . tableWidgetBlacklist . item (
currentRow , 1 ) . text ( )
self . ui . tableWidgetBlacklist . item (
currentRow , 0 ) . setTextColor ( QtGui . QColor ( 0 , 0 , 0 ) )
self . ui . tableWidgetBlacklist . item (
currentRow , 1 ) . setTextColor ( QtGui . QColor ( 0 , 0 , 0 ) )
2013-05-02 17:53:54 +02:00
t = ( str ( addressAtCurrentRow ) , )
shared . sqlLock . acquire ( )
if shared . config . get ( ' bitmessagesettings ' , ' blackwhitelist ' ) == ' black ' :
2013-06-12 23:12:32 +02:00
shared . sqlSubmitQueue . put (
''' UPDATE blacklist SET enabled=1 WHERE address=? ''' )
2013-05-02 17:53:54 +02:00
shared . sqlSubmitQueue . put ( t )
shared . sqlReturnQueue . get ( )
else :
2013-06-12 23:12:32 +02:00
shared . sqlSubmitQueue . put (
''' UPDATE whitelist SET enabled=1 WHERE address=? ''' )
2013-05-02 17:53:54 +02:00
shared . sqlSubmitQueue . put ( t )
shared . sqlReturnQueue . get ( )
shared . sqlSubmitQueue . put ( ' commit ' )
shared . sqlLock . release ( )
2013-06-12 23:12:32 +02:00
2013-05-02 17:53:54 +02:00
def on_action_BlacklistDisable ( self ) :
currentRow = self . ui . tableWidgetBlacklist . currentRow ( )
2013-06-12 23:12:32 +02:00
addressAtCurrentRow = self . ui . tableWidgetBlacklist . item (
currentRow , 1 ) . text ( )
self . ui . tableWidgetBlacklist . item (
currentRow , 0 ) . setTextColor ( QtGui . QColor ( 128 , 128 , 128 ) )
self . ui . tableWidgetBlacklist . item (
currentRow , 1 ) . setTextColor ( QtGui . QColor ( 128 , 128 , 128 ) )
2013-05-02 17:53:54 +02:00
t = ( str ( addressAtCurrentRow ) , )
shared . sqlLock . acquire ( )
if shared . config . get ( ' bitmessagesettings ' , ' blackwhitelist ' ) == ' black ' :
2013-06-12 23:12:32 +02:00
shared . sqlSubmitQueue . put (
''' UPDATE blacklist SET enabled=0 WHERE address=? ''' )
2013-05-02 17:53:54 +02:00
shared . sqlSubmitQueue . put ( t )
shared . sqlReturnQueue . get ( )
else :
2013-06-12 23:12:32 +02:00
shared . sqlSubmitQueue . put (
''' UPDATE whitelist SET enabled=0 WHERE address=? ''' )
2013-05-02 17:53:54 +02:00
shared . sqlSubmitQueue . put ( t )
shared . sqlReturnQueue . get ( )
shared . sqlSubmitQueue . put ( ' commit ' )
shared . sqlLock . release ( )
2013-06-12 23:12:32 +02:00
# Group of functions for the Your Identities dialog box
2013-05-02 17:53:54 +02:00
def on_action_YourIdentitiesNew ( self ) :
self . click_NewAddressDialog ( )
2013-06-12 23:12:32 +02:00
2013-05-02 17:53:54 +02:00
def on_action_YourIdentitiesEnable ( self ) :
currentRow = self . ui . tableWidgetYourIdentities . currentRow ( )
2013-06-12 23:12:32 +02:00
addressAtCurrentRow = str (
self . ui . tableWidgetYourIdentities . item ( currentRow , 1 ) . text ( ) )
shared . config . set ( addressAtCurrentRow , ' enabled ' , ' true ' )
2013-05-02 17:53:54 +02:00
with open ( shared . appdata + ' keys.dat ' , ' wb ' ) as configfile :
shared . config . write ( configfile )
2013-06-12 23:12:32 +02:00
self . ui . tableWidgetYourIdentities . item (
currentRow , 0 ) . setTextColor ( QtGui . QColor ( 0 , 0 , 0 ) )
self . ui . tableWidgetYourIdentities . item (
currentRow , 1 ) . setTextColor ( QtGui . QColor ( 0 , 0 , 0 ) )
self . ui . tableWidgetYourIdentities . item (
currentRow , 2 ) . setTextColor ( QtGui . QColor ( 0 , 0 , 0 ) )
if shared . safeConfigGetBoolean ( addressAtCurrentRow , ' mailinglist ' ) :
self . ui . tableWidgetYourIdentities . item ( currentRow , 1 ) . setTextColor ( QtGui . QColor ( 137 , 04 , 177 ) )
2013-05-02 17:53:54 +02:00
shared . reloadMyAddressHashes ( )
2013-06-12 23:12:32 +02:00
2013-05-02 17:53:54 +02:00
def on_action_YourIdentitiesDisable ( self ) :
currentRow = self . ui . tableWidgetYourIdentities . currentRow ( )
2013-06-12 23:12:32 +02:00
addressAtCurrentRow = str (
self . ui . tableWidgetYourIdentities . item ( currentRow , 1 ) . text ( ) )
shared . config . set ( str ( addressAtCurrentRow ) , ' enabled ' , ' false ' )
self . ui . tableWidgetYourIdentities . item (
currentRow , 0 ) . setTextColor ( QtGui . QColor ( 128 , 128 , 128 ) )
self . ui . tableWidgetYourIdentities . item (
currentRow , 1 ) . setTextColor ( QtGui . QColor ( 128 , 128 , 128 ) )
self . ui . tableWidgetYourIdentities . item (
currentRow , 2 ) . setTextColor ( QtGui . QColor ( 128 , 128 , 128 ) )
if shared . safeConfigGetBoolean ( addressAtCurrentRow , ' mailinglist ' ) :
self . ui . tableWidgetYourIdentities . item ( currentRow , 1 ) . setTextColor ( QtGui . QColor ( 137 , 04 , 177 ) )
2013-05-02 17:53:54 +02:00
with open ( shared . appdata + ' keys.dat ' , ' wb ' ) as configfile :
shared . config . write ( configfile )
shared . reloadMyAddressHashes ( )
2013-06-12 23:12:32 +02:00
2013-05-02 17:53:54 +02:00
def on_action_YourIdentitiesClipboard ( self ) :
currentRow = self . ui . tableWidgetYourIdentities . currentRow ( )
2013-06-12 23:12:32 +02:00
addressAtCurrentRow = self . ui . tableWidgetYourIdentities . item (
currentRow , 1 ) . text ( )
2013-05-02 17:53:54 +02:00
clipboard = QtGui . QApplication . clipboard ( )
clipboard . setText ( str ( addressAtCurrentRow ) )
2013-06-12 23:12:32 +02:00
2013-05-02 17:53:54 +02:00
def on_context_menuYourIdentities ( self , point ) :
2013-06-12 23:12:32 +02:00
self . popMenu . exec_ (
self . ui . tableWidgetYourIdentities . mapToGlobal ( point ) )
2013-05-02 17:53:54 +02:00
def on_context_menuInbox ( self , point ) :
2013-06-12 23:12:32 +02:00
self . popMenuInbox . exec_ ( self . ui . tableWidgetInbox . mapToGlobal ( point ) )
2013-05-02 17:53:54 +02:00
def on_context_menuSent ( self , point ) :
2013-06-12 23:12:32 +02:00
self . popMenuSent = QtGui . QMenu ( self )
self . popMenuSent . addAction ( self . actionSentClipboard )
self . popMenuSent . addAction ( self . actionTrashSentMessage )
# Check to see if this item is toodifficult and display an additional
# menu option (Force Send) if it is.
2013-06-11 00:53:15 +02:00
currentRow = self . ui . tableWidgetSent . currentRow ( )
2013-06-12 23:12:32 +02:00
ackData = str ( self . ui . tableWidgetSent . item (
currentRow , 3 ) . data ( Qt . UserRole ) . toPyObject ( ) )
2013-06-11 00:53:15 +02:00
shared . sqlLock . acquire ( )
2013-06-12 23:12:32 +02:00
shared . sqlSubmitQueue . put (
''' SELECT status FROM sent where ackdata=? ''' )
2013-06-11 00:53:15 +02:00
shared . sqlSubmitQueue . put ( ( ackData , ) )
queryreturn = shared . sqlReturnQueue . get ( )
shared . sqlLock . release ( )
for row in queryreturn :
status , = row
if status == ' toodifficult ' :
2013-06-12 23:12:32 +02:00
self . popMenuSent . addAction ( self . actionForceSend )
self . popMenuSent . exec_ ( self . ui . tableWidgetSent . mapToGlobal ( point ) )
2013-05-02 17:53:54 +02:00
def tableWidgetInboxItemClicked ( self ) :
currentRow = self . ui . tableWidgetInbox . currentRow ( )
if currentRow > = 0 :
2013-06-12 23:12:32 +02:00
fromAddress = str ( self . ui . tableWidgetInbox . item (
currentRow , 1 ) . data ( Qt . UserRole ) . toPyObject ( ) )
# If we have received this message from either a broadcast address
# or from someone in our address book, display as HTML
2013-05-02 17:53:54 +02:00
if decodeAddress ( fromAddress ) [ 3 ] in shared . broadcastSendersForWhichImWatching or shared . isAddressInMyAddressBook ( fromAddress ) :
2013-06-12 23:12:32 +02:00
if len ( self . ui . tableWidgetInbox . item ( currentRow , 2 ) . data ( Qt . UserRole ) . toPyObject ( ) ) < 30000 :
self . ui . textEditInboxMessage . setText ( self . ui . tableWidgetInbox . item (
currentRow , 2 ) . data ( Qt . UserRole ) . toPyObject ( ) ) # Only show the first 30K characters
2013-05-02 17:53:54 +02:00
else :
2013-06-12 23:12:32 +02:00
self . ui . textEditInboxMessage . setText ( self . ui . tableWidgetInbox . item ( currentRow , 2 ) . data ( Qt . UserRole ) . toPyObject ( ) [
: 30000 ] + ' \n \n Display of the remainder of the message truncated because it is too long. ' ) # Only show the first 30K characters
2013-05-02 17:53:54 +02:00
else :
2013-06-12 23:12:32 +02:00
if len ( self . ui . tableWidgetInbox . item ( currentRow , 2 ) . data ( Qt . UserRole ) . toPyObject ( ) ) < 30000 :
self . ui . textEditInboxMessage . setPlainText ( self . ui . tableWidgetInbox . item (
currentRow , 2 ) . data ( Qt . UserRole ) . toPyObject ( ) ) # Only show the first 30K characters
2013-05-02 17:53:54 +02:00
else :
2013-06-12 23:12:32 +02:00
self . ui . textEditInboxMessage . setPlainText ( self . ui . tableWidgetInbox . item ( currentRow , 2 ) . data ( Qt . UserRole ) . toPyObject ( ) [
: 30000 ] + ' \n \n Display of the remainder of the message truncated because it is too long. ' ) # Only show the first 30K characters
2013-05-02 17:53:54 +02:00
font = QFont ( )
font . setBold ( False )
2013-06-12 23:12:32 +02:00
self . ui . tableWidgetInbox . item ( currentRow , 0 ) . setFont ( font )
self . ui . tableWidgetInbox . item ( currentRow , 1 ) . setFont ( font )
self . ui . tableWidgetInbox . item ( currentRow , 2 ) . setFont ( font )
self . ui . tableWidgetInbox . item ( currentRow , 3 ) . setFont ( font )
2013-05-02 17:53:54 +02:00
2013-06-12 23:12:32 +02:00
inventoryHash = str ( self . ui . tableWidgetInbox . item (
currentRow , 3 ) . data ( Qt . UserRole ) . toPyObject ( ) )
2013-05-02 17:53:54 +02:00
t = ( inventoryHash , )
2013-05-14 17:06:01 +02:00
self . ubuntuMessagingMenuClear ( t )
2013-05-02 17:53:54 +02:00
shared . sqlLock . acquire ( )
2013-06-12 23:12:32 +02:00
shared . sqlSubmitQueue . put (
''' update inbox set read=1 WHERE msgid=? ''' )
2013-05-02 17:53:54 +02:00
shared . sqlSubmitQueue . put ( t )
shared . sqlReturnQueue . get ( )
shared . sqlSubmitQueue . put ( ' commit ' )
shared . sqlLock . release ( )
def tableWidgetSentItemClicked ( self ) :
currentRow = self . ui . tableWidgetSent . currentRow ( )
if currentRow > = 0 :
2013-06-12 23:12:32 +02:00
self . ui . textEditSentMessage . setPlainText ( self . ui . tableWidgetSent . item (
currentRow , 2 ) . data ( Qt . UserRole ) . toPyObject ( ) )
2013-05-02 17:53:54 +02:00
def tableWidgetYourIdentitiesItemChanged ( self ) :
currentRow = self . ui . tableWidgetYourIdentities . currentRow ( )
if currentRow > = 0 :
2013-06-12 23:12:32 +02:00
addressAtCurrentRow = self . ui . tableWidgetYourIdentities . item (
currentRow , 1 ) . text ( )
shared . config . set ( str ( addressAtCurrentRow ) , ' label ' , str (
self . ui . tableWidgetYourIdentities . item ( currentRow , 0 ) . text ( ) . toUtf8 ( ) ) )
2013-05-02 17:53:54 +02:00
with open ( shared . appdata + ' keys.dat ' , ' wb ' ) as configfile :
shared . config . write ( configfile )
self . rerenderComboBoxSendFrom ( )
2013-06-12 23:12:32 +02:00
# self.rerenderInboxFromLabels()
2013-05-02 17:53:54 +02:00
self . rerenderInboxToLabels ( )
self . rerenderSentFromLabels ( )
2013-06-12 23:12:32 +02:00
# self.rerenderSentToLabels()
2013-05-02 17:53:54 +02:00
def tableWidgetAddressBookItemChanged ( self ) :
currentRow = self . ui . tableWidgetAddressBook . currentRow ( )
shared . sqlLock . acquire ( )
if currentRow > = 0 :
2013-06-12 23:12:32 +02:00
addressAtCurrentRow = self . ui . tableWidgetAddressBook . item (
currentRow , 1 ) . text ( )
t = ( str ( self . ui . tableWidgetAddressBook . item (
currentRow , 0 ) . text ( ) . toUtf8 ( ) ) , str ( addressAtCurrentRow ) )
shared . sqlSubmitQueue . put (
''' UPDATE addressbook set label=? WHERE address=? ''' )
2013-05-02 17:53:54 +02:00
shared . sqlSubmitQueue . put ( t )
shared . sqlReturnQueue . get ( )
shared . sqlSubmitQueue . put ( ' commit ' )
shared . sqlLock . release ( )
self . rerenderInboxFromLabels ( )
self . rerenderSentToLabels ( )
def tableWidgetSubscriptionsItemChanged ( self ) :
currentRow = self . ui . tableWidgetSubscriptions . currentRow ( )
shared . sqlLock . acquire ( )
if currentRow > = 0 :
2013-06-12 23:12:32 +02:00
addressAtCurrentRow = self . ui . tableWidgetSubscriptions . item (
currentRow , 1 ) . text ( )
t = ( str ( self . ui . tableWidgetSubscriptions . item (
currentRow , 0 ) . text ( ) . toUtf8 ( ) ) , str ( addressAtCurrentRow ) )
shared . sqlSubmitQueue . put (
''' UPDATE subscriptions set label=? WHERE address=? ''' )
2013-05-02 17:53:54 +02:00
shared . sqlSubmitQueue . put ( t )
shared . sqlReturnQueue . get ( )
shared . sqlSubmitQueue . put ( ' commit ' )
shared . sqlLock . release ( )
self . rerenderInboxFromLabels ( )
self . rerenderSentToLabels ( )
2013-06-12 23:12:32 +02:00
def writeNewAddressToTable ( self , label , address , streamNumber ) :
2013-05-02 17:53:54 +02:00
self . ui . tableWidgetYourIdentities . setSortingEnabled ( False )
self . ui . tableWidgetYourIdentities . insertRow ( 0 )
2013-06-12 23:12:32 +02:00
self . ui . tableWidgetYourIdentities . setItem (
0 , 0 , QtGui . QTableWidgetItem ( unicode ( label , ' utf-8 ' ) ) )
2013-05-02 17:53:54 +02:00
newItem = QtGui . QTableWidgetItem ( address )
2013-06-12 23:12:32 +02:00
newItem . setFlags (
QtCore . Qt . ItemIsSelectable | QtCore . Qt . ItemIsEnabled )
2013-05-02 17:53:54 +02:00
self . ui . tableWidgetYourIdentities . setItem ( 0 , 1 , newItem )
newItem = QtGui . QTableWidgetItem ( streamNumber )
2013-06-12 23:12:32 +02:00
newItem . setFlags (
QtCore . Qt . ItemIsSelectable | QtCore . Qt . ItemIsEnabled )
2013-05-02 17:53:54 +02:00
self . ui . tableWidgetYourIdentities . setItem ( 0 , 2 , newItem )
2013-06-12 23:12:32 +02:00
# self.ui.tableWidgetYourIdentities.setSortingEnabled(True)
2013-05-02 17:53:54 +02:00
self . rerenderComboBoxSendFrom ( )
2013-06-12 23:12:32 +02:00
def updateStatusBar ( self , data ) :
2013-05-02 17:53:54 +02:00
if data != " " :
2013-06-29 19:29:35 +02:00
with shared . printLock :
print ' Status bar: ' , data
2013-05-02 17:53:54 +02:00
self . statusBar ( ) . showMessage ( data )
class helpDialog ( QtGui . QDialog ) :
2013-06-12 23:12:32 +02:00
def __init__ ( self , parent ) :
2013-05-02 17:53:54 +02:00
QtGui . QWidget . __init__ ( self , parent )
self . ui = Ui_helpDialog ( )
self . ui . setupUi ( self )
self . parent = parent
self . ui . labelHelpURI . setOpenExternalLinks ( True )
2013-06-12 23:12:32 +02:00
QtGui . QWidget . resize ( self , QtGui . QWidget . sizeHint ( self ) )
2013-05-02 17:53:54 +02:00
class aboutDialog ( QtGui . QDialog ) :
2013-06-12 23:12:32 +02:00
def __init__ ( self , parent ) :
2013-05-02 17:53:54 +02:00
QtGui . QWidget . __init__ ( self , parent )
self . ui = Ui_aboutDialog ( )
self . ui . setupUi ( self )
self . parent = parent
2013-05-02 22:05:31 +02:00
self . ui . labelVersion . setText ( ' version ' + shared . softwareVersion )
2013-05-02 17:53:54 +02:00
2013-06-12 23:12:32 +02:00
2013-05-02 17:53:54 +02:00
class regenerateAddressesDialog ( QtGui . QDialog ) :
2013-06-12 23:12:32 +02:00
def __init__ ( self , parent ) :
2013-05-02 17:53:54 +02:00
QtGui . QWidget . __init__ ( self , parent )
self . ui = Ui_regenerateAddressesDialog ( )
self . ui . setupUi ( self )
self . parent = parent
2013-06-12 23:12:32 +02:00
QtGui . QWidget . resize ( self , QtGui . QWidget . sizeHint ( self ) )
2013-05-02 17:53:54 +02:00
class settingsDialog ( QtGui . QDialog ) :
2013-06-12 23:12:32 +02:00
def __init__ ( self , parent ) :
2013-05-02 17:53:54 +02:00
QtGui . QWidget . __init__ ( self , parent )
self . ui = Ui_settingsDialog ( )
self . ui . setupUi ( self )
self . parent = parent
2013-06-12 23:12:32 +02:00
self . ui . checkBoxStartOnLogon . setChecked (
shared . config . getboolean ( ' bitmessagesettings ' , ' startonlogon ' ) )
self . ui . checkBoxMinimizeToTray . setChecked (
shared . config . getboolean ( ' bitmessagesettings ' , ' minimizetotray ' ) )
self . ui . checkBoxShowTrayNotifications . setChecked (
shared . config . getboolean ( ' bitmessagesettings ' , ' showtraynotifications ' ) )
self . ui . checkBoxStartInTray . setChecked (
shared . config . getboolean ( ' bitmessagesettings ' , ' startintray ' ) )
2013-05-02 17:53:54 +02:00
if shared . appdata == ' ' :
self . ui . checkBoxPortableMode . setChecked ( True )
if ' darwin ' in sys . platform :
self . ui . checkBoxStartOnLogon . setDisabled ( True )
self . ui . checkBoxMinimizeToTray . setDisabled ( True )
self . ui . checkBoxShowTrayNotifications . setDisabled ( True )
2013-06-13 09:59:40 +02:00
self . ui . labelSettingsNote . setText ( _translate (
2013-06-24 04:49:18 +02:00
" MainWindow " , " Options have been disabled because they either aren \' t applicable or because they haven \' t yet been implemented for your operating system. " ) )
2013-05-02 17:53:54 +02:00
elif ' linux ' in sys . platform :
self . ui . checkBoxStartOnLogon . setDisabled ( True )
self . ui . checkBoxMinimizeToTray . setDisabled ( True )
2013-06-13 09:59:40 +02:00
self . ui . labelSettingsNote . setText ( _translate (
2013-06-24 04:49:18 +02:00
" MainWindow " , " Options have been disabled because they either aren \' t applicable or because they haven \' t yet been implemented for your operating system. " ) )
2013-06-12 23:12:32 +02:00
# On the Network settings tab:
self . ui . lineEditTCPPort . setText ( str (
shared . config . get ( ' bitmessagesettings ' , ' port ' ) ) )
self . ui . checkBoxAuthentication . setChecked ( shared . config . getboolean (
' bitmessagesettings ' , ' socksauthentication ' ) )
2013-05-02 17:53:54 +02:00
if str ( shared . config . get ( ' bitmessagesettings ' , ' socksproxytype ' ) ) == ' none ' :
self . ui . comboBoxProxyType . setCurrentIndex ( 0 )
self . ui . lineEditSocksHostname . setEnabled ( False )
self . ui . lineEditSocksPort . setEnabled ( False )
self . ui . lineEditSocksUsername . setEnabled ( False )
self . ui . lineEditSocksPassword . setEnabled ( False )
self . ui . checkBoxAuthentication . setEnabled ( False )
elif str ( shared . config . get ( ' bitmessagesettings ' , ' socksproxytype ' ) ) == ' SOCKS4a ' :
self . ui . comboBoxProxyType . setCurrentIndex ( 1 )
self . ui . lineEditTCPPort . setEnabled ( False )
elif str ( shared . config . get ( ' bitmessagesettings ' , ' socksproxytype ' ) ) == ' SOCKS5 ' :
self . ui . comboBoxProxyType . setCurrentIndex ( 2 )
self . ui . lineEditTCPPort . setEnabled ( False )
2013-06-12 23:12:32 +02:00
self . ui . lineEditSocksHostname . setText ( str (
shared . config . get ( ' bitmessagesettings ' , ' sockshostname ' ) ) )
self . ui . lineEditSocksPort . setText ( str (
shared . config . get ( ' bitmessagesettings ' , ' socksport ' ) ) )
self . ui . lineEditSocksUsername . setText ( str (
shared . config . get ( ' bitmessagesettings ' , ' socksusername ' ) ) )
self . ui . lineEditSocksPassword . setText ( str (
shared . config . get ( ' bitmessagesettings ' , ' sockspassword ' ) ) )
QtCore . QObject . connect ( self . ui . comboBoxProxyType , QtCore . SIGNAL (
" currentIndexChanged(int) " ) , self . comboBoxProxyTypeChanged )
self . ui . lineEditTotalDifficulty . setText ( str ( ( float ( shared . config . getint (
' bitmessagesettings ' , ' defaultnoncetrialsperbyte ' ) ) / shared . networkDefaultProofOfWorkNonceTrialsPerByte ) ) )
self . ui . lineEditSmallMessageDifficulty . setText ( str ( ( float ( shared . config . getint (
' bitmessagesettings ' , ' defaultpayloadlengthextrabytes ' ) ) / shared . networkDefaultPayloadLengthExtraBytes ) ) )
# Max acceptable difficulty tab
self . ui . lineEditMaxAcceptableTotalDifficulty . setText ( str ( ( float ( shared . config . getint (
' bitmessagesettings ' , ' maxacceptablenoncetrialsperbyte ' ) ) / shared . networkDefaultProofOfWorkNonceTrialsPerByte ) ) )
self . ui . lineEditMaxAcceptableSmallMessageDifficulty . setText ( str ( ( float ( shared . config . getint (
' bitmessagesettings ' , ' maxacceptablepayloadlengthextrabytes ' ) ) / shared . networkDefaultPayloadLengthExtraBytes ) ) )
2013-06-11 00:53:15 +02:00
2013-07-07 17:34:43 +02:00
# Namecoin integration tab
ensureNamecoinOptions ( )
self . ui . lineEditNamecoinHost . setText ( str (
shared . config . get ( ' bitmessagesettings ' , ' namecoinrpchost ' ) ) )
self . ui . lineEditNamecoinPort . setText ( str (
shared . config . get ( ' bitmessagesettings ' , ' namecoinrpcport ' ) ) )
self . ui . lineEditNamecoinUser . setText ( str (
shared . config . get ( ' bitmessagesettings ' , ' namecoinrpcuser ' ) ) )
self . ui . lineEditNamecoinPassword . setText ( str (
shared . config . get ( ' bitmessagesettings ' , ' namecoinrpcpassword ' ) ) )
2013-06-04 05:14:24 +02:00
#'System' tab removed for now.
""" try:
2013-05-30 22:25:42 +02:00
maxCores = shared . config . getint ( ' bitmessagesettings ' , ' maxcores ' )
except :
maxCores = 99999
if maxCores < = 1 :
self . ui . comboBoxMaxCores . setCurrentIndex ( 0 )
elif maxCores == 2 :
self . ui . comboBoxMaxCores . setCurrentIndex ( 1 )
elif maxCores < = 4 :
self . ui . comboBoxMaxCores . setCurrentIndex ( 2 )
elif maxCores < = 8 :
self . ui . comboBoxMaxCores . setCurrentIndex ( 3 )
elif maxCores < = 16 :
self . ui . comboBoxMaxCores . setCurrentIndex ( 4 )
else :
2013-06-04 05:14:24 +02:00
self . ui . comboBoxMaxCores . setCurrentIndex ( 5 ) """
2013-05-30 22:25:42 +02:00
2013-06-12 23:12:32 +02:00
QtGui . QWidget . resize ( self , QtGui . QWidget . sizeHint ( self ) )
2013-05-02 17:53:54 +02:00
2013-06-12 23:12:32 +02:00
def comboBoxProxyTypeChanged ( self , comboBoxIndex ) :
2013-05-02 17:53:54 +02:00
if comboBoxIndex == 0 :
self . ui . lineEditSocksHostname . setEnabled ( False )
self . ui . lineEditSocksPort . setEnabled ( False )
self . ui . lineEditSocksUsername . setEnabled ( False )
self . ui . lineEditSocksPassword . setEnabled ( False )
self . ui . checkBoxAuthentication . setEnabled ( False )
self . ui . lineEditTCPPort . setEnabled ( True )
elif comboBoxIndex == 1 or comboBoxIndex == 2 :
self . ui . lineEditSocksHostname . setEnabled ( True )
self . ui . lineEditSocksPort . setEnabled ( True )
self . ui . checkBoxAuthentication . setEnabled ( True )
if self . ui . checkBoxAuthentication . isChecked ( ) :
self . ui . lineEditSocksUsername . setEnabled ( True )
self . ui . lineEditSocksPassword . setEnabled ( True )
self . ui . lineEditTCPPort . setEnabled ( False )
2013-06-12 23:12:32 +02:00
2013-05-02 17:53:54 +02:00
class SpecialAddressBehaviorDialog ( QtGui . QDialog ) :
2013-06-12 23:12:32 +02:00
def __init__ ( self , parent ) :
2013-05-02 17:53:54 +02:00
QtGui . QWidget . __init__ ( self , parent )
self . ui = Ui_SpecialAddressBehaviorDialog ( )
self . ui . setupUi ( self )
self . parent = parent
currentRow = parent . ui . tableWidgetYourIdentities . currentRow ( )
2013-06-12 23:12:32 +02:00
addressAtCurrentRow = str (
parent . ui . tableWidgetYourIdentities . item ( currentRow , 1 ) . text ( ) )
if shared . safeConfigGetBoolean ( addressAtCurrentRow , ' mailinglist ' ) :
2013-05-02 17:53:54 +02:00
self . ui . radioButtonBehaviorMailingList . click ( )
else :
self . ui . radioButtonBehaveNormalAddress . click ( )
try :
2013-06-12 23:12:32 +02:00
mailingListName = shared . config . get (
addressAtCurrentRow , ' mailinglistname ' )
2013-05-02 17:53:54 +02:00
except :
mailingListName = ' '
2013-06-12 23:12:32 +02:00
self . ui . lineEditMailingListName . setText (
unicode ( mailingListName , ' utf-8 ' ) )
QtGui . QWidget . resize ( self , QtGui . QWidget . sizeHint ( self ) )
2013-05-02 17:53:54 +02:00
class NewSubscriptionDialog ( QtGui . QDialog ) :
2013-06-12 23:12:32 +02:00
def __init__ ( self , parent ) :
2013-05-02 17:53:54 +02:00
QtGui . QWidget . __init__ ( self , parent )
self . ui = Ui_NewSubscriptionDialog ( )
self . ui . setupUi ( self )
self . parent = parent
2013-06-12 23:12:32 +02:00
QtCore . QObject . connect ( self . ui . lineEditSubscriptionAddress , QtCore . SIGNAL (
" textChanged(QString) " ) , self . subscriptionAddressChanged )
2013-05-02 17:53:54 +02:00
2013-06-12 23:12:32 +02:00
def subscriptionAddressChanged ( self , QString ) :
status , a , b , c = decodeAddress ( str ( QString ) )
2013-05-02 17:53:54 +02:00
if status == ' missingbm ' :
2013-06-13 09:59:40 +02:00
self . ui . labelSubscriptionAddressCheck . setText ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " The address should start with ' ' BM- ' ' " ) )
2013-05-02 17:53:54 +02:00
elif status == ' checksumfailed ' :
2013-06-13 09:59:40 +02:00
self . ui . labelSubscriptionAddressCheck . setText ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " The address is not typed or copied correctly (the checksum failed). " ) )
2013-05-02 17:53:54 +02:00
elif status == ' versiontoohigh ' :
2013-06-13 09:59:40 +02:00
self . ui . labelSubscriptionAddressCheck . setText ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " The version number of this address is higher than this software can support. Please upgrade Bitmessage. " ) )
2013-05-02 17:53:54 +02:00
elif status == ' invalidcharacters ' :
2013-06-13 09:59:40 +02:00
self . ui . labelSubscriptionAddressCheck . setText ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " The address contains invalid characters. " ) )
2013-05-02 17:53:54 +02:00
elif status == ' ripetooshort ' :
2013-06-13 09:59:40 +02:00
self . ui . labelSubscriptionAddressCheck . setText ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Some data encoded in the address is too short. " ) )
2013-05-02 17:53:54 +02:00
elif status == ' ripetoolong ' :
2013-06-13 09:59:40 +02:00
self . ui . labelSubscriptionAddressCheck . setText ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Some data encoded in the address is too long. " ) )
2013-05-02 17:53:54 +02:00
elif status == ' success ' :
2013-06-12 23:12:32 +02:00
self . ui . labelSubscriptionAddressCheck . setText (
2013-06-13 09:59:40 +02:00
_translate ( " MainWindow " , " Address is valid. " ) )
2013-06-12 23:12:32 +02:00
2013-05-02 17:53:54 +02:00
class NewAddressDialog ( QtGui . QDialog ) :
2013-06-12 23:12:32 +02:00
2013-05-02 17:53:54 +02:00
def __init__ ( self , parent ) :
QtGui . QWidget . __init__ ( self , parent )
self . ui = Ui_NewAddressDialog ( )
self . ui . setupUi ( self )
self . parent = parent
row = 1
2013-06-12 23:12:32 +02:00
# Let's fill out the 'existing address' combo box with addresses from
# the 'Your Identities' tab.
while self . parent . ui . tableWidgetYourIdentities . item ( row - 1 , 1 ) :
2013-05-02 17:53:54 +02:00
self . ui . radioButtonExisting . click ( )
2013-06-12 23:12:32 +02:00
# print
# self.parent.ui.tableWidgetYourIdentities.item(row-1,1).text()
self . ui . comboBoxExisting . addItem (
self . parent . ui . tableWidgetYourIdentities . item ( row - 1 , 1 ) . text ( ) )
2013-05-02 17:53:54 +02:00
row + = 1
self . ui . groupBoxDeterministic . setHidden ( True )
2013-06-12 23:12:32 +02:00
QtGui . QWidget . resize ( self , QtGui . QWidget . sizeHint ( self ) )
2013-06-25 23:14:44 +02:00
class NewChanDialog ( QtGui . QDialog ) :
def __init__ ( self , parent ) :
QtGui . QWidget . __init__ ( self , parent )
self . ui = Ui_NewChanDialog ( )
self . ui . setupUi ( self )
self . parent = parent
self . ui . groupBoxCreateChan . setHidden ( True )
QtGui . QWidget . resize ( self , QtGui . QWidget . sizeHint ( self ) )
2013-05-02 17:53:54 +02:00
class iconGlossaryDialog ( QtGui . QDialog ) :
2013-06-12 23:12:32 +02:00
def __init__ ( self , parent ) :
2013-05-02 17:53:54 +02:00
QtGui . QWidget . __init__ ( self , parent )
self . ui = Ui_iconGlossaryDialog ( )
self . ui . setupUi ( self )
self . parent = parent
2013-06-13 09:59:40 +02:00
self . ui . labelPortNumber . setText ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " You are using TCP port % 1. (This can be changed in the settings). " ) . arg ( str ( shared . config . getint ( ' bitmessagesettings ' , ' port ' ) ) ) )
QtGui . QWidget . resize ( self , QtGui . QWidget . sizeHint ( self ) )
2013-05-02 17:53:54 +02:00
2013-06-12 23:12:32 +02:00
# In order for the time columns on the Inbox and Sent tabs to be sorted
# correctly (rather than alphabetically), we need to overload the <
# operator and use this class instead of QTableWidgetItem.
2013-05-02 17:53:54 +02:00
class myTableWidgetItem ( QTableWidgetItem ) :
2013-06-12 23:12:32 +02:00
def __lt__ ( self , other ) :
2013-05-02 17:53:54 +02:00
return int ( self . data ( 33 ) . toPyObject ( ) ) < int ( other . data ( 33 ) . toPyObject ( ) )
2013-06-28 16:26:31 +02:00
from threading import Thread
class UISignaler ( Thread , QThread ) :
2013-06-12 23:12:32 +02:00
def __init__ ( self , parent = None ) :
2013-06-28 16:26:31 +02:00
Thread . __init__ ( self , parent )
2013-05-02 17:53:54 +02:00
QThread . __init__ ( self , parent )
def run ( self ) :
while True :
2013-06-28 16:26:31 +02:00
try :
command , data = shared . UISignalQueue . get ( )
if command == ' writeNewAddressToTable ' :
label , address , streamNumber = data
self . emit ( SIGNAL (
" writeNewAddressToTable(PyQt_PyObject,PyQt_PyObject,PyQt_PyObject) " ) , label , address , str ( streamNumber ) )
elif command == ' updateStatusBar ' :
self . emit ( SIGNAL ( " updateStatusBar(PyQt_PyObject) " ) , data )
elif command == ' updateSentItemStatusByHash ' :
hash , message = data
self . emit ( SIGNAL (
" updateSentItemStatusByHash(PyQt_PyObject,PyQt_PyObject) " ) , hash , message )
elif command == ' updateSentItemStatusByAckdata ' :
ackData , message = data
self . emit ( SIGNAL (
" updateSentItemStatusByAckdata(PyQt_PyObject,PyQt_PyObject) " ) , ackData , message )
elif command == ' displayNewInboxMessage ' :
inventoryHash , toAddress , fromAddress , subject , body = data
self . emit ( SIGNAL (
" displayNewInboxMessage(PyQt_PyObject,PyQt_PyObject,PyQt_PyObject,PyQt_PyObject,PyQt_PyObject) " ) ,
inventoryHash , toAddress , fromAddress , subject , body )
elif command == ' displayNewSentMessage ' :
toAddress , fromLabel , fromAddress , subject , message , ackdata = data
self . emit ( SIGNAL (
" displayNewSentMessage(PyQt_PyObject,PyQt_PyObject,PyQt_PyObject,PyQt_PyObject,PyQt_PyObject,PyQt_PyObject) " ) ,
toAddress , fromLabel , fromAddress , subject , message , ackdata )
elif command == ' updateNetworkStatusTab ' :
self . emit ( SIGNAL ( " updateNetworkStatusTab() " ) )
elif command == ' incrementNumberOfMessagesProcessed ' :
self . emit ( SIGNAL ( " incrementNumberOfMessagesProcessed() " ) )
elif command == ' incrementNumberOfPubkeysProcessed ' :
self . emit ( SIGNAL ( " incrementNumberOfPubkeysProcessed() " ) )
elif command == ' incrementNumberOfBroadcastsProcessed ' :
self . emit ( SIGNAL ( " incrementNumberOfBroadcastsProcessed() " ) )
elif command == ' setStatusIcon ' :
self . emit ( SIGNAL ( " setStatusIcon(PyQt_PyObject) " ) , data )
elif command == ' rerenderInboxFromLabels ' :
self . emit ( SIGNAL ( " rerenderInboxFromLabels() " ) )
elif command == ' rerenderSubscriptions ' :
self . emit ( SIGNAL ( " rerenderSubscriptions() " ) )
elif command == ' removeInboxRowByMsgid ' :
self . emit ( SIGNAL ( " removeInboxRowByMsgid(PyQt_PyObject) " ) , data )
else :
sys . stderr . write (
' Command sent to UISignaler not recognized: %s \n ' % command )
except Exception , ex :
# uncaught exception will block gevent
import traceback
traceback . print_exc ( )
traceback . print_stack ( )
print ex
pass
2013-06-12 23:12:32 +02:00
2013-06-28 10:45:03 +02:00
try :
import gevent
except ImportError as ex :
2013-07-05 22:01:20 +02:00
gevent = None
2013-06-28 10:45:03 +02:00
else :
def mainloop ( app ) :
while True :
app . processEvents ( )
2013-07-05 22:43:40 +02:00
gevent . sleep ( 0.01 )
2013-06-28 10:45:03 +02:00
def testprint ( ) :
#print 'this is running'
gevent . spawn_later ( 1 , testprint )
2013-05-02 17:53:54 +02:00
def run ( ) :
app = QtGui . QApplication ( sys . argv )
2013-06-12 10:07:04 +02:00
translator = QtCore . QTranslator ( )
2013-06-14 21:58:46 +02:00
2013-07-02 13:52:16 +02:00
try :
translator . load ( " translations/bitmessage_ " + str ( locale . getlocale ( ) [ 0 ] ) )
except :
# The above is not compatible with all versions of OSX.
translator . load ( " translations/bitmessage_en_US " ) # Default to english.
2013-06-14 21:58:46 +02:00
2013-06-12 10:07:04 +02:00
QtGui . QApplication . installTranslator ( translator )
2013-05-02 17:53:54 +02:00
app . setStyleSheet ( " QStatusBar::item { border: 0px solid black } " )
myapp = MyForm ( )
2013-05-13 12:51:48 +02:00
2013-06-03 05:22:28 +02:00
if not shared . config . getboolean ( ' bitmessagesettings ' , ' startintray ' ) :
2013-05-13 12:51:48 +02:00
myapp . show ( )
2013-05-11 18:33:16 +02:00
myapp . appIndicatorInit ( app )
2013-05-10 21:47:01 +02:00
myapp . ubuntuMessagingMenuInit ( )
2013-05-11 18:33:16 +02:00
myapp . notifierInit ( )
2013-06-28 10:45:03 +02:00
if gevent is None :
sys . exit ( app . exec_ ( ) )
else :
2013-06-29 19:29:35 +02:00
gevent . joinall ( [ gevent . spawn ( testprint ) , gevent . spawn ( mainloop , app ) , gevent . spawn ( mainloop , app ) , gevent . spawn ( mainloop , app ) , gevent . spawn ( mainloop , app ) , gevent . spawn ( mainloop , app ) ] )
2013-06-28 10:45:03 +02:00
print ' done '