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