1
/***************************************************************************
2
* Copyright (C) 2009 by Kai Dombrowe <just89@gmx.de> *
4
* This program is free software; you can redistribute it and/or modify *
5
* it under the terms of the GNU General Public License as published by *
6
* the Free Software Foundation; either version 2 of the License, or *
7
* (at your option) any later version. *
9
* This program is distributed in the hope that it will be useful, *
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12
* GNU General Public License for more details. *
14
* You should have received a copy of the GNU General Public License *
15
* along with this program; if not, write to the *
16
* Free Software Foundation, Inc., *
17
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
18
***************************************************************************/
22
#include "ffmpegencoderconfig.h"
23
#include <recorditnow_ffmpeg.h>
24
#include "formatdialog.h"
27
#include <kpluginfactory.h>
29
#include <kconfiggroup.h>
33
K_PLUGIN_FACTORY(ConfigFactory, registerPlugin<FfmpegEncoderConfig>();)
34
K_EXPORT_PLUGIN(ConfigFactory("recorditnow_ffmpeg_config"))
35
FfmpegEncoderConfig::FfmpegEncoderConfig(QWidget *parent, const QVariantList &args)
36
: KCModule(ConfigFactory::componentData(), parent, args)
41
addButton->setIcon(KIcon("list-add"));
42
editButton->setIcon(KIcon("document-edit"));
43
removeButton->setIcon(KIcon("list-remove"));
45
connect(formatCombo, SIGNAL(currentIndexChanged(QString)), this, SLOT(formatChanged(QString)));
46
connect(addButton, SIGNAL(clicked()), this, SLOT(addClicked()));
47
connect(editButton, SIGNAL(clicked()), this, SLOT(editClicked()));
48
connect(removeButton, SIGNAL(clicked()), this, SLOT(removeClicked()));
50
addConfig(Settings::self(), this);
55
FfmpegEncoderConfig::~FfmpegEncoderConfig()
62
void FfmpegEncoderConfig::defaults()
67
m_format[i18n("flv")] = "-i %1 -sameq -xerror %2.flv";
68
m_format[i18n("avi")] = "-i %1 -sameq -xerror %2.avi";
69
m_format[i18n("wmv")] = "-i %1 -sameq -xerror %2.wmv";
70
m_format[i18n("mpeg")] = "-i %1 -sameq -xerror %2.mpeg";
71
m_format[i18n("mkv")] = "-i %1 -sameq -xerror %2.mkv";
78
void FfmpegEncoderConfig::load()
83
Settings::self()->readConfig();
84
KConfigGroup cfg(Settings::self()->config(), "ffmpeg");
85
const QStringList list = cfg.readEntry("List", QStringList());
87
foreach (const QString &format, list) {
88
m_format[format] = cfg.readEntry(format, QString());
93
formatCombo->setCurrentItem(Settings::self()->format(), false);
98
void FfmpegEncoderConfig::save()
101
const QString format = formatCombo->currentText();
102
Settings::self()->setFormat(format);
103
Settings::self()->setCommand(m_format[format]);
105
KConfigGroup cfg(Settings::self()->config(), "ffmpeg");
107
QHashIterator<QString, QString> it(m_format);
108
while (it.hasNext()) {
110
cfg.writeEntry(it.key(), it.value());
112
cfg.writeEntry("List", m_format.keys());
114
Settings::self()->writeConfig();
119
void FfmpegEncoderConfig::addClicked()
122
FormatDialog *dialog = new FormatDialog(QString(), QString(), this);
123
connect(dialog, SIGNAL(addFinished(QString,QString)), this, SLOT(addFinished(QString, QString)));
129
void FfmpegEncoderConfig::editClicked()
132
const QString format = formatCombo->currentText();
133
if (!format.isEmpty()) {
134
FormatDialog *dialog = new FormatDialog(format, m_format[format], this);
135
connect(dialog, SIGNAL(editFinished(QString,QString, QString)), this,
136
SLOT(editFinished(QString, QString, QString)));
143
void FfmpegEncoderConfig::removeClicked()
146
m_format.remove(formatCombo->currentText());
153
void FfmpegEncoderConfig::formatChanged(const QString &newFormat)
156
if (!newFormat.isEmpty() && m_format.contains(newFormat)) {
157
previewEdit->setText(m_format[newFormat]);
164
void FfmpegEncoderConfig::formatListChanged()
167
const QString format = formatCombo->currentText();
168
formatCombo->clear();
170
if (m_format.isEmpty()) {
173
formatCombo->addItems(m_format.keys());
176
formatCombo->setCurrentItem(format, false);
181
void FfmpegEncoderConfig::editFinished(const QString &oldName, const QString &newName,
182
const QString &command)
185
m_format.remove(oldName);
186
m_format[newName] = command;
193
void FfmpegEncoderConfig::addFinished(const QString &format, const QString &command)
196
m_format[format] = command;