Skip to content
Extraits de code Groupes Projets

Implement the VivyDocument specification

Fusionnées Kubat a demandé de fusionner vivy-doc vers master
4 files
+ 61
18
Comparer les modifications
  • Côte à côte
  • En ligne

Fichiers

+ 44
7
@@ -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 {
Chargement en cours