mirror of
https://github.com/markqvist/Sideband.git
synced 2026-12-05 14:19:59 -05:00
Initial commit
This commit is contained in:
parent
765f72a3ab
commit
70e49c8e6f
13 changed files with 2827 additions and 0 deletions
151
ui/announces.py
Normal file
151
ui/announces.py
Normal file
|
|
@ -0,0 +1,151 @@
|
|||
import time
|
||||
import RNS
|
||||
|
||||
from kivy.metrics import dp
|
||||
from kivy.uix.boxlayout import BoxLayout
|
||||
from kivy.properties import StringProperty, BooleanProperty
|
||||
from kivymd.uix.list import MDList, IconLeftWidget, IconRightWidget, OneLineAvatarIconListItem
|
||||
from kivymd.uix.menu import MDDropdownMenu
|
||||
from kivy.uix.gridlayout import GridLayout
|
||||
from kivy.uix.boxlayout import BoxLayout
|
||||
|
||||
from kivymd.uix.button import MDFlatButton
|
||||
from kivymd.uix.dialog import MDDialog
|
||||
|
||||
from ui.helpers import ts_format
|
||||
|
||||
class Announces():
|
||||
def __init__(self, app):
|
||||
self.app = app
|
||||
self.context_dests = []
|
||||
self.added_item_dests = []
|
||||
self.list = None
|
||||
self.update()
|
||||
|
||||
def reload(self):
|
||||
self.clear_list()
|
||||
self.update()
|
||||
|
||||
def clear_list(self):
|
||||
if self.list != None:
|
||||
self.list.clear_widgets()
|
||||
|
||||
self.context_dests = []
|
||||
self.added_item_dests = []
|
||||
|
||||
def update(self):
|
||||
self.clear_list()
|
||||
self.announces = self.app.sideband.list_announces()
|
||||
self.update_widget()
|
||||
|
||||
self.app.flag_new_announces = False
|
||||
|
||||
def update_widget(self):
|
||||
if self.list == None:
|
||||
self.list = MDList()
|
||||
|
||||
for announce in self.announces:
|
||||
context_dest = announce["dest"]
|
||||
ts = announce["time"]
|
||||
a_data = announce["data"]
|
||||
|
||||
if not context_dest in self.added_item_dests:
|
||||
if self.app.sideband.is_trusted(context_dest):
|
||||
trust_icon = "account-check"
|
||||
else:
|
||||
trust_icon = "account-question"
|
||||
|
||||
def gen_info(ts, dest, name):
|
||||
def x(sender):
|
||||
yes_button = MDFlatButton(
|
||||
text="OK",
|
||||
)
|
||||
|
||||
dialog = MDDialog(
|
||||
text="Announce Received: "+ts+"\nAnnounced Name: "+name+"\nLXMF Address: "+RNS.prettyhexrep(dest),
|
||||
buttons=[ yes_button ],
|
||||
)
|
||||
def dl_yes(s):
|
||||
dialog.dismiss()
|
||||
|
||||
yes_button.bind(on_release=dl_yes)
|
||||
item.dmenu.dismiss()
|
||||
dialog.open()
|
||||
return x
|
||||
|
||||
time_string = time.strftime(ts_format, time.localtime(ts))
|
||||
disp_name = self.app.sideband.peer_display_name(context_dest)
|
||||
iconl = IconLeftWidget(icon=trust_icon)
|
||||
item = OneLineAvatarIconListItem(text=time_string+": "+disp_name, on_release=gen_info(time_string, context_dest, a_data))
|
||||
item.add_widget(iconl)
|
||||
item.sb_uid = context_dest
|
||||
|
||||
def gen_del(dest, item):
|
||||
def x():
|
||||
yes_button = MDFlatButton(
|
||||
text="Yes",
|
||||
)
|
||||
no_button = MDFlatButton(
|
||||
text="No",
|
||||
)
|
||||
dialog = MDDialog(
|
||||
text="Delete announce?",
|
||||
buttons=[ yes_button, no_button ],
|
||||
)
|
||||
def dl_yes(s):
|
||||
dialog.dismiss()
|
||||
self.app.sideband.delete_announce(dest)
|
||||
self.reload()
|
||||
def dl_no(s):
|
||||
dialog.dismiss()
|
||||
|
||||
yes_button.bind(on_release=dl_yes)
|
||||
no_button.bind(on_release=dl_no)
|
||||
item.dmenu.dismiss()
|
||||
dialog.open()
|
||||
return x
|
||||
|
||||
def gen_conv(dest, item):
|
||||
def x():
|
||||
item.dmenu.dismiss()
|
||||
self.app.conversation_from_announce_action(dest)
|
||||
return x
|
||||
|
||||
dm_items = [
|
||||
{
|
||||
"viewclass": "OneLineListItem",
|
||||
"text": "Converse",
|
||||
"height": dp(64),
|
||||
"on_release": gen_conv(context_dest, item)
|
||||
},
|
||||
# {
|
||||
# "text": "Delete Announce",
|
||||
# "viewclass": "OneLineListItem",
|
||||
# "height": dp(64),
|
||||
# "on_release": gen_del(context_dest, item)
|
||||
# }
|
||||
]
|
||||
|
||||
item.iconr = IconRightWidget(icon="dots-vertical");
|
||||
|
||||
item.dmenu = MDDropdownMenu(
|
||||
caller=item.iconr,
|
||||
items=dm_items,
|
||||
position="center",
|
||||
width_mult=4,
|
||||
)
|
||||
|
||||
def callback_factory(ref):
|
||||
def x(sender):
|
||||
ref.dmenu.open()
|
||||
return x
|
||||
|
||||
item.iconr.bind(on_release=callback_factory(item))
|
||||
|
||||
item.add_widget(item.iconr)
|
||||
|
||||
self.added_item_dests.append(context_dest)
|
||||
self.list.add_widget(item)
|
||||
|
||||
def get_widget(self):
|
||||
return self.list
|
||||
228
ui/conversations.py
Normal file
228
ui/conversations.py
Normal file
|
|
@ -0,0 +1,228 @@
|
|||
import RNS
|
||||
|
||||
from kivy.metrics import dp
|
||||
from kivy.uix.boxlayout import BoxLayout
|
||||
from kivy.properties import StringProperty, BooleanProperty
|
||||
from kivymd.uix.list import MDList, IconLeftWidget, IconRightWidget, OneLineAvatarIconListItem
|
||||
from kivymd.uix.menu import MDDropdownMenu
|
||||
from kivy.uix.gridlayout import GridLayout
|
||||
from kivy.uix.boxlayout import BoxLayout
|
||||
|
||||
from kivymd.uix.button import MDFlatButton
|
||||
from kivymd.uix.dialog import MDDialog
|
||||
|
||||
|
||||
class NewConv(BoxLayout):
|
||||
pass
|
||||
|
||||
|
||||
class MsgSync(BoxLayout):
|
||||
pass
|
||||
|
||||
|
||||
class ConvSettings(BoxLayout):
|
||||
disp_name = StringProperty()
|
||||
trusted = BooleanProperty()
|
||||
|
||||
|
||||
class Conversations():
|
||||
def __init__(self, app):
|
||||
self.app = app
|
||||
self.context_dests = []
|
||||
self.added_item_dests = []
|
||||
self.list = None
|
||||
self.update()
|
||||
|
||||
def reload(self):
|
||||
self.clear_list()
|
||||
self.update()
|
||||
|
||||
def clear_list(self):
|
||||
if self.list != None:
|
||||
self.list.clear_widgets()
|
||||
|
||||
self.context_dests = []
|
||||
self.added_item_dests = []
|
||||
|
||||
def update(self):
|
||||
if self.app.flag_unread_conversations:
|
||||
self.clear_list()
|
||||
|
||||
self.context_dests = self.app.sideband.list_conversations()
|
||||
self.update_widget()
|
||||
|
||||
self.app.flag_new_conversations = False
|
||||
self.app.flag_unread_conversations = False
|
||||
|
||||
def update_widget(self):
|
||||
if self.list == None:
|
||||
self.list = MDList()
|
||||
|
||||
for conv in self.context_dests:
|
||||
context_dest = conv["dest"]
|
||||
unread = conv["unread"]
|
||||
|
||||
if not context_dest in self.added_item_dests:
|
||||
if self.app.sideband.is_trusted(context_dest):
|
||||
if unread:
|
||||
trust_icon = "email-seal"
|
||||
else:
|
||||
trust_icon = "account-check"
|
||||
else:
|
||||
if unread:
|
||||
trust_icon = "email"
|
||||
else:
|
||||
trust_icon = "account-question"
|
||||
|
||||
iconl = IconLeftWidget(icon=trust_icon)
|
||||
item = OneLineAvatarIconListItem(text=self.app.sideband.peer_display_name(context_dest), on_release=self.app.conversation_action)
|
||||
item.add_widget(iconl)
|
||||
item.sb_uid = context_dest
|
||||
|
||||
def gen_edit(dest, item):
|
||||
def x():
|
||||
try:
|
||||
disp_name = self.app.sideband.raw_display_name(dest)
|
||||
is_trusted = self.app.sideband.is_trusted(dest)
|
||||
|
||||
yes_button = MDFlatButton(
|
||||
text="Save",
|
||||
font_size=dp(20),
|
||||
)
|
||||
no_button = MDFlatButton(
|
||||
text="Cancel",
|
||||
font_size=dp(20),
|
||||
)
|
||||
dialog_content = ConvSettings(disp_name=disp_name, trusted=is_trusted)
|
||||
dialog = MDDialog(
|
||||
title="Conversation with "+RNS.prettyhexrep(dest),
|
||||
type="custom",
|
||||
content_cls=dialog_content,
|
||||
buttons=[ yes_button, no_button ],
|
||||
)
|
||||
dialog.d_content = dialog_content
|
||||
def dl_yes(s):
|
||||
try:
|
||||
name = dialog.d_content.ids["name_field"].text
|
||||
trusted = dialog.d_content.ids["trusted_switch"].active
|
||||
if trusted:
|
||||
RNS.log("Setting Trusted "+str(trusted))
|
||||
self.app.sideband.trusted_conversation(dest)
|
||||
else:
|
||||
RNS.log("Setting Untrusted "+str(trusted))
|
||||
self.app.sideband.untrusted_conversation(dest)
|
||||
|
||||
RNS.log("Name="+name)
|
||||
self.app.sideband.named_conversation(name, dest)
|
||||
|
||||
except Exception as e:
|
||||
RNS.log("Error while saving conversation settings: "+str(e), RNS.LOG_ERROR)
|
||||
|
||||
dialog.dismiss()
|
||||
self.reload()
|
||||
|
||||
def dl_no(s):
|
||||
dialog.dismiss()
|
||||
|
||||
yes_button.bind(on_release=dl_yes)
|
||||
no_button.bind(on_release=dl_no)
|
||||
item.dmenu.dismiss()
|
||||
dialog.open()
|
||||
except Exception as e:
|
||||
RNS.log("Error while creating conversation settings: "+str(e), RNS.LOG_ERROR)
|
||||
|
||||
return x
|
||||
|
||||
def gen_clear(dest, item):
|
||||
def x():
|
||||
yes_button = MDFlatButton(
|
||||
text="Yes",
|
||||
)
|
||||
no_button = MDFlatButton(
|
||||
text="No",
|
||||
)
|
||||
dialog = MDDialog(
|
||||
text="Clear all messages in conversation?",
|
||||
buttons=[ yes_button, no_button ],
|
||||
)
|
||||
def dl_yes(s):
|
||||
dialog.dismiss()
|
||||
self.app.sideband.clear_conversation(dest)
|
||||
def dl_no(s):
|
||||
dialog.dismiss()
|
||||
|
||||
yes_button.bind(on_release=dl_yes)
|
||||
no_button.bind(on_release=dl_no)
|
||||
item.dmenu.dismiss()
|
||||
dialog.open()
|
||||
return x
|
||||
|
||||
def gen_del(dest, item):
|
||||
def x():
|
||||
yes_button = MDFlatButton(
|
||||
text="Yes",
|
||||
)
|
||||
no_button = MDFlatButton(
|
||||
text="No",
|
||||
)
|
||||
dialog = MDDialog(
|
||||
text="Delete conversation?",
|
||||
buttons=[ yes_button, no_button ],
|
||||
)
|
||||
def dl_yes(s):
|
||||
dialog.dismiss()
|
||||
self.app.sideband.delete_conversation(dest)
|
||||
self.reload()
|
||||
def dl_no(s):
|
||||
dialog.dismiss()
|
||||
|
||||
yes_button.bind(on_release=dl_yes)
|
||||
no_button.bind(on_release=dl_no)
|
||||
item.dmenu.dismiss()
|
||||
dialog.open()
|
||||
return x
|
||||
|
||||
dm_items = [
|
||||
{
|
||||
"viewclass": "OneLineListItem",
|
||||
"text": "Edit",
|
||||
"height": dp(64),
|
||||
"on_release": gen_edit(context_dest, item)
|
||||
},
|
||||
{
|
||||
"text": "Clear Messages",
|
||||
"viewclass": "OneLineListItem",
|
||||
"height": dp(64),
|
||||
"on_release": gen_clear(context_dest, item)
|
||||
},
|
||||
{
|
||||
"text": "Delete Conversation",
|
||||
"viewclass": "OneLineListItem",
|
||||
"height": dp(64),
|
||||
"on_release": gen_del(context_dest, item)
|
||||
}
|
||||
]
|
||||
|
||||
item.iconr = IconRightWidget(icon="dots-vertical");
|
||||
|
||||
item.dmenu = MDDropdownMenu(
|
||||
caller=item.iconr,
|
||||
items=dm_items,
|
||||
position="center",
|
||||
width_mult=4,
|
||||
)
|
||||
|
||||
def callback_factory(ref):
|
||||
def x(sender):
|
||||
ref.dmenu.open()
|
||||
return x
|
||||
|
||||
item.iconr.bind(on_release=callback_factory(item))
|
||||
|
||||
item.add_widget(item.iconr)
|
||||
|
||||
self.added_item_dests.append(context_dest)
|
||||
self.list.add_widget(item)
|
||||
|
||||
def get_widget(self):
|
||||
return self.list
|
||||
30
ui/helpers.py
Normal file
30
ui/helpers.py
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
from kivy.utils import get_color_from_hex
|
||||
from kivymd.color_definitions import colors
|
||||
from kivy.uix.screenmanager import ScreenManager, Screen
|
||||
from kivymd.theming import ThemableBehavior
|
||||
from kivymd.uix.list import OneLineIconListItem, MDList, IconLeftWidget, IconRightWidget
|
||||
from kivy.properties import StringProperty
|
||||
|
||||
ts_format = "%Y-%m-%d %H:%M:%S"
|
||||
|
||||
def mdc(color, hue=None):
|
||||
if hue == None:
|
||||
hue = "400"
|
||||
return get_color_from_hex(colors[color][hue])
|
||||
|
||||
color_received = "Green"
|
||||
color_delivered = "Indigo"
|
||||
color_propagated = "Blue"
|
||||
color_failed = "Red"
|
||||
color_unknown = "Gray"
|
||||
intensity_msgs = "600"
|
||||
|
||||
class ContentNavigationDrawer(Screen):
|
||||
pass
|
||||
|
||||
class DrawerList(ThemableBehavior, MDList):
|
||||
pass
|
||||
|
||||
class IconListItem(OneLineIconListItem):
|
||||
icon = StringProperty()
|
||||
|
||||
675
ui/layouts.py
Normal file
675
ui/layouts.py
Normal file
|
|
@ -0,0 +1,675 @@
|
|||
root_layout = """
|
||||
MDNavigationLayout:
|
||||
|
||||
ScreenManager:
|
||||
id: screen_manager
|
||||
|
||||
MDScreen:
|
||||
name: "conversations_screen"
|
||||
|
||||
BoxLayout:
|
||||
orientation: "vertical"
|
||||
|
||||
MDToolbar:
|
||||
title: "Conversations"
|
||||
elevation: 10
|
||||
pos_hint: {"top": 1}
|
||||
left_action_items:
|
||||
[['menu', lambda x: nav_drawer.set_state("open")]]
|
||||
right_action_items:
|
||||
[
|
||||
['access-point', lambda x: root.ids.screen_manager.app.announce_now_action(self)],
|
||||
['email-sync', lambda x: root.ids.screen_manager.app.lxmf_sync_action(self)],
|
||||
['account-plus', lambda x: root.ids.screen_manager.app.new_conversation_action(self)],
|
||||
]
|
||||
|
||||
ScrollView:
|
||||
id: conversations_scrollview
|
||||
|
||||
|
||||
MDScreen:
|
||||
name: "messages_screen"
|
||||
|
||||
BoxLayout:
|
||||
orientation: "vertical"
|
||||
|
||||
MDToolbar:
|
||||
id: messages_toolbar
|
||||
title: "Messages"
|
||||
elevation: 10
|
||||
pos_hint: {"top": 1}
|
||||
left_action_items:
|
||||
[['menu', lambda x: nav_drawer.set_state("open")]]
|
||||
right_action_items:
|
||||
[
|
||||
['lan-connect', lambda x: root.ids.screen_manager.app.message_propagation_action(self)],
|
||||
['close', lambda x: root.ids.screen_manager.app.close_messages_action(self)],
|
||||
]
|
||||
|
||||
ScrollView:
|
||||
id: messages_scrollview
|
||||
do_scroll_x: False
|
||||
do_scroll_y: True
|
||||
|
||||
BoxLayout:
|
||||
orientation: "vertical"
|
||||
id: no_keys_part
|
||||
padding: [dp(28), dp(16), dp(16), dp(16)]
|
||||
spacing: dp(24)
|
||||
size_hint_y: None
|
||||
height: self.minimum_height + dp(64)
|
||||
|
||||
MDLabel:
|
||||
id: nokeys_text
|
||||
text: ""
|
||||
|
||||
MDRectangleFlatIconButton:
|
||||
icon: "key-wireless"
|
||||
text: "Query Network For Keys"
|
||||
# padding: [dp(16), dp(16), dp(16), dp(16)]
|
||||
on_release: root.ids.screen_manager.app.key_query_action(self)
|
||||
|
||||
|
||||
BoxLayout:
|
||||
id: message_input_part
|
||||
# orientation: "vertical"
|
||||
padding: [dp(28), dp(16), dp(16), dp(16)]
|
||||
spacing: dp(24)
|
||||
size_hint_y: None
|
||||
height: self.minimum_height
|
||||
|
||||
MDTextField:
|
||||
id: message_text
|
||||
multiline: True
|
||||
hint_text: "Write message"
|
||||
mode: "rectangle"
|
||||
max_height: dp(100)
|
||||
|
||||
MDRectangleFlatIconButton:
|
||||
icon: "transfer-up"
|
||||
text: "Send"
|
||||
# padding: [dp(16), dp(16), dp(16), dp(16)]
|
||||
on_release: root.ids.screen_manager.app.message_send_action(self)
|
||||
|
||||
|
||||
MDScreen:
|
||||
name: "broadcasts_screen"
|
||||
|
||||
BoxLayout:
|
||||
orientation: "vertical"
|
||||
|
||||
MDToolbar:
|
||||
title: "Local Broadcasts"
|
||||
elevation: 10
|
||||
pos_hint: {"top": 1}
|
||||
left_action_items:
|
||||
[['menu', lambda x: nav_drawer.set_state("open")]]
|
||||
|
||||
ScrollView:
|
||||
id: broadcasts_scrollview
|
||||
|
||||
MDBoxLayout:
|
||||
orientation: "vertical"
|
||||
spacing: "24dp"
|
||||
size_hint_y: None
|
||||
height: self.minimum_height
|
||||
padding: dp(64)
|
||||
|
||||
MDLabel:
|
||||
id: broadcasts_info
|
||||
markup: True
|
||||
text: ""
|
||||
size_hint_y: None
|
||||
text_size: self.width, None
|
||||
height: self.texture_size[1]
|
||||
|
||||
|
||||
MDScreen:
|
||||
name: "connectivity_screen"
|
||||
|
||||
BoxLayout:
|
||||
orientation: "vertical"
|
||||
|
||||
MDToolbar:
|
||||
title: "Connectivity"
|
||||
elevation: 10
|
||||
pos_hint: {"top": 1}
|
||||
left_action_items:
|
||||
[['menu', lambda x: nav_drawer.set_state("open")]]
|
||||
|
||||
ScrollView:
|
||||
id:connectivity_scrollview
|
||||
|
||||
MDBoxLayout:
|
||||
orientation: "vertical"
|
||||
spacing: "24dp"
|
||||
size_hint_y: None
|
||||
height: self.minimum_height
|
||||
padding: dp(64)
|
||||
|
||||
MDLabel:
|
||||
id: connectivity_info
|
||||
markup: True
|
||||
text: ""
|
||||
size_hint_y: None
|
||||
text_size: self.width, None
|
||||
height: self.texture_size[1]
|
||||
|
||||
|
||||
MDScreen:
|
||||
name: "guide_screen"
|
||||
|
||||
BoxLayout:
|
||||
orientation: "vertical"
|
||||
|
||||
MDToolbar:
|
||||
title: "Guide"
|
||||
elevation: 10
|
||||
pos_hint: {"top": 1}
|
||||
left_action_items:
|
||||
[['menu', lambda x: nav_drawer.set_state("open")]]
|
||||
|
||||
ScrollView:
|
||||
id:guide_scrollview
|
||||
|
||||
MDBoxLayout:
|
||||
orientation: "vertical"
|
||||
spacing: "24dp"
|
||||
size_hint_y: None
|
||||
height: self.minimum_height
|
||||
padding: dp(64)
|
||||
|
||||
MDLabel:
|
||||
id: guide_info
|
||||
markup: True
|
||||
text: ""
|
||||
size_hint_y: None
|
||||
text_size: self.width, None
|
||||
height: self.texture_size[1]
|
||||
|
||||
|
||||
MDScreen:
|
||||
name: "information_screen"
|
||||
|
||||
BoxLayout:
|
||||
orientation: "vertical"
|
||||
|
||||
MDToolbar:
|
||||
title: "App & Version Information"
|
||||
elevation: 10
|
||||
pos_hint: {"top": 1}
|
||||
left_action_items:
|
||||
[['menu', lambda x: nav_drawer.set_state("open")]]
|
||||
|
||||
ScrollView:
|
||||
id:information_scrollview
|
||||
|
||||
MDBoxLayout:
|
||||
orientation: "vertical"
|
||||
spacing: "24dp"
|
||||
size_hint_y: None
|
||||
height: self.minimum_height
|
||||
padding: dp(64)
|
||||
|
||||
MDLabel:
|
||||
id: information_info
|
||||
markup: True
|
||||
text: ""
|
||||
size_hint_y: None
|
||||
text_size: self.width, None
|
||||
height: self.texture_size[1]
|
||||
|
||||
|
||||
MDScreen:
|
||||
name: "map_screen"
|
||||
|
||||
BoxLayout:
|
||||
orientation: "vertical"
|
||||
|
||||
MDToolbar:
|
||||
title: "Local Area Map"
|
||||
elevation: 10
|
||||
pos_hint: {"top": 1}
|
||||
left_action_items:
|
||||
[['menu', lambda x: nav_drawer.set_state("open")]]
|
||||
|
||||
ScrollView:
|
||||
id:information_scrollview
|
||||
|
||||
MDBoxLayout:
|
||||
orientation: "vertical"
|
||||
spacing: "24dp"
|
||||
size_hint_y: None
|
||||
height: self.minimum_height
|
||||
padding: dp(64)
|
||||
|
||||
MDLabel:
|
||||
id: map_info
|
||||
markup: True
|
||||
text: ""
|
||||
size_hint_y: None
|
||||
text_size: self.width, None
|
||||
height: self.texture_size[1]
|
||||
|
||||
|
||||
MDScreen:
|
||||
name: "keys_screen"
|
||||
|
||||
BoxLayout:
|
||||
orientation: "vertical"
|
||||
|
||||
MDToolbar:
|
||||
title: "Encryption Keys"
|
||||
elevation: 10
|
||||
pos_hint: {"top": 1}
|
||||
left_action_items:
|
||||
[['menu', lambda x: nav_drawer.set_state("open")]]
|
||||
|
||||
ScrollView:
|
||||
id:keys_scrollview
|
||||
|
||||
MDBoxLayout:
|
||||
orientation: "vertical"
|
||||
spacing: "24dp"
|
||||
size_hint_y: None
|
||||
height: self.minimum_height
|
||||
padding: dp(64)
|
||||
|
||||
MDLabel:
|
||||
id: keys_info
|
||||
markup: True
|
||||
text: ""
|
||||
size_hint_y: None
|
||||
text_size: self.width, None
|
||||
height: self.texture_size[1]
|
||||
|
||||
|
||||
MDScreen:
|
||||
name: "announces_screen"
|
||||
|
||||
BoxLayout:
|
||||
orientation: "vertical"
|
||||
|
||||
MDToolbar:
|
||||
title: "Announce Stream"
|
||||
elevation: 10
|
||||
pos_hint: {"top": 1}
|
||||
left_action_items:
|
||||
[['menu', lambda x: nav_drawer.set_state("open")]]
|
||||
right_action_items:
|
||||
[
|
||||
['close', lambda x: root.ids.screen_manager.app.close_settings_action(self)],
|
||||
]
|
||||
# [['eye-off', lambda x: root.ids.screen_manager.app.announce_filter_action(self)]]
|
||||
|
||||
ScrollView:
|
||||
id: announces_scrollview
|
||||
|
||||
MDBoxLayout:
|
||||
orientation: "vertical"
|
||||
spacing: "24dp"
|
||||
size_hint_y: None
|
||||
height: self.minimum_height
|
||||
padding: dp(64)
|
||||
|
||||
MDLabel:
|
||||
id: announces_info
|
||||
markup: True
|
||||
text: ""
|
||||
size_hint_y: None
|
||||
text_size: self.width, None
|
||||
height: self.texture_size[1]
|
||||
|
||||
|
||||
MDScreen:
|
||||
name: "settings_screen"
|
||||
|
||||
BoxLayout:
|
||||
orientation: "vertical"
|
||||
|
||||
MDToolbar:
|
||||
title: "Settings"
|
||||
elevation: 10
|
||||
pos_hint: {"top": 1}
|
||||
left_action_items:
|
||||
[['menu', lambda x: nav_drawer.set_state("open")]]
|
||||
right_action_items:
|
||||
[
|
||||
['close', lambda x: root.ids.screen_manager.app.close_settings_action(self)],
|
||||
]
|
||||
|
||||
ScrollView:
|
||||
id: settings_scrollview
|
||||
|
||||
MDBoxLayout:
|
||||
orientation: "vertical"
|
||||
spacing: "24dp"
|
||||
size_hint_y: None
|
||||
height: self.minimum_height
|
||||
padding: dp(16)
|
||||
|
||||
MDLabel:
|
||||
text: ""
|
||||
font_style: "H6"
|
||||
|
||||
MDLabel:
|
||||
text: "User Options"
|
||||
font_style: "H6"
|
||||
|
||||
MDTextField:
|
||||
id: settings_display_name
|
||||
hint_text: "Display Name"
|
||||
text: ""
|
||||
max_text_length: 128
|
||||
font_size: dp(24)
|
||||
|
||||
MDTextField:
|
||||
id: settings_lxmf_address
|
||||
hint_text: "Your LXMF Address"
|
||||
text: ""
|
||||
disabled: False
|
||||
max_text_length: 20
|
||||
font_size: dp(24)
|
||||
|
||||
MDTextField:
|
||||
id: settings_propagation_node_address
|
||||
hint_text: "LXMF Propagation Node"
|
||||
disabled: False
|
||||
text: ""
|
||||
max_text_length: 20
|
||||
font_size: dp(24)
|
||||
|
||||
MDTextField:
|
||||
id: settings_home_node_address
|
||||
hint_text: "Nomad Network Home Node"
|
||||
disabled: False
|
||||
text: ""
|
||||
max_text_length: 20
|
||||
font_size: dp(24)
|
||||
|
||||
MDBoxLayout:
|
||||
orientation: "horizontal"
|
||||
# spacing: "24dp"
|
||||
size_hint_y: None
|
||||
height: dp(48)
|
||||
|
||||
MDLabel:
|
||||
text: "Announce At App Startup"
|
||||
font_style: "H6"
|
||||
|
||||
MDSwitch:
|
||||
id: settings_start_announce
|
||||
active: False
|
||||
|
||||
MDBoxLayout:
|
||||
orientation: "horizontal"
|
||||
# spacing: "24dp"
|
||||
size_hint_y: None
|
||||
height: dp(48)
|
||||
|
||||
MDLabel:
|
||||
text: "Deliver via LXMF Propagation Node by default"
|
||||
font_style: "H6"
|
||||
|
||||
MDSwitch:
|
||||
id: settings_lxmf_delivery_by_default
|
||||
disabled: False
|
||||
active: False
|
||||
|
||||
MDBoxLayout:
|
||||
orientation: "horizontal"
|
||||
# spacing: "24dp"
|
||||
size_hint_y: None
|
||||
height: dp(48)
|
||||
|
||||
MDLabel:
|
||||
text: "Limit each sync to 3 messages"
|
||||
font_style: "H6"
|
||||
|
||||
MDSwitch:
|
||||
id: settings_lxmf_sync_limit
|
||||
disabled: False
|
||||
active: False
|
||||
|
||||
MDBoxLayout:
|
||||
orientation: "horizontal"
|
||||
# spacing: "24dp"
|
||||
size_hint_y: None
|
||||
height: dp(48)
|
||||
|
||||
MDLabel:
|
||||
text: "Use Home Node as Broadcast Repeater"
|
||||
font_style: "H6"
|
||||
|
||||
MDSwitch:
|
||||
id: settings_home_node_as_broadcast_repeater
|
||||
active: False
|
||||
disabled: True
|
||||
|
||||
MDBoxLayout:
|
||||
orientation: "horizontal"
|
||||
# spacing: "24dp"
|
||||
size_hint_y: None
|
||||
height: dp(48)
|
||||
|
||||
MDLabel:
|
||||
text: "Send Telemetry to Home Node"
|
||||
font_style: "H6"
|
||||
|
||||
MDSwitch:
|
||||
id: settings_telemetry_to_home_node
|
||||
disabled: True
|
||||
active: False
|
||||
|
||||
|
||||
MDNavigationDrawer:
|
||||
id: nav_drawer
|
||||
|
||||
ContentNavigationDrawer:
|
||||
ScrollView:
|
||||
DrawerList:
|
||||
id: md_list
|
||||
|
||||
MDList:
|
||||
OneLineIconListItem:
|
||||
text: "Conversations"
|
||||
on_release: root.ids.screen_manager.app.conversations_action(self)
|
||||
|
||||
IconLeftWidget:
|
||||
icon: "email"
|
||||
on_release: root.ids.screen_manager.app.conversations_action(self)
|
||||
|
||||
|
||||
OneLineIconListItem:
|
||||
text: "Announce Stream"
|
||||
on_release: root.ids.screen_manager.app.announces_action(self)
|
||||
|
||||
IconLeftWidget:
|
||||
icon: "account-voice"
|
||||
on_release: root.ids.screen_manager.app.announces_action(self)
|
||||
|
||||
|
||||
OneLineIconListItem:
|
||||
text: "Local Broadcasts"
|
||||
on_release: root.ids.screen_manager.app.broadcasts_action(self)
|
||||
|
||||
IconLeftWidget:
|
||||
icon: "radio-tower"
|
||||
on_release: root.ids.screen_manager.app.broadcasts_action(self)
|
||||
|
||||
|
||||
OneLineIconListItem:
|
||||
text: "Local Area Map"
|
||||
on_release: root.ids.screen_manager.app.map_action(self)
|
||||
|
||||
IconLeftWidget:
|
||||
icon: "map"
|
||||
on_release: root.ids.screen_manager.app.map_action(self)
|
||||
|
||||
|
||||
OneLineIconListItem:
|
||||
text: "Connectivity"
|
||||
on_release: root.ids.screen_manager.app.connectivity_action(self)
|
||||
_no_ripple_effect: True
|
||||
|
||||
IconLeftWidget:
|
||||
icon: "wifi"
|
||||
on_release: root.ids.screen_manager.app.connectivity_action(self)
|
||||
|
||||
|
||||
OneLineIconListItem:
|
||||
text: "Settings"
|
||||
on_release: root.ids.screen_manager.app.settings_action(self)
|
||||
_no_ripple_effect: True
|
||||
|
||||
IconLeftWidget:
|
||||
icon: "cog"
|
||||
on_release: root.ids.screen_manager.app.settings_action(self)
|
||||
|
||||
|
||||
OneLineIconListItem:
|
||||
text: "Encryption Keys"
|
||||
on_release: root.ids.screen_manager.app.keys_action(self)
|
||||
_no_ripple_effect: True
|
||||
|
||||
IconLeftWidget:
|
||||
icon: "key-chain"
|
||||
on_release: root.ids.screen_manager.app.keys_action(self)
|
||||
|
||||
|
||||
OneLineIconListItem:
|
||||
text: "Guide"
|
||||
on_release: root.ids.screen_manager.app.guide_action(self)
|
||||
_no_ripple_effect: True
|
||||
|
||||
IconLeftWidget:
|
||||
icon: "book-open"
|
||||
on_release: root.ids.screen_manager.app.guide_action(self)
|
||||
|
||||
|
||||
OneLineIconListItem:
|
||||
id: app_version_info
|
||||
text: ""
|
||||
on_release: root.ids.screen_manager.app.information_action(self)
|
||||
_no_ripple_effect: True
|
||||
|
||||
IconLeftWidget:
|
||||
icon: "information"
|
||||
on_release: root.ids.screen_manager.app.information_action(self)
|
||||
|
||||
|
||||
OneLineIconListItem:
|
||||
text: "Shutdown"
|
||||
on_release: root.ids.screen_manager.app.quit_action(self)
|
||||
_no_ripple_effect: True
|
||||
|
||||
IconLeftWidget:
|
||||
icon: "power"
|
||||
on_release: root.ids.screen_manager.app.quit_action(self)
|
||||
|
||||
<ListLXMessageCard>:
|
||||
padding: dp(8)
|
||||
size_hint: 1.0, None
|
||||
height: content_text.height + heading_text.height + dp(32)
|
||||
pos_hint: {"center_x": .5, "center_y": .5}
|
||||
|
||||
MDRelativeLayout:
|
||||
size_hint: 1.0, None
|
||||
# size: root.size
|
||||
|
||||
MDIconButton:
|
||||
id: msg_submenu
|
||||
icon: "dots-vertical"
|
||||
pos:
|
||||
root.width - (self.width + root.padding[0] + dp(4)), root.height - (self.height + root.padding[0] + dp(4))
|
||||
|
||||
MDLabel:
|
||||
id: heading_text
|
||||
markup: True
|
||||
text: root.heading
|
||||
adaptive_size: True
|
||||
pos: 0, root.height - (self.height + root.padding[0] + dp(8))
|
||||
|
||||
MDLabel:
|
||||
id: content_text
|
||||
text: root.text
|
||||
# adaptive_size: True
|
||||
size_hint_y: None
|
||||
text_size: self.width, None
|
||||
height: self.texture_size[1]
|
||||
|
||||
<MsgSync>
|
||||
orientation: "vertical"
|
||||
spacing: "24dp"
|
||||
size_hint_y: None
|
||||
height: self.minimum_height+dp(24)
|
||||
|
||||
MDLabel:
|
||||
id: sync_status
|
||||
hint_text: "Name"
|
||||
text: "Initiating sync..."
|
||||
|
||||
MDProgressBar:
|
||||
id: sync_progress
|
||||
value: 0
|
||||
|
||||
<ConvSettings>
|
||||
orientation: "vertical"
|
||||
spacing: "24dp"
|
||||
size_hint_y: None
|
||||
height: dp(148)
|
||||
|
||||
MDTextField:
|
||||
id: name_field
|
||||
hint_text: "Name"
|
||||
text: root.disp_name
|
||||
font_size: dp(24)
|
||||
|
||||
MDBoxLayout:
|
||||
orientation: "horizontal"
|
||||
# spacing: "24dp"
|
||||
size_hint_y: None
|
||||
height: dp(48)
|
||||
MDLabel:
|
||||
id: trusted_switch_label
|
||||
text: "Trusted"
|
||||
font_style: "H6"
|
||||
|
||||
MDSwitch:
|
||||
id: trusted_switch
|
||||
active: root.trusted
|
||||
|
||||
<NewConv>
|
||||
orientation: "vertical"
|
||||
spacing: "24dp"
|
||||
size_hint_y: None
|
||||
height: dp(250)
|
||||
|
||||
MDTextField:
|
||||
id: n_address_field
|
||||
max_text_length: 20
|
||||
hint_text: "Address"
|
||||
helper_text: "Error, check your input"
|
||||
helper_text_mode: "on_error"
|
||||
text: ""
|
||||
font_size: dp(24)
|
||||
|
||||
MDTextField:
|
||||
id: n_name_field
|
||||
hint_text: "Name"
|
||||
text: ""
|
||||
font_size: dp(24)
|
||||
|
||||
MDBoxLayout:
|
||||
orientation: "horizontal"
|
||||
size_hint_y: None
|
||||
height: dp(48)
|
||||
MDLabel:
|
||||
id: "trusted_switch_label"
|
||||
text: "Trusted"
|
||||
font_style: "H6"
|
||||
|
||||
MDSwitch:
|
||||
id: n_trusted
|
||||
active: False
|
||||
"""
|
||||
207
ui/messages.py
Normal file
207
ui/messages.py
Normal file
|
|
@ -0,0 +1,207 @@
|
|||
import time
|
||||
import RNS
|
||||
import LXMF
|
||||
|
||||
from kivy.metrics import dp
|
||||
from kivy.core.clipboard import Clipboard
|
||||
from kivymd.uix.card import MDCard
|
||||
from kivymd.uix.menu import MDDropdownMenu
|
||||
from kivymd.uix.behaviors import RoundedRectangularElevationBehavior
|
||||
from kivy.properties import StringProperty, BooleanProperty
|
||||
from kivy.uix.gridlayout import GridLayout
|
||||
from kivy.uix.boxlayout import BoxLayout
|
||||
|
||||
from kivymd.uix.button import MDFlatButton
|
||||
from kivymd.uix.dialog import MDDialog
|
||||
|
||||
from ui.helpers import ts_format, mdc
|
||||
from ui.helpers import color_received, color_delivered, color_propagated, color_failed, color_unknown, intensity_msgs
|
||||
|
||||
class ListLXMessageCard(MDCard, RoundedRectangularElevationBehavior):
|
||||
text = StringProperty()
|
||||
heading = StringProperty()
|
||||
|
||||
class Messages():
|
||||
def __init__(self, app, context_dest):
|
||||
self.app = app
|
||||
self.context_dest = context_dest
|
||||
self.messages = []
|
||||
self.added_item_hashes = []
|
||||
self.latest_message_timestamp = None
|
||||
self.list = None
|
||||
self.widgets = []
|
||||
self.send_error_dialog = None
|
||||
self.update()
|
||||
|
||||
def reload(self):
|
||||
if self.list != None:
|
||||
self.list.clear_widgets()
|
||||
|
||||
self.messages = []
|
||||
self.added_item_hashes = []
|
||||
self.latest_message_timestamp = None
|
||||
self.widgets = []
|
||||
|
||||
self.update()
|
||||
|
||||
def update(self):
|
||||
self.messages = self.app.sideband.list_messages(self.context_dest, self.latest_message_timestamp)
|
||||
if self.list == None:
|
||||
layout = GridLayout(cols=1, spacing=16, padding=16, size_hint_y=None)
|
||||
layout.bind(minimum_height=layout.setter('height'))
|
||||
self.list = layout
|
||||
|
||||
if len(self.messages) > 0:
|
||||
self.update_widget()
|
||||
|
||||
for w in self.widgets:
|
||||
m = w.m
|
||||
if m["state"] == LXMF.LXMessage.SENDING or m["state"] == LXMF.LXMessage.OUTBOUND:
|
||||
msg = self.app.sideband.message(m["hash"])
|
||||
if msg["state"] == LXMF.LXMessage.DELIVERED:
|
||||
w.md_bg_color = msg_color = mdc(color_delivered, intensity_msgs)
|
||||
txstr = time.strftime(ts_format, time.localtime(msg["sent"]))
|
||||
titlestr = ""
|
||||
if msg["title"]:
|
||||
titlestr = "[b]Title[/b] "+msg["title"].decode("utf-8")+"\n"
|
||||
w.heading = titlestr+"[b]Sent[/b] "+txstr+" [b]State[/b] Delivered"
|
||||
m["state"] = msg["state"]
|
||||
|
||||
if msg["method"] == LXMF.LXMessage.PROPAGATED and msg["state"] == LXMF.LXMessage.SENT:
|
||||
w.md_bg_color = msg_color = mdc(color_propagated, intensity_msgs)
|
||||
txstr = time.strftime(ts_format, time.localtime(msg["sent"]))
|
||||
titlestr = ""
|
||||
if msg["title"]:
|
||||
titlestr = "[b]Title[/b] "+msg["title"].decode("utf-8")+"\n"
|
||||
w.heading = titlestr+"[b]Sent[/b] "+txstr+" [b]State[/b] On Propagation Net"
|
||||
m["state"] = msg["state"]
|
||||
|
||||
if msg["state"] == LXMF.LXMessage.FAILED:
|
||||
w.md_bg_color = msg_color = mdc(color_failed, intensity_msgs)
|
||||
txstr = time.strftime(ts_format, time.localtime(msg["sent"]))
|
||||
titlestr = ""
|
||||
if msg["title"]:
|
||||
titlestr = "[b]Title[/b] "+msg["title"].decode("utf-8")+"\n"
|
||||
w.heading = titlestr+"[b]Sent[/b] "+txstr+" [b]State[/b] Failed"
|
||||
m["state"] = msg["state"]
|
||||
|
||||
|
||||
def update_widget(self):
|
||||
for m in self.messages:
|
||||
if not m["hash"] in self.added_item_hashes:
|
||||
txstr = time.strftime(ts_format, time.localtime(m["sent"]))
|
||||
rxstr = time.strftime(ts_format, time.localtime(m["received"]))
|
||||
titlestr = ""
|
||||
|
||||
if m["title"]:
|
||||
titlestr = "[b]Title[/b] "+m["title"].decode("utf-8")+"\n"
|
||||
|
||||
if m["source"] == self.app.sideband.lxmf_destination.hash:
|
||||
if m["state"] == LXMF.LXMessage.DELIVERED:
|
||||
msg_color = mdc(color_delivered, intensity_msgs)
|
||||
heading_str = titlestr+"[b]Sent[/b] "+txstr+" [b]State[/b] Delivered"
|
||||
|
||||
elif m["method"] == LXMF.LXMessage.PROPAGATED and m["state"] == LXMF.LXMessage.SENT:
|
||||
msg_color = mdc(color_propagated, intensity_msgs)
|
||||
heading_str = titlestr+"[b]Sent[/b] "+txstr+" [b]State[/b] On Propagation Net"
|
||||
|
||||
elif m["state"] == LXMF.LXMessage.FAILED:
|
||||
msg_color = mdc(color_failed, intensity_msgs)
|
||||
heading_str = titlestr+"[b]Sent[/b] "+txstr+" [b]State[/b] Failed"
|
||||
|
||||
elif m["state"] == LXMF.LXMessage.OUTBOUND or m["state"] == LXMF.LXMessage.SENDING:
|
||||
msg_color = mdc(color_unknown, intensity_msgs)
|
||||
heading_str = titlestr+"[b]Sent[/b] "+txstr+" [b]State[/b] Sending "
|
||||
|
||||
else:
|
||||
msg_color = mdc(color_unknown, intensity_msgs)
|
||||
heading_str = titlestr+"[b]Sent[/b] "+txstr+" [b]State[/b] Unknown"
|
||||
|
||||
else:
|
||||
msg_color = mdc("Green", intensity_msgs)
|
||||
heading_str = titlestr+"[b]Sent[/b] "+txstr+"\n[b]Received[/b] "+rxstr
|
||||
|
||||
item = ListLXMessageCard(
|
||||
text=m["content"].decode("utf-8"),
|
||||
heading=heading_str,
|
||||
md_bg_color=msg_color,
|
||||
)
|
||||
item.sb_uid = m["hash"]
|
||||
item.m = m
|
||||
|
||||
def gen_del(mhash, item):
|
||||
def x():
|
||||
yes_button = MDFlatButton(
|
||||
text="Yes",
|
||||
)
|
||||
no_button = MDFlatButton(
|
||||
text="No",
|
||||
)
|
||||
dialog = MDDialog(
|
||||
text="Delete message?",
|
||||
buttons=[ yes_button, no_button ],
|
||||
)
|
||||
def dl_yes(s):
|
||||
dialog.dismiss()
|
||||
self.app.sideband.delete_message(mhash)
|
||||
self.reload()
|
||||
def dl_no(s):
|
||||
dialog.dismiss()
|
||||
|
||||
yes_button.bind(on_release=dl_yes)
|
||||
no_button.bind(on_release=dl_no)
|
||||
item.dmenu.dismiss()
|
||||
dialog.open()
|
||||
return x
|
||||
|
||||
def gen_copy(msg, item):
|
||||
def x():
|
||||
Clipboard.copy(msg)
|
||||
RNS.log(str(item))
|
||||
item.dmenu.dismiss()
|
||||
|
||||
return x
|
||||
|
||||
dm_items = [
|
||||
{
|
||||
"viewclass": "OneLineListItem",
|
||||
"text": "Copy",
|
||||
"height": dp(64),
|
||||
"on_release": gen_copy(m["content"].decode("utf-8"), item)
|
||||
},
|
||||
{
|
||||
"text": "Delete",
|
||||
"viewclass": "OneLineListItem",
|
||||
"height": dp(64),
|
||||
"on_release": gen_del(m["hash"], item)
|
||||
}
|
||||
]
|
||||
|
||||
item.dmenu = MDDropdownMenu(
|
||||
caller=item.ids.msg_submenu,
|
||||
items=dm_items,
|
||||
position="center",
|
||||
width_mult=4,
|
||||
)
|
||||
|
||||
def callback_factory(ref):
|
||||
def x(sender):
|
||||
ref.dmenu.open()
|
||||
return x
|
||||
|
||||
# Bind menu open
|
||||
item.ids.msg_submenu.bind(on_release=callback_factory(item))
|
||||
|
||||
self.added_item_hashes.append(m["hash"])
|
||||
self.widgets.append(item)
|
||||
self.list.add_widget(item)
|
||||
|
||||
if self.latest_message_timestamp == None or m["received"] > self.latest_message_timestamp:
|
||||
self.latest_message_timestamp = m["received"]
|
||||
|
||||
def get_widget(self):
|
||||
return self.list
|
||||
|
||||
def close_send_error_dialog(self, sender=None):
|
||||
if self.send_error_dialog:
|
||||
self.send_error_dialog.dismiss()
|
||||
Loading…
Add table
Add a link
Reference in a new issue