Add monitor for file system

This commit is contained in:
李 翔 2018-02-03 23:00:32 +08:00
parent b54dcc61a0
commit 7256d8aa2b
31 changed files with 944 additions and 842 deletions

81
component/myswitcher.cpp Normal file
View File

@ -0,0 +1,81 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "myswitcher.h"
#include <QPainter>
#include <QPainterPath>
#include <QMouseEvent>
#include <QDebug>
MySwitcher::MySwitcher(QWidget *parent) :
QFrame(parent),
m_isOn(false)
{
this->setFixedSize(76, 29);
m_offImage.load("://res/off.png");
m_onImage.load("://res/on.png");
}
bool MySwitcher::isOn() const
{
return m_isOn;
}
void MySwitcher::setOnStatus(bool b)
{
if (m_isOn != b) {
m_isOn = b;
emit this->statusChanged(b);
this->update();
}
}
void MySwitcher::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
this->setOnStatus(!m_isOn);
event->accept();
}
}
void MySwitcher::paintEvent(QPaintEvent *event)
{
QPixmap *m_nowImagePix;
if(this->m_isOn) {
m_nowImagePix = &m_onImage;
}
else {
m_nowImagePix = &m_offImage;
}
if(m_nowImagePix->isNull())
return;
QPainter painter(this);
painter.setRenderHints(QPainter::Antialiasing, true);
QPainterPath path;
path.addRoundedRect(rect(), m_nowImagePix->height() / 2.0, m_nowImagePix->height() / 2.0);
path.closeSubpath();
painter.setClipPath(path);
painter.drawPixmap(rect(), *m_nowImagePix);
}

51
component/myswitcher.h Normal file
View File

@ -0,0 +1,51 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef MYSWITCHER_H
#define MYSWITCHER_H
#include <QFrame>
#include <QPixmap>
class MySwitcher : public QFrame
{
Q_OBJECT
public:
explicit MySwitcher(QWidget *parent = 0);
bool isOn() const;
public slots:
void setOnStatus(bool b);
signals:
void statusChanged(bool b);
protected:
void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
private:
bool m_isOn;
QPixmap m_onImage;
QPixmap m_offImage;
};
#endif // MYSWITCHER_H

View File

@ -36,12 +36,9 @@ ThreadPool *ThreadPool::Instance()
return &threadPool;
}
QThread *ThreadPool::newThread()
{
QThread *thread = new QThread;
// qDebug() << "add <<<<<<<" << thread;
thread_pool.push_back(thread);
return thread;
}
@ -53,8 +50,6 @@ void ThreadPool::moveToNewThread(QObject *obj)
work->start();
}
//QThread *ThreadPool::createNewThread()
//{
// QThread *thread = new QThread;

1
debian/changelog vendored
View File

@ -15,5 +15,6 @@ kylin-assistant (1.0.0-0ubuntu1) bionic; urgency=low
* Add processes, resources and file system manager.
* Add auto startup manager.
* Add monitor for auto startup manager.
* Add monitor for file system.
-- lixiang <lixiang@kylinos.cn> Mon, 29 Jan 2018 17:54:44 +0800

5
debian/control vendored
View File

@ -17,8 +17,9 @@ Build-Depends: debhelper (>= 9),
qtscript5-dev,
qttools5-dev-tools,
pkg-config,
libglib2.0-dev,
libgtop2-dev
libglib2.0-dev (>= 2.46.0),
libgtop2-dev,
libsystemd-dev (>= 209) [linux-any]
Standards-Version: 3.9.8
X-Python3-Version: >= 3.1
Homepage: https://github.com/KylinAppCenter/kylin-assistant

View File

@ -2,7 +2,8 @@ TEMPLATE = subdirs
SUBDIRS = \
src \
plugins \
backends
backends \
qdbusservice
TRANSLATIONS += \
src/translation/kylin-assistant_zh_CN.ts \

View File

@ -28,24 +28,22 @@
#include <QFileSystemWatcher>
#include <glib.h>
class GspXdgDir
{
public:
/*typedef struct {
QString dir;
int index;
QFileSystemWatcher *wather;
QFileSystemWatcher *watcher;
QStringList fileList;
} MonitorData;*/
class MonitorData
{
public:
QString dir;//监控目录
int index;
QFileSystemWatcher *watcher;//监控器
QStringList fileList;//监控目录下的文件列表
};
//typedef QSharedPointer<GspXdgDir> GspXdgDirPtr;
//typedef QList<GspXdgDirPtr> GspXdgDirPtrList;
//Q_DECLARE_METATYPE(GspXdgDir)
//Q_DECLARE_METATYPE(GspXdgDirPtr)
//Q_DECLARE_METATYPE(GspXdgDirPtrList)
class StartupData/* : public QObject*/
{

View File

@ -18,7 +18,7 @@
*/
#include "startupitem.h"
#include "../../component/kylinswitcher.h"
#include "../../component/myswitcher.h"
#include "startupdata.h"
#include <QApplication>
@ -66,15 +66,13 @@ StartupItem::StartupItem(StartupData info, QWidget *parent) : QWidget(parent)
m_appDescLabel = new QLabel();
m_appDescLabel->setText(info.comment);
switcher = new KylinSwitcher();
switcher->switchedOn = info.enabled;
// connect(switcher, SIGNAL(clicked()), this, SLOT()
connect(switcher, &KylinSwitcher::clicked, [=] () {
//changeAutoStartAppStatus
emit changeStartup(info.exec, switcher->switchedOn);
switcher = new MySwitcher();
switcher->setOnStatus(info.enabled);
connect(switcher, &MySwitcher::statusChanged, [=] (const bool b) {
emit changeStartup(info.exec, b);
});
m_switchLayout->addWidget(switcher, 0, Qt::AlignCenter);
m_switchLayout->addWidget(switcher, 0, Qt::AlignCenter);
m_leftLayout->addWidget(m_appIcon);
m_labelWidget = new QWidget();
@ -90,6 +88,13 @@ StartupItem::StartupItem(StartupData info, QWidget *parent) : QWidget(parent)
this->setLayout(m_layout);
}
void StartupItem::setSwitcherOn(const bool b)
{
switcher->blockSignals(true);
switcher->setOnStatus(b);
switcher->blockSignals(false);
}
QListWidgetItem* StartupItem::getItem()
{
return item;
@ -133,10 +138,9 @@ void StartupItem::paintEvent(QPaintEvent *event)
QPainterPath path;
path.addRoundedRect(QRectF(rect()), 2, 2);
painter.fillPath(path, QColor(135, 206, 250, 127));
painter.setOpacity(0.1);
painter.fillPath(path, QColor("#2bb6ea"));
}
QWidget::paintEvent(event);
}

View File

@ -25,7 +25,7 @@
#include <QLabel>
#include <QListWidgetItem>
class KylinSwitcher;
class MySwitcher;
class StartupData;
class StartupItem : public QWidget
@ -41,9 +41,10 @@ public:
void setItemHovered();
void unsetItemHovered();
void setSwitcherOn(const bool b);
signals:
void changeStartup(const QString &exec, bool active);
void changeStartup(const QString &exec, const bool active);
void enter();
protected:
@ -58,8 +59,7 @@ private:
QLabel *m_appIcon = nullptr;
QLabel *m_appNameLabel = nullptr;
QLabel *m_appDescLabel = nullptr;
KylinSwitcher *switcher = nullptr;
MySwitcher *switcher = nullptr;
QWidget *m_labelWidget = nullptr;
QHBoxLayout *m_switchLayout = nullptr;

View File

@ -34,7 +34,6 @@
#include <sstream>
#include <stdio.h>
#include <string>
#include <glib-object.h>
#include <glib.h>
@ -46,7 +45,7 @@ inline QStringList autoStartupDirectorys()
const gchar *config_dir = g_get_user_config_dir();
std::string formatted_result(make_string(g_strdup(config_dir)));//std::string formatted_result = make_string(g_strdup(config_dir));
QString userdirPath = QString::fromStdString(formatted_result);
if (userdirPath.endsWith("/"))
if (userdirPath.endsWith(QLatin1String("/")))
userdirPath = QString("%1autostart").arg(userdirPath);
else
userdirPath = QString("%1/autostart").arg(userdirPath);
@ -59,7 +58,7 @@ inline QStringList autoStartupDirectorys()
for (i = 0; system_data_dirs[i]; i++) {
std::string formatted_result(make_string(g_strdup(system_data_dirs[i])));
QString dirPath = QString::fromStdString(formatted_result);
if (dirPath.endsWith("/"))
if (dirPath.endsWith(QLatin1String("/")))
dirPath = QString("%1gnome/autostart").arg(dirPath);
else
dirPath = QString("%1/gnome/autostart").arg(dirPath);
@ -71,7 +70,7 @@ inline QStringList autoStartupDirectorys()
for (i = 0; system_config_dirs[i]; i++) {
std::string formatted_result(make_string(g_strdup(system_config_dirs[i])));
QString dirPath = QString::fromStdString(formatted_result);
if (dirPath.endsWith("/"))
if (dirPath.endsWith(QLatin1String("/")))
dirPath = dirPath + "autostart";
else
dirPath = dirPath + QLatin1Char('/') + "autostart";
@ -85,7 +84,7 @@ inline QStringList autoStartupDirectorys()
StartupListWidget::StartupListWidget(QWidget *parent) : QListWidget(parent)
{
// this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
this->setFixedWidth(parent->width());
this->setFixedWidth(parent->width() - 2);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
connect(this, &StartupListWidget::itemDoubleClicked, [=] (QListWidgetItem *item) {
@ -93,13 +92,12 @@ StartupListWidget::StartupListWidget(QWidget *parent) : QListWidget(parent)
qDebug() << fileItem->getAppName();
});
//this->m_watherList = new QList<QFileSystemWatcher*>();
//this->m_watcherList = new QList<QFileSystemWatcher*>();
m_startupWorker = new StartupWorker;
m_startupWorker->moveToThread(qApp->thread());
connect(m_startupWorker, SIGNAL(refreshUI()), this, SLOT(onRefreshUI()), Qt::QueuedConnection);
//gsp_app_manager_fill
QStringList autoDir = autoStartupDirectorys();
int i = 0;
/*QList<QString>::Iterator it = autoDir.begin(), itend = autoDir.end();
@ -107,31 +105,20 @@ StartupListWidget::StartupListWidget(QWidget *parent) : QListWidget(parent)
qDebug() << *it;
}*/
foreach (auto dir, autoDir) {
qDebug() << "dir="<<dir;
GspXdgDir xdgDir;
MonitorData monitorData;
if (m_startupWorker->getDirIndex(dir) >= 0) {
i++;
continue;
}
xdgDir.dir = dir;
xdgDir.index = i;
xdgDir.wather = m_startupWorker->createFileSystemMonitor(xdgDir.dir);
monitorData.dir = dir;
monitorData.index = i;
monitorData.watcher = m_startupWorker->createFileSystemMonitor(monitorData.dir);
i++;
// m_startupWorker->appendXdgDirData(xdgDir);//append dir
listAllDesktopFileFromDir(xdgDir);
// GspXdgDir *xdgdir;
// if (gsp_app_manager_get_dir_index (manager, autostart_dirs[i]) >= 0) {
// continue;
// }
// xdgdir = _gsp_xdg_dir_new (autostart_dirs[i], i);
// manager->priv->dirs = g_slist_prepend (manager->priv->dirs,xdgdir);
// _gsp_app_manager_fill_from_dir (manager, xdgdir);
listAllDesktopFileInDirectory(monitorData);
}
this->clear();
this->displayAutoStartupItems();
// qDebug()<<"GenericDataLocation=" << QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
// qDebug()<<"ConfigLocation=" << QStandardPaths::standardLocations(QStandardPaths::ConfigLocation);
// qDebug()<<"DocumentsLocation1=" << QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
@ -160,32 +147,30 @@ StartupListWidget::StartupListWidget(QWidget *parent) : QListWidget(parent)
StartupListWidget::~StartupListWidget()
{
/*qDeleteAll(this->m_watherList->begin(), this->m_watherList->end());
this->m_watherList->clear();
delete this->m_watherList;*/
m_startupWorker->deleteLater();
this->clearUI();
/*for (int i=0; i<m_watherList.count(); i++) {
QFileSystemWatcher *wather = m_watherList.at(i);
// wather->removePath(m_monitorFile);
delete wather;
wather = NULL;
/*qDeleteAll(this->m_watcherList->begin(), this->m_watcherList->end());
this->m_watcherList->clear();
delete this->m_watcherList;*/
/*for (int i=0; i<m_watcherList.count(); i++) {
QFileSystemWatcher *watcher = m_watcherList.at(i);
// watcher->removePath(m_monitorFile);
delete watcher;
watcher = NULL;
}
m_watherList.clear();*/
m_watcherList.clear();*/
// QMap<QString,QVariant>::iterator it; //遍历map
// for (it = m_watherMap.begin(); it != m_watherMap.end(); ++it) {
// for (it = m_watcherMap.begin(); it != m_watcherMap.end(); ++it) {
// QString path = it.key();
// QFileSystemWatcher *wather = static_cast<QFileSystemWatcher *>(it.value());
// wather->removePath(path);
// delete wather;
// wather = NULL;
// QFileSystemWatcher *watcher = static_cast<QFileSystemWatcher *>(it.value());
// watcher->removePath(path);
// delete watcher;
// watcher = NULL;
// }
// m_watherMap.clear();
m_startupWorker->deleteLater();
this->clearUI();
// this->clear();
// m_watcherMap.clear();
}
void StartupListWidget::clearUI()
@ -200,10 +185,21 @@ void StartupListWidget::clearUI()
this->clear();
}
void StartupListWidget::removeItemByName(const QString &appName)
{
QList<StartupItem *> items = findChildren<StartupItem*>();
for (StartupItem *item : items) {
if (item->getAppName() == appName) {
this->removeItemWidget(item->getItem());
item->deleteLater();
break;
}
}
}
void StartupListWidget::onRefreshUI()
{
this->clearUI();
// this->clear();
this->displayAutoStartupItems();
}
@ -219,143 +215,25 @@ void StartupListWidget::displayAutoStartupItems()
this->verticalScrollBar()->setValue(0);
}
///*QFileSystemWatcher **/void StartupListWidget::createFileSystemMonitor(const QString &path)
//{
// /*int fd = inotify_init();
// int wd = inotify_add_watch (fd, path, mask);
//// int ret = inotify_rm_watch (fd, wd);*/
// QFileSystemWatcher *m_fileSystemMonitor = new QFileSystemWatcher(this);
// m_fileSystemMonitor->addPath(path);
//// QFileInfo info(m_monitorFile);
//// m_fileSystemMonitor->addPath(info.absoluteFilePath());
// connect(m_fileSystemMonitor, &QFileSystemWatcher::directoryChanged, [=] (const QString &path) {
// qDebug()<< "directoryChanged path===================="<<path;
// });
//// m_watherList.append(m_fileSystemMonitor);
// if (m_watherMap.contains(path))
// m_watherMap.insert(path, m_fileSystemMonitor);
//// return m_fileSystemMonitor;
//// connect(m_fileSystemMonitor, &QFileSystemWatcher::fileChanged, [=] (const QString &path) {
//// qDebug()<< "fileChanged path===================="<<path;
//// });
//}
//static gboolean
//gsp_app_manager_xdg_dir_monitor (GFileMonitor *monitor,
// GFile *child,
// GFile *other_file,
// GFileMonitorEvent flags,
// gpointer data)
//{
// GspAppManager *manager;
// GspApp *old_app;
// GspApp *app;
// GFile *parent;
// char *basename;
// char *dir;
// char *path;
// int index;
// manager = GSP_APP_MANAGER (data);
// basename = g_file_get_basename (child);
// if (!g_str_has_suffix (basename, ".desktop")) {
// /* not a desktop file, we can ignore */
// g_free (basename);
// return TRUE;
// }
// old_app = gsp_app_manager_find_app_with_basename (manager, basename);
// parent = g_file_get_parent (child);
// dir = g_file_get_path (parent);
// g_object_unref (parent);
// index = gsp_app_manager_get_dir_index (manager, dir);
// if (index < 0) {
// /* not a directory we know; should never happen, though */
// g_free (dir);
// return TRUE;
// }
// path = g_file_get_path (child);
// switch (flags) {
// case G_FILE_MONITOR_EVENT_CHANGED:
// case G_FILE_MONITOR_EVENT_CREATED:
// /* we just do as if it was a new file: GspApp is clever enough
// * to do the right thing */
// app = gsp_app_new (path, (unsigned int) index);
// /* we didn't have this app before, so add it */
// if (old_app == NULL && app != NULL) {
// gsp_app_manager_add (manager, app);
// g_object_unref (app);
// }
// /* else: it was just updated, GspApp took care of
// * sending the event */
// break;
// case G_FILE_MONITOR_EVENT_DELETED:
// if (!old_app) {
// /* it got deleted, but we don't know about it, so
// * nothing to do */
// break;
// }
// _gsp_app_manager_handle_delete (manager, old_app,
// basename, index);
// break;
// default:
// break;
// }
// g_free (path);
// g_free (dir);
// g_free (basename);
// return TRUE;
//}
//_gsp_app_manager_fill_from_dir
void StartupListWidget::listAllDesktopFileFromDir(GspXdgDir xdgDir)
void StartupListWidget::listAllDesktopFileInDirectory(MonitorData monitorData)
{
//start to call monitor
// GFile *file;
// GDir *dir;
// const char *name;
// file = g_file_new_for_path (xdgDir.dir.toStdString().data());
// xdgdir->monitor = g_file_monitor_directory (file, G_FILE_MONITOR_NONE,NULL, NULL);
// g_object_unref (file);
// if (xdgdir->monitor) {
// g_signal_connect (xdgdir->monitor, "changed",G_CALLBACK (gsp_app_manager_xdg_dir_monitor),manager);
// }
monitorData.fileList.clear();
// m_startupWorker->createFileSystemMonitor(xdgDir.dir);
xdgDir.fileList.clear();
QDirIterator dir(xdgDir.dir, QDirIterator::Subdirectories);
QDirIterator dir(monitorData.dir, QDirIterator::Subdirectories);
while(dir.hasNext()) {
if (dir.fileInfo().suffix() == "desktop") {
QString desktopFile = dir.filePath();//dir.fileName().toLower()
// qDebug() << "desktopFile="<<desktopFile;
xdgDir.fileList.append(desktopFile);
m_startupWorker->newStartupInfo(desktopFile, xdgDir.index);
monitorData.fileList.append(desktopFile);
m_startupWorker->newStartupInfo(desktopFile, monitorData.index);
}
dir.next();
}
m_startupWorker->appendXdgDirData(xdgDir);//append xdgdir
m_startupWorker->appendMonitorXdgDirData(monitorData);
}
//gsp_app_set_enabled (gboolean enabled)
void StartupListWidget::setAppAutoStartup(/*StartupData info,*/const QString &exec, bool enabled)
void StartupListWidget::setAppAutoStartup(const QString &exec, bool enabled)
{
StartupData info = m_startupWorker->getStartupInfo(exec);
// qDebug() << "info.enabled="<<info.enabled << ",enabled="<<enabled;
if (info.enabled == enabled)
return;
@ -363,7 +241,7 @@ void StartupListWidget::setAppAutoStartup(/*StartupData info,*/const QString &ex
info.save_mask |= SAVE_MASK_ENABLED;
m_startupWorker->updateEnable(info.exec, info.enabled);
m_startupWorker->updateSaveMask(info.exec, info.save_mask);
m_startupWorker->_gsp_app_queue_save(info);
m_startupWorker->readySaveDesktopInfo(info);
}
void StartupListWidget::loadItem(StartupData info)
@ -371,7 +249,7 @@ void StartupListWidget::loadItem(StartupData info)
StartupItem *item = new StartupItem(info);
connect(item, SIGNAL(changeStartup(QString,bool)), this, SLOT(onChangeStartup(QString,bool)));
connect(item, SIGNAL(enter()), this, SLOT(onMouseEnter()));
addItem(item->getItem());
this->addItem(item->getItem());
item->getItem()->setSizeHint(QSize(this->width() - 10, 60));
setItemWidget(item->getItem(), item);
}
@ -379,19 +257,15 @@ void StartupListWidget::loadItem(StartupData info)
void StartupListWidget::loadItems(QStringList items, int scrollValue)
{
// clear();
// foreach (auto item, items) {
// loadItem(item);
// }
// this->verticalScrollBar()->setValue(scrollValue);
}
void StartupListWidget::onChangeStartup(const QString &exec, bool active)
{
// QString appName = ((StartupItem*) sender())->getAppName();
// StartupData data = m_startupWorker->getStartupInfo(exec);
this->setAppAutoStartup(/*data,*/exec, active);
this->setAppAutoStartup(exec, active);
}
void StartupListWidget::onMouseEnter()

View File

@ -27,7 +27,6 @@
#include <QListWidget>
class QFileSystemWatcher;
class StartupWorker;
class StartupData;
class StartupListWidget : public QListWidget
@ -42,11 +41,9 @@ public:
void clearUI();
void loadItem(StartupData info);
void loadItems(QStringList items, int scrollValue);
void listAllDesktopFileFromDir(GspXdgDir xdgDir);
void setAppAutoStartup(/*StartupData info,*/const QString &exec, bool enabled);
// /*QFileSystemWatcher **/void createFileSystemMonitor(const QString &path);
void listAllDesktopFileInDirectory(MonitorData monitorData);
void setAppAutoStartup(const QString &exec, bool enabled);
void removeItemByName(const QString &appName);
public slots:
void onChangeStartup(const QString &exec, bool active);
@ -55,8 +52,8 @@ public slots:
private:
StartupWorker *m_startupWorker = nullptr;
// QList <QFileSystemWatcher*> m_watherList;//QList<QFileSystemWatcher*> *m_watherList;
// QMap<QString, QFileSystemWatcher*> m_watherMap;
// QList <QFileSystemWatcher*> m_watcherList;//QList<QFileSystemWatcher*> *m_watcherList;
// QMap<QString, QFileSystemWatcher*> m_watcherMap;
};
#endif // STARTUPLISTWIDGET_H

View File

@ -2,6 +2,8 @@
#
# Project created by QtCreator 2015-01-26T09:16:38
#
# Functional code references "gnome-session" (gnome-session-properties)
#
#-------------------------------------------------
QT += core
@ -35,7 +37,7 @@ HEADERS += \
../widgets/mytristatebutton.h \
startuplistwidget.h \
startupitem.h \
../../component/kylinswitcher.h \
../../component/myswitcher.h \
startupworker.h \
startupdata.h \
util.h
@ -47,9 +49,8 @@ SOURCES += \
../widgets/mytristatebutton.cpp \
startuplistwidget.cpp \
startupitem.cpp \
../../component/kylinswitcher.cpp \
../../component/myswitcher.cpp \
startupworker.cpp \
# startupdata.cpp \
util.cpp
OTHER_FILES += \

View File

@ -34,7 +34,7 @@ StartupTitleWidget::StartupTitleWidget(QWidget *parent)
setMouseTracking(true);
setFixedHeight(39);
m_topBorderColor = QColor(255, 255, 255, 153);
// m_topBorderColor = QColor(255, 255, 255, 153);
this->setAutoFillBackground(true);
QPalette palette;
palette.setColor(QPalette::Background, QColor("#0d87ca"));
@ -61,7 +61,7 @@ StartupTitleWidget::~StartupTitleWidget()
delete m_layout;
}
void StartupTitleWidget::paintEvent(QPaintEvent *e)
/*void StartupTitleWidget::paintEvent(QPaintEvent *e)
{
QFrame::paintEvent(e);
@ -76,7 +76,7 @@ void StartupTitleWidget::paintEvent(QPaintEvent *e)
tPath.lineTo(QPointF(x() + width(), y() + borderHeight - 0.5));
p.setPen(QPen(tc));
p.drawPath(tPath);
}
}*/
void StartupTitleWidget::initLeftContent()
{

View File

@ -35,11 +35,11 @@ public:
void initRightContent();
void initWidgets();
protected:
void paintEvent(QPaintEvent *e) override;
//protected:
// void paintEvent(QPaintEvent *e) override;
private:
QColor m_topBorderColor;
// QColor m_topBorderColor;
QHBoxLayout *m_layout;
QHBoxLayout *m_lLayout;
QHBoxLayout *m_rLayout;

View File

@ -40,7 +40,7 @@ QDataStream &operator<<(QDataStream &dataStream, const StartupDataPtr &object)
auto ptrval = reinterpret_cast<qulonglong>(ptr);
auto var = QVariant::fromValue(ptrval);
dataStream << var;
return dataStream;
return dataStream;
}
QDataStream &operator>>(QDataStream &dataStream, StartupDataPtr &object)
@ -53,25 +53,6 @@ QDataStream &operator>>(QDataStream &dataStream, StartupDataPtr &object)
return dataStream;
}
//QDataStream &operator<<(QDataStream &dataStream, const GspXdgDirPtr &object)
//{
// auto ptr = object.data();
// auto ptrval = reinterpret_cast<qulonglong>(ptr);
// auto var = QVariant::fromValue(ptrval);
// dataStream << var;
// return dataStream;
//}
//QDataStream &operator>>(QDataStream &dataStream, GspXdgDirPtr &object)
//{
// QVariant var;
// dataStream >> var;
// qulonglong ptrval = var.toULongLong();
// auto ptr = reinterpret_cast<GspXdgDir *>(ptrval);
// object = GspXdgDirPtr(ptr);
// return dataStream;
//}
StartupWidget::StartupWidget(QWidget *parent)
: QFrame(parent)
, mousePressed(false)
@ -81,12 +62,6 @@ StartupWidget::StartupWidget(QWidget *parent)
qRegisterMetaType<StartupDataPtrList>();
qRegisterMetaType<QList<StartupData>>();
// qRegisterMetaType<GspXdgDirPtr>();
// qRegisterMetaTypeStreamOperators<GspXdgDirPtr>();
// qRegisterMetaType<GspXdgDirPtrList>();
// qRegisterMetaType<QList<GspXdgDir>>();
this->setWindowFlags(this->windowFlags() | Qt::FramelessWindowHint | Qt::WindowCloseButtonHint);//去掉边框
this->setAttribute(Qt::WA_TranslucentBackground);//背景透明
@ -96,18 +71,19 @@ StartupWidget::StartupWidget(QWidget *parent)
this->setFixedSize(500, 645);
m_titleWidget = new StartupTitleWidget(this);
m_titleWidget->setFixedSize(this->width(), 39);
m_titleWidget->setFixedSize(this->width() - 2, 39);
m_layout = new QVBoxLayout();
m_layout->setSpacing(0);
m_layout->setMargin(0);
m_layout->setContentsMargins(0,0,0,0);
setLayout(m_layout);
m_layout->setContentsMargins(1,1,1,1);
m_startupView = new StartupListWidget(this);
m_layout->addWidget(m_titleWidget, 0, Qt::AlignTop);
m_layout->addWidget(m_startupView, 0, Qt::AlignHCenter);
this->setLayout(m_layout);
this->moveCenter();
}
@ -147,16 +123,6 @@ void StartupWidget::closeEvent(QCloseEvent *event)
event->accept();
}
void StartupWidget::paintEvent(QPaintEvent *)
{
QPainter painter(this);
QPainterPath path;
path.addRect(QRectF(rect()));
painter.setOpacity(1);
painter.fillPath(path, QColor("#FFFFFF"));
}
void StartupWidget::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
@ -183,3 +149,25 @@ void StartupWidget::mouseMoveEvent(QMouseEvent *event)
QFrame::mouseMoveEvent(event);
}
void StartupWidget::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
//绘制圆角矩形
painter.setPen(QPen(QColor("#0d87ca"), 0));//边框颜色 #3f96e4
painter.setBrush(QColor("#e9eef0"));//背景色
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setOpacity(1);
QRectF r(0 / 2.0, 0 / 2.0, width() - 0, height() - 0);//左边 上边 右边 下边
painter.drawRoundedRect(r, 4, 4);
//绘制背景色
// QPainterPath path;
// path.addRect(QRectF(rect()));
// painter.setOpacity(1);
// painter.fillPath(path, QColor("#ffffff"));
QFrame::paintEvent(event);
}

