@@ -131,6 +131,7 @@ MainWindow::MainWindow( QWidget *parent )
131131
132132MainWindow::~MainWindow ()
133133{
134+ digiDoc.reset ();
134135 cryptoDoc.reset ();
135136 delete ui;
136137}
@@ -167,7 +168,7 @@ void MainWindow::changeEvent(QEvent* event)
167168void MainWindow::closeEvent (QCloseEvent * /* event*/ )
168169{
169170 cryptoDoc.reset ();
170- resetDigiDoc ();
171+ resetDigiDoc ({} );
171172 ui->startScreen ->setCurrentIndex (SignIntro);
172173}
173174
@@ -248,15 +249,17 @@ bool MainWindow::encrypt()
248249 if (!cryptoDoc)
249250 return false ;
250251
251- if (!FileDialog::fileIsWritable (cryptoDoc->fileName ())) {
252+ while (!FileDialog::fileIsWritable (cryptoDoc->fileName ()))
253+ {
252254 auto *dlg = new WarningDialog (tr (" Cannot alter container %1. Save different location?" )
253255 .arg (FileDialog::normalized (cryptoDoc->fileName ())), this );
254256 dlg->addButton (WarningDialog::YES, QMessageBox::Yes);
255- if (dlg->exec () == QMessageBox::Yes) {
256- moveCryptoContainer ();
257- return encrypt ();
258- }
259- return false ;
257+ if (dlg->exec () != QMessageBox::Yes)
258+ return false ;
259+ QString to = FileDialog::getSaveFileName (this , FileDialog::tr (" Save file" ), cryptoDoc->fileName ());
260+ if (to.isNull () || !cryptoDoc->move (to))
261+ return false ;
262+ ui->cryptoContainerPage ->setHeader (to);
260263 }
261264
262265 WaitDialogHolder waitDialog (this , tr (" Encrypting" ));
@@ -296,8 +299,8 @@ void MainWindow::navigateToPage( Pages page, const QStringList &files, bool crea
296299 navigate = signatureContainer->open (files[0 ]);
297300 if (navigate)
298301 {
299- resetDigiDoc (signatureContainer. release ( ));
300- ui->signContainerPage ->transition (digiDoc);
302+ resetDigiDoc (std::move (signatureContainer ));
303+ ui->signContainerPage ->transition (digiDoc. get () );
301304 }
302305 }
303306 else if (page == CryptoDetails)
@@ -358,9 +361,10 @@ void MainWindow::onSignAction(int action, const QString &idCode, const QString &
358361 case ClearSignatureWarning:
359362 ui->signature ->warningIcon (false );
360363 ui->warnings ->closeWarnings (SignDetails);
364+ ui->warnings ->closeWarning (EmptyFileWarning);
361365 break ;
362366 case ContainerCancel:
363- resetDigiDoc ();
367+ resetDigiDoc ({} );
364368 selectPage (Pages::SignIntro);
365369 break ;
366370 case ContainerConvert:
@@ -369,26 +373,13 @@ void MainWindow::onSignAction(int action, const QString &idCode, const QString &
369373 break ;
370374 case ContainerSave:
371375 save ();
372- ui->signContainerPage ->transition (digiDoc);
373- break ;
374- case ContainerSaveAs:
375- save (true );
376- break ;
377- case ContainerLocation:
378- if (digiDoc)
379- moveSignatureContainer ();
376+ ui->signContainerPage ->transition (digiDoc.get ());
380377 break ;
381378 default :
382379 break ;
383380 }
384381}
385382
386- void MainWindow::convertToBDoc ()
387- {
388- if (wrap (cryptoDoc->fileName (), cryptoDoc->state () == EncryptedContainer))
389- FadeInNotification::success (ui->topBar , tr (" Converted to signed document!" ));
390- }
391-
392383void MainWindow::convertToCDoc ()
393384{
394385 QString filename = FileDialog::createNewFileName (digiDoc->fileName (), false , this );
@@ -409,27 +400,13 @@ void MainWindow::convertToCDoc()
409400 cryptoContainer->addKey (CKey (cardData.cert ()));
410401
411402 cryptoDoc = std::move (cryptoContainer);
412- resetDigiDoc ( nullptr , false );
403+ digiDoc. reset ( );
413404 ui->cryptoContainerPage ->transition (cryptoDoc.get (), qApp->signer ()->tokenauth ().cert ());
414405 selectPage (CryptoDetails);
415406
416407 FadeInNotification::success (ui->topBar , tr (" Converted to crypto container!" ));
417408}
418409
419- void MainWindow::moveCryptoContainer ()
420- {
421- QString to = FileDialog::getSaveFileName (this , tr (" Move file" ), cryptoDoc->fileName ());
422- if (!to.isNull () && cryptoDoc->move (to))
423- emit ui->cryptoContainerPage ->moved (to);
424- }
425-
426- void MainWindow::moveSignatureContainer ()
427- {
428- QString to = FileDialog::getSaveFileName (this , tr (" Move file" ), digiDoc->fileName ());
429- if (!to.isNull () && digiDoc->move (to))
430- emit ui->signContainerPage ->moved (to);
431- }
432-
433410void MainWindow::onCryptoAction (int action, const QString &/* id*/ , const QString &/* phone*/ )
434411{
435412 switch (action)
@@ -439,8 +416,8 @@ void MainWindow::onCryptoAction(int action, const QString &/*id*/, const QString
439416 selectPage (Pages::CryptoIntro);
440417 break ;
441418 case ContainerConvert:
442- if (cryptoDoc)
443- convertToBDoc ( );
419+ if (cryptoDoc && wrap (cryptoDoc-> fileName (), false ) )
420+ FadeInNotification::success (ui-> topBar , tr ( " Converted to signed document! " ) );
444421 break ;
445422 case DecryptContainer:
446423 case DecryptToken:
@@ -457,33 +434,11 @@ void MainWindow::onCryptoAction(int action, const QString &/*id*/, const QString
457434 FadeInNotification::success (ui->topBar , tr (" Encryption succeeded!" ));
458435 }
459436 break ;
460- case ContainerSaveAs:
461- {
462- if (!cryptoDoc)
463- break ;
464- QString target = FileDialog::getSaveFileName (this , tr (" Save file" ), cryptoDoc->fileName ());
465- if (target.isEmpty ())
466- break ;
467- if ( !FileDialog::fileIsWritable (target))
468- {
469- auto *dlg = new WarningDialog (tr (" Cannot alter container %1. Save different location?" ).arg (target), this );
470- dlg->addButton (WarningDialog::YES, QMessageBox::Yes);
471- if (dlg->exec () == QMessageBox::Yes) {
472- QString file = FileDialog::getSaveFileName (this , tr (" Save file" ), target);
473- if (!file.isEmpty ())
474- cryptoDoc->saveCopy (file);
475- }
476- }
477- cryptoDoc->saveCopy (target);
478- break ;
479- }
480437 case ClearCryptoWarning:
481438 ui->crypto ->warningIcon (false );
482439 ui->warnings ->closeWarnings (CryptoDetails);
483440 break ;
484- case ContainerLocation:
485- if (cryptoDoc)
486- moveCryptoContainer ();
441+ default :
487442 break ;
488443 }
489444}
@@ -588,9 +543,9 @@ void MainWindow::openContainer(bool signature)
588543 openFiles (files);
589544}
590545
591- void MainWindow::resetDigiDoc (DigiDoc * doc, bool warnOnChange )
546+ void MainWindow::resetDigiDoc (std::unique_ptr< DigiDoc> && doc)
592547{
593- if (warnOnChange && digiDoc && digiDoc->isModified ())
548+ if (digiDoc && digiDoc->isModified ())
594549 {
595550 QString warning, cancelTxt, saveTxt;
596551 if (digiDoc->state () == UnsignedContainer)
@@ -612,37 +567,28 @@ void MainWindow::resetDigiDoc(DigiDoc *doc, bool warnOnChange)
612567 if (dlg->exec () == QMessageBox::Save)
613568 save ();
614569 }
615-
616- ui->signature ->warningIcon (false );
617-
618- ui->signContainerPage ->clear ();
619- delete digiDoc;
620- ui->warnings ->closeWarnings (SignDetails);
621- ui->warnings ->closeWarning (EmptyFileWarning);
622- digiDoc = doc;
570+ digiDoc = std::move (doc);
623571}
624572
625- bool MainWindow::save (bool saveAs )
573+ bool MainWindow::save ()
626574{
627575 if (!digiDoc)
628576 return false ;
629577
630578 QString target = digiDoc->fileName ();
631- if (saveAs)
632- target = FileDialog::getSaveFileName (this , tr (" Save file" ), target);
633- if (target.isEmpty ())
634- return false ;
635-
636- if (!FileDialog::fileIsWritable (target))
579+ while (!FileDialog::fileIsWritable (target))
637580 {
638581 auto *dlg = new WarningDialog (tr (" Cannot alter container %1. Save different location?" ).arg (target), this );
639582 dlg->addButton (WarningDialog::YES, QMessageBox::Yes);
640- if (dlg->exec () == QMessageBox::Yes) {
641- if (QString file = FileDialog::getSaveFileName ( this , tr ( " Save file " ), target); !file. isEmpty ())
642- return saveAs ? digiDoc-> saveAs ( file) : digiDoc-> save (file);
643- }
583+ if (dlg->exec () != QMessageBox::Yes)
584+ return false ;
585+ if (target = FileDialog::getSaveFileName ( this , FileDialog::tr ( " Save file" ), target); target. isEmpty ())
586+ return false ;
644587 }
645- return saveAs ? digiDoc->saveAs (target) : digiDoc->save (target);
588+ bool result = digiDoc->save (target);
589+ if (result)
590+ ui->signContainerPage ->setHeader (target);
591+ return result;
646592}
647593
648594void MainWindow::selectPage (Pages page)
@@ -705,7 +651,7 @@ void MainWindow::sign(F &&sign)
705651
706652 if (!sign (city, state, zip, country, role))
707653 {
708- resetDigiDoc ( nullptr , false );
654+ digiDoc. reset ( );
709655 navigateToPage (SignDetails, {std::move (wrappedFile)}, false );
710656 return ;
711657 }
@@ -716,7 +662,7 @@ void MainWindow::sign(F &&sign)
716662 if (!save ())
717663 return ;
718664
719- ui->signContainerPage ->transition (digiDoc);
665+ ui->signContainerPage ->transition (digiDoc. get () );
720666
721667 FadeInNotification::success (ui->topBar , tr (" The container has been successfully signed!" ));
722668 adjustDrops ();
@@ -761,7 +707,7 @@ bool MainWindow::removeFile(DocumentModel *model, int index)
761707 continue ;
762708 ui->warnings ->closeWarning (EmptyFileWarning);
763709 if (digiDoc)
764- ui->signContainerPage ->transition (digiDoc);
710+ ui->signContainerPage ->transition (digiDoc. get () );
765711 break ;
766712 }
767713
@@ -775,7 +721,7 @@ void MainWindow::removeSignature(int index)
775721 WaitDialogHolder waitDialog (this , tr (" Removing signature" ));
776722 digiDoc->removeSignature (unsigned (index));
777723 save ();
778- ui->signContainerPage ->transition (digiDoc);
724+ ui->signContainerPage ->transition (digiDoc. get () );
779725 adjustDrops ();
780726}
781727
@@ -788,7 +734,7 @@ void MainWindow::removeSignatureFile(int index)
788734 {
789735 if (QFile::exists (digiDoc->fileName ()))
790736 QFile::remove (digiDoc->fileName ());
791- resetDigiDoc ( nullptr , false );
737+ digiDoc. reset ( );
792738 selectPage (Pages::SignIntro);
793739 }
794740}
@@ -807,7 +753,7 @@ bool MainWindow::validateFiles(const QString &container, const QStringList &file
807753 return false ;
808754}
809755
810- bool MainWindow::wrap (const QString& wrappedFile, bool enclose )
756+ bool MainWindow::wrap (const QString& wrappedFile, bool pdf )
811757{
812758 QString filename = FileDialog::createNewFileName (wrappedFile, true , this );
813759 if (filename.isNull ())
@@ -816,16 +762,16 @@ bool MainWindow::wrap(const QString& wrappedFile, bool enclose)
816762 std::unique_ptr<DigiDoc> signatureContainer (new DigiDoc (this ));
817763 signatureContainer->create (filename);
818764
819- // If encrypted container or pdf, add whole file to signature container; otherwise content only
820- if (enclose )
765+ // If pdf, add whole file to signature container; otherwise content only
766+ if (pdf )
821767 signatureContainer->documentModel ()->addFile (wrappedFile);
822768 else
823769 signatureContainer->documentModel ()->addTempFiles (cryptoDoc->documentModel ()->tempFiles ());
824770
825771 cryptoDoc.reset ();
826- resetDigiDoc (signatureContainer. release ( ));
772+ resetDigiDoc (std::move (signatureContainer ));
827773
828- ui->signContainerPage ->transition (digiDoc);
774+ ui->signContainerPage ->transition (digiDoc. get () );
829775 selectPage (SignDetails);
830776
831777 return true ;
0 commit comments