Add previous-/nextActivity methods
ClosedPublic

Authored by muesli on Jul 10 2019, 2:53 PM.

Details

Summary

These two methods can be used to switch to the previous/next activity in
alphabetical order. They are exposed via the DBus interface. This
functionality can also be accessed by kactivities(-cli) and plasmashell, which
currently both implement their own separate versions of it.

@ivan mentioned being a bit wary of keeping a sorted activity list in
kactivitymanagerd, so I've opted to only retrieve and sort the list on demand
here.

Diff Detail

Repository
R161 KActivity Manager Service
Branch
prevnext-activity (branched from master)
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 13849
Build 13867: arc lint + arc unit
muesli created this revision.Jul 10 2019, 2:53 PM
Restricted Application added a project: Plasma. · View Herald TranscriptJul 10 2019, 2:53 PM
Restricted Application added a subscriber: plasma-devel. · View Herald Transcript
muesli requested review of this revision.Jul 10 2019, 2:53 PM
ivan requested changes to this revision.Jul 10 2019, 4:14 PM
ivan added inline comments.
src/service/Activities.cpp
243

I don't like the fact that it constantly resorts the activities.

The second problem is that ListActivities returns a list in one order, and this traverses activities in another order. If this will work by name, probably the List functions should as well.

This revision now requires changes to proceed.Jul 10 2019, 4:14 PM
muesli added inline comments.Jul 10 2019, 8:07 PM
src/service/Activities.cpp
243

List probably returns a fairly randomized (per session) list, seeing how it's returning keys() from a QHash. Maybe I misunderstood you on IRC, I thought you'd rather not store a sorted list here. Instead of keeping a sorted cache though, maybe we should just keep the original list in a sorted order?

ivan added a comment.Jul 10 2019, 9:33 PM

You are right, they are randomized.

And, yes, that is what I meant on IRC - that redundancy due to keeping a sorted list will likely lead to future issues, but I see no other way if we want to be consistent regarding listing and switching.

As it is required to have fast access by UUID, the hash needs to stay. So, I'd say we will need the redundancy. Maybe there is some multi-key sorted multi-map in boost - kamd already uses boost::flat_map, so this would be fine. :)

muesli updated this revision to Diff 61579.Jul 11 2019, 10:58 AM

Keep an alphabetically sorted list of activities

Summary:
Instead of re-sorting the activity list every time previous-/nextActivity gets
called, maintain a sorted list.

ivan requested changes to this revision.Jul 11 2019, 12:14 PM

Inserting/Removing/Updating a sorted list does not need to resort every time - removing is easy, adding a new item is std::lower_bound (a binary search), and updating is a combination of the two.

src/service/Activities.cpp
54

You can use anonymous namespace for this (instead of static) or just make it a non-static function.

It can be marked as inline, although the compiler will probably do that regardless of you saying so.

You can rename it to something like nameBasedOrdering - better communicates what it does.

342

You can just find the activity in the list, and remove it - the order for the rest will not change.

src/service/Activities_p.h
76

QList -> QVector.

QList is an evil and slow class :)

This revision now requires changes to proceed.Jul 11 2019, 12:14 PM
muesli updated this revision to Diff 61588.Jul 11 2019, 12:19 PM

Use a QVector instead of a QList to store sorted activities.

muesli marked 3 inline comments as done.Jul 11 2019, 12:22 PM
muesli updated this revision to Diff 61589.Jul 11 2019, 12:52 PM

Addressed @ivan's change requests

Summary:

  • Renamed sorting method to nameBaseOrdering
  • Remove activity from sorted cache without re-sorting the entire list
  • Switch to prev/next running activity, skipping other states
muesli marked an inline comment as done.Jul 11 2019, 12:54 PM
muesli updated this revision to Diff 61590.Jul 11 2019, 12:57 PM

Move nameBaseOrdering to an anonymous namespace and mark it as inline.

muesli marked an inline comment as done.Jul 11 2019, 12:58 PM
ivan added inline comments.Oct 3 2019, 5:40 PM
src/service/Activities.cpp
56

Nitpick Base -> Based

249

Can be done with std::find_if as well

331

This can be done with std::find_if and then remove with iterator.

muesli updated this revision to Diff 67276.Oct 3 2019, 6:57 PM

Fix typo in 'nameBasedOrdering'

ivan accepted this revision.Oct 3 2019, 7:23 PM
This revision is now accepted and ready to land.Oct 3 2019, 7:23 PM
This revision was automatically updated to reflect the committed changes.
muesli marked an inline comment as done.