messagingapp/msgui/unifiedviewer/src/univieweraudiowidget.cpp
author hgs
Tue, 31 Aug 2010 18:53:38 +0530
changeset 56 f42d9a78f435
parent 51 3507212d340e
child 62 fdbe8253b596
permissions -rw-r--r--
201033_02
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37
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: This widget is used to display audio content in univiewer.
hgs
parents:
diff changeset
    15
 *
hgs
parents:
diff changeset
    16
 */
hgs
parents:
diff changeset
    17
#include "univieweraudiowidget.h"
hgs
parents:
diff changeset
    18
hgs
parents:
diff changeset
    19
// SYSTEM INCLUDES
hgs
parents:
diff changeset
    20
#include <QFileInfo>
hgs
parents:
diff changeset
    21
#include <QTimer>
hgs
parents:
diff changeset
    22
#include <HbMenu>
hgs
parents:
diff changeset
    23
hgs
parents:
diff changeset
    24
// USER INCLUDES
hgs
parents:
diff changeset
    25
#include "msgmediautil.h"
hgs
parents:
diff changeset
    26
#include "univiewerutils.h"
hgs
parents:
diff changeset
    27
#include "unidatamodelplugininterface.h"
hgs
parents:
diff changeset
    28
hgs
parents:
diff changeset
    29
// LOCAL CONSTANTS
hgs
parents:
diff changeset
    30
#define LOC_OPEN    hbTrId("txt_common_menu_open")
hgs
parents:
diff changeset
    31
#define LOC_SAVE    hbTrId("txt_common_menu_save")
hgs
parents:
diff changeset
    32
51
3507212d340e 201031_02
hgs
parents: 37
diff changeset
    33
static const char VIDEO_MIMETYPE[] = "video";
3507212d340e 201031_02
hgs
parents: 37
diff changeset
    34
static const char AUDIO_ICON[] = "qtg_mono_audio";
3507212d340e 201031_02
hgs
parents: 37
diff changeset
    35
static const char VIDEO_ICON[] = "qtg_mono_video";
3507212d340e 201031_02
hgs
parents: 37
diff changeset
    36
static const char CORRUPTED_AUDIO_ICON[] = "qtg_mono_corrupted";
37
hgs
parents:
diff changeset
    37
hgs
parents:
diff changeset
    38
//----------------------------------------------------------------------------
hgs
parents:
diff changeset
    39
// UniViewerAudioWidget::UniViewerAudioWidget
hgs
parents:
diff changeset
    40
// @see header file
hgs
parents:
diff changeset
    41
//----------------------------------------------------------------------------
hgs
parents:
diff changeset
    42
UniViewerAudioWidget::UniViewerAudioWidget(QGraphicsItem *parent) :
51
3507212d340e 201031_02
hgs
parents: 37
diff changeset
    43
    HbPushButton(parent), mViewerUtils(0), mValidMediaDuration(true)
37
hgs
parents:
diff changeset
    44
{
hgs
parents:
diff changeset
    45
    connect(this, SIGNAL(clicked()), this, SLOT(handleShortTap()));
hgs
parents:
diff changeset
    46
    connect(this, SIGNAL(longPress(QPointF)), this, SLOT(handleLongTap(QPointF)));
hgs
parents:
diff changeset
    47
}
hgs
parents:
diff changeset
    48
hgs
parents:
diff changeset
    49
//----------------------------------------------------------------------------
hgs
parents:
diff changeset
    50
// UniViewerAudioWidget::~UniViewerAudioWidget
hgs
parents:
diff changeset
    51
// @see header file
hgs
parents:
diff changeset
    52
//----------------------------------------------------------------------------
hgs
parents:
diff changeset
    53
UniViewerAudioWidget::~UniViewerAudioWidget()
hgs
parents:
diff changeset
    54
{
hgs
parents:
diff changeset
    55
}
hgs
parents:
diff changeset
    56
hgs
parents:
diff changeset
    57
//----------------------------------------------------------------------------
hgs
parents:
diff changeset
    58
// UniViewerAudioWidget::~UniViewerAudioWidget
hgs
parents:
diff changeset
    59
// @see header file
hgs
parents:
diff changeset
    60
//----------------------------------------------------------------------------
hgs
parents:
diff changeset
    61
