comparison ui/mainwindow.cpp @ 628:3a9c0f38bbad trustbridge-refactor

Made certificate lists member of mainwindow and added some temporary debug msgs.
author Raimund Renkert <rrenkert@intevation.de>
date Mon, 23 Jun 2014 12:49:09 +0200
parents ebfe1128ee97
children 626507197360
comparison
equal deleted inserted replaced
627:566ee111e331 628:3a9c0f38bbad
162 mSettings.remove("Software/availableDate"); 162 mSettings.remove("Software/availableDate");
163 } 163 }
164 } 164 }
165 165
166 void MainWindow::handleNewList(const QString& fileName, const QDateTime& modDate) { 166 void MainWindow::handleNewList(const QString& fileName, const QDateTime& modDate) {
167 qDebug() << "new list available";
167 mSettings.setValue("List/available", fileName); 168 mSettings.setValue("List/available", fileName);
168 mSettings.setValue("List/availableDate", modDate); 169 mSettings.setValue("List/availableDate", modDate);
169 170
170 verifyAvailableData(); 171 verifyAvailableData();
171 if (!mListToInstall.isValid()) { 172 if (!mListToInstall.isValid()) {
450 mUpdatesWidget = new QWidget; 451 mUpdatesWidget = new QWidget;
451 QHBoxLayout *updatesHeaderLayout = new QHBoxLayout; 452 QHBoxLayout *updatesHeaderLayout = new QHBoxLayout;
452 QVBoxLayout *updatesHeaderTextLayout = new QVBoxLayout; 453 QVBoxLayout *updatesHeaderTextLayout = new QVBoxLayout;
453 QVBoxLayout *updatesHeaderSettLayout = new QVBoxLayout; 454 QVBoxLayout *updatesHeaderSettLayout = new QVBoxLayout;
454 455
455 QLabel *updatesHeader = 456 mUpdatesHeader =
456 new QLabel("<h2>" + tr("Updates (%1/%2)").arg(2).arg(4)+ "</h2>"); 457 new QLabel("<h2>" + tr("Updates (%1/%2)").arg(2).arg(4)+ "</h2>");
457 QLabel *lastCertUpdate = 458 mLastCertUpdate =
458 new QLabel(tr("Last certificate update: %1").arg("today")); 459 new QLabel(tr("Last certificate update: %1").arg("today"));
459 QLabel *lastSWupdate = 460 mLastSWupdate =
460 new QLabel(tr("Last Software update: %1").arg("today")); 461 new QLabel(tr("Last Software update: %1").arg("today"));
461 updatesHeaderTextLayout->addWidget(updatesHeader); 462 updatesHeaderTextLayout->addWidget(mUpdatesHeader);
462 updatesHeaderTextLayout->addWidget(lastCertUpdate); 463 updatesHeaderTextLayout->addWidget(mLastCertUpdate);
463 updatesHeaderTextLayout->addWidget(lastSWupdate); 464 updatesHeaderTextLayout->addWidget(mLastSWupdate);
464 465
465 QPushButton *searchUpdates = new QPushButton(tr("Search for Updates")); 466 QPushButton *searchUpdates = new QPushButton(tr("Search for Updates"));
467 connect(searchUpdates, SIGNAL(clicked()), this, SLOT(checkUpdates()));
466 updatesHeaderSettLayout->insertStretch(0, 10); 468 updatesHeaderSettLayout->insertStretch(0, 10);
467 updatesHeaderSettLayout->addWidget(searchUpdates); 469 updatesHeaderSettLayout->addWidget(searchUpdates);
468 updatesHeaderLayout->addLayout(updatesHeaderTextLayout); 470 updatesHeaderLayout->addLayout(updatesHeaderTextLayout);
469 updatesHeaderLayout->insertStretch(1, 10); 471 updatesHeaderLayout->insertStretch(1, 10);
470 updatesHeaderLayout->addLayout(updatesHeaderSettLayout); 472 updatesHeaderLayout->addLayout(updatesHeaderSettLayout);
473 QHBoxLayout *updatesNewLayout = new QHBoxLayout; 475 QHBoxLayout *updatesNewLayout = new QHBoxLayout;
474 QHBoxLayout *updatesRemoveLayout = new QHBoxLayout; 476 QHBoxLayout *updatesRemoveLayout = new QHBoxLayout;
475 QHBoxLayout *updatesManualLayout = new QHBoxLayout; 477 QHBoxLayout *updatesManualLayout = new QHBoxLayout;
476 QLabel *updatesTip = 478 QLabel *updatesTip =
477 new QLabel(tr("The following certificate changes are recommended.")); 479 new QLabel(tr("The following certificate changes are recommended."));
478 QLabel *updatesNewCertificates = 480 mUpdatesNewCertificates =
479 new QLabel("<h3>" + 481 new QLabel("<h3>" +
480 tr("Install new Certificates (%1/%2)").arg(2).arg(2) + 482 tr("Install new Certificates (%1/%2)").arg(2).arg(2) +
481 "</h3>"); 483 "</h3>");
482 QPushButton *updatesDetailsNew = new QPushButton(tr("Details")); 484 QPushButton *updatesDetailsNew = new QPushButton(tr("Details"));
483 connect(updatesDetailsNew, 485 connect(updatesDetailsNew,
484 SIGNAL(clicked()), 486 SIGNAL(clicked()),
485 this, 487 this,
486 SLOT(toggleUpdatesNew())); 488 SLOT(toggleUpdatesNew()));
487 updatesNewLayout->addWidget(updatesNewCertificates); 489 updatesNewLayout->addWidget(mUpdatesNewCertificates);
488 updatesNewLayout->addWidget(updatesDetailsNew); 490 updatesNewLayout->addWidget(updatesDetailsNew);
489 updatesNewLayout->insertStretch(2, 10); 491 updatesNewLayout->insertStretch(2, 10);
490 mUpdatesNew = new CertificateListWidget(this); 492 mUpdatesNew = new CertificateListWidget(this);
493 connect(mUpdatesNew, SIGNAL(certListChanged(int)),
494 this, SLOT(listChanged(int)));
491 mUpdatesNew->hide(); 495 mUpdatesNew->hide();
492 496
493 QLabel *updatesRemoveCertificates = 497 mUpdatesRemoveCertificates =
494 new QLabel("<h3>" + 498 new QLabel("<h3>" +
495 tr("Remove insecure Certificates (%1/%2)").arg(2).arg(2) + 499 tr("Remove insecure Certificates (%1/%2)").arg(2).arg(2) +
496 "</h3>"); 500 "</h3>");
497 QPushButton *updatesDetailsRemove = new QPushButton(tr("Details")); 501 QPushButton *updatesDetailsRemove = new QPushButton(tr("Details"));
498 connect(updatesDetailsRemove, 502 connect(updatesDetailsRemove,
499 SIGNAL(clicked()), 503 SIGNAL(clicked()),
500 this, 504 this,
501 SLOT(toggleUpdatesRemove())); 505 SLOT(toggleUpdatesRemove()));
502 updatesRemoveLayout->addWidget(updatesRemoveCertificates); 506 updatesRemoveLayout->addWidget(mUpdatesRemoveCertificates);
503 updatesRemoveLayout->addWidget(updatesDetailsRemove); 507 updatesRemoveLayout->addWidget(updatesDetailsRemove);
504 updatesRemoveLayout->insertStretch(2, 10); 508 updatesRemoveLayout->insertStretch(2, 10);
505 mUpdatesRemove = new CertificateListWidget(this); 509 mUpdatesRemove = new CertificateListWidget(this);
506 mUpdatesRemove->hide(); 510 mUpdatesRemove->hide();
507 511
508 QLabel *updatesManualCertificates = 512 mUpdatesManualCertificates =
509 new QLabel("<h3>" + 513 new QLabel("<h3>" +
510 tr("Manualy changed Certificates (%1)").arg(2) + 514 tr("Manualy changed Certificates (%1)").arg(2) +
511 "</h3>"); 515 "</h3>");
512 QPushButton *updatesDetailsManual = new QPushButton(tr("Details")); 516 QPushButton *updatesDetailsManual = new QPushButton(tr("Details"));
513 connect(updatesDetailsManual, 517 connect(updatesDetailsManual,
514 SIGNAL(clicked()), 518 SIGNAL(clicked()),
515 this, 519 this,
516 SLOT(toggleUpdatesManual())); 520 SLOT(toggleUpdatesManual()));
517 updatesManualLayout->addWidget(updatesManualCertificates); 521 updatesManualLayout->addWidget(mUpdatesManualCertificates);
518 updatesManualLayout->addWidget(updatesDetailsManual); 522 updatesManualLayout->addWidget(updatesDetailsManual);
519 updatesManualLayout->insertStretch(2, 10); 523 updatesManualLayout->insertStretch(2, 10);
520 mUpdatesManual = new CertificateListWidget(this); 524 mUpdatesManual = new CertificateListWidget(this);
521 mUpdatesManual->hide(); 525 mUpdatesManual->hide();
522 526
530 534
531 QHBoxLayout *updatesBottomLayout = new QHBoxLayout; 535 QHBoxLayout *updatesBottomLayout = new QHBoxLayout;
532 quitButton = new QPushButton(tr("Quit without saving")); 536 quitButton = new QPushButton(tr("Quit without saving"));
533 QPushButton *saveButton = new QPushButton(tr("Update")); 537 QPushButton *saveButton = new QPushButton(tr("Update"));
534 connect(quitButton, SIGNAL(clicked()), this, SLOT(closeApp())); 538 connect(quitButton, SIGNAL(clicked()), this, SLOT(closeApp()));
539 connect(saveButton, SIGNAL(clicked()), this, SLOT(installCerts()));
535 updatesBottomLayout->insertStretch(0, 10); 540 updatesBottomLayout->insertStretch(0, 10);
536 updatesBottomLayout->addWidget(saveButton); 541 updatesBottomLayout->addWidget(saveButton);
537 updatesBottomLayout->addWidget(quitButton); 542 updatesBottomLayout->addWidget(quitButton);
538 543
539 QFrame *updatesPanelSeparator = new QFrame(); 544 QFrame *updatesPanelSeparator = new QFrame();
590 removeHeaderLayout->addWidget(removeHeaderText); 595 removeHeaderLayout->addWidget(removeHeaderText);
591 596
592 QLabel *removeCenterText = new QLabel(tr("Please choose the certificates" 597 QLabel *removeCenterText = new QLabel(tr("Please choose the certificates"
593 " you want to remove. TrustBridge will remove these certificates.")); 598 " you want to remove. TrustBridge will remove these certificates."));
594 removeCenterLayout->addWidget(removeCenterText); 599 removeCenterLayout->addWidget(removeCenterText);
600 mRemoveList = new CertificateListWidget(this);
595 601
596 removePanelLayout->addLayout(removeHeaderLayout); 602 removePanelLayout->addLayout(removeHeaderLayout);
597 removePanelLayout->addLayout(removeCenterLayout); 603 removePanelLayout->addLayout(removeCenterLayout);
604 removePanelLayout->addWidget(mRemoveList);
598 mRemovePanel->setLayout(removePanelLayout); 605 mRemovePanel->setLayout(removePanelLayout);
599 606
600 // Info panel. 607 // Info panel.
601 mInfoPanel = new QScrollArea; 608 mInfoPanel = new QScrollArea;
602 609
782 mainLayout->addLayout(bottomLayout); 789 mainLayout->addLayout(bottomLayout);
783 base->setLayout(mainLayout); 790 base->setLayout(mainLayout);
784 setCentralWidget(base); 791 setCentralWidget(base);
785 } 792 }
786 793
794 void MainWindow::listChanged(int selected)
795 {
796 mUpdatesHeader->setText("<h2>" + tr("Updates (%1/%2)")
797 .arg(mUpdatesRemove->selectedCertCount() + mUpdatesNew->selectedCertCount())
798 .arg(mUpdatesRemove->certificates().size() + mUpdatesNew->certificates().size()) +
799 "</h2>");
800 mUpdatesNewCertificates->setText("<h3>" +
801 tr("Install new Certificates (%1/%2)")
802 .arg(mUpdatesNew->selectedCertCount())
803 .arg(mUpdatesNew->certificates().size()) +
804 "</h3>");
805 mUpdatesRemoveCertificates->setText("<h3>" +
806 tr("Remove insecure Certificates (%1/%2)")
807 .arg(mUpdatesRemove->selectedCertCount())
808 .arg(mUpdatesRemove->certificates().size()) +
809 "</h3>");
810 }
811
787 void MainWindow::loadCertificateList() 812 void MainWindow::loadCertificateList()
788 { 813 {
789 //mCertListWidget->clear(); 814 //mCertListWidget->clear();
790 //int i = 0; 815 //int i = 0;
791 816
817 qDebug() << "loading list";
792 /* TODO: if nothing is available (neither old nor new) add some progress 818 /* TODO: if nothing is available (neither old nor new) add some progress
793 * indication */ 819 * indication */
820 mInstallList->clear();
821 mUpdatesNew->clear();
822 mRemoveList->clear();
823 mUpdatesRemove->clear();
794 QList<Certificate> newInstallCerts; 824 QList<Certificate> newInstallCerts;
795 QList<Certificate> newRemoveCerts; 825 QList<Certificate> newRemoveCerts;
796 QList<Certificate> oldInstallCerts; 826 QList<Certificate> oldInstallCerts;
797 QList<Certificate> oldRemoveCerts; 827 QList<Certificate> oldRemoveCerts;
798 828
799 if (mListToInstall.getCertificates().isEmpty()) { 829 if (mListToInstall.getCertificates().isEmpty()) {
800 // No new list available, add old certificates. 830 // No new list available, add old certificates.
831 qDebug() << "no new list...";
801 foreach (const Certificate &cert, mInstalledList.getCertificates()) { 832 foreach (const Certificate &cert, mInstalledList.getCertificates()) {
802 if (cert.isInstallCert()) { 833 if (cert.isInstallCert()) {
803 oldInstallCerts.append(cert); 834 oldInstallCerts.append(cert);
804 mInstallList->addCertificate(cert); 835 mInstallList->addCertificate(cert);
805 } 836 }
806 else { 837 else {
807 oldRemoveCerts.append(cert); 838 oldRemoveCerts.append(cert);
839 mRemoveList->addCertificate(cert);
808 } 840 }
809 } 841 }
842 qDebug() << "old list date: " << mInstalledList.date().toString();
810 // Set the date of the old list. 843 // Set the date of the old list.
811 mCurrentListDate->setText(tr("Current List Date: %1") 844 // mCurrentListDate->setText(tr("Current List Date: %1")
812 .arg(mInstalledList.date().toString())); 845 // .arg(mInstalledList.date().toString()));
813 } 846 }
814 else { 847 else {
848 qDebug() << "new list available";
815 // Sort and filter both lists. 849 // Sort and filter both lists.
816 foreach (const Certificate &cert, mListToInstall.getCertificates()) { 850 foreach (const Certificate &cert, mListToInstall.getCertificates()) {
817 if (cert.isInstallCert()) { 851 if (cert.isInstallCert()) {
818 // Certificate with status "install". 852 // Certificate with status "install".
819 if (mInstalledList.getCertificates().contains(cert)) { 853 if (mInstalledList.getCertificates().contains(cert)) {
820 // Was in the old list. 854 // Was in the old list.
821 oldInstallCerts.append(cert); 855 oldInstallCerts.append(cert);
856 qDebug() << "add install";
857 mInstallList->addCertificate(cert);
822 } 858 }
823 else { 859 else {
824 // Is a brand new certificate 860 // Is a brand new certificate
825 newInstallCerts.append(cert); 861 newInstallCerts.append(cert);
862 qDebug() << "add new install";
826 mUpdatesNew->addCertificate(cert); 863 mUpdatesNew->addCertificate(cert);
827 } 864 }
828 } 865 }
829 else { 866 else {
830 // Certificate with status "remove". 867 // Certificate with status "remove".
831 if (mInstalledList.getCertificates().contains(cert)) { 868 if (mInstalledList.getCertificates().contains(cert)) {
832 // Was in the old list. 869 // Was in the old list.
833 oldRemoveCerts.append(cert); 870 oldRemoveCerts.append(cert);
871 qDebug() << "add remove";
872 mRemoveList->addCertificate(cert);
834 } 873 }
835 else { 874 else {
836 // Was in the old list with status "install" and now has the 875 // Was in the old list with status "install" and now has the
837 // status "remove". 876 // status "remove".
838 newRemoveCerts.append(cert); 877 newRemoveCerts.append(cert);
878 qDebug() << "add new remove";
879 mUpdatesRemove->addCertificate(cert);
839 } 880 }
840 } 881 }
841 } 882 }
883 mUpdatesHeader->setText("<h2>" +
884 tr("Updates (%1/%2)")
885 .arg(newRemoveCerts.size() + newInstallCerts.size())
886 .arg(newRemoveCerts.size() + newInstallCerts.size()) + "</h2>");
887 mLastCertUpdate->setText(tr("Last certificate update: %1")
888 .arg(mInstalledList.date().toString()));
842 /* mCurrentListDate->setText(tr("Current List Date: %1") 889 /* mCurrentListDate->setText(tr("Current List Date: %1")
843 .arg(mInstalledList.date().toString())); 890 .arg(mInstalledList.date().toString()));
844 mNewListDate->setText(tr("New List Date: %1").arg(mListToInstall.date().toString()));*/ 891 mNewListDate->setText(tr("New List Date: %1").arg(mListToInstall.date().toString()));*/
845 } 892 }
893 mUpdatesNewCertificates->setText("<h3>" +
894 tr("Install new Certificates (%1/%2)")
895 .arg(mUpdatesNew->selectedCertCount())
896 .arg(mUpdatesNew->certificates().size()) +
897 "</h3>");
898
899 mUpdatesRemoveCertificates->setText("<h3>" +
900 tr("Remove insecure Certificates (%1/%2)")
901 .arg(mUpdatesRemove->selectedCertCount())
902 .arg(mUpdatesRemove->certificates().size()) +
903 "</h3>");
904 mUpdatesManualCertificates->setText("<h3>" +
905 tr("Manualy changed Certificates (%1)").arg(0) +
906 "</h3>");
846 /* 907 /*
847 // Add separators and certificates to list widget. 908 // Add separators and certificates to list widget.
848 if (!newInstallCerts.isEmpty()) { 909 if (!newInstallCerts.isEmpty()) {
849 mCertListWidget->addItem(createSeparator(tr("New certificates to install"), i++)); 910 mCertListWidget->addItem(createSeparator(tr("New certificates to install"), i++));
850 foreach (const Certificate &cert, newInstallCerts) { 911 foreach (const Certificate &cert, newInstallCerts) {
965 mSettings.setValue("List/installed", listFileName); 1026 mSettings.setValue("List/installed", listFileName);
966 mSettings.setValue("List/installedDate", listFileDate); 1027 mSettings.setValue("List/installedDate", listFileDate);
967 mInstalledList = mListToInstall; 1028 mInstalledList = mListToInstall;
968 mListToInstall = CertificateList(); 1029 mListToInstall = CertificateList();
969 } 1030 }
970 //loadCertificateList(); 1031 loadCertificateList();
971 } 1032 }
972 1033
973 void MainWindow::installCerts() { 1034 void MainWindow::installCerts() {
974 QStringList choices; 1035 QStringList choices;
975 1036
976 for (int i = 0; i < mCertListWidget->count(); i++) { 1037 choices << mUpdatesNew->certificates();
1038 choices << mUpdatesRemove->certificates();
1039 choices << mUpdatesManual->certificates();
1040
1041 /* for (int i = 0; i < mCertListWidget->count(); i++) {
977 QListWidgetItem *item = mCertListWidget->item(i); 1042 QListWidgetItem *item = mCertListWidget->item(i);
978 if (item->checkState() == Qt::Checked) { 1043 if (item->checkState() == Qt::Checked) {
979 choices << item->data(CertificateItemDelegate::DataRole).value<Certificate>().base64Line(); 1044 choices << item->data(CertificateItemDelegate::DataRole).value<Certificate>().base64Line();
980 continue; 1045 continue;
981 } 1046 }
983 if (certLine.startsWith("I:")) { 1048 if (certLine.startsWith("I:")) {
984 certLine[0] = 'R'; 1049 certLine[0] = 'R';
985 choices << certLine; 1050 choices << certLine;
986 } 1051 }
987 } 1052 }
988 1053 */
989 QProgressDialog *progress = new QProgressDialog(this); 1054 QProgressDialog *progress = new QProgressDialog(this);
990 progress->setWindowModality(Qt::WindowModal); 1055 progress->setWindowModality(Qt::WindowModal);
991 progress->setLabelText(tr("Installing certificates...")); 1056 progress->setLabelText(tr("Installing certificates..."));
992 progress->setCancelButton(0); 1057 progress->setCancelButton(0);
993 progress->setRange(0,0); 1058 progress->setRange(0,0);

http://wald.intevation.org/projects/trustbridge/