deviceupdatesui/devicemanagementnotifiersplugin/devicemanagementnotifierutils.cpp
changeset 30 d3981f4fe6a4
parent 27 516a867811c3
child 31 4b5fb8110426
child 41 c742e1129640
equal deleted inserted replaced
27:516a867811c3 30:d3981f4fe6a4
     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 <hbdocumentloader.h>
       
    19 #include <hbdialog.h>
       
    20 #include <hblabel.h>
       
    21 #include <hbmessagebox.h>
       
    22 #include <hbaction.h>
       
    23 #include <e32property.h>
       
    24 #include <qdebug.h>
       
    25 #include "SyncMLNotifierParams.h"
       
    26 #include "PnpUtilLogger.h"
       
    27 #include "devicemanagementnotifierutils.h"
       
    28 
       
    29  enum TSyncmlHbNotifierKeys 
       
    30 		{
       
    31 
       
    32      EHbSOSNotifierKeyStatus = 11, // status set will complete the client subscribe
       
    33      EHbSOSNotifierKeyStatusReturn = 12, // Return the content of actual status value accepted from UI
       
    34      
       
    35      EHbDMSyncNotifierKeyStatus = 13,
       
    36      EHbDMSyncNotifierKeyStatusReturn = 14
       
    37 		};
       
    38 
       
    39 
       
    40 devicemanagementnotifierutils::devicemanagementnotifierutils(
       
    41         const QVariantMap &parameters)
       
    42     {
       
    43 	qDebug("devicemanagementnotifierutils");
       
    44     syncmlnotifier* notifier = new syncmlnotifier();
       
    45     notifier->launchDialog(parameters);
       
    46 
       
    47     }
       
    48 
       
    49 syncmlnotifier::syncmlnotifier()
       
    50     {
       
    51     qDebug("devicemanagementnotifierutils syncmlnotifier");
       
    52     QTranslator *translator = new QTranslator();
       
    53     QString lang = QLocale::system().name();
       
    54     QString path = "Z:/resource/qt/translations/";
       
    55     bool fine = translator->load("deviceupdates_en.qm", path);
       
    56     if (fine)
       
    57         qApp->installTranslator(translator);
       
    58 
       
    59     QTranslator *commontranslator = new QTranslator();
       
    60 
       
    61     fine = commontranslator->load("common_" + lang, path);
       
    62     if (fine)
       
    63         qApp->installTranslator(commontranslator);
       
    64 
       
    65     msymnotifier = new syncmlnotifierprivate();
       
    66     }
       
    67 
       
    68 void syncmlnotifier::launchDialog(const QVariantMap &parameters)
       
    69     {
       
    70 
       
    71     QVariantMap::const_iterator i = parameters.constBegin();
       
    72     qDebug("devicemanagementnotifierutils syncmlnotifier launchDialog");
       
    73     //i++;
       
    74 
       
    75     bool profileidenabled = false;
       
    76     bool uiserverinteraction = false;
       
    77     bool serverpushinformativeenabled = false;
       
    78     bool serverpushinteractiveenabled = false;
       
    79 
       
    80     int profileid = 0;
       
    81     int uimode = 0;
       
    82 
       
    83     QString serverpushinformmessage;
       
    84     QString serverpushconfirmmessage;
       
    85 
       
    86     QString serverdispname;
       
    87 
       
    88     while (i != parameters.constEnd())
       
    89         {
       
    90         if (i.key().toAscii() == "profileid")
       
    91             {
       
    92 
       
    93             profileid = i.value().toInt();
       
    94             profileidenabled = true;
       
    95             }
       
    96 
       
    97         if (i.key().toAscii() == "uimode")
       
    98             {
       
    99             uiserverinteraction = true;
       
   100             uimode = i.value().toInt();
       
   101             }
       
   102 
       
   103         if (i.key().toAscii() == "serverpushinformative")
       
   104             {
       
   105 			qDebug("server push informative enabled");
       
   106             serverpushinformativeenabled = true;
       
   107             serverpushinformmessage = i.value().toString();
       
   108             }
       
   109 
       
   110         if (i.key().toAscii() == "serverpushconfirmative")
       
   111             {
       
   112 		    LOGSTRING("Server Push Confirmative");
       
   113             serverpushinteractiveenabled = true;
       
   114             serverpushconfirmmessage = i.value().toString();
       
   115             }
       
   116 
       
   117         if (i.key().toAscii() == "serverdisplayname")
       
   118             {
       
   119             serverdispname = i.value().toString();
       
   120             }
       
   121 
       
   122         ++i;
       
   123         }
       
   124 
       
   125     if (profileidenabled && uiserverinteraction)
       
   126         {
       
   127         qDebug("server interaction packet 0 enabled ");
       
   128         qDebug()<<EHbSOSNotifierKeyStatus;
       
   129         msymnotifier->setnotifierorigin(EHbSOSNotifierKeyStatus);
       
   130         createserverinitnotifier(profileid, uimode, serverdispname);
       
   131         }
       
   132     else if (serverpushinformativeenabled)
       
   133         {
       
   134         qDebug("server push informative enabled ");
       
   135         qDebug()<<EHbDMSyncNotifierKeyStatus;
       
   136         msymnotifier->setnotifierorigin(EHbDMSyncNotifierKeyStatus);
       
   137         createserveralertinformative(serverpushinformmessage);
       
   138         }
       
   139     else if (serverpushinteractiveenabled)
       
   140         {
       
   141         qDebug("server push informative enabled ");
       
   142         qDebug()<<EHbDMSyncNotifierKeyStatus;
       
   143          msymnotifier->setnotifierorigin(EHbDMSyncNotifierKeyStatus);
       
   144         createserveralertconfirmative(serverpushconfirmmessage);
       
   145         }
       
   146 
       
   147     }
       
   148 
       
   149 void syncmlnotifier::createserverinitnotifier(int profileid, int uimode,
       
   150         QString& servername)
       
   151     {
       
   152     
       
   153     int inittype = msymnotifier->serverinittype(uimode);
       
   154     qDebug("Notification type");
       
   155     qDebug()<<inittype;
       
   156 
       
   157 	LOGSTRING2("Init value = %d", inittype);
       
   158 
       
   159     /*For testing purpose*/
       
   160     //inittype = ESANUserInteractive;
       
   161 
       
   162     if (inittype == ESANUserInteractive)
       
   163         {
       
   164         HbDocumentLoader loader;
       
   165         bool ok = false;
       
   166         loader.load(":/xml/dialog.docml", &ok);
       
   167         if (!ok)
       
   168             {
       
   169             return;
       
   170             }
       
   171         HbDialog *dialog = qobject_cast<HbDialog *> (loader.findWidget(
       
   172                 "dialog"));
       
   173 
       
   174         //set heading content
       
   175         HbLabel *contentheading = qobject_cast<HbLabel *> (loader.findWidget(
       
   176                 "qtl_dialog_pri_heading"));
       
   177         QString heading = hbTrId("txt_device_update_title_update_available");
       
   178         contentheading->setPlainText(heading);
       
   179 
       
   180         //set body content
       
   181         HbLabel *contentbody = qobject_cast<HbLabel *> (loader.findWidget(
       
   182                 "qtl_dialog_pri5"));
       
   183         QString serverinitmessage = hbTrId(
       
   184                 "txt_device_update_info_recommended_update_is_avail").arg(
       
   185                 servername);
       
   186         contentbody->setPlainText(serverinitmessage);
       
   187 
       
   188         //set softkeys
       
   189         HbAction *primaryAction = (HbAction *) dialog->actions().first();
       
   190         QString softkeyok = hbTrId("txt_common_button_ok");
       
   191         primaryAction->setText(softkeyok);
       
   192 
       
   193         HbAction *secondaryAction = (HbAction *) dialog->actions().at(1);
       
   194         QString softkeyCancel = hbTrId("txt_common_button_cancel");
       
   195         secondaryAction->setText(softkeyCancel);
       
   196 
       
   197         //set dialog properties
       
   198         dialog->setTimeout(HbPopup::NoTimeout);
       
   199 
       
   200         //load appropriate icon from svg file
       
   201         HbLabel* label1 = qobject_cast<HbLabel*> (loader.findWidget("icon"));
       
   202         HbIcon* icon1 = new HbIcon(":/devman_icon/iconnotifier.svg");
       
   203         label1->setIcon(*icon1);
       
   204         //label1->setMode(QIcon::Normal);
       
   205         //label1->setState(QIcon::Off);
       
   206         label1->setToolTip("Mode=Normal, State=Off");
       
   207 
       
   208         QObject::connect(primaryAction, SIGNAL(triggered()), this,
       
   209                 SLOT(okSelected()));
       
   210 
       
   211         QObject::connect(secondaryAction, SIGNAL(triggered()), this,
       
   212                 SLOT(cancelSelected()));
       
   213 
       
   214         if (dialog)
       
   215             dialog->show();
       
   216         }
       
   217     else if (inittype == ESANUserInformative)
       
   218         {
       
   219         HbDocumentLoader loader;
       
   220         bool ok = false;
       
   221         loader.load(":/xml/dialoginformative.docml", &ok);
       
   222         if (!ok)
       
   223             {
       
   224             return;
       
   225             }
       
   226 
       
   227         //hbTrId("qtl_dialog_pri_heading");
       
   228 
       
   229         HbDialog *dialog = qobject_cast<HbDialog *> (loader.findWidget(
       
   230                 "dialog"));
       
   231 
       
   232         HbLabel *content = qobject_cast<HbLabel *> (loader.findWidget(
       
   233                 "qtl_dialog_pri5"));
       
   234 
       
   235         QString serverinitmessage = hbTrId(
       
   236                 "txt_device_update_info_update_serverpush_informative").arg(
       
   237                 servername);
       
   238 
       
   239         //getserverspecifictexttodisplay(profileid, uimode, serverinitmessage);
       
   240         content->setPlainText(serverinitmessage);
       
   241 
       
   242         //get string here /*TODO*/ /*QTranslations*/
       
   243 
       
   244         dialog->setTimeout(3000);
       
   245 
       
   246         //msymnotifier->setstatus(0);
       
   247 
       
   248         if (dialog)
       
   249             dialog->show();
       
   250 
       
   251         QObject::connect(dialog, SIGNAL(aboutToClose()), this,
       
   252                 SLOT(okSelected()));
       
   253 
       
   254         }
       
   255     else if (inittype == ESANSilent)
       
   256         {
       
   257         msymnotifier->setstatus(0);
       
   258         }
       
   259 
       
   260     }
       
   261 
       
   262 void syncmlnotifier::createserveralertinformative(const QString &string)
       
   263     {
       
   264     qDebug("createserveralertinformative start");
       
   265 		LOGSTRING("createserveralertinformative start");
       
   266     HbDocumentLoader loader;
       
   267     bool ok = false;
       
   268     loader.load(":/xml/dialoginformative.docml", &ok);
       
   269     if (!ok)
       
   270         {
       
   271         return;
       
   272         }
       
   273     HbDialog *dialog = qobject_cast<HbDialog *> (loader.findWidget("dialog"));
       
   274 
       
   275     HbLabel *content = qobject_cast<HbLabel *> (loader.findWidget(
       
   276             "qtl_dialog_pri5"));
       
   277 
       
   278     // No translations required
       
   279     content->setPlainText(string);
       
   280 
       
   281     dialog->setTimeout(3000);
       
   282 
       
   283     if (dialog)
       
   284         dialog->show();
       
   285 
       
   286     QObject::connect(dialog, SIGNAL(aboutToClose()), this, SLOT(okSelected()));
       
   287 
       
   288 	qDebug("createserveralertinformative end");
       
   289 
       
   290     }
       
   291 
       
   292 void syncmlnotifier::createserveralertconfirmative(const QString &string)
       
   293     {
       
   294     HbDocumentLoader loader;
       
   295     bool ok = false;
       
   296     loader.load(":/xml/dialogserverpushconfirm.docml", &ok);
       
   297     if (!ok)
       
   298         {
       
   299         return;
       
   300         }
       
   301     HbDialog *dialog = qobject_cast<HbDialog *> (loader.findWidget("dialog"));
       
   302 
       
   303     //set heading content
       
   304     HbLabel *contentheading = qobject_cast<HbLabel *> (loader.findWidget(
       
   305             "qtl_dialog_pri_heading"));
       
   306     QString heading = hbTrId("txt_device_update_title_server_message");
       
   307     contentheading->setPlainText(heading);
       
   308 
       
   309     //set body content
       
   310     HbLabel *contentbody = qobject_cast<HbLabel *> (loader.findWidget(
       
   311             "qtl_dialog_pri5"));
       
   312 
       
   313     contentbody->setPlainText(string);
       
   314 
       
   315     //set softkeys
       
   316     HbAction *primaryAction = (HbAction *) dialog->actions().first();
       
   317     QString softkeyok = hbTrId("txt_common_button_yes");
       
   318     primaryAction->setText(softkeyok);
       
   319 
       
   320     HbAction *secondaryAction = (HbAction *) dialog->actions().at(1);
       
   321     QString softkeyCancel = hbTrId("txt_common_button_no");
       
   322     secondaryAction->setText(softkeyCancel);
       
   323 
       
   324     dialog->setTimeout(HbPopup::NoTimeout);
       
   325 
       
   326     QObject::connect(primaryAction, SIGNAL(triggered()), this,
       
   327             SLOT(okSelected()));
       
   328 
       
   329     QObject::connect(secondaryAction, SIGNAL(triggered()), this,
       
   330             SLOT(cancelSelected()));
       
   331 
       
   332     if (dialog)
       
   333         dialog->show();
       
   334     }
       
   335 
       
   336 void syncmlnotifier::okSelected()
       
   337     {
       
   338     qDebug("ok selected");
       
   339     msymnotifier->setstatus(0);
       
   340     }
       
   341 
       
   342 void syncmlnotifier::cancelSelected()
       
   343     {
       
   344     qDebug("cancel selected");
       
   345     msymnotifier->setstatus(-3);
       
   346 
       
   347     }
       
   348