]> git.sesse.net Git - kdenlive/blob - src/mainwindow.cpp
use appropriate icons
[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     m_timelineContextClipMenu->addAction(actionCollection()->action("delete_timeline_clip"));
220     m_timelineContextClipMenu->addAction(actionCollection()->action("cut_timeline_clip"));
221
222     QMenu *markersMenu = (QMenu*)(factory()->container("marker_menu", this));
223     m_timelineContextClipMenu->addMenu(markersMenu);
224     m_timelineContextClipMenu->addMenu(videoEffectsMenu);
225     m_timelineContextClipMenu->addMenu(audioEffectsMenu);
226     m_timelineContextClipMenu->addMenu(customEffectsMenu);
227
228     m_timelineContextTransitionMenu->addAction(action);
229
230     connect(projectMonitorDock, SIGNAL(visibilityChanged(bool)), m_projectMonitor, SLOT(refreshMonitor(bool)));
231     connect(clipMonitorDock, SIGNAL(visibilityChanged(bool)), m_clipMonitor, SLOT(refreshMonitor(bool)));
232     //connect(m_monitorManager, SIGNAL(connectMonitors()), this, SLOT(slotConnectMonitors()));
233     connect(m_monitorManager, SIGNAL(raiseClipMonitor(bool)), this, SLOT(slotRaiseMonitor(bool)));
234     connect(m_effectList, SIGNAL(addEffect(QDomElement)), this, SLOT(slotAddEffect(QDomElement)));
235     m_monitorManager->initMonitors(m_clipMonitor, m_projectMonitor);
236     slotConnectMonitors();
237
238     setAutoSaveSettings();
239     newFile();
240
241     activateShuttleDevice();
242 }
243
244 void MainWindow::queryQuit() {
245     kDebug() << "----- SAVING CONFUIG";
246     if (queryClose()) kapp->quit();
247 }
248
249 //virtual
250 bool MainWindow::queryClose() {
251     saveOptions();
252     if (m_activeDocument && m_activeDocument->isModified()) {
253         switch (KMessageBox::warningYesNoCancel(this, i18n("Save changes to document ?"))) {
254         case KMessageBox::Yes :
255             // save document here. If saving fails, return false;
256             return true;
257         case KMessageBox::No :
258             return true;
259         default: // cancel
260             return false;
261         }
262     }
263     return true;
264 }
265
266 void MainWindow::activateShuttleDevice() {
267     if (m_jogProcess) delete m_jogProcess;
268     m_jogProcess = NULL;
269     if (KdenliveSettings::enableshuttle() == false) return;
270     m_jogProcess = new JogShuttle(KdenliveSettings::shuttledevice());
271     connect(m_jogProcess, SIGNAL(rewind1()), m_monitorManager, SLOT(slotRewindOneFrame()));
272     connect(m_jogProcess, SIGNAL(forward1()), m_monitorManager, SLOT(slotForwardOneFrame()));
273     connect(m_jogProcess, SIGNAL(rewind(double)), m_monitorManager, SLOT(slotRewind(double)));
274     connect(m_jogProcess, SIGNAL(forward(double)), m_monitorManager, SLOT(slotForward(double)));
275     connect(m_jogProcess, SIGNAL(stop()), m_monitorManager, SLOT(slotPlay()));
276     connect(m_jogProcess, SIGNAL(button(int)), this, SLOT(slotShuttleButton(int)));
277 }
278
279 void MainWindow::slotShuttleButton(int code) {
280     switch (code) {
281     case 5:
282         slotShuttleAction(KdenliveSettings::shuttle1());
283         break;
284     case 6:
285         slotShuttleAction(KdenliveSettings::shuttle2());
286         break;
287     case 7:
288         slotShuttleAction(KdenliveSettings::shuttle3());
289         break;
290     case 8:
291         slotShuttleAction(KdenliveSettings::shuttle4());
292         break;
293     case 9:
294         slotShuttleAction(KdenliveSettings::shuttle5());
295         break;
296     }
297 }
298
299 void MainWindow::slotShuttleAction(int code) {
300     switch (code) {
301     case 0:
302         return;
303     case 1:
304         m_monitorManager->slotPlay();
305         break;
306     default:
307         m_monitorManager->slotPlay();
308         break;
309     }
310 }
311
312 void MainWindow::slotFullScreen() {
313     //KToggleFullScreenAction::setFullScreen(this, actionCollection()->action("fullscreen")->isChecked());
314 }
315
316 void MainWindow::slotAddEffect(QDomElement effect, GenTime pos, int track) {
317     if (!m_activeDocument) return;
318     if (effect.isNull()) {
319         kDebug() << "--- ERROR, TRYING TO APPEND NULL EFFECT";
320         return;
321     }
322     TrackView *currentTimeLine = (TrackView *) m_timelineArea->currentWidget();
323     currentTimeLine->projectView()->slotAddEffect(effect, pos, track);
324 }
325
326 void MainWindow::slotRaiseMonitor(bool clipMonitor) {
327     if (clipMonitor) clipMonitorDock->raise();
328     else projectMonitorDock->raise();
329 }
330
331 void MainWindow::slotSetClipDuration(int id, int duration) {
332     if (!m_activeDocument) return;
333     m_activeDocument->setProducerDuration(id, duration);
334 }
335
336 void MainWindow::slotConnectMonitors() {
337
338     m_projectList->setRenderer(m_clipMonitor->render);
339     connect(m_projectList, SIGNAL(clipSelected(const QDomElement &)), m_clipMonitor, SLOT(slotSetXml(const QDomElement &)));
340     connect(m_projectList, SIGNAL(receivedClipDuration(int, int)), this, SLOT(slotSetClipDuration(int, int)));
341     connect(m_projectList, SIGNAL(showClipProperties(DocClipBase *)), this, SLOT(slotShowClipProperties(DocClipBase *)));
342     connect(m_projectList, SIGNAL(getFileProperties(const QDomElement &, int)), m_clipMonitor->render, SLOT(getFileProperties(const QDomElement &, int)));
343     connect(m_clipMonitor->render, SIGNAL(replyGetImage(int, int, const QPixmap &, int, int)), m_projectList, SLOT(slotReplyGetImage(int, int, const QPixmap &, int, int)));
344     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 > &)));
345 }
346
347 void MainWindow::setupActions() {
348
349     m_timecodeFormat = new KComboBox(this);
350     m_timecodeFormat->addItem(i18n("hh:mm:ss::ff"));
351     m_timecodeFormat->addItem(i18n("Frames"));
352
353     statusProgressBar = new QProgressBar(this);
354     statusProgressBar->setMinimum(0);
355     statusProgressBar->setMaximum(100);
356     statusProgressBar->setMaximumWidth(150);
357     statusProgressBar->setVisible(false);
358     statusLabel = new QLabel(this);
359
360     QWidget *w = new QWidget;
361
362     QHBoxLayout *layout = new QHBoxLayout;
363     w->setLayout(layout);
364     layout->setContentsMargins(5, 0, 5, 0);
365     QToolBar *toolbar = new QToolBar("statusToolBar", this);
366
367
368     m_toolGroup = new QActionGroup(this);
369
370     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;}";
371
372     m_buttonSelectTool = toolbar->addAction(KIcon("kdenlive-select-tool"), i18n("Selection tool"));
373     m_buttonSelectTool->setCheckable(true);
374     m_buttonSelectTool->setChecked(true);
375
376     m_buttonRazorTool = toolbar->addAction(KIcon("edit-cut"), i18n("Razor tool"));
377     m_buttonRazorTool->setCheckable(true);
378     m_buttonRazorTool->setChecked(false);
379
380     m_toolGroup->addAction(m_buttonSelectTool);
381     m_toolGroup->addAction(m_buttonRazorTool);
382     m_toolGroup->setExclusive(true);
383     toolbar->setStyleSheet(style1);
384     connect(m_toolGroup, SIGNAL(triggered(QAction *)), this, SLOT(slotChangeTool(QAction *)));
385
386     toolbar->addSeparator();
387     m_buttonFitZoom = toolbar->addAction(KIcon("zoom-fit-best"), i18n("Fit zoom to project"));
388     m_buttonFitZoom->setCheckable(false);
389     connect(m_buttonFitZoom, SIGNAL(triggered()), this, SLOT(slotFitZoom()));
390
391     m_zoomSlider = new QSlider(Qt::Horizontal, this);
392     m_zoomSlider->setMaximum(13);
393
394     m_zoomSlider->setMaximumWidth(150);
395     m_zoomSlider->setMinimumWidth(100);
396
397     const int contentHeight = QFontMetrics(w->font()).height() + 3;
398     QString style = "QSlider::groove:horizontal { border: 1px solid #999999;height: 8px }";
399     style.append("QSlider::handle:horizontal {  background-color: white; border: 1px solid #999999;width: 8px;margin: -2px 0;border-radius: 3px; }");
400     m_zoomSlider->setStyleSheet(style);
401
402     //m_zoomSlider->setMaximumHeight(contentHeight);
403     //m_zoomSlider->height() + 5;
404     statusBar()->setMinimumHeight(contentHeight + 5);
405
406
407     toolbar->addWidget(m_zoomSlider);
408
409     m_buttonVideoThumbs = toolbar->addAction(KIcon("video-mpeg"), i18n("Show videoo thumbnails"));
410     m_buttonVideoThumbs->setCheckable(true);
411     m_buttonVideoThumbs->setChecked(KdenliveSettings::audiothumbnails());
412     connect(m_buttonVideoThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchVideoThumbs()));
413
414     m_buttonAudioThumbs = toolbar->addAction(KIcon("audio-mpeg"), i18n("Show audio thumbnails"));
415     m_buttonAudioThumbs->setCheckable(true);
416     m_buttonAudioThumbs->setChecked(KdenliveSettings::videothumbnails());
417     connect(m_buttonAudioThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchAudioThumbs()));
418
419     m_buttonShowMarkers = toolbar->addAction(KIcon("audio-mpeg"), i18n("Show markers comments"));
420     m_buttonShowMarkers->setCheckable(true);
421     m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
422     connect(m_buttonShowMarkers, SIGNAL(triggered()), this, SLOT(slotSwitchMarkersComments()));
423     layout->addWidget(toolbar);
424
425     statusBar()->insertPermanentWidget(0, statusProgressBar, 1);
426     statusBar()->insertPermanentWidget(1, statusLabel, 1);
427     statusBar()->insertPermanentWidget(ID_TIMELINE_BUTTONS, w);
428     statusBar()->insertPermanentFixedItem("00:00:00:00", ID_TIMELINE_POS);
429     statusBar()->insertPermanentWidget(ID_TIMELINE_FORMAT, m_timecodeFormat);
430     statusBar()->setMaximumHeight(statusBar()->font().pointSize() * 4);
431
432     actionCollection()->addAction("select_tool", m_buttonSelectTool);
433     actionCollection()->addAction("razor_tool", m_buttonRazorTool);
434
435     KAction* profilesAction = new KAction(KIcon("document-new"), i18n("Manage Profiles"), this);
436     actionCollection()->addAction("manage_profiles", profilesAction);
437     connect(profilesAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProfiles()));
438
439     KAction* projectAction = new KAction(KIcon("configure"), i18n("Project Settings"), this);
440     actionCollection()->addAction("project_settings", projectAction);
441     connect(projectAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProjectSettings()));
442
443     KAction* projectRender = new KAction(KIcon("media-record"), i18n("Render"), this);
444     actionCollection()->addAction("project_render", projectRender);
445     connect(projectRender, SIGNAL(triggered(bool)), this, SLOT(slotRenderProject()));
446
447     KAction* monitorPlay = new KAction(KIcon("media-playback-start"), i18n("Play"), this);
448     monitorPlay->setShortcut(Qt::Key_Space);
449     actionCollection()->addAction("monitor_play", monitorPlay);
450     connect(monitorPlay, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotPlay()));
451
452     KAction* monitorSeekBackward = new KAction(KIcon("media-seek-backward"), i18n("Rewind"), this);
453     monitorSeekBackward->setShortcut(Qt::Key_J);
454     actionCollection()->addAction("monitor_seek_backward", monitorSeekBackward);
455     connect(monitorSeekBackward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewind()));
456
457     KAction* monitorSeekBackwardOneFrame = new KAction(KIcon("media-skip-backward"), i18n("Rewind 1 Frame"), this);
458     monitorSeekBackwardOneFrame->setShortcut(Qt::Key_Left);
459     actionCollection()->addAction("monitor_seek_backward-one-frame", monitorSeekBackwardOneFrame);
460     connect(monitorSeekBackwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewindOneFrame()));
461
462     KAction* monitorSeekSnapBackward = new KAction(KIcon("media-seek-backward"), i18n("Go to Previous Snap Point"), this);
463     monitorSeekSnapBackward->setShortcut(Qt::ALT + Qt::Key_Left);
464     actionCollection()->addAction("monitor_seek_snap_backward", monitorSeekSnapBackward);
465     connect(monitorSeekSnapBackward, SIGNAL(triggered(bool)), this, SLOT(slotSnapRewind()));
466
467     KAction* monitorSeekForward = new KAction(KIcon("media-seek-forward"), i18n("Forward"), this);
468     monitorSeekForward->setShortcut(Qt::Key_L);
469     actionCollection()->addAction("monitor_seek_forward", monitorSeekForward);
470     connect(monitorSeekForward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForward()));
471
472     KAction* monitorSeekForwardOneFrame = new KAction(KIcon("media-skip-forward"), i18n("Forward 1 Frame"), this);
473     monitorSeekForwardOneFrame->setShortcut(Qt::Key_Right);
474     actionCollection()->addAction("monitor_seek_forward-one-frame", monitorSeekForwardOneFrame);
475     connect(monitorSeekForwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForwardOneFrame()));
476
477     KAction* monitorSeekSnapForward = new KAction(KIcon("media-seek-forward"), i18n("Go to Next Snap Point"), this);
478     monitorSeekSnapForward->setShortcut(Qt::ALT + Qt::Key_Right);
479     actionCollection()->addAction("monitor_seek_snap_forward", monitorSeekSnapForward);
480     connect(monitorSeekSnapForward, SIGNAL(triggered(bool)), this, SLOT(slotSnapForward()));
481
482     KAction* deleteTimelineClip = new KAction(KIcon("edit-delete"), i18n("Delete Selected Item"), this);
483     deleteTimelineClip->setShortcut(Qt::Key_Delete);
484     actionCollection()->addAction("delete_timeline_clip", deleteTimelineClip);
485     connect(deleteTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotDeleteTimelineClip()));
486
487     KAction* cutTimelineClip = new KAction(KIcon("edit-cut"), i18n("Cut Clip"), this);
488     cutTimelineClip->setShortcut(Qt::SHIFT + Qt::Key_R);
489     actionCollection()->addAction("cut_timeline_clip", cutTimelineClip);
490     connect(cutTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotCutTimelineClip()));
491
492     KAction* addClipMarker = new KAction(KIcon("bookmark-new"), i18n("Add Marker to Clip"), this);
493     actionCollection()->addAction("add_clip_marker", addClipMarker);
494     connect(addClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotAddClipMarker()));
495
496     KAction* deleteClipMarker = new KAction(KIcon("edit-delete"), i18n("Delete Marker from Clip"), this);
497     actionCollection()->addAction("delete_clip_marker", deleteClipMarker);
498     connect(deleteClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotDeleteClipMarker()));
499
500     KAction* editClipMarker = new KAction(KIcon("document-properties"), i18n("Edit Marker"), this);
501     actionCollection()->addAction("edit_clip_marker", editClipMarker);
502     connect(editClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotEditClipMarker()));
503
504     KStandardAction::quit(this, SLOT(queryQuit()),
505                           actionCollection());
506
507     KStandardAction::open(this, SLOT(openFile()),
508                           actionCollection());
509
510     m_fileOpenRecent = KStandardAction::openRecent(this, SLOT(openFile(const KUrl &)),
511                        actionCollection());
512
513     KStandardAction::save(this, SLOT(saveFile()),
514                           actionCollection());
515
516     KStandardAction::saveAs(this, SLOT(saveFileAs()),
517                             actionCollection());
518
519     KStandardAction::openNew(this, SLOT(newFile()),
520                              actionCollection());
521
522     KStandardAction::preferences(this, SLOT(slotPreferences()),
523                                  actionCollection());
524
525     KStandardAction::undo(this, SLOT(undo()),
526                           actionCollection());
527
528     KStandardAction::redo(this, SLOT(redo()),
529                           actionCollection());
530
531     KStandardAction::fullScreen(this, SLOT(slotFullScreen()), this, actionCollection());
532
533     connect(actionCollection(), SIGNAL(actionHovered(QAction*)),
534             this, SLOT(slotDisplayActionMessage(QAction*)));
535     //connect(actionCollection(), SIGNAL( clearStatusText() ),
536     //statusBar(), SLOT( clear() ) );
537
538     readOptions();
539 }
540
541 void MainWindow::undo() {
542     m_commandStack->undo();
543 }
544
545 void MainWindow::redo() {
546     m_commandStack->redo();
547 }
548
549 void MainWindow::slotDisplayActionMessage(QAction *a) {
550     statusBar()->showMessage(a->data().toString(), 3000);
551 }
552
553 void MainWindow::saveOptions() {
554     KdenliveSettings::self()->writeConfig();
555     KSharedConfigPtr config = KGlobal::config();
556     m_fileOpenRecent->saveEntries(KConfigGroup(config, "Recent Files"));
557     config->sync();
558 }
559
560 void MainWindow::readOptions() {
561     KSharedConfigPtr config = KGlobal::config();
562     m_fileOpenRecent->loadEntries(KConfigGroup(config, "Recent Files"));
563 }
564
565 void MainWindow::newFile() {
566     QString profileName;
567     KUrl projectFolder;
568     if (m_timelineArea->count() == 0) profileName = KdenliveSettings::default_profile();
569     else {
570         ProjectSettings *w = new ProjectSettings;
571         if (w->exec() != QDialog::Accepted) return;
572         profileName = w->selectedProfile();
573         projectFolder = w->selectedFolder();
574         delete w;
575     }
576     MltVideoProfile prof = ProfilesDialog::getVideoProfile(profileName);
577     if (prof.width == 0) prof = ProfilesDialog::getVideoProfile("dv_pal");
578     KdenliveDoc *doc = new KdenliveDoc(KUrl(), projectFolder, prof, m_commandStack, this);
579     TrackView *trackView = new TrackView(doc, this);
580     m_timelineArea->addTab(trackView, KIcon("kdenlive"), i18n("Untitled") + " / " + prof.description);
581     if (m_timelineArea->count() == 1) {
582         connectDocumentInfo(doc);
583         connectDocument(trackView, doc);
584     } else m_timelineArea->setTabBarHidden(false);
585 }
586
587 void MainWindow::activateDocument() {
588     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
589     KdenliveDoc *currentDoc = currentTab->document();
590     connectDocumentInfo(currentDoc);
591     connectDocument(currentTab, currentDoc);
592 }
593
594 void MainWindow::slotRemoveTab() {
595     QWidget *w = m_timelineArea->currentWidget();
596     // closing current document
597     int ix = m_timelineArea->currentIndex() + 1;
598     if (ix == m_timelineArea->count()) ix = 0;
599     m_timelineArea->setCurrentIndex(ix);
600     TrackView *tabToClose = (TrackView *) w;
601     KdenliveDoc *docToClose = tabToClose->document();
602     m_timelineArea->removeTab(m_timelineArea->indexOf(w));
603     if (m_timelineArea->count() == 1) m_timelineArea->setTabBarHidden(true);
604     delete docToClose;
605     delete w;
606 }
607
608 void MainWindow::saveFileAs(const QString &outputFileName) {
609     m_projectMonitor->saveSceneList(outputFileName, m_activeDocument->documentInfoXml());
610     m_activeDocument->setUrl(KUrl(outputFileName));
611     setCaption(m_activeDocument->description());
612     m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
613     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), m_activeDocument->url().path());
614     m_activeDocument->setModified(false);
615 }
616
617 void MainWindow::saveFileAs() {
618     QString outputFile = KFileDialog::getSaveFileName(KUrl(), "*.kdenlive|Kdenlive project files (*.kdenlive)");
619     if (QFile::exists(outputFile)) {
620         if (KMessageBox::questionYesNo(this, i18n("File already exists.\nDo you want to overwrite it ?")) == KMessageBox::No) return;
621     }
622     saveFileAs(outputFile);
623 }
624
625 void MainWindow::saveFile() {
626     if (!m_activeDocument) return;
627     if (m_activeDocument->url().isEmpty()) {
628         saveFileAs();
629     } else {
630         saveFileAs(m_activeDocument->url().path());
631     }
632 }
633
634 void MainWindow::openFile() { //changed
635     KUrl url = KFileDialog::getOpenUrl(KUrl(), "*.kdenlive|Kdenlive project files (*.kdenlive)\n*.westley|MLT project files (*.westley)");
636     if (url.isEmpty()) return;
637     m_fileOpenRecent->addUrl(url);
638     openFile(url);
639 }
640
641 void MainWindow::openFile(const KUrl &url) { //new
642     //TODO: get video profile from url before opening it
643     MltVideoProfile prof = ProfilesDialog::getVideoProfile(KdenliveSettings::default_profile());
644     if (prof.width == 0) prof = ProfilesDialog::getVideoProfile("dv_pal");
645     KdenliveDoc *doc = new KdenliveDoc(url, KUrl(), prof, m_commandStack, this);
646     connectDocumentInfo(doc);
647     TrackView *trackView = new TrackView(doc, this);
648     m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description()));
649     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), doc->url().path());
650     if (m_timelineArea->count() > 1) m_timelineArea->setTabBarHidden(false);
651     slotGotProgressInfo(QString(), -1);
652     //connectDocument(trackView, doc);
653 }
654
655
656 void MainWindow::parseProfiles() {
657     //kdDebug()<<" + + YOUR MLT INSTALL WAS FOUND IN: "<< MLT_PREFIX <<endl;
658
659     //KdenliveSettings::setDefaulttmpfolder();
660     if (KdenliveSettings::mltpath().isEmpty()) {
661         KdenliveSettings::setMltpath(QString(MLT_PREFIX) + QString("/share/mlt/profiles/"));
662     }
663     if (KdenliveSettings::rendererpath().isEmpty()) {
664         KdenliveSettings::setRendererpath(KStandardDirs::findExe("inigo"));
665     }
666     QStringList profilesFilter;
667     profilesFilter << "*";
668     QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
669
670     if (profilesList.isEmpty()) {
671         // Cannot find MLT path, try finding inigo
672         QString profilePath = KdenliveSettings::rendererpath();
673         if (!profilePath.isEmpty()) {
674             profilePath = profilePath.section('/', 0, -3);
675             KdenliveSettings::setMltpath(profilePath + "/share/mlt/profiles/");
676             QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
677         }
678
679         if (profilesList.isEmpty()) {
680             // Cannot find the MLT profiles, ask for location
681             KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find your Mlt profiles, please give the path"), this);
682             getUrl->fileDialog()->setMode(KFile::Directory);
683             getUrl->exec();
684             KUrl mltPath = getUrl->selectedUrl();
685             delete getUrl;
686             if (mltPath.isEmpty()) kapp->quit();
687             KdenliveSettings::setMltpath(mltPath.path());
688             QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
689         }
690     }
691
692     if (KdenliveSettings::rendererpath().isEmpty()) {
693         // Cannot find the MLT inigo renderer, ask for location
694         KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find the inigo program required for rendering (part of Mlt)"), this);
695         getUrl->exec();
696         KUrl rendererPath = getUrl->selectedUrl();
697         delete getUrl;
698         if (rendererPath.isEmpty()) kapp->quit();
699         KdenliveSettings::setRendererpath(rendererPath.path());
700     }
701
702     kDebug() << "RESULTING MLT PATH: " << KdenliveSettings::mltpath();
703
704     // Parse MLT profiles to build a list of available video formats
705     if (profilesList.isEmpty()) parseProfiles();
706 }
707
708
709 void MainWindow::slotEditProfiles() {
710     ProfilesDialog *w = new ProfilesDialog;
711     w->exec();
712     delete w;
713 }
714
715 void MainWindow::slotEditProjectSettings() {
716     ProjectSettings *w = new ProjectSettings;
717     if (w->exec() == QDialog::Accepted) {
718         QString profile = w->selectedProfile();
719         m_activeDocument->setProfilePath(profile);
720         m_monitorManager->resetProfiles(profile);
721         setCaption(m_activeDocument->description());
722         KdenliveSettings::setCurrent_profile(m_activeDocument->profilePath());
723         if (m_renderWidget) m_renderWidget->setDocumentStandard(m_activeDocument->getDocumentStandard());
724         m_monitorManager->setTimecode(m_activeDocument->timecode());
725         m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
726
727         // We need to desactivate & reactivate monitors to get a refresh
728         m_monitorManager->switchMonitors();
729     }
730     delete w;
731 }
732
733 void MainWindow::slotRenderProject() {
734     if (!m_renderWidget) {
735         m_renderWidget = new RenderWidget(this);
736         connect(m_renderWidget, SIGNAL(doRender(const QString&, const QString&, const QStringList &, bool, bool)), this, SLOT(slotDoRender(const QString&, const QString&, const QStringList &, bool, bool)));
737     }
738     /*TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
739     if (currentTab) m_renderWidget->setTimeline(currentTab);
740     m_renderWidget->setDocument(m_activeDocument);*/
741     m_renderWidget->show();
742 }
743
744 void MainWindow::slotDoRender(const QString &dest, const QString &render, const QStringList &avformat_args, bool zoneOnly, bool playAfter) {
745     if (dest.isEmpty()) return;
746     int in;
747     int out;
748     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
749     if (currentTab && zoneOnly) {
750         in = currentTab->inPoint();
751         out = currentTab->outPoint();
752     }
753     KTemporaryFile temp;
754     temp.setAutoRemove(false);
755     temp.setSuffix(".westley");
756     if (temp.open()) {
757         m_projectMonitor->saveSceneList(temp.fileName());
758         QStringList args;
759         args << "-erase";
760         if (zoneOnly) args << "in=" + QString::number(in) << "out=" + QString::number(out);
761         QString videoPlayer = "-";
762         if (playAfter) videoPlayer = "kmplayer";
763         args << "inigo" << m_activeDocument->profilePath() << render << videoPlayer << temp.fileName() << dest << avformat_args;
764         QProcess::startDetached("kdenlive_render", args);
765     }
766 }
767
768 void MainWindow::slotUpdateMousePosition(int pos) {
769     if (m_activeDocument)
770         switch (m_timecodeFormat->currentIndex()) {
771         case 0:
772             statusBar()->changeItem(m_activeDocument->timecode().getTimecodeFromFrames(pos), ID_TIMELINE_POS);
773             break;
774         default:
775             statusBar()->changeItem(QString::number(pos), ID_TIMELINE_POS);
776         }
777 }
778
779 void MainWindow::slotUpdateDocumentState(bool modified) {
780     setCaption(m_activeDocument->description(), modified);
781     if (modified) {
782         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Link));
783         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("document-save"));
784     } else {
785         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Text));
786         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("kdenlive"));
787     }
788 }
789
790 void MainWindow::connectDocumentInfo(KdenliveDoc *doc) {
791     if (m_activeDocument) {
792         if (m_activeDocument == doc) return;
793         disconnect(m_activeDocument, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
794     }
795     connect(doc, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
796 }
797
798 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //changed
799     //m_projectMonitor->stop();
800     kDebug() << "///////////////////   CONNECTING DOC TO PROJECT VIEW ////////////////";
801     if (m_activeDocument) {
802         if (m_activeDocument == doc) return;
803         m_activeDocument->backupMltPlaylist();
804         if (m_activeTimeline) {
805             disconnect(m_projectMonitor, SIGNAL(renderPosition(int)), m_activeTimeline, SLOT(moveCursorPos(int)));
806             disconnect(m_projectMonitor, SIGNAL(durationChanged(int)), m_activeTimeline, SLOT(setDuration(int)));
807             disconnect(m_activeDocument, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
808             disconnect(m_activeDocument, SIGNAL(addProjectFolder(const QString, int, bool, bool)), m_projectList, SLOT(slotAddFolder(const QString, int, bool, bool)));
809             disconnect(m_activeDocument, SIGNAL(signalDeleteProjectClip(int)), m_projectList, SLOT(slotDeleteClip(int)));
810             disconnect(m_activeDocument, SIGNAL(updateClipDisplay(int)), m_projectList, SLOT(slotUpdateClip(int)));
811             disconnect(m_activeDocument, SIGNAL(refreshClipThumbnail(int)), m_projectList, SLOT(slotRefreshClipThumbnail(int)));
812             disconnect(m_activeDocument, SIGNAL(deletTimelineClip(int)), m_activeTimeline, SLOT(slotDeleteClip(int)));
813             disconnect(m_activeTimeline, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*)));
814             disconnect(trackView, SIGNAL(clipItemSelected(ClipItem*)), this, SLOT(slotActivateEffectStackView()));
815             disconnect(m_activeTimeline, SIGNAL(transitionItemSelected(Transition*)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*)));
816             disconnect(trackView, SIGNAL(transitionItemSelected(Transition*)), this, SLOT(slotActivateTransitionView()));
817             disconnect(m_zoomSlider, SIGNAL(valueChanged(int)), m_activeTimeline, SLOT(slotChangeZoom(int)));
818             disconnect(m_activeDocument, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
819             disconnect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement)), m_activeTimeline->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement)));
820             disconnect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), m_activeTimeline->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
821             disconnect(effectStack, SIGNAL(changeEffectState(ClipItem*, QDomElement, bool)), m_activeTimeline->projectView(), SLOT(slotChangeEffectState(ClipItem*, QDomElement, bool)));
822             disconnect(effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), trackView->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
823             disconnect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), m_activeTimeline->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
824             disconnect(transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
825             disconnect(m_activeTimeline->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
826         }
827         m_activeDocument->setRenderer(NULL);
828         disconnect(m_projectList, SIGNAL(clipSelected(const QDomElement &)), m_clipMonitor, SLOT(slotSetXml(const QDomElement &)));
829         m_clipMonitor->stop();
830     }
831     m_monitorManager->resetProfiles(doc->profilePath());
832     m_projectList->setDocument(doc);
833     connect(m_projectList, SIGNAL(clipSelected(const QDomElement &)), m_clipMonitor, SLOT(slotSetXml(const QDomElement &)));
834     connect(trackView, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
835     connect(trackView, SIGNAL(mousePosition(int)), this, SLOT(slotUpdateMousePosition(int)));
836     connect(m_projectMonitor, SIGNAL(renderPosition(int)), trackView, SLOT(moveCursorPos(int)));
837     connect(m_projectMonitor, SIGNAL(durationChanged(int)), trackView, SLOT(setDuration(int)));
838     connect(doc, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
839     connect(doc, SIGNAL(addProjectFolder(const QString, int, bool, bool)), m_projectList, SLOT(slotAddFolder(const QString, int, bool, bool)));
840     connect(doc, SIGNAL(signalDeleteProjectClip(int)), m_projectList, SLOT(slotDeleteClip(int)));
841     connect(doc, SIGNAL(updateClipDisplay(int)), m_projectList, SLOT(slotUpdateClip(int)));
842     connect(doc, SIGNAL(refreshClipThumbnail(int)), m_projectList, SLOT(slotRefreshClipThumbnail(int)));
843
844     connect(doc, SIGNAL(deletTimelineClip(int)), trackView, SLOT(slotDeleteClip(int)));
845     connect(doc, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
846
847
848
849     connect(trackView, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*)));
850     connect(trackView, SIGNAL(clipItemSelected(ClipItem*)), this, SLOT(slotActivateEffectStackView()));
851     connect(trackView, SIGNAL(transitionItemSelected(Transition*)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*)));
852     connect(trackView, SIGNAL(transitionItemSelected(Transition*)), this, SLOT(slotActivateTransitionView()));
853     m_zoomSlider->setValue(trackView->currentZoom());
854     connect(m_zoomSlider, SIGNAL(valueChanged(int)), trackView, SLOT(slotChangeZoom(int)));
855     connect(trackView->projectView(), SIGNAL(zoomIn()), this, SLOT(slotZoomIn()));
856     connect(trackView->projectView(), SIGNAL(zoomOut()), this, SLOT(slotZoomOut()));
857     connect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement)), trackView->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement)));
858     connect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), trackView->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
859     connect(effectStack, SIGNAL(changeEffectState(ClipItem*, QDomElement, bool)), trackView->projectView(), SLOT(slotChangeEffectState(ClipItem*, QDomElement, bool)));
860     connect(effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), trackView->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
861     connect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), trackView->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
862     connect(transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
863     connect(trackView->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
864     trackView->projectView()->setContextMenu(m_timelineContextMenu, m_timelineContextClipMenu, m_timelineContextTransitionMenu);
865     m_activeTimeline = trackView;
866     KdenliveSettings::setCurrent_profile(doc->profilePath());
867     if (m_renderWidget) m_renderWidget->setDocumentStandard(doc->getDocumentStandard());
868     m_monitorManager->setTimecode(doc->timecode());
869     doc->setRenderer(m_projectMonitor->render);
870     m_commandStack->setActiveStack(doc->commandStack());
871     if (m_commandStack->isClean()) kDebug() << "////////////  UNDO STACK IS CLEAN";
872     else  kDebug() << "////////////  UNDO STACK IS NOT CLEAN*******************";
873
874     //m_overView->setScene(trackView->projectScene());
875     //m_overView->scale(m_overView->width() / trackView->duration(), m_overView->height() / (50 * trackView->tracksNumber()));
876     //m_overView->fitInView(m_overView->itemAt(0, 50), Qt::KeepAspectRatio);
877
878     setCaption(doc->description());
879     m_activeDocument = doc;
880 }
881
882 void MainWindow::slotPreferences() {
883     //An instance of your dialog could be already created and could be
884     // cached, in which case you want to display the cached dialog
885     // instead of creating another one
886     if (KConfigDialog::showDialog("settings"))
887         return;
888
889     // KConfigDialog didn't find an instance of this dialog, so lets
890     // create it :
891     KdenliveSettingsDialog* dialog = new KdenliveSettingsDialog(this);
892     connect(dialog, SIGNAL(settingsChanged(const QString&)), this, SLOT(updateConfiguration()));
893     dialog->show();
894 }
895
896 void MainWindow::updateConfiguration() {
897     //TODO: we should apply settings to all projects, not only the current one
898     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
899     if (currentTab) {
900         currentTab->refresh();
901         currentTab->projectView()->checkAutoScroll();
902         currentTab->projectView()->checkTrackHeight();
903         if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
904     }
905     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
906     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
907     activateShuttleDevice();
908
909 }
910
911 void MainWindow::slotSwitchVideoThumbs() {
912     KdenliveSettings::setVideothumbnails(!KdenliveSettings::videothumbnails());
913     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
914     if (currentTab) {
915         currentTab->refresh();
916     }
917     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
918 }
919
920 void MainWindow::slotSwitchAudioThumbs() {
921     KdenliveSettings::setAudiothumbnails(!KdenliveSettings::audiothumbnails());
922     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
923     if (currentTab) {
924         currentTab->refresh();
925         currentTab->projectView()->checkAutoScroll();
926         if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
927     }
928     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
929 }
930
931 void MainWindow::slotSwitchMarkersComments() {
932     KdenliveSettings::setShowmarkers(!KdenliveSettings::showmarkers());
933     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
934     if (currentTab) {
935         currentTab->refresh();
936     }
937     m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
938 }
939
940
941
942
943 void MainWindow::slotDeleteTimelineClip() {
944     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
945     if (currentTab) {
946         currentTab->projectView()->deleteSelectedClips();
947     }
948 }
949
950 void MainWindow::slotAddClipMarker() {
951     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
952     if (currentTab) {
953         currentTab->projectView()->slotAddClipMarker();
954     }
955 }
956
957 void MainWindow::slotDeleteClipMarker() {
958     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
959     if (currentTab) {
960         currentTab->projectView()->slotDeleteClipMarker();
961     }
962 }
963
964 void MainWindow::slotEditClipMarker() {
965     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
966     if (currentTab) {
967         currentTab->projectView()->slotEditClipMarker();
968     }
969 }
970
971 void MainWindow::slotCutTimelineClip() {
972     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
973     if (currentTab) {
974         currentTab->projectView()->cutSelectedClips();
975     }
976 }
977
978 void MainWindow::slotAddProjectClip(KUrl url) {
979     if (m_activeDocument)
980         m_activeDocument->slotAddClipFile(url, QString());
981 }
982
983 void MainWindow::slotAddVideoEffect(QAction *result) {
984     if (!result) return;
985     QDomElement effect = videoEffects.getEffectByName(result->data().toString());
986     slotAddEffect(effect);
987 }
988
989 void MainWindow::slotAddAudioEffect(QAction *result) {
990     if (!result) return;
991     QDomElement effect = audioEffects.getEffectByName(result->data().toString());
992     slotAddEffect(effect);
993 }
994
995 void MainWindow::slotAddCustomEffect(QAction *result) {
996     if (!result) return;
997     QDomElement effect = customEffects.getEffectByName(result->data().toString());
998     slotAddEffect(effect);
999 }
1000
1001 void MainWindow::slotZoomIn() {
1002     m_zoomSlider->setValue(m_zoomSlider->value() - 1);
1003 }
1004
1005 void MainWindow::slotZoomOut() {
1006     m_zoomSlider->setValue(m_zoomSlider->value() + 1);
1007 }
1008
1009 void MainWindow::slotFitZoom() {
1010     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
1011     if (currentTab) {
1012         m_zoomSlider->setValue(currentTab->fitZoom());
1013     }
1014 }
1015
1016 void MainWindow::slotGotProgressInfo(const QString &message, int progress) {
1017     statusProgressBar->setValue(progress);
1018     if (progress >= 0) {
1019         if (!message.isEmpty()) statusLabel->setText(message);
1020         statusProgressBar->setVisible(true);
1021     } else {
1022         statusLabel->setText(QString());
1023         statusProgressBar->setVisible(false);
1024     }
1025 }
1026
1027 void MainWindow::slotShowClipProperties(DocClipBase *clip) {
1028     if (clip->clipType() == TEXT) {
1029         m_activeDocument->editTextClip(clip->getProperty("xml"), clip->getId());
1030         return;
1031     }
1032     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
1033     ClipProperties dia(clip, m_activeDocument->timecode(), m_activeDocument->fps(), this);
1034     connect(&dia, SIGNAL(addMarker(int, GenTime, QString)), currentTab->projectView(), SLOT(slotAddClipMarker(int, GenTime, QString)));
1035     if (dia.exec() == QDialog::Accepted) {
1036         m_projectList->slotUpdateClipProperties(dia.clipId(), dia.properties());
1037         if (dia.needsTimelineRefresh()) {
1038             // update clip occurences in timeline
1039
1040             currentTab->projectView()->slotUpdateClip(dia.clipId());
1041         }
1042     }
1043 }
1044
1045 void MainWindow::customEvent(QEvent* e) {
1046     if (e->type() == QEvent::User) {
1047         // The timeline playing position changed...
1048         kDebug() << "RECIEVED JOG EVEMNT!!!";
1049     }
1050 }
1051 void MainWindow::slotActivateEffectStackView() {
1052     effectStack->raiseWindow(effectStackDock);
1053 }
1054
1055 void MainWindow::slotActivateTransitionView() {
1056     transitionConfig->raiseWindow(transitionConfigDock);
1057 }
1058
1059 void MainWindow::slotSnapRewind() {
1060     if (m_monitorManager->projectMonitorFocused()) {
1061         TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
1062         currentTab->projectView()->slotSeekToPreviousSnap();
1063     }
1064 }
1065
1066 void MainWindow::slotSnapForward() {
1067     if (m_monitorManager->projectMonitorFocused()) {
1068         TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
1069         currentTab->projectView()->slotSeekToNextSnap();
1070     }
1071 }
1072
1073 void MainWindow::slotChangeTool(QAction * action) {
1074     if (action == m_buttonSelectTool) slotSetTool(SELECTTOOL);
1075     else if (action == m_buttonRazorTool) slotSetTool(RAZORTOOL);
1076 }
1077
1078 void MainWindow::slotSetTool(PROJECTTOOL tool) {
1079     if (m_activeDocument) {
1080         //m_activeDocument->setTool(tool);
1081         TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
1082         currentTab->projectView()->setTool(tool);
1083     }
1084 }
1085
1086 #include "mainwindow.moc"