Skip to content
Open
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
113 changes: 96 additions & 17 deletions panels/dock/taskmanager/itemmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

#include "itemmodel.h"
#include "abstractitem.h"
#include "appitem.h"
#include "globals.h"
#include "taskmanager.h"
#include "taskmanagersettings.h"

#include <algorithm>

Check warning on line 12 in panels/dock/taskmanager/itemmodel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

#include <QVariant>
#include <QPointer>
Expand All @@ -32,17 +35,19 @@

QHash<int, QByteArray> ItemModel::roleNames() const
{
return {{ItemModel::ItemIdRole, "itemId"},
{ItemModel::NameRole, "name"},
{ItemModel::IconNameRole, "iconName"},
{ItemModel::ActiveRole, "active"},
{ItemModel::AttentionRole, "attention"},
{ItemModel::MenusRole, "menus"},
{ItemModel::DockedRole, "docked"},
{ItemModel::WindowsRole, "windows"},
{ItemModel::DesktopFilesIconsRole, "desktopfileIcons"},
// clang-format off
return {{ItemModel::ItemIdRole, MODEL_ITEMID},
{TaskManager::NameRole, MODEL_NAME},
{TaskManager::IconNameRole, MODEL_ICONNAME},
{TaskManager::ActiveRole, MODEL_ACTIVE},
{TaskManager::AttentionRole, MODEL_ATTENTION},
{TaskManager::MenusRole, MODEL_MENUS},
{TaskManager::DockedRole, MODEL_DOCKED},
{TaskManager::WindowsRole, MODEL_WINDOWS},
{TaskManager::WinIconRole, MODEL_WINICON},
{ItemModel::DockedDirRole, "dockedDir"}
};
// clang-format on
}

int ItemModel::rowCount(const QModelIndex &parent) const
Expand All @@ -57,18 +62,20 @@
}

auto item = m_items[index.row()];
// clang-format off
switch (role) {
case ItemModel::ItemIdRole: return item->id();
case ItemModel::NameRole: return item->name();
case ItemModel::IconNameRole: return item->icon();
case ItemModel::ActiveRole: return item->isActive();
case ItemModel::AttentionRole: return item->isAttention();
case ItemModel::MenusRole: return item->menus();
case ItemModel::DockedRole: return item->isDocked();
case ItemModel::WindowsRole: return item->data().toStringList();
case ItemModel::DesktopFilesIconsRole: return item->data().toStringList();
case TaskManager::NameRole: return item->name();
case TaskManager::IconNameRole: return item->icon();
case TaskManager::ActiveRole: return item->isActive();
case TaskManager::AttentionRole: return item->isAttention();
case TaskManager::MenusRole: return item->menus();
case TaskManager::DockedRole: return item->isDocked();
case TaskManager::WindowsRole: return item->data().toStringList();
case TaskManager::WinIconRole: return item->data().toStringList();
case ItemModel::DockedDirRole: return item->data().toString();
}
// clang-format on
return QVariant();
}

Expand All @@ -89,6 +96,78 @@
return result;
}

void ItemModel::requestActivate(const QModelIndex &index) const
{
QString itemId = data(index).toString();

auto item = ItemModel::instance()->getItemById(itemId);
if (!item) {
return;
}

item->handleClick(QString());
}

void ItemModel::requestNewInstance(const QModelIndex &index, const QString &action) const
{
QString itemId = data(index).toString();

auto item = ItemModel::instance()->getItemById(itemId);
if (!item) {
return;
}

item->handleClick(DOCK_ACTIN_LAUNCH);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (typo): Typo in constant name: DOCK_ACTIN_LAUNCH.

Please correct the constant name to DOCK_ACTION_LAUNCH to avoid potential runtime errors.

Suggested change
item->handleClick(DOCK_ACTIN_LAUNCH);
item->handleClick(DOCK_ACTION_LAUNCH);

}

void ItemModel::requestClose(const QModelIndex &index, bool force) const
{
QString itemId = data(index).toString();

auto item = ItemModel::instance()->getItemById(itemId);
if (!item) {
return;
}

item->handleClick(force ? DOCK_ACTION_FORCEQUIT : DOCK_ACTION_CLOSEALL);
}

void ItemModel::requestOpenUrls(const QModelIndex &index, const QList<QUrl> &urls) const
{
QString itemId = data(index).toString();

auto item = ItemModel::instance()->getItemById(itemId);
if (!item) {
return;
}

// convert urls to string list
QStringList urlsStr;
for (auto url : std::as_const(urls)) {
urlsStr.append(url.toString());
}

item->handleFileDrop(urlsStr);
}

