- AddToAddressBook

- Use proper label for "Subscribe to this address"
This commit is contained in:
sendiulo 2013-09-09 16:16:28 +02:00
parent 80242a9fa1
commit 4f7fbec5bf

View File

@ -188,7 +188,7 @@ class MyForm(QtGui.QMainWindow):
self.actionInboxSenderSubscribe = self.ui.inboxContextMenuToolbar.addAction(_translate( self.actionInboxSenderSubscribe = self.ui.inboxContextMenuToolbar.addAction(_translate(
"MainWindow", "Subscribe to this address"), self.on_action_InboxSenderSubscribe) "MainWindow", "Subscribe to this address"), self.on_action_InboxSenderSubscribe)
self.actionAddSenderToAddressBook = self.ui.inboxContextMenuToolbar.addAction(_translate( self.actionAddSenderToAddressBook = self.ui.inboxContextMenuToolbar.addAction(_translate(
"MainWindow", "Add address to Address Book"), self.on_action_InboxAddSenderToAddressBook) "MainWindow", "Add to Address Book"), self.on_action_InboxAddSenderToAddressBook)
self.actionTrashInboxMessage = self.ui.inboxContextMenuToolbar.addAction( self.actionTrashInboxMessage = self.ui.inboxContextMenuToolbar.addAction(
_translate("MainWindow", "Move to Trash"), self.on_action_InboxTrash) _translate("MainWindow", "Move to Trash"), self.on_action_InboxTrash)
self.actionSaveMessageAs = self.ui.inboxContextMenuToolbar.addAction(_translate( self.actionSaveMessageAs = self.ui.inboxContextMenuToolbar.addAction(_translate(
@ -239,7 +239,7 @@ class MyForm(QtGui.QMainWindow):
self.actionSentClipboardSender = self.ui.sentContextMenuToolbar.addAction(_translate( self.actionSentClipboardSender = self.ui.sentContextMenuToolbar.addAction(_translate(
"MainWindow", "Copy sender address to clipboard"), self.on_action_SentClipboardSender) "MainWindow", "Copy sender address to clipboard"), self.on_action_SentClipboardSender)
self.actionSentAddRecipientToAddressBook = self.ui.inboxContextMenuToolbar.addAction(_translate( self.actionSentAddRecipientToAddressBook = self.ui.inboxContextMenuToolbar.addAction(_translate(
"MainWindow", "Add address to Address Book"), self.on_action_SentAddRecipientToAddressBook) "MainWindow", "Add to Address Book"), self.on_action_SentAddRecipientToAddressBook)
self.actionSentRecipientSubscribe = self.ui.inboxContextMenuToolbar.addAction(_translate( self.actionSentRecipientSubscribe = self.ui.inboxContextMenuToolbar.addAction(_translate(
"MainWindow", "Subscribe to this address"), self.on_action_SentRecipientSubscribe) "MainWindow", "Subscribe to this address"), self.on_action_SentRecipientSubscribe)
self.actionSentSaveMessageAs = self.ui.inboxContextMenuToolbar.addAction(_translate( self.actionSentSaveMessageAs = self.ui.inboxContextMenuToolbar.addAction(_translate(
@ -293,6 +293,8 @@ class MyForm(QtGui.QMainWindow):
"MainWindow", "Send message to this Chan"), self.on_action_YourIdentitiesSendToChan) "MainWindow", "Send message to this Chan"), self.on_action_YourIdentitiesSendToChan)
self.actionYourIdentitiesClipboard = self.ui.addressContextMenuToolbar.addAction(_translate( self.actionYourIdentitiesClipboard = self.ui.addressContextMenuToolbar.addAction(_translate(
"MainWindow", "Copy address to clipboard"), self.on_action_YourIdentitiesClipboard) "MainWindow", "Copy address to clipboard"), self.on_action_YourIdentitiesClipboard)
self.actionYourIdentitiesAddToAddressBook = self.ui.addressContextMenuToolbar.addAction(_translate(
"MainWindow", "Add to Address Book"), self.on_action_YourIdentitiesAddToAddressBook)
self.actionSpecialAddressBehavior = self.ui.addressContextMenuToolbar.addAction(_translate( self.actionSpecialAddressBehavior = self.ui.addressContextMenuToolbar.addAction(_translate(
"MainWindow", "Special address behavior..."), self.on_action_SpecialAddressBehaviorDialog) "MainWindow", "Special address behavior..."), self.on_action_SpecialAddressBehaviorDialog)
self.ui.tableWidgetYourIdentities.setContextMenuPolicy( self.ui.tableWidgetYourIdentities.setContextMenuPolicy(
@ -306,6 +308,7 @@ class MyForm(QtGui.QMainWindow):
self.popMenuIdentities.addAction(self.actionYourIdentitiesSendFromAddress) self.popMenuIdentities.addAction(self.actionYourIdentitiesSendFromAddress)
self.popMenuIdentities.addAction(self.actionYourIdentitiesSendToChan) self.popMenuIdentities.addAction(self.actionYourIdentitiesSendToChan)
self.popMenuIdentities.addAction(self.actionYourIdentitiesClipboard) self.popMenuIdentities.addAction(self.actionYourIdentitiesClipboard)
self.popMenuIdentities.addAction(self.actionYourIdentitiesAddToAddressBook)
self.popMenuIdentities.addSeparator() self.popMenuIdentities.addSeparator()
self.popMenuIdentities.addAction(self.actionEnable) self.popMenuIdentities.addAction(self.actionEnable)
self.popMenuIdentities.addAction(self.actionDisable) self.popMenuIdentities.addAction(self.actionDisable)
@ -320,6 +323,8 @@ class MyForm(QtGui.QMainWindow):
_translate("MainWindow", "Delete"), self.on_action_SubscriptionsDelete) _translate("MainWindow", "Delete"), self.on_action_SubscriptionsDelete)
self.actionsubscriptionsClipboard = self.ui.subscriptionsContextMenuToolbar.addAction( self.actionsubscriptionsClipboard = self.ui.subscriptionsContextMenuToolbar.addAction(
_translate("MainWindow", "Copy address to clipboard"), self.on_action_SubscriptionsClipboard) _translate("MainWindow", "Copy address to clipboard"), self.on_action_SubscriptionsClipboard)
self.actionSubscriptionsAddToAddressBook = self.ui.subscriptionsContextMenuToolbar.addAction(
_translate("MainWindow", "Add to Address Book"), self.on_action_SubscriptionsAddToAddressBook)
self.actionsubscriptionsSend = self.ui.subscriptionsContextMenuToolbar.addAction( self.actionsubscriptionsSend = self.ui.subscriptionsContextMenuToolbar.addAction(
_translate("MainWindow", "Send message to this address"), self.on_action_SubscriptionsSend) _translate("MainWindow", "Send message to this address"), self.on_action_SubscriptionsSend)
self.actionsubscriptionsEnable = self.ui.subscriptionsContextMenuToolbar.addAction( self.actionsubscriptionsEnable = self.ui.subscriptionsContextMenuToolbar.addAction(
@ -335,6 +340,7 @@ class MyForm(QtGui.QMainWindow):
self.popMenuSubscriptions.addSeparator() self.popMenuSubscriptions.addSeparator()
self.popMenuSubscriptions.addAction(self.actionsubscriptionsSend) self.popMenuSubscriptions.addAction(self.actionsubscriptionsSend)
self.popMenuSubscriptions.addAction(self.actionsubscriptionsClipboard) self.popMenuSubscriptions.addAction(self.actionsubscriptionsClipboard)
self.popMenuSubscriptions.addAction(self.actionSubscriptionsAddToAddressBook)
self.popMenuSubscriptions.addSeparator() self.popMenuSubscriptions.addSeparator()
self.popMenuSubscriptions.addAction(self.actionsubscriptionsEnable) self.popMenuSubscriptions.addAction(self.actionsubscriptionsEnable)
self.popMenuSubscriptions.addAction(self.actionsubscriptionsDisable) self.popMenuSubscriptions.addAction(self.actionsubscriptionsDisable)
@ -378,6 +384,8 @@ class MyForm(QtGui.QMainWindow):
"MainWindow", "Send message to this address"), self.on_action_BlacklistSend) "MainWindow", "Send message to this address"), self.on_action_BlacklistSend)
self.actionBlacklistClipboard = self.ui.blacklistContextMenuToolbar.addAction(_translate( self.actionBlacklistClipboard = self.ui.blacklistContextMenuToolbar.addAction(_translate(
"MainWindow", "Copy address to clipboard"), self.on_action_BlacklistClipboard) "MainWindow", "Copy address to clipboard"), self.on_action_BlacklistClipboard)
self.actionBlacklistAddToAddressBook = self.ui.blacklistContextMenuToolbar.addAction(_translate(
"MainWindow", "Add to Address Book"), self.on_action_BlacklistAddToAddressBook)
self.actionBlacklistSubscribe = self.ui.addressBookContextMenuToolbar.addAction(_translate( self.actionBlacklistSubscribe = self.ui.addressBookContextMenuToolbar.addAction(_translate(
"MainWindow", "Subscribe to this address"), self.on_action_BlacklistSubscribe) "MainWindow", "Subscribe to this address"), self.on_action_BlacklistSubscribe)
self.actionBlacklistEnable = self.ui.blacklistContextMenuToolbar.addAction(_translate( self.actionBlacklistEnable = self.ui.blacklistContextMenuToolbar.addAction(_translate(
@ -393,6 +401,7 @@ class MyForm(QtGui.QMainWindow):
self.popMenuBlacklist.addSeparator() self.popMenuBlacklist.addSeparator()
self.popMenuBlacklist.addAction(self.actionBlacklistSend) self.popMenuBlacklist.addAction(self.actionBlacklistSend)
self.popMenuBlacklist.addAction(self.actionBlacklistClipboard) self.popMenuBlacklist.addAction(self.actionBlacklistClipboard)
self.popMenuBlacklist.addAction(self.actionBlacklistAddToAddressBook)
self.popMenuBlacklist.addAction(self.actionBlacklistSubscribe) self.popMenuBlacklist.addAction(self.actionBlacklistSubscribe)
self.popMenuBlacklist.addSeparator() self.popMenuBlacklist.addSeparator()
self.popMenuBlacklist.addAction(self.actionBlacklistEnable) self.popMenuBlacklist.addAction(self.actionBlacklistEnable)
@ -1174,6 +1183,8 @@ class MyForm(QtGui.QMainWindow):
else: else:
self.tray.showMessage(title, subtitle, 1, 2000) self.tray.showMessage(title, subtitle, 1, 2000)
# Key actions
def tableWidgetInboxKeyPressEvent(self, event): def tableWidgetInboxKeyPressEvent(self, event):
if event.key() == QtCore.Qt.Key_Delete: if event.key() == QtCore.Qt.Key_Delete:
self.on_action_InboxTrash() self.on_action_InboxTrash()
@ -1184,6 +1195,8 @@ class MyForm(QtGui.QMainWindow):
self.on_action_SentTrash() self.on_action_SentTrash()
return QtGui.QTableWidget.keyPressEvent(self.ui.tableWidgetSent, event) return QtGui.QTableWidget.keyPressEvent(self.ui.tableWidgetSent, event)
# Click actions
def click_actionManageKeys(self): def click_actionManageKeys(self):
if 'darwin' in sys.platform or 'linux' in sys.platform: if 'darwin' in sys.platform or 'linux' in sys.platform:
if shared.appdata == '': if shared.appdata == '':
@ -2352,8 +2365,8 @@ class MyForm(QtGui.QMainWindow):
# disable certain context menu items for multiselection # disable certain context menu items for multiselection
self.actionReply.setEnabled(is_singleselection==True) self.actionReply.setEnabled(is_singleselection==True)
self.actionReplyChan.setEnabled(is_singleselection==True) self.actionReplyChan.setEnabled(is_singleselection==True)
self.actionInboxSenderSubscribe.setEnabled(is_singleselection==True) # cannot handle multiselection yet ### self.actionInboxSenderSubscribe.setEnabled(is_singleselection==True) # cannot handle multiselection yet
self.actionAddSenderToAddressBook.setEnabled(is_singleselection==True) # cannot handle multiselection yet ### self.actionAddSenderToAddressBook.setEnabled(is_singleselection==True) # cannot handle multiselection yet
self.actionSaveMessageAs.setEnabled(is_singleselection==True) # cannot handle multiselection yet self.actionSaveMessageAs.setEnabled(is_singleselection==True) # cannot handle multiselection yet
# disable certain context menu items for single selction # disable certain context menu items for single selction
# check whether among the recipients there is a chan for "reply to chan" and "send to recipient" # check whether among the recipients there is a chan for "reply to chan" and "send to recipient"
@ -2395,7 +2408,7 @@ class MyForm(QtGui.QMainWindow):
self.actionSendAnother.setEnabled(is_singleselection==True) self.actionSendAnother.setEnabled(is_singleselection==True)
self.actionSentSaveMessageAs.setEnabled(is_singleselection==True) self.actionSentSaveMessageAs.setEnabled(is_singleselection==True)
self.actionSentAddRecipientToAddressBook.setEnabled(is_singleselection==True) # cannot handle multiselection yet self.actionSentAddRecipientToAddressBook.setEnabled(is_singleselection==True) # cannot handle multiselection yet
self.actionSentRecipientSubscribe.setEnabled(is_singleselection==True) # cannot handle multiselection yet ### self.actionSentRecipientSubscribe.setEnabled(is_singleselection==True) # cannot handle multiselection yet
self.actionSaveMessageAs.setEnabled(is_singleselection==True) # cannot handle multiselection yet self.actionSaveMessageAs.setEnabled(is_singleselection==True) # cannot handle multiselection yet
# pop up # pop up
self.popMenuSent.exec_(self.ui.tableWidgetSent.mapToGlobal(point)) self.popMenuSent.exec_(self.ui.tableWidgetSent.mapToGlobal(point))
@ -2618,36 +2631,67 @@ class MyForm(QtGui.QMainWindow):
self.ui.tabWidget.setCurrentIndex(1) self.ui.tabWidget.setCurrentIndex(1)
# Add to Address Book # Add to Address Book
###
def on_action_InboxAddSenderToAddressBook(self):
thisTableWidget = self.ui.tableWidgetInbox
labelColumn = 1
addressColumn = 1
useData = True
self.on_action_AddToAddressBook(thisTableWidget,labelColumn,addressColumn,useData)
def on_action_SentAddRecipientToAddressBook(self): def on_action_SentAddRecipientToAddressBook(self):
thisTableWidget = self.ui.tableWidgetSent thisTableWidget = self.ui.tableWidgetSent
thisColumn = 0 labelColumn = 0
self.on_action_AddToAddressBook(thisTableWidget,thisColumn) addressColumn = 0
useData = True
self.on_action_AddToAddressBook(thisTableWidget,labelColumn,addressColumn,useData)
def on_action_InboxAddSenderToAddressBook(self): def on_action_YourIdentitiesAddToAddressBook(self):
thisTableWidget = self.ui.tableWidgetInbox thisTableWidget = self.ui.tableWidgetYourIdentities
thisColumn = 1 labelColumn = 0
self.on_action_AddToAddressBook(thisTableWidget,thisColumn) addressColumn = 1
useData = False
self.on_action_AddToAddressBook(thisTableWidget,labelColumn,addressColumn,useData)
def on_action_AddToAddressBook(self,thisTableWidget,thisColumn): def on_action_SubscriptionsAddToAddressBook(self):
thisTableWidget = self.ui.tableWidgetSubscriptions
labelColumn = 0
addressColumn = 1
useData = False
self.on_action_AddToAddressBook(thisTableWidget,labelColumn,addressColumn,useData)
def on_action_BlacklistAddToAddressBook(self):
thisTableWidget = self.ui.tableWidgetBlacklist
labelColumn = 0
addressColumn = 1
useData = False
self.on_action_AddToAddressBook(thisTableWidget,labelColumn,addressColumn,useData)
def on_action_AddToAddressBook(self,thisTableWidget,labelColumn,addressColumn,useData):
currentRow = thisTableWidget.currentRow() currentRow = thisTableWidget.currentRow()
addressAtCurrentRow = str(thisTableWidget.item( if useData:
currentRow, thisColumn).data(Qt.UserRole).toPyObject()) labelAtCurrentRow = str(_translate("MainWindow", "--New entry. Change label in Address Book.--"))
addressAtCurrentRow = str(thisTableWidget.item(
currentRow, addressColumn).data(Qt.UserRole).toPyObject())
else:
labelAtCurrentRow = str(thisTableWidget.item(
currentRow, labelColumn).text())
addressAtCurrentRow = str(thisTableWidget.item(
currentRow, addressColumn).text())
# Let's make sure that it isn't already in the address book # Let's make sure that it isn't already in the address book
queryreturn = sqlQuery('''select * from addressbook where address=?''', queryreturn = sqlQuery('''select * from addressbook where address=?''',
addressAtCurrentInboxRow) addressAtCurrentRow)
if queryreturn == []: if queryreturn == []:
self.ui.tableWidgetAddressBook.insertRow(0) self.ui.tableWidgetAddressBook.insertRow(0)
newItem = QtGui.QTableWidgetItem( newItem = QtGui.QTableWidgetItem(labelAtCurrentRow)
'--New entry. Change label in Address Book.--')
self.ui.tableWidgetAddressBook.setItem(0, 0, newItem) self.ui.tableWidgetAddressBook.setItem(0, 0, newItem)
newItem = QtGui.QTableWidgetItem(addressAtCurrentRow) newItem = QtGui.QTableWidgetItem(addressAtCurrentRow)
newItem.setFlags( newItem.setFlags(
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
self.ui.tableWidgetAddressBook.setItem(0, 1, newItem) self.ui.tableWidgetAddressBook.setItem(0, 1, newItem)
sqlExecute('''INSERT INTO addressbook VALUES (?,?)''', sqlExecute('''INSERT INTO addressbook VALUES (?,?)''',
'--New entry. Change label in Address Book.--', labelAtCurrentRow,
addressAtCurrentInboxRow) addressAtCurrentRow)
self.ui.tabWidget.setCurrentIndex(5) self.ui.tabWidget.setCurrentIndex(5)
self.ui.tableWidgetAddressBook.setCurrentCell(0, 0) self.ui.tableWidgetAddressBook.setCurrentCell(0, 0)
self.statusBar().showMessage(_translate( self.statusBar().showMessage(_translate(
@ -2866,7 +2910,7 @@ class MyForm(QtGui.QMainWindow):
currentRow, 0).text().toUtf8() currentRow, 0).text().toUtf8()
addressAtCurrentRow = thisTableWidget.item( addressAtCurrentRow = thisTableWidget.item(
currentRow, 1).text() currentRow, 1).text()
sqlExecute('''DELETE FROM addressbook WHERE label=? AND address=?''', sqlExecute('''DELETE FROM '''+sql_where+''' WHERE label=? AND address=?''',
str(labelAtCurrentRow), str(addressAtCurrentRow)) str(labelAtCurrentRow), str(addressAtCurrentRow))
thisTableWidget.removeRow(currentRow) thisTableWidget.removeRow(currentRow)
# probably more efficient not to do this every time: # probably more efficient not to do this every time:
@ -2985,47 +3029,51 @@ class MyForm(QtGui.QMainWindow):
def on_action_InboxSenderSubscribe(self): def on_action_InboxSenderSubscribe(self):
thisTableWidget = self.ui.tableWidgetInbox thisTableWidget = self.ui.tableWidgetInbox
thisColumn = 1 thisColumn = 1
self.on_action_Subscribe(thisTableWidget,thisColumn) useData = True
self.on_action_Subscribe(thisTableWidget,thisColumn,useData)
def on_action_SentRecipientSubscribe(self): def on_action_SentRecipientSubscribe(self):
thisTableWidget = self.ui.tableWidgetSent thisTableWidget = self.ui.tableWidgetSent
thisColumn = 0 thisColumn = 0
self.on_action_Subscribe(thisTableWidget,thisColumn) useData = True
self.on_action_Subscribe(thisTableWidget,thisColumn,useData)
def on_action_BlacklistSubscribe(self): def on_action_BlacklistSubscribe(self):
thisTableWidget = self.ui.tableWidgetBlacklist thisTableWidget = self.ui.tableWidgetBlacklist
thisColumn = 1 thisColumn = 1
self.on_action_Subscribe(thisTableWidget,thisColumn) useData = False
self.on_action_Subscribe(thisTableWidget,thisColumn,useData)
def on_action_AddressBookSubscribe(self): def on_action_AddressBookSubscribe(self):
thisTableWidget = self.ui.tableWidgetAddressBook thisTableWidget = self.ui.tableWidgetAddressBook
thisColumn = 1 thisColumn = 1
self.on_action_Subscribe(thisTableWidget,thisColumn) useData = False
self.on_action_Subscribe(thisTableWidget,thisColumn,useData)
def on_action_BlacklistSubscribe(self):
thisTableWidget = self.ui.tableWidgetBlacklist
thisColumn = 1
self.on_action_Subscribe(thisTableWidget,thisColumn)
# there's no on_action_YourIdentitiesSubscribe, on_action_InboxRecipientSubscribe, and on_action_SentSenderSubscribe, because you wouldn't want to subscribe to yourself or to a chan # there's no on_action_YourIdentitiesSubscribe, on_action_InboxRecipientSubscribe, and on_action_SentSenderSubscribe, because you wouldn't want to subscribe to yourself or to a chan
def on_action_Subscribe(self,thisTableWidget,thisColumn): def on_action_Subscribe(self,thisTableWidget,thisColumn,useData):
listOfSelectedRows = {} listOfSelectedRows = {}
for i in range(len(thisTableWidget.selectedIndexes())): for i in range(len(thisTableWidget.selectedIndexes())):
listOfSelectedRows[thisTableWidget.selectedIndexes()[i].row()] = 0 listOfSelectedRows[thisTableWidget.selectedIndexes()[i].row()] = 0
for currentRow in listOfSelectedRows: for currentRow in listOfSelectedRows:
addressAtCurrentRow = str(thisTableWidget.item(currentRow,thisColumn).text()) addressAtCurrentRow = str(thisTableWidget.item(currentRow,thisColumn).text())
# Then subscribe to it... provided it's not already in the address book if useData:
if shared.isAddressInMySubscriptionsList(addressAtCurrentRow): labelAtCurrentRow = str(thisTableWidget.item(currentRow,thisColumn).text())
self.statusBar().showMessage(QtGui.QApplication.translate("MainWindow", "Error: You cannot add the same address to your subsciptions twice. Perhaps rename the existing one if you want.")) addressAtCurrentRow = str(thisTableWidget.item(currentRow,thisColumn).data(Qt.UserRole).toPyObject())
continue if labelAtCurrentRow == addressAtCurrentRow:
labelAtCurrentRow = '' labelAtCurrentRow = str(_translate("MainWindow", "--New entry. Change label in Subscriptions.--"))
if (thisTableWidget == self.ui.tableWidgetAddressBook) | (thisTableWidget == self.ui.tableWidgetBlacklist): elif (thisTableWidget == self.ui.tableWidgetAddressBook) | (thisTableWidget == self.ui.tableWidgetBlacklist):
# if subscribing from an address list, copy the label # if subscribing from an address list, copy the label
labelAtCurrentRow = thisTableWidget.item(currentRow,0).text().toUtf8() labelAtCurrentRow = thisTableWidget.item(currentRow,0).text().toUtf8()
# Then subscribe to it... provided it's not already in the address book
if shared.isAddressInMySubscriptionsList(addressAtCurrentRow):
self.statusBar().showMessage(_translate("MainWindow", "Error: You cannot add the same address to your subsciptions twice. Perhaps rename the existing one if you want."))
continue
self.addSubscription(addressAtCurrentRow, labelAtCurrentRow) self.addSubscription(addressAtCurrentRow, labelAtCurrentRow)
# switch to the Subscriptions tab # switch to the Subscriptions tab
self.ui.tabWidget.setCurrentIndex(4) self.ui.tabWidget.setCurrentIndex(4)
# maybe it should then select the new label of the new item to immediately edit it ###
# Enable / Disable Addresses # Enable / Disable Addresses