emailuis/nmailui/src/nmutilities.cpp
changeset 23 2dc6caa42ec3
parent 20 ecc8def7944a
child 27 9ba4404ef423
equal deleted inserted replaced
20:ecc8def7944a 23:2dc6caa42ec3
    16 */
    16 */
    17 
    17 
    18 #include "nmuiheaders.h"
    18 #include "nmuiheaders.h"
    19 
    19 
    20 static const int NmMegabyte = 1048576;
    20 static const int NmMegabyte = 1048576;
       
    21 static const int NmShortInterval = 1000; // 1 sec
    21 
    22 
    22 // taken from http://www.regular-expressions.info/email.html
    23 // taken from http://www.regular-expressions.info/email.html
    23 static const QRegExp EmailAddressPattern("[A-Za-z\\d!#$%&'*+/=?^_`{|}~-]+"
    24 static const QRegExp EmailAddressPattern("[A-Za-z\\d!#$%&'*+/=?^_`{|}~-]+"
    24                                          "(?:"
    25                                          "(?:"
    25                                          "\\."
    26                                          "\\."
   259     }
   260     }
   260     return QString().sprintf("(%.1f Mb)", sizeMb); // Use loc string when available    
   261     return QString().sprintf("(%.1f Mb)", sizeMb); // Use loc string when available    
   261 }
   262 }
   262 
   263 
   263 /*!
   264 /*!
   264     takes care of necessary error/information note displaying
   265     takes care of necessary error/information note displaying based on the given operation completion event
   265 */
   266     returns boolean whether settings should be opened or not
   266 void NmUtilities::displayOperationCompletionNote(const NmOperationCompletionEvent &event)
   267 */
   267 {
   268 bool NmUtilities::displayOperationCompletionNote(const NmOperationCompletionEvent &event)
   268     if(event.mCompletionCode != NmNoError) {
   269 {
   269         if(event.mCompletionCode == NmAuthenticationError) {
   270     bool openSettings(false);
   270             HbMessageBox *messageBox = new HbMessageBox(HbMessageBox::MessageTypeWarning);
   271     // nothing to do in successfull or cancelled case
   271             messageBox->setText(hbTrId("txt_mail_dialog_mail_address_or_password_is_incorr"));
   272     if(event.mCompletionCode != NmNoError && event.mCompletionCode != NmCancelError) {
   272             // using default timeout
   273         if(event.mOperationType == Synch && event.mCompletionCode == NmAuthenticationError) {
   273             HbAction *action = messageBox->exec();
   274             openSettings = displayQuestionNote(hbTrId("txt_mail_dialog_address_or_password_incorrect"));
   274         }
   275         }
   275         if(event.mCompletionCode == NmServerConnectionError) {
   276         if(event.mOperationType == Synch && event.mCompletionCode == NmServerConnectionError) {
   276             HbMessageBox *messageBox = new HbMessageBox(HbMessageBox::MessageTypeWarning);
   277             openSettings = displayQuestionNote(hbTrId("txt_mail_dialog_server_settings_incorrect"));
   277             messageBox->setText(hbTrId("txt_mail_dialog_server_settings_incorrect_link"));
   278         }
   278             messageBox->setTimeout(HbMessageBox::NoTimeout);
   279         // following applies to all operation/event types
   279             HbAction *action = messageBox->exec();
   280         if(event.mCompletionCode == NmConnectionError) {
   280             if(action == messageBox->primaryAction()) {
   281             displayWarningNote(hbTrId("txt_mail_dialog_mail_connection_error"));
   281                 // Settings to be launched..
   282         }
   282             }
   283     }
   283         }
   284     return openSettings;
   284     }
   285 }
   285 }
   286 
   286 
   287 /*!
       
   288     displays a note with Yes/No buttons. Note has no timeout, i.e. it has to be dismissed manually
       
   289     returns boolean whether primaryaction was taken (Left button ("Yes") pressed)
       
   290 */
       
   291 bool NmUtilities::displayQuestionNote(QString noteText)
       
   292 {
       
   293 	HbMessageBox::warning(noteText);
       
   294 	return true;
       
   295 	/*
       
   296 	 * Commented out because of exec() deprecation. Will be fixed later...
       
   297 	 * 
       
   298     bool ret(false);
       
   299     HbMessageBox *messageBox = new HbMessageBox(HbMessageBox::MessageTypeQuestion);
       
   300     messageBox->setText(noteText);
       
   301     messageBox->setTimeout(HbMessageBox::NoTimeout); // note has to be dismissed manually
       
   302     HbAction *action = messageBox->exec();
       
   303     if(action == messageBox->primaryAction()) {
       
   304         ret=true; // primary/left button was pressed
       
   305     }
       
   306     delete messageBox;
       
   307     return ret;
       
   308     */
       
   309 }
       
   310 
       
   311 /*!
       
   312  * displays an error note with no buttons. Note dismisses itself after NmShortInterval.
       
   313  */
       
   314 void NmUtilities::displayWarningNote(QString noteText)
       
   315 {
       
   316     HbMessageBox *messageBox = new HbMessageBox(HbMessageBox::MessageTypeWarning);
       
   317     messageBox->setText(noteText);
       
   318     messageBox->setTimeout(NmShortInterval);
       
   319     messageBox->clearActions(); // gets rid of buttons from the note
       
   320     messageBox->setModal(false);
       
   321     messageBox->setBackgroundFaded(false);
       
   322     messageBox->show();
       
   323 
       
   324     delete messageBox;
       
   325 }
   287 
   326 
   288 /*!
   327 /*!
   289     Function returns localized "Original message" header
   328     Function returns localized "Original message" header
   290     in html format based on envelope
   329     in html format based on envelope
   291 */
   330 */
   367         }
   406         }
   368     }    
   407     }    
   369     ret+="<br></body></html>";
   408     ret+="<br></body></html>";
   370     return ret;
   409     return ret;
   371 }
   410 }
   372 
       
   373