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

0001 /***************************************************************************
0002  *  Copyright (C) 2021 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 "undoCmd/renamecampaignmedia.h"
0021 #include "data/campaign.h"
0022 #include "utils/iohelper.h"
0023 #include "model/mediamodel.h"
0024 
0025 #include <QDebug>
0026 
0027 RenameCampaignMedia::RenameCampaignMedia(campaign::MediaNode* mediaNode, const QString& newPath, const QString& oldPath,
0028                                          campaign::MediaModel* model, campaign::Campaign* campaign)
0029     : QUndoCommand(), m_model(model), m_media(mediaNode), m_newPath(newPath), m_oldPath(oldPath), m_campaign(campaign)
0030 {
0031 }
0032 void RenameCampaignMedia::redo()
0033 {
0034     if(!m_media)
0035         return;
0036 
0037     qDebug() << "move " << m_oldPath << m_newPath;
0038 
0039     if(utils::IOHelper::moveFile(m_oldPath, m_newPath))
0040     {
0041         m_media->setPath(m_newPath);
0042         m_model->dataChangedFor(m_media);
0043         m_campaign->renameMedia(m_media->uuid(), m_newPath);
0044     }
0045 }
0046 void RenameCampaignMedia::undo()
0047 {
0048     if(!m_media)
0049         return;
0050 
0051     qDebug() << "moveundo " << m_newPath << m_oldPath;
0052 
0053     if(utils::IOHelper::moveFile(m_newPath, m_oldPath))
0054     {
0055         m_media->setPath(m_oldPath);
0056         m_model->dataChangedFor(m_media);
0057         m_campaign->renameMedia(m_media->uuid(), m_oldPath);
0058     }
0059 }