File indexing completed on 2024-03-24 15:27:58

0001 /*
0002     Copyright 2013      Patrick von Reth <vonreth@kde.org>
0003     Copyright 2006-2007 Will Stephenson <wstephenson@kde.org>
0004     Copyright 2006-2007 Kevin Ottens <ervin@kde.org>
0005 
0006     This library is free software; you can redistribute it and/or
0007     modify it under the terms of the GNU Lesser General Public
0008     License as published by the Free Software Foundation; either
0009     version 2.1 of the License, or (at your option) version 3, or any
0010     later version accepted by the membership of KDE e.V. (or its
0011     successor approved by the membership of KDE e.V.), which shall
0012     act as a proxy defined in Section 6 of version 3 of the license.
0013 
0014     This library is distributed in the hope that it will be useful,
0015     but WITHOUT ANY WARRANTY; without even the implied warranty of
0016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0017     Lesser General Public License for more details.
0018 
0019     You should have received a copy of the GNU Lesser General Public
0020     License along with this library. If not, see <http://www.gnu.org/licenses/>.
0021 */
0022 
0023 //#include <KDebug>
0024 
0025 #include "networking.h"
0026 #include "networking_p.h"
0027 
0028 Solid::NetworkingPrivate::NetworkingPrivate()
0029     : netStatus(Solid::Networking::Unknown),
0030       connectPolicy(Solid::Networking::Managed),
0031       disconnectPolicy(Solid::Networking::Managed),
0032       m_manager(new QNetworkConfigurationManager())
0033 {
0034     initialize();
0035 }
0036 
0037 Solid::NetworkingPrivate::~NetworkingPrivate()
0038 {
0039     m_manager->deleteLater();
0040 }
0041 
0042 void Solid::NetworkingPrivate::initialize()
0043 {
0044 
0045     netStatus = m_manager->isOnline() ? Solid::Networking::Connected : Solid::Networking::Unconnected;
0046 
0047     connect(m_manager, SIGNAL(onlineStateChanged(bool)), this, SLOT(serviceStatusChanged(bool)));
0048 }
0049 
0050 void Solid::NetworkingPrivate::serviceStatusChanged(bool status)
0051 {
0052 //    kDebug( 921 ) ;
0053     netStatus = status ? Solid::Networking::Connected : Solid::Networking::Unconnected;
0054     switch (netStatus) {
0055     case Solid::Networking::Unknown:
0056         break;
0057     case Solid::Networking::Unconnected:
0058         emit Solid::Networking::notifier()->shouldDisconnect();
0059         break;
0060     case Solid::Networking::Connected:
0061         emit Solid::Networking::notifier()->shouldConnect();
0062         break;
0063     default:
0064         break;
0065 //        kDebug( 921 ) <<  "Unrecognised status code!";
0066     }
0067     emit Solid::Networking::notifier()->statusChanged(netStatus);
0068 }
0069 
0070 void Solid::NetworkingPrivate::serviceOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner)
0071 {
0072     Q_UNUSED(name)
0073     Q_UNUSED(oldOwner)
0074     if (newOwner.isEmpty()) {
0075         // kded quit on us
0076         netStatus = Solid::Networking::Unknown;
0077         emit Solid::Networking::notifier()->statusChanged(netStatus);
0078 
0079     } else {
0080         // kded was replaced or started
0081         initialize();
0082         emit Solid::Networking::notifier()->statusChanged(netStatus);
0083         serviceStatusChanged(netStatus == Solid::Networking::Connected);
0084     }
0085 }