[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    =?utf-8?q?=5Bnetworkmanagement=5D_libs=3A_Use_the_correct_icon_f?=
From:       "Lamarque V.Souza" <lamarque () gmail ! com>
Date:       2011-03-01 1:14:31
Message-ID: 20110301011431.4CC63A60CD () git ! kde ! org
[Download RAW message or body]

Git commit 0b0d7309abfccc5dd8efdd2c68ab2c9f3a66cda0 by Lamarque V. Souza.
Committed on 01/03/2011 at 02:12.
Pushed by lvsouza into branch 'master'.

Use the correct icon for the network interface when notifying.

M  +28   -24   libs/internals/connection.cpp     
M  +1    -0    libs/internals/connection.h     
M  +34   -15   libs/service/notificationmanager.cpp     
M  +1    -1    libs/service/notificationmanager.h     

http://commits.kde.org/networkmanagement/0b0d7309abfccc5dd8efdd2c68ab2c9f3a66cda0

diff --git a/libs/internals/connection.cpp b/libs/internals/connection.cpp
index 970c086..2914b39 100644
--- a/libs/internals/connection.cpp
+++ b/libs/internals/connection.cpp
@@ -149,36 +149,40 @@ QString Connection::name() const
     return m_name;
 }
 
-QString Connection::iconName() const
+QString Connection::iconName(const Connection::Type type)
 {
     QString iconName;
-    if (m_iconName.isEmpty()) {
-        switch (m_type) {
-            case Connection::Wired:
-                iconName = QLatin1String("network-wired");
-                break;
-            case Connection::Wireless:
-                iconName = QLatin1String("network-wireless");
-                break;
-            case Connection::Pppoe:
-                iconName = QLatin1String("modem");
-                break;
-            case Connection::Gsm:
-            case Connection::Cdma:
-                iconName = QLatin1String("phone");
-                break;
-            case Connection::Vpn:
-                iconName = QLatin1String("network-server");
-
-            default:
-                break;
-        }
-    } else {
-        iconName = m_iconName;
+    switch (type) {
+        case Connection::Wired:
+            iconName = QLatin1String("network-wired");
+            break;
+        case Connection::Wireless:
+            iconName = QLatin1String("network-wireless");
+            break;
+        case Connection::Pppoe:
+            iconName = QLatin1String("modem");
+            break;
+        case Connection::Gsm:
+        case Connection::Cdma:
+            iconName = QLatin1String("phone");
+            break;
+        case Connection::Vpn:
+            iconName = QLatin1String("network-server");
+
+        default:
+            break;
     }
     return iconName;
 }
 
+QString Connection::iconName() const
+{
+    if (m_iconName.isEmpty()) {
+        return iconName(m_type);
+    }
+    return m_iconName;
+}
+
 QUuid Connection::uuid() const
 {
     return m_uuid;
diff --git a/libs/internals/connection.h b/libs/internals/connection.h
index 0ad7173..752ae78 100644
--- a/libs/internals/connection.h
+++ b/libs/internals/connection.h
@@ -40,6 +40,7 @@ public:
     enum Type { Wired = 1, Wireless, Gsm, Cdma, Vpn, Pppoe };
     static QString typeAsString(Connection::Type);
     static Connection::Type typeFromString(const QString & type);
+    static QString iconName(const Connection::Type type);
 
     /**
      * Create a connection with a new Uuid
diff --git a/libs/service/notificationmanager.cpp \
b/libs/service/notificationmanager.cpp index 2c2556b..a1f6c85 100644
--- a/libs/service/notificationmanager.cpp
+++ b/libs/service/notificationmanager.cpp
@@ -39,6 +39,10 @@ License along with this library.  If not, see \
<http://www.gnu.org/licenses/>.  #include <wirelessnetworkinterfaceenvironment.h>
 
 #include "events.h"
+#include "../internals/connection.h"
+
+static int iconSize = 48;
+Knm::Connection::Type solidToKnmType(const Solid::Control::NetworkInterface::Type \
sType);  
 K_GLOBAL_STATIC_WITH_ARGS(KComponentData, s_networkManagementComponentData, \
("networkmanagement", "networkmanagement", \
KComponentData::SkipMainComponentRegistration))  
@@ -99,18 +103,18 @@ void \
InterfaceNotificationHost::interfaceConnectionActivationStateChanged(Knm::I  case \
Knm::InterfaceConnection::Activating:   kDebug() << ic->connectionName() << "is \
activating";  m_activating.insert(ic);
-            KNotification::event(Event::Connecting, m_interfaceNameLabel, \
i18nc("@info:status Notification text when connecting","Activating %1", \
ic->connectionName()), QPixmap(), 0, KNotification::CloseOnTimeout, \
m_manager->componentData()); +            KNotification::event(Event::Connecting, \
m_interfaceNameLabel, i18nc("@info:status Notification text when \
connecting","Activating %1", ic->connectionName()), \
KIcon(Knm::Connection::iconName(ic->connectionType())).pixmap(QSize(iconSize,iconSize)), \
0, KNotification::CloseOnTimeout, m_manager->componentData());  break;
         case Knm::InterfaceConnection::Activated:
             m_activating.remove(ic);
-            KNotification::event(Event::Connected, m_interfaceNameLabel, \
i18nc("@info:status Notification text when a connection has been activated","%1 \
activated", ic->connectionName()), QPixmap(), 0, KNotification::CloseOnTimeout, \
m_manager->componentData()); +            KNotification::event(Event::Connected, \
m_interfaceNameLabel, i18nc("@info:status Notification text when a connection has \
been activated","%1 activated", ic->connectionName()), \
KIcon(Knm::Connection::iconName(ic->connectionType())).pixmap(QSize(iconSize,iconSize)), \
0, KNotification::CloseOnTimeout, m_manager->componentData());  break;
         case Knm::InterfaceConnection::Unknown:
             m_activating.remove(ic);
             if (ic->oldActivationState() == Knm::InterfaceConnection::Activating)
-                KNotification::event(Event::ConnectFailed, m_interfaceNameLabel, \
i18nc("@info:status Notification text when connection has failed","Connection %1 \
failed", ic->connectionName()), QPixmap(), 0, KNotification::CloseOnTimeout, \
m_manager->componentData()); +                \
KNotification::event(Event::ConnectFailed, m_interfaceNameLabel, i18nc("@info:status \
Notification text when connection has failed","Connection %1 failed", \
ic->connectionName()), \
KIcon(Knm::Connection::iconName(ic->connectionType())).pixmap(QSize(iconSize,iconSize)), \
0, KNotification::CloseOnTimeout, m_manager->componentData());  else
-                KNotification::event(Event::Disconnected, m_interfaceNameLabel, \
i18nc("@info:status Notification text when deactivating a connection","%1 \
deactivated", ic->connectionName()), QPixmap(), 0, KNotification::CloseOnTimeout, \
m_manager->componentData()); +                \
KNotification::event(Event::Disconnected, m_interfaceNameLabel, i18nc("@info:status \
Notification text when deactivating a connection","%1 deactivated", \
ic->connectionName()), \
KIcon(Knm::Connection::iconName(ic->connectionType())).pixmap(QSize(iconSize,iconSize)), \
0, KNotification::CloseOnTimeout, m_manager->componentData());  break;
     }
 }
@@ -119,7 +123,7 @@ void InterfaceNotificationHost::strengthChanged(int strength)
 {
     if (strength < 30) {
         Knm::InterfaceConnection * ic = qobject_cast<Knm::InterfaceConnection \
                *>(sender());
-        KNotification::event(Event::LowSignal, m_interfaceNameLabel, \
i18nc("@info:status Notification text when wireless/gsm signal is low","Low signal on \
%1", ic->connectionName()), QPixmap(), 0, KNotification::CloseOnTimeout, \
m_manager->componentData()); +        KNotification::event(Event::LowSignal, \
m_interfaceNameLabel, i18nc("@info:status Notification text when wireless/gsm signal \
is low","Low signal on %1", ic->connectionName()), \
KIcon(Knm::Connection::iconName(ic->connectionType())).pixmap(QSize(iconSize,iconSize)), \
0, KNotification::CloseOnTimeout, m_manager->componentData());  }
 }
 
@@ -309,10 +313,10 @@ void \
InterfaceNotificationHost::interfaceConnectionStateChanged(int new_state, i  text = \
i18nc("@info:status Notification when an interface changes state (%1) due to \
CarrierReason","%1 because the cable was disconnected", stateString);  break;
     }
-    performInterfaceNotification(title, text, flag);
+    performInterfaceNotification(title, text, \
KIcon(Knm::Connection::iconName(solidToKnmType(m_interface->type()))).pixmap(QSize(iconSize,iconSize)), \
flag);  }
 
-void InterfaceNotificationHost::performInterfaceNotification(const QString & title, \
const QString & text, KNotification::NotificationFlag flag) +void \
InterfaceNotificationHost::performInterfaceNotification(const QString & title, const \
QString & text, const QPixmap & pixmap, KNotification::NotificationFlag flag)  {
     kDebug() << title << text << flag;
     KNotification * notification = 0;
@@ -337,10 +341,24 @@ void \
InterfaceNotificationHost::performInterfaceNotification(const QString & tit  \
notification->setTitle(title);  
     notification->setText(text);
+    notification->setPixmap(pixmap);
 
     notification->sendEvent();
 }
 
+Knm::Connection::Type solidToKnmType(const Solid::Control::NetworkInterface::Type \
sType) +{
+    Knm::Connection::Type type;
+    switch (sType) {
+        case Solid::Control::NetworkInterface::Ieee80211: type = \
Knm::Connection::Wireless; break; +        case \
Solid::Control::NetworkInterface::Gsm: type = Knm::Connection::Gsm; break; +        \
case Solid::Control::NetworkInterface::Cdma: type = Knm::Connection::Cdma; break; +   \
case Solid::Control::NetworkInterface::Serial: type = Knm::Connection::Pppoe; break; \
+        default: type = Knm::Connection::Wired; +    }
+    return type;
+}
+
 class NotificationManagerPrivate
 {
 public:
@@ -435,7 +453,7 @@ void NotificationManager::networkInterfaceAdded(const QString & \
uni)  
             // notify hardware added
             if (!d->suppressHardwareEvents) {
-                KNotification::event(Event::HwAdded, i18nc("@info:status \
Notification for hardware added", "%1 attached", host->label()), QPixmap(), 0, \
KNotification::CloseOnTimeout, componentData()); +                \
KNotification::event(Event::HwAdded, i18nc("@info:status Notification for hardware \
added", "%1 attached", host->label()), \
KIcon(Knm::Connection::iconName(solidToKnmType(iface->type()))).pixmap(QSize(iconSize,iconSize)), \
0, KNotification::CloseOnTimeout, componentData());  }
 
             // if wireless, listen for new networks
@@ -476,7 +494,8 @@ void NotificationManager::networkInterfaceRemoved(const QString \
                &uni)
             notificationText = i18nc("@info:status Notification for hardware removed \
used if we don't have its user-visible name", "Network interface removed");  }
 
-        KNotification::event(Event::HwRemoved, notificationText, QPixmap(), 0, \
KNotification::CloseOnTimeout, componentData()); +        \
Solid::Control::NetworkInterface * iface = \
Solid::Control::NetworkManager::findNetworkInterface(uni); +        \
KNotification::event(Event::HwRemoved, notificationText, \
KIcon(Knm::Connection::iconName(solidToKnmType(iface->type()))).pixmap(QSize(iconSize,iconSize)), \
0, KNotification::CloseOnTimeout, componentData());  }
 }
 
@@ -498,13 +517,13 @@ void NotificationManager::notifyNewNetworks()
 {
     Q_D(NotificationManager);    
     if (d->newWirelessNetworks.count() == 1) {
-        KNotification::event(Event::NetworkAppeared, i18nc("@info:status \
Notification text when a single wireless network was found","Wireless network %1 \
found", d->newWirelessNetworks[0]), QPixmap(), 0, KNotification::CloseOnTimeout, \
KComponentData("knetworkmanager", "knetworkmanager", \
KComponentData::SkipMainComponentRegistration)); +        \
KNotification::event(Event::NetworkAppeared, i18nc("@info:status Notification text \
when a single wireless network was found","Wireless network %1 found", \
d->newWirelessNetworks[0]), \
KIcon("network-wireless").pixmap(QSize(iconSize,iconSize)), 0, \
KNotification::CloseOnTimeout, KComponentData("knetworkmanager", "knetworkmanager", \
KComponentData::SkipMainComponentRegistration));  } else {
         KNotification::event(Event::NetworkAppeared, i18ncp("@info:status \
Notification text when multiple wireless networks are found. %2 is a list of \
networks, and the %1 value (not printed) is just used to determine the plural form of \
network.",  "<b>New wireless network:</b><br /> %2",
 							    "<b>New wireless networks:</b><br /> %2",
 							    d->newWirelessNetworks.count(), // the %1 parameter, used only to choose \
                between plural forms on the word network
-							    d->newWirelessNetworks.join(", ")), \
KIcon("network-wireless").pixmap(QSize(48,48)), 0, KNotification::CloseOnTimeout, \
componentData()); +							    d->newWirelessNetworks.join(", ")), \
KIcon("network-wireless").pixmap(QSize(iconSize,iconSize)), 0, \
KNotification::CloseOnTimeout, componentData());  }
     d->newNetworkTimer->stop();
     d->newWirelessNetworks.clear();
@@ -514,14 +533,14 @@ void NotificationManager::notifyDisappearedNetworks()
 {
     Q_D(NotificationManager);
     if (d->disappearedWirelessNetworks.count() == 1) {
-        KNotification::event(Event::NetworkDisappeared, i18nc("@info:status \
Notification text when a single wireless network disappeared","Wireless network %1 \
disappeared", d->disappearedWirelessNetworks[0]), QPixmap(), 0, \
KNotification::CloseOnTimeout, KComponentData("knetworkmanager", "knetworkmanager", \
KComponentData::SkipMainComponentRegistration)); +        \
KNotification::event(Event::NetworkDisappeared, i18nc("@info:status Notification text \
when a single wireless network disappeared","Wireless network %1 disappeared", \
d->disappearedWirelessNetworks[0]), \
KIcon("network-wireless").pixmap(QSize(iconSize,iconSize)), 0, \
KNotification::CloseOnTimeout, KComponentData("knetworkmanager", "knetworkmanager", \
KComponentData::SkipMainComponentRegistration));  
     } else {
         KNotification::event(Event::NetworkDisappeared, i18ncp("@info:status \
Notification text when multiple wireless networks have disappeared.  %2 is a list of \
networks, and the %1 value (not printed) is just used to determine the plural form of \
network.",  "<b>Wireless network disappeared:</b><br /> %2",
 							       "<b>Wireless networks disappeared:</b><br /> %2",
 							       d->disappearedWirelessNetworks.count(), // the %1 parameter, used only \
                to choose between plural forms on the word network
-							       d->disappearedWirelessNetworks.join(", ")), \
KIcon("network-wireless").pixmap(QSize(48,48)), 0, KNotification::CloseOnTimeout, \
componentData()); +							       d->disappearedWirelessNetworks.join(", ")), \
KIcon("network-wireless").pixmap(QSize(iconSize,iconSize)), 0, \
KNotification::CloseOnTimeout, componentData());  }
     d->disappearedNetworkTimer->stop();
     d->disappearedWirelessNetworks.clear();
@@ -530,9 +549,9 @@ void NotificationManager::notifyDisappearedNetworks()
 void NotificationManager::wirelessHardwareEnabledChanged(bool enabled)
 {
     if (enabled) {
-        KNotification::event(Event::RfOn, i18nc("@info:status Notification for radio \
kill switch turned on", "Wireless hardware enabled"), QPixmap(), 0, \
KNotification::CloseOnTimeout, componentData()); +        \
KNotification::event(Event::RfOn, i18nc("@info:status Notification for radio kill \
switch turned on", "Wireless hardware enabled"), \
KIcon("network-wireless").pixmap(QSize(iconSize,iconSize)), 0, \
KNotification::CloseOnTimeout, componentData());  } else {
-        KNotification::event(Event::RfOff, i18nc("@info:status Notification for \
radio kill switch turned on", "Wireless hardware disabled"), QPixmap(), 0, \
KNotification::CloseOnTimeout, componentData()); +        \
KNotification::event(Event::RfOff, i18nc("@info:status Notification for radio kill \
switch turned on", "Wireless hardware disabled"), \
KIcon("network-wireless").pixmap(QSize(iconSize,iconSize)), 0, \
KNotification::CloseOnTimeout, componentData());  }
 }
 
diff --git a/libs/service/notificationmanager.h b/libs/service/notificationmanager.h
index cec1013..9b43902 100644
--- a/libs/service/notificationmanager.h
+++ b/libs/service/notificationmanager.h
@@ -97,7 +97,7 @@ public Q_SLOTS:
 
     void strengthChanged(int strength);
 private:
-    void performInterfaceNotification(const QString & title, const QString & text, \
KNotification::NotificationFlag flag); +    void performInterfaceNotification(const \
QString & title, const QString & text, const QPixmap & pixmap, \
KNotification::NotificationFlag flag);  
     NotificationManager * m_manager;
     Solid::Control::NetworkInterface * m_interface;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic