Compare commits

...

9 Commits

Author SHA1 Message Date
navjot 8ad43c2fcd
added fake address list 2021-04-08 17:41:17 +05:30
navjot a59b25f1ca
added .travis-kivy.yml for runnig kivy test cases 2021-04-08 15:24:38 +05:30
navjot b7d68db7f2
added fake_addressGenerator module 2021-04-06 15:11:25 +05:30
navjot e333b26588
fixed kivymd latest update issues 2021-04-06 15:11:25 +05:30
navjot cb3fa3b510
added test cases 2021-04-06 15:11:25 +05:30
navjot 6aee6f12d5
fixed app crashing issues 2021-04-06 15:11:25 +05:30
navjot ebb350b81b
split mpybit module into multiple files and added working test with it 2021-04-06 15:11:25 +05:30
navjot 81eb365e97
remove internationalization, identiconGeneration and bitmsghash 2021-04-06 15:11:25 +05:30
navjot 410924aa00
added kivy app code and telenium test cases 2021-04-06 15:11:25 +05:30
64 changed files with 7441 additions and 1 deletions

15
.travis-kivy.yml Normal file
View File

@ -0,0 +1,15 @@
language: python3.7
cache: pip3
dist: bionic
python:
- "3.7"
addons:
apt:
packages:
- build-essential
- libcap-dev
- xvfb
install:
- pip3 install -r kivy-requirements.txt
script:
- python3 src/tests-kivy.py

View File

@ -14,6 +14,8 @@ RUN add-apt-repository ppa:deadsnakes/ppa
RUN apt-get -y install sudo
RUN apt-get -y install git
RUN apt-get install -yq --no-install-suggests --no-install-recommends \
# travis xenial bionic
python-setuptools libssl-dev libpq-dev python-prctl python-dev \
@ -61,4 +63,6 @@ ENV LC_ALL en_US.UTF-8
WORKDIR /home/builder/src
ENTRYPOINT /usr/local/bin/travis2bash.sh
# ENTRYPOINT /usr/local/bin/travis2bash.sh
ENTRYPOINT ["/usr/local/bin/travis2bash.sh", ".travis-kivy.yml"]

34
kivy-requirements.txt Normal file
View File

@ -0,0 +1,34 @@
certifi==2020.12.5
chardet==4.0.0
cheroot==8.5.2
CherryPy==18.6.0
docutils==0.16
idna==2.10
jaraco.classes==3.2.1
jaraco.collections==3.2.0
jaraco.functools==3.2.1
jaraco.text==3.5.0
json-rpc==1.13.0
Kivy==2.0.0
Kivy-Garden==0.1.4
kivy-garden.qrcode==2021.314
-e git+https://github.com/kivymd/KivyMD#egg=kivymd
Mako==1.1.4
MarkupSafe==1.1.1
more-itertools==8.7.0
numpy==1.20.1
opencv-python==4.5.1.48
Pillow==8.1.2
portend==2.7.1
Pygments==2.8.1
pytz==2021.1
pyzbar==0.1.8
qrcode==6.1
requests==2.25.1
six==1.15.0
telenium==0.5.0
tempora==4.0.1
urllib3==1.26.4
Werkzeug==1.0.1
ws4py==0.5.1
zc.lockfile==2.0

View File

View File

