fileabstractdatajob.cpp 4.94 KB
Newer Older
1 2 3
/*
 * This file is part of LibKGAPI library
 *
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 "fileabstractdatajob.h"
Daniel Vrátil's avatar
Daniel Vrátil committed
10
#include "../debug.h"
11 12
#include "utils.h"

13 14
#include <QUrlQuery>

15
using namespace KGAPI2;
16
using namespace KGAPI2::Drive;
17

18
class Q_DECL_HIDDEN FileAbstractDataJob::Private
19 20 21 22 23 24 25 26 27 28
{
  public:
    Private();

    bool convert;
    bool ocr;
    QString ocrLanguage;
    bool pinned;
    QString timedTextLanguage;
    QString timedTextTrackName;
29
    bool useContentAsIndexableText;
30
    bool supportsAllDrives;
31 32
};

33
FileAbstractDataJob::Private::Private():
34 35
    convert(false),
    ocr(false),
36
    pinned(false),
37
    useContentAsIndexableText(false),
38
    supportsAllDrives(true)
39 40 41
{
}

42 43
FileAbstractDataJob::FileAbstractDataJob(const AccountPtr &account,
                                         QObject *parent):
44 45 46 47 48
    Job(account, parent),
    d(new Private)
{
}

49
FileAbstractDataJob::~FileAbstractDataJob()
50 51 52 53
{
    delete d;
}

54
bool FileAbstractDataJob::convert() const
55 56 57 58
{
    return d->convert;
}

59
void FileAbstractDataJob::setConvert(bool convert)
60 61
{
    if (isRunning()) {
Daniel Vrátil's avatar
Daniel Vrátil committed
62
        qCWarning(KGAPIDebug) << "Can't modify setConvert property when job is running";
63 64 65 66 67 68
        return;
    }

    d->convert = convert;
}

69
bool FileAbstractDataJob::ocr() const
70 71 72 73
{
    return d->ocr;
}

74
void FileAbstractDataJob::setOcr(bool ocr)
75 76
{
    if (isRunning()) {
Daniel Vrátil's avatar
Daniel Vrátil committed
77
        qCWarning(KGAPIDebug) << "Can't modify ocr property when job is running";
78 79 80 81 82 83
        return;
    }

    d->ocr = ocr;
}

84
QString FileAbstractDataJob::ocrLanguage() const
85 86 87 88
{
    return d->ocrLanguage;
}

89
void FileAbstractDataJob::setOcrLanguage(const QString &ocrLanguage)
90 91
{
    if (isRunning()) {
Daniel Vrátil's avatar
Daniel Vrátil committed
92
        qCWarning(KGAPIDebug) << "Can't modify ocrLanguage property when job is running";
93 94 95 96 97 98
        return;
    }

    d->ocrLanguage = ocrLanguage;
}

99
bool FileAbstractDataJob::pinned() const
100 101 102 103
{
    return d->pinned;
}

104
void FileAbstractDataJob::setPinned(bool pinned)
105 106
{
    if (isRunning()) {
Daniel Vrátil's avatar
Daniel Vrátil committed
107
        qCWarning(KGAPIDebug) << "Can't modify pinned property when job is running";
108 109 110 111 112 113
        return;
    }

    d->pinned = pinned;
}

114
QString FileAbstractDataJob::timedTextLanguage() const
115 116 117 118 119
{
    return d->timedTextLanguage;
}


120
void FileAbstractDataJob::setTimedTextLanguage(const QString &timedTextLanguage)
121 122
{
    if (isRunning()) {
Daniel Vrátil's avatar
Daniel Vrátil committed
123
        qCWarning(KGAPIDebug) << "Can't modify timedTextLanguage property when job is running";
124 125 126 127 128 129
        return;
    }

    d->timedTextLanguage = timedTextLanguage;
}

130
QString FileAbstractDataJob::timedTextTrackName() const
131 132 133 134
{
    return d->timedTextLanguage;
}

135
void FileAbstractDataJob::setTimedTextTrackName(const QString &timedTextTrackName)
136 137
{
    if (isRunning()) {
Daniel Vrátil's avatar
Daniel Vrátil committed
138
        qCWarning(KGAPIDebug) << "Can't modify timedTextTrackName property when job is running";
139 140 141 142 143 144
        return;
    }

    d->timedTextTrackName = timedTextTrackName;
}

145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
void FileAbstractDataJob::setUseContentAsIndexableText(bool useContentAsIndexableText)
{
    if (isRunning()) {
        qCWarning(KGAPIDebug) << "Can't modify useContentAsIndexableText property when job is running";
        return;
    }

    d->useContentAsIndexableText = useContentAsIndexableText;
}

bool FileAbstractDataJob::useContentAsIndexableText() const
{
    return d->useContentAsIndexableText;
}

160 161 162 163 164 165 166 167 168 169
bool FileAbstractDataJob::supportsAllDrives() const
{
    return d->supportsAllDrives;
}

void FileAbstractDataJob::setSupportsAllDrives(bool supportsAllDrives)
{
    d->supportsAllDrives = supportsAllDrives;
}

170
QUrl FileAbstractDataJob::updateUrl(QUrl &url)
171
{
172 173 174
    QUrlQuery query(url);
    query.removeQueryItem(QStringLiteral("convert"));
    query.addQueryItem(QStringLiteral("convert"), Utils::bool2Str(d->convert));
175

176 177 178
    query.removeQueryItem(QStringLiteral("ocr"));
    query.removeQueryItem(QStringLiteral("ocrLanguage"));
    query.addQueryItem(QStringLiteral("ocr"), Utils::bool2Str(d->ocr));
179
    if (d->ocr && !d->ocrLanguage.isEmpty()) {
180
        query.addQueryItem(QStringLiteral("ocrLanguage"), d->ocrLanguage);
181 182
    }

183 184
    query.removeQueryItem(QStringLiteral("pinned"));
    query.addQueryItem(QStringLiteral("pinned"), Utils::bool2Str(d->pinned));
185

186
    query.removeQueryItem(QStringLiteral("timedTextLanguage"));
187
    if (!d->timedTextLanguage.isEmpty()) {
188
        query.addQueryItem(QStringLiteral("timedTextLanguage"), d->timedTextLanguage);
189 190
    }

191
    query.removeQueryItem(QStringLiteral("timedTextTrackName"));
192
    if (!d->timedTextTrackName.isEmpty()) {
193
        query.addQueryItem(QStringLiteral("timedTextTrackName"), d->timedTextTrackName);
194
    }
195 196 197
    
    query.removeQueryItem(QStringLiteral("useContentAsIndexableText"));
    query.addQueryItem(QStringLiteral("useContentAsIndexableText"), Utils::bool2Str(d->useContentAsIndexableText));
198

199 200 201 202
    query.removeQueryItem(QStringLiteral("supportsAllDrives"));
    query.addQueryItem(QStringLiteral("supportsAllDrives"), Utils::bool2Str(d->supportsAllDrives));

    url.setQuery(query);
203 204 205 206
    return url;
}


Daniel Vrátil's avatar
Daniel Vrátil committed
207
#include "moc_fileabstractdatajob.cpp"