File indexing completed on 2024-05-12 05:46:43
0001 /* This file is part of the KDE project 0002 Copyright (C) 2007 Will Stephenson <wstephenson@kde.org> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License version 2 as published by the Free Software Foundation. 0007 0008 This library is distributed in the hope that it will be useful, 0009 but WITHOUT ANY WARRANTY; without even the implied warranty of 0010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0011 Library General Public License for more details. 0012 0013 You should have received a copy of the GNU Library General Public License 0014 along with this library. If not, write to the Free Software 0015 Foundation, Inc., 51 Franklin Street, Fifth Floor, 0016 Boston, MA 02110-1301, USA. 0017 0018 As a special exception, permission is given to link this library 0019 with any edition of Qt, and distribute the resulting executable, 0020 without including the source code for Qt in the source distribution. 0021 */ 0022 0023 #include "kstatusbarofflineindicator.h" 0024 0025 #include <QLabel> 0026 #include <QVBoxLayout> 0027 #include <kiconloader.h> 0028 #include <klocalizedstring.h> 0029 0030 #include <QIcon> 0031 #include <QNetworkConfigurationManager> 0032 0033 class KStatusBarOfflineIndicatorPrivate 0034 { 0035 public: 0036 explicit KStatusBarOfflineIndicatorPrivate(KStatusBarOfflineIndicator *parent) 0037 : q(parent) 0038 , networkConfiguration(new QNetworkConfigurationManager(parent)) 0039 { 0040 } 0041 0042 void initialize(); 0043 void _k_networkStatusChanged(bool isOnline); 0044 0045 KStatusBarOfflineIndicator * const q; 0046 QNetworkConfigurationManager *networkConfiguration; 0047 }; 0048 0049 KStatusBarOfflineIndicator::KStatusBarOfflineIndicator(QWidget *parent) 0050 : QWidget(parent), 0051 d(new KStatusBarOfflineIndicatorPrivate(this)) 0052 { 0053 QVBoxLayout *layout = new QVBoxLayout(this); 0054 layout->setContentsMargins(2, 2, 2, 2); 0055 QLabel *label = new QLabel(this); 0056 label->setPixmap(QIcon::fromTheme(QStringLiteral("network-disconnect")).pixmap(KIconLoader::SizeSmall)); 0057 label->setToolTip(i18n("The desktop is offline")); 0058 layout->addWidget(label); 0059 d->initialize(); 0060 connect(d->networkConfiguration, SIGNAL(onlineStateChanged(bool)), 0061 SLOT(_k_networkStatusChanged(bool))); 0062 } 0063 0064 KStatusBarOfflineIndicator::~KStatusBarOfflineIndicator() 0065 { 0066 delete d; 0067 } 0068 0069 void KStatusBarOfflineIndicatorPrivate::initialize() 0070 { 0071 _k_networkStatusChanged(networkConfiguration->isOnline()); 0072 } 0073 0074 void KStatusBarOfflineIndicatorPrivate::_k_networkStatusChanged(bool isOnline) 0075 { 0076 if (isOnline) { 0077 q->hide(); 0078 } else { 0079 q->show(); 0080 } 0081 } 0082 0083 #include "moc_kstatusbarofflineindicator.cpp"