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="<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()
diff --git a/plugins/startupmanager/startuplistwidget.h b/plugins/startupmanager/startuplistwidget.h
index ed2a830..9b9cb7d 100644
--- a/plugins/startupmanager/startuplistwidget.h
+++ b/plugins/startupmanager/startuplistwidget.h
@@ -27,7 +27,6 @@
#include
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 m_watherList;//QList *m_watherList;
-// QMap m_watherMap;
+// QList m_watcherList;//QList *m_watcherList;
+// QMap m_watcherMap;
};
#endif // STARTUPLISTWIDGET_H
diff --git a/plugins/startupmanager/startupmanager.pro b/plugins/startupmanager/startupmanager.pro
index be02e6e..a701aa8 100644
--- a/plugins/startupmanager/startupmanager.pro
+++ b/plugins/startupmanager/startupmanager.pro
@@ -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 += \
diff --git a/plugins/startupmanager/startuptitlewidget.cpp b/plugins/startupmanager/startuptitlewidget.cpp
index 7c45bba..4c6d35a 100644
--- a/plugins/startupmanager/startuptitlewidget.cpp
+++ b/plugins/startupmanager/startuptitlewidget.cpp
@@ -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()
{
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="<updateGspXdgDir(path, fileList);
});
-// m_watherList.append(m_fileSystemMonitor);
-// if (m_watherMap.contains(path))
-// m_watherMap.insert(path, m_fileSystemMonitor);
+// m_watcherList.append(m_fileSystemMonitor);
+// if (m_watcherMap.contains(path))
+// m_watcherMap.insert(path, m_fileSystemMonitor);
return m_fileSystemMonitor;
-
// connect(m_fileSystemMonitor, &QFileSystemWatcher::fileChanged, [=] (const QString &path) {
// qDebug()<< "fileChanged 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