-

   rss_rss_hh_new

 - e-mail

 

 -

 LiveInternet.ru:
: 17.03.2011
:
:
: 51

:


D-Bus Sailfish OS

, 11 2017 . 10:17 +
osanwe 10:17

D-Bus Sailfish OS

  • Tutorial


API Sailfish OS D-Bus . . D-Bus .

Sailfish OS D-Bus . FRUCT:
[1] Sailfish OS;
[2] Sailfish OS: D-Bus.


D-Bus. (, Visual D-Bus D-Bus Inspector) ( 1). .


[ 1 D-Bus.]

, , . , , .


D-Bus ( ) C++ ( ), QML- desktop- . , , -, org.nemomobile.dbus; -, D-Bus desktop-.

QML- org.nemomobile.dbus D-Bus: DBusAdaptor DBusInterface. , . , , , .

, D-Bus , /usr/share/jolla-settings D-Bus:
grep -i -H 'dbus' * && grep -A 5 'DBusAdaptor' ./settings.qml
$ 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() {



, desktop- , , -, desktop- /usr/share/applications; -, ; -, D-Bus X-Maemo:
  • X-Maemo-Service , ;
  • X-Maemo-Object-Path , ;
  • X-Maemo-Method .

X-Maemo Sailfish OS Maemo ( 2), Nokia. D-Bus , . .

image
[ 2 Sailfish OS ().]

, desktop- MimeType , . GitHub.


, , D-Bus, /usr/share/applications :
grep -H 'X-Maemo-Service' *
$ 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



API D-Bus .


, , D-Bus.

, . /usr/share/jolla-calendar ( ) , D-Bus:
grep -r -i -H 'dbus' *
$ 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, D-Bus:
cat ./DbusInvoker.qml -n
$ 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 /com/jolla/calendar/ui com.jolla.calendar.ui ( 7-9). , , , viewDate ( 30-43), , Date. :
CalendarController.qml
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'
    }
}



, D-Bus .

. , /usr/share/jolla-settings/pages/flashlight, com.jolla.settings.system.flashlight /com/jolla/settings/system/flashlight com.jolla.settings.system.flashlight. , toggleFlashlight , .

