summaryrefslogtreecommitdiffstats
path: root/rbutil/rbutilqt/installtalkwindow.cpp
blob: 4d1cdb14910759283952a5e590f0d0bde20a1c6c (plain)
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 *
 *   Copyright (C) 2007 by Dominik Riebeling
 *   $Id: installtalkwindow.cpp 14151 2007-08-02 22:27:51Z bluebrother $
 *
 * All files in this archive are subject to the GNU General Public License.
 * See the file COPYING in the source tree root for full license agreement.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ****************************************************************************/

#include "installtalkwindow.h"
#include "ui_installtalkfrm.h"

InstallTalkWindow::InstallTalkWindow(QWidget *parent) : QDialog(parent)
{
    ui.setupUi(this);
    talkcreator = new TalkFileCreator(this);
    
    connect(ui.buttonBrowse, SIGNAL(clicked()), this, SLOT(browseFolder()));
    connect(ui.buttonBrowseTTS, SIGNAL(clicked()), this, SLOT(browseTTS()));
    connect(ui.buttonBrowseEncoder, SIGNAL(clicked()), this, SLOT(browseEncoder()));
  
    connect(ui.Encodercbx,SIGNAL(currentIndexChanged(int)),this,SLOT(setEncoderOptions(int)));
    connect(ui.TTScbx,SIGNAL(currentIndexChanged(int)),this,SLOT(setTTSOptions(int)));
    
    ui.OverwriteWav->setChecked(true);
    ui.RemoveWav->setChecked(true);
    ui.recursive->setChecked(true);
    ui.OverwriteTalk->setChecked(true);
    ui.StripExtensions->setChecked(true);
    
    
}

void InstallTalkWindow::browseFolder()
{
    QFileDialog browser(this);
    if(QFileInfo(ui.lineTalkFolder->text()).isDir())
        browser.setDirectory(ui.lineTalkFolder->text());
    else
        browser.setDirectory("/media");
    browser.setReadOnly(true);
    browser.setFileMode(QFileDialog::DirectoryOnly);
    browser.setAcceptMode(QFileDialog::AcceptOpen);
    if(browser.exec()) {
        qDebug() << browser.directory();
        QStringList files = browser.selectedFiles();
        setTalkFolder(files.at(0));
    }
}

void InstallTalkWindow::setTalkFolder(QString folder)
{
	ui.lineTalkFolder->clear();
	ui.lineTalkFolder->insert(folder);
}

void InstallTalkWindow::browseTTS()
{
    QFileDialog browser(this);
    if(QFileInfo(ui.TTSpath->text()).isDir())
        browser.setDirectory(ui.TTSpath->text());
    else
        browser.setDirectory("/media");
    browser.setReadOnly(true);
    browser.setFileMode(QFileDialog::ExistingFile);
    browser.setAcceptMode(QFileDialog::AcceptOpen);
    if(browser.exec()) {
        qDebug() << browser.directory();
        QStringList files = browser.selectedFiles();
        setTTSExec(files.at(0));
    }
}

void InstallTalkWindow::setTTSExec(QString path)
{
	ui.TTSpath->clear();
	ui.TTSpath->insert(path);
}

void InstallTalkWindow::browseEncoder()
{
    QFileDialog browser(this);
    if(QFileInfo(ui.Encoderpath->text()).isDir())
        browser.setDirectory(ui.Encoderpath->text());
    else
        browser.setDirectory("/media");
    browser.setReadOnly(true);
    browser.setFileMode(QFileDialog::ExistingFile);
    browser.setAcceptMode(QFileDialog::AcceptOpen);
    if(browser.exec()) {
        qDebug() << browser.directory();
        QStringList files = browser.selectedFiles();
        setEncoderExec(files.at(0));
    }
}

void InstallTalkWindow::setEncoderExec(QString path)
{
	ui.Encoderpath->clear();
	ui.Encoderpath->insert(path);
}

void InstallTalkWindow::setEncoderOptions(int index)
{
	QString options = talkcreator->getEncOpts(ui.Encodercbx->itemText(index));
	setEncoderOptions(options);
}
void InstallTalkWindow::setEncoderOptions(QString options)
{	
	ui.EncoderOptions->clear();
	ui.EncoderOptions->insert(options);
}
void InstallTalkWindow::setTTSOptions(QString options)
{
	ui.TTSOptions->clear();
	ui.TTSOptions->insert(options);
}
void InstallTalkWindow::setTTSOptions(int index)
{
	QString options = talkcreator->getTTsOpts(ui.TTScbx->itemText(index));
	setEncoderOptions(options);
}

