File indexing completed on 2024-05-12 05:39:49
0001 /*************************************************************************** 0002 * Copyright (C) 2009 by Renaud Guezennec * 0003 * https://rolisteam.org/contact * 0004 * * 0005 * Rolisteam 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 CLEVERURI_H 0021 #define CLEVERURI_H 0022 0023 #include <QList> 0024 #include <QMetaType> 0025 #include <QString> 0026 0027 #include "media/mediatype.h" 0028 #include "resourcesnode.h" 0029 #include <core_global.h> 0030 /** 0031 * @brief This class stores data refering to file, uri and type 0032 * @brief as a file can be loaded as different type. 0033 * @brief E.g: an image can be loaded as Picture or as Background for map. 0034 * 0035 */ 0036 class CORE_EXPORT CleverURI : public ResourcesNode 0037 { 0038 Q_OBJECT 0039 Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged) 0040 Q_PROPERTY(Core::ContentType contentType READ contentType WRITE setContentType NOTIFY contentTypeChanged) 0041 Q_PROPERTY(QByteArray data READ data WRITE setData NOTIFY dataChanged) 0042 Q_PROPERTY(Core::State state READ state WRITE setState NOTIFY stateChanged) 0043 Q_PROPERTY(Core::LoadingMode loadingMode READ loadingMode WRITE setLoadingMode NOTIFY loadingModeChanged) 0044 0045 public: 0046 /** 0047 * @brief default constructor 0048 */ 0049 CleverURI(Core::ContentType type); 0050 /** 0051 * @brief constructor with parameter 0052 * 0053 */ 0054 CleverURI(const QString& name, const QString& uri, Core::ContentType type); 0055 /** 0056 * @brief Destructor 0057 * 0058 */ 0059 virtual ~CleverURI() override; 0060 0061 void setPath(const QString& uri); 0062 QString path() const; 0063 0064 void setContentType(Core::ContentType type); 0065 Core::ContentType contentType() const; 0066 0067 Core::LoadingMode loadingMode() const; 0068 void setLoadingMode(const Core::LoadingMode& currentMode); 0069 0070 bool isDisplayed() const; 0071 0072 Core::State state() const; 0073 void setState(const Core::State& state); 0074 0075 QByteArray data() const; 0076 bool hasData() const; 0077 void setData(const QByteArray& data); 0078 0079 void loadFileFromUri(QByteArray&) const; 0080 0081 // From Resources 0082 bool hasChildren() const override; 0083 virtual QIcon icon() const override; 0084 void write(QDataStream& out, bool tag= true, bool saveData= true) const; 0085 void read(QDataStream& in); 0086 0087 QVariant getData(ResourcesNode::DataValue i) const override; 0088 0089 // utility function 0090 bool exists(); 0091 const QString getAbsolueDir() const; 0092 0093 bool operator==(const CleverURI& uri1) const; 0094 0095 signals: 0096 void pathChanged(); 0097 void contentTypeChanged(); 0098 void dataChanged(); 0099 void stateChanged(); 0100 void loadingModeChanged(); 0101 0102 protected: 0103 void loadData(); 0104 void init(); 0105 0106 private: 0107 QString m_path; 0108 Core::ContentType m_type; 0109 QByteArray m_data; 0110 Core::LoadingMode m_loadingMode; 0111 Core::State m_state; 0112 0113 static QStringList m_typeNameList; 0114 static QStringList m_typeToPreferenceDirectory; 0115 }; 0116 0117 typedef QList<CleverURI> CleverUriList; 0118 #endif // CLEVERURI_H