File indexing completed on 2024-04-21 04:57:26
0001 /* 0002 * SPDX-FileCopyrightText: 2022 Kai Uwe Broulik <kde@broulik.de> 0003 * SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #include "afcapp.h" 0007 0008 #include "afc_debug.h" 0009 0010 using namespace KIO; 0011 0012 AfcApp::AfcApp() = default; 0013 0014 AfcApp::AfcApp(plist_t app) 0015 { 0016 auto fetchAppField = [app](const char *key, QString &member) { 0017 plist_t plistItem = plist_dict_get_item(app, key); 0018 if (plistItem) { 0019 char *stringValue = nullptr; 0020 plist_get_string_val(plistItem, &stringValue); 0021 member = QString::fromUtf8(stringValue); 0022 free(stringValue); 0023 } 0024 }; 0025 0026 fetchAppField("CFBundleIdentifier", m_bundleId); 0027 fetchAppField("CFBundleDisplayName", m_displayName); 0028 0029 plist_t sharingItem = plist_dict_get_item(app, "UIFileSharingEnabled"); 0030 if (sharingItem) { 0031 const auto type = plist_get_node_type(sharingItem); 0032 switch (type) { 0033 case PLIST_BOOLEAN: { 0034 uint8_t sharingEnabled = 0; 0035 plist_get_bool_val(sharingItem, &sharingEnabled); 0036 m_sharingEnabled = sharingEnabled; 0037 break; 0038 } 0039 case PLIST_STRING: { 0040 char *sharingString = nullptr; 0041 plist_get_string_val(sharingItem, &sharingString); 0042 if (sharingString) { 0043 m_sharingEnabled = (strcmp(sharingString, "YES") == 0 || strcmp(sharingString, "true") == 0); 0044 free(sharingString); 0045 } 0046 break; 0047 } 0048 default: 0049 qCWarning(KIO_AFC_LOG) << "Unhandled plist node type" << type << "for file sharing enabled property"; 0050 break; 0051 } 0052 } 0053 } 0054 0055 bool AfcApp::isValid() const 0056 { 0057 return !m_bundleId.isEmpty(); 0058 } 0059 0060 QString AfcApp::bundleId() const 0061 { 0062 return m_bundleId; 0063 } 0064 0065 QString AfcApp::displayName() const 0066 { 0067 return m_displayName; 0068 } 0069 0070 bool AfcApp::sharingEnabled() const 0071 { 0072 return m_sharingEnabled; 0073 } 0074 0075 QString AfcApp::iconPath() const 0076 { 0077 return m_iconPath; 0078 } 0079 0080 UDSEntry AfcApp::entry(const QString &name) const 0081 { 0082 UDSEntry entry; 0083 entry.fastInsert(UDSEntry::UDS_NAME, !name.isEmpty() ? name : m_bundleId); 0084 entry.fastInsert(UDSEntry::UDS_DISPLAY_NAME, m_displayName); 0085 entry.fastInsert(UDSEntry::UDS_FILE_TYPE, S_IFDIR); 0086 if (!m_iconPath.isEmpty()) { 0087 entry.fastInsert(UDSEntry::UDS_ICON_NAME, m_iconPath); 0088 } 0089 return entry; 0090 }