Dolphin got the ability to send the events when the user opens a
directory to the activity manager. It is quite a small patch that I
decided to share in order to demonstrate how easy it is to use
KActivities API.
Simple example
Find the widget that displays your document (in this case, a folder).
Declare one KActivities::ResourceInstance object inside it
KActivities::ResourceInstance *
m_activityResourceInstance;
When you create the container, just create a new ResourceInstance and
pass the window id (of the top-level window that your container resides
in) and the url you just opened:
DolphinViewContainer::DolphinViewContainer
(const KUrl& url, QWidget* parent)
{
:::
#ifdef KActivities_FOUND
m_activityResourceInstance
= new KActivities::ResourceInstance(
window()->winId(), url
);
m_activityResourceInstance->setParent(this);
#endif
:::
}
This is it if you have a SDI (single-document interface) - interface
where one main window can contain only one document (okular, kwrite
etc.)
MDI
If you have a possibility to have multiple documents inside one
window (dolphin, konqueror, kate etc.), you’ll need to do some
additional things:
If your component lost the user’s focus (switched to another
document), call:
m_activityResourceInstance->notifyFocusedOut()
When it receives the focus, call:
m_activityResourceInstance->notifyFocusedIn()
And when the url of the document that is shown changes (user opens
another file, navigates to another web page), just call:
m_activityResourceInstance->setUri(newUrl);
This is all.
Why?
This info is used for the share-like-connect applet and to rank the
locations users visit. This can be, in turn, used to sort applications,
documents etc. in krunner based on the ranking; to show most recent
documents for pinned applications in the task bar etc.
Privacy
Although every system tracks the user’s behaviour in some way, it
might not be something the user desires. This will be configurable - see
this for
more info
For the whole ResourceInstance API, see: api.kde.org/KActivities::ResourceInstance