KActivities 5.109.0
Properties | Signals | Public Slots | Public Member Functions | Static Public Member Functions | List of all members
KActivities::ResourceInstance

This class is used to notify the system that a file, web page or some other resource has been accessed. More...

#include <resourceinstance.h>

Properties

QString mimetype
 
QString title
 
QUrl uri
 
quintptr winId
 

Signals

void requestsFocus ()
 Emitted when the system wants to show the resource represented by this ResourceInstance.
 

Public Slots

void notifyFocusedIn ()
 Call this method to notify the system that the resource has the focus in your application.
 
void notifyFocusedOut ()
 Call this method to notify the system that the resource lost the focus in your application.
 
void notifyModified ()
 Call this method to notify the system that you modified (the contents of) the resource.
 
void setMimetype (const QString &mimetype)
 Sets the mimetype for this resource.
 
void setTitle (const QString &title)
 Sets the title for this resource.
 
void setUri (const QUrl &newUri)
 This is a convenience method that sets the new URI.
 

Public Member Functions

 ResourceInstance (quintptr wid, const QString &application, QObject *parent=nullptr)
 Creates a new resource instance.
 
 ResourceInstance (quintptr wid, QObject *parent=nullptr)
 Creates a new resource instance.
 
 ResourceInstance (quintptr wid, QUrl resourceUri, const QString &mimetype=QString(), const QString &title=QString(), const QString &application=QString(), QObject *parent=nullptr)
 Creates a new resource instance and automatically notifies the system that it was opened.
 
 ~ResourceInstance () override
 Destroys the ResourceInstance and notifies the system that the resource has been closed.
 
QString mimetype () const
 
QString title () const
 
virtual QUrl uri () const
 
quintptr winId () const
 

Static Public Member Functions

static void notifyAccessed (const QUrl &uri, const QString &application=QString())
 If there's no way to tell for how long an application is keeping the resource open, you can just call this static method - it will notify the system that the application has accessed the resource.
 

Detailed Description

This class is used to notify the system that a file, web page or some other resource has been accessed.

It provides methods to notify the system when the resource was opened, modified and closed, along with in what window the resource is shown.

You should create an instance of this class for every resource you open.

"The system" in this case can be the backend for tracking and automatically scoring files that are being accessed, the system to show the open files per window in the taskbar, the share-like-connect, etc.

The user of this class shouldn't care about the backend systems - everything is done under-the-hood automatically.

Constructor & Destructor Documentation

◆ ResourceInstance() [1/3]

KActivities::ResourceInstance::ResourceInstance ( quintptr  wid,
QObject *  parent = nullptr 
)
explicit

Creates a new resource instance.

Parameters
widid of the window that will show the resource
parentpointer to the parent object
Since
4.10

◆ ResourceInstance() [2/3]

KActivities::ResourceInstance::ResourceInstance ( quintptr  wid,
const QString &  application,
QObject *  parent = nullptr 
)
explicit

Creates a new resource instance.

Parameters
widid of the window that will show the resource
applicationapplication's name (the name used for the .desktop file). If not specified, QCoreApplication::applicationName is used
parentpointer to the parent object

◆ ResourceInstance() [3/3]

KActivities::ResourceInstance::ResourceInstance ( quintptr  wid,
QUrl  resourceUri,
const QString &  mimetype = QString(),
const QString &  title = QString(),
const QString &  application = QString(),
QObject *  parent = nullptr 
)

Creates a new resource instance and automatically notifies the system that it was opened.

In some special cases, where the URI of the resource is being constantly changed (for example, in the world globe, street map applications) you have two options:

  • to pass an empty resourceUri while passing the mimetype
  • to update the uri from time to time (in the example of the world map - to send URIs for major objects - cities or main streets. and in both cases reimplementing the currentUri() method which will return the exact URI shown at that specific moment.
Parameters
widwindow id in which the resource is shown
resourceUriURI of the resource that is shown
mimetypethe mime type of the resource
titlethe title of the resource
applicationapplication's name (the name used for the .desktop file). If not specified, QCoreApplication::applicationName is used
parentpointer to the parent object

◆ ~ResourceInstance()

KActivities::ResourceInstance::~ResourceInstance ( )
override

Destroys the ResourceInstance and notifies the system that the resource has been closed.

Member Function Documentation

◆ mimetype()

QString KActivities::ResourceInstance::mimetype ( ) const
Returns
mimetype of the resource

◆ notifyAccessed()

static void KActivities::ResourceInstance::notifyAccessed ( const QUrl &  uri,
const QString &  application = QString() 
)
static

If there's no way to tell for how long an application is keeping the resource open, you can just call this static method - it will notify the system that the application has accessed the resource.

Parameters
uriURI of the resource
applicationapplication's name (the name used for the .desktop file). If not specified, QCoreApplication::applicationName is used

◆ notifyFocusedIn

void KActivities::ResourceInstance::notifyFocusedIn ( )
slot

Call this method to notify the system that the resource has the focus in your application.

Note
You only need to call this in MDI applications

◆ notifyFocusedOut

void KActivities::ResourceInstance::notifyFocusedOut ( )
slot

Call this method to notify the system that the resource lost the focus in your application.

Note
You only need to call this in MDI applications

◆ notifyModified

void KActivities::ResourceInstance::notifyModified ( )
slot

Call this method to notify the system that you modified (the contents of) the resource.

◆ requestsFocus

void KActivities::ResourceInstance::requestsFocus ( )
signal

Emitted when the system wants to show the resource represented by this ResourceInstance.

You should listen to this signal if you have multiple resources shown in one window (MDI). On catching it, show the resource and give it focus.

◆ setMimetype

void KActivities::ResourceInstance::setMimetype ( const QString &  mimetype)
slot

Sets the mimetype for this resource.

◆ setTitle

void KActivities::ResourceInstance::setTitle ( const QString &  title)
slot

Sets the title for this resource.

◆ setUri

void KActivities::ResourceInstance::setUri ( const QUrl &  newUri)
slot

This is a convenience method that sets the new URI.

This is usually handled by sending the close event for the previous URI, and an open event for the new one.

◆ title()

QString KActivities::ResourceInstance::title ( ) const
Returns
title of the resource

◆ uri()

virtual QUrl KActivities::ResourceInstance::uri ( ) const
virtual
Returns
the current uri The default implementation returns the URI that was passed to the constructor. You need to reimplement it only for the applications with frequently updated URIs.

◆ winId()

quintptr KActivities::ResourceInstance::winId ( ) const
Returns
the window id