comparison ui/mainwindow.cpp @ 641:a7c3ab273d41 trustbridge-refactor

Some code cleanup.
author Raimund Renkert <rrenkert@intevation.de>
date Tue, 24 Jun 2014 17:40:40 +0200
parents 626507197360
children dd738ef17715
comparison
equal deleted inserted replaced
640:626507197360 641:a7c3ab273d41
528 mUpdatesManual->hide(); 528 mUpdatesManual->hide();
529 connect(mUpdatesManual, SIGNAL(certChanged(bool, const Certificate&)), 529 connect(mUpdatesManual, SIGNAL(certChanged(bool, const Certificate&)),
530 this, SLOT(removeFromManual(bool, const Certificate&))); 530 this, SLOT(removeFromManual(bool, const Certificate&)));
531 531
532 QHBoxLayout *updatesBottomLayout = new QHBoxLayout; 532 QHBoxLayout *updatesBottomLayout = new QHBoxLayout;
533 quitButton = new QPushButton(tr("Quit without saving")); 533 QPushButton *quitButton = new QPushButton(tr("Quit without saving"));
534 QPushButton *saveButton = new QPushButton(tr("Update")); 534 QPushButton *installButton = new QPushButton(tr("Update"));
535 #ifdef Q_OS_WIN
536 if (is_admin()) {
537 QIcon uacShield = QApplication::style()->standardIcon(QStyle::SP_VistaShield);
538 installButton->setIcon(uacShield);
539 }
540 #endif
535 connect(quitButton, SIGNAL(clicked()), this, SLOT(closeApp())); 541 connect(quitButton, SIGNAL(clicked()), this, SLOT(closeApp()));
536 connect(saveButton, SIGNAL(clicked()), this, SLOT(installCerts())); 542 connect(installButton, SIGNAL(clicked()), this, SLOT(installCerts()));
537 updatesBottomLayout->insertStretch(0, 10); 543 updatesBottomLayout->insertStretch(0, 10);
538 updatesBottomLayout->addWidget(saveButton); 544 updatesBottomLayout->addWidget(installButton);
539 updatesBottomLayout->addWidget(quitButton); 545 updatesBottomLayout->addWidget(quitButton);
540 updatesBottomLayout->setAlignment(Qt::AlignBottom); 546 updatesBottomLayout->setAlignment(Qt::AlignBottom);
541 547
542 updatesNewLayout->setAlignment(Qt::AlignTop); 548 updatesNewLayout->setAlignment(Qt::AlignTop);
543 updatesRemoveLayout->setAlignment(Qt::AlignTop); 549 updatesRemoveLayout->setAlignment(Qt::AlignTop);
703 containerLayout->addWidget(mInfoPanel); 709 containerLayout->addWidget(mInfoPanel);
704 710
705 centerLayout->addLayout(buttonBarLayout); 711 centerLayout->addLayout(buttonBarLayout);
706 centerLayout->addLayout(containerLayout); 712 centerLayout->addLayout(containerLayout);
707 713
708
709 /*
710 // The certificate list
711 QGroupBox *certBox = new QGroupBox(tr("Managed Certificates"));
712 mCertListWidget = new QListWidget;
713 connect(mCertListWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
714 this, SLOT(showDetails(QListWidgetItem*)));
715 certLayout->addWidget(mCertListWidget);
716
717 mCurrentListDate = new QLabel(tr("Current List Date: %1").arg(""));
718 mNewListDate = new QLabel("");
719 listInfoLayout->addWidget(mCurrentListDate);
720 listInfoLayout->addWidget(mNewListDate);
721 certLayout->addLayout(listInfoLayout);
722
723 certBox->setLayout(certLayout);
724
725
726 // The settings.
727 QGroupBox *settingsBox = new QGroupBox(tr("Settings"));
728 mAutoUpdateOption = new QCheckBox(tr("Autoupdate"));
729 mAutoStartOption = new QCheckBox(tr("Autostart"));
730 settingsLayout->addWidget(mAutoUpdateOption);
731 settingsLayout->addWidget(mAutoStartOption);
732 settingsBox->setLayout(settingsLayout);
733 connect(mAutoUpdateOption, SIGNAL(stateChanged(int)),
734 this, SLOT(saveAutoUpdate(int)));
735 connect(mAutoStartOption, SIGNAL(stateChanged(int)),
736 this, SLOT(saveAutoStart(int)));
737 mSettings.beginGroup("settings");
738 bool autoUpdate = mSettings.value("autoupdate", false).toBool();
739 bool autoStart = mSettings.value("autostart", true).toBool();
740 mSettings.endGroup();
741 mAutoUpdateOption->setCheckState(autoUpdate ? Qt::Checked : Qt::Unchecked);
742 mAutoStartOption->setCheckState(autoStart ? Qt::Checked : Qt::Unchecked);
743
744
745 #ifdef Q_OS_WIN
746 if (is_admin()) {
747 QIcon uacShield = QApplication::style()->standardIcon(QStyle::SP_VistaShield);
748 installButton->setIcon(uacShield);
749 }
750 #endif
751
752 // The certificate details
753 QGroupBox *detailBox = new QGroupBox(tr("Details"));
754 QLabel *subjectCN = new QLabel(tr("Subject Common Name:"));
755 QLabel *subjectOU = new QLabel(tr("Subject Organisation:"));
756 QLabel *issuerCN = new QLabel(tr("Issuer Common Name:"));
757 QLabel *issuerOU = new QLabel(tr("Issuer Organisation:"));
758 QLabel *validFrom = new QLabel(tr("Valid from:"));
759 QLabel *validTo = new QLabel(tr("Valid to:"));
760 QLabel *fingerprint = new QLabel(tr("Fingerprint:"));
761 detailLabelLayout->addWidget(subjectCN);
762 detailLabelLayout->addWidget(subjectOU);
763 detailLabelLayout->addWidget(issuerCN);
764 detailLabelLayout->addWidget(issuerOU);
765 detailLabelLayout->addWidget(validFrom);
766 detailLabelLayout->addWidget(validTo);
767 detailLabelLayout->addWidget(fingerprint);
768 mSubjectCN = new QLabel(tr(""));
769 mSubjectO = new QLabel(tr(""));
770 mIssuerCN = new QLabel(tr(""));
771 mIssuerO = new QLabel(tr(""));
772 mValidFrom = new QLabel(tr(""));
773 mValidTo = new QLabel(tr(""));
774 mFingerprint = new QLabel(tr(""));
775 mFingerprint->setFont(QFont("DejaVu Sans Mono"));
776 detailContentLayout->addWidget(mSubjectCN);
777 detailContentLayout->addWidget(mSubjectO);
778 detailContentLayout->addWidget(mIssuerCN);
779 detailContentLayout->addWidget(mIssuerO);
780 detailContentLayout->addWidget(mValidFrom);
781 detailContentLayout->addWidget(mValidTo);
782 detailContentLayout->addWidget(mFingerprint);
783 detailLayout->addLayout(detailLabelLayout);
784 detailLayout->addLayout(detailContentLayout);
785 detailBox->setLayout(detailLayout);
786
787 infoLayout->addSpacing(20);
788 infoLayout->addLayout(headerLayout);
789 //infoLayout->addWidget(detailBox);
790 //infoLayout->addWidget(settingsBox);
791 infoLayout->addLayout(bottomLayout);
792
793 //mainLayout->addWidget(certBox);
794 mainLayout->addLayout(infoLayout);
795 mainLayout->setStretchFactor(certBox, 37);
796 mainLayout->setStretchFactor(infoLayout, 63);
797
798 // QMainWindow allready has a layout. All child layouts and widgets are
799 // managed in the central widget.
800 */
801
802 QFrame *topSeparator = new QFrame(); 714 QFrame *topSeparator = new QFrame();
803 topSeparator->setFrameShape(QFrame::HLine); 715 topSeparator->setFrameShape(QFrame::HLine);
804 topSeparator->setFrameShadow(QFrame::Sunken); 716 topSeparator->setFrameShadow(QFrame::Sunken);
805 717
806 mainLayout->addLayout(headerLayout); 718 mainLayout->addLayout(headerLayout);
829 "</h3>"); 741 "</h3>");
830 } 742 }
831 743
832 void MainWindow::loadCertificateList() 744 void MainWindow::loadCertificateList()
833 { 745 {
834 //mCertListWidget->clear();
835 //int i = 0;
836
837 /* TODO: if nothing is available (neither old nor new) add some progress 746 /* TODO: if nothing is available (neither old nor new) add some progress
838 * indication */ 747 * indication */
839 mInstallList->clear(); 748 mInstallList->clear();
840 mUpdatesNew->clear(); 749 mUpdatesNew->clear();
841 mRemoveList->clear(); 750 mRemoveList->clear();
917 .arg(mUpdatesRemove->certificates().size()) + 826 .arg(mUpdatesRemove->certificates().size()) +
918 "</h3>"); 827 "</h3>");
919 mUpdatesManualCertificates->setText("<h3>" + 828 mUpdatesManualCertificates->setText("<h3>" +
920 tr("Manualy changed Certificates (%1)").arg(0) + 829 tr("Manualy changed Certificates (%1)").arg(0) +
921 "</h3>"); 830 "</h3>");
922 /*
923 // Add separators and certificates to list widget.
924 if (!newInstallCerts.isEmpty()) {
925 mCertListWidget->addItem(createSeparator(tr("New certificates to install"), i++));
926 foreach (const Certificate &cert, newInstallCerts) {
927 mCertListWidget->addItem(createListItem(cert, Certificate::InstallNew, i++));
928 }
929 }
930
931 if (!newRemoveCerts.isEmpty()) {
932 mCertListWidget->addItem(createSeparator(tr("New certificates to remove"), i++));
933 foreach (const Certificate &cert, newRemoveCerts) {
934 mCertListWidget->addItem(createListItem(cert, Certificate::RemoveNew, i++));
935 }
936 }
937
938 if (!oldInstallCerts.isEmpty()) {
939 mCertListWidget->addItem(createSeparator(tr("Old certificates to install"), i++));
940 foreach (const Certificate &cert, oldInstallCerts) {
941 mCertListWidget->addItem(createListItem(cert, Certificate::InstallOld, i++));
942 }
943 }
944
945 if (!oldRemoveCerts.isEmpty()) {
946 mCertListWidget->addItem(createSeparator(tr("Old certificates to remove"), i++));
947 foreach (const Certificate &cert, oldRemoveCerts) {
948 mCertListWidget->addItem(createListItem(cert, Certificate::RemoveOld, i++));
949 }
950 }
951 */
952 }
953
954 QListWidgetItem* MainWindow::createSeparator(const QString &text, int index)
955 {
956 SeparatorItemDelegate *separatorDelegate = new SeparatorItemDelegate();
957 QListWidgetItem *separator = new QListWidgetItem(text);
958 mCertListWidget->setItemDelegateForRow(index, separatorDelegate);
959 separator->setFlags(separator->flags() ^ Qt::ItemIsUserCheckable);
960 return separator;
961 }
962
963 QListWidgetItem* MainWindow::createListItem(const Certificate &certificate,
964 Certificate::Status status, int index)
965 {
966 CertificateItemDelegate *certDelegate = new CertificateItemDelegate();
967 QListWidgetItem* item = new QListWidgetItem(certificate.shortDescription());
968 item->setData(CertificateItemDelegate::DataRole,
969 QVariant::fromValue(certificate));
970 item->setData(CertificateItemDelegate::StatusRole, status);
971 if (!mPreviouslyUnselected.contains(certificate.base64Line()) &&
972 status == Certificate::RemoveOld) {
973 item->setFlags(item->flags() ^ Qt::ItemIsUserCheckable);
974 }
975 else {
976 Qt::CheckState checkedState =
977 mPreviouslyUnselected.contains(certificate.base64Line()) ?
978 Qt::Unchecked : Qt::Checked;
979 item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
980 item->setCheckState(checkedState);
981 }
982 mCertListWidget->setItemDelegateForRow(index, certDelegate);
983 return item;
984 }
985
986 void MainWindow::showHelp()
987 {
988 qDebug() << "show helpdialog";
989 HelpDialog *help = new HelpDialog(this);
990 help->show();
991 }
992
993 void MainWindow::showAbout()
994 {
995 qDebug() << "show aboutdialog";
996 AboutDialog *about = new AboutDialog(this);
997 about->show();
998 }
999
1000 void MainWindow::showDetails(QListWidgetItem *item)
1001 {
1002 if (item == NULL) {
1003 return;
1004 }
1005 Certificate cert = item->data(CertificateItemDelegate::DataRole).value<Certificate>();
1006 mSubjectCN->setText(cert.subjectCN());
1007 mSubjectO->setText(cert.subjectO());
1008 mIssuerCN->setText(cert.issuerCN());
1009 mIssuerO->setText(cert.issuerO());
1010 mValidFrom->setText(cert.validFrom().toString());
1011 mValidTo->setText(cert.validTo().toString());
1012 mFingerprint->setText(cert.fingerprint());
1013 }
1014
1015 void MainWindow::resizeButtons()
1016 {
1017 installButton->setFixedHeight(20);
1018 quitButton->setFixedHeight(80);
1019 } 831 }
1020 832
1021 void MainWindow::installerError(const QString& errMsg) { 833 void MainWindow::installerError(const QString& errMsg) {
1022 QMessageBox::warning(this, tr("Error executing update"), errMsg); 834 QMessageBox::warning(this, tr("Error executing update"), errMsg);
1023 } 835 }
1066 unselected << mUpdatesNew->unselectedCertificates(); 878 unselected << mUpdatesNew->unselectedCertificates();
1067 unselected << mUpdatesRemove->unselectedCertificates(); 879 unselected << mUpdatesRemove->unselectedCertificates();
1068 unselected << mInstallList->unselectedCertificates(); 880 unselected << mInstallList->unselectedCertificates();
1069 unselected << mRemoveList->unselectedCertificates(); 881 unselected << mRemoveList->unselectedCertificates();
1070 882
1071 /* for (int i = 0; i < mCertListWidget->count(); i++) {
1072 QListWidgetItem *item = mCertListWidget->item(i);
1073 if (item->checkState() == Qt::Checked) {
1074 choices << item->data(CertificateItemDelegate::DataRole).value<Certificate>().base64Line();
1075 continue;
1076 }
1077 QString certLine = item->data(CertificateItemDelegate::DataRole).value<Certificate>().base64Line();
1078 if (certLine.startsWith("I:")) {
1079 certLine[0] = 'R';
1080 choices << certLine;
1081 }
1082 }
1083 */
1084 QProgressDialog *progress = new QProgressDialog(this); 883 QProgressDialog *progress = new QProgressDialog(this);
1085 progress->setWindowModality(Qt::WindowModal); 884 progress->setWindowModality(Qt::WindowModal);
1086 progress->setLabelText(tr("Installing certificates...")); 885 progress->setLabelText(tr("Installing certificates..."));
1087 progress->setCancelButton(0); 886 progress->setCancelButton(0);
1088 progress->setRange(0,0); 887 progress->setRange(0,0);
1135 mSettings.endGroup(); 934 mSettings.endGroup();
1136 mSettings.sync(); 935 mSettings.sync();
1137 return mSettings.status() == QSettings::NoError; 936 return mSettings.status() == QSettings::NoError;
1138 } 937 }
1139 938
1140 void MainWindow::saveAutoUpdate(int state)
1141 {
1142 mSettings.beginGroup("settings");
1143 mSettings.setValue("autoupdate", state != Qt::Unchecked);
1144 mSettings.endGroup();
1145 }
1146
1147 void MainWindow::saveAutoStart(int state)
1148 {
1149 mSettings.beginGroup("settings");
1150 mSettings.setValue("autostart", state != Qt::Unchecked);
1151 mSettings.endGroup();
1152 }
1153
1154 void MainWindow::toggleInManual(bool state, const Certificate &cert) 939 void MainWindow::toggleInManual(bool state, const Certificate &cert)
1155 { 940 {
1156 if (!mUpdatesManual->contains(cert)) { 941 if (!mUpdatesManual->contains(cert)) {
1157 mUpdatesManual->addCertificate(cert, state); 942 mUpdatesManual->addCertificate(cert, state);
1158 } 943 }

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