Skip to content
This repository has been archived by the owner on Sep 1, 2021. It is now read-only.

Commit

Permalink
Fix crash reported when crystal files not present.
Browse files Browse the repository at this point in the history
Simply disables the entire interface.
Uses qWarning() to spit out a warning to console.
Fixes bug report PR#3530795.

Change-Id: Ifbbf1b6a3c1b99fdfedb9158862d889eebd856af
  • Loading branch information
ghutchis committed Jun 13, 2012
1 parent 732b377 commit 0efeaed
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions libavogadro/src/extensions/insertfragmentdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,25 @@ namespace Avogadro {
// Mac and Windows use relative path from application location
m_directory = QCoreApplication::applicationDirPath() + "/../share/avogadro/";
#endif
m_directory += directory; // fragments or crystals
m_directory += directory; // fragments or crystals or whatever
if ( directory.contains(QLatin1String("crystals")) )
d->crystalFiles = true;
else
d->crystalFiles = false;

QDir dir(m_directory);
if (!dir.exists() || !dir.isReadable() ) {
qWarning() << "Cannot find the directory: " << m_directory;

// Can't really do anything!
ui.directoryTreeView->setEnabled(false);
ui.insertFragmentButton->setEnabled(false);
ui.filterLineEdit->setEnabled(false);
ui.clearToolButton->setEnabled(false);

return;
}

d->model = new QFileSystemModel(this);
d->model->setReadOnly(true);
QModelIndex rootIndex = d->model->setRootPath(m_directory);
Expand Down Expand Up @@ -141,8 +154,6 @@ namespace Avogadro {

const Molecule &InsertFragmentDialog::fragment()
{
OBMol obfragment;

// The selected model index is in the proxy
QModelIndexList selected = ui.directoryTreeView->selectionModel()->selectedIndexes();

Expand All @@ -166,6 +177,7 @@ namespace Avogadro {
if (fileInfo.isDir())
return d->fragment; // return an empty fragment and do nothing

OBMol obfragment;
Molecule *mol;
if (d->crystalFiles) {
// No bonding, at first
Expand Down

0 comments on commit 0efeaed

Please sign in to comment.