]> git.sesse.net Git - kdenlive/blob - src/profilesdialog.cpp
Reindent all source files
[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 QStringList ProfilesDialog::getProfileNames() {
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     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);
66     }
67
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);
76         }
77     }
78
79     return profilesNames;
80 }
81
82 // static
83 QMap< QString, QString > ProfilesDialog::getSettingsFromFile(const QString path) {
84     QStringList profilesNames;
85     QStringList profilesFiles;
86     QStringList profilesFilter;
87     profilesFilter << "*";
88
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();
95         }
96     }
97
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();
106             }
107         }
108     }
109     return QMap< QString, QString >();
110 }
111
112 // static
113 QMap< QString, QString > ProfilesDialog::getSettingsForProfile(const QString profileName) {
114     QStringList profilesNames;
115     QStringList profilesFiles;
116     QStringList profilesFilter;
117     profilesFilter << "*";
118
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;
125     }
126
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;
135         }
136     }
137     return QMap< QString, QString >();
138 }
139
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;
146     } else {
147         m_isCustomProfile = true;
148         QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "mltprofiles");
149         QStringList profilesFilter;
150         profilesFilter << "*";
151         int i;
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;
155         }
156         currentProfilePath = customProfiles.at(i) + "/" + currentProfile;
157     }
158     m_view.button_delete->setEnabled(m_isCustomProfile);
159     m_view.properties->setEnabled(m_isCustomProfile);
160
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());
173
174 }
175
176
177 #include "profilesdialog.moc"
178
179