Unity 8
ScopesList.qml
1 /*
2  * Copyright (C) 2014 Canonical, Ltd.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 3.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 import QtQuick 2.4
18 import Ubuntu.Components 1.3
19 import Dash 0.1
20 import "../Components"
21 
22 Item {
23  id: root
24 
25  // Properties set by parent
26  property var scope: null
27 
28  // Properties used by parent
29  readonly property bool processing: scope ? (scope.searchInProgress || scope.activationInProgress) : false
30 
31  // Signals
32  signal backClicked()
33  signal storeClicked()
34  signal requestFavorite(string scopeId, bool favorite)
35  signal requestFavoriteMoveTo(string scopeId, int index)
36  signal requestRestore(string scopeId)
37 
38  state: "browse"
39 
40  property var scopeStyle: ScopeStyle {
41  }
42 
43  onStateChanged: {
44  if (state == "edit") {
45  // As per design entering edit mode clears the possible existing search
46  header.resetSearch(false /* false == unfocus */);
47  }
48  }
49 
50  DashBackground {
51  anchors.fill: parent
52  }
53 
54  DashPageHeader {
55  id: header
56  objectName: "pageHeader"
57  title: i18n.tr("Manage")
58  width: parent.width
59  clip: true
60  showBackButton: true
61  backIsClose: root.state == "edit"
62  storeEntryEnabled: root.state == "browse"
63  searchEntryEnabled: false
64  scopeStyle: root.scopeStyle
65  onBackClicked: {
66  if (backIsClose) {
67  root.state = "browse"
68  } else {
69  root.backClicked()
70  }
71  }
72  onStoreClicked: root.storeClicked();
73  z: 1
74  }
75 
76  Flickable {
77  objectName: "scopesListFlickable"
78  anchors {
79  top: header.bottom
80  bottom: parent.bottom
81  left: parent.left
82  right: parent.right
83  }
84  clip: true
85  contentWidth: root.width
86  contentHeight: column.height
87  onContentHeightChanged: returnToBounds();
88  Column {
89  id: column
90  Repeater {
91  model: scope ? scope.categories : null
92 
93  delegate: Loader {
94  asynchronous: true
95  width: root.width
96  active: results.count > 0
97  visible: active
98  sourceComponent: ScopesListCategory {
99  objectName: "scopesListCategory" + categoryId
100 
101  model: results
102 
103  title: {
104  if (isFavoritesFeed) return i18n.tr("Home");
105  else if (isAlsoInstalled) return i18n.tr("Also installed");
106  else return name;
107  }
108 
109  editMode: root.state == "edit"
110 
111  scopeStyle: root.scopeStyle
112  isFavoritesFeed: categoryId == "favorites"
113  isAlsoInstalled: categoryId == "other"
114 
115  onRequestFavorite: root.requestFavorite(scopeId, favorite);
116  onRequestEditMode: root.state = "edit";
117  onRequestScopeMoveTo: root.requestFavoriteMoveTo(scopeId, index);
118  onRequestActivate: root.scope.activate(result, categoryId);
119  onRequestRestore: root.requestRestore(scopeId);
120  }
121  }
122  }
123  }
124  }
125 }