File indexing completed on 2024-12-01 04:48:03

0001 /*
0002     This file is part of oxaccess.
0003 
0004     SPDX-FileCopyrightText: 2010 Tobias Koenig <tokoe@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 #include "foldersrequestdeltajob.h"
0010 
0011 #include "foldersrequestjob.h"
0012 
0013 using namespace OXA;
0014 
0015 FoldersRequestDeltaJob::FoldersRequestDeltaJob(qulonglong lastSync, QObject *parent)
0016     : KJob(parent)
0017     , mLastSync(lastSync)
0018 {
0019 }
0020 
0021 void FoldersRequestDeltaJob::start()
0022 {
0023     auto modifiedJob = new FoldersRequestJob(mLastSync, FoldersRequestJob::Modified, this);
0024     connect(modifiedJob, &FoldersRequestJob::result, this, &FoldersRequestDeltaJob::fetchModifiedJobFinished);
0025     modifiedJob->start();
0026 
0027     auto deletedJob = new FoldersRequestJob(mLastSync, FoldersRequestJob::Deleted, this);
0028     connect(deletedJob, &FoldersRequestJob::result, this, &FoldersRequestDeltaJob::fetchDeletedJobFinished);
0029     deletedJob->start();
0030 }
0031 
0032 Folder::List FoldersRequestDeltaJob::modifiedFolders() const
0033 {
0034     return mModifiedFolders;
0035 }
0036 
0037 Folder::List FoldersRequestDeltaJob::deletedFolders() const
0038 {
0039     return mDeletedFolders;
0040 }
0041 
0042 void FoldersRequestDeltaJob::fetchModifiedJobFinished(KJob *job)
0043 {
0044     if (job->error()) {
0045         setError(job->error());
0046         setErrorText(job->errorText());
0047         emitResult();
0048         return;
0049     }
0050 
0051     const FoldersRequestJob *requestJob = qobject_cast<FoldersRequestJob *>(job);
0052 
0053     mModifiedFolders << requestJob->folders();
0054 
0055     mJobFinishedCount++;
0056 
0057     if (mJobFinishedCount == 2) {
0058         emitResult();
0059     }
0060 }
0061 
0062 void FoldersRequestDeltaJob::fetchDeletedJobFinished(KJob *job)
0063 {
0064     if (job->error()) {
0065         setError(job->error());
0066         setErrorText(job->errorText());
0067         emitResult();
0068         return;
0069     }
0070 
0071     const FoldersRequestJob *requestJob = qobject_cast<FoldersRequestJob *>(job);
0072 
0073     mDeletedFolders << requestJob->folders();
0074 
0075     mJobFinishedCount++;
0076 
0077     if (mJobFinishedCount == 2) {
0078         emitResult();
0079     }
0080 }
0081 
0082 #include "moc_foldersrequestdeltajob.cpp"