37
|
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 |
|
51
|
33 |
static const char VIDEO_MIMETYPE[] = "video";
|
|
34 |
static const char AUDIO_ICON[] = "qtg_mono_audio";
|
|
35 |
static const char VIDEO_ICON[] = "qtg_mono_video";
|
|
36 |
static const char CORRUPTED_AUDIO_ICON[] = "qtg_mono_corrupted";
|
37
|
37 |
|
|
38 |
//----------------------------------------------------------------------------
|
|
39 |
// UniViewerAudioWidget::UniViewerAudioWidget
|
|
40 |
// @see header file
|
|
41 |
//----------------------------------------------------------------------------
|
|
42 |
UniViewerAudioWidget::UniViewerAudioWidget(QGraphicsItem *parent) :
|
51
|
43 |
HbPushButton(parent), mViewerUtils(0), mValidMediaDuration(true)
|
37
|
44 |
{
|
|
45 |
connect(this, SIGNAL(clicked()), this, SLOT(handleShortTap()));
|
|
46 |
connect(this, SIGNAL(longPress(QPointF)), this, SLOT(handleLongTap(QPointF)));
|
|
47 |
}
|
|
48 |
|
|
49 |
//----------------------------------------------------------------------------
|
|
50 |
// UniViewerAudioWidget::~UniViewerAudioWidget
|
|
51 |
// @see header file
|
|
52 |
//----------------------------------------------------------------------------
|
|
53 |
UniViewerAudioWidget::~UniViewerAudioWidget()
|
|
54 |
{
|
|
55 |
}
|
|
56 |
|
|
57 |
//----------------------------------------------------------------------------
|
|
58 |
// UniViewerAudioWidget::~UniViewerAudioWidget
|
|
59 |
// @see header file
|
|
60 |
//----------------------------------------------------------------------------
|
|
61 |
void UniViewerAudioWidget::populate(UniMessageInfo *info)
|
|
62 |
{
|
|
63 |
mMimeType = info->mimetype();
|
|
64 |
mMediaPath = info->path();
|
|
65 |
|
|
66 |
HbIcon audioIcon;
|
51
|
67 |
|
37
|
68 |
if (info->isProtected()) {
|
51
|
69 |
if (mMimeType.contains(VIDEO_MIMETYPE)) {
|
|
70 |
audioIcon.setIconName(VIDEO_ICON);
|
|
71 |
}
|
|
72 |
else {
|
|
73 |
audioIcon.setIconName(AUDIO_ICON);
|
|
74 |
}
|
37
|
75 |
}
|
|
76 |
else if (info->isCorrupted()) {
|
|
77 |
audioIcon.setIconName(CORRUPTED_AUDIO_ICON);
|
|
78 |
}
|
|
79 |
else {
|
51
|
80 |
if (mMimeType.contains(VIDEO_MIMETYPE)) {
|
|
81 |
audioIcon.setIconName(VIDEO_ICON);
|
|
82 |
}
|
|
83 |
else {
|
|
84 |
audioIcon.setIconName(AUDIO_ICON);
|
|
85 |
}
|
37
|
86 |
}
|
|
87 |
|
|
88 |
this->setIcon(audioIcon);
|
|
89 |
QFileInfo fileInfo(mMediaPath);
|
|
90 |
this->setText(fileInfo.baseName());
|
|
91 |
this->setTextAlignment(Qt::AlignLeft);
|
|
92 |
MsgMediaUtil mediaUtil;
|
51
|
93 |
QString mediaDuration(mediaUtil.mediaDuration(mMediaPath));
|
|
94 |
if (mediaDuration.isEmpty()) {
|
|
95 |
mValidMediaDuration = false;
|
|
96 |
}
|
|
97 |
else {
|
|
98 |
mValidMediaDuration = true;
|
|
99 |
this->setAdditionalText(mediaDuration);
|
|
100 |
}
|
|
101 |
}
|
|
102 |
|
|
103 |
//----------------------------------------------------------------------------
|
|
104 |
// UniViewerAudioWidget::setStretched
|
|
105 |
// @see header file
|
|
106 |
//----------------------------------------------------------------------------
|
|
107 |
void UniViewerAudioWidget::setStretched(bool stretched)
|
|
108 |
{
|
|
109 |
if (mValidMediaDuration) {
|
|
110 |
HbPushButton::setStretched(stretched);
|
|
111 |
}
|
|
112 |
else {
|
|
113 |
HbPushButton::setStretched(true);
|
|
114 |
}
|
37
|
115 |
}
|
|
116 |
|
|
117 |
//----------------------------------------------------------------------------
|
|
118 |
// UniViewerAudioWidget::handleShortTap
|
|
119 |
// @see header file
|
|
120 |
//----------------------------------------------------------------------------
|
|
121 |
void UniViewerAudioWidget::handleShortTap()
|
|
122 |
{
|
|
123 |
emit shortTap(mMediaPath);
|
|
124 |
|
|
125 |
// Open the media.
|
|
126 |
handleOpen();
|
|
127 |
}
|
|
128 |
|
|
129 |
//----------------------------------------------------------------------------
|
|
130 |
// UniViewerAudioWidget::handleLongTap
|
|
131 |
// @see header file
|
|
132 |
//----------------------------------------------------------------------------
|
|
133 |
void UniViewerAudioWidget::handleLongTap(const QPointF &position)
|
|
134 |
{
|
|
135 |
emit longTap(position);
|
|
136 |
|
|
137 |
// Display context sensitive menu.
|
|
138 |
HbMenu* menu = new HbMenu;
|
|
139 |
menu->setAttribute(Qt::WA_DeleteOnClose);
|
|
140 |
menu->addAction(LOC_OPEN, this, SLOT(handleOpen()));
|
|
141 |
menu->addAction(LOC_SAVE, this, SLOT(handleSave()));
|
|
142 |
menu->setPreferredPos(position);
|
|
143 |
menu->show();
|
|
144 |
}
|
|
145 |
|
|
146 |
//----------------------------------------------------------------------------
|
|
147 |
// UniViewerAudioWidget::handleOpen
|
|
148 |
// @see header file
|
|
149 |
//----------------------------------------------------------------------------
|
|
150 |
void UniViewerAudioWidget::handleOpen()
|
|
151 |
{
|
|
152 |
this->ungrabGesture(Qt::TapGesture);
|
|
153 |
|
|
154 |
if (!mViewerUtils) {
|
|
155 |
mViewerUtils = new UniViewerUtils(this);
|
|
156 |
}
|
|
157 |
mViewerUtils->launchContentViewer(mMimeType, mMediaPath);
|
|
158 |
|
|
159 |
//fire timer to regrab gesture after some delay.
|
|
160 |
QTimer::singleShot(300,this,SLOT(regrabGesture()));
|
|
161 |
}
|
|
162 |
|
|
163 |
//----------------------------------------------------------------------------
|
|
164 |
// UniViewerAudioWidget::handleSave
|
|
165 |
// @see header file
|
|
166 |
//----------------------------------------------------------------------------
|
|
167 |
void UniViewerAudioWidget::handleSave()
|
|
168 |
{
|
|
169 |
|
|
170 |
}
|
|
171 |
|
|
172 |
//---------------------------------------------------------------
|
|
173 |
// UniViewerAudioWidget::regrabGesture
|
|
174 |
// @see header file
|
|
175 |
//---------------------------------------------------------------
|
|
176 |
void UniViewerAudioWidget::regrabGesture()
|
|
177 |
{
|
|
178 |
this->grabGesture(Qt::TapGesture);
|
|
179 |
}
|
|
180 |
// EOF
|