commit c7f89da934a48cf8960cbdc789cc5bf032546259
parent ce5808e894d30fd56f30bcf64175097d5c4ccce7
Author: ThomasV <thomasv@gitorious>
Date: Wed, 25 Feb 2015 10:01:59 +0100
copy request URI to clipboard
Diffstat:
2 files changed, 23 insertions(+), 17 deletions(-)
diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py
@@ -797,7 +797,6 @@ class ElectrumWindow(QMainWindow):
self.receive_message_e.setText(message)
self.receive_amount_e.setAmount(amount)
-
def receive_list_delete(self, item):
addr = str(item.text(2))
self.receive_requests.pop(addr)
@@ -807,8 +806,12 @@ class ElectrumWindow(QMainWindow):
def receive_list_menu(self, position):
item = self.receive_list.itemAt(position)
+ addr = str(item.text(2))
+ req = self.receive_requests[addr]
+ time, amount, message = req['time'], req['amount'], req['msg']
+ URI = util.create_URI(addr, amount, message)
menu = QMenu()
- menu.addAction(_("Copy to clipboard"), lambda: self.app.clipboard().setText(str(item.text(2))))
+ menu.addAction(_("Copy to clipboard"), lambda: self.app.clipboard().setText(str(URI)))
menu.addAction(_("Delete"), lambda: self.receive_list_delete(item))
menu.exec_(self.receive_list.viewport().mapToGlobal(position))
@@ -914,26 +917,15 @@ class ElectrumWindow(QMainWindow):
self.receive_list.addTopLevelItem(item)
-
def update_receive_qr(self):
- import urlparse, urllib
addr = str(self.receive_address_e.text())
amount = self.receive_amount_e.get_amount()
message = unicode(self.receive_message_e.text()).encode('utf8')
self.save_request_button.setEnabled((amount is not None) or (message != ""))
- if addr:
- query = []
- if amount:
- query.append('amount=%s'%format_satoshis(amount))
- if message:
- query.append('message=%s'%urllib.quote(message))
- p = urlparse.ParseResult(scheme='bitcoin', netloc='', path=addr, params='', query='&'.join(query), fragment='')
- url = urlparse.urlunparse(p)
- else:
- url = ""
- self.receive_qr.setData(url)
+ uri = util.create_URI(addr, amount, message)
+ self.receive_qr.setData(uri)
if self.qr_window:
- self.qr_window.set_content(addr, amount, message, url)
+ self.qr_window.set_content(addr, amount, message, uri)
def create_send_tab(self):
diff --git a/lib/util.py b/lib/util.py
@@ -2,6 +2,8 @@ import os, sys, re, json
import platform
import shutil
from datetime import datetime
+import urlparse
+import urllib
class NotEnoughFunds(Exception): pass
@@ -139,7 +141,6 @@ def age(from_date, since_date = None, target_tz=None, include_seconds=False):
#urldecode = lambda x: _ud.sub(lambda m: chr(int(m.group(1), 16)), x)
def parse_URI(uri):
- import urlparse
import bitcoin
from decimal import Decimal
@@ -187,6 +188,19 @@ def parse_URI(uri):
return address, amount, label, message, request_url
+def create_URI(addr, amount, message):
+ import bitcoin
+ if not bitcoin.is_address(addr):
+ return ""
+ query = []
+ if amount:
+ query.append('amount=%s'%format_satoshis(amount))
+ if message:
+ query.append('message=%s'%urllib.quote(message))
+ p = urlparse.ParseResult(scheme='bitcoin', netloc='', path=addr, params='', query='&'.join(query), fragment='')
+ return urlparse.urlunparse(p)
+
+
# Python bug (http://bugs.python.org/issue1927) causes raw_input
# to be redirected improperly between stdin/stderr on Unix systems
def raw_input(prompt=None):