Please mark bug as Resolved/Fixed, otherwise we never get chance to set it 
Released and thus QA never would verify it

Peter



> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On Behalf Of Kevron Rees
> Sent: Wednesday, June 08, 2011 2:03 PM
> To: [email protected]
> Cc: Kevron Rees
> Subject: [meego-commits] 20285: Changes to
> MeeGo:1.2:oss:Testing/contextkit-meego
>
> Hi,
> I have made the following changes to contextkit-meego in project
> MeeGo:1.2:oss:Testing. Please review and accept ASAP.
>
> Thank You,
> Kevron Rees
>
> [This message was auto-generated]
>
> ---
>
> Request #20285:
>
>   submit:   devel:meego-ux/contextkit-meego(r35)(update) ->
> MeeGo:1.2:oss:Testing/contextkit-meego
>
>
> Message:
>     fixed bugs. see changes.
>
> State:   new          2011-06-08T14:02:52 kevronx_m_rees
> Comment: None
>
>
>
> changes files:
> --------------
> --- contextkit-meego.changes
> +++ contextkit-meego.changes
> @@ -0,0 +1,3 @@
> +* Wed Jun 08 2011 Kevron Rees <[email protected]> - 0.0.16
> +- BMC #10636 - Battery.ChargeBars added to contextkit plugin
> +
>
> old:
> ----
>   contextkit-meego-0.0.15.tar.bz2
>
> new:
> ----
>   contextkit-meego-0.0.16.tar.bz2
>
> spec files:
> -----------
> --- contextkit-meego.spec
> +++ contextkit-meego.spec
> @@ -7,7 +7,7 @@
>
>  Name:       contextkit-meego
>  Summary:    Contextkit providers for various functions
> -Version:    0.0.15
> +Version:    0.0.16
>  Release:    1
>  Group:      System/GUI/Other
>  License:    Apache License, Version 2.0
> @@ -19,6 +19,7 @@
>  BuildRequires:  pkgconfig(connman)
>  BuildRequires:  pkgconfig(bluetooth-qt)
>  BuildRequires:  pkgconfig(contextsubscriber-1.0) >= 0.5.25
> +BuildRequires:  pkgconfig(mlite)
>  BuildRequires:  connman-qt-devel
>  Provides:   contextkit-meego-providers
>
>
> other changes:
> --------------
>
> ++++++ contextkit-meego-0.0.15.tar.bz2 -> contextkit-meego-0.0.16.tar.bz2
> --- .gitignore
> +++ .gitignore
> +*.o
> +*.so
> +moc_*
> +*~
> +Makefile
> +*-test
> +*_interface.*
> --- battery/battery.pro
> +++ battery/battery.pro
> @@ -1,2 +1,2 @@
>  TEMPLATE=subdirs
> -SUBDIRS += src tests
> +SUBDIRS += src tests
> \ No newline at end of file
> --- battery/src/battery.context
> +++ battery/src/battery.context
> @@ -6,4 +6,5 @@
>    <key name="Battery.IsCharging"></key>
>    <key name="Battery.TimeUntilLow"></key>
>    <key name="Battery.TimeUntilFull"></key>
> +  <key name="Battery.ChargeBars"></key>
>  </provider>
> --- battery/src/devicekitprovider.cpp
> +++ battery/src/devicekitprovider.cpp
> @@ -14,6 +14,7 @@
>
>  #include <QDBusConnection>
>  #include <QDBusServiceWatcher>
> +#include <MGConfItem>
>
>  #define OnBattery "Battery.OnBattery"
>  #define ChargePercentage "Battery.ChargePercentage"
> @@ -21,6 +22,7 @@
>  #define TimeUntilLow "Battery.TimeUntilLow"
>  #define TimeUntilFull "Battery.TimeUntilFull"
>  #define IsCharging "Battery.IsCharging"
> +#define ChargeBars "Battery.ChargeBars"
>
>
>  //typedef OrgFreedesktopDeviceKitPowerInterface Power;
> @@ -134,12 +136,32 @@
>       if(!batteryDevice) return;
>
>       Properties[OnBattery] = batteryDevice->state() == 2 ||
> batteryDevice->state() == 3;
> -     Properties[ChargePercentage] = batteryDevice->percentage();
> +        Properties[ChargePercentage] = (int) batteryDevice->percentage();
>       Properties[LowBattery] = batteryDevice->percentage() < 10;
>       Properties[TimeUntilLow] = batteryDevice->timeToEmpty();
>       Properties[TimeUntilFull] = batteryDevice->timeToFull();
>       Properties[IsCharging] = batteryDevice->state() == 1 ||
> batteryDevice->state() == 4;
>
> +        MGConfItem *numChargeBars = new
> MGConfItem("/gconf/meego/apps/contextkit/battery/chargebars");
> +        qDebug() << "DeviceKitPowerProvider" << "ChargeBars value is" <<
> numChargeBars->value().toInt();
> +
> +        if(numChargeBars->value().toInt() < 0){
> +            qDebug() << "DeviceKitPowerProvider" << "invalid
> /gconf/meego/apps/contextkit/battery/chargebars key";
> +            numChargeBars->set(10); //set default to 10
> +        }
> +
> +        QList<QVariant> bars;
> +        int maxBars = numChargeBars->value().toInt();
> +
> +        if(batteryDevice->percentage() > 100 ||
> batteryDevice->percentage() < 0) //If percentage is corrupted
> +            bars.append(50/maxBars);
> +        else
> +            bars.append((int)batteryDevice->percentage()/maxBars);
> +
> +        bars.append(maxBars);
> +
> +        Properties[ChargeBars] = QVariant(bars);
> +
>       foreach(QString key, subscribedProps)
>       {
>               emit valueChanged(key, Properties[key]);
> --- battery/src/src.pro
> +++ battery/src/src.pro
> @@ -5,11 +5,16 @@
>
>  TEMPLATE = lib
>  CONFIG += debug \
> -    link_pkgconfig \
> -    plugin
> +link_pkgconfig \
> +plugin \
> +gconf-2.0 \
> +mlite \
> +dbus
>  QT += dbus
> -PKGCONFIG += contextprovider-1.0 contextsubscriber-1.0
> -
> +PKGCONFIG += gconf-2.0 \
> +contextprovider-1.0 \
> +contextsubscriber-1.0 \
> +mlite
>  TARGET = battery
>  SOURCES += devicekitprovider.cpp device_interface.cpp power_interface.cpp
>  HEADERS += devicekitprovider.h device_interface.h power_interface.h
> --- contextkit-meego-providers.pro
> +++ contextkit-meego-providers.pro
> @@ -1,4 +1,4 @@
> -VERSION=0.0.15
> +VERSION=0.0.16
>
>  TEMPLATE = subdirs
>
> @@ -6,7 +6,8 @@
>      cellular \
>      phone \
>      internet \
> -    bluetooth
> -#    location
> +    bluetooth \
> +    media \
> +    location
>
>  OTHER_FILES +=
> --- location/location.context
> +++ location/location.context
> @@ -1,4 +1,6 @@
>  <?xml version="1.0"?>
>  <provider xmlns="http://contextkit.freedesktop.org/Provider";
> plugin="/liblocation" constructionString="location">
>    <key name="Location.SatPositioningState"></key>
> +  <key name="Location.Coordinates"></key>
> +  <key name="Location.Heading"></key>
>  </provider>
> --- location/location.cpp
> +++ location/location.cpp
> @@ -14,13 +14,15 @@
>
>  #include <QDBusConnection>
>  #include <QDBusObjectPath>
> -#include <QXmlQuery>
> -#include <QDomDocument>
> +#include <QDBusPendingCallWatcher>
> +#include <MGConfItem>
>
> -#define SatPositioningState "Location.SatPositioningState"
> -///on, searching, off
> +const QString LocationProvider::gypsyService("org.freedesktop.Gypsy");
> +const QString
> LocationProvider::satPositioningState("Location.SatPositioningState"); ///on,
> searching, off
> +
> +const QString LocationProvider::coordinates("Location.Coordinates");
> +const QString LocationProvider::heading("Location.Heading");
>
> -//typedef OrgFreedesktopDeviceKitPowerInterface Power;
>
>  IProviderPlugin* pluginFactory(const QString& constructionString)
>  {
> @@ -28,37 +30,14 @@
>       return new LocationProvider();
>  }
>
> -LocationProvider::LocationProvider():gpsDevice(NULL)
> +LocationProvider::LocationProvider() :
> +  gpsDevice(NULL), position(NULL), course(NULL)
>  {
>       qDebug() << "LocationProvider " << "Initializing LocationProvider
> provider";
>
> -     QDBusInterface
> interface("org.freedesktop.Gypsy","/org/freedesktop/Gypsy",
> -                              "org.freedesktop.DBus.Introspectable",
> QDBusConnection::systemBus(), this);
> -
> -     QDBusReply<QString> reply = interface.call("Introspect");
> -
> -     QString xml = reply.value();
> -
> -     QString devicePath = parseOutNode(xml);
> -
> -     qDebug()<<"device path: "<<devicePath;
> -
> -     if(!devicePath.isEmpty())
> -     {
> -              gpsDevice = new
> OrgFreedesktopGypsyDeviceInterface("org.freedesktop.Gypsy", devicePath,
> -                                                        
> QDBusConnection::systemBus(), this);
> -
> -
> connect(gpsDevice,SIGNAL(ConnectionStatusChanged(bool)),this,SLOT(connect
> ionStatusChanged(bool)));
> -              connect(gpsDevice,SIGNAL(FixStatusChanged(int)),this,
> SLOT(fixStatusChanged(int)));
> -     }
>       QMetaObject::invokeMethod(this, "ready", Qt::QueuedConnection);
>  }
>
> -LocationProvider::~LocationProvider()
> -{
> -
> -}
> -
>  void LocationProvider::subscribe(QSet<QString> keys)
>  {
>       qDebug() << "LocationProvider " << "subscribed to LocationProvider
> provider";
> @@ -67,6 +46,13 @@
>
>       subscribedProps.unite(keys);
>
> +     if (subscribedProps.contains(coordinates)) {
> +       getCoordinates();
> +     }
> +     if (subscribedProps.contains(heading)) {
> +       getHeading();
> +     }
> +
>       QMetaObject::invokeMethod(this, "emitSubscribeFinished",
> Qt::QueuedConnection);
>  }
>
> @@ -81,18 +67,55 @@
>       qDebug("first subscriber appeared!");
>       qDebug() << "LocationProvider " << "First subscriber appeared, 
> connecting
> to Gypsy";
>
> +     MGConfItem *gypsyPath = new
> MGConfItem("/apps/geoclue/master/org.freedesktop.Geoclue.GPSDevice",
> this);
> +     if (!gypsyPath || gypsyPath->value() == QVariant::Invalid) {
> +       QString errorString("Gypsy path is invalid or missing from gconf!");
> +       qDebug()  << "LocationProvider " << errorString;
> +       QMetaObject::invokeMethod(this, "failed", Qt::QueuedConnection,
> +                                 Q_ARG(QString, errorString));
> +       return;
> +     }
> +     qDebug() << "using" << gypsyPath->value().toString() << "as gypsy path";
> +
> +     QDBusInterface *interface = new QDBusInterface(gypsyService,
> "/org/freedesktop/Gypsy",
> +                                                    
> "org.freedesktop.Gypsy.Server",
> QDBusConnection::systemBus(), this);
> +     QDBusReply<QDBusObjectPath> reply = interface->call("Create",
> gypsyPath->value().toString());
> +       if (!reply.isValid()) {
> +         QDBusError error = reply.error();
> +         QString errorString(error.errorString(error.type()) + ": " +
> error.message());
> +         qDebug() << "creating gypsy device resulted in error:" << 
> errorString;
> +         QMetaObject::invokeMethod(this, "failed", Qt::QueuedConnection,
> +                                   Q_ARG(QString, errorString));
> +         return;
> +       }
> +     QString devicePath = reply.value().path();
> +     qDebug()<<"device path: "<<devicePath;
> +
> +     gpsDevice = new OrgFreedesktopGypsyDeviceInterface(gypsyService,
> devicePath,
> +                                                        
> QDBusConnection::systemBus(), this);
> +     position = new OrgFreedesktopGypsyPositionInterface(gypsyService,
> devicePath, QDBusConnection::systemBus(), this);
> +
> +
>       connect(gpsDevice,SIGNAL(ConnectionStatusChanged(bool)),this,SLOT(co
> nnectionStatusChanged(bool)));
> +     connect(gpsDevice,SIGNAL(FixStatusChanged(int)),this,
> SLOT(fixStatusChanged(int)));
> +
> +     connect(position,SIGNAL(PositionChanged(int,int,double,double,double)),
> this, SLOT(positionChanged(int,int,double,double,double)));
> +
> +     course = new OrgFreedesktopGypsyCourseInterface(gypsyService,
> devicePath, QDBusConnection::systemBus(), this);
> +     connect(course, SIGNAL(CourseChanged(int,int,double,double,double)),
> +             this, SLOT(courseChanged(int,int,double,double,double)));
> +
>       QMetaObject::invokeMethod(this, "updateProperties",
> Qt::QueuedConnection);
>  }
>
>  void LocationProvider::onLastSubscriberDisappeared()
>  {
>       qDebug() << "LocationProvider" << "Last subscriber gone, destroying
> LocationProvider connections";
> -
> +     //TODO: disconnect from gpysy at this point
>  }
>
>  void LocationProvider::updateProperties()
>  {
> -     ///TODO: update properties
> +     ///TODO: update all properties
>
>       if(!gpsDevice || !gpsDevice->isValid())
>       {
> @@ -105,9 +128,9 @@
>       qDebug()<<" connected? "<<isConnected<<" fix status: "<<fixStatus;
>
>       if(!isConnected)
> -             Properties[SatPositioningState] = "off";
> +             Properties[satPositioningState] = "off";
>       else
> -             Properties[SatPositioningState] = fixStatus == 1 ? 
> "searching":"on";
> +             Properties[satPositioningState] = fixStatus == 1 ? 
> "searching":"on";
>
>       foreach(QString key, subscribedProps)
>       {
> @@ -123,30 +146,41 @@
>       }
>  }
>
> -QString LocationProvider::parseOutNode(QString xml)
> +void LocationProvider::getCoordinates()
>  {
> -     QXmlQuery query;
> -     query.setFocus(xml);
> -     query.setQuery("/node/node");
> -
> -     if(!query.isValid())
> -             return 0;
> -
> -     query.evaluateTo(&xml);
> -
> -     if(xml.isEmpty() || xml.isNull())
> -             return "";
> -
> -     QDomDocument doc;
> -     doc.setContent(xml);
> -
> -     QDomNodeList nodes = doc.elementsByTagName("node");
> -
> -     if(!nodes.size()) return "";
> -
> -     QDomNode node = nodes.at(0);
> -
> -     return "/org/freedesktop/Gypsy/"+node.toElement().attribute("name");
> +  if (!position->isValid()) {
> +    qDebug() << "position interface is invalid!";
> +    return;
> +  }
> +  QDBusPendingReply<int, int, double, double, double> reply =
> position->GetPosition();
> +  QDBusPendingCallWatcher *watcher = new
> QDBusPendingCallWatcher(reply, this);
> +  connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
> +       this, SLOT(getPositionFinished(QDBusPendingCallWatcher*)));
> +}
> +
> +void LocationProvider::getHeading()
> +{
> +  if (!course->isValid()) {
> +    qDebug() << "course interface is invalid!";
> +    return;
> +  }
> +  QDBusPendingReply<int, int, double, double, double> reply =
> course->GetCourse();
> +  QDBusPendingCallWatcher *watcher = new
> QDBusPendingCallWatcher(reply, this);
> +  connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
> +       this, SLOT(getCourseFinished(QDBusPendingCallWatcher*)));
> +}
> +
> +void LocationProvider::updateProperty(const QString& key, const QVariant&
> value)
> +{
> +    bool changed = true;
> +    if (Properties[key] == value) {
> +      changed = false;
> +    }
> +
> +    Properties[key] = value;
> +    if (subscribedProps.contains(key) && changed) {
> +      emit valueChanged(key, value);
> +    }
>  }
>
>  void LocationProvider::fixStatusChanged(int)
> @@ -154,7 +188,67 @@
>       updateProperties();
>  }
>
> +void LocationProvider::positionChanged(int fields, int timestamp, double
> latitude, double longitude, double altitude)
> +{
> +    //FIXME: use fields correctly
> +    qDebug() << "LocationProvider:" << "New coordinate values:";
> +    qDebug() << "\tfields:" << fields << endl
> +             << "\ttimestamp:" << timestamp << endl
> +             << "\tlatitude:" << latitude << endl
> +             << "\tlongitude:" << longitude << endl
> +             << "\taltitude:" << altitude;
> +
> +    QList<QVariant> coords;
> +    coords.append(QVariant(latitude));
> +    coords.append(QVariant(longitude));
> +    coords.append(QVariant(altitude));
> +    updateProperty("Location.Coordinates", coords);
> +}
> +
> +void LocationProvider::courseChanged(int fields, int timestamp, double speed,
> double direction, double climb)
> +{
> +    //FIXME: use fields correctly
> +    qDebug() << "LocationProvider:" << "New course values:";
> +    qDebug() << "\tfields:" << fields << endl
> +          << "\ttimestamp:" << timestamp << endl
> +          << "\tspeed:" << speed << endl
> +          << "\tdirection:" << direction << endl
> +          << "\tclimb:" << climb << endl;
> +    updateProperty(heading, direction);
> +}
> +
> +
>  void LocationProvider::connectionStatusChanged(bool)
>  {
>       updateProperties();
>  }
> +
> +void LocationProvider::getPositionFinished(QDBusPendingCallWatcher
> *watcher)
> +{
> +  QDBusPendingReply<int, int, double, double, double> reply = *watcher;
> +  if (reply.isError()) {
> +    qDebug() << "GetPosition resulted in error!";
> +  } else {
> +    positionChanged(reply.argumentAt<0>(),
> +                 reply.argumentAt<1>(),
> +                 reply.argumentAt<2>(),
> +                 reply.argumentAt<3>(),
> +                 reply.argumentAt<4>());
> +  }
> +  watcher->deleteLater();
> +}
> +
> +void LocationProvider::getCourseFinished(QDBusPendingCallWatcher*
> watcher)
> +{
> +  QDBusPendingReply<int, int, double, double, double> reply = *watcher;
> +  if (reply.isError()) {
> +    qDebug() << "GetCourse resulted in error!";
> +  } else {
> +    courseChanged(reply.argumentAt<0>(),
> +               reply.argumentAt<1>(),
> +               reply.argumentAt<2>(),
> +               reply.argumentAt<3>(),
> +               reply.argumentAt<4>());
> +  }
> +  watcher->deleteLater();
> +}
> --- location/location.h
> +++ location/location.h
> @@ -19,6 +19,8 @@
>  #include <contextproperty.h>
>  #include "gypsy_interface.h"
>
> +class QDBusPendingCallWatcher;
> +
>  using ContextSubscriber::IProviderPlugin;
>
>  extern "C"
> @@ -40,11 +42,20 @@
>      virtual void blockUntilSubscribed(const QString&) {}
>
>  private:
> +    static const QString gypsyService;
> +    static const QString satPositioningState;
> +    static const QString coordinates;
> +    static const QString heading;
> +
>      QHash<QString,QVariant> Properties;
>      QSet<QString> subscribedProps;
>      OrgFreedesktopGypsyDeviceInterface *gpsDevice;
> +    OrgFreedesktopGypsyPositionInterface *position;
> +    OrgFreedesktopGypsyCourseInterface *course;
>
> -    QString parseOutNode(QString xml);
> +    void updateProperty(const QString& key, const QVariant& value);
> +    void getCoordinates();
> +    void getHeading();
>
>  private slots:
>      void updateProperties();
> @@ -53,7 +64,11 @@
>      void onLastSubscriberDisappeared();
>
>      void fixStatusChanged(int);
> +    void positionChanged(int fields, int timestamp, double latitude, double
> longitude, double altitude);
> +  void courseChanged(int fields, int timestamp, double speed, double
> direction, double climb);
>      void connectionStatusChanged(bool);
> +    void getPositionFinished(QDBusPendingCallWatcher* watcher);
> +    void getCourseFinished(QDBusPendingCallWatcher* watcher);
>  };
>
>
> --- location/location.pro
> +++ location/location.pro
> @@ -6,7 +6,8 @@
>      plugin
>  QT += dbus xmlpatterns
>  PKGCONFIG += contextprovider-1.0 \
> -    contextsubscriber-1.0
> +    contextsubscriber-1.0 \
> +    mlite
>  TARGET = location
>  SOURCES += location.cpp \
>      gypsy_interface.cpp
> --- media
> +++ media
> +(directory)
> --- media/com.meego.app.Music.xml
> +++ media/com.meego.app.Music.xml
> +<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection
> 1.0//EN"
> +
> "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd";>
> +<node>
> +  <interface name="com.meego.app.music">
> +    <property name="state" type="s" access="readwrite"/>
> +    <property name="nowNextTracks" type="as" access="readwrite"/>
> +    <signal name="error">
> +      <arg name="errorCode" type="i" direction="out"/>
> +    </signal>
> +    <signal name="playerClosed">
> +    </signal>
> +    <signal name="playerLaunched">
> +    </signal>
> +    <signal name="positionChanged">
> +      <arg name="position" type="i" direction="out"/>
> +    </signal>
> +    <signal name="trackChanged">
> +      <arg name="track" type="i" direction="out"/>
> +    </signal>
> +    <signal name="stateChanged">
> +    </signal>
> +    <signal name="nowNextTracksChanged">
> +    </signal>
> +    <signal name="currentTrackMetadataChanged">
> +      <arg name="data" type="as" direction="out"/>
> +    </signal>
> +    <method name="close">
> +    </method>
> +    <method name="fastForward">
> +    </method>
> +    <method name="getCurrentTrack">
> +      <arg type="i" direction="out"/>
> +    </method>
> +    <method name="getNumberOfTracks">
> +      <arg type="i" direction="out"/>
> +    </method>
> +    <method name="getPlaybackMode">
> +      <arg type="i" direction="out"/>
> +    </method>
> +    <method name="getPlaybackState">
> +      <arg type="i" direction="out"/>
> +    </method>
> +    <method name="getPosition">
> +      <arg type="i" direction="out"/>
> +    </method>
> +    <method name="getVolume">
> +      <arg type="i" direction="out"/>
> +    </method>
> +    <method name="pause">
> +    </method>
> +    <method name="play">
> +    </method>
> +    <method name="prev">
> +    </method>
> +    <method name="playNextTrack">
> +    </method>
> +    <method name="next">
> +    </method>
> +    <method name="playPreviousTrack">
> +    </method>
> +    <method name="rewind">
> +    </method>
> +    <method name="setMuted">
> +      <arg name="muted" type="b" direction="in"/>
> +    </method>
> +    <method name="setVolume">
> +      <arg name="level" type="i" direction="in"/>
> +    </method>
> +    <method name="show">
> +    </method>
> +    <method name="stop">
> +    </method>
> +    <method name="getCurrentTrackMetadata">
> +      <arg type="as" direction="out"/>
> +    </method>
> +  </interface>
> +</node>
> --- media/media.context
> +++ media/media.context
> +<?xml version="1.0"?>
> +<provider xmlns="http://contextkit.freedesktop.org/Provider";
> plugin="/media" constructionString="media">
> +  <key name="Media.NowPlaying"></key>
> +</provider>
> --- media/media.pro
> +++ media/media.pro
> +include(../common.pri)
> +
> +system(qdbusxml2cpp -N -c Music -p music_interface.h:music_interface.cpp
> com.meego.app.Music.xml)
> +
> +TEMPLATE = lib
> +SUBDIRS += tests
> +CONFIG += debug \
> +          link_pkgconfig \
> +          plugin
> +PKGCONFIG += contextprovider-1.0 contextsubscriber-1.0
> +TARGET = media
> +target.path = $$CONTEXTKIT_SUBSCRIBER_PLUGIN_PATH
> +
> +SOURCES += \
> +mediaprovider.cpp \
> +music_interface.cpp
> +
> +HEADERS += \
> +mediaprovider.h \
> +music_interface.h
> +
> +OTHER_FILES += media.context \
> +    com.meego.app.Music.xml
> +
> +configuration.files = media.context
> +configuration.path = $$CONTEXTKIT_PROVIDER_CONTEXT_PATH
> +
> +INSTALLS += target configuration
> --- media/mediaprovider.cpp
> +++ media/mediaprovider.cpp
> +/*  -*- Mode: C++ -*-
> + *
> + * contextkit-meego
> + * Copyright © 2010, Intel Corporation.
> + *
> + * This program is licensed under the terms and conditions of the
> + * Apache License, version 2.0.  The full text of the Apache License is at
> + * http://www.apache.org/licenses/LICENSE-2.0
> + *
> + */
> +
> +#include "mediaprovider.h"
> +#include <QDebug>
> +#include <QDBusConnection>
> +#include <QDBusReply>
> +#include <QStringList>
> +#include <QVariant>
> +#include <QString>
> +
> +IProviderPlugin* pluginFactory(const QString& constructionString)
> +{
> +     Q_UNUSED(constructionString)
> +        return new MediaProvider();
> +}
> +
> +const QString MediaProvider::music("Media.NowPlaying");
> +
> +MediaProvider::MediaProvider()
> +{
> +        qDebug() << "MediaProvider::MediaProvider()";
> +
> +        QMetaObject::invokeMethod(this,"ready",Qt::QueuedConnection);
> +
> +        musicPlayer = new Music("com.meego.app.music",
> "/com/meego/app/music", QDBusConnection::sessionBus(), 0);
> +        QObject::connect(musicPlayer,
> SIGNAL(currentTrackMetadataChanged(QStringList)),
> +            this, SLOT(getCurrentTrackMetadata()));
> +
> +        getCurrentTrackMetadata();
> +
> +        //sadly, QVariant is not a registered metatype
> +        qRegisterMetaType<QVariant>("QVariant");
> +
> +        QMetaObject::invokeMethod(this, "valueChanged",
> Qt::QueuedConnection,
> +                      Q_ARG(QString, music),
> +                      Q_ARG(QVariant, m_properties[music]));
> +}
> +
> +MediaProvider::~MediaProvider()
> +{
> +    qDebug() << "MediaProvider::~MediaProvider()";
> +}
> +
> +void MediaProvider::subscribe(QSet<QString> keys)
> +{
> +    qDebug() << "MediaProvider::subscribe(" <<
> QStringList(keys.toList()).join(", ") << ")";
> +
> +         m_subscribedProperties.unite(keys);
> +
> +     QMetaObject::invokeMethod(this, "emitSubscribeFinished",
> Qt::QueuedConnection);
> +        QMetaObject::invokeMethod(this, "emitChanged",
> Qt::QueuedConnection);
> +}
> +
> +void MediaProvider::unsubscribe(QSet<QString> keys)
> +{
> +    qDebug() << "MediaProvider::unsubscribe(" <<
> QStringList(keys.toList()).join(", ") << ")";
> +    m_subscribedProperties.subtract(keys);
> +}
> +
> +void MediaProvider::emitSubscribeFinished()
> +{
> +        foreach(QString key, m_subscribedProperties){
> +                emit subscribeFinished(key);
> +        }
> +}
> +
> +void MediaProvider::emitChanged()
> +{
> +  foreach (QString key, m_subscribedProperties) {
> +    emit valueChanged(key, QVariant(m_properties[key]));
> +  }
> +}
> +
> +void MediaProvider::getCurrentTrackMetadata()
> +{
> +    QStringList musicprops = musicPlayer->getCurrentTrackMetadata();
> +    if(!musicPlayer->isValid() && musicprops.count() < 4){
> +        qDebug() << "No valid metadata for the music app";
> +        return;
> +    }
> +    qDebug() << "Music properties fetched " << musicprops;
> +    QVariantMap metadata;
> +    metadata["album"]= musicprops[0];
> +    metadata["artist"] = musicprops[1];
> +    metadata["title"]= musicprops[2];
> +    metadata["duration"]= musicprops[3].toInt();
> +    metadata["resource"] = ""; //tracker-uri object
> +    metadata["genre"] = ""; //string
> +    metadata["start-time"] = 0; //time
> +    /*if(musicPlayer->getPlaybackState() &&
> musicPlayer->getPlaybackState().value() == 0)
> +        metadata["state"] = "unknown";
> +    else if(musicPlayer->getPlaybackState().value() == 1)
> +        metadata["state"] = "playing";
> +    else if(musicPlayer->getPlaybackState().value() == 2)
> +        metadata["state"] = "paused";
> +    else if(musicPlayer->getPlaybackState().value() == 3)
> +        metadata["state"] = "stopped";
> +    else if(musicPlayer->getPlaybackState().value() == 4)
> +        metadata["state"] = "fastforward";
> +    else if(musicPlayer->getPlaybackState().value() == 5)
> +        metadata["state"] = "rewind"; */
> +    m_properties[music] = metadata;
> +    if (m_subscribedProperties.contains(music))
> +        emitChanged();
> +}
> --- media/mediaprovider.h
> +++ media/mediaprovider.h
> +/*  -*- Mode: C++ -*-
> + *
> + * contextkit-meego
> + * Copyright © 2010, Intel Corporation.
> + *
> + * This program is licensed under the terms and conditions of the
> + * Apache License, version 2.0.  The full text of the Apache License is at
> + * http://www.apache.org/licenses/LICENSE-2.0
> + *
> + */
> +
> +#ifndef MEDIAPROVIDER_H
> +#define MEDIAPROVIDER_H
> +
> +#include <QVariant>
> +#include <QStringList>
> +#include <QObject>
> +#include <iproviderplugin.h>
> +#include <contextproperty.h>
> +#include "music_interface.h"
> +
> +using ContextSubscriber::IProviderPlugin;
> +
> +extern "C"
> +{
> +     IProviderPlugin* pluginFactory(const QString& constructionString);
> +}
> +
> +class MediaProvider : public IProviderPlugin
> +{
> +     Q_OBJECT
> +
> +public:
> +        MediaProvider();
> +        virtual ~MediaProvider();
> +
> +     virtual void subscribe(QSet<QString> keys);
> +     virtual void unsubscribe(QSet<QString> keys);
> +     virtual void blockUntilReady() {}
> +     virtual void blockUntilSubscribed(const QString&) {}
> +
> +        static const QString music;
> +
> +private:
> +        QSet<QString> m_subscribedProperties;
> +        QVariantMap m_properties;
> +        Music *musicPlayer; ///< The interface to the music app
> +
> +private slots:
> +        void emitSubscribeFinished();
> +        void emitChanged();
> +        void getCurrentTrackMetadata();
> +};
> +
> +#endif // MEDIAPROVIDER_H
>
> ++++++ contextkit-meego.yaml
> --- contextkit-meego.yaml
> +++ contextkit-meego.yaml
> @@ -1,6 +1,6 @@
>  Name: contextkit-meego
>  Summary: Contextkit providers for various functions
> -Version: 0.0.15
> +Version: 0.0.16
>  Release: 1
>  Group: System/GUI/Other
>  License: Apache License, Version 2.0
> @@ -20,6 +20,7 @@
>      - connman
>      - bluetooth-qt
>      - contextsubscriber-1.0 >= 0.5.25
> +    - mlite
>  Configure: none
>  Builder: qmake
>
>
> _______________________________________________
> MeeGo-commits mailing list
> [email protected]
> http://lists.meego.com/listinfo/meego-commits
_______________________________________________
MeeGo-packaging mailing list
[email protected]
http://lists.meego.com/listinfo/meego-packaging

Reply via email to