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