Beispiel #1
0
void checkFileNameOrUrl(const QString &pInFileNameOrUrl, bool &pOutIsLocalFile,
                        QString &pOutFileNameOrUrl)
{
    // Determine whether pInFileNameOrUrl refers to a local file or a remote
    // one, and set pOutIsLocalFile and pOutFileNameOrUrl accordingly
    // Note #1: to use QUrl::isLocalFile() is not enough. Indeed, say that
    //          pInFileNameOrUrl is equal to
    //              /home/me/mymodel.cellml
    //          then QUrl(pInFileNameOrUrl).isLocalFile() will be false. For it
    //          to be true, we would have to initialise the QUrl object using
    //          QUrl::fromLocalFile(), but we can't do that since we don't know
    //          whether pInFileNameOrUrl refers to a local file or not. So,
    //          instead we test for the scheme and host of the QUrl object...
    // Note #2: a local file can be passed as a URL. For example,
    //              file:///home/me/mymodel.cellml
    //          is a URL, but effectively a local file, hence pOutIsLocalFile is
    //          to be true and pOutFileNameOrUrl is to be set to
    //              /home/me/mymodel.cellml

    QUrl fileNameOrUrl = pInFileNameOrUrl;

    pOutIsLocalFile =    !fileNameOrUrl.scheme().compare("file")
                      ||  fileNameOrUrl.host().isEmpty();
    pOutFileNameOrUrl = pOutIsLocalFile?
                            !fileNameOrUrl.scheme().compare("file")?
                                nativeCanonicalFileName(fileNameOrUrl.toLocalFile()):
                                nativeCanonicalFileName(pInFileNameOrUrl):
                            fileNameOrUrl.url();
}
Beispiel #2
0
FileManager::Status FileManager::unmanage(const QString &pFileName)
{
    QString nativeFileName = nativeCanonicalFileName(pFileName);

    if (QFileInfo(nativeFileName).exists()) {
        File *file = isManaged(nativeFileName);

        if (file) {
            // The file is managed, so we can remove it

            mFiles.removeAt(mFiles.indexOf(file));

            delete file;

            emit fileUnmanaged(nativeFileName);

            return Removed;
        } else {
            // The file isn't managed, so...

            return NotManaged;
        }
    } else {
        // The file doesn't exist, so...

        return NotManaged;
    }
}
Beispiel #3
0
File * FileManager::isManaged(const QString &pFileName) const
{
    QString nativeFileName = nativeCanonicalFileName(pFileName);

    foreach (File *file, mFiles)
        if (file->fileName() == nativeFileName)
            // The file has been found meaning it is managed

            return file;

    // The file couldn't be found meaning it's not managed

    return 0;
}
Beispiel #4
0
FileManager::Status FileManager::rename(const QString &pOldFileName,
                                        const QString &pNewFileName)
{
    // Check whether the 'old' file is managed

    QString oldFileName = nativeCanonicalFileName(pOldFileName);
    QString newFileName = nativeCanonicalFileName(pNewFileName);

    File *file = isManaged(oldFileName);

    if (!file) {
        // The 'old' file is not managed, so...

        return NotManaged;
    } else {
        // The 'old' file is managed, so we can rename it

        file->setFileName(newFileName);

        emit fileRenamed(oldFileName, newFileName);

        return Renamed;
    }
}
Beispiel #5
0
void FileManager::setModified(const QString &pFileName, const bool &pModified)
{
    // Set the modified status of the file, should it be managed

    File *file = isManaged(pFileName);

    if (file) {
        // We are dealing with a managed file, so we can check its modified
        // status and update it, if necessary, and then let people know about
        // the new modified status

        if (pModified == file->isModified())
            return;

        file->setModified(pModified);

        emit fileModified(nativeCanonicalFileName(pFileName), pModified);
    }
}
Beispiel #6
0
File::File(const QString &pFileName) :
    mFileName(nativeCanonicalFileName(pFileName)),
    mSha1(sha1()),
    mModified(false)
{
}