gstreamer_test_apps/QtGSTPlayer/folderview.cpp
branchRCL_3
changeset 30 7e817e7e631c
parent 29 567bb019e3e3
equal deleted inserted replaced
29:567bb019e3e3 30:7e817e7e631c
     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::showNote(const int err)
       
   122 {
       
   123     if(err)
       
   124     {
       
   125         HbNotificationDialog* notifyDialog = new HbNotificationDialog;
       
   126         notifyDialog->setTimeout(HbPopup::StandardTimeout);
       
   127         QString strong;
       
   128         QString sprint= strong.sprintf("Format Not supported(%d)",err);
       
   129         notifyDialog->setTitleTextWrapping(Hb::TextWordWrap);
       
   130         notifyDialog->setTitle(QString("Error"));
       
   131         notifyDialog->setWrapMode(Hb::TextWordWrap);
       
   132         notifyDialog->setText(sprint);
       
   133         
       
   134         notifyDialog->exec();
       
   135         delete notifyDialog;
       
   136     }
       
   137 }
       
   138 void FolderView::item_pressed(const QModelIndex &index)
       
   139 {
       
   140     if( mIsRecording )
       
   141     {
       
   142         return;
       
   143     }
       
   144     QVariant variant=index.data();
       
   145     QString str = variant.toString();
       
   146     
       
   147     
       
   148     QString fullpath = mFolderPath;
       
   149     fullpath.append( str );
       
   150     
       
   151     TBuf16<1024> buf16;
       
   152     buf16.Copy( (TUint16*)fullpath.data_ptr()->data ,fullpath.data_ptr()->size );
       
   153     TBuf8<1024> buf8;
       
   154     buf8.Copy( buf16 );
       
   155 
       
   156     if( NONE != mCurrentState )
       
   157     {
       
   158     gst_unref();
       
   159     }
       
   160    
       
   161     int err = gst_play_file( (char*)buf8.PtrZ() );
       
   162     if(err)
       
   163     {
       
   164         showNote(err);
       
   165         mCurrentState = NONE;
       
   166     }
       
   167     else
       
   168     {
       
   169         mCurrentState = PLAYING;
       
   170     }   
       
   171 
       
   172 }
       
   173 void FolderView::pause()
       
   174 {
       
   175     if( PLAYING == mCurrentState  ){
       
   176     gst_pause();
       
   177     mCurrentState = PAUSE;
       
   178     }
       
   179 }
       
   180 
       
   181 void FolderView::resume()
       
   182 {
       
   183     if( PAUSE == mCurrentState  ){
       
   184     gst_resume();
       
   185     mCurrentState = PLAYING;
       
   186     }
       
   187 }
       
   188 
       
   189 void FolderView::stop()
       
   190 {
       
   191     if( mIsRecording == TRUE )
       
   192     {
       
   193         gst_record_stop();
       
   194     
       
   195         if( mModel )
       
   196             delete mModel;
       
   197         
       
   198         mModel = new QDirModel(this);
       
   199         mFileList->setModel(mModel);
       
   200 
       
   201         mFileList->reset();
       
   202         mFileList->setRootIndex(mModel->index(mFolderPath));
       
   203 //        mFileList->show();
       
   204 //      int x = mFileList->indexCount();
       
   205         //setWidget(mFileList);
       
   206         mIsRecording = FALSE;
       
   207         return;
       
   208     }
       
   209     if( PLAYING == mCurrentState || PAUSE == mCurrentState ){
       
   210     gst_unref();
       
   211     mCurrentState = NONE;
       
   212     }
       
   213 }
       
   214 
       
   215 void FolderView::record_AMR()
       
   216 {
       
   217     if( mCurrentState == NONE ){
       
   218         int err = gst_record_file( RECORD_AMR );
       
   219         if(err)
       
   220         {
       
   221             showNote(err);
       
   222             mCurrentState = NONE;
       
   223             mIsRecording = FALSE;
       
   224         }
       
   225         else
       
   226         {
       
   227             mCurrentState = PLAYING;
       
   228             mIsRecording = TRUE;
       
   229         }
       
   230     }
       
   231 }
       
   232 
       
   233 void FolderView::record_WAV()
       
   234 {
       
   235     if( mCurrentState == NONE ){
       
   236         int err = gst_record_file( RECORD_WAV );
       
   237         if(err)
       
   238         {
       
   239             showNote(err);
       
   240             mCurrentState = NONE;
       
   241             mIsRecording = FALSE;
       
   242         }
       
   243         else
       
   244         {
       
   245             mCurrentState = PLAYING;
       
   246             mIsRecording = TRUE;
       
   247         }
       
   248         //gst_record_wav();
       
   249     }    
       
   250 }
       
   251 
       
   252 void FolderView::record_RAW()
       
   253 {
       
   254     if( mCurrentState == NONE ){
       
   255         int err = gst_record_file( RECORD_RAW );
       
   256         if(err)
       
   257         {
       
   258             showNote(err);
       
   259             mCurrentState = NONE;
       
   260             mIsRecording = FALSE;
       
   261         }
       
   262         else
       
   263         {
       
   264             mCurrentState = PLAYING;
       
   265             mIsRecording = TRUE;
       
   266         }
       
   267     }
       
   268 }
       
   269 
       
   270 void FolderView::record_G711()
       
   271 {
       
   272     if( mCurrentState == NONE ){
       
   273         int err = gst_record_file( RECORD_G711 );
       
   274         if(err)
       
   275         {
       
   276             showNote(err);
       
   277             mCurrentState = NONE;
       
   278             mIsRecording = FALSE;
       
   279         }
       
   280         else
       
   281         {
       
   282             mCurrentState = PLAYING;
       
   283             mIsRecording = TRUE;
       
   284         }
       
   285     }
       
   286 }
       
   287 
       
   288 void FolderView::record_G729()
       
   289 {
       
   290     if( mCurrentState == NONE ){
       
   291         int err = gst_record_file( RECORD_G729 );
       
   292         if(err)
       
   293         {
       
   294             showNote(err);
       
   295             mCurrentState = NONE;
       
   296             mIsRecording = FALSE;
       
   297         }
       
   298         else
       
   299         {
       
   300             mCurrentState = PLAYING;
       
   301             mIsRecording = TRUE;
       
   302         }
       
   303     }
       
   304 }
       
   305 
       
   306 void FolderView::record_ILBC()
       
   307 {
       
   308     if( mCurrentState == NONE ){
       
   309         int err = gst_record_file( RECORD_ILBC );
       
   310         if(err)
       
   311         {
       
   312             showNote(err);
       
   313             mCurrentState = NONE;
       
   314             mIsRecording = FALSE;
       
   315         }
       
   316         else
       
   317         {
       
   318             mCurrentState = PLAYING;
       
   319             mIsRecording = TRUE;
       
   320         }
       
   321     }
       
   322 }
       
   323 
       
   324 void FolderView::record_AAC()
       
   325 {
       
   326     if( mCurrentState == NONE ){
       
   327         int err = gst_record_file( RECORD_AAC );
       
   328         if(err)
       
   329         {
       
   330             showNote(err);
       
   331             mCurrentState = NONE;
       
   332             mIsRecording = FALSE;
       
   333         }
       
   334         else
       
   335         {
       
   336             mCurrentState = PLAYING;
       
   337             mIsRecording = TRUE;
       
   338         }
       
   339     }
       
   340 }
       
   341 void FolderView::timertimeout()
       
   342 {
       
   343     if( PLAYING == mCurrentState ){
       
   344     gst_get_events();
       
   345     }
       
   346     
       
   347     if( STOP == mCurrentState ){
       
   348         gst_unref();
       
   349         mCurrentState = NONE;
       
   350         mIsRecording = FALSE;
       
   351     }
       
   352 }