messagingapp/msgnotifications/flashmsgnotifier/src/flashmsgnotifier.cpp
changeset 51 3507212d340e
child 62 fdbe8253b596
equal deleted inserted replaced
49:2a272ef608c4 51:3507212d340e
       
     1 /*
       
     2  * Copyright (c) 2009 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: Implements interface for showing flash messages
       
    15  *
       
    16  */
       
    17 
       
    18 #include "flashmsgnotifier.h"
       
    19 
       
    20 #include <hbapplication.h>
       
    21 #include <hbdevicemessagebox.h>
       
    22 #include <hbmessagebox.h>
       
    23 #include <hbtextitem.h>
       
    24 #include <QAction>
       
    25 #include <debugtraces.h>
       
    26 #include <xqconversions.h>
       
    27 #include <xqapplicationmanager.h>
       
    28 #include <xqaiwrequest.h>
       
    29 #include <xqsystemtoneservice.h>
       
    30 #include "flashmsgnotifier_p.h"
       
    31 
       
    32 #define LOC_NOTIFICATION_MSG_TITLE  hbTrId("txt_messaging_title_notification_message")
       
    33 #define LOC_BUTTON_SAVE       hbTrId("txt_common_menu_save")
       
    34 #define LOC_BUTTON_DELETE       hbTrId("txt_common_menu_delete")
       
    35 
       
    36 //-------------------------------------------------------
       
    37 // FlashMsgNotifier::FlashMsgNotifier()
       
    38 // Constructor
       
    39 //-------------------------------------------------------
       
    40 FlashMsgNotifier::FlashMsgNotifier(QObject *parent) :
       
    41         XQServiceProvider(QLatin1String("flashmsgnotifier.com.nokia.symbian.IFlashMsgNotifier"),
       
    42             parent)
       
    43 {
       
    44     publishAll();
       
    45     mSts = new XQSystemToneService;
       
    46     d_ptr = q_check_ptr(new FlashMsgNotifierPrivate(this));
       
    47 }
       
    48 
       
    49 //-------------------------------------------------------
       
    50 // FlashMsgNotifier::~FlashMsgNotifier()
       
    51 // Destructor
       
    52 //-------------------------------------------------------
       
    53 FlashMsgNotifier::~FlashMsgNotifier()
       
    54 {
       
    55     delete d_ptr;
       
    56     delete mSts;
       
    57 }
       
    58 
       
    59 //-------------------------------------------------------
       
    60 // FlashMsgNotifier::displayFlashMsg()
       
    61 // @see header
       
    62 //-------------------------------------------------------
       
    63 void FlashMsgNotifier::displayFlashMsg(QByteArray displayParams)
       
    64 {
       
    65     QCRITICAL_WRITE("FlashMsgNotifier::displayFlashMsg start.")
       
    66     
       
    67     // Dialog
       
    68     HbDeviceMessageBox notificationDialog(HbMessageBox::MessageTypeNone, this);
       
    69 
       
    70     QDataStream stream(displayParams);
       
    71 
       
    72     QString body;
       
    73     QString address;
       
    74     QString alias;
       
    75     QString time;
       
    76 
       
    77     int msgId;
       
    78 
       
    79     stream >> body;
       
    80     stream >> address;
       
    81     stream >> alias;
       
    82     stream >> time;
       
    83     stream >> msgId;
       
    84 
       
    85     //Save the address to be used later   
       
    86     mAddress.clear();
       
    87     mAddress.append(address);
       
    88 
       
    89     QString class0SmsBody;
       
    90 
       
    91     class0SmsBody = LOC_NOTIFICATION_MSG_TITLE;
       
    92 
       
    93     class0SmsBody.append("\n");
       
    94 
       
    95     if (alias.isEmpty()) {
       
    96         class0SmsBody.append(address);
       
    97         class0SmsBody.append("\n");
       
    98     }
       
    99     else {
       
   100         class0SmsBody.append(alias);
       
   101         class0SmsBody.append("\n");
       
   102     }
       
   103 
       
   104     class0SmsBody.append(time);
       
   105     class0SmsBody.append("\n");
       
   106     class0SmsBody.append(body);
       
   107 
       
   108     QDEBUG_WRITE_FORMAT("flashmsgnotifier launch message ", class0SmsBody);
       
   109 
       
   110     notificationDialog.setText(class0SmsBody);
       
   111 
       
   112     notificationDialog.setDismissPolicy(HbDialog::NoDismiss);
       
   113     notificationDialog.setTimeout(HbPopup::NoTimeout);
       
   114 
       
   115     notificationDialog.setTimeout(HbPopup::NoTimeout);
       
   116     QAction* actionSave = new QAction(LOC_BUTTON_SAVE, this);
       
   117     notificationDialog.setAction(actionSave, HbDeviceMessageBox::AcceptButtonRole);
       
   118 
       
   119     QAction* actionQuit = new QAction(LOC_BUTTON_DELETE, this);
       
   120     notificationDialog.setAction(actionQuit, HbDeviceMessageBox::RejectButtonRole);
       
   121 
       
   122     //Play audio alert when flash msg is shown
       
   123     mSts->playTone(XQSystemToneService::SmsAlertTone);
       
   124 
       
   125     const QAction* result = notificationDialog.exec();
       
   126     // if accepted launch view else quit
       
   127     if (notificationDialog.isAcceptAction(result)) 
       
   128     {
       
   129         onSaveAction(msgId);
       
   130     }
       
   131     else 
       
   132     {
       
   133         onDeleteAction(msgId);
       
   134     }   
       
   135     QCRITICAL_WRITE("FlashMsgNotifier::displayFlashMsg end.")  
       
   136 
       
   137 }
       
   138 
       
   139 //-------------------------------------------------------
       
   140 // FlashMsgNotifier::onSaveAction()
       
   141 // @see header
       
   142 //-------------------------------------------------------
       
   143 void FlashMsgNotifier::onSaveAction(int msgId)
       
   144 {
       
   145     TRAPD(err, d_ptr->SaveMessageL(msgId));
       
   146     QDEBUG_WRITE_FORMAT("error while saving", err);
       
   147 
       
   148     HBufC* addr = NULL;
       
   149     qint64 conversationId = -1;
       
   150     addr = XQConversions::qStringToS60Desc(mAddress);
       
   151     QDEBUG_WRITE_FORMAT("onSaveAction", mAddress);
       
   152     TRAP(err, conversationId = d_ptr->GetConversationIdFromAddressL(*addr));
       
   153     delete addr;
       
   154     QDEBUG_WRITE_FORMAT("error while fetching address", err);
       
   155 
       
   156     if (conversationId != -1) {
       
   157         //Switch to CV
       
   158         QList<QVariant> args;
       
   159         QString serviceName("com.nokia.services.hbserviceprovider");
       
   160         QString operation("open(qint64)");
       
   161         XQAiwRequest* request;
       
   162         XQApplicationManager appManager;
       
   163         request = appManager.create(serviceName, "conversationview", 
       
   164                                     operation,false); // embedded
       
   165         if (request == NULL) {
       
   166             QDEBUG_WRITE_FORMAT("error while fetching address", 
       
   167                                 request->lastErrorMessage());
       
   168             return;
       
   169         }
       
   170         args << QVariant(conversationId);
       
   171         request->setArguments(args);
       
   172         request->send();
       
   173         delete request;
       
   174     }   
       
   175 }
       
   176 
       
   177 //-------------------------------------------------------
       
   178 // FlashMsgNotifier::onDeleteAction()
       
   179 // @see header
       
   180 //-------------------------------------------------------
       
   181 void FlashMsgNotifier::onDeleteAction(int msgId)
       
   182 {
       
   183     d_ptr->DeleteMessage(msgId);
       
   184 }