File diff suppressed because it is too large Load Diff

View File

@ -21,50 +21,12 @@
#ifndef STARTUPWORKER_H
#define STARTUPWORKER_H
#include "startupdata.h"
#include <QObject>
#include <QMap>
#include <QFileSystemWatcher>
#include "startupdata.h"
#define KEY_FILE_DESKTOP_GROUP "Desktop Entry"
#define KEY_FILE_DESKTOP_KEY_HIDDEN "Hidden"
#define KEY_FILE_DESKTOP_KEY_NO_DISPLAY "NoDisplay"
#define KEY_FILE_DESKTOP_KEY_ONLY_SHOW_IN "OnlyShowIn"
#define KEY_FILE_DESKTOP_KEY_NOT_SHOW_IN "NotShowIn"
#define KEY_FILE_DESKTOP_KEY_AUTOSTART_ENABLED "X-GNOME-Autostart-enabled"
#define KEY_FILE_DESKTOP_KEY_NAME "Name"
#define KEY_FILE_DESKTOP_KEY_EXEC "Exec"
#define KEY_FILE_DESKTOP_KEY_TRY_EXEC "TryExec"
#define KEY_FILE_DESKTOP_KEY_COMMENT "Comment"
#define KEY_FILE_DESKTOP_KEY_ICON "Icon"
#define KEY_FILE_DESKTOP_KEY_TYPE "Type"
#define KEY_FILE_DESKTOP_TYPE_APPLICATION "Application"
#define KEY_FILE_DESKTOP_TYPE_LINK "Link"
#define KEY_FILE_DESKTOP_KEY_URL "URL"
#define KEY_FILE_DESKTOP_KEY_STARTUP_NOTIFY "StartupNotify"
#define KEY_FILE_DESKTOP_KEY_CATEGORIES "Categories"
#define KEY_FILE_DESKTOP_KEY_MIME_TYPE "MimeType"
#define KEY_FILE_DESKTOP_KEY_TERMINAL "Terminal"
#define KEY_FILE_DESKTOP_TYPE_DIRECTORY "Directory"
#define SAVE_MASK_HIDDEN 0x0001
#define SAVE_MASK_ENABLED 0x0002
#define SAVE_MASK_NAME 0x0004
#define SAVE_MASK_EXEC 0x0008
#define SAVE_MASK_COMMENT 0x0010
#define SAVE_MASK_NO_DISPLAY 0x0020
#define SAVE_MASK_ALL 0xffff
/*typedef struct {
QString dir;
int index;
QFileSystemWatcher *wather;
QStringList fileList;
// GFileMonitor *monitor;
} GspXdgDir;*/
class StartupWorker : public QObject
{
Q_OBJECT
@ -72,6 +34,7 @@ class StartupWorker : public QObject
public:
explicit StartupWorker(QObject *parent = 0);
~StartupWorker();
void newStartupInfo(const QString &desktopFile, unsigned int xdg_position);
bool isExecContains(const QString &exec);
QList<StartupData> getStartupInfoList() const;
@ -82,8 +45,6 @@ public:
void updateGspXdgDir(const QString &dir, QStringList fileList);
QString getStringValueAccordKeyFromDesktopFile(const gchar *key, const QString &desktopFile, bool isLocale = false);
// void gsp_key_file_ensure_C_key(QString filename, QString key, QString locale);
void updateEnable(const QString &exec, bool enabled);
void updateSaveMask(const QString &exec, unsigned int save_mask);
void updateXdgPosition(const QString &exec, unsigned int xdg_position);
@ -91,26 +52,25 @@ public:
void updateOldSystemPath(const QString &exec, QString old_system_path);
void updatePath(const QString &exec, QString path);
void appendXdgDirData(GspXdgDir xdgDir);
void appendMonitorXdgDirData(MonitorData monitorData);
int getDirIndex(QString dir);
QString gsp_app_manager_get_dir(unsigned int index);
QList<GspXdgDir> getAllDirs() { /*return dirs;*/ return this->m_xdgMap.values(); }
QString getMonitorDirectoryAccordXdgSystemPosition(unsigned int index);
QList<MonitorData> getAllDirs() { /*return m_monitorList;*/ return this->m_xdgMap.values(); }
void _gsp_ensure_user_autostart_dir(void);
void _gsp_app_save_done_success (StartupData info);
// bool _gsp_app_user_equal_system (StartupData info, QString &system_path, QString locale);
bool _gsp_app_user_equal_system (StartupData info, char **system_path);
bool _gsp_app_save(StartupData info);
void _gsp_app_queue_save(StartupData info);
StartupData gsp_app_manager_find_app_with_basename(QString &basename);
void ensureUserAutostartupDirExists(void);
void changeSaveFlagsWhenDoneSuccess (StartupData info);
// bool isDesktopFileInUserAndSystemConfiguDir (StartupData info, QString &system_path, QString locale);//Qt
bool isDesktopFileInUserAndSystemConfiguDir (StartupData info, char **system_path);//glibc
bool saveAppDesktopInfo(StartupData info);
void readySaveDesktopInfo(StartupData info);
StartupData getAppStartupDataAccrodDesktopFileName(QString &basename);
signals:
void refreshUI();
private:
QMap<QString, StartupData> m_startupInfoList;
QList<GspXdgDir> dirs;
QMap<QString, GspXdgDir> m_xdgMap;
QMap<QString, MonitorData> m_xdgMap;//QList<MonitorData> m_monitorList;
};
#endif // STARTUPWORKER_H

