3 * Copyright 2014-2017 Roy Marples <roy@marples.name>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <QHBoxLayout>
30 #include <QRadioButton>
37 #include "dhcpcd-qt.h"
38 #include "dhcpcd-ssidmenuwidget.h"
42 DhcpcdSsidMenuWidget::DhcpcdSsidMenuWidget(QWidget *parent,
43 DhcpcdWi *wi, DHCPCD_WI_SCAN *scan)
51 QHBoxLayout *layout = new QHBoxLayout(this);
52 layout->setContentsMargins(1, 1, 1, 1);
53 selicon = new QLabel(this);
54 selicon->setMinimumSize(ICON_SIZE, ICON_SIZE);
55 layout->addWidget(selicon);
57 ssid = new QLabel(this);
58 ssid->setSizePolicy(QSizePolicy::MinimumExpanding,
59 QSizePolicy::MinimumExpanding);
60 layout->addWidget(ssid);
62 encicon = new QLabel(this);
63 layout->addWidget(encicon);
64 layout->setAlignment(encicon, Qt::AlignRight);
66 stricon = new QLabel(this);
67 layout->addWidget(stricon);
68 layout->setAlignment(stricon, Qt::AlignRight);
71 installEventFilter(this);
73 setStyleSheet("QFrame { border-radius: 4px; } "
75 "color:palette(highlighted-text);"
76 "background-color:palette(highlight);"
80 DHCPCD_WI_SCAN *DhcpcdSsidMenuWidget::getScan()
86 bool DhcpcdSsidMenuWidget::isAssociated()
92 bool DhcpcdSsidMenuWidget::isActive()
98 void DhcpcdSsidMenuWidget::setActive(bool active)
101 if (this->active != active) {
102 this->ssid->setEnabled(active);
103 this->active = active;
107 void DhcpcdSsidMenuWidget::setScan(DHCPCD_WI_SCAN *scan)
117 i = dhcpcd_wpa_if(wpa);
118 associated = dhcpcd_wi_associated(i, scan);
121 * Icons are rescaled because they are not always the size requested
122 * due to a bug in Qt-4.8.
123 * https://qt.gitorious.org/qt/qt/merge_requests/2566
127 icon = DhcpcdQt::getIcon("actions", "dialog-ok-apply");
128 picon = icon.pixmap(ICON_SIZE);
129 if (picon.height() != ICON_SIZE)
130 picon = picon.scaledToHeight(ICON_SIZE,
131 Qt::SmoothTransformation);
132 selicon->setPixmap(picon);
133 ssid->setStyleSheet("font:bold;");
135 selicon->setPixmap(QPixmap());
136 ssid->setStyleSheet(NULL);
138 ssid->setText(scan->ssid);
140 if (scan->flags & WSF_SECURE) {
141 if (scan->flags & WSF_PSK)
142 icon = DhcpcdQt::getIcon("status",
143 "network-wireless-encrypted");
145 icon = DhcpcdQt::getIcon("status",
150 icon = DhcpcdQt::getIcon("status", "dialog-warning");
151 picon = icon.pixmap(ICON_SIZE);
152 if (picon.height() != ICON_SIZE)
153 picon = picon.scaledToHeight(ICON_SIZE, Qt::SmoothTransformation);
154 encicon->setPixmap(picon);
156 icon = DhcpcdQt::getIcon("status",
157 DhcpcdQt::signalStrengthIcon(scan));
158 picon = icon.pixmap(ICON_SIZE);
159 if (picon.height() != ICON_SIZE)
160 picon = picon.scaledToHeight(ICON_SIZE, Qt::SmoothTransformation);
161 stricon->setPixmap(picon);
166 bool DhcpcdSsidMenuWidget::eventFilter(QObject *, QEvent *event)
169 if (event->type() == QEvent::MouseButtonPress) {
176 void DhcpcdSsidMenuWidget::enterEvent(QEvent *)
183 ssid->setStyleSheet("color:palette(highlighted-text); font:bold;");
185 ssid->setStyleSheet("color:palette(highlighted-text);");
189 void DhcpcdSsidMenuWidget::leaveEvent(QEvent *)
196 ssid->setStyleSheet("color:palette(text); font:bold;");
198 ssid->setStyleSheet("color:palette(text);");