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