@ -0,0 +1,192 @@
from bitmessagekivy.get_platform import platform
from bitmessagekivy import kivy_helper_search
from helper_sql import sqlExecute
from functools import partial
from kivy.clock import Clock
from kivy.properties import (
ListProperty,
StringProperty
)
from kivy.uix.button import Button
from kivymd.uix.button import MDRaisedButton
from kivy.uix.carousel import Carousel
from kivymd.uix.dialog import MDDialog
from kivymd.uix.label import MDLabel
from kivymd.uix.list import TwoLineAvatarIconListItem
from kivy.uix.screenmanager import Screen
import state
from bitmessagekivy.baseclass.common import (
AvatarSampleWidget, avatarImageFirstLetter, toast,
ThemeClsColor,
)
from bitmessagekivy.baseclass.popup import AddbookDetailPopup
class AddressBook(Screen):
"""AddressBook Screen class for kivy Ui"""
queryreturn = ListProperty()
has_refreshed = True
address_label = StringProperty()
address = StringProperty()
def __init__(self, *args, **kwargs):
"""Getting AddressBook Details"""
super(AddressBook, self).__init__(*args, **kwargs)
Clock.schedule_once(self.init_ui, 0)
def init_ui(self, dt=0):
"""Clock Schdule for method AddressBook"""
self.loadAddresslist(None, 'All', '')
print(dt)
def loadAddresslist(self, account, where="", what=""):
"""Clock Schdule for method AddressBook"""
if state.searcing_text:
self.ids.scroll_y.scroll_y = 1.0
where = ['label', 'address']
what = state.searcing_text
xAddress = ''
self.ids.tag_label.text = ''
self.queryreturn = kivy_helper_search.search_sql(
xAddress, account, "addressbook", where, what, False)
self.queryreturn = [obj for obj in reversed(self.queryreturn)]
if self.queryreturn:
self.ids.tag_label.text = 'Address Book'
self.has_refreshed = True
self.set_mdList(0, 20)
self.ids.scroll_y.bind(scroll_y=self.check_scroll_y)
else:
content = MDLabel(
font_style='Caption',
theme_text_color='Primary',
text="No contact found!" if state.searcing_text
else "No contact found yet...... ",
halign='center',
size_hint_y=None,
valign='top')
self.ids.ml.add_widget(content)
def set_mdList(self, start_index, end_index):
"""Creating the mdList"""
for item in self.queryreturn[start_index:end_index]:
meny = TwoLineAvatarIconListItem(
text=item[0], secondary_text=item[1], theme_text_color='Custom',
text_color=ThemeClsColor)
meny.add_widget(AvatarSampleWidget(
source=state.imageDir + '/text_images/{}.png'.format(
avatarImageFirstLetter(item[0].strip()))))
meny.bind(on_press=partial(
self.addBook_detail, item[1], item[0]))
carousel = Carousel(direction='right')
carousel.height = meny.height
carousel.size_hint_y = None
carousel.ignore_perpendicular_swipes = True
carousel.data_index = 0
carousel.min_move = 0.2
del_btn = Button(text='Delete')
del_btn.background_normal = ''
del_btn.background_color = (1, 0, 0, 1)
del_btn.bind(on_press=partial(self.delete_address, item[1]))
carousel.add_widget(del_btn)
carousel.add_widget(meny)
carousel.index = 1
self.ids.ml.add_widget(carousel)
def check_scroll_y(self, instance, somethingelse):
"""Load data on scroll"""
if self.ids.scroll_y.scroll_y <= -0.0 and self.has_refreshed:
self.ids.scroll_y.scroll_y = 0.06
exist_addresses = len(self.ids.ml.children)
if exist_addresses != len(self.queryreturn):
self.update_addressBook_on_scroll(exist_addresses)
self.has_refreshed = (
True if exist_addresses != len(self.queryreturn) else False
)
def update_addressBook_on_scroll(self, exist_addresses):
"""Load more data on scroll down"""
self.set_mdList(exist_addresses, exist_addresses + 5)
@staticmethod
def refreshs(*args):
"""Refresh the Widget"""
# state.navinstance.ids.sc11.ids.ml.clear_widgets()
# state.navinstance.ids.sc11.loadAddresslist(None, 'All', '')
# @staticmethod
def addBook_detail(self, address, label, *args):
"""Addressbook details"""
obj = AddbookDetailPopup()
self.address_label = obj.address_label = label
self.address = obj.address = address
width = .9 if platform == 'android' else .8
self.addbook_popup = MDDialog(
type="custom",
size_hint=(width, .25),
content_cls=obj,
buttons=[
MDRaisedButton(
text="Send message to",
on_release=self.send_message_to,
),
MDRaisedButton(
text="Save",
on_release=self.update_addbook_label,
),
MDRaisedButton(
text="Cancel",
on_release=self.close_pop,
),
],
)
# self.addbook_popup.set_normal_height()
self.addbook_popup.auto_dismiss = False
self.addbook_popup.open()
def delete_address(self, address, instance, *args):
"""Delete inbox mail from inbox listing"""
self.ids.ml.remove_widget(instance.parent.parent)
# if len(self.ids.ml.children) == 0:
if self.ids.ml.children is not None:
self.ids.tag_label.text = ''
sqlExecute(
"DELETE FROM addressbook WHERE address = '{}';".format(address))
toast('Address Deleted')
def close_pop(self, instance):
"""Pop is Canceled"""
self.addbook_popup.dismiss()
toast('Canceled')
def update_addbook_label(self, instance):
"""Updating the label of address book address"""
address_list = kivy_helper_search.search_sql(folder="addressbook")
stored_labels = [labels[0] for labels in address_list]
add_dict = dict(address_list)
label = str(self.addbook_popup.content_cls.ids.add_label.text)
if label in stored_labels and self.address == add_dict[label]:
stored_labels.remove(label)
if label and label not in stored_labels:
sqlExecute(
"UPDATE addressbook SET label = '{}' WHERE"
" address = '{}';".format(
label, self.addbook_popup.content_cls.address))
state.kivyapp.root.ids.sc11.ids.ml.clear_widgets()
state.kivyapp.root.ids.sc11.loadAddresslist(None, 'All', '')
self.addbook_popup.dismiss()
toast('Saved')
def send_message_to(self, instance):
"""Method used to fill to_address of composer autofield"""
state.kivyapp.set_navbar_for_composer()
window_obj = state.kivyapp.root.ids
window_obj.sc3.children[1].ids.txt_input.text = self.address
window_obj.sc3.children[1].ids.ti.text = ''
window_obj.sc3.children[1].ids.btn.text = 'Select'
window_obj.sc3.children[1].ids.subject.text = ''
window_obj.sc3.children[1].ids.body.text = ''
window_obj.scr_mngr.current = 'create'
self.addbook_popup.dismiss()

View File

