-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathabc_import.qml
142 lines (129 loc) · 4.37 KB
/
abc_import.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
//=============================================================================
//
// ABC Import Plugin
// Based on ABC Import by Nicolas Froment (lasconic)
// Copyright (2013) Stephane Groleau (vgstef)
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//=============================================================================
import QtQuick 2.1
import QtQuick.Dialogs 1.0
import QtQuick.Controls 1.0
import MuseScore 1.0
import FileIO 1.0
MuseScore {
menuPath: "Plugins.ABC Import"
version: "2.0"
description: qsTr("This plugin imports et converts ABC text from a file or the clipboard.")
pluginType: "dialog"
id:window
width: 800; height: 500;
onRun: {}
FileIO {
id: myFileAbc
onError: console.log(msg + " Filename = " + myFileAbc.source)
}
FileIO {
id: myFile
source: tempPath() + "/my_file.xml"
onError: console.log(msg)
}
FileDialog {
id: fileDialog
title: qsTr("Please choose a file")
onAccepted: {
var filename = fileDialog.fileUrl
//console.log("You chose: " + filename)
if(filename){
myFileAbc.source = filename
//read abc file and put it in the TextArea
abcText.text = myFileAbc.read()
}
}
}
Label {
id: textLabel
wrapMode: Text.WordWrap
text: qsTr("Paste your ABC tune here (or click button to load a file)\nYou need to be connected to internet for this plugin to work")
font.pointSize:12
anchors.left: window.left
anchors.top: window.top
anchors.leftMargin: 10
anchors.topMargin: 10
}
// Where people can paste their ABC tune or where an ABC file is put when opened
TextArea {
id:abcText
anchors.top: textLabel.bottom
anchors.left: window.left
anchors.right: window.right
anchors.bottom: buttonOpenFile.top
anchors.topMargin: 10
anchors.bottomMargin: 10
anchors.leftMargin: 10
anchors.rightMargin: 10
width:parent.width
height:400
wrapMode: TextEdit.WrapAnywhere
textFormat: TextEdit.PlainText
}
Button {
id : buttonOpenFile
text: qsTr("Open file")
anchors.bottom: window.bottom
anchors.left: abcText.left
anchors.topMargin: 10
anchors.bottomMargin: 10
anchors.leftMargin: 10
onClicked: {
fileDialog.open();
}
}
Button {
id : buttonConvert
text: qsTr("Import")
anchors.bottom: window.bottom
anchors.right: abcText.right
anchors.topMargin: 10
anchors.bottomMargin: 10
anchors.rightMargin: 10
onClicked: {
var content = "content=" + encodeURIComponent(abcText.text)
//console.log("content : " + content)
var request = new XMLHttpRequest()
request.onreadystatechange = function() {
if (request.readyState == XMLHttpRequest.DONE) {
var response = request.responseText
//console.log("responseText : " + response)
myFile.write(response)
readScore(myFile.source)
Qt.quit()
}
}
request.open("POST", "http://abc2xml.appspot.com/abcrenderer", true)
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
request.send(content)
}
}
Button {
id : buttonCancel
text: qsTr("Cancel")
anchors.bottom: window.bottom
anchors.right: buttonConvert.left
anchors.topMargin: 10
anchors.bottomMargin: 10
onClicked: {
Qt.quit();
}
}
}