, . getProperty "flashlightOn". .
grep -i -H 'dbus' ./pages/flashlight/* && grep -A 5 -i -H 'DBusInterface' ./pages/flashlight/Flashlight.qml
$ 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) {



, :
FlashlightController.qml
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")
    }
}




D-Bus Sailfish OS, . . GitHub.

, . , sailfish-browser https://google.com/. .
sailfish-browser https://google.com/
$ 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



API :
import Sailfish.Ambience 1.0

var previousAmbienceUrl = Ambience.source
Ambience.setAmbience(url, function(ambienceId) {
    pageStack.push(ambienceSettings, {
        'contentId': ambienceId,
        'previousAmbienceUrl': previousAmbienceUrl
    })
})
import org.nemomobile.systemsettings 1.0

DisplaySettings { id: displaySettings }

maximumValue: displaySettings.maximumBrightness
minimumValue: 1
value: displaySettings.brightness

displaySettings.brightness = Math.round(value)
import org.nemomobile.systemsettings 1.0

DisplaySettings { id: displaySettings }

displaySettings.orientationLock = "dynamic" //  
displaySettings.orientationLock = "portrait" //  
displaySettings.orientationLock = "landscape" //  
import org.nemomobile.systemsettings 1.0

DisplaySettings { id: displaySettings }

checked: displaySettings.ambientLightSensorEnabled && displaySettings.autoBrightnessEnabled

if (checked) {
    displaySettings.autoBrightnessEnabled = false
} else {
    displaySettings.autoBrightnessEnabled = true
    displaySettings.ambientLightSensorEnabled = true
}
import org.nemomobile.systemsettings 1.0

DisplaySettings { id: displaySettings }

displaySettings.dimTimeout = VALUE_IN_SECONDS
import org.nemomobile.systemsettings 1.0

DisplaySettings { id: displaySettings }

displaySettings.inhibitMode = DisplaySettings.InhibitOff //     
displaySettings.inhibitMode = DisplaySettings.InhibitStayOnWithCharger //      
import org.nemomobile.configuration 1.0

ConfigurationValue {
    id: fontSizeCategory
    key: "/desktop/jolla/theme/font/sizeCategory"
    defaultValue: "normal"
}

fontSizeCategory.value = "normal" //   
fontSizeCategory.value = "large" //   
fontSizeCategory.value = "huge" //   
import org.nemomobile.systemsettings 1.0

ProfileControl { id: profileControl }

maximumValue: 100
minimumValue: 0

profileControl.ringerVolume = value
profileControl.profile = (value > 0) ? "general" : "silent"
import org.nemomobile.systemsettings 1.0

ProfileControl { id: soundSettings }

soundSettings.vibraMode = ProfileControl.VibraAlways //   
soundSettings.vibraMode = ProfileControl.VibraSilent //     
soundSettings.vibraMode = ProfileControl.VibraNormal //     
soundSettings.vibraMode = ProfileControl.VibraNever //   
/
import org.nemomobile.systemsettings 1.0

ProfileControl { id: soundSettings }

soundSettings.systemSoundLevel = false // 
soundSettings.systemSoundLevel = true // 
/ WLAN
import MeeGo.Connman 0.2
import com.jolla.settings 1.0
import com.jolla.connection 1.0

TechnologyModel {
    id: wifiListModel
    name: "wifi"
}

NetworkManagerFactory { id: networkManager }

NetworkTechnology {
    id: wifiTechnology
    path: networkManager.instance.technologyPathForType("wifi")
}

ConnectionAgent { id: connectionAgent }

checked: wifiListModel.available && wifiListModel.powered && !wifiTechnology.tethering

if (wifiTechnology.tethering) connectionAgent.stopTethering(true)
else wifiListModel.powered = !wifiListModel.powered
/
import Sailfish.Telephony 1.0
import Sailfish.Silica.private 1.0
import MeeGo.Connman 0.2
import MeeGo.QOfono 0.2
import com.jolla.connection 1.0

ConnectionAgent { id: connectionAgent }

NetworkManagerFactory { id: networkManager }

NetworkTechnology {
    id: wifiTechnology
    path: networkManager.instance.technologyPathForType("wifi")
}

SimManager {
    id: simManager
    controlType: SimManagerType.Data
}

OfonoNetworkRegistration {
    id: networkRegistration
    modemPath: simManager.activeModem
}

OfonoConnMan {
    id: connectionManager
    modemPath: simManager.activeModem
}

function roamingDataAllowed() {
    return networkRegistration.valid && connectionManager.valid
        && !(networkRegistration.status === "roaming" && !connectionManager.roamingAllowed)
}

enabled: !networkManager.instance.offlineMode && (roamingDataAllowed() || wifiTechnology.tethering)

if (wifiTechnology.tethering) {
    delayedTetheringSwitch.start()
    connectionAgent.stopTethering()
} else {
    delayedTetheringSwitch.start()
    connectionAgent.startTethering("wifi")
}
/
import MeeGo.Connman 0.2

NetworkManagerFactory { id: connMgr }

connMgr.instance.offlineMode = true // 
connMgr.instance.offlineMode = false // 
/ Bluetooth
import MeeGo.Connman 0.2
import Sailfish.Bluetooth 1.0
import org.kde.bluezqt 1.0 as BluezQt

TechnologyModel {
    id: btTechModel;
    name: "bluetooth"
}

btTechModel.powered = !btTechModel.powered // 


D-Bus :
:
com.jolla.calendar.ui
:
/com/jolla/calendar/ui
:
com.jolla.calendar.ui
:
viewEvent(id, recurrenceId, startDate)
:
com.jolla.calendar.ui
:
/com/jolla/calendar/ui
:
com.jolla.calendar.ui
:
viewDate(dateTime)
:
com.jolla.camera
:
/
:
com.jolla.camera.ui
:
showViewfinder()
:
com.jolla.camera
:
/
:
com.jolla.camera.ui
:
showFrontViewfinder()
:
com.jolla.clock
:
/
:
com.jolla.clock
:
newAlarm()
:
com.jolla.contacts.ui
:
/com/jolla/contacts/ui
:
com.jolla.contacts.ui
:
showContact(int contactId)
:
com.jolla.contacts.ui
:
/com/jolla/contacts/ui
:
com.jolla.contacts.ui
:
editContact(int contactId)
:
com.jolla.contacts.ui
:
/com/jolla/contacts/ui
:
com.jolla.contacts.ui
:
importWizard()
URL :
com.jolla.mediaplayer
:
/com/jolla/mediaplayer/ui
:
com.jolla.mediaplayer.ui
:
openUrl(url)
:
com.jolla.notes
:
/
:
com.jolla.notes
:
newNote()
:
com.jolla.settings
:
/com/jolla/settings/ui
:
com.jolla.settings.ui
:
showSettings()
:
com.jolla.settings
:
/com/jolla/settings/ui
:
com.jolla.settings.ui
:
showTransfers()
:
com.jolla.settings
:
/com/jolla/settings/ui
:
com.jolla.settings.ui
:
showAccounts()
:
com.jolla.settings
:
/com/jolla/settings/ui
:
com.jolla.settings.ui
:
showCallRecordings()
/ Android :
com.jolla.apkd
:
/com/jolla/apkd
:
com.jolla.apkd
:
controlService(true/false)
/ :
com.jolla.settings.system.flashlight
:
/com/jolla/settings/system/flashlight
:
com.jolla.settings.system.flashlight
:
toggleFlashlight()
:
com.nokia.dsme
:
/com/nokia/dsme/request
:
com.nokia.dsme.request
:
req_reboot()
:
com.nokia.dsme
:
/com/nokia/dsme/request
:
com.nokia.dsme.request
:
req_shutdown
:
com.jolla.voicecall.ui
:
/
:
com.jolla.voicecall.ui
:
dial(number)
:
com.jolla.gallery
:
/com/jolla/gallery/ui
:
com.jolla.gallery.ui
:
showImages(array_of_urls)
:
com.jolla.gallery
:
/com/jolla/gallery/ui
:
com.jolla.gallery.ui
:
playVideoStream(url)
:
com.jolla.email.ui
:
/com/jolla/email/ui
:
com.jolla.email.ui
:
mailto()
WLAN- :
com.jolla.lipstick.ConnectionSelector
:
/
:
com.jolla.lipstick.ConnectionSelectorIf
:
openConnectionNow('wifi')



Telegram- .
Original source: habrahabr.ru (comments, light).

https://habrahabr.ru/post/337618/

:  

: [1] []
 

:
: 

: ( )

:

  URL