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