1
/***************************************************************************
3
* knetworkmanager-notify.cpp - A NetworkManager frontend for KDE
5
* Copyright (C) 2005, 2006 Novell, Inc.
7
* Author: Timo Hoenig <thoenig@suse.de>, <thoenig@nouse.net>
8
* Helmut Schaa <hschaa@suse.de>, <helmut.schaa@gmx.de>
10
* This program is free software; you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published by
12
* the Free Software Foundation; either version 2 of the License, or
13
* (at your option) any later version.
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU General Public License for more details.
20
* You should have received a copy of the GNU General Public License
21
* along with this program; if not, write to the Free Software
22
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
**************************************************************************/
26
#include <qpushbutton.h>
27
#include <kprogress.h>
30
#include <kpushbutton.h>
31
#include <kglobalsettings.h>
32
#include <qpointarray.h>
35
#include <kiconloader.h>
38
#include "knetworkmanager-notify.h"
39
#include "activation.h"
44
/* ActivationStageNotifyVPN */
47
ActivationStageNotifyVPN::updateActivationStage ()
49
State* state = _ctx->getState ();
52
/* close dialog if NetworkManager is not running*/
53
if (state->isNetworkManagerRunning () == false)
56
/* if we have an unclosed error let it unchanged */
57
if (_errorWidget != NULL)
60
switch (progress = _vpnConnection->getActivationStage ()) {
61
case NM_VPN_ACT_STAGE_PREPARE:
63
stage = i18n("Preparing...");
66
case NM_VPN_ACT_STAGE_CONNECT:
68
stage = i18n("Connection in progress...");
71
case NM_VPN_ACT_STAGE_IP_CONFIG_GET:
73
stage = i18n("Getting IP configuration...");
76
case NM_VPN_ACT_STAGE_ACTIVATED:
78
stage = i18n("Successfully connected.");
81
case NM_VPN_ACT_STAGE_DISCONNECTED:
82
case NM_VPN_ACT_STAGE_FAILED:
83
stage = i18n("Failed.");
86
case NM_VPN_ACT_STAGE_CANCELED:
93
if (progress == NM_VPN_ACT_STAGE_FAILED || progress == NM_VPN_ACT_STAGE_DISCONNECTED)
96
connectionFailure(temp, temp);
100
_activationWidget->pbarActivationStage->setProgress (progress);
101
_activationWidget->lblActivationStage->setText (i18n("Activation stage: %1.").arg(stage));
103
this->resize(minimumSizeHint());
105
if (progress < NM_VPN_ACT_STAGE_ACTIVATED)
108
if (progress == NM_VPN_ACT_STAGE_ACTIVATED) {
110
QTimer* timer = new QTimer(this);
111
connect(timer, SIGNAL(timeout()), this, SLOT(done()));
112
timer->start(1000, true);
125
ActivationStageNotifyVPN::connectionFailure(QString& member, QString& err_msg)
129
QString details = err_msg;
131
if (member == NM_DBUS_VPN_SIGNAL_LOGIN_FAILED) {
132
title = i18n("VPN Login Failure");
133
desc = i18n("Could not start the VPN connection '%1' due to a login failure.").arg(_vpnConnection->getName());
135
else if (member == NM_DBUS_VPN_SIGNAL_LAUNCH_FAILED) {
136
title = i18n("VPN Start Failure");
137
desc = i18n("Could not start the VPN connection '%1' due to a failure launching the VPN program.").arg(_vpnConnection->getName());
139
else if (member == NM_DBUS_VPN_SIGNAL_CONNECT_FAILED) {
140
title = i18n("VPN Connect Failure");
141
desc = i18n("Could not start the VPN connection '%1' due to a connection error.").arg(_vpnConnection->getName());
143
else if (member == NM_DBUS_VPN_SIGNAL_VPN_CONFIG_BAD) {
144
title = i18n("VPN Configuration Error");
145
desc = i18n("The VPN connection '%1' was not correctly configured.").arg(_vpnConnection->getName());
147
else if (member == NM_DBUS_VPN_SIGNAL_IP_CONFIG_BAD) {
148
title = i18n("VPN Connect Failure");
149
desc = i18n("Could not start the VPN connection '%1' because the VPN server did not return an adequate network configuration.").arg(_vpnConnection->getName());
152
title = i18n("VPN Failure");
153
desc = i18n("Could not start the VPN connection %1.").arg(_vpnConnection->getName());
156
showError(title, desc + "\n" + err_msg);
159
ActivationStageNotifyVPN::ActivationStageNotifyVPN (QWidget* parent, const char* name, bool /*modal*/, WFlags fl, KNetworkManager* ctx, VPNConnection* vpnConnection)
160
: ActivationStageNotify (parent, name, fl, ctx)
167
_vpnConnection = vpnConnection;
169
QWidget* mainWid = this;
170
_activationWidget = new ActivationWidget (mainWid, "activationwidget");
171
_activationWidget->lblActivationCaption->setText (i18n ("Activating VPN Connection"));
172
_activationWidget->lblPixmap->setPixmap(SmallIcon("encrypted", QIconSet::Automatic));
173
_activationWidget->lblActivation->setText (_vpnConnection->getName ());
174
_activationWidget->pbarActivationStage->setTotalSteps (5);
175
_activationWidget->lblActivationStage->setText (QString::null);
177
connect (parent, SIGNAL (destroyActivationStage ()),
178
this, SLOT (destroyActivationStage ()));
180
connect (vpnConnection, SIGNAL (activationStateChanged ()),
181
this, SLOT (updateActivationStage ()));
183
connect (vpnConnection, SIGNAL (connectionFailure(QString&, QString&)), this, SLOT(connectionFailure(QString&, QString&)));
184
this->resize(minimumSizeHint());
187
ActivationStageNotifyVPN::~ActivationStageNotifyVPN ()
193
/* ActivationStageNotifyNetwork */
196
ActivationStageNotifyNetwork::updateActivationStage ()
198
State* state = _ctx->getState ();
202
/* close dialog if NetworkManager is not running*/
203
if (state->isNetworkManagerRunning () == false)
206
switch (progress = _dev->getActivationStage ()) {
207
case NM_ACT_STAGE_DEVICE_PREPARE:
209
stage = i18n("Preparing device");
212
case NM_ACT_STAGE_DEVICE_CONFIG:
214
stage = i18n("Configuring device");
217
case NM_ACT_STAGE_NEED_USER_KEY:
219
stage = i18n("Waiting for passphrase from user");
222
case NM_ACT_STAGE_IP_CONFIG_START:
224
stage = i18n("IP configuration started");
227
case NM_ACT_STAGE_IP_CONFIG_GET:
229
stage = i18n("IP configuration requested");
232
case NM_ACT_STAGE_IP_CONFIG_COMMIT:
234
stage = i18n("Commit IP configuration");
237
case NM_ACT_STAGE_ACTIVATED:
239
stage = i18n("Device activated");
242
case NM_ACT_STAGE_FAILED:
244
stage = i18n("Device activation failed");
247
case NM_ACT_STAGE_CANCELLED:
249
stage = i18n("Device activation canceled");
252
case NM_ACT_STAGE_UNKNOWN:
255
stage = i18n("Unknown");
259
_activationWidget->pbarActivationStage->setProgress (progress);
260
_activationWidget->lblActivationStage->setText (i18n("Activation stage: %1.").arg(stage));
262
if (progress == NM_ACT_STAGE_NEED_USER_KEY)
265
if (progress < NM_ACT_STAGE_ACTIVATED)
268
if (progress == NM_ACT_STAGE_ACTIVATED)
270
// close us in 1 second
271
QTimer* timer = new QTimer(this);
272
connect(timer, SIGNAL(timeout()), this, SLOT(close()));
273
timer->start(1000, true);
277
if (progress == NM_ACT_STAGE_FAILED)
283
if (progress == (int) NM_ACT_STAGE_CANCELLED) {
285
// printf ("notify::NM_ACT_STAGE_CANCELLED\n");
297
ActivationStageNotifyNetwork::connectionFailure(const QString& /*member*/, const QString& /*err_msg*/)
302
title = i18n("Connection Failure");
305
if ( _dev->isWired() ) {
306
desc = i18n("Could not connect to the network using device %1").arg(_dev->getInterface());
308
desc = i18n("Could not connect to the network %1").arg(_essid);
312
showError(title, desc);
315
ActivationStageNotifyNetwork::ActivationStageNotifyNetwork (const QString & essid, QWidget* parent, const char* name, bool /*modal*/, WFlags fl, KNetworkManager* ctx, Device* dev )
316
: ActivationStageNotify (parent, name, fl, ctx), _essid( essid )
322
QWidget* mainWid = this;
323
_activationWidget = new ActivationWidget (mainWid, "activationwidget");
326
if ( _dev->isWired() ) {
327
_activationWidget->lblActivationCaption->setText (i18n ("Activating Network Connection"));
328
_activationWidget->lblPixmap->setPixmap(SmallIcon("wired", QIconSet::Automatic));
329
if ((info = _dev->getVendor () + " " + _dev->getProduct ()) == " ")
330
info = _dev->getInterface ();
332
_activationWidget->lblActivationCaption->setText (i18n ("Activating Wireless Network Connection"));
333
_activationWidget->lblPixmap->setPixmap(SmallIcon("wireless", QIconSet::Automatic));
335
info += " (" + _dev->getInterface () + ")";
339
_activationWidget->lblActivation->setText (info);
340
_activationWidget->pbarActivationStage->setTotalSteps (7);
341
_activationWidget->lblActivationStage->setText (QString::null);
343
connect (parent, SIGNAL (destroyActivationStage ()),
344
this, SLOT (destroyActivationStage ()));
346
connect (_ctx->getDeviceStore (), SIGNAL (deviceStoreChanged (DeviceStore*)),
347
this, SLOT (updateActivationStage ()));
349
resize(minimumSizeHint());
352
ActivationStageNotifyNetwork::~ActivationStageNotifyNetwork ()
360
ActivationStageNotify::destroyActivationStage ()
365
ActivationStageNotify::ActivationStageNotify (QWidget* parent, const char* name/*, bool modal,*/, WFlags /*fl*/ , KNetworkManager* ctx)
366
: QWidget (NULL, name, WStyle_StaysOnTop | WStyle_Customize | WStyle_NoBorder | WStyle_Tool | WX11BypassWM | Qt::WDestructiveClose)
370
// we do not want the parent as our parent-widget but we want this deleted at last when our parent is deleted
372
parent->insertChild(this);
374
setName ("ActivationStageNotify");
376
setCaption (i18n("Activation"));
378
QHBoxLayout* layout = new QHBoxLayout( this, 20 );
379
layout->setAutoAdd(true);
380
clearWState (WState_Polished);
381
setPalette(QToolTip::palette());
384
resize(minimumSizeHint());
387
ActivationStageNotify::~ActivationStageNotify ()
392
void ActivationStageNotify::showError(const QString& title, const QString& details)
394
// hide the activation widget
395
if (_activationWidget)
396
_activationWidget->hide();
398
// we need an errorwidget to show the error message
399
if (_errorWidget == NULL)
400
_errorWidget = new ErrorMessageWidget(this);
402
_errorWidget->setCaption(title);
403
_errorWidget->labelTitle->setText(title);
404
_errorWidget->labelMessage->setText(details);
405
_errorWidget->labelPixmap->setPixmap(KGlobal::instance()->iconLoader()->loadIcon("messagebox_critical", KIcon::Small, 32));
406
_errorWidget->pushOK->setIconSet(SmallIcon("button_ok", QIconSet::Automatic));
408
// close us when ok is pressed
409
connect(_errorWidget->pushOK, SIGNAL(clicked()), this, SLOT(done()));
410
_errorWidget->show();
412
// resize so the message fits in our widget
413
this->resize(minimumSizeHint());
415
// show if we are hidden
420
ActivationStageNotify::done()
425
void ActivationStageNotify::mousePressEvent(QMouseEvent* /*me*/)
427
if (_errorWidget != NULL)
428
/* if we display an error and the user clicked us he wants
429
the error to go away -> delete */
432
/* if we have only normal state reporting and the user
433
clicked us he doesnt want to see the state changes but
434
maybe he wants o be notified when an error occurs */
438
void ActivationStageNotify::getArrowPoints(QPointArray& arrow)
441
arrow.setPoint(0, QPoint(_right ? width() - 10 : 10,
442
_bottom ? height() - 20 : 20));
443
arrow.setPoint(1, QPoint(_right ? width() : 0, _bottom ? height() : 0));
444
arrow.setPoint(2, QPoint(_right ? width() - 20 : 20,
445
_bottom ? height() - 10 : 10));
448
void ActivationStageNotify::paintEvent(QPaintEvent* /*pe*/)
450
QPainter paint(this);
451
paint.drawRoundRect(10,10,width()-20, height()-20, 1600/width(), 1600/height());
454
getArrowPoints(arrow);
456
paint.setPen(this->backgroundColor());
457
paint.setBrush(this->backgroundColor());
458
paint.drawPolygon(arrow);
460
paint.setPen(Qt::black);
461
paint.drawPolyline(arrow);
464
void ActivationStageNotify::setAnchor(const QPoint &anchor)
470
// Based on work of Kopete (http://kopete.kde.org)
471
void ActivationStageNotify::updateMask()
473
QRect deskRect = KGlobalSettings::desktopGeometry(_anchor);
474
_bottom = (_anchor.y() + height()) > ((deskRect.y() + deskRect.height()-48));
475
_right = (_anchor.x() + width()) > ((deskRect.x() + deskRect.width()-48));
478
getArrowPoints(arrow);
480
QBitmap mask(width(), height());
481
QPainter maskPainter(&mask);
482
mask.fill(Qt::black);
483
maskPainter.setBrush(Qt::white);
484
maskPainter.setPen(Qt::white);
485
maskPainter.drawRoundRect(10, 10, mask.rect().width()- 20, mask.rect().height()-20, 1600 / mask.rect().width(), 1600 / mask.rect().height());
486
maskPainter.drawPolygon(arrow);
489
move( _right ? _anchor.x() - width() - 10 : ( _anchor.x() + 10 < 0 ? 0 : _anchor.x() + 10 ),
490
_bottom ? _anchor.y() - height() - 10 : ( _anchor.y() + 10 < 0 ? 0 : _anchor.y() + 10 ) );
493
#include "knetworkmanager-notify.moc"