• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

Solid

  • sources
  • kde-4.12
  • kdelibs
  • solid
  • solid
networking.cpp
Go to the documentation of this file.
1 /*
2  Copyright 2006-2007 Will Stephenson <wstephenson@kde.org>
3  Copyright 2006-2007 Kevin Ottens <ervin@kde.org>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) version 3, or any
9  later version accepted by the membership of KDE e.V. (or its
10  successor approved by the membership of KDE e.V.), which shall
11  act as a proxy defined in Section 6 of version 3 of the license.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public
19  License along with this library. If not, see <http://www.gnu.org/licenses/>.
20 */
21 
22 //#include <KDebug>
23 
24 #include "networking.h"
25 #include "networking_p.h"
26 
27 #include "soliddefs_p.h"
28 #include "org_kde_solid_networking_client.h"
29 
30 SOLID_GLOBAL_STATIC(Solid::NetworkingPrivate, globalNetworkManager)
31 
32 Solid::NetworkingPrivate::NetworkingPrivate()
33  : netStatus(Solid::Networking::Unknown),
34  connectPolicy(Solid::Networking::Managed),
35  disconnectPolicy(Solid::Networking::Managed),
36  iface(0)
37 {
38  QDBusServiceWatcher *watcher = new QDBusServiceWatcher("org.kde.kded", QDBusConnection::sessionBus(),
39  QDBusServiceWatcher::WatchForOwnerChange, this);
40  connect(watcher, SIGNAL(serviceOwnerChanged(QString,QString,QString)),
41  this, SLOT(serviceOwnerChanged(QString,QString,QString)));
42 
43  initialize();
44 }
45 
46 Solid::NetworkingPrivate::~NetworkingPrivate()
47 {
48 }
49 
50 Solid::Networking::Notifier::Notifier()
51 {
52 }
53 
54 void Solid::NetworkingPrivate::initialize()
55 {
56  delete iface;
57  iface = new OrgKdeSolidNetworkingClientInterface( "org.kde.kded",
58  "/modules/networkstatus",
59  QDBusConnection::sessionBus(),
60  this);
61 
62  //connect( iface, SIGNAL(statusChanged(uint)), globalNetworkManager, SIGNAL(statusChanged(Networking::Status)) );
63  connect(iface, SIGNAL(statusChanged(uint)), this, SLOT(serviceStatusChanged(uint)));
64 
65  QDBusReply<uint> reply = iface->status();
66  if (reply.isValid()) {
67  netStatus = ( Solid::Networking::Status )reply.value();
68  } else {
69  netStatus = Solid::Networking::Unknown;
70  }
71 }
72 
73 uint Solid::NetworkingPrivate::status() const
74 {
75  return netStatus;
76 }
77 
78 /*=========================================================================*/
79 
80 Solid::Networking::Status Solid::Networking::status()
81 {
82  return static_cast<Solid::Networking::Status>( globalNetworkManager->status() );
83 }
84 
85 Solid::Networking::Notifier *Solid::Networking::notifier()
86 {
87  return globalNetworkManager;
88 }
89 
90 void Solid::NetworkingPrivate::serviceStatusChanged( uint status )
91 {
92 // kDebug( 921 ) ;
93  netStatus = ( Solid::Networking::Status )status;
94  switch ( netStatus ) {
95  case Solid::Networking::Unknown:
96  break;
97  case Solid::Networking::Unconnected:
98  case Solid::Networking::Disconnecting:
99  case Solid::Networking::Connecting:
100  if ( disconnectPolicy == Solid::Networking::Managed ) {
101  emit globalNetworkManager->shouldDisconnect();
102  } else if ( disconnectPolicy == Solid::Networking::OnNextStatusChange ) {
103  setDisconnectPolicy( Solid::Networking::Manual );
104  emit globalNetworkManager->shouldDisconnect();
105  }
106  break;
107  case Solid::Networking::Connected:
108  if ( disconnectPolicy == Solid::Networking::Managed ) {
109  emit globalNetworkManager->shouldConnect();
110  } else if ( disconnectPolicy == Solid::Networking::OnNextStatusChange ) {
111  setConnectPolicy( Solid::Networking::Manual );
112  emit globalNetworkManager->shouldConnect();
113  }
114  break;
115 // default:
116 // kDebug( 921 ) << "Unrecognised status code!";
117  }
118  emit globalNetworkManager->statusChanged( netStatus );
119 }
120 
121 void Solid::NetworkingPrivate::serviceOwnerChanged( const QString & name, const QString & oldOwner, const QString & newOwner )
122 {
123  Q_UNUSED(name)
124  Q_UNUSED(oldOwner)
125  if ( newOwner.isEmpty() ) {
126  // kded quit on us
127  netStatus = Solid::Networking::Unknown;
128  emit globalNetworkManager->statusChanged( netStatus );
129 
130  } else {
131  // kded was replaced or started
132  initialize();
133  emit globalNetworkManager->statusChanged( netStatus );
134  serviceStatusChanged( netStatus );
135  }
136 }
137 
138 Solid::Networking::ManagementPolicy Solid::Networking::connectPolicy()
139 {
140  return globalNetworkManager->connectPolicy;
141 }
142 
143 void Solid::Networking::setConnectPolicy( Solid::Networking::ManagementPolicy policy )
144 {
145  globalNetworkManager->connectPolicy = policy;
146 }
147 
148 Solid::Networking::ManagementPolicy Solid::Networking::disconnectPolicy()
149 {
150  return globalNetworkManager->disconnectPolicy;
151 }
152 
153 void Solid::Networking::setDisconnectPolicy( Solid::Networking::ManagementPolicy policy )
154 {
155  globalNetworkManager->disconnectPolicy = policy;
156 }
157 
158 #include "networking_p.moc"
159 #include "networking.moc"
Solid::Networking::Notifier::Notifier
Notifier()
Definition: networking.cpp:50
Solid::NetworkingPrivate::~NetworkingPrivate
~NetworkingPrivate()
Definition: networking.cpp:46
Solid::Networking::Connecting
the system is not connected to any network
Definition: networking.h:49
Solid::Networking::setDisconnectPolicy
SOLID_EXPORT void setDisconnectPolicy(ManagementPolicy policy)
Set a policy to manage the application's disconnect behaviour.
Definition: networking.cpp:153
Solid::Networking::disconnectPolicy
SOLID_EXPORT ManagementPolicy disconnectPolicy()
Retrieve a policy managing the application's disconnect behaviour.
Definition: networking.cpp:148
Solid::Networking::notifier
SOLID_EXPORT Notifier * notifier()
Definition: networking.cpp:85
Solid::Networking::Manual
Manual - the app should only disconnect when the user does so manually.
Definition: networking.h:57
Solid::Networking::ManagementPolicy
ManagementPolicy
This defines application policy in response to networking connect/disconnect events.
Definition: networking.h:56
SOLID_GLOBAL_STATIC
#define SOLID_GLOBAL_STATIC(TYPE, NAME)
Definition: soliddefs_p.h:77
Solid::Networking::status
SOLID_EXPORT Status status()
Get the current networking status If the result is Unknown, the backend may be unconfigured or otherw...
Definition: networking.cpp:80
Solid::Networking::setConnectPolicy
SOLID_EXPORT void setConnectPolicy(ManagementPolicy policy)
Set a policy to manage the application's connect behaviour.
Definition: networking.cpp:143
Solid::Networking::connectPolicy
SOLID_EXPORT ManagementPolicy connectPolicy()
Retrieve a policy managing the application's connect behaviour.
Definition: networking.cpp:138
Solid::Networking::OnNextStatusChange
the app should connect or disconnect the next time the network changes status, thereafter Manual ...
Definition: networking.h:58
soliddefs_p.h
networking.h
Solid::Networking::Unconnected
the system is not connected to any network
Definition: networking.h:47
Solid::Networking::Unknown
the networking system is not active or unable to report its status - proceed with caution ...
Definition: networking.h:46
Solid::NetworkingPrivate::serviceStatusChanged
void serviceStatusChanged(bool status)
Definition: networking.cpp:90
Solid::NetworkingPrivate
Definition: networking_p.h:38
Solid::Networking::Status
Status
Describes the state of the networking system.
Definition: networking.h:45
Solid::Networking::Connected
the system is currently connected to a network
Definition: networking.h:50
networking_p.h
Solid::Networking::Managed
the app should connect or disconnect whenever the KConnectionManager reports a state change ...
Definition: networking.h:59
Solid::Networking::Disconnecting
the system is breaking the connection
Definition: networking.h:48
Solid::Networking::Notifier
This object emits signals, for use if your application requires notification of changes to networking...
Definition: networking.h:97
Solid::NetworkingPrivate::status
uint status() const
Definition: networking.cpp:73
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:48:47 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Solid

Skip menu "Solid"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal