From 1656ea2f8b0c56b36f877e3b5e93ad1e7cee725b Mon Sep 17 00:00:00 2001 From: Felix Berlakovich Date: Wed, 11 Feb 2026 17:12:10 +0100 Subject: [PATCH] Use Qt built-in QString::toNSString/fromNSString --- src/autofill/AutoFill.mm | 55 +++++++++++----------------------------- 1 file changed, 15 insertions(+), 40 deletions(-) diff --git a/src/autofill/AutoFill.mm b/src/autofill/AutoFill.mm index 7822b80f6..7d89bcb55 100644 --- a/src/autofill/AutoFill.mm +++ b/src/autofill/AutoFill.mm @@ -50,31 +50,6 @@ Q_LOGGING_CATEGORY(lcAutoFill, "keepassxc.autofill") -namespace -{ -NSString* toNSString(const QString& value) -{ - if (value.isEmpty()) { - return @""; - } - return [NSString stringWithCharacters:reinterpret_cast(value.constData()) length:value.size()]; -} - -QString fromNSString(NSString* value) -{ - if (!value) { - return {}; - } - - const char* buffer = [value UTF8String]; - if (!buffer) { - return {}; - } - - return QString::fromUtf8(buffer); -} -} - @class AutoFillHostAdapter; class AutoFillPrivate : public QObject @@ -167,7 +142,7 @@ private: return; } void (^replyCopy)(NSArray*>*) = [reply copy]; - QString host = fromNSString(domain); + QString host = QString::fromNSString(domain); AutoFillPrivate* owner = self.owner; if (!owner) { replyCopy(@[]); @@ -183,7 +158,7 @@ private: return; } void (^replyCopy)(NSDictionary*) = [reply copy]; - QString identifier = fromNSString(recordIdentifier); + QString identifier = QString::fromNSString(recordIdentifier); AutoFillPrivate* owner = self.owner; if (!owner) { replyCopy(@{}); @@ -393,12 +368,12 @@ void AutoFillPrivate::refreshIdentityStore() auto identities = [NSMutableArray arrayWithCapacity:records.size()]; for (const auto& record : records) { auto* serviceIdentifier = [[ASCredentialServiceIdentifier alloc] - initWithIdentifier:toNSString(record.domain) + initWithIdentifier:record.domain.toNSString() type:ASCredentialServiceIdentifierTypeDomain]; auto* identity = [[ASPasswordCredentialIdentity alloc] initWithServiceIdentifier:serviceIdentifier - user:toNSString(record.username) - recordIdentifier:toNSString(record.recordIdentifier)]; + user:record.username.toNSString() + recordIdentifier:record.recordIdentifier.toNSString()]; [identities addObject:identity]; } @@ -418,7 +393,7 @@ void AutoFillPrivate::refreshIdentityStore() } else if (error) { qCWarning(lcAutoFill) << "Unable to refresh AutoFill identities:" - << fromNSString(error.localizedDescription); + << QString::fromNSString(error.localizedDescription); } }]; }); @@ -476,14 +451,14 @@ void AutoFillPrivate::connectToServiceIfNeeded() id remote = [m_serviceConnection remoteObjectProxyWithErrorHandler:^(NSError* error) { - qCWarning(lcAutoFill) << "AutoFill XPC service unavailable:" << fromNSString(error.localizedDescription); + qCWarning(lcAutoFill) << "AutoFill XPC service unavailable:" << QString::fromNSString(error.localizedDescription); }]; [remote registerProvider:m_listener.endpoint withReply:^(NSError* error) { if (error) { qCWarning(lcAutoFill) << "Failed to register AutoFill provider:" - << fromNSString(error.localizedDescription); + << QString::fromNSString(error.localizedDescription); return; } qCDebug(lcAutoFill) << "Successfully registered AutoFill provider."; @@ -729,14 +704,14 @@ NSDictionary* AutoFillPrivate::serializeCredential(const Credenti } NSMutableDictionary* dict = [NSMutableDictionary dictionary]; - dict[AutoFillCredentialRecordIdentifierKey] = toNSString(record.recordIdentifier); - dict[AutoFillCredentialDomainKey] = toNSString(record.domain); - dict[AutoFillCredentialUsernameKey] = toNSString(record.username); - dict[AutoFillCredentialPasswordKey] = toNSString(record.password); - dict[AutoFillCredentialTitleKey] = toNSString(record.title); - dict[AutoFillCredentialUrlKey] = toNSString(record.url); + dict[AutoFillCredentialRecordIdentifierKey] = record.recordIdentifier.toNSString(); + dict[AutoFillCredentialDomainKey] = record.domain.toNSString(); + dict[AutoFillCredentialUsernameKey] = record.username.toNSString(); + dict[AutoFillCredentialPasswordKey] = record.password.toNSString(); + dict[AutoFillCredentialTitleKey] = record.title.toNSString(); + dict[AutoFillCredentialUrlKey] = record.url.toNSString(); if (!record.otp.isEmpty()) { - dict[AutoFillCredentialOtpKey] = toNSString(record.otp); + dict[AutoFillCredentialOtpKey] = record.otp.toNSString(); } return dict; }