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