rbutil: fix a bug in rbsettings: FS#8512 by Sander Knopper. Also remove a warning...
[Rockbox.git] / rbutil / rbutilqt / encodersgui.cpp
blobb363e95e61d2658487d1c4a58e146c396da3a38d
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2007 by Dominik Wenger
10 * $Id: encodersgui.cpp 15212 2007-10-19 21:49:07Z domonoky $
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #include "encodersgui.h"
22 #include "rbsettings.h"
23 #include "browsedirtree.h"
25 EncExesGui::EncExesGui(QDialog* parent) : QDialog(parent)
27 ui.setupUi(this);
28 this->hide();
29 connect(ui.reset,SIGNAL(clicked()),this,SLOT(reset()));
30 connect(ui.browse,SIGNAL(clicked()),this,SLOT(browse()));
33 void EncExesGui::showCfg(QString name)
35 m_name = name;
36 // try to get config from settings
37 QString exepath =settings->encoderPath(m_name);
38 ui.encoderoptions->setText(settings->encoderOptions(m_name));
40 if(exepath == "")
43 // try to autodetect encoder
44 #if defined(Q_OS_LINUX) || defined(Q_OS_MACX)
45 QStringList path = QString(getenv("PATH")).split(":", QString::SkipEmptyParts);
46 #elif defined(Q_OS_WIN)
47 QStringList path = QString(getenv("PATH")).split(";", QString::SkipEmptyParts);
48 #endif
49 qDebug() << path;
51 for(int i = 0; i < path.size(); i++)
53 QString executable = QDir::fromNativeSeparators(path.at(i)) + "/" + m_name;
54 #if defined(Q_OS_WIN)
55 executable += ".exe";
56 QStringList ex = executable.split("\"", QString::SkipEmptyParts);
57 executable = ex.join("");
58 #endif
59 if(QFileInfo(executable).isExecutable())
61 qDebug() << "found:" << executable;
62 exepath = QDir::toNativeSeparators(executable);
63 break;
68 ui.encoderpath->setText(exepath);
70 //show dialog
71 this->exec();
75 void EncExesGui::accept(void)
77 //save settings in user config
78 settings->setEncoderPath(m_name,ui.encoderpath->text());
79 settings->setEncoderOptions(m_name,ui.encoderoptions->text());
81 // sync settings
82 settings->sync();
83 this->close();
86 void EncExesGui::reject(void)
88 this->close();
91 void EncExesGui::reset()
93 ui.encoderpath->setText("");
94 ui.encoderoptions->setText("");
97 void EncExesGui::browse()
99 BrowseDirtree browser(this);
100 browser.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
102 if(QFileInfo(ui.encoderpath->text()).isDir())
104 browser.setDir(ui.encoderpath->text());
106 if(browser.exec() == QDialog::Accepted)
108 qDebug() << browser.getSelected();
109 QString exe = browser.getSelected();
110 if(!QFileInfo(exe).isExecutable())
111 return;
112 ui.encoderpath->setText(exe);
117 EncRbSpeexGui::EncRbSpeexGui(QDialog* parent) : QDialog(parent)
119 ui.setupUi(this);
120 this->hide();
121 connect(ui.reset,SIGNAL(clicked()),this,SLOT(reset()));
125 void EncRbSpeexGui::showCfg(float defQ,float defV,int defC, bool defB)
127 defaultQuality =defQ;
128 defaultVolume = defV;
129 defaultComplexity = defC;
130 defaultBand =defB;
132 //fill in the usersettings
133 ui.volume->setValue(settings->encoderVolume("rbspeex"));
134 ui.quality->setValue(settings->encoderQuality("rbspeex"));
135 ui.complexity->setValue(settings->encoderComplexity("rbspeex"));
137 if(settings->encoderNarrowband("rbspeex"))
138 ui.narrowband->setCheckState(Qt::Checked);
139 else
140 ui.narrowband->setCheckState(Qt::Unchecked);
142 //show dialog
143 this->exec();
146 void EncRbSpeexGui::accept(void)
148 //save settings in user config
149 settings->setEncoderVolume("rbspeex",ui.volume->value());
150 settings->setEncoderQuality("rbspeex",ui.quality->value());
151 settings->setEncoderComplexity("rbspeex",ui.complexity->value());
152 settings->setEncoderNarrowband("rbspeex",ui.narrowband->isChecked() ? true : false);
154 // sync settings
155 settings->sync();
156 this->close();
159 void EncRbSpeexGui::reject(void)
161 this->close();
164 void EncRbSpeexGui::reset()
166 ui.volume->setValue(defaultVolume);
167 ui.quality->setValue(defaultQuality);
168 ui.complexity->setValue(defaultComplexity);
169 ui.narrowband->setChecked(Qt::Unchecked);