mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 18:32:49 +00:00
solid: remove unused connect/disconnect policy API
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
e4345f58ed
commit
2344fa495f
3 changed files with 66 additions and 136 deletions
|
@ -31,22 +31,20 @@ Q_GLOBAL_STATIC(Solid::NetworkingPrivate, globalNetworkManager)
|
|||
|
||||
Solid::NetworkingPrivate::NetworkingPrivate()
|
||||
: netStatus(Solid::Networking::Unknown),
|
||||
connectPolicy(Solid::Networking::Managed),
|
||||
disconnectPolicy(Solid::Networking::Managed),
|
||||
iface(0)
|
||||
iface(nullptr)
|
||||
{
|
||||
QDBusServiceWatcher *watcher = new QDBusServiceWatcher("org.kde.kded", QDBusConnection::sessionBus(),
|
||||
QDBusServiceWatcher::WatchForOwnerChange, this);
|
||||
connect(watcher, SIGNAL(serviceOwnerChanged(QString,QString,QString)),
|
||||
this, SLOT(serviceOwnerChanged(QString,QString,QString)));
|
||||
QDBusServiceWatcher *watcher = new QDBusServiceWatcher(
|
||||
"org.kde.kded", QDBusConnection::sessionBus(),
|
||||
QDBusServiceWatcher::WatchForOwnerChange, this
|
||||
);
|
||||
connect(
|
||||
watcher, SIGNAL(serviceOwnerChanged(QString,QString,QString)),
|
||||
this, SLOT(serviceOwnerChanged(QString,QString,QString))
|
||||
);
|
||||
|
||||
initialize();
|
||||
}
|
||||
|
||||
Solid::NetworkingPrivate::~NetworkingPrivate()
|
||||
{
|
||||
}
|
||||
|
||||
Solid::Networking::Notifier::Notifier()
|
||||
{
|
||||
}
|
||||
|
@ -54,17 +52,19 @@ Solid::Networking::Notifier::Notifier()
|
|||
void Solid::NetworkingPrivate::initialize()
|
||||
{
|
||||
delete iface;
|
||||
iface = new OrgKdeSolidNetworkingClientInterface( "org.kde.kded",
|
||||
"/modules/networkstatus",
|
||||
QDBusConnection::sessionBus(),
|
||||
this);
|
||||
iface = new OrgKdeSolidNetworkingClientInterface(
|
||||
"org.kde.kded",
|
||||
"/modules/networkstatus",
|
||||
QDBusConnection::sessionBus(),
|
||||
this
|
||||
);
|
||||
|
||||
//connect( iface, SIGNAL(statusChanged(uint)), globalNetworkManager(), SIGNAL(statusChanged(Networking::Status)) );
|
||||
// connect(iface, SIGNAL(statusChanged(uint)), globalNetworkManager(), SIGNAL(statusChanged(Networking::Status)));
|
||||
connect(iface, SIGNAL(statusChanged(uint)), this, SLOT(serviceStatusChanged(uint)));
|
||||
|
||||
QDBusReply<uint> reply = iface->status();
|
||||
if (reply.isValid()) {
|
||||
netStatus = ( Solid::Networking::Status )reply.value();
|
||||
netStatus = static_cast<Solid::Networking::Status>(reply.value());
|
||||
} else {
|
||||
netStatus = Solid::Networking::Unknown;
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ uint Solid::NetworkingPrivate::status() const
|
|||
|
||||
Solid::Networking::Status Solid::Networking::status()
|
||||
{
|
||||
return static_cast<Solid::Networking::Status>( globalNetworkManager()->status() );
|
||||
return static_cast<Solid::Networking::Status>(globalNetworkManager()->status());
|
||||
}
|
||||
|
||||
Solid::Networking::Notifier *Solid::Networking::notifier()
|
||||
|
@ -87,73 +87,42 @@ Solid::Networking::Notifier *Solid::Networking::notifier()
|
|||
return globalNetworkManager();
|
||||
}
|
||||
|
||||
void Solid::NetworkingPrivate::serviceStatusChanged( uint status )
|
||||
void Solid::NetworkingPrivate::serviceStatusChanged(uint status)
|
||||
{
|
||||
// kDebug( 921 ) ;
|
||||
netStatus = ( Solid::Networking::Status )status;
|
||||
switch ( netStatus ) {
|
||||
case Solid::Networking::Unknown:
|
||||
break;
|
||||
case Solid::Networking::Unconnected:
|
||||
case Solid::Networking::Disconnecting:
|
||||
case Solid::Networking::Connecting:
|
||||
if ( disconnectPolicy == Solid::Networking::Managed ) {
|
||||
emit globalNetworkManager()->shouldDisconnect();
|
||||
} else if ( disconnectPolicy == Solid::Networking::OnNextStatusChange ) {
|
||||
setDisconnectPolicy( Solid::Networking::Manual );
|
||||
emit globalNetworkManager()->shouldDisconnect();
|
||||
}
|
||||
break;
|
||||
case Solid::Networking::Connected:
|
||||
if ( disconnectPolicy == Solid::Networking::Managed ) {
|
||||
emit globalNetworkManager()->shouldConnect();
|
||||
} else if ( disconnectPolicy == Solid::Networking::OnNextStatusChange ) {
|
||||
setConnectPolicy( Solid::Networking::Manual );
|
||||
emit globalNetworkManager()->shouldConnect();
|
||||
}
|
||||
break;
|
||||
// default:
|
||||
// kDebug( 921 ) << "Unrecognised status code!";
|
||||
// kDebug(921) ;
|
||||
netStatus = static_cast<Solid::Networking::Status>(status);
|
||||
switch (netStatus) {
|
||||
case Solid::Networking::Unknown:
|
||||
break;
|
||||
case Solid::Networking::Unconnected:
|
||||
case Solid::Networking::Disconnecting:
|
||||
case Solid::Networking::Connecting:
|
||||
emit globalNetworkManager()->shouldDisconnect();
|
||||
break;
|
||||
case Solid::Networking::Connected:
|
||||
emit globalNetworkManager()->shouldConnect();
|
||||
break;
|
||||
// default:
|
||||
// kDebug(921) << "Unrecognised status code!";
|
||||
}
|
||||
emit globalNetworkManager()->statusChanged( netStatus );
|
||||
emit globalNetworkManager()->statusChanged(netStatus);
|
||||
}
|
||||
|
||||
void Solid::NetworkingPrivate::serviceOwnerChanged( const QString & name, const QString & oldOwner, const QString & newOwner )
|
||||
void Solid::NetworkingPrivate::serviceOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner)
|
||||
{
|
||||
Q_UNUSED(name)
|
||||
Q_UNUSED(oldOwner)
|
||||
if ( newOwner.isEmpty() ) {
|
||||
if (newOwner.isEmpty()) {
|
||||
// kded quit on us
|
||||
netStatus = Solid::Networking::Unknown;
|
||||
emit globalNetworkManager()->statusChanged( netStatus );
|
||||
|
||||
emit globalNetworkManager()->statusChanged(netStatus);
|
||||
} else {
|
||||
// kded was replaced or started
|
||||
initialize();
|
||||
emit globalNetworkManager()->statusChanged( netStatus );
|
||||
serviceStatusChanged( netStatus );
|
||||
emit globalNetworkManager()->statusChanged(netStatus);
|
||||
serviceStatusChanged(netStatus);
|
||||
}
|
||||
}
|
||||
|
||||
Solid::Networking::ManagementPolicy Solid::Networking::connectPolicy()
|
||||
{
|
||||
return globalNetworkManager()->connectPolicy;
|
||||
}
|
||||
|
||||
void Solid::Networking::setConnectPolicy( Solid::Networking::ManagementPolicy policy )
|
||||
{
|
||||
globalNetworkManager()->connectPolicy = policy;
|
||||
}
|
||||
|
||||
Solid::Networking::ManagementPolicy Solid::Networking::disconnectPolicy()
|
||||
{
|
||||
return globalNetworkManager()->disconnectPolicy;
|
||||
}
|
||||
|
||||
void Solid::Networking::setDisconnectPolicy( Solid::Networking::ManagementPolicy policy )
|
||||
{
|
||||
globalNetworkManager()->disconnectPolicy = policy;
|
||||
}
|
||||
|
||||
#include "moc_networking_p.cpp"
|
||||
#include "moc_networking.cpp"
|
||||
|
|
|
@ -50,15 +50,6 @@ namespace Solid
|
|||
Connected /**< the system is currently connected to a network */
|
||||
};
|
||||
|
||||
/**
|
||||
* This defines application policy in response to networking connect/disconnect events
|
||||
*/
|
||||
enum ManagementPolicy {
|
||||
Manual, /**< Manual - the app should only disconnect when the user does so manually */
|
||||
OnNextStatusChange, /**< the app should connect or disconnect the next time the network changes status, thereafter Manual */
|
||||
Managed /**< the app should connect or disconnect whenever the KConnectionManager reports a state change */
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the current networking status
|
||||
* If the result is Unknown, the backend may be unconfigured or otherwise in a state where
|
||||
|
@ -66,60 +57,32 @@ namespace Solid
|
|||
*/
|
||||
SOLID_EXPORT Status status();
|
||||
|
||||
/**
|
||||
* Set a policy to manage the application's connect behaviour
|
||||
* @param policy the new connection policy
|
||||
*/
|
||||
SOLID_EXPORT void setConnectPolicy( ManagementPolicy policy );
|
||||
|
||||
/**
|
||||
* Retrieve a policy managing the application's connect behaviour
|
||||
* @return the connection policy in use
|
||||
*/
|
||||
SOLID_EXPORT ManagementPolicy connectPolicy();
|
||||
|
||||
/**
|
||||
* Set a policy to manage the application's disconnect behaviour
|
||||
* @param policy the new disconnection policy
|
||||
*/
|
||||
SOLID_EXPORT void setDisconnectPolicy( ManagementPolicy policy );
|
||||
|
||||
/**
|
||||
* Retrieve a policy managing the application's disconnect behaviour
|
||||
* @return the disconnection policy in use
|
||||
*/
|
||||
SOLID_EXPORT ManagementPolicy disconnectPolicy();
|
||||
|
||||
/**
|
||||
* This object emits signals, for use if your application requires notification
|
||||
* of changes to networking.
|
||||
*/
|
||||
class SOLID_EXPORT Notifier : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
Q_SIGNALS:
|
||||
/**
|
||||
* Signals that the network status has changed
|
||||
* @param status the new status of the network status service
|
||||
*/
|
||||
void statusChanged( Solid::Networking::Status status );
|
||||
/**
|
||||
* Signals that the system's network has become connected, so receivers
|
||||
* should connect their sockets, ioslaves etc.
|
||||
*
|
||||
* This signal is emitted according to the active connectPolicy.
|
||||
*/
|
||||
void shouldConnect();
|
||||
/**
|
||||
* Signals that the system's network has become disconnected,
|
||||
* so receivers should adjust application state appropriately.
|
||||
*
|
||||
* This signal is emitted according to the active disconnectPolicy.
|
||||
*/
|
||||
void shouldDisconnect();
|
||||
/**
|
||||
* Signals that the network status has changed
|
||||
* @param status the new status of the network status service
|
||||
*/
|
||||
void statusChanged(Solid::Networking::Status status);
|
||||
/**
|
||||
* Signals that the system's network has become connected, so receivers
|
||||
* should connect their sockets, ioslaves etc.
|
||||
*/
|
||||
void shouldConnect();
|
||||
/**
|
||||
* Signals that the system's network has become disconnected,
|
||||
* so receivers should adjust application state appropriately.
|
||||
*/
|
||||
void shouldDisconnect();
|
||||
|
||||
protected:
|
||||
Notifier();
|
||||
Notifier();
|
||||
};
|
||||
|
||||
SOLID_EXPORT Notifier *notifier();
|
||||
|
|
|
@ -30,35 +30,33 @@ class OrgKdeSolidNetworkingClientInterface;
|
|||
|
||||
namespace Solid
|
||||
{
|
||||
class ManagedSocketContainer;
|
||||
|
||||
class NetworkingPrivate : public Networking::Notifier
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY( uint Status READ status )
|
||||
Q_CLASSINFO( "D-Bus Interface", "org.kde.Solid.Networking.Client" )
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(uint Status READ status)
|
||||
Q_CLASSINFO("D-Bus Interface", "org.kde.Solid.Networking.Client")
|
||||
public:
|
||||
NetworkingPrivate();
|
||||
~NetworkingPrivate();
|
||||
|
||||
void shouldConnect() { Networking::Notifier::shouldConnect(); }
|
||||
void shouldDisconnect() { Networking::Notifier::shouldDisconnect(); }
|
||||
|
||||
Networking::Status netStatus;
|
||||
Networking::ManagementPolicy connectPolicy;
|
||||
Networking::ManagementPolicy disconnectPolicy;
|
||||
public Q_SLOTS:
|
||||
uint status() const;
|
||||
/**
|
||||
* Called on DBus signal from the network status service
|
||||
*/
|
||||
void serviceStatusChanged( uint status );
|
||||
void serviceStatusChanged(uint status);
|
||||
/**
|
||||
* Detects when kded restarts, and sets status to NoNetworks so that apps
|
||||
* may proceed
|
||||
*/
|
||||
void serviceOwnerChanged( const QString &, const QString &, const QString & );
|
||||
void serviceOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner);
|
||||
|
||||
private:
|
||||
void initialize();
|
||||
OrgKdeSolidNetworkingClientInterface * iface;
|
||||
OrgKdeSolidNetworkingClientInterface* iface;
|
||||
};
|
||||
} // namespace Solid
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue