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