Visual D-Bus and D-Bus Inspector ) or the command line (Figure 1). The second approach uses the source code study methodology described in the previous article.
org.nemomobile.dbus module; secondly, about the way to access the D-Bus from the desktop-files.org.nemomobile.dbus QML module provides two main components for working with D-Bus: DBusAdaptor and DBusInterface . The first allows the application to create its own interface, the second - to use the existing one. In general information retrieval, both components are of interest, as they allow you to learn how to interact with the application from the outside, and how the application uses third-party interfaces, respectively./usr/share/jolla-settings and check for D-Bus usage: $ cd /usr/share/jolla-settings/ $ grep -i -H 'dbus' * settings.qml:import org.nemomobile.dbus 2.0 settings.qml: DBusAdaptor { $ grep -A 5 'DBusAdaptor' ./settings.qml DBusAdaptor { service: "com.jolla.settings" path: "/com/jolla/settings/ui" iface: "com.jolla.settings.ui" function showSettings() { /usr/share/applications directory; secondly, using the described functions starts an instance of the application; thirdly, when describing interaction with D-Bus, fields with the X-Maemo prefix are used:X-Maemo-Service - service, or the location of the application on the user or system bus;X-Maemo-Object-Path - the path or name of the object;X-Maemo-Method - the name of the called method.X-Maemo prefixes appeared in Sailfish OS as a legacy from the Maemo operating system (Figure 2), previously developed by Nokia. They allow you to declare D-Bus functions in such a way that they can be accessed without first running the program. These functions allow you to start the program with the implementation before it opens some preliminary work.MimeType field to specify the types of files that the program can handle. An example implementation is available on GitHub ./usr/share/applications directory and search for one of the keywords: $ cd /usr/share/applications/ $ grep -H 'X-Maemo-Service' * jolla-calendar-import.desktop:X-Maemo-Service=com.jolla.calendar.ui jolla-calendar.desktop:X-Maemo-Service=com.jolla.calendar.ui jolla-camera-viewfinder.desktop:X-Maemo-Service=com.jolla.camera jolla-clock.desktop:X-Maemo-Service=com.jolla.clock jolla-contacts-import.desktop:X-Maemo-Service=com.jolla.contacts.ui jolla-email.desktop:X-Maemo-Service=com.jolla.email.ui jolla-gallery-openfile.desktop:X-Maemo-Service=com.jolla.gallery jolla-gallery-playvideostream.desktop:X-Maemo-Service=com.jolla.gallery jolla-mediaplayer-openfile.desktop:X-Maemo-Service=com.jolla.mediaplayer jolla-mediaplayer.desktop:X-Maemo-Service=com.jolla.mediaplayer jolla-messages-openurl.desktop:X-Maemo-Service=org.nemomobile.qmlmessages jolla-messages.desktop:X-Maemo-Service=org.nemomobile.qmlmessages jolla-notes-import.desktop:X-Maemo-Service=com.jolla.notes jolla-notes.desktop:X-Maemo-Service=com.jolla.notes jolla-settings.desktop:X-Maemo-Service=com.jolla.settings new-mail.desktop:X-Maemo-Service=com.jolla.email.ui open-url.desktop:X-Maemo-Service=org.sailfishos.browser.ui ovpn-import.desktop:X-Maemo-Service=com.jolla.settings sailfish-office-openfile.desktop:X-Maemo-Service=org.sailfish.office sailfish-office.desktop:X-Maemo-Service=org.sailfish.office simkit.desktop:X-Maemo-Service=org.sailfish.simkit voicecall-ui-openurl.desktop:X-Maemo-Service=com.jolla.voicecall.ui voicecall-ui.desktop:X-Maemo-Service=com.jolla.voicecall.ui /usr/share/jolla-calendar directory (principles of directory naming were described in the previous article) and find out which files have a D-Bus address: $ cd /usr/share/jolla-calendar/ $ grep -r -i -H 'dbus' * DbusInvoker.qml:import org.nemomobile.dbus 2.0 DbusInvoker.qml:DBusAdaptor { calendar.qml:import org.nemomobile.dbus 2.0 calendar.qml: DbusInvoker {} DbusInvoker.qml file, which contains only the definitions of the interface and D-Bus functions: $ cat ./DbusInvoker.qml -n 1 import QtQuick 2.0 2 import Sailfish.Silica 1.0 3 import org.nemomobile.dbus 2.0 4 import Calendar.dateParser 1.0 5 6 DBusAdaptor { 7 service: "com.jolla.calendar.ui" 8 path: "/com/jolla/calendar/ui" 9 iface: "com.jolla.calendar.ui" 10 11 function viewEvent(id, recurrenceId, startDate) { 12 var occurrence = DateParser.parseTime(startDate) 13 if (isNaN(occurrence.getTime())) { 14 console.warn("Invalid event start date, unable to show event") 15 return 16 } 17 18 if (pageStack.currentPage.objectName === "EventViewPage") { 19 pageStack.currentPage.uniqueId = id 20 pageStack.currentPage.recurrenceId = recurrenceId 21 pageStack.currentPage.startTime = occurrence 22 } else { 23 pageStack.push("pages/EventViewPage.qml", 24 { uniqueId: id, recurrenceId: recurrenceId, startTime: occurrence }, 25 PageStackAction.Immediate) 26 } 27 requestActive.start() 28 } 29 30 function viewDate(dateTime) { 31 var parsedDate = new Date(dateTime) 32 if (isNaN(parsedDate.getTime())) { 33 console.warn("Invalid date, unable to show events for date") 34 return 35 } 36 37 if (pageStack.currentPage.objectName === "DayPage") { 38 pageStack.currentPage.date = parsedDate 39 } else { 40 pageStack.push("pages/DayPage.qml", { date: parsedDate }, PageStackAction.Immediate) 41 } 42 requestActive.start() 43 } 44 45 function importFile(fileName) { 46 if (pageStack.currentPage.objectName === "ImportPage") { 47 pageStack.currentPage.fileName = fileName 48 } else { 49 pageStack.push("pages/ImportPage.qml", { "fileName": fileName }, PageStackAction.Immediate) 50 } 51 requestActive.start() 52 } 53 54 function activateWindow(arg) { 55 app.activate() 56 } 57 } com.jolla.calendar.ui service and use the path /com/jolla/calendar/ui and the interface com.jolla.calendar.ui (lines 7-9). After that, the declared functions will become available, of which, within the framework of the task, only the viewDate (lines 30-43) is of interest, taking as argument one of the date representations recognized by the Date object. The results obtained allow you to implement your component to work with the calendar: import QtQuick 2.0 import Sailfish.Silica 1.0 import org.nemomobile.dbus 2.0 Item { id: calendarControl /* . */ function showAgenda() { calendar.call('viewDate', Date.now()) } DBusInterface { id: calendar service: 'com.jolla.calendar.ui' path: '/com/jolla/calendar/ui' iface: 'com.jolla.calendar.ui' } } /usr/share/jolla-settings/pages/flashlight directory, you must connect to the com.jolla.settings.system.flashlight service and use the path /com/jolla/settings/system/flashlight and the interface com.jolla.settings.system.flashlight . After that, by calling the toggleFlashlight function without parameters, it becomes possible to turn the flash on and off.getProperty function with the "flashlightOn" parameter passed to it. In this case, returns a boolean value. $ cd /usr/share/jolla-settings $ grep -i -H "dbus" ./pages/flashlight/* ./pages/flashlight/Flashlight.qml:import org.nemomobile.dbus 2.0 ./pages/flashlight/Flashlight.qml: flashlightDbus.call("toggleFlashlight", undefined, handleToggle, handleError) ./pages/flashlight/Flashlight.qml: property QtObject flashlightDbus: DBusInterface { ./pages/flashlight/Flashlight.qml: flashlight.flashlightOn = flashlightDbus.getProperty("flashlightOn") $ grep -A 5 -i -H "DBusInterface" ./pages/flashlight/Flashlight.qml ./pages/flashlight/Flashlight.qml: property QtObject flashlightDbus: DBusInterface { ./pages/flashlight/Flashlight.qml- signalsEnabled: true ./pages/flashlight/Flashlight.qml- service: "com.jolla.settings.system.flashlight" ./pages/flashlight/Flashlight.qml- path: "/com/jolla/settings/system/flashlight" ./pages/flashlight/Flashlight.qml- iface: "com.jolla.settings.system.flashlight" ./pages/flashlight/Flashlight.qml- function flashlightOnChanged(newOn) { import QtQuick 2.0 import Sailfish.Silica 1.0 import org.nemomobile.dbus 2.0 Item { id: flashlightControl // . property bool flashlightOn // . function toggleFlashlight() { flashlightOn = !flashlightOn; flashlight.call("toggleFlashlight", undefined); } DBusInterface { id: flashlight service: "com.jolla.settings.system.flashlight" path: "/com/jolla/settings/system/flashlight" iface: "com.jolla.settings.system.flashlight" signalsEnabled: true function flashlightOnChanged(newOn) { flashlightControl.flashlightOn = newOn } } Component.onCompleted: { flashlightControl.flashlightOn = flashlight.getProperty("flashlightOn") } } sailfish-browser https://google.com/ command sailfish-browser https://google.com/ . But this is beyond the scope of the material described in the article. $ sailfish-browser https://google.com/ [D] unknown:0 - Using Wayland-EGL greHome from GRE_HOME:/usr/bin libxul.so is not found, in /usr/bin/libxul.so Created LOG for EmbedLite [D] onCompleted:103 - ViewPlaceholder requires a SilicaFlickable parent Loaded xulDir:/usr/lib/xulrunner-qt5-38.8.0/libxul.so, appDir:/usr/bin EmbedLiteExt virtual nsresult EmbedChromeManager::Observe(nsISupports*, const char*, const char16_t*):82: obj:(nil), top:app-startup EmbedLiteExt virtual nsresult EmbedTouchManager::Observe(nsISupports*, const char*, const char16_t*):86: obj:(nil), top:app-startup EmbedLiteGlobalHelper app-startup EmbedLiteSyncService app-startup PREFS SERVICE INITAILIZED EmbedPrefService app-startup EmbedliteDownloadManager initialized UserAgentOverrideHelper app-startup 1505073762747 addons.manager DEBUG Application has been upgraded 1505073762892 addons.manager DEBUG Loaded provider scope for resource://gre/modules/addons/XPIProvider.jsm: ["XPIProvider"] 1505073762912 addons.manager DEBUG Loaded provider scope for resource://gre/modules/LightweightThemeManager.jsm: ["LightweightThemeManager"] 1505073762942 addons.manager DEBUG Loaded provider scope for resource://gre/modules/addons/GMPProvider.jsm 1505073762961 addons.manager DEBUG Loaded provider scope for resource://gre/modules/addons/PluginProvider.jsm 1505073762968 addons.manager DEBUG Starting provider: XPIProvider 1505073762973 addons.xpi DEBUG startup 1505073762982 addons.xpi DEBUG checkForChanges 1505073762993 addons.xpi DEBUG Loaded add-on state from prefs: {} 1505073763000 addons.xpi DEBUG getInstallState changed: false, state: {} 1505073763009 addons.xpi DEBUG Empty XPI database, setting schema version preference to 16 1505073763012 addons.xpi DEBUG No changes found 1505073763015 addons.manager DEBUG Registering shutdown blocker for XPIProvider 1505073763021 addons.manager DEBUG Provider finished startup: XPIProvider 1505073763022 addons.manager DEBUG Starting provider: LightweightThemeManager 1505073763024 addons.manager DEBUG Registering shutdown blocker for LightweightThemeManager 1505073763029 addons.manager DEBUG Provider finished startup: LightweightThemeManager 1505073763032 addons.manager DEBUG Starting provider: GMPProvider 1505073763046 addons.manager DEBUG Registering shutdown blocker for GMPProvider 1505073763050 addons.manager DEBUG Provider finished startup: GMPProvider 1505073763052 addons.manager DEBUG Starting provider: PluginProvider 1505073763055 addons.manager DEBUG Registering shutdown blocker for PluginProvider 1505073763059 addons.manager DEBUG Provider finished startup: PluginProvider 1505073763060 addons.manager DEBUG Completed startup sequence Created LOG for EmbedPrefs [D] QMozWindowPrivate::setSize:71 - Trying to set empty size: QSize(-1, -1) Attempting load of libEGL.so EmbedLiteExt virtual nsresult EmbedTouchManager::Observe(nsISupports*, const char*, const char16_t*):86: obj:0xb225a130, top:domwindowopened EmbedLiteExt void EmbedChromeManager::WindowCreated(nsIDOMWindow*):91: WindowOpened: 0xb225a140 EmbedLiteExt void EmbedTouchManager::WindowCreated(nsIDOMWindow*):95: WindowOpened: 0xb225a140 EmbedLiteExt void EmbedTouchManager::WindowCreated(nsIDOMWindow*):108: id for window: 1 ###################################### SelectAsyncHelper.js loaded ###################################### embedhelper.js loaded ### ContextMenuHandler.js loaded ### SelectionPrototype.js loaded ### SelectionHandler.js loaded Init Called:[object Object] JavaScript warning: https://www.google.ru/xjs/_/js/k=xjs.mhp.en_US.2vKAz7DqmvI.O/m=sb_mobh,hjsa,d,csi/am=AAAD/rt=j/d=1/t=zcms/rs=ACT90oFx8AHVqc9lMfPQBwURKXyQ4qaFiA, line 7: mutating the [[Prototype]] of an object will cause your code to run very slowly; instead create the object with the correct initial [[Prototype]] value using Object.create | Description | Required data |
|---|---|
| Create atmosphere | |
| Adjust screen brightness | |
| Adjust screen orientation | |
| Automatic adjustment of screen brightness | |
| Setting the sleep time | |
| Setting the display status while charging | |
| Setting the system font size | |
| Adjusting the system volume | |
| Vibration setting | |
| Enable / disable sounds for system events | |
| Enable / Disable WLAN | |
| Enable / Disable Internet Sharing | |
| Enable / Disable Flight Mode | |
| Turn on / off Bluetooth | |
| Description | Required data |
|---|---|
| View calendar event | Service:com.jolla.calendar.uiWay: /com/jolla/calendar/uiInterface: com.jolla.calendar.uiFunction: viewEvent(id, recurrenceId, startDate) |
| View the day on the calendar | Service:com.jolla.calendar.uiWay: /com/jolla/calendar/uiInterface: com.jolla.calendar.uiFunction: viewDate(dateTime) |
| Opening the camera in the last state | Service:com.jolla.cameraWay: /Interface: com.jolla.camera.uiFunction: showViewfinder() |
| Opening the front camera | Service:com.jolla.cameraWay: /Interface: com.jolla.camera.uiFunction: showFrontViewfinder() |
| Create alarm | Service:com.jolla.clockWay: /Interface: com.jolla.clockFunction: newAlarm() |
| View contact | Service:com.jolla.contacts.uiWay: /com/jolla/contacts/uiInterface: com.jolla.contacts.uiFunction: showContact(int contactId) |
| Editing a contact | Service:com.jolla.contacts.uiWay: /com/jolla/contacts/uiInterface: com.jolla.contacts.uiFunction: editContact(int contactId) |
| Importing contacts | Service:com.jolla.contacts.uiWay: /com/jolla/contacts/uiInterface: com.jolla.contacts.uiFunction: importWizard() |
| Play audio file by URL | Service:com.jolla.mediaplayerWay: /com/jolla/mediaplayer/uiInterface: com.jolla.mediaplayer.uiFunction: openUrl(url) |
| Create a new note | Service:com.jolla.notesWay: /Interface: com.jolla.notesFunction: newNote() |
| View settings | Service:com.jolla.settingsWay: /com/jolla/settings/uiInterface: com.jolla.settings.uiFunction: showSettings() |
| View Download List | Service:com.jolla.settingsWay: /com/jolla/settings/uiInterface: com.jolla.settings.uiFunction: showTransfers() |
| View list of accounts | Service:com.jolla.settingsWay: /com/jolla/settings/uiInterface: com.jolla.settings.uiFunction: showAccounts() |
| View call recording settings | Service:com.jolla.settingsWay: /com/jolla/settings/uiInterface: com.jolla.settings.uiFunction: showCallRecordings() |
| Enable / Disable Android Support | Service:com.jolla.apkdWay: /com/jolla/apkdInterface: com.jolla.apkdFunction: controlService(true/false) |
| Turn on / off flash | Service:com.jolla.settings.system.flashlightWay: /com/jolla/settings/system/flashlightInterface: com.jolla.settings.system.flashlightFunction: toggleFlashlight() |
| Reboot device | Service:com.nokia.dsmeWay: /com/nokia/dsme/requestInterface: com.nokia.dsme.requestFunction: req_reboot() |
| Turn off the device | Service:com.nokia.dsmeWay: /com/nokia/dsme/requestInterface: com.nokia.dsme.requestFunction: req_shutdown |
| Call | Service:com.jolla.voicecall.uiWay: /Interface: com.jolla.voicecall.uiFunction: dial(number) |
| View images in the gallery | Service:com.jolla.galleryWay: /com/jolla/gallery/uiInterface: com.jolla.gallery.uiFunction: showImages(array_of_urls) |
| View Video Gallery | Service:com.jolla.galleryWay: /com/jolla/gallery/uiInterface: com.jolla.gallery.uiFunction: playVideoStream(url) |
| Create a new letter | Service:com.jolla.email.uiWay: /com/jolla/email/uiInterface: com.jolla.email.uiFunction: mailto() |
| Search for WLAN networks | Service:com.jolla.lipstick.ConnectionSelectorWay: /Interface: com.jolla.lipstick.ConnectionSelectorIfFunction: openConnectionNow('wifi') |
Source: https://habr.com/ru/post/337618/
All Articles