1
0
Fork 0
mirror of https://github.com/borgbase/vorta synced 2024-12-23 00:07:58 +00:00

Keep wifi list in sync with OS. #6

This commit is contained in:
Manu 2018-11-20 12:19:00 +08:00
parent 7bb320f281
commit ea27db4ee9

View file

@ -10,10 +10,10 @@
from PyQt5 import uic, QtCore from PyQt5 import uic, QtCore
import subprocess import subprocess
import keyring import keyring
from keyring import backend from .models import WifiSettingModel
class VortaKeyring(backend.KeyringBackend): class VortaKeyring(keyring.backend.KeyringBackend):
"""Fallback keyring service.""" """Fallback keyring service."""
@classmethod @classmethod
def priority(cls): def priority(cls):
@ -55,23 +55,13 @@ def delete_password(self, service, repo_url):
keyring.set_keyring(VortaKeyring()) keyring.set_keyring(VortaKeyring())
from .models import WifiSettingModel
def choose_folder_dialog(parent, title): def choose_folder_dialog(parent, title):
# messagebox.setWindowModality(QtCore.Qt.WindowModal)
# messagebox.setParent(messagebox.parentWidget(), QtCore.Qt.Sheet)
# messagebox.setResult(0)
# messagebox.show()
options = QFileDialog.Options() options = QFileDialog.Options()
options |= QFileDialog.ShowDirsOnly options |= QFileDialog.ShowDirsOnly
# options |= QFileDialog.DontUseNativeDialog
dialog = QFileDialog(parent, title, os.path.expanduser('~'), options=options) dialog = QFileDialog(parent, title, os.path.expanduser('~'), options=options)
# dialog.setWindowModality(QtCore.Qt.WindowModal)
dialog.setParent(parent, QtCore.Qt.Sheet) dialog.setParent(parent, QtCore.Qt.Sheet)
# dialog.setResult(0)
return dialog return dialog
# return QFileDialog.getExistingDirectory(parent, title, "", options=options)
def get_private_keys(): def get_private_keys():
"""Find SSH keys in standard folder.""" """Find SSH keys in standard folder."""
@ -133,10 +123,20 @@ def get_sorted_wifis(profile):
for wifi in wifis.values(): for wifi in wifis.values():
timestamp = wifi.get('LastConnected', None) timestamp = wifi.get('LastConnected', None)
ssid = wifi['SSIDString'] ssid = wifi['SSIDString']
WifiSettingModel.get_or_create(ssid=ssid, profile=profile.id, db_wifi, created = WifiSettingModel.get_or_create(ssid=ssid, profile=profile.id,
defaults={'last_connected': timestamp, defaults={'last_connected': timestamp,
'allowed': True}) 'allowed': True})
# update last connected time
if not created and db_wifi.last_connected != timestamp:
db_wifi.last_connected = timestamp
db_wifi.save()
# remove Wifis that were deleted in the system.
deleted_wifis = WifiSettingModel.select().where(WifiSettingModel.ssid.not_in([w['SSIDString'] for w in wifis.values()]))
for wifi in deleted_wifis:
wifi.delete_instance()
return WifiSettingModel.select().where(WifiSettingModel.profile == profile.id).order_by(-WifiSettingModel.last_connected) return WifiSettingModel.select().where(WifiSettingModel.profile == profile.id).order_by(-WifiSettingModel.last_connected)