emailuis/nmailui/src/nmutilities.cpp
changeset 43 99bcbff212ad
parent 40 2c62ef3caffd
child 44 c2d07d913565
equal deleted inserted replaced
42:139d4b7b2938 43:99bcbff212ad
    45  */
    45  */
    46 void NmUtilities::getRecipientsFromMessage( const NmMessage &message,
    46 void NmUtilities::getRecipientsFromMessage( const NmMessage &message,
    47     QList<NmAddress> &recipients,
    47     QList<NmAddress> &recipients,
    48     NmAddressValidationType type )
    48     NmAddressValidationType type )
    49 {
    49 {
       
    50     NM_FUNCTION;
       
    51     
    50     // validate TO addresses
    52     // validate TO addresses
    51     QList<NmAddress> toRecipients = message.envelope().toRecipients();
    53     QList<NmAddress> toRecipients = message.envelope().toRecipients();
    52     int recipientCount = toRecipients.count();
    54     int recipientCount = toRecipients.count();
    53 
    55 
    54     for (int i = 0; i < recipientCount; ++i) {
    56     for (int i = 0; i < recipientCount; ++i) {
    93 /*!
    95 /*!
    94   Validates the given string against an email address pattern.
    96   Validates the given string against an email address pattern.
    95 */
    97 */
    96 bool NmUtilities::isValidEmailAddress( const QString &emailAddress )
    98 bool NmUtilities::isValidEmailAddress( const QString &emailAddress )
    97 {
    99 {
       
   100     NM_FUNCTION;
       
   101     
    98     return EmailAddressPattern.exactMatch(emailAddress);
   102     return EmailAddressPattern.exactMatch(emailAddress);
    99 }
   103 }
   100 
   104 
   101 /*!
   105 /*!
   102   Generates a display string from an NmAddress object.
   106   Generates a display string from an NmAddress object.
   103 */
   107 */
   104 QString NmUtilities::addressToDisplayName( const NmAddress &address )
   108 QString NmUtilities::addressToDisplayName( const NmAddress &address )
   105 {
   109 {
       
   110     NM_FUNCTION;
       
   111     
   106     QString emailAddress = address.address();
   112     QString emailAddress = address.address();
   107     QString displayName = address.displayName();
   113     QString displayName = address.displayName();
   108 
   114 
   109     QString ret;
   115     QString ret;
   110     if (displayName.length() > 0 && displayName != emailAddress) {
   116     if (displayName.length() > 0 && displayName != emailAddress) {
   119 /*!
   125 /*!
   120   Returns an NmAddress object that is parsed from a display name string.
   126   Returns an NmAddress object that is parsed from a display name string.
   121 */
   127 */
   122 bool NmUtilities::parseEmailAddress( const QString &emailAddress, NmAddress &address )
   128 bool NmUtilities::parseEmailAddress( const QString &emailAddress, NmAddress &address )
   123 {
   129 {
       
   130     NM_FUNCTION;
       
   131     
   124     bool foundAddress = false;
   132     bool foundAddress = false;
   125 
   133 
   126     QRegExp rx(EmailAddressPattern);
   134     QRegExp rx(EmailAddressPattern);
   127     // locate the email address in the string
   135     // locate the email address in the string
   128     int pos = rx.indexIn(emailAddress);
   136     int pos = rx.indexIn(emailAddress);
   145 /*!
   153 /*!
   146   Cleans up display name by stripping extra characters from the beginning and end of the string.
   154   Cleans up display name by stripping extra characters from the beginning and end of the string.
   147 */
   155 */
   148 QString NmUtilities::cleanupDisplayName( const QString &displayName )
   156 QString NmUtilities::cleanupDisplayName( const QString &displayName )
   149 {
   157 {
       
   158     NM_FUNCTION;
       
   159     
   150     // find the first and last position that is NOT one of the characters below
   160     // find the first and last position that is NOT one of the characters below
   151     QRegExp rx("[^\\s\"<>]");
   161     QRegExp rx("[^\\s\"<>]");
   152     int firstPos = std::max(rx.indexIn(displayName), 0);
   162     int firstPos = std::max(rx.indexIn(displayName), 0);
   153     int lastPos = rx.lastIndexIn(displayName);
   163     int lastPos = rx.lastIndexIn(displayName);
   154 
   164 
   163   Opens file specified by QFile handle. Usually used by editor
   173   Opens file specified by QFile handle. Usually used by editor
   164   for opening added attachments
   174   for opening added attachments
   165 */
   175 */
   166 int NmUtilities::openFile(QFile &file)
   176 int NmUtilities::openFile(QFile &file)
   167 {
   177 {
       
   178     NM_FUNCTION;
       
   179     
   168     int ret(NmNotFoundError);
   180     int ret(NmNotFoundError);
   169     XQApplicationManager aiwMgr;
   181     XQApplicationManager aiwMgr;
   170     XQAiwRequest *request(NULL);
   182     XQAiwRequest *request(NULL);
   171     request = aiwMgr.create(file);
   183     request = aiwMgr.create(file);
   172     // If request is created then there is a handler for that file
   184     // If request is created then there is a handler for that file
   191   Opens file specified by RFile handle. Usually used by viewer
   203   Opens file specified by RFile handle. Usually used by viewer
   192   for opening attachments from message store as RFiles
   204   for opening attachments from message store as RFiles
   193 */
   205 */
   194 int NmUtilities::openFile(XQSharableFile &file)
   206 int NmUtilities::openFile(XQSharableFile &file)
   195 {
   207 {
       
   208     NM_FUNCTION;
       
   209     
   196     int ret(NmNotFoundError);
   210     int ret(NmNotFoundError);
   197     XQApplicationManager aiwMgr;
   211     XQApplicationManager aiwMgr;
   198     XQAiwRequest *request(NULL);
   212     XQAiwRequest *request(NULL);
   199     request = aiwMgr.create(file);  
   213     request = aiwMgr.create(file);  
   200     // Create request for the sharable file
   214     // Create request for the sharable file
   218  * Truncate a string to a specific length. If length is less than
   232  * Truncate a string to a specific length. If length is less than
   219  * the string, ellipses are added to the end of the string.
   233  * the string, ellipses are added to the end of the string.
   220  */
   234  */
   221 QString NmUtilities::truncate( const QString &string, int length )
   235 QString NmUtilities::truncate( const QString &string, int length )
   222 {
   236 {
       
   237     NM_FUNCTION;
       
   238     
   223     if (string.length() <= length) {
   239     if (string.length() <= length) {
   224         return string;
   240         return string;
   225     }
   241     }
   226 
   242 
   227     QString padding = "...";
   243     QString padding = "...";
   233  * Shows an error note. Used by at least editor and viewer classes.
   249  * Shows an error note. Used by at least editor and viewer classes.
   234  * 
   250  * 
   235  */
   251  */
   236 void NmUtilities::displayErrorNote(QString noteText)
   252 void NmUtilities::displayErrorNote(QString noteText)
   237 {
   253 {
       
   254     NM_FUNCTION;
       
   255     
   238 	HbNotificationDialog *note = new HbNotificationDialog();
   256 	HbNotificationDialog *note = new HbNotificationDialog();
   239 	
   257 	
   240 	note->setIcon(HbIcon(QLatin1String("note_warning")));
   258 	note->setIcon(HbIcon(QLatin1String("note_warning")));
   241 	note->setTitle(noteText);
   259 	note->setTitle(noteText);
   242 	note->setTitleTextWrapping(Hb::TextWordWrap);
   260 	note->setTitleTextWrapping(Hb::TextWordWrap);
   251     Function returns localized attachment size string based
   269     Function returns localized attachment size string based
   252     on attachment size in bytes
   270     on attachment size in bytes
   253  */
   271  */
   254 QString NmUtilities::attachmentSizeString(const int sizeInBytes)
   272 QString NmUtilities::attachmentSizeString(const int sizeInBytes)
   255 {
   273 {
       
   274     NM_FUNCTION;
       
   275     
   256     qreal sizeMb = (qreal)sizeInBytes / (qreal)NmMegabyte;
   276     qreal sizeMb = (qreal)sizeInBytes / (qreal)NmMegabyte;
   257     if (sizeMb < 0.1) {
   277     if (sizeMb < 0.1) {
   258         // 0.1 Mb is the minimum size shown for attachment
   278         // 0.1 Mb is the minimum size shown for attachment
   259         sizeMb = 0.1;
   279         sizeMb = 0.1;
   260     }
   280     }
   261     return QString().sprintf("(%.1f Mb)", sizeMb); // Use loc string when available    
   281     return QString().sprintf("(%.1f Mb)", sizeMb); // Use loc string when available    
   262 }
   282 }
   263 
   283 
   264 /*!
   284 /*!
   265     takes care of necessary error/information note displaying based on the given operation completion event
       
   266     returns boolean whether settings should be opened or not
       
   267 */
       
   268 bool NmUtilities::displayOperationCompletionNote(const NmOperationCompletionEvent &event)
       
   269 {
       
   270     bool openSettings(false);
       
   271     // nothing to do in successfull or cancelled case
       
   272     if(event.mCompletionCode != NmNoError && event.mCompletionCode != NmCancelError) {
       
   273         if(event.mOperationType == Synch && event.mCompletionCode == NmAuthenticationError) {
       
   274 /*
       
   275  * Commented out temporarily, because of wk18 HbDialog API deprecation.
       
   276  *         openSettings = displayQuestionNote(hbTrId("txt_mail_dialog_address_or_password_incorrect"));
       
   277  */
       
   278         }
       
   279         if(event.mOperationType == Synch && event.mCompletionCode == NmServerConnectionError) {
       
   280 /*
       
   281  * Commented out temporarily, because of wk18 HbDialog API deprecation.
       
   282  *         openSettings = displayQuestionNote(hbTrId("txt_mail_dialog_server_settings_incorrect"));
       
   283  */
       
   284         }
       
   285         // following applies to all operation/event types
       
   286         if(event.mCompletionCode == NmConnectionError) {
       
   287             displayWarningNote(hbTrId("txt_mail_dialog_mail_connection_error"));
       
   288         }
       
   289     }
       
   290     return openSettings;
       
   291 }
       
   292 
       
   293 /*!
       
   294     Displays a note with Yes/No buttons. Note has no timeout, i.e. it has to be dismissed manually.
   285     Displays a note with Yes/No buttons. Note has no timeout, i.e. it has to be dismissed manually.
   295     Returns pointer to dialog so that caller can take ownership and handle deletion.
   286     Returns pointer to dialog so that caller can take ownership and handle deletion.
   296     Parameter 'receiver' is the object and 'member' is the slot where user selection is passed. 
   287     Parameter 'receiver' is the object and 'member' is the slot where user selection is passed. 
   297 */
   288 */
   298 HbMessageBox* NmUtilities::displayQuestionNote(
   289 HbMessageBox* NmUtilities::displayQuestionNote(
   299     QString noteText, QObject* receiver, const char* member)
   290     QString noteText, QObject* receiver, const char* member)
   300 {
   291 {
       
   292     NM_FUNCTION;
       
   293     
   301     HbMessageBox *messageBox = new HbMessageBox(HbMessageBox::MessageTypeQuestion);
   294     HbMessageBox *messageBox = new HbMessageBox(HbMessageBox::MessageTypeQuestion);
   302     messageBox->setText(noteText);
   295     messageBox->setText(noteText);
   303     messageBox->setTimeout(HbMessageBox::NoTimeout); // Note has to be dismissed manually
   296     messageBox->setTimeout(HbMessageBox::NoTimeout); // Note has to be dismissed manually
   304     messageBox->open(receiver, member);
   297     messageBox->open(receiver, member);
   305     return messageBox;
   298     return messageBox;
   308 /*!
   301 /*!
   309  * displays an error note with no buttons. Note dismisses itself after NmShortInterval.
   302  * displays an error note with no buttons. Note dismisses itself after NmShortInterval.
   310  */
   303  */
   311 void NmUtilities::displayWarningNote(QString noteText)
   304 void NmUtilities::displayWarningNote(QString noteText)
   312 {
   305 {
       
   306     NM_FUNCTION;
       
   307     
   313     HbMessageBox *messageBox = new HbMessageBox(HbMessageBox::MessageTypeWarning);
   308     HbMessageBox *messageBox = new HbMessageBox(HbMessageBox::MessageTypeWarning);
   314     messageBox->setText(noteText);
   309     messageBox->setText(noteText);
   315     messageBox->setTimeout(NmShortInterval);
   310     messageBox->setTimeout(NmShortInterval);
   316     messageBox->clearActions(); // gets rid of buttons from the note
   311     messageBox->clearActions(); // gets rid of buttons from the note
   317     messageBox->setModal(false);
   312     messageBox->setModal(false);
   325     Function returns localized "Original message" header
   320     Function returns localized "Original message" header
   326     in html format based on envelope
   321     in html format based on envelope
   327 */
   322 */
   328 QString NmUtilities::createReplyHeader(const NmMessageEnvelope &env)
   323 QString NmUtilities::createReplyHeader(const NmMessageEnvelope &env)
   329 {
   324 {
       
   325     NM_FUNCTION;
       
   326     
   330     QString ret = "<html><body><br><br>";
   327     QString ret = "<html><body><br><br>";
   331     // Append "----- Original message ----" text
   328     // Append "----- Original message ----" text
   332     ret+=hbTrId("txt_mail_editor_reply_original_msg");                  
   329     ret+=hbTrId("txt_mail_editor_reply_original_msg");                  
   333     // Append sender
   330     // Append sender
   334     ret+="<br>";
   331     ret+="<br>";