Slicer  5.3
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  Q_PROPERTY(QStringList activeTasks READ activeTasks NOTIFY activeTasksChanged DESIGNABLE false)
75 
76 public:
78  typedef QObject Superclass;
79 
81  typedef qSlicerExtensionsManagerModelPrivate Pimpl;
82 
85 
87  explicit qSlicerExtensionsManagerModel(QObject* parent = nullptr);
88 
91 
94 
95  enum ServerAPI
96  {
97  Girder_v1 = 1,
98  ServerAPI_Last
99  };
100 
104  int serverAPI() const;
105 
109  static QString serverAPIToString(int serverAPI);
110 
114  static int serverAPIFromString(const QString& str);
115 
122  Q_INVOKABLE QUrl serverUrl()const;
123 
130  Q_INVOKABLE QUrl frontendServerUrl()const;
131 
133  Q_INVOKABLE QUrl extensionsListUrl()const;
134 
135  Q_INVOKABLE QString extensionsInstallPath()const;
136 
137  Q_INVOKABLE QString extensionInstallPath(const QString& extensionName) const;
138 
139  Q_INVOKABLE QStringList extensionModulePaths(const QString& extensionName)const;
140 
141  Q_INVOKABLE QString extensionDescriptionFile(const QString& extensionName) const;
142 
143  void setNewExtensionEnabledByDefault(bool value);
144  bool newExtensionEnabledByDefault()const;
145 
146  bool autoUpdateCheck()const;
147  bool autoUpdateInstall()const;
148  bool autoInstallDependencies()const;
149 
152  bool interactive()const;
153 
155  {
156  MetadataAll = 0,
158  MetadataServer
159  };
160  Q_INVOKABLE ExtensionMetadataType extensionMetadata(const QString& extensionName, int source = MetadataAll)const;
161 
162  Q_INVOKABLE QString extensionDescription(const QString& extensionName)const;
163 
166  int managedExtensionsCount()const;
167 
169  QStringList managedExtensions()const;
170 
172  bool isExtensionLoaded(const QString& extensionName) const;
173 
176  Q_INVOKABLE bool isExtensionInstalled(const QString& extensionName)const;
177 
180  int installedExtensionsCount()const;
181 
184  int numberOfInstalledExtensions()const;
185 
188  QStringList installedExtensions()const;
189 
193  Q_INVOKABLE bool isExtensionBookmarked(const QString& extensionName)const;
194 
197  Q_INVOKABLE bool isExtensionEnabled(const QString& extensionName)const;
198 
203  QStringList scheduledForUpdateExtensions() const;
204 
211  Q_INVOKABLE bool isExtensionUpdateAvailable(const QString& extensionName)const;
212 
215  QStringList availableUpdateExtensions()const;
216 
222  Q_INVOKABLE bool isExtensionScheduledForUpdate(const QString& extensionName)const;
223 
226  QStringList scheduledForUninstallExtensions() const;
227 
230  Q_INVOKABLE bool isExtensionScheduledForUninstall(const QString& extensionName)const;
231 
234  QStringList bookmarkedExtensions()const;
235 
238  QStringList enabledExtensions()const;
239 
243  QString extensionsSettingsFilePath()const;
244  void setExtensionsSettingsFilePath(const QString& extensionsSettingsFilePath);
245 
249  QString slicerRevision()const;
250  void setSlicerRevision(const QString& revision);
251 
255  QString slicerOs()const;
256  void setSlicerOs(const QString& os);
257 
261  QString slicerArch()const;
262  void setSlicerArch(const QString& arch);
263 
271  void setSlicerRequirements(const QString& revision, const QString& os, const QString& arch);
272 
273  QString slicerVersion()const;
274  void setSlicerVersion(const QString& version);
275 
280  Q_INVOKABLE QStringList isExtensionCompatible(const QString& extensionName, const QString& slicerRevision,
281  const QString& slicerOs, const QString& slicerArch) const;
282 
289  Q_INVOKABLE QStringList isExtensionCompatible(const QString& extensionName) const;
290 
298  Q_INVOKABLE bool installExtension(const QString &archiveFile, bool installDependencies = true, bool waitForCompletion = false);
299 
307  Q_INVOKABLE bool installExtension(const QString& extensionName,
308  ExtensionMetadataType extensionMetadata,
309  const QString &archiveFile, bool installDependencies = true,
310  bool waitForCompletion = false);
311 
317  bool uninstallExtension(const QString& extensionName);
318 
320  Q_INVOKABLE bool extractExtensionArchive(const QString& extensionName,
321  const QString& archiveFile,
322  const QString &destinationPath);
323 
325  Q_INVOKABLE const QStandardItemModel * model()const;
326 
329  QDateTime lastUpdateTimeExtensionsMetadataFromServer();
330 
332  QStringList activeTasks() const;
333 
336  static QHash<QString, QString> serverToExtensionDescriptionKey(int serverAPI);
337 
340  static ExtensionMetadataType convertExtensionMetadata(const ExtensionMetadataType &extensionMetadata, int serverAPI);
341 
344  static QStringList serverKeysToIgnore(int serverAPI);
345 
348  static ExtensionMetadataType filterExtensionMetadata(const ExtensionMetadataType &extensionMetadata, int serverAPI);
349 
350  static QStringList readArrayValues(QSettings& settings,
351  const QString& arrayName, const QString fieldName);
352 
353  static void writeArrayValues(QSettings& settings, const QStringList& values,
354  const QString& arrayName, const QString fieldName);
355 
356  static bool writeExtensionDescriptionFile(const QString& file,
357  const ExtensionMetadataType& metadata);
358 
359  static ExtensionMetadataType parseExtensionDescriptionFile(const QString& file);
360 
361 public slots:
362 
365  void setExtensionBookmarked(const QString& extensionName, bool value);
366 
370  void setExtensionEnabled(const QString& extensionName, bool value);
371 
375  bool downloadAndInstallExtension(const QString& extensionId, bool installDependencies = true, bool waitForCompletion = false);
376 
381  bool downloadAndInstallExtensionByName(const QString& extensionName, bool installDependencies = true, bool waitForCompletion = false);
382 
388  bool scheduleExtensionForUninstall(const QString& extensionName);
389 
393  bool cancelExtensionScheduledForUninstall(const QString& extensionName);
394 
402  bool updateExtensionsMetadataFromServer(bool force = false, bool waitForCompletion = false);
403 
407  void checkForExtensionsUpdates();
408 
415  bool scheduleExtensionForUpdate(const QString& extensionName);
416 
420  bool cancelExtensionScheduledForUpdate(const QString& extensionName);
421 
430  bool updateScheduledExtensions(QStringList &updatedExtensions);
431 
437  bool updateScheduledExtensions();
438 
447  bool uninstallScheduledExtensions(QStringList &uninstalledExtensions);
448 
454  bool uninstallScheduledExtensions();
455 
456  void identifyIncompatibleExtensions();
457 
458  bool exportExtensionList(QString& exportFilePath);
459 
460  QStringList checkInstallPrerequisites() const;
461 
466  void aboutToLoadExtensions();
467 
469  void updateModel();
470 
471  void setAutoUpdateCheck(bool enable);
472  void setAutoUpdateInstall(bool enable);
473  void setAutoInstallDependencies(bool enable);
474  void setInteractive(bool value);
475 
479  Q_INVOKABLE bool waitForAllTasksCompletion(int timeoutMsec = -1)const;
480 
481 signals:
482 
483  void downloadStarted(QNetworkReply * reply);
484 
485  void downloadFinished(QNetworkReply * reply);
486 
487  void updateDownloadProgress(const QString& extensionName,
488  qint64 received, qint64 total);
489 
490  void modelUpdated();
491 
493  void updateExtensionsMetadataFromServerCompleted(bool success);
494 
495  void extensionUpdateAvailable(const QString& extensionName);
496 
498  void extensionUpdatesAvailable(bool available);
499 
500  void extensionInstalled(const QString& extensionName);
501 
502  void extensionUpdated(const QString& extensionName);
503 
505  void extensionMetadataUpdated(const QString& extensionName);
506 
507  void extensionScheduledForUninstall(const QString& extensionName);
508 
509  void extensionCancelledScheduleForUninstall(const QString& extensionName);
510 
511  void extensionScheduledForUpdate(const QString& extensionName);
512 
513  void extensionCancelledScheduleForUpdate(const QString& extensionName);
514 
515  void extensionUninstalled(const QString& extensionName);
516 
518  void extensionBookmarkedChanged(const QString& extensionName, bool value);
519 
520  void extensionEnabledChanged(const QString& extensionName, bool value);
521 
522  void extensionIdentifedAsIncompatible(const QString& extensionName);
523 
524  void newExtensionEnabledByDefaultChanged(bool value);
525 
526  void slicerRequirementsChanged(const QString& revision, const QString& os, const QString& arch);
527  void slicerArchChanged(const QString& slicerArch);
528  void slicerOsChanged(const QString& slicerOs);
529  void slicerRevisionChanged(const QString& slicerRevision);
530 
531  void interactiveChanged(bool interactive);
532 
533  void slicerVersionChanged(const QString& slicerVersion);
534 
535  void messageLogged(const QString& text, ctkErrorLogLevel::LogLevels level) const;
536 
537  void installDownloadProgress(const QString& extensionName, qint64 received, qint64 total);
538 
539  void extensionsSettingsFilePathChanged(const QString& extensionsSettingsFilePath);
540 
542  void autoUpdateSettingsChanged();
543 
545  void activeTasksChanged();
546 
547 protected slots:
548 
549  void onInstallDownloadProgress(qSlicerExtensionDownloadTask* task, qint64 received, qint64 total);
550 
552  void onInstallDownloadFinished(qSlicerExtensionDownloadTask* task);
553 
555  void onUpdateDownloadFinished(qSlicerExtensionDownloadTask* task);
556 
557  void onUpdateDownloadProgress(qSlicerExtensionDownloadTask* task,
558  qint64 received, qint64 total);
559 
560  bool onExtensionsMetadataFromServerQueryFinished(const QUuid& requestId);
561 
562 protected:
563  QScopedPointer<qSlicerExtensionsManagerModelPrivate> d_ptr;
564 
565 private:
566  Q_DECLARE_PRIVATE(qSlicerExtensionsManagerModel);
567  Q_DISABLE_COPY(qSlicerExtensionsManagerModel);
568 };
569 
571 
572 // Metatype already declared in qSlicerIO.h
573 //Q_DECLARE_METATYPE(qSlicerExtensionsManagerModel::ExtensionMetadataType)
574 
575 #endif
Q_DECLARE_METATYPE(qSlicerExtensionsManagerModel::ServerAPI)
QScopedPointer< qSlicerExtensionsManagerModelPrivate > d_ptr
QObject Superclass
Superclass typedef.
string version
Definition: conf.py:85
Class querying and storing extensions data.
qSlicerExtensionsManagerModelPrivate Pimpl
Pimpl typedef.
return local metadata (stored in s4ext files in the extensions folder)