]> git.sesse.net Git - kdenlive/blob - src/mainwindow.cpp
copy / paste clips and transitions, move several clips
[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 #include <QKeyEvent>
28
29 #include <KApplication>
30 #include <KAction>
31 #include <KLocale>
32 #include <KGlobal>
33 #include <KActionCollection>
34 #include <KStandardAction>
35 #include <KFileDialog>
36 #include <KMessageBox>
37 #include <KDebug>
38 #include <KIO/NetAccess>
39 #include <KSaveFile>
40 #include <KRuler>
41 #include <KConfigDialog>
42 #include <KXMLGUIFactory>
43 #include <KStatusBar>
44 #include <kstandarddirs.h>
45 #include <KUrlRequesterDialog>
46 #include <KTemporaryFile>
47 #include <KActionMenu>
48 #include <KMenu>
49 #include <locale.h>
50 #include <ktogglefullscreenaction.h>
51
52 #include <mlt++/Mlt.h>
53
54 #include "mainwindow.h"
55 #include "kdenlivesettings.h"
56 #include "kdenlivesettingsdialog.h"
57 #include "initeffects.h"
58 #include "profilesdialog.h"
59 #include "projectsettings.h"
60 #include "events.h"
61 #include "renderjob.h"
62 #include "clipmanager.h"
63 #include "projectlist.h"
64 #include "monitor.h"
65 #include "recmonitor.h"
66 #include "monitormanager.h"
67 #include "kdenlivedoc.h"
68 #include "trackview.h"
69 #include "customtrackview.h"
70 #include "effectslistview.h"
71 #include "effectstackview.h"
72 #include "transitionsettings.h"
73 #include "renderwidget.h"
74 #include "renderer.h"
75 #include "jogshuttle.h"
76 #include "clipproperties.h"
77
78 #define ID_STATUS_MSG 1
79 #define ID_EDITMODE_MSG 2
80 #define ID_TIMELINE_MSG 3
81 #define ID_TIMELINE_BUTTONS 5
82 #define ID_TIMELINE_POS 6
83 #define ID_TIMELINE_FORMAT 7
84
85 EffectsList MainWindow::videoEffects;
86 EffectsList MainWindow::audioEffects;
87 EffectsList MainWindow::customEffects;
88 EffectsList MainWindow::transitions;
89
90 MainWindow::MainWindow(QWidget *parent)
91         : KXmlGuiWindow(parent),
92         m_activeDocument(NULL), m_activeTimeline(NULL), m_renderWidget(NULL), m_jogProcess(NULL), m_findActivated(false), m_initialized(false) {
93     setlocale(LC_NUMERIC, "POSIX");
94     parseProfiles();
95     setFont(KGlobalSettings::toolBarFont());
96     m_commandStack = new QUndoGroup;
97     m_timelineArea = new KTabWidget(this);
98     m_timelineArea->setTabReorderingEnabled(true);
99     m_timelineArea->setTabBarHidden(true);
100
101     QToolButton *closeTabButton = new QToolButton;
102     connect(closeTabButton, SIGNAL(clicked()), this, SLOT(slotRemoveTab()));
103     closeTabButton->setIcon(KIcon("tab-close"));
104     closeTabButton->adjustSize();
105     closeTabButton->setToolTip(i18n("Close the current tab"));
106     m_timelineArea->setCornerWidget(closeTabButton);
107     connect(m_timelineArea, SIGNAL(currentChanged(int)), this, SLOT(activateDocument()));
108
109     connect(&m_findTimer, SIGNAL(timeout()), this, SLOT(findTimeout()));
110     m_findTimer.setSingleShot(true);
111
112     initEffects::parseEffectFiles();
113     m_monitorManager = new MonitorManager();
114
115     projectListDock = new QDockWidget(i18n("Project Tree"), this);
116     projectListDock->setObjectName("project_tree");
117     m_projectList = new ProjectList(this);
118     projectListDock->setWidget(m_projectList);
119     addDockWidget(Qt::TopDockWidgetArea, projectListDock);
120
121     effectListDock = new QDockWidget(i18n("Effect List"), this);
122     effectListDock->setObjectName("effect_list");
123     m_effectList = new EffectsListView();
124
125     //m_effectList = new KListWidget(this);
126     effectListDock->setWidget(m_effectList);
127     addDockWidget(Qt::TopDockWidgetArea, effectListDock);
128
129     effectStackDock = new QDockWidget(i18n("Effect Stack"), this);
130     effectStackDock->setObjectName("effect_stack");
131     effectStack = new EffectStackView(this);
132     effectStackDock->setWidget(effectStack);
133     addDockWidget(Qt::TopDockWidgetArea, effectStackDock);
134
135     transitionConfigDock = new QDockWidget(i18n("Transition"), this);
136     transitionConfigDock->setObjectName("transition");
137     transitionConfig = new TransitionSettings(this);
138     transitionConfigDock->setWidget(transitionConfig);
139     addDockWidget(Qt::TopDockWidgetArea, transitionConfigDock);
140
141
142     clipMonitorDock = new QDockWidget(i18n("Clip Monitor"), this);
143     clipMonitorDock->setObjectName("clip_monitor");
144     m_clipMonitor = new Monitor("clip", m_monitorManager, this);
145     clipMonitorDock->setWidget(m_clipMonitor);
146     addDockWidget(Qt::TopDockWidgetArea, clipMonitorDock);
147     //m_clipMonitor->stop();
148
149     projectMonitorDock = new QDockWidget(i18n("Project Monitor"), this);
150     projectMonitorDock->setObjectName("project_monitor");
151     m_projectMonitor = new Monitor("project", m_monitorManager, this);
152     projectMonitorDock->setWidget(m_projectMonitor);
153     addDockWidget(Qt::TopDockWidgetArea, projectMonitorDock);
154
155     recMonitorDock = new QDockWidget(i18n("Record Monitor"), this);
156     recMonitorDock->setObjectName("record_monitor");
157     m_recMonitor = new RecMonitor("record", this);
158     recMonitorDock->setWidget(m_recMonitor);
159     addDockWidget(Qt::TopDockWidgetArea, recMonitorDock);
160
161     connect(m_recMonitor, SIGNAL(addProjectClip(KUrl)), this, SLOT(slotAddProjectClip(KUrl)));
162
163     undoViewDock = new QDockWidget(i18n("Undo History"), this);
164     undoViewDock->setObjectName("undo_history");
165     m_undoView = new QUndoView(this);
166     m_undoView->setCleanIcon(KIcon("edit-clear"));
167     m_undoView->setEmptyLabel(i18n("Clean"));
168     undoViewDock->setWidget(m_undoView);
169     m_undoView->setGroup(m_commandStack);
170     addDockWidget(Qt::TopDockWidgetArea, undoViewDock);
171
172     //overviewDock = new QDockWidget(i18n("Project Overview"), this);
173     //overviewDock->setObjectName("project_overview");
174     //m_overView = new CustomTrackView(NULL, NULL, this);
175     //overviewDock->setWidget(m_overView);
176     //addDockWidget(Qt::TopDockWidgetArea, overviewDock);
177
178     setupActions();
179     //tabifyDockWidget(projectListDock, effectListDock);
180     tabifyDockWidget(projectListDock, effectStackDock);
181     tabifyDockWidget(projectListDock, transitionConfigDock);
182     //tabifyDockWidget(projectListDock, undoViewDock);
183     projectListDock->raise();
184
185     tabifyDockWidget(clipMonitorDock, projectMonitorDock);
186     tabifyDockWidget(clipMonitorDock, recMonitorDock);
187     setCentralWidget(m_timelineArea);
188
189     setupGUI(Default, NULL /*"kdenliveui.rc"*/);
190     kDebug() << factory() << " " << factory()->container("video_effects_menu", this);
191
192     // build effects menus
193     QAction *action;
194     QMenu *videoEffectsMenu = static_cast<QMenu*>(factory()->container("video_effects_menu", this));
195     QStringList effects = videoEffects.effectNames();
196     foreach(const QString &name, effects) {
197         action = new QAction(name, this);
198         action->setData(name);
199         videoEffectsMenu->addAction(action);
200     }
201     QMenu *audioEffectsMenu = static_cast<QMenu*>(factory()->container("audio_effects_menu", this));
202     effects = audioEffects.effectNames();
203     foreach(const QString &name, effects) {
204         action = new QAction(name, this);
205         action->setData(name);
206         audioEffectsMenu->addAction(action);
207     }
208     QMenu *customEffectsMenu = static_cast<QMenu*>(factory()->container("custom_effects_menu", this));
209     effects = customEffects.effectNames();
210     foreach(const QString &name, effects) {
211         action = new QAction(name, this);
212         action->setData(name);
213         customEffectsMenu->addAction(action);
214     }
215
216     QMenu *viewMenu = static_cast<QMenu*>(factory()->container("dockwindows", this));
217     const QList<QAction *> viewActions = createPopupMenu()->actions();
218     viewMenu->insertActions(NULL, viewActions);
219
220     connect(videoEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddVideoEffect(QAction *)));
221     connect(audioEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddAudioEffect(QAction *)));
222     connect(customEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddCustomEffect(QAction *)));
223
224     m_timelineContextMenu = new QMenu(this);
225     m_timelineContextClipMenu = new QMenu(this);
226     m_timelineContextTransitionMenu = new QMenu(this);
227
228
229     QMenu *transitionsMenu = new QMenu(i18n("Add Transition"), this);
230     effects = transitions.effectNames();
231     foreach(const QString &name, effects) {
232         action = new QAction(name, this);
233         action->setData(name);
234         transitionsMenu->addAction(action);
235     }
236     connect(transitionsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddTransition(QAction *)));
237
238     m_timelineContextMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Paste)));
239
240     m_timelineContextClipMenu->addAction(actionCollection()->action("delete_timeline_clip"));
241     m_timelineContextClipMenu->addAction(actionCollection()->action("cut_timeline_clip"));
242     m_timelineContextClipMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Copy)));
243
244     QMenu *markersMenu = (QMenu*)(factory()->container("marker_menu", this));
245     m_timelineContextClipMenu->addMenu(markersMenu);
246     m_timelineContextClipMenu->addMenu(transitionsMenu);
247     m_timelineContextClipMenu->addMenu(videoEffectsMenu);
248     m_timelineContextClipMenu->addMenu(audioEffectsMenu);
249     m_timelineContextClipMenu->addMenu(customEffectsMenu);
250
251     m_timelineContextTransitionMenu->addAction(actionCollection()->action("delete_timeline_clip"));
252     m_timelineContextTransitionMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Copy)));
253
254     connect(projectMonitorDock, SIGNAL(visibilityChanged(bool)), m_projectMonitor, SLOT(refreshMonitor(bool)));
255     connect(clipMonitorDock, SIGNAL(visibilityChanged(bool)), m_clipMonitor, SLOT(refreshMonitor(bool)));
256     //connect(m_monitorManager, SIGNAL(connectMonitors()), this, SLOT(slotConnectMonitors()));
257     connect(m_monitorManager, SIGNAL(raiseClipMonitor(bool)), this, SLOT(slotRaiseMonitor(bool)));
258     connect(m_effectList, SIGNAL(addEffect(QDomElement)), this, SLOT(slotAddEffect(QDomElement)));
259     m_monitorManager->initMonitors(m_clipMonitor, m_projectMonitor);
260     slotConnectMonitors();
261
262     setAutoSaveSettings();
263
264     if (KdenliveSettings::openlastproject()) {
265         openLastFile();
266     } else newFile();
267
268     activateShuttleDevice();
269 }
270
271 void MainWindow::queryQuit() {
272     kDebug() << "----- SAVING CONFUIG";
273     if (queryClose()) kapp->quit();
274 }
275
276 //virtual
277 bool MainWindow::queryClose() {
278     saveOptions();
279     if (m_activeDocument && m_activeDocument->isModified()) {
280         switch (KMessageBox::warningYesNoCancel(this, i18n("Save changes to document ?"))) {
281         case KMessageBox::Yes :
282             // save document here. If saving fails, return false;
283             return true;
284         case KMessageBox::No :
285             return true;
286         default: // cancel
287             return false;
288         }
289     }
290     return true;
291 }
292
293 void MainWindow::saveProperties(KConfig*) {
294     // save properties here,used by session management
295     saveFile();
296 }
297
298
299 void MainWindow::readProperties(KConfig *config) {
300     // read properties here,used by session management
301     QString Lastproject = config->group("Recent Files").readPathEntry("File1", QString());
302     openFile(KUrl(Lastproject));
303 }
304
305 void MainWindow::activateShuttleDevice() {
306     if (m_jogProcess) delete m_jogProcess;
307     m_jogProcess = NULL;
308     if (KdenliveSettings::enableshuttle() == false) return;
309     m_jogProcess = new JogShuttle(KdenliveSettings::shuttledevice());
310     connect(m_jogProcess, SIGNAL(rewind1()), m_monitorManager, SLOT(slotRewindOneFrame()));
311     connect(m_jogProcess, SIGNAL(forward1()), m_monitorManager, SLOT(slotForwardOneFrame()));
312     connect(m_jogProcess, SIGNAL(rewind(double)), m_monitorManager, SLOT(slotRewind(double)));
313     connect(m_jogProcess, SIGNAL(forward(double)), m_monitorManager, SLOT(slotForward(double)));
314     connect(m_jogProcess, SIGNAL(stop()), m_monitorManager, SLOT(slotPlay()));
315     connect(m_jogProcess, SIGNAL(button(int)), this, SLOT(slotShuttleButton(int)));
316 }
317
318 void MainWindow::slotShuttleButton(int code) {
319     switch (code) {
320     case 5:
321         slotShuttleAction(KdenliveSettings::shuttle1());
322         break;
323     case 6:
324         slotShuttleAction(KdenliveSettings::shuttle2());
325         break;
326     case 7:
327         slotShuttleAction(KdenliveSettings::shuttle3());
328         break;
329     case 8:
330         slotShuttleAction(KdenliveSettings::shuttle4());
331         break;
332     case 9:
333         slotShuttleAction(KdenliveSettings::shuttle5());
334         break;
335     }
336 }
337
338 void MainWindow::slotShuttleAction(int code) {
339     switch (code) {
340     case 0:
341         return;
342     case 1:
343         m_monitorManager->slotPlay();
344         break;
345     default:
346         m_monitorManager->slotPlay();
347         break;
348     }
349 }
350
351 void MainWindow::slotFullScreen() {
352     //KToggleFullScreenAction::setFullScreen(this, actionCollection()->action("fullscreen")->isChecked());
353 }
354
355 void MainWindow::slotAddEffect(QDomElement effect, GenTime pos, int track) {
356     if (!m_activeDocument) return;
357     if (effect.isNull()) {
358         kDebug() << "--- ERROR, TRYING TO APPEND NULL EFFECT";
359         return;
360     }
361     TrackView *currentTimeLine = (TrackView *) m_timelineArea->currentWidget();
362     currentTimeLine->projectView()->slotAddEffect(effect, pos, track);
363 }
364
365 void MainWindow::slotRaiseMonitor(bool clipMonitor) {
366     if (clipMonitor) clipMonitorDock->raise();
367     else projectMonitorDock->raise();
368 }
369
370 void MainWindow::slotSetClipDuration(int id, int duration) {
371     if (!m_activeDocument) return;
372     m_activeDocument->setProducerDuration(id, duration);
373 }
374
375 void MainWindow::slotConnectMonitors() {
376
377     m_projectList->setRenderer(m_clipMonitor->render);
378     connect(m_projectList, SIGNAL(receivedClipDuration(int, int)), this, SLOT(slotSetClipDuration(int, int)));
379     connect(m_projectList, SIGNAL(showClipProperties(DocClipBase *)), this, SLOT(slotShowClipProperties(DocClipBase *)));
380     connect(m_projectList, SIGNAL(getFileProperties(const QDomElement &, int)), m_clipMonitor->render, SLOT(getFileProperties(const QDomElement &, int)));
381     connect(m_clipMonitor->render, SIGNAL(replyGetImage(int, int, const QPixmap &, int, int)), m_projectList, SLOT(slotReplyGetImage(int, int, const QPixmap &, int, int)));
382     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 > &)));
383     connect(m_clipMonitor, SIGNAL(refreshClipThumbnail(int)), m_projectList, SLOT(slotRefreshClipThumbnail(int)));
384 }
385
386 void MainWindow::setupActions() {
387
388     m_timecodeFormat = new KComboBox(this);
389     m_timecodeFormat->addItem(i18n("hh:mm:ss::ff"));
390     m_timecodeFormat->addItem(i18n("Frames"));
391
392     statusProgressBar = new QProgressBar(this);
393     statusProgressBar->setMinimum(0);
394     statusProgressBar->setMaximum(100);
395     statusProgressBar->setMaximumWidth(150);
396     statusProgressBar->setVisible(false);
397
398     QWidget *w = new QWidget;
399
400     QHBoxLayout *layout = new QHBoxLayout;
401     w->setLayout(layout);
402     layout->setContentsMargins(5, 0, 5, 0);
403     QToolBar *toolbar = new QToolBar("statusToolBar", this);
404
405
406     m_toolGroup = new QActionGroup(this);
407
408     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;}";
409
410     m_buttonSelectTool = toolbar->addAction(KIcon("kdenlive-select-tool"), i18n("Selection tool"));
411     m_buttonSelectTool->setCheckable(true);
412     m_buttonSelectTool->setChecked(true);
413
414     m_buttonRazorTool = toolbar->addAction(KIcon("edit-cut"), i18n("Razor tool"));
415     m_buttonRazorTool->setCheckable(true);
416     m_buttonRazorTool->setChecked(false);
417
418     m_toolGroup->addAction(m_buttonSelectTool);
419     m_toolGroup->addAction(m_buttonRazorTool);
420     m_toolGroup->setExclusive(true);
421     toolbar->setToolButtonStyle(Qt::ToolButtonIconOnly);
422
423     QWidget * actionWidget;
424     actionWidget = toolbar->widgetForAction(m_buttonSelectTool);
425     actionWidget->setMaximumWidth(24);
426     actionWidget->setMinimumHeight(17);
427
428     actionWidget = toolbar->widgetForAction(m_buttonRazorTool);
429     actionWidget->setMaximumWidth(24);
430     actionWidget->setMinimumHeight(17);
431
432     toolbar->setStyleSheet(style1);
433     connect(m_toolGroup, SIGNAL(triggered(QAction *)), this, SLOT(slotChangeTool(QAction *)));
434
435     toolbar->addSeparator();
436     m_buttonFitZoom = toolbar->addAction(KIcon("zoom-fit-best"), i18n("Fit zoom to project"));
437     m_buttonFitZoom->setCheckable(false);
438     connect(m_buttonFitZoom, SIGNAL(triggered()), this, SLOT(slotFitZoom()));
439
440     actionWidget = toolbar->widgetForAction(m_buttonFitZoom);
441     actionWidget->setMaximumWidth(24);
442     actionWidget->setMinimumHeight(17);
443
444     m_zoomSlider = new QSlider(Qt::Horizontal, this);
445     m_zoomSlider->setMaximum(13);
446
447     m_zoomSlider->setMaximumWidth(150);
448     m_zoomSlider->setMinimumWidth(100);
449
450     const int contentHeight = QFontMetrics(w->font()).height() + 8;
451     QString style = "QSlider::groove:horizontal { background-color: rgba(230, 230, 230, 220);border: 1px solid #999999;height: 8px;border-radius: 3px;margin-top:3px }";
452     style.append("QSlider::handle:horizontal {  background-color: white; border: 1px solid #999999;width: 9px;margin: -2px 0;border-radius: 3px; }");
453     m_zoomSlider->setStyleSheet(style);
454
455     //m_zoomSlider->setMaximumHeight(contentHeight);
456     //m_zoomSlider->height() + 5;
457     statusBar()->setMinimumHeight(contentHeight);
458
459
460     toolbar->addWidget(m_zoomSlider);
461
462     m_buttonVideoThumbs = toolbar->addAction(KIcon("kdenlive-show-videothumb"), i18n("Show video thumbnails"));
463     m_buttonVideoThumbs->setCheckable(true);
464     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
465     connect(m_buttonVideoThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchVideoThumbs()));
466
467     m_buttonAudioThumbs = toolbar->addAction(KIcon("kdenlive-show-audiothumb"), i18n("Show audio thumbnails"));
468     m_buttonAudioThumbs->setCheckable(true);
469     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
470     connect(m_buttonAudioThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchAudioThumbs()));
471
472     m_buttonShowMarkers = toolbar->addAction(KIcon("kdenlive-show-markers"), i18n("Show markers comments"));
473     m_buttonShowMarkers->setCheckable(true);
474     m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
475     connect(m_buttonShowMarkers, SIGNAL(triggered()), this, SLOT(slotSwitchMarkersComments()));
476
477     m_buttonSnap = toolbar->addAction(KIcon("kdenlive-snap"), i18n("Snap"));
478     m_buttonSnap->setCheckable(true);
479     m_buttonSnap->setChecked(KdenliveSettings::snaptopoints());
480     connect(m_buttonSnap, SIGNAL(triggered()), this, SLOT(slotSwitchSnap()));
481     layout->addWidget(toolbar);
482
483
484     actionWidget = toolbar->widgetForAction(m_buttonVideoThumbs);
485     actionWidget->setMaximumWidth(24);
486     actionWidget->setMinimumHeight(17);
487
488     actionWidget = toolbar->widgetForAction(m_buttonAudioThumbs);
489     actionWidget->setMaximumWidth(24);
490     actionWidget->setMinimumHeight(17);
491
492     actionWidget = toolbar->widgetForAction(m_buttonShowMarkers);
493     actionWidget->setMaximumWidth(24);
494     actionWidget->setMinimumHeight(17);
495
496     actionWidget = toolbar->widgetForAction(m_buttonSnap);
497     actionWidget->setMaximumWidth(24);
498     actionWidget->setMinimumHeight(17);
499
500     m_messageLabel = new StatusBarMessageLabel(this);
501     m_messageLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding);
502
503     statusBar()->addWidget(m_messageLabel, 10);
504     statusBar()->addWidget(statusProgressBar, 0);
505     statusBar()->insertPermanentWidget(ID_TIMELINE_BUTTONS, w);
506     statusBar()->insertPermanentFixedItem("00:00:00:00", ID_TIMELINE_POS);
507     statusBar()->insertPermanentWidget(ID_TIMELINE_FORMAT, m_timecodeFormat);
508     statusBar()->setMaximumHeight(statusBar()->font().pointSize() * 4);
509     m_messageLabel->hide();
510
511     actionCollection()->addAction("select_tool", m_buttonSelectTool);
512     actionCollection()->addAction("razor_tool", m_buttonRazorTool);
513
514     actionCollection()->addAction("show_video_thumbs", m_buttonVideoThumbs);
515     actionCollection()->addAction("show_audio_thumbs", m_buttonAudioThumbs);
516     actionCollection()->addAction("show_markers", m_buttonShowMarkers);
517     actionCollection()->addAction("snap", m_buttonSnap);
518     actionCollection()->addAction("zoom_fit", m_buttonFitZoom);
519
520     m_projectSearch = new KAction(KIcon("edit-find"), i18n("Find"), this);
521     actionCollection()->addAction("project_find", m_projectSearch);
522     connect(m_projectSearch, SIGNAL(triggered(bool)), this, SLOT(slotFind()));
523     m_projectSearch->setShortcut(Qt::Key_Slash);
524
525     m_projectSearchNext = new KAction(KIcon("go-down-search"), i18n("Find Next"), this);
526     actionCollection()->addAction("project_find_next", m_projectSearchNext);
527     connect(m_projectSearchNext, SIGNAL(triggered(bool)), this, SLOT(slotFindNext()));
528     m_projectSearchNext->setShortcut(Qt::Key_F3);
529     m_projectSearchNext->setEnabled(false);
530
531     KAction* profilesAction = new KAction(KIcon("document-new"), i18n("Manage Profiles"), this);
532     actionCollection()->addAction("manage_profiles", profilesAction);
533     connect(profilesAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProfiles()));
534
535     KAction* projectAction = new KAction(KIcon("configure"), i18n("Project Settings"), this);
536     actionCollection()->addAction("project_settings", projectAction);
537     connect(projectAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProjectSettings()));
538
539     KAction* projectRender = new KAction(KIcon("media-record"), i18n("Render"), this);
540     actionCollection()->addAction("project_render", projectRender);
541     connect(projectRender, SIGNAL(triggered(bool)), this, SLOT(slotRenderProject()));
542
543     KAction* monitorPlay = new KAction(KIcon("media-playback-start"), i18n("Play"), this);
544     monitorPlay->setShortcut(Qt::Key_Space);
545     actionCollection()->addAction("monitor_play", monitorPlay);
546     connect(monitorPlay, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotPlay()));
547
548     KAction* monitorSeekBackward = new KAction(KIcon("media-seek-backward"), i18n("Rewind"), this);
549     monitorSeekBackward->setShortcut(Qt::Key_J);
550     actionCollection()->addAction("monitor_seek_backward", monitorSeekBackward);
551     connect(monitorSeekBackward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewind()));
552
553     KAction* monitorSeekBackwardOneFrame = new KAction(KIcon("media-skip-backward"), i18n("Rewind 1 Frame"), this);
554     monitorSeekBackwardOneFrame->setShortcut(Qt::Key_Left);
555     actionCollection()->addAction("monitor_seek_backward-one-frame", monitorSeekBackwardOneFrame);
556     connect(monitorSeekBackwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewindOneFrame()));
557
558     KAction* monitorSeekSnapBackward = new KAction(KIcon("media-seek-backward"), i18n("Go to Previous Snap Point"), this);
559     monitorSeekSnapBackward->setShortcut(Qt::ALT + Qt::Key_Left);
560     actionCollection()->addAction("monitor_seek_snap_backward", monitorSeekSnapBackward);
561     connect(monitorSeekSnapBackward, SIGNAL(triggered(bool)), this, SLOT(slotSnapRewind()));
562
563     KAction* monitorSeekForward = new KAction(KIcon("media-seek-forward"), i18n("Forward"), this);
564     monitorSeekForward->setShortcut(Qt::Key_L);
565     actionCollection()->addAction("monitor_seek_forward", monitorSeekForward);
566     connect(monitorSeekForward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForward()));
567
568     KAction* clipStart = new KAction(KIcon("media-seek-backward"), i18n("Go to Clip Start"), this);
569     clipStart->setShortcut(Qt::Key_Home);
570     actionCollection()->addAction("seek_clip_start", clipStart);
571     connect(clipStart, SIGNAL(triggered(bool)), this, SLOT(slotClipStart()));
572
573     KAction* clipEnd = new KAction(KIcon("media-seek-forward"), i18n("Go to Clip End"), this);
574     clipEnd->setShortcut(Qt::Key_End);
575     actionCollection()->addAction("seek_clip_end", clipEnd);
576     connect(clipEnd, SIGNAL(triggered(bool)), this, SLOT(slotClipEnd()));
577
578     KAction* projectStart = new KAction(KIcon("media-seek-backward"), i18n("Go to Project Start"), this);
579     projectStart->setShortcut(Qt::CTRL + Qt::Key_Home);
580     actionCollection()->addAction("seek_start", projectStart);
581     connect(projectStart, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotStart()));
582
583     KAction* projectEnd = new KAction(KIcon("media-seek-forward"), i18n("Go to Project End"), this);
584     projectEnd->setShortcut(Qt::CTRL + Qt::Key_End);
585     actionCollection()->addAction("seek_end", projectEnd);
586     connect(projectEnd, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotEnd()));
587
588     KAction* monitorSeekForwardOneFrame = new KAction(KIcon("media-skip-forward"), i18n("Forward 1 Frame"), this);
589     monitorSeekForwardOneFrame->setShortcut(Qt::Key_Right);
590     actionCollection()->addAction("monitor_seek_forward-one-frame", monitorSeekForwardOneFrame);
591     connect(monitorSeekForwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForwardOneFrame()));
592
593     KAction* monitorSeekSnapForward = new KAction(KIcon("media-seek-forward"), i18n("Go to Next Snap Point"), this);
594     monitorSeekSnapForward->setShortcut(Qt::ALT + Qt::Key_Right);
595     actionCollection()->addAction("monitor_seek_snap_forward", monitorSeekSnapForward);
596     connect(monitorSeekSnapForward, SIGNAL(triggered(bool)), this, SLOT(slotSnapForward()));
597
598     KAction* deleteTimelineClip = new KAction(KIcon("edit-delete"), i18n("Delete Selected Item"), this);
599     deleteTimelineClip->setShortcut(Qt::Key_Delete);
600     actionCollection()->addAction("delete_timeline_clip", deleteTimelineClip);
601     connect(deleteTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotDeleteTimelineClip()));
602
603     KAction* cutTimelineClip = new KAction(KIcon("edit-cut"), i18n("Cut Clip"), this);
604     cutTimelineClip->setShortcut(Qt::SHIFT + Qt::Key_R);
605     actionCollection()->addAction("cut_timeline_clip", cutTimelineClip);
606     connect(cutTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotCutTimelineClip()));
607
608     KAction* addClipMarker = new KAction(KIcon("bookmark-new"), i18n("Add Marker to Clip"), this);
609     actionCollection()->addAction("add_clip_marker", addClipMarker);
610     connect(addClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotAddClipMarker()));
611
612     KAction* deleteClipMarker = new KAction(KIcon("edit-delete"), i18n("Delete Marker from Clip"), this);
613     actionCollection()->addAction("delete_clip_marker", deleteClipMarker);
614     connect(deleteClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotDeleteClipMarker()));
615
616     KAction* deleteAllClipMarkers = new KAction(KIcon("edit-delete"), i18n("Delete All Markers from Clip"), this);
617     actionCollection()->addAction("delete_all_clip_markers", deleteAllClipMarkers);
618     connect(deleteAllClipMarkers, SIGNAL(triggered(bool)), this, SLOT(slotDeleteAllClipMarkers()));
619
620     KAction* editClipMarker = new KAction(KIcon("document-properties"), i18n("Edit Marker"), this);
621     actionCollection()->addAction("edit_clip_marker", editClipMarker);
622     connect(editClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotEditClipMarker()));
623
624     KAction *addGuide = new KAction(KIcon("document-new"), i18n("Add Guide"), this);
625     actionCollection()->addAction("add_guide", addGuide);
626     connect(addGuide, SIGNAL(triggered()), this, SLOT(slotAddGuide()));
627
628     QAction *delGuide = new KAction(KIcon("edit-delete"), i18n("Delete Guide"), this);
629     actionCollection()->addAction("delete_guide", delGuide);
630     connect(delGuide, SIGNAL(triggered()), this, SLOT(slotDeleteGuide()));
631
632     QAction *editGuide = new KAction(KIcon("document-properties"), i18n("Edit Guide"), this);
633     actionCollection()->addAction("edit_guide", editGuide);
634     connect(editGuide, SIGNAL(triggered()), this, SLOT(slotEditGuide()));
635
636     QAction *delAllGuides = new KAction(KIcon("edit-delete"), i18n("Delete All Guides"), this);
637     actionCollection()->addAction("delete_all_guides", delAllGuides);
638     connect(delAllGuides, SIGNAL(triggered()), this, SLOT(slotDeleteAllGuides()));
639
640     KStandardAction::quit(this, SLOT(queryQuit()),
641                           actionCollection());
642
643     KStandardAction::open(this, SLOT(openFile()),
644                           actionCollection());
645
646     m_fileOpenRecent = KStandardAction::openRecent(this, SLOT(openFile(const KUrl &)),
647                        actionCollection());
648
649     KStandardAction::save(this, SLOT(saveFile()),
650                           actionCollection());
651
652     KStandardAction::saveAs(this, SLOT(saveFileAs()),
653                             actionCollection());
654
655     KStandardAction::openNew(this, SLOT(newFile()),
656                              actionCollection());
657
658     KStandardAction::preferences(this, SLOT(slotPreferences()),
659                                  actionCollection());
660
661     KStandardAction::copy(this, SLOT(slotCopy()),
662                           actionCollection());
663
664     KStandardAction::paste(this, SLOT(slotPaste()),
665                            actionCollection());
666
667     KStandardAction::undo(this, SLOT(undo()),
668                           actionCollection());
669
670     KStandardAction::redo(this, SLOT(redo()),
671                           actionCollection());
672
673     KStandardAction::fullScreen(this, SLOT(slotFullScreen()), this, actionCollection());
674
675     connect(actionCollection(), SIGNAL(actionHovered(QAction*)),
676             this, SLOT(slotDisplayActionMessage(QAction*)));
677     //connect(actionCollection(), SIGNAL( clearStatusText() ),
678     //statusBar(), SLOT( clear() ) );
679
680     readOptions();
681 }
682
683 void MainWindow::undo() {
684     m_commandStack->undo();
685 }
686
687 void MainWindow::redo() {
688     m_commandStack->redo();
689 }
690
691 void MainWindow::slotDisplayActionMessage(QAction *a) {
692     statusBar()->showMessage(a->data().toString(), 3000);
693 }
694
695 void MainWindow::saveOptions() {
696     KdenliveSettings::self()->writeConfig();
697     KSharedConfigPtr config = KGlobal::config();
698     m_fileOpenRecent->saveEntries(KConfigGroup(config, "Recent Files"));
699     config->sync();
700 }
701
702 void MainWindow::readOptions() {
703     KSharedConfigPtr config = KGlobal::config();
704     m_fileOpenRecent->loadEntries(KConfigGroup(config, "Recent Files"));
705 }
706
707 void MainWindow::newFile() {
708     QString profileName;
709     KUrl projectFolder;
710     if (m_timelineArea->count() == 0) profileName = KdenliveSettings::default_profile();
711     else {
712         ProjectSettings *w = new ProjectSettings;
713         if (w->exec() != QDialog::Accepted) return;
714         profileName = w->selectedProfile();
715         projectFolder = w->selectedFolder();
716         delete w;
717     }
718     MltVideoProfile prof;
719     if (!profileName.isEmpty()) prof = ProfilesDialog::getVideoProfile(profileName);
720     else prof = ProfilesDialog::getVideoProfile("dv_pal");
721     if (prof.width == 0) prof = ProfilesDialog::getVideoProfile("dv_pal");
722     KdenliveDoc *doc = new KdenliveDoc(KUrl(), projectFolder, prof, m_commandStack, this);
723     TrackView *trackView = new TrackView(doc, this);
724     m_timelineArea->addTab(trackView, KIcon("kdenlive"), i18n("Untitled") + " / " + prof.description);
725     if (m_timelineArea->count() == 1) {
726         connectDocumentInfo(doc);
727         connectDocument(trackView, doc);
728     } else m_timelineArea->setTabBarHidden(false);
729 }
730
731 void MainWindow::activateDocument() {
732     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
733     KdenliveDoc *currentDoc = currentTab->document();
734     connectDocumentInfo(currentDoc);
735     connectDocument(currentTab, currentDoc);
736 }
737
738 void MainWindow::slotRemoveTab() {
739     QWidget *w = m_timelineArea->currentWidget();
740     // closing current document
741     int ix = m_timelineArea->currentIndex() + 1;
742     if (ix == m_timelineArea->count()) ix = 0;
743     m_timelineArea->setCurrentIndex(ix);
744     TrackView *tabToClose = (TrackView *) w;
745     KdenliveDoc *docToClose = tabToClose->document();
746     m_timelineArea->removeTab(m_timelineArea->indexOf(w));
747     if (m_timelineArea->count() == 1) m_timelineArea->setTabBarHidden(true);
748     delete docToClose;
749     delete w;
750 }
751
752 void MainWindow::saveFileAs(const QString &outputFileName) {
753     m_projectMonitor->saveSceneList(outputFileName, m_activeDocument->documentInfoXml(m_activeTimeline->projectView()->xmlInfo()));
754     m_activeDocument->setUrl(KUrl(outputFileName));
755     setCaption(m_activeDocument->description());
756     m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
757     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), m_activeDocument->url().path());
758     m_activeDocument->setModified(false);
759     m_fileOpenRecent->addUrl(KUrl(outputFileName));
760 }
761
762 void MainWindow::saveFileAs() {
763     QString outputFile = KFileDialog::getSaveFileName(KUrl(), "*.kdenlive|Kdenlive project files (*.kdenlive)");
764     if (QFile::exists(outputFile)) {
765         if (KMessageBox::questionYesNo(this, i18n("File already exists.\nDo you want to overwrite it ?")) == KMessageBox::No) return;
766     }
767     saveFileAs(outputFile);
768 }
769
770 void MainWindow::saveFile() {
771     if (!m_activeDocument) return;
772     if (m_activeDocument->url().isEmpty()) {
773         saveFileAs();
774     } else {
775         saveFileAs(m_activeDocument->url().path());
776     }
777 }
778
779 void MainWindow::openFile() { //changed
780     KUrl url = KFileDialog::getOpenUrl(KUrl(), "*.kdenlive|Kdenlive project files (*.kdenlive)\n*.westley|MLT project files (*.westley)");
781     if (url.isEmpty()) return;
782     m_fileOpenRecent->addUrl(url);
783     openFile(url);
784 }
785
786 void MainWindow::openLastFile() {
787     KSharedConfigPtr config = KGlobal::config();
788     QString Lastproject = config->group("Recent Files").readPathEntry("File1", QString());
789     openFile(KUrl(Lastproject));
790 }
791
792 void MainWindow::openFile(const KUrl &url) { //new
793     //TODO: get video profile from url before opening it
794     MltVideoProfile prof = ProfilesDialog::getVideoProfile(KdenliveSettings::default_profile());
795     if (prof.width == 0) prof = ProfilesDialog::getVideoProfile("dv_pal");
796     KdenliveDoc *doc = new KdenliveDoc(url, KUrl(), prof, m_commandStack, this);
797     connectDocumentInfo(doc);
798     TrackView *trackView = new TrackView(doc, this);
799     m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description()));
800     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), doc->url().path());
801     if (m_timelineArea->count() > 1) m_timelineArea->setTabBarHidden(false);
802     slotGotProgressInfo(QString(), -1);
803     m_projectMonitor->refreshMonitor(true);
804     //connectDocument(trackView, doc);
805 }
806
807
808 void MainWindow::parseProfiles() {
809     //kdDebug()<<" + + YOUR MLT INSTALL WAS FOUND IN: "<< MLT_PREFIX <<endl;
810
811     //KdenliveSettings::setDefaulttmpfolder();
812     if (KdenliveSettings::mltpath().isEmpty()) {
813         KdenliveSettings::setMltpath(QString(MLT_PREFIX) + QString("/share/mlt/profiles/"));
814     }
815     if (KdenliveSettings::rendererpath().isEmpty()) {
816         KdenliveSettings::setRendererpath(KStandardDirs::findExe("inigo"));
817     }
818     QStringList profilesFilter;
819     profilesFilter << "*";
820     QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
821
822     if (profilesList.isEmpty()) {
823         // Cannot find MLT path, try finding inigo
824         QString profilePath = KdenliveSettings::rendererpath();
825         if (!profilePath.isEmpty()) {
826             profilePath = profilePath.section('/', 0, -3);
827             KdenliveSettings::setMltpath(profilePath + "/share/mlt/profiles/");
828             QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
829         }
830
831         if (profilesList.isEmpty()) {
832             // Cannot find the MLT profiles, ask for location
833             KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find your Mlt profiles, please give the path"), this);
834             getUrl->fileDialog()->setMode(KFile::Directory);
835             getUrl->exec();
836             KUrl mltPath = getUrl->selectedUrl();
837             delete getUrl;
838             if (mltPath.isEmpty()) kapp->quit();
839             KdenliveSettings::setMltpath(mltPath.path());
840             QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
841         }
842     }
843
844     if (KdenliveSettings::rendererpath().isEmpty()) {
845         // Cannot find the MLT inigo renderer, ask for location
846         KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find the inigo program required for rendering (part of Mlt)"), this);
847         getUrl->exec();
848         KUrl rendererPath = getUrl->selectedUrl();
849         delete getUrl;
850         if (rendererPath.isEmpty()) kapp->quit();
851         KdenliveSettings::setRendererpath(rendererPath.path());
852     }
853
854     kDebug() << "RESULTING MLT PATH: " << KdenliveSettings::mltpath();
855
856     // Parse MLT profiles to build a list of available video formats
857     if (profilesList.isEmpty()) parseProfiles();
858 }
859
860
861 void MainWindow::slotEditProfiles() {
862     ProfilesDialog *w = new ProfilesDialog;
863     w->exec();
864     delete w;
865 }
866
867 void MainWindow::slotEditProjectSettings() {
868     ProjectSettings *w = new ProjectSettings;
869     if (w->exec() == QDialog::Accepted) {
870         QString profile = w->selectedProfile();
871         m_activeDocument->setProfilePath(profile);
872         m_monitorManager->resetProfiles(profile);
873         setCaption(m_activeDocument->description());
874         KdenliveSettings::setCurrent_profile(m_activeDocument->profilePath());
875         if (m_renderWidget) m_renderWidget->setDocumentStandard(m_activeDocument->getDocumentStandard());
876         m_monitorManager->setTimecode(m_activeDocument->timecode());
877         m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
878
879         // We need to desactivate & reactivate monitors to get a refresh
880         m_monitorManager->switchMonitors();
881     }
882     delete w;
883 }
884
885 void MainWindow::slotRenderProject() {
886     if (!m_renderWidget) {
887         m_renderWidget = new RenderWidget(this);
888         connect(m_renderWidget, SIGNAL(doRender(const QString&, const QString&, const QStringList &, bool, bool)), this, SLOT(slotDoRender(const QString&, const QString&, const QStringList &, bool, bool)));
889     }
890     /*TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
891     if (currentTab) m_renderWidget->setTimeline(currentTab);
892     m_renderWidget->setDocument(m_activeDocument);*/
893     m_renderWidget->show();
894 }
895
896 void MainWindow::slotDoRender(const QString &dest, const QString &render, const QStringList &avformat_args, bool zoneOnly, bool playAfter) {
897     if (dest.isEmpty()) return;
898     int in;
899     int out;
900     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
901     if (currentTab && zoneOnly) {
902         in = currentTab->inPoint();
903         out = currentTab->outPoint();
904     }
905     KTemporaryFile temp;
906     temp.setAutoRemove(false);
907     temp.setSuffix(".westley");
908     if (temp.open()) {
909         m_projectMonitor->saveSceneList(temp.fileName());
910         QStringList args;
911         args << "-erase";
912         if (zoneOnly) args << "in=" + QString::number(in) << "out=" + QString::number(out);
913         QString videoPlayer = "-";
914         if (playAfter) {
915             videoPlayer = KdenliveSettings::defaultplayerapp();
916             if (videoPlayer.isEmpty()) KMessageBox::sorry(this, i18n("Cannot play video after rendering because the default video player application is not set.\nPlease define it in Kdenlive settings dialog."));
917         }
918         args << KdenliveSettings::rendererpath() << m_activeDocument->profilePath() << render << videoPlayer << temp.fileName() << dest << avformat_args;
919         QProcess::startDetached("kdenlive_render", args);
920     }
921 }
922
923 void MainWindow::slotUpdateMousePosition(int pos) {
924     if (m_activeDocument)
925         switch (m_timecodeFormat->currentIndex()) {
926         case 0:
927             statusBar()->changeItem(m_activeDocument->timecode().getTimecodeFromFrames(pos), ID_TIMELINE_POS);
928             break;
929         default:
930             statusBar()->changeItem(QString::number(pos), ID_TIMELINE_POS);
931         }
932 }
933
934 void MainWindow::slotUpdateDocumentState(bool modified) {
935     setCaption(m_activeDocument->description(), modified);
936     if (modified) {
937         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Link));
938         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("document-save"));
939     } else {
940         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Text));
941         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("kdenlive"));
942     }
943 }
944
945 void MainWindow::connectDocumentInfo(KdenliveDoc *doc) {
946     if (m_activeDocument) {
947         if (m_activeDocument == doc) return;
948         disconnect(m_activeDocument, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
949     }
950     connect(doc, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
951 }
952
953 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //changed
954     //m_projectMonitor->stop();
955     kDebug() << "///////////////////   CONNECTING DOC TO PROJECT VIEW ////////////////";
956     if (m_activeDocument) {
957         if (m_activeDocument == doc) return;
958         m_activeDocument->backupMltPlaylist();
959         if (m_activeTimeline) {
960             disconnect(m_projectMonitor, SIGNAL(renderPosition(int)), m_activeTimeline, SLOT(moveCursorPos(int)));
961             disconnect(m_projectMonitor, SIGNAL(durationChanged(int)), m_activeTimeline, SLOT(setDuration(int)));
962             disconnect(m_activeDocument, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
963             disconnect(m_activeDocument, SIGNAL(addProjectFolder(const QString, int, bool, bool)), m_projectList, SLOT(slotAddFolder(const QString, int, bool, bool)));
964             disconnect(m_activeDocument, SIGNAL(signalDeleteProjectClip(int)), m_projectList, SLOT(slotDeleteClip(int)));
965             disconnect(m_activeDocument, SIGNAL(updateClipDisplay(int)), m_projectList, SLOT(slotUpdateClip(int)));
966             disconnect(m_activeDocument, SIGNAL(refreshClipThumbnail(int)), m_projectList, SLOT(slotRefreshClipThumbnail(int)));
967             disconnect(m_activeDocument, SIGNAL(deletTimelineClip(int)), m_activeTimeline, SLOT(slotDeleteClip(int)));
968             disconnect(m_activeTimeline, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*)));
969             disconnect(m_activeTimeline, SIGNAL(clipItemSelected(ClipItem*)), this, SLOT(slotActivateEffectStackView()));
970             disconnect(m_activeTimeline, SIGNAL(transitionItemSelected(Transition*)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*)));
971             disconnect(m_activeTimeline, SIGNAL(transitionItemSelected(Transition*)), this, SLOT(slotActivateTransitionView()));
972             disconnect(m_zoomSlider, SIGNAL(valueChanged(int)), m_activeTimeline, SLOT(slotChangeZoom(int)));
973             disconnect(m_activeTimeline->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
974             disconnect(m_activeTimeline->projectView(), SIGNAL(showClipFrame(DocClipBase *, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, const int)));
975
976             disconnect(m_activeDocument, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
977             disconnect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement, int)), m_activeTimeline->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement, int)));
978             disconnect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), m_activeTimeline->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
979             disconnect(effectStack, SIGNAL(changeEffectState(ClipItem*, int, bool)), m_activeTimeline->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, bool)));
980             disconnect(effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), trackView->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
981             disconnect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), m_activeTimeline->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
982             disconnect(transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
983             disconnect(m_activeTimeline->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
984         }
985         m_activeDocument->setRenderer(NULL);
986         disconnect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
987         m_clipMonitor->stop();
988     }
989     m_monitorManager->resetProfiles(doc->profilePath());
990     m_projectList->setDocument(doc);
991     connect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
992     connect(trackView, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
993     connect(trackView, SIGNAL(mousePosition(int)), this, SLOT(slotUpdateMousePosition(int)));
994     connect(m_projectMonitor, SIGNAL(renderPosition(int)), trackView, SLOT(moveCursorPos(int)));
995     connect(m_projectMonitor, SIGNAL(durationChanged(int)), trackView, SLOT(setDuration(int)));
996     connect(doc, SIGNAL(addProjectClip(DocClipBase *)), m_projectList, SLOT(slotAddClip(DocClipBase *)));
997     connect(doc, SIGNAL(addProjectFolder(const QString, int, bool, bool)), m_projectList, SLOT(slotAddFolder(const QString, int, bool, bool)));
998     connect(doc, SIGNAL(signalDeleteProjectClip(int)), m_projectList, SLOT(slotDeleteClip(int)));
999     connect(doc, SIGNAL(updateClipDisplay(int)), m_projectList, SLOT(slotUpdateClip(int)));
1000     connect(doc, SIGNAL(refreshClipThumbnail(int)), m_projectList, SLOT(slotRefreshClipThumbnail(int)));
1001
1002     connect(doc, SIGNAL(deletTimelineClip(int)), trackView, SLOT(slotDeleteClip(int)));
1003     connect(doc, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
1004
1005
1006
1007     connect(trackView, SIGNAL(clipItemSelected(ClipItem*)), effectStack, SLOT(slotClipItemSelected(ClipItem*)));
1008     connect(trackView, SIGNAL(clipItemSelected(ClipItem*)), this, SLOT(slotActivateEffectStackView()));
1009     connect(trackView, SIGNAL(transitionItemSelected(Transition*)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*)));
1010     connect(trackView, SIGNAL(transitionItemSelected(Transition*)), this, SLOT(slotActivateTransitionView()));
1011     m_zoomSlider->setValue(trackView->currentZoom());
1012     connect(m_zoomSlider, SIGNAL(valueChanged(int)), trackView, SLOT(slotChangeZoom(int)));
1013     connect(trackView->projectView(), SIGNAL(zoomIn()), this, SLOT(slotZoomIn()));
1014     connect(trackView->projectView(), SIGNAL(zoomOut()), this, SLOT(slotZoomOut()));
1015     connect(trackView->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
1016
1017     connect(trackView->projectView(), SIGNAL(showClipFrame(DocClipBase *, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, const int)));
1018
1019
1020     connect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement, int)), trackView->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement, int)));
1021     connect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), trackView->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
1022     connect(effectStack, SIGNAL(changeEffectState(ClipItem*, int, bool)), trackView->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, bool)));
1023     connect(effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), trackView->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
1024     connect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), trackView->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
1025     connect(transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
1026     connect(trackView->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
1027     trackView->projectView()->setContextMenu(m_timelineContextMenu, m_timelineContextClipMenu, m_timelineContextTransitionMenu);
1028     m_activeTimeline = trackView;
1029     KdenliveSettings::setCurrent_profile(doc->profilePath());
1030     if (m_renderWidget) m_renderWidget->setDocumentStandard(doc->getDocumentStandard());
1031     m_monitorManager->setTimecode(doc->timecode());
1032     doc->setRenderer(m_projectMonitor->render);
1033     m_commandStack->setActiveStack(doc->commandStack());
1034
1035     doc->updateAllProjectClips();
1036
1037     if (m_commandStack->isClean()) kDebug() << "////////////  UNDO STACK IS CLEAN";
1038     else  kDebug() << "////////////  UNDO STACK IS NOT CLEAN*******************";
1039
1040     //m_overView->setScene(trackView->projectScene());
1041     //m_overView->scale(m_overView->width() / trackView->duration(), m_overView->height() / (50 * trackView->tracksNumber()));
1042     //m_overView->fitInView(m_overView->itemAt(0, 50), Qt::KeepAspectRatio);
1043
1044     setCaption(doc->description());
1045     m_activeDocument = doc;
1046 }
1047
1048 void MainWindow::slotPreferences() {
1049     //An instance of your dialog could be already created and could be
1050     // cached, in which case you want to display the cached dialog
1051     // instead of creating another one
1052     if (KConfigDialog::showDialog("settings"))
1053         return;
1054
1055     // KConfigDialog didn't find an instance of this dialog, so lets
1056     // create it :
1057     KdenliveSettingsDialog* dialog = new KdenliveSettingsDialog(this);
1058     connect(dialog, SIGNAL(settingsChanged(const QString&)), this, SLOT(updateConfiguration()));
1059     dialog->show();
1060 }
1061
1062 void MainWindow::updateConfiguration() {
1063     //TODO: we should apply settings to all projects, not only the current one
1064     if (m_activeTimeline) {
1065         m_activeTimeline->refresh();
1066         m_activeTimeline->projectView()->checkAutoScroll();
1067         m_activeTimeline->projectView()->checkTrackHeight();
1068         if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
1069     }
1070     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
1071     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
1072     activateShuttleDevice();
1073
1074 }
1075
1076 void MainWindow::slotSwitchVideoThumbs() {
1077     KdenliveSettings::setVideothumbnails(!KdenliveSettings::videothumbnails());
1078     if (m_activeTimeline) {
1079         m_activeTimeline->refresh();
1080     }
1081     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
1082 }
1083
1084 void MainWindow::slotSwitchAudioThumbs() {
1085     KdenliveSettings::setAudiothumbnails(!KdenliveSettings::audiothumbnails());
1086     if (m_activeTimeline) {
1087         m_activeTimeline->refresh();
1088         m_activeTimeline->projectView()->checkAutoScroll();
1089         if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
1090     }
1091     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
1092 }
1093
1094 void MainWindow::slotSwitchMarkersComments() {
1095     KdenliveSettings::setShowmarkers(!KdenliveSettings::showmarkers());
1096     if (m_activeTimeline) {
1097         m_activeTimeline->refresh();
1098     }
1099     m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
1100 }
1101
1102 void MainWindow::slotSwitchSnap() {
1103     KdenliveSettings::setSnaptopoints(!KdenliveSettings::snaptopoints());
1104     m_buttonShowMarkers->setChecked(KdenliveSettings::snaptopoints());
1105 }
1106
1107
1108 void MainWindow::slotDeleteTimelineClip() {
1109     if (m_activeTimeline) {
1110         m_activeTimeline->projectView()->deleteSelectedClips();
1111     }
1112 }
1113
1114 void MainWindow::slotAddClipMarker() {
1115     if (m_activeTimeline) {
1116         m_activeTimeline->projectView()->slotAddClipMarker();
1117     }
1118 }
1119
1120 void MainWindow::slotDeleteClipMarker() {
1121     if (m_activeTimeline) {
1122         m_activeTimeline->projectView()->slotDeleteClipMarker();
1123     }
1124 }
1125
1126 void MainWindow::slotDeleteAllClipMarkers() {
1127     if (m_activeTimeline) {
1128         m_activeTimeline->projectView()->slotDeleteAllClipMarkers();
1129     }
1130 }
1131
1132 void MainWindow::slotEditClipMarker() {
1133     if (m_activeTimeline) {
1134         m_activeTimeline->projectView()->slotEditClipMarker();
1135     }
1136 }
1137
1138 void MainWindow::slotAddGuide() {
1139     if (m_activeTimeline)
1140         m_activeTimeline->projectView()->slotAddGuide();
1141 }
1142
1143 void MainWindow::slotEditGuide() {
1144     if (m_activeTimeline)
1145         m_activeTimeline->projectView()->slotEditGuide();
1146 }
1147
1148 void MainWindow::slotDeleteGuide() {
1149     if (m_activeTimeline)
1150         m_activeTimeline->projectView()->slotDeleteGuide();
1151 }
1152
1153 void MainWindow::slotDeleteAllGuides() {
1154     if (m_activeTimeline)
1155         m_activeTimeline->projectView()->slotDeleteAllGuides();
1156 }
1157
1158 void MainWindow::slotCutTimelineClip() {
1159     if (m_activeTimeline) {
1160         m_activeTimeline->projectView()->cutSelectedClips();
1161     }
1162 }
1163
1164 void MainWindow::slotAddProjectClip(KUrl url) {
1165     if (m_activeDocument)
1166         m_activeDocument->slotAddClipFile(url, QString());
1167 }
1168
1169 void MainWindow::slotAddTransition(QAction *result) {
1170     if (!result) return;
1171     QDomElement effect = transitions.getEffectByName(result->data().toString());
1172     if (m_activeTimeline) {
1173         m_activeTimeline->projectView()->slotAddTransitionToSelectedClips(effect);
1174     }
1175 }
1176
1177 void MainWindow::slotAddVideoEffect(QAction *result) {
1178     if (!result) return;
1179     QDomElement effect = videoEffects.getEffectByName(result->data().toString());
1180     slotAddEffect(effect);
1181 }
1182
1183 void MainWindow::slotAddAudioEffect(QAction *result) {
1184     if (!result) return;
1185     QDomElement effect = audioEffects.getEffectByName(result->data().toString());
1186     slotAddEffect(effect);
1187 }
1188
1189 void MainWindow::slotAddCustomEffect(QAction *result) {
1190     if (!result) return;
1191     QDomElement effect = customEffects.getEffectByName(result->data().toString());
1192     slotAddEffect(effect);
1193 }
1194
1195 void MainWindow::slotZoomIn() {
1196     m_zoomSlider->setValue(m_zoomSlider->value() - 1);
1197 }
1198
1199 void MainWindow::slotZoomOut() {
1200     m_zoomSlider->setValue(m_zoomSlider->value() + 1);
1201 }
1202
1203 void MainWindow::slotFitZoom() {
1204     if (m_activeTimeline) {
1205         m_zoomSlider->setValue(m_activeTimeline->fitZoom());
1206     }
1207 }
1208
1209 void MainWindow::slotGotProgressInfo(const QString &message, int progress) {
1210     statusProgressBar->setValue(progress);
1211     if (progress >= 0) {
1212         if (!message.isEmpty()) m_messageLabel->setMessage(message, InformationMessage);//statusLabel->setText(message);
1213         statusProgressBar->setVisible(true);
1214     } else {
1215         m_messageLabel->setMessage(QString(), DefaultMessage);
1216         statusProgressBar->setVisible(false);
1217     }
1218 }
1219
1220 void MainWindow::slotShowClipProperties(DocClipBase *clip) {
1221     if (clip->clipType() == TEXT) {
1222         m_activeDocument->editTextClip(clip->getProperty("xml"), clip->getId());
1223         return;
1224     }
1225     ClipProperties dia(clip, m_activeDocument->timecode(), m_activeDocument->fps(), this);
1226     connect(&dia, SIGNAL(addMarker(int, GenTime, QString)), m_activeTimeline->projectView(), SLOT(slotAddClipMarker(int, GenTime, QString)));
1227     if (dia.exec() == QDialog::Accepted) {
1228         m_projectList->slotUpdateClipProperties(dia.clipId(), dia.properties());
1229         if (dia.needsTimelineRefresh()) {
1230             // update clip occurences in timeline
1231             m_activeTimeline->projectView()->slotUpdateClip(dia.clipId());
1232         }
1233     }
1234 }
1235
1236 void MainWindow::customEvent(QEvent* e) {
1237     if (e->type() == QEvent::User) {
1238         // The timeline playing position changed...
1239         kDebug() << "RECIEVED JOG EVEMNT!!!";
1240     }
1241 }
1242 void MainWindow::slotActivateEffectStackView() {
1243     effectStack->raiseWindow(effectStackDock);
1244 }
1245
1246 void MainWindow::slotActivateTransitionView() {
1247     transitionConfig->raiseWindow(transitionConfigDock);
1248 }
1249
1250 void MainWindow::slotSnapRewind() {
1251     if (m_monitorManager->projectMonitorFocused()) {
1252         if (m_activeTimeline)
1253             m_activeTimeline->projectView()->slotSeekToPreviousSnap();
1254     }
1255 }
1256
1257 void MainWindow::slotSnapForward() {
1258     if (m_monitorManager->projectMonitorFocused()) {
1259         if (m_activeTimeline)
1260             m_activeTimeline->projectView()->slotSeekToNextSnap();
1261     }
1262 }
1263
1264 void MainWindow::slotClipStart() {
1265     if (m_monitorManager->projectMonitorFocused()) {
1266         if (m_activeTimeline)
1267             m_activeTimeline->projectView()->clipStart();
1268     }
1269 }
1270
1271 void MainWindow::slotClipEnd() {
1272     if (m_monitorManager->projectMonitorFocused()) {
1273         if (m_activeTimeline)
1274             m_activeTimeline->projectView()->clipEnd();
1275     }
1276 }
1277
1278 void MainWindow::slotChangeTool(QAction * action) {
1279     if (action == m_buttonSelectTool) slotSetTool(SELECTTOOL);
1280     else if (action == m_buttonRazorTool) slotSetTool(RAZORTOOL);
1281 }
1282
1283 void MainWindow::slotSetTool(PROJECTTOOL tool) {
1284     if (m_activeDocument && m_activeTimeline) {
1285         //m_activeDocument->setTool(tool);
1286         m_activeTimeline->projectView()->setTool(tool);
1287     }
1288 }
1289
1290 void MainWindow::slotCopy() {
1291     if (!m_activeDocument || !m_activeTimeline) return;
1292     m_activeTimeline->projectView()->copyClip();
1293 }
1294
1295 void MainWindow::slotPaste() {
1296     if (!m_activeDocument || !m_activeTimeline) return;
1297     m_activeTimeline->projectView()->pasteClip();
1298 }
1299
1300 void MainWindow::slotFind() {
1301     if (!m_activeDocument || !m_activeTimeline) return;
1302     m_projectSearch->setEnabled(false);
1303     m_findActivated = true;
1304     m_findString = QString();
1305     m_activeTimeline->projectView()->initSearchStrings();
1306     statusBar()->showMessage(i18n("Starting -- find text as you type"));
1307     m_findTimer.start(5000);
1308     qApp->installEventFilter(this);
1309 }
1310
1311 void MainWindow::slotFindNext() {
1312     if (m_activeTimeline && m_activeTimeline->projectView()->findNextString(m_findString)) {
1313         statusBar()->showMessage(i18n("Found : %1", m_findString));
1314     } else {
1315         statusBar()->showMessage(i18n("Reached end of project"));
1316     }
1317     m_findTimer.start(4000);
1318 }
1319
1320 void MainWindow::findAhead() {
1321     if (m_activeTimeline && m_activeTimeline->projectView()->findString(m_findString)) {
1322         m_projectSearchNext->setEnabled(true);
1323         statusBar()->showMessage(i18n("Found : %1", m_findString));
1324     } else {
1325         m_projectSearchNext->setEnabled(false);
1326         statusBar()->showMessage(i18n("Not found : %1", m_findString));
1327     }
1328 }
1329
1330 void MainWindow::findTimeout() {
1331     m_projectSearchNext->setEnabled(false);
1332     m_findActivated = false;
1333     m_findString = QString();
1334     statusBar()->showMessage(i18n("Find stopped"), 3000);
1335     if (m_activeTimeline) m_activeTimeline->projectView()->clearSearchStrings();
1336     m_projectSearch->setEnabled(true);
1337     removeEventFilter(this);
1338 }
1339
1340 void MainWindow::keyPressEvent(QKeyEvent *ke) {
1341     if (m_findActivated) {
1342         if (ke->key() == Qt::Key_Backspace) {
1343             m_findString = m_findString.left(m_findString.length() - 1);
1344
1345             if (!m_findString.isEmpty()) {
1346                 findAhead();
1347             } else {
1348                 findTimeout();
1349             }
1350
1351             m_findTimer.start(4000);
1352             ke->accept();
1353             return;
1354         } else if (ke->key() == Qt::Key_Escape) {
1355             findTimeout();
1356             ke->accept();
1357             return;
1358         } else if (ke->key() == Qt::Key_Space || !ke->text().trimmed().isEmpty()) {
1359             m_findString += ke->text();
1360
1361             findAhead();
1362
1363             m_findTimer.start(4000);
1364             ke->accept();
1365             return;
1366         }
1367     } else KXmlGuiWindow::keyPressEvent(ke);
1368 }
1369
1370 bool MainWindow::eventFilter(QObject *obj, QEvent *event) {
1371     if (m_findActivated) {
1372         if (event->type() == QEvent::ShortcutOverride) {
1373             QKeyEvent* ke = (QKeyEvent*) event;
1374             if (ke->text().trimmed().isEmpty()) return false;
1375             ke->accept();
1376             return true;
1377         } else return false;
1378     } else {
1379         // pass the event on to the parent class
1380         return QMainWindow::eventFilter(obj, event);
1381     }
1382 }
1383
1384 #include "mainwindow.moc"