File indexing completed on 2024-05-19 05:40:49
0001 /*************************************************************************** 0002 * Copyright (C) 2020 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 "updater/media/mediaupdaterinterface.h" 0021 0022 #include "data/campaign.h" 0023 #include "data/campaignmanager.h" 0024 #include "worker/fileserializer.h" 0025 #include "worker/iohelper.h" 0026 #include "worker/utilshelper.h" 0027 0028 #include <QDebug> 0029 0030 MediaUpdaterInterface::MediaUpdaterInterface(campaign::CampaignManager* campaign, QObject* object) 0031 : QObject(object), m_manager(campaign) 0032 { 0033 } 0034 0035 NetWorkReceiver::SendType MediaUpdaterInterface::processMessage(NetworkMessageReader*) 0036 { 0037 return NetWorkReceiver::NONE; 0038 } 0039 0040 bool MediaUpdaterInterface::is(NetworkMessageReader* msg, NetMsg::Category c, NetMsg::Action a) const 0041 { 0042 if(!msg) 0043 return false; 0044 0045 return (msg->action() == a && msg->category() == c); 0046 } 0047 0048 void MediaUpdaterInterface::saveMediaController(MediaControllerBase* ctrl) 0049 { 0050 if(!ctrl) 0051 return; 0052 if(ctrl->remote()) 0053 return; 0054 0055 auto id= ctrl->uuid(); 0056 auto campaign= m_manager->campaign(); 0057 auto path= ctrl->url().toLocalFile(); 0058 if(campaign) 0059 { 0060 auto p= campaign->pathFromUuid(id); 0061 if(!p.isEmpty()) 0062 path= p; 0063 } 0064 ctrl->setUrl(QUrl::fromLocalFile(path)); 0065 0066 helper::utils::setContinuation<bool>( 0067 campaign::FileSerializer::writeFileIntoCampaign(path, IOHelper::saveController(ctrl)), ctrl, [ctrl](bool b) { 0068 if(b) 0069 ctrl->setModified(false); 0070 }); 0071 } 0072 0073 bool MediaUpdaterInterface::localIsGM() const 0074 { 0075 return m_localIsGM; 0076 } 0077 0078 void MediaUpdaterInterface::setLocalIsGM(bool newLocalIsGM) 0079 { 0080 if (m_localIsGM == newLocalIsGM) 0081 return; 0082 m_localIsGM = newLocalIsGM; 0083 emit localIsGMChanged(); 0084 }