homescreenapp/hsutils/src/hsmenudialogfactory.cpp
changeset 63 52b0f64eeb51
child 90 3ac3aaebaee5
equal deleted inserted replaced
62:341166945d65 63:52b0f64eeb51
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Menu Dialog
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QString>
       
    19 #include <QStringList>
       
    20 #include <QList>
       
    21 #include <QAction>
       
    22 
       
    23 #include <HbAction>
       
    24 #include <HbMessageBox>
       
    25 #include "hsmenudialogfactory.h"
       
    26 
       
    27 /*!
       
    28     \class HsMenuDialogFactory
       
    29     \ingroup group_hsutils
       
    30 
       
    31     \brief Creates dialog instances for Application Library.
       
    32 
       
    33     \sa HsMenuEvent
       
    34 */
       
    35 
       
    36 /*! \enum HsMenuDialogFactory::Options
       
    37  Describes what actions the dialog will have.
       
    38  */
       
    39 
       
    40 /*! \var HsMenuDialogFactory::Options HsMenuDialogFactory::OkCancel
       
    41  Requested dialog should have two actions in the following order: Ok (confirm) and Cancel (reject).
       
    42  */
       
    43 /*! \var HsMenuDialogFactory::Options HsMenuDialogFactory::Close
       
    44  Requested dialog should have one action: Close.
       
    45  */
       
    46 /*!
       
    47     Creates dialog.
       
    48     \param text to be displayed in the dialog.
       
    49     \param options specify dialog actions.
       
    50     \return requested dialog.
       
    51 */
       
    52 HbMessageBox *HsMenuDialogFactory::create(const QString &text,
       
    53                                  Options options) const
       
    54 {
       
    55 
       
    56     QStringList actionIdentifiers; // head of the list will be first action in dialog
       
    57     HbMessageBox::MessageBoxType type(HbMessageBox::MessageTypeNone);
       
    58 
       
    59     switch (options) {
       
    60 
       
    61     case OkCancel:
       
    62 
       
    63         actionIdentifiers << hbTrId("txt_common_button_ok");
       
    64         actionIdentifiers << hbTrId("txt_common_button_cancel");
       
    65         type = HbMessageBox::MessageTypeQuestion;
       
    66         break;
       
    67 
       
    68     case Close:
       
    69 
       
    70         actionIdentifiers << hbTrId("txt_common_button_close");
       
    71         type = HbMessageBox::MessageTypeInformation;
       
    72         break;
       
    73 
       
    74     default:
       
    75         break;
       
    76     }
       
    77 
       
    78     QScopedPointer<HbMessageBox> box(new HbMessageBox(type));
       
    79 
       
    80     setUpActions(box.data(), actionIdentifiers);
       
    81 
       
    82     box->setText(text);
       
    83     box->setAttribute(Qt::WA_DeleteOnClose);
       
    84 
       
    85     return box.take();
       
    86 }
       
    87 
       
    88 
       
    89 /*!
       
    90     Destructor.
       
    91 */
       
    92 HsMenuDialogFactory::~HsMenuDialogFactory() {}
       
    93 
       
    94 /*!
       
    95     Sets up dialog actions
       
    96     \param box dialog to operate on.
       
    97     \param actionIdentifiers list of translation identifiers for actions. Order of
       
    98     actions in the dialog will reflect the identifiers order in the list.
       
    99 */
       
   100 void HsMenuDialogFactory::setUpActions(HbMessageBox *box,
       
   101                                     const QStringList &translationIdentifiers) const
       
   102 {
       
   103     box->clearActions();
       
   104 
       
   105     foreach (QString identifier, translationIdentifiers) {
       
   106         QScopedPointer<HbAction> action(new HbAction(identifier));
       
   107         action->setParent(box);
       
   108         box->addAction(action.take());
       
   109     }
       
   110 }