]> git.sesse.net Git - kdenlive/blob - src/mainwindow.cpp
Display some progress info when opening document
[kdenlive] / src / mainwindow.cpp
1 /***************************************************************************
2  *   Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3  *                                                                         *
4  *   This program is free software; you can redistribute it and/or modify  *
5  *   it under the terms of the GNU General Public License as published by  *
6  *   the Free Software Foundation; either version 2 of the License, or     *
7  *   (at your option) any later version.                                   *
8  *                                                                         *
9  *   This program is distributed in the hope that it will be useful,       *
10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12  *   GNU General Public License for more details.                          *
13  *                                                                         *
14  *   You should have received a copy of the GNU General Public License     *
15  *   along with this program; if not, write to the                         *
16  *   Free Software Foundation, Inc.,                                       *
17  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
18  ***************************************************************************/
19
20
21
22 #include <QTextStream>
23 #include <QTimer>
24 #include <QAction>
25 #include <QtTest>
26 #include <QtCore>
27
28 #include <KApplication>
29 #include <KAction>
30 #include <KLocale>
31 #include <KGlobal>
32 #include <KActionCollection>
33 #include <KStandardAction>
34 #include <KFileDialog>
35 #include <KMessageBox>
36 #include <KDebug>
37 #include <KIO/NetAccess>
38 #include <KSaveFile>
39 #include <KRuler>
40 #include <KConfigDialog>
41 #include <KXMLGUIFactory>
42 #include <KStatusBar>
43 #include <kstandarddirs.h>
44 #include <KUrlRequesterDialog>
45 #include <KTemporaryFile>
46 #include <KActionMenu>
47 #include <KMenu>
48 #include <locale.h>
49 #include <ktogglefullscreenaction.h>
50
51 #include <mlt++/Mlt.h>
52
53 #include "mainwindow.h"
54 #include "kdenlivesettings.h"
55 #include "kdenlivesettingsdialog.h"
56 #include "initeffects.h"
57 #include "profilesdialog.h"
58 #include "projectsettings.h"
59 #include "events.h"
60 #include "renderjob.h"
61 #include "clipmanager.h"
62 #include "projectlist.h"
63 #include "monitor.h"
64 #include "recmonitor.h"
65 #include "monitormanager.h"
66 #include "kdenlivedoc.h"
67 #include "trackview.h"
68 #include "customtrackview.h"
69 #include "effectslistview.h"
70 #include "effectstackview.h"
71 #include "transitionsettings.h"
72 #include "renderwidget.h"
73 #include "renderer.h"
74 #include "jogshuttle.h"
75 #include "clipproperties.h"
76
77 #define ID_STATUS_MSG 1
78 #define ID_EDITMODE_MSG 2
79 #define ID_TIMELINE_MSG 3
80 #define ID_TIMELINE_BUTTONS 5
81 #define ID_TIMELINE_POS 6
82 #define ID_TIMELINE_FORMAT 7
83
84 EffectsList MainWindow::videoEffects;
85 EffectsList MainWindow::audioEffects;
86 EffectsList MainWindow::customEffects;
87 EffectsList MainWindow::transitions;
88
89 MainWindow::MainWindow(QWidget *parent)
90         : KXmlGuiWindow(parent),
91         m_activeDocument(NULL), m_activeTimeline(NULL), m_renderWidget(NULL), m_jogProcess(NULL) {
92     setlocale(LC_NUMERIC, "POSIX");
93     parseProfiles();
94     setFont(KGlobalSettings::toolBarFont());
95     m_commandStack = new QUndoGroup;
96     m_timelineArea = new KTabWidget(this);
97     m_timelineArea->setTabReorderingEnabled(true);
98     m_timelineArea->setTabBarHidden(true);
99
100     QToolButton *closeTabButton = new QToolButton;
101     connect(closeTabButton, SIGNAL(clicked()), this, SLOT(slotRemoveTab()));
102     closeTabButton->setIcon(KIcon("tab-close"));
103     closeTabButton->adjustSize();
104     closeTabButton->setToolTip(i18n("Close the current tab"));
105     m_timelineArea->setCornerWidget(closeTabButton);
106     connect(m_timelineArea, SIGNAL(currentChanged(int)), this, SLOT(activateDocument()));
107
108     initEffects::parseEffectFiles();
109     m_monitorManager = new MonitorManager();
110
111     projectListDock = new QDockWidget(i18n("Project Tree"), this);
112     projectListDock->setObjectName("project_tree");
113     m_projectList = new ProjectList(this);
114     projectListDock->setWidget(m_projectList);
115     addDockWidget(Qt::TopDockWidgetArea, projectListDock);
116
117     effectListDock = new QDockWidget(i18n("Effect List"), this);
118     effectListDock->setObjectName("effect_list");
119     m_effectList = new EffectsListView();
120
121     //m_effectList = new KListWidget(this);
122     effectListDock->setWidget(m_effectList);
123     addDockWidget(Qt::TopDockWidgetArea, effectListDock);
124
125     effectStackDock = new QDockWidget(i18n("Effect Stack"), this);
126     effectStackDock->setObjectName("effect_stack");
127     effectStack = new EffectStackView(this);
128     effectStackDock->setWidget(effectStack);
129     addDockWidget(Qt::TopDockWidgetArea, effectStackDock);
130
131     transitionConfigDock = new QDockWidget(i18n("Transition"), this);
132     transitionConfigDock->setObjectName("transition");
133     transitionConfig = new TransitionSettings(this);
134     transitionConfigDock->setWidget(transitionConfig);
135     addDockWidget(Qt::TopDockWidgetArea, transitionConfigDock);
136
137
138     clipMonitorDock = new QDockWidget(i18n("Clip Monitor"), this);
139     clipMonitorDock->setObjectName("clip_monitor");
140     m_clipMonitor = new Monitor("clip", m_monitorManager, this);
141     clipMonitorDock->setWidget(m_clipMonitor);
142     addDockWidget(Qt::TopDockWidgetArea, clipMonitorDock);
143     //m_clipMonitor->stop();
144
145     projectMonitorDock = new QDockWidget(i18n("Project Monitor"), this);
146     projectMonitorDock->setObjectName("project_monitor");
147     m_projectMonitor = new Monitor("project", m_monitorManager, this);
148     projectMonitorDock->setWidget(m_projectMonitor);
149     addDockWidget(Qt::TopDockWidgetArea, projectMonitorDock);
150
151     recMonitorDock = new QDockWidget(i18n("Record Monitor"), this);
152     recMonitorDock->setObjectName("record_monitor");
153     m_recMonitor = new RecMonitor("record", this);
154     recMonitorDock->setWidget(m_recMonitor);
155     addDockWidget(Qt::TopDockWidgetArea, recMonitorDock);
156
157     connect(m_recMonitor, SIGNAL(addProjectClip(KUrl)), this, SLOT(slotAddProjectClip(KUrl)));
158
159     undoViewDock = new QDockWidget(i18n("Undo History"), this);
160     undoViewDock->setObjectName("undo_history");
161     m_undoView = new QUndoView(this);
162     m_undoView->setCleanIcon(KIcon("edit-clear"));
163     m_undoView->setEmptyLabel(i18n("Clean"));
164     undoViewDock->setWidget(m_undoView);
165     m_undoView->setGroup(m_commandStack);
166     addDockWidget(Qt::TopDockWidgetArea, undoViewDock);
167
168     overviewDock = new QDockWidget(i18n("Project Overview"), this);
169     overviewDock->setObjectName("project_overview");
170     //m_overView = new CustomTrackView(NULL, NULL, this);
171     //overviewDock->setWidget(m_overView);
172     addDockWidget(Qt::TopDockWidgetArea, overviewDock);
173
174     setupActions();
175     tabifyDockWidget(projectListDock, effectListDock);
176     tabifyDockWidget(projectListDock, effectStackDock);
177     tabifyDockWidget(projectListDock, transitionConfigDock);
178     tabifyDockWidget(projectListDock, undoViewDock);
179     projectListDock->raise();
180
181     tabifyDockWidget(clipMonitorDock, projectMonitorDock);
182     setCentralWidget(m_timelineArea);
183
184     setupGUI(Default, NULL /*"kdenliveui.rc"*/);
185     kDebug() << factory() << " " << factory()->container("video_effects_menu", this);
186
187     // build effects menus
188     QAction *action;
189     QMenu *videoEffectsMenu = (QMenu*)(factory()->container("video_effects_menu", this));
190     QStringList effects = videoEffects.effectNames();
191     foreach(const QString &name, effects) {
192         action = new QAction(name, this);
193         action->setData(name);
194         videoEffectsMenu->addAction(action);
195     }
196     QMenu *audioEffectsMenu = (QMenu*)(factory()->container("audio_effects_menu", this));
197     effects = audioEffects.effectNames();
198     foreach(const QString &name, effects) {
199         action = new QAction(name, this);
200         action->setData(name);
201         audioEffectsMenu->addAction(action);
202     }
203     QMenu *customEffectsMenu = (QMenu*)(factory()->container("custom_effects_menu", this));
204     effects = customEffects.effectNames();
205     foreach(const QString &name, effects) {
206         action = new QAction(name, this);
207         action->setData(name);
208         customEffectsMenu->addAction(action);
209     }
210
211     connect(videoEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddVideoEffect(QAction *)));
212     connect(audioEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddAudioEffect(QAction *)));
213     connect(customEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddCustomEffect(QAction *)));
214
215     m_timelineContextMenu = new QMenu(this);
216     m_timelineContextClipMenu = new QMenu(this);
217     m_timelineContextTransitionMenu = new QMenu(this);
218
219     action = actionCollection()->action("delete_timeline_clip");
220     m_timelineContextClipMenu->addAction(action);
221     action = actionCollection()->action("add_clip_marker");
222     m_timelineContextClipMenu->addAction(action);
223     m_timelineContextClipMenu->addMenu(videoEffectsMenu);
224     m_timelineContextClipMenu->addMenu(audioEffectsMenu);
225     m_timelineContextClipMenu->addMenu(customEffectsMenu);
226
227     m_timelineContextTransitionMenu->addAction(action);
228
229     connect(projectMonitorDock, SIGNAL(visibilityChanged(bool)), m_projectMonitor, SLOT(refreshMonitor(bool)));
230     connect(clipMonitorDock, SIGNAL(visibilityChanged(bool)), m_clipMonitor, SLOT(refreshMonitor(bool)));
231     //connect(m_monitorManager, SIGNAL(connectMonitors()), this, SLOT(slotConnectMonitors()));
232     connect(m_monitorManager, SIGNAL(raiseClipMonitor(bool)), this, SLOT(slotRaiseMonitor(bool)));
233     connect(m_effectList, SIGNAL(addEffect(QDomElement)), this, SLOT(slotAddEffect(QDomElement)));
234     m_monitorManager->initMonitors(m_clipMonitor, m_projectMonitor);
235     slotConnectMonitors();
236
237     setAutoSaveSettings();
238     newFile();
239
240     activateShuttleDevice();
241 }
242
243 void MainWindow::queryQuit() {
244     kDebug() << "----- SAVING CONFUIG";
245     if (queryClose()) kapp->quit();
246 }
247
248 //virtual
249 bool MainWindow::queryClose() {
250     saveOptions();
251     if (m_activeDocument && m_activeDocument->isModified()) {
252         switch (KMessageBox::warningYesNoCancel(this, i18n("Save changes to document ?"))) {
253         case KMessageBox::Yes :
254             // save document here. If saving fails, return false;
255             return true;
256         case KMessageBox::No :
257             return true;
258         default: // cancel
259             return false;
260         }
261     }
262     return true;
263 }
264
265 void MainWindow::activateShuttleDevice() {
266     if (m_jogProcess) delete m_jogProcess;
267     m_jogProcess = NULL;
268     if (KdenliveSettings::enableshuttle() == false) return;
269     m_jogProcess = new JogShuttle(KdenliveSettings::shuttledevice());
270     connect(m_jogProcess, SIGNAL(rewind1()), m_monitorManager, SLOT(slotRewindOneFrame()));
271     connect(m_jogProcess, SIGNAL(forward1()), m_monitorManager, SLOT(slotForwardOneFrame()));
272     connect(m_jogProcess, SIGNAL(rewind(double)), m_monitorManager, SLOT(slotRewind(double)));
273     connect(m_jogProcess, SIGNAL(forward(double)), m_monitorManager, SLOT(slotForward(double)));
274     connect(m_jogProcess, SIGNAL(stop()), m_monitorManager, SLOT(slotPlay()));
275     connect(m_jogProcess, SIGNAL(button(int)), this, SLOT(slotShuttleButton(int)));
276 }
277
278 void MainWindow::slotShuttleButton(int code) {
279     switch (code) {
280     case 5:
281         slotShuttleAction(KdenliveSettings::shuttle1());
282         break;
283     case 6:
284         slotShuttleAction(KdenliveSettings::shuttle2());
285         break;
286     case 7:
287         slotShuttleAction(KdenliveSettings::shuttle3());
288         break;
289     case 8:
290         slotShuttleAction(KdenliveSettings::shuttle4());
291         break;
292     case 9:
293         slotShuttleAction(KdenliveSettings::shuttle5());
294         break;
295     }
296 }
297
298 void MainWindow::slotShuttleAction(int code) {
299     switch (code) {
300     case 0:
301         return;
302     case 1:
303         m_monitorManager->slotPlay();
304         break;
305     default:
306         m_monitorManager->slotPlay();
307         break;
308     }
309 }
310
311 void MainWindow::slotFullScreen() {
312     //KToggleFullScreenAction::setFullScreen(this, actionCollection()->action("fullscreen")->isChecked());
313 }
314
315 void MainWindow::slotAddEffect(QDomElement effect, GenTime pos, int track) {
316     if (!m_activeDocument) return;
317     if (effect.isNull()) {
318         kDebug() << "--- ERROR, TRYING TO APPEND NULL EFFECT";
319         return;
320     }
321     TrackView *currentTimeLine = (TrackView *) m_timelineArea->currentWidget();
322     currentTimeLine->projectView()->slotAddEffect(effect, pos, track);
323 }
324
325 void MainWindow::slotRaiseMonitor(bool clipMonitor) {
326     if (clipMonitor) clipMonitorDock->raise();
327     else projectMonitorDock->raise();
328 }
329
330 void MainWindow::slotSetClipDuration(int id, int duration) {
331     if (!m_activeDocument) return;
332     m_activeDocument->setProducerDuration(id, duration);
333 }
334
335 void MainWindow::slotConnectMonitors() {
336
337     m_projectList->setRenderer(m_clipMonitor->render);
338     connect(m_projectList, SIGNAL(clipSelected(const QDomElement &)), m_clipMonitor, SLOT(slotSetXml(const QDomElement &)));
339     connect(m_projectList, SIGNAL(receivedClipDuration(int, int)), this, SLOT(slotSetClipDuration(int, int)));
340     connect(m_projectList, SIGNAL(showClipProperties(DocClipBase *)), this, SLOT(slotShowClipProperties(DocClipBase *)));
341     connect(m_projectList, SIGNAL(getFileProperties(const QDomElement &, int)), m_clipMonitor->render, SLOT(getFileProperties(const QDomElement &, int)));
342     connect(m_clipMonitor->render, SIGNAL(replyGetImage(int, int, const QPixmap &, int, int)), m_projectList, SLOT(slotReplyGetImage(int, int, const QPixmap &, int, int)));
343     connect(m_clipMonitor->render, SIGNAL(replyGetFileProperties(int, const QMap < QString, QString > &, const QMap < QString, QString > &)), m_projectList, SLOT(slotReplyGetFileProperties(int, const QMap < QString, QString > &, const QMap < QString, QString > &)));
344 }
345
346 void MainWindow::setupActions() {
347
348     m_timecodeFormat = new KComboBox(this);
349     m_timecodeFormat->addItem(i18n("hh:mm:ss::ff"));
350     m_timecodeFormat->addItem(i18n("Frames"));
351
352     statusProgressBar = new QProgressBar(this);
353     statusProgressBar->setMinimum(0);
354     statusProgressBar->setMaximum(100);
355     statusProgressBar->setMaximumWidth(150);
356     statusProgressBar->setVisible(false);
357     statusLabel = new QLabel(this);
358
359     QWidget *w = new QWidget;
360
361     QHBoxLayout *layout = new QHBoxLayout;
362     w->setLayout(layout);
363     layout->setContentsMargins(5, 0, 5, 0);
364     QToolBar *toolbar = new QToolBar("statusToolBar", this);
365
366
367     m_toolGroup = new QActionGroup(this);
368
369     QString style1 = "QToolButton { background-color: rgba(230, 230, 230, 20); border-style: inset; border:1px solid #666666;border-radius: 3px;margin: 0px 3px} QToolButton:checked { background-color: rgba(224, 0, 0, 100); border-style: inset; border:1px solid #666666;border-radius: 3px;}";
370
371     m_buttonSelectTool = toolbar->addAction(KIcon("kdenlive-select-tool"), i18n("Selection tool"));
372     m_buttonSelectTool->setCheckable(true);
373     m_buttonSelectTool->setChecked(true);
374
375     m_buttonRazorTool = toolbar->addAction(KIcon("edit-cut"), i18n("Razor tool"));
376     m_buttonRazorTool->setCheckable(true);
377     m_buttonRazorTool->setChecked(false);
378
379     m_toolGroup->addAction(m_buttonSelectTool);
380     m_toolGroup->addAction(m_buttonRazorTool);
381     m_toolGroup->setExclusive(true);
382     toolbar->setStyleSheet(style1);
383     connect(m_toolGroup, SIGNAL(triggered(QAction *)), this, SLOT(slotChangeTool(QAction *)));
384
385     toolbar->addSeparator();
386     m_buttonFitZoom = toolbar->addAction(KIcon("zoom-fit-best"), i18n("Fit zoom to project"));
387     m_buttonFitZoom->setCheckable(false);
388     connect(m_buttonFitZoom, SIGNAL(triggered()), this, SLOT(slotFitZoom()));
389
390     m_zoomSlider = new QSlider(Qt::Horizontal, this);
391     m_zoomSlider->setMaximum(13);
392
393     m_zoomSlider->setMaximumWidth(150);
394     m_zoomSlider->setMinimumWidth(100);
395
396     const int contentHeight = QFontMetrics(w->font()).height() + 3;
397     QString style = "QSlider::groove:horizontal { border: 1px solid #999999;height: 8px }";
398     style.append("QSlider::handle:horizontal {  background-color: white; border: 1px solid #999999;width: 8px;margin: -2px 0;border-radius: 3px; }");
399     m_zoomSlider->setStyleSheet(style);
400
401     //m_zoomSlider->setMaximumHeight(contentHeight);
402     //m_zoomSlider->height() + 5;
403     statusBar()->setMinimumHeight(contentHeight + 5);
404
405
406     toolbar->addWidget(m_zoomSlider);
407
408     m_buttonVideoThumbs = toolbar->addAction(KIcon("video-mpeg"), i18n("Show videoo thumbnails"));
409     m_buttonVideoThumbs->setCheckable(true);
410     m_buttonVideoThumbs->setChecked(KdenliveSettings::audiothumbnails());
411     connect(m_buttonVideoThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchVideoThumbs()));
412
413     m_buttonAudioThumbs = toolbar->addAction(KIcon("audio-mpeg"), i18n("Show audio thumbnails"));
414     m_buttonAudioThumbs->setCheckable(true);
415     m_buttonAudioThumbs->setChecked(KdenliveSettings::videothumbnails());
416     connect(m_buttonAudioThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchAudioThumbs()));
417
418     m_buttonShowMarkers = toolbar->addAction(KIcon("audio-mpeg"), i18n("Show markers comments"));
419     m_buttonShowMarkers->setCheckable(true);
420     m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
421     connect(m_buttonShowMarkers, SIGNAL(triggered()), this, SLOT(slotSwitchMarkersComments()));
422     layout->addWidget(toolbar);
423
424     statusBar()->insertPermanentWidget(0, statusProgressBar, 1);
425     statusBar()->insertPermanentWidget(1, statusLabel, 1);
426     statusBar()->insertPermanentWidget(ID_TIMELINE_BUTTONS, w);
427     statusBar()->insertPermanentFixedItem("00:00:00:00", ID_TIMELINE_POS);
428     statusBar()->insertPermanentWidget(ID_TIMELINE_FORMAT, m_timecodeFormat);
429     statusBar()->setMaximumHeight(statusBar()->font().pointSize() * 4);
430
431     actionCollection()->addAction("select_tool", m_buttonSelectTool);
432     actionCollection()->addAction("razor_tool", m_buttonRazorTool);
433
434     KAction* clearAction = new KAction(KIcon("document-new"), i18n("Clear"), this);
435     clearAction->setShortcut(Qt::CTRL + Qt::Key_W);
436     actionCollection()->addAction("clear", clearAction);
437     /*connect(clearAction, SIGNAL(triggered(bool)),
438             textArea, SLOT(clear()));*/
439
440     KAction* profilesAction = new KAction(KIcon("document-new"), i18n("Manage Profiles"), this);
441     actionCollection()->addAction("manage_profiles", profilesAction);
442     connect(profilesAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProfiles()));
443
444     KAction* projectAction = new KAction(KIcon("document-new"), i18n("Project Settings"), this);
445     actionCollection()->addAction("project_settings", projectAction);
446     connect(projectAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProjectSettings()));
447
448     KAction* projectRender = new KAction(KIcon("document-new"), i18n("Render Project"), this);
449     actionCollection()->addAction("project_render", projectRender);
450     connect(projectRender, SIGNAL(triggered(bool)), this, SLOT(slotRenderProject()));
451
452     KAction* monitorPlay = new KAction(KIcon("media-playback-start"), i18n("Play"), this);
453     monitorPlay->setShortcut(Qt::Key_Space);
454     actionCollection()->addAction("monitor_play", monitorPlay);
455     connect(monitorPlay, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotPlay()));
456
457     KAction* monitorSeekBackward = new KAction(KIcon("media-seek-backward"), i18n("Rewind"), this);
458     monitorSeekBackward->setShortcut(Qt::Key_J);
459     actionCollection()->addAction("monitor_seek_backward", monitorSeekBackward);
460     connect(monitorSeekBackward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewind()));
461
462     KAction* monitorSeekBackwardOneFrame = new KAction(KIcon("media-skip-backward"), i18n("Rewind 1 Frame"), this);
463     monitorSeekBackwardOneFrame->setShortcut(Qt::Key_Left);
464     actionCollection()->addAction("monitor_seek_backward-one-frame", monitorSeekBackwardOneFrame);
465     connect(monitorSeekBackwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewindOneFrame()));
466
467     KAction* monitorSeekSnapBackward = new KAction(KIcon("media-seek-backward"), i18n("Go to Previous Snap Point"), this);
468     monitorSeekSnapBackward->setShortcut(Qt::ALT + Qt::Key_Left);
469     actionCollection()->addAction("monitor_seek_snap_backward", monitorSeekSnapBackward);
470     connect(monitorSeekSnapBackward, SIGNAL(triggered(bool)), this, SLOT(slotSnapRewind()));
471
472     KAction* monitorSeekForward = new KAction(KIcon("media-seek-forward"), i18n("Forward"), this);
473     monitorSeekForward->setShortcut(Qt::Key_L);
474     actionCollection()->addAction("monitor_seek_forward", monitorSeekForward);
475     connect(monitorSeekForward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForward()));
476
477     KAction* monitorSeekForwardOneFrame = new KAction(KIcon("media-skip-forward"), i18n("Forward 1 Frame"), this);
478     monitorSeekForwardOneFrame->setShortcut(Qt::Key_Right);
479     actionCollection()->addAction("monitor_seek_forward-one-frame", monitorSeekForwardOneFrame);
480     connect(monitorSeekForwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForwardOneFrame()));
481
482     KAction* monitorSeekSnapForward = new KAction(KIcon("media-seek-forward"), i18n("Go to Next Snap Point"), this);
483     monitorSeekSnapForward->setShortcut(Qt::ALT + Qt::Key_Right);
484     actionCollection()->addAction("monitor_seek_snap_forward", monitorSeekSnapForward);
485     connect(monitorSeekSnapForward, SIGNAL(triggered(bool)), this, SLOT(slotSnapForward()));
486
487     KAction* deleteTimelineClip = new KAction(KIcon("edit-delete"), i18n("Delete Selected Item"), this);
488     deleteTimelineClip->setShortcut(Qt::Key_Delete);
489     actionCollection()->addAction("delete_timeline_clip", deleteTimelineClip);
490     connect(deleteTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotDeleteTimelineClip()));
491
492     KAction* cutTimelineClip = new KAction(KIcon("edit-cut"), i18n("Cut Clip"), this);
493     cutTimelineClip->setShortcut(Qt::SHIFT + Qt::Key_R);
494     actionCollection()->addAction("cut_timeline_clip", cutTimelineClip);
495     connect(cutTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotCutTimelineClip()));
496
497     KAction* addClipMarker = new KAction(KIcon("edit-delete"), i18n("Add Marker to Clip"), this);
498     actionCollection()->addAction("add_clip_marker", addClipMarker);
499     connect(addClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotAddClipMarker()));
500
501     KStandardAction::quit(this, SLOT(queryQuit()),
502                           actionCollection());
503
504     KStandardAction::open(this, SLOT(openFile()),
505                           actionCollection());
506
507     m_fileOpenRecent = KStandardAction::openRecent(this, SLOT(openFile(const KUrl &)),
508                        actionCollection());
509
510     KStandardAction::save(this, SLOT(saveFile()),
511                           actionCollection());
512
513     KStandardAction::saveAs(this, SLOT(saveFileAs()),
514                             actionCollection());
515
516     KStandardAction::openNew(this, SLOT(newFile()),
517                              actionCollection());
518
519     KStandardAction::preferences(this, SLOT(slotPreferences()),
520                                  actionCollection());
521
522     KStandardAction::undo(this, SLOT(undo()),
523                           actionCollection());
524
525     KStandardAction::redo(this, SLOT(redo()),
526                           actionCollection());
527
528     KStandardAction::fullScreen(this, SLOT(slotFullScreen()), this, actionCollection());
529
530     connect(actionCollection(), SIGNAL(actionHovered(QAction*)),
531             this, SLOT(slotDisplayActionMessage(QAction*)));
532     //connect(actionCollection(), SIGNAL( clearStatusText() ),
533     //statusBar(), SLOT( clear() ) );
534
535     readOptions();
536 }
537
538 void MainWindow::undo() {
539     m_commandStack->undo();
540 }
541
542 void MainWindow::redo() {
543     m_commandStack->redo();
544 }
545
546 void MainWindow::slotDisplayActionMessage(QAction *a) {
547     statusBar()->showMessage(a->data().toString(), 3000);
548 }
549
550 void MainWindow::saveOptions() {
551     KdenliveSettings::self()->writeConfig();
552     KSharedConfigPtr config = KGlobal::config();
553     m_fileOpenRecent->saveEntries(KConfigGroup(config, "Recent Files"));
554     config->sync();
555 }
556
557 void MainWindow::readOptions() {
558     KSharedConfigPtr config = KGlobal::config();
559     m_fileOpenRecent->loadEntries(KConfigGroup(config, "Recent Files"));
560 }
561
562 void MainWindow::newFile() {
563     QString profileName;
564     KUrl projectFolder;
565     if (m_timelineArea->count() == 0) profileName = KdenliveSettings::default_profile();
566     else {
567         ProjectSettings *w = new ProjectSettings;
568         if (w->exec() != QDialog::Accepted) return;
569         profileName = w->selectedProfile();
570         projectFolder = w->selectedFolder();
571         delete w;
572     }
573     MltVideoProfile prof = ProfilesDialog::getVideoProfile(profileName);
574     if (prof.width == 0) prof = ProfilesDialog::getVideoProfile("dv_pal");
575     KdenliveDoc *doc = new KdenliveDoc(KUrl(), projectFolder, prof, m_commandStack, this);
576     TrackView *trackView = new TrackView(doc, this);
577     m_timelineArea->addTab(trackView, KIcon("kdenlive"), i18n("Untitled") + " / " + prof.description);
578     if (m_timelineArea->count() == 1) {
579                 connectDocumentInfo(doc);
580         connectDocument(trackView, doc);
581         }
582     else m_timelineArea->setTabBarHidden(false);
583 }
584
585 void MainWindow::activateDocument() {
586     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
587     KdenliveDoc *currentDoc = currentTab->document();
588         connectDocumentInfo(currentDoc);
589     connectDocument(currentTab, currentDoc);
590 }
591
592 void MainWindow::slotRemoveTab() {
593     QWidget *w = m_timelineArea->currentWidget();
594     // closing current document
595     int ix = m_timelineArea->currentIndex() + 1;
596     if (ix == m_timelineArea->count()) ix = 0;
597     m_timelineArea->setCurrentIndex(ix);
598     TrackView *tabToClose = (TrackView *) w;
599     KdenliveDoc *docToClose = tabToClose->document();
600     m_timelineArea->removeTab(m_timelineArea->indexOf(w));
601     if (m_timelineArea->count() == 1) m_timelineArea->setTabBarHidden(true);
602     delete docToClose;
603     delete w;
604 }
605
606 void MainWindow::saveFileAs(const QString &outputFileName) {
607     m_projectMonitor->saveSceneList(outputFileName, m_activeDocument->documentInfoXml());
608     m_activeDocument->setUrl(KUrl(outputFileName));
609     setCaption(m_activeDocument->description());
610     m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
611     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), m_activeDocument->url().path());
612     m_activeDocument->setModified(false);
613 }
614
615 void MainWindow::saveFileAs() {
616     QString outputFile = KFileDialog::getSaveFileName();
617     if (QFile::exists(outputFile)) {
618         if (KMessageBox::questionYesNo(this, i18n("File already exists.\nDo you want to overwrite it ?")) == KMessageBox::No) return;
619     }
620     saveFileAs(outputFile);
621 }
622
623 void MainWindow::saveFile() {
624     if (!m_activeDocument) return;
625     if (m_activeDocument->url().isEmpty()) {
626         saveFileAs();
627     } else {
628         saveFileAs(m_activeDocument->url().path());
629     }
630 }
631
632 void MainWindow::openFile() { //changed
633     KUrl url = KFileDialog::getOpenUrl(KUrl(), "*.kdenlive|Kdenlive project files (*.kdenlive)\n*.westley|MLT project files (*.westley)");
634     if (url.isEmpty()) return;
635     m_fileOpenRecent->addUrl(url);
636     openFile(url);
637 }
638
639 void MainWindow::openFile(const KUrl &url) { //new
640     //TODO: get video profile from url before opening it
641     MltVideoProfile prof = ProfilesDialog::getVideoProfile(KdenliveSettings::default_profile());
642     if (prof.width == 0) prof = ProfilesDialog::getVideoProfile("dv_pal");
643     KdenliveDoc *doc = new KdenliveDoc(url, KUrl(), prof, m_commandStack, this);
644         connectDocumentInfo(doc);
645     TrackView *trackView = new TrackView(doc, this);
646     m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description()));
647     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), doc->url().path());
648     if (m_timelineArea->count() > 1) m_timelineArea->setTabBarHidden(false);
649         slotGotProgressInfo(QString(), -1);
650     //connectDocument(trackView, doc);
651 }
652
653
654 void MainWindow::parseProfiles() {
655     //kdDebug()<<" + + YOUR MLT INSTALL WAS FOUND IN: "<< MLT_PREFIX <<endl;
656
657     //KdenliveSettings::setDefaulttmpfolder();
658     if (KdenliveSettings::mltpath().isEmpty()) {
659         KdenliveSettings::setMltpath(QString(MLT_PREFIX) + QString("/share/mlt/profiles/"));
660     }
661     if (KdenliveSettings::rendererpath().isEmpty()) {
662         KdenliveSettings::setRendererpath(KStandardDirs::findExe("inigo"));
663     }
664     QStringList profilesFilter;
665     profilesFilter << "*";
666     QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
667
668     if (profilesList.isEmpty()) {
669         // Cannot find MLT path, try finding inigo
670         QString profilePath = KdenliveSettings::rendererpath();
671         if (!profilePath.isEmpty()) {
672             profilePath = profilePath.section('/', 0, -3);
673             KdenliveSettings::setMltpath(profilePath + "/share/mlt/profiles/");
674             QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
675         }
676
677         if (profilesList.isEmpty()) {
678             // Cannot find the MLT profiles, ask for location
679             KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find your Mlt profiles, please give the path"), this);
680             getUrl->fileDialog()->setMode(KFile::Directory);
681             getUrl->exec();
682             KUrl mltPath = getUrl->selectedUrl();
683             delete getUrl;
684             if (mltPath.isEmpty()) exit(1);
685             KdenliveSettings::setMltpath(mltPath.path());
686             QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
687         }
688     }
689
690     if (KdenliveSettings::rendererpath().isEmpty()) {
691         // Cannot find the MLT inigo renderer, ask for location
692         KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find the inigo program required for rendering (part of Mlt)"), this);
693         getUrl->exec();
694         KUrl rendererPath = getUrl->selectedUrl();
695         delete getUrl;
696         if (rendererPath.isEmpty()) exit(1);
697         KdenliveSettings::setRendererpath(rendererPath.path());
698     }
699
700     kDebug() << "RESULTING MLT PATH: " << KdenliveSettings::mltpath();
701
702     // Parse MLT profiles to build a list of available video formats
703     if (profilesList.isEmpty()) parseProfiles();
704 }
705
706
707 void MainWindow::slotEditProfiles() {
708     ProfilesDialog *w = new ProfilesDialog;
709     w->exec();
710     delete w;
711 }
712
713 void MainWindow::slotEditProjectSettings() {
714     ProjectSettings *w = new ProjectSettings;
715     if (w->exec() == QDialog::Accepted) {
716         QString profile = w->selectedProfile();
717         m_activeDocument->setProfilePath(profile);
718         m_monitorManager->resetProfiles(profile);
719         setCaption(m_activeDocument->description());
720         KdenliveSettings::setCurrent_profile(m_activeDocument->profilePath());
721         if (m_renderWidget) m_renderWidget->setDocumentStandard(m_activeDocument->getDocumentStandard());
722         m_monitorManager->setTimecode(m_activeDocument->timecode());
723         m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
724
725         // We need to desactivate & reactivate monitors to get a refresh
726         m_monitorManager->switchMonitors();
727     }
728     delete w;
729 }
730
731 void MainWindow::slotRenderProject() {
732     if (!m_renderWidget) {
733         m_renderWidget = new RenderWidget(this);
734         connect(m_renderWidget, SIGNAL(doRender(const QString&, const QString&, const QStringList &, bool, bool)), this, SLOT(slotDoRender(const QString&, const QString&, const QStringList &, bool, bool)));
735     }
736     /*TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
737     if (currentTab) m_renderWidget->setTimeline(currentTab);
738     m_renderWidget->setDocument(m_activeDocument);*/
739     m_renderWidget->show();
740 }
741
742 void MainWindow::slotDoRender(const QString &dest, const QString &render, const QStringList &avformat_args, bool zoneOnly, bool playAfter) {
743     if (dest.isEmpty()) return;
744     int in;
745     int out;
746     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
747     if (currentTab && zoneOnly) {
748         in = currentTab->inPoint();
749         out = currentTab->outPoint();
750     }
751     KTemporaryFile temp;
752     temp.setAutoRemove(false);
753     temp.setSuffix(".westley");
754     if (temp.open()) {
755         m_projectMonitor->saveSceneList(temp.fileName());
756         QStringList args;
757         args << "-erase";
758         if (zoneOnly) args << "in=" + QString::number(in) << "out=" + QString::number(out);
759         QString videoPlayer = "-";
760         if (playAfter) videoPlayer = "kmplayer";
761         args << "inigo" << m_activeDocument->profilePath() << render << videoPlayer << temp.fileName() << dest << avformat_args;
762         QProcess::startDetached("kdenlive_render", args);
763     }
764 }
765
766 void MainWindow::slotUpdateMousePosition(int pos) {
767     if (m_activeDocument)
768         switch (m_timecodeFormat->currentIndex()) {
769         case 0:
770             statusBar()->changeItem(m_activeDocument->timecode().getTimecodeFromFrames(pos), ID_TIMELINE_POS);
771             break;
772         default:
773             statusBar()->changeItem(QString::number(pos), ID_TIMELINE_POS);
774         }
775 }
776
777 void MainWindow::slotUpdateDocumentState(bool modified) {
778     setCaption(m_activeDocument->description(), modified);
779     if (modified) {
780         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Link));
781         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("document-save"));
782     } else {
783         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Text));
784         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("kdenlive"));
785     }
786 }
787
788 void MainWindow::connectDocumentInfo(KdenliveDoc *doc) {
789     if (m_activeDocument) {
790         if (m_activeDocument == doc) return;
791         disconnect(m_activeDocument, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
792         }
793         connect(doc, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
794 }
795
796 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //changed
797     //m_projectMonitor->stop();
798     kDebug() << "///////////////////   CONNECTING DOC TO PROJECT VIEW ////////////////";
799     if (m_activeDocument) {
800         if (m_activeDocument == doc) return;
801         m_activeDocument->backupMltPlaylist();
802         if (m_activeTimeline) {
803             disconnect(m_projectMonitor, SIGNAL(renderPosition(int)), m_activeTimeline, SLOT(moveCursorPos(int)));
804             disconnect(m_projectMonitor, SIGNAL(durationChanged(int)), m_activeTimeline, SLOT(setDuration(int)));
805             disconnect(m_activeDocument, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
806             disconnect(m_activeDocument, SIGNAL(addProjectFolder(const QString, int, bool, bool)), m_projectList, SLOT(slotAddFolder(const QString, int, bool, bool)));
807             disconnect(m_activeDocument, SIGNAL(signalDeleteProjectClip(int)), m_projectList, SLOT(slotDeleteClip(int)));
808             disconnect(m_activeDocument, SIGNAL(updateClipDisplay(int)), m_projectList, SLOT(slotUpdateClip(int)));
809             disconnect(m_activeDocument, SIGNAL(refreshClipThumbnail(int)), m_projectList, SLOT(slotRefreshClipThumbnail(int)));
810             disconnect(m_activeDocument, SIGNAL(deletTimelineClip(int)), m_activeTimeline, SLOT(slotDeleteClip(int)));
811             disconnect(m_activeTimeline, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*)));
812             disconnect(trackView, SIGNAL(clipItemSelected(ClipItem*)), this, SLOT(slotActivateEffectStackView()));
813             disconnect(m_activeTimeline, SIGNAL(transitionItemSelected(Transition*)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*)));
814             disconnect(trackView, SIGNAL(transitionItemSelected(Transition*)), this, SLOT(slotActivateTransitionView()));
815             disconnect(m_zoomSlider, SIGNAL(valueChanged(int)), m_activeTimeline, SLOT(slotChangeZoom(int)));
816             disconnect(m_activeDocument, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
817             disconnect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement)), m_activeTimeline->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement)));
818             disconnect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), m_activeTimeline->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
819             disconnect(effectStack, SIGNAL(changeEffectState(ClipItem*, QDomElement, bool)), m_activeTimeline->projectView(), SLOT(slotChangeEffectState(ClipItem*, QDomElement, bool)));
820             disconnect(effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), trackView->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
821             disconnect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), m_activeTimeline->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
822             disconnect(transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
823             disconnect(m_activeTimeline->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
824         }
825         m_activeDocument->setRenderer(NULL);
826         disconnect(m_projectList, SIGNAL(clipSelected(const QDomElement &)), m_clipMonitor, SLOT(slotSetXml(const QDomElement &)));
827         m_clipMonitor->stop();
828     }
829     m_monitorManager->resetProfiles(doc->profilePath());
830     m_projectList->setDocument(doc);
831     connect(m_projectList, SIGNAL(clipSelected(const QDomElement &)), m_clipMonitor, SLOT(slotSetXml(const QDomElement &)));
832     connect(trackView, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
833     connect(trackView, SIGNAL(mousePosition(int)), this, SLOT(slotUpdateMousePosition(int)));
834     connect(m_projectMonitor, SIGNAL(renderPosition(int)), trackView, SLOT(moveCursorPos(int)));
835     connect(m_projectMonitor, SIGNAL(durationChanged(int)), trackView, SLOT(setDuration(int)));
836     connect(doc, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
837     connect(doc, SIGNAL(addProjectFolder(const QString, int, bool, bool)), m_projectList, SLOT(slotAddFolder(const QString, int, bool, bool)));
838     connect(doc, SIGNAL(signalDeleteProjectClip(int)), m_projectList, SLOT(slotDeleteClip(int)));
839     connect(doc, SIGNAL(updateClipDisplay(int)), m_projectList, SLOT(slotUpdateClip(int)));
840     connect(doc, SIGNAL(refreshClipThumbnail(int)), m_projectList, SLOT(slotRefreshClipThumbnail(int)));
841
842     connect(doc, SIGNAL(deletTimelineClip(int)), trackView, SLOT(slotDeleteClip(int)));
843     connect(doc, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
844
845
846
847     connect(trackView, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*)));
848     connect(trackView, SIGNAL(clipItemSelected(ClipItem*)), this, SLOT(slotActivateEffectStackView()));
849     connect(trackView, SIGNAL(transitionItemSelected(Transition*)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*)));
850     connect(trackView, SIGNAL(transitionItemSelected(Transition*)), this, SLOT(slotActivateTransitionView()));
851     m_zoomSlider->setValue(trackView->currentZoom());
852     connect(m_zoomSlider, SIGNAL(valueChanged(int)), trackView, SLOT(slotChangeZoom(int)));
853     connect(trackView->projectView(), SIGNAL(zoomIn()), this, SLOT(slotZoomIn()));
854     connect(trackView->projectView(), SIGNAL(zoomOut()), this, SLOT(slotZoomOut()));
855     connect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement)), trackView->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement)));
856     connect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), trackView->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
857     connect(effectStack, SIGNAL(changeEffectState(ClipItem*, QDomElement, bool)), trackView->projectView(), SLOT(slotChangeEffectState(ClipItem*, QDomElement, bool)));
858     connect(effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), trackView->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
859     connect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), trackView->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
860     connect(transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
861     connect(trackView->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
862     trackView->projectView()->setContextMenu(m_timelineContextMenu, m_timelineContextClipMenu, m_timelineContextTransitionMenu);
863     m_activeTimeline = trackView;
864     KdenliveSettings::setCurrent_profile(doc->profilePath());
865     if (m_renderWidget) m_renderWidget->setDocumentStandard(doc->getDocumentStandard());
866     m_monitorManager->setTimecode(doc->timecode());
867     doc->setRenderer(m_projectMonitor->render);
868     m_commandStack->setActiveStack(doc->commandStack());
869     if (m_commandStack->isClean()) kDebug() << "////////////  UNDO STACK IS CLEAN";
870     else  kDebug() << "////////////  UNDO STACK IS NOT CLEAN*******************";
871
872     //m_overView->setScene(trackView->projectScene());
873     //m_overView->scale(m_overView->width() / trackView->duration(), m_overView->height() / (50 * trackView->tracksNumber()));
874     //m_overView->fitInView(m_overView->itemAt(0, 50), Qt::KeepAspectRatio);
875
876     setCaption(doc->description());
877     m_activeDocument = doc;
878 }
879
880 void MainWindow::slotPreferences() {
881     //An instance of your dialog could be already created and could be
882     // cached, in which case you want to display the cached dialog
883     // instead of creating another one
884     if (KConfigDialog::showDialog("settings"))
885         return;
886
887     // KConfigDialog didn't find an instance of this dialog, so lets
888     // create it :
889     KdenliveSettingsDialog* dialog = new KdenliveSettingsDialog(this);
890     connect(dialog, SIGNAL(settingsChanged(const QString&)), this, SLOT(updateConfiguration()));
891     dialog->show();
892 }
893
894 void MainWindow::updateConfiguration() {
895     //TODO: we should apply settings to all projects, not only the current one
896     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
897     if (currentTab) {
898         currentTab->refresh();
899         currentTab->projectView()->checkAutoScroll();
900         currentTab->projectView()->checkTrackHeight();
901         if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
902     }
903     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
904     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
905     activateShuttleDevice();
906
907 }
908
909 void MainWindow::slotSwitchVideoThumbs() {
910     KdenliveSettings::setVideothumbnails(!KdenliveSettings::videothumbnails());
911     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
912     if (currentTab) {
913         currentTab->refresh();
914     }
915     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
916 }
917
918 void MainWindow::slotSwitchAudioThumbs() {
919     KdenliveSettings::setAudiothumbnails(!KdenliveSettings::audiothumbnails());
920     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
921     if (currentTab) {
922         currentTab->refresh();
923         currentTab->projectView()->checkAutoScroll();
924         if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
925     }
926     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
927 }
928
929 void MainWindow::slotSwitchMarkersComments() {
930     KdenliveSettings::setShowmarkers(!KdenliveSettings::showmarkers());
931     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
932     if (currentTab) {
933         currentTab->refresh();
934     }
935     m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
936 }
937
938
939
940
941 void MainWindow::slotDeleteTimelineClip() {
942     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
943     if (currentTab) {
944         currentTab->projectView()->deleteSelectedClips();
945     }
946 }
947
948 void MainWindow::slotAddClipMarker() {
949     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
950     if (currentTab) {
951         currentTab->projectView()->slotAddClipMarker();
952     }
953 }
954
955 void MainWindow::slotCutTimelineClip() {
956     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
957     if (currentTab) {
958         currentTab->projectView()->cutSelectedClips();
959     }
960 }
961
962 void MainWindow::slotAddProjectClip(KUrl url) {
963     if (m_activeDocument)
964         m_activeDocument->slotAddClipFile(url, QString());
965 }
966
967 void MainWindow::slotAddVideoEffect(QAction *result) {
968     if (!result) return;
969     QDomElement effect = videoEffects.getEffectByName(result->data().toString());
970     slotAddEffect(effect);
971 }
972
973 void MainWindow::slotAddAudioEffect(QAction *result) {
974     if (!result) return;
975     QDomElement effect = audioEffects.getEffectByName(result->data().toString());
976     slotAddEffect(effect);
977 }
978
979 void MainWindow::slotAddCustomEffect(QAction *result) {
980     if (!result) return;
981     QDomElement effect = customEffects.getEffectByName(result->data().toString());
982     slotAddEffect(effect);
983 }
984
985 void MainWindow::slotZoomIn() {
986     m_zoomSlider->setValue(m_zoomSlider->value() - 1);
987 }
988
989 void MainWindow::slotZoomOut() {
990     m_zoomSlider->setValue(m_zoomSlider->value() + 1);
991 }
992
993 void MainWindow::slotFitZoom() {
994     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
995     if (currentTab) {
996         m_zoomSlider->setValue(currentTab->fitZoom());
997     }
998 }
999
1000 void MainWindow::slotGotProgressInfo(const QString &message, int progress) {
1001     statusProgressBar->setValue(progress);
1002     if (progress >= 0) {
1003         if (!message.isEmpty()) statusLabel->setText(message);
1004         statusProgressBar->setVisible(true);
1005     } else {
1006         statusLabel->setText(QString());
1007         statusProgressBar->setVisible(false);
1008     }
1009 }
1010
1011 void MainWindow::slotShowClipProperties(DocClipBase *clip) {
1012     if (clip->clipType() == TEXT) {
1013         m_activeDocument->editTextClip(clip->getProperty("xml"), clip->getId());
1014         return;
1015     }
1016     ClipProperties dia(clip, m_activeDocument->timecode(), m_activeDocument->fps(), this);
1017     if (dia.exec() == QDialog::Accepted) {
1018         m_projectList->slotUpdateClipProperties(dia.clipId(), dia.properties());
1019         if (dia.needsTimelineRefresh()) {
1020             // update clip occurences in timeline
1021             TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
1022             currentTab->projectView()->slotUpdateClip(dia.clipId());
1023         }
1024     }
1025 }
1026
1027 void MainWindow::customEvent(QEvent* e) {
1028     if (e->type() == QEvent::User) {
1029         // The timeline playing position changed...
1030         kDebug() << "RECIEVED JOG EVEMNT!!!";
1031     }
1032 }
1033 void MainWindow::slotActivateEffectStackView() {
1034     effectStack->raiseWindow(effectStackDock);
1035 }
1036
1037 void MainWindow::slotActivateTransitionView() {
1038     transitionConfig->raiseWindow(transitionConfigDock);
1039 }
1040
1041 void MainWindow::slotSnapRewind() {
1042     if (m_monitorManager->projectMonitorFocused()) {
1043         TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
1044         currentTab->projectView()->slotSeekToPreviousSnap();
1045     }
1046 }
1047
1048 void MainWindow::slotSnapForward() {
1049     if (m_monitorManager->projectMonitorFocused()) {
1050         TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
1051         currentTab->projectView()->slotSeekToNextSnap();
1052     }
1053 }
1054
1055 void MainWindow::slotChangeTool(QAction * action) {
1056     if (action == m_buttonSelectTool) slotSetTool(SELECTTOOL);
1057     else if (action == m_buttonRazorTool) slotSetTool(RAZORTOOL);
1058 }
1059
1060 void MainWindow::slotSetTool(PROJECTTOOL tool) {
1061     if (m_activeDocument) {
1062         //m_activeDocument->setTool(tool);
1063         TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
1064         currentTab->projectView()->setTool(tool);
1065     }
1066 }
1067
1068 #include "mainwindow.moc"