Added automatic clean of the friend certificate in ConnectFriendWizard.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5422 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2012-08-14 23:20:33 +00:00
parent 5d289b520b
commit cfe72859bf
3 changed files with 87 additions and 45 deletions

View File

@ -136,11 +136,19 @@ void ConnectFriendWizard::initializePage(int id)
connect(ui->userCertCopyButton, SIGNAL(clicked()), this, SLOT(copyCert()));
connect(ui->userCertSaveButton, SIGNAL(clicked()), this, SLOT(saveCert()));
connect(ui->userCertMailButton, SIGNAL(clicked()), this, SLOT(runEmailClient()));
connect(ui->friendCertCleanButton, SIGNAL(clicked()), this, SLOT(cleanFriendCert()));
connect(ui->friendCertEdit, SIGNAL(textChanged()), this, SLOT(friendCertChanged()));
ui->TextPage->registerField("friendCert*", ui->friendCertEdit, "plainText", SIGNAL(textChanged()));
cleanfriendCertTimer = new QTimer(this);
cleanfriendCertTimer->setSingleShot(true);
cleanfriendCertTimer->setInterval(1000); // 1 second
connect(cleanfriendCertTimer, SIGNAL(timeout()), this, SLOT(cleanFriendCert()));
toggleFormatState(false);
toggleSignatureState(false);
updateOwnCert();
cleanFriendCert();
toggleSignatureState(); // updateOwnCert
break;
case Page_Cert:
connect(ui->userFileCreateButton, SIGNAL(clicked()), this, SLOT(generateCertificateCalled()));
@ -287,8 +295,6 @@ bool ConnectFriendWizard::validateCurrentPage()
break;
case Page_Text:
{
cleanFriendCert() ;
std::string certstr = ui->friendCertEdit->toPlainText().toUtf8().constData();
std::string error_string;
@ -478,7 +484,8 @@ void ConnectFriendWizard::updateOwnCert()
ui->userCertEdit->setPlainText(QString::fromUtf8(invite.c_str()));
}
void ConnectFriendWizard::toggleFormatState()
void ConnectFriendWizard::toggleFormatState(bool doUpdate)
{
if (ui->userCertOldFormatButton->isChecked())
{
@ -491,9 +498,12 @@ void ConnectFriendWizard::toggleFormatState()
ui->userCertOldFormatButton->setIcon(QIcon(":/images/ledon1.png")) ;
}
updateOwnCert();
if (doUpdate) {
updateOwnCert();
}
}
void ConnectFriendWizard::toggleSignatureState()
void ConnectFriendWizard::toggleSignatureState(bool doUpdate)
{
if (ui->userCertIncludeSignaturesButton->isChecked()) {
ui->userCertIncludeSignaturesButton->setToolTip(tr("Remove signatures"));
@ -501,7 +511,9 @@ void ConnectFriendWizard::toggleSignatureState()
ui->userCertIncludeSignaturesButton->setToolTip(tr("Include signatures"));
}
updateOwnCert();
if (doUpdate) {
updateOwnCert();
}
}
void ConnectFriendWizard::runEmailClient()
@ -509,37 +521,57 @@ void ConnectFriendWizard::runEmailClient()
sendMail("", tr("RetroShare Invite"), ui->userCertEdit->toPlainText());
}
void ConnectFriendWizard::friendCertChanged()
{
ui->TextPage->setComplete(false);
cleanfriendCertTimer->start();
}
void ConnectFriendWizard::cleanFriendCert()
{
bool certValid = false;
QString errorMsg;
std::string cert = ui->friendCertEdit->toPlainText().toUtf8().constData();
cert += "\n"; // add an end of line to avoid a bug
std::string cleanCert;
int error_code;
if (rsPeers->cleanCertificate(cert, cleanCert, error_code)) {
ui->friendCertEdit->setPlainText(QString::fromStdString(cleanCert));
if (cert.empty()) {
ui->friendCertCleanLabel->setPixmap(QPixmap(":/images/delete.png"));
ui->friendCertCleanLabel->setToolTip("");
} else {
std::string cleanCert;
int error_code;
if (error_code > 0) {
QString msg;
switch (error_code) {
case RS_PEER_CERT_CLEANING_CODE_NO_BEGIN_TAG:
msg = tr("No or misspelled BEGIN tag found") ;
break ;
case RS_PEER_CERT_CLEANING_CODE_NO_END_TAG:
msg = tr("No or misspelled END tag found") ;
break ;
case RS_PEER_CERT_CLEANING_CODE_NO_CHECKSUM:
msg = tr("No checksum found (the last 5 chars should be separated by a '=' char), or no newline after tag line (e.g. line beginning with Version:)") ;
break ;
default:
msg = tr("Unknown error. Your cert is probably not even a certificate.") ;
if (rsPeers->cleanCertificate(cert, cleanCert, error_code)) {
certValid = true;
if (cert != cleanCert) {
disconnect(ui->friendCertEdit, SIGNAL(textChanged()), this, SLOT(friendCertChanged()));
QTextCursor textCursor = ui->friendCertEdit->textCursor();
ui->friendCertEdit->setPlainText(QString::fromUtf8(cleanCert.c_str()));
ui->friendCertEdit->setTextCursor(textCursor);
connect(ui->friendCertEdit, SIGNAL(textChanged()), this, SLOT(friendCertChanged()));
}
} else {
if (error_code > 0) {
switch (error_code) {
case RS_PEER_CERT_CLEANING_CODE_NO_BEGIN_TAG:
errorMsg = tr("No or misspelled BEGIN tag found") ;
break ;
case RS_PEER_CERT_CLEANING_CODE_NO_END_TAG:
errorMsg = tr("No or misspelled END tag found") ;
break ;
case RS_PEER_CERT_CLEANING_CODE_NO_CHECKSUM:
errorMsg = tr("No checksum found (the last 5 chars should be separated by a '=' char), or no newline after tag line (e.g. line beginning with Version:)") ;
break ;
default:
errorMsg = tr("Unknown error. Your cert is probably not even a certificate.") ;
}
}
QMessageBox::information(NULL, tr("Certificate cleaning error"), msg) ;
}
}
ui->friendCertCleanLabel->setPixmap(certValid ? QPixmap(":/images/accepted16.png") : QPixmap(":/images/delete.png"));
ui->friendCertCleanLabel->setToolTip(errorMsg);
ui->TextPage->setComplete(certValid);
}
void ConnectFriendWizard::showHelpUserCert()

View File

@ -44,12 +44,13 @@ protected:
private slots:
/* TextPage */
void updateOwnCert();
void toggleSignatureState();
void toggleFormatState();
void toggleSignatureState(bool doUpdate = true);
void toggleFormatState(bool doUpdate = true);
void runEmailClient();
void showHelpUserCert();
void copyCert();
void saveCert();
void friendCertChanged();
void cleanFriendCert();
/* CertificatePage */
@ -67,6 +68,9 @@ private:
bool error;
RsPeerDetails peerDetails;
/* TextPage */
QTimer *cleanfriendCertTimer;
/* FofPage */
std::map<QCheckBox*, std::string> _id_boxes;
std::map<QCheckBox*, std::string> _gpg_id_boxes;

View File

@ -215,9 +215,6 @@
<verstretch>20</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Run Email program</string>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/ledon1.png</normaloff>:/images/ledon1.png</iconset>
@ -272,21 +269,30 @@
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QPushButton" name="friendCertCleanButton">
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="friendCertCleanLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>20</horstretch>
<verstretch>20</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Clean certificate</string>
<property name="pixmap">
<pixmap resource="../images.qrc">:/images/accepted16.png</pixmap>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/accepted16.png</normaloff>:/images/accepted16.png</iconset>
</property>
<property name="flat">
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>