@ -0,0 +1,209 @@
from bitmessagekivy import kivy_helper_search
from bmconfigparser import BMConfigParser
from helper_sql import sqlExecute, sqlQuery
from functools import partial
from kivy.clock import Clock
from kivy.metrics import dp
from kivy.properties import (
ListProperty,
StringProperty
)
from kivy.uix.button import Button
from kivy.uix.carousel import Carousel
from kivy.uix.screenmanager import Screen
from kivymd.uix.label import MDLabel
from kivymd.uix.list import TwoLineAvatarIconListItem
import state
from bitmessagekivy.baseclass.common import (
showLimitedCnt, toast, ThemeClsColor,
chipTag, avatarImageFirstLetter, AddTimeWidget, AvatarSampleWidget
)
from bitmessagekivy.baseclass.maildetail import MailDetail
from bitmessagekivy.baseclass.trash import Trash
class Allmails(Screen):
"""Allmails Screen for kivy Ui"""
data = ListProperty()
has_refreshed = True
all_mails = ListProperty()
account = StringProperty()
def __init__(self, *args, **kwargs):
"""Method Parsing the address"""
super(Allmails, self).__init__(*args, **kwargs)
if state.association == '':
if BMConfigParser().addresses():
state.association = BMConfigParser().addresses()[0]
Clock.schedule_once(self.init_ui, 0)
def init_ui(self, dt=0):
"""Clock Schdule for method all mails"""
self.loadMessagelist()
print(dt)
def loadMessagelist(self):
"""Load Inbox, Sent anf Draft list of messages"""
self.account = state.association
self.ids.tag_label.text = ''
self.allMessageQuery(0, 20)
if self.all_mails:
self.ids.tag_label.text = 'All Mails'
state.kivyapp.get_inbox_count()
state.kivyapp.get_sent_count()
state.all_count = str(
int(state.sent_count) + int(state.inbox_count))
self.set_AllmailCnt(state.all_count)
self.set_mdlist()
# self.ids.refresh_layout.bind(scroll_y=self.check_scroll_y)
self.ids.scroll_y.bind(scroll_y=self.check_scroll_y)
else:
self.set_AllmailCnt('0')
content = MDLabel(
font_style='Caption',
theme_text_color='Primary',
text="yet no message for this account!!!!!!!!!!!!!",
halign='center',
size_hint_y=None,
valign='top')
self.ids.ml.add_widget(content)
def allMessageQuery(self, start_indx, end_indx):
"""Retrieving data from inbox or sent both tables"""
self.all_mails = sqlQuery(
"SELECT toaddress, fromaddress, subject, message, folder, ackdata"
" As id, DATE(senttime) As actionTime, senttime as msgtime FROM sent WHERE"
" folder = 'sent' and fromaddress = '{0}'"
" UNION SELECT toaddress, fromaddress, subject, message, folder,"
" msgid As id, DATE(received) As actionTime, received as msgtime FROM inbox"
" WHERE folder = 'inbox' and toaddress = '{0}'"
" ORDER BY actionTime DESC limit {1}, {2}".format(
self.account, start_indx, end_indx))
def set_AllmailCnt(self, Count): # pylint: disable=no-self-use
"""This method is used to set allmails message count"""
allmailCnt_obj = state.kivyapp.root.ids.content_drawer.ids.allmail_cnt
allmailCnt_obj.ids.badge_txt.text = showLimitedCnt(int(Count))
def set_mdlist(self):
"""This method is used to create mdList for allmaills"""
data_exist = len(self.ids.ml.children)
for item in self.all_mails:
body = item[3].decode() if isinstance(item[3], bytes) else item[3]
subject = item[2].decode() if isinstance(item[2], bytes) else item[2]
meny = TwoLineAvatarIconListItem(
text=item[1],
secondary_text=(subject[:50] + '........' if len(
subject) >= 50 else (
subject + ',' + body)[0:50] + '........').replace('\t', '').replace(' ', ''),
theme_text_color='Custom',
text_color=ThemeClsColor)
meny._txt_right_pad = dp(70)
meny.add_widget(AvatarSampleWidget(
source=state.imageDir + '/text_images/{}.png'.format(
avatarImageFirstLetter(body.strip()))))
meny.bind(on_press=partial(
self.mail_detail, item[5], item[4]))
meny.add_widget(AddTimeWidget(item[7]))
meny.add_widget(chipTag(item[4]))
carousel = Carousel(direction='right')
carousel.height = meny.height
carousel.size_hint_y = None
carousel.ignore_perpendicular_swipes = True
carousel.data_index = 0
carousel.min_move = 0.2
del_btn = Button(text='Delete')
del_btn.background_normal = ''
del_btn.background_color = (1, 0, 0, 1)
del_btn.bind(on_press=partial(
self.swipe_delete, item[5], item[4]))
carousel.add_widget(del_btn)
carousel.add_widget(meny)
carousel.index = 1
self.ids.ml.add_widget(carousel)
updated_data = len(self.ids.ml.children)
self.has_refreshed = True if data_exist != updated_data else False
def check_scroll_y(self, instance, somethingelse):
"""Scroll fixed length"""
if self.ids.scroll_y.scroll_y <= -0.00 and self.has_refreshed:
self.ids.scroll_y.scroll_y = .06
load_more = len(self.ids.ml.children)
self.updating_allmail(load_more)
def updating_allmail(self, load_more):
"""This method is used to update the all mail
listing value on the scroll of screen"""
self.allMessageQuery(load_more, 5)
self.set_mdlist()
def mail_detail(self, unique_id, folder, *args):
"""Load sent and inbox mail details"""
state.detailPageType = folder
state.is_allmail = True
state.mail_id = unique_id
if self.manager:
src_mng_obj = self.manager
else:
src_mng_obj = self.parent.parent
src_mng_obj.screens[11].clear_widgets()
src_mng_obj.screens[11].add_widget(MailDetail())
src_mng_obj.current = 'mailDetail'
def swipe_delete(self, unique_id, folder, instance, *args):
"""Delete inbox mail from all mail listing"""
if folder == 'inbox':
sqlExecute(
"UPDATE inbox SET folder = 'trash' WHERE msgid = ?;",
unique_id)
else:
sqlExecute(
"UPDATE sent SET folder = 'trash' WHERE ackdata = ?;",
unique_id)
self.ids.ml.remove_widget(instance.parent.parent)
try:
msg_count_objs = self.parent.parent.ids.content_drawer.ids
nav_lay_obj = self.parent.parent.ids
except Exception:
msg_count_objs = self.parent.parent.parent.ids.content_drawer.ids
nav_lay_obj = self.parent.parent.parent.ids
if folder == 'inbox':
msg_count_objs.inbox_cnt.ids.badge_txt.text = showLimitedCnt(int(state.inbox_count) - 1)
state.inbox_count = str(int(state.inbox_count) - 1)
nav_lay_obj.sc1.ids.ml.clear_widgets()
nav_lay_obj.sc1.loadMessagelist(state.association)
else:
msg_count_objs.send_cnt.ids.badge_txt.text = showLimitedCnt(int(state.sent_count) - 1)
state.sent_count = str(int(state.sent_count) - 1)
nav_lay_obj.sc4.ids.ml.clear_widgets()
nav_lay_obj.sc4.loadSent(state.association)
if folder != 'inbox':
msg_count_objs.allmail_cnt.ids.badge_txt.text = showLimitedCnt(int(state.all_count) - 1)
state.all_count = str(int(state.all_count) - 1)
msg_count_objs.trash_cnt.ids.badge_txt.text = showLimitedCnt(int(state.trash_count) + 1)
state.trash_count = str(int(state.trash_count) + 1)
if int(state.all_count) <= 0:
self.ids.tag_label.text = ''
nav_lay_obj.sc5.clear_widgets()
nav_lay_obj.sc5.add_widget(Trash())
nav_lay_obj.sc17.remove_widget(instance.parent.parent)
toast('Deleted')
def refresh_callback(self, *args):
"""Method updates the state of application,
While the spinner remains on the screen"""
def refresh_callback(interval):
"""Load the allmails screen data"""
self.ids.ml.clear_widgets()
self.remove_widget(self.children[1])
try:
screens_obj = self.parent.screens[16]
except Exception:
screens_obj = self.parent.parent.screens[16]
screens_obj.add_widget(Allmails())
self.ids.refresh_layout.refresh_done()
self.tick = 0
Clock.schedule_once(refresh_callback, 1)

