2323
2424#include " Application.h"
2525#include " CheckConnection.h"
26- #include " common_enums.h"
2726#include " FileDialog.h"
2827#include " IKValidator.h"
2928#include " LdapSearch.h"
3231#include " TokenData.h"
3332#include " dialogs/WarningDialog.h"
3433#include " effects/Overlay.h"
34+ #include " widgets/AddressItem.h"
35+ #include " widgets/ItemList.h"
3536
3637#include < QtCore/QDateTime>
37- #include < QtCore/QJsonArray>
38- #include < QtCore/QJsonObject>
38+ #include < QtCore/QJsonValue>
3939#include < QtNetwork/QSslConfiguration>
4040#include < QtNetwork/QSslError>
4141#include < QtWidgets/QMessageBox>
4242
4343AddRecipients::AddRecipients (ItemList* itemList, QWidget *parent)
4444 : QDialog(parent)
4545 , ui(new Ui::AddRecipients)
46- , ldap_person(new LdapSearch(defaultUrl(QLatin1String(" LDAP-PERSON-URL" ), QStringLiteral(" ldaps://esteid.ldap.sk.ee" )).toUtf8(), this))
47- , ldap_corp(new LdapSearch(defaultUrl(QLatin1String(" LDAP-CORP-URL" ), QStringLiteral(" ldaps://k3.ldap.sk.ee" )).toUtf8(), this))
46+ , ldap_person(new LdapSearch(defaultUrl(QLatin1String(" LDAP-PERSON-URL" ), QStringLiteral(" ldaps://esteid.ldap.sk.ee" )), this))
47+ , ldap_person2(new LdapSearch(" ldaps://ldap-test.eidpki.ee/dc=eidpki,dc=ee" , this ))
48+ , ldap_corp(new LdapSearch(defaultUrl(QLatin1String(" LDAP-CORP-URL" ), QStringLiteral(" ldaps://k3.ldap.sk.ee" )), this))
4849{
4950 ui->setupUi (this );
5051#if defined (Q_OS_WIN)
@@ -63,8 +64,10 @@ AddRecipients::AddRecipients(ItemList* itemList, QWidget *parent)
6364 search (term);
6465 });
6566 connect (ldap_person, &LdapSearch::searchResult, this , &AddRecipients::showResult);
67+ connect (ldap_person2, &LdapSearch::searchResult, this , &AddRecipients::showResult);
6668 connect (ldap_corp, &LdapSearch::searchResult, this , &AddRecipients::showResult);
6769 connect (ldap_person, &LdapSearch::error, this , &AddRecipients::showError);
70+ connect (ldap_person2, &LdapSearch::error, this , &AddRecipients::showError);
6871 connect (ldap_corp, &LdapSearch::error, this , &AddRecipients::showError);
6972 connect (this , &AddRecipients::finished, this , &AddRecipients::close);
7073
@@ -139,7 +142,7 @@ void AddRecipients::addRecipientFromHistory()
139142
140143 ui->leftPane ->clear ();
141144 for (const HistoryCertData &certData: selectedCertData) {
142- QString term = (certData.type == QStringLiteral (" 1" ) || certData.type == QStringLiteral (" 3" )) ? certData.CN : certData.CN .split (' ,' ).value (2 );
145+ QString term = (certData.type == QLatin1String (" 1" ) || certData.type == QLatin1String (" 3" )) ? certData.CN : certData.CN .split (' ,' ).value (2 );
143146 search (term, true , certData.type );
144147 }
145148 });
@@ -153,13 +156,9 @@ void AddRecipients::addRecipient(const QSslCertificate& cert, bool select)
153156 {
154157 leftItem = new AddressItem (cert, AddressItem::Add, ui->leftPane );
155158 ui->leftPane ->addWidget (leftItem);
156- bool contains = rightList.contains (cert);
157- leftItem->setDisabled (contains);
159+ leftItem->setDisabled (rightList.contains (cert));
158160 connect (leftItem, &AddressItem::add, this , [this ](Item *item) { addRecipientToRightPane (item); });
159- if (auto *add = ui->leftPane ->findChild <QWidget*>(QStringLiteral (" add" )))
160- add->setVisible (true );
161161 }
162-
163162 if (select)
164163 addRecipientToRightPane (leftItem);
165164}
@@ -202,7 +201,6 @@ void AddRecipients::addRecipientToRightPane(Item *item, bool update)
202201 return ;
203202 }
204203 }
205- updated = update;
206204
207205 rightList.append (key);
208206
@@ -212,7 +210,6 @@ void AddRecipients::addRecipientToRightPane(Item *item, bool update)
212210 if (auto *leftItem = itemListValue (ui->leftPane , rightItem->getKey ().cert ))
213211 leftItem->setDisabled (false );
214212 rightList.removeAll (rightItem->getKey ());
215- updated = true ;
216213 ui->confirm ->setDisabled (rightList.isEmpty ());
217214 });
218215 ui->rightPane ->addWidget (rightItem);
@@ -229,7 +226,7 @@ QString AddRecipients::defaultUrl(QLatin1String key, const QString &defaultValue
229226
230227bool AddRecipients::isUpdated () const
231228{
232- return updated ;
229+ return ui-> confirm -> isEnabled () ;
233230}
234231
235232AddressItem* AddRecipients::itemListValue (ItemList *list, const CKey &cert)
@@ -273,6 +270,7 @@ void AddRecipients::search(const QString &term, bool select, const QString &type
273270 .replace (QStringLiteral (" (" ), QStringLiteral (" \\ (" ))
274271 .replace (QStringLiteral (" )" ), QStringLiteral (" \\ )" ));
275272#endif
273+ dualSeach = false ;
276274 bool isDigit = false ;
277275 void (cleanTerm.toULongLong (&isDigit));
278276 if (!isDigit || (cleanTerm.size () != 11 && cleanTerm.size () != 8 ))
@@ -282,7 +280,9 @@ void AddRecipients::search(const QString &term, bool select, const QString &type
282280 else if (IKValidator::isValid (cleanTerm))
283281 {
284282 userData[QStringLiteral (" personSearch" )] = true ;
285- ldap_person->search (QStringLiteral (" (serialNumber=%1%2)" ).arg (ldap_person->isSSL () ? QStringLiteral (" PNOEE-" ) : QString (), cleanTerm), userData);
283+ dualSeach = true ;
284+ ldap_person->search (QStringLiteral (" (serialNumber=PNOEE-%1)" ).arg (cleanTerm), userData);
285+ ldap_person2->search (QStringLiteral (" (serialNumber=PNOEE-%1)" ).arg (cleanTerm), userData);
286286 }
287287 else
288288 {
@@ -314,11 +314,12 @@ void AddRecipients::showResult(const QList<QSslCertificate> &result, int resultC
314314 }
315315 if (resultCount >= 50 )
316316 showError (tr (" The name you were looking for gave too many results, please refine your search." ));
317- else if (ui->leftPane ->items .isEmpty ())
317+ else if (!dualSeach && ui->leftPane ->items .isEmpty ())
318318 {
319319 showError (tr (" Person or company does not own a valid certificate.<br />"
320320 " It is necessary to have a valid certificate for encryption.<br />"
321321 " <a href='https://www.id.ee/en/article/encryption-and-decryption-of-documents/'>Read more about it</a>." ));
322322 }
323+ dualSeach = false ;
323324 QApplication::restoreOverrideCursor ();
324325}
0 commit comments