void UniViewerAudioWidget::populate(UniMessageInfo *info)
hgs
parents:
diff changeset
    62
{
hgs
parents:
diff changeset
    63
    mMimeType = info->mimetype();
hgs
parents:
diff changeset
    64
    mMediaPath = info->path();
hgs
parents:
diff changeset
    65
hgs
parents:
diff changeset
    66
    HbIcon audioIcon;
51
3507212d340e 201031_02
hgs
parents: 37
diff changeset
    67
37
hgs
parents:
diff changeset
    68
    if (info->isProtected()) {
51
3507212d340e 201031_02
hgs
parents: 37
diff changeset
    69
        if (mMimeType.contains(VIDEO_MIMETYPE)) {
3507212d340e 201031_02
hgs
parents: 37
diff changeset
    70
            audioIcon.setIconName(VIDEO_ICON);
3507212d340e 201031_02
hgs
parents: 37
diff changeset
    71
        }
3507212d340e 201031_02
hgs
parents: 37
diff changeset
    72
        else {
3507212d340e 201031_02
hgs
parents: 37
diff changeset
    73
            audioIcon.setIconName(AUDIO_ICON);
3507212d340e 201031_02
hgs
parents: 37
diff changeset
    74
        }
37
hgs
parents:
diff changeset
    75
    }
hgs
parents:
diff changeset
    76
    else if (info->isCorrupted()) {
hgs
parents:
diff changeset
    77
        audioIcon.setIconName(CORRUPTED_AUDIO_ICON);
hgs
parents:
diff changeset
    78
    }
hgs
parents:
diff changeset
    79
    else {
51
3507212d340e 201031_02
hgs
parents: 37
diff changeset
    80
        if (mMimeType.contains(VIDEO_MIMETYPE)) {
3507212d340e 201031_02
hgs
parents: 37
diff changeset
    81
            audioIcon.setIconName(VIDEO_ICON);
3507212d340e 201031_02
hgs
parents: 37
diff changeset
    82
        }
3507212d340e 201031_02
hgs
parents: 37
diff changeset
    83
        else {
3507212d340e 201031_02
hgs
parents: 37
diff changeset
    84
            audioIcon.setIconName(AUDIO_ICON);
3507212d340e 201031_02
hgs
parents: 37
diff changeset
    85
        }
37
hgs
parents:
diff changeset
    86
    }
hgs
parents:
diff changeset
    87
hgs
parents:
diff changeset
    88
    this->setIcon(audioIcon);
hgs
parents:
diff changeset
    89
    QFileInfo fileInfo(mMediaPath);
hgs
parents:
diff changeset
    90
    this->setText(fileInfo.baseName());
hgs
parents:
diff changeset
    91
    this->setTextAlignment(Qt::AlignLeft);
hgs
parents:
diff changeset
    92
    MsgMediaUtil mediaUtil;
51
3507212d340e 201031_02
hgs
parents: 37
diff changeset
    93
    QString mediaDuration(mediaUtil.mediaDuration(mMediaPath));
3507212d340e 201031_02
hgs
parents: 37
diff changeset
    94
    if (mediaDuration.isEmpty()) {
3507212d340e 201031_02
hgs
parents: 37
diff changeset
    95
        mValidMediaDuration = false;
3507212d340e 201031_02
hgs
parents: 37
diff changeset
    96
    }
3507212d340e 201031_02
hgs
parents: 37
diff changeset
    97
    else {
3507212d340e 201031_02
hgs
parents: 37
diff changeset
    98
        mValidMediaDuration = true;
3507212d340e 201031_02
hgs
parents: 37
diff changeset
    99
        this->setAdditionalText(mediaDuration);
3507212d340e 201031_02
hgs
parents: 37
diff changeset
   100
    }
3507212d340e 201031_02
hgs
parents: 37
diff changeset
   101
}
3507212d340e 201031_02
hgs
parents: 37
diff changeset
   102
3507212d340e 201031_02
hgs
parents: 37
diff changeset
   103
//----------------------------------------------------------------------------
3507212d340e 201031_02
hgs
parents: 37
diff changeset
   104
// UniViewerAudioWidget::setStretched
3507212d340e 201031_02
hgs
parents: 37
diff changeset
   105
// @see header file
3507212d340e 201031_02
hgs
parents: 37
diff changeset
   106
//----------------------------------------------------------------------------
3507212d340e 201031_02
hgs
parents: 37
diff changeset
   107
void UniViewerAudioWidget::setStretched(bool stretched)
3507212d340e 201031_02
hgs
parents: 37
diff changeset
   108
{
3507212d340e 201031_02
hgs
parents: 37
diff changeset
   109
    if (mValidMediaDuration) {
3507212d340e 201031_02
hgs
parents: 37
diff changeset
   110
        HbPushButton::setStretched(stretched);
3507212d340e 201031_02
hgs
parents: 37
diff changeset
   111
    }
3507212d340e 201031_02
hgs
parents: 37
diff changeset
   112
    else {
3507212d340e 201031_02
hgs
parents: 37
diff changeset
   113
        HbPushButton::setStretched(true);
3507212d340e 201031_02
hgs
parents: 37
diff changeset
   114
    }
37
hgs
parents:
diff changeset
   115
}
hgs
parents:
diff changeset
   116
hgs
parents:
diff changeset
   117
//----------------------------------------------------------------------------
hgs
parents:
diff changeset
   118
// UniViewerAudioWidget::handleShortTap
hgs
parents:
diff changeset
   119
// @see header file
hgs
parents:
diff changeset
   120
//----------------------------------------------------------------------------
hgs
parents:
diff changeset
   121
void UniViewerAudioWidget::handleShortTap()
hgs
parents:
diff changeset
   122
{
hgs
parents:
diff changeset
   123
    emit shortTap(mMediaPath);
hgs
parents:
diff changeset
   124
hgs
parents:
diff changeset
   125
    // Open the media.
hgs
parents:
diff changeset
   126
    handleOpen();
hgs
parents:
diff changeset
   127
}
hgs
parents:
diff changeset
   128
hgs
parents:
diff changeset
   129
//----------------------------------------------------------------------------
hgs
parents:
diff changeset
   130
// UniViewerAudioWidget::handleLongTap
hgs
parents:
diff changeset
   131
// @see header file
hgs
parents:
diff changeset
   132
//----------------------------------------------------------------------------
hgs
parents:
diff changeset
   133
void UniViewerAudioWidget::handleLongTap(const QPointF &position)
hgs
parents:
diff changeset
   134
{
hgs
parents:
diff changeset
   135
    emit longTap(position);
hgs
parents:
diff changeset
   136
hgs
parents:
diff changeset
   137
    // Display context sensitive menu.
hgs
parents:
diff changeset
   138
    HbMenu* menu = new HbMenu;
hgs
parents:
diff changeset
   139
    menu->setAttribute(Qt::WA_DeleteOnClose);
hgs
parents:
diff changeset
   140
    menu->addAction(LOC_OPEN, this, SLOT(handleOpen()));
hgs
parents:
diff changeset
   141
    menu->addAction(LOC_SAVE, this, SLOT(handleSave()));
hgs
parents:
diff changeset
   142
    menu->setPreferredPos(position);
hgs
parents:
diff changeset
   143
    menu->show();
hgs
parents:
diff changeset
   144
}
hgs
parents:
diff changeset
   145
hgs
parents:
diff changeset
   146
//----------------------------------------------------------------------------
hgs
parents:
diff changeset
   147
// UniViewerAudioWidget::handleOpen
hgs
parents:
diff changeset
   148
// @see header file
hgs
parents:
diff changeset
   149
//----------------------------------------------------------------------------
hgs
parents:
diff changeset
   150
void UniViewerAudioWidget::handleOpen()
hgs
parents:
diff changeset
   151
{
hgs
parents:
diff changeset
   152
    this->ungrabGesture(Qt::TapGesture);
hgs
parents:
diff changeset
   153
    
hgs
parents:
diff changeset
   154
    if (!mViewerUtils) {
hgs
parents:
diff changeset
   155
        mViewerUtils = new UniViewerUtils(this);
hgs
parents:
diff changeset
   156
    }
hgs
parents:
diff changeset
   157
    mViewerUtils->launchContentViewer(mMimeType, mMediaPath);
hgs
parents:
diff changeset
   158
    
hgs
parents:
diff changeset
   159
    //fire timer to regrab gesture after some delay.
hgs
parents:
diff changeset
   160
    QTimer::singleShot(300,this,SLOT(regrabGesture()));
hgs
parents:
diff changeset
   161
}
hgs
parents:
diff changeset
   162
hgs
parents:
diff changeset
   163
//----------------------------------------------------------------------------
hgs
parents:
diff changeset
   164
// UniViewerAudioWidget::handleSave
hgs
parents:
diff changeset
   165
// @see header file
hgs
parents:
diff changeset
   166
//----------------------------------------------------------------------------
hgs
parents:
diff changeset
   167
void UniViewerAudioWidget::handleSave()
hgs
parents:
diff changeset
   168
{
hgs
parents:
diff changeset
   169
hgs
parents:
diff changeset
   170
}
hgs
parents:
diff changeset
   171
hgs
parents:
diff changeset
   172
//---------------------------------------------------------------
hgs
parents:
diff changeset
   173
// UniViewerAudioWidget::regrabGesture
hgs
parents:
diff changeset
   174
// @see header file
hgs
parents:
diff changeset
   175
//---------------------------------------------------------------
hgs
parents:
diff changeset
   176
void UniViewerAudioWidget::regrabGesture()
hgs
parents:
diff changeset
   177
{
hgs
parents:
diff changeset
   178
    this->grabGesture(Qt::TapGesture);
hgs
parents:
diff changeset
   179
}
hgs
parents:
diff changeset
   180
// EOF