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