mirror of https://github.com/CGAL/cgal
Display the scene files available when loading a scene from ssh.
This commit is contained in:
parent
ed6c1cb95e
commit
f8c1bc5aa7
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -20,8 +20,10 @@
|
|||
#include <vector>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
#include <sstream>
|
||||
|
||||
#include <QMessageBox>
|
||||
#include <QStringList>
|
||||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
#ifndef USE_SSH_H
|
||||
#define USE_SSH_H
|
||||
#include <libssh/libsshpp.hpp>
|
||||
#include <vector>
|
||||
|
||||
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
|
||||
|
|
|
|||
Loading…
Reference in New Issue