Skip to content

Commit

Permalink
v0.12: Added pause/resume option to device context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
kozec committed Sep 22, 2015
1 parent 299c684 commit 1e93e2e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 7 deletions.
30 changes: 30 additions & 0 deletions app.glade
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,29 @@
<property name="image">menu-popup-show-id-image</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="menu-popup-pause-device">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">gtk-media-pause</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
<property name="always_show_image">True</property>
<signal name="activate" handler="cb_menu_popup_pause_device" swapped="no"/>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="menu-popup-resume-device">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Resume</property>
<property name="image">menu-popup-resume-image</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
<property name="always_show_image">True</property>
<signal name="activate" handler="cb_menu_popup_resume_device" swapped="no"/>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="menu-popup-delete-device">
<property name="visible">True</property>
Expand Down Expand Up @@ -987,6 +1010,13 @@
<property name="can_focus">False</property>
<property name="icon-name">folder-open</property>
</object>

<object class="GtkImage" id="menu-popup-resume-image">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon-name">gtk-media-play</property>
</object>

<!-- /Popup menu icon images -->

</interface>
11 changes: 10 additions & 1 deletion syncthing_gtk/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1643,6 +1643,8 @@ def cb_popup_menu_device(self, box, button, time):
b = box["id"] != self.daemon.get_my_id()
self["menu-popup-edit-device"].set_visible(b)
self["menu-popup-delete-device"].set_visible(b)
self["menu-popup-pause-device"].set_visible(box.get_status() != _("Paused"))
self["menu-popup-resume-device"].set_visible(box.get_status() == _("Paused"))
self["popup-menu-device"].popup(None, None, None, None, button, time)

def cb_menu_popup(self, source, menu):
Expand Down Expand Up @@ -1704,9 +1706,16 @@ def cb_menu_popup_override(self, *a):

def cb_menu_popup_delete_device(self, *a):
""" Handler for other 'edit' context menu item """
# Editing device
self.check_delete("device", self.rightclick_box["id"], self.rightclick_box.get_title())

def cb_menu_popup_pause_device(self, *a):
""" Handler for 'resume device' context menu item """
self.daemon.pause(self.rightclick_box["id"])

def cb_menu_popup_resume_device(self, *a):
""" Handler for 'resume device' context menu item """
self.daemon.resume(self.rightclick_box["id"])

def check_delete(self, mode, id, name):
"""
Asks user if he really wants to do what he just asked to do
Expand Down
18 changes: 12 additions & 6 deletions syncthing_gtk/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -1254,21 +1254,27 @@ def is_connected(self):
""" Returns True if daemon is known to be alive """
return self._connected

def rescan(self, folder_id, path=None):
""" Asks daemon to rescan entire folder or specified path """
def pause(self, device_id):
""" Pauses synchronization with specified device """
self._rest_post("system/pause?device=%s" % (device_id,), {}, lambda *a: a, lambda *a: log.error(a), device_id)

def resume(self, device_id):
""" Resumes synchronization with specified device """
def on_error(*a):
log.error(a)
self._rest_post("system/resume?device=%s" % (device_id,), {}, lambda *a: a, lambda *a: log.error(a), device_id)

def rescan(self, folder_id, path=None):
""" Asks daemon to rescan entire folder or specified path """
if path is None:
self._rest_post("db/scan?folder=%s" % (folder_id,), {}, lambda *a: a, on_error, folder_id)
self._rest_post("db/scan?folder=%s" % (folder_id,), {}, lambda *a: a, lambda *a: log.error(a), folder_id)
else:
path_enc = urllib.quote(path.encode('utf-8'), ''.encode('utf-8'))
self._rest_post("db/scan?folder=%s&sub=%s" % (folder_id, path_enc), {}, lambda *a: a, on_error, folder_id)

def override(self, folder_id):
""" Asks daemon to override changes made in specified folder """
def on_error(*a):
log.error(a)
self._rest_post("model/override?folder=%s" % (folder_id,), {}, lambda *a: a, on_error, folder_id)
self._rest_post("model/override?folder=%s" % (folder_id,), {}, lambda *a: a, lambda *a: log.error(a), folder_id)

def request_events(self):
"""
Expand Down

0 comments on commit 1e93e2e

Please sign in to comment.