void InstallTalkWindow::accept()
{
    logger = new ProgressLoggerGui(this);
    logger->show();
    
    QString folderToTalk = ui.lineTalkFolder->text();
    QString pathEncoder = ui.Encoderpath->text();
    QString pathTTS = ui.TTSpath->text();
    
    if(!QFileInfo(folderToTalk).isDir())
    {
    	 logger->addItem(tr("The Folder to Talk is wrong!"),LOGERROR);
    	 logger->abort();
    	 return;
    }
    
    if(!QFileInfo(pathEncoder).exists())
    {
      	 logger->addItem(tr("Path to Encoder is wrong!"),LOGERROR);
       	 logger->abort();
       	 return;
    }
    
    if(!QFileInfo(pathTTS).exists())
    {
         logger->addItem(tr("Path to TTS is wrong!"),LOGERROR);
         logger->abort();
         return;
    }
    
    userSettings->setValue("defaults/folderToTalk",folderToTalk);
    userSettings->setValue("defaults/pathEncoder",pathEncoder);
    userSettings->setValue("defaults/pathTTS",pathTTS);
    
    userSettings->sync();
    
    talkcreator->setDir(folderToTalk);
    talkcreator->setTTSexe(pathTTS);
    talkcreator->setEncexe(pathEncoder);
    talkcreator->setEncOpts(ui.EncoderOptions->text());
    talkcreator->setTTsOpts(ui.TTSOptions->text());
    talkcreator->setTTsType(ui.TTScbx->currentText());
    talkcreator->setEncType(ui.Encodercbx->currentText());
    
    talkcreator->setOverwriteTalk(ui.OverwriteTalk->isChecked());
    talkcreator->setOverwriteWav(ui.OverwriteWav->isChecked());
    talkcreator->setRemoveWav(ui.RemoveWav->isChecked());
    talkcreator->setRecursive(ui.recursive->isChecked());
    talkcreator->setStripExtensions(ui.StripExtensions->isChecked());

    talkcreator->createTalkFiles(logger);
}


void InstallTalkWindow::setDeviceSettings(QSettings *dev)
{
    devices = dev;
    qDebug() << "Install::setDeviceSettings:" << devices;

    QStringList encoders;
    QStringList encodersOpts;
    QStringList encodersTemplates;

    QStringList tts;
    QStringList ttsOpts;
    QStringList ttsTemplates;
    
    devices->beginGroup("encoders");
    QStringList keys = devices->allKeys();
    qDebug() << keys;
    for(int i=0; i < keys.size();i++)
    {
       	encoders << devices->value(keys.at(i),"null").toString();
    }
    qDebug() << encoders;
    devices->endGroup();
    for(int i=0; i < encoders.size();i++)
    {
    	devices->beginGroup(encoders.at(i));
       	encodersOpts << devices->value("options","null").toString();
       	encodersTemplates << devices->value("template","null").toString();
       	devices->endGroup();
    }
    qDebug() << encodersOpts;
    qDebug() << encodersTemplates;
    
    devices->beginGroup("tts");
    keys = devices->allKeys();
    qDebug() << keys;
    for(int i=0; i < keys.size();i++)
    {
        tts << devices->value(keys.at(i),"null").toString();
    } 
    qDebug() << tts;
    devices->endGroup();
    for(int i= 0; i < tts.size();i++)
    {
    	devices->beginGroup(tts.at(i));
       	ttsOpts << devices->value("options","null").toString();
        ttsTemplates << devices->value("template","null").toString();
        devices->endGroup();
    }
    qDebug() << ttsOpts;
    qDebug() << ttsTemplates;
    
    talkcreator->setSupportedEnc(encoders);
    talkcreator->setSupportedEncOptions(encodersOpts);
    talkcreator->setSupportedEncTemplates(encodersTemplates);
       
    talkcreator->setSupportedTTS(tts);
    talkcreator->setSupportedTTSOptions(ttsOpts);
    talkcreator->setSupportedTTSTemplates(ttsTemplates);
       
    ui.Encodercbx->insertItems(0,talkcreator->getSupportedEnc());
    ui.TTScbx->insertItems(0,talkcreator->getSupportedTTS());    
    
}




void InstallTalkWindow::setUserSettings(QSettings *user)
{
    userSettings = user;
    

   
    setTalkFolder(userSettings->value("defaults/folderToTalk").toString());
    setEncoderExec(userSettings->value("defaults/pathEncoder").toString());
    setTTSExec(userSettings->value("defaults/pathTTS").toString());
}