]> git.sesse.net Git - kdenlive/blob - src/mainwindow.cpp
Allow document closing
[kdenlive] / src / mainwindow.cpp
1 /***************************************************************************
2  *   Copyright (C) 2007 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
21
22 #include <QTextStream>
23 #include <QTimer>
24 #include <QAction>
25 #include <QtTest>
26 #include <QtCore>
27
28 #include <KApplication>
29 #include <KAction>
30 #include <KLocale>
31 #include <KActionCollection>
32 #include <KStandardAction>
33 #include <KFileDialog>
34 #include <KMessageBox>
35 #include <KDebug>
36 #include <KIO/NetAccess>
37 #include <KSaveFile>
38 #include <KRuler>
39 #include <KConfigDialog>
40 #include <KXMLGUIFactory>
41 #include <KStatusBar>
42 #include <kstandarddirs.h>
43 #include <KUrlRequesterDialog>
44
45 #include <mlt++/Mlt.h>
46
47 #include "mainwindow.h"
48 #include "kdenlivesettings.h"
49 #include "kdenlivesettingsdialog.h"
50 #include "initeffects.h"
51 #include "profilesdialog.h"
52 #include "projectsettings.h"
53 #include "events.h"
54
55 #define ID_STATUS_MSG 1
56 #define ID_EDITMODE_MSG 2
57 #define ID_TIMELINE_MSG 3
58 #define ID_TIMELINE_POS 4
59 #define ID_TIMELINE_FORMAT 5
60
61 MainWindow::MainWindow(QWidget *parent)
62         : KXmlGuiWindow(parent),
63         fileName(QString()), m_activeDocument(NULL), m_activeTimeline(NULL), m_commandStack(NULL) {
64     parseProfiles();
65     m_timelineArea = new KTabWidget(this);
66     m_timelineArea->setHoverCloseButton(true);
67     m_timelineArea->setTabReorderingEnabled(true);
68     m_timelineArea->setTabBarHidden(true);
69     connect(m_timelineArea, SIGNAL(currentChanged(int)), this, SLOT(activateDocument()));
70     connect(m_timelineArea, SIGNAL(closeRequest(QWidget *)), this, SLOT(closeDocument(QWidget *)));
71
72
73     initEffects::parseEffectFiles(&m_audioEffects, &m_videoEffects);
74     m_monitorManager = new MonitorManager();
75
76     projectListDock = new QDockWidget(i18n("Project Tree"), this);
77     projectListDock->setObjectName("project_tree");
78     m_projectList = new ProjectList(this);
79     projectListDock->setWidget(m_projectList);
80     addDockWidget(Qt::TopDockWidgetArea, projectListDock);
81
82     effectListDock = new QDockWidget(i18n("Effect List"), this);
83     effectListDock->setObjectName("effect_list");
84     m_effectList = new EffectsListView(&m_audioEffects, &m_videoEffects, &m_customEffects);
85
86     //m_effectList = new KListWidget(this);
87     effectListDock->setWidget(m_effectList);
88     addDockWidget(Qt::TopDockWidgetArea, effectListDock);
89
90     effectStackDock = new QDockWidget(i18n("Effect Stack"), this);
91     effectStackDock->setObjectName("effect_stack");
92     effectStack = new EffectStackView(&m_audioEffects, &m_videoEffects, &m_customEffects, this);
93     effectStackDock->setWidget(effectStack);
94     addDockWidget(Qt::TopDockWidgetArea, effectStackDock);
95
96     transitionConfigDock = new QDockWidget(i18n("Transition"), this);
97     transitionConfigDock->setObjectName("transition");
98     transitionConfig = new KListWidget(this);
99     transitionConfigDock->setWidget(transitionConfig);
100     addDockWidget(Qt::TopDockWidgetArea, transitionConfigDock);
101
102
103     clipMonitorDock = new QDockWidget(i18n("Clip Monitor"), this);
104     clipMonitorDock->setObjectName("clip_monitor");
105     m_clipMonitor = new Monitor("clip", m_monitorManager, this);
106     clipMonitorDock->setWidget(m_clipMonitor);
107     addDockWidget(Qt::TopDockWidgetArea, clipMonitorDock);
108     //m_clipMonitor->stop();
109
110     projectMonitorDock = new QDockWidget(i18n("Project Monitor"), this);
111     projectMonitorDock->setObjectName("project_monitor");
112     m_projectMonitor = new Monitor("project", m_monitorManager, this);
113     projectMonitorDock->setWidget(m_projectMonitor);
114     addDockWidget(Qt::TopDockWidgetArea, projectMonitorDock);
115
116     undoViewDock = new QDockWidget(i18n("Undo History"), this);
117     undoViewDock->setObjectName("undo_history");
118     m_undoView = new QUndoView(this);
119     undoViewDock->setWidget(m_undoView);
120     m_undoView->setStack(m_commandStack);
121     addDockWidget(Qt::TopDockWidgetArea, undoViewDock);
122
123     overviewDock = new QDockWidget(i18n("Project Overview"), this);
124     overviewDock->setObjectName("project_overview");
125     m_overView = new CustomTrackView(NULL, NULL, this);
126     overviewDock->setWidget(m_overView);
127     addDockWidget(Qt::TopDockWidgetArea, overviewDock);
128
129     setupActions();
130     tabifyDockWidget(projectListDock, effectListDock);
131     tabifyDockWidget(projectListDock, effectStackDock);
132     tabifyDockWidget(projectListDock, transitionConfigDock);
133     tabifyDockWidget(projectListDock, undoViewDock);
134     projectListDock->raise();
135
136     tabifyDockWidget(clipMonitorDock, projectMonitorDock);
137     setCentralWidget(m_timelineArea);
138
139     m_timecodeFormat = new KComboBox(this);
140     m_timecodeFormat->addItem(i18n("hh:mm:ss::ff"));
141     m_timecodeFormat->addItem(i18n("Frames"));
142
143     statusProgressBar = new QProgressBar(this);
144     statusProgressBar->setMinimum(0);
145     statusProgressBar->setMaximum(100);
146     statusProgressBar->setMaximumWidth(150);
147     statusProgressBar->setVisible(false);
148     statusLabel = new QLabel(this);
149
150     statusBar()->insertPermanentWidget(0, statusProgressBar, 1);
151     statusBar()->insertPermanentWidget(1, statusLabel, 1);
152     statusBar()->insertPermanentFixedItem("00:00:00:00", ID_TIMELINE_POS);
153     statusBar()->insertPermanentWidget(ID_TIMELINE_FORMAT, m_timecodeFormat);
154
155     setupGUI(Default, "kdenliveui.rc");
156
157     connect(projectMonitorDock, SIGNAL(visibilityChanged(bool)), m_projectMonitor, SLOT(refreshMonitor(bool)));
158     connect(clipMonitorDock, SIGNAL(visibilityChanged(bool)), m_clipMonitor, SLOT(refreshMonitor(bool)));
159     connect(m_monitorManager, SIGNAL(connectMonitors()), this, SLOT(slotConnectMonitors()));
160     connect(m_monitorManager, SIGNAL(raiseClipMonitor(bool)), this, SLOT(slotRaiseMonitor(bool)));
161     connect(m_effectList, SIGNAL(addEffect(QDomElement)), this, SLOT(slotAddEffect(QDomElement)));
162     m_monitorManager->initMonitors(m_clipMonitor, m_projectMonitor);
163
164     setAutoSaveSettings();
165     newFile();
166 }
167
168 //virtual
169 bool MainWindow::queryClose() {
170     saveOptions();
171     switch (KMessageBox::warningYesNoCancel(this, i18n("Save changes to document ?"))) {
172     case KMessageBox::Yes :
173         // save document here. If saving fails, return false;
174         return true;
175     case KMessageBox::No :
176         return true;
177     default: // cancel
178         return false;
179     }
180 }
181
182 void MainWindow::slotAddEffect(QDomElement effect, GenTime pos, int track) {
183     if (!m_activeDocument) return;
184     if (effect.isNull()) {
185         kDebug() << "--- ERROR, TRYING TO APPEND NULL EFFECT";
186         return;
187     }
188     TrackView *currentTimeLine = (TrackView *) m_timelineArea->currentWidget();
189     currentTimeLine->projectView()->slotAddEffect(effect, pos, track);
190 }
191
192 void MainWindow::slotRaiseMonitor(bool clipMonitor) {
193     if (clipMonitor) clipMonitorDock->raise();
194     else projectMonitorDock->raise();
195 }
196
197 void MainWindow::slotSetClipDuration(int id, int duration) {
198     if (!m_activeDocument) return;
199     m_activeDocument->setProducerDuration(id, duration);
200 }
201
202 void MainWindow::slotConnectMonitors() {
203
204     m_projectList->setRenderer(m_clipMonitor->render);
205
206     connect(m_projectList, SIGNAL(clipSelected(const QDomElement &)), m_clipMonitor, SLOT(slotSetXml(const QDomElement &)));
207
208     connect(m_projectList, SIGNAL(receivedClipDuration(int, int)), this, SLOT(slotSetClipDuration(int, int)));
209
210     connect(m_projectList, SIGNAL(getFileProperties(const QDomElement &, int)), m_clipMonitor->render, SLOT(getFileProperties(const QDomElement &, int)));
211
212     connect(m_clipMonitor->render, SIGNAL(replyGetImage(int, int, const QPixmap &, int, int)), m_projectList, SLOT(slotReplyGetImage(int, int, const QPixmap &, int, int)));
213
214     connect(m_clipMonitor->render, SIGNAL(replyGetFileProperties(int, const QMap < QString, QString > &, const QMap < QString, QString > &)), m_projectList, SLOT(slotReplyGetFileProperties(int, const QMap < QString, QString > &, const QMap < QString, QString > &)));
215
216 }
217
218 void MainWindow::setupActions() {
219     KAction* clearAction = new KAction(this);
220     clearAction->setText(i18n("Clear"));
221     clearAction->setIcon(KIcon("document-new"));
222     clearAction->setShortcut(Qt::CTRL + Qt::Key_W);
223     actionCollection()->addAction("clear", clearAction);
224     /*connect(clearAction, SIGNAL(triggered(bool)),
225             textArea, SLOT(clear()));*/
226
227     KAction* profilesAction = new KAction(this);
228     profilesAction->setText(i18n("Manage Profiles"));
229     profilesAction->setIcon(KIcon("document-new"));
230     actionCollection()->addAction("manage_profiles", profilesAction);
231     connect(profilesAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProfiles()));
232
233     KAction* projectAction = new KAction(this);
234     projectAction->setText(i18n("Project Settings"));
235     projectAction->setIcon(KIcon("document-new"));
236     actionCollection()->addAction("project_settings", projectAction);
237     connect(projectAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProjectSettings()));
238
239     KAction* monitorPlay = new KAction(this);
240     monitorPlay->setText(i18n("Play"));
241     monitorPlay->setIcon(KIcon("media-playback-start"));
242     monitorPlay->setShortcut(Qt::Key_Space);
243     actionCollection()->addAction("monitor_play", monitorPlay);
244     connect(monitorPlay, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotPlay()));
245
246     KStandardAction::quit(kapp, SLOT(quit()),
247                           actionCollection());
248
249     KStandardAction::open(this, SLOT(openFile()),
250                           actionCollection());
251
252     m_fileOpenRecent = KStandardAction::openRecent(this, SLOT(openFile(const KUrl &)),
253                        actionCollection());
254
255     KStandardAction::save(this, SLOT(saveFile()),
256                           actionCollection());
257
258     KStandardAction::saveAs(this, SLOT(saveFileAs()),
259                             actionCollection());
260
261     KStandardAction::openNew(this, SLOT(newFile()),
262                              actionCollection());
263
264     KStandardAction::preferences(this, SLOT(slotPreferences()),
265                                  actionCollection());
266
267     /*KStandardAction::undo(this, SLOT(undo()),
268                           actionCollection());
269
270     KStandardAction::redo(this, SLOT(redo()),
271                           actionCollection());*/
272
273     connect(actionCollection(), SIGNAL(actionHighlighted(QAction*)),
274             this, SLOT(slotDisplayActionMessage(QAction*)));
275     //connect(actionCollection(), SIGNAL( clearStatusText() ),
276     //statusBar(), SLOT( clear() ) );
277
278     readOptions();
279
280     /*m_redo = m_commandStack->createRedoAction(actionCollection());
281     m_undo = m_commandStack->createUndoAction(actionCollection());*/
282 }
283
284 void MainWindow::slotDisplayActionMessage(QAction *a) {
285     statusBar()->showMessage(a->data().toString(), 3000);
286 }
287
288 void MainWindow::saveOptions() {
289     KSharedConfigPtr config = KGlobal::config();
290     m_fileOpenRecent->saveEntries(KConfigGroup(config, "Recent Files"));
291     config->sync();
292 }
293
294 void MainWindow::readOptions() {
295     KSharedConfigPtr config = KGlobal::config();
296     m_fileOpenRecent->loadEntries(KConfigGroup(config, "Recent Files"));
297 }
298
299 void MainWindow::newFile() {
300     MltVideoProfile prof = ProfilesDialog::getVideoProfile(KdenliveSettings::default_profile());
301     if (prof.width == 0) prof = ProfilesDialog::getVideoProfile("dv_pal");
302     KdenliveDoc *doc = new KdenliveDoc(KUrl(), prof);
303     TrackView *trackView = new TrackView(doc);
304     m_timelineArea->addTab(trackView, KIcon("kdenlive"), i18n("Untitled") + " / " + prof.description);
305     if (m_timelineArea->count() == 1)
306         connectDocument(trackView, doc);
307     else m_timelineArea->setTabBarHidden(false);
308 }
309
310 void MainWindow::activateDocument() {
311     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
312     KdenliveDoc *currentDoc = currentTab->document();
313     connectDocument(currentTab, currentDoc);
314 }
315
316 void MainWindow::closeDocument(QWidget *w) {
317     if (w == m_timelineArea->currentWidget()) {
318         // closing current document
319         int ix = m_timelineArea->currentIndex() + 1;
320         if (ix == m_timelineArea->count()) ix = 0;
321         m_timelineArea->setCurrentIndex(ix);
322     }
323
324     TrackView *tabToClose = (TrackView *) w;
325     KdenliveDoc *docToClose = tabToClose->document();
326     m_timelineArea->removeTab(m_timelineArea->indexOf(w));
327     delete docToClose;
328     delete w;
329 }
330
331 void MainWindow::saveFileAs(const QString &outputFileName) {
332     KSaveFile file(outputFileName);
333     file.open();
334
335     QByteArray outputByteArray;
336     //outputByteArray.append(textArea->toPlainText());
337     file.write(outputByteArray);
338     file.finalize();
339     file.close();
340
341     fileName = outputFileName;
342 }
343
344 void MainWindow::saveFileAs() {
345     saveFileAs(KFileDialog::getSaveFileName());
346 }
347
348 void MainWindow::saveFile() {
349     if (!fileName.isEmpty()) {
350         saveFileAs(fileName);
351     } else {
352         saveFileAs();
353     }
354 }
355
356 void MainWindow::openFile() { //changed
357     KUrl url = KFileDialog::getOpenUrl(KUrl(), "application/vnd.kde.kdenlive;*.kdenlive");
358     if (url.isEmpty()) return;
359     m_fileOpenRecent->addUrl(url);
360     openFile(url);
361 }
362
363 void MainWindow::openFile(const KUrl &url) { //new
364     //TODO: get video profile from url before opening it
365     MltVideoProfile prof = ProfilesDialog::getVideoProfile(KdenliveSettings::default_profile());
366     if (prof.width == 0) prof = ProfilesDialog::getVideoProfile("dv_pal");
367     KdenliveDoc *doc = new KdenliveDoc(url, prof);
368     TrackView *trackView = new TrackView(doc);
369     m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description()));
370     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), doc->url().path());
371     if (m_timelineArea->count() > 1) m_timelineArea->setTabBarHidden(false);
372     //connectDocument(trackView, doc);
373 }
374
375
376 void MainWindow::parseProfiles() {
377     //kdDebug()<<" + + YOUR MLT INSTALL WAS FOUND IN: "<< MLT_PREFIX <<endl;
378     if (KdenliveSettings::mltpath().isEmpty()) {
379         KdenliveSettings::setMltpath(QString(MLT_PREFIX) + QString("/share/mlt/profiles/"));
380     }
381     if (KdenliveSettings::rendererpath().isEmpty()) {
382         KdenliveSettings::setRendererpath(KStandardDirs::findExe("inigo"));
383     }
384     QStringList profilesFilter;
385     profilesFilter << "*";
386     QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
387
388     if (profilesList.isEmpty()) {
389         // Cannot find MLT path, try finding inigo
390         QString profilePath = KdenliveSettings::rendererpath();
391         if (!profilePath.isEmpty()) {
392             profilePath = profilePath.section('/', 0, -3);
393             KdenliveSettings::setMltpath(profilePath + "/share/mlt/profiles/");
394             QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
395         }
396
397         if (profilesList.isEmpty()) {
398             // Cannot find the MLT profiles, ask for location
399             KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find your Mlt profiles, please give the path"), this);
400             getUrl->fileDialog()->setMode(KFile::Directory);
401             getUrl->exec();
402             KUrl mltPath = getUrl->selectedUrl();
403             delete getUrl;
404             if (mltPath.isEmpty()) exit(1);
405             KdenliveSettings::setMltpath(mltPath.path());
406             QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
407         }
408     }
409
410     if (KdenliveSettings::rendererpath().isEmpty()) {
411         // Cannot find the MLT inigo renderer, ask for location
412         KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find the inigo program required for rendering (part of Mlt)"), this);
413         getUrl->exec();
414         KUrl rendererPath = getUrl->selectedUrl();
415         delete getUrl;
416         if (rendererPath.isEmpty()) exit(1);
417         KdenliveSettings::setRendererpath(rendererPath.path());
418     }
419
420     kDebug() << "RESULTING MLT PATH: " << KdenliveSettings::mltpath();
421
422     // Parse MLT profiles to build a list of available video formats
423     if (profilesList.isEmpty()) parseProfiles();
424 }
425
426
427 void MainWindow::slotEditProfiles() {
428     ProfilesDialog *w = new ProfilesDialog;
429     w->exec();
430     delete w;
431 }
432
433 void MainWindow::slotEditProjectSettings() {
434     ProjectSettings *w = new ProjectSettings;
435     w->exec();
436     delete w;
437 }
438
439
440 void MainWindow::slotUpdateMousePosition(int pos) {
441     if (m_activeDocument)
442         switch (m_timecodeFormat->currentIndex()) {
443         case 0:
444             statusBar()->changeItem(m_activeDocument->timecode().getTimecodeFromFrames(pos), ID_TIMELINE_POS);
445             break;
446         default:
447             statusBar()->changeItem(QString::number(pos), ID_TIMELINE_POS);
448         }
449 }
450
451 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //changed
452     //m_projectMonitor->stop();
453     kDebug() << "///////////////////   CONNECTING DOC TO PROJECT VIEW ////////////////";
454     if (m_activeDocument) {
455         if (m_activeDocument == doc) return;
456         m_activeDocument->backupMltPlaylist();
457         if (m_activeTimeline) {
458             disconnect(m_projectMonitor, SIGNAL(renderPosition(int)), m_activeTimeline, SLOT(moveCursorPos(int)));
459             disconnect(m_projectMonitor, SIGNAL(durationChanged(int)), m_activeTimeline->projectView(), SLOT(setDuration(int)));
460             disconnect(m_activeDocument, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
461             disconnect(m_activeDocument, SIGNAL(signalDeleteProjectClip(int)), m_projectList, SLOT(slotDeleteClip(int)));
462             disconnect(m_activeDocument, SIGNAL(updateClipDisplay(int)), m_projectList, SLOT(slotUpdateClip(int)));
463             disconnect(m_activeDocument, SIGNAL(deletTimelineClip(int)), m_activeTimeline, SLOT(slotDeleteClip(int)));
464             disconnect(m_activeDocument, SIGNAL(thumbsProgress(KUrl, int)), this, SLOT(slotGotProgressInfo(KUrl, int)));
465             disconnect(m_activeTimeline, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*)));
466             disconnect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement)), m_activeTimeline->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement)));
467             disconnect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), m_activeTimeline->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
468             disconnect(effectStack, SIGNAL(changeEffectState(ClipItem*, QDomElement, bool)), m_activeTimeline->projectView(), SLOT(slotChangeEffectState(ClipItem*, QDomElement, bool)));
469             disconnect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), m_activeTimeline->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
470         }
471         m_activeDocument->setRenderer(NULL);
472     }
473     m_monitorManager->resetProfiles(doc->profilePath());
474     m_projectList->setDocument(doc);
475
476     connect(trackView, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
477     connect(trackView, SIGNAL(mousePosition(int)), this, SLOT(slotUpdateMousePosition(int)));
478     connect(m_projectMonitor, SIGNAL(renderPosition(int)), trackView, SLOT(moveCursorPos(int)));
479     connect(m_projectMonitor, SIGNAL(durationChanged(int)), trackView->projectView(), SLOT(setDuration(int)));
480     connect(doc, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
481     connect(doc, SIGNAL(signalDeleteProjectClip(int)), m_projectList, SLOT(slotDeleteClip(int)));
482     connect(doc, SIGNAL(updateClipDisplay(int)), m_projectList, SLOT(slotUpdateClip(int)));
483     connect(doc, SIGNAL(deletTimelineClip(int)), trackView, SLOT(slotDeleteClip(int)));
484     connect(doc, SIGNAL(thumbsProgress(KUrl, int)), this, SLOT(slotGotProgressInfo(KUrl, int)));
485
486     connect(trackView, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*)));
487     connect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement)), trackView->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement)));
488     connect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), trackView->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
489     connect(effectStack, SIGNAL(changeEffectState(ClipItem*, QDomElement, bool)), trackView->projectView(), SLOT(slotChangeEffectState(ClipItem*, QDomElement, bool)));
490     connect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), trackView->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
491     m_activeTimeline = trackView;
492
493     m_monitorManager->setTimecode(doc->timecode());
494     doc->setRenderer(m_projectMonitor->render);
495     //m_undoView->setStack(0);
496     m_commandStack = doc->commandStack();
497
498     m_overView->setScene(trackView->projectScene());
499     m_overView->scale(m_overView->width() / trackView->duration(), m_overView->height() / (50 * trackView->tracksNumber()));
500     //m_overView->fitInView(m_overView->itemAt(0, 50), Qt::KeepAspectRatio);
501     QAction *redo = m_commandStack->createRedoAction(actionCollection());
502     QAction *undo = m_commandStack->createUndoAction(actionCollection());
503
504     QWidget* w = factory()->container("mainToolBar", this);
505     if (w) {
506         if (actionCollection()->action("undo"))
507             delete actionCollection()->action("undo");
508         if (actionCollection()->action("redo"))
509             delete actionCollection()->action("redo");
510
511         actionCollection()->addAction("undo", undo);
512         actionCollection()->addAction("redo", redo);
513         w->addAction(undo);
514         w->addAction(redo);
515     }
516     m_undoView->setStack(doc->commandStack());
517     setCaption(doc->description());
518     m_activeDocument = doc;
519 }
520
521 void MainWindow::slotPreferences() {
522     //An instance of your dialog could be already created and could be
523     // cached, in which case you want to display the cached dialog
524     // instead of creating another one
525     if (KConfigDialog::showDialog("settings"))
526         return;
527
528     // KConfigDialog didn't find an instance of this dialog, so lets
529     // create it :
530     KdenliveSettingsDialog* dialog = new KdenliveSettingsDialog(this);
531     connect(dialog, SIGNAL(settingsChanged(const QString&)), this, SLOT(updateConfiguration()));
532     dialog->show();
533 }
534
535 void MainWindow::updateConfiguration() {
536     //TODO: we should apply settings to all projects, not only the current one
537     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
538     if (currentTab) {
539         currentTab->refresh();
540         currentTab->projectView()->checkAutoScroll();
541         if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
542     }
543 }
544
545 void MainWindow::slotGotProgressInfo(KUrl url, int progress) {
546     statusProgressBar->setValue(progress);
547     if (progress > 0) {
548         statusLabel->setText(tr("Creating Audio Thumbs"));
549         statusProgressBar->setVisible(true);
550     } else {
551         statusLabel->setText("");
552         statusProgressBar->setVisible(false);
553     }
554 }
555
556 #include "mainwindow.moc"