mirror of
https://github.com/liberatedsystems/openCom-Companion.git
synced 2024-11-25 06:40:38 +01:00
Added UI components for telemetry fetching and sending
This commit is contained in:
parent
ad2dd3cba5
commit
cb27a0d774
@ -3126,6 +3126,12 @@ class SidebandApp(MDApp):
|
||||
def close_sub_telemetry_action(self, sender=None):
|
||||
self.telemetry_action(direction="right")
|
||||
|
||||
def converse_from_telemetry(self, sender=None):
|
||||
if self.object_details_screen != None:
|
||||
context_dest = self.object_details_screen.object_hash
|
||||
if not self.object_details_screen.object_hash == self.sideband.lxmf_destination.hash:
|
||||
self.open_conversation(context_dest)
|
||||
|
||||
def telemetry_send_update(self, sender=None):
|
||||
# TODO: Implement
|
||||
pass
|
||||
|
@ -502,6 +502,12 @@ class SidebandCore():
|
||||
self.config["telemetry_send_to_trusted"] = False
|
||||
if not "telemetry_send_to_collector" in self.config:
|
||||
self.config["telemetry_send_to_collector"] = False
|
||||
if not "telemetry_request_from_collector" in self.config:
|
||||
self.config["telemetry_request_from_collector"] = False
|
||||
if not "telemetry_send_interval" in self.config:
|
||||
self.config["telemetry_send_interval"] = 43200
|
||||
if not "telemetry_request_interval" in self.config:
|
||||
self.config["telemetry_request_interval"] = 43200
|
||||
|
||||
if not "telemetry_icon" in self.config:
|
||||
self.config["telemetry_icon"] = SidebandCore.DEFAULT_APPEARANCE[0]
|
||||
@ -716,6 +722,22 @@ class SidebandCore():
|
||||
RNS.log("Error while checking telemetry sending for "+RNS.prettyhexrep(context_dest)+": "+str(e), RNS.LOG_ERROR)
|
||||
return False
|
||||
|
||||
def requests_allowed_from(self, context_dest):
|
||||
try:
|
||||
existing_conv = self._db_conversation(context_dest)
|
||||
if existing_conv != None:
|
||||
cd = existing_conv["data"]
|
||||
if cd != None and "allow_requests" in cd and cd["allow_requests"] == True:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
else:
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
RNS.log("Error while checking request permissions for "+RNS.prettyhexrep(context_dest)+": "+str(e), RNS.LOG_ERROR)
|
||||
return False
|
||||
|
||||
def raw_display_name(self, context_dest):
|
||||
try:
|
||||
existing_conv = self._db_conversation(context_dest)
|
||||
@ -811,6 +833,12 @@ class SidebandCore():
|
||||
def no_telemetry_in_conversation(self, context_dest):
|
||||
self._db_conversation_set_telemetry(context_dest, False)
|
||||
|
||||
def allow_requests_from(self, context_dest):
|
||||
self._db_conversation_set_requests(context_dest, True)
|
||||
|
||||
def disallow_requests_from(self, context_dest):
|
||||
self._db_conversation_set_requests(context_dest, False)
|
||||
|
||||
def named_conversation(self, name, context_dest):
|
||||
self._db_conversation_set_name(context_dest, name)
|
||||
|
||||
@ -1458,6 +1486,24 @@ class SidebandCore():
|
||||
result = dbc.fetchall()
|
||||
db.commit()
|
||||
|
||||
def _db_conversation_set_requests(self, context_dest, allow_requests=False):
|
||||
conv = self._db_conversation(context_dest)
|
||||
data_dict = conv["data"]
|
||||
if data_dict == None:
|
||||
data_dict = {}
|
||||
|
||||
data_dict["allow_requests"] = allow_requests
|
||||
packed_dict = msgpack.packb(data_dict)
|
||||
|
||||
db = self.__db_connect()
|
||||
dbc = db.cursor()
|
||||
|
||||
query = "UPDATE conv set data = ? where dest_context = ?"
|
||||
data = (packed_dict, context_dest)
|
||||
dbc.execute(query, data)
|
||||
result = dbc.fetchall()
|
||||
db.commit()
|
||||
|
||||
def _db_conversation_set_trusted(self, context_dest, trusted):
|
||||
db = self.__db_connect()
|
||||
dbc = db.cursor()
|
||||
|
@ -28,6 +28,7 @@ class ConvSettings(BoxLayout):
|
||||
context_dest = StringProperty()
|
||||
trusted = BooleanProperty()
|
||||
telemetry = BooleanProperty()
|
||||
allow_requests = BooleanProperty()
|
||||
|
||||
class Conversations():
|
||||
def __init__(self, app):
|
||||
@ -130,10 +131,11 @@ class Conversations():
|
||||
disp_name = self.app.sideband.raw_display_name(dest)
|
||||
is_trusted = self.app.sideband.is_trusted(dest)
|
||||
send_telemetry = self.app.sideband.should_send_telemetry(dest)
|
||||
allow_requests = self.app.sideband.requests_allowed_from(dest)
|
||||
|
||||
yes_button = MDRectangleFlatButton(text="Save",font_size=dp(18), theme_text_color="Custom", line_color=self.app.color_accept, text_color=self.app.color_accept)
|
||||
no_button = MDRectangleFlatButton(text="Cancel",font_size=dp(18))
|
||||
dialog_content = ConvSettings(disp_name=disp_name, context_dest=RNS.hexrep(dest, delimit=False), trusted=is_trusted, telemetry=send_telemetry)
|
||||
dialog_content = ConvSettings(disp_name=disp_name, context_dest=RNS.hexrep(dest, delimit=False), trusted=is_trusted, telemetry=send_telemetry, allow_requests=allow_requests)
|
||||
dialog = MDDialog(
|
||||
title="Edit Conversation",
|
||||
text= "With "+RNS.prettyhexrep(dest),
|
||||
@ -148,6 +150,7 @@ class Conversations():
|
||||
name = dialog.d_content.ids["name_field"].text
|
||||
trusted = dialog.d_content.ids["trusted_switch"].active
|
||||
telemetry = dialog.d_content.ids["telemetry_switch"].active
|
||||
allow_requests = dialog.d_content.ids["allow_requests_switch"].active
|
||||
if trusted:
|
||||
self.app.sideband.trusted_conversation(dest)
|
||||
else:
|
||||
@ -158,6 +161,11 @@ class Conversations():
|
||||
else:
|
||||
self.app.sideband.no_telemetry_in_conversation(dest)
|
||||
|
||||
if allow_requests:
|
||||
self.app.sideband.allow_requests_from(dest)
|
||||
else:
|
||||
self.app.sideband.disallow_requests_from(dest)
|
||||
|
||||
self.app.sideband.named_conversation(name, dest)
|
||||
|
||||
except Exception as e:
|
||||
@ -434,10 +442,9 @@ Builder.load_string("""
|
||||
|
||||
MDBoxLayout:
|
||||
orientation: "horizontal"
|
||||
# spacing: "24dp"
|
||||
size_hint_y: None
|
||||
padding: [0,0,dp(8),0]
|
||||
height: dp(48)
|
||||
height: dp(32)
|
||||
MDLabel:
|
||||
id: trusted_switch_label
|
||||
text: "Trusted"
|
||||
@ -450,10 +457,9 @@ Builder.load_string("""
|
||||
|
||||
MDBoxLayout:
|
||||
orientation: "horizontal"
|
||||
# spacing: "24dp"
|
||||
size_hint_y: None
|
||||
padding: [0,0,dp(8),0]
|
||||
height: dp(48)
|
||||
height: dp(32)
|
||||
MDLabel:
|
||||
id: telemetry_switch_label
|
||||
text: "Include Telemetry"
|
||||
@ -464,6 +470,21 @@ Builder.load_string("""
|
||||
pos_hint: {"center_y": 0.43}
|
||||
active: root.telemetry
|
||||
|
||||
MDBoxLayout:
|
||||
orientation: "horizontal"
|
||||
size_hint_y: None
|
||||
padding: [0,0,dp(8),0]
|
||||
height: dp(32)
|
||||
MDLabel:
|
||||
id: allow_requests_label
|
||||
text: "Allow Requests"
|
||||
font_style: "H6"
|
||||
|
||||
MDSwitch:
|
||||
id: allow_requests_switch
|
||||
pos_hint: {"center_y": 0.43}
|
||||
active: root.allow_requests
|
||||
|
||||
<MsgSync>
|
||||
orientation: "vertical"
|
||||
spacing: "24dp"
|
||||
|
@ -52,9 +52,6 @@ class Telemetry():
|
||||
self.screen.ids.telemetry_enabled.active = self.app.sideband.config["telemetry_enabled"]
|
||||
self.screen.ids.telemetry_enabled.bind(active=self.telemetry_enabled_toggle)
|
||||
|
||||
self.screen.ids.telemetry_send_to_collector.active = self.app.sideband.config["telemetry_send_to_collector"]
|
||||
self.screen.ids.telemetry_send_to_collector.bind(active=self.telemetry_save)
|
||||
|
||||
self.screen.ids.telemetry_send_to_trusted.active = self.app.sideband.config["telemetry_send_to_trusted"]
|
||||
self.screen.ids.telemetry_send_to_trusted.bind(active=self.telemetry_save)
|
||||
|
||||
@ -71,6 +68,126 @@ class Telemetry():
|
||||
|
||||
self.screen.ids.telemetry_info.text = info
|
||||
|
||||
def send_interval_change(sender=None, event=None, save=True):
|
||||
slider_val = int(self.screen.ids.telemetry_send_interval.value)
|
||||
mseg = 72; hseg = 84
|
||||
if slider_val <= mseg:
|
||||
interval = slider_val*5*60
|
||||
elif slider_val > mseg and slider_val <= mseg+hseg:
|
||||
h = (slider_val-mseg)/2; mm = mseg*5*60
|
||||
interval = h*60*60+mm
|
||||
else:
|
||||
d = slider_val-hseg-mseg
|
||||
hm = (hseg/2)*60*60; mm = mseg*5*60
|
||||
interval = d*86400+hm+mm
|
||||
|
||||
interval_text = RNS.prettytime(interval)
|
||||
if self.screen.ids.telemetry_send_to_collector.active:
|
||||
self.screen.ids.telemetry_send_to_collector_label.text = "Auto send to collector every "+interval_text
|
||||
else:
|
||||
self.screen.ids.telemetry_send_to_collector_label.text = "Auto send to collector"
|
||||
|
||||
if save:
|
||||
self.app.sideband.config["telemetry_send_interval"] = interval
|
||||
self.app.sideband.save_configuration()
|
||||
|
||||
def save_send_to_collector(sender=None, event=None, save=True):
|
||||
if self.screen.ids.telemetry_send_to_collector.active:
|
||||
self.widget_hide(self.screen.ids.send_syncslider_container, False)
|
||||
else:
|
||||
self.widget_hide(self.screen.ids.send_syncslider_container, True)
|
||||
|
||||
if save:
|
||||
self.app.sideband.config["telemetry_send_to_collector"] = self.screen.ids.telemetry_send_to_collector.active
|
||||
self.app.sideband.save_configuration()
|
||||
|
||||
send_interval_change(save=False)
|
||||
|
||||
self.screen.ids.telemetry_send_to_collector.active = self.app.sideband.config["telemetry_send_to_collector"]
|
||||
self.screen.ids.telemetry_send_to_collector.bind(active=save_send_to_collector)
|
||||
save_send_to_collector(save=False)
|
||||
|
||||
def send_interval_change_cb(sender=None, event=None):
|
||||
send_interval_change(sender=sender, event=event, save=False)
|
||||
self.screen.ids.telemetry_send_interval.bind(value=send_interval_change_cb)
|
||||
self.screen.ids.telemetry_send_interval.bind(on_touch_up=send_interval_change)
|
||||
self.screen.ids.telemetry_send_interval.value = self.interval_to_slider_val(self.app.sideband.config["telemetry_send_interval"])
|
||||
send_interval_change(save=False)
|
||||
|
||||
def request_interval_change(sender=None, event=None, save=True):
|
||||
slider_val = int(self.screen.ids.telemetry_request_interval.value)
|
||||
mseg = 72; hseg = 84
|
||||
if slider_val <= mseg:
|
||||
interval = slider_val*5*60
|
||||
elif slider_val > mseg and slider_val <= mseg+hseg:
|
||||
h = (slider_val-mseg)/2; mm = mseg*5*60
|
||||
interval = h*60*60+mm
|
||||
else:
|
||||
d = slider_val-hseg-mseg
|
||||
hm = (hseg/2)*60*60; mm = mseg*5*60
|
||||
interval = d*86400+hm+mm
|
||||
|
||||
interval_text = RNS.prettytime(interval)
|
||||
if self.screen.ids.telemetry_request_from_collector.active:
|
||||
self.screen.ids.telemetry_request_from_collector_label.text = "Auto request from collector every "+interval_text
|
||||
else:
|
||||
self.screen.ids.telemetry_request_from_collector_label.text = "Auto request from collector"
|
||||
|
||||
if save:
|
||||
self.app.sideband.config["telemetry_request_interval"] = interval
|
||||
self.app.sideband.save_configuration()
|
||||
|
||||
def save_request_from_collector(sender=None, event=None, save=True):
|
||||
if self.screen.ids.telemetry_request_from_collector.active:
|
||||
self.widget_hide(self.screen.ids.request_syncslider_container, False)
|
||||
else:
|
||||
self.widget_hide(self.screen.ids.request_syncslider_container, True)
|
||||
|
||||
if save:
|
||||
self.app.sideband.config["telemetry_request_from_collector"] = self.screen.ids.telemetry_request_from_collector.active
|
||||
self.app.sideband.save_configuration()
|
||||
|
||||
request_interval_change(save=False)
|
||||
|
||||
self.screen.ids.telemetry_request_from_collector.active = self.app.sideband.config["telemetry_request_from_collector"]
|
||||
self.screen.ids.telemetry_request_from_collector.bind(active=save_request_from_collector)
|
||||
save_request_from_collector(save=False)
|
||||
|
||||
def request_interval_change_cb(sender=None, event=None):
|
||||
request_interval_change(sender=sender, event=event, save=False)
|
||||
self.screen.ids.telemetry_request_interval.bind(value=request_interval_change_cb)
|
||||
self.screen.ids.telemetry_request_interval.bind(on_touch_up=request_interval_change)
|
||||
self.screen.ids.telemetry_request_interval.value = self.interval_to_slider_val(self.app.sideband.config["telemetry_request_interval"])
|
||||
request_interval_change(save=False)
|
||||
|
||||
|
||||
def interval_to_slider_val(self, interval):
|
||||
try:
|
||||
mseg = 72; hseg = 84; sv = 0
|
||||
mm = mseg*5*60; hm = hseg*60*30+mm
|
||||
|
||||
if interval <= mm:
|
||||
sv = interval/60/5
|
||||
elif interval > mm and interval <= hm:
|
||||
half_hours = interval/(60*30)-(mm/(60*30))
|
||||
sv = mseg+half_hours
|
||||
else:
|
||||
days = (interval/86400)-((hseg*60*30)/84600)-(mm/86400)
|
||||
sv = 1+mseg+hseg+days
|
||||
except Exception as e:
|
||||
return 43200
|
||||
|
||||
return sv
|
||||
|
||||
def widget_hide(self, w, hide=True):
|
||||
if hasattr(w, "saved_attrs"):
|
||||
if not hide:
|
||||
w.height, w.size_hint_y, w.opacity, w.disabled = w.saved_attrs
|
||||
del w.saved_attrs
|
||||
elif hide:
|
||||
w.saved_attrs = w.height, w.size_hint_y, w.opacity, w.disabled
|
||||
w.height, w.size_hint_y, w.opacity, w.disabled = 0, None, 0, True
|
||||
|
||||
def telemetry_enabled_toggle(self, sender=None, event=None):
|
||||
self.telemetry_save()
|
||||
if self.screen.ids.telemetry_enabled.active:
|
||||
@ -102,12 +219,6 @@ class Telemetry():
|
||||
else:
|
||||
self.app.sideband.setstate("app.flags.last_telemetry", time.time())
|
||||
|
||||
def converse_from_telemetry(self, sender=None):
|
||||
if self.object_details_screen != None:
|
||||
context_dest = self.object_details_screen.object_hash
|
||||
if not self.object_details_screen.object_hash == self.app.sideband.lxmf_destination.hash:
|
||||
self.open_conversation(context_dest)
|
||||
|
||||
def telemetry_copy(self, sender=None):
|
||||
Clipboard.copy(str(self.app.sideband.get_telemetry()))
|
||||
self.app.sideband.update_telemetry()
|
||||
@ -419,21 +530,6 @@ MDScreen:
|
||||
pos_hint: {"center_y": 0.3}
|
||||
active: False
|
||||
|
||||
MDBoxLayout:
|
||||
orientation: "horizontal"
|
||||
size_hint_y: None
|
||||
padding: [0,0,dp(24),dp(0)]
|
||||
height: dp(48)
|
||||
|
||||
MDLabel:
|
||||
text: "Automatically send to collector"
|
||||
font_style: "H6"
|
||||
|
||||
MDSwitch:
|
||||
id: telemetry_send_to_collector
|
||||
pos_hint: {"center_y": 0.3}
|
||||
active: False
|
||||
|
||||
MDBoxLayout:
|
||||
orientation: "horizontal"
|
||||
size_hint_y: None
|
||||
@ -479,6 +575,68 @@ MDScreen:
|
||||
pos_hint: {"center_y": 0.3}
|
||||
active: False
|
||||
|
||||
MDBoxLayout:
|
||||
orientation: "horizontal"
|
||||
size_hint_y: None
|
||||
padding: [0,0,dp(24),dp(0)]
|
||||
height: dp(48)
|
||||
|
||||
MDLabel:
|
||||
id: telemetry_send_to_collector_label
|
||||
text: "Auto send to collector"
|
||||
font_style: "H6"
|
||||
|
||||
MDSwitch:
|
||||
id: telemetry_send_to_collector
|
||||
pos_hint: {"center_y": 0.3}
|
||||
active: False
|
||||
|
||||
MDBoxLayout:
|
||||
id: send_syncslider_container
|
||||
orientation: "vertical"
|
||||
size_hint_y: None
|
||||
padding: [0,0,dp(0),0]
|
||||
height: dp(68)
|
||||
|
||||
MDSlider
|
||||
id: telemetry_send_interval
|
||||
min: 1
|
||||
max: 214
|
||||
value: 150
|
||||
sensitivity: "all"
|
||||
hint: False
|
||||
|
||||
MDBoxLayout:
|
||||
orientation: "horizontal"
|
||||
size_hint_y: None
|
||||
padding: [0,0,dp(24),dp(0)]
|
||||
height: dp(48)
|
||||
|
||||
MDLabel:
|
||||
id: telemetry_request_from_collector_label
|
||||
text: "Auto request from collector"
|
||||
font_style: "H6"
|
||||
|
||||
MDSwitch:
|
||||
id: telemetry_request_from_collector
|
||||
pos_hint: {"center_y": 0.3}
|
||||
active: False
|
||||
|
||||
MDBoxLayout:
|
||||
id: request_syncslider_container
|
||||
orientation: "vertical"
|
||||
size_hint_y: None
|
||||
padding: [0,0,dp(0),0]
|
||||
height: dp(68)
|
||||
|
||||
MDSlider
|
||||
id: telemetry_request_interval
|
||||
min: 1
|
||||
max: 214
|
||||
value: 150
|
||||
sensitivity: "all"
|
||||
hint: False
|
||||
|
||||
MDBoxLayout:
|
||||
orientation: "vertical"
|
||||
spacing: dp(24)
|
||||
@ -529,7 +687,7 @@ MDScreen:
|
||||
font_size: dp(16)
|
||||
size_hint: [1.0, None]
|
||||
on_release: root.app.telemetry_send_update(self)
|
||||
disabled: True
|
||||
disabled: False
|
||||
|
||||
MDRectangleFlatIconButton:
|
||||
id: telemetry_request_button
|
||||
@ -540,7 +698,7 @@ MDScreen:
|
||||
font_size: dp(16)
|
||||
size_hint: [1.0, None]
|
||||
on_release: root.app.telemetry_request_action(self)
|
||||
disabled: True
|
||||
disabled: False
|
||||
|
||||
MDLabel:
|
||||
text: "Display Options"
|
||||
|
Loading…
Reference in New Issue
Block a user