KIO

kstatusbarofflineindicator.cpp
1 /*
2  This file is part of the KDE project
3  SPDX-FileCopyrightText: 2007 Will Stephenson <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.0-only WITH Qt-Commercial-exception-1.0
6 */
7 
8 #include "kstatusbarofflineindicator.h"
9 
10 #if KIOFILEWIDGETS_BUILD_DEPRECATED_SINCE(5, 70)
11 
12 #include <KIconLoader>
13 #include <KLocalizedString>
14 #include <QLabel>
15 #include <QVBoxLayout>
16 
17 #include <QIcon>
18 #include <QNetworkConfigurationManager>
19 
20 class KStatusBarOfflineIndicatorPrivate
21 {
22 public:
23  // Silence deprecation warnings as there is no Qt 5 substitute for QNetworkConfigurationManager
24  QT_WARNING_PUSH
25  QT_WARNING_DISABLE_CLANG("-Wdeprecated-declarations")
26  QT_WARNING_DISABLE_GCC("-Wdeprecated-declarations")
27  explicit KStatusBarOfflineIndicatorPrivate(KStatusBarOfflineIndicator *parent)
28  : q(parent)
29  , networkConfiguration(new QNetworkConfigurationManager(parent))
30  {
31  }
32  QT_WARNING_POP
33 
34  void initialize();
35  void networkStatusChanged(bool isOnline);
36 
38  // Silence deprecation warnings as there is no Qt 5 substitute for QNetworkConfigurationManager
39  QT_WARNING_PUSH
40  QT_WARNING_DISABLE_CLANG("-Wdeprecated-declarations")
41  QT_WARNING_DISABLE_GCC("-Wdeprecated-declarations")
42  QNetworkConfigurationManager *networkConfiguration;
43  QT_WARNING_POP
44 };
45 
47  : QWidget(parent)
48  , d(new KStatusBarOfflineIndicatorPrivate(this))
49 {
50  QVBoxLayout *layout = new QVBoxLayout(this);
51  layout->setContentsMargins(2, 2, 2, 2);
52  QLabel *label = new QLabel(this);
53  label->setPixmap(QIcon::fromTheme(QStringLiteral("network-disconnect")).pixmap(KIconLoader::SizeSmall));
54  label->setToolTip(i18n("The desktop is offline"));
55  layout->addWidget(label);
56  d->initialize();
57  // Silence deprecation warnings as there is no Qt 5 substitute for QNetworkConfigurationManager
58  QT_WARNING_PUSH
59  QT_WARNING_DISABLE_CLANG("-Wdeprecated-declarations")
60  QT_WARNING_DISABLE_GCC("-Wdeprecated-declarations")
61  connect(d->networkConfiguration, &QNetworkConfigurationManager::onlineStateChanged, this, [this](bool isOnline) {
62  d->networkStatusChanged(isOnline);
63  });
64  QT_WARNING_POP
65 }
66 
67 KStatusBarOfflineIndicator::~KStatusBarOfflineIndicator() = default;
68 
69 void KStatusBarOfflineIndicatorPrivate::initialize()
70 {
71  networkStatusChanged(networkConfiguration->isOnline());
72 }
73 
74 void KStatusBarOfflineIndicatorPrivate::networkStatusChanged(bool isOnline)
75 {
76  if (isOnline) {
77  q->hide();
78  } else {
79  q->show();
80  }
81 }
82 
83 #include "moc_kstatusbarofflineindicator.cpp"
84 
85 #endif
QIcon fromTheme(const QString &name)
void hide()
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
void initialize(StandardShortcut id)
QString i18n(const char *text, const TYPE &arg...)
void show()
void setContentsMargins(int left, int top, int right, int bottom)
void onlineStateChanged(bool isOnline)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Feb 7 2023 04:00:36 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.