qtinternetradio/ui/src/main.cpp
changeset 3 ee64f059b8e1
parent 0 09774dfdd46b
child 5 0930554dc389
equal deleted inserted replaced
2:2e1adbfc62af 3:ee64f059b8e1
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 #include <hbapplication.h>
    18 #include <hbapplication.h>
    19 #include <hbdevicemessagebox.h>
    19 #include <hbdevicemessagebox.h>
       
    20 #include <QLocalSocket>
       
    21 
    20 #include "irviewmanager.h"
    22 #include "irviewmanager.h"
    21 #include "irapplication.h"
    23 #include "irapplication.h"
    22 #include "irqdiskspacewatcher.h"
       
    23 #include "irmemorycollector.h"
    24 #include "irmemorycollector.h"
    24 #include "irsymbianapplication.h"
       
    25 #include "irqlogger.h"
    25 #include "irqlogger.h"
       
    26 #include "irqsystemeventhandler.h"
    26 
    27 
    27 bool isDiskSpaceLow();
    28 #ifdef LOCALIZATION 
       
    29 #include <QTranslator> 
       
    30 void initLanguage(QTranslator*& aTranslator);
       
    31 #endif
       
    32 
       
    33 bool isDiskSpaceLow(IRQSystemEventHandler* aEventHandler);
       
    34 bool isSecondInstance();
    28 
    35 
    29 int main(int argc, char* argv[])
    36 int main(int argc, char* argv[])
    30 {
    37 {
    31     INSTALL_MESSAGE_HANDLER;
    38     INSTALL_MESSAGE_HANDLER;
       
    39     HbApplication app(argc, argv);
    32     
    40     
    33     QCoreApplication::setApplicationName("InternetRadioApplication");
    41 #ifdef LOCALIZATION    
    34     HbApplication app(newS60Application, argc, argv);
    42     QTranslator* translator = NULL;
    35     if (IRSymbianApplication::getInstance()->getInstanceFlag())
    43     initLanguage(translator);
       
    44     Q_ASSERT( NULL != translator );
       
    45 #endif
       
    46     
       
    47     QCoreApplication::setApplicationName(hbTrId("txt_irad_title_internet_radio"));
       
    48     if (isSecondInstance())
    36     {
    49     {
    37         return 0;
    50         return 0;
    38     }
    51     }
    39     
    52     
    40     if(isDiskSpaceLow())
    53     //for the note should be translated too     
       
    54     IRQSystemEventHandler *systemEventHandler = new IRQSystemEventHandler();
       
    55     if( isDiskSpaceLow(systemEventHandler) )
    41     {       
    56     {       
       
    57 #ifdef LOCALIZATION   
       
    58         qApp->removeTranslator(translator);
       
    59         delete translator;
       
    60 #endif
       
    61         delete systemEventHandler;
    42         return 0;
    62         return 0;
    43     }  
    63     }
    44 
    64 
    45     IRViewManager *mainWindow = new IRViewManager;
    65     IRViewManager *mainWindow = new IRViewManager;    
    46     
       
    47     mainWindow->show();
    66     mainWindow->show();
    48     
    67     
    49     //when constructing irapp, OpenFileL() has already been called
    68     //here, we transfer the ownership of the event handler to the irapp
    50     IRApplication *irapp = new IRApplication(mainWindow);
    69     IRApplication *irapp = new IRApplication(mainWindow, systemEventHandler);
       
    70     
       
    71 #ifdef LOCALIZATION
       
    72     //this function will transfer the ownership of translator to irapp
       
    73     irapp->setTranslator(translator);
       
    74 #endif
    51     
    75     
    52     IRMemoryCollector mc(irapp);
    76     IRMemoryCollector mc(irapp);
    53     
    77     
    54     if(!mainWindow->isExiting())
    78     if(!mainWindow->isExiting())
    55     {
    79     {
    56         return app.exec();
    80         return app.exec();
    57     }
    81     }
    58 	return 0;
    82 	return 0;
    59 }
    83 }
    60 
    84 
    61 bool isDiskSpaceLow()
    85 bool isDiskSpaceLow(IRQSystemEventHandler* aEventHandler)
    62 {
    86 {     
    63     IRQDiskSpaceWatcher diskSpaceWatcher;
    87     bool ret = aEventHandler->isBelowCriticalLevel();
    64     bool ret = diskSpaceWatcher.isBelowCriticalLevel();
       
    65     if(ret)
    88     if(ret)
    66     {
    89     {
    67         HbDeviceMessageBox messageBox(hbTrId("txt_irad_info_no_space_on_c_drive_internet_radio_closed"),
    90         HbDeviceMessageBox messageBox(hbTrId("txt_irad_info_no_space_on_c_drive_internet_radio_closed"),
    68                 HbMessageBox::MessageTypeWarning);
    91                 HbMessageBox::MessageTypeWarning);
    69         messageBox.setTimeout(HbPopup::NoTimeout);
    92         messageBox.setTimeout(HbPopup::NoTimeout);
    70         messageBox.exec();
    93         messageBox.exec();
    71     }
    94     }
    72     return ret;
    95     return ret;
    73 }
    96 }
    74 
    97 
       
    98 #ifdef LOCALIZATION 
       
    99 void initLanguage(QTranslator*& aTranslator)
       
   100 {
       
   101     aTranslator = new QTranslator();    
       
   102     QString lang = QLocale::system().name();
       
   103     LOG_FORMAT( "Current language is %s", STRING2CHAR(lang) );
       
   104     QString path = "z:/resource/qt/translations/";  //this will be changed to a micro in future
       
   105     bool ret = aTranslator->load(path + "internet_radio_10_1_" + lang);        
       
   106     qApp->installTranslator(aTranslator); 
       
   107 }
       
   108 #endif
       
   109 
       
   110 bool isSecondInstance()
       
   111 {
       
   112     QLocalSocket socket;
       
   113     QString serverName = QCoreApplication::applicationName();
       
   114     socket.connectToServer(serverName);
       
   115     if (socket.waitForConnected(500))
       
   116     {
       
   117         return true;
       
   118     }
       
   119     else
       
   120     {
       
   121         return false;
       
   122     }
       
   123 }