Salome HOME
Moved some functionality to VTKViewer_Utilities.h
[modules/kernel.git] / src / SALOMEGUI / QAD_DirListDlg.cxx
index a45638cd539f3fb928485727d869f8508bed902b..a0479d94492917011876b13c5946d98c29b3ad26 100644 (file)
@@ -9,7 +9,6 @@
 //  Module : SALOME
 //  $Header$
 
-using namespace std;
 #include "QAD_DirListDlg.h"
 #include "QAD_Desktop.h"
 #include "QAD_FileDlg.h"
@@ -19,6 +18,7 @@ using namespace std;
 #include <qlabel.h>
 #include <qpushbutton.h>
 #include <qapplication.h>
+using namespace std;
 
 #define MIN_WIDTH     400
 #define MIN_HEIGHT    200
@@ -142,9 +142,41 @@ void QAD_DirListDlg::setPathList(const QStringList& list) {
 /*!
   Validates entered path, returns true if OK
 */
+#ifndef WNT
+#include <pwd.h>
+#endif
 bool QAD_DirListDlg::validate() {
   if (myEdited) {
     QString dirPath = myEdit->text().stripWhiteSpace();
+#ifndef WNT
+    if ( dirPath.startsWith( "~") ) {
+      dirPath = dirPath.remove(0,1);
+      QString user;
+      int slashPos = dirPath.find("/");
+      if ( slashPos >= 0 ) {
+       user = dirPath.left(slashPos);
+       dirPath = dirPath.mid(slashPos);
+      }
+      else {
+       user = dirPath;
+       dirPath = "";
+      }
+      if ( user.isEmpty() )
+       user = getenv( "USER" );
+
+      struct passwd* user_data = getpwnam( user.latin1() );
+      if ( user_data == NULL ) {
+       // unknown user or something another error
+       QAD_MessageBox::error1(this, 
+                              tr("ERR_ERROR"),
+                              tr("Unknown user %1").arg(user), 
+                              tr("BUT_OK"));
+       myEdit->setFocus();
+        return false;
+      }
+      dirPath = user_data->pw_dir + dirPath;
+    }
+#endif
     QDir dir(dirPath);
     QListBoxItem* found = 0;
     for (unsigned i = 0; i < myDirList->count()-1; i++) {