Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pause sync states #2209

Merged
merged 5 commits into from
Jul 21, 2020
Merged

Fix pause sync states #2209

merged 5 commits into from
Jul 21, 2020

Conversation

DominiqueFuchs
Copy link
Contributor

Fixes #2207
Fixes #2206

Changes:

  1. Fix of a (apparently) copy/paste bug where the same signal (pause) was used for resume and pause slots.
  2. Proper initial setting of _syncIsPaused state variable on Systray creation method (e.g. when accounts are populated and set up, if existing) to ensure correct qml gui dropdown entry text

@@ -105,6 +105,11 @@ void Systray::create()
}
hideWindow();
emit activated(QSystemTrayIcon::ActivationReason::Unknown);
foreach (Folder *f, FolderMan::instance()->map()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use a for range loop, foreach is a deprecated "Qtism" (and we can expect that macro to disappear post-5.15).
Another option is to use std::any_of.
In both cases it's likely a good idea to hold the result of the ->map() call in a const auto variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, thanks! Also makes a point for the 80-100 foreach uses in the rest of the code base, glimpsing through that lets assume that some deep copies could be saved -> #2219

@er-vin er-vin added this to the 2.7 🌟 UI improvements milestone Jul 20, 2020
@@ -105,6 +105,11 @@ void Systray::create()
}
hideWindow();
emit activated(QSystemTrayIcon::ActivationReason::Unknown);
for (const auto *folderMap : FolderMan::instance()->map()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I guess I was being unclear, this is the right hand side of the : which should be wrapped into qAsConst() or stored in a const auto variable. Currently this might detach.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't think of detaching b/c we're receiving a QMap here but I get your point now. But: Why not making the map method return const then as const OCC::Folder::Map map() instead of "casting" it? As it's whole purpose is to essentially generate an iterator for an independent class datablock.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because then for any non const use you'd force a copy for nothing NRVO wouldn't kick in. Returning const data objects is the exception not the norm in most cases it's not what you want.

Rule of thumbs: non const -> const "good", const -> non const "bad". Reality is finer than that but it's a good heuristic. :-)

Copy link
Member

@er-vin er-vin Jul 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And one more thing: yes, you'd hope you don't need the qAsConst or the intermediate const variable (at least personally I find that annoying nowadays). Unfortunately Qt containers are CoW, there was a good reason for that, it's less of a good reason now that move semantic appeared but they can't just be changed to be non-CoW now. So we end up dealing with that legacy...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah thats obvious, my point was that the map() really should be const imho. If you attempt to use map() to modify it, this is not how the current code was built to be used afaik.

But nvmd, for this particular snippet it doesn‘t make difference, rather style, I‘ll go add a qAsConst later..

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah thats obvious, my point was that the map() really should be const imho. If you attempt to use map() to modify it, this is not how the current code was built to be used afaik.

I think you're having a slight confusion here: it's perfectly fine to get the map() and modify it (and so shouldn't be prevented). It's a data type returned by value. I'd be worried if it was a pointer or a reference being returned. There's no risk of breaking the encapsulation here.

I'd even argue it's bad API design to try to make it harder to modify the object returned by map(). It'd be perfectly legitimate for instance to get the object returned by map() and then want to use std::remove_if on it (or whatever) to keep only the entries for which the key start with a given prefix (I'm making up the example but you get the idea).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK turns out qAsConst was implicitly deleted for these kinds of rvalues (in this case QMap). Pulled it out into an extra const auto now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right, qAsConst shouldn't be used on rvalues indeed, my bad.

@er-vin
Copy link
Member

er-vin commented Jul 21, 2020

/rebase

…stead of ::resumeSync

Signed-off-by: Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com>
… done

Signed-off-by: Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com>
Signed-off-by: Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com>
Signed-off-by: Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com>

const auto folderMap = FolderMan::instance()->map();
for (const auto *folder : folderMap) {
if(!folder->syncPaused()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somehow it wasn't here before or I spot it only now: please add a space after if

const auto folderMap = FolderMan::instance()->map();
for (const auto *folder : folderMap) {
if(!folder->syncPaused()) {
_syncIsPaused = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, my brain kicks in only now... sigh.

You can break the loop after that, no need to iterate further on the map.

Signed-off-by: Dominique Fuchs <32204802+DominiqueFuchs@users.noreply.github.com>
@nextcloud-desktop-bot
Copy link

AppImage file: Nextcloud-PR-2209-a07db657d5cf1073b99122aa1345e05283ce0abd-x86_64.AppImage

To test this change/fix you can simply download above AppImage file and test it.

Please make sure to quit your existing Nextcloud app and backup your data.

@er-vin er-vin merged commit f8fb264 into master Jul 21, 2020
@er-vin er-vin deleted the fix-pause-sync-states branch July 21, 2020 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"pause all" does not persist on restart tray icon doesn't show "paused"
3 participants