diff --git a/nomadnet/Directory.py b/nomadnet/Directory.py index 9d3029b..740fd4f 100644 --- a/nomadnet/Directory.py +++ b/nomadnet/Directory.py @@ -60,6 +60,9 @@ class Directory: entries = {} for e in unpacked_list: + if e[1] == None: + e[1] = RNS.prettyhexrep(e[0]) + if len(e) > 3: hosts_node = e[3] else: @@ -132,7 +135,11 @@ class Directory: return "<"+RNS.hexrep(source_hash, delimit=False)+">" else: if source_hash in self.directory_entries: - return self.directory_entries[source_hash].display_name + dn = self.directory_entries[source_hash].display_name + if dn == None: + return RNS.prettyhexrep(source_hash) + else: + return dn else: return "<"+RNS.hexrep(source_hash, delimit=False)+">" @@ -242,10 +249,12 @@ class DirectoryEntry: def __init__(self, source_hash, display_name=None, trust_level=UNKNOWN, hosts_node=False, preferred_delivery=None, identify_on_connect=False): if len(source_hash) == RNS.Identity.TRUNCATED_HASHLENGTH//8: self.source_hash = source_hash - self.display_name = display_name + if display_name == None: display_name = source_hash + self.display_name = display_name + if preferred_delivery == None: self.preferred_delivery = DirectoryEntry.DIRECT else: diff --git a/nomadnet/ui/textui/Browser.py b/nomadnet/ui/textui/Browser.py index 8e40928..b7dc0f6 100644 --- a/nomadnet/ui/textui/Browser.py +++ b/nomadnet/ui/textui/Browser.py @@ -6,6 +6,7 @@ import nomadnet import subprocess import threading from .MicronParser import markup_to_attrmaps +from nomadnet.Directory import DirectoryEntry from nomadnet.vendor.Scrollable import * class BrowserFrame(urwid.Frame): @@ -20,6 +21,8 @@ class BrowserFrame(urwid.Frame): self.delegate.reload() elif key == "ctrl u": self.delegate.url_dialog() + elif key == "ctrl s": + self.delegate.save_node_dialog() elif self.get_focus() == "body": return super(BrowserFrame, self).keypress(size, key) # if key == "up" and self.delegate.messagelist.top_is_visible: @@ -501,6 +504,40 @@ class Browser: self.delegate.columns.contents[1] = (overlay, options) self.delegate.columns.focus_position = 1 + def save_node_dialog(self): + def dismiss_dialog(sender): + self.close_dialogs() + + display_name = RNS.Identity.recall_app_data(self.destination_hash) + disp_str = "" + if display_name != None: + display_name = display_name.decode("utf-8") + disp_str = " \""+display_name+"\"" + + def confirmed(sender): + node_entry = DirectoryEntry(self.destination_hash, display_name=display_name, hosts_node=True) + self.app.directory.remember(node_entry) + self.app.ui.main_display.sub_displays.network_display.directory_change_callback() + + self.close_dialogs() + + dialog = UrlDialogLineBox( + urwid.Pile([ + urwid.Text("Save connected node"+disp_str+" "+RNS.prettyhexrep(self.destination_hash)+" to Known Nodes?\n"), + urwid.Columns([("weight", 0.45, urwid.Button("Cancel", on_press=dismiss_dialog)), ("weight", 0.1, urwid.Text("")), ("weight", 0.45, urwid.Button("Save", on_press=confirmed))]) + ]), title="Save Node" + ) + + dialog.confirmed = confirmed + dialog.delegate = self + bottom = self.display_widget + + overlay = urwid.Overlay(dialog, bottom, align="center", width=("relative", 50), valign="middle", height="pack", left=2, right=2) + + options = self.delegate.columns.options("weight", self.delegate.right_area_width) + self.delegate.columns.contents[1] = (overlay, options) + self.delegate.columns.focus_position = 1 + def load_page(self): cached = self.get_cached(self.current_url()) diff --git a/nomadnet/ui/textui/Network.py b/nomadnet/ui/textui/Network.py index 8bfe457..475767d 100644 --- a/nomadnet/ui/textui/Network.py +++ b/nomadnet/ui/textui/Network.py @@ -1284,6 +1284,9 @@ class NetworkLeftPile(urwid.Pile): self.parent.browser.disconnect() elif key == "ctrl u": self.parent.browser.url_dialog() + elif key == "ctrl s": + self.parent.browser.save_node_dialog() + else: return super(NetworkLeftPile, self).keypress(size, key)