diff --git a/debian/changelog b/debian/changelog index 6bd0e37..cb2248b 100644 --- a/debian/changelog +++ b/debian/changelog @@ -12,5 +12,6 @@ kylin-assistant (1.0.0-0ubuntu1) bionic; urgency=low * Add Network. * Add memory rate. * Add cpu rate and idle rate. + * Add processes, resources and file system manager. - -- lixiang Thu, 21 Dec 2017 14:52:56 +0800 + -- lixiang Mon, 29 Jan 2018 17:54:44 +0800 diff --git a/plugins/systemmonitor/diskitem.cpp b/plugins/systemmonitor/diskitem.cpp deleted file mode 100644 index 2ec9fdc..0000000 --- a/plugins/systemmonitor/diskitem.cpp +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright (C) 2013 ~ 2018 National University of Defense Technology(NUDT) & Tianjin Kylin Ltd. - * - * Authors: - * Kobe Lee xiangli@ubuntukylin.com/kobe24_lixiang@126.com - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "diskitem.h" -#include "../widgets/mytristatebutton.h" - -#include -#include -#include - -DiskItem::DiskItem(QWidget *parent) - : QFrame(parent) - ,m_isHead(false) - ,m_isTail(false) - ,m_nameLabel(new QLabel) - ,m_mountLabel(new QLabel) - ,m_typeLabel(new QLabel) - ,m_totoalLabel(new QLabel) - ,m_availLabel(new QLabel) - ,m_usedLabel(new QLabel) - ,m_percentageLabel(new QLabel) - ,m_detailBtn(new MyTristateButton) -{ - this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); - this->setFixedHeight(36); - - QHBoxLayout *mainLayout = new QHBoxLayout; - mainLayout->setSpacing(0); - mainLayout->setMargin(0); - - mainLayout->setContentsMargins(20, 0, 10, 0); - mainLayout->addWidget(m_nameLabel); - mainLayout->addWidget(m_mountLabel); - mainLayout->addWidget(m_typeLabel); - mainLayout->addWidget(m_totoalLabel); - mainLayout->addWidget(m_availLabel); - mainLayout->addWidget(m_usedLabel); - mainLayout->addWidget(m_percentageLabel); - mainLayout->addSpacing(8); -// mainLayout->addStretch(); - mainLayout->addWidget(m_detailBtn); - setLayout(mainLayout); - - m_detailBtn->setObjectName("DiskDetailButton"); - connect(m_detailBtn, &MyTristateButton::clicked, this, [=] { - //TODO: show detail dialog - }); -} - -DiskItem::~DiskItem() -{ - delete m_nameLabel; - delete m_mountLabel; - delete m_typeLabel; - delete m_totoalLabel; - delete m_availLabel; - delete m_usedLabel; - delete m_percentageLabel; - delete m_detailBtn; -} - -void DiskItem::setIsHead(bool head) -{ - if (head == m_isHead) return; - m_isHead = head; - - style()->unpolish(this); - style()->polish(this); -} - -void DiskItem::setIsTail(bool tail) -{ - if (tail == m_isTail) return; - m_isTail = tail; - - style()->unpolish(this); - style()->polish(this); -} - -void DiskItem::setDevName(const QString &name) -{ - m_nameLabel->setText(name); - - setAccessibleName(name); -} - -void DiskItem::setMountDir(const QString &mountdir) -{ - m_mountLabel->setText(mountdir); -} - -void DiskItem::setDiskType(const QString &disktype) -{ - m_typeLabel->setText(disktype); -} - -void DiskItem::setTotalCapacity(const QString &totalcapacity) -{ - m_totoalLabel->setText(totalcapacity); -} - -void DiskItem::setAvailCapacity(const QString &availcapacity) -{ - m_availLabel->setText(availcapacity); -} - -void DiskItem::setUsedCapactiy(const QString &usedcapactiy) -{ - m_usedLabel->setText(usedcapactiy); -} - -void DiskItem::setPercentage(const QString &percentage) -{ - m_percentageLabel->setText(percentage); -} - -void DiskItem::mouseReleaseEvent(QMouseEvent *e) -{ - e->accept(); - - emit selected(); - emit clicked(); -} - diff --git a/plugins/systemmonitor/diskitem.h b/plugins/systemmonitor/diskitem.h deleted file mode 100644 index 7cd09ee..0000000 --- a/plugins/systemmonitor/diskitem.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (C) 2013 ~ 2018 National University of Defense Technology(NUDT) & Tianjin Kylin Ltd. - * - * Authors: - * Kobe Lee xiangli@ubuntukylin.com/kobe24_lixiang@126.com - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - - -#ifndef DISKITEM_H -#define DISKITEM_H - -#include -#include -#include -#include - -class MyTristateButton; - -class DiskItem : public QFrame -{ - Q_OBJECT - -public: - explicit DiskItem(QWidget *parent = 0); - ~DiskItem(); - - inline QString devName() const { return m_nameLabel->text(); } - void setDevName(const QString &name); - void setMountDir(const QString &mountdir); - void setDiskType(const QString &disktype); - void setTotalCapacity(const QString &totalcapacity); - void setAvailCapacity(const QString &availcapacity); - void setUsedCapactiy(const QString &usedcapactiy); - void setPercentage(const QString &percentage); - void setIsHead(bool head = true); - void setIsTail(bool tail = true); - -protected: - void mouseReleaseEvent(QMouseEvent *e); - -signals: - void clicked() const; - void selected() const; - void acceptNextPage() const; - -private: - QLabel *m_nameLabel; - QLabel *m_mountLabel; - QLabel *m_typeLabel; - QLabel *m_totoalLabel; - QLabel *m_availLabel; - QLabel *m_usedLabel; - QLabel *m_percentageLabel; - MyTristateButton *m_detailBtn; - bool m_isHead; - bool m_isTail; -}; - -#endif // DISKITEM_H - diff --git a/plugins/systemmonitor/diskitemlist.cpp b/plugins/systemmonitor/diskitemlist.cpp deleted file mode 100644 index b00740c..0000000 --- a/plugins/systemmonitor/diskitemlist.cpp +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Copyright (C) 2013 ~ 2018 National University of Defense Technology(NUDT) & Tianjin Kylin Ltd. - * - * Authors: - * Kobe Lee xiangli@ubuntukylin.com/kobe24_lixiang@126.com - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "diskitemlist.h" -#include "diskitem.h" - -#include -#include -#include - -DiskItemList::DiskItemList(QFrame *parent) : - QWidget(parent), - m_layout(new QVBoxLayout), - m_updateHTimer(new QTimer(this)), - m_updateHeadTimer(new QTimer(this)) -{ - m_layout->setMargin(0); - m_layout->setSpacing(1); - - m_updateHTimer->setSingleShot(true); - m_updateHTimer->setInterval(10); - - m_updateHeadTimer->setSingleShot(true); - m_updateHeadTimer->setInterval(10); - - connect(m_updateHTimer, &QTimer::timeout, this, &DiskItemList::updateHeight, Qt::QueuedConnection); - connect(m_updateHeadTimer, &QTimer::timeout, this, &DiskItemList::updateHeadTail, Qt::QueuedConnection); - - setLayout(m_layout); -} - -DiskItemList::~DiskItemList() -{ - -} - -void DiskItemList::appendItem(DiskItem *item) -{ - m_layout->insertWidget(m_layout->count(), item); - item->installEventFilter(this); - - m_updateHeadTimer->start(); - m_updateHTimer->start(); -} - -void DiskItemList::removeItem(DiskItem *item) -{ - m_layout->removeWidget(item); - item->removeEventFilter(this); - - m_updateHeadTimer->start(); - m_updateHTimer->start(); -} - -void DiskItemList::moveItem(DiskItem *item, const int index) -{ - const int oldIndex = m_layout->indexOf(item); - if (oldIndex == index) - return; - - m_layout->removeWidget(item); - m_layout->insertWidget(index, item); - - const int max = m_layout->count() - 1; - if (index == 0 || index == max || - oldIndex == 0 || oldIndex == max) - m_updateHeadTimer->start(); -} - -void DiskItemList::setSpacing(const int spaceing) -{ - m_layout->setSpacing(spaceing); - - m_updateHTimer->start(); -} - -int DiskItemList::itemCount() const -{ - return m_layout->count(); -} - -void DiskItemList::clear() -{ - const int index = 0; - const int count = m_layout->count(); - - for (int i(index); i != count; ++i) - { - QLayoutItem *item = m_layout->takeAt(index); - QWidget *w = item->widget(); - w->removeEventFilter(this); - w->setParent(nullptr); - delete item; - } - - m_updateHeadTimer->start(); - m_updateHTimer->start(); -} - -DiskItem *DiskItemList::getItem(int index) -{ - if(index < 0) - return NULL; - - if(index < itemCount()) - { - return qobject_cast(m_layout->itemAt(index)->widget()); - } - - return NULL; -} - -bool DiskItemList::eventFilter(QObject *, QEvent *event) -{ - switch (event->type()) - { - case QEvent::Show: - case QEvent::Hide: m_updateHeadTimer->start(); - case QEvent::Resize: m_updateHTimer->start(); break; - default:; - } - - return false; -} - -void DiskItemList::updateHeadTail() -{ - DiskItem *head = nullptr; - DiskItem *tail = nullptr; - - const int count = m_layout->count(); - for (int i(0); i != count; ++i) - { - DiskItem *item = qobject_cast(m_layout->itemAt(i)->widget()); - Q_ASSERT(item); - - if (!item->isVisible()) - continue; - - item->setIsHead(false); - item->setIsTail(false); - - if (!head) - head = item; - tail = item; - } - - if (head) - head->setIsHead(); - if (tail) - tail->setIsTail(); -} - -void DiskItemList::updateHeight() -{ - Q_ASSERT(sender() == m_updateHTimer); - - setFixedHeight(m_layout->sizeHint().height()); -} diff --git a/plugins/systemmonitor/diskitemlist.h b/plugins/systemmonitor/diskitemlist.h deleted file mode 100644 index 5ddcf89..0000000 --- a/plugins/systemmonitor/diskitemlist.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2013 ~ 2018 National University of Defense Technology(NUDT) & Tianjin Kylin Ltd. - * - * Authors: - * Kobe Lee xiangli@ubuntukylin.com/kobe24_lixiang@126.com - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - - -#ifndef DISKITEMLIST_H -#define DISKITEMLIST_H - -#include -#include - - -class QVBoxLayout; - -class DiskItem; - -class DiskItemList : public QWidget -{ - Q_OBJECT - -public: - explicit DiskItemList(QFrame *parent = 0); - explicit DiskItemList(const QString &title, QFrame *parent = 0); - ~DiskItemList(); - - DiskItem* getItem(int index); - void appendItem(DiskItem * item); - void removeItem(DiskItem * item); - void moveItem(DiskItem *item, const int index); - void setSpacing(const int spaceing); - - int itemCount() const; - void clear(); - -private: - bool eventFilter(QObject *, QEvent *event); - void updateHeadTail(); - -private slots: - void updateHeight(); - -private: - QVBoxLayout *m_layout; - QTimer *m_updateHTimer; - QTimer *m_updateHeadTimer; -}; - -#endif // DISKITEMLIST_H diff --git a/plugins/systemmonitor/diskmodel.cpp b/plugins/systemmonitor/diskmodel.cpp deleted file mode 100644 index 42e2895..0000000 --- a/plugins/systemmonitor/diskmodel.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (C) 2013 ~ 2018 National University of Defense Technology(NUDT) & Tianjin Kylin Ltd. - * - * Authors: - * Kobe Lee xiangli@ubuntukylin.com/kobe24_lixiang@126.com - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "diskmodel.h" - -#include - -DiskModel::DiskModel(QObject *parent) : - QObject(parent) -{ - -} - -DiskModel::~DiskModel() -{ - -} - -DiskInfo *DiskModel::getDiskInfo(const QString &devname) -{ - return m_diskInfoList.value(devname, nullptr); -} - -QList DiskModel::diskInfoList() const -{ - return m_diskInfoList.values(); -} - -void DiskModel::addDiskInfo(const QString &devname, DiskInfo *info) -{ - if (!m_diskInfoList.contains(devname)) { - m_diskInfoList[devname] = info; - emit oneDiskInfoAdded(info); - } -} - -void DiskModel::removeDiskInfo(const QString &devname) -{ - DiskInfo *info = getDiskInfo(devname); - m_diskInfoList.remove(devname); - - if (info) - emit oneDiskInfoRemoved(info); -} - -bool DiskModel::contains(const QString &devname) -{ - return m_diskInfoList.contains(devname); -} diff --git a/plugins/systemmonitor/diskinfo.cpp b/plugins/systemmonitor/filesystemdata.cpp similarity index 65% rename from plugins/systemmonitor/diskinfo.cpp rename to plugins/systemmonitor/filesystemdata.cpp index d31bd39..41cec50 100644 --- a/plugins/systemmonitor/diskinfo.cpp +++ b/plugins/systemmonitor/filesystemdata.cpp @@ -17,56 +17,61 @@ * along with this program. If not, see . */ -#include "diskinfo.h" +#include "filesystemdata.h" #include -DiskInfo::DiskInfo(QObject *parent) +FileSystemData::FileSystemData(QObject *parent) : QObject(parent) { } -const QString DiskInfo::devname() const +const QString FileSystemData::deviceName() const { return m_devName; } -void DiskInfo::setDevName(const QString &name) +void FileSystemData::setDevName(const QString &name) { if (name != m_devName) m_devName = name; } -const QString DiskInfo::mountdir() const +const QString FileSystemData::mountDir() const { return m_mountDir; } -const QString DiskInfo::disktype() const +const QString FileSystemData::diskType() const { return m_diskType; } -const QString DiskInfo::totalcapacity() const +const QString FileSystemData::totalCapacity() const { return m_totalCapacity; } -const QString DiskInfo::availcapacity() const +const QString FileSystemData::freeCapacity() const +{ + return m_freeCapacity; +} + +const QString FileSystemData::availCapacity() const { return m_availCapacity; } -const QString DiskInfo::usedcapactiy() const +const QString FileSystemData::usedCapactiy() const { return m_usedCapactiy; } -const QString DiskInfo::percentage() const +const int FileSystemData::usedPercentage() { return m_percentage; } -void DiskInfo::setOtherDiskInfo(QString mountDir, QString diskType, QString totalCapacity, QString availCapacity, QString usedCapactiy, QString percentage) +void FileSystemData::updateDiskInfo(QString mountDir, QString diskType, QString totalCapacity, QString freeCapacity, QString availCapacity, QString usedCapactiy, int percentage) { if (mountDir != m_mountDir) m_mountDir = mountDir; @@ -74,6 +79,8 @@ void DiskInfo::setOtherDiskInfo(QString mountDir, QString diskType, QString tota m_diskType = diskType; if (totalCapacity != m_totalCapacity) m_totalCapacity = totalCapacity; + if (freeCapacity != m_freeCapacity) + m_freeCapacity = freeCapacity; if (availCapacity != m_availCapacity) m_availCapacity = availCapacity; if (usedCapactiy != m_usedCapactiy) diff --git a/plugins/systemmonitor/diskinfo.h b/plugins/systemmonitor/filesystemdata.h similarity index 64% rename from plugins/systemmonitor/diskinfo.h rename to plugins/systemmonitor/filesystemdata.h index b4b6661..9b3fb17 100644 --- a/plugins/systemmonitor/diskinfo.h +++ b/plugins/systemmonitor/filesystemdata.h @@ -24,32 +24,35 @@ #include #include -class DiskInfo : public QObject +class FileSystemData : public QObject { Q_OBJECT public: - explicit DiskInfo(QObject *parent = 0); + explicit FileSystemData(QObject *parent = 0); - const QString devname() const; + const QString deviceName() const; void setDevName(const QString &name); - const QString mountdir() const; - const QString disktype() const; - const QString totalcapacity() const; - const QString availcapacity() const; - const QString usedcapactiy() const; - const QString percentage() const; - void setOtherDiskInfo(QString mountDir, QString diskType, QString totalCapacity, QString availCapacity, QString usedCapactiy, QString percentage); + const QString mountDir() const; + const QString diskType() const; + const QString totalCapacity() const; + const QString freeCapacity() const; + const QString availCapacity() const; + const QString usedCapactiy() const; + const int usedPercentage(); + + void updateDiskInfo(QString mountDir, QString diskType, QString totalCapacity, QString freeCapacity, QString availCapacity, QString usedCapactiy, int percentage); private: QString m_devName; QString m_mountDir; QString m_diskType; QString m_totalCapacity; + QString m_freeCapacity; QString m_availCapacity; QString m_usedCapactiy; - QString m_percentage; + int m_percentage; }; diff --git a/plugins/systemmonitor/filesystemdialog.cpp b/plugins/systemmonitor/filesystemdialog.cpp index 5e764bc..9de8922 100644 --- a/plugins/systemmonitor/filesystemdialog.cpp +++ b/plugins/systemmonitor/filesystemdialog.cpp @@ -24,16 +24,13 @@ #include #include -#include "diskitemlist.h" -#include "diskitem.h" -#include "diskmodel.h" -#include "diskinfo.h" +#include "filesystemdata.h" #include "filesystemworker.h" -FileSystemDialog::FileSystemDialog(QWidget *parent) +FileSystemDialog::FileSystemDialog(QList toBeDisplayedColumns, QSettings *settings, QWidget *parent) :QWidget(parent) - ,m_diskItemList(new DiskItemList) - ,m_monitorFile("/home/lixiang/testwatcher/1.c") + ,proSettings(settings) +// ,m_monitorFile("/home/lixiang/testwatcher/1.c") // ,m_monitorFile("/etc/mtab") { setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); @@ -43,42 +40,62 @@ FileSystemDialog::FileSystemDialog(QWidget *parent) this->setObjectName("FileSystemDialog"); - m_centralLayout = new QVBoxLayout; - m_centralLayout->addWidget(m_diskItemList); - m_centralLayout->setSpacing(10); - m_centralLayout->setMargin(0); + m_layout = new QVBoxLayout(this); + m_layout->setContentsMargins(0, 0, 0, 0); + m_layout->setSpacing(0); - setLayout(m_centralLayout); + m_fileSysListWidget = new FileSystemListWidget(toBeDisplayedColumns); + connect(m_fileSysListWidget, &FileSystemListWidget::rightMouseClickedItem, this, &FileSystemDialog::popupMenu, Qt::QueuedConnection); + connect(m_fileSysListWidget, SIGNAL(changeColumnVisible(int,bool,QList)), this, SIGNAL(changeColumnVisible(int,bool,QList))); + m_layout->addWidget(m_fileSysListWidget); - - m_diskModelList = new DiskModel; - connect(m_diskModelList, SIGNAL(oneDiskInfoAdded(DiskInfo*)), this, SLOT(addDiskInfoItem(DiskInfo*))); - connect(m_diskModelList, SIGNAL(oneDiskInfoRemoved(DiskInfo*)), this, SLOT(removeDiskInfoItemByDevName(DiskInfo*))); - - m_fileSystemWorker = new FileSystemWorker(m_diskModelList); + m_fileSystemWorker = new FileSystemWorker; m_fileSystemWorker->moveToThread(qApp->thread()); - m_diskModelList->moveToThread(qApp->thread()); - this->initFileSystemMonitor(); +// this->initFileSystemMonitor(); + + m_menu = new QMenu(); + m_refreshAction = new QAction(tr("Refresh"), this); + connect(m_refreshAction, &QAction::triggered, this, &FileSystemDialog::refreshFileSysList); + m_menu->addAction(m_refreshAction); + + this->refreshFileSysList(); } FileSystemDialog::~FileSystemDialog() { - m_fileSystemMonitor->removePath(m_monitorFile); - delete m_fileSystemMonitor; +// m_fileSystemMonitor->removePath(m_monitorFile); +// delete m_fileSystemMonitor; - m_diskModelList->deleteLater(); m_fileSystemWorker->deleteLater(); + delete m_fileSysListWidget; + delete m_refreshAction; + delete m_menu; + delete m_layout; +} - QList items = findChildren(); - for (DiskItem *item : items) { - m_diskItemList->removeItem(item); - item->deleteLater(); - } - if (m_diskItemList) { - delete m_diskItemList; - m_diskItemList = 0; +void FileSystemDialog::refreshFileSysList() +{ + + m_fileSystemWorker->onFileSystemListChanged(); + + + QList items; + for (FileSystemData *info : m_fileSystemWorker->diskInfoList()) { + FileSystemListItem *item = new FileSystemListItem(info); + items << item; } + m_fileSysListWidget->refreshFileSystemItems(items); +} + +void FileSystemDialog::popupMenu(QPoint pos) +{ + m_menu->exec(pos); +} + +FileSystemListWidget* FileSystemDialog::getFileSysView() +{ + return m_fileSysListWidget; } void FileSystemDialog::initFileSystemMonitor() { @@ -87,7 +104,7 @@ void FileSystemDialog::initFileSystemMonitor() { // int ret = inotify_rm_watch (fd, wd);*/ - m_fileSystemMonitor = new QFileSystemWatcher(this); + /*m_fileSystemMonitor = new QFileSystemWatcher(this); // m_fileSystemMonitor->addPath(m_monitorFile); QFileInfo info(m_monitorFile); m_fileSystemMonitor->addPath(info.absoluteFilePath()); @@ -95,7 +112,7 @@ void FileSystemDialog::initFileSystemMonitor() { connect(m_fileSystemMonitor, SIGNAL(directoryChanged(QString)), this, SLOT(onDirectoryChanged(QString))); connect(m_fileSystemMonitor, &QFileSystemWatcher::fileChanged, [=] (const QString &path) { qDebug()<< "file path===================="<appendItem(w); - w->setDevName(info->devname()); - w->setMountDir(info->mountdir()); - w->setDiskType(info->disktype()); - w->setTotalCapacity(info->totalcapacity()); - w->setAvailCapacity(info->availcapacity()); - w->setUsedCapactiy(info->usedcapactiy()); - w->setPercentage(info->percentage()); -} +//bool FileSystemDialog::event(QEvent *event) +//{ +// if (event->type() == QEvent::LayoutRequest) +// setFixedHeight(m_centralLayout->sizeHint().height()); -void FileSystemDialog::removeDiskInfoItemByDevName(DiskInfo *info) -{ - QList items = findChildren(); - for (DiskItem *item : items) { - if (item->devName() == info->devname()) { - m_diskItemList->removeItem(item); - item->deleteLater(); - break; - } - } -} - -bool FileSystemDialog::event(QEvent *event) -{ - if (event->type() == QEvent::LayoutRequest) - setFixedHeight(m_centralLayout->sizeHint().height()); - - return QWidget::event(event); -} +// return QWidget::event(event); +//} diff --git a/plugins/systemmonitor/filesystemdialog.h b/plugins/systemmonitor/filesystemdialog.h index 55b191b..c4af161 100644 --- a/plugins/systemmonitor/filesystemdialog.h +++ b/plugins/systemmonitor/filesystemdialog.h @@ -18,37 +18,50 @@ */ #include +#include +#include #include +#include "filesystemlistwidget.h" -class DiskItemList; -class DiskModel; -class DiskInfo; +//class DiskItemList; +//class DiskModel; +class FileSystemData; class FileSystemWorker; class QVBoxLayout; +class QHBoxLayout; class FileSystemDialog : public QWidget { Q_OBJECT public: - explicit FileSystemDialog(QWidget* parent = 0); + explicit FileSystemDialog(QList toBeDisplayedColumns, QSettings *settings, QWidget* parent = 0); ~FileSystemDialog(); + FileSystemListWidget* getFileSysView(); void initFileSystemMonitor(); public slots: - void addDiskInfoItem(DiskInfo *info); - void removeDiskInfoItemByDevName(DiskInfo *info); + void refreshFileSysList(); void onDirectoryChanged(QString path); + void popupMenu(QPoint pos); + +signals: + void changeColumnVisible(int index, bool visible, QList columnVisible); + +//private: +// bool event(QEvent *event); private: - bool event(QEvent *event); - -private: - QVBoxLayout *m_centralLayout = nullptr; - DiskItemList *m_diskItemList; - DiskModel *m_diskModelList; +// QVBoxLayout *m_centralLayout = nullptr; +// DiskItemList *m_diskItemList; +// DiskModel *m_diskModelList; FileSystemWorker *m_fileSystemWorker = nullptr; - QFileSystemWatcher *m_fileSystemMonitor = nullptr; - QString m_monitorFile; +// QFileSystemWatcher *m_fileSystemMonitor = nullptr; +// QString m_monitorFile; + QSettings *proSettings = nullptr; + FileSystemListWidget *m_fileSysListWidget = nullptr; + QAction *m_refreshAction = nullptr; + QMenu *m_menu = nullptr; + QVBoxLayout *m_layout = nullptr; }; diff --git a/plugins/systemmonitor/filesystemlistitem.cpp b/plugins/systemmonitor/filesystemlistitem.cpp new file mode 100644 index 0000000..a1ecd33 --- /dev/null +++ b/plugins/systemmonitor/filesystemlistitem.cpp @@ -0,0 +1,211 @@ +/* + * Copyright (C) 2013 ~ 2018 National University of Defense Technology(NUDT) & Tianjin Kylin Ltd. + * + * Authors: + * Kobe Lee xiangli@ubuntukylin.com/kobe24_lixiang@126.com + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "filesystemlistitem.h" +#include +#include +#include +#include "util.h" + + +#include +#include +#include + +FileSystemListItem::FileSystemListItem(FileSystemData *info) +{ + m_data = info; + iconSize = 16; + padding = 14; + textPadding = 5; +} + +bool FileSystemListItem::isSameItem(FileSystemListItem *item) +{ + return m_data->deviceName() == ((static_cast(item)))->m_data->deviceName(); +} + +void FileSystemListItem::drawBackground(QRect rect, QPainter *painter, int index, bool isSelect) +{ + QPainterPath path; + path.addRect(QRectF(rect)); + + if (isSelect) { + painter->setOpacity(0.1); + painter->fillPath(path, QColor("#2bb6ea")); + } + else { + painter->setOpacity(1); + painter->fillPath(path, QColor("#ffffff")); +// if (index % 2 == 0) { +// painter->fillPath(path, QColor("#ffffff")); +// } else { +// painter->fillPath(path, QColor("#e9eef0")); +// } + } +} + +void FileSystemListItem::drawForeground(QRect rect, QPainter *painter, int column, int, bool isSelect, bool isSeparator) +{ + setFontSize(*painter, 12); + painter->setOpacity(1); + painter->setPen(QPen(QColor("#000000"))); + if (column == 0) { + painter->drawPixmap(QRect(rect.x() + padding, rect.y() + (rect.height() - iconSize) / 2, iconSize, iconSize), QPixmap(":/res/disk.png")); + int nameMaxWidth = rect.width() - iconSize - padding * 3; + QFont font = painter->font(); + QFontMetrics fm(font); + QString deviceName = fm.elidedText(m_data->deviceName(), Qt::ElideRight, nameMaxWidth);//Qt::ElideMiddle + painter->drawText(QRect(rect.x() + iconSize + padding * 2, rect.y(), nameMaxWidth, rect.height()), Qt::AlignLeft | Qt::AlignVCenter, deviceName); + if (isSeparator) { + painter->setOpacity(0.8); + QPainterPath separatorPath; + separatorPath.addRect(QRectF(rect.x() + rect.width() - 1, rect.y(), 1, rect.height())); + painter->fillPath(separatorPath, QColor("#e0e0e0")); + } + } + else if (column == 1) { + if (!m_data->mountDir().isEmpty()) { + int maxWidth = rect.width(); + QFont font = painter->font(); + QFontMetrics fm(font); + QString mountDir = fm.elidedText(m_data->mountDir(), Qt::ElideMiddle, maxWidth); + painter->drawText(QRect(rect.x(), rect.y(), rect.width() - textPadding, rect.height()), Qt::AlignLeft | Qt::AlignVCenter, mountDir); + } + if (isSeparator) { + painter->setOpacity(0.8); + QPainterPath separatorPath; + separatorPath.addRect(QRectF(rect.x() + rect.width() - 1, rect.y(), 1, rect.height())); + painter->fillPath(separatorPath, QColor("#e0e0e0")); + } + } + else if (column == 2) { + if (!m_data->diskType().isEmpty()) { + int maxWidth = rect.width(); + QFont font = painter->font(); + QFontMetrics fm(font); + QString diskType = fm.elidedText(m_data->diskType(), Qt::ElideRight, maxWidth); + painter->drawText(QRect(rect.x(), rect.y(), rect.width() - textPadding, rect.height()), Qt::AlignRight | Qt::AlignVCenter, diskType); + } + if (isSeparator) { + painter->setOpacity(0.8); + QPainterPath separatorPath; + separatorPath.addRect(QRectF(rect.x() + rect.width() - 1, rect.y(), 1, rect.height())); + painter->fillPath(separatorPath, QColor("#e0e0e0")); + } + } + else if (column == 3) { + if (!m_data->totalCapacity().isEmpty()) { + int maxWidth = rect.width(); + QFont font = painter->font(); + QFontMetrics fm(font); + QString tCapacity = fm.elidedText(m_data->totalCapacity(), Qt::ElideRight, maxWidth); + painter->drawText(QRect(rect.x(), rect.y(), rect.width() - textPadding, rect.height()), Qt::AlignRight | Qt::AlignVCenter, tCapacity); + } + if (isSeparator) { + painter->setOpacity(0.8); + QPainterPath separatorPath; + separatorPath.addRect(QRectF(rect.x() + rect.width() - 1, rect.y(), 1, rect.height())); + painter->fillPath(separatorPath, QColor("#e0e0e0")); + } + } + else if (column == 4) { + if (!m_data->freeCapacity().isEmpty()) { + int maxWidth = rect.width(); + QFont font = painter->font(); + QFontMetrics fm(font); + QString fCapacity = fm.elidedText(m_data->freeCapacity(), Qt::ElideRight, maxWidth); + painter->drawText(QRect(rect.x(), rect.y(), rect.width() - textPadding, rect.height()), Qt::AlignRight | Qt::AlignVCenter, fCapacity); + } + if (isSeparator) { + painter->setOpacity(0.8); + QPainterPath separatorPath; + separatorPath.addRect(QRectF(rect.x() + rect.width() - 1, rect.y(), 1, rect.height())); + painter->fillPath(separatorPath, QColor("#e0e0e0")); + } + } + else if (column == 5) { + if (!m_data->availCapacity().isEmpty()) { + int maxWidth = rect.width(); + QFont font = painter->font(); + QFontMetrics fm(font); + QString aCapacity = fm.elidedText(m_data->availCapacity(), Qt::ElideRight, maxWidth); + painter->drawText(QRect(rect.x(), rect.y(), rect.width() - textPadding, rect.height()), Qt::AlignRight | Qt::AlignVCenter, aCapacity); + } + if (isSeparator) { + painter->setOpacity(0.8); + QPainterPath separatorPath; + separatorPath.addRect(QRectF(rect.x() + rect.width() - 1, rect.y(), 1, rect.height())); + painter->fillPath(separatorPath, QColor("#e0e0e0")); + } + } + else if (column == 6) { + if (!m_data->usedCapactiy().isEmpty()) { + int maxWidth = 60; + QFont font = painter->font(); + QFontMetrics fm(font); + QString uCapacity = fm.elidedText(m_data->usedCapactiy(), Qt::ElideRight, maxWidth); + painter->drawText(QRect(rect.x(), rect.y(), maxWidth - textPadding, rect.height()), Qt::AlignLeft | Qt::AlignVCenter, uCapacity); + } + int leftPadding = 10; + int topPadding = 5; + int pWidth = rect.width() - 60 - 2 * leftPadding - textPadding; + int pHeight = rect.height() - 2 * topPadding; + QPainterPath bgPath; + bgPath.addRect(QRectF(rect.x() + 60, rect.y() + topPadding, pWidth, pHeight)); + painter->fillPath(bgPath, QColor("#eeeeee")); + QPainterPath fillPath; + fillPath.addRect(QRectF(rect.x() + 60, rect.y() + topPadding, pWidth - m_data->usedPercentage(), pHeight)); + painter->setOpacity(0.5); + painter->fillPath(fillPath, QColor("#0288d1")); + painter->setOpacity(1); + painter->drawText(QRect(rect.x() + 60, rect.y() + topPadding, pWidth, pHeight), Qt::AlignHCenter | Qt::AlignVCenter, QString::number(m_data->usedPercentage()).append("%")); + + /* + QStyleOptionProgressBar progressBarStyle;//progressBarStyle.initFrom(this); + progressBarStyle.rect = QRect(rect.x() + 60, rect.y() + topPadding, pWidth, pHeight); + progressBarStyle.minimum = 0; + progressBarStyle.maximum = 100; + progressBarStyle.textAlignment = Qt::AlignCenter; + progressBarStyle.progress = m_data->usedPercentage(); + progressBarStyle.text = QString("%1%").arg(m_data->usedPercentage()); + progressBarStyle.textVisible = true; + QProgressBar progressBar; + progressBar.setStyleSheet("QProgressBar{border: none;text-align: center;background:#eeeeee;}QProgressBar::chunk {background:#0288d1;}"); + QApplication::style()->drawControl(QStyle::CE_ProgressBar, &progressBarStyle, painter, &progressBar);//绘制进度条 + */ + + if (isSeparator) { + painter->setOpacity(0.8); + QPainterPath separatorPath; + separatorPath.addRect(QRectF(rect.x() + rect.width() - 1, rect.y(), 1, rect.height())); + painter->fillPath(separatorPath, QColor("#e0e0e0")); + } + } +} + +QString FileSystemListItem::getDeviceName() const +{ + return m_data->deviceName(); +} + +QString FileSystemListItem::getDirectory() const +{ + return m_data->mountDir(); +} diff --git a/plugins/systemmonitor/diskmodel.h b/plugins/systemmonitor/filesystemlistitem.h similarity index 53% rename from plugins/systemmonitor/diskmodel.h rename to plugins/systemmonitor/filesystemlistitem.h index 822eb9f..56b7ab2 100644 --- a/plugins/systemmonitor/diskmodel.h +++ b/plugins/systemmonitor/filesystemlistitem.h @@ -18,34 +18,35 @@ */ -#ifndef DISKMODEL_H -#define DISKMODEL_H +#ifndef FILESYSTEMLISTITEM_H +#define FILESYSTEMLISTITEM_H #include -#include +#include +#include -#include "diskinfo.h" +#include "filesystemdata.h" -class DiskModel : public QObject +class FileSystemListItem : public QObject { Q_OBJECT + public: - explicit DiskModel(QObject *parent = 0); - ~DiskModel(); - - DiskInfo *getDiskInfo(const QString &devname); - QList diskInfoList() const; - void addDiskInfo(const QString &devname, DiskInfo *info); - void removeDiskInfo(const QString &devname); - bool contains(const QString &devname); - -signals: - void oneDiskInfoAdded(DiskInfo *info); - void oneDiskInfoRemoved(DiskInfo *info); + FileSystemListItem(FileSystemData *info); + + bool isSameItem(FileSystemListItem *item); + void drawCellBackground(QRect rect, QPainter *painter, int level); + void drawBackground(QRect rect, QPainter *painter, int index, bool isSelect); + void drawForeground(QRect rect, QPainter *painter, int column, int index, bool isSelect, bool isSeparator); + QString getDeviceName() const; + QString getDirectory() const; + private: - QMap m_diskInfoList; + FileSystemData *m_data; + int iconSize; + int padding; + int textPadding; }; -#endif // DISKMODEL_H - +#endif // FILESYSTEMLISTITEM_H diff --git a/plugins/systemmonitor/filesystemlistwidget.cpp b/plugins/systemmonitor/filesystemlistwidget.cpp new file mode 100644 index 0000000..e990853 --- /dev/null +++ b/plugins/systemmonitor/filesystemlistwidget.cpp @@ -0,0 +1,586 @@ +/* + * Copyright (C) 2013 ~ 2018 National University of Defense Technology(NUDT) & Tianjin Kylin Ltd. + * + * Authors: + * Kobe Lee xiangli@ubuntukylin.com/kobe24_lixiang@126.com + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "filesystemlistwidget.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +FileSystemListWidget::FileSystemListWidget(QList toBeDisplayedColumns, QWidget *parent) : QWidget(parent) + ,m_titlePadding(10) + ,m_titleHeight(34) + ,m_rowHeight(29) + ,m_offSet(0) + ,m_origOffset(0) + ,m_scrollbarWidth(10) + ,m_titleHoverColumn(-1) + ,m_titlePressColumn(-1) + ,m_mouseAtScrollArea(false) + ,m_mouseDragScrollbar(false) +{ + this->m_lastItem = NULL; + this->m_listItems = new QList(); + this->m_selectedItems = new QList(); + + this->columnTitles << tr("Device") << tr("Directory") << tr("Type") << tr("Total") << tr("Free") << tr("Available") << tr("Used"); + QList widths; + widths << 150 << -1 << 60 << 60 << 60 << 60 << 180;//-1时让改行填充所有剩余空间 + + QFont font; + font.setPixelSize(12);//需要和填充所有剩余空间的那个的文字字体大小一致 font.setPointSize(9) + QFontMetrics fm(font); + + this->m_columnWidths.clear(); + for (int i = 0; i < widths.length(); i++) { + if (widths[i] == -1) { + this->m_columnWidths << widths[i]; + } else {//-1时让改行填充所有剩余空间 + int maxWidth = fm.width(this->columnTitles[i]) + this->m_titlePadding + /*m_upArrowPixmap.width() / m_upArrowPixmap.devicePixelRatio() +*/ 2 * 2; + this->m_columnWidths << std::max(widths[i], maxWidth); + } + } + + this->m_columnVisibles.clear(); + for (int i = 0; i < toBeDisplayedColumns.count(); i++) { + this->m_columnVisibles.append(toBeDisplayedColumns[i]); + } + + this->setFocus(); +} + +FileSystemListWidget::~FileSystemListWidget() +{ + if (this->m_hideScrollbarTimer != NULL) { + disconnect(this->m_hideScrollbarTimer,SIGNAL(timeout()),this,SLOT(hideScrollbar())); + if(this->m_hideScrollbarTimer->isActive()) { + this->m_hideScrollbarTimer->stop(); + } + delete this->m_hideScrollbarTimer; + this->m_hideScrollbarTimer = nullptr; + } + + delete this->m_lastItem; + delete this->m_listItems; + delete this->m_selectedItems; +} + +void FileSystemListWidget::clearItems() +{ + qDeleteAll(this->m_listItems->begin(), this->m_listItems->end()); + this->m_listItems->clear(); +} + +void FileSystemListWidget::addSelectedItems(QList items, bool recordLastItem) +{ + this->m_selectedItems->append(items); + + if (recordLastItem && this->m_selectedItems->count() > 0) { + this->m_lastItem = this->m_selectedItems->last(); + } +} + +void FileSystemListWidget::clearSelectedItems(bool clearLast) +{ + this->m_selectedItems->clear(); + if (clearLast) { + this->m_lastItem = NULL; + } +} + +void FileSystemListWidget::refreshFileSystemItems(QList items) +{ + QList *allItems = new QList(); + FileSystemListItem *newLastItem = NULL; + + for (FileSystemListItem *item:items) { + for (FileSystemListItem *selectionItem:*this->m_selectedItems) { + if (item->isSameItem(selectionItem)) { + allItems->append(item); + break; + } + } + } + if (this->m_lastItem != NULL) { + for (FileSystemListItem *item:items) { + if (item->isSameItem(this->m_lastItem)) { + newLastItem = item; + break; + } + } + } + + clearItems(); + this->m_listItems->append(items); + + clearSelectedItems(); + addSelectedItems(*allItems, false); + + this->m_lastItem = newLastItem; + this->m_offSet = setOffset(this->m_offSet); + + repaint(); +} + +void FileSystemListWidget::leaveEvent(QEvent * event) +{ + hideScrollbar(); + QWidget::leaveEvent(event); +} + +void FileSystemListWidget::hideScrollbar() +{ + this->m_mouseAtScrollArea = false; + this->m_origOffset = this->m_offSet; + + repaint(); +} + +void FileSystemListWidget::mouseMoveEvent(QMouseEvent *mouseEvent) +{ + if (this->m_mouseDragScrollbar) { + this->m_offSet = setOffset((mouseEvent->y() - getScrollbarHeight() / 2 - this->m_titleHeight) / (getTheScrollAreaHeight() * 1.0) * this->getItemsTotalHeight()); + repaint(); + } + else if (mouseAtScrollArea(mouseEvent->x()) != this->m_mouseAtScrollArea) { + this->m_mouseAtScrollArea = mouseAtScrollArea(mouseEvent->x()); + repaint(); + } +} + +void FileSystemListWidget::mouseDoubleClickEvent(QMouseEvent *event) +{ + bool isTitleArea = mouseAtTitleArea(event->y()); + bool isScrollArea = mouseAtScrollArea(event->x()); + if (!isTitleArea && !isScrollArea) { + int pressedItemIndex = (this->m_offSet + event->y() - this->m_titleHeight) / this->m_rowHeight; + if (pressedItemIndex >= this->m_listItems->count()) { + clearSelectedItems(); + repaint(); + } + else { + if (event->button() == Qt::LeftButton) { + FileSystemListItem *pressItem = (*this->m_listItems)[pressedItemIndex]; + bool pressInSelectionArea = false; + for (FileSystemListItem *item : *this->m_selectedItems) { + if (item == pressItem) { + pressInSelectionArea = true; + break; + } + } + if (pressInSelectionArea) { + //open the mount dir + FileSystemListItem *procItem = static_cast(pressItem); + QString targetPath = QString("file://%1").arg(procItem->getDirectory()); + QDesktopServices::openUrl(QUrl(targetPath));//xdg-open + } + } + } + } + + QWidget::mouseDoubleClickEvent(event); +} + +void FileSystemListWidget::mousePressEvent(QMouseEvent *mouseEvent) +{ + setFocus(); + + bool isTitleArea = mouseAtTitleArea(mouseEvent->y()); + bool isScrollArea = mouseAtScrollArea(mouseEvent->x()); + + if (isTitleArea) {//点击列表的标题栏区域 + if (mouseEvent->button() == Qt::RightButton) { + if (m_columnVisibles.count() == this->columnTitles.count()) { + QMenu *menu = new QMenu(); + menu->setObjectName("MonitorMenu"); + for (int i = 0; i < m_columnVisibles.count(); i++) { + if (i != 0) {//让第一行总是显示,不可以设置显示或者不显示,其他行可以设置 + QAction *action = new QAction(menu); + action->setText(this->columnTitles[i]); + action->setCheckable(true); + action->setChecked(m_columnVisibles[i]); + connect(action, &QAction::triggered, this, [this, action, i] { + m_columnVisibles[i] = !m_columnVisibles[i]; + emit this->changeColumnVisible(i, m_columnVisibles[i], m_columnVisibles); + repaint(); + }); + menu->addAction(action); + } + } + menu->exec(this->mapToGlobal(mouseEvent->pos())); + delete menu; + } + } + } + else if (isScrollArea) {//点击滚动条区域 + int barHeight = getScrollbarHeight(); + int barY = getScrollbarY(); + if (mouseEvent->y() > barY && mouseEvent->y() < barY + barHeight) { + this->m_mouseDragScrollbar = true; + } + else { + this->m_offSet = setOffset((mouseEvent->y() - barHeight / 2 - this->m_titleHeight) / (getTheScrollAreaHeight() * 1.0) * this->getItemsTotalHeight()); + repaint(); + } + } + else { + int pressedItemIndex = (this->m_offSet + mouseEvent->y() - this->m_titleHeight) / this->m_rowHeight; + if (pressedItemIndex >= this->m_listItems->count()) { + clearSelectedItems(); + repaint(); + } + else { + if (mouseEvent->button() == Qt::LeftButton) { + if (pressedItemIndex < this->m_listItems->count()) { + if (mouseEvent->modifiers() == Qt::ControlModifier) { + FileSystemListItem *item = (*this->m_listItems)[pressedItemIndex]; + if (this->m_selectedItems->contains(item)) { + this->m_selectedItems->removeOne(item); + } else { + QList items = QList(); + items << item; + addSelectedItems(items); + } + } + else { + clearSelectedItems(); + QList items = QList(); + items << (*this->m_listItems)[pressedItemIndex]; + addSelectedItems(items); + } + repaint(); + } + } + else if (mouseEvent->button() == Qt::RightButton) { + FileSystemListItem *pressItem = (*this->m_listItems)[pressedItemIndex]; + bool pressInSelectionArea = false; + for (FileSystemListItem *item : *this->m_selectedItems) { + if (item == pressItem) { + pressInSelectionArea = true; + break; + } + } + if (pressInSelectionArea) { + emit this->rightMouseClickedItem(this->mapToGlobal(mouseEvent->pos())); + } + } + } + } +} + +void FileSystemListWidget::mouseReleaseEvent(QMouseEvent *) +{ + if (this->m_mouseDragScrollbar) { + this->m_mouseDragScrollbar = false; + repaint(); + } + else { + if (this->m_titlePressColumn != -1) { + this->m_titlePressColumn = -1; + repaint(); + } + } +} + +void FileSystemListWidget::wheelEvent(QWheelEvent *event) +{ + if (event->orientation() == Qt::Vertical) { + this->m_origOffset = this->m_offSet; + qreal scrollStep = event->angleDelta().y() / 100.0; + this->m_offSet = setOffset(this->m_offSet - scrollStep * this->m_rowHeight); + repaint(); + } + event->accept(); +} + +void FileSystemListWidget::paintEvent(QPaintEvent *) +{ + QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing, true); + + QList titleItemsWidths = getTitleItemsWidths(); + + painter.setOpacity(0.05); + + int penWidth = 1; + QPainterPath framePath; + framePath.addRoundedRect(QRect(rect().x() + penWidth, rect().y() + penWidth, rect().width() - penWidth * 2, rect().height() - penWidth * 2), 5, 5);//背景弧度 + painter.setClipPath(framePath); + + //标题的背景 + if (this->m_titleHeight > 0) { + QPainterPath titlePath; + titlePath.addRect(QRectF(rect().x(), rect().y(), rect().width(), this->m_titleHeight)); + painter.setOpacity(0.02); + painter.fillPath(titlePath, QColor("#ffffff")); + } + + int title_Y = 0; + int title_Height = 0; + if (this->m_titleHeight > 0) { + int counter = 0; + int posX = 0; + for (int itemWidth:titleItemsWidths) { + if (itemWidth > 0) { + //标题文字 + painter.setOpacity(1); + QFont font = painter.font(); + font.setPixelSize(12); + painter.setFont(font); + painter.setPen(QPen(QColor("#999999"))); + + if (this->columnTitles[counter] == tr("Device") || this->columnTitles[counter] == tr("Directory") || this->columnTitles[counter] == tr("Used")) + painter.drawText(QRect(posX + this->m_titlePadding, 0, itemWidth, this->m_titleHeight), Qt::AlignBottom | Qt::AlignLeft, this->columnTitles[counter]); + else + painter.drawText(QRect(posX, 0, itemWidth - this->m_titlePadding, this->m_titleHeight), Qt::AlignBottom | Qt::AlignRight, this->columnTitles[counter]); + + //水平下划线 + painter.setOpacity(0.8); + QPainterPath h_separatorPath; + h_separatorPath.addRect(QRectF(posX, rect().y() + this->m_titleHeight - 1, itemWidth, 1)); + painter.fillPath(h_separatorPath, QColor("#e0e0e0")); + + if (counter < titleItemsWidths.size()) {//垂直分割线 + QPainterPath v_separatorPath; + v_separatorPath.addRect(QRectF(rect().x() + posX - 1, rect().y() + 5, 1, this->m_titleHeight - 5)); + painter.fillPath(v_separatorPath, QColor("#e0e0e0")); + } + + posX += itemWidth; + } + counter++; + } + + title_Y += this->m_titleHeight; + title_Height += this->m_titleHeight; + } + + //去掉列表标题栏后的列表显示区域的背景 + painter.setOpacity(0.05); + QPainterPath backgroundPath; + backgroundPath.addRect(QRectF(rect().x(), rect().y() + this->m_titleHeight, rect().width(), rect().height() - this->m_titleHeight)); + painter.fillPath(backgroundPath, QColor("#ffffff")); + + //挂载的磁盘文件系统信息 + QPainterPath scrollAreaPath; + scrollAreaPath.addRect(QRectF(rect().x(), rect().y() + this->m_titleHeight, rect().width(), getTheScrollAreaHeight())); + + int rowCounter = 0; + for (FileSystemListItem *item:*this->m_listItems) { + if (rowCounter > ((this->m_offSet - this->m_rowHeight) / this->m_rowHeight)) { + QPainterPath itemPath; + itemPath.addRect(QRect(0, title_Y + rowCounter * this->m_rowHeight - this->m_offSet, rect().width(), this->m_rowHeight)); + painter.setClipPath((framePath.intersected(scrollAreaPath)).intersected(itemPath)); + + bool isSelect = this->m_selectedItems->contains(item); + painter.save(); + item->drawBackground(QRect(0, title_Y + rowCounter * this->m_rowHeight - this->m_offSet, rect().width(), this->m_rowHeight), &painter, rowCounter, isSelect); + painter.restore(); + + int columnCounter = 0; + int columnTitleX = 0; + for (int titleItemWidth : titleItemsWidths) { + if (titleItemWidth > 0) { + painter.save(); + if (columnCounter < titleItemsWidths.size() - 1) + item->drawForeground(QRect(columnTitleX, title_Y + rowCounter * this->m_rowHeight - this->m_offSet, titleItemWidth, this->m_rowHeight), &painter, columnCounter, rowCounter, isSelect, true); + else + item->drawForeground(QRect(columnTitleX, title_Y + rowCounter * this->m_rowHeight - this->m_offSet, titleItemWidth, this->m_rowHeight), &painter, columnCounter, rowCounter, isSelect, false); + painter.restore(); + columnTitleX += titleItemWidth; + } + columnCounter++; + } + title_Height += this->m_rowHeight; + if (title_Height > rect().height()) { + break; + } + } + rowCounter++; + } + painter.setClipPath(framePath); + + //没有挂载的磁盘文件系统信息时绘制提示文字 + if (this->m_listItems->size() == 0) { + painter.setOpacity(1); + painter.setPen(QPen(QColor("#666666"))); + QFont font = painter.font() ; + font.setPointSize(22); + painter.setFont(font); + painter.drawText(QRect(rect().x(), rect().y() + this->m_titleHeight, rect().width(), rect().height() - this->m_titleHeight), Qt::AlignCenter, tr("No File System Info")); + } + + //背景 +// QPen framePen; +// framePen.setColor(QColor("#F5F5F5")); +// painter.setPen(framePen); + painter.setOpacity(0.2); + painter.drawPath(framePath); + + //垂直滚动条 + if (this->m_mouseAtScrollArea) { + paintScrollbar(&painter); + } else if (this->m_origOffset != this->m_offSet) { + paintScrollbar(&painter); + readyToHideScrollbar(); + } +} + +void FileSystemListWidget::paintScrollbar(QPainter *painter) +{ + if (this->getItemsTotalHeight() > getTheScrollAreaHeight()) { + qreal opacitry = 0; + if (this->m_mouseDragScrollbar) { + opacitry = 0.8; + } + else { + if (this->m_mouseAtScrollArea) + opacitry = 0.7; + else + opacitry = 0.5; + } + + int barWidth = (this->m_mouseAtScrollArea || this->m_mouseDragScrollbar) ? this->m_scrollbarWidth : 6; + int barY = getScrollbarY(); + int barHeight = getScrollbarHeight(); + painter->setOpacity(opacitry); + QPainterPath path; + path.addRoundedRect( + QRectF(rect().x() + rect().width() - barWidth - 4, barY + 2, barWidth, barHeight - 2 * 2), 2, 2);//2 is radius + painter->fillPath(path, QColor("#0B95D7")); + + QPen pen; + pen.setColor(QColor("#0B95D7")); + pen.setWidth(1); + painter->setOpacity(0); + painter->setPen(pen); + painter->drawPath(path); + } +} + +QList FileSystemListWidget::getTitleItemsWidths() +{ + QList titleItemsWidths; + if (this->m_columnWidths.length() > 0) { + if (this->m_columnWidths.contains(-1)) { + for (int i = 0; i < this->m_columnWidths.count(); i++) { + if (this->m_columnWidths[i] != -1) { + if (m_columnVisibles[i]) { + titleItemsWidths << this->m_columnWidths[i]; + } else { + titleItemsWidths << 0; + } + } else { + if (m_columnVisibles[i]) { + int totalWidth = 0; + for (int j = 0; j < this->m_columnWidths.count(); j++) { + if (this->m_columnWidths[j] != -1 && m_columnVisibles[j]) { + totalWidth += this->m_columnWidths[j]; + } + } + titleItemsWidths << rect().width() - totalWidth; + } + else { + titleItemsWidths << 0; + } + } + } + } else { + for (int i = 0; i < this->m_columnWidths.count(); i++) { + if (m_columnVisibles[i]) { + titleItemsWidths << this->m_columnWidths[i]; + } + else { + titleItemsWidths << 0; + } + } + } + } + else { + titleItemsWidths << rect().width(); + } + + return titleItemsWidths; +} + +bool FileSystemListWidget::mouseAtScrollArea(int x) +{ + return (x > rect().x() + rect().width() - this->m_scrollbarWidth) && (x < rect().x() + rect().width()); +} + +bool FileSystemListWidget::mouseAtTitleArea(int y) +{ + return (y > rect().y() && y < rect().y() + this->m_titleHeight); +} + +int FileSystemListWidget::setOffset(int offset) +{ + return std::max(0, std::min(offset, getBottomOffset())); +} + +int FileSystemListWidget::getItemsTotalHeight() +{ + return m_listItems->count() * m_rowHeight; +} + +int FileSystemListWidget::getTheScrollAreaHeight() +{ + return this->rect().height() - this->m_titleHeight; +} + +int FileSystemListWidget::getScrollbarY() +{ + return static_cast((this->m_offSet / (this->getItemsTotalHeight() * 1.0)) * getTheScrollAreaHeight() + this->m_titleHeight); +} + +int FileSystemListWidget::getScrollbarHeight() +{ + return std::max(static_cast(getTheScrollAreaHeight() / (this->getItemsTotalHeight() * 1.0) * rect().height()), 30);//30 is min height +} + +int FileSystemListWidget::getBottomOffset() +{ + int itemsHeight = this->getItemsTotalHeight(); + if (itemsHeight > rect().height() - this->m_titleHeight) { + return this->getItemsTotalHeight() - rect().height() + this->m_titleHeight; + } else { + return 0; + } +} + +void FileSystemListWidget::readyToHideScrollbar() +{ + if (this->m_hideScrollbarTimer) { + if (this->m_hideScrollbarTimer->isActive()) + this->m_hideScrollbarTimer->stop(); + } + else { + this->m_hideScrollbarTimer = new QTimer(); + this->m_hideScrollbarTimer->setSingleShot(true); + connect(this->m_hideScrollbarTimer, SIGNAL(timeout()), this, SLOT(hideScrollbar())); + } + this->m_hideScrollbarTimer->start(2000); +} diff --git a/plugins/systemmonitor/filesystemlistwidget.h b/plugins/systemmonitor/filesystemlistwidget.h new file mode 100644 index 0000000..5d25010 --- /dev/null +++ b/plugins/systemmonitor/filesystemlistwidget.h @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2013 ~ 2018 National University of Defense Technology(NUDT) & Tianjin Kylin Ltd. + * + * Authors: + * Kobe Lee xiangli@ubuntukylin.com/kobe24_lixiang@126.com + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +#ifndef FILESYSTEMLISTWIDGET_H +#define FILESYSTEMLISTWIDGET_H + +#include "filesystemlistitem.h" + +#include +#include +#include +#include + +class FileSystemListWidget : public QWidget +{ + Q_OBJECT + +public: + FileSystemListWidget(QList toBeDisplayedColumns, QWidget *parent = 0); + ~FileSystemListWidget(); + + void readyToHideScrollbar(); + void clearItems(); + void addSelectedItems(QList items, bool recordLastItem=true); + void clearSelectedItems(bool clearLast=true); + void refreshFileSystemItems(QList items); + + int getItemsTotalHeight(); + int getBottomOffset(); + int getScrollbarY(); + int getScrollbarHeight(); + int getTheScrollAreaHeight(); + + QList getTitleItemsWidths(); + + int setOffset(int offset); + + bool mouseAtScrollArea(int x); + bool mouseAtTitleArea(int y); + +signals: + void rightMouseClickedItem(QPoint pos); + void changeColumnVisible(int index, bool visible, QList columnVisible); + +public slots: + void hideScrollbar(); + +protected: + virtual void leaveEvent(QEvent *event); + void mouseMoveEvent(QMouseEvent *mouseEvent); + void mousePressEvent(QMouseEvent *mouseEvent); + void mouseReleaseEvent(QMouseEvent *mouseEvent); + void paintEvent(QPaintEvent *); + void wheelEvent(QWheelEvent *event); + void paintScrollbar(QPainter *painter); + void mouseDoubleClickEvent(QMouseEvent *event) override; + +private: + QTimer *m_hideScrollbarTimer = nullptr; +// SearchFunction m_searchFunc; + + FileSystemListItem *m_lastItem = nullptr; + QList *m_listItems; + QList *m_selectedItems; + QList columnTitles; + QList m_columnWidths; + QList m_columnVisibles; + + bool m_mouseAtScrollArea; + bool m_mouseDragScrollbar; + int m_origOffset; + int m_offSet; + int m_rowHeight; + int m_scrollbarWidth; + int m_titleHeight; + int m_titleHoverColumn; + int m_titlePadding; + int m_titlePressColumn; +}; + +#endif // PROCESSLISTWIDGET_H diff --git a/plugins/systemmonitor/filesystemworker.cpp b/plugins/systemmonitor/filesystemworker.cpp index d750cee..8027737 100644 --- a/plugins/systemmonitor/filesystemworker.cpp +++ b/plugins/systemmonitor/filesystemworker.cpp @@ -18,14 +18,16 @@ */ #include "filesystemworker.h" -#include "diskinfo.h" #include #include #include /*For PRIu64*/ #include + +//extern "C" { //#include +//} typedef struct _DISK_INFO { @@ -34,6 +36,7 @@ typedef struct _DISK_INFO char type[256]; gint percentage; guint64 btotal; + guint64 bfree; guint64 bavail; guint64 bused; gint valid; @@ -85,6 +88,7 @@ DISK_INFO add_disk(const glibtop_mountentry *entry, gboolean show_all_fs) memcpy(disk.type, entry->type, strlen(entry->type)); disk.percentage = percentage; disk.btotal = btotal; + disk.bfree = bfree; disk.bavail = bavail; disk.bused = bused; disk.valid = 1; @@ -103,11 +107,9 @@ DISK_INFO add_disk(const glibtop_mountentry *entry, gboolean show_all_fs) // g_print ("Hello World\n"); //} -FileSystemWorker::FileSystemWorker(DiskModel *diskList, QObject *parent) +FileSystemWorker::FileSystemWorker(QObject *parent) : QObject(parent) - ,m_diskModel(diskList) { - onFileSystemListChanged(); // GVolumeMonitor * monitor;//GVolumeMonitor不是 thread-default-context aware,因此不能在除了主线程中的其他地方使用???? // monitor = g_volume_monitor_get(); // g_signal_connect(monitor, "mount-added", G_CALLBACK(hello), NULL); @@ -125,8 +127,14 @@ FileSystemWorker::FileSystemWorker(DiskModel *diskList, QObject *parent) // } } +FileSystemWorker::~FileSystemWorker() +{ + m_diskInfoList.clear(); +} + void FileSystemWorker::onFileSystemListChanged() { + QStringList newDiskList; glibtop_mountentry *entries; glibtop_mountlist mountlist; guint i; @@ -136,27 +144,65 @@ void FileSystemWorker::onFileSystemListChanged() DISK_INFO disk = add_disk(&entries[i], show_all_fs); if (disk.valid == 1) { QString dev_name = QString(QLatin1String(disk.devname)); - if (!m_diskModel->contains(dev_name)) { - DiskInfo *info = new DiskInfo(this); + newDiskList.append(dev_name); + + if (!this->isDeviceContains(dev_name)) { + FileSystemData *info = new FileSystemData(this); info->setDevName(dev_name); - info->setOtherDiskInfo(QString(QLatin1String(disk.mountdir)), QString(QLatin1String(disk.type)), QString(QLatin1String(g_format_size_full(disk.btotal, G_FORMAT_SIZE_DEFAULT))), QString(QLatin1String(g_format_size_full(disk.bavail, G_FORMAT_SIZE_DEFAULT))), QString(QLatin1String(g_format_size_full(disk.bused, G_FORMAT_SIZE_DEFAULT))), QString::number(disk.percentage).append("%")); - m_diskModel->addDiskInfo(dev_name, info); + info->updateDiskInfo(QString(QLatin1String(disk.mountdir)), QString(QLatin1String(disk.type)), QString(QLatin1String(g_format_size_full(disk.btotal, G_FORMAT_SIZE_DEFAULT))), QString(QLatin1String(g_format_size_full(disk.bfree, G_FORMAT_SIZE_DEFAULT))), QString(QLatin1String(g_format_size_full(disk.bavail, G_FORMAT_SIZE_DEFAULT))), QString(QLatin1String(g_format_size_full(disk.bused, G_FORMAT_SIZE_DEFAULT))), disk.percentage/*QString::number(disk.percentage).append("%")*/); + this->addDiskInfo(dev_name, info); } else {//update info which had exists - DiskInfo *info = m_diskModel->getDiskInfo(dev_name); + FileSystemData *info = this->getDiskInfo(dev_name); if (info) { - info->setOtherDiskInfo(QString(QLatin1String(disk.mountdir)), QString(QLatin1String(disk.type)), QString(QLatin1String(g_format_size_full(disk.btotal, G_FORMAT_SIZE_DEFAULT))), QString(QLatin1String(g_format_size_full(disk.bavail, G_FORMAT_SIZE_DEFAULT))), QString(QLatin1String(g_format_size_full(disk.bused, G_FORMAT_SIZE_DEFAULT))), QString::number(disk.percentage).append("%")); + info->updateDiskInfo(QString(QLatin1String(disk.mountdir)), QString(QLatin1String(disk.type)), QString(QLatin1String(g_format_size_full(disk.btotal, G_FORMAT_SIZE_DEFAULT))), QString(QLatin1String(g_format_size_full(disk.bfree, G_FORMAT_SIZE_DEFAULT))), QString(QLatin1String(g_format_size_full(disk.bavail, G_FORMAT_SIZE_DEFAULT))), QString(QLatin1String(g_format_size_full(disk.bused, G_FORMAT_SIZE_DEFAULT))), disk.percentage/*QString::number(disk.percentage).append("%")*/); } -// for (DiskInfo *info : m_diskModel->diskInfoList()) { -// } } } } + + //remove the device whice not exists anymore + for (auto device : m_diskInfoList.keys()) { + bool foundDevice = false; + for (auto devName : newDiskList) { + if (devName == device) { + foundDevice = true; + break; + } + } + + if (!foundDevice) { + m_diskInfoList.remove(device);//or erase??? + } + } + g_free(entries); } +FileSystemData *FileSystemWorker::getDiskInfo(const QString &devname) +{ + return m_diskInfoList.value(devname, nullptr); +} + +QList FileSystemWorker::diskInfoList() const +{ + return m_diskInfoList.values(); +} + +void FileSystemWorker::addDiskInfo(const QString &devname, FileSystemData *info) +{ + if (!m_diskInfoList.contains(devname)) { + m_diskInfoList[devname] = info; + } +} + void FileSystemWorker::removeDiskItem(const QString &devname) { - m_diskModel->removeDiskInfo(devname); +// FileSystemData *info = getDiskInfo(devname); +// m_diskInfoList.remove(devname); } +bool FileSystemWorker::isDeviceContains(const QString &devname) +{ + return m_diskInfoList.contains(devname); +} diff --git a/plugins/systemmonitor/filesystemworker.h b/plugins/systemmonitor/filesystemworker.h index 044e240..e390cb5 100644 --- a/plugins/systemmonitor/filesystemworker.h +++ b/plugins/systemmonitor/filesystemworker.h @@ -22,25 +22,33 @@ #define FILESYSTEMWORKER_H #include -#include "diskinfo.h" -#include "diskmodel.h" +#include + +#include "filesystemdata.h" class FileSystemWorker : public QObject { Q_OBJECT public: - explicit FileSystemWorker(DiskModel *diskList, QObject *parent = 0); + explicit FileSystemWorker(QObject *parent = 0); + ~FileSystemWorker(); void removeDiskItem(const QString &devname); + FileSystemData *getDiskInfo(const QString &devname); + QList diskInfoList() const; + void addDiskInfo(const QString &devname, FileSystemData *info); + void removeDiskInfo(const QString &devname); + bool isDeviceContains(const QString &devname); + public slots: void onFileSystemListChanged(); void removeUserByName(const QString &name); - private: - DiskModel *m_diskModel; + QMap m_diskInfoList; +// QMap *processSentBytes; }; #endif // FILESYSTEMWORKER_H diff --git a/plugins/systemmonitor/processlistitem.cpp b/plugins/systemmonitor/processlistitem.cpp index cb26ea2..5ab9ac9 100644 --- a/plugins/systemmonitor/processlistitem.cpp +++ b/plugins/systemmonitor/processlistitem.cpp @@ -26,7 +26,7 @@ ProcessListItem::ProcessListItem(ProcData info) { m_data = info; - iconSize = 24; + iconSize = 16; padding = 14; textPadding = 5; } @@ -63,11 +63,12 @@ void ProcessListItem::drawBackground(QRect rect, QPainter *painter, int index, b } else { painter->setOpacity(1); - if (index % 2 == 0) { - painter->fillPath(path, QColor("#ffffff")); - } else { - painter->fillPath(path, QColor("#e9eef0")); - } + painter->fillPath(path, QColor("#ffffff")); +// if (index % 2 == 0) { +// painter->fillPath(path, QColor("#ffffff")); +// } else { +// painter->fillPath(path, QColor("#e9eef0")); +// } } } @@ -138,6 +139,12 @@ void ProcessListItem::drawForeground(QRect rect, QPainter *painter, int column, this->drawCellBackground(QRect(rect.x(), rect.y(), rect.width(), rect.height()), painter, 2); } painter->drawText(QRect(rect.x(), rect.y(), rect.width() - textPadding, rect.height()), Qt::AlignRight | Qt::AlignVCenter, QString("%1%").arg(m_data.cpu)); + if (isSeparator) { + painter->setOpacity(0.8); + QPainterPath separatorPath; + separatorPath.addRect(QRectF(rect.x() + rect.width() - 1, rect.y(), 1, rect.height())); + painter->fillPath(separatorPath, QColor("#e0e0e0")); + } } else if (column == 4) { painter->drawText(QRect(rect.x(), rect.y(), rect.width() - padding, rect.height()), Qt::AlignRight | Qt::AlignVCenter, QString("%1").arg(m_data.pid)); diff --git a/plugins/systemmonitor/processlistwidget.cpp b/plugins/systemmonitor/processlistwidget.cpp index 53a859c..d1f2e16 100644 --- a/plugins/systemmonitor/processlistwidget.cpp +++ b/plugins/systemmonitor/processlistwidget.cpp @@ -616,7 +616,8 @@ void ProcessListWidget::mousePressEvent(QMouseEvent *mouseEvent) clearSelectedItems(); repaint(); - } else { + } + else { if (mouseEvent->button() == Qt::LeftButton) { if (pressedItemIndex < this->m_searchedItems->count()) { if (mouseEvent->modifiers() == Qt::ControlModifier) { @@ -644,7 +645,8 @@ void ProcessListWidget::mousePressEvent(QMouseEvent *mouseEvent) } repaint(); } - } else if (mouseEvent->button() == Qt::RightButton) { + } + else if (mouseEvent->button() == Qt::RightButton) { ProcessListItem *pressItem = (*this->m_searchedItems)[pressedItemIndex]; bool pressInSelectionArea = false; for (ProcessListItem *item : *this->m_selectedItems) { diff --git a/plugins/systemmonitor/processlistwidget.h b/plugins/systemmonitor/processlistwidget.h index 455e748..b8115b1 100644 --- a/plugins/systemmonitor/processlistwidget.h +++ b/plugins/systemmonitor/processlistwidget.h @@ -36,12 +36,10 @@ class ProcessListWidget : public QWidget Q_OBJECT public: - - ~ProcessListWidget(); ProcessListWidget(QList toBeDisplayedColumns, QWidget *parent = 0); + ~ProcessListWidget(); void readyToHideScrollbar(); - void setProcessSortFunctions(QList *list, int sortColumn=-1, bool isSort=false); void setSearchFunction(SearchFunction func); void addItems(QList items); diff --git a/plugins/systemmonitor/systemmonitor.cpp b/plugins/systemmonitor/systemmonitor.cpp index 7ff9905..ad1dc66 100644 --- a/plugins/systemmonitor/systemmonitor.cpp +++ b/plugins/systemmonitor/systemmonitor.cpp @@ -102,7 +102,7 @@ void SystemMonitor::resizeEvent(QResizeEvent *e) } } -void SystemMonitor::recordVisibleColumn(int, bool, QList columnVisible) +void SystemMonitor::recordProcessVisibleColumn(int, bool, QList columnVisible) { QList m_visibleColumns; m_visibleColumns << "name"; @@ -161,6 +161,50 @@ void SystemMonitor::recordSortStatus(int index, bool isSort) proSettings->sync(); } +void SystemMonitor::recordFileSysVisibleColumn(int, bool, QList columnVisible) +{ + QList m_visibleColumns; + m_visibleColumns << "device"; + + if (columnVisible[1]) { + m_visibleColumns << "directory"; + } + + if (columnVisible[2]) { + m_visibleColumns << "type"; + } + + if (columnVisible[3]) { + m_visibleColumns << "total"; + } + + if (columnVisible[4]) { + m_visibleColumns << "free"; + } + + if (columnVisible[5]) { + m_visibleColumns << "available"; + } + + if (columnVisible[6]) { + m_visibleColumns << "used"; + } + + QString displayedColumns = ""; + for (int i = 0; i < m_visibleColumns.length(); i++) { + if (i != m_visibleColumns.length() - 1) { + displayedColumns += QString("%1,").arg(m_visibleColumns[i]); + } else { + displayedColumns += m_visibleColumns[i]; + } + } + + proSettings->beginGroup("FileSystem"); + proSettings->setValue("DisplayedColumns", displayedColumns); + proSettings->endGroup(); + proSettings->sync(); +} + void SystemMonitor::initPanelStack() { m_sysMonitorStack = new QStackedWidget(this); @@ -172,13 +216,16 @@ void SystemMonitor::initPanelStack() m_sysMonitorStack->setMouseTracking(false); m_sysMonitorStack->installEventFilter(this); - process_dialog = new ProcessDialog(getReadyDisplayColumns(), getCurrentSortColumnIndex(), isSortOrNot(), proSettings); + process_dialog = new ProcessDialog(getReadyDisplayProcessColumns(), getCurrentSortColumnIndex(), isSortOrNot(), proSettings); process_dialog->getProcessView()->installEventFilter(this); - connect(process_dialog, &ProcessDialog::changeColumnVisible, this, &SystemMonitor::recordVisibleColumn); + connect(process_dialog, &ProcessDialog::changeColumnVisible, this, &SystemMonitor::recordProcessVisibleColumn); connect(process_dialog, &ProcessDialog::changeSortStatus, this, &SystemMonitor::recordSortStatus); resources_dialog = new ResouresDialog; - filesystem_dialog = new FileSystemDialog; + + filesystem_dialog = new FileSystemDialog(getReadyDisplayFileSysColumns(), proSettings); + filesystem_dialog->getFileSysView()->installEventFilter(this); + connect(filesystem_dialog, SIGNAL(changeColumnVisible(int,bool,QList)), this, SLOT(recordFileSysVisibleColumn(int,bool,QList))); m_sysMonitorStack->addWidget(process_dialog); m_sysMonitorStack->addWidget(resources_dialog); @@ -235,7 +282,7 @@ bool SystemMonitor::isSortOrNot() return value; } -QList SystemMonitor::getReadyDisplayColumns() +QList SystemMonitor::getReadyDisplayProcessColumns() { proSettings->beginGroup("PROCESS"); QString displayedColumns = proSettings->value("DisplayedColumns", "name,user,status,cpu,pid,command,memory,priority").toString(); @@ -262,6 +309,32 @@ QList SystemMonitor::getReadyDisplayColumns() return m_shows; } +QList SystemMonitor::getReadyDisplayFileSysColumns() +{ + proSettings->beginGroup("FileSystem"); + QString displayedColumns = proSettings->value("DisplayedColumns", "device,directory,type,total,free,available,used").toString(); + proSettings->endGroup(); + + if (displayedColumns.isEmpty()) { + proSettings->beginGroup("FileSystem"); + displayedColumns = "device,directory,type,total,free,available,used"; + proSettings->setValue("DisplayedColumns", displayedColumns); + proSettings->endGroup(); + proSettings->sync(); + } + + QList m_shows; + m_shows << displayedColumns.contains("device"); + m_shows << displayedColumns.contains("directory"); + m_shows << displayedColumns.contains("type"); + m_shows << displayedColumns.contains("total"); + m_shows << displayedColumns.contains("free"); + m_shows << displayedColumns.contains("available"); + m_shows << displayedColumns.contains("used"); + + return m_shows; +} + void SystemMonitor::moveCenter() { QPoint pos = QCursor::pos(); diff --git a/plugins/systemmonitor/systemmonitor.h b/plugins/systemmonitor/systemmonitor.h index 021ffba..906542d 100644 --- a/plugins/systemmonitor/systemmonitor.h +++ b/plugins/systemmonitor/systemmonitor.h @@ -42,14 +42,18 @@ public: void initPanelStack(); void initConnections(); - QList getReadyDisplayColumns(); + QList getReadyDisplayProcessColumns(); bool isSortOrNot(); int getCurrentSortColumnIndex(); + + QList getReadyDisplayFileSysColumns(); + void moveCenter(); public slots: - void recordVisibleColumn(int, bool, QList columnVisible); + void recordProcessVisibleColumn(int, bool, QList columnVisible); void recordSortStatus(int index, bool isSort); + void recordFileSysVisibleColumn(int, bool, QList columnVisible); void onChangePage(int index); protected: diff --git a/plugins/systemmonitor/systemmonitor.pro b/plugins/systemmonitor/systemmonitor.pro index 1db0900..8dca898 100644 --- a/plugins/systemmonitor/systemmonitor.pro +++ b/plugins/systemmonitor/systemmonitor.pro @@ -16,6 +16,7 @@ DESTDIR = $$_PRO_FILE_PWD_/../ CONFIG += plugin c++11 link_pkgconfig PKGCONFIG += libgtop-2.0 libsystemd #gio-2.0 +#LIBS +=-lgio-2.0 -lglib-2.0 target.path = $${PREFIX}/lib/kylin-assistant/plugins/ INSTALLS += target @@ -49,11 +50,8 @@ HEADERS += \ monitortitlewidget.h \ resourcesdialog.h \ filesystemdialog.h \ - diskitemlist.h \ - diskitem.h \ filesystemworker.h \ - diskmodel.h \ - diskinfo.h \ + filesystemdata.h \ ../widgets/mysearchedit.h \ networkwidget.h \ networkflow.h \ @@ -64,7 +62,9 @@ HEADERS += \ memorycircle.h \ networkindicator.h \ resourcesindicator.h \ - resourcescategory.h + resourcescategory.h \ + filesystemlistwidget.h \ + filesystemlistitem.h SOURCES += \ systemmonitor.cpp \ @@ -86,11 +86,8 @@ SOURCES += \ monitortitlewidget.cpp \ resourcesdialog.cpp \ filesystemdialog.cpp \ - diskitemlist.cpp \ - diskitem.cpp \ filesystemworker.cpp \ - diskmodel.cpp \ - diskinfo.cpp \ + filesystemdata.cpp \ ../widgets/mysearchedit.cpp \ networkwidget.cpp \ networkflow.cpp \ @@ -101,7 +98,9 @@ SOURCES += \ memorycircle.cpp \ networkindicator.cpp \ resourcesindicator.cpp \ - resourcescategory.cpp + resourcescategory.cpp \ + filesystemlistwidget.cpp \ + filesystemlistitem.cpp OTHER_FILES += \ systemmonitor.json diff --git a/src/translation/kylin-assistant_de.ts b/src/translation/kylin-assistant_de.ts index 2f44ff3..11b2afd 100644 --- a/src/translation/kylin-assistant_de.ts +++ b/src/translation/kylin-assistant_de.ts @@ -771,6 +771,60 @@ Kylin Team <ubuntukylin-members@list.launchpad.net> + + FileSystemDialog + + + Refresh + + + + + FileSystemListWidget + + + + Device + + + + + + Directory + + + + + Type + + + + + Total + + + + + Free + + + + + Available + + + + + + Used + + + + + No File System Info + + + FontWidget @@ -1716,28 +1770,28 @@ Are you sure to continue? ProcessListItem - + Stopped - + Suspend - + Zombie - + No response - - + + Uninterruptible @@ -1746,7 +1800,7 @@ Are you sure to continue? ProcessListWidget - + Process Name @@ -1772,7 +1826,7 @@ Are you sure to continue? - + Command Line @@ -1783,12 +1837,12 @@ Are you sure to continue? - + Priority - + No search result diff --git a/src/translation/kylin-assistant_es.ts b/src/translation/kylin-assistant_es.ts index e8f4bdb..acd28b5 100644 --- a/src/translation/kylin-assistant_es.ts +++ b/src/translation/kylin-assistant_es.ts @@ -771,6 +771,60 @@ Kylin Team <ubuntukylin-members@list.launchpad.net> + + FileSystemDialog + + + Refresh + + + + + FileSystemListWidget + + + + Device + + + + + + Directory + + + + + Type + + + + + Total + + + + + Free + + + + + Available + + + + + + Used + + + + + No File System Info + + + FontWidget @@ -1716,28 +1770,28 @@ Are you sure to continue? ProcessListItem - + Stopped - + Suspend - + Zombie - + No response - - + + Uninterruptible @@ -1746,7 +1800,7 @@ Are you sure to continue? ProcessListWidget - + Process Name @@ -1772,7 +1826,7 @@ Are you sure to continue? - + Command Line @@ -1783,12 +1837,12 @@ Are you sure to continue? - + Priority - + No search result diff --git a/src/translation/kylin-assistant_fr.ts b/src/translation/kylin-assistant_fr.ts index b25f776..5af4214 100644 --- a/src/translation/kylin-assistant_fr.ts +++ b/src/translation/kylin-assistant_fr.ts @@ -771,6 +771,60 @@ Kylin Team <ubuntukylin-members@list.launchpad.net> + + FileSystemDialog + + + Refresh + + + + + FileSystemListWidget + + + + Device + + + + + + Directory + + + + + Type + + + + + Total + + + + + Free + + + + + Available + + + + + + Used + + + + + No File System Info + + + FontWidget @@ -1716,28 +1770,28 @@ Are you sure to continue? ProcessListItem - + Stopped - + Suspend - + Zombie - + No response - - + + Uninterruptible @@ -1746,7 +1800,7 @@ Are you sure to continue? ProcessListWidget - + Process Name @@ -1772,7 +1826,7 @@ Are you sure to continue? - + Command Line @@ -1783,12 +1837,12 @@ Are you sure to continue? - + Priority - + No search result diff --git a/src/translation/kylin-assistant_ru.ts b/src/translation/kylin-assistant_ru.ts index c0e7c1e..418ef27 100644 --- a/src/translation/kylin-assistant_ru.ts +++ b/src/translation/kylin-assistant_ru.ts @@ -771,6 +771,60 @@ Kylin Team <ubuntukylin-members@list.launchpad.net> + + FileSystemDialog + + + Refresh + + + + + FileSystemListWidget + + + + Device + + + + + + Directory + + + + + Type + + + + + Total + + + + + Free + + + + + Available + + + + + + Used + + + + + No File System Info + + + FontWidget @@ -1716,28 +1770,28 @@ Are you sure to continue? ProcessListItem - + Stopped - + Suspend - + Zombie - + No response - - + + Uninterruptible @@ -1746,7 +1800,7 @@ Are you sure to continue? ProcessListWidget - + Process Name @@ -1772,7 +1826,7 @@ Are you sure to continue? - + Command Line @@ -1783,12 +1837,12 @@ Are you sure to continue? - + Priority - + No search result diff --git a/src/translation/kylin-assistant_zh_CN.qm b/src/translation/kylin-assistant_zh_CN.qm index 3544cda..00102a2 100644 Binary files a/src/translation/kylin-assistant_zh_CN.qm and b/src/translation/kylin-assistant_zh_CN.qm differ diff --git a/src/translation/kylin-assistant_zh_CN.ts b/src/translation/kylin-assistant_zh_CN.ts index eb4daa0..8ee7b6e 100644 --- a/src/translation/kylin-assistant_zh_CN.ts +++ b/src/translation/kylin-assistant_zh_CN.ts @@ -1456,6 +1456,60 @@ Kylin Team <ubuntukylin-members@list.launchpad.net> 最大缩略图缓存尺寸(MB) + + FileSystemDialog + + + Refresh + 刷新 + + + + FileSystemListWidget + + + + Device + 设备 + + + + + Directory + 目录 + + + + Type + 类型 + + + + Total + 总数 + + + + Free + 空闲 + + + + Available + 可用 + + + + + Used + 已用 + + + + No File System Info + 没有发现文件系统信息 + + FontWidget @@ -2576,28 +2630,28 @@ Are you sure to continue? ProcessListItem - + Stopped 已停止 - + Suspend 停止 - + Zombie 僵死 - + No response 无反应 - - + + Uninterruptible 不可中断 @@ -2606,7 +2660,7 @@ Are you sure to continue? ProcessListWidget - + Process Name 进程名 @@ -2632,7 +2686,7 @@ Are you sure to continue? - + Command Line 命令行 @@ -2643,12 +2697,12 @@ Are you sure to continue? - + Priority 优先级 - + No search result 无搜索结果