Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions desktopintegration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
// SPDX-License-Identifier: GPL-3.0-or-later

#include "desktopintegration.h"
#include "appmgr.h"

Check warning on line 6 in desktopintegration.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "appmgr.h" not found.
#include "appsmodel.h"

Check warning on line 7 in desktopintegration.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "appsmodel.h" not found.

#include <DConfig>

Check warning on line 9 in desktopintegration.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DConfig> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <DDesktopEntry>

Check warning on line 10 in desktopintegration.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DDesktopEntry> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <DStandardPaths>
#include <DDesktopServices>
#include <QDir>
Expand Down Expand Up @@ -42,7 +43,7 @@
void DesktopIntegration::openSystemSettings()
{
qCInfo(logDesktopIntegration) << "Opening system settings";
launchByDesktopId("org.deepin.dde.control-center.desktop");
launchByDesktopId("org.deepin.dde.control-center");
}

void DesktopIntegration::launchByDesktopId(const QString &desktopId)
Expand All @@ -52,7 +53,7 @@
connect(activation, &ds::XdgActivation::tokenReady, &instance(), [desktopId, activation](const QString &token) {
if (!AppMgr::launchApp(desktopId, token)) {
qCDebug(logDesktopIntegration) << "AppMgr launch failed, trying AppInfo launch";
AppInfo::launchByDesktopId(desktopId);
AppInfo::launchByDesktopId(AppsModel::normalizedDesktopId(desktopId));
}
activation->deleteLater();
});
Expand Down Expand Up @@ -89,11 +90,11 @@

