/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Free Documentation License
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of this
** file.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
** $QT_END_LICENSE$
**
****************************************************************************/

/*!
\example declarative-sfw-dialer

\title Service Framework using QML Example

\bold {Execution}

This example requires the example dialer services to be pre-registered in order
for the application to discover and load the services. This can be done by using the
service framework command line tool to add the corresponding service XML file:

\list
    \o ./servicefw add voipdialerservice.xml
    \o ./servicefw add landlinedialerservice.xml
    \o ./servicefw add remotedialerservice.xml
    \o ./servicefw dbusservice removedialerservice.xml dialer_service
\endlist

These deployment commands will register the two plugin-based services as well as the remote
IPC-based service. The last line features the ability to create an autostarting file for
D-Bus if the platform supports the QtDBus module, typically available on Linux systems.

There are 2 ways to run the example:
\list
    \o ./qmldialer (only method for Symbian)
    \o qmldialer declarative-sfw-dialer.qml
\endlist

The XML files for all example services can be found in the QtMobility build directory
under install/bin/xmldata.

For Maemo and Linux platforms using D-Bus as the underlying IPC mechanism, the
autostart feature can be initialised by running the service framework tool:
\code
    servicefw dbusservice xmldata/remotedialerservice.xml dialer_service
\endcode

\bold {Explanation}

This example should demonstrate how to use the Service Framework to
access a list of services in a QML context. A library plugin provides QML with elements
that can reference a single service or a list of services, called 'Service' and
'ServiceList' respectively.

An example that demonstrates how to connect to a single service object to
implement a simple note taking application can be found \l{declarative-sfw-notes}{here}.

\target guidesign

The GUI looks like following picture:

\image DialerServiceGUI.png "GUI"

The following steps outline how to make a QML based application using the Service Framework technology.
It is assumed that QtMobility has been successfully built and environment variables have been set
as per \l {Installation Guide}.

\bold {Service Framework in QML:}

To included the Service Framework QML plugin to our QML file we need to import it as follows:

\snippet declarative-sfw-dialer/declarative-sfw-dialer/content-sfw-dialer/DialerList.qml 4


\bold {The Services:}

The services are implemented in a shared library and can be register in the service framework.
After the service is registered it can be used in different applications.
In our case we'll access the services over an application that is based on QML scripting.
We will be able to change between different services and call their properties,
receiving their signals and so forth.

In this example we've implemented 2 services called
Landdialer and Voipdialer.
You can find the projects for those services in:

declarative-sfw-dialer\\landlinedialer and declarative-sfw-dialer\\voipdialer.
Those projects will create a shared library in each case.

If the library needs to be available over the Service Framework,
we need to register the library.
In our example this will be done manually by using the servicefw tool. Refer to the project
README for further details.

As you can see we register the services using a xml file.
This xml file basically contains all information to register the shared library in the
Service Framework environment.
For more information please read more about the Qt Service Framework
\l {service-frameworks.html#adding-and-removing-of-services}{XML Format}

The QServiceManager creates an instance of a services over a QServicePluginInterface.
For each services we provide a Plugin.

\snippet declarative-sfw-dialer/voipdialer/voipdialerplugin.h 0

The Q_INTERFACES macro tells Qt which interfaces the class implements.

Both seviceplugins needs to implement the QServicePluginInterface.
In our case we only need to overwrite the virtual function createInstance.
\snippet declarative-sfw-dialer/voipdialer/voipdialerplugin.cpp 0

As you can see the createInstance function create the appropriate dialer object
and returns it.
The Q_EXPORT_PLUGIN2 macro provides the necessary implementation for a plugin.
See \l{How to Create Qt Plugins} for more details.

The last thing we need to provide in our services are
the states, properties, signals and slots that we
want to access in out QML script later.

\target voipdialer_h_0
\snippet declarative-sfw-dialer/voipdialer/voipdialer.h 0


\bold {Service access on the QML site}

The QML elements are implemented in 4 different qml scripting files
\l {guidesign}{ see GUI design}.

The first step is to use our ServiceWrapperList to specify the interface and minimum version (optional) through QML item
context, which will produce a list of ServiceWrapper objects.

\snippet declarative-sfw-dialer/declarative-sfw-dialer/content-sfw-dialer/DialerList.qml 5

In the DialerList.qml file the services property is assigned to the ListView model property.

\snippet declarative-sfw-dialer/declarative-sfw-dialer/content-sfw-dialer/DialerList.qml 0

To show the items of the model property we need to create a delegate component and assign it to the ListView
Delegate property:

\snippet declarative-sfw-dialer/declarative-sfw-dialer/content-sfw-dialer/DialerList.qml 1

In this component you can define how you want to draw one ListView item.
You can access inside of this component the current ListWiew item by using the variable modelData.
In our example we are using two text lines. Furthermore we can define whats happening if we click
on a ListView item by using the MouseRegion.

\target DialerList_qml_2
\snippet declarative-sfw-dialer/declarative-sfw-dialer/content-sfw-dialer/DialerList.qml 2

Another component can be created for highliting a list item:

\snippet declarative-sfw-dialer/declarative-sfw-dialer/content-sfw-dialer/DialerList.qml 3

\bold {Service signals and function calls on the QML site}

In sfw-kinetic-example.qml we define a control named DialScreen and implement
the function onDial and onHangup.
As you can see in the onDial event we call the service function dialNumber and
the onHangup calls hangup.
Both function are implemented in the service \l {voipdialer_h_0} { (see voipdialer header file).}

\snippet declarative-sfw-dialer/declarative-sfw-dialer/declarative-sfw-dialer.qml 0

In DialScreen.qml the dial and the hangup signals are defined.
The hangup signal will be emitted if the HangUpButton was clicked:

\snippet declarative-sfw-dialer/declarative-sfw-dialer/content-sfw-dialer/DialScreen.qml 1

The dial signal will be emitted if the CallButton was clicked:

\snippet declarative-sfw-dialer/declarative-sfw-dialer/content-sfw-dialer/DialScreen.qml 2

Now we need to connect the stateChanged signal form the services with an event handler on the QML site.
This is done in our main declarative file:

\snippet declarative-sfw-dialer/declarative-sfw-dialer/declarative-sfw-dialer.qml 1

The DialScreen.currentDialer is assigned during a ListView item click in the
\l {DialerList_qml_2}{ ServiceList.qml file}.

*/
