summaryrefslogtreecommitdiffstats
path: root/rbutil/rbutilqt
diff options
context:
space:
mode:
authorDominik Wenger <domonoky@googlemail.com>2007-12-14 20:09:44 +0000
committerDominik Wenger <domonoky@googlemail.com>2007-12-14 20:09:44 +0000
commited33c89f9ff67fb3c3b1004ab73a4bd2a0ff6d15 (patch)
treeee873699695c8d23c741e2f6f50b2d2785550865 /rbutil/rbutilqt
parent37113e69df30421c7a4713ab2e28f98fe4411cc0 (diff)
downloadrockbox-ed33c89f9ff67fb3c3b1004ab73a4bd2a0ff6d15.tar.gz
rockbox-ed33c89f9ff67fb3c3b1004ab73a4bd2a0ff6d15.zip
rbutil: ups again, more missing files.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15928 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'rbutil/rbutilqt')
-rw-r--r--rbutil/rbutilqt/encoders.cpp366
-rw-r--r--rbutil/rbutilqt/encoders.h125
2 files changed, 491 insertions, 0 deletions
diff --git a/rbutil/rbutilqt/encoders.cpp b/rbutil/rbutilqt/encoders.cpp
new file mode 100644
index 0000000000..3eeea02300
--- /dev/null
+++ b/rbutil/rbutilqt/encoders.cpp
@@ -0,0 +1,366 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ *
+ * Copyright (C) 2007 by Dominik Wenger
+ * $Id: talkfile.cpp 15212 2007-10-19 21:49:07Z domonoky $
+ *
+ * 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 "encoders.h"
+#include "browsedirtree.h"
+
+
+static QMap<QString,QString> encoderList;
+static QMap<QString,EncBase*> encoderCache;
+
+void initEncoderList()
+{
+ encoderList["rbspeex"] = "Rockbox Speex Encoder";
+ encoderList["lame"] = "Lame Mp3 Encoder";
+}
+
+// function to get a specific encoder
+EncBase* getEncoder(QString encname)
+{
+ QString encoder = encoderList.key(encname);
+
+ // check cache
+ if(encoderCache.contains(encoder))
+ return encoderCache.value(encoder);
+
+ EncBase* enc;
+ if(encoder == "rbspeex")
+ {
+ enc = new EncRbSpeex();
+ encoderCache[encoder] = enc;
+ return enc;
+ }
+ else if(encoder == "lame")
+ {
+ enc = new EncExes(encoder);
+ encoderCache[encoder] = enc;
+ return enc;
+ }
+ else
+ return NULL;
+}
+
+// get the list of encoders, nice names
+QStringList getEncoderList()
+{
+ QStringList encList;
+ QMapIterator<QString, QString> i(encoderList);
+ while (i.hasNext()) {
+ i.next();
+ encList << i.value();
+ }
+
+ return encList;
+}
+
+
+/*********************************************************************
+* Encoder Base
+**********************************************************************/
+EncBase::EncBase(QWidget *parent): QDialog(parent)
+{
+
+}
+
+/*********************************************************************
+* GEneral Exe Encoder
+**********************************************************************/
+EncExes::EncExes(QString name,QWidget *parent) : EncBase(parent)
+{
+ m_name = name;
+
+ m_TemplateMap["lame"] = "\"%exe\" %options \"%input\" \"%output\"";
+
+ ui.setupUi(this);
+ this->hide();
+ connect(ui.reset,SIGNAL(clicked()),this,SLOT(reset()));
+ connect(ui.browse,SIGNAL(clicked()),this,SLOT(browse()));
+}
+
+bool EncExes::start()
+{
+ userSettings->beginGroup(m_name);
+ m_EncExec = userSettings->value("encoderpath","").toString();
+ m_EncOpts = userSettings->value("encoderoptions","").toString();
+ userSettings->endGroup();
+
+ m_EncTemplate = m_TemplateMap.value(m_name);
+
+ QFileInfo enc(m_EncExec);
+ if(enc.exists())
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+}
+
+bool EncExes::encode(QString input,QString output)
+{
+ //qDebug() << "encoding..";
+ QString execstring = m_EncTemplate;
+
+ execstring.replace("%exe",m_EncExec);
+ execstring.replace("%options",m_EncOpts);
+ execstring.replace("%input",input);
+ execstring.replace("%output",output);
+ qDebug() << execstring;
+ QProcess::execute(execstring);
+ return true;
+}
+
+void EncExes::reset()
+{
+ ui.encoderpath->setText("");
+ ui.encoderoptions->setText("");
+}
+
+void EncExes::showCfg()
+{
+ // try to get config from settings
+ userSettings->beginGroup(m_name);
+ QString exepath =userSettings->value("encoderpath","").toString();
+ ui.encoderoptions->setText(userSettings->value("encoderoptions","").toString());
+ userSettings->endGroup();
+
+ if(exepath == "")
+ {
+
+ // try to autodetect encoder
+#if defined(Q_OS_LINUX) || defined(Q_OS_MACX)
+ QStringList path = QString(getenv("PATH")).split(":", QString::SkipEmptyParts);
+#elif defined(Q_OS_WIN)
+ QStringList path = QString(getenv("PATH")).split(";", QString::SkipEmptyParts);
+#endif
+ qDebug() << path;
+
+ for(int i = 0; i < path.size(); i++)
+ {
+ QString executable = QDir::fromNativeSeparators(path.at(i)) + "/" + m_name;
+#if defined(Q_OS_WIN)
+ executable += ".exe";
+ QStringList ex = executable.split("\"", QString::SkipEmptyParts);
+ executable = ex.join("");
+#endif
+ if(QFileInfo(executable).isExecutable())
+ {
+ qDebug() << "found:" << executable;
+ exepath = QDir::toNativeSeparators(executable);
+ break;
+ }
+ }
+ }
+
+ ui.encoderpath->setText(exepath);
+
+ //show dialog
+ this->exec();
+
+}
+
+void EncExes::accept(void)
+{
+ if(userSettings != NULL)
+ {
+ //save settings in user config
+ userSettings->beginGroup(m_name);
+ userSettings->setValue("encoderpath",ui.encoderpath->text());
+ userSettings->setValue("encoderoptions",ui.encoderoptions->text());
+ userSettings->endGroup();
+ // sync settings
+ userSettings->sync();
+ }
+ this->close();
+}
+
+void EncExes::reject(void)
+{
+ this->close();
+}
+
+bool EncExes::configOk()
+{
+ userSettings->beginGroup(m_name);
+ QString path = userSettings->value("encoderpath","").toString();
+ userSettings->endGroup();
+
+ if (QFileInfo(path).exists())
+ return true;
+
+ return false;
+}
+
+void EncExes::browse()
+{
+ BrowseDirtree browser(this);
+ browser.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
+
+ if(QFileInfo(ui.encoderpath->text()).isDir())
+ {
+ browser.setDir(ui.encoderpath->text());
+ }
+ if(browser.exec() == QDialog::Accepted)
+ {
+ qDebug() << browser.getSelected();
+ QString exe = browser.getSelected();
+ if(!QFileInfo(exe).isExecutable())
+ return;
+ ui.encoderpath->setText(exe);
+ }
+}
+
+/*********************************************************************
+* RB SPEEX ENCODER
+**********************************************************************/
+EncRbSpeex::EncRbSpeex(QWidget *parent) : EncBase(parent)
+{
+ ui.setupUi(this);
+ this->hide();
+ connect(ui.reset,SIGNAL(clicked()),this,SLOT(reset()));
+
+ defaultQuality = 8.f;
+ defaultVolume = 1.f;
+ defaultComplexity =3;
+ defaultBand = false;
+
+}
+
+
+bool EncRbSpeex::start()
+{
+ // no user config
+ if(userSettings == NULL)
+ {
+ return false;
+ }
+ // try to get config from settings
+ userSettings->beginGroup("rbspeex");
+ quality = userSettings->value("quality",defaultQuality).toDouble();
+ complexity = userSettings->value("complexity",defaultComplexity).toInt();
+ volume =userSettings->value("volume",defaultVolume).toDouble();
+ narrowband = userSettings->value("narrowband",false).toBool();
+
+ userSettings->endGroup();
+
+ return true;
+}
+
+bool EncRbSpeex::encode(QString input,QString output)
+{
+ //qDebug() << "encoding
+ char errstr[512];
+
+ FILE *fin,*fout;
+ if ((fin = fopen(input.toUtf8(), "rb")) == NULL) {
+ qDebug() << "Error: could not open input file\n";
+ return false;
+ }
+ if ((fout = fopen(output.toUtf8(), "wb")) == NULL) {
+ qDebug() << "Error: could not open output file\n";
+ return false;
+ }
+
+
+ int ret = encode_file(fin, fout, quality, complexity, narrowband, volume,
+ errstr, sizeof(errstr));
+ fclose(fout);
+ fclose(fin);
+
+ if (!ret) {
+ /* Attempt to delete unfinished output */
+ qDebug() << "Error:" << errstr;
+ QFile(output).remove();
+ return false;
+ }
+ return true;
+}
+
+void EncRbSpeex::reset()
+{
+ ui.volume->setValue(defaultVolume);
+ ui.quality->setValue(defaultQuality);
+ ui.complexity->setValue(defaultComplexity);
+ ui.narrowband->setChecked(Qt::Unchecked);
+}
+
+void EncRbSpeex::showCfg()
+{
+ //fill in the usersettings
+ userSettings->beginGroup("rbspeex");
+ ui.volume->setValue(userSettings->value("volume",defaultVolume).toDouble());
+ ui.quality->setValue(userSettings->value("quality",defaultQuality).toDouble());
+ ui.complexity->setValue(userSettings->value("complexity",defaultComplexity).toInt());
+
+ if(userSettings->value("narrowband","False").toString() == "True")
+ ui.narrowband->setCheckState(Qt::Checked);
+ else
+ ui.narrowband->setCheckState(Qt::Unchecked);
+
+ userSettings->endGroup();
+
+ //show dialog
+ this->exec();
+}
+
+void EncRbSpeex::accept(void)
+{
+ if(userSettings != NULL)
+ {
+ //save settings in user config
+ userSettings->beginGroup("rbspeex");
+ userSettings->setValue("volume",ui.volume->value());
+ userSettings->setValue("quality",ui.quality->value());
+ userSettings->setValue("complexity",ui.complexity->value());
+ userSettings->setValue("narrowband",ui.narrowband->isChecked() ? true : false);
+
+ userSettings->endGroup();
+ // sync settings
+ userSettings->sync();
+ }
+ this->close();
+}
+
+void EncRbSpeex::reject(void)
+{
+ this->close();
+}
+
+
+bool EncRbSpeex::configOk()
+{
+ bool result=true;
+ // check config
+ userSettings->beginGroup("rbspeex");
+
+ if(userSettings->value("volume","null").toDouble() <= 0)
+ result =false;
+
+ if(userSettings->value("quality","null").toDouble() <= 0)
+ result =false;
+
+ if(userSettings->value("complexity","null").toInt() <= 0)
+ result =false;
+
+ userSettings->endGroup();
+
+ return result;
+}
+
diff --git a/rbutil/rbutilqt/encoders.h b/rbutil/rbutilqt/encoders.h
new file mode 100644
index 0000000000..f69c3ba611
--- /dev/null
+++ b/rbutil/rbutilqt/encoders.h
@@ -0,0 +1,125 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ *
+ * Copyright (C) 2007 by Dominik Wenger
+ * $Id: talkfile.h 15212 2007-10-19 21:49:07Z domonoky $
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+#ifndef ENCODERS_H
+#define ENCODERS_H
+
+#include "ui_rbspeexcfgfrm.h"
+#include "ui_encexescfgfrm.h"
+#include <QtGui>
+
+extern "C"
+{
+ #include "rbspeex.h"
+}
+
+class EncBase;
+
+//inits the encoder List
+void initEncoderList();
+// function to get a specific encoder
+EncBase* getEncoder(QString encname);
+// get the list of encoders, nice names
+QStringList getEncoderList();
+
+
+
+class EncBase : public QDialog
+{
+ Q_OBJECT
+public:
+ EncBase(QWidget *parent );
+ virtual ~EncBase(){}
+ virtual bool encode(QString input,QString output) = 0;
+ virtual bool start() = 0;
+ virtual bool stop() = 0;
+ virtual void showCfg() = 0;
+ virtual bool configOk()=0;
+
+ void setUserCfg(QSettings *uSettings){userSettings = uSettings;}
+
+public slots:
+ virtual void accept(void)=0;
+ virtual void reject(void)=0;
+ virtual void reset(void)=0;
+
+protected:
+
+ QSettings *userSettings;
+};
+
+
+
+class EncExes : public EncBase
+{
+ Q_OBJECT
+public:
+ EncExes(QString name,QWidget *parent = NULL);
+ virtual bool encode(QString input,QString output);
+ virtual bool start();
+ virtual bool stop() {return true;}
+ virtual void showCfg();
+ virtual bool configOk();
+
+public slots:
+ virtual void accept(void);
+ virtual void reject(void);
+ virtual void reset(void);
+ void browse(void);
+
+private:
+ Ui::EncExesCfgFrm ui;
+ QString m_name;
+ QString m_EncExec;
+ QString m_EncOpts;
+ QMap<QString,QString> m_TemplateMap;
+ QString m_EncTemplate;
+};
+
+class EncRbSpeex : public EncBase
+{
+ Q_OBJECT
+public:
+ EncRbSpeex(QWidget *parent = NULL);
+ virtual bool encode(QString input,QString output);
+ virtual bool start();
+ virtual bool stop() {return true;}
+ virtual void showCfg();
+ virtual bool configOk();
+
+public slots:
+ virtual void accept(void);
+ virtual void reject(void);
+ virtual void reset(void);
+
+private:
+ Ui::RbSpeexCfgFrm ui;
+ float quality;
+ float volume;
+ int complexity;
+ bool narrowband;
+
+ float defaultQuality;
+ float defaultVolume;
+ int defaultComplexity;
+ bool defaultBand;
+};
+
+
+#endif