44
55#include " itemmodel.h"
66#include " abstractitem.h"
7+ #include " appitem.h"
8+ #include " globals.h"
9+ #include " taskmanager.h"
710#include " taskmanagersettings.h"
811
912#include < algorithm>
@@ -32,17 +35,19 @@ ItemModel::ItemModel(QObject* parent)
3235
3336QHash<int , QByteArray> ItemModel::roleNames () const
3437{
35- return {{ItemModel::ItemIdRole, " itemId" },
36- {ItemModel::NameRole, " name" },
37- {ItemModel::IconNameRole, " iconName" },
38- {ItemModel::ActiveRole, " active" },
39- {ItemModel::AttentionRole, " attention" },
40- {ItemModel::MenusRole, " menus" },
41- {ItemModel::DockedRole, " docked" },
42- {ItemModel::WindowsRole, " windows" },
43- {ItemModel::DesktopFilesIconsRole, " desktopfileIcons" },
38+ // clang-format off
39+ return {{ItemModel::ItemIdRole, MODEL_ITEMID},
40+ {TaskManager::NameRole, MODEL_NAME},
41+ {TaskManager::IconNameRole, MODEL_ICONNAME},
42+ {TaskManager::ActiveRole, MODEL_ACTIVE},
43+ {TaskManager::AttentionRole, MODEL_ATTENTION},
44+ {TaskManager::MenusRole, MODEL_MENUS},
45+ {TaskManager::DockedRole, MODEL_DOCKED},
46+ {TaskManager::WindowsRole, MODEL_WINDOWS},
47+ {TaskManager::WinIconRole, MODEL_WINICON},
4448 {ItemModel::DockedDirRole, " dockedDir" }
4549 };
50+ // clang-format on
4651}
4752
4853int ItemModel::rowCount (const QModelIndex &parent) const
@@ -57,18 +62,20 @@ QVariant ItemModel::data(const QModelIndex &index, int role) const
5762 }
5863
5964 auto item = m_items[index.row ()];
65+ // clang-format off
6066 switch (role) {
6167 case ItemModel::ItemIdRole: return item->id ();
62- case ItemModel ::NameRole: return item->name ();
63- case ItemModel ::IconNameRole: return item->icon ();
64- case ItemModel ::ActiveRole: return item->isActive ();
65- case ItemModel ::AttentionRole: return item->isAttention ();
66- case ItemModel ::MenusRole: return item->menus ();
67- case ItemModel ::DockedRole: return item->isDocked ();
68- case ItemModel ::WindowsRole: return item->data ().toStringList ();
69- case ItemModel::DesktopFilesIconsRole : return item->data ().toStringList ();
68+ case TaskManager ::NameRole: return item->name ();
69+ case TaskManager ::IconNameRole: return item->icon ();
70+ case TaskManager ::ActiveRole: return item->isActive ();
71+ case TaskManager ::AttentionRole: return item->isAttention ();
72+ case TaskManager ::MenusRole: return item->menus ();
73+ case TaskManager ::DockedRole: return item->isDocked ();
74+ case TaskManager ::WindowsRole: return item->data ().toStringList ();
75+ case TaskManager::WinIconRole : return item->data ().toStringList ();
7076 case ItemModel::DockedDirRole: return item->data ().toString ();
7177 }
78+ // clang-format on
7279 return QVariant ();
7380}
7481
@@ -89,6 +96,78 @@ QJsonArray ItemModel::dumpDockedItems() const
8996 return result;
9097}
9198
99+ void ItemModel::requestActivate (const QModelIndex &index) const
100+ {
101+ QString itemId = data (index).toString ();
102+
103+ auto item = ItemModel::instance ()->getItemById (itemId);
104+ if (!item) {
105+ return ;
106+ }
107+
108+ item->handleClick (QString ());
109+ }
110+
111+ void ItemModel::requestNewInstance (const QModelIndex &index, const QString &action) const
112+ {
113+ QString itemId = data (index).toString ();
114+
115+ auto item = ItemModel::instance ()->getItemById (itemId);
116+ if (!item) {
117+ return ;
118+ }
119+
120+ item->handleClick (DOCK_ACTIN_LAUNCH);
121+ }
122+
123+ void ItemModel::requestClose (const QModelIndex &index, bool force) const
124+ {
125+ QString itemId = data (index).toString ();
126+
127+ auto item = ItemModel::instance ()->getItemById (itemId);
128+ if (!item) {
129+ return ;
130+ }
131+
132+ item->handleClick (force ? DOCK_ACTION_FORCEQUIT : DOCK_ACTION_CLOSEALL);
133+ }
134+
135+ void ItemModel::requestOpenUrls (const QModelIndex &index, const QList<QUrl> &urls) const
136+ {
137+ QString itemId = data (index).toString ();
138+
139+ auto item = ItemModel::instance ()->getItemById (itemId);
140+ if (!item) {
141+ return ;
142+ }
143+
144+ // convert urls to string list
145+ QStringList urlsStr;
146+ for (auto url : std::as_const (urls)) {
147+ urlsStr.append (url.toString ());
148+ }
149+
150+ item->handleFileDrop (urlsStr);
151+ }
152+
153+ void ItemModel::requestWindowsView (const QModelIndexList &indexes) const
154+ {
155+ // nothing here, dummy entry.
156+ }
157+
158+ void ItemModel::requestUpdateWindowIconGeometry (const QModelIndex &index, const QRect &geometry, QObject *delegate) const
159+ {
160+ QString itemId = data (index).toString ();
161+
162+ QPointer<AppItem> item = static_cast <AppItem *>(ItemModel::instance ()->getItemById (itemId).get ());
163+ if (item.isNull ())
164+ return ;
165+
166+ for (auto window : item->getAppendWindows ()) {
167+ window->setWindowIconGeometry (qobject_cast<QWindow *>(delegate), geometry);
168+ }
169+ }
170+
92171QPointer<AbstractItem> ItemModel::getItemById (const QString& id) const
93172{
94173 auto it = std::find_if (m_items.begin (), m_items.end (),[id](QPointer<AbstractItem> item){
0 commit comments