Curses fixes

- curses interface should now work with older versions of dialog
- Fixes #711
This commit is contained in:
Peter Šurda 2016-06-30 12:28:17 +02:00
parent 3d9c036129
commit e5c9e6d383
Signed by untrusted user: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87

View File

@ -94,6 +94,18 @@ def drawmenu(stdscr):
menustr += " " menustr += " "
stdscr.addstr(2, 5, menustr, curses.A_UNDERLINE) stdscr.addstr(2, 5, menustr, curses.A_UNDERLINE)
def set_background_title(d, title):
try:
d.set_background_title(title)
except:
d.add_persistent_args(("--backtitle", title))
def scrollbox(d, text, height=None, width=None):
try:
d.scrollbox(text, height, width, exit_label = "Continue")
except:
d.msgbox(text, height or 0, width or 0, ok_label = "Continue")
def resetlookups(): def resetlookups():
global inventorydata global inventorydata
inventorydata = shared.numberOfInventoryLookupsPerformed inventorydata = shared.numberOfInventoryLookupsPerformed
@ -260,7 +272,7 @@ def handlech(c, stdscr):
curses.curs_set(1) curses.curs_set(1)
d = Dialog(dialog="dialog") d = Dialog(dialog="dialog")
if menutab == 1: if menutab == 1:
d.set_background_title("Inbox Message Dialog Box") set_background_title(d, "Inbox Message Dialog Box")
r, t = d.menu("Do what with \""+inbox[inboxcur][5]+"\" from \""+inbox[inboxcur][3]+"\"?", r, t = d.menu("Do what with \""+inbox[inboxcur][5]+"\" from \""+inbox[inboxcur][3]+"\"?",
choices=[("1", "View message"), choices=[("1", "View message"),
("2", "Mark message as unread"), ("2", "Mark message as unread"),
@ -270,7 +282,7 @@ def handlech(c, stdscr):
("6", "Move to trash")]) ("6", "Move to trash")])
if r == d.DIALOG_OK: if r == d.DIALOG_OK:
if t == "1": # View if t == "1": # View
d.set_background_title("\""+inbox[inboxcur][5]+"\" from \""+inbox[inboxcur][3]+"\" to \""+inbox[inboxcur][1]+"\"") set_background_title(d, "\""+inbox[inboxcur][5]+"\" from \""+inbox[inboxcur][3]+"\" to \""+inbox[inboxcur][1]+"\"")
data = "" data = ""
ret = sqlQuery("SELECT message FROM inbox WHERE msgid=?", inbox[inboxcur][0]) ret = sqlQuery("SELECT message FROM inbox WHERE msgid=?", inbox[inboxcur][0])
if ret != []: if ret != []:
@ -280,11 +292,11 @@ def handlech(c, stdscr):
msg = "" msg = ""
for i, item in enumerate(data.split("\n")): for i, item in enumerate(data.split("\n")):
msg += fill(item, replace_whitespace=False)+"\n" msg += fill(item, replace_whitespace=False)+"\n"
d.scrollbox(unicode(ascii(msg)), 30, 80, exit_label="Continue") scrollbox(d, unicode(ascii(msg)), 30, 80)
sqlExecute("UPDATE inbox SET read=1 WHERE msgid=?", inbox[inboxcur][0]) sqlExecute("UPDATE inbox SET read=1 WHERE msgid=?", inbox[inboxcur][0])
inbox[inboxcur][7] = 1 inbox[inboxcur][7] = 1
else: else:
d.scrollbox(unicode("Could not fetch message."), exit_label="Continue") scrollbox(d, unicode("Could not fetch message."))
elif t == "2": # Mark unread elif t == "2": # Mark unread
sqlExecute("UPDATE inbox SET read=0 WHERE msgid=?", inbox[inboxcur][0]) sqlExecute("UPDATE inbox SET read=0 WHERE msgid=?", inbox[inboxcur][0])
inbox[inboxcur][7] = 0 inbox[inboxcur][7] = 0
@ -298,7 +310,7 @@ def handlech(c, stdscr):
ischan = True ischan = True
break break
if not addresses[i][1]: if not addresses[i][1]:
d.scrollbox(unicode("Sending address disabled, please either enable it or choose a different address."), exit_label="Continue") scrollbox(d, unicode("Sending address disabled, please either enable it or choose a different address."))
return return
toaddr = m[2] toaddr = m[2]
if ischan: if ischan:
@ -329,9 +341,9 @@ def handlech(c, stdscr):
addrbook.append([label, addr]) addrbook.append([label, addr])
addrbook.reverse() addrbook.reverse()
else: else:
d.scrollbox(unicode("The selected address is already in the Address Book."), exit_label="Continue") scrollbox(d, unicode("The selected address is already in the Address Book."))
elif t == "5": # Save message elif t == "5": # Save message
d.set_background_title("Save \""+inbox[inboxcur][5]+"\" as text file") set_background_title(d, "Save \""+inbox[inboxcur][5]+"\" as text file")
r, t = d.inputbox("Filename", init=inbox[inboxcur][5]+".txt") r, t = d.inputbox("Filename", init=inbox[inboxcur][5]+".txt")
if r == d.DIALOG_OK: if r == d.DIALOG_OK:
msg = "" msg = ""
@ -343,25 +355,24 @@ def handlech(c, stdscr):
fh.write(msg) fh.write(msg)
fh.close() fh.close()
else: else:
d.scrollbox(unicode("Could not fetch message."), exit_label="Continue") scrollbox(d, unicode("Could not fetch message."))
elif t == "6": # Move to trash elif t == "6": # Move to trash
sqlExecute("UPDATE inbox SET folder='trash' WHERE msgid=?", inbox[inboxcur][0]) sqlExecute("UPDATE inbox SET folder='trash' WHERE msgid=?", inbox[inboxcur][0])
del inbox[inboxcur] del inbox[inboxcur]
d.scrollbox(unicode("Message moved to trash. There is no interface to view your trash, \nbut the message is still on disk if you are desperate to recover it."), scrollbox(d, unicode("Message moved to trash. There is no interface to view your trash, \nbut the message is still on disk if you are desperate to recover it."))
exit_label="Continue")
elif menutab == 2: elif menutab == 2:
a = "" a = ""
if addresses[addrcur][3] != 0: # if current address is a chan if addresses[addrcur][3] != 0: # if current address is a chan
a = addresses[addrcur][2] a = addresses[addrcur][2]
sendMessage(addresses[addrcur][2], a) sendMessage(addresses[addrcur][2], a)
elif menutab == 3: elif menutab == 3:
d.set_background_title("Sent Messages Dialog Box") set_background_title(d, "Sent Messages Dialog Box")
r, t = d.menu("Do what with \""+sentbox[sentcur][4]+"\" to \""+sentbox[sentcur][0]+"\"?", r, t = d.menu("Do what with \""+sentbox[sentcur][4]+"\" to \""+sentbox[sentcur][0]+"\"?",
choices=[("1", "View message"), choices=[("1", "View message"),
("2", "Move to trash")]) ("2", "Move to trash")])
if r == d.DIALOG_OK: if r == d.DIALOG_OK:
if t == "1": # View if t == "1": # View
d.set_background_title("\""+sentbox[sentcur][4]+"\" from \""+sentbox[sentcur][3]+"\" to \""+sentbox[sentcur][1]+"\"") set_background_title(d, "\""+sentbox[sentcur][4]+"\" from \""+sentbox[sentcur][3]+"\" to \""+sentbox[sentcur][1]+"\"")
data = "" data = ""
ret = sqlQuery("SELECT message FROM sent WHERE subject=? AND ackdata=?", sentbox[sentcur][4], sentbox[sentcur][6]) ret = sqlQuery("SELECT message FROM sent WHERE subject=? AND ackdata=?", sentbox[sentcur][4], sentbox[sentcur][6])
if ret != []: if ret != []:
@ -371,28 +382,31 @@ def handlech(c, stdscr):
msg = "" msg = ""
for i, item in enumerate(data.split("\n")): for i, item in enumerate(data.split("\n")):
msg += fill(item, replace_whitespace=False)+"\n" msg += fill(item, replace_whitespace=False)+"\n"
d.scrollbox(unicode(ascii(msg)), 30, 80, exit_label="Continue") scrollbox(d, unicode(ascii(msg)), 30, 80)
else: else:
d.scrollbox(unicode("Could not fetch message."), exit_label="Continue") scrollbox(d, unicode("Could not fetch message."))
elif t == "2": # Move to trash elif t == "2": # Move to trash
sqlExecute("UPDATE sent SET folder='trash' WHERE subject=? AND ackdata=?", sentbox[sentcur][4], sentbox[sentcur][6]) sqlExecute("UPDATE sent SET folder='trash' WHERE subject=? AND ackdata=?", sentbox[sentcur][4], sentbox[sentcur][6])
del sentbox[sentcur] del sentbox[sentcur]
d.scrollbox(unicode("Message moved to trash. There is no interface to view your trash, \nbut the message is still on disk if you are desperate to recover it."), scrollbox(d, unicode("Message moved to trash. There is no interface to view your trash, \nbut the message is still on disk if you are desperate to recover it."))
exit_label="Continue")
elif menutab == 4: elif menutab == 4:
d.set_background_title("Your Identities Dialog Box") set_background_title(d, "Your Identities Dialog Box")
r, t = d.menu("Do what with \""+addresses[addrcur][0]+"\" : \""+addresses[addrcur][2]+"\"?", if len(addresses) <= addrcur:
choices=[("1", "Create new address"), r, t = d.menu("Do what with addresses?",
("2", "Send a message from this address"), choices=[("1", "Create new address")])
("3", "Rename"), else:
("4", "Enable"), r, t = d.menu("Do what with \""+addresses[addrcur][0]+"\" : \""+addresses[addrcur][2]+"\"?",
("5", "Disable"), choices=[("1", "Create new address"),
("6", "Delete"), ("2", "Send a message from this address"),
("7", "Special address behavior")]) ("3", "Rename"),
("4", "Enable"),
("5", "Disable"),
("6", "Delete"),
("7", "Special address behavior")])
if r == d.DIALOG_OK: if r == d.DIALOG_OK:
if t == "1": # Create new address if t == "1": # Create new address
d.set_background_title("Create new address") set_background_title(d, "Create new address")
d.scrollbox(unicode("Here you may generate as many addresses as you like.\n" scrollbox(d, unicode("Here you may generate as many addresses as you like.\n"
"Indeed, creating and abandoning addresses is encouraged.\n" "Indeed, creating and abandoning addresses is encouraged.\n"
"Deterministic addresses have several pros and cons:\n" "Deterministic addresses have several pros and cons:\n"
"\nPros:\n" "\nPros:\n"
@ -401,14 +415,13 @@ def handlech(c, stdscr):
"Cons:\n" "Cons:\n"
" * You must remember (or write down) your passphrase in order to recreate \n your keys if they are lost\n" " * You must remember (or write down) your passphrase in order to recreate \n your keys if they are lost\n"
" * You must also remember the address version and stream numbers\n" " * You must also remember the address version and stream numbers\n"
" * If you choose a weak passphrase someone may be able to brute-force it \n and then send and receive messages as you"), " * If you choose a weak passphrase someone may be able to brute-force it \n and then send and receive messages as you"))
exit_label="Continue")
r, t = d.menu("Choose an address generation technique", r, t = d.menu("Choose an address generation technique",
choices=[("1", "Use a random number generator"), choices=[("1", "Use a random number generator"),
("2", "Use a passphrase")]) ("2", "Use a passphrase")])
if r == d.DIALOG_OK: if r == d.DIALOG_OK:
if t == "1": if t == "1":
d.set_background_title("Randomly generate address") set_background_title(d, "Randomly generate address")
r, t = d.inputbox("Label (not shown to anyone except you)") r, t = d.inputbox("Label (not shown to anyone except you)")
label = "" label = ""
if r == d.DIALOG_OK and len(t) > 0: if r == d.DIALOG_OK and len(t) > 0:
@ -428,12 +441,12 @@ def handlech(c, stdscr):
stream = decodeAddress(addrs[int(t)][1])[2] stream = decodeAddress(addrs[int(t)][1])[2]
shorten = False shorten = False
r, t = d.checklist("Miscellaneous options", r, t = d.checklist("Miscellaneous options",
choices=[("1", "Spend time shortening the address", shorten)]) choices=[("1", "Spend time shortening the address", 1 if shorten else 0)])
if r == d.DIALOG_OK and "1" in t: if r == d.DIALOG_OK and "1" in t:
shorten = True shorten = True
shared.addressGeneratorQueue.put(("createRandomAddress", 4, stream, label, 1, "", shorten)) shared.addressGeneratorQueue.put(("createRandomAddress", 4, stream, label, 1, "", shorten))
elif t == "2": elif t == "2":
d.set_background_title("Make deterministic addresses") set_background_title(d, "Make deterministic addresses")
r, t = d.passwordform("Enter passphrase", r, t = d.passwordform("Enter passphrase",
[("Passphrase", 1, 1, "", 2, 1, 64, 128), [("Passphrase", 1, 1, "", 2, 1, 64, 128),
("Confirm passphrase", 3, 1, "", 4, 1, 64, 128)], ("Confirm passphrase", 3, 1, "", 4, 1, 64, 128)],
@ -448,16 +461,15 @@ def handlech(c, stdscr):
stream = 1 stream = 1
shorten = False shorten = False
r, t = d.checklist("Miscellaneous options", r, t = d.checklist("Miscellaneous options",
choices=[("1", "Spend time shortening the address", shorten)]) choices=[("1", "Spend time shortening the address", 1 if shorten else 0)])
if r == d.DIALOG_OK and "1" in t: if r == d.DIALOG_OK and "1" in t:
shorten = True shorten = True
d.scrollbox(unicode("In addition to your passphrase, be sure to remember the following numbers:\n" scrollbox(d, unicode("In addition to your passphrase, be sure to remember the following numbers:\n"
"\n * Address version number: "+str(4)+"\n" "\n * Address version number: "+str(4)+"\n"
" * Stream number: "+str(stream)), " * Stream number: "+str(stream)))
exit_label="Continue")
shared.addressGeneratorQueue.put(('createDeterministicAddresses', 4, stream, "unused deterministic address", number, str(passphrase), shorten)) shared.addressGeneratorQueue.put(('createDeterministicAddresses', 4, stream, "unused deterministic address", number, str(passphrase), shorten))
else: else:
d.scrollbox(unicode("Passphrases do not match"), exit_label="Continue") scrollbox(d, unicode("Passphrases do not match"))
elif t == "2": # Send a message elif t == "2": # Send a message
a = "" a = ""
if addresses[addrcur][3] != 0: # if current address is a chan if addresses[addrcur][3] != 0: # if current address is a chan
@ -503,9 +515,9 @@ def handlech(c, stdscr):
del addresses[addrcur] del addresses[addrcur]
elif t == "7": # Special address behavior elif t == "7": # Special address behavior
a = addresses[addrcur][2] a = addresses[addrcur][2]
d.set_background_title("Special address behavior") set_background_title(d, "Special address behavior")
if shared.safeConfigGetBoolean(a, "chan"): if shared.safeConfigGetBoolean(a, "chan"):
d.scrollbox(unicode("This is a chan address. You cannot use it as a pseudo-mailing list."), exit_label="Continue") scrollbox(d, unicode("This is a chan address. You cannot use it as a pseudo-mailing list."))
else: else:
m = shared.safeConfigGetBoolean(a, "mailinglist") m = shared.safeConfigGetBoolean(a, "mailinglist")
r, t = d.radiolist("Select address behavior", r, t = d.radiolist("Select address behavior",
@ -532,12 +544,16 @@ def handlech(c, stdscr):
# Write config # Write config
shared.writeKeysFile() shared.writeKeysFile()
elif menutab == 5: elif menutab == 5:
d.set_background_title("Subscriptions Dialog Box") set_background_title(d, "Subscriptions Dialog Box")
r, t = d.menu("Do what with subscription to \""+subscriptions[subcur][0]+"\"?", if len(subscriptions) <= subcur:
choices=[("1", "Add new subscription"), r, t = d.menu("Do what with subscription to \""+subscriptions[subcur][0]+"\"?",
("2", "Delete this subscription"), choices=[("1", "Add new subscription")])
("3", "Enable"), else:
("4", "Disable")]) r, t = d.menu("Do what with subscription to \""+subscriptions[subcur][0]+"\"?",
choices=[("1", "Add new subscription"),
("2", "Delete this subscription"),
("3", "Enable"),
("4", "Disable")])
if r == d.DIALOG_OK: if r == d.DIALOG_OK:
if t == "1": if t == "1":
r, t = d.inputbox("New subscription address") r, t = d.inputbox("New subscription address")
@ -569,12 +585,16 @@ def handlech(c, stdscr):
shared.reloadBroadcastSendersForWhichImWatching() shared.reloadBroadcastSendersForWhichImWatching()
subscriptions[subcur][2] = False subscriptions[subcur][2] = False
elif menutab == 6: elif menutab == 6:
d.set_background_title("Address Book Dialog Box") set_background_title(d, "Address Book Dialog Box")
r, t = d.menu("Do what with \""+addrbook[abookcur][0]+"\" : \""+addrbook[abookcur][1]+"\"", if len(addrbook) <= abookcur:
choices=[("1", "Send a message to this address"), r, t = d.menu("Do what with addressbook?",
("2", "Subscribe to this address"), choices=[("3", "Add new address to Address Book")])
("3", "Add new address to Address Book"), else:
("4", "Delete this address")]) r, t = d.menu("Do what with \""+addrbook[abookcur][0]+"\" : \""+addrbook[abookcur][1]+"\"",
choices=[("1", "Send a message to this address"),
("2", "Subscribe to this address"),
("3", "Add new address to Address Book"),
("4", "Delete this address")])
if r == d.DIALOG_OK: if r == d.DIALOG_OK:
if t == "1": if t == "1":
sendMessage(recv=addrbook[abookcur][1]) sendMessage(recv=addrbook[abookcur][1])
@ -602,14 +622,14 @@ def handlech(c, stdscr):
addrbook.append([t, addr]) addrbook.append([t, addr])
addrbook.reverse() addrbook.reverse()
else: else:
d.scrollbox(unicode("The selected address is already in the Address Book."), exit_label="Continue") scrollbox(d, unicode("The selected address is already in the Address Book."))
elif t == "4": elif t == "4":
r, t = d.inputbox("Type in \"I want to delete this Address Book entry\"") r, t = d.inputbox("Type in \"I want to delete this Address Book entry\"")
if r == d.DIALOG_OK and t == "I want to delete this Address Book entry": if r == d.DIALOG_OK and t == "I want to delete this Address Book entry":
sqlExecute("DELETE FROM addressbook WHERE label=? AND address=?", addrbook[abookcur][0], addrbook[abookcur][1]) sqlExecute("DELETE FROM addressbook WHERE label=? AND address=?", addrbook[abookcur][0], addrbook[abookcur][1])
del addrbook[abookcur] del addrbook[abookcur]
elif menutab == 7: elif menutab == 7:
d.set_background_title("Blacklist Dialog Box") set_background_title(d, "Blacklist Dialog Box")
r, t = d.menu("Do what with \""+blacklist[blackcur][0]+"\" : \""+blacklist[blackcur][1]+"\"?", r, t = d.menu("Do what with \""+blacklist[blackcur][0]+"\" : \""+blacklist[blackcur][1]+"\"?",
choices=[("1", "Delete"), choices=[("1", "Delete"),
("2", "Enable"), ("2", "Enable"),
@ -685,7 +705,7 @@ def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=F
if sender == "": if sender == "":
return return
d = Dialog(dialog="dialog") d = Dialog(dialog="dialog")
d.set_background_title("Send a message") set_background_title(d, "Send a message")
if recv == "": if recv == "":
r, t = d.inputbox("Recipient address (Cancel to load from the Address Book or leave blank to broadcast)", 10, 60) r, t = d.inputbox("Recipient address (Cancel to load from the Address Book or leave blank to broadcast)", 10, 60)
if r != d.DIALOG_OK: if r != d.DIALOG_OK:
@ -695,8 +715,8 @@ def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=F
recv = t recv = t
if broadcast == None and sender != recv: if broadcast == None and sender != recv:
r, t = d.radiolist("How to send the message?", r, t = d.radiolist("How to send the message?",
choices=[("1", "Send to one or more specific people", True), choices=[("1", "Send to one or more specific people", 1),
("2", "Broadcast to everyone who is subscribed to your address", False)]) ("2", "Broadcast to everyone who is subscribed to your address", 0)])
if r != d.DIALOG_OK: if r != d.DIALOG_OK:
return return
broadcast = False broadcast = False
@ -723,7 +743,7 @@ def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=F
if addr != "": if addr != "":
status, version, stream, ripe = decodeAddress(addr) status, version, stream, ripe = decodeAddress(addr)
if status != "success": if status != "success":
d.set_background_title("Recipient address error") set_background_title(d, "Recipient address error")
err = "Could not decode" + addr + " : " + status + "\n\n" err = "Could not decode" + addr + " : " + status + "\n\n"
if status == "missingbm": if status == "missingbm":
err += "Bitmessage addresses should start with \"BM-\"." err += "Bitmessage addresses should start with \"BM-\"."
@ -741,23 +761,20 @@ def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=F
err += "Some data encoded in the address is malformed. There might be something wrong with the software of your acquaintance." err += "Some data encoded in the address is malformed. There might be something wrong with the software of your acquaintance."
else: else:
err += "It is unknown what is wrong with the address." err += "It is unknown what is wrong with the address."
d.scrollbox(unicode(err), exit_label="Continue") scrollbox(d, unicode(err))
else: else:
addr = addBMIfNotPresent(addr) addr = addBMIfNotPresent(addr)
if version > 4 or version <= 1: if version > 4 or version <= 1:
d.set_background_title("Recipient address error") set_background_title(d, "Recipient address error")
d.scrollbox(unicode("Could not understand version number " + version + "of address" + addr + "."), scrollbox(d, unicode("Could not understand version number " + version + "of address" + addr + "."))
exit_label="Continue")
continue continue
if stream > 1 or stream == 0: if stream > 1 or stream == 0:
d.set_background_title("Recipient address error") set_background_title(d, "Recipient address error")
d.scrollbox(unicode("Bitmessage currently only supports stream numbers of 1, unlike as requested for address " + addr + "."), scrollbox(d, unicode("Bitmessage currently only supports stream numbers of 1, unlike as requested for address " + addr + "."))
exit_label="Continue")
continue continue
if len(shared.connectedHostsList) == 0: if len(shared.connectedHostsList) == 0:
d.set_background_title("Not connected warning") set_background_title(d, "Not connected warning")
d.scrollbox(unicode("Because you are not currently connected to the network, "), scrollbox(d, unicode("Because you are not currently connected to the network, "))
exit_label="Continue")
ackdata = OpenSSL.rand(32) ackdata = OpenSSL.rand(32)
sqlExecute( sqlExecute(
"INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", "INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
@ -779,9 +796,8 @@ def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=F
shared.workerQueue.put(("sendmessage", addr)) shared.workerQueue.put(("sendmessage", addr))
else: # Broadcast else: # Broadcast
if recv == "": if recv == "":
d.set_background_title("Empty sender error") set_background_title(d, "Empty sender error")
d.scrollbox(unicode("You must specify an address to send the message from."), scrollbox(d, unicode("You must specify an address to send the message from."))
exit_label="Continue")
else: else:
ackdata = OpenSSL.rand(32) ackdata = OpenSSL.rand(32)
recv = BROADCAST_STR recv = BROADCAST_STR