musicservices/src/playmusicservice.cpp
changeset 22 ecf06a08d4d9
child 29 8192e5b5c935
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 "musicservices.h"
       
    22 #include "playmusicservice.h"
       
    23 #include "mptrace.h"
       
    24 
       
    25 
       
    26 
       
    27 
       
    28 /*!
       
    29  Constructs play music service
       
    30  */
       
    31 PlayMusicService::PlayMusicService( MusicServices* parent )
       
    32 : XQServiceProvider(QLatin1String("musicplayer.com.nokia.symbian.IFileView"), parent),
       
    33   mRequestIndex( 0 ),
       
    34   mServiceApp( parent )
       
    35 {
       
    36     TX_ENTRY
       
    37     publishAll();
       
    38     TX_EXIT
       
    39 }
       
    40 
       
    41 /*!
       
    42  Destructs play music service
       
    43  */
       
    44 PlayMusicService::~PlayMusicService()
       
    45 {
       
    46     TX_LOG
       
    47 }
       
    48 
       
    49 
       
    50 /*!
       
    51  Returns whether current service is still active
       
    52  */
       
    53 bool PlayMusicService::isActive()
       
    54 {
       
    55     return mRequestIndex > 0;
       
    56 }
       
    57 
       
    58 /*!
       
    59  Completes current request 
       
    60  */
       
    61 void PlayMusicService::complete(QStringList filesList)
       
    62 {   TX_ENTRY_ARGS("EmbeddeddoComplete: ");
       
    63     if ( isActive() ) {
       
    64         TX_ENTRY_ARGS("EmbeddeddoComplete2: ");
       
    65         connect(this, SIGNAL(returnValueDelivered()), qApp, SLOT(quit()));
       
    66         completeRequest(mRequestIndex, filesList);
       
    67         mRequestIndex=0;
       
    68     }
       
    69 }
       
    70 
       
    71 /*!
       
    72  Returns title of calling application
       
    73  */
       
    74 QString PlayMusicService::contextTitle() const
       
    75 {
       
    76     return mTitle;
       
    77 }
       
    78 
       
    79 /*!
       
    80     Embedded Playback service interface defined in service registration xml.
       
    81 
       
    82     Example usage:
       
    83     
       
    84     QFile file("c:\\audio.mp3");
       
    85 
       
    86     mReq = mAppMgr.create(file);
       
    87     if (mReq == NULL)
       
    88     {
       
    89            // No handlers for the URI
       
    90            return;
       
    91      }
       
    92     // By default operation is "view(QString)"
       
    93 
       
    94     // Set function parameters
       
    95    QList<QVariant> args;
       
    96    args << file.fileName();
       
    97    mReq->setArguments(args);
       
    98    QString title("WindowTitle");
       
    99    QVariant title2(QString("<app_name>View"));
       
   100    XQRequestInfo info;
       
   101    info.setInfo(title, title2);
       
   102    mReq->setInfo(info);
       
   103    // Send the request
       
   104    bool res = mReq->send();
       
   105    if  (!res) 
       
   106    {
       
   107        // Request failed. 
       
   108       int error = mReq->lastError();
       
   109 
       
   110       // Handle error
       
   111    }
       
   112  
       
   113    // If making multiple requests to same service, you can save the request as member variable
       
   114    // In this example all done.
       
   115    delete mReq;
       
   116  */
       
   117 
       
   118 bool PlayMusicService::view(const QString& file)
       
   119 {
       
   120     TX_ENTRY
       
   121 	QString uri(file);
       
   122     uri.replace(QString("/"),QString("\\"));
       
   123     mTitle = requestInfo().info("WindowTitle").toString();
       
   124     mServiceApp->setCurrentService( MusicServices::EPlayback );
       
   125     TUid uid = TUid::Uid(requestInfo().clientSecureId()); 
       
   126     emit mServiceApp->serviceActive( uid );
       
   127     emit mServiceApp->playReady( uri );
       
   128     connect(this, SIGNAL( clientDisconnected() ), qApp, SLOT( quit() ) );
       
   129     mRequestIndex = setCurrentRequestAsync();
       
   130     
       
   131     return true;
       
   132     
       
   133 }
       
   134 
       
   135 /*!
       
   136     Embedded Playback service interface defined in service registration xml.
       
   137 
       
   138     Example usage:
       
   139     
       
   140    XQSharableFile sf;
       
   141     if (!sf.open("c:\\audio.mp3"))
       
   142     {
       
   143         // Failed to open sharable file
       
   144         return;
       
   145     }
       
   146 
       
   147     // Create request for the sharable file
       
   148     mReq = mAppMgr.create(sf);
       
   149     if (!mReq)
       
   150     {
       
   151          // No viewer app found for the file
       
   152          // As we opened the handle, we need to close it !
       
   153          sf.close(); 
       
   154          return;  
       
   155     }
       
   156     // By default operation is "view(XQSharableFile)"
       
   157 
       
   158     // Set function parameters
       
   159     // Not only one sharable handle supported,  otherwise upon send EArgumentError error occurs
       
   160     QList<QVariant> args;
       
   161     args << qVariantFromValue(sf);  
       
   162     mReq->setArguments(args);
       
   163     QString title("WindowTitle");
       
   164    QVariant title2(QString("<app_name>"));
       
   165    XQRequestInfo info;
       
   166    info.setInfo(title, title2);
       
   167    mReq->setInfo(info);
       
   168    // Send the request
       
   169    bool res = mReq->send();
       
   170    if  (!res) 
       
   171    {
       
   172        // Request failed. 
       
   173       int error = mReq->lastError();
       
   174       // Handle error
       
   175    }
       
   176 
       
   177     // As we opened the handle, we need to close it !
       
   178     sf.close(); 
       
   179 
       
   180    // If making multiple requests to same service, you can save the mReq as member variable
       
   181    // In this example all done.
       
   182    delete mReq;
       
   183  */
       
   184 bool PlayMusicService::view(const XQSharableFile& file)
       
   185 {
       
   186     TX_ENTRY
       
   187     mTitle = requestInfo().info("WindowTitle").toString();
       
   188     mServiceApp->setCurrentService( MusicServices::EPlayback );
       
   189     TUid uid = TUid::Uid(requestInfo().clientSecureId()); 
       
   190     emit mServiceApp->serviceActive( uid );
       
   191     emit mServiceApp->playReady( file );
       
   192     connect(this, SIGNAL( clientDisconnected() ), qApp, SLOT( quit() ) );
       
   193     mRequestIndex = setCurrentRequestAsync();
       
   194     return true;
       
   195 }