--- a/qtinternetradio/ui/src/irapplication.cpp Mon Jun 21 22:33:45 2010 +0100
+++ b/qtinternetradio/ui/src/irapplication.cpp Thu Jul 22 16:31:41 2010 +0100
@@ -16,6 +16,7 @@
*/
#include <hbaction.h>
+#include <hbapplication.h>
#include <qcoreapplication.h>
#include <hbdevicemessagebox.h>
#include <hbprogressdialog.h>
@@ -24,8 +25,18 @@
#include <QFile>
#include <QTextStream>
#include <QDir>
-#include <xqsharablefile.h>
+#include <hbmessagebox.h>
+
#include <xqserviceutil.h>
+#include <hbiconitem.h>
+#include <hbiconanimator.h>
+#include <hbiconanimationmanager.h>
+#ifdef HS_WIDGET_ENABLED
+#include <XQSettingsManager>
+#include <XQPublishAndSubscribeSettingsKey>
+#include <XQPublishAndSubscribeUtils>
+#include <QDateTime>
+#endif
#ifdef LOCALIZATION
#include <QTranslator>
@@ -43,20 +54,24 @@
#include "irqsettings.h"
#include "irmediakeyobserver.h"
#include "ircategoryview.h"
-#include "irstationsview.h"
#include "irqlogger.h"
#include "iruidefines.h"
#include "irqsystemeventhandler.h"
-#include "irplaylist.h"
-
-#define INTERNETRADIO_SERVICE_NAME "internet_radio_10_1.com.nokia.symbian.IFileView"
+#include "irabstractlistviewbase.h"
+#include "irfileviewservice.h"
+#ifdef HS_WIDGET_ENABLED
+#include "irmonitorservice.h"
+#include "ircontrolservice.h"
+#include "irservicedef.h"
+#include "irqisdsdatastructure.h"
+#include "irsearchchannelsview.h"
+#endif
/*
* Description : constructor, initialize all data members
* Parameters : aViewManager : pointer to the view manager object
* Return : None
*/
IRApplication::IRApplication(IRViewManager* aViewManager, IRQSystemEventHandler* aSystemEventHandler):
- XQServiceProvider(INTERNETRADIO_SERVICE_NAME),
#ifdef _DEBUG
iTestPreferredBitrate(false),
#endif
@@ -74,20 +89,22 @@
iDisconnected(false),
iConnectingCanceled(false),
iLocalServer(NULL),
- iConnectingNote(NULL),
+ iLoadingNote(NULL),
#ifdef LOCALIZATION
iTranslator(NULL),
#endif
- iSystemEventHandler(aSystemEventHandler),
- iPlayList(NULL)
+ iSystemEventHandler(aSystemEventHandler),
+ iUseNetworkReason(EIR_UseNetwork_NoReason),
+ iAppFullyStarted(false),
+ #ifdef HS_WIDGET_ENABLED
+ iControlService(NULL),
+ iMonitorService(NULL),
+ #endif
+ iFileViewService(NULL),
+ iMessageBox(NULL)
{
LOG_METHOD;
- if (XQServiceUtil::isService())
- {
- //Publishes all public slots on this object
- publishAll();
- }
iViewManager->setApplication(this);
iInitEvent = static_cast<QEvent::Type>(QEvent::registerEventType());
@@ -100,7 +117,19 @@
// get advertisement setting
iSettings->getGlobalAdvFlag(iEnableGlobalAdv);
setupConnection();
- setLaunchView();
+
+ if (!XQServiceUtil::isService())
+ {
+ setLaunchView();
+ }
+
+ QString name = XQServiceUtil::interfaceName();
+ if (name == QString("com.nokia.symbian.IFileView"))
+ {
+ iFileViewService = new IRFileViewService(this);
+ }
+
+ iMessageBox = new HbMessageBox(hbTrId("No network connection!"),HbMessageBox::MessageTypeWarning,NULL);
}
/*
@@ -112,6 +141,8 @@
{
LOG_METHOD;
setExitingView();
+ iViewManager->saveActivity();
+
destroyComponents();
if (iLocalServer)
@@ -122,13 +153,14 @@
delete iLastPlayedStationInfo;
iLastPlayedStationInfo = NULL;
- delete iConnectingNote;
- iConnectingNote = NULL;
+ delete iLoadingNote;
+ iLoadingNote = NULL;
+
+ delete iMessageBox;
+ iMessageBox = NULL;
delete iSystemEventHandler;
- delete iPlayList;
-
#ifdef LOCALIZATION
if( iTranslator )
{
@@ -137,6 +169,16 @@
iTranslator = NULL;
}
#endif
+
+ delete iFileViewService;
+ iFileViewService = NULL;
+
+#ifdef HS_WIDGET_ENABLED
+ XQSettingsManager settingsManager;
+ XQPublishAndSubscribeUtils psUtils(settingsManager);
+ XQPublishAndSubscribeSettingsKey irStartupKey(KInternetRadioPSUid, KInternetRadioStartupKey);
+ psUtils.deleteProperty(irStartupKey);
+#endif
}
@@ -148,13 +190,33 @@
*/
void IRApplication::setLaunchView()
{
- if (!XQServiceUtil::isService())
+ //get starting view id according to activate reason
+ TIRViewId viewId = EIRView_CategoryView;
+ HbApplication *hbApp = qobject_cast<HbApplication*>(qApp);
+
+ if (hbApp->activateReason() == Hb::ActivationReasonActivity)
{
- //normal launch, launch starting view
- TIRViewId viewId = EIRView_CategoryView;
+ QVariant data = hbApp->activateData();
+ QByteArray serializedModel = data.toByteArray();
+ QDataStream stream(&serializedModel, QIODevice::ReadOnly);
+ int id = 0;
+ stream>>id;
+ viewId = TIRViewId(id);
+ }
+ else
+ {
iSettings->getStartingViewId(viewId);
- launchStartingView(viewId);
+ if (EIRView_PlayingView == viewId)
+ {
+ //handle error case
+ if (NULL == getLastPlayedStationInfo()->getLastPlayedStation())
+ {
+ viewId = EIRView_CategoryView;
+ }
+ }
}
+
+ launchStartingView(viewId);
}
/*
@@ -171,43 +233,92 @@
if (!iNetworkController->getNetworkStatus())
{
+ LOG( "IRApplication::verifyNetworkConnectivity--1");
ret = false;
if (!iNetworkController->isConnectRequestIssued())
{
+ LOG( "IRApplication::verifyNetworkConnectivity--2");
iConnectingText = aConnectingText;
iNetworkController->chooseAccessPoint();
}
}
return ret;
-}
+}
-void IRApplication::createConnectingDialog()
+void IRApplication::startLoadingAnimation(const QObject *aReceiver, const char *aFunc)
{
LOG_METHOD_ENTER;
- if (NULL == iConnectingNote)
+
+ //for downloading logos in stations view, favorites view and history view, network connection
+ //is initiated by low layer, we don't show any dialog
+ if (!iNetworkController->getNetworkStatus())
{
- iConnectingNote = new HbProgressDialog(HbProgressDialog::WaitDialog);
- iConnectingNote->setModal(true);
- iConnectingNote->setTimeout(HbPopup::NoTimeout);
- QAction *action = iConnectingNote->actions().at(0);
+ if (EIR_UseNetwork_NoReason == iUseNetworkReason) // network is not used by the Application
+ {
+ IRBaseView *currentView = static_cast<IRBaseView*>(iViewManager->currentView());
+ if (currentView && EIR_UseNetwork_NoReason == currentView->getUseNetworkReason())
+ {
+ return;
+ }
+ }
+ }
+
+ if (NULL == iLoadingNote)
+ {
+ iLoadingNote = new HbProgressDialog(HbProgressDialog::WaitDialog);
+ iLoadingNote->setModal(true);
+ iLoadingNote->setTimeout(HbPopup::NoTimeout);
+ QAction *action = iLoadingNote->actions().at(0);
+#ifdef SUBTITLE_STR_BY_LOCID
action->setText(hbTrId("txt_common_button_cancel"));
- connect(action, SIGNAL(triggered()), this, SLOT(cancelConnect()));
+#else
+ action->setText(hbTrId("Cancel"));
+#endif
}
- iConnectingNote->setText(iConnectingText);
- iConnectingNote->show();
+ iLoadingNote->disconnect(SIGNAL(cancelled()));
+ connect(iLoadingNote, SIGNAL(cancelled()), aReceiver, aFunc);
+
+ if (iLoadingNote->isVisible())
+ {
+ return;
+ }
+
+ //if iConnectingText == "", network connection is initiated by lower layer (eg. downloading logos)
+ if ("" != iConnectingText)
+ {
+ iLoadingNote->setText(iConnectingText);
+ iConnectingText = "";
+ }
+ else
+ {
+#ifdef SUBTITLE_STR_BY_LOCID
+ iLoadingNote->setText(hbTrId("txt_common_info_loading"));
+#else
+ iLoadingNote->setText(hbTrId("Loading"));
+#endif
+ }
+
+ iLoadingNote->show();
}
-void IRApplication::closeConnectingDialog()
+void IRApplication::stopLoadingAnimation()
{
LOG_METHOD_ENTER;
- if (iConnectingNote)
+
+ // this function is the endpoint of cancel loading actions for all views
+ // so we can do cleanup action here, including player stop action.
+ // No need to stop the player in each views in the slot connected to the cancel signal of the loading note
+ if (!getPlayController()->isPlaying())
{
- iConnectingNote->close();
- delete iConnectingNote;
- iConnectingNote = NULL;
+ getPlayController()->stop(EIRQUnknownTermination);
}
+
+ if (iLoadingNote)
+ {
+ iLoadingNote->close();
+ }
}
/*
@@ -230,6 +341,8 @@
if(NULL == iNetworkController)
{
iNetworkController = IRQNetworkController::openInstance();
+ connect(iNetworkController, SIGNAL(networkEventNotified(IRQNetworkEvent)),
+ this, SLOT(networkEventNotified(IRQNetworkEvent)));
}
return iNetworkController;
}
@@ -311,7 +424,12 @@
IRPlayList* IRApplication::getPlayList() const
{
- return iPlayList;
+ if (NULL == iFileViewService)
+ {
+ return NULL;
+ }
+
+ return iFileViewService->getPlayList();
}
#ifdef LOCALIZATION
@@ -324,37 +442,6 @@
}
#endif
-void IRApplication::view(const QString &aFileName)
-{
- if (NULL == iPlayList)
- {
- iPlayList = new IRPlayList;
- }
-
- iPlayList->parseFile(aFileName);
-
- if (1 == iPlayList->getNumberOfEntries())
- {
- launchStartingView(EIRView_PlayingView);
- }
- else if (iPlayList->getNumberOfEntries() > 1)
- {
- launchStartingView(EIRView_PlsView);
- }
- else
- {
- //normal launch, launch starting view
- TIRViewId viewId = EIRView_CategoryView;
- iSettings->getStartingViewId(viewId);
- launchStartingView(viewId);
- }
-}
-
-void IRApplication::view(const XQSharableFile &/*aSharableFile*/)
-{
-
-}
-
/*
* Description : create all the application level components, including network controller,
* favorites db, isds client, play controller, etc
@@ -364,6 +451,10 @@
void IRApplication::createComponents()
{
getSettings();
+#ifdef HS_WIDGET_ENABLED
+ iControlService = new IrControlService(this);
+ iMonitorService = new IrMonitorService(this);
+#endif
}
/*
@@ -402,6 +493,14 @@
delete iMediaKeyObserver;
iMediaKeyObserver = NULL;
+
+#ifdef HS_WIDGET_ENABLED
+ delete iControlService;
+ iControlService = NULL;
+
+ delete iMonitorService;
+ iMonitorService = NULL;
+#endif
}
void IRApplication::setupConnection()
@@ -416,6 +515,7 @@
return;
}
+ stopLoadingAnimation();
iConnectingCanceled = true;
if (iNetworkController->getNetworkStatus())
{
@@ -437,7 +537,7 @@
switch (aEvent)
{
case EIRQNetworkConnectionConnecting :
- createConnectingDialog();
+ startLoadingAnimation(this, SLOT(cancelConnect()));
iConnectingCanceled = false;
break;
@@ -456,7 +556,6 @@
break;
case EIRQAccessPointSelectionCancelled :
- closeConnectingDialog();
cancelConnect();
break;
@@ -471,8 +570,14 @@
case EIRQDisplayNetworkMessageNoConnectivity:
{
- closeConnectingDialog();
- HbMessageBox::warning(hbTrId("txt_irad_info_no_network_connectiion"), (QObject*)NULL, NULL);
+ stopLoadingAnimation();
+ LOG("IRApplication::networkEventNotified::no network connection");
+ if( !iMessageBox->isVisible() )
+ {
+ LOG("IRApplication::networkEventNotified::no network connection -- show dialog");
+ iMessageBox->show();
+ }
+
if (!iDisconnected)
{
/* the handling is up to each view */
@@ -494,14 +599,12 @@
if (!hasCache)
{
- IRBaseView *currView = static_cast<IRBaseView*>(iViewManager->currentView());
- Q_ASSERT(currView);
- currView->setUseNetworkReason(EIR_UseNetwork_LoadCategory);
+ iUseNetworkReason = EIR_UseNetwork_LoadCategory;
if (false == verifyNetworkConnectivity())
{
return;
}
- currView->setUseNetworkReason(EIR_UseNetwork_NoReason);
+ iUseNetworkReason = EIR_UseNetwork_NoReason;
}
IRCategoryView *categoryView = static_cast<IRCategoryView*>(getViewManager()->getView(EIRView_CategoryView, true));
@@ -518,13 +621,11 @@
delete socket;
iViewManager->raise();
-}
+}
void IRApplication::initApp()
{
- getNetworkController();
- connect(iNetworkController, SIGNAL(networkEventNotified(IRQNetworkEvent)),
- this, SLOT(networkEventNotified(IRQNetworkEvent)));
+ getNetworkController();
IRBaseView *view = static_cast<IRBaseView*> (iViewManager->currentView());
if (view)
@@ -535,6 +636,19 @@
getMediaKeyObserver();
startSystemEventMonitor();
startLocalServer();
+ //when IR is running, remove activity. Otherwise user can see two items in task switcher
+ iViewManager->removeActivity();
+
+#ifdef HS_WIDGET_ENABLED
+ // Write the startup timestamp to P&S key for the homescreen widget
+ XQSettingsManager settingsManager;
+ XQPublishAndSubscribeUtils psUtils(settingsManager);
+ XQPublishAndSubscribeSettingsKey irStartupKey(KInternetRadioPSUid, KInternetRadioStartupKey);
+ if (psUtils.defineProperty(irStartupKey, XQSettingsManager::TypeInt))
+ {
+ settingsManager.writeItemValue(irStartupKey, (int)QDateTime::currentDateTime().toTime_t());
+ }
+#endif
}
bool IRApplication::event(QEvent* e)
@@ -550,19 +664,29 @@
TIRHandleResult IRApplication::handleConnectionEstablished()
{
- IRBaseView *currView = static_cast<IRBaseView*>(iViewManager->currentView());
- Q_ASSERT(currView);
-
- if (EIR_UseNetwork_LoadCategory == currView->getUseNetworkReason())
+ TIRHandleResult retVal = EIR_DoDefault;
+ switch (iUseNetworkReason)
{
- closeConnectingDialog();
- IRCategoryView *categoryView = static_cast<IRCategoryView*>(getViewManager()->getView(EIRView_CategoryView, true));
- categoryView->loadCategory(IRQIsdsClient::EGenre);
- currView->setUseNetworkReason(EIR_UseNetwork_NoReason);
- return EIR_NoDefault;
+ case EIR_UseNetwork_LoadCategory:
+ {
+ IRCategoryView *categoryView = static_cast<IRCategoryView*>(getViewManager()->getView(EIRView_CategoryView, true));
+ categoryView->loadCategory(IRQIsdsClient::EGenre);
+ retVal = EIR_NoDefault;
+ break;
+ }
+
+#ifdef HS_WIDGET_ENABLED
+ case EIR_UseNetwork_PlayStation: // play last station when player is in Idle state while there is no connection.
+ getPlayController()->resume();
+ retVal = EIR_NoDefault;
+ break;
+#endif
+ default:
+ break;
}
- return EIR_DoDefault;
+ iUseNetworkReason = EIR_UseNetwork_NoReason;
+ return retVal;
}
void IRApplication::handleTermsConsAccepted()
@@ -580,42 +704,86 @@
void IRApplication::launchStartingView(TIRViewId aViewId)
{
- bool isFirstTimeUsage = false;
+ iStartingViewId = aViewId;
+ /* bool isFirstTimeUsage = false;
iSettings->isFlagTermsAndConditions(isFirstTimeUsage);
- iStartingViewId = aViewId;
+
if(isFirstTimeUsage)
{
iViewManager->activateView(EIRView_TermsConsView);
QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
}
- else
+ else*/
{
iViewManager->activateView(iStartingViewId);
QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
QEvent* initEvent = new QEvent(iInitEvent);
QCoreApplication::postEvent(this, initEvent, Qt::HighEventPriority);
- }
+ }
+
+ iAppFullyStarted = true;
+}
+
+bool IRApplication::isAppFullyStarted() const
+{
+ return iAppFullyStarted;
}
void IRApplication::setExitingView()
-{
- IRQSettings *settings = getSettings();
- TIRViewId viewId = iViewManager->currentViewId();
-
- switch (viewId)
- {
- case EIRView_MainView:
- case EIRView_FavoritesView:
- case EIRView_PlayingView:
- settings->setStartingViewId(viewId);
- break;
-
- default:
- settings->setStartingViewId(EIRView_CategoryView);
- break;
+{
+ TIRViewId viewId = iViewManager->getExitingView();
+ if(EIRView_InvalidId != viewId)
+ {
+ getSettings()->setStartingViewId(viewId);
}
}
+
+#ifdef HS_WIDGET_ENABLED
+bool IRApplication::startPlaying()
+{
+ // if any loading is in progress, disallow to play
+ if (iLoadingNote && iLoadingNote->isVisible())
+ {
+ LOG( "IRApplication::startPlaying() in the return false1");
+ return false;
+ }
+
+ if (getPlayController()->isStopped())
+ {
+ LOG_FORMAT( "IRApplication::startPlaying(), the station name is %s",
+ STRING2CHAR(getPlayController()->getNowPlayingPreset()->name));
+ iUseNetworkReason = EIR_UseNetwork_PlayStation;
+ getPlayController()->setConnectingStationName(getPlayController()->getNowPlayingPreset()->name);
+ if (verifyNetworkConnectivity())
+ {
+ iUseNetworkReason = EIR_UseNetwork_NoReason;
+ getPlayController()->resume();
+ }
+ return true;
+ }
+ else
+ {
+ LOG( "IRApplication::startPlaying() in the return false2");
+ return false;
+ }
+}
+
+void IRApplication::cancelPlayerLoading()
+{
+ if (IRPlayController::EConnecting == getPlayController()->state()
+ || IRPlayController::EBuffering == getPlayController()->state())
+ {
+ if (iLoadingNote && iLoadingNote->isVisible())
+ {
+ iLoadingNote->cancel();
+ }
+ }
+}
+
+#endif
+
+
void IRApplication::startLocalServer()
{
QString serverName = QCoreApplication::applicationName();
@@ -648,12 +816,34 @@
{
bool eventWasConsumed = false;
- if (object->objectName() == ABSTRACT_LIST_VIEW_BASE_OBJECT_PLAYINGBANNER
- && event->type() == QEvent::GraphicsSceneMousePress)
+ if (object->objectName() == ABSTRACT_LIST_VIEW_BASE_OBJECT_PLAYINGBANNER)
{
- eventWasConsumed = true;
- Q_ASSERT(iPlayController->isPlaying());
- iViewManager->activateView(EIRView_PlayingView);
+ if (NULL == iViewManager->currentView())
+ {
+ return false;
+ }
+
+ if( (EIRView_PlayingView == static_cast<IRBaseView*>(iViewManager->currentView())->id()) \
+ ||(EIRView_SearchView == static_cast<IRBaseView*>(iViewManager->currentView())->id()) )
+ {
+ return false;
+ }
+
+ if (event->type() == QEvent::GraphicsSceneMousePress)
+ {
+ eventWasConsumed = true;
+ Q_ASSERT(iPlayController->isPlaying());
+ IrAbstractListViewBase* listview = static_cast<IrAbstractListViewBase*>(iViewManager->currentView());
+ listview->setPlayingBannerTextColor("qtc_multimedia_trans_pressed");
+ }
+ else if(event->type() == QEvent::GraphicsSceneMouseRelease)
+ {
+ eventWasConsumed = true;
+ Q_ASSERT(iPlayController->isPlaying());
+ IrAbstractListViewBase* listview = static_cast<IrAbstractListViewBase*>(iViewManager->currentView());
+ listview->setPlayingBannerTextColor("qtc_multimedia_trans_normal");
+ iViewManager->activateView(EIRView_PlayingView);
+ }
}
return eventWasConsumed;
}
@@ -662,19 +852,60 @@
{
connect(iSystemEventHandler, SIGNAL(diskSpaceLowNotification(qint64)),
this, SLOT(handleDiskSpaceLow(qint64)));
+ connect(iSystemEventHandler, SIGNAL(callActivated()), this, SLOT(handleCallActivated()));
+ connect(iSystemEventHandler, SIGNAL(callDeactivated()), this, SLOT(handleCallDeactivated()));
iSystemEventHandler->start();
}
void IRApplication::handleDiskSpaceLow(qint64 aCriticalLevel)
{
Q_UNUSED(aCriticalLevel);
- HbDeviceMessageBox messageBox(hbTrId("txt_irad_info_no_space_on_c_drive_internet_radio_closed"),
+#ifdef SUBTITLE_STR_BY_LOCID
+ HbDeviceMessageBox messageBox(hbTrId("txt_irad_info_insufficient_disk_space"),
HbMessageBox::MessageTypeWarning);
+#else
+ HbDeviceMessageBox messageBox(hbTrId("Insufficient disk space"),
+ HbMessageBox::MessageTypeWarning);
+#endif
messageBox.setTimeout(HbPopup::NoTimeout);
messageBox.exec();
qApp->quit();
}
+void IRApplication::handleCallActivated()
+{
+ LOG_METHOD;
+ //for the buffering state needs more attention, we firstly
+ //don't handle it, improve in future.
+ if( iPlayController->isPlaying() /*|| iPlayController->isBuffering()*/)
+ {
+ iPlayController->stop(EIRQCallIsActivated);
+ stopLoadingAnimation();
+ }
+
+ //for we don't cancel the loading when call is activated,
+ //so, here , we don't add the handling for it.
+}
+
+void IRApplication::handleCallDeactivated()
+{
+ LOG_METHOD;
+ if( iPlayController->getStopReason() == EIRQCallIsActivated )
+ {
+ iPlayController->resume();
+ }
+}
+
+void IRApplication::handleHeadsetConnected()
+{
+ LOG_METHOD;
+}
+
+void IRApplication::handleHeadsetDisconnected()
+{
+ LOG_METHOD;
+}
+
#ifdef _DEBUG
void IRApplication::readConfiguration()
{