Make all dbus modules quit when the app quit

This commit is contained in:
李 翔 2018-02-04 21:25:17 +08:00
parent 0c31512548
commit fac7c6d530
13 changed files with 358 additions and 431 deletions

View File

@ -36,30 +36,23 @@ ThreadPool *ThreadPool::Instance()
return &threadPool; return &threadPool;
} }
QThread *ThreadPool::newThread() QThread *ThreadPool::createNewThread()
{ {
QThread *thread = new QThread; QThread *thread = new QThread;
thread_pool.push_back(thread); m_threadPool.push_back(thread);
return thread; return thread;
} }
void ThreadPool::moveToNewThread(QObject *obj) void ThreadPool::moveObjectToThread(QObject *obj)
{ {
QThread *work = newThread(); QThread *work = createNewThread();
obj->moveToThread(work); obj->moveToThread(work);
work->start(); work->start();
} }
//QThread *ThreadPool::createNewThread()
//{
// QThread *thread = new QThread;
// thread_pool.push_back(thread);
// return thread;
//}
void ThreadPool::exitAllThreads() void ThreadPool::exitAllThreads()
{ {
foreach (QThread *thread, thread_pool) { foreach (QThread *thread, m_threadPool) {
thread->quit(); thread->quit();
thread->wait(2000); thread->wait(2000);
} }

View File

@ -29,14 +29,12 @@ public:
~ThreadPool(); ~ThreadPool();
static ThreadPool *Instance(); static ThreadPool *Instance();
// QThread *createNewThread(); QThread *createNewThread();
QThread *newThread(); void moveObjectToThread(QObject *obj);
void moveToNewThread(QObject *obj);
void exitAllThreads(); void exitAllThreads();
private: private:
QList<QThread *> thread_pool; QList<QThread *> m_threadPool;
}; };
#endif // THREADPOOL_H #endif // THREADPOOL_H

View File

