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