16
|
1 |
#include <QModelIndex>
|
|
2 |
#include <QDirModel>
|
|
3 |
#include <QApplication>
|
|
4 |
|
|
5 |
//#include <hbformitem.h>
|
|
6 |
//#include <hbformview.h>
|
|
7 |
#include <hblistview.h>
|
|
8 |
#include <hblistviewitem.h>
|
|
9 |
#include <hbmenu.h>
|
|
10 |
#include <hbmainwindow.h>
|
|
11 |
|
|
12 |
#include <QDebug>
|
|
13 |
#include <QAction>
|
|
14 |
#include <HbAction>
|
|
15 |
#include "folderview.h"
|
|
16 |
#include "views.h"
|
|
17 |
#include <HbAbstractViewItem>
|
|
18 |
#include <QTimer>
|
|
19 |
#include <hbnotificationdialog.h>
|
|
20 |
/*! Constructor of FolderView.
|
|
21 |
*/
|
|
22 |
#ifdef __cplusplus
|
|
23 |
extern "C"
|
|
24 |
{
|
|
25 |
#endif
|
|
26 |
|
|
27 |
int mCurrentState = 0;
|
|
28 |
|
|
29 |
#ifdef __cplusplus
|
|
30 |
}
|
|
31 |
#endif
|
|
32 |
//extern int mCurrentState;
|
|
33 |
|
|
34 |
FolderView::FolderView(QGraphicsItem *parent)
|
|
35 |
: HbView(parent),mModel( NULL ), mFolderPath("c:\\data\\Sounds\\Digital\\"),mTimer(NULL),mIsRecording( FALSE )
|
|
36 |
{
|
|
37 |
mCurrentState = NONE;
|
|
38 |
|
|
39 |
// Create a main widget for this view
|
|
40 |
// In this case, list view is appropriate
|
|
41 |
// Note: HbListView is not derived from HbView,
|
|
42 |
// this is just like any other Hb widget but with a feature of
|
|
43 |
// model-view separation
|
|
44 |
mFileList = new HbListView(this);
|
|
45 |
|
|
46 |
// Create a model to set for the list view
|
|
47 |
mModel = new QDirModel(this);
|
|
48 |
mFileList->setModel(mModel);
|
|
49 |
|
|
50 |
// Setting initial path for folder list
|
|
51 |
mFileList->setRootIndex(mModel->index(mFolderPath));
|
|
52 |
//mFileList->
|
|
53 |
// Setting the main widget for this view
|
|
54 |
setWidget(mFileList);
|
|
55 |
//int x = mFileList->indexCount();
|
|
56 |
QObject::connect(mFileList, SIGNAL(pressed(const QModelIndex)), this, SLOT(item_pressed(const QModelIndex)));
|
|
57 |
|
|
58 |
// add menu
|
|
59 |
HbMenu* menu1 = menu()->addMenu(tr("Record"));
|
|
60 |
|
|
61 |
HbAction* menu1_Action = new HbAction(tr("RAW"), this);
|
|
62 |
connect(menu1_Action, SIGNAL(triggered()), this, SLOT(record_RAW()));
|
|
63 |
menu1->addAction( menu1_Action );
|
|
64 |
|
|
65 |
menu1_Action = new HbAction(tr("WAV"), this);
|
|
66 |
connect(menu1_Action, SIGNAL(triggered()), this, SLOT(record_WAV()));
|
|
67 |
menu1->addAction( menu1_Action );
|
|
68 |
|
|
69 |
//create action Nokia India sub menu item.
|
|
70 |
menu1_Action = new HbAction(tr("AMR"), this);
|
|
71 |
connect(menu1_Action, SIGNAL(triggered()), this, SLOT(record_AMR()));
|
|
72 |
menu1->addAction( menu1_Action );
|
|
73 |
|
|
74 |
menu1_Action = new HbAction(tr("G711"), this);
|
|
75 |
connect(menu1_Action, SIGNAL(triggered()), this, SLOT(record_G711()));
|
|
76 |
menu1->addAction( menu1_Action );
|
|
77 |
|
|
78 |
menu1_Action = new HbAction(tr("AAC"), this);
|
|
79 |
connect(menu1_Action, SIGNAL(triggered()), this, SLOT(record_AAC()));
|
|
80 |
menu1->addAction( menu1_Action );
|
|
81 |
menu1_Action = new HbAction(tr("G729"), this);
|
|
82 |
connect(menu1_Action, SIGNAL(triggered()), this, SLOT(record_G729()));
|
|
83 |
menu1->addAction( menu1_Action );
|
|
84 |
|
|
85 |
menu1_Action = new HbAction(tr("ILBC"), this);
|
|
86 |
connect(menu1_Action, SIGNAL(triggered()), this, SLOT(record_ILBC()));
|
|
87 |
menu1->addAction( menu1_Action );
|
|
88 |
|
|
89 |
|
|
90 |
|
|
91 |
//menu()->addAction(tr("Play"), this, SLOT(play()));
|
|
92 |
menu()->addAction(tr("Stop"), this, SLOT(stop()));
|
|
93 |
menu()->addAction(tr("Pause"), this, SLOT(pause()));
|
|
94 |
menu()->addAction(tr("Resume"), this, SLOT(resume()));
|
|
95 |
menu()->addAction(tr("Exit"), qApp, SLOT(quit()));
|
|
96 |
|
|
97 |
|
|
98 |
/// timer required to get the glib events
|
|
99 |
mTimer = new QTimer(this);
|
|
100 |
connect(mTimer, SIGNAL(timeout()), this, SLOT(timertimeout()));
|
|
101 |
mTimer->start(10);
|
|
102 |
|
|
103 |
}
|
|
104 |
|
|
105 |
FolderView::~FolderView()
|
|
106 |
{
|
|
107 |
if(mCurrentState != NONE)
|
|
108 |
gst_unref();
|
|
109 |
delete mFileList;
|
|
110 |
delete mModel;
|
|
111 |
mTimer->stop();
|
|
112 |
delete mTimer;
|
|
113 |
}
|
|
114 |
|
|
115 |
|
|
116 |
void FolderView::folderViewTriggered()
|
|
117 |
{
|
|
118 |
mainWindow()->setCurrentView(Views::folderView());
|
|
119 |
}
|
|
120 |
|
|
121 |
/*void FolderView::settingsViewTriggered()
|
|
122 |
{
|
|
123 |
mainWindow()->setCurrentView(Views::settingsView());
|
|
124 |
}*/
|
|
125 |
|
|
126 |
void FolderView::showNote(const int err)
|
|
127 |
{
|
|
128 |
if(err)
|
|
129 |
{
|
|
130 |
HbNotificationDialog* notifyDialog = new HbNotificationDialog;
|
|
131 |
notifyDialog->setTimeout(HbPopup::StandardTimeout);
|
|
132 |
QString strong;
|
|
133 |
QString sprint= strong.sprintf("Format Not supported(%d)",err);
|
|
134 |
notifyDialog->setTitleTextWrapping(Hb::TextWordWrap);
|
|
135 |
notifyDialog->setTitle(QString("Error"));
|
|
136 |
notifyDialog->setWrapMode(Hb::TextWordWrap);
|
|
137 |
notifyDialog->setText(sprint);
|
|
138 |
|
|
139 |
notifyDialog->exec();
|
|
140 |
delete notifyDialog;
|
|
141 |
}
|
|
142 |
}
|
|
143 |
void FolderView::item_pressed(const QModelIndex &index)
|
|
144 |
{
|
|
145 |
if( mIsRecording )
|
|
146 |
{
|
|
147 |
return;
|
|
148 |
}
|
|
149 |
QVariant variant=index.data();
|
|
150 |
QString str = variant.toString();
|
|
151 |
|
|
152 |
|
|
153 |
QString fullpath = mFolderPath;
|
|
154 |
fullpath.append( str );
|
|
155 |
|
|
156 |
TBuf16<1024> buf16;
|
|
157 |
buf16.Copy( (TUint16*)fullpath.data_ptr()->data ,fullpath.data_ptr()->size );
|
|
158 |
TBuf8<1024> buf8;
|
|
159 |
buf8.Copy( buf16 );
|
|
160 |
|
|
161 |
if( NONE != mCurrentState )
|
|
162 |
{
|
|
163 |
gst_unref();
|
|
164 |
}
|
|
165 |
|
|
166 |
int err = gst_play_file( (char*)buf8.PtrZ() );
|
|
167 |
if(err)
|
|
168 |
{
|
|
169 |
showNote(err);
|
|
170 |
mCurrentState = NONE;
|
|
171 |
}
|
|
172 |
else
|
|
173 |
{
|
|
174 |
mCurrentState = PLAYING;
|
|
175 |
}
|
|
176 |
|
|
177 |
}
|
|
178 |
void FolderView::pause()
|
|
179 |
{
|
|
180 |
if( PLAYING == mCurrentState ){
|
|
181 |
gst_pause();
|
|
182 |
mCurrentState = PAUSE;
|
|
183 |
}
|
|
184 |
}
|
|
185 |
|
|
186 |
void FolderView::resume()
|
|
187 |
{
|
|
188 |
if( PAUSE == mCurrentState ){
|
|
189 |
gst_resume();
|
|
190 |
mCurrentState = PLAYING;
|
|
191 |
}
|
|
192 |
}
|
|
193 |
|
|
194 |
void FolderView::stop()
|
|
195 |
{
|
|
196 |
if( mIsRecording == TRUE )
|
|
197 |
{
|
|
198 |
gst_record_stop();
|
|
199 |
|
|
200 |
if( mModel )
|
|
201 |
delete mModel;
|
|
202 |
|
|
203 |
mModel = new QDirModel(this);
|
|
204 |
mFileList->setModel(mModel);
|
|
205 |
|
|
206 |
mFileList->reset();
|
|
207 |
mFileList->setRootIndex(mModel->index(mFolderPath));
|
|
208 |
// mFileList->show();
|
|
209 |
// int x = mFileList->indexCount();
|
|
210 |
//setWidget(mFileList);
|
|
211 |
mIsRecording = FALSE;
|
|
212 |
return;
|
|
213 |
}
|
|
214 |
if( PLAYING == mCurrentState || PAUSE == mCurrentState ){
|
|
215 |
gst_unref();
|
|
216 |
mCurrentState = NONE;
|
|
217 |
}
|
|
218 |
}
|
|
219 |
|
|
220 |
void FolderView::record_AMR()
|
|
221 |
{
|
|
222 |
if( mCurrentState == NONE ){
|
|
223 |
int err = gst_record_file( RECORD_AMR );
|
|
224 |
if(err)
|
|
225 |
{
|
|
226 |
showNote(err);
|
|
227 |
mCurrentState = NONE;
|
|
228 |
mIsRecording = FALSE;
|
|
229 |
}
|
|
230 |
else
|
|
231 |
{
|
|
232 |
mCurrentState = PLAYING;
|
|
233 |
mIsRecording = TRUE;
|
|
234 |
}
|
|
235 |
}
|
|
236 |
}
|
|
237 |
|
|
238 |
void FolderView::record_WAV()
|
|
239 |
{
|
|
240 |
if( mCurrentState == NONE ){
|
|
241 |
int err = gst_record_file( RECORD_WAV );
|
|
242 |
if(err)
|
|
243 |
{
|
|
244 |
showNote(err);
|
|
245 |
mCurrentState = NONE;
|
|
246 |
mIsRecording = FALSE;
|
|
247 |
}
|
|
248 |
else
|
|
249 |
{
|
|
250 |
mCurrentState = PLAYING;
|
|
251 |
mIsRecording = TRUE;
|
|
252 |
}
|
|
253 |
//gst_record_wav();
|
|
254 |
}
|
|
255 |
}
|
|
256 |
|
|
257 |
void FolderView::record_RAW()
|
|
258 |
{
|
|
259 |
if( mCurrentState == NONE ){
|
|
260 |
int err = gst_record_file( RECORD_RAW );
|
|
261 |
if(err)
|
|
262 |
{
|
|
263 |
showNote(err);
|
|
264 |
mCurrentState = NONE;
|
|
265 |
mIsRecording = FALSE;
|
|
266 |
}
|
|
267 |
else
|
|
268 |
{
|
|
269 |
mCurrentState = PLAYING;
|
|
270 |
mIsRecording = TRUE;
|
|
271 |
}
|
|
272 |
}
|
|
273 |
}
|
|
274 |
|
|
275 |
void FolderView::record_G711()
|
|
276 |
{
|
|
277 |
if( mCurrentState == NONE ){
|
|
278 |
int err = gst_record_file( RECORD_G711 );
|
|
279 |
if(err)
|
|
280 |
{
|
|
281 |
showNote(err);
|
|
282 |
mCurrentState = NONE;
|
|
283 |
mIsRecording = FALSE;
|
|
284 |
}
|
|
285 |
else
|
|
286 |
{
|
|
287 |
mCurrentState = PLAYING;
|
|
288 |
mIsRecording = TRUE;
|
|
289 |
}
|
|
290 |
}
|
|
291 |
}
|
|
292 |
|
|
293 |
void FolderView::record_G729()
|
|
294 |
{
|
|
295 |
if( mCurrentState == NONE ){
|
|
296 |
int err = gst_record_file( RECORD_G729 );
|
|
297 |
if(err)
|
|
298 |
{
|
|
299 |
showNote(err);
|
|
300 |
mCurrentState = NONE;
|
|
301 |
mIsRecording = FALSE;
|
|
302 |
}
|
|
303 |
else
|
|
304 |
{
|
|
305 |
mCurrentState = PLAYING;
|
|
306 |
mIsRecording = TRUE;
|
|
307 |
}
|
|
308 |
}
|
|
309 |
}
|
|
310 |
|
|
311 |
void FolderView::record_ILBC()
|
|
312 |
{
|
|
313 |
if( mCurrentState == NONE ){
|
|
314 |
int err = gst_record_file( RECORD_ILBC );
|
|
315 |
if(err)
|
|
316 |
{
|
|
317 |
showNote(err);
|
|
318 |
mCurrentState = NONE;
|
|
319 |
mIsRecording = FALSE;
|
|
320 |
}
|
|
321 |
else
|
|
322 |
{
|
|
323 |
mCurrentState = PLAYING;
|
|
324 |
mIsRecording = TRUE;
|
|
325 |
}
|
|
326 |
}
|
|
327 |
}
|
|
328 |
|
|
329 |
void FolderView::record_AAC()
|
|
330 |
{
|
|
331 |
if( mCurrentState == NONE ){
|
|
332 |
int err = gst_record_file( RECORD_AAC );
|
|
333 |
if(err)
|
|
334 |
{
|
|
335 |
showNote(err);
|
|
336 |
mCurrentState = NONE;
|
|
337 |
mIsRecording = FALSE;
|
|
338 |
}
|
|
339 |
else
|
|
340 |
{
|
|
341 |
mCurrentState = PLAYING;
|
|
342 |
mIsRecording = TRUE;
|
|
343 |
}
|
|
344 |
}
|
|
345 |
}
|
|
346 |
void FolderView::timertimeout()
|
|
347 |
{
|
|
348 |
if( PLAYING == mCurrentState ){
|
|
349 |
gst_get_events();
|
|
350 |
}
|
|
351 |
|
|
352 |
if( STOP == mCurrentState ){
|
|
353 |
gst_unref();
|
|
354 |
mCurrentState = NONE;
|
|
355 |
mIsRecording = FALSE;
|
|
356 |
}
|
|
357 |
}
|