]> git.sesse.net Git - kdenlive/blob - src/encodingprofilesdialog.cpp
Don't hardcode encoding profiles, use an external config file
[kdenlive] / src / encodingprofilesdialog.cpp
1 /***************************************************************************
2  *   Copyright (C) 2008 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
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 #include "encodingprofilesdialog.h"
21 #include "kdenlivesettings.h"
22
23 #include <KStandardDirs>
24 #include <KDebug>
25 #include <KMessageBox>
26 #include <KIO/NetAccess>
27
28 #include <QDir>
29 #include <QCloseEvent>
30 #include <QVBoxLayout>
31 #include <QLineEdit>
32 #include <QPlainTextEdit>
33
34 EncodingProfilesDialog::EncodingProfilesDialog(int profileType, QWidget * parent) :
35     QDialog(parent),
36     m_configGroup(NULL)
37 {
38     setupUi(this);
39     setWindowTitle(i18n("Manage Encoding Profiles"));
40     profile_type->addItem(i18n("Proxy clips"), 0);
41     profile_type->addItem(i18n("Video4Linux capture"), 1);
42     profile_type->addItem(i18n("Decklink capture"), 2);
43     
44     button_add->setIcon(KIcon("list-add"));
45     button_edit->setIcon(KIcon("document-edit"));
46     button_delete->setIcon(KIcon("list-remove"));
47     button_download->setIcon(KIcon("download"));
48     
49     m_configFile = new KConfig("encodingprofiles.rc", KConfig::FullConfig, "appdata");
50     profile_type->setCurrentIndex(profileType);
51     connect(profile_type, SIGNAL(currentIndexChanged(int)), this, SLOT(slotLoadProfiles()));
52     connect(profile_list, SIGNAL(currentRowChanged(int)), this, SLOT(slotShowParams()));
53     connect(button_delete, SIGNAL(clicked()), this, SLOT(slotDeleteProfile()));
54     connect(button_add, SIGNAL(clicked()), this, SLOT(slotAddProfile()));
55     connect(button_edit, SIGNAL(clicked()), this, SLOT(slotEditProfile()));
56     profile_parameters->setMaximumHeight(QFontMetrics(font()).lineSpacing() * 5);
57     slotLoadProfiles();
58 }
59
60 EncodingProfilesDialog::~EncodingProfilesDialog()
61 {
62     delete m_configGroup;
63     delete m_configFile;
64 }
65
66 void EncodingProfilesDialog::slotLoadProfiles()
67 {
68     profile_list->blockSignals(true);
69     profile_list->clear();
70     QString group;
71     switch (profile_type->currentIndex()) {
72         case 0: 
73             group = "proxy";
74             break;          
75         case 1: 
76             group = "video4linux";
77             break;
78         default:
79         case 2: 
80             group = "decklink";
81             break;
82     }
83
84
85     m_configGroup = new KConfigGroup(m_configFile, group);
86     QMap< QString, QString > values = m_configGroup->entryMap();
87     QMapIterator<QString, QString> i(values);
88     while (i.hasNext()) {
89         i.next();
90         QListWidgetItem *item = new QListWidgetItem(i.key(), profile_list);
91         item->setData(Qt::UserRole, i.value());
92         //cout << i.key() << ": " << i.value() << endl;
93     }
94     profile_list->blockSignals(false);
95     profile_list->setCurrentRow(0);
96     button_delete->setEnabled(profile_list->count() > 0);
97     button_edit->setEnabled(profile_list->count() > 0);
98 }
99
100 void EncodingProfilesDialog::slotShowParams()
101 {
102     profile_parameters->clear();
103     QListWidgetItem *item = profile_list->currentItem();
104     if (!item) return;
105     profile_parameters->setPlainText(item->data(Qt::UserRole).toString().section(";", 0, 0));
106 }
107
108 void EncodingProfilesDialog::slotDeleteProfile()
109 {
110     QListWidgetItem *item = profile_list->currentItem();
111     if (!item) return;
112     QString profile = item->text();
113     m_configGroup->deleteEntry(profile);
114     slotLoadProfiles();
115 }
116
117 void EncodingProfilesDialog::slotAddProfile()
118 {
119     QDialog *d = new QDialog(this);
120     QVBoxLayout *l = new QVBoxLayout;
121     l->addWidget(new QLabel(i18n("Profile name:")));
122     QLineEdit *pname = new QLineEdit;
123     l->addWidget(pname);
124     l->addWidget(new QLabel(i18n("Parameters:")));
125     QPlainTextEdit *pparams = new QPlainTextEdit;
126     l->addWidget(pparams);
127     l->addWidget(new QLabel(i18n("File extension:")));
128     QLineEdit *pext = new QLineEdit;
129     l->addWidget(pext);
130     QDialogButtonBox *box = new QDialogButtonBox(QDialogButtonBox::Save | QDialogButtonBox::Cancel);
131     connect(box, SIGNAL(accepted()), d, SLOT(accept()));
132     connect(box, SIGNAL(rejected()), d, SLOT(reject()));
133     l->addWidget(box);
134     d->setLayout(l);
135     
136     QListWidgetItem *item = profile_list->currentItem();
137     if (item) {
138         QString data = item->data(Qt::UserRole).toString();
139         pparams->setPlainText(data.section(";", 0, 0));
140         pext->setText(data.section(";", 1, 1));
141     }
142     if (d->exec() == QDialog::Accepted) {
143         m_configGroup->writeEntry(pname->text(), pparams->toPlainText() + ";" + pext->text());
144         slotLoadProfiles();
145     }
146     delete d;
147 }
148
149 void EncodingProfilesDialog::slotEditProfile()
150 {
151     QDialog *d = new QDialog(this);
152     QVBoxLayout *l = new QVBoxLayout;
153     l->addWidget(new QLabel(i18n("Profile name:")));
154     QLineEdit *pname = new QLineEdit;
155     l->addWidget(pname);
156     l->addWidget(new QLabel(i18n("Parameters:")));
157     QPlainTextEdit *pparams = new QPlainTextEdit;
158     l->addWidget(pparams);
159     l->addWidget(new QLabel(i18n("File extension:")));
160     QLineEdit *pext = new QLineEdit;
161     l->addWidget(pext);
162     QDialogButtonBox *box = new QDialogButtonBox(QDialogButtonBox::Save | QDialogButtonBox::Cancel);
163     connect(box, SIGNAL(accepted()), d, SLOT(accept()));
164     connect(box, SIGNAL(rejected()), d, SLOT(reject()));
165     l->addWidget(box);
166     d->setLayout(l);
167     
168     QListWidgetItem *item = profile_list->currentItem();
169     if (item) {
170         pname->setText(item->text());
171         QString data = item->data(Qt::UserRole).toString();
172         pparams->setPlainText(data.section(";", 0, 0));
173         pext->setText(data.section(";", 1, 1));
174         pparams->setFocus();
175     }
176     if (d->exec() == QDialog::Accepted) {
177         m_configGroup->writeEntry(pname->text(), pparams->toPlainText() + ";" + pext->text());
178         slotLoadProfiles();
179     }
180     delete d;
181 }
182