View File

@ -1,20 +1,30 @@
/*
*
* Copyright (C) 2008, 2009 Novell, Inc.
* Copyright (C) 1999 Free Software Foundation, Inc.
* Copyright (C) 2007, 2009 Vincent Untz.
* Copyright (C) 2008 Lucas Rocha.
* Copyright (C) 2008 William Jon McCann <jmccann@redhat.com>
* 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; either version 2 of the
* License, or (at your option) any later version.
*
* 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.
* 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 <http://www.gnu.org/licenses/>.
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* Authors:
* Vincent Untz <vuntz@gnome.org>
* Kobe Lee xiangli@ubuntukylin.com/kobe24_lixiang@126.com
*/
#include "util.h"
@ -33,3 +43,170 @@ std::string make_string(char *c_str)
g_free(c_str);
return s;
}
gboolean get_boolean_from_desktop_file(GKeyFile *keyfile, const gchar *key, gboolean default_value)
{
GError *error;
gboolean retval;
error = NULL;
retval = g_key_file_get_boolean(keyfile, G_KEY_FILE_DESKTOP_GROUP, key, &error);
if (error != NULL) {
retval = default_value;
g_error_free(error);
}
return retval;
}
gboolean write_contents_into_desktop_file(GKeyFile *keyfile, const gchar *path, GError **error)
{
GError *write_error;
gchar *data;
gsize length;
gboolean res;
g_return_val_if_fail(keyfile != NULL, FALSE);
g_return_val_if_fail(path != NULL, FALSE);
write_error = NULL;
data = g_key_file_to_data(keyfile, &length, &write_error);
if (write_error) {
g_propagate_error(error, write_error);
return FALSE;
}
res = g_file_set_contents(path, data, length, &write_error);
g_free(data);
if (write_error) {
g_propagate_error (error, write_error);
return FALSE;
}
return res;
}
void write_default_error_info_to_desktop_file(GKeyFile *keyfile)
{
kylin_start_manager_key_file_set_string(keyfile, G_KEY_FILE_DESKTOP_KEY_TYPE, "Application");
kylin_start_manager_key_file_set_string(keyfile, G_KEY_FILE_DESKTOP_KEY_EXEC, "/bin/false");
}
void set_locale_string_into_desktop_file(GKeyFile *keyfile, const gchar *key, const gchar *value)
{
const char *locale;
const char * const *langs_pointer;
int i;
if (value == NULL) {
value = "";
}
locale = NULL;
langs_pointer = g_get_language_names ();
for (i = 0; langs_pointer[i] != NULL; i++) {
/* find first without encoding */
if (strchr (langs_pointer[i], '.') == NULL) {
locale = langs_pointer[i];
break;
}
}
if (locale != NULL) {
g_key_file_set_locale_string(keyfile, G_KEY_FILE_DESKTOP_GROUP, key, locale, value);
}
else {
g_key_file_set_string(keyfile, G_KEY_FILE_DESKTOP_GROUP, key, value);
}
}
gboolean get_shown_from_desktop_file(GKeyFile *keyfile, const char *current_desktop)
{
char **only_show_in, **not_show_in;
gboolean found;
int i;
if (!current_desktop)
return TRUE;
only_show_in = g_key_file_get_string_list(keyfile, G_KEY_FILE_DESKTOP_GROUP,
G_KEY_FILE_DESKTOP_KEY_ONLY_SHOW_IN, NULL, NULL);
if (only_show_in) {
found = FALSE;
for (i = 0; only_show_in[i] != NULL; i++) {
if (g_strcmp0 (current_desktop, only_show_in[i]) == 0) {
found = TRUE;
break;
}
}
g_strfreev (only_show_in);
if (!found)
return FALSE;
}
not_show_in = g_key_file_get_string_list(keyfile, G_KEY_FILE_DESKTOP_GROUP,
G_KEY_FILE_DESKTOP_KEY_NOT_SHOW_IN, NULL, NULL);
if (not_show_in) {
found = FALSE;
for (i = 0; not_show_in[i] != NULL; i++) {
if (g_strcmp0 (current_desktop, not_show_in[i]) == 0) {
found = TRUE;
break;
}
}
g_strfreev (not_show_in);
if (found)
return FALSE;
}
return TRUE;
}
char *get_current_desktop_env()
{
static char *current_desktop = NULL;
/* Support XDG_CURRENT_DESKTOP environment variable; this can be used
* to abuse gnome-session in non-GNOME desktops. */
if (!current_desktop) {
const char *desktop;
desktop = g_getenv("XDG_CURRENT_DESKTOP");
/* Note: if XDG_CURRENT_DESKTOP is set but empty, do as if it
* was not set */
if (!desktop || desktop[0] == '\0')
current_desktop = g_strdup ("GNOME");
else
current_desktop = g_strdup (desktop);
}
/* Using "*" means skipping desktop-related checks */
if (g_strcmp0(current_desktop, "*") == 0)
return NULL;
return current_desktop;
}
gboolean is_str_equal(const char *a, const char *b)
{
if (g_strcmp0 (a, b) == 0) {
return TRUE;
}
if (a && !b && a[0] == '\0') {
return TRUE;
}
if (b && !a && b[0] == '\0') {
return TRUE;
}
return FALSE;
}

