Q{Contact,Calendar}Permission: rename isReadOnly → isReadWrite

The typed permission classes' properties, insofar as they have any,
should default to the least-intrusive capabilities.

QLocationPermission implements it that way, but these two typed
permissions defaulted to read-write access instead of read-only. This
was fixed in an earlier commit. However, default values of properties
are most natural when they're equal to the default-constructed value
of the property's type, and this was no longer the case for
isReadOnly.

By renaming the property to isReadWrite, defaulting to false, this
relationship is restored, and code using the classes looks more
natural:

  - p.setReadOnly(false);
  + p.setReadWrite(true);

Found in API review.

Change-Id: I4efa4c0326b5a54181c96f477709b0686c963e90
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
(cherry picked from commit 1b6883146d4a3b022434fac1a4bda579a6767986)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2023-01-11 17:33:26 +01:00 committed by Qt Cherry-pick Bot
parent 9e4a8fa163
commit 5e42f44691
3 changed files with 28 additions and 24 deletions

View File

@ -434,7 +434,7 @@ QLocationPermission::Availability QLocationPermission::availability() const
\brief Access the user's contacts.
By default the request is for read-only access.
Use setReadOnly(false) to override the default.
Use setReadWrite() to override the default.
\section1 Requirements
@ -447,7 +447,7 @@ QLocationPermission::Availability QLocationPermission::availability() const
\li Android
\li \l{android-uses-permission}{\c{uses-permission}}
\li \c android.permission.READ_CONTACTS. \c android.permission.WRITE_CONTACTS if
QContactsPermission::isReadOnly() is set to \c false.
QContactsPermission::isReadWrite() is set to \c true.
\include permissions.qdocinc end-usage-declarations
\include permissions.qdocinc permission-metadata
@ -455,26 +455,28 @@ QLocationPermission::Availability QLocationPermission::availability() const
class QContactsPermissionPrivate : public QSharedData
{
public:
bool isReadOnly = true;
bool isReadWrite = false;
};
QT_DEFINE_PERMISSION_SPECIAL_FUNCTIONS(QContactsPermission)
/*!
Sets whether to \a enable read-only access to the contacts.
Sets whether the request is for read-write (\a enable == \c true) or
read-only (\a enable == \c false) access to the contacts.
*/
void QContactsPermission::setReadOnly(bool enable)
void QContactsPermission::setReadWrite(bool enable)
{
d.detach();
d->isReadOnly = enable;
d->isReadWrite = enable;
}
/*!
Returns whether the request is for read-only access to the contacts.
Returns \c true when the request is for read-write and \c false when it is
for read-only access to the contacts.
*/
bool QContactsPermission::isReadOnly() const
bool QContactsPermission::isReadWrite() const
{
return d->isReadOnly;
return d->isReadWrite;
}
/*!
@ -482,7 +484,7 @@ bool QContactsPermission::isReadOnly() const
\brief Access the user's calendar.
By default the request is for read-only access.
Use setReadOnly(false) to override the default.
Use setReadWrite() to override the default.
\section1 Requirements
@ -495,7 +497,7 @@ bool QContactsPermission::isReadOnly() const
\li Android
\li \l{android-uses-permission}{\c{uses-permission}}
\li \c android.permission.READ_CALENDAR. \c android.permission.WRITE_CALENDAR if
QContactsPermission::isReadOnly() is set to \c false.
QContactsPermission::isReadWrite() is set to \c true.
\include permissions.qdocinc end-usage-declarations
\include permissions.qdocinc permission-metadata
@ -503,26 +505,28 @@ bool QContactsPermission::isReadOnly() const
class QCalendarPermissionPrivate : public QSharedData
{
public:
bool isReadOnly = true;
bool isReadWrite = false;
};
QT_DEFINE_PERMISSION_SPECIAL_FUNCTIONS(QCalendarPermission)
/*!
Sets whether to \a enable read-only access to the calendar.
Sets whether the request is for read-write (\a enable == \c true) or
read-only (\a enable == \c false) access to the calendar.
*/
void QCalendarPermission::setReadOnly(bool enable)
void QCalendarPermission::setReadWrite(bool enable)
{
d.detach();
d->isReadOnly = enable;
d->isReadWrite = enable;
}
/*!
Returns whether the request is for read-only access to the calendar.
Returns \c true when the request is for read-write and \c false when it is
for read-only access to the calendar.
*/
bool QCalendarPermission::isReadOnly() const
bool QCalendarPermission::isReadWrite() const
{
return d->isReadOnly;
return d->isReadWrite;
}
/*!

View File

@ -121,8 +121,8 @@ class QCalendarPermission
{
QT_PERMISSION(QCalendarPermission)
public:
Q_CORE_EXPORT void setReadOnly(bool enable);
Q_CORE_EXPORT bool isReadOnly() const;
Q_CORE_EXPORT void setReadWrite(bool enable);
Q_CORE_EXPORT bool isReadWrite() const;
};
Q_DECLARE_SHARED(QCalendarPermission)
@ -131,8 +131,8 @@ class QContactsPermission
{
QT_PERMISSION(QContactsPermission)
public:
Q_CORE_EXPORT void setReadOnly(bool enable);
Q_CORE_EXPORT bool isReadOnly() const;
Q_CORE_EXPORT void setReadWrite(bool enable);
Q_CORE_EXPORT bool isReadWrite() const;
};
Q_DECLARE_SHARED(QContactsPermission)

View File

@ -63,12 +63,12 @@ static QStringList nativeStringsFromPermission(const QPermission &permission)
return { u"android.permission.BLUETOOTH"_s };
} else if (id == qMetaTypeId<QContactsPermission>()) {
const auto readContactsString = u"android.permission.READ_CONTACTS"_s;
if (permission.data<QContactsPermission>().isReadOnly())
if (!permission.data<QContactsPermission>().isReadWrite())
return { readContactsString };
return { readContactsString, u"android.permission.WRITE_CONTACTS"_s };
} else if (id == qMetaTypeId<QCalendarPermission>()) {
const auto readContactsString = u"android.permission.READ_CALENDAR"_s;
if (permission.data<QCalendarPermission>().isReadOnly())
if (!permission.data<QCalendarPermission>().isReadWrite())
return { readContactsString };
return { readContactsString, u"android.permission.WRITE_CALENDAR"_s };
}