bool DesktopIntegration::appIsCompulsoryForDesktop(const QString &desktopId)
{
if (m_compulsoryAppIdList.contains(desktopId)) return true;
if (m_compulsoryAppIdList.contains(AppsModel::normalizedDesktopId(desktopId))) return true;

const QString currentDE(DesktopIntegration::currentDE());

const AppStream::ComponentBox components = m_appStreamPool.componentsByLaunchable(AppStream::Launchable::KindDesktopId, desktopId);
const AppStream::ComponentBox components = m_appStreamPool.componentsByLaunchable(AppStream::Launchable::KindDesktopId, AppsModel::normalizedDesktopId(desktopId));
for (const AppStream::Component & component : components) {
return component.compulsoryForDesktops().contains(currentDE);
}
Expand All @@ -103,7 +104,7 @@

bool DesktopIntegration::appIsDummyPackage(const QString &desktopId)
{
const AppStream::ComponentBox components = m_appStreamPool.componentsByLaunchable(AppStream::Launchable::KindDesktopId, desktopId);
const AppStream::ComponentBox components = m_appStreamPool.componentsByLaunchable(AppStream::Launchable::KindDesktopId, AppsModel::normalizedDesktopId(desktopId));
for (const AppStream::Component & component : components) {
return component.customValue("DDE::is_dummy_package") == "true";
}
Expand Down Expand Up @@ -135,22 +136,22 @@
bool DesktopIntegration::isDockedApp(const QString &desktopId) const
{
// This is something we shouldn't do but anyway...
const QString & fullPath = AppInfo::fullPathByDesktopId(desktopId);
const QString & fullPath = AppInfo::fullPathByDesktopId(AppsModel::normalizedDesktopId(desktopId));
// Seems QML's list type doesn't have a contains() method...
return m_dockIntegration->isDocked(fullPath);
}

void DesktopIntegration::sendToDock(const QString &desktopId)
{
qCInfo(logDesktopIntegration) << "Sending app to dock:" << desktopId;
const QString & fullPath = AppInfo::fullPathByDesktopId(desktopId);
const QString & fullPath = AppInfo::fullPathByDesktopId(AppsModel::normalizedDesktopId(desktopId));
return m_dockIntegration->sendToDock(fullPath);
}

void DesktopIntegration::removeFromDock(const QString &desktopId)
{
qCInfo(logDesktopIntegration) << "Removing app from dock:" << desktopId;
const QString & fullPath = AppInfo::fullPathByDesktopId(desktopId);
const QString & fullPath = AppInfo::fullPathByDesktopId(AppsModel::normalizedDesktopId(desktopId));
return m_dockIntegration->removeFromDock(fullPath);
}

Expand All @@ -165,7 +166,7 @@

bool DesktopIntegration::isOnDesktop(const QString &desktopId) const
{
QString desktopItemPath = desktopItemFilePath(desktopId);
QString desktopItemPath = desktopItemFilePath(AppsModel::normalizedDesktopId(desktopId));
if (desktopItemPath.isEmpty()) return false;
return QFileInfo::exists(desktopItemPath);
}
Expand Down Expand Up @@ -196,7 +197,7 @@
bool DesktopIntegration::shouldSkipConfirmUninstallDialog(const QString &desktopId) const
{
bool result = false;
const QString & fullPath = AppInfo::fullPathByDesktopId(desktopId);
const QString & fullPath = AppInfo::fullPathByDesktopId(AppsModel::normalizedDesktopId(desktopId));
if (fullPath.isEmpty()) return result;

DDesktopEntry entry(fullPath);
Expand All @@ -210,7 +211,7 @@
void DesktopIntegration::uninstallApp(const QString &desktopId)
{
qCInfo(logDesktopIntegration) << "Uninstalling app:" << desktopId;
const QString & fullPath = AppInfo::fullPathByDesktopId(desktopId);
const QString & fullPath = AppInfo::fullPathByDesktopId(AppsModel::normalizedDesktopId(desktopId));
m_appWizIntegration->legacyRequestUninstall(fullPath);
}

Expand Down
2 changes: 0 additions & 2 deletions src/ddeintegration/appmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ const QStringList &disabledScaleEnvironments()

QString applicationObjectPath(QString desktopId)
{
if (desktopId.endsWith(QLatin1String(".desktop")))
desktopId.chop(8);
if (desktopId.isEmpty() || desktopId.startsWith(QLatin1String("internal/")))
return {};
return ApplicationObjectPathPrefix + DUtil::escapeToObjectPath(desktopId);
Expand Down
24 changes: 13 additions & 11 deletions src/models/appsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ AppsModel::AppsModel(QObject *parent)

for (int sourceRow = 0; sourceRow < m_sourceModel->rowCount(); ++sourceRow) {
const QModelIndex sourceIndex = m_sourceModel->index(sourceRow, 0);
if (normalizedDesktopId(sourceData(sourceIndex, DesktopIdRoleName).toString()) != desktopId)
if (AppsModel::normalizedDesktopId(sourceData(sourceIndex, DesktopIdRoleName).toString()) != desktopId)
continue;
if (!acceptsSourceIndex(sourceIndex))
return;
Expand Down Expand Up @@ -117,9 +117,11 @@ QModelIndex AppsModel::indexFromDesktopId(const QString &desktopId) const
{
if (rowCount() == 0)
return {};
const auto matches = match(index(0, 0), AppsModel::DesktopIdRole,
normalizedDesktopId(desktopId), 1, Qt::MatchExactly);
return matches.value(0);
for (int i = 0; i < rowCount(); ++i) {
if (AppsModel::normalizedDesktopId(desktopId) == AppsModel::normalizedDesktopId(data(index(i, 0), DesktopIdRole).toString()))
return index(i, 0);
}
return {};
}

bool AppsModel::ready() const
Expand Down Expand Up @@ -169,7 +171,7 @@ QVariant AppsModel::data(const QModelIndex &index, int role) const
case AppsModel::NameRole:
return sourceData(sourceIndex, NameRoleName);
case AppsModel::DesktopIdRole:
return normalizedDesktopId(sourceData(sourceIndex, DesktopIdRoleName).toString());
return sourceData(sourceIndex, DesktopIdRoleName).toString();
case AppsModel::CategoriesRole:
return sourceData(sourceIndex, CategoriesRoleName);
case AppsModel::DDECategoryRole:
Expand Down Expand Up @@ -238,7 +240,7 @@ bool AppsModel::acceptsSourceIndex(const QModelIndex &sourceIndex) const
if (!sourceIndex.isValid())
return false;

const QString desktopId = normalizedDesktopId(sourceData(sourceIndex, DesktopIdRoleName).toString());
const QString desktopId = AppsModel::normalizedDesktopId(sourceData(sourceIndex, DesktopIdRoleName).toString());
if (desktopId.isEmpty() || m_excludedAppIdList.contains(desktopId))
return false;

Expand Down Expand Up @@ -289,7 +291,7 @@ QList<int> AppsModel::mappedRoles(const QList<int> &sourceRoles) const
return uniqueRoles;
}

QString AppsModel::normalizedDesktopId(const QString &sourceId) const
QString AppsModel::normalizedDesktopId(const QString &sourceId)
{
if (sourceId.isEmpty() || sourceId.endsWith(QLatin1String(".desktop")) || sourceId.startsWith(QLatin1String("internal/")))
return sourceId;
Expand Down Expand Up @@ -333,7 +335,7 @@ void AppsModel::beginRemoveSourceRows(const QModelIndex &parent, int first, int
for (int sourceRow = first; sourceRow <= last; ++sourceRow) {
const QModelIndex sourceIndex = m_sourceModel->index(sourceRow, 0);
AppMgr::instance()->cancelPendingAppItem(
normalizedDesktopId(sourceData(sourceIndex, DesktopIdRoleName).toString()));
AppsModel::normalizedDesktopId(sourceData(sourceIndex, DesktopIdRoleName).toString()));
}

const int adapterFirst = adapterRowForSourceRow(first);
Expand Down Expand Up @@ -376,7 +378,7 @@ void AppsModel::updateSourceRows(const QModelIndex &topLeft, const QModelIndex &
const int currentRow = m_rows.indexOf(persistentSourceIndex);
const bool accepted = acceptsSourceIndex(sourceIndex);

const QString desktopId = normalizedDesktopId(sourceData(sourceIndex, DesktopIdRoleName).toString());
const QString desktopId = AppsModel::normalizedDesktopId(sourceData(sourceIndex, DesktopIdRoleName).toString());
const bool pending = AppMgr::instance()->isPendingAppItem(desktopId);
if ((mayChangeMembership || pending) && accepted && currentRow < 0) {
if (shouldDelaySourceIndex(sourceIndex))
Expand Down Expand Up @@ -405,7 +407,7 @@ void AppsModel::rebuildRows()
if (m_sourceModel) {
for (int row = 0; row < m_sourceModel->rowCount(); ++row) {
const QModelIndex sourceIndex = m_sourceModel->index(row, 0);
const QString desktopId = normalizedDesktopId(sourceData(sourceIndex, DesktopIdRoleName).toString());
const QString desktopId = AppsModel::normalizedDesktopId(sourceData(sourceIndex, DesktopIdRoleName).toString());
if (acceptsSourceIndex(sourceIndex) && !AppMgr::instance()->isPendingAppItem(desktopId))
m_rows.append(sourceIndex);
}
Expand All @@ -415,7 +417,7 @@ void AppsModel::rebuildRows()

bool AppsModel::shouldDelaySourceIndex(const QModelIndex &sourceIndex) const
{
const QString desktopId = normalizedDesktopId(sourceData(sourceIndex, DesktopIdRoleName).toString());
const QString desktopId = AppsModel::normalizedDesktopId(sourceData(sourceIndex, DesktopIdRoleName).toString());
const QString iconName = sourceData(sourceIndex, IconNameRoleName).toString();
return AppMgr::instance()->waitForIcon(desktopId, iconName);
}
Expand Down
3 changes: 2 additions & 1 deletion src/models/appsmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class AppsModel : public QAbstractListModel
bool ready() const;
QVariantMap ddeCategories() const;

static QString normalizedDesktopId(const QString &sourceId);

int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role) const override;
QHash<int, QByteArray> roleNames() const override;
Expand All @@ -81,7 +83,6 @@ public Q_SLOTS:
int sourceRole(const QByteArray &name) const;
QVariant sourceData(const QModelIndex &sourceIndex, const QByteArray &roleName) const;
QList<int> mappedRoles(const QList<int> &sourceRoles) const;
QString normalizedDesktopId(const QString &sourceId) const;
int adapterRowForSourceRow(int sourceRow) const;
void insertSourceRows(const QModelIndex &parent, int first, int last);
void beginRemoveSourceRows(const QModelIndex &parent, int first, int last);
Expand Down
18 changes: 9 additions & 9 deletions src/models/favoritedproxymodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ FavoritedProxyModel::FavoritedProxyModel(QObject *parent)

bool FavoritedProxyModel::exists(const QString &desktopId)
{
qCDebug(logModels) << desktopId << m_favoritedAppIds.contains(desktopId);
return m_favoritedAppIds.contains(desktopId);
qCDebug(logModels) << desktopId << m_favoritedAppIds.contains(AppsModel::normalizedDesktopId(desktopId));
return m_favoritedAppIds.contains(AppsModel::normalizedDesktopId(desktopId));
}

void FavoritedProxyModel::addFavorite(const QString &desktopId)
{
if (m_favoritedAppIds.contains(desktopId)) return;
if (m_favoritedAppIds.contains(AppsModel::normalizedDesktopId(desktopId))) return;

m_favoritedAppIds.append(desktopId);
m_favoritedAppIds.append(AppsModel::normalizedDesktopId(desktopId));
qCInfo(logModels) << "Favorite added:" << desktopId;

save();
Expand All @@ -43,7 +43,7 @@ void FavoritedProxyModel::addFavorite(const QString &desktopId)

void FavoritedProxyModel::removeFavorite(const QString &desktopId)
{
m_favoritedAppIds.removeOne(desktopId);
m_favoritedAppIds.removeOne(AppsModel::normalizedDesktopId(desktopId));
qCInfo(logModels) << "Favorite removed:" << desktopId;

save();
Expand All @@ -52,7 +52,7 @@ void FavoritedProxyModel::removeFavorite(const QString &desktopId)

void FavoritedProxyModel::pinToTop(const QString &desktopId)
{
int idx = m_favoritedAppIds.indexOf(desktopId);
int idx = m_favoritedAppIds.indexOf(AppsModel::normalizedDesktopId(desktopId));

if (idx != -1) {
m_favoritedAppIds.move(idx, 0);
Expand All @@ -67,13 +67,13 @@ bool FavoritedProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sou
{
QModelIndex modelIndex = this->sourceModel()->index(sourceRow, 0, sourceParent);

return m_favoritedAppIds.contains(modelIndex.data(AppsModel::DesktopIdRole).toString());
return m_favoritedAppIds.contains(AppsModel::normalizedDesktopId(modelIndex.data(AppsModel::DesktopIdRole).toString()));
}

bool FavoritedProxyModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const
{
const int leftIndex = m_favoritedAppIds.indexOf(source_left.data(AppsModel::DesktopIdRole).toString());
const int rightIndex = m_favoritedAppIds.indexOf(source_right.data(AppsModel::DesktopIdRole).toString());
const int leftIndex = m_favoritedAppIds.indexOf(AppsModel::normalizedDesktopId(source_left.data(AppsModel::DesktopIdRole).toString()));
const int rightIndex = m_favoritedAppIds.indexOf(AppsModel::normalizedDesktopId(source_right.data(AppsModel::DesktopIdRole).toString()));

return leftIndex < rightIndex;
}
Expand Down
7 changes: 4 additions & 3 deletions src/models/frequentlyusedproxymodel.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2024-2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "frequentlyusedproxymodel.h"
#include "appsmodel.h"

#include <QDebug>

Check warning on line 8 in src/models/frequentlyusedproxymodel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDebug> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <DConfig>

Check warning on line 9 in src/models/frequentlyusedproxymodel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DConfig> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QLoggingCategory>

Q_DECLARE_LOGGING_CATEGORY(logModels)
Expand Down Expand Up @@ -125,8 +126,8 @@

bool FrequentlyUsedProxyModel::lessThenByFrequentlyUsed(const QModelIndex &sourceLeft, const QModelIndex &sourceRight) const
{
const auto leftId = sourceLeft.data(m_desktopIdRole).toString();
const auto rightId = sourceRight.data(m_desktopIdRole).toString();
const auto leftId = AppsModel::normalizedDesktopId(sourceLeft.data(m_desktopIdRole).toString());
const auto rightId = AppsModel::normalizedDesktopId(sourceRight.data(m_desktopIdRole).toString());
const auto leftInFrequentlyUsed = m_frequentlyUsedAppIdList.indexOf(leftId);
const auto rightInFrequentlyUsed = m_frequentlyUsedAppIdList.indexOf(rightId);
return leftInFrequentlyUsed < rightInFrequentlyUsed;
Expand Down
Loading
Loading