This repository has been archived by the owner on Jun 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCustomFileDialog.qml
109 lines (87 loc) · 3 KB
/
CustomFileDialog.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
import QtQuick 2.0
import QtQuick.Dialogs 1.2
Item
{
id:root
property string mode //mode, open file or create file
property string sound_filepath:"" //filepath of sound file
property string write_data_filepath:"" //filepath of file to write data to
FileDialog
{
id: fileDialog
folder: shortcuts.home
visible: false
selectMultiple: false
title: fileDialog.getTitle()
selectExisting: fileDialog.getOpenFileTrueBool() //if true, open file, if false, create file
property string tempFilePath //path of file
onAccepted:
{
fileDialog.tempFilePath = fileDialog.fileUrl;
if(root.mode === "OpenSoundFile")
{
openSoundFile();
}
else if(root.mode == "CreateWriteFile")
{
createWriteFile();
}
}
onRejected:
{
//console.log("Canceled")
}
function getOpenFileTrueBool()
{
if(root.mode === "OpenSourceCircuit"){return true;}
else if(root.mode === "CreateWriteFile"){return false;}
return false; //return false by default
}
function getTitle()
{
if(root.mode === "OpenSoundFile"){return "Please choose a file with .wav or other sound file extension";}
else if(root.mode === "CreateWriteFile"){return "Please create a new file.";}
return ""; //return empty string by default
}
}
MessageDialog
{
id: messageDialog
function show(caption)
{
messageDialog.text = caption;
messageDialog.open();
}
}
function open(){fileDialog.open()}
function openSoundFile()
{
var extensionCheck = fileDialog.tempFilePath.substring(fileDialog.tempFilePath.length - 4,
fileDialog.tempFilePath.length);
//check if filePath has .wav extension
//if extension is .wav
if(extensionCheck === ".wav" ||
extensionCheck === ".mp3")
{
//take out the file://
fileDialog.tempFilePath = fileDialog.tempFilePath.replace("file://","");
//assign to source_circuit_filepath
sound_filepath = fileDialog.tempFilePath;
console.log("Sound file is "+sound_filepath);
}
else
{
messageDialog.show("Choose a file that ends with '.wav','.mp3' !\n");
}
}
function createWriteFile()
{
//take out the file://
fileDialog.tempFilePath = fileDialog.tempFilePath.replace("file://","");
//add .raw extension
fileDialog.tempFilePath = fileDialog.tempFilePath + ".raw";
//assign to write_sim_data_filepath
write_data_filepath = fileDialog.tempFilePath;
console.log("file created is "+write_data_filepath );
}
}