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->userCertCopyButton, SIGNAL(clicked()), this, SLOT(copyCert()));
connect(ui->userCertSaveButton, SIGNAL(clicked()), this, SLOT(saveCert())); connect(ui->userCertSaveButton, SIGNAL(clicked()), this, SLOT(saveCert()));
connect(ui->userCertMailButton, SIGNAL(clicked()), this, SLOT(runEmailClient())); 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; break;
case Page_Cert: case Page_Cert:
connect(ui->userFileCreateButton, SIGNAL(clicked()), this, SLOT(generateCertificateCalled())); connect(ui->userFileCreateButton, SIGNAL(clicked()), this, SLOT(generateCertificateCalled()));
@ -287,8 +295,6 @@ bool ConnectFriendWizard::validateCurrentPage()
break; break;
case Page_Text: case Page_Text:
{ {
cleanFriendCert() ;
std::string certstr = ui->friendCertEdit->toPlainText().toUtf8().constData(); std::string certstr = ui->friendCertEdit->toPlainText().toUtf8().constData();
std::string error_string; std::string error_string;
@ -478,7 +484,8 @@ void ConnectFriendWizard::updateOwnCert()
ui->userCertEdit->setPlainText(QString::fromUtf8(invite.c_str())); ui->userCertEdit->setPlainText(QString::fromUtf8(invite.c_str()));
} }
void ConnectFriendWizard::toggleFormatState()
void ConnectFriendWizard::toggleFormatState(bool doUpdate)
{ {
if (ui->userCertOldFormatButton->isChecked()) if (ui->userCertOldFormatButton->isChecked())
{ {
@ -491,9 +498,12 @@ void ConnectFriendWizard::toggleFormatState()
ui->userCertOldFormatButton->setIcon(QIcon(":/images/ledon1.png")) ; ui->userCertOldFormatButton->setIcon(QIcon(":/images/ledon1.png")) ;
} }
updateOwnCert(); if (doUpdate) {
updateOwnCert();
}
} }
void ConnectFriendWizard::toggleSignatureState()
void ConnectFriendWizard::toggleSignatureState(bool doUpdate)
{ {
if (ui->userCertIncludeSignaturesButton->isChecked()) { if (ui->userCertIncludeSignaturesButton->isChecked()) {
ui->userCertIncludeSignaturesButton->setToolTip(tr("Remove signatures")); ui->userCertIncludeSignaturesButton->setToolTip(tr("Remove signatures"));
@ -501,7 +511,9 @@ void ConnectFriendWizard::toggleSignatureState()
ui->userCertIncludeSignaturesButton->setToolTip(tr("Include signatures")); ui->userCertIncludeSignaturesButton->setToolTip(tr("Include signatures"));
} }
updateOwnCert(); if (doUpdate) {
updateOwnCert();
}
} }
void ConnectFriendWizard::runEmailClient() void ConnectFriendWizard::runEmailClient()
@ -509,37 +521,57 @@ void ConnectFriendWizard::runEmailClient()
sendMail("", tr("RetroShare Invite"), ui->userCertEdit->toPlainText()); sendMail("", tr("RetroShare Invite"), ui->userCertEdit->toPlainText());
} }
void ConnectFriendWizard::friendCertChanged()
{
ui->TextPage->setComplete(false);
cleanfriendCertTimer->start();
}
void ConnectFriendWizard::cleanFriendCert() void ConnectFriendWizard::cleanFriendCert()
{ {
bool certValid = false;
QString errorMsg;
std::string cert = ui->friendCertEdit->toPlainText().toUtf8().constData(); 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)) { if (cert.empty()) {
ui->friendCertEdit->setPlainText(QString::fromStdString(cleanCert)); ui->friendCertCleanLabel->setPixmap(QPixmap(":/images/delete.png"));
ui->friendCertCleanLabel->setToolTip("");
} else {
std::string cleanCert;
int error_code;
if (error_code > 0) { if (rsPeers->cleanCertificate(cert, cleanCert, error_code)) {
QString msg; certValid = true;
if (cert != cleanCert) {
switch (error_code) { disconnect(ui->friendCertEdit, SIGNAL(textChanged()), this, SLOT(friendCertChanged()));
case RS_PEER_CERT_CLEANING_CODE_NO_BEGIN_TAG: QTextCursor textCursor = ui->friendCertEdit->textCursor();
msg = tr("No or misspelled BEGIN tag found") ; ui->friendCertEdit->setPlainText(QString::fromUtf8(cleanCert.c_str()));
break ; ui->friendCertEdit->setTextCursor(textCursor);
case RS_PEER_CERT_CLEANING_CODE_NO_END_TAG: connect(ui->friendCertEdit, SIGNAL(textChanged()), this, SLOT(friendCertChanged()));
msg = tr("No or misspelled END tag found") ; }
break ; } else {
case RS_PEER_CERT_CLEANING_CODE_NO_CHECKSUM: if (error_code > 0) {
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:)") ; switch (error_code) {
break ; case RS_PEER_CERT_CLEANING_CODE_NO_BEGIN_TAG:
default: errorMsg = tr("No or misspelled BEGIN tag found") ;
msg = tr("Unknown error. Your cert is probably not even a certificate.") ; 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() void ConnectFriendWizard::showHelpUserCert()

View File

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

View File

@ -215,9 +215,6 @@
<verstretch>20</verstretch> <verstretch>20</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="toolTip">
<string>Run Email program</string>
</property>
<property name="icon"> <property name="icon">
<iconset resource="../images.qrc"> <iconset resource="../images.qrc">
<normaloff>:/images/ledon1.png</normaloff>:/images/ledon1.png</iconset> <normaloff>:/images/ledon1.png</normaloff>:/images/ledon1.png</iconset>
@ -272,21 +269,30 @@
<item> <item>
<layout class="QVBoxLayout" name="verticalLayout_3"> <layout class="QVBoxLayout" name="verticalLayout_3">
<item> <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"> <property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed"> <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>20</horstretch> <horstretch>20</horstretch>
<verstretch>20</verstretch> <verstretch>20</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="toolTip"> <property name="pixmap">
<string>Clean certificate</string> <pixmap resource="../images.qrc">:/images/accepted16.png</pixmap>
</property> </property>
<property name="icon"> <property name="scaledContents">
<iconset resource="../images.qrc">
<normaloff>:/images/accepted16.png</normaloff>:/images/accepted16.png</iconset>
</property>
<property name="flat">
<bool>true</bool> <bool>true</bool>
</property> </property>
</widget> </widget>