ui/commandhandlers/commoncommandhandlers/src/glxcommondialogs.cpp
changeset 69 45459746d5e8
parent 62 36d93b4dc635
--- a/ui/commandhandlers/commoncommandhandlers/src/glxcommondialogs.cpp	Mon Sep 20 12:39:08 2010 +0530
+++ b/ui/commandhandlers/commoncommandhandlers/src/glxcommondialogs.cpp	Mon Sep 27 15:13:20 2010 +0530
@@ -21,6 +21,18 @@
 #include <QEventLoop>
 const int MAXSTRINGLENGHT = 256; 
 
+// this is regexp for valid file/folder name: no \/:*?"<>| and is not totally empty characters.
+// file name can not end with "." , but it is not include in this RegExp. It should be checked in Regex_ValidNotEndWithDot
+// this expression is composed by two expressions:
+// ^.*[^\\s].*$  used to match un-empty string and is not totally empty characters.
+// [^\\\\/:*?\"<>|] used to math valid file/folder name
+// merge the two regex together:
+// valid file/folder name and is not totally empty.
+#define Regex_ValidFileFolderName QString( "^[^\\\\/:*?\"<>|]*[^\\\\/:*?\"<>|\\s][^\\\\/:*?\"<>|]*$" )
+
+// is not end with dot( trim blank characters in the end first )
+#define Regex_ValidNotEndWithDot QString( "^.*[^\\.\\s][\\s]*$" )
+
 GlxTextInputDialog::GlxTextInputDialog(bool disableOkForEmptyText) 
     : mDialog ( NULL ),
       mEventLoop ( 0 ),
@@ -70,7 +82,20 @@
 
 void GlxTextInputDialog::textChanged(const QString &text)
 {
-    if (text.trimmed().isEmpty()) {
+    // check if all regExp match, disable primary action if not match
+    QStringList regExpList = (QStringList() << Regex_ValidFileFolderName << Regex_ValidNotEndWithDot );
+    
+    bool validateResult = true;
+    foreach( const QString &regExpString, regExpList ) {
+        if( !regExpString.isEmpty() ) {
+            QRegExp regExp( regExpString );
+            if( !regExp.exactMatch( text ) ) {
+                validateResult =  false;
+            }
+        }
+    }
+    
+    if(!validateResult){
         mDialog->actions().first()->setEnabled(false);
     }
     else {