Add ConnectFriendWizard improvement.

Add cert details in friendCertCleanLabel tooltip.
Use qss for background color of friendCertCleanLabel.
Add Known IP in final view.
This commit is contained in:
Phenom 2021-11-06 14:10:17 +01:00
parent e8b97405b9
commit a072b151f5
7 changed files with 57 additions and 36 deletions

View File

@ -552,26 +552,24 @@ unsigned short RsCertificate::loc_port_us() const
return (int)ipv4_internal_ip_and_port[4]*256 + (int)ipv4_internal_ip_and_port[5] ;
}
bool RsCertificate::cleanCertificate( const std::string& input, std::string& output, Format& format, uint32_t& error_code, bool check_content )
bool RsCertificate::cleanCertificate( const std::string& input, std::string& output, Format& format, uint32_t& error_code, bool check_content, RsPeerDetails& details)
{
if(cleanRadix64(input,output,error_code))
{
RsPeerDetails details;
if(rsPeers->parseShortInvite(output,details,error_code))
{
format = RS_CERTIFICATE_SHORT_RADIX;
return true;
}
if(rsPeers->parseShortInvite(output,details,error_code))
{
format = RS_CERTIFICATE_SHORT_RADIX;
return true;
}
//Clear details. As parseShortInvite may make it dirty.
details = RsPeerDetails();
format = RS_CERTIFICATE_RADIX;
if(!check_content) return true;
uint32_t errCode;
auto crt = RsCertificate::fromString(input, errCode);
error_code = static_cast<int>(errCode);
return crt != nullptr;
return rsPeers->loadDetailsFromStringCert(input,details,error_code);
}
return false;

View File

@ -84,7 +84,7 @@ public:
static bool cleanCertificate(
const std::string& input, std::string& output,
RsCertificate::Format& format, uint32_t& error_code, bool check_content);
RsCertificate::Format& format, uint32_t& error_code, bool check_content, RsPeerDetails& details);
const std::set<RsUrl>& locators() const { return mLocators; }

View File

@ -887,7 +887,7 @@ public:
// Certificate utils
virtual bool cleanCertificate(
const std::string& certstr, std::string& cleanCert,
bool& is_short_format, uint32_t& error_code ) = 0;
bool& is_short_format, uint32_t& error_code, RsPeerDetails& details) = 0;
virtual std::string saveCertificateToString(const RsPeerId &id) = 0;
virtual bool signGPGCertificate(const RsPgpId &gpg_id,const std::string& gpg_passphrase) = 0;

View File

