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 tone fetcher widget. |
|
16 * |
|
17 */ |
|
18 #include "tonefetcherwidget.h" |
|
19 #include "hbabstractviewitem.h" |
|
20 #include "hbstyle.h" |
|
21 #include "hbabstractitemview.h" |
|
22 #include <hblistview.h> |
|
23 #include <hbmenu.h> |
|
24 #include <hbaction.h> |
|
25 #include <QModelIndex> |
|
26 #include <QGraphicsLinearLayout> |
|
27 #include <QDirModel> |
|
28 #include <QTime> |
|
29 #include <QFileInfo> |
|
30 #include <QString> |
|
31 #include <QStandardItemModel> |
|
32 #include <XQUtils> |
|
33 #include <hblabel.h> |
|
34 #include "tonefetcherview.h" |
|
35 #include "tonefetchermodel.h" |
|
36 #include <hbmessagebox.h> |
|
37 #include <hbprogressdialog.h> |
|
38 |
|
39 ToneFetcherWidget::ToneFetcherWidget(HbWidget *parent, ToneFetcherView *serviceView) |
|
40 : HbWidget(parent), |
|
41 mLabel(0), |
|
42 mListView(0), |
|
43 mLayout(0), |
|
44 mToneModel(0), |
|
45 mServiceView(serviceView), |
|
46 mServiceEngine(0), |
|
47 mWaitNote(0) |
|
48 |
|
49 { |
|
50 init(); |
|
51 connect(mServiceEngine, SIGNAL(mdeSessionOpened()), |
|
52 this, SLOT(mdeSessionOpened())); |
|
53 connect(mServiceEngine, SIGNAL(mdeSessionError(int)), |
|
54 this, SLOT(mdeSessionError(int))); |
|
55 connect(mServiceEngine, SIGNAL(queryComplete(QStringList)), |
|
56 this, SLOT(queryComplete(QStringList))); |
|
57 connect(mServiceEngine, SIGNAL(queryError(int)), |
|
58 this, SLOT(queryError(int))); |
|
59 connect(mServiceEngine, |
|
60 SIGNAL(notifyPreviewEvent(int)), |
|
61 this, SLOT(previewEvent(int))); |
|
62 connect( mServiceEngine, SIGNAL(notifyObjectChanged()), |
|
63 this, SLOT(onObjectChanged())); |
|
64 } |
|
65 |
|
66 ToneFetcherWidget::~ToneFetcherWidget() |
|
67 { |
|
68 delete mToneModel; |
|
69 mToneModel = 0; |
|
70 delete mWaitNote; |
|
71 mWaitNote = 0; |
|
72 } |
|
73 |
|
74 void ToneFetcherWidget::on_list_activated(const QModelIndex &index) |
|
75 { |
|
76 //stop previewing when clicking another item. |
|
77 if (mServiceEngine->isPlaying()) { |
|
78 mServiceEngine->stopPlaying(); |
|
79 } |
|
80 /* |
|
81 * when one item is selected, reselecting it will deselect it. selecting another |
|
82 * will also deselect it, while the other is selected. |
|
83 */ |
|
84 QItemSelectionModel *selectionModel = mListView->selectionModel(); |
|
85 if (mOldSeletedItem == index) { |
|
86 selectionModel->select(index,QItemSelectionModel::Toggle); |
|
87 } |
|
88 |
|
89 QModelIndexList modelIndexList = selectionModel->selectedIndexes(); |
|
90 if (modelIndexList.isEmpty()) { |
|
91 mOldSeletedItem = QModelIndex(); |
|
92 } |
|
93 else { |
|
94 mOldSeletedItem = modelIndexList.front(); |
|
95 } |
|
96 emit triggerToolBar(selectionModel->hasSelection()); |
|
97 |
|
98 |
|
99 } |
|
100 |
|
101 void ToneFetcherWidget::init() |
|
102 { |
|
103 mLayout = new QGraphicsLinearLayout(this); |
|
104 mLayout->setOrientation(Qt::Vertical); |
|
105 setLayout(mLayout); |
|
106 |
|
107 mLabel = new HbLabel(this); |
|
108 mLabel->setPlainText(hbTrId("Select tone")); |
|
109 mLayout->addItem(mLabel); |
|
110 |
|
111 mListView = new HbListView(this); |
|
112 mListView->setObjectName("list"); |
|
113 mLayout->addItem(mListView); |
|
114 mListView->setSelectionMode(HbAbstractItemView::SingleSelection); |
|
115 |
|
116 mServiceEngine = new ToneFetcherEngine(this); |
|
117 mToneModel = new ToneFetcherModel(this); |
|
118 |
|
119 initRomSoundList(); |
|
120 |
|
121 connect(mListView, SIGNAL(activated(QModelIndex)), |
|
122 this, SLOT(on_list_activated(QModelIndex ))); |
|
123 if( !mWaitNote ){ |
|
124 mWaitNote = new HbProgressDialog( HbProgressDialog::WaitDialog ); |
|
125 mWaitNote->setText( hbTrId( "Refreshing..." ) ); |
|
126 QAction *action = mWaitNote->actions().at(0);//disable Cancel buttion. |
|
127 action->setEnabled(false); |
|
128 } |
|
129 } |
|
130 |
|
131 void ToneFetcherWidget::mdeSessionOpened() |
|
132 { |
|
133 mServiceEngine->getTones(); |
|
134 } |
|
135 |
|
136 void ToneFetcherWidget::queryComplete(const QStringList &uriList) |
|
137 { |
|
138 addFilesFromMDE(uriList); |
|
139 addFilesFromRom(); |
|
140 mToneModel->sort(); |
|
141 mToneModel->layoutHasChanged(); |
|
142 if (!mListView->model()) { |
|
143 mListView->setModel(mToneModel); |
|
144 } |
|
145 refreshFinish(); |
|
146 } |
|
147 |
|
148 void ToneFetcherWidget::queryError(int error) |
|
149 { |
|
150 Q_UNUSED(error); |
|
151 |
|
152 } |
|
153 |
|
154 void ToneFetcherWidget::mdeSessionError(int error) |
|
155 { |
|
156 Q_UNUSED(error); |
|
157 } |
|
158 |
|
159 QString ToneFetcherWidget::getCurrentItemPath() |
|
160 { |
|
161 QModelIndexList modelIndexList = mListView->selectionModel()->selectedIndexes(); |
|
162 if (modelIndexList.count() > 0) { |
|
163 QModelIndex index = modelIndexList.front(); |
|
164 QString path = mToneModel->getPath(index); |
|
165 return path; |
|
166 } |
|
167 return QString(); |
|
168 } |
|
169 |
|
170 void ToneFetcherWidget::playOrPause() |
|
171 { |
|
172 if(mServiceEngine->isPlaying()) { |
|
173 mServiceEngine->stopPlaying(); |
|
174 } else { |
|
175 mServiceEngine->play(getCurrentItemPath()); |
|
176 } |
|
177 |
|
178 } |
|
179 |
|
180 void ToneFetcherWidget::previewEvent(int event) |
|
181 { |
|
182 if (event == 0) { |
|
183 //preview successful, reserved |
|
184 } else { |
|
185 HbMessageBox::information(QString(hbTrId("Preview Error"))); |
|
186 } |
|
187 } |
|
188 |
|
189 void ToneFetcherWidget::onObjectChanged() |
|
190 { |
|
191 refreshStart(); |
|
192 if (mServiceEngine->isPlaying()) { |
|
193 mServiceEngine->stopPlaying(); |
|
194 } |
|
195 mToneModel->layoutToBeChanged(); |
|
196 emit triggerToolBar(false); |
|
197 mToneModel->removeRows(0, mToneModel->rowCount()); |
|
198 mServiceEngine->getTones(); |
|
199 } |
|
200 |
|
201 void ToneFetcherWidget::addFilesFromRom() |
|
202 { |
|
203 int currentCount = mToneModel->rowCount(); |
|
204 mToneModel->insertRows(currentCount, mRomSoundList.size()); |
|
205 for (int i = 0; i < mRomSoundList.size(); ++i) { |
|
206 mToneModel->setData(mToneModel->index(i + currentCount), |
|
207 QFileInfo(mRomSoundList.at(i)).absoluteFilePath()); |
|
208 } |
|
209 } |
|
210 |
|
211 void ToneFetcherWidget::addFilesFromMDE(const QStringList &uriList) |
|
212 { |
|
213 int currentCount = mToneModel->rowCount(); |
|
214 mToneModel->insertRows(currentCount, uriList.size()); |
|
215 for (int i = 0; i < uriList.size(); ++i) { |
|
216 mToneModel->setData(mToneModel->index(i + currentCount), QFileInfo(uriList.at(i)).absoluteFilePath()); |
|
217 } |
|
218 } |
|
219 |
|
220 void ToneFetcherWidget::refreshFinish() |
|
221 { |
|
222 if (mWaitNote) { |
|
223 mWaitNote->close(); |
|
224 } |
|
225 } |
|
226 |
|
227 void ToneFetcherWidget::refreshStart() |
|
228 { |
|
229 if (mWaitNote) { |
|
230 mWaitNote->open(); |
|
231 } |
|
232 } |
|
233 |
|
234 void ToneFetcherWidget::initRomSoundList() |
|
235 { |
|
236 QDir digitalSoundPath(XQUtils::romRootPath() + XQUtils::digitalSoundsPath()); |
|
237 QDir simpleSoundPath(XQUtils::romRootPath() + XQUtils::simpleSoundsPath()); |
|
238 mRomSoundList = digitalSoundPath.entryInfoList() + simpleSoundPath.entryInfoList(); |
|
239 } |
|
240 //End of File |
|