messagingapp/msgui/msgaudiofetcher/src/msgaudiofetcherwidget.cpp
author hgs
Fri, 25 Jun 2010 15:47:40 +0530
changeset 37 518b245aa84c
child 46 b1f0785c289d
permissions -rw-r--r--
201025
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:
hgs
parents:
diff changeset
    15
 *     The source file for messaging's audio fetcher widget.
hgs
parents:
diff changeset
    16
 *
hgs
parents:
diff changeset
    17
 */
hgs
parents:
diff changeset
    18
hgs
parents:
diff changeset
    19
// SYSTEM INCLUDES
hgs
parents:
diff changeset
    20
#include <HbListView>
hgs
parents:
diff changeset
    21
#include <QModelIndex>
hgs
parents:
diff changeset
    22
#include <QGraphicsLinearLayout>
hgs
parents:
diff changeset
    23
#include <QStandardItemModel>
hgs
parents:
diff changeset
    24
#include <HbLabel>
hgs
parents:
diff changeset
    25
hgs
parents:
diff changeset
    26
// USER INCLUDES
hgs
parents:
diff changeset
    27
#include "msgaudiofetcherwidget.h"
hgs
parents:
diff changeset
    28
#include "msgaudiofetchermodel.h"
hgs
parents:
diff changeset
    29
#include "msgaudiopreview.h"
hgs
parents:
diff changeset
    30
hgs
parents:
diff changeset
    31
// LOCALIZED CONSTANTS
hgs
parents:
diff changeset
    32
#define LOC_SELECT_SOUND  hbTrId("txt_messaging_title_select_a_sound")
hgs
parents:
diff changeset
    33
hgs
parents:
diff changeset
    34
hgs
parents:
diff changeset
    35
MsgAudioFetcherWidget::MsgAudioFetcherWidget()
hgs
parents:
diff changeset
    36
    : HbWidget(this),
hgs
parents:
diff changeset
    37
      mLabel(0),
hgs
parents:
diff changeset
    38
      mListView(0),
hgs
parents:
diff changeset
    39
      mLayout(0),
hgs
parents:
diff changeset
    40
      mFetcherModel(0),
hgs
parents:
diff changeset
    41
      mAudioPreview(0),
hgs
parents:
diff changeset
    42
      mSelected(false)
hgs
parents:
diff changeset
    43
{
hgs
parents:
diff changeset
    44
    init();
hgs
parents:
diff changeset
    45
}
hgs
parents:
diff changeset
    46
hgs
parents:
diff changeset
    47
MsgAudioFetcherWidget::~MsgAudioFetcherWidget()
hgs
parents:
diff changeset
    48
{
hgs
parents:
diff changeset
    49
}
hgs
parents:
diff changeset
    50
hgs
parents:
diff changeset
    51
QString MsgAudioFetcherWidget::getCurrentItemPath()
hgs
parents:
diff changeset
    52
{
hgs
parents:
diff changeset
    53
    QModelIndexList modelIndexList = mListView->selectionModel()->selectedIndexes();
hgs
parents:
diff changeset
    54
    if(modelIndexList.count() > 0)
hgs
parents:
diff changeset
    55
    {
hgs
parents:
diff changeset
    56
        QModelIndex index = modelIndexList.at(0);
hgs
parents:
diff changeset
    57
        QString temppath = 
hgs
parents:
diff changeset
    58
                mFetcherModel->data(index, Qt::UserRole).toString();
hgs
parents:
diff changeset
    59
        return QDir::toNativeSeparators(temppath);
hgs
parents:
diff changeset
    60
    }
hgs
parents:
diff changeset
    61
    return QString();
hgs
parents:
diff changeset
    62
}
hgs
parents:
diff changeset
    63
hgs
parents:
diff changeset
    64
void MsgAudioFetcherWidget::playOrPause()
hgs
parents:
diff changeset
    65
{
hgs
parents:
diff changeset
    66
    mAudioPreview->SetAttr(getCurrentItemPath());
hgs
parents:
diff changeset
    67
    mAudioPreview->Play();
hgs
parents:
diff changeset
    68
}
hgs
parents:
diff changeset
    69
hgs
parents:
diff changeset
    70