@ -48,7 +48,6 @@ SystemDispatcher::~SystemDispatcher() {
clean_thread = NULL; clean_thread = NULL;
} }
qDebug() << "system dbus destroy..............";
this->exit_qt(); this->exit_qt();
if (systemiface != NULL) { if (systemiface != NULL) {
delete systemiface; delete systemiface;

1
debian/changelog vendored
View File

@ -17,5 +17,6 @@ kylin-assistant (1.0.0-0ubuntu1) bionic; urgency=low
* Add monitor for auto startup manager. * Add monitor for auto startup manager.
* Add monitor for file system. * Add monitor for file system.
* Add QDbus module(system dbus and session dbus). * Add QDbus module(system dbus and session dbus).
* Make all dbus modules quit when the app quit.
-- lixiang <lixiang@kylinos.cn> Mon, 29 Jan 2018 17:54:44 +0800 -- lixiang <lixiang@kylinos.cn> Mon, 29 Jan 2018 17:54:44 +0800

View File

@ -33,107 +33,13 @@
#include <QDebug> #include <QDebug>
#include <QFileInfo> #include <QFileInfo>
#include <QDirIterator> #include <QDirIterator>
#include <QSet>
#include <glib.h> #include <glib.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <string.h> #include <string.h>
#include "util.h" #include "util.h"
//#include <gio/gio.h>
//static gboolean
//gsp_app_manager_xdg_dir_monitor (GFileMonitor *monitor,
// GFile *child,
// GFile *other_file,
// GFileMonitorEvent flags,
// gpointer data)
//{
//// GspAppManager *manager;
//// GspApp *old_app;
//// GspApp *app;
// GFile *parent;
// char *basename;
// char *dir;
// char *path;
// int index;
// manager = GSP_APP_MANAGER (data);
// basename = g_file_get_basename (child);
// if (!g_str_has_suffix (basename, ".desktop")) {
// /* not a desktop file, we can ignore */
// g_free (basename);
// return TRUE;
// }
// old_app = getAppStartupDataAccrodDesktopFileName (manager, basename);
// parent = g_file_get_parent (child);
// dir = g_file_get_path (parent);
// g_object_unref (parent);
// index = gsp_app_manager_get_dir_index (manager, dir);
// if (index < 0) {
// /* not a directory we know; should never happen, though */
// g_free (dir);
// return TRUE;
// }
// path = g_file_get_path (child);
// switch (flags) {
// case G_FILE_MONITOR_EVENT_CHANGED:
// case G_FILE_MONITOR_EVENT_CREATED:
// /* we just do as if it was a new file: GspApp is clever enough
// * to do the right thing */
// app = gsp_app_new (path, (unsigned int) index);
// /* we didn't have this app before, so add it */
// if (old_app == NULL && app != NULL) {
// gsp_app_manager_add (manager, app);
// g_object_unref (app);
// }
// /* else: it was just updated, GspApp took care of
// * sending the event */
// break;
// case G_FILE_MONITOR_EVENT_DELETED:
// if (!old_app) {
// /* it got deleted, but we don't know about it, so
// * nothing to do */
// break;
// }
// _gsp_app_manager_handle_delete (manager, old_app,
// basename, index);
// break;
// default:
// break;
// }
// g_free (path);
// g_free (dir);
// g_free (basename);
// return TRUE;
//}
//GFile *file;
//GDir *dir;
//const char *name;
//file = g_file_new_for_path (xdgdir->dir);
//GFileMonitor *monitor;
//monitor = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, NULL, NULL);
//g_object_unref (file);
//if (monitor) {
// g_signal_connect (monitor, "changed", G_CALLBACK (gsp_app_manager_xdg_dir_monitor), manager);
//}
//g_file_monitor_cancel (monitor);
//g_object_unref (monitor);
//monitor = NULL;
void ensureCKeyInDesktopFil (GKeyFile *keyfile, const char *key) void ensureCKeyInDesktopFil (GKeyFile *keyfile, const char *key)
{ {
char *C_value; char *C_value;
@ -143,15 +49,15 @@ void ensureCKeyInDesktopFil (GKeyFile *keyfile, const char *key)
* This is so that if the user logs into another locale they get their * 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 * own description there rather then empty. It is not the C locale
* however, but the user created this entry herself so it's OK */ * however, but the user created this entry herself so it's OK */
C_value = kylin_start_manager_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') { if (C_value == NULL || C_value [0] == '\0') {
buffer = kylin_start_manager_key_file_get_locale_string (keyfile, key); buffer = kylin_start_manager_key_file_get_locale_string(keyfile, key);
if (buffer) { if (buffer) {
kylin_start_manager_key_file_set_string (keyfile, key, buffer); kylin_start_manager_key_file_set_string(keyfile, key, buffer);
g_free (buffer); g_free(buffer);
} }
} }
g_free (C_value); g_free(C_value);
} }
inline QString getCurrentDesktopEnvironment() inline QString getCurrentDesktopEnvironment()
@ -320,12 +226,37 @@ StartupData StartupWorker::getAppStartupDataAccrodDesktopFileName(QString &basen
return StartupData(); return StartupData();
} }
/*
* dir: fileList:
*/
void StartupWorker::updateGspXdgDir(const QString &dir, QStringList fileList) void StartupWorker::updateGspXdgDir(const QString &dir, QStringList fileList)
{ {
if (this->m_xdgMap.keys().contains(dir)) { if (this->m_xdgMap.keys().contains(dir)) {
QSet<QString> nowAutoStartSet = QSet<QString>::fromList(fileList);
//canel auto start, add the desktop file to user config dir
for(const QString &startupItem: nowAutoStartSet - QSet<QString>::fromList(this->m_xdgMap.value(dir).fileList)) {
//qDebug() << "Add startupItem===="<<startupItem;
this->newStartupInfo(startupItem, this->m_xdgMap.value(dir).index);
}
//start auto start, remove the desktop file which in user config dir
for(const QString &startupItem: QSet<QString>::fromList(this->m_xdgMap.value(dir).fileList) - nowAutoStartSet) {
//qDebug() << "Removed startupItem===="<<startupItem;
StartupData info = getStartupInfoAccordDestkopFile(startupItem);
if (info.exec.isEmpty() && info.name.isEmpty())
continue;
info.enabled = true;
info.save_mask |= SAVE_MASK_ENABLED;
this->updateEnable(info.exec, info.enabled);
this->updateSaveMask(info.exec, info.save_mask);
this->readySaveDesktopInfo(info);
}
/*
//start auto start, remove the desktop file which in user config dir //start auto start, remove the desktop file which in user config dir
foreach (QString orgFileAbsPath, this->m_xdgMap.value(dir).fileList) { foreach (QString orgFileAbsPath, this->m_xdgMap.value(dir).fileList) {
if (!fileList.contains(orgFileAbsPath)) { if (!fileList.contains(orgFileAbsPath)) {
qDebug() << "had removed orgFileAbsPath="<<orgFileAbsPath;
//had removed //had removed
StartupData info = getStartupInfoAccordDestkopFile(orgFileAbsPath); StartupData info = getStartupInfoAccordDestkopFile(orgFileAbsPath);
if (info.exec.isEmpty() && info.name.isEmpty()) if (info.exec.isEmpty() && info.name.isEmpty())
@ -342,9 +273,11 @@ void StartupWorker::updateGspXdgDir(const QString &dir, QStringList fileList)
foreach (QString nowFileAbsPath, fileList) { foreach (QString nowFileAbsPath, fileList) {
if (!this->m_xdgMap[dir].fileList.contains(nowFileAbsPath)) { if (!this->m_xdgMap[dir].fileList.contains(nowFileAbsPath)) {
//new added //new added
qDebug() << "add new nowFileAbsPath="<<nowFileAbsPath;
this->newStartupInfo(nowFileAbsPath, this->m_xdgMap.value(dir).index); this->newStartupInfo(nowFileAbsPath, this->m_xdgMap.value(dir).index);
} }
} }
*/
this->m_xdgMap[dir].fileList.clear(); this->m_xdgMap[dir].fileList.clear();
this->m_xdgMap[dir].fileList = fileList; this->m_xdgMap[dir].fileList = fileList;

View File

@ -66,6 +66,7 @@ bool FileSystemWatcher::clearWatcher()
return false; return false;
} }
} }
void FileSystemWatcher::onMountDeviceFileContentsChanged() void FileSystemWatcher::onMountDeviceFileContentsChanged()
{ {
QSet<QString> nowFileSet = getFileContentsLineByLine(DEVICE_MOUNT_PONINT_RECORD_FILE); QSet<QString> nowFileSet = getFileContentsLineByLine(DEVICE_MOUNT_PONINT_RECORD_FILE);

View File

@ -36,7 +36,6 @@ SessionService::~SessionService()
this->exitService(); this->exitService();
} }
QString SessionService::demoInfo() QString SessionService::demoInfo()
{ {
return "QtSessionDbus"; return "QtSessionDbus";

View File

@ -18,6 +18,7 @@ SystemDbusProxy::SystemDbusProxy(QObject *parent) :
SystemDbusProxy::~SystemDbusProxy() SystemDbusProxy::~SystemDbusProxy()
{ {
this->exitService();
m_handler->deleteLater(); m_handler->deleteLater();
} }

View File

@ -69,5 +69,6 @@ void SystemService::sendCustomData(const CustomData &message)
void SystemService::exitService() void SystemService::exitService()
{ {
qDebug() << "ready to exit service";
qApp->exit(0); qApp->exit(0);
} }

File diff suppressed because it is too large Load Diff

View File

@ -23,6 +23,10 @@
#include <QScopedPointer> #include <QScopedPointer>
#include <QDBusInterface> #include <QDBusInterface>
#include "../qdbusservice/systemdbus/data/systemdbusproxy.h"
#include "../qdbusservice/systemdbus/customdata.h"
#include "../qdbusservice/systemdbus/customdatalist.h"
class QTimer; class QTimer;
class SessionDispatcher; class SessionDispatcher;
class SystemDispatcher; class SystemDispatcher;
@ -328,9 +332,10 @@ signals:
void sendFileManagerData(bool locationReplacePathbar, bool autoMountMedia, bool autoOpenFolder, bool promptAutorunPrograms, int thumbnailIconSize, int thumbnailCacheTime, int thumbnailCacheSize); void sendFileManagerData(bool locationReplacePathbar, bool autoMountMedia, bool autoOpenFolder, bool promptAutorunPrograms, int thumbnailIconSize, int thumbnailCacheTime, int thumbnailCacheSize);
private: private:
QDBusInterface *iface = nullptr; QDBusInterface *m_powerIface = nullptr;
SessionDispatcher *sessioninterface = nullptr; SessionDispatcher *m_sessionInterface = nullptr;
SystemDispatcher *systeminterface = nullptr; SystemDispatcher *m_systemInterface = nullptr;
SystemDbusProxy *m_qSystemDbus = nullptr;
QString desktop; QString desktop;
bool m_existBattery; bool m_existBattery;

View File

@ -28,10 +28,6 @@
//#include "cameramanager.h" //#include "cameramanager.h"
#include "../component/threadpool.h" #include "../component/threadpool.h"
#include "dataworker.h" #include "dataworker.h"
#include "../qdbusservice/systemdbus/data/systemdbusproxy.h"
#include "../qdbusservice/systemdbus/customdata.h"
#include "../qdbusservice/systemdbus/customdatalist.h"
//QDBusPendingCallWatcher *m_getAllPendingCallWatcher; //QDBusPendingCallWatcher *m_getAllPendingCallWatcher;
// QDBusError m_lastExtendedError; // QDBusError m_lastExtendedError;
@ -254,11 +250,6 @@ MainWindow::MainWindow(QString cur_arch, int d_count, QWidget* parent, Qt::Windo
this->initAnimation(); this->initAnimation();
this->hide(); this->hide();
m_qSystemDbus = new SystemDbusProxy;
connect(m_qSystemDbus, &SystemDbusProxy::reportAlert, this, [ = ](int ret, const QString &description) {
qDebug() <<"ret="<<ret<<",description="<<description;
});
this->startDbusDaemon(); this->startDbusDaemon();
// 添加阴影 // 添加阴影
@ -271,7 +262,7 @@ MainWindow::MainWindow(QString cur_arch, int d_count, QWidget* parent, Qt::Windo
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {
delete m_qSystemDbus; // delete m_qSystemDbus;
if (m_dataWorker) { if (m_dataWorker) {
m_dataWorker->deleteLater(); m_dataWorker->deleteLater();
@ -374,9 +365,6 @@ void MainWindow::onInitDataFinished()
this->displayMainWindow(); this->displayMainWindow();
qDebug() << "m_qSystemDbus->demoInfo()===="<<m_qSystemDbus->demoInfo();
qDebug() << m_qSystemDbus->getCustomData().hash;
//bind setting notify signal //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(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))); // connect(m_dataWorker, SIGNAL(bool_value_notify(QString,bool)), setting_widget, SIGNAL(bool_value_notify(QString,bool)));
@ -960,7 +948,7 @@ void MainWindow::startDbusDaemon()
// systeminterface = new SystemDispatcher; // systeminterface = new SystemDispatcher;
m_dataWorker = new DataWorker(this->desktop); m_dataWorker = new DataWorker(this->desktop);
QThread *w_thread = ThreadPool::Instance()->newThread(); QThread *w_thread = ThreadPool::Instance()->createNewThread();
m_dataWorker->moveToThread(w_thread); m_dataWorker->moveToThread(w_thread);
connect(w_thread, SIGNAL(started()), m_dataWorker, SLOT(doWork())); connect(w_thread, SIGNAL(started()), m_dataWorker, SLOT(doWork()));
connect(m_dataWorker, SIGNAL(dataLoadFinished()), this, SLOT(onInitDataFinished())); connect(m_dataWorker, SIGNAL(dataLoadFinished()), this, SLOT(onInitDataFinished()));

View File

@ -173,11 +173,7 @@ private:
// QStringList skinlist; // QStringList skinlist;
ShadowWidget *shadow_widget; ShadowWidget *shadow_widget;
int display_count; int display_count;
DataWorker *m_dataWorker = nullptr; DataWorker *m_dataWorker = nullptr;
SystemDbusProxy *m_qSystemDbus = nullptr;
}; };
class GlobalData // define by hebing,just for transmit var class GlobalData // define by hebing,just for transmit var