mirror of
https://bitbucket.org/smil3y/kde-workspace.git
synced 2025-02-23 18:32:50 +00:00
solid-networkstatus: notify about status changes via desktop notification
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
c46a5297cc
commit
809b90a113
4 changed files with 95 additions and 4 deletions
|
@ -30,9 +30,10 @@ qt4_add_dbus_adaptor(kded_networkstatus_PART_SRCS
|
|||
|
||||
kde4_add_plugin(kded_networkstatus ${kded_networkstatus_PART_SRCS})
|
||||
|
||||
target_link_libraries(kded_networkstatus ${KDE4_KDECORE_LIBS})
|
||||
target_link_libraries(kded_networkstatus ${KDE4_KDECORE_LIBS} ${KDE4_KDEUI_LIBS})
|
||||
|
||||
install(TARGETS kded_networkstatus DESTINATION ${KDE4_PLUGIN_INSTALL_DIR})
|
||||
|
||||
install( FILES networkstatus.desktop DESTINATION ${KDE4_SERVICES_INSTALL_DIR}/kded)
|
||||
install(FILES networkstatus.desktop DESTINATION ${KDE4_SERVICES_INSTALL_DIR}/kded)
|
||||
|
||||
install(FILES networkstatus.notifyrc DESTINATION ${KDE4_DATA_INSTALL_DIR}/networkstatus)
|
||||
|
|
|
@ -29,6 +29,8 @@
|
|||
#include <QtCore/qtimer.h>
|
||||
|
||||
#include <KDebug>
|
||||
#include <KNotification>
|
||||
#include <KLocale>
|
||||
|
||||
#include "network.h"
|
||||
#include "clientadaptor.h"
|
||||
|
@ -57,8 +59,8 @@ typedef QMap< QString, Network * > NetworkMap;
|
|||
class NetworkStatusModule::Private
|
||||
{
|
||||
public:
|
||||
Private() : status( Solid::Networking::Unknown ), backend( 0 ), serviceWatcher( 0 ),
|
||||
backendAppearedWatcher( 0 ), backendDisappearedWatcher ( 0 )
|
||||
Private() : firstnotification(true), status( Solid::Networking::Unknown ), backend( 0 ),
|
||||
serviceWatcher( 0 ), backendAppearedWatcher( 0 ), backendDisappearedWatcher ( 0 )
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -66,6 +68,7 @@ public:
|
|||
{
|
||||
|
||||
}
|
||||
bool firstnotification;
|
||||
NetworkMap networks;
|
||||
Solid::Networking::Status status;
|
||||
SystemStatusInterface *backend;
|
||||
|
@ -120,6 +123,7 @@ void NetworkStatusModule::updateStatus()
|
|||
QTimer::singleShot(2000, this, SLOT(delayedStatusChanged()));
|
||||
} else {
|
||||
Q_EMIT statusChanged( (uint)d->status );
|
||||
notifyStatus( (uint)d->status );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -127,6 +131,56 @@ void NetworkStatusModule::updateStatus()
|
|||
void NetworkStatusModule::delayedStatusChanged()
|
||||
{
|
||||
Q_EMIT statusChanged( (uint)d->status );
|
||||
notifyStatus( (uint)d->status );
|
||||
}
|
||||
|
||||
void NetworkStatusModule::notifyStatus( uint status)
|
||||
{
|
||||
if (d->firstnotification) {
|
||||
// backends may change their state from unknown to a known state on first run which makes
|
||||
// sense for the module initialization but not for the user when the desktop just started
|
||||
d->firstnotification = false;
|
||||
return;
|
||||
}
|
||||
KNotification *notify = Q_NULLPTR;
|
||||
switch ((Solid::Networking::Status)status) {
|
||||
case Solid::Networking::Unknown: {
|
||||
notify = new KNotification("Unknown");
|
||||
notify->setComponentData(KComponentData("networkstatus"));
|
||||
notify->setTitle(i18n("Network status changed"));
|
||||
notify->setText(i18n("Network status is unknown"));
|
||||
break;
|
||||
}
|
||||
case Solid::Networking::Unconnected: {
|
||||
notify = new KNotification("Unconnected");
|
||||
notify->setComponentData(KComponentData("networkstatus"));
|
||||
notify->setTitle(i18n("Network status changed"));
|
||||
notify->setText(i18n("Network status is offline"));
|
||||
break;
|
||||
}
|
||||
case Solid::Networking::Disconnecting: {
|
||||
notify = new KNotification("Disconnecting");
|
||||
notify->setComponentData(KComponentData("networkstatus"));
|
||||
notify->setTitle(i18n("Network status changed"));
|
||||
notify->setText(i18n("Network status is about to be offline"));
|
||||
break;
|
||||
}
|
||||
case Solid::Networking::Connecting: {
|
||||
notify = new KNotification("Connecting");
|
||||
notify->setComponentData(KComponentData("networkstatus"));
|
||||
notify->setTitle(i18n("Network status changed"));
|
||||
notify->setText(i18n("Network status is connecting"));
|
||||
break;
|
||||
}
|
||||
case Solid::Networking::Connected: {
|
||||
notify = new KNotification("Connected");
|
||||
notify->setComponentData(KComponentData("networkstatus"));
|
||||
notify->setTitle(i18n("Network status changed"));
|
||||
notify->setText(i18n("Network status is connected"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
notify->sendEvent();
|
||||
}
|
||||
|
||||
void NetworkStatusModule::serviceUnregistered( const QString & name )
|
||||
|
|
|
@ -62,6 +62,8 @@ protected:
|
|||
void init();
|
||||
// recalculate cached status
|
||||
void updateStatus();
|
||||
// send notification on status change
|
||||
void notifyStatus( uint status );
|
||||
|
||||
private:
|
||||
QList<SystemStatusInterface*> backends;
|
||||
|
|
34
solid-networkstatus/kded/networkstatus.notifyrc
Normal file
34
solid-networkstatus/kded/networkstatus.notifyrc
Normal file
|
@ -0,0 +1,34 @@
|
|||
[Global]
|
||||
Name=networkstatus
|
||||
Comment=Network status notification
|
||||
IconName=network-workgroup
|
||||
|
||||
[Event/Unknown]
|
||||
Name=Network status is unknown
|
||||
Action=Sound|Popup
|
||||
Sound=KDE-Im-Cant-Connect.ogg
|
||||
IconName=dialog-warning
|
||||
|
||||
[Event/Unconnected]
|
||||
Name=Network status is offline
|
||||
Action=Sound|Popup
|
||||
Sound=KDE-Im-Contact-Out.ogg
|
||||
IconName=network-disconnect
|
||||
|
||||
[Event/Disconnecting]
|
||||
Name=Network status is about to be offline
|
||||
Action=Sound|Popup
|
||||
Sound=KDE-Im-Contact-Out.ogg
|
||||
IconName=network-disconnect
|
||||
|
||||
[Event/Connecting]
|
||||
Name=Network status is connecting
|
||||
Action=Sound|Popup
|
||||
Sound=KDE-Im-Contact-In.ogg
|
||||
IconName=network-connect
|
||||
|
||||
[Event/Connected]
|
||||
Name=Network status is connected
|
||||
Action=Sound|Popup
|
||||
Sound=KDE-Im-Contact-In.ogg
|
||||
IconName=network-connect
|
Loading…
Add table
Reference in a new issue