source: s10k/Vago/soundWizard/soundpage2.cpp@ 1115

Last change on this file since 1115 was 1093, checked in by s10k, 7 years ago

Vago 1.4

File size: 5.0 KB
Line 
1#include "soundpage2.h"
2#include "ui_soundpage2.h"
3
4const QStringList SoundPage2::allowedFiles = QStringList() << "*.wav" << "*.aif" << "*.aifc" << "*.afc";
5
6SoundPage2::SoundPage2(QString appLocation, QWidget *parent) :
7 QWizardPage(parent),
8 ui(new Ui::soundpage2)
9{
10 ui->setupUi(this);
11 this->soundTable=ui->twSoundFiles;
12 this->codecLocalHelpFile=appLocation+"/"+GlobalVars::HelpDir + "/XMLSNDD.html#Source_file_creation";
13 ui->twSoundFiles->removeColumn(2); // Only two columns
14
15 ui->label->setText("<html>Add here the files you want to convert. "
16 "All the files will have the same properties applied.<br/>"
17 "Don't forget to first convert the files to an oni compatible codec. "
18 "More information <a href='file:///"+this->codecLocalHelpFile+"'>here.</a></html>"); // Don't use rich text in qtdesigner because it generates platform dependent code
19
20 // Drop signal for Packages table
21 connect(ui->twSoundFiles, SIGNAL(dropped(DropTableWidget*,QStringList)), this, SLOT(addResourcesSounds(DropTableWidget*,QStringList)));
22 // Signal for click in label (display local help)
23 connect(ui->label, SIGNAL(linkActivated(const QString & )), this, SLOT(openCodecLocalHelp()));
24
25 //Register fields to be accessible in another pages
26 registerField("rbOther", ui->rbOther);
27 registerField("leOtherLocation", ui->leOtherLocation);
28}
29
30SoundPage2::~SoundPage2()
31{
32 delete ui;
33}
34
35void SoundPage2::on_rbOther_toggled(bool checked)
36{
37 if(checked){
38 ui->leOtherLocation->setEnabled(true);
39 ui->pbBrowserOtherLocation->setEnabled(true);
40 return;
41 }
42
43 ui->leOtherLocation->setEnabled(false);
44 ui->pbBrowserOtherLocation->setEnabled(false);
45}
46
47void SoundPage2::on_tbAddFiles_clicked()
48{
49 addResourcesSounds(ui->twSoundFiles,QFileDialog::getOpenFileNames(this,"Choose the sound files...","./" , "Audio (" + this->allowedFiles.join(" ") + ")"));
50}
51
52void SoundPage2::on_tbRemoveFiles_clicked()
53{
54 int size = ui->twSoundFiles->selectionModel()->selectedRows().size();
55
56 if(size==0){
57 Util::Dialogs::showInfo("Select a row first.");
58 return;
59 }
60
61 if(Util::Dialogs::showQuestion(this,"Are you sure you want to delete the selected rows?")){
62 for(int i=0; i<size; i++){
63 ui->twSoundFiles->removeRow(ui->twSoundFiles->selectionModel()->selectedRows().at(size-i-1).row());
64 }
65 }
66}
67
68void SoundPage2::addResourcesSounds(DropTableWidget *myTable, QStringList resources){
69
70 bool fileExtValid=false;
71
72 //Pre-processing (check if received only folders)
73 for(const QString &myFile : resources){
74 QString currFileExt="."+QFileInfo(myFile).completeSuffix();
75 if(QDir(myFile).exists()){
76 Util::Dialogs::showError("Only files are allowed for this operation.");
77 return;
78 }
79
80 for(QString vext : this->allowedFiles){
81 vext.remove("*");
82 if(currFileExt.endsWith(vext)){
83 fileExtValid=true;
84 break;
85 }
86 }
87
88 if(!fileExtValid){
89 Util::Dialogs::showError("Files must be in the follow formats:\n" +
90 this->allowedFiles.join(" "));
91 return;
92 }
93 }
94
95 for(const QString &currentFile : resources){
96
97 //Get actual number rows
98 int twSize=myTable->rowCount();
99
100 //increase the rows for the new item
101 myTable->setRowCount(twSize+1);
102
103 //Add to table and list to
104 QTableWidgetItem *newName = new QTableWidgetItem(QFileInfo(currentFile).baseName());
105 QTableWidgetItem *newFileLocation = new QTableWidgetItem(Util::FileSystem::normalizePath(currentFile));
106
107 myTable->setItem(twSize,0,newName);
108 myTable->setItem(twSize,1,newFileLocation);
109 myTable->updateTableToolTips(twSize); //Update tool tips
110 }
111}
112
113void SoundPage2::on_pbBrowserOtherLocation_clicked()
114{
115 ui->leOtherLocation->setText(QFileDialog::getExistingDirectory(this,"Choose output folder..."));
116}
117
118void SoundPage2::openCodecLocalHelp(){
119 QDesktopServices::openUrl(QUrl("file:///"+this->codecLocalHelpFile));
120}
121
122bool SoundPage2::validatePage(){
123
124 QStringList namesList;
125
126 if(ui->twSoundFiles->rowCount()==0){
127 Util::Dialogs::showError("You need to add some sound files first!");
128 return false;
129 }
130
131 for(int i=0; i<ui->twSoundFiles->rowCount(); i++){
132 namesList << ui->twSoundFiles->item(i,0)->text();
133 }
134
135 if(ui->rbOther->isChecked() && Util::Validation::checkEmptySpaces(QStringList() << ui->leOtherLocation->text())){
136 Util::Dialogs::showError("Please input a directory to output the files.");
137 return false;
138 }
139
140 if(ui->rbOther->isChecked() && !QDir(ui->leOtherLocation->text()).exists()){
141 Util::Dialogs::showError("Invalid directory specified in other location. Please fix it.");
142 return false;
143 }
144
145 return true;
146}
Note: See TracBrowser for help on using the repository browser.