Applications can define offline (jump list) actions in their .desktop files. These actions are available in the Launcher, AppMenu, HUD and MessagingMenu even if the application is not running. When an offline action is executed and the application is not running the application is started and executes the given action on startup, but for the user it does not make any difference if the application is running or not prior to the action invocation.
This example assumes we have a mail application, MailApp. This application defines offline actions in mail-app.desktop:
[Desktop Entry]
Encoding=UTF-8
Name=Mail Application
Exec=mail-app %u
Actions=Compose;Contacts
[Desktop Action Compose]
Name=Compose New Message
OnlyShowIn=Messaging Menu;Lomiri;
Exec=
[Desktop Action Contacts]
Name=Contacts
OnlyShowIn=Messaging Menu;Lomiri;
Exec=
The desktop file's Actions key lists the offline actions. Each action then has its own group entry in the .desktop file. MailApp defines two offline actions: Compose and Contacts.
By leaving the Exec keys empty for the actions the platform will invoke the Lomiri Actions defined by the application.
Now, the Application has to define corresponding actions in it's code:
Action *newMessageAction = new Action(this);
newMessageAction->setName("Compose");
Action *openAddressBookAction = new Action(this);
openAddressBookAction->setName("Contacts");
And finally add the actions to the manager.
ActionManager *actionManager = new ActionManager(this);
actionManager->addAction(newMessageAction);
actionManager->addAction(openAddressBookAction);
Here is the full example also showing the connections to the Action::triggered() signal:
#include <QMainWindow>
#include <QApplication>
#include <lomiri/action/Action>
#include <lomiri/action/ActionManager>
class MailApp : public QMainWindow
{
Q_OBJECT
public:
MailApp(QWidget *parent = 0);
public slots:
void newMessage();
void openAddressBook();
private:
};
MailApp::MailApp(QWidget *parent)
: QMainWindow(parent)
{
Action *newMessageAction = new Action(this);
newMessageAction->setName("Compose");
newMessageAction->setText(tr("Compose New Message"));
newMessageAction->setKeywords(tr("Write New Message;Send New Message"));
Action *openAddressBookAction = new Action(this);
openAddressBookAction->setName("Contacts");
openAddressBookAction->setText(tr("Open Address Book"));
ActionManager *actionManager = new ActionManager(this);
actionManager->addAction(newMessageAction);
actionManager->addAction(openAddressBookAction);
}
void
MailApp::newMessage()
{
}
void
MailApp::openAddressBook()
{
}
int main(int argc, char *argv[])
{
QApplication *app = new QApplication(argc, argv);
MailApp mailApp;
mailApp.show();
return app->exec();
}
#include "mail-app.moc"