-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.qml
174 lines (146 loc) · 4.25 KB
/
Main.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
import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Window 2.2
import QtQuick.Dialogs 1.2
import QtQuick.Layouts 1.1
import QtQuick.Controls.Styles 1.4
import eswarm.DirWatcher 1.0
ApplicationWindow {
title: qsTr("AutoSortD")
width: 480
height: 640
color: "#2196f3"
visible: true
property int margin : 10;
ColumnLayout {
id: mainColumn
anchors.margins: margin
anchors.fill : parent
Layout.minimumHeight: 480
Layout.minimumWidth: 640
ColumnLayout {
id: col
anchors.horizontalCenter: parent.horizontalCenter
Layout.fillWidth: true
anchors.top: parent.top
anchors.right: parent.right
Label {
color: "#ffffff"
text : "Folders to auto sort"
font.pointSize: 16
anchors.horizontalCenter: parent.horizontalCenter
}
ColumnLayout {
id : folderLayout
}
Button {
text : "Add folder"
anchors.horizontalCenter: parent.horizontalCenter
style: CustButtonStyle{}
onClicked: fileDialog.open()
}
}
Label {
color: "#ffffff"
text : "Changes Made"
font.pointSize: 16
anchors.horizontalCenter: parent.horizontalCenter
}
TextArea {
id: changesText
Layout.fillHeight: true
Layout.fillWidth: true
anchors.margins: 10
readOnly: true
}
Button {
text : "clear"
anchors.horizontalCenter: parent.horizontalCenter
style: CustButtonStyle {}
}
}
Component.onCompleted: {
refreshFolderRows();
}
Connections {
target: DirWatcher
onTextChanged: {
changesText.text += msg
}
}
function sort() {
DirWatcher.startSort();
}
// Destroy everything and create everything
// Not efficient, but there should not be a lot of folders
// being monitored.
function refreshFolderRows() {
var folders = DirWatcher.getFolders();
// Destroy everything.
for(var i = 0; i <folderLayout.children.length; i++) {
folderLayout.children[i].destroy();
}
var folderRowComp;
folderRowComp = Qt.createComponent("FolderRow.qml");
if( folderRowComp.status != Component.Ready )
{
if( folderRowComp.status == Component.Error )
console.debug("Error:"+ folderRowComp.errorString() );
return; // or maybe throw
}
// Create everything.
for(var f in folders)
{
var folderRowObj;
folderRowObj = folderRowComp.createObject(folderLayout, { "text" : folders[f] });
if (folderRowObj == null) {
// Error Handling
console.log("Error creating object");
return;
}
folderRowObj.remove.connect(removeFolderRow)
}
sort();
}
function removeFolderRow(path)
{
DirWatcher.removeFromSettings(path);
refreshFolderRows();
}
function addFolderRow(path)
{
DirWatcher.addToSettings(path);
refreshFolderRows();
}
function printObject(obj) {
for (var p in obj) {
if (obj.hasOwnProperty(p)) {
console.log( p + '::' + obj[p] + '\n');
}
}
}
FileDialog {
id: fileDialog
title: "Please choose a folder"
folder: shortcuts.home
selectFolder: true
onAccepted: {
var path = fileDialog.fileUrl.toString();
// remove prefixed "file:///"
path = path.replace(/^(file:\/{3})|(qrc:\/{2})|(http:\/{2})/,"");
// unescape html codes like '%23' for '#'
var cleanPath = decodeURIComponent(path);
//Qt.quit()
addFolderRow(cleanPath)
}
onRejected: {
console.log("Canceled")
//Qt.quit()
}
// Component.onCompleted: visible = true
}
function launchFileDialog()
{
DirWatcher.launchFileDialog();
}
}