fix(extension):完善收藏插件细节(解散应用组到指定位置),兼容原有配置文件

This commit is contained in:
qiqi49 2024-01-24 11:31:57 +08:00 committed by hewenfei
parent 970dc89f26
commit 379b07fc7a
16 changed files with 178 additions and 139 deletions

View File

@ -110,13 +110,14 @@ set(SOURCE_FILES
src/extension/widget-extension-model.cpp src/extension/widget-extension-model.h src/extension/widget-extension-model.cpp src/extension/widget-extension-model.h
src/extension/widget-model.cpp src/extension/widget-model.h src/extension/widget-model.cpp src/extension/widget-model.h
src/extension/menu/app-menu-plugin.cpp src/extension/menu/app-menu-plugin.h src/extension/menu/app-menu-plugin.cpp src/extension/menu/app-menu-plugin.h
src/extension/favorite/favorite-extension-plugin.cpp src/extension/favorite/favorite-extension-plugin.h src/extension/favorite/folder-model.cpp src/extension/favorite/folder-model.h
src/extension/favorite/favorite-context-menu.cpp src/extension/favorite/favorite-context-menu.h
src/extension/favorite/favorite-widget.cpp src/extension/favorite/favorite-widget.h
src/extension/favorite/app-favorite-model.cpp src/extension/favorite/app-favorite-model.h
src/extension/favorite/favorites-config.cpp src/extension/favorite/favorites-config.h
src/extension/favorite/favorites-model.cpp src/extension/favorite/favorites-model.h src/extension/favorite/favorites-model.cpp src/extension/favorite/favorites-model.h
src/extension/favorite/favorite-widget.cpp src/extension/favorite/favorite-widget.h
src/extension/favorite/favorites-config.cpp src/extension/favorite/favorites-config.h
src/extension/favorite/app-favorite-model.cpp src/extension/favorite/app-favorite-model.h
src/extension/favorite/favorite-context-menu.cpp src/extension/favorite/favorite-context-menu.h
src/extension/favorite/favorite-folder-helper.cpp src/extension/favorite/favorite-folder-helper.h src/extension/favorite/favorite-folder-helper.cpp src/extension/favorite/favorite-folder-helper.h
src/extension/favorite/favorite-extension-plugin.cpp src/extension/favorite/favorite-extension-plugin.h
src/libappdata/basic-app-model.cpp src/libappdata/basic-app-model.h src/libappdata/basic-app-model.cpp src/libappdata/basic-app-model.h
src/libappdata/app-database-interface.cpp src/libappdata/app-database-interface.h src/libappdata/app-database-interface.cpp src/libappdata/app-database-interface.h
src/libappdata/app-category-model.cpp src/libappdata/app-category-model.h src/libappdata/app-category-model.cpp src/libappdata/app-category-model.h

View File

@ -28,7 +28,7 @@ import org.ukui.quick.items 1.0 as UkuiItems
Loader { Loader {
id: root id: root
active: false active: false
property var folderModel: modelManager.getFolderModel() property var folderModel
property string folderName: "" property string folderName: ""
property int folderX: 0 property int folderX: 0
property int folderY: 0 property int folderY: 0
@ -42,7 +42,7 @@ Loader {
signal turnPageFinished() signal turnPageFinished()
function initFolder(id, name, x, y) { function initFolder(id, name, x, y) {
folderModel.setFolderId(id); extensionData.folderModel.setFolderId(id);
folderName = name; folderName = name;
folderX = x; folderX = x;
folderY = y; folderY = y;

View File

@ -53,6 +53,7 @@ UkuiMenuExtension {
anchors.fill: parent anchors.fill: parent
isFullScreen: false isFullScreen: false
folderModel: extensionData.folderModel
Component.onCompleted: favoriteView.openFolderSignal.connect(initFolder) Component.onCompleted: favoriteView.openFolderSignal.connect(initFolder)
Component.onDestruction: favoriteView.openFolderSignal.disconnect(initFolder) Component.onDestruction: favoriteView.openFolderSignal.disconnect(initFolder)
} }

View File

@ -120,6 +120,7 @@ void AppFavoritesModel::updateFavoritesApps(const DataEntity &app, const QModelI
if (app.favorite() > 0 && !FavoriteFolderHelper::instance()->containApp(app.id())) { if (app.favorite() > 0 && !FavoriteFolderHelper::instance()->containApp(app.id())) {
QPersistentModelIndex index(sourceIndex); QPersistentModelIndex index(sourceIndex);
addFavoriteApp(index); addFavoriteApp(index);
FavoritesConfig::instance().insertValue(APP_ID_SCHEME + index.data(DataEntity::Id).toString());
} else if (app.favorite() == 0) { } else if (app.favorite() == 0) {
if (FavoriteFolderHelper::instance()->containApp(app.id())) { if (FavoriteFolderHelper::instance()->containApp(app.id())) {
@ -185,30 +186,23 @@ QVariant AppFavoritesModel::fileData(const QModelIndex &index, int role) const
return {}; return {};
} }
QStringList AppFavoritesModel::favoritesApps() const void AppFavoritesModel::clearFavorites()
{ {
QMap<int, QString> apps; for(const auto &appIndex : m_favoritesApps) {
for (const auto &index : m_favoritesApps) { removeAppFromFavorites(appIndex.data(DataEntity::Id).toString());
QString id = m_sourceModel->data(index, DataEntity::Id).toString();
int favorite = m_sourceModel->data(index, DataEntity::Favorite).toInt();
apps.insert(favorite, id);
} }
return apps.values(); for (const auto &id : FavoriteFolderHelper::instance()->appsInFolders()) {
removeAppFromFavorites(id);
} }
void AppFavoritesModel::changeAppState(const QString &id, const int &index) beginRemoveRows(QModelIndex(), 0, rowCount());
{ m_favoritesApps.clear();
if (id.isEmpty()) { m_folders.clear();
return; m_favoritesFiles.clear();
} endRemoveRows();
m_sourceModel->databaseInterface()->fixAppToFavorite(id, index); FavoritesConfig::instance().clear();
// 同步配置文件,更新应用顺序
if (index > 0) {
FavoritesConfig::instance().insertValue(APP_ID_SCHEME + id, index);
}
} }
bool AppFavoritesModel::getApp(const QString &appid, DataEntity &app) bool AppFavoritesModel::getApp(const QString &appid, DataEntity &app)
@ -243,8 +237,6 @@ void AppFavoritesModel::addFavoriteApp(const QPersistentModelIndex &modelIndex)
beginInsertRows(QModelIndex(), m_favoritesApps.count(), m_favoritesApps.count()); beginInsertRows(QModelIndex(), m_favoritesApps.count(), m_favoritesApps.count());
m_favoritesApps.append(modelIndex); m_favoritesApps.append(modelIndex);
endInsertRows(); endInsertRows();
FavoritesConfig::instance().insertValue(APP_ID_SCHEME + modelIndex.data(DataEntity::Id).toString());
} }
void AppFavoritesModel::removeFavoriteApp(const QPersistentModelIndex &modelIndex) void AppFavoritesModel::removeFavoriteApp(const QPersistentModelIndex &modelIndex)
@ -284,9 +276,11 @@ void AppFavoritesModel::onFolderDeleted(const int &folderId, const QStringList &
m_folders.removeOne(folderId); m_folders.removeOne(folderId);
endRemoveRows(); endRemoveRows();
for (auto app : apps) { int index = FavoritesConfig::instance().getOrderById(FOLDER_ID_SCHEME +QString::number(folderId));
QPersistentModelIndex modelIndex(m_sourceModel->index(m_sourceModel->indexOfApp(app))); for (int i = 0; i < apps.count(); i++) {
QPersistentModelIndex modelIndex(m_sourceModel->index(m_sourceModel->indexOfApp(apps.at(i))));
addFavoriteApp(modelIndex); addFavoriteApp(modelIndex);
FavoritesConfig::instance().insertValue(APP_ID_SCHEME + modelIndex.data(DataEntity::Id).toString(), index + i);
} }
FavoritesConfig::instance().removeValueById(FOLDER_ID_SCHEME + QString::number(folderId)); FavoritesConfig::instance().removeValueById(FOLDER_ID_SCHEME + QString::number(folderId));
@ -310,6 +304,7 @@ void AppFavoritesModel::onFolderChanged(const int &folderId, const QString &appI
} else { } else {
QPersistentModelIndex modelIndex(m_sourceModel->index(m_sourceModel->indexOfApp(appId))); QPersistentModelIndex modelIndex(m_sourceModel->index(m_sourceModel->indexOfApp(appId)));
addFavoriteApp(modelIndex); addFavoriteApp(modelIndex);
FavoritesConfig::instance().insertValue(APP_ID_SCHEME + modelIndex.data(DataEntity::Id).toString());
} }
roles.append(DataEntity::Icon); roles.append(DataEntity::Icon);
@ -344,9 +339,34 @@ void AppFavoritesModel::changeFileState(const QString &url, const bool &favorite
} }
if (favorite) { if (favorite) {
m_favoritesFiles.append(url);
FavoritesConfig::instance().insertValue(fileId); FavoritesConfig::instance().insertValue(fileId);
} else { } else {
m_favoritesFiles.removeAll(url);
FavoritesConfig::instance().removeValueById(fileId); FavoritesConfig::instance().removeValueById(fileId);
} }
} }
void AppFavoritesModel::addAppToFavorites(const QString &id, const int &index)
{
if (id.isEmpty()) {
return;
}
m_sourceModel->databaseInterface()->fixAppToFavorite(id, 1);
// 同步配置文件,更新应用顺序
if (index > 0) {
FavoritesConfig::instance().insertValue(APP_ID_SCHEME + id, index);
}
}
void AppFavoritesModel::removeAppFromFavorites(const QString &id)
{
if (id.isEmpty()) {
return;
}
m_sourceModel->databaseInterface()->fixAppToFavorite(id, 0);
}
} // UkuiMenu } // UkuiMenu

View File

@ -38,8 +38,9 @@ public:
int rowCount(const QModelIndex &parent = QModelIndex()) const override; int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role) const override; QVariant data(const QModelIndex &index, int role) const override;
QStringList favoritesApps() const; void clearFavorites();
void changeAppState(const QString &id, const int &index); void addAppToFavorites(const QString &id, const int &index);
void removeAppFromFavorites(const QString &id);
void changeFileState(const QString &url, const bool &favorite); void changeFileState(const QString &url, const bool &favorite);
bool getApp(const QString &appid, DataEntity &app); bool getApp(const QString &appid, DataEntity &app);

View File

@ -15,13 +15,6 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
* *
*/ */
#include "favorite-folder-helper.h"
#include "app-data-manager.h"
#include "event-track.h"
#include "favorites-config.h"
#include "basic-app-model.h"
#include <QJsonDocument> #include <QJsonDocument>
#include <QJsonArray> #include <QJsonArray>
#include <QJsonObject> #include <QJsonObject>
@ -30,13 +23,21 @@
#include <QDir> #include <QDir>
#include <QMenu> #include <QMenu>
#include "favorite-folder-helper.h"
#include "event-track.h"
#include "favorites-config.h"
#include "libappdata/basic-app-model.h"
#define FOLDER_FILE_PATH ".config/ukui-menu/" #define FOLDER_FILE_PATH ".config/ukui-menu/"
#define FOLDER_FILE_NAME "folder0.json" #define FOLDER_FILE_NAME "folder.json"
namespace UkuiMenu { namespace UkuiMenu {
QString FavoriteFolderHelper::s_folderConfigFile = QDir::homePath() + "/" + FOLDER_FILE_PATH + FOLDER_FILE_NAME; QString FavoriteFolderHelper::s_folderConfigFile = QDir::homePath() + "/" + FOLDER_FILE_PATH + FOLDER_FILE_NAME;
/**
* changelog 1.0.0
*/
static const QString FOLDER_CONFIG_VERSION = QStringLiteral("1.0.0");
FavoriteFolderHelper *FavoriteFolderHelper::instance() FavoriteFolderHelper *FavoriteFolderHelper::instance()
{ {
static FavoriteFolderHelper FavoriteFolderHelper; static FavoriteFolderHelper FavoriteFolderHelper;
@ -263,12 +264,15 @@ void FavoriteFolderHelper::readData()
} }
// 读取json数据 // 读取json数据
QByteArray byteArray = file.readAll(); QTextStream stream(&file);
stream.setCodec("UTF-8");
QString str = stream.readAll();
file.close(); file.close();
QJsonDocument jsonDocument(QJsonDocument::fromJson(byteArray)); QJsonParseError jsonError;
if (jsonDocument.isNull() || jsonDocument.isEmpty() || !jsonDocument.isArray()) { QJsonDocument jsonDocument(QJsonDocument::fromJson(str.toUtf8(),&jsonError));
qWarning() << "FavoriteFolderHelper: Incorrect configuration files are ignored."; if (jsonDocument.isNull() || jsonDocument.isEmpty()) {
qWarning() << "FavoriteFolderHelper: Incorrect configuration files are ignored." << jsonError.error;
return; return;
} }
@ -277,8 +281,10 @@ void FavoriteFolderHelper::readData()
m_folders.clear(); m_folders.clear();
} }
// 遍历json数据节点 QJsonObject fileObject = jsonDocument.object();
QJsonArray jsonArray = jsonDocument.array(); if (fileObject.value("version").toString() == FOLDER_CONFIG_VERSION) {
if (fileObject.contains("folders")) {
QJsonArray jsonArray = fileObject.value(QLatin1String("folders")).toArray();
for (const auto &value : jsonArray) { for (const auto &value : jsonArray) {
QJsonObject object = value.toObject(); QJsonObject object = value.toObject();
if (object.contains("name") && object.contains("id") && object.contains("apps")) { if (object.contains("name") && object.contains("id") && object.contains("apps")) {
@ -298,6 +304,12 @@ void FavoriteFolderHelper::readData()
} }
} }
} else {
saveData();
return;
}
}
void FavoriteFolderHelper::saveData() void FavoriteFolderHelper::saveData()
{ {
QFile file(s_folderConfigFile); QFile file(s_folderConfigFile);
@ -306,6 +318,7 @@ void FavoriteFolderHelper::saveData()
} }
QJsonDocument jsonDocument; QJsonDocument jsonDocument;
QJsonObject fileObject;
QJsonArray folderArray; QJsonArray folderArray;
{ {
@ -326,7 +339,9 @@ void FavoriteFolderHelper::saveData()
} }
} }
jsonDocument.setArray(folderArray); fileObject.insert("version", FOLDER_CONFIG_VERSION);
fileObject.insert("folders", folderArray);
jsonDocument.setObject(fileObject);
if (file.write(jsonDocument.toJson()) == -1) { if (file.write(jsonDocument.toJson()) == -1) {
qWarning() << "Error saving configuration file."; qWarning() << "Error saving configuration file.";
@ -350,4 +365,14 @@ QStringList FavoriteFolderHelper::folderIcon(const FavoritesFolder &folder)
return icons; return icons;
} }
QStringList FavoriteFolderHelper::appsInFolders()
{
QStringList apps;
for (const auto &folder : m_folders) {
apps.append(folder.apps);
}
return apps;
}
} // UkuiMenu } // UkuiMenu

