File indexing completed on 2024-05-19 05:00:39

0001 /*
0002     SPDX-FileCopyrightText: 2020 Nicolas Fella <nicolas.fella@gmx.de>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-or-later
0005 */
0006 
0007 #include "gdrivejob.h"
0008 
0009 #include <KIO/CopyJob>
0010 
0011 QList<QUrl> arrayToList(const QJsonArray &array)
0012 {
0013     QList<QUrl> ret;
0014     for (const QJsonValue &val : array) {
0015         ret += val.toVariant().toUrl();
0016     }
0017     return ret;
0018 }
0019 
0020 void GDriveJob::start()
0021 {
0022     const QString accountName = data().value(QStringLiteral("accountName")).toString();
0023     QString folder = data().value(QStringLiteral("folder")).toString();
0024 
0025     if (!folder.startsWith(QLatin1Char('/'))) {
0026         folder.prepend(QLatin1Char('/'));
0027     }
0028 
0029     QUrl destUrl;
0030     destUrl.setScheme(QStringLiteral("gdrive"));
0031     destUrl.setPath(accountName + folder);
0032 
0033     const QList<QUrl> sourceUrls = arrayToList(data().value(QStringLiteral("urls")).toArray());
0034 
0035     KIO::CopyJob *copyJob = KIO::copy(sourceUrls, destUrl);
0036 
0037     connect(copyJob, &KIO::CopyJob::finished, this, [this, copyJob] {
0038         if (copyJob->error()) {
0039             setError(copyJob->error());
0040             setErrorText(copyJob->errorText());
0041         }
0042         emitResult();
0043     });
0044 
0045     copyJob->start();
0046 }