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