diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-09-04 17:53:12 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-09-04 17:53:12 +0000 |
commit | af20635a2bb11eefabb627a2419644d3ac78831d (patch) | |
tree | a10097346376a69cf49288d3bd592b635a8744f9 /networkstatus/network.cpp | |
parent | 84ae8923dff22da5912d9a322db515ce0a2388c7 (diff) | |
download | tdelibs-af20635a2bb11eefabb627a2419644d3ac78831d.tar.gz tdelibs-af20635a2bb11eefabb627a2419644d3ac78831d.zip |
Added networkstatus service from pim to core for use in other network enabled applications
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdelibs@1171617 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'networkstatus/network.cpp')
-rw-r--r-- | networkstatus/network.cpp | 87 |
1 files changed, 59 insertions, 28 deletions
diff --git a/networkstatus/network.cpp b/networkstatus/network.cpp index a937634cb..fcb4a6f51 100644 --- a/networkstatus/network.cpp +++ b/networkstatus/network.cpp @@ -1,9 +1,12 @@ -/* This file is part of kdepim. - Copyright (C) 2005,2007 Will Stephenson <wstephenson@kde.org> +/* + This file is part of kdepim. + + Copyright (c) 2005 Will Stephenson <lists@stevello.free-online.co.uk> 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. + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -11,52 +14,80 @@ 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, + along with this library; see the file COPYING.LIB. 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 TQt, and distribute the resulting executable, - without including the source code for TQt in the source distribution. */ #include <kdebug.h> #include "network.h" -Network::Network( NetworkStatus::Properties properties ) - : m_name( properties.name ), m_status( properties.status ), m_service( properties.service ) -{ -} - -void Network::setStatus( NetworkStatus::Status status ) +Network::Network( const TQString name, NetworkStatus::Properties properties ) + : m_name( name ) { - m_status = status; + kdDebug() << k_funcinfo << "constructing network '" << name << "', status: " << properties.status << endl; + m_status = properties.status; + m_netmasks = properties.netmasks; + m_internet = properties.internet; + m_service = properties.service; + m_onDemandPolicy = properties.onDemandPolicy; } -NetworkStatus::Status Network::status() +NetworkStatus::EnumStatus Network::reachabilityFor( const TQString & host ) { - return m_status; + // initially assume all networks are internet + // TODO: compute reachability properly + Q_UNUSED( host ); + if ( true /*nss.properties.internet && notPrivateNetwork( host )*/ ) + { + NetworkStatus::EnumStatus status; + if ( m_status == NetworkStatus::Establishing || m_status == NetworkStatus::Online ) + status = NetworkStatus::Online; + else if ( m_status == NetworkStatus::ShuttingDown || m_status == NetworkStatus::Offline ) + status = NetworkStatus::Offline; + else + status = m_status; + + return status; + } } -void Network::setName( const TQString& name ) +void Network::registerUsage( const TQCString appId, const TQString host ) { - m_name = name; + NetworkUsageStruct nus; + nus.appId = appId; + nus.host = host; + NetworkUsageList::iterator end = m_usage.end(); + for ( NetworkUsageList::iterator it = m_usage.begin(); it != end; ++it ) + { + if ( (*it).appId == appId && (*it).host == host ) + return; + } + kdDebug() << k_funcinfo << "registering " << appId << " as using network " << m_name << " for " << host << endl; + m_usage.append( nus ); } -TQString Network::name() +void Network::unregisterUsage( const TQCString appId, const TQString host ) { - return m_name; + NetworkUsageList::iterator end = m_usage.end(); + for ( NetworkUsageList::iterator it = m_usage.begin(); it != end; ++it ) + { + if ( (*it).appId == appId && (*it).host == host ) + { + kdDebug() << k_funcinfo << "unregistering " << appId << "'s usage of " << m_name << " for " << host << endl; + m_usage.remove( it ); + break; + } + } } -TQString Network::service() +void Network::setStatus( NetworkStatus::EnumStatus status ) { - return m_service; + m_status = status; } -void Network::setService( const TQString& service ) +void Network::removeAllUsage() { - m_service = service; + m_usage.clear(); } - -// vim: sw=4 ts=4 |