!81 修复部分内存泄露;

Merge pull request !81 from 纪笑旭/upstream
This commit is contained in:
lixueman 2023-02-28 09:38:49 +00:00 committed by Gitee
commit 3027234313
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 44 additions and 27 deletions

View File

@ -35,6 +35,17 @@ UkuiMenuInterface::UkuiMenuInterface()
QString syspath = QDir::homePath() + "/.config/ukui/menusysapplist.ini"; QString syspath = QDir::homePath() + "/.config/ukui/menusysapplist.ini";
syssetting = new QSettings(syspath, QSettings::IniFormat); 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<QStringList> UkuiMenuInterface::appInfoVector = QVector<QStringList>(); QVector<QStringList> UkuiMenuInterface::appInfoVector = QVector<QStringList>();
@ -130,6 +141,7 @@ void UkuiMenuInterface::recursiveSearchFile(const QString &_filePath)
keyfile = g_key_file_new(); keyfile = g_key_file_new();
if (!g_key_file_load_from_file(keyfile, filepath, flags, error)) { if (!g_key_file_load_from_file(keyfile, filepath, flags, error)) {
g_key_file_free(keyfile);
return; return;
} }
@ -137,7 +149,7 @@ void UkuiMenuInterface::recursiveSearchFile(const QString &_filePath)
if (ret_1 != nullptr) { if (ret_1 != nullptr) {
QString str = QString::fromLocal8Bit(ret_1); QString str = QString::fromLocal8Bit(ret_1);
g_free(ret_1);
if (str.contains("true")) { if (str.contains("true")) {
g_key_file_free(keyfile); g_key_file_free(keyfile);
i++; i++;
@ -149,7 +161,7 @@ void UkuiMenuInterface::recursiveSearchFile(const QString &_filePath)
if (ret_2 != nullptr) { if (ret_2 != nullptr) {
QString str = QString::fromLocal8Bit(ret_2); QString str = QString::fromLocal8Bit(ret_2);
g_free(ret_2);
if (str.contains("UKUI")) { if (str.contains("UKUI")) {
g_key_file_free(keyfile); g_key_file_free(keyfile);
i++; i++;
@ -162,7 +174,7 @@ void UkuiMenuInterface::recursiveSearchFile(const QString &_filePath)
if (ret != nullptr) { if (ret != nullptr) {
QString str = QString::fromLocal8Bit(ret); QString str = QString::fromLocal8Bit(ret);
g_free(ret);
if (str.contains("LXQt") || str.contains("KDE")) { if (str.contains("LXQt") || str.contains("KDE")) {
g_key_file_free(keyfile); g_key_file_free(keyfile);
i++; i++;
@ -540,18 +552,7 @@ QVector<QStringList> UkuiMenuInterface::createAppInfoVector()
{ {
desktopfpVector.clear(); desktopfpVector.clear();
QVector<QStringList> appInfoVector; QVector<QStringList> appInfoVector;
QVector<QStringList> 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(); QStringList desktopfpList = getDesktopFilePath();
QSqlDatabase db = QSqlDatabase::database("MainThreadDataBase"); QSqlDatabase db = QSqlDatabase::database("MainThreadDataBase");
QSqlQuery sql(db); QSqlQuery sql(db);
@ -575,8 +576,8 @@ QVector<QStringList> UkuiMenuInterface::createAppInfoVector()
sql.exec(QString("select name_zh from appCategory where app_name=\"%1\" ").arg(desktopfpExecName)); sql.exec(QString("select name_zh from appCategory where app_name=\"%1\" ").arg(desktopfpExecName));
if (sql.next()) { if (sql.next()) {
for (int j = 0; j < vector.size(); j++) { for (int j = 0; j < m_categoriesVector.size(); j++) {
if (vector.at(j).contains(sql.value(0).toString())) { if (m_categoriesVector.at(j).contains(sql.value(0).toString())) {
appInfoList.append(QString::number(j)); appInfoList.append(QString::number(j));
} }
} }
@ -588,8 +589,8 @@ QVector<QStringList> UkuiMenuInterface::createAppInfoVector()
bool is_owned = false; bool is_owned = false;
for (int j = 0; j < vector.size(); j++) { for (int j = 0; j < m_categoriesVector.size(); j++) {
if (matchingAppCategories(desktopfpList.at(i), vector.at(j))) { //有对应分类 if (matchingAppCategories(desktopfpList.at(i), m_categoriesVector.at(j))) { //有对应分类
is_owned = true; is_owned = true;
appInfoList.append(QString::number(j)); 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); char *name = g_key_file_get_locale_string(keyfile, "Desktop Entry", "Name", nullptr, nullptr);
QString namestr = QString::fromLocal8Bit(name); QString namestr = QString::fromLocal8Bit(name);
g_key_file_free(keyfile); g_key_file_free(keyfile);
g_free(name);
return namestr; return namestr;
} }
//获取英应用英文名 //获取英应用英文名
@ -643,6 +645,8 @@ QString UkuiMenuInterface::getAppEnglishName(QString desktopfp)
g_key_file_load_from_file(keyfile, filepath, flags, error); g_key_file_load_from_file(keyfile, filepath, flags, error);
char *name = g_key_file_get_string(keyfile, "Desktop Entry", "Name", nullptr); char *name = g_key_file_get_string(keyfile, "Desktop Entry", "Name", nullptr);
QString namestr = QString::fromLocal8Bit(name); QString namestr = QString::fromLocal8Bit(name);
g_key_file_free(keyfile);
g_free(name);
return namestr; return namestr;
} }
//获取应用分类 //获取应用分类
@ -656,7 +660,9 @@ QString UkuiMenuInterface::getAppCategories(QString desktopfp)
g_key_file_load_from_file(keyfile, filepath, flags, error); g_key_file_load_from_file(keyfile, filepath, flags, error);
char *category = g_key_file_get_locale_string(keyfile, "Desktop Entry", "Categories", nullptr, nullptr); char *category = g_key_file_get_locale_string(keyfile, "Desktop Entry", "Categories", nullptr, nullptr);
g_key_file_free(keyfile); g_key_file_free(keyfile);
return QString::fromLocal8Bit(category); QString categorystr = QString::fromLocal8Bit(category);
g_free(category);
return categorystr;
} }
//获取应用图标 //获取应用图标
QString UkuiMenuInterface::getAppIcon(QString desktopfp) QString UkuiMenuInterface::getAppIcon(QString desktopfp)
@ -669,7 +675,9 @@ QString UkuiMenuInterface::getAppIcon(QString desktopfp)
g_key_file_load_from_file(keyfile, filepath, flags, error); g_key_file_load_from_file(keyfile, filepath, flags, error);
char *icon = g_key_file_get_locale_string(keyfile, "Desktop Entry", "Icon", nullptr, nullptr); char *icon = g_key_file_get_locale_string(keyfile, "Desktop Entry", "Icon", nullptr, nullptr);
g_key_file_free(keyfile); g_key_file_free(keyfile);
return QString::fromLocal8Bit(icon); QString iconstr = QString::fromLocal8Bit(icon);
g_free(icon);
return iconstr;
} }
//获取应用命令 //获取应用命令
QString UkuiMenuInterface::getAppExec(QString desktopfp) QString UkuiMenuInterface::getAppExec(QString desktopfp)
@ -682,7 +690,9 @@ QString UkuiMenuInterface::getAppExec(QString desktopfp)
g_key_file_load_from_file(keyfile, filepath, flags, error); g_key_file_load_from_file(keyfile, filepath, flags, error);
char *exec = g_key_file_get_locale_string(keyfile, "Desktop Entry", "Exec", nullptr, nullptr); char *exec = g_key_file_get_locale_string(keyfile, "Desktop Entry", "Exec", nullptr, nullptr);
g_key_file_free(keyfile); g_key_file_free(keyfile);
return QString::fromLocal8Bit(exec); QString execstr = QString::fromLocal8Bit(exec);
g_free(exec);
return execstr;
} }
//获取应用注释 //获取应用注释
QString UkuiMenuInterface::getAppComment(QString desktopfp) QString UkuiMenuInterface::getAppComment(QString desktopfp)
@ -1562,6 +1572,7 @@ void UkuiMenuInterface::getAndroidApp()
// } // }
// else // else
// { // {
g_free(ret_1);
m_filePathList.append(filePathStr); m_filePathList.append(filePathStr);
androidDesktopfnList.append(fileInfo.fileName()); androidDesktopfnList.append(fileInfo.fileName());
// } // }

View File

@ -37,6 +37,8 @@ private:
GKeyFileFlags flags = G_KEY_FILE_NONE; GKeyFileFlags flags = G_KEY_FILE_NONE;
GKeyFile *keyfile = nullptr; GKeyFile *keyfile = nullptr;
QVector<QStringList> m_categoriesVector;
protected: protected:
void recursiveSearchFile(const QString &_filePath);//遍历/usr/share/applications/文件夹 void recursiveSearchFile(const QString &_filePath);//遍历/usr/share/applications/文件夹
QStringList getSpecifiedCategoryAppList(QString categorystr);//获取指定类型应用列表 QStringList getSpecifiedCategoryAppList(QString categorystr);//获取指定类型应用列表

View File

@ -105,7 +105,7 @@ bool GetModelData::cmpApp(QStringList &arg_1, QStringList &arg_2)
QVector<QStringList> GetModelData::getRecentData() QVector<QStringList> GetModelData::getRecentData()
{ {
QVector<QStringList> recentDataVector = QVector<QStringList>(); QVector<QStringList> recentDataVector = QVector<QStringList>();
enumerator = new Peony::FileEnumerator(this); enumerator = new Peony::FileEnumerator();
enumerator->setEnumerateDirectory("recent:///"); enumerator->setEnumerateDirectory("recent:///");
enumerator->enumerateSync(); enumerator->enumerateSync();
@ -126,6 +126,10 @@ QVector<QStringList> GetModelData::getRecentData()
} }
qSort(recentDataVector.begin(), recentDataVector.end(), cmpApp); qSort(recentDataVector.begin(), recentDataVector.end(), cmpApp);
if (enumerator) {
delete enumerator;
enumerator = nullptr;
}
return recentDataVector; return recentDataVector;
} }

View File

@ -25,6 +25,7 @@
KListView::KListView(QWidget *parent): KListView::KListView(QWidget *parent):
QListView(parent) QListView(parent)
{ {
m_listmodel = new QStandardItemModel(this);
} }
KListView::~KListView() KListView::~KListView()
@ -42,7 +43,6 @@ KListView::~KListView()
void KListView::addData(QStringList data) void KListView::addData(QStringList data)
{ {
m_listmodel = new QStandardItemModel(this);
this->setModel(m_listmodel); this->setModel(m_listmodel);
Q_FOREACH(QString desktopfp, data) { Q_FOREACH(QString desktopfp, data) {

View File

@ -23,8 +23,8 @@ SplitBarFrame::SplitBarFrame(QWidget *parent, QString category, int width, int h
m_width(width), m_width(width),
m_height(height), m_height(height),
m_module(module), m_module(module),
m_textLabel(new QLabel), m_textLabel(new QLabel(this)),
m_line(new QFrame) m_line(new QFrame(this))
{ {
initAppBtn(); initAppBtn();
} }
@ -40,7 +40,7 @@ void SplitBarFrame::initAppBtn()
//按钮透明 //按钮透明
this->setFocusPolicy(Qt::NoFocus); this->setFocusPolicy(Qt::NoFocus);
this->setAttribute(Qt::WA_TranslucentBackground); this->setAttribute(Qt::WA_TranslucentBackground);
QHBoxLayout *layout = new QHBoxLayout; QHBoxLayout *layout = new QHBoxLayout(this);
layout->setContentsMargins(15, 0, 0, 0); layout->setContentsMargins(15, 0, 0, 0);
layout->setSpacing(6); layout->setSpacing(6);
m_textLabel->setAutoFillBackground(false); m_textLabel->setAutoFillBackground(false);