View File

@ -17,6 +17,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <glib.h>
#include <iostream>
#include <map>
@ -25,4 +27,49 @@
using std::string;
#define KEY_FILE_DESKTOP_GROUP "Desktop Entry"
#define KEY_FILE_DESKTOP_KEY_HIDDEN "Hidden"
#define KEY_FILE_DESKTOP_KEY_NO_DISPLAY "NoDisplay"
#define KEY_FILE_DESKTOP_KEY_ONLY_SHOW_IN "OnlyShowIn"
#define KEY_FILE_DESKTOP_KEY_NOT_SHOW_IN "NotShowIn"
#define KEY_FILE_DESKTOP_KEY_AUTOSTART_ENABLED "X-GNOME-Autostart-enabled"
#define KEY_FILE_DESKTOP_KEY_NAME "Name"
#define KEY_FILE_DESKTOP_KEY_EXEC "Exec"
#define KEY_FILE_DESKTOP_KEY_TRY_EXEC "TryExec"
#define KEY_FILE_DESKTOP_KEY_COMMENT "Comment"
#define KEY_FILE_DESKTOP_KEY_ICON "Icon"
#define KEY_FILE_DESKTOP_KEY_TYPE "Type"
#define KEY_FILE_DESKTOP_TYPE_APPLICATION "Application"
#define KEY_FILE_DESKTOP_TYPE_LINK "Link"
#define KEY_FILE_DESKTOP_KEY_URL "URL"
#define KEY_FILE_DESKTOP_KEY_STARTUP_NOTIFY "StartupNotify"
#define KEY_FILE_DESKTOP_KEY_CATEGORIES "Categories"
#define KEY_FILE_DESKTOP_KEY_MIME_TYPE "MimeType"
#define KEY_FILE_DESKTOP_KEY_TERMINAL "Terminal"
#define KEY_FILE_DESKTOP_TYPE_DIRECTORY "Directory"
#define SAVE_MASK_HIDDEN 0x0001
#define SAVE_MASK_ENABLED 0x0002
#define SAVE_MASK_NAME 0x0004
#define SAVE_MASK_EXEC 0x0008
#define SAVE_MASK_COMMENT 0x0010
#define SAVE_MASK_NO_DISPLAY 0x0020
#define SAVE_MASK_ALL 0xffff
#define kylin_start_manager_key_file_get_string(key_file, key) \
g_key_file_get_string(key_file, G_KEY_FILE_DESKTOP_GROUP, key, NULL)
#define kylin_start_manager_key_file_get_locale_string(key_file, key) \
g_key_file_get_locale_string(key_file, G_KEY_FILE_DESKTOP_GROUP, key, NULL, NULL)
#define kylin_start_manager_key_file_set_boolean(key_file, key, value) \
g_key_file_set_boolean(key_file, G_KEY_FILE_DESKTOP_GROUP, key, value)
#define kylin_start_manager_key_file_set_string(key_file, key, value) \
g_key_file_set_string(key_file, G_KEY_FILE_DESKTOP_GROUP, key, value)
std::string make_string(char *c_str);
gboolean get_boolean_from_desktop_file(GKeyFile *keyfile, const gchar *key, gboolean default_value);
gboolean write_contents_into_desktop_file (GKeyFile *keyfile, const gchar *path, GError **error);
void write_default_error_info_to_desktop_file(GKeyFile *keyfile);
void set_locale_string_into_desktop_file(GKeyFile *keyfile, const gchar *key, const gchar *value);
gboolean get_shown_from_desktop_file(GKeyFile *keyfile, const char *current_desktop);
char *get_current_desktop_env();
gboolean is_str_equal(const char *a, const char *b);

