📜 ⬆️ ⬇️

Start of development for Sailfish OS

Sailfish OS is a mobile platform based on the Linux kernel. You can read about it on the official website or in one of the reviews of the platform on the network. For example, one of them was published on GeekTimes . In this article, I would like to touch on the development of applications for Sailfish OS, talk about how to start programming for this platform, and also share some of the features of development.



To write applications for the Sailfish OS platform, the C ++ language and the Qt library are used, as well as the QML language for describing the graphical interface of applications. Therefore, if you already have experience writing applications using Qt and QML, development for Sailfish OS will not cause you any difficulty. In addition, Sailfish OS allows you to develop native applications in the Python language. However, this topic is beyond the scope of this article and will not be described in it (you can read more about it, for example, here ).
')
As with other mobile platforms, development for Sailfish OS is carried out using the SDK provided by the platform creators. SailfishOS SDK includes:


The Mer Build Engine and the platform emulator are shipped as virtual machine images for VirtualBox. However, VirtualBox itself is not included in the SailfishOS SDK. Therefore, before directly installing the SDK, you must first install VirtualBox version not lower than 4.1.18. In addition, when working in Windows, before installing the SDK, it is also necessary to install the Microsoft Visual C ++ 2010 redistributable (x86) Windows package.

SailfishOS SDK itself is available for Linux, Windows and Max OS X, you can download it here . The SDK comes as a graphical installer, so installing the SDK does not cause any difficulties. However, when installing you will be asked for an alternative way for projects. This parameter is required for the Mer Build Engine virtual machine to have access to the source codes of your project. The default is your home directory. Subsequently, this parameter can be changed in the Qt Creator settings.

After installing the SDK, you are fully prepared to develop applications for the Sailfish OS platform.

Making Hello World! applications also does not cause any difficulties. Just run Qt Creator, click on the “New Project” button on the main screen (or through the menu File -> Create File or Project ...) and set up the project:
  1. We select SailfishOS Qt Quick Application as the application type:

  2. We specify the name and directory in which the project data should be saved (remember that the project should be saved only in your home directory or alternative path for projects specified during installation or in the Qt Creator settings, because for building the project Mer Build Engine should have access to him):

  3. Select the necessary kits that will be used to build the application.

    In total, as can be seen from the screenshot above, two sets are available:
    • MerSDK-SailfishOS-armv7hl - for devices based on ARM architecture (for example, Jolla smartphone),
    • MerSDK-SailfishOS-i486 - for devices based on Intel architecture.

    It is also worth noting here that the emulator works only with the i486 kit. Therefore, if you plan to test your application in the emulator, you need to choose the second set at this step.
  4. Specify additional information about the project:

  5. And that's it, the SDK generated the Hello World project for us.


An automatically generated project is a bit more complicated than the standard one-page Hello World. This allows you to immediately reveal some features of Sailfish OS. The main page displays the standard greeting. However, if on this screen you perform a swipe gesture down (standard control for this platform), a menu will appear at the top, allowing you to go to the second page of the application, where the list of items is located.

Below are screenshots of the Hello World app:


Now let's take a look at the code. Everything here is standard for QML applications and therefore familiar to anyone who has ever written an application using this language. A single .cpp file describes which .qml file should be displayed when the application starts. In our case, this is HelloWorld.qml . In addition, the project contains 2 pages, as well as the Cover Page, which defines the type of application on the Sailfish OS home screen, which displays thumbnails of all running applications and allows you to switch between them or close them.

HelloWorld.qml describes the main application window. It indicates the application's start page and Cover Page, as well as additional application parameters (in our case, these are allowed screen orientations and screen orientation, which will be used by default):
ApplicationWindow { initialPage: Component { FirstPage { } } cover: Qt.resolvedUrl("cover/CoverPage.qml") allowedOrientations: Orientation.All _defaultPageOrientations: Orientation.All } 


FirstPage.qml describes the application's start page. Here, everything is standard for QML applications, but there is some feature of Sailfish OS that you should pay attention to:
 //... SilicaFlickable { anchors.fill: parent PullDownMenu { MenuItem { text: qsTr("  ") onClicked: pageStack.push(Qt.resolvedUrl("SecondPage.qml")) } } //... 

It uses the SilicaFlickable element, which, firstly, allows you to make the content inside the element scrollable, if it does not fit inside the element. And secondly, it allows you to use PullDownMenu - the very menu of the application that opens with the swipe down.

In addition, I would also like to draw attention to the CoverPage.qml , which describes the Cover Page application. It contains the following element:
 CoverActionList { id: coverAction CoverAction { iconSource: "image://theme/icon-cover-next" } CoverAction { iconSource: "image://theme/icon-cover-pause" } } 


This element, in addition to displaying information, also allows the user to control the application directly from his thumbnail on the home screen.

To run the application in the emulator, select the i486 package in the side menu, select the type of assembly (release or debugging) and install the Deploy as RPM Package :


After that just click on the green arrow in the side menu. This action will build the application, start the emulator, install and run your application on the emulator.

In addition, you can simply start the emulator by clicking on the button in the sidebar. This will allow you to simply explore Sailfish OS without having a device on this platform.

That's all, in the future I will try to describe in more detail some features of development for the Sailfish OS platform.

Article author: Denis Laure

UPD: Thank you very much @kirikch for the comments and comments, they were taken into account in the updated text of the article.

Source: https://habr.com/ru/post/305510/


All Articles