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