1
0
Fork 0
mirror of https://github.com/kbumsik/VirtScreen.git synced 2025-03-09 15:40:18 +00:00

Backend: show ip list

This commit is contained in:
Bumsik Kim 2018-05-10 12:15:28 -04:00
parent 85b0670a92
commit 3a76aa7ef7
No known key found for this signature in database
GPG key ID: E31041C8EC5B01C6
2 changed files with 37 additions and 12 deletions

View file

@ -152,17 +152,8 @@ ApplicationWindow {
anchors.leftMargin: 120
textRole: "name"
model: []
Component.onCompleted: {
var screens = backend.screens;
var list = [];
for (var i = 0; i < screens.length; i++) {
list.push(screens[i]);
}
deviceComboBox.model = list;
deviceComboBox.currentIndex = backend.virtScreenIndex
}
model: backend.screens
currentIndex: backend.virtScreenIndex
onActivated: function(index) {
backend.virtScreenIndex = index
@ -287,6 +278,18 @@ ApplicationWindow {
// Material.foreground: Material.Grey
onClicked: backend.vncState == Backend.OFF ? backend.startVNC() : backend.stopVNC()
}
ListView {
// width: 180;
height: 200
anchors.left: parent.left
anchors.right: parent.right
model: backend.ipAddresses
delegate: Text {
text: modelData
}
}
}
}

View file

@ -329,7 +329,9 @@ class Backend(QObject):
# Signals
onVirtScreenCreatedChanged = pyqtSignal(bool)
onVirtScreenIndexChanged = pyqtSignal(int)
onVncStateChanged = pyqtSignal(VNCState)
onIPAddressesChanged = pyqtSignal()
def __init__(self, parent=None):
super(Backend, self).__init__(parent)
@ -348,6 +350,8 @@ class Backend(QObject):
self._vncPort = 5900
self._vncPassword = ""
self._vncState = Backend.VNCState.OFF
self._ipAddresses: List[str] = []
self.updateIPAddresses()
# Primary screen and mouse posistion
self._primary: DisplayProperty() = self.xrandr.get_primary_screen()
self._cursor_x: int
@ -387,7 +391,7 @@ class Backend(QObject):
def screens(self):
return QQmlListProperty(DisplayProperty, self, self._screens)
@pyqtProperty(int)
@pyqtProperty(int, notify=onVirtScreenIndexChanged)
def virtScreenIndex(self):
return self._virtScreenIndex
@virtScreenIndex.setter
@ -418,6 +422,10 @@ class Backend(QObject):
def vncState(self, state):
self._vncState = state
self.onVncStateChanged.emit(self._vncState)
@pyqtProperty('QStringList', notify=onIPAddressesChanged)
def ipAddresses(self):
return self._ipAddresses
@pyqtProperty(DisplayProperty)
def primary(self):
@ -507,6 +515,20 @@ class Backend(QObject):
else:
print("stopVNC called while it is not running")
@pyqtSlot()
def updateIPAddresses(self):
self._ipAddresses.clear()
for interface in interfaces():
if interface == 'lo':
continue
addresses = ifaddresses(interface).get(AF_INET, None)
if addresses is None:
continue
for link in addresses:
if link is not None:
self._ipAddresses.append(link['addr'])
self.onIPAddressesChanged.emit()
@pyqtSlot()
def quitProgram(self):
QApplication.instance().quit()