Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 8a63bb44 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

DOC: Add the load from .vivy file

parent 38319b3b
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Ce commit fait partie de la requête de fusion !18. Les commentaires créés ici seront créés dans le contexte de cette requête de fusion.
...@@ -58,6 +58,7 @@ protected: ...@@ -58,6 +58,7 @@ protected:
public: public:
virtual bool rename(const QString &) noexcept = 0; virtual bool rename(const QString &) noexcept = 0;
virtual bool save() const noexcept = 0;
QString getName() const noexcept { return name; } QString getName() const noexcept { return name; }
Type getType() const noexcept { return type; } Type getType() const noexcept { return type; }
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
#include <QStringList> #include <QStringList>
#include <QJsonArray> #include <QJsonArray>
#include <QJsonObject> #include <QJsonObject>
#include <QJsonDocument>
#include <QTextStream>
using namespace Vivy; using namespace Vivy;
...@@ -13,13 +15,48 @@ VivyDocument::VivyDocument(const QString &documentPath, Options opt) ...@@ -13,13 +15,48 @@ VivyDocument::VivyDocument(const QString &documentPath, Options opt)
: AbstractDocument(AbstractDocument::Type::Vivy, documentPath) : AbstractDocument(AbstractDocument::Type::Vivy, documentPath)
, documentOptions(opt) , documentOptions(opt)
{ {
QFileInfo file(name); QFileInfo fileInfo(name);
documentName = file.baseName(); QFile file(name);
documentLocation = file.absoluteDir(); documentName = fileInfo.baseName();
documentLocation = fileInfo.absoluteDir();
if (fileInfo.completeSuffix() != fileSuffix)
throw std::runtime_error("Invalid file suffix");
if (!file.exists() || !fileInfo.isFile() || !file.open(QIODevice::ReadOnly | QIODevice::Text))
throw std::runtime_error("Document doesn't exists");
QTextStream fileContent(&file);
QJsonParseError jsonError;
QJsonDocument json = QJsonDocument::fromJson(fileContent.readAll().toUtf8(), &jsonError);
if (json.isNull())
throw std::runtime_error("Json error " + jsonError.errorString().toStdString());
// Init from the JSON
documentType = json[KeyCapabilities].toString().toULongLong() & possibleCapabilities;
if (json[KeyName].toString() != documentName)
throw std::runtime_error("The document was edited outside of Vivy");
if (QJsonValue audio = json[KeySubDocuments][KeySubAudio]; !audio.isNull())
loadSubDocument(audio.toString(), Capabilities::AudioAble);
if (QJsonValue video = json[KeySubDocuments][KeySubVideo]; !video.isNull())
loadSubDocument(video.toString(), Capabilities::VideoAble);
if (QJsonValue internalAssSource = json[KeySubDocuments][KeyInternalAssSource];
!internalAssSource.isNull() && internalAssSource.toBool()) {
// ASS is inside Vivy document
throw std::runtime_error("The internal ASS feature is not supported for now");
} else if (QJsonValue ass = json[KeySubDocuments][KeySubAss]; !ass.isNull()) {
// ASS in its own ASS file
loadSubDocument(ass.toString(), Capabilities::AssAble);
}
}
loadSubDocument(name); bool
qDebug() << "CONSTRUCTOR: VivyDocument(" << name << "," << opt << "," VivyDocument::save() const noexcept
<< getDocumentCapabilitiesString() << ")"; {
return false;
} }
bool bool
...@@ -108,7 +145,7 @@ VivyDocument::rename(const QString &newName) noexcept ...@@ -108,7 +145,7 @@ VivyDocument::rename(const QString &newName) noexcept
{ {
/* Compute new paths */ /* Compute new paths */
const QString newNameWithExtension = const QString newNameWithExtension =
newName.right(filePrefix.size()) == filePrefix ? newName : newName + "." + filePrefix; newName.right(fileSuffix.size()) == fileSuffix ? newName : newName + "." + fileSuffix;
const QFileInfo newPath(documentLocation, newNameWithExtension); const QFileInfo newPath(documentLocation, newNameWithExtension);
return renameWith(newPath, [=, this]() noexcept -> void { return renameWith(newPath, [=, this]() noexcept -> void {
......
...@@ -21,20 +21,23 @@ class VivyDocument final : public AbstractDocument { ...@@ -21,20 +21,23 @@ class VivyDocument final : public AbstractDocument {
Q_OBJECT Q_OBJECT
VIVY_UNMOVABLE_OBJECT(VivyDocument) VIVY_UNMOVABLE_OBJECT(VivyDocument)
public: enum JsonKey {
enum Capabilities : quint64 { KeyCapabilities,
AudioAble = (1 << 1), KeyName,
VideoAble = (1 << 2), KeySubDocuments,
AssAble = (1 << 3), KeySubAudio,
KeySubAss,
KeySubVideo,
KeyInternalAssSource
}; };
enum Options : quint64 { public:
NoOption = 0, enum Capabilities : quint64 { AudioAble = (1 << 1), VideoAble = (1 << 2), AssAble = (1 << 3) };
UntouchedByDefault = (1 << 1), enum Options : quint64 { NoOption = 0, UntouchedByDefault = (1 << 1) };
};
static inline const QString filePrefix{ "vivy" }; static inline const QString fileSuffix{ "vivy" };
static inline constexpr Utils::DocumentType type = Utils::DocumentType::Vivy; static inline constexpr Utils::DocumentType type = Utils::DocumentType::Vivy;
static constexpr inline quint64 possibleCapabilities = AudioAble | VideoAble | AssAble;
private: private:
/* The document name */ /* The document name */
...@@ -59,6 +62,7 @@ public: ...@@ -59,6 +62,7 @@ public:
explicit VivyDocument(const QString &name, Options opt = NoOption); explicit VivyDocument(const QString &name, Options opt = NoOption);
bool rename(const QString &) noexcept override; bool rename(const QString &) noexcept override;
bool save() const noexcept override;
bool loadSubDocument(const QString &) noexcept; bool loadSubDocument(const QString &) noexcept;
bool loadSubDocument(const QString &, Capabilities) noexcept; bool loadSubDocument(const QString &, Capabilities) noexcept;
......
...@@ -14,5 +14,6 @@ public: ...@@ -14,5 +14,6 @@ public:
explicit ScriptDocument(const QString &name); explicit ScriptDocument(const QString &name);
bool rename(const QString &) noexcept override; bool rename(const QString &) noexcept override;
bool save() const noexcept override { return false; }
}; };
} }
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter