devicemgmtdialogsplugin/src/fotadevicedialogs.cpp
changeset 47 d316aecb87fd
child 52 6e38e48ee756
equal deleted inserted replaced
46:b9b00b134b0d 47:d316aecb87fd
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 #include "devicemanagementnotifierutils.h"
       
    19 #include <hbdocumentloader.h>
       
    20 #include <hbdialog.h>
       
    21 #include <hblabel.h>
       
    22 #include <hbmessagebox.h>
       
    23 #include <HbAction.h>
       
    24 #include <e32Property.h>
       
    25 #include "syncmlnotifierparams.h"
       
    26 #include "fotadevicedialogs.h"
       
    27 #include "PnpUtilLogger.h"
       
    28 #include <QDebug.h>
       
    29 #include <HbListView.h>
       
    30 #include <hbpushbutton.h>
       
    31 #include <e32math.h>
       
    32 #include <QStandardItemModel>
       
    33 
       
    34 
       
    35 // ---------------------------------------------------------------------------
       
    36 // fotadevicedialogs::fotadevicedialogs
       
    37 // Constructor for fota related device dialogs 
       
    38 // ---------------------------------------------------------------------------
       
    39 //
       
    40 
       
    41 fotadevicedialogs::fotadevicedialogs(const QVariantMap &parameters)
       
    42 //:	devicemanagementnotifierwidget(parameters)
       
    43     {
       
    44     qDebug("devicemanagementnotifierutils fotadevicedialogs");
       
    45     QTranslator *translator = new QTranslator();
       
    46     QString lang = QLocale::system().name();
       
    47     QString path = "Z:/resource/qt/translations/";
       
    48     bool fine = translator->load("deviceupdates_" + lang, path);
       
    49     if (fine)
       
    50         qApp->installTranslator(translator); 
       
    51     
       
    52     QTranslator *commontranslator = new QTranslator();
       
    53     fine = commontranslator->load("common_" + lang, path);/*finally required once localisation available*/
       
    54     if(fine)
       
    55         qApp->installTranslator(commontranslator);
       
    56     else
       
    57         qDebug("device dialog common translator loading failed");
       
    58 
       
    59     
       
    60     launchFotaDialog(parameters);
       
    61     }
       
    62 
       
    63 
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // fotadevicedialogs::launchFotaDialog
       
    67 // This function lauches is called to lauch the specific dialog based on the
       
    68 // dialogID passed to it.
       
    69 // ---------------------------------------------------------------------------
       
    70 //
       
    71 void fotadevicedialogs::launchFotaDialog(const QVariantMap &parameters)
       
    72     {
       
    73 
       
    74     QVariantMap::const_iterator i = parameters.constBegin();
       
    75     qDebug("devicemanagementnotifierutils fotadevicedialogs launchDialog");    
       
    76     TFwUpdNoteTypes aType = EFwUpdDeviceBusy;
       
    77     
       
    78     //QString temp = QString::fromUtf8(reinterpret_cast<const char*>(url.Ptr()), url.Length());
       
    79     //TDesC8 * tempStr = KKeyDialog;
       
    80     //const QString temp = QString::fromUtf8(reinterpret_cast<const char*>(tempStr.Ptr()), tempStr.Length());
       
    81     i = parameters.find(keydialog);
       
    82     if(i != parameters.end())
       
    83         aType = (TFwUpdNoteTypes)i.value().toInt();
       
    84     
       
    85     
       
    86     if(aType == EFwUpdRebootNote)
       
    87     	{
       
    88     		createfotainformativedialog(aType,parameters);
       
    89     	}
       
    90     	else if(aType == EFwUpdResumeDownload || aType == EFwUpdResumeUpdate)
       
    91         {
       
    92         createfotaconfirmationdialog(aType,parameters);
       
    93         //createfotainformativedialog();
       
    94         }
       
    95     else if(aType == EFwDLNeedMoreMemory || aType == EFwDLConnectionFailure || aType == EFwDLGeneralFailure || 
       
    96     	 aType == EFwUpdNotEnoughBattery || aType == EFwUpdDeviceBusy || aType == EFwUpdSuccess || aType == EFwUpdNotCompatible
       
    97     || aType == EFwDLNonResumableFailure)
       
    98         {
       
    99         //createfotamessagedialog();
       
   100         createfotamessagedialog(aType,parameters);
       
   101         }
       
   102     }
       
   103 
       
   104 
       
   105 // ---------------------------------------------------------------------------
       
   106 // fotadevicedialogs::createfotainformativedialog
       
   107 // This function is called to show the informative dialog of FOTA
       
   108 // ---------------------------------------------------------------------------
       
   109 //
       
   110 void fotadevicedialogs::createfotainformativedialog(TFwUpdNoteTypes aType,const QVariantMap &parameters)
       
   111     {
       
   112     qDebug("createserveralertinformative start");
       
   113 		LOGSTRING("createserveralertinformative start");
       
   114     HbDocumentLoader loader;
       
   115     bool ok = false;
       
   116     loader.load(":/xml/resources/fotainformativedialog.docml", &ok);
       
   117     if (!ok)
       
   118         {
       
   119         return;
       
   120         }
       
   121     HbDialog *dialog = qobject_cast<HbDialog *> (loader.findWidget("dialog"));
       
   122 
       
   123     HbLabel *content = qobject_cast<HbLabel *> (loader.findWidget(
       
   124             "lblContent"));
       
   125 
       
   126     // No translations required
       
   127     //content->setPlainText("Testing");
       
   128 
       
   129     dialog->setTimeout(3000);
       
   130 
       
   131     if (dialog)
       
   132         dialog->show();
       
   133 
       
   134     QObject::connect(dialog, SIGNAL(aboutToClose()), this, SLOT(okSelected()));
       
   135 
       
   136 	qDebug("createserveralertinformative end");
       
   137 
       
   138     }
       
   139 
       
   140 
       
   141 
       
   142 // ---------------------------------------------------------------------------
       
   143 // fotadevicedialogs::createfotaconfirmationdialog
       
   144 // This function is called to show the confirmation dialog of FOTA.
       
   145 // ---------------------------------------------------------------------------
       
   146 //
       
   147 void fotadevicedialogs::createfotaconfirmationdialog(TFwUpdNoteTypes aType,const QVariantMap &parameters)
       
   148     {
       
   149     qDebug("createserveralertinformative start");
       
   150         LOGSTRING("createserveralertinformative start");
       
   151         
       
   152     QVariantMap::const_iterator i;
       
   153     HbDocumentLoader loader;
       
   154     bool ok = false;
       
   155     HbDialog *dialog = NULL;
       
   156     
       
   157     QString param1;
       
   158     QString param2;
       
   159     TInt size = 0;
       
   160     TBool postpone = 0;
       
   161 
       
   162     i = parameters.find(keyparam1);
       
   163     if(i != parameters.end())
       
   164         size = i.value().toInt();
       
   165 
       
   166     i = parameters.find(keyparam2);
       
   167     if(i != parameters.end())
       
   168         param1 = i.value().toString();
       
   169     i = parameters.find(keyparam3);
       
   170     if(i != parameters.end())
       
   171         param2 = i.value().toString();
       
   172     i = parameters.find(keyparam4);
       
   173     if(i != parameters.end())
       
   174         postpone = i.value().toBool();
       
   175 
       
   176     
       
   177     switch(aType)
       
   178         {
       
   179         case EFwUpdResumeDownload:
       
   180             {          
       
   181             loader.load(":/xml/resources/fotasoftkeysdialog.docml", &ok);
       
   182             if (!ok)
       
   183             {
       
   184             return;
       
   185             }
       
   186             dialog = qobject_cast<HbDialog *> (loader.findWidget("dialog"));
       
   187             
       
   188             HbLabel *headingString = qobject_cast<HbLabel *> (loader.findWidget(
       
   189                                 "lblDialogHeading"));
       
   190             
       
   191             headingString->setPlainText(hbTrId("txt_device_update_title_device_update"));
       
   192             
       
   193             HbLabel *contentString = qobject_cast<HbLabel *> (loader.findWidget(
       
   194                                 "lblDialogContent"));
       
   195             
       
   196             TReal sizeRounded = 0;
       
   197             TReal sizeKB = size / 1024;
       
   198             if(sizeKB > 1024)
       
   199                 {
       
   200                 TReal sizeMB = sizeKB / 1024;
       
   201                 Math::Round(sizeRounded,sizeMB,2);
       
   202                 QString str = hbTrId("txt_device_update_info_the_last_updte_incomp_dwnld_Mb")
       
   203                         //.arg(param1).arg(param2).arg(sizeMB);
       
   204                         .arg(param2).arg(param1).arg(sizeRounded);
       
   205                 contentString->setPlainText(str);//HACK
       
   206                 }
       
   207             else
       
   208                 {
       
   209                 Math::Round(sizeRounded,sizeKB,2);
       
   210                 contentString->setPlainText(hbTrId("txt_device_update_info_the_last_update_incomplete_dwnld_kb")
       
   211                         .arg(param1).arg(param2).arg(sizeRounded));
       
   212                 }
       
   213             //HbAction *primaryAction = dialog->primaryAction();
       
   214             HbAction *primaryAction = (HbAction *) dialog->actions().first();
       
   215             primaryAction->setText(hbTrId("txt_common_button_continue_dialog"));
       
   216 
       
   217             //HbAction *secondaryAction = dialog->secondaryAction();
       
   218             HbAction *secondaryAction = (HbAction *) dialog->actions().at(1);
       
   219             secondaryAction->setText(hbTrId("txt_device_update_button_resume_later"));
       
   220             if(!postpone)
       
   221                 secondaryAction->setEnabled(postpone);
       
   222 
       
   223             dialog->setTimeout(HbPopup::NoTimeout);
       
   224             dialog->setDismissPolicy(HbPopup::NoDismiss);
       
   225 
       
   226             QObject::connect(primaryAction, SIGNAL(triggered()), this,
       
   227                     SLOT(fotaLSK()));
       
   228 
       
   229             QObject::connect(secondaryAction, SIGNAL(triggered()), this,
       
   230                     SLOT(fotaRSK()));
       
   231             break;
       
   232             }
       
   233         case EFwUpdResumeUpdate:
       
   234             {
       
   235             bool ok = false;
       
   236                 loader.load(":/xml/resources/fotaresumeupdate.docml", &ok);
       
   237                 if (!ok)
       
   238                     {
       
   239                     return;
       
   240                     }
       
   241                 
       
   242                 dialog = qobject_cast<HbDialog *> (loader.findWidget("dialog"));
       
   243                 
       
   244                 dialog->setTimeout(HbPopup::NoTimeout);
       
   245                 dialog->setDismissPolicy(HbPopup::NoDismiss);
       
   246                 
       
   247                 HbLabel *headingString = qobject_cast<HbLabel *> (loader.findWidget(
       
   248                         "lblHeading"));
       
   249                 headingString->setPlainText(hbTrId("txt_device_update_title_device_update"));
       
   250                             
       
   251                 
       
   252                 //HbAction *primaryAction = dialog->primaryAction();
       
   253                 HbAction *primaryAction = (HbAction *) dialog->actions().first();
       
   254                 primaryAction->setText(hbTrId("txt_common_button_continue_dialog"));
       
   255                 
       
   256                 //HbAction *secondaryAction = dialog->secondaryAction();
       
   257                 HbAction *secondaryAction = (HbAction *) dialog->actions().at(1);
       
   258                 secondaryAction->setText(hbTrId("txt_device_update_button_resume_later"));
       
   259                 if(!postpone)
       
   260                     secondaryAction->setEnabled(postpone);
       
   261                 
       
   262                 HbLabel *contentSwDetails = qobject_cast<HbLabel *> (loader.findWidget(
       
   263                                                 "label"));
       
   264                 TReal sizeRounded = 0;
       
   265                 TReal sizeKB = size / 1024;
       
   266                 
       
   267                 QString content;
       
   268                 if(sizeKB > 1024)
       
   269                     {
       
   270                     TReal sizeMB = sizeKB / 1024;
       
   271                     Math::Round(sizeRounded,sizeMB,2);
       
   272                     contentSwDetails->setPlainText(hbTrId("txt_device_update_info_the_last_update_incomp_instal_Mb")
       
   273                             .arg(param1).arg(param2).arg(sizeRounded));
       
   274                     }
       
   275                 else
       
   276                     {
       
   277                     Math::Round(sizeRounded,sizeKB,2);
       
   278                     contentSwDetails->setPlainText(hbTrId("txt_device_update_info_the_last_update_incomp_instal_kb")
       
   279                             .arg(param1).arg(param2).arg(sizeRounded));
       
   280                     }
       
   281                 
       
   282                 HbLabel *contentCharger = qobject_cast<HbLabel *> (loader.findWidget(
       
   283                                                                 "label_3"));
       
   284                 contentCharger->setPlainText(hbTrId("txt_device_update_info_it_is_recommended_to_connec"));
       
   285                 
       
   286                 HbLabel *contentInstall = qobject_cast<HbLabel *> (loader.findWidget(
       
   287                                                                 "label_2"));
       
   288                 contentInstall->setPlainText(hbTrId("txt_device_update_info_after_the_installation_the"));
       
   289                 
       
   290                 HbLabel *contentEmergency = qobject_cast<HbLabel *> (loader.findWidget(
       
   291                                                                 "label_1"));
       
   292                 contentEmergency->setPlainText(hbTrId("txt_device_update_info_during_the_installation_the"));
       
   293 
       
   294                 dialog->setTimeout(HbPopup::NoTimeout);
       
   295 
       
   296                 QObject::connect(primaryAction, SIGNAL(triggered()), this,
       
   297                         SLOT(fotaLSK()));
       
   298 
       
   299                 QObject::connect(secondaryAction, SIGNAL(triggered()), this,
       
   300                         SLOT(fotaRSK()));
       
   301             }
       
   302             break;
       
   303         default:
       
   304             {
       
   305             break;
       
   306             }
       
   307         }
       
   308 
       
   309     if (dialog)
       
   310         dialog->show();
       
   311 
       
   312     qDebug("createserveralertinformative end");
       
   313 
       
   314     }
       
   315 
       
   316 
       
   317 // ---------------------------------------------------------------------------
       
   318 // fotadevicedialogs::createfotamessagedialog
       
   319 // This function is called to show the message dialog of FOTA
       
   320 // ---------------------------------------------------------------------------
       
   321 //
       
   322 void fotadevicedialogs::createfotamessagedialog(TFwUpdNoteTypes aType,const QVariantMap &parameters)
       
   323     {
       
   324     QVariantMap::const_iterator i;
       
   325     qDebug("createserveralertinformative start");
       
   326         LOGSTRING("createserveralertinformative start");
       
   327     HbDocumentLoader loader;
       
   328     bool ok = false;
       
   329     loader.load(":/xml/resources/fotasoftkeydialog.docml", &ok);
       
   330     if (!ok)
       
   331         {
       
   332         return;
       
   333         }
       
   334     HbDialog *dialog = qobject_cast<HbDialog *> (loader.findWidget("dialog"));
       
   335     
       
   336     HbLabel *headingString = qobject_cast<HbLabel *> (loader.findWidget(
       
   337             "lblHeaind"));
       
   338     headingString->setPlainText(hbTrId("txt_device_update_title_device_update"));
       
   339     
       
   340     HbLabel *contentString = qobject_cast<HbLabel *> (loader.findWidget(
       
   341             "lblContent"));
       
   342             
       
   343     dialog->setTimeout(HbPopup::NoTimeout);
       
   344     dialog->setDismissPolicy(HbPopup::NoDismiss);
       
   345     
       
   346     //HbAction *primaryAction = dialog->primaryAction();
       
   347     HbAction *primaryAction = (HbAction *) dialog->actions().first();
       
   348     primaryAction->setText(hbTrId("txt_common_button_ok_single_dialog"));
       
   349 
       
   350     QObject::connect(primaryAction, SIGNAL(triggered()), this,
       
   351                 SLOT(fotaLSK()));
       
   352                 
       
   353                 
       
   354     switch(aType)
       
   355         {
       
   356         	case EFwDLNeedMoreMemory:
       
   357             {
       
   358             QString content;
       
   359             TInt aMemNeeded = 0;
       
   360             i = parameters.find(keyparam1);
       
   361             if(i != parameters.end())
       
   362                 aMemNeeded = i.value().toInt();
       
   363             TInt aMemNeededKB = aMemNeeded / 1024;
       
   364             if(aMemNeededKB <= 1024)
       
   365                 {
       
   366                 content = hbTrId("txt_de_info_l1_kb_free_memory_needed_for_update").arg(aMemNeededKB);
       
   367                 }
       
   368             else
       
   369                 {
       
   370                 TInt aMemNeededMB = aMemNeededKB / 1024;
       
   371                 content = hbTrId("txt_de_info_l1_Mb_free_memory_needed_for_update").arg(aMemNeededMB);
       
   372                 }
       
   373             contentString->setPlainText(content);
       
   374             break;
       
   375             }
       
   376         case EFwDLConnectionFailure:
       
   377             {
       
   378             contentString->setPlainText(hbTrId("txt_device_update_info_connection_lost_while_do"));
       
   379             break;
       
   380             }
       
   381         case EFwDLGeneralFailure:
       
   382             {
       
   383             contentString->setPlainText(hbTrId("txt_device_update_info_an_error_occurred_during_do"));
       
   384             break;
       
   385             }
       
   386         case EFwDLNonResumableFailure:
       
   387             {
       
   388             contentString->setPlainText(hbTrId("txt_device_update_info_an_error_occurred_update_stop"));
       
   389             break;
       
   390             }
       
   391         case EFwUpdDeviceBusy:
       
   392             {
       
   393             contentString->setPlainText(hbTrId("txt_device_update_info_FS_warning_device_memory_is_b"));
       
   394             break;
       
   395             }
       
   396        case EFwUpdSuccess:
       
   397            {
       
   398            headingString->setPlainText(hbTrId("txt_device_update_title_phone_uptodate"));
       
   399            contentString->setPlainText(hbTrId("txt_device_update_info_your_phone_is_now_updated_w"));
       
   400            break;
       
   401            }
       
   402        case EFwUpdNotCompatible:
       
   403            {           
       
   404            contentString->setPlainText(hbTrId("txt_device_update_info_the_phone_was_not_updated"));
       
   405            break;
       
   406            }
       
   407        case EFwUpdNotEnoughBattery:
       
   408            {
       
   409            contentString->setPlainText(hbTrId("txt_device_update_info_you_will_be_notified_once_t"));
       
   410            break;
       
   411            }
       
   412        default:
       
   413            {
       
   414            break;
       
   415            }
       
   416         }
       
   417 
       
   418     if (dialog)
       
   419         dialog->show();
       
   420 
       
   421     qDebug("createserveralertinformative end");
       
   422 
       
   423     }
       
   424 
       
   425 
       
   426 // ---------------------------------------------------------------------------
       
   427 // fotadevicedialogs::fotaLSK
       
   428 // This slot is called when LSK is pressed in device dialog.
       
   429 // ---------------------------------------------------------------------------
       
   430 //
       
   431 void fotadevicedialogs::fotaLSK()
       
   432     {
       
   433     qDebug("ok selected");
       
   434     QVariantMap resultMap;
       
   435     resultMap.insert(returnkey, EHbLSK);
       
   436     emit deviceDialogData(resultMap);
       
   437     }
       
   438 
       
   439 
       
   440 
       
   441 // ---------------------------------------------------------------------------
       
   442 // CFotaDownloadNotifHandler::aboutToClose
       
   443 // This slot is called when RSK is pressed in device dialog.
       
   444 // ---------------------------------------------------------------------------
       
   445 //
       
   446 void fotadevicedialogs::fotaRSK()
       
   447     {
       
   448     qDebug("cancel selected");
       
   449     QVariantMap resultMap;
       
   450     resultMap.insert(returnkey, EHbRSK);
       
   451     emit deviceDialogData(resultMap);
       
   452     }
       
   453 
       
   454 
       
   455 
       
   456 // Set parameters
       
   457 bool fotadevicedialogs::setDeviceDialogParameters(
       
   458     const QVariantMap &parameters)
       
   459 {
       
   460     
       
   461     return true;
       
   462 }
       
   463 
       
   464 // Get error
       
   465 int fotadevicedialogs::deviceDialogError() const
       
   466 {
       
   467     
       
   468     return 0;
       
   469 }
       
   470 
       
   471 
       
   472 // Close device dialog
       
   473 // ---------------------------------------------------------------------------
       
   474 // fotadevicedialogs::closeDeviceDialog
       
   475 // This slot is called when device dialog is closed due to errors.
       
   476 // ---------------------------------------------------------------------------
       
   477 //
       
   478 
       
   479 void fotadevicedialogs::closeDeviceDialog(bool byClient)
       
   480 {
       
   481 		qDebug("cancel selected");
       
   482     emit deviceDialogClosed();
       
   483 }
       
   484 
       
   485 
       
   486 // Return display widget
       
   487 HbDialog *fotadevicedialogs::deviceDialogWidget() const
       
   488 {
       
   489    
       
   490     return const_cast<fotadevicedialogs*>(this);
       
   491     //return const_cast<devicemanagementnotifierwidget*>(this);
       
   492 }