@@ -19,155 +19,65 @@ import Ubuntu.Components 0.1
19import Utils 0.1
19import Utils 0.1
20import "../Components"
20import "../Components"
21import "../Components/ListItems"
21import "../Components/ListItems"
22+import "../Applications"
22import "Apps"
23import "Apps"
24−ScopeView {
25+GenericScopeView {
25 id: scopeView
26 id: scopeView
27 // FIXME: a way to aggregate these models would be ideal
28 // FIXME: a way to aggregate these models would be ideal
28 property var mainStageApplicationsModel: shell.applicationManager.mainStageApplications
29 property var mainStageApplicationsModel: shell.applicationManager.mainStageApplications
29 property var sideStageApplicationModel: shell.applicationManager.sideStageApplications
30 property var sideStageApplicationModel: shell.applicationManager.sideStageApplications
31− onMovementStarted: categoryView.showHeader()
32+ ListModel {
32− onPositionedAtBeginning: {
33+ id: frequentlyUsedAppsModel
34− categoryView.positionAtBeginning()
38− onIsCurrentChanged: {
39− pageHeader.resetSearch();
43− target: scopeView.scope
44− property: "searchQuery"
45− value: pageHeader.searchQuery
48− Connections {
36+ FrequentlyUsedAppsModel { id: frequentlyUsedAppsBaseModel }
50− onSearchClicked: if (isCurrent) {
51− pageHeader.triggerSearch()
52− categoryView.showHeader()
56− ListModel {
38+ Repeater {
57− id: categoryListModel
39+ model: frequentlyUsedAppsBaseModel
58− // specifies app categories, type of delegate and model used in each category
40+ delegate: Item {
59− ListElement { category: "Running apps"; component: "Apps/RunningApplicationsGrid.qml"; modelName: "RunningApplicationsModel" }
41+ Application {
60− ListElement { category: "Frequently used"; component: "Apps/ApplicationsFilterGrid.qml"; modelName: "FrequentlyUsedAppsModel" }
42+ id: application
61− ListElement { category: "Installed"; component: "Apps/ApplicationsFilterGrid.qml"; modelName: "InstalledApplicationsModel" }
43+ desktopFile: model.desktopFile
62− ListElement { category: "Available for download"; component: "Apps/ApplicationsFilterGrid.qml"; modelName: "AppsAvailableForDownloadModel" }
63− function getCategory(category1) {
64− if (category1 === "Running apps") {
65− return i18n.tr("Running apps");
67− if (category1 === "Frequently used") {
68− return i18n.tr("Frequently used");
70− if (category1 === "Installed") {
71− return i18n.tr("Installed");
73− if (category1 === "Available for download") {
45+ Component.onCompleted: {
74− return i18n.tr("Available for download");
46+ frequentlyUsedAppsModel.append({"uri": model.desktopFile, "icon": "../../graphics/applicationIcons/" + application.icon + ".png", "title": application.name, "dndUri": model.desktopFile});
80− FrequentlyUsedAppsModel { id: frequentlyUsedAppsModel }
51+ ListModel {
81− AppsAvailableForDownloadModel { id: appsAvailableForDownloadModel }
52+ id: appsAvailableForDownloadModel
83− // FIXME this should not be needed, the backend should handle all that itself
55+ AppsAvailableForDownloadModel { id: appsAvailableForDownloadBaseModel }
84− property var installedModel: null
86 Repeater {
57 Repeater {
87− model: scopeView.scope.categories
58+ model: appsAvailableForDownloadBaseModel
89 delegate: Item {
59 delegate: Item {
90− Component.onCompleted: if (categoryId == "installed") scopeView.installedModel = Qt.binding(function() { return model.results; });
60+ Application {
62+ desktopFile: model.desktopFile
64+ Component.onCompleted: {
65+ appsAvailableForDownloadModel.append({"uri": model.desktopFile, "icon": "../../graphics/applicationIcons/" + application.icon + ".png", "title": application.name, "dndUri": model.desktopFile});
94− property var categoryModels: {
70+ ListModel {
95− "FrequentlyUsedAppsModel": frequentlyUsedAppsModel,
71+ id: runningApplicationsModel
96− "InstalledApplicationsModel": installedModel,
97− "AppsAvailableForDownloadModel": appsAvailableForDownloadModel,
102− anchors.fill: parent
103− model: SortFilterProxyModel {
104− model: categoryListModel
105− filterRole: 0 // 0 == modelName
106− // FIXME: need to use invertMatch here, otherwise the filter won't update correctly
107− // if filterRegExp is set before invertMatch. Bug in SortFilterProxyModel?
108− filterRegExp: invertMatch ? ((mainStageApplicationsModel.count === 0
109− && sideStageApplicationModel.count === 0) ? RegExp("RunningApplicationsModel") : RegExp("")) :
110− RegExp("InstalledApplicationsModel")
111− invertMatch: pageHeader.searchQuery.length == 0
114− onAtYEndChanged: if (atYEnd) endReached()
115− onMovingChanged: if (moving && atYEnd) endReached()
119− highlightWhenPressed: false
129− if (modelName == "RunningApplicationsModel") {
130− item.firstModel = mainStageApplicationsModel
131− item.secondModel = sideStageApplicationModel
132− item.canEnableTerminationMode =
133− Qt.binding(function() { return isCurrent; })
135− function activateApplication(index, data) {
136− shell.activateApplication(data);
139− item.model = Qt.binding(function() { return categoryModels[modelName]; });
140− item.clicked.connect(activateApplication);
146− ListView.onRemove: SequentialAnimation {
73+ property var firstModel: mainStageApplicationsModel
147− PropertyAction {
74+ property var secondModel: sideStageApplicationModel
148− target: container; property: "ListView.delayRemove"; value: true
75+ property bool canEnableTerminationMode: Qt.binding(function() { return isCurrent; })
151− target: container; property: "height"; to: 0;
152− duration: 250; easing.type: Easing.InOutQuad
155− target: container; property: "ListView.delayRemove"; value: false
160− sectionProperty: "category"
78+ onScopeChanged: {
161− sectionDelegate: Header {
79+ scopeView.scope.categories.overrideCategory("recently-used", frequentlyUsedAppsModel);
162− width: categoryView.width
80+ scopeView.scope.categories.overrideCategory("recent", runningApplicationsModel);
163− text: categoryListModel.getCategory(section)
81+ scopeView.scope.categories.overrideCategory("more", appsAvailableForDownloadModel);
165− pageHeader: PageHeader {
167− width: categoryView.width
168− text: i18n.tr("Apps")
169− searchEntryEnabled: true
170− searchHistory: scopeView.searchHistory