File: afcapp.cpp

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 (90 lines) | stat: -rw-r--r-- 2,347 bytes parent folder | download
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
84
85
86
87
88
89
90
/*
 * SPDX-FileCopyrightText: 2022 Kai Uwe Broulik <kde@broulik.de>
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include "afcapp.h"

#include "afc_debug.h"

using namespace KIO;

AfcApp::AfcApp() = default;

AfcApp::AfcApp(plist_t app)
{
    auto fetchAppField = [app](const char *key, QString &member) {
        plist_t plistItem = plist_dict_get_item(app, key);
        if (plistItem) {
            char *stringValue = nullptr;
            plist_get_string_val(plistItem, &stringValue);
            member = QString::fromUtf8(stringValue);
            free(stringValue);
        }
    };

    fetchAppField("CFBundleIdentifier", m_bundleId);
    fetchAppField("CFBundleDisplayName", m_displayName);

    plist_t sharingItem = plist_dict_get_item(app, "UIFileSharingEnabled");
    if (sharingItem) {
        const auto type = plist_get_node_type(sharingItem);
        switch (type) {
        case PLIST_BOOLEAN: {
            uint8_t sharingEnabled = 0;
            plist_get_bool_val(sharingItem, &sharingEnabled);
            m_sharingEnabled = sharingEnabled;
            break;
        }
        case PLIST_STRING: {
            char *sharingString = nullptr;
            plist_get_string_val(sharingItem, &sharingString);
            if (sharingString) {
                m_sharingEnabled = (strcmp(sharingString, "YES") == 0 || strcmp(sharingString, "true") == 0);
                free(sharingString);
            }
            break;
        }
        default:
            qCWarning(KIO_AFC_LOG) << "Unhandled plist node type" << type << "for file sharing enabled property";
            break;
        }
    }
}

bool AfcApp::isValid() const
{
    return !m_bundleId.isEmpty();
}

QString AfcApp::bundleId() const
{
    return m_bundleId;
}

QString AfcApp::displayName() const
{
    return m_displayName;
}

bool AfcApp::sharingEnabled() const
{
    return m_sharingEnabled;
}

QString AfcApp::iconPath() const
{
    return m_iconPath;
}

UDSEntry AfcApp::entry(const QString &name) const
{
    UDSEntry entry;
    entry.fastInsert(UDSEntry::UDS_NAME, !name.isEmpty() ? name : m_bundleId);
    entry.fastInsert(UDSEntry::UDS_DISPLAY_NAME, m_displayName);
    entry.fastInsert(UDSEntry::UDS_FILE_TYPE, S_IFDIR);
    if (!m_iconPath.isEmpty()) {
        entry.fastInsert(UDSEntry::UDS_ICON_NAME, m_iconPath);
    }
    return entry;
}