File indexing completed on 2024-05-12 05:39:54
0001 /*************************************************************************** 0002 * Copyright (C) 2019 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 #ifndef IOHELPER_H 0021 #define IOHELPER_H 0022 0023 #include "data/campaign.h" 0024 #include "media/mediatype.h" 0025 #include "model/playermodel.h" 0026 #include <QJsonDocument> 0027 #include <QJsonObject> 0028 #include <QMimeData> 0029 #include <QString> 0030 #include <QVariant> 0031 #include <core_global.h> 0032 #include <map> 0033 0034 class MediaControllerBase; 0035 class ImageController; 0036 class WebpageController; 0037 class NoteController; 0038 class PdfController; 0039 class SharedNoteController; 0040 class CharacterSheetController; 0041 class ContentController; 0042 class ContentModel; 0043 class MindMapController; 0044 class DiceAlias; 0045 class CharacterState; 0046 class RolisteamTheme; 0047 class GenericModel; 0048 class AudioPlayerController; 0049 0050 namespace mindmap 0051 { 0052 class MindMapControllerBase; 0053 } 0054 0055 namespace campaign 0056 { 0057 class NonPlayableCharacter; 0058 } // namespace campaign 0059 0060 class CORE_EXPORT IOHelper 0061 { 0062 public: 0063 IOHelper(); 0064 0065 // Import data from campaign 0066 static bool mergePlayList(const QString& source, const QString& dest); 0067 static bool copyArrayModelAndFile(const QString& source, const QString& sourceDir, const QString& dest, 0068 const QString& destDir); 0069 static QStringList mediaList(const QString& source, Core::MediaType type); 0070 0071 // json to file 0072 static QJsonObject byteArrayToJsonObj(const QByteArray& data); 0073 static QJsonObject textByteArrayToJsonObj(const QByteArray& data); 0074 static QJsonArray byteArrayToJsonArray(const QByteArray& data); 0075 static QByteArray jsonObjectToByteArray(const QJsonObject& obj); 0076 static QJsonArray loadJsonFileIntoArray(const QString& filename, bool& ok); 0077 static QJsonObject loadJsonFileIntoObject(const QString& filename, bool& ok); 0078 static void writeJsonArrayIntoFile(const QString& destination, const QJsonArray& array); 0079 static void writeJsonObjectIntoFile(const QString& destination, const QJsonObject& obj); 0080 static void saveMediaBaseIntoJSon(MediaControllerBase* base, QJsonObject& obj); 0081 static QJsonArray fetchLanguageModel(); 0082 0083 static const QMimeData* clipboardMineData(); 0084 0085 // image to file 0086 static QByteArray pixmapToData(const QPixmap& pix); 0087 static QByteArray imageToData(const QImage& pix); 0088 static QPixmap dataToPixmap(const QByteArray& data); 0089 static QImage readImageFromURL(const QUrl& url); 0090 static QImage readImageFromFile(const QString& url); 0091 static QString htmlToTitle(const QMimeData& data, const QString& defaultName); 0092 0093 // Controller Generic method 0094 static QByteArray saveController(MediaControllerBase* media); 0095 //static MediaControllerBase* loadController(const QByteArray& data); 0096 static void saveBase(MediaControllerBase* base, QDataStream& output); 0097 static void readBase(MediaControllerBase* base, QDataStream& input); 0098 static void readBaseFromJson(MediaControllerBase* base, const QJsonObject& data); 0099 0100 static void readPdfController(PdfController* ctrl, const QByteArray& array); 0101 static void readImageController(ImageController* ctrl, const QByteArray& array); 0102 static void readNoteController(NoteController* ctrl, const QByteArray& array); 0103 static void readSharedNoteController(SharedNoteController* ctrl, const QByteArray& array); 0104 static void readWebpageController(WebpageController* ctrl, const QByteArray& array); 0105 static void readMindmapControllerBase(mindmap::MindMapControllerBase* ctrl, const QJsonObject& objCtrl); 0106 static QJsonObject readMindmapController(MindMapController* ctrl, const QByteArray& array); 0107 0108 // dice alias 0109 static QJsonObject diceAliasToJSonObject(DiceAlias* alias); 0110 0111 // states 0112 static QJsonObject stateToJSonObject(CharacterState* state, const QString& root); 0113 0114 // NPC 0115 static QJsonObject npcToJsonObject(const campaign::NonPlayableCharacter* npc, const QString& destination); 0116 static campaign::NonPlayableCharacter* jsonObjectToNpc(const QJsonObject& obj, const QString& rootDir); 0117 0118 // read theme file 0119 static RolisteamTheme* jsonToTheme(const QJsonObject& json); 0120 static QJsonObject themeToObject(const RolisteamTheme* theme); 0121 0122 // audio 0123 static QUrl findSong(const QString& name, QStringList list); 0124 static QList<QUrl> readM3uPlayList(const QString& filepath); 0125 static void writePlaylist(const QString& path, const QList<QUrl>& url); 0126 static QJsonObject saveAudioPlayerController(AudioPlayerController* controller); 0127 static void fetchAudioPlayerController(AudioPlayerController* controller, const QJsonObject& obj); 0128 0129 // charactersheet 0130 static void readCharacterSheetController(CharacterSheetController* ctrl, const QByteArray& array); 0131 0132 // Campaign 0133 static QString copyImageFileIntoCampaign(const QString& path, const QString& dest); 0134 0135 // character 0136 static Character *dupplicateCharacter(const Character *obj); 0137 }; 0138 0139 #endif // IOHELPER_H