Slicer  5.0
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
qSlicerExtensionsManagerModel.h
Go to the documentation of this file.
1 /*==============================================================================
2 
3  Program: 3D Slicer
4 
5  Copyright (c) Kitware Inc.
6 
7  See COPYRIGHT.txt
8  or http://www.slicer.org/copyright/copyright.txt for details.
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 
16  This file was originally developed by Jean-Christophe Fillion-Robin, Kitware Inc.
17  and was partially funded by NIH grant 3P41RR013218-12S1
18 
19 ==============================================================================*/
20 
21 #ifndef __qSlicerExtensionsManagerModel_h
22 #define __qSlicerExtensionsManagerModel_h
23 
24 // Qt includes
25 #include <QHash>
26 #include <QStringList>
27 #include <QUrl>
28 #include <QSettings>
29 #include <QUuid>
30 #include <QVariantMap>
31 
32 // CTK includes
33 #include <ctkErrorLogModel.h>
34 
35 // QtGUI includes
36 #include "qSlicerBaseQTCoreExport.h"
38 
39 class QNetworkReply;
40 class qSlicerExtensionsManagerModelPrivate;
41 class QStandardItemModel;
42 
47 class Q_SLICER_BASE_QTCORE_EXPORT qSlicerExtensionsManagerModel : public QObject
48 {
49  Q_OBJECT
50  Q_PROPERTY(int numberOfInstalledExtensions READ numberOfInstalledExtensions NOTIFY modelUpdated)
51  Q_PROPERTY(int installedExtensionsCount READ installedExtensionsCount NOTIFY modelUpdated)
53  Q_PROPERTY(int managedExtensionsCount READ managedExtensionsCount NOTIFY modelUpdated)
55  Q_PROPERTY(QStringList managedExtensions READ managedExtensions NOTIFY modelUpdated)
57  Q_PROPERTY(QStringList bookmarkedExtensions READ bookmarkedExtensions NOTIFY modelUpdated)
58  Q_PROPERTY(QStringList installedExtensions READ installedExtensions NOTIFY modelUpdated)
59  Q_PROPERTY(QStringList enabledExtensions READ enabledExtensions NOTIFY modelUpdated)
61  Q_PROPERTY(QStringList availableUpdateExtensions READ availableUpdateExtensions NOTIFY modelUpdated)
62  Q_PROPERTY(bool newExtensionEnabledByDefault READ newExtensionEnabledByDefault WRITE setNewExtensionEnabledByDefault NOTIFY newExtensionEnabledByDefaultChanged)
63  Q_PROPERTY(bool interactive READ interactive WRITE setInteractive NOTIFY interactiveChanged)
64  Q_PROPERTY(QString extensionsSettingsFilePath READ extensionsSettingsFilePath WRITE setExtensionsSettingsFilePath NOTIFY extensionsSettingsFilePathChanged)
65  Q_PROPERTY(QString slicerRevision READ slicerRevision WRITE setSlicerRevision NOTIFY slicerRevisionChanged)
66  Q_PROPERTY(QString slicerOs READ slicerOs WRITE setSlicerOs NOTIFY slicerOsChanged)
67  Q_PROPERTY(QString slicerArch READ slicerArch WRITE setSlicerArch NOTIFY slicerArchChanged)
69  Q_PROPERTY(bool autoUpdateCheck READ autoUpdateCheck WRITE setAutoUpdateCheck NOTIFY autoUpdateSettingsChanged)
71  Q_PROPERTY(bool autoUpdateInstall READ autoUpdateInstall WRITE setAutoUpdateInstall NOTIFY autoUpdateSettingsChanged)
73  Q_PROPERTY(bool autoInstallDependencies READ autoInstallDependencies WRITE setAutoInstallDependencies NOTIFY autoUpdateSettingsChanged)
74 
75 public:
77  typedef QObject Superclass;
78 
80  typedef qSlicerExtensionsManagerModelPrivate Pimpl;
81 
84 
86  explicit qSlicerExtensionsManagerModel(QObject* parent = nullptr);
87 
90 
93 
94  enum ServerAPI
95  {
96  Girder_v1 = 1,
97  ServerAPI_Last
98  };
99 
103  int serverAPI() const;
104 
108  static QString serverAPIToString(int serverAPI);
109 
113  static int serverAPIFromString(const QString& str);
114 
121  Q_INVOKABLE QUrl serverUrl()const;
122 
129  Q_INVOKABLE QUrl frontendServerUrl()const;
130 
132  Q_INVOKABLE QUrl extensionsListUrl()const;
133 
134  Q_INVOKABLE QString extensionsInstallPath()const;
135 
136  Q_INVOKABLE QString extensionInstallPath(const QString& extensionName) const;
137 
138  Q_INVOKABLE QStringList extensionModulePaths(const QString& extensionName)const;
139 
140  Q_INVOKABLE QString extensionDescriptionFile(const QString& extensionName) const;
141 
142  void setNewExtensionEnabledByDefault(bool value);
143  bool newExtensionEnabledByDefault()const;
144 
145  bool autoUpdateCheck()const;
146  bool autoUpdateInstall()const;
147  bool autoInstallDependencies()const;
148 
151  bool interactive()const;
152 
154  {
155  MetadataAll = 0,
157  MetadataServer
158  };
159  Q_INVOKABLE ExtensionMetadataType extensionMetadata(const QString& extensionName, int source = MetadataAll)const;
160 
161  Q_INVOKABLE QString extensionDescription(const QString& extensionName)const;
162 
165  int managedExtensionsCount()const;
166 
168  QStringList managedExtensions()const;
169 
171  bool isExtensionLoaded(const QString& extensionName) const;
172 
175  Q_INVOKABLE bool isExtensionInstalled(const QString& extensionName)const;
176 
179  int installedExtensionsCount()const;
180 
183  int numberOfInstalledExtensions()const;
184 
187  QStringList installedExtensions()const;
188 
192  Q_INVOKABLE bool isExtensionBookmarked(const QString& extensionName)const;
193 
196  Q_INVOKABLE bool isExtensionEnabled(const QString& extensionName)const;
197 
202  QStringList scheduledForUpdateExtensions() const;
203 
210  Q_INVOKABLE bool isExtensionUpdateAvailable(const QString& extensionName)const;
211 
214  QStringList availableUpdateExtensions()const;
215 
221  Q_INVOKABLE bool isExtensionScheduledForUpdate(const QString& extensionName)const;
222 
225  QStringList scheduledForUninstallExtensions() const;
226 
229  Q_INVOKABLE bool isExtensionScheduledForUninstall(const QString& extensionName)const;
230 
233  QStringList bookmarkedExtensions()const;
234 
237  QStringList enabledExtensions()const;
238 
242  QString extensionsSettingsFilePath()const;
243  void setExtensionsSettingsFilePath(const QString& extensionsSettingsFilePath);
244 
248  QString slicerRevision()const;
249  void setSlicerRevision(const QString& revision);
250 
254  QString slicerOs()const;
255  void setSlicerOs(const QString& os);
256 
260  QString slicerArch()const;
261  void setSlicerArch(const QString& arch);
262 
270  void setSlicerRequirements(const QString& revision, const QString& os, const QString& arch);
271 
272  QString slicerVersion()const;
273  void setSlicerVersion(const QString& version);
274 
279  Q_INVOKABLE QStringList isExtensionCompatible(const QString& extensionName, const QString& slicerRevision,
280  const QString& slicerOs, const QString& slicerArch) const;
281 
288  Q_INVOKABLE QStringList isExtensionCompatible(const QString& extensionName) const;
289 
297  Q_INVOKABLE bool installExtension(const QString &archiveFile, bool installDependencies = true);
298 
306  Q_INVOKABLE bool installExtension(const QString& extensionName,
307  ExtensionMetadataType extensionMetadata,
308  const QString &archiveFile, bool installDependencies = true);
309 
315  bool uninstallExtension(const QString& extensionName);
316 
318  Q_INVOKABLE bool extractExtensionArchive(const QString& extensionName,
319  const QString& archiveFile,
320  const QString &destinationPath);
321 
323  Q_INVOKABLE const QStandardItemModel * model()const;
324 
327  QDateTime lastUpdateTimeExtensionsMetadataFromServer();
328 
330  QStringList activeTasks() const;
331 
334  static QHash<QString, QString> serverToExtensionDescriptionKey(int serverAPI);
335 
338  static ExtensionMetadataType convertExtensionMetadata(const ExtensionMetadataType &extensionMetadata, int serverAPI);
339 
342  static QStringList serverKeysToIgnore(int serverAPI);
343 
346  static ExtensionMetadataType filterExtensionMetadata(const ExtensionMetadataType &extensionMetadata, int serverAPI);
347 
348  static QStringList readArrayValues(QSettings& settings,
349  const QString& arrayName, const QString fieldName);
350 
351  static void writeArrayValues(QSettings& settings, const QStringList& values,
352  const QString& arrayName, const QString fieldName);
353 
354  static bool writeExtensionDescriptionFile(const QString& file,
355  const ExtensionMetadataType& metadata);
356 
357  static ExtensionMetadataType parseExtensionDescriptionFile(const QString& file);
358 
359 public slots:
360 
363  void setExtensionBookmarked(const QString& extensionName, bool value);
364 
368  void setExtensionEnabled(const QString& extensionName, bool value);
369 
373  bool downloadAndInstallExtension(const QString& extensionId, bool installDependencies=true);
374 
379  bool downloadAndInstallExtensionByName(const QString& extensionId, bool installDependencies=true);
380 
386  bool scheduleExtensionForUninstall(const QString& extensionName);
387 
391  bool cancelExtensionScheduledForUninstall(const QString& extensionName);
392 
400  bool updateExtensionsMetadataFromServer(bool force=false, bool waitForCompletion=false);
401 
405  void checkForExtensionsUpdates();
406 
413  bool scheduleExtensionForUpdate(const QString& extensionName);
414 
418  bool cancelExtensionScheduledForUpdate(const QString& extensionName);
419 
428  bool updateScheduledExtensions(QStringList &updatedExtensions);
429 
435  bool updateScheduledExtensions();
436 
445  bool uninstallScheduledExtensions(QStringList &uninstalledExtensions);
446 
452  bool uninstallScheduledExtensions();
453 
454  void identifyIncompatibleExtensions();
455 
456  bool exportExtensionList(QString& exportFilePath);
457 
458  QStringList checkInstallPrerequisites() const;
459 
464  void aboutToLoadExtensions();
465 
467  void updateModel();
468 
469  void setAutoUpdateCheck(bool enable);
470  void setAutoUpdateInstall(bool enable);
471  void setAutoInstallDependencies(bool enable);
472  void setInteractive(bool value);
473 
474 signals:
475 
476  void downloadStarted(QNetworkReply * reply);
477 
478  void downloadFinished(QNetworkReply * reply);
479 
480  void updateDownloadProgress(const QString& extensionName,
481  qint64 received, qint64 total);
482 
483  void modelUpdated();
484 
486  void updateExtensionsMetadataFromServerCompleted(bool success);
487 
488  void extensionUpdateAvailable(const QString& extensionName);
489 
491  void extensionUpdatesAvailable(bool available);
492 
493  void extensionInstalled(const QString& extensionName);
494 
495  void extensionUpdated(const QString& extensionName);
496 
498  void extensionMetadataUpdated(const QString& extensionName);
499 
500  void extensionScheduledForUninstall(const QString& extensionName);
501 
502  void extensionCancelledScheduleForUninstall(const QString& extensionName);
503 
504  void extensionScheduledForUpdate(const QString& extensionName);
505 
506  void extensionCancelledScheduleForUpdate(const QString& extensionName);
507 
508  void extensionUninstalled(const QString& extensionName);
509 
511  void extensionBookmarkedChanged(const QString& extensionName, bool value);
512 
513  void extensionEnabledChanged(const QString& extensionName, bool value);
514 
515  void extensionIdentifedAsIncompatible(const QString& extensionName);
516 
517  void newExtensionEnabledByDefaultChanged(bool value);
518 
519  void slicerRequirementsChanged(const QString& revision, const QString& os, const QString& arch);
520  void slicerArchChanged(const QString& slicerArch);
521  void slicerOsChanged(const QString& slicerOs);
522  void slicerRevisionChanged(const QString& slicerRevision);
523 
524  void interactiveChanged(bool interactive);
525 
526  void slicerVersionChanged(const QString& slicerVersion);
527 
528  void messageLogged(const QString& text, ctkErrorLogLevel::LogLevels level) const;
529 
530  void installDownloadProgress(const QString& extensionName, qint64 received, qint64 total);
531 
532  void extensionsSettingsFilePathChanged(const QString& extensionsSettingsFilePath);
533 
535  void autoUpdateSettingsChanged();
536 
537 protected slots:
538 
539  void onInstallDownloadProgress(qSlicerExtensionDownloadTask* task, qint64 received, qint64 total);
540 
542  void onInstallDownloadFinished(qSlicerExtensionDownloadTask* task);
543 
545  void onUpdateDownloadFinished(qSlicerExtensionDownloadTask* task);
546 
547  void onUpdateDownloadProgress(qSlicerExtensionDownloadTask* task,
548  qint64 received, qint64 total);
549 
550  bool onExtensionsMetadataFromServerQueryFinished(const QUuid& requestId);
551 
552 protected:
553  QScopedPointer<qSlicerExtensionsManagerModelPrivate> d_ptr;
554 
555 private:
556  Q_DECLARE_PRIVATE(qSlicerExtensionsManagerModel);
557  Q_DISABLE_COPY(qSlicerExtensionsManagerModel);
558 };
559 
561 
562 // Metatype already declared in qSlicerIO.h
563 //Q_DECLARE_METATYPE(qSlicerExtensionsManagerModel::ExtensionMetadataType)
564 
565 #endif
Q_DECLARE_METATYPE(qSlicerExtensionsManagerModel::ServerAPI)
QScopedPointer< qSlicerExtensionsManagerModelPrivate > d_ptr
QObject Superclass
Superclass typedef.
string version
Definition: conf.py:73
Class querying and storing extensions data.
qSlicerExtensionsManagerModelPrivate Pimpl
Pimpl typedef.
return local metadata (stored in s4ext files in the extensions folder)