void MsgAudioFetcherWidget::on_list_activated(const QModelIndex &index)
hgs
parents:
diff changeset
    71
{
hgs
parents:
diff changeset
    72
    QModelIndexList modelIndexList = mListView->selectionModel()->selectedIndexes();
hgs
parents:
diff changeset
    73
hgs
parents:
diff changeset
    74
    //stop previewing when clicking another item.
hgs
parents:
diff changeset
    75
    if (mAudioPreview->IsPlaying()) {
hgs
parents:
diff changeset
    76
        mAudioPreview->SetAttr(getCurrentItemPath());
hgs
parents:
diff changeset
    77
            mAudioPreview->Play();
hgs
parents:
diff changeset
    78
        
hgs
parents:
diff changeset
    79
    }
hgs
parents:
diff changeset
    80
hgs
parents:
diff changeset
    81
    /*
hgs
parents:
diff changeset
    82
     * when one item is selected, reselecting it will deselect it. selecting another
hgs
parents:
diff changeset
    83
     * will also deselect it, while the other is selected.
hgs
parents:
diff changeset
    84
     */
hgs
parents:
diff changeset
    85
    if(mSelected)
hgs
parents:
diff changeset
    86
    {
hgs
parents:
diff changeset
    87
        if(mOldSeletedItem != index)
hgs
parents:
diff changeset
    88
        {
hgs
parents:
diff changeset
    89
            mListView->selectionModel()->select(index, QItemSelectionModel::Select);
hgs
parents:
diff changeset
    90
            mOldSeletedItem = index;
hgs
parents:
diff changeset
    91
            emit triggerToolBar(true);
hgs
parents:
diff changeset
    92
        }
hgs
parents:
diff changeset
    93
        else
hgs
parents:
diff changeset
    94
        {
hgs
parents:
diff changeset
    95
            mListView->selectionModel()->select(index, QItemSelectionModel::Deselect);
hgs
parents:
diff changeset
    96
            mSelected = false;
hgs
parents:
diff changeset
    97
            emit triggerToolBar(false);
hgs
parents:
diff changeset
    98
        }
hgs
parents:
diff changeset
    99
        return;
hgs
parents:
diff changeset
   100
    }
hgs
parents:
diff changeset
   101
hgs
parents:
diff changeset
   102
    if(modelIndexList.count() > 0)
hgs
parents:
diff changeset
   103
    {
hgs
parents:
diff changeset
   104
		QModelIndexList::const_iterator it;
hgs
parents:
diff changeset
   105
        for(it=modelIndexList.begin(); it!=modelIndexList.end(); ++it)
hgs
parents:
diff changeset
   106
        {
hgs
parents:
diff changeset
   107
            if((*it) == index)
hgs
parents:
diff changeset
   108
            {
hgs
parents:
diff changeset
   109
                mSelected = true;
hgs
parents:
diff changeset
   110
                mOldSeletedItem = index;
hgs
parents:
diff changeset
   111
                emit triggerToolBar(true);
hgs
parents:
diff changeset
   112
            }
hgs
parents:
diff changeset
   113
        }
hgs
parents:
diff changeset
   114
    }
hgs
parents:
diff changeset
   115
}
hgs
parents:
diff changeset
   116
hgs
parents:
diff changeset
   117
void MsgAudioFetcherWidget::init()
hgs
parents:
diff changeset
   118
{
hgs
parents:
diff changeset
   119
    mLayout = new QGraphicsLinearLayout(this);
hgs
parents:
diff changeset
   120
    mLayout->setOrientation(Qt::Vertical);
hgs
parents:
diff changeset
   121
    setLayout(mLayout);
hgs
parents:
diff changeset
   122
hgs
parents:
diff changeset
   123
    mLabel = new HbLabel(this);
hgs
parents:
diff changeset
   124
    // TODO: need localized string
hgs
parents:
diff changeset
   125
    mLabel->setPlainText(LOC_SELECT_SOUND);
hgs
parents:
diff changeset
   126
    mLayout->addItem(mLabel);
hgs
parents:
diff changeset
   127
hgs
parents:
diff changeset
   128
    mListView = new HbListView(this);
hgs
parents:
diff changeset
   129
    mListView->setObjectName("list");
hgs
parents:
diff changeset
   130
    mLayout->addItem(mListView);
hgs
parents:
diff changeset
   131
    mListView->setSelectionMode(HbAbstractItemView::SingleSelection);
hgs
parents:
diff changeset
   132
hgs
parents:
diff changeset
   133
    mFetcherModel = new MsgAudioFetcherModel(this);
hgs
parents:
diff changeset
   134
    mListView->setModel(mFetcherModel);
hgs
parents:
diff changeset
   135
    connect(mListView, SIGNAL(activated(QModelIndex)),
hgs
parents:
diff changeset
   136
        this, SLOT(on_list_activated(QModelIndex)));
hgs
parents:
diff changeset
   137
    mAudioPreview = new MsgAudioPreview(this);
hgs
parents:
diff changeset
   138
}
hgs
parents:
diff changeset
   139
hgs
parents:
diff changeset
   140
//End of File