51 |
51 |
52 #include <QDebug> |
52 #include <QDebug> |
53 |
53 |
54 #include <math.h> |
54 #include <math.h> |
55 |
55 |
56 static QMap<QString, QSvgRenderer *> svgCache; |
56 static QMap<QNetworkConfiguration::BearerType, QSvgRenderer *> svgCache; |
57 |
57 |
58 //! [0] |
58 //! [0] |
59 Cloud::Cloud(const QNetworkConfiguration &config, QGraphicsItem *parent) |
59 Cloud::Cloud(const QNetworkConfiguration &config, QGraphicsItem *parent) |
60 : QGraphicsItem(parent), configuration(config), deleteAfterAnimation(false) |
60 : QGraphicsItem(parent), configuration(config), deleteAfterAnimation(false) |
61 { |
61 { |
257 if (interface.isValid()) |
259 if (interface.isValid()) |
258 tooltip += tr("<br>Interface: %1").arg(interface.humanReadableName()); |
260 tooltip += tr("<br>Interface: %1").arg(interface.humanReadableName()); |
259 tooltip += tr("<br>Id: %1").arg(configuration.identifier()); |
261 tooltip += tr("<br>Id: %1").arg(configuration.identifier()); |
260 #endif |
262 #endif |
261 |
263 |
262 const QString bearerName = configuration.bearerName(); |
264 const QString bearerTypeName = configuration.bearerTypeName(); |
263 if (!bearerName.isEmpty()) |
265 if (!bearerTypeName.isEmpty()) |
264 tooltip += tr("<br>Bearer: %1").arg(bearerName); |
266 tooltip += tr("<br>Bearer: %1").arg(bearerTypeName); |
265 |
267 |
266 QString s = tr("<br>State: %1 (%2)"); |
268 QString s = tr("<br>State: %1 (%2)"); |
267 switch (state) { |
269 switch (state) { |
268 case QNetworkSession::Invalid: |
270 case QNetworkSession::Invalid: |
269 s = s.arg(tr("Invalid")); |
271 s = s.arg(tr("Invalid")); |
300 tooltip += tr("<br><br>Active time: %1 seconds").arg(session->activeTime()); |
302 tooltip += tr("<br><br>Active time: %1 seconds").arg(session->activeTime()); |
301 tooltip += tr("<br>Received data: %1 bytes").arg(session->bytesReceived()); |
303 tooltip += tr("<br>Received data: %1 bytes").arg(session->bytesReceived()); |
302 tooltip += tr("<br>Sent data: %1 bytes").arg(session->bytesWritten()); |
304 tooltip += tr("<br>Sent data: %1 bytes").arg(session->bytesWritten()); |
303 |
305 |
304 setToolTip(tooltip); |
306 setToolTip(tooltip); |
|
307 #else |
|
308 Q_UNUSED(state); |
|
309 #endif |
305 } |
310 } |
306 //! [2] |
311 //! [2] |
307 |
312 |
308 //! [1] |
313 //! [1] |
309 void Cloud::newConfigurationActivated() |
314 void Cloud::newConfigurationActivated() |
310 { |
315 { |
311 const QString bearerName = configuration.bearerName(); |
316 QNetworkConfiguration::BearerType bearerType = configuration.bearerType(); |
312 if (!svgCache.contains(bearerName)) { |
317 if (!svgCache.contains(bearerType)) { |
313 if (bearerName == QLatin1String("WLAN")) |
318 QSvgRenderer *renderer = 0; |
314 svgCache.insert(bearerName, new QSvgRenderer(QLatin1String(":wlan.svg"))); |
319 switch (bearerType) { |
315 else if (bearerName == QLatin1String("Ethernet")) |
320 case QNetworkConfiguration::BearerWLAN: |
316 svgCache.insert(bearerName, new QSvgRenderer(QLatin1String(":lan.svg"))); |
321 renderer = new QSvgRenderer(QLatin1String(":wlan.svg")); |
317 else |
322 break; |
318 svgCache.insert(bearerName, new QSvgRenderer(QLatin1String(":unknown.svg"))); |
323 case QNetworkConfiguration::BearerEthernet: |
319 } |
324 renderer = new QSvgRenderer(QLatin1String(":lan.svg")); |
320 |
325 break; |
321 icon->setSharedRenderer(svgCache[bearerName]); |
326 case QNetworkConfiguration::Bearer2G: |
|
327 renderer = new QSvgRenderer(QLatin1String(":cell.svg")); |
|
328 break; |
|
329 case QNetworkConfiguration::BearerBluetooth: |
|
330 renderer = new QSvgRenderer(QLatin1String(":bluetooth.svg")); |
|
331 break; |
|
332 case QNetworkConfiguration::BearerCDMA2000: |
|
333 case QNetworkConfiguration::BearerWCDMA: |
|
334 case QNetworkConfiguration::BearerHSPA: |
|
335 renderer = new QSvgRenderer(QLatin1String(":umts.svg")); |
|
336 break; |
|
337 default: |
|
338 renderer = new QSvgRenderer(QLatin1String(":unknown.svg")); |
|
339 } |
|
340 |
|
341 if (renderer) |
|
342 svgCache.insert(bearerType, renderer); |
|
343 } |
|
344 |
|
345 icon->setSharedRenderer(svgCache[bearerType]); |
322 |
346 |
323 if (configuration.name().isEmpty()) { |
347 if (configuration.name().isEmpty()) { |
324 text->setPlainText(tr("HIDDEN NETWORK")); |
348 text->setPlainText(tr("HIDDEN NETWORK")); |
325 } else { |
349 } else { |
326 if (configuration.type() == QNetworkConfiguration::ServiceNetwork) |
350 if (configuration.type() == QNetworkConfiguration::ServiceNetwork) |