@ -1758,11 +1758,11 @@ bool p3Peers::loadDetailsFromStringCert( const std::string &certstr,
return true;
}
bool p3Peers::cleanCertificate(const std::string &certstr, std::string &cleanCert,bool& is_short_format,uint32_t& error_code)
bool p3Peers::cleanCertificate(const std::string &certstr, std::string &cleanCert,bool& is_short_format,uint32_t& error_code,RsPeerDetails& details)
{
RsCertificate::Format format ;
bool res = RsCertificate::cleanCertificate(certstr,cleanCert,format,error_code,true) ;
bool res = RsCertificate::cleanCertificate(certstr,cleanCert,format,error_code,true,details) ;
if(format == RsCertificate::RS_CERTIFICATE_RADIX)
is_short_format = false;

View File

@ -163,7 +163,7 @@ public:
virtual bool loadPgpKeyFromBinaryData( const unsigned char *bin_key_data,uint32_t bin_key_len, RsPgpId& gpg_id, std::string& error_string ) override;
virtual bool loadDetailsFromStringCert(const std::string &cert, RsPeerDetails &pd, uint32_t& error_code) override;
virtual bool cleanCertificate(const std::string &certstr, std::string &cleanCert, bool &is_short_format, uint32_t& error_code) override;
virtual bool cleanCertificate(const std::string &certstr, std::string &cleanCert, bool &is_short_format, uint32_t& error_code, RsPeerDetails& details) override;
virtual std::string saveCertificateToString(const RsPeerId &id) override;
virtual bool signGPGCertificate(const RsPgpId &id,const std::string& gpg_passphrase) override;

View File

@ -39,6 +39,7 @@
#include "ConnectFriendWizard.h"
#include "ui_ConnectFriendWizard.h"
#include "gui/common/PeerDefs.h"
#include "gui/connect/ConfCertDialog.h"
#include "gui/notifyqt.h"
#include "gui/common/GroupDefs.h"
#include "gui/msgs/MessageComposer.h"
@ -572,6 +573,16 @@ void ConnectFriendWizard::initializePage(int id)
ui->ipEdit->setText(s);
ui->signersEdit->setPlainText(ts);
ui->knownIpLabel->setHidden(peerDetails.ipAddressList.empty());
ui->knownIpEdit->setHidden(peerDetails.ipAddressList.empty());
{
QString ipList;
for(auto& it : peerDetails.ipAddressList)
ipList.append(QString::fromStdString(it) + "\n");
ui->knownIpEdit->setPlainText(ipList);
}
fillGroups(this, ui->groupComboBox, groupId);
if(peerDetails.isHiddenNode)
@ -587,15 +598,16 @@ void ConnectFriendWizard::initializePage(int id)
}
if(mIsShortInvite)
{
ui->nameEdit->setText(tr("[Unknown]"));
ui->addKeyToKeyring_CB->setChecked(false);
ui->addKeyToKeyring_CB->setEnabled(false);
if(ui->nameEdit->text().isEmpty())
ui->nameEdit->setText(tr("[Unknown]"));
ui->addKeyToKeyring_CB->setChecked(false);
ui->addKeyToKeyring_CB->setEnabled(false);
ui->signersEdit->hide();
ui->signersLabel->hide();
ui->signGPGCheckBox->setChecked(false);
ui->signGPGCheckBox->setEnabled(false);
ui->acceptNoSignGPGCheckBox->setChecked(true);
ui->acceptNoSignGPGCheckBox->setEnabled(false);
ui->signGPGCheckBox->setChecked(false);
ui->signGPGCheckBox->setEnabled(false);
ui->acceptNoSignGPGCheckBox->setChecked(true);
ui->acceptNoSignGPGCheckBox->setEnabled(false);
}
ui->ipEdit->setTextInteractionFlags(Qt::TextSelectableByMouse);
@ -856,30 +868,30 @@ void ConnectFriendWizard::cleanFriendCert()
{
bool certValid = false;
QString errorMsg ;
QString certDetail;
std::string cert = ui->friendCertEdit->toPlainText().toUtf8().constData();
if (cert.empty()) {
ui->friendCertCleanLabel->setPixmap(FilesDefs::getPixmapFromQtResourcePath(":/images/delete.png"));
ui->friendCertCleanLabel->setToolTip("");
ui->friendCertCleanLabel->setStyleSheet("");
errorMsg = tr("");
} else {
std::string cleanCert;
uint32_t error_code;
RsPeerDetails details;
if (rsPeers->cleanCertificate(cert, cleanCert, mIsShortInvite, error_code))
{
if (rsPeers->cleanCertificate(cert, cleanCert, mIsShortInvite, error_code, details))
{
certValid = true;
if (cert != cleanCert)
{
{
QTextCursor textCursor = ui->friendCertEdit->textCursor();
whileBlocking(ui->friendCertEdit)->setPlainText(QString::fromUtf8(cleanCert.c_str()));
whileBlocking(ui->friendCertEdit)->setTextCursor(textCursor);
ui->friendCertCleanLabel->setStyleSheet("");
certDetail = ConfCertDialog::getCertificateDescription(details,false,mIsShortInvite,!details.ipAddressList.empty());
}
if (mIsShortInvite)
@ -887,7 +899,7 @@ void ConnectFriendWizard::cleanFriendCert()
else
errorMsg = tr("Valid certificate") ;
ui->friendCertCleanLabel->setPixmap(FilesDefs::getPixmapFromQtResourcePath(":/images/accepted16.png"));
ui->friendCertCleanLabel->setPixmap(FilesDefs::getPixmapFromQtResourcePath(":/images/accepted16.png"));
} else {
if (error_code > 0) {
switch (error_code) {
@ -903,16 +915,17 @@ void ConnectFriendWizard::cleanFriendCert()
default:
errorMsg = tr("Not a valid Retroshare certificate!") ;
ui->friendCertCleanLabel->setStyleSheet("QLabel#friendCertCleanLabel {border: 1px solid #DCDC41; border-radius: 6px; background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #FFFFD7, stop:1 #FFFFB2);}");
}
}
ui->friendCertCleanLabel->setPixmap(FilesDefs::getPixmapFromQtResourcePath(":/images/delete.png"));
}
}
ui->friendCertCleanLabel->setPixmap(certValid ? FilesDefs::getPixmapFromQtResourcePath(":/images/accepted16.png") : FilesDefs::getPixmapFromQtResourcePath(":/images/delete.png"));
ui->friendCertCleanLabel->setToolTip(errorMsg);
ui->friendCertCleanLabel->setPixmap(certValid ? FilesDefs::getPixmapFromQtResourcePath(":/images/accepted16.png") : FilesDefs::getPixmapFromQtResourcePath(":/images/delete.png"));
ui->friendCertCleanLabel->setToolTip("<p>" + errorMsg + (certValid ? "\n" + certDetail : "") + "</p>");
ui->friendCertCleanLabel->setText(errorMsg);
ui->friendCertCleanLabel->setProperty("WrongValue", !certValid && !errorMsg.isEmpty());
ui->friendCertCleanLabel->style()->unpolish(ui->friendCertCleanLabel);
ui->friendCertCleanLabel->style()->polish( ui->friendCertCleanLabel);
ui->TextPage->setComplete(certValid);
}

View File

@ -590,7 +590,7 @@
</sizepolicy>
</property>
<property name="text">
<string notr="true">Email</string>
<string notr="true">ProfilId</string>
</property>
</widget>
</item>
@ -629,7 +629,7 @@
</sizepolicy>
</property>
<property name="text">
<string>Signers</string>
<string>Signers:</string>
</property>
</widget>
</item>
@ -675,6 +675,16 @@
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="knownIpLabel">
<property name="text">
<string>Known IP:</string>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QPlainTextEdit" name="knownIpEdit"/>
</item>
</layout>
</widget>
</item>