File indexing completed on 2025-02-02 05:02:28

0001 /*
0002     SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "filehelper.h"
0008 
0009 #include <QString>
0010 #include <QUrl>
0011 
0012 #ifdef Q_OS_ANDROID
0013 #include <kandroidextras/contentresolver.h>
0014 #endif
0015 
0016 #include <cstring>
0017 
0018 using namespace Qt::Literals::StringLiterals;
0019 
0020 bool FileHelper::isLocalFile(const QUrl &url)
0021 {
0022     return url.isLocalFile() || url.scheme() == QLatin1StringView("content");
0023 }
0024 
0025 QString FileHelper::toLocalFile(const QUrl &url)
0026 {
0027     return url.isLocalFile() ? url.toLocalFile() : url.toString(QUrl::FullyEncoded);
0028 }
0029 
0030 QString FileHelper::fileName(const QUrl &url)
0031 {
0032 #if defined(Q_OS_ANDROID)
0033     if (url.scheme() == "content"_L1) {
0034         return KAndroidExtras::ContentResolver::fileName(url);
0035     }
0036 #endif
0037     return url.fileName();
0038 }
0039 
0040 bool FileHelper::hasZipHeader(const QByteArray &data)
0041 {
0042     return data.size() >= 4 && std::strncmp(data.constData(), "PK\x03\x04", 4) == 0;
0043 }