diff --git a/libsearch/appdata/app-info-table-private.h b/libsearch/appdata/app-info-table-private.h index b62ae45..b842718 100644 --- a/libsearch/appdata/app-info-table-private.h +++ b/libsearch/appdata/app-info-table-private.h @@ -67,7 +67,7 @@ private: QDBusInterface *m_appDBInterface = nullptr; AppInfoTable *q = nullptr; - QSqlDatabase m_database; + QSqlDatabase *m_database = nullptr; QString m_ConnectionName; public Q_SLOTS: diff --git a/libsearch/appdata/app-info-table.cpp b/libsearch/appdata/app-info-table.cpp index debe2e8..634f438 100644 --- a/libsearch/appdata/app-info-table.cpp +++ b/libsearch/appdata/app-info-table.cpp @@ -19,7 +19,7 @@ using namespace UkuiSearch; -AppInfoTablePrivate::AppInfoTablePrivate(AppInfoTable *parent) : QObject(parent), q(parent), m_database(QSqlDatabase()) +AppInfoTablePrivate::AppInfoTablePrivate(AppInfoTable *parent) : QObject(parent), q(parent), m_database(new QSqlDatabase()) { //dbus接收数据库信号 @@ -55,7 +55,7 @@ AppInfoTablePrivate::AppInfoTablePrivate(AppInfoTable *parent) : QObject(parent) qDebug() << "App info database currunt connection name:" << m_ConnectionName; if (!this->openDataBase()) { Q_EMIT q->DBOpenFailed(); - qWarning() << "Fail to open App DataBase, because:" << m_database.lastError(); + qWarning() << "Fail to open App DataBase, because:" << m_database->lastError(); } } @@ -224,8 +224,8 @@ bool AppInfoTablePrivate::addAppShortcut2Panel(QString &desktopfp) bool AppInfoTablePrivate::searchInstallApp(QString &keyWord, QStringList &installAppInfoRes) { bool res(true); - if (m_database.transaction()) { - QSqlQuery sql(m_database); + if (m_database->transaction()) { + QSqlQuery sql(*m_database); QString cmd; if (keyWord.size() < 2) { cmd = QString("SELECT DESKTOP_FILE_PATH,LOCAL_NAME,ICON FROM APPINFO WHERE LOCAL_NAME OR NAME_EN OR NAME_ZH OR FIRST_LETTER_OF_PINYIN LIKE '%%0%' ORDER BY FAVORITES DESC") @@ -240,12 +240,12 @@ bool AppInfoTablePrivate::searchInstallApp(QString &keyWord, QStringList &instal installAppInfoRes << sql.value(0).toString() << sql.value(1).toString() << sql.value(2).toString(); } } else { - qWarning() << QString("cmd %0 failed!").arg(cmd) << m_database.lastError(); + qWarning() << QString("cmd %0 failed!").arg(cmd) << m_database->lastError(); res = false; } - if (!m_database.commit()) { + if (!m_database->commit()) { qWarning() << "Failed to commit !" << cmd; - m_database.rollback(); + m_database->rollback(); res = false; } } else { @@ -258,8 +258,8 @@ bool AppInfoTablePrivate::searchInstallApp(QString &keyWord, QStringList &instal bool AppInfoTablePrivate::searchInstallApp(QStringList &keyWord, QStringList &installAppInfoRes) { bool res(true); - if (m_database.transaction() or keyWord.size() != 0) { - QSqlQuery sql(m_database); + if (m_database->transaction() or keyWord.size() != 0) { + QSqlQuery sql(*m_database); QString cmd; if (keyWord.at(0).size() < 2) { cmd = QString("SELECT DESKTOP_FILE_PATH,LOCAL_NAME,ICON,NAME_EN,NAME_ZH,FIRST_LETTER_OF_PINYIN FROM APPINFO" @@ -285,12 +285,12 @@ bool AppInfoTablePrivate::searchInstallApp(QStringList &keyWord, QStringList &in installAppInfoRes << sql.value(0).toString() << sql.value(1).toString() << sql.value(2).toString(); } } else { - qWarning() << QString("cmd %0 failed!").arg(cmd) << m_database.lastError(); + qWarning() << QString("cmd %0 failed!").arg(cmd) << m_database->lastError(); res = false; } - if (!m_database.commit()) { + if (!m_database->commit()) { qWarning() << "Failed to commit !" << cmd; - m_database.rollback(); + m_database->rollback(); res = false; } } else { @@ -344,26 +344,26 @@ bool AppInfoTablePrivate::uninstallApp(QString &desktopfp) QString AppInfoTablePrivate::lastError() const { - return m_database.lastError().text(); + return m_database->lastError().text(); } bool AppInfoTablePrivate::setAppLaunchTimes(QString &desktopfp, size_t num) { bool res(true); - if (m_database.transaction()) { - QSqlQuery sql(m_database); + if (m_database->transaction()) { + QSqlQuery sql(*m_database); QString cmd = QString("UPDATE appInfo SET MODIFYED_TIME='%0', LAUNCH_TIMES=%1, LAUNCHED=%2 WHERE DESKTOP_FILE_PATH='%3'") .arg(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss")) .arg(num) .arg(1) .arg(desktopfp); if (!sql.exec(cmd)) { - qWarning() << "Set app favorites state failed!" << m_database.lastError(); + qWarning() << "Set app favorites state failed!" << m_database->lastError(); res = false; } - if (!m_database.commit()) { + if (!m_database->commit()) { qWarning() << "Failed to commit !" << cmd; - m_database.rollback(); + m_database->rollback(); res = false; } } else { @@ -376,8 +376,8 @@ bool AppInfoTablePrivate::setAppLaunchTimes(QString &desktopfp, size_t num) bool AppInfoTablePrivate::updateAppLaunchTimes(QString &desktopfp) { bool res(true); - if (m_database.transaction()) { - QSqlQuery sql(m_database); + if (m_database->transaction()) { + QSqlQuery sql(*m_database); QString cmd = QString("SELECT LAUNCH_TIMES FROM APPINFO WHERE DESKTOP_FILE_PATH='%1'").arg(desktopfp); if (sql.exec(cmd)) { if (sql.next()) { @@ -387,7 +387,7 @@ bool AppInfoTablePrivate::updateAppLaunchTimes(QString &desktopfp) .arg(1) .arg(desktopfp); if (!sql.exec(cmd)) { - qWarning() << "Set app favorites state failed!" << m_database.lastError(); + qWarning() << "Set app favorites state failed!" << m_database->lastError(); res = false; } } else { @@ -398,9 +398,9 @@ bool AppInfoTablePrivate::updateAppLaunchTimes(QString &desktopfp) qWarning() << "Failed to exec:" << cmd; res = false; } - if (!m_database.commit()) { + if (!m_database->commit()) { qWarning() << "Failed to commit !" << cmd; - m_database.rollback(); + m_database->rollback(); res = false; } } else { @@ -413,19 +413,19 @@ bool AppInfoTablePrivate::updateAppLaunchTimes(QString &desktopfp) bool AppInfoTablePrivate::setAppLockState(QString &desktopfp, size_t num) { bool res(true); - if (m_database.transaction()) { - QSqlQuery sql(m_database); + if (m_database->transaction()) { + QSqlQuery sql(*m_database); QString cmd = QString("UPDATE appInfo SET MODIFYED_TIME='%0', LOCK=%1 WHERE DESKTOP_FILE_PATH='%2'") .arg(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss")) .arg(num) .arg(desktopfp); if (!sql.exec(cmd)) { - qWarning() << "Set app favorites state failed!" << m_database.lastError(); + qWarning() << "Set app favorites state failed!" << m_database->lastError(); res = false; } - if (!m_database.commit()) { + if (!m_database->commit()) { qWarning() << "Failed to commit !" << cmd; - m_database.rollback(); + m_database->rollback(); res = false; } } else { @@ -438,7 +438,7 @@ bool AppInfoTablePrivate::setAppLockState(QString &desktopfp, size_t num) bool AppInfoTablePrivate::getAllAppDesktopList(QStringList &list) { bool res(true); - QSqlQuery sql(m_database); + QSqlQuery sql(*m_database); QString cmd = QString("SELECT DESKTOP_FILE_PATH FROM APPINFO"); if (sql.exec(cmd)) { @@ -446,7 +446,7 @@ bool AppInfoTablePrivate::getAllAppDesktopList(QStringList &list) list.append(sql.value(0).toString()); } } else { - qWarning() << QString("cmd %0 failed!").arg(cmd) << m_database.lastError(); + qWarning() << QString("cmd %0 failed!").arg(cmd) << m_database->lastError(); res = false; } @@ -456,14 +456,14 @@ bool AppInfoTablePrivate::getAllAppDesktopList(QStringList &list) bool AppInfoTablePrivate::getFavoritesAppList(QStringList &list) { bool res(true); - QSqlQuery sql(m_database); + QSqlQuery sql(*m_database); QString cmd = QString("SELECT DESKTOP_FILE_PATH FROM APPINFO WHERE FAVORITES!=0 ORDER BY FAVORITES"); if (sql.exec(cmd)) { while (sql.next()) { list.append(sql.value(0).toString()); } } else { - qWarning() << QString("cmd %0 failed!").arg(cmd) << m_database.lastError(); + qWarning() << QString("cmd %0 failed!").arg(cmd) << m_database->lastError(); res = false; } return res; @@ -472,7 +472,7 @@ bool AppInfoTablePrivate::getFavoritesAppList(QStringList &list) bool AppInfoTablePrivate::getTopAppList(QStringList &list) { bool res(true); - QSqlQuery sql(m_database); + QSqlQuery sql(*m_database); QString cmd = QString("SELECT DESKTOP_FILE_PATH FROM APPINFO WHERE TOP!=0 ORDER BY TOP"); if (sql.exec(cmd)) { @@ -480,7 +480,7 @@ bool AppInfoTablePrivate::getTopAppList(QStringList &list) list.append(sql.value(0).toString()); } } else { - qWarning() << QString("cmd %0 failed!").arg(cmd) << m_database.lastError(); + qWarning() << QString("cmd %0 failed!").arg(cmd) << m_database->lastError(); res = false; } @@ -490,9 +490,9 @@ bool AppInfoTablePrivate::getTopAppList(QStringList &list) bool AppInfoTablePrivate::getLaunchTimesAppList(QStringList &list) { bool res(true); - if (m_database.transaction()) { - QSqlQuery sql(m_database); - QSqlQuery sqlque(m_database); + if (m_database->transaction()) { + QSqlQuery sql(*m_database); + QSqlQuery sqlque(*m_database); QString cmd = QString("SELECT DESKTOP_FILE_PATH FROM APPINFO ORDER BY LAUNCH_TIMES"); int count = 0; if (sql.exec(cmd)) { @@ -502,18 +502,18 @@ bool AppInfoTablePrivate::getLaunchTimesAppList(QStringList &list) .arg(++count) .arg(sql.value(0).toString()); if (!sqlque.exec(cmd)) { - qWarning() << QString("cmd %0 failed!").arg(cmd) << m_database.lastError(); + qWarning() << QString("cmd %0 failed!").arg(cmd) << m_database->lastError(); res = false; break; } } } else { - qWarning() << QString("cmd %0 failed!").arg(cmd) << m_database.lastError(); + qWarning() << QString("cmd %0 failed!").arg(cmd) << m_database->lastError(); res = false; } - if (!m_database.commit()) { + if (!m_database->commit()) { qWarning() << "Failed to commit !" << cmd; - m_database.rollback(); + m_database->rollback(); res = false; } } else { @@ -526,13 +526,19 @@ bool AppInfoTablePrivate::getLaunchTimesAppList(QStringList &list) AppInfoTablePrivate::~AppInfoTablePrivate() { this->closeDataBase(); + if (m_signalTransInterface) + delete m_signalTransInterface; + m_signalTransInterface = nullptr; + if (m_appDBInterface) + delete m_appDBInterface; + m_appDBInterface = nullptr; } bool AppInfoTablePrivate::initDateBaseConnection() { - m_database.setDatabaseName(APP_DATABASE_PATH + APP_DATABASE_NAME); - if(!m_database.open()) { - qWarning() << m_database.lastError(); + m_database->setDatabaseName(APP_DATABASE_PATH + APP_DATABASE_NAME); + if(!m_database->open()) { + qWarning() << m_database->lastError(); return false; // QApplication::quit(); } @@ -541,10 +547,10 @@ bool AppInfoTablePrivate::initDateBaseConnection() bool AppInfoTablePrivate::openDataBase() { - m_database = QSqlDatabase::addDatabase("QSQLITE", m_ConnectionName); - m_database.setDatabaseName(APP_DATABASE_PATH + APP_DATABASE_NAME); + *m_database = QSqlDatabase::addDatabase("QSQLITE", m_ConnectionName); + m_database->setDatabaseName(APP_DATABASE_PATH + APP_DATABASE_NAME); - if(!m_database.open()) { + if(!m_database->open()) { return false; } return true; @@ -552,8 +558,9 @@ bool AppInfoTablePrivate::openDataBase() void AppInfoTablePrivate::closeDataBase() { - m_database.close(); -// delete m_database; + m_database->close(); + delete m_database; + m_database = nullptr; QSqlDatabase::removeDatabase(m_ConnectionName); } diff --git a/libsearch/appsearch/app-search-plugin.cpp b/libsearch/appsearch/app-search-plugin.cpp index bb8e66b..dc3bfc4 100644 --- a/libsearch/appsearch/app-search-plugin.cpp +++ b/libsearch/appsearch/app-search-plugin.cpp @@ -333,16 +333,14 @@ bool AppSearchPlugin::installAppAction(const QString & name) { "/com/kylin/softwarecenter", "com.kylin.utiliface", QDBusConnection::sessionBus()); - + bool res(false); if(interface->isValid()) { //软件商店已打开,直接跳转 interface->call("show_search_result", name); - bool reply = QDBusReply(interface->call(QString("show_search_result"), name)); - return reply; + res = QDBusReply(interface->call(QString("show_search_result"), name)); } else { //软件商店未打开,打开软件商店下载此软件 qDebug() << "Softwarecenter has not been launched, now launch it." << name; - bool res(false); QDBusInterface * appLaunchInterface = new QDBusInterface("com.kylin.AppManager", "/com/kylin/AppManager", "com.kylin.AppManager", @@ -363,12 +361,17 @@ bool AppSearchPlugin::installAppAction(const QString & name) { if(appLaunchInterface) { delete appLaunchInterface; } - appLaunchInterface = NULL; - if (res) - return true; - QProcess process; - return process.startDetached(QString("kylin-software-center -find %1").arg(name)); + appLaunchInterface = nullptr; + if (!res) { + QProcess process; + res = process.startDetached(QString("kylin-software-center -find %1").arg(name)); + } } + if(interface) { + delete interface; + } + interface = nullptr; + return res; } //AppSearch::AppSearch(DataQueue *searchResult, DataQueue* appSearchResults, UkuiSearchTask *appSearchTask, QString keyword, size_t uniqueSymbol) diff --git a/libsearch/dirwatcher/dir-watcher.cpp b/libsearch/dirwatcher/dir-watcher.cpp index 54c8d86..55bcb87 100644 --- a/libsearch/dirwatcher/dir-watcher.cpp +++ b/libsearch/dirwatcher/dir-watcher.cpp @@ -25,6 +25,13 @@ DirWatcher::DirWatcher(QObject *parent) } } +DirWatcher::~DirWatcher() +{ + if (m_dbusInterface) + delete m_dbusInterface; + m_dbusInterface = nullptr; +} + DirWatcher *DirWatcher::getDirWatcher() { std::call_once(flag, [ & ] { diff --git a/libsearch/dirwatcher/dir-watcher.h b/libsearch/dirwatcher/dir-watcher.h index 56ea7e5..041acb3 100644 --- a/libsearch/dirwatcher/dir-watcher.h +++ b/libsearch/dirwatcher/dir-watcher.h @@ -31,7 +31,7 @@ Q_SIGNALS: void removeIndexItem(const QString&); private: DirWatcher(QObject *parent = nullptr); - ~DirWatcher() = default; + ~DirWatcher(); QDBusInterface *m_dbusInterface = nullptr; diff --git a/libsearch/index/ukui-search-qdbus.cpp b/libsearch/index/ukui-search-qdbus.cpp index 54070b3..5c6159e 100644 --- a/libsearch/index/ukui-search-qdbus.cpp +++ b/libsearch/index/ukui-search-qdbus.cpp @@ -31,7 +31,8 @@ UkuiSearchQDBus::UkuiSearchQDBus() { } } UkuiSearchQDBus::~UkuiSearchQDBus() { - delete this->tmpSystemQDBusInterface; + if (this->tmpSystemQDBusInterface) + delete this->tmpSystemQDBusInterface; this->tmpSystemQDBusInterface = nullptr; } diff --git a/libsearch/searchinterface/searchtasks/app-search-task.cpp b/libsearch/searchinterface/searchtasks/app-search-task.cpp index 13e6dd0..94e749f 100644 --- a/libsearch/searchinterface/searchtasks/app-search-task.cpp +++ b/libsearch/searchinterface/searchtasks/app-search-task.cpp @@ -143,7 +143,9 @@ void AppSearchWorker::run() AppSearchWorker::~AppSearchWorker() { - + if (m_interFace) + delete m_interFace; + m_interFace = nullptr; } void AppSearchWorker::sendErrorMsg(const QString &msg) diff --git a/libsearch/searchinterface/searchtasks/file-search-task.cpp b/libsearch/searchinterface/searchtasks/file-search-task.cpp index c5a0024..9b6f73b 100644 --- a/libsearch/searchinterface/searchtasks/file-search-task.cpp +++ b/libsearch/searchinterface/searchtasks/file-search-task.cpp @@ -197,6 +197,8 @@ bool FileSearchWorker::directSearch() while (!searchPathQueue.empty()) { dir.setPath(searchPathQueue.dequeue()); + if (!dir.exists()) + continue; infoList = dir.entryInfoList(); for (const auto &fileInfo : infoList) { diff --git a/ukui-search-service-dir-manager/dirwatcher/dir-watcher.cpp b/ukui-search-service-dir-manager/dirwatcher/dir-watcher.cpp index 5bc1007..34b0883 100644 --- a/ukui-search-service-dir-manager/dirwatcher/dir-watcher.cpp +++ b/ukui-search-service-dir-manager/dirwatcher/dir-watcher.cpp @@ -42,6 +42,7 @@ DirWatcher::~DirWatcher() if(m_qSettings){ delete m_qSettings; } + m_qSettings = nullptr; } DirWatcher *DirWatcher::getDirWatcher()