diff -r 578830873419 -r ecc8def7944a emailuis/nmailui/src/nmutilities.cpp --- a/emailuis/nmailui/src/nmutilities.cpp Fri Apr 16 14:51:52 2010 +0300 +++ b/emailuis/nmailui/src/nmutilities.cpp Mon May 03 12:23:15 2010 +0300 @@ -17,6 +17,8 @@ #include "nmuiheaders.h" +static const int NmMegabyte = 1048576; + // taken from http://www.regular-expressions.info/email.html static const QRegExp EmailAddressPattern("[A-Za-z\\d!#$%&'*+/=?^_`{|}~-]+" "(?:" @@ -188,20 +190,18 @@ Opens file specified by RFile handle. Usually used by viewer for opening attachments from message store as RFiles */ -int NmUtilities::openFile(RFile &file) +int NmUtilities::openFile(XQSharableFile &file) { int ret(NmNotFoundError); - XQSharableFile sf; - sf.setHandle(file); XQApplicationManager aiwMgr; XQAiwRequest *request(NULL); - request = aiwMgr.create(sf); + request = aiwMgr.create(file); // Create request for the sharable file if (request) { // Set request arguments QList args; - args << qVariantFromValue(sf); + args << qVariantFromValue(file); request->setArguments(args); // Send the request, ownership of request is transferred bool res = request->send(); @@ -228,3 +228,146 @@ return string.mid(0, length - padding.length()) + padding; } +/*! + * Shows an error note. Used by at least editor and viewer classes. + * + */ +void NmUtilities::displayErrorNote(QString noteText) +{ + HbNotificationDialog *note = new HbNotificationDialog(); + + note->setIcon(HbIcon(QLatin1String("note_warning"))); + note->setTitle(noteText); + note->setTitleTextWrapping(Hb::TextWordWrap); + note->setDismissPolicy(HbPopup::TapAnywhere); + note->setAttribute(Qt::WA_DeleteOnClose); + note->setSequentialShow(false); + + note->show(); +} + +/*! + Function returns localized attachment size string based + on attachment size in bytes + */ +QString NmUtilities::attachmentSizeString(const int sizeInBytes) +{ + qreal sizeMb = (qreal)sizeInBytes / (qreal)NmMegabyte; + if (sizeMb < 0.1) { + // 0.1 Mb is the minimum size shown for attachment + sizeMb = 0.1; + } + return QString().sprintf("(%.1f Mb)", sizeMb); // Use loc string when available +} + +/*! + takes care of necessary error/information note displaying +*/ +void NmUtilities::displayOperationCompletionNote(const NmOperationCompletionEvent &event) +{ + if(event.mCompletionCode != NmNoError) { + if(event.mCompletionCode == NmAuthenticationError) { + HbMessageBox *messageBox = new HbMessageBox(HbMessageBox::MessageTypeWarning); + messageBox->setText(hbTrId("txt_mail_dialog_mail_address_or_password_is_incorr")); + // using default timeout + HbAction *action = messageBox->exec(); + } + if(event.mCompletionCode == NmServerConnectionError) { + HbMessageBox *messageBox = new HbMessageBox(HbMessageBox::MessageTypeWarning); + messageBox->setText(hbTrId("txt_mail_dialog_server_settings_incorrect_link")); + messageBox->setTimeout(HbMessageBox::NoTimeout); + HbAction *action = messageBox->exec(); + if(action == messageBox->primaryAction()) { + // Settings to be launched.. + } + } + } +} + + +/*! + Function returns localized "Original message" header + in html format based on envelope +*/ +QString NmUtilities::createReplyHeader(const NmMessageEnvelope &env) +{ + QString ret = "

"; + // Append "----- Original message ----" text + ret+=hbTrId("txt_mail_editor_reply_original_msg"); + // Append sender + ret+="
"; + ret+=hbTrId("txt_mail_editor_reply_from"); + ret+=" "; + if (env.sender().displayName().length()){ + ret+=env.sender().displayName(); + } + else{ + ret+=env.sender().address(); + } + // Append sent time + ret+="
"; + ret+=hbTrId("txt_mail_editor_reply_sent"); + ret+=" "; + HbExtendedLocale locale = HbExtendedLocale::system(); + QDate sentLocalDate = env.sentTime().toLocalTime().date(); + ret+=locale.format(sentLocalDate, r_qtn_date_usual); + // Append to recipients + const QList &toList = env.toRecipients(); + if (toList.count()){ + ret+="
"; + ret+=hbTrId("txt_mail_editor_reply_to"); + ret+=" "; + for (int i=0;i &ccList = env.ccRecipients(); + if (ccList.count()){ + ret+="
"; + ret+=hbTrId("txt_mail_editor_reply_cc"); + ret+=" "; + for (int i=0;i