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
2015-10-02 22:24:46 +02:00
try :
from PyQt4 import QtCore , QtGui
from PyQt4 . QtCore import *
from PyQt4 . QtGui import *
except Exception as err :
2015-11-18 16:22:17 +01:00
logger . error ( ' PyBitmessage requires PyQt unless you want to run it as a daemon and interact with it using the API. You can download it from http://www.riverbankcomputing.com/software/pyqt/download or by searching Google for \' PyQt Download \' (without quotes). ' )
logger . error ( ' Error message: ' + str ( err ) )
2015-10-02 22:24:46 +02:00
sys . exit ( )
try :
_encoding = QtGui . QApplication . UnicodeUTF8
except AttributeError :
2015-11-18 16:22:17 +01:00
logger . error ( ' QtGui.QApplication.UnicodeUTF8 error: ' + str ( err ) )
2015-10-02 22:24:46 +02:00
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 *
2015-10-01 09:42:47 +02:00
from newaddresswizard import *
from migrationwizard import *
2015-10-02 22:24:46 +02:00
from foldertree import *
2013-12-01 05:15:18 +01:00
from addaddressdialog import *
2013-05-02 17:53:54 +02:00
from newsubscriptiondialog import *
from regenerateaddresses import *
2013-07-22 07:10:22 +02:00
from newchandialog import *
2013-05-02 17:53:54 +02:00
from specialaddressbehavior import *
2015-10-03 17:24:21 +02:00
from emailgateway import *
2013-05-02 17:53:54 +02:00
from settings import *
2015-11-08 21:44:02 +01:00
import settingsmixin
2013-05-02 17:53:54 +02:00
from about import *
from help import *
from iconglossary import *
2013-07-24 17:46:28 +02:00
from connect import *
2013-05-02 17:53:54 +02:00
import sys
from time import strftime , localtime , gmtime
import time
import os
2013-11-02 00:25:24 +01:00
import hashlib
2013-05-02 17:53:54 +02:00
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
2014-01-28 20:32:16 +01:00
import textwrap
2013-07-15 21:45:03 +02:00
import debug
from debug import logger
2013-07-15 18:58:22 +02:00
import subprocess
2013-07-31 23:25:34 +02:00
import datetime
2013-08-27 02:01:19 +02:00
from helper_sql import *
2014-08-06 04:01:01 +02:00
import l10n
2015-11-15 00:12:19 +01:00
try :
from PyQt4 import QtCore , QtGui
from PyQt4 . QtCore import *
from PyQt4 . QtGui import *
from PyQt4 . QtNetwork import QLocalSocket , QLocalServer
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
2013-06-25 22:26:12 +02:00
def _translate ( context , text ) :
return QtGui . QApplication . translate ( context , text )
2014-11-14 12:21:18 +01:00
def change_translation ( locale ) :
global qtranslator
qtranslator = QtCore . QTranslator ( )
2015-11-13 12:25:50 +01:00
translationpath = os . path . join ( shared . codePath ( ) , ' translations ' , ' bitmessage_ ' + locale )
2014-11-14 12:21:18 +01:00
qtranslator . load ( translationpath )
QtGui . QApplication . installTranslator ( qtranslator )
2013-11-02 00:25:24 +01:00
2015-11-08 21:44:02 +01:00
class MyForm ( settingsmixin . SMainWindow ) :
2013-05-10 21:47:01 +02:00
2013-07-15 18:01:12 +02:00
# sound type constants
SOUND_NONE = 0
SOUND_KNOWN = 1
SOUND_UNKNOWN = 2
SOUND_CONNECTED = 3
SOUND_DISCONNECTED = 4
SOUND_CONNECTION_GREEN = 5
2013-07-31 23:25:34 +02:00
# the last time that a message arrival sound was played
lastSoundTime = datetime . datetime . now ( ) - datetime . timedelta ( days = 1 )
# the maximum frequency of message sounds in seconds
maxSoundFrequencySec = 60
2013-07-22 07:10:22 +02:00
str_chan = ' [chan] '
2013-05-14 17:06:01 +02:00
2013-11-07 20:35:11 +01:00
def init_file_menu ( self ) :
2013-06-12 23:12:32 +02:00
QtCore . QObject . connect ( self . ui . actionExit , QtCore . SIGNAL (
" triggered() " ) , self . quit )
QtCore . QObject . connect ( self . ui . actionManageKeys , QtCore . SIGNAL (
" triggered() " ) , self . click_actionManageKeys )
2013-11-07 20:35:11 +01:00
QtCore . QObject . connect ( self . ui . actionDeleteAllTrashedMessages ,
QtCore . SIGNAL (
" triggered() " ) ,
self . click_actionDeleteAllTrashedMessages )
QtCore . QObject . connect ( self . ui . actionRegenerateDeterministicAddresses ,
QtCore . SIGNAL (
" triggered() " ) ,
self . click_actionRegenerateDeterministicAddresses )
2015-03-23 22:35:56 +01:00
QtCore . QObject . connect ( self . ui . pushButtonAddChan , QtCore . SIGNAL (
2015-03-03 18:17:56 +01:00
" clicked() " ) ,
2013-11-07 20:35:11 +01:00
self . click_actionJoinChan ) # also used for creating chans.
2013-06-12 23:12:32 +02:00
QtCore . QObject . connect ( self . ui . pushButtonNewAddress , QtCore . SIGNAL (
" clicked() " ) , self . click_NewAddressDialog )
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 )
2015-03-03 20:04:12 +01:00
QtCore . QObject . connect ( self . ui . pushButtonTTL , QtCore . SIGNAL (
" clicked() " ) , self . click_pushButtonTTL )
2013-06-12 23:12:32 +02:00
QtCore . QObject . connect ( self . ui . pushButtonSend , QtCore . SIGNAL (
" clicked() " ) , self . click_pushButtonSend )
2015-03-21 11:37:08 +01: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 )
2014-12-28 11:42:38 +01:00
def init_inbox_popup_menu ( self , connectSignal = True ) :
2013-06-12 23:12:32 +02:00
# Popup menu for the Inbox tab
2013-05-02 17:53:54 +02:00
self . ui . inboxContextMenuToolbar = QtGui . QToolBar ( )
2013-11-07 20:35:11 +01:00
# Actions
2013-06-13 09:59:40 +02:00
self . actionReply = self . ui . inboxContextMenuToolbar . addAction ( _translate (
" MainWindow " , " Reply " ) , self . on_action_InboxReply )
2013-11-07 20:35:11 +01:00
self . actionAddSenderToAddressBook = self . ui . inboxContextMenuToolbar . addAction (
_translate (
" MainWindow " , " Add sender to your Address Book " ) ,
self . on_action_InboxAddSenderToAddressBook )
2015-11-14 01:14:10 +01:00
self . actionAddSenderToBlackList = self . ui . inboxContextMenuToolbar . addAction (
_translate (
" MainWindow " , " Add sender to your Blacklist " ) ,
self . on_action_InboxAddSenderToBlackList )
2013-06-12 23:12:32 +02:00
self . actionTrashInboxMessage = self . ui . inboxContextMenuToolbar . addAction (
2013-11-07 20:35:11 +01:00
_translate ( " MainWindow " , " Move to Trash " ) ,
self . on_action_InboxTrash )
2015-11-01 10:56:37 +01:00
self . actionUndeleteTrashedMessage = self . ui . inboxContextMenuToolbar . addAction (
_translate ( " MainWindow " , " Undelete " ) ,
self . on_action_TrashUndelete )
2013-11-07 20:35:11 +01:00
self . actionForceHtml = self . ui . inboxContextMenuToolbar . addAction (
_translate (
" MainWindow " , " View HTML code as formatted text " ) ,
self . on_action_InboxMessageForceHtml )
self . actionSaveMessageAs = self . ui . inboxContextMenuToolbar . addAction (
_translate (
" MainWindow " , " Save message as... " ) ,
self . on_action_InboxSaveMessageAs )
self . actionMarkUnread = self . ui . inboxContextMenuToolbar . addAction (
_translate (
" MainWindow " , " Mark Unread " ) , self . on_action_InboxMarkUnread )
2015-03-23 22:35:56 +01:00
# contextmenu messagelists
2013-06-12 23:12:32 +02:00
self . ui . tableWidgetInbox . setContextMenuPolicy (
QtCore . Qt . CustomContextMenu )
2014-12-28 11:42:38 +01:00
if connectSignal :
self . connect ( self . ui . tableWidgetInbox , QtCore . SIGNAL (
' customContextMenuRequested(const QPoint&) ' ) ,
self . on_context_menuInbox )
2015-03-23 22:35:56 +01:00
self . ui . tableWidgetInboxSubscriptions . setContextMenuPolicy (
QtCore . Qt . CustomContextMenu )
if connectSignal :
self . connect ( self . ui . tableWidgetInboxSubscriptions , QtCore . SIGNAL (
' customContextMenuRequested(const QPoint&) ' ) ,
self . on_context_menuInbox )
self . ui . tableWidgetInboxChans . setContextMenuPolicy (
QtCore . Qt . CustomContextMenu )
if connectSignal :
self . connect ( self . ui . tableWidgetInboxChans , QtCore . SIGNAL (
' customContextMenuRequested(const QPoint&) ' ) ,
self . on_context_menuInbox )
2014-12-28 11:42:38 +01:00
def init_identities_popup_menu ( self , connectSignal = True ) :
2013-06-12 23:12:32 +02:00
# Popup menu for the Your Identities tab
2015-03-21 11:37:08 +01:00
self . ui . addressContextMenuToolbarYourIdentities = QtGui . QToolBar ( )
# Actions
self . actionNewYourIdentities = self . ui . addressContextMenuToolbarYourIdentities . addAction ( _translate (
" MainWindow " , " New " ) , self . on_action_YourIdentitiesNew )
self . actionEnableYourIdentities = self . ui . addressContextMenuToolbarYourIdentities . addAction (
_translate (
" MainWindow " , " Enable " ) , self . on_action_Enable )
self . actionDisableYourIdentities = self . ui . addressContextMenuToolbarYourIdentities . addAction (
_translate (
" MainWindow " , " Disable " ) , self . on_action_Disable )
self . actionSetAvatarYourIdentities = self . ui . addressContextMenuToolbarYourIdentities . addAction (
_translate (
" MainWindow " , " Set avatar... " ) ,
self . on_action_TreeWidgetSetAvatar )
self . actionClipboardYourIdentities = self . ui . addressContextMenuToolbarYourIdentities . addAction (
_translate (
" MainWindow " , " Copy address to clipboard " ) ,
self . on_action_Clipboard )
self . actionSpecialAddressBehaviorYourIdentities = self . ui . addressContextMenuToolbarYourIdentities . addAction (
_translate (
" MainWindow " , " Special address behavior... " ) ,
self . on_action_SpecialAddressBehaviorDialog )
2015-10-03 17:24:21 +02:00
self . actionEmailGateway = self . ui . addressContextMenuToolbarYourIdentities . addAction (
_translate (
" MainWindow " , " Email gateway " ) ,
self . on_action_EmailGatewayDialog )
2015-03-21 11:37:08 +01:00
self . ui . treeWidgetYourIdentities . setContextMenuPolicy (
QtCore . Qt . CustomContextMenu )
if connectSignal :
self . connect ( self . ui . treeWidgetYourIdentities , QtCore . SIGNAL (
' customContextMenuRequested(const QPoint&) ' ) ,
self . on_context_menuYourIdentities )
def init_chan_popup_menu ( self , connectSignal = True ) :
2015-03-23 22:35:56 +01:00
# Popup menu for the Channels tab
2013-05-02 17:53:54 +02:00
self . ui . addressContextMenuToolbar = QtGui . QToolBar ( )
2013-11-07 20:35:11 +01:00
# 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 )
2015-11-09 18:22:38 +01:00
self . actionDelete = self . ui . addressContextMenuToolbar . addAction (
_translate ( " MainWindow " , " Delete " ) ,
self . on_action_YourIdentitiesDelete )
2013-11-07 20:35:11 +01:00
self . actionEnable = self . ui . addressContextMenuToolbar . addAction (
_translate (
2015-03-21 11:37:08 +01:00
" MainWindow " , " Enable " ) , self . on_action_Enable )
2013-11-07 20:35:11 +01:00
self . actionDisable = self . ui . addressContextMenuToolbar . addAction (
_translate (
2015-03-21 11:37:08 +01:00
" MainWindow " , " Disable " ) , self . on_action_Disable )
2013-11-07 20:35:11 +01:00
self . actionSetAvatar = self . ui . addressContextMenuToolbar . addAction (
_translate (
" MainWindow " , " Set avatar... " ) ,
2015-03-21 11:37:08 +01:00
self . on_action_TreeWidgetSetAvatar )
2013-11-07 20:35:11 +01:00
self . actionClipboard = self . ui . addressContextMenuToolbar . addAction (
_translate (
" MainWindow " , " Copy address to clipboard " ) ,
2015-03-21 11:37:08 +01:00
self . on_action_Clipboard )
2013-11-07 20:35:11 +01:00
self . actionSpecialAddressBehavior = self . ui . addressContextMenuToolbar . addAction (
_translate (
" MainWindow " , " Special address behavior... " ) ,
self . on_action_SpecialAddressBehaviorDialog )
2015-03-03 18:17:56 +01:00
2015-03-23 22:35:56 +01:00
self . ui . treeWidgetChans . setContextMenuPolicy (
2013-06-12 23:12:32 +02:00
QtCore . Qt . CustomContextMenu )
2014-12-28 11:42:38 +01:00
if connectSignal :
2015-03-23 22:35:56 +01:00
self . connect ( self . ui . treeWidgetChans , QtCore . SIGNAL (
2014-12-28 11:42:38 +01:00
' customContextMenuRequested(const QPoint&) ' ) ,
2015-03-21 11:37:08 +01:00
self . on_context_menuChan )
2015-03-03 18:17:56 +01:00
2014-12-28 11:42:38 +01:00
def init_addressbook_popup_menu ( self , connectSignal = True ) :
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 ( )
2013-11-07 20:35:11 +01:00
# Actions
self . actionAddressBookSend = self . ui . addressBookContextMenuToolbar . addAction (
_translate (
" MainWindow " , " Send message to this address " ) ,
self . on_action_AddressBookSend )
self . actionAddressBookClipboard = self . ui . addressBookContextMenuToolbar . addAction (
_translate (
" MainWindow " , " Copy address to clipboard " ) ,
self . on_action_AddressBookClipboard )
self . actionAddressBookSubscribe = self . ui . addressBookContextMenuToolbar . addAction (
_translate (
" MainWindow " , " Subscribe to this address " ) ,
self . on_action_AddressBookSubscribe )
self . actionAddressBookSetAvatar = self . ui . addressBookContextMenuToolbar . addAction (
_translate (
" MainWindow " , " Set avatar... " ) ,
self . on_action_AddressBookSetAvatar )
self . actionAddressBookNew = self . ui . addressBookContextMenuToolbar . addAction (
_translate (
" MainWindow " , " Add New Address " ) , self . on_action_AddressBookNew )
self . actionAddressBookDelete = self . ui . addressBookContextMenuToolbar . addAction (
_translate (
" MainWindow " , " Delete " ) , self . on_action_AddressBookDelete )
2013-06-12 23:12:32 +02:00
self . ui . tableWidgetAddressBook . setContextMenuPolicy (
QtCore . Qt . CustomContextMenu )
2014-12-28 11:42:38 +01:00
if connectSignal :
self . connect ( self . ui . tableWidgetAddressBook , QtCore . SIGNAL (
' customContextMenuRequested(const QPoint&) ' ) ,
self . on_context_menuAddressBook )
2013-05-02 17:53:54 +02:00
2014-12-28 11:42:38 +01:00
def init_subscriptions_popup_menu ( self , connectSignal = True ) :
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 ( )
2013-11-07 20:35:11 +01:00
# 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-11-07 20:35:11 +01:00
_translate ( " MainWindow " , " Delete " ) ,
self . on_action_SubscriptionsDelete )
2013-06-12 23:12:32 +02:00
self . actionsubscriptionsClipboard = self . ui . subscriptionsContextMenuToolbar . addAction (
2013-11-07 20:35:11 +01: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-11-07 20:35:11 +01:00
_translate ( " MainWindow " , " Enable " ) ,
self . on_action_SubscriptionsEnable )
2013-06-12 23:12:32 +02:00
self . actionsubscriptionsDisable = self . ui . subscriptionsContextMenuToolbar . addAction (
2013-11-07 20:35:11 +01:00
_translate ( " MainWindow " , " Disable " ) ,
self . on_action_SubscriptionsDisable )
2013-09-21 09:41:23 +02:00
self . actionsubscriptionsSetAvatar = self . ui . subscriptionsContextMenuToolbar . addAction (
2013-11-07 20:35:11 +01:00
_translate ( " MainWindow " , " Set avatar... " ) ,
2015-03-21 11:37:08 +01:00
self . on_action_TreeWidgetSetAvatar )
self . ui . treeWidgetSubscriptions . setContextMenuPolicy (
2013-06-12 23:12:32 +02:00
QtCore . Qt . CustomContextMenu )
2014-12-28 11:42:38 +01:00
if connectSignal :
2015-03-21 11:37:08 +01:00
self . connect ( self . ui . treeWidgetSubscriptions , QtCore . SIGNAL (
2014-12-28 11:42:38 +01:00
' customContextMenuRequested(const QPoint&) ' ) ,
self . on_context_menuSubscriptions )
2013-05-02 17:53:54 +02:00
2014-12-28 11:42:38 +01:00
def init_sent_popup_menu ( self , connectSignal = True ) :
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 ( )
2013-11-07 20:35:11 +01:00
# Actions
self . actionTrashSentMessage = self . ui . sentContextMenuToolbar . addAction (
_translate (
" MainWindow " , " Move to Trash " ) , self . on_action_SentTrash )
self . actionSentClipboard = self . ui . sentContextMenuToolbar . addAction (
_translate (
" MainWindow " , " Copy destination address to clipboard " ) ,
self . on_action_SentClipboard )
self . actionForceSend = self . ui . sentContextMenuToolbar . addAction (
_translate (
" MainWindow " , " Force send " ) , self . on_action_ForceSend )
2013-06-12 23:12:32 +02:00
# self.popMenuSent = QtGui.QMenu( self )
# self.popMenuSent.addAction( self.actionSentClipboard )
# self.popMenuSent.addAction( self.actionTrashSentMessage )
2014-12-28 11:42:38 +01:00
def init_blacklist_popup_menu ( self , connectSignal = True ) :
2013-06-12 23:12:32 +02:00
# Popup menu for the Blacklist page
2013-05-02 17:53:54 +02:00
self . ui . blacklistContextMenuToolbar = QtGui . QToolBar ( )
2013-11-07 20:35:11 +01:00
# Actions
self . actionBlacklistNew = self . ui . blacklistContextMenuToolbar . addAction (
_translate (
" MainWindow " , " Add new entry " ) , self . on_action_BlacklistNew )
self . actionBlacklistDelete = self . ui . blacklistContextMenuToolbar . addAction (
_translate (
" MainWindow " , " Delete " ) , self . on_action_BlacklistDelete )
self . actionBlacklistClipboard = self . ui . blacklistContextMenuToolbar . addAction (
_translate (
" MainWindow " , " Copy address to clipboard " ) ,
self . on_action_BlacklistClipboard )
self . actionBlacklistEnable = self . ui . blacklistContextMenuToolbar . addAction (
_translate (
" MainWindow " , " Enable " ) , self . on_action_BlacklistEnable )
self . actionBlacklistDisable = self . ui . blacklistContextMenuToolbar . addAction (
_translate (
" MainWindow " , " Disable " ) , self . on_action_BlacklistDisable )
self . actionBlacklistSetAvatar = self . ui . blacklistContextMenuToolbar . addAction (
_translate (
" MainWindow " , " Set avatar... " ) ,
self . on_action_BlacklistSetAvatar )
2013-06-12 23:12:32 +02:00
self . ui . tableWidgetBlacklist . setContextMenuPolicy (
QtCore . Qt . CustomContextMenu )
2014-12-28 11:42:38 +01:00
if connectSignal :
self . connect ( self . ui . tableWidgetBlacklist , QtCore . SIGNAL (
' customContextMenuRequested(const QPoint&) ' ) ,
self . on_context_menuBlacklist )
2013-06-12 23:12:32 +02:00
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-09-21 09:41:23 +02:00
self . popMenuBlacklist . addAction ( self . actionBlacklistSetAvatar )
2013-05-02 17:53:54 +02:00
2015-03-23 22:35:56 +01:00
def rerenderTabTreeSubscriptions ( self ) :
treeWidget = self . ui . treeWidgetSubscriptions
2015-10-23 12:38:59 +02:00
folders = [ ' inbox ' , ' sent ' , ' trash ' ]
2015-03-23 22:35:56 +01:00
2015-11-19 04:05:58 +01:00
# sort ascending when creating
if treeWidget . topLevelItemCount ( ) == 0 :
treeWidget . header ( ) . setSortIndicator ( 0 , Qt . AscendingOrder )
# init dictionary
db = getSortedSubscriptions ( True )
2015-11-19 04:14:13 +01:00
for address in db :
for folder in folders :
if not folder in db [ address ] :
db [ address ] [ folder ] = { }
2015-11-19 04:05:58 +01:00
if treeWidget . isSortingEnabled ( ) :
treeWidget . setSortingEnabled ( False )
widgets = { }
i = 0
while i < treeWidget . topLevelItemCount ( ) :
widget = treeWidget . topLevelItem ( i )
if widget is not None :
toAddress = widget . address
else :
toAddress = None
if not toAddress in db :
treeWidget . takeTopLevelItem ( i )
# no increment
continue
unread = 0
j = 0
while j < widget . childCount ( ) :
subwidget = widget . child ( j )
try :
subwidget . setUnreadCount ( db [ toAddress ] [ subwidget . folderName ] [ ' count ' ] )
unread + = db [ toAddress ] [ subwidget . folderName ] [ ' count ' ]
db [ toAddress ] . pop ( subwidget . folderName , None )
except :
widget . takeChild ( j )
# no increment
continue
j + = 1
# add missing folders
if len ( db [ toAddress ] ) > 0 :
j = 0
for f , c in db [ toAddress ] . iteritems ( ) :
2015-11-19 04:14:13 +01:00
try :
subwidget = Ui_FolderWidget ( widget , j , toAddress , f , c [ ' count ' ] )
except KeyError :
subwidget = Ui_FolderWidget ( widget , j , toAddress , f , 0 )
2015-11-19 04:05:58 +01:00
j + = 1
widget . setUnreadCount ( unread )
db . pop ( toAddress , None )
i + = 1
i = 0
for toAddress in db :
widget = Ui_SubscriptionWidget ( treeWidget , i , toAddress , db [ toAddress ] [ " inbox " ] [ ' count ' ] , db [ toAddress ] [ " inbox " ] [ ' label ' ] , db [ toAddress ] [ " inbox " ] [ ' enabled ' ] )
j = 0
2015-10-18 21:11:10 +02:00
unread = 0
2015-03-23 22:35:56 +01:00
for folder in folders :
2015-10-18 21:11:10 +02:00
try :
2015-11-19 04:05:58 +01:00
subwidget = Ui_FolderWidget ( widget , j , toAddress , folder , db [ toAddress ] [ folder ] [ ' count ' ] )
unread + = db [ toAddress ] [ folder ] [ ' count ' ]
2015-10-18 21:11:10 +02:00
except KeyError :
2015-11-19 04:05:58 +01:00
subwidget = Ui_FolderWidget ( widget , j , toAddress , folder , 0 )
j + = 1
widget . setUnreadCount ( unread )
widget . setFlags ( widget . flags ( ) | QtCore . Qt . ItemIsEditable )
i + = 1
2015-10-10 19:58:01 +02:00
treeWidget . setSortingEnabled ( True )
2015-03-23 22:35:56 +01:00
2015-11-19 04:05:58 +01:00
2015-03-23 22:35:56 +01:00
def rerenderTabTreeMessages ( self ) :
self . rerenderTabTree ( ' messages ' )
def rerenderTabTreeChans ( self ) :
self . rerenderTabTree ( ' chan ' )
2015-10-01 10:08:12 +02:00
2015-03-21 11:37:08 +01:00
def rerenderTabTree ( self , tab ) :
if tab == ' messages ' :
treeWidget = self . ui . treeWidgetYourIdentities
elif tab == ' chan ' :
2015-03-23 22:35:56 +01:00
treeWidget = self . ui . treeWidgetChans
2015-10-23 12:38:59 +02:00
folders = [ ' inbox ' , ' sent ' , ' trash ' ]
2015-03-21 11:37:08 +01:00
2015-10-03 12:12:18 +02:00
# sort ascending when creating
if treeWidget . topLevelItemCount ( ) == 0 :
treeWidget . header ( ) . setSortIndicator ( 0 , Qt . AscendingOrder )
2015-10-02 22:24:46 +02:00
# init dictionary
db = { }
enabled = { }
2015-10-19 20:03:06 +02:00
for toAddress in getSortedAccounts ( ) :
2015-10-01 10:15:23 +02:00
isEnabled = shared . config . getboolean (
2015-10-02 22:24:46 +02:00
toAddress , ' enabled ' )
2015-10-01 10:15:23 +02:00
isChan = shared . safeConfigGetBoolean (
2015-10-02 22:24:46 +02:00
toAddress , ' chan ' )
2015-10-01 10:15:23 +02:00
isMaillinglist = shared . safeConfigGetBoolean (
2015-10-02 22:24:46 +02:00
toAddress , ' mailinglist ' )
2015-10-01 10:15:23 +02:00
if tab == ' messages ' :
if isChan :
continue
elif tab == ' chan ' :
if not isChan :
continue
2015-10-02 22:24:46 +02:00
db [ toAddress ] = { }
2015-10-01 10:15:23 +02:00
for folder in folders :
2015-10-02 22:24:46 +02:00
db [ toAddress ] [ folder ] = 0
enabled [ toAddress ] = isEnabled
2015-10-01 10:15:23 +02:00
2015-10-02 22:24:46 +02:00
# get number of (unread) messages
queryreturn = sqlQuery ( ' SELECT toaddress, folder, count(msgid) as cnt FROM inbox WHERE read = 0 GROUP BY toaddress, folder ' )
for row in queryreturn :
toaddress , folder , cnt = row
if toaddress in db and folder in db [ toaddress ] :
db [ toaddress ] [ folder ] = cnt
if treeWidget . isSortingEnabled ( ) :
treeWidget . setSortingEnabled ( False )
widgets = { }
2015-11-09 18:44:27 +01:00
i = 0
while i < treeWidget . topLevelItemCount ( ) :
2015-10-02 22:24:46 +02:00
widget = treeWidget . topLevelItem ( i )
2015-11-09 18:22:38 +01:00
if widget is not None :
toAddress = widget . address
else :
toAddress = None
2015-10-02 22:24:46 +02:00
if not toAddress in db :
treeWidget . takeTopLevelItem ( i )
2015-11-09 18:44:27 +01:00
# no increment
2015-10-02 22:24:46 +02:00
continue
unread = 0
2015-11-09 18:44:27 +01:00
j = 0
while j < widget . childCount ( ) :
2015-10-02 22:24:46 +02:00
subwidget = widget . child ( j )
try :
subwidget . setUnreadCount ( db [ toAddress ] [ subwidget . folderName ] )
unread + = db [ toAddress ] [ subwidget . folderName ]
db [ toAddress ] . pop ( subwidget . folderName , None )
except :
2015-11-09 18:44:27 +01:00
widget . takeChild ( j )
# no increment
continue
j + = 1
2015-10-02 22:24:46 +02:00
# add missing folders
if len ( db [ toAddress ] ) > 0 :
2015-11-09 18:44:27 +01:00
j = 0
2015-10-02 22:24:46 +02:00
for f , c in db [ toAddress ] . iteritems ( ) :
2015-11-09 18:44:27 +01:00
subwidget = Ui_FolderWidget ( widget , j , toAddress , f , c )
j + = 1
2015-10-02 22:24:46 +02:00
widget . setUnreadCount ( unread )
db . pop ( toAddress , None )
2015-11-09 18:44:27 +01:00
i + = 1
2015-10-02 22:24:46 +02:00
i = 0
for toAddress in db :
2015-10-27 19:24:29 +01:00
widget = Ui_AddressWidget ( treeWidget , i , toAddress , db [ toAddress ] [ " inbox " ] , enabled [ toAddress ] )
2015-10-02 22:24:46 +02:00
j = 0
unread = 0
for folder in folders :
subwidget = Ui_FolderWidget ( widget , j , toAddress , folder , db [ toAddress ] [ folder ] )
unread + = db [ toAddress ] [ folder ]
j + = 1
widget . setUnreadCount ( unread )
2015-10-27 19:50:52 +01:00
widget . setFlags ( widget . flags ( ) | QtCore . Qt . ItemIsEditable )
2015-10-02 22:24:46 +02:00
i + = 1
2015-10-04 10:47:51 +02:00
2015-10-02 22:24:46 +02:00
treeWidget . setSortingEnabled ( True )
2015-03-21 11:37:08 +01:00
2013-11-07 20:35:11 +01:00
def __init__ ( self , parent = None ) :
QtGui . QWidget . __init__ ( self , parent )
self . ui = Ui_MainWindow ( )
self . ui . setupUi ( self )
# Ask the user if we may delete their old version 1 addresses if they
# have any.
2015-10-19 20:03:06 +02:00
for addressInKeysFile in getSortedAccounts ( ) :
status , addressVersionNumber , streamNumber , hash = decodeAddress (
addressInKeysFile )
if addressVersionNumber == 1 :
displayMsg = _translate (
" 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 )
if reply == QtGui . QMessageBox . Yes :
shared . config . remove_section ( addressInKeysFile )
shared . writeKeysFile ( )
2013-11-07 20:35:11 +01:00
# Configure Bitmessage to start on startup (or remove the
# configuration) based on the setting in the keys.dat file
if ' win32 ' in sys . platform or ' win64 ' in sys . platform :
# Auto-startup for Windows
RUN_PATH = " HKEY_CURRENT_USER \\ Software \\ Microsoft \\ Windows \\ CurrentVersion \\ Run "
self . settings = QSettings ( RUN_PATH , QSettings . NativeFormat )
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.
if shared . config . getboolean ( ' bitmessagesettings ' , ' startonlogon ' ) :
self . settings . setValue ( " PyBitmessage " , sys . argv [ 0 ] )
elif ' darwin ' in sys . platform :
# startup for mac
pass
elif ' linux ' in sys . platform :
# startup for linux
pass
2014-08-01 22:35:48 +02:00
self . totalNumberOfBytesReceived = 0
self . totalNumberOfBytesSent = 0
2013-11-07 20:35:11 +01:00
self . timer = QtCore . QTimer ( )
self . timer . start ( 2000 ) # milliseconds
QtCore . QObject . connect ( self . timer , QtCore . SIGNAL ( " timeout() " ) , self . runEveryTwoSeconds )
2015-10-19 17:37:43 +02:00
# e.g. for editing labels
2015-10-04 20:32:17 +02:00
self . recurDepth = 0
2015-10-19 17:37:43 +02:00
# switch back to this when replying
self . replyFromTab = None
2015-10-31 15:27:07 +01:00
2013-11-07 20:35:11 +01:00
self . init_file_menu ( )
self . init_inbox_popup_menu ( )
self . init_identities_popup_menu ( )
self . init_addressbook_popup_menu ( )
self . init_subscriptions_popup_menu ( )
2015-03-21 11:37:08 +01:00
self . init_chan_popup_menu ( )
2013-11-07 20:35:11 +01:00
self . init_sent_popup_menu ( )
self . init_blacklist_popup_menu ( )
2015-10-04 20:32:17 +02:00
2015-03-21 11:37:08 +01:00
# Initialize the user's list of addresses on the 'Chan' tab.
2015-03-23 22:35:56 +01:00
self . rerenderTabTreeChans ( )
2015-03-03 18:17:56 +01:00
2015-03-21 11:37:08 +01:00
# Initialize the user's list of addresses on the 'Messages' tab.
2015-03-23 22:35:56 +01:00
self . rerenderTabTreeMessages ( )
2015-03-03 18:17:56 +01:00
2015-03-21 11:37:08 +01:00
# Set welcome message
self . ui . textEditInboxMessage . setText (
"""
Welcome to easy and secure Bitmessage
2015-03-23 22:35:56 +01:00
* send messages to other people
2015-03-21 11:37:08 +01:00
* send broadcast messages like twitter or
2015-03-23 22:35:56 +01:00
* discuss in chan ( nel ) s with other people
2015-03-21 11:37:08 +01:00
"""
)
2013-05-02 17:53:54 +02:00
2013-06-12 23:12:32 +02:00
# Initialize the address book
2013-09-05 12:31:52 +02:00
self . rerenderAddressBook ( )
2013-06-12 23:12:32 +02:00
# Initialize the Subscriptions
2013-05-24 22:12:16 +02:00
self . rerenderSubscriptions ( )
2013-05-02 17:53:54 +02:00
2013-07-12 10:24:24 +02:00
# Initialize the inbox search
QtCore . QObject . connect ( self . ui . inboxSearchLineEdit , QtCore . SIGNAL (
" returnPressed() " ) , self . inboxSearchLineEditPressed )
2015-03-23 22:35:56 +01:00
QtCore . QObject . connect ( self . ui . inboxSearchLineEditSubscriptions , QtCore . SIGNAL (
" returnPressed() " ) , self . inboxSearchLineEditPressed )
QtCore . QObject . connect ( self . ui . inboxSearchLineEditChans , QtCore . SIGNAL (
" returnPressed() " ) , self . inboxSearchLineEditPressed )
2013-07-12 10:24:24 +02:00
2013-06-12 23:12:32 +02:00
# Initialize the Blacklist or Whitelist
2014-11-22 22:56:41 +01:00
if shared . config . get ( ' bitmessagesettings ' , ' blackwhitelist ' ) == ' white ' :
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 ( )
2014-11-22 22:56:41 +01:00
self . rerenderBlackWhiteList ( )
2013-05-02 17:53:54 +02:00
2015-03-23 22:35:56 +01:00
# Initialize addressbook
2013-06-12 23:12:32 +02:00
QtCore . QObject . connect ( self . ui . tableWidgetAddressBook , QtCore . SIGNAL (
" itemChanged(QTableWidgetItem *) " ) , self . tableWidgetAddressBookItemChanged )
2015-03-23 22:35:56 +01:00
# show messages from message list
2013-06-12 23:12:32 +02:00
QtCore . QObject . connect ( self . ui . tableWidgetInbox , QtCore . SIGNAL (
" itemSelectionChanged () " ) , self . tableWidgetInboxItemClicked )
2015-03-23 22:35:56 +01:00
QtCore . QObject . connect ( self . ui . tableWidgetInboxSubscriptions , QtCore . SIGNAL (
" itemSelectionChanged () " ) , self . tableWidgetInboxItemClicked )
QtCore . QObject . connect ( self . ui . tableWidgetInboxChans , QtCore . SIGNAL (
" itemSelectionChanged () " ) , self . tableWidgetInboxItemClicked )
# tree address lists
2015-03-21 11:37:08 +01:00
QtCore . QObject . connect ( self . ui . treeWidgetYourIdentities , QtCore . SIGNAL (
2015-03-23 22:35:56 +01:00
" itemSelectionChanged () " ) , self . treeWidgetItemClicked )
2015-10-04 10:47:51 +02:00
QtCore . QObject . connect ( self . ui . treeWidgetYourIdentities , QtCore . SIGNAL (
" itemChanged (QTreeWidgetItem *, int) " ) , self . treeWidgetItemChanged )
2015-03-21 11:37:08 +01:00
QtCore . QObject . connect ( self . ui . treeWidgetSubscriptions , QtCore . SIGNAL (
2015-03-23 22:35:56 +01:00
" itemSelectionChanged () " ) , self . treeWidgetItemClicked )
2015-10-27 19:50:52 +01:00
QtCore . QObject . connect ( self . ui . treeWidgetSubscriptions , QtCore . SIGNAL (
" itemChanged (QTreeWidgetItem *, int) " ) , self . treeWidgetItemChanged )
2015-03-23 22:35:56 +01:00
QtCore . QObject . connect ( self . ui . treeWidgetChans , QtCore . SIGNAL (
" itemSelectionChanged () " ) , self . treeWidgetItemClicked )
2015-10-27 19:50:52 +01:00
QtCore . QObject . connect ( self . ui . treeWidgetChans , QtCore . SIGNAL (
" itemChanged (QTreeWidgetItem *, int) " ) , self . treeWidgetItemChanged )
2013-06-12 23:12:32 +02:00
# 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 (
2014-08-06 04:01:01 +02:00
l10n . formatTimestamp ( ) ) )
2013-05-02 17:53:54 +02:00
self . numberOfMessagesProcessed = 0
self . numberOfBroadcastsProcessed = 0
self . numberOfPubkeysProcessed = 0
2015-10-31 15:27:07 +01:00
self . unreadCount = 0
2013-05-02 17:53:54 +02:00
2013-08-27 11:47:14 +02:00
# Set the icon sizes for the identicons
identicon_size = 3 * 7
self . ui . tableWidgetInbox . setIconSize ( QtCore . QSize ( identicon_size , identicon_size ) )
2015-03-23 22:35:56 +01:00
self . ui . treeWidgetChans . setIconSize ( QtCore . QSize ( identicon_size , identicon_size ) )
2015-03-03 18:17:56 +01:00
self . ui . treeWidgetYourIdentities . setIconSize ( QtCore . QSize ( identicon_size , identicon_size ) )
2015-03-21 11:37:08 +01:00
self . ui . treeWidgetSubscriptions . setIconSize ( QtCore . QSize ( identicon_size , identicon_size ) )
2013-08-27 11:47:14 +02:00
self . ui . tableWidgetAddressBook . setIconSize ( QtCore . QSize ( identicon_size , identicon_size ) )
self . ui . tableWidgetBlacklist . setIconSize ( QtCore . QSize ( identicon_size , identicon_size ) )
2013-05-02 17:53:54 +02:00
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 (
2015-03-09 07:35:32 +01:00
" updateSentItemStatusByToAddress(PyQt_PyObject,PyQt_PyObject) " ) , self . updateSentItemStatusByToAddress )
2013-06-12 23:12:32 +02:00
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 (
2013-08-25 01:40:48 +02:00
" updateNumberOfMessagesProcessed() " ) , self . updateNumberOfMessagesProcessed )
2013-06-12 23:12:32 +02:00
QtCore . QObject . connect ( self . UISignalThread , QtCore . SIGNAL (
2013-08-25 01:40:48 +02:00
" updateNumberOfPubkeysProcessed() " ) , self . updateNumberOfPubkeysProcessed )
2013-06-12 23:12:32 +02:00
QtCore . QObject . connect ( self . UISignalThread , QtCore . SIGNAL (
2013-08-25 01:40:48 +02:00
" updateNumberOfBroadcastsProcessed() " ) , self . updateNumberOfBroadcastsProcessed )
2013-06-12 23:12:32 +02:00
QtCore . QObject . connect ( self . UISignalThread , QtCore . SIGNAL (
" setStatusIcon(PyQt_PyObject) " ) , self . setStatusIcon )
2013-11-29 02:05:53 +01:00
QtCore . QObject . connect ( self . UISignalThread , QtCore . SIGNAL (
" changedInboxUnread(PyQt_PyObject) " ) , self . changedInboxUnread )
2013-06-12 23:12:32 +02:00
QtCore . QObject . connect ( self . UISignalThread , QtCore . SIGNAL (
" rerenderInboxFromLabels() " ) , self . rerenderInboxFromLabels )
2013-09-05 12:31:52 +02:00
QtCore . QObject . connect ( self . UISignalThread , QtCore . SIGNAL (
" rerenderSentToLabels() " ) , self . rerenderSentToLabels )
QtCore . QObject . connect ( self . UISignalThread , QtCore . SIGNAL (
" rerenderAddressBook() " ) , self . rerenderAddressBook )
2013-06-12 23:12:32 +02:00
QtCore . QObject . connect ( self . UISignalThread , QtCore . SIGNAL (
" rerenderSubscriptions() " ) , self . rerenderSubscriptions )
2014-11-22 22:13:35 +01:00
QtCore . QObject . connect ( self . UISignalThread , QtCore . SIGNAL (
2014-11-22 22:56:41 +01:00
" rerenderBlackWhiteList() " ) , self . rerenderBlackWhiteList )
2013-06-12 23:12:32 +02:00
QtCore . QObject . connect ( self . UISignalThread , QtCore . SIGNAL (
" removeInboxRowByMsgid(PyQt_PyObject) " ) , self . removeInboxRowByMsgid )
2015-10-19 22:33:18 +02:00
QtCore . QObject . connect ( self . UISignalThread , QtCore . SIGNAL (
" newVersionAvailable(PyQt_PyObject) " ) , self . newVersionAvailable )
2013-09-05 02:14:25 +02:00
QtCore . QObject . connect ( self . UISignalThread , QtCore . SIGNAL (
" displayAlert(PyQt_PyObject,PyQt_PyObject,PyQt_PyObject) " ) , self . displayAlert )
2013-05-02 17:53:54 +02:00
self . UISignalThread . start ( )
2013-08-15 00:59:50 +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 ( )
2015-03-21 11:37:08 +01:00
self . rerenderComboBoxSendFromBroadcast ( )
2013-08-15 00:59:50 +02:00
2015-03-03 20:04:12 +01:00
# Put the TTL slider in the correct spot
TTL = shared . config . getint ( ' bitmessagesettings ' , ' ttl ' )
if TTL < 3600 : # an hour
TTL = 3600
elif TTL > 28 * 24 * 60 * 60 : # 28 days
TTL = 28 * 24 * 60 * 60
self . ui . horizontalSliderTTL . setSliderPosition ( ( TTL - 3600 ) * * ( 1 / 3.199 ) )
self . updateHumanFriendlyTTLDescription ( TTL )
QtCore . QObject . connect ( self . ui . horizontalSliderTTL , QtCore . SIGNAL (
" valueChanged(int) " ) , self . updateTTL )
2015-11-08 21:44:02 +01:00
self . initSettings ( )
2013-08-15 00:59:50 +02:00
# Check to see whether we can connect to namecoin. Hide the 'Fetch Namecoin ID' button if we can't.
2013-08-15 01:46:59 +02:00
try :
options = { }
options [ " type " ] = shared . config . get ( ' bitmessagesettings ' , ' namecoinrpctype ' )
options [ " host " ] = shared . config . get ( ' bitmessagesettings ' , ' namecoinrpchost ' )
options [ " port " ] = shared . config . get ( ' bitmessagesettings ' , ' namecoinrpcport ' )
options [ " user " ] = shared . config . get ( ' bitmessagesettings ' , ' namecoinrpcuser ' )
options [ " password " ] = shared . config . get ( ' bitmessagesettings ' , ' namecoinrpcpassword ' )
nc = namecoinConnection ( options )
2015-03-21 11:37:08 +01:00
if nc . test ( ) [ 0 ] == ' failed ' :
self . ui . pushButtonFetchNamecoinID . hide ( )
2013-08-15 01:46:59 +02:00
except :
2015-11-18 16:22:17 +01:00
logger . error ( ' There was a problem testing for a Namecoin daemon. Hiding the Fetch Namecoin ID button ' )
2015-03-21 11:37:08 +01:00
self . ui . pushButtonFetchNamecoinID . hide ( )
2015-03-19 18:44:10 +01:00
def updateTTL ( self , sliderPosition ) :
TTL = int ( sliderPosition * * 3.199 + 3600 )
self . updateHumanFriendlyTTLDescription ( TTL )
shared . config . set ( ' bitmessagesettings ' , ' ttl ' , str ( TTL ) )
shared . writeKeysFile ( )
def updateHumanFriendlyTTLDescription ( self , TTL ) :
numberOfHours = int ( round ( TTL / ( 60 * 60 ) ) )
if numberOfHours < 48 :
if numberOfHours == 1 :
self . ui . labelHumanFriendlyTTLDescription . setText ( _translate ( " MainWindow " , " 1 hour " ) )
else :
self . ui . labelHumanFriendlyTTLDescription . setText ( _translate ( " MainWindow " , " % 1 hours " ) . arg ( numberOfHours ) )
else :
numberOfDays = int ( round ( TTL / ( 24 * 60 * 60 ) ) )
self . ui . labelHumanFriendlyTTLDescription . setText ( _translate ( " MainWindow " , " % 1 days " ) . arg ( numberOfDays ) )
2013-07-24 17:46:28 +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 ( )
2015-03-03 18:17:56 +01:00
self . ui . tabWidget . setCurrentIndex ( 2 )
2013-05-07 23:22:34 +02:00
2015-03-23 22:35:56 +01:00
# Show the program window and select channels tab
def appIndicatorChannel ( self ) :
2013-05-07 23:22:34 +02:00
self . appIndicatorShow ( )
2015-03-03 18:17:56 +01:00
self . ui . tabWidget . setCurrentIndex ( 3 )
2015-10-31 15:27:07 +01:00
def propagateUnreadCount ( self , address = None , folder = " inbox " , widget = None , type = 1 ) :
2015-10-31 20:05:58 +01:00
def updateUnreadCount ( item ) :
2015-11-01 11:09:36 +01:00
# if refreshing the account root, we need to rescan folders
if type == 0 or ( folder is None and isinstance ( item , Ui_FolderWidget ) ) :
2015-10-31 20:05:58 +01:00
if addressItem . type == ' subscription ' or addressItem . type == ' mailinglist ' :
xAddress = " fromaddress "
else :
xAddress = " toaddress "
2015-11-01 11:09:36 +01:00
xFolder = folder
if isinstance ( item , Ui_FolderWidget ) :
xFolder = item . folderName
if address and xFolder :
queryreturn = sqlQuery ( " SELECT COUNT(*) FROM inbox WHERE " + xAddress + " = ? AND folder = ? AND read = 0 " , address , xFolder )
2015-10-31 15:27:07 +01:00
elif address :
2015-10-31 20:05:58 +01:00
queryreturn = sqlQuery ( " SELECT COUNT(*) FROM inbox WHERE " + xAddress + " = ? AND read = 0 " , address )
2015-11-01 11:09:36 +01:00
elif xFolder :
queryreturn = sqlQuery ( " SELECT COUNT(*) FROM inbox WHERE folder = ? AND read = 0 " , xFolder )
2015-10-31 15:27:07 +01:00
else :
queryreturn = sqlQuery ( " SELECT COUNT(*) FROM inbox WHERE read = 0 " )
for row in queryreturn :
item . setUnreadCount ( int ( row [ 0 ] ) )
if isinstance ( item , Ui_AddressWidget ) :
self . drawTrayIcon ( self . currentTrayIconFileName , self . findInboxUnreadCount ( ) )
2015-11-01 11:09:36 +01:00
elif type == 1 :
item . setUnreadCount ( item . unreadCount + 1 )
if isinstance ( item , Ui_AddressWidget ) :
self . drawTrayIcon ( self . currentTrayIconFileName , self . findInboxUnreadCount ( self . unreadCount + 1 ) )
elif type == - 1 :
item . setUnreadCount ( item . unreadCount - 1 )
if isinstance ( item , Ui_AddressWidget ) :
self . drawTrayIcon ( self . currentTrayIconFileName , self . findInboxUnreadCount ( self . unreadCount - 1 ) )
2015-10-31 15:27:07 +01:00
if widget == None :
widgets = [ self . ui . treeWidgetYourIdentities , self . ui . treeWidgetSubscriptions , self . ui . treeWidgetChans ]
else :
widgets = [ widget ]
for treeWidget in widgets :
root = treeWidget . invisibleRootItem ( )
for i in range ( root . childCount ( ) ) :
addressItem = root . child ( i )
if address is not None and addressItem . data ( 0 , QtCore . Qt . UserRole ) != address :
continue
2015-10-31 20:05:58 +01:00
updateUnreadCount ( addressItem )
2015-10-31 15:27:07 +01:00
if addressItem . childCount == 0 :
continue
for j in range ( addressItem . childCount ( ) ) :
folderItem = addressItem . child ( j )
2015-11-01 11:09:36 +01:00
if folder is not None and folderItem . folderName != folder :
2015-10-31 15:27:07 +01:00
continue
2015-10-31 20:05:58 +01:00
updateUnreadCount ( folderItem )
2013-05-07 23:22:34 +02:00
2013-07-12 10:24:24 +02:00
# Load Sent items from database
2015-03-23 22:35:56 +01:00
def loadSent ( self , tableWidget , account , where = " " , what = " " ) :
2013-07-12 10:42:52 +02:00
what = " % " + what + " % "
2015-03-23 22:35:56 +01:00
if where == _translate ( " MainWindow " , " To " ) :
2013-07-12 10:42:52 +02:00
where = " toaddress "
2015-03-23 22:35:56 +01:00
elif where == _translate ( " MainWindow " , " From " ) :
2013-07-12 10:42:52 +02:00
where = " fromaddress "
2015-03-23 22:35:56 +01:00
elif where == _translate ( " MainWindow " , " Subject " ) :
2013-07-12 10:42:52 +02:00
where = " subject "
2015-03-23 22:35:56 +01:00
elif where == _translate ( " MainWindow " , " Message " ) :
2013-07-12 10:42:52 +02:00
where = " message "
else :
where = " toaddress || fromaddress || subject || message "
2015-10-03 12:12:18 +02:00
tableWidget . setSortingEnabled ( False )
2015-10-23 12:38:59 +02:00
if tableWidget == self . ui . tableWidgetInboxChans or tableWidget == self . ui . tableWidgetInboxSubscriptions :
2015-10-23 19:23:16 +02:00
tableWidget . setColumnHidden ( 0 , True )
tableWidget . setColumnHidden ( 1 , False )
2015-10-23 12:38:59 +02:00
xAddress = ' toaddress '
else :
2015-10-23 19:23:16 +02:00
tableWidget . setColumnHidden ( 0 , False )
tableWidget . setColumnHidden ( 1 , True )
2015-10-23 12:38:59 +02:00
xAddress = ' fromaddress '
2013-09-03 00:24:22 +02:00
sqlStatement = '''
2013-10-13 19:45:30 +02:00
SELECT toaddress , fromaddress , subject , status , ackdata , lastactiontime
2015-10-23 12:38:59 +02:00
FROM sent WHERE ''' + xAddress + ''' = ? AND folder = " sent " AND % s LIKE ?
2013-07-12 10:42:52 +02:00
ORDER BY lastactiontime
2013-07-12 11:02:21 +02:00
''' % (where,)
2013-07-12 10:42:52 +02:00
2015-11-01 10:09:04 +01:00
tableWidget . setRowCount ( 0 )
2015-10-03 12:12:18 +02:00
acct = None
2015-03-23 22:35:56 +01:00
queryreturn = sqlQuery ( sqlStatement , account , what )
2013-07-12 10:24:24 +02:00
for row in queryreturn :
2013-10-13 19:45:30 +02:00
toAddress , fromAddress , subject , status , ackdata , lastactiontime = row
2013-07-12 10:24:24 +02:00
subject = shared . fixPotentiallyInvalidUTF8Data ( subject )
2015-10-03 12:12:18 +02:00
if acct is None :
acct = accountClass ( fromAddress )
acct . parseMessage ( toAddress , fromAddress , subject , " " )
2013-07-12 10:24:24 +02:00
2015-03-23 22:35:56 +01:00
tableWidget . insertRow ( 0 )
2015-10-03 12:12:18 +02:00
toAddressItem = QtGui . QTableWidgetItem ( unicode ( acct . toLabel , ' utf-8 ' ) )
toAddressItem . setToolTip ( unicode ( acct . toLabel , ' utf-8 ' ) )
2013-11-05 22:36:15 +01:00
toAddressItem . setIcon ( avatarize ( toAddress ) )
toAddressItem . setData ( Qt . UserRole , str ( toAddress ) )
2015-10-31 10:12:12 +01:00
toAddressItem . setTextColor ( AccountColor ( toAddress ) . accountColor ( ) )
2013-11-05 22:36:15 +01:00
toAddressItem . setFlags (
2013-07-12 10:24:24 +02:00
QtCore . Qt . ItemIsSelectable | QtCore . Qt . ItemIsEnabled )
2015-03-23 22:35:56 +01:00
tableWidget . setItem ( 0 , 0 , toAddressItem )
2013-11-05 22:36:15 +01:00
2015-10-03 12:12:18 +02:00
fromAddressItem = QtGui . QTableWidgetItem ( unicode ( acct . fromLabel , ' utf-8 ' ) )
fromAddressItem . setToolTip ( unicode ( acct . fromLabel , ' utf-8 ' ) )
2013-11-05 22:36:15 +01:00
fromAddressItem . setIcon ( avatarize ( fromAddress ) )
fromAddressItem . setData ( Qt . UserRole , str ( fromAddress ) )
2015-10-31 10:12:12 +01:00
fromAddressItem . setTextColor ( AccountColor ( fromAddress ) . accountColor ( ) )
2013-11-05 22:36:15 +01:00
fromAddressItem . setFlags (
2013-07-12 10:24:24 +02:00
QtCore . Qt . ItemIsSelectable | QtCore . Qt . ItemIsEnabled )
2015-03-23 22:35:56 +01:00
tableWidget . setItem ( 0 , 1 , fromAddressItem )
2013-11-05 22:36:15 +01:00
2015-10-03 12:12:18 +02:00
subjectItem = QtGui . QTableWidgetItem ( unicode ( acct . subject , ' utf-8 ' ) )
subjectItem . setToolTip ( unicode ( acct . subject , ' utf-8 ' ) )
2015-10-03 17:24:21 +02:00
subjectItem . setData ( Qt . UserRole , str ( subject ) )
2013-11-05 22:36:15 +01:00
subjectItem . setFlags (
2013-07-12 10:24:24 +02:00
QtCore . Qt . ItemIsSelectable | QtCore . Qt . ItemIsEnabled )
2015-03-23 22:35:56 +01:00
tableWidget . setItem ( 0 , 2 , subjectItem )
2013-11-05 22:36:15 +01:00
2013-07-12 10:24:24 +02:00
if status == ' awaitingpubkey ' :
statusText = _translate (
2013-11-29 02:52:05 +01:00
" MainWindow " , " Waiting for their encryption key. Will request it again soon. " )
2013-07-12 10:24:24 +02:00
elif status == ' doingpowforpubkey ' :
statusText = _translate (
" MainWindow " , " Encryption key request queued. " )
elif status == ' msgqueued ' :
statusText = _translate (
" MainWindow " , " Queued. " )
elif status == ' msgsent ' :
2013-11-29 02:52:05 +01:00
statusText = _translate ( " MainWindow " , " Message sent. Waiting for acknowledgement. Sent at % 1 " ) . arg (
2014-08-06 04:01:01 +02:00
l10n . formatTimestamp ( lastactiontime ) )
2013-07-22 07:10:22 +02:00
elif status == ' msgsentnoackexpected ' :
statusText = _translate ( " MainWindow " , " Message sent. Sent at % 1 " ) . arg (
2014-08-06 04:01:01 +02:00
l10n . formatTimestamp ( lastactiontime ) )
2013-07-12 10:24:24 +02:00
elif status == ' doingmsgpow ' :
statusText = _translate (
" MainWindow " , " Need to do work to send message. Work is queued. " )
elif status == ' ackreceived ' :
statusText = _translate ( " MainWindow " , " Acknowledgement of the message received % 1 " ) . arg (
2014-08-06 04:01:01 +02:00
l10n . formatTimestamp ( lastactiontime ) )
2013-07-12 10:24:24 +02:00
elif status == ' broadcastqueued ' :
statusText = _translate (
" MainWindow " , " Broadcast queued. " )
elif status == ' broadcastsent ' :
2014-08-06 04:01:01 +02:00
statusText = _translate ( " MainWindow " , " Broadcast on % 1 " ) . arg (
l10n . formatTimestamp ( lastactiontime ) )
2013-07-12 10:24:24 +02:00
elif status == ' toodifficult ' :
statusText = _translate ( " MainWindow " , " Problem: The work demanded by the recipient is more difficult than you are willing to do. % 1 " ) . arg (
2014-08-06 04:01:01 +02:00
l10n . formatTimestamp ( lastactiontime ) )
2013-07-12 10:24:24 +02:00
elif status == ' badkey ' :
statusText = _translate ( " MainWindow " , " Problem: The recipient \' s encryption key is no good. Could not encrypt message. % 1 " ) . arg (
2014-08-06 04:01:01 +02:00
l10n . formatTimestamp ( lastactiontime ) )
2013-07-12 10:24:24 +02:00
elif status == ' forcepow ' :
statusText = _translate (
" MainWindow " , " Forced difficulty override. Send should start soon. " )
else :
2014-08-06 04:01:01 +02:00
statusText = _translate ( " MainWindow " , " Unknown status: % 1 % 2 " ) . arg ( status ) . arg (
l10n . formatTimestamp ( lastactiontime ) )
2013-07-12 10:24:24 +02:00
newItem = myTableWidgetItem ( statusText )
newItem . setToolTip ( statusText )
newItem . setData ( Qt . UserRole , QByteArray ( ackdata ) )
newItem . setData ( 33 , int ( lastactiontime ) )
newItem . setFlags (
QtCore . Qt . ItemIsSelectable | QtCore . Qt . ItemIsEnabled )
2015-03-23 22:35:56 +01:00
tableWidget . setItem ( 0 , 3 , newItem )
2015-10-03 12:12:18 +02:00
tableWidget . setSortingEnabled ( False )
tableWidget . horizontalHeader ( ) . setSortIndicator ( 3 , Qt . DescendingOrder )
2015-11-19 17:37:34 +01:00
tableWidget . keyPressEvent = self . tableWidgetSentKeyPressEvent
2013-07-12 10:24:24 +02:00
2015-03-23 22:35:56 +01:00
# Load messages from database file
2015-03-21 11:37:08 +01:00
def loadMessagelist ( self , tableWidget , account , folder = " inbox " , where = " " , what = " " ) :
2015-03-23 22:35:56 +01:00
if folder == ' sent ' :
self . loadSent ( tableWidget , account , where , what )
return
2015-03-19 18:25:50 +01:00
what = " % " + what + " % "
2015-03-23 22:35:56 +01:00
if where == _translate ( " MainWindow " , " To " ) :
2015-03-19 18:25:50 +01:00
where = " toaddress "
2015-03-23 22:35:56 +01:00
elif where == _translate ( " MainWindow " , " From " ) :
2015-03-19 18:25:50 +01:00
where = " fromaddress "
2015-03-23 22:35:56 +01:00
elif where == _translate ( " MainWindow " , " Subject " ) :
2015-03-19 18:25:50 +01:00
where = " subject "
2015-03-23 22:35:56 +01:00
elif where == _translate ( " MainWindow " , " Message " ) :
2015-03-19 18:25:50 +01:00
where = " message "
else :
where = " toaddress || fromaddress || subject || message "
2015-10-10 19:58:01 +02:00
if tableWidget == self . ui . tableWidgetInboxSubscriptions :
xAddress = " fromaddress "
else :
xAddress = " toaddress "
2015-11-01 11:08:41 +01:00
if folder is not None :
2015-10-03 12:12:18 +02:00
sqlStatement = '''
SELECT folder , msgid , toaddress , fromaddress , subject , received , read
2015-10-10 19:58:01 +02:00
FROM inbox WHERE ''' + xAddress + ''' = ? AND folder = ? AND % s LIKE ?
2015-10-03 12:12:18 +02:00
ORDER BY received
''' % (where)
queryreturn = sqlQuery ( sqlStatement , account , folder , what )
else :
sqlStatement = '''
SELECT folder , msgid , toaddress , fromaddress , subject , received , read
2015-10-10 19:58:01 +02:00
FROM inbox WHERE ''' + xAddress + ''' = ? AND folder != " trash " AND % s LIKE ?
2015-10-03 12:12:18 +02:00
ORDER BY received
''' % (where)
queryreturn = sqlQuery ( sqlStatement , account , what )
2015-03-19 18:25:50 +01:00
2015-11-01 10:09:04 +01:00
tableWidget . setRowCount ( 0 )
2015-03-19 18:25:50 +01:00
2015-10-03 12:12:18 +02:00
tableWidget . setColumnHidden ( 0 , True )
tableWidget . setColumnHidden ( 1 , False )
tableWidget . setSortingEnabled ( False )
2015-03-19 18:25:50 +01:00
font = QFont ( )
font . setBold ( True )
2015-10-03 01:17:47 +02:00
acct = None
2015-03-19 18:25:50 +01:00
for row in queryreturn :
2015-10-03 12:12:18 +02:00
msgfolder , msgid , toAddress , fromAddress , subject , received , read = row
2015-10-03 01:17:47 +02:00
if acct is None :
2015-10-10 19:58:01 +02:00
if tableWidget == self . ui . tableWidgetInboxSubscriptions :
acct = accountClass ( fromAddress )
else :
acct = accountClass ( toAddress )
2015-03-19 18:25:50 +01:00
subject = shared . fixPotentiallyInvalidUTF8Data ( subject )
2015-10-03 01:17:47 +02:00
acct . parseMessage ( toAddress , fromAddress , subject , " " )
2015-03-19 18:25:50 +01:00
# message row
2015-03-21 11:37:08 +01:00
tableWidget . insertRow ( 0 )
2015-03-19 18:25:50 +01:00
# to
2015-10-03 12:12:18 +02:00
to_item = QtGui . QTableWidgetItem ( unicode ( acct . toLabel , ' utf-8 ' ) )
to_item . setToolTip ( unicode ( acct . toLabel , ' utf-8 ' ) )
2015-03-19 18:25:50 +01:00
to_item . setFlags (
QtCore . Qt . ItemIsSelectable | QtCore . Qt . ItemIsEnabled )
if not read :
to_item . setFont ( font )
to_item . setData ( Qt . UserRole , str ( toAddress ) )
2015-10-31 10:12:12 +01:00
to_item . setTextColor ( AccountColor ( toAddress ) . accountColor ( ) )
2015-03-19 18:25:50 +01:00
to_item . setIcon ( avatarize ( toAddress ) )
2015-03-21 11:37:08 +01:00
tableWidget . setItem ( 0 , 0 , to_item )
2015-03-19 18:25:50 +01:00
# from
2015-10-03 12:12:18 +02:00
from_item = QtGui . QTableWidgetItem ( unicode ( acct . fromLabel , ' utf-8 ' ) )
from_item . setToolTip ( unicode ( acct . fromLabel , ' utf-8 ' ) )
2015-03-19 18:25:50 +01:00
from_item . setFlags (
QtCore . Qt . ItemIsSelectable | QtCore . Qt . ItemIsEnabled )
if not read :
from_item . setFont ( font )
from_item . setData ( Qt . UserRole , str ( fromAddress ) )
2015-10-31 10:12:12 +01:00
from_item . setTextColor ( AccountColor ( fromAddress ) . accountColor ( ) )
2015-03-19 18:25:50 +01:00
from_item . setIcon ( avatarize ( fromAddress ) )
2015-03-21 11:37:08 +01:00
tableWidget . setItem ( 0 , 1 , from_item )
2015-03-19 18:25:50 +01:00
# subject
2015-10-03 01:17:47 +02:00
subject_item = QtGui . QTableWidgetItem ( unicode ( acct . subject , ' utf-8 ' ) )
subject_item . setToolTip ( unicode ( acct . subject , ' utf-8 ' ) )
2015-10-03 17:24:21 +02:00
subject_item . setData ( Qt . UserRole , str ( subject ) )
2015-03-19 18:25:50 +01:00
subject_item . setFlags (
QtCore . Qt . ItemIsSelectable | QtCore . Qt . ItemIsEnabled )
if not read :
subject_item . setFont ( font )
2015-03-21 11:37:08 +01:00
tableWidget . setItem ( 0 , 2 , subject_item )
2015-03-19 18:25:50 +01:00
# time received
time_item = myTableWidgetItem ( l10n . formatTimestamp ( received ) )
time_item . setToolTip ( l10n . formatTimestamp ( received ) )
time_item . setData ( Qt . UserRole , QByteArray ( msgid ) )
time_item . setData ( 33 , int ( received ) )
time_item . setFlags (
QtCore . Qt . ItemIsSelectable | QtCore . Qt . ItemIsEnabled )
if not read :
time_item . setFont ( font )
2015-03-21 11:37:08 +01:00
tableWidget . setItem ( 0 , 3 , time_item )
2015-03-19 18:25:50 +01:00
2015-10-03 12:12:18 +02:00
tableWidget . horizontalHeader ( ) . setSortIndicator ( 3 , Qt . DescendingOrder )
tableWidget . setSortingEnabled ( True )
2015-03-21 11:37:08 +01:00
tableWidget . keyPressEvent = self . tableWidgetInboxKeyPressEvent
2015-03-19 18:25:50 +01:00
2013-05-07 23:22:34 +02:00
# create application indicator
2013-06-12 23:12:32 +02:00
def appIndicatorInit ( self , app ) :
2013-11-29 02:05:53 +01:00
self . initTrayIcon ( " can-icon-24px-red.png " , app )
2015-02-21 14:24:17 +01:00
traySignal = " activated(QSystemTrayIcon::ActivationReason) "
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 )
2015-03-23 22:35:56 +01:00
# Channels
2015-03-03 18:17:56 +01:00
actionSubscribe = QtGui . QAction ( _translate (
2015-03-23 22:35:56 +01:00
" MainWindow " , " Channel " ) , m , checkable = False )
actionSubscribe . triggered . connect ( self . appIndicatorChannel )
2015-03-03 18:17:56 +01:00
m . addAction ( actionSubscribe )
2013-05-07 23:22:34 +02:00
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-08-27 02:01:19 +02:00
queryreturn = sqlQuery (
''' SELECT toaddress, read FROM inbox WHERE msgid=? ''' , inventoryHash )
2013-05-14 17:06:01 +02:00
for row in queryreturn :
toAddress , read = row
if not read :
2015-10-13 23:36:09 +02:00
if toAddress == str_broadcast_subscribers :
2013-05-14 17:06:01 +02:00
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
2013-08-27 02:01:19 +02:00
queryreturn = sqlQuery (
2013-06-12 23:12:32 +02:00
''' SELECT msgid, toaddress, read FROM inbox where folder= ' inbox ' ''' )
2013-05-10 21:47:01 +02:00
for row in queryreturn :
msgid , toAddress , read = row
try :
2015-10-13 23:36:09 +02:00
if toAddress == str_broadcast_subscribers :
toLabel = 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 :
2015-10-13 23:36:09 +02:00
if toLabel == 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 :
2015-11-18 16:22:17 +01:00
logger . warning ( ' 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
2015-11-18 16:22:17 +01:00
logger . warning ( ' 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 :
2015-11-18 16:22:17 +01:00
logger . warning ( ' 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
2015-10-13 23:36:09 +02:00
if toLabel == str_broadcast_subscribers :
2013-05-14 17:06:01 +02:00
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-08-01 15:48:01 +02:00
# returns true if the given sound category is a connection sound
# rather than a received message sound
def isConnectionSound ( self , category ) :
if ( category is self . SOUND_CONNECTED or
category is self . SOUND_DISCONNECTED or
category is self . SOUND_CONNECTION_GREEN ) :
return True
return False
2013-07-15 18:01:12 +02:00
# play a sound
def playSound ( self , category , label ) :
2013-08-01 15:48:01 +02:00
# filename of the sound to be played
2013-07-15 18:01:12 +02:00
soundFilename = None
2013-08-01 15:48:01 +02:00
# whether to play a sound or not
2013-07-31 23:25:34 +02:00
play = True
2013-07-15 18:01:12 +02:00
2013-08-01 15:48:01 +02:00
# if the address had a known label in the address book
2013-07-15 18:01:12 +02:00
if label is not None :
2013-07-31 23:25:34 +02:00
# Does a sound file exist for this particular contact?
2013-07-15 18:01:12 +02:00
if ( os . path . isfile ( shared . appdata + ' sounds/ ' + label + ' .wav ' ) or
os . path . isfile ( shared . appdata + ' sounds/ ' + label + ' .mp3 ' ) ) :
soundFilename = shared . appdata + ' sounds/ ' + label
2013-07-31 23:25:34 +02:00
# Avoid making sounds more frequently than the threshold.
# This suppresses playing sounds repeatedly when there
# are many new messages
if ( soundFilename is None and
2013-08-01 15:48:01 +02:00
not self . isConnectionSound ( category ) ) :
# elapsed time since the last sound was played
2013-07-31 23:25:34 +02:00
dt = datetime . datetime . now ( ) - self . lastSoundTime
2013-08-01 15:48:01 +02:00
# suppress sounds which are more frequent than the threshold
2013-07-31 23:25:34 +02:00
if dt . total_seconds ( ) < self . maxSoundFrequencySec :
play = False
2013-07-15 18:01:12 +02:00
if soundFilename is None :
2013-08-01 15:48:01 +02:00
# the sound is for an address which exists in the address book
2013-07-15 18:01:12 +02:00
if category is self . SOUND_KNOWN :
soundFilename = shared . appdata + ' sounds/known '
2013-08-01 15:48:01 +02:00
# the sound is for an unknown address
2013-07-15 18:01:12 +02:00
elif category is self . SOUND_UNKNOWN :
soundFilename = shared . appdata + ' sounds/unknown '
2013-08-01 15:48:01 +02:00
# initial connection sound
2013-07-15 18:01:12 +02:00
elif category is self . SOUND_CONNECTED :
soundFilename = shared . appdata + ' sounds/connected '
2013-08-01 15:48:01 +02:00
# disconnected sound
2013-07-15 18:01:12 +02:00
elif category is self . SOUND_DISCONNECTED :
soundFilename = shared . appdata + ' sounds/disconnected '
2013-08-01 15:48:01 +02:00
# sound when the connection status becomes green
2013-07-15 18:01:12 +02:00
elif category is self . SOUND_CONNECTION_GREEN :
2013-07-31 23:25:34 +02:00
soundFilename = shared . appdata + ' sounds/green '
2013-07-15 18:01:12 +02:00
2013-07-31 23:25:34 +02:00
if soundFilename is not None and play is True :
2013-08-01 15:48:01 +02:00
if not self . isConnectionSound ( category ) :
# record the last time that a received message sound was played
self . lastSoundTime = datetime . datetime . now ( )
2013-08-01 10:58:30 +02:00
2013-07-15 18:01:12 +02:00
# if not wav then try mp3 format
if not os . path . isfile ( soundFilename + ' .wav ' ) :
soundFilename = soundFilename + ' .mp3 '
else :
soundFilename = soundFilename + ' .wav '
if os . path . isfile ( soundFilename ) :
if ' linux ' in sys . platform :
# Note: QSound was a nice idea but it didn't work
if ' .mp3 ' in soundFilename :
2013-08-11 13:07:54 +02:00
gst_available = False
2013-07-20 11:55:03 +02:00
try :
subprocess . call ( [ " gst123 " , soundFilename ] ,
stdin = subprocess . PIPE ,
stdout = subprocess . PIPE )
2013-08-11 13:07:54 +02:00
gst_available = True
2013-07-20 11:55:03 +02:00
except :
2015-11-18 16:22:17 +01:00
logger . warning ( " WARNING: gst123 must be installed in order to play mp3 sounds " )
2013-08-11 13:07:54 +02:00
if not gst_available :
try :
subprocess . call ( [ " mpg123 " , soundFilename ] ,
stdin = subprocess . PIPE ,
stdout = subprocess . PIPE )
gst_available = True
except :
2015-11-18 16:22:17 +01:00
logger . warning ( " WARNING: mpg123 must be installed in order to play mp3 sounds " )
2013-07-15 18:01:12 +02:00
else :
2013-07-20 11:55:03 +02:00
try :
subprocess . call ( [ " aplay " , soundFilename ] ,
stdin = subprocess . PIPE ,
stdout = subprocess . PIPE )
except :
2015-11-18 16:22:17 +01:00
logger . warning ( " WARNING: aplay must be installed in order to play WAV sounds " )
2013-07-15 18:01:12 +02:00
elif sys . platform [ 0 : 3 ] == ' win ' :
# use winsound on Windows
import winsound
winsound . PlaySound ( soundFilename , winsound . SND_FILENAME )
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
2013-07-15 18:01:12 +02:00
def notifierShow ( self , title , subtitle , fromCategory , label ) :
2013-05-11 18:33:16 +02:00
global withMessagingMenu
2013-07-15 18:01:12 +02:00
2014-10-24 04:39:34 +02:00
self . playSound ( fromCategory , label )
2013-07-15 18:01:12 +02:00
2013-05-11 18:33:16 +02:00
if withMessagingMenu :
2013-06-12 23:12:32 +02:00
n = Notify . Notification . new (
title , subtitle , ' notification-message-email ' )
2013-11-07 05:41:37 +01:00
try :
n . show ( )
except :
# n.show() has been known to throw this exception:
# gi._glib.GError: GDBus.Error:org.freedesktop.Notifications.
# MaxNotificationsExceeded: Exceeded maximum number of
# notifications
pass
2013-05-11 18:33:16 +02:00
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
2015-03-03 18:17:56 +01:00
# set delete key in inbox
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 ( )
2015-10-22 23:16:44 +02:00
return QtGui . QTableWidget . keyPressEvent ( self . getCurrentMessagelist ( ) , event )
2013-05-02 17:53:54 +02:00
2015-11-19 17:37:34 +01:00
# set delete key in inbox
def tableWidgetSentKeyPressEvent ( self , event ) :
if event . key ( ) == QtCore . Qt . Key_Delete :
self . on_action_SentTrash ( )
return QtGui . QTableWidget . keyPressEvent ( self . getCurrentMessagelist ( ) , event )
2015-03-03 18:17:56 +01:00
# menu button 'manage keys'
2013-05-02 17:53:54 +02:00
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 :
2014-09-15 08:34:33 +02:00
shared . openKeysFile ( )
2013-05-02 17:53:54 +02:00
2015-03-03 18:17:56 +01:00
# menu button 'delete all treshed messages'
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
2013-08-27 02:01:19 +02:00
sqlStoredProcedure ( ' deleteandvacuume ' )
2015-11-01 09:02:20 +01:00
self . rerenderTabTreeMessages ( )
self . rerenderTabTreeSubscriptions ( )
self . rerenderTabTreeChans ( )
if self . getCurrentFolder ( self . ui . treeWidgetYourIdentities ) == " trash " :
self . loadMessagelist ( self . ui . tableWidgetInbox , self . getCurrentAccount ( self . ui . treeWidgetYourIdentities ) , " trash " )
elif self . getCurrentFolder ( self . ui . treeWidgetSubscriptions ) == " trash " :
self . loadMessagelist ( self . ui . tableWidgetInboxSubscriptions , self . getCurrentAccount ( self . ui . treeWidgetSubscriptions ) , " trash " )
elif self . getCurrentFolder ( self . ui . treeWidgetChans ) == " trash " :
self . loadMessagelist ( self . ui . tableWidgetInboxChans , self . getCurrentAccount ( self . ui . treeWidgetChans ) , " trash " )
2013-05-28 22:50:09 +02:00
2015-03-03 18:17:56 +01:00
# menu botton 'regenerate deterministic addresses'
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. " ) )
2014-09-10 22:47:51 +02:00
return
streamNumberForAddress = int (
self . regenerateAddressesDialogInstance . ui . lineEditStreamNumber . text ( ) )
try :
addressVersionNumber = int (
self . regenerateAddressesDialogInstance . ui . lineEditAddressVersionNumber . text ( ) )
except :
QMessageBox . about ( self , _translate ( " MainWindow " , " Bad address version number " ) , _translate (
" MainWindow " , " Your address version number must be a number: either 3 or 4. " ) )
return
if addressVersionNumber < 3 or addressVersionNumber > 4 :
QMessageBox . about ( self , _translate ( " MainWindow " , " Bad address version number " ) , _translate (
" MainWindow " , " Your address version number must be either 3 or 4. " ) )
return
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 ( ) ) )
self . ui . tabWidget . setCurrentIndex ( 3 )
2013-05-02 17:53:54 +02:00
2015-03-03 18:17:56 +01:00
# opens 'join chan' dialog
2013-07-22 07:10:22 +02:00
def click_actionJoinChan ( self ) :
self . newChanDialogInstance = newChanDialog ( self )
if self . newChanDialogInstance . exec_ ( ) :
if self . newChanDialogInstance . ui . radioButtonCreateChan . isChecked ( ) :
if self . newChanDialogInstance . ui . lineEditChanNameCreate . text ( ) == " " :
QMessageBox . about ( self , _translate ( " MainWindow " , " Chan name needed " ) , _translate (
" MainWindow " , " You didn ' t enter a chan name. " ) )
return
shared . apiAddressGeneratorReturnQueue . queue . clear ( )
2013-09-18 06:04:01 +02:00
shared . addressGeneratorQueue . put ( ( ' createChan ' , 4 , 1 , self . str_chan + ' ' + str ( self . newChanDialogInstance . ui . lineEditChanNameCreate . text ( ) . toUtf8 ( ) ) , self . newChanDialogInstance . ui . lineEditChanNameCreate . text ( ) . toUtf8 ( ) ) )
2013-07-22 07:10:22 +02:00
addressGeneratorReturnValue = shared . apiAddressGeneratorReturnQueue . get ( )
2015-11-18 16:22:17 +01:00
logger . debug ( ' addressGeneratorReturnValue ' + addressGeneratorReturnValue )
2013-07-22 07:10:22 +02:00
if len ( addressGeneratorReturnValue ) == 0 :
QMessageBox . about ( self , _translate ( " MainWindow " , " Address already present " ) , _translate (
" MainWindow " , " Could not add chan because it appears to already be one of your identities. " ) )
return
createdAddress = addressGeneratorReturnValue [ 0 ]
QMessageBox . about ( self , _translate ( " MainWindow " , " Success " ) , _translate (
" MainWindow " , " Successfully created chan. To let others join your chan, give them the chan name and this Bitmessage address: % 1. This address also appears in ' Your Identities ' . " ) . arg ( createdAddress ) )
self . ui . tabWidget . setCurrentIndex ( 3 )
elif self . newChanDialogInstance . ui . radioButtonJoinChan . isChecked ( ) :
if self . newChanDialogInstance . ui . lineEditChanNameJoin . text ( ) == " " :
QMessageBox . about ( self , _translate ( " MainWindow " , " Chan name needed " ) , _translate (
" MainWindow " , " You didn ' t enter a chan name. " ) )
return
if decodeAddress ( self . newChanDialogInstance . ui . lineEditChanBitmessageAddress . text ( ) ) [ 0 ] == ' versiontoohigh ' :
QMessageBox . about ( self , _translate ( " MainWindow " , " Address too new " ) , _translate (
" MainWindow " , " Although that Bitmessage address might be valid, its version number is too new for us to handle. Perhaps you need to upgrade Bitmessage. " ) )
return
if decodeAddress ( self . newChanDialogInstance . ui . lineEditChanBitmessageAddress . text ( ) ) [ 0 ] != ' success ' :
QMessageBox . about ( self , _translate ( " MainWindow " , " Address invalid " ) , _translate (
" MainWindow " , " That Bitmessage address is not valid. " ) )
return
shared . apiAddressGeneratorReturnQueue . queue . clear ( )
2013-07-22 07:41:50 +02:00
shared . addressGeneratorQueue . put ( ( ' joinChan ' , addBMIfNotPresent ( self . newChanDialogInstance . ui . lineEditChanBitmessageAddress . text ( ) ) , self . str_chan + ' ' + str ( self . newChanDialogInstance . ui . lineEditChanNameJoin . text ( ) . toUtf8 ( ) ) , self . newChanDialogInstance . ui . lineEditChanNameJoin . text ( ) . toUtf8 ( ) ) )
2013-07-22 07:10:22 +02:00
addressGeneratorReturnValue = shared . apiAddressGeneratorReturnQueue . get ( )
2015-11-18 16:22:17 +01:00
logger . debug ( ' addressGeneratorReturnValue ' + addressGeneratorReturnValue )
2013-07-22 07:10:22 +02:00
if addressGeneratorReturnValue == ' chan name does not match address ' :
QMessageBox . about ( self , _translate ( " MainWindow " , " Address does not match chan name " ) , _translate (
" MainWindow " , " Although the Bitmessage address you entered was valid, it doesn \' t match the chan name. " ) )
return
if len ( addressGeneratorReturnValue ) == 0 :
QMessageBox . about ( self , _translate ( " MainWindow " , " Address already present " ) , _translate (
" MainWindow " , " Could not add chan because it appears to already be one of your identities. " ) )
return
2013-07-22 07:20:36 +02:00
createdAddress = addressGeneratorReturnValue [ 0 ]
2013-07-22 07:10:22 +02:00
QMessageBox . about ( self , _translate ( " MainWindow " , " Success " ) , _translate (
" MainWindow " , " Successfully joined chan. " ) )
self . ui . tabWidget . setCurrentIndex ( 3 )
2013-07-24 17:46:28 +02:00
def showConnectDialog ( self ) :
self . connectDialogInstance = connectDialog ( self )
if self . connectDialogInstance . exec_ ( ) :
if self . connectDialogInstance . ui . radioButtonConnectNow . isChecked ( ) :
shared . config . remove_option ( ' bitmessagesettings ' , ' dontconnect ' )
2014-09-15 08:34:33 +02:00
shared . writeKeysFile ( )
2013-07-24 17:46:28 +02:00
else :
self . click_actionSettings ( )
2015-10-02 15:05:47 +02:00
def showMigrationWizard ( self , level ) :
self . migrationWizardInstance = Ui_MigrationWizard ( [ " a " ] )
if self . migrationWizardInstance . exec_ ( ) :
pass
else :
pass
2013-05-02 17:53:54 +02:00
def changeEvent ( self , event ) :
2014-11-14 12:21:18 +01:00
if event . type ( ) == QtCore . QEvent . LanguageChange :
self . ui . retranslateUi ( self )
2014-12-28 11:42:38 +01:00
self . init_inbox_popup_menu ( False )
2015-03-21 11:37:08 +01:00
self . init_chan_popup_menu ( False )
2014-12-28 11:42:38 +01:00
self . init_addressbook_popup_menu ( False )
self . init_subscriptions_popup_menu ( False )
self . init_sent_popup_menu ( False )
self . init_blacklist_popup_menu ( False )
2013-05-08 22:42:28 +02:00
if event . type ( ) == QtCore . QEvent . WindowStateChange :
if self . windowState ( ) & QtCore . Qt . WindowMinimized :
2015-01-06 23:55:01 +01:00
if shared . config . getboolean ( ' bitmessagesettings ' , ' minimizetotray ' ) and not ' darwin ' in sys . platform :
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 :
2015-01-06 23:55:01 +01:00
self . setWindowFlags ( Qt . ToolTip )
elif event . oldState ( ) & QtCore . Qt . WindowMinimized :
# The window state has just been changed to
# Normal/Maximised/FullScreen
pass
# 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-08-25 01:40:48 +02:00
def updateNumberOfMessagesProcessed ( self ) :
2015-11-12 01:00:27 +01:00
self . ui . labelSyncStatus . setText ( _translate ( " MainWindow " , " Objects to be synced: % 1 " ) . arg ( str ( sum ( shared . numberOfObjectsThatWeHaveYetToGetPerPeer . itervalues ( ) ) ) ) )
2013-06-13 09:59:40 +02:00
self . ui . labelMessageCount . setText ( _translate (
2013-08-25 01:40:48 +02:00
" MainWindow " , " Processed % 1 person-to-person messages. " ) . arg ( str ( shared . numberOfMessagesProcessed ) ) )
2013-05-02 17:53:54 +02:00
2013-08-25 01:40:48 +02:00
def updateNumberOfBroadcastsProcessed ( self ) :
2015-11-12 01:00:27 +01:00
self . ui . labelSyncStatus . setText ( _translate ( " MainWindow " , " Objects to be synced: % 1 " ) . arg ( str ( sum ( shared . numberOfObjectsThatWeHaveYetToGetPerPeer . itervalues ( ) ) ) ) )
2013-06-13 09:59:40 +02:00
self . ui . labelBroadcastCount . setText ( _translate (
2013-08-25 01:40:48 +02:00
" MainWindow " , " Processed % 1 broadcast messages. " ) . arg ( str ( shared . numberOfBroadcastsProcessed ) ) )
2013-05-02 17:53:54 +02:00
2013-08-25 01:40:48 +02:00
def updateNumberOfPubkeysProcessed ( self ) :
2015-11-12 01:00:27 +01:00
self . ui . labelSyncStatus . setText ( _translate ( " MainWindow " , " Objects to be synced: % 1 " ) . arg ( str ( sum ( shared . numberOfObjectsThatWeHaveYetToGetPerPeer . itervalues ( ) ) ) ) )
2013-06-13 09:59:40 +02:00
self . ui . labelPubkeyCount . setText ( _translate (
2013-08-25 01:40:48 +02:00
" MainWindow " , " Processed % 1 public keys. " ) . arg ( str ( shared . numberOfPubkeysProcessed ) ) )
2013-05-02 17:53:54 +02:00
2014-08-01 22:35:48 +02:00
def formatBytes ( self , num ) :
2014-07-11 20:12:58 +02:00
for x in [ ' bytes ' , ' KB ' , ' MB ' , ' GB ' ] :
2014-08-01 22:35:48 +02:00
if num < 1000.0 :
return " %3.0f %s " % ( num , x )
num / = 1000.0
return " %3.0f %s " % ( num , ' TB ' )
def formatByteRate ( self , num ) :
num / = 1000
return " %4.0f KB " % num
2014-07-11 20:12:58 +02:00
2014-07-07 22:30:23 +02:00
def updateNumberOfBytes ( self ) :
2014-08-01 22:35:48 +02:00
"""
This function is run every two seconds , so we divide the rate of bytes
sent and received by 2.
"""
2014-07-07 22:30:23 +02:00
self . ui . labelBytesRecvCount . setText ( _translate (
2014-08-01 22:35:48 +02:00
" MainWindow " , " Down: % 1/s Total: % 2 " ) . arg ( self . formatByteRate ( shared . numberOfBytesReceived / 2 ) , self . formatBytes ( self . totalNumberOfBytesReceived ) ) )
2014-07-07 22:30:23 +02:00
self . ui . labelBytesSentCount . setText ( _translate (
2014-08-01 22:35:48 +02:00
" MainWindow " , " Up: % 1/s Total: % 2 " ) . arg ( self . formatByteRate ( shared . numberOfBytesSent / 2 ) , self . formatBytes ( self . totalNumberOfBytesSent ) ) )
self . totalNumberOfBytesReceived + = shared . numberOfBytesReceived
self . totalNumberOfBytesSent + = shared . numberOfBytesSent
shared . numberOfBytesReceived = 0
shared . numberOfBytesSent = 0
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
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-09-04 00:08:29 +02:00
# timer driven
def runEveryTwoSeconds ( self ) :
self . ui . labelLookupsPerSecond . setText ( _translate (
" MainWindow " , " Inventory lookups per second: % 1 " ) . arg ( str ( shared . numberOfInventoryLookupsPerformed / 2 ) ) )
shared . numberOfInventoryLookupsPerformed = 0
2014-07-07 22:30:23 +02:00
self . updateNumberOfBytes ( )
2013-09-04 00:08:29 +02:00
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 (
2013-07-15 18:01:12 +02:00
" MainWindow " , " Connection lost " ) . toUtf8 ( ) , ' utf-8 ' ) ,
self . SOUND_DISCONNECTED , None )
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 " ) )
2013-11-29 02:05:53 +01:00
self . setTrayIconFile ( " 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 (
2013-07-15 18:01:12 +02:00
" MainWindow " , " Connected " ) . toUtf8 ( ) , ' utf-8 ' ) ,
self . SOUND_CONNECTED , None )
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 " ) )
2013-11-29 02:05:53 +01:00
self . setTrayIconFile ( " 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 (
2013-07-15 18:01:12 +02:00
" MainWindow " , " Connected " ) . toUtf8 ( ) , ' utf-8 ' ) ,
self . SOUND_CONNECTION_GREEN , None )
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 " ) )
2013-11-29 02:05:53 +01:00
self . setTrayIconFile ( " can-icon-24px-green.png " )
def initTrayIcon ( self , iconFileName , app ) :
self . currentTrayIconFileName = iconFileName
self . tray = QSystemTrayIcon (
self . calcTrayIcon ( iconFileName , self . findInboxUnreadCount ( ) ) , app )
def setTrayIconFile ( self , iconFileName ) :
self . currentTrayIconFileName = iconFileName
self . drawTrayIcon ( iconFileName , self . findInboxUnreadCount ( ) )
def calcTrayIcon ( self , iconFileName , inboxUnreadCount ) :
pixmap = QtGui . QPixmap ( " :/newPrefix/images/ " + iconFileName )
if inboxUnreadCount > 0 :
# choose font and calculate font parameters
fontName = " Lucida "
fontSize = 10
font = QtGui . QFont ( fontName , fontSize , QtGui . QFont . Bold )
fontMetrics = QtGui . QFontMetrics ( font )
# text
txt = str ( inboxUnreadCount )
rect = fontMetrics . boundingRect ( txt )
# margins that we add in the top-right corner
marginX = 2
marginY = 0 # it looks like -2 is also ok due to the error of metric
# if it renders too wide we need to change it to a plus symbol
if rect . width ( ) > 20 :
txt = " + "
fontSize = 15
font = QtGui . QFont ( fontName , fontSize , QtGui . QFont . Bold )
fontMetrics = QtGui . QFontMetrics ( font )
rect = fontMetrics . boundingRect ( txt )
# draw text
painter = QPainter ( )
painter . begin ( pixmap )
painter . setPen ( QtGui . QPen ( QtGui . QColor ( 255 , 0 , 0 ) , Qt . SolidPattern ) )
painter . setFont ( font )
painter . drawText ( 24 - rect . right ( ) - marginX , - rect . top ( ) + marginY , txt )
painter . end ( )
return QtGui . QIcon ( pixmap )
def drawTrayIcon ( self , iconFileName , inboxUnreadCount ) :
self . tray . setIcon ( self . calcTrayIcon ( iconFileName , inboxUnreadCount ) )
2015-10-03 01:17:47 +02:00
def changedInboxUnread ( self , row = None ) :
2013-11-29 02:05:53 +01:00
self . drawTrayIcon ( self . currentTrayIconFileName , self . findInboxUnreadCount ( ) )
2015-10-03 01:17:47 +02:00
self . rerenderTabTreeMessages ( )
2015-10-31 15:27:07 +01:00
self . rerenderTabTreeSubscriptions ( )
self . rerenderTabTreeChans ( )
2013-11-29 02:05:53 +01:00
2015-10-31 15:27:07 +01:00
def findInboxUnreadCount ( self , count = None ) :
if count is None :
queryreturn = sqlQuery ( ''' SELECT count(*) from inbox WHERE folder= ' inbox ' and read=0 ''' )
cnt = 0
for row in queryreturn :
cnt , = row
self . unreadCount = int ( cnt )
else :
self . unreadCount = count
return self . unreadCount
2013-05-02 17:53:54 +02:00
2015-11-05 17:27:35 +01:00
def updateSentItemStatusByToAddress ( self , toAddress , textToDisplay ) :
2015-11-09 19:39:30 +01:00
for sent in [ self . ui . tableWidgetInbox , self . ui . tableWidgetInboxSubscriptions , self . ui . tableWidgetInboxChans ] :
treeWidget = self . widgetConvert ( sent )
if self . getCurrentFolder ( treeWidget ) != " sent " :
continue
if treeWidget in [ self . ui . treeWidgetSubscriptions , self . ui . treeWidgetChans ] and self . getCurrentAccount ( treeWidget ) != toAddress :
continue
for i in range ( sent . rowCount ( ) ) :
rowAddress = str ( sent . item (
i , 0 ) . data ( Qt . UserRole ) . toPyObject ( ) )
if toAddress == rowAddress :
sent . item ( i , 3 ) . setToolTip ( textToDisplay )
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
if newlinePosition > 1 :
sent . item ( i , 3 ) . setText (
textToDisplay [ : newlinePosition ] )
else :
sent . 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 ) :
2015-11-09 19:39:30 +01:00
for sent in [ self . ui . tableWidgetInbox , self . ui . tableWidgetInboxSubscriptions , self . ui . tableWidgetInboxChans ] :
treeWidget = self . widgetConvert ( sent )
if self . getCurrentFolder ( treeWidget ) != " sent " :
continue
for i in range ( sent . rowCount ( ) ) :
toAddress = str ( sent . item (
i , 0 ) . data ( Qt . UserRole ) . toPyObject ( ) )
tableAckdata = sent . item (
i , 3 ) . data ( Qt . UserRole ) . toPyObject ( )
status , addressVersionNumber , streamNumber , ripe = decodeAddress (
toAddress )
if ackdata == tableAckdata :
sent . item ( i , 3 ) . setToolTip ( textToDisplay )
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
if newlinePosition > 1 :
sent . item ( i , 3 ) . setText (
textToDisplay [ : newlinePosition ] )
else :
sent . 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
2015-10-31 18:42:44 +01:00
for inbox in ( [
self . ui . tableWidgetInbox ,
self . ui . tableWidgetInboxSubscriptions ,
self . ui . tableWidgetInboxChans ] ) :
for i in range ( inbox . rowCount ( ) ) :
if msgid == str ( inbox . item ( i , 3 ) . data ( Qt . UserRole ) . toPyObject ( ) ) :
self . statusBar ( ) . showMessage ( _translate (
" MainWindow " , " Message trashed " ) )
2015-11-09 19:39:30 +01:00
treeWidget = self . widgetConvert ( inbox )
2015-10-31 18:42:44 +01:00
self . propagateUnreadCount ( self . getCurrentAccount ( treeWidget ) , self . getCurrentFolder ( treeWidget ) , treeWidget , 0 )
inbox . removeRow ( i )
break
2015-10-19 22:33:18 +02:00
def newVersionAvailable ( self , version ) :
# if (not (self.windowState() & QtCore.Qt.WindowActive)) or (self.windowState() & QtCore.Qt.WindowMinimized):
# return
# only notify once until next restart
try :
if self . notifiedNewVersion :
return
except AttributeError :
pass
self . notifiedNewVersion = " . " . join ( str ( n ) for n in version )
message = " New "
if version [ 1 ] % 2 :
message + = " UNSTABLE "
else :
message + = " stable "
message + = " version of PyBitmessage is available: " + self . notifiedNewVersion + " . Download it from https://github.com/ "
if version [ 0 ] == 0 and version [ 1 ] == 5 :
message + = " mailchuck "
else :
message + = " Bitmessage "
message + = " /PyBitmessage/releases/latest "
self . displayAlert ( " New release of PyBitmessage available " , message , False )
2013-06-05 23:15:26 +02:00
2013-09-05 02:14:25 +02:00
def displayAlert ( self , title , text , exitAfterUserClicksOk ) :
self . statusBar ( ) . showMessage ( text )
QtGui . QMessageBox . critical ( self , title , text , QMessageBox . Ok )
if exitAfterUserClicksOk :
os . _exit ( 0 )
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 = ' '
2013-08-27 02:01:19 +02:00
queryreturn = sqlQuery (
''' select label from addressbook where address=? ''' , addressToLookup )
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-11-02 00:25:24 +01:00
if fromLabel == ' ' :
2013-06-12 23:12:32 +02:00
# It might be a broadcast message. We should check for that
# label.
2013-08-27 02:01:19 +02:00
queryreturn = sqlQuery (
''' select label from subscriptions where address=? ''' , addressToLookup )
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-11-02 00:25:24 +01:00
if fromLabel == ' ' :
# Message might be from an address we own like a chan address. Let's look for that label.
if shared . config . has_section ( addressToLookup ) :
fromLabel = shared . config . get ( addressToLookup , ' label ' )
if fromLabel == ' ' :
fromLabel = addressToLookup
self . ui . tableWidgetInbox . item (
i , 1 ) . setText ( unicode ( fromLabel , ' utf-8 ' ) )
self . ui . tableWidgetInbox . item (
i , 1 ) . setIcon ( avatarize ( addressToLookup ) )
# Set the color according to whether it is the address of a mailing
# list or not.
if shared . safeConfigGetBoolean ( addressToLookup , ' chan ' ) :
self . ui . tableWidgetInbox . item ( i , 1 ) . setTextColor ( QtGui . QColor ( 216 , 119 , 0 ) ) # orange
else :
self . ui . tableWidgetInbox . item (
i , 1 ) . setTextColor ( QApplication . palette ( ) . text ( ) . color ( ) )
2013-09-21 09:41:23 +02:00
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-11-02 00:25:24 +01:00
# Message might be to an address we own like a chan address. Let's look for that label.
if shared . config . has_section ( toAddress ) :
2013-05-02 17:53:54 +02:00
toLabel = shared . config . get ( toAddress , ' label ' )
2013-11-02 00:25:24 +01:00
else :
2013-05-02 17:53:54 +02:00
toLabel = toAddress
2013-06-12 23:12:32 +02:00
self . ui . tableWidgetInbox . item (
i , 0 ) . setText ( unicode ( toLabel , ' utf-8 ' ) )
2013-08-27 11:47:14 +02:00
self . ui . tableWidgetInbox . item (
2013-11-02 00:25:24 +01:00
i , 0 ) . setIcon ( avatarize ( toAddress ) )
2013-06-12 23:12:32 +02:00
# Set the color according to whether it is the address of a mailing
2013-09-21 09:41:23 +02:00
# list, a chan or neither.
if shared . safeConfigGetBoolean ( toAddress , ' chan ' ) :
self . ui . tableWidgetInbox . item ( i , 0 ) . setTextColor ( QtGui . QColor ( 216 , 119 , 0 ) ) # orange
elif shared . safeConfigGetBoolean ( toAddress , ' mailinglist ' ) :
self . ui . tableWidgetInbox . item ( i , 0 ) . setTextColor ( QtGui . QColor ( 137 , 04 , 177 ) ) # magenta
2013-05-02 17:53:54 +02:00
else :
2013-06-12 23:12:32 +02:00
self . ui . tableWidgetInbox . item (
2013-07-22 20:28:51 +02:00
i , 0 ) . setTextColor ( QApplication . palette ( ) . text ( ) . color ( ) )
2013-05-02 17:53:54 +02:00
def rerenderSentFromLabels ( self ) :
2015-03-03 18:17:56 +01:00
for i in range ( self . ui . tableWidgetInbox . rowCount ( ) ) :
fromAddress = str ( self . ui . tableWidgetInbox . item (
2013-06-12 23:12:32 +02:00
i , 1 ) . data ( Qt . UserRole ) . toPyObject ( ) )
2013-11-02 00:25:24 +01:00
# Message might be from an address we own like a chan address. Let's look for that label.
if shared . config . has_section ( fromAddress ) :
2013-05-02 17:53:54 +02:00
fromLabel = shared . config . get ( fromAddress , ' label ' )
2013-11-02 00:25:24 +01:00
else :
2013-05-02 17:53:54 +02:00
fromLabel = fromAddress
2015-03-03 18:17:56 +01:00
self . ui . tableWidgetInbox . item (
2013-06-12 23:12:32 +02:00
i , 1 ) . setText ( unicode ( fromLabel , ' utf-8 ' ) )
2015-03-03 18:17:56 +01:00
self . ui . tableWidgetInbox . item (
2013-11-02 00:25:24 +01:00
i , 1 ) . setIcon ( avatarize ( fromAddress ) )
2013-05-02 17:53:54 +02:00
def rerenderSentToLabels ( self ) :
2015-03-03 18:17:56 +01:00
for i in range ( self . ui . tableWidgetInbox . rowCount ( ) ) :
addressToLookup = str ( self . ui . tableWidgetInbox . item (
2013-06-12 23:12:32 +02:00
i , 0 ) . data ( Qt . UserRole ) . toPyObject ( ) )
2013-05-02 17:53:54 +02:00
toLabel = ' '
2013-08-27 02:01:19 +02:00
queryreturn = sqlQuery (
''' select label from addressbook where address=? ''' , addressToLookup )
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-11-02 00:25:24 +01:00
if toLabel == ' ' :
# Message might be to an address we own like a chan address. Let's look for that label.
if shared . config . has_section ( addressToLookup ) :
toLabel = shared . config . get ( addressToLookup , ' label ' )
2013-11-02 05:02:46 +01:00
if toLabel == ' ' :
toLabel = addressToLookup
2015-03-03 18:17:56 +01:00
self . ui . tableWidgetInbox . item (
2013-11-02 00:25:24 +01:00
i , 0 ) . setText ( unicode ( toLabel , ' utf-8 ' ) )
2013-05-02 17:53:54 +02:00
2013-09-05 12:31:52 +02:00
def rerenderAddressBook ( self ) :
2015-10-23 19:14:01 +02:00
def addRow ( address , label , type ) :
self . ui . tableWidgetAddressBook . insertRow ( 0 )
newItem = Ui_AddressBookWidgetItemLabel ( address , unicode ( label , ' utf-8 ' ) , type )
2015-10-31 21:38:54 +01:00
newItem . setData ( Qt . UserRole , type )
2015-10-23 19:14:01 +02:00
self . ui . tableWidgetAddressBook . setItem ( 0 , 0 , newItem )
newItem = Ui_AddressBookWidgetItemAddress ( address , unicode ( label , ' utf-8 ' ) , type )
self . ui . tableWidgetAddressBook . setItem ( 0 , 1 , newItem )
self . ui . tableWidgetAddressBook . setSortingEnabled ( False )
2013-09-05 12:31:52 +02:00
self . ui . tableWidgetAddressBook . setRowCount ( 0 )
2015-10-23 19:14:01 +02:00
# subscriptions
queryreturn = sqlQuery ( ' SELECT label, address FROM subscriptions WHERE enabled = 1 ' )
for row in queryreturn :
label , address = row
addRow ( address , label , ' subscription ' )
# chans
addresses = getSortedAccounts ( )
for address in addresses :
account = accountClass ( address )
if ( account . type == ' chan ' ) :
addRow ( address , account . getLabel ( ) , ' chan ' )
# normal accounts
2013-09-05 12:31:52 +02:00
queryreturn = sqlQuery ( ' SELECT * FROM addressbook ' )
for row in queryreturn :
label , address = row
2015-10-23 19:14:01 +02:00
addRow ( address , label , ' normal ' )
# sort
self . ui . tableWidgetAddressBook . sortItems ( 0 , QtCore . Qt . AscendingOrder )
self . ui . tableWidgetAddressBook . setSortingEnabled ( True )
2013-09-05 12:31:52 +02:00
2013-05-24 22:12:16 +02:00
def rerenderSubscriptions ( self ) :
2015-03-23 22:35:56 +01:00
self . rerenderTabTreeSubscriptions ( )
2013-05-24 22:12:16 +02:00
2014-11-22 22:56:41 +01:00
def rerenderBlackWhiteList ( self ) :
2014-11-22 22:13:35 +01:00
self . ui . tableWidgetBlacklist . setRowCount ( 0 )
2014-11-22 22:56:41 +01:00
listType = shared . config . get ( ' bitmessagesettings ' , ' blackwhitelist ' )
if listType == ' black ' :
queryreturn = sqlQuery ( ''' SELECT label, address, enabled FROM blacklist ''' )
else :
queryreturn = sqlQuery ( ''' SELECT label, address, enabled FROM whitelist ''' )
2014-11-22 22:13:35 +01:00
for row in queryreturn :
label , address , enabled = row
self . ui . tableWidgetBlacklist . insertRow ( 0 )
newItem = QtGui . QTableWidgetItem ( unicode ( label , ' utf-8 ' ) )
if not enabled :
newItem . setTextColor ( QtGui . QColor ( 128 , 128 , 128 ) )
newItem . setIcon ( avatarize ( address ) )
self . ui . tableWidgetBlacklist . setItem ( 0 , 0 , newItem )
newItem = QtGui . QTableWidgetItem ( address )
newItem . setFlags (
QtCore . Qt . ItemIsSelectable | QtCore . Qt . ItemIsEnabled )
if not enabled :
newItem . setTextColor ( QtGui . QColor ( 128 , 128 , 128 ) )
self . ui . tableWidgetBlacklist . setItem ( 0 , 1 , newItem )
2015-03-03 20:04:12 +01:00
def click_pushButtonTTL ( self ) :
QtGui . QMessageBox . information ( self , ' Time To Live ' , _translate (
2015-10-11 11:18:25 +02:00
" MainWindow " , """ The TTL, or Time-To-Live is the length of time that the network will hold the message.
The recipient must get it during this time . If your Bitmessage client does not hear an acknowledgement , it
will resend the message automatically . The longer the Time - To - Live , the
more work your computer must do to send the message . A Time - To - Live of four or five days is often appropriate . """ ), QMessageBox.Ok)
2015-03-03 20:04:12 +01:00
2013-05-02 17:53:54 +02:00
def click_pushButtonSend ( self ) :
self . statusBar ( ) . showMessage ( ' ' )
2015-03-21 11:37:08 +01:00
if self . ui . tabWidgetSend . currentIndex ( ) == 0 :
2015-03-23 22:35:56 +01:00
# message to specific people
2015-03-21 11:37:08 +01:00
sendMessageToPeople = True
2015-09-30 10:22:41 +02:00
fromAddress = str ( self . ui . comboBoxSendFrom . itemData (
2015-03-23 22:35:56 +01:00
self . ui . comboBoxSendFrom . currentIndex ( ) ,
2015-09-30 10:22:41 +02:00
Qt . UserRole ) . toString ( ) )
2015-03-21 11:37:08 +01:00
toAddresses = str ( self . ui . lineEditTo . text ( ) )
subject = str ( self . ui . lineEditSubject . text ( ) . toUtf8 ( ) )
message = str (
self . ui . textEditMessage . document ( ) . toPlainText ( ) . toUtf8 ( ) )
else :
2015-03-23 22:35:56 +01:00
# broadcast message
2015-03-21 11:37:08 +01:00
sendMessageToPeople = False
2015-09-30 10:22:41 +02:00
fromAddress = str ( self . ui . comboBoxSendFromBroadcast . itemData (
2015-03-23 22:35:56 +01:00
self . ui . comboBoxSendFromBroadcast . currentIndex ( ) ,
2015-09-30 10:22:41 +02:00
Qt . UserRole ) . toString ( ) )
2015-03-21 11:37:08 +01:00
subject = str ( self . ui . lineEditSubjectBroadcast . text ( ) . toUtf8 ( ) )
message = str (
self . ui . textEditMessageBroadcast . document ( ) . toPlainText ( ) . toUtf8 ( ) )
2014-08-27 09:14:32 +02:00
"""
The whole network message must fit in 2 ^ 18 bytes . Let ' s assume 500
bytes of overhead . If someone wants to get that too an exact
number you are welcome to but I think that it would be a better
use of time to support message continuation so that users can
send messages of any length .
"""
if len ( message ) > ( 2 * * 18 - 500 ) :
QMessageBox . about ( self , _translate ( " MainWindow " , " Message too long " ) , _translate (
" MainWindow " , " The message that you are trying to send is too long by % 1 bytes. (The maximum is 261644 bytes). Please cut it down before sending. " ) . arg ( len ( message ) - ( 2 * * 18 - 500 ) ) )
return
2015-10-03 17:24:21 +02:00
acct = accountClass ( fromAddress )
2015-03-21 11:37:08 +01:00
if sendMessageToPeople : # To send a message to specific people (rather than broadcast)
2013-06-12 23:12:32 +02:00
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 != ' ' :
2015-10-03 17:24:21 +02:00
if toAddress . find ( " @ " ) > = 0 and isinstance ( acct , GatewayAccount ) :
acct . createMessage ( toAddress , fromAddress , subject , message )
subject = acct . subject
toAddress = acct . toAddress
2015-11-18 16:22:17 +01:00
logger . debug ( " Subject: %s " % ( subject ) )
logger . debug ( " address: %s " % ( toAddress ) )
2013-06-12 23:12:32 +02:00
status , addressVersionNumber , streamNumber , ripe = decodeAddress (
toAddress )
if status != ' success ' :
2015-11-18 16:22:17 +01:00
logger . error ( ' Error: Could not decode ' + toAddress + ' : ' + status )
2013-06-29 19:29:35 +02:00
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 ) )
2014-08-27 09:14:32 +02:00
elif status == ' varintmalformed ' :
self . statusBar ( ) . showMessage ( _translate (
" MainWindow " , " Error: Some data encoded in the address % 1 is malformed. 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 )
2015-09-30 10:22:41 +02:00
2013-09-13 06:27:34 +02:00
if addressVersionNumber > 4 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 )
2013-08-27 02:01:19 +02:00
t = ( )
sqlExecute (
2015-03-09 07:35:32 +01:00
''' INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) ''' ,
2013-08-27 02:01:19 +02:00
' ' ,
toAddress ,
ripe ,
fromAddress ,
subject ,
message ,
ackdata ,
2015-03-09 07:35:32 +01:00
int ( time . time ( ) ) , # sentTime (this will never change)
int ( time . time ( ) ) , # lastActionTime
0 , # sleepTill time. This will get set when the POW gets done.
2013-08-27 02:01:19 +02:00
' msgqueued ' ,
2015-03-09 07:35:32 +01:00
0 , # retryNumber
' sent ' , # folder
2 , # encodingtype
shared . config . getint ( ' bitmessagesettings ' , ' ttl ' )
2015-03-03 20:04:12 +01:00
)
2013-05-02 17:53:54 +02:00
toLabel = ' '
2013-08-27 02:01:19 +02:00
queryreturn = sqlQuery ( ''' select label from addressbook where address=? ''' ,
toAddress )
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 . lineEditTo . setText ( ' ' )
self . ui . lineEditSubject . setText ( ' ' )
self . ui . textEditMessage . setText ( ' ' )
2015-10-19 17:37:43 +02:00
if self . replyFromTab is not None :
self . ui . tabWidget . setCurrentIndex ( self . replyFromTab )
self . replyFromTab = None
2015-10-31 18:48:33 +01:00
self . statusBar ( ) . showMessage ( _translate (
" MainWindow " , " Message queued. " ) )
2015-10-19 17:37:43 +02:00
#self.ui.tableWidgetInbox.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 )
2015-10-13 23:36:09 +02:00
toAddress = str_broadcast_subscribers
2013-05-02 17:53:54 +02:00
ripe = ' '
2015-03-09 07:35:32 +01:00
t = ( ' ' , # msgid. We don't know what this will be until the POW is done.
toAddress ,
ripe ,
fromAddress ,
subject ,
message ,
ackdata ,
int ( time . time ( ) ) , # sentTime (this will never change)
int ( time . time ( ) ) , # lastActionTime
0 , # sleepTill time. This will get set when the POW gets done.
' broadcastqueued ' ,
0 , # retryNumber
' sent ' , # folder
2 , # encoding type
shared . config . getint ( ' bitmessagesettings ' , ' ttl ' )
)
2013-08-27 02:01:19 +02:00
sqlExecute (
2015-03-09 07:35:32 +01:00
''' INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) ''' , * t )
2013-05-02 17:53:54 +02:00
2015-10-13 23:36:09 +02:00
toLabel = str_broadcast_subscribers
2013-10-16 07:08:22 +02:00
self . displayNewSentMessage (
toAddress , toLabel , fromAddress , subject , message , ackdata )
2013-05-02 17:53:54 +02:00
2013-10-16 07:08:22 +02:00
shared . workerQueue . put ( ( ' sendbroadcast ' , ' ' ) )
2013-05-02 17:53:54 +02:00
2015-03-21 11:37:08 +01:00
self . ui . comboBoxSendFromBroadcast . setCurrentIndex ( 0 )
self . ui . lineEditSubjectBroadcast . setText ( ' ' )
self . ui . textEditMessageBroadcast . setText ( ' ' )
self . ui . tabWidget . setCurrentIndex ( 1 )
2015-10-10 19:58:01 +02:00
self . ui . tableWidgetInboxSubscriptions . setCurrentCell ( 0 , 0 )
2015-10-31 18:48:33 +01:00
self . statusBar ( ) . showMessage ( _translate (
" MainWindow " , " Broadcast queued. " ) )
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-07 18:43:09 +02:00
self . statusBar ( ) . showMessage ( _translate (
" MainWindow " , " Fetched address from namecoin identity. " ) )
2013-07-04 22:06:30 +02:00
2015-10-14 23:38:34 +02:00
def setBroadcastEnablementDependingOnWhetherThisIsAMailingListAddress ( self , address ) :
2013-07-22 07:10:22 +02:00
# If this is a chan then don't let people broadcast because no one
# should subscribe to chan addresses.
2015-10-14 23:38:34 +02:00
if shared . safeConfigGetBoolean ( str ( address ) , ' mailinglist ' ) :
2015-03-21 11:37:08 +01:00
self . ui . tabWidgetSend . setCurrentIndex ( 1 )
2015-10-14 23:38:34 +02:00
else :
self . ui . tabWidgetSend . setCurrentIndex ( 0 )
2013-05-02 17:53:54 +02:00
def rerenderComboBoxSendFrom ( self ) :
self . ui . comboBoxSendFrom . clear ( )
2015-10-19 20:03:06 +02:00
for addressInKeysFile in getSortedAccounts ( ) :
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.
isMaillinglist = shared . safeConfigGetBoolean ( addressInKeysFile , ' mailinglist ' )
if isEnabled and not isMaillinglist :
self . ui . comboBoxSendFrom . addItem ( avatarize ( addressInKeysFile ) , unicode ( shared . config . get (
addressInKeysFile , ' label ' ) , ' utf-8 ' ) , addressInKeysFile )
# self.ui.comboBoxSendFrom.model().sort(1, Qt.AscendingOrder)
2015-10-31 20:27:28 +01:00
for i in range ( self . ui . comboBoxSendFrom . count ( ) ) :
address = str ( self . ui . comboBoxSendFrom . itemData ( i , Qt . UserRole ) . toString ( ) )
self . ui . comboBoxSendFrom . setItemData ( i , AccountColor ( address ) . accountColor ( ) , Qt . ForegroundRole )
2013-06-12 23:12:32 +02:00
self . ui . comboBoxSendFrom . insertItem ( 0 , ' ' , ' ' )
2013-05-02 17:53:54 +02:00
if ( self . ui . comboBoxSendFrom . count ( ) == 2 ) :
self . ui . comboBoxSendFrom . setCurrentIndex ( 1 )
else :
self . ui . comboBoxSendFrom . setCurrentIndex ( 0 )
2015-03-21 11:37:08 +01:00
def rerenderComboBoxSendFromBroadcast ( self ) :
self . ui . comboBoxSendFromBroadcast . clear ( )
2015-10-19 20:03:06 +02:00
for addressInKeysFile in getSortedAccounts ( ) :
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.
2015-11-12 01:42:20 +01:00
isChan = shared . safeConfigGetBoolean ( addressInKeysFile , ' chan ' )
if isEnabled and not isChan :
2015-10-19 20:03:06 +02:00
self . ui . comboBoxSendFromBroadcast . addItem ( avatarize ( addressInKeysFile ) , unicode ( shared . config . get (
addressInKeysFile , ' label ' ) , ' utf-8 ' ) , addressInKeysFile )
2015-10-31 20:27:28 +01:00
for i in range ( self . ui . comboBoxSendFromBroadcast . count ( ) ) :
address = str ( self . ui . comboBoxSendFromBroadcast . itemData ( i , Qt . UserRole ) . toString ( ) )
self . ui . comboBoxSendFromBroadcast . setItemData ( i , AccountColor ( address ) . accountColor ( ) , Qt . ForegroundRole )
2015-03-21 11:37:08 +01:00
self . ui . comboBoxSendFromBroadcast . insertItem ( 0 , ' ' , ' ' )
if ( self . ui . comboBoxSendFromBroadcast . count ( ) == 2 ) :
self . ui . comboBoxSendFromBroadcast . setCurrentIndex ( 1 )
else :
self . ui . comboBoxSendFromBroadcast . 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 )
2015-10-03 12:12:18 +02:00
acct = accountClass ( fromAddress )
acct . parseMessage ( toAddress , fromAddress , subject , message )
2015-11-09 19:39:30 +01:00
for sent in [ self . ui . tableWidgetInbox , self . ui . tableWidgetInboxSubscriptions , self . ui . tableWidgetInboxChans ] :
treeWidget = self . widgetConvert ( sent )
if self . getCurrentFolder ( treeWidget ) != " sent " :
continue
if treeWidget == self . ui . treeWidgetYourIdentities and self . getCurrentAccount ( treeWidget ) != fromAddress :
continue
elif treeWidget in [ self . ui . treeWidgetSubscriptions , self . ui . treeWidgetChans ] and self . getCurrentAccount ( treeWidget ) != toAddress :
continue
2015-10-03 17:24:21 +02:00
2015-11-09 19:39:30 +01:00
sent . setSortingEnabled ( False )
sent . insertRow ( 0 )
newItem = QtGui . QTableWidgetItem ( unicode ( acct . toLabel , ' utf-8 ' ) )
newItem . setToolTip ( unicode ( acct . toLabel , ' utf-8 ' ) )
newItem . setData ( Qt . UserRole , str ( toAddress ) )
newItem . setIcon ( avatarize ( toAddress ) )
sent . setItem ( 0 , 0 , newItem )
newItem = QtGui . QTableWidgetItem ( unicode ( acct . fromLabel , ' utf-8 ' ) )
newItem . setToolTip ( unicode ( acct . fromLabel , ' utf-8 ' ) )
newItem . setData ( Qt . UserRole , str ( fromAddress ) )
newItem . setIcon ( avatarize ( fromAddress ) )
sent . setItem ( 0 , 1 , newItem )
newItem = QtGui . QTableWidgetItem ( unicode ( acct . subject , ' utf-8) ' ) )
newItem . setToolTip ( unicode ( acct . subject , ' utf-8) ' ) )
newItem . setData ( Qt . UserRole , str ( subject ) )
#newItem.setData(Qt.UserRole, unicode(message, 'utf-8)')) # No longer hold the message in the table; we'll use a SQL query to display it as needed.
sent . setItem ( 0 , 2 , newItem )
# newItem = QtGui.QTableWidgetItem('Doing work necessary to send
# broadcast...'+
# l10n.formatTimestamp())
newItem = myTableWidgetItem ( _translate ( " MainWindow " , " Work is queued. % 1 " ) . arg ( l10n . formatTimestamp ( ) ) )
newItem . setToolTip ( _translate ( " MainWindow " , " Work is queued. % 1 " ) . arg ( l10n . formatTimestamp ( ) ) )
newItem . setData ( Qt . UserRole , QByteArray ( ackdata ) )
newItem . setData ( 33 , int ( time . time ( ) ) )
sent . setItem ( 0 , 3 , newItem )
self . getAccountTextedit ( acct ) . setPlainText ( unicode ( message , ' utf-8) ' ) )
sent . setSortingEnabled ( True )
2013-05-02 17:53:54 +02:00
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 )
2015-10-31 20:05:58 +01:00
if toAddress == str_broadcast_subscribers :
acct = accountClass ( fromAddress )
else :
acct = accountClass ( toAddress )
2015-10-03 12:12:18 +02:00
acct . parseMessage ( toAddress , fromAddress , subject , message )
2015-10-22 23:56:20 +02:00
inbox = self . getAccountMessagelist ( acct )
treeWidget = self . getAccountTreeWidget ( acct )
2015-10-31 20:05:58 +01:00
self . propagateUnreadCount ( acct . address )
2015-11-01 11:43:05 +01:00
if shared . config . getboolean ( ' bitmessagesettings ' , ' showtraynotifications ' ) :
self . notifierShow ( unicode ( _translate ( " MainWindow " , ' New Message ' ) . toUtf8 ( ) , ' utf-8 ' ) , unicode ( _translate ( " MainWindow " , ' From ' ) . toUtf8 ( ) , ' utf-8 ' ) + unicode ( acct . fromLabel , ' utf-8 ' ) , self . SOUND_UNKNOWN , None )
2015-11-01 11:08:41 +01:00
if ( self . getCurrentFolder ( treeWidget ) != " inbox " and self . getCurrentFolder ( treeWidget ) is not None ) or self . getCurrentAccount ( treeWidget ) != acct . address :
2015-10-31 19:03:10 +01:00
# Ubuntu should notify of new message irespective of whether it's in current message list or not
self . ubuntuMessagingMenuUpdate ( True , None , acct . toLabel )
2015-10-22 23:56:20 +02:00
return
2013-05-02 17:53:54 +02:00
font = QFont ( )
font . setBold ( True )
2015-10-10 19:58:01 +02:00
inbox . setSortingEnabled ( False )
2015-10-03 12:12:18 +02:00
newItem = QtGui . QTableWidgetItem ( unicode ( acct . toLabel , ' utf-8 ' ) )
newItem . setToolTip ( unicode ( acct . 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 ) )
2015-11-01 08:30:06 +01:00
newItem . setTextColor ( AccountColor ( toAddress ) . accountColor ( ) )
2015-10-10 19:58:01 +02:00
inbox . insertRow ( 0 )
2013-11-02 00:25:24 +01:00
newItem . setIcon ( avatarize ( toAddress ) )
2015-10-10 19:58:01 +02:00
inbox . setItem ( 0 , 0 , newItem )
2013-05-02 17:53:54 +02:00
2015-10-03 12:12:18 +02:00
newItem = QtGui . QTableWidgetItem ( unicode ( acct . fromLabel , ' utf-8 ' ) )
newItem . setToolTip ( unicode ( acct . 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 )
2015-11-01 08:30:06 +01:00
newItem . setTextColor ( AccountColor ( fromAddress ) . accountColor ( ) )
2013-11-02 00:25:24 +01:00
newItem . setIcon ( avatarize ( fromAddress ) )
2015-10-10 19:58:01 +02:00
inbox . setItem ( 0 , 1 , newItem )
2015-10-03 12:12:18 +02:00
newItem = QtGui . QTableWidgetItem ( unicode ( acct . subject , ' utf-8) ' ) )
newItem . setToolTip ( unicode ( acct . subject , ' utf-8) ' ) )
2015-10-03 17:24:21 +02:00
newItem . setData ( Qt . UserRole , str ( subject ) )
2013-10-13 19:45:30 +02:00
#newItem.setData(Qt.UserRole, unicode(message, 'utf-8)')) # No longer hold the message in the table; we'll use a SQL query to display it as needed.
2013-05-02 17:53:54 +02:00
newItem . setFont ( font )
2015-10-10 19:58:01 +02:00
inbox . setItem ( 0 , 2 , newItem )
2014-08-06 04:01:01 +02:00
newItem = myTableWidgetItem ( l10n . formatTimestamp ( ) )
newItem . setToolTip ( l10n . formatTimestamp ( ) )
2013-06-12 23:12:32 +02:00
newItem . setData ( Qt . UserRole , QByteArray ( inventoryHash ) )
newItem . setData ( 33 , int ( time . time ( ) ) )
2013-05-02 17:53:54 +02:00
newItem . setFont ( font )
2015-10-10 19:58:01 +02:00
inbox . setItem ( 0 , 3 , newItem )
inbox . setSortingEnabled ( True )
2015-10-31 19:03:10 +01:00
self . ubuntuMessagingMenuUpdate ( True , newItem , acct . toLabel )
2013-05-02 17:53:54 +02:00
def click_pushButtonAddAddressBook ( self ) :
2013-12-01 05:15:18 +01:00
self . AddAddressDialogInstance = AddAddressDialog ( self )
if self . AddAddressDialogInstance . exec_ ( ) :
if self . AddAddressDialogInstance . ui . labelAddressCheck . 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-07-22 07:10:22 +02:00
address = addBMIfNotPresent ( str (
2013-12-01 05:15:18 +01:00
self . AddAddressDialogInstance . ui . lineEditAddress . text ( ) ) )
label = self . AddAddressDialogInstance . ui . newAddressLabel . text ( ) . toUtf8 ( )
2013-07-22 07:10:22 +02:00
self . addEntryToAddressBook ( address , label )
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-07-22 07:10:22 +02:00
def addEntryToAddressBook ( self , address , label ) :
2013-08-29 17:16:59 +02:00
queryreturn = sqlQuery ( ''' select * from addressbook where address=? ''' , address )
2013-07-22 07:10:22 +02:00
if queryreturn == [ ] :
2013-08-27 02:01:19 +02:00
sqlExecute ( ''' INSERT INTO addressbook VALUES (?,?) ''' , str ( label ) , address )
2015-11-13 14:31:22 +01:00
self . rerenderAddressBook ( )
2013-07-22 07:10:22 +02:00
self . rerenderInboxFromLabels ( )
self . rerenderSentToLabels ( )
else :
self . statusBar ( ) . showMessage ( _translate (
" MainWindow " , " Error: You cannot add the same address to your address book twice. Try renaming the existing one if you want. " ) )
def addSubscription ( self , address , label ) :
2013-06-14 03:55:38 +02:00
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 database (perhaps this should be separated from the MyForm class)
2013-08-27 02:01:19 +02:00
sqlExecute ( ''' INSERT INTO subscriptions VALUES (?,?,?) ''' , str ( label ) , address , True )
2013-06-14 03:55:38 +02:00
self . rerenderInboxFromLabels ( )
shared . reloadBroadcastSendersForWhichImWatching ( )
2015-03-21 11:37:08 +01:00
2015-03-23 22:35:56 +01:00
self . rerenderTabTreeSubscriptions ( )
2013-05-02 17:53:54 +02:00
def click_pushButtonAddSubscription ( self ) :
self . NewSubscriptionDialogInstance = NewSubscriptionDialog ( self )
if self . NewSubscriptionDialogInstance . exec_ ( ) :
2013-12-01 05:15:18 +01:00
if self . NewSubscriptionDialogInstance . ui . labelAddressCheck . text ( ) != _translate ( " MainWindow " , " Address is valid. " ) :
2013-06-19 18:19:07 +02:00
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 ) :
2015-03-21 11:37:08 +01:00
self . statusBar ( ) . showMessage ( _translate ( " MainWindow " , " Error: You cannot add the same address to your subscriptions twice. Perhaps rename the existing one if you want. " ) )
2013-06-19 18:19:07 +02:00
return
label = self . NewSubscriptionDialogInstance . ui . newsubscriptionlabel . text ( ) . toUtf8 ( )
2013-07-22 07:10:22 +02:00
self . addSubscription ( address , label )
2013-12-01 05:15:18 +01:00
# Now, if the user wants to display old broadcasts, let's get them out of the inventory and put them
# in the objectProcessorQueue to be processed
if self . NewSubscriptionDialogInstance . ui . checkBoxDisplayMessagesAlreadyInInventory . isChecked ( ) :
status , addressVersion , streamNumber , ripe = decodeAddress ( address )
shared . flushInventory ( )
doubleHashOfAddressData = hashlib . sha512 ( hashlib . sha512 ( encodeVarint (
addressVersion ) + encodeVarint ( streamNumber ) + ripe ) . digest ( ) ) . digest ( )
tag = doubleHashOfAddressData [ 32 : ]
queryreturn = sqlQuery (
2014-08-27 09:14:32 +02:00
''' select payload from inventory where objecttype=3 and tag=? ''' , tag )
2013-12-01 05:15:18 +01:00
for row in queryreturn :
payload , = row
2014-08-27 09:14:32 +02:00
objectType = 3
2013-12-01 05:15:18 +01:00
with shared . objectProcessorQueueSizeLock :
shared . objectProcessorQueueSize + = len ( payload )
2013-12-02 07:35:34 +01:00
shared . objectProcessorQueue . put ( ( objectType , payload ) )
2013-05-02 17:53:54 +02:00
def click_pushButtonStatusIcon ( self ) :
2015-11-18 16:22:17 +01:00
logger . debug ( ' click_pushButtonStatusIcon ' )
2013-05-02 17:53:54 +02:00
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 ( ) ) )
2013-08-08 21:37:48 +02:00
shared . config . set ( ' bitmessagesettings ' , ' willinglysendtomobile ' , str (
self . settingsDialogInstance . ui . checkBoxWillinglySendToMobile . isChecked ( ) ) )
2013-11-02 00:25:24 +01:00
shared . config . set ( ' bitmessagesettings ' , ' useidenticons ' , str (
self . settingsDialogInstance . ui . checkBoxUseIdenticons . isChecked ( ) ) )
2014-01-28 20:57:01 +01:00
shared . config . set ( ' bitmessagesettings ' , ' replybelow ' , str (
self . settingsDialogInstance . ui . checkBoxReplyBelow . isChecked ( ) ) )
2013-09-21 14:31:47 +02:00
2013-08-24 09:07:46 +02:00
lang_ind = int ( self . settingsDialogInstance . ui . languageComboBox . currentIndex ( ) )
2013-08-24 09:21:59 +02:00
if not languages [ lang_ind ] == ' other ' :
shared . config . set ( ' bitmessagesettings ' , ' userlocale ' , languages [ lang_ind ] )
2014-11-14 12:21:18 +01:00
change_translation ( languages [ lang_ind ] )
2013-11-02 00:25:24 +01:00
2013-06-12 23:12:32 +02:00
if int ( shared . config . get ( ' bitmessagesettings ' , ' port ' ) ) != int ( self . settingsDialogInstance . ui . lineEditTCPPort . text ( ) ) :
2013-07-24 17:46:28 +02:00
if not shared . safeConfigGetBoolean ( ' bitmessagesettings ' , ' dontconnect ' ) :
QMessageBox . about ( self , _translate ( " MainWindow " , " Restart " ) , _translate (
" MainWindow " , " You must restart Bitmessage for the port number change to take effect. " ) )
2013-06-12 23:12:32 +02:00
shared . config . set ( ' bitmessagesettings ' , ' port ' , str (
self . settingsDialogInstance . ui . lineEditTCPPort . text ( ) ) )
2013-08-28 04:29:39 +02:00
#print 'self.settingsDialogInstance.ui.comboBoxProxyType.currentText()', self.settingsDialogInstance.ui.comboBoxProxyType.currentText()
#print 'self.settingsDialogInstance.ui.comboBoxProxyType.currentText())[0:5]', self.settingsDialogInstance.ui.comboBoxProxyType.currentText()[0:5]
if shared . config . get ( ' bitmessagesettings ' , ' socksproxytype ' ) == ' none ' and self . settingsDialogInstance . ui . comboBoxProxyType . currentText ( ) [ 0 : 5 ] == ' SOCKS ' :
2013-05-02 17:53:54 +02:00
if shared . statusIconColor != ' red ' :
2013-06-13 09:59:40 +02:00
QMessageBox . about ( self , _translate ( " MainWindow " , " Restart " ) , _translate (
2013-07-24 06:29:30 +02:00
" MainWindow " , " Bitmessage will use your proxy from now on but you may want to manually restart Bitmessage now to close existing connections (if any). " ) )
2013-08-28 04:29:39 +02:00
if shared . config . get ( ' bitmessagesettings ' , ' socksproxytype ' ) [ 0 : 5 ] == ' SOCKS ' and self . settingsDialogInstance . ui . comboBoxProxyType . currentText ( ) [ 0 : 5 ] != ' SOCKS ' :
2013-05-02 17:53:54 +02:00
self . statusBar ( ) . showMessage ( ' ' )
2013-08-28 04:29:39 +02:00
if self . settingsDialogInstance . ui . comboBoxProxyType . currentText ( ) [ 0 : 5 ] == ' SOCKS ' :
shared . config . set ( ' bitmessagesettings ' , ' socksproxytype ' , str (
self . settingsDialogInstance . ui . comboBoxProxyType . currentText ( ) ) )
else :
shared . config . set ( ' bitmessagesettings ' , ' socksproxytype ' , ' none ' )
2013-06-12 23:12:32 +02:00
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-12 20:03:09 +02:00
shared . config . set ( ' bitmessagesettings ' , ' sockslisten ' , str (
self . settingsDialogInstance . ui . checkBoxSocksListen . isChecked ( ) ) )
2014-09-10 22:47:51 +02:00
try :
# Rounding to integers just for aesthetics
shared . config . set ( ' bitmessagesettings ' , ' maxdownloadrate ' , str (
int ( float ( self . settingsDialogInstance . ui . lineEditMaxDownloadRate . text ( ) ) ) ) )
shared . config . set ( ' bitmessagesettings ' , ' maxuploadrate ' , str (
int ( float ( self . settingsDialogInstance . ui . lineEditMaxUploadRate . text ( ) ) ) ) )
except :
QMessageBox . about ( self , _translate ( " MainWindow " , " Number needed " ) , _translate (
" MainWindow " , " Your maximum download and upload rate must be numbers. Ignoring what you typed. " ) )
2013-07-07 17:34:43 +02:00
2013-07-07 20:04:57 +02:00
shared . config . set ( ' bitmessagesettings ' , ' namecoinrpctype ' ,
self . settingsDialogInstance . getNamecoinType ( ) )
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 ( ) ) )
2014-09-10 22:47:51 +02:00
# Demanded difficulty tab
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 ) ) )
2014-10-15 23:16:27 +02:00
acceptableDifficultyChanged = False
2013-06-11 00:53:15 +02:00
if float ( self . settingsDialogInstance . ui . lineEditMaxAcceptableTotalDifficulty . text ( ) ) > = 1 or float ( self . settingsDialogInstance . ui . lineEditMaxAcceptableTotalDifficulty . text ( ) ) == 0 :
2014-10-15 23:16:27 +02:00
if shared . config . get ( ' bitmessagesettings ' , ' maxacceptablenoncetrialsperbyte ' ) != str ( int ( float (
self . settingsDialogInstance . ui . lineEditMaxAcceptableTotalDifficulty . text ( ) ) * shared . networkDefaultProofOfWorkNonceTrialsPerByte ) ) :
# the user changed the max acceptable total difficulty
acceptableDifficultyChanged = True
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 :
2014-10-15 23:16:27 +02:00
if shared . config . get ( ' bitmessagesettings ' , ' maxacceptablepayloadlengthextrabytes ' ) != str ( int ( float (
self . settingsDialogInstance . ui . lineEditMaxAcceptableSmallMessageDifficulty . text ( ) ) * shared . networkDefaultPayloadLengthExtraBytes ) ) :
# the user changed the max acceptable small message difficulty
acceptableDifficultyChanged = True
shared . config . set ( ' bitmessagesettings ' , ' maxacceptablepayloadlengthextrabytes ' , str ( int ( float (
self . settingsDialogInstance . ui . lineEditMaxAcceptableSmallMessageDifficulty . text ( ) ) * shared . networkDefaultPayloadLengthExtraBytes ) ) )
if acceptableDifficultyChanged :
# It might now be possible to send msgs which were previously marked as toodifficult.
# Let us change them to 'msgqueued'. The singleWorker will try to send them and will again
# mark them as toodifficult if the receiver's required difficulty is still higher than
# we are willing to do.
sqlExecute ( ''' UPDATE sent SET status= ' msgqueued ' WHERE status= ' toodifficult ' ''' )
shared . workerQueue . put ( ( ' sendmessage ' , ' ' ) )
2013-11-04 08:05:07 +01:00
#start:UI setting to stop trying to send messages after X days/months
# I'm open to changing this UI to something else if someone has a better idea.
if ( ( self . settingsDialogInstance . ui . lineEditDays . text ( ) == ' ' ) and ( self . settingsDialogInstance . ui . lineEditMonths . text ( ) == ' ' ) ) : #We need to handle this special case. Bitmessage has its default behavior. The input is blank/blank
shared . config . set ( ' bitmessagesettings ' , ' stopresendingafterxdays ' , ' ' )
shared . config . set ( ' bitmessagesettings ' , ' stopresendingafterxmonths ' , ' ' )
shared . maximumLengthOfTimeToBotherResendingMessages = float ( ' inf ' )
2013-11-06 05:22:51 +01:00
try :
float ( self . settingsDialogInstance . ui . lineEditDays . text ( ) )
lineEditDaysIsValidFloat = True
except :
lineEditDaysIsValidFloat = False
try :
float ( self . settingsDialogInstance . ui . lineEditMonths . text ( ) )
lineEditMonthsIsValidFloat = True
except :
lineEditMonthsIsValidFloat = False
if lineEditDaysIsValidFloat and not lineEditMonthsIsValidFloat :
self . settingsDialogInstance . ui . lineEditMonths . setText ( " 0 " )
if lineEditMonthsIsValidFloat and not lineEditDaysIsValidFloat :
self . settingsDialogInstance . ui . lineEditDays . setText ( " 0 " )
if lineEditDaysIsValidFloat or lineEditMonthsIsValidFloat :
if ( float ( self . settingsDialogInstance . ui . lineEditDays . text ( ) ) > = 0 and float ( self . settingsDialogInstance . ui . lineEditMonths . text ( ) ) > = 0 ) :
shared . maximumLengthOfTimeToBotherResendingMessages = ( float ( str ( self . settingsDialogInstance . ui . lineEditDays . text ( ) ) ) * 24 * 60 * 60 ) + ( float ( str ( self . settingsDialogInstance . ui . lineEditMonths . text ( ) ) ) * ( 60 * 60 * 24 * 365 ) / 12 )
if shared . maximumLengthOfTimeToBotherResendingMessages < 432000 : # If the time period is less than 5 hours, we give zero values to all fields. No message will be sent again.
QMessageBox . about ( self , _translate ( " MainWindow " , " Will not resend ever " ) , _translate (
" MainWindow " , " Note that the time limit you entered is less than the amount of time Bitmessage waits for the first resend attempt therefore your messages will never be resent. " ) )
shared . config . set ( ' bitmessagesettings ' , ' stopresendingafterxdays ' , ' 0 ' )
shared . config . set ( ' bitmessagesettings ' , ' stopresendingafterxmonths ' , ' 0 ' )
shared . maximumLengthOfTimeToBotherResendingMessages = 0
else :
shared . config . set ( ' bitmessagesettings ' , ' stopresendingafterxdays ' , str ( float (
self . settingsDialogInstance . ui . lineEditDays . text ( ) ) ) )
shared . config . set ( ' bitmessagesettings ' , ' stopresendingafterxmonths ' , str ( float (
self . settingsDialogInstance . ui . lineEditMonths . text ( ) ) ) )
2013-05-02 17:53:54 +02:00
2014-09-15 08:34:33 +02:00
shared . writeKeysFile ( )
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 )
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-08-27 02:01:19 +02:00
sqlStoredProcedure ( ' movemessagstoprog ' )
2014-12-26 03:06:10 +01: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 ' )
2013-07-15 21:45:03 +02:00
previousAppdataLocation = shared . appdata
2013-05-02 17:53:54 +02:00
shared . appdata = ' '
2013-07-15 21:45:03 +02:00
debug . restartLoggingInUpdatedAppdataLocation ( )
try :
os . remove ( previousAppdataLocation + ' debug.log ' )
os . remove ( previousAppdataLocation + ' debug.log.1 ' )
except :
pass
2013-05-02 17:53:54 +02:00
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-08-27 02:01:19 +02:00
sqlStoredProcedure ( ' movemessagstoappdata ' )
2013-06-12 23:12:32 +02:00
# Write the keys.dat file to disk in the new location
2014-09-15 08:34:33 +02:00
shared . writeKeysFile ( )
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 ' )
2013-07-15 21:45:03 +02:00
debug . restartLoggingInUpdatedAppdataLocation ( )
try :
os . remove ( ' debug.log ' )
os . remove ( ' debug.log.1 ' )
except :
pass
2013-05-02 17:53:54 +02:00
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 ' )
2014-09-15 08:34:33 +02:00
shared . writeKeysFile ( )
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 )
2014-11-22 22:56:41 +01:00
self . rerenderBlackWhiteList ( )
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 ' )
2014-09-15 08:34:33 +02:00
shared . writeKeysFile ( )
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 )
2014-11-22 22:56:41 +01:00
self . rerenderBlackWhiteList ( )
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 ) :
2013-12-01 05:15:18 +01:00
self . NewBlacklistDialogInstance = AddAddressDialog ( self )
2013-05-02 17:53:54 +02:00
if self . NewBlacklistDialogInstance . exec_ ( ) :
2013-12-01 05:15:18 +01:00
if self . NewBlacklistDialogInstance . ui . labelAddressCheck . text ( ) == _translate ( " MainWindow " , " Address is valid. " ) :
2013-11-02 00:25:24 +01:00
address = addBMIfNotPresent ( str (
2013-12-01 05:15:18 +01:00
self . NewBlacklistDialogInstance . ui . lineEditAddress . text ( ) ) )
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-11-02 00:25:24 +01:00
t = ( address , )
2013-05-02 17:53:54 +02:00
if shared . config . get ( ' bitmessagesettings ' , ' blackwhitelist ' ) == ' black ' :
2013-08-27 02:01:19 +02:00
sql = ''' select * from blacklist where address=? '''
2013-05-02 17:53:54 +02:00
else :
2013-08-27 02:01:19 +02:00
sql = ''' select * from whitelist where address=? '''
queryreturn = sqlQuery ( sql , * t )
2013-05-02 17:53:54 +02:00
if queryreturn == [ ] :
self . ui . tableWidgetBlacklist . setSortingEnabled ( False )
self . ui . tableWidgetBlacklist . insertRow ( 0 )
2013-06-12 23:12:32 +02:00
newItem = QtGui . QTableWidgetItem ( unicode (
2013-12-01 05:15:18 +01:00
self . NewBlacklistDialogInstance . ui . newAddressLabel . text ( ) . toUtf8 ( ) , ' utf-8 ' ) )
2013-11-02 00:25:24 +01:00
newItem . setIcon ( avatarize ( address ) )
2013-06-12 23:12:32 +02:00
self . ui . tableWidgetBlacklist . setItem ( 0 , 0 , newItem )
2013-11-02 00:25:24 +01:00
newItem = QtGui . QTableWidgetItem ( address )
2013-06-12 23:12:32 +02:00
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-12-01 05:15:18 +01:00
t = ( str ( self . NewBlacklistDialogInstance . ui . newAddressLabel . text ( ) . toUtf8 ( ) ) , address , True )
2013-05-02 17:53:54 +02:00
if shared . config . get ( ' bitmessagesettings ' , ' blackwhitelist ' ) == ' black ' :
2013-08-27 02:01:19 +02:00
sql = ''' INSERT INTO blacklist VALUES (?,?,?) '''
2013-05-02 17:53:54 +02:00
else :
2013-08-27 02:01:19 +02:00
sql = ''' INSERT INTO whitelist VALUES (?,?,?) '''
sqlExecute ( sql , * t )
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 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_ ( ) :
2015-03-21 11:37:08 +01:00
addressAtCurrentRow = self . getCurrentAccount ( )
if shared . safeConfigGetBoolean ( addressAtCurrentRow , ' chan ' ) :
return
if self . dialog . ui . radioButtonBehaveNormalAddress . isChecked ( ) :
shared . config . set ( str (
addressAtCurrentRow ) , ' mailinglist ' , ' false ' )
# Set the color to either black or grey
if shared . config . getboolean ( addressAtCurrentRow , ' enabled ' ) :
self . setCurrentItemColor ( QApplication . palette ( )
. text ( ) . color ( ) )
else :
self . setCurrentItemColor ( QtGui . QColor ( 128 , 128 , 128 ) )
else :
shared . config . set ( str (
addressAtCurrentRow ) , ' mailinglist ' , ' true ' )
shared . config . set ( str ( addressAtCurrentRow ) , ' mailinglistname ' , str (
self . dialog . ui . lineEditMailingListName . text ( ) . toUtf8 ( ) ) )
self . setCurrentItemColor ( QtGui . QColor ( 137 , 04 , 177 ) ) #magenta
2015-10-19 21:12:10 +02:00
self . rerenderComboBoxSendFrom ( )
self . rerenderComboBoxSendFromBroadcast ( )
2015-03-21 11:37:08 +01:00
shared . writeKeysFile ( )
self . rerenderInboxToLabels ( )
2015-10-03 17:24:21 +02:00
def on_action_EmailGatewayDialog ( self ) :
self . dialog = EmailGatewayDialog ( self )
# For Modal dialogs
if self . dialog . exec_ ( ) :
addressAtCurrentRow = self . getCurrentAccount ( )
acct = accountClass ( addressAtCurrentRow )
2015-10-05 10:36:04 +02:00
# no chans / mailinglists
if acct . type != ' normal ' :
2015-10-05 17:07:23 +02:00
return
2015-11-10 13:15:07 +01:00
if self . dialog . ui . radioButtonUnregister . isChecked ( ) and isinstance ( acct , GatewayAccount ) :
2015-10-03 17:24:21 +02:00
acct . unregister ( )
shared . config . remove_option ( addressAtCurrentRow , ' gateway ' )
shared . writeKeysFile ( )
2015-10-05 10:36:04 +02:00
elif self . dialog . ui . radioButtonRegister . isChecked ( ) :
2015-10-03 17:24:21 +02:00
email = str ( self . dialog . ui . lineEditEmail . text ( ) . toUtf8 ( ) )
acct = MailchuckAccount ( addressAtCurrentRow )
acct . register ( email )
shared . config . set ( addressAtCurrentRow , ' label ' , email )
shared . config . set ( addressAtCurrentRow , ' gateway ' , ' mailchuck ' )
2015-10-04 11:47:06 +02:00
self . getCurrentTreeWidget ( ) . currentItem ( ) . updateText ( )
2015-10-03 17:24:21 +02:00
shared . writeKeysFile ( )
else :
2015-10-05 10:36:04 +02:00
pass
#print "well nothing"
2015-10-03 17:24:21 +02:00
# shared.writeKeysFile()
# self.rerenderInboxToLabels()
2013-05-02 17:53:54 +02:00
def click_NewAddressDialog ( self ) :
2015-10-01 09:42:47 +02:00
addresses = [ ]
2015-10-19 20:03:06 +02:00
for addressInKeysFile in getSortedAccounts ( ) :
2015-10-01 09:42:47 +02:00
addresses . append ( addressInKeysFile )
2015-10-03 17:24:21 +02:00
# self.dialog = Ui_NewAddressWizard(addresses)
# self.dialog.exec_()
2015-10-01 09:42:47 +02:00
# print "Name: " + self.dialog.field("name").toString()
# print "Email: " + self.dialog.field("email").toString()
2015-10-03 17:24:21 +02:00
# return
2013-05-02 17:53:54 +02:00
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.'
2013-09-13 06:27:34 +02:00
streamNumberForAddress = decodeAddress (
self . dialog . ui . comboBoxExisting . currentText ( ) ) [ 2 ]
shared . addressGeneratorQueue . put ( ( ' createRandomAddress ' , 4 , streamNumberForAddress , str (
2013-06-12 23:12:32 +02:00
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.
2013-09-13 06:27:34 +02:00
shared . addressGeneratorQueue . put ( ( ' createDeterministicAddresses ' , 4 , streamNumberForAddress , " unused deterministic address " , self . dialog . ui . spinBoxNumberOfAddressesToMake . value (
2013-06-12 23:12:32 +02:00
) , self . dialog . ui . lineEditPassphrase . text ( ) . toUtf8 ( ) , self . dialog . ui . checkBoxEighteenByteRipe . isChecked ( ) ) )
2013-05-02 17:53:54 +02:00
else :
2015-11-18 16:22:17 +01:00
logger . debug ( ' new address dialog box rejected ' )
2013-05-02 17:53:54 +02:00
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
'''
2015-11-14 21:07:46 +01:00
# save state and geometry self and all widgets
self . saveSettings ( )
for attr , obj in self . ui . __dict__ . iteritems ( ) :
if hasattr ( obj , " __class__ " ) and isinstance ( obj , settingsmixin . SettingsMixin ) :
saveMethod = getattr ( obj , " saveSettings " , None )
if callable ( saveMethod ) :
obj . saveSettings ( )
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 ( )
2015-10-11 11:57:58 +02:00
2015-11-08 21:44:02 +01:00
# settings = QSettings("Bitmessage", "PyBitmessage")
# settings.setValue("geometry", self.saveGeometry())
# settings.setValue("state", self.saveState())
2015-10-11 11:57:58 +02:00
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 ) :
2015-03-23 22:35:56 +01:00
msgid = self . getCurrentMessageId ( )
textEdit = self . getCurrentMessageTextedit ( )
if not msgid :
return
2013-10-16 07:08:22 +02:00
queryreturn = sqlQuery (
''' select message from inbox where msgid=? ''' , msgid )
if queryreturn != [ ] :
for row in queryreturn :
2014-06-02 19:05:26 +02:00
messageText , = row
2013-10-16 07:08:22 +02:00
2014-06-02 19:05:26 +02:00
lines = messageText . split ( ' \n ' )
2014-06-03 07:45:59 +02:00
totalLines = len ( lines )
for i in xrange ( totalLines ) :
2013-10-16 07:08:22 +02:00
if ' Message ostensibly from ' in lines [ i ] :
2014-06-03 07:45:59 +02:00
lines [ i ] = ' <p style= " font-size: 12px; color: grey; " > %s </span></p> ' % (
2013-06-12 23:12:32 +02:00
lines [ i ] )
2013-05-02 17:53:54 +02:00
elif lines [ i ] == ' ------------------------------------------------------ ' :
lines [ i ] = ' <hr> '
2014-06-03 07:45:59 +02:00
elif lines [ i ] == ' ' and ( i + 1 ) < totalLines and \
lines [ i + 1 ] != ' ------------------------------------------------------ ' :
lines [ i ] = ' <br><br> '
content = ' ' . join ( lines ) # To keep the whitespace between lines
content = shared . fixPotentiallyInvalidUTF8Data ( content )
content = unicode ( content , ' utf-8) ' )
2015-03-23 22:35:56 +01:00
textEdit . setHtml ( QtCore . QString ( content ) )
2013-05-02 17:53:54 +02:00
2013-07-26 04:00:54 +02:00
def on_action_InboxMarkUnread ( self ) :
2015-03-23 22:35:56 +01:00
tableWidget = self . getCurrentMessagelist ( )
if not tableWidget :
return
2013-07-26 04:00:54 +02:00
font = QFont ( )
font . setBold ( True )
2014-10-20 17:45:53 +02:00
inventoryHashesToMarkUnread = [ ]
2015-10-31 20:04:52 +01:00
modified = 0
2015-03-23 22:35:56 +01:00
for row in tableWidget . selectedIndexes ( ) :
2013-07-26 04:00:54 +02:00
currentRow = row . row ( )
2015-03-23 22:35:56 +01:00
inventoryHashToMarkUnread = str ( tableWidget . item (
2013-07-26 04:00:54 +02:00
currentRow , 3 ) . data ( Qt . UserRole ) . toPyObject ( ) )
2015-10-31 20:04:52 +01:00
if inventoryHashToMarkUnread in inventoryHashesToMarkUnread :
# it returns columns as separate items, so we skip dupes
continue
if not tableWidget . item ( currentRow , 0 ) . font ( ) . bold ( ) :
modified + = 1
2014-10-20 17:45:53 +02:00
inventoryHashesToMarkUnread . append ( inventoryHashToMarkUnread )
2015-03-23 22:35:56 +01:00
tableWidget . item ( currentRow , 0 ) . setFont ( font )
tableWidget . item ( currentRow , 1 ) . setFont ( font )
tableWidget . item ( currentRow , 2 ) . setFont ( font )
tableWidget . item ( currentRow , 3 ) . setFont ( font )
2014-10-20 17:45:53 +02:00
#sqlite requires the exact number of ?s to prevent injection
sqlExecute ( ''' UPDATE inbox SET read=0 WHERE msgid IN ( %s ) ''' % (
" ?, " * len ( inventoryHashesToMarkUnread ) ) [ : - 1 ] , * inventoryHashesToMarkUnread )
2015-10-31 20:04:52 +01:00
if modified == 1 :
# performance optimisation
2015-11-01 09:01:34 +01:00
self . propagateUnreadCount ( self . getCurrentAccount ( ) , self . getCurrentFolder ( ) )
2015-10-31 20:04:52 +01:00
else :
2015-11-01 09:01:34 +01:00
self . propagateUnreadCount ( self . getCurrentAccount ( ) , self . getCurrentFolder ( ) , self . getCurrentTreeWidget ( ) , 0 )
2015-03-23 22:35:56 +01:00
# tableWidget.selectRow(currentRow + 1)
2013-07-26 04:10:22 +02:00
# This doesn't de-select the last message if you try to mark it unread, but that doesn't interfere. Might not be necessary.
# We could also select upwards, but then our problem would be with the topmost message.
2015-03-23 22:35:56 +01:00
# tableWidget.clearSelection() manages to mark the message as read again.
2013-07-26 04:00:54 +02:00
2014-01-28 20:32:16 +01:00
# Format predefined text on message reply.
def quoted_text ( self , message ) :
2014-01-28 20:57:01 +01:00
if not shared . safeConfigGetBoolean ( ' bitmessagesettings ' , ' replybelow ' ) :
return ' \n \n ------------------------------------------------------ \n ' + message
2014-01-28 20:32:16 +01:00
quoteWrapper = textwrap . TextWrapper ( replace_whitespace = False ,
initial_indent = ' > ' ,
subsequent_indent = ' > ' ,
break_long_words = False ,
break_on_hyphens = False )
def quote_line ( line ) :
# Do quote empty lines.
if line == ' ' or line . isspace ( ) :
return ' > '
# Quote already quoted lines, but do not wrap them.
elif line [ 0 : 2 ] == ' > ' :
return ' > ' + line
# Wrap and quote lines/paragraphs new to this message.
else :
return quoteWrapper . fill ( line )
return ' \n ' . join ( [ quote_line ( l ) for l in message . splitlines ( ) ] ) + ' \n \n '
2013-05-02 17:53:54 +02:00
def on_action_InboxReply ( self ) :
2015-03-23 22:35:56 +01:00
tableWidget = self . getCurrentMessagelist ( )
if not tableWidget :
return
2015-10-19 17:37:43 +02:00
# save this to return back after reply is done
self . replyFromTab = self . ui . tabWidget . currentIndex ( )
2015-03-23 22:35:56 +01:00
currentInboxRow = tableWidget . currentRow ( )
toAddressAtCurrentInboxRow = str ( tableWidget . item (
2013-06-12 23:12:32 +02:00
currentInboxRow , 0 ) . data ( Qt . UserRole ) . toPyObject ( ) )
2015-10-03 17:24:21 +02:00
acct = accountClass ( toAddressAtCurrentInboxRow )
2015-03-23 22:35:56 +01:00
fromAddressAtCurrentInboxRow = str ( tableWidget . item (
2013-06-12 23:12:32 +02:00
currentInboxRow , 1 ) . data ( Qt . UserRole ) . toPyObject ( ) )
2015-03-23 22:35:56 +01:00
msgid = str ( tableWidget . item (
2013-10-13 19:45:30 +02:00
currentInboxRow , 3 ) . data ( Qt . UserRole ) . toPyObject ( ) )
queryreturn = sqlQuery (
''' select message from inbox where msgid=? ''' , msgid )
if queryreturn != [ ] :
for row in queryreturn :
messageAtCurrentInboxRow , = row
2015-10-18 22:54:52 +02:00
acct . parseMessage ( toAddressAtCurrentInboxRow , fromAddressAtCurrentInboxRow , unicode ( tableWidget . item ( currentInboxRow , 2 ) . data ( Qt . UserRole ) . toPyObject ( ) , ' utf-8 ' ) , messageAtCurrentInboxRow )
2015-10-13 23:36:09 +02:00
widget = {
' subject ' : self . ui . lineEditSubject ,
' from ' : self . ui . comboBoxSendFrom ,
' message ' : self . ui . textEditMessage
}
if toAddressAtCurrentInboxRow == str_broadcast_subscribers :
2015-10-14 23:38:34 +02:00
self . ui . tabWidgetSend . setCurrentIndex ( 0 )
# toAddressAtCurrentInboxRow = fromAddressAtCurrentInboxRow
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 )
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-05-02 17:53:54 +02:00
else :
2015-10-14 23:38:34 +02:00
self . setBroadcastEnablementDependingOnWhetherThisIsAMailingListAddress ( toAddressAtCurrentInboxRow )
if self . ui . tabWidgetSend . currentIndex ( ) == 1 :
widget = {
' subject ' : self . ui . lineEditSubjectBroadcast ,
' from ' : self . ui . comboBoxSendFromBroadcast ,
' message ' : self . ui . textEditMessageBroadcast
}
self . ui . tabWidgetSend . setCurrentIndex ( 1 )
toAddressAtCurrentInboxRow = fromAddressAtCurrentInboxRow
2013-09-04 23:33:39 +02:00
2015-10-13 23:36:09 +02:00
self . ui . lineEditTo . setText ( str ( acct . fromAddress ) )
2013-09-04 23:33:39 +02:00
# If the previous message was to a chan then we should send our reply to the chan rather than to the particular person who sent the message.
if shared . config . has_section ( toAddressAtCurrentInboxRow ) :
if shared . safeConfigGetBoolean ( toAddressAtCurrentInboxRow , ' chan ' ) :
2015-11-18 16:22:17 +01:00
logger . debug ( ' original sent to a chan. Setting the to address in the reply to the chan address. ' )
2013-09-04 23:33:39 +02:00
self . ui . lineEditTo . setText ( str ( toAddressAtCurrentInboxRow ) )
2013-12-01 10:23:34 +01:00
2015-10-13 23:36:09 +02:00
listOfAddressesInComboBoxSendFrom = [ str ( widget [ ' from ' ] . itemData ( i ) . toPyObject ( ) ) for i in range ( widget [ ' from ' ] . count ( ) ) ]
2013-12-25 07:48:01 +01:00
if toAddressAtCurrentInboxRow in listOfAddressesInComboBoxSendFrom :
currentIndex = listOfAddressesInComboBoxSendFrom . index ( toAddressAtCurrentInboxRow )
2015-10-13 23:36:09 +02:00
widget [ ' from ' ] . setCurrentIndex ( currentIndex )
2013-12-01 10:23:34 +01:00
else :
2015-10-13 23:36:09 +02:00
widget [ ' from ' ] . setCurrentIndex ( 0 )
2013-12-25 07:30:39 +01:00
2014-01-28 20:32:16 +01:00
quotedText = self . quoted_text ( unicode ( messageAtCurrentInboxRow , ' utf-8 ' ) )
2015-10-13 23:36:09 +02:00
widget [ ' message ' ] . setText ( quotedText )
2015-10-03 17:24:21 +02:00
if acct . subject [ 0 : 3 ] in [ ' Re: ' , ' RE: ' ] :
2015-10-13 23:36:09 +02:00
widget [ ' subject ' ] . setText ( acct . subject )
2013-05-02 17:53:54 +02:00
else :
2015-10-13 23:36:09 +02:00
widget [ ' subject ' ] . setText ( ' Re: ' + acct . subject )
2013-05-02 17:53:54 +02:00
self . ui . tabWidget . setCurrentIndex ( 1 )
def on_action_InboxAddSenderToAddressBook ( self ) :
2015-03-23 22:35:56 +01:00
tableWidget = self . getCurrentMessagelist ( )
if not tableWidget :
return
currentInboxRow = tableWidget . currentRow ( )
# tableWidget.item(currentRow,1).data(Qt.UserRole).toPyObject()
addressAtCurrentInboxRow = str ( tableWidget . item (
2013-06-12 23:12:32 +02:00
currentInboxRow , 1 ) . data ( Qt . UserRole ) . toPyObject ( ) )
# Let's make sure that it isn't already in the address book
2013-08-27 02:01:19 +02:00
queryreturn = sqlQuery ( ''' select * from addressbook where address=? ''' ,
addressAtCurrentInboxRow )
2013-05-02 17:53:54 +02:00
if queryreturn == [ ] :
2013-08-27 02:01:19 +02:00
sqlExecute ( ''' INSERT INTO addressbook VALUES (?,?) ''' ,
' --New entry. Change label in Address Book.-- ' ,
addressAtCurrentInboxRow )
2015-11-13 14:31:22 +01:00
self . rerenderAddressBook ( )
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
2015-11-14 01:14:10 +01:00
def on_action_InboxAddSenderToBlackList ( self ) :
tableWidget = self . getCurrentMessagelist ( )
if not tableWidget :
return
currentInboxRow = tableWidget . currentRow ( )
# tableWidget.item(currentRow,1).data(Qt.UserRole).toPyObject()
addressAtCurrentInboxRow = str ( tableWidget . item (
currentInboxRow , 1 ) . data ( Qt . UserRole ) . toPyObject ( ) )
# Let's make sure that it isn't already in the address book
queryreturn = sqlQuery ( ''' select * from blacklist where address=? ''' ,
addressAtCurrentInboxRow )
if queryreturn == [ ] :
2015-11-14 18:53:11 +01:00
label = " \" " + str ( tableWidget . item ( currentInboxRow , 2 ) . data ( Qt . UserRole ) . toPyObject ( ) ) + " \" in " + shared . config . get ( self . getCurrentAccount ( ) , " label " )
2015-11-14 01:14:10 +01:00
sqlExecute ( ''' INSERT INTO blacklist VALUES (?,?, ?) ''' ,
2015-11-14 18:53:11 +01:00
label ,
2015-11-14 01:14:10 +01:00
addressAtCurrentInboxRow , True )
self . rerenderBlackWhiteList ( )
self . statusBar ( ) . showMessage ( _translate (
" MainWindow " , " Entry added to the blacklist. Edit the label to your liking. " ) )
else :
self . statusBar ( ) . showMessage ( _translate (
" MainWindow " , " Error: You cannot add the same address to your blacklist twice. Try renaming the existing one if you want. " ) )
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 ) :
2015-03-23 22:35:56 +01:00
tableWidget = self . getCurrentMessagelist ( )
if not tableWidget :
return
2015-10-03 12:12:18 +02:00
unread = False
2015-10-10 19:58:01 +02:00
currentRow = 0
2015-11-19 17:37:34 +01:00
folder = self . getCurrentFolder ( )
shifted = QtGui . QApplication . queryKeyboardModifiers ( ) & QtCore . Qt . ShiftModifier
2015-10-10 19:58:01 +02:00
while tableWidget . selectedIndexes ( ) :
2015-03-23 22:35:56 +01:00
currentRow = tableWidget . selectedIndexes ( ) [ 0 ] . row ( )
inventoryHashToTrash = str ( tableWidget . item (
2013-06-12 23:12:32 +02:00
currentRow , 3 ) . data ( Qt . UserRole ) . toPyObject ( ) )
2015-11-19 17:37:34 +01:00
if folder == " trash " or shifted :
sqlExecute ( ''' DELETE FROM inbox WHERE msgid=? ''' , inventoryHashToTrash )
else :
sqlExecute ( ''' UPDATE inbox SET folder= ' trash ' WHERE msgid=? ''' , inventoryHashToTrash )
2015-10-03 12:12:18 +02:00
if tableWidget . item ( currentRow , 0 ) . font ( ) . bold ( ) :
unread = True
2015-11-01 11:09:58 +01:00
self . getCurrentMessageTextedit ( ) . setText ( " " )
2015-03-23 22:35:56 +01:00
tableWidget . removeRow ( currentRow )
2013-06-13 09:59:40 +02:00
self . statusBar ( ) . showMessage ( _translate (
2015-09-30 11:30:21 +02:00
" MainWindow " , " Moved items to trash. " ) )
2013-05-02 17:53:54 +02:00
if currentRow == 0 :
2015-03-23 22:35:56 +01:00
tableWidget . selectRow ( currentRow )
2013-05-02 17:53:54 +02:00
else :
2015-03-23 22:35:56 +01:00
tableWidget . selectRow ( currentRow - 1 )
2015-10-03 12:12:18 +02:00
if unread :
2015-11-01 11:09:36 +01:00
self . propagateUnreadCount ( self . getCurrentAccount ( ) , None , self . getCurrentTreeWidget ( ) , 0 )
2015-11-01 10:56:37 +01:00
def on_action_TrashUndelete ( self ) :
tableWidget = self . getCurrentMessagelist ( )
if not tableWidget :
return
unread = False
currentRow = 0
while tableWidget . selectedIndexes ( ) :
currentRow = tableWidget . selectedIndexes ( ) [ 0 ] . row ( )
inventoryHashToTrash = str ( tableWidget . item (
currentRow , 3 ) . data ( Qt . UserRole ) . toPyObject ( ) )
sqlExecute ( ''' UPDATE inbox SET folder= ' inbox ' WHERE msgid=? ''' , inventoryHashToTrash )
if tableWidget . item ( currentRow , 0 ) . font ( ) . bold ( ) :
unread = True
self . getCurrentMessageTextedit ( ) . setText ( " " )
tableWidget . removeRow ( currentRow )
self . statusBar ( ) . showMessage ( _translate (
" MainWindow " , " Undeleted item. " ) )
if currentRow == 0 :
tableWidget . selectRow ( currentRow )
else :
tableWidget . selectRow ( currentRow - 1 )
if unread :
self . propagateUnreadCount ( self . getCurrentAccount ( ) , None , self . getCurrentTreeWidget ( ) , 0 )
2013-05-02 17:53:54 +02:00
2013-06-17 00:28:18 +02:00
def on_action_InboxSaveMessageAs ( self ) :
2015-03-23 22:35:56 +01:00
tableWidget = self . getCurrentMessagelist ( )
if not tableWidget :
return
currentInboxRow = tableWidget . currentRow ( )
2013-06-19 22:49:31 +02:00
try :
2015-03-23 22:35:56 +01:00
subjectAtCurrentInboxRow = str ( tableWidget . item ( currentInboxRow , 2 ) . text ( ) )
2013-06-19 22:49:31 +02:00
except :
subjectAtCurrentInboxRow = ' '
2013-10-16 07:08:22 +02:00
# Retrieve the message data out of the SQL database
2015-03-23 22:35:56 +01:00
msgid = str ( tableWidget . item (
2013-10-16 07:08:22 +02:00
currentInboxRow , 3 ) . data ( Qt . UserRole ) . toPyObject ( ) )
queryreturn = sqlQuery (
''' select message from inbox where msgid=? ''' , msgid )
if queryreturn != [ ] :
for row in queryreturn :
message , = row
2013-06-17 00:28:18 +02:00
defaultFilename = " " . join ( x for x in subjectAtCurrentInboxRow if x . isalnum ( ) ) + ' .txt '
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-10-16 07:08:22 +02:00
f . write ( message )
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 ) :
2015-11-01 10:59:11 +01:00
currentRow = 0
unread = False
tableWidget = self . getCurrentMessagelist ( )
if not tableWidget :
return
2015-11-19 17:37:34 +01:00
folder = self . getCurrentFolder ( )
shifted = ( QtGui . QApplication . queryKeyboardModifiers ( ) & QtCore . Qt . ShiftModifier ) > 0
2015-11-01 10:59:11 +01:00
while tableWidget . selectedIndexes ( ) != [ ] :
currentRow = tableWidget . selectedIndexes ( ) [ 0 ] . row ( )
ackdataToTrash = str ( tableWidget . item (
2013-06-12 23:12:32 +02:00
currentRow , 3 ) . data ( Qt . UserRole ) . toPyObject ( ) )
2015-11-19 17:37:34 +01:00
if folder == " trash " or shifted :
sqlExecute ( ''' DELETE FROM sent WHERE ackdata=? ''' , ackdataToTrash )
else :
sqlExecute ( ''' UPDATE sent SET folder= ' trash ' WHERE ackdata=? ''' , ackdataToTrash )
2015-11-01 10:59:11 +01:00
if tableWidget . item ( currentRow , 0 ) . font ( ) . bold ( ) :
unread = True
self . getCurrentMessageTextedit ( ) . setPlainText ( " " )
tableWidget . removeRow ( currentRow )
2013-06-13 09:59:40 +02:00
self . statusBar ( ) . showMessage ( _translate (
2015-11-01 10:59:11 +01:00
" MainWindow " , " Moved items to trash. " ) )
2013-05-02 17:53:54 +02:00
if currentRow == 0 :
2015-03-03 18:17:56 +01:00
self . ui . tableWidgetInbox . selectRow ( currentRow )
2013-05-02 17:53:54 +02:00
else :
2015-03-03 18:17:56 +01:00
self . ui . tableWidgetInbox . selectRow ( currentRow - 1 )
2015-11-01 10:59:11 +01:00
if unread :
self . propagateUnreadCount ( self . getCurrentAccount ( ) , None , self . getCurrentTreeWidget ( ) , 0 )
2013-05-02 17:53:54 +02:00
2013-06-11 00:53:15 +02:00
def on_action_ForceSend ( self ) :
2015-03-03 18:17:56 +01:00
currentRow = self . ui . tableWidgetInbox . currentRow ( )
addressAtCurrentRow = str ( self . ui . tableWidgetInbox . item (
2013-06-12 23:12:32 +02:00
currentRow , 0 ) . data ( Qt . UserRole ) . toPyObject ( ) )
2013-06-11 00:53:15 +02:00
toRipe = decodeAddress ( addressAtCurrentRow ) [ 3 ]
2013-08-27 02:01:19 +02:00
sqlExecute (
''' UPDATE sent SET status= ' forcepow ' WHERE toripe=? AND status= ' toodifficult ' and folder= ' sent ' ''' ,
toRipe )
queryreturn = sqlQuery ( ''' select ackdata FROM sent WHERE status= ' forcepow ' ''' )
2013-06-11 00:53:15 +02:00
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 ) :
2015-03-03 18:17:56 +01:00
currentRow = self . ui . tableWidgetInbox . currentRow ( )
addressAtCurrentRow = str ( self . ui . tableWidgetInbox . item (
2013-06-12 23:12:32 +02:00
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 ( )
2013-08-27 02:01:19 +02:00
sqlExecute ( ''' DELETE FROM addressbook WHERE label=? AND address=? ''' ,
str ( labelAtCurrentRow ) , str ( addressAtCurrentRow ) )
2013-05-02 17:53:54 +02:00
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 ) :
2015-03-21 11:37:08 +01:00
self . statusBar ( ) . showMessage ( QtGui . QApplication . translate ( " MainWindow " , " Error: You cannot add the same address to your subscriptions twice. Perhaps rename the existing one if you want. " ) )
2013-06-14 04:27:52 +02:00
continue
2013-06-19 19:10:43 +02:00
labelAtCurrentRow = self . ui . tableWidgetAddressBook . item ( currentRow , 0 ) . text ( ) . toUtf8 ( )
2013-07-22 07:10:22 +02:00
self . addSubscription ( addressAtCurrentRow , labelAtCurrentRow )
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 ) :
2015-11-01 08:46:27 +01:00
self . popMenuAddressBook = QtGui . QMenu ( self )
2015-10-31 21:38:54 +01:00
self . popMenuAddressBook . addAction ( self . actionAddressBookSend )
self . popMenuAddressBook . addAction ( self . actionAddressBookClipboard )
self . popMenuAddressBook . addAction ( self . actionAddressBookSubscribe )
self . popMenuAddressBook . addAction ( self . actionAddressBookSetAvatar )
self . popMenuAddressBook . addSeparator ( )
self . popMenuAddressBook . addAction ( self . actionAddressBookNew )
normal = True
for row in self . ui . tableWidgetAddressBook . selectedIndexes ( ) :
currentRow = row . row ( )
type = str ( self . ui . tableWidgetAddressBook . item (
currentRow , 0 ) . data ( Qt . UserRole ) . toPyObject ( ) )
if type != " normal " :
normal = False
if normal :
# only if all selected addressbook items are normal, allow delete
self . popMenuAddressBook . addAction ( self . actionAddressBookDelete )
2013-06-12 23:12:32 +02:00
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 ) :
2015-03-23 22:35:56 +01:00
address = self . getCurrentAccount ( )
sqlExecute ( ''' DELETE FROM subscriptions WHERE address=? ''' ,
address )
self . rerenderTabTreeSubscriptions ( )
2013-05-02 17:53:54 +02:00
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 ) :
2015-03-23 22:35:56 +01:00
address = self . getCurrentAccount ( )
2013-05-02 17:53:54 +02:00
clipboard = QtGui . QApplication . clipboard ( )
2015-03-23 22:35:56 +01:00
clipboard . setText ( str ( address ) )
2013-06-12 23:12:32 +02:00
2013-05-02 17:53:54 +02:00
def on_action_SubscriptionsEnable ( self ) :
2015-03-23 22:35:56 +01:00
address = self . getCurrentAccount ( )
2013-08-27 02:01:19 +02:00
sqlExecute (
2015-03-23 22:35:56 +01:00
''' update subscriptions set enabled=1 WHERE address=? ''' ,
address )
2015-10-27 19:24:29 +01:00
account = self . getCurrentItem ( )
account . setEnabled ( True )
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 ) :
2015-03-23 22:35:56 +01:00
address = self . getCurrentAccount ( )
2013-08-27 02:01:19 +02:00
sqlExecute (
2015-03-23 22:35:56 +01:00
''' update subscriptions set enabled=0 WHERE address=? ''' ,
address )
2015-10-27 19:24:29 +01:00
account = self . getCurrentItem ( )
account . setEnabled ( False )
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 ) :
2015-11-01 08:46:27 +01:00
self . popMenuSubscriptions = QtGui . QMenu ( self )
self . popMenuSubscriptions . addAction ( self . actionsubscriptionsNew )
self . popMenuSubscriptions . addAction ( self . actionsubscriptionsDelete )
self . popMenuSubscriptions . addSeparator ( )
if self . getCurrentItem ( ) . isEnabled :
self . popMenuSubscriptions . addAction ( self . actionsubscriptionsDisable )
else :
self . popMenuSubscriptions . addAction ( self . actionsubscriptionsEnable )
self . popMenuSubscriptions . addAction ( self . actionsubscriptionsSetAvatar )
self . popMenuSubscriptions . addSeparator ( )
self . popMenuSubscriptions . addAction ( self . actionsubscriptionsClipboard )
2013-06-12 23:12:32 +02:00
self . popMenuSubscriptions . exec_ (
2015-03-23 22:35:56 +01:00
self . ui . treeWidgetSubscriptions . 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 ( )
2013-05-02 17:53:54 +02:00
if shared . config . get ( ' bitmessagesettings ' , ' blackwhitelist ' ) == ' black ' :
2013-08-27 02:01:19 +02:00
sqlExecute (
''' DELETE FROM blacklist WHERE label=? AND address=? ''' ,
str ( labelAtCurrentRow ) , str ( addressAtCurrentRow ) )
2013-05-02 17:53:54 +02:00
else :
2013-08-27 02:01:19 +02:00
sqlExecute (
''' DELETE FROM whitelist WHERE label=? AND address=? ''' ,
str ( labelAtCurrentRow ) , str ( addressAtCurrentRow ) )
2013-05-02 17:53:54 +02:00
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 (
2013-07-22 20:28:51 +02:00
currentRow , 0 ) . setTextColor ( QApplication . palette ( ) . text ( ) . color ( ) )
2013-06-12 23:12:32 +02:00
self . ui . tableWidgetBlacklist . item (
2013-07-22 20:28:51 +02:00
currentRow , 1 ) . setTextColor ( QApplication . palette ( ) . text ( ) . color ( ) )
2013-05-02 17:53:54 +02:00
if shared . config . get ( ' bitmessagesettings ' , ' blackwhitelist ' ) == ' black ' :
2013-08-27 02:01:19 +02:00
sqlExecute (
''' UPDATE blacklist SET enabled=1 WHERE address=? ''' ,
str ( addressAtCurrentRow ) )
2013-05-02 17:53:54 +02:00
else :
2013-08-27 02:01:19 +02:00
sqlExecute (
''' UPDATE whitelist SET enabled=1 WHERE address=? ''' ,
str ( addressAtCurrentRow ) )
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
if shared . config . get ( ' bitmessagesettings ' , ' blackwhitelist ' ) == ' black ' :
2013-08-27 02:01:19 +02:00
sqlExecute (
''' UPDATE blacklist SET enabled=0 WHERE address=? ''' , str ( addressAtCurrentRow ) )
2013-05-02 17:53:54 +02:00
else :
2013-08-27 02:01:19 +02:00
sqlExecute (
''' UPDATE whitelist SET enabled=0 WHERE address=? ''' , str ( addressAtCurrentRow ) )
2013-05-02 17:53:54 +02:00
2015-11-09 19:39:30 +01:00
def widgetConvert ( self , widget ) :
if widget == self . ui . tableWidgetInbox :
return self . ui . treeWidgetYourIdentities
elif widget == self . ui . tableWidgetInboxSubscriptions :
return self . ui . treeWidgetSubscriptions
elif widget == self . ui . tableWidgetInboxChans :
return self . ui . treeWidgetChans
elif widget == self . ui . treeWidgetYourIdentities :
return self . ui . tableWidgetInbox
elif widget == self . ui . treeWidgetSubscriptions :
return self . ui . tableWidgetInboxSubscriptions
elif twidget == self . ui . treeWidgetChans :
return self . ui . tableWidgetInboxChans
else :
return None
2015-03-21 11:37:08 +01:00
def getCurrentTreeWidget ( self ) :
currentIndex = self . ui . tabWidget . currentIndex ( ) ;
treeWidgetList = [
self . ui . treeWidgetYourIdentities ,
False ,
self . ui . treeWidgetSubscriptions ,
self . ui . treeWidgetChans
]
if currentIndex > = 0 and currentIndex < len ( treeWidgetList ) :
return treeWidgetList [ currentIndex ]
else :
return False
2015-10-22 23:56:20 +02:00
def getAccountTreeWidget ( self , account ) :
try :
if account . type == ' chan ' :
return self . ui . treeWidgetChans
elif account . type == ' subscription ' :
return self . ui . treeWidgetSubscriptions
else :
return self . ui . treeWidgetYourIdentities
except :
return self . ui . treeWidgetYourIdentities
2015-03-23 22:35:56 +01:00
def getCurrentMessagelist ( self ) :
currentIndex = self . ui . tabWidget . currentIndex ( ) ;
messagelistList = [
self . ui . tableWidgetInbox ,
False ,
self . ui . tableWidgetInboxSubscriptions ,
self . ui . tableWidgetInboxChans ,
]
if currentIndex > = 0 and currentIndex < len ( messagelistList ) :
return messagelistList [ currentIndex ]
else :
return False
2015-10-22 23:56:20 +02:00
def getAccountMessagelist ( self , account ) :
try :
if account . type == ' chan ' :
return self . ui . tableWidgetInboxChans
elif account . type == ' subscription ' :
return self . ui . tableWidgetInboxSubscriptions
else :
return self . ui . tableWidgetInbox
except :
return self . ui . tableWidgetInbox
2015-03-23 22:35:56 +01:00
def getCurrentMessageId ( self ) :
messagelist = self . getCurrentMessagelist ( )
if messagelist :
currentRow = messagelist . currentRow ( )
if currentRow > = 0 :
msgid = str ( messagelist . item (
currentRow , 3 ) . data ( Qt . UserRole ) . toPyObject ( ) ) # data is saved at the 4. column of the table...
return msgid
return False
def getCurrentMessageTextedit ( self ) :
currentIndex = self . ui . tabWidget . currentIndex ( ) ;
messagelistList = [
self . ui . textEditInboxMessage ,
False ,
self . ui . textEditInboxMessageSubscriptions ,
self . ui . textEditInboxMessageChans ,
]
if currentIndex > = 0 and currentIndex < len ( messagelistList ) :
return messagelistList [ currentIndex ]
else :
return False
2015-10-22 23:56:20 +02:00
def getAccountTextedit ( self , account ) :
try :
if account . type == ' chan ' :
return self . ui . textEditInboxMessageChans
elif account . type == ' subscription ' :
return self . ui . textEditInboxSubscriptions
else :
return self . ui . textEditInboxMessage
except :
return self . ui . textEditInboxMessage
2015-03-23 22:35:56 +01:00
def getCurrentSearchLine ( self ) :
currentIndex = self . ui . tabWidget . currentIndex ( ) ;
messagelistList = [
self . ui . inboxSearchLineEdit ,
False ,
self . ui . inboxSearchLineEditSubscriptions ,
self . ui . inboxSearchLineEditChans ,
]
if currentIndex > = 0 and currentIndex < len ( messagelistList ) :
return messagelistList [ currentIndex ]
else :
return False
def getCurrentSearchOption ( self ) :
currentIndex = self . ui . tabWidget . currentIndex ( ) ;
messagelistList = [
self . ui . inboxSearchOption ,
False ,
self . ui . inboxSearchOptionSubscriptions ,
self . ui . inboxSearchOptionChans ,
]
if currentIndex > = 0 and currentIndex < len ( messagelistList ) :
return messagelistList [ currentIndex ] . currentText ( ) . toUtf8 ( ) . data ( )
else :
return False
2013-06-12 23:12:32 +02:00
# Group of functions for the Your Identities dialog box
2015-10-22 23:56:20 +02:00
def getCurrentItem ( self , treeWidget = None ) :
if treeWidget is None :
treeWidget = self . getCurrentTreeWidget ( )
2015-03-21 11:37:08 +01:00
if treeWidget :
currentItem = treeWidget . currentItem ( )
if currentItem :
2015-10-19 17:22:37 +02:00
return currentItem
return False
2015-10-22 23:56:20 +02:00
def getCurrentAccount ( self , treeWidget = None ) :
currentItem = self . getCurrentItem ( treeWidget )
2015-10-19 17:22:37 +02:00
if currentItem :
account = currentItem . address
return account
else :
# TODO need debug msg?
return False
2015-03-21 11:37:08 +01:00
2015-10-22 23:56:20 +02:00
def getCurrentFolder ( self , treeWidget = None ) :
if treeWidget is None :
treeWidget = self . getCurrentTreeWidget ( )
2015-10-14 23:43:50 +02:00
#treeWidget = self.ui.treeWidgetYourIdentities
2015-03-21 11:37:08 +01:00
if treeWidget :
currentItem = treeWidget . currentItem ( )
2015-10-03 12:12:18 +02:00
if currentItem and hasattr ( currentItem , ' folderName ' ) :
return currentItem . folderName
2015-03-21 11:37:08 +01:00
else :
2015-11-01 11:08:41 +01:00
return None
2015-03-21 11:37:08 +01:00
def setCurrentItemColor ( self , color ) :
treeWidget = self . getCurrentTreeWidget ( )
if treeWidget :
brush = QtGui . QBrush ( )
brush . setStyle ( QtCore . Qt . NoBrush )
2015-03-23 22:35:56 +01:00
brush . setColor ( color )
2015-03-21 11:37:08 +01:00
currentItem = treeWidget . currentItem ( )
currentItem . setForeground ( 0 , brush )
2013-05-02 17:53:54 +02:00
def on_action_YourIdentitiesNew ( self ) :
self . click_NewAddressDialog ( )
2013-06-12 23:12:32 +02:00
2015-11-09 18:22:38 +01:00
def on_action_YourIdentitiesDelete ( self ) :
account = self . getCurrentItem ( )
if account . type == " normal " :
return # maybe in the future
elif account . type == " chan " :
if QtGui . QMessageBox . question ( self , " Delete channel? " , _translate ( " MainWindow " , " If you delete the channel, messages that you already received will become inaccessible. Maybe you can consider disabling the channel instead. Disabled channels will not receive new messages, but you can still view messages you already received. \n \n Are you sure you want to delete the channel? " ) , QMessageBox . Yes | QMessageBox . No ) == QMessageBox . Yes :
shared . config . remove_section ( str ( account . address ) )
else :
return
else :
return
shared . writeKeysFile ( )
shared . reloadMyAddressHashes ( )
if account . type == " normal " :
self . rerenderTabTreeMessages ( )
elif account . type == " chan " :
self . rerenderTabTreeChans ( )
2015-03-21 11:37:08 +01:00
def on_action_Enable ( self ) :
addressAtCurrentRow = self . getCurrentAccount ( )
self . enableIdentity ( addressAtCurrentRow )
2015-10-27 19:24:29 +01:00
account = self . getCurrentItem ( )
account . setEnabled ( True )
2015-03-21 11:37:08 +01:00
def enableIdentity ( self , address ) :
shared . config . set ( address , ' enabled ' , ' true ' )
shared . writeKeysFile ( )
2013-05-02 17:53:54 +02:00
shared . reloadMyAddressHashes ( )
2013-06-12 23:12:32 +02:00
2015-03-21 11:37:08 +01:00
def on_action_Disable ( self ) :
address = self . getCurrentAccount ( )
self . disableIdentity ( address )
2015-10-27 19:24:29 +01:00
account = self . getCurrentItem ( )
account . setEnabled ( False )
2015-03-21 11:37:08 +01:00
def disableIdentity ( self , address ) :
2015-03-23 22:35:56 +01:00
shared . config . set ( str ( address ) , ' enabled ' , ' false ' )
2014-09-15 08:34:33 +02:00
shared . writeKeysFile ( )
2013-05-02 17:53:54 +02:00
shared . reloadMyAddressHashes ( )
2013-06-12 23:12:32 +02:00
2015-03-21 11:37:08 +01:00
def on_action_Clipboard ( self ) :
2015-03-23 22:35:56 +01:00
address = self . getCurrentAccount ( )
2013-05-02 17:53:54 +02:00
clipboard = QtGui . QApplication . clipboard ( )
2015-03-23 22:35:56 +01:00
clipboard . setText ( str ( address ) )
2015-03-21 11:37:08 +01:00
#set avatar functions
def on_action_TreeWidgetSetAvatar ( self ) :
2015-03-23 22:35:56 +01:00
address = self . getCurrentAccount ( )
self . setAvatar ( address )
2013-06-12 23:12:32 +02:00
2013-09-21 09:41:23 +02:00
def on_action_AddressBookSetAvatar ( self ) :
self . on_action_SetAvatar ( self . ui . tableWidgetAddressBook )
def on_action_BlacklistSetAvatar ( self ) :
self . on_action_SetAvatar ( self . ui . tableWidgetBlacklist )
2015-03-21 11:37:08 +01:00
2013-09-21 09:41:23 +02:00
def on_action_SetAvatar ( self , thisTableWidget ) :
currentRow = thisTableWidget . currentRow ( )
addressAtCurrentRow = thisTableWidget . item (
2013-09-20 14:30:53 +02:00
currentRow , 1 ) . text ( )
2015-03-21 11:37:08 +01:00
setToIdenticon = not self . setAvatar ( addressAtCurrentRow )
if setToIdenticon :
thisTableWidget . item (
currentRow , 0 ) . setIcon ( avatarize ( addressAtCurrentRow ) )
def setAvatar ( self , addressAtCurrentRow ) :
if not os . path . exists ( shared . appdata + ' avatars/ ' ) :
os . makedirs ( shared . appdata + ' avatars/ ' )
2013-09-20 14:30:53 +02:00
hash = hashlib . md5 ( addBMIfNotPresent ( addressAtCurrentRow ) ) . hexdigest ( )
extensions = [ ' PNG ' , ' GIF ' , ' JPG ' , ' JPEG ' , ' SVG ' , ' BMP ' , ' MNG ' , ' PBM ' , ' PGM ' , ' PPM ' , ' TIFF ' , ' XBM ' , ' XPM ' , ' TGA ' ]
# http://pyqt.sourceforge.net/Docs/PyQt4/qimagereader.html#supportedImageFormats
names = { ' BMP ' : ' Windows Bitmap ' , ' GIF ' : ' Graphic Interchange Format ' , ' JPG ' : ' Joint Photographic Experts Group ' , ' JPEG ' : ' Joint Photographic Experts Group ' , ' MNG ' : ' Multiple-image Network Graphics ' , ' PNG ' : ' Portable Network Graphics ' , ' PBM ' : ' Portable Bitmap ' , ' PGM ' : ' Portable Graymap ' , ' PPM ' : ' Portable Pixmap ' , ' TIFF ' : ' Tagged Image File Format ' , ' XBM ' : ' X11 Bitmap ' , ' XPM ' : ' X11 Pixmap ' , ' SVG ' : ' Scalable Vector Graphics ' , ' TGA ' : ' Targa Image Format ' }
filters = [ ]
all_images_filter = [ ]
2013-09-21 09:41:23 +02:00
current_files = [ ]
2013-09-20 14:30:53 +02:00
for ext in extensions :
filters + = [ names [ ext ] + ' (*. ' + ext . lower ( ) + ' ) ' ]
all_images_filter + = [ ' *. ' + ext . lower ( ) ]
2013-09-21 09:41:23 +02:00
upper = shared . appdata + ' avatars/ ' + hash + ' . ' + ext . upper ( )
lower = shared . appdata + ' avatars/ ' + hash + ' . ' + ext . lower ( )
if os . path . isfile ( lower ) :
current_files + = [ lower ]
elif os . path . isfile ( upper ) :
current_files + = [ upper ]
2013-09-20 14:30:53 +02:00
filters [ 0 : 0 ] = [ ' Image files ( ' + ' ' . join ( all_images_filter ) + ' ) ' ]
filters [ 1 : 1 ] = [ ' All files (*.*) ' ]
sourcefile = QFileDialog . getOpenFileName ( self , _translate ( " MainWindow " , " Set avatar... " ) , filter = ' ;; ' . join ( filters ) )
# determine the correct filename (note that avatars don't use the suffix)
destination = shared . appdata + ' avatars/ ' + hash + ' . ' + sourcefile . split ( ' . ' ) [ - 1 ]
exists = QtCore . QFile . exists ( destination )
2013-09-21 09:41:23 +02:00
if sourcefile == ' ' :
# ask for removal of avatar
if exists | ( len ( current_files ) > 0 ) :
displayMsg = _translate ( " MainWindow " , " Do you really want to remove this avatar? " )
overwrite = QtGui . QMessageBox . question (
self , ' Message ' , displayMsg , QtGui . QMessageBox . Yes , QtGui . QMessageBox . No )
else :
overwrite = QtGui . QMessageBox . No
else :
# ask whether to overwrite old avatar
if exists | ( len ( current_files ) > 0 ) :
displayMsg = _translate ( " MainWindow " , " You have already set an avatar for this address. Do you really want to overwrite it? " )
overwrite = QtGui . QMessageBox . question (
self , ' Message ' , displayMsg , QtGui . QMessageBox . Yes , QtGui . QMessageBox . No )
else :
overwrite = QtGui . QMessageBox . No
# copy the image file to the appdata folder
2013-09-20 14:30:53 +02:00
if ( not exists ) | ( overwrite == QtGui . QMessageBox . Yes ) :
if overwrite == QtGui . QMessageBox . Yes :
2013-09-21 09:41:23 +02:00
for file in current_files :
QtCore . QFile . remove ( file )
2013-09-20 14:30:53 +02:00
QtCore . QFile . remove ( destination )
2013-09-21 09:41:23 +02:00
# copy it
if sourcefile != ' ' :
copied = QtCore . QFile . copy ( sourcefile , destination )
if not copied :
2015-11-18 16:22:17 +01:00
logger . error ( ' couldn \' t copy :( ' )
2013-09-20 14:30:53 +02:00
# set the icon
2015-03-23 22:35:56 +01:00
self . rerenderTabTreeMessages ( )
self . rerenderTabTreeSubscriptions ( )
self . rerenderTabTreeChans ( )
2013-09-21 09:41:23 +02:00
self . rerenderComboBoxSendFrom ( )
2015-03-21 11:37:08 +01:00
self . rerenderComboBoxSendFromBroadcast ( )
2013-09-21 09:41:23 +02:00
self . rerenderInboxFromLabels ( )
self . rerenderInboxToLabels ( )
self . rerenderSentFromLabels ( )
self . rerenderSentToLabels ( )
2014-11-22 22:56:41 +01:00
self . rerenderBlackWhiteList ( )
2015-03-21 11:37:08 +01:00
# generate identicon
return False
return True
2013-09-20 14:30:53 +02:00
2013-05-02 17:53:54 +02:00
def on_context_menuYourIdentities ( self , point ) :
2015-11-01 08:46:27 +01:00
self . popMenuYourIdentities = QtGui . QMenu ( self )
self . popMenuYourIdentities . addAction ( self . actionNewYourIdentities )
self . popMenuYourIdentities . addSeparator ( )
self . popMenuYourIdentities . addAction ( self . actionClipboardYourIdentities )
self . popMenuYourIdentities . addSeparator ( )
if self . getCurrentItem ( ) . isEnabled :
self . popMenuYourIdentities . addAction ( self . actionDisableYourIdentities )
else :
self . popMenuYourIdentities . addAction ( self . actionEnableYourIdentities )
self . popMenuYourIdentities . addAction ( self . actionSetAvatarYourIdentities )
self . popMenuYourIdentities . addAction ( self . actionSpecialAddressBehaviorYourIdentities )
self . popMenuYourIdentities . addAction ( self . actionEmailGateway )
2015-03-21 11:37:08 +01:00
self . popMenuYourIdentities . exec_ (
self . ui . treeWidgetYourIdentities . mapToGlobal ( point ) )
2015-03-23 22:35:56 +01:00
# TODO make one popMenu
2015-03-21 11:37:08 +01:00
def on_context_menuChan ( self , point ) :
2015-11-01 08:46:27 +01:00
self . popMenu = QtGui . QMenu ( self )
self . popMenu . addAction ( self . actionNew )
2015-11-09 18:22:38 +01:00
self . popMenu . addAction ( self . actionDelete )
2015-11-01 08:46:27 +01:00
self . popMenu . addSeparator ( )
self . popMenu . addAction ( self . actionClipboard )
self . popMenu . addSeparator ( )
if self . getCurrentItem ( ) . isEnabled :
self . popMenu . addAction ( self . actionDisable )
else :
self . popMenu . addAction ( self . actionEnable )
self . popMenu . addAction ( self . actionSetAvatar )
2013-06-12 23:12:32 +02:00
self . popMenu . exec_ (
2015-03-23 22:35:56 +01:00
self . ui . treeWidgetChans . mapToGlobal ( point ) )
2013-06-12 23:12:32 +02:00
2013-05-02 17:53:54 +02:00
def on_context_menuInbox ( self , point ) :
2015-03-23 22:35:56 +01:00
tableWidget = self . getCurrentMessagelist ( )
if tableWidget :
currentFolder = self . getCurrentFolder ( )
2015-11-01 11:08:41 +01:00
if currentFolder is None :
2015-03-23 22:35:56 +01:00
pass
if currentFolder == ' sent ' :
self . on_context_menuSent ( point )
else :
2015-11-01 10:56:37 +01:00
self . popMenuInbox = QtGui . QMenu ( self )
self . popMenuInbox . addAction ( self . actionForceHtml )
self . popMenuInbox . addAction ( self . actionMarkUnread )
self . popMenuInbox . addSeparator ( )
self . popMenuInbox . addAction ( self . actionReply )
self . popMenuInbox . addAction ( self . actionAddSenderToAddressBook )
self . popMenuInbox . addSeparator ( )
2015-11-14 01:14:10 +01:00
self . popMenuInbox . addAction ( self . actionAddSenderToBlackList )
self . popMenuInbox . addSeparator ( )
2015-11-01 10:56:37 +01:00
self . popMenuInbox . addAction ( self . actionSaveMessageAs )
if currentFolder == " trash " :
self . popMenuInbox . addAction ( self . actionUndeleteTrashedMessage )
else :
self . popMenuInbox . addAction ( self . actionTrashInboxMessage )
2015-03-23 22:35:56 +01:00
self . popMenuInbox . exec_ ( tableWidget . mapToGlobal ( point ) )
2013-06-12 23:12:32 +02:00
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.
2015-03-03 18:17:56 +01:00
currentRow = self . ui . tableWidgetInbox . currentRow ( )
2015-03-23 22:35:56 +01:00
if currentRow > = 0 :
ackData = str ( self . ui . tableWidgetInbox . item (
currentRow , 3 ) . data ( Qt . UserRole ) . toPyObject ( ) )
queryreturn = sqlQuery ( ''' SELECT status FROM sent where ackdata=? ''' , ackData )
for row in queryreturn :
status , = row
if status == ' toodifficult ' :
self . popMenuSent . addAction ( self . actionForceSend )
2015-03-03 18:17:56 +01:00
self . popMenuSent . exec_ ( self . ui . tableWidgetInbox . mapToGlobal ( point ) )
2013-05-02 17:53:54 +02:00
2013-07-12 10:24:24 +02:00
def inboxSearchLineEditPressed ( self ) :
2015-03-23 22:35:56 +01:00
searchLine = self . getCurrentSearchLine ( )
searchOption = self . getCurrentSearchOption ( )
if searchLine :
searchKeyword = searchLine . text ( ) . toUtf8 ( ) . data ( )
searchLine . setText ( QString ( " " ) )
messageTextedit = self . getCurrentMessageTextedit ( )
if messageTextedit :
messageTextedit . setPlainText ( QString ( " " ) )
messagelist = self . getCurrentMessagelist ( )
if messagelist :
account = self . getCurrentAccount ( )
folder = self . getCurrentFolder ( )
self . loadMessagelist ( messagelist , account , folder , searchOption , searchKeyword )
def treeWidgetItemClicked ( self ) :
messagelist = self . getCurrentMessagelist ( )
if messagelist :
account = self . getCurrentAccount ( )
folder = self . getCurrentFolder ( )
self . loadMessagelist ( messagelist , account , folder )
2013-05-02 17:53:54 +02:00
2015-10-04 10:47:51 +02:00
def treeWidgetItemChanged ( self , item , column ) :
2015-10-04 10:57:14 +02:00
# only for manual edits. automatic edits (setText) are ignored
if column != 0 :
return
2015-10-05 10:32:56 +02:00
# only account names of normal addresses (no chans/mailinglists)
2015-10-27 19:50:52 +01:00
if ( not isinstance ( item , Ui_AddressWidget ) ) or ( not self . getCurrentTreeWidget ( ) ) or self . getCurrentTreeWidget ( ) . currentItem ( ) is None :
2015-10-05 17:07:23 +02:00
return
# not visible
2015-10-19 17:22:37 +02:00
if ( not self . getCurrentItem ( ) ) or ( not isinstance ( self . getCurrentItem ( ) , Ui_AddressWidget ) ) :
2015-10-04 10:57:14 +02:00
return
# only currently selected item
2015-10-19 17:22:37 +02:00
if item . address != self . getCurrentAccount ( ) :
2015-10-04 10:57:14 +02:00
return
newLabel = str ( item . text ( 0 ) )
newLabel = newLabel . replace ( " ( " + str ( item . address ) + " ) " , ' ' )
newLabel = newLabel . rstrip ( )
2015-10-27 19:50:52 +01:00
if item . type == " subscription " :
oldLabel = item . label
else :
oldLabel = shared . config . get ( str ( item . address ) , ' label ' )
2015-10-04 10:57:14 +02:00
oldLabel = oldLabel . replace ( " ( " + str ( item . address ) + " ) " , ' ' )
oldLabel = oldLabel . rstrip ( )
# unchanged, do not do anything either
if newLabel == oldLabel :
return
2015-10-04 20:32:17 +02:00
# recursion prevention
if self . recurDepth > 0 :
return
self . recurDepth + = 1
2015-10-27 19:50:52 +01:00
if item . type == " subscription " :
sqlExecute (
''' UPDATE subscriptions SET label=? WHERE address=? ''' ,
newLabel , item . address )
item . setLabel ( newLabel )
else :
shared . config . set ( str ( item . address ) , ' label ' , newLabel )
shared . writeKeysFile ( )
2015-10-04 10:57:14 +02:00
item . updateText ( )
2015-10-19 20:17:28 +02:00
if item . type == ' mailinglist ' :
self . rerenderComboBoxSendFromBroadcast ( )
2015-10-27 19:50:52 +01:00
elif item . type != " subscription " :
2015-10-19 20:17:28 +02:00
self . rerenderComboBoxSendFrom ( )
2015-10-04 20:32:17 +02:00
self . recurDepth - = 1
2015-10-04 10:47:51 +02:00
2015-03-03 18:17:56 +01:00
def tableWidgetInboxItemClicked ( self ) :
2015-03-23 22:35:56 +01:00
folder = self . getCurrentFolder ( )
messageTextedit = self . getCurrentMessageTextedit ( )
2015-11-12 01:43:06 +01:00
if not messageTextedit :
return
2015-03-23 22:35:56 +01:00
queryreturn = [ ]
message = " "
if folder == ' sent ' :
ackdata = self . getCurrentMessageId ( )
if ackdata and messageTextedit :
queryreturn = sqlQuery (
2015-09-30 10:22:41 +02:00
''' select message, 1 from sent where ackdata=? ''' , ackdata )
2015-03-23 22:35:56 +01:00
else :
msgid = self . getCurrentMessageId ( )
if msgid and messageTextedit :
queryreturn = sqlQuery (
2015-09-30 10:22:41 +02:00
''' select message, read from inbox where msgid=? ''' , msgid )
2015-03-23 22:35:56 +01:00
if queryreturn != [ ] :
2015-09-30 10:22:41 +02:00
refresh = False
2015-03-23 22:35:56 +01:00
for row in queryreturn :
2015-09-30 10:22:41 +02:00
message , read = row
2015-10-03 12:12:18 +02:00
if folder != ' sent ' and read == 0 :
2015-09-30 10:22:41 +02:00
markread = sqlQuery (
''' UPDATE inbox SET read = 1 WHERE msgid = ? ''' , msgid )
refresh = True
if refresh :
tableWidget = self . getCurrentMessagelist ( )
if not tableWidget :
return
font = QFont ( )
font . setBold ( False )
# inventoryHashesToMarkRead = []
2015-11-01 08:30:06 +01:00
currentRow = tableWidget . currentRow ( )
2015-09-30 10:22:41 +02:00
# inventoryHashToMarkRead = str(tableWidget.item(
# currentRow, 3).data(Qt.UserRole).toPyObject())
# inventoryHashesToMarkRead.append(inventoryHashToMarkRead)
tableWidget . item ( currentRow , 0 ) . setFont ( font )
2015-11-01 08:30:06 +01:00
tableWidget . item ( currentRow , 0 ) . setTextColor ( AccountColor ( str ( tableWidget . item ( currentRow , 0 ) . data ( Qt . UserRole ) . toPyObject ( ) ) ) . accountColor ( ) )
2015-09-30 10:22:41 +02:00
tableWidget . item ( currentRow , 1 ) . setFont ( font )
2015-11-01 08:30:06 +01:00
tableWidget . item ( currentRow , 1 ) . setTextColor ( AccountColor ( str ( tableWidget . item ( currentRow , 1 ) . data ( Qt . UserRole ) . toPyObject ( ) ) ) . accountColor ( ) )
2015-09-30 10:22:41 +02:00
tableWidget . item ( currentRow , 2 ) . setFont ( font )
tableWidget . item ( currentRow , 3 ) . setFont ( font )
2015-10-31 15:27:07 +01:00
self . propagateUnreadCount ( self . getCurrentAccount ( ) , folder , self . getCurrentTreeWidget ( ) , - 1 )
2015-10-02 22:24:46 +02:00
2015-03-23 22:35:56 +01:00
else :
data = self . getCurrentMessageId ( )
if data != False :
2013-10-13 19:45:30 +02:00
message = " Error occurred: could not load message from disk. "
2015-03-23 22:35:56 +01:00
message = unicode ( message , ' utf-8) ' )
2015-11-11 00:51:55 +01:00
messageTextedit . setCurrentFont ( QtGui . QFont ( ) )
messageTextedit . setTextColor ( QtGui . QColor ( ) )
2015-03-23 22:35:56 +01:00
messageTextedit . setPlainText ( message )
2013-05-02 17:53:54 +02:00
def tableWidgetAddressBookItemChanged ( self ) :
currentRow = self . ui . tableWidgetAddressBook . currentRow ( )
if currentRow > = 0 :
2013-06-12 23:12:32 +02:00
addressAtCurrentRow = self . ui . tableWidgetAddressBook . item (
currentRow , 1 ) . text ( )
2013-08-27 02:01:19 +02:00
sqlExecute ( ''' UPDATE addressbook set label=? WHERE address=? ''' ,
str ( self . ui . tableWidgetAddressBook . item ( currentRow , 0 ) . text ( ) . toUtf8 ( ) ) ,
str ( addressAtCurrentRow ) )
2015-11-13 14:31:22 +01:00
self . ui . tableWidgetAddressBook . item ( currentRow , 0 ) . setLabel ( str ( self . ui . tableWidgetAddressBook . item ( currentRow , 0 ) . text ( ) . toUtf8 ( ) ) )
2013-05-02 17:53:54 +02:00
self . rerenderInboxFromLabels ( )
self . rerenderSentToLabels ( )
2013-06-12 23:12:32 +02:00
def writeNewAddressToTable ( self , label , address , streamNumber ) :
2015-03-23 22:35:56 +01:00
self . rerenderTabTreeMessages ( )
self . rerenderTabTreeSubscriptions ( )
self . rerenderTabTreeChans ( )
2013-05-02 17:53:54 +02:00
self . rerenderComboBoxSendFrom ( )
2015-03-21 11:37:08 +01:00
self . rerenderComboBoxSendFromBroadcast ( )
2013-05-02 17:53:54 +02:00
2013-06-12 23:12:32 +02:00
def updateStatusBar ( self , data ) :
2013-05-02 17:53:54 +02:00
if data != " " :
2015-11-18 16:22:17 +01:00
logger . info ( ' Status bar: ' + data )
2013-06-29 19:29:35 +02:00
2013-05-02 17:53:54 +02:00
self . statusBar ( ) . showMessage ( data )
2015-11-08 21:44:02 +01:00
def initSettings ( self ) :
QtCore . QCoreApplication . setOrganizationName ( " PyBitmessage " )
QtCore . QCoreApplication . setOrganizationDomain ( " bitmessage.org " )
QtCore . QCoreApplication . setApplicationName ( " pybitmessageqt " )
self . loadSettings ( )
for attr , obj in self . ui . __dict__ . iteritems ( ) :
if hasattr ( obj , " __class__ " ) and isinstance ( obj , settingsmixin . SettingsMixin ) :
loadMethod = getattr ( obj , " loadSettings " , None )
if callable ( loadMethod ) :
obj . loadSettings ( )
2013-05-02 17:53:54 +02:00
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-07-24 17:46:28 +02:00
class connectDialog ( QtGui . QDialog ) :
2013-06-12 23:12:32 +02:00
2013-07-24 17:46:28 +02:00
def __init__ ( self , parent ) :
QtGui . QWidget . __init__ ( self , parent )
self . ui = Ui_connectDialog ( )
self . ui . setupUi ( self )
self . parent = parent
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-08-08 21:37:48 +02:00
self . ui . checkBoxWillinglySendToMobile . setChecked (
shared . safeConfigGetBoolean ( ' bitmessagesettings ' , ' willinglysendtomobile ' ) )
2013-11-02 00:25:24 +01:00
self . ui . checkBoxUseIdenticons . setChecked (
shared . safeConfigGetBoolean ( ' bitmessagesettings ' , ' useidenticons ' ) )
2014-01-28 20:57:01 +01:00
self . ui . checkBoxReplyBelow . setChecked (
shared . safeConfigGetBoolean ( ' bitmessagesettings ' , ' replybelow ' ) )
2013-08-24 09:07:46 +02:00
global languages
2014-12-26 05:24:09 +01:00
languages = [ ' system ' , ' en ' , ' eo ' , ' fr ' , ' de ' , ' es ' , ' ru ' , ' no ' , ' ar ' , ' zh_cn ' , ' ja ' , ' nl ' , ' cs ' , ' en_pirate ' , ' other ' ]
2013-08-24 09:07:46 +02:00
user_countrycode = str ( shared . config . get ( ' bitmessagesettings ' , ' userlocale ' ) )
2013-08-24 09:21:59 +02:00
if user_countrycode in languages :
curr_index = languages . index ( user_countrycode )
else :
curr_index = languages . index ( ' other ' )
self . ui . languageComboBox . setCurrentIndex ( curr_index )
2013-08-24 09:07:46 +02:00
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 )
2013-11-02 05:19:54 +01:00
self . ui . checkBoxStartOnLogon . setText ( _translate (
" MainWindow " , " Start-on-login not yet supported on your OS. " ) )
2013-05-02 17:53:54 +02:00
self . ui . checkBoxMinimizeToTray . setDisabled ( True )
2013-11-02 05:19:54 +01:00
self . ui . checkBoxMinimizeToTray . setText ( _translate (
" MainWindow " , " Minimize-to-tray not yet supported on your OS. " ) )
2013-05-02 17:53:54 +02:00
self . ui . checkBoxShowTrayNotifications . setDisabled ( True )
2013-11-02 05:19:54 +01:00
self . ui . checkBoxShowTrayNotifications . setText ( _translate (
" MainWindow " , " Tray notifications not yet supported on your OS. " ) )
2013-05-02 17:53:54 +02:00
elif ' linux ' in sys . platform :
self . ui . checkBoxStartOnLogon . setDisabled ( True )
2013-11-02 05:19:54 +01:00
self . ui . checkBoxStartOnLogon . setText ( _translate (
" MainWindow " , " Start-on-login not yet supported on your OS. " ) )
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-07-16 01:36:37 +02:00
self . ui . checkBoxSocksListen . setChecked ( shared . config . getboolean (
2013-07-12 20:03:09 +02:00
' bitmessagesettings ' , ' sockslisten ' ) )
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 )
2013-07-12 20:03:09 +02:00
self . ui . checkBoxSocksListen . setEnabled ( False )
2013-05-02 17:53:54 +02:00
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 )
2014-09-10 22:47:51 +02:00
self . ui . lineEditMaxDownloadRate . setText ( str (
shared . config . get ( ' bitmessagesettings ' , ' maxdownloadrate ' ) ) )
self . ui . lineEditMaxUploadRate . setText ( str (
shared . config . get ( ' bitmessagesettings ' , ' maxuploadrate ' ) ) )
2013-06-12 23:12:32 +02:00
2014-09-10 22:47:51 +02:00
# Demanded difficulty tab
2013-06-12 23:12:32 +02:00
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
2013-07-07 20:04:57 +02:00
nmctype = shared . config . get ( ' bitmessagesettings ' , ' namecoinrpctype ' )
2013-07-07 17:34:43 +02:00
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-07-07 20:04:57 +02:00
if nmctype == " namecoind " :
self . ui . radioButtonNamecoinNamecoind . setChecked ( True )
elif nmctype == " nmcontrol " :
self . ui . radioButtonNamecoinNmcontrol . setChecked ( True )
self . ui . lineEditNamecoinUser . setEnabled ( False )
self . ui . labelNamecoinUser . setEnabled ( False )
self . ui . lineEditNamecoinPassword . setEnabled ( False )
self . ui . labelNamecoinPassword . setEnabled ( False )
else :
assert False
QtCore . QObject . connect ( self . ui . radioButtonNamecoinNamecoind , QtCore . SIGNAL (
" toggled(bool) " ) , self . namecoinTypeChanged )
QtCore . QObject . connect ( self . ui . radioButtonNamecoinNmcontrol , QtCore . SIGNAL (
" toggled(bool) " ) , self . namecoinTypeChanged )
2013-07-07 18:41:13 +02:00
QtCore . QObject . connect ( self . ui . pushButtonNamecoinTest , QtCore . SIGNAL (
" clicked() " ) , self . click_pushButtonNamecoinTest )
2013-07-07 17:34:43 +02:00
2013-11-04 08:05:07 +01:00
#Message Resend tab
2013-09-28 02:47:16 +02:00
self . ui . lineEditDays . setText ( str (
2013-11-04 08:05:07 +01:00
shared . config . get ( ' bitmessagesettings ' , ' stopresendingafterxdays ' ) ) )
2013-09-28 02:47:16 +02:00
self . ui . lineEditMonths . setText ( str (
2013-11-04 08:05:07 +01:00
shared . config . get ( ' bitmessagesettings ' , ' stopresendingafterxmonths ' ) ) )
2013-09-28 02:47:16 +02:00
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 )
2013-07-12 20:03:09 +02:00
self . ui . checkBoxSocksListen . setEnabled ( False )
2013-05-02 17:53:54 +02:00
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 )
2013-07-12 20:03:09 +02:00
self . ui . checkBoxSocksListen . setEnabled ( True )
2013-05-02 17:53:54 +02:00
if self . ui . checkBoxAuthentication . isChecked ( ) :
self . ui . lineEditSocksUsername . setEnabled ( True )
self . ui . lineEditSocksPassword . setEnabled ( True )
self . ui . lineEditTCPPort . setEnabled ( False )
2013-07-07 20:04:57 +02:00
# Check status of namecoin integration radio buttons and translate
# it to a string as in the options.
def getNamecoinType ( self ) :
if self . ui . radioButtonNamecoinNamecoind . isChecked ( ) :
return " namecoind "
if self . ui . radioButtonNamecoinNmcontrol . isChecked ( ) :
return " nmcontrol "
assert False
# Namecoin connection type was changed.
def namecoinTypeChanged ( self , checked ) :
nmctype = self . getNamecoinType ( )
assert nmctype == " namecoind " or nmctype == " nmcontrol "
isNamecoind = ( nmctype == " namecoind " )
self . ui . lineEditNamecoinUser . setEnabled ( isNamecoind )
self . ui . labelNamecoinUser . setEnabled ( isNamecoind )
self . ui . lineEditNamecoinPassword . setEnabled ( isNamecoind )
self . ui . labelNamecoinPassword . setEnabled ( isNamecoind )
if isNamecoind :
2013-07-17 18:33:26 +02:00
self . ui . lineEditNamecoinPort . setText ( shared . namecoinDefaultRpcPort )
2013-07-07 20:04:57 +02:00
else :
self . ui . lineEditNamecoinPort . setText ( " 9000 " )
2013-07-07 18:41:13 +02:00
# Test the namecoin settings specified in the settings dialog.
def click_pushButtonNamecoinTest ( self ) :
2013-08-15 00:59:50 +02:00
self . ui . labelNamecoinTestResult . setText ( _translate (
" MainWindow " , " Testing... " ) )
2013-07-07 18:41:13 +02:00
options = { }
2013-07-07 20:04:57 +02:00
options [ " type " ] = self . getNamecoinType ( )
2013-07-07 18:41:13 +02:00
options [ " host " ] = self . ui . lineEditNamecoinHost . text ( )
options [ " port " ] = self . ui . lineEditNamecoinPort . text ( )
options [ " user " ] = self . ui . lineEditNamecoinUser . text ( )
options [ " password " ] = self . ui . lineEditNamecoinPassword . text ( )
nc = namecoinConnection ( options )
2013-08-15 01:46:59 +02:00
response = nc . test ( )
responseStatus = response [ 0 ]
responseText = response [ 1 ]
self . ui . labelNamecoinTestResult . setText ( responseText )
2015-03-21 11:37:08 +01:00
if responseStatus == ' success ' :
self . parent . ui . pushButtonFetchNamecoinID . show ( )
2013-07-07 18:41:13 +02:00
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
2015-03-21 11:37:08 +01:00
addressAtCurrentRow = parent . getCurrentAccount ( )
if not shared . safeConfigGetBoolean ( addressAtCurrentRow , ' chan ' ) :
if shared . safeConfigGetBoolean ( addressAtCurrentRow , ' mailinglist ' ) :
self . ui . radioButtonBehaviorMailingList . click ( )
else :
self . ui . radioButtonBehaveNormalAddress . click ( )
try :
mailingListName = shared . config . get (
addressAtCurrentRow , ' mailinglistname ' )
except :
mailingListName = ' '
self . ui . lineEditMailingListName . setText (
unicode ( mailingListName , ' utf-8 ' ) )
else : # if addressAtCurrentRow is a chan address
self . ui . radioButtonBehaviorMailingList . setDisabled ( True )
self . ui . lineEditMailingListName . setText ( _translate (
" MainWindow " , " This is a chan address. You cannot use it as a pseudo-mailing list. " ) )
QtGui . QWidget . resize ( self , QtGui . QWidget . sizeHint ( self ) )
2015-10-03 17:24:21 +02:00
class EmailGatewayDialog ( QtGui . QDialog ) :
def __init__ ( self , parent ) :
QtGui . QWidget . __init__ ( self , parent )
self . ui = Ui_EmailGatewayDialog ( )
self . ui . setupUi ( self )
self . parent = parent
addressAtCurrentRow = parent . getCurrentAccount ( )
acct = accountClass ( addressAtCurrentRow )
2015-11-10 13:15:07 +01:00
if isinstance ( acct , GatewayAccount ) :
self . ui . radioButtonUnregister . setEnabled ( True )
else :
self . ui . radioButtonUnregister . setEnabled ( False )
2015-10-03 17:24:21 +02:00
label = shared . config . get ( addressAtCurrentRow , ' label ' )
if label . find ( " @mailchuck.com " ) > - 1 :
self . ui . lineEditEmail . setText ( label )
QtGui . QWidget . resize ( self , QtGui . QWidget . sizeHint ( self ) )
2013-12-01 05:15:18 +01:00
class AddAddressDialog ( QtGui . QDialog ) :
def __init__ ( self , parent ) :
QtGui . QWidget . __init__ ( self , parent )
self . ui = Ui_AddAddressDialog ( )
self . ui . setupUi ( self )
self . parent = parent
QtCore . QObject . connect ( self . ui . lineEditAddress , QtCore . SIGNAL (
" textChanged(QString) " ) , self . addressChanged )
def addressChanged ( self , QString ) :
status , a , b , c = decodeAddress ( str ( QString ) )
if status == ' missingbm ' :
self . ui . labelAddressCheck . setText ( _translate (
" MainWindow " , " The address should start with ' ' BM- ' ' " ) )
elif status == ' checksumfailed ' :
self . ui . labelAddressCheck . setText ( _translate (
" MainWindow " , " The address is not typed or copied correctly (the checksum failed). " ) )
elif status == ' versiontoohigh ' :
self . ui . labelAddressCheck . setText ( _translate (
" MainWindow " , " The version number of this address is higher than this software can support. Please upgrade Bitmessage. " ) )
elif status == ' invalidcharacters ' :
self . ui . labelAddressCheck . setText ( _translate (
" MainWindow " , " The address contains invalid characters. " ) )
elif status == ' ripetooshort ' :
self . ui . labelAddressCheck . setText ( _translate (
" MainWindow " , " Some data encoded in the address is too short. " ) )
elif status == ' ripetoolong ' :
self . ui . labelAddressCheck . setText ( _translate (
" MainWindow " , " Some data encoded in the address is too long. " ) )
2014-08-27 09:14:32 +02:00
elif status == ' varintmalformed ' :
self . ui . labelAddressCheck . setText ( _translate (
" MainWindow " , " Some data encoded in the address is malformed. " ) )
2013-12-01 05:15:18 +01:00
elif status == ' success ' :
self . ui . labelAddressCheck . setText (
_translate ( " MainWindow " , " Address is valid. " ) )
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 (
2013-12-01 05:15:18 +01:00
" textChanged(QString) " ) , self . addressChanged )
self . ui . checkBoxDisplayMessagesAlreadyInInventory . setText (
_translate ( " MainWindow " , " Enter an address above. " ) )
def addressChanged ( self , QString ) :
self . ui . checkBoxDisplayMessagesAlreadyInInventory . setEnabled ( False )
self . ui . checkBoxDisplayMessagesAlreadyInInventory . setChecked ( False )
status , addressVersion , streamNumber , ripe = decodeAddress ( str ( QString ) )
2013-05-02 17:53:54 +02:00
if status == ' missingbm ' :
2013-12-01 05:15:18 +01:00
self . ui . labelAddressCheck . 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-12-01 05:15:18 +01:00
self . ui . labelAddressCheck . 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-12-01 05:15:18 +01:00
self . ui . labelAddressCheck . 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-12-01 05:15:18 +01:00
self . ui . labelAddressCheck . 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-12-01 05:15:18 +01:00
self . ui . labelAddressCheck . 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-12-01 05:15:18 +01:00
self . ui . labelAddressCheck . setText ( _translate (
2013-06-12 23:12:32 +02:00
" MainWindow " , " Some data encoded in the address is too long. " ) )
2014-08-27 09:14:32 +02:00
elif status == ' varintmalformed ' :
self . ui . labelAddressCheck . setText ( _translate (
" MainWindow " , " Some data encoded in the address is malformed. " ) )
2013-05-02 17:53:54 +02:00
elif status == ' success ' :
2013-12-01 05:15:18 +01:00
self . ui . labelAddressCheck . setText (
2013-06-13 09:59:40 +02:00
_translate ( " MainWindow " , " Address is valid. " ) )
2013-12-01 05:15:18 +01:00
if addressVersion < = 3 :
self . ui . checkBoxDisplayMessagesAlreadyInInventory . setText (
_translate ( " MainWindow " , " Address is an old type. We cannot display its past broadcasts. " ) )
else :
shared . flushInventory ( )
doubleHashOfAddressData = hashlib . sha512 ( hashlib . sha512 ( encodeVarint (
addressVersion ) + encodeVarint ( streamNumber ) + ripe ) . digest ( ) ) . digest ( )
tag = doubleHashOfAddressData [ 32 : ]
queryreturn = sqlQuery (
2014-08-27 09:14:32 +02:00
''' select hash from inventory where objecttype=3 and tag=? ''' , tag )
2013-12-01 05:15:18 +01:00
if len ( queryreturn ) == 0 :
self . ui . checkBoxDisplayMessagesAlreadyInInventory . setText (
_translate ( " MainWindow " , " There are no recent broadcasts from this address to display. " ) )
elif len ( queryreturn ) == 1 :
self . ui . checkBoxDisplayMessagesAlreadyInInventory . setEnabled ( True )
self . ui . checkBoxDisplayMessagesAlreadyInInventory . setText (
_translate ( " MainWindow " , " Display the % 1 recent broadcast from this address. " ) . arg ( str ( len ( queryreturn ) ) ) )
else :
self . ui . checkBoxDisplayMessagesAlreadyInInventory . setEnabled ( True )
self . ui . checkBoxDisplayMessagesAlreadyInInventory . setText (
_translate ( " MainWindow " , " Display the % 1 recent broadcasts from this address. " ) . arg ( str ( len ( queryreturn ) ) ) )
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.
2015-10-19 20:03:06 +02:00
for addressInKeysFile in getSortedAccounts ( ) :
2013-05-02 17:53:54 +02:00
self . ui . radioButtonExisting . click ( )
2013-06-12 23:12:32 +02:00
self . ui . comboBoxExisting . addItem (
2015-03-23 22:35:56 +01:00
addressInKeysFile )
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-07-22 07:10:22 +02:00
class newChanDialog ( QtGui . QDialog ) :
2013-06-25 23:14:44 +02:00
def __init__ ( self , parent ) :
QtGui . QWidget . __init__ ( self , parent )
2013-07-22 07:10:22 +02:00
self . ui = Ui_newChanDialog ( )
2013-06-25 23:14:44 +02:00
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-08-26 01:31:54 +02:00
class UISignaler ( QThread ) :
2013-06-12 23:12:32 +02:00
def __init__ ( self , parent = None ) :
2013-05-02 17:53:54 +02:00
QThread . __init__ ( self , parent )
def run ( self ) :
while True :
2013-08-26 01:31:54 +02:00
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 )
2015-03-09 07:35:32 +01:00
elif command == ' updateSentItemStatusByToAddress ' :
toAddress , message = data
2013-08-26 01:31:54 +02:00
self . emit ( SIGNAL (
2015-03-09 07:35:32 +01:00
" updateSentItemStatusByToAddress(PyQt_PyObject,PyQt_PyObject) " ) , toAddress , message )
2013-08-26 01:31:54 +02:00
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 == ' updateNumberOfMessagesProcessed ' :
self . emit ( SIGNAL ( " updateNumberOfMessagesProcessed() " ) )
elif command == ' updateNumberOfPubkeysProcessed ' :
self . emit ( SIGNAL ( " updateNumberOfPubkeysProcessed() " ) )
elif command == ' updateNumberOfBroadcastsProcessed ' :
self . emit ( SIGNAL ( " updateNumberOfBroadcastsProcessed() " ) )
elif command == ' setStatusIcon ' :
self . emit ( SIGNAL ( " setStatusIcon(PyQt_PyObject) " ) , data )
2013-11-29 02:05:53 +01:00
elif command == ' changedInboxUnread ' :
self . emit ( SIGNAL ( " changedInboxUnread(PyQt_PyObject) " ) , data )
2013-08-26 01:31:54 +02:00
elif command == ' rerenderInboxFromLabels ' :
self . emit ( SIGNAL ( " rerenderInboxFromLabels() " ) )
2013-09-05 12:31:52 +02:00
elif command == ' rerenderSentToLabels ' :
self . emit ( SIGNAL ( " rerenderSentToLabels() " ) )
elif command == ' rerenderAddressBook ' :
self . emit ( SIGNAL ( " rerenderAddressBook() " ) )
2013-08-26 01:31:54 +02:00
elif command == ' rerenderSubscriptions ' :
self . emit ( SIGNAL ( " rerenderSubscriptions() " ) )
2014-11-22 22:56:41 +01:00
elif command == ' rerenderBlackWhiteList ' :
self . emit ( SIGNAL ( " rerenderBlackWhiteList() " ) )
2013-08-26 01:31:54 +02:00
elif command == ' removeInboxRowByMsgid ' :
self . emit ( SIGNAL ( " removeInboxRowByMsgid(PyQt_PyObject) " ) , data )
2015-10-19 22:33:18 +02:00
elif command == ' newVersionAvailable ' :
self . emit ( SIGNAL ( " newVersionAvailable(PyQt_PyObject) " ) , data )
2013-09-05 02:14:25 +02:00
elif command == ' alert ' :
title , text , exitAfterUserClicksOk = data
self . emit ( SIGNAL ( " displayAlert(PyQt_PyObject, PyQt_PyObject, PyQt_PyObject) " ) , title , text , exitAfterUserClicksOk )
2013-08-26 01:31:54 +02:00
else :
sys . stderr . write (
' Command sent to UISignaler not recognized: %s \n ' % command )
2013-05-02 17:53:54 +02:00
2015-11-15 00:12:19 +01:00
app = None
myapp = None
class MySingleApplication ( QApplication ) :
"""
Listener to allow our Qt form to get focus when another instance of the
application is open .
Based off this nice reimplmentation of MySingleApplication :
http : / / stackoverflow . com / a / 12712362 / 2679626
"""
# Unique identifier for this application
uuid = ' 6ec0149b-96e1-4be1-93ab-1465fb3ebf7c '
def __init__ ( self , * argv ) :
super ( MySingleApplication , self ) . __init__ ( * argv )
id = MySingleApplication . uuid
self . server = None
self . is_running = False
socket = QLocalSocket ( )
socket . connectToServer ( id )
self . is_running = socket . waitForConnected ( )
# Cleanup past crashed servers
if not self . is_running :
if socket . error ( ) == QLocalSocket . ConnectionRefusedError :
socket . disconnectFromServer ( )
QLocalServer . removeServer ( id )
socket . abort ( )
# Checks if there's an instance of the local server id running
if self . is_running :
# This should be ignored, singleton.py will take care of exiting me.
pass
else :
# Nope, create a local server with this id and assign on_new_connection
# for whenever a second instance tries to run focus the application.
self . server = QLocalServer ( )
self . server . listen ( id )
self . server . newConnection . connect ( self . on_new_connection )
def __del__ ( self ) :
if self . server :
self . server . close ( )
def on_new_connection ( self ) :
global myapp
if myapp :
myapp . appIndicatorShow ( )
def init ( ) :
global app
if not app :
app = MySingleApplication ( sys . argv )
return app
2013-05-02 17:53:54 +02:00
def run ( ) :
2015-11-15 00:12:19 +01:00
global myapp
app = init ( )
2014-11-14 12:21:18 +01:00
change_translation ( l10n . getTranslationLanguage ( ) )
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-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-07-24 17:46:28 +02:00
if shared . safeConfigGetBoolean ( ' bitmessagesettings ' , ' dontconnect ' ) :
myapp . showConnectDialog ( ) # ask the user if we may connect
2015-10-02 15:05:47 +02:00
2015-10-03 17:24:21 +02:00
# try:
# if shared.config.get('bitmessagesettings', 'mailchuck') < 1:
# myapp.showMigrationWizard(shared.config.get('bitmessagesettings', 'mailchuck'))
# except:
# myapp.showMigrationWizard(0)
2015-10-02 15:05:47 +02:00
# only show after wizards and connect dialogs have completed
if not shared . config . getboolean ( ' bitmessagesettings ' , ' startintray ' ) :
myapp . show ( )
2013-08-26 01:31:54 +02:00
sys . exit ( app . exec_ ( ) )