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.3
18 import Dash 0.1
19 
20 Item {
21  id: root
22 
23  // Properties set by parent
24  property var scope: null
25 
26  // Properties used by parent
27  readonly property bool processing: scope ? scope.searchInProgress : false
28 
29  // Signals
30  signal backClicked()
31  signal storeClicked()
32  signal requestFavorite(string scopeId, bool favorite)
33  signal requestFavoriteMoveTo(string scopeId, int index)
34 
35  state: "browse"
36 
37  property var scopeStyle: ScopeStyle {
38  }
39 
40  onStateChanged: {
41  if (state == "edit") {
42  // As per design entering edit mode clears the possible existing search
43  header.resetSearch(false /* false == unfocus */);
44  }
45  }
46 
47  DashBackground {
48  anchors.fill: parent
49  }
50 
51  Binding {
52  target: root.scope
53  property: "searchQuery"
54  value: header.searchQuery
55  }
56 
57  Binding {
58  target: header
59  property: "searchQuery"
60  value: root.scope ? root.scope.searchQuery : ""
61  }
62 
63  PageHeader {
64  id: header
65  objectName: "pageHeader"
66  title: i18n.tr("Manage")
67  width: parent.width
68  clip: true
69  showBackButton: true
70  backIsClose: root.state == "edit"
71  storeEntryEnabled: root.state == "browse"
72  searchEntryEnabled: false // Disable search for now
73  scopeStyle: root.scopeStyle
74  onBackClicked: {
75  if (backIsClose) {
76  root.state = "browse"
77  } else {
78  root.backClicked()
79  }
80  }
81  onStoreClicked: root.storeClicked();
82  z: 1
83  }
84 
85  Flickable {
86  anchors {
87  top: header.bottom
88  bottom: parent.bottom
89  left: parent.left
90  right: parent.right
91  }
92  clip: true
93  contentWidth: root.width
94  contentHeight: column.height
95  onContentHeightChanged: returnToBounds();
96  Column {
97  id: column
98  Repeater {
99  model: scope ? scope.categories : null
100 
101  delegate: Loader {
102  asynchronous: true
103  width: root.width
104  active: results.count > 0
105  visible: active
106  sourceComponent: ScopesListCategory {
107  objectName: "scopesListCategory" + categoryId
108 
109  model: results
110 
111  title: {
112  if (isFavoritesFeed) return i18n.tr("Home");
113  else if (isAlsoInstalled) return i18n.tr("Also installed");
114  else return name;
115  }
116 
117  editMode: root.state == "edit"
118 
119  scopeStyle: root.scopeStyle
120  isFavoritesFeed: categoryId == "favorites"
121  isAlsoInstalled: categoryId == "other"
122 
123  onRequestFavorite: root.requestFavorite(scopeId, favorite);
124  onRequestEditMode: root.state = "edit";
125  onRequestScopeMoveTo: root.requestFavoriteMoveTo(scopeId, index);
126  onRequestActivate: root.scope.activate(result);
127  }
128  }
129  }
130  }
131  }
132 }