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

#include "afcurl.h"

AfcUrl::AfcUrl(const QUrl &url)
    : m_url(url)
{
    if (!url.isValid() || url.scheme() != QLatin1String("afc")) {
        return;
    }

    m_device = url.host().toUpper();
    m_path = url.path();

    if (!m_path.isEmpty()) {
        Q_ASSERT(m_path.startsWith(QLatin1Char('/')));
    }

    const QString appsPrefix = QLatin1Char('/') + appsTag();
    if (m_path == appsPrefix || m_path.startsWith(appsPrefix + QLatin1Char('/'))) {
        m_browseMode = BrowseMode::Apps;
        m_path = m_path.mid(appsPrefix.length());

        int slashAfterAppIdx = m_path.indexOf(QLatin1Char('/'), 1);
        if (slashAfterAppIdx == -1) {
            slashAfterAppIdx = m_path.length();
        }

        m_appId = m_path.mid(1, slashAfterAppIdx - 1); // exclude slashes in app ID
        m_path = m_path.mid(slashAfterAppIdx); // include leading slash in path
    } else {
        m_browseMode = BrowseMode::FileSystem;
    }

    if (m_path == QLatin1Char('/')) {
        m_path.clear();
    }
}

QUrl AfcUrl::url() const
{
    return m_url;
}

AfcUrl::BrowseMode AfcUrl::browseMode() const
{
    return m_browseMode;
}

QString AfcUrl::device() const
{
    return m_device;
}

QString AfcUrl::appId() const
{
    return m_appId;
}

QString AfcUrl::path() const
{
    return m_path;
}

bool AfcUrl::isValid() const
{
    return m_browseMode == BrowseMode::FileSystem || m_browseMode == BrowseMode::Apps;
}

QString AfcUrl::appsTag()
{
    return QStringLiteral("@apps");
}