activityfw/activitylauncher/activitylauncherview.cpp
author hgs
Fri, 28 May 2010 16:17:03 +0300
changeset 96 5d243a69bdda
parent 92 782e3408c2ab
permissions -rw-r--r--
201021
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
89
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
*
92
hgs
parents: 90
diff changeset
    14
* Description:
89
hgs
parents:
diff changeset
    15
*
hgs
parents:
diff changeset
    16
*/
hgs
parents:
diff changeset
    17
#include "activitylauncherview.h"
hgs
parents:
diff changeset
    18
hgs
parents:
diff changeset
    19
#include <QGraphicsLinearLayout>
hgs
parents:
diff changeset
    20
#include <QStandardItemModel>
hgs
parents:
diff changeset
    21
#include <QProcess>
hgs
parents:
diff changeset
    22
hgs
parents:
diff changeset
    23
#include <qservicemanager.h>
hgs
parents:
diff changeset
    24
hgs
parents:
diff changeset
    25
#include <hblabel.h>
hgs
parents:
diff changeset
    26
#include <hbapplication.h>
hgs
parents:
diff changeset
    27
#include <hbpushbutton.h>
hgs
parents:
diff changeset
    28
#include <hbgridview.h>
hgs
parents:
diff changeset
    29
hgs
parents:
diff changeset
    30
#include <hsactivitydbclientinterface.h>
hgs
parents:
diff changeset
    31
hgs
parents:
diff changeset
    32
QTM_USE_NAMESPACE
hgs
parents:
diff changeset
    33
hgs
parents:
diff changeset
    34
ActivityLauncherView::ActivityLauncherView(QGraphicsItem *parent) : HbView(parent), mModel(NULL), mActivityManager(NULL)
hgs
parents:
diff changeset
    35
{
hgs
parents:
diff changeset
    36
    QServiceManager serviceManager;
hgs
parents:
diff changeset
    37
    mActivityManager = serviceManager.loadInterface("com.nokia.qt.activities.ActivityManager");
92
hgs
parents: 90
diff changeset
    38
89
hgs
parents:
diff changeset
    39
    if (!mActivityManager) {
hgs
parents:
diff changeset
    40
        qFatal("Cannot initialize critical com.nokia.qt.activities.ActivityManager service");
hgs
parents:
diff changeset
    41
    }
hgs
parents:
diff changeset
    42
hgs
parents:
diff changeset
    43
    // create UI
hgs
parents:
diff changeset
    44
    setTitle(tr("Activity launcher"));
92
hgs
parents: 90
diff changeset
    45
    QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical);
hgs
parents: 90
diff changeset
    46
    QGraphicsLinearLayout *statusLayout = new QGraphicsLinearLayout(Qt::Horizontal);
89
hgs
parents:
diff changeset
    47
    mStatusLabel = new HbLabel(this);
hgs
parents:
diff changeset
    48
    mStatusLabel->setAlignment(Qt::AlignLeft);
hgs
parents:
diff changeset
    49
    statusLayout->setMaximumHeight(15);
hgs
parents:
diff changeset
    50
92
hgs
parents: 90
diff changeset
    51
    HbLabel *statusHeader = new HbLabel("Status: ");
89
hgs
parents:
diff changeset
    52
    statusHeader->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
hgs
parents:
diff changeset
    53
    statusLayout->addItem(statusHeader);
hgs
parents:
diff changeset
    54
    statusLayout->addItem(mStatusLabel);
hgs
parents:
diff changeset
    55
92
hgs
parents: 90
diff changeset
    56
    HbGridView *activities = new HbGridView();
89
hgs
parents:
diff changeset
    57
    connect(activities, SIGNAL(activated(QModelIndex)), this, SLOT(itemPressed(QModelIndex)));
hgs
parents:
diff changeset
    58
    activities->setRowCount(1);
hgs
parents:
diff changeset
    59
    activities->setColumnCount(1);
hgs
parents:
diff changeset
    60
hgs
parents:
diff changeset
    61
    activities->setScrollDirections(Qt::Horizontal);
hgs
parents:
diff changeset
    62
hgs
parents:
diff changeset
    63
    mModel = new QStandardItemModel(this);
hgs
parents:
diff changeset
    64
    activities->setModel(mModel);
hgs
parents:
diff changeset
    65
hgs
parents:
diff changeset
    66
    layout->addItem(statusLayout);
hgs
parents:
diff changeset
    67
    layout->addItem(activities);
hgs
parents:
diff changeset
    68
hgs
parents:
diff changeset
    69
    setLayout(layout);
hgs
parents:
diff changeset
    70
    qApp->installEventFilter(this);
hgs
parents:
diff changeset
    71
    getActivitiesList();
hgs
parents:
diff changeset
    72
}
hgs
parents:
diff changeset
    73
hgs
parents:
diff changeset
    74
ActivityLauncherView::~ActivityLauncherView()
hgs
parents:
diff changeset
    75
{
92
hgs
parents: 90
diff changeset
    76
    delete mActivityManager;
89
hgs
parents:
diff changeset
    77
}
hgs
parents:
diff changeset
    78
hgs
parents:
diff changeset
    79
void ActivityLauncherView::getActivitiesList()
hgs
parents:
diff changeset
    80
{
hgs
parents:
diff changeset
    81
    mStatusLabel->setPlainText("Fetching activities");
hgs
parents:
diff changeset
    82
    mCurrentActivities.clear();
hgs
parents:
diff changeset
    83
    QMetaObject::invokeMethod(mActivityManager, "activitiesList", Q_RETURN_ARG(QList<QVariantHash>, mCurrentActivities));
hgs
parents:
diff changeset
    84
    mModel->clear();
hgs
parents:
diff changeset
    85
hgs
parents:
diff changeset
    86
    foreach(const QVariantHash& activityEntry, mCurrentActivities) {
92
hgs
parents: 90
diff changeset
    87
        QStandardItem *newItem = new QStandardItem(QIcon(activityEntry.value("screenshot").value<QPixmap>()), QString("%1").arg(activityEntry.value(ActivityActivityKeyword).toInt()));
89
hgs
parents:
diff changeset
    88
        mModel->invisibleRootItem()->appendRow(newItem);
hgs
parents:
diff changeset
    89
    }
hgs
parents:
diff changeset
    90
    mStatusLabel->setPlainText(QString("Ready (%1 activities)").arg(mCurrentActivities.count()));
hgs
parents:
diff changeset
    91
}
hgs
parents:
diff changeset
    92
92
hgs
parents: 90
diff changeset
    93
bool ActivityLauncherView::eventFilter(QObject *obj, QEvent *event)
89
hgs
parents:
diff changeset
    94
{
hgs
parents:
diff changeset
    95
    if (event->type() == QEvent::ApplicationActivate) {
hgs
parents:
diff changeset
    96
        getActivitiesList();
hgs
parents:
diff changeset
    97
    }
hgs
parents:
diff changeset
    98
    return QObject::eventFilter(obj, event);
hgs
parents:
diff changeset
    99
}
hgs
parents:
diff changeset
   100
92
hgs
parents: 90
diff changeset
   101
void ActivityLauncherView::itemPressed(const QModelIndex &index)
89
hgs
parents:
diff changeset
   102
{
hgs
parents:
diff changeset
   103
    QVariantHash activity = mCurrentActivities.at(index.row());
hgs
parents:
diff changeset
   104
    int applicationId = activity.value(ActivityApplicationKeyword).toInt();
hgs
parents:
diff changeset
   105
    QString activityName = activity.value(ActivityActivityKeyword).toString();
hgs
parents:
diff changeset
   106
    QMetaObject::invokeMethod(mActivityManager, "launchActivity", Q_ARG(int, applicationId), Q_ARG(QString, activityName));
hgs
parents:
diff changeset
   107
}