This repository has been archived by the owner on Dec 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Page1.qml
190 lines (165 loc) · 5.19 KB
/
Page1.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import QtQuick 2.7
import QtQuick.Controls 2.2
import QtQuick.Dialogs 1.2
import QtQuick.Controls 1.4
import Qt.labs.platform 1.0
Page1Form {
property alias messageDialog: messageDialog
property alias searchResults: searchResults
property var currentCategory: {}
objectName: "page1Form"
contentWidth: parent.width;
contentHeight: parent.height;
ListModel {
id: cddbSearchResultsModel
}
ListModel {
id: cddbAlbumModel
}
FolderDialog {
id: folderDialog
title: qsTr("Please choose a directory.")
options: FolderDialog.ShowDirsOnly
currentFolder: "file://" + QtCdParanoia.getMusicHome();
onAccepted: {
musicHome.text = folder.toString().replace(/^file:\/\//, '');
}
onRejected: {
musicHome.text = "";
}
}
pickMusicHome.onClicked: {
musicHome.text = "";
folderDialog.open();
}
freedbResults.onLinkActivated: {
Qt.openUrlExternally(link);
}
driveScanButton.onClicked: {
cddbSearchResultsModel.clear();
artistName.text = "";
titleName.text = "";
cddbAlbumModel.clear();
importStatus.text = "\n\n\n\n\n";
QtCdParanoia.scanForDrive();
}
importMusic.onClicked: {
if (musicHome.text === ""
|| musicHome.text === "Select Music Home Directory.") {
message("No music home directory.",
"Please choose a music home directory.");
return;
}
var importData = {
"dest_root_dir": musicHome.text,
"dest_artist_dir": artistName.text,
"dest_album_dir": titleName.text,
"tracks": {}
};
var i = 0;
var track = {};
var track_num = 0;
for (; i<cddbAlbumModel.count; i++) {
track = cddbAlbumModel.get(i);
track_num = i + 1;
importData.tracks = Object.defineProperty(
importData.tracks,
i.toString(),
{
enumerable: true,
value: {
"track_num": track_num,
"title": track.title
}
}
);
}
QtCdParanoia.writeTracks(importData);
}
cancelImportMusic.onClicked: {
QtCdParanoia.cancelImport();
}
MessageDialog {
id: messageDialog
objectName: "messageDialog"
title: qsTr("Warning")
buttons: MessageDialog.Close
Component.onCompleted: visible = false
onYesClicked: {
updateArtistTitleTracks(searchResults.current);
}
onCancelClicked: {
currentCategory.checked = true;
}
}
Connections {
target: QtCdParanoia
onErrorMessage: message(text, detailedText)
}
function message(text, detailedText) {
messageDialog.text = text;
messageDialog.detailedText = detailedText;
messageDialog.buttons = MessageDialog.Close
messageDialog.open();
}
function getAlbum(category) {
var getAlbumResult = {};
var item = {};
for(var i=0; i<cddbSearchResultsModel.count; i++) {
item = cddbSearchResultsModel.get(i);
if (category === item.category) {
getAlbumResult = {
"artist": item.artist,
"title": item.title,
"category": item.category
}
}
}
return getAlbumResult;
}
ExclusiveGroup {
id: searchResults
onCurrentChanged: {
if (current && noAlbumSelected()) {
updateArtistTitleTracks(current);
} else if (currentCategory.objectName !== current.objectName ) {
askDeleteArtistTitleTracks();
}
}
}
function noAlbumSelected() {
if (artistName.text.length === 0 &&
titleName.text.length === 0 &&
cddbAlbumModel.count === 0) {
return true;
} else {
return false;
}
}
function updateArtistTitleTracks(current) {
currentCategory = current;
var category = current.objectName;
var item = getAlbum(category);
cddbAlbumModel.clear();
QtCdParanoia.listTracks(item.category);
if (item !== {}) {
artistName.text = item.artist;
titleName.text = item.title;
}
}
function askDeleteArtistTitleTracks() {
messageDialog.text = "Discard edits?";
messageDialog.informativeText = "Changing the selected album will"
+ " discard any edits to Artist, Title, and track titles.";
messageDialog.buttons = MessageDialog.Yes | MessageDialog.Cancel
messageDialog.open();
}
importStatusView.onContentHeightChanged: {
scrollDown();
}
function scrollDown() {
importStatusView.contentY = importStatus.contentHeight -
importStatusView.height + importStatus.padding + 12;
importStatusView.forceActiveFocus();
}
}