mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 09:23:03 +00:00
59 lines
1.5 KiB
C++
59 lines
1.5 KiB
C++
![]() |
// SPDX-FileCopyrightText: 2018 - 2023 UnionTech Software Technology Co., Ltd.
|
||
|
//
|
||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||
|
|
||
|
#include "appinfo.h"
|
||
|
#include "common.h"
|
||
|
|
||
|
#include <QDebug>
|
||
|
#include <QString>
|
||
|
#include <QCryptographicHash>
|
||
|
|
||
|
AppInfo::AppInfo(DesktopInfo &info)
|
||
|
: m_isValid(true)
|
||
|
{
|
||
|
init(info);
|
||
|
}
|
||
|
|
||
|
AppInfo::AppInfo(const QString &_fileName)
|
||
|
: m_isValid(true)
|
||
|
{
|
||
|
DesktopInfo info(_fileName);
|
||
|
init(info);
|
||
|
}
|
||
|
|
||
|
void AppInfo::init(DesktopInfo &info)
|
||
|
{
|
||
|
if (!info.isValidDesktop()) {
|
||
|
m_isValid = false;
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
QString xDeepinVendor = info.getDesktopFile()->value(MainSection + "/X-Deepin-Vendor").toString();
|
||
|
if (xDeepinVendor == "deepin") {
|
||
|
m_name = info.getGenericName();
|
||
|
if (m_name.isEmpty()) {
|
||
|
m_name = info.getName();
|
||
|
}
|
||
|
} else {
|
||
|
m_name = info.getName();
|
||
|
}
|
||
|
|
||
|
m_innerId = genInnerIdWithDesktopInfo(info);
|
||
|
m_fileName = info.getDesktopFilePath();
|
||
|
m_id = info.getId();
|
||
|
m_icon = info.getIcon();
|
||
|
for (const auto & action : info.getActions()) {
|
||
|
m_actions.push_back(action);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
QString AppInfo::genInnerIdWithDesktopInfo(DesktopInfo &info)
|
||
|
{
|
||
|
QString cmdline = info.getCommandLine();
|
||
|
QByteArray encryText = QCryptographicHash::hash(QString(cmdline).toLatin1(), QCryptographicHash::Md5);
|
||
|
QString innerId = desktopHashPrefix + encryText.toHex();
|
||
|
qInfo() << "app: " << info.getId() << " generate innerId: " << innerId;
|
||
|
return innerId;
|
||
|
}
|