File: afcdevice.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 (82 lines) | stat: -rw-r--r-- 1,978 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
/*
 * SPDX-FileCopyrightText: 2022 Kai Uwe Broulik <kde@broulik.de>
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#pragma once

#include <QList>
#include <QObject>

#include <KIO/WorkerBase>

#include <libimobiledevice/afc.h>
#include <libimobiledevice/libimobiledevice.h>
#include <libimobiledevice/lockdown.h>

#include "afcclient.h"
#include "afcdiskusage.h"
#include "afcfilereader.h"

#include <KIO/UDSEntry>

class AfcApp;

struct LockdowndClientCleanup {
    static inline void cleanup(lockdownd_client_t lockdowndClient)
    {
        if (lockdowndClient) {
            lockdownd_client_free(lockdowndClient);
        }
    }
};
using ScopedLockdowndClientPtr = QScopedPointer<lockdownd_client_private, LockdowndClientCleanup>;

class AfcDevice
{
public:
    explicit AfcDevice(const QString &id);
    ~AfcDevice();

    idevice_t device() const;

    QString id() const;
    bool isValid() const;
    QString errorText() const;

    QString name() const;
    QString deviceClass() const;

    QString cacheLocation() const;

    KIO::WorkerResult client(const QString &appId, AfcClient::Ptr &client);

    AfcApp app(const QString &bundleId);
    KIO::WorkerResult apps(QList<AfcApp> &apps);

    KIO::WorkerResult fetchAppIcon(AfcApp &app);
    // Fetches app icons for the list of apps provided.
    KIO::WorkerResult fetchAppIcons(QList<AfcApp> &apps);

private:
    KIO::WorkerResult handshake();
    QString appIconCachePath(const QString &bundleId) const;

    idevice_t m_device = nullptr;

    ScopedLockdowndClientPtr m_lockdowndClient;
    bool m_handshakeSuccessful = false;

    afc_client_t m_afcClient = nullptr;

    QString m_id;
    QString m_name;
    QString m_deviceClass;

    QHash<QString, AfcApp> m_apps;

    // We can't have too many simultaneous house arrest connections
    // so store only the last requested client which in the majority case
    // should be the one where subsequent requests go to
    AfcClient::Ptr m_lastClient;
};