17 |
17 |
18 #include <hbaction.h> |
18 #include <hbaction.h> |
19 #include <hbapplication.h> |
19 #include <hbapplication.h> |
20 #include <qcoreapplication.h> |
20 #include <qcoreapplication.h> |
21 #include <hbdevicemessagebox.h> |
21 #include <hbdevicemessagebox.h> |
22 #include <hbprogressdialog.h> |
22 #include <hbprogressdialog.h> |
23 #include <QLocalServer> |
|
24 #include <QLocalSocket> |
|
25 #include <QFile> |
23 #include <QFile> |
26 #include <QTextStream> |
24 #include <QTextStream> |
27 #include <QDir> |
25 #include <QDir> |
28 #include <hbmessagebox.h> |
26 #include <hbmessagebox.h> |
|
27 #include <HbEvent> |
29 |
28 |
30 #include <xqserviceutil.h> |
29 #include <xqserviceutil.h> |
31 #include <hbiconitem.h> |
30 #include <hbiconitem.h> |
32 #include <hbiconanimator.h> |
31 #include <hbiconanimator.h> |
33 #include <hbiconanimationmanager.h> |
32 #include <hbiconanimationmanager.h> |
36 #include <XQPublishAndSubscribeSettingsKey> |
35 #include <XQPublishAndSubscribeSettingsKey> |
37 #include <XQPublishAndSubscribeUtils> |
36 #include <XQPublishAndSubscribeUtils> |
38 #include <QDateTime> |
37 #include <QDateTime> |
39 #endif |
38 #endif |
40 |
39 |
41 #ifdef LOCALIZATION |
40 |
42 #include <QTranslator> |
|
43 #include "irqutility.h" |
|
44 #endif |
|
45 |
41 |
46 #include "irviewmanager.h" |
42 #include "irviewmanager.h" |
47 #include "irapplication.h" |
43 #include "irapplication.h" |
48 |
44 |
49 #include "irqnetworkcontroller.h" |
45 #include "irqnetworkcontroller.h" |
85 iMediaKeyObserver(NULL), |
81 iMediaKeyObserver(NULL), |
86 iLastPlayedStationInfo(NULL), |
82 iLastPlayedStationInfo(NULL), |
87 iAdvertisementClient(NULL), |
83 iAdvertisementClient(NULL), |
88 iEnableGlobalAdv(true), |
84 iEnableGlobalAdv(true), |
89 iDisconnected(false), |
85 iDisconnected(false), |
90 iConnectingCanceled(false), |
86 iConnectingCanceled(false), |
91 iLocalServer(NULL), |
87 iLoadingNote(NULL), |
92 iLoadingNote(NULL), |
|
93 #ifdef LOCALIZATION |
|
94 iTranslator(NULL), |
|
95 #endif |
|
96 iSystemEventHandler(aSystemEventHandler), |
88 iSystemEventHandler(aSystemEventHandler), |
97 iUseNetworkReason(EIR_UseNetwork_NoReason), |
89 iUseNetworkReason(EIR_UseNetwork_NoReason), |
98 iAppFullyStarted(false), |
90 iAppFullyStarted(false), |
99 #ifdef HS_WIDGET_ENABLED |
91 #ifdef HS_WIDGET_ENABLED |
100 iControlService(NULL), |
92 iControlService(NULL), |
101 iMonitorService(NULL), |
93 iMonitorService(NULL), |
102 #endif |
94 #endif |
103 iFileViewService(NULL), |
95 iFileViewService(NULL), |
104 iMessageBox(NULL) |
96 iMessageBox(NULL), |
|
97 iIsEmbedded(XQServiceUtil::isEmbedded()) |
105 |
98 |
106 { |
99 { |
107 LOG_METHOD; |
100 LOG_METHOD; |
108 |
101 |
109 iViewManager->setApplication(this); |
102 iViewManager->setApplication(this); |
139 */ |
132 */ |
140 IRApplication::~IRApplication() |
133 IRApplication::~IRApplication() |
141 { |
134 { |
142 LOG_METHOD; |
135 LOG_METHOD; |
143 setExitingView(); |
136 setExitingView(); |
144 iViewManager->saveActivity(); |
137 if (iViewManager) |
145 |
138 { |
146 destroyComponents(); |
139 iViewManager->saveActivity(); |
147 |
140 } |
148 if (iLocalServer) |
141 |
149 { |
142 destroyComponents(); |
150 iLocalServer->close(); |
|
151 } |
|
152 |
143 |
153 delete iLastPlayedStationInfo; |
144 delete iLastPlayedStationInfo; |
154 iLastPlayedStationInfo = NULL; |
145 iLastPlayedStationInfo = NULL; |
155 |
146 |
156 delete iLoadingNote; |
147 delete iLoadingNote; |
157 iLoadingNote = NULL; |
148 iLoadingNote = NULL; |
158 |
149 |
159 delete iMessageBox; |
150 delete iMessageBox; |
160 iMessageBox = NULL; |
151 iMessageBox = NULL; |
161 |
152 |
162 delete iSystemEventHandler; |
153 delete iSystemEventHandler; |
163 |
|
164 #ifdef LOCALIZATION |
|
165 if( iTranslator ) |
|
166 { |
|
167 qApp->removeTranslator(iTranslator); |
|
168 delete iTranslator; |
|
169 iTranslator = NULL; |
|
170 } |
|
171 #endif |
|
172 |
|
173 delete iFileViewService; |
154 delete iFileViewService; |
174 iFileViewService = NULL; |
155 iFileViewService = NULL; |
175 |
156 |
176 #ifdef HS_WIDGET_ENABLED |
157 #ifdef HS_WIDGET_ENABLED |
177 XQSettingsManager settingsManager; |
158 if( !iIsEmbedded ) |
178 XQPublishAndSubscribeUtils psUtils(settingsManager); |
159 { |
179 XQPublishAndSubscribeSettingsKey irStartupKey(KInternetRadioPSUid, KInternetRadioStartupKey); |
160 XQSettingsManager settingsManager; |
180 psUtils.deleteProperty(irStartupKey); |
161 XQPublishAndSubscribeUtils psUtils(settingsManager); |
|
162 XQPublishAndSubscribeSettingsKey irStartupKey(KInternetRadioPSUid, KInternetRadioStartupKey); |
|
163 psUtils.deleteProperty(irStartupKey); |
|
164 } |
181 #endif |
165 #endif |
182 } |
166 } |
183 |
167 |
184 |
168 |
185 /* |
169 /* |
207 { |
191 { |
208 iSettings->getStartingViewId(viewId); |
192 iSettings->getStartingViewId(viewId); |
209 if (EIRView_PlayingView == viewId) |
193 if (EIRView_PlayingView == viewId) |
210 { |
194 { |
211 //handle error case |
195 //handle error case |
212 if (NULL == getLastPlayedStationInfo()->getLastPlayedStation()) |
196 IRLastPlayedStationInfo *lastPlayedStationInfo = getLastPlayedStationInfo(); |
|
197 if (lastPlayedStationInfo) |
213 { |
198 { |
214 viewId = EIRView_CategoryView; |
199 IRQPreset *lastPreset = NULL; |
215 } |
200 lastPreset = lastPlayedStationInfo->getLastPlayedStation(); |
|
201 if( NULL == lastPreset ) |
|
202 { |
|
203 viewId = EIRView_CategoryView; |
|
204 } |
|
205 } |
216 } |
206 } |
217 } |
207 } |
218 |
208 |
219 launchStartingView(viewId); |
209 launchStartingView(viewId); |
220 } |
210 } |
375 return iPlayController; |
365 return iPlayController; |
376 } |
366 } |
377 |
367 |
378 IRLastPlayedStationInfo* IRApplication::getLastPlayedStationInfo() |
368 IRLastPlayedStationInfo* IRApplication::getLastPlayedStationInfo() |
379 { |
369 { |
|
370 if( iIsEmbedded ) |
|
371 { |
|
372 return NULL; |
|
373 } |
|
374 |
380 if(NULL == iLastPlayedStationInfo) |
375 if(NULL == iLastPlayedStationInfo) |
381 { |
376 { |
382 iLastPlayedStationInfo = new IRLastPlayedStationInfo(); |
377 iLastPlayedStationInfo = new IRLastPlayedStationInfo(); |
383 } |
378 } |
384 return iLastPlayedStationInfo; |
379 return iLastPlayedStationInfo; |
429 return NULL; |
424 return NULL; |
430 } |
425 } |
431 |
426 |
432 return iFileViewService->getPlayList(); |
427 return iFileViewService->getPlayList(); |
433 } |
428 } |
434 |
|
435 #ifdef LOCALIZATION |
|
436 /* |
|
437 * this function will take ownership of the translator |
|
438 */ |
|
439 void IRApplication::setTranslator(QTranslator* aTranslator) |
|
440 { |
|
441 iTranslator = aTranslator; |
|
442 } |
|
443 #endif |
|
444 |
429 |
445 /* |
430 /* |
446 * Description : create all the application level components, including network controller, |
431 * Description : create all the application level components, including network controller, |
447 * favorites db, isds client, play controller, etc |
432 * favorites db, isds client, play controller, etc |
448 * Parameters : None |
433 * Parameters : None |
450 */ |
435 */ |
451 void IRApplication::createComponents() |
436 void IRApplication::createComponents() |
452 { |
437 { |
453 getSettings(); |
438 getSettings(); |
454 #ifdef HS_WIDGET_ENABLED |
439 #ifdef HS_WIDGET_ENABLED |
455 iControlService = new IrControlService(this); |
440 if( !iIsEmbedded ) |
456 iMonitorService = new IrMonitorService(this); |
441 { |
|
442 iControlService = new IrControlService(this); |
|
443 iMonitorService = new IrMonitorService(this); |
|
444 } |
|
445 |
457 #endif |
446 #endif |
458 } |
447 } |
459 |
448 |
460 /* |
449 /* |
461 * Descriiption : destroy all the application level components |
450 * Descriiption : destroy all the application level components |
607 iUseNetworkReason = EIR_UseNetwork_NoReason; |
596 iUseNetworkReason = EIR_UseNetwork_NoReason; |
608 } |
597 } |
609 |
598 |
610 IRCategoryView *categoryView = static_cast<IRCategoryView*>(getViewManager()->getView(EIRView_CategoryView, true)); |
599 IRCategoryView *categoryView = static_cast<IRCategoryView*>(getViewManager()->getView(EIRView_CategoryView, true)); |
611 categoryView->loadCategory(IRQIsdsClient::EGenre); |
600 categoryView->loadCategory(IRQIsdsClient::EGenre); |
612 } |
|
613 |
|
614 void IRApplication::newLocalSocketConnection() |
|
615 { |
|
616 QLocalSocket *socket = iLocalServer->nextPendingConnection(); |
|
617 if (!socket) |
|
618 { |
|
619 return; |
|
620 } |
|
621 delete socket; |
|
622 |
|
623 iViewManager->raise(); |
|
624 } |
601 } |
625 |
602 |
626 void IRApplication::initApp() |
603 void IRApplication::initApp() |
627 { |
604 { |
628 getNetworkController(); |
605 getNetworkController(); |
633 view->lazyInit(); |
610 view->lazyInit(); |
634 view->launchAction(); |
611 view->launchAction(); |
635 } |
612 } |
636 getMediaKeyObserver(); |
613 getMediaKeyObserver(); |
637 startSystemEventMonitor(); |
614 startSystemEventMonitor(); |
638 startLocalServer(); |
615 |
|
616 |
639 //when IR is running, remove activity. Otherwise user can see two items in task switcher |
617 //when IR is running, remove activity. Otherwise user can see two items in task switcher |
640 iViewManager->removeActivity(); |
618 iViewManager->removeActivity(); |
641 |
619 |
642 #ifdef HS_WIDGET_ENABLED |
620 #ifdef HS_WIDGET_ENABLED |
643 // Write the startup timestamp to P&S key for the homescreen widget |
621 if( !iIsEmbedded ) |
644 XQSettingsManager settingsManager; |
622 { |
645 XQPublishAndSubscribeUtils psUtils(settingsManager); |
623 // Write the startup timestamp to P&S key for the homescreen widget |
646 XQPublishAndSubscribeSettingsKey irStartupKey(KInternetRadioPSUid, KInternetRadioStartupKey); |
624 XQSettingsManager settingsManager; |
647 if (psUtils.defineProperty(irStartupKey, XQSettingsManager::TypeInt)) |
625 XQPublishAndSubscribeUtils psUtils(settingsManager); |
648 { |
626 XQPublishAndSubscribeSettingsKey irStartupKey(KInternetRadioPSUid, KInternetRadioStartupKey); |
649 settingsManager.writeItemValue(irStartupKey, (int)QDateTime::currentDateTime().toTime_t()); |
627 if (psUtils.defineProperty(irStartupKey, XQSettingsManager::TypeInt)) |
650 } |
628 { |
|
629 settingsManager.writeItemValue(irStartupKey, (int)QDateTime::currentDateTime().toTime_t()); |
|
630 } |
|
631 } |
651 #endif |
632 #endif |
652 } |
633 } |
653 |
634 |
654 bool IRApplication::event(QEvent* e) |
635 bool IRApplication::event(QEvent* e) |
655 { |
636 { |
727 bool IRApplication::isAppFullyStarted() const |
708 bool IRApplication::isAppFullyStarted() const |
728 { |
709 { |
729 return iAppFullyStarted; |
710 return iAppFullyStarted; |
730 } |
711 } |
731 |
712 |
|
713 bool IRApplication::isEmbeddedInstance() const |
|
714 { |
|
715 return iIsEmbedded; |
|
716 } |
732 void IRApplication::setExitingView() |
717 void IRApplication::setExitingView() |
733 { |
718 { |
734 TIRViewId viewId = iViewManager->getExitingView(); |
719 TIRViewId viewId = iViewManager->getExitingView(); |
735 if(EIRView_InvalidId != viewId) |
720 if(EIRView_InvalidId != viewId) |
736 { |
721 { |
782 } |
767 } |
783 |
768 |
784 #endif |
769 #endif |
785 |
770 |
786 |
771 |
787 void IRApplication::startLocalServer() |
772 |
788 { |
773 |
789 QString serverName = QCoreApplication::applicationName(); |
|
790 iLocalServer = new QLocalServer(this); |
|
791 connect(iLocalServer, SIGNAL(newConnection()), |
|
792 this, SLOT(newLocalSocketConnection())); |
|
793 |
|
794 if (!iLocalServer->listen(serverName)) |
|
795 { |
|
796 QAbstractSocket::SocketError error = iLocalServer->serverError(); |
|
797 QString fullServerName; |
|
798 fullServerName = QDir::cleanPath(QDir::tempPath()); |
|
799 fullServerName += QLatin1Char('/') + serverName; |
|
800 bool fileExists = QFile::exists(fullServerName); |
|
801 |
|
802 if (error == QAbstractSocket::AddressInUseError && fileExists) |
|
803 { |
|
804 QFile::remove(fullServerName); |
|
805 bool ret = iLocalServer->listen(serverName); |
|
806 //following lines aim to fix coverity errors |
|
807 if (!ret) |
|
808 { |
|
809 Q_ASSERT(false); |
|
810 } |
|
811 } |
|
812 } |
|
813 } |
|
814 |
|
815 bool IRApplication::eventFilter(QObject *object, QEvent *event) |
|
816 { |
|
817 bool eventWasConsumed = false; |
|
818 |
|
819 if (object->objectName() == ABSTRACT_LIST_VIEW_BASE_OBJECT_PLAYINGBANNER) |
|
820 { |
|
821 if (NULL == iViewManager->currentView()) |
|
822 { |
|
823 return false; |
|
824 } |
|
825 |
|
826 if( (EIRView_PlayingView == static_cast<IRBaseView*>(iViewManager->currentView())->id()) \ |
|
827 ||(EIRView_SearchView == static_cast<IRBaseView*>(iViewManager->currentView())->id()) ) |
|
828 { |
|
829 return false; |
|
830 } |
|
831 |
|
832 if (event->type() == QEvent::GraphicsSceneMousePress) |
|
833 { |
|
834 eventWasConsumed = true; |
|
835 Q_ASSERT(iPlayController->isPlaying()); |
|
836 IrAbstractListViewBase* listview = static_cast<IrAbstractListViewBase*>(iViewManager->currentView()); |
|
837 listview->setPlayingBannerTextColor("qtc_multimedia_trans_pressed"); |
|
838 } |
|
839 else if(event->type() == QEvent::GraphicsSceneMouseRelease) |
|
840 { |
|
841 eventWasConsumed = true; |
|
842 Q_ASSERT(iPlayController->isPlaying()); |
|
843 IrAbstractListViewBase* listview = static_cast<IrAbstractListViewBase*>(iViewManager->currentView()); |
|
844 listview->setPlayingBannerTextColor("qtc_multimedia_trans_normal"); |
|
845 iViewManager->activateView(EIRView_PlayingView); |
|
846 } |
|
847 } |
|
848 return eventWasConsumed; |
|
849 } |
|
850 |
774 |
851 void IRApplication::startSystemEventMonitor() |
775 void IRApplication::startSystemEventMonitor() |
852 { |
776 { |
853 connect(iSystemEventHandler, SIGNAL(diskSpaceLowNotification(qint64)), |
777 connect(iSystemEventHandler, SIGNAL(diskSpaceLowNotification(qint64)), |
854 this, SLOT(handleDiskSpaceLow(qint64))); |
778 this, SLOT(handleDiskSpaceLow(qint64))); |