Mercurial > trustbridge
comparison ui/mainwindow.cpp @ 445:b3721ded6f5b
Sort and filter the certificate list, changed certificate item roles.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Wed, 23 Apr 2014 11:53:57 +0200 |
parents | 4b486a14252f |
children | 43090637d6ae |
comparison
equal
deleted
inserted
replaced
443:20f539866fa8 | 445:b3721ded6f5b |
---|---|
292 QVBoxLayout *settingsLayout = new QVBoxLayout; | 292 QVBoxLayout *settingsLayout = new QVBoxLayout; |
293 | 293 |
294 // The certificate list | 294 // The certificate list |
295 QGroupBox *certBox = new QGroupBox(tr("Managed Certificates")); | 295 QGroupBox *certBox = new QGroupBox(tr("Managed Certificates")); |
296 mCertListWidget = new QListWidget; | 296 mCertListWidget = new QListWidget; |
297 mCertListWidget->setItemDelegate(new CertificateItemDelegate); | |
298 connect(mCertListWidget, SIGNAL(itemClicked(QListWidgetItem*)), | 297 connect(mCertListWidget, SIGNAL(itemClicked(QListWidgetItem*)), |
299 this, SLOT(showDetails(QListWidgetItem*))); | 298 this, SLOT(showDetails(QListWidgetItem*))); |
300 certLayout->addWidget(mCertListWidget); | 299 certLayout->addWidget(mCertListWidget); |
301 certBox->setLayout(certLayout); | 300 certBox->setLayout(certLayout); |
302 | 301 |
393 mCertListWidget->clear(); | 392 mCertListWidget->clear(); |
394 int i = 0; | 393 int i = 0; |
395 | 394 |
396 /* TODO: if nothing is available (neither old nor new) add some progress | 395 /* TODO: if nothing is available (neither old nor new) add some progress |
397 * indication */ | 396 * indication */ |
398 | 397 QList<Certificate> newInstallCerts; |
399 foreach (const Certificate &cert, mListToInstall.isValid() ? | 398 QList<Certificate> newRemoveCerts; |
400 mListToInstall.getCertificates() : | 399 QList<Certificate> oldInstallCerts; |
401 mInstalledList.getCertificates()) { | 400 QList<Certificate> oldRemoveCerts; |
402 if (!cert.isValid()) { | 401 |
403 qWarning() << "Invalid certificate in list"; | 402 if (mListToInstall.getCertificates().isEmpty()) { |
404 continue; | 403 // No new list available, add old certificates. |
405 } | 404 foreach (const Certificate &cert, mInstalledList.getCertificates()) { |
406 QListWidgetItem* item = new QListWidgetItem(cert.shortDescription()); | 405 if (cert.isInstallCert()) { |
407 SeparatorItemDelegate *separator = new SeparatorItemDelegate(); | 406 oldInstallCerts.append(cert); |
408 item->setData(CertificateItemDelegate::DetailsRole, QVariant::fromValue(cert)); | |
409 Qt::CheckState checkedState = mPreviouslyUnselected.contains(cert.base64Line()) ? | |
410 Qt::Unchecked : Qt::Checked; | |
411 | |
412 bool isOld = mInstalledList.getCertificates().contains(cert); | |
413 qDebug() << "Found old certificate."; | |
414 /* TODO properly work with that information. */ | |
415 | |
416 if (cert.isInstallCert()) { | |
417 // This if statements is for testing! @TODO Remove this! | |
418 if (isOld) { | |
419 item->setData(CertificateItemDelegate::StatusRole, Certificate::InstallOld); | |
420 item->setFlags(item->flags() | Qt::ItemIsUserCheckable); | |
421 } | 407 } |
422 else { | 408 else { |
423 item->setData(CertificateItemDelegate::StatusRole, Certificate::InstallNew); | 409 oldRemoveCerts.append(cert); |
424 item->setFlags(item->flags() | Qt::ItemIsUserCheckable); | |
425 } | 410 } |
426 if (i == 3) { | 411 } |
427 QListWidgetItem *sep = new QListWidgetItem("New certificates"); | 412 } |
428 mCertListWidget->setItemDelegateForRow(i, separator); | 413 else { |
429 mCertListWidget->addItem(sep); | 414 // Sort and filter both lists. |
430 i++; | 415 foreach (const Certificate &cert, mListToInstall.getCertificates()) { |
431 } | 416 if (cert.isInstallCert()) { |
432 item->setCheckState(checkedState); | 417 // Certificate with status "install". |
433 } | 418 if (mInstalledList.getCertificates().contains(cert)) { |
434 else { | 419 // Was in the old list. |
435 // This if statements is for testing! @TODO Remove this! | 420 oldInstallCerts.append(cert); |
436 if (i > 35) { | 421 } |
437 item->setData(CertificateItemDelegate::StatusRole, Certificate::RemoveNew); | 422 else { |
438 item->setFlags(item->flags() | Qt::ItemIsUserCheckable); | 423 // Is a brand new certificate |
439 item->setCheckState(checkedState); | 424 newInstallCerts.append(cert); |
425 } | |
440 } | 426 } |
441 else { | 427 else { |
442 item->setData(CertificateItemDelegate::StatusRole, Certificate::RemoveOld); | 428 // Certificate with status "remove". |
443 item->setFlags(item->flags() | Qt::ItemIsUserCheckable); | 429 if (mInstalledList.getCertificates().contains(cert)) { |
430 // Was in the old list. | |
431 oldRemoveCerts.append(cert); | |
432 } | |
433 else { | |
434 // Was in the old list with status "install" and now has the | |
435 // status "remove". | |
436 newRemoveCerts.append(cert); | |
437 } | |
444 } | 438 } |
445 } | 439 } |
446 mCertListWidget->addItem(item); | 440 } |
447 i++; | 441 |
448 } | 442 // Add separators and certificates to list widget. |
443 mCertListWidget->addItem(createSeparator(tr("New certificates to install"), i++)); | |
444 foreach (const Certificate &cert, newInstallCerts) { | |
445 mCertListWidget->addItem(createListItem(cert, Certificate::InstallNew, i++)); | |
446 } | |
447 | |
448 mCertListWidget->addItem(createSeparator(tr("New certificates to remove"), i++)); | |
449 foreach (const Certificate &cert, newRemoveCerts) { | |
450 mCertListWidget->addItem(createListItem(cert, Certificate::RemoveNew, i++)); | |
451 } | |
452 | |
453 mCertListWidget->addItem(createSeparator(tr("Old certificates to install"), i++)); | |
454 foreach (const Certificate &cert, oldInstallCerts) { | |
455 mCertListWidget->addItem(createListItem(cert, Certificate::InstallOld, i++)); | |
456 } | |
457 | |
458 mCertListWidget->addItem(createSeparator(tr("Old certificates to remove"), i++)); | |
459 foreach (const Certificate &cert, oldRemoveCerts) { | |
460 mCertListWidget->addItem(createListItem(cert, Certificate::RemoveOld, i++)); | |
461 } | |
462 } | |
463 | |
464 QListWidgetItem* MainWindow::createSeparator(const QString &text, int index) | |
465 { | |
466 SeparatorItemDelegate *separatorDelegate = new SeparatorItemDelegate(); | |
467 QListWidgetItem *separator = new QListWidgetItem(text); | |
468 mCertListWidget->setItemDelegateForRow(index, separatorDelegate); | |
469 separator->setFlags(separator->flags() ^ Qt::ItemIsUserCheckable); | |
470 return separator; | |
471 } | |
472 | |
473 QListWidgetItem* MainWindow::createListItem(const Certificate &certificate, | |
474 Certificate::Status status, int index) | |
475 { | |
476 CertificateItemDelegate *certDelegate = new CertificateItemDelegate(); | |
477 QListWidgetItem* item = new QListWidgetItem(certificate.shortDescription()); | |
478 item->setData(CertificateItemDelegate::DataRole, | |
479 QVariant::fromValue(certificate)); | |
480 item->setData(CertificateItemDelegate::StatusRole, status); | |
481 if (!mPreviouslyUnselected.contains(certificate.base64Line()) && | |
482 status == Certificate::RemoveOld) { | |
483 item->setFlags(item->flags() ^ Qt::ItemIsUserCheckable); | |
484 } | |
485 else { | |
486 Qt::CheckState checkedState = | |
487 mPreviouslyUnselected.contains(certificate.base64Line()) ? | |
488 Qt::Unchecked : Qt::Checked; | |
489 item->setFlags(item->flags() | Qt::ItemIsUserCheckable); | |
490 item->setCheckState(checkedState); | |
491 } | |
492 mCertListWidget->setItemDelegateForRow(index, certDelegate); | |
493 return item; | |
449 } | 494 } |
450 | 495 |
451 void MainWindow::showSettings() | 496 void MainWindow::showSettings() |
452 { | 497 { |
453 qDebug() << "show settingsdialog"; | 498 qDebug() << "show settingsdialog"; |
474 about->show(); | 519 about->show(); |
475 } | 520 } |
476 | 521 |
477 void MainWindow::showDetails(QListWidgetItem *item) | 522 void MainWindow::showDetails(QListWidgetItem *item) |
478 { | 523 { |
479 Certificate cert = item->data(CertificateItemDelegate::DetailsRole).value<Certificate>(); | 524 Certificate cert = item->data(CertificateItemDelegate::DataRole).value<Certificate>(); |
480 mSubjectCN->setText(cert.subjectCN()); | 525 mSubjectCN->setText(cert.subjectCN()); |
481 mSubjectOU->setText(cert.subjectOU()); | 526 mSubjectOU->setText(cert.subjectOU()); |
482 mIssuerCN->setText(cert.issuerCN()); | 527 mIssuerCN->setText(cert.issuerCN()); |
483 mIssuerOU->setText(cert.issuerO()); | 528 mIssuerOU->setText(cert.issuerO()); |
484 mValidFrom->setText(cert.validFrom().toString()); | 529 mValidFrom->setText(cert.validFrom().toString()); |
521 QStringList choices; | 566 QStringList choices; |
522 | 567 |
523 for (int i = 0; i < mCertListWidget->count(); i++) { | 568 for (int i = 0; i < mCertListWidget->count(); i++) { |
524 QListWidgetItem *item = mCertListWidget->item(i); | 569 QListWidgetItem *item = mCertListWidget->item(i); |
525 if (item->checkState() == Qt::Checked) { | 570 if (item->checkState() == Qt::Checked) { |
526 choices << item->data(CertificateItemDelegate::B64LineRole).toString(); | 571 choices << item->data(CertificateItemDelegate::DataRole).value<Certificate>().base64Line(); |
527 continue; | 572 continue; |
528 } | 573 } |
529 QString certLine = item->data(CertificateItemDelegate::B64LineRole).toString(); | 574 QString certLine = item->data(CertificateItemDelegate::DataRole).value<Certificate>().base64Line(); |
530 if (certLine.startsWith("I:")) { | 575 if (certLine.startsWith("I:")) { |
531 certLine[0] = 'R'; | 576 certLine[0] = 'R'; |
532 choices << certLine; | 577 choices << certLine; |
533 } | 578 } |
534 } | 579 } |
578 mSettings.remove(""); /* Clears old choices */ | 623 mSettings.remove(""); /* Clears old choices */ |
579 for (int i = 0; i < mCertListWidget->count(); i++) { | 624 for (int i = 0; i < mCertListWidget->count(); i++) { |
580 QListWidgetItem *item = mCertListWidget->item(i); | 625 QListWidgetItem *item = mCertListWidget->item(i); |
581 if (item->checkState() != Qt::Checked) { | 626 if (item->checkState() != Qt::Checked) { |
582 mSettings.setValue(QString::fromLatin1("cert%1").arg(i), | 627 mSettings.setValue(QString::fromLatin1("cert%1").arg(i), |
583 item->data(CertificateItemDelegate::B64LineRole).toString()); | 628 item->data(CertificateItemDelegate::DataRole).value<Certificate>().base64Line()); |
584 } | 629 } |
585 } | 630 } |
586 mSettings.endGroup(); | 631 mSettings.endGroup(); |
587 mSettings.sync(); | 632 mSettings.sync(); |
588 return mSettings.status() == QSettings::NoError; | 633 return mSettings.status() == QSettings::NoError; |