Enumerate drives in seperate thread

Ref #87
This commit is contained in:
Floris Bos 2020-07-02 23:31:20 +02:00
parent 6069e8f441
commit 755d7dc6ab
8 changed files with 115 additions and 23 deletions

View file

@ -20,6 +20,9 @@ DriveListModel::DriveListModel(QObject *parent)
{isScsiRole, "isScsi"},
{mountpointsRole, "mountpoints"}
};
// Enumerate drives in seperate thread, but process results in UI thread
connect(&_thread, SIGNAL(newDriveList(std::vector<Drivelist::DeviceDescriptor>)), SLOT(processDriveList(std::vector<Drivelist::DeviceDescriptor>)));
}
int DriveListModel::rowCount(const QModelIndex &) const
@ -45,11 +48,10 @@ QVariant DriveListModel::data(const QModelIndex &index, int role) const
return _drivelist.values().at(row)->property(propertyName);
}
void DriveListModel::refreshDriveList()
void DriveListModel::processDriveList(std::vector<Drivelist::DeviceDescriptor> l)
{
bool changes = false;
bool filterSystemDrives = DRIVELIST_FILTER_SYSTEM_DRIVES;
auto l = Drivelist::ListStorageDevices();
QSet<QString> drivesInNewList;
for (auto &i: l)
@ -117,3 +119,13 @@ void DriveListModel::refreshDriveList()
if (changes)
endResetModel();
}
void DriveListModel::startPolling()
{
_thread.start();
}
void DriveListModel::stopPolling()
{
_thread.stop();
}