Changeset View
Changeset View
Standalone View
Standalone View
libtaskmanager/tasksmodel.cpp
Show First 20 Lines • Show All 52 Lines • ▼ Show 20 Line(s) | 46 | public: | |||
---|---|---|---|---|---|
53 | static StartupTasksModel* startupTasksModel; | 53 | static StartupTasksModel* startupTasksModel; | ||
54 | LauncherTasksModel* launcherTasksModel = nullptr; | 54 | LauncherTasksModel* launcherTasksModel = nullptr; | ||
55 | ConcatenateTasksProxyModel* concatProxyModel = nullptr; | 55 | ConcatenateTasksProxyModel* concatProxyModel = nullptr; | ||
56 | TaskFilterProxyModel* filterProxyModel = nullptr; | 56 | TaskFilterProxyModel* filterProxyModel = nullptr; | ||
57 | TaskGroupingProxyModel* groupingProxyModel = nullptr; | 57 | TaskGroupingProxyModel* groupingProxyModel = nullptr; | ||
58 | FlattenTaskGroupsProxyModel* flattenGroupsProxyModel = nullptr; | 58 | FlattenTaskGroupsProxyModel* flattenGroupsProxyModel = nullptr; | ||
59 | AbstractTasksModelIface *abstractTasksSourceModel = nullptr; | 59 | AbstractTasksModelIface *abstractTasksSourceModel = nullptr; | ||
60 | 60 | | |||
61 | QSet<QString> pinAppIdList; | ||||
62 | QSet<QString> pinLauncherUrlList; | ||||
63 | | ||||
61 | bool anyTaskDemandsAttention = false; | 64 | bool anyTaskDemandsAttention = false; | ||
62 | 65 | | |||
63 | int launcherCount = 0; | 66 | int launcherCount = 0; | ||
64 | int virtualDesktop = -1; | 67 | int virtualDesktop = -1; | ||
65 | int screen = -1; | 68 | int screen = -1; | ||
66 | QString activity; | 69 | QString activity; | ||
67 | 70 | | |||
68 | SortMode sortMode = SortAlpha; | 71 | SortMode sortMode = SortAlpha; | ||
▲ Show 20 Lines • Show All 896 Lines • ▼ Show 20 Line(s) | 967 | } else if (rowCount(proxyIndex) && role == AbstractTasksModel::LegacyWinIdList) { | |||
965 | QVariantList winIds; | 968 | QVariantList winIds; | ||
966 | 969 | | |||
967 | for (int i = 0; i < rowCount(proxyIndex); ++i) { | 970 | for (int i = 0; i < rowCount(proxyIndex); ++i) { | ||
968 | winIds.append(proxyIndex.child(i, 0).data(AbstractTasksModel::LegacyWinIdList).toList()); | 971 | winIds.append(proxyIndex.child(i, 0).data(AbstractTasksModel::LegacyWinIdList).toList()); | ||
969 | } | 972 | } | ||
970 | 973 | | |||
971 | return winIds; | 974 | return winIds; | ||
972 | } | 975 | } | ||
976 | else if (role == AbstractTasksModel::IsPinned | ||||
977 | && proxyIndex.isValid() && proxyIndex.row() < rowCount()) { | ||||
978 | return isPinned(proxyIndex); | ||||
979 | } | ||||
973 | 980 | | |||
974 | return QSortFilterProxyModel::data(proxyIndex, role); | 981 | return QSortFilterProxyModel::data(proxyIndex, role); | ||
975 | } | 982 | } | ||
976 | 983 | | |||
977 | void TasksModel::updateLauncherCount() | 984 | void TasksModel::updateLauncherCount() | ||
978 | { | 985 | { | ||
979 | if (!d->launcherTasksModel) { | 986 | if (!d->launcherTasksModel) { | ||
980 | return; | 987 | return; | ||
▲ Show 20 Lines • Show All 251 Lines • ▼ Show 20 Line(s) | |||||
1232 | 1239 | | |||
1233 | void TasksModel::setGroupingLauncherUrlBlacklist(const QStringList &list) | 1240 | void TasksModel::setGroupingLauncherUrlBlacklist(const QStringList &list) | ||
1234 | { | 1241 | { | ||
1235 | if (d->groupingProxyModel) { | 1242 | if (d->groupingProxyModel) { | ||
1236 | d->groupingProxyModel->setBlacklistedLauncherUrls(list); | 1243 | d->groupingProxyModel->setBlacklistedLauncherUrls(list); | ||
1237 | } | 1244 | } | ||
1238 | } | 1245 | } | ||
1239 | 1246 | | |||
1247 | QStringList TasksModel::pinAppIdList() const | ||||
1248 | { | ||||
1249 | return d->pinAppIdList.toList(); | ||||
1250 | } | ||||
1251 | | ||||
1252 | void TasksModel::setPinAppIdList(const QStringList &list) | ||||
1253 | { | ||||
1254 | const QSet<QString> &set = QSet<QString>::fromList(list); | ||||
1255 | | ||||
1256 | if (d->pinAppIdList != set) { | ||||
1257 | d->pinAppIdList = set; | ||||
1258 | emit pinAppIdListChanged(); | ||||
1259 | } | ||||
1260 | } | ||||
1261 | | ||||
1262 | QStringList TasksModel::pinLauncherUrlList() const | ||||
1263 | { | ||||
1264 | return d->pinLauncherUrlList.toList(); | ||||
1265 | } | ||||
1266 | | ||||
1267 | void TasksModel::setPinLauncherUrlList(const QStringList &list) | ||||
1268 | { | ||||
1269 | const QSet<QString> &set = QSet<QString>::fromList(list); | ||||
1270 | | ||||
1271 | if (d->pinLauncherUrlList != set) { | ||||
1272 | d->pinLauncherUrlList = set; | ||||
1273 | emit pinLauncherUrlListChanged(); | ||||
1274 | } | ||||
1275 | } | ||||
1276 | | ||||
1240 | QStringList TasksModel::launcherList() const | 1277 | QStringList TasksModel::launcherList() const | ||
1241 | { | 1278 | { | ||
1242 | if (d->launcherTasksModel) { | 1279 | if (d->launcherTasksModel) { | ||
1243 | return d->launcherTasksModel->launcherList(); | 1280 | return d->launcherTasksModel->launcherList(); | ||
1244 | } | 1281 | } | ||
1245 | 1282 | | |||
1246 | return QStringList(); | 1283 | return QStringList(); | ||
1247 | } | 1284 | } | ||
▲ Show 20 Lines • Show All 204 Lines • ▼ Show 20 Line(s) | |||||
1452 | { | 1489 | { | ||
1453 | if (index.isValid() && index.model() == this) { | 1490 | if (index.isValid() && index.model() == this) { | ||
1454 | const QModelIndex &target = (d->flattenGroupsProxyModel | 1491 | const QModelIndex &target = (d->flattenGroupsProxyModel | ||
1455 | ? d->flattenGroupsProxyModel->mapToSource(mapToSource(index)) : mapToSource(index)); | 1492 | ? d->flattenGroupsProxyModel->mapToSource(mapToSource(index)) : mapToSource(index)); | ||
1456 | d->groupingProxyModel->requestToggleGrouping(target); | 1493 | d->groupingProxyModel->requestToggleGrouping(target); | ||
1457 | } | 1494 | } | ||
1458 | } | 1495 | } | ||
1459 | 1496 | | |||
1497 | void TasksModel::requestTogglePin(const QModelIndex &index) | ||||
1498 | { | ||||
1499 | if (index.isValid() && index.model() == this) { | ||||
1500 | const QModelIndex &target = mapToSource(index); | ||||
1501 | const QString &appId = target.data(AbstractTasksModel::AppId).toString(); | ||||
1502 | const QUrl &launcherUrl = target.data(AbstractTasksModel::LauncherUrlWithoutIcon).toUrl(); | ||||
1503 | const QString &launcherUrlString = launcherUrl.toString(QUrl::RemoveQuery | QUrl::RemoveQuery); | ||||
1504 | | ||||
1505 | if (d->pinAppIdList.contains(appId) || d->pinLauncherUrlList.contains(launcherUrlString)) { | ||||
1506 | d->pinAppIdList.remove(appId); | ||||
1507 | d->pinLauncherUrlList.remove(launcherUrlString); | ||||
1508 | } else { | ||||
1509 | d->pinAppIdList.insert(appId); | ||||
1510 | d->pinLauncherUrlList.insert(launcherUrlString); | ||||
1511 | } | ||||
1512 | | ||||
1513 | //TODO: Update IsPinned data role for all items | ||||
1514 | dataChanged(index, index, QVector<int>{AbstractTasksModel::IsPinned}); | ||||
1515 | | ||||
1516 | emit pinAppIdListChanged(); | ||||
1517 | emit pinLauncherUrlListChanged(); | ||||
1518 | } | ||||
1519 | } | ||||
1520 | | ||||
1521 | bool TasksModel::isPinned(const QModelIndex &sourceIndex) const | ||||
1522 | { | ||||
1523 | // Check app id against pin list. | ||||
1524 | if (d->pinAppIdList.count() | ||||
1525 | && d->pinAppIdList.contains(sourceIndex.data(AbstractTasksModel::AppId).toString())) { | ||||
1526 | return true; | ||||
1527 | } | ||||
1528 | | ||||
1529 | // Check launcher URL (sans query items) against pin list. | ||||
1530 | if (d->pinLauncherUrlList.count()) { | ||||
1531 | const QUrl &launcherUrl = sourceIndex.data(AbstractTasksModel::LauncherUrlWithoutIcon).toUrl(); | ||||
1532 | const QString &launcherUrlString = launcherUrl.toString(QUrl::PrettyDecoded | QUrl::RemoveQuery); | ||||
1533 | | ||||
1534 | if (d->pinLauncherUrlList.contains(launcherUrlString)) { | ||||
1535 | return true; | ||||
1536 | } | ||||
1537 | } | ||||
1538 | | ||||
1539 | return false; | ||||
1540 | } | ||||
1541 | | ||||
1460 | bool TasksModel::move(int row, int newPos, const QModelIndex &parent) | 1542 | bool TasksModel::move(int row, int newPos, const QModelIndex &parent) | ||
1461 | { | 1543 | { | ||
1462 | if (d->sortMode != SortManual || row == newPos || newPos < 0 || newPos >= rowCount(parent)) { | 1544 | if (d->sortMode != SortManual || row == newPos || newPos < 0 || newPos >= rowCount(parent)) { | ||
1463 | return false; | 1545 | return false; | ||
1464 | } | 1546 | } | ||
1465 | 1547 | | |||
1466 | const QModelIndex &idx = index(row, 0); | 1548 | const QModelIndex &idx = index(row, 0); | ||
1467 | bool isLauncherMove = false; | 1549 | bool isLauncherMove = false; | ||
▲ Show 20 Lines • Show All 332 Lines • Show Last 20 Lines |