comparison ui/mainwindow.cpp @ 377:e3f825a7257e

merged.
author Raimund Renkert <rrenkert@intevation.de>
date Tue, 15 Apr 2014 12:34:04 +0200
parents 9e38a4bcd44e
children 3be838c3e4d8
comparison
equal deleted inserted replaced
376:9731d28b95af 377:e3f825a7257e
54 mMessageTimer->start(); 54 mMessageTimer->start();
55 checkUpdates(); 55 checkUpdates();
56 if (!trayMode) { 56 if (!trayMode) {
57 show(); 57 show();
58 } 58 }
59 loadUnselectedCertificates();
59 } 60 }
60 61
61 void MainWindow::iconActivated(QSystemTrayIcon::ActivationReason reason) 62 void MainWindow::iconActivated(QSystemTrayIcon::ActivationReason reason)
62 { 63 {
63 switch (reason) { 64 switch (reason) {
314 setCentralWidget(base); 315 setCentralWidget(base);
315 } 316 }
316 317
317 void MainWindow::loadCertificateList() 318 void MainWindow::loadCertificateList()
318 { 319 {
319 qDebug() << "display certificates";
320 mCertListWidget->clear(); 320 mCertListWidget->clear();
321 int i = 0; 321 int i = 0;
322 foreach (const Certificate &cert, mListToInstall.getCertificates()) { 322 foreach (const Certificate &cert, mListToInstall.getCertificates()) {
323 if (!cert.isValid()) { 323 if (!cert.isValid()) {
324 qWarning() << "Invalid certificate in list"; 324 qWarning() << "Invalid certificate in list";
325 continue; 325 continue;
326 } 326 }
327 QListWidgetItem* item = new QListWidgetItem(cert.shortDescription()); 327 QListWidgetItem* item = new QListWidgetItem(cert.shortDescription());
328 SeparatorItemDelegate *separator = new SeparatorItemDelegate(); 328 SeparatorItemDelegate *separator = new SeparatorItemDelegate();
329 item->setData(Qt::UserRole, cert.details()); 329 item->setData(CertificateItemDelegate::DetailsRole, cert.details());
330 item->setData(CertificateItemDelegate::B64LineRole, cert.base64Line());
331 Qt::CheckState checkedState = mPreviouslyUnselected.contains(cert.base64Line()) ?
332 Qt::Unchecked : Qt::Checked;
330 if (cert.isInstallCert()) { 333 if (cert.isInstallCert()) {
331 // This if statements is for testing! @TODO Remove this! 334 // This if statements is for testing! @TODO Remove this!
332 if (i <= 2) { 335 if (i <= 2) {
333 item->setData(Qt::UserRole + 1, Certificate::InstallOld); 336 item->setData(CertificateItemDelegate::StatusRole, Certificate::InstallOld);
334 item->setFlags(item->flags() | Qt::ItemIsUserCheckable); 337 item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
335 item->setCheckState(Qt::Checked);
336 } 338 }
337 else { 339 else {
338 item->setData(Qt::UserRole + 1, Certificate::InstallNew); 340 item->setData(CertificateItemDelegate::StatusRole, Certificate::InstallNew);
339 item->setFlags(item->flags() | Qt::ItemIsUserCheckable); 341 item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
340 item->setCheckState(Qt::Checked);
341 } 342 }
342 if (i == 3) { 343 if (i == 3) {
343 QListWidgetItem *sep = new QListWidgetItem("New certificates"); 344 QListWidgetItem *sep = new QListWidgetItem("New certificates");
344 mCertListWidget->setItemDelegateForRow(i, separator); 345 mCertListWidget->setItemDelegateForRow(i, separator);
345 mCertListWidget->addItem(sep); 346 mCertListWidget->addItem(sep);
346 i++; 347 i++;
347 } 348 }
349 item->setCheckState(checkedState);
348 } 350 }
349 else { 351 else {
350 // This if statements is for testing! @TODO Remove this! 352 // This if statements is for testing! @TODO Remove this!
351 if (i > 35) { 353 if (i > 35) {
352 item->setData(Qt::UserRole + 1, Certificate::RemoveNew); 354 item->setData(CertificateItemDelegate::StatusRole, Certificate::RemoveNew);
353 item->setFlags(item->flags() | Qt::ItemIsUserCheckable); 355 item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
354 item->setCheckState(Qt::Checked); 356 item->setCheckState(checkedState);
355 } 357 }
356 else { 358 else {
357 item->setData(Qt::UserRole + 1, Certificate::RemoveOld); 359 item->setData(CertificateItemDelegate::StatusRole, Certificate::RemoveOld);
358 item->setFlags(item->flags() | Qt::ItemIsUserCheckable); 360 item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
359 } 361 }
360 } 362 }
361 mCertListWidget->addItem(item); 363 mCertListWidget->addItem(item);
362 i++; 364 i++;
389 about->show(); 391 about->show();
390 } 392 }
391 393
392 void MainWindow::showDetails(QListWidgetItem *item) 394 void MainWindow::showDetails(QListWidgetItem *item)
393 { 395 {
394 QString details = item->data(Qt::UserRole).toString(); 396 QString details = item->data(CertificateItemDelegate::DetailsRole).toString();
395 certificateDetails->setPlainText(details); 397 certificateDetails->setPlainText(details);
396 } 398 }
397 399
398 void MainWindow::resizeButtons() 400 void MainWindow::resizeButtons()
399 { 401 {
409 QStringList choices; 411 QStringList choices;
410 412
411 for (int i = 0; i < mCertListWidget->count(); i++) { 413 for (int i = 0; i < mCertListWidget->count(); i++) {
412 QListWidgetItem *item = mCertListWidget->item(i); 414 QListWidgetItem *item = mCertListWidget->item(i);
413 if (item->checkState() == Qt::Checked) { 415 if (item->checkState() == Qt::Checked) {
414 choices << item->data(Qt::UserRole).toString(); 416 choices << item->data(CertificateItemDelegate::B64LineRole).toString();
415 continue; 417 continue;
416 } 418 }
417 QString certLine = item->data(Qt::UserRole).toString(); 419 QString certLine = item->data(CertificateItemDelegate::B64LineRole).toString();
418 if (certLine.startsWith("I:")) { 420 if (certLine.startsWith("I:")) {
419 certLine[0] = 'R'; 421 certLine[0] = 'R';
420 choices << certLine; 422 choices << certLine;
421 } 423 }
422 } 424 }
438 connect(instWrap, SIGNAL(finished()), progress, SLOT(cancel())); 440 connect(instWrap, SIGNAL(finished()), progress, SLOT(cancel()));
439 connect(instWrap, SIGNAL(error(const QString &)), 441 connect(instWrap, SIGNAL(error(const QString &)),
440 this, SLOT(installerError(const QString &))); 442 this, SLOT(installerError(const QString &)));
441 instWrap->start(); 443 instWrap->start();
442 444
443 } 445 if (!saveUnselectedCertificates()) {
446 qWarning() << "Failed to save previosly unselected certificates.";
447 }
448 }
449
450 void MainWindow::loadUnselectedCertificates()
451 {
452 mPreviouslyUnselected.clear();
453 mSettings.beginGroup("unselected");
454 QStringList keys = mSettings.allKeys();
455 foreach (const QString &key, keys) {
456 mPreviouslyUnselected << mSettings.value(key, QString()).toString();
457 }
458 mSettings.endGroup();
459 }
460
461 bool MainWindow::saveUnselectedCertificates()
462 {
463 mSettings.beginGroup("unselected");
464 mSettings.remove(""); /* Clears old choices */
465 for (int i = 0; i < mCertListWidget->count(); i++) {
466 QListWidgetItem *item = mCertListWidget->item(i);
467 if (item->checkState() != Qt::Checked) {
468 mSettings.setValue(QString::fromLatin1("cert%1").arg(i),
469 item->data(CertificateItemDelegate::B64LineRole).toString());
470 }
471 }
472 mSettings.endGroup();
473 mSettings.sync();
474 return mSettings.status() == QSettings::NoError;
475 }

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