messagingapp/msgui/unifiededitor/src/msgunieditoraudiowidget.cpp
branchGCC_SURGE
changeset 47 5b14749788d7
parent 34 84197e66a4bd
child 51 3507212d340e
equal deleted inserted replaced
35:a32b19fb291e 47:5b14749788d7
       
     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 "msgunieditoraudiowidget.h"
       
    18 
       
    19 // SYSTEM INCLUDES
       
    20 #include <QFileInfo>
       
    21 #include <QTimer>
       
    22 #include <HbMenu>
       
    23 
       
    24 // USER INCLUDES
       
    25 #include "msgmediautil.h"
       
    26 #include "msgunieditorutils.h"
       
    27 
       
    28 // LOCAL CONSTANTS
       
    29 #define LOC_OPEN    hbTrId("txt_common_menu_open")
       
    30 #define LOC_REMOVE  hbTrId("txt_common_menu_remove")
       
    31 
       
    32 const QString AUDIO_ICON("qtg_mono_audio");
       
    33 const QString AUDIO_MIMETYPE("audio");
       
    34 
       
    35 //----------------------------------------------------------------------------
       
    36 // MsgUniFiedEditorAudioWidget::MsgUniFiedEditorAudioWidget
       
    37 // @see header file
       
    38 //----------------------------------------------------------------------------
       
    39 MsgUniFiedEditorAudioWidget::MsgUniFiedEditorAudioWidget(QGraphicsItem *parent) :
       
    40 HbPushButton(parent),
       
    41 mEditorUtils(0)
       
    42 {
       
    43     connect(this, SIGNAL(clicked()), this, SLOT(handleShortTap()));
       
    44     connect(this, SIGNAL(longPress(QPointF)), this, SLOT(handleLongTap(QPointF)));
       
    45 }
       
    46 
       
    47 //----------------------------------------------------------------------------
       
    48 // MsgUniFiedEditorAudioWidget::~MsgUniFiedEditorAudioWidget
       
    49 // @see header file
       
    50 //----------------------------------------------------------------------------
       
    51 MsgUniFiedEditorAudioWidget::~MsgUniFiedEditorAudioWidget()
       
    52 {
       
    53 }
       
    54 
       
    55 //----------------------------------------------------------------------------
       
    56 // MsgUniFiedEditorAudioWidget::~MsgUniFiedEditorAudioWidget
       
    57 // @see header file
       
    58 //----------------------------------------------------------------------------
       
    59 void MsgUniFiedEditorAudioWidget::populate(const QString &filePath)
       
    60 {
       
    61     mMediaPath = filePath;
       
    62 
       
    63     this->setIcon(HbIcon(AUDIO_ICON));
       
    64     QFileInfo fileInfo(mMediaPath);
       
    65     this->setText(fileInfo.baseName());    
       
    66     MsgMediaUtil mediaUtil;
       
    67     this->setAdditionalText(mediaUtil.mediaDuration(mMediaPath));
       
    68     this->setTextAlignment(Qt::AlignVCenter | Qt::AlignLeft);
       
    69 }
       
    70 
       
    71 //----------------------------------------------------------------------------
       
    72 // MsgUniFiedEditorAudioWidget::handleShortTap
       
    73 // @see header file
       
    74 //----------------------------------------------------------------------------
       
    75 void MsgUniFiedEditorAudioWidget::handleShortTap()
       
    76 {
       
    77     emit shortTap(mMediaPath);
       
    78 
       
    79     // Open the media.
       
    80     handleOpen();
       
    81 }
       
    82 
       
    83 //----------------------------------------------------------------------------
       
    84 // MsgUniFiedEditorAudioWidget::handleLongTap
       
    85 // @see header file
       
    86 //----------------------------------------------------------------------------
       
    87 void MsgUniFiedEditorAudioWidget::handleLongTap(const QPointF &position)
       
    88 {
       
    89     emit longTap(position);
       
    90 
       
    91     // Display context sensitive menu.
       
    92     HbMenu* menu = new HbMenu;
       
    93     menu->setAttribute(Qt::WA_DeleteOnClose);
       
    94     menu->setDismissPolicy(HbPopup::TapAnywhere);
       
    95     
       
    96     menu->addAction(LOC_OPEN, this, SLOT(handleOpen()));
       
    97     menu->addAction(LOC_REMOVE, this, SLOT(handleRemove()));
       
    98     menu->setPreferredPos(position);
       
    99     menu->show();
       
   100 }
       
   101 
       
   102 //----------------------------------------------------------------------------
       
   103 // MsgUniFiedEditorAudioWidget::handleOpen
       
   104 // @see header file
       
   105 //----------------------------------------------------------------------------
       
   106 void MsgUniFiedEditorAudioWidget::handleOpen()
       
   107 {
       
   108     this->ungrabGesture(Qt::TapGesture);
       
   109     
       
   110     if (!mEditorUtils) 
       
   111     {
       
   112         mEditorUtils = new MsgUnifiedEditorUtils(this);
       
   113     }
       
   114     mEditorUtils->launchContentViewer(AUDIO_MIMETYPE, mMediaPath);
       
   115     
       
   116     //fire timer to regrab gesture after some delay.
       
   117     QTimer::singleShot(300,this,SLOT(regrabGesture()));
       
   118 }
       
   119 
       
   120 //----------------------------------------------------------------------------
       
   121 // MsgUniFiedEditorAudioWidget::handleRemove
       
   122 // @see header file
       
   123 //----------------------------------------------------------------------------
       
   124 void MsgUniFiedEditorAudioWidget::handleRemove()
       
   125 {
       
   126     emit remove();
       
   127 }
       
   128 
       
   129 //---------------------------------------------------------------
       
   130 // MsgUniFiedEditorAudioWidget::regrabGesture
       
   131 // @see header file
       
   132 //---------------------------------------------------------------
       
   133 void MsgUniFiedEditorAudioWidget::regrabGesture()
       
   134 {
       
   135     this->grabGesture(Qt::TapGesture);
       
   136 }
       
   137 // EOF