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