+#include <cpPlugins/QT/OpenFileDialog.h>
+
+#ifdef cpPlugins_QT4
+
+#include <cpPlugins/BaseObjects/Parameters.h>
+
+// -------------------------------------------------------------------------
+cpPlugins::QT::OpenFileDialog::
+OpenFileDialog( QWidget* parent )
+ : QFileDialog( parent ),
+ m_Parameters( NULL ),
+ m_Name( "" )
+{
+ this->connect(
+ this, SIGNAL( accepted( ) ), this, SLOT( _dlg_Accepted( ) )
+ );
+ this->setWindowTitle( "Open an(some) file(s)" );
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::QT::OpenFileDialog::
+~OpenFileDialog( )
+{
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::QT::OpenFileDialog::
+SetParameters(
+ cpPlugins::BaseObjects::Parameters* params, const std::string& name
+ )
+{
+ if( params == NULL )
+ {
+ this->m_Parameters = NULL;
+ this->m_Name = "";
+ return;
+
+ } // fi
+ auto param_type = params->GetType( name );
+ if(
+ param_type != cpPlugins::BaseObjects::Parameters::OpenFileName &&
+ param_type != cpPlugins::BaseObjects::Parameters::OpenFileNameList
+ )
+ {
+ this->m_Parameters = NULL;
+ this->m_Name = "";
+ return;
+
+ } // fi
+ this->m_Parameters = params;
+ this->m_Name = name;
+
+ QStringList filters;
+ auto extensions = this->m_Parameters->GetAcceptedFileExtensions( name );
+ if( extensions != "" )
+ filters << extensions.c_str( );
+ filters << "Any file (*)";
+ if( param_type == cpPlugins::BaseObjects::Parameters::OpenFileName )
+ this->setFileMode( QFileDialog::ExistingFile );
+ else
+ this->setFileMode( QFileDialog::ExistingFiles );
+ this->setNameFilters( filters );
+ this->setAcceptMode( QFileDialog::AcceptOpen );
+ if( param_type == cpPlugins::BaseObjects::Parameters::OpenFileName )
+ {
+ auto file = this->m_Parameters->GetOpenFileName( this->m_Name );
+ if( file == "" )
+ file = ".";
+ QFileInfo info( file.c_str( ) );
+ this->setDirectory( info.canonicalPath( ) );
+ }
+ else
+ {
+ auto files = this->m_Parameters->GetOpenFileNameList( this->m_Name );
+ if( files.size( ) > 0 )
+ {
+ QFileInfo info( files[ 0 ].c_str( ) );
+ this->setDirectory( info.canonicalPath( ) );
+ }
+ else
+ this->setDirectory( "." );
+
+ } // fi
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::QT::OpenFileDialog::
+_dlg_Accepted( )
+{
+ if( this->m_Parameters != NULL )
+ {
+ auto files = this->selectedFiles( );
+ auto param_type = this->m_Parameters->GetType( this->m_Name );
+ if( param_type == cpPlugins::BaseObjects::Parameters::OpenFileNameList )
+ {
+ this->m_Parameters->ClearOpenFileNameList( this->m_Name );
+ for( auto fIt = files.begin( ); fIt != files.end( ); ++fIt )
+ this->m_Parameters->AddToOpenFileNameList(
+ this->m_Name, fIt->toStdString( )
+ );
+ }
+ else
+ this->m_Parameters->SetOpenFileName(
+ this->m_Name, files[ 0 ].toStdString( )
+ );
+
+ } // fi
+}
+
+#endif // cpPlugins_QT4
+
+// eof - $RCSfile$