messagingapp/msgnotifications/msgnotificationdialogplugin/src/msgnotificationdialogwidget.cpp
changeset 23 238255e8b033
child 25 84d9eb65b26f
equal deleted inserted replaced
5:4697dfb2d7ad 23:238255e8b033
       
     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: Widget class for Notificaiton Dialog Plugin
       
    15  *
       
    16  */
       
    17 #include <QThreadPool>
       
    18 #include <QRunnable>
       
    19 #include "debugtraces.h"
       
    20 
       
    21 #include <ccsdefs.h>
       
    22 #include <QIcon>
       
    23 #include <QVariant>
       
    24 #include <QList>
       
    25 #include <hbicon.h>
       
    26 #include <hbpopup.h>
       
    27 #include <xqservicerequest.h>
       
    28 #include "convergedmessage.h"
       
    29 
       
    30 #include "msgnotificationdialogpluginkeys.h"
       
    31 #include "msgnotificationdialogwidget.h"
       
    32 
       
    33 const int NoError = 0;
       
    34 const int ParameterError = 10000;
       
    35 
       
    36 
       
    37 //----------------------------------------------------------------
       
    38 
       
    39 class ServiceRequestSenderTask : public QRunnable
       
    40  {
       
    41 public:
       
    42      ServiceRequestSenderTask(qint64 conversationId):mConvId(conversationId)  {}
       
    43      
       
    44      void run()
       
    45      {
       
    46      XQServiceRequest snd(
       
    47             "com.nokia.services.hbserviceprovider.conversationview",
       
    48                 "open(qint64)",false);
       
    49 		  snd << mConvId;
       
    50 		  bool res=snd.send();    
       
    51      }
       
    52      
       
    53      ~ServiceRequestSenderTask()
       
    54      {     
       
    55      }
       
    56      
       
    57  private: 
       
    58  	qint64 mConvId;    
       
    59  };
       
    60 
       
    61 // ------------------------------------------------------------------------
       
    62 
       
    63 
       
    64 
       
    65 // ----------------------------------------------------------------------------
       
    66 // MsgNotificationDialogWidget::MsgNotificationDialogWidget
       
    67 // @see msgnotificationdialogwidget.h
       
    68 // ----------------------------------------------------------------------------
       
    69 MsgNotificationDialogWidget::MsgNotificationDialogWidget(
       
    70                                                 const QVariantMap &parameters)
       
    71 : HbNotificationDialog(),
       
    72 mLastError(NoError),
       
    73 mShowEventReceived(false),
       
    74 mConversationId(-1)
       
    75 {
       
    76     constructDialog(parameters);
       
    77 }
       
    78 
       
    79                                                 
       
    80 // ----------------------------------------------------------------------------
       
    81 // MsgNotificationDialogWidget::setDeviceDialogParameters
       
    82 // @see msgnotificationdialogwidget.h
       
    83 // ----------------------------------------------------------------------------
       
    84 bool MsgNotificationDialogWidget::setDeviceDialogParameters(
       
    85                                                 const QVariantMap &parameters)
       
    86 {
       
    87    return constructDialog(parameters);
       
    88 }
       
    89 
       
    90 // ----------------------------------------------------------------------------
       
    91 // MsgNotificationDialogWidget::constructDialog
       
    92 // @see msgnotificationdialogwidget.h
       
    93 // ----------------------------------------------------------------------------
       
    94 bool MsgNotificationDialogWidget::constructDialog(
       
    95                                                 const QVariantMap &parameters)
       
    96     {
       
    97     // Set parameters 
       
    98     mLastError = NoError;
       
    99 
       
   100     // if conversation id is not proper return false
       
   101     mConversationId = parameters.value(KConversationIdKey).toLongLong(); 
       
   102     if( mConversationId <= 0)
       
   103         {
       
   104         mLastError = ParameterError;
       
   105         return false;    
       
   106         }
       
   107 
       
   108     prepareDisplayName(parameters);
       
   109 
       
   110     int messageType = parameters.value(KMessageTypeKey).toInt();
       
   111     if( messageType == ECsSMS)
       
   112         {
       
   113         HbIcon icon(":/sms.svg");
       
   114         setIcon(icon);
       
   115         setText(parameters.value(KMessageBodyKey).toString());    
       
   116         }
       
   117     else if(messageType == ECsMMS)
       
   118         {
       
   119         HbIcon icon(":/mms.svg");
       
   120         setIcon(icon);
       
   121         setText(parameters.value(KMessageSubjectKey).toString());       
       
   122         }
       
   123     else if(messageType == ECsRingingTone)
       
   124         {
       
   125         HbIcon icon(":/ringingtone.svg");
       
   126         setIcon(icon);
       
   127         setText(parameters.value(KMessageBodyKey).toString());      
       
   128         }
       
   129     else
       
   130         {
       
   131         HbIcon icon(":/sms.svg"); // show default for other message types
       
   132         setIcon(icon);
       
   133         setText(parameters.value(KMessageBodyKey).toString());    
       
   134         }
       
   135     
       
   136     // enable touch activation and connect to slot
       
   137     enableTouchActivation(true);
       
   138     connect(this, SIGNAL(activated()), this, SLOT(widgetActivated()));
       
   139 
       
   140     // set the standard timeout value, that is used by default notificaitons dialogs
       
   141     setTimeout(HbPopup::StandardTimeout);
       
   142 
       
   143     return true;
       
   144 }
       
   145 
       
   146 // ----------------------------------------------------------------------------
       
   147 // MsgNotificationDialogWidget::deviceDialogError
       
   148 // @see msgnotificationdialogwidget.h
       
   149 // ----------------------------------------------------------------------------
       
   150 int MsgNotificationDialogWidget::deviceDialogError() const
       
   151 {    
       
   152     // Get error
       
   153     return mLastError;
       
   154 }
       
   155 
       
   156 // ----------------------------------------------------------------------------
       
   157 // MsgNotificationDialogWidget::closeDeviceDialog
       
   158 // @see msgnotificationdialogwidget.h
       
   159 // ----------------------------------------------------------------------------
       
   160 void MsgNotificationDialogWidget::closeDeviceDialog(bool byClient)
       
   161 {
       
   162     // Close device dialog
       
   163     Q_UNUSED(byClient);
       
   164     close();
       
   165     // If show event has been received, close is signalled from hide event. If not,
       
   166     // hide event does not come and close is signalled from here.
       
   167     if (!mShowEventReceived) {
       
   168         emit deviceDialogClosed();
       
   169     }
       
   170     
       
   171 }
       
   172 
       
   173 // ----------------------------------------------------------------------------
       
   174 // MsgNotificationDialogWidget::deviceDialogWidget
       
   175 // @see msgnotificationdialogwidget.h
       
   176 // ----------------------------------------------------------------------------
       
   177 HbDialog *MsgNotificationDialogWidget::deviceDialogWidget() const
       
   178 {    
       
   179     // Return display widget
       
   180     return const_cast<MsgNotificationDialogWidget*>(this);
       
   181 }
       
   182 
       
   183 
       
   184 // ----------------------------------------------------------------------------
       
   185 // MsgNotificationDialogWidget::hideEvent
       
   186 // @see msgnotificationdialogwidget.h
       
   187 // ----------------------------------------------------------------------------
       
   188 void MsgNotificationDialogWidget::hideEvent(QHideEvent *event)
       
   189 {
       
   190     HbNotificationDialog::hideEvent(event);
       
   191     emit deviceDialogClosed();
       
   192 }
       
   193 
       
   194 // ----------------------------------------------------------------------------
       
   195 // MsgNotificationDialogWidget::showEvent
       
   196 // @see msgnotificationdialogwidget.h
       
   197 // ----------------------------------------------------------------------------
       
   198 void MsgNotificationDialogWidget::showEvent(QShowEvent *event)
       
   199 {
       
   200     HbNotificationDialog::showEvent(event);
       
   201     mShowEventReceived = true;
       
   202 }
       
   203 
       
   204 // ----------------------------------------------------------------------------
       
   205 // MsgNotificationDialogWidget::widgetActivated
       
   206 // @see msgnotificationdialogwidget.h
       
   207 // ----------------------------------------------------------------------------
       
   208 void MsgNotificationDialogWidget::widgetActivated()
       
   209 {
       
   210 QThreadPool::globalInstance()->start(
       
   211         	new ServiceRequestSenderTask(mConversationId));  
       
   212 }
       
   213 
       
   214 // ----------------------------------------------------------------------------
       
   215 // MsgNotificationDialogWidget::prepareDisplayName
       
   216 // @see msgnotificationdialogwidget.h
       
   217 // ----------------------------------------------------------------------------
       
   218 void MsgNotificationDialogWidget::prepareDisplayName(
       
   219                                                 const QVariantMap &parameters)
       
   220 {
       
   221     //Set the Contact Name/Number
       
   222     QString firstName = parameters.value(KFirstNameKey).toString();
       
   223     QString lastName = parameters.value(KLastNameKey).toString();
       
   224     QString contactAddress = parameters.value(KContactAddressKey).toString();
       
   225     QString nickName = parameters.value(KNickNameKey).toString();
       
   226     
       
   227     QString displayName;
       
   228     
       
   229     if (!nickName.isEmpty())
       
   230     {
       
   231         displayName.append(nickName);
       
   232     }
       
   233     else if ( firstName.isEmpty() && lastName.isEmpty())
       
   234     {
       
   235         displayName.append(contactAddress);
       
   236     }
       
   237     else if (lastName.isEmpty() && !firstName.isEmpty())
       
   238     {
       
   239         displayName.append(firstName);
       
   240     }
       
   241     else if (firstName.isEmpty() && !lastName.isEmpty())
       
   242     {
       
   243         displayName.append(lastName);
       
   244     }
       
   245     else
       
   246     {
       
   247         // If both first Name and last name are present
       
   248         displayName.append(firstName);
       
   249         displayName.append(" ");
       
   250         displayName.append(lastName);
       
   251     }
       
   252     
       
   253     // set the display name
       
   254     setTitle(displayName);
       
   255 }