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