View File

@ -0,0 +1,129 @@
import os
from datetime import datetime
from kivy.lang import Builder
from kivy.metrics import dp
from kivymd.uix.list import (
ILeftBody,
IRightBodyTouch,
TwoLineAvatarIconListItem,
OneLineIconListItem,
OneLineAvatarIconListItem,
OneLineListItem
)
from kivy.uix.image import Image
from kivymd.uix.label import MDLabel
from bitmessagekivy.get_platform import platform
from kivymd.uix.chip import MDChip
ThemeClsColor = [0.12, 0.58, 0.95, 1]
data_screens = {
"MailDetail": {
"kv_string": "maildetail",
"Factory": "MailDetail()",
"name_screen": "mailDetail",
"object": 0,
"Import": "from bitmessagekivy.baseclass.maildetail import MailDetail",
}
,}
def chipTag(text):
"""This method is used for showing chip tag"""
obj = MDChip()
# obj.size_hint = (None, None)
obj.size_hint = (0.16 if platform == "android" else 0.08, None)
obj.text = text
obj.icon = ""
obj.pos_hint = {
"center_x": 0.91 if platform == "android" else 0.94,
"center_y": 0.3
}
obj.height = dp(18)
obj.text_color = (1,1,1,1)
obj.radius =[8]
return obj
def initailize_detail_page(manager):
if not manager.has_screen(
data_screens['MailDetail']["name_screen"]
):
Builder.load_file(
os.path.join(
# os.environ["KITCHEN_SINK_ROOT"],
os.path.dirname(os.path.dirname(__file__)),
"kv",
"maildetail.kv",
)
)
if "Import" in data_screens['MailDetail']:
exec(data_screens['MailDetail']["Import"])
screen_object = eval(data_screens['MailDetail']["Factory"])
data_screens['MailDetail']["object"] = screen_object
manager.add_widget(screen_object)
manager.current = data_screens['MailDetail']["name_screen"]
def toast(text):
"""Method will display the toast message"""
# pylint: disable=redefined-outer-name
from kivymd.toast.kivytoast import toast
toast(text)
return None
def showLimitedCnt(total_msg):
"""This method set the total count limit in badge_text"""
return "99+" if total_msg > 99 else str(total_msg)
def avatarImageFirstLetter(letter_string):
"""This function is used to the first letter for the avatar image"""
try:
if letter_string[0].upper() >= 'A' and letter_string[0].upper() <= 'Z':
img_latter = letter_string[0].upper()
elif int(letter_string[0]) >= 0 and int(letter_string[0]) <= 9:
img_latter = letter_string[0]
else:
img_latter = '!'
except ValueError:
img_latter = '!'
return img_latter if img_latter else '!'
def AddTimeWidget(time): # pylint: disable=redefined-outer-name
"""This method is used to create TimeWidget"""
action_time = TimeTagRightSampleWidget(
text=str(ShowTimeHistoy(time)),
font_style="Caption",
size=[120, 140] if platform == "android" else [64, 80],
)
action_time.font_size = "11sp"
return action_time
def ShowTimeHistoy(act_time):
"""This method is used to return the message sent or receive time"""
action_time = datetime.fromtimestamp(int(act_time))
crnt_date = datetime.now()
duration = crnt_date - action_time
display_data = (
action_time.strftime("%d/%m/%Y")
if duration.days >= 365
else action_time.strftime("%I:%M %p").lstrip("0")
if duration.days == 0 and crnt_date.strftime("%d/%m/%Y") == action_time.strftime("%d/%m/%Y")
else action_time.strftime("%d %b")
)
return display_data
class AvatarSampleWidget(ILeftBody, Image):
"""AvatarSampleWidget class for kivy Ui"""
class TimeTagRightSampleWidget(IRightBodyTouch, MDLabel):
"""TimeTagRightSampleWidget class for Ui"""

View File

@ -0,0 +1,209 @@
import time
from bitmessagekivy import kivy_helper_search
from bmconfigparser import BMConfigParser
from helper_sql import sqlExecute
from functools import partial
from addresses import decodeAddress
from kivy.clock import Clock
from kivy.metrics import dp
from kivy.properties import (
ListProperty,
StringProperty
)
from kivy.uix.button import Button
from kivy.uix.carousel import Carousel
from kivy.uix.screenmanager import Screen
from kivymd.uix.label import MDLabel
from kivymd.uix.list import TwoLineAvatarIconListItem
import state
from bitmessagekivy.baseclass.common import (
showLimitedCnt, toast, ThemeClsColor,
AddTimeWidget, AvatarSampleWidget
)
from bitmessagekivy.baseclass.maildetail import MailDetail
class Draft(Screen):
"""Draft screen class for kivy Ui"""
data = ListProperty()
account = StringProperty()
queryreturn = ListProperty()
has_refreshed = True
def __init__(self, *args, **kwargs):
"""Method used for storing draft messages"""
super(Draft, self).__init__(*args, **kwargs)
if state.association == '':
if BMConfigParser().addresses():
state.association = BMConfigParser().addresses()[0]
Clock.schedule_once(self.init_ui, 0)
def init_ui(self, dt=0):
"""Clock Schdule for method draft accounts"""
self.sentaccounts()
print(dt)
def sentaccounts(self):
"""Load draft accounts"""
# self.account = state.association
self.loadDraft()
def loadDraft(self, where="", what=""):
"""Load draft list for Draft messages"""
self.account = state.association
xAddress = 'fromaddress'
self.ids.tag_label.text = ''
self.draftDataQuery(xAddress, where, what)
# if state.msg_counter_objs:
# state.msg_counter_objs.draft_cnt.children[0].children[0].text = showLimitedCnt(len(self.queryreturn))
if self.queryreturn:
self.ids.tag_label.text = 'Draft'
self.set_draftCnt(state.draft_count)
self.set_mdList()
self.ids.scroll_y.bind(scroll_y=self.check_scroll_y)
else:
self.set_draftCnt('0')
content = MDLabel(
font_style='Caption',
theme_text_color='Primary',
text="yet no message for this account!!!!!!!!!!!!!",
halign='center',
size_hint_y=None,
valign='top')
self.ids.ml.add_widget(content)
def draftDataQuery(self, xAddress, where, what, start_indx=0, end_indx=20):
"""This methosd is for retrieving draft messages"""
self.queryreturn = kivy_helper_search.search_sql(
xAddress, self.account, "draft", where, what,
False, start_indx, end_indx)
def set_draftCnt(self, Count): # pylint: disable=no-self-use
"""This method set the count of draft mails"""
draftCnt_obj = state.kivyapp.root.ids.content_drawer.ids.draft_cnt
draftCnt_obj.ids.badge_txt.text = showLimitedCnt(int(Count))
def set_mdList(self):
"""This method is used to create mdlist"""
data = []
total_draft_msg = len(self.ids.ml.children)
for mail in self.queryreturn:
third_text = mail[3].replace('\n', ' ')
data.append({
'text': mail[1].strip(),
'secondary_text': mail[2][:10] + '...........' if len(
mail[2]) > 10 else mail[2] + '\n' + " " + (
third_text[:25] + '...!') if len(
third_text) > 25 else third_text,
'ackdata': mail[5], 'senttime': mail[6]})
for item in data:
meny = TwoLineAvatarIconListItem(
text='Draft', secondary_text=item['text'],
theme_text_color='Custom',
text_color=ThemeClsColor)
meny._txt_right_pad = dp(70)
meny.add_widget(AvatarSampleWidget(
source=state.imageDir + '/avatar.png'))
meny.bind(on_press=partial(
self.draft_detail, item['ackdata']))
meny.add_widget(AddTimeWidget(item['senttime']))
carousel = Carousel(direction='right')
carousel.height = meny.height
carousel.size_hint_y = None
carousel.ignore_perpendicular_swipes = True
carousel.data_index = 0
carousel.min_move = 0.2
del_btn = Button(text='Delete')
del_btn.background_normal = ''
del_btn.background_color = (1, 0, 0, 1)
del_btn.bind(on_press=partial(self.delete_draft, item['ackdata']))
carousel.add_widget(del_btn)
carousel.add_widget(meny)
carousel.index = 1
self.ids.ml.add_widget(carousel)
updated_msg = len(self.ids.ml.children)
self.has_refreshed = True if total_draft_msg != updated_msg else False
def check_scroll_y(self, instance, somethingelse):
"""Load data on scroll"""
if self.ids.scroll_y.scroll_y <= -0.0 and self.has_refreshed:
self.ids.scroll_y.scroll_y = 0.06
total_draft_msg = len(self.ids.ml.children)
self.update_draft_screen_on_scroll(total_draft_msg)
def update_draft_screen_on_scroll(self, total_draft_msg, where='', what=''):
"""Load more data on scroll down"""
self.draftDataQuery('fromaddress', where, what, total_draft_msg, 5)
self.set_mdList()
def draft_detail(self, ackdata, *args):
"""Show draft Details"""
state.detailPageType = 'draft'
state.mail_id = ackdata
if self.manager:
src_mng_obj = self.manager
else:
src_mng_obj = self.parent.parent
src_mng_obj.screens[11].clear_widgets()
src_mng_obj.screens[11].add_widget(MailDetail())
src_mng_obj.current = 'mailDetail'
def delete_draft(self, data_index, instance, *args):
"""Delete draft message permanently"""
sqlExecute("DELETE FROM sent WHERE ackdata = ?;", data_index)
if int(state.draft_count) > 0:
state.draft_count = str(int(state.draft_count) - 1)
self.set_draftCnt(state.draft_count)
if int(state.draft_count) <= 0:
# self.ids.identi_tag.children[0].text = ''
self.ids.tag_label.text = ''
self.ids.ml.remove_widget(instance.parent.parent)
toast('Deleted')
@staticmethod
def draft_msg(src_object):
"""Save draft mails"""
composer_object = state.kivyapp.root.ids.sc3.children[1].ids
fromAddress = str(composer_object.ti.text)
toAddress = str(composer_object.txt_input.text)
subject = str(composer_object.subject.text)
message = str(composer_object.body.text)
encoding = 3
sendMessageToPeople = True
if sendMessageToPeople:
streamNumber, ripe = decodeAddress(toAddress)[2:]
from addresses import addBMIfNotPresent
toAddress = addBMIfNotPresent(toAddress)
stealthLevel = BMConfigParser().safeGetInt(
'bitmessagesettings', 'ackstealthlevel')
from helper_ackPayload import genAckPayload
ackdata = genAckPayload(streamNumber, stealthLevel)
sqlExecute(
'''INSERT INTO sent VALUES
(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)''',
'',
toAddress,
ripe,
fromAddress,
subject,
message,
ackdata,
int(time.time()),
int(time.time()),
0,
'msgqueued',
0,
'draft',
encoding,
BMConfigParser().safeGetInt('bitmessagesettings', 'ttl'))
state.msg_counter_objs = src_object.children[2].children[0].ids
state.draft_count = str(int(state.draft_count) + 1) \
if state.association == fromAddress else state.draft_count
src_object.ids.sc16.clear_widgets()
src_object.ids.sc16.add_widget(Draft())
toast('Save draft')
return

View File

