]> git.sesse.net Git - kdenlive/blob - src/mainwindow.cpp
* Fix crash on renderer stopping
[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 #include <QKeyEvent>
28
29 #include <KApplication>
30 #include <KAction>
31 #include <KLocale>
32 #include <KGlobal>
33 #include <KActionCollection>
34 #include <KStandardAction>
35 #include <KFileDialog>
36 #include <KMessageBox>
37 #include <KDebug>
38 #include <KIO/NetAccess>
39 #include <KSaveFile>
40 #include <KRuler>
41 #include <KConfigDialog>
42 #include <KXMLGUIFactory>
43 #include <KStatusBar>
44 #include <kstandarddirs.h>
45 #include <KUrlRequesterDialog>
46 #include <KTemporaryFile>
47 #include <KActionMenu>
48 #include <KMenu>
49 #include <locale.h>
50 #include <ktogglefullscreenaction.h>
51 #include <KFileItem>
52
53 #include <mlt++/Mlt.h>
54
55 #include "mainwindow.h"
56 #include "kdenlivesettings.h"
57 #include "kdenlivesettingsdialog.h"
58 #include "initeffects.h"
59 #include "profilesdialog.h"
60 #include "projectsettings.h"
61 #include "events.h"
62 #include "renderjob.h"
63 #include "clipmanager.h"
64 #include "projectlist.h"
65 #include "monitor.h"
66 #include "recmonitor.h"
67 #include "monitormanager.h"
68 #include "kdenlivedoc.h"
69 #include "trackview.h"
70 #include "customtrackview.h"
71 #include "effectslistview.h"
72 #include "effectstackview.h"
73 #include "transitionsettings.h"
74 #include "renderwidget.h"
75 #include "renderer.h"
76 #include "jogshuttle.h"
77 #include "clipproperties.h"
78 #include "wizard.h"
79
80 static const int ID_STATUS_MSG = 1;
81 static const int ID_EDITMODE_MSG = 2;
82 static const int ID_TIMELINE_MSG = 3;
83 static const int ID_TIMELINE_BUTTONS = 5;
84 static const int ID_TIMELINE_POS = 6;
85 static const int ID_TIMELINE_FORMAT = 7;
86
87 namespace Mlt {
88 class Producer;
89 };
90
91 EffectsList MainWindow::videoEffects;
92 EffectsList MainWindow::audioEffects;
93 EffectsList MainWindow::customEffects;
94 EffectsList MainWindow::transitions;
95
96 MainWindow::MainWindow(QWidget *parent)
97         : KXmlGuiWindow(parent),
98         m_activeDocument(NULL), m_activeTimeline(NULL), m_renderWidget(NULL), m_jogProcess(NULL), m_findActivated(false), m_initialized(false) {
99     setlocale(LC_NUMERIC, "POSIX");
100     setFont(KGlobalSettings::toolBarFont());
101     parseProfiles();
102     m_commandStack = new QUndoGroup;
103     m_timelineArea = new KTabWidget(this);
104     m_timelineArea->setTabReorderingEnabled(true);
105     m_timelineArea->setTabBarHidden(true);
106
107     QToolButton *closeTabButton = new QToolButton;
108     connect(closeTabButton, SIGNAL(clicked()), this, SLOT(closeCurrentDocument()));
109     closeTabButton->setIcon(KIcon("tab-close"));
110     closeTabButton->adjustSize();
111     closeTabButton->setToolTip(i18n("Close the current tab"));
112     m_timelineArea->setCornerWidget(closeTabButton);
113     connect(m_timelineArea, SIGNAL(currentChanged(int)), this, SLOT(activateDocument()));
114
115     connect(&m_findTimer, SIGNAL(timeout()), this, SLOT(findTimeout()));
116     m_findTimer.setSingleShot(true);
117
118     initEffects::parseEffectFiles();
119     m_monitorManager = new MonitorManager();
120
121     projectListDock = new QDockWidget(i18n("Project Tree"), this);
122     projectListDock->setObjectName("project_tree");
123     m_projectList = new ProjectList(this);
124     projectListDock->setWidget(m_projectList);
125     addDockWidget(Qt::TopDockWidgetArea, projectListDock);
126
127     effectListDock = new QDockWidget(i18n("Effect List"), this);
128     effectListDock->setObjectName("effect_list");
129     m_effectList = new EffectsListView();
130
131     //m_effectList = new KListWidget(this);
132     effectListDock->setWidget(m_effectList);
133     addDockWidget(Qt::TopDockWidgetArea, effectListDock);
134
135     effectStackDock = new QDockWidget(i18n("Effect Stack"), this);
136     effectStackDock->setObjectName("effect_stack");
137     effectStack = new EffectStackView(this);
138     effectStackDock->setWidget(effectStack);
139     addDockWidget(Qt::TopDockWidgetArea, effectStackDock);
140
141     transitionConfigDock = new QDockWidget(i18n("Transition"), this);
142     transitionConfigDock->setObjectName("transition");
143     transitionConfig = new TransitionSettings(this);
144     transitionConfigDock->setWidget(transitionConfig);
145     addDockWidget(Qt::TopDockWidgetArea, transitionConfigDock);
146
147     KdenliveSettings::setCurrent_profile(KdenliveSettings::default_profile());
148     m_fileOpenRecent = KStandardAction::openRecent(this, SLOT(openFile(const KUrl &)),
149                        actionCollection());
150     readOptions();
151
152     clipMonitorDock = new QDockWidget(i18n("Clip Monitor"), this);
153     clipMonitorDock->setObjectName("clip_monitor");
154     m_clipMonitor = new Monitor("clip", m_monitorManager, this);
155     clipMonitorDock->setWidget(m_clipMonitor);
156     addDockWidget(Qt::TopDockWidgetArea, clipMonitorDock);
157     //m_clipMonitor->stop();
158
159     projectMonitorDock = new QDockWidget(i18n("Project Monitor"), this);
160     projectMonitorDock->setObjectName("project_monitor");
161     m_projectMonitor = new Monitor("project", m_monitorManager, this);
162     projectMonitorDock->setWidget(m_projectMonitor);
163     addDockWidget(Qt::TopDockWidgetArea, projectMonitorDock);
164
165     recMonitorDock = new QDockWidget(i18n("Record Monitor"), this);
166     recMonitorDock->setObjectName("record_monitor");
167     m_recMonitor = new RecMonitor("record", this);
168     recMonitorDock->setWidget(m_recMonitor);
169     addDockWidget(Qt::TopDockWidgetArea, recMonitorDock);
170
171     connect(m_recMonitor, SIGNAL(addProjectClip(KUrl)), this, SLOT(slotAddProjectClip(KUrl)));
172     connect(m_recMonitor, SIGNAL(showConfigDialog(int, int)), this, SLOT(slotPreferences(int, int)));
173
174     undoViewDock = new QDockWidget(i18n("Undo History"), this);
175     undoViewDock->setObjectName("undo_history");
176     m_undoView = new QUndoView(this);
177     m_undoView->setCleanIcon(KIcon("edit-clear"));
178     m_undoView->setEmptyLabel(i18n("Clean"));
179     undoViewDock->setWidget(m_undoView);
180     m_undoView->setGroup(m_commandStack);
181     addDockWidget(Qt::TopDockWidgetArea, undoViewDock);
182
183     //overviewDock = new QDockWidget(i18n("Project Overview"), this);
184     //overviewDock->setObjectName("project_overview");
185     //m_overView = new CustomTrackView(NULL, NULL, this);
186     //overviewDock->setWidget(m_overView);
187     //addDockWidget(Qt::TopDockWidgetArea, overviewDock);
188
189     setupActions();
190     //tabifyDockWidget(projectListDock, effectListDock);
191     tabifyDockWidget(projectListDock, effectStackDock);
192     tabifyDockWidget(projectListDock, transitionConfigDock);
193     //tabifyDockWidget(projectListDock, undoViewDock);
194
195
196     tabifyDockWidget(clipMonitorDock, projectMonitorDock);
197     tabifyDockWidget(clipMonitorDock, recMonitorDock);
198     setCentralWidget(m_timelineArea);
199
200     setupGUI(Default, NULL /*"kdenliveui.rc"*/);
201     kDebug() << factory() << " " << factory()->container("video_effects_menu", this);
202
203     // build effects menus
204     QAction *action;
205     QMenu *videoEffectsMenu = static_cast<QMenu*>(factory()->container("video_effects_menu", this));
206     QStringList effects = videoEffects.effectNames();
207     foreach(const QString &name, effects) {
208         action = new QAction(name, this);
209         action->setData(name);
210         videoEffectsMenu->addAction(action);
211     }
212     QMenu *audioEffectsMenu = static_cast<QMenu*>(factory()->container("audio_effects_menu", this));
213     effects = audioEffects.effectNames();
214     foreach(const QString &name, effects) {
215         action = new QAction(name, this);
216         action->setData(name);
217         audioEffectsMenu->addAction(action);
218     }
219     m_customEffectsMenu = static_cast<QMenu*>(factory()->container("custom_effects_menu", this));
220     effects = customEffects.effectNames();
221     foreach(const QString &name, effects) {
222         action = new QAction(name, this);
223         action->setData(name);
224         m_customEffectsMenu->addAction(action);
225     }
226
227     QMenu *viewMenu = static_cast<QMenu*>(factory()->container("dockwindows", this));
228     const QList<QAction *> viewActions = createPopupMenu()->actions();
229     viewMenu->insertActions(NULL, viewActions);
230
231     connect(videoEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddVideoEffect(QAction *)));
232     connect(audioEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddAudioEffect(QAction *)));
233     connect(m_customEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddCustomEffect(QAction *)));
234
235     m_timelineContextMenu = new QMenu(this);
236     m_timelineContextClipMenu = new QMenu(this);
237     m_timelineContextTransitionMenu = new QMenu(this);
238
239
240     QMenu *transitionsMenu = new QMenu(i18n("Add Transition"), this);
241     effects = transitions.effectNames();
242     foreach(const QString &name, effects) {
243         action = new QAction(name, this);
244         action->setData(name);
245         transitionsMenu->addAction(action);
246     }
247     connect(transitionsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddTransition(QAction *)));
248
249     m_timelineContextMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Paste)));
250
251     m_timelineContextClipMenu->addAction(actionCollection()->action("delete_timeline_clip"));
252     m_timelineContextClipMenu->addAction(actionCollection()->action("change_clip_speed"));
253     m_timelineContextClipMenu->addAction(actionCollection()->action("cut_timeline_clip"));
254     m_timelineContextClipMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Copy)));
255     m_timelineContextClipMenu->addAction(actionCollection()->action("paste_effects"));
256
257     QMenu *markersMenu = (QMenu*)(factory()->container("marker_menu", this));
258     m_timelineContextClipMenu->addMenu(markersMenu);
259     m_timelineContextClipMenu->addMenu(transitionsMenu);
260     m_timelineContextClipMenu->addMenu(videoEffectsMenu);
261     m_timelineContextClipMenu->addMenu(audioEffectsMenu);
262     m_timelineContextClipMenu->addMenu(m_customEffectsMenu);
263
264     m_timelineContextTransitionMenu->addAction(actionCollection()->action("delete_timeline_clip"));
265     m_timelineContextTransitionMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Copy)));
266
267     connect(projectMonitorDock, SIGNAL(visibilityChanged(bool)), m_projectMonitor, SLOT(refreshMonitor(bool)));
268     connect(clipMonitorDock, SIGNAL(visibilityChanged(bool)), m_clipMonitor, SLOT(refreshMonitor(bool)));
269     //connect(m_monitorManager, SIGNAL(connectMonitors()), this, SLOT(slotConnectMonitors()));
270     connect(m_monitorManager, SIGNAL(raiseClipMonitor(bool)), this, SLOT(slotRaiseMonitor(bool)));
271     connect(m_effectList, SIGNAL(addEffect(QDomElement)), this, SLOT(slotAddEffect(QDomElement)));
272     connect(m_effectList, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
273
274     m_monitorManager->initMonitors(m_clipMonitor, m_projectMonitor);
275     slotConnectMonitors();
276
277     setAutoSaveSettings();
278
279     if (KdenliveSettings::openlastproject()) {
280         openLastFile();
281     } else {
282         /*QList<KAutoSaveFile *> staleFiles = KAutoSaveFile::allStaleFiles();
283         if (!staleFiles.isEmpty()) {
284             if (KMessageBox::questionYesNo(this, i18n("Auto-saved files exist. Do you want to recover them now?"), i18n("File Recovery"), KGuiItem(i18n("Recover")), KGuiItem(i18n("Don't recover"))) == KMessageBox::Yes) {
285          recoverFiles(staleFiles);
286             }
287             else newFile();
288         }
289         else*/
290         newFile();
291     }
292
293     activateShuttleDevice();
294     projectListDock->raise();
295 }
296
297 void MainWindow::queryQuit() {
298     kDebug() << "----- SAVING CONFUIG";
299     if (queryClose()) kapp->quit();
300 }
301
302 //virtual
303 bool MainWindow::queryClose() {
304     saveOptions();
305     if (m_activeDocument && m_activeDocument->isModified()) {
306         switch (KMessageBox::warningYesNoCancel(this, i18n("Save changes to document ?"))) {
307         case KMessageBox::Yes :
308             // save document here. If saving fails, return false;
309             saveFile();
310             return true;
311         case KMessageBox::No :
312             return true;
313         default: // cancel
314             return false;
315         }
316     }
317     return true;
318 }
319
320 void MainWindow::saveProperties(KConfig*) {
321     // save properties here,used by session management
322     saveFile();
323 }
324
325
326 void MainWindow::readProperties(KConfig *config) {
327     // read properties here,used by session management
328     QString Lastproject = config->group("Recent Files").readPathEntry("File1", QString());
329     openFile(KUrl(Lastproject));
330 }
331
332 void MainWindow::slotReloadEffects() {
333     initEffects::parseCustomEffectsFile();
334     m_customEffectsMenu->clear();
335     const QStringList effects = customEffects.effectNames();
336     QAction *action;
337     foreach(const QString &name, effects) {
338         action = new QAction(name, this);
339         action->setData(name);
340         m_customEffectsMenu->addAction(action);
341     }
342     m_effectList->reloadEffectList();
343 }
344
345 void MainWindow::activateShuttleDevice() {
346     if (m_jogProcess) delete m_jogProcess;
347     m_jogProcess = NULL;
348     if (KdenliveSettings::enableshuttle() == false) return;
349     m_jogProcess = new JogShuttle(KdenliveSettings::shuttledevice());
350     connect(m_jogProcess, SIGNAL(rewind1()), m_monitorManager, SLOT(slotRewindOneFrame()));
351     connect(m_jogProcess, SIGNAL(forward1()), m_monitorManager, SLOT(slotForwardOneFrame()));
352     connect(m_jogProcess, SIGNAL(rewind(double)), m_monitorManager, SLOT(slotRewind(double)));
353     connect(m_jogProcess, SIGNAL(forward(double)), m_monitorManager, SLOT(slotForward(double)));
354     connect(m_jogProcess, SIGNAL(stop()), m_monitorManager, SLOT(slotPlay()));
355     connect(m_jogProcess, SIGNAL(button(int)), this, SLOT(slotShuttleButton(int)));
356 }
357
358 void MainWindow::slotShuttleButton(int code) {
359     switch (code) {
360     case 5:
361         slotShuttleAction(KdenliveSettings::shuttle1());
362         break;
363     case 6:
364         slotShuttleAction(KdenliveSettings::shuttle2());
365         break;
366     case 7:
367         slotShuttleAction(KdenliveSettings::shuttle3());
368         break;
369     case 8:
370         slotShuttleAction(KdenliveSettings::shuttle4());
371         break;
372     case 9:
373         slotShuttleAction(KdenliveSettings::shuttle5());
374         break;
375     }
376 }
377
378 void MainWindow::slotShuttleAction(int code) {
379     switch (code) {
380     case 0:
381         return;
382     case 1:
383         m_monitorManager->slotPlay();
384         break;
385     default:
386         m_monitorManager->slotPlay();
387         break;
388     }
389 }
390
391 void MainWindow::slotFullScreen() {
392     //KToggleFullScreenAction::setFullScreen(this, actionCollection()->action("fullscreen")->isChecked());
393 }
394
395 void MainWindow::slotAddEffect(QDomElement effect, GenTime pos, int track) {
396     if (!m_activeDocument) return;
397     if (effect.isNull()) {
398         kDebug() << "--- ERROR, TRYING TO APPEND NULL EFFECT";
399         return;
400     }
401     TrackView *currentTimeLine = (TrackView *) m_timelineArea->currentWidget();
402     currentTimeLine->projectView()->slotAddEffect(effect, pos, track);
403 }
404
405 void MainWindow::slotRaiseMonitor(bool clipMonitor) {
406     if (clipMonitor) clipMonitorDock->raise();
407     else projectMonitorDock->raise();
408 }
409
410 void MainWindow::slotSetClipDuration(const QString &id, int duration) {
411     if (!m_activeDocument) return;
412     m_activeDocument->setProducerDuration(id, duration);
413 }
414
415 void MainWindow::slotConnectMonitors() {
416
417     m_projectList->setRenderer(m_clipMonitor->render);
418     connect(m_projectList, SIGNAL(receivedClipDuration(const QString &, int)), this, SLOT(slotSetClipDuration(const QString &, int)));
419     connect(m_projectList, SIGNAL(showClipProperties(DocClipBase *)), this, SLOT(slotShowClipProperties(DocClipBase *)));
420     connect(m_projectList, SIGNAL(getFileProperties(const QDomElement &, const QString &)), m_clipMonitor->render, SLOT(getFileProperties(const QDomElement &, const QString &)));
421     connect(m_clipMonitor->render, SIGNAL(replyGetImage(const QString &, int, const QPixmap &, int, int)), m_projectList, SLOT(slotReplyGetImage(const QString &, int, const QPixmap &, int, int)));
422     connect(m_clipMonitor->render, SIGNAL(replyGetFileProperties(const QString &, Mlt::Producer*, const QMap < QString, QString > &, const QMap < QString, QString > &)), m_projectList, SLOT(slotReplyGetFileProperties(const QString &, Mlt::Producer*, const QMap < QString, QString > &, const QMap < QString, QString > &)));
423
424     connect(m_clipMonitor->render, SIGNAL(removeInvalidClip(const QString &)), m_projectList, SLOT(slotRemoveInvalidClip(const QString &)));
425
426     connect(m_clipMonitor, SIGNAL(refreshClipThumbnail(const QString &)), m_projectList, SLOT(slotRefreshClipThumbnail(const QString &)));
427
428     connect(m_clipMonitor, SIGNAL(adjustMonitorSize()), this, SLOT(slotAdjustClipMonitor()));
429     connect(m_projectMonitor, SIGNAL(adjustMonitorSize()), this, SLOT(slotAdjustProjectMonitor()));
430 }
431
432 void MainWindow::slotAdjustClipMonitor() {
433     clipMonitorDock->updateGeometry();
434     clipMonitorDock->adjustSize();
435     m_clipMonitor->resetSize();
436 }
437
438 void MainWindow::slotAdjustProjectMonitor() {
439     projectMonitorDock->updateGeometry();
440     projectMonitorDock->adjustSize();
441     m_projectMonitor->resetSize();
442 }
443
444 void MainWindow::setupActions() {
445
446     m_timecodeFormat = new KComboBox(this);
447     m_timecodeFormat->addItem(i18n("hh:mm:ss::ff"));
448     m_timecodeFormat->addItem(i18n("Frames"));
449
450     statusProgressBar = new QProgressBar(this);
451     statusProgressBar->setMinimum(0);
452     statusProgressBar->setMaximum(100);
453     statusProgressBar->setMaximumWidth(150);
454     statusProgressBar->setVisible(false);
455
456     QWidget *w = new QWidget;
457
458     QHBoxLayout *layout = new QHBoxLayout;
459     w->setLayout(layout);
460     layout->setContentsMargins(5, 0, 5, 0);
461     QToolBar *toolbar = new QToolBar("statusToolBar", this);
462
463
464     m_toolGroup = new QActionGroup(this);
465
466     QString style1 = "QToolButton {background-color: rgba(230, 230, 230, 220); border-style: inset; border:1px solid #999999;border-radius: 3px;margin: 0px 3px;padding: 0px;} QToolButton:checked { background-color: rgba(224, 224, 0, 100); border-style: inset; border:1px solid #cc6666;border-radius: 3px;}";
467
468     m_buttonSelectTool = toolbar->addAction(KIcon("kdenlive-select-tool"), i18n("Selection tool"));
469     m_buttonSelectTool->setCheckable(true);
470     m_buttonSelectTool->setChecked(true);
471
472     m_buttonRazorTool = toolbar->addAction(KIcon("edit-cut"), i18n("Razor tool"));
473     m_buttonRazorTool->setCheckable(true);
474     m_buttonRazorTool->setChecked(false);
475
476     m_toolGroup->addAction(m_buttonSelectTool);
477     m_toolGroup->addAction(m_buttonRazorTool);
478     m_toolGroup->setExclusive(true);
479     toolbar->setToolButtonStyle(Qt::ToolButtonIconOnly);
480
481     QWidget * actionWidget;
482     actionWidget = toolbar->widgetForAction(m_buttonSelectTool);
483     actionWidget->setMaximumWidth(24);
484     actionWidget->setMinimumHeight(17);
485
486     actionWidget = toolbar->widgetForAction(m_buttonRazorTool);
487     actionWidget->setMaximumWidth(24);
488     actionWidget->setMinimumHeight(17);
489
490     toolbar->setStyleSheet(style1);
491     connect(m_toolGroup, SIGNAL(triggered(QAction *)), this, SLOT(slotChangeTool(QAction *)));
492
493     toolbar->addSeparator();
494     m_buttonFitZoom = toolbar->addAction(KIcon("zoom-fit-best"), i18n("Fit zoom to project"));
495     m_buttonFitZoom->setCheckable(false);
496     connect(m_buttonFitZoom, SIGNAL(triggered()), this, SLOT(slotFitZoom()));
497
498     actionWidget = toolbar->widgetForAction(m_buttonFitZoom);
499     actionWidget->setMaximumWidth(24);
500     actionWidget->setMinimumHeight(17);
501
502     m_zoomSlider = new QSlider(Qt::Horizontal, this);
503     m_zoomSlider->setMaximum(13);
504     m_zoomSlider->setPageStep(1);
505
506     m_zoomSlider->setMaximumWidth(150);
507     m_zoomSlider->setMinimumWidth(100);
508
509     const int contentHeight = QFontMetrics(w->font()).height() + 8;
510     QString style = "QSlider::groove:horizontal { background-color: rgba(230, 230, 230, 220);border: 1px solid #999999;height: 8px;border-radius: 3px;margin-top:3px }";
511     style.append("QSlider::handle:horizontal {  background-color: white; border: 1px solid #999999;width: 9px;margin: -2px 0;border-radius: 3px; }");
512     m_zoomSlider->setStyleSheet(style);
513
514     //m_zoomSlider->setMaximumHeight(contentHeight);
515     //m_zoomSlider->height() + 5;
516     statusBar()->setMinimumHeight(contentHeight);
517
518
519     toolbar->addWidget(m_zoomSlider);
520
521     m_buttonVideoThumbs = toolbar->addAction(KIcon("kdenlive-show-videothumb"), i18n("Show video thumbnails"));
522     m_buttonVideoThumbs->setCheckable(true);
523     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
524     connect(m_buttonVideoThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchVideoThumbs()));
525
526     m_buttonAudioThumbs = toolbar->addAction(KIcon("kdenlive-show-audiothumb"), i18n("Show audio thumbnails"));
527     m_buttonAudioThumbs->setCheckable(true);
528     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
529     connect(m_buttonAudioThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchAudioThumbs()));
530
531     m_buttonShowMarkers = toolbar->addAction(KIcon("kdenlive-show-markers"), i18n("Show markers comments"));
532     m_buttonShowMarkers->setCheckable(true);
533     m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
534     connect(m_buttonShowMarkers, SIGNAL(triggered()), this, SLOT(slotSwitchMarkersComments()));
535
536     m_buttonSnap = toolbar->addAction(KIcon("kdenlive-snap"), i18n("Snap"));
537     m_buttonSnap->setCheckable(true);
538     m_buttonSnap->setChecked(KdenliveSettings::snaptopoints());
539     connect(m_buttonSnap, SIGNAL(triggered()), this, SLOT(slotSwitchSnap()));
540     layout->addWidget(toolbar);
541
542
543     actionWidget = toolbar->widgetForAction(m_buttonVideoThumbs);
544     actionWidget->setMaximumWidth(24);
545     actionWidget->setMinimumHeight(17);
546
547     actionWidget = toolbar->widgetForAction(m_buttonAudioThumbs);
548     actionWidget->setMaximumWidth(24);
549     actionWidget->setMinimumHeight(17);
550
551     actionWidget = toolbar->widgetForAction(m_buttonShowMarkers);
552     actionWidget->setMaximumWidth(24);
553     actionWidget->setMinimumHeight(17);
554
555     actionWidget = toolbar->widgetForAction(m_buttonSnap);
556     actionWidget->setMaximumWidth(24);
557     actionWidget->setMinimumHeight(17);
558
559     m_messageLabel = new StatusBarMessageLabel(this);
560     m_messageLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding);
561
562     statusBar()->addWidget(m_messageLabel, 10);
563     statusBar()->addWidget(statusProgressBar, 0);
564     statusBar()->insertPermanentWidget(ID_TIMELINE_BUTTONS, w);
565     statusBar()->insertPermanentFixedItem("00:00:00:00", ID_TIMELINE_POS);
566     statusBar()->insertPermanentWidget(ID_TIMELINE_FORMAT, m_timecodeFormat);
567     statusBar()->setMaximumHeight(statusBar()->font().pointSize() * 4);
568     m_messageLabel->hide();
569
570     actionCollection()->addAction("select_tool", m_buttonSelectTool);
571     actionCollection()->addAction("razor_tool", m_buttonRazorTool);
572
573     actionCollection()->addAction("show_video_thumbs", m_buttonVideoThumbs);
574     actionCollection()->addAction("show_audio_thumbs", m_buttonAudioThumbs);
575     actionCollection()->addAction("show_markers", m_buttonShowMarkers);
576     actionCollection()->addAction("snap", m_buttonSnap);
577     actionCollection()->addAction("zoom_fit", m_buttonFitZoom);
578
579     m_projectSearch = new KAction(KIcon("edit-find"), i18n("Find"), this);
580     actionCollection()->addAction("project_find", m_projectSearch);
581     connect(m_projectSearch, SIGNAL(triggered(bool)), this, SLOT(slotFind()));
582     m_projectSearch->setShortcut(Qt::Key_Slash);
583
584     m_projectSearchNext = new KAction(KIcon("go-down-search"), i18n("Find Next"), this);
585     actionCollection()->addAction("project_find_next", m_projectSearchNext);
586     connect(m_projectSearchNext, SIGNAL(triggered(bool)), this, SLOT(slotFindNext()));
587     m_projectSearchNext->setShortcut(Qt::Key_F3);
588     m_projectSearchNext->setEnabled(false);
589
590     KAction* profilesAction = new KAction(KIcon("document-new"), i18n("Manage Profiles"), this);
591     actionCollection()->addAction("manage_profiles", profilesAction);
592     connect(profilesAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProfiles()));
593
594     KAction* projectAction = new KAction(KIcon("configure"), i18n("Project Settings"), this);
595     actionCollection()->addAction("project_settings", projectAction);
596     connect(projectAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProjectSettings()));
597
598     KAction* projectRender = new KAction(KIcon("media-record"), i18n("Render"), this);
599     actionCollection()->addAction("project_render", projectRender);
600     connect(projectRender, SIGNAL(triggered(bool)), this, SLOT(slotRenderProject()));
601
602     KAction* monitorPlay = new KAction(KIcon("media-playback-start"), i18n("Play"), this);
603     monitorPlay->setShortcut(Qt::Key_Space);
604     actionCollection()->addAction("monitor_play", monitorPlay);
605     connect(monitorPlay, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotPlay()));
606
607     KAction* monitorSeekBackward = new KAction(KIcon("media-seek-backward"), i18n("Rewind"), this);
608     monitorSeekBackward->setShortcut(Qt::Key_J);
609     actionCollection()->addAction("monitor_seek_backward", monitorSeekBackward);
610     connect(monitorSeekBackward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewind()));
611
612     KAction* monitorSeekBackwardOneFrame = new KAction(KIcon("media-skip-backward"), i18n("Rewind 1 Frame"), this);
613     monitorSeekBackwardOneFrame->setShortcut(Qt::Key_Left);
614     actionCollection()->addAction("monitor_seek_backward-one-frame", monitorSeekBackwardOneFrame);
615     connect(monitorSeekBackwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewindOneFrame()));
616
617     KAction* monitorSeekSnapBackward = new KAction(KIcon("media-seek-backward"), i18n("Go to Previous Snap Point"), this);
618     monitorSeekSnapBackward->setShortcut(Qt::ALT + Qt::Key_Left);
619     actionCollection()->addAction("monitor_seek_snap_backward", monitorSeekSnapBackward);
620     connect(monitorSeekSnapBackward, SIGNAL(triggered(bool)), this, SLOT(slotSnapRewind()));
621
622     KAction* monitorSeekForward = new KAction(KIcon("media-seek-forward"), i18n("Forward"), this);
623     monitorSeekForward->setShortcut(Qt::Key_L);
624     actionCollection()->addAction("monitor_seek_forward", monitorSeekForward);
625     connect(monitorSeekForward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForward()));
626
627     KAction* clipStart = new KAction(KIcon("media-seek-backward"), i18n("Go to Clip Start"), this);
628     clipStart->setShortcut(Qt::Key_Home);
629     actionCollection()->addAction("seek_clip_start", clipStart);
630     connect(clipStart, SIGNAL(triggered(bool)), this, SLOT(slotClipStart()));
631
632     KAction* clipEnd = new KAction(KIcon("media-seek-forward"), i18n("Go to Clip End"), this);
633     clipEnd->setShortcut(Qt::Key_End);
634     actionCollection()->addAction("seek_clip_end", clipEnd);
635     connect(clipEnd, SIGNAL(triggered(bool)), this, SLOT(slotClipEnd()));
636
637     KAction* projectStart = new KAction(KIcon("media-seek-backward"), i18n("Go to Project Start"), this);
638     projectStart->setShortcut(Qt::CTRL + Qt::Key_Home);
639     actionCollection()->addAction("seek_start", projectStart);
640     connect(projectStart, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotStart()));
641
642     KAction* projectEnd = new KAction(KIcon("media-seek-forward"), i18n("Go to Project End"), this);
643     projectEnd->setShortcut(Qt::CTRL + Qt::Key_End);
644     actionCollection()->addAction("seek_end", projectEnd);
645     connect(projectEnd, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotEnd()));
646
647     KAction* monitorSeekForwardOneFrame = new KAction(KIcon("media-skip-forward"), i18n("Forward 1 Frame"), this);
648     monitorSeekForwardOneFrame->setShortcut(Qt::Key_Right);
649     actionCollection()->addAction("monitor_seek_forward-one-frame", monitorSeekForwardOneFrame);
650     connect(monitorSeekForwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForwardOneFrame()));
651
652     KAction* monitorSeekSnapForward = new KAction(KIcon("media-seek-forward"), i18n("Go to Next Snap Point"), this);
653     monitorSeekSnapForward->setShortcut(Qt::ALT + Qt::Key_Right);
654     actionCollection()->addAction("monitor_seek_snap_forward", monitorSeekSnapForward);
655     connect(monitorSeekSnapForward, SIGNAL(triggered(bool)), this, SLOT(slotSnapForward()));
656
657     KAction* deleteTimelineClip = new KAction(KIcon("edit-delete"), i18n("Delete Selected Item"), this);
658     deleteTimelineClip->setShortcut(Qt::Key_Delete);
659     actionCollection()->addAction("delete_timeline_clip", deleteTimelineClip);
660     connect(deleteTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotDeleteTimelineClip()));
661
662     KAction* editTimelineClipSpeed = new KAction(KIcon("edit-delete"), i18n("Change Clip Speed"), this);
663     actionCollection()->addAction("change_clip_speed", editTimelineClipSpeed);
664     connect(editTimelineClipSpeed, SIGNAL(triggered(bool)), this, SLOT(slotChangeClipSpeed()));
665
666     KAction* cutTimelineClip = new KAction(KIcon("edit-cut"), i18n("Cut Clip"), this);
667     cutTimelineClip->setShortcut(Qt::SHIFT + Qt::Key_R);
668     actionCollection()->addAction("cut_timeline_clip", cutTimelineClip);
669     connect(cutTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotCutTimelineClip()));
670
671     KAction* addClipMarker = new KAction(KIcon("bookmark-new"), i18n("Add Marker to Clip"), this);
672     actionCollection()->addAction("add_clip_marker", addClipMarker);
673     connect(addClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotAddClipMarker()));
674
675     KAction* deleteClipMarker = new KAction(KIcon("edit-delete"), i18n("Delete Marker from Clip"), this);
676     actionCollection()->addAction("delete_clip_marker", deleteClipMarker);
677     connect(deleteClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotDeleteClipMarker()));
678
679     KAction* deleteAllClipMarkers = new KAction(KIcon("edit-delete"), i18n("Delete All Markers from Clip"), this);
680     actionCollection()->addAction("delete_all_clip_markers", deleteAllClipMarkers);
681     connect(deleteAllClipMarkers, SIGNAL(triggered(bool)), this, SLOT(slotDeleteAllClipMarkers()));
682
683     KAction* editClipMarker = new KAction(KIcon("document-properties"), i18n("Edit Marker"), this);
684     actionCollection()->addAction("edit_clip_marker", editClipMarker);
685     connect(editClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotEditClipMarker()));
686
687     KAction *addGuide = new KAction(KIcon("document-new"), i18n("Add Guide"), this);
688     actionCollection()->addAction("add_guide", addGuide);
689     connect(addGuide, SIGNAL(triggered()), this, SLOT(slotAddGuide()));
690
691     QAction *delGuide = new KAction(KIcon("edit-delete"), i18n("Delete Guide"), this);
692     actionCollection()->addAction("delete_guide", delGuide);
693     connect(delGuide, SIGNAL(triggered()), this, SLOT(slotDeleteGuide()));
694
695     QAction *editGuide = new KAction(KIcon("document-properties"), i18n("Edit Guide"), this);
696     actionCollection()->addAction("edit_guide", editGuide);
697     connect(editGuide, SIGNAL(triggered()), this, SLOT(slotEditGuide()));
698
699     QAction *delAllGuides = new KAction(KIcon("edit-delete"), i18n("Delete All Guides"), this);
700     actionCollection()->addAction("delete_all_guides", delAllGuides);
701     connect(delAllGuides, SIGNAL(triggered()), this, SLOT(slotDeleteAllGuides()));
702
703     QAction *pasteEffects = new KAction(KIcon("edit-paste"), i18n("Paste Effects"), this);
704     actionCollection()->addAction("paste_effects", pasteEffects);
705     connect(pasteEffects , SIGNAL(triggered()), this, SLOT(slotPasteEffects()));
706
707     KStandardAction::quit(this, SLOT(queryQuit()),
708                           actionCollection());
709
710     KStandardAction::open(this, SLOT(openFile()),
711                           actionCollection());
712
713     m_saveAction = KStandardAction::save(this, SLOT(saveFile()),
714                                          actionCollection());
715
716     KStandardAction::saveAs(this, SLOT(saveFileAs()),
717                             actionCollection());
718
719     KStandardAction::openNew(this, SLOT(newFile()),
720                              actionCollection());
721
722     KStandardAction::preferences(this, SLOT(slotPreferences()),
723                                  actionCollection());
724
725     KStandardAction::copy(this, SLOT(slotCopy()),
726                           actionCollection());
727
728     KStandardAction::paste(this, SLOT(slotPaste()),
729                            actionCollection());
730
731     KAction *undo = KStandardAction::undo(m_commandStack, SLOT(undo()),
732                                           actionCollection());
733     undo->setEnabled(false);
734     connect(m_commandStack, SIGNAL(canUndoChanged(bool)), undo, SLOT(setEnabled(bool)));
735
736     KAction *redo = KStandardAction::redo(m_commandStack, SLOT(redo()),
737                                           actionCollection());
738     redo->setEnabled(false);
739     connect(m_commandStack, SIGNAL(canRedoChanged(bool)), redo, SLOT(setEnabled(bool)));
740
741     KStandardAction::fullScreen(this, SLOT(slotFullScreen()), this, actionCollection());
742
743     connect(actionCollection(), SIGNAL(actionHovered(QAction*)),
744             this, SLOT(slotDisplayActionMessage(QAction*)));
745     //connect(actionCollection(), SIGNAL( clearStatusText() ),
746     //statusBar(), SLOT( clear() ) );
747 }
748
749 void MainWindow::slotDisplayActionMessage(QAction *a) {
750     statusBar()->showMessage(a->data().toString(), 3000);
751 }
752
753 void MainWindow::saveOptions() {
754     KdenliveSettings::self()->writeConfig();
755     KSharedConfigPtr config = KGlobal::config();
756     m_fileOpenRecent->saveEntries(KConfigGroup(config, "Recent Files"));
757     config->sync();
758 }
759
760 void MainWindow::readOptions() {
761     KSharedConfigPtr config = KGlobal::config();
762     m_fileOpenRecent->loadEntries(KConfigGroup(config, "Recent Files"));
763     KConfigGroup initialGroup(config, "version");
764     if (!initialGroup.exists()) {
765         // this is our first run, show Wizard
766         Wizard *w = new Wizard(this);
767         if (w->exec() == QDialog::Accepted) {
768             w->adjustSettings();
769             initialGroup.writeEntry("version", "0.7");
770         }
771         delete w;
772     }
773 }
774
775 void MainWindow::newFile() {
776     QString profileName;
777     KUrl projectFolder;
778     if (m_timelineArea->count() == 0) profileName = KdenliveSettings::default_profile();
779     else {
780         ProjectSettings *w = new ProjectSettings;
781         if (w->exec() != QDialog::Accepted) return;
782         profileName = w->selectedProfile();
783         projectFolder = w->selectedFolder();
784         delete w;
785     }
786     KdenliveDoc *doc = new KdenliveDoc(KUrl(), projectFolder, m_commandStack, profileName, this);
787     doc->m_autosave = new KAutoSaveFile(KUrl(), doc);
788     TrackView *trackView = new TrackView(doc, this);
789     m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description());
790     if (m_timelineArea->count() == 1) {
791         connectDocumentInfo(doc);
792         connectDocument(trackView, doc);
793     } else m_timelineArea->setTabBarHidden(false);
794 }
795
796 void MainWindow::activateDocument() {
797     if (m_timelineArea->currentWidget() == NULL) return;
798     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
799     KdenliveDoc *currentDoc = currentTab->document();
800     connectDocumentInfo(currentDoc);
801     connectDocument(currentTab, currentDoc);
802 }
803
804 void MainWindow::closeCurrentDocument() {
805     QWidget *w = m_timelineArea->currentWidget();
806     // closing current document
807     int ix = m_timelineArea->currentIndex() + 1;
808     if (ix == m_timelineArea->count()) ix = 0;
809     m_timelineArea->setCurrentIndex(ix);
810     TrackView *tabToClose = (TrackView *) w;
811     KdenliveDoc *docToClose = tabToClose->document();
812     if (docToClose && docToClose->isModified()) {
813         switch (KMessageBox::warningYesNoCancel(this, i18n("Save changes to document ?"))) {
814         case KMessageBox::Yes :
815             // save document here. If saving fails, return false;
816             saveFile();
817             break;
818         case KMessageBox::Cancel :
819             return;
820         default:
821             break;
822         }
823     }
824     m_timelineArea->removeTab(m_timelineArea->indexOf(w));
825     if (m_timelineArea->count() == 1) m_timelineArea->setTabBarHidden(true);
826     delete docToClose;
827     delete w;
828     if (m_timelineArea->count() == 0) m_activeDocument = NULL;
829 }
830
831 void MainWindow::saveFileAs(const QString &outputFileName) {
832     m_projectMonitor->saveSceneList(outputFileName, m_activeDocument->documentInfoXml());
833     m_activeDocument->setUrl(KUrl(outputFileName));
834     if (m_activeDocument->m_autosave == NULL) {
835         m_activeDocument->m_autosave = new KAutoSaveFile(KUrl(outputFileName), this);
836     } else m_activeDocument->m_autosave->setManagedFile(KUrl(outputFileName));
837     setCaption(m_activeDocument->description());
838     m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
839     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), m_activeDocument->url().path());
840     m_activeDocument->setModified(false);
841     m_fileOpenRecent->addUrl(KUrl(outputFileName));
842 }
843
844 void MainWindow::saveFileAs() {
845     QString outputFile = KFileDialog::getSaveFileName(KUrl(), "*.kdenlive|Kdenlive project files (*.kdenlive)");
846     if (QFile::exists(outputFile)) {
847         if (KMessageBox::questionYesNo(this, i18n("File already exists.\nDo you want to overwrite it ?")) == KMessageBox::No) return;
848     }
849     saveFileAs(outputFile);
850 }
851
852 void MainWindow::saveFile() {
853     if (!m_activeDocument) return;
854     if (m_activeDocument->url().isEmpty()) {
855         saveFileAs();
856     } else {
857         saveFileAs(m_activeDocument->url().path());
858         m_activeDocument->m_autosave->resize(0);
859     }
860 }
861
862 void MainWindow::openFile() {
863     KUrl url = KFileDialog::getOpenUrl(KUrl(), "*.kdenlive|Kdenlive project files (*.kdenlive)\n*.westley|MLT project files (*.westley)");
864     if (url.isEmpty()) return;
865     m_fileOpenRecent->addUrl(url);
866     openFile(url);
867 }
868
869 void MainWindow::openLastFile() {
870     KSharedConfigPtr config = KGlobal::config();
871     KUrl::List urls = m_fileOpenRecent->urls();
872     if (urls.isEmpty()) newFile();
873     else openFile(urls.last());
874 }
875
876 void MainWindow::openFile(const KUrl &url) {
877     // Check for backup file
878     QList<KAutoSaveFile *> staleFiles = KAutoSaveFile::staleFiles(url);
879     if (!staleFiles.isEmpty()) {
880         if (KMessageBox::questionYesNo(this,
881                                        i18n("Auto-saved files exist. Do you want to recover them now?"),
882                                        i18n("File Recovery"),
883                                        KGuiItem(i18n("Recover")), KGuiItem(i18n("Don't recover"))) == KMessageBox::Yes) {
884             recoverFiles(staleFiles);
885             return;
886         } else {
887             // remove the stale files
888             foreach(KAutoSaveFile *stale, staleFiles) {
889                 stale->open(QIODevice::ReadWrite);
890                 delete stale;
891             }
892         }
893     }
894     if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
895     doOpenFile(url, NULL);
896 }
897
898 void MainWindow::doOpenFile(const KUrl &url, KAutoSaveFile *stale) {
899     KdenliveDoc *doc;
900     doc = new KdenliveDoc(url, KUrl(), m_commandStack, QString(), this);
901     if (stale == NULL) {
902         stale = new KAutoSaveFile(url, doc);
903         doc->m_autosave = stale;
904     } else {
905         doc->m_autosave = stale;
906         doc->setUrl(stale->managedFile());
907         doc->setModified(true);
908         stale->setParent(doc);
909     }
910     connectDocumentInfo(doc);
911     TrackView *trackView = new TrackView(doc, this);
912     m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description()));
913     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), doc->url().path());
914     if (m_timelineArea->count() > 1) m_timelineArea->setTabBarHidden(false);
915     slotGotProgressInfo(QString(), -1);
916     m_projectMonitor->refreshMonitor(true);
917 }
918
919 void MainWindow::recoverFiles(QList<KAutoSaveFile *> staleFiles) {
920     if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
921     foreach(KAutoSaveFile *stale, staleFiles) {
922         /*if (!stale->open(QIODevice::QIODevice::ReadOnly)) {
923                   // show an error message; we could not steal the lockfile
924                   // maybe another application got to the file before us?
925                   delete stale;
926                   continue;
927         }*/
928         kDebug() << "// OPENING RECOVERY: " << stale->fileName() << "\nMANAGED: " << stale->managedFile().path();
929         // the stalefiles also contain ".lock" files so we must ignore them... bug in KAutoSaveFile ?
930         if (!stale->fileName().endsWith(".lock")) doOpenFile(KUrl(stale->fileName()), stale);
931         else KIO::NetAccess::del(KUrl(stale->fileName()), this);
932     }
933 }
934
935
936 void MainWindow::parseProfiles() {
937     //kdDebug()<<" + + YOUR MLT INSTALL WAS FOUND IN: "<< MLT_PREFIX <<endl;
938
939     //KdenliveSettings::setDefaulttmpfolder();
940     if (KdenliveSettings::mltpath().isEmpty()) {
941         KdenliveSettings::setMltpath(QString(MLT_PREFIX) + QString("/share/mlt/profiles/"));
942     }
943     if (KdenliveSettings::rendererpath().isEmpty()) {
944         KdenliveSettings::setRendererpath(KStandardDirs::findExe("inigo"));
945     }
946     QStringList profilesFilter;
947     profilesFilter << "*";
948     QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
949
950     if (profilesList.isEmpty()) {
951         // Cannot find MLT path, try finding inigo
952         QString profilePath = KdenliveSettings::rendererpath();
953         if (!profilePath.isEmpty()) {
954             profilePath = profilePath.section('/', 0, -3);
955             KdenliveSettings::setMltpath(profilePath + "/share/mlt/profiles/");
956             QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
957         }
958
959         if (profilesList.isEmpty()) {
960             // Cannot find the MLT profiles, ask for location
961             KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find your Mlt profiles, please give the path"), this);
962             getUrl->fileDialog()->setMode(KFile::Directory);
963             getUrl->exec();
964             KUrl mltPath = getUrl->selectedUrl();
965             delete getUrl;
966             if (mltPath.isEmpty()) kapp->quit();
967             KdenliveSettings::setMltpath(mltPath.path());
968             QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
969         }
970     }
971
972     if (KdenliveSettings::rendererpath().isEmpty()) {
973         // Cannot find the MLT inigo renderer, ask for location
974         KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find the inigo program required for rendering (part of Mlt)"), this);
975         getUrl->exec();
976         KUrl rendererPath = getUrl->selectedUrl();
977         delete getUrl;
978         if (rendererPath.isEmpty()) kapp->quit();
979         KdenliveSettings::setRendererpath(rendererPath.path());
980     }
981
982     kDebug() << "RESULTING MLT PATH: " << KdenliveSettings::mltpath();
983
984     // Parse MLT profiles to build a list of available video formats
985     if (profilesList.isEmpty()) parseProfiles();
986 }
987
988
989 void MainWindow::slotEditProfiles() {
990     ProfilesDialog *w = new ProfilesDialog;
991     w->exec();
992     delete w;
993 }
994
995 void MainWindow::slotEditProjectSettings() {
996     ProjectSettings *w = new ProjectSettings;
997     if (w->exec() == QDialog::Accepted) {
998         QString profile = w->selectedProfile();
999         m_activeDocument->setProfilePath(profile);
1000         KdenliveSettings::setCurrent_profile(profile);
1001         KdenliveSettings::setProject_fps(m_activeDocument->fps());
1002         setCaption(m_activeDocument->description(), m_activeDocument->isModified());
1003         m_monitorManager->resetProfiles(m_activeDocument->timecode());
1004         if (m_renderWidget) m_renderWidget->setDocumentStandard(m_activeDocument->getDocumentStandard());
1005         m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
1006
1007         // We need to desactivate & reactivate monitors to get a refresh
1008         m_monitorManager->switchMonitors();
1009     }
1010     delete w;
1011 }
1012
1013 void MainWindow::slotRenderProject() {
1014     if (!m_renderWidget) {
1015         m_renderWidget = new RenderWidget(this);
1016         connect(m_renderWidget, SIGNAL(doRender(const QString&, const QString&, const QStringList &, bool, bool)), this, SLOT(slotDoRender(const QString&, const QString&, const QStringList &, bool, bool)));
1017     }
1018     /*TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
1019     if (currentTab) m_renderWidget->setTimeline(currentTab);
1020     m_renderWidget->setDocument(m_activeDocument);*/
1021     m_renderWidget->show();
1022 }
1023
1024 void MainWindow::slotDoRender(const QString &dest, const QString &render, const QStringList &avformat_args, bool zoneOnly, bool playAfter) {
1025     if (dest.isEmpty()) return;
1026     int in;
1027     int out;
1028     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
1029     if (currentTab && zoneOnly) {
1030         in = currentTab->inPoint();
1031         out = currentTab->outPoint();
1032     }
1033     KTemporaryFile temp;
1034     temp.setAutoRemove(false);
1035     temp.setSuffix(".westley");
1036     if (temp.open()) {
1037         m_projectMonitor->saveSceneList(temp.fileName());
1038         QStringList args;
1039         args << "-erase";
1040         if (zoneOnly) args << "in=" + QString::number(in) << "out=" + QString::number(out);
1041         QString videoPlayer = "-";
1042         if (playAfter) {
1043             videoPlayer = KdenliveSettings::defaultplayerapp();
1044             if (videoPlayer.isEmpty()) KMessageBox::sorry(this, i18n("Cannot play video after rendering because the default video player application is not set.\nPlease define it in Kdenlive settings dialog."));
1045         }
1046         args << KdenliveSettings::rendererpath() << m_activeDocument->profilePath() << render << videoPlayer << temp.fileName() << dest << avformat_args;
1047         QProcess::startDetached("kdenlive_render", args);
1048     }
1049 }
1050
1051 void MainWindow::slotUpdateMousePosition(int pos) {
1052     if (m_activeDocument)
1053         switch (m_timecodeFormat->currentIndex()) {
1054         case 0:
1055             statusBar()->changeItem(m_activeDocument->timecode().getTimecodeFromFrames(pos), ID_TIMELINE_POS);
1056             break;
1057         default:
1058             statusBar()->changeItem(QString::number(pos), ID_TIMELINE_POS);
1059         }
1060 }
1061
1062 void MainWindow::slotUpdateDocumentState(bool modified) {
1063     setCaption(m_activeDocument->description(), modified);
1064     m_saveAction->setEnabled(modified);
1065     if (modified) {
1066         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Link));
1067         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("document-save"));
1068     } else {
1069         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Text));
1070         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("kdenlive"));
1071     }
1072 }
1073
1074 void MainWindow::connectDocumentInfo(KdenliveDoc *doc) {
1075     if (m_activeDocument) {
1076         if (m_activeDocument == doc) return;
1077         disconnect(m_activeDocument, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
1078     }
1079     connect(doc, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
1080 }
1081
1082 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //changed
1083     //m_projectMonitor->stop();
1084     kDebug() << "///////////////////   CONNECTING DOC TO PROJECT VIEW ////////////////";
1085     if (m_activeDocument) {
1086         if (m_activeDocument == doc) return;
1087         m_activeDocument->backupMltPlaylist();
1088         if (m_activeTimeline) {
1089             disconnect(m_projectMonitor, SIGNAL(renderPosition(int)), m_activeTimeline, SLOT(moveCursorPos(int)));
1090             disconnect(m_projectMonitor, SIGNAL(durationChanged(int)), m_activeTimeline, SLOT(setDuration(int)));
1091             disconnect(m_projectList, SIGNAL(projectModified()), m_activeDocument, SLOT(setModified()));
1092             disconnect(m_activeDocument, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
1093             disconnect(m_activeDocument, SIGNAL(addProjectFolder(const QString, const QString &, bool, bool)), m_projectList, SLOT(slotAddFolder(const QString, const QString &, bool, bool)));
1094             disconnect(m_activeDocument, SIGNAL(signalDeleteProjectClip(const QString &)), m_projectList, SLOT(slotDeleteClip(const QString &)));
1095             disconnect(m_activeDocument, SIGNAL(updateClipDisplay(const QString &)), m_projectList, SLOT(slotUpdateClip(const QString &)));
1096             disconnect(m_activeDocument, SIGNAL(refreshClipThumbnail(const QString &)), m_projectList, SLOT(slotRefreshClipThumbnail(const QString &)));
1097             disconnect(m_activeDocument, SIGNAL(selectLastAddedClip(const QString &)), m_projectList, SLOT(slotSelectClip(const QString &)));
1098             disconnect(m_activeDocument, SIGNAL(deleteTimelineClip(const QString &)), m_activeTimeline, SLOT(slotDeleteClip(const QString &)));
1099             disconnect(m_activeTimeline, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*)));
1100             disconnect(m_activeTimeline, SIGNAL(clipItemSelected(ClipItem*)), this, SLOT(slotActivateEffectStackView()));
1101             disconnect(m_activeTimeline, SIGNAL(transitionItemSelected(Transition*)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*)));
1102             disconnect(m_activeTimeline, SIGNAL(transitionItemSelected(Transition*)), this, SLOT(slotActivateTransitionView()));
1103             disconnect(m_zoomSlider, SIGNAL(valueChanged(int)), m_activeTimeline, SLOT(slotChangeZoom(int)));
1104             disconnect(m_activeTimeline->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
1105             disconnect(m_activeTimeline->projectView(), SIGNAL(showClipFrame(DocClipBase *, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, const int)));
1106
1107             disconnect(m_activeDocument, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
1108             disconnect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement, int)), m_activeTimeline->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement, int)));
1109             disconnect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), m_activeTimeline->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
1110             disconnect(effectStack, SIGNAL(changeEffectState(ClipItem*, int, bool)), m_activeTimeline->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, bool)));
1111             disconnect(effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), trackView->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
1112             disconnect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), m_activeTimeline->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
1113             disconnect(effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
1114             disconnect(transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
1115             disconnect(m_activeTimeline->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
1116             effectStack->clear();
1117         }
1118         m_activeDocument->setRenderer(NULL);
1119         disconnect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
1120         m_clipMonitor->stop();
1121     }
1122     KdenliveSettings::setCurrent_profile(doc->profilePath());
1123     KdenliveSettings::setProject_fps(doc->fps());
1124     m_monitorManager->resetProfiles(doc->timecode());
1125     m_projectList->setDocument(doc);
1126     connect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
1127     connect(m_projectList, SIGNAL(projectModified()), doc, SLOT(setModified()));
1128     connect(trackView, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
1129     connect(trackView, SIGNAL(mousePosition(int)), this, SLOT(slotUpdateMousePosition(int)));
1130     connect(m_projectMonitor, SIGNAL(renderPosition(int)), trackView, SLOT(moveCursorPos(int)));
1131     connect(m_projectMonitor, SIGNAL(durationChanged(int)), trackView, SLOT(setDuration(int)));
1132     connect(doc, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
1133     connect(doc, SIGNAL(addProjectFolder(const QString, const QString &, bool, bool)), m_projectList, SLOT(slotAddFolder(const QString, const QString &, bool, bool)));
1134     connect(doc, SIGNAL(signalDeleteProjectClip(const QString &)), m_projectList, SLOT(slotDeleteClip(const QString &)));
1135     connect(doc, SIGNAL(updateClipDisplay(const QString &)), m_projectList, SLOT(slotUpdateClip(const QString &)));
1136     connect(doc, SIGNAL(refreshClipThumbnail(const QString &)), m_projectList, SLOT(slotRefreshClipThumbnail(const QString &)));
1137     connect(doc, SIGNAL(selectLastAddedClip(const QString &)), m_projectList, SLOT(slotSelectClip(const QString &)));
1138
1139     connect(doc, SIGNAL(deleteTimelineClip(const QString &)), trackView, SLOT(slotDeleteClip(const QString &)));
1140     connect(doc, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
1141
1142
1143
1144     connect(trackView, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*)));
1145     connect(trackView, SIGNAL(clipItemSelected(ClipItem*)), this, SLOT(slotActivateEffectStackView()));
1146     connect(trackView, SIGNAL(transitionItemSelected(Transition*)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*)));
1147     connect(trackView, SIGNAL(transitionItemSelected(Transition*)), this, SLOT(slotActivateTransitionView()));
1148     m_zoomSlider->setValue(doc->zoom());
1149     connect(m_zoomSlider, SIGNAL(valueChanged(int)), trackView, SLOT(slotChangeZoom(int)));
1150     connect(trackView->projectView(), SIGNAL(zoomIn()), this, SLOT(slotZoomIn()));
1151     connect(trackView->projectView(), SIGNAL(zoomOut()), this, SLOT(slotZoomOut()));
1152     connect(trackView->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
1153
1154     connect(trackView->projectView(), SIGNAL(showClipFrame(DocClipBase *, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, const int)));
1155
1156
1157     connect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement, int)), trackView->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement, int)));
1158     connect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), trackView->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
1159     connect(effectStack, SIGNAL(changeEffectState(ClipItem*, int, bool)), trackView->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, bool)));
1160     connect(effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), trackView->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
1161     connect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), trackView->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
1162     connect(transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
1163     connect(effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
1164
1165     connect(trackView->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
1166     trackView->projectView()->setContextMenu(m_timelineContextMenu, m_timelineContextClipMenu, m_timelineContextTransitionMenu);
1167     m_activeTimeline = trackView;
1168     if (m_renderWidget) m_renderWidget->setDocumentStandard(doc->getDocumentStandard());
1169     doc->setRenderer(m_projectMonitor->render);
1170     m_commandStack->setActiveStack(doc->commandStack());
1171     KdenliveSettings::setProject_display_ratio(doc->dar());
1172     doc->updateAllProjectClips();
1173
1174     if (m_commandStack->isClean()) kDebug() << "////////////  UNDO STACK IS CLEAN";
1175     else  kDebug() << "////////////  UNDO STACK IS NOT CLEAN*******************";
1176
1177     //m_overView->setScene(trackView->projectScene());
1178     //m_overView->scale(m_overView->width() / trackView->duration(), m_overView->height() / (50 * trackView->tracksNumber()));
1179     //m_overView->fitInView(m_overView->itemAt(0, 50), Qt::KeepAspectRatio);
1180
1181     setCaption(doc->description(), doc->isModified());
1182     m_saveAction->setEnabled(doc->isModified());
1183     m_activeDocument = doc;
1184 }
1185
1186 void MainWindow::slotPreferences(int page, int option) {
1187     //An instance of your dialog could be already created and could be
1188     // cached, in which case you want to display the cached dialog
1189     // instead of creating another one
1190     if (KConfigDialog::showDialog("settings")) {
1191         if (page != -1) static_cast <KdenliveSettingsDialog*>(KConfigDialog::exists("settings"))->showPage(page, option);
1192         return;
1193     }
1194
1195     // KConfigDialog didn't find an instance of this dialog, so lets
1196     // create it :
1197     KdenliveSettingsDialog* dialog = new KdenliveSettingsDialog(this);
1198     connect(dialog, SIGNAL(settingsChanged(const QString&)), this, SLOT(updateConfiguration()));
1199     connect(dialog, SIGNAL(doResetProfile()), m_monitorManager, SLOT(slotResetProfiles()));
1200     dialog->show();
1201     if (page != -1) dialog->showPage(page, option);
1202 }
1203
1204 void MainWindow::updateConfiguration() {
1205     //TODO: we should apply settings to all projects, not only the current one
1206     if (m_activeTimeline) {
1207         m_activeTimeline->refresh();
1208         m_activeTimeline->projectView()->checkAutoScroll();
1209         m_activeTimeline->projectView()->checkTrackHeight();
1210         if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
1211     }
1212     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
1213     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
1214     activateShuttleDevice();
1215
1216 }
1217
1218 void MainWindow::slotSwitchVideoThumbs() {
1219     KdenliveSettings::setVideothumbnails(!KdenliveSettings::videothumbnails());
1220     if (m_activeTimeline) {
1221         m_activeTimeline->refresh();
1222     }
1223     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
1224 }
1225
1226 void MainWindow::slotSwitchAudioThumbs() {
1227     KdenliveSettings::setAudiothumbnails(!KdenliveSettings::audiothumbnails());
1228     if (m_activeTimeline) {
1229         m_activeTimeline->refresh();
1230         m_activeTimeline->projectView()->checkAutoScroll();
1231         if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
1232     }
1233     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
1234 }
1235
1236 void MainWindow::slotSwitchMarkersComments() {
1237     KdenliveSettings::setShowmarkers(!KdenliveSettings::showmarkers());
1238     if (m_activeTimeline) {
1239         m_activeTimeline->refresh();
1240     }
1241     m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
1242 }
1243
1244 void MainWindow::slotSwitchSnap() {
1245     KdenliveSettings::setSnaptopoints(!KdenliveSettings::snaptopoints());
1246     m_buttonShowMarkers->setChecked(KdenliveSettings::snaptopoints());
1247 }
1248
1249
1250 void MainWindow::slotDeleteTimelineClip() {
1251     if (m_activeTimeline) {
1252         m_activeTimeline->projectView()->deleteSelectedClips();
1253     }
1254 }
1255
1256 void MainWindow::slotChangeClipSpeed() {
1257     if (m_activeTimeline) {
1258         m_activeTimeline->projectView()->changeClipSpeed();
1259     }
1260 }
1261
1262 void MainWindow::slotAddClipMarker() {
1263     if (m_activeTimeline) {
1264         m_activeTimeline->projectView()->slotAddClipMarker();
1265     }
1266 }
1267
1268 void MainWindow::slotDeleteClipMarker() {
1269     if (m_activeTimeline) {
1270         m_activeTimeline->projectView()->slotDeleteClipMarker();
1271     }
1272 }
1273
1274 void MainWindow::slotDeleteAllClipMarkers() {
1275     if (m_activeTimeline) {
1276         m_activeTimeline->projectView()->slotDeleteAllClipMarkers();
1277     }
1278 }
1279
1280 void MainWindow::slotEditClipMarker() {
1281     if (m_activeTimeline) {
1282         m_activeTimeline->projectView()->slotEditClipMarker();
1283     }
1284 }
1285
1286 void MainWindow::slotAddGuide() {
1287     if (m_activeTimeline)
1288         m_activeTimeline->projectView()->slotAddGuide();
1289 }
1290
1291 void MainWindow::slotEditGuide() {
1292     if (m_activeTimeline)
1293         m_activeTimeline->projectView()->slotEditGuide();
1294 }
1295
1296 void MainWindow::slotDeleteGuide() {
1297     if (m_activeTimeline)
1298         m_activeTimeline->projectView()->slotDeleteGuide();
1299 }
1300
1301 void MainWindow::slotDeleteAllGuides() {
1302     if (m_activeTimeline)
1303         m_activeTimeline->projectView()->slotDeleteAllGuides();
1304 }
1305
1306 void MainWindow::slotCutTimelineClip() {
1307     if (m_activeTimeline) {
1308         m_activeTimeline->projectView()->cutSelectedClips();
1309     }
1310 }
1311
1312 void MainWindow::slotAddProjectClip(KUrl url) {
1313     if (m_activeDocument)
1314         m_activeDocument->slotAddClipFile(url, QString());
1315 }
1316
1317 void MainWindow::slotAddTransition(QAction *result) {
1318     if (!result) return;
1319     QDomElement effect = transitions.getEffectByName(result->data().toString());
1320     if (m_activeTimeline) {
1321         m_activeTimeline->projectView()->slotAddTransitionToSelectedClips(effect);
1322     }
1323 }
1324
1325 void MainWindow::slotAddVideoEffect(QAction *result) {
1326     if (!result) return;
1327     QDomElement effect = videoEffects.getEffectByName(result->data().toString());
1328     slotAddEffect(effect);
1329 }
1330
1331 void MainWindow::slotAddAudioEffect(QAction *result) {
1332     if (!result) return;
1333     QDomElement effect = audioEffects.getEffectByName(result->data().toString());
1334     slotAddEffect(effect);
1335 }
1336
1337 void MainWindow::slotAddCustomEffect(QAction *result) {
1338     if (!result) return;
1339     QDomElement effect = customEffects.getEffectByName(result->data().toString());
1340     slotAddEffect(effect);
1341 }
1342
1343 void MainWindow::slotZoomIn() {
1344     m_zoomSlider->setValue(m_zoomSlider->value() - 1);
1345 }
1346
1347 void MainWindow::slotZoomOut() {
1348     m_zoomSlider->setValue(m_zoomSlider->value() + 1);
1349 }
1350
1351 void MainWindow::slotFitZoom() {
1352     if (m_activeTimeline) {
1353         m_zoomSlider->setValue(m_activeTimeline->fitZoom());
1354     }
1355 }
1356
1357 void MainWindow::slotGotProgressInfo(const QString &message, int progress) {
1358     statusProgressBar->setValue(progress);
1359     if (progress >= 0) {
1360         if (!message.isEmpty()) m_messageLabel->setMessage(message, InformationMessage);//statusLabel->setText(message);
1361         statusProgressBar->setVisible(true);
1362     } else {
1363         m_messageLabel->setMessage(QString(), DefaultMessage);
1364         statusProgressBar->setVisible(false);
1365     }
1366 }
1367
1368 void MainWindow::slotShowClipProperties(DocClipBase *clip) {
1369     if (clip->clipType() == TEXT) {
1370         m_activeDocument->editTextClip(clip->getProperty("xml"), clip->getId());
1371         return;
1372     }
1373     ClipProperties dia(clip, m_activeDocument->timecode(), m_activeDocument->fps(), this);
1374     connect(&dia, SIGNAL(addMarker(const QString &, GenTime, QString)), m_activeTimeline->projectView(), SLOT(slotAddClipMarker(const QString &, GenTime, QString)));
1375     if (dia.exec() == QDialog::Accepted) {
1376         m_projectList->slotUpdateClipProperties(dia.clipId(), dia.properties());
1377         if (dia.needsTimelineRefresh()) {
1378             // update clip occurences in timeline
1379             m_activeTimeline->projectView()->slotUpdateClip(dia.clipId());
1380         }
1381     }
1382 }
1383
1384 void MainWindow::customEvent(QEvent* e) {
1385     if (e->type() == QEvent::User) {
1386         // The timeline playing position changed...
1387         kDebug() << "RECIEVED JOG EVEMNT!!!";
1388     }
1389 }
1390 void MainWindow::slotActivateEffectStackView() {
1391     effectStack->raiseWindow(effectStackDock);
1392 }
1393
1394 void MainWindow::slotActivateTransitionView() {
1395     transitionConfig->raiseWindow(transitionConfigDock);
1396 }
1397
1398 void MainWindow::slotSnapRewind() {
1399     if (m_monitorManager->projectMonitorFocused()) {
1400         if (m_activeTimeline)
1401             m_activeTimeline->projectView()->slotSeekToPreviousSnap();
1402     }
1403 }
1404
1405 void MainWindow::slotSnapForward() {
1406     if (m_monitorManager->projectMonitorFocused()) {
1407         if (m_activeTimeline)
1408             m_activeTimeline->projectView()->slotSeekToNextSnap();
1409     }
1410 }
1411
1412 void MainWindow::slotClipStart() {
1413     if (m_monitorManager->projectMonitorFocused()) {
1414         if (m_activeTimeline)
1415             m_activeTimeline->projectView()->clipStart();
1416     }
1417 }
1418
1419 void MainWindow::slotClipEnd() {
1420     if (m_monitorManager->projectMonitorFocused()) {
1421         if (m_activeTimeline)
1422             m_activeTimeline->projectView()->clipEnd();
1423     }
1424 }
1425
1426 void MainWindow::slotChangeTool(QAction * action) {
1427     if (action == m_buttonSelectTool) slotSetTool(SELECTTOOL);
1428     else if (action == m_buttonRazorTool) slotSetTool(RAZORTOOL);
1429 }
1430
1431 void MainWindow::slotSetTool(PROJECTTOOL tool) {
1432     if (m_activeDocument && m_activeTimeline) {
1433         //m_activeDocument->setTool(tool);
1434         m_activeTimeline->projectView()->setTool(tool);
1435     }
1436 }
1437
1438 void MainWindow::slotCopy() {
1439     if (!m_activeDocument || !m_activeTimeline) return;
1440     m_activeTimeline->projectView()->copyClip();
1441 }
1442
1443 void MainWindow::slotPaste() {
1444     if (!m_activeDocument || !m_activeTimeline) return;
1445     m_activeTimeline->projectView()->pasteClip();
1446 }
1447
1448 void MainWindow::slotPasteEffects() {
1449     if (!m_activeDocument || !m_activeTimeline) return;
1450     m_activeTimeline->projectView()->pasteClipEffects();
1451 }
1452
1453 void MainWindow::slotFind() {
1454     if (!m_activeDocument || !m_activeTimeline) return;
1455     m_projectSearch->setEnabled(false);
1456     m_findActivated = true;
1457     m_findString = QString();
1458     m_activeTimeline->projectView()->initSearchStrings();
1459     statusBar()->showMessage(i18n("Starting -- find text as you type"));
1460     m_findTimer.start(5000);
1461     qApp->installEventFilter(this);
1462 }
1463
1464 void MainWindow::slotFindNext() {
1465     if (m_activeTimeline && m_activeTimeline->projectView()->findNextString(m_findString)) {
1466         statusBar()->showMessage(i18n("Found : %1", m_findString));
1467     } else {
1468         statusBar()->showMessage(i18n("Reached end of project"));
1469     }
1470     m_findTimer.start(4000);
1471 }
1472
1473 void MainWindow::findAhead() {
1474     if (m_activeTimeline && m_activeTimeline->projectView()->findString(m_findString)) {
1475         m_projectSearchNext->setEnabled(true);
1476         statusBar()->showMessage(i18n("Found : %1", m_findString));
1477     } else {
1478         m_projectSearchNext->setEnabled(false);
1479         statusBar()->showMessage(i18n("Not found : %1", m_findString));
1480     }
1481 }
1482
1483 void MainWindow::findTimeout() {
1484     m_projectSearchNext->setEnabled(false);
1485     m_findActivated = false;
1486     m_findString = QString();
1487     statusBar()->showMessage(i18n("Find stopped"), 3000);
1488     if (m_activeTimeline) m_activeTimeline->projectView()->clearSearchStrings();
1489     m_projectSearch->setEnabled(true);
1490     removeEventFilter(this);
1491 }
1492
1493 void MainWindow::keyPressEvent(QKeyEvent *ke) {
1494     if (m_findActivated) {
1495         if (ke->key() == Qt::Key_Backspace) {
1496             m_findString = m_findString.left(m_findString.length() - 1);
1497
1498             if (!m_findString.isEmpty()) {
1499                 findAhead();
1500             } else {
1501                 findTimeout();
1502             }
1503
1504             m_findTimer.start(4000);
1505             ke->accept();
1506             return;
1507         } else if (ke->key() == Qt::Key_Escape) {
1508             findTimeout();
1509             ke->accept();
1510             return;
1511         } else if (ke->key() == Qt::Key_Space || !ke->text().trimmed().isEmpty()) {
1512             m_findString += ke->text();
1513
1514             findAhead();
1515
1516             m_findTimer.start(4000);
1517             ke->accept();
1518             return;
1519         }
1520     } else KXmlGuiWindow::keyPressEvent(ke);
1521 }
1522
1523 bool MainWindow::eventFilter(QObject *obj, QEvent *event) {
1524     if (m_findActivated) {
1525         if (event->type() == QEvent::ShortcutOverride) {
1526             QKeyEvent* ke = (QKeyEvent*) event;
1527             if (ke->text().trimmed().isEmpty()) return false;
1528             ke->accept();
1529             return true;
1530         } else return false;
1531     } else {
1532         // pass the event on to the parent class
1533         return QMainWindow::eventFilter(obj, event);
1534     }
1535 }
1536
1537 #include "mainwindow.moc"