messagingapp/msgui/msgaudiofetcher/src/msgaudiofetcherview.cpp
changeset 37 518b245aa84c
child 48 4f501b74aeb1
equal deleted inserted replaced
25:84d9eb65b26f 37:518b245aa84c
       
     1 /*
       
     2  * Copyright (c) 2010 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  *     The source file for messaging's audio fetcher view.
       
    16  *
       
    17  */
       
    18 
       
    19 // SYSTEM INCLUDES
       
    20 #include <hbaction.h>
       
    21 #include <hbtoolbar.h>
       
    22 
       
    23 // USER INCLUDES
       
    24 #include "msgaudiofetcherview.h"
       
    25 #include "msgaudiofetcherwidget.h"
       
    26 #include "convergedmessage.h"
       
    27 
       
    28 MsgAudioFetcherView::MsgAudioFetcherView(const QVariantList& data) :
       
    29 message(NULL)
       
    30 {
       
    31     message = new ConvergedMessage;
       
    32     if(data.length() > 0)
       
    33     {
       
    34         QByteArray dataArray = data.at(0).toByteArray();
       
    35         QDataStream stream(&dataArray, QIODevice::ReadOnly);
       
    36         message->deserialize(stream);
       
    37     }
       
    38     initToolBar();
       
    39     initMainWidget();
       
    40     QMetaObject::connectSlotsByName(this);
       
    41 }
       
    42 
       
    43 MsgAudioFetcherView::~MsgAudioFetcherView()
       
    44 {
       
    45     if(message != NULL)
       
    46     {
       
    47         delete message;
       
    48         message = NULL;
       
    49     }
       
    50     removeToolBarAction();
       
    51 }
       
    52 
       
    53 void MsgAudioFetcherView::initMainWidget()
       
    54 {
       
    55     mWidget = new MsgAudioFetcherWidget();
       
    56     Q_ASSERT(mWidget);
       
    57     setWidget(mWidget);
       
    58     connect(mWidget, SIGNAL(triggerToolBar(bool)), this, SLOT(enableToolBar(bool)));
       
    59 }
       
    60 
       
    61 void MsgAudioFetcherView::initToolBar()
       
    62 {
       
    63     mToolBarLeftAction = new HbAction(this);
       
    64     mToolBarLeftAction->setObjectName("leftAction");
       
    65     //TODO: need localized string
       
    66     mToolBarLeftAction->setText(hbTrId("Play/Pause"));
       
    67     toolBar()->addAction(mToolBarLeftAction);
       
    68     mToolBarLeftAction->setEnabled(false);
       
    69 
       
    70     mToolBarRightAction = new HbAction(this);
       
    71     mToolBarRightAction->setObjectName("rightAction");
       
    72     //TODO: need localized string
       
    73     mToolBarRightAction->setText(hbTrId("Select"));
       
    74     mToolBarRightAction->setEnabled(false);
       
    75     toolBar()->addAction(mToolBarRightAction);
       
    76 
       
    77     toolBar()->setOrientation(Qt::Horizontal);
       
    78     toolBar()->setEnabled(false);
       
    79 }
       
    80 
       
    81 void MsgAudioFetcherView::removeToolBarAction()
       
    82 {
       
    83     toolBar()->removeAction(mToolBarRightAction);
       
    84     toolBar()->removeAction(mToolBarLeftAction);
       
    85 }
       
    86 
       
    87 void MsgAudioFetcherView::on_leftAction_triggered()
       
    88 {
       
    89     mWidget->playOrPause();
       
    90 }
       
    91 
       
    92 void MsgAudioFetcherView::on_rightAction_triggered()
       
    93 {    
       
    94     // param list for switching to editor view
       
    95     QVariantList params;
       
    96     QByteArray dataArray;
       
    97     QDataStream messageStream
       
    98     (&dataArray, QIODevice::WriteOnly | QIODevice::Append);
       
    99 
       
   100     QString filepath(mWidget->getCurrentItemPath());
       
   101     ConvergedMessageAttachment* attachment =
       
   102             new ConvergedMessageAttachment(filepath);
       
   103     ConvergedMessageAttachmentList attachmentList;
       
   104     attachmentList.append(attachment);
       
   105     message->addAttachments(attachmentList);
       
   106     
       
   107     message->serialize(messageStream);
       
   108     params << MsgBaseView::UNIEDITOR;
       
   109     params << MsgBaseView::AUDIOFETCHER;
       
   110     params << dataArray;
       
   111     params << MsgBaseView::ADD_AUDIO;
       
   112     emit switchView(params);
       
   113 }
       
   114 
       
   115 void MsgAudioFetcherView::enableToolBar(bool enable)
       
   116 {
       
   117     mToolBarRightAction->setEnabled(enable);
       
   118     mToolBarLeftAction->setEnabled(enable);
       
   119     toolBar()->setEnabled(enable);
       
   120 }
       
   121 
       
   122 //End of File