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