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

DOC: Add the load from .vivy file

parent 2527588b
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!18Implement the VivyDocument specification
......@@ -58,6 +58,7 @@ protected:
public:
virtual bool rename(const QString &) noexcept = 0;
virtual bool save() const noexcept = 0;
QString getName() const noexcept { return name; }
Type getType() const noexcept { return type; }
......
......@@ -6,6 +6,8 @@
#include <QStringList>
#include <QJsonArray>
#include <QJsonObject>
#include <QJsonDocument>
#include <QTextStream>
using namespace Vivy;
......@@ -13,13 +15,48 @@ VivyDocument::VivyDocument(const QString &documentPath, Options opt)
: AbstractDocument(AbstractDocument::Type::Vivy, documentPath)
, documentOptions(opt)
{
QFileInfo file(name);
documentName = file.baseName();
documentLocation = file.absoluteDir();
QFileInfo fileInfo(name);
QFile file(name);
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);
qDebug() << "CONSTRUCTOR: VivyDocument(" << name << "," << opt << ","
<< getDocumentCapabilitiesString() << ")";
bool
VivyDocument::save() const noexcept
{
return false;
}
bool
......@@ -108,7 +145,7 @@ VivyDocument::rename(const QString &newName) noexcept
{
/* Compute new paths */
const QString newNameWithExtension =
newName.right(filePrefix.size()) == filePrefix ? newName : newName + "." + filePrefix;
newName.right(fileSuffix.size()) == fileSuffix ? newName : newName + "." + fileSuffix;
const QFileInfo newPath(documentLocation, newNameWithExtension);
return renameWith(newPath, [=, this]() noexcept -> void {
......
......@@ -21,20 +21,23 @@ class VivyDocument final : public AbstractDocument {
Q_OBJECT
VIVY_UNMOVABLE_OBJECT(VivyDocument)
public:
enum Capabilities : quint64 {
AudioAble = (1 << 1),
VideoAble = (1 << 2),
AssAble = (1 << 3),
enum JsonKey {
KeyCapabilities,
KeyName,
KeySubDocuments,
KeySubAudio,
KeySubAss,
KeySubVideo,
KeyInternalAssSource
};
enum Options : quint64 {
NoOption = 0,
UntouchedByDefault = (1 << 1),
};
public:
enum Capabilities : quint64 { AudioAble = (1 << 1), VideoAble = (1 << 2), AssAble = (1 << 3) };
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 constexpr inline quint64 possibleCapabilities = AudioAble | VideoAble | AssAble;
private:
/* The document name */
......@@ -59,6 +62,7 @@ public:
explicit VivyDocument(const QString &name, Options opt = NoOption);
bool rename(const QString &) noexcept override;
bool save() const noexcept override;
bool loadSubDocument(const QString &) noexcept;
bool loadSubDocument(const QString &, Capabilities) noexcept;
......
......@@ -14,5 +14,6 @@ public:
explicit ScriptDocument(const QString &name);
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