Navigation

Views

With the Sharing dialog API, the user can open the first dialog, which starts the Sharing flow. From the first dialog the user can select "Send via Bluetooth", "Send via E-mail" and "Share via service".

In the example above we use the API to start sharing single file. In case you want to share simultaneously more than one file or you want
to change what button are seen in the dialog use one of the functions below.

Send Via E-mail and Bluetooth can be used directly without Sharing dialog and the functionality is provided by the platform to enable applications to send data via E-mail or over a Bluetooth connection. Because several applications share this functionality, the platform provides a public interface to facilitate the deployment of these services in user applications. The interfaces are defined in two header files: libmodest-dbus-client.h (in the libmodest-dbus-client-dev package) and conbtdialogs-dbus.h (in the conbtdialogs-dev package). The following sample code is an example of the usage of these interfaces. See the maemopad source code available in the SDK repository for a fully functional application using this service.

Maemo 5 introduces a new library for handling Sharing related information and services. This chapter will walk you through the process of creating a sharing plug-in using a template plug-in as example. Basic knowledge of Debian development and working in a Scratchbox environment is needed in order to follow these guides.

Before starting to create your own plugin it is a good idea to check the default services: OVI and Flickr. From those you can see two different UI flows for creating accounts. In OVI the UI flow is pretty simple and clear, you just type a user name and password and then validate the account. In Flickr the flow is more complex, as before validation the user must login to Flickr via a web page to get authentication and continue the validation after that.

Sharing application abstracts the file sharing and implements common parts needed for file sharing application. Sharing Application service support can be extended by using Sharing Plug-ins. These plug-ins can be created by any 3rd party developer. The plug-ins should implement the Sharing Plug-in API functions and define some parameters in a service definition XML file.

Figure 1 below shows Sharing accounts dialog opened from the control panel. With the Sharing accounts, you can create a new Sharing account or edit an existing one. If you install a custom Sharing plug-in, you can see the service it provides in the "Select service list" when creating a new Sharing account.

Figure 1: Sharing Accounts

Figure 2 shows the Sharing Dialog user interface that is used to share images with the selected account on some service. The images displayed can come for example from the Photos application or from the device camera. You can choose the account created for your service from the "Account" combo box which holds all existing Sharing accounts.

Many web services provide APIs that are available for 3rd party developers. In this tutorial, we focus on services that provide APIs for image and video uploads. It is possible to give a title, description and tags for the images using the common service API. Sharing supports image scaling and metadata filtering as common options for any service. Sharing Plug-ins can have service-specific options, like privacy. These settings can be accessed through the Options dialog (in Figure 2.)

Figure 3 shows the general overview of how Sharing Plug-in connects to Sharing Application using the Sharing Plugin API. The basic plug-in components are the service definition file and the plugin library. The Application Sharing-Dialog is used to create SharingEntries that are shared by a SharingManager. Sharing Account Manager implements the Sharing Accounts. Libsharing is a library for all common Sharing functionality.

Figure 3: Sharing Plugin API

Figure 4 shows the common Sharing classes found in libsharing that you would use while creating the plug-in:

SharingTransfer is the object that contains all the data of a sharing task, overall status of the transfer process for one set of shared files.

SharingEntry contains the SharingEntryMedia that are the selected files. It also knows the SharingAccount that is the target of sharing.

SharingAccount contains the username and password along with other parameters that you have to save for your service's accounts. It also has the information about SharingService which is registered with the SharingAccount.

The service definition file, data/template.service.xml.in is the starting point for plugin loading. It defines the library that implements Sharing Plugin API functions, the sign up URL for totally new account creation using a web browser, the service name, icon file names and some basic information from plug-in.

Options element defines all the options that a user can change through "Options" for the selected service. Each individual option is an element option.

Property id defines the internal id for this option. User selected choice for this option is asked with the id, see here.

Property type defines the type of option. You can select enumeration or updatable. For the enumeration you need to specify the shown values with values elements. Updatable option can contain default values and the remaining values can be updated from service.

Property default defines the default value to select if user haven't made any selections yet. The value of the default property must mach one of the value element ids.

Properties domain and key under caption element defines the actual text to be displayed. If you want to use some localization package then define domain and desired logical id to key. For free text the domain is not mandatory.

Element value defines one value in the selection. If option is updatable new values with id/key pair can be added in code, see here. Otherwise you need to specify the shown values.

Sharing accounts can either create a default flow where username and password parameters are set to the account or an optional custom flow. In File 1, the accounts tag has a parameter plugInSetup. If it is set to "1", Sharing Accounts will call the Sharing Plugin API function sharing_plugin_interface_account_setup to create UI flow; it will use the default flow. You can see the difference between UI flows when creating Flickr and Ovi account. Ovi uses the default flow and Flickr uses it's own UI flow.

Account validation is needed to reduce error cases in the sending process. Of course you can use the dummy function at template plug-in, but for better user experience this function is recommended to be implemented so that Sharing Account account information is really validated against the service when new account is created.

Next function is called after sharing_plugin_interface_account_setup call ends or when default account setup flow is done (when the "Validate" button is pressed).

In the last phase of account creation, the account must be validated. Sharing Plug-in API sharing_plugin_interface_test_account is the function called in the validation phase of the account creation flow. Usually web services have a phase in account creation where you have put the needed information from your account, only then you get the actual credentials to upload images if your account information is valid. This is the phase that is implemented in the Sharing Plug-in API function.

Sharing Accounts support here too either default flow where username and password parameters are edited or optional custom edit UI flow. The desired flow can be set by setting the parameter plugInEdit from the service definition file either to "0" or to "1" where "0" means the default flow and "1" plug-in flow.

The default flow can be used when you need only username and password to get needed information for sending. The plug-in flow is used when you need more than this or customised account validation flow. You can see the difference between UI flows here too when editing Flickr and Ovi accounts.

Next function must be implemented only when plug-in account setup is used (when plugInSetup is set to "1"):

After pressing the 'Share' button in Sharing dialog (Figure 2.), the data is put into the Sharing Outbox (can be seen under /home/user/MyDocs/.sharing/outbox/). Sharing manager process is started and the status menu gets the icon to process the new Sharing Entry. SharingHTTP provides an API to create common HTTP requests. In order to create a better user experience following things are good to be implemented after you get the basic functionality working in your plug-in:

Set progress of sending with sharing_transfer_set_progress between 0 and 1 to estimate the current transfer time / total transfer time.

Set sent to SharingEntryMedia with sharing_entry_media_set_sent when file sending is done and check the send value with sharing_entry_media_get_sent to prevent sending same files multiple times for example in reboot scenarios.

Poll cancel flag time to time, for example in curl or SharingHTTP progress function to end transferring when needed. Use sharing_transfer_continue to get the continue flag bit.

If you are using libcurl instead of SharingHTTP, please listen to conic events to disconnect transfer when no connection available. It returns with 'no connection' return value in this case.

Next some example source for common tasks found in usual sending functionality:

When you process SharingEntryMedias from the SharingEntry you propably end up with loop where you go the list of SharingEntryMedias through. Here is a raw example, where some example lines commented out with "//".

Usually services accept the tags in their API to be added to images. Here is example source to create nice string about tag information to be put where ", " string used as separator. If service supports also geo tagging you should develop this source further by checking the tag type also.

sharing_plugin_interface_update_options is used to update account specific
options in Sharing Dialog's Options menu. This is pretty handy when you want to have
changing options in your plug-in for example albums.

You are defining these options in your plug-in's service definion .xml file. For
example next lines can add updatable option "album" to the plug-in's accounts:

When update options is pressed sharing_plugin_interface_update_options is called. After you have got the newest options from service's server you can add them to currently selected account by creating a GSList* of SharingServiceOptionValues. After having a nice list of new options you can then set them to account with sharing_account_set_option_values (self->account, "album", option_values).

When setting the options to account is done you have to call the function that was given to you as parameter passing the SharingPluginInterfaceUpdateOptionsResult with value of your choise and the already before got cb_data as parameter. This tells to the caller that your part from the update flow is succesfully done. Next source can be used to create this function call (self->result is containing the result in you opinion):

Libsharing provides the sharing-account-remover binary that can be used to clean Sharing Accounts created for your plugin. This binary is run by debian/ dir's prerm script. Prerm scripts are run just before the package is uninstalled. Change the plugin id from sharingplugintemplate to match your plug-in id in the script. Your plug-in's id is the service definitions files prefix. For template.service.xml, the prefix is "template".

Example prerm script:

#!/bin/sh# You can use sharing-account-remover to remove the accounts at plugin# uninstallationif["$1" = "remove"]; then/usr/bin/sharing-account-remover <service name>fi

All the needed packages should be installed along with nokia-binaries.

Important: When testing inside scratchbox remember to start the signond daemon after the desktop is started. Signond is used for storing the account information and it's needed in order to get Sharing framework working properly

[sbox] > signond &

Also remember to install the debian .deb package build from your sources.

Creating sharing account is started from setting.

settings -> Sharing accounts -> New

Select your service and create new account. After one account is created you can use ImageViewer for sharing images and MediaPlayer for sharing video files.