3 * Copyright 2014 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"
40 DhcpcdSsidMenuWidget::DhcpcdSsidMenuWidget(QWidget *parent,
41 DhcpcdWi *wi, DHCPCD_WI_SCAN *scan)
48 QHBoxLayout *layout = new QHBoxLayout(this);
49 layout->setContentsMargins(1, 1, 1, 1);
50 selicon = new QLabel(this);
51 selicon->setMinimumSize(16, 16);
52 layout->addWidget(selicon);
54 ssid = new QLabel(this);
55 ssid->setSizePolicy(QSizePolicy::MinimumExpanding,
56 QSizePolicy::MinimumExpanding);
57 layout->addWidget(ssid);
59 encicon = new QLabel(this);
60 layout->addWidget(encicon);
61 layout->setAlignment(encicon, Qt::AlignRight);
63 stricon = new QLabel(this);
64 layout->addWidget(stricon);
65 layout->setAlignment(stricon, Qt::AlignRight);
68 installEventFilter(this);
70 setStyleSheet("QFrame { border-radius: 4px; } "
72 "color:palette(highlighted-text);"
73 "background-color:palette(highlight);"
77 DHCPCD_WI_SCAN *DhcpcdSsidMenuWidget::getScan()
83 bool DhcpcdSsidMenuWidget::isAssociated()
89 void DhcpcdSsidMenuWidget::setScan(DHCPCD_WI_SCAN *scan)
98 i = dhcpcd_wpa_if(wpa);
99 associated = dhcpcd_wi_associated(i, scan);
102 icon = DhcpcdQt::getIcon("actions", "dialog-ok-apply");
103 picon = icon.pixmap(16, 16);
104 selicon->setPixmap(picon);
105 ssid->setStyleSheet("font:bold;");
107 selicon->setPixmap(NULL);
108 ssid->setStyleSheet(NULL);
110 ssid->setText(scan->ssid);
111 if (scan->flags & WSF_SECURE)
112 icon = DhcpcdQt::getIcon("status",
113 "network-wireless-encrypted");
115 icon = DhcpcdQt::getIcon("status", "dialog-warning");
116 picon = icon.pixmap(16, 16);
117 encicon->setPixmap(picon);
119 if (scan->strength.value > 80)
120 icon = DhcpcdQt::getIcon("status",
121 "network-wireless-connected-100");
122 else if (scan->strength.value > 55)
123 icon = DhcpcdQt::getIcon("status",
124 "network-wireless-connected-75");
125 else if (scan->strength.value > 30)
126 icon = DhcpcdQt::getIcon("status",
127 "network-wireless-connected-50");
128 else if (scan->strength.value > 5)
129 icon = DhcpcdQt::getIcon("status",
130 "network-wireless-connected-25");
132 icon = DhcpcdQt::getIcon("status",
133 "network-wireless-connected-00");
134 picon = icon.pixmap(16, 16);
135 stricon->setPixmap(picon);
138 bool DhcpcdSsidMenuWidget::eventFilter(QObject *, QEvent *event)
141 if (event->type() == QEvent::MouseButtonPress)
146 void DhcpcdSsidMenuWidget::enterEvent(QEvent *)
150 ssid->setStyleSheet("color:palette(highlighted-text); font:bold;");
152 ssid->setStyleSheet("color:palette(highlighted-text);");
156 void DhcpcdSsidMenuWidget::leaveEvent(QEvent *)
160 ssid->setStyleSheet("color:palette(text); font:bold;");
162 ssid->setStyleSheet("color:palette(text);");