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