musicfetcher/src/musicfetcher.cpp
changeset 22 ecf06a08d4d9
parent 20 82baf59ce8dd
child 23 d45f4c087764
child 25 3ec52facab4d
child 34 2c5162224003
equal deleted inserted replaced
20:82baf59ce8dd 22:ecf06a08d4d9
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 #include <hbapplication.h>
       
    19 #include <qstringlist.h>
       
    20 
       
    21 #include "musicfetcher.h"
       
    22 #include "mptrace.h"
       
    23 
       
    24 /*!
       
    25     \class MusicFetcher
       
    26     \brief Music fecther service.
       
    27 
       
    28     Music fetcher implements fetching of music uris via service provider API.
       
    29 */
       
    30 
       
    31 // ----------------------------------------------------------------------------
       
    32 // Constructs the music fetcher.
       
    33 // ----------------------------------------------------------------------------
       
    34 //
       
    35 MusicFetcher::MusicFetcher()
       
    36 {
       
    37     TX_ENTRY
       
    38     mService = new GetMusicService(this);
       
    39     TX_EXIT
       
    40 }
       
    41 
       
    42 // ----------------------------------------------------------------------------
       
    43 // Destructs the music fetcher.
       
    44 // ----------------------------------------------------------------------------
       
    45 //
       
    46 MusicFetcher::~MusicFetcher()
       
    47 {
       
    48     TX_ENTRY
       
    49     delete mService;
       
    50     TX_EXIT
       
    51 }
       
    52 
       
    53 // ----------------------------------------------------------------------------
       
    54 // Returns a string to show in music fetcher application title.
       
    55 // ----------------------------------------------------------------------------
       
    56 //
       
    57 QString MusicFetcher::contextTitle() const
       
    58 {
       
    59     return mService->contextTitle();
       
    60 }
       
    61 
       
    62 // ----------------------------------------------------------------------------
       
    63 // Slot to be called when music item has been selected.
       
    64 // ----------------------------------------------------------------------------
       
    65 //
       
    66 void MusicFetcher::itemSelected(QString songName)
       
    67 {
       
    68     TX_ENTRY_ARGS("songName: " << songName);
       
    69     QStringList list;
       
    70     list.append(songName);
       
    71     mService->complete( list );
       
    72 }
       
    73 
       
    74 // ----------------------------------------------------------------------------
       
    75 // Constructs the music service.
       
    76 // ----------------------------------------------------------------------------
       
    77 //
       
    78 GetMusicService::GetMusicService(MusicFetcher* parent)
       
    79     : XQServiceProvider(QLatin1String("Music Fetcher.com.nokia.services.media.Music"), parent),
       
    80     mRequestIndex(0),
       
    81     mServiceApp(parent)
       
    82 {
       
    83     TX_ENTRY
       
    84     publishAll();
       
    85     TX_EXIT
       
    86 }
       
    87 
       
    88 // ----------------------------------------------------------------------------
       
    89 // Destructs the music service.
       
    90 // ----------------------------------------------------------------------------
       
    91 //
       
    92 GetMusicService::~GetMusicService()
       
    93 {
       
    94     TX_LOG
       
    95 }
       
    96 
       
    97 // ----------------------------------------------------------------------------
       
    98 // Completes the service request.
       
    99 // ----------------------------------------------------------------------------
       
   100 //
       
   101 void GetMusicService::complete(QStringList filesList)
       
   102 {
       
   103     doComplete(filesList);
       
   104 }
       
   105 
       
   106 // ----------------------------------------------------------------------------
       
   107 // Completes the service request.
       
   108 // ----------------------------------------------------------------------------
       
   109 //
       
   110 void GetMusicService::doComplete(QStringList filesList)
       
   111 {
       
   112     if ( isActive() ) {
       
   113         connect(this, SIGNAL(returnValueDelivered()), qApp, SLOT(quit()));
       
   114         completeRequest(mRequestIndex, filesList);
       
   115         mRequestIndex=0;
       
   116     }
       
   117 }
       
   118 
       
   119 // ----------------------------------------------------------------------------
       
   120 // Returns title set by service client.
       
   121 // ----------------------------------------------------------------------------
       
   122 //
       
   123 QString GetMusicService::contextTitle() const
       
   124 {
       
   125     return mTitle;
       
   126 }
       
   127 
       
   128 // ----------------------------------------------------------------------------
       
   129 // Returns indication whether service request still active.
       
   130 // ----------------------------------------------------------------------------
       
   131 //
       
   132 bool GetMusicService::isActive()
       
   133 {
       
   134     return mRequestIndex > 0;
       
   135 }
       
   136 
       
   137 /*!
       
   138     Music Fetcher service interface defined in service registration xml.
       
   139     Service client needs to create a request using interface name
       
   140     "com.nokia.services.media.Music" and set string to show in
       
   141     opened views title as a request argument.
       
   142 
       
   143     Example usage:
       
   144     \code
       
   145     XQApplicationManager appMgr;
       
   146     XQAiwRequest* req = appMgr.create("com.nokia.services.media.Music",
       
   147         "fetch(QString)", true);
       
   148 
       
   149     if (req)
       
   150     {
       
   151         connect(req, SIGNAL(requestOk(const QVariant&)),
       
   152             SLOT(handleRequestOk(const QVariant&)));
       
   153         connect(req, SIGNAL(requestError(int,const QString&)),
       
   154             SLOT(handleRequestError(int,const QString&)));
       
   155 
       
   156         // Set argument for request (title for opened views)
       
   157         QList<QVariant> args;
       
   158         args << QVariant(QString("<title to show>"));
       
   159         req->setArguments(args);
       
   160 
       
   161         // Make the request
       
   162         if (!req->send())
       
   163         {
       
   164             qDebug() <<  "Failed to send REQ";
       
   165         }
       
   166         delete req;
       
   167     }
       
   168     \endcode
       
   169  */
       
   170 void GetMusicService::fetch(QString title)
       
   171 {
       
   172     TX_ENTRY_ARGS("title: " << title);
       
   173     mTitle = title;
       
   174     emit mServiceApp->titleReady(title);
       
   175     mRequestIndex = setCurrentRequestAsync();
       
   176 }