From a4b9eedd5eff8f565ce0da6aea3ce3a129ed735b Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Fri, 3 Jul 2020 12:54:27 -0400 Subject: [PATCH] feat: set device name --- src/app/profile/core.nim | 2 + src/app/profile/view.nim | 25 +++++++ src/status/devices.nim | 22 ++++++ src/status/libstatus/installations.nim | 9 +++ ui/app/AppLayouts/Profile/LeftTab/Menu.qml | 27 +++++++- ui/app/AppLayouts/Profile/ProfileLayout.qml | 2 + .../Profile/Sections/DevicesContainer.qml | 69 +++++++++++++++++++ ui/app/AppLayouts/Profile/Sections/qmldir | 1 + ui/nim-status-client.pro | 1 + 9 files changed, 157 insertions(+), 1 deletion(-) create mode 100644 src/status/devices.nim create mode 100644 src/status/libstatus/installations.nim create mode 100644 ui/app/AppLayouts/Profile/Sections/DevicesContainer.qml diff --git a/src/app/profile/core.nim b/src/app/profile/core.nim index 2885b0c16e..8ff6724f0c 100644 --- a/src/app/profile/core.nim +++ b/src/app/profile/core.nim @@ -7,6 +7,7 @@ import ../../status/libstatus/settings as status_settings import ../../status/profile/[profile, mailserver] import ../../status/[status, contacts] import ../../status/chat as status_chat +import ../../status/devices import ../../status/chat/chat import view import chronicles @@ -39,6 +40,7 @@ proc init*(self: ProfileController, account: Account) = profile.appearance = appearance profile.id = pubKey + self.view.setDeviceSetup(devices.isDeviceSetup()) self.view.setNewProfile(profile) self.view.setMnemonic(mnemonic) diff --git a/src/app/profile/view.nim b/src/app/profile/view.nim index a23d0edc4b..f7b9d5a9ad 100644 --- a/src/app/profile/view.nim +++ b/src/app/profile/view.nim @@ -5,6 +5,7 @@ import ../../status/profile as status_profile import ../../status/contacts as status_contacts import ../../status/accounts as status_accounts import ../../status/status +import ../../status/devices import ../../status/chat/chat import qrcode/qrcode @@ -15,6 +16,7 @@ QtObject: contactList*: ContactList mnemonic: string status*: Status + isDeviceSetup: bool proc setup(self: ProfileView) = self.QObject.setup @@ -33,6 +35,7 @@ QtObject: result.contactList = newContactList() result.mnemonic = "" result.status = status + result.isDeviceSetup = false result.setup proc addMailServerToList*(self: ProfileView, mailserver: MailServer) = @@ -101,3 +104,25 @@ QtObject: proc changeTheme*(self: ProfileView, theme: int) {.slot.} = self.profile.setAppearance(theme) self.status.saveSetting("appearance", $theme) + + proc isDeviceSetup*(self: ProfileView): bool {.slot} = + result = self.isDeviceSetup + + proc deviceSetupChanged*(self: ProfileView) {.signal.} + + proc setDeviceSetup*(self: ProfileView, isSetup: bool) {.slot} = + self.isDeviceSetup = isSetup + self.deviceSetupChanged() + + QtProperty[bool] deviceSetup: + read = isDeviceSetup + notify = deviceSetupChanged + + proc setDeviceName*(self: ProfileView, deviceName: string) {.slot.} = + devices.setDeviceName(deviceName) + self.isDeviceSetup = true + self.deviceSetupChanged() + + proc syncAllDevices*(self: ProfileView) {.slot.} = + discard + #devices.syncAllDevices() diff --git a/src/status/devices.nim b/src/status/devices.nim new file mode 100644 index 0000000000..41491a7595 --- /dev/null +++ b/src/status/devices.nim @@ -0,0 +1,22 @@ +import system +import libstatus/settings +import libstatus/installations +import json + +proc setDeviceName*(name: string) = + discard getSettings() + discard setInstallationMetadata(getSetting[string]("installation-id", "", true), name, hostOs) + +proc isDeviceSetup*():bool = + discard getSettings() + let installationId = getSetting[string]("installation-id", "", true) + let responseResult = parseJSON($getOurInstallations())["result"] + if responseResult.kind == JNull: + return false + for installation in responseResult: + if installation["id"].getStr == installationId: + return installation["metadata"].kind != JNull + result = false + +proc syncAllDevices*() = + discard \ No newline at end of file diff --git a/src/status/libstatus/installations.nim b/src/status/libstatus/installations.nim new file mode 100644 index 0000000000..94ea024703 --- /dev/null +++ b/src/status/libstatus/installations.nim @@ -0,0 +1,9 @@ +import json, core, utils, system + +proc setInstallationMetadata*(installationId: string, deviceName: string, deviceType: string): string = + result = callPrivateRPC("setInstallationMetadata".prefix, %* [installationId, {"name": deviceName, "deviceType": deviceType}]) + # TODO: handle errors + +proc getOurInstallations*(): string = + result = callPrivateRPC("getOurInstallations".prefix, %* []) + echo result diff --git a/ui/app/AppLayouts/Profile/LeftTab/Menu.qml b/ui/app/AppLayouts/Profile/LeftTab/Menu.qml index 0df10f3685..050376ce3e 100644 --- a/ui/app/AppLayouts/Profile/LeftTab/Menu.qml +++ b/ui/app/AppLayouts/Profile/LeftTab/Menu.qml @@ -101,6 +101,31 @@ Rectangle { } } + TabButton { + id: devicesTabButton + width: profileTabBar.w + height: profileTabBar.btnheight + visible: true + text: "" + anchors.left: parent.left + anchors.leftMargin: 0 + anchors.top: privacyTabButton.bottom + anchors.topMargin: 0 + background: Rectangle { + color: Theme.transparent + } + + StyledText { + color: "#000000" + text: qsTr("Devices") + anchors.left: parent.left + anchors.leftMargin: 72 + anchors.verticalCenter: parent.verticalCenter + font.weight: profileScreenButtons.currentIndex === 3 ? Font.Bold : Font.Medium + font.pixelSize: 14 + } + } + TabButton { id: syncTabButton width: profileTabBar.w @@ -109,7 +134,7 @@ Rectangle { text: "" anchors.left: parent.left anchors.leftMargin: 0 - anchors.top: privacyTabButton.bottom + anchors.top: devicesTabButton.bottom anchors.topMargin: 0 background: Rectangle { color: Style.current.transparent diff --git a/ui/app/AppLayouts/Profile/ProfileLayout.qml b/ui/app/AppLayouts/Profile/ProfileLayout.qml index 813faa9c14..0d8c5ebc71 100644 --- a/ui/app/AppLayouts/Profile/ProfileLayout.qml +++ b/ui/app/AppLayouts/Profile/ProfileLayout.qml @@ -42,6 +42,8 @@ SplitView { PrivacyContainer {} + DevicesContainer {} + SyncContainer {} LanguageContainer {} diff --git a/ui/app/AppLayouts/Profile/Sections/DevicesContainer.qml b/ui/app/AppLayouts/Profile/Sections/DevicesContainer.qml new file mode 100644 index 0000000000..026a13413e --- /dev/null +++ b/ui/app/AppLayouts/Profile/Sections/DevicesContainer.qml @@ -0,0 +1,69 @@ +import QtQuick 2.13 +import QtQuick.Controls 2.13 +import QtQuick.Layouts 1.13 +import "../../../../imports" +import "../../../../shared" + +Item { + id: syncContainer + width: 200 + height: 200 + Layout.fillHeight: true + Layout.fillWidth: true + + StyledText { + id: sectionTitle + text: qsTr("Devices") + anchors.left: parent.left + anchors.leftMargin: 24 + anchors.top: parent.top + anchors.topMargin: 24 + font.weight: Font.Bold + font.pixelSize: 20 + } + + Item { + id: firstTimeSetup + anchors.left: syncContainer.left + anchors.leftMargin: Theme.padding + anchors.top: sectionTitle.bottom + anchors.topMargin: Theme.padding + anchors.right: syncContainer.right + anchors.rightMargin: Theme.padding + visible: !profileModel.deviceSetup + + StyledText { + id: deviceNameLbl + text: qsTr("Please set a name for your device.") + font.pixelSize: 14 + } + + Input { + id: deviceNameTxt + placeholderText: qsTr("Specify a name") + anchors.top: deviceNameLbl.bottom + anchors.topMargin: Theme.padding + } + + StyledButton { + visible: !selectChatMembers + anchors.top: deviceNameTxt.bottom + anchors.topMargin: 10 + anchors.right: deviceNameTxt.right + label: qsTr("Continue") + disabled: deviceNameTxt.text === "" + onClicked : profileModel.setDeviceName(deviceNameTxt.text.trim()) + } + } + + StyledButton { + anchors.bottom: syncContainer.bottom + anchors.bottomMargin: Theme.padding + anchors.right: deviceNameTxt.right + label: qsTr("Sync all devices") + onClicked : { + console.log("TODO") + } + } + +} diff --git a/ui/app/AppLayouts/Profile/Sections/qmldir b/ui/app/AppLayouts/Profile/Sections/qmldir index 57f9a0f53e..babce23780 100644 --- a/ui/app/AppLayouts/Profile/Sections/qmldir +++ b/ui/app/AppLayouts/Profile/Sections/qmldir @@ -2,6 +2,7 @@ EnsContainer 1.0 EnsContainer.qml ContactsContainer 1.0 ContactsContainer.qml PrivacyContainer 1.0 PrivacyContainer.qml SyncContainer 1.0 SyncContainer.qml +DevicesContainer 1.0 DevicesContainer.qml LanguageContainer 1.0 LanguageContainer.qml NotificationsContainer 1.0 NotificationsContainer.qml AdvancedContainer 1.0 AdvancedContainer.qml diff --git a/ui/nim-status-client.pro b/ui/nim-status-client.pro index d5addf86b2..0d5796cf9c 100644 --- a/ui/nim-status-client.pro +++ b/ui/nim-status-client.pro @@ -134,6 +134,7 @@ DISTFILES += \ app/AppLayouts/Profile/Sections/PrivacyContainer.qml \ app/AppLayouts/Profile/Sections/SignoutContainer.qml \ app/AppLayouts/Profile/Sections/SyncContainer.qml \ + app/AppLayouts/Profile/Sections/DevicesContainer.qml \ app/AppLayouts/Profile/Sections/qmldir \ app/AppLayouts/Profile/qmldir \ app/AppLayouts/Wallet/LeftTab.qml \