File: wirelessnetworkitem.cpp

package info (click to toggle)
wicd-kde 0.3.0-2
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 1,000 kB
  • sloc: cpp: 2,963; sh: 3; makefile: 2
file content (119 lines) | stat: -rw-r--r-- 4,990 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/****************************************************************************
 *  Copyright (c) 2011 Anthony Vital <anthony.vital@gmail.com>              *
 *                                                                          *
 *  This file is part of Wicd Client KDE.                                   *
 *                                                                          *
 *  Wicd Client KDE is free software: you can redistribute it and/or modify *
 *  it under the terms of the GNU General Public License as published by    *
 *  the Free Software Foundation, either version 3 of the License, or       *
 *  (at your option) any later version.                                     *
 *                                                                          *
 *  Wicd Client KDE is distributed in the hope that it will be useful,      *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of          *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
 *  GNU General Public License for more details.                            *
 *                                                                          *
 *  You should have received a copy of the GNU General Public License       *
 *  along with Wicd Client KDE.  If not, see <http://www.gnu.org/licenses/>.*
 ****************************************************************************/

#include "wirelessnetworkitem.h"

#include <QWidget>
#include <QLabel>
#include <QFormLayout>

#include <Plasma/Meter>
#include <Plasma/Theme>

bool WirelessNetworkItem::m_showStrength(false);

WirelessNetworkItem::WirelessNetworkItem(NetworkInfo info, QGraphicsWidget *parent)
    : NetworkItem(info, parent),
      m_infoWidget(0)
{
    m_networkIcon->setText(m_info.value("essid").toString());
    m_networkIcon->setIcon("network-wireless");

    if (m_info.value("encryption").toBool()) {
        m_networkIcon->setOverlayIcon(KIcon("security-high"));
    } else {
        m_networkIcon->setOverlayIcon(KIcon("security-low"));
    }

    //add signal quality
    Plasma::Meter *qualityBar = new Plasma::Meter(this);
    qualityBar->setMeterType(Plasma::Meter::BarMeterHorizontal);
    qualityBar->setPreferredWidth(100);
    qualityBar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    qualityBar->setMinimum(0);
    qualityBar->setMaximum(100);
    qualityBar->setValue(m_info.value("quality").toInt());

    if (m_showStrength) {
        Plasma::Theme* theme = Plasma::Theme::defaultTheme();
        QFont font = theme->font(Plasma::Theme::DefaultFont);
        font.setPointSize(7.5);
        qualityBar->setLabelFont(0, font);
        qualityBar->setLabelAlignment(0, Qt::AlignVCenter | Qt::AlignLeft);
        bool usedbm = m_info.value("usedbm").toBool();
        QString signal = usedbm ? m_info.value("strength").toString()+" dBm" : m_info.value("quality").toString()+'%';
        qualityBar->setLabel(0, signal);
    } else {
        qualityBar->setMaximumHeight(12);
    }

    m_hLayout->insertItem(2, qualityBar);
    m_hLayout->setAlignment(qualityBar, Qt::AlignVCenter);

    connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), SLOT(updateColors()));
    updateColors();
}

void WirelessNetworkItem::updateColors()
{
    QPalette pal = palette();
    pal.setColor(QPalette::WindowText, Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor));
    setPalette(pal);
}

QGraphicsWidget* WirelessNetworkItem::moreWidget()
{
    if (!m_infoWidget) {
        m_infoWidget = new QGraphicsProxyWidget(this);
        m_infoFade->setTargetWidget(m_infoWidget);

        QWidget *widget = new QWidget();
        widget->setPalette(palette());
        widget->setAttribute(Qt::WA_NoSystemBackground);
        QFormLayout *formLayout = new QFormLayout(widget);
        formLayout->setLabelAlignment(Qt::AlignLeft);
        widget->setLayout(formLayout);

        QString signal;
        if (m_info.value("usedbm").toBool())
            signal = m_info.value("strength").toString()+" dBm";
        else
            signal = m_info.value("quality").toString()+'%';
        formLayout->addRow(new QLabel(i18n("Signal strength:")), new QLabel(signal));

        QString encryption;
        if (m_info.value("encryption").toBool())
            encryption = m_info.value("encryptionType").toString();
        else
            encryption = i18n("Unsecured");
        formLayout->addRow(new QLabel(i18n("Encryption type:")), new QLabel(encryption));

        QString accessPoint = m_info.value("bssid").toString();
        formLayout->addRow(new QLabel(i18n("Access point address:")), new QLabel(accessPoint));

        QString mode = m_info.value("mode").toString();
        formLayout->addRow(new QLabel(i18n("Mode:")), new QLabel(mode));

        QString channel = m_info.value("channel").toString();
        formLayout->addRow(new QLabel(i18n("Channel:")), new QLabel(channel));

        m_infoWidget->setWidget(widget);
    }
    return m_infoWidget;
}