From c1b47f1c9c8c3245e2c8fd35a6c24daafa74d949 Mon Sep 17 00:00:00 2001 From: Sale Djenic Date: Wed, 28 Jul 2021 13:57:55 +0200 Subject: [PATCH] High cpu usage fix --- src/app/profile/view.nim | 1 + src/app/profile/views/profile_info.nim | 114 +++++++++++++------------ 2 files changed, 59 insertions(+), 56 deletions(-) diff --git a/src/app/profile/view.nim b/src/app/profile/view.nim index 10eb6fcb32..720ee593a3 100644 --- a/src/app/profile/view.nim +++ b/src/app/profile/view.nim @@ -80,6 +80,7 @@ QtObject: proc setNewProfile*(self: ProfileView, profile: Profile) = self.profile.setProfile(profile) self.profileSettings.removeUnknownAccountSettings() + self.profileChanged() QtProperty[QVariant] profile: read = getProfile diff --git a/src/app/profile/views/profile_info.nim b/src/app/profile/views/profile_info.nim index f2360a16bb..90ba73c022 100644 --- a/src/app/profile/views/profile_info.nim +++ b/src/app/profile/views/profile_info.nim @@ -35,9 +35,10 @@ QtObject: result.sendUserStatus = false result.setup - proc profileChanged*(self: ProfileInfoView) {.signal.} - proc identityImageChanged*(self: ProfileInfoView) {.signal.} + proc sendUserStatusChanged*(self: ProfileInfoView) {.signal.} + proc appearanceChanged*(self: ProfileInfoView) {.signal.} + proc messagesFromContactsOnlyChanged*(self: ProfileInfoView) {.signal.} proc setProfile*(self: ProfileInfoView, profile: Profile) = self.username = profile.username @@ -49,7 +50,55 @@ QtObject: self.identityImage = profile.identityImage self.messagesFromContactsOnly = profile.messagesFromContactsOnly self.sendUserStatus = profile.sendUserStatus - self.profileChanged() + + proc username*(self: ProfileInfoView): string {.slot.} = result = self.username + + QtProperty[string] username: + read = username + + proc identicon*(self: ProfileInfoView): string {.slot.} = result = self.identicon + + QtProperty[string] identicon: + read = identicon + + proc pubKey*(self: ProfileInfoView): string {.slot.} = self.pubKey + + QtProperty[string] pubKey: + read = pubKey + + proc address*(self: ProfileInfoView): string {.slot.} = self.address + + QtProperty[string] address: + read = address + + proc ensVerified*(self: ProfileInfoView): bool {.slot.} = self.ensVerified + + QtProperty[bool] ensVerified: + read = ensVerified + + proc appearance*(self: ProfileInfoView): int {.slot.} = result = self.appearance + proc setAppearance*(self: ProfileInfoView, appearance: int) {.slot.} = + if self.appearance == appearance: + return + self.appearance = appearance + self.appearanceChanged() + + QtProperty[int] appearance: + read = appearance + write = setAppearance + notify = appearanceChanged + + proc messagesFromContactsOnly*(self: ProfileInfoView): bool {.slot.} = result = self.messagesFromContactsOnly + proc setMessagesFromContactsOnly*(self: ProfileInfoView, messagesFromContactsOnly: bool) {.slot.} = + if self.messagesFromContactsOnly == messagesFromContactsOnly: + return + self.messagesFromContactsOnly = messagesFromContactsOnly + self.messagesFromContactsOnlyChanged() + + QtProperty[bool] messagesFromContactsOnly: + read = messagesFromContactsOnly + write = setMessagesFromContactsOnly + notify = messagesFromContactsOnlyChanged proc setIdentityImage*(self: ProfileInfoView, identityImage: IdentityImage) = self.identityImage = identityImage @@ -59,44 +108,12 @@ QtObject: self.identityImage = IdentityImage() self.identityImageChanged() - proc username*(self: ProfileInfoView): string {.slot.} = result = self.username - QtProperty[string] username: - read = username - notify = profileChanged - - proc appearance*(self: ProfileInfoView): int {.slot.} = result = self.appearance - proc setAppearance*(self: ProfileInfoView, appearance: int) {.slot.} = - if self.appearance == appearance: - return - self.appearance = appearance - self.profileChanged() - QtProperty[int] appearance: - read = appearance - write = setAppearance - notify = profileChanged - - proc messagesFromContactsOnly*(self: ProfileInfoView): bool {.slot.} = result = self.messagesFromContactsOnly - proc setMessagesFromContactsOnly*(self: ProfileInfoView, messagesFromContactsOnly: bool) {.slot.} = - if self.messagesFromContactsOnly == messagesFromContactsOnly: - return - self.messagesFromContactsOnly = messagesFromContactsOnly - self.profileChanged() - QtProperty[bool] messagesFromContactsOnly: - read = messagesFromContactsOnly - write = setMessagesFromContactsOnly - notify = profileChanged - - - proc identicon*(self: ProfileInfoView): string {.slot.} = result = self.identicon - QtProperty[string] identicon: - read = identicon - notify = profileChanged - proc thumbnailImage*(self: ProfileInfoView): string {.slot.} = if (?.self.identityImage.thumbnail != ""): result = self.identityImage.thumbnail else: result = self.identicon + QtProperty[string] thumbnailImage: read = thumbnailImage notify = identityImageChanged @@ -106,41 +123,26 @@ QtObject: result = self.identityImage.large else: result = self.identicon + QtProperty[string] largeImage: read = largeImage notify = identityImageChanged proc hasIdentityImage*(self: ProfileInfoView): bool {.slot.} = result = (?.self.identityImage.thumbnail != "") + QtProperty[bool] hasIdentityImage: read = hasIdentityImage notify = identityImageChanged - proc pubKey*(self: ProfileInfoView): string {.slot.} = self.pubKey - - QtProperty[string] pubKey: - read = pubKey - notify = profileChanged - - proc address*(self: ProfileInfoView): string {.slot.} = self.address - - QtProperty[string] address: - read = address - notify = profileChanged - - proc ensVerified*(self: ProfileInfoView): bool {.slot.} = self.ensVerified - - QtProperty[bool] ensVerified: - read = ensVerified - notify = profileChanged - proc sendUserStatus*(self: ProfileInfoView): bool {.slot.} = result = self.sendUserStatus proc setSendUserStatus*(self: ProfileInfoView, sendUserStatus: bool) {.slot.} = if self.sendUserStatus == sendUserStatus: return self.sendUserStatus = sendUserStatus - self.profileChanged() + self.sendUserStatusChanged() + QtProperty[bool] sendUserStatus: read = sendUserStatus write = setSendUserStatus - notify = profileChanged \ No newline at end of file + notify = sendUserStatusChanged \ No newline at end of file