新增文件夹界面后端
This commit is contained in:
parent
634688f433
commit
c9ab90589d
|
@ -85,6 +85,7 @@ set(SOURCE_FILES
|
||||||
src/model/label-model.cpp src/model/label-model.h
|
src/model/label-model.cpp src/model/label-model.h
|
||||||
src/model/app-group-model.cpp src/model/app-group-model.h
|
src/model/app-group-model.cpp src/model/app-group-model.h
|
||||||
src/model/model-manager.cpp src/model/model-manager.h
|
src/model/model-manager.cpp src/model/model-manager.h
|
||||||
|
src/model/folder-model.cpp src/model/folder-model.h
|
||||||
src/settings/settings.cpp src/settings/settings.h
|
src/settings/settings.cpp src/settings/settings.h
|
||||||
src/uiconfig/color-helper.cpp src/uiconfig/color-helper.h
|
src/uiconfig/color-helper.cpp src/uiconfig/color-helper.h
|
||||||
src/uiconfig/theme-palette.cpp src/uiconfig/theme-palette.h
|
src/uiconfig/theme-palette.cpp src/uiconfig/theme-palette.h
|
||||||
|
@ -115,6 +116,7 @@ set(QRC_FILES qml/qml.qrc res/res.qrc)
|
||||||
# desktop file
|
# desktop file
|
||||||
set(DESKTOP_FILE data/ukui-menu.desktop)
|
set(DESKTOP_FILE data/ukui-menu.desktop)
|
||||||
set(GSETTING_FILE data/org.ukui.menu.settings.gschema.xml)
|
set(GSETTING_FILE data/org.ukui.menu.settings.gschema.xml)
|
||||||
|
set(GLOBAL_CONFIG_FILE data/ukui-menu-global-config.conf)
|
||||||
# data files
|
# data files
|
||||||
#set(DATA_FILES data/xxx)
|
#set(DATA_FILES data/xxx)
|
||||||
# extension
|
# extension
|
||||||
|
@ -157,4 +159,5 @@ install(FILES ${QM_FILES} DESTINATION "${UKUI_MENU_TRANSLATION_DIR}")
|
||||||
# 安装desktop文件
|
# 安装desktop文件
|
||||||
install(FILES ${DESKTOP_FILE} DESTINATION "/etc/xdg/autostart")
|
install(FILES ${DESKTOP_FILE} DESTINATION "/etc/xdg/autostart")
|
||||||
install(FILES ${GSETTING_FILE} DESTINATION "/usr/share/glib-2.0/schemas")
|
install(FILES ${GSETTING_FILE} DESTINATION "/usr/share/glib-2.0/schemas")
|
||||||
|
install(FILES ${GLOBAL_CONFIG_FILE} DESTINATION "${UKUI_MENU_DATA_DIR}")
|
||||||
#install(FILES ${EXTENSION_IFACE_QML_FILES} DESTINATION "${UKUI_MENU_EXTENSION_IFACE_QML_DIR}")
|
#install(FILES ${EXTENSION_IFACE_QML_FILES} DESTINATION "${UKUI_MENU_EXTENSION_IFACE_QML_DIR}")
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
#include "app-folder-helper.h"
|
#include "app-folder-helper.h"
|
||||||
#include "menu-manager.h"
|
#include "menu-manager.h"
|
||||||
|
#include "app-data-manager.h"
|
||||||
|
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
|
@ -96,7 +97,7 @@ void FolderMenuProvider::folderMenuForNormal(QObject *parent, const QString &app
|
||||||
|
|
||||||
QList<Folder> folders = AppFolderHelper::instance()->folderData();
|
QList<Folder> folders = AppFolderHelper::instance()->folderData();
|
||||||
for (const Folder &folder : folders) {
|
for (const Folder &folder : folders) {
|
||||||
QString name = QObject::tr("Add to %1").arg(folder.getName());
|
QString name = QObject::tr("Add to \"%1\"").arg(folder.getName());
|
||||||
QAction* act = new QAction(name, subMenu);
|
QAction* act = new QAction(name, subMenu);
|
||||||
QObject::connect(act, &QAction::triggered, parent, [appId, folder] {
|
QObject::connect(act, &QAction::triggered, parent, [appId, folder] {
|
||||||
AppFolderHelper::instance()->addAppToFolder(appId, folder.getId());
|
AppFolderHelper::instance()->addAppToFolder(appId, folder.getId());
|
||||||
|
@ -183,8 +184,7 @@ void AppFolderHelper::addAppToFolder(const QString &appId, const int &folderId)
|
||||||
}
|
}
|
||||||
|
|
||||||
forceSync();
|
forceSync();
|
||||||
|
Q_EMIT folderDataChanged(folderId);
|
||||||
Q_EMIT folderDataChanged();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppFolderHelper::addAppToNewFolder(const QString &appId, const QString &folderName)
|
void AppFolderHelper::addAppToNewFolder(const QString &appId, const QString &folderName)
|
||||||
|
@ -206,7 +206,7 @@ void AppFolderHelper::addAppToNewFolder(const QString &appId, const QString &fol
|
||||||
folder.apps.append(appId);
|
folder.apps.append(appId);
|
||||||
|
|
||||||
insertFolder(folder);
|
insertFolder(folder);
|
||||||
Q_EMIT folderDataChanged();
|
Q_EMIT folderAdded(folder.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppFolderHelper::removeAppFromFolder(const QString &appId, const int &folderId)
|
void AppFolderHelper::removeAppFromFolder(const QString &appId, const int &folderId)
|
||||||
|
@ -231,22 +231,24 @@ void AppFolderHelper::removeAppFromFolder(const QString &appId, const int &folde
|
||||||
deleteFolder(folderId);
|
deleteFolder(folderId);
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_EMIT folderDataChanged();
|
Q_EMIT folderDataChanged(folderId);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AppFolderHelper::deleteFolder(const int& folderId)
|
bool AppFolderHelper::deleteFolder(const int& folderId)
|
||||||
|
{
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&m_mutex);
|
QMutexLocker locker(&m_mutex);
|
||||||
if (!m_folders.contains(folderId)) {
|
if (!m_folders.contains(folderId)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_folders.remove(folderId)) {
|
if (!m_folders.remove(folderId)) {
|
||||||
Q_EMIT folderDataChanged();
|
return false;
|
||||||
return true;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
Q_EMIT folderDeleted(folderId);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppFolderHelper::renameFolder(const int &folderId, const QString &folderName)
|
void AppFolderHelper::renameFolder(const int &folderId, const QString &folderName)
|
||||||
|
@ -259,7 +261,7 @@ void AppFolderHelper::renameFolder(const int &folderId, const QString &folderNam
|
||||||
m_folders[folderId].name = folderName;
|
m_folders[folderId].name = folderName;
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_EMIT folderDataChanged();
|
Q_EMIT folderDataChanged(folderId);
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<Folder> AppFolderHelper::folderData()
|
QList<Folder> AppFolderHelper::folderData()
|
||||||
|
@ -298,6 +300,20 @@ bool AppFolderHelper::searchFolderByAppName(const QString &appId, Folder &folder
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AppFolderHelper::containFolder(int folderId)
|
||||||
|
{
|
||||||
|
QMutexLocker locker(&m_mutex);
|
||||||
|
return m_folders.contains(folderId);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AppFolderHelper::containApp(const QString &appId)
|
||||||
|
{
|
||||||
|
QMutexLocker locker(&m_mutex);
|
||||||
|
return std::any_of(m_folders.constBegin(), m_folders.constEnd(), [appId] (const Folder &folder) {
|
||||||
|
return folder.apps.contains(appId);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void AppFolderHelper::forceSync()
|
void AppFolderHelper::forceSync()
|
||||||
{
|
{
|
||||||
saveData();
|
saveData();
|
||||||
|
@ -384,4 +400,20 @@ void AppFolderHelper::saveData()
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList AppFolderHelper::folderIcon(const Folder &folder)
|
||||||
|
{
|
||||||
|
// TODO: 使用绘图API生成图片
|
||||||
|
QStringList icons;
|
||||||
|
DataEntity app;
|
||||||
|
|
||||||
|
int count = qMin(folder.apps.count(), FOLDER_MAX_ICON_NUM);
|
||||||
|
for (int i = 0; i < count; ++i) {
|
||||||
|
if (AppDataManager::instance()->getApp(folder.apps.at(i), app)) {
|
||||||
|
icons.append(app.icon());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return icons;
|
||||||
|
}
|
||||||
|
|
||||||
} // UkuiMenu
|
} // UkuiMenu
|
||||||
|
|
|
@ -28,6 +28,8 @@
|
||||||
|
|
||||||
namespace UkuiMenu {
|
namespace UkuiMenu {
|
||||||
|
|
||||||
|
#define FOLDER_MAX_ICON_NUM 16
|
||||||
|
|
||||||
class AppFolderHelper;
|
class AppFolderHelper;
|
||||||
|
|
||||||
class Folder
|
class Folder
|
||||||
|
@ -53,6 +55,7 @@ class AppFolderHelper : public QObject
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
static AppFolderHelper *instance();
|
static AppFolderHelper *instance();
|
||||||
|
static QStringList folderIcon(const Folder &folder);
|
||||||
~AppFolderHelper() override;
|
~AppFolderHelper() override;
|
||||||
|
|
||||||
AppFolderHelper(const AppFolderHelper& obj) = delete;
|
AppFolderHelper(const AppFolderHelper& obj) = delete;
|
||||||
|
@ -64,6 +67,9 @@ public:
|
||||||
// xxxx
|
// xxxx
|
||||||
bool searchFolder(const int& folderId, Folder &folder);
|
bool searchFolder(const int& folderId, Folder &folder);
|
||||||
bool searchFolderByAppName(const QString& appId, Folder &folder);
|
bool searchFolderByAppName(const QString& appId, Folder &folder);
|
||||||
|
bool containFolder(int folderId);
|
||||||
|
bool containApp(const QString& appId);
|
||||||
|
|
||||||
QList<Folder> folderData();
|
QList<Folder> folderData();
|
||||||
|
|
||||||
void addAppToFolder(const QString& appId, const int& folderId);
|
void addAppToFolder(const QString& appId, const int& folderId);
|
||||||
|
@ -75,7 +81,9 @@ public:
|
||||||
void forceSync();
|
void forceSync();
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void folderDataChanged();
|
void folderAdded(int folderId);
|
||||||
|
void folderDeleted(int folderId);
|
||||||
|
void folderDataChanged(int folderId);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AppFolderHelper();
|
AppFolderHelper();
|
||||||
|
|
|
@ -0,0 +1,108 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2023, KylinSoft Co., Ltd.
|
||||||
|
*
|
||||||
|
* 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 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* 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 <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "folder-model.h"
|
||||||
|
#include "app-folder-helper.h"
|
||||||
|
#include "app-data-manager.h"
|
||||||
|
|
||||||
|
namespace UkuiMenu {
|
||||||
|
|
||||||
|
FolderModel::FolderModel(QObject *parent) : QAbstractListModel(parent)
|
||||||
|
{
|
||||||
|
connect(AppFolderHelper::instance(), &AppFolderHelper::folderDataChanged, this, &FolderModel::loadFolderData);
|
||||||
|
connect(AppFolderHelper::instance(), &AppFolderHelper::folderDeleted, this, [this] (int id) {
|
||||||
|
if (id == m_folderId) {
|
||||||
|
beginResetModel();
|
||||||
|
m_folderId = -1;
|
||||||
|
m_apps.clear();
|
||||||
|
endResetModel();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void FolderModel::setFolderId(const QString &folderId)
|
||||||
|
{
|
||||||
|
bool ok;
|
||||||
|
int id = folderId.toInt(&ok);
|
||||||
|
if (!ok) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
loadFolderData(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FolderModel::loadFolderData(int id)
|
||||||
|
{
|
||||||
|
Folder folder;
|
||||||
|
if (!AppFolderHelper::instance()->searchFolder(id, folder)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
beginResetModel();
|
||||||
|
m_folderId = id;
|
||||||
|
m_apps = folder.getApps();
|
||||||
|
endResetModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
int FolderModel::rowCount(const QModelIndex &parent) const
|
||||||
|
{
|
||||||
|
return m_apps.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant FolderModel::data(const QModelIndex &index, int role) const
|
||||||
|
{
|
||||||
|
int i = index.row();
|
||||||
|
if (i < 0 || i >= m_apps.size()) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
DataEntity app;
|
||||||
|
if (!AppDataManager::instance()->getApp(m_apps.at(i), app)) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (role) {
|
||||||
|
case DataEntity::Type:
|
||||||
|
return app.type();
|
||||||
|
case DataEntity::Icon:
|
||||||
|
return app.icon();
|
||||||
|
case DataEntity::Name:
|
||||||
|
return app.name();
|
||||||
|
case DataEntity::Comment:
|
||||||
|
return app.comment();
|
||||||
|
case DataEntity::ExtraData:
|
||||||
|
return app.extraData();
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
QHash<int, QByteArray> FolderModel::roleNames() const
|
||||||
|
{
|
||||||
|
QHash<int, QByteArray> names;
|
||||||
|
names.insert(DataEntity::Type, "type");
|
||||||
|
names.insert(DataEntity::Icon, "icon");
|
||||||
|
names.insert(DataEntity::Name, "name");
|
||||||
|
names.insert(DataEntity::Comment, "comment");
|
||||||
|
names.insert(DataEntity::ExtraData, "extraData");
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // UkuiMenu
|
|
@ -0,0 +1,48 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2023, KylinSoft Co., Ltd.
|
||||||
|
*
|
||||||
|
* 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 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* 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 <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef UKUI_MENU_FOLDER_MODEL_H
|
||||||
|
#define UKUI_MENU_FOLDER_MODEL_H
|
||||||
|
|
||||||
|
#include <QAbstractListModel>
|
||||||
|
#include "commons.h"
|
||||||
|
|
||||||
|
namespace UkuiMenu {
|
||||||
|
|
||||||
|
class FolderModel : public QAbstractListModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit FolderModel(QObject *parent = nullptr);
|
||||||
|
Q_INVOKABLE void setFolderId(const QString &folderId);
|
||||||
|
|
||||||
|
int rowCount(const QModelIndex &parent) const override;
|
||||||
|
QVariant data(const QModelIndex &index, int role) const override;
|
||||||
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void loadFolderData(int id);
|
||||||
|
|
||||||
|
private:
|
||||||
|
int m_folderId;
|
||||||
|
QStringList m_apps;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // UkuiMenu
|
||||||
|
|
||||||
|
#endif //UKUI_MENU_FOLDER_MODEL_H
|
|
@ -20,6 +20,7 @@
|
||||||
#include "label-model.h"
|
#include "label-model.h"
|
||||||
#include "app-model.h"
|
#include "app-model.h"
|
||||||
#include "app-group-model.h"
|
#include "app-group-model.h"
|
||||||
|
#include "folder-model.h"
|
||||||
#include <QQmlEngine>
|
#include <QQmlEngine>
|
||||||
|
|
||||||
namespace UkuiMenu {
|
namespace UkuiMenu {
|
||||||
|
@ -34,6 +35,7 @@ void ModelManager::registerMetaTypes()
|
||||||
{
|
{
|
||||||
qRegisterMetaType<AppModel*>("AppModel*");
|
qRegisterMetaType<AppModel*>("AppModel*");
|
||||||
qRegisterMetaType<LabelModel*>("LabelModel*");
|
qRegisterMetaType<LabelModel*>("LabelModel*");
|
||||||
|
qRegisterMetaType<FolderModel*>("FolderModel*");
|
||||||
qRegisterMetaType<AppGroupModel*>("AppGroupModel*");
|
qRegisterMetaType<AppGroupModel*>("AppGroupModel*");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,10 +45,12 @@ ModelManager::ModelManager(QObject *parent) : QObject(parent)
|
||||||
|
|
||||||
appModel = new AppModel(this);
|
appModel = new AppModel(this);
|
||||||
labelModel = new LabelModel(this);
|
labelModel = new LabelModel(this);
|
||||||
|
folderModel = new FolderModel(this);
|
||||||
labelGroupModel = new AppGroupModel(appModel, this);
|
labelGroupModel = new AppGroupModel(appModel, this);
|
||||||
|
|
||||||
QQmlEngine::setObjectOwnership(appModel, QQmlEngine::CppOwnership);
|
QQmlEngine::setObjectOwnership(appModel, QQmlEngine::CppOwnership);
|
||||||
QQmlEngine::setObjectOwnership(labelModel, QQmlEngine::CppOwnership);
|
QQmlEngine::setObjectOwnership(labelModel, QQmlEngine::CppOwnership);
|
||||||
|
QQmlEngine::setObjectOwnership(folderModel, QQmlEngine::CppOwnership);
|
||||||
QQmlEngine::setObjectOwnership(labelGroupModel, QQmlEngine::CppOwnership);
|
QQmlEngine::setObjectOwnership(labelGroupModel, QQmlEngine::CppOwnership);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,4 +69,9 @@ AppGroupModel *ModelManager::getLabelGroupModel()
|
||||||
return labelGroupModel;
|
return labelGroupModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FolderModel *ModelManager::getFolderModel()
|
||||||
|
{
|
||||||
|
return folderModel;
|
||||||
|
}
|
||||||
|
|
||||||
} // UkuiMenu
|
} // UkuiMenu
|
||||||
|
|
|
@ -26,6 +26,7 @@ namespace UkuiMenu {
|
||||||
class AppModel;
|
class AppModel;
|
||||||
class LabelModel;
|
class LabelModel;
|
||||||
class AppGroupModel;
|
class AppGroupModel;
|
||||||
|
class FolderModel;
|
||||||
|
|
||||||
class ModelManager : public QObject
|
class ModelManager : public QObject
|
||||||
{
|
{
|
||||||
|
@ -37,6 +38,7 @@ public:
|
||||||
|
|
||||||
Q_INVOKABLE AppModel *getAppModel();
|
Q_INVOKABLE AppModel *getAppModel();
|
||||||
Q_INVOKABLE LabelModel *getLabelModel();
|
Q_INVOKABLE LabelModel *getLabelModel();
|
||||||
|
Q_INVOKABLE FolderModel *getFolderModel();
|
||||||
Q_INVOKABLE AppGroupModel *getLabelGroupModel();
|
Q_INVOKABLE AppGroupModel *getLabelGroupModel();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -45,6 +47,7 @@ private:
|
||||||
private:
|
private:
|
||||||
AppModel *appModel{nullptr};
|
AppModel *appModel{nullptr};
|
||||||
LabelModel *labelModel{nullptr};
|
LabelModel *labelModel{nullptr};
|
||||||
|
FolderModel *folderModel{nullptr};
|
||||||
AppGroupModel *labelGroupModel{nullptr};
|
AppGroupModel *labelGroupModel{nullptr};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue