diff -r ea65f74e6de4 -r 8e5f6eea9c9f ui/commandhandlers/commoncommandhandlers/src/glxcommondialogs.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/commandhandlers/commoncommandhandlers/src/glxcommondialogs.cpp Tue Aug 31 15:14:51 2010 +0300 @@ -0,0 +1,91 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#include + +#include +#include + +GlxTextInputDialog::GlxTextInputDialog(bool disableOkForEmptyText) + : mDialog ( NULL ), + mEventLoop ( 0 ), + mResult ( false ), + mDisableOkForEmptyText(disableOkForEmptyText) +{ +} + +GlxTextInputDialog::~GlxTextInputDialog() +{ +} + +QString GlxTextInputDialog::getText(const QString &label, + const QString &text, bool *ok) +{ + QEventLoop eventLoop; + mEventLoop = &eventLoop; + + mDialog = new HbInputDialog(); + mDialog->setPromptText(label); + mDialog->setInputMode(HbInputDialog::TextInput); + mDialog->setValue(text); + if(mDisableOkForEmptyText){ + connect(mDialog->lineEdit(0), SIGNAL( textChanged (const QString &) ), + this, SLOT( textChanged (const QString &))); + } + mDialog->open( this, SLOT( dialogClosed( HbAction* ) ) ); + eventLoop.exec( ); + mEventLoop = 0 ; + + if ( ok ) { + *ok = mResult ; + } + QString retText = NULL; + if ( mResult ) { + retText = mDialog->value().toString().trimmed(); + } + if(mDisableOkForEmptyText){ + disconnect(mDialog->lineEdit(0), SIGNAL( textChanged (const QString &) ), + this, SLOT( textChanged (const QString &))); + } + delete mDialog; + mDialog = NULL; + return retText; +} + +void GlxTextInputDialog::textChanged(const QString &text) +{ + if (text.trimmed().isEmpty()) { + mDialog->actions().first()->setEnabled(false); + } + else { + mDialog->actions().first()->setEnabled(true); + } +} + +void GlxTextInputDialog::dialogClosed(HbAction *action) +{ + HbInputDialog *dlg = static_cast(sender()); + if( action == dlg->actions().first() ) { + mResult = true ; + } + else { + mResult = false ; + } + if ( mEventLoop && mEventLoop->isRunning( ) ) { + mEventLoop->exit( 0 ); + } +}