Remove the unneeded BackupListModel

CURA-6005
This commit is contained in:
Jaime van Kessel 2019-01-03 17:42:58 +01:00
parent 1578aaa301
commit 49076a7103
5 changed files with 22 additions and 61 deletions

View file

@ -3,18 +3,17 @@
import os
from datetime import datetime
from typing import Optional
from typing import Optional, List
from PyQt5.QtCore import QObject, pyqtSlot, pyqtProperty, pyqtSignal
from UM.Application import Application
from UM.Extension import Extension
from UM.Logger import Logger
from UM.Message import Message
from cura.CuraApplication import CuraApplication
from .Settings import Settings
from .DriveApiService import DriveApiService
from .models.BackupListModel import BackupListModel
from UM.i18n import i18nCatalog
catalog = i18nCatalog("cura")
@ -45,7 +44,7 @@ class DrivePluginExtension(QObject, Extension):
# Local data caching for the UI.
self._drive_window = None # type: Optional[QObject]
self._backups_list_model = BackupListModel()
self._backups = []
self._is_restoring_backup = False
self._is_creating_backup = False
@ -126,13 +125,13 @@ class DrivePluginExtension(QObject, Extension):
def autoBackupEnabled(self) -> bool:
return bool(self._preferences.getValue(Settings.AUTO_BACKUP_ENABLED_PREFERENCE_KEY))
@pyqtProperty(QObject, notify = backupsChanged)
def backups(self) -> BackupListModel:
return self._backups_list_model
@pyqtProperty("QVariantList", notify = backupsChanged)
def backups(self) -> List:
return self._backups
@pyqtSlot(name = "refreshBackups")
def refreshBackups(self) -> None:
self._backups_list_model.loadBackups(self._drive_api_service.getBackups())
self._backups = self._drive_api_service.getBackups()
self.backupsChanged.emit()
@pyqtProperty(bool, notify = restoringStateChanged)
@ -145,9 +144,11 @@ class DrivePluginExtension(QObject, Extension):
@pyqtSlot(str, name = "restoreBackup")
def restoreBackup(self, backup_id: str) -> None:
index = self._backups_list_model.find("backup_id", backup_id)
backup = self._backups_list_model.getItem(index)
for backup in self._backups:
if backup.get("backup_id") == backup_id:
self._drive_api_service.restoreBackup(backup)
return
Logger.log("w", "Unable to find backup with the ID %s", backup_id)
@pyqtSlot(name = "createBackup")
def createBackup(self) -> None:

View file

@ -1,40 +0,0 @@
# Copyright (c) 2018 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
from typing import Any, List, Dict
from UM.Qt.ListModel import ListModel
from PyQt5.QtCore import Qt
class BackupListModel(ListModel):
"""
The BackupListModel transforms the backups data that came from the server so it can be served to the Qt UI.
"""
def __init__(self, parent = None) -> None:
super().__init__(parent)
self.addRoleName(Qt.UserRole + 1, "backup_id")
self.addRoleName(Qt.UserRole + 2, "download_url")
self.addRoleName(Qt.UserRole + 3, "generated_time")
self.addRoleName(Qt.UserRole + 4, "md5_hash")
self.addRoleName(Qt.UserRole + 5, "data")
def loadBackups(self, data: List[Dict[str, Any]]) -> None:
"""
Populate the model with server data.
:param data:
"""
items = []
for backup in data:
# We do this loop because we only want to append these specific fields.
# Without this, ListModel will break.
items.append({
"backup_id": backup["backup_id"],
"download_url": backup["download_url"],
"generated_time": backup["generated_time"],
"md5_hash": backup["md5_hash"],
"data": backup["metadata"]
})
self.setItems(items)

View file

@ -44,7 +44,7 @@ Item
Label
{
text: new Date(model["generated_time"]).toLocaleString(UM.Preferences.getValue("general/language"))
text: new Date(modelData.generated_time).toLocaleString(UM.Preferences.getValue("general/language"))
color: UM.Theme.getColor("text")
elide: Text.ElideRight
Layout.minimumWidth: 100 * screenScaleFactor
@ -55,7 +55,7 @@ Item
Label
{
text: model["data"]["description"]
text: modelData.metadata.description
color: UM.Theme.getColor("text")
elide: Text.ElideRight
Layout.minimumWidth: 100 * screenScaleFactor
@ -85,7 +85,7 @@ Item
BackupListItemDetails
{
id: backupDetails
backupDetailsData: model
backupDetailsData: modelData
width: parent.width
visible: parent.showDetails
anchors.top: dataRow.bottom
@ -97,7 +97,7 @@ Item
title: catalog.i18nc("@dialog:title", "Delete Backup")
text: catalog.i18nc("@dialog:info", "Are you sure you want to delete this backup? This cannot be undone.")
standardButtons: StandardButton.Yes | StandardButton.No
onYes: CuraDrive.deleteBackup(model["backup_id"])
onYes: CuraDrive.deleteBackup(modelData.backup_id)
}
MessageDialog
@ -106,6 +106,6 @@ Item
title: catalog.i18nc("@dialog:title", "Restore Backup")
text: catalog.i18nc("@dialog:info", "You will need to restart Cura before your backup is restored. Do you want to close Cura now?")
standardButtons: StandardButton.Yes | StandardButton.No
onYes: CuraDrive.restoreBackup(model["backup_id"])
onYes: CuraDrive.restoreBackup(modelData.backup_id)
}
}

View file

@ -19,7 +19,7 @@ ColumnLayout
{
iconSource: "../images/cura.svg"
label: catalog.i18nc("@backuplist:label", "Cura Version")
value: backupDetailsData["data"]["cura_release"]
value: backupDetailsData.metadata.cura_release
}
// Machine count.
@ -27,7 +27,7 @@ ColumnLayout
{
iconSource: "../images/printer.svg"
label: catalog.i18nc("@backuplist:label", "Machines")
value: backupDetailsData["data"]["machine_count"]
value: backupDetailsData.metadata.machine_count
}
// Meterial count.
@ -35,7 +35,7 @@ ColumnLayout
{
iconSource: "../images/material.svg"
label: catalog.i18nc("@backuplist:label", "Materials")
value: backupDetailsData["data"]["material_count"]
value: backupDetailsData.metadata.material_count
}
// Meterial count.
@ -43,7 +43,7 @@ ColumnLayout
{
iconSource: "../images/profile.svg"
label: catalog.i18nc("@backuplist:label", "Profiles")
value: backupDetailsData["data"]["profile_count"]
value: backupDetailsData.metadata.profile_count
}
// Meterial count.
@ -51,7 +51,7 @@ ColumnLayout
{
iconSource: "../images/plugin.svg"
label: catalog.i18nc("@backuplist:label", "Plugins")
value: backupDetailsData["data"]["plugin_count"]
value: backupDetailsData.metadata.plugin_count
}
// Spacer.