Skip to content

Commit

Permalink
Only enable PQR search if site is up
Browse files Browse the repository at this point in the history
Fix OpenChemistry#1687

Signed-off-by: Geoff Hutchison <[email protected]>
  • Loading branch information
ghutchis committed Dec 27, 2024
1 parent 0ccd1d4 commit 4c71ea6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
22 changes: 19 additions & 3 deletions avogadro/qtplugins/importpqr/importpqr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,32 @@ namespace Avogadro::QtPlugins {

ImportPQR::ImportPQR(QObject* parent_)
: ExtensionPlugin(parent_), m_action(new QAction(this)), m_molecule(nullptr),
m_dialog(nullptr), m_outputFormat(nullptr)
m_dialog(nullptr), m_outputFormat(nullptr),
m_manager(new QNetworkAccessManager(this))
{
m_action->setEnabled(true);
m_action->setEnabled(false);
m_action->setText(tr("&Search PQR…"));
connect(m_action, SIGNAL(triggered()), SLOT(menuActivated()));

// check if PQR is up
connect(m_manager, SIGNAL(finished(QNetworkReply*)),
SLOT(checkAccess(QNetworkReply*)));
m_manager->get(QNetworkRequest(QUrl("https://pqr.pitt.edu")));
}

ImportPQR::~ImportPQR()
{
delete m_outputFormat;
m_manager->deleteLater();
}

void ImportPQR::checkAccess(QNetworkReply* reply)
{
// only enable if we can access the site
if (reply->error() == QNetworkReply::NoError) {
m_action->setEnabled(true);
}
reply->deleteLater();
}

QList<QAction*> ImportPQR::actions() const
Expand Down Expand Up @@ -77,4 +93,4 @@ void ImportPQR::setMoleculeData(QByteArray& molData, QString name)
m_dialog->hide();
emit moleculeReady(1);
}
} // namespace Avogadro
} // namespace Avogadro::QtPlugins
7 changes: 5 additions & 2 deletions avogadro/qtplugins/importpqr/importpqr.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <avogadro/io/fileformatmanager.h>
#include <avogadro/qtgui/extensionplugin.h>

#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkReply>

#include <QtCore/QString>
Expand Down Expand Up @@ -50,6 +51,7 @@ public slots:

private slots:
void menuActivated();
void checkAccess(QNetworkReply* reply);

private:
QAction* m_action;
Expand All @@ -59,8 +61,9 @@ private slots:
QString m_moleculeName;
QString m_moleculePath;
QByteArray m_moleculeData;
QNetworkAccessManager* m_manager;
};
}
}
} // namespace QtPlugins
} // namespace Avogadro

#endif // AVOGADRO_QTPLUGINS_IMPORTPQR_H

1 comment on commit 4c71ea6

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ERROR: clang-format-diff detected formatting issues. See the artifact for a patch or run clang-format on your branch.

Please sign in to comment.