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
|
|
|
|
2016-07-20 15:43:12 +08:00
|
|
|
m_centeralLayout(new QVBoxLayout),
|
|
|
|
m_centeralWidget(new QWidget),
|
|
|
|
|
2016-07-19 11:21:29 +08:00
|
|
|
m_diskInter(new DBusDiskMount(this))
|
|
|
|
{
|
2016-07-20 15:43:12 +08:00
|
|
|
m_centeralWidget->setLayout(m_centeralLayout);
|
|
|
|
m_centeralWidget->setFixedWidth(WIDTH);
|
|
|
|
|
|
|
|
setWidget(m_centeralWidget);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DiskControlWidget::diskListChanged()
|
|
|
|
{
|
|
|
|
m_diskInfoList = m_diskInter->diskList();
|
|
|
|
|
2016-07-20 16:30:56 +08:00
|
|
|
while (QLayoutItem *item = m_centeralLayout->takeAt(0))
|
|
|
|
{
|
|
|
|
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-07-20 15:43:12 +08:00
|
|
|
for (auto info : m_diskInfoList)
|
|
|
|
{
|
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);
|
|
|
|
|
2016-07-20 15:43:12 +08:00
|
|
|
m_centeralLayout->addWidget(item);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
m_centeralWidget->setFixedHeight(contentHeight);
|
|
|
|
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;
|
|
|
|
}
|