File: kio_mtp.h

package info (click to toggle)
kio-extras 4%3A25.04.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 31,928 kB
  • sloc: cpp: 28,852; ansic: 3,084; perl: 1,048; xml: 116; sh: 92; python: 28; makefile: 9
file content (83 lines) | stat: -rw-r--r-- 2,319 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
 *  Main implementation for KIO-MTP
 *  SPDX-FileCopyrightText: 2012 Philipp Schmidt <philschmidt@gmx.net>
 *  SPDX-FileCopyrightText: 2018 Andreas Krutzler <andreas.krutzler@gmx.net>
 *  SPDX-FileCopyrightText: 2022 Harald Sitter <sitter@kde.org>
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 */

#pragma once

#include <KIO/Global>
#include <KIO/WorkerBase>
#include <KLocalizedString>

#include <errno.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <time.h>

// #include <QCache>

#include <QUrl>

#define MAX_XFER_BUF_SIZE 16348
#define KIO_MTP 7000
#include <kmtpdinterface.h>

class KMTPDeviceInterface;
class KMTPStorageInterface;
class KMTPFile;

using namespace KIO;

class MTPWorker : public QObject, public KIO::WorkerBase
{
    Q_OBJECT

    enum class Url {
        Invalid = -1,
        Valid = 0,
        Redirected = 1,
        NotFound = 2,
    };

public:
    /*
     * Overwritten KIO-functions, see "kio_mtp.cpp"
     */
    MTPWorker(const QByteArray &pool, const QByteArray &app);
    ~MTPWorker() override;

    WorkerResult listDir(const QUrl &url) override;
    WorkerResult stat(const QUrl &url) override;
    WorkerResult mimetype(const QUrl &url) override;
    WorkerResult get(const QUrl &url) override;
    WorkerResult put(const QUrl &url, int, JobFlags flags) override;
    WorkerResult copy(const QUrl &src, const QUrl &dest, int, JobFlags flags) override;
    WorkerResult mkdir(const QUrl &url, int) override;
    WorkerResult del(const QUrl &url, bool) override;
    WorkerResult rename(const QUrl &src, const QUrl &dest, JobFlags flags) override;
    WorkerResult fileSystemFreeSpace(const QUrl &url) override;
    WorkerResult chmod(const QUrl &url, int permissions) override;
    WorkerResult chown(const QUrl &url, const QString &owner, const QString &group) override;

private:
    /**
     * Check if it is a valid url or an udi.
     *
     * @param url The url to checkUrl
     * @return enum MTPWorker::Url
     */
    enum MTPWorker::Url checkUrl(const QUrl &url);

    /**
     * @brief Waits for a pending copy operation to finish while updating its progress.
     * @param storage
     * @return The result of the operation, usually 0 if valid
     */
    int waitForCopyOperation(const KMTPStorageInterface *storage);

    KMTPDInterface m_kmtpDaemon;
};