Add a curses terminal interface as an alternative to QT #666

Merged
lwizchz merged 11 commits from master into master 2014-07-14 20:06:21 +02:00
Showing only changes of commit d4327cef81 - Show all commits

View File

@ -10,6 +10,7 @@
import os import os
import sys import sys
import StringIO import StringIO
from textwrap import *
import time import time
from time import strftime, localtime from time import strftime, localtime
@ -246,6 +247,7 @@ def dialogreset(stdscr):
curses.curs_set(0) curses.curs_set(0)
def handlech(c, stdscr): def handlech(c, stdscr):
if c != curses.ERR: if c != curses.ERR:
global inboxcur, addrcur, sentcur, subcur, abookcur, blackcur
if c in range(256): if c in range(256):
if chr(c) in '12345678': if chr(c) in '12345678':
global menutab global menutab
@ -268,13 +270,16 @@ def handlech(c, stdscr):
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]+"\"") d.set_background_title("\""+inbox[inboxcur][5]+"\" from \""+inbox[inboxcur][3]+"\" to \""+inbox[inboxcur][1]+"\"")
msg = "" 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 != []:
for row in ret: for row in ret:
msg, = row data, = row
msg = shared.fixPotentiallyInvalidUTF8Data(msg) data = shared.fixPotentiallyInvalidUTF8Data(data)
d.scrollbox(unicode(ascii(msg)), 30, 100, exit_label="Continue") msg = ""
for i, item in enumerate(data.split("\n")):
msg += fill(item, replace_whitespace=False)+"\n"
d.scrollbox(unicode(ascii(msg)), 30, 80, exit_label="Continue")
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:
@ -311,12 +316,17 @@ def handlech(c, stdscr):
sendMessage(fromaddr, toaddr, ischan, subject, body, True) sendMessage(fromaddr, toaddr, ischan, subject, body, True)
dialogreset(stdscr) dialogreset(stdscr)
elif t == "4": # Add to Address Book elif t == "4": # Add to Address Book
global addrbook
addr = inbox[inboxcur][4] addr = inbox[inboxcur][4]
if addr not in [item[1] for i,item in enumerate(addrbook)]: if addr not in [item[1] for i,item in enumerate(addrbook)]:
r, t = d.inputbox("Label for address \""+addr+"\"") r, t = d.inputbox("Label for address \""+addr+"\"")
if r == d.DIALOG_OK: if r == d.DIALOG_OK:
sqlExecute("INSERT INTO addressbook VALUES (?,?)", t, addr) label = t
addrbook.reverse().append([t, addr]).reverse() # Prepend new entry sqlExecute("INSERT INTO addressbook VALUES (?,?)", label, addr)
# Prepend entry
addrbook.reverse()
addrbook.append([label, addr])
addrbook.reverse()
else: else:
d.scrollbox(unicode("The selected address is already in the Address Book."), exit_label="Continue") d.scrollbox(unicode("The selected address is already in the Address Book."), exit_label="Continue")
elif t == "5": # Save message elif t == "5": # Save message
@ -348,13 +358,16 @@ def handlech(c, stdscr):
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]+"\"") d.set_background_title("\""+sentbox[sentcur][4]+"\" from \""+sentbox[sentcur][3]+"\" to \""+sentbox[sentcur][1]+"\"")
msg = "" 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 != []:
for row in ret: for row in ret:
msg, = row data, = row
msg = shared.fixPotentiallyInvalidUTF8Data(msg) data = shared.fixPotentiallyInvalidUTF8Data(data)
d.scrollbox(unicode(ascii(msg)), 30, 100, exit_label="Continue") msg = ""
for i, item in enumerate(data.split("\n")):
msg += fill(item, replace_whitespace=False)+"\n"
d.scrollbox(unicode(ascii(msg)), 30, 80, exit_label="Continue")
else: else:
d.scrollbox(unicode("Could not fetch message."), exit_label="Continue") d.scrollbox(unicode("Could not fetch message."), exit_label="Continue")
elif t == "2": # Move to trash elif t == "2": # Move to trash
@ -602,7 +615,6 @@ def handlech(c, stdscr):
blacklist[blackcur][2] = False blacklist[blackcur][2] = False
dialogreset(stdscr) dialogreset(stdscr)
else: else:
global addrcur, inboxcur, sentcur, subcur, abookcur, blackcur
if c == curses.KEY_UP: if c == curses.KEY_UP:
if menutab == 1 and inboxcur > 0: if menutab == 1 and inboxcur > 0:
inboxcur -= 1 inboxcur -= 1
@ -681,12 +693,13 @@ def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=F
r, t = d.inputbox("Message subject", width=60, init=subject) r, t = d.inputbox("Message subject", width=60, init=subject)
if r != d.DIALOG_OK: if r != d.DIALOG_OK:
return return
subject = shared.fixPotentiallyInvalidUTF8Data(t) subject = t
if body == "" or reply: if body == "" or reply:
r, t = d.inputbox("Message body", 10, 80, init=body) r, t = d.inputbox("Message body", 10, 80, init=body)
if r != d.DIALOG_OK: if r != d.DIALOG_OK:
return return
body = shared.fixPotentiallyInvalidUTF8Data(t) body = t
body = body.replace("\\n", "\n").replace("\\t", "\t")
if not broadcast: if not broadcast:
recvlist = [] recvlist = []
@ -730,7 +743,6 @@ def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=F
d.set_background_title("Not connected warning") d.set_background_title("Not connected warning")
d.scrollbox(unicode("Because you are not currently connected to the network, "), d.scrollbox(unicode("Because you are not currently connected to the network, "),
exit_label="Continue") exit_label="Continue")
ackdata = OpenSSL.rand(32) ackdata = OpenSSL.rand(32)
sqlExecute( sqlExecute(
"INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)", "INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)",