summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Solovev <ivan.solovev@qt.io>2023-03-31 14:59:45 +0200
committerIvan Solovev <ivan.solovev@qt.io>2023-04-05 10:01:02 +0200
commit92bea4cac7b0f8a3c93ba6b6dfb53218bcc8d4df (patch)
tree748599d9f8d9387147f7a872fc8447b497d9de93
parent7be77bb98e4e272de1fd6d6d8e70058ff52363e7 (diff)
downloadqtconnectivity-92bea4cac7b0f8a3c93ba6b6dfb53218bcc8d4df.tar.gz
BtChat: adapt to using new QBluetoothPermission
Also add missing Info.plist files Task-number: QTBUG-109964 Change-Id: Icf1fdf1353898538ce42a27cb0b0cb01c0823e26 Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
-rw-r--r--examples/bluetooth/btchat/CMakeLists.txt14
-rw-r--r--examples/bluetooth/btchat/btchat.pro3
-rw-r--r--examples/bluetooth/btchat/chat.cpp41
-rw-r--r--examples/bluetooth/btchat/chat.h2
4 files changed, 54 insertions, 6 deletions
diff --git a/examples/bluetooth/btchat/CMakeLists.txt b/examples/bluetooth/btchat/CMakeLists.txt
index ef578b88..6d2bd0b9 100644
--- a/examples/bluetooth/btchat/CMakeLists.txt
+++ b/examples/bluetooth/btchat/CMakeLists.txt
@@ -33,6 +33,20 @@ target_link_libraries(btchat PRIVATE
Qt::Widgets
)
+if (APPLE)
+ # Using absolute path for shared plist files is a Ninja bug workaround
+ get_filename_component(SHARED_PLIST_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../shared ABSOLUTE)
+ if (IOS)
+ set_target_properties(btchat PROPERTIES
+ MACOSX_BUNDLE_INFO_PLIST "${SHARED_PLIST_DIR}/Info.cmake.ios.plist"
+ )
+ else()
+ set_target_properties(btchat PROPERTIES
+ MACOSX_BUNDLE_INFO_PLIST "${SHARED_PLIST_DIR}/Info.cmake.macos.plist"
+ )
+ endif()
+endif()
+
install(TARGETS btchat
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
diff --git a/examples/bluetooth/btchat/btchat.pro b/examples/bluetooth/btchat/btchat.pro
index bbf9ed18..7e0c976f 100644
--- a/examples/bluetooth/btchat/btchat.pro
+++ b/examples/bluetooth/btchat/btchat.pro
@@ -21,5 +21,8 @@ FORMS = \
chat.ui \
remoteselector.ui
+ios: QMAKE_INFO_PLIST = ../shared/Info.qmake.ios.plist
+macos: QMAKE_INFO_PLIST = ../shared/Info.qmake.macos.plist
+
target.path = $$[QT_INSTALL_EXAMPLES]/bluetooth/btchat
INSTALLS += target
diff --git a/examples/bluetooth/btchat/chat.cpp b/examples/bluetooth/btchat/chat.cpp
index a9545cf6..288f4641 100644
--- a/examples/bluetooth/btchat/chat.cpp
+++ b/examples/bluetooth/btchat/chat.cpp
@@ -13,6 +13,12 @@
#include <QtBluetooth/qbluetoothlocaldevice.h>
#include <QtBluetooth/qbluetoothuuid.h>
+#if QT_CONFIG(permissions)
+#include <QtCore/qcoreapplication.h>
+#include <QtCore/qpermissions.h>
+#include <QtWidgets/qmessagebox.h>
+#endif
+
using namespace Qt::StringLiterals;
static constexpr auto serviceUuid = "e8e10f95-1a70-4b27-9ccf-02010264e9c8"_L1;
@@ -32,6 +38,35 @@ Chat::Chat(QWidget *parent)
//! [Construct UI]
ui->connectButton->setFocus();
+ initBluetooth();
+}
+
+Chat::~Chat()
+{
+ qDeleteAll(clients);
+ delete ui;
+}
+
+void Chat::initBluetooth()
+{
+#if QT_CONFIG(permissions)
+ QBluetoothPermission permission{};
+ switch (qApp->checkPermission(permission)) {
+ case Qt::PermissionStatus::Undetermined:
+ qApp->requestPermission(permission, this, &Chat::initBluetooth);
+ return;
+ case Qt::PermissionStatus::Denied:
+ QMessageBox::warning(this, tr("Missing permissions"),
+ tr("Permissions are needed to use Bluetooth. "
+ "Please grant the permissions to this "
+ "application in the system settings."));
+ qApp->quit();
+ return;
+ case Qt::PermissionStatus::Granted:
+ break; // proceed to initialization
+ }
+#endif // QT_CONFIG(permissions)
+
localAdapters = QBluetoothLocalDevice::allDevices();
if (localAdapters.size() < 2) {
ui->localAdapterBox->setVisible(false);
@@ -71,12 +106,6 @@ Chat::Chat(QWidget *parent)
//! [Get local device name]
}
-Chat::~Chat()
-{
- qDeleteAll(clients);
- delete ui;
-}
-
//! [clientConnected clientDisconnected]
void Chat::clientConnected(const QString &name)
{
diff --git a/examples/bluetooth/btchat/chat.h b/examples/bluetooth/btchat/chat.h
index 1c9d3211..d9a22ca7 100644
--- a/examples/bluetooth/btchat/chat.h
+++ b/examples/bluetooth/btchat/chat.h
@@ -40,6 +40,8 @@ private slots:
void newAdapterSelected();
+ void initBluetooth();
+
private:
int adapterFromUserSelection() const;
int currentAdapterIndex = 0;