2020-09-20 20:33:16 +01:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2010 Volker Lanz <vl@fidra.de>
|
|
|
|
SPDX-FileCopyrightText: 2014-2020 Andrius Štikonas <andrius@stikonas.eu>
|
|
|
|
SPDX-FileCopyrightText: 2016 Chantara Tith <tith.chantara@gmail.com>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
*/
|
2015-06-04 01:29:22 +01:00
|
|
|
|
|
|
|
#include "core/devicescanner.h"
|
|
|
|
|
|
|
|
#include "backend/corebackend.h"
|
|
|
|
#include "backend/corebackendmanager.h"
|
|
|
|
|
|
|
|
#include "core/operationstack.h"
|
|
|
|
#include "core/device.h"
|
2016-06-08 16:50:40 +01:00
|
|
|
#include "core/diskdevice.h"
|
|
|
|
|
2016-09-10 22:08:21 +01:00
|
|
|
#include "fs/lvm2_pv.h"
|
|
|
|
|
2016-06-08 16:50:40 +01:00
|
|
|
#include "util/externalcommand.h"
|
2016-09-18 01:53:42 +01:00
|
|
|
|
2016-06-08 16:50:40 +01:00
|
|
|
#include <QRegularExpression>
|
2015-06-04 01:29:22 +01:00
|
|
|
|
|
|
|
/** Constructs a DeviceScanner
|
2015-07-13 15:16:36 +01:00
|
|
|
@param ostack the OperationStack where the devices will be created
|
2015-06-04 01:29:22 +01:00
|
|
|
*/
|
|
|
|
DeviceScanner::DeviceScanner(QObject* parent, OperationStack& ostack) :
|
2015-07-13 15:16:36 +01:00
|
|
|
QThread(parent),
|
|
|
|
m_OperationStack(ostack)
|
2015-06-04 01:29:22 +01:00
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
setupConnections();
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void DeviceScanner::setupConnections()
|
|
|
|
{
|
2016-05-24 01:37:15 +01:00
|
|
|
connect(CoreBackendManager::self()->backend(), &CoreBackend::scanProgress, this, &DeviceScanner::progress);
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void DeviceScanner::clear()
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
operationStack().clearOperations();
|
|
|
|
operationStack().clearDevices();
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void DeviceScanner::run()
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
scan();
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void DeviceScanner::scan()
|
|
|
|
{
|
2020-09-15 02:36:46 +01:00
|
|
|
Q_EMIT progress(QString(), 0);
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
clear();
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2019-02-09 15:40:06 +00:00
|
|
|
const QList<Device*> deviceList = CoreBackendManager::self()->backend()->scanDevices(ScanFlag::includeLoopback);
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2016-08-11 14:26:54 +01:00
|
|
|
for (const auto &d : deviceList)
|
2016-06-01 21:00:31 +01:00
|
|
|
operationStack().addDevice(d);
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2016-08-14 16:23:17 +01:00
|
|
|
operationStack().sortDevices();
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
2016-06-08 16:50:40 +01:00
|
|
|
|