Skip to content

Commit

Permalink
Saving for that stuff above
Browse files Browse the repository at this point in the history
  • Loading branch information
kozec committed Sep 27, 2014
1 parent b360c23 commit 8f11647
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
35 changes: 16 additions & 19 deletions syncthing_gtk/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -850,19 +850,6 @@ def _syncthing_cb_config_in_sync(self, data):
# Not in sync...
self.emit("config-out-of-sync")

def _syncthing_cb_config_written(self, data, callback, errorcallback, calbackdata):
self.check_config()
if calbackdata == None:
callback()
else:
callback(*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))
Expand Down Expand Up @@ -991,25 +978,35 @@ def read_config(self, callback, error_callback=None, *calbackdata):
def write_config(self, config, callback, error_callback=None, *calbackdata):
"""
Asynchronously POSTs new configuration to daemon. Calls
callback() with data decoded from json on success,
error_callback(exception) on failure.
callback() on success, 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)
def run_before(data, *a):
self.check_config()
callback(*calbackdata)
self._rest_post("config", config, run_before, error_callback, *calbackdata)

def read_stignore(self, repo_id, callback, error_callback=None, *calbackdata):
"""
Asynchronously reads .stignore data from from daemon.
Calls callback(text) with .stignore content on success,
error_callback(exception) on failure
"""
def r_filter(data):
def r_filter(data, *a):
if "ignore" in data and not data["ignore"] is None:
callback("\n".join(data["ignore"]).strip(" \t\n"))
callback("\n".join(data["ignore"]).strip(" \t\n"), *a)
else:
callback("")
callback("", *a)
self._rest_request("ignores?repo=%s" % (repo_id,), r_filter, error_callback, *calbackdata)

def write_stignore(self, repo_id, text, callback, error_callback=None, *calbackdata):
"""
Asynchronously POSTs .stignore to daemon. Calls callback()
with on success, error_callback(exception) on failure.
"""
data = { 'ignore': text.split("\n") }
self._rest_post("ignores?repo=%s" % (repo_id,), data, callback, error_callback, *calbackdata)

def restart(self):
"""
Asks daemon to restart. If sucesfull, call will cause
Expand Down
12 changes: 9 additions & 3 deletions syncthing_gtk/ignoreeditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def show(self, parent=None):
self["dialog"].set_transient_for(parent)
self["dialog"].show_all()

def close(self):
def close(self, *a):
self["dialog"].set_visible(False)
self["dialog"].destroy()

Expand Down Expand Up @@ -61,7 +61,13 @@ def on_lblLocation_activate_link(self, *a):
self.close()

def btSave_clicked_cb(self, *a):
pass
start_iter = self["tbPatterns"].get_start_iter()
end_iter = self["tbPatterns"].get_end_iter()
text = self["tbPatterns"].get_text(start_iter, end_iter, True)
self["tvPatterns"].set_sensitive(False)
self["btSave"].set_sensitive(False)
# TODO: Expect error and create appropriate callback for it
self.app.daemon.write_stignore(self.rid, text, self.close, self.close)

def load(self):
self.app.daemon.read_stignore(self.rid, self.cb_data_loaded, self.cb_data_failed)
Expand All @@ -74,6 +80,6 @@ def cb_data_failed(self, *a):

def cb_data_loaded(self, text):
self["tbPatterns"].set_text(text)
self["tvPatterns"].set_sensitive(True)
self["tvPatterns"].grab_focus()
self["tvPatterns"].set_sensitive(True)
self["btSave"].set_sensitive(True)

0 comments on commit 8f11647

Please sign in to comment.