Play-/Source/ui_unix/vfsmodel.cpp

108 lines
2 KiB
C++
Raw Normal View History

2016-09-06 00:03:02 +01:00
#include "vfsmodel.h"
#include "vfsmanagerdialog.h"
2017-12-21 18:21:44 -05:00
VFSModel::VFSModel(QObject* parent)
: QAbstractTableModel(parent)
2016-09-06 00:03:02 +01:00
{
2017-12-21 18:21:44 -05:00
SetupDevices();
2016-09-06 00:03:02 +01:00
}
VFSModel::~VFSModel()
{
2017-12-21 18:21:44 -05:00
for(int i = 0; i < m_devices.size(); i++)
{
delete m_devices.at(i);
}
2016-09-06 00:03:02 +01:00
}
2017-12-21 18:21:44 -05:00
int VFSModel::rowCount(const QModelIndex& /*parent*/) const
2016-09-06 00:03:02 +01:00
{
2017-12-21 18:21:44 -05:00
return m_devices.size();
2016-09-06 00:03:02 +01:00
}
2017-12-21 18:21:44 -05:00
int VFSModel::columnCount(const QModelIndex& /*parent*/) const
2016-09-06 00:03:02 +01:00
{
2017-12-21 18:21:44 -05:00
if(m_devices.size() > 0)
{
return 3;
}
else
{
return 0;
}
2016-09-06 00:03:02 +01:00
}
2017-12-21 18:21:44 -05:00
QVariant VFSModel::data(const QModelIndex& index, int role) const
2016-09-06 00:03:02 +01:00
{
2017-12-21 18:21:44 -05:00
if(role == Qt::DisplayRole)
{
CDevice* m_device = m_devices.at(index.row());
const char* val = "";
switch(index.column())
{
case 0:
val = m_device->GetDeviceName();
break;
case 1:
val = m_device->GetBindingType();
break;
case 2:
val = m_device->GetBinding();
break;
}
return QVariant(val);
}
return QVariant();
2016-09-06 00:03:02 +01:00
}
2016-08-10 16:42:37 +01:00
void VFSModel::SetupDevices()
2016-09-06 00:03:02 +01:00
{
2017-12-21 18:21:44 -05:00
m_devices[0] = new CDirectoryDevice("mc0", "ps2.mc0.directory");
m_devices[1] = new CDirectoryDevice("mc1", "ps2.mc1.directory");
m_devices[2] = new CDirectoryDevice("host", "ps2.host.directory");
m_devices[3] = new CCdrom0Device();
2016-09-06 00:03:02 +01:00
}
2017-12-21 18:21:44 -05:00
bool VFSModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant& value, int role)
2016-09-06 00:03:02 +01:00
{
2017-12-21 18:21:44 -05:00
if(orientation == Qt::Horizontal)
{
if(role == Qt::DisplayRole)
{
m_h_header.insert(section, value);
return true;
}
}
return QAbstractTableModel::setHeaderData(section, orientation, value, role);
2016-09-06 00:03:02 +01:00
}
QVariant VFSModel::headerData(int section, Qt::Orientation orientation, int role) const
{
2017-12-21 18:21:44 -05:00
if(orientation == Qt::Horizontal)
{
if(role == Qt::DisplayRole)
{
if(section < m_h_header.size())
{
return m_h_header.at(section);
}
}
}
2016-09-06 00:03:02 +01:00
2017-12-21 18:21:44 -05:00
return QAbstractTableModel::headerData(section, orientation, role);
2016-09-06 00:03:02 +01:00
}
2017-12-21 18:21:44 -05:00
void VFSModel::DoubleClicked(const QModelIndex& index, QWidget* parent)
2016-09-06 00:03:02 +01:00
{
2017-12-21 18:21:44 -05:00
CDevice* m_device = m_devices.at(index.row());
m_device->RequestModification(parent);
2016-09-06 00:03:02 +01:00
}
void VFSModel::Save()
{
2017-12-21 18:21:44 -05:00
for(int i = 0; i < m_devices.size(); i++)
{
m_devices.at(i)->Save();
}
2016-09-06 00:03:02 +01:00
}