View File

@ -61,6 +61,7 @@ public:
bool getFolderFromId(const int& folderId, FavoritesFolder& folder); bool getFolderFromId(const int& folderId, FavoritesFolder& folder);
bool containApp(const QString& appId); bool containApp(const QString& appId);
bool deleteFolder(const int& folderId);
QList<FavoritesFolder> folderData(); QList<FavoritesFolder> folderData();
@ -68,10 +69,10 @@ public:
void addAppToNewFolder(const QString& appId, const QString& folderName); void addAppToNewFolder(const QString& appId, const QString& folderName);
void addAppsToNewFolder(const QString& idFrom, const QString& idTo, const QString& folderName); void addAppsToNewFolder(const QString& idFrom, const QString& idTo, const QString& folderName);
void removeAppFromFolder(const QString& appId); void removeAppFromFolder(const QString& appId);
bool deleteFolder(const int& folderId);
void renameFolder(const int& folderId, const QString& folderName); void renameFolder(const int& folderId, const QString& folderName);
void forceSync(); void forceSync();
QStringList appsInFolders();
Q_SIGNALS: Q_SIGNALS:
void folderAdded(int folderId, const int& order); void folderAdded(int folderId, const int& order);

View File

@ -36,7 +36,9 @@ FavoriteWidget::FavoriteWidget(QObject *parent) : WidgetExtension(parent)
FavoritesModel::instance().setSourceModel(&AppFavoritesModel::instance()); FavoritesModel::instance().setSourceModel(&AppFavoritesModel::instance());
FavoritesModel::instance().sort(0); FavoritesModel::instance().sort(0);
m_folderModel = new FolderModel;
m_data.insert("favoriteAppsModel", QVariant::fromValue(&FavoritesModel::instance())); m_data.insert("favoriteAppsModel", QVariant::fromValue(&FavoritesModel::instance()));
m_data.insert("folderModel", QVariant::fromValue(m_folderModel));
} }
int FavoriteWidget::index() const int FavoriteWidget::index() const

View File

@ -20,6 +20,7 @@
#define UKUI_MENU_FAVORITE_WIDGET_H #define UKUI_MENU_FAVORITE_WIDGET_H
#include "../widget-extension.h" #include "../widget-extension.h"
#include "folder-model.h"
namespace UkuiMenu { namespace UkuiMenu {
@ -37,6 +38,7 @@ public:
private: private:
MetadataMap m_metadata; MetadataMap m_metadata;
QVariantMap m_data; QVariantMap m_data;
FolderModel *m_folderModel;
}; };
} // UkuiMenu } // UkuiMenu

View File

@ -38,64 +38,62 @@ FavoritesConfig &FavoritesConfig::instance()
FavoritesConfig::FavoritesConfig(QObject *parent) FavoritesConfig::FavoritesConfig(QObject *parent)
{ {
initConfig();
} }
QJsonObject FavoritesConfig::getValue(const int &index) const QString FavoritesConfig::getValue(const int &index) const
{ {
if (index < 0 || index > arrayFromConfigFile().count()) { if (index < 0 || index > m_favoritesList.count()) {
return {}; return {};
} }
return arrayFromConfigFile().at(index).toObject(); return m_favoritesList.at(index);
} }
void FavoritesConfig::insertValue(const QString &id, const int &index) void FavoritesConfig::insertValue(const QString &id, const int &index)
{ {
QJsonArray array = arrayFromConfigFile(); if (m_favoritesList.indexOf(id) > -1) {
if (indexOfObject(id, array) > -1) {
return; return;
} }
QJsonObject object; m_favoritesList.insert(index, id);
object.insert("id", id); sync();
array.insert(index, object);
setArrayToConfigFile(array);
} }
void FavoritesConfig::removeValueById(const QString &id) void FavoritesConfig::removeValueById(const QString &id)
{ {
QJsonArray array = arrayFromConfigFile(); int index = m_favoritesList.indexOf(id);
int index = indexOfObject(id, array);
if (index > -1 && index < array.size()) { if (index > -1 && index < m_favoritesList.count()) {
array.removeAt(index); m_favoritesList.removeAt(index);
} }
setArrayToConfigFile(array); sync();
} }
void FavoritesConfig::initConfig(const QStringList &apps) int FavoritesConfig::getOrderById(const QString &id)
{ {
QJsonArray favoritesArray; return m_favoritesList.indexOf(id);
for (const auto &appId : apps) {
QJsonObject object;
object.insert("id", appId);
favoritesArray.append(object);
} }
setArrayToConfigFile(favoritesArray); void FavoritesConfig::changeOrder(const int &indexFrom, const int &indexTo)
{
m_favoritesList.move(indexFrom, indexTo);
sync();
} }
void FavoritesConfig::setArrayToConfigFile(const QJsonArray &array) int FavoritesConfig::configSize() const
{
return m_favoritesList.size();
}
void FavoritesConfig::sync()
{ {
QDir dir; QDir dir;
QString folderConfigDir(QDir::homePath() + "/" + FOLDER_FILE_PATH); QString folderConfigDir(QDir::homePath() + "/" + FOLDER_FILE_PATH);
if (!dir.exists(folderConfigDir)) { if (!dir.exists(folderConfigDir)) {
if (!dir.mkdir(folderConfigDir)) { if (!dir.mkdir(folderConfigDir)) {
qWarning() << "Unable to create profile favorites."; qWarning() << "FavoritesConfig::Unable to create configuration file.";
return; return;
} }
} }
@ -104,10 +102,10 @@ void FavoritesConfig::setArrayToConfigFile(const QJsonArray &array)
file.open(QFile::WriteOnly); file.open(QFile::WriteOnly);
QJsonDocument jsonDocument; QJsonDocument jsonDocument;
jsonDocument.setArray(array); jsonDocument.setArray(QJsonArray::fromStringList(m_favoritesList));
if (file.write(jsonDocument.toJson()) == -1) { if (file.write(jsonDocument.toJson()) == -1) {
qWarning() << "Error saving configuration file."; qWarning() << "FavoritesConfig::Error saving configuration file.";
} }
file.flush(); file.flush();
@ -116,57 +114,35 @@ void FavoritesConfig::setArrayToConfigFile(const QJsonArray &array)
Q_EMIT configChanged(); Q_EMIT configChanged();
} }
QJsonArray FavoritesConfig::arrayFromConfigFile() const void FavoritesConfig::clear()
{
m_favoritesList.clear();
sync();
}
void FavoritesConfig::initConfig()
{ {
QFile file(s_favoritesConfigFile); QFile file(s_favoritesConfigFile);
if (!file.open(QFile::ReadOnly)) { if (!file.open(QFile::ReadOnly)) {
return {}; qWarning() << "FavoritesConfig: Incorrect configuration files open failed.";
return;
} }
QJsonDocument jsonDocument(QJsonDocument::fromJson(file.readAll())); QJsonDocument jsonDocument(QJsonDocument::fromJson(file.readAll()));
file.close(); file.close();
if (jsonDocument.isNull() || jsonDocument.isEmpty() || !jsonDocument.isArray()) { if (jsonDocument.isNull() || jsonDocument.isEmpty() || !jsonDocument.isArray()) {
qWarning() << "AppFolderHelper: Incorrect configuration files are ignored."; qWarning() << "FavoritesConfig: Incorrect configuration files are ignored.";
return {}; return;
}
return jsonDocument.array();
}
int FavoritesConfig::indexOfObject(const QString &id, const QJsonArray &array)
{
if (id.isEmpty()) {
qWarning() << "id is unavailable!";
return -1;
} }
m_favoritesList.clear();
QJsonArray array = jsonDocument.array();
for (int i = 0; i < array.size(); i++) { for (int i = 0; i < array.size(); i++) {
if (array.at(i).toObject().contains("id")) { if (array.at(i).toObject().contains("id")) {
if (array.at(i).toObject().value("id").toString() == id) { m_favoritesList.append(array.at(i).toString());
return i;
} }
} }
} }
return -1;
}
int FavoritesConfig::getOrderById(const QString &id)
{
return indexOfObject(id, arrayFromConfigFile());
}
void FavoritesConfig::changeOrder(const int &indexFrom, const int &indexTo)
{
QVariantList list = arrayFromConfigFile().toVariantList();
list.move(indexFrom, indexTo);
setArrayToConfigFile(QJsonArray::fromVariantList(list));
}
int FavoritesConfig::configSize() const
{
return arrayFromConfigFile().size();
}
} // UkuiMenu } // UkuiMenu

