src/hbwidgets/devicedialogs/hbdevicemessagebox.cpp
changeset 34 ed14f46c0e55
parent 7 923ff622b8b9
equal deleted inserted replaced
31:7516d6d86cf5 34:ed14f46c0e55
    47 }
    47 }
    48 
    48 
    49 HbDeviceMessageBoxPrivate::~HbDeviceMessageBoxPrivate()
    49 HbDeviceMessageBoxPrivate::~HbDeviceMessageBoxPrivate()
    50 {
    50 {
    51     TRACE_ENTRY
    51     TRACE_ENTRY
    52     // information/warning dialogs may be left at server when client is deleted. If there are no connected
    52     // Dialogs may be left at server when client is deleted. If there are no connected
    53     // signals, device dialog widget is not deleted but runs at server and is closed by a timeout.
    53     // signals, device dialog widget is not deleted but runs at server and is closed by a timeout.
    54     if (mProperties[Type].mValue.toInt() != HbMessageBox::MessageTypeQuestion &&
    54     if (q_ptr->receivers(SIGNAL(aboutToClose())) <= 0) {
    55         q_ptr->receivers(SIGNAL(aboutToClose())) <= 0) {
       
    56         mDeviceDialog->disconnect(q_ptr, SLOT(aboutToClose()));
    55         mDeviceDialog->disconnect(q_ptr, SLOT(aboutToClose()));
    57         mDeviceDialog->disconnect(this, SLOT(triggerAction(QVariantMap)));
    56         mDeviceDialog->disconnect(this, SLOT(triggerAction(QVariantMap)));
    58         if (mUpdateTimerId != 0) {
    57         if (mUpdateTimerId != 0) {
    59             // There's a pending update
    58             // There's a pending update
    60             sendToServer(false); // this also kills the timer
    59             sendToServer(false); // this also kills the timer
   363 
   362 
   364     static const struct { HbPopup::DefaultTimeout timeout; int value; } timeoutValues[] = {
   363     static const struct { HbPopup::DefaultTimeout timeout; int value; } timeoutValues[] = {
   365         {HbPopup::NoTimeout,0},
   364         {HbPopup::NoTimeout,0},
   366         {HbPopup::ConfirmationNoteTimeout,1500},
   365         {HbPopup::ConfirmationNoteTimeout,1500},
   367         {HbPopup::StandardTimeout,3000},
   366         {HbPopup::StandardTimeout,3000},
   368         {HbPopup::ContextMenuTimeout,6000},
   367         {HbPopup::ContextMenuTimeout,6000}
   369     };
   368     };
   370     int count = sizeof(timeoutValues) / sizeof(timeoutValues[0]);
   369     int count = sizeof(timeoutValues) / sizeof(timeoutValues[0]);
   371     if (timeout < 0 || timeout >= count) {
   370     if (timeout < 0 || timeout >= count) {
   372         TRACE_EXIT
   371         TRACE_EXIT
   373         return timeoutValues[HbPopup::NoTimeout].value;
   372         return timeoutValues[HbPopup::NoTimeout].value;
   405 
   404 
   406 /*!
   405 /*!
   407     @stable
   406     @stable
   408     @hbwidgets
   407     @hbwidgets
   409     \class HbDeviceMessageBox
   408     \class HbDeviceMessageBox
   410     \brief HbDeviceMessageBox displays a message box on top of any running applications.
   409     \brief HbDeviceMessageBox displays a message box on top all applications.
   411 
   410 
   412     HbDeviceMessageBox is a device dialog version of HbMessageBox. It displays a message box
   411     HbDeviceMessageBox is a device-dialog version of HbMessageBox. It is a modal
   413     with text, icon or animation and optional accept and reject buttons. It is not a widget.
   412     dialog and displayed on top all applications by a device-dialog service.
   414     The message box is displayed by a device dialog service which HbDeviceMessageBox is a
   413     HbDeviceMessageBox is a client of the service.
   415     client of.
   414 
   416 
   415     For content it provides text, icon or animation and optional accept and reject buttons.
   417     Device dialogs are shown on top of any running applications and are always modal by nature.
       
   418 
   416 
   419     A device message box is lauched by a show(). A new message box is lauched every time show()
   417     A device message box is lauched by a show(). A new message box is lauched every time show()
   420     is called. aboutToClose() signal is emitted when the box has closed. There is also syncronous
   418     is called. aboutToClose() signal is emitted when the box has closed. There is also syncronous
   421     exec() function which launches a message box and waits for it close. exec() is not compatible
   419     exec() function which launches a message box and waits for it close. exec() is not compatible
   422     with gestures and cannot be used from applications that have an user interface.
   420     with gestures and cannot be used from applications that have an user interface.
   438 
   436 
   439     Static convenience functions are provided for launching message boxes. They launch message boxes
   437     Static convenience functions are provided for launching message boxes. They launch message boxes
   440     containing default properties appropriate for the message box type and their contents cannot
   438     containing default properties appropriate for the message box type and their contents cannot
   441     be updated. Information and warning convenience methods return immediately. Question waits for
   439     be updated. Information and warning convenience methods return immediately. Question waits for
   442     a message box to close and is not compatible with gestures.
   440     a message box to close and is not compatible with gestures.
       
   441 
       
   442     If none of HbDeviceMessageBox signals have been connected to, the object can be deleted after
       
   443     show() has been called and device-dialog service takes care showing the message box. If any
       
   444     signals are connected, message box is closed when HbDeviceMessageBox object goes out of scope.  
   443 
   445 
   444     Four types of message boxes are predefined. The type determines a set of default properties that
   446     Four types of message boxes are predefined. The type determines a set of default properties that
   445     are set on construction. Below is a table listing types and their default properties.
   447     are set on construction. Below is a table listing types and their default properties.
   446 
   448 
   447     <table border="1">
   449     <table border="1">
   451         <tr><td>Information</td><td>Info icon</td><td>"Ok" button</td><td>Standard timeout</td><td>Tap anywhere</td><td>Info sound</td></tr>
   453         <tr><td>Information</td><td>Info icon</td><td>"Ok" button</td><td>Standard timeout</td><td>Tap anywhere</td><td>Info sound</td></tr>
   452         <tr><td>Warning</td><td>Warning icon</td><td>"Ok" button</td><td>Standard timeout</td><td>Tap anywhere</td><td>Warn sound</td></tr>
   454         <tr><td>Warning</td><td>Warning icon</td><td>"Ok" button</td><td>Standard timeout</td><td>Tap anywhere</td><td>Warn sound</td></tr>
   453         <tr><td>Question</td><td>Question icon</td><td>"Yes" and "No" buttons</td><td>No timeout</td><td>Button press</td><td>Question sound</td></tr>
   455         <tr><td>Question</td><td>Question icon</td><td>"Yes" and "No" buttons</td><td>No timeout</td><td>Button press</td><td>Question sound</td></tr>
   454     </table>
   456     </table>
   455 
   457 
   456     In place of an icon, message box may conatain an animation. Supported icon animation formats are:
   458     In place of an icon, message box may contain an animation. Supported icon animation formats are:
   457     - GIF (.gif)
   459     - GIF (.gif)
   458     - MNG (.mng)
   460     - MNG (.mng)
   459     - Frame animations (.axml)
   461     - Frame animations (.axml)
   460 
   462 
   461     Sample code:
   463     \section _platform_spec Platform-specific implementation notes for HbDeviceNotificationDialog
       
   464 
       
   465     \subsection _nonsymbian Non-Symbian
       
   466     Device dialog service is implemented only for the Symbian platform. On other platforms device 
       
   467     message boxes are displayed on client's main window.
       
   468 
       
   469     \section _code_samples Sample code
   462 
   470 
   463     \code
   471     \code
   464     // Ask from user whether to continue operation or not.
   472     // Ask from user whether to continue operation or not.
   465     // Uses default accept/reject buttons (yes/no).
   473     // Uses default accept/reject buttons (yes/no).
   466 
   474 
   525     msg->setAnimationDefinition(animationDefinitionXML);
   533     msg->setAnimationDefinition(animationDefinitionXML);
   526     msg->setIconName(logicalIconName);
   534     msg->setIconName(logicalIconName);
   527     msg->show();
   535     msg->show();
   528     \endcode
   536     \endcode
   529 
   537 
   530     \sa HbMessageBox, HbDialog, HbDeviceDialog
   538     \sa HbMessageBox, HbDialog, HbDeviceDialog, CHbDeviceMessageBoxSymbian
   531 */
   539 */
   532 
   540 
   533 /*!
   541 /*!
   534     \fn void HbDeviceMessageBox::aboutToClose();
   542     \fn void HbDeviceMessageBox::aboutToClose();
   535 
   543 
   553     \var HbDeviceMessageBox::ActionRole HbDeviceMessageBox::RejectButtonRole
   561     \var HbDeviceMessageBox::ActionRole HbDeviceMessageBox::RejectButtonRole
   554     Reject button action.
   562     Reject button action.
   555 */
   563 */
   556 
   564 
   557 /*!
   565 /*!
   558     Constructor.
   566     Constructs HbDeviceMessageBox.
       
   567 
   559     \param type Type of the message box.
   568     \param type Type of the message box.
   560     \param parent An optional parameter.
   569     \param parent Parent pointer or 0.
   561 */
   570 */
   562 HbDeviceMessageBox::HbDeviceMessageBox(HbMessageBox::MessageBoxType type, QObject *parent) :
   571 HbDeviceMessageBox::HbDeviceMessageBox(HbMessageBox::MessageBoxType type, QObject *parent) :
   563     QObject(parent), d_ptr(new HbDeviceMessageBoxPrivate)
   572     QObject(parent), d_ptr(new HbDeviceMessageBoxPrivate)
   564 {
   573 {
   565     TRACE_ENTRY
   574     TRACE_ENTRY
   568     d_ptr->init();
   577     d_ptr->init();
   569     TRACE_EXIT
   578     TRACE_EXIT
   570 }
   579 }
   571 
   580 
   572 /*!
   581 /*!
   573     Constructor.
   582     Constructs HbDeviceMessageBox.
       
   583 
   574     \param text Message box text.
   584     \param text Message box text.
   575     \param type Type of the message box.
   585     \param type Type of the message box.
   576     \param parent An optional parameter.
   586     \param parent Parent pointer or 0.
   577 */
   587 */
   578 HbDeviceMessageBox::HbDeviceMessageBox(const QString &text, HbMessageBox::MessageBoxType type,
   588 HbDeviceMessageBox::HbDeviceMessageBox(const QString &text, HbMessageBox::MessageBoxType type,
   579     QObject *parent) : QObject(parent), d_ptr(new HbDeviceMessageBoxPrivate)
   589     QObject *parent) : QObject(parent), d_ptr(new HbDeviceMessageBoxPrivate)
   580 {
   590 {
   581     TRACE_ENTRY
   591     TRACE_ENTRY
   585     setText(text);
   595     setText(text);
   586     TRACE_EXIT
   596     TRACE_EXIT
   587 }
   597 }
   588 
   598 
   589 /*!
   599 /*!
   590     Destructs the class.
   600     Destructs HbDeviceMessageBox. The message box launched by show() is closed if aboutToClose()
       
   601     signal is connected to by an application. Otherwise the box is left executing
       
   602     and should close itself by a timeout.
   591 */
   603 */
   592 HbDeviceMessageBox::~HbDeviceMessageBox()
   604 HbDeviceMessageBox::~HbDeviceMessageBox()
   593 {
   605 {
   594     TRACE_ENTRY
   606     TRACE_ENTRY
   595     delete d_ptr;
   607     delete d_ptr;
   596     TRACE_EXIT
   608     TRACE_EXIT
   597 }
   609 }
   598 
   610 
   599 /*!
   611 /*!
   600     Shows a message box and returns immediately without waiting for it to close. Closing of the
   612     Shows a message box and returns immediately without waiting for it to close. A new message box
       
   613     is launched each time show() is called. Closing of the
   601     message box is indicated by aboutToClose() signal. Button presses are indicated by
   614     message box is indicated by aboutToClose() signal. Button presses are indicated by
   602     QAction::triggered() signals. The message box can be updated while showing by property
   615     QAction::triggered() signals. The message box can be updated while showing by property
   603     setters.
   616     setters.
   604 
   617 
   605     \sa update(), aboutToClose()
   618     \sa update(), aboutToClose()
   700     Type of a showing message box cannot be changed on the fly. show() must be called to launch
   713     Type of a showing message box cannot be changed on the fly. show() must be called to launch
   701     a new message box after setMessageBoxType() has been called.
   714     a new message box after setMessageBoxType() has been called.
   702 
   715 
   703     \param type Message box type.
   716     \param type Message box type.
   704 
   717 
   705     \sa setMessageBoxType()
   718     \sa messageBoxType(), show()
   706 */
   719 */
   707 void HbDeviceMessageBox::setMessageBoxType(HbMessageBox::MessageBoxType type)
   720 void HbDeviceMessageBox::setMessageBoxType(HbMessageBox::MessageBoxType type)
   708 {
   721 {
   709     TRACE_ENTRY
   722     TRACE_ENTRY
   710     // After setType(), a new message is launched by a show()
   723     // After setType(), a new message is launched by a show()
   731 
   744 
   732     \param buttons Message box buttons. A combination of flags,
   745     \param buttons Message box buttons. A combination of flags,
   733     eg. HbMessageBox::Yes | HbMessageBox::No. Button flags are scanned starting from lsb.
   746     eg. HbMessageBox::Yes | HbMessageBox::No. Button flags are scanned starting from lsb.
   734     First button found goes to accept position and so forth.
   747     First button found goes to accept position and so forth.
   735 
   748 
   736     \sa standardButtons()
   749     \sa standardButtons(), show(), update()
   737 */
   750 */
   738 void HbDeviceMessageBox::setStandardButtons(HbMessageBox::StandardButtons buttons)
   751 void HbDeviceMessageBox::setStandardButtons(HbMessageBox::StandardButtons buttons)
   739 {
   752 {
   740     TRACE_ENTRY
   753     TRACE_ENTRY
   741     d_ptr->setStandardButtons(buttons);
   754     d_ptr->setStandardButtons(buttons);
   885     Default actions are owned and deleted by the message box.
   898     Default actions are owned and deleted by the message box.
   886 
   899 
   887     \param action Action or null. Ownership does not transfer.
   900     \param action Action or null. Ownership does not transfer.
   888     \param role Selects an action.
   901     \param role Selects an action.
   889 
   902 
   890     \sa action()
   903     \sa action(), show(), update()
   891 */
   904 */
   892 void HbDeviceMessageBox::setAction(QAction *action, ActionRole role)
   905 void HbDeviceMessageBox::setAction(QAction *action, ActionRole role)
   893 {
   906 {
   894     TRACE_ENTRY
   907     TRACE_ENTRY
   895     HbDeviceMessageBoxPrivate::ActionSelector  actionSelector =
   908     HbDeviceMessageBoxPrivate::ActionSelector  actionSelector =
   904 /*!
   917 /*!
   905     Sets message box text. Supported text formats are the same as HbMessageBox::setText().
   918     Sets message box text. Supported text formats are the same as HbMessageBox::setText().
   906 
   919 
   907     \param text Message box text.
   920     \param text Message box text.
   908 
   921 
   909     \sa text(), HbMessageBox::setText()
   922     \sa text(), show(), update(), HbMessageBox::setText()
   910 */
   923 */
   911 void HbDeviceMessageBox::setText(const QString &text)
   924 void HbDeviceMessageBox::setText(const QString &text)
   912 {
   925 {
   913     TRACE_ENTRY
   926     TRACE_ENTRY
   914     d_ptr->setProperty(HbDeviceMessageBoxPrivate::Text, text);
   927     d_ptr->setProperty(HbDeviceMessageBoxPrivate::Text, text);
   929     Sets message box icon name or animation logical name.
   942     Sets message box icon name or animation logical name.
   930 
   943 
   931     \param aIconName Icon name. Icon can be from Hb resources or themes. Or can be a file in
   944     \param aIconName Icon name. Icon can be from Hb resources or themes. Or can be a file in
   932     a file system.
   945     a file system.
   933 
   946 
   934     \sa IconName()
   947     \sa IconName(), show(), update()
   935 */
   948 */
   936 void HbDeviceMessageBox::setIconName(const QString &iconName)
   949 void HbDeviceMessageBox::setIconName(const QString &iconName)
   937 {
   950 {
   938     TRACE_ENTRY
   951     TRACE_ENTRY
   939     d_ptr->setProperty(HbDeviceMessageBoxPrivate::IconName, iconName);
   952     d_ptr->setProperty(HbDeviceMessageBoxPrivate::IconName, iconName);
   953 /*!
   966 /*!
   954     Enables/disables icon visibility.
   967     Enables/disables icon visibility.
   955 
   968 
   956     \param visible Enables icon visibility.
   969     \param visible Enables icon visibility.
   957 
   970 
   958     \sa iconVisible()
   971     \sa iconVisible(), show(), update()
   959 */
   972 */
   960 void HbDeviceMessageBox::setIconVisible(bool visible)
   973 void HbDeviceMessageBox::setIconVisible(bool visible)
   961 {
   974 {
   962     TRACE_ENTRY
   975     TRACE_ENTRY
   963     d_ptr->setProperty(HbDeviceMessageBoxPrivate::IconVisible, visible);
   976     d_ptr->setProperty(HbDeviceMessageBoxPrivate::IconVisible, visible);
   977 /*!
   990 /*!
   978     Sets message box timeout.
   991     Sets message box timeout.
   979 
   992 
   980     \param timeout Timeout in milliseconds. 0 denotes no timeout (infinite).
   993     \param timeout Timeout in milliseconds. 0 denotes no timeout (infinite).
   981 
   994 
   982     \sa timeout() setTimeout(HbPopup::DefaultTimeout)
   995     \sa timeout(), setTimeout(HbPopup::DefaultTimeout), show(), update()
   983 */
   996 */
   984 void HbDeviceMessageBox::setTimeout(int timeout)
   997 void HbDeviceMessageBox::setTimeout(int timeout)
   985 {
   998 {
   986     TRACE_ENTRY
   999     TRACE_ENTRY
   987     d_ptr->setProperty(HbDeviceMessageBoxPrivate::Timeout, timeout);
  1000     d_ptr->setProperty(HbDeviceMessageBoxPrivate::Timeout, timeout);
   992     Sets timeout to one of HbPopup::DefaultTimeout values. Helps achieving
  1005     Sets timeout to one of HbPopup::DefaultTimeout values. Helps achieving
   993     common look and feel of message boxes.
  1006     common look and feel of message boxes.
   994 
  1007 
   995     \param timeout Timeout as an enumerated constant.
  1008     \param timeout Timeout as an enumerated constant.
   996 
  1009 
   997     \sa enum HbPopup::DefaultTimeout timeout() setTimeout(int)
  1010     \sa enum HbPopup::DefaultTimeout, timeout(), setTimeout(int), show(), update()
   998 */
  1011 */
   999 void HbDeviceMessageBox::setTimeout(HbPopup::DefaultTimeout timeout)
  1012 void HbDeviceMessageBox::setTimeout(HbPopup::DefaultTimeout timeout)
  1000 {
  1013 {
  1001     TRACE_ENTRY
  1014     TRACE_ENTRY
  1002     setTimeout(HbDeviceMessageBoxPrivate::timeoutValue(timeout));
  1015     setTimeout(HbDeviceMessageBoxPrivate::timeoutValue(timeout));
  1018 /*!
  1031 /*!
  1019     Sets message box dismiss policy.
  1032     Sets message box dismiss policy.
  1020 
  1033 
  1021     \param dismissPolicy Dismiss policy.
  1034     \param dismissPolicy Dismiss policy.
  1022 
  1035 
  1023     \sa dismissPolicy()
  1036     \sa dismissPolicy(), show(), update()
  1024 */
  1037 */
  1025 void HbDeviceMessageBox::setDismissPolicy(HbPopup::DismissPolicy dismissPolicy)
  1038 void HbDeviceMessageBox::setDismissPolicy(HbPopup::DismissPolicy dismissPolicy)
  1026 {
  1039 {
  1027     TRACE_ENTRY
  1040     TRACE_ENTRY
  1028     d_ptr->setProperty(HbDeviceMessageBoxPrivate::DismissPolicy, dismissPolicy);
  1041     d_ptr->setProperty(HbDeviceMessageBoxPrivate::DismissPolicy, dismissPolicy);
  1051     - MNG (.mng)
  1064     - MNG (.mng)
  1052         - Frame animations
  1065         - Frame animations
  1053 
  1066 
  1054     \param animationDefinition Path and name of the animation definition file.
  1067     \param animationDefinition Path and name of the animation definition file.
  1055 
  1068 
  1056     \sa setIcon(), animationDefinition(), HbIconAnimationManager::addDefinitionFile()
  1069     \sa setIcon(), animationDefinition(), HbIconAnimationManager::addDefinitionFile(), show(), update()
  1057 */
  1070 */
  1058 void HbDeviceMessageBox::setAnimationDefinition(QString &animationDefinition)
  1071 void HbDeviceMessageBox::setAnimationDefinition(QString &animationDefinition)
  1059 {
  1072 {
  1060     TRACE_ENTRY
  1073     TRACE_ENTRY
  1061     d_ptr->setProperty(HbDeviceMessageBoxPrivate::AnimationDefinition, animationDefinition);
  1074     d_ptr->setProperty(HbDeviceMessageBoxPrivate::AnimationDefinition, animationDefinition);