ui/commandhandlers/commoncommandhandlers/src/glxcommondialogs.cpp
author hgs
Mon, 27 Sep 2010 15:13:20 +0530
changeset 69 45459746d5e8
parent 62 36d93b4dc635
permissions -rw-r--r--
201039
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
69
hgs
parents: 62
diff changeset
    24
// this is regexp for valid file/folder name: no \/:*?"<>| and is not totally empty characters.
hgs
parents: 62
diff changeset
    25
// file name can not end with "." , but it is not include in this RegExp. It should be checked in Regex_ValidNotEndWithDot
hgs
parents: 62
diff changeset
    26
// this expression is composed by two expressions:
hgs
parents: 62
diff changeset
    27
// ^.*[^\\s].*$  used to match un-empty string and is not totally empty characters.
hgs
parents: 62
diff changeset
    28
// [^\\\\/:*?\"<>|] used to math valid file/folder name
hgs
parents: 62
diff changeset
    29
// merge the two regex together:
hgs
parents: 62
diff changeset
    30
// valid file/folder name and is not totally empty.
hgs
parents: 62
diff changeset
    31
#define Regex_ValidFileFolderName QString( "^[^\\\\/:*?\"<>|]*[^\\\\/:*?\"<>|\\s][^\\\\/:*?\"<>|]*$" )
hgs
parents: 62
diff changeset
    32
hgs
parents: 62
diff changeset
    33
// is not end with dot( trim blank characters in the end first )
hgs
parents: 62
diff changeset
    34
#define Regex_ValidNotEndWithDot QString( "^.*[^\\.\\s][\\s]*$" )
hgs
parents: 62
diff changeset
    35
58
hgs
parents: 40
diff changeset
    36
GlxTextInputDialog::GlxTextInputDialog(bool disableOkForEmptyText) 
40
hgs
parents: 26
diff changeset
    37
    : mDialog ( NULL ),
hgs
parents: 26
diff changeset
    38
      mEventLoop ( 0 ),
58
hgs
parents: 40
diff changeset
    39
      mResult ( false ),
hgs
parents: 40
diff changeset
    40
      mDisableOkForEmptyText(disableOkForEmptyText)
40
hgs
parents: 26
diff changeset
    41
{
hgs
parents: 26
diff changeset
    42
}
26
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    43
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    44
GlxTextInputDialog::~GlxTextInputDialog()
40
hgs
parents: 26
diff changeset
    45
{
hgs
parents: 26
diff changeset
    46
}
26
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    47
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    48
QString GlxTextInputDialog::getText(const QString &label,
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    49
        const QString &text, bool *ok)
