Salome HOME
Moved some functionality to VTKViewer_Utilities.h
[modules/kernel.git] / src / SALOMEGUI / QAD_DirListDlg.cxx
index 5605f1b5f3197b66dd3de42550d3df3737c248f2..a0479d94492917011876b13c5946d98c29b3ad26 100644 (file)
@@ -1,12 +1,12 @@
-using namespace std;
-//  File      : QAD_DirListDlg.cxx
-//  Created   : 10/10/2002
-//  Descr     : Dialog box for editing of directory list
-
-//  Author    : Vadim SANDLER
-//  Project   : SALOME Pro
-//  Module    : SALOMEGUI 
-//  Copyright : Open CASCADE
+//  SALOME SALOMEGUI : implementation of desktop and GUI kernel
+//
+//  Copyright (C) 2003  CEA/DEN, EDF R&D
+//
+//
+//
+//  File   : QAD_DirListDlg.cxx
+//  Author : Vadim SANDLER
+//  Module : SALOME
 //  $Header$
 
 #include "QAD_DirListDlg.h"
@@ -18,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
@@ -141,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++) {