|
27 | 27 | #include <avogadro/qtgui/molecule.h> |
28 | 28 | #include <avogadro/qtgui/moleculemodel.h> |
29 | 29 | #include <avogadro/qtgui/multiviewwidget.h> |
| 30 | +#include <avogadro/qtgui/packagemanager.h> |
30 | 31 | #include <avogadro/qtgui/periodictableview.h> |
31 | 32 | #include <avogadro/qtgui/richtextdelegate.h> |
32 | 33 | #include <avogadro/qtgui/rwmolecule.h> |
33 | 34 | #include <avogadro/qtgui/sceneplugin.h> |
34 | 35 | #include <avogadro/qtgui/scenepluginmodel.h> |
35 | 36 | #include <avogadro/qtgui/toolplugin.h> |
| 37 | +#include <avogadro/qtgui/utilities.h> |
36 | 38 | #include <avogadro/qtopengl/activeobjects.h> |
37 | 39 | #include <avogadro/qtopengl/glwidget.h> |
38 | 40 | #include <avogadro/qtplugins/pluginmanager.h> |
@@ -316,12 +318,18 @@ MainWindow::MainWindow(const QStringList& fileNames, bool disableSettings) |
316 | 318 | connect(extension, &QtGui::ExtensionPlugin::registerCommand, this, |
317 | 319 | &MainWindow::registerExtensionCommand); |
318 | 320 | extension->registerCommands(); |
319 | | - |
320 | | - buildMenu(extension); |
321 | 321 | m_extensions.append(extension); |
322 | 322 | } |
323 | 323 | } |
324 | 324 |
|
| 325 | + // Scan for pyproject.toml-based plugin packages. |
| 326 | + loadPackages(); |
| 327 | + |
| 328 | + // now we can build the menus for extensions |
| 329 | + foreach (ExtensionPlugin* extension, m_extensions) { |
| 330 | + buildMenu(extension); |
| 331 | + } |
| 332 | + |
325 | 333 | // Now set up the interface. |
326 | 334 | #ifdef Q_OS_WIN |
327 | 335 | qDebug() << " setting interface "; |
@@ -1268,6 +1276,73 @@ void MainWindow::cleanupCurrentAutosave() |
1268 | 1276 | } |
1269 | 1277 | } |
1270 | 1278 |
|
| 1279 | +void MainWindow::loadPackages() |
| 1280 | +{ |
| 1281 | + QStringList dirs; |
| 1282 | + |
| 1283 | + // Add the standard install locations |
| 1284 | + QStringList stdPaths = |
| 1285 | + QStandardPaths::standardLocations(QStandardPaths::AppLocalDataLocation); |
| 1286 | + foreach (const QString& dirStr, stdPaths) { |
| 1287 | + QString path = dirStr + "/packages"; |
| 1288 | + dirs << path; |
| 1289 | + } |
| 1290 | + |
| 1291 | + // Add the install-relative library path |
| 1292 | + dirs << QCoreApplication::applicationDirPath() + "/../" + |
| 1293 | + QtGui::Utilities::libraryDirectory() + "/avogadro2/packages"; |
| 1294 | + |
| 1295 | + // Check the directories for new packages |
| 1296 | + QtGui::PackageManager* pkgManager = QtGui::PackageManager::instance(); |
| 1297 | + QStringList newPackages; |
| 1298 | + foreach (const QString& dir, dirs) { |
| 1299 | +#ifndef NDEBUG |
| 1300 | + qDebug() << "Checking for packages in" << dir; |
| 1301 | +#endif |
| 1302 | + newPackages.append(pkgManager->scanDirectory(dir)); |
| 1303 | + } |
| 1304 | + |
| 1305 | + // If there are new or updated packages, ask the user before installing |
| 1306 | + if (!newPackages.isEmpty()) { |
| 1307 | + QStringList packageNames; |
| 1308 | + foreach (const QString& dir, newPackages) { |
| 1309 | + packageNames << QFileInfo(dir).baseName(); |
| 1310 | + } |
| 1311 | + |
| 1312 | + // TODO: list the packages and count, maybe the versions |
| 1313 | + auto reply = |
| 1314 | + QMessageBox::question(this, tr("Install New Packages"), |
| 1315 | + tr("New or updated packages were found.\n" |
| 1316 | + "Would you like to install them now?"), |
| 1317 | + QMessageBox::Yes | QMessageBox::No); |
| 1318 | + if (reply != QMessageBox::Yes) { |
| 1319 | + // Still need to replay cached registrations for already-installed |
| 1320 | + // packages |
| 1321 | + pkgManager->loadRegisteredPackages(); |
| 1322 | + return; |
| 1323 | + } |
| 1324 | + |
| 1325 | + // TODO: show a dialog listing the new packages and let the user |
| 1326 | + // choose which to install |
| 1327 | + connect(pkgManager, &QtGui::PackageManager::packagesInstalled, this, |
| 1328 | + [this, pkgManager]() { |
| 1329 | + disconnect(pkgManager, &QtGui::PackageManager::packagesInstalled, |
| 1330 | + this, nullptr); |
| 1331 | + foreach (ExtensionPlugin* ext, m_extensions) |
| 1332 | + buildMenu(ext); |
| 1333 | + m_menuBuilder->buildMenuBar(menuBar()); |
| 1334 | + }); |
| 1335 | + pkgManager->installPackages(newPackages); |
| 1336 | + return; // Registration and loadRegisteredPackages run in PackageManager |
| 1337 | + } |
| 1338 | + |
| 1339 | + // Load cached registrations so consumer plugins get their signals |
| 1340 | +#ifndef DEBUG |
| 1341 | + qDebug() << "Load cached packages"; |
| 1342 | +#endif |
| 1343 | + pkgManager->loadRegisteredPackages(); |
| 1344 | +} |
| 1345 | + |
1271 | 1346 | void MainWindow::checkAutosaveRecovery() |
1272 | 1347 | { |
1273 | 1348 | QString autosaveDirPath = |
|
0 commit comments