Skip to content

Commit

Permalink
Added 'rescan' menu option for repo context menu - added in syncthing…
Browse files Browse the repository at this point in the history
… 0.9.5
  • Loading branch information
kozec committed Aug 25, 2014
1 parent 14d5416 commit d5e5e09
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
18 changes: 18 additions & 0 deletions app.glade
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,18 @@
<signal name="activate" handler="cb_menu_popup_edit_repo" swapped="no"/>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="menu-popup-rescan-repo">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">_Rescan</property>
<property name="use_underline">True</property>
<property name="use_stock">False</property>
<property name="always_show_image">True</property>
<property name="image">menu-popup-rescan-repo-image</property>
<signal name="activate" handler="cb_menu_popup_rescan_repo" swapped="no"/>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="menu-popup-delete-repo">
<property name="visible">True</property>
Expand Down Expand Up @@ -542,4 +554,10 @@
<property name="pixbuf">icons/show_id.png</property>
</object>

<object class="GtkImage" id="menu-popup-rescan-repo-image">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-refresh</property>
</object>

</interface>
7 changes: 6 additions & 1 deletion syncthing_gtk/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,9 +679,14 @@ def cb_menu_popup_edit_node(self, *a):
self.open_editor("node-edit", self.rightclick_box["id"])

def cb_menu_popup_delete_repo(self, *a):
""" Handler for 'edit' context menu item """
""" Handler for 'delete' repo context menu item """
# Editing repository
self.check_delete("repo", self.rightclick_box["id"], self.rightclick_box.get_title())

def cb_menu_popup_rescan_repo(self, *a):
""" Handler for 'rescan' context menu item """
# Editing repository
self.daemon.rescan(self.rightclick_box["id"])

def cb_menu_popup_delete_node(self, *a):
""" Handler for other 'edit' context menu item """
Expand Down
23 changes: 18 additions & 5 deletions syncthing_gtk/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,9 +464,11 @@ def _rest_post_response(self, sc, results, con, command, data, epoch, callback,
return
# Extract response code
try:
code = int(response.split("\n")[0].strip("\r\n").split(" ")[1])
headers, response = response.split("\r\n\r\n", 1)
headers = headers.split("\r\n")
code = int(headers[0].split(" ")[1])
if code != 200:
self._rest_post_error(HTTPException("HTTP error %s" % (code,)), command, data, callback, error_callback, callback_data)
self._rest_post_error(HTTPException("HTTP error %s" % (code,), response), command, data, callback, error_callback, callback_data)
return
except Exception:
# That probably wasn't HTTP
Expand Down Expand Up @@ -746,12 +748,16 @@ def _syncthing_cb_config_written(self, data, callback, errorcallback, calbackdat
else:
callback(*calbackdata)

def __syncthing_cb_config_write_failed(self, exception, command, data, callback, errorcallback, calbackdata):
def _syncthing_cb_config_write_failed(self, exception, command, data, callback, errorcallback, calbackdata):
if errorcallback == None:
errorcallback(exception)
else:
errorcallback(exception, *calbackdata)

def _syncthing_cb_rescan_error(self, exception, command, data, repo_id):
print >>sys.stderr, "Warning: Failed to rescan repository %s: %s" % (repo_id, exception.response)
self.emit("error", "Warning: Failed to rescan repository %s: %s" % (repo_id, exception.response))

def _repo_state_changed(self, rid, state, progress):
"""
Emits event according to last known and new state.
Expand Down Expand Up @@ -851,7 +857,7 @@ def write_config(self, config, callback, error_callback=None, *calbackdata):
error_callback(exception) on failure.
Should cause 'config-out-of-sync' event to be raised ASAP.
"""
self._rest_post("config", config, self._syncthing_cb_config_written, self.__syncthing_cb_config_write_failed, callback, error_callback, calbackdata)
self._rest_post("config", config, self._syncthing_cb_config_written, self._syncthing_cb_config_write_failed, callback, error_callback, calbackdata)

def restart(self):
"""
Expand Down Expand Up @@ -893,7 +899,14 @@ def get_address(self):
""" Returns tuple address on which daemon listens on. """
return self._address

def rescan(self, repo_id):
""" Asks daemon to rescan repository """
self._rest_post("scan?repo=%s" % (repo_id,), {}, lambda *a: a, self._syncthing_cb_rescan_error, repo_id)

class InvalidConfigurationException(RuntimeError): pass
class TLSUnsupportedException(InvalidConfigurationException): pass
class HTTPException(RuntimeError): pass
class HTTPException(RuntimeError):
def __init__(self, message, response=None):
RuntimeError.__init__(self, message)
self.response = response
class HTTPAuthException(HTTPException): pass

0 comments on commit d5e5e09

Please sign in to comment.