Skip to content

Commit

Permalink
Fix: receive-only folder displays nonsense when out of sync. Fixes ko…
Browse files Browse the repository at this point in the history
  • Loading branch information
kozec committed Aug 3, 2019
1 parent ec6ca75 commit 0c55d13
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 12 deletions.
18 changes: 18 additions & 0 deletions glade/app.glade
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,18 @@
<signal name="activate" handler="cb_menu_popup_override" swapped="no"/>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="menu-popup-revert">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Override Local Changes</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
<property name="always_show_image">True</property>
<property name="image">menu-popup-revert-image</property>
<signal name="activate" handler="cb_menu_popup_revert" swapped="no"/>
</object>
</child>
<child>
<object class="GtkSeparatorMenuItem" id="menu-separator-override">
<property name="visible">True</property>
Expand Down Expand Up @@ -1026,6 +1038,12 @@
<property name="icon-name">edit-undo</property>
</object>

<object class="GtkImage" id="menu-popup-revert-image">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon-name">edit-undo</property>
</object>

<object class="GtkImage" id="menu-popup-rescan-folder-image">
<property name="visible">True</property>
<property name="can_focus">False</property>
Expand Down
8 changes: 8 additions & 0 deletions locale/en/LC_MESSAGES/syncthing-gtk.po
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@ msgstr ""
msgid "Stopped"
msgstr ""

#: syncthing_gtk/app.py:1090
msgid "Local changes"
msgstr ""

#: syncthing_gtk/app.py:998 syncthing_gtk/app.py:1005
msgid "Error"
msgstr ""
Expand All @@ -294,6 +298,10 @@ msgstr ""
msgid "Synchronizing '%s'"
msgstr ""

#: glade/app.glade:490
msgid "Override Local Changes"
msgstr ""

#: syncthing_gtk/app.py:1026
#, python-format
msgid "Synchronizing %s folders"
Expand Down
38 changes: 27 additions & 11 deletions syncthing_gtk/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1076,23 +1076,27 @@ def cb_syncthing_folder_data_changed(self, daemon, rid, data):
folder = self.folders[rid]
global_files = data["globalFiles"] + data["globalSymlinks"]
local_files = data["localFiles"] + data["localSymlinks"]
need_files = data["needFiles"] + data["needSymlinks"]
need_files = data["needFiles"] + data["needSymlinks"] + data.get("receiveOnlyTotalItems", 0)
need_bytes = data["needBytes"] + data.get("receiveOnlyChangedBytes", 0)
folder["global"] = "%s %s, %s" % (global_files, _("Files"), sizeof_fmt(data["globalBytes"]))
folder["local"] = "%s %s, %s" % (local_files, _("Files"), sizeof_fmt(data["localBytes"]))
folder["oos"] = "%s %s, %s" % (need_files, _("Files"), sizeof_fmt(data["needBytes"]))
if folder["folder_type"] == "sendonly":
folder["oos"] = "%s %s, %s" % (need_files, _("Files"), sizeof_fmt(need_bytes))
if folder["folder_type_s"] in ("sendonly", "receiveonly"):
can_override = (need_files > 0)
if can_override != folder["can_override"]:
folder["can_override"] = can_override
folder["override_title"] = (_("Cluster out of sync")
if folder["folder_type_s"] == "sendonly"
else _("Local changes"))
self.cb_syncthing_folder_up_to_date(None, rid)

def cb_syncthing_folder_up_to_date(self, daemon, rid):
if rid in self.folders: # Should be always
folder = self.folders[rid]
self.cb_syncthing_folder_state_changed(daemon, rid, 1.0,
COLOR_FOLDER_IDLE,
_("Cluster out of sync") if folder["can_override"] else _("Up to Date")
)
title = _("Up to Date")
if folder["can_override"]:
title = folder["override_title"]
self.cb_syncthing_folder_state_changed(daemon, rid, 1.0, COLOR_FOLDER_IDLE, title)

def cb_syncthing_folder_state_changed(self, daemon, rid, percentage, color, text):
if rid in self.folders: # Should be always
Expand Down Expand Up @@ -1180,7 +1184,7 @@ def update_folders(self):
if online and folder.compare_color_hex(COLOR_FOLDER_OFFLINE):
# Folder was marked as offline but is back online now
if folder["can_override"]:
folder.set_status(_("Cluster out of sync"))
folder.set_status(folder["override_title"])
else:
folder.set_status(_("Up to Date"))
folder.set_color_hex(COLOR_FOLDER_IDLE)
Expand Down Expand Up @@ -1420,7 +1424,8 @@ def show_folder(self, id, label, path, folder_type, ignore_perms, rescan_interva
box.add_value("rescan", "rescan.svg", _("Rescan Interval"))
box.add_value("shared", "shared.svg", _("Shared With"))
# Add hidden stuff
box.add_hidden_value("folder_type", folder_type)
box.add_hidden_value("folder_type_s", folder_type)
box.add_hidden_value("override_title", "")
box.add_hidden_value("can_override", False)
box.add_hidden_value("devices", shared)
box.add_hidden_value("norm_path", os.path.abspath(os.path.expanduser(path)))
Expand Down Expand Up @@ -1826,8 +1831,14 @@ def cb_menu_limit_other(self, menuitem, speed):

def cb_popup_menu_folder(self, box, button, time):
self.rightclick_box = box
self["menu-popup-override"].set_visible(box["can_override"])
self["menu-separator-override"].set_visible(box["can_override"])
if box["can_override"]:
self["menu-popup-override"].set_visible(box["folder_type_s"] == "sendonly")
self["menu-popup-revert"].set_visible(box["folder_type_s"] == "receiveonly")
self["menu-separator-override"].set_visible(box["can_override"])
else:
self["menu-popup-override"].set_visible(False)
self["menu-popup-revert"].set_visible(False)
self["menu-separator-override"].set_visible(False)
self["popup-menu-folder"].popup(None, None, None, None, button, time)

def cb_popup_menu_device(self, box, button, time):
Expand Down Expand Up @@ -1900,6 +1911,11 @@ def cb_menu_popup_override(self, *a):
log.info("Override folder %s", self.rightclick_box["id"])
self.daemon.override(self.rightclick_box["id"])

def cb_menu_popup_revert(self, *a):
""" Handler for 'override local' context menu item """
log.info("Revert folder %s", self.rightclick_box["id"])
self.daemon.revert(self.rightclick_box["id"])

def cb_menu_popup_delete_device(self, *a):
""" Handler for other 'edit' context menu item """
self.check_delete("device", self.rightclick_box["id"], self.rightclick_box.get_title())
Expand Down
7 changes: 6 additions & 1 deletion syncthing_gtk/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -1006,10 +1006,15 @@ def rescan(self, folder_id, path=None):
RESTPOSTRequest(self, url, {}, lambda *a: a, lambda *a: log.error(a), folder_id).start()

def override(self, folder_id):
""" Asks daemon to override changes made in specified folder """
""" Asks daemon to override remote changes made in specified folder """
id_enc = urllib.quote(folder_id.encode('utf-8'))
RESTPOSTRequest(self, "db/override?folder=%s" % (id_enc,), {}, lambda *a: a, lambda *a: log.error(a), folder_id).start()

def revert(self, folder_id):
""" Asks daemon to revert local changes made in specified folder """
id_enc = urllib.quote(folder_id.encode('utf-8'))
RESTPOSTRequest(self, "db/revert?folder=%s" % (id_enc,), {}, lambda *a: a, lambda *a: log.error(a), folder_id).start()

def request_events(self):
"""
No longer needed.
Expand Down

0 comments on commit 0c55d13

Please sign in to comment.