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) {
31 QStringList profilesFilter;
32 profilesFilter << "*";
34 // List the Mlt profiles
35 m_mltProfilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
36 m_view.profiles_list->addItems(m_mltProfilesList);
38 // List custom profiles
39 QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "profiles");
40 for (int i = 0; i < customProfiles.size(); ++i)
41 m_customProfilesList << QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files);
42 m_view.profiles_list->addItems(m_customProfilesList);
44 if (!KdenliveSettings::default_profile().isEmpty()) {
45 int ix = m_view.profiles_list->findText(KdenliveSettings::default_profile());
46 m_view.profiles_list->setCurrentIndex(ix);
49 connect(m_view.profiles_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateDisplay()));
54 QStringList ProfilesDialog::getProfileNames() {
55 QStringList profilesNames;
56 QStringList profilesFiles;
57 QStringList profilesFilter;
58 profilesFilter << "*";
60 // List the Mlt profiles
61 profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
62 for (int i = 0; i < profilesFiles.size(); ++i) {
63 KConfig confFile(KdenliveSettings::mltpath() + "/" + profilesFiles.at(i));
64 QString desc = confFile.entryMap().value("description");
65 if (!desc.isEmpty()) profilesNames.append(desc);
68 // List custom profiles
69 QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "profiles");
70 for (int i = 0; i < customProfiles.size(); ++i) {
71 profilesFiles = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files);
72 for (int i = 0; i < profilesFiles.size(); ++i) {
73 KConfig confFile(customProfiles.at(i) + "/" + profilesFiles.at(i));
74 QString desc = confFile.entryMap().value("description");
75 if (!desc.isEmpty()) profilesNames.append(desc);
83 QMap< QString, QString > ProfilesDialog::getSettingsFromFile(const QString path) {
84 QStringList profilesNames;
85 QStringList profilesFiles;
86 QStringList profilesFilter;
87 profilesFilter << "*";
89 // List the Mlt profiles
90 profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
91 for (int i = 0; i < profilesFiles.size(); ++i) {
92 if (profilesFiles.at(i) == path) {
93 KConfig confFile(KdenliveSettings::mltpath() + "/" + profilesFiles.at(i));
94 return confFile.entryMap();
98 // List custom profiles
99 QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "profiles");
100 for (int i = 0; i < customProfiles.size(); ++i) {
101 QStringList profiles = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files);
102 for (int i = 0; i < profiles.size(); ++i) {
103 if (profiles.at(i) == path) {
104 KConfig confFile(customProfiles.at(i) + "/" + profiles.at(i));
105 return confFile.entryMap();
109 return QMap< QString, QString >();
113 QMap< QString, QString > ProfilesDialog::getSettingsForProfile(const QString profileName) {
114 QStringList profilesNames;
115 QStringList profilesFiles;
116 QStringList profilesFilter;
117 profilesFilter << "*";
119 // List the Mlt profiles
120 profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
121 for (int i = 0; i < profilesFiles.size(); ++i) {
122 KConfig confFile(KdenliveSettings::mltpath() + "/" + profilesFiles.at(i));
123 QMap< QString, QString > values = confFile.entryMap();
124 if (values.value("description") == profileName) return values;
127 // List custom profiles
128 QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "profiles");
129 for (int i = 0; i < customProfiles.size(); ++i) {
130 QStringList profiles = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files);
131 for (int i = 0; i < profiles.size(); ++i) {
132 KConfig confFile(customProfiles.at(i) + "/" + profiles.at(i));
133 QMap< QString, QString > values = confFile.entryMap();
134 if (values.value("description") == profileName) return values;
137 return QMap< QString, QString >();
140 void ProfilesDialog::slotUpdateDisplay() {
141 QString currentProfile = m_view.profiles_list->currentText();
142 QString currentProfilePath;
143 if (m_mltProfilesList.indexOf(currentProfile) != -1) {
144 currentProfilePath = KdenliveSettings::mltpath() + "/" + currentProfile;
145 m_isCustomProfile = false;
147 m_isCustomProfile = true;
148 QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "mltprofiles");
149 QStringList profilesFilter;
150 profilesFilter << "*";
152 for (i = 0; i < customProfiles.size(); ++i) {
153 QStringList profs = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files);
154 if (profs.indexOf(currentProfile) != -1) break;
156 currentProfilePath = customProfiles.at(i) + "/" + currentProfile;
158 m_view.button_delete->setEnabled(m_isCustomProfile);
159 m_view.properties->setEnabled(m_isCustomProfile);
161 KConfig confFile(currentProfilePath);
162 QMap< QString, QString > values = confFile.entryMap();
163 m_view.description->setText(values.value("description"));
164 m_view.size_w->setValue(values.value("width").toInt());
165 m_view.size_h->setValue(values.value("height").toInt());
166 m_view.aspect_num->setValue(values.value("sample_aspect_num").toInt());
167 m_view.aspect_den->setValue(values.value("sample_aspect_den").toInt());
168 m_view.display_num->setValue(values.value("display_aspect_num").toInt());
169 m_view.display_den->setValue(values.value("display_aspect_den").toInt());
170 m_view.frame_num->setValue(values.value("frame_rate_num").toInt());
171 m_view.frame_den->setValue(values.value("frame_rate_den").toInt());
172 m_view.progressive->setChecked(values.value("progressive").toInt());
177 #include "profilesdialog.moc"