~ubuntu-branches/ubuntu/natty/recorditnow/natty

« back to all changes in this revision

Viewing changes to src/plugins/encoder/ffmpeg/ffmpegencoderconfig.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2009-11-26 16:50:53 UTC
  • Revision ID: james.westby@ubuntu.com-20091126165053-yifjycveb8j7yt8r
Tags: upstream-0.4
Import upstream version 0.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2009 by Kai Dombrowe <just89@gmx.de>                    *
 
3
 *                                                                         *
 
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.                                   *
 
8
 *                                                                         *
 
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.                          *
 
13
 *                                                                         *
 
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
 ***************************************************************************/
 
19
 
 
20
 
 
21
// own
 
22
#include "ffmpegencoderconfig.h"
 
23
#include <recorditnow_ffmpeg.h>
 
24
#include "formatdialog.h"
 
25
 
 
26
// KDE
 
27
#include <kpluginfactory.h>
 
28
#include <kdialog.h>
 
29
#include <kconfiggroup.h>
 
30
#include <kdebug.h>
 
31
 
 
32
 
 
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)
 
37
{
 
38
 
 
39
    setupUi(this);
 
40
 
 
41
    addButton->setIcon(KIcon("list-add"));
 
42
    editButton->setIcon(KIcon("document-edit"));
 
43
    removeButton->setIcon(KIcon("list-remove"));
 
44
 
 
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()));
 
49
 
 
50
    addConfig(Settings::self(), this);
 
51
 
 
52
}
 
53
 
 
54
 
 
55
FfmpegEncoderConfig::~FfmpegEncoderConfig()
 
56
{
 
57
 
 
58
 
 
59
}
 
60
 
 
61
 
 
62
void FfmpegEncoderConfig::defaults()
 
63
{
 
64
 
 
65
    m_format.clear();
 
66
 
 
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";
 
72
 
 
73
    formatListChanged();
 
74
 
 
75
}
 
76
 
 
77
 
 
78
void FfmpegEncoderConfig::load()
 
79
{
 
80
 
 
81
    m_format.clear();
 
82
 
 
83
    Settings::self()->readConfig();
 
84
    KConfigGroup cfg(Settings::self()->config(), "ffmpeg");
 
85
    const QStringList list = cfg.readEntry("List", QStringList());
 
86
 
 
87
    foreach (const QString &format, list) {
 
88
        m_format[format] = cfg.readEntry(format, QString());
 
89
    }
 
90
 
 
91
    formatListChanged();
 
92
 
 
93
    formatCombo->setCurrentItem(Settings::self()->format(), false);
 
94
 
 
95
}
 
96
 
 
97
 
 
98
void FfmpegEncoderConfig::save()
 
99
{
 
100
 
 
101
    const QString format = formatCombo->currentText();
 
102
    Settings::self()->setFormat(format);
 
103
    Settings::self()->setCommand(m_format[format]);
 
104
 
 
105
    KConfigGroup cfg(Settings::self()->config(), "ffmpeg");
 
106
 
 
107
    QHashIterator<QString, QString> it(m_format);
 
108
    while (it.hasNext()) {
 
109
        it.next();
 
110
        cfg.writeEntry(it.key(), it.value());
 
111
    }
 
112
    cfg.writeEntry("List", m_format.keys());
 
113
 
 
114
    Settings::self()->writeConfig();
 
115
 
 
116
}
 
117
 
 
118
 
 
119
void FfmpegEncoderConfig::addClicked()
 
120
{
 
121
 
 
122
    FormatDialog *dialog = new FormatDialog(QString(), QString(), this);
 
123
    connect(dialog, SIGNAL(addFinished(QString,QString)), this, SLOT(addFinished(QString, QString)));
 
124
    dialog->show();
 
125
 
 
126
}
 
127
 
 
128
 
 
129
void FfmpegEncoderConfig::editClicked()
 
130
{
 
131
 
 
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)));
 
137
        dialog->show();
 
138
    }
 
139
 
 
140
}
 
141
 
 
142
 
 
143
void FfmpegEncoderConfig::removeClicked()
 
144
{
 
145
 
 
146
    m_format.remove(formatCombo->currentText());
 
147
    formatListChanged();
 
148
    changed();
 
149
 
 
150
}
 
151
 
 
152
 
 
153
void FfmpegEncoderConfig::formatChanged(const QString &newFormat)
 
154
{
 
155
 
 
156
    if (!newFormat.isEmpty() && m_format.contains(newFormat)) {
 
157
        previewEdit->setText(m_format[newFormat]);
 
158
    }
 
159
    changed();
 
160
 
 
161
}
 
162
 
 
163
 
 
164
void FfmpegEncoderConfig::formatListChanged()
 
165
{
 
166
 
 
167
    const QString format = formatCombo->currentText();
 
168
    formatCombo->clear();
 
169
 
 
170
    if (m_format.isEmpty()) {
 
171
        defaults();
 
172
    } else {
 
173
        formatCombo->addItems(m_format.keys());
 
174
    }
 
175
 
 
176
    formatCombo->setCurrentItem(format, false);
 
177
 
 
178
}
 
179
 
 
180
 
 
181
void FfmpegEncoderConfig::editFinished(const QString &oldName, const QString &newName,
 
182
                                       const QString &command)
 
183
{
 
184
 
 
185
    m_format.remove(oldName);
 
186
    m_format[newName] = command;
 
187
    formatListChanged();
 
188
    changed();
 
189
 
 
190
}
 
191
 
 
192
 
 
193
void FfmpegEncoderConfig::addFinished(const QString &format, const QString &command)
 
194
{
 
195
 
 
196
    m_format[format] = command;
 
197
    formatListChanged();
 
198
    changed();
 
199
 
 
200
}
 
201