File indexing completed on 2024-03-24 05:49:26
0001 // SPDX-License-Identifier: GPL-3.0-or-later 0002 /* 0003 Copyright 2017 - 2023 Martin Koller, kollix@aon.at 0004 0005 This file is part of liquidshell. 0006 0007 liquidshell is free software: you can redistribute it and/or modify 0008 it under the terms of the GNU General Public License as published by 0009 the Free Software Foundation, either version 3 of the License, or 0010 (at your option) any later version. 0011 0012 liquidshell is distributed in the hope that it will be useful, 0013 but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0015 GNU General Public License for more details. 0016 0017 You should have received a copy of the GNU General Public License 0018 along with liquidshell. If not, see <http://www.gnu.org/licenses/>. 0019 */ 0020 0021 #include <Bluetooth.hxx> 0022 0023 #include <QIcon> 0024 0025 #include <BluezQt/Adapter> 0026 #include <BluezQt/InitManagerJob> 0027 0028 #include <KLocalizedString> 0029 #include <KIconLoader> 0030 #include <KPluginMetaData> 0031 #include <kcmutils_version.h> 0032 0033 //-------------------------------------------------------------------------------- 0034 0035 Bluetooth::Bluetooth(QWidget *parent) 0036 : SysTrayItem(parent) 0037 { 0038 manager = new BluezQt::Manager(this); 0039 job = manager->init(); 0040 job->start(); 0041 connect(job, &BluezQt::InitManagerJob::result, this, &Bluetooth::changed); 0042 0043 connect(manager, &BluezQt::Manager::adapterAdded, this, &Bluetooth::changed); 0044 connect(manager, &BluezQt::Manager::adapterRemoved, this, &Bluetooth::changed); 0045 connect(manager, &BluezQt::Manager::allAdaptersRemoved, this, &Bluetooth::changed); 0046 connect(manager, &BluezQt::Manager::bluetoothOperationalChanged, this, &Bluetooth::changed); 0047 connect(manager, &BluezQt::Manager::operationalChanged, this, &Bluetooth::changed); 0048 0049 connect(KIconLoader::global(), &KIconLoader::iconLoaderSettingsChanged, this, &Bluetooth::changed); 0050 } 0051 0052 //-------------------------------------------------------------------------------- 0053 0054 Bluetooth::~Bluetooth() 0055 { 0056 if ( job ) 0057 job->kill(); 0058 } 0059 0060 //-------------------------------------------------------------------------------- 0061 0062 void Bluetooth::changed() 0063 { 0064 job = nullptr; 0065 0066 if ( manager->adapters().isEmpty() || !manager->isOperational() ) 0067 { 0068 hide(); // no BT 0069 return; 0070 } 0071 0072 show(); 0073 0074 if ( manager->isBluetoothOperational() ) 0075 { 0076 setPixmap(QIcon::fromTheme("preferences-system-bluetooth.png").pixmap(size())); 0077 setToolTip(i18n("Bluetooth is operational")); 0078 } 0079 else 0080 { 0081 setPixmap(QIcon::fromTheme("preferences-system-bluetooth-inactive.png").pixmap(size())); 0082 setToolTip(i18n("Bluetooth is not operational")); 0083 } 0084 } 0085 0086 //-------------------------------------------------------------------------------- 0087 0088 QWidget *Bluetooth::getDetailsList() 0089 { 0090 if ( !dialog ) 0091 { 0092 dialog = new KCMultiDialog(this); 0093 dialog->setAttribute(Qt::WA_DeleteOnClose); 0094 0095 // different KDE versions need different ways ... 0096 #if KCMUTILS_VERSION >= QT_VERSION_CHECK(5, 85, 0) 0097 KPluginMetaData module("plasma/kcms/systemsettings/kcm_bluetooth"); 0098 if ( !module.name().isEmpty() ) 0099 dialog->addModule(module); 0100 #else 0101 if ( KCModuleInfo("bluetooth").service() ) 0102 dialog->addModule("bluetooth"); 0103 else // older KDE versions 0104 { 0105 dialog->addModule("bluedevilglobal"); 0106 dialog->addModule("bluedeviladapters"); 0107 dialog->addModule("bluedevildevices"); 0108 } 0109 #endif 0110 0111 dialog->adjustSize(); 0112 dialog->setWindowTitle(i18n("Bluetooth")); 0113 } 0114 0115 return dialog; 0116 } 0117 0118 //--------------------------------------------------------------------------------