View File

@ -34,33 +34,32 @@ class FavoritesConfig : public QObject
Q_OBJECT Q_OBJECT
public: public:
static FavoritesConfig &instance(); static FavoritesConfig &instance();
void changeOrder(const int &indexFrom, const int &indexTo);
QJsonObject getValue(const int &index) const;
/* /*
* id * id
* folder://、应用app://)、文件file://) * folder://、应用app://)、文件file://)
*/ */
void insertValue(const QString &id, const int &index = 0); void insertValue(const QString &id, const int &index = 0);
void removeValueById(const QString &id); void removeValueById(const QString &id);
void clear();
int configSize() const;
/* /*
* id的位置 * id的位置
*/ */
int getOrderById(const QString &id); int getOrderById(const QString &id);
void changeOrder(const int &indexFrom, const int &indexTo); QString getValue(const int &index) const;
int configSize() const;
void initConfig(const QStringList &apps);
Q_SIGNALS: Q_SIGNALS:
void configChanged(); void configChanged();
private: private:
explicit FavoritesConfig(QObject *parent = nullptr); explicit FavoritesConfig(QObject *parent = nullptr);
void setArrayToConfigFile(const QJsonArray &array); void initConfig();
QJsonArray arrayFromConfigFile() const; void sync();
int indexOfObject(const QString &id, const QJsonArray &array);
private: private:
static QString s_favoritesConfigFile; static QString s_favoritesConfigFile;
QStringList m_favoritesList;
}; };
} // UkuiMenu } // UkuiMenu

