Sailfish OS
  • Info
  • User Experience
  • Cases
  • Community
  • Developers
  • Contact
  • Get Sailfish OS
Select Page
  • Info
  • User Experience
  • Cases
  • Community
  • Developers
  • Contact
  • Get Sailfish OS

Sailfish Share

API Documentation
  • API Documentation
  • Libsailfishapp
  • Sailfish Silica
    • Documentation
    • Icon Reference
  • Sailfish Components
    • Sailfish Accounts
    • Sailfish Bluetooth
    • Sailfish Contacts
    • Sailfish Crypto
    • Sailfish Gallery
    • Sailfish Media
    • Sailfish Pickers
    • Sailfish Secrets
    • Sailfish Share
    • Sailfish Telephony
    • Sailfish Webview
    • Amber Web Authorization
    • Amber MPRIS
  • Nemo QML Plugins
    • Configuration
    • Contacts
    • D-Bus
    • Keepalive
    • Notifications
    • Thumbnailer
  • Sailfish Middleware
    • MDM Framework
    • MDM Policy Framework
    • User Manager Daemon
  • API Documentation
  • Libsailfishapp
  • Sailfish Silica
    • Documentation
    • Icon Reference
  • Sailfish Components
    • Sailfish Accounts
    • Sailfish Bluetooth
    • Sailfish Contacts
    • Sailfish Crypto
    • Sailfish Gallery
    • Sailfish Media
    • Sailfish Pickers
    • Sailfish Secrets
    • Sailfish Share
    • Sailfish Telephony
    • Sailfish Webview
    • Amber Web Authorization
    • Amber MPRIS
  • Nemo QML Plugins
    • Configuration
    • Contacts
    • D-Bus
    • Keepalive
    • Notifications
    • Thumbnailer
  • Sailfish Middleware
    • MDM Framework
    • MDM Policy Framework
    • User Manager Daemon

Contents

  • Properties
  • Signals
  • Detailed Description

ShareProvider QML Type

Import Statement: import Sailfish.Share 1.0
  • List of all members, including inherited members

Properties

  • capabilities : list
  • method : string
  • registerName : bool

Signals

  • triggered(list resources)

Detailed Description

Accepts shared files and signals ShareProvider::triggered when another application shares with this application.

Use this item to implement sharing in your application. You need to define the sharing method in desktop entry file. See the example below.

 [Desktop Entry]
 Type=Application
 Name=My application
 Icon=my-application
 Exec=my-application
 X-Share-Methods=images;

 [X-Sailjail]
 ApplicationName=MyApplication
 OrganizationName=org.example
 Permissions=Internet;UserDirs;RemovableMedia

 [X-Share Method images]
 Description=Send to friends
 Capabilities=image/png;image/jpeg
 SupportsMultipleFiles=yes

The changes you need to make to the application are addition of share methods list and definitions of those share methods.

Depending on the locations of files you expect to receive, you should define appropriate permissions for your application in X-Sailjail section. Files common to all applications are stored on device in directories allowed by UserDirs permission or one of the more specific directory permissions. Similarly files stored on memory card can be accessed with RemovableMedia permission. It is possible that an application tries to share a file private to that application and that may fail as your application may not have access to it.

Each share method must be listed in X-Share-Methods key and have its own section. You may supply a short description of the sharing method to be displayed on sharing dialog. It can be localised with desktop entry style localisation keys, e.g. Description[fi] would define Finnish version of Description which is loaded when device language is set to Finnish. If a suitable translated version can not be found, it defaults to non-localised version.

You need to handle registering D-Bus name on session bus in your application. Do not use DBusInterface for that purpose to avoid race conditions with registering objects on D-Bus. Use C++ to do it race-free instead.

Example:

 int main(int argc, char *argv[])
 {
     QScopedPointer<QGuiApplication> app(SailfishApp::application(argc, argv));
     QScopedPointer<QQuickView> view(SailfishApp::createView());

     // ...

     view->setSource(SailfishApp::pathToMainQml());

     // Registering the service after QML is loaded
     QDBusConnection::sessionBus().registerService("org.example.MyApplication");

     return app->exec();
 }

Place ShareProvider directly under your ApplicationWindow and define the same method name value there. In case of the example above, this would be appropriate:

 ApplicationWindow {
     id: root

     // ...

     ShareProvider {
         method: "images"
         capabilities: ["image/png", "image/jpeg"]

         onTriggered: {
             root.activate() // Show window
             // Pass resources to handling code. A dialog allows to
             // query more information from user before acting on the data.
             var dialog = pageStack.push("SendPicturesDialog.qml", { 'resources': resources })
         }
     }
 }

You may register multiple share methods by defining multiple X-Share Method sections and ShareProvider items. Use a different method name for each section and use the same name in corresponding item on QML code.

To make your application robust, don't trust that the resources contain what you expect. Validating them before use is a good idea.

Property Documentation

capabilities : list

List of mime types that this sharing method accepts.

If you want to enforce checking of reported mime types while sharing, set this to the same value as X-Share Method <method>/Capabilities. E.g. if Capabilities is "image/png;image/jpeg" set this to ["image/png", "image/jpeg"].

If this is left empty, set to undefined, or one of the types is "*", no checking of mime types takes place.

Note that you should not trust that the resource content matches to the reported mime type. This only checks that the reported mime type matches the capabilities set here.

See also ShareAction::mimeType.


method : string

Sharing method name as defined in desktop entry file.

Set this to the same value as listed in X-Share-Methods list and in X-Share Method section name in the desktop entry file of the application.


registerName : bool

Set to true to automatically register D-Bus bus name on session bus.

This works only for simple use cases, i.e. when you have only one ShareProvider in the application and it doesn't provide D-Bus service for anything else. Otherwise register your bus name in C++ after the ShareProvider items have been completed.


Signal Documentation

triggered(list resources)

Signaled when this share method is used.

The signal handler is onTriggered. The argument is a list of resources that were shared to the application. See ShareResource for more information about resources.


  • Legal
  • Contact Us
  • Jollyboys Ltd © 2024

  • Facebook
  • Twitter
  • Mastodon
  • YouTube
  • LinkedIn