Select device using a command line option

pass --device=/dev/sda to select that device

BUG: 43485
This commit is contained in:
Tomaz Canabrava 2021-11-30 10:19:39 -03:00
parent a577f8a0b8
commit 479c3f4678
3 changed files with 26 additions and 2 deletions

View File

@ -1336,3 +1336,15 @@ void MainWindow::checkFileSystemSupport()
xi18nc("@title:window", "Missing File System Support Packages"),
QStringLiteral("showInformationOnMissingFileSystemSupport"), KMessageBox::Notify | KMessageBox::AllowLink);
}
void MainWindow::setCurrentDeviceByName(const QString& name)
{
// TODO: Port KPartitionManager away from KMessageBox into KMessageWidget.
// TODO: setSelectedDevice from m_ListDevices is not using a device name, but
// just issuing a match query on a string list, this will produce false results.
if (!m_ListDevices->setSelectedDevice(name)) {
KMessageBox::error(this,
xi18nc("@info device should be inside of /dev", "Unrecognized device \"%1\" ", name),
xi18nc("@title:window", "Error While Importing Partition Table"));
}
}

View File

@ -44,6 +44,9 @@ class MainWindow : public KXmlGuiWindow, public Ui::MainWindowBase
public:
explicit MainWindow(QWidget* parent = nullptr);
// for instance `/dev/sda`
void setCurrentDeviceByName(const QString& name);
Q_SIGNALS:
void settingsChanged();
void scanFinished();

View File

@ -16,6 +16,7 @@
#include <QApplication>
#include <QCommandLineParser>
#include <QCommandLineOption>
#include <KAboutData>
#include <KCrash>
@ -57,7 +58,9 @@ int Q_DECL_IMPORT main(int argc, char* argv[])
QCommandLineParser parser;
aboutData.setupCommandLine(&parser);
// FIXME parser.addPositionalArgument(QStringLiteral("device"), xi18nc("@info:shell", "Device(s) to manage"), QStringLiteral("[device...]"));
QCommandLineOption deviceOption({QStringLiteral("device")}, xi18nc("@info:shell", "Device to manage"), QStringLiteral("device"));
parser.addOption(deviceOption);
parser.process(app);
aboutData.processCommandLine(&parser);
@ -71,8 +74,14 @@ int Q_DECL_IMPORT main(int argc, char* argv[])
if (!loadBackend())
return 0;
const QString selectedDevice = parser.value(deviceOption);
MainWindow* mainWindow = new MainWindow();
Q_UNUSED(mainWindow)
QObject::connect(mainWindow, &MainWindow::scanFinished, mainWindow, [mainWindow, selectedDevice] {
if (selectedDevice.length()) {
mainWindow->setCurrentDeviceByName(selectedDevice);
}
});
return app.exec();
}