@ -0,0 +1,262 @@
# from bitmessagekivy.get_platform import platform
# from bitmessagekivy import identiconGeneration
from bitmessagekivy import kivy_helper_search
from bmconfigparser import BMConfigParser
from helper_sql import sqlExecute
from functools import partial
from kivy.clock import Clock
from kivy.metrics import dp
from kivy.properties import (
ListProperty,
StringProperty
)
from kivy.uix.button import Button
from kivy.uix.carousel import Carousel
from kivy.uix.screenmanager import Screen
from kivymd.uix.label import MDLabel
from kivymd.uix.list import TwoLineAvatarIconListItem
import state
from bitmessagekivy.baseclass.common import (
showLimitedCnt, avatarImageFirstLetter,
AddTimeWidget, ThemeClsColor, AvatarSampleWidget, toast
)
from bitmessagekivy.baseclass.maildetail import MailDetail
from bitmessagekivy.baseclass.trash import Trash
class Inbox(Screen):
"""Inbox Screen class for kivy Ui"""
queryreturn = ListProperty()
has_refreshed = True
account = StringProperty()
def __init__(self, *args, **kwargs):
"""Method Parsing the address"""
super(Inbox, self).__init__(*args, **kwargs)
Clock.schedule_once(self.init_ui, 0)
@staticmethod
def set_defaultAddress():
"""This method set's default address"""
if state.association == "":
if BMConfigParser().addresses():
state.association = BMConfigParser().addresses()[0]
def init_ui(self, dt=0):
"""Clock schdule for method inbox accounts"""
self.loadMessagelist()
def loadMessagelist(self, where="", what=""):
"""Load Inbox list for Inbox messages"""
self.set_defaultAddress()
self.account = state.association
if state.searcing_text:
# self.children[2].children[0].children[0].scroll_y = 1.0
self.ids.scroll_y.scroll_y = 1.0
where = ["subject", "message"]
what = state.searcing_text
xAddress = "toaddress"
data = []
self.ids.tag_label.text = ""
self.inboxDataQuery(xAddress, where, what)
self.ids.tag_label.text = ""
if self.queryreturn:
self.ids.tag_label.text = "Inbox"
state.kivyapp.get_inbox_count()
self.set_inboxCount(state.inbox_count)
for mail in self.queryreturn:
# third_text = mail[3].replace('\n', ' ')
body = mail[3].decode() if isinstance(mail[3], bytes) else mail[3]
subject = mail[5].decode() if isinstance(mail[5], bytes) else mail[5]
data.append(
{
"text": mail[4].strip(),
"secondary_text": (
subject[:50] + "........"
if len(subject) >= 50
else (subject + "," + body)[0:50] + "........"
)
.replace("\t", "")
.replace(" ", ""),
"msgid": mail[1],
"received": mail[6]
}
)
self.has_refreshed = True
self.set_mdList(data)
self.ids.scroll_y.bind(scroll_y=self.check_scroll_y)
else:
self.set_inboxCount("0")
content = MDLabel(
font_style="Caption",
theme_text_color="Primary",
text="No message found!"
if state.searcing_text
else "yet no message for this account!!!!!!!!!!!!!",
halign="center",
size_hint_y=None,
valign="top"
)
self.ids.ml.add_widget(content)
def set_inboxCount(self, msgCnt): # pylint: disable=no-self-use
"""This method is used to sent inbox message count"""
src_mng_obj = state.kivyapp.root.ids.content_drawer.ids
src_mng_obj.inbox_cnt.ids.badge_txt.text = showLimitedCnt(int(msgCnt))
state.kivyapp.get_sent_count()
state.all_count = str(
int(state.sent_count) + int(state.inbox_count))
src_mng_obj.allmail_cnt.ids.badge_txt.text = showLimitedCnt(int(state.all_count))
def inboxDataQuery(self, xAddress, where, what, start_indx=0, end_indx=20):
"""This method is used for retrieving inbox data"""
self.queryreturn = kivy_helper_search.search_sql(
xAddress, self.account, "inbox", where, what, False, start_indx, end_indx
)
def set_mdList(self, data):
"""This method is used to create the mdList"""
total_message = len(self.ids.ml.children)
for item in data:
meny = TwoLineAvatarIconListItem(
text=item["text"],
secondary_text=item["secondary_text"],
theme_text_color="Custom",
text_color=ThemeClsColor
)
meny._txt_right_pad = dp(70)
meny.add_widget(
AvatarSampleWidget(
source=state.imageDir + "/text_images/{}.png".format(
avatarImageFirstLetter(item["secondary_text"].strip())
)
)
)
meny.bind(on_press=partial(self.inbox_detail, item["msgid"]))
meny.add_widget(AddTimeWidget(item["received"]))
carousel = Carousel(direction="right")
carousel.height = meny.height
carousel.size_hint_y = None
carousel.ignore_perpendicular_swipes = True
carousel.data_index = 0
carousel.min_move = 0.2
del_btn = Button(text="Delete")
del_btn.background_normal = ""
del_btn.background_color = (1, 0, 0, 1)
del_btn.bind(on_press=partial(self.delete, item["msgid"]))
carousel.add_widget(del_btn)
carousel.add_widget(meny)
# ach_btn = Button(text='Achieve')
# ach_btn.background_color = (0, 1, 0, 1)
# ach_btn.bind(on_press=partial(self.archive, item['msgid']))
# carousel.add_widget(ach_btn)
carousel.index = 1
self.ids.ml.add_widget(carousel)
update_message = len(self.ids.ml.children)
self.has_refreshed = True if total_message != update_message else False
def check_scroll_y(self, instance, somethingelse):
"""Loads data on scroll"""
if self.ids.scroll_y.scroll_y <= -0.0 and self.has_refreshed:
self.ids.scroll_y.scroll_y = 0.06
total_message = len(self.ids.ml.children)
self.update_inbox_screen_on_scroll(total_message)
def update_inbox_screen_on_scroll(self, total_message, where="", what=""):
"""This method is used to load more data on scroll down"""
data = []
if state.searcing_text:
where = ["subject", "message"]
what = state.searcing_text
self.inboxDataQuery("toaddress", where, what, total_message, 5)
for mail in self.queryreturn:
# third_text = mail[3].replace('\n', ' ')
subject = mail[3].decode() if isinstance(mail[3], bytes) else mail[3]
body = mail[5].decode() if isinstance(mail[5], bytes) else mail[5]
data.append(
{
"text": mail[4].strip(),
"secondary_text": body[:50] + "........"
if len(body) >= 50
else (body + "," + subject.replace("\n", ""))[0:50] + "........",
"msgid": mail[1],
"received": mail[6]
}
)
self.set_mdList(data)
def inbox_detail(self, msg_id, *args):
"""Load inbox page details"""
state.detailPageType = "inbox"
state.mail_id = msg_id
if self.manager:
src_mng_obj = self.manager
else:
src_mng_obj = self.parent.parent
src_mng_obj.screens[11].clear_widgets()
src_mng_obj.screens[11].add_widget(MailDetail())
src_mng_obj.current = "mailDetail"
def delete(self, data_index, instance, *args):
"""Delete inbox mail from inbox listing"""
sqlExecute("UPDATE inbox SET folder = 'trash' WHERE msgid = ?;", data_index)
msg_count_objs = self.parent.parent.ids.content_drawer.ids
if int(state.inbox_count) > 0:
msg_count_objs.inbox_cnt.ids.badge_txt.text = showLimitedCnt(
int(state.inbox_count) - 1
)
msg_count_objs.trash_cnt.ids.badge_txt.text = showLimitedCnt(
int(state.trash_count) + 1
)
state.inbox_count = str(int(state.inbox_count) - 1)
state.trash_count = str(int(state.trash_count) + 1)
if int(state.all_count) > 0:
msg_count_objs.allmail_cnt.ids.badge_txt.text = showLimitedCnt(
int(state.all_count) - 1
)
state.all_count = str(int(state.all_count) - 1)
if int(state.inbox_count) <= 0:
# self.ids.identi_tag.children[0].text = ''
self.ids.tag_label.text = ''
self.ids.ml.remove_widget(
instance.parent.parent)
toast('Deleted')
self.update_trash()
def archive(self, data_index, instance, *args):
"""Archive inbox mail from inbox listing"""
sqlExecute("UPDATE inbox SET folder = 'trash' WHERE msgid = ?;", data_index)
self.ids.ml.remove_widget(instance.parent.parent)
self.update_trash()
def update_trash(self):
"""Update trash screen mails which is deleted from inbox"""
self.manager.parent.ids.sc5.clear_widgets()
self.manager.parent.ids.sc5.add_widget(Trash())
# try:
# self.parent.screens[4].clear_widgets()
# self.parent.screens[4].add_widget(Trash())
# except Exception:
# self.parent.parent.screens[4].clear_widgets()
# self.parent.parent.screens[4].add_widget(Trash())
def refresh_callback(self, *args):
"""Method updates the state of application,
While the spinner remains on the screen"""
def refresh_callback(interval):
"""Method used for loading the inbox screen data"""
state.searcing_text = ""
self.children[2].children[1].ids.search_field.text = ""
self.ids.ml.clear_widgets()
self.loadMessagelist(state.association)
self.has_refreshed = True
self.ids.refresh_layout.refresh_done()
self.tick = 0
Clock.schedule_once(refresh_callback, 1)

