onlinesearchproviders/isengine/src/isengine.cpp
author hgs
Mon, 28 Jun 2010 11:03:15 +0530
changeset 9 4a2987baf8f7
permissions -rw-r--r--
201025
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     3
* All rights reserved.
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
*
hgs
parents:
diff changeset
     9
* Initial Contributors:
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
*
hgs
parents:
diff changeset
    12
* Contributors:
hgs
parents:
diff changeset
    13
*
hgs
parents:
diff changeset
    14
* Description: 
hgs
parents:
diff changeset
    15
*
hgs
parents:
diff changeset
    16
*/
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
hgs
parents:
diff changeset
    19
#include <QDesktopServices>
hgs
parents:
diff changeset
    20
#include <xqapplicationmanager.h>
hgs
parents:
diff changeset
    21
#include <QUrl>
hgs
parents:
diff changeset
    22
#include <qservicemanager.h>
hgs
parents:
diff changeset
    23
#include "isengine.h"
hgs
parents:
diff changeset
    24
#include "isproviderdbmanager.h"
hgs
parents:
diff changeset
    25
QTM_USE_NAMESPACE
hgs
parents:
diff changeset
    26
const QString KAppUid = "0x2002C377";
hgs
parents:
diff changeset
    27
hgs
parents:
diff changeset
    28
IsEngine::IsEngine(QObject *parent) :
hgs
parents:
diff changeset
    29
    QObject(parent), m_activityManager(0)
hgs
parents:
diff changeset
    30
    {
hgs
parents:
diff changeset
    31
    QServiceManager serviceManager;
hgs
parents:
diff changeset
    32
    m_activityManager = serviceManager.loadInterface(
hgs
parents:
diff changeset
    33
            "com.nokia.qt.activities.ActivityManager");
hgs
parents:
diff changeset
    34
    
hgs
parents:
diff changeset
    35
    m_dbHandler = new IsProviderDBManager;
hgs
parents:
diff changeset
    36
    }
hgs
parents:
diff changeset
    37
hgs
parents:
diff changeset
    38
IsEngine::~IsEngine()
hgs
parents:
diff changeset
    39
    {
hgs
parents:
diff changeset
    40
    if (m_activityManager)
hgs
parents:
diff changeset
    41
        {
hgs
parents:
diff changeset
    42
        delete m_activityManager;
hgs
parents:
diff changeset
    43
        }
hgs
parents:
diff changeset
    44
    
hgs
parents:
diff changeset
    45
    delete m_dbHandler; 
hgs
parents:
diff changeset
    46
    }
hgs
parents:
diff changeset
    47
hgs
parents:
diff changeset
    48
/*!
hgs
parents:
diff changeset
    49
 * \brief   Sets selected provider
hgs
parents:
diff changeset
    50
 *          Returns false if something goes wrong with the database access
hgs
parents:
diff changeset
    51
 */
hgs
parents:
diff changeset
    52
bool IsEngine::SetSelectedProvider(const int providerId)
hgs
parents:
diff changeset
    53
    {    
hgs
parents:
diff changeset
    54
    return m_dbHandler->SetSelectedProvider(providerId);    
hgs
parents:
diff changeset
    55
    }
hgs
parents:
diff changeset
    56
hgs
parents:
diff changeset
    57
/*!
hgs
parents:
diff changeset
    58
 * \brief   Gets selected provider
hgs
parents:
diff changeset
    59
 */
hgs
parents:
diff changeset
    60
ServiceProvider* IsEngine::SelectedProvider()
hgs
parents:
diff changeset
    61
    {    
hgs
parents:
diff changeset
    62
    return m_dbHandler->SelectedProvider();    
hgs
parents:
diff changeset
    63
    }
hgs
parents:
diff changeset
    64
hgs
parents:
diff changeset
    65
/*!
hgs
parents:
diff changeset
    66
 * \brief   Gets list of providers allowed in the current country.
hgs
parents:
diff changeset
    67
 *          Returns false if something goes wrong with the database access
hgs
parents:
diff changeset
    68
 */
hgs
parents:
diff changeset
    69
bool IsEngine::Providers(QList<ServiceProvider>& providers)
hgs
parents:
diff changeset
    70
    {    
hgs
parents:
diff changeset
    71
    return m_dbHandler->GetProviders(providers);    
hgs
parents:
diff changeset
    72
    }
hgs
parents:
diff changeset
    73
hgs
parents:
diff changeset
    74
/*!
hgs
parents:
diff changeset
    75
 * \brief   Performs internet search by creating search url and opening the browser
hgs
parents:
diff changeset
    76
 *          with it.
hgs
parents:
diff changeset
    77
 */
hgs
parents:
diff changeset
    78
void IsEngine::PerformWebSearch(const QString &searchParam)
hgs
parents:
diff changeset
    79
    {
hgs
parents:
diff changeset
    80
    ServiceProvider* provider = SelectedProvider();
hgs
parents:
diff changeset
    81
    
hgs
parents:
diff changeset
    82
    if (provider)
hgs
parents:
diff changeset
    83
        {
hgs
parents:
diff changeset
    84
        QString url;
hgs
parents:
diff changeset
    85
        if ( searchParam.length() )
hgs
parents:
diff changeset
    86
            {
hgs
parents:
diff changeset
    87
            // add search param to url
hgs
parents:
diff changeset
    88
            url.append((provider->ProviderUrl().arg(searchParam)));        
hgs
parents:
diff changeset
    89
            }
hgs
parents:
diff changeset
    90
        else
hgs
parents:
diff changeset
    91
            {
hgs
parents:
diff changeset
    92
            // search with empty param
hgs
parents:
diff changeset
    93
            url.append((provider->ProviderUrl().arg("")));
hgs
parents:
diff changeset
    94
            }
hgs
parents:
diff changeset
    95
        
hgs
parents:
diff changeset
    96
hgs
parents:
diff changeset
    97
        // Launch the browser
hgs
parents:
diff changeset
    98
        QDesktopServices::openUrl(QUrl(url));
hgs
parents:
diff changeset
    99
        }
hgs
parents:
diff changeset
   100
    }
hgs
parents:
diff changeset
   101
hgs
parents:
diff changeset
   102
/*!
hgs
parents:
diff changeset
   103
 * \brief   Performs in device search
hgs
parents:
diff changeset
   104
 * 
hgs
parents:
diff changeset
   105
 * \param searchParam a const QString & argument.
hgs
parents:
diff changeset
   106
 */
hgs
parents:
diff changeset
   107
void IsEngine::PerformInDeviceSearch(const QString &searchParam) const
hgs
parents:
diff changeset
   108
    {
hgs
parents:
diff changeset
   109
    QUrl url;
hgs
parents:
diff changeset
   110
    url.setScheme("appto");
hgs
parents:
diff changeset
   111
    url.setHost(KAppUid);
hgs
parents:
diff changeset
   112
    url.addQueryItem("activityname", "SearchDeviceQueryView");
hgs
parents:
diff changeset
   113
hgs
parents:
diff changeset
   114
    url.addQueryItem("query", searchParam);
hgs
parents:
diff changeset
   115
hgs
parents:
diff changeset
   116
    QString debugString = url.toString();
hgs
parents:
diff changeset
   117
    bool ok = QMetaObject::invokeMethod(m_activityManager, "launchActivity",
hgs
parents:
diff changeset
   118
            Q_ARG(QUrl, url));
hgs
parents:
diff changeset
   119
hgs
parents:
diff changeset
   120
    }