]> git.sesse.net Git - kdenlive/blob - src/profilesdialog.cpp
0a471c08492a7ead44ab7bbe864a1be144c1132d
[kdenlive] / src / profilesdialog.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 <QDir>
21
22 #include <KStandardDirs>
23 #include <KDebug>
24
25 #include "kdenlivesettings.h"
26 #include "profilesdialog.h"
27
28 ProfilesDialog::ProfilesDialog(QWidget * parent): QDialog(parent), m_isCustomProfile(false)
29 {
30   m_view.setupUi(this);
31
32   QStringList profilesFilter;
33   profilesFilter<<"*";
34
35   // List the Mlt profiles
36   m_mltProfilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
37   m_view.profiles_list->addItems(m_mltProfilesList);
38
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);
44
45   if (!KdenliveSettings::default_profile().isEmpty()) {
46     int ix = m_view.profiles_list->findText(KdenliveSettings::default_profile());
47     m_view.profiles_list->setCurrentIndex(ix);
48   }
49   slotUpdateDisplay();
50   connect(m_view.profiles_list, SIGNAL(currentIndexChanged( int )), this, SLOT(slotUpdateDisplay()));
51 }
52
53
54 // static
55 QStringList ProfilesDialog::getProfileNames()
56 {
57   QStringList profilesNames;
58   QStringList profilesFiles;
59   QStringList profilesFilter;
60   profilesFilter<<"*";
61
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);
68   }
69
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);
78     }
79   }
80
81   return profilesNames;
82 }
83
84 // static
85 QMap< QString, QString > ProfilesDialog::getSettingsFromFile(const QString path)
86 {
87   QStringList profilesNames;
88   QStringList profilesFiles;
89   QStringList profilesFilter;
90   profilesFilter<<"*";
91
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();
98     }
99   }
100
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();
109       }
110     }
111   }
112   return QMap< QString, QString >();
113 }
114
115 // static
116 QMap< QString, QString > ProfilesDialog::getSettingsForProfile(const QString profileName)
117 {
118   QStringList profilesNames;
119   QStringList profilesFiles;
120   QStringList profilesFilter;
121   profilesFilter<<"*";
122
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;
129   }
130
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;
139     }
140   }
141   return QMap< QString, QString >();
142 }
143
144 void ProfilesDialog::slotUpdateDisplay()
145 {
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;
151   }
152   else {
153     m_isCustomProfile = true;
154     QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "mltprofiles");
155     QStringList profilesFilter;
156     profilesFilter<<"*";
157     int i;
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;
161     }
162     currentProfilePath = customProfiles.at(i) + "/" + currentProfile;
163   }
164   m_view.button_delete->setEnabled(m_isCustomProfile);
165   m_view.properties->setEnabled(m_isCustomProfile);
166
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());
179
180 }
181
182
183 #include "profilesdialog.moc"
184
185