View File

@ -27,6 +27,8 @@
#include "filesystemdata.h"
#include "filesystemworker.h"
#include "filesystemwatcher.h"
FileSystemDialog::FileSystemDialog(QList<bool> toBeDisplayedColumns, QSettings *settings, QWidget *parent)
:QWidget(parent)
,proSettings(settings)
@ -61,10 +63,18 @@ FileSystemDialog::FileSystemDialog(QList<bool> toBeDisplayedColumns, QSettings *
this->refreshFileSysList();
//refresh file system info every 5 minutes
m_fileSystemWatcher = FileSystemWatcher::instance();
connect(m_fileSystemWatcher, &FileSystemWatcher::deviceAdded, this, [=] (const QString &dev) {
this->refreshFileSysList();
});
connect(m_fileSystemWatcher, &FileSystemWatcher::deviceRemoved, this, [=] (const QString &dev) {
this->refreshFileSysList();
});
//refresh file system info every 10 minutes
m_timer = new QTimer(this);
connect(m_timer,SIGNAL(timeout()),this,SLOT(refreshFileSysList()));
m_timer->start(5000);
m_timer->start(10000);
}
FileSystemDialog::~FileSystemDialog()
@ -89,10 +99,8 @@ FileSystemDialog::~FileSystemDialog()
void FileSystemDialog::refreshFileSysList()
{
m_fileSystemWorker->onFileSystemListChanged();
QList<FileSystemListItem*> items;
for (FileSystemData *info : m_fileSystemWorker->diskInfoList()) {
FileSystemListItem *item = new FileSystemListItem(info);

View File

@ -23,10 +23,9 @@
#include <QFileSystemWatcher>
#include "filesystemlistwidget.h"
//class DiskItemList;
//class DiskModel;
class FileSystemData;
class FileSystemWorker;
class FileSystemWatcher;
class QVBoxLayout;
class QHBoxLayout;
@ -38,7 +37,7 @@ public:
explicit FileSystemDialog(QList<bool> toBeDisplayedColumns, QSettings *settings, QWidget* parent = 0);
~FileSystemDialog();
FileSystemListWidget* getFileSysView();
FileSystemListWidget *getFileSysView();
void initFileSystemMonitor();
public slots:
@ -53,9 +52,6 @@ signals:
// bool event(QEvent *event);
private:
// QVBoxLayout *m_centralLayout = nullptr;
// DiskItemList *m_diskItemList;
// DiskModel *m_diskModelList;
FileSystemWorker *m_fileSystemWorker = nullptr;
// QFileSystemWatcher *m_fileSystemMonitor = nullptr;
// QString m_monitorFile;
@ -65,4 +61,5 @@ private:
QMenu *m_menu = nullptr;
QVBoxLayout *m_layout = nullptr;
QTimer *m_timer = nullptr;
FileSystemWatcher *m_fileSystemWatcher = nullptr;
};

View File

@ -0,0 +1,79 @@
#include "filesystemwatcher.h"
#include "util.h"
#include <QDebug>
FileSystemWatcher *FileSystemWatcher::m_watcher = NULL;
FileSystemWatcher *FileSystemWatcher::instance()
{
if (!m_watcher) {
m_watcher = new FileSystemWatcher;
m_watcher->initWatcher();
}
return m_watcher;
}
FileSystemWatcher::FileSystemWatcher(QObject *parent)
: QObject(parent)
,m_fd(-1)
{
}
FileSystemWatcher::~FileSystemWatcher()
{
this->clearWatcher();
}
bool FileSystemWatcher::initWatcher()
{
m_origFileSet = getFileContentsLineByLine(DEVICE_MOUNT_PONINT_RECORD_FILE);
m_fd = open(DEVICE_MOUNT_PONINT_RECORD_FILE, O_RDONLY);
if (m_fd == -1) {
qDebug() << QString("open %1 failed!").arg(DEVICE_MOUNT_PONINT_RECORD_FILE);
return false;
}
m_socketNotifier = new QSocketNotifier(m_fd, QSocketNotifier::Write, this);
m_socketNotifier->setEnabled(true);
connect(m_socketNotifier, &QSocketNotifier::activated, this, &FileSystemWatcher::onMountDeviceFileContentsChanged);
return true;
}
bool FileSystemWatcher::watcherInitSuccess()
{
if (m_fd != -1 && m_socketNotifier) {
return true;
}
else {
return false;
}
}
bool FileSystemWatcher::clearWatcher()
{
if (this->watcherInitSuccess()) {
close(m_fd);
m_fd = -1;
delete m_socketNotifier;
m_socketNotifier = nullptr;
return true;
}
else {
return false;
}
}
void FileSystemWatcher::onMountDeviceFileContentsChanged()
{
QSet<QString> nowFileSet = getFileContentsLineByLine(DEVICE_MOUNT_PONINT_RECORD_FILE);
for(const QString &mountPath: nowFileSet - m_origFileSet) {
emit this->deviceAdded(getDeviceMountedPointPath(mountPath));
}
for(const QString &mountPath: m_origFileSet - nowFileSet) {
emit this->deviceRemoved(getDeviceMountedPointPath(mountPath));
}
m_origFileSet = nowFileSet;
}

View File

@ -0,0 +1,37 @@
#ifndef FILESYSTEMWATCHER_H
#define FILESYSTEMWATCHER_H
#include <QObject>
#include <QSet>
#include <QSocketNotifier>
class FileSystemWatcher : public QObject
{
Q_OBJECT
public:
static FileSystemWatcher *instance();
FileSystemWatcher(QObject *parent = 0);
~FileSystemWatcher();
bool watcherInitSuccess();
signals:
void deviceAdded(const QString &addDevice);
void deviceRemoved(const QString &removeDevice);
public slots:
bool initWatcher();
bool clearWatcher();
private slots:
void onMountDeviceFileContentsChanged();
private:
int m_fd;
QSocketNotifier *m_socketNotifier = nullptr;
QSet<QString> m_origFileSet;
static FileSystemWatcher *m_watcher;
};
#endif // FILESYSTEMWATCHER_H

View File

@ -91,14 +91,14 @@ SystemMonitor::~SystemMonitor()
void SystemMonitor::resizeEvent(QResizeEvent *e)
{
if (m_titleWidget) {
m_titleWidget->resize(width(), MONITOR_TITLE_WIDGET_HEIGHT);
m_titleWidget->resize(width() - 2, MONITOR_TITLE_WIDGET_HEIGHT);
if (e->oldSize() != e->size()) {
emit m_titleWidget->updateMaxBtn();
}
}
if (m_sysMonitorStack) {
m_sysMonitorStack->resize(width(), this->height() - MONITOR_TITLE_WIDGET_HEIGHT);
m_sysMonitorStack->move(0, MONITOR_TITLE_WIDGET_HEIGHT);
m_sysMonitorStack->resize(width() - 2, this->height() - MONITOR_TITLE_WIDGET_HEIGHT - 2);
m_sysMonitorStack->move(1, MONITOR_TITLE_WIDGET_HEIGHT + 1);
}
}
@ -210,8 +210,8 @@ void SystemMonitor::initPanelStack()
m_sysMonitorStack = new QStackedWidget(this);
m_sysMonitorStack->setStyleSheet("QStackedWidget{background: rgb(255, 255, 255);}");
m_sysMonitorStack->setObjectName("SystemMonitorStack");
m_sysMonitorStack->resize(width(), this->height() - TITLE_WIDGET_HEIGHT);
m_sysMonitorStack->move(0, TITLE_WIDGET_HEIGHT);
m_sysMonitorStack->resize(width() - 2, this->height() - TITLE_WIDGET_HEIGHT);
m_sysMonitorStack->move(1, TITLE_WIDGET_HEIGHT);
m_sysMonitorStack->setMouseTracking(false);
m_sysMonitorStack->installEventFilter(this);
@ -236,8 +236,8 @@ void SystemMonitor::initPanelStack()
void SystemMonitor::initTitleWidget()
{
m_titleWidget = new MonitorTitleWidget(proSettings, this);
m_titleWidget->resize(width(), MONITOR_TITLE_WIDGET_HEIGHT);
m_titleWidget->move(0, 0);
m_titleWidget->resize(width() - 2, MONITOR_TITLE_WIDGET_HEIGHT);
m_titleWidget->move(1, 1);
}
void SystemMonitor::initConnections()
@ -368,12 +368,13 @@ void SystemMonitor::paintEvent(QPaintEvent *event)
// painter.setOpacity(1);
// painter.fillPath(path, QColor("#FFFFFF"));
//绘制圆角矩形
painter.setPen(QPen(QColor("#e9eef0"), 0));//边框颜色 QColor(255, 255, 255, 153)
painter.setBrush(QColor("#ffffff"));//背景色 #0d87ca
painter.setPen(QPen(QColor("#0d87ca"), 0));//边框颜色 #3f96e4
painter.setBrush(QColor("#e9eef0"));//背景色
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setOpacity(1);
QRectF r(1, 1, width() - 2, height() - 2);//左边 上边 右边 下边
painter.drawRoundedRect(r, 5, 5);
QRectF r(0 / 2.0, 0 / 2.0, width() - 0, height() - 0);//左边 上边 右边 下边
painter.drawRoundedRect(r, 4, 4);
QFrame::paintEvent(event);
}