View File

@ -0,0 +1,112 @@
import queues
from bmconfigparser import BMConfigParser
from kivy.clock import Clock
from kivy.properties import StringProperty, BooleanProperty
from kivy.uix.boxlayout import BoxLayout
from kivymd.uix.behaviors.elevation import RectangularElevationBehavior
from kivy.uix.screenmanager import Screen
import state
from bitmessagekivy.baseclass.common import (
toast, ThemeClsColor
)
class Login(Screen):
"""Login Screeen class for kivy Ui"""
log_text1 = (
'You may generate addresses by using either random numbers'
' or by using a passphrase If you use a passphrase, the address'
' is called a deterministic; address The Random Number option is'
' selected by default but deterministic addresses have several pros'
' and cons:')
log_text2 = ('If talk about pros You can recreate your addresses on any computer'
' from memory, You need-not worry about backing up your keys.dat file'
' as long as you can remember your passphrase and aside talk about cons'
' You must remember (or write down) your You must remember the address'
' version number and the stream number along with your passphrase If you'
' choose a weak passphrase and someone on the Internet can brute-force it,'
' they can read your messages and send messages as you')
class Random(Screen):
"""Random Screen class for Ui"""
is_active = BooleanProperty(False)
checked = StringProperty("")
def generateaddress(self, navApp):
"""Method for Address Generator"""
# entered_label = str(self.ids.lab.text).strip()
entered_label = str(self.ids.add_random_bx.children[0].ids.lab.text).strip()
if not entered_label:
self.ids.add_random_bx.children[0].ids.lab.focus = True
streamNumberForAddress = 1
eighteenByteRipe = False
nonceTrialsPerByte = 1000
payloadLengthExtraBytes = 1000
lables = [BMConfigParser().get(obj, 'label')
for obj in BMConfigParser().addresses()]
if entered_label and entered_label not in lables:
toast('Address Creating...')
queues.addressGeneratorQueue.put((
'createRandomAddress', 4, streamNumberForAddress, entered_label, 1,
"", eighteenByteRipe, nonceTrialsPerByte,
payloadLengthExtraBytes))
self.parent.parent.ids.toolbar.opacity = 1
self.parent.parent.ids.toolbar.disabled = False
state.kivyapp.loadMyAddressScreen(True)
self.manager.current = 'myaddress'
Clock.schedule_once(self.address_created_callback, 6)
def address_created_callback(self, dt=0):
"""New address created"""
state.kivyapp.loadMyAddressScreen(False)
state.kivyapp.root.ids.sc10.ids.ml.clear_widgets()
state.kivyapp.root.ids.sc10.is_add_created = True
state.kivyapp.root.ids.sc10.init_ui()
self.reset_address_spinner()
toast('New address created')
def reset_address_spinner(self):
"""reseting spinner address and UI"""
addresses = [addr for addr in BMConfigParser().addresses()
if BMConfigParser().get(str(addr), 'enabled') == 'true']
self.manager.parent.ids.content_drawer.ids.btn.values = []
self.manager.parent.ids.sc3.children[1].ids.btn.values = []
self.manager.parent.ids.content_drawer.ids.btn.values = addresses
self.manager.parent.ids.sc3.children[1].ids.btn.values = addresses
@staticmethod
def add_validation(instance):
"""Checking validation at address creation time"""
entered_label = str(instance.text.strip())
lables = [BMConfigParser().get(obj, 'label')
for obj in BMConfigParser().addresses()]
if entered_label in lables:
instance.error = True
instance.helper_text = 'it is already exist you'\
' can try this Ex. ( {0}_1, {0}_2 )'.format(
entered_label)
elif entered_label:
instance.error = False
else:
instance.error = False
instance.helper_text = 'This field is required'
def reset_address_label(self, n):
"""Resetting address labels"""
if not self.ids.add_random_bx.children:
self.ids.add_random_bx.add_widget(RandomBoxlayout())
class InfoLayout(BoxLayout, RectangularElevationBehavior):
"""InfoLayout class for kivy Ui"""
class RandomBoxlayout(BoxLayout):
"""RandomBoxlayout class for BoxLayout behaviour"""

