commit 782522fb7103ca4cac3d83a271f344f247ed73af
parent e8189490e9a2ac6805c5800526bd1ea582e97daa
Author: ThomasV <thomasv@gitorious>
Date: Thu, 23 Apr 2015 12:46:52 +0200
update guis for new contacts
Diffstat:
4 files changed, 27 insertions(+), 39 deletions(-)
diff --git a/gui/android.py b/gui/android.py
@@ -76,11 +76,7 @@ def edit_label(addr):
def select_from_contacts():
title = 'Contacts:'
droid.dialogCreateAlert(title)
- l = []
- for i in range(len(wallet.addressbook)):
- addr = wallet.addressbook[i]
- label = wallet.labels.get(addr,addr)
- l.append( label )
+ l = contacts.keys()
droid.dialogSetItems(l)
droid.dialogSetPositiveButtonText('New contact')
droid.dialogShow()
@@ -92,8 +88,8 @@ def select_from_contacts():
result = response.get('item')
if result is not None:
- addr = wallet.addressbook[result]
- return addr
+ t, v = contacts.get(result)
+ return v
@@ -483,7 +479,8 @@ def make_new_contact():
address = None
if address:
if modal_question('Add to contacts?', address):
- wallet.add_contact(address)
+ # fixme: ask for key
+ contacts[address] = ('address', address)
else:
modal_dialog('Invalid address', data)
@@ -893,17 +890,20 @@ droid = android.Android()
menu_commands = ["send", "receive", "settings", "contacts", "main"]
wallet = None
network = None
+contacts = None
class ElectrumGui:
def __init__(self, config, _network):
- global wallet, network
+ global wallet, network, contacts
network = _network
network.register_callback('updated', update_callback)
network.register_callback('connected', update_callback)
network.register_callback('disconnected', update_callback)
network.register_callback('disconnecting', update_callback)
+ contacts = util.StoreDict(config, 'contacts')
+
storage = WalletStorage(config)
if not storage.file_exists:
action = self.restore_or_create()
diff --git a/gui/gtk.py b/gui/gtk.py
@@ -466,6 +466,9 @@ class ElectrumWindow:
self.window.set_default_size(720, 350)
self.wallet_updated = False
+ from electrum.util import StoreDict
+ self.contacts = StoreDict(self.config, 'contacts')
+
vbox = Gtk.VBox()
self.notebook = Gtk.Notebook()
@@ -1154,17 +1157,10 @@ class ElectrumWindow:
self.recv_list.append((address, label, tx, format_satoshis(c,False,self.num_zeros), Type ))
def update_sending_tab(self):
- # detect addresses that are not mine in history, add them here...
self.addressbook_list.clear()
- #for alias, v in self.wallet.aliases.items():
- # s, target = v
- # label = self.wallet.labels.get(alias)
- # self.addressbook_list.append((alias, label, '-'))
-
- for address in self.wallet.addressbook:
- label = self.wallet.labels.get(address)
- n = self.wallet.get_num_tx(address)
- self.addressbook_list.append((address, label, "%d"%n))
+ for k, v in self.contacts.items():
+ t, v = v
+ self.addressbook_list.append((k, v, t))
def update_history_tab(self):
cursor = self.history_treeview.get_cursor()[0]
@@ -1268,7 +1264,7 @@ class ElectrumWindow:
if result == 1:
if is_valid(address):
- self.wallet.add_contact(address,label)
+ self.contacts[label] = address
self.update_sending_tab()
else:
errorDialog = Gtk.MessageDialog(
diff --git a/gui/stdio.py b/gui/stdio.py
@@ -2,7 +2,7 @@ from decimal import Decimal
_ = lambda x:x
#from i18n import _
from electrum.wallet import WalletStorage, Wallet
-from electrum.util import format_satoshis, set_verbosity
+from electrum.util import format_satoshis, set_verbosity, StoreDict
from electrum.bitcoin import is_valid
from electrum.network import filter_protocol
import sys, getpass, datetime
@@ -32,6 +32,7 @@ class ElectrumGui:
self.wallet = Wallet(storage)
self.wallet.start_threads(network)
+ self.contacts = StoreDict(self.config, 'contacts')
self.wallet.network.register_callback('updated', self.updated)
self.wallet.network.register_callback('connected', self.connected)
@@ -133,8 +134,8 @@ class ElectrumGui:
def print_contacts(self):
- messages = map(lambda addr: "%30s %30s "%(addr, self.wallet.labels.get(addr,"")), self.wallet.addressbook)
- self.print_list(messages, "%19s %25s "%("Address", "Label"))
+ messages = map(lambda x: "%20s %45s "%(x[0], x[1][1]), self.contacts.items())
+ self.print_list(messages, "%19s %25s "%("Key", "Value"))
def print_addresses(self):
messages = map(lambda addr: "%30s %30s "%(addr, self.wallet.labels.get(addr,"")), self.wallet.addresses())
@@ -239,14 +240,3 @@ class ElectrumGui:
def run_contacts_tab(self, c):
pass
-# if c == 10 and self.wallet.addressbook:
-# out = self.run_popup('Adress', ["Copy", "Pay to", "Edit label", "Delete"]).get('button')
-# address = self.wallet.addressbook[self.pos%len(self.wallet.addressbook)]
-# if out == "Pay to":
-# self.tab = 1
-# self.str_recipient = address
-# self.pos = 2
-# elif out == "Edit label":
-# s = self.get_string(6 + self.pos, 18)
-# if s:
-# self.wallet.labels[address] = s
diff --git a/gui/text.py b/gui/text.py
@@ -3,6 +3,7 @@ from decimal import Decimal
_ = lambda x:x
#from i18n import _
from electrum.util import format_satoshis, set_verbosity
+from electrum.util import StoreDict
from electrum.bitcoin import is_valid
from electrum import Wallet, WalletStorage
@@ -23,6 +24,7 @@ class ElectrumGui:
self.wallet = Wallet(storage)
self.wallet.start_threads(self.network)
+ self.contacts = StoreDict(self.config, 'contacts')
locale.setlocale(locale.LC_ALL, '')
self.encoding = locale.getpreferredencoding()
@@ -145,8 +147,8 @@ class ElectrumGui:
def print_contacts(self):
- messages = map(lambda addr: "%30s %30s "%(addr, self.wallet.labels.get(addr,"")), self.wallet.addressbook)
- self.print_list(messages, "%19s %25s "%("Address", "Label"))
+ messages = map(lambda x: "%20s %45s "%(x[0], x[1][1]), self.contacts.items())
+ self.print_list(messages, "%19s %15s "%("Key", "Value"))
def print_receive(self):
fmt = "%-35s %-30s"
@@ -248,12 +250,12 @@ class ElectrumGui:
out = self.run_popup('Address', ["Edit label", "Freeze", "Prioritize"])
def run_contacts_tab(self, c):
- if c == 10 and self.wallet.addressbook:
+ if c == 10 and self.contacts:
out = self.run_popup('Adress', ["Copy", "Pay to", "Edit label", "Delete"]).get('button')
- address = self.wallet.addressbook[self.pos%len(self.wallet.addressbook)]
+ key = self.contacts.keys()[self.pos%len(self.contacts.keys())]
if out == "Pay to":
self.tab = 1
- self.str_recipient = address
+ self.str_recipient = key
self.pos = 2
elif out == "Edit label":
s = self.get_string(6 + self.pos, 18)