]> git.sesse.net Git - kdenlive/blob - src/encodingprofilesdialog.cpp
Fix indent
[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("Screen capture"), 2);
43     profile_type->addItem(i18n("Decklink capture"), 3);
44     
45     button_add->setIcon(KIcon("list-add"));
46     button_edit->setIcon(KIcon("document-edit"));
47     button_delete->setIcon(KIcon("list-remove"));
48     button_download->setIcon(KIcon("download"));
49     
50     m_configFile = new KConfig("encodingprofiles.rc", KConfig::CascadeConfig, "appdata");
51     profile_type->setCurrentIndex(profileType);
52     connect(profile_type, SIGNAL(currentIndexChanged(int)), this, SLOT(slotLoadProfiles()));
53     connect(profile_list, SIGNAL(currentRowChanged(int)), this, SLOT(slotShowParams()));
54     connect(button_delete, SIGNAL(clicked()), this, SLOT(slotDeleteProfile()));
55     connect(button_add, SIGNAL(clicked()), this, SLOT(slotAddProfile()));
56     connect(button_edit, SIGNAL(clicked()), this, SLOT(slotEditProfile()));
57     profile_parameters->setMaximumHeight(QFontMetrics(font()).lineSpacing() * 5);
58     slotLoadProfiles();
59 }
60
61 EncodingProfilesDialog::~EncodingProfilesDialog()
62 {
63     delete m_configGroup;
64     delete m_configFile;
65 }
66
67 void EncodingProfilesDialog::slotLoadProfiles()
68 {
69     profile_list->blockSignals(true);
70     profile_list->clear();
71     QString group;
72     switch (profile_type->currentIndex()) {
73     case 0:
74         group = "proxy";
75         break;
76     case 1:
77         group = "video4linux";
78         break;
79     case 2:
80         group = "screengrab";
81         break;
82     default:
83     case 3:
84         group = "decklink";
85         break;
86     }
87
88     delete m_configGroup;
89     m_configGroup = new KConfigGroup(m_configFile, group);
90     QMap< QString, QString > values = m_configGroup->entryMap();
91     QMapIterator<QString, QString> i(values);
92     while (i.hasNext()) {
93         i.next();
94         QListWidgetItem *item = new QListWidgetItem(i.key(), profile_list);
95         item->setData(Qt::UserRole, i.value());
96         //cout << i.key() << ": " << i.value() << endl;
97     }
98     profile_list->blockSignals(false);
99     profile_list->setCurrentRow(0);
100     button_delete->setEnabled(profile_list->count() > 0);
101     button_edit->setEnabled(profile_list->count() > 0);
102 }
103
104 void EncodingProfilesDialog::slotShowParams()
105 {
106     profile_parameters->clear();
107     QListWidgetItem *item = profile_list->currentItem();
108     if (!item)
109         return;
110     profile_parameters->setPlainText(item->data(Qt::UserRole).toString().section(';', 0, 0));
111 }
112
113 void EncodingProfilesDialog::slotDeleteProfile()
114 {
115     QListWidgetItem *item = profile_list->currentItem();
116     if (!item)
117         return;
118     QString profile = item->text();
119     m_configGroup->deleteEntry(profile);
120     slotLoadProfiles();
121 }
122
123 void EncodingProfilesDialog::slotAddProfile()
124 {
125     QDialog *d = new QDialog(this);
126     QVBoxLayout *l = new QVBoxLayout;
127     l->addWidget(new QLabel(i18n("Profile name:")));
128     QLineEdit *pname = new QLineEdit;
129     l->addWidget(pname);
130     l->addWidget(new QLabel(i18n("Parameters:")));
131     QPlainTextEdit *pparams = new QPlainTextEdit;
132     l->addWidget(pparams);
133     l->addWidget(new QLabel(i18n("File extension:")));
134     QLineEdit *pext = new QLineEdit;
135     l->addWidget(pext);
136     QDialogButtonBox *box = new QDialogButtonBox(QDialogButtonBox::Save | QDialogButtonBox::Cancel);
137     connect(box, SIGNAL(accepted()), d, SLOT(accept()));
138     connect(box, SIGNAL(rejected()), d, SLOT(reject()));
139     l->addWidget(box);
140     d->setLayout(l);
141     
142     QListWidgetItem *item = profile_list->currentItem();
143     if (item) {
144         QString data = item->data(Qt::UserRole).toString();
145         pparams->setPlainText(data.section(';', 0, 0));
146         pext->setText(data.section(';', 1, 1));
147     }
148     if (d->exec() == QDialog::Accepted) {
149         m_configGroup->writeEntry(pname->text(), pparams->toPlainText() + ';' + pext->text());
150         slotLoadProfiles();
151     }
152     delete d;
153 }
154
155 void EncodingProfilesDialog::slotEditProfile()
156 {
157     QDialog *d = new QDialog(this);
158     QVBoxLayout *l = new QVBoxLayout;
159     l->addWidget(new QLabel(i18n("Profile name:")));
160     QLineEdit *pname = new QLineEdit;
161     l->addWidget(pname);
162     l->addWidget(new QLabel(i18n("Parameters:")));
163     QPlainTextEdit *pparams = new QPlainTextEdit;
164     l->addWidget(pparams);
165     l->addWidget(new QLabel(i18n("File extension:")));
166     QLineEdit *pext = new QLineEdit;
167     l->addWidget(pext);
168     QDialogButtonBox *box = new QDialogButtonBox(QDialogButtonBox::Save | QDialogButtonBox::Cancel);
169     connect(box, SIGNAL(accepted()), d, SLOT(accept()));
170     connect(box, SIGNAL(rejected()), d, SLOT(reject()));
171     l->addWidget(box);
172     d->setLayout(l);
173     
174     QListWidgetItem *item = profile_list->currentItem();
175     if (item) {
176         pname->setText(item->text());
177         QString data = item->data(Qt::UserRole).toString();
178         pparams->setPlainText(data.section(';', 0, 0));
179         pext->setText(data.section(';', 1, 1));
180         pparams->setFocus();
181     }
182     if (d->exec() == QDialog::Accepted) {
183         m_configGroup->writeEntry(pname->text(), pparams->toPlainText() + ';' + pext->text());
184         slotLoadProfiles();
185     }
186     delete d;
187 }
188
189
190 #include "encodingprofilesdialog.moc"