]> git.sesse.net Git - kdenlive/blob - src/mainwindow.cpp
2b1eb67d66a55e12abbb63143c72626d9f6d38cd
[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 #include <stdlib.h>
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 #include <KFileItem>
52 #include <KNotification>
53 #include <KNotifyConfigWidget>
54 #include <knewstuff2/engine.h>
55 #include <knewstuff2/ui/knewstuffaction.h>
56
57 #include "mainwindow.h"
58 #include "kdenlivesettings.h"
59 #include "kdenlivesettingsdialog.h"
60 #include "initeffects.h"
61 #include "profilesdialog.h"
62 #include "projectsettings.h"
63 #include "events.h"
64 #include "clipmanager.h"
65 #include "projectlist.h"
66 #include "monitor.h"
67 #include "recmonitor.h"
68 #include "monitormanager.h"
69 #include "kdenlivedoc.h"
70 #include "trackview.h"
71 #include "customtrackview.h"
72 #include "effectslistview.h"
73 #include "effectstackview.h"
74 #include "transitionsettings.h"
75 #include "renderwidget.h"
76 #include "renderer.h"
77 #ifndef NO_JOGSHUTTLE
78 #include "jogshuttle.h"
79 #endif /* NO_JOGSHUTTLE */
80 #include "clipproperties.h"
81 #include "wizard.h"
82 #include "editclipcommand.h"
83 #include "titlewidget.h"
84 #include "markerdialog.h"
85 #include "clipitem.h"
86
87 static const int ID_STATUS_MSG = 1;
88 static const int ID_EDITMODE_MSG = 2;
89 static const int ID_TIMELINE_MSG = 3;
90 static const int ID_TIMELINE_BUTTONS = 5;
91 static const int ID_TIMELINE_POS = 6;
92 static const int ID_TIMELINE_FORMAT = 7;
93
94 namespace Mlt {
95 class Producer;
96 };
97
98 EffectsList MainWindow::videoEffects;
99 EffectsList MainWindow::audioEffects;
100 EffectsList MainWindow::customEffects;
101 EffectsList MainWindow::transitions;
102
103 MainWindow::MainWindow(const QString &MltPath, const KUrl & Url, QWidget *parent)
104         : KXmlGuiWindow(parent),
105         m_activeDocument(NULL), m_activeTimeline(NULL), m_renderWidget(NULL),
106 #ifndef NO_JOGSHUTTLE
107         m_jogProcess(NULL),
108 #endif /* NO_JOGSHUTTLE */
109         m_findActivated(false), m_initialized(false) {
110     setlocale(LC_NUMERIC, "POSIX");
111     setFont(KGlobalSettings::toolBarFont());
112     parseProfiles(MltPath);
113     m_commandStack = new QUndoGroup;
114     m_timelineArea = new KTabWidget(this);
115     m_timelineArea->setTabReorderingEnabled(true);
116     m_timelineArea->setTabBarHidden(true);
117
118     QToolButton *closeTabButton = new QToolButton;
119     connect(closeTabButton, SIGNAL(clicked()), this, SLOT(closeCurrentDocument()));
120     closeTabButton->setIcon(KIcon("tab-close"));
121     closeTabButton->adjustSize();
122     closeTabButton->setToolTip(i18n("Close the current tab"));
123     m_timelineArea->setCornerWidget(closeTabButton);
124     connect(m_timelineArea, SIGNAL(currentChanged(int)), this, SLOT(activateDocument()));
125
126     connect(&m_findTimer, SIGNAL(timeout()), this, SLOT(findTimeout()));
127     m_findTimer.setSingleShot(true);
128
129     initEffects::parseEffectFiles();
130     //initEffects::parseCustomEffectsFile();
131
132     m_monitorManager = new MonitorManager();
133
134     projectListDock = new QDockWidget(i18n("Project Tree"), this);
135     projectListDock->setObjectName("project_tree");
136     m_projectList = new ProjectList(this);
137     projectListDock->setWidget(m_projectList);
138     addDockWidget(Qt::TopDockWidgetArea, projectListDock);
139
140     effectListDock = new QDockWidget(i18n("Effect List"), this);
141     effectListDock->setObjectName("effect_list");
142     m_effectList = new EffectsListView();
143
144     //m_effectList = new KListWidget(this);
145     effectListDock->setWidget(m_effectList);
146     addDockWidget(Qt::TopDockWidgetArea, effectListDock);
147
148     effectStackDock = new QDockWidget(i18n("Effect Stack"), this);
149     effectStackDock->setObjectName("effect_stack");
150     effectStack = new EffectStackView(this);
151     effectStackDock->setWidget(effectStack);
152     addDockWidget(Qt::TopDockWidgetArea, effectStackDock);
153
154     transitionConfigDock = new QDockWidget(i18n("Transition"), this);
155     transitionConfigDock->setObjectName("transition");
156     transitionConfig = new TransitionSettings(this);
157     transitionConfigDock->setWidget(transitionConfig);
158     addDockWidget(Qt::TopDockWidgetArea, transitionConfigDock);
159
160     KdenliveSettings::setCurrent_profile(KdenliveSettings::default_profile());
161     m_fileOpenRecent = KStandardAction::openRecent(this, SLOT(openFile(const KUrl &)),
162                        actionCollection());
163     readOptions();
164
165     clipMonitorDock = new QDockWidget(i18n("Clip Monitor"), this);
166     clipMonitorDock->setObjectName("clip_monitor");
167     m_clipMonitor = new Monitor("clip", m_monitorManager, this);
168     clipMonitorDock->setWidget(m_clipMonitor);
169     addDockWidget(Qt::TopDockWidgetArea, clipMonitorDock);
170     //m_clipMonitor->stop();
171
172     projectMonitorDock = new QDockWidget(i18n("Project Monitor"), this);
173     projectMonitorDock->setObjectName("project_monitor");
174     m_projectMonitor = new Monitor("project", m_monitorManager, this);
175     projectMonitorDock->setWidget(m_projectMonitor);
176     addDockWidget(Qt::TopDockWidgetArea, projectMonitorDock);
177
178     recMonitorDock = new QDockWidget(i18n("Record Monitor"), this);
179     recMonitorDock->setObjectName("record_monitor");
180     m_recMonitor = new RecMonitor("record", this);
181     recMonitorDock->setWidget(m_recMonitor);
182     addDockWidget(Qt::TopDockWidgetArea, recMonitorDock);
183
184     connect(m_recMonitor, SIGNAL(addProjectClip(KUrl)), this, SLOT(slotAddProjectClip(KUrl)));
185     connect(m_recMonitor, SIGNAL(showConfigDialog(int, int)), this, SLOT(slotPreferences(int, int)));
186
187     undoViewDock = new QDockWidget(i18n("Undo History"), this);
188     undoViewDock->setObjectName("undo_history");
189     m_undoView = new QUndoView(this);
190     m_undoView->setCleanIcon(KIcon("edit-clear"));
191     m_undoView->setEmptyLabel(i18n("Clean"));
192     undoViewDock->setWidget(m_undoView);
193     m_undoView->setGroup(m_commandStack);
194     addDockWidget(Qt::TopDockWidgetArea, undoViewDock);
195
196     //overviewDock = new QDockWidget(i18n("Project Overview"), this);
197     //overviewDock->setObjectName("project_overview");
198     //m_overView = new CustomTrackView(NULL, NULL, this);
199     //overviewDock->setWidget(m_overView);
200     //addDockWidget(Qt::TopDockWidgetArea, overviewDock);
201
202     setupActions();
203     //tabifyDockWidget(projectListDock, effectListDock);
204     tabifyDockWidget(projectListDock, effectStackDock);
205     tabifyDockWidget(projectListDock, transitionConfigDock);
206     //tabifyDockWidget(projectListDock, undoViewDock);
207
208
209     tabifyDockWidget(clipMonitorDock, projectMonitorDock);
210     tabifyDockWidget(clipMonitorDock, recMonitorDock);
211     setCentralWidget(m_timelineArea);
212
213     setupGUI();
214     //kDebug() << factory() << " " << factory()->container("video_effects_menu", this);
215
216     m_projectMonitor->setupMenu(static_cast<QMenu*>(factory()->container("monitor_go", this)));
217     m_clipMonitor->setupMenu(static_cast<QMenu*>(factory()->container("monitor_go", this)), static_cast<QMenu*>(factory()->container("marker_menu", this)));
218
219     // build effects menus
220     QAction *action;
221     QMenu *videoEffectsMenu = static_cast<QMenu*>(factory()->container("video_effects_menu", this));
222
223     QStringList effectInfo;
224     QMap<QString, QStringList> effectsList;
225     for (int ix = 0; ix < videoEffects.count(); ix++) {
226         effectInfo = videoEffects.effectIdInfo(ix);
227         effectsList.insert(effectInfo.at(0).toLower(), effectInfo);
228     }
229
230     foreach(QStringList value, effectsList) {
231         action = new QAction(value.at(0), this);
232         action->setData(value);
233         videoEffectsMenu->addAction(action);
234     }
235
236     QMenu *audioEffectsMenu = static_cast<QMenu*>(factory()->container("audio_effects_menu", this));
237
238
239     effectsList.clear();
240     for (int ix = 0; ix < audioEffects.count(); ix++) {
241         effectInfo = audioEffects.effectIdInfo(ix);
242         effectsList.insert(effectInfo.at(0).toLower(), effectInfo);
243     }
244
245     foreach(QStringList value, effectsList) {
246         action = new QAction(value.at(0), this);
247         action->setData(value);
248         audioEffectsMenu->addAction(action);
249     }
250
251     m_customEffectsMenu = static_cast<QMenu*>(factory()->container("custom_effects_menu", this));
252
253     if (customEffects.isEmpty()) m_customEffectsMenu->setEnabled(false);
254     else m_customEffectsMenu->setEnabled(true);
255
256     effectsList.clear();
257     for (int ix = 0; ix < customEffects.count(); ix++) {
258         effectInfo = customEffects.effectIdInfo(ix);
259         effectsList.insert(effectInfo.at(0).toLower(), effectInfo);
260     }
261
262     foreach(QStringList value, effectsList) {
263         action = new QAction(value.at(0), this);
264         action->setData(value);
265         m_customEffectsMenu->addAction(action);
266     }
267
268     QMenu *newEffect = new QMenu(this);
269     newEffect->addMenu(videoEffectsMenu);
270     newEffect->addMenu(audioEffectsMenu);
271     newEffect->addMenu(m_customEffectsMenu);
272     effectStack->setMenu(newEffect);
273
274
275     QMenu *viewMenu = static_cast<QMenu*>(factory()->container("dockwindows", this));
276     const QList<QAction *> viewActions = createPopupMenu()->actions();
277     viewMenu->insertActions(NULL, viewActions);
278
279     connect(videoEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddVideoEffect(QAction *)));
280     connect(audioEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddAudioEffect(QAction *)));
281     connect(m_customEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddCustomEffect(QAction *)));
282
283     m_timelineContextMenu = new QMenu(this);
284     m_timelineContextClipMenu = new QMenu(this);
285     m_timelineContextTransitionMenu = new QMenu(this);
286
287
288     QMenu *transitionsMenu = new QMenu(i18n("Add Transition"), this);
289     QStringList effects = transitions.effectNames();
290
291     effectsList.clear();
292     for (int ix = 0; ix < transitions.count(); ix++) {
293         effectInfo = transitions.effectIdInfo(ix);
294         effectsList.insert(effectInfo.at(0).toLower(), effectInfo);
295     }
296     foreach(QStringList value, effectsList) {
297         action = new QAction(value.at(0), this);
298         action->setData(value);
299         transitionsMenu->addAction(action);
300     }
301     connect(transitionsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddTransition(QAction *)));
302
303     m_timelineContextMenu->addAction(actionCollection()->action("insert_space"));
304     m_timelineContextMenu->addAction(actionCollection()->action("delete_space"));
305     m_timelineContextMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Paste)));
306
307     m_timelineContextClipMenu->addAction(actionCollection()->action("delete_timeline_clip"));
308     m_timelineContextClipMenu->addAction(actionCollection()->action("change_clip_speed"));
309     m_timelineContextClipMenu->addAction(actionCollection()->action("cut_timeline_clip"));
310     m_timelineContextClipMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Copy)));
311     m_timelineContextClipMenu->addAction(actionCollection()->action("paste_effects"));
312
313     QMenu *markersMenu = (QMenu*)(factory()->container("marker_menu", this));
314     m_timelineContextClipMenu->addMenu(markersMenu);
315     m_timelineContextClipMenu->addMenu(transitionsMenu);
316     m_timelineContextClipMenu->addMenu(videoEffectsMenu);
317     m_timelineContextClipMenu->addMenu(audioEffectsMenu);
318     //TODO: re-enable custom effects menu when it is implemented
319     m_timelineContextClipMenu->addMenu(m_customEffectsMenu);
320
321     m_timelineContextTransitionMenu->addAction(actionCollection()->action("delete_timeline_clip"));
322     m_timelineContextTransitionMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Copy)));
323
324     m_timelineContextTransitionMenu->addAction(actionCollection()->action("auto_transition"));
325
326     connect(projectMonitorDock, SIGNAL(visibilityChanged(bool)), m_projectMonitor, SLOT(refreshMonitor(bool)));
327     connect(clipMonitorDock, SIGNAL(visibilityChanged(bool)), m_clipMonitor, SLOT(refreshMonitor(bool)));
328     //connect(m_monitorManager, SIGNAL(connectMonitors()), this, SLOT(slotConnectMonitors()));
329     connect(m_monitorManager, SIGNAL(raiseClipMonitor(bool)), this, SLOT(slotRaiseMonitor(bool)));
330     connect(m_effectList, SIGNAL(addEffect(QDomElement)), this, SLOT(slotAddEffect(QDomElement)));
331     connect(m_effectList, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
332
333     m_monitorManager->initMonitors(m_clipMonitor, m_projectMonitor);
334     slotConnectMonitors();
335
336     // Open or create a file.  Command line argument passed in Url has
337     // precedence, then "openlastproject", then just a plain empty file.
338     // If opening Url fails, openlastproject will _not_ be used.
339     if (!Url.isEmpty()) {
340         openFile(Url);
341     } else {
342         if (KdenliveSettings::openlastproject()) {
343             openLastFile();
344         }
345     }
346     if (m_timelineArea->count() == 0) {
347         newFile(false);
348     }
349
350 #ifndef NO_JOGSHUTTLE
351     activateShuttleDevice();
352 #endif /* NO_JOGSHUTTLE */
353     projectListDock->raise();
354 }
355
356 void MainWindow::queryQuit() {
357     kDebug() << "----- SAVING CONFUIG";
358     if (queryClose()) kapp->quit();
359 }
360
361 //virtual
362 bool MainWindow::queryClose() {
363     saveOptions();
364     if (m_monitorManager) m_monitorManager->stopActiveMonitor();
365     if (m_activeDocument && m_activeDocument->isModified()) {
366         switch (KMessageBox::warningYesNoCancel(this, i18n("Save changes to document ?"))) {
367         case KMessageBox::Yes :
368             // save document here. If saving fails, return false;
369             return saveFile();
370         case KMessageBox::No :
371             return true;
372         default: // cancel
373             return false;
374         }
375     }
376     return true;
377 }
378
379 void MainWindow::saveProperties(KConfig*) {
380     // save properties here,used by session management
381     saveFile();
382 }
383
384
385 void MainWindow::readProperties(KConfig *config) {
386     // read properties here,used by session management
387     QString Lastproject = config->group("Recent Files").readPathEntry("File1", QString());
388     openFile(KUrl(Lastproject));
389 }
390
391 void MainWindow::slotReloadEffects() {
392     initEffects::parseCustomEffectsFile();
393     m_customEffectsMenu->clear();
394     const QStringList effects = customEffects.effectNames();
395     QAction *action;
396     if (effects.isEmpty()) m_customEffectsMenu->setEnabled(false);
397     else m_customEffectsMenu->setEnabled(true);
398
399     foreach(const QString &name, effects) {
400         action = new QAction(name, this);
401         action->setData(name);
402         m_customEffectsMenu->addAction(action);
403     }
404     m_effectList->reloadEffectList();
405 }
406
407 #ifndef NO_JOGSHUTTLE
408 void MainWindow::activateShuttleDevice() {
409     if (m_jogProcess) delete m_jogProcess;
410     m_jogProcess = NULL;
411     if (KdenliveSettings::enableshuttle() == false) return;
412     m_jogProcess = new JogShuttle(KdenliveSettings::shuttledevice());
413     connect(m_jogProcess, SIGNAL(rewind1()), m_monitorManager, SLOT(slotRewindOneFrame()));
414     connect(m_jogProcess, SIGNAL(forward1()), m_monitorManager, SLOT(slotForwardOneFrame()));
415     connect(m_jogProcess, SIGNAL(rewind(double)), m_monitorManager, SLOT(slotRewind(double)));
416     connect(m_jogProcess, SIGNAL(forward(double)), m_monitorManager, SLOT(slotForward(double)));
417     connect(m_jogProcess, SIGNAL(stop()), m_monitorManager, SLOT(slotPlay()));
418     connect(m_jogProcess, SIGNAL(button(int)), this, SLOT(slotShuttleButton(int)));
419 }
420
421 void MainWindow::slotShuttleButton(int code) {
422     switch (code) {
423     case 5:
424         slotShuttleAction(KdenliveSettings::shuttle1());
425         break;
426     case 6:
427         slotShuttleAction(KdenliveSettings::shuttle2());
428         break;
429     case 7:
430         slotShuttleAction(KdenliveSettings::shuttle3());
431         break;
432     case 8:
433         slotShuttleAction(KdenliveSettings::shuttle4());
434         break;
435     case 9:
436         slotShuttleAction(KdenliveSettings::shuttle5());
437         break;
438     }
439 }
440
441 void MainWindow::slotShuttleAction(int code) {
442     switch (code) {
443     case 0:
444         return;
445     case 1:
446         m_monitorManager->slotPlay();
447         break;
448     default:
449         m_monitorManager->slotPlay();
450         break;
451     }
452 }
453 #endif /* NO_JOGSHUTTLE */
454
455 void MainWindow::configureNotifications() {
456     KNotifyConfigWidget::configure(this);
457 }
458
459 void MainWindow::slotFullScreen() {
460     KToggleFullScreenAction::setFullScreen(this, actionCollection()->action("fullscreen")->isChecked());
461 }
462
463 void MainWindow::slotAddEffect(QDomElement effect, GenTime pos, int track) {
464     if (!m_activeDocument) return;
465     if (effect.isNull()) {
466         kDebug() << "--- ERROR, TRYING TO APPEND NULL EFFECT";
467         return;
468     }
469     TrackView *currentTimeLine = (TrackView *) m_timelineArea->currentWidget();
470     currentTimeLine->projectView()->slotAddEffect(effect.cloneNode().toElement(), pos, track);
471 }
472
473 void MainWindow::slotRaiseMonitor(bool clipMonitor) {
474     if (clipMonitor) clipMonitorDock->raise();
475     else projectMonitorDock->raise();
476 }
477
478 void MainWindow::slotSetClipDuration(const QString &id, int duration) {
479     if (!m_activeDocument) return;
480     m_activeDocument->setProducerDuration(id, duration);
481 }
482
483 void MainWindow::slotConnectMonitors() {
484
485     m_projectList->setRenderer(m_clipMonitor->render);
486     connect(m_projectList, SIGNAL(receivedClipDuration(const QString &, int)), this, SLOT(slotSetClipDuration(const QString &, int)));
487     connect(m_projectList, SIGNAL(showClipProperties(DocClipBase *)), this, SLOT(slotShowClipProperties(DocClipBase *)));
488     connect(m_projectList, SIGNAL(getFileProperties(const QDomElement &, const QString &)), m_clipMonitor->render, SLOT(getFileProperties(const QDomElement &, const QString &)));
489     connect(m_clipMonitor->render, SIGNAL(replyGetImage(const QString &, int, const QPixmap &, int, int)), m_projectList, SLOT(slotReplyGetImage(const QString &, int, const QPixmap &, int, int)));
490     connect(m_clipMonitor->render, SIGNAL(replyGetFileProperties(const QString &, Mlt::Producer*, const QMap < QString, QString > &, const QMap < QString, QString > &)), m_projectList, SLOT(slotReplyGetFileProperties(const QString &, Mlt::Producer*, const QMap < QString, QString > &, const QMap < QString, QString > &)));
491
492     connect(m_clipMonitor->render, SIGNAL(removeInvalidClip(const QString &)), m_projectList, SLOT(slotRemoveInvalidClip(const QString &)));
493
494     connect(m_clipMonitor, SIGNAL(refreshClipThumbnail(const QString &)), m_projectList, SLOT(slotRefreshClipThumbnail(const QString &)));
495
496     connect(m_clipMonitor, SIGNAL(adjustMonitorSize()), this, SLOT(slotAdjustClipMonitor()));
497     connect(m_projectMonitor, SIGNAL(adjustMonitorSize()), this, SLOT(slotAdjustProjectMonitor()));
498
499     connect(m_clipMonitor, SIGNAL(saveZone(Render *, QPoint)), this, SLOT(slotSaveZone(Render *, QPoint)));
500     connect(m_projectMonitor, SIGNAL(saveZone(Render *, QPoint)), this, SLOT(slotSaveZone(Render *, QPoint)));
501 }
502
503 void MainWindow::slotAdjustClipMonitor() {
504     clipMonitorDock->updateGeometry();
505     clipMonitorDock->adjustSize();
506     m_clipMonitor->resetSize();
507 }
508
509 void MainWindow::slotAdjustProjectMonitor() {
510     projectMonitorDock->updateGeometry();
511     projectMonitorDock->adjustSize();
512     m_projectMonitor->resetSize();
513 }
514
515 void MainWindow::setupActions() {
516
517     KActionCollection* collection = actionCollection();
518     m_timecodeFormat = new KComboBox(this);
519     m_timecodeFormat->addItem(i18n("hh:mm:ss::ff"));
520     m_timecodeFormat->addItem(i18n("Frames"));
521
522     statusProgressBar = new QProgressBar(this);
523     statusProgressBar->setMinimum(0);
524     statusProgressBar->setMaximum(100);
525     statusProgressBar->setMaximumWidth(150);
526     statusProgressBar->setVisible(false);
527
528     QWidget *w = new QWidget;
529
530     QHBoxLayout *layout = new QHBoxLayout;
531     w->setLayout(layout);
532     layout->setContentsMargins(5, 0, 5, 0);
533     QToolBar *toolbar = new QToolBar("statusToolBar", this);
534
535
536     m_toolGroup = new QActionGroup(this);
537
538     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;}";
539
540     m_buttonSelectTool = new KAction(KIcon("kdenlive-select-tool"), i18n("Selection tool"), this);
541     toolbar->addAction(m_buttonSelectTool);
542     m_buttonSelectTool->setCheckable(true);
543     m_buttonSelectTool->setChecked(true);
544
545     m_buttonRazorTool = new KAction(KIcon("edit-cut"), i18n("Razor tool"), this);
546     toolbar->addAction(m_buttonRazorTool);
547     m_buttonRazorTool->setCheckable(true);
548     m_buttonRazorTool->setChecked(false);
549
550     m_buttonSpacerTool = new KAction(KIcon("kdenlive-spacer-tool"), i18n("Spacer tool"), this);
551     toolbar->addAction(m_buttonSpacerTool);
552     m_buttonSpacerTool->setCheckable(true);
553     m_buttonSpacerTool->setChecked(false);
554
555     m_toolGroup->addAction(m_buttonSelectTool);
556     m_toolGroup->addAction(m_buttonRazorTool);
557     m_toolGroup->addAction(m_buttonSpacerTool);
558     m_toolGroup->setExclusive(true);
559     toolbar->setToolButtonStyle(Qt::ToolButtonIconOnly);
560
561     QWidget * actionWidget;
562     actionWidget = toolbar->widgetForAction(m_buttonSelectTool);
563     actionWidget->setMaximumWidth(24);
564     actionWidget->setMinimumHeight(17);
565
566     actionWidget = toolbar->widgetForAction(m_buttonRazorTool);
567     actionWidget->setMaximumWidth(24);
568     actionWidget->setMinimumHeight(17);
569
570     actionWidget = toolbar->widgetForAction(m_buttonSpacerTool);
571     actionWidget->setMaximumWidth(24);
572     actionWidget->setMinimumHeight(17);
573
574     toolbar->setStyleSheet(style1);
575     connect(m_toolGroup, SIGNAL(triggered(QAction *)), this, SLOT(slotChangeTool(QAction *)));
576
577     toolbar->addSeparator();
578     m_buttonFitZoom = new KAction(KIcon("zoom-fit-best"), i18n("Fit zoom to project"), this);
579     toolbar->addAction(m_buttonFitZoom);
580     m_buttonFitZoom->setCheckable(false);
581     connect(m_buttonFitZoom, SIGNAL(triggered()), this, SLOT(slotFitZoom()));
582
583     actionWidget = toolbar->widgetForAction(m_buttonFitZoom);
584     actionWidget->setMaximumWidth(24);
585     actionWidget->setMinimumHeight(17);
586
587     m_zoomSlider = new QSlider(Qt::Horizontal, this);
588     m_zoomSlider->setMaximum(13);
589     m_zoomSlider->setPageStep(1);
590
591     m_zoomSlider->setMaximumWidth(150);
592     m_zoomSlider->setMinimumWidth(100);
593
594     const int contentHeight = QFontMetrics(w->font()).height() + 8;
595
596     QString style = "QSlider::groove:horizontal { background-color: rgba(230, 230, 230, 220);border: 1px solid #999999;height: 8px;border-radius: 3px;margin-top:3px }";
597     style.append("QSlider::handle:horizontal {  background-color: white; border: 1px solid #999999;width: 9px;margin: -2px 0;border-radius: 3px; }");
598
599     m_zoomSlider->setStyleSheet(style);
600
601     //m_zoomSlider->height() + 5;
602     statusBar()->setMinimumHeight(contentHeight);
603
604
605     toolbar->addWidget(m_zoomSlider);
606
607     m_buttonVideoThumbs = new KAction(KIcon("kdenlive-show-videothumb"), i18n("Show video thumbnails"), this);
608     toolbar->addAction(m_buttonVideoThumbs);
609     m_buttonVideoThumbs->setCheckable(true);
610     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
611     connect(m_buttonVideoThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchVideoThumbs()));
612
613     m_buttonAudioThumbs = new KAction(KIcon("kdenlive-show-audiothumb"), i18n("Show audio thumbnails"), this);
614     toolbar->addAction(m_buttonAudioThumbs);
615     m_buttonAudioThumbs->setCheckable(true);
616     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
617     connect(m_buttonAudioThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchAudioThumbs()));
618
619     m_buttonShowMarkers = new KAction(KIcon("kdenlive-show-markers"), i18n("Show markers comments"), this);
620     toolbar->addAction(m_buttonShowMarkers);
621     m_buttonShowMarkers->setCheckable(true);
622     m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
623     connect(m_buttonShowMarkers, SIGNAL(triggered()), this, SLOT(slotSwitchMarkersComments()));
624
625     m_buttonSnap = new KAction(KIcon("kdenlive-snap"), i18n("Snap"), this);
626     toolbar->addAction(m_buttonSnap);
627     m_buttonSnap->setCheckable(true);
628     m_buttonSnap->setChecked(KdenliveSettings::snaptopoints());
629     connect(m_buttonSnap, SIGNAL(triggered()), this, SLOT(slotSwitchSnap()));
630     layout->addWidget(toolbar);
631
632
633     actionWidget = toolbar->widgetForAction(m_buttonVideoThumbs);
634     actionWidget->setMaximumWidth(24);
635     actionWidget->setMinimumHeight(17);
636
637     actionWidget = toolbar->widgetForAction(m_buttonAudioThumbs);
638     actionWidget->setMaximumWidth(24);
639     actionWidget->setMinimumHeight(17);
640
641     actionWidget = toolbar->widgetForAction(m_buttonShowMarkers);
642     actionWidget->setMaximumWidth(24);
643     actionWidget->setMinimumHeight(17);
644
645     actionWidget = toolbar->widgetForAction(m_buttonSnap);
646     actionWidget->setMaximumWidth(24);
647     actionWidget->setMinimumHeight(17);
648
649     m_messageLabel = new StatusBarMessageLabel(this);
650     m_messageLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding);
651
652     statusBar()->addWidget(m_messageLabel, 10);
653     statusBar()->addWidget(statusProgressBar, 0);
654     statusBar()->insertPermanentWidget(ID_TIMELINE_BUTTONS, w);
655     statusBar()->insertPermanentFixedItem("00:00:00:00", ID_TIMELINE_POS);
656     statusBar()->insertPermanentWidget(ID_TIMELINE_FORMAT, m_timecodeFormat);
657     statusBar()->setMaximumHeight(statusBar()->font().pointSize() * 4);
658     m_messageLabel->hide();
659
660     collection->addAction("select_tool", m_buttonSelectTool);
661     collection->addAction("razor_tool", m_buttonRazorTool);
662     collection->addAction("spacer_tool", m_buttonSpacerTool);
663
664     collection->addAction("show_video_thumbs", m_buttonVideoThumbs);
665     collection->addAction("show_audio_thumbs", m_buttonAudioThumbs);
666     collection->addAction("show_markers", m_buttonShowMarkers);
667     collection->addAction("snap", m_buttonSnap);
668     collection->addAction("zoom_fit", m_buttonFitZoom);
669
670     KAction* zoomIn = new KAction(KIcon("zoom-in"), i18n("Zoom In"), this);
671     collection->addAction("zoom_in", zoomIn);
672     connect(zoomIn, SIGNAL(triggered(bool)), this, SLOT(slotZoomIn()));
673     zoomIn->setShortcut(Qt::CTRL + Qt::Key_Plus);
674
675     KAction* zoomOut = new KAction(KIcon("zoom-out"), i18n("Zoom Out"), this);
676     collection->addAction("zoom_out", zoomOut);
677     connect(zoomOut, SIGNAL(triggered(bool)), this, SLOT(slotZoomOut()));
678     zoomOut->setShortcut(Qt::CTRL + Qt::Key_Minus);
679
680     m_projectSearch = new KAction(KIcon("edit-find"), i18n("Find"), this);
681     collection->addAction("project_find", m_projectSearch);
682     connect(m_projectSearch, SIGNAL(triggered(bool)), this, SLOT(slotFind()));
683     m_projectSearch->setShortcut(Qt::Key_Slash);
684
685     m_projectSearchNext = new KAction(KIcon("go-down-search"), i18n("Find Next"), this);
686     collection->addAction("project_find_next", m_projectSearchNext);
687     connect(m_projectSearchNext, SIGNAL(triggered(bool)), this, SLOT(slotFindNext()));
688     m_projectSearchNext->setShortcut(Qt::Key_F3);
689     m_projectSearchNext->setEnabled(false);
690
691     KAction* profilesAction = new KAction(KIcon("document-new"), i18n("Manage Profiles"), this);
692     collection->addAction("manage_profiles", profilesAction);
693     connect(profilesAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProfiles()));
694
695     KAction* fileGHNS = KNS::standardAction(i18n("Download New Lumas..."), this, SLOT(slotGetNewStuff()), actionCollection(), "get_new_stuff");
696
697     KAction* wizAction = new KAction(KIcon("configure"), i18n("Run Config Wizard"), this);
698     collection->addAction("run_wizard", wizAction);
699     connect(wizAction, SIGNAL(triggered(bool)), this, SLOT(slotRunWizard()));
700
701     KAction* projectAction = new KAction(KIcon("configure"), i18n("Project Settings"), this);
702     collection->addAction("project_settings", projectAction);
703     connect(projectAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProjectSettings()));
704
705     KAction* projectRender = new KAction(KIcon("media-record"), i18n("Render"), this);
706     collection->addAction("project_render", projectRender);
707     projectRender->setShortcut(Qt::CTRL + Qt::Key_Return);
708     connect(projectRender, SIGNAL(triggered(bool)), this, SLOT(slotRenderProject()));
709
710     KAction* monitorPlay = new KAction(KIcon("media-playback-start"), i18n("Play"), this);
711     KShortcut playShortcut;
712     playShortcut.setPrimary(Qt::Key_Space);
713     playShortcut.setAlternate(Qt::Key_K);
714     monitorPlay->setShortcut(playShortcut);
715     collection->addAction("monitor_play", monitorPlay);
716     connect(monitorPlay, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotPlay()));
717
718     KAction *markIn = collection->addAction("mark_in");
719     markIn->setText(i18n("Set In Point"));
720     markIn->setShortcut(Qt::Key_I);
721     connect(markIn, SIGNAL(triggered(bool)), this, SLOT(slotSetInPoint()));
722
723     KAction *markOut = collection->addAction("mark_out");
724     markOut->setText(i18n("Set Out Point"));
725     markOut->setShortcut(Qt::Key_O);
726     connect(markOut, SIGNAL(triggered(bool)), this, SLOT(slotSetOutPoint()));
727
728     KAction* monitorSeekBackward = new KAction(KIcon("media-seek-backward"), i18n("Rewind"), this);
729     monitorSeekBackward->setShortcut(Qt::Key_J);
730     collection->addAction("monitor_seek_backward", monitorSeekBackward);
731     connect(monitorSeekBackward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewind()));
732
733     KAction* monitorSeekBackwardOneFrame = new KAction(KIcon("media-skip-backward"), i18n("Rewind 1 Frame"), this);
734     monitorSeekBackwardOneFrame->setShortcut(Qt::Key_Left);
735     collection->addAction("monitor_seek_backward-one-frame", monitorSeekBackwardOneFrame);
736     connect(monitorSeekBackwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewindOneFrame()));
737
738     KAction* monitorSeekBackwardOneSecond = new KAction(KIcon("media-skip-backward"), i18n("Rewind 1 Second"), this);
739     monitorSeekBackwardOneSecond->setShortcut(Qt::SHIFT + Qt::Key_Left);
740     collection->addAction("monitor_seek_backward-one-second", monitorSeekBackwardOneSecond);
741     connect(monitorSeekBackwardOneSecond, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewindOneSecond()));
742
743     KAction* monitorSeekSnapBackward = new KAction(KIcon("media-seek-backward"), i18n("Go to Previous Snap Point"), this);
744     monitorSeekSnapBackward->setShortcut(Qt::ALT + Qt::Key_Left);
745     collection->addAction("monitor_seek_snap_backward", monitorSeekSnapBackward);
746     connect(monitorSeekSnapBackward, SIGNAL(triggered(bool)), this, SLOT(slotSnapRewind()));
747
748     KAction* monitorSeekForward = new KAction(KIcon("media-seek-forward"), i18n("Forward"), this);
749     monitorSeekForward->setShortcut(Qt::Key_L);
750     collection->addAction("monitor_seek_forward", monitorSeekForward);
751     connect(monitorSeekForward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForward()));
752
753     KAction* clipStart = new KAction(KIcon("media-seek-backward"), i18n("Go to Clip Start"), this);
754     clipStart->setShortcut(Qt::Key_Home);
755     collection->addAction("seek_clip_start", clipStart);
756     connect(clipStart, SIGNAL(triggered(bool)), this, SLOT(slotClipStart()));
757
758     KAction* clipEnd = new KAction(KIcon("media-seek-forward"), i18n("Go to Clip End"), this);
759     clipEnd->setShortcut(Qt::Key_End);
760     collection->addAction("seek_clip_end", clipEnd);
761     connect(clipEnd, SIGNAL(triggered(bool)), this, SLOT(slotClipEnd()));
762
763     KAction* projectStart = new KAction(KIcon("go-first"), i18n("Go to Project Start"), this);
764     projectStart->setShortcut(Qt::CTRL + Qt::Key_Home);
765     collection->addAction("seek_start", projectStart);
766     connect(projectStart, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotStart()));
767
768     KAction* projectEnd = new KAction(KIcon("go-last"), i18n("Go to Project End"), this);
769     projectEnd->setShortcut(Qt::CTRL + Qt::Key_End);
770     collection->addAction("seek_end", projectEnd);
771     connect(projectEnd, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotEnd()));
772
773     KAction* monitorSeekForwardOneFrame = new KAction(KIcon("media-skip-forward"), i18n("Forward 1 Frame"), this);
774     monitorSeekForwardOneFrame->setShortcut(Qt::Key_Right);
775     collection->addAction("monitor_seek_forward-one-frame", monitorSeekForwardOneFrame);
776     connect(monitorSeekForwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForwardOneFrame()));
777
778     KAction* monitorSeekForwardOneSecond = new KAction(KIcon("media-skip-forward"), i18n("Forward 1 Second"), this);
779     monitorSeekForwardOneSecond->setShortcut(Qt::SHIFT + Qt::Key_Right);
780     collection->addAction("monitor_seek_forward-one-second", monitorSeekForwardOneSecond);
781     connect(monitorSeekForwardOneSecond, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForwardOneSecond()));
782
783     KAction* monitorSeekSnapForward = new KAction(KIcon("media-seek-forward"), i18n("Go to Next Snap Point"), this);
784     monitorSeekSnapForward->setShortcut(Qt::ALT + Qt::Key_Right);
785     collection->addAction("monitor_seek_snap_forward", monitorSeekSnapForward);
786     connect(monitorSeekSnapForward, SIGNAL(triggered(bool)), this, SLOT(slotSnapForward()));
787
788     KAction* deleteTimelineClip = new KAction(KIcon("edit-delete"), i18n("Delete Selected Item"), this);
789     deleteTimelineClip->setShortcut(Qt::Key_Delete);
790     collection->addAction("delete_timeline_clip", deleteTimelineClip);
791     connect(deleteTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotDeleteTimelineClip()));
792
793     KAction* editTimelineClipSpeed = new KAction(i18n("Change Clip Speed"), this);
794     collection->addAction("change_clip_speed", editTimelineClipSpeed);
795     connect(editTimelineClipSpeed, SIGNAL(triggered(bool)), this, SLOT(slotChangeClipSpeed()));
796
797     KAction *stickTransition = collection->addAction("auto_transition");
798     stickTransition->setData(QString("auto"));
799     stickTransition->setCheckable(true);
800     stickTransition->setEnabled(false);
801     stickTransition->setText(i18n("Automatic Transition"));
802     connect(stickTransition, SIGNAL(triggered(bool)), this, SLOT(slotAutoTransition()));
803
804     KAction* cutTimelineClip = new KAction(KIcon("edit-cut"), i18n("Cut Clip"), this);
805     cutTimelineClip->setShortcut(Qt::SHIFT + Qt::Key_R);
806     collection->addAction("cut_timeline_clip", cutTimelineClip);
807     connect(cutTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotCutTimelineClip()));
808
809     KAction* addClipMarker = new KAction(KIcon("bookmark-new"), i18n("Add Marker"), this);
810     collection->addAction("add_clip_marker", addClipMarker);
811     connect(addClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotAddClipMarker()));
812
813     KAction* deleteClipMarker = new KAction(KIcon("edit-delete"), i18n("Delete Marker"), this);
814     collection->addAction("delete_clip_marker", deleteClipMarker);
815     connect(deleteClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotDeleteClipMarker()));
816
817     KAction* deleteAllClipMarkers = new KAction(KIcon("edit-delete"), i18n("Delete All Markers"), this);
818     collection->addAction("delete_all_clip_markers", deleteAllClipMarkers);
819     connect(deleteAllClipMarkers, SIGNAL(triggered(bool)), this, SLOT(slotDeleteAllClipMarkers()));
820
821     KAction* editClipMarker = new KAction(KIcon("document-properties"), i18n("Edit Marker"), this);
822     collection->addAction("edit_clip_marker", editClipMarker);
823     connect(editClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotEditClipMarker()));
824
825     KAction *insertSpace = new KAction(KIcon(), i18n("Insert Space"), this);
826     collection->addAction("insert_space", insertSpace);
827     connect(insertSpace, SIGNAL(triggered()), this, SLOT(slotInsertSpace()));
828
829     KAction *removeSpace = new KAction(KIcon(), i18n("Remove Space"), this);
830     collection->addAction("delete_space", removeSpace);
831     connect(removeSpace, SIGNAL(triggered()), this, SLOT(slotRemoveSpace()));
832
833     KAction *insertTrack = new KAction(KIcon(), i18n("Insert Track"), this);
834     collection->addAction("insert_track", insertTrack);
835     connect(insertTrack, SIGNAL(triggered()), this, SLOT(slotInsertTrack()));
836
837     KAction *deleteTrack = new KAction(KIcon(), i18n("Delete Track"), this);
838     collection->addAction("delete_track", deleteTrack);
839     connect(deleteTrack, SIGNAL(triggered()), this, SLOT(slotDeleteTrack()));
840
841     KAction *changeTrack = new KAction(KIcon(), i18n("Change Track"), this);
842     collection->addAction("change_track", changeTrack);
843     connect(changeTrack, SIGNAL(triggered()), this, SLOT(slotChangeTrack()));
844
845     KAction *addGuide = new KAction(KIcon("document-new"), i18n("Add Guide"), this);
846     collection->addAction("add_guide", addGuide);
847     connect(addGuide, SIGNAL(triggered()), this, SLOT(slotAddGuide()));
848
849     QAction *delGuide = new KAction(KIcon("edit-delete"), i18n("Delete Guide"), this);
850     collection->addAction("delete_guide", delGuide);
851     connect(delGuide, SIGNAL(triggered()), this, SLOT(slotDeleteGuide()));
852
853     QAction *editGuide = new KAction(KIcon("document-properties"), i18n("Edit Guide"), this);
854     collection->addAction("edit_guide", editGuide);
855     connect(editGuide, SIGNAL(triggered()), this, SLOT(slotEditGuide()));
856
857     QAction *delAllGuides = new KAction(KIcon("edit-delete"), i18n("Delete All Guides"), this);
858     collection->addAction("delete_all_guides", delAllGuides);
859     connect(delAllGuides, SIGNAL(triggered()), this, SLOT(slotDeleteAllGuides()));
860
861     QAction *pasteEffects = new KAction(KIcon("edit-paste"), i18n("Paste Effects"), this);
862     collection->addAction("paste_effects", pasteEffects);
863     connect(pasteEffects , SIGNAL(triggered()), this, SLOT(slotPasteEffects()));
864
865     m_closeAction = KStandardAction::close(this, SLOT(closeCurrentDocument()), collection);
866
867     KStandardAction::quit(this, SLOT(queryQuit()), collection);
868
869     KStandardAction::open(this, SLOT(openFile()), collection);
870
871     m_saveAction = KStandardAction::save(this, SLOT(saveFile()), collection);
872
873     KStandardAction::saveAs(this, SLOT(saveFileAs()), collection);
874
875     KStandardAction::openNew(this, SLOT(newFile()), collection);
876
877     KStandardAction::preferences(this, SLOT(slotPreferences()), collection);
878
879     KStandardAction::configureNotifications(this , SLOT(configureNotifications()), collection);
880
881     KStandardAction::copy(this, SLOT(slotCopy()), collection);
882
883     KStandardAction::paste(this, SLOT(slotPaste()), collection);
884
885     KAction *undo = KStandardAction::undo(m_commandStack, SLOT(undo()), collection);
886     undo->setEnabled(false);
887     connect(m_commandStack, SIGNAL(canUndoChanged(bool)), undo, SLOT(setEnabled(bool)));
888
889     KAction *redo = KStandardAction::redo(m_commandStack, SLOT(redo()), collection);
890     redo->setEnabled(false);
891     connect(m_commandStack, SIGNAL(canRedoChanged(bool)), redo, SLOT(setEnabled(bool)));
892
893     KStandardAction::fullScreen(this, SLOT(slotFullScreen()), this, collection);
894
895     connect(collection, SIGNAL(actionHovered(QAction*)),
896             this, SLOT(slotDisplayActionMessage(QAction*)));
897     //connect(collection, SIGNAL( clearStatusText() ),
898     //statusBar(), SLOT( clear() ) );
899 }
900
901 void MainWindow::slotDisplayActionMessage(QAction *a) {
902     statusBar()->showMessage(a->data().toString(), 3000);
903 }
904
905 void MainWindow::saveOptions() {
906     KdenliveSettings::self()->writeConfig();
907     KSharedConfigPtr config = KGlobal::config();
908     m_fileOpenRecent->saveEntries(KConfigGroup(config, "Recent Files"));
909     KConfigGroup treecolumns(config, "Project Tree");
910     treecolumns.writeEntry("columns", m_projectList->headerInfo());
911     config->sync();
912 }
913
914 void MainWindow::readOptions() {
915     KSharedConfigPtr config = KGlobal::config();
916     m_fileOpenRecent->loadEntries(KConfigGroup(config, "Recent Files"));
917     KConfigGroup initialGroup(config, "version");
918     if (!initialGroup.exists()) {
919         // this is our first run, show Wizard
920         Wizard *w = new Wizard(this);
921         if (w->exec() == QDialog::Accepted && w->isOk()) {
922             w->adjustSettings();
923             initialGroup.writeEntry("version", "0.7");
924             delete w;
925         } else {
926             ::exit(1);
927         }
928     } else if (initialGroup.readEntry("version") == "0.7") {
929         //Add new settings from 0.7.1
930         if (KdenliveSettings::defaultprojectfolder().isEmpty()) {
931             QString path = QDir::homePath() + "/kdenlive";
932             if (KStandardDirs::makeDir(path)  == false) kDebug() << "/// ERROR CREATING PROJECT FOLDER: " << path;
933             KdenliveSettings::setDefaultprojectfolder(path);
934         }
935     }
936     KConfigGroup treecolumns(config, "Project Tree");
937     const QByteArray state = treecolumns.readEntry("columns", QByteArray());
938     if (!state.isEmpty())
939         m_projectList->setHeaderInfo(state);
940 }
941
942 void MainWindow::slotRunWizard() {
943     Wizard *w = new Wizard(this);
944     if (w->exec() == QDialog::Accepted && w->isOk()) {
945         w->adjustSettings();
946     }
947     delete w;
948 }
949
950 void MainWindow::newFile(bool showProjectSettings) {
951     QString profileName;
952     KUrl projectFolder;
953     QPoint projectTracks(KdenliveSettings::videotracks(), KdenliveSettings::audiotracks());
954     if (!showProjectSettings && m_timelineArea->count() == 0) {
955         if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
956         profileName = KdenliveSettings::default_profile();
957     } else {
958         ProjectSettings *w = new ProjectSettings(projectTracks.x(), projectTracks.y(), KdenliveSettings::defaultprojectfolder(), false, this);
959         if (w->exec() != QDialog::Accepted) return;
960         if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
961         profileName = w->selectedProfile();
962         projectFolder = w->selectedFolder();
963         projectTracks = w->tracks();
964         delete w;
965     }
966     KdenliveDoc *doc = new KdenliveDoc(KUrl(), projectFolder, m_commandStack, profileName, projectTracks,  this);
967     doc->m_autosave = new KAutoSaveFile(KUrl(), doc);
968     TrackView *trackView = new TrackView(doc, this);
969     m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description());
970     if (m_timelineArea->count() == 1) {
971         connectDocumentInfo(doc);
972         connectDocument(trackView, doc);
973     } else m_timelineArea->setTabBarHidden(false);
974     m_closeAction->setEnabled(m_timelineArea->count() > 1);
975 }
976
977 void MainWindow::activateDocument() {
978     if (m_timelineArea->currentWidget() == NULL) return;
979     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
980     KdenliveDoc *currentDoc = currentTab->document();
981     connectDocumentInfo(currentDoc);
982     connectDocument(currentTab, currentDoc);
983 }
984
985 void MainWindow::closeCurrentDocument() {
986     QWidget *w = m_timelineArea->currentWidget();
987     if (!w) return;
988     // closing current document
989     int ix = m_timelineArea->currentIndex() + 1;
990     if (ix == m_timelineArea->count()) ix = 0;
991     m_timelineArea->setCurrentIndex(ix);
992     TrackView *tabToClose = (TrackView *) w;
993     KdenliveDoc *docToClose = tabToClose->document();
994     if (docToClose && docToClose->isModified()) {
995         switch (KMessageBox::warningYesNoCancel(this, i18n("Save changes to document ?"))) {
996         case KMessageBox::Yes :
997             // save document here. If saving fails, return false;
998             saveFile();
999             break;
1000         case KMessageBox::Cancel :
1001             return;
1002         default:
1003             break;
1004         }
1005     }
1006     m_timelineArea->removeTab(m_timelineArea->indexOf(w));
1007     if (m_timelineArea->count() == 1) {
1008         m_timelineArea->setTabBarHidden(true);
1009         m_closeAction->setEnabled(false);
1010     }
1011     delete docToClose;
1012     delete w;
1013     if (m_timelineArea->count() == 0) {
1014         m_activeDocument = NULL;
1015         effectStack->clear();
1016         transitionConfig->slotTransitionItemSelected(NULL, false);
1017     }
1018 }
1019
1020 bool MainWindow::saveFileAs(const QString &outputFileName) {
1021     QDomDocument currentSceneList = m_projectMonitor->sceneList();
1022     if (m_activeDocument->saveSceneList(outputFileName, currentSceneList) == false)
1023         return false;
1024
1025     // Save timeline thumbnails
1026     m_activeTimeline->projectView()->saveThumbnails();
1027     m_activeDocument->setUrl(KUrl(outputFileName));
1028     if (m_activeDocument->m_autosave == NULL) {
1029         m_activeDocument->m_autosave = new KAutoSaveFile(KUrl(outputFileName), this);
1030     } else m_activeDocument->m_autosave->setManagedFile(KUrl(outputFileName));
1031     setCaption(m_activeDocument->description());
1032     m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
1033     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), m_activeDocument->url().path());
1034     m_activeDocument->setModified(false);
1035     m_fileOpenRecent->addUrl(KUrl(outputFileName));
1036     return true;
1037 }
1038
1039 bool MainWindow::saveFileAs() {
1040     // Check that the Kdenlive mime type is correctly installed
1041     QString mimetype = "application/x-kdenlive";
1042     KMimeType::Ptr mime = KMimeType::mimeType(mimetype);
1043     if (!mime) mimetype = "*.kdenlive";
1044
1045     QString outputFile = KFileDialog::getSaveFileName(KUrl(), mimetype);
1046     if (outputFile.isEmpty()) return false;
1047     if (QFile::exists(outputFile)) {
1048         if (KMessageBox::questionYesNo(this, i18n("File already exists.\nDo you want to overwrite it ?")) == KMessageBox::No) return false;
1049     }
1050     return saveFileAs(outputFile);
1051 }
1052
1053 bool MainWindow::saveFile() {
1054     if (!m_activeDocument) return true;
1055     if (m_activeDocument->url().isEmpty()) {
1056         return saveFileAs();
1057     } else {
1058         bool result = saveFileAs(m_activeDocument->url().path());
1059         m_activeDocument->m_autosave->resize(0);
1060         return result;
1061     }
1062 }
1063
1064 void MainWindow::openFile() {
1065     // Check that the Kdenlive mime type is correctly installed
1066     QString mimetype = "application/x-kdenlive";
1067     KMimeType::Ptr mime = KMimeType::mimeType(mimetype);
1068     if (!mime) mimetype = "*.kdenlive";
1069
1070     KUrl url = KFileDialog::getOpenUrl(KUrl(), mimetype);
1071     if (url.isEmpty()) return;
1072     m_fileOpenRecent->addUrl(url);
1073     openFile(url);
1074 }
1075
1076 void MainWindow::openLastFile() {
1077     KSharedConfigPtr config = KGlobal::config();
1078     KUrl::List urls = m_fileOpenRecent->urls();
1079     if (urls.isEmpty()) newFile(false);
1080     else openFile(urls.last());
1081 }
1082
1083 void MainWindow::openFile(const KUrl &url) {
1084     // Check if the document is already opened
1085     const int ct = m_timelineArea->count();
1086     bool isOpened = false;
1087     int i;
1088     for (i = 0; i < ct; i++) {
1089         TrackView *tab = (TrackView *) m_timelineArea->widget(i);
1090         KdenliveDoc *doc = tab->document();
1091         if (doc->url() == url) {
1092             isOpened = true;
1093             break;
1094         }
1095     }
1096     if (isOpened) {
1097         m_timelineArea->setCurrentIndex(i);
1098         return;
1099     }
1100
1101     // Check for backup file
1102     QList<KAutoSaveFile *> staleFiles = KAutoSaveFile::staleFiles(url);
1103     if (!staleFiles.isEmpty()) {
1104         if (KMessageBox::questionYesNo(this,
1105                                        i18n("Auto-saved files exist. Do you want to recover them now?"),
1106                                        i18n("File Recovery"),
1107                                        KGuiItem(i18n("Recover")), KGuiItem(i18n("Don't recover"))) == KMessageBox::Yes) {
1108             recoverFiles(staleFiles);
1109             return;
1110         } else {
1111             // remove the stale files
1112             foreach(KAutoSaveFile *stale, staleFiles) {
1113                 stale->open(QIODevice::ReadWrite);
1114                 delete stale;
1115             }
1116         }
1117     }
1118     if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
1119     doOpenFile(url, NULL);
1120 }
1121
1122 void MainWindow::doOpenFile(const KUrl &url, KAutoSaveFile *stale) {
1123     KdenliveDoc *doc;
1124     doc = new KdenliveDoc(url, KUrl(), m_commandStack, QString(), QPoint(3, 2), this);
1125     if (stale == NULL) {
1126         stale = new KAutoSaveFile(url, doc);
1127         doc->m_autosave = stale;
1128     } else {
1129         doc->m_autosave = stale;
1130         doc->setUrl(stale->managedFile());
1131         doc->setModified(true);
1132         stale->setParent(doc);
1133     }
1134     connectDocumentInfo(doc);
1135     TrackView *trackView = new TrackView(doc, this);
1136     m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description()));
1137     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), doc->url().path());
1138     if (m_timelineArea->count() > 1) m_timelineArea->setTabBarHidden(false);
1139     slotGotProgressInfo(QString(), -1);
1140     m_clipMonitor->refreshMonitor(true);
1141 }
1142
1143 void MainWindow::recoverFiles(QList<KAutoSaveFile *> staleFiles) {
1144     if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
1145     foreach(KAutoSaveFile *stale, staleFiles) {
1146         /*if (!stale->open(QIODevice::QIODevice::ReadOnly)) {
1147                   // show an error message; we could not steal the lockfile
1148                   // maybe another application got to the file before us?
1149                   delete stale;
1150                   continue;
1151         }*/
1152         kDebug() << "// OPENING RECOVERY: " << stale->fileName() << "\nMANAGED: " << stale->managedFile().path();
1153         // the stalefiles also contain ".lock" files so we must ignore them... bug in KAutoSaveFile ?
1154         if (!stale->fileName().endsWith(".lock")) doOpenFile(KUrl(stale->fileName()), stale);
1155         else KIO::NetAccess::del(KUrl(stale->fileName()), this);
1156     }
1157 }
1158
1159
1160 void MainWindow::parseProfiles(const QString &mltPath) {
1161     //kdDebug()<<" + + YOUR MLT INSTALL WAS FOUND IN: "<< MLT_PREFIX <<endl;
1162
1163     //KdenliveSettings::setDefaulttmpfolder();
1164     if (!mltPath.isEmpty()) {
1165         KdenliveSettings::setMltpath(mltPath + "/share/mlt/profiles/");
1166         KdenliveSettings::setRendererpath(mltPath + "/bin/inigo");
1167     }
1168
1169     if (KdenliveSettings::mltpath().isEmpty()) {
1170         KdenliveSettings::setMltpath(QString(MLT_PREFIX) + QString("/share/mlt/profiles/"));
1171     }
1172     if (KdenliveSettings::rendererpath().isEmpty()) {
1173         QString inigoPath = QString(MLT_PREFIX) + QString("/bin/inigo");
1174         if (!QFile::exists(inigoPath))
1175             inigoPath = KStandardDirs::findExe("inigo");
1176         else KdenliveSettings::setRendererpath(inigoPath);
1177     }
1178     QStringList profilesFilter;
1179     profilesFilter << "*";
1180     QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
1181
1182     if (profilesList.isEmpty()) {
1183         // Cannot find MLT path, try finding inigo
1184         QString profilePath = KdenliveSettings::rendererpath();
1185         if (!profilePath.isEmpty()) {
1186             profilePath = profilePath.section('/', 0, -3);
1187             KdenliveSettings::setMltpath(profilePath + "/share/mlt/profiles/");
1188             QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
1189         }
1190
1191         if (profilesList.isEmpty()) {
1192             // Cannot find the MLT profiles, ask for location
1193             KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find your Mlt profiles, please give the path"), this);
1194             getUrl->fileDialog()->setMode(KFile::Directory);
1195             if (getUrl->exec() == QDialog::Rejected) {
1196                 ::exit(0);
1197             }
1198             KUrl mltPath = getUrl->selectedUrl();
1199             delete getUrl;
1200             if (mltPath.isEmpty()) ::exit(0);
1201             KdenliveSettings::setMltpath(mltPath.path());
1202             QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
1203         }
1204     }
1205
1206     if (KdenliveSettings::rendererpath().isEmpty()) {
1207         // Cannot find the MLT inigo renderer, ask for location
1208         KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(QString(), i18n("Cannot find the inigo program required for rendering (part of Mlt)"), this);
1209         if (getUrl->exec() == QDialog::Rejected) {
1210             ::exit(0);
1211         }
1212         KUrl rendererPath = getUrl->selectedUrl();
1213         delete getUrl;
1214         if (rendererPath.isEmpty()) ::exit(0);
1215         KdenliveSettings::setRendererpath(rendererPath.path());
1216     }
1217
1218     kDebug() << "RESULTING MLT PATH: " << KdenliveSettings::mltpath();
1219
1220     // Parse MLT profiles to build a list of available video formats
1221     if (profilesList.isEmpty()) parseProfiles();
1222 }
1223
1224
1225 void MainWindow::slotEditProfiles() {
1226     ProfilesDialog *w = new ProfilesDialog;
1227     w->exec();
1228     delete w;
1229 }
1230
1231 void MainWindow::slotEditProjectSettings() {
1232     QPoint p = m_activeDocument->getTracksCount();
1233     ProjectSettings *w = new ProjectSettings(p.x(), p.y(), m_activeDocument->projectFolder().path(), true, this);
1234
1235     if (w->exec() == QDialog::Accepted) {
1236         QString profile = w->selectedProfile();
1237         m_activeDocument->setProjectFolder(w->selectedFolder());
1238         if (m_activeDocument->profilePath() != profile) {
1239             // Profile was changed
1240             m_activeDocument->setProfilePath(profile);
1241             KdenliveSettings::setCurrent_profile(profile);
1242             KdenliveSettings::setProject_fps(m_activeDocument->fps());
1243             setCaption(m_activeDocument->description(), m_activeDocument->isModified());
1244             m_monitorManager->resetProfiles(m_activeDocument->timecode());
1245             if (m_renderWidget) m_renderWidget->setProfile(m_activeDocument->mltProfile());
1246             m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
1247
1248             // We need to desactivate & reactivate monitors to get a refresh
1249             m_monitorManager->switchMonitors();
1250         }
1251     }
1252     delete w;
1253 }
1254
1255 void MainWindow::slotRenderProject() {
1256     if (!m_renderWidget) {
1257         m_renderWidget = new RenderWidget(this);
1258         connect(m_renderWidget, SIGNAL(doRender(const QString&, const QString&, const QStringList &, const QStringList &, bool, bool, double, double)), this, SLOT(slotDoRender(const QString&, const QString&, const QStringList &, const QStringList &, bool, bool, double, double)));
1259         if (m_activeDocument) {
1260             m_renderWidget->setProfile(m_activeDocument->mltProfile());
1261             m_renderWidget->setGuides(m_activeDocument->guidesXml(), m_activeDocument->projectDuration());
1262         }
1263     }
1264     /*TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
1265     if (currentTab) m_renderWidget->setTimeline(currentTab);
1266     m_renderWidget->setDocument(m_activeDocument);*/
1267     m_renderWidget->show();
1268 }
1269
1270 void MainWindow::slotDoRender(const QString &dest, const QString &render, const QStringList &overlay_args, const QStringList &avformat_args, bool zoneOnly, bool playAfter, double guideStart, double guideEnd) {
1271     if (dest.isEmpty()) return;
1272     int in;
1273     int out;
1274     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
1275     if (currentTab && zoneOnly) {
1276         in = currentTab->inPoint();
1277         out = currentTab->outPoint();
1278     }
1279     KTemporaryFile temp;
1280     temp.setAutoRemove(false);
1281     temp.setSuffix(".westley");
1282     if (temp.open()) {
1283         m_projectMonitor->saveSceneList(temp.fileName());
1284         QStringList args;
1285         args << "-erase";
1286         if (zoneOnly) args << "in=" + QString::number(in) << "out=" + QString::number(out);
1287         else if (guideStart != -1) {
1288             args << "in=" + QString::number(GenTime(guideStart).frames(m_activeDocument->fps())) << "out=" + QString::number(GenTime(guideEnd).frames(m_activeDocument->fps()));
1289         }
1290         if (!overlay_args.isEmpty()) args << "preargs=" + overlay_args.join(" ");
1291         QString videoPlayer = "-";
1292         if (playAfter) {
1293             videoPlayer = KdenliveSettings::defaultplayerapp();
1294             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."));
1295         }
1296         if (!QFile::exists(KdenliveSettings::rendererpath())) {
1297             KMessageBox::sorry(this, i18n("Cannot find the inigo program required for rendering (part of Mlt)"));
1298             return;
1299         }
1300         args << KdenliveSettings::rendererpath() << m_activeDocument->profilePath() << render << videoPlayer << temp.fileName() << dest << avformat_args;
1301         QString renderer = QCoreApplication::applicationDirPath() + QString("/kdenlive_render");
1302         if (!QFile::exists(renderer)) renderer = "kdenlive_render";
1303         QProcess::startDetached(renderer, args);
1304
1305         KNotification::event("RenderStarted", i18n("Rendering <i>%1</i> started", dest), QPixmap(), this);
1306     }
1307 }
1308
1309 void MainWindow::slotUpdateMousePosition(int pos) {
1310     if (m_activeDocument)
1311         switch (m_timecodeFormat->currentIndex()) {
1312         case 0:
1313             statusBar()->changeItem(m_activeDocument->timecode().getTimecodeFromFrames(pos), ID_TIMELINE_POS);
1314             break;
1315         default:
1316             statusBar()->changeItem(QString::number(pos), ID_TIMELINE_POS);
1317         }
1318 }
1319
1320 void MainWindow::slotUpdateDocumentState(bool modified) {
1321     setCaption(m_activeDocument->description(), modified);
1322     m_saveAction->setEnabled(modified);
1323     if (modified) {
1324         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Link));
1325         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("document-save"));
1326     } else {
1327         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Text));
1328         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("kdenlive"));
1329     }
1330 }
1331
1332 void MainWindow::connectDocumentInfo(KdenliveDoc *doc) {
1333     if (m_activeDocument) {
1334         if (m_activeDocument == doc) return;
1335         disconnect(m_activeDocument, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
1336     }
1337     connect(doc, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
1338 }
1339
1340 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //changed
1341     //m_projectMonitor->stop();
1342     m_closeAction->setEnabled(m_timelineArea->count() > 1);
1343     kDebug() << "///////////////////   CONNECTING DOC TO PROJECT VIEW ////////////////";
1344     if (m_activeDocument) {
1345         if (m_activeDocument == doc) return;
1346         m_activeDocument->backupMltPlaylist();
1347         if (m_activeTimeline) {
1348             disconnect(m_projectMonitor, SIGNAL(renderPosition(int)), m_activeTimeline, SLOT(moveCursorPos(int)));
1349             disconnect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), m_activeTimeline, SLOT(slotSetZone(QPoint)));
1350             disconnect(m_projectMonitor, SIGNAL(durationChanged(int)), m_activeTimeline, SLOT(setDuration(int)));
1351             disconnect(m_projectList, SIGNAL(projectModified()), m_activeDocument, SLOT(setModified()));
1352
1353
1354             disconnect(m_activeDocument, SIGNAL(guidesUpdated()), this, SLOT(slotGuidesUpdated()));
1355             disconnect(m_activeDocument, SIGNAL(addProjectClip(DocClipBase *, bool)), m_projectList, SLOT(slotAddClip(DocClipBase *, bool)));
1356             disconnect(m_activeDocument, SIGNAL(addProjectFolder(const QString, const QString &, bool, bool)), m_projectList, SLOT(slotAddFolder(const QString, const QString &, bool, bool)));
1357             disconnect(m_activeDocument, SIGNAL(signalDeleteProjectClip(const QString &)), m_projectList, SLOT(slotDeleteClip(const QString &)));
1358             disconnect(m_activeDocument, SIGNAL(updateClipDisplay(const QString &)), m_projectList, SLOT(slotUpdateClip(const QString &)));
1359             disconnect(m_activeDocument, SIGNAL(selectLastAddedClip(const QString &)), m_projectList, SLOT(slotSelectClip(const QString &)));
1360             disconnect(m_activeDocument, SIGNAL(deleteTimelineClip(const QString &)), m_activeTimeline, SLOT(slotDeleteClip(const QString &)));
1361             disconnect(m_activeTimeline->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), effectStack, SLOT(slotClipItemSelected(ClipItem*, int)));
1362             disconnect(m_activeTimeline->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), this, SLOT(slotActivateEffectStackView()));
1363             disconnect(m_activeTimeline, SIGNAL(transitionItemSelected(Transition*, bool)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*, bool)));
1364             disconnect(m_activeTimeline, SIGNAL(transitionItemSelected(Transition*, bool)), this, SLOT(slotActivateTransitionView()));
1365             disconnect(m_zoomSlider, SIGNAL(valueChanged(int)), m_activeTimeline, SLOT(slotChangeZoom(int)));
1366             disconnect(m_activeTimeline->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
1367             disconnect(m_activeTimeline->projectView(), SIGNAL(showClipFrame(DocClipBase *, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, const int)));
1368             disconnect(m_activeTimeline, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
1369             disconnect(m_activeTimeline, SIGNAL(insertTrack(int)), this, SLOT(slotInsertTrack(int)));
1370             disconnect(m_activeTimeline, SIGNAL(deleteTrack(int)), this, SLOT(slotDeleteTrack(int)));
1371             disconnect(m_activeTimeline, SIGNAL(changeTrack(int)), this, SLOT(slotChangeTrack(int)));
1372             disconnect(m_activeDocument, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
1373             disconnect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement, int)), m_activeTimeline->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement, int)));
1374             disconnect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), m_activeTimeline->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
1375             disconnect(effectStack, SIGNAL(changeEffectState(ClipItem*, int, bool)), m_activeTimeline->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, bool)));
1376             disconnect(effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), m_activeTimeline->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
1377             disconnect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), m_activeTimeline->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
1378             disconnect(effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
1379             disconnect(transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), m_activeTimeline->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
1380             disconnect(transitionConfig, SIGNAL(transitionTrackUpdated(Transition *, int)), m_activeTimeline->projectView() , SLOT(slotTransitionTrackUpdated(Transition *, int)));
1381             disconnect(transitionConfig, SIGNAL(seekTimeline(int)), m_activeTimeline->projectView() , SLOT(setCursorPos(int)));
1382             disconnect(m_activeTimeline->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
1383             disconnect(m_activeTimeline, SIGNAL(zoneMoved(int, int)), m_projectMonitor, SLOT(slotZoneMoved(int, int)));
1384             disconnect(m_projectList, SIGNAL(loadingIsOver()), m_activeTimeline->projectView(), SLOT(slotUpdateAllThumbs()));
1385             effectStack->clear();
1386         }
1387         m_activeDocument->setRenderer(NULL);
1388         disconnect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
1389         m_clipMonitor->stop();
1390     }
1391     KdenliveSettings::setCurrent_profile(doc->profilePath());
1392     KdenliveSettings::setProject_fps(doc->fps());
1393     m_monitorManager->resetProfiles(doc->timecode());
1394     m_projectList->setDocument(doc);
1395     transitionConfig->updateProjectFormat(doc->mltProfile(), doc->timecode(), trackView->tracksNumber());
1396     effectStack->updateProjectFormat(doc->mltProfile(), doc->timecode());
1397     connect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
1398     connect(m_projectList, SIGNAL(projectModified()), doc, SLOT(setModified()));
1399     connect(trackView, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
1400     connect(trackView, SIGNAL(insertTrack(int)), this, SLOT(slotInsertTrack(int)));
1401     connect(trackView, SIGNAL(deleteTrack(int)), this, SLOT(slotDeleteTrack(int)));
1402     connect(trackView, SIGNAL(changeTrack(int)), this, SLOT(slotChangeTrack(int)));
1403     connect(trackView, SIGNAL(mousePosition(int)), this, SLOT(slotUpdateMousePosition(int)));
1404     connect(m_projectMonitor, SIGNAL(renderPosition(int)), trackView, SLOT(moveCursorPos(int)));
1405     connect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), trackView, SLOT(slotSetZone(QPoint)));
1406     connect(m_projectMonitor, SIGNAL(durationChanged(int)), trackView, SLOT(setDuration(int)));
1407     connect(doc, SIGNAL(addProjectClip(DocClipBase *, bool)), m_projectList, SLOT(slotAddClip(DocClipBase *, bool)));
1408     connect(doc, SIGNAL(addProjectFolder(const QString, const QString &, bool, bool)), m_projectList, SLOT(slotAddFolder(const QString, const QString &, bool, bool)));
1409     connect(doc, SIGNAL(signalDeleteProjectClip(const QString &)), m_projectList, SLOT(slotDeleteClip(const QString &)));
1410     connect(doc, SIGNAL(updateClipDisplay(const QString &)), m_projectList, SLOT(slotUpdateClip(const QString &)));
1411     connect(doc, SIGNAL(selectLastAddedClip(const QString &)), m_projectList, SLOT(slotSelectClip(const QString &)));
1412
1413     connect(doc, SIGNAL(deleteTimelineClip(const QString &)), trackView, SLOT(slotDeleteClip(const QString &)));
1414     connect(doc, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
1415     connect(doc, SIGNAL(guidesUpdated()), this, SLOT(slotGuidesUpdated()));
1416
1417
1418     connect(trackView->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), effectStack, SLOT(slotClipItemSelected(ClipItem*, int)));
1419     connect(trackView->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), this, SLOT(slotActivateEffectStackView()));
1420     connect(trackView, SIGNAL(transitionItemSelected(Transition*, bool)), transitionConfig, SLOT(slotTransitionItemSelected(Transition*, bool)));
1421     connect(trackView, SIGNAL(transitionItemSelected(Transition*, bool)), this, SLOT(slotActivateTransitionView()));
1422     m_zoomSlider->setValue(doc->zoom());
1423     connect(m_zoomSlider, SIGNAL(valueChanged(int)), trackView, SLOT(slotChangeZoom(int)));
1424     connect(trackView->projectView(), SIGNAL(zoomIn()), this, SLOT(slotZoomIn()));
1425     connect(trackView->projectView(), SIGNAL(zoomOut()), this, SLOT(slotZoomOut()));
1426     connect(trackView->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
1427
1428     connect(trackView->projectView(), SIGNAL(showClipFrame(DocClipBase *, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, const int)));
1429
1430
1431     connect(effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement, int)), trackView->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement, int)));
1432     connect(effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), trackView->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
1433     connect(effectStack, SIGNAL(changeEffectState(ClipItem*, int, bool)), trackView->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, bool)));
1434     connect(effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), trackView->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
1435     connect(effectStack, SIGNAL(refreshEffectStack(ClipItem*)), trackView->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
1436     connect(transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
1437     connect(transitionConfig, SIGNAL(transitionTrackUpdated(Transition *, int)), trackView->projectView() , SLOT(slotTransitionTrackUpdated(Transition *, int)));
1438     connect(transitionConfig, SIGNAL(seekTimeline(int)), trackView->projectView() , SLOT(setCursorPos(int)));
1439     connect(effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
1440
1441     connect(trackView->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
1442     connect(trackView, SIGNAL(zoneMoved(int, int)), m_projectMonitor, SLOT(slotZoneMoved(int, int)));
1443     connect(m_projectList, SIGNAL(loadingIsOver()), trackView->projectView(), SLOT(slotUpdateAllThumbs()));
1444
1445     trackView->projectView()->setContextMenu(m_timelineContextMenu, m_timelineContextClipMenu, m_timelineContextTransitionMenu);
1446     m_activeTimeline = trackView;
1447     if (m_renderWidget) m_renderWidget->setProfile(doc->mltProfile());
1448     doc->setRenderer(m_projectMonitor->render);
1449     m_commandStack->setActiveStack(doc->commandStack());
1450     KdenliveSettings::setProject_display_ratio(doc->dar());
1451     m_projectList->updateAllClips();
1452     //doc->clipManager()->checkAudioThumbs();
1453
1454     //m_overView->setScene(trackView->projectScene());
1455     //m_overView->scale(m_overView->width() / trackView->duration(), m_overView->height() / (50 * trackView->tracksNumber()));
1456     //m_overView->fitInView(m_overView->itemAt(0, 50), Qt::KeepAspectRatio);
1457
1458     setCaption(doc->description(), doc->isModified());
1459     m_saveAction->setEnabled(doc->isModified());
1460     m_activeDocument = doc;
1461
1462     // set tool to select tool
1463     m_buttonSelectTool->setChecked(true);
1464 }
1465
1466 void MainWindow::slotGuidesUpdated() {
1467     if (m_renderWidget) m_renderWidget->setGuides(m_activeDocument->guidesXml(), m_activeDocument->projectDuration());
1468 }
1469
1470 void MainWindow::slotPreferences(int page, int option) {
1471     //An instance of your dialog could be already created and could be
1472     // cached, in which case you want to display the cached dialog
1473     // instead of creating another one
1474     if (KConfigDialog::showDialog("settings")) {
1475         KdenliveSettingsDialog* d = static_cast <KdenliveSettingsDialog*>(KConfigDialog::exists("settings"));
1476         if (page != -1) d->showPage(page, option);
1477         d->checkProfile();
1478         return;
1479     }
1480
1481     // KConfigDialog didn't find an instance of this dialog, so lets
1482     // create it :
1483     KdenliveSettingsDialog* dialog = new KdenliveSettingsDialog(this);
1484     connect(dialog, SIGNAL(settingsChanged(const QString&)), this, SLOT(updateConfiguration()));
1485     connect(dialog, SIGNAL(doResetProfile()), m_monitorManager, SLOT(slotResetProfiles()));
1486     dialog->show();
1487     if (page != -1) dialog->showPage(page, option);
1488 }
1489
1490 void MainWindow::updateConfiguration() {
1491     //TODO: we should apply settings to all projects, not only the current one
1492     if (m_activeTimeline) {
1493         m_activeTimeline->refresh();
1494         m_activeTimeline->projectView()->checkAutoScroll();
1495         m_activeTimeline->projectView()->checkTrackHeight();
1496         if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
1497     }
1498     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
1499     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
1500 #ifndef NO_JOGSHUTTLE
1501     activateShuttleDevice();
1502 #endif /* NO_JOGSHUTTLE */
1503
1504 }
1505
1506 void MainWindow::slotSwitchVideoThumbs() {
1507     KdenliveSettings::setVideothumbnails(!KdenliveSettings::videothumbnails());
1508     if (m_activeTimeline) {
1509         m_activeTimeline->refresh();
1510     }
1511     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
1512 }
1513
1514 void MainWindow::slotSwitchAudioThumbs() {
1515     KdenliveSettings::setAudiothumbnails(!KdenliveSettings::audiothumbnails());
1516     if (m_activeTimeline) {
1517         m_activeTimeline->refresh();
1518         m_activeTimeline->projectView()->checkAutoScroll();
1519         if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
1520     }
1521     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
1522 }
1523
1524 void MainWindow::slotSwitchMarkersComments() {
1525     KdenliveSettings::setShowmarkers(!KdenliveSettings::showmarkers());
1526     if (m_activeTimeline) {
1527         m_activeTimeline->refresh();
1528     }
1529     m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
1530 }
1531
1532 void MainWindow::slotSwitchSnap() {
1533     KdenliveSettings::setSnaptopoints(!KdenliveSettings::snaptopoints());
1534     m_buttonSnap->setChecked(KdenliveSettings::snaptopoints());
1535 }
1536
1537
1538 void MainWindow::slotDeleteTimelineClip() {
1539     if (QApplication::focusWidget()->parentWidget()->parentWidget() == projectListDock) m_projectList->slotRemoveClip();
1540     else if (m_activeTimeline) {
1541         m_activeTimeline->projectView()->deleteSelectedClips();
1542     }
1543 }
1544
1545 void MainWindow::slotChangeClipSpeed() {
1546     if (m_activeTimeline) {
1547         m_activeTimeline->projectView()->changeClipSpeed();
1548     }
1549 }
1550
1551 void MainWindow::slotAddClipMarker() {
1552     DocClipBase *clip = NULL;
1553     GenTime pos;
1554     if (m_projectMonitor->isActive()) {
1555         if (m_activeTimeline) {
1556             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
1557             if (item) {
1558                 pos = m_projectMonitor->position() - item->startPos() + item->cropStart();
1559                 clip = item->baseClip();
1560             }
1561         }
1562     } else {
1563         clip = m_clipMonitor->activeClip();
1564         pos = m_clipMonitor->position();
1565     }
1566     if (!clip) {
1567         m_messageLabel->setMessage(i18n("Cannot find clip to add marker"), ErrorMessage);
1568         return;
1569     }
1570     QString id = clip->getId();
1571     CommentedTime marker(pos, i18n("Marker"));
1572     MarkerDialog d(clip, marker, m_activeDocument->timecode(), i18n("Add Marker"), this);
1573     if (d.exec() == QDialog::Accepted) {
1574         m_activeTimeline->projectView()->slotAddClipMarker(id, d.newMarker().time(), d.newMarker().comment());
1575     }
1576     if (m_clipMonitor->isActive()) m_clipMonitor->checkOverlay();
1577 }
1578
1579 void MainWindow::slotDeleteClipMarker() {
1580     DocClipBase *clip = NULL;
1581     GenTime pos;
1582     if (m_projectMonitor->isActive()) {
1583         if (m_activeTimeline) {
1584             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
1585             if (item) {
1586                 pos = m_projectMonitor->position() - item->startPos() + item->cropStart();
1587                 clip = item->baseClip();
1588             }
1589         }
1590     } else {
1591         clip = m_clipMonitor->activeClip();
1592         pos = m_clipMonitor->position();
1593     }
1594     if (!clip) {
1595         m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
1596         return;
1597     }
1598
1599     QString id = clip->getId();
1600     QString comment = clip->markerComment(pos);
1601     if (comment.isEmpty()) {
1602         m_messageLabel->setMessage(i18n("No marker found at cursor time"), ErrorMessage);
1603         return;
1604     }
1605     m_activeTimeline->projectView()->slotDeleteClipMarker(comment, id, pos);
1606     if (m_clipMonitor->isActive()) m_clipMonitor->checkOverlay();
1607
1608 }
1609
1610 void MainWindow::slotDeleteAllClipMarkers() {
1611     DocClipBase *clip = NULL;
1612     if (m_projectMonitor->isActive()) {
1613         if (m_activeTimeline) {
1614             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
1615             if (item) {
1616                 clip = item->baseClip();
1617             }
1618         }
1619     } else {
1620         clip = m_clipMonitor->activeClip();
1621     }
1622     if (!clip) {
1623         m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
1624         return;
1625     }
1626     m_activeTimeline->projectView()->slotDeleteAllClipMarkers(clip->getId());
1627     if (m_clipMonitor->isActive()) m_clipMonitor->checkOverlay();
1628 }
1629
1630 void MainWindow::slotEditClipMarker() {
1631     DocClipBase *clip = NULL;
1632     GenTime pos;
1633     if (m_projectMonitor->isActive()) {
1634         if (m_activeTimeline) {
1635             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
1636             if (item) {
1637                 pos = m_projectMonitor->position() - item->startPos() + item->cropStart();
1638                 clip = item->baseClip();
1639             }
1640         }
1641     } else {
1642         clip = m_clipMonitor->activeClip();
1643         pos = m_clipMonitor->position();
1644     }
1645     if (!clip) {
1646         m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
1647         return;
1648     }
1649
1650     QString id = clip->getId();
1651     QString oldcomment = clip->markerComment(pos);
1652     if (oldcomment.isEmpty()) {
1653         m_messageLabel->setMessage(i18n("No marker found at cursor time"), ErrorMessage);
1654         return;
1655     }
1656
1657     CommentedTime marker(pos, oldcomment);
1658     MarkerDialog d(clip, marker, m_activeDocument->timecode(), i18n("Edit Marker"), this);
1659     if (d.exec() == QDialog::Accepted) {
1660         m_activeTimeline->projectView()->slotAddClipMarker(id, d.newMarker().time(), d.newMarker().comment());
1661         if (d.newMarker().time() != pos) {
1662             // remove old marker
1663             m_activeTimeline->projectView()->slotAddClipMarker(id, pos, QString());
1664         }
1665         if (m_clipMonitor->isActive()) m_clipMonitor->checkOverlay();
1666     }
1667 }
1668
1669 void MainWindow::slotAddGuide() {
1670     if (m_activeTimeline)
1671         m_activeTimeline->projectView()->slotAddGuide();
1672 }
1673
1674 void MainWindow::slotInsertSpace() {
1675     if (m_activeTimeline)
1676         m_activeTimeline->projectView()->slotInsertSpace();
1677 }
1678
1679 void MainWindow::slotRemoveSpace() {
1680     if (m_activeTimeline)
1681         m_activeTimeline->projectView()->slotRemoveSpace();
1682 }
1683
1684 void MainWindow::slotInsertTrack(int ix) {
1685     m_projectMonitor->activateMonitor();
1686     if (m_activeTimeline)
1687         m_activeTimeline->projectView()->slotInsertTrack(ix);
1688 }
1689
1690 void MainWindow::slotDeleteTrack(int ix) {
1691     m_projectMonitor->activateMonitor();
1692     if (m_activeTimeline)
1693         m_activeTimeline->projectView()->slotDeleteTrack(ix);
1694 }
1695
1696 void MainWindow::slotChangeTrack(int ix) {
1697     m_projectMonitor->activateMonitor();
1698     if (m_activeTimeline)
1699         m_activeTimeline->projectView()->slotChangeTrack(ix);
1700 }
1701
1702 void MainWindow::slotEditGuide() {
1703     if (m_activeTimeline)
1704         m_activeTimeline->projectView()->slotEditGuide();
1705 }
1706
1707 void MainWindow::slotDeleteGuide() {
1708     if (m_activeTimeline)
1709         m_activeTimeline->projectView()->slotDeleteGuide();
1710 }
1711
1712 void MainWindow::slotDeleteAllGuides() {
1713     if (m_activeTimeline)
1714         m_activeTimeline->projectView()->slotDeleteAllGuides();
1715 }
1716
1717 void MainWindow::slotCutTimelineClip() {
1718     if (m_activeTimeline) {
1719         m_activeTimeline->projectView()->cutSelectedClips();
1720     }
1721 }
1722
1723 void MainWindow::slotAddProjectClip(KUrl url) {
1724     if (m_activeDocument)
1725         m_activeDocument->slotAddClipFile(url, QString());
1726 }
1727
1728 void MainWindow::slotAddTransition(QAction *result) {
1729     if (!result) return;
1730     QStringList info = result->data().toStringList();
1731     if (info.isEmpty()) return;
1732     QDomElement transition = transitions.getEffectByTag(info.at(1), info.at(2));
1733     if (m_activeTimeline && !transition.isNull()) {
1734         m_activeTimeline->projectView()->slotAddTransitionToSelectedClips(transition.cloneNode().toElement());
1735     }
1736 }
1737
1738 void MainWindow::slotAddVideoEffect(QAction *result) {
1739     if (!result) return;
1740     QStringList info = result->data().toStringList();
1741     if (info.isEmpty()) return;
1742     QDomElement effect = videoEffects.getEffectByTag(info.at(1), info.at(2));
1743     slotAddEffect(effect);
1744 }
1745
1746 void MainWindow::slotAddAudioEffect(QAction *result) {
1747     if (!result) return;
1748     QStringList info = result->data().toStringList();
1749     if (info.isEmpty()) return;
1750     QDomElement effect = audioEffects.getEffectByTag(info.at(1), info.at(2));
1751     slotAddEffect(effect);
1752 }
1753
1754 void MainWindow::slotAddCustomEffect(QAction *result) {
1755     if (!result) return;
1756     QStringList info = result->data().toStringList();
1757     if (info.isEmpty()) return;
1758     QDomElement effect = customEffects.getEffectByTag(info.at(1), info.at(2));
1759     slotAddEffect(effect);
1760 }
1761
1762 void MainWindow::slotZoomIn() {
1763     m_zoomSlider->setValue(m_zoomSlider->value() - 1);
1764 }
1765
1766 void MainWindow::slotZoomOut() {
1767     m_zoomSlider->setValue(m_zoomSlider->value() + 1);
1768 }
1769
1770 void MainWindow::slotFitZoom() {
1771     if (m_activeTimeline) {
1772         m_zoomSlider->setValue(m_activeTimeline->fitZoom());
1773     }
1774 }
1775
1776 void MainWindow::slotGotProgressInfo(const QString &message, int progress) {
1777     statusProgressBar->setValue(progress);
1778     if (progress >= 0) {
1779         if (!message.isEmpty()) m_messageLabel->setMessage(message, InformationMessage);//statusLabel->setText(message);
1780         statusProgressBar->setVisible(true);
1781     } else {
1782         m_messageLabel->setMessage(QString(), DefaultMessage);
1783         statusProgressBar->setVisible(false);
1784     }
1785 }
1786
1787 void MainWindow::slotShowClipProperties(DocClipBase *clip) {
1788     if (clip->clipType() == TEXT) {
1789         QString titlepath = m_activeDocument->projectFolder().path() + "/titles/";
1790         QString path = clip->getProperty("resource");
1791         TitleWidget *dia_ui = new TitleWidget(KUrl(), titlepath, m_projectMonitor->render, this);
1792         QDomDocument doc;
1793         doc.setContent(clip->getProperty("xmldata"));
1794         dia_ui->setXml(doc);
1795         if (dia_ui->exec() == QDialog::Accepted) {
1796             QPixmap pix = dia_ui->renderedPixmap();
1797             pix.save(path);
1798             //slotAddClipFile(KUrl("/tmp/kdenlivetitle.png"), QString(), -1);
1799             //m_clipManager->slotEditTextClipFile(id, dia_ui->xml().toString());
1800             QMap <QString, QString> newprops;
1801             newprops.insert("xmldata", dia_ui->xml().toString());
1802             EditClipCommand *command = new EditClipCommand(m_projectList, clip->getId(), clip->properties(), newprops, true);
1803             m_activeDocument->commandStack()->push(command);
1804             m_clipMonitor->refreshMonitor(true);
1805             m_activeDocument->setModified(true);
1806         }
1807         delete dia_ui;
1808
1809         //m_activeDocument->editTextClip(clip->getProperty("xml"), clip->getId());
1810         return;
1811     }
1812     ClipProperties dia(clip, m_activeDocument->timecode(), m_activeDocument->fps(), this);
1813     connect(&dia, SIGNAL(addMarker(const QString &, GenTime, QString)), m_activeTimeline->projectView(), SLOT(slotAddClipMarker(const QString &, GenTime, QString)));
1814     if (dia.exec() == QDialog::Accepted) {
1815         EditClipCommand *command = new EditClipCommand(m_projectList, dia.clipId(), clip->properties(), dia.properties(), true);
1816         m_activeDocument->commandStack()->push(command);
1817
1818         //m_projectList->slotUpdateClipProperties(dia.clipId(), dia.properties());
1819         if (dia.needsTimelineRefresh()) {
1820             // update clip occurences in timeline
1821             m_activeTimeline->projectView()->slotUpdateClip(dia.clipId());
1822         }
1823     }
1824 }
1825
1826 void MainWindow::customEvent(QEvent* e) {
1827     if (e->type() == QEvent::User) {
1828         // The timeline playing position changed...
1829         kDebug() << "RECIEVED JOG EVEMNT!!!";
1830     }
1831 }
1832 void MainWindow::slotActivateEffectStackView() {
1833     effectStack->raiseWindow(effectStackDock);
1834 }
1835
1836 void MainWindow::slotActivateTransitionView() {
1837     transitionConfig->raiseWindow(transitionConfigDock);
1838 }
1839
1840 void MainWindow::slotSnapRewind() {
1841     if (m_projectMonitor->isActive()) {
1842         if (m_activeTimeline)
1843             m_activeTimeline->projectView()->slotSeekToPreviousSnap();
1844     } else m_clipMonitor->slotSeekToPreviousSnap();
1845 }
1846
1847 void MainWindow::slotSnapForward() {
1848     if (m_projectMonitor->isActive()) {
1849         if (m_activeTimeline)
1850             m_activeTimeline->projectView()->slotSeekToNextSnap();
1851     } else m_clipMonitor->slotSeekToNextSnap();
1852 }
1853
1854 void MainWindow::slotClipStart() {
1855     if (m_projectMonitor->isActive()) {
1856         if (m_activeTimeline)
1857             m_activeTimeline->projectView()->clipStart();
1858     }
1859 }
1860
1861 void MainWindow::slotClipEnd() {
1862     if (m_projectMonitor->isActive()) {
1863         if (m_activeTimeline)
1864             m_activeTimeline->projectView()->clipEnd();
1865     }
1866 }
1867
1868 void MainWindow::slotChangeTool(QAction * action) {
1869     if (action == m_buttonSelectTool) slotSetTool(SELECTTOOL);
1870     else if (action == m_buttonRazorTool) slotSetTool(RAZORTOOL);
1871     else if (action == m_buttonSpacerTool) slotSetTool(SPACERTOOL);
1872 }
1873
1874 void MainWindow::slotSetTool(PROJECTTOOL tool) {
1875     if (m_activeDocument && m_activeTimeline) {
1876         //m_activeDocument->setTool(tool);
1877         m_activeTimeline->projectView()->setTool(tool);
1878     }
1879 }
1880
1881 void MainWindow::slotCopy() {
1882     if (!m_activeDocument || !m_activeTimeline) return;
1883     m_activeTimeline->projectView()->copyClip();
1884 }
1885
1886 void MainWindow::slotPaste() {
1887     if (!m_activeDocument || !m_activeTimeline) return;
1888     m_activeTimeline->projectView()->pasteClip();
1889 }
1890
1891 void MainWindow::slotPasteEffects() {
1892     if (!m_activeDocument || !m_activeTimeline) return;
1893     m_activeTimeline->projectView()->pasteClipEffects();
1894 }
1895
1896 void MainWindow::slotFind() {
1897     if (!m_activeDocument || !m_activeTimeline) return;
1898     m_projectSearch->setEnabled(false);
1899     m_findActivated = true;
1900     m_findString = QString();
1901     m_activeTimeline->projectView()->initSearchStrings();
1902     statusBar()->showMessage(i18n("Starting -- find text as you type"));
1903     m_findTimer.start(5000);
1904     qApp->installEventFilter(this);
1905 }
1906
1907 void MainWindow::slotFindNext() {
1908     if (m_activeTimeline && m_activeTimeline->projectView()->findNextString(m_findString)) {
1909         statusBar()->showMessage(i18n("Found : %1", m_findString));
1910     } else {
1911         statusBar()->showMessage(i18n("Reached end of project"));
1912     }
1913     m_findTimer.start(4000);
1914 }
1915
1916 void MainWindow::findAhead() {
1917     if (m_activeTimeline && m_activeTimeline->projectView()->findString(m_findString)) {
1918         m_projectSearchNext->setEnabled(true);
1919         statusBar()->showMessage(i18n("Found : %1", m_findString));
1920     } else {
1921         m_projectSearchNext->setEnabled(false);
1922         statusBar()->showMessage(i18n("Not found : %1", m_findString));
1923     }
1924 }
1925
1926 void MainWindow::findTimeout() {
1927     m_projectSearchNext->setEnabled(false);
1928     m_findActivated = false;
1929     m_findString = QString();
1930     statusBar()->showMessage(i18n("Find stopped"), 3000);
1931     if (m_activeTimeline) m_activeTimeline->projectView()->clearSearchStrings();
1932     m_projectSearch->setEnabled(true);
1933     removeEventFilter(this);
1934 }
1935
1936 void MainWindow::keyPressEvent(QKeyEvent *ke) {
1937     if (m_findActivated) {
1938         if (ke->key() == Qt::Key_Backspace) {
1939             m_findString = m_findString.left(m_findString.length() - 1);
1940
1941             if (!m_findString.isEmpty()) {
1942                 findAhead();
1943             } else {
1944                 findTimeout();
1945             }
1946
1947             m_findTimer.start(4000);
1948             ke->accept();
1949             return;
1950         } else if (ke->key() == Qt::Key_Escape) {
1951             findTimeout();
1952             ke->accept();
1953             return;
1954         } else if (ke->key() == Qt::Key_Space || !ke->text().trimmed().isEmpty()) {
1955             m_findString += ke->text();
1956
1957             findAhead();
1958
1959             m_findTimer.start(4000);
1960             ke->accept();
1961             return;
1962         }
1963     } else KXmlGuiWindow::keyPressEvent(ke);
1964 }
1965
1966
1967 /** Gets called when the window gets hidden */
1968 void MainWindow::hideEvent(QHideEvent *event) {
1969     // kDebug() << "I was hidden";
1970     // issue http://www.kdenlive.org/mantis/view.php?id=231
1971     if (this->isMinimized()) {
1972         // kDebug() << "I am minimized";
1973         if (m_monitorManager) m_monitorManager->stopActiveMonitor();
1974     }
1975 }
1976
1977 bool MainWindow::eventFilter(QObject *obj, QEvent *event) {
1978     if (m_findActivated) {
1979         if (event->type() == QEvent::ShortcutOverride) {
1980             QKeyEvent* ke = (QKeyEvent*) event;
1981             if (ke->text().trimmed().isEmpty()) return false;
1982             ke->accept();
1983             return true;
1984         } else return false;
1985     } else {
1986         // pass the event on to the parent class
1987         return QMainWindow::eventFilter(obj, event);
1988     }
1989 }
1990
1991 void MainWindow::slotSaveZone(Render *render, QPoint zone) {
1992     KDialog *dialog = new KDialog(this);
1993     dialog->setCaption("Save clip zone");
1994     dialog->setButtons(KDialog::Ok | KDialog::Cancel);
1995
1996     QWidget *widget = new QWidget(dialog);
1997     dialog->setMainWidget(widget);
1998
1999     QVBoxLayout *vbox = new QVBoxLayout(widget);
2000     QLabel *label1 = new QLabel(i18n("Save clip zone as:"), this);
2001     QString path = m_activeDocument->projectFolder().path();
2002     path.append("/");
2003     path.append("untitled.westley");
2004     KUrlRequester *url = new KUrlRequester(KUrl(path), this);
2005     url->setFilter("video/mlt-playlist");
2006     QLabel *label2 = new QLabel(i18n("Description:"), this);
2007     KLineEdit *edit = new KLineEdit(this);
2008     vbox->addWidget(label1);
2009     vbox->addWidget(url);
2010     vbox->addWidget(label2);
2011     vbox->addWidget(edit);
2012     if (dialog->exec() == QDialog::Accepted) render->saveZone(url->url(), edit->text(), zone);
2013
2014 }
2015
2016 void MainWindow::slotSetInPoint() {
2017     if (m_clipMonitor->isActive()) {
2018         m_clipMonitor->slotSetZoneStart();
2019     } else m_activeTimeline->projectView()->setInPoint();
2020 }
2021
2022 void MainWindow::slotSetOutPoint() {
2023     if (m_clipMonitor->isActive()) {
2024         m_clipMonitor->slotSetZoneEnd();
2025     } else m_activeTimeline->projectView()->setOutPoint();
2026 }
2027
2028 void MainWindow::slotGetNewStuff() {
2029     //KNS::Entry::List download();
2030     KNS::Entry::List entries = KNS::Engine::download();
2031     int numberInstalled = 0;
2032     // list of changed entries
2033     kDebug() << "// PARSING KNS";
2034     foreach(KNS::Entry* entry, entries) {
2035         // care only about installed ones
2036         if (entry->status() == KNS::Entry::Installed) {
2037             foreach(const QString &file, entry->installedFiles()) {
2038                 kDebug() << "// CURRENTLY INSTALLED: " << file;
2039             }
2040         }
2041     }
2042     qDeleteAll(entries);
2043     initEffects::refreshLumas();
2044 }
2045
2046 void MainWindow::slotAutoTransition() {
2047     m_activeTimeline->projectView()->autoTransition();
2048 }
2049
2050 #include "mainwindow.moc"