-
Notifications
You must be signed in to change notification settings - Fork 791
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
Fix pause sync states #2209
Conversation
src/gui/systray.cpp
Outdated
@@ -105,6 +105,11 @@ void Systray::create() | |||
} | |||
hideWindow(); | |||
emit activated(QSystemTrayIcon::ActivationReason::Unknown); | |||
foreach (Folder *f, FolderMan::instance()->map()) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
src/gui/systray.cpp
Outdated
@@ -105,6 +105,11 @@ void Systray::create() | |||
} | |||
hideWindow(); | |||
emit activated(QSystemTrayIcon::ActivationReason::Unknown); | |||
for (const auto *folderMap : FolderMan::instance()->map()) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. :-)
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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..
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
/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>
59b7733
to
cd3a728
Compare
src/gui/systray.cpp
Outdated
|
||
const auto folderMap = FolderMan::instance()->map(); | ||
for (const auto *folder : folderMap) { | ||
if(!folder->syncPaused()) { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
AppImage file: Nextcloud-PR-2209-a07db657d5cf1073b99122aa1345e05283ce0abd-x86_64.AppImage |
Fixes #2207
Fixes #2206
Changes: