Lomiri Action API
Offline Actions

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);
// matches the .desktop file Desktop Action identifier
newMessageAction->setName("Compose");
Action *openAddressBookAction = new Action(this);
// matches the .desktop file Desktop Action identifier
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:

/* This file is part of lomiri-action-api
* Copyright 2013 Canonical Ltd.
*
* lomiri-action-api is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3,
* as published by the Free Software Foundation.
*
* lomiri-action-api is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranties of
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#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);
// matches the .desktop file Desktop Action identifier
newMessageAction->setName("Compose");
newMessageAction->setText(tr("Compose New Message"));
newMessageAction->setKeywords(tr("Write New Message;Send New Message"));
connect(newMessageAction, &Action::triggered, this, &MailApp::newMessage);
Action *openAddressBookAction = new Action(this);
// matches the .desktop file Desktop Action identifier
openAddressBookAction->setName("Contacts");
openAddressBookAction->setText(tr("Open Address Book"));
connect(openAddressBookAction, &Action::triggered, this, &MailApp::openAddressBook);
ActionManager *actionManager = new ActionManager(this);
actionManager->addAction(newMessageAction);
actionManager->addAction(openAddressBookAction);
}
void
MailApp::newMessage()
{
// show the compose view
}
void
MailApp::openAddressBook()
{
// show the address book view
}
int main(int argc, char *argv[])
{
QApplication *app = new QApplication(argc, argv);
MailApp mailApp;
mailApp.show();
return app->exec();
}
#include "mail-app.moc"
Definition: lomiri-action-manager.h:32
The main action class.
Definition: lomiri-action.h:31