Play-/Source/ui_unix/vfsmodel.cpp

109 lines
2.1 KiB
C++
Raw Normal View History

2016-09-06 00:03:02 +01:00
#include "vfsmodel.h"
#include "vfsmanagerdialog.h"
2017-12-22 16:29:30 -05:00
#include "PS2VM_Preferences.h"
2016-09-06 00:03:02 +01:00
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)
{
2018-01-09 11:42:02 -05:00
auto device = m_devices.at(index.row());
std::string val;
2017-12-21 18:21:44 -05:00
switch(index.column())
{
case 0:
2018-01-09 11:42:02 -05:00
val = device->GetDeviceName();
2017-12-21 18:21:44 -05:00
break;
case 1:
2018-01-09 11:42:02 -05:00
val = device->GetBindingType();
2017-12-21 18:21:44 -05:00
break;
case 2:
2018-01-09 11:42:02 -05:00
val = device->GetBinding();
2017-12-21 18:21:44 -05:00
break;
}
2018-01-09 11:42:02 -05:00
return QVariant(val.c_str());
2017-12-21 18:21:44 -05:00
}
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-22 16:29:30 -05:00
m_devices[0] = new CDirectoryDevice("mc0", PREF_PS2_MC0_DIRECTORY);
m_devices[1] = new CDirectoryDevice("mc1", PREF_PS2_MC1_DIRECTORY);
m_devices[2] = new CDirectoryDevice("host", PREF_PS2_HOST_DIRECTORY);
2017-12-21 18:21:44 -05:00
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
}