| 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_PACKAGEMANAGERDIALOG_H |
| 7 |
#define AVOGADRO_QTPLUGINS_PACKAGEMANAGERDIALOG_H |
| 8 |
|
| 9 |
#include <QtCore/QList> |
| 10 |
#include <QtCore/QModelIndex> |
| 11 |
#include <QtCore/QString> |
| 12 |
#include <QtWidgets/QDialog> |
| 13 |
|
| 14 |
class QNetworkAccessManager; |
| 15 |
class QNetworkReply; |
| 16 |
class QSortFilterProxyModel; |
| 17 |
|
| 18 |
namespace Ui { |
| 19 |
class PackageManagerDialog; |
| 20 |
} |
| 21 |
|
| 22 |
namespace Avogadro { |
| 23 |
namespace QtPlugins { |
| 24 |
|
| 25 |
class PackageModel; |
| 26 |
|
| 27 |
/** |
| 28 |
* @brief Dialog for browsing, installing, updating, and removing Avogadro |
| 29 |
* packages. Replaces the old DownloaderWidget. |
| 30 |
* |
| 31 |
* Combines the online catalog from avogadro.cc/plugins.json with locally |
| 32 |
* installed packages tracked by PackageManager. |
| 33 |
*/ |
| 34 |
class PackageManagerDialog : public QDialog |
| 35 |
{ |
| 36 |
Q_OBJECT |
| 37 |
|
| 38 |
public: |
| 39 |
explicit PackageManagerDialog(QWidget* parent = nullptr); |
| 40 |
~PackageManagerDialog() override; |
| 41 |
|
| 42 |
private slots: |
| 43 |
void refreshOnlineCatalog(); |
| 44 |
void onCatalogReply(); |
| 45 |
void onReadmeReply(); |
| 46 |
void showCellTooltip(const QModelIndex& index); |
| 47 |
void onCurrentRowChanged(const QModelIndex& current, |
| 48 |
const QModelIndex& previous); |
| 49 |
void installSelected(); |
| 50 |
void removeSelected(); |
| 51 |
void installFromDirectory(); |
| 52 |
void onPackagesInstalled(); |
| 53 |
void handleRedirect(); |
| 54 |
|
| 55 |
private: |
| 56 |
void getRepoData( |
| 57 |
const QString& url = QStringLiteral("https://avogadro.cc/plugins2.json")); |
| 58 |
void downloadNext(); |
| 59 |
void unzipPlugin(QNetworkReply* reply); |
| 60 |
static bool copyDir(const QString& src, const QString& dst); |
| 61 |
|
| 62 |
struct DownloadEntry |
| 63 |
{ |
| 64 |
QString url; |
| 65 |
QString name; |
| 66 |
}; |
| 67 |
|
| 68 |
Ui::PackageManagerDialog* m_ui = nullptr; |
| 69 |
PackageModel* m_model = nullptr; |
| 70 |
QSortFilterProxyModel* m_proxyModel = nullptr; |
| 71 |
QNetworkAccessManager* m_network = nullptr; |
| 72 |
QString m_filePath; |
| 73 |
QList<DownloadEntry> m_downloadQueue; |
| 74 |
}; |
| 75 |
|
| 76 |
} // namespace QtPlugins |
| 77 |
} // namespace Avogadro |
| 78 |
|
| 79 |
#endif // AVOGADRO_QTPLUGINS_PACKAGEMANAGERDIALOG_H |