From 5cd676797a21215dcf574d545f38ec2e1a0b14f0 Mon Sep 17 00:00:00 2001 From: Dean Lee Date: Mon, 29 Mar 2021 13:32:33 +0800 Subject: [PATCH] Qt: show username for current SSH keys (#20508) * Show username for current SSH keys * Update ssh_keys.cc * Update ssh_keys.cc * Update selfdrive/ui/qt/widgets/ssh_keys.cc Co-authored-by: Adeeb Shihadeh * rename param * cleanup Co-authored-by: Adeeb Shihadeh --- common/params_pyx.pyx | 1 + selfdrive/ui/qt/widgets/ssh_keys.cc | 13 ++++++++++++- selfdrive/ui/qt/widgets/ssh_keys.hpp | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/common/params_pyx.pyx b/common/params_pyx.pyx index 499e6ea6e7..3d366b08f1 100755 --- a/common/params_pyx.pyx +++ b/common/params_pyx.pyx @@ -36,6 +36,7 @@ keys = { b"GitCommit": [TxType.PERSISTENT], b"GitRemote": [TxType.PERSISTENT], b"GithubSshKeys": [TxType.PERSISTENT], + b"GithubUsername": [TxType.PERSISTENT], b"HardwareSerial": [TxType.PERSISTENT], b"HasAcceptedTerms": [TxType.PERSISTENT], b"HasCompletedSetup": [TxType.PERSISTENT], diff --git a/selfdrive/ui/qt/widgets/ssh_keys.cc b/selfdrive/ui/qt/widgets/ssh_keys.cc index c3c1ad9ec2..6a22defbe8 100644 --- a/selfdrive/ui/qt/widgets/ssh_keys.cc +++ b/selfdrive/ui/qt/widgets/ssh_keys.cc @@ -1,12 +1,19 @@ #include - +#include #include "widgets/input.hpp" #include "widgets/ssh_keys.hpp" #include "common/params.h" SshControl::SshControl() : AbstractControl("SSH Keys", "Warning: This grants SSH access to all public keys in your GitHub settings. Never enter a GitHub username other than your own. A comma employee will NEVER ask you to add their GitHub username.", "") { + // setup widget + hlayout->addStretch(1); + + username_label.setAlignment(Qt::AlignVCenter); + username_label.setStyleSheet("color: #aaaaaa"); + hlayout->addWidget(&username_label); + btn.setStyleSheet(R"( padding: 0; border-radius: 50px; @@ -27,6 +34,7 @@ SshControl::SshControl() : AbstractControl("SSH Keys", "Warning: This grants SSH getUserKeys(username); } } else { + Params().delete_db_value("GithubUsername"); Params().delete_db_value("GithubSshKeys"); refresh(); } @@ -45,8 +53,10 @@ SshControl::SshControl() : AbstractControl("SSH Keys", "Warning: This grants SSH void SshControl::refresh() { QString param = QString::fromStdString(Params().get("GithubSshKeys")); if (param.length()) { + username_label.setText(QString::fromStdString(Params().get("GithubUsername"))); btn.setText("REMOVE"); } else { + username_label.setText(""); btn.setText("ADD"); } btn.setEnabled(true); @@ -79,6 +89,7 @@ void SshControl::parseResponse(){ networkTimer->stop(); QString response = reply->readAll(); if (reply->error() == QNetworkReply::NoError && response.length()) { + Params().write_db_value("GithubUsername", username.toStdString()); Params().write_db_value("GithubSshKeys", response.toStdString()); } else if(reply->error() == QNetworkReply::NoError){ err = "Username '" + username + "' has no keys on GitHub"; diff --git a/selfdrive/ui/qt/widgets/ssh_keys.hpp b/selfdrive/ui/qt/widgets/ssh_keys.hpp index c55249c0d5..24deee9534 100644 --- a/selfdrive/ui/qt/widgets/ssh_keys.hpp +++ b/selfdrive/ui/qt/widgets/ssh_keys.hpp @@ -29,6 +29,7 @@ public: private: QPushButton btn; QString username; + QLabel username_label; // networking QTimer* networkTimer;