From f34b82e5b6c15471baee16d5dcad3e22c3862d24 Mon Sep 17 00:00:00 2001 From: jixiaoxu Date: Tue, 21 Feb 2023 16:33:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DGLIB=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=86=85=E5=AD=98=E6=B3=84=E6=BC=8F=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Interface/ukuimenuinterface.cpp | 55 +++++++++++-------- src/BackProcess/Interface/ukuimenuinterface.h | 2 + 2 files changed, 35 insertions(+), 22 deletions(-) diff --git a/src/BackProcess/Interface/ukuimenuinterface.cpp b/src/BackProcess/Interface/ukuimenuinterface.cpp index d7438fb..2518f64 100644 --- a/src/BackProcess/Interface/ukuimenuinterface.cpp +++ b/src/BackProcess/Interface/ukuimenuinterface.cpp @@ -35,6 +35,17 @@ UkuiMenuInterface::UkuiMenuInterface() QString syspath = QDir::homePath() + "/.config/ukui/menusysapplist.ini"; syssetting = new QSettings(syspath, QSettings::IniFormat); } + m_categoriesVector.append(QStringList() << "office" << "Office" << "Calculator" << "Spreadsheet" << "Presentation" << "WordProcessor" << "TextEditor"); //0办公 + m_categoriesVector.append(QStringList() << "develop" << "Development"); //1开发 + m_categoriesVector.append(QStringList() << "graphic" << "Graphics"); //2图像 + m_categoriesVector.append(QStringList() << "video" << "Audio" << "Video"); //3影音 + m_categoriesVector.append(QStringList() << "network" << "Network"); //4网络 + m_categoriesVector.append(QStringList() << "game" << "Game"); //5游戏 + m_categoriesVector.append(QStringList() << "education" << "Education"); //6教育 + m_categoriesVector.append(QStringList() << "social" << "Messaging"); //7社交 + m_categoriesVector.append(QStringList() << "system" << "System" << "Settings" << "Security"); //8系统 + m_categoriesVector.append(QStringList() << "safe"); //9安全 + m_categoriesVector.append(QStringList() << "others"); //10其他 } QVector UkuiMenuInterface::appInfoVector = QVector(); @@ -130,6 +141,7 @@ void UkuiMenuInterface::recursiveSearchFile(const QString &_filePath) keyfile = g_key_file_new(); if (!g_key_file_load_from_file(keyfile, filepath, flags, error)) { + g_key_file_free(keyfile); return; } @@ -137,7 +149,7 @@ void UkuiMenuInterface::recursiveSearchFile(const QString &_filePath) if (ret_1 != nullptr) { QString str = QString::fromLocal8Bit(ret_1); - + g_free(ret_1); if (str.contains("true")) { g_key_file_free(keyfile); i++; @@ -149,7 +161,7 @@ void UkuiMenuInterface::recursiveSearchFile(const QString &_filePath) if (ret_2 != nullptr) { QString str = QString::fromLocal8Bit(ret_2); - + g_free(ret_2); if (str.contains("UKUI")) { g_key_file_free(keyfile); i++; @@ -162,7 +174,7 @@ void UkuiMenuInterface::recursiveSearchFile(const QString &_filePath) if (ret != nullptr) { QString str = QString::fromLocal8Bit(ret); - + g_free(ret); if (str.contains("LXQt") || str.contains("KDE")) { g_key_file_free(keyfile); i++; @@ -540,18 +552,7 @@ QVector UkuiMenuInterface::createAppInfoVector() { desktopfpVector.clear(); QVector appInfoVector; - QVector vector; - vector.append(QStringList() << "office" << "Office" << "Calculator" << "Spreadsheet" << "Presentation" << "WordProcessor" << "TextEditor"); //0办公 - vector.append(QStringList() << "develop" << "Development"); //1开发 - vector.append(QStringList() << "graphic" << "Graphics"); //2图像 - vector.append(QStringList() << "video" << "Audio" << "Video"); //3影音 - vector.append(QStringList() << "network" << "Network"); //4网络 - vector.append(QStringList() << "game" << "Game"); //5游戏 - vector.append(QStringList() << "education" << "Education"); //6教育 - vector.append(QStringList() << "social" << "Messaging"); //7社交 - vector.append(QStringList() << "system" << "System" << "Settings" << "Security"); //8系统 - vector.append(QStringList() << "safe"); //9安全 - vector.append(QStringList() << "others"); //10其他 + QStringList desktopfpList = getDesktopFilePath(); QSqlDatabase db = QSqlDatabase::database("MainThreadDataBase"); QSqlQuery sql(db); @@ -575,8 +576,8 @@ QVector UkuiMenuInterface::createAppInfoVector() sql.exec(QString("select name_zh from appCategory where app_name=\"%1\" ").arg(desktopfpExecName)); if (sql.next()) { - for (int j = 0; j < vector.size(); j++) { - if (vector.at(j).contains(sql.value(0).toString())) { + for (int j = 0; j < m_categoriesVector.size(); j++) { + if (m_categoriesVector.at(j).contains(sql.value(0).toString())) { appInfoList.append(QString::number(j)); } } @@ -588,8 +589,8 @@ QVector UkuiMenuInterface::createAppInfoVector() bool is_owned = false; - for (int j = 0; j < vector.size(); j++) { - if (matchingAppCategories(desktopfpList.at(i), vector.at(j))) { //有对应分类 + for (int j = 0; j < m_categoriesVector.size(); j++) { + if (matchingAppCategories(desktopfpList.at(i), m_categoriesVector.at(j))) { //有对应分类 is_owned = true; appInfoList.append(QString::number(j)); } @@ -630,6 +631,7 @@ QString UkuiMenuInterface::getAppName(QString desktopfp) char *name = g_key_file_get_locale_string(keyfile, "Desktop Entry", "Name", nullptr, nullptr); QString namestr = QString::fromLocal8Bit(name); g_key_file_free(keyfile); + g_free(name); return namestr; } //获取英应用英文名 @@ -643,6 +645,8 @@ QString UkuiMenuInterface::getAppEnglishName(QString desktopfp) g_key_file_load_from_file(keyfile, filepath, flags, error); char *name = g_key_file_get_string(keyfile, "Desktop Entry", "Name", nullptr); QString namestr = QString::fromLocal8Bit(name); + g_key_file_free(keyfile); + g_free(name); return namestr; } //获取应用分类 @@ -656,7 +660,9 @@ QString UkuiMenuInterface::getAppCategories(QString desktopfp) g_key_file_load_from_file(keyfile, filepath, flags, error); char *category = g_key_file_get_locale_string(keyfile, "Desktop Entry", "Categories", nullptr, nullptr); g_key_file_free(keyfile); - return QString::fromLocal8Bit(category); + QString categorystr = QString::fromLocal8Bit(category); + g_free(category); + return categorystr; } //获取应用图标 QString UkuiMenuInterface::getAppIcon(QString desktopfp) @@ -669,7 +675,9 @@ QString UkuiMenuInterface::getAppIcon(QString desktopfp) g_key_file_load_from_file(keyfile, filepath, flags, error); char *icon = g_key_file_get_locale_string(keyfile, "Desktop Entry", "Icon", nullptr, nullptr); g_key_file_free(keyfile); - return QString::fromLocal8Bit(icon); + QString iconstr = QString::fromLocal8Bit(icon); + g_free(icon); + return iconstr; } //获取应用命令 QString UkuiMenuInterface::getAppExec(QString desktopfp) @@ -682,7 +690,9 @@ QString UkuiMenuInterface::getAppExec(QString desktopfp) g_key_file_load_from_file(keyfile, filepath, flags, error); char *exec = g_key_file_get_locale_string(keyfile, "Desktop Entry", "Exec", nullptr, nullptr); g_key_file_free(keyfile); - return QString::fromLocal8Bit(exec); + QString execstr = QString::fromLocal8Bit(exec); + g_free(exec); + return execstr; } //获取应用注释 QString UkuiMenuInterface::getAppComment(QString desktopfp) @@ -1562,6 +1572,7 @@ void UkuiMenuInterface::getAndroidApp() // } // else // { + g_free(ret_1); m_filePathList.append(filePathStr); androidDesktopfnList.append(fileInfo.fileName()); // } diff --git a/src/BackProcess/Interface/ukuimenuinterface.h b/src/BackProcess/Interface/ukuimenuinterface.h index 38ed9c2..cc020b0 100644 --- a/src/BackProcess/Interface/ukuimenuinterface.h +++ b/src/BackProcess/Interface/ukuimenuinterface.h @@ -37,6 +37,8 @@ private: GKeyFileFlags flags = G_KEY_FILE_NONE; GKeyFile *keyfile = nullptr; + QVector m_categoriesVector; + protected: void recursiveSearchFile(const QString &_filePath);//遍历/usr/share/applications/文件夹 QStringList getSpecifiedCategoryAppList(QString categorystr);//获取指定类型应用列表