forked from openkylin/ukui-menu
1.新增应用数据更新,删除和增加信号,2.修改参数FolderHelper内函数参数名
This commit is contained in:
parent
5098dce1cc
commit
920c9ad99e
|
@ -31,7 +31,9 @@ public:
|
|||
explicit AppDataWorker(AppDataManager *appManager = nullptr);
|
||||
|
||||
Q_SIGNALS:
|
||||
void appDataChanged();
|
||||
void appAdded(QList<DataEntity> apps);
|
||||
void appUpdated(QList<DataEntity> apps);
|
||||
void appDeleted(QStringList idList);
|
||||
void favoriteAppChanged();
|
||||
void appDataBaseOpenFailed();
|
||||
|
||||
|
@ -43,14 +45,19 @@ private Q_SLOTS:
|
|||
|
||||
private:
|
||||
void updateFavoriteApps();
|
||||
void removeApps(QStringList& appIdList, QStringList &removedIdList);
|
||||
void updateApps(QVector<UkuiSearch::AppInfoResult> &infos, QList<DataEntity> &apps);
|
||||
void appendApps(const QVector<UkuiSearch::AppInfoResult> &infos, QList<DataEntity> &apps);
|
||||
|
||||
private:
|
||||
AppDataManager *m_appManager{nullptr};
|
||||
UkuiSearch::AppInfoTable *m_appInfoTable = nullptr;
|
||||
UkuiSearch::AppInfoTable *m_appInfoTable{nullptr};
|
||||
};
|
||||
|
||||
AppDataWorker::AppDataWorker(AppDataManager *appManager) : QObject(nullptr), m_appManager(appManager)
|
||||
{
|
||||
qRegisterMetaType<QList<DataEntity> >("QList<DataEntity>");
|
||||
qRegisterMetaType<QVector<DataEntity> >("QVector<DataEntity>");
|
||||
m_appInfoTable = new UkuiSearch::AppInfoTable(this);
|
||||
if (!m_appInfoTable || !m_appManager) {
|
||||
return;
|
||||
|
@ -75,9 +82,6 @@ void AppDataWorker::initAppData()
|
|||
return;
|
||||
}
|
||||
|
||||
// parse app-info
|
||||
QVector<DataEntity> normalApps;
|
||||
|
||||
for (const auto &info : appInfos) {
|
||||
DataEntity app;
|
||||
app.setTop(info.top);
|
||||
|
@ -91,12 +95,7 @@ void AppDataWorker::initAppData()
|
|||
app.setCategory(info.category);
|
||||
app.setFirstLetter(info.firstLetter);
|
||||
|
||||
normalApps.append(app);
|
||||
}
|
||||
|
||||
{
|
||||
QMutexLocker locker(&m_appManager->m_mutex);
|
||||
m_appManager->m_normalApps.swap(normalApps);
|
||||
m_appManager->m_normalApps.append(app);
|
||||
}
|
||||
|
||||
updateFavoriteApps();
|
||||
|
@ -134,25 +133,30 @@ void AppDataWorker::onAppAdded(const QVector<UkuiSearch::AppInfoResult> &infos)
|
|||
return;
|
||||
}
|
||||
|
||||
{
|
||||
QMutexLocker locker(&m_appManager->m_mutex);
|
||||
for (const auto &info: infos) {
|
||||
DataEntity app;
|
||||
app.setTop(info.top);
|
||||
app.setLock(info.lock == 1);
|
||||
app.setFavorite(info.favorite);
|
||||
app.setLaunchTimes(info.launchTimes);
|
||||
app.setId(info.desktopPath);
|
||||
app.setIcon(APP_ICON_PREFIX + info.iconName);
|
||||
app.setName(info.appLocalName);
|
||||
app.setCategory(info.category);
|
||||
app.setFirstLetter(info.firstLetter);
|
||||
QList<DataEntity> apps;
|
||||
appendApps(infos, apps);
|
||||
|
||||
m_appManager->m_normalApps.append(app);
|
||||
}
|
||||
Q_EMIT appAdded(apps);
|
||||
}
|
||||
|
||||
void AppDataWorker::appendApps(const QVector<UkuiSearch::AppInfoResult> &infos, QList<DataEntity> &apps)
|
||||
{
|
||||
QMutexLocker locker(&m_appManager->m_mutex);
|
||||
for (const auto &info : infos) {
|
||||
DataEntity app;
|
||||
app.setTop(info.top);
|
||||
app.setLock(info.lock == 1);
|
||||
app.setFavorite(info.favorite);
|
||||
app.setLaunchTimes(info.launchTimes);
|
||||
app.setId(info.desktopPath);
|
||||
app.setIcon(APP_ICON_PREFIX + info.iconName);
|
||||
app.setName(info.appLocalName);
|
||||
app.setCategory(info.category);
|
||||
app.setFirstLetter(info.firstLetter);
|
||||
|
||||
m_appManager->m_normalApps.append(app);
|
||||
apps.append(app);
|
||||
}
|
||||
|
||||
Q_EMIT appDataChanged();
|
||||
}
|
||||
|
||||
void AppDataWorker::onAppUpdated(QVector<UkuiSearch::AppInfoResult> infos)
|
||||
|
@ -161,6 +165,16 @@ void AppDataWorker::onAppUpdated(QVector<UkuiSearch::AppInfoResult> infos)
|
|||
return;
|
||||
}
|
||||
|
||||
QList<DataEntity> apps;
|
||||
updateApps(infos, apps);
|
||||
Q_EMIT appUpdated(apps);
|
||||
|
||||
updateFavoriteApps();
|
||||
}
|
||||
|
||||
void AppDataWorker::updateApps(QVector<UkuiSearch::AppInfoResult> &infos, QList<DataEntity> &apps)
|
||||
{
|
||||
QMutexLocker locker(&m_appManager->m_mutex);
|
||||
for (auto &app : m_appManager->m_normalApps) {
|
||||
if (infos.isEmpty()) {
|
||||
break;
|
||||
|
@ -168,8 +182,6 @@ void AppDataWorker::onAppUpdated(QVector<UkuiSearch::AppInfoResult> infos)
|
|||
for (int i = 0; i < infos.size(); ++i) {
|
||||
const UkuiSearch::AppInfoResult &info = infos.at(i);
|
||||
if (info.desktopPath == app.id()) {
|
||||
QMutexLocker locker(&m_appManager->m_mutex);
|
||||
|
||||
app.setTop(info.top);
|
||||
app.setLock(info.lock == 1);
|
||||
app.setFavorite(info.favorite);
|
||||
|
@ -179,14 +191,12 @@ void AppDataWorker::onAppUpdated(QVector<UkuiSearch::AppInfoResult> infos)
|
|||
app.setCategory(info.category);
|
||||
app.setFirstLetter(info.firstLetter);
|
||||
|
||||
apps.append(app);
|
||||
infos.remove(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Q_EMIT appDataChanged();
|
||||
updateFavoriteApps();
|
||||
}
|
||||
|
||||
void AppDataWorker::onAppDeleted(QStringList infos)
|
||||
|
@ -194,28 +204,29 @@ void AppDataWorker::onAppDeleted(QStringList infos)
|
|||
if (infos.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
QStringList removedIdList;
|
||||
removeApps(infos, removedIdList);
|
||||
Q_EMIT appDeleted(removedIdList);
|
||||
|
||||
QVector<DataEntity>::iterator appIterator = m_appManager->m_normalApps.begin();
|
||||
for (; appIterator != m_appManager->m_normalApps.end(); ++appIterator) {
|
||||
if (infos.isEmpty()) {
|
||||
break;
|
||||
}
|
||||
|
||||
QStringList::iterator infoIterator = infos.begin();
|
||||
for (; infoIterator != infos.end(); ++infoIterator) {
|
||||
if ((*appIterator).id() == *infoIterator) {
|
||||
QMutexLocker locker(&m_appManager->m_mutex);
|
||||
m_appManager->m_normalApps.erase(appIterator);
|
||||
infos.erase(infoIterator);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Q_EMIT appDataChanged();
|
||||
updateFavoriteApps();
|
||||
}
|
||||
|
||||
void AppDataWorker::removeApps(QStringList &appIdList, QStringList &removedIdList)
|
||||
{
|
||||
QMutexLocker locker(&m_appManager->m_mutex);
|
||||
QList<DataEntity> &normalApps = m_appManager->m_normalApps;
|
||||
QList<DataEntity>::iterator iterator = normalApps.begin();
|
||||
|
||||
while (iterator != normalApps.end() && !appIdList.isEmpty()) {
|
||||
if (appIdList.removeOne((*iterator).id())) {
|
||||
removedIdList.append((*iterator).id());
|
||||
iterator = normalApps.erase(iterator);
|
||||
continue;
|
||||
}
|
||||
++iterator;
|
||||
}
|
||||
}
|
||||
|
||||
// ===== AppDataManager ===== //
|
||||
AppDataManager *AppDataManager::instance()
|
||||
{
|
||||
|
@ -229,7 +240,9 @@ AppDataManager::AppDataManager()
|
|||
appDataWorker->moveToThread(&m_workerThread);
|
||||
|
||||
connect(&m_workerThread, &QThread::finished, appDataWorker, &QObject::deleteLater);
|
||||
connect(appDataWorker, &AppDataWorker::appDataChanged, this, &AppDataManager::appDataChanged);
|
||||
connect(appDataWorker, &AppDataWorker::appAdded, this, &AppDataManager::appAdded);
|
||||
connect(appDataWorker, &AppDataWorker::appDeleted, this, &AppDataManager::appDeleted);
|
||||
connect(appDataWorker, &AppDataWorker::appUpdated, this, &AppDataManager::appUpdated);
|
||||
connect(appDataWorker, &AppDataWorker::favoriteAppChanged, this, &AppDataManager::favoriteAppChanged);
|
||||
|
||||
m_workerThread.start();
|
||||
|
@ -241,7 +254,7 @@ AppDataManager::~AppDataManager()
|
|||
m_workerThread.wait();
|
||||
}
|
||||
|
||||
QVector<DataEntity> AppDataManager::normalApps()
|
||||
QList<DataEntity> AppDataManager::normalApps()
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
return m_normalApps;
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <QThread>
|
||||
#include <QMutex>
|
||||
#include <QMutexLocker>
|
||||
#include <QList>
|
||||
|
||||
#include "commons.h"
|
||||
|
||||
|
@ -43,10 +44,13 @@ public:
|
|||
AppDataManager(AppDataManager&& obj) = delete;
|
||||
AppDataManager &operator=(AppDataManager&& obj) = delete;
|
||||
|
||||
QVector<DataEntity> normalApps();
|
||||
QList<DataEntity> normalApps();
|
||||
QVector<DataEntity> favoriteApps();
|
||||
|
||||
Q_SIGNALS:
|
||||
void appAdded(QList<DataEntity> apps);
|
||||
void appUpdated(QList<DataEntity> apps);
|
||||
void appDeleted(QStringList idList);
|
||||
void appDataChanged();
|
||||
void favoriteAppChanged();
|
||||
|
||||
|
@ -56,7 +60,7 @@ private:
|
|||
private:
|
||||
QMutex m_mutex;
|
||||
QThread m_workerThread;
|
||||
QVector<DataEntity> m_normalApps;
|
||||
QList<DataEntity> m_normalApps;
|
||||
QVector<DataEntity> m_favoriteApps;
|
||||
};
|
||||
|
||||
|
|
|
@ -69,9 +69,9 @@ void AppFolderHelper::insertFolder(const Folder &folder)
|
|||
m_folders.append(folder);
|
||||
}
|
||||
|
||||
void AppFolderHelper::addAppToFolder(const QString& appName, const QString& folderName)
|
||||
void AppFolderHelper::addAppToFolder(const QString& appId, const QString& folderName)
|
||||
{
|
||||
if (appName.isEmpty() || folderName.isEmpty()) {
|
||||
if (appId.isEmpty() || folderName.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -79,8 +79,8 @@ void AppFolderHelper::addAppToFolder(const QString& appName, const QString& fold
|
|||
QMutexLocker locker(&m_mutex);
|
||||
Folder *folder = findFolder(folderName);
|
||||
if (folder) {
|
||||
if (!folder->apps.contains(appName)) {
|
||||
folder->apps.append(appName);
|
||||
if (!folder->apps.contains(appId)) {
|
||||
folder->apps.append(appId);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ void AppFolderHelper::addAppToFolder(const QString& appName, const QString& fold
|
|||
// 新文件夹放最后
|
||||
Folder folder;
|
||||
folder.name = folderName;
|
||||
folder.apps.append(appName);
|
||||
folder.apps.append(appId);
|
||||
if (m_folders.isEmpty()) {
|
||||
folder.index = 1;
|
||||
} else {
|
||||
|
@ -99,9 +99,9 @@ void AppFolderHelper::addAppToFolder(const QString& appName, const QString& fold
|
|||
insertFolder(folder);
|
||||
}
|
||||
|
||||
void AppFolderHelper::removeAppFromFolder(const QString &appName, const QString &folderName)
|
||||
void AppFolderHelper::removeAppFromFolder(const QString &appId, const QString &folderName)
|
||||
{
|
||||
if (appName.isEmpty() || folderName.isEmpty()) {
|
||||
if (appId.isEmpty() || folderName.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -111,8 +111,8 @@ void AppFolderHelper::removeAppFromFolder(const QString &appName, const QString
|
|||
return;
|
||||
}
|
||||
|
||||
if (folder->apps.contains(appName)) {
|
||||
folder->apps.removeOne(appName);
|
||||
if (folder->apps.contains(appId)) {
|
||||
folder->apps.removeOne(appId);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -140,16 +140,42 @@ QVector<Folder> AppFolderHelper::folderData()
|
|||
return m_folders;
|
||||
}
|
||||
|
||||
const Folder *AppFolderHelper::searchFolder(const QString &folderName)
|
||||
bool AppFolderHelper::searchFolder(const QString& folderName, Folder &folder)
|
||||
{
|
||||
if (folderName.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QMutexLocker locker(&m_mutex);
|
||||
return findFolder(folderName);
|
||||
Folder *tmp = findFolder(folderName);
|
||||
if (!tmp) {
|
||||
return false;
|
||||
}
|
||||
|
||||
folder.name = tmp->name;
|
||||
folder.index = tmp->index;
|
||||
folder.apps = tmp->apps;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const Folder *AppFolderHelper::searchFolderByAppName(const QString &appName)
|
||||
bool AppFolderHelper::searchFolderByAppName(const QString &appId, Folder &folder)
|
||||
{
|
||||
if (appId.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QMutexLocker locker(&m_mutex);
|
||||
return findFolderByAppName(appName);
|
||||
Folder *tmp = findFolderByAppName(appId);
|
||||
if (!tmp) {
|
||||
return false;
|
||||
}
|
||||
|
||||
folder.name = tmp->name;
|
||||
folder.index = tmp->index;
|
||||
folder.apps = tmp->apps;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Folder *AppFolderHelper::findFolder(const QString &folderName)
|
||||
|
@ -171,7 +197,7 @@ Folder *AppFolderHelper::findFolder(const QString &folderName)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
Folder *AppFolderHelper::findFolderByAppName(const QString &appName)
|
||||
Folder *AppFolderHelper::findFolderByAppName(const QString &appId)
|
||||
{
|
||||
if (m_folders.empty()) {
|
||||
return nullptr;
|
||||
|
@ -179,7 +205,7 @@ Folder *AppFolderHelper::findFolderByAppName(const QString &appName)
|
|||
|
||||
QVector<Folder>::iterator iterator = m_folders.begin();
|
||||
for (; iterator != m_folders.end(); ++iterator) {
|
||||
if (iterator->apps.contains(appName)) {
|
||||
if (iterator->apps.contains(appId)) {
|
||||
return iterator;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,13 +31,13 @@ namespace UkuiMenu {
|
|||
class Folder
|
||||
{
|
||||
Q_GADGET
|
||||
Q_PROPERTY(QString index READ getIndex)
|
||||
Q_PROPERTY(int index READ getIndex)
|
||||
Q_PROPERTY(QString name READ getName)
|
||||
Q_PROPERTY(QStringList apps READ getApps)
|
||||
public:
|
||||
int getIndex() { return index; }
|
||||
QString getName() { return name; }
|
||||
QStringList getApps() { return apps; }
|
||||
int getIndex() const { return index; }
|
||||
QString getName() const { return name; }
|
||||
QStringList getApps() const { return apps; }
|
||||
|
||||
public:
|
||||
int index;
|
||||
|
@ -59,12 +59,12 @@ public:
|
|||
|
||||
// TODO 修改文件夹信息
|
||||
// xxxx
|
||||
const Folder *searchFolder(const QString& folderName);
|
||||
const Folder *searchFolderByAppName(const QString& appName);
|
||||
bool searchFolder(const QString& folderName, Folder &folder);
|
||||
bool searchFolderByAppName(const QString& appId, Folder &folder);
|
||||
QVector<Folder> folderData();
|
||||
|
||||
void addAppToFolder(const QString& appName, const QString& folderName);
|
||||
void removeAppFromFolder(const QString& appName, const QString& folderName);
|
||||
void addAppToFolder(const QString& appId, const QString& folderName);
|
||||
void removeAppFromFolder(const QString& appId, const QString& folderName);
|
||||
bool deleteFolder(const QString& folderName);
|
||||
|
||||
void forceSync();
|
||||
|
@ -78,7 +78,7 @@ private:
|
|||
void saveData();
|
||||
void insertFolder(const Folder& folder);
|
||||
Folder *findFolder(const QString& folderName);
|
||||
Folder *findFolderByAppName(const QString& appName);
|
||||
Folder *findFolderByAppName(const QString& appId);
|
||||
// TODO 配置文件监听
|
||||
|
||||
private:
|
||||
|
|
|
@ -44,6 +44,7 @@ class DataProviderPluginIFace : public QObject
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit DataProviderPluginIFace() : QObject(nullptr) {}
|
||||
virtual int index() = 0;
|
||||
virtual QString name() = 0;
|
||||
virtual QString icon() = 0;
|
||||
|
|
Loading…
Reference in New Issue