]> git.sesse.net Git - kdenlive/blob - src/profilesdialog.cpp
Start of project settings dialog
[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::getSettingsForProfile(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     KConfig confFile(KdenliveSettings::mltpath() + "/" + profilesFiles.at(i));
96     QMap< QString, QString > values = confFile.entryMap();
97     if (values.value("description") == path) return values;
98   }
99
100   // List custom profiles
101   QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "profiles");
102   for (int i = 0; i < customProfiles.size(); ++i) {
103     QStringList profiles = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files);
104     for (int i = 0; i < profiles.size(); ++i) {
105       KConfig confFile(customProfiles.at(i) + "/" + profiles.at(i));
106       QMap< QString, QString > values = confFile.entryMap();
107       if (values.value("description") == path) return values;
108     }
109   }
110   return QMap< QString, QString >();
111 }
112
113 void ProfilesDialog::slotUpdateDisplay()
114 {
115   QString currentProfile = m_view.profiles_list->currentText();
116   QString currentProfilePath;
117   if (m_mltProfilesList.indexOf(currentProfile) != -1) { 
118     currentProfilePath = KdenliveSettings::mltpath() + "/" + currentProfile;
119     m_isCustomProfile = false;
120   }
121   else {
122     m_isCustomProfile = true;
123     QStringList customProfiles = KGlobal::dirs()->findDirs("appdata", "mltprofiles");
124     QStringList profilesFilter;
125     profilesFilter<<"*";
126     int i;
127     for (i = 0; i < customProfiles.size(); ++i) {
128       QStringList profs = QDir(customProfiles.at(i)).entryList(profilesFilter, QDir::Files);
129       if (profs.indexOf(currentProfile) != -1) break;
130     }
131     currentProfilePath = customProfiles.at(i) + "/" + currentProfile;
132   }
133   m_view.button_delete->setEnabled(m_isCustomProfile);
134   m_view.properties->setEnabled(m_isCustomProfile);
135
136   KConfig confFile(currentProfilePath);
137   QMap< QString, QString > values = confFile.entryMap();
138   m_view.description->setText(values.value("description"));
139   m_view.size_w->setValue(values.value("width").toInt());
140   m_view.size_h->setValue(values.value("height").toInt());
141   m_view.aspect_num->setValue(values.value("sample_aspect_num").toInt());
142   m_view.aspect_den->setValue(values.value("sample_aspect_den").toInt());
143   m_view.display_num->setValue(values.value("display_aspect_num").toInt());
144   m_view.display_den->setValue(values.value("display_aspect_den").toInt());
145   m_view.frame_num->setValue(values.value("frame_rate_num").toInt());
146   m_view.frame_den->setValue(values.value("frame_rate_den").toInt());
147   m_view.progressive->setChecked(values.value("progressive").toInt());
148
149 }
150
151
152 #include "profilesdialog.moc"
153
154