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