radioapp/radiowidgets/src/radiomainview.cpp
changeset 51 bbebb0235466
parent 44 0a3ad94fc71c
child 54 a8ba0c289b44
equal deleted inserted replaced
47:74b7c6e79031 51:bbebb0235466
    19 #include <QTimer>
    19 #include <QTimer>
    20 #include <HbPushButton>
    20 #include <HbPushButton>
    21 #include <HbAction>
    21 #include <HbAction>
    22 #include <HbMenu>
    22 #include <HbMenu>
    23 #include <HbApplication>
    23 #include <HbApplication>
    24 #include <HbActivityManager>
    24 #include <afactivitystorage.h>
    25 #include <QPixmap>
    25 #include <QPixmap>
    26 #include <HbLabel>
    26 #include <HbLabel>
    27 #include <HbFrameItem>          // Temporarily here until docml supports frame items
    27 #include <HbFrameItem>          // Temporarily here until docml supports frame items
    28 
    28 
    29 // User includes
    29 // User includes
    60  *
    60  *
    61  */
    61  */
    62 RadioMainView::RadioMainView() :
    62 RadioMainView::RadioMainView() :
    63     RadioViewBase( false ),
    63     RadioViewBase( false ),
    64     mCarousel( NULL ),
    64     mCarousel( NULL ),
    65     mFrequencyStrip( NULL ),
    65     mFrequencyStrip( NULL )
    66     mSkippingAction( NULL ),
       
    67     mAlternateSkipping( false )
       
    68 {
    66 {
    69 }
    67 }
    70 
    68 
    71 /*!
    69 /*!
    72  *
    70  *
   194 
   192 
   195     Radio::connect( static_cast<HbApplication*>( qApp ),    SIGNAL(aboutToQuit()),
   193     Radio::connect( static_cast<HbApplication*>( qApp ),    SIGNAL(aboutToQuit()),
   196                     this,                                   SLOT(saveActivity()) );
   194                     this,                                   SLOT(saveActivity()) );
   197 
   195 
   198     emit applicationReady();
   196     emit applicationReady();
       
   197 
       
   198     QScopedPointer<AfActivityStorage> storage( new AfActivityStorage() );
       
   199     bool ok = storage->removeActivity( RADIO_MAINVIEW_ACTIVITY_ID );
       
   200     LOG_ASSERT( ok, LOG( "Failed to remove old activity from Activity Storage!" ) );
   199 }
   201 }
   200 
   202 
   201 /*!
   203 /*!
   202  * \reimp
   204  * \reimp
   203  *
   205  *
   277 /*!
   279 /*!
   278  * Private slot
   280  * Private slot
   279  */
   281  */
   280 void RadioMainView::skip( int skipMode )
   282 void RadioMainView::skip( int skipMode )
   281 {
   283 {
   282 //    if ( !mAlternateSkipping && ( skipMode == StationSkip::PreviousFavorite || skipMode == StationSkip::NextFavorite ) &&
   284     LOG_FORMAT( "RadioMainView::skip skipMode: %d", skipMode );
   283 //        mUiEngine->stationModel().favoriteCount() == 0 ) {
   285 
   284 //        mCarousel->setInfoText( CarouselInfoText::NoFavorites );
   286     const uint currentFrequency = mFrequencyStrip->frequency();
   285 //    } else {
   287     RadioStation station;
   286         const uint currentFrequency = mFrequencyStrip->frequency();
   288     mUiEngine->stationModel().findFrequency( currentFrequency, station );
   287         RadioStation station;
   289 
   288         mUiEngine->stationModel().findFrequency( currentFrequency, station );
   290     const uint frequency = mUiEngine->skipStation( static_cast<StationSkip::Mode>( skipMode ),
   289 
   291                                                             currentFrequency);
   290         if ( mAlternateSkipping ) { //TODO: Remove. Temporary test code
   292 
   291             if ( sender() == mFrequencyStrip ) {
   293     if ( currentFrequency != frequency || station.isFavorite() ) {
   292                 if ( skipMode == StationSkip::NextFavorite ) {
   294         const Scroll::Direction direction = RadioUtil::scrollDirectionFromSkipMode( skipMode );
   293                     skipMode = StationSkip::Next;
   295         mCarousel->setFrequency( frequency, TuneReason::Skip, direction );
   294                 } else if ( skipMode == StationSkip::PreviousFavorite ) {
   296         mFrequencyStrip->setFrequency( frequency, TuneReason::Skip, direction );
   295                     skipMode = StationSkip::Previous;
   297     }
   296                 }
       
   297             } else if ( sender() == mCarousel ) {
       
   298                 if ( skipMode == StationSkip::Next ) {
       
   299                     skipMode = StationSkip::NextFavorite;
       
   300                 } else if ( skipMode == StationSkip::Previous ) {
       
   301                     skipMode = StationSkip::PreviousFavorite;
       
   302                 }
       
   303             }
       
   304         }
       
   305 
       
   306         const uint frequency = mUiEngine->skipStation( static_cast<StationSkip::Mode>( skipMode ),
       
   307                                                                 currentFrequency);
       
   308 
       
   309         if ( currentFrequency != frequency || station.isFavorite() ) {
       
   310             const Scroll::Direction direction = RadioUtil::scrollDirectionFromSkipMode( skipMode );
       
   311             mCarousel->setFrequency( frequency, TuneReason::Skip, direction );
       
   312             mFrequencyStrip->setFrequency( frequency, TuneReason::Skip, direction );
       
   313         }
       
   314 //    }
       
   315 }
   298 }
   316 
   299 
   317 /*!
   300 /*!
   318  * Private slot
   301  * Private slot
   319  */
   302  */
   439 /*!
   422 /*!
   440  * Private slot
   423  * Private slot
   441  */
   424  */
   442 void RadioMainView::saveActivity()
   425 void RadioMainView::saveActivity()
   443 {
   426 {
   444     HbActivityManager* activityManager = qobject_cast<HbApplication*>(qApp)->activityManager();
       
   445 
       
   446     // Get a screenshot for saving to the activity manager
   427     // Get a screenshot for saving to the activity manager
   447     QSize screenShotSize = mCarousel->size().toSize();
   428     QSize screenShotSize = mCarousel->size().toSize();
   448     QPixmap screenShot( screenShotSize );
   429     QPixmap screenShot( screenShotSize );
   449     QPainter painter( &screenShot );
   430     QPainter painter( &screenShot );
   450 
   431 
   451     // Draw the background and overlay
   432     // Draw the background and overlay
   452     HbLabel* backgroundLabel = mUiLoader->findWidget<HbLabel>( DOCML::MV_NAME_CAROUSEL_BACKGROUND );
   433     // TODO: Uncomment when Orbit fixes the crash caused calling the pixmap() function.
   453     painter.drawPixmap( 0, 0, backgroundLabel->icon().pixmap().scaled( screenShotSize ) );
   434 //    HbLabel* backgroundLabel = mUiLoader->findWidget<HbLabel>( DOCML::MV_NAME_CAROUSEL_BACKGROUND );
   454     backgroundLabel = mUiLoader->findWidget<HbLabel>( DOCML::MV_NAME_CAROUSEL_OVERLAY );
   435 //    painter.drawPixmap( 0, 0, backgroundLabel->icon().pixmap().scaled( screenShotSize ) );
   455     painter.drawPixmap( 0, 0, backgroundLabel->icon().pixmap().scaled( screenShotSize ) );
   436 //    backgroundLabel = mUiLoader->findWidget<HbLabel>( DOCML::MV_NAME_CAROUSEL_OVERLAY );
       
   437 //    painter.drawPixmap( 0, 0, backgroundLabel->icon().pixmap().scaled( screenShotSize ) );
   456 
   438 
   457     mCarousel->drawOffScreen( painter );
   439     mCarousel->drawOffScreen( painter );
   458 
   440 
   459     QVariantHash metadata;
   441     QVariantHash metadata;
   460     metadata.insert( "screenshot", screenShot );
   442     metadata.insert( "screenshot", screenShot );
   464     #elif defined BUILD_WIN32
   446     #elif defined BUILD_WIN32
   465         screenShot.save( "radio.bmp" );
   447         screenShot.save( "radio.bmp" );
   466     #endif
   448     #endif
   467 
   449 
   468     // Update the activity to the activity manager
   450     // Update the activity to the activity manager
   469     bool ok = activityManager->removeActivity( RADIO_MAINVIEW_ACTIVITY_ID );
   451     QScopedPointer<AfActivityStorage> storage( new AfActivityStorage() );
   470     LOG_ASSERT( ok, LOG( "Failed to remove old activity from Activity Manager!" ) );
   452     bool ok = storage->saveActivity( RADIO_MAINVIEW_ACTIVITY_ID, QVariant(), metadata );
   471     ok = activityManager->addActivity( RADIO_MAINVIEW_ACTIVITY_ID, QVariant(), metadata );
   453     LOG_ASSERT( ok, LOG( "Failed to update activity to Activity Storage!" ) );
   472     LOG_ASSERT( ok, LOG( "Failed to update activity to Activity Manager!" ) );
       
   473 }
   454 }
   474 
   455 
   475 /*!
   456 /*!
   476  *
   457  *
   477  */
   458  */