Port DeviceManager to enum class
This commit is contained in:
@@ -326,12 +326,12 @@ QVariant DeviceManager::data(const QModelIndex &idx, int role) const {
|
|||||||
return ((device_info->BestBackend() && device_info->BestBackend()->lister_) ? device_info->BestBackend()->lister_->DeviceFreeSpace(device_info->BestBackend()->unique_id_) : QVariant());
|
return ((device_info->BestBackend() && device_info->BestBackend()->lister_) ? device_info->BestBackend()->lister_->DeviceFreeSpace(device_info->BestBackend()->unique_id_) : QVariant());
|
||||||
|
|
||||||
case Role_State:
|
case Role_State:
|
||||||
if (device_info->device_) return State_Connected;
|
if (device_info->device_) return QVariant::fromValue(State::Connected);
|
||||||
if (device_info->BestBackend() && device_info->BestBackend()->lister_) {
|
if (device_info->BestBackend() && device_info->BestBackend()->lister_) {
|
||||||
if (device_info->BestBackend()->lister_->DeviceNeedsMount(device_info->BestBackend()->unique_id_)) return State_NotMounted;
|
if (device_info->BestBackend()->lister_->DeviceNeedsMount(device_info->BestBackend()->unique_id_)) return QVariant::fromValue(State::NotMounted);
|
||||||
return State_NotConnected;
|
return QVariant::fromValue(State::NotConnected);
|
||||||
}
|
}
|
||||||
return State_Remembered;
|
return QVariant::fromValue(State::Remembered);
|
||||||
|
|
||||||
case Role_UpdatingPercentage:
|
case Role_UpdatingPercentage:
|
||||||
if (device_info->task_percentage_ == -1) return QVariant();
|
if (device_info->task_percentage_ == -1) return QVariant();
|
||||||
|
|||||||
@@ -85,11 +85,11 @@ class DeviceManager : public SimpleTreeModel<DeviceInfo> {
|
|||||||
LastRole,
|
LastRole,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum State {
|
enum class State {
|
||||||
State_Remembered,
|
Remembered,
|
||||||
State_NotMounted,
|
NotMounted,
|
||||||
State_NotConnected,
|
NotConnected,
|
||||||
State_Connected,
|
Connected,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const int kDeviceIconSize;
|
static const int kDeviceIconSize;
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
#include "devicemanager.h"
|
#include "devicemanager.h"
|
||||||
#include "devicestatefiltermodel.h"
|
#include "devicestatefiltermodel.h"
|
||||||
|
|
||||||
DeviceStateFilterModel::DeviceStateFilterModel(QObject *parent, DeviceManager::State state)
|
DeviceStateFilterModel::DeviceStateFilterModel(QObject *parent, const DeviceManager::State state)
|
||||||
: QSortFilterProxyModel(parent),
|
: QSortFilterProxyModel(parent),
|
||||||
state_(state) {
|
state_(state) {
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ DeviceStateFilterModel::DeviceStateFilterModel(QObject *parent, DeviceManager::S
|
|||||||
|
|
||||||
bool DeviceStateFilterModel::filterAcceptsRow(const int row, const QModelIndex &parent) const {
|
bool DeviceStateFilterModel::filterAcceptsRow(const int row, const QModelIndex &parent) const {
|
||||||
Q_UNUSED(parent)
|
Q_UNUSED(parent)
|
||||||
return sourceModel()->index(row, 0).data(DeviceManager::Role_State).toInt() != state_ && sourceModel()->index(row, 0).data(DeviceManager::Role_CopyMusic).toBool();
|
return sourceModel()->index(row, 0).data(DeviceManager::Role_State).value<DeviceManager::State>() != state_ && sourceModel()->index(row, 0).data(DeviceManager::Role_CopyMusic).toBool();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceStateFilterModel::ProxyRowCountChanged(const QModelIndex &idx, const int first, const int last) {
|
void DeviceStateFilterModel::ProxyRowCountChanged(const QModelIndex &idx, const int first, const int last) {
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ class DeviceStateFilterModel : public QSortFilterProxyModel {
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit DeviceStateFilterModel(QObject *parent, DeviceManager::State state = DeviceManager::State_Remembered);
|
explicit DeviceStateFilterModel(QObject *parent, const DeviceManager::State state = DeviceManager::State::Remembered);
|
||||||
|
|
||||||
void setSourceModel(QAbstractItemModel *sourceModel) override;
|
void setSourceModel(QAbstractItemModel *sourceModel) override;
|
||||||
|
|
||||||
@@ -52,7 +52,7 @@ class DeviceStateFilterModel : public QSortFilterProxyModel {
|
|||||||
void ProxyRowCountChanged(const QModelIndex &idx, const int first, const int last);
|
void ProxyRowCountChanged(const QModelIndex &idx, const int first, const int last);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DeviceManager::State state_;
|
const DeviceManager::State state_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DEVICESTATEFILTERMODEL_H
|
#endif // DEVICESTATEFILTERMODEL_H
|
||||||
|
|||||||
@@ -128,19 +128,19 @@ void DeviceItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case DeviceManager::State_Remembered:
|
case DeviceManager::State::Remembered:
|
||||||
status_text = tr("Not connected");
|
status_text = tr("Not connected");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DeviceManager::State_NotMounted:
|
case DeviceManager::State::NotMounted:
|
||||||
status_text = tr("Not mounted - double click to mount");
|
status_text = tr("Not mounted - double click to mount");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DeviceManager::State_NotConnected:
|
case DeviceManager::State::NotConnected:
|
||||||
status_text = tr("Double click to open");
|
status_text = tr("Double click to open");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DeviceManager::State_Connected:{
|
case DeviceManager::State::Connected:{
|
||||||
QVariant song_count = idx.data(DeviceManager::Role_SongCount);
|
QVariant song_count = idx.data(DeviceManager::Role_SongCount);
|
||||||
if (song_count.isValid()) {
|
if (song_count.isValid()) {
|
||||||
int count = song_count.toInt();
|
int count = song_count.toInt();
|
||||||
|
|||||||
Reference in New Issue
Block a user