View File

@ -0,0 +1,242 @@
from datetime import datetime
from bitmessagekivy.get_platform import platform
from helper_sql import sqlExecute, sqlQuery
from kivy.core.clipboard import Clipboard
from kivy.clock import Clock
from kivy.properties import (
StringProperty,
NumericProperty
)
from kivy.factory import Factory
from kivymd.uix.button import MDFlatButton, MDIconButton
from kivymd.uix.dialog import MDDialog
from kivymd.uix.list import (
OneLineListItem,
IRightBodyTouch
)
from kivymd.uix.label import MDLabel
from kivy.uix.screenmanager import Screen
import state
from bitmessagekivy.baseclass.common import (
toast, avatarImageFirstLetter, ShowTimeHistoy
)
from bitmessagekivy.baseclass.popup import SenderDetailPopup
class OneLineListTitle(OneLineListItem):
"""OneLineListTitle class for kivy Ui"""
__events__ = ('on_long_press', )
long_press_time = NumericProperty(1)
def on_state(self, instance, value):
"""On state"""
if value == 'down':
lpt = self.long_press_time
self._clockev = Clock.schedule_once(self._do_long_press, lpt)
else:
self._clockev.cancel()
def _do_long_press(self, dt):
"""Do long press"""
self.dispatch('on_long_press')
def on_long_press(self, *largs):
"""On long press"""
self.copymessageTitle(self.text)
def copymessageTitle(self, title_text):
"""this method is for displaying dialog box"""
self.title_text = title_text
width = .8 if platform == 'android' else .55
self.dialog_box = MDDialog(
text=title_text,
size_hint=(width, .25),
buttons=[
MDFlatButton(
text="Copy", on_release=self.callback_for_copy_title
),
MDFlatButton(
text="Cancel", on_release=self.callback_for_copy_title,
),
],)
self.dialog_box.open()
def callback_for_copy_title(self, instance):
"""Callback of alert box"""
if instance.text == 'Copy':
Clipboard.copy(self.title_text)
self.dialog_box.dismiss()
toast(instance.text)
class IconRightSampleWidget(IRightBodyTouch, MDIconButton):
"""IconRightSampleWidget class for kivy Ui"""
class MailDetail(Screen): # pylint: disable=too-many-instance-attributes
"""MailDetail Screen class for kivy Ui"""
to_addr = StringProperty()
from_addr = StringProperty()
subject = StringProperty()
message = StringProperty()
status = StringProperty()
page_type = StringProperty()
time_tag = StringProperty()
avatarImg = StringProperty()
def __init__(self, *args, **kwargs):
"""Mail Details method"""
super(MailDetail, self).__init__(*args, **kwargs)
Clock.schedule_once(self.init_ui, 0)
def init_ui(self, dt=0):
"""Clock Schdule for method MailDetail mails"""
self.page_type = state.detailPageType if state.detailPageType else ''
try:
if state.detailPageType == 'sent' or state.detailPageType == 'draft':
data = sqlQuery(
"select toaddress, fromaddress, subject, message, status,"
" ackdata, senttime from sent where ackdata = ?;", state.mail_id)
state.status = self
state.ackdata = data[0][5]
self.assign_mail_details(data)
state.kivyapp.set_mail_detail_header()
elif state.detailPageType == 'inbox':
data = sqlQuery(
"select toaddress, fromaddress, subject, message, received from inbox"
" where msgid = ?;", state.mail_id)
self.assign_mail_details(data)
state.kivyapp.set_mail_detail_header()
except Exception as e:
print('Something wents wrong!!')
def assign_mail_details(self, data):
"""Assigning mail details"""
subject = data[0][2].decode() if isinstance(data[0][2], bytes) else data[0][2]
body = data[0][3].decode() if isinstance(data[0][2], bytes) else data[0][3]
self.to_addr = data[0][0] if len(data[0][0]) > 4 else ' '
self.from_addr = data[0][1]
self.subject = subject.capitalize(
) if subject.capitalize() else '(no subject)'
self.message = body
if len(data[0]) == 7:
self.status = data[0][4]
self.time_tag = ShowTimeHistoy(data[0][4]) if state.detailPageType == 'inbox' else ShowTimeHistoy(data[0][6])
self.avatarImg = state.imageDir + '/avatar.png' if state.detailPageType == 'draft' else (
state.imageDir + '/text_images/{0}.png'.format(avatarImageFirstLetter(self.subject.strip())))
self.timeinseconds = data[0][4] if state.detailPageType == 'inbox' else data[0][6]
def delete_mail(self):
"""Method for mail delete"""
msg_count_objs = state.kivyapp.root.ids.content_drawer.ids
state.searcing_text = ''
self.children[0].children[0].active = True
if state.detailPageType == 'sent':
state.kivyapp.root.ids.sc4.ids.sent_search.ids.search_field.text = ''
sqlExecute(
"UPDATE sent SET folder = 'trash' WHERE"
" ackdata = ?;", state.mail_id)
msg_count_objs.send_cnt.ids.badge_txt.text = str(int(state.sent_count) - 1)
state.sent_count = str(int(state.sent_count)