-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utils.js
242 lines (122 loc) · 3.63 KB
/
Utils.js
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/**
* @author rafael
*/
function extend(subclass, superclass) { //method that implements inheritance
function Dummy(){}
Dummy.prototype = superclass.prototype;
subclass.prototype = new Dummy();
subclass.prototype.constructor = subclass;
subclass.superclass = superclass;
subclass.superproto = superclass.prototype;
}
function cropString(str,limite){
var resul = str.substring(0,limite);
resul +="...";
return resul;
}
function sql(query){
var result = Amarok.Collection.query(query);
return result;
}
function addListItem(list,item,font,icon){
//item.setFont(font);
list.addItem(item);
}
function loadWindow(file){ ////reads file UI file and creates a window
var loader = new QUiLoader(Amarok.Window);
var ui_file = new QFile(Amarok.Info.scriptPath() + "/"+file, loader);
ui_file.open( QIODevice.ReadOnly );
var window = loader.load(ui_file, Amarok.Window);
ui_file.close();
return window;
}
function loadWidget(file,parent){
var loader = new QUiLoader();
var ui_file = new QFile(Amarok.Info.scriptPath()+ "/"+file, loader);
ui_file.open(QIODevice.ReadOnly);
var widget = loader.load(ui_file,parent);
ui_file.close();
return widget;
}
function createArrayOfTracks(queryResult,ncols){
var resultArray = new Array();
for(var i = 0; i < queryResult.length; i++){
if(i == 0 || i%ncols == 0){
var id = queryResult[i];
var URL = queryResult[i+1];
var title = queryResult[i+2];
var artistid = queryResult[i+3];
var artist = queryResult[i+4];
var albumid = queryResult[i+5];
var albumname = queryResult[i+6];
var genrename = queryResult[i+7];
var year = queryResult[i+8];
var image = queryResult[i+9];
if(image == ""){
image = Amarok.Info.scriptPath() + "/nocover.png";
}
resultArray.push(
new Track(id,URL,title,artistid,artist,albumid,albumname,genrename,year,image)
);
}
}
return resultArray;
}
Array.prototype.clear=function() //cria novo metodo para tipo interno Array
{
this.length = 0; //limpa array
}
/////////////MATH//////////////
function degreeToRadian(degree){
return degree * (Math.PI/180);
}
function radianToDegree(radian){
return radian * (180/Math.PI);
}
///////////////////////////////
/////////////QUICK SORT/////////////
var pivot = new Object();
function q_sort1(array, left, right){ //sorts an array of objects (name, value)
var l_hold = left;
var r_hold = right;
pivot.value = array[left].value;
pivot.name = array[left].name;
pivot.id = array[left].id;
while (left < right) {
while ((array[right].value>=pivot.value) && (left<right)) {
right--;
}
if (left != right){
array[left].value = array[right].value;
array[left].name = array[right].name;
array[left].id = array[right].id;
left++;
}
while ((array[left].value<=pivot.value) && (left<right)) {
left++;
}
if (left != right) {
array[right].value = array[left].value;
array[right].name = array[left].name;
array[right].id = array[left].id;
right--;
}
}
array[left].value = pivot.value;
array[left].name = pivot.name;
array[left].id = pivot.id;
pivot.value = left;
left = l_hold;
right = r_hold;
if (left < pivot.value) q_sort1(array, left, pivot.value-1);
if (right > pivot.value) q_sort1(array, pivot.value+1, right);
}
function quickSort(array,type){
if (type == 1) {
q_sort1(array, 0, array.length - 1);
}
else
if (type == 2) {
q_sort2(array, 0, array.length - 1);
}
}