View File

@ -64,7 +64,8 @@ HEADERS += \
resourcesindicator.h \
resourcescategory.h \
filesystemlistwidget.h \
filesystemlistitem.h
filesystemlistitem.h \
filesystemwatcher.h
SOURCES += \
systemmonitor.cpp \
@ -100,7 +101,8 @@ SOURCES += \
resourcesindicator.cpp \
resourcescategory.cpp \
filesystemlistwidget.cpp \
filesystemlistitem.cpp
filesystemlistitem.cpp \
filesystemwatcher.cpp
OTHER_FILES += \
systemmonitor.json

View File

@ -262,3 +262,30 @@ QString formatByteCount(double v)
return formatUnitSize(v, orders, sizeof(orders)/sizeof(orders[0]));
}
QString getDeviceMountedPointPath(const QString &line)
{
const QStringList items = line.split(" ");
if (items.length() > 4) {
return items.at(1);
}
else {
return "";
}
}
QString getFileContent(const QString &filePath)
{
QFile fd(filePath);
QString fileContent = "";
if (fd.open(QFile::ReadOnly)) {
fileContent = QLatin1String(fd.readAll());
fd.close();
}
return fileContent;
}
QSet<QString> getFileContentsLineByLine(const QString &filePath)
{
QString fileContent = getFileContent(filePath);
return QSet<QString>::fromList(fileContent.split("\n"));
}

