diff --git a/src/devicekiosk.py b/src/devicekiosk.py index 83ee07d..8cae00e 100644 --- a/src/devicekiosk.py +++ b/src/devicekiosk.py @@ -11,6 +11,7 @@ import zipfile import traceback import subprocess +import uuid from PySide6.QtGui import QGuiApplication from PySide6.QtQml import QQmlApplicationEngine @@ -54,6 +55,7 @@ class UI(QObject): showErrorPageSignal = Signal(None) showFinishSignal = Signal(None) showEOYReturnSignal = Signal(None) + showEOYStartSignal = Signal(None) firstName = "" lastName = "" @@ -220,6 +222,11 @@ def submitEOYReturn(self, returnInfo): self.addToReturnFile(returnSerial, chargerReturned) self.showEOYReturnSignal.emit() + @Slot('QString') + def submitEOYFinish(self, returnEmail): + self.emailEOYReturnFiles(returnEmail) + self.archiveReturns() + self.showEOYStartSignal.emit() def postToZenDesk(self): self.errorMessage = "" @@ -273,6 +280,34 @@ def sendEmail(self): self.errorMessage = ex s.close() + def emailEOYReturnFiles(self, returnAddress): + msg = EmailMessage() + msg['Subject'] = 'EOY Return Files' + body = "EOY Return Files" + msg.set_content(body) + attachmentFolder = os.path.dirname(os.path.abspath(__file__)) + # files = + for file in os.listdir(attachmentFolder): + if file.endswith(".csv"): + with open(os.path.join(attachmentFolder, file), 'rb') as content_file: + print(file) + content = content_file.read() + msg.add_attachment(content, maintype='application', subtype='txt', filename=str(file)) + # email.add_attachment(content, maintype='application', subtype='pdf', filename='example.pdf') + msg['From'] = self.config["smtp_user"] + msg['To'] = "asher@tolland.k12.ct.us, " + returnAddress + # Send the message via Gmail SMTP server + s = smtplib.SMTP("smtp.gmail.com", 587) + s.ehlo() + s.starttls() + s.login(self.config["smtp_user"], self.config["smtp_password"]) + try: + s.send_message(msg) + except smtplib.SMTPException as ex: + self.errorMessage = ex + print("Email error " + ex) + s.close() + def addToReturnFile(self, serial, returnedCharger): print("Adding " + serial + " to return file, with charger: " + str(returnedCharger)) filename = "eoy-returns-" + str(datetime.date.today()) + ".csv" @@ -287,7 +322,15 @@ def addToReturnFile(self, serial, returnedCharger): with open(returnsFile, 'a') as f: f.writelines(serial + "," + str(returnedCharger) + "\n") f.close() - + + def archiveReturns(self): + workingDir = os.path.dirname(os.path.abspath(__file__)) + archiveDir = os.path.join(workingDir, "return-archive", str(uuid.uuid4())) + if not os.path.exists(archiveDir): + os.makedirs(archiveDir) + for file in os.listdir(workingDir): + if file.endswith(".csv"): + shutil.move(os.path.join(workingDir, file), archiveDir) if __name__ == "__main__": QGuiApplication.setAttribute(Qt.AA_EnableHighDpiScaling, True) #enable highdpi scaling diff --git a/src/qml/EOYFinish.qml b/src/qml/EOYFinish.qml new file mode 100644 index 0000000..6ad25a4 --- /dev/null +++ b/src/qml/EOYFinish.qml @@ -0,0 +1,103 @@ +import QtQuick +import QtQuick.Window +import QtQuick.Controls +import QtQuick.Layouts + +Item { + + function verifyForm() { + if (inputEmail.text.toString().length > 0) { + btnSubmit.enabled = true + } + else { + btnSubmit.enabled = false + } + } + + function setFocus() { + inputEmail.focus = true + inputEmail.forceActiveFocus() + } + + property var chargerReturned: true + + + + ColumnLayout { + anchors.fill: parent + // spacing: 2 + + Text { + id: txtHeader + Layout.fillWidth: true + Layout.fillHeight: true + + text: "Enter an email address to receive the return files.\nEmail will also be sent to Candace de Loureiro.\nFiles will be backed up this computer in the event something goes wrong." + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + wrapMode: Text.WordWrap + font.pointSize: 30 + + } + + // AnimatedImage { + // id: image + // Layout.alignment: Qt.AlignHCenter + // source: "../images/dropoff.gif" + // fillMode: Image.Image.PreserveAspectCrop + // } + + TextField { + id: inputEmail + placeholderText: qsTr("Email Address") + font.pointSize: 20 + Layout.fillWidth: true + Layout.fillHeight: true + horizontalAlignment: TextInput.AlignHCenter + focus: true + onTextChanged: { + verifyForm() + } + + Component.onCompleted: { + this.focus = true + this.forceActiveFocus() + } + } + + Button { + id: btnSubmit + text: "Submit Returns" + enabled: false + font.pointSize: 50 + Layout.fillWidth: true + Layout.fillHeight: true + + onClicked: { + ui.submitEOYFinish(inputEmail.text) + } + } + + Button { + id: btnMenu + text: "Return to EOY Menu" + enabled: true + font.pointSize: 20 + Layout.fillWidth: true + Layout.fillHeight: true + + onClicked: { + contentFrame.push(Qt.createComponent("EOYStart.qml")) + } + } + + } + // Setting focus any other way doesn't seem to work. + // Kind of kludge, but works + Timer { + interval: 100 + running: true + repeat: false + onTriggered: setFocus() + } +} diff --git a/src/qml/EOYReturn.qml b/src/qml/EOYReturn.qml index a0505cc..8879ac9 100644 --- a/src/qml/EOYReturn.qml +++ b/src/qml/EOYReturn.qml @@ -38,12 +38,6 @@ Item { btnChargerNoText.color = "white" btnChargerNoRect.color = "red" } - - function listProperty(item) - { - for (var p in item) - console.log(p + ": " + item[p]); - } ColumnLayout { anchors.fill: parent @@ -165,9 +159,7 @@ Item { } } } - } - - + } Button { id: btnSubmit @@ -182,6 +174,19 @@ Item { ui.submitEOYReturn(returnInfo) } } + + Button { + id: btnMenu + text: "Return to EOY Menu" + enabled: true + font.pointSize: 20 + Layout.fillWidth: true + Layout.fillHeight: true + + onClicked: { + contentFrame.push(Qt.createComponent("EOYStart.qml")) + } + } } // Setting focus any other way doesn't seem to work. diff --git a/src/qml/EOYStart.qml b/src/qml/EOYStart.qml new file mode 100644 index 0000000..86e8fbf --- /dev/null +++ b/src/qml/EOYStart.qml @@ -0,0 +1,59 @@ +import QtQuick +import QtQuick.Window +import QtQuick.Controls +import QtQuick.Layouts + +Item { + ColumnLayout { + anchors.fill: parent + // spacing: 2 + + Text { + id: txtIntro + Layout.fillWidth: true + Layout.fillHeight: true + + text: "EOY Return" + // anchors.fill: self + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + wrapMode: Text.WordWrap + font.pointSize: 30 + // fontSizeMode: Text.Fit + // minimumPixelSize: 30 + // font.pixelSize: 1000 + + // anchors.centerIn: self + } + + // Image { + // id: image + // width: 100 + // height: 100 + // source: "../images/logo.png" + // Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter + // fillMode: Image.PreserveAspectFit + // } + + Button { + id: btnDropOff + text: "Begin Returns" + font.pointSize: 50 + Layout.fillWidth: true + Layout.fillHeight: true + onClicked: { + contentFrame.push(Qt.createComponent("EOYReturn.qml")) + } + } + Button { + id: btnPickUp + text: "Submit Saved Returns" + font.pointSize: 50 + Layout.fillWidth: true + Layout.fillHeight: true + onClicked: { + contentFrame.push(Qt.createComponent("EOYFinish.qml")) + } + } + } +} diff --git a/src/qml/Main.qml b/src/qml/Main.qml index 28e35cf..216bd1a 100644 --- a/src/qml/Main.qml +++ b/src/qml/Main.qml @@ -77,7 +77,12 @@ ApplicationWindow { function onShowEOYReturnSignal() { // contentFrame.clear() contentFrame.push(Qt.createComponent("EOYReturn.qml")) - } + } + + function onShowEOYStartSignal() { + // contentFrame.clear() + contentFrame.push(Qt.createComponent("EOYStart.qml")) + } } // Automatically go to a non-standard kiosk mode start page @@ -90,7 +95,7 @@ ApplicationWindow { break; case 2: // EOY Return Only Mode - contentFrame.push(Qt.createComponent("EOYReturn.qml")) + contentFrame.push(Qt.createComponent("EOYStart.qml")) default: break; }