| 1 |
/****************************************************************************** |
| 2 |
This source file is part of the Avogadro project. |
| 3 |
This source code is released under the 3-Clause BSD License, (see "LICENSE"). |
| 4 |
******************************************************************************/ |
| 5 |
|
| 6 |
#ifndef AVOGADRO_QTPLUGINS_COMMAND_H |
| 7 |
#define AVOGADRO_QTPLUGINS_COMMAND_H |
| 8 |
|
| 9 |
#include <avogadro/qtgui/extensionplugin.h> |
| 10 |
|
| 11 |
#include <QtCore/QMap> |
| 12 |
#include <QtCore/QMultiHash> |
| 13 |
#include <QtCore/QVariantMap> |
| 14 |
|
| 15 |
class QAction; |
| 16 |
class QDialog; |
| 17 |
class QProgressDialog; |
| 18 |
|
| 19 |
namespace Avogadro { |
| 20 |
namespace Io { |
| 21 |
class FileFormat; |
| 22 |
} |
| 23 |
|
| 24 |
namespace QtGui { |
| 25 |
class InterfaceScript; |
| 26 |
class InterfaceWidget; |
| 27 |
} // namespace QtGui |
| 28 |
|
| 29 |
namespace QtPlugins { |
| 30 |
|
| 31 |
/** |
| 32 |
* @brief The Command class implements the extension interface for |
| 33 |
* external (script) Commands |
| 34 |
* @author Geoffrey R. Hutchison |
| 35 |
*/ |
| 36 |
class Command : public QtGui::ExtensionPlugin |
| 37 |
{ |
| 38 |
Q_OBJECT |
| 39 |
|
| 40 |
public: |
| 41 |
explicit Command(QObject* parent = nullptr); |
| 42 |
~Command() override; |
| 43 |
|
| 44 |
QString name() const override { return tr("Command scripts"); } |
| 45 |
|
| 46 |
QString description() const override |
| 47 |
{ |
| 48 |
return tr("Run external script commands"); |
| 49 |
} |
| 50 |
|
| 51 |
QList<QAction*> actions() const override; |
| 52 |
|
| 53 |
QStringList menuPath(QAction*) const override; |
| 54 |
|
| 55 |
void setMolecule(QtGui::Molecule* mol) override; |
| 56 |
|
| 57 |
public slots: |
| 58 |
/** |
| 59 |
* Scan for new scripts in the command directories. |
| 60 |
*/ |
| 61 |
void refreshScripts(); |
| 62 |
|
| 63 |
void run(); |
| 64 |
|
| 65 |
bool readMolecule(QtGui::Molecule& mol) override; |
| 66 |
|
| 67 |
void processFinished(); |
| 68 |
|
| 69 |
/** |
| 70 |
* Handle a feature registered by PackageManager. |
| 71 |
*/ |
| 72 |
void registerFeature(const QString& type, const QString& packageDir, |
| 73 |
const QString& command, const QString& identifier, |
| 74 |
const QVariantMap& metadata); |
| 75 |
|
| 76 |
/** |
| 77 |
* Handle a feature removed by PackageManager. |
| 78 |
*/ |
| 79 |
void unregisterFeature(const QString& type, const QString& packageDir, |
| 80 |
const QString& command, const QString& identifier); |
| 81 |
|
| 82 |
private slots: |
| 83 |
void menuActivated(); |
| 84 |
void configurePython(); |
| 85 |
|
| 86 |
private: |
| 87 |
QList<QAction*> m_actions; |
| 88 |
QtGui::Molecule* m_molecule; |
| 89 |
// keyed on script file path or package feature key |
| 90 |
QMap<QString, QtGui::InterfaceWidget*> m_dialogs; |
| 91 |
QDialog* m_currentDialog; |
| 92 |
QtGui::InterfaceWidget* m_currentInterface; |
| 93 |
QtGui::InterfaceScript* m_currentScript; |
| 94 |
QProgressDialog* m_progress; |
| 95 |
|
| 96 |
QMultiHash<QString, QAction*> m_packageActions; |
| 97 |
|
| 98 |
const Io::FileFormat* m_outputFormat; |
| 99 |
QString m_outputFileName; |
| 100 |
}; |
| 101 |
} // namespace QtPlugins |
| 102 |
} // namespace Avogadro |
| 103 |
|
| 104 |
#endif // AVOGADRO_QTPLUGINS_COMMAND_H |