app/src/mpmainwindow.cpp
changeset 35 fdb31ab341af
parent 34 2c5162224003
child 32 c163ef0b758d
--- a/app/src/mpmainwindow.cpp	Fri Apr 30 19:33:32 2010 -0500
+++ b/app/src/mpmainwindow.cpp	Fri May 14 18:54:37 2010 -0500
@@ -29,7 +29,7 @@
 #include "mpmainwindow.h"
 #include "mpviewbase.h"
 #include "musicservices.h"
-#include "mpengine.h"
+#include "mpenginefactory.h"
 #include "mptrace.h"
 
 /*!
@@ -50,6 +50,7 @@
       mPlaybackViewPlugin(0),
       mSettingsViewPlugin(0),
       mDetailsViewPlugin(0),
+      mMediaWallViewPlugin(0),
       mCurrentViewPlugin(0),
       mVerticalViewType( CollectionView ),
       mMusicServices(0)
@@ -83,8 +84,11 @@
         mDetailsViewPlugin->destroyView();
         delete mDetailsViewPlugin;
     }
-
-    MpEngine::instance()->close();
+    if (mMediaWallViewPlugin) {
+        mMediaWallViewPlugin->destroyView();
+        delete mMediaWallViewPlugin;
+    }    
+    MpEngineFactory::close();
 
 
     TX_EXIT
@@ -128,20 +132,26 @@
         XQServiceUtil::toBackground( false );
     }
 
-    MpEngine *engine = MpEngine::instance();
-
     if ( !mMusicServices ) {
-        engine->initialize(MpCommon::DefaultView);
-      
-        loadView(CollectionView);
-        activateView(CollectionView);
-
+        MpEngineFactory::createSharedEngine();
+        if ( orientation() == Qt::Vertical ) {
+            loadView(CollectionView);
+            activateView(CollectionView);
+            loadView(MediaWallView);
+        }
+        else {
+            loadView(MediaWallView);
+            activateView(MediaWallView);
+            loadView(CollectionView);
+        }
         connect(this, SIGNAL( orientationChanged( Qt::Orientation ) ), SLOT( switchView( Qt::Orientation ) ) );
-        connect( engine, SIGNAL( libraryUpdated() ), SLOT( handleLibraryUpdated() ) );
-        engine->checkForSystemEvents();
+        connect( MpEngineFactory::sharedEngine(), SIGNAL( libraryUpdated() ), SLOT( handleLibraryUpdated() ) );
+        MpEngineFactory::sharedEngine()->checkForSystemEvents();
         loadView( PlaybackView );
     }
-    setOrientation(Qt::Vertical, true);//This sould prevent media wall activation.
+    else {
+        setOrientation(Qt::Vertical, true);//This sould prevent media wall activation.
+    }
     TX_EXIT
 }
 
@@ -151,7 +161,7 @@
 void MpMainWindow::handleCommand( int commandCode )
 {
     TX_ENTRY_ARGS("commandCode=" << commandCode );
-
+    
     switch ( commandCode ) {
         case MpCommon::Exit:
             if ( mCurrentViewPlugin ) {
@@ -159,6 +169,9 @@
             }
             qApp->quit();
             break;
+        case MpCommon::SendToBackground:
+            lower();
+            break;
         case MpCommon::ActivateCollectionView:
             activateView(CollectionView);
             break;
@@ -183,7 +196,9 @@
         if (orientation == Qt::Vertical) {
             activateView( mVerticalViewType );   
         }
-
+        else {
+            activateView(MediaWallView);
+        }
 }
 
 /*!
@@ -199,7 +214,10 @@
     if ( mCurrentViewPlugin ) {     
         disconnectView();
         mCurrentViewPlugin->deactivateView();
-        if ( viewType  == CollectionView && mCurrentViewPlugin == mPlaybackViewPlugin ||
+        if ( viewType  == MediaWallView || mCurrentViewPlugin == mMediaWallViewPlugin ) {
+            doTransition = false;
+        }
+        else if ( viewType  == CollectionView && mCurrentViewPlugin == mPlaybackViewPlugin ||
                   viewType  == PlaybackView && mCurrentViewPlugin == mDetailsViewPlugin ||
                   viewType  == PlaybackView && mCurrentViewPlugin == mSettingsViewPlugin ) {
             transitionFlags |= Hb::ViewSwitchUseBackAnim;
@@ -212,9 +230,9 @@
     Q_ASSERT( mCurrentViewPlugin );
 
     if ( mCurrentViewPlugin ) {
-        
-        mVerticalViewType = viewType;
-        
+        if ( viewType != MediaWallView  ) {
+            mVerticalViewType = viewType;
+        }
         addView( reinterpret_cast<HbView*>( mCurrentViewPlugin->getView() ) );
         setCurrentView( reinterpret_cast<HbView*>( mCurrentViewPlugin->getView() ) , doTransition , transitionFlags);
         mCurrentViewPlugin->activateView();
@@ -275,17 +293,35 @@
 /*!
  Reimp.
  */
