UBPersistenceWorker.cpp 2.96 KB
Newer Older
1
/*
2
 * Copyright (C) 2015-2018 Département de l'Instruction Publique (DIP-SEM)
3
 *
Craig Watson's avatar
Craig Watson committed
4 5 6 7
 * Copyright (C) 2013 Open Education Foundation
 *
 * Copyright (C) 2010-2013 Groupement d'Intérêt Public pour
 * l'Education Numérique en Afrique (GIP ENA)
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
 *
 * This file is part of OpenBoard.
 *
 * OpenBoard is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 3 of the License,
 * with a specific linking exception for the OpenSSL project's
 * "OpenSSL" library (or with modified versions of it that use the
 * same license as the "OpenSSL" library).
 *
 * OpenBoard is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with OpenBoard. If not, see <http://www.gnu.org/licenses/>.
 */



#include "UBPersistenceWorker.h"
#include "adaptors/UBSvgSubsetAdaptor.h"
#include "adaptors/UBThumbnailAdaptor.h"
32
#include "adaptors/UBMetadataDcSubsetAdaptor.h"
33 34 35 36 37 38 39 40 41

UBPersistenceWorker::UBPersistenceWorker(QObject *parent) :
    QObject(parent)
  , mReceivedApplicationClosing(false)
{
}

void UBPersistenceWorker::saveScene(UBDocumentProxy* proxy, UBGraphicsScene* scene, const int pageIndex)
{
42 43 44
    PersistenceInformation entry = {WriteScene, proxy, scene, pageIndex};

    saves.append(entry);
45 46 47 48 49
    mSemaphore.release();
}

void UBPersistenceWorker::readScene(UBDocumentProxy* proxy, const int pageIndex)
{
50 51 52
    PersistenceInformation entry = {ReadScene, proxy, 0, pageIndex};

    saves.append(entry);
53 54 55
    mSemaphore.release();
}

56 57 58 59 60 61 62
void UBPersistenceWorker::saveMetadata(UBDocumentProxy *proxy)
{
    PersistenceInformation entry = {WriteMetadata, proxy, NULL, 0};
    saves.append(entry);
    mSemaphore.release();
}

63 64 65 66 67 68 69 70 71 72 73 74 75
void UBPersistenceWorker::applicationWillClose()
{
    qDebug() << "applicaiton Will close signal received";
    mReceivedApplicationClosing = true;
    mSemaphore.release();
}

void UBPersistenceWorker::process()
{
    qDebug() << "process starts";
    mSemaphore.acquire();
    do{
        PersistenceInformation info = saves.takeFirst();
76
        if(info.action == WriteScene){
77
            UBSvgSubsetAdaptor::persistScene(info.proxy, info.scene, info.sceneIndex);
78
            emit scenePersisted(info.scene);
79
        }
80
        else if (info.action == ReadScene){
81 82
            emit sceneLoaded(UBSvgSubsetAdaptor::loadSceneAsText(info.proxy,info.sceneIndex), info.proxy, info.sceneIndex);
        }
83 84 85 86 87 88
        else if (info.action == WriteMetadata) {
            if (info.proxy->isModified()) {
                UBMetadataDcSubsetAdaptor::persist(info.proxy);
                emit metadataPersisted(info.proxy);
            }
        }
89 90 91 92 93
        mSemaphore.acquire();
    }while(!mReceivedApplicationClosing);
    qDebug() << "process will stop";
    emit finished();
}