commit 7cb02f5d2ace5e4e17665c0cf4b2dfcaa0df24b4
parent 68c7d2e349e98320a1cc23ccc20a90559814ca8c
Author: ThomasV <thomasv@gitorious>
Date: Mon, 24 Nov 2014 12:28:51 +0100
Merge branch 'Tafelpoot-contacts'
Diffstat:
2 files changed, 52 insertions(+), 26 deletions(-)
diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py
@@ -628,6 +628,13 @@ class ElectrumWindow(QMainWindow):
run_hook('current_item_changed', a)
+ def format_time(self, timestamp):
+ try:
+ time_str = datetime.datetime.fromtimestamp( timestamp).isoformat(' ')[:-3]
+ except Exception:
+ time_str = _("error")
+ return time_str
+
def update_history_tab(self):
@@ -636,11 +643,7 @@ class ElectrumWindow(QMainWindow):
tx_hash, conf, is_mine, value, fee, balance, timestamp = item
time_str = _("unknown")
if conf > 0:
- try:
- time_str = datetime.datetime.fromtimestamp( timestamp).isoformat(' ')[:-3]
- except Exception:
- time_str = _("error")
-
+ time_str = self.format_time(timestamp)
if conf == -1:
time_str = 'unverified'
icon = QIcon(":icons/unconfirmed.png")
@@ -715,6 +718,7 @@ class ElectrumWindow(QMainWindow):
self.save_request_button = QPushButton(_('Save'))
self.save_request_button.clicked.connect(self.save_payment_request)
grid.addWidget(self.save_request_button, 3, 1)
+
clear_button = QPushButton(_('New'))
clear_button.clicked.connect(self.new_receive_address)
grid.addWidget(clear_button, 3, 2)
@@ -731,12 +735,14 @@ class ElectrumWindow(QMainWindow):
self.receive_list.customContextMenuRequested.connect(self.receive_list_menu)
self.receive_list.currentItemChanged.connect(self.receive_item_changed)
self.receive_list.itemClicked.connect(self.receive_item_changed)
- self.receive_list.setHeaderLabels( [_('Address'), _('Message'), _('Amount')] )
- self.receive_list.setColumnWidth(0, 340)
+ self.receive_list.setHeaderLabels( [_('Date'), _('Account'), _('Address'), _('Message'), _('Amount')] )
+ self.receive_list.setSortingEnabled(True)
+ self.receive_list.setColumnWidth(0, 180)
+ self.receive_list.hideColumn(1) # the update will show it if necessary
+ self.receive_list.setColumnWidth(2, 340)
h = self.receive_list.header()
h.setStretchLastSection(False)
- h.setResizeMode(1, QHeaderView.Stretch)
-
+ h.setResizeMode(3, QHeaderView.Stretch)
grid.addWidget(self.receive_requests_label, 6, 0)
grid.addWidget(self.receive_list, 7, 0, 1, 6)
return w
@@ -744,37 +750,39 @@ class ElectrumWindow(QMainWindow):
def receive_item_changed(self, item):
if item is None:
return
- addr = str(item.text(0))
- amount, message = self.receive_requests[addr]
+ addr = str(item.text(2))
+ req = self.receive_requests[addr]
+ time, amount, message = req['time'], req['amount'], req['msg']
self.receive_address_e.setText(addr)
self.receive_message_e.setText(message)
self.receive_amount_e.setAmount(amount)
def receive_list_delete(self, item):
- addr = str(item.text(0))
+ addr = str(item.text(2))
self.receive_requests.pop(addr)
- self.wallet.storage.put('receive_requests', self.receive_requests)
+ self.wallet.storage.put('receive_requests2', self.receive_requests)
self.update_receive_tab()
self.clear_receive_tab()
def receive_list_menu(self, position):
item = self.receive_list.itemAt(position)
menu = QMenu()
- menu.addAction(_("Copy to clipboard"), lambda: self.app.clipboard().setText(str(item.text(0))))
+ menu.addAction(_("Copy to clipboard"), lambda: self.app.clipboard().setText(str(item.text(2))))
menu.addAction(_("Delete"), lambda: self.receive_list_delete(item))
menu.exec_(self.receive_list.viewport().mapToGlobal(position))
def save_payment_request(self):
+ timestamp = int(time.time())
addr = str(self.receive_address_e.text())
amount = self.receive_amount_e.get_amount()
message = unicode(self.receive_message_e.text())
if not message and not amount:
QMessageBox.warning(self, _('Error'), _('No message or amount'), _('OK'))
return
- self.receive_requests = self.wallet.storage.get('receive_requests',{})
- self.receive_requests[addr] = (amount, message)
- self.wallet.storage.put('receive_requests', self.receive_requests)
+ self.receive_requests = self.wallet.storage.get('receive_requests2',{})
+ self.receive_requests[addr] = {'time':timestamp, 'amount':amount, 'msg':message}
+ self.wallet.storage.put('receive_requests2', self.receive_requests)
self.update_receive_tab()
def new_receive_address(self):
@@ -794,7 +802,7 @@ class ElectrumWindow(QMainWindow):
self.receive_amount_e.setAmount(None)
def clear_receive_tab(self):
- self.receive_requests = self.wallet.storage.get('receive_requests',{})
+ self.receive_requests = self.wallet.storage.get('receive_requests2',{})
domain = self.wallet.get_account_addresses(self.current_account, include_change=False)
for addr in domain:
if not self.wallet.history.get(addr) and addr not in self.receive_requests.keys():
@@ -828,19 +836,37 @@ class ElectrumWindow(QMainWindow):
self.receive_address_e.setText(addr)
def update_receive_tab(self):
- self.receive_requests = self.wallet.storage.get('receive_requests',{})
+ self.receive_requests = self.wallet.storage.get('receive_requests2',{})
+
+ # hide receive tab if no receive requests available
b = len(self.receive_requests) > 0
self.receive_list.setVisible(b)
self.receive_requests_label.setVisible(b)
+ # check if it is necessary to show the account
+ self.receive_list.setColumnHidden(1, len(self.wallet.get_accounts()) == 1)
+
+ # update the receive address if necessary
+ current_address = self.receive_address_e.text()
+ domain = self.wallet.get_account_addresses(self.current_account, include_change=False)
+ if not current_address in domain:
+ self.new_receive_address()
+
+ # clear the list and fill it again
self.receive_list.clear()
- for address, v in self.receive_requests.items():
- amount, message = v
- item = QTreeWidgetItem( [ address, message, self.format_amount(amount) if amount else ""] )
- item.setFont(0, QFont(MONOSPACE_FONT))
+ for address, req in self.receive_requests.viewitems():
+ timestamp, amount, message = req['time'], req['amount'], req['msg']
+ # only show requests for the current account
+ if address not in domain:
+ continue
+ date = self.format_time(timestamp)
+ account = self.wallet.get_account_name(self.wallet.get_account_from_address(address))
+ item = QTreeWidgetItem( [ date, account, address, message, self.format_amount(amount) if amount else ""])
+ item.setFont(2, QFont(MONOSPACE_FONT))
self.receive_list.addTopLevelItem(item)
+
def update_receive_qr(self):
import urlparse, urllib
addr = str(self.receive_address_e.text())
@@ -2404,10 +2430,10 @@ class ElectrumWindow(QMainWindow):
h, b = ok_cancel_buttons2(d, _('Export'))
vbox.addLayout(h)
-
+
run_hook('export_history_dialog', self,hbox)
self.update()
-
+
if not d.exec_():
return
diff --git a/lib/wallet.py b/lib/wallet.py
@@ -486,7 +486,7 @@ class Abstract_Wallet(object):
"Returns the account that contains this address, or None"
for acc_id in self.accounts: # similar to get_address_index but simpler
if addr in self.get_account_addresses(acc_id):
- return self.accounts[acc_id]
+ return acc_id
return None
def get_account_balance(self, account):