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