View File

@ -18,14 +18,20 @@
*/
#include <glib.h>
#include <fcntl.h>
#include <unistd.h>
#include <iostream>
#include <map>
#include <QString>
#include <QSet>
#include <QFile>
#include <QTextStream>
#include <QObject>
#include <QPainter>
#define MONITOR_TITLE_WIDGET_HEIGHT 77
#define TITLE_WIDGET_HEIGHT 39
#define DEVICE_MOUNT_PONINT_RECORD_FILE "/proc/mounts"
using std::string;
@ -39,3 +45,6 @@ QString formatUnitSize(double v, const char** orders, int nb_orders);
QString formatByteCount(double v);
void setFontSize(QPainter &painter, int textSize);
QString formatDurationForDisplay(unsigned centiseconds);
QString getDeviceMountedPointPath(const QString &line);
QString getFileContent(const QString &filePath);
QSet<QString> getFileContentsLineByLine(const QString &filePath);

View File

@ -28,6 +28,39 @@
//#include "cameramanager.h"
#include "../component/threadpool.h"
#include "dataworker.h"
#include "../qdbusservice/systemdbus/data/systemdbusproxy.h"
#include "../qdbusservice/systemdbus/customdata.h"
#include "../qdbusservice/systemdbus/customdatalist.h"
//QDBusPendingCallWatcher *m_getAllPendingCallWatcher;
// QDBusError m_lastExtendedError;
//QPointer<Sink> m_defaultSink;
//if (m_defaultSink) m_defaultSink->deleteLater();
//m_defaultSink = new Sink("com.deepin.daemon.Audio", path.path(), QDBusConnection::sessionBus(), this);
//connect(m_defaultSink, &Sink::ActivePortChanged, this, &SoundWorker::activeSinkPortChanged);
//void activeSinkPortChanged(const AudioPort &activeSinkPort);
//void activeSourcePortChanged(const AudioPort &activeSourcePort);
//void SoundWorker::activeSinkPortChanged(const AudioPort &activeSinkPort)
//{
// qDebug() << "active sink port changed to: " << activeSinkPort.name;
//}
//void SoundWorker::activeSourcePortChanged(const AudioPort &activeSourcePort)
//{
// qDebug() << "active source port changed to: " << activeSourcePort.name;
//}
QString GlobalData::globalarch = ""; // add by hebing, just for transmit var
@ -40,6 +73,9 @@ MainWindow::MainWindow(QString cur_arch, int d_count, QWidget* parent, Qt::Windo
{
GlobalData::globalarch = this->arch;
registerCustomDataMetaType();
registerCustomDataListMetaType();
this->osName = accessOSName();
// char *dsk;
// dsk = getenv("XDG_CURRENT_DESKTOP");
@ -218,6 +254,11 @@ MainWindow::MainWindow(QString cur_arch, int d_count, QWidget* parent, Qt::Windo
this->initAnimation();
this->hide();
m_qSystemDbus = new SystemDbusProxy;
connect(m_qSystemDbus, &SystemDbusProxy::reportAlert, this, [ = ](int ret, const QString &description) {
qDebug() <<"ret="<<ret<<",description="<<description;
});
this->startDbusDaemon();
// 添加阴影
@ -230,6 +271,8 @@ MainWindow::MainWindow(QString cur_arch, int d_count, QWidget* parent, Qt::Windo
MainWindow::~MainWindow()
{
delete m_qSystemDbus;
if (m_dataWorker) {
m_dataWorker->deleteLater();
}
@ -331,7 +374,9 @@ void MainWindow::onInitDataFinished()
this->displayMainWindow();
qDebug() << "m_qSystemDbus->demoInfo()===="<<m_qSystemDbus->demoInfo();
qDebug() << m_qSystemDbus->getCustomData().hash;
//bind setting notify signal
// connect(m_dataWorker, SIGNAL(string_value_notify(QString,QString)), setting_widget, SIGNAL(string_value_notify(QString,QString)));
// connect(m_dataWorker, SIGNAL(bool_value_notify(QString,bool)), setting_widget, SIGNAL(bool_value_notify(QString,bool)));

View File

@ -56,6 +56,8 @@ class ShadowWidget;
//#include "cameramanager.h"
class DataWorker;
class SystemDbusProxy;
class SessionDbusProxy;
//class MainWindow : public QDialog
class MainWindow : public QMainWindow
@ -174,7 +176,8 @@ private:
DataWorker *m_dataWorker;
DataWorker *m_dataWorker = nullptr;
SystemDbusProxy *m_qSystemDbus = nullptr;
};
class GlobalData // define by hebing,just for transmit var

View File

@ -9,7 +9,7 @@ private:
~PluginManager();
public:
static PluginManager* Instance();
static PluginManager *Instance();
bool loadPlugin(QString plugin_path);
bool unloadPlugin(QString plugin_guid);

View File

@ -110,8 +110,6 @@ SOURCES += main.cpp\
../dbusproxy/youkersessiondbus.cpp \
../info/devicemanager.cpp \
../component/settingaction.cpp \
autostartwidget.cpp \
../component/autogroup.cpp \
kthread.cpp \
aboutdialog.cpp \
../cleaner/cleanlistwidget.cpp \
@ -128,7 +126,11 @@ SOURCES += main.cpp\
../component/normalcard.cpp \
shadowwidget.cpp \
../component/basewidget.cpp \
dataworker.cpp
dataworker.cpp \
../qdbusservice/systemdbus/data/systemdbusproxy.cpp \
../qdbusservice/systemdbus/data/systeminterface.cpp \
../qdbusservice/systemdbus/customdata.cpp \
../qdbusservice/systemdbus/customdatalist.cpp
HEADERS += mainwindow.h \
kpplication.h \
@ -197,8 +199,6 @@ HEADERS += mainwindow.h \
../dbusproxy/youkersessiondbus.h \
../info/devicemanager.h \
../component/settingaction.h \
autostartwidget.h \
../component/autogroup.h \
kthread.h \
aboutdialog.h \
../cleaner/cleanlistwidget.h \
@ -215,13 +215,16 @@ HEADERS += mainwindow.h \
../component/normalcard.h \
shadowwidget.h \
../component/basewidget.h \
dataworker.h
dataworker.h \
../qdbusservice/systemdbus/data/systemdbusproxy.h \
../qdbusservice/systemdbus/data/systeminterface.h \
../qdbusservice/systemdbus/data/systemdbushandler.h \
../qdbusservice/systemdbus/customdata.h \
../qdbusservice/systemdbus/customdatalist.h
FORMS += \
../component/quibo.ui \
../component/alertdialog.ui \
autostartwidget.ui \
# aboutdialog.ui \
../cleaner/cleanlistwidget.ui \
../cleaner/cleanerdetailwidget.ui \
../component/itemcard.ui \