25
25
26
26
#include " util/pbcConfig.h"
27
27
#include " gui/pbcPlayerView.h"
28
+ #include " pbcController.h"
28
29
#include " models/pbcPlaybook.h"
29
30
#include " dialogs/pbcExportPdfDialog.h"
30
31
#include " dialogs/pbcDeleteDialog.h"
@@ -116,7 +117,7 @@ void MainDialog::updateTitle(bool saved) {
116
117
std::string windowTitle = " Playbook Creator V" +
117
118
PBCVersion::getSimpleVersionString () +
118
119
" - " +
119
- PBCPlaybook ::getInstance ()->name ();
120
+ PBCController ::getInstance()-> getPlaybook ()->name ();
120
121
if (saved == false ) {
121
122
windowTitle += " *" ;
122
123
}
@@ -240,7 +241,7 @@ void MainDialog::savePlayAs() {
240
241
int returnCode = dialog.exec ();
241
242
if (returnCode == QDialog::Accepted) {
242
243
struct PBCSavePlayAsDialog ::ReturnStruct rs = dialog.getReturnStruct ();
243
- std::vector<std::string> playNames = PBCPlaybook ::getInstance ()->getPlayNames ();
244
+ std::vector<std::string> playNames = PBCController ::getInstance()-> getPlaybook ()->getPlayNames ();
244
245
const auto & it = std::find (playNames.begin (), playNames.end (), rs.name );
245
246
if (it != playNames.end ()) {
246
247
QMessageBox::StandardButton button =
@@ -289,7 +290,7 @@ void MainDialog::saveFormationAs() {
289
290
if (ok == true ) {
290
291
pbcAssert (qformationname != " " );
291
292
std::string formationName = qformationname.toStdString ();
292
- std::vector<std::string> formationNames = PBCPlaybook ::getInstance ()->getFormationNames ();
293
+ std::vector<std::string> formationNames = PBCController ::getInstance()-> getPlaybook ()->getFormationNames ();
293
294
const auto &it = std::find (formationNames.begin (), formationNames.end (), formationName);
294
295
if (it != formationNames.end ()) {
295
296
QMessageBox::StandardButton button =
@@ -329,7 +330,7 @@ void MainDialog::newPlaybook() {
329
330
pbcAssert (name != " " );
330
331
pbcAssert (playerNumber == 5 || playerNumber == 7 ||
331
332
playerNumber == 9 || playerNumber == 11 );
332
- PBCPlaybook ::getInstance ()->resetToNewEmptyPlaybook (name,
333
+ PBCController ::getInstance()-> getPlaybook ()->resetToNewEmptyPlaybook (name,
333
334
playerNumber);
334
335
PBCStorage::getInstance ()->init (name);
335
336
_playView->resetPlay ();
@@ -343,7 +344,7 @@ void MainDialog::newPlaybook() {
343
344
* @brief Saves the playbook persistently to a file after asking for a file name.
344
345
*/
345
346
void MainDialog::savePlaybookAs () {
346
- std::string stdFile = PBCPlaybook ::getInstance ()->name () + " .pbc" ;
347
+ std::string stdFile = PBCController ::getInstance()-> getPlaybook ()->name () + " .pbc" ;
347
348
QFileDialog fileDialog (
348
349
this , " Save Playbook" ,
349
350
QString::fromStdString (stdFile),
@@ -396,8 +397,8 @@ void MainDialog::openPlaybook() {
396
397
QLineEdit::Password, " " , &ok);
397
398
if (ok == true ) {
398
399
try {
399
- PBCStorage::getInstance ()->loadPlaybook (password.toStdString (),
400
- fileName.toStdString ());
400
+ PBCStorage::getInstance ()->loadActivePlaybook (password.toStdString (),
401
+ fileName.toStdString ());
401
402
} catch (PBCDecryptionException &e) {
402
403
if (decryptionFailureCount < PASSWORD_MAX_RETRYS - 1 ) {
403
404
decryptionFailureCount++;
@@ -419,6 +420,72 @@ void MainDialog::openPlaybook() {
419
420
}
420
421
}
421
422
423
+
424
+ /* *
425
+ * @brief Import a playbook from a file which is specified by an open-dialog.
426
+ */
427
+ void MainDialog::importPlaybook () {
428
+ QFileDialog fileDialog (this , " Impport Playbook" , " " ,
429
+ " PBC Files (*.pbc);;All Files (*.*)" );
430
+
431
+ fileDialog.setFileMode (QFileDialog::ExistingFile);
432
+ if (fileDialog.exec () == true ) {
433
+ QStringList files = fileDialog.selectedFiles ();
434
+ pbcAssert (files.size () == 1 );
435
+ QString fileName = files.first ();
436
+
437
+ unsigned int decryptionFailureCount = 0 ;
438
+ while (true ) {
439
+ bool ok;
440
+ std::string msg;
441
+ if (decryptionFailureCount == 0 ) {
442
+ msg = " Enter decryption password" ;
443
+ } else {
444
+ msg = " Error on decryption. Maybe wrong password. Try again!" ;
445
+ }
446
+ QString password = QInputDialog::getText (this , " Import Playbook" ,
447
+ QString::fromStdString (msg),
448
+ QLineEdit::Password, " " , &ok);
449
+ if (ok == true ) {
450
+ try {
451
+ // TODO design dialog to get parameters for playbook importing
452
+ PBCStorage::getInstance ()->importPlaybook (
453
+ password.toStdString (),
454
+ fileName.toStdString (),
455
+ true ,
456
+ true ,
457
+ false ,
458
+ true ,
459
+ " imported_" );
460
+ QMessageBox::information (this ,
461
+ " Import Playbook" ,
462
+ " Import successful Your playbook has been saved automatically!" );
463
+ } catch (PBCImportException& e) {
464
+ QString msg = e.what ();
465
+ msg.append (" \n\n You should rename or delete it and try to import again." );
466
+ QMessageBox::critical (this , " Import Playbook" , msg);
467
+ } catch (PBCDecryptionException &e) {
468
+ if (decryptionFailureCount < PASSWORD_MAX_RETRYS - 1 ) {
469
+ decryptionFailureCount++;
470
+ continue ;
471
+ } else {
472
+ throw e;
473
+ }
474
+ } catch (PBCDeprecatedVersionException& e) {
475
+ QMessageBox::critical (this ,
476
+ " Import Playbook" ,
477
+ " Cannot load playbook because it's created by a newer version of Playbook-Creator. "
478
+ " Please download the latest version of Playbook-Creator!" );
479
+ }
480
+ _playView->resetPlay ();
481
+ updateTitle (true );
482
+ break ;
483
+ }
484
+ }
485
+ }
486
+ }
487
+
488
+
422
489
/* *
423
490
* @brief Exports the playbook to a PDF file.
424
491
*
@@ -433,7 +500,7 @@ void MainDialog::exportAsPDF() {
433
500
boost::shared_ptr<PBCExportPDFDialog::ReturnStruct> returnStruct (new PBCExportPDFDialog::ReturnStruct ()); // NOLINT
434
501
boost::shared_ptr<QStringList> playListSP = exportDialog.exec (returnStruct);
435
502
if (playListSP != NULL && playListSP->size () > 0 ) {
436
- std::string stdFile = PBCPlaybook ::getInstance ()->name () + " .pdf" ;
503
+ std::string stdFile = PBCController ::getInstance()-> getPlaybook ()->name () + " .pdf" ;
437
504
QFileDialog fileDialog (
438
505
this , " Export Playbook As PDF" ,
439
506
QString::fromStdString (stdFile),
@@ -480,7 +547,7 @@ void MainDialog::deleteRoutes() {
480
547
if (deleteDialog.exec () == QDialog::Accepted) {
481
548
for (const auto &name : *deleteDialog.get_nameList ()) {
482
549
try {
483
- PBCPlaybook ::getInstance ()->deleteRoute (name.toStdString ());
550
+ PBCController ::getInstance()-> getPlaybook ()->deleteRoute (name.toStdString ());
484
551
} catch (PBCAutoSaveException &e) {
485
552
// TODO log message
486
553
/* The exception should not really be an issue here. If the playbook has not been saved to file yet,
@@ -500,7 +567,7 @@ void MainDialog::deletePlays() {
500
567
if (deleteDialog.exec () == QDialog::Accepted){
501
568
for (const auto & name : *deleteDialog.get_nameList ()) {
502
569
try {
503
- PBCPlaybook ::getInstance ()->deletePlay (name.toStdString ());
570
+ PBCController ::getInstance()-> getPlaybook ()->deletePlay (name.toStdString ());
504
571
} catch (PBCAutoSaveException &e) {
505
572
// TODO log message (see issue #19)
506
573
/* The exception should not really be an issue here. If the playbook has not been saved to file yet,
@@ -519,7 +586,7 @@ void MainDialog::deleteFormations() {
519
586
if (deleteDialog.exec () == QDialog::Accepted){
520
587
for (const auto & name : *deleteDialog.get_nameList ()) {
521
588
try {
522
- PBCPlaybook ::getInstance ()->deleteFormation (name.toStdString ());
589
+ PBCController ::getInstance()-> getPlaybook ()->deleteFormation (name.toStdString ());
523
590
} catch (PBCAutoSaveException &e) {
524
591
// TODO log message (see issue #19)
525
592
/* The exception should not really be an issue here. If the playbook has not been saved to file yet,
@@ -538,7 +605,7 @@ void MainDialog::deleteCategories() {
538
605
if (deleteDialog.exec () == QDialog::Accepted){
539
606
for (const auto & name : *deleteDialog.get_nameList ()) {
540
607
try {
541
- PBCPlaybook ::getInstance ()->deleteCategory (name.toStdString ());
608
+ PBCController ::getInstance()-> getPlaybook ()->deleteCategory (name.toStdString ());
542
609
} catch (PBCAutoSaveException &e) {
543
610
// TODO log message (see issue #19)
544
611
/* The exception should not really be an issue here. If the playbook has not been saved to file yet,
@@ -559,3 +626,4 @@ void MainDialog::deleteCategories() {
559
626
MainDialog::~MainDialog () {
560
627
delete ui;
561
628
}
629
+
0 commit comments