qtinternetradio/ui/src/main.cpp
changeset 14 896e9dbc5f19
parent 12 608f67c22514
child 16 5723da102db1
equal deleted inserted replaced
12:608f67c22514 14:896e9dbc5f19
    16 */
    16 */
    17 
    17 
    18 #include <hbapplication.h>
    18 #include <hbapplication.h>
    19 #include <hbdevicemessagebox.h>
    19 #include <hbdevicemessagebox.h>
    20 #include <QLocalSocket>
    20 #include <QLocalSocket>
    21 #include <hbsplashscreen.h>
    21 #include <hbsplashscreen.h> 
    22 #include <QSettings>
    22 #include <hbtranslator.h> 
       
    23 
       
    24 #include <xqserviceutil.h>
    23 
    25 
    24 #include "irviewmanager.h"
    26 #include "irviewmanager.h"
    25 #include "irapplication.h"
    27 #include "irapplication.h"
    26 #include "irmemorycollector.h"
    28 #include "irmemorycollector.h"
    27 #include "irqlogger.h"
    29 #include "irqlogger.h"
    28 #include "irqsystemeventhandler.h"
    30 #include "irqsystemeventhandler.h"
    29 #include "irqsettings.h"
    31 #include "irqsettings.h"
    30 #include "irservicedef.h"
    32 #include "irservicedef.h"
       
    33 #include "irviewdefinitions.h"
       
    34 #include "irqsettings.h" 
    31 
    35 
    32 #ifdef LOCALIZATION 
    36 bool isDiskSpaceLow(IRQSystemEventHandler* aEventHandler); 
    33 #include <QTranslator> 
    37 void startSplashScreen();
    34 void initLanguage(QTranslator*& aTranslator);
    38 TIRViewId getSplashViewID(); 
    35 #endif
       
    36 
       
    37 bool isDiskSpaceLow(IRQSystemEventHandler* aEventHandler);
       
    38 bool isSecondInstance();
       
    39 void setSplashScreen();
       
    40 bool isSplashNowplaying();
       
    41 
    39 
    42 int main(int argc, char* argv[])
    40 int main(int argc, char* argv[])
    43 {
    41 {   
    44     installLogDir();
    42     int  result = 0;
       
    43 	  
    45     
    44     
    46     INSTALL_MESSAGE_HANDLER;
    45     installLogDir();    
    47     //the following is for splash screen, this must be placed 
    46     INSTALL_MESSAGE_HANDLER;   
    48     //before the creating of HbApplication
    47   
    49     setSplashScreen(); 
    48     HbApplication app(argc, argv, Hb::NoSplash);
    50     
    49     HbTranslator* translator = new HbTranslator();
    51     HbApplication app(argc, argv);
       
    52     
       
    53 #ifdef LOCALIZATION    
       
    54     QTranslator* translator = NULL;
       
    55     initLanguage(translator);
       
    56     Q_ASSERT( NULL != translator );
    50     Q_ASSERT( NULL != translator );
    57 #endif
    51     translator->loadCommon(); 
    58     
    52      
    59 #ifdef SUBTITLE_STR_BY_LOCID
    53 	  //we start the splash screen here for the translator will be 
    60     QCoreApplication::setApplicationName(hbTrId("txt_irad_title_internet_radio"));
    54 	  //installed ok only after the HbApplication is constructed ready
    61 #else
    55     startSplashScreen();  
    62     QCoreApplication::setApplicationName(hbTrId("Internet radio"));    
       
    63 #endif
       
    64     if (isSecondInstance())
       
    65     {
       
    66         return 0;
       
    67     }
       
    68     
    56     
    69     //for the note should be translated too     
    57     //for the note should be translated too     
    70     IRQSystemEventHandler *systemEventHandler = new IRQSystemEventHandler();
    58     IRQSystemEventHandler *systemEventHandler = new IRQSystemEventHandler();
    71     if( isDiskSpaceLow(systemEventHandler) )
    59     if( isDiskSpaceLow(systemEventHandler) )
    72     {       
    60     {         
    73 #ifdef LOCALIZATION   
       
    74         qApp->removeTranslator(translator);
       
    75         delete translator;
    61         delete translator;
    76 #endif
       
    77         delete systemEventHandler;
    62         delete systemEventHandler;
    78         return 0;
    63         return 0;
    79     }
    64     }
    80 
    65 
    81     IRViewManager *mainWindow = new IRViewManager;    
    66     IRViewManager *mainWindow = new IRViewManager;    
    82     mainWindow->show();
    67     mainWindow->show();
    83     
    68     
    84     //here, we transfer the ownership of the event handler to the irapp
    69     //here, we transfer the ownership of the event handler to the irapp
    85     IRApplication *irapp = new IRApplication(mainWindow, systemEventHandler);
    70     IRApplication *irapp = new IRApplication(mainWindow, systemEventHandler);    
    86     
       
    87 #ifdef LOCALIZATION
       
    88     //this function will transfer the ownership of translator to irapp
       
    89     irapp->setTranslator(translator);
       
    90 #endif
       
    91     
       
    92     IRMemoryCollector mc(irapp);
    71     IRMemoryCollector mc(irapp);
    93     
    72     
    94     if(!mainWindow->isExiting())
    73     if(!mainWindow->isExiting())
    95     {
    74     {
    96         return app.exec();
    75         result =  app.exec();                  
    97     }
    76     }    
    98 	return 0;
    77             
       
    78     delete translator; 
       
    79 	  return result;
    99 }
    80 }
   100 
    81 
   101 bool isDiskSpaceLow(IRQSystemEventHandler* aEventHandler)
    82 bool isDiskSpaceLow(IRQSystemEventHandler* aEventHandler)
   102 {     
    83 {     
   103     bool ret = aEventHandler->isBelowCriticalLevel();
    84     bool ret = aEventHandler->isBelowCriticalLevel();
   112 #endif
    93 #endif
   113         messageBox.setTimeout(HbPopup::NoTimeout);
    94         messageBox.setTimeout(HbPopup::NoTimeout);
   114         messageBox.exec();
    95         messageBox.exec();
   115     }
    96     }
   116     return ret;
    97     return ret;
       
    98 } 
       
    99 
       
   100 void startSplashScreen()
       
   101 {   
       
   102     TIRViewId viewId = getSplashViewID();    
       
   103     switch( viewId )
       
   104     {
       
   105     case EIRView_PlayingView:
       
   106          HbSplashScreen::setScreenId("nowplaying_screen");
       
   107          break;
       
   108     case EIRView_CategoryView:      
       
   109     case EIRView_FavoritesView:       
       
   110     case EIRView_MainView: 
       
   111     default: 
       
   112         HbSplashScreen::setScreenId("normal_screen");
       
   113         break;    
       
   114     } 
       
   115     
       
   116     HbSplashScreen::start();
   117 }
   117 }
   118 
   118 
   119 #ifdef LOCALIZATION 
   119 TIRViewId getSplashViewID()
   120 void initLanguage(QTranslator*& aTranslator)
   120 { 
   121 {
   121     TIRViewId startingViewID;
   122     aTranslator = new QTranslator();    
   122     IRQSettings *settings = IRQSettings::openInstance();
   123     QString lang = QLocale::system().name();
   123     settings->getStartingViewId(startingViewID);
   124     LOG_FORMAT( "Current language is %s", STRING2CHAR(lang) );
   124     settings->closeInstance();
   125     QString path = "z:/resource/qt/translations/";  //this will be changed to a micro in future
   125     return startingViewID;    
   126     bool ret = aTranslator->load(path + "internet_radio_10_1_" + lang);        
       
   127     qApp->installTranslator(aTranslator); 
       
   128 }
       
   129 #endif
       
   130 
       
   131 bool isSecondInstance()
       
   132 {
       
   133     QLocalSocket socket;
       
   134     QString serverName = QCoreApplication::applicationName();
       
   135     socket.connectToServer(serverName);
       
   136     if (socket.waitForConnected(500))
       
   137     {
       
   138         return true;
       
   139     }
       
   140     else
       
   141     {
       
   142         return false;
       
   143     }
       
   144 }
   126 }
   145 
   127 
   146 void setSplashScreen()
       
   147 {     
       
   148     if( isSplashNowplaying() )
       
   149     {
       
   150         HbSplashScreen::setScreenId("nowplaying_screen");
       
   151     }
       
   152     else
       
   153     {
       
   154         HbSplashScreen::setScreenId("normal_screen");
       
   155     }    
       
   156 }
       
   157 
       
   158 bool isSplashNowplaying()
       
   159 {
       
   160     QSettings settings(KIrSettingOrganization, KIrSettingApplication);
       
   161     return settings.value(KIrSettingSplashNowplaying,false).toBool();
       
   162 }
       
   163  
   128  
       
   129