40
hgs
parents: 26
diff changeset
    50
{
hgs
parents: 26
diff changeset
    51
    QEventLoop eventLoop;
hgs
parents: 26
diff changeset
    52
    mEventLoop = &eventLoop;
hgs
parents: 26
diff changeset
    53
    
26
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    54
    mDialog = new HbInputDialog();
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    55
    mDialog->setPromptText(label);
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    56
    mDialog->setInputMode(HbInputDialog::TextInput);
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    57
    mDialog->setValue(text);
62
hgs
parents: 58
diff changeset
    58
    mDialog->lineEdit(0)->setMaxLength(MAXSTRINGLENGHT);
58
hgs
parents: 40
diff changeset
    59
    if(mDisableOkForEmptyText){
hgs
parents: 40
diff changeset
    60
        connect(mDialog->lineEdit(0), SIGNAL( textChanged (const QString &) ),
hgs
parents: 40
diff changeset
    61
                this, SLOT( textChanged (const QString &)));
hgs
parents: 40
diff changeset
    62
    }
40
hgs
parents: 26
diff changeset
    63
    mDialog->open( this, SLOT( dialogClosed( HbAction* ) ) ); 
hgs
parents: 26
diff changeset
    64
    eventLoop.exec( );
hgs
parents: 26
diff changeset
    65
    mEventLoop = 0 ;
hgs
parents: 26
diff changeset
    66
    
hgs
parents: 26
diff changeset
    67
    if ( ok ) {
hgs
parents: 26
diff changeset
    68
        *ok = mResult ;
hgs
parents: 26
diff changeset
    69
    }
26
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    70
    QString retText = NULL;
40
hgs
parents: 26
diff changeset
    71
    if ( mResult ) {
26
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    72
        retText = mDialog->value().toString().trimmed();
40
hgs
parents: 26
diff changeset
    73
    }
58
hgs
parents: 40
diff changeset
    74
    if(mDisableOkForEmptyText){
hgs
parents: 40
diff changeset
    75
        disconnect(mDialog->lineEdit(0), SIGNAL( textChanged (const QString &) ),
hgs
parents: 40
diff changeset
    76
                    this, SLOT( textChanged (const QString &)));
hgs
parents: 40
diff changeset
    77
    }
26
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    78
    delete mDialog;
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    79
    mDialog = NULL;
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    80
    return retText;
40
hgs
parents: 26
diff changeset
    81
}
26
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    82
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    83
void GlxTextInputDialog::textChanged(const QString &text)
40
hgs
parents: 26
diff changeset
    84
{
69
hgs
parents: 62
diff changeset
    85
    // check if all regExp match, disable primary action if not match
hgs
parents: 62
diff changeset
    86
    QStringList regExpList = (QStringList() << Regex_ValidFileFolderName << Regex_ValidNotEndWithDot );
hgs
parents: 62
diff changeset
    87
    
hgs
parents: 62
diff changeset
    88
    bool validateResult = true;
hgs
parents: 62
diff changeset
    89
    foreach( const QString &regExpString, regExpList ) {
hgs
parents: 62
diff changeset
    90
        if( !regExpString.isEmpty() ) {
hgs
parents: 62
diff changeset
    91
            QRegExp regExp( regExpString );
hgs
parents: 62
diff changeset
    92
            if( !regExp.exactMatch( text ) ) {
hgs
parents: 62
diff changeset
    93
                validateResult =  false;
hgs
parents: 62
diff changeset
    94
            }
hgs
parents: 62
diff changeset
    95
        }
hgs
parents: 62
diff changeset
    96
    }
hgs
parents: 62
diff changeset
    97
    
hgs
parents: 62
diff changeset
    98
    if(!validateResult){
40
hgs
parents: 26
diff changeset
    99
        mDialog->actions().first()->setEnabled(false);
hgs
parents: 26
diff changeset
   100
    }
hgs
parents: 26
diff changeset
   101
    else {
hgs
parents: 26
diff changeset
   102
        mDialog->actions().first()->setEnabled(true);
26
c499df2dbb33 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   103
    }
40
hgs
parents: 26
diff changeset
   104
}
hgs
parents: 26
diff changeset
   105
hgs
parents: 26
diff changeset
   106
void GlxTextInputDialog::dialogClosed(HbAction *action)
hgs
parents: 26
diff changeset
   107
{
hgs
parents: 26
diff changeset
   108
    HbInputDialog *dlg = static_cast<HbInputDialog*>(sender());
hgs
parents: 26
diff changeset
   109
    if( action == dlg->actions().first() ) {
hgs
parents: 26
diff changeset
   110
        mResult = true ;
hgs
parents: 26
diff changeset
   111
    }
hgs
parents: 26
diff changeset
   112
    else {
hgs
parents: 26
diff changeset
   113
        mResult = false ;
hgs
parents: 26
diff changeset
   114
    }
hgs
parents: 26
diff changeset
   115
    if ( mEventLoop && mEventLoop->isRunning( ) ) {
hgs
parents: 26
diff changeset
   116
        mEventLoop->exit( 0 );
hgs
parents: 26
diff changeset
   117
    }
hgs
parents: 26
diff changeset
   118
}