@@ -133,6 +133,7 @@ MainWindow::MainWindow( QWidget *parent )
133133
134134MainWindow::~MainWindow ()
135135{
136+ digiDoc.reset ();
136137 cryptoDoc.reset ();
137138 delete ui;
138139}
@@ -169,7 +170,7 @@ void MainWindow::changeEvent(QEvent* event)
169170void MainWindow::closeEvent (QCloseEvent * /* event*/ )
170171{
171172 cryptoDoc.reset ();
172- resetDigiDoc ();
173+ resetDigiDoc ({} );
173174 ui->startScreen ->setCurrentIndex (SignIntro);
174175}
175176
@@ -250,15 +251,17 @@ bool MainWindow::encrypt()
250251 if (!cryptoDoc)
251252 return false ;
252253
253- if (!FileDialog::fileIsWritable (cryptoDoc->fileName ())) {
254+ while (!FileDialog::fileIsWritable (cryptoDoc->fileName ()))
255+ {
254256 auto *dlg = new WarningDialog (tr (" Cannot alter container %1. Save different location?" )
255257 .arg (FileDialog::normalized (cryptoDoc->fileName ())), this );
256258 dlg->addButton (WarningDialog::YES, QMessageBox::Yes);
257- if (dlg->exec () == QMessageBox::Yes) {
258- moveCryptoContainer ();
259- return encrypt ();
260- }
261- return false ;
259+ if (dlg->exec () != QMessageBox::Yes)
260+ return false ;
261+ QString to = FileDialog::getSaveFileName (this , tr (" Move file" ), cryptoDoc->fileName ());
262+ if (to.isNull () || !cryptoDoc->move (to))
263+ return false ;
264+ ui->cryptoContainerPage ->setHeader (to);
262265 }
263266
264267 WaitDialogHolder waitDialog (this , tr (" Encrypting" ));
@@ -298,8 +301,8 @@ void MainWindow::navigateToPage( Pages page, const QStringList &files, bool crea
298301 navigate = signatureContainer->open (files[0 ]);
299302 if (navigate)
300303 {
301- resetDigiDoc (signatureContainer. release ( ));
302- ui->signContainerPage ->transition (digiDoc);
304+ resetDigiDoc (std::move (signatureContainer ));
305+ ui->signContainerPage ->transition (digiDoc. get () );
303306 }
304307 }
305308 else if (page == CryptoDetails)
@@ -360,9 +363,10 @@ void MainWindow::onSignAction(int action, const QString &info1, const QString &i
360363 case ClearSignatureWarning:
361364 ui->signature ->warningIcon (false );
362365 ui->warnings ->closeWarnings (SignDetails);
366+ ui->warnings ->closeWarning (EmptyFileWarning);
363367 break ;
364368 case ContainerCancel:
365- resetDigiDoc ();
369+ resetDigiDoc ({} );
366370 selectPage (Pages::SignIntro);
367371 break ;
368372 case ContainerConvert:
@@ -371,26 +375,13 @@ void MainWindow::onSignAction(int action, const QString &info1, const QString &i
371375 break ;
372376 case ContainerSave:
373377 save ();
374- ui->signContainerPage ->transition (digiDoc);
375- break ;
376- case ContainerSaveAs:
377- save (true );
378- break ;
379- case ContainerLocation:
380- if (digiDoc)
381- moveSignatureContainer ();
378+ ui->signContainerPage ->transition (digiDoc.get ());
382379 break ;
383380 default :
384381 break ;
385382 }
386383}
387384
388- void MainWindow::convertToBDoc ()
389- {
390- if (wrap (cryptoDoc->fileName (), cryptoDoc->state () == EncryptedContainer))
391- FadeInNotification::success (ui->topBar , tr (" Converted to signed document!" ));
392- }
393-
394385void MainWindow::convertToCDoc ()
395386{
396387 QString filename = FileDialog::createNewFileName (digiDoc->fileName (), false , this );
@@ -418,20 +409,6 @@ void MainWindow::convertToCDoc()
418409 FadeInNotification::success (ui->topBar , tr (" Converted to crypto container!" ));
419410}
420411
421- void MainWindow::moveCryptoContainer ()
422- {
423- QString to = FileDialog::getSaveFileName (this , tr (" Move file" ), cryptoDoc->fileName ());
424- if (!to.isNull () && cryptoDoc->move (to))
425- emit ui->cryptoContainerPage ->moved (to);
426- }
427-
428- void MainWindow::moveSignatureContainer ()
429- {
430- QString to = FileDialog::getSaveFileName (this , tr (" Move file" ), digiDoc->fileName ());
431- if (!to.isNull () && digiDoc->move (to))
432- emit ui->signContainerPage ->moved (to);
433- }
434-
435412void MainWindow::onCryptoAction (int action, const QString &/* id*/ , const QString &/* phone*/ )
436413{
437414 switch (action)
@@ -441,8 +418,8 @@ void MainWindow::onCryptoAction(int action, const QString &/*id*/, const QString
441418 selectPage (Pages::CryptoIntro);
442419 break ;
443420 case ContainerConvert:
444- if (cryptoDoc)
445- convertToBDoc ( );
421+ if (cryptoDoc && wrap (cryptoDoc-> fileName (), false ) )
422+ FadeInNotification::success (ui-> topBar , tr ( " Converted to signed document! " ) );
446423 break ;
447424 case DecryptContainer:
448425 case DecryptToken:
@@ -459,33 +436,11 @@ void MainWindow::onCryptoAction(int action, const QString &/*id*/, const QString
459436 FadeInNotification::success (ui->topBar , tr (" Encryption succeeded!" ));
460437 }
461438 break ;
462- case ContainerSaveAs:
463- {
464- if (!cryptoDoc)
465- break ;
466- QString target = FileDialog::getSaveFileName (this , tr (" Save file" ), cryptoDoc->fileName ());
467- if (target.isEmpty ())
468- break ;
469- if ( !FileDialog::fileIsWritable (target))
470- {
471- auto *dlg = new WarningDialog (tr (" Cannot alter container %1. Save different location?" ).arg (target), this );
472- dlg->addButton (WarningDialog::YES, QMessageBox::Yes);
473- if (dlg->exec () == QMessageBox::Yes) {
474- QString file = FileDialog::getSaveFileName (this , tr (" Save file" ), target);
475- if (!file.isEmpty ())
476- cryptoDoc->saveCopy (file);
477- }
478- }
479- cryptoDoc->saveCopy (target);
480- break ;
481- }
482439 case ClearCryptoWarning:
483440 ui->crypto ->warningIcon (false );
484441 ui->warnings ->closeWarnings (CryptoDetails);
485442 break ;
486- case ContainerLocation:
487- if (cryptoDoc)
488- moveCryptoContainer ();
443+ default :
489444 break ;
490445 }
491446}
@@ -590,7 +545,7 @@ void MainWindow::openContainer(bool signature)
590545 openFiles (files);
591546}
592547
593- void MainWindow::resetDigiDoc (DigiDoc * doc, bool warnOnChange)
548+ void MainWindow::resetDigiDoc (std::unique_ptr< DigiDoc> && doc, bool warnOnChange)
594549{
595550 if (warnOnChange && digiDoc && digiDoc->isModified ())
596551 {
@@ -614,37 +569,25 @@ void MainWindow::resetDigiDoc(DigiDoc *doc, bool warnOnChange)
614569 if (dlg->exec () == QMessageBox::Save)
615570 save ();
616571 }
617-
618- ui->signature ->warningIcon (false );
619-
620- ui->signContainerPage ->clear ();
621- delete digiDoc;
622- ui->warnings ->closeWarnings (SignDetails);
623- ui->warnings ->closeWarning (EmptyFileWarning);
624- digiDoc = doc;
572+ digiDoc = std::move (doc);
625573}
626574
627- bool MainWindow::save (bool saveAs )
575+ bool MainWindow::save ()
628576{
629577 if (!digiDoc)
630578 return false ;
631579
632580 QString target = digiDoc->fileName ();
633- if (saveAs)
634- target = FileDialog::getSaveFileName (this , tr (" Save file" ), target);
635- if (target.isEmpty ())
636- return false ;
637-
638- if (!FileDialog::fileIsWritable (target))
581+ while (!FileDialog::fileIsWritable (target))
639582 {
640583 auto *dlg = new WarningDialog (tr (" Cannot alter container %1. Save different location?" ).arg (target), this );
641584 dlg->addButton (WarningDialog::YES, QMessageBox::Yes);
642- if (dlg->exec () == QMessageBox::Yes) {
643- if (QString file = FileDialog::getSaveFileName ( this , tr ( " Save file " ), target); !file. isEmpty ())
644- return saveAs ? digiDoc-> saveAs ( file) : digiDoc-> save (file);
645- }
585+ if (dlg->exec () != QMessageBox::Yes)
586+ return false ;
587+ if (target = FileDialog::getSaveFileName ( this , tr ( " Save file" ), target); target. isEmpty ())
588+ return false ;
646589 }
647- return saveAs ? digiDoc-> saveAs (target) : digiDoc->save (target);
590+ return digiDoc->save (target);
648591}
649592
650593void MainWindow::selectPage (Pages page)
@@ -718,7 +661,7 @@ void MainWindow::sign(F &&sign)
718661 if (!save ())
719662 return ;
720663
721- ui->signContainerPage ->transition (digiDoc);
664+ ui->signContainerPage ->transition (digiDoc. get () );
722665
723666 FadeInNotification::success (ui->topBar , tr (" The container has been successfully signed!" ));
724667 adjustDrops ();
@@ -763,7 +706,7 @@ bool MainWindow::removeFile(DocumentModel *model, int index)
763706 continue ;
764707 ui->warnings ->closeWarning (EmptyFileWarning);
765708 if (digiDoc)
766- ui->signContainerPage ->transition (digiDoc);
709+ ui->signContainerPage ->transition (digiDoc. get () );
767710 break ;
768711 }
769712
@@ -777,7 +720,7 @@ void MainWindow::removeSignature(int index)
777720 WaitDialogHolder waitDialog (this , tr (" Removing signature" ));
778721 digiDoc->removeSignature (unsigned (index));
779722 save ();
780- ui->signContainerPage ->transition (digiDoc);
723+ ui->signContainerPage ->transition (digiDoc. get () );
781724 adjustDrops ();
782725}
783726
@@ -809,7 +752,7 @@ bool MainWindow::validateFiles(const QString &container, const QStringList &file
809752 return false ;
810753}
811754
812- bool MainWindow::wrap (const QString& wrappedFile, bool enclose )
755+ bool MainWindow::wrap (const QString& wrappedFile, bool pdf )
813756{
814757 QString filename = FileDialog::createNewFileName (wrappedFile, true , this );
815758 if (filename.isNull ())
@@ -818,16 +761,16 @@ bool MainWindow::wrap(const QString& wrappedFile, bool enclose)
818761 std::unique_ptr<DigiDoc> signatureContainer (new DigiDoc (this ));
819762 signatureContainer->create (filename);
820763
821- // If encrypted container or pdf, add whole file to signature container; otherwise content only
822- if (enclose )
764+ // If pdf, add whole file to signature container; otherwise content only
765+ if (pdf )
823766 signatureContainer->documentModel ()->addFile (wrappedFile);
824767 else
825768 signatureContainer->documentModel ()->addTempFiles (cryptoDoc->documentModel ()->tempFiles ());
826769
827770 cryptoDoc.reset ();
828- resetDigiDoc (signatureContainer. release ( ));
771+ resetDigiDoc (std::move (signatureContainer ));
829772
830- ui->signContainerPage ->transition (digiDoc);
773+ ui->signContainerPage ->transition (digiDoc. get () );
831774 selectPage (SignDetails);
832775
833776 return true ;
0 commit comments