File indexing completed on 2024-10-06 09:39:39
0001 /* 0002 This file is part of the KDE project 0003 SPDX-FileCopyrightText: 2007 Will Stephenson <wstephenson@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-only WITH Qt-Commercial-exception-1.0 0006 */ 0007 0008 #include "kstatusbarofflineindicator.h" 0009 0010 #if KIOFILEWIDGETS_BUILD_DEPRECATED_SINCE(5, 70) 0011 0012 #include <KIconLoader> 0013 #include <KLocalizedString> 0014 #include <QLabel> 0015 #include <QVBoxLayout> 0016 0017 #include <QIcon> 0018 #include <QNetworkConfigurationManager> 0019 0020 class KStatusBarOfflineIndicatorPrivate 0021 { 0022 public: 0023 // Silence deprecation warnings as there is no Qt 5 substitute for QNetworkConfigurationManager 0024 QT_WARNING_PUSH 0025 QT_WARNING_DISABLE_CLANG("-Wdeprecated-declarations") 0026 QT_WARNING_DISABLE_GCC("-Wdeprecated-declarations") 0027 explicit KStatusBarOfflineIndicatorPrivate(KStatusBarOfflineIndicator *parent) 0028 : q(parent) 0029 , networkConfiguration(new QNetworkConfigurationManager(parent)) 0030 { 0031 } 0032 QT_WARNING_POP 0033 0034 void initialize(); 0035 void networkStatusChanged(bool isOnline); 0036 0037 KStatusBarOfflineIndicator *const q; 0038 // Silence deprecation warnings as there is no Qt 5 substitute for QNetworkConfigurationManager 0039 QT_WARNING_PUSH 0040 QT_WARNING_DISABLE_CLANG("-Wdeprecated-declarations") 0041 QT_WARNING_DISABLE_GCC("-Wdeprecated-declarations") 0042 QNetworkConfigurationManager *networkConfiguration; 0043 QT_WARNING_POP 0044 }; 0045 0046 KStatusBarOfflineIndicator::KStatusBarOfflineIndicator(QWidget *parent) 0047 : QWidget(parent) 0048 , d(new KStatusBarOfflineIndicatorPrivate(this)) 0049 { 0050 QVBoxLayout *layout = new QVBoxLayout(this); 0051 layout->setContentsMargins(2, 2, 2, 2); 0052 QLabel *label = new QLabel(this); 0053 label->setPixmap(QIcon::fromTheme(QStringLiteral("network-disconnect")).pixmap(KIconLoader::SizeSmall)); 0054 label->setToolTip(i18n("The desktop is offline")); 0055 layout->addWidget(label); 0056 d->initialize(); 0057 // Silence deprecation warnings as there is no Qt 5 substitute for QNetworkConfigurationManager 0058 QT_WARNING_PUSH 0059 QT_WARNING_DISABLE_CLANG("-Wdeprecated-declarations") 0060 QT_WARNING_DISABLE_GCC("-Wdeprecated-declarations") 0061 connect(d->networkConfiguration, &QNetworkConfigurationManager::onlineStateChanged, this, [this](bool isOnline) { 0062 d->networkStatusChanged(isOnline); 0063 }); 0064 QT_WARNING_POP 0065 } 0066 0067 KStatusBarOfflineIndicator::~KStatusBarOfflineIndicator() = default; 0068 0069 void KStatusBarOfflineIndicatorPrivate::initialize() 0070 { 0071 networkStatusChanged(networkConfiguration->isOnline()); 0072 } 0073 0074 void KStatusBarOfflineIndicatorPrivate::networkStatusChanged(bool isOnline) 0075 { 0076 if (isOnline) { 0077 q->hide(); 0078 } else { 0079 q->show(); 0080 } 0081 } 0082 0083 #include "moc_kstatusbarofflineindicator.cpp" 0084 0085 #endif