Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qdarwinpermissionplugin_calendar.mm
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5
6#include <EventKit/EventKit.h>
7
8@interface QDarwinCalendarPermissionHandler ()
9@property (nonatomic, retain) EKEventStore *eventStore;
10@end
11
12@implementation QDarwinCalendarPermissionHandler
13- (Qt::PermissionStatus)checkPermission:(QPermission)permission
14{
15 Q_UNUSED(permission);
16 return [self currentStatus];
17}
18
19- (Qt::PermissionStatus)currentStatus
20{
21 auto status = [EKEventStore authorizationStatusForEntityType:EKEntityTypeEvent];
22 switch (status) {
23 case EKAuthorizationStatusNotDetermined:
24 return Qt::PermissionStatus::Undetermined;
25 case EKAuthorizationStatusRestricted:
26 case EKAuthorizationStatusDenied:
27 return Qt::PermissionStatus::Denied;
28 case EKAuthorizationStatusAuthorized:
29 return Qt::PermissionStatus::Granted;
30 case EKAuthorizationStatusWriteOnly:
31 // FIXME: Add WriteOnly AccessMode
32 return Qt::PermissionStatus::Denied;
33 }
34
35 qCWarning(lcPermissions) << "Unknown permission status" << status << "detected in" << self;
36 return Qt::PermissionStatus::Denied;
37}
38
39- (QStringList)usageDescriptionsFor:(QPermission)permission
40{
41 Q_UNUSED(permission);
42 return { "NSCalendarsUsageDescription" };
43}
44
45- (void)requestPermission:(QPermission)permission withCallback:(PermissionCallback)callback
46{
47 if (!self.eventStore) {
48 // Note: Creating the EKEventStore results in warnings in the
49 // console about "An error occurred in the persistent store".
50 // This seems like a EventKit API bug.
51 self.eventStore = [[EKEventStore new] autorelease];
52 }
53
54 [self.eventStore requestAccessToEntityType:EKEntityTypeEvent
55 completion:^(BOOL granted, NSError * _Nullable error) {
56 Q_UNUSED(granted); // We use status instead
57 // Permission denied will result in an error, which we don't
58 // want to report/log, so we ignore the error and just report
59 // the status.
60 Q_UNUSED(error);
61
62 callback([self currentStatus]);
63 }
64 ];
65}
66
67@end
68
69#include "moc_qdarwinpermissionplugin_p_p.cpp"
QList< QString > QStringList
Constructs a string list that contains the given string, str.