Skip to content
Extraits de code Groupes Projets
Sélectionner une révision Git
  • 314c9a751ae2734c432c1465078a82ea2acf8386
  • master par défaut protégée
  • devel
  • v5.2.6
  • v5.2.5
5 résultats

Action.pm

Blame
    • ElTata's avatar
      314c9a75
      commit title · 314c9a75
      ElTata a rédigé
      - actions results now show the roll and the atk/def multiplicator
      - POINTS command shows how many points the user have to spend
      - style corrections (aligment, empty lines...)
      314c9a75
      Historique
      commit title
      ElTata a rédigé
      - actions results now show the roll and the atk/def multiplicator
      - POINTS command shows how many points the user have to spend
      - style corrections (aligment, empty lines...)
    VivyDocument.cc 2,70 Kio
    #include "VivyDocument.h"
    
    #include <QStringList>
    #include <QString>
    #include <QFileInfo>
    
    VivyDocument::VivyDocument(const QString &name)
        : documentName(name)
    {
    }
    
    bool
    VivyDocument::loadSubDocument(const QString &name) noexcept
    {
        QFileInfo file(name);
        SubDocument type;
    
        if (detectDocumentType(file, &type)) {
            switch (type) {
            case SubDocument::Audio:
                audioFile = name;
                break;
    
            case SubDocument::Video:
                videoFile = name;
                break;
    
            case SubDocument::ASS:
                assFile = name;
                break;
            }
    
            return true;
        }
    
        return false;
    }
    
    bool
    VivyDocument::detectDocumentType(const QFileInfo &file, VivyDocument::SubDocument *type)
    {
        const QString suffix               = file.suffix();
        static QStringList audioFileSuffix = { "wave", "ogg", "mp3" };
        static QStringList videoFileSuffix = { "mkv", "mp4" };
        static QStringList assFileSuffix   = { "ass", "vivy" };
    
        if (audioFileSuffix.contains(suffix, Qt::CaseInsensitive)) {
            *type = SubDocument::Audio;
            return true;
        }
        if (videoFileSuffix.contains(suffix, Qt::CaseInsensitive)) {
            *type = SubDocument::Video;
            return true;
        }
        if (assFileSuffix.contains(suffix, Qt::CaseInsensitive)) {
            *type = SubDocument::ASS;
            return true;
        }
    
        return false;
    }
    
    bool
    VivyDocument::rename(const QString &name) noexcept
    {
        /* Compute new paths */
        const QString newNameWithExtension = name.right(filePrefix.size()) == filePrefix ? name : name + "." + filePrefix;
        QFileInfo oldPath(documentLocation, documentName + "." + filePrefix);
        QFileInfo newPath(documentLocation, newNameWithExtension);
    
        /* Create folder if needed */
        QDir dirOp;
        const QString newAbsDirPath = newPath.dir().absolutePath();
        if (!dirOp.exists(newAbsDirPath))
            dirOp.mkpath(newAbsDirPath);
    
        if (dirOp.rename(oldPath.absoluteFilePath(), newPath.absoluteFilePath())) {
            documentLocation = newPath.dir();
            documentName     = newPath.baseName();
            return true;
        }
        return false;
    }
    
    QString
    VivyDocument::getSubDocument(SubDocument subType) const noexcept
    {
        if ((documentType & subType) == 0) {
            QString ret;
            return ret;
        }
    
        switch (subType) {
        case SubDocument::Audio:
            return audioFile;
        case SubDocument::Video:
            return videoFile;
        case SubDocument::ASS:
            return assFile;
        }
    }
    
    VivyDocument *
    VivyDocument::fromPath(const QString &path) noexcept
    {
        return nullptr;
    }
    
    VivyDocument *
    VivyDocument::newEmpty(const QString &name) noexcept
    {
        return nullptr;
    }
    
    QString
    VivyDocument::getName() const noexcept
    {
        return documentName;
    }