~ubuntu-branches/ubuntu/saucy/plasma-nm/saucy-proposed

« back to all changes in this revision

Viewing changes to kcm/TabConnectionInfo.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-08-16 19:07:09 UTC
  • Revision ID: package-import@ubuntu.com-20130816190709-ef9ydm9skigmg15l
Tags: upstream-0.0~git20130816
ImportĀ upstreamĀ versionĀ 0.0~git20130816

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2012 by Daniel Nicoletti                                *
 
3
 *   dantti12@gmail.com                                                    *
 
4
 *                                                                         *
 
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.                                   *
 
9
 *                                                                         *
 
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.                          *
 
14
 *                                                                         *
 
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
 ***************************************************************************/
 
20
 
 
21
#include "TabConnectionInfo.h"
 
22
#include "ui_TabConnectionInfo.h"
 
23
 
 
24
#include "uiutils.h"
 
25
 
 
26
#include <NetworkManagerQt/ActiveConnection>
 
27
#include <NetworkManagerQt/Manager>
 
28
 
 
29
#define CONNECTION_ICON_SIZE 64
 
30
 
 
31
using namespace NetworkManager;
 
32
 
 
33
TabConnectionInfo::TabConnectionInfo(QWidget *parent) :
 
34
    QWidget(parent),
 
35
    ui(new Ui::TabConnectionInfo)
 
36
{
 
37
    ui->setupUi(this);
 
38
}
 
39
 
 
40
TabConnectionInfo::~TabConnectionInfo()
 
41
{
 
42
    delete ui;
 
43
}
 
44
 
 
45
void TabConnectionInfo::setConnection(const NetworkManager::Connection::Ptr &connection)
 
46
{
 
47
    if (m_connection && m_connection->path() == connection->path()) {
 
48
        return;
 
49
    }
 
50
 
 
51
    if (m_connection) {
 
52
        m_connection->disconnect(this);
 
53
    }
 
54
    m_connection = connection;
 
55
    if (connection) {
 
56
        connect(connection.data(), SIGNAL(updated()),
 
57
                this, SLOT(updateState()));
 
58
        updateState();
 
59
    }
 
60
}
 
61
 
 
62
void TabConnectionInfo::updateState()
 
63
{
 
64
    QDateTime dateTime = m_connection->settings()->timestamp();
 
65
    if (dateTime.isValid()) {
 
66
        ui->lastUsedL->setText(KGlobal::locale()->formatDateTime(dateTime));
 
67
    } else {
 
68
        ui->lastUsedL->setText(i18n("never"));
 
69
    }
 
70
    ui->nameL->setText(m_connection->name());
 
71
    QStringList devices;
 
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);
 
76
                if (device) {
 
77
                    devices << UiUtils::prettyInterfaceName(device->type(), device->interfaceName());
 
78
                }
 
79
            }
 
80
        }
 
81
    }
 
82
 
 
83
    if (devices.isEmpty()) {
 
84
        ui->statusL->setText(i18n("not active"));
 
85
        ui->connectDisconnectPB->setText(i18n("Connect"));
 
86
    } else {
 
87
        ui->statusL->setText(i18n("active on %1", devices.join(QLatin1String(", "))));
 
88
        ui->connectDisconnectPB->setText(i18n("Disconnect"));
 
89
    }
 
90
 
 
91
    QString title;
 
92
    QString iconName;
 
93
    iconName = UiUtils::iconAndTitleForConnectionSettingsType(m_connection->settings()->connectionType(),
 
94
                                                              title);
 
95
    ui->typeL->setText(title);
 
96
 
 
97
    QPixmap icon = KIconLoader::global()->loadIcon(iconName,
 
98
                                                   KIconLoader::NoGroup,
 
99
                                                   CONNECTION_ICON_SIZE, // a not so huge icon
 
100
                                                   KIconLoader::DefaultState);
 
101
    ui->iconL->setPixmap(icon);
 
102
}
 
103
 
 
104
void TabConnectionInfo::on_connectDisconnectPB_clicked()
 
105
{
 
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());
 
110
            disconnected = true;
 
111
        }
 
112
    }
 
113
 
 
114
    if (disconnected) {
 
115
        // TODO find a device to activate this connection
 
116
    }
 
117
}