diff --git a/ktorrent/CMakeLists.txt b/ktorrent/CMakeLists.txt --- a/ktorrent/CMakeLists.txt +++ b/ktorrent/CMakeLists.txt @@ -8,6 +8,7 @@ trayicon.cpp ipfilterlist.cpp ipfilterwidget.cpp + statusbarofflineindicator.cpp tools/queuemanagerwidget.cpp tools/queuemanagermodel.cpp diff --git a/ktorrent/statusbar.cpp b/ktorrent/statusbar.cpp --- a/ktorrent/statusbar.cpp +++ b/ktorrent/statusbar.cpp @@ -24,11 +24,11 @@ #include #include #include -#include #include #include +#include "statusbarofflineindicator.h" using namespace bt; namespace kt @@ -57,7 +57,7 @@ transfer->setFrameShadow(QFrame::Sunken); addPermanentWidget(transfer); - addPermanentWidget(new KStatusBarOfflineIndicator(this)); + addPermanentWidget(new StatusBarOfflineIndicator(this)); } StatusBar::~StatusBar() diff --git a/ktorrent/statusbarofflineindicator.h b/ktorrent/statusbarofflineindicator.h new file mode 100644 --- /dev/null +++ b/ktorrent/statusbarofflineindicator.h @@ -0,0 +1,49 @@ +/* This file is part of the KDE project + Copyright (C) 2007 Will Stephenson + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library. If not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + As a special exception, permission is given to link this library + with any edition of Qt, and distribute the resulting executable, + without including the source code for Qt in the source distribution. +*/ + +#ifndef STATUSBAROFFLINEINDICATOR_H +#define STATUSBAROFFLINEINDICATOR_H + +#include + +class StatusBarOfflineIndicatorPrivate; + +class StatusBarOfflineIndicator : public QWidget +{ + Q_OBJECT +public: + /** + * Default constructor. + * @param parent the widget's parent + */ + explicit StatusBarOfflineIndicator(QWidget *parent); + ~StatusBarOfflineIndicator(); + +private: + StatusBarOfflineIndicatorPrivate *const d; + + Q_PRIVATE_SLOT(d, void _k_networkStatusChanged(bool isOnline)) +}; + +#endif + + diff --git a/ktorrent/statusbarofflineindicator.cpp b/ktorrent/statusbarofflineindicator.cpp new file mode 100644 --- /dev/null +++ b/ktorrent/statusbarofflineindicator.cpp @@ -0,0 +1,83 @@ +/* This file is part of the KDE project + Copyright (C) 2007 Will Stephenson + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library. If not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + As a special exception, permission is given to link this library + with any edition of Qt, and distribute the resulting executable, + without including the source code for Qt in the source distribution. +*/ + +#include "statusbarofflineindicator.h" + +#include +#include +#include +#include + +#include +#include + +class StatusBarOfflineIndicatorPrivate +{ +public: + explicit StatusBarOfflineIndicatorPrivate(StatusBarOfflineIndicator *parent) + : q(parent) + , networkConfiguration(new QNetworkConfigurationManager(parent)) + { + } + + void initialize(); + void _k_networkStatusChanged(bool isOnline); + + StatusBarOfflineIndicator * const q; + QNetworkConfigurationManager *networkConfiguration; +}; + +StatusBarOfflineIndicator::StatusBarOfflineIndicator(QWidget *parent) + : QWidget(parent), + d(new StatusBarOfflineIndicatorPrivate(this)) +{ + QVBoxLayout *layout = new QVBoxLayout(this); + layout->setContentsMargins(2, 2, 2, 2); + QLabel *label = new QLabel(this); + label->setPixmap(QIcon::fromTheme(QStringLiteral("network-disconnect")).pixmap(KIconLoader::SizeSmall)); + label->setToolTip(i18n("The desktop is offline")); + layout->addWidget(label); + d->initialize(); + connect(d->networkConfiguration, SIGNAL(onlineStateChanged(bool)), + SLOT(_k_networkStatusChanged(bool))); +} + +StatusBarOfflineIndicator::~StatusBarOfflineIndicator() +{ + delete d; +} + +void StatusBarOfflineIndicatorPrivate::initialize() +{ + _k_networkStatusChanged(networkConfiguration->isOnline()); +} + +void StatusBarOfflineIndicatorPrivate::_k_networkStatusChanged(bool isOnline) +{ + if (isOnline) { + q->hide(); + } else { + q->show(); + } +} + +#include "moc_statusbarofflineindicator.cpp"