messagingapp/msgui/unifiededitor/src/msgunieditorsubject.cpp
branchRCL_3
changeset 57 ebe688cedc25
equal deleted inserted replaced
54:fa1df4b99609 57:ebe688cedc25
       
     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:
       
    15  *
       
    16  */
       
    17 
       
    18 // INCLUDES
       
    19 #include "debugtraces.h"
       
    20 #include <HbIconItem>
       
    21 #include <HbNotificationDialog>
       
    22 #include <hbmessagebox.h>
       
    23 
       
    24 // USER INCLUDES
       
    25 #include "msgunieditorsubject.h"
       
    26 #include "UniEditorGenUtils.h"
       
    27 #include "msgunieditorlineedit.h"
       
    28 #include "msgunieditormonitor.h"
       
    29 
       
    30 // Localized Constants
       
    31 #define LOC_SUBJECT hbTrId("txt_messaging_formlabel_subject")
       
    32 #define LOC_UNABLE_TO_ADD_CONTENT hbTrId("txt_messaging_dpopinfo_unable_to_add_more_content")
       
    33 
       
    34 //priority icon
       
    35 const QString HIGH_PRIORITY("qtg_small_priority_high");
       
    36 const QString LOW_PRIORITY("qtg_small_priority_low");
       
    37 
       
    38 //---------------------------------------------------------------
       
    39 // MsgUnifiedEditorSubject::MsgUnifiedEditorSubject
       
    40 // @see header file
       
    41 //---------------------------------------------------------------
       
    42 MsgUnifiedEditorSubject::MsgUnifiedEditorSubject( QGraphicsItem *parent ) :
       
    43 MsgUnifiedEditorBaseWidget(parent),
       
    44 mPriorityIcon(NULL),
       
    45 mPriority(ConvergedMessage::Normal),
       
    46 mGenUtils(0)
       
    47 {
       
    48         mSubjectEdit = new MsgUnifiedEditorLineEdit(LOC_SUBJECT,this);
       
    49         mSubjectEdit->setDefaultBehaviour(true);        
       
    50         HbStyle::setItemName(mSubjectEdit,"subjectEdit");
       
    51         mSubjectEdit->setMinRows(1);
       
    52         mSubjectEdit->setMaxRows(10);
       
    53         
       
    54         mGenUtils = q_check_ptr(new UniEditorGenUtils());
       
    55         
       
    56         connect(mSubjectEdit, SIGNAL(contentsChanged(const QString&)),
       
    57                 this, SLOT(onContentsChanged(const QString&)));
       
    58 }
       
    59 
       
    60 //---------------------------------------------------------------
       
    61 // MsgUnifiedEditorSubject::~MsgUnifiedEditorSubject
       
    62 // @see header file
       
    63 //---------------------------------------------------------------
       
    64 MsgUnifiedEditorSubject::~MsgUnifiedEditorSubject()
       
    65 {
       
    66     if(mGenUtils)
       
    67     {
       
    68         delete mGenUtils;
       
    69         mGenUtils = NULL;
       
    70     }
       
    71 }
       
    72 
       
    73 void MsgUnifiedEditorSubject::setPriority(ConvergedMessage::Priority priority)
       
    74 {
       
    75 	mPriority = priority;
       
    76     if(mPriorityIcon)
       
    77     {// Transition from low/high => low/normal/high
       
    78         mPriorityIcon->setParent(NULL);
       
    79         delete mPriorityIcon;
       
    80         mPriorityIcon = NULL;
       
    81     }
       
    82 
       
    83     switch(priority)
       
    84     {
       
    85         case ConvergedMessage::High :
       
    86         {
       
    87         mPriorityIcon = new HbIconItem(HIGH_PRIORITY, this);
       
    88         HbStyle::setItemName(mPriorityIcon,"priorityIcon");
       
    89         }
       
    90         break;
       
    91         case ConvergedMessage::Low :
       
    92         {
       
    93         mPriorityIcon = new HbIconItem(LOW_PRIORITY, this);
       
    94         HbStyle::setItemName(mPriorityIcon,"priorityIcon");
       
    95         }
       
    96         break;
       
    97         default:
       
    98         break;
       
    99     }
       
   100 
       
   101     emit contentChanged();
       
   102     this->repolish();
       
   103 }
       
   104 
       
   105 QString MsgUnifiedEditorSubject::text()
       
   106 {
       
   107     return mSubjectEdit->content();
       
   108 }
       
   109 
       
   110 ConvergedMessage::Priority MsgUnifiedEditorSubject::priority()
       
   111 {
       
   112 	return mPriority;
       
   113 }
       
   114 
       
   115 void MsgUnifiedEditorSubject::onContentsChanged(const QString& text)
       
   116 {
       
   117     // reject any text input if mms size limit is reached
       
   118     int futureSize = subjectSize() +
       
   119             MsgUnifiedEditorMonitor::containerSize() + MsgUnifiedEditorMonitor::bodySize();
       
   120     if(futureSize > MsgUnifiedEditorMonitor::maxMmsSize())
       
   121     {
       
   122         // atomic operation
       
   123         disconnect(mSubjectEdit, SIGNAL(contentsChanged(const QString&)),
       
   124                     this, SLOT(onContentsChanged(const QString&)));
       
   125         mSubjectEdit->clearContent();
       
   126         mSubjectEdit->setText(mPrevBuffer);
       
   127         connect(mSubjectEdit, SIGNAL(contentsChanged(const QString&)),
       
   128                         this, SLOT(onContentsChanged(const QString&)));
       
   129         HbMessageBox::information(LOC_UNABLE_TO_ADD_CONTENT, 0, 0, HbMessageBox::Ok);
       
   130         return;
       
   131     }
       
   132 
       
   133     mPrevBuffer = text;
       
   134     if(!subjectOkInSms())
       
   135     {
       
   136         emit contentChanged();
       
   137     }
       
   138 }
       
   139 
       
   140 bool MsgUnifiedEditorSubject::subjectOkInSms()
       
   141 {
       
   142     bool result = false;
       
   143     int error;
       
   144     TRAP(error, result = mGenUtils->AcceptEmailAddressesL());
       
   145     return result;    
       
   146 }
       
   147 
       
   148 int MsgUnifiedEditorSubject::subjectSize()
       
   149 {
       
   150     return mGenUtils->UTF8Size(mSubjectEdit->content());
       
   151 }
       
   152 
       
   153 void MsgUnifiedEditorSubject::setText(const QString& text)
       
   154 {
       
   155     if(!text.isEmpty())
       
   156     {
       
   157         mSubjectEdit->setText(text);
       
   158     }
       
   159 }
       
   160 
       
   161 void MsgUnifiedEditorSubject::setFocus()
       
   162 {
       
   163     mSubjectEdit->setFocus(Qt::MouseFocusReason);
       
   164 }
       
   165 
       
   166 //EOF