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