-
+void 	MpMainWindow::keyPressEvent(QKeyEvent *event)
+{
+    switch(event->key()) {
+    case 16842754:
+    case Qt::Key_Hangup:
+        if (orientation () == Qt::Vertical) {
+            setOrientation(Qt::Horizontal, false);
+        }
+        else {
+            setOrientation(Qt::Vertical, false);
+        }
+        break;
+    case 16842753:
+    case Qt::Key_Call:         
+        unsetOrientation(false);
+        break;
+    default:
+        HbMainWindow::keyPressEvent (event);
+        break;          
+    }
+}
 
-void MpMainWindow::initializeServiceView( TUid hostUid ){
-    
-    MpEngine *engine = MpEngine::instance();
-        
+void MpMainWindow::initializeServiceView( TUid hostUid )
+{
     switch (mMusicServices->currentService()) {
  
     case MusicServices::EUriFetcher:
         {
-            engine->initialize( MpCommon::FetchView, hostUid );
+            MpEngineFactory::createSharedEngine( hostUid , MpEngine::Fetch );
             loadView( CollectionView, MpCommon::FetchView );
             MpViewBase* collectionView = reinterpret_cast<MpViewBase*>(mCollectionViewPlugin->getView());
             connect(collectionView, SIGNAL(songSelected(QString)), mMusicServices, SLOT(itemSelected(QString)));
@@ -293,22 +329,22 @@
             loadView(PlaybackView, MpCommon::FetchView );
             MpViewBase* playbackView = reinterpret_cast<MpViewBase*>(mPlaybackViewPlugin->getView());
             connect(playbackView, SIGNAL(songSelected(QString)), mMusicServices, SLOT(itemSelected(QString)));
-            connect( engine, SIGNAL( libraryUpdated() ), this, SLOT( handleLibraryUpdated() ) );
-            engine->checkForSystemEvents();
+            connect( MpEngineFactory::sharedEngine(), SIGNAL( libraryUpdated() ), this, SLOT( handleLibraryUpdated() ) );
+            MpEngineFactory::sharedEngine()->checkForSystemEvents();
             break;
         }
     case MusicServices::EPlayback:
         {
-            engine->initialize( MpCommon::EmbeddedView, hostUid );
+            MpEngineFactory::createSharedEngine( hostUid , MpEngine::Embedded );
             loadView(PlaybackView, MpCommon::EmbeddedView );   
             MpViewBase* playbackView = reinterpret_cast<MpViewBase*>(mPlaybackViewPlugin->getView());
-            connect(mMusicServices, SIGNAL(playReady(QString)), engine, SLOT(playEmbedded(QString)));
-            connect(mMusicServices, SIGNAL(playReady(const XQSharableFile&)), engine, SLOT(playEmbedded(const XQSharableFile&)));
+            connect(mMusicServices, SIGNAL(playReady(QString)), MpEngineFactory::sharedEngine(), SLOT(playEmbedded(QString)));
+            connect(mMusicServices, SIGNAL(playReady(const XQSharableFile&)), MpEngineFactory::sharedEngine(), SLOT(playEmbedded(const XQSharableFile&)));
             connect(playbackView, SIGNAL(songSelected(QString)), mMusicServices, SLOT(itemSelected(QString)));
             activateView( PlaybackView );
             break;
         }
-        default:
+    default:
         Q_ASSERT_X(false, "MpMainWindow::initializeServiceView", "undefined service");
         break;
     }
@@ -338,7 +374,10 @@
         pluginUid = MpCommon::KDetailsViewUid;
         plugin = &mDetailsViewPlugin;
         break;
-
+    case MediaWallView:
+        pluginUid = MpCommon::KMediaWallViewUid;
+        plugin = &mMediaWallViewPlugin;
+        break;
     default:
         Q_ASSERT_X(false, "MpMainWindow::loadView", "undefined view type");
         break;