diff --git a/src/OptionsPopup.qml b/src/OptionsPopup.qml index ee814df..0791418 100644 --- a/src/OptionsPopup.qml +++ b/src/OptionsPopup.qml @@ -31,7 +31,7 @@ Window { ColumnLayout { id: cl - spacing: 20 + spacing: 10 anchors.fill: parent ScrollView { @@ -69,6 +69,11 @@ Window { TabButton { text: qsTr("General") + onClicked: { + if (chkSetUser.checked && !fieldUserPassword.length) { + fieldUserPassword.forceActiveFocus() + } + } } TabButton { text: qsTr("Services") @@ -101,6 +106,7 @@ Window { id: fieldHostname enabled: chkHostname.checked text: "raspberrypi" + selectByMouse: true validator: RegularExpressionValidator { regularExpression: /[0-9A-Za-z][0-9A-Za-z-]{0,62}/ } } Text { @@ -109,7 +115,6 @@ Window { } } - ImCheckBox { id: chkSetUser text: qsTr("Set username and password") @@ -117,6 +122,9 @@ Window { if (!checked && chkSSH.checked && radioPasswordAuthentication.checked) { checked = true; } + if (checked && !fieldUserPassword.length) { + fieldUserPassword.forceActiveFocus() + } } } @@ -138,6 +146,7 @@ Window { id: fieldUserName text: "pi" Layout.minimumWidth: 200 + selectByMouse: true property bool indicateError: false onTextEdited: { @@ -153,6 +162,7 @@ Window { id: fieldUserPassword echoMode: TextInput.Password Layout.minimumWidth: 200 + selectByMouse: true property bool alreadyCrypted: false property bool indicateError: false @@ -198,19 +208,13 @@ Window { TextField { id: fieldWifiSSID Layout.minimumWidth: 200 + selectByMouse: true property bool indicateError: false onTextEdited: { indicateError = false } } - ImCheckBox { - id: chkWifiSSIDHidden - Layout.columnSpan: 2 - text: qsTr("Hidden SSID") - checked: false - } - Text { text: qsTr("Password:") color: parent.enabled ? (fieldWifiPassword.indicateError ? "red" : "black") : "grey" @@ -218,6 +222,7 @@ Window { TextField { id: fieldWifiPassword Layout.minimumWidth: 200 + selectByMouse: true echoMode: chkShowPassword.checked ? TextInput.Normal : TextInput.Password property bool indicateError: false onTextEdited: { @@ -225,11 +230,20 @@ Window { } } - ImCheckBox { - id: chkShowPassword + RowLayout { Layout.columnSpan: 2 - text: qsTr("Show password") - checked: true + + ImCheckBox { + id: chkShowPassword + text: qsTr("Show password") + checked: true + } + ImCheckBox { + id: chkWifiSSIDHidden + Layout.columnSpan: 2 + text: qsTr("Hidden SSID") + checked: false + } } Text { @@ -289,9 +303,6 @@ Window { } if (radioPasswordAuthentication.checked) { chkSetUser.checked = true - if (!fieldUserPassword.length) { - fieldUserPassword.forceActiveFocus() - } } } } @@ -339,6 +350,7 @@ Window { id: fieldPublicKey wrapMode: TextEdit.WrapAnywhere Layout.minimumWidth: 400 + selectByMouse: true } ImButton { diff --git a/src/imagewriter.cpp b/src/imagewriter.cpp index 92d43d7..9253642 100644 --- a/src/imagewriter.cpp +++ b/src/imagewriter.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #endif #ifdef QT_NO_WIDGETS @@ -790,16 +791,19 @@ QByteArray ImageWriter::getUsbSourceOSlist() #endif } +QString ImageWriter::_sshKeyDir() +{ + return QDir::homePath()+"/.ssh"; +} + QString ImageWriter::_pubKeyFileName() { - return QDir::homePath()+"/.ssh/id_rsa.pub"; + return _sshKeyDir()+"/id_rsa.pub"; } QString ImageWriter::_privKeyFileName() { - QString fn = _pubKeyFileName(); - fn.chop(4); - return fn; + return _sshKeyDir()+"/id_rsa"; } QString ImageWriter::getDefaultPubKey() @@ -821,18 +825,45 @@ bool ImageWriter::hasPubKey() return QFile::exists(_pubKeyFileName()); } +QString ImageWriter::_sshKeyGen() +{ +#ifdef Q_OS_WIN + QString windir = QProcessEnvironment::systemEnvironment().value("windir"); + return QDir::fromNativeSeparators(windir+"\\SysNative\\OpenSSH\\ssh-keygen.exe"); +#else + return "ssh-keygen"; +#endif +} + bool ImageWriter::hasSshKeyGen() { +#ifdef Q_OS_WIN + return QFile::exists(_sshKeyGen()); +#else return true; +#endif } void ImageWriter::generatePubKey() { if (!hasPubKey() && !QFile::exists(_privKeyFileName())) { + QDir dir; + QProcess proc; + QString progName = _sshKeyGen(); QStringList args; args << "-t" << "rsa" << "-f" << _privKeyFileName() << "-N" << ""; - QProcess::execute("ssh-keygen", args); + + if (!dir.exists(_sshKeyDir())) + { + qDebug() << "Creating" << _sshKeyDir(); + dir.mkdir(_sshKeyDir()); + } + + qDebug() << "Executing:" << progName << args; + proc.start(progName, args); + proc.waitForFinished(); + qDebug() << proc.readAll(); } } diff --git a/src/imagewriter.h b/src/imagewriter.h index ed0efa0..4328815 100644 --- a/src/imagewriter.h +++ b/src/imagewriter.h @@ -183,6 +183,8 @@ protected: void _parseCompressedFile(); QString _pubKeyFileName(); QString _privKeyFileName(); + QString _sshKeyDir(); + QString _sshKeyGen(); }; #endif // IMAGEWRITER_H