]> git.sesse.net Git - kdenlive/blob - src/slideshowclip.cpp
several updates for slideshow clips
[kdenlive] / src / slideshowclip.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 #include <KFileItem>
25
26 #include "kdenlivesettings.h"
27 #include "slideshowclip.h"
28
29 #define TYPE_JPEG 0
30 #define TYPE_PNG 1
31 #define TYPE_BMP 2
32 #define TYPE_GIF 3
33
34 SlideshowClip::SlideshowClip(QWidget * parent): QDialog(parent), m_count(0) {
35     setFont(KGlobalSettings::toolBarFont());
36     setWindowTitle(i18n("Add Slideshow Clip"));
37     m_view.setupUi(this);
38     m_view.clip_name->setText(i18n("Slideshow Clip"));
39     m_view.folder_url->setMode(KFile::Directory);
40     m_view.icon_list->setIconSize(QSize(50, 50));
41     connect(m_view.folder_url, SIGNAL(textChanged(const QString &)), this, SLOT(parseFolder()));
42     connect(m_view.image_type, SIGNAL(currentIndexChanged(int)), this, SLOT(parseFolder()));
43     m_view.image_type->addItem("JPG");
44     m_view.image_type->addItem("PNG");
45     m_view.image_type->addItem("BMP");
46     m_view.image_type->addItem("GIF");
47     m_view.clip_duration->setText("00:00:03:00");
48     m_view.folder_url->setUrl(QDir::homePath());
49     adjustSize();
50 }
51
52 void SlideshowClip::parseFolder() {
53     m_view.icon_list->clear();
54     QDir dir(m_view.folder_url->url().path());
55
56     QStringList filters;
57     switch (m_view.image_type->currentIndex()) {
58     case TYPE_PNG:
59         filters << "*.png";
60         break;
61     case TYPE_BMP:
62         filters << "*.bmp";
63         break;
64     case TYPE_GIF:
65         filters << "*.gif";
66         break;
67     default:
68         filters << "*.jpg" << "*.jpeg";
69         break;
70     }
71
72     dir.setNameFilters(filters);
73     QStringList result = dir.entryList(QDir::Files);
74     m_count = result.count();
75     if (m_count == 0) m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
76     else m_view.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
77     m_view.label_info->setText(i18n("%1 images found", m_count));
78     foreach(QString path, result) {
79         QIcon icon(dir.filePath(path));
80         QListWidgetItem *item = new QListWidgetItem(icon, KUrl(path).fileName());
81         m_view.icon_list->addItem(item);
82     }
83 }
84
85 QString SlideshowClip::selectedPath() const {
86     QString extension;
87     switch (m_view.image_type->currentIndex()) {
88     case TYPE_PNG:
89         extension = "/.all.png";
90         break;
91     case TYPE_BMP:
92         extension = "/.all.bmp";
93         break;
94     case TYPE_GIF:
95         extension = "/.all.gif";
96         break;
97     default:
98         extension = "/.all.jpg";
99         break;
100     }
101     return m_view.folder_url->url().path() + extension;
102 }
103
104
105 QString SlideshowClip::clipName() const {
106     return m_view.clip_name->text();
107 }
108
109 QString SlideshowClip::clipDuration() const {
110     return m_view.clip_duration->text();
111 }
112
113 int SlideshowClip::imageCount() const {
114     return m_count;
115 }
116
117 bool SlideshowClip::loop() const {
118     return m_view.slide_loop->isChecked();
119 }
120 #include "slideshowclip.moc"
121
122