View File

@ -86,12 +86,12 @@ void FavoritesModel::addAppToFavorites(const QString &id, const int &index)
} else { } else {
appOrder = index; appOrder = index;
} }
AppFavoritesModel::instance().changeAppState(id, appOrder); AppFavoritesModel::instance().addAppToFavorites(id, appOrder);
} }
void FavoritesModel::removeAppFromFavorites(const QString &id) void FavoritesModel::removeAppFromFavorites(const QString &id)
{ {
AppFavoritesModel::instance().changeAppState(id, 0); AppFavoritesModel::instance().removeAppFromFavorites(id);
} }
void FavoritesModel::exchangedAppsOrder(const int &indexFrom, const int &indexTo) void FavoritesModel::exchangedAppsOrder(const int &indexFrom, const int &indexTo)
@ -128,4 +128,9 @@ void FavoritesModel::addFileToFavorites(const QString &url)
{ {
AppFavoritesModel::instance().changeFileState(url, true); AppFavoritesModel::instance().changeFileState(url, true);
} }
void FavoritesModel::clearFavorites()
{
AppFavoritesModel::instance().clearFavorites();
}
} // UkuiMenu } // UkuiMenu

View File

@ -66,6 +66,10 @@ public:
* @param url url路径 * @param url url路径
*/ */
Q_INVOKABLE void addFileToFavorites(const QString &url); Q_INVOKABLE void addFileToFavorites(const QString &url);
/**
*
*/
Q_INVOKABLE void clearFavorites();
protected: protected:
bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override; bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override;

View File

@ -21,6 +21,7 @@
#include "app-data-manager.h" #include "app-data-manager.h"
#include "favorite/favorite-folder-helper.h" #include "favorite/favorite-folder-helper.h"
#include "context-menu-manager.h" #include "context-menu-manager.h"
#include "libappdata/basic-app-model.h"
namespace UkuiMenu { namespace UkuiMenu {
@ -81,7 +82,8 @@ QVariant FolderModel::data(const QModelIndex &index, int role) const
} }
DataEntity app; DataEntity app;
if (!AppDataManager::instance()->getApp(m_apps.at(i), app)) {
if (!BasicAppModel::instance()->getAppById(m_apps.at(i), app)) {
return {}; return {};
} }

View File

@ -20,7 +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 "favorite/folder-model.h"
#include <QQmlEngine> #include <QQmlEngine>
namespace UkuiMenu { namespace UkuiMenu {