File indexing completed on 2024-05-12 17:07:35

0001 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0002 // SPDX-FileCopyrightText: 2018 Alexis Lopes Zubeta <contact@azubieta.net>
0003 // SPDX-FileCopyrightText: 2020 Tomaz Canabrava <tcanabrava@kde.org>
0004 
0005 #include "netstatclient.h"
0006 
0007 #include <QStandardPaths>
0008 
0009 /* Access to the Netstat Client thru the Connections Model */
0010 static NetstatClient *_self = nullptr;
0011 
0012 NetstatClient *NetstatClient::self()
0013 {
0014     assert(_self);
0015     return _self;
0016 }
0017 
0018 NetstatClient::NetstatClient(QObject *parent)
0019     : QObject(parent)
0020     , m_connections(new ConnectionsModel(this))
0021 {
0022     _self = this;
0023     mHasSS = !QStandardPaths::findExecutable(QStringLiteral("ss")).isEmpty();
0024 }
0025 
0026 bool NetstatClient::hasSS() const
0027 {
0028     return mHasSS;
0029 }
0030 
0031 ConnectionsModel *NetstatClient::connectionsModel() const
0032 {
0033     return m_connections;
0034 }
0035 
0036 void NetstatClient::setStatus(const QString &message)
0037 {
0038     if (mStatus != message) {
0039         mStatus = message;
0040         Q_EMIT statusChanged(mStatus);
0041     }
0042 }
0043 
0044 QString NetstatClient::status() const
0045 {
0046     return mStatus;
0047 }