Slicer  4.10
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 
43 class Q_SLICER_BASE_QTCORE_EXPORT qSlicerExtensionsManagerModel : public QObject
44 {
45  Q_OBJECT
46  Q_PROPERTY(int numberOfInstalledExtensions READ numberOfInstalledExtensions NOTIFY modelUpdated)
47  Q_PROPERTY(QStringList installedExtensions READ installedExtensions NOTIFY modelUpdated)
48  Q_PROPERTY(QStringList enabledExtensions READ enabledExtensions NOTIFY modelUpdated)
49  Q_PROPERTY(bool newExtensionEnabledByDefault READ newExtensionEnabledByDefault WRITE setNewExtensionEnabledByDefault NOTIFY newExtensionEnabledByDefaultChanged)
50  Q_PROPERTY(QString extensionsSettingsFilePath READ extensionsSettingsFilePath WRITE setExtensionsSettingsFilePath NOTIFY extensionsSettingsFilePathChanged)
51  Q_PROPERTY(QString extensionsHistorySettingsFilePath READ extensionsHistorySettingsFilePath WRITE setExtensionsHistorySettingsFilePath NOTIFY extensionsHistorySettingsFilePathChanged)
52  Q_PROPERTY(QString slicerRevision READ slicerRevision WRITE setSlicerRevision NOTIFY slicerRevisionChanged)
53  Q_PROPERTY(QString slicerOs READ slicerOs WRITE setSlicerOs NOTIFY slicerOsChanged)
54  Q_PROPERTY(QString slicerArch READ slicerArch WRITE setSlicerArch NOTIFY slicerArchChanged)
55  Q_PROPERTY(QString slicerVersion READ slicerVersion WRITE setSlicerVersion NOTIFY slicerVersionChanged)
56 public:
58  typedef QObject Superclass;
59 
61  typedef qSlicerExtensionsManagerModelPrivate Pimpl;
62 
65 
67  explicit qSlicerExtensionsManagerModel(QObject* parent = 0);
68 
71 
74 
75  Q_INVOKABLE QUrl serverUrl()const;
76  Q_INVOKABLE QUrl serverUrlWithPackagePath()const;
77  Q_INVOKABLE QUrl serverUrlWithExtensionsStorePath()const;
78 
79  Q_INVOKABLE QString extensionsInstallPath()const;
80 
81  Q_INVOKABLE QString extensionInstallPath(const QString& extensionName) const;
82 
83  Q_INVOKABLE QStringList extensionModulePaths(const QString& extensionName)const;
84 
85  Q_INVOKABLE QString extensionDescriptionFile(const QString& extensionName) const;
86 
87  void setNewExtensionEnabledByDefault(bool value);
88  bool newExtensionEnabledByDefault()const;
89 
90  Q_INVOKABLE ExtensionMetadataType extensionMetadata(const QString& extensionName)const;
91 
94  Q_INVOKABLE bool isExtensionInstalled(const QString& extensionName)const;
95 
98  int numberOfInstalledExtensions()const;
99 
102  QStringList installedExtensions()const;
103 
106  Q_INVOKABLE bool isExtensionEnabled(const QString& extensionName)const;
107 
112  QStringList scheduledForUpdateExtensions() const;
113 
120  Q_INVOKABLE bool isExtensionUpdateAvailable(const QString& extensionName)const;
121 
127  Q_INVOKABLE bool isExtensionScheduledForUpdate(const QString& extensionName)const;
128 
131  QStringList scheduledForUninstallExtensions() const;
132 
135  Q_INVOKABLE bool isExtensionScheduledForUninstall(const QString& extensionName)const;
136 
139  QStringList enabledExtensions()const;
140 
144  QString extensionsSettingsFilePath()const;
145  void setExtensionsSettingsFilePath(const QString& extensionsSettingsFilePath);
146 
150  QString extensionsHistorySettingsFilePath()const;
151  void setExtensionsHistorySettingsFilePath(const QString& extensionsHistorySettingsFilePath);
152 
153  QVariantMap extensionsHistoryInformation()const;
154 
158  QString slicerRevision()const;
159  void setSlicerRevision(const QString& revision);
160 
164  QString slicerOs()const;
165  void setSlicerOs(const QString& os);
166 
170  QString slicerArch()const;
171  void setSlicerArch(const QString& arch);
172 
180  void setSlicerRequirements(const QString& revision, const QString& os, const QString& arch);
181 
182  QString slicerVersion()const;
183  void setSlicerVersion(const QString& version);
184 
189  Q_INVOKABLE QStringList isExtensionCompatible(const QString& extensionName, const QString& slicerRevision,
190  const QString& slicerOs, const QString& slicerArch) const;
191 
198  Q_INVOKABLE QStringList isExtensionCompatible(const QString& extensionName) const;
199 
202  Q_INVOKABLE ExtensionMetadataType retrieveExtensionMetadata(const QString& extensionId);
203 
206  Q_INVOKABLE ExtensionMetadataType retrieveExtensionMetadataByName(const QString& extensionName);
207 
215  Q_INVOKABLE bool installExtension(const QString &archiveFile);
216 
224  Q_INVOKABLE bool installExtension(const QString& extensionName,
225  ExtensionMetadataType extensionMetadata,
226  const QString &archiveFile);
227 
229  Q_INVOKABLE bool extractExtensionArchive(const QString& extensionName,
230  const QString& archiveFile,
231  const QString &destinationPath);
232 
234  Q_INVOKABLE const QStandardItemModel * model()const;
235 
236  static QHash<QString, QString> serverToExtensionDescriptionKey();
237 
238  static QStringList serverKeysToIgnore();
239 
240  static ExtensionMetadataType filterExtensionMetadata(const ExtensionMetadataType &extensionMetadata);
241 
242  static QStringList readArrayValues(QSettings& settings,
243  const QString& arrayName, const QString fieldName);
244 
245  static void writeArrayValues(QSettings& settings, const QStringList& values,
246  const QString& arrayName, const QString fieldName);
247 
248  static bool writeExtensionDescriptionFile(const QString& file,
249  const ExtensionMetadataType& metadata);
250 
251  static ExtensionMetadataType parseExtensionDescriptionFile(const QString& file);
252 
253 public slots:
254 
258  void setExtensionEnabled(const QString& extensionName, bool value);
259 
263  bool downloadAndInstallExtension(const QString& extensionId);
264 
270  bool scheduleExtensionForUninstall(const QString& extensionName);
271 
275  bool cancelExtensionScheduledForUninstall(const QString& extensionName);
276 
282  void checkForUpdates(bool installUpdates);
283 
290  bool scheduleExtensionForUpdate(const QString& extensionName);
291 
295  bool cancelExtensionScheduledForUpdate(const QString& extensionName);
296 
305  bool updateScheduledExtensions(QStringList &updatedExtensions);
306 
312  bool updateScheduledExtensions();
313 
322  bool uninstallScheduledExtensions(QStringList &uninstalledExtensions);
323 
329  bool uninstallScheduledExtensions();
330 
331  void gatherExtensionsHistoryInformationOnStartup();
332 
333  QVariantMap getExtensionHistoryInformation();
334 
335  void identifyIncompatibleExtensions();
336 
337  bool exportExtensionList(QString& exportFilePath);
338 
339  QStringList checkInstallPrerequisites() const;
340 
341  void updateModel();
342 
343 signals:
344 
345  void downloadStarted(QNetworkReply * reply);
346 
347  void downloadFinished(QNetworkReply * reply);
348 
349  void updateDownloadProgress(const QString& extensionName,
350  qint64 received, qint64 total);
351 
352  void modelUpdated();
353 
354  void extensionUpdateAvailable(const QString& extensionName);
355 
356  void extensionInstalled(const QString& extensionName);
357 
358  void extensionUpdated(const QString& extensionName);
359 
360  void extensionScheduledForUninstall(const QString& extensionName);
361 
362  void extensionCancelledScheduleForUninstall(const QString& extensionName);
363 
364  void extensionScheduledForUpdate(const QString& extensionName);
365 
366  void extensionCancelledScheduleForUpdate(const QString& extensionName);
367 
368  void extensionUninstalled(const QString& extensionName);
369 
370  void extensionEnabledChanged(const QString& extensionName, bool value);
371 
372  void extensionIdentifedAsIncompatible(const QString& extensionName);
373 
374  void newExtensionEnabledByDefaultChanged(bool value);
375 
376  void slicerRequirementsChanged(const QString& revision, const QString& os, const QString& arch);
377  void slicerArchChanged(const QString& slicerArch);
378  void slicerOsChanged(const QString& slicerOs);
379  void slicerRevisionChanged(const QString& slicerRevision);
380 
381  void slicerVersionChanged(const QString& slicerVersion);
382 
383  void messageLogged(const QString& text, ctkErrorLogLevel::LogLevels level) const;
384 
385  void extensionHistoryGatheredOnStartup(const QVariantMap&);
386 
387  void installDownloadProgress(const QString& extensionName, qint64 received, qint64 total);
388 
389  void extensionsSettingsFilePathChanged(const QString& extensionsSettingsFilePath);
390 
391  void extensionsHistorySettingsFilePathChanged(const QString& extensionsHistorySettingsFilePath);
392 
393 protected slots:
394 
395  void onInstallDownloadProgress(qSlicerExtensionDownloadTask* task, qint64 received, qint64 total);
396 
398  void onInstallDownloadFinished(qSlicerExtensionDownloadTask* task);
399 
401  void onUpdateDownloadFinished(qSlicerExtensionDownloadTask* task);
402 
403  void onUpdateDownloadProgress(qSlicerExtensionDownloadTask* task,
404  qint64 received, qint64 total);
405 
406  void onUpdateCheckComplete(const QUuid& requestId,
407  const QList<QVariantMap>& results);
408  void onUpdateCheckFailed(const QUuid& requestId);
409 
410 protected:
411  QScopedPointer<qSlicerExtensionsManagerModelPrivate> d_ptr;
412 
413 private:
414  Q_DECLARE_PRIVATE(qSlicerExtensionsManagerModel);
415  Q_DISABLE_COPY(qSlicerExtensionsManagerModel);
416 };
417 
418 // Metatype already declared in qSlicerIO.h
419 //Q_DECLARE_METATYPE(qSlicerExtensionsManagerModel::ExtensionMetadataType)
420 
421 #endif
QObject Superclass
Superclass typedef.
qSlicerExtensionsManagerModelPrivate Pimpl
Pimpl typedef.