diff --git a/avogadro/qtplugins/importpqr/importpqr.cpp b/avogadro/qtplugins/importpqr/importpqr.cpp index d9d7b2af5e..8038ca713a 100644 --- a/avogadro/qtplugins/importpqr/importpqr.cpp +++ b/avogadro/qtplugins/importpqr/importpqr.cpp @@ -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 ImportPQR::actions() const @@ -77,4 +93,4 @@ void ImportPQR::setMoleculeData(QByteArray& molData, QString name) m_dialog->hide(); emit moleculeReady(1); } -} // namespace Avogadro +} // namespace Avogadro::QtPlugins diff --git a/avogadro/qtplugins/importpqr/importpqr.h b/avogadro/qtplugins/importpqr/importpqr.h index 06a8fcc07c..ac52577e31 100644 --- a/avogadro/qtplugins/importpqr/importpqr.h +++ b/avogadro/qtplugins/importpqr/importpqr.h @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -50,6 +51,7 @@ public slots: private slots: void menuActivated(); + void checkAccess(QNetworkReply* reply); private: QAction* m_action; @@ -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