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