From 0c55d13bfb2d6d4b290e52be4b7ae263400fad93 Mon Sep 17 00:00:00 2001 From: kozec Date: Sat, 3 Aug 2019 13:03:18 +0200 Subject: [PATCH] Fix: receive-only folder displays nonsense when out of sync. Fixes #512 --- glade/app.glade | 18 ++++++++++++ locale/en/LC_MESSAGES/syncthing-gtk.po | 8 ++++++ syncthing_gtk/app.py | 38 ++++++++++++++++++-------- syncthing_gtk/daemon.py | 7 ++++- 4 files changed, 59 insertions(+), 12 deletions(-) diff --git a/glade/app.glade b/glade/app.glade index 67ad8e99..f56a1684 100644 --- a/glade/app.glade +++ b/glade/app.glade @@ -483,6 +483,18 @@ + + + True + False + Override Local Changes + True + True + True + menu-popup-revert-image + + + True @@ -1026,6 +1038,12 @@ edit-undo + + True + False + edit-undo + + True False diff --git a/locale/en/LC_MESSAGES/syncthing-gtk.po b/locale/en/LC_MESSAGES/syncthing-gtk.po index 83ebda13..50050d96 100644 --- a/locale/en/LC_MESSAGES/syncthing-gtk.po +++ b/locale/en/LC_MESSAGES/syncthing-gtk.po @@ -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 "" @@ -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" diff --git a/syncthing_gtk/app.py b/syncthing_gtk/app.py index f056d1b0..f6d2446b 100644 --- a/syncthing_gtk/app.py +++ b/syncthing_gtk/app.py @@ -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 @@ -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) @@ -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))) @@ -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): @@ -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()) diff --git a/syncthing_gtk/daemon.py b/syncthing_gtk/daemon.py index 9f864fe7..bd03cdae 100644 --- a/syncthing_gtk/daemon.py +++ b/syncthing_gtk/daemon.py @@ -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.