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