kpmcore/src/core/devicescanner.cpp

64 lines
1.4 KiB
C++
Raw Normal View History

/*
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
*/
#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"
#include "fs/lvm2_pv.h"
2016-06-08 16:50:40 +01:00
#include "util/externalcommand.h"
2016-06-08 16:50:40 +01:00
#include <QRegularExpression>
/** Constructs a DeviceScanner
2015-07-13 15:16:36 +01:00
@param ostack the OperationStack where the devices will be created
*/
DeviceScanner::DeviceScanner(QObject* parent, OperationStack& ostack) :
2015-07-13 15:16:36 +01:00
QThread(parent),
m_OperationStack(ostack)
{
2015-07-13 15:16:36 +01:00
setupConnections();
}
void DeviceScanner::setupConnections()
{
connect(CoreBackendManager::self()->backend(), &CoreBackend::scanProgress, this, &DeviceScanner::progress);
}
void DeviceScanner::clear()
{
2015-07-13 15:16:36 +01:00
operationStack().clearOperations();
operationStack().clearDevices();
}
void DeviceScanner::run()
{
2015-07-13 15:16:36 +01:00
scan();
}
void DeviceScanner::scan()
{
2020-09-15 02:36:46 +01:00
Q_EMIT progress(QString(), 0);
2015-07-13 15:16:36 +01:00
clear();
const QList<Device*> deviceList = CoreBackendManager::self()->backend()->scanDevices(ScanFlag::includeLoopback);
for (const auto &d : deviceList)
2016-06-01 21:00:31 +01:00
operationStack().addDevice(d);
operationStack().sortDevices();
}
2016-06-08 16:50:40 +01:00