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