Changeset View
Changeset View
Standalone View
Standalone View
libtaskmanager/tasksmodel.cpp
Show All 19 Lines | |||||
20 | 20 | | |||
21 | #include "tasksmodel.h" | 21 | #include "tasksmodel.h" | ||
22 | #include "activityinfo.h" | 22 | #include "activityinfo.h" | ||
23 | #include "concatenatetasksproxymodel.h" | 23 | #include "concatenatetasksproxymodel.h" | ||
24 | #include "flattentaskgroupsproxymodel.h" | 24 | #include "flattentaskgroupsproxymodel.h" | ||
25 | #include "taskfilterproxymodel.h" | 25 | #include "taskfilterproxymodel.h" | ||
26 | #include "taskgroupingproxymodel.h" | 26 | #include "taskgroupingproxymodel.h" | ||
27 | #include "tasktools.h" | 27 | #include "tasktools.h" | ||
28 | #include "virtualdesktopinfo.h" | ||||
28 | 29 | | |||
29 | #include "launchertasksmodel.h" | 30 | #include "launchertasksmodel.h" | ||
30 | #include "startuptasksmodel.h" | 31 | #include "startuptasksmodel.h" | ||
31 | #include "windowtasksmodel.h" | 32 | #include "windowtasksmodel.h" | ||
32 | 33 | | |||
33 | #include "launchertasksmodel_p.h" | 34 | #include "launchertasksmodel_p.h" | ||
34 | 35 | | |||
35 | #include <QGuiApplication> | 36 | #include <QGuiApplication> | ||
Show All 20 Lines | 47 | public: | |||
56 | TaskFilterProxyModel* filterProxyModel = nullptr; | 57 | TaskFilterProxyModel* filterProxyModel = nullptr; | ||
57 | TaskGroupingProxyModel* groupingProxyModel = nullptr; | 58 | TaskGroupingProxyModel* groupingProxyModel = nullptr; | ||
58 | FlattenTaskGroupsProxyModel* flattenGroupsProxyModel = nullptr; | 59 | FlattenTaskGroupsProxyModel* flattenGroupsProxyModel = nullptr; | ||
59 | AbstractTasksModelIface *abstractTasksSourceModel = nullptr; | 60 | AbstractTasksModelIface *abstractTasksSourceModel = nullptr; | ||
60 | 61 | | |||
61 | bool anyTaskDemandsAttention = false; | 62 | bool anyTaskDemandsAttention = false; | ||
62 | 63 | | |||
63 | int launcherCount = 0; | 64 | int launcherCount = 0; | ||
64 | int virtualDesktop = -1; | | |||
65 | int screen = -1; | | |||
66 | QString activity; | | |||
67 | 65 | | |||
68 | SortMode sortMode = SortAlpha; | 66 | SortMode sortMode = SortAlpha; | ||
69 | bool separateLaunchers = true; | 67 | bool separateLaunchers = true; | ||
70 | bool launchInPlace = false; | 68 | bool launchInPlace = false; | ||
71 | bool launchersEverSet = false; | 69 | bool launchersEverSet = false; | ||
72 | bool launcherSortingDirty = false; | 70 | bool launcherSortingDirty = false; | ||
73 | bool launcherCheckNeeded = false; | 71 | bool launcherCheckNeeded = false; | ||
74 | QList<int> sortedPreFilterRows; | 72 | QList<int> sortedPreFilterRows; | ||
75 | QVector<int> sortRowInsertQueue; | 73 | QVector<int> sortRowInsertQueue; | ||
76 | bool sortRowInsertQueueStale = false; | 74 | bool sortRowInsertQueueStale = false; | ||
77 | QHash<QString, int> activityTaskCounts; | 75 | QHash<QString, int> activityTaskCounts; | ||
76 | static VirtualDesktopInfo *virtualDesktopInfo; | ||||
77 | static int virtualDesktopInfoUsers; | ||||
78 | static ActivityInfo* activityInfo; | 78 | static ActivityInfo* activityInfo; | ||
79 | static int activityInfoUsers; | 79 | static int activityInfoUsers; | ||
80 | 80 | | |||
81 | bool groupInline = false; | 81 | bool groupInline = false; | ||
82 | int groupingWindowTasksThreshold = -1; | 82 | int groupingWindowTasksThreshold = -1; | ||
83 | 83 | | |||
84 | bool usedByQml = false; | 84 | bool usedByQml = false; | ||
85 | bool componentComplete = false; | 85 | bool componentComplete = false; | ||
Show All 31 Lines | 116 | private: | |||
117 | const QAbstractItemModel *sourceModel; | 117 | const QAbstractItemModel *sourceModel; | ||
118 | const TasksModel *tasksModel; | 118 | const TasksModel *tasksModel; | ||
119 | bool sortOnlyLaunchers; | 119 | bool sortOnlyLaunchers; | ||
120 | }; | 120 | }; | ||
121 | 121 | | |||
122 | int TasksModel::Private::instanceCount = 0; | 122 | int TasksModel::Private::instanceCount = 0; | ||
123 | WindowTasksModel* TasksModel::Private::windowTasksModel = nullptr; | 123 | WindowTasksModel* TasksModel::Private::windowTasksModel = nullptr; | ||
124 | StartupTasksModel* TasksModel::Private::startupTasksModel = nullptr; | 124 | StartupTasksModel* TasksModel::Private::startupTasksModel = nullptr; | ||
125 | VirtualDesktopInfo* TasksModel::Private::virtualDesktopInfo = nullptr; | ||||
126 | int TasksModel::Private::virtualDesktopInfoUsers = 0; | ||||
125 | ActivityInfo* TasksModel::Private::activityInfo = nullptr; | 127 | ActivityInfo* TasksModel::Private::activityInfo = nullptr; | ||
126 | int TasksModel::Private::activityInfoUsers = 0; | 128 | int TasksModel::Private::activityInfoUsers = 0; | ||
127 | 129 | | |||
128 | TasksModel::Private::Private(TasksModel *q) | 130 | TasksModel::Private::Private(TasksModel *q) | ||
129 | : q(q) | 131 | : q(q) | ||
130 | { | 132 | { | ||
131 | ++instanceCount; | 133 | ++instanceCount; | ||
132 | } | 134 | } | ||
133 | 135 | | |||
134 | TasksModel::Private::~Private() | 136 | TasksModel::Private::~Private() | ||
135 | { | 137 | { | ||
136 | --instanceCount; | 138 | --instanceCount; | ||
137 | 139 | | |||
138 | if (sortMode == SortActivity) { | 140 | if (sortMode == SortActivity) { | ||
139 | --activityInfoUsers; | 141 | --activityInfoUsers; | ||
140 | } | 142 | } | ||
141 | 143 | | |||
142 | if (!instanceCount) { | 144 | if (!instanceCount) { | ||
143 | delete windowTasksModel; | 145 | delete windowTasksModel; | ||
144 | windowTasksModel = nullptr; | 146 | windowTasksModel = nullptr; | ||
145 | delete startupTasksModel; | 147 | delete startupTasksModel; | ||
146 | startupTasksModel = nullptr; | 148 | startupTasksModel = nullptr; | ||
149 | delete virtualDesktopInfo; | ||||
150 | virtualDesktopInfo = nullptr; | ||||
147 | delete activityInfo; | 151 | delete activityInfo; | ||
148 | activityInfo = nullptr; | 152 | activityInfo = nullptr; | ||
149 | } | 153 | } | ||
150 | } | 154 | } | ||
151 | 155 | | |||
152 | void TasksModel::Private::initModels() | 156 | void TasksModel::Private::initModels() | ||
153 | { | 157 | { | ||
154 | // NOTE: Overview over the entire model chain assembled here: | 158 | // NOTE: Overview over the entire model chain assembled here: | ||
▲ Show 20 Lines • Show All 717 Lines • ▼ Show 20 Line(s) | 832 | { | |||
872 | // If told to stop after launchers we fall through to the existing map if it exists. | 876 | // If told to stop after launchers we fall through to the existing map if it exists. | ||
873 | if (sortOnlyLaunchers && !sortedPreFilterRows.isEmpty()) { | 877 | if (sortOnlyLaunchers && !sortedPreFilterRows.isEmpty()) { | ||
874 | return (sortedPreFilterRows.indexOf(left.row()) < sortedPreFilterRows.indexOf(right.row())); | 878 | return (sortedPreFilterRows.indexOf(left.row()) < sortedPreFilterRows.indexOf(right.row())); | ||
875 | } | 879 | } | ||
876 | 880 | | |||
877 | // Sort other cases by sort mode. | 881 | // Sort other cases by sort mode. | ||
878 | switch (sortMode) { | 882 | switch (sortMode) { | ||
879 | case SortVirtualDesktop: { | 883 | case SortVirtualDesktop: { | ||
880 | const QVariant &leftDesktopVariant = left.data(AbstractTasksModel::VirtualDesktop); | 884 | const bool leftAll = left.data(AbstractTasksModel::IsOnAllVirtualDesktops).toBool(); | ||
881 | bool leftOk = false; | 885 | const bool rightAll = right.data(AbstractTasksModel::IsOnAllVirtualDesktops).toBool(); | ||
882 | const int leftDesktop = leftDesktopVariant.toInt(&leftOk); | 886 | | ||
883 | 887 | if (leftAll && !rightAll) { | |||
884 | const QVariant &rightDesktopVariant = right.data(AbstractTasksModel::VirtualDesktop); | 888 | return true; | ||
885 | bool rightOk = false; | 889 | } else if (rightAll && !leftAll) { | ||
886 | const int rightDesktop = rightDesktopVariant.toInt(&rightOk); | 890 | return true; | ||
887 | 891 | } | |||
888 | if (leftOk && rightOk && (leftDesktop != rightDesktop)) { | 892 | | ||
889 | return (leftDesktop < rightDesktop); | 893 | const QVariantList &leftDesktops = left.data(AbstractTasksModel::VirtualDesktops).toList(); | ||
890 | } else if (leftOk && !rightOk) { | 894 | QVariant leftDesktop; | ||
895 | int leftDesktopPos = virtualDesktopInfo->numberOfDesktops(); | ||||
896 | | ||||
897 | for (const QVariant &desktop : leftDesktops) { | ||||
898 | const int desktopPos = virtualDesktopInfo->position(desktop); | ||||
899 | | ||||
900 | if (desktopPos < leftDesktopPos) { | ||||
901 | leftDesktop = desktop; | ||||
902 | leftDesktopPos = desktopPos; | ||||
903 | } | ||||
904 | } | ||||
905 | | ||||
906 | const QVariantList &rightDesktops = right.data(AbstractTasksModel::VirtualDesktops).toList(); | ||||
907 | QVariant rightDesktop; | ||||
908 | int rightDesktopPos = virtualDesktopInfo->numberOfDesktops(); | ||||
909 | | ||||
910 | for (const QVariant &desktop : rightDesktops) { | ||||
911 | const int desktopPos = virtualDesktopInfo->position(desktop); | ||||
912 | | ||||
913 | if (desktopPos < rightDesktopPos) { | ||||
914 | rightDesktop = desktop; | ||||
915 | rightDesktopPos = desktopPos; | ||||
916 | } | ||||
917 | } | ||||
918 | | ||||
919 | if (!leftDesktop.isNull() && !rightDesktop.isNull() && (leftDesktop != rightDesktop)) { | ||||
920 | return (virtualDesktopInfo->position(leftDesktop) < virtualDesktopInfo->position(rightDesktop)); | ||||
921 | } else if (!leftDesktop.isNull() && rightDesktop.isNull()) { | ||||
891 | return false; | 922 | return false; | ||
892 | } else if (!leftOk && rightOk) { | 923 | } else if (leftDesktop.isNull() && !rightDesktop.isNull()) { | ||
893 | return true; | 924 | return true; | ||
894 | } | 925 | } | ||
926 | | ||||
927 | return false; | ||||
895 | } | 928 | } | ||
896 | case SortActivity: { | 929 | case SortActivity: { | ||
897 | // updateActivityTaskCounts() counts the number of window tasks on each | 930 | // updateActivityTaskCounts() counts the number of window tasks on each | ||
898 | // activity. This will sort tasks by comparing a cumulative score made | 931 | // activity. This will sort tasks by comparing a cumulative score made | ||
899 | // up of the task counts for each acvtivity a task is assigned to, and | 932 | // up of the task counts for each acvtivity a task is assigned to, and | ||
900 | // otherwise fall through to alphabetical sorting. | 933 | // otherwise fall through to alphabetical sorting. | ||
901 | int leftScore = -1; | 934 | int leftScore = -1; | ||
902 | int rightScore = -1; | 935 | int rightScore = -1; | ||
Show All 26 Lines | 953 | if (leftScore == -1 || rightScore == -1) { | |||
929 | } | 962 | } | ||
930 | } | 963 | } | ||
931 | 964 | | |||
932 | if (leftScore != rightScore) { | 965 | if (leftScore != rightScore) { | ||
933 | return (leftScore > rightScore); | 966 | return (leftScore > rightScore); | ||
934 | } | 967 | } | ||
935 | } | 968 | } | ||
936 | // Fall through to source order if sorting is disabled or manual, or alphabetical by app name otherwise. | 969 | // Fall through to source order if sorting is disabled or manual, or alphabetical by app name otherwise. | ||
970 | // This marker comment makes gcc/clang happy: | ||||
971 | // fall through | ||||
937 | default: { | 972 | default: { | ||
938 | if (sortMode == SortDisabled) { | 973 | if (sortMode == SortDisabled) { | ||
939 | return (left.row() < right.row()); | 974 | return (left.row() < right.row()); | ||
940 | } else { | 975 | } else { | ||
941 | // The overall goal of alphabetic sorting is to sort tasks belonging to the | 976 | // The overall goal of alphabetic sorting is to sort tasks belonging to the | ||
942 | // same app together, while sorting the resulting sets alphabetically among | 977 | // same app together, while sorting the resulting sets alphabetically among | ||
943 | // themselves by the app name. The following code tries to achieve this by | 978 | // themselves by the app name. The following code tries to achieve this by | ||
944 | // going for AppName first, and falling back to DisplayRole - which for | 979 | // going for AppName first, and falling back to DisplayRole - which for | ||
▲ Show 20 Lines • Show All 89 Lines • ▼ Show 20 Line(s) | 1067 | for (int i = 0; i < d->launcherTasksModel->rowCount(); ++i) { | |||
1034 | 1069 | | |||
1035 | if (appsMatch(proxyIndex, launcherIndex)) { | 1070 | if (appsMatch(proxyIndex, launcherIndex)) { | ||
1036 | return true; | 1071 | return true; | ||
1037 | } | 1072 | } | ||
1038 | } | 1073 | } | ||
1039 | 1074 | | |||
1040 | return false; | 1075 | return false; | ||
1041 | } | 1076 | } | ||
1042 | } else if (rowCount(proxyIndex) && role == AbstractTasksModel::LegacyWinIdList) { | 1077 | } else if (rowCount(proxyIndex) && role == AbstractTasksModel::WinIdList) { | ||
1043 | QVariantList winIds; | 1078 | QVariantList winIds; | ||
1044 | 1079 | | |||
1045 | for (int i = 0; i < rowCount(proxyIndex); ++i) { | 1080 | for (int i = 0; i < rowCount(proxyIndex); ++i) { | ||
1046 | winIds.append(proxyIndex.child(i, 0).data(AbstractTasksModel::LegacyWinIdList).toList()); | 1081 | winIds.append(proxyIndex.child(i, 0).data(AbstractTasksModel::WinIdList).toList()); | ||
1047 | } | 1082 | } | ||
1048 | 1083 | | |||
1049 | return winIds; | 1084 | return winIds; | ||
1050 | } | 1085 | } | ||
1051 | 1086 | | |||
1052 | return QSortFilterProxyModel::data(proxyIndex, role); | 1087 | return QSortFilterProxyModel::data(proxyIndex, role); | ||
1053 | } | 1088 | } | ||
1054 | 1089 | | |||
Show All 22 Lines | 1111 | { | |||
1077 | return d->launcherCount; | 1112 | return d->launcherCount; | ||
1078 | } | 1113 | } | ||
1079 | 1114 | | |||
1080 | bool TasksModel::anyTaskDemandsAttention() const | 1115 | bool TasksModel::anyTaskDemandsAttention() const | ||
1081 | { | 1116 | { | ||
1082 | return d->anyTaskDemandsAttention; | 1117 | return d->anyTaskDemandsAttention; | ||
1083 | } | 1118 | } | ||
1084 | 1119 | | |||
1085 | int TasksModel::virtualDesktop() const | 1120 | QVariant TasksModel::virtualDesktop() const | ||
1086 | { | 1121 | { | ||
1087 | return d->filterProxyModel->virtualDesktop(); | 1122 | return d->filterProxyModel->virtualDesktop(); | ||
1088 | } | 1123 | } | ||
1089 | 1124 | | |||
1090 | void TasksModel::setVirtualDesktop(int virtualDesktop) | 1125 | void TasksModel::setVirtualDesktop(const QVariant &desktop) | ||
1091 | { | 1126 | { | ||
1092 | d->filterProxyModel->setVirtualDesktop(virtualDesktop); | 1127 | d->filterProxyModel->setVirtualDesktop(desktop); | ||
davidedmundson: leftover | |||||
1093 | } | 1128 | } | ||
1094 | 1129 | | |||
1095 | QRect TasksModel::screenGeometry() const | 1130 | QRect TasksModel::screenGeometry() const | ||
1096 | { | 1131 | { | ||
1097 | return d->filterProxyModel->screenGeometry(); | 1132 | return d->filterProxyModel->screenGeometry(); | ||
1098 | } | 1133 | } | ||
1099 | 1134 | | |||
1100 | void TasksModel::setScreenGeometry(const QRect &geometry) | 1135 | void TasksModel::setScreenGeometry(const QRect &geometry) | ||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Line(s) | |||||
1161 | { | 1196 | { | ||
1162 | if (d->sortMode != mode) { | 1197 | if (d->sortMode != mode) { | ||
1163 | if (mode == SortManual) { | 1198 | if (mode == SortManual) { | ||
1164 | d->updateManualSortMap(); | 1199 | d->updateManualSortMap(); | ||
1165 | } else if (d->sortMode == SortManual) { | 1200 | } else if (d->sortMode == SortManual) { | ||
1166 | d->sortedPreFilterRows.clear(); | 1201 | d->sortedPreFilterRows.clear(); | ||
1167 | } | 1202 | } | ||
1168 | 1203 | | |||
1204 | if (mode == SortVirtualDesktop) { | ||||
1205 | if (!d->virtualDesktopInfo) { | ||||
1206 | d->virtualDesktopInfo = new VirtualDesktopInfo(); | ||||
1207 | } | ||||
1208 | | ||||
1209 | ++d->virtualDesktopInfoUsers; | ||||
1210 | | ||||
1211 | setSortRole(AbstractTasksModel::VirtualDesktops); | ||||
1212 | } else if (d->sortMode == SortVirtualDesktop) { | ||||
1213 | --d->virtualDesktopInfoUsers; | ||||
1214 | | ||||
1215 | if (!d->virtualDesktopInfoUsers) { | ||||
1216 | delete d->virtualDesktopInfo; | ||||
1217 | d->virtualDesktopInfo = nullptr; | ||||
1218 | } | ||||
1219 | | ||||
1220 | setSortRole(Qt::DisplayRole); | ||||
1221 | } | ||||
1222 | | ||||
1169 | if (mode == SortActivity) { | 1223 | if (mode == SortActivity) { | ||
1170 | if (!d->activityInfo) { | 1224 | if (!d->activityInfo) { | ||
1171 | d->activityInfo = new ActivityInfo(); | 1225 | d->activityInfo = new ActivityInfo(); | ||
1172 | } | 1226 | } | ||
1173 | 1227 | | |||
1174 | ++d->activityInfoUsers; | 1228 | ++d->activityInfoUsers; | ||
1175 | 1229 | | |||
1176 | d->updateActivityTaskCounts(); | 1230 | d->updateActivityTaskCounts(); | ||
▲ Show 20 Lines • Show All 323 Lines • ▼ Show 20 Line(s) | |||||
1500 | 1554 | | |||
1501 | void TasksModel::requestToggleShaded(const QModelIndex &index) | 1555 | void TasksModel::requestToggleShaded(const QModelIndex &index) | ||
1502 | { | 1556 | { | ||
1503 | if (index.isValid() && index.model() == this) { | 1557 | if (index.isValid() && index.model() == this) { | ||
1504 | d->abstractTasksSourceModel->requestToggleShaded(mapToSource(index)); | 1558 | d->abstractTasksSourceModel->requestToggleShaded(mapToSource(index)); | ||
1505 | } | 1559 | } | ||
1506 | } | 1560 | } | ||
1507 | 1561 | | |||
1508 | void TasksModel::requestVirtualDesktop(const QModelIndex &index, qint32 desktop) | 1562 | void TasksModel::requestVirtualDesktops(const QModelIndex &index, const QVariantList &desktops) | ||
1563 | { | ||||
1564 | if (index.isValid() && index.model() == this) { | ||||
1565 | d->abstractTasksSourceModel->requestVirtualDesktops(mapToSource(index), desktops); | ||||
1566 | } | ||||
1567 | } | ||||
1568 | | ||||
1569 | void TasksModel::requestNewVirtualDesktop(const QModelIndex &index) | ||||
1509 | { | 1570 | { | ||
1510 | if (index.isValid() && index.model() == this) { | 1571 | if (index.isValid() && index.model() == this) { | ||
1511 | d->abstractTasksSourceModel->requestVirtualDesktop(mapToSource(index), desktop); | 1572 | d->abstractTasksSourceModel->requestNewVirtualDesktop(mapToSource(index)); | ||
1512 | } | 1573 | } | ||
1513 | } | 1574 | } | ||
1514 | 1575 | | |||
1515 | void TasksModel::requestActivities(const QModelIndex &index, const QStringList &activities) | 1576 | void TasksModel::requestActivities(const QModelIndex &index, const QStringList &activities) | ||
1516 | { | 1577 | { | ||
1517 | if (index.isValid() && index.model() == this) { | 1578 | if (index.isValid() && index.model() == this) { | ||
1518 | d->groupingProxyModel->requestActivities(mapToSource(index), activities); | 1579 | d->groupingProxyModel->requestActivities(mapToSource(index), activities); | ||
1519 | } | 1580 | } | ||
▲ Show 20 Lines • Show All 358 Lines • Show Last 20 Lines |
leftover