Skip to content

Commit

Permalink
Merge pull request cryos#29 from cryos/obabel-plugin
Browse files Browse the repository at this point in the history
Obabel plugin
  • Loading branch information
cryos committed Sep 2, 2015
2 parents 808df5b + 38a9fbb commit a3a0090
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
41 changes: 34 additions & 7 deletions avogadro/qtplugins/openbabel/obprocess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,28 @@ OBProcess::OBProcess(QObject *parent_) :
env.insert("BABEL_DATADIR",
QCoreApplication::applicationDirPath() + "/data");
#else
// FIXME: Hardwiring a versioned subdirectory for now.
env.insert("BABEL_DATADIR",
QCoreApplication::applicationDirPath()
+ "/../share/openbabel/2.3.2");
env.insert("BABEL_LIBDIR",
QCoreApplication::applicationDirPath()
+ "/../lib/openbabel/2.3.2");
QDir dir(QCoreApplication::applicationDirPath() + "/../share/openbabel");
QStringList filters;
filters << "2.*";
QStringList dirs = dir.entryList(filters);
if (dirs.size() == 1) {
env.insert("BABEL_DATADIR",
QCoreApplication::applicationDirPath()
+ "/../share/openbabel/" + dirs[0]);
}
else {
qDebug() << "Error, Open Babel data directory not found.";
}
dir.setPath(QCoreApplication::applicationDirPath() + "/../lib/openbabel");
dirs = dir.entryList(filters);
if (dirs.size() == 1) {
env.insert("BABEL_LIBDIR",
QCoreApplication::applicationDirPath()
+ "/../lib/openbabel/" + dirs[0]);
}
else {
qDebug() << "Error, Open Babel plugins directory not found.";
}
#endif
m_process->setProcessEnvironment(env);
}
Expand Down Expand Up @@ -91,6 +106,16 @@ void OBProcess::abort()
emit aborted();
}

void OBProcess::obError()
{
qDebug() << "Process encountered an error, and did not execute correctly.";
if (m_process) {
qDebug() << "\tExit code:" << m_process->exitCode();
qDebug() << "\tExit status:" << m_process->exitStatus();
qDebug() << "\tExit output:" << m_process->readAll();
}
}

bool OBProcess::queryReadFormats()
{
if (!tryLockProcess()) {
Expand Down Expand Up @@ -345,6 +370,8 @@ void OBProcess::executeObabel(const QStringList &options,
if (receiver) {
connect(m_process, SIGNAL(finished(int)), receiver, slot);
connect(m_process, SIGNAL(error(QProcess::ProcessError)), receiver, slot);
connect(m_process, SIGNAL(error(QProcess::ProcessError)),
this, SLOT(obError()));
}

// Start process
Expand Down
5 changes: 5 additions & 0 deletions avogadro/qtplugins/openbabel/obprocess.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ public slots:
*/
void abort();

/**
* Called when an error in the process occurs.
*/
void obError();

signals:
/**
* Emitted when the abort() method has been called.
Expand Down

0 comments on commit a3a0090

Please sign in to comment.