1 /***************************************************************************
2 * Copyright (C) 2008 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
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 <KStandardDirs>
25 #include "kdenlivesettings.h"
26 #include "profilesdialog.h"
28 ProfilesDialog::ProfilesDialog(QWidget * parent): QDialog(parent), m_isCustomProfile(false)
32 QStringList profilesFilter;
35 // List the Mlt profiles
36 m_mltProfilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
37 m_view.profiles_list->addItems(m_mltProfilesList);
39 // List custom profiles
40 QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "profiles");
41 for (int i = 0; i < customProfiles.size(); ++i)
42 m_customProfilesList << QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files);
43 m_view.profiles_list->addItems(m_customProfilesList);
45 if (!KdenliveSettings::default_profile().isEmpty()) {
46 int ix = m_view.profiles_list->findText(KdenliveSettings::default_profile());
47 m_view.profiles_list->setCurrentIndex(ix);
50 connect(m_view.profiles_list, SIGNAL(currentIndexChanged( int )), this, SLOT(slotUpdateDisplay()));
55 QStringList ProfilesDialog::getProfileNames()
57 QStringList profilesNames;
58 QStringList profilesFiles;
59 QStringList profilesFilter;
62 // List the Mlt profiles
63 profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
64 for (int i = 0; i < profilesFiles.size(); ++i) {
65 KConfig confFile(KdenliveSettings::mltpath() + "/" + profilesFiles.at(i));
66 QString desc = confFile.entryMap().value("description");
67 if (!desc.isEmpty()) profilesNames.append(desc);
70 // List custom profiles
71 QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "profiles");
72 for (int i = 0; i < customProfiles.size(); ++i) {
73 profilesFiles = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files);
74 for (int i = 0; i < profilesFiles.size(); ++i) {
75 KConfig confFile(customProfiles.at(i) + "/" + profilesFiles.at(i));
76 QString desc = confFile.entryMap().value("description");
77 if (!desc.isEmpty()) profilesNames.append(desc);
85 QMap< QString, QString > ProfilesDialog::getSettingsFromFile(const QString path)
87 QStringList profilesNames;
88 QStringList profilesFiles;
89 QStringList profilesFilter;
92 // List the Mlt profiles
93 profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
94 for (int i = 0; i < profilesFiles.size(); ++i) {
95 if (profilesFiles.at(i) == path) {
96 KConfig confFile(KdenliveSettings::mltpath() + "/" + profilesFiles.at(i));
97 return confFile.entryMap();
101 // List custom profiles
102 QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "profiles");
103 for (int i = 0; i < customProfiles.size(); ++i) {
104 QStringList profiles = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files);
105 for (int i = 0; i < profiles.size(); ++i) {
106 if (profiles.at(i) == path) {
107 KConfig confFile(customProfiles.at(i) + "/" + profiles.at(i));
108 return confFile.entryMap();
112 return QMap< QString, QString >();
116 QMap< QString, QString > ProfilesDialog::getSettingsForProfile(const QString profileName)
118 QStringList profilesNames;
119 QStringList profilesFiles;
120 QStringList profilesFilter;
123 // List the Mlt profiles
124 profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
125 for (int i = 0; i < profilesFiles.size(); ++i) {
126 KConfig confFile(KdenliveSettings::mltpath() + "/" + profilesFiles.at(i));
127 QMap< QString, QString > values = confFile.entryMap();
128 if (values.value("description") == profileName) return values;
131 // List custom profiles
132 QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "profiles");
133 for (int i = 0; i < customProfiles.size(); ++i) {
134 QStringList profiles = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files);
135 for (int i = 0; i < profiles.size(); ++i) {
136 KConfig confFile(customProfiles.at(i) + "/" + profiles.at(i));
137 QMap< QString, QString > values = confFile.entryMap();
138 if (values.value("description") == profileName) return values;
141 return QMap< QString, QString >();
144 void ProfilesDialog::slotUpdateDisplay()
146 QString currentProfile = m_view.profiles_list->currentText();
147 QString currentProfilePath;
148 if (m_mltProfilesList.indexOf(currentProfile) != -1) {
149 currentProfilePath = KdenliveSettings::mltpath() + "/" + currentProfile;
150 m_isCustomProfile = false;
153 m_isCustomProfile = true;
154 QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "mltprofiles");
155 QStringList profilesFilter;
158 for (i = 0; i < customProfiles.size(); ++i) {
159 QStringList profs = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files);
160 if (profs.indexOf(currentProfile) != -1) break;
162 currentProfilePath = customProfiles.at(i) + "/" + currentProfile;
164 m_view.button_delete->setEnabled(m_isCustomProfile);
165 m_view.properties->setEnabled(m_isCustomProfile);
167 KConfig confFile(currentProfilePath);
168 QMap< QString, QString > values = confFile.entryMap();
169 m_view.description->setText(values.value("description"));
170 m_view.size_w->setValue(values.value("width").toInt());
171 m_view.size_h->setValue(values.value("height").toInt());
172 m_view.aspect_num->setValue(values.value("sample_aspect_num").toInt());
173 m_view.aspect_den->setValue(values.value("sample_aspect_den").toInt());
174 m_view.display_num->setValue(values.value("display_aspect_num").toInt());
175 m_view.display_den->setValue(values.value("display_aspect_den").toInt());
176 m_view.frame_num->setValue(values.value("frame_rate_num").toInt());
177 m_view.frame_den->setValue(values.value("frame_rate_den").toInt());
178 m_view.progressive->setChecked(values.value("progressive").toInt());
183 #include "profilesdialog.moc"