2
Copyright 2008,2009 Will Stephenson <wstephenson@kde.org>
3
Copyright 2008-2010 Sebastian Kügler <sebas@kde.org>
5
This program is free software; you can redistribute it and/or
6
modify it under the terms of the GNU General Public License as
7
published by the Free Software Foundation; either version 2 of
8
the License or (at your option) version 3 or any later version
9
accepted by the membership of KDE e.V. (or its successor approved
10
by the membership of KDE e.V.), which shall act as a proxy
11
defined in Section 14 of version 3 of the license.
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
GNU General Public License for more details.
18
You should have received a copy of the GNU General Public License
19
along with this program. If not, see <http://www.gnu.org/licenses/>.
26
#include <QGraphicsLinearLayout>
27
#include <QGraphicsGridLayout>
29
#include <QDBusConnection>
35
#include <KIconLoader>
36
#include <KToolInvocation>
39
#include <Plasma/Label>
40
#include <Plasma/Separator>
43
#include <solid/control/networkmanager.h>
44
#include <solid/control/wirelessnetworkinterface.h>
45
#include <solid/control/wirednetworkinterface.h>
48
#include "activatableitem.h"
49
#include "remoteactivatable.h"
50
#include "remoteactivatablelist.h"
51
#include "remotewirelessinterfaceconnection.h"
54
#include "interfaceitem.h"
55
#include "wirelessinterfaceitem.h"
56
#include "vpninterfaceitem.h"
57
#include "activatablelistwidget.h"
58
#include "interfacedetailswidget.h"
62
NMPopup::NMPopup(RemoteActivatableList * activatableList, QGraphicsWidget* parent)
63
: QGraphicsWidget(parent),
64
m_activatables(activatableList),
65
m_hasWirelessInterface(false),
83
m_mainLayout = new QGraphicsGridLayout(this);
85
m_leftLabel = new Plasma::Label(this);
86
m_leftLabel->setMaximumHeight(24);
87
m_leftLabel->setMinimumHeight(24);
88
m_leftLabel->setText(i18nc("title on the LHS of the plasmoid", "<h3>Interfaces</h3>"));
89
m_mainLayout->addItem(m_leftLabel, 0, 0);
91
m_rightLabel = new Plasma::Label(this);
92
m_rightLabel->setMaximumHeight(24);
93
m_rightLabel->setMinimumHeight(24);
94
m_rightLabel->setText(i18nc("title on the RHS of the plasmoid", "<h3>Connections</h3>"));
95
m_mainLayout->addItem(m_rightLabel, 0, 2);
97
Plasma::Separator* sep = new Plasma::Separator(this);
98
sep->setOrientation(Qt::Vertical);
99
m_mainLayout->addItem(sep, 0, 1, 2, 1, Qt::AlignRight);
100
m_mainLayout->setRowFixedHeight(0, 24);
102
m_leftWidget = new Plasma::TabBar(this);
103
m_leftWidget->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
104
m_leftLayout = new QGraphicsLinearLayout;
105
m_leftLayout->setOrientation(Qt::Vertical);
107
m_interfaceLayout = new QGraphicsLinearLayout;
108
m_interfaceLayout->setOrientation(Qt::Vertical);
109
m_interfaceLayout->setSpacing(0);
111
m_leftLayout->addItem(m_interfaceLayout);
112
m_leftLayout->addStretch(5);
114
Plasma::Separator* sep2 = new Plasma::Separator(this);
115
sep->setOrientation(Qt::Vertical);
116
m_leftLayout->addItem(sep2);
118
QGraphicsWidget* checkboxWidget = new QGraphicsWidget(this);
119
QGraphicsGridLayout* checkboxLayout = new QGraphicsGridLayout(checkboxWidget);
120
// flight-mode checkbox
121
m_networkingCheckBox = new Plasma::CheckBox(m_leftWidget);
122
m_networkingCheckBox->setText(i18nc("CheckBox to enable or disable networking completely", "Enable networking"));
123
checkboxLayout->addItem(m_networkingCheckBox, 0, 0);
124
connect(m_networkingCheckBox, SIGNAL(toggled(bool)),
125
this, SLOT(networkingEnabledToggled(bool)));
126
connect(Solid::Control::NetworkManagerNm09::notifier(), SIGNAL(networkingEnabledChanged(bool)),
127
this, SLOT(managerNetworkingEnabledChanged(bool)));
129
// flight-mode checkbox
130
m_wwanCheckBox = new Plasma::CheckBox(m_leftWidget);
131
m_wwanCheckBox->setText(i18nc("CheckBox to enable or disable wwan (mobile broadband) interface)", "Enable mobile broadband"));
132
m_wwanCheckBox->hide();
133
m_wwanCheckBox->nativeWidget()->setTristate(true);
134
checkboxLayout->addItem(m_wwanCheckBox, 0, 1);
136
connect(m_wwanCheckBox, SIGNAL(toggled(bool)), SLOT(wwanEnabledToggled(bool)));
137
connect(Solid::Control::NetworkManagerNm09::notifier(), SIGNAL(wwanEnabledChanged(bool)),
138
this, SLOT(managerWwanEnabledChanged(bool)));
139
connect(Solid::Control::NetworkManagerNm09::notifier(), SIGNAL(wwanHardwareEnabledChanged(bool)),
140
this, SLOT(managerWwanHardwareEnabledChanged(bool)));
142
// flight-mode checkbox
143
m_wifiCheckBox = new Plasma::CheckBox(m_leftWidget);
144
m_wifiCheckBox->setText(i18nc("CheckBox to enable or disable wireless interface (rfkill)", "Enable wireless"));
145
m_wifiCheckBox->hide();
146
checkboxLayout->addItem(m_wifiCheckBox, 1, 0);
148
connect(m_wifiCheckBox, SIGNAL(toggled(bool)), SLOT(wirelessEnabledToggled(bool)));
149
connect(Solid::Control::NetworkManagerNm09::notifier(), SIGNAL(wirelessEnabledChanged(bool)),
150
this, SLOT(managerWirelessEnabledChanged(bool)));
151
connect(Solid::Control::NetworkManagerNm09::notifier(), SIGNAL(wirelessHardwareEnabledChanged(bool)),
152
this, SLOT(managerWirelessHardwareEnabledChanged(bool)));
154
m_leftLayout->addItem(checkboxWidget);
156
m_leftWidget->addTab(i18nc("tabbar on the left side", "Interfaces"), m_leftLayout);
157
m_leftWidget->setTabBarShown(false); // TODO: enable
159
m_interfaceDetailsWidget = new InterfaceDetailsWidget(m_leftWidget);
160
m_interfaceDetailsWidget->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
161
connect(m_interfaceDetailsWidget, SIGNAL(back()), this, SLOT(toggleInterfaceTab()));
163
// Hack to prevent graphical artifacts during tab transition.
164
connect(m_leftWidget, SIGNAL(currentChanged(int)), SLOT(refresh()));
166
m_leftWidget->addTab(i18nc("details for the interface", "Details"), m_interfaceDetailsWidget);
168
m_mainLayout->addItem(m_leftWidget, 1, 0);
170
m_rightWidget = new QGraphicsWidget(this);
171
m_rightWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
172
m_rightLayout = new QGraphicsLinearLayout(m_rightWidget);
173
m_rightLayout->setOrientation(Qt::Vertical);
175
// List with activatables
176
m_connectionList = new ActivatableListWidget(m_activatables, m_rightWidget);
177
m_connectionList->addType(Knm::Activatable::InterfaceConnection);
178
m_connectionList->addType(Knm::Activatable::WirelessInterfaceConnection);
179
m_connectionList->addType(Knm::Activatable::VpnInterfaceConnection);
180
m_connectionList->addType(Knm::Activatable::GsmInterfaceConnection);
181
m_connectionList->init();
183
m_connectionList->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
184
m_connectionList->setPreferredHeight(240);
185
m_connectionList->setShowAllTypes(true, true);
186
connect(m_connectionList, SIGNAL(showInterfaceDetails(QString)), SLOT(showInterfaceDetails(QString)));
188
m_rightLayout->addItem(m_connectionList);
190
m_connectionsButton = new Plasma::PushButton(m_rightWidget);
191
m_connectionsButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
192
m_connectionsButton->setIcon(KIcon("configure"));
193
m_connectionsButton->setText(i18nc("manage connections button in the applet's popup", "Manage Connections..."));
194
m_connectionsButton->setMinimumHeight(28);
195
m_connectionsButton->setMaximumHeight(28);
196
connect(m_connectionsButton, SIGNAL(clicked()), this, SLOT(manageConnections()));
198
m_showMoreButton = new Plasma::PushButton(m_rightWidget);
199
m_showMoreButton->setToolTip(i18nc("@info:tooltip tooltip for the 'Show More' button", "Show all available networks"));
200
// Do not use this according to KDE HIG. Bug #272492
201
//m_showMoreButton->setCheckable(true);
202
m_showMoreButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
203
m_showMoreButton->setIcon(KIcon("list-add"));
204
m_showMoreButton->setText(i18nc("show more button in the applet's popup", "Show More..."));
205
m_showMoreButton->setMinimumHeight(28);
206
m_showMoreButton->setMaximumHeight(28);
207
QSizeF sMore = m_showMoreButton->size();
208
m_showMoreButton->setText(i18nc("show more button in the applet's popup", "Show Less..."));
209
QSizeF sLess = m_showMoreButton->size();
210
QSizeF sMax = sMore.width() > sLess.width() ? sMore : sLess;
211
m_showMoreButton->setMinimumSize(sMax);
212
m_showMoreButton->setMaximumSize(sMax);
213
connect(m_showMoreButton, SIGNAL(clicked()), this, SLOT(showMore()));
214
connect(m_activatables, SIGNAL(activatableAdded(RemoteActivatable *, int)), this, SLOT(uncheckShowMore(RemoteActivatable *)));
215
connect(m_activatables, SIGNAL(activatableRemoved(RemoteActivatable *)), this, SLOT(checkShowMore(RemoteActivatable *)));
217
QGraphicsLinearLayout* connectionLayout = new QGraphicsLinearLayout;
218
connectionLayout->addItem(m_showMoreButton);
219
connectionLayout->addItem(m_connectionsButton);
221
m_rightLayout->addItem(connectionLayout);
223
m_mainLayout->addItem(m_rightWidget, 1, 2);
224
m_mainLayout->setColumnFixedWidth(2, m_showMoreButton->size().rwidth() + m_connectionsButton->size().rwidth());
226
//createTab(Knm::Activatable::WirelessInterfaceConnection);
227
kDebug() << "Adding interfaces initially";
228
foreach (Solid::Control::NetworkInterfaceNm09 * iface, Solid::Control::NetworkManagerNm09::networkInterfaces()) {
229
addInterfaceInternal(iface);
230
kDebug() << "Network Interface:" << iface->interfaceName() << iface->driver() << iface->designSpeed();
233
// hook up signals to allow us to change the connection list depending on APs present, etc
234
connect(Solid::Control::NetworkManagerNm09::notifier(), SIGNAL(networkInterfaceAdded(const QString&)),
235
SLOT(interfaceAdded(const QString&)));
236
connect(Solid::Control::NetworkManagerNm09::notifier(), SIGNAL(networkInterfaceRemoved(const QString&)),
237
SLOT(interfaceRemoved(const QString&)));
239
m_showMoreChecked = false;
240
m_oldShowMoreChecked = true;
241
wicCount = 0; // number of wireless networks which user explicitly configured using the kcm module.
243
KNetworkManagerServicePrefs::instance(Knm::NETWORKMANAGEMENT_RCFILE);
244
KConfigGroup config(KNetworkManagerServicePrefs::self()->config(), QLatin1String("General"));
245
m_oldShowMoreChecked = config.readEntry(QLatin1String("ShowAllConnections"), true);
246
showMore(m_oldShowMoreChecked);
250
QDBusConnection dbus = QDBusConnection::sessionBus();
251
dbus.connect("org.kde.Solid.PowerManagement", "/org/kde/Solid/PowerManagement", "org.kde.Solid.PowerManagement", "resumingFromSuspend", this, SLOT(readConfig()));
252
dbus.connect("org.kde.kded", "/org/kde/networkmanagement", "org.kde.networkmanagement", "ReloadConfig", this, SLOT(readConfig()));
257
static int compareVersions(const QString & version1, const QString & version2)
259
QStringList sl1 = version1.split('.');
260
QStringList sl2 = version2.split('.');
262
if (sl1.size() > 2 && sl2.size() > 2) {
263
int v1[3] = { sl1[0].toInt(), sl1[1].toInt(), sl1[2].toInt() };
264
int v2[3] = { sl2[0].toInt(), sl2[1].toInt(), sl2[2].toInt() };
268
} else if (v1[0] < v2[0]) {
270
} else if (v1[1] > v2[1]) {
272
} else if (v1[1] < v2[1]) {
274
} else if (v1[2] > v2[2]) {
276
} else if (v1[2] < v2[2]) {
285
void NMPopup::readConfig()
288
KNetworkManagerServicePrefs::self()->readConfig();
290
m_networkingCheckBox->setChecked(Solid::Control::NetworkManagerNm09::isNetworkingEnabled());
291
m_wifiCheckBox->setChecked(Solid::Control::NetworkManagerNm09::isWirelessEnabled());
293
/* There is a bug in Solid < 4.6.2 where it does not emit the wirelessHardwareEnabledChanged signal.
294
* So we always enable the wireless checkbox for versions below 4.6.2. */
295
#if KDE_IS_VERSION(4,6,2)
296
m_wifiCheckBox->setEnabled(Solid::Control::NetworkManagerNm09::isWirelessHardwareEnabled());
298
m_wifiCheckBox->setEnabled(true);
301
m_showMoreButton->setEnabled(Solid::Control::NetworkManagerNm09::isNetworkingEnabled() &&
302
Solid::Control::NetworkManagerNm09::isWirelessEnabled());
304
m_wwanCheckBox->nativeWidget()->setCheckState(Solid::Control::NetworkManagerNm09::isWwanEnabled() ? Qt::Checked : Qt::Unchecked);
305
m_wwanCheckBox->setEnabled(Solid::Control::NetworkManagerNm09::isWwanHardwareEnabled());
307
foreach(InterfaceItem * i, m_interfaces) {
308
i->setNameDisplayMode(InterfaceItem::InterfaceName);
311
QString version = Solid::Control::NetworkManagerNm09::version();
312
if (version.isEmpty()) {
313
Plasma::Label * warning = new Plasma::Label(this);
314
warning->setText(i18nc("Warning about wrong NetworkManager version", "NetworkManager is not running. Please start it."));
315
m_interfaceLayout->addItem(warning);
316
} else if (compareVersions(version, QString(MINIMUM_NM_VERSION_REQUIRED)) < 0) {
317
Plasma::Label * warning = new Plasma::Label(this);
318
warning->setText(i18nc("Warning about wrong NetworkManager version", "We need at least NetworkManager-%1 to work properly, found '%2'. Please upgrade to a newer version.", QString(MINIMUM_NM_VERSION_REQUIRED), version));
319
m_interfaceLayout->addItem(warning);
324
void NMPopup::interfaceAdded(const QString& uni)
326
if (m_interfaces.contains(uni)) {
329
Solid::Control::NetworkInterfaceNm09 * iface = Solid::Control::NetworkManagerNm09::findNetworkInterface(uni);
331
kDebug() << "Interface Added:" << iface->interfaceName() << iface->driver() << iface->designSpeed();
332
addInterfaceInternal(iface);
336
void NMPopup::interfaceRemoved(const QString& uni)
338
if (m_interfaces.contains(uni)) {
339
// To prevent crashes when the interface removed is the one in interfaceDetailsWidget.
340
// the m_iface pointer in interfaceDetailsWidget become invalid in this case.
341
if (uni == m_interfaceDetailsWidget->getLastIfaceUni()) {
342
m_interfaceDetailsWidget->setInterface(0, false);
343
// Since it is invalid go back to "main" window.
344
m_leftWidget->setCurrentIndex(0);
347
InterfaceItem* item = m_interfaces.take(uni);
348
connect(item, SIGNAL(disappearAnimationFinished()), this, SLOT(deleteInterfaceItem()));
355
void NMPopup::deleteInterfaceItem()
357
// slot is called from animation's finished()
358
InterfaceItem* item = dynamic_cast<InterfaceItem*>(sender());
359
m_interfaceLayout->removeItem(item);
363
Solid::Control::NetworkInterfaceNm09* NMPopup::defaultInterface()
365
// In fact we're returning the first available interface,
366
// and if there is none available just the first one we have
367
// and if we don't have one, 0. Make sure you check though.
368
if (Solid::Control::NetworkManagerNm09::networkInterfaces().isEmpty()) {
371
Solid::Control::NetworkInterfaceNm09* iface = Solid::Control::NetworkManagerNm09::networkInterfaces().first();
372
foreach (Solid::Control::NetworkInterfaceNm09 * _iface, Solid::Control::NetworkManagerNm09::networkInterfaces()) {
373
switch (_iface->connectionState()) {
374
case Solid::Control::NetworkInterfaceNm09::Disconnected:
375
case Solid::Control::NetworkInterfaceNm09::Preparing:
376
case Solid::Control::NetworkInterfaceNm09::Configuring:
377
case Solid::Control::NetworkInterfaceNm09::NeedAuth:
378
case Solid::Control::NetworkInterfaceNm09::IPConfig:
379
case Solid::Control::NetworkInterfaceNm09::IPCheck:
380
case Solid::Control::NetworkInterfaceNm09::Secondaries:
381
case Solid::Control::NetworkInterfaceNm09::Activated:
382
case Solid::Control::NetworkInterfaceNm09::Deactivating:
383
case Solid::Control::NetworkInterfaceNm09::Failed:
386
case Solid::Control::NetworkInterfaceNm09::Unavailable:
387
case Solid::Control::NetworkInterfaceNm09::Unmanaged:
388
case Solid::Control::NetworkInterfaceNm09::UnknownState:
396
void NMPopup::addInterfaceInternal(Solid::Control::NetworkInterfaceNm09* iface)
399
// the interface might be gone in the meantime...
402
if (!m_interfaces.contains(iface->uni())) {
403
InterfaceItem * ifaceItem = 0;
404
if (iface->type() == Solid::Control::NetworkInterfaceNm09::Wifi) {
405
// Create the wireless interface item
406
WirelessInterfaceItem* wifiItem = 0;
407
wifiItem = new WirelessInterfaceItem(static_cast<Solid::Control::WirelessNetworkInterfaceNm09 *>(iface), m_activatables, InterfaceItem::InterfaceName, this);
408
ifaceItem = wifiItem;
409
//connect(wirelessinterface, SIGNAL(stateChanged()), this, SLOT(updateNetworks()));
410
wifiItem->setEnabled(Solid::Control::NetworkManagerNm09::isWirelessEnabled());
411
kDebug() << "WiFi added";
412
connect(wifiItem, SIGNAL(disconnectInterfaceRequested(const QString&)), m_connectionList, SLOT(deactivateConnection(const QString&)));
414
// Create the interfaceitem
415
ifaceItem = new InterfaceItem(static_cast<Solid::Control::WiredNetworkInterfaceNm09 *>(iface), m_activatables, InterfaceItem::InterfaceName, this);
416
connect(ifaceItem, SIGNAL(disconnectInterfaceRequested(const QString&)), m_connectionList, SLOT(deactivateConnection(const QString&)));
418
connect(ifaceItem, SIGNAL(clicked()), this, SLOT(toggleInterfaceTab()));
419
connect(ifaceItem, SIGNAL(clicked(Solid::Control::NetworkInterfaceNm09*)),
420
m_connectionList, SLOT(addInterface(Solid::Control::NetworkInterfaceNm09*)));
421
connect(ifaceItem, SIGNAL(hoverEnter(const QString&)), m_connectionList, SLOT(hoverEnter(const QString&)));
422
connect(ifaceItem, SIGNAL(hoverLeave(const QString&)), m_connectionList, SLOT(hoverLeave(const QString&)));
424
// Catch connection changes
425
connect(iface, SIGNAL(connectionStateChanged(int,int,int)), this, SLOT(handleConnectionStateChange(int,int,int)));
426
m_interfaceLayout->addItem(ifaceItem);
427
m_interfaces.insert(iface->uni(), ifaceItem);
433
void NMPopup::showInterfaceDetails(const QString & uni)
435
InterfaceItem * ifaceItem = m_interfaces.value(uni, 0);
438
ifaceItem = m_vpnItem;
443
QMetaObject::invokeMethod(ifaceItem, "clicked", Qt::QueuedConnection);
446
void NMPopup::addVpnInterface()
448
m_vpnItem = new VpnInterfaceItem(0, m_activatables, InterfaceItem::InterfaceName, this);
449
connect(m_vpnItem, SIGNAL(clicked()), this, SLOT(toggleInterfaceTab()));
450
connect(m_vpnItem, SIGNAL(clicked(Solid::Control::NetworkInterfaceNm09*)),
451
m_connectionList, SLOT(addInterface(Solid::Control::NetworkInterfaceNm09*)));
452
connect(m_vpnItem, SIGNAL(hoverEnter()), m_connectionList, SLOT(vpnHoverEnter()));
453
connect(m_vpnItem, SIGNAL(hoverLeave()), m_connectionList, SLOT(vpnHoverLeave()));
455
connect(m_vpnItem, SIGNAL(clicked()), m_connectionList, SLOT(toggleVpn()));
457
m_leftLayout->insertItem(2, m_vpnItem);
460
void NMPopup::handleConnectionStateChange(int new_state, int old_state, int reason)
463
// Switch to default tab if an interface has become available, or unavailable
464
if (available(new_state) != available(old_state)) {
465
m_connectionList->clearInterfaces();
469
bool NMPopup::hasWireless() {
470
return m_hasWirelessInterface;
473
bool NMPopup::available(int state)
475
// Can an interface be used?
477
case Solid::Control::NetworkInterfaceNm09::Disconnected:
478
case Solid::Control::NetworkInterfaceNm09::Preparing:
479
case Solid::Control::NetworkInterfaceNm09::Configuring:
480
case Solid::Control::NetworkInterfaceNm09::NeedAuth:
481
case Solid::Control::NetworkInterfaceNm09::IPConfig:
482
case Solid::Control::NetworkInterfaceNm09::IPCheck:
483
case Solid::Control::NetworkInterfaceNm09::Secondaries:
484
case Solid::Control::NetworkInterfaceNm09::Activated:
485
case Solid::Control::NetworkInterfaceNm09::Deactivating:
486
case Solid::Control::NetworkInterfaceNm09::Failed:
489
case Solid::Control::NetworkInterfaceNm09::Unavailable:
490
case Solid::Control::NetworkInterfaceNm09::Unmanaged:
491
case Solid::Control::NetworkInterfaceNm09::UnknownState:
499
void NMPopup::wirelessEnabledToggled(bool checked)
501
kDebug() << "Applet wireless enable switch toggled" << checked;
502
if (Solid::Control::NetworkManagerNm09::isWirelessEnabled() != checked) {
503
Solid::Control::NetworkManagerNm09::setWirelessEnabled(checked);
505
updateHasWireless(checked);
508
void NMPopup::wwanEnabledToggled(bool checked)
510
kDebug() << "Applet wwan enable switch toggled" << checked;
511
if (Solid::Control::NetworkManagerNm09::isWwanEnabled() != checked) {
512
Solid::Control::NetworkManagerNm09::setWwanEnabled(checked);
516
void NMPopup::networkingEnabledToggled(bool checked)
518
// Switch networking on / off
519
if (Solid::Control::NetworkManagerNm09::isNetworkingEnabled() != checked) {
520
Solid::Control::NetworkManagerNm09::setNetworkingEnabled(checked);
522
// Update wireless checkbox
523
m_wifiCheckBox->setChecked(Solid::Control::NetworkManagerNm09::isWirelessEnabled());
525
kDebug() << "Wireless hardware enabled ==" << Solid::Control::NetworkManagerNm09::isWirelessHardwareEnabled();
527
#if KDE_IS_VERSION(4,6,2)
528
m_wifiCheckBox->setEnabled(Solid::Control::NetworkManagerNm09::isWirelessHardwareEnabled() || Solid::Control::NetworkManagerNm09::isWirelessEnabled());
531
m_wwanCheckBox->nativeWidget()->setCheckState(Solid::Control::NetworkManagerNm09::isWwanEnabled() ? Qt::Checked : Qt::Unchecked);
532
m_wwanCheckBox->setEnabled(Solid::Control::NetworkManagerNm09::isWwanHardwareEnabled() || Solid::Control::NetworkManagerNm09::isWwanEnabled());
534
updateHasWireless(checked);
537
void NMPopup::updateHasWireless(bool checked)
539
//kDebug() << "UPDATE!!!!!!!!!!!!";
540
bool hasWireless = true;
541
if (!Solid::Control::NetworkManagerNm09::isWirelessHardwareEnabled() ||
542
!Solid::Control::NetworkManagerNm09::isNetworkingEnabled() ||
543
!Solid::Control::NetworkManagerNm09::isWirelessEnabled() || !checked) {
545
//kDebug () << "networking enabled?" << Solid::Control::NetworkManagerNm09::isNetworkingEnabled();
546
//kDebug () << "wireless hardware enabled?" << Solid::Control::NetworkManagerNm09::isWirelessHardwareEnabled();
547
//kDebug () << "wireless enabled?" << Solid::Control::NetworkManagerNm09::isWirelessEnabled();
549
// either networking is disabled, or wireless is disabled
552
//solid is too slow, we need to see if the checkbox was checked by the user
555
kDebug() << "After chckboxn" << hasWireless;
557
foreach (InterfaceItem* ifaceitem, m_interfaces) {
558
Solid::Control::NetworkInterfaceNm09* iface = ifaceitem->interface();
559
if (iface && iface->type() == Solid::Control::NetworkInterfaceNm09::Wifi) {
560
//kDebug() << "there's a wifi iface" << ifaceitem->connectionName() << iface->interfaceName();
561
m_hasWirelessInterface = true; // at least one interface is wireless. We're happy.
562
m_wifiCheckBox->show();
566
if (!m_hasWirelessInterface) {
567
kDebug() << "no ifaces";
569
m_wifiCheckBox->hide();
571
m_connectionList->setHasWireless(hasWireless);
574
void NMPopup::updateHasWwan()
576
bool hasWwan = false;
577
foreach (InterfaceItem* ifaceitem, m_interfaces) {
578
Solid::Control::ModemNetworkInterfaceNm09* iface = qobject_cast<Solid::Control::ModemNetworkInterfaceNm09 *>(ifaceitem->interface());
585
m_wwanCheckBox->show();
586
hasWwan = m_wwanCheckBox->isChecked();
588
m_wwanCheckBox->hide();
592
void NMPopup::managerWirelessEnabledChanged(bool enabled)
594
kDebug() << "NM daemon changed wireless enable state" << enabled;
595
// it might have changed because we toggled the switch,
596
// but it might have been changed externally, so set it anyway
597
m_wifiCheckBox->setChecked(enabled);
599
m_wifiCheckBox->setEnabled(enabled);
602
m_showMoreButton->setEnabled(enabled && Solid::Control::NetworkManagerNm09::isNetworkingEnabled());
605
void NMPopup::managerWirelessHardwareEnabledChanged(bool enabled)
607
kDebug() << "Hardware wireless enable switch state changed" << enabled;
608
m_wifiCheckBox->setEnabled(enabled);
609
updateHasWireless(enabled);
610
m_showMoreButton->setEnabled(enabled && Solid::Control::NetworkManagerNm09::isNetworkingEnabled());
613
void NMPopup::managerNetworkingEnabledChanged(bool enabled)
615
kDebug() << "NM daemon changed networking enable state" << enabled;
616
m_networkingCheckBox->setChecked(enabled);
617
m_showMoreButton->setEnabled(enabled);
620
void NMPopup::managerWwanEnabledChanged(bool enabled)
622
kDebug() << "NM daemon changed wwan enable state" << enabled;
623
m_wwanCheckBox->nativeWidget()->setCheckState(enabled ? Qt::Checked : Qt::Unchecked);
625
m_wwanCheckBox->setEnabled(enabled);
629
void NMPopup::managerWwanHardwareEnabledChanged(bool enabled)
631
kDebug() << "Hardware wwan enable switch state changed" << enabled;
632
m_wwanCheckBox->setEnabled(enabled);
635
void NMPopup::showMore()
637
// Simulate button toggling.
638
m_showMoreChecked = !m_showMoreChecked;
639
m_oldShowMoreChecked = m_showMoreChecked;
640
showMore(m_oldShowMoreChecked);
642
KConfigGroup config(KNetworkManagerServicePrefs::self()->config(), QLatin1String("General"));
643
config.writeEntry(QLatin1String("ShowAllConnections"), m_oldShowMoreChecked);
647
void NMPopup::showMore(bool more)
649
if (!Solid::Control::NetworkManagerNm09::isWirelessEnabled()) {
654
m_showMoreButton->setText(i18nc("pressed show more button", "Show Less..."));
655
m_showMoreButton->setIcon(KIcon("list-remove"));
656
m_showMoreChecked = true;
657
m_connectionList->setShowAllTypes(true, true); // also refresh list
659
m_showMoreButton->setText(i18nc("unpressed show more button", "Show More..."));
660
m_showMoreChecked = false;
661
m_connectionList->setShowAllTypes(false, true); // also refresh list
662
m_showMoreButton->setIcon(KIcon("list-add"));
664
kDebug() << m_showMoreButton->text();
667
void NMPopup::checkShowMore(RemoteActivatable * ra)
669
RemoteWirelessInterfaceConnection * wic = qobject_cast<RemoteWirelessInterfaceConnection*>(ra);
671
if (wic->operationMode() == Solid::Control::WirelessNetworkInterfaceNm09::Adhoc &&
672
wic->activationState() == Knm::InterfaceConnection::Unknown) {
678
if (wicCount == 0 && !m_showMoreChecked) {
679
// There is no wireless network around which the user has explicitly configured
680
// so temporaly show all wifi available networks.
686
void NMPopup::uncheckShowMore(RemoteActivatable *ra)
688
RemoteWirelessInterfaceConnection * wic = qobject_cast<RemoteWirelessInterfaceConnection*>(ra);
690
if (wic->operationMode() == Solid::Control::WirelessNetworkInterfaceNm09::Adhoc &&
691
wic->activationState() == Knm::InterfaceConnection::Unknown) {
695
if (m_oldShowMoreChecked != m_showMoreChecked) {
696
// One wireless network explicitly configured by the user appeared, reset "Show More" button
697
// state to the value before the checkShowMore method above took action.
698
showMore(m_oldShowMoreChecked);
703
void NMPopup::manageConnections()
705
//kDebug() << "opening connection management dialog";
707
args << "--icon" << "networkmanager" << "kcm_networkmanagement" << "kcm_networkmanagement_tray";
708
KToolInvocation::kdeinitExec("kcmshell4", args);
711
void NMPopup::toggleInterfaceTab()
713
InterfaceItem* item = qobject_cast<InterfaceItem*>(sender());
715
m_interfaceDetailsWidget->setInterface(item->interface());
718
if (m_leftWidget->currentIndex() == 0) {
719
// Enable / disable updating of the details widget
720
m_interfaceDetailsWidget->setUpdateEnabled(true);
723
if (item->interface()) {
724
// Temporaly disables hightlight for all connections of this interface.
725
QMetaObject::invokeMethod(item, "hoverLeave", Qt::QueuedConnection,
726
Q_ARG(QString, item->interface()->uni()));
728
m_leftLabel->setText(QString("<h3>%1</h3>").arg(
729
UiUtils::interfaceNameLabel(item->interface()->uni())));
731
// Temporaly disables hightlight for all VPN connections.
732
QMetaObject::invokeMethod(item, "hoverLeave", Qt::QueuedConnection);
737
// Hack to prevent graphical artifact during tab transition.
738
// m_interfaceDetailsWidget will be shown again when transition finishes.
739
m_interfaceDetailsWidget->hide();
740
m_leftWidget->setCurrentIndex(1);
742
m_leftLabel->setText(i18nc("title on the LHS of the plasmoid", "<h3>Interfaces</h3>"));
743
m_connectionList->clearInterfaces();
744
showMore(m_oldShowMoreChecked);
745
m_interfaceDetailsWidget->setUpdateEnabled(false);
746
m_leftWidget->setCurrentIndex(0);
750
void NMPopup::refresh()
752
m_interfaceDetailsWidget->show();
754
// vim: sw=4 sts=4 et tw=100