devicemgmtdialogsplugin/src/devicemanagementnotifierutils.cpp
branchRCL_3
changeset 57 6757f1e2efd2
equal deleted inserted replaced
55:c4687ff85147 57:6757f1e2efd2
       
     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 <qdebug.h>
       
    26 #include <devicedialogsymbian.h>
       
    27 #include "pnputillogger.h"
       
    28 #include "omacppinquerydialog.h"
       
    29 #include "devicemanagementnotifierwidget_p.h"
       
    30  enum TSyncmlHbNotifierKeys 
       
    31 		{
       
    32 
       
    33      EHbSOSNotifierKeyStatus = 11, // status set will complete the client subscribe
       
    34      EHbSOSNotifierKeyStatusReturn = 12, // Return the content of actual status value accepted from UI
       
    35      
       
    36      EHbDMSyncNotifierKeyStatus = 13,
       
    37      EHbDMSyncNotifierKeyStatusReturn = 14
       
    38 		};
       
    39 
       
    40 
       
    41 devicemanagementnotifierutils::devicemanagementnotifierutils(devicemanagementnotifierwidget* ptr,
       
    42         const QVariantMap &parameters)
       
    43     {
       
    44 	qDebug("devicemanagementnotifierutils");
       
    45 	LOGSTRING("devicemanagementnotifierutils");
       
    46 	
       
    47 	QVariantMap::const_iterator i = parameters.constBegin();
       
    48     int notifiertolaunch = 0;
       
    49 	while (i != parameters.constEnd())
       
    50         {
       
    51             if (i.key().toAscii() == "syncmlfw")
       
    52                 {
       
    53 
       
    54             notifiertolaunch = i.value().toInt();
       
    55                // profileidenabled = true;
       
    56                 }           
       
    57             ++i;
       
    58             }
       
    59     if(notifiertolaunch == 1000001 )// Connecting dialog
       
    60         {
       
    61     connectDialog = new syncmlConnectNotifier(ptr);
       
    62     	 connectDialog->launchDialog(parameters);
       
    63     	 notifier = NULL;
       
    64         }
       
    65         
       
    66     else 
       
    67         {
       
    68     notifier = new syncmlnotifier(ptr);
       
    69        notifier->launchDialog(parameters);
       
    70        connectDialog = NULL;
       
    71         }
       
    72         }
       
    73 devicemanagementnotifierutils::~devicemanagementnotifierutils()
       
    74     {
       
    75     qDebug("devicemanagementnotifierutils::~devicemanagementnotifierutils");
       
    76     if(notifier)
       
    77     delete notifier;
       
    78     if(connectDialog)
       
    79     delete connectDialog;
       
    80     }
       
    81 
       
    82 syncmlnotifier::syncmlnotifier(devicemanagementnotifierwidget* ptr)
       
    83     {
       
    84     iPtr = ptr;
       
    85     mDefaultServerPkgZero = false;
       
    86     qDebug("devicemanagementnotifierutils syncmlnotifier");
       
    87     QTranslator *translator = new QTranslator();
       
    88     QString lang = QLocale::system().name();
       
    89     QString path = "Z:/resource/qt/translations/";
       
    90     bool fine = translator->load("deviceupdates_en.qm", path);
       
    91     if (fine)
       
    92         qApp->installTranslator(translator);
       
    93 
       
    94     QTranslator *commontranslator = new QTranslator();
       
    95 
       
    96     fine = commontranslator->load("common_" + lang, path);
       
    97     if (fine)
       
    98         qApp->installTranslator(commontranslator);
       
    99 
       
   100     msymnotifier = new syncmlnotifierprivate();
       
   101     
       
   102     }
       
   103 
       
   104 void syncmlnotifier::launchDialog(const QVariantMap &parameters)
       
   105     {
       
   106 
       
   107     QVariantMap::const_iterator i = parameters.constBegin();
       
   108     qDebug("devicemanagementnotifierutils syncmlnotifier launchDialog");
       
   109     //i++;
       
   110 
       
   111     bool profileidenabled = false;
       
   112     bool uiserverinteraction = false;
       
   113     bool serverpushinformativeenabled = false;
       
   114     bool serverpushinteractiveenabled = false;
       
   115     bool scomonotifierenabled = false;
       
   116     
       
   117     int profileid = 0;
       
   118     int uimode = 0;
       
   119 
       
   120     QString serverpushinformmessage;
       
   121     QString serverpushconfirmmessage;
       
   122     QString appname = NULL;
       
   123     QString size = NULL;
       
   124     QString sizeformat = NULL;
       
   125     QString data = NULL;
       
   126     QString serverdispname;
       
   127     bool defaultprofile = false;
       
   128 	QString scomonotifiertype;
       
   129     int timeout = 0;
       
   130     while (i != parameters.constEnd())
       
   131         {
       
   132         if (i.key().toAscii() == "profileid")
       
   133             {
       
   134 
       
   135             profileid = i.value().toInt();
       
   136             profileidenabled = true;
       
   137             }
       
   138 
       
   139         if (i.key().toAscii() == "uimode")
       
   140             {
       
   141             uiserverinteraction = true;
       
   142             uimode = i.value().toInt();
       
   143             }
       
   144 
       
   145         if (i.key().toAscii() == "serverpushinformative")
       
   146             {
       
   147 			qDebug("server push informative enabled");
       
   148             serverpushinformativeenabled = true;
       
   149             serverpushinformmessage = i.value().toString();
       
   150             }
       
   151 
       
   152         if (i.key().toAscii() == "serverpushconfirmative")
       
   153             {
       
   154 		    LOGSTRING("Server Push Confirmative");
       
   155             serverpushinteractiveenabled = true;
       
   156             serverpushconfirmmessage = i.value().toString();
       
   157             }
       
   158 
       
   159         if (i.key().toAscii() == "serverdisplayname")
       
   160             {
       
   161             serverdispname = i.value().toString();
       
   162             }
       
   163         
       
   164         if (i.key().toAscii() == "fotadefaultprofile")
       
   165             {
       
   166             defaultprofile = i.value().toBool();
       
   167             }
       
   168         
       
   169         if (i.key().toAscii()== "scomonotifier")
       
   170             {
       
   171             scomonotifierenabled = true;
       
   172             scomonotifiertype = i.value().toString();
       
   173             }
       
   174         if (i.key().toAscii()=="scomoappdata")
       
   175             {
       
   176             //getting data for download failed cases
       
   177             data = i.value().toString();
       
   178             QStringList list1 = data.split(",");
       
   179             appname = list1[0];
       
   180             size =list1[1];
       
   181             sizeformat = list1[2];
       
   182             }
       
   183         if(i.key().toAscii()=="scomoappname")
       
   184             {
       
   185             //getting app name for install and uninstall failed cases
       
   186             appname = i.value().toString();
       
   187             }
       
   188         if (i.key().toAscii() == "pkgzerotimeout")
       
   189             {
       
   190             timeout = i.value().toInt();
       
   191             }
       
   192         ++i;
       
   193         }
       
   194 
       
   195     if (profileidenabled && uiserverinteraction)
       
   196         {
       
   197         qDebug("server interaction packet 0 enabled ");
       
   198         qDebug()<<EHbSOSNotifierKeyStatus;
       
   199         msymnotifier->setnotifierorigin(EHbSOSNotifierKeyStatus);
       
   200         createserverinitnotifier(profileid, uimode, serverdispname,
       
   201                 defaultprofile, timeout);
       
   202         }
       
   203     else if (serverpushinformativeenabled)
       
   204         {
       
   205         qDebug("server push informative enabled ");
       
   206         qDebug()<<EHbDMSyncNotifierKeyStatus;
       
   207         msymnotifier->setnotifierorigin(EHbDMSyncNotifierKeyStatus);
       
   208         createserveralertinformative(serverpushinformmessage);
       
   209         }
       
   210     else if (serverpushinteractiveenabled)
       
   211         {
       
   212         qDebug("server push informative enabled ");
       
   213         qDebug()<<EHbDMSyncNotifierKeyStatus;
       
   214          msymnotifier->setnotifierorigin(EHbDMSyncNotifierKeyStatus);
       
   215         createserveralertconfirmative(serverpushconfirmmessage);
       
   216         }
       
   217     else if (scomonotifierenabled)
       
   218         {
       
   219         createscomonotifier(scomonotifiertype,appname,size,sizeformat);
       
   220         }
       
   221 
       
   222     }
       
   223 
       
   224 void syncmlnotifier::createscomonotifier(QString notifiertype,QString app_name,QString asize,QString format)
       
   225     {
       
   226     HbDocumentLoader loader;
       
   227     bool ok = false;
       
   228     loader.load(":/xml/resources/error_notes.docml", &ok);
       
   229     if (!ok)
       
   230         {
       
   231         return;
       
   232         }
       
   233     QString val;
       
   234     HbDialog* dialog = qobject_cast<HbDialog*> (loader.findWidget("dialog"));
       
   235     HbLabel* label;
       
   236 
       
   237     dialog->setTimeout(HbPopup::ContextMenuTimeout);
       
   238 
       
   239     if (notifiertype == "installfailed")
       
   240         {
       
   241         //install failed case
       
   242         label = qobject_cast<HbLabel*> (loader.findWidget("heading_text"));
       
   243         val = hbTrId("txt_device_update_title_installation_failed");
       
   244         label->setPlainText(val);
       
   245         val = hbTrId("txt_device_update_info_installation_of_1_kb_failed").arg(
       
   246                 app_name);
       
   247         label = qobject_cast<HbLabel*> (loader.findWidget("content_text"));
       
   248         label->setPlainText(val);
       
   249         }
       
   250     else if (notifiertype == "downloadfailed")
       
   251         {
       
   252         //download failed
       
   253         label = qobject_cast<HbLabel*> (loader.findWidget("heading_text"));
       
   254         val = hbTrId("txt_device_update_title_downloading_failed");
       
   255 
       
   256         label->setPlainText(val);
       
   257         int sizfor = -1;
       
   258         format == QString("kb") ? sizfor = 0 : sizfor = 1;
       
   259         format == QString("mb") ? sizfor = 1 : sizfor = 2;
       
   260         switch (sizfor)
       
   261             {
       
   262             case 0:
       
   263                 val
       
   264                         = hbTrId(
       
   265                                 "txt_device_update_info_downloading_of_1_Kb_failed").arg(
       
   266                                 app_name, asize);
       
   267                 break;
       
   268             case 1:
       
   269                 val
       
   270                         = hbTrId(
       
   271                                 "txt_device_update_info_downloading_of_1_Mb_failed").arg(
       
   272                                 app_name, asize);
       
   273                 break;
       
   274             default:
       
   275                 val
       
   276                         = hbTrId(
       
   277                                 "txt_device_update_info_downloading_of_1_Gb_failed").arg(
       
   278                                 app_name, asize);
       
   279                 break;
       
   280             }
       
   281         label = qobject_cast<HbLabel*> (loader.findWidget("content_text"));
       
   282         label->setPlainText(val);
       
   283         }
       
   284     else
       
   285         {
       
   286         //uninstall failed
       
   287         label = qobject_cast<HbLabel*> (loader.findWidget("heading_text"));
       
   288         val = hbTrId("txt_device_update_title_Uninstallation_failed");
       
   289         label->setPlainText(val);
       
   290         val = hbTrId("txt_device_update_info_uninstalling_of_1_Mb_failed").arg(
       
   291                 app_name, asize);
       
   292 
       
   293         label = qobject_cast<HbLabel*> (loader.findWidget("content_text"));
       
   294         label->setPlainText(val);
       
   295         }
       
   296     dialog->setTimeout(HbPopup::StandardTimeout);
       
   297     dialog->show();
       
   298     }
       
   299 void syncmlnotifier::createserverinitnotifier(int& profileid, int& uimode,
       
   300         QString& servername, bool& defaultprofile, int& timeout)
       
   301     {
       
   302     
       
   303     int inittype = msymnotifier->serverinittype(uimode);
       
   304     qDebug("Notification type");
       
   305     qDebug()<<inittype;
       
   306 
       
   307 	LOGSTRING2("Init value = %d", inittype);
       
   308 
       
   309     /*For testing purpose*/
       
   310     //inittype = ESANUserInteractive;
       
   311 
       
   312     if (inittype == ESANUserInteractive)
       
   313         {
       
   314         HbDocumentLoader loader;
       
   315         bool ok = false;
       
   316         loader.load(":/xml/resources/dialog.docml", &ok);
       
   317         if (!ok)
       
   318             {
       
   319             return;
       
   320             }
       
   321         HbDialog *dialog = qobject_cast<HbDialog *> (loader.findWidget(
       
   322                 "dialog"));
       
   323 
       
   324         //set heading content
       
   325         HbLabel *contentheading = qobject_cast<HbLabel *> (loader.findWidget(
       
   326                 "qtl_dialog_pri_heading"));
       
   327         QString heading;        
       
   328         //set body content
       
   329         HbLabel *contentbody = qobject_cast<HbLabel *> (loader.findWidget(
       
   330                 "qtl_dialog_pri5"));
       
   331         QString serverinitmessage;
       
   332         QString softkeyok;
       
   333         QString softkeyCancel;
       
   334         if(defaultprofile)
       
   335             {
       
   336             mDefaultServerPkgZero = true;	
       
   337             heading = hbTrId("txt_device_update_title_update_available");
       
   338             serverinitmessage = 
       
   339               hbTrId("txt_device_update_info_recommended_update_is_avail").arg(
       
   340                             servername);
       
   341             softkeyok = hbTrId("txt_device_update_button_update");
       
   342             softkeyCancel = hbTrId("txt_device_update_button_later");                 
       
   343             }
       
   344         else
       
   345             {
       
   346             mDefaultServerPkgZero = false;	
       
   347             heading = hbTrId("txt_device_update_title_service_recomended");
       
   348             serverinitmessage = 
       
   349               hbTrId("txt_device_update_info_1_recommends_a_service_for").arg(
       
   350                             servername);
       
   351             softkeyok = hbTrId("txt_common_button_ok");
       
   352             softkeyCancel = hbTrId("txt_common_button_cancel");                            
       
   353             }
       
   354         contentheading->setPlainText(heading);
       
   355         contentbody->setPlainText(serverinitmessage);
       
   356 
       
   357         //set softkeys
       
   358         HbAction *primaryAction = (HbAction *) dialog->actions().first();
       
   359         
       
   360         primaryAction->setText(softkeyok);
       
   361 
       
   362         HbAction *secondaryAction = (HbAction *) dialog->actions().at(1);
       
   363         
       
   364         secondaryAction->setText(softkeyCancel);
       
   365 
       
   366         //set dialog properties
       
   367         dialog->setTimeout(timeout);
       
   368         dialog->setDismissPolicy(HbPopup::NoDismiss);
       
   369         //load appropriate icon from svg file
       
   370         HbLabel* label1 = qobject_cast<HbLabel*> (loader.findWidget("icon"));
       
   371         HbIcon* icon1 = new HbIcon(":/devman_icon/resources/iconnotifier.svg");
       
   372         label1->setIcon(*icon1);
       
   373         //label1->setMode(QIcon::Normal);
       
   374         //label1->setState(QIcon::Off);
       
   375         label1->setToolTip("Mode=Normal, State=Off");
       
   376 
       
   377         QObject::connect(dialog, SIGNAL(finished(HbAction*)), 
       
   378                 this, SLOT(noteTimedOut(HbAction*)));
       
   379         QObject::connect(primaryAction, SIGNAL(triggered()), this,
       
   380                 SLOT(okSelected()));
       
   381 
       
   382         QObject::connect(secondaryAction, SIGNAL(triggered()), this,
       
   383                 SLOT(cancelSelected()));
       
   384 
       
   385         if (dialog)
       
   386             dialog->show();
       
   387         }
       
   388     else if (inittype == ESANUserInformative)
       
   389         {
       
   390         HbDocumentLoader loader;
       
   391         bool ok = false;
       
   392         loader.load(":/xml/resources/dialoginformative.docml", &ok);
       
   393         if (!ok)
       
   394             {
       
   395             return;
       
   396             }
       
   397 
       
   398         //hbTrId("qtl_dialog_pri_heading");
       
   399 
       
   400         HbDialog *dialog = qobject_cast<HbDialog *> (loader.findWidget(
       
   401                 "dialog"));
       
   402 
       
   403         HbLabel *content = qobject_cast<HbLabel *> (loader.findWidget(
       
   404                 "qtl_dialog_pri5"));
       
   405 
       
   406         QString serverinitmessage = hbTrId(
       
   407                 "txt_deviceupdate_info_updating_device_from_server").arg(
       
   408                 servername);
       
   409 
       
   410         //getserverspecifictexttodisplay(profileid, uimode, serverinitmessage);
       
   411         content->setPlainText(serverinitmessage);
       
   412 
       
   413         //get string here /*TODO*/ /*QTranslations*/
       
   414 
       
   415         dialog->setTimeout(3000);
       
   416 
       
   417         //msymnotifier->setstatus(0);
       
   418 
       
   419         if (dialog)
       
   420             dialog->show();
       
   421 
       
   422         QObject::connect(dialog, SIGNAL(aboutToClose()), this,
       
   423                 SLOT(okSelected()));
       
   424 
       
   425         }
       
   426     else if (inittype == ESANSilent)
       
   427         {
       
   428         msymnotifier->setstatus(0);
       
   429         }
       
   430 
       
   431     }
       
   432 
       
   433 void syncmlnotifier::createserveralertinformative(const QString &string)
       
   434     {
       
   435     qDebug("createserveralertinformative start");
       
   436 		LOGSTRING("createserveralertinformative start");
       
   437     HbDocumentLoader loader;
       
   438     bool ok = false;
       
   439     loader.load(":/xml/resources/dialoginformative.docml", &ok);
       
   440     if (!ok)
       
   441         {
       
   442         return;
       
   443         }
       
   444     HbDialog *dialog = qobject_cast<HbDialog *> (loader.findWidget("dialog"));
       
   445 
       
   446     HbLabel *content = qobject_cast<HbLabel *> (loader.findWidget(
       
   447             "qtl_dialog_pri5"));
       
   448 
       
   449     // No translations required
       
   450     content->setPlainText(string);
       
   451 
       
   452     dialog->setTimeout(3000);
       
   453 
       
   454     if (dialog)
       
   455         dialog->show();
       
   456 
       
   457     QObject::connect(dialog, SIGNAL(aboutToClose()), this, SLOT(infoNoteOkSelected()));
       
   458 
       
   459 	qDebug("createserveralertinformative end");
       
   460 
       
   461     }
       
   462 
       
   463 void syncmlnotifier::createserveralertconfirmative(const QString &string)
       
   464     {
       
   465     HbDocumentLoader loader;
       
   466     bool ok = false;
       
   467     loader.load(":/xml/resources/dialogserverpushconfirm.docml", &ok);
       
   468     if (!ok)
       
   469         {
       
   470         return;
       
   471         }
       
   472     HbDialog *dialog = qobject_cast<HbDialog *> (loader.findWidget("dialog"));
       
   473 
       
   474     //set heading content
       
   475     HbLabel *contentheading = qobject_cast<HbLabel *> (loader.findWidget(
       
   476             "qtl_dialog_pri_heading"));
       
   477     QString heading = hbTrId("txt_device_update_title_server_message");
       
   478     contentheading->setPlainText(heading);
       
   479 
       
   480     //set body content
       
   481     HbLabel *contentbody = qobject_cast<HbLabel *> (loader.findWidget(
       
   482             "qtl_dialog_pri5"));
       
   483 
       
   484     contentbody->setPlainText(string);
       
   485 
       
   486     //set softkeys
       
   487     HbAction *primaryAction = (HbAction *) dialog->actions().first();
       
   488     QString softkeyok = hbTrId("txt_common_button_yes");
       
   489     primaryAction->setText(softkeyok);
       
   490 
       
   491     HbAction *secondaryAction = (HbAction *) dialog->actions().at(1);
       
   492     QString softkeyCancel = hbTrId("txt_common_button_no");
       
   493     secondaryAction->setText(softkeyCancel);
       
   494 
       
   495     dialog->setTimeout(HbPopup::NoTimeout);
       
   496 
       
   497     QObject::connect(primaryAction, SIGNAL(triggered()), this,
       
   498             SLOT(conirmNoteOkSelected()));
       
   499 
       
   500     QObject::connect(secondaryAction, SIGNAL(triggered()), this,
       
   501             SLOT(conirmNoteCancelSelected()));
       
   502 
       
   503     if (dialog)
       
   504         dialog->show();
       
   505     }
       
   506 
       
   507 void syncmlnotifier::okSelected()
       
   508     {
       
   509     qDebug("ok selected");
       
   510     //msymnotifier->setstatus(0);
       
   511 
       
   512 iPtr->dmDevdialogDismissed(devicemanagementnotifierwidget::EServerAlertNote,0);
       
   513     }
       
   514 void syncmlnotifier::infoNoteOkSelected()
       
   515     {
       
   516     iPtr->dmDevdialogDismissed(devicemanagementnotifierwidget::EInformativeNote,0);
       
   517     }
       
   518 
       
   519 void syncmlnotifier::conirmNoteOkSelected()
       
   520     {
       
   521     iPtr->dmDevdialogDismissed(devicemanagementnotifierwidget::EConfirmativeNote,0);
       
   522     }
       
   523 void syncmlnotifier::conirmNoteCancelSelected()
       
   524     {
       
   525     iPtr->dmDevdialogDismissed(devicemanagementnotifierwidget::EConfirmativeNote,-3);
       
   526     }
       
   527 
       
   528 void syncmlnotifier::cancelSelected()
       
   529     {
       
   530     qDebug("cancel selected");
       
   531     //msymnotifier->setstatus(-3);
       
   532     iPtr->dmDevdialogDismissed(devicemanagementnotifierwidget::EServerAlertNote,-3);
       
   533     
       
   534     }
       
   535 
       
   536 void syncmlnotifier::noteTimedOut(HbAction* action)
       
   537     {
       
   538     qDebug("Pkg zero note timed out");
       
   539     if (action == NULL)
       
   540         {
       
   541         int timeout = -33; //KErrTimedOut
       
   542         msymnotifier->setstatus(timeout);
       
   543         if(mDefaultServerPkgZero) //For default server action is RSK
       
   544         iPtr->dmDevdialogDismissed(
       
   545                 devicemanagementnotifierwidget::EServerAlertNote, -3);
       
   546         else //For Non default server action is LSK
       
   547         iPtr->dmDevdialogDismissed(
       
   548                 devicemanagementnotifierwidget::EServerAlertNote, 0);	        	
       
   549         }
       
   550     }
       
   551 
       
   552 syncmlnotifier::~syncmlnotifier()
       
   553     {
       
   554     qDebug("syncmlnotifier::~syncmlnotifier");
       
   555         qDebug("syncmlnotifier::~syncmlnotifier end");
       
   556     }
       
   557