@@ -43,13 +43,37 @@ QVariant AppGroupManager::data(const QModelIndex &index, int role) const
4343 if (!index.isValid ())
4444 return QVariant ();
4545
46- if (role == GroupIdRole) {
47- return index.row ();
48- }
49-
5046 return QStandardItemModel::data (index, role);
5147}
5248
49+ QHash<int , QByteArray> AppGroupManager::roleNames () const
50+ {
51+ return {
52+ {GroupIdRole, QByteArrayLiteral (" groupId" )},
53+ {GroupItemsPerPageRole, QByteArrayLiteral (" groupItemsPerPage" )},
54+ {AppItemModel::DesktopIdRole, QByteArrayLiteral (" desktopId" )},
55+ {AppItemModel::NameRole, QByteArrayLiteral (" name" )},
56+ {AppItemModel::IconNameRole, QByteArrayLiteral (" iconName" )},
57+ {AppItemModel::StartUpWMClassRole, QByteArrayLiteral (" startupWMClass" )},
58+ {AppItemModel::NoDisplayRole, QByteArrayLiteral (" noDisplay" )},
59+ {AppItemModel::ActionsRole, QByteArrayLiteral (" actions" )},
60+ {AppItemModel::DDECategoryRole, QByteArrayLiteral (" ddeCategory" )},
61+ {AppItemModel::CategoriesRole, QByteArrayLiteral (" categories" )},
62+ {AppItemModel::InstalledTimeRole, QByteArrayLiteral (" installedTime" )},
63+ {AppItemModel::LastLaunchedTimeRole, QByteArrayLiteral (" lastLaunchedTime" )},
64+ {AppItemModel::LaunchedTimesRole, QByteArrayLiteral (" launchedTimes" )},
65+ {AppItemModel::DockedRole, QByteArrayLiteral (" docked" )},
66+ {AppItemModel::OnDesktopRole, QByteArrayLiteral (" onDesktop" )},
67+ {AppItemModel::AutoStartRole, QByteArrayLiteral (" autoStart" )},
68+ {AppItemModel::AppTypeRole, QByteArrayLiteral (" appType" )},
69+ {AppItemModel::XLingLongRole, QByteArrayLiteral (" isLingLong" )},
70+ {AppItemModel::IdRole, QByteArrayLiteral (" id" )},
71+ {AppItemModel::XCreatedByRole, QByteArrayLiteral (" xCreatedBy" )},
72+ {AppItemModel::ExecsRole, QByteArrayLiteral (" execs" )},
73+ {AppItemModel::DesktopSourcePathRole, QByteArrayLiteral (" desktopSourcePath" )},
74+ };
75+ }
76+
5377// Find the item's location. If folderId is -1, search all folders.
5478ItemPosition AppGroupManager::findItem (const QString &appId, int folderId)
5579{
@@ -121,6 +145,32 @@ ItemsPage * AppGroupManager::groupPages(int groupId)
121145 return folder->itemsPage ();
122146}
123147
148+ QStringList AppGroupManager::groupItems (const QString &groupId) const
149+ {
150+ QString normalizedGroupId = groupId;
151+ bool isNumericGroupId = false ;
152+ groupId.toInt (&isNumericGroupId);
153+
154+ if (AppGroup::idIsFolder (groupId)) {
155+ normalizedGroupId = AppGroup::normalizeGroupId (groupId);
156+ } else if (isNumericGroupId) {
157+ normalizedGroupId = AppGroup::groupIdFromNumber (groupId.toInt ());
158+ } else {
159+ return {};
160+ }
161+
162+ for (int i = 0 ; i < rowCount (); ++i) {
163+ auto folder = static_cast <AppGroup *>(item (i));
164+ if (!folder || AppGroup::normalizeGroupId (folder->appId ()) != normalizedGroupId) {
165+ continue ;
166+ }
167+
168+ return folder->itemsPage ()->allArrangedItems ();
169+ }
170+
171+ return {};
172+ }
173+
124174void AppGroupManager::bringToFromt (const QString & id)
125175{
126176 const ItemPosition origPos = findItem (id);
@@ -342,6 +392,8 @@ void AppGroupManager::loadAppGroupInfo()
342392
343393 if (groupId.isEmpty ()) {
344394 groupId = assignGroupId ();
395+ } else {
396+ groupId = AppGroup::normalizeGroupId (groupId);
345397 }
346398 appendGroup (groupId, name, items);
347399 }
@@ -373,15 +425,15 @@ QString AppGroupManager::assignGroupId() const
373425 QStringList knownGroupIds;
374426 for (int i = 0 ; i < rowCount (); i++) {
375427 auto group = index (i, 0 );
376- knownGroupIds.append (group.data (AppItemModel::DesktopIdRole).toString ());
428+ knownGroupIds.append (AppGroup::normalizeGroupId ( group.data (AppItemModel::DesktopIdRole).toString () ));
377429 }
378430
379431 int idNumber = 0 ;
380- while (knownGroupIds.contains (QString ( " internal/group/%1 " ). arg (idNumber))) {
432+ while (knownGroupIds.contains (AppGroup::groupIdFromNumber (idNumber))) {
381433 idNumber++;
382434 }
383435
384- return QString ( " internal/group/%1 " ). arg (idNumber);
436+ return AppGroup::groupIdFromNumber (idNumber);
385437}
386438
387439AppGroup * AppGroupManager::appendGroup (int groupId, QString groupName, const QList<QStringList> &appItemIDs)
@@ -392,7 +444,7 @@ AppGroup * AppGroupManager::appendGroup(int groupId, QString groupName, const QL
392444
393445AppGroup * AppGroupManager::appendGroup (QString groupId, QString groupName, const QList<QStringList> &appItemIDs)
394446{
395- auto p = new AppGroup (groupId, groupName, appItemIDs);
447+ auto p = new AppGroup (AppGroup::normalizeGroupId ( groupId) , groupName, appItemIDs);
396448 appendRow (p);
397449 return p;
398450}
0 commit comments