File indexing completed on 2024-05-05 05:40:57

0001 /***************************************************************************
0002  *  Copyright (C) 2022 by Renaud Guezennec                               *
0003  *   http://www.rolisteam.org/contact                                      *
0004  *                                                                         *
0005  *   This software is free software; you can redistribute it and/or modify *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program; if not, write to the                         *
0017  *   Free Software Foundation, Inc.,                                       *
0018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
0019  ***************************************************************************/
0020 #include "importdatafromcampaigndialog.h"
0021 #include "ui_importdatafromcampaigndialog.h"
0022 
0023 #include "worker/fileserializer.h"
0024 
0025 ImportDataFromCampaignDialog::ImportDataFromCampaignDialog(const QString& campaignRoot, QWidget* parent)
0026     : QDialog(parent), ui(new Ui::ImportDataFromCampaignDialog), m_root(campaignRoot)
0027 {
0028     ui->setupUi(this);
0029 }
0030 
0031 ImportDataFromCampaignDialog::~ImportDataFromCampaignDialog()
0032 {
0033     delete ui;
0034 }
0035 
0036 void ImportDataFromCampaignDialog::changeEvent(QEvent* e)
0037 {
0038     QDialog::changeEvent(e);
0039     switch(e->type())
0040     {
0041     case QEvent::LanguageChange:
0042         ui->retranslateUi(this);
0043         break;
0044     default:
0045         break;
0046     }
0047 }
0048 
0049 bool ImportDataFromCampaignDialog::validSource() const
0050 {
0051     return (m_root != source() && campaign::FileSerializer::isValidCampaignDirectory(source(), false));
0052 }
0053 
0054 const QString ImportDataFromCampaignDialog::source() const
0055 {
0056     return ui->m_pathEdit->text();
0057 }
0058 
0059 void ImportDataFromCampaignDialog::setSource(const QString& newSource)
0060 {
0061     ui->m_pathEdit->setText(newSource);
0062 
0063     if(validSource())
0064     {
0065         using cf= campaign::FileSerializer;
0066         using cc= Core::CampaignDataCategory;
0067         ui->m_antagonistListCb->setEnabled(cf::hasContent(source(), cc::AntagonistList));
0068         ui->m_audioPlayer1Cb->setEnabled(cf::hasContent(source(), cc::AudioPlayer1));
0069         ui->m_audioPlayer2Cb->setEnabled(cf::hasContent(source(), cc::AudioPlayer2));
0070         ui->m_audioPlayer3Cb->setEnabled(cf::hasContent(source(), cc::AudioPlayer3));
0071         ui->m_characterSheetCb->setEnabled(cf::hasContent(source(), cc::CharacterSheets));
0072         ui->m_characterStatesCb->setEnabled(cf::hasContent(source(), cc::CharacterStates));
0073         ui->m_diceCb->setEnabled(cf::hasContent(source(), cc::DiceAlias));
0074         ui->m_imageCb->setEnabled(cf::hasContent(source(), cc::Images));
0075         ui->m_mapCb->setEnabled(cf::hasContent(source(), cc::Maps));
0076         ui->m_mindmapCb->setEnabled(cf::hasContent(source(), cc::MindMaps));
0077         ui->m_noteCb->setEnabled(cf::hasContent(source(), cc::Notes));
0078         ui->m_themeCb->setEnabled(cf::hasContent(source(), cc::Themes));
0079         ui->m_pdfCb->setEnabled(cf::hasContent(source(), cc::PDFDoc));
0080         ui->m_weblinkCb->setEnabled(cf::hasContent(source(), cc::WebLink));
0081     }
0082 }
0083 
0084 const QVector<Core::CampaignDataCategory> ImportDataFromCampaignDialog::categoryList() const
0085 {
0086     return m_categoryList;
0087 }