]> git.sesse.net Git - kdenlive/blob - src/mainwindow.cpp
Avoid loop if no MLT found
[kdenlive] / src / mainwindow.cpp
1 /***************************************************************************
2  *   Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3  *                                                                         *
4  *   This program is free software; you can redistribute it and/or modify  *
5  *   it under the terms of the GNU General Public License as published by  *
6  *   the Free Software Foundation; either version 2 of the License, or     *
7  *   (at your option) any later version.                                   *
8  *                                                                         *
9  *   This program is distributed in the hope that it will be useful,       *
10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12  *   GNU General Public License for more details.                          *
13  *                                                                         *
14  *   You should have received a copy of the GNU General Public License     *
15  *   along with this program; if not, write to the                         *
16  *   Free Software Foundation, Inc.,                                       *
17  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
18  ***************************************************************************/
19
20 #include <stdlib.h>
21
22 #include <QTextStream>
23 #include <QTimer>
24 #include <QAction>
25 #include <QtTest>
26 #include <QtCore>
27 #include <QKeyEvent>
28
29 #include <KApplication>
30 #include <KAction>
31 #include <KLocale>
32 #include <KGlobal>
33 #include <KActionCollection>
34 #include <KStandardAction>
35 #include <KFileDialog>
36 #include <KMessageBox>
37 #include <KDebug>
38 #include <KIO/NetAccess>
39 #include <KSaveFile>
40 #include <KRuler>
41 #include <KConfigDialog>
42 #include <KXMLGUIFactory>
43 #include <KStatusBar>
44 #include <kstandarddirs.h>
45 #include <KUrlRequesterDialog>
46 #include <KTemporaryFile>
47 #include <KActionMenu>
48 #include <KMenu>
49 #include <locale.h>
50 #include <ktogglefullscreenaction.h>
51 #include <KFileItem>
52 #include <KNotification>
53 #include <KNotifyConfigWidget>
54
55 #include <mlt++/Mlt.h>
56
57 #include "mainwindow.h"
58 #include "kdenlivesettings.h"
59 #include "kdenlivesettingsdialog.h"
60 #include "initeffects.h"
61 #include "profilesdialog.h"
62 #include "projectsettings.h"
63 #include "events.h"
64 #include "clipmanager.h"
65 #include "projectlist.h"
66 #include "monitor.h"
67 #include "recmonitor.h"
68 #include "monitormanager.h"
69 #include "kdenlivedoc.h"
70 #include "trackview.h"
71 #include "customtrackview.h"
72 #include "effectslistview.h"
73 #include "effectstackview.h"
74 #include "transitionsettings.h"
75 #include "renderwidget.h"
76 #include "renderer.h"
77 #include "jogshuttle.h"
78 #include "clipproperties.h"
79 #include "wizard.h"
80 #include "editclipcommand.h"
81 #include "titlewidget.h"
82
83 static const int ID_STATUS_MSG = 1;
84 static const int ID_EDITMODE_MSG = 2;
85 static const int ID_TIMELINE_MSG = 3;
86 static const int ID_TIMELINE_BUTTONS = 5;
87 static const int ID_TIMELINE_POS = 6;
88 static const int ID_TIMELINE_FORMAT = 7;
89
90 namespace Mlt {
91 class Producer;
92 };
93
94 EffectsList MainWindow::videoEffects;
95 EffectsList MainWindow::audioEffects;
96 EffectsList MainWindow::customEffects;
97 EffectsList MainWindow::transitions;
98
99 MainWindow::MainWindow(QWidget *parent)
100         : KXmlGuiWindow(parent),
101         m_activeDocument(NULL), m_activeTimeline(NULL), m_renderWidget(NULL), m_jogProcess(NULL), m_findActivated(false), m_initialized(false) {
102     setlocale(LC_NUMERIC, "POSIX");
103     setFont(KGlobalSettings::toolBarFont());
104     parseProfiles();
105     m_commandStack = new QUndoGroup;
106     m_timelineArea = new KTabWidget(this);
107     m_timelineArea->setTabReorderingEnabled(true);
108     m_timelineArea->setTabBarHidden(true);
109
110     QToolButton *closeTabButton = new QToolButton;
111     connect(closeTabButton, SIGNAL(clicked()), this, SLOT(closeCurrentDocument()));
112     closeTabButton->setIcon(KIcon("tab-close"));
113     closeTabButton->adjustSize();
114     closeTabButton->setToolTip(i18n("Close the current tab"));
115     m_timelineArea->setCornerWidget(closeTabButton);
116     connect(m_timelineArea, SIGNAL(currentChanged(int)), this, SLOT(activateDocument()));
117
118     connect(&m_findTimer, SIGNAL(timeout()), this, SLOT(findTimeout()));
119     m_findTimer.setSingleShot(true);
120
121     initEffects::parseEffectFiles();
122     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             ::exit(1);
800         }
801     }
802 }
803
804 void MainWindow::newFile() {
805     QString profileName;
806     KUrl projectFolder;
807     QPoint projectTracks(3, 2);
808     if (m_timelineArea->count() == 0) profileName = KdenliveSettings::default_profile();
809     else {
810         ProjectSettings *w = new ProjectSettings;
811         if (w->exec() != QDialog::Accepted) return;
812         profileName = w->selectedProfile();
813         projectFolder = w->selectedFolder();
814         projectTracks = w->tracks();
815         delete w;
816     }
817     KdenliveDoc *doc = new KdenliveDoc(KUrl(), projectFolder, m_commandStack, profileName, projectTracks,  this);
818     doc->m_autosave = new KAutoSaveFile(KUrl(), doc);
819     TrackView *trackView = new TrackView(doc, this);
820     m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description());
821     if (m_timelineArea->count() == 1) {
822         connectDocumentInfo(doc);
823         connectDocument(trackView, doc);
824     } else m_timelineArea->setTabBarHidden(false);
825 }
826
827 void MainWindow::activateDocument() {
828     if (m_timelineArea->currentWidget() == NULL) return;
829     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
830     KdenliveDoc *currentDoc = currentTab->document();
831     connectDocumentInfo(currentDoc);
832     connectDocument(currentTab, currentDoc);
833 }
834
835 void MainWindow::closeCurrentDocument() {
836     QWidget *w = m_timelineArea->currentWidget();
837     // closing current document
838     int ix = m_timelineArea->currentIndex() + 1;
839     if (ix == m_timelineArea->count()) ix = 0;
840     m_timelineArea->setCurrentIndex(ix);
841     TrackView *tabToClose = (TrackView *) w;
842     KdenliveDoc *docToClose = tabToClose->document();
843     if (docToClose && docToClose->isModified()) {
844         switch (KMessageBox::warningYesNoCancel(this, i18n("Save changes to document ?"))) {
845         case KMessageBox::Yes :
846             // save document here. If saving fails, return false;
847             saveFile();
848             break;
849         case KMessageBox::Cancel :
850             return;
851         default:
852             break;
853         }
854     }
855     m_timelineArea->removeTab(m_timelineArea->indexOf(w));
856     if (m_timelineArea->count() == 1) m_timelineArea->setTabBarHidden(true);
857     delete docToClose;
858     delete w;
859     if (m_timelineArea->count() == 0) m_activeDocument = NULL;
860 }
861
862 void MainWindow::saveFileAs(const QString &outputFileName) {
863     m_projectMonitor->saveSceneList(outputFileName, m_activeDocument->documentInfoXml());
864     m_activeDocument->setUrl(KUrl(outputFileName));
865     if (m_activeDocument->m_autosave == NULL) {
866         m_activeDocument->m_autosave = new KAutoSaveFile(KUrl(outputFileName), this);
867     } else m_activeDocument->m_autosave->setManagedFile(KUrl(outputFileName));
868     setCaption(m_activeDocument->description());
869     m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
870     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), m_activeDocument->url().path());
871     m_activeDocument->setModified(false);
872     m_fileOpenRecent->addUrl(KUrl(outputFileName));
873 }
874
875 void MainWindow::saveFileAs() {
876     QString outputFile = KFileDialog::getSaveFileName(KUrl(), "*.kdenlive|Kdenlive project files (*.kdenlive)");
877     if (QFile::exists(outputFile)) {
878         if (KMessageBox::questionYesNo(this, i18n("File already exists.\nDo you want to overwrite it ?")) == KMessageBox::No) return;
879     }
880     saveFileAs(outputFile);
881 }
882
883 void MainWindow::saveFile() {
884     if (!m_activeDocument) return;
885     if (m_activeDocument->url().isEmpty()) {
886         saveFileAs();
887     } else {
888         saveFileAs(m_activeDocument->url().path());
889         m_activeDocument->m_autosave->resize(0);
890     }
891 }
892
893 void MainWindow::openFile() {
894     KUrl url = KFileDialog::getOpenUrl(KUrl(), "*.kdenlive|Kdenlive project files (*.kdenlive)\n*.westley|MLT project files (*.westley)");
895     if (url.isEmpty()) return;
896     m_fileOpenRecent->addUrl(url);
897     openFile(url);
898 }
899
900 void MainWindow::openLastFile() {
901     KSharedConfigPtr config = KGlobal::config();
902     KUrl::List urls = m_fileOpenRecent->urls();
903     if (urls.isEmpty()) newFile();
904     else openFile(urls.last());
905 }
906
907 void MainWindow::openFile(const KUrl &url) {
908     // Check for backup file
909     QList<KAutoSaveFile *> staleFiles = KAutoSaveFile::staleFiles(url);
910     if (!staleFiles.isEmpty()) {
911         if (KMessageBox::questionYesNo(this,
912                                        i18n("Auto-saved files exist. Do you want to recover them now?"),
913                                        i18n("File Recovery"),
914                                        KGuiItem(i18n("Recover")), KGuiItem(i18n("Don't recover"))) == KMessageBox::Yes) {
915             recoverFiles(staleFiles);
916             return;
917         } else {
918             // remove the stale files
919             foreach(KAutoSaveFile *stale, staleFiles) {
920                 stale->open(QIODevice::ReadWrite);
921                 delete stale;
922             }
923         }
924     }
925     if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
926     doOpenFile(url, NULL);
927 }
928
929 void MainWindow::doOpenFile(const KUrl &url, KAutoSaveFile *stale) {
930     KdenliveDoc *doc;
931     doc = new KdenliveDoc(url, KUrl(), m_commandStack, QString(), QPoint(3, 2), this);
932     if (stale == NULL) {
933         stale = new KAutoSaveFile(url, doc);
934         doc->m_autosave = stale;
935     } else {
936         doc->m_autosave = stale;
937         doc->setUrl(stale->managedFile());
938         doc->setModified(true);
939         stale->setParent(doc);
940     }
941     connectDocumentInfo(doc);
942     TrackView *trackView = new TrackView(doc, this);
943     m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description()));
944     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), doc->url().path());
945     if (m_timelineArea->count() > 1) m_timelineArea->setTabBarHidden(false);
946     slotGotProgressInfo(QString(), -1);
947     m_clipMonitor->refreshMonitor(true);
948 }
949
950 void MainWindow::recoverFiles(QList<KAutoSaveFile *> staleFiles) {
951     if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
952     foreach(KAutoSaveFile *stale, staleFiles) {
953         /*if (!stale->open(QIODevice::QIODevice::ReadOnly)) {
954                   // show an error message; we could not steal the lockfile
955                   // maybe another application got to the file before us?
956                   delete stale;
957                   continue;
958         }*/
959         kDebug() << "// OPENING RECOVERY: " << stale->fileName() << "\nMANAGED: " << stale->managedFile().path();
960         // the stalefiles also contain ".lock" files so we must ignore them... bug in KAutoSaveFile ?
961         if (!stale->fileName().endsWith(".lock")) doOpenFile(KUrl(stale->fileName()), stale);
962         else KIO::NetAccess::del(KUrl(stale->fileName()), this);
963     }
964 }
965
966
967 void MainWindow::parseProfiles() {
968     //kdDebug()<<" + + YOUR MLT INSTALL WAS FOUND IN: "<< MLT_PREFIX <<endl;
969
970     //KdenliveSettings::setDefaulttmpfolder();
971     if (KdenliveSettings::mltpath().isEmpty()) {
972         KdenliveSettings::setMltpath(QString(MLT_PREFIX) + QString("/share/mlt/profiles/"));
973     }
974     if (KdenliveSettings::rendererpath().isEmpty()) {
975         QString inigoPath = QString(MLT_PREFIX) + QString("/bin/inigo");
976         if (!QFile::exists(inigoPath))
977             inigoPath = KStandardDirs::findExe("inigo");
978         else KdenliveSettings::setRendererpath(inigoPath);
979     }
980     QStringList profilesFilter;
981     profilesFilter << "*";
982     QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
983
984     if (profilesList.isEmpty()) {
985         // Cannot find MLT path, try finding inigo
986         QString profilePath = KdenliveSettings::rendererpath();
987         if (!profilePath.isEmpty()) {
988             profilePath = profilePath.section('/', 0, -3);
989             KdenliveSettings::setMltpath(profilePath + "/share/mlt/profiles/");
990             QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
991         }
992
993         if (profilesList.isEmpty()) {
994             // Cannot find the MLT profiles, ask for location
995             KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find your Mlt profiles, please give the path"), this);
996             getUrl->fileDialog()->setMode(KFile::Directory);
997             if (getUrl->exec() == QDialog::Rejected) {
998                 ::exit(0);
999             }
1000             KUrl mltPath = getUrl->selectedUrl();
1001             delete getUrl;
1002             if (mltPath.isEmpty()) ::exit(0);
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         if (getUrl->exec() == QDialog::Rejected) {
1012             ::exit(0);
1013         }
1014         KUrl rendererPath = getUrl->selectedUrl();
1015         delete getUrl;
1016         if (rendererPath.isEmpty()) ::exit(0);
1017         KdenliveSettings::setRendererpath(rendererPath.path());
1018     }
1019
1020     kDebug() << "RESULTING MLT PATH: " << KdenliveSettings::mltpath();
1021
1022     // Parse MLT profiles to build a list of available video formats
1023     if (profilesList.isEmpty()) parseProfiles();
1024 }
1025
1026
1027 void MainWindow::slotEditProfiles() {
1028     ProfilesDialog *w = new ProfilesDialog;
1029     w->exec();
1030     delete w;
1031 }
1032
1033 void MainWindow::slotEditProjectSettings() {
1034     ProjectSettings *w = new ProjectSettings;
1035     if (w->exec() == QDialog::Accepted) {
1036         QString profile = w->selectedProfile();
1037         m_activeDocument->setProfilePath(profile);
1038         KdenliveSettings::setCurrent_profile(profile);
1039         KdenliveSettings::setProject_fps(m_activeDocument->fps());
1040         setCaption(m_activeDocument->description(), m_activeDocument->isModified());
1041         m_monitorManager->resetProfiles(m_activeDocument->timecode());
1042         if (m_renderWidget) m_renderWidget->setDocumentStandard(m_activeDocument->getDocumentStandard());
1043         m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
1044
1045         // We need to desactivate & reactivate monitors to get a refresh
1046         m_monitorManager->switchMonitors();
1047     }
1048     delete w;
1049 }
1050
1051 void MainWindow::slotRenderProject() {
1052     if (!m_renderWidget) {
1053         m_renderWidget = new RenderWidget(this);
1054         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)));
1055         if (m_activeDocument) m_renderWidget->setGuides(m_activeDocument->guidesXml(), m_activeDocument->projectDuration());
1056     }
1057     /*TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
1058     if (currentTab) m_renderWidget->setTimeline(currentTab);
1059     m_renderWidget->setDocument(m_activeDocument);*/
1060     m_renderWidget->show();
1061 }
1062
1063 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) {
1064     if (dest.isEmpty()) return;
1065     int in;
1066     int out;
1067     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
1068     if (currentTab && zoneOnly) {
1069         in = currentTab->inPoint();
1070         out = currentTab->outPoint();
1071     }
1072     KTemporaryFile temp;
1073     temp.setAutoRemove(false);
1074     temp.setSuffix(".westley");
1075     if (temp.open()) {
1076         m_projectMonitor->saveSceneList(temp.fileName());
1077         QStringList args;
1078         args << "-erase";
1079         if (zoneOnly) args << "in=" + QString::number(in) << "out=" + QString::number(out);
1080         else if (guideStart != -1) {
1081             args << "in=" + QString::number(GenTime(guideStart).frames(m_activeDocument->fps())) << "out=" + QString::number(GenTime(guideEnd).frames(m_activeDocument->fps()));
1082         }
1083         if (!overlay_args.isEmpty()) args << "preargs=" + overlay_args.join(" ");
1084         QString videoPlayer = "-";
1085         if (playAfter) {
1086             videoPlayer = KdenliveSettings::defaultplayerapp();
1087             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."));
1088         }
1089         args << KdenliveSettings::rendererpath() << m_activeDocument->profilePath() << render << videoPlayer << temp.fileName() << dest << avformat_args;
1090         QString renderer = QCoreApplication::applicationDirPath() + QString("/kdenlive_render");
1091         if (!QFile::exists(renderer)) renderer = "kdenlive_render";
1092         QProcess::startDetached(renderer, args);
1093
1094         KNotification::event("RenderStarted", i18n("Rendering <i>%1</i> started", dest), QPixmap(), this);
1095     }
1096 }
1097
1098 void MainWindow::slotUpdateMousePosition(int pos) {
1099     if (m_activeDocument)
1100         switch (m_timecodeFormat->currentIndex()) {
1101         case 0:
1102             statusBar()->changeItem(m_activeDocument->timecode().getTimecodeFromFrames(pos), ID_TIMELINE_POS);
1103             break;
1104         default:
1105             statusBar()->changeItem(QString::number(pos), ID_TIMELINE_POS);
1106         }
1107 }
1108
1109 void MainWindow::slotUpdateDocumentState(bool modified) {
1110     setCaption(m_activeDocument->description(), modified);
1111     m_saveAction->setEnabled(modified);
1112     if (modified) {
1113         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Link));
1114         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("document-save"));
1115     } else {
1116         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Text));
1117         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("kdenlive"));
1118     }
1119 }
1120
1121 void MainWindow::connectDocumentInfo(KdenliveDoc *doc) {
1122     if (m_activeDocument) {
1123         if (m_activeDocument == doc) return;
1124         disconnect(m_activeDocument, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
1125     }
1126     connect(doc, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
1127 }
1128
1129 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //changed
1130     //m_projectMonitor->stop();
1131     kDebug() << "///////////////////   CONNECTING DOC TO PROJECT VIEW ////////////////";
1132     if (m_activeDocument) {
1133         if (m_activeDocument == doc) return;
1134         m_activeDocument->backupMltPlaylist();
1135         if (m_activeTimeline) {
1136             disconnect(m_projectMonitor, SIGNAL(renderPosition(int)), m_activeTimeline, SLOT(moveCursorPos(int)));
1137             disconnect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), trackView, SLOT(slotSetZone(QPoint)));
1138             disconnect(m_projectMonitor, SIGNAL(durationChanged(int)), m_activeTimeline, SLOT(setDuration(int)));
1139             disconnect(m_projectList, SIGNAL(projectModified()), m_activeDocument, SLOT(setModified()));
1140             disconnect(m_activeDocument, SIGNAL(guidesUpdated()), this, SLOT(slotGuidesUpdated()));
1141             disconnect(m_activeDocument, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
1142             disconnect(m_activeDocument, SIGNAL(addProjectFolder(const QString, const QString &, bool, bool)), m_projectList, SLOT(slotAddFolder(const QString, const QString &, bool, bool)));
1143             disconnect(m_activeDocument, SIGNAL(signalDeleteProjectClip(const QString &)), m_projectList, SLOT(slotDeleteClip(const QString &)));
1144             disconnect(m_activeDocument, SIGNAL(updateClipDisplay(const QString &)), m_projectList, SLOT(slotUpdateClip(const QString &)));
1145             disconnect(m_activeDocument, SIGNAL(selectLastAddedClip(const QString &)), m_projectList, SLOT(slotSelectClip(const QString &)));
1146             disconnect(m_activeDocument, SIGNAL(deleteTimelineClip(const QString &)), m_activeTimeline, SLOT(slotDeleteClip(const QString &)));
1147             disconnect(m_activeTimeline, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*)));
1148             disconnect(m_activeTimeline, SIGNAL(clipItemSelected(ClipItem*)), this, SLOT(slotActivateEffectStackView()));
1149             disconnect(m_activeTimeline, SIGNAL(transitionItemSelected(Transition*)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*)));
1150             disconnect(m_activeTimeline, SIGNAL(transitionItemSelected(Transition*)), this, SLOT(slotActivateTransitionView()));
1151             disconnect(m_zoomSlider, SIGNAL(valueChanged(int)), m_activeTimeline, SLOT(slotChangeZoom(int)));
1152             disconnect(m_activeTimeline->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
1153             disconnect(m_activeTimeline->projectView(), SIGNAL(showClipFrame(DocClipBase *, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, const int)));
1154
1155             disconnect(m_activeDocument, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
1156             disconnect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement, int)), m_activeTimeline->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement, int)));
1157             disconnect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), m_activeTimeline->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
1158             disconnect(effectStack, SIGNAL(changeEffectState(ClipItem*, int, bool)), m_activeTimeline->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, bool)));
1159             disconnect(effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), trackView->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
1160             disconnect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), m_activeTimeline->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
1161             disconnect(effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
1162             disconnect(transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
1163             disconnect(transitionConfig, SIGNAL(seekTimeline(int)), trackView->projectView() , SLOT(setCursorPos(int)));
1164             disconnect(m_activeTimeline->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
1165             disconnect(trackView, SIGNAL(zoneMoved(int, int)), m_projectMonitor, SLOT(slotZoneMoved(int, int)));
1166             effectStack->clear();
1167         }
1168         m_activeDocument->setRenderer(NULL);
1169         disconnect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
1170         m_clipMonitor->stop();
1171     }
1172     KdenliveSettings::setCurrent_profile(doc->profilePath());
1173     KdenliveSettings::setProject_fps(doc->fps());
1174     m_monitorManager->resetProfiles(doc->timecode());
1175     m_projectList->setDocument(doc);
1176     transitionConfig->updateProjectFormat(doc->mltProfile());
1177     connect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
1178     connect(m_projectList, SIGNAL(projectModified()), doc, SLOT(setModified()));
1179     connect(trackView, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
1180     connect(trackView, SIGNAL(mousePosition(int)), this, SLOT(slotUpdateMousePosition(int)));
1181     connect(m_projectMonitor, SIGNAL(renderPosition(int)), trackView, SLOT(moveCursorPos(int)));
1182     connect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), trackView, SLOT(slotSetZone(QPoint)));
1183     connect(m_projectMonitor, SIGNAL(durationChanged(int)), trackView, SLOT(setDuration(int)));
1184     connect(doc, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
1185     connect(doc, SIGNAL(addProjectFolder(const QString, const QString &, bool, bool)), m_projectList, SLOT(slotAddFolder(const QString, const QString &, bool, bool)));
1186     connect(doc, SIGNAL(signalDeleteProjectClip(const QString &)), m_projectList, SLOT(slotDeleteClip(const QString &)));
1187     connect(doc, SIGNAL(updateClipDisplay(const QString &)), m_projectList, SLOT(slotUpdateClip(const QString &)));
1188     connect(doc, SIGNAL(selectLastAddedClip(const QString &)), m_projectList, SLOT(slotSelectClip(const QString &)));
1189
1190     connect(doc, SIGNAL(deleteTimelineClip(const QString &)), trackView, SLOT(slotDeleteClip(const QString &)));
1191     connect(doc, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
1192     connect(doc, SIGNAL(guidesUpdated()), this, SLOT(slotGuidesUpdated()));
1193
1194
1195     connect(trackView, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*)));
1196     connect(trackView, SIGNAL(clipItemSelected(ClipItem*)), this, SLOT(slotActivateEffectStackView()));
1197     connect(trackView, SIGNAL(transitionItemSelected(Transition*)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*)));
1198     connect(trackView, SIGNAL(transitionItemSelected(Transition*)), this, SLOT(slotActivateTransitionView()));
1199     m_zoomSlider->setValue(doc->zoom());
1200     connect(m_zoomSlider, SIGNAL(valueChanged(int)), trackView, SLOT(slotChangeZoom(int)));
1201     connect(trackView->projectView(), SIGNAL(zoomIn()), this, SLOT(slotZoomIn()));
1202     connect(trackView->projectView(), SIGNAL(zoomOut()), this, SLOT(slotZoomOut()));
1203     connect(trackView->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
1204
1205     connect(trackView->projectView(), SIGNAL(showClipFrame(DocClipBase *, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, const int)));
1206
1207
1208     connect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement, int)), trackView->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement, int)));
1209     connect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), trackView->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
1210     connect(effectStack, SIGNAL(changeEffectState(ClipItem*, int, bool)), trackView->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, bool)));
1211     connect(effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), trackView->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
1212     connect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), trackView->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
1213     connect(transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
1214     connect(transitionConfig, SIGNAL(seekTimeline(int)), trackView->projectView() , SLOT(setCursorPos(int)));
1215     connect(effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
1216
1217     connect(trackView->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
1218     connect(trackView, SIGNAL(zoneMoved(int, int)), m_projectMonitor, SLOT(slotZoneMoved(int, int)));
1219
1220     trackView->projectView()->setContextMenu(m_timelineContextMenu, m_timelineContextClipMenu, m_timelineContextTransitionMenu);
1221     m_activeTimeline = trackView;
1222     if (m_renderWidget) m_renderWidget->setDocumentStandard(doc->getDocumentStandard());
1223     doc->setRenderer(m_projectMonitor->render);
1224     m_commandStack->setActiveStack(doc->commandStack());
1225     KdenliveSettings::setProject_display_ratio(doc->dar());
1226     m_projectList->updateAllClips();
1227     trackView->projectView()->updateAllThumbs();
1228
1229
1230     //m_overView->setScene(trackView->projectScene());
1231     //m_overView->scale(m_overView->width() / trackView->duration(), m_overView->height() / (50 * trackView->tracksNumber()));
1232     //m_overView->fitInView(m_overView->itemAt(0, 50), Qt::KeepAspectRatio);
1233
1234     setCaption(doc->description(), doc->isModified());
1235     m_saveAction->setEnabled(doc->isModified());
1236     m_activeDocument = doc;
1237 }
1238
1239 void MainWindow::slotGuidesUpdated() {
1240     if (m_renderWidget) m_renderWidget->setGuides(m_activeDocument->guidesXml(), m_activeDocument->projectDuration());
1241 }
1242
1243 void MainWindow::slotPreferences(int page, int option) {
1244     //An instance of your dialog could be already created and could be
1245     // cached, in which case you want to display the cached dialog
1246     // instead of creating another one
1247     if (KConfigDialog::showDialog("settings")) {
1248         if (page != -1) static_cast <KdenliveSettingsDialog*>(KConfigDialog::exists("settings"))->showPage(page, option);
1249         return;
1250     }
1251
1252     // KConfigDialog didn't find an instance of this dialog, so lets
1253     // create it :
1254     KdenliveSettingsDialog* dialog = new KdenliveSettingsDialog(this);
1255     connect(dialog, SIGNAL(settingsChanged(const QString&)), this, SLOT(updateConfiguration()));
1256     connect(dialog, SIGNAL(doResetProfile()), m_monitorManager, SLOT(slotResetProfiles()));
1257     dialog->show();
1258     if (page != -1) dialog->showPage(page, option);
1259 }
1260
1261 void MainWindow::updateConfiguration() {
1262     //TODO: we should apply settings to all projects, not only the current one
1263     if (m_activeTimeline) {
1264         m_activeTimeline->refresh();
1265         m_activeTimeline->projectView()->checkAutoScroll();
1266         m_activeTimeline->projectView()->checkTrackHeight();
1267         if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
1268     }
1269     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
1270     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
1271     activateShuttleDevice();
1272
1273 }
1274
1275 void MainWindow::slotSwitchVideoThumbs() {
1276     KdenliveSettings::setVideothumbnails(!KdenliveSettings::videothumbnails());
1277     if (m_activeTimeline) {
1278         m_activeTimeline->refresh();
1279     }
1280     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
1281 }
1282
1283 void MainWindow::slotSwitchAudioThumbs() {
1284     KdenliveSettings::setAudiothumbnails(!KdenliveSettings::audiothumbnails());
1285     if (m_activeTimeline) {
1286         m_activeTimeline->refresh();
1287         m_activeTimeline->projectView()->checkAutoScroll();
1288         if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
1289     }
1290     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
1291 }
1292
1293 void MainWindow::slotSwitchMarkersComments() {
1294     KdenliveSettings::setShowmarkers(!KdenliveSettings::showmarkers());
1295     if (m_activeTimeline) {
1296         m_activeTimeline->refresh();
1297     }
1298     m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
1299 }
1300
1301 void MainWindow::slotSwitchSnap() {
1302     KdenliveSettings::setSnaptopoints(!KdenliveSettings::snaptopoints());
1303     m_buttonShowMarkers->setChecked(KdenliveSettings::snaptopoints());
1304 }
1305
1306
1307 void MainWindow::slotDeleteTimelineClip() {
1308     if (m_activeTimeline) {
1309         m_activeTimeline->projectView()->deleteSelectedClips();
1310     }
1311 }
1312
1313 void MainWindow::slotChangeClipSpeed() {
1314     if (m_activeTimeline) {
1315         m_activeTimeline->projectView()->changeClipSpeed();
1316     }
1317 }
1318
1319 void MainWindow::slotAddClipMarker() {
1320     if (m_activeTimeline) {
1321         m_activeTimeline->projectView()->slotAddClipMarker();
1322     }
1323 }
1324
1325 void MainWindow::slotDeleteClipMarker() {
1326     if (m_activeTimeline) {
1327         m_activeTimeline->projectView()->slotDeleteClipMarker();
1328     }
1329 }
1330
1331 void MainWindow::slotDeleteAllClipMarkers() {
1332     if (m_activeTimeline) {
1333         m_activeTimeline->projectView()->slotDeleteAllClipMarkers();
1334     }
1335 }
1336
1337 void MainWindow::slotEditClipMarker() {
1338     if (m_activeTimeline) {
1339         m_activeTimeline->projectView()->slotEditClipMarker();
1340     }
1341 }
1342
1343 void MainWindow::slotAddGuide() {
1344     if (m_activeTimeline)
1345         m_activeTimeline->projectView()->slotAddGuide();
1346 }
1347
1348 void MainWindow::slotEditGuide() {
1349     if (m_activeTimeline)
1350         m_activeTimeline->projectView()->slotEditGuide();
1351 }
1352
1353 void MainWindow::slotDeleteGuide() {
1354     if (m_activeTimeline)
1355         m_activeTimeline->projectView()->slotDeleteGuide();
1356 }
1357
1358 void MainWindow::slotDeleteAllGuides() {
1359     if (m_activeTimeline)
1360         m_activeTimeline->projectView()->slotDeleteAllGuides();
1361 }
1362
1363 void MainWindow::slotCutTimelineClip() {
1364     if (m_activeTimeline) {
1365         m_activeTimeline->projectView()->cutSelectedClips();
1366     }
1367 }
1368
1369 void MainWindow::slotAddProjectClip(KUrl url) {
1370     if (m_activeDocument)
1371         m_activeDocument->slotAddClipFile(url, QString());
1372 }
1373
1374 void MainWindow::slotAddTransition(QAction *result) {
1375     if (!result) return;
1376     QDomElement effect = transitions.getEffectByName(result->data().toString());
1377     if (m_activeTimeline) {
1378         m_activeTimeline->projectView()->slotAddTransitionToSelectedClips(effect);
1379     }
1380 }
1381
1382 void MainWindow::slotAddVideoEffect(QAction *result) {
1383     if (!result) return;
1384     QDomElement effect = videoEffects.getEffectByName(result->data().toString());
1385     slotAddEffect(effect);
1386 }
1387
1388 void MainWindow::slotAddAudioEffect(QAction *result) {
1389     if (!result) return;
1390     QDomElement effect = audioEffects.getEffectByName(result->data().toString());
1391     slotAddEffect(effect);
1392 }
1393
1394 void MainWindow::slotAddCustomEffect(QAction *result) {
1395     if (!result) return;
1396     QDomElement effect = customEffects.getEffectByName(result->data().toString());
1397     slotAddEffect(effect);
1398 }
1399
1400 void MainWindow::slotZoomIn() {
1401     m_zoomSlider->setValue(m_zoomSlider->value() - 1);
1402 }
1403
1404 void MainWindow::slotZoomOut() {
1405     m_zoomSlider->setValue(m_zoomSlider->value() + 1);
1406 }
1407
1408 void MainWindow::slotFitZoom() {
1409     if (m_activeTimeline) {
1410         m_zoomSlider->setValue(m_activeTimeline->fitZoom());
1411     }
1412 }
1413
1414 void MainWindow::slotGotProgressInfo(const QString &message, int progress) {
1415     statusProgressBar->setValue(progress);
1416     if (progress >= 0) {
1417         if (!message.isEmpty()) m_messageLabel->setMessage(message, InformationMessage);//statusLabel->setText(message);
1418         statusProgressBar->setVisible(true);
1419     } else {
1420         m_messageLabel->setMessage(QString(), DefaultMessage);
1421         statusProgressBar->setVisible(false);
1422     }
1423 }
1424
1425 void MainWindow::slotShowClipProperties(DocClipBase *clip) {
1426     if (clip->clipType() == TEXT) {
1427         QString titlepath = m_activeDocument->projectFolder().path() + "/titles/";
1428         QString path = clip->getProperty("resource");
1429         TitleWidget *dia_ui = new TitleWidget(KUrl(), titlepath, m_projectMonitor->render, this);
1430         QDomDocument doc;
1431         doc.setContent(clip->getProperty("xmldata"));
1432         dia_ui->setXml(doc);
1433         if (dia_ui->exec() == QDialog::Accepted) {
1434             QPixmap pix = dia_ui->renderedPixmap();
1435             pix.save(path);
1436             //slotAddClipFile(KUrl("/tmp/kdenlivetitle.png"), QString(), -1);
1437             //m_clipManager->slotEditTextClipFile(id, dia_ui->xml().toString());
1438             QMap <QString, QString> newprops;
1439             newprops.insert("xmldata", dia_ui->xml().toString());
1440             EditClipCommand *command = new EditClipCommand(m_projectList, clip->getId(), clip->properties(), newprops, true);
1441             m_activeDocument->commandStack()->push(command);
1442             m_clipMonitor->refreshMonitor(true);
1443             m_activeDocument->setModified(true);
1444         }
1445         delete dia_ui;
1446
1447         //m_activeDocument->editTextClip(clip->getProperty("xml"), clip->getId());
1448         return;
1449     }
1450     ClipProperties dia(clip, m_activeDocument->timecode(), m_activeDocument->fps(), this);
1451     connect(&dia, SIGNAL(addMarker(const QString &, GenTime, QString)), m_activeTimeline->projectView(), SLOT(slotAddClipMarker(const QString &, GenTime, QString)));
1452     if (dia.exec() == QDialog::Accepted) {
1453         EditClipCommand *command = new EditClipCommand(m_projectList, dia.clipId(), clip->properties(), dia.properties(), true);
1454         m_activeDocument->commandStack()->push(command);
1455
1456         //m_projectList->slotUpdateClipProperties(dia.clipId(), dia.properties());
1457         if (dia.needsTimelineRefresh()) {
1458             // update clip occurences in timeline
1459             m_activeTimeline->projectView()->slotUpdateClip(dia.clipId());
1460         }
1461     }
1462 }
1463
1464 void MainWindow::customEvent(QEvent* e) {
1465     if (e->type() == QEvent::User) {
1466         // The timeline playing position changed...
1467         kDebug() << "RECIEVED JOG EVEMNT!!!";
1468     }
1469 }
1470 void MainWindow::slotActivateEffectStackView() {
1471     effectStack->raiseWindow(effectStackDock);
1472 }
1473
1474 void MainWindow::slotActivateTransitionView() {
1475     transitionConfig->raiseWindow(transitionConfigDock);
1476 }
1477
1478 void MainWindow::slotSnapRewind() {
1479     if (m_projectMonitor->isActive()) {
1480         if (m_activeTimeline)
1481             m_activeTimeline->projectView()->slotSeekToPreviousSnap();
1482     }
1483 }
1484
1485 void MainWindow::slotSnapForward() {
1486     if (m_projectMonitor->isActive()) {
1487         if (m_activeTimeline)
1488             m_activeTimeline->projectView()->slotSeekToNextSnap();
1489     }
1490 }
1491
1492 void MainWindow::slotClipStart() {
1493     if (m_projectMonitor->isActive()) {
1494         if (m_activeTimeline)
1495             m_activeTimeline->projectView()->clipStart();
1496     }
1497 }
1498
1499 void MainWindow::slotClipEnd() {
1500     if (m_projectMonitor->isActive()) {
1501         if (m_activeTimeline)
1502             m_activeTimeline->projectView()->clipEnd();
1503     }
1504 }
1505
1506 void MainWindow::slotChangeTool(QAction * action) {
1507     if (action == m_buttonSelectTool) slotSetTool(SELECTTOOL);
1508     else if (action == m_buttonRazorTool) slotSetTool(RAZORTOOL);
1509 }
1510
1511 void MainWindow::slotSetTool(PROJECTTOOL tool) {
1512     if (m_activeDocument && m_activeTimeline) {
1513         //m_activeDocument->setTool(tool);
1514         m_activeTimeline->projectView()->setTool(tool);
1515     }
1516 }
1517
1518 void MainWindow::slotCopy() {
1519     if (!m_activeDocument || !m_activeTimeline) return;
1520     m_activeTimeline->projectView()->copyClip();
1521 }
1522
1523 void MainWindow::slotPaste() {
1524     if (!m_activeDocument || !m_activeTimeline) return;
1525     m_activeTimeline->projectView()->pasteClip();
1526 }
1527
1528 void MainWindow::slotPasteEffects() {
1529     if (!m_activeDocument || !m_activeTimeline) return;
1530     m_activeTimeline->projectView()->pasteClipEffects();
1531 }
1532
1533 void MainWindow::slotFind() {
1534     if (!m_activeDocument || !m_activeTimeline) return;
1535     m_projectSearch->setEnabled(false);
1536     m_findActivated = true;
1537     m_findString = QString();
1538     m_activeTimeline->projectView()->initSearchStrings();
1539     statusBar()->showMessage(i18n("Starting -- find text as you type"));
1540     m_findTimer.start(5000);
1541     qApp->installEventFilter(this);
1542 }
1543
1544 void MainWindow::slotFindNext() {
1545     if (m_activeTimeline && m_activeTimeline->projectView()->findNextString(m_findString)) {
1546         statusBar()->showMessage(i18n("Found : %1", m_findString));
1547     } else {
1548         statusBar()->showMessage(i18n("Reached end of project"));
1549     }
1550     m_findTimer.start(4000);
1551 }
1552
1553 void MainWindow::findAhead() {
1554     if (m_activeTimeline && m_activeTimeline->projectView()->findString(m_findString)) {
1555         m_projectSearchNext->setEnabled(true);
1556         statusBar()->showMessage(i18n("Found : %1", m_findString));
1557     } else {
1558         m_projectSearchNext->setEnabled(false);
1559         statusBar()->showMessage(i18n("Not found : %1", m_findString));
1560     }
1561 }
1562
1563 void MainWindow::findTimeout() {
1564     m_projectSearchNext->setEnabled(false);
1565     m_findActivated = false;
1566     m_findString = QString();
1567     statusBar()->showMessage(i18n("Find stopped"), 3000);
1568     if (m_activeTimeline) m_activeTimeline->projectView()->clearSearchStrings();
1569     m_projectSearch->setEnabled(true);
1570     removeEventFilter(this);
1571 }
1572
1573 void MainWindow::keyPressEvent(QKeyEvent *ke) {
1574     if (m_findActivated) {
1575         if (ke->key() == Qt::Key_Backspace) {
1576             m_findString = m_findString.left(m_findString.length() - 1);
1577
1578             if (!m_findString.isEmpty()) {
1579                 findAhead();
1580             } else {
1581                 findTimeout();
1582             }
1583
1584             m_findTimer.start(4000);
1585             ke->accept();
1586             return;
1587         } else if (ke->key() == Qt::Key_Escape) {
1588             findTimeout();
1589             ke->accept();
1590             return;
1591         } else if (ke->key() == Qt::Key_Space || !ke->text().trimmed().isEmpty()) {
1592             m_findString += ke->text();
1593
1594             findAhead();
1595
1596             m_findTimer.start(4000);
1597             ke->accept();
1598             return;
1599         }
1600     } else KXmlGuiWindow::keyPressEvent(ke);
1601 }
1602
1603 bool MainWindow::eventFilter(QObject *obj, QEvent *event) {
1604     if (m_findActivated) {
1605         if (event->type() == QEvent::ShortcutOverride) {
1606             QKeyEvent* ke = (QKeyEvent*) event;
1607             if (ke->text().trimmed().isEmpty()) return false;
1608             ke->accept();
1609             return true;
1610         } else return false;
1611     } else {
1612         // pass the event on to the parent class
1613         return QMainWindow::eventFilter(obj, event);
1614     }
1615 }
1616
1617 void MainWindow::slotSaveZone(Render *render, QPoint zone) {
1618     KDialog *dialog = new KDialog(this);
1619     dialog->setCaption("Save clip zone");
1620     dialog->setButtons(KDialog::Ok | KDialog::Cancel);
1621
1622     QWidget *widget = new QWidget(dialog);
1623     dialog->setMainWidget(widget);
1624
1625     QVBoxLayout *vbox = new QVBoxLayout(widget);
1626     QLabel *label1 = new QLabel(i18n("Save clip zone as:"), this);
1627     QString path = m_activeDocument->projectFolder().path();
1628     path.append("/");
1629     path.append("untitled.westley");
1630     KUrlRequester *url = new KUrlRequester(KUrl(path), this);
1631     url->setFilter("video/mlt-playlist");
1632     QLabel *label2 = new QLabel(i18n("Description:"), this);
1633     KLineEdit *edit = new KLineEdit(this);
1634     vbox->addWidget(label1);
1635     vbox->addWidget(url);
1636     vbox->addWidget(label2);
1637     vbox->addWidget(edit);
1638     if (dialog->exec() == QDialog::Accepted) render->saveZone(url->url(), edit->text(), zone);
1639
1640 }
1641
1642 void MainWindow::slotSetInPoint() {
1643     if (m_clipMonitor->isActive()) {
1644         m_clipMonitor->slotSetZoneStart();
1645     } else m_activeTimeline->projectView()->setInPoint();
1646 }
1647
1648 void MainWindow::slotSetOutPoint() {
1649     if (m_clipMonitor->isActive()) {
1650         m_clipMonitor->slotSetZoneEnd();
1651     } else m_activeTimeline->projectView()->setOutPoint();
1652 }
1653
1654 #include "mainwindow.moc"