]> git.sesse.net Git - kdenlive/blob - src/profilesdialog.cpp
Show project format in tab title / hide tab bar when only one project open
[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     m_view.setupUi(this);
30
31     QStringList profilesFilter;
32     profilesFilter << "*";
33
34     // List the Mlt profiles
35     m_mltProfilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
36     m_view.profiles_list->addItems(m_mltProfilesList);
37
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);
43
44     if (!KdenliveSettings::default_profile().isEmpty()) {
45         int ix = m_view.profiles_list->findText(KdenliveSettings::default_profile());
46         m_view.profiles_list->setCurrentIndex(ix);
47     }
48     slotUpdateDisplay();
49     connect(m_view.profiles_list, SIGNAL(currentIndexChanged(int)), this, SLOT(slotUpdateDisplay()));
50 }
51
52
53 // static
54 QString ProfilesDialog::getProfileDescription(QString name) {
55     QStringList profilesNames;
56     QStringList profilesFiles;
57     QStringList profilesFilter;
58     profilesFilter << "*";
59
60     // List the Mlt profiles
61     profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
62     if (profilesFiles.contains(name)) {
63         KConfig confFile(KdenliveSettings::mltpath() + "/" + name);
64         return confFile.entryMap().value("description");
65     }
66
67     // List custom profiles
68     QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "profiles");
69     for (int i = 0; i < customProfiles.size(); ++i) {
70         profilesFiles = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files);
71         if (profilesFiles.contains(name)) {
72             KConfig confFile(customProfiles.at(i) + "/" + name);
73             return confFile.entryMap().value("description");
74         }
75     }
76
77     return QString();
78 }
79
80 // static
81 QStringList ProfilesDialog::getProfileNames() {
82     QStringList profilesNames;
83     QStringList profilesFiles;
84     QStringList profilesFilter;
85     profilesFilter << "*";
86
87     // List the Mlt profiles
88     profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
89     for (int i = 0; i < profilesFiles.size(); ++i) {
90         KConfig confFile(KdenliveSettings::mltpath() + "/" + profilesFiles.at(i));
91         QString desc = confFile.entryMap().value("description");
92         if (!desc.isEmpty()) profilesNames.append(desc);
93     }
94
95     // List custom profiles
96     QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "profiles");
97     for (int i = 0; i < customProfiles.size(); ++i) {
98         profilesFiles = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files);
99         for (int i = 0; i < profilesFiles.size(); ++i) {
100             KConfig confFile(customProfiles.at(i) + "/" + profilesFiles.at(i));
101             QString desc = confFile.entryMap().value("description");
102             if (!desc.isEmpty()) profilesNames.append(desc);
103         }
104     }
105
106     return profilesNames;
107 }
108
109 // static
110 QMap< QString, QString > ProfilesDialog::getSettingsFromFile(const QString path) {
111     QStringList profilesNames;
112     QStringList profilesFiles;
113     QStringList profilesFilter;
114     profilesFilter << "*";
115
116     // List the Mlt profiles
117     profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
118     for (int i = 0; i < profilesFiles.size(); ++i) {
119         if (profilesFiles.at(i) == path) {
120             KConfig confFile(KdenliveSettings::mltpath() + "/" + profilesFiles.at(i));
121             return confFile.entryMap();
122         }
123     }
124
125     // List custom profiles
126     QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "profiles");
127     for (int i = 0; i < customProfiles.size(); ++i) {
128         QStringList profiles = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files);
129         for (int i = 0; i < profiles.size(); ++i) {
130             if (profiles.at(i) == path) {
131                 KConfig confFile(customProfiles.at(i) + "/" + profiles.at(i));
132                 return confFile.entryMap();
133             }
134         }
135     }
136     return QMap< QString, QString >();
137 }
138
139 // static
140 QMap< QString, QString > ProfilesDialog::getSettingsForProfile(const QString profileName) {
141     QStringList profilesNames;
142     QStringList profilesFiles;
143     QStringList profilesFilter;
144     profilesFilter << "*";
145
146     // List the Mlt profiles
147     profilesFiles = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
148     for (int i = 0; i < profilesFiles.size(); ++i) {
149         KConfig confFile(KdenliveSettings::mltpath() + "/" + profilesFiles.at(i));
150         QMap< QString, QString > values = confFile.entryMap();
151         if (values.value("description") == profileName) return values;
152     }
153
154     // List custom profiles
155     QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "profiles");
156     for (int i = 0; i < customProfiles.size(); ++i) {
157         QStringList profiles = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files);
158         for (int i = 0; i < profiles.size(); ++i) {
159             KConfig confFile(customProfiles.at(i) + "/" + profiles.at(i));
160             QMap< QString, QString > values = confFile.entryMap();
161             if (values.value("description") == profileName) return values;
162         }
163     }
164     return QMap< QString, QString >();
165 }
166
167 void ProfilesDialog::slotUpdateDisplay() {
168     QString currentProfile = m_view.profiles_list->currentText();
169     QString currentProfilePath;
170     if (m_mltProfilesList.indexOf(currentProfile) != -1) {
171         currentProfilePath = KdenliveSettings::mltpath() + "/" + currentProfile;
172         m_isCustomProfile = false;
173     } else {
174         m_isCustomProfile = true;
175         QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "mltprofiles");
176         QStringList profilesFilter;
177         profilesFilter << "*";
178         int i;
179         for (i = 0; i < customProfiles.size(); ++i) {
180             QStringList profs = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files);
181             if (profs.indexOf(currentProfile) != -1) break;
182         }
183         currentProfilePath = customProfiles.at(i) + "/" + currentProfile;
184     }
185     m_view.button_delete->setEnabled(m_isCustomProfile);
186     m_view.properties->setEnabled(m_isCustomProfile);
187
188     KConfig confFile(currentProfilePath);
189     QMap< QString, QString > values = confFile.entryMap();
190     m_view.description->setText(values.value("description"));
191     m_view.size_w->setValue(values.value("width").toInt());
192     m_view.size_h->setValue(values.value("height").toInt());
193     m_view.aspect_num->setValue(values.value("sample_aspect_num").toInt());
194     m_view.aspect_den->setValue(values.value("sample_aspect_den").toInt());
195     m_view.display_num->setValue(values.value("display_aspect_num").toInt());
196     m_view.display_den->setValue(values.value("display_aspect_den").toInt());
197     m_view.frame_num->setValue(values.value("frame_rate_num").toInt());
198     m_view.frame_den->setValue(values.value("frame_rate_den").toInt());
199     m_view.progressive->setChecked(values.value("progressive").toInt());
200
201 }
202
203
204 #include "profilesdialog.moc"
205
206