From ad01fd69515bd51e7d3cf87a0713f1df4426715b Mon Sep 17 00:00:00 2001 From: bikash617 Date: Fri, 8 Nov 2013 17:10:19 +0400 Subject: [PATCH] added a functionality which adds the selected subscription to address book. --- src/bitmessageqt/__init__.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index a3bf7ec3..39abcf32 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -363,6 +363,8 @@ class MyForm(QtGui.QMainWindow): self.actionsubscriptionsSetAvatar = self.ui.subscriptionsContextMenuToolbar.addAction( _translate("MainWindow", "Set avatar..."), self.on_action_SubscriptionsSetAvatar) + self.actionsendaddressfromsubscription = self.ui.subscriptionsContextMenuToolbar.addAction( + _translate("MainWindow", "Add Subscription to Address book"), self.on_action_SubscriptionAddSenderToAddressBook) self.ui.tableWidgetSubscriptions.setContextMenuPolicy( QtCore.Qt.CustomContextMenu) self.connect(self.ui.tableWidgetSubscriptions, QtCore.SIGNAL( @@ -377,6 +379,7 @@ class MyForm(QtGui.QMainWindow): self.popMenuSubscriptions.addAction(self.actionsubscriptionsSetAvatar) self.popMenuSubscriptions.addSeparator() self.popMenuSubscriptions.addAction(self.actionsubscriptionsClipboard) + self.popMenuSubscriptions.addAction(self.actionsendaddressfromsubscription) def init_sent_popup_menu(self): # Popup menu for the Sent page @@ -2831,6 +2834,39 @@ class MyForm(QtGui.QMainWindow): self.popMenuSubscriptions.exec_( self.ui.tableWidgetSubscriptions.mapToGlobal(point)) + def on_action_SubscriptionAddSenderToAddressBook(self): + currentSubscriptionRow = self.ui.tableWidgetSubscriptions.currentRow() + # self.ui.tableWidgetInbox.item(currentRow,1).data(Qt.UserRole).toPyObject() + addressAtCurrentSubscriptionRow = str(self.ui.tableWidgetSubscriptions.item( + currentSubscriptionRow, 1).text()) + labelAtCurrentSubscriptionRow = str(self.ui.tableWidgetSubscriptions.item( + currentSubscriptionRow, 0).text()) + + # Let's make sure that it isn't already in the address book + queryreturn = sqlQuery('''select * from addressbook where address=?''', + addressAtCurrentSubscriptionRow) + if queryreturn == []: + self.ui.tableWidgetAddressBook.insertRow(0) + #newItem = QtGui.QTableWidgetItem( + # '--New entry. Change label in Address Book.--') + newItem = QtGui.QTableWidgetItem(labelAtCurrentSubscriptionRow) + self.ui.tableWidgetAddressBook.setItem(0, 0, newItem) + newItem = QtGui.QTableWidgetItem(addressAtCurrentSubscriptionRow) + newItem.setFlags( + QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) + self.ui.tableWidgetAddressBook.setItem(0, 1, newItem) + sqlExecute('''INSERT INTO addressbook VALUES (?,?)''', + labelAtCurrentSubscriptionRow, + addressAtCurrentSubscriptionRow) + self.ui.tabWidget.setCurrentIndex(5) + self.ui.tableWidgetAddressBook.setCurrentCell(0, 0) + self.statusBar().showMessage(_translate( + "MainWindow", "Entry added to the Address Book. Edit the label to your liking. ")) + 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.")) + + # Group of functions for the Blacklist dialog box def on_action_BlacklistNew(self): self.click_pushButtonAddBlacklist()