emailuis/nmailui/src/nmutilities.cpp
changeset 53 bf7eb7911fc5
parent 30 759dc5235cdb
child 47 f83bd4ae1fe3
--- a/emailuis/nmailui/src/nmutilities.cpp	Fri Jun 11 13:27:14 2010 +0300
+++ b/emailuis/nmailui/src/nmutilities.cpp	Wed Jun 23 18:00:21 2010 +0300
@@ -18,7 +18,6 @@
 #include "nmuiheaders.h"
 
 static const int NmMegabyte = 1048576;
-static const int NmShortInterval = 1000; // 1 sec
 
 // taken from http://www.regular-expressions.info/email.html
 static const QRegExp EmailAddressPattern("[A-Za-z\\d!#$%&'*+/=?^_`{|}~-]+"
@@ -48,7 +47,7 @@
     NmAddressValidationType type )
 {
     NM_FUNCTION;
-    
+
     // validate TO addresses
     QList<NmAddress> toRecipients = message.envelope().toRecipients();
     int recipientCount = toRecipients.count();
@@ -98,7 +97,7 @@
 bool NmUtilities::isValidEmailAddress( const QString &emailAddress )
 {
     NM_FUNCTION;
-    
+
     return EmailAddressPattern.exactMatch(emailAddress);
 }
 
@@ -108,7 +107,7 @@
 QString NmUtilities::addressToDisplayName( const NmAddress &address )
 {
     NM_FUNCTION;
-    
+
     QString emailAddress = address.address();
     QString displayName = address.displayName();
 
@@ -128,7 +127,7 @@
 bool NmUtilities::parseEmailAddress( const QString &emailAddress, NmAddress &address )
 {
     NM_FUNCTION;
-    
+
     bool foundAddress = false;
 
     QRegExp rx(EmailAddressPattern);
@@ -156,7 +155,7 @@
 QString NmUtilities::cleanupDisplayName( const QString &displayName )
 {
     NM_FUNCTION;
-    
+
     // find the first and last position that is NOT one of the characters below
     QRegExp rx("[^\\s\"<>]");
     int firstPos = std::max(rx.indexIn(displayName), 0);
@@ -170,53 +169,23 @@
 }
 
 /*!
-  Opens file specified by QFile handle. Usually used by editor
-  for opening added attachments
-*/
-int NmUtilities::openFile(QFile &file)
-{
-    NM_FUNCTION;
-    
-    int ret(NmNotFoundError);
-    XQApplicationManager aiwMgr;
-    XQAiwRequest *request(NULL);
-    request = aiwMgr.create(file);
-    // If request is created then there is a handler for that file
-    if (request) {
-         // Set request arguments
-         QList<QVariant> args;
-         args << file.fileName();
-         request->setArguments(args);
-         // Send the request, ownership of request is transferred
-         bool res = request->send();
-         if (res) {
-             // Request ok, set error status.
-             ret = NmNoError;
-         }
-    }
-    delete request;
-    return ret;
-}
-
-
-/*!
   Opens file specified by RFile handle. Usually used by viewer
   for opening attachments from message store as RFiles
 */
 int NmUtilities::openFile(XQSharableFile &file)
 {
     NM_FUNCTION;
-    
+
     int ret(NmNotFoundError);
     XQApplicationManager aiwMgr;
     XQAiwRequest *request(NULL);
-    request = aiwMgr.create(file);  
+    request = aiwMgr.create(file);
     // Create request for the sharable file
     if (request)
     {
         // Set request arguments
         QList<QVariant> args;
-        args << qVariantFromValue(file);  
+        args << qVariantFromValue(file);
         request->setArguments(args);
         // Send the request, ownership of request is transferred
         bool res = request->send();
@@ -235,7 +204,7 @@
 QString NmUtilities::truncate( const QString &string, int length )
 {
     NM_FUNCTION;
-    
+
     if (string.length() <= length) {
         return string;
     }
@@ -247,14 +216,14 @@
 
 /*!
  * Shows an error note. Used by at least editor and viewer classes.
- * 
+ *
  */
 void NmUtilities::displayErrorNote(QString noteText)
 {
     NM_FUNCTION;
-    
+
 	HbNotificationDialog *note = new HbNotificationDialog();
-	
+
 	note->setIcon(HbIcon(QLatin1String("note_warning")));
 	note->setTitle(noteText);
 	note->setTitleTextWrapping(Hb::TextWordWrap);
@@ -272,25 +241,25 @@
 QString NmUtilities::attachmentSizeString(const int sizeInBytes)
 {
     NM_FUNCTION;
-    
+
     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    
+    return QString().sprintf("(%.1f Mb)", sizeMb); // Use loc string when available
 }
 
 /*!
     Displays a note with Yes/No buttons. Note has no timeout, i.e. it has to be dismissed manually.
     Returns pointer to dialog so that caller can take ownership and handle deletion.
-    Parameter 'receiver' is the object and 'member' is the slot where user selection is passed. 
+    Parameter 'receiver' is the object and 'member' is the slot where user selection is passed.
 */
 HbMessageBox* NmUtilities::displayQuestionNote(
     QString noteText, QObject* receiver, const char* member)
 {
     NM_FUNCTION;
-    
+
     HbMessageBox *messageBox = new HbMessageBox(HbMessageBox::MessageTypeQuestion);
     messageBox->setText(noteText);
     messageBox->setTimeout(HbMessageBox::NoTimeout); // Note has to be dismissed manually
@@ -299,21 +268,17 @@
 }
 
 /*!
- * displays an error note with no buttons. Note dismisses itself after NmShortInterval.
+ * displays an warning note.
  */
-void NmUtilities::displayWarningNote(QString noteText)
+HbMessageBox* NmUtilities::displayWarningNote(QString noteText, QObject* receiver, const char* member)
 {
     NM_FUNCTION;
-    
+
     HbMessageBox *messageBox = new HbMessageBox(HbMessageBox::MessageTypeWarning);
     messageBox->setText(noteText);
-    messageBox->setTimeout(NmShortInterval);
-    messageBox->clearActions(); // gets rid of buttons from the note
-    messageBox->setModal(false);
-    messageBox->setBackgroundFaded(false);
-    messageBox->show();
-
-    delete messageBox;
+    messageBox->setTimeout(HbMessageBox::NoTimeout); // Note has to be dismissed manually
+    messageBox->open(receiver, member);
+    return messageBox;
 }
 
 /*!
@@ -323,33 +288,34 @@
 QString NmUtilities::createReplyHeader(const NmMessageEnvelope &env)
 {
     NM_FUNCTION;
-    
+
     QString ret = "<html><body><br><br>";
     // Append "----- Original message ----" text
-    ret+=hbTrId("txt_mail_editor_reply_original_msg");                  
+    ret+=hbTrId("txt_mail_editor_reply_original_msg");
     // Append sender
     ret+="<br>";
-    ret+=hbTrId("txt_mail_editor_reply_from");               
-    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+="<br>";
-    ret+=hbTrId("txt_mail_editor_reply_sent");   
-    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);   
+    QDateTime localTime = env.sentTime().addSecs(locale.universalTimeOffset());
+    QDate sentLocalDate = localTime.date();
+    ret+=locale.format(sentLocalDate, r_qtn_date_usual);
     // Append to recipients
     const QList<NmAddress> &toList = env.toRecipients();
     if (toList.count()){
         ret+="<br>";
-        ret+=hbTrId("txt_mail_editor_reply_to"); 
-        ret+=" ";    
+        ret+=hbTrId("txt_mail_editor_reply_to");
+        ret+=" ";
         for (int i=0;i<toList.count();i++){
             if (toList[i].displayName().length()){
                 ret+=toList[i].displayName();
@@ -358,16 +324,16 @@
                 ret+=toList[i].address();
             }
             if (i!=toList.count()-1){
-                ret+=";";          
+                ret+=";";
             }
-        }    
+        }
     }
     // Append cc recipients
     const QList<NmAddress> &ccList = env.ccRecipients();
     if (ccList.count()){
         ret+="<br>";
-        ret+=hbTrId("txt_mail_editor_reply_cc"); 
-        ret+=" ";         
+        ret+=hbTrId("txt_mail_editor_reply_cc");
+        ret+=" ";
         for (int i=0;i<ccList.count();i++){
             if (ccList[i].displayName().length()){
                 ret+=ccList[i].displayName();
@@ -376,29 +342,29 @@
                 ret+=ccList[i].address();
             }
             if (i!=toList.count()-1){
-                ret+=";";          
+                ret+=";";
             }
-        }    
+        }
     }
     // Append subject if there is subject to display
     if (env.subject().length()){
         ret+="<br>";
-        ret+=hbTrId("txt_mail_editor_reply_subject"); 
-        ret+=" ";    
-        ret+=env.subject();    
+        ret+=hbTrId("txt_mail_editor_reply_subject");
+        ret+=" ";
+        ret+=env.subject();
     }
-    // Append priority if it is other than normal  
-    if (env.priority()!=NmMessagePriorityNormal){   
+    // Append priority if it is other than normal
+    if (env.priority()!=NmMessagePriorityNormal){
         ret+="<br>";
-        ret+=hbTrId("txt_mail_editor_reply_importance"); 
-        ret+=" ";    
+        ret+=hbTrId("txt_mail_editor_reply_importance");
+        ret+=" ";
         if (env.priority()==NmMessagePriorityLow){
-            ret+=hbTrId("txt_mail_editor_reply_importance_low");         
+            ret+=hbTrId("txt_mail_editor_reply_importance_low");
         }
         else {
-            ret+=hbTrId("txt_mail_editor_reply_importance_high"); 
+            ret+=hbTrId("txt_mail_editor_reply_importance_high");
         }
-    }    
+    }
     ret+="<br></body></html>";
     return ret;
 }