fix(SyncingView): only suggest to sync non-synced devices (#11083)
This commit is contained in:
parent
7f18a76fd5
commit
11bd51fc27
|
@ -17,9 +17,13 @@ type
|
|||
QtObject:
|
||||
type Model* = ref object of QAbstractListModel
|
||||
items*: seq[Item]
|
||||
pairedCount: int
|
||||
|
||||
proc updatePairedCount(self: Model)
|
||||
|
||||
proc setup(self: Model) =
|
||||
self.QAbstractListModel.setup
|
||||
self.pairedCount = 0
|
||||
|
||||
proc delete(self: Model) =
|
||||
self.items = @[]
|
||||
|
@ -36,6 +40,13 @@ QtObject:
|
|||
read = getCount
|
||||
notify = countChanged
|
||||
|
||||
proc pairedCountChanged(self: Model) {.signal.}
|
||||
proc getPairedCount(self: Model): int {.slot.} =
|
||||
self.pairedCount
|
||||
QtProperty[int] pairedCount:
|
||||
read = getPairedCount
|
||||
notify = pairedCountChanged
|
||||
|
||||
method rowCount(self: Model, index: QModelIndex = nil): int =
|
||||
return self.items.len
|
||||
|
||||
|
@ -85,6 +96,7 @@ QtObject:
|
|||
self.items = items
|
||||
self.endResetModel()
|
||||
self.countChanged()
|
||||
self.updatePairedCount()
|
||||
|
||||
proc addItem*(self: Model, item: Item) =
|
||||
let parentModelIndex = newQModelIndex()
|
||||
|
@ -94,6 +106,7 @@ QtObject:
|
|||
self.items.add(item)
|
||||
self.endInsertRows()
|
||||
self.countChanged()
|
||||
self.updatePairedCount()
|
||||
|
||||
proc findIndexByInstallationId(self: Model, installationId: string): int =
|
||||
for i in 0..<self.items.len:
|
||||
|
@ -122,6 +135,7 @@ QtObject:
|
|||
ModelRole.DeviceType.int,
|
||||
ModelRole.FcmToken.int,
|
||||
])
|
||||
self.updatePairedCount()
|
||||
|
||||
proc updateItemName*(self: Model, installationId: string, name: string) =
|
||||
var i = self.findIndexByInstallationId(installationId)
|
||||
|
@ -136,3 +150,12 @@ QtObject:
|
|||
|
||||
proc getIsDeviceSetup*(self: Model, installationId: string): bool =
|
||||
return anyIt(self.items, it.installation.id == installationId and it.name != "")
|
||||
|
||||
proc updatePairedCount(self: Model) =
|
||||
var count = 0
|
||||
for i in 0..<self.items.len:
|
||||
if self.items[i].installation.enabled:
|
||||
count += 1
|
||||
if count != self.pairedCount:
|
||||
self.pairedCount = count
|
||||
self.pairedCountChanged()
|
||||
|
|
|
@ -15,6 +15,7 @@ StatusListItem {
|
|||
|
||||
property string deviceName: ""
|
||||
property string deviceType: ""
|
||||
property bool deviceEnabled
|
||||
property real timestamp: 0
|
||||
property bool isCurrentDevice: false
|
||||
property bool showOnlineBadge: !isCurrentDevice
|
||||
|
@ -22,7 +23,7 @@ StatusListItem {
|
|||
signal itemClicked
|
||||
signal setupSyncingButtonClicked
|
||||
|
||||
title: root.deviceName || qsTr("No device name")
|
||||
title: root.deviceName || qsTr("Unknown device")
|
||||
|
||||
asset.name: Utils.deviceIcon(root.deviceType)
|
||||
asset.bgColor: Theme.palette.primaryColor3
|
||||
|
@ -56,7 +57,7 @@ StatusListItem {
|
|||
components: [
|
||||
StatusButton {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
visible: root.enabled && !root.isCurrentDevice
|
||||
visible: root.enabled && !root.deviceEnabled && !root.isCurrentDevice
|
||||
text: qsTr("Setup syncing")
|
||||
size: StatusBaseButton.Size.Small
|
||||
onClicked: {
|
||||
|
@ -65,7 +66,7 @@ StatusListItem {
|
|||
},
|
||||
StatusIcon {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
visible: root.enabled
|
||||
visible: root.deviceEnabled
|
||||
icon: "next"
|
||||
color: Theme.palette.baseColor1
|
||||
}
|
||||
|
@ -80,6 +81,9 @@ StatusListItem {
|
|||
readonly property int minutesFromSync: secondsFromSync / 60
|
||||
readonly property int daysFromSync: LocaleUtils.daysBetween(new Date(now), new Date(d.deviceLastTimestamp))
|
||||
readonly property bool onlineNow: secondsFromSync <= 120
|
||||
|
||||
// We know if the device is paired (aka syncing is set up), if we have it's metadata
|
||||
readonly property bool paired: root.deviceName
|
||||
}
|
||||
|
||||
Timer {
|
||||
|
|
|
@ -45,6 +45,7 @@ StatusSectionLayout {
|
|||
Component.onCompleted: {
|
||||
profileContainer.currentIndex = -1
|
||||
profileContainer.currentIndex = Qt.binding(() => Global.settingsSubsection)
|
||||
root.store.devicesStore.loadDevices() // Load devices to get non-paired number for badge
|
||||
}
|
||||
|
||||
QtObject {
|
||||
|
|
|
@ -6,12 +6,15 @@ import shared 1.0
|
|||
|
||||
import utils 1.0
|
||||
|
||||
import "../stores"
|
||||
|
||||
Column {
|
||||
id: root
|
||||
spacing: 8
|
||||
|
||||
property var privacyStore
|
||||
property var contactsStore
|
||||
property PrivacyStore privacyStore
|
||||
property ContactsStore contactsStore
|
||||
property DevicesStore devicesStore
|
||||
property alias mainMenuItems: mainMenuItems.model
|
||||
property alias settingsMenuItems: settingsMenuItems.model
|
||||
property alias extraMenuItems: extraMenuItems.model
|
||||
|
@ -36,6 +39,8 @@ Column {
|
|||
switch (model.subsection) {
|
||||
case Constants.settingsSubsection.backUpSeed:
|
||||
return !root.privacyStore.mnemonicBackedUp
|
||||
case Constants.settingsSubsection.syncingSettings:
|
||||
return root.devicesStore.devicesModel.count - root.devicesStore.devicesModel.pairedCount
|
||||
default: return "";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ Item {
|
|||
width: scrollView.availableWidth
|
||||
privacyStore: store.privacyStore
|
||||
contactsStore: store.contactsStore
|
||||
devicesStore: store.devicesStore
|
||||
mainMenuItems: store.mainMenuItems
|
||||
settingsMenuItems: store.settingsMenuItems
|
||||
extraMenuItems: store.extraMenuItems
|
||||
|
|
|
@ -32,10 +32,6 @@ SettingsContentBase {
|
|||
property PrivacyStore privacyStore
|
||||
property AdvancedStore advancedStore
|
||||
|
||||
Component.onCompleted: {
|
||||
root.devicesStore.loadDevices()
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
id: layout
|
||||
width: root.contentWidth
|
||||
|
@ -117,23 +113,35 @@ SettingsContentBase {
|
|||
|
||||
model: SortFilterProxyModel {
|
||||
sourceModel: root.devicesStore.devicesModel
|
||||
sorters: StringSorter {
|
||||
roleName: "isCurrentDevice"
|
||||
sortOrder: Qt.DescendingOrder
|
||||
}
|
||||
sorters: [
|
||||
RoleSorter {
|
||||
roleName: "isCurrentDevice"
|
||||
sortOrder: Qt.DescendingOrder
|
||||
priority: 2
|
||||
},
|
||||
RoleSorter {
|
||||
roleName: "enabled"
|
||||
sortOrder: Qt.DescendingOrder
|
||||
priority: 1 // Higher number === higher priority
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
delegate: StatusSyncDeviceDelegate {
|
||||
width: ListView.view.width
|
||||
deviceName: model.name
|
||||
deviceType: model.deviceType
|
||||
deviceEnabled: model.enabled
|
||||
timestamp: model.timestamp
|
||||
isCurrentDevice: model.isCurrentDevice
|
||||
onSetupSyncingButtonClicked: {
|
||||
d.setupSyncing(SetupSyncingPopup.GenerateSyncCode)
|
||||
}
|
||||
onClicked: {
|
||||
d.personalizeDevice(model)
|
||||
if (deviceEnabled)
|
||||
d.personalizeDevice(model)
|
||||
else
|
||||
d.setupSyncing(SetupSyncingPopup.GenerateSyncCode)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue