filemanager/src/filemanager/src/components/fmsingletextquery.cpp
branchRCL_3
changeset 20 491b3ed49290
equal deleted inserted replaced
19:95243422089a 20:491b3ed49290
       
     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  * 
       
    15  * Description:
       
    16  *     The source file of the drive rename query of file manager
       
    17  */
       
    18 
       
    19 #include "fmsingletextquery.h"
       
    20 
       
    21 #include <QGraphicsLinearLayout>
       
    22 #include <QRegExp>
       
    23 
       
    24 #include <hbwidget.h>
       
    25 #include <hblineedit.h>
       
    26 #include <hbaction.h>
       
    27 
       
    28 FmSingleTextQuery::FmSingleTextQuery( HbLineEdit::EchoMode echoMode, QGraphicsItem *parent  ) :
       
    29     FmDialog( parent ), mEchoMode( echoMode )
       
    30 {
       
    31     init();
       
    32 }
       
    33 
       
    34 FmSingleTextQuery::~FmSingleTextQuery()
       
    35 {
       
    36 }
       
    37 
       
    38 void FmSingleTextQuery::init()
       
    39 {
       
    40     setObjectName( "SingleTextQuery " );
       
    41     setDismissPolicy( HbPopup::NoDismiss );
       
    42     mContentWidget = new HbWidget();
       
    43     mContentWidget->setObjectName( "SingleTextContentWidget" );
       
    44     setContentWidget( mContentWidget );
       
    45 	
       
    46 
       
    47     QGraphicsLinearLayout *vLayout = new QGraphicsLinearLayout();
       
    48     vLayout->setOrientation( Qt::Vertical );
       
    49 
       
    50     mTextEdit = new HbLineEdit();
       
    51     mTextEdit->setEchoMode( mEchoMode );
       
    52     mTextEdit->setFontSpec( HbFontSpec( HbFontSpec::Primary ) );
       
    53     mTextEdit->setObjectName( "textLineEdit" );
       
    54 	vLayout->addItem( mTextEdit );
       
    55 
       
    56     mContentWidget->setLayout( vLayout );
       
    57 
       
    58     setTimeout( NoTimeout );
       
    59 
       
    60     connect( mTextEdit, SIGNAL(contentsChanged()), this, SLOT(checkActions()) );
       
    61 }
       
    62 
       
    63 void FmSingleTextQuery::setLineEditText( const QString &text )
       
    64 {
       
    65     mTextEdit->setText( text );
       
    66     mTextEdit->setSelection( 0, text.length() );
       
    67 }
       
    68 
       
    69 QString FmSingleTextQuery::getLineEditText()
       
    70 {
       
    71     QString text = mTextEdit->text();
       
    72 
       
    73     return text;
       
    74 }
       
    75 
       
    76 void FmSingleTextQuery::setLineEditMaxLength( int length )
       
    77 {
       
    78     mTextEdit->setMaxLength( length );
       
    79 }
       
    80 
       
    81 void FmSingleTextQuery::setRegExpStringList( QStringList regExpStringList )
       
    82 {
       
    83 	mRegExpStringList = regExpStringList;
       
    84 }
       
    85 
       
    86 void FmSingleTextQuery::checkActions()
       
    87 {
       
    88     // check if all regExp match, disable primary action if not match
       
    89     bool validateResult = true;
       
    90     foreach( const QString &regExpString, mRegExpStringList ) {
       
    91         if( !regExpString.isEmpty() ) {
       
    92             QRegExp regExp( regExpString );
       
    93             if( !regExp.exactMatch( mTextEdit->text() ) ) {
       
    94                 validateResult =  false;
       
    95             }
       
    96         }
       
    97     }
       
    98     if( validateResult ) {
       
    99         this->primaryAction()->setEnabled( true );
       
   100     } else {
       
   101         this->primaryAction()->setEnabled( false );
       
   102     }
       
   103 }