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