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