1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
3
# Copyright (C) 2012 David Planella <david.planella@ubuntu.com>
4
# This program is free software: you can redistribute it and/or modify it
5
# under the terms of the GNU General Public License version 3, as published
6
# by the Free Software Foundation.
8
# This program is distributed in the hope that it will be useful, but
9
# WITHOUT ANY WARRANTY; without even the implied warranties of
10
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11
# PURPOSE. See the GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License along
14
# with this program. If not, see <http://www.gnu.org/licenses/>.
17
from qreator_lib.i18n import _
18
from qreator_lib.helpers import get_data_file
19
from gi.repository import Gtk, NetworkManager, NMClient
22
class QRCodeWifiGtk(object):
23
def __init__(self, qr_code_update_func):
24
self.qr_code_update_func = qr_code_update_func
25
self.builder = Gtk.Builder()
27
self.builder.add_from_file(
28
get_data_file('ui', '%s.ui' % ('QrCodeWifi',)))
29
self.grid = self.builder.get_object('qr_code_wifi')
30
self.builder.connect_signals(self)
32
self.comboboxtextSecurity = self.builder.get_object(
33
'comboboxtextSecurity')
34
self.entrySSID = self.builder.get_object('entrySSID')
35
self.entryPassword = self.builder.get_object('entryPassword')
36
self.comboboxtextSSID = self.builder.get_object('comboboxtextSSID')
38
# Initialize combo boxes (Glade seems not to do it for us)
39
self.comboboxtextSecurity.set_active(0)
41
# TRANSLATORS: 'expand' refers to expanding the drop-down menu
42
# that shows autodetected wireless network identifiers
43
self.entrySSID.set_placeholder_text(
44
_('[Network identifier - expand for autodetection]'))
45
self.entryPassword.set_placeholder_text(_('[Network password]'))
47
def update_ssids(self):
50
# TODO: clear combobox
51
self.comboboxtextSSID.append_text(ssid)
53
def update_wifi_qr_code(self, security=None, ssid=None, password=None):
55
security = self.comboboxtextSecurity.get_active_text()
57
ssid = self.entrySSID.get_text()
59
password = self.entryPassword.get_text()
61
if not security or ssid == '' or password == '':
64
wifi_qr_code = 'WIFI:T:{0};S:{1};P:{2};;'.format(security, ssid,
66
self.qr_code_update_func(wifi_qr_code)
68
def on_comboboxtextSecurity_changed(self, widget, data=None):
69
self.update_wifi_qr_code(security=widget.get_active_text())
71
#def on_entrySSID_icon_press(self, widget, icon, mouse_button):
72
# self._clear_text_entry(widget, icon)
74
def on_comboboxtextSSID_changed(self, widget, data=None):
75
#self._check_style(self.ui.entrySSID)
76
self.update_wifi_qr_code(ssid=widget.get_active_text())
78
#def on_entryPassword_icon_press(self, widget, icon, mouse_button):
79
# self._clear_text_entry(widget, icon)
81
def on_entryPassword_changed(self, widget, data=None):
82
#self._check_style(widget)
83
self.update_wifi_qr_code(password=widget.get_text())
85
def on_checkbutton1_clicked(self, widget):
86
if widget.get_active():
87
self.entryPassword.set_visibility(True)
89
self.entryPassword.set_visibility(False)
91
def on_activated(self):
96
nmc = NMClient.Client.new()
97
devs = nmc.get_devices()
101
if dev.get_device_type() == NetworkManager.DeviceType.WIFI:
102
for ap in dev.get_access_points():
103
ssids.append(ap.get_ssid())