ui/commandhandlers/commoncommandhandlers/src/glxcommondialogs.cpp
author hgs
Sat, 04 Sep 2010 11:36:24 +0530
changeset 62 36d93b4dc635
parent 58 383b67fbdb11
child 69 45459746d5e8
permissions -rw-r--r--
201035
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     1
/*
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     3
* All rights reserved.
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     4
* This component and the accompanying materials are made available
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     6
* which accompanies this distribution, and is available
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     8
*
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     9
* Initial Contributors:
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    11
*
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    12
* Contributors:
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    13
*
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    14
* Description: 
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    15
*
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    16
*/
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    17
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    18
#include <glxcommondialogs.h>
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    19
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    20
#include <hbaction.h>
40
hgs
parents: 26
diff changeset
    21
#include <QEventLoop>
62
hgs
parents: 58
diff changeset
    22
const int MAXSTRINGLENGHT = 256; 
26
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    23
58
hgs
parents: 40
diff changeset
    24
GlxTextInputDialog::GlxTextInputDialog(bool disableOkForEmptyText) 
40
hgs
parents: 26
diff changeset
    25
    : mDialog ( NULL ),
hgs
parents: 26
diff changeset
    26
      mEventLoop ( 0 ),
58
hgs
parents: 40
diff changeset
    27
      mResult ( false ),
hgs
parents: 40
diff changeset
    28
      mDisableOkForEmptyText(disableOkForEmptyText)
40
hgs
parents: 26
diff changeset
    29
{
hgs
parents: 26
diff changeset
    30
}
26
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    31
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    32
GlxTextInputDialog::~GlxTextInputDialog()
40
hgs
parents: 26
diff changeset
    33
{
hgs
parents: 26
diff changeset
    34
}
26
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    35
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    36
QString GlxTextInputDialog::getText(const QString &label,
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    37
        const QString &text, bool *ok)
40
hgs
parents: 26
diff changeset
    38
{
hgs
parents: 26
diff changeset
    39
    QEventLoop eventLoop;
hgs
parents: 26
diff changeset
    40
    mEventLoop = &eventLoop;
hgs
parents: 26
diff changeset
    41
    
26
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    42
    mDialog = new HbInputDialog();
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    43
    mDialog->setPromptText(label);
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    44
    mDialog->setInputMode(HbInputDialog::TextInput);
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    45
    mDialog->setValue(text);
62
hgs
parents: 58
diff changeset
    46
    mDialog->lineEdit(0)->setMaxLength(MAXSTRINGLENGHT);
58
hgs
parents: 40
diff changeset
    47
    if(mDisableOkForEmptyText){
hgs
parents: 40
diff changeset
    48
        connect(mDialog->lineEdit(0), SIGNAL( textChanged (const QString &) ),
hgs
parents: 40
diff changeset
    49
                this, SLOT( textChanged (const QString &)));
hgs
parents: 40
diff changeset
    50
    }
40
hgs
parents: 26
diff changeset
    51
    mDialog->open( this, SLOT( dialogClosed( HbAction* ) ) ); 
hgs
parents: 26
diff changeset
    52
    eventLoop.exec( );
hgs
parents: 26
diff changeset
    53
    mEventLoop = 0 ;
hgs
parents: 26
diff changeset
    54
    
hgs
parents: 26
diff changeset
    55
    if ( ok ) {
hgs
parents: 26
diff changeset
    56
        *ok = mResult ;
hgs
parents: 26
diff changeset
    57
    }
26
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    58
    QString retText = NULL;
40
hgs
parents: 26
diff changeset
    59
    if ( mResult ) {
26
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    60
        retText = mDialog->value().toString().trimmed();
40
hgs
parents: 26
diff changeset
    61
    }
58
hgs
parents: 40
diff changeset
    62
    if(mDisableOkForEmptyText){
hgs
parents: 40
diff changeset
    63
        disconnect(mDialog->lineEdit(0), SIGNAL( textChanged (const QString &) ),
hgs
parents: 40
diff changeset
    64
                    this, SLOT( textChanged (const QString &)));
hgs
parents: 40
diff changeset
    65
    }
26
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    66
    delete mDialog;
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    67
    mDialog = NULL;
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    68
    return retText;
40
hgs
parents: 26
diff changeset
    69
}
26
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    70
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    71
void GlxTextInputDialog::textChanged(const QString &text)
40
hgs
parents: 26
diff changeset
    72
{
hgs
parents: 26
diff changeset
    73
    if (text.trimmed().isEmpty()) {
hgs
parents: 26
diff changeset
    74
        mDialog->actions().first()->setEnabled(false);
hgs
parents: 26
diff changeset
    75
    }
hgs
parents: 26
diff changeset
    76
    else {
hgs
parents: 26
diff changeset
    77
        mDialog->actions().first()->setEnabled(true);
26
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    78
    }
40
hgs
parents: 26
diff changeset
    79
}
hgs
parents: 26
diff changeset
    80
hgs
parents: 26
diff changeset
    81
void GlxTextInputDialog::dialogClosed(HbAction *action)
hgs
parents: 26
diff changeset
    82
{
hgs
parents: 26
diff changeset
    83
    HbInputDialog *dlg = static_cast<HbInputDialog*>(sender());
hgs
parents: 26
diff changeset
    84
    if( action == dlg->actions().first() ) {
hgs
parents: 26
diff changeset
    85
        mResult = true ;
hgs
parents: 26
diff changeset
    86
    }
hgs
parents: 26
diff changeset
    87
    else {
hgs
parents: 26
diff changeset
    88
        mResult = false ;
hgs
parents: 26
diff changeset
    89
    }
hgs
parents: 26
diff changeset
    90
    if ( mEventLoop && mEventLoop->isRunning( ) ) {
hgs
parents: 26
diff changeset
    91
        mEventLoop->exit( 0 );
hgs
parents: 26
diff changeset
    92
    }
hgs
parents: 26
diff changeset
    93
}