diff --git a/component/myswitcher.cpp b/component/myswitcher.cpp new file mode 100644 index 0000000..f11afbd --- /dev/null +++ b/component/myswitcher.cpp @@ -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 . + */ + +#include "myswitcher.h" + +#include +#include +#include +#include + +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); +} diff --git a/component/myswitcher.h b/component/myswitcher.h new file mode 100644 index 0000000..721e2d1 --- /dev/null +++ b/component/myswitcher.h @@ -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 . + */ + +#ifndef MYSWITCHER_H +#define MYSWITCHER_H + +#include +#include + +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 diff --git a/component/threadpool.cpp b/component/threadpool.cpp index edc158c..635a3be 100644 --- a/component/threadpool.cpp +++ b/component/threadpool.cpp @@ -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; diff --git a/debian/changelog b/debian/changelog index 63a938c..e7ffbc1 100644 --- a/debian/changelog +++ b/debian/changelog @@ -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 Mon, 29 Jan 2018 17:54:44 +0800 diff --git a/debian/control b/debian/control index f2340a9..9be828d 100644 --- a/debian/control +++ b/debian/control @@ -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 diff --git a/kylin-assistant.pro b/kylin-assistant.pro index ea6f19e..5d3fb48 100644 --- a/kylin-assistant.pro +++ b/kylin-assistant.pro @@ -2,7 +2,8 @@ TEMPLATE = subdirs SUBDIRS = \ src \ plugins \ - backends + backends \ + qdbusservice TRANSLATIONS += \ src/translation/kylin-assistant_zh_CN.ts \ diff --git a/plugins/startupmanager/startupdata.h b/plugins/startupmanager/startupdata.h index 372e99e..2b8cf17 100644 --- a/plugins/startupmanager/startupdata.h +++ b/plugins/startupmanager/startupdata.h @@ -28,24 +28,22 @@ #include #include - -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 GspXdgDirPtr; -//typedef QList GspXdgDirPtrList; -//Q_DECLARE_METATYPE(GspXdgDir) -//Q_DECLARE_METATYPE(GspXdgDirPtr) -//Q_DECLARE_METATYPE(GspXdgDirPtrList) - - - class StartupData/* : public QObject*/ { diff --git a/plugins/startupmanager/startupitem.cpp b/plugins/startupmanager/startupitem.cpp index 080f879..f910447 100644 --- a/plugins/startupmanager/startupitem.cpp +++ b/plugins/startupmanager/startupitem.cpp @@ -18,7 +18,7 @@ */ #include "startupitem.h" -#include "../../component/kylinswitcher.h" +#include "../../component/myswitcher.h" #include "startupdata.h" #include @@ -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); } - - diff --git a/plugins/startupmanager/startupitem.h b/plugins/startupmanager/startupitem.h index af6f7b4..335a9dd 100644 --- a/plugins/startupmanager/startupitem.h +++ b/plugins/startupmanager/startupitem.h @@ -25,7 +25,7 @@ #include #include -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; diff --git a/plugins/startupmanager/startuplistwidget.cpp b/plugins/startupmanager/startuplistwidget.cpp index e70883c..c80a9d4 100644 --- a/plugins/startupmanager/startuplistwidget.cpp +++ b/plugins/startupmanager/startuplistwidget.cpp @@ -34,7 +34,6 @@ #include #include #include - #include #include @@ -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(); + //this->m_watcherList = new QList(); 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::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="<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; iremovePath(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; iremovePath(m_monitorFile); + delete watcher; + watcher = NULL; } - m_watherList.clear();*/ + m_watcherList.clear();*/ // QMap::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(it.value()); -// wather->removePath(path); -// delete wather; -// wather = NULL; +// QFileSystemWatcher *watcher = static_cast(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 items = findChildren(); + 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===================="<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="<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="<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() { diff --git a/plugins/startupmanager/startuptitlewidget.h b/plugins/startupmanager/startuptitlewidget.h index e2869a6..d5e1c3c 100644 --- a/plugins/startupmanager/startuptitlewidget.h +++ b/plugins/startupmanager/startuptitlewidget.h @@ -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; diff --git a/plugins/startupmanager/startupwidget.cpp b/plugins/startupmanager/startupwidget.cpp index 539cb34..e0093e0 100644 --- a/plugins/startupmanager/startupwidget.cpp +++ b/plugins/startupmanager/startupwidget.cpp @@ -40,7 +40,7 @@ QDataStream &operator<<(QDataStream &dataStream, const StartupDataPtr &object) auto ptrval = reinterpret_cast(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(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(ptrval); -// object = GspXdgDirPtr(ptr); -// return dataStream; -//} - StartupWidget::StartupWidget(QWidget *parent) : QFrame(parent) , mousePressed(false) @@ -81,12 +62,6 @@ StartupWidget::StartupWidget(QWidget *parent) qRegisterMetaType(); qRegisterMetaType>(); - -// qRegisterMetaType(); -// qRegisterMetaTypeStreamOperators(); -// qRegisterMetaType(); -// qRegisterMetaType>(); - 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); +} + diff --git a/plugins/startupmanager/startupworker.cpp b/plugins/startupmanager/startupworker.cpp index a0c84ea..3290a36 100644 --- a/plugins/startupmanager/startupworker.cpp +++ b/plugins/startupmanager/startupworker.cpp @@ -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 * 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 . + * 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 + * Kobe Lee xiangli@ubuntukylin.com/kobe24_lixiang@126.com */ #include "startupworker.h" @@ -30,200 +40,6 @@ #include "util.h" -#define gsp_key_file_get_string(key_file, key) \ - g_key_file_get_string (key_file, G_KEY_FILE_DESKTOP_GROUP, key, NULL) -#define gsp_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 gsp_key_file_set_boolean(key_file, key, value) \ - g_key_file_set_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP, key, value) -#define gsp_key_file_set_string(key_file, key, value) \ - g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP, key, value) - -gboolean gsp_key_file_get_boolean (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 gsp_key_file_to_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 gsp_key_file_populate (GKeyFile *keyfile) -{ - gsp_key_file_set_string (keyfile, - G_KEY_FILE_DESKTOP_KEY_TYPE, - "Application"); - - gsp_key_file_set_string (keyfile, - G_KEY_FILE_DESKTOP_KEY_EXEC, - "/bin/false"); -} - -void gsp_key_file_set_locale_string (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 gsp_key_file_get_shown (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; -} - -static char *_gsp_get_current_desktop () -{ - 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; -} - -static gboolean _gsp_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; -} @@ -253,7 +69,7 @@ static gboolean _gsp_str_equal (const char *a, // g_free (basename); // return TRUE; // } -// old_app = gsp_app_manager_find_app_with_basename (manager, basename); +// old_app = getAppStartupDataAccrodDesktopFileName (manager, basename); // parent = g_file_get_parent (child); // dir = g_file_get_path (parent); @@ -318,7 +134,7 @@ static gboolean _gsp_str_equal (const char *a, //monitor = NULL; -void gsp_key_file_ensure_C_key (GKeyFile *keyfile, const char *key) +void ensureCKeyInDesktopFil (GKeyFile *keyfile, const char *key) { char *C_value; char *buffer; @@ -327,11 +143,11 @@ void gsp_key_file_ensure_C_key (GKeyFile *keyfile, const char *key) * This is so that if the user logs into another locale they get their * own description there rather then empty. It is not the C locale * however, but the user created this entry herself so it's OK */ - C_value = gsp_key_file_get_string (keyfile, key); + C_value = kylin_start_manager_key_file_get_string (keyfile, key); if (C_value == NULL || C_value [0] == '\0') { - buffer = gsp_key_file_get_locale_string (keyfile, key); + buffer = kylin_start_manager_key_file_get_locale_string (keyfile, key); if (buffer) { - gsp_key_file_set_string (keyfile, key, buffer); + kylin_start_manager_key_file_set_string (keyfile, key, buffer); g_free (buffer); } } @@ -402,18 +218,18 @@ StartupWorker::~StartupWorker() { m_startupInfoList.clear(); -// foreach (GspXdgDir item, this->dirs) { -// QFileSystemWatcher *wather = item.wather; -// wather->removePath(item.dir); -// delete wather; -// wather = NULL; +// foreach (MonitorData item, this->m_monitorList) { +// QFileSystemWatcher *watcher = item.watcher; +// watcher->removePath(item.dir); +// delete watcher; +// watcher = NULL; // } -// this->dirs.clear(); - foreach (GspXdgDir item, this->m_xdgMap.values()) { - QFileSystemWatcher *wather = item.wather; - wather->removePath(item.dir); - delete wather; - wather = NULL; +// this->m_monitorList.clear(); + foreach (MonitorData item, this->m_xdgMap.values()) { + QFileSystemWatcher *watcher = item.watcher; + watcher->removePath(item.dir); + delete watcher; + watcher = NULL; } this->m_xdgMap.clear(); } @@ -424,14 +240,14 @@ QFileSystemWatcher *StartupWorker::createFileSystemMonitor(const QString &path) int wd = inotify_add_watch (fd, path, mask); // int ret = inotify_rm_watch (fd, wd);*/ -// qDebug() << "wather path="<dirs.append(xdgDir); - m_xdgMap.insert(xdgDir.dir, xdgDir); +// this->m_monitorList.append(monitorData); + m_xdgMap.insert(monitorData.dir, monitorData); } int StartupWorker::getDirIndex(QString dir) { -// foreach (GspXdgDir item, this->dirs) { +// foreach (MonitorData item, this->m_monitorList) { // if (item.dir == dir) { // return item.index; // } // } - foreach (GspXdgDir item, this->m_xdgMap.values()) { + foreach (MonitorData item, this->m_xdgMap.values()) { if (item.dir == dir) { return item.index; } @@ -477,14 +292,14 @@ int StartupWorker::getDirIndex(QString dir) return -1; } -QString StartupWorker::gsp_app_manager_get_dir(unsigned int index) +QString StartupWorker::getMonitorDirectoryAccordXdgSystemPosition(unsigned int index) { -// foreach (GspXdgDir item, this->dirs) { +// foreach (MonitorData item, this->m_monitorList) { // if (item.index == index) { // return item.dir; // } // } - foreach (GspXdgDir item, this->m_xdgMap.values()) { + foreach (MonitorData item, this->m_xdgMap.values()) { if (item.index == index) { return item.dir; } @@ -494,7 +309,7 @@ QString StartupWorker::gsp_app_manager_get_dir(unsigned int index) } -StartupData StartupWorker::gsp_app_manager_find_app_with_basename(QString &basename) +StartupData StartupWorker::getAppStartupDataAccrodDesktopFileName(QString &basename) { for (StartupData info : this->getStartupInfoList()) { if (info.basename == basename) { @@ -508,31 +323,24 @@ StartupData StartupWorker::gsp_app_manager_find_app_with_basename(QString &basen void StartupWorker::updateGspXdgDir(const QString &dir, QStringList fileList) { if (this->m_xdgMap.keys().contains(dir)) { - qDebug() << "before this->m_xdgMap[dir].fileList=" << this->m_xdgMap[dir].fileList.length(); - //start auto start, remove the desktop file which in user config dir foreach (QString orgFileAbsPath, this->m_xdgMap.value(dir).fileList) { - qDebug() << "orgFileAbsPath="<updateEnable(info.exec, info.enabled); this->updateSaveMask(info.exec, info.save_mask); - this->_gsp_app_queue_save(info); + this->readySaveDesktopInfo(info); } } //canel auto start, add the desktop file to user config dir foreach (QString nowFileAbsPath, fileList) { - qDebug() << "nowFileAbsPath="<m_xdgMap[dir].fileList.contains(nowFileAbsPath)) { - qDebug() << "222222222222 nowFileAbsPath="<newStartupInfo(nowFileAbsPath, this->m_xdgMap.value(dir).index); } @@ -540,34 +348,30 @@ void StartupWorker::updateGspXdgDir(const QString &dir, QStringList fileList) this->m_xdgMap[dir].fileList.clear(); this->m_xdgMap[dir].fileList = fileList; - qDebug() << "after this->m_xdgMap[dir].fileList=" << this->m_xdgMap[dir].fileList.length(); + emit this->refreshUI(); } } QString StartupWorker::getStringValueAccordKeyFromDesktopFile(const gchar *key, const QString &desktopFile, bool isLocale) { - qDebug() << "aaa" << desktopFile; GKeyFile *keyfile; keyfile = g_key_file_new (); if (!g_key_file_load_from_file (keyfile, desktopFile.toStdString().c_str(), G_KEY_FILE_NONE, NULL)) { g_key_file_free (keyfile); - qDebug() << "bbb"; return QString(); } if (isLocale) { - std::string formatted_result(make_string(gsp_key_file_get_locale_string (keyfile, key))); + std::string formatted_result(make_string(kylin_start_manager_key_file_get_locale_string (keyfile, key))); QString result = QString::fromStdString(formatted_result); g_key_file_free (keyfile); return result; } else { - qDebug() << "ccc"; - std::string formatted_result = make_string(gsp_key_file_get_string (keyfile, key)); + std::string formatted_result = make_string(kylin_start_manager_key_file_get_string (keyfile, key)); QString result = QString::fromStdString(formatted_result); g_key_file_free (keyfile); - qDebug() << "ddd" << result; return result; } } @@ -577,7 +381,7 @@ void StartupWorker::newStartupInfo(const QString &desktopFile, unsigned int xdg_ bool isNew; QString basename = QFileInfo(desktopFile).fileName(); - StartupData info = gsp_app_manager_find_app_with_basename(basename); + StartupData info = getAppStartupDataAccrodDesktopFileName(basename); if (info.basename.isEmpty() && info.name.isEmpty() && info.exec.isEmpty()) isNew = true; else @@ -585,14 +389,6 @@ void StartupWorker::newStartupInfo(const QString &desktopFile, unsigned int xdg_ if (!isNew) { //qDebug() << "is not new!!!!"; - if (info.xdg_position == xdg_position) { -// if (app->priv->skip_next_monitor_event) { -// app->priv->skip_next_monitor_event = FALSE; -// return; -// } - /* else: the file got changed but not by us, we'll - * update our data from disk */ - } if (info.xdg_position < xdg_position) { /* we don't really care about this file, since we * already have something with a higher priority, or @@ -604,25 +400,25 @@ void StartupWorker::newStartupInfo(const QString &desktopFile, unsigned int xdg_ } } - GKeyFile *keyfile; + GKeyFile *keyfile; keyfile = g_key_file_new (); if (!g_key_file_load_from_file (keyfile, desktopFile.toStdString().c_str(), G_KEY_FILE_NONE, NULL)) { - g_key_file_free (keyfile); + g_key_file_free(keyfile); return; } - bool hidden = gsp_key_file_get_boolean (keyfile, G_KEY_FILE_DESKTOP_KEY_HIDDEN, FALSE); - bool no_display = gsp_key_file_get_boolean (keyfile,G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY,FALSE); - bool enabled = gsp_key_file_get_boolean (keyfile, KEY_FILE_DESKTOP_KEY_AUTOSTART_ENABLED,TRUE); - bool shown = gsp_key_file_get_shown (keyfile,_gsp_get_current_desktop ()); + bool hidden = get_boolean_from_desktop_file (keyfile, G_KEY_FILE_DESKTOP_KEY_HIDDEN, FALSE); + bool no_display = get_boolean_from_desktop_file (keyfile,G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY,FALSE); + bool enabled = get_boolean_from_desktop_file (keyfile, KEY_FILE_DESKTOP_KEY_AUTOSTART_ENABLED,TRUE); + bool shown = get_shown_from_desktop_file (keyfile,get_current_desktop_env ()); - std::string formatted_result(make_string(gsp_key_file_get_locale_string (keyfile, G_KEY_FILE_DESKTOP_KEY_NAME))); + std::string formatted_result(make_string(kylin_start_manager_key_file_get_locale_string (keyfile, G_KEY_FILE_DESKTOP_KEY_NAME))); QString name = QString::fromStdString(formatted_result); - formatted_result = make_string(gsp_key_file_get_string (keyfile, G_KEY_FILE_DESKTOP_KEY_EXEC)); + formatted_result = make_string(kylin_start_manager_key_file_get_string (keyfile, G_KEY_FILE_DESKTOP_KEY_EXEC)); QString exec = QString::fromStdString(formatted_result); - formatted_result = make_string(gsp_key_file_get_locale_string (keyfile, G_KEY_FILE_DESKTOP_KEY_COMMENT)); + formatted_result = make_string(kylin_start_manager_key_file_get_locale_string (keyfile, G_KEY_FILE_DESKTOP_KEY_COMMENT)); QString comment = QString::fromStdString(formatted_result); - formatted_result = make_string(gsp_key_file_get_locale_string (keyfile, G_KEY_FILE_DESKTOP_KEY_ICON)); + formatted_result = make_string(kylin_start_manager_key_file_get_locale_string (keyfile, G_KEY_FILE_DESKTOP_KEY_ICON)); QString icon = QString::fromStdString(formatted_result); if (name.isEmpty() || name.isNull()) name = exec; @@ -731,8 +527,6 @@ StartupData StartupWorker::getStartupInfoAccordDestkopFile(const QString &deskto void StartupWorker::updateEnable(const QString &exec, bool enabled) { -// m_startupInfoList.value(exec).enabled = enabled; -// m_startupInfoList.value(exec).setEnabled(enabled); if (m_startupInfoList.contains(exec)) { m_startupInfoList[exec].enabled = enabled;//m_startupInfoList[exec].setEnabled(enabled); } @@ -773,31 +567,27 @@ void StartupWorker::updatePath(const QString &exec, QString path) } } -void StartupWorker::_gsp_ensure_user_autostart_dir (void) +void StartupWorker::ensureUserAutostartupDirExists(void) { char *dir; dir = g_build_filename(g_get_user_config_dir(), "autostart", NULL); - g_mkdir_with_parents(dir, S_IRWXU); -// printf("ensure dir=%s\n", dir); + g_mkdir_with_parents(dir, S_IRWXU);//S_IRWXU 00700 权限,代表该文件所有者具有可读、可写及可执行的权限 g_free(dir); // QDir dir; // if(!dir.exists("aa")){ // dir.mkdir("aa"); // } - - /*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 dir = QString::fromStdString(formatted_result); - //S_IRWXU 00700 权限,代表该文件所有者具有可读、可写及可执行的权限 - if (dir.endsWith("/")) + if (dir.endsWith(QLatin1String("/"))) g_mkdir_with_parents (dir + "autostart", S_IRWXU);//if (g_mkdir_with_parents (dir, 0755) == 0) else g_mkdir_with_parents (dir + "/autostart", S_IRWXU);*/ } -void StartupWorker::_gsp_app_save_done_success (StartupData info) +void StartupWorker::changeSaveFlagsWhenDoneSuccess(StartupData info) { info.save_mask = 0; this->updateSaveMask(info.exec, info.save_mask); @@ -807,114 +597,97 @@ void StartupWorker::_gsp_app_save_done_success (StartupData info) } } -bool StartupWorker::_gsp_app_user_equal_system (StartupData info, char **system_path) +/* + *判断desktop文件是否同时存在于用户的启动配置目录下和系统的启动配置目录下, + *如果同时存在,说明已经禁止了自启动,否则该应用程序是开机自启动的 +*/ +bool StartupWorker::isDesktopFileInUserAndSystemConfiguDir(StartupData info, char **system_path) { - QString system_dir; - char *path; - char *str; - GKeyFile *keyfile; + QString system_dir; + char *path; + char *str; + GKeyFile *keyfile; - system_dir = gsp_app_manager_get_dir(info.xdg_system_position); - if (system_dir.isEmpty()) { -// qDebug() << "PPP 111"; + system_dir = getMonitorDirectoryAccordXdgSystemPosition(info.xdg_system_position); + if (system_dir.isEmpty()) { + return false; + } + + path = g_build_filename(system_dir.toStdString().c_str(), info.basename.toStdString().c_str(), NULL); + keyfile = g_key_file_new(); + if (!g_key_file_load_from_file(keyfile, path, G_KEY_FILE_NONE, NULL)) { + g_free(path); + g_key_file_free(keyfile); + return false; + } + + if (get_boolean_from_desktop_file(keyfile, G_KEY_FILE_DESKTOP_KEY_HIDDEN, FALSE) != info.hidden || + get_boolean_from_desktop_file(keyfile, KEY_FILE_DESKTOP_KEY_AUTOSTART_ENABLED, TRUE) != info.enabled || + get_shown_from_desktop_file (keyfile, get_current_desktop_env()) != info.shown) { + g_free(path); + g_key_file_free(keyfile); + return false; + } + if (get_boolean_from_desktop_file(keyfile, G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY, FALSE) != info.no_display) { + g_free(path); + g_key_file_free(keyfile); + return false; + } + + str = kylin_start_manager_key_file_get_locale_string(keyfile, G_KEY_FILE_DESKTOP_KEY_NAME); + if (!is_str_equal (str, info.name.toStdString().c_str())) { + g_free(str); + g_free(path); + g_key_file_free(keyfile); return false; - } + } + g_free(str); - path = g_build_filename(system_dir.toStdString().c_str(), info.basename.toStdString().c_str(), NULL); -// printf("_gsp_app_user_equal_system path=%s\n", path);///etc/xdg/autostart/indicator-china-weather.desktop - - keyfile = g_key_file_new(); - if (!g_key_file_load_from_file(keyfile, path, G_KEY_FILE_NONE, NULL)) { -// qDebug() << "PPP 222"; - g_free (path); - g_key_file_free (keyfile); + str = kylin_start_manager_key_file_get_locale_string(keyfile, G_KEY_FILE_DESKTOP_KEY_COMMENT); + if (!is_str_equal(str, info.comment.toStdString().c_str())) { + g_free(str); + g_free(path); + g_key_file_free(keyfile); return false; - } + } + g_free(str); - if (gsp_key_file_get_boolean (keyfile, - G_KEY_FILE_DESKTOP_KEY_HIDDEN, - FALSE) != info.hidden || - gsp_key_file_get_boolean (keyfile, - KEY_FILE_DESKTOP_KEY_AUTOSTART_ENABLED, - TRUE) != info.enabled || - gsp_key_file_get_shown (keyfile, - _gsp_get_current_desktop ()) != info.shown) { -// qDebug() << "PPP 333"; - g_free (path); - g_key_file_free (keyfile); - return false; - } - if (gsp_key_file_get_boolean (keyfile, - G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY, - FALSE) != info.no_display) { -// qDebug() << "PPP 444"; - g_free (path); - g_key_file_free (keyfile); - return false; - } + str = kylin_start_manager_key_file_get_string(keyfile, G_KEY_FILE_DESKTOP_KEY_EXEC); + if (!is_str_equal(str, info.exec.toStdString().c_str())) { + g_free(str); + g_free(path); + g_key_file_free(keyfile); + return false; + } + g_free(str); - str = gsp_key_file_get_locale_string (keyfile, G_KEY_FILE_DESKTOP_KEY_NAME); - if (!_gsp_str_equal (str, info.name.toStdString().c_str())) { -// qDebug() << "PPP 555"; - g_free (str); - g_free (path); - g_key_file_free (keyfile); - return false; - } - g_free (str); + str = kylin_start_manager_key_file_get_locale_string(keyfile, G_KEY_FILE_DESKTOP_KEY_ICON); + if (!is_str_equal(str, info.icon.toStdString().c_str())) {//info.icon.toStdString().data() + g_free(str); + g_free(path); + g_key_file_free(keyfile); + return false; + } + g_free(str); - str = gsp_key_file_get_locale_string (keyfile, G_KEY_FILE_DESKTOP_KEY_COMMENT); - if (!_gsp_str_equal (str, info.comment.toStdString().c_str())) { -// qDebug() << "PPP 666"; - g_free (str); - g_free (path); - g_key_file_free (keyfile); - return false; - } - g_free (str); + g_key_file_free(keyfile); + *system_path = path; - str = gsp_key_file_get_string (keyfile, - G_KEY_FILE_DESKTOP_KEY_EXEC); - if (!_gsp_str_equal (str, info.exec.toStdString().c_str())) { -// qDebug() << "PPP 777"; - g_free (str); - g_free (path); - g_key_file_free (keyfile); - return false; - } - g_free (str); - str = gsp_key_file_get_locale_string (keyfile, - G_KEY_FILE_DESKTOP_KEY_ICON); - if (!_gsp_str_equal (str, info.icon.toStdString().c_str())) {//info.icon.toStdString().data() -// qDebug() << "PPP 888"; - g_free (str); - g_free (path); - g_key_file_free (keyfile); - return false; - } - g_free (str); - - g_key_file_free (keyfile); -// qDebug() << "PPP 999"; - *system_path = path; - - return true; + return true; } -/*bool StartupWorker::_gsp_app_user_equal_system (StartupData info, QString &system_path, QString locale) +/*bool StartupWorker::isDesktopFileInUserAndSystemConfiguDir (StartupData info, QString &system_path, QString locale) { QString system_dir; QString path; QString str; - qDebug() << "info.xdg_system_position="<updateXdgPosition(info.exec, info.xdg_position); - //printf("end info.xdg_position===%d\n", info.xdg_position); - _gsp_app_save_done_success(info); -// qDebug() << "yyy info.path="<updatePath(info.exec, info.path); + info.xdg_position = info.xdg_system_position; + this->updateXdgPosition(info.exec, info.xdg_position); + changeSaveFlagsWhenDoneSuccess(info); + return false; } + //由开启到关闭的转换过程 if (!info.old_system_path.isEmpty()) { - //qDebug() << "111 info.old_system_path="<updateXdgPosition(info.exec, info.xdg_position); - qDebug() << "KK info.path=" << info.path; if (info.old_system_path.isEmpty()) { info.old_system_path = info.path;//将desktop文件当前路径记录到old_system_path中 - qDebug() << "KK 111 info.old_system_path="<updateOldSystemPath(info.exec, info.old_system_path); /* if old_system_path was not NULL, then it means we * tried to save and we failed; in that case, we want * to try again and use the old file as a basis again */ } - else - qDebug() << "KK 222 info.old_system_path="<updatePath(info.exec, info.path); } - _gsp_app_save(info); + saveAppDesktopInfo(info); } diff --git a/plugins/startupmanager/startupworker.h b/plugins/startupmanager/startupworker.h index ec26781..9c422cb 100644 --- a/plugins/startupmanager/startupworker.h +++ b/plugins/startupmanager/startupworker.h @@ -21,50 +21,12 @@ #ifndef STARTUPWORKER_H #define STARTUPWORKER_H +#include "startupdata.h" + #include #include #include -#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 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 getAllDirs() { /*return dirs;*/ return this->m_xdgMap.values(); } + QString getMonitorDirectoryAccordXdgSystemPosition(unsigned int index); + QList 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 m_startupInfoList; - QList dirs; - QMap m_xdgMap; + QMap m_xdgMap;//QList m_monitorList; }; #endif // STARTUPWORKER_H diff --git a/plugins/startupmanager/util.cpp b/plugins/startupmanager/util.cpp index bfc419d..7688547 100644 --- a/plugins/startupmanager/util.cpp +++ b/plugins/startupmanager/util.cpp @@ -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 * 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 . + * 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 + * 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; +} diff --git a/plugins/startupmanager/util.h b/plugins/startupmanager/util.h index 828563a..cb6af35 100644 --- a/plugins/startupmanager/util.h +++ b/plugins/startupmanager/util.h @@ -17,6 +17,8 @@ * along with this program. If not, see . */ +#pragma once + #include #include #include @@ -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); diff --git a/plugins/systemmonitor/filesystemdialog.cpp b/plugins/systemmonitor/filesystemdialog.cpp index eb160cd..44a7cae 100644 --- a/plugins/systemmonitor/filesystemdialog.cpp +++ b/plugins/systemmonitor/filesystemdialog.cpp @@ -27,6 +27,8 @@ #include "filesystemdata.h" #include "filesystemworker.h" +#include "filesystemwatcher.h" + FileSystemDialog::FileSystemDialog(QList toBeDisplayedColumns, QSettings *settings, QWidget *parent) :QWidget(parent) ,proSettings(settings) @@ -61,10 +63,18 @@ FileSystemDialog::FileSystemDialog(QList 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 items; for (FileSystemData *info : m_fileSystemWorker->diskInfoList()) { FileSystemListItem *item = new FileSystemListItem(info); diff --git a/plugins/systemmonitor/filesystemdialog.h b/plugins/systemmonitor/filesystemdialog.h index ff6d262..025ffb6 100644 --- a/plugins/systemmonitor/filesystemdialog.h +++ b/plugins/systemmonitor/filesystemdialog.h @@ -23,10 +23,9 @@ #include #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 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; }; diff --git a/plugins/systemmonitor/filesystemwatcher.cpp b/plugins/systemmonitor/filesystemwatcher.cpp new file mode 100644 index 0000000..f6185ee --- /dev/null +++ b/plugins/systemmonitor/filesystemwatcher.cpp @@ -0,0 +1,79 @@ +#include "filesystemwatcher.h" +#include "util.h" + +#include + +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 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; +} diff --git a/plugins/systemmonitor/filesystemwatcher.h b/plugins/systemmonitor/filesystemwatcher.h new file mode 100644 index 0000000..c912f2a --- /dev/null +++ b/plugins/systemmonitor/filesystemwatcher.h @@ -0,0 +1,37 @@ +#ifndef FILESYSTEMWATCHER_H +#define FILESYSTEMWATCHER_H + +#include +#include +#include + +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 m_origFileSet; + static FileSystemWatcher *m_watcher; +}; + +#endif // FILESYSTEMWATCHER_H diff --git a/plugins/systemmonitor/systemmonitor.cpp b/plugins/systemmonitor/systemmonitor.cpp index ad1dc66..e378e0d 100644 --- a/plugins/systemmonitor/systemmonitor.cpp +++ b/plugins/systemmonitor/systemmonitor.cpp @@ -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); } diff --git a/plugins/systemmonitor/systemmonitor.pro b/plugins/systemmonitor/systemmonitor.pro index 8dca898..d29128d 100644 --- a/plugins/systemmonitor/systemmonitor.pro +++ b/plugins/systemmonitor/systemmonitor.pro @@ -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 diff --git a/plugins/systemmonitor/util.cpp b/plugins/systemmonitor/util.cpp index 2203d6c..cfe3499 100644 --- a/plugins/systemmonitor/util.cpp +++ b/plugins/systemmonitor/util.cpp @@ -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 getFileContentsLineByLine(const QString &filePath) +{ + QString fileContent = getFileContent(filePath); + return QSet::fromList(fileContent.split("\n")); +} diff --git a/plugins/systemmonitor/util.h b/plugins/systemmonitor/util.h index 5f2b8f6..1135a70 100644 --- a/plugins/systemmonitor/util.h +++ b/plugins/systemmonitor/util.h @@ -18,14 +18,20 @@ */ #include +#include +#include #include #include #include +#include +#include +#include #include #include #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 getFileContentsLineByLine(const QString &filePath); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index d0905c3..aff5733 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -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 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="<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()===="<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))); diff --git a/src/mainwindow.h b/src/mainwindow.h index 0cf263d..c63d7c0 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -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 diff --git a/src/pluginmanager.h b/src/pluginmanager.h index 51904dc..3222359 100644 --- a/src/pluginmanager.h +++ b/src/pluginmanager.h @@ -9,7 +9,7 @@ private: ~PluginManager(); public: - static PluginManager* Instance(); + static PluginManager *Instance(); bool loadPlugin(QString plugin_path); bool unloadPlugin(QString plugin_guid); diff --git a/src/src.pro b/src/src.pro index cafc426..842295e 100644 --- a/src/src.pro +++ b/src/src.pro @@ -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 \