|
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: This widget is used to display audio content in univiewer. |
|
15 * |
|
16 */ |
|
17 #include "univieweraudiowidget.h" |
|
18 |
|
19 // SYSTEM INCLUDES |
|
20 #include <QFileInfo> |
|
21 #include <QTimer> |
|
22 #include <HbMenu> |
|
23 |
|
24 // USER INCLUDES |
|
25 #include "msgmediautil.h" |
|
26 #include "univiewerutils.h" |
|
27 #include "unidatamodelplugininterface.h" |
|
28 |
|
29 // LOCAL CONSTANTS |
|
30 #define LOC_OPEN hbTrId("txt_common_menu_open") |
|
31 #define LOC_SAVE hbTrId("txt_common_menu_save") |
|
32 |
|
33 const QString AUDIO_ICON("qtg_mono_audio"); |
|
34 const QString CORRUPTED_AUDIO_ICON("qtg_mono_corrupted"); |
|
35 |
|
36 //---------------------------------------------------------------------------- |
|
37 // UniViewerAudioWidget::UniViewerAudioWidget |
|
38 // @see header file |
|
39 //---------------------------------------------------------------------------- |
|
40 UniViewerAudioWidget::UniViewerAudioWidget(QGraphicsItem *parent) : |
|
41 HbPushButton(parent), mViewerUtils(0) |
|
42 { |
|
43 connect(this, SIGNAL(clicked()), this, SLOT(handleShortTap())); |
|
44 connect(this, SIGNAL(longPress(QPointF)), this, SLOT(handleLongTap(QPointF))); |
|
45 } |
|
46 |
|
47 //---------------------------------------------------------------------------- |
|
48 // UniViewerAudioWidget::~UniViewerAudioWidget |
|
49 // @see header file |
|
50 //---------------------------------------------------------------------------- |
|
51 UniViewerAudioWidget::~UniViewerAudioWidget() |
|
52 { |
|
53 } |
|
54 |
|
55 //---------------------------------------------------------------------------- |
|
56 // UniViewerAudioWidget::~UniViewerAudioWidget |
|
57 // @see header file |
|
58 //---------------------------------------------------------------------------- |
|
59 void UniViewerAudioWidget::populate(UniMessageInfo *info) |
|
60 { |
|
61 mMimeType = info->mimetype(); |
|
62 mMediaPath = info->path(); |
|
63 |
|
64 HbIcon audioIcon; |
|
65 if (info->isProtected()) { |
|
66 audioIcon.setIconName(AUDIO_ICON); |
|
67 } |
|
68 else if (info->isCorrupted()) { |
|
69 audioIcon.setIconName(CORRUPTED_AUDIO_ICON); |
|
70 } |
|
71 else { |
|
72 audioIcon.setIconName(AUDIO_ICON); |
|
73 } |
|
74 |
|
75 this->setIcon(audioIcon); |
|
76 QFileInfo fileInfo(mMediaPath); |
|
77 this->setText(fileInfo.baseName()); |
|
78 this->setTextAlignment(Qt::AlignLeft); |
|
79 MsgMediaUtil mediaUtil; |
|
80 this->setAdditionalText(mediaUtil.mediaDuration(mMediaPath)); |
|
81 } |
|
82 |
|
83 //---------------------------------------------------------------------------- |
|
84 // UniViewerAudioWidget::handleShortTap |
|
85 // @see header file |
|
86 //---------------------------------------------------------------------------- |
|
87 void UniViewerAudioWidget::handleShortTap() |
|
88 { |
|
89 emit shortTap(mMediaPath); |
|
90 |
|
91 // Open the media. |
|
92 handleOpen(); |
|
93 } |
|
94 |
|
95 //---------------------------------------------------------------------------- |
|
96 // UniViewerAudioWidget::handleLongTap |
|
97 // @see header file |
|
98 //---------------------------------------------------------------------------- |
|
99 void UniViewerAudioWidget::handleLongTap(const QPointF &position) |
|
100 { |
|
101 emit longTap(position); |
|
102 |
|
103 // Display context sensitive menu. |
|
104 HbMenu* menu = new HbMenu; |
|
105 menu->setAttribute(Qt::WA_DeleteOnClose); |
|
106 menu->addAction(LOC_OPEN, this, SLOT(handleOpen())); |
|
107 menu->addAction(LOC_SAVE, this, SLOT(handleSave())); |
|
108 menu->setPreferredPos(position); |
|
109 menu->show(); |
|
110 } |
|
111 |
|
112 //---------------------------------------------------------------------------- |
|
113 // UniViewerAudioWidget::handleOpen |
|
114 // @see header file |
|
115 //---------------------------------------------------------------------------- |
|
116 void UniViewerAudioWidget::handleOpen() |
|
117 { |
|
118 this->ungrabGesture(Qt::TapGesture); |
|
119 |
|
120 if (!mViewerUtils) { |
|
121 mViewerUtils = new UniViewerUtils(this); |
|
122 } |
|
123 mViewerUtils->launchContentViewer(mMimeType, mMediaPath); |
|
124 |
|
125 //fire timer to regrab gesture after some delay. |
|
126 QTimer::singleShot(300,this,SLOT(regrabGesture())); |
|
127 } |
|
128 |
|
129 //---------------------------------------------------------------------------- |
|
130 // UniViewerAudioWidget::handleSave |
|
131 // @see header file |
|
132 //---------------------------------------------------------------------------- |
|
133 void UniViewerAudioWidget::handleSave() |
|
134 { |
|
135 |
|
136 } |
|
137 |
|
138 //--------------------------------------------------------------- |
|
139 // UniViewerAudioWidget::regrabGesture |
|
140 // @see header file |
|
141 //--------------------------------------------------------------- |
|
142 void UniViewerAudioWidget::regrabGesture() |
|
143 { |
|
144 this->grabGesture(Qt::TapGesture); |
|
145 } |
|
146 // EOF |