Kgapi

filemodifyjob.cpp
1/*
2 * This file is part of LibKGAPI library
3 *
4 * SPDX-FileCopyrightText: 2013 Daniel Vrátil <dvratil@redhat.com>
5 *
6 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
7 */
8
9#include "filemodifyjob.h"
10#include "debug.h"
11#include "driveservice.h"
12#include "file.h"
13#include "utils.h"
14
15#include <QNetworkAccessManager>
16#include <QNetworkRequest>
17#include <QUrlQuery>
18
19using namespace KGAPI2;
20using namespace KGAPI2::Drive;
21
22class Q_DECL_HIDDEN FileModifyJob::Private
23{
24public:
25 Private();
26
27 QMap<QString /* filepath */, QString /* fileId */> files;
28
29 bool createNewRevision = true;
30 bool changeModifiedDate = false;
31 bool updateViewedDate = true;
32};
33
34FileModifyJob::Private::Private()
35{
36}
37
38FileModifyJob::FileModifyJob(const FilePtr &metadata, const AccountPtr &account, QObject *parent)
39 : FileAbstractUploadJob(metadata, account, parent)
40 , d(new Private)
41{
42 d->files.insert(QStringLiteral("?=0"), metadata->id());
43 setSerializationOptions(File::ExcludeCreationDate);
44}
45
46FileModifyJob::FileModifyJob(const QString &filePath, const QString &fileId, const AccountPtr &account, QObject *parent)
47 : FileAbstractUploadJob(filePath, account, parent)
48 , d(new Private)
49{
50 d->files.insert(filePath, fileId);
51}
52
53FileModifyJob::FileModifyJob(const QString &filePath, const FilePtr &metaData, const AccountPtr &account, QObject *parent)
54 : FileAbstractUploadJob(filePath, metaData, account, parent)
55 , d(new Private)
56{
57 d->files.insert(filePath, metaData->id());
58 setSerializationOptions(File::ExcludeCreationDate);
59}
60
61FileModifyJob::FileModifyJob(const QMap<QString, QString> &files, const AccountPtr &account, QObject *parent)
62 : FileAbstractUploadJob(files.keys(), account, parent)
63 , d(new Private)
64{
65 d->files = files;
66}
67
68FileModifyJob::FileModifyJob(const QMap<QString, FilePtr> &files, const AccountPtr &account, QObject *parent)
69 : FileAbstractUploadJob(files, account, parent)
70 , d(new Private)
71{
74 for (; iter != iterEnd; ++iter) {
75 d->files.insert(iter.key(), iter.value()->id());
76 }
77 setSerializationOptions(File::ExcludeCreationDate);
78}
79
80FileModifyJob::~FileModifyJob()
81{
82 delete d;
83}
84
85bool FileModifyJob::createNewRevision() const
86{
87 return d->createNewRevision;
88}
89
90void FileModifyJob::setCreateNewRevision(bool createNewRevision)
91{
92 if (isRunning()) {
93 qCWarning(KGAPIDebug) << "Can't modify createNewRevision property when the job is running";
94 return;
95 }
96
97 d->createNewRevision = createNewRevision;
98}
99
100bool FileModifyJob::updateModifiedDate() const
101{
102 return d->updateViewedDate;
103}
104
105void FileModifyJob::setUpdateModifiedDate(bool updateModifiedDate)
106{
107 if (isRunning()) {
108 qCWarning(KGAPIDebug) << "Can't modify updateModifiedDate property when the job is running";
109 return;
110 }
111
112 d->updateViewedDate = updateModifiedDate;
113}
114
115bool FileModifyJob::updateViewedDate() const
116{
117 return d->updateViewedDate;
118}
119
120void FileModifyJob::setUpdateViewedDate(bool updateViewedDate)
121{
122 if (isRunning()) {
123 qCWarning(KGAPIDebug) << "Can't modify updateViewedDate property when job is running";
124 return;
125 }
126
127 d->updateViewedDate = updateViewedDate;
128}
129
130QUrl FileModifyJob::createUrl(const QString &filePath, const FilePtr &metaData)
131{
132 QUrl url;
133
134 if (metaData.isNull()) {
135 url = DriveService::uploadMediaFileUrl(d->files.value(filePath));
136 } else if (filePath.isEmpty()) {
137 url = DriveService::uploadMetadataFileUrl(metaData->id());
138 } else {
139 url = DriveService::uploadMultipartFileUrl(d->files.value(filePath));
140 }
141
142 QUrlQuery query(url);
143 query.addQueryItem(QStringLiteral("newRevision"), Utils::bool2Str(d->createNewRevision));
144 query.addQueryItem(QStringLiteral("setModifiedDate"), Utils::bool2Str(d->changeModifiedDate));
145 query.addQueryItem(QStringLiteral("updateViewedDate"), Utils::bool2Str(d->updateViewedDate));
146 url.setQuery(query);
147
148 return url;
149}
150
151QNetworkReply *FileModifyJob::dispatch(QNetworkAccessManager *accessManager, const QNetworkRequest &request, const QByteArray &data)
152{
153 return accessManager->put(request, data);
154}
155
156#include "moc_filemodifyjob.cpp"
AccountPtr account() const
Returns account used to authenticate requests.
Definition job.cpp:436
bool isRunning
Whether the job is running.
Definition job.h:67
std::optional< QSqlQuery > query(const QString &queryStatement)
A job to fetch a single map tile described by a StaticMapUrl.
Definition blog.h:16
ConstIterator
const_iterator constBegin() const const
const_iterator constEnd() const const
Key key(const T &value, const Key &defaultKey) const const
T value(const Key &key, const T &defaultValue) const const
QNetworkReply * put(const QNetworkRequest &request, QHttpMultiPart *multiPart)
QObject * parent() const const
bool isNull() const const
bool isEmpty() const const
void setQuery(const QString &query, ParsingMode mode)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:00:12 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.