Fully migrate the settings to Qt.labs.settings

This commit is contained in:
nikwen.developer@gmail.com
2014-09-01 11:33:01 +00:00
parent 945f63aa92
commit 3a5fd5ca11
4 changed files with 46 additions and 247 deletions

View File

@@ -29,6 +29,7 @@ import QtQuick 2.2
import Ubuntu.Components 1.1
import Ubuntu.Components.ListItems 1.0 as ListItem
import Ubuntu.Components.Popups 1.0
import Qt.labs.settings 1.0
import 'qrc:/qml/cantata/components'
Item {
@@ -113,8 +114,7 @@ Item {
Connections {
target: backend
onCurrentSongPlayqueuePositionChanged: {
var uiContents = settingsBackend.getUiContents()
if (uiContents !== undefined && uiContents["playQueueScroll"]) {
if (settingsBackend.scrollPlayQueue) {
playqueueListView.positionViewAtIndex(backend.getCurrentSongPlayqueuePosition(), ListView.Contain)
}
}

View File

@@ -27,66 +27,30 @@
import QtQuick 2.2
import Ubuntu.Components 1.1
import U1db 1.0 as U1db
import Qt.labs.settings 1.0
import 'qrc:/qml/cantata/'
Item {
signal fetchCoversChanged()
readonly property alias uiSettings: uiSettings
U1db.Database {
id: db
path: appDir + "/u1db"
readonly property alias scrollPlayQueue: uiSettings.scrollPlayQueue
readonly property alias fetchCovers: uiSettings.fetchCovers
Component.onCompleted: {
backend.setCoverFetch(fetchCovers)
}
U1db.Document {
id: uiDocument
database: db
docId: 'ui'
create: true
defaults: {
"playQueueScroll": true,
"coverFetch": true,
"artistYear": true,
"hiddenViews": ["folders"],
"albumSort": "album-artist"
}
onContentsChanged: {
if (contents != undefined) {
backend.setCoverFetch(contents["coverFetch"])
fetchCoversChanged()
}
}
onFetchCoversChanged: {
backend.setCoverFetch(fetchCovers)
}
U1db.Document {
id: connectionDocument
database: db
docId: 'connections'
create: true
defaults: {
"host": "",
"port": "",
"password": "",
"musicfolder": ""
}
}
Settings {
id: uiSettings
function getUiContents() {
return uiDocument.contents
}
function setUiContents(contents) {
uiDocument.contents = contents
}
function getConnectionContents() {
return connectionDocument.contents
}
function setConnectionContents(contents) {
connectionDocument.contents = contents
category: "ui"
property bool scrollPlayQueue: true
property bool fetchCovers: true
}
}

View File

@@ -28,7 +28,6 @@
import QtQuick 2.2
import Ubuntu.Components 1.1
import Ubuntu.Components.ListItems 1.0 as ListItem
//import U1db 1.0 as U1db
import Qt.labs.settings 1.0
Flickable {
@@ -51,7 +50,7 @@ Flickable {
tryToConnect()
}
Settings {
Settings { //Here as it is not needed anywhere else (easier here)
id: settings
category: "connection"
property alias host: hostTextField.text

View File

@@ -2,6 +2,7 @@
** Cantata
**
** Copyright (c) 2014 Craig Drummond <craig.p.drummond@gmail.com>
** Copyright (c) 2014 Niklas Wenzel <nikwen.developer@gmail.com>
**
** $QT_BEGIN_LICENSE:GPL$
** This program is free software; you can redistribute it and/or modify
@@ -27,242 +28,77 @@
import QtQuick 2.2
import Ubuntu.Components 1.1
import Ubuntu.Components.ListItems 1.0 as ListItem
import U1db 1.0 as U1db
import Qt.labs.settings 1.0
Flickable {
clip: true
contentHeight: column.height
Column { //TODO: Find better solution for spacing
Column {
id: column
spacing: units.gu(1)
height: childrenRect.height
anchors.horizontalCenter: parent.horizontalCenter
Component.onCompleted: {
fillWithU1dbData()
}
function arrayContains(container, element) {
for (var i = 0; i < container.length; i++) {
if (container[i] === element) {
return true
}
}
return false
}
function fillWithU1dbData() {
// TODO: albumSort
var contents = settingsBackend.getUiContents()
if (contents !== undefined) {
// artistYear.checked = contents["artistYear"]
coverFetch.checked = contents["coverFetch"]
playQueueScroll.checked = contents["playQueueScroll"]
// albumsView.checked = !arrayContains(contents["hiddenViews"], "albums")
// foldersView.checked = !arrayContains(contents["hiddenViews"], "folders")
// playlistsView.checked = !arrayContains(contents["hiddenViews"], "playlists")
} else {
// artistYear.checked = false
coverFetch.checked = true
playQueueScroll.checked = true
// albumsView.checked = true
// foldersView.checked = true
// playlistsView.checked = true
}
}
function saveDataToU1db() {
var contents = {};
// contents["artistYear"] = artistYear.checked
contents["coverFetch"] = coverFetch.checked
contents["playQueueScroll"] = playQueueScroll.checked
// contents["hiddenViews"] = []
// if (!albumsView.checked) contents["hiddenViews"].push("albums")
// if (!foldersView.checked) contents["hiddenViews"].push("folders")
// if (!playlistsView.checked) contents["hiddenViews"].push("playlists")
// TODO: albumSort
settingsBackend.setUiContents(contents)
}
Item {
id: topSpacer
height: units.gu(2)
width: parent.width
}
// UbuntuShape {
// id: notReadyShape
// width: parent.width
// height: isPhone?notReadyLabel.height + 2 * notReadyLabel.anchors.margins:0
// color: "#88CCCCCC"
// visible: isPhone
// Label {
// id: notReadyLabel
// text: i18n.tr("Not all functionality on this page has been implemented yet, partly due to constraints of the Ubuntu SDK.")
// wrapMode: Text.Wrap
// anchors {
// top: parent.top
// right: parent.right
// left: parent.left
// margins: units.gu(1)
// }
// }
// }
// Item {
// id: notReadySpacer
// height: units.gu(2)
// width: parent.width
// }
Grid {
anchors.horizontalCenter: parent.horizontalCenter
columns: 2
rowSpacing: units.gu(2)
columnSpacing: parent.width/10
height: childrenRect.height
//width: aboutTabLayout.width*0.25
//height: iconTabletItem.height*0.75
Component.onCompleted: {
for (var i = 0; i < children.length; i++) {
if (children[i].checked !== undefined) { //Is CheckBox
children[i].onCheckedChanged.connect(column.saveDataToU1db)
}
}
}
Component.onDestruction: {
for (var i = 0; i < children.length; i++) {
if (children[i].checked !== undefined) { //Is CheckBox
children[i].onCheckedChanged.disconnect(column.saveDataToU1db) //Needed when created dynamically
}
}
}
Label {
id: playQueueScrollLabel
id: scrollPlayQueueLabel
text: i18n.tr("Scroll play queue to active track:")
fontSize: "medium"
verticalAlignment: Text.AlignVCenter
height: playQueueScroll.height
height: scrollPlayQueueCheckBox.height
}
CheckBox {
id: playQueueScroll
id: scrollPlayQueueCheckBox
checked: true
KeyNavigation.priority: KeyNavigation.BeforeItem
KeyNavigation.tab: coverFetch
KeyNavigation.tab: fetchCoversCheckBox
Component.onCompleted: {
scrollPlayQueueCheckBox.checked = settingsBackend.scrollPlayQueue
}
onCheckedChanged: {
settingsBackend.uiSettings.scrollPlayQueue = scrollPlayQueueCheckBox.checked
}
}
Label {
id: coverFetchLabel
id: fetchCoversLabel
text: i18n.tr("Fetch missing covers from last.fm:")
fontSize: "medium"
verticalAlignment: Text.AlignVCenter
height: coverFetch.height
height: fetchCoversCheckBox.height
}
CheckBox {
id: coverFetch
id: fetchCoversCheckBox
checked: true
KeyNavigation.priority: KeyNavigation.BeforeItem
// KeyNavigation.tab: artistYear
KeyNavigation.backtab: playQueueScroll
KeyNavigation.backtab: scrollPlayQueueCheckBox
Component.onCompleted: {
fetchCoversCheckBox.checked = settingsBackend.fetchCovers
}
onCheckedChanged: {
settingsBackend.uiSettings.fetchCovers = fetchCoversCheckBox.checked
}
}
//I don't see the point of implementing these options.
//Too many options, which nearly no user will miss if they aren't there, aren't good for phone (!) apps in my opinion.
//If we once implement options to adjust the order in which list items are shown, it will in my opinion be easier for the user if the options are shown on the page the list is on.
// Label {
// id: artistYearLabel
// text: i18n.tr("Sort albums in artists view by year:")
// fontSize: "medium"
// verticalAlignment: Text.AlignVCenter
// height: artistYear.height
// }
// CheckBox {
// id: artistYear
// KeyNavigation.priority: KeyNavigation.BeforeItem
// KeyNavigation.tab: albumsView
// KeyNavigation.backtab: coverFetch
// enabled: false
// }
// Label {
// id: albumsViewLabel
// text: i18n.tr("Show albums view:")
// fontSize: "medium"
// verticalAlignment: Text.AlignVCenter
// height: albumsView.height
// }
// CheckBox {
// id: albumsView
// KeyNavigation.priority: KeyNavigation.BeforeItem
// KeyNavigation.tab: foldersView
// KeyNavigation.backtab: coverFetch
// enabled: false
// }
// Label {
// id: foldersViewLabel
// text: i18n.tr("Show folders view:")
// fontSize: "medium"
// verticalAlignment: Text.AlignVCenter
// height: foldersView.height
// }
// CheckBox {
// id: foldersView
// KeyNavigation.priority: KeyNavigation.BeforeItem
// KeyNavigation.tab: albumSort
// KeyNavigation.backtab: playlistsView
// enabled: false
// }
// Label {
// id: playlistsViewLabel
// text: i18n.tr("Show playlists view:")
// fontSize: "medium"
// verticalAlignment: Text.AlignVCenter
// height: playlistsView.height
// }
// CheckBox {
// id: playlistsView
// KeyNavigation.priority: KeyNavigation.BeforeItem
// KeyNavigation.tab: albumSort
// KeyNavigation.backtab: foldersView
// enabled: false
// }
// }
// Item {
// id: spacer
// height: units.gu(1)
// width: parent.width
// }
// OptionSelector {
// id: albumSort
// text: i18n.tr("Sort albums in albums view by:")
// model: [ i18n.tr("Album, Artist, Year"),
// i18n.tr("Album, Year, Artist"),
// i18n.tr("Artist, Album, Year"),
// i18n.tr("Artist, Year, Album"),
// i18n.tr("Year, Album, Artist"),
// i18n.tr("Year, Artist, Album") ]
// width: parent.width
// selectedIndex: 0
// KeyNavigation.priority: KeyNavigation.BeforeItem
// KeyNavigation.backtab: foldersView
// enabled: false
}
Item {