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