void ItemModel::requestWindowsView(const QModelIndexList &indexes) const
{
// nothing here, dummy entry.
}

void ItemModel::requestUpdateWindowIconGeometry(const QModelIndex &index, const QRect &geometry, QObject *delegate) const
{
QString itemId = data(index).toString();

QPointer<AppItem> item = static_cast<AppItem *>(ItemModel::instance()->getItemById(itemId).get());
if (item.isNull())
return;

for (auto window : item->getAppendWindows()) {
window->setWindowIconGeometry(qobject_cast<QWindow *>(delegate), geometry);
}
}

QPointer<AbstractItem> ItemModel::getItemById(const QString& id) const
{
auto it = std::find_if(m_items.begin(), m_items.end(),[id](QPointer<AbstractItem> item){
Expand Down
17 changes: 8 additions & 9 deletions panels/dock/taskmanager/itemmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,8 @@
Q_OBJECT
public:
enum Roles {
ItemIdRole = Qt::UserRole + 1,
NameRole,
IconNameRole,
ActiveRole,
AttentionRole,
MenusRole,
DockedRole,
ItemIdRole = Qt::UserRole + 64,
// data type
WindowsRole,
DesktopFilesIconsRole,
DockedDirRole,
};
Q_ENUM(Roles)
Expand All @@ -38,7 +30,14 @@
void addItem(QPointer<AbstractItem> item);
QJsonArray dumpDockedItems() const;

void requestActivate(const QModelIndex &index) const;
void requestNewInstance(const QModelIndex &index, const QString &action) const;
void requestClose(const QModelIndex &index, bool force = false) const;
void requestOpenUrls(const QModelIndex &index, const QList<QUrl> &urls) const;
void requestWindowsView(const QModelIndexList &indexes) const;
void requestUpdateWindowIconGeometry(const QModelIndex &index, const QRect &geometry, QObject *delegate = nullptr) const;

private Q_SLOTS:

Check warning on line 40 in panels/dock/taskmanager/itemmodel.h

View workflow job for this annotation

GitHub Actions / cppcheck

There is an unknown macro here somewhere. Configuration is required. If Q_SLOTS is a macro then please configure it.
void onItemDestroyed();
void onItemChanged();

Expand Down
14 changes: 7 additions & 7 deletions panels/dock/taskmanager/taskmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,27 +216,27 @@ HoverPreviewProxyModel *TaskManager::hoverPreviewModel() const

void TaskManager::requestActivate(const QModelIndex &index) const
{
m_itemModel->requestActivate(index);
dataModel()->requestActivate(index);
}

void TaskManager::requestOpenUrls(const QModelIndex &index, const QList<QUrl> &urls) const
{
m_itemModel->requestOpenUrls(index, urls);
dataModel()->requestOpenUrls(index, urls);
}

void TaskManager::requestNewInstance(const QModelIndex &index, const QString &action) const
{
m_itemModel->requestNewInstance(index, action);
dataModel()->requestNewInstance(index, action);
}

void TaskManager::requestClose(const QModelIndex &index, bool force) const
{
m_itemModel->requestClose(index, force);
dataModel()->requestClose(index, force);
}

void TaskManager::requestUpdateWindowIconGeometry(const QModelIndex &index, const QRect &geometry, QObject *delegate) const
{
m_itemModel->requestUpdateWindowIconGeometry(index, geometry, delegate);
dataModel()->requestUpdateWindowIconGeometry(index, geometry, delegate);
}

void TaskManager::requestPreview(const QModelIndex &index, QObject *relativePositionItem, int32_t previewXoffset, int32_t previewYoffset, uint32_t direction)
Expand All @@ -261,7 +261,7 @@ void TaskManager::requestPreview(const QModelIndex &index, QObject *relativePosi

void TaskManager::requestWindowsView(const QModelIndexList &indexes) const
{
m_itemModel->requestWindowsView(indexes);
dataModel()->requestWindowsView(indexes);
}

void TaskManager::handleWindowAdded(QPointer<AbstractWindow> window)
Expand Down Expand Up @@ -316,7 +316,7 @@ void TaskManager::dropFilesOnItem(const QString& itemId, const QStringList& urls
urlList.append(QUrl::fromLocalFile(url));
}

m_itemModel->requestOpenUrls(indexes.first(), urlList);
dataModel()->requestOpenUrls(indexes.first(), urlList);
}

void TaskManager::hideItemPreview()
Expand Down