solid: remove unused connect/disconnect policy API

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2023-06-16 17:45:56 +03:00
parent e4345f58ed
commit 2344fa495f
3 changed files with 66 additions and 136 deletions

View file

@ -31,22 +31,20 @@ Q_GLOBAL_STATIC(Solid::NetworkingPrivate, globalNetworkManager)
Solid::NetworkingPrivate::NetworkingPrivate() Solid::NetworkingPrivate::NetworkingPrivate()
: netStatus(Solid::Networking::Unknown), : netStatus(Solid::Networking::Unknown),
connectPolicy(Solid::Networking::Managed), iface(nullptr)
disconnectPolicy(Solid::Networking::Managed),
iface(0)
{ {
QDBusServiceWatcher *watcher = new QDBusServiceWatcher("org.kde.kded", QDBusConnection::sessionBus(), QDBusServiceWatcher *watcher = new QDBusServiceWatcher(
QDBusServiceWatcher::WatchForOwnerChange, this); "org.kde.kded", QDBusConnection::sessionBus(),
connect(watcher, SIGNAL(serviceOwnerChanged(QString,QString,QString)), QDBusServiceWatcher::WatchForOwnerChange, this
this, SLOT(serviceOwnerChanged(QString,QString,QString))); );
connect(
watcher, SIGNAL(serviceOwnerChanged(QString,QString,QString)),
this, SLOT(serviceOwnerChanged(QString,QString,QString))
);
initialize(); initialize();
} }
Solid::NetworkingPrivate::~NetworkingPrivate()
{
}
Solid::Networking::Notifier::Notifier() Solid::Networking::Notifier::Notifier()
{ {
} }
@ -54,17 +52,19 @@ Solid::Networking::Notifier::Notifier()
void Solid::NetworkingPrivate::initialize() void Solid::NetworkingPrivate::initialize()
{ {
delete iface; delete iface;
iface = new OrgKdeSolidNetworkingClientInterface( "org.kde.kded", iface = new OrgKdeSolidNetworkingClientInterface(
"/modules/networkstatus", "org.kde.kded",
QDBusConnection::sessionBus(), "/modules/networkstatus",
this); 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))); connect(iface, SIGNAL(statusChanged(uint)), this, SLOT(serviceStatusChanged(uint)));
QDBusReply<uint> reply = iface->status(); QDBusReply<uint> reply = iface->status();
if (reply.isValid()) { if (reply.isValid()) {
netStatus = ( Solid::Networking::Status )reply.value(); netStatus = static_cast<Solid::Networking::Status>(reply.value());
} else { } else {
netStatus = Solid::Networking::Unknown; netStatus = Solid::Networking::Unknown;
} }
@ -79,7 +79,7 @@ uint Solid::NetworkingPrivate::status() const
Solid::Networking::Status Solid::Networking::status() 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() Solid::Networking::Notifier *Solid::Networking::notifier()
@ -87,73 +87,42 @@ Solid::Networking::Notifier *Solid::Networking::notifier()
return globalNetworkManager(); return globalNetworkManager();
} }
void Solid::NetworkingPrivate::serviceStatusChanged( uint status ) void Solid::NetworkingPrivate::serviceStatusChanged(uint status)
{ {
// kDebug( 921 ) ; // kDebug(921) ;
netStatus = ( Solid::Networking::Status )status; netStatus = static_cast<Solid::Networking::Status>(status);
switch ( netStatus ) { switch (netStatus) {
case Solid::Networking::Unknown: case Solid::Networking::Unknown:
break; break;
case Solid::Networking::Unconnected: case Solid::Networking::Unconnected:
case Solid::Networking::Disconnecting: case Solid::Networking::Disconnecting:
case Solid::Networking::Connecting: case Solid::Networking::Connecting:
if ( disconnectPolicy == Solid::Networking::Managed ) { emit globalNetworkManager()->shouldDisconnect();
emit globalNetworkManager()->shouldDisconnect(); break;
} else if ( disconnectPolicy == Solid::Networking::OnNextStatusChange ) { case Solid::Networking::Connected:
setDisconnectPolicy( Solid::Networking::Manual ); emit globalNetworkManager()->shouldConnect();
emit globalNetworkManager()->shouldDisconnect(); break;
} // default:
break; // kDebug(921) << "Unrecognised status code!";
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!";
} }
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(name)
Q_UNUSED(oldOwner) Q_UNUSED(oldOwner)
if ( newOwner.isEmpty() ) { if (newOwner.isEmpty()) {
// kded quit on us // kded quit on us
netStatus = Solid::Networking::Unknown; netStatus = Solid::Networking::Unknown;
emit globalNetworkManager()->statusChanged( netStatus ); emit globalNetworkManager()->statusChanged(netStatus);
} else { } else {
// kded was replaced or started // kded was replaced or started
initialize(); initialize();
emit globalNetworkManager()->statusChanged( netStatus ); emit globalNetworkManager()->statusChanged(netStatus);
serviceStatusChanged( 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_p.cpp"
#include "moc_networking.cpp" #include "moc_networking.cpp"

View file

@ -50,15 +50,6 @@ namespace Solid
Connected /**< the system is currently connected to a network */ 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 * Get the current networking status
* If the result is Unknown, the backend may be unconfigured or otherwise in a state where * 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(); 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 * This object emits signals, for use if your application requires notification
* of changes to networking. * of changes to networking.
*/ */
class SOLID_EXPORT Notifier : public QObject class SOLID_EXPORT Notifier : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_SIGNALS: Q_SIGNALS:
/** /**
* Signals that the network status has changed * Signals that the network status has changed
* @param status the new status of the network status service * @param status the new status of the network status service
*/ */
void statusChanged( Solid::Networking::Status status ); void statusChanged(Solid::Networking::Status status);
/** /**
* Signals that the system's network has become connected, so receivers * Signals that the system's network has become connected, so receivers
* should connect their sockets, ioslaves etc. * should connect their sockets, ioslaves etc.
* */
* This signal is emitted according to the active connectPolicy. void shouldConnect();
*/ /**
void shouldConnect(); * Signals that the system's network has become disconnected,
/** * so receivers should adjust application state appropriately.
* Signals that the system's network has become disconnected, */
* so receivers should adjust application state appropriately. void shouldDisconnect();
*
* This signal is emitted according to the active disconnectPolicy.
*/
void shouldDisconnect();
protected: protected:
Notifier(); Notifier();
}; };
SOLID_EXPORT Notifier *notifier(); SOLID_EXPORT Notifier *notifier();

View file

@ -30,35 +30,33 @@ class OrgKdeSolidNetworkingClientInterface;
namespace Solid namespace Solid
{ {
class ManagedSocketContainer;
class NetworkingPrivate : public Networking::Notifier class NetworkingPrivate : public Networking::Notifier
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY( uint Status READ status ) Q_PROPERTY(uint Status READ status)
Q_CLASSINFO( "D-Bus Interface", "org.kde.Solid.Networking.Client" ) Q_CLASSINFO("D-Bus Interface", "org.kde.Solid.Networking.Client")
public: public:
NetworkingPrivate(); NetworkingPrivate();
~NetworkingPrivate();
void shouldConnect() { Networking::Notifier::shouldConnect(); } void shouldConnect() { Networking::Notifier::shouldConnect(); }
void shouldDisconnect() { Networking::Notifier::shouldDisconnect(); } void shouldDisconnect() { Networking::Notifier::shouldDisconnect(); }
Networking::Status netStatus; Networking::Status netStatus;
Networking::ManagementPolicy connectPolicy;
Networking::ManagementPolicy disconnectPolicy;
public Q_SLOTS: public Q_SLOTS:
uint status() const; uint status() const;
/** /**
* Called on DBus signal from the network status service * 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 * Detects when kded restarts, and sets status to NoNetworks so that apps
* may proceed * may proceed
*/ */
void serviceOwnerChanged( const QString &, const QString &, const QString & ); void serviceOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner);
private: private:
void initialize(); void initialize();
OrgKdeSolidNetworkingClientInterface * iface; OrgKdeSolidNetworkingClientInterface* iface;
}; };
} // namespace Solid } // namespace Solid
#endif #endif