Skip to content

Commit

Permalink
Support for nodeRejected event + button to add discovered node
Browse files Browse the repository at this point in the history
  • Loading branch information
kozec committed Aug 27, 2014
1 parent 9767c16 commit 0f39170
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
32 changes: 26 additions & 6 deletions syncthing_gtk/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@
# Response IDs
RESPONSE_RESTART = 256
RESPONSE_FIX_REPOID = 257
RESPONSE_QUIT = 258
RESPONSE_START_DAEMON = 259
RESPONSE_SLAIN_DAEMON = 260
RESPONSE_SPARE_DAEMON = 261
RESPONSE_FIX_NEW_NODE = 258
RESPONSE_QUIT = 260
RESPONSE_START_DAEMON = 271
RESPONSE_SLAIN_DAEMON = 272
RESPONSE_SPARE_DAEMON = 273

class App(Gtk.Application, TimerManager):
"""
Expand Down Expand Up @@ -168,6 +169,7 @@ def setup_connection(self):
self.daemon.connect("disconnected", self.cb_syncthing_disconnected)
self.daemon.connect("error", self.cb_syncthing_error)
self.daemon.connect("repo-rejected", self.cb_syncthing_repo_rejected)
self.daemon.connect("node-rejected", self.cb_syncthing_node_rejected)
self.daemon.connect("my-id-changed", self.cb_syncthing_my_id_changed)
self.daemon.connect("node-added", self.cb_syncthing_node_added)
self.daemon.connect("node-data-changed", self.cb_syncthing_node_data_changed)
Expand Down Expand Up @@ -295,6 +297,20 @@ def cb_syncthing_repo_rejected(self, daemon, nid, rid):
r.add_button(RIBar.build_button(_("_Fix")), RESPONSE_FIX_REPOID)
self.show_error_box(r, {"nid" : nid, "rid" : rid} )

def cb_syncthing_node_rejected(self, daemon, nid, address):
address = address.split(":")[0] # Remove port from address, it's random by default anyway
if (nid, address) in self.error_messages:
# Store as error message and don't display twice
return
self.error_messages.add((nid, address))
markup = _('Unknown node "<b>%s</b>" is trying to connect from IP "<b>%s</b>"; '
'If you just configured this remote node, you can click \'fix\' '
'to open Add node dialog.') % (nid, address)
r = RIBar("", Gtk.MessageType.WARNING,)
r.get_label().set_markup(markup)
r.add_button(RIBar.build_button(_("_Fix")), RESPONSE_FIX_NEW_NODE)
self.show_error_box(r, {"nid" : nid, "address" : address} )

def cb_syncthing_my_id_changed(self, daemon, node_id):
if node_id in self.nodes:
node = self.nodes[node_id]
Expand Down Expand Up @@ -791,11 +807,11 @@ def cb_infobar_close(self, bar):
if bar in self.error_boxes:
self.error_boxes.remove(bar)

def cb_infobar_response(self, bar, response_id, additional_data):
def cb_infobar_response(self, bar, response_id, additional_data={}):
if response_id == RESPONSE_RESTART:
# Restart
self.daemon.restart()
if response_id == RESPONSE_FIX_REPOID:
elif response_id == RESPONSE_FIX_REPOID:
# Give up if there is no node with matching ID
if additional_data["nid"] in self.nodes:
# Find repository with matching ID ...
Expand All @@ -814,6 +830,10 @@ def cb_infobar_response(self, bar, response_id, additional_data):
e.call_after_loaded(e.fill_repo_id, additional_data["rid"])
e.load()
e.show(self["window"])
elif response_id == RESPONSE_FIX_NEW_NODE:
e = EditorDialog(self, "node-edit", True, additional_data["nid"])
e.load()
e.show(self["window"])
self.cb_infobar_close(bar)

def cb_open_closed(self, box):
Expand Down
10 changes: 10 additions & 0 deletions syncthing_gtk/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ class Daemon(GObject.GObject, TimerManager):
node_id: id of node that send unexpected repository id
repo_id: id of unexpected repository
node-rejected(node_id, address)
Emited when daemon detects connection from unknown node
node_id: node id
address: address which connection come from
node-added (id, name, data)
Emited when new node is loaded from configuration
id: id of loaded node
Expand Down Expand Up @@ -155,6 +160,7 @@ class Daemon(GObject.GObject, TimerManager):
b"connection-error" : (GObject.SIGNAL_RUN_FIRST, None, (int, object)),
b"error" : (GObject.SIGNAL_RUN_FIRST, None, (object,)),
b"repo-rejected" : (GObject.SIGNAL_RUN_FIRST, None, (object,object)),
b"node-rejected" : (GObject.SIGNAL_RUN_FIRST, None, (object,object)),
b"my-id-changed" : (GObject.SIGNAL_RUN_FIRST, None, (object,)),
b"node-added" : (GObject.SIGNAL_RUN_FIRST, None, (object, object, object)),
b"node-connected" : (GObject.SIGNAL_RUN_FIRST, None, (object,)),
Expand Down Expand Up @@ -822,6 +828,10 @@ def _on_event(self, e):
nid = e["data"]["node"]
rid = e["data"]["repo"]
self.emit("repo-rejected", nid, rid)
elif eType == "NodeRejected":
nid = e["data"]["node"]
address = e["data"]["address"]
self.emit("node-rejected", nid, address)
else:
print "Unhandled event type:", e

Expand Down
3 changes: 3 additions & 0 deletions syncthing_gtk/editordialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,9 @@ def cb_data_loaded(self, config):
self.checks = {
"vNodeID" : check_node_id,
}
if self.id != None:
# Pre-fill node id, if provided
self.set_value("NodeID", self.id)
else:
if self.mode == "repo-edit":
self.values = [ x for x in self.config["Repositories"] if x["ID"] == self.id ][0]
Expand Down

0 comments on commit 0f39170

Please sign in to comment.