2018-07-18 14:49:39 +02:00
|
|
|
import os
|
2018-08-07 08:14:14 +02:00
|
|
|
import kivy_helper_search
|
2018-07-24 14:42:53 +02:00
|
|
|
import queues
|
2018-08-04 10:30:12 +02:00
|
|
|
import random
|
2018-07-25 12:25:47 +02:00
|
|
|
import shutdown
|
|
|
|
import time
|
|
|
|
|
2018-07-09 13:17:59 +02:00
|
|
|
from kivy.app import App
|
2018-07-18 14:49:39 +02:00
|
|
|
from kivy.lang import Builder
|
2018-07-24 12:05:39 +02:00
|
|
|
from kivy.uix.boxlayout import BoxLayout
|
2018-07-24 14:42:53 +02:00
|
|
|
from kivy.properties import BooleanProperty
|
2018-08-04 10:30:12 +02:00
|
|
|
from kivy.uix.button import Button
|
2018-07-25 12:25:47 +02:00
|
|
|
from kivy.clock import Clock
|
2018-08-04 10:30:12 +02:00
|
|
|
from kivy.uix.floatlayout import FloatLayout
|
|
|
|
from kivy.uix.image import Image
|
2018-07-18 14:49:39 +02:00
|
|
|
from kivy.uix.label import Label
|
2018-08-04 10:30:12 +02:00
|
|
|
from kivy.uix.listview import ListItemButton
|
2018-07-25 12:25:47 +02:00
|
|
|
from navigationdrawer import NavigationDrawer
|
2018-08-04 10:30:12 +02:00
|
|
|
from kivy.properties import ObjectProperty, StringProperty, ListProperty, NumericProperty
|
2018-07-25 12:25:47 +02:00
|
|
|
from kivy.uix.screenmanager import Screen
|
2018-07-18 14:49:39 +02:00
|
|
|
from kivy.uix.textinput import TextInput
|
2018-07-25 12:25:47 +02:00
|
|
|
from kivymd.theming import ThemeManager
|
|
|
|
from kivymd.toolbar import Toolbar
|
|
|
|
from kivy.uix.widget import Widget
|
2018-07-24 12:05:39 +02:00
|
|
|
from bmconfigparser import BMConfigParser
|
2018-07-24 14:42:53 +02:00
|
|
|
from helper_ackPayload import genAckPayload
|
|
|
|
from addresses import decodeAddress, addBMIfNotPresent
|
2018-08-07 08:14:14 +02:00
|
|
|
from helper_sql import sqlExecute, sqlQuery
|
2018-07-24 12:05:39 +02:00
|
|
|
statusIconColor = 'red'
|
2018-08-04 10:30:12 +02:00
|
|
|
avatarlist = os.listdir("images/ngletteravatar")
|
2018-08-09 12:20:20 +02:00
|
|
|
global belonging
|
|
|
|
belonging = ''
|
2018-07-24 12:05:39 +02:00
|
|
|
|
2018-07-07 14:11:58 +02:00
|
|
|
|
2018-07-24 12:05:39 +02:00
|
|
|
class NavigateApp(App, TextInput):
|
2018-07-18 14:49:39 +02:00
|
|
|
theme_cls = ThemeManager()
|
|
|
|
nav_drawer = ObjectProperty()
|
2018-07-03 11:08:02 +02:00
|
|
|
|
2018-07-18 14:49:39 +02:00
|
|
|
def build(self):
|
2018-08-09 12:20:20 +02:00
|
|
|
global main_widget
|
2018-07-24 14:42:53 +02:00
|
|
|
main_widget = Builder.load_file(
|
|
|
|
os.path.join(os.path.dirname(__file__), 'main.kv'))
|
2018-07-18 14:49:39 +02:00
|
|
|
self.nav_drawer = Navigator()
|
|
|
|
return main_widget
|
2018-07-03 12:06:20 +02:00
|
|
|
|
2018-08-09 12:20:20 +02:00
|
|
|
def getCurrentAccountData(self, text):
|
|
|
|
global belonging
|
|
|
|
belonging = text
|
|
|
|
main_widget.ids.sc1.clear_widgets()
|
|
|
|
main_widget.ids.sc2.clear_widgets()
|
|
|
|
main_widget.ids.sc1.add_widget(Inbox())
|
|
|
|
main_widget.ids.sc2.add_widget(Sent())
|
|
|
|
Inbox()
|
|
|
|
Sent()
|
2018-08-07 08:14:14 +02:00
|
|
|
|
2018-07-18 14:49:39 +02:00
|
|
|
def say_exit(self):
|
2018-07-24 14:42:53 +02:00
|
|
|
print("**************************EXITING FROM APPLICATION*****************************")
|
2018-07-18 14:49:39 +02:00
|
|
|
App.get_running_app().stop()
|
|
|
|
shutdown.doCleanShutdown()
|
2018-07-03 12:06:20 +02:00
|
|
|
|
2018-08-07 08:14:14 +02:00
|
|
|
def showmeaddresses(self, name="text"):
|
|
|
|
if name == "text":
|
|
|
|
return BMConfigParser().addresses()[0]
|
|
|
|
elif name == "values":
|
|
|
|
return BMConfigParser().addresses()
|
2018-08-04 10:30:12 +02:00
|
|
|
|
2018-07-24 12:05:39 +02:00
|
|
|
|
2018-07-18 14:49:39 +02:00
|
|
|
class Navigator(NavigationDrawer):
|
2018-08-04 10:30:12 +02:00
|
|
|
image_source = StringProperty('images/qidenticon_two.png')
|
2018-07-18 14:49:39 +02:00
|
|
|
title = StringProperty('Navigation')
|
2018-07-03 12:06:20 +02:00
|
|
|
|
|
|
|
|
2018-07-18 14:49:39 +02:00
|
|
|
class Inbox(Screen):
|
2018-08-04 10:30:12 +02:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super(Inbox, self).__init__(*args, **kwargs)
|
2018-08-09 12:20:20 +02:00
|
|
|
global belonging
|
|
|
|
if belonging == '':
|
|
|
|
belonging = Navigator().ids.btn.text
|
2018-08-04 10:30:12 +02:00
|
|
|
Clock.schedule_once(self.init_ui, 0)
|
|
|
|
|
|
|
|
def init_ui(self, dt=0):
|
2018-08-09 12:20:20 +02:00
|
|
|
global belonging
|
2018-08-04 10:30:12 +02:00
|
|
|
self.orientation = "vertical"
|
2018-08-09 12:20:20 +02:00
|
|
|
self.inboxaccounts(self.ids.box_share)
|
2018-08-04 10:30:12 +02:00
|
|
|
|
2018-08-09 12:20:20 +02:00
|
|
|
def inboxaccounts(self, box_share):
|
|
|
|
account = belonging
|
2018-08-07 08:14:14 +02:00
|
|
|
folder = 'inbox'
|
2018-08-09 12:20:20 +02:00
|
|
|
self.loadinboxlist(account, folder, box_share, 'All', '')
|
2018-08-07 08:14:14 +02:00
|
|
|
|
2018-08-09 12:20:20 +02:00
|
|
|
def loadinboxlist(self, account, folder, box_share, where="", what="", unreadOnly=False):
|
2018-08-04 10:30:12 +02:00
|
|
|
top_logo_share = 1.01
|
|
|
|
top_button_share = 1.1
|
|
|
|
top_label_share = 1.4
|
2018-08-07 08:14:14 +02:00
|
|
|
xAddress = "toaddress"
|
|
|
|
|
|
|
|
queryreturn = kivy_helper_search.search_sql(xAddress, account, folder, where, what, unreadOnly)
|
|
|
|
if queryreturn:
|
|
|
|
for row in queryreturn:
|
|
|
|
msgfolder, msgid, toAddress, fromAddress, subject, received, read = row
|
|
|
|
top_logo_share -= .4
|
|
|
|
top_button_share -= .4
|
|
|
|
top_label_share -= .4
|
|
|
|
logo_share = \
|
2018-08-09 12:20:20 +02:00
|
|
|
Image(source='images/ngletteravatar/{}'.format(self.getletterimage(avatarlist, subject)),
|
2018-08-07 08:14:14 +02:00
|
|
|
pos_hint={"center_x": .05, "top": top_logo_share},
|
|
|
|
size_hint_y=None, height=25)
|
|
|
|
button_share = \
|
|
|
|
Button(pos_hint={"x": 0, "top": top_button_share},
|
|
|
|
size_hint_y=None, height=40, text=subject, multiline=True, background_color=NavigateApp.theme_cls.primary_dark)
|
2018-08-09 12:20:20 +02:00
|
|
|
button_share.bind(on_press=self.getInboxMessageDetail)
|
2018-08-07 08:14:14 +02:00
|
|
|
fl = FloatLayout(size_hint_y=None, height=25)
|
|
|
|
fl.add_widget(button_share)
|
|
|
|
fl.add_widget(logo_share)
|
|
|
|
box_share.add_widget(fl)
|
|
|
|
else:
|
2018-08-04 10:30:12 +02:00
|
|
|
label_share = \
|
2018-08-07 08:14:14 +02:00
|
|
|
Label(text="yet you dont have any emails received", pos_hint={"x": 0, "top": top_label_share},
|
2018-08-04 10:30:12 +02:00
|
|
|
size_hint_y=None)
|
2018-08-07 08:14:14 +02:00
|
|
|
box_share.add_widget(label_share)
|
|
|
|
|
2018-08-09 12:20:20 +02:00
|
|
|
def getletterimage(self, ran, subject):
|
2018-08-07 08:14:14 +02:00
|
|
|
limit = 5
|
|
|
|
for x in subject[:limit]:
|
|
|
|
if '{}.png'.format(x.lower()) in ran:
|
|
|
|
return '{}.png'.format(x.lower())
|
|
|
|
elif '{}.jpg'.format(x.lower()) in ran:
|
|
|
|
return '{}.jpg'.format(x.lower())
|
|
|
|
if x == limit:
|
|
|
|
random.shuffle(ran)
|
|
|
|
return ran[0]
|
|
|
|
break
|
2018-08-04 10:30:12 +02:00
|
|
|
|
2018-08-09 12:20:20 +02:00
|
|
|
def getInboxMessageDetail(self, instance):
|
|
|
|
try:
|
|
|
|
self.manager.current = 'page'
|
|
|
|
except AttributeError:
|
|
|
|
self.parent.manager.current = 'page'
|
2018-08-04 10:30:12 +02:00
|
|
|
print('I am {}'.format(instance.text))
|
|
|
|
|
|
|
|
|
|
|
|
class Page(Screen):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class AddressSuccessful(Screen):
|
|
|
|
pass
|
2018-07-03 11:08:02 +02:00
|
|
|
|
2018-07-24 12:05:39 +02:00
|
|
|
|
2018-07-18 14:49:39 +02:00
|
|
|
class Sent(Screen):
|
2018-08-09 12:20:20 +02:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super(Sent, self).__init__(*args, **kwargs)
|
|
|
|
global belonging
|
|
|
|
if belonging == '':
|
|
|
|
belonging = Navigator().ids.btn.text
|
|
|
|
Clock.schedule_once(self.init_ui, 0)
|
|
|
|
|
|
|
|
def init_ui(self, dt=0):
|
|
|
|
global belonging
|
|
|
|
self.orientation = "vertical"
|
|
|
|
self.sentaccounts(self.ids.box_share)
|
|
|
|
|
|
|
|
def sentaccounts(self, box_share):
|
|
|
|
account = belonging
|
|
|
|
folder = 'inbox'
|
|
|
|
self.loadSent(account, box_share, 'All', '')
|
|
|
|
|
|
|
|
def loadSent(self, account, box_share, where="", what=""):
|
|
|
|
top_logo_share = 1.01
|
|
|
|
top_button_share = 1.1
|
|
|
|
top_label_share = 1.4
|
|
|
|
xAddress = 'fromaddress'
|
|
|
|
queryreturn = kivy_helper_search.search_sql(xAddress, account, "sent", where, what, False)
|
|
|
|
if queryreturn:
|
|
|
|
for row in queryreturn:
|
|
|
|
toAddress, fromAddress, subject, status, ackdata, lastactiontime = row
|
|
|
|
top_logo_share -= .4
|
|
|
|
top_button_share -= .4
|
|
|
|
top_label_share -= .4
|
|
|
|
logo_share = \
|
|
|
|
Image(source='images/ngletteravatar/{}'.format(self.getletterimage(avatarlist, subject)),
|
|
|
|
pos_hint={"center_x": .05, "top": top_logo_share},
|
|
|
|
size_hint_y=None, height=25)
|
|
|
|
button_share = \
|
|
|
|
Button(pos_hint={"x": 0, "top": top_button_share},
|
|
|
|
size_hint_y=None, height=40, text=subject, multiline=True, background_color=NavigateApp.theme_cls.primary_dark)
|
|
|
|
button_share.bind(on_press=self.getSentMessageDetail)
|
|
|
|
fl = FloatLayout(size_hint_y=None, height=25)
|
|
|
|
fl.add_widget(button_share)
|
|
|
|
fl.add_widget(logo_share)
|
|
|
|
box_share.add_widget(fl)
|
|
|
|
else:
|
|
|
|
label_share = \
|
|
|
|
Label(text="yet you dont have any emails received", pos_hint={"x": 0, "top": top_label_share},
|
|
|
|
size_hint_y=None)
|
|
|
|
box_share.add_widget(label_share)
|
|
|
|
|
|
|
|
def getletterimage(self, ran, subject):
|
|
|
|
limit = 5
|
|
|
|
for x in subject[:limit]:
|
|
|
|
if '{}.png'.format(x.lower()) in ran:
|
|
|
|
return '{}.png'.format(x.lower())
|
|
|
|
elif '{}.jpg'.format(x.lower()) in ran:
|
|
|
|
return '{}.jpg'.format(x.lower())
|
|
|
|
if x == limit:
|
|
|
|
random.shuffle(ran)
|
|
|
|
return ran[0]
|
|
|
|
break
|
|
|
|
|
|
|
|
def getSentMessageDetail(self, instance):
|
|
|
|
try:
|
|
|
|
self.manager.current = 'page'
|
|
|
|
except AttributeError:
|
|
|
|
self.parent.manager.current = 'page'
|
|
|
|
print('I am {}'.format(instance.text))
|
2018-07-03 11:08:02 +02:00
|
|
|
|
2018-07-24 12:05:39 +02:00
|
|
|
|
2018-07-18 14:49:39 +02:00
|
|
|
class Trash(Screen):
|
2018-07-24 12:05:39 +02:00
|
|
|
def __init__(self, **kwargs):
|
|
|
|
super(Trash, self).__init__(**kwargs)
|
2018-07-19 13:47:37 +02:00
|
|
|
val_y = .1
|
|
|
|
val_z = 0
|
|
|
|
my_box1 = BoxLayout(orientation='vertical')
|
|
|
|
for i in range(1, 5):
|
2018-07-24 14:42:53 +02:00
|
|
|
my_box1.add_widget(Label(text="I am in trash", size_hint=(.3, .1), pos_hint={
|
|
|
|
'x': val_z, 'top': val_y}, color=(0, 0, 0, 1), background_color=(0, 0, 0, 0)))
|
2018-07-24 12:05:39 +02:00
|
|
|
val_y += .1
|
2018-07-19 13:47:37 +02:00
|
|
|
self.add_widget(my_box1)
|
2018-07-03 11:08:02 +02:00
|
|
|
|
|
|
|
|
2018-07-18 14:49:39 +02:00
|
|
|
class Dialog(Screen):
|
|
|
|
pass
|
2018-07-03 11:08:02 +02:00
|
|
|
|
|
|
|
|
2018-07-18 14:49:39 +02:00
|
|
|
class Test(Screen):
|
|
|
|
pass
|
2018-07-03 11:08:02 +02:00
|
|
|
|
2018-07-07 14:11:58 +02:00
|
|
|
|
2018-08-04 10:30:12 +02:00
|
|
|
class Create(Screen):
|
2018-07-24 12:05:39 +02:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super(Create, self).__init__(*args, **kwargs)
|
|
|
|
Clock.schedule_once(self.init_ui, 0)
|
|
|
|
|
|
|
|
def init_ui(self, dt=0):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def send(self):
|
2018-07-24 14:42:53 +02:00
|
|
|
# toAddress = self.ids.recipent.text
|
|
|
|
fromAddress = self.ids.spinner_id.text
|
|
|
|
# For now we are using static address i.e we are not using recipent field value.
|
|
|
|
toAddress = "BM-2cWyUfBdY2FbgyuCb7abFZ49JYxSzUhNFe"
|
|
|
|
message = self.ids.message.text
|
|
|
|
subject = self.ids.subject.text
|
|
|
|
encoding = 3
|
|
|
|
print("message: ", self.ids.message.text)
|
|
|
|
sendMessageToPeople = True
|
|
|
|
if sendMessageToPeople:
|
|
|
|
if toAddress != '':
|
|
|
|
status, addressVersionNumber, streamNumber, ripe = decodeAddress(
|
|
|
|
toAddress)
|
|
|
|
if status == 'success':
|
|
|
|
toAddress = addBMIfNotPresent(toAddress)
|
|
|
|
|
|
|
|
if addressVersionNumber > 4 or addressVersionNumber <= 1:
|
|
|
|
print("addressVersionNumber > 4 or addressVersionNumber <= 1")
|
|
|
|
if streamNumber > 1 or streamNumber == 0:
|
|
|
|
print("streamNumber > 1 or streamNumber == 0")
|
|
|
|
if statusIconColor == 'red':
|
|
|
|
print("shared.statusIconColor == 'red'")
|
|
|
|
stealthLevel = BMConfigParser().safeGetInt(
|
|
|
|
'bitmessagesettings', 'ackstealthlevel')
|
|
|
|
ackdata = genAckPayload(streamNumber, stealthLevel)
|
|
|
|
t = ()
|
|
|
|
sqlExecute(
|
|
|
|
'''INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)''',
|
|
|
|
'',
|
|
|
|
toAddress,
|
|
|
|
ripe,
|
|
|
|
fromAddress,
|
|
|
|
subject,
|
|
|
|
message,
|
|
|
|
ackdata,
|
|
|
|
int(time.time()),
|
|
|
|
int(time.time()),
|
|
|
|
0,
|
|
|
|
'msgqueued',
|
|
|
|
0,
|
|
|
|
'sent',
|
|
|
|
encoding,
|
|
|
|
BMConfigParser().getint('bitmessagesettings', 'ttl'))
|
|
|
|
toLabel = ''
|
|
|
|
queues.workerQueue.put(('sendmessage', toAddress))
|
|
|
|
print("sqlExecute successfully ##### ##################")
|
|
|
|
self.ids.message.text = ''
|
|
|
|
self.ids.spinner_id.text = '<select>'
|
|
|
|
self.ids.subject.text = ''
|
|
|
|
self.ids.recipent.text = ''
|
|
|
|
return None
|
|
|
|
|
|
|
|
def cancel(self):
|
|
|
|
self.ids.message.text = ''
|
|
|
|
self.ids.spinner_id.text = '<select>'
|
|
|
|
self.ids.subject.text = ''
|
|
|
|
self.ids.recipent.text = ''
|
|
|
|
return None
|
2018-07-24 12:05:39 +02:00
|
|
|
|
|
|
|
|
|
|
|
class NewIdentity(Screen):
|
|
|
|
is_active = BooleanProperty(False)
|
2018-08-04 10:30:12 +02:00
|
|
|
checked = StringProperty("")
|
|
|
|
|
|
|
|
def generateaddress(self):
|
|
|
|
if self.checked == 'use a random number generator to make an address':
|
|
|
|
queues.apiAddressGeneratorReturnQueue.queue.clear()
|
|
|
|
streamNumberForAddress = 1
|
|
|
|
label = self.ids.label.text
|
|
|
|
eighteenByteRipe = False
|
|
|
|
nonceTrialsPerByte = 1000
|
|
|
|
payloadLengthExtraBytes = 1000
|
|
|
|
queues.addressGeneratorQueue.put((
|
|
|
|
'createRandomAddress', 4, streamNumberForAddress, label, 1, "", eighteenByteRipe, nonceTrialsPerByte, payloadLengthExtraBytes)
|
|
|
|
)
|
|
|
|
self.manager.current = 'add_sucess'
|
2018-07-24 14:42:53 +02:00
|
|
|
|
2018-07-18 14:49:39 +02:00
|
|
|
if __name__ == '__main__':
|
2018-07-24 14:42:53 +02:00
|
|
|
NavigateApp().run()
|