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:
parent
85b0670a92
commit
3a76aa7ef7
2 changed files with 37 additions and 12 deletions
25
main.qml
25
main.qml
|
@ -152,17 +152,8 @@ ApplicationWindow {
|
||||||
anchors.leftMargin: 120
|
anchors.leftMargin: 120
|
||||||
|
|
||||||
textRole: "name"
|
textRole: "name"
|
||||||
model: []
|
model: backend.screens
|
||||||
|
currentIndex: backend.virtScreenIndex
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
onActivated: function(index) {
|
onActivated: function(index) {
|
||||||
backend.virtScreenIndex = index
|
backend.virtScreenIndex = index
|
||||||
|
@ -287,6 +278,18 @@ ApplicationWindow {
|
||||||
// Material.foreground: Material.Grey
|
// Material.foreground: Material.Grey
|
||||||
onClicked: backend.vncState == Backend.OFF ? backend.startVNC() : backend.stopVNC()
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -329,7 +329,9 @@ class Backend(QObject):
|
||||||
|
|
||||||
# Signals
|
# Signals
|
||||||
onVirtScreenCreatedChanged = pyqtSignal(bool)
|
onVirtScreenCreatedChanged = pyqtSignal(bool)
|
||||||
|
onVirtScreenIndexChanged = pyqtSignal(int)
|
||||||
onVncStateChanged = pyqtSignal(VNCState)
|
onVncStateChanged = pyqtSignal(VNCState)
|
||||||
|
onIPAddressesChanged = pyqtSignal()
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super(Backend, self).__init__(parent)
|
super(Backend, self).__init__(parent)
|
||||||
|
@ -348,6 +350,8 @@ class Backend(QObject):
|
||||||
self._vncPort = 5900
|
self._vncPort = 5900
|
||||||
self._vncPassword = ""
|
self._vncPassword = ""
|
||||||
self._vncState = Backend.VNCState.OFF
|
self._vncState = Backend.VNCState.OFF
|
||||||
|
self._ipAddresses: List[str] = []
|
||||||
|
self.updateIPAddresses()
|
||||||
# Primary screen and mouse posistion
|
# Primary screen and mouse posistion
|
||||||
self._primary: DisplayProperty() = self.xrandr.get_primary_screen()
|
self._primary: DisplayProperty() = self.xrandr.get_primary_screen()
|
||||||
self._cursor_x: int
|
self._cursor_x: int
|
||||||
|
@ -387,7 +391,7 @@ class Backend(QObject):
|
||||||
def screens(self):
|
def screens(self):
|
||||||
return QQmlListProperty(DisplayProperty, self, self._screens)
|
return QQmlListProperty(DisplayProperty, self, self._screens)
|
||||||
|
|
||||||
@pyqtProperty(int)
|
@pyqtProperty(int, notify=onVirtScreenIndexChanged)
|
||||||
def virtScreenIndex(self):
|
def virtScreenIndex(self):
|
||||||
return self._virtScreenIndex
|
return self._virtScreenIndex
|
||||||
@virtScreenIndex.setter
|
@virtScreenIndex.setter
|
||||||
|
@ -418,6 +422,10 @@ class Backend(QObject):
|
||||||
def vncState(self, state):
|
def vncState(self, state):
|
||||||
self._vncState = state
|
self._vncState = state
|
||||||
self.onVncStateChanged.emit(self._vncState)
|
self.onVncStateChanged.emit(self._vncState)
|
||||||
|
|
||||||
|
@pyqtProperty('QStringList', notify=onIPAddressesChanged)
|
||||||
|
def ipAddresses(self):
|
||||||
|
return self._ipAddresses
|
||||||
|
|
||||||
@pyqtProperty(DisplayProperty)
|
@pyqtProperty(DisplayProperty)
|
||||||
def primary(self):
|
def primary(self):
|
||||||
|
@ -507,6 +515,20 @@ class Backend(QObject):
|
||||||
else:
|
else:
|
||||||
print("stopVNC called while it is not running")
|
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()
|
@pyqtSlot()
|
||||||
def quitProgram(self):
|
def quitProgram(self):
|
||||||
QApplication.instance().quit()
|
QApplication.instance().quit()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue