ui/commandhandlers/commoncommandhandlers/src/glxcommondialogs.cpp
branchRCL_3
changeset 59 8e5f6eea9c9f
equal deleted inserted replaced
57:ea65f74e6de4 59:8e5f6eea9c9f
       
     1 /*
       
     2 * Copyright (c) 2009 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: 
       
    15 *
       
    16 */
       
    17 
       
    18 #include <glxcommondialogs.h>
       
    19 
       
    20 #include <hbaction.h>
       
    21 #include <QEventLoop>
       
    22 
       
    23 GlxTextInputDialog::GlxTextInputDialog(bool disableOkForEmptyText) 
       
    24     : mDialog ( NULL ),
       
    25       mEventLoop ( 0 ),
       
    26       mResult ( false ),
       
    27       mDisableOkForEmptyText(disableOkForEmptyText)
       
    28 {
       
    29 }
       
    30 
       
    31 GlxTextInputDialog::~GlxTextInputDialog()
       
    32 {
       
    33 }
       
    34 
       
    35 QString GlxTextInputDialog::getText(const QString &label,
       
    36         const QString &text, bool *ok)
       
    37 {
       
    38     QEventLoop eventLoop;
       
    39     mEventLoop = &eventLoop;
       
    40     
       
    41     mDialog = new HbInputDialog();
       
    42     mDialog->setPromptText(label);
       
    43     mDialog->setInputMode(HbInputDialog::TextInput);
       
    44     mDialog->setValue(text);
       
    45     if(mDisableOkForEmptyText){
       
    46         connect(mDialog->lineEdit(0), SIGNAL( textChanged (const QString &) ),
       
    47                 this, SLOT( textChanged (const QString &)));
       
    48     }
       
    49     mDialog->open( this, SLOT( dialogClosed( HbAction* ) ) ); 
       
    50     eventLoop.exec( );
       
    51     mEventLoop = 0 ;
       
    52     
       
    53     if ( ok ) {
       
    54         *ok = mResult ;
       
    55     }
       
    56     QString retText = NULL;
       
    57     if ( mResult ) {
       
    58         retText = mDialog->value().toString().trimmed();
       
    59     }
       
    60     if(mDisableOkForEmptyText){
       
    61         disconnect(mDialog->lineEdit(0), SIGNAL( textChanged (const QString &) ),
       
    62                     this, SLOT( textChanged (const QString &)));
       
    63     }
       
    64     delete mDialog;
       
    65     mDialog = NULL;
       
    66     return retText;
       
    67 }
       
    68 
       
    69 void GlxTextInputDialog::textChanged(const QString &text)
       
    70 {
       
    71     if (text.trimmed().isEmpty()) {
       
    72         mDialog->actions().first()->setEnabled(false);
       
    73     }
       
    74     else {
       
    75         mDialog->actions().first()->setEnabled(true);
       
    76     }
       
    77 }
       
    78 
       
    79 void GlxTextInputDialog::dialogClosed(HbAction *action)
       
    80 {
       
    81     HbInputDialog *dlg = static_cast<HbInputDialog*>(sender());
       
    82     if( action == dlg->actions().first() ) {
       
    83         mResult = true ;
       
    84     }
       
    85     else {
       
    86         mResult = false ;
       
    87     }
       
    88     if ( mEventLoop && mEventLoop->isRunning( ) ) {
       
    89         mEventLoop->exit( 0 );
       
    90     }
       
    91 }