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 || scope.activationInProgress) : 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  DashPageHeader {
53  id: header
54  objectName: "pageHeader"
55  title: i18n.tr("Manage")
56  width: parent.width
57  clip: true
58  showBackButton: true
59  backIsClose: root.state == "edit"
60  storeEntryEnabled: root.state == "browse"
61  searchEntryEnabled: false
62  scopeStyle: root.scopeStyle
63  onBackClicked: {
64  if (backIsClose) {
65  root.state = "browse"
66  } else {
67  root.backClicked()
68  }
69  }
70  onStoreClicked: root.storeClicked();
71  z: 1
72  }
73 
74  Flickable {
75  objectName: "scopesListFlickable"
76  anchors {
77  top: header.bottom
78  bottom: parent.bottom
79  left: parent.left
80  right: parent.right
81  }
82  clip: true
83  contentWidth: root.width
84  contentHeight: column.height
85  onContentHeightChanged: returnToBounds();
86  Column {
87  id: column
88  Repeater {
89  model: scope ? scope.categories : null
90 
91  delegate: Loader {
92  asynchronous: true
93  width: root.width
94  active: results.count > 0
95  visible: active
96  sourceComponent: ScopesListCategory {
97  objectName: "scopesListCategory" + categoryId
98 
99  model: results
100 
101  title: {
102  if (isFavoritesFeed) return i18n.tr("Home");
103  else if (isAlsoInstalled) return i18n.tr("Also installed");
104  else return name;
105  }
106 
107  editMode: root.state == "edit"
108 
109  scopeStyle: root.scopeStyle
110  isFavoritesFeed: categoryId == "favorites"
111  isAlsoInstalled: categoryId == "other"
112 
113  onRequestFavorite: root.requestFavorite(scopeId, favorite);
114  onRequestEditMode: root.state = "edit";
115  onRequestScopeMoveTo: root.requestFavoriteMoveTo(scopeId, index);
116  onRequestActivate: root.scope.activate(result, categoryId);
117  onRequestRestore: root.requestRestore(scopeId);
118  }
119  }
120  }
121  }
122  }
123 }