diff --git a/Polyhedron/demo/Polyhedron/MainWindow.cpp b/Polyhedron/demo/Polyhedron/MainWindow.cpp index e547916ace7..ee2274122fe 100644 --- a/Polyhedron/demo/Polyhedron/MainWindow.cpp +++ b/Polyhedron/demo/Polyhedron/MainWindow.cpp @@ -3611,14 +3611,7 @@ void MainWindow::on_actionLoad_a_Scene_from_a_Script_File_triggered() server = server.trimmed(); pk = pk.trimmed(); privK=privK.trimmed(); - QString path; - path = QInputDialog::getText(this, - "", - tr("Enter the name of the scene file.")); - if(path.isEmpty()) - return; - if(!path.contains("Polyhedron_demo_")) - path.prepend("Polyhedron_demo_"); + try{ ssh_session session; bool res = establish_ssh_session_from_agent(session, @@ -3649,7 +3642,22 @@ void MainWindow::on_actionLoad_a_Scene_from_a_Script_File_triggered() "The SSH session could not be started."); return; } + QStringList names; + if(!CGAL::ssh_internal::explore_the_galaxy(session, names)) + { + QMessageBox::warning(this, + "Error", + "Could not find remote directory."); + } + QString path; + path = QInputDialog::getItem(this, + "Choose a file", + tr("Choose the scene file."), + names); filename = QString("%1/load_scene.js").arg(QDir::tempPath()); + if(path.isEmpty()) + return; + path.prepend("Polyhedron_demo_"); path = tr("/tmp/%2").arg(path); res = pull_file(session,path.toStdString().c_str(), filename.toStdString().c_str()); if(!res) diff --git a/Polyhedron/demo/Polyhedron/Use_ssh.cpp b/Polyhedron/demo/Polyhedron/Use_ssh.cpp index c54d4ff14f1..028909251c2 100644 --- a/Polyhedron/demo/Polyhedron/Use_ssh.cpp +++ b/Polyhedron/demo/Polyhedron/Use_ssh.cpp @@ -20,8 +20,10 @@ #include #include #include +#include #include +#include bool test_result(int res) { @@ -355,5 +357,62 @@ bool pull_file(ssh_session &session, return true; } -}} +bool explore_the_galaxy(ssh_session &session, + QStringList& files) +{ + ssh_channel channel; + int rc; + channel = ssh_channel_new(session); + if (channel == NULL) return false; + rc = ssh_channel_open_session(channel); + if (rc != SSH_OK) + { + ssh_channel_free(channel); + return rc; + } + rc = ssh_channel_request_exec(channel, "ls /tmp"); + if (rc != SSH_OK) + { + ssh_channel_close(channel); + ssh_channel_free(channel); + return rc; + } + + char buffer[256]; + int nbytes; + nbytes = ssh_channel_read(channel, buffer, sizeof(buffer), 0); + while (nbytes > 0) + { + + std::string sbuf(buffer, nbytes); + if(sbuf.find("Polyhedron_demo_") != std::string::npos) + { + std::istringstream iss(sbuf); + std::string file; + while(iss >> file) + { + if(file.find("Polyhedron_demo_") != std::string::npos) + { + QString name(file.c_str()); + files.push_back(name.remove("Polyhedron_demo_")); + } + } + } + + nbytes = ssh_channel_read(channel, buffer, sizeof(buffer), 0); + } + if (nbytes < 0) + { + ssh_channel_close(channel); + ssh_channel_free(channel); + return false; + } + ssh_channel_send_eof(channel); + ssh_channel_close(channel); + ssh_channel_free(channel); + return true; +} + +}// end of ssh_internal +}// end of CGAL #endif diff --git a/Polyhedron/demo/Polyhedron/include/CGAL/Use_ssh.h b/Polyhedron/demo/Polyhedron/include/CGAL/Use_ssh.h index 7d3ea0bdcc9..5d24a129302 100644 --- a/Polyhedron/demo/Polyhedron/include/CGAL/Use_ssh.h +++ b/Polyhedron/demo/Polyhedron/include/CGAL/Use_ssh.h @@ -1,6 +1,10 @@ #ifndef USE_SSH_H #define USE_SSH_H #include +#include + +class QStringList; + namespace CGAL{ namespace ssh_internal{ //should be used inside a try/catch(ssh::SshException e) @@ -27,5 +31,8 @@ bool pull_file(ssh_session &session, const char *from_path, const char *to_path); +bool explore_the_galaxy(ssh_session &session, + QStringList &files); + }} #endif