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