From 19dd35eb491e529847ccca5bc16d877ab3044fe6 Mon Sep 17 00:00:00 2001 From: caitao123456789 Date: Fri, 30 Aug 2024 10:56:24 +0800 Subject: [PATCH] =?UTF-8?q?fix(ukui-bluetooth):=2027534=20=E3=80=90?= =?UTF-8?q?=E5=A5=BD=E7=94=A8=E5=B7=A5=E7=A8=8B=E3=80=91=E3=80=90=E6=94=BB?= =?UTF-8?q?=E5=85=B3=E3=80=91=E5=B0=86=E8=93=9D=E7=89=99=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=8E=A5=E5=8F=97=E4=BD=8D=E7=BD=AE=EF=BC=8C=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=AD=98=E6=94=BE=E8=87=B3=E4=B8=8B=E8=BD=BD=E4=B8=AD=E8=BF=9B?= =?UTF-8?q?=E8=A1=8C=E7=BB=9F=E4=B8=80=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Description: none Log: none --- data/com.ukui.bluetooth.conf | 1 + debian/control | 8 +- service/app.cpp | 13 +++ service/app.h | 2 + service/device.cpp | 31 ++++-- service/device.h | 6 +- service/filesess.cpp | 57 +++++++---- service/filesess.h | 2 +- service/service.pro | 4 +- ukcc-bluetooth/bluetoothbottomwindow.cpp | 7 +- ukcc-bluetooth/bluetoothdbusservice.cpp | 28 +++--- ukcc-bluetooth/bluetoothdevicefunc.cpp | 1 + ukcc-bluetooth/bluetoothmiddlewindow.cpp | 14 ++- ukcc-bluetooth/bluetoothmiddlewindow.h | 4 +- ukcc-bluetooth/bluetoothtopwindow.cpp | 123 ++++++++++++++++++++++- ukcc-bluetooth/bluetoothtopwindow.h | 8 ++ ukcc-bluetooth/common.cpp | 110 ++++++++++++++++++++ ukcc-bluetooth/common.h | 22 ++++ ukcc-bluetooth/devicebase.cpp | 8 ++ ukcc-bluetooth/devicebase.h | 4 + ukcc-bluetooth/translate_generation.sh | 15 +++ ukcc-bluetooth/ukcc-bluetooth.pro | 17 +++- ukcc-bluetooth/ukccbluetoothconfig.h | 1 + ukui-bluetooth/dbus/sysdbusinterface.cpp | 42 ++++++++ ukui-bluetooth/dbus/sysdbusinterface.h | 24 +++++ ukui-bluetooth/main/main.cpp | 4 + ukui-bluetooth/translate_generation.sh | 15 +++ ukui-bluetooth/ukui-bluetooth.pro | 11 ++ 28 files changed, 520 insertions(+), 62 deletions(-) create mode 100644 ukcc-bluetooth/common.cpp create mode 100644 ukcc-bluetooth/common.h create mode 100755 ukcc-bluetooth/translate_generation.sh create mode 100644 ukui-bluetooth/dbus/sysdbusinterface.cpp create mode 100644 ukui-bluetooth/dbus/sysdbusinterface.h create mode 100755 ukui-bluetooth/translate_generation.sh diff --git a/data/com.ukui.bluetooth.conf b/data/com.ukui.bluetooth.conf index 6451364..325108a 100644 --- a/data/com.ukui.bluetooth.conf +++ b/data/com.ukui.bluetooth.conf @@ -6,6 +6,7 @@ + diff --git a/debian/control b/debian/control index 0f573c6..71ed979 100644 --- a/debian/control +++ b/debian/control @@ -19,8 +19,12 @@ Build-Depends: debhelper (>= 9), libxrandr-dev, libpeony-dev, libkysdk-sysinfo-dev, -# libkysec-dev -# libkysdk-diagnostics-dev + qt5-qmake, + qtbase5-dev, + qtbase5-dev-tools, + qtchooser, + qtscript5-dev, + qttools5-dev-tools, Standards-Version: 4.4.1 Homepage: https://github.com/supreme886/ukui-bluetooth diff --git a/service/app.cpp b/service/app.cpp index 11ce989..b5d30da 100644 --- a/service/app.cpp +++ b/service/app.cpp @@ -118,6 +118,19 @@ QStringList ApplicationMng::getRegisterClient() return apps; } +QString ApplicationMng::getUserDbusid(QString user, int type) +{ + for(auto item : m_apps.toStdMap()) + { + //控制面板 + if(item.second->type() == type && item.second->username() == user) + { + return item.second->dbusid(); + } + } + return ""; +} + void ApplicationMng::update() { KylinAdapterPtr ptr = ADAPTERMNG::getInstance()->getDefaultAdapter(); diff --git a/service/app.h b/service/app.h index ebc93d6..066d0c6 100644 --- a/service/app.h +++ b/service/app.h @@ -63,6 +63,8 @@ public: QStringList getRegisterClient(void); //int unknownDbusid(QString, ); + + QString getUserDbusid(QString, int); private: void update(void); diff --git a/service/device.cpp b/service/device.cpp index 5d4da44..1a072bc 100644 --- a/service/device.cpp +++ b/service/device.cpp @@ -279,13 +279,22 @@ int KylinDevice::reset() return 0; } -void KylinDevice::setSendfileStatus() +void KylinDevice::setSendfileStatus(bool status /*= true*/) { - if(!m_connect) - { - m_connect = true; - m_attr_send[DeviceAttr(enum_device_attr_Connected)] = m_connect; - this->__send_attr(); + KyInfo() << "connect: " << m_connect << " devconnect: " << m_device->isConnected() << " stasus: " << status; + if (status) { + if (!m_connect) { + m_connect = true; + m_attr_send[DeviceAttr(enum_device_attr_Connected)] = m_connect; + this->__send_attr(); + } + } + else { + if (m_connect != m_device->isConnected()) { + m_connect = m_device->isConnected(); + m_attr_send[DeviceAttr(enum_device_attr_Connected)] = m_connect; + this->__send_attr(); + } } } @@ -395,10 +404,20 @@ void KylinDevice::batteryChanged(BluezQt::BatteryPtr battery) m_need_clean = 0; if(battery) { + connect(battery.data(), &BluezQt::Battery::percentageChanged, + this, &KylinDevice::percentageChanged, Qt::UniqueConnection); m_attr_send[DeviceAttr(enum_device_attr_Battery)] = battery->percentage(); this->__send_attr(); } } + +void KylinDevice::percentageChanged(int percentage) +{ + m_need_clean = 0; + m_attr_send[DeviceAttr(enum_device_attr_Battery)] = percentage; + this->__send_attr(); +} + #endif void KylinDevice::typeChanged(BluezQt::Device::Type Type) { diff --git a/service/device.h b/service/device.h index 17c6064..3cd3444 100644 --- a/service/device.h +++ b/service/device.h @@ -67,7 +67,7 @@ public: bool ispaired(void) { return m_paired; } - void setSendfileStatus(void); + void setSendfileStatus(bool status = true); protected slots: void nameChanged(const QString &name); void pairedChanged(bool paired); @@ -77,11 +77,11 @@ protected slots: void connectedChanged(bool connected); #ifdef BATTERY void batteryChanged(BluezQt::BatteryPtr battery); + void percentageChanged(int percentage); #endif void typeChanged(BluezQt::Device::Type type); void uuidsChanged(const QStringList &uuids); - void mediaTransportChanged(BluezQt::MediaTransportPtr mediaTransport); - + void mediaTransportChanged(BluezQt::MediaTransportPtr mediaTransport); ////////////////////////////////////////////// void pairfinished(BluezQt::PendingCall *call); void connectfinished(BluezQt::PendingCall *call); diff --git a/service/filesess.cpp b/service/filesess.cpp index 9a11a3d..3db0e45 100644 --- a/service/filesess.cpp +++ b/service/filesess.cpp @@ -28,6 +28,7 @@ #include "sessiondbusregister.h" #include "device.h" #include "config.h" +#include "app.h" #include @@ -87,6 +88,9 @@ KylinFileSess::~KylinFileSess() m_attr[FileStatusAttr(enum_filestatus_status)] = 0xff; m_attr[FileStatusAttr(enum_filestatus_transportType)] = m_type; this->__send_statuschanged(); + + //设置文件传输状态 + this->setSendfileStatus(false); } void KylinFileSess::receiveUpdate(BluezQt::ObexTransferPtr transfer, BluezQt::ObexSessionPtr session, const BluezQt::Request &request) @@ -161,7 +165,6 @@ void KylinFileSess::CreateSessStart(BluezQt::PendingCall *call) m_attr[FileStatusAttr(enum_filestatus_dev)] = m_dest; m_attr[FileStatusAttr(enum_filestatus_fileFailedDisc)] = call->errorText(); - this->__send_statuschanged(); FILESESSMNG::getInstance()->removeSession(m_object_path); return; @@ -174,6 +177,7 @@ void KylinFileSess::CreateSessStart(BluezQt::PendingCall *call) return; } + this->__send_statuschanged(); m_opp = new BluezQt::ObexObjectPush(m_object_path); this->sendfile(); } @@ -317,24 +321,41 @@ int KylinFileSess::sendfile() QString KylinFileSess::getProperFilePath(QString dir, QString filename) { QString dest; - if(dest.isEmpty()) + QString dbusid = APPMNG::getInstance()->getUserDbusid(m_user, enum_app_type_bluetooth_tray); + if(!dbusid.isEmpty()) { - dest = m_savePathdir + filename; - } - else - { - dest = dir + filename; + QDBusInterface iface(dbusid, "/", "com.ukui.bluetooth", QDBusConnection::systemBus()); + QDBusPendingCall pcall = iface.asyncCall("getProperFilePath", m_user, filename); + pcall.waitForFinished(); + QDBusMessage res = pcall.reply(); + if(res.type() == QDBusMessage::ReplyMessage) + { + KyInfo() << res; + if(res.arguments().size() > 0) + { + dest = res.arguments().takeFirst().toString(); + } + } + else + { + KyWarning()<< res.errorName() << ": "<< res.errorMessage(); + } } - KyDebug() << dest; - while (QFile::exists(dest)) + if(dest.isEmpty()) { - QStringList newUrl = dest.split("/"); - newUrl.pop_back(); - newUrl.append(Peony::FileUtils::handleDuplicateName(Peony::FileUtils::urlDecode(dest))); - dest = newUrl.join("/"); - KyDebug() << dest << newUrl; + dest = "/home/" + m_user + "/" + filename; + KyDebug() << dest; + while (QFile::exists(dest)) + { + QStringList newUrl = dest.split("/"); + newUrl.pop_back(); + newUrl.append(Peony::FileUtils::handleDuplicateName(Peony::FileUtils::urlDecode(dest))); + dest = newUrl.join("/"); + KyDebug() << dest << newUrl; + } } + return dest; } @@ -351,10 +372,10 @@ int KylinFileSess::movefile(QString filename, QString & dest) if(flag) { QString cmd; - cmd = "chgrp " + m_user + " \"" + dest + "\""; + cmd = "chgrp " + m_user + " \'" + dest + "\'"; KyInfo() << cmd; system(cmd.toStdString().c_str()); - cmd = "chown " + m_user + " \"" + dest + "\"";; + cmd = "chown " + m_user + " \'" + dest + "\'";; KyInfo() << cmd; system(cmd.toStdString().c_str()); } @@ -378,7 +399,7 @@ void KylinFileSess::timerEvent(QTimerEvent *event) } } -void KylinFileSess::setSendfileStatus() +void KylinFileSess::setSendfileStatus(bool status /*= true*/) { KylinAdapterPtr ptr = ADAPTERMNG::getInstance()->getDefaultAdapter(); KylinDevicePtr d = nullptr; @@ -389,7 +410,7 @@ void KylinFileSess::setSendfileStatus() if(d) { - d->setSendfileStatus(); + d->setSendfileStatus(status); } } diff --git a/service/filesess.h b/service/filesess.h index aa47132..3ba9802 100644 --- a/service/filesess.h +++ b/service/filesess.h @@ -88,7 +88,7 @@ protected: virtual void timerEvent( QTimerEvent *event); - void setSendfileStatus(void); + void setSendfileStatus(bool status = true); private: int send_statuschanged(void); diff --git a/service/service.pro b/service/service.pro index 5d08d83..82e63a1 100644 --- a/service/service.pro +++ b/service/service.pro @@ -11,7 +11,7 @@ include(../environment.pri) QT += core gui dbus -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +#greaterThan(QT_MAJOR_VERSION, 4): QT += widgets CONFIG += c++11 \ link_pkgconfig @@ -89,4 +89,4 @@ TRANSLATIONS += ../translations/ukui-bluetooth_zh_CN.ts OBJECTS_DIR = ./obj/ MOC_DIR = ./moc/ -CONFIG+=force_debug_info +#CONFIG+=force_debug_info diff --git a/ukcc-bluetooth/bluetoothbottomwindow.cpp b/ukcc-bluetooth/bluetoothbottomwindow.cpp index 0b4f34a..d9efc4b 100644 --- a/ukcc-bluetooth/bluetoothbottomwindow.cpp +++ b/ukcc-bluetooth/bluetoothbottomwindow.cpp @@ -31,7 +31,9 @@ BluetoothBottomWindow::BluetoothBottomWindow(BlueToothDBusService * btServer,QWi InitNormalWidgetBottom(); InitConnectionData(); - AddBluetoothDevices(); + + if (btServer->m_default_bluetooth_adapter) + AddBluetoothDevices(); } BluetoothBottomWindow::~BluetoothBottomWindow() @@ -103,6 +105,9 @@ void BluetoothBottomWindow::InitConnectionData() void BluetoothBottomWindow::AddBluetoothDevices() { + if (!BlueToothDBusService::m_default_bluetooth_adapter) + return; + QList devKeyList = BlueToothDBusService::m_default_bluetooth_adapter->m_bt_dev_list.keys(); // 存放的就是QMap的key值 KyDebug() << devKeyList; for(QString dev_addr:devKeyList) diff --git a/ukcc-bluetooth/bluetoothdbusservice.cpp b/ukcc-bluetooth/bluetoothdbusservice.cpp index 9a3c86c..566b947 100644 --- a/ukcc-bluetooth/bluetoothdbusservice.cpp +++ b/ukcc-bluetooth/bluetoothdbusservice.cpp @@ -251,30 +251,30 @@ void BlueToothDBusService::getDefaultAdapterDevices() dev_add_count++; KyInfo() << "add an device (mac):" << dev_addr << "is count device: " << dev_add_count ; - if (dev_add_count > 100) - {//首次启动时,设备数量超过100个的情况下,多余的设备以定时加入的方式 - m_remainder_loaded_bluetooth_device_address_list.append(dev_addr); - } - else - { +// if (dev_add_count > 100) +// {//首次启动时,设备数量超过100个的情况下,多余的设备以定时加入的方式 +// m_remainder_loaded_bluetooth_device_address_list.append(dev_addr); +// } +// else +// { bluetoothdevice * dev = createOneBleutoothDeviceForAddress(dev_addr); if (dev != nullptr && !dev->isPaired()) { m_default_bluetooth_adapter->m_bt_dev_list.insert(dev->getDevAddress(),dev); } - } +// } } KyInfo() << "####" << m_remainder_loaded_bluetooth_device_address_list; - if (m_remainder_loaded_bluetooth_device_address_list.size() > 0) - { - if (m_loading_dev_timer->isActive()) - m_loading_dev_timer->stop(); +// if (m_remainder_loaded_bluetooth_device_address_list.size() > 0) +// { +// if (m_loading_dev_timer->isActive()) +// m_loading_dev_timer->stop(); - m_loading_dev_timer->start(); - KyInfo() << "start m_loading_dev_timer!" << m_remainder_loaded_bluetooth_device_address_list; - } +// m_loading_dev_timer->start(); +// KyInfo() << "start m_loading_dev_timer!" << m_remainder_loaded_bluetooth_device_address_list; +// } KyDebug() << "end"; } diff --git a/ukcc-bluetooth/bluetoothdevicefunc.cpp b/ukcc-bluetooth/bluetoothdevicefunc.cpp index e0a1259..aa2e50b 100644 --- a/ukcc-bluetooth/bluetoothdevicefunc.cpp +++ b/ukcc-bluetooth/bluetoothdevicefunc.cpp @@ -134,6 +134,7 @@ void bluetoothdevicefunc::showDeviceRemoveWidget(DevRemoveDialog::REMOVE_INTERFA connect(mesgBox,&DevRemoveDialog::accepted,this,[=]{ KyDebug() << "To :" << _MDev_addr << "Remove" ; + BlueToothDBusService::m_default_bluetooth_adapter->m_bt_dev_list[_MDev_addr]->setRemoving(true); BlueToothDBusService::devRemove(_MDev_addr); Q_EMIT devFuncOpertionRemoveSignal(_MDev_addr); }); diff --git a/ukcc-bluetooth/bluetoothmiddlewindow.cpp b/ukcc-bluetooth/bluetoothmiddlewindow.cpp index c3dfcf3..5043ca4 100644 --- a/ukcc-bluetooth/bluetoothmiddlewindow.cpp +++ b/ukcc-bluetooth/bluetoothmiddlewindow.cpp @@ -26,7 +26,9 @@ BluetoothMiddleWindow::BluetoothMiddleWindow(BlueToothDBusService * btServer,QWi InitNormalWidgetMiddle(); InitConnectionData(); - AddMyBluetoothDevices(); + + if (btServer->m_default_bluetooth_adapter) + AddMyBluetoothDevices(); } BluetoothMiddleWindow::~BluetoothMiddleWindow() @@ -58,15 +60,15 @@ void BluetoothMiddleWindow::InitNormalWidgetMiddle() _NormalWidgetPairedDevLayout->setContentsMargins(0,0,0,0); _MNormalFrameMiddle->setLayout(_NormalWidgetPairedDevLayout); - _MConnectedNormalFrameMiddle = new QFrame(_MNormalFrameMiddle); + _MConnectedNormalFrameMiddle = new QWidget(_MNormalFrameMiddle); _MConnectedNormalFrameMiddle->setMinimumWidth(582); - _MConnectedNormalFrameMiddle->setFrameShape(QFrame::Shape::Box); +// _MConnectedNormalFrameMiddle->setFrameShape(QFrame::Shape::Box); _MConnectedNormalFrameMiddle->setContentsMargins(0,0,0,0); _NormalWidgetPairedDevLayout->addWidget(_MConnectedNormalFrameMiddle); - _MNotConnectedNormalFrameMiddle = new QFrame(_MNormalFrameMiddle); + _MNotConnectedNormalFrameMiddle = new QWidget(_MNormalFrameMiddle); _MNotConnectedNormalFrameMiddle->setMinimumWidth(582); - _MNotConnectedNormalFrameMiddle->setFrameShape(QFrame::Shape::Box); +// _MNotConnectedNormalFrameMiddle->setFrameShape(QFrame::Shape::Box); _MNotConnectedNormalFrameMiddle->setContentsMargins(0,0,0,0); _NormalWidgetPairedDevLayout->addWidget(_MNotConnectedNormalFrameMiddle); @@ -99,6 +101,8 @@ void BluetoothMiddleWindow::InitConnectionData() void BluetoothMiddleWindow::AddMyBluetoothDevices() { + if (!BlueToothDBusService::m_default_bluetooth_adapter) + return; QList pairedDevKeyList = BlueToothDBusService::m_default_bluetooth_adapter->m_bt_dev_list.keys(); // 存放的就是QMap的key值 KyDebug() << pairedDevKeyList; for (QString dev_addr:pairedDevKeyList) diff --git a/ukcc-bluetooth/bluetoothmiddlewindow.h b/ukcc-bluetooth/bluetoothmiddlewindow.h index 22405da..c402fb4 100644 --- a/ukcc-bluetooth/bluetoothmiddlewindow.h +++ b/ukcc-bluetooth/bluetoothmiddlewindow.h @@ -52,9 +52,9 @@ private: QFrame *_MNormalFrameMiddle = nullptr; QVBoxLayout *_NormalWidgetPairedDevLayout = nullptr; - QFrame *_MNotConnectedNormalFrameMiddle = nullptr; + QWidget *_MNotConnectedNormalFrameMiddle = nullptr; QVBoxLayout *_NormalWidgetNotConnecededDevLayout = nullptr; - QFrame *_MConnectedNormalFrameMiddle = nullptr; + QWidget *_MConnectedNormalFrameMiddle = nullptr; QVBoxLayout *_NormalWidgetConnecededDevLayout = nullptr; //bool ; diff --git a/ukcc-bluetooth/bluetoothtopwindow.cpp b/ukcc-bluetooth/bluetoothtopwindow.cpp index a664948..37c9eff 100644 --- a/ukcc-bluetooth/bluetoothtopwindow.cpp +++ b/ukcc-bluetooth/bluetoothtopwindow.cpp @@ -18,16 +18,23 @@ #include "bluetoothtopwindow.h" +#include "common.h" + bool BluetoothTopWindow::m_defaultAdapterPowerStatus = false; BluetoothTopWindow::BluetoothTopWindow(BlueToothDBusService * btServer,QWidget * parent) : m_btServer(btServer), QWidget(parent) { - this->setFocusPolicy(Qt::NoFocus); +// this->setFocusPolicy(Qt::NoFocus); + this->setFocus(Qt::NoFocusReason); + InitNormalWidgetTop(); - InitDisplayState(); + + if (btServer->m_default_bluetooth_adapter) + InitDisplayState(); + InitConnectionData(); } @@ -78,9 +85,11 @@ void BluetoothTopWindow::InitNormalWidgetTop() _BtNameLabel = new BluetoothNameLabel(BtSwitchFrame,300,38); BtSwitchFrameLayout->addWidget(_BtNameLabel,1,Qt::AlignLeft); + BtSwitchFrameLayout->addStretch(25); + + _BtSwitchBtn = new KSwitchButton(BtSwitchFrame); // _BtSwitchBtn->setChecked(true); - BtSwitchFrameLayout->addStretch(25); BtSwitchFrameLayout->addWidget(_BtSwitchBtn); //添加分割线 @@ -204,6 +213,9 @@ void BluetoothTopWindow::InitNormalWidgetTop() void BluetoothTopWindow::InitDisplayState() { + if (!BlueToothDBusService::m_default_bluetooth_adapter) + return; + //bluetooth _BtNameLabel->set_dev_name(BlueToothDBusService::m_default_bluetooth_adapter->getDevName()); KyWarning()<< "power status:" << BlueToothDBusService::m_default_bluetooth_adapter->getAdapterPower(); @@ -263,6 +275,9 @@ void BluetoothTopWindow::InitConnectionData() //btn connect(_BtSwitchBtn,SIGNAL(stateChanged(bool)),this,SLOT(_BtSwitchBtnSlot(bool))); + connect(_BtSwitchBtn, &KSwitchButton::pressed, this, &BluetoothTopWindow::_BtSwitchBtnPressedSlot); + connect(_BtSwitchBtn, &KSwitchButton::released, this, &BluetoothTopWindow::_BtSwitchBtnReleasedSlot); + connect(_BtTrayIconShow,SIGNAL(stateChanged(bool)),this,SLOT(_BtTrayIconShowSlot(bool))); connect(_BtDiscoverable,SIGNAL(stateChanged(bool)),this,SLOT(_BtDiscoverableSlot(bool))); connect(_BtAutoAudioConnBtn,SIGNAL(stateChanged(bool)),this,SLOT(_BtAutoAudioConnBtnSlot(bool))); @@ -396,7 +411,31 @@ void BluetoothTopWindow::sendBtPowerChangedSignal(bool status) void BluetoothTopWindow::_BtSwitchBtnSlot(bool status) { - KyDebug(); + KyDebug() << "status" << status << "_BtSwitchBtn status: "<< _BtSwitchBtn->isChecked(); + + if (!_BTServiceReportPowerSwitchFlag && !status && whetherNeedInfoUser()) + { + KyInfo() << "Close bluetooth risk info!" ; + + QMessageBox box; + box.setIcon(QMessageBox::Warning); + box.setText(tr("Using Bluetooth mouse or keyboard, Do you want to turn off bluetooth?")); + QPushButton * cancelBtn= new QPushButton(tr("Cancel")); + QPushButton * closeBluetoothBtn= new QPushButton(tr("Close bluetooth")); + + box.addButton(cancelBtn,QMessageBox::RejectRole); + box.addButton(closeBluetoothBtn,QMessageBox::AcceptRole); + int res = box.exec(); + if (!res) + { + _BtSwitchBtn->disconnect(_BtSwitchBtn,NULL,this,NULL); + _BtSwitchBtn->setChecked(true); + connect(_BtSwitchBtn,SIGNAL(stateChanged(bool)),this,SLOT(_BtSwitchBtnSlot(bool))); + connect(_BtSwitchBtn, &KSwitchButton::pressed, this, &BluetoothTopWindow::_BtSwitchBtnPressedSlot); + connect(_BtSwitchBtn, &KSwitchButton::released, this, &BluetoothTopWindow::_BtSwitchBtnReleasedSlot); + return; + } + } BtSwitchLineFrame->setVisible(status); if (BlueToothDBusService::m_bluetooth_adapter_name_list.size() > 1) @@ -419,6 +458,7 @@ void BluetoothTopWindow::_BtSwitchBtnSlot(bool status) KyInfo() << "_BTServiceReportPowerSwitchFlag:" << _BTServiceReportPowerSwitchFlag ; if(!_BTServiceReportPowerSwitchFlag)//服务上报的状态不再次下发 { + m_SwitchBtnPressed = false; ukccbluetoothconfig::ukccBtBuriedSettings(QString("Bluetooth"),QString("BtSwitchBtn"),QString("clicked"),status?QString("true"):QString("false")); BlueToothDBusService::setDefaultAdapterSwitchStatus(status); } @@ -427,6 +467,26 @@ void BluetoothTopWindow::_BtSwitchBtnSlot(bool status) } +void BluetoothTopWindow::_BtSwitchBtnPressedSlot() +{ + m_SwitchBtnPressed = true; +} + +void BluetoothTopWindow::_BtSwitchBtnReleasedSlot() +{ + if (m_SwitchBtnPressed) { + KyWarning() << "active click"; + _BtSwitchBtn->disconnect(_BtSwitchBtn,NULL,this,NULL); + connect(_BtSwitchBtn,SIGNAL(stateChanged(bool)),this,SLOT(_BtSwitchBtnSlot(bool))); + + _BtSwitchBtn->click(); + connect(_BtSwitchBtn, &KSwitchButton::pressed, this, &BluetoothTopWindow::_BtSwitchBtnPressedSlot); + connect(_BtSwitchBtn, &KSwitchButton::released, this, &BluetoothTopWindow::_BtSwitchBtnReleasedSlot); + } + + m_SwitchBtnPressed = false; +} + void BluetoothTopWindow::_BtTrayIconShowSlot(bool status) { KyDebug(); @@ -583,3 +643,58 @@ void BluetoothTopWindow::quitWindow() { } + + +bool BluetoothTopWindow::whetherNeedInfoUser() +{ + KyDebug(); + unsigned int bluetoothMouseAmount = 0; + unsigned int bluetoothKeyBoardAmount = 0 ; + + if (BlueToothDBusService::m_default_bluetooth_adapter) + { + for (auto var : BlueToothDBusService::m_default_bluetooth_adapter->m_bt_dev_list) + { + if (!var->getRemoving() && var->isPaired() && var->isConnected()) + { + if (bluetoothdevice::DEVICE_TYPE::mouse == var->getDevType()) + { + bluetoothMouseAmount += 1; + } + else if (bluetoothdevice::DEVICE_TYPE::keyboard == var->getDevType()) + { + bluetoothKeyBoardAmount += 1; + } + else + continue; + } + } + } + KyInfo() << "Connected mouse amount:" << bluetoothMouseAmount + << "Connected KeyBoard amount:" << bluetoothKeyBoardAmount; + + if (bluetoothMouseAmount == 0 && bluetoothKeyBoardAmount == 0) + { + KyDebug() << "Not connected KeyBoard and Mouse"; + return false; + } + + unsigned int systemMouseAndTouchPadAmount = Common::getSystemCurrentMouseAndTouchPadDevCount(); + unsigned int systemKeyBoardAmount = Common::getSystemCurrentKeyBoardDevCount(); + KyInfo() << "Connected bluetooth Mouse amount:" << bluetoothMouseAmount + << "Connected bluetooth KeyBoard amount:" << bluetoothKeyBoardAmount + << "System Mouse and TouchPad amount:" << systemMouseAndTouchPadAmount + << "System KeyBoard amount:" << systemKeyBoardAmount; + + if ((bluetoothMouseAmount != 0) && (systemMouseAndTouchPadAmount == bluetoothMouseAmount)) + { + return true; + } + + if ((bluetoothKeyBoardAmount != 0) && (systemKeyBoardAmount == bluetoothKeyBoardAmount)) + { + return true; + } + + return false; +} diff --git a/ukcc-bluetooth/bluetoothtopwindow.h b/ukcc-bluetooth/bluetoothtopwindow.h index c9d7252..3ddf885 100644 --- a/ukcc-bluetooth/bluetoothtopwindow.h +++ b/ukcc-bluetooth/bluetoothtopwindow.h @@ -25,6 +25,7 @@ #include #include #include +#include #include "kswitchbutton.h" #include "bluetoothnamelabel.h" @@ -55,6 +56,9 @@ private Q_SLOTS: void setDefaultAdapterNameSlot(QString); void _BtSwitchBtnSlot(bool status); + void _BtSwitchBtnPressedSlot(); + void _BtSwitchBtnReleasedSlot(); + void _BtTrayIconShowSlot(bool status); void _BtDiscoverableSlot(bool status); void _BtAutoAudioConnBtnSlot(bool status); @@ -101,12 +105,16 @@ private: bool _BTServiceReportAutoAudioConnSwtichFlag = false; //服务上报的自动音频状态 // bool _BTServiceReportDiscoveringSwtichFlag = false; //服务上报的扫描状态 + bool m_SwitchBtnPressed = false; + private: void InitNormalWidgetTop(); void InitDisplayState(); void InitConnectionData(); void sendBtPowerChangedSignal(bool status); void adapterChangedRefreshInterface(int indx); + + bool whetherNeedInfoUser(); }; #endif // BLUETOOTHTOPWINDOW_H diff --git a/ukcc-bluetooth/common.cpp b/ukcc-bluetooth/common.cpp new file mode 100644 index 0000000..84c44aa --- /dev/null +++ b/ukcc-bluetooth/common.cpp @@ -0,0 +1,110 @@ +#include "common.h" + +#include + +extern "C"{ + #include + #include +} + + + +Common::Common(QObject *parent) : QObject(parent) +{ + +} + + + +unsigned int Common::getSystemCurrentMouseAndTouchPadDevCount() +{ + unsigned int count = 0 ; + Display *display = XOpenDisplay(NULL); + if (display == NULL) { + // 错误处理 + KyWarning() << "display error!"; + XCloseDisplay(display); + exit(1); + } + + XDeviceInfo *devices; + int num_devices; + devices = XListInputDevices(display, &num_devices); + if (devices == NULL) { + //KyWarning() << "devices error!"; + XCloseDisplay(display); + exit(1); + } + + Atom mouse_prop = XInternAtom(display,STR_MOUSE,false); + Atom touchPad_prop = XInternAtom(display,STR_TOUCHPAD,false); + + //KyDebug() << "mouse_prop:" << mouse_prop ; + //KyDebug() << "touchPad_prop:" << touchPad_prop; + + + for (int i = 0; i < num_devices; i++) { + if (devices[i].type == mouse_prop || devices[i].type == touchPad_prop) { + QString dev_name = QString(devices[i].name); + KyDebug() << "dev_name:" < + +#define STR_MOUSE "MOUSE" +#define STR_TOUCHPAD "TOUCHPAD" +#define STR_KEYBOARD "KEYBOARD" +#define STR_TRACKPOINT "TRACKPOINT" + +class Common : public QObject +{ + Q_OBJECT +public: + explicit Common(QObject *parent = nullptr); + static unsigned int getSystemCurrentMouseAndTouchPadDevCount(); + static unsigned int getSystemCurrentKeyBoardDevCount(); +signals: + +}; + +#endif // COMMON_H diff --git a/ukcc-bluetooth/devicebase.cpp b/ukcc-bluetooth/devicebase.cpp index 12c5d81..3ec6bce 100644 --- a/ukcc-bluetooth/devicebase.cpp +++ b/ukcc-bluetooth/devicebase.cpp @@ -585,6 +585,14 @@ int bluetoothdevice::getErrorId() return this->m_dev_connectFailedId; } +void bluetoothdevice::setRemoving(bool state) +{ + this->m_dev_removing = state; +} +bool bluetoothdevice::getRemoving() +{ + return this->m_dev_removing; +} //bluetoothdevice end diff --git a/ukcc-bluetooth/devicebase.h b/ukcc-bluetooth/devicebase.h index a3421f7..3041b8f 100644 --- a/ukcc-bluetooth/devicebase.h +++ b/ukcc-bluetooth/devicebase.h @@ -309,6 +309,9 @@ public: int getErrorId(); + void setRemoving(bool); + bool getRemoving(); + signals: void nameChanged(QString); @@ -341,6 +344,7 @@ private: qint16 m_dev_rssi ; bool m_dev_sendFileMark ; QString m_adapter_address ;//暂时不使用 + bool m_dev_removing = false ;//正在移除该设备 void bluetoothDeviceDataAnalysis(QMap value); diff --git a/ukcc-bluetooth/translate_generation.sh b/ukcc-bluetooth/translate_generation.sh new file mode 100755 index 0000000..72f748b --- /dev/null +++ b/ukcc-bluetooth/translate_generation.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +ts_list=(`ls translations/*.ts`) +source /etc/os-release +version=(`echo $ID`) + +for ts in "${ts_list[@]}" +do + printf "\nprocess ${ts}\n" + if [ "$version" == "fedora" ] || [ "$version" == "opensuse-leap" ] || [ "$version" == "opensuse-tumbleweed" ];then + lrelease-qt5 "${ts}" + else + lrelease "${ts}" + fi +done diff --git a/ukcc-bluetooth/ukcc-bluetooth.pro b/ukcc-bluetooth/ukcc-bluetooth.pro index e4c4481..45a43af 100644 --- a/ukcc-bluetooth/ukcc-bluetooth.pro +++ b/ukcc-bluetooth/ukcc-bluetooth.pro @@ -1,4 +1,4 @@ -QT += gui dbus +QT += gui dbus x11extras include(../environment.pri) @@ -6,16 +6,23 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets dbus KWindowSystem TEMPLATE = lib CONFIG += plugin \ - += c++11 \ + c++11 \ + x11extras \ link_pkgconfig -PKGCONFIG += gsettings-qt \ +PKGCONFIG += gsettings-qt \ kysdk-qtwidgets \ kysdk-waylandhelper \ - kysdk-sysinfo + kysdk-sysinfo \ + x11 \ + xi LIBS += -lukcc +CONFIG(release, debug|release) { + !system($$PWD/translate_generation.sh): error("Failed to generate translation") +} + # The following define makes your compiler emit warnings if you use # any Qt feature that has been marked deprecated (the exact warnings # depend on your compiler). Please consult the documentation of the @@ -48,6 +55,7 @@ SOURCES += \ bluetoothmiddlewindow.cpp \ bluetoothnamelabel.cpp \ bluetoothtopwindow.cpp \ + common.cpp \ devicebase.cpp \ devremovedialog.cpp \ devrenamedialog.cpp \ @@ -68,6 +76,7 @@ HEADERS += \ bluetoothmiddlewindow.h \ bluetoothnamelabel.h \ bluetoothtopwindow.h \ + common.h \ config.h \ devicebase.h \ devremovedialog.h \ diff --git a/ukcc-bluetooth/ukccbluetoothconfig.h b/ukcc-bluetooth/ukccbluetoothconfig.h index 9963525..4d6e327 100644 --- a/ukcc-bluetooth/ukccbluetoothconfig.h +++ b/ukcc-bluetooth/ukccbluetoothconfig.h @@ -26,6 +26,7 @@ #include #include + #ifdef UKCC_BLUETOOTH_DATA_BURIAL_POINT #include #endif diff --git a/ukui-bluetooth/dbus/sysdbusinterface.cpp b/ukui-bluetooth/dbus/sysdbusinterface.cpp new file mode 100644 index 0000000..25f0652 --- /dev/null +++ b/ukui-bluetooth/dbus/sysdbusinterface.cpp @@ -0,0 +1,42 @@ +#include "sysdbusinterface.h" + +#include +#include +#include + +#include "ukui-log4qt.h" + +sysdbusinterface::sysdbusinterface() +{ + + QDBusConnection systemBus = QDBusConnection::systemBus(); + if (!systemBus.registerObject("/", this, QDBusConnection::ExportAllSlots)) + { + KyWarning() << "QDbus register object failed reason:" << systemBus.lastError(); + } +} + + +sysdbusinterface::~sysdbusinterface() +{ + +} + +QString sysdbusinterface::getProperFilePath(QString user, QString filename) +{ + KyInfo() << user << filename; + QString dest; + dest = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation) + "/" + filename; + + KyDebug() << dest; + while (QFile::exists(dest)) + { + QStringList newUrl = dest.split("/"); + newUrl.pop_back(); + newUrl.append(Peony::FileUtils::handleDuplicateName(Peony::FileUtils::urlDecode(dest))); + dest = newUrl.join("/"); + KyDebug() << dest << newUrl; + } + + return dest; +} diff --git a/ukui-bluetooth/dbus/sysdbusinterface.h b/ukui-bluetooth/dbus/sysdbusinterface.h new file mode 100644 index 0000000..f00ac48 --- /dev/null +++ b/ukui-bluetooth/dbus/sysdbusinterface.h @@ -0,0 +1,24 @@ +#ifndef SYSDBUSINTERFACE_H +#define SYSDBUSINTERFACE_H + +#include +#include +#include +#include +#include +#include + +class sysdbusinterface : public QObject, protected QDBusContext +{ + Q_CLASSINFO("D-Bus Interface", "com.ukui.bluetooth") + Q_OBJECT +public: + sysdbusinterface(); + ~sysdbusinterface(); + +public slots: + QString getProperFilePath(QString user, QString filename); + +}; + +#endif // SYSDBUSINTERFACE_H diff --git a/ukui-bluetooth/main/main.cpp b/ukui-bluetooth/main/main.cpp index 44f7bf9..a107958 100644 --- a/ukui-bluetooth/main/main.cpp +++ b/ukui-bluetooth/main/main.cpp @@ -30,6 +30,8 @@ #include #include "kysdk/kysdk-system/libkysysinfo.h" +#include "dbus/sysdbusinterface.h" + extern bool global_rightToleft; int main(int argc, char *argv[]) @@ -77,6 +79,8 @@ int main(int argc, char *argv[]) if (qt_translator->load(QLocale(), "qt", "_", qtTransPath)) app.installTranslator(qt_translator); + auto ptr = new sysdbusinterface(); + MainProgram w(envPC); if(w.exit_flag){ return 0; diff --git a/ukui-bluetooth/translate_generation.sh b/ukui-bluetooth/translate_generation.sh new file mode 100755 index 0000000..72f748b --- /dev/null +++ b/ukui-bluetooth/translate_generation.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +ts_list=(`ls translations/*.ts`) +source /etc/os-release +version=(`echo $ID`) + +for ts in "${ts_list[@]}" +do + printf "\nprocess ${ts}\n" + if [ "$version" == "fedora" ] || [ "$version" == "opensuse-leap" ] || [ "$version" == "opensuse-tumbleweed" ];then + lrelease-qt5 "${ts}" + else + lrelease "${ts}" + fi +done diff --git a/ukui-bluetooth/ukui-bluetooth.pro b/ukui-bluetooth/ukui-bluetooth.pro index 3374c53..669156e 100644 --- a/ukui-bluetooth/ukui-bluetooth.pro +++ b/ukui-bluetooth/ukui-bluetooth.pro @@ -25,6 +25,10 @@ LIBS += -L /usr/lib/x86_64-linux-gnu -l KF5BluezQt -lgio-2.0 -lglib-2.0 -lukui-l QMAKE_LFLAGS += -D_FORTIFY_SOURCE=2 -O2 +CONFIG(release, debug|release) { + !system($$PWD/translate_generation.sh): error("Failed to generate translation") +} + inst1.files += ../data/org.bluez.Agent1.conf inst1.path = $$CONF_INSTALL_DIR inst2.files += ../data/org.ukui.bluetooth.gschema.xml @@ -37,14 +41,19 @@ inst5.files += ../data/file-transfer-failed.svg inst5.path = $$SHARE_INSTALL_DIR inst6.files +=../data/connection-failed.svg inst6.path = $$SHARE_INSTALL_DIR +qm_files.files += translations/*.qm +qm_files.path += $${SHARE_TRANSLATIONS_INSTALL_DIR} target.source += $$TARGET target.path = $$BIN_INSTALL_DIR + + INSTALLS += inst1 \ inst2 \ inst3 \ inst4 \ inst5 \ inst6 \ + qm_files \ target # The following define makes your compiler emit warnings if you use @@ -72,6 +81,7 @@ unix { } SOURCES += \ + dbus/sysdbusinterface.cpp \ popwidget/activeconnectionwidget.cpp \ component/bluetoothsettinglabel.cpp \ component/kyfiledialog.cpp \ @@ -91,6 +101,7 @@ SOURCES += \ dbus/sessiondbusinterface.cpp HEADERS += \ + dbus/sysdbusinterface.h \ popwidget/activeconnectionwidget.h \ component/bluetoothsettinglabel.h \ component/kyfiledialog.h \