2
* Copyright 2015 Canonical Ltd.
4
* This file is part of webbrowser-app.
6
* webbrowser-app is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 3.
10
* webbrowser-app is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20
import Qt.labs.settings 1.0
21
import Ubuntu.Components 1.3
22
import webbrowserapp.private 0.1
28
property QtObject bookmarksModel
29
property alias historyModel: historyTimeframeModel.sourceModel
30
property QtObject settingsObject
31
property alias selectedIndex: sections.selectedIndex
32
readonly property bool inBookmarksView: newTabViewWide.selectedIndex === 1
34
signal bookmarkClicked(url url)
35
signal bookmarkRemoved(url url)
36
signal historyEntryClicked(url url)
37
signal releasingKeyboardFocus()
39
Keys.onTabPressed: selectedIndex = (selectedIndex + 1) % 2
40
Keys.onBacktabPressed: selectedIndex = Math.abs((selectedIndex - 1) % 2)
41
onActiveFocusChanged: {
43
if (inBookmarksView) {
44
if (sections.lastFocusedBookmarksColumn === bookmarksList &&
45
bookmarksList.model.length === 0) {
46
sections.lastFocusedBookmarksColumn = folders
48
sections.lastFocusedBookmarksColumn.focus = true
50
else topSitesList.focus = true
57
sourceModel: TopSitesModel {
58
sourceModel: HistoryTimeframeModel {
59
id: historyTimeframeModel
71
objectName: "foldersList"
72
visible: inBookmarksView
74
Keys.onRightPressed: if (bookmarksList.model.length > 0) bookmarksList.focus = true
75
Keys.onDownPressed: currentIndex = Math.min(currentIndex + 1, folders.model.count - 1)
77
if (currentIndex > 0) currentIndex = Math.max(currentIndex - 1, 0)
78
else newTabViewWide.releasingKeyboardFocus()
80
onActiveFocusChanged: {
82
sections.lastFocusedBookmarksColumn = folders
83
if (currentIndex < 0) currentIndex = 0
88
top: sectionsGroup.bottom
91
topMargin: units.gu(2)
96
model: BookmarksFolderListModel {
97
sourceModel: newTabViewWide.bookmarksModel
102
objectName: "folderItem"
103
property var model: entries
104
property bool isActiveFolder: ListView.isCurrentItem
105
property bool isCurrentItem: ListView.isCurrentItem
106
property bool isAllBookmarksFolder: folder.length === 0
107
property alias name: dropArea.folderName
108
divider.visible: false
110
property bool isCurrentDropTarget: dropArea.containsDrag && dropArea.drag.source.folder !== folder
111
color: isCurrentDropTarget ? "green" :
112
((folders.activeFocus && isActiveFolder) ? Qt.rgba(0, 0, 0, 0.05) : "transparent")
115
anchors.verticalCenter: parent.verticalCenter
116
anchors.left: parent.left
117
anchors.right: parent.right
118
anchors.leftMargin: units.gu(2)
119
anchors.rightMargin: units.gu(2)
121
fontSize: isAllBookmarksFolder ? "medium" : "small"
122
text: isAllBookmarksFolder ? i18n.tr("All Bookmarks") : folderItem.name
123
color: isActiveFolder ? UbuntuColors.orange : UbuntuColors.darkGrey
126
onClicked: folders.currentIndex = index
131
property string folderName: folder
137
flickableItem: folders
142
objectName: "bookmarksList"
144
top: sectionsGroup.bottom
145
bottom: parent.bottom
148
topMargin: units.gu(2)
150
visible: inBookmarksView
151
onActiveFocusChanged: if (activeFocus) sections.lastFocusedBookmarksColumn = bookmarksList
153
// Build a temporary model for the bookmarks list that includes, when
154
// necessary, the homepage bookmark as a fixed first item in the list
156
if (!folders.currentItem) return null
159
if (folders.currentItem.isAllBookmarksFolder) items.push({
160
title: i18n.tr("Homepage"),
161
url: newTabViewWide.settingsObject.homepage,
165
if (!folders.currentItem.model) return null
166
for (var i = 0; i < folders.currentItem.model.count; i++) {
167
items.push(folders.currentItem.model.get(i))
174
delegate: DraggableUrlDelegateWide {
175
objectName: "bookmarkItem"
178
title: modelData.title
179
icon: modelData.icon ? modelData.icon : ""
182
property string folder: modelData.folder
183
property bool isHomeBookmark: folder === "" && index === 0
185
removable: !isHomeBookmark
186
draggable: !isHomeBookmark && contentItem.x === 0
187
highlighted: bookmarksList.activeFocus && ListView.isCurrentItem
189
onClicked: newTabViewWide.bookmarkClicked(url)
190
onRemoved: newTabViewWide.bookmarkRemoved(url)
192
// Larger margin to prevent interference from Scrollbar hovering area
193
gripMargin: units.gu(4)
195
// Remove interactivity to prevent the list from scrolling
196
// while dragging near its margins. This ensures we can correctly
197
// return the item to its original position on a failed drop.
198
bookmarksList.interactive = false
200
// Relinquish focus as the presses and releases that compose the
201
// drag will move the keyboard focus in a location unexpected
202
// for the user. This way it will go back to the address bar and
203
// the user can predictably resume keyboard interaction from there.
204
newTabViewWide.releasingKeyboardFocus()
207
bookmarksList.interactive = true
209
if (dragAndDrop.target && dragAndDrop.target.folderName !== folder) {
210
bookmarksModel.update(modelData.url, modelData.title,
211
dragAndDrop.target.folderName)
212
dragAndDrop.success = true
217
Keys.onReturnPressed: newTabViewWide.bookmarkClicked(currentItem.url)
218
Keys.onDeletePressed: {
219
if (currentItem.removable) {
220
newTabViewWide.bookmarkRemoved(currentItem.url)
221
if (bookmarksList.model.length === 0) folders.focus = true
224
Keys.onLeftPressed: folders.focus = true
225
Keys.onDownPressed: currentIndex = Math.min(currentIndex + 1, model.length - 1)
227
if (currentIndex > 0) currentIndex = Math.max(currentIndex - 1, 0)
228
else newTabViewWide.releasingKeyboardFocus()
233
flickableItem: bookmarksList
238
objectName: "topSitesList"
240
top: sectionsGroup.bottom
241
bottom: parent.bottom
244
topMargin: units.gu(2)
247
visible: !inBookmarksView
251
delegate: UrlDelegateWide {
252
objectName: "topSiteItem"
258
highlighted: topSitesList.activeFocus && ListView.isCurrentItem
260
onClicked: newTabViewWide.historyEntryClicked(url)
261
onRemoved: newTabViewWide.historyModel.hide(url)
264
Keys.onReturnPressed: newTabViewWide.historyEntryClicked(currentItem.url)
265
Keys.onDeletePressed: {
266
newTabViewWide.historyModel.hide(currentItem.url)
267
if (topSitesList.model.count === 0) newTabViewWide.releasingKeyboardFocus()
269
Keys.onDownPressed: currentIndex = Math.min(currentIndex + 1, model.count - 1)
271
if (currentIndex > 0) currentIndex = Math.max(currentIndex - 1, 0)
272
else newTabViewWide.releasingKeyboardFocus()
277
flickableItem: topSitesList
288
height: sections.height
292
objectName: "sections"
296
leftMargin: units.gu(1)
299
selectedIndex: settingsObject.newTabDefaultSection
300
onSelectedIndexChanged: {
301
settingsObject.newTabDefaultSection = selectedIndex
302
if (selectedIndex === 0) topSitesList.focus = true
304
if (lastFocusedBookmarksColumn) lastFocusedBookmarksColumn.focus = true
305
else folders.focus = true
309
property var lastFocusedBookmarksColumn: folders
312
Action { text: i18n.tr("Top sites") },
313
Action { text: i18n.tr("Bookmarks") }