1
/***************************************************************************
2
* Copyright (C) 2012 by Daniel Nicoletti *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; see the file COPYING. If not, write to *
17
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
18
* Boston, MA 02110-1301, USA. *
19
***************************************************************************/
21
#include "TabConnectionInfo.h"
22
#include "ui_TabConnectionInfo.h"
26
#include <NetworkManagerQt/ActiveConnection>
27
#include <NetworkManagerQt/Manager>
29
#define CONNECTION_ICON_SIZE 64
31
using namespace NetworkManager;
33
TabConnectionInfo::TabConnectionInfo(QWidget *parent) :
35
ui(new Ui::TabConnectionInfo)
40
TabConnectionInfo::~TabConnectionInfo()
45
void TabConnectionInfo::setConnection(const NetworkManager::Connection::Ptr &connection)
47
if (m_connection && m_connection->path() == connection->path()) {
52
m_connection->disconnect(this);
54
m_connection = connection;
56
connect(connection.data(), SIGNAL(updated()),
57
this, SLOT(updateState()));
62
void TabConnectionInfo::updateState()
64
QDateTime dateTime = m_connection->settings()->timestamp();
65
if (dateTime.isValid()) {
66
ui->lastUsedL->setText(KGlobal::locale()->formatDateTime(dateTime));
68
ui->lastUsedL->setText(i18n("never"));
70
ui->nameL->setText(m_connection->name());
72
foreach (const ActiveConnection::Ptr &activeConnection, NetworkManager::activeConnections()) {
73
if (activeConnection->connection()->path() == m_connection->path()) {
74
foreach (const QString &deviceUNI, activeConnection->devices()) {
75
Device::Ptr device = NetworkManager::findNetworkInterface(deviceUNI);
77
devices << UiUtils::prettyInterfaceName(device->type(), device->interfaceName());
83
if (devices.isEmpty()) {
84
ui->statusL->setText(i18n("not active"));
85
ui->connectDisconnectPB->setText(i18n("Connect"));
87
ui->statusL->setText(i18n("active on %1", devices.join(QLatin1String(", "))));
88
ui->connectDisconnectPB->setText(i18n("Disconnect"));
93
iconName = UiUtils::iconAndTitleForConnectionSettingsType(m_connection->settings()->connectionType(),
95
ui->typeL->setText(title);
97
QPixmap icon = KIconLoader::global()->loadIcon(iconName,
99
CONNECTION_ICON_SIZE, // a not so huge icon
100
KIconLoader::DefaultState);
101
ui->iconL->setPixmap(icon);
104
void TabConnectionInfo::on_connectDisconnectPB_clicked()
106
bool disconnected = false;
107
foreach (const ActiveConnection::Ptr &activeConnection, NetworkManager::activeConnections()) {
108
if (activeConnection->connection()->path() == m_connection->path()) {
109
NetworkManager::deactivateConnection(activeConnection->path());
115
// TODO find a device to activate this connection