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