[Pkg-privacy-commits] [tails-installer] 31/210: Start working on exposing the USB devices
Intrigeri
intrigeri at moszumanska.debian.org
Wed May 24 15:26:25 UTC 2017
This is an automated email from the git hooks/post-receive script.
intrigeri pushed a commit to tag 3.90.0
in repository tails-installer.
commit 5d60ae72b018f2b0ffa71c16bb32a80317a641a1
Author: Martin Briza <mbriza at redhat.com>
Date: Thu Feb 26 16:29:56 2015 +0100
Start working on exposing the USB devices
---
liveusb/components/AdwaitaProgressBar.qml | 13 ++--
liveusb/components/DownloadDialog.qml | 19 ++++--
liveusb/gui.py | 104 +++++++++++++++++++++++++++++-
3 files changed, 123 insertions(+), 13 deletions(-)
diff --git a/liveusb/components/AdwaitaProgressBar.qml b/liveusb/components/AdwaitaProgressBar.qml
index 9aaf410..e663759 100644
--- a/liveusb/components/AdwaitaProgressBar.qml
+++ b/liveusb/components/AdwaitaProgressBar.qml
@@ -3,8 +3,11 @@ import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2
ProgressBar {
+ id: root
width: 100
height: 6
+ property color progressColor: "#54aada"
+ property color backgroundColor: "#c3c3c3"
style: ProgressBarStyle {
background: Rectangle {
height: 6
@@ -15,8 +18,8 @@ ProgressBar {
radius: 3
clip: true
gradient: Gradient {
- GradientStop { position: 0.0; color: "#b2b2b2" }
- GradientStop { position: 1.0; color: "#d4d4d4" }
+ GradientStop { position: 0.0; color: Qt.lighter(root.backgroundColor, 1.05) }
+ GradientStop { position: 1.0; color: Qt.darker(root.backgroundColor, 1.05) }
}
}
progress: Rectangle {
@@ -28,9 +31,9 @@ ProgressBar {
}
radius: 3
gradient: Gradient {
- GradientStop { position: 0.0; color: "#3D7DCD" }
- GradientStop { position: 0.9; color: "#54AADA" }
- GradientStop { position: 1.0; color: "#5D9DDD" }
+ GradientStop { position: 0.0; color: Qt.lighter(root.progressColor, 1.05) }
+ GradientStop { position: 0.9; color: root.progressColor }
+ GradientStop { position: 1.0; color: Qt.darker(root.progressColor) }
}
}
}
diff --git a/liveusb/components/DownloadDialog.qml b/liveusb/components/DownloadDialog.qml
index b01bfb6..d4c48d5 100644
--- a/liveusb/components/DownloadDialog.qml
+++ b/liveusb/components/DownloadDialog.qml
@@ -42,9 +42,20 @@ Dialog {
((leftSize / 1024 / 1024 / 1024).toFixed(1) + " GB")
text: liveUSBData.currentImage.status + (liveUSBData.currentImage.download.maxProgress > 0 ? " (" + leftStr + " left)" : "")
}
- AdwaitaProgressBar {
+ Item {
Layout.fillWidth: true
- value: liveUSBData.currentImage.download.progress / liveUSBData.currentImage.download.maxProgress
+ height: childrenRect.height
+ AdwaitaProgressBar {
+ width: parent.width
+ value: liveUSBData.currentImage.download.running ? liveUSBData.currentImage.download.progress / liveUSBData.currentImage.download.maxProgress : 0
+ visible: !liveUSBData.currentImage.writer.running
+ }
+ AdwaitaProgressBar {
+ width: parent.width
+ value: liveUSBData.currentImage.writer.running ? liveUSBData.currentImage.writer.progress / liveUSBData.currentImage.writer.maxProgress : 0
+ visible: !liveUSBData.currentImage.download.running
+ progressColor: "red"
+ }
}
}
@@ -63,9 +74,7 @@ Dialog {
}
AdwaitaComboBox {
Layout.preferredWidth: implicitWidth * 2
- model: ListModel {
- ListElement { text: "SanDisk Cruzer 2.0 GB Drive"; device:"sdj1" }
- }
+ model: liveUSBData.usbDrives
}
}
}
diff --git a/liveusb/gui.py b/liveusb/gui.py
index 763b21e..b5e971b 100755
--- a/liveusb/gui.py
+++ b/liveusb/gui.py
@@ -48,9 +48,10 @@ else:
from urlgrabber.progress import BaseMeter
try:
- import dbus.mainloop.qt
- dbus.mainloop.qt.DBusQtMainLoop(set_as_default=True)
-except:
+ import dbus.mainloop.pyqt5
+ dbus.mainloop.pyqt5.DBusQtMainLoop(set_as_default=True)
+except Exception, e:
+ print(e)
pass
MAX_FAT16 = 2047
@@ -168,6 +169,39 @@ class ReleaseDownload(QObject, BaseMeter):
def path(self):
return self._path
+class ReleaseWriter(QObject):
+ runningChanged = pyqtSignal()
+ currentChanged = pyqtSignal()
+ maximumChanged = pyqtSignal()
+
+ _running = False
+ _current = -1.0
+ _maximum = -1.0
+
+ def __init__(self, parent):
+ QObject.__init__(self, parent)
+
+ def reset(self):
+ self._running = False
+ self._current = -1.0
+ self._maximum = -1.0
+ self.runningChanged.emit()
+ self.currentChanged.emit()
+ self.maximumChanged.emit()
+
+ @pyqtProperty(bool, notify=runningChanged)
+ def running(self):
+ return self._running
+
+ @pyqtProperty(float, notify=maximumChanged)
+ def maxProgress(self):
+ return self._maximum
+
+ @pyqtProperty(float, notify=currentChanged)
+ def progress(self):
+ return self._current
+
+
class Release(QObject):
screenshotsChanged = pyqtSignal()
pathChanged = pyqtSignal()
@@ -209,6 +243,8 @@ class Release(QObject):
self._download = ReleaseDownload(self)
self._download.pathChanged.connect(self.pathChanged)
+ self._writer = ReleaseWriter(self)
+
self._download.runningChanged.connect(self.statusChanged)
@@ -276,6 +312,10 @@ class Release(QObject):
def download(self):
return self._download
+ @pyqtProperty(ReleaseWriter, constant=True)
+ def writer(self):
+ return self._writer
+
@pyqtProperty(str, notify=statusChanged)
def status(self):
if not self._download.running and not self.readyToWrite:
@@ -382,10 +422,25 @@ class LiveUSBLogHandler(logging.Handler):
if record.levelname in ('INFO', 'ERROR', 'WARN'):
self.cb(record.msg)
+class USBDrive(QObject):
+
+ def __init__(self, parent, name, path):
+ QObject.__init__(self, parent)
+ self._name = name
+ self._path = path
+
+ @pyqtProperty(str, constant=True)
+ def text(self):
+ return self._name
+
+ @pyqtProperty(str, constant=True)
+ def path(self):
+ return self._path
class LiveUSBData(QObject):
releasesChanged = pyqtSignal()
currentImageChanged = pyqtSignal()
+ usbDrivesChanged = pyqtSignal()
_currentIndex = 0
@@ -402,6 +457,41 @@ class LiveUSBData(QObject):
size=release['size'],
url=release['url']
))
+ self._usbDrives = []
+
+ def USBDeviceCallback():
+ self._usbDrives = []
+ for device, info in self.live.drives.items():
+ name = ''
+ if info['vendor'] and info['model']:
+ name = info['vendor'] + ' ' + info['model']
+ elif info['label']:
+ name = info['label']
+ else:
+ name = device
+
+ # TODO for some reason it gives me 4MB for my 4GB drive... and the rounding is off on my 8GB drive
+ if info['size']:
+ name += str(info['size'])
+ pass
+ if info['size'] < 1024:
+ name += ' (%d B)' % (info['size'])
+ elif info['size'] < 1024 * 1024:
+ name += ' (%d KB)' % (info['size'] / 1024)
+ elif info['size'] < 1024 * 1024 * 1024:
+ name += ' (%d MB)' % (info['size'] / 1024 / 1024)
+ elif info['size'] < 1024 * 1024 * 1024 * 1024:
+ name += ' (%d GB)' % (info['size'] / 1024 / 1024 / 1024)
+ else:
+ name += ' (%d TB)' % (info['size'] / 1024 / 1024 / 1024 / 1024)
+
+ self._usbDrives.append(USBDrive(self, name, device))
+ self.usbDrivesChanged.emit()
+ try:
+ self.live.detect_removable_drives(callback=USBDeviceCallback)
+ except LiveUSBError, e:
+ pass # TODO
+
@pyqtProperty(QQmlListProperty, notify=releasesChanged)
def releases(self):
@@ -424,6 +514,12 @@ class LiveUSBData(QObject):
def currentImage(self):
return self.releaseData[self._currentIndex]
+ @pyqtProperty(USBDrive, notify=usbDrivesChanged)
+ def usbDrives(self):
+ print(self._usbDrives)
+ return QQmlListProperty(USBDrive, self, self._usbDrives)
+
+
class LiveUSBApp(QApplication):
@@ -431,7 +527,9 @@ class LiveUSBApp(QApplication):
def __init__(self, opts, args):
QApplication.__init__(self, args)
qmlRegisterUncreatableType(ReleaseDownload, "LiveUSB", 1, 0, "Download", "Not creatable directly, use the liveUSBData instance instead")
+ qmlRegisterUncreatableType(ReleaseWriter, "LiveUSB", 1, 0, "Writer", "Not creatable directly, use the liveUSBData instance instead")
qmlRegisterUncreatableType(Release, "LiveUSB", 1, 0, "Release", "Not creatable directly, use the liveUSBData instance instead")
+ qmlRegisterUncreatableType(USBDrive, "LiveUSB", 1, 0, "Drive", "Not creatable directly, use the liveUSBData instance instead")
qmlRegisterUncreatableType(LiveUSBData, "LiveUSB", 1, 0, "Data", "Use the liveUSBData root instance")
view = QQmlApplicationEngine()
self.data = LiveUSBData(opts)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/tails-installer.git
More information about the Pkg-privacy-commits
mailing list