2016-07-19 11:21:29 +08:00
|
|
|
#include "diskcontrolwidget.h"
|
2016-07-20 15:43:12 +08:00
|
|
|
#include "diskcontrolitem.h"
|
|
|
|
|
|
|
|
#define WIDTH 300
|
2016-07-19 11:21:29 +08:00
|
|
|
|
|
|
|
DiskControlWidget::DiskControlWidget(QWidget *parent)
|
2016-07-19 15:08:16 +08:00
|
|
|
: QScrollArea(parent),
|
2016-07-19 11:21:29 +08:00
|
|
|
|
2017-02-06 22:25:47 +08:00
|
|
|
m_centralLayout(new QVBoxLayout),
|
|
|
|
m_centralWidget(new QWidget),
|
2016-07-20 15:43:12 +08:00
|
|
|
|
2016-07-19 11:21:29 +08:00
|
|
|
m_diskInter(new DBusDiskMount(this))
|
|
|
|
{
|
2017-02-06 22:25:47 +08:00
|
|
|
m_centralWidget->setLayout(m_centralLayout);
|
|
|
|
m_centralWidget->setFixedWidth(WIDTH);
|
2016-07-20 15:43:12 +08:00
|
|
|
|
2017-02-06 22:25:47 +08:00
|
|
|
setWidget(m_centralWidget);
|
2016-07-20 15:43:12 +08:00
|
|
|
setFixedWidth(WIDTH);
|
2016-07-19 15:08:16 +08:00
|
|
|
setFrameStyle(QFrame::NoFrame);
|
|
|
|
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
setStyleSheet("background-color:transparent;");
|
2016-07-19 11:21:29 +08:00
|
|
|
|
|
|
|
connect(m_diskInter, &DBusDiskMount::DiskListChanged, this, &DiskControlWidget::diskListChanged);
|
2016-08-04 16:02:40 +08:00
|
|
|
connect(m_diskInter, &DBusDiskMount::Error, this, &DiskControlWidget::unmountFinished);
|
2016-07-19 11:21:29 +08:00
|
|
|
|
|
|
|
QMetaObject::invokeMethod(this, "diskListChanged", Qt::QueuedConnection);
|
|
|
|
}
|
|
|
|
|
2016-09-22 14:31:38 +08:00
|
|
|
void DiskControlWidget::unmountAll()
|
|
|
|
{
|
|
|
|
for (auto disk : m_diskInfoList)
|
|
|
|
unmountDisk(disk.m_id);
|
|
|
|
}
|
|
|
|
|
2016-07-19 11:21:29 +08:00
|
|
|
void DiskControlWidget::diskListChanged()
|
|
|
|
{
|
2016-11-08 15:36:43 +08:00
|
|
|
DiskInfoList diskList = m_diskInter->diskList();
|
2016-07-19 11:21:29 +08:00
|
|
|
|
2017-02-06 22:25:47 +08:00
|
|
|
while (QLayoutItem *item = m_centralLayout->takeAt(0))
|
2016-07-20 16:30:56 +08:00
|
|
|
{
|
|
|
|
delete item->widget();
|
|
|
|
delete item;
|
|
|
|
}
|
2016-07-20 15:43:12 +08:00
|
|
|
|
2016-07-20 16:30:56 +08:00
|
|
|
int mountedCount = 0;
|
2016-11-08 15:36:43 +08:00
|
|
|
for (auto info : diskList)
|
2016-07-20 15:43:12 +08:00
|
|
|
{
|
2016-07-20 16:30:56 +08:00
|
|
|
if (info.m_mountPoint.isEmpty())
|
|
|
|
continue;
|
|
|
|
else
|
|
|
|
++mountedCount;
|
|
|
|
|
2016-07-20 15:43:12 +08:00
|
|
|
DiskControlItem *item = new DiskControlItem(info, this);
|
2016-07-20 16:30:56 +08:00
|
|
|
|
|
|
|
connect(item, &DiskControlItem::requestUnmount, this, &DiskControlWidget::unmountDisk);
|
|
|
|
|
2017-02-06 22:25:47 +08:00
|
|
|
m_centralLayout->addWidget(item);
|
2016-11-08 15:36:43 +08:00
|
|
|
m_diskInfoList.append(info);
|
2016-07-20 15:43:12 +08:00
|
|
|
}
|
|
|
|
|
2016-07-20 16:30:56 +08:00
|
|
|
emit diskCountChanged(mountedCount);
|
|
|
|
|
|
|
|
const int contentHeight = mountedCount * 70;
|
2016-08-30 15:46:08 +08:00
|
|
|
const int maxHeight = std::min(contentHeight, 70 * 6);
|
2016-07-20 15:43:12 +08:00
|
|
|
|
2017-02-06 22:25:47 +08:00
|
|
|
m_centralWidget->setFixedHeight(contentHeight);
|
2016-07-20 15:43:12 +08:00
|
|
|
setFixedHeight(maxHeight);
|
2016-07-19 11:21:29 +08:00
|
|
|
}
|
2016-07-20 16:30:56 +08:00
|
|
|
|
|
|
|
void DiskControlWidget::unmountDisk(const QString &diskId) const
|
|
|
|
{
|
|
|
|
m_diskInter->Unmount(diskId);
|
|
|
|
}
|
2016-08-04 16:02:40 +08:00
|
|
|
|
|
|
|
void DiskControlWidget::unmountFinished(const QString &uuid, const QString &info)
|
|
|
|
{
|
|
|
|
qDebug() << uuid << info;
|
|
|
|
}
|