]> git.sesse.net Git - kdenlive/blob - src/mainwindow.cpp
* Play audio when previewing in v4l capture mode
[kdenlive] / src / mainwindow.cpp
1 /***************************************************************************
2  *   Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3  *                                                                         *
4  *   This program is free software; you can redistribute it and/or modify  *
5  *   it under the terms of the GNU General Public License as published by  *
6  *   the Free Software Foundation; either version 2 of the License, or     *
7  *   (at your option) any later version.                                   *
8  *                                                                         *
9  *   This program is distributed in the hope that it will be useful,       *
10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12  *   GNU General Public License for more details.                          *
13  *                                                                         *
14  *   You should have received a copy of the GNU General Public License     *
15  *   along with this program; if not, write to the                         *
16  *   Free Software Foundation, Inc.,                                       *
17  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
18  ***************************************************************************/
19
20
21 #include "mainwindow.h"
22 #include "mainwindowadaptor.h"
23 #include "kdenlivesettings.h"
24 #include "kdenlivesettingsdialog.h"
25 #include "initeffects.h"
26 #include "profilesdialog.h"
27 #include "projectsettings.h"
28 #include "events.h"
29 #include "clipmanager.h"
30 #include "projectlist.h"
31 #include "monitor.h"
32 #include "recmonitor.h"
33 #include "monitormanager.h"
34 #include "kdenlivedoc.h"
35 #include "trackview.h"
36 #include "customtrackview.h"
37 #include "effectslistview.h"
38 #include "effectstackview.h"
39 #include "transitionsettings.h"
40 #include "renderwidget.h"
41 #include "renderer.h"
42 #include "audiosignal.h"
43 #ifdef USE_JOGSHUTTLE
44 #include "jogshuttle.h"
45 #include "jogaction.h"
46 #include "jogshuttleconfig.h"
47 #endif
48 #include "clipproperties.h"
49 #include "wizard.h"
50 #include "commands/editclipcommand.h"
51 #include "titlewidget.h"
52 #include "markerdialog.h"
53 #include "clipitem.h"
54 #include "interfaces.h"
55 #include "config-kdenlive.h"
56 #include "cliptranscode.h"
57 #include "clipstabilize.h"
58 #include "ui_templateclip_ui.h"
59 #include "colorscopes/vectorscope.h"
60 #include "colorscopes/waveform.h"
61 #include "colorscopes/rgbparade.h"
62 #include "colorscopes/histogram.h"
63 #include "audioscopes/audiospectrum.h"
64 #include "audioscopes/spectrogram.h"
65 #include "archivewidget.h"
66 #include "databackup/backupwidget.h"
67
68
69 #include <KApplication>
70 #include <KAction>
71 #include <KLocale>
72 #include <KGlobal>
73 #include <KActionCollection>
74 #include <KActionCategory>
75 #include <KStandardAction>
76 #include <KShortcutsDialog>
77 #include <KFileDialog>
78 #include <KMessageBox>
79 #include <KDebug>
80 #include <KIO/NetAccess>
81 #include <KSaveFile>
82 #include <KRuler>
83 #include <KConfigDialog>
84 #include <KXMLGUIFactory>
85 #include <KStatusBar>
86 #include <kstandarddirs.h>
87 #include <KUrlRequesterDialog>
88 #include <KTemporaryFile>
89 #include <KProcess>
90 #include <KActionMenu>
91 #include <KMenu>
92 #include <ktogglefullscreenaction.h>
93 #include <KFileItem>
94 #include <KNotification>
95 #include <KNotifyConfigWidget>
96 #if KDE_IS_VERSION(4,3,80)
97 #include <knewstuff3/downloaddialog.h>
98 #include <knewstuff3/knewstuffaction.h>
99 #else
100 #include <knewstuff2/engine.h>
101 #include <knewstuff2/ui/knewstuffaction.h>
102 #define KNS3 KNS
103 #endif
104 #include <KToolBar>
105 #include <KColorScheme>
106 #include <KProgressDialog>
107
108 #include <QTextStream>
109 #include <QTimer>
110 #include <QAction>
111 #include <QKeyEvent>
112 #include <QInputDialog>
113 #include <QDesktopWidget>
114 #include <QBitmap>
115
116 #include <stdlib.h>
117 #include <locale.h>
118
119 // Uncomment for deeper debugging
120 //#define DEBUG_MAINW
121
122 #ifdef DEBUG_MAINW
123 #include <QDebug>
124 #endif
125
126 static const char version[] = VERSION;
127
128 static const int ID_TIMELINE_POS = 0;
129 namespace Mlt
130 {
131 class Producer;
132 };
133
134 Q_DECLARE_METATYPE(QVector<int16_t>)
135
136
137 EffectsList MainWindow::videoEffects;
138 EffectsList MainWindow::audioEffects;
139 EffectsList MainWindow::customEffects;
140 EffectsList MainWindow::transitions;
141
142 MainWindow::MainWindow(const QString &MltPath, const KUrl & Url, const QString & clipsToLoad, QWidget *parent) :
143     KXmlGuiWindow(parent),
144     m_activeDocument(NULL),
145     m_activeTimeline(NULL),
146     m_recMonitor(NULL),
147     m_renderWidget(NULL),
148 #ifdef USE_JOGSHUTTLE
149     m_jogProcess(NULL),
150     m_jogShuttle(NULL),
151 #endif
152     m_findActivated(false),
153     m_stopmotion(NULL)
154 {   
155     qRegisterMetaType<QVector<int16_t> > ();
156     qRegisterMetaType<stringMap> ("stringMap");
157     qRegisterMetaType<audioByteArray> ("audioByteArray");
158
159     // Init locale
160     QLocale systemLocale = QLocale();
161     setlocale(LC_NUMERIC, NULL);
162     char *separator = localeconv()->decimal_point;
163     if (separator != systemLocale.decimalPoint()) {
164         kDebug()<<"------\n!!! system locale is not similar to Qt's locale... be prepared for bugs!!!\n------";
165         // HACK: There is a locale conflict, so set locale to at least have correct decimal point
166         if (strncmp(separator, ".", 1) == 0) systemLocale = QLocale::c();
167         else if (strncmp(separator, ",", 1) == 0) systemLocale = QLocale("fr_FR.UTF-8");
168     }
169     
170     systemLocale.setNumberOptions(QLocale::OmitGroupSeparator);
171     QLocale::setDefault(systemLocale);
172
173     // Create DBus interface
174     new MainWindowAdaptor(this);
175     QDBusConnection dbus = QDBusConnection::sessionBus();
176     dbus.registerObject("/MainWindow", this);
177
178     if (!KdenliveSettings::colortheme().isEmpty()) slotChangePalette(NULL, KdenliveSettings::colortheme());
179     setFont(KGlobalSettings::toolBarFont());
180     parseProfiles(MltPath);
181     KdenliveSettings::setCurrent_profile(KdenliveSettings::default_profile());
182     m_commandStack = new QUndoGroup;
183     setDockNestingEnabled(true);
184     m_timelineArea = new KTabWidget(this);
185     m_timelineArea->setTabReorderingEnabled(true);
186     m_timelineArea->setTabBarHidden(true);
187     m_timelineArea->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
188     m_timelineArea->setMinimumHeight(200);
189
190     QToolButton *closeTabButton = new QToolButton;
191     connect(closeTabButton, SIGNAL(clicked()), this, SLOT(closeCurrentDocument()));
192     closeTabButton->setIcon(KIcon("tab-close"));
193     closeTabButton->adjustSize();
194     closeTabButton->setToolTip(i18n("Close the current tab"));
195     m_timelineArea->setCornerWidget(closeTabButton);
196     //connect(m_timelineArea, SIGNAL(currentChanged(int)), this, SLOT(activateDocument()));
197
198     connect(&m_findTimer, SIGNAL(timeout()), this, SLOT(findTimeout()));
199     m_findTimer.setSingleShot(true);
200
201     // FIXME: the next call returns a newly allocated object, which leaks
202     initEffects::parseEffectFiles();
203     //initEffects::parseCustomEffectsFile();
204
205     m_monitorManager = new MonitorManager();
206
207     m_shortcutRemoveFocus = new QShortcut(QKeySequence("Esc"), this);
208     connect(m_shortcutRemoveFocus, SIGNAL(activated()), this, SLOT(slotRemoveFocus()));
209
210
211     /// Add Widgets ///
212
213     m_projectListDock = new QDockWidget(i18n("Project Tree"), this);
214     m_projectListDock->setObjectName("project_tree");
215     m_projectList = new ProjectList();
216     m_projectListDock->setWidget(m_projectList);
217     addDockWidget(Qt::TopDockWidgetArea, m_projectListDock);
218
219     m_clipMonitorDock = new QDockWidget(i18n("Clip Monitor"), this);
220     m_clipMonitorDock->setObjectName("clip_monitor");
221     m_clipMonitor = new Monitor("clip", m_monitorManager, QString(), m_timelineArea);
222     m_clipMonitorDock->setWidget(m_clipMonitor);
223     
224     // Connect the project list
225     connect(m_projectList, SIGNAL(clipSelected(DocClipBase *, QPoint, bool)), m_clipMonitor, SLOT(slotSetClipProducer(DocClipBase *, QPoint, bool)));
226     connect(m_projectList, SIGNAL(raiseClipMonitor()), m_clipMonitor, SLOT(activateMonitor()));
227     connect(m_projectList, SIGNAL(loadingIsOver()), this, SLOT(slotElapsedTime()));
228     connect(m_projectList, SIGNAL(displayMessage(const QString&, int)), this, SLOT(slotGotProgressInfo(const QString&, int)));
229     connect(m_projectList, SIGNAL(updateRenderStatus()), this, SLOT(slotCheckRenderStatus()));
230     connect(m_projectList, SIGNAL(clipNeedsReload(const QString&)),this, SLOT(slotUpdateClip(const QString &)));
231     connect(m_projectList, SIGNAL(updateProfile(const QString &)), this, SLOT(slotUpdateProjectProfile(const QString &)));
232     connect(m_projectList, SIGNAL(refreshClip(const QString &, bool)), m_monitorManager, SLOT(slotRefreshCurrentMonitor(const QString &)));
233     connect(m_projectList, SIGNAL(findInTimeline(const QString&)), this, SLOT(slotClipInTimeline(const QString&)));
234     connect(m_clipMonitor, SIGNAL(zoneUpdated(QPoint)), m_projectList, SLOT(slotUpdateClipCut(QPoint)));
235     connect(m_clipMonitor, SIGNAL(extractZone(const QString &, QPoint)), m_projectList, SLOT(slotCutClipJob(const QString &, QPoint)));
236
237     m_projectMonitorDock = new QDockWidget(i18n("Project Monitor"), this);
238     m_projectMonitorDock->setObjectName("project_monitor");
239     m_projectMonitor = new Monitor("project", m_monitorManager, QString());
240     m_projectMonitorDock->setWidget(m_projectMonitor);
241
242 #ifndef Q_WS_MAC
243     m_recMonitorDock = new QDockWidget(i18n("Record Monitor"), this);
244     m_recMonitorDock->setObjectName("record_monitor");
245     m_recMonitor = new RecMonitor("record", m_monitorManager);
246     m_recMonitorDock->setWidget(m_recMonitor);
247     connect(m_recMonitor, SIGNAL(addProjectClip(KUrl)), this, SLOT(slotAddProjectClip(KUrl)));
248     connect(m_recMonitor, SIGNAL(addProjectClipList(KUrl::List)), this, SLOT(slotAddProjectClipList(KUrl::List)));
249     connect(m_recMonitor, SIGNAL(showConfigDialog(int, int)), this, SLOT(slotPreferences(int, int)));
250     
251 #endif /* ! Q_WS_MAC */
252     m_monitorManager->initMonitors(m_clipMonitor, m_projectMonitor, m_recMonitor);
253
254     m_notesDock = new QDockWidget(i18n("Project Notes"), this);
255     m_notesDock->setObjectName("notes_widget");
256     m_notesWidget = new NotesWidget();
257     connect(m_notesWidget, SIGNAL(insertNotesTimecode()), this, SLOT(slotInsertNotesTimecode()));
258     connect(m_notesWidget, SIGNAL(seekProject(int)), m_projectMonitor->render, SLOT(seekToFrame(int)));
259     
260     m_notesWidget->setTabChangesFocus(true);
261 #if KDE_IS_VERSION(4,4,0)
262     m_notesWidget->setClickMessage(i18n("Enter your project notes here ..."));
263 #endif
264     m_notesDock->setWidget(m_notesWidget);
265     addDockWidget(Qt::TopDockWidgetArea, m_notesDock);
266
267     m_effectStackDock = new QDockWidget(i18n("Effect Stack"), this);
268     m_effectStackDock->setObjectName("effect_stack");
269     m_effectStack = new EffectStackView(m_projectMonitor);
270     m_effectStackDock->setWidget(m_effectStack);
271     addDockWidget(Qt::TopDockWidgetArea, m_effectStackDock);
272
273     m_transitionConfigDock = new QDockWidget(i18n("Transition"), this);
274     m_transitionConfigDock->setObjectName("transition");
275     m_transitionConfig = new TransitionSettings(m_projectMonitor);
276     m_transitionConfigDock->setWidget(m_transitionConfig);
277     addDockWidget(Qt::TopDockWidgetArea, m_transitionConfigDock);
278
279     m_effectListDock = new QDockWidget(i18n("Effect List"), this);
280     m_effectListDock->setObjectName("effect_list");
281     m_effectList = new EffectsListView();
282     m_effectListDock->setWidget(m_effectList);
283     addDockWidget(Qt::TopDockWidgetArea, m_effectListDock);
284
285     m_vectorscope = new Vectorscope(m_monitorManager);
286     m_vectorscopeDock = new QDockWidget(i18n("Vectorscope"), this);
287     m_vectorscopeDock->setObjectName(m_vectorscope->widgetName());
288     m_vectorscopeDock->setWidget(m_vectorscope);
289     addDockWidget(Qt::TopDockWidgetArea, m_vectorscopeDock);
290     connect(m_vectorscopeDock, SIGNAL(visibilityChanged(bool)), m_vectorscope, SLOT(forceUpdate(bool)));
291     connect(m_vectorscopeDock, SIGNAL(visibilityChanged(bool)), this, SLOT(slotUpdateGfxScopeFrameRequest()));
292     connect(m_vectorscope, SIGNAL(requestAutoRefresh(bool)), this, SLOT(slotUpdateGfxScopeFrameRequest()));
293     m_gfxScopesList.append(m_vectorscopeDock);
294
295     m_waveform = new Waveform(m_monitorManager);
296     m_waveformDock = new QDockWidget(i18n("Waveform"), this);
297     m_waveformDock->setObjectName(m_waveform->widgetName());
298     m_waveformDock->setWidget(m_waveform);
299     addDockWidget(Qt::TopDockWidgetArea, m_waveformDock);
300     connect(m_waveformDock, SIGNAL(visibilityChanged(bool)), m_waveform, SLOT(forceUpdate(bool)));
301     connect(m_waveformDock, SIGNAL(visibilityChanged(bool)), this, SLOT(slotUpdateGfxScopeFrameRequest()));
302     connect(m_waveform, SIGNAL(requestAutoRefresh(bool)), this, SLOT(slotUpdateGfxScopeFrameRequest()));
303     m_gfxScopesList.append(m_waveformDock);
304
305     m_RGBParade = new RGBParade(m_monitorManager);
306     m_RGBParadeDock = new QDockWidget(i18n("RGB Parade"), this);
307     m_RGBParadeDock->setObjectName(m_RGBParade->widgetName());
308     m_RGBParadeDock->setWidget(m_RGBParade);
309     addDockWidget(Qt::TopDockWidgetArea, m_RGBParadeDock);
310     connect(m_RGBParadeDock, SIGNAL(visibilityChanged(bool)), m_RGBParade, SLOT(forceUpdate(bool)));
311     connect(m_RGBParadeDock, SIGNAL(visibilityChanged(bool)), this, SLOT(slotUpdateGfxScopeFrameRequest()));
312     connect(m_RGBParade, SIGNAL(requestAutoRefresh(bool)), this, SLOT(slotUpdateGfxScopeFrameRequest()));
313     m_gfxScopesList.append(m_RGBParadeDock);
314
315     m_histogram = new Histogram(m_monitorManager);
316     m_histogramDock = new QDockWidget(i18n("Histogram"), this);
317     m_histogramDock->setObjectName(m_histogram->widgetName());
318     m_histogramDock->setWidget(m_histogram);
319     addDockWidget(Qt::TopDockWidgetArea, m_histogramDock);
320     connect(m_histogramDock, SIGNAL(visibilityChanged(bool)), m_histogram, SLOT(forceUpdate(bool)));
321     connect(m_histogramDock, SIGNAL(visibilityChanged(bool)), this, SLOT(slotUpdateGfxScopeFrameRequest()));
322     connect(m_histogram, SIGNAL(requestAutoRefresh(bool)), this, SLOT(slotUpdateGfxScopeFrameRequest()));
323     m_gfxScopesList.append(m_histogramDock);
324
325
326     m_audiosignal = new AudioSignal;
327     m_audiosignalDock = new QDockWidget(i18n("Audio Signal"), this);
328     m_audiosignalDock->setObjectName("audiosignal");
329     m_audiosignalDock->setWidget(m_audiosignal);
330     addDockWidget(Qt::TopDockWidgetArea, m_audiosignalDock);
331     connect(m_audiosignalDock, SIGNAL(visibilityChanged(bool)), this, SLOT(slotUpdateAudioScopeFrameRequest()));
332     connect(m_audiosignal, SIGNAL(updateAudioMonitoring()), this, SLOT(slotUpdateAudioScopeFrameRequest()));
333
334     m_audioSpectrum = new AudioSpectrum();
335     m_audioSpectrumDock = new QDockWidget(i18n("AudioSpectrum"), this);
336     m_audioSpectrumDock->setObjectName(m_audioSpectrum->widgetName());
337     m_audioSpectrumDock->setWidget(m_audioSpectrum);
338     addDockWidget(Qt::TopDockWidgetArea, m_audioSpectrumDock);
339     m_audioScopesList.append(m_audioSpectrum);
340     connect(m_audioSpectrumDock, SIGNAL(visibilityChanged(bool)), this, SLOT(slotUpdateAudioScopeFrameRequest()));
341     connect(m_audioSpectrum, SIGNAL(requestAutoRefresh(bool)), this, SLOT(slotUpdateAudioScopeFrameRequest()));
342
343     m_spectrogram = new Spectrogram();
344     m_spectrogramDock = new QDockWidget(i18n("Spectrogram"), this);
345     m_spectrogramDock->setObjectName(m_spectrogram->widgetName());
346     m_spectrogramDock->setWidget(m_spectrogram);
347     addDockWidget(Qt::TopDockWidgetArea, m_spectrogramDock);
348     m_audioScopesList.append(m_spectrogram);
349     connect(m_audioSpectrumDock, SIGNAL(visibilityChanged(bool)), this, SLOT(slotUpdateAudioScopeFrameRequest()));
350     connect(m_audioSpectrum, SIGNAL(requestAutoRefresh(bool)), this, SLOT(slotUpdateAudioScopeFrameRequest()));
351
352     // Connect the audio signal to the audio scope slots
353     bool b = true;
354     if (m_projectMonitor) {
355         qDebug() << "project monitor connected";
356         b &= connect(m_projectMonitor->render, SIGNAL(audioSamplesSignal(QVector<int16_t>, int, int, int)),
357                      m_audioSpectrum, SLOT(slotReceiveAudio(QVector<int16_t>, int, int, int)));
358         b &= connect(m_projectMonitor->render, SIGNAL(audioSamplesSignal(const QVector<int16_t>&, const int&, const int&, const int&)),
359                      m_audiosignal, SLOT(slotReceiveAudio(const QVector<int16_t>&, const int&, const int&, const int&)));
360         b &= connect(m_projectMonitor->render, SIGNAL(audioSamplesSignal(QVector<int16_t>,int,int,int)),
361                      m_spectrogram, SLOT(slotReceiveAudio(QVector<int16_t>,int,int,int)));
362     }
363     if (m_clipMonitor) {
364         qDebug() << "clip monitor connected";
365         b &= connect(m_clipMonitor->render, SIGNAL(audioSamplesSignal(QVector<int16_t>, int, int, int)),
366                      m_audioSpectrum, SLOT(slotReceiveAudio(QVector<int16_t>, int, int, int)));
367         b &= connect(m_clipMonitor->render, SIGNAL(audioSamplesSignal(const QVector<int16_t>&, int, int, int)),
368                      m_audiosignal, SLOT(slotReceiveAudio(const QVector<int16_t>&, int, int, int)));
369         b &= connect(m_clipMonitor->render, SIGNAL(audioSamplesSignal(QVector<int16_t>,int,int,int)),
370                      m_spectrogram, SLOT(slotReceiveAudio(QVector<int16_t>,int,int,int)));
371     }
372     // Ensure connections were set up correctly
373     Q_ASSERT(b);
374
375
376
377     // Add monitors here to keep them at the right of the window
378     addDockWidget(Qt::TopDockWidgetArea, m_clipMonitorDock);
379     addDockWidget(Qt::TopDockWidgetArea, m_projectMonitorDock);
380 #ifndef Q_WS_MAC
381     addDockWidget(Qt::TopDockWidgetArea, m_recMonitorDock);
382 #endif
383
384     m_undoViewDock = new QDockWidget(i18n("Undo History"), this);
385     m_undoViewDock->setObjectName("undo_history");
386     m_undoView = new QUndoView();
387     m_undoView->setCleanIcon(KIcon("edit-clear"));
388     m_undoView->setEmptyLabel(i18n("Clean"));
389     m_undoViewDock->setWidget(m_undoView);
390     m_undoView->setGroup(m_commandStack);
391     addDockWidget(Qt::TopDockWidgetArea, m_undoViewDock);
392
393
394     setupActions();
395     connect(m_commandStack, SIGNAL(cleanChanged(bool)), m_saveAction, SLOT(setDisabled(bool)));
396
397
398     // Close non-general docks for the initial layout
399     // only show important ones
400     m_histogramDock->close();
401     m_RGBParadeDock->close();
402     m_waveformDock->close();
403     m_vectorscopeDock->close();
404
405     m_audioSpectrumDock->close();
406     m_spectrogramDock->close();
407     m_audiosignalDock->close();
408
409     m_undoViewDock->close();
410
411
412
413     /// Tabify Widgets ///
414     tabifyDockWidget(m_effectListDock, m_effectStackDock);
415     tabifyDockWidget(m_effectListDock, m_transitionConfigDock);
416     tabifyDockWidget(m_projectListDock, m_notesDock);
417
418     tabifyDockWidget(m_clipMonitorDock, m_projectMonitorDock);
419 #ifndef Q_WS_MAC
420     tabifyDockWidget(m_clipMonitorDock, m_recMonitorDock);
421 #endif
422
423
424
425
426     setCentralWidget(m_timelineArea);
427
428
429     m_fileOpenRecent = KStandardAction::openRecent(this, SLOT(openFile(const KUrl &)), actionCollection());
430     readOptions();
431     m_fileRevert = KStandardAction::revert(this, SLOT(slotRevert()), actionCollection());
432     m_fileRevert->setEnabled(false);
433
434     // Prepare layout actions
435     KActionCategory *layoutActions = new KActionCategory(i18n("Layouts"), actionCollection());
436     m_loadLayout = new KSelectAction(i18n("Load Layout"), actionCollection());
437     for (int i = 1; i < 5; i++) {
438         KAction *load = new KAction(KIcon(), i18n("Layout %1").arg(i), this);
439         load->setData("_" + QString::number(i));
440         layoutActions->addAction("load_layout" + QString::number(i), load);
441         m_loadLayout->addAction(load);
442         KAction *save = new KAction(KIcon(), i18n("Save As Layout %1").arg(i), this);
443         save->setData("_" + QString::number(i));
444         layoutActions->addAction("save_layout" + QString::number(i), save);
445     }
446     layoutActions->addAction("load_layouts", m_loadLayout);
447     connect(m_loadLayout, SIGNAL(triggered(QAction*)), this, SLOT(slotLoadLayout(QAction*)));
448
449     KAction *action;
450     // Stop motion actions. Beware of the order, we MUST use the same order in stopmotion/stopmotion.cpp
451     m_stopmotion_actions = new KActionCategory(i18n("Stop Motion"), actionCollection());
452     action = new KAction(KIcon("media-record"), i18n("Capture frame"), this);
453     //action->setShortcutContext(Qt::WidgetWithChildrenShortcut);
454     m_stopmotion_actions->addAction("stopmotion_capture", action);
455     action = new KAction(i18n("Switch live / captured frame"), this);
456     //action->setShortcutContext(Qt::WidgetWithChildrenShortcut);
457     m_stopmotion_actions->addAction("stopmotion_switch", action);
458     action = new KAction(KIcon("edit-paste"), i18n("Show last frame over video"), this);
459     action->setCheckable(true);
460     action->setChecked(false);
461     m_stopmotion_actions->addAction("stopmotion_overlay", action);
462
463     // Build effects menu
464     m_effectsMenu = new QMenu(i18n("Add Effect"));
465     m_effectActions = new KActionCategory(i18n("Effects"), actionCollection());
466     m_effectList->reloadEffectList(m_effectsMenu, m_effectActions);
467     m_effectsActionCollection->readSettings();
468     
469     setupGUI();
470
471     // Find QDockWidget tab bars and show / hide widget title bars on right click
472     QList <QTabBar *> tabs = findChildren<QTabBar *>();
473     for (int i = 0; i < tabs.count(); i++) {
474         tabs.at(i)->setContextMenuPolicy(Qt::CustomContextMenu);
475         connect(tabs.at(i), SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(slotSwitchTitles()));
476     }
477
478     /*ScriptingPart* sp = new ScriptingPart(this, QStringList());
479     guiFactory()->addClient(sp);*/
480
481     QMenu *saveLayout = (QMenu*)(factory()->container("layout_save_as", this));
482     if (saveLayout)
483         connect(saveLayout, SIGNAL(triggered(QAction*)), this, SLOT(slotSaveLayout(QAction*)));
484
485
486     // Load layout names from config file
487     loadLayouts();
488
489     loadPlugins();
490     loadTranscoders();
491     loadStabilize();
492
493     m_projectMonitor->setupMenu(static_cast<QMenu*>(factory()->container("monitor_go", this)), m_playZone, m_loopZone, NULL, m_loopClip);
494     m_clipMonitor->setupMenu(static_cast<QMenu*>(factory()->container("monitor_go", this)), m_playZone, m_loopZone, static_cast<QMenu*>(factory()->container("marker_menu", this)));
495
496     QMenu *clipInTimeline = static_cast<QMenu*>(factory()->container("clip_in_timeline", this));
497     clipInTimeline->setIcon(KIcon("go-jump"));
498         QHash<QString,QMenu*> menus;
499         menus.insert("addMenu",static_cast<QMenu*>(factory()->container("generators", this)));
500         menus.insert("transcodeMenu",static_cast<QMenu*>(factory()->container("transcoders", this)));
501         menus.insert("stabilizeMenu",static_cast<QMenu*>(factory()->container("stabilize", this)));
502         menus.insert("inTimelineMenu",clipInTimeline);
503     m_projectList->setupGeneratorMenu(menus);
504
505     // build themes menus
506     QMenu *themesMenu = static_cast<QMenu*>(factory()->container("themes_menu", this));
507     QActionGroup *themegroup = new QActionGroup(this);
508     themegroup->setExclusive(true);
509     action = new KAction(i18n("Default"), this);
510     action->setCheckable(true);
511     themegroup->addAction(action);
512     if (KdenliveSettings::colortheme().isEmpty()) action->setChecked(true);
513
514     const QStringList schemeFiles = KGlobal::dirs()->findAllResources("data", "color-schemes/*.colors", KStandardDirs::NoDuplicates);
515
516     for (int i = 0; i < schemeFiles.size(); ++i) {
517         // get the file name
518         const QString filename = schemeFiles.at(i);
519         const QFileInfo info(filename);
520
521         // add the entry
522         KSharedConfigPtr config = KSharedConfig::openConfig(filename);
523         QIcon icon = createSchemePreviewIcon(config);
524         KConfigGroup group(config, "General");
525         const QString name = group.readEntry("Name", info.baseName());
526         action = new KAction(name, this);
527         action->setData(filename);
528         action->setIcon(icon);
529         action->setCheckable(true);
530         themegroup->addAction(action);
531         if (KdenliveSettings::colortheme() == filename) action->setChecked(true);
532     }
533
534     /*KGlobal::dirs()->addResourceDir("themes", KStandardDirs::installPath("data") + QString("kdenlive/themes"));
535     QStringList themes = KGlobal::dirs()->findAllResources("themes", QString(), KStandardDirs::Recursive | KStandardDirs::NoDuplicates);
536     for (QStringList::const_iterator it = themes.constBegin(); it != themes.constEnd(); ++it)
537     {
538     QFileInfo fi(*it);
539         action = new QAction(fi.fileName(), this);
540         action->setData(*it);
541     action->setCheckable(true);
542     themegroup->addAction(action);
543     if (KdenliveSettings::colortheme() == *it) action->setChecked(true);
544     }*/
545     themesMenu->addActions(themegroup->actions());
546     connect(themesMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotChangePalette(QAction*)));
547
548     // Setup and fill effects and transitions menus.
549
550
551     QMenu *m = static_cast<QMenu*>(factory()->container("video_effects_menu", this));
552     m->addActions(m_effectsMenu->actions());
553
554
555     m_transitionsMenu = new QMenu(i18n("Add Transition"), this);
556     for (int i = 0; i < transitions.count(); ++i)
557         m_transitionsMenu->addAction(m_transitions[i]);
558
559     connect(m, SIGNAL(triggered(QAction *)), this, SLOT(slotAddVideoEffect(QAction *)));
560     connect(m_effectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddVideoEffect(QAction *)));
561     connect(m_transitionsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddTransition(QAction *)));
562
563     m_effectStack->setMenu(m_effectsMenu);
564
565     QMenu *viewMenu = static_cast<QMenu*>(factory()->container("dockwindows", this));
566     const QList<QAction *> viewActions = createPopupMenu()->actions();
567     viewMenu->insertActions(NULL, viewActions);
568
569     m_timelineContextMenu = new QMenu(this);
570     m_timelineContextClipMenu = new QMenu(this);
571     m_timelineContextTransitionMenu = new QMenu(this);
572
573     m_timelineContextMenu->addAction(actionCollection()->action("insert_space"));
574     m_timelineContextMenu->addAction(actionCollection()->action("delete_space"));
575     m_timelineContextMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Paste)));
576
577     m_timelineContextClipMenu->addAction(actionCollection()->action("clip_in_project_tree"));
578     //m_timelineContextClipMenu->addAction(actionCollection()->action("clip_to_project_tree"));
579     m_timelineContextClipMenu->addAction(actionCollection()->action("edit_item_duration"));
580     m_timelineContextClipMenu->addAction(actionCollection()->action("delete_item"));
581     m_timelineContextClipMenu->addSeparator();
582     m_timelineContextClipMenu->addAction(actionCollection()->action("group_clip"));
583     m_timelineContextClipMenu->addAction(actionCollection()->action("ungroup_clip"));
584     m_timelineContextClipMenu->addAction(actionCollection()->action("split_audio"));
585     m_timelineContextClipMenu->addSeparator();
586     m_timelineContextClipMenu->addAction(actionCollection()->action("cut_timeline_clip"));
587     m_timelineContextClipMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Copy)));
588     m_timelineContextClipMenu->addAction(actionCollection()->action("paste_effects"));
589     m_timelineContextClipMenu->addSeparator();
590
591     QMenu *markersMenu = (QMenu*)(factory()->container("marker_menu", this));
592     m_timelineContextClipMenu->addMenu(markersMenu);
593     m_timelineContextClipMenu->addSeparator();
594     m_timelineContextClipMenu->addMenu(m_transitionsMenu);
595     m_timelineContextClipMenu->addMenu(m_effectsMenu);
596
597     m_timelineContextTransitionMenu->addAction(actionCollection()->action("edit_item_duration"));
598     m_timelineContextTransitionMenu->addAction(actionCollection()->action("delete_item"));
599     m_timelineContextTransitionMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Copy)));
600
601     m_timelineContextTransitionMenu->addAction(actionCollection()->action("auto_transition"));
602
603     connect(m_projectMonitorDock, SIGNAL(visibilityChanged(bool)), m_projectMonitor, SLOT(refreshMonitor(bool)));
604     connect(m_clipMonitorDock, SIGNAL(visibilityChanged(bool)), m_clipMonitor, SLOT(refreshMonitor(bool)));
605     connect(m_monitorManager, SIGNAL(checkColorScopes()), this, SLOT(slotUpdateColorScopes()));
606     connect(m_monitorManager, SIGNAL(clearScopes()), this, SLOT(slotClearColorScopes()));
607     connect(m_effectList, SIGNAL(addEffect(const QDomElement)), this, SLOT(slotAddEffect(const QDomElement)));
608     connect(m_effectList, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
609
610     slotConnectMonitors();
611
612     // Open or create a file.  Command line argument passed in Url has
613     // precedence, then "openlastproject", then just a plain empty file.
614     // If opening Url fails, openlastproject will _not_ be used.
615     if (!Url.isEmpty()) {
616         // delay loading so that the window shows up
617         m_startUrl = Url;
618         QTimer::singleShot(500, this, SLOT(openFile()));
619     } else if (KdenliveSettings::openlastproject()) {
620         QTimer::singleShot(500, this, SLOT(openLastFile()));
621     } else { //if (m_timelineArea->count() == 0) {
622         newFile(false);
623     }
624
625     if (!clipsToLoad.isEmpty() && m_activeDocument) {
626         QStringList list = clipsToLoad.split(',');
627         QList <QUrl> urls;
628         foreach(QString path, list) {
629             kDebug() << QDir::current().absoluteFilePath(path);
630             urls << QUrl::fromLocalFile(QDir::current().absoluteFilePath(path));
631         }
632         m_projectList->slotAddClip(urls);
633     }
634
635 #ifdef USE_JOGSHUTTLE
636     activateShuttleDevice();
637 #endif
638     m_projectListDock->raise();
639
640     actionCollection()->addAssociatedWidget(m_clipMonitor->container());
641     actionCollection()->addAssociatedWidget(m_projectMonitor->container());
642     
643     // Populate encoding profiles
644     KConfig conf("encodingprofiles.rc", KConfig::FullConfig, "appdata");
645     if (KdenliveSettings::proxyparams().isEmpty() || KdenliveSettings::proxyextension().isEmpty()) {
646         KConfigGroup group(&conf, "proxy");
647         QMap< QString, QString > values = group.entryMap();
648         QMapIterator<QString, QString> i(values);
649         if (i.hasNext()) {
650             i.next();
651             QString data = i.value();
652             KdenliveSettings::setProxyparams(data.section(';', 0, 0));
653             KdenliveSettings::setProxyextension(data.section(';', 1, 1));
654         }
655     }
656     if (KdenliveSettings::v4l_parameters().isEmpty() || KdenliveSettings::v4l_extension().isEmpty()) {
657         KConfigGroup group(&conf, "video4linux");
658         QMap< QString, QString > values = group.entryMap();
659         QMapIterator<QString, QString> i(values);
660         if (i.hasNext()) {
661             i.next();
662             QString data = i.value();
663             KdenliveSettings::setV4l_parameters(data.section(';', 0, 0));
664             KdenliveSettings::setV4l_extension(data.section(';', 1, 1));
665         }
666     }
667     if (KdenliveSettings::decklink_parameters().isEmpty() || KdenliveSettings::decklink_extension().isEmpty()) {
668         KConfigGroup group(&conf, "decklink");
669         QMap< QString, QString > values = group.entryMap();
670         QMapIterator<QString, QString> i(values);
671         if (i.hasNext()) {
672             i.next();
673             QString data = i.value();
674             KdenliveSettings::setDecklink_parameters(data.section(';', 0, 0));
675             KdenliveSettings::setDecklink_extension(data.section(';', 1, 1));
676         }
677     }
678 }
679
680 MainWindow::~MainWindow()
681 {
682     if (m_stopmotion) {
683         delete m_stopmotion;
684     }
685     m_effectStack->slotClipItemSelected(NULL, 0);
686     m_transitionConfig->slotTransitionItemSelected(NULL, 0, QPoint(), false);
687
688     if (m_projectMonitor) m_projectMonitor->stop();
689     if (m_clipMonitor) m_clipMonitor->stop();
690
691     delete m_activeTimeline;
692     delete m_effectStack;
693     delete m_transitionConfig;
694     delete m_activeDocument;
695     delete m_projectMonitor;
696     delete m_clipMonitor;
697     delete m_shortcutRemoveFocus;
698     delete[] m_transitions;
699     Mlt::Factory::close();
700 }
701
702 //virtual
703 bool MainWindow::queryClose()
704 {
705     if (m_renderWidget) {
706         int waitingJobs = m_renderWidget->waitingJobsCount();
707         if (waitingJobs > 0) {
708             switch (KMessageBox::warningYesNoCancel(this, i18np("You have 1 rendering job waiting in the queue.\nWhat do you want to do with this job?", "You have %1 rendering jobs waiting in the queue.\nWhat do you want to do with these jobs?", waitingJobs), QString(), KGuiItem(i18n("Start them now")), KGuiItem(i18n("Delete them")))) {
709             case KMessageBox::Yes :
710                 // create script with waiting jobs and start it
711                 if (m_renderWidget->startWaitingRenderJobs() == false) return false;
712                 break;
713             case KMessageBox::No :
714                 // Don't do anything, jobs will be deleted
715                 break;
716             default:
717                 return false;
718             }
719         }
720     }
721     saveOptions();
722     if (m_monitorManager) m_monitorManager->stopActiveMonitor();
723     // warn the user to save if document is modified and we have clips in our project list
724     if (m_activeDocument && m_activeDocument->isModified() &&
725             ((m_projectList->documentClipList().isEmpty() && !m_activeDocument->url().isEmpty()) ||
726              !m_projectList->documentClipList().isEmpty())) {
727         raise();
728         activateWindow();
729         QString message;
730         if (m_activeDocument->url().fileName().isEmpty())
731             message = i18n("Save changes to document?");
732         else
733             message = i18n("The project <b>\"%1\"</b> has been changed.\nDo you want to save your changes?").arg(m_activeDocument->url().fileName());
734         switch (KMessageBox::warningYesNoCancel(this, message)) {
735         case KMessageBox::Yes :
736             // save document here. If saving fails, return false;
737             return saveFile();
738         case KMessageBox::No :
739             // User does not want to save the changes, clear recovery files
740             m_activeDocument->m_autosave->resize(0);
741             return true;
742         default: // cancel
743             return false;
744         }
745     }
746     return true;
747 }
748
749 void MainWindow::loadPlugins()
750 {
751     foreach(QObject * plugin, QPluginLoader::staticInstances()) {
752         populateMenus(plugin);
753     }
754
755     QStringList directories = KGlobal::dirs()->findDirs("module", QString());
756     QStringList filters;
757     filters << "libkdenlive*";
758     foreach(const QString & folder, directories) {
759         kDebug() << "Parsing plugin folder: " << folder;
760         QDir pluginsDir(folder);
761         foreach(const QString & fileName,
762                 pluginsDir.entryList(filters, QDir::Files)) {
763             /*
764              * Avoid loading the same plugin twice when there is more than one
765              * installation.
766              */
767             if (!m_pluginFileNames.contains(fileName)) {
768                 kDebug() << "Found plugin: " << fileName;
769                 QPluginLoader loader(pluginsDir.absoluteFilePath(fileName));
770                 QObject *plugin = loader.instance();
771                 if (plugin) {
772                     populateMenus(plugin);
773                     m_pluginFileNames += fileName;
774                 } else
775                     kDebug() << "Error loading plugin: " << fileName << ", " << loader.errorString();
776             }
777         }
778     }
779 }
780
781 void MainWindow::populateMenus(QObject *plugin)
782 {
783     QMenu *addMenu = static_cast<QMenu*>(factory()->container("generators", this));
784     ClipGenerator *iGenerator = qobject_cast<ClipGenerator *>(plugin);
785     if (iGenerator)
786         addToMenu(plugin, iGenerator->generators(KdenliveSettings::producerslist()), addMenu, SLOT(generateClip()),
787                   NULL);
788 }
789
790 void MainWindow::addToMenu(QObject *plugin, const QStringList &texts,
791                            QMenu *menu, const char *member,
792                            QActionGroup *actionGroup)
793 {
794     kDebug() << "// ADD to MENU" << texts;
795     foreach(const QString & text, texts) {
796         QAction *action = new QAction(text, plugin);
797         action->setData(text);
798         connect(action, SIGNAL(triggered()), this, member);
799         menu->addAction(action);
800
801         if (actionGroup) {
802             action->setCheckable(true);
803             actionGroup->addAction(action);
804         }
805     }
806 }
807
808 void MainWindow::aboutPlugins()
809 {
810     //PluginDialog dialog(pluginsDir.path(), m_pluginFileNames, this);
811     //dialog.exec();
812 }
813
814
815 void MainWindow::generateClip()
816 {
817     QAction *action = qobject_cast<QAction *>(sender());
818     ClipGenerator *iGenerator = qobject_cast<ClipGenerator *>(action->parent());
819
820     KUrl clipUrl = iGenerator->generatedClip(action->data().toString(), m_activeDocument->projectFolder(),
821                    QStringList(), QStringList(), m_activeDocument->fps(), m_activeDocument->width(), m_activeDocument->height());
822     if (!clipUrl.isEmpty()) {
823         m_projectList->slotAddClip(QList <QUrl> () << clipUrl);
824     }
825 }
826
827 void MainWindow::saveProperties(KConfigGroup &config)
828 {
829     // save properties here,used by session management
830     saveFile();
831     KMainWindow::saveProperties(config);
832 }
833
834
835 void MainWindow::readProperties(const KConfigGroup &config)
836 {
837     // read properties here,used by session management
838     KMainWindow::readProperties(config);
839     QString Lastproject = config.group("Recent Files").readPathEntry("File1", QString());
840     openFile(KUrl(Lastproject));
841 }
842
843 void MainWindow::slotReloadEffects()
844 {
845     initEffects::parseCustomEffectsFile();
846     m_effectList->reloadEffectList(m_effectsMenu, m_effectActions);
847 }
848
849 #ifdef USE_JOGSHUTTLE
850 void MainWindow::activateShuttleDevice()
851 {
852     delete m_jogShuttle;
853     m_jogShuttle = NULL;
854     delete m_jogProcess;
855     m_jogProcess = NULL;
856     if (KdenliveSettings::enableshuttle() == false) return;
857     
858     m_jogProcess = new JogShuttle(KdenliveSettings::shuttledevice());
859     m_jogShuttle = new JogShuttleAction(m_jogProcess, JogShuttleConfig::actionMap(KdenliveSettings::shuttlebuttons()));
860     
861     connect(m_jogShuttle, SIGNAL(rewindOneFrame()), m_monitorManager, SLOT(slotRewindOneFrame()));
862     connect(m_jogShuttle, SIGNAL(forwardOneFrame()), m_monitorManager, SLOT(slotForwardOneFrame()));
863     connect(m_jogShuttle, SIGNAL(rewind(double)), m_monitorManager, SLOT(slotRewind(double)));
864     connect(m_jogShuttle, SIGNAL(forward(double)), m_monitorManager, SLOT(slotForward(double)));
865     connect(m_jogShuttle, SIGNAL(action(const QString&)), this, SLOT(slotDoAction(const QString&)));
866 }
867 #endif /* USE_JOGSHUTTLE */
868
869 void MainWindow::slotDoAction(const QString& action_name)
870 {
871     QAction* action = actionCollection()->action(action_name);
872     if (!action) {
873         fprintf(stderr, "%s", QString("shuttle action '%1' unknown\n").arg(action_name).toAscii().constData());
874         return;
875     }
876     action->trigger();
877 }
878
879 void MainWindow::configureNotifications()
880 {
881     KNotifyConfigWidget::configure(this);
882 }
883
884 void MainWindow::slotFullScreen()
885 {
886     KToggleFullScreenAction::setFullScreen(this, actionCollection()->action("fullscreen")->isChecked());
887 }
888
889 void MainWindow::slotAddEffect(const QDomElement effect)
890 {
891     if (!m_activeDocument) return;
892     if (effect.isNull()) {
893         kDebug() << "--- ERROR, TRYING TO APPEND NULL EFFECT";
894         return;
895     }
896     QDomElement effectToAdd = effect.cloneNode().toElement();
897     bool ok;
898     int ix = m_effectStack->isTrackMode(&ok);
899     if (ok) m_activeTimeline->projectView()->slotAddTrackEffect(effectToAdd, m_activeDocument->tracksCount() - ix);
900     else m_activeTimeline->projectView()->slotAddEffect(effectToAdd, GenTime(), -1);
901 }
902
903 void MainWindow::slotUpdateClip(const QString &id)
904 {
905     if (!m_activeDocument) return;
906     DocClipBase *clip = m_activeDocument->clipManager()->getClipById(id);
907     if (!clip) return;
908     if (clip->numReferences() > 0) m_activeTimeline->projectView()->slotUpdateClip(id);
909     if (m_clipMonitor->activeClip() && m_clipMonitor->activeClip()->getId() == id) {
910         Mlt::Producer *monitorProducer = clip->getCloneProducer();
911         m_clipMonitor->updateClipProducer(monitorProducer);
912     }
913     clip->cleanupProducers();
914 }
915
916 void MainWindow::slotConnectMonitors()
917 {
918     m_projectList->setRenderer(m_projectMonitor->render);
919     connect(m_projectList, SIGNAL(deleteProjectClips(QStringList, QMap<QString, QString>)), this, SLOT(slotDeleteProjectClips(QStringList, QMap<QString, QString>)));
920     connect(m_projectList, SIGNAL(showClipProperties(DocClipBase *)), this, SLOT(slotShowClipProperties(DocClipBase *)));
921     connect(m_projectList, SIGNAL(showClipProperties(QList <DocClipBase *>, QMap<QString, QString>)), this, SLOT(slotShowClipProperties(QList <DocClipBase *>, QMap<QString, QString>)));
922     connect(m_projectMonitor->render, SIGNAL(replyGetImage(const QString &, const QString &, int, int)), m_projectList, SLOT(slotReplyGetImage(const QString &, const QString &, int, int)));
923     connect(m_projectMonitor->render, SIGNAL(replyGetImage(const QString &, const QImage &)), m_projectList, SLOT(slotReplyGetImage(const QString &, const QImage &)));
924     connect(m_projectMonitor->render, SIGNAL(replyGetFileProperties(const QString &, Mlt::Producer*, const stringMap &, const stringMap &, bool)), m_projectList, SLOT(slotReplyGetFileProperties(const QString &, Mlt::Producer*, const stringMap &, const stringMap &, bool)));
925
926     connect(m_projectMonitor->render, SIGNAL(removeInvalidClip(const QString &, bool)), m_projectList, SLOT(slotRemoveInvalidClip(const QString &, bool)));
927     
928     connect(m_projectMonitor->render, SIGNAL(removeInvalidProxy(const QString &, bool)), m_projectList, SLOT(slotRemoveInvalidProxy(const QString &, bool)));
929
930     connect(m_clipMonitor, SIGNAL(refreshClipThumbnail(const QString &, bool)), m_projectList, SLOT(slotRefreshClipThumbnail(const QString &, bool)));
931
932     connect(m_clipMonitor, SIGNAL(adjustMonitorSize()), this, SLOT(slotAdjustClipMonitor()));
933     connect(m_projectMonitor, SIGNAL(adjustMonitorSize()), this, SLOT(slotAdjustProjectMonitor()));
934
935     connect(m_projectMonitor, SIGNAL(requestFrameForAnalysis(bool)), this, SLOT(slotMonitorRequestRenderFrame(bool)));
936
937     connect(m_clipMonitor, SIGNAL(saveZone(Render *, QPoint, DocClipBase *)), this, SLOT(slotSaveZone(Render *, QPoint, DocClipBase *)));
938     connect(m_projectMonitor, SIGNAL(saveZone(Render *, QPoint, DocClipBase *)), this, SLOT(slotSaveZone(Render *, QPoint, DocClipBase *)));
939 }
940
941 void MainWindow::slotAdjustClipMonitor()
942 {
943     m_clipMonitorDock->updateGeometry();
944     m_clipMonitorDock->adjustSize();
945     m_clipMonitor->resetSize();
946 }
947
948 void MainWindow::slotAdjustProjectMonitor()
949 {
950     m_projectMonitorDock->updateGeometry();
951     m_projectMonitorDock->adjustSize();
952     m_projectMonitor->resetSize();
953 }
954
955
956 class NameGrabbingKActionCollection {
957 public:
958   NameGrabbingKActionCollection(KActionCollection* collection, QStringList& action_names)
959     : m_collection(collection), m_action_names(action_names) {
960       m_action_names.clear();
961     }
962   KAction* addAction(const QString& action_name) {
963     m_action_names << action_name;
964     return m_collection->addAction(action_name);
965   }
966   void addAction(const QString& action_name, QAction* action) {
967     m_action_names << action_name;
968     m_collection->addAction(action_name, action);
969   }
970   operator KActionCollection*() { return m_collection; }
971   const QStringList& actionNames() const { return m_action_names; }
972 private:
973   KActionCollection* m_collection;
974   QStringList& m_action_names;
975 };
976
977 void MainWindow::setupActions()
978 {
979
980     NameGrabbingKActionCollection collection(actionCollection(), m_action_names);
981     m_timecodeFormat = new KComboBox(this);
982     m_timecodeFormat->addItem(i18n("hh:mm:ss:ff"));
983     m_timecodeFormat->addItem(i18n("Frames"));
984     if (KdenliveSettings::frametimecode()) m_timecodeFormat->setCurrentIndex(1);
985     connect(m_timecodeFormat, SIGNAL(activated(int)), this, SLOT(slotUpdateTimecodeFormat(int)));
986
987     m_statusProgressBar = new QProgressBar(this);
988     m_statusProgressBar->setMinimum(0);
989     m_statusProgressBar->setMaximum(100);
990     m_statusProgressBar->setMaximumWidth(150);
991     m_statusProgressBar->setVisible(false);
992
993     KToolBar *toolbar = new KToolBar("statusToolBar", this, Qt::BottomToolBarArea);
994     toolbar->setMovable(false);
995     KColorScheme scheme(palette().currentColorGroup(), KColorScheme::Window, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
996     QColor buttonBg = scheme.background(KColorScheme::LinkBackground).color();
997     QColor buttonBord = scheme.foreground(KColorScheme::LinkText).color();
998     QColor buttonBord2 = scheme.shade(KColorScheme::LightShade);
999     statusBar()->setStyleSheet(QString("QStatusBar QLabel {font-size:%1pt;} QStatusBar::item { border: 0px; font-size:%1pt;padding:0px; }").arg(statusBar()->font().pointSize()));
1000     QString style1 = QString("QToolBar { border: 0px } QToolButton { border-style: inset; border:1px solid transparent;border-radius: 3px;margin: 0px 3px;padding: 0px;} QToolButton:hover { background: rgb(%7, %8, %9);border-style: inset; border:1px solid rgb(%7, %8, %9);border-radius: 3px;} QToolButton:checked { background-color: rgb(%1, %2, %3); border-style: inset; border:1px solid rgb(%4, %5, %6);border-radius: 3px;}").arg(buttonBg.red()).arg(buttonBg.green()).arg(buttonBg.blue()).arg(buttonBord.red()).arg(buttonBord.green()).arg(buttonBord.blue()).arg(buttonBord2.red()).arg(buttonBord2.green()).arg(buttonBord2.blue());
1001     QString styleBorderless = "QToolButton { border-width: 0px;margin: 1px 3px 0px;padding: 0px;}";
1002
1003     //create edit mode buttons
1004     m_normalEditTool = new KAction(KIcon("kdenlive-normal-edit"), i18n("Normal mode"), this);
1005     m_normalEditTool->setShortcut(i18nc("Normal editing", "n"));
1006     toolbar->addAction(m_normalEditTool);
1007     m_normalEditTool->setCheckable(true);
1008     m_normalEditTool->setChecked(true);
1009
1010     m_overwriteEditTool = new KAction(KIcon("kdenlive-overwrite-edit"), i18n("Overwrite mode"), this);
1011     //m_overwriteEditTool->setShortcut(i18nc("Overwrite mode shortcut", "o"));
1012     toolbar->addAction(m_overwriteEditTool);
1013     m_overwriteEditTool->setCheckable(true);
1014     m_overwriteEditTool->setChecked(false);
1015
1016     m_insertEditTool = new KAction(KIcon("kdenlive-insert-edit"), i18n("Insert mode"), this);
1017     //m_insertEditTool->setShortcut(i18nc("Insert mode shortcut", "i"));
1018     toolbar->addAction(m_insertEditTool);
1019     m_insertEditTool->setCheckable(true);
1020     m_insertEditTool->setChecked(false);
1021     // not implemented yet
1022     m_insertEditTool->setEnabled(false);
1023
1024     QActionGroup *editGroup = new QActionGroup(this);
1025     editGroup->addAction(m_normalEditTool);
1026     editGroup->addAction(m_overwriteEditTool);
1027     editGroup->addAction(m_insertEditTool);
1028     editGroup->setExclusive(true);
1029     connect(editGroup, SIGNAL(triggered(QAction *)), this, SLOT(slotChangeEdit(QAction *)));
1030     //connect(m_overwriteEditTool, SIGNAL(toggled(bool)), this, SLOT(slotSetOverwriteMode(bool)));
1031
1032     toolbar->addSeparator();
1033
1034     // create tools buttons
1035     m_buttonSelectTool = new KAction(KIcon("kdenlive-select-tool"), i18n("Selection tool"), this);
1036     m_buttonSelectTool->setShortcut(i18nc("Selection tool shortcut", "s"));
1037     toolbar->addAction(m_buttonSelectTool);
1038     m_buttonSelectTool->setCheckable(true);
1039     m_buttonSelectTool->setChecked(true);
1040
1041     m_buttonRazorTool = new KAction(KIcon("edit-cut"), i18n("Razor tool"), this);
1042     m_buttonRazorTool->setShortcut(i18nc("Razor tool shortcut", "x"));
1043     toolbar->addAction(m_buttonRazorTool);
1044     m_buttonRazorTool->setCheckable(true);
1045     m_buttonRazorTool->setChecked(false);
1046
1047     m_buttonSpacerTool = new KAction(KIcon("kdenlive-spacer-tool"), i18n("Spacer tool"), this);
1048     m_buttonSpacerTool->setShortcut(i18nc("Spacer tool shortcut", "m"));
1049     toolbar->addAction(m_buttonSpacerTool);
1050     m_buttonSpacerTool->setCheckable(true);
1051     m_buttonSpacerTool->setChecked(false);
1052
1053     QActionGroup *toolGroup = new QActionGroup(this);
1054     toolGroup->addAction(m_buttonSelectTool);
1055     toolGroup->addAction(m_buttonRazorTool);
1056     toolGroup->addAction(m_buttonSpacerTool);
1057     toolGroup->setExclusive(true);
1058     toolbar->setToolButtonStyle(Qt::ToolButtonIconOnly);
1059
1060     QWidget * actionWidget;
1061     int max = toolbar->iconSizeDefault() + 2;
1062     actionWidget = toolbar->widgetForAction(m_normalEditTool);
1063     actionWidget->setMaximumWidth(max);
1064     actionWidget->setMaximumHeight(max - 4);
1065
1066     actionWidget = toolbar->widgetForAction(m_insertEditTool);
1067     actionWidget->setMaximumWidth(max);
1068     actionWidget->setMaximumHeight(max - 4);
1069
1070     actionWidget = toolbar->widgetForAction(m_overwriteEditTool);
1071     actionWidget->setMaximumWidth(max);
1072     actionWidget->setMaximumHeight(max - 4);
1073
1074     actionWidget = toolbar->widgetForAction(m_buttonSelectTool);
1075     actionWidget->setMaximumWidth(max);
1076     actionWidget->setMaximumHeight(max - 4);
1077
1078     actionWidget = toolbar->widgetForAction(m_buttonRazorTool);
1079     actionWidget->setMaximumWidth(max);
1080     actionWidget->setMaximumHeight(max - 4);
1081
1082     actionWidget = toolbar->widgetForAction(m_buttonSpacerTool);
1083     actionWidget->setMaximumWidth(max);
1084     actionWidget->setMaximumHeight(max - 4);
1085
1086     toolbar->setStyleSheet(style1);
1087     connect(toolGroup, SIGNAL(triggered(QAction *)), this, SLOT(slotChangeTool(QAction *)));
1088
1089     toolbar->addSeparator();
1090     m_buttonFitZoom = new KAction(KIcon("zoom-fit-best"), i18n("Fit zoom to project"), this);
1091     toolbar->addAction(m_buttonFitZoom);
1092     m_buttonFitZoom->setCheckable(false);
1093
1094     m_zoomOut = new KAction(KIcon("zoom-out"), i18n("Zoom Out"), this);
1095     toolbar->addAction(m_zoomOut);
1096     m_zoomOut->setShortcut(Qt::CTRL + Qt::Key_Minus);
1097
1098     m_zoomSlider = new QSlider(Qt::Horizontal, this);
1099     m_zoomSlider->setMaximum(13);
1100     m_zoomSlider->setPageStep(1);
1101     m_zoomSlider->setInvertedAppearance(true);
1102
1103     m_zoomSlider->setMaximumWidth(150);
1104     m_zoomSlider->setMinimumWidth(100);
1105     toolbar->addWidget(m_zoomSlider);
1106
1107     m_zoomIn = new KAction(KIcon("zoom-in"), i18n("Zoom In"), this);
1108     toolbar->addAction(m_zoomIn);
1109     m_zoomIn->setShortcut(Qt::CTRL + Qt::Key_Plus);
1110
1111     actionWidget = toolbar->widgetForAction(m_buttonFitZoom);
1112     actionWidget->setMaximumWidth(max);
1113     actionWidget->setMaximumHeight(max - 4);
1114     actionWidget->setStyleSheet(styleBorderless);
1115
1116     actionWidget = toolbar->widgetForAction(m_zoomIn);
1117     actionWidget->setMaximumWidth(max);
1118     actionWidget->setMaximumHeight(max - 4);
1119     actionWidget->setStyleSheet(styleBorderless);
1120
1121     actionWidget = toolbar->widgetForAction(m_zoomOut);
1122     actionWidget->setMaximumWidth(max);
1123     actionWidget->setMaximumHeight(max - 4);
1124     actionWidget->setStyleSheet(styleBorderless);
1125
1126     connect(m_zoomSlider, SIGNAL(valueChanged(int)), this, SLOT(slotSetZoom(int)));
1127     connect(m_zoomSlider, SIGNAL(sliderMoved(int)), this, SLOT(slotShowZoomSliderToolTip(int)));
1128     connect(m_buttonFitZoom, SIGNAL(triggered()), this, SLOT(slotFitZoom()));
1129     connect(m_zoomIn, SIGNAL(triggered(bool)), this, SLOT(slotZoomIn()));
1130     connect(m_zoomOut, SIGNAL(triggered(bool)), this, SLOT(slotZoomOut()));
1131
1132     toolbar->addSeparator();
1133
1134     //create automatic audio split button
1135     m_buttonAutomaticSplitAudio = new KAction(KIcon("kdenlive-split-audio"), i18n("Split audio and video automatically"), this);
1136     toolbar->addAction(m_buttonAutomaticSplitAudio);
1137     m_buttonAutomaticSplitAudio->setCheckable(true);
1138     m_buttonAutomaticSplitAudio->setChecked(KdenliveSettings::splitaudio());
1139     connect(m_buttonAutomaticSplitAudio, SIGNAL(triggered()), this, SLOT(slotSwitchSplitAudio()));
1140
1141     m_buttonVideoThumbs = new KAction(KIcon("kdenlive-show-videothumb"), i18n("Show video thumbnails"), this);
1142     toolbar->addAction(m_buttonVideoThumbs);
1143     m_buttonVideoThumbs->setCheckable(true);
1144     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
1145     connect(m_buttonVideoThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchVideoThumbs()));
1146
1147     m_buttonAudioThumbs = new KAction(KIcon("kdenlive-show-audiothumb"), i18n("Show audio thumbnails"), this);
1148     toolbar->addAction(m_buttonAudioThumbs);
1149     m_buttonAudioThumbs->setCheckable(true);
1150     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
1151     connect(m_buttonAudioThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchAudioThumbs()));
1152
1153     m_buttonShowMarkers = new KAction(KIcon("kdenlive-show-markers"), i18n("Show markers comments"), this);
1154     toolbar->addAction(m_buttonShowMarkers);
1155     m_buttonShowMarkers->setCheckable(true);
1156     m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
1157     connect(m_buttonShowMarkers, SIGNAL(triggered()), this, SLOT(slotSwitchMarkersComments()));
1158
1159     m_buttonSnap = new KAction(KIcon("kdenlive-snap"), i18n("Snap"), this);
1160     toolbar->addAction(m_buttonSnap);
1161     m_buttonSnap->setCheckable(true);
1162     m_buttonSnap->setChecked(KdenliveSettings::snaptopoints());
1163     connect(m_buttonSnap, SIGNAL(triggered()), this, SLOT(slotSwitchSnap()));
1164
1165     actionWidget = toolbar->widgetForAction(m_buttonAutomaticSplitAudio);
1166     actionWidget->setMaximumWidth(max);
1167     actionWidget->setMaximumHeight(max - 4);
1168
1169     actionWidget = toolbar->widgetForAction(m_buttonVideoThumbs);
1170     actionWidget->setMaximumWidth(max);
1171     actionWidget->setMaximumHeight(max - 4);
1172
1173     actionWidget = toolbar->widgetForAction(m_buttonAudioThumbs);
1174     actionWidget->setMaximumWidth(max);
1175     actionWidget->setMaximumHeight(max - 4);
1176
1177     actionWidget = toolbar->widgetForAction(m_buttonShowMarkers);
1178     actionWidget->setMaximumWidth(max);
1179     actionWidget->setMaximumHeight(max - 4);
1180
1181     actionWidget = toolbar->widgetForAction(m_buttonSnap);
1182     actionWidget->setMaximumWidth(max);
1183     actionWidget->setMaximumHeight(max - 4);
1184
1185     m_messageLabel = new StatusBarMessageLabel(this);
1186     m_messageLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding);
1187
1188     statusBar()->addWidget(m_messageLabel, 10);
1189     statusBar()->addWidget(m_statusProgressBar, 0);
1190     statusBar()->addPermanentWidget(toolbar);
1191     statusBar()->insertPermanentFixedItem("00:00:00:00", ID_TIMELINE_POS);
1192     statusBar()->addPermanentWidget(m_timecodeFormat);
1193     //statusBar()->setMaximumHeight(statusBar()->font().pointSize() * 3);
1194
1195     collection.addAction("normal_mode", m_normalEditTool);
1196     collection.addAction("overwrite_mode", m_overwriteEditTool);
1197     collection.addAction("insert_mode", m_insertEditTool);
1198     collection.addAction("select_tool", m_buttonSelectTool);
1199     collection.addAction("razor_tool", m_buttonRazorTool);
1200     collection.addAction("spacer_tool", m_buttonSpacerTool);
1201
1202     collection.addAction("automatic_split_audio", m_buttonAutomaticSplitAudio);
1203     collection.addAction("show_video_thumbs", m_buttonVideoThumbs);
1204     collection.addAction("show_audio_thumbs", m_buttonAudioThumbs);
1205     collection.addAction("show_markers", m_buttonShowMarkers);
1206     collection.addAction("snap", m_buttonSnap);
1207     collection.addAction("zoom_fit", m_buttonFitZoom);
1208     collection.addAction("zoom_in", m_zoomIn);
1209     collection.addAction("zoom_out", m_zoomOut);
1210
1211     m_projectSearch = new KAction(KIcon("edit-find"), i18n("Find"), this);
1212     collection.addAction("project_find", m_projectSearch);
1213     connect(m_projectSearch, SIGNAL(triggered(bool)), this, SLOT(slotFind()));
1214     m_projectSearch->setShortcut(Qt::Key_Slash);
1215
1216     m_projectSearchNext = new KAction(KIcon("go-down-search"), i18n("Find Next"), this);
1217     collection.addAction("project_find_next", m_projectSearchNext);
1218     connect(m_projectSearchNext, SIGNAL(triggered(bool)), this, SLOT(slotFindNext()));
1219     m_projectSearchNext->setShortcut(Qt::Key_F3);
1220     m_projectSearchNext->setEnabled(false);
1221
1222     KAction* profilesAction = new KAction(KIcon("document-new"), i18n("Manage Project Profiles"), this);
1223     collection.addAction("manage_profiles", profilesAction);
1224     connect(profilesAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProfiles()));
1225
1226     KNS3::standardAction(i18n("Download New Wipes..."),            this, SLOT(slotGetNewLumaStuff()),       actionCollection(), "get_new_lumas");
1227     KNS3::standardAction(i18n("Download New Render Profiles..."),  this, SLOT(slotGetNewRenderStuff()),     actionCollection(), "get_new_profiles");
1228     KNS3::standardAction(i18n("Download New Project Profiles..."), this, SLOT(slotGetNewMltProfileStuff()), actionCollection(), "get_new_mlt_profiles");
1229     KNS3::standardAction(i18n("Download New Title Templates..."),  this, SLOT(slotGetNewTitleStuff()),      actionCollection(), "get_new_titles");
1230
1231     KAction* wizAction = new KAction(KIcon("configure"), i18n("Run Config Wizard"), this);
1232     collection.addAction("run_wizard", wizAction);
1233     connect(wizAction, SIGNAL(triggered(bool)), this, SLOT(slotRunWizard()));
1234
1235     KAction* projectAction = new KAction(KIcon("configure"), i18n("Project Settings"), this);
1236     collection.addAction("project_settings", projectAction);
1237     connect(projectAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProjectSettings()));
1238
1239     KAction* backupAction = new KAction(KIcon("edit-undo"), i18n("Open Backup File"), this);
1240     collection.addAction("open_backup", backupAction);
1241     connect(backupAction, SIGNAL(triggered(bool)), this, SLOT(slotOpenBackupDialog()));
1242
1243     KAction* projectRender = new KAction(KIcon("media-record"), i18n("Render"), this);
1244     collection.addAction("project_render", projectRender);
1245     projectRender->setShortcut(Qt::CTRL + Qt::Key_Return);
1246     connect(projectRender, SIGNAL(triggered(bool)), this, SLOT(slotRenderProject()));
1247
1248     KAction* projectClean = new KAction(KIcon("edit-clear"), i18n("Clean Project"), this);
1249     collection.addAction("project_clean", projectClean);
1250     connect(projectClean, SIGNAL(triggered(bool)), this, SLOT(slotCleanProject()));
1251
1252     KAction* projectAdjust = new KAction(KIcon(), i18n("Adjust Profile to Current Clip"), this);
1253     collection.addAction("project_adjust_profile", projectAdjust);
1254     connect(projectAdjust, SIGNAL(triggered(bool)), m_projectList, SLOT(adjustProjectProfileToItem()));
1255
1256     KAction* monitorPlay = new KAction(KIcon("media-playback-start"), i18n("Play"), this);
1257     KShortcut playShortcut;
1258     playShortcut.setPrimary(Qt::Key_Space);
1259     playShortcut.setAlternate(Qt::Key_K);
1260     monitorPlay->setShortcut(playShortcut);
1261     collection.addAction("monitor_play", monitorPlay);
1262     connect(monitorPlay, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotPlay()));
1263
1264     KAction* monitorPause = new KAction(KIcon("media-playback-stop"), i18n("Pause"), this);
1265     collection.addAction("monitor_pause", monitorPause);
1266     connect(monitorPause, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotPause()));
1267
1268     m_playZone = new KAction(KIcon("media-playback-start"), i18n("Play Zone"), this);
1269     m_playZone->setShortcut(Qt::CTRL + Qt::Key_Space);
1270     collection.addAction("monitor_play_zone", m_playZone);
1271     connect(m_playZone, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotPlayZone()));
1272
1273     m_loopZone = new KAction(KIcon("media-playback-start"), i18n("Loop Zone"), this);
1274     m_loopZone->setShortcut(Qt::ALT + Qt::Key_Space);
1275     collection.addAction("monitor_loop_zone", m_loopZone);
1276     connect(m_loopZone, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotLoopZone()));
1277
1278     m_loopClip = new KAction(KIcon("media-playback-start"), i18n("Loop selected clip"), this);
1279     m_loopClip->setEnabled(false);
1280     collection.addAction("monitor_loop_clip", m_loopClip);
1281     connect(m_loopClip, SIGNAL(triggered(bool)), m_projectMonitor, SLOT(slotLoopClip()));
1282
1283     KAction *dvdWizard =  new KAction(KIcon("media-optical"), i18n("DVD Wizard"), this);
1284     collection.addAction("dvd_wizard", dvdWizard);
1285     connect(dvdWizard, SIGNAL(triggered(bool)), this, SLOT(slotDvdWizard()));
1286
1287     KAction *transcodeClip =  new KAction(KIcon("edit-copy"), i18n("Transcode Clips"), this);
1288     collection.addAction("transcode_clip", transcodeClip);
1289     connect(transcodeClip, SIGNAL(triggered(bool)), this, SLOT(slotTranscodeClip()));
1290
1291     KAction *archiveProject =  new KAction(KIcon("file-save"), i18n("Archive Project"), this);
1292     collection.addAction("archive_project", archiveProject);
1293     connect(archiveProject, SIGNAL(triggered(bool)), this, SLOT(slotArchiveProject()));
1294     
1295
1296     KAction *markIn = collection.addAction("mark_in");
1297     markIn->setText(i18n("Set Zone In"));
1298     markIn->setShortcut(Qt::Key_I);
1299     connect(markIn, SIGNAL(triggered(bool)), this, SLOT(slotSetInPoint()));
1300
1301     KAction *markOut = collection.addAction("mark_out");
1302     markOut->setText(i18n("Set Zone Out"));
1303     markOut->setShortcut(Qt::Key_O);
1304     connect(markOut, SIGNAL(triggered(bool)), this, SLOT(slotSetOutPoint()));
1305
1306     KAction *switchMon = collection.addAction("switch_monitor");
1307     switchMon->setText(i18n("Switch monitor"));
1308     switchMon->setShortcut(Qt::Key_T);
1309     connect(switchMon, SIGNAL(triggered(bool)), this, SLOT(slotSwitchMonitors()));
1310
1311     KAction *fullMon = collection.addAction("monitor_fullscreen");
1312     fullMon->setText(i18n("Switch monitor fullscreen"));
1313     fullMon->setIcon(KIcon("view-fullscreen"));
1314     connect(fullMon, SIGNAL(triggered(bool)), this, SLOT(slotSwitchFullscreen()));
1315
1316     KAction *insertTree = collection.addAction("insert_project_tree");
1317     insertTree->setText(i18n("Insert zone in project tree"));
1318     insertTree->setShortcut(Qt::CTRL + Qt::Key_I);
1319     connect(insertTree, SIGNAL(triggered(bool)), this, SLOT(slotInsertZoneToTree()));
1320
1321     KAction *insertTimeline = collection.addAction("insert_timeline");
1322     insertTimeline->setText(i18n("Insert zone in timeline"));
1323     insertTimeline->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_I);
1324     connect(insertTimeline, SIGNAL(triggered(bool)), this, SLOT(slotInsertZoneToTimeline()));
1325
1326     KAction *resizeStart =  new KAction(KIcon(), i18n("Resize Item Start"), this);
1327     collection.addAction("resize_timeline_clip_start", resizeStart);
1328     resizeStart->setShortcut(Qt::Key_1);
1329     connect(resizeStart, SIGNAL(triggered(bool)), this, SLOT(slotResizeItemStart()));
1330
1331     KAction *resizeEnd =  new KAction(KIcon(), i18n("Resize Item End"), this);
1332     collection.addAction("resize_timeline_clip_end", resizeEnd);
1333     resizeEnd->setShortcut(Qt::Key_2);
1334     connect(resizeEnd, SIGNAL(triggered(bool)), this, SLOT(slotResizeItemEnd()));
1335
1336     KAction* monitorSeekBackward = new KAction(KIcon("media-seek-backward"), i18n("Rewind"), this);
1337     monitorSeekBackward->setShortcut(Qt::Key_J);
1338     collection.addAction("monitor_seek_backward", monitorSeekBackward);
1339     connect(monitorSeekBackward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewind()));
1340
1341     KAction* monitorSeekBackwardOneFrame = new KAction(KIcon("media-skip-backward"), i18n("Rewind 1 Frame"), this);
1342     monitorSeekBackwardOneFrame->setShortcut(Qt::Key_Left);
1343     collection.addAction("monitor_seek_backward-one-frame", monitorSeekBackwardOneFrame);
1344     connect(monitorSeekBackwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewindOneFrame()));
1345
1346     KAction* monitorSeekBackwardOneSecond = new KAction(KIcon("media-skip-backward"), i18n("Rewind 1 Second"), this);
1347     monitorSeekBackwardOneSecond->setShortcut(Qt::SHIFT + Qt::Key_Left);
1348     collection.addAction("monitor_seek_backward-one-second", monitorSeekBackwardOneSecond);
1349     connect(monitorSeekBackwardOneSecond, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewindOneSecond()));
1350
1351     KAction* monitorSeekSnapBackward = new KAction(KIcon("media-seek-backward"), i18n("Go to Previous Snap Point"), this);
1352     monitorSeekSnapBackward->setShortcut(Qt::ALT + Qt::Key_Left);
1353     collection.addAction("monitor_seek_snap_backward", monitorSeekSnapBackward);
1354     connect(monitorSeekSnapBackward, SIGNAL(triggered(bool)), this, SLOT(slotSnapRewind()));
1355
1356     KAction* monitorSeekForward = new KAction(KIcon("media-seek-forward"), i18n("Forward"), this);
1357     monitorSeekForward->setShortcut(Qt::Key_L);
1358     collection.addAction("monitor_seek_forward", monitorSeekForward);
1359     connect(monitorSeekForward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForward()));
1360
1361     KAction* clipStart = new KAction(KIcon("media-seek-backward"), i18n("Go to Clip Start"), this);
1362     clipStart->setShortcut(Qt::Key_Home);
1363     collection.addAction("seek_clip_start", clipStart);
1364     connect(clipStart, SIGNAL(triggered(bool)), this, SLOT(slotClipStart()));
1365
1366     KAction* clipEnd = new KAction(KIcon("media-seek-forward"), i18n("Go to Clip End"), this);
1367     clipEnd->setShortcut(Qt::Key_End);
1368     collection.addAction("seek_clip_end", clipEnd);
1369     connect(clipEnd, SIGNAL(triggered(bool)), this, SLOT(slotClipEnd()));
1370
1371     KAction* zoneStart = new KAction(KIcon("media-seek-backward"), i18n("Go to Zone Start"), this);
1372     zoneStart->setShortcut(Qt::SHIFT + Qt::Key_I);
1373     collection.addAction("seek_zone_start", zoneStart);
1374     connect(zoneStart, SIGNAL(triggered(bool)), this, SLOT(slotZoneStart()));
1375
1376     KAction* zoneEnd = new KAction(KIcon("media-seek-forward"), i18n("Go to Zone End"), this);
1377     zoneEnd->setShortcut(Qt::SHIFT + Qt::Key_O);
1378     collection.addAction("seek_zone_end", zoneEnd);
1379     connect(zoneEnd, SIGNAL(triggered(bool)), this, SLOT(slotZoneEnd()));
1380
1381     KAction* projectStart = new KAction(KIcon("go-first"), i18n("Go to Project Start"), this);
1382     projectStart->setShortcut(Qt::CTRL + Qt::Key_Home);
1383     collection.addAction("seek_start", projectStart);
1384     connect(projectStart, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotStart()));
1385
1386     KAction* projectEnd = new KAction(KIcon("go-last"), i18n("Go to Project End"), this);
1387     projectEnd->setShortcut(Qt::CTRL + Qt::Key_End);
1388     collection.addAction("seek_end", projectEnd);
1389     connect(projectEnd, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotEnd()));
1390
1391     KAction* monitorSeekForwardOneFrame = new KAction(KIcon("media-skip-forward"), i18n("Forward 1 Frame"), this);
1392     monitorSeekForwardOneFrame->setShortcut(Qt::Key_Right);
1393     collection.addAction("monitor_seek_forward-one-frame", monitorSeekForwardOneFrame);
1394     connect(monitorSeekForwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForwardOneFrame()));
1395
1396     KAction* monitorSeekForwardOneSecond = new KAction(KIcon("media-skip-forward"), i18n("Forward 1 Second"), this);
1397     monitorSeekForwardOneSecond->setShortcut(Qt::SHIFT + Qt::Key_Right);
1398     collection.addAction("monitor_seek_forward-one-second", monitorSeekForwardOneSecond);
1399     connect(monitorSeekForwardOneSecond, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForwardOneSecond()));
1400
1401     KAction* monitorSeekSnapForward = new KAction(KIcon("media-seek-forward"), i18n("Go to Next Snap Point"), this);
1402     monitorSeekSnapForward->setShortcut(Qt::ALT + Qt::Key_Right);
1403     collection.addAction("monitor_seek_snap_forward", monitorSeekSnapForward);
1404     connect(monitorSeekSnapForward, SIGNAL(triggered(bool)), this, SLOT(slotSnapForward()));
1405
1406     KAction* deleteItem = new KAction(KIcon("edit-delete"), i18n("Delete Selected Item"), this);
1407     deleteItem->setShortcut(Qt::Key_Delete);
1408     collection.addAction("delete_timeline_clip", deleteItem);
1409     connect(deleteItem, SIGNAL(triggered(bool)), this, SLOT(slotDeleteItem()));
1410
1411     /*KAction* editTimelineClipSpeed = new KAction(i18n("Change Clip Speed"), this);
1412     collection.addAction("change_clip_speed", editTimelineClipSpeed);
1413     editTimelineClipSpeed->setData("change_speed");
1414     connect(editTimelineClipSpeed, SIGNAL(triggered(bool)), this, SLOT(slotChangeClipSpeed()));*/
1415
1416     KAction *stickTransition = collection.addAction("auto_transition");
1417     stickTransition->setData(QString("auto"));
1418     stickTransition->setCheckable(true);
1419     stickTransition->setEnabled(false);
1420     stickTransition->setText(i18n("Automatic Transition"));
1421     connect(stickTransition, SIGNAL(triggered(bool)), this, SLOT(slotAutoTransition()));
1422
1423     KAction* groupClip = new KAction(KIcon("object-group"), i18n("Group Clips"), this);
1424     groupClip->setShortcut(Qt::CTRL + Qt::Key_G);
1425     collection.addAction("group_clip", groupClip);
1426     connect(groupClip, SIGNAL(triggered(bool)), this, SLOT(slotGroupClips()));
1427
1428     KAction* ungroupClip = new KAction(KIcon("object-ungroup"), i18n("Ungroup Clips"), this);
1429     collection.addAction("ungroup_clip", ungroupClip);
1430     ungroupClip->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_G);
1431     ungroupClip->setData("ungroup_clip");
1432     connect(ungroupClip, SIGNAL(triggered(bool)), this, SLOT(slotUnGroupClips()));
1433
1434     KAction* editItemDuration = new KAction(KIcon("measure"), i18n("Edit Duration"), this);
1435     collection.addAction("edit_item_duration", editItemDuration);
1436     connect(editItemDuration, SIGNAL(triggered(bool)), this, SLOT(slotEditItemDuration()));
1437
1438     KAction* clipInProjectTree = new KAction(KIcon("go-jump-definition"), i18n("Clip in Project Tree"), this);
1439     collection.addAction("clip_in_project_tree", clipInProjectTree);
1440     connect(clipInProjectTree, SIGNAL(triggered(bool)), this, SLOT(slotClipInProjectTree()));
1441
1442     /*KAction* clipToProjectTree = new KAction(KIcon("go-jump-definition"), i18n("Add Clip to Project Tree"), this);
1443     collection.addAction("clip_to_project_tree", clipToProjectTree);
1444     connect(clipToProjectTree, SIGNAL(triggered(bool)), this, SLOT(slotClipToProjectTree()));*/
1445
1446     KAction* insertOvertwrite = new KAction(KIcon(), i18n("Insert Clip Zone in Timeline (Overwrite)"), this);
1447     insertOvertwrite->setShortcut(Qt::Key_V);
1448     collection.addAction("overwrite_to_in_point", insertOvertwrite);
1449     connect(insertOvertwrite, SIGNAL(triggered(bool)), this, SLOT(slotInsertClipOverwrite()));
1450
1451     KAction* selectTimelineClip = new KAction(KIcon("edit-select"), i18n("Select Clip"), this);
1452     selectTimelineClip->setShortcut(Qt::Key_Plus);
1453     collection.addAction("select_timeline_clip", selectTimelineClip);
1454     connect(selectTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotSelectTimelineClip()));
1455
1456     KAction* deselectTimelineClip = new KAction(KIcon("edit-select"), i18n("Deselect Clip"), this);
1457     deselectTimelineClip->setShortcut(Qt::Key_Minus);
1458     collection.addAction("deselect_timeline_clip", deselectTimelineClip);
1459     connect(deselectTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotDeselectTimelineClip()));
1460
1461     KAction* selectAddTimelineClip = new KAction(KIcon("edit-select"), i18n("Add Clip To Selection"), this);
1462     selectAddTimelineClip->setShortcut(Qt::ALT + Qt::Key_Plus);
1463     collection.addAction("select_add_timeline_clip", selectAddTimelineClip);
1464     connect(selectAddTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotSelectAddTimelineClip()));
1465
1466     KAction* selectTimelineTransition = new KAction(KIcon("edit-select"), i18n("Select Transition"), this);
1467     selectTimelineTransition->setShortcut(Qt::SHIFT + Qt::Key_Plus);
1468     collection.addAction("select_timeline_transition", selectTimelineTransition);
1469     connect(selectTimelineTransition, SIGNAL(triggered(bool)), this, SLOT(slotSelectTimelineTransition()));
1470
1471     KAction* deselectTimelineTransition = new KAction(KIcon("edit-select"), i18n("Deselect Transition"), this);
1472     deselectTimelineTransition->setShortcut(Qt::SHIFT + Qt::Key_Minus);
1473     collection.addAction("deselect_timeline_transition", deselectTimelineTransition);
1474     connect(deselectTimelineTransition, SIGNAL(triggered(bool)), this, SLOT(slotDeselectTimelineTransition()));
1475
1476     KAction* selectAddTimelineTransition = new KAction(KIcon("edit-select"), i18n("Add Transition To Selection"), this);
1477     selectAddTimelineTransition->setShortcut(Qt::ALT + Qt::SHIFT + Qt::Key_Plus);
1478     collection.addAction("select_add_timeline_transition", selectAddTimelineTransition);
1479     connect(selectAddTimelineTransition, SIGNAL(triggered(bool)), this, SLOT(slotSelectAddTimelineTransition()));
1480
1481     KAction* cutTimelineClip = new KAction(KIcon("edit-cut"), i18n("Cut Clip"), this);
1482     cutTimelineClip->setShortcut(Qt::SHIFT + Qt::Key_R);
1483     collection.addAction("cut_timeline_clip", cutTimelineClip);
1484     connect(cutTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotCutTimelineClip()));
1485
1486     KAction* addClipMarker = new KAction(KIcon("bookmark-new"), i18n("Add Marker"), this);
1487     collection.addAction("add_clip_marker", addClipMarker);
1488     connect(addClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotAddClipMarker()));
1489
1490     KAction* deleteClipMarker = new KAction(KIcon("edit-delete"), i18n("Delete Marker"), this);
1491     collection.addAction("delete_clip_marker", deleteClipMarker);
1492     connect(deleteClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotDeleteClipMarker()));
1493
1494     KAction* deleteAllClipMarkers = new KAction(KIcon("edit-delete"), i18n("Delete All Markers"), this);
1495     collection.addAction("delete_all_clip_markers", deleteAllClipMarkers);
1496     connect(deleteAllClipMarkers, SIGNAL(triggered(bool)), this, SLOT(slotDeleteAllClipMarkers()));
1497
1498     KAction* editClipMarker = new KAction(KIcon("document-properties"), i18n("Edit Marker"), this);
1499     editClipMarker->setData(QString("edit_marker"));
1500     collection.addAction("edit_clip_marker", editClipMarker);
1501     connect(editClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotEditClipMarker()));
1502
1503     KAction *addMarkerGuideQuickly = new KAction(KIcon("bookmark-new"), i18n("Add Marker/Guide quickly"), this);
1504     addMarkerGuideQuickly->setShortcut(Qt::Key_Asterisk);
1505     collection.addAction("add_marker_guide_quickly", addMarkerGuideQuickly);
1506     connect(addMarkerGuideQuickly, SIGNAL(triggered(bool)), this, SLOT(slotAddMarkerGuideQuickly()));
1507
1508     KAction* splitAudio = new KAction(KIcon("document-new"), i18n("Split Audio"), this);
1509     collection.addAction("split_audio", splitAudio);
1510     connect(splitAudio, SIGNAL(triggered(bool)), this, SLOT(slotSplitAudio()));
1511
1512     KAction* audioOnly = new KAction(KIcon("document-new"), i18n("Audio Only"), this);
1513     collection.addAction("clip_audio_only", audioOnly);
1514     audioOnly->setData("clip_audio_only");
1515     audioOnly->setCheckable(true);
1516
1517     KAction* videoOnly = new KAction(KIcon("document-new"), i18n("Video Only"), this);
1518     collection.addAction("clip_video_only", videoOnly);
1519     videoOnly->setData("clip_video_only");
1520     videoOnly->setCheckable(true);
1521
1522     KAction* audioAndVideo = new KAction(KIcon("document-new"), i18n("Audio and Video"), this);
1523     collection.addAction("clip_audio_and_video", audioAndVideo);
1524     audioAndVideo->setData("clip_audio_and_video");
1525     audioAndVideo->setCheckable(true);
1526
1527     m_clipTypeGroup = new QActionGroup(this);
1528     m_clipTypeGroup->addAction(audioOnly);
1529     m_clipTypeGroup->addAction(videoOnly);
1530     m_clipTypeGroup->addAction(audioAndVideo);
1531     connect(m_clipTypeGroup, SIGNAL(triggered(QAction *)), this, SLOT(slotUpdateClipType(QAction *)));
1532     m_clipTypeGroup->setEnabled(false);
1533
1534     KAction *insertSpace = new KAction(KIcon(), i18n("Insert Space"), this);
1535     collection.addAction("insert_space", insertSpace);
1536     connect(insertSpace, SIGNAL(triggered()), this, SLOT(slotInsertSpace()));
1537
1538     KAction *removeSpace = new KAction(KIcon(), i18n("Remove Space"), this);
1539     collection.addAction("delete_space", removeSpace);
1540     connect(removeSpace, SIGNAL(triggered()), this, SLOT(slotRemoveSpace()));
1541
1542     KAction *insertTrack = new KAction(KIcon(), i18n("Insert Track"), this);
1543     collection.addAction("insert_track", insertTrack);
1544     connect(insertTrack, SIGNAL(triggered()), this, SLOT(slotInsertTrack()));
1545
1546     KAction *deleteTrack = new KAction(KIcon(), i18n("Delete Track"), this);
1547     collection.addAction("delete_track", deleteTrack);
1548     connect(deleteTrack, SIGNAL(triggered()), this, SLOT(slotDeleteTrack()));
1549
1550     KAction *configTracks = new KAction(KIcon("configure"), i18n("Configure Tracks"), this);
1551     collection.addAction("config_tracks", configTracks);
1552     connect(configTracks, SIGNAL(triggered()), this, SLOT(slotConfigTrack()));
1553
1554     KAction *addGuide = new KAction(KIcon("document-new"), i18n("Add Guide"), this);
1555     collection.addAction("add_guide", addGuide);
1556     connect(addGuide, SIGNAL(triggered()), this, SLOT(slotAddGuide()));
1557
1558     QAction *delGuide = new KAction(KIcon("edit-delete"), i18n("Delete Guide"), this);
1559     collection.addAction("delete_guide", delGuide);
1560     connect(delGuide, SIGNAL(triggered()), this, SLOT(slotDeleteGuide()));
1561
1562     QAction *editGuide = new KAction(KIcon("document-properties"), i18n("Edit Guide"), this);
1563     collection.addAction("edit_guide", editGuide);
1564     connect(editGuide, SIGNAL(triggered()), this, SLOT(slotEditGuide()));
1565
1566     QAction *delAllGuides = new KAction(KIcon("edit-delete"), i18n("Delete All Guides"), this);
1567     collection.addAction("delete_all_guides", delAllGuides);
1568     connect(delAllGuides, SIGNAL(triggered()), this, SLOT(slotDeleteAllGuides()));
1569
1570     QAction *pasteEffects = new KAction(KIcon("edit-paste"), i18n("Paste Effects"), this);
1571     collection.addAction("paste_effects", pasteEffects);
1572     pasteEffects->setData("paste_effects");
1573     connect(pasteEffects , SIGNAL(triggered()), this, SLOT(slotPasteEffects()));
1574
1575     QAction *showTimeline = new KAction(i18n("Show Timeline"), this);
1576     collection.addAction("show_timeline", showTimeline);
1577     showTimeline->setCheckable(true);
1578     showTimeline->setChecked(true);
1579     connect(showTimeline, SIGNAL(triggered(bool)), this, SLOT(slotShowTimeline(bool)));
1580
1581     QAction *showTitleBar = new KAction(i18n("Show Title Bars"), this);
1582     collection.addAction("show_titlebars", showTitleBar);
1583     showTitleBar->setCheckable(true);
1584     connect(showTitleBar, SIGNAL(triggered(bool)), this, SLOT(slotShowTitleBars(bool)));
1585     showTitleBar->setChecked(KdenliveSettings::showtitlebars());
1586     slotShowTitleBars(KdenliveSettings::showtitlebars());
1587
1588     m_closeAction = KStandardAction::close(this,  SLOT(closeCurrentDocument()),   collection);
1589     KStandardAction::quit(this,                   SLOT(close()),                  collection);
1590     KStandardAction::open(this,                   SLOT(openFile()),               collection);
1591     m_saveAction = KStandardAction::save(this,    SLOT(saveFile()),               collection);
1592     KStandardAction::saveAs(this,                 SLOT(saveFileAs()),             collection);
1593     KStandardAction::openNew(this,                SLOT(newFile()),                collection);
1594     // TODO: make the following connection to slotEditKeys work
1595     KStandardAction::keyBindings(this,            SLOT(slotEditKeys()),           collection);
1596     KStandardAction::preferences(this,            SLOT(slotPreferences()),        collection);
1597     KStandardAction::configureNotifications(this, SLOT(configureNotifications()), collection);
1598     KStandardAction::copy(this,                   SLOT(slotCopy()),               collection);
1599     KStandardAction::paste(this,                  SLOT(slotPaste()),              collection);
1600     KStandardAction::fullScreen(this,             SLOT(slotFullScreen()), this,   collection);
1601
1602     KAction *undo = KStandardAction::undo(m_commandStack, SLOT(undo()), collection);
1603     undo->setEnabled(false);
1604     connect(m_commandStack, SIGNAL(canUndoChanged(bool)), undo, SLOT(setEnabled(bool)));
1605
1606     KAction *redo = KStandardAction::redo(m_commandStack, SLOT(redo()), collection);
1607     redo->setEnabled(false);
1608     connect(m_commandStack, SIGNAL(canRedoChanged(bool)), redo, SLOT(setEnabled(bool)));
1609
1610     /*
1611     //TODO: Add status tooltip to actions ?
1612     connect(collection, SIGNAL(actionHovered(QAction*)),
1613             this, SLOT(slotDisplayActionMessage(QAction*)));*/
1614
1615
1616     QAction *addClip = new KAction(KIcon("kdenlive-add-clip"), i18n("Add Clip"), this);
1617     collection.addAction("add_clip", addClip);
1618     connect(addClip , SIGNAL(triggered()), m_projectList, SLOT(slotAddClip()));
1619
1620     QAction *addColorClip = new KAction(KIcon("kdenlive-add-color-clip"), i18n("Add Color Clip"), this);
1621     collection.addAction("add_color_clip", addColorClip);
1622     connect(addColorClip , SIGNAL(triggered()), m_projectList, SLOT(slotAddColorClip()));
1623
1624     QAction *addSlideClip = new KAction(KIcon("kdenlive-add-slide-clip"), i18n("Add Slideshow Clip"), this);
1625     collection.addAction("add_slide_clip", addSlideClip);
1626     connect(addSlideClip , SIGNAL(triggered()), m_projectList, SLOT(slotAddSlideshowClip()));
1627
1628     QAction *addTitleClip = new KAction(KIcon("kdenlive-add-text-clip"), i18n("Add Title Clip"), this);
1629     collection.addAction("add_text_clip", addTitleClip);
1630     connect(addTitleClip , SIGNAL(triggered()), m_projectList, SLOT(slotAddTitleClip()));
1631
1632     QAction *addTitleTemplateClip = new KAction(KIcon("kdenlive-add-text-clip"), i18n("Add Template Title"), this);
1633     collection.addAction("add_text_template_clip", addTitleTemplateClip);
1634     connect(addTitleTemplateClip , SIGNAL(triggered()), m_projectList, SLOT(slotAddTitleTemplateClip()));
1635
1636     QAction *addFolderButton = new KAction(KIcon("folder-new"), i18n("Create Folder"), this);
1637     collection.addAction("add_folder", addFolderButton);
1638     connect(addFolderButton , SIGNAL(triggered()), m_projectList, SLOT(slotAddFolder()));
1639
1640     QAction *clipProperties = new KAction(KIcon("document-edit"), i18n("Clip Properties"), this);
1641     collection.addAction("clip_properties", clipProperties);
1642     clipProperties->setData("clip_properties");
1643     connect(clipProperties , SIGNAL(triggered()), m_projectList, SLOT(slotEditClip()));
1644     clipProperties->setEnabled(false);
1645
1646     QAction *openClip = new KAction(KIcon("document-open"), i18n("Edit Clip"), this);
1647     collection.addAction("edit_clip", openClip);
1648     openClip->setData("edit_clip");
1649     connect(openClip , SIGNAL(triggered()), m_projectList, SLOT(slotOpenClip()));
1650     openClip->setEnabled(false);
1651
1652     QAction *deleteClip = new KAction(KIcon("edit-delete"), i18n("Delete Clip"), this);
1653     collection.addAction("delete_clip", deleteClip);
1654     deleteClip->setData("delete_clip");
1655     connect(deleteClip , SIGNAL(triggered()), m_projectList, SLOT(slotRemoveClip()));
1656     deleteClip->setEnabled(false);
1657
1658     QAction *reloadClip = new KAction(KIcon("view-refresh"), i18n("Reload Clip"), this);
1659     collection.addAction("reload_clip", reloadClip);
1660     reloadClip->setData("reload_clip");
1661     connect(reloadClip , SIGNAL(triggered()), m_projectList, SLOT(slotReloadClip()));
1662     reloadClip->setEnabled(false);
1663
1664     QAction *proxyClip = new KAction(i18n("Proxy Clip"), this);
1665     collection.addAction("proxy_clip", proxyClip);
1666     proxyClip->setData("proxy_clip");
1667     proxyClip->setCheckable(true);
1668     proxyClip->setChecked(false);
1669     connect(proxyClip, SIGNAL(toggled(bool)), m_projectList, SLOT(slotProxyCurrentItem(bool)));
1670     
1671     QAction *stopMotion = new KAction(KIcon("image-x-generic"), i18n("Stop Motion Capture"), this);
1672     collection.addAction("stopmotion", stopMotion);
1673     connect(stopMotion , SIGNAL(triggered()), this, SLOT(slotOpenStopmotion()));
1674
1675     QMenu *addClips = new QMenu();
1676     addClips->addAction(addClip);
1677     addClips->addAction(addColorClip);
1678     addClips->addAction(addSlideClip);
1679     addClips->addAction(addTitleClip);
1680     addClips->addAction(addTitleTemplateClip);
1681     addClips->addAction(addFolderButton);
1682
1683     addClips->addAction(reloadClip);
1684     addClips->addAction(proxyClip);
1685     addClips->addAction(clipProperties);
1686     addClips->addAction(openClip);
1687     addClips->addAction(deleteClip);
1688     m_projectList->setupMenu(addClips, addClip);
1689
1690     // Setup effects and transitions actions.
1691     m_effectsActionCollection = new KActionCollection(this, KGlobal::mainComponent());
1692     //KActionCategory *transitionActions = new KActionCategory(i18n("Transitions"), m_effectsActionCollection);
1693     KActionCategory *transitionActions = new KActionCategory(i18n("Transitions"), collection);
1694     m_transitions = new KAction*[transitions.count()];
1695     for (int i = 0; i < transitions.count(); i++) {
1696         QStringList effectInfo = transitions.effectIdInfo(i);
1697         m_transitions[i] = new KAction(effectInfo.at(0), this);
1698         m_transitions[i]->setData(effectInfo);
1699         m_transitions[i]->setIconVisibleInMenu(false);
1700         QString id = effectInfo.at(2);
1701         if (id.isEmpty()) id = effectInfo.at(1);
1702         transitionActions->addAction("transition_" + id, m_transitions[i]);
1703     }
1704     //m_effectsActionCollection->readSettings();
1705
1706 }
1707
1708 void MainWindow::slotDisplayActionMessage(QAction *a)
1709 {
1710     statusBar()->showMessage(a->data().toString(), 3000);
1711 }
1712
1713 void MainWindow::loadLayouts()
1714 {
1715     QMenu *saveLayout = (QMenu*)(factory()->container("layout_save_as", this));
1716     if (m_loadLayout == NULL || saveLayout == NULL) return;
1717     KSharedConfigPtr config = KGlobal::config();
1718     KConfigGroup layoutGroup(config, "Layouts");
1719     QStringList entries = layoutGroup.keyList();
1720     QList<QAction *> loadActions = m_loadLayout->actions();
1721     QList<QAction *> saveActions = saveLayout->actions();
1722     for (int i = 1; i < 5; i++) {
1723         // Rename the layouts actions
1724         foreach(const QString & key, entries) {
1725             if (key.endsWith(QString("_%1").arg(i))) {
1726                 // Found previously saved layout
1727                 QString layoutName = key.section("_", 0, -2);
1728                 for (int j = 0; j < loadActions.count(); j++) {
1729                     if (loadActions.at(j)->data().toString().endsWith("_" + QString::number(i))) {
1730                         loadActions[j]->setText(layoutName);
1731                         loadActions[j]->setData(key);
1732                         break;
1733                     }
1734                 }
1735                 for (int j = 0; j < saveActions.count(); j++) {
1736                     if (saveActions.at(j)->data().toString().endsWith("_" + QString::number(i))) {
1737                         saveActions[j]->setText(i18n("Save as %1").arg(layoutName));
1738                         saveActions[j]->setData(key);
1739                         break;
1740                     }
1741                 }
1742             }
1743         }
1744     }
1745 }
1746
1747 void MainWindow::slotLoadLayout(QAction *action)
1748 {
1749     if (!action) return;
1750     QString layoutId = action->data().toString();
1751     if (layoutId.isEmpty()) return;
1752     KSharedConfigPtr config = KGlobal::config();
1753     KConfigGroup layouts(config, "Layouts");
1754     QByteArray state = QByteArray::fromBase64(layouts.readEntry(layoutId).toAscii());
1755     restoreState(state);
1756 }
1757
1758 void MainWindow::slotSaveLayout(QAction *action)
1759 {
1760     QString originallayoutName = action->data().toString();
1761     int layoutId = originallayoutName.section('_', -1).toInt();
1762
1763     QString layoutName = QInputDialog::getText(this, i18n("Save Layout"), i18n("Layout name:"), QLineEdit::Normal, originallayoutName.section('_', 0, -2));
1764     if (layoutName.isEmpty()) return;
1765     KSharedConfigPtr config = KGlobal::config();
1766     KConfigGroup layouts(config, "Layouts");
1767     layouts.deleteEntry(originallayoutName);
1768
1769     QByteArray st = saveState();
1770     layoutName.append("_" + QString::number(layoutId));
1771     layouts.writeEntry(layoutName, st.toBase64());
1772     loadLayouts();
1773 }
1774
1775 void MainWindow::saveOptions()
1776 {
1777     KdenliveSettings::self()->writeConfig();
1778     KSharedConfigPtr config = KGlobal::config();
1779     m_fileOpenRecent->saveEntries(KConfigGroup(config, "Recent Files"));
1780     KConfigGroup treecolumns(config, "Project Tree");
1781     treecolumns.writeEntry("columns", m_projectList->headerInfo());
1782     config->sync();
1783 }
1784
1785 void MainWindow::readOptions()
1786 {
1787     KSharedConfigPtr config = KGlobal::config();
1788     m_fileOpenRecent->loadEntries(KConfigGroup(config, "Recent Files"));
1789     KConfigGroup initialGroup(config, "version");
1790     bool upgrade = false;
1791     if (initialGroup.exists()) {
1792         if (initialGroup.readEntry("version", QString()).section(' ', 0, 0) != QString(version).section(' ', 0, 0)) {
1793             upgrade = true;
1794         }
1795
1796         if (initialGroup.readEntry("version") == "0.7") {
1797             //Add new settings from 0.7.1
1798             if (KdenliveSettings::defaultprojectfolder().isEmpty()) {
1799                 QString path = QDir::homePath() + "/kdenlive";
1800                 if (KStandardDirs::makeDir(path)  == false) {
1801                     kDebug() << "/// ERROR CREATING PROJECT FOLDER: " << path;
1802                 } else KdenliveSettings::setDefaultprojectfolder(path);
1803             }
1804         }
1805
1806     }
1807
1808     if (!initialGroup.exists() || upgrade) {
1809         // this is our first run, show Wizard
1810         Wizard *w = new Wizard(upgrade, this);
1811         if (w->exec() == QDialog::Accepted && w->isOk()) {
1812             w->adjustSettings();
1813             initialGroup.writeEntry("version", version);
1814             delete w;
1815         } else {
1816             ::exit(1);
1817         }
1818     }
1819     KConfigGroup treecolumns(config, "Project Tree");
1820     const QByteArray state = treecolumns.readEntry("columns", QByteArray());
1821     if (!state.isEmpty())
1822         m_projectList->setHeaderInfo(state);
1823 }
1824
1825 void MainWindow::slotRunWizard()
1826 {
1827     Wizard *w = new Wizard(false, this);
1828     if (w->exec() == QDialog::Accepted && w->isOk()) {
1829         w->adjustSettings();
1830     }
1831     delete w;
1832 }
1833
1834 void MainWindow::newFile(bool showProjectSettings, bool force)
1835 {
1836     if (!m_timelineArea->isEnabled() && !force)
1837         return;
1838     m_fileRevert->setEnabled(false);
1839     QString profileName = KdenliveSettings::default_profile();
1840     KUrl projectFolder = KdenliveSettings::defaultprojectfolder();
1841     QMap <QString, QString> documentProperties;
1842     QPoint projectTracks(KdenliveSettings::videotracks(), KdenliveSettings::audiotracks());
1843     if (!showProjectSettings) {
1844         if (!KdenliveSettings::activatetabs())
1845             if (!closeCurrentDocument())
1846                 return;
1847     } else {
1848         ProjectSettings *w = new ProjectSettings(NULL, QStringList(), projectTracks.x(), projectTracks.y(), KdenliveSettings::defaultprojectfolder(), false, true, this);
1849         if (w->exec() != QDialog::Accepted)
1850             return;
1851         if (!KdenliveSettings::activatetabs())
1852             if (!closeCurrentDocument())
1853                 return;
1854         if (KdenliveSettings::videothumbnails() != w->enableVideoThumbs())
1855             slotSwitchVideoThumbs();
1856         if (KdenliveSettings::audiothumbnails() != w->enableAudioThumbs())
1857             slotSwitchAudioThumbs();
1858         profileName = w->selectedProfile();
1859         projectFolder = w->selectedFolder();
1860         projectTracks = w->tracks();
1861         documentProperties.insert("enableproxy", QString::number((int) w->useProxy()));
1862         documentProperties.insert("generateproxy", QString::number((int) w->generateProxy()));
1863         documentProperties.insert("proxyminsize", QString::number(w->proxyMinSize()));
1864         documentProperties.insert("proxyparams", w->proxyParams());
1865         documentProperties.insert("proxyextension", w->proxyExtension());
1866         documentProperties.insert("generateimageproxy", QString::number((int) w->generateImageProxy()));
1867         documentProperties.insert("proxyimageminsize", QString::number(w->proxyImageMinSize()));
1868         delete w;
1869     }
1870     m_timelineArea->setEnabled(true);
1871     m_projectList->setEnabled(true);
1872     bool openBackup;
1873     KdenliveDoc *doc = new KdenliveDoc(KUrl(), projectFolder, m_commandStack, profileName, documentProperties, projectTracks, m_projectMonitor->render, m_notesWidget, &openBackup, this);
1874     doc->m_autosave = new KAutoSaveFile(KUrl(), doc);
1875     bool ok;
1876     TrackView *trackView = new TrackView(doc, &ok, this);
1877     m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description());
1878     if (!ok) {
1879         // MLT is broken
1880         //m_timelineArea->setEnabled(false);
1881         //m_projectList->setEnabled(false);
1882         slotPreferences(6);
1883         return;
1884     }
1885     if (m_timelineArea->count() == 1) {
1886         connectDocumentInfo(doc);
1887         connectDocument(trackView, doc);
1888     } else
1889         m_timelineArea->setTabBarHidden(false);
1890     m_monitorManager->activateMonitor("clip");
1891     m_closeAction->setEnabled(m_timelineArea->count() > 1);
1892 }
1893
1894 void MainWindow::activateDocument()
1895 {
1896     if (m_timelineArea->currentWidget() == NULL || !m_timelineArea->isEnabled()) return;
1897     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
1898     KdenliveDoc *currentDoc = currentTab->document();
1899     connectDocumentInfo(currentDoc);
1900     connectDocument(currentTab, currentDoc);
1901 }
1902
1903 bool MainWindow::closeCurrentDocument(bool saveChanges)
1904 {
1905     QWidget *w = m_timelineArea->currentWidget();
1906     if (!w) return true;
1907     // closing current document
1908     int ix = m_timelineArea->currentIndex() + 1;
1909     if (ix == m_timelineArea->count()) ix = 0;
1910     m_timelineArea->setCurrentIndex(ix);
1911     TrackView *tabToClose = (TrackView *) w;
1912     KdenliveDoc *docToClose = tabToClose->document();
1913     if (docToClose && docToClose->isModified() && saveChanges) {
1914         QString message;
1915         if (m_activeDocument->url().fileName().isEmpty())
1916             message = i18n("Save changes to document?");
1917         else
1918             message = i18n("The project <b>\"%1\"</b> has been changed.\nDo you want to save your changes?").arg(m_activeDocument->url().fileName());
1919         switch (KMessageBox::warningYesNoCancel(this, message)) {
1920         case KMessageBox::Yes :
1921             // save document here. If saving fails, return false;
1922             if (saveFile() == false) return false;
1923             break;
1924         case KMessageBox::Cancel :
1925             return false;
1926             break;
1927         default:
1928             break;
1929         }
1930     }
1931     m_clipMonitor->slotSetClipProducer(NULL);
1932     m_projectList->slotResetProjectList();
1933     m_timelineArea->removeTab(m_timelineArea->indexOf(w));
1934     if (m_timelineArea->count() == 1) {
1935         m_timelineArea->setTabBarHidden(true);
1936         m_closeAction->setEnabled(false);
1937     }
1938     if (docToClose == m_activeDocument) {
1939         delete m_activeDocument;
1940         m_activeDocument = NULL;
1941         m_effectStack->clear();
1942         m_transitionConfig->slotTransitionItemSelected(NULL, 0, QPoint(), false);
1943     } else {
1944         delete docToClose;
1945     }
1946     if (w == m_activeTimeline) {
1947         delete m_activeTimeline;
1948         m_activeTimeline = NULL;
1949     } else {
1950         delete w;
1951     }
1952     return true;
1953 }
1954
1955 bool MainWindow::saveFileAs(const QString &outputFileName)
1956 {
1957     QString currentSceneList;
1958     m_monitorManager->stopActiveMonitor();
1959
1960     if (m_activeDocument->saveSceneList(outputFileName, m_projectMonitor->sceneList(), m_projectList->expandedFolders()) == false)
1961         return false;
1962
1963     // Save timeline thumbnails
1964     m_activeTimeline->projectView()->saveThumbnails();
1965     m_activeDocument->setUrl(KUrl(outputFileName));
1966     if (m_activeDocument->m_autosave == NULL) {
1967         m_activeDocument->m_autosave = new KAutoSaveFile(KUrl(outputFileName), this);
1968     } else m_activeDocument->m_autosave->setManagedFile(KUrl(outputFileName));
1969     setCaption(m_activeDocument->description());
1970     m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
1971     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), m_activeDocument->url().path());
1972     m_activeDocument->setModified(false);
1973     m_fileOpenRecent->addUrl(KUrl(outputFileName));
1974     m_fileRevert->setEnabled(true);
1975     m_undoView->stack()->setClean();
1976     return true;
1977 }
1978
1979 bool MainWindow::saveFileAs()
1980 {
1981     QString outputFile = KFileDialog::getSaveFileName(m_activeDocument->projectFolder(), getMimeType(false));
1982     if (outputFile.isEmpty()) {
1983         return false;
1984     }
1985     if (QFile::exists(outputFile)) {
1986         // Show the file dialog again if the user does not want to overwrite the file
1987         if (KMessageBox::questionYesNo(this, i18n("File %1 already exists.\nDo you want to overwrite it?", outputFile)) == KMessageBox::No)
1988             return saveFileAs();
1989     }
1990     return saveFileAs(outputFile);
1991 }
1992
1993 bool MainWindow::saveFile()
1994 {
1995     if (!m_activeDocument) return true;
1996     if (m_activeDocument->url().isEmpty()) {
1997         return saveFileAs();
1998     } else {
1999         bool result = saveFileAs(m_activeDocument->url().path());
2000         m_activeDocument->m_autosave->resize(0);
2001         return result;
2002     }
2003 }
2004
2005 void MainWindow::openFile()
2006 {
2007     if (!m_startUrl.isEmpty()) {
2008         openFile(m_startUrl);
2009         m_startUrl = KUrl();
2010         return;
2011     }
2012     KUrl url = KFileDialog::getOpenUrl(KUrl("kfiledialog:///projectfolder"), getMimeType());
2013     if (url.isEmpty()) return;
2014     m_fileOpenRecent->addUrl(url);
2015     openFile(url);
2016 }
2017
2018 void MainWindow::openLastFile()
2019 {
2020     KSharedConfigPtr config = KGlobal::config();
2021     KUrl::List urls = m_fileOpenRecent->urls();
2022     //WARNING: this is buggy, we get a random url, not the last one. Bug in KRecentFileAction?
2023     if (urls.isEmpty()) newFile(false);
2024     else openFile(urls.last());
2025 }
2026
2027 void MainWindow::openFile(const KUrl &url)
2028 {
2029     // Make sure the url is a Kdenlive project file
2030     KMimeType::Ptr mime = KMimeType::findByUrl(url);
2031     if (mime.data()->is("application/x-compressed-tar")) {
2032         // Opening a compressed project file, we need to process it
2033         kDebug()<<"Opening archive, processing";
2034         ArchiveWidget *ar = new ArchiveWidget(url);
2035         if (ar->exec() == QDialog::Accepted) openFile(KUrl(ar->extractedProjectFile()));
2036         delete ar;
2037         return;
2038     }
2039     if (!url.fileName().endsWith(".kdenlive")) {
2040         // This is not a Kdenlive project file, abort loading
2041         KMessageBox::sorry(this, i18n("File %1 is not a Kdenlive project file", url.path()));
2042         return;
2043     }
2044     
2045     // Check if the document is already opened
2046     const int ct = m_timelineArea->count();
2047     bool isOpened = false;
2048     int i;
2049     for (i = 0; i < ct; i++) {
2050         TrackView *tab = (TrackView *) m_timelineArea->widget(i);
2051         KdenliveDoc *doc = tab->document();
2052         if (doc->url() == url) {
2053             isOpened = true;
2054             break;
2055         }
2056     }
2057     if (isOpened) {
2058         m_timelineArea->setCurrentIndex(i);
2059         return;
2060     }
2061
2062     if (!KdenliveSettings::activatetabs()) if (!closeCurrentDocument()) return;
2063
2064     // Check for backup file
2065     QList<KAutoSaveFile *> staleFiles = KAutoSaveFile::staleFiles(url);
2066     if (!staleFiles.isEmpty()) {
2067         if (KMessageBox::questionYesNo(this,
2068                                        i18n("Auto-saved files exist. Do you want to recover them now?"),
2069                                        i18n("File Recovery"),
2070                                        KGuiItem(i18n("Recover")), KGuiItem(i18n("Don't recover"))) == KMessageBox::Yes) {
2071             recoverFiles(staleFiles);
2072             return;
2073         } else {
2074             // remove the stale files
2075             foreach(KAutoSaveFile * stale, staleFiles) {
2076                 stale->open(QIODevice::ReadWrite);
2077                 delete stale;
2078             }
2079         }
2080     }
2081     m_messageLabel->setMessage(i18n("Opening file %1", url.path()), InformationMessage);
2082     m_messageLabel->repaint();
2083     doOpenFile(url, NULL);
2084 }
2085
2086 void MainWindow::doOpenFile(const KUrl &url, KAutoSaveFile *stale)
2087 {
2088     if (!m_timelineArea->isEnabled()) return;
2089     m_fileRevert->setEnabled(true);
2090
2091     // Recreate stopmotion widget on document change
2092     if (m_stopmotion) {
2093         delete m_stopmotion;
2094         m_stopmotion = NULL;
2095     }
2096     
2097     m_timer.start();
2098     KProgressDialog progressDialog(this, i18n("Loading project"), i18n("Loading project"));
2099     progressDialog.setAllowCancel(false);
2100     progressDialog.progressBar()->setMaximum(4);
2101     progressDialog.show();
2102     progressDialog.progressBar()->setValue(0);
2103     qApp->processEvents();
2104
2105     bool openBackup;
2106     KdenliveDoc *doc = new KdenliveDoc(url, KdenliveSettings::defaultprojectfolder(), m_commandStack, KdenliveSettings::default_profile(), QMap <QString, QString> (), QPoint(KdenliveSettings::videotracks(), KdenliveSettings::audiotracks()), m_projectMonitor->render, m_notesWidget, &openBackup, this, &progressDialog);
2107
2108     progressDialog.progressBar()->setValue(1);
2109     progressDialog.progressBar()->setMaximum(4);
2110     progressDialog.setLabelText(i18n("Loading project"));
2111     qApp->processEvents();
2112
2113     if (stale == NULL) {
2114         stale = new KAutoSaveFile(url, doc);
2115         doc->m_autosave = stale;
2116     } else {
2117         doc->m_autosave = stale;
2118         doc->setUrl(stale->managedFile());
2119         doc->setModified(true);
2120         stale->setParent(doc);
2121     }
2122     connectDocumentInfo(doc);
2123
2124     progressDialog.progressBar()->setValue(2);
2125     qApp->processEvents();
2126
2127     bool ok;
2128     TrackView *trackView = new TrackView(doc, &ok, this);
2129     connectDocument(trackView, doc);
2130     progressDialog.progressBar()->setValue(3);
2131     qApp->processEvents();
2132
2133     m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description()));
2134     if (!ok) {
2135         m_timelineArea->setEnabled(false);
2136         m_projectList->setEnabled(false);
2137         KMessageBox::sorry(this, i18n("Cannot open file %1.\nProject is corrupted.", url.path()));
2138         slotGotProgressInfo(QString(), -1);
2139         newFile(false, true);
2140         return;
2141     }
2142     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), doc->url().path());
2143     trackView->setDuration(trackView->duration());
2144     trackView->projectView()->initCursorPos(m_projectMonitor->render->seekPosition().frames(doc->fps()));
2145
2146     if (m_timelineArea->count() > 1) m_timelineArea->setTabBarHidden(false);
2147     slotGotProgressInfo(QString(), -1);
2148     m_projectMonitor->adjustRulerSize(trackView->duration());
2149     m_projectMonitor->slotZoneMoved(trackView->inPoint(), trackView->outPoint());
2150     progressDialog.progressBar()->setValue(4);
2151     if (openBackup) slotOpenBackupDialog(url);
2152 }
2153
2154 void MainWindow::recoverFiles(QList<KAutoSaveFile *> staleFiles)
2155 {
2156     foreach(KAutoSaveFile * stale, staleFiles) {
2157         /*if (!stale->open(QIODevice::QIODevice::ReadOnly)) {
2158                   // show an error message; we could not steal the lockfile
2159                   // maybe another application got to the file before us?
2160                   delete stale;
2161                   continue;
2162         }*/
2163         kDebug() << "// OPENING RECOVERY: " << stale->fileName() << "\nMANAGED: " << stale->managedFile().path();
2164         // the stalefiles also contain ".lock" files so we must ignore them... bug in KAutoSaveFile?
2165         if (!stale->fileName().endsWith(".lock")) doOpenFile(KUrl(stale->fileName()), stale);
2166         else KIO::NetAccess::del(KUrl(stale->fileName()), this);
2167     }
2168 }
2169
2170 void MainWindow::parseProfiles(const QString &mltPath)
2171 {
2172     //KdenliveSettings::setDefaulttmpfolder();
2173     if (!mltPath.isEmpty()) {
2174         KdenliveSettings::setMltpath(mltPath + "/share/mlt/profiles/");
2175         KdenliveSettings::setRendererpath(mltPath + "/bin/melt");
2176     }
2177
2178     if (KdenliveSettings::mltpath().isEmpty())
2179         KdenliveSettings::setMltpath(QString(MLT_PREFIX) + QString("/share/mlt/profiles/"));
2180
2181     if (KdenliveSettings::rendererpath().isEmpty() || KdenliveSettings::rendererpath().endsWith("inigo")) {
2182         QString meltPath = QString(MLT_PREFIX) + QString("/bin/melt");
2183         if (!QFile::exists(meltPath))
2184             meltPath = KStandardDirs::findExe("melt");
2185         KdenliveSettings::setRendererpath(meltPath);
2186     }
2187
2188     if (KdenliveSettings::rendererpath().isEmpty()) {
2189         // Cannot find the MLT melt renderer, ask for location
2190         KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(QString(), i18n("Cannot find the melt program required for rendering (part of MLT)"), this);
2191         if (getUrl->exec() == QDialog::Rejected) {
2192             ::exit(0);
2193         }
2194         KUrl rendererPath = getUrl->selectedUrl();
2195         delete getUrl;
2196         if (rendererPath.isEmpty()) ::exit(0);
2197         KdenliveSettings::setRendererpath(rendererPath.path());
2198     }
2199
2200     QStringList profilesFilter;
2201     profilesFilter << "*";
2202     QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
2203     if (profilesList.isEmpty()) {
2204         // Cannot find MLT path, try finding melt
2205         QString profilePath = KdenliveSettings::rendererpath();
2206         if (!profilePath.isEmpty()) {
2207             profilePath = profilePath.section('/', 0, -3);
2208             KdenliveSettings::setMltpath(profilePath + "/share/mlt/profiles/");
2209             profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
2210         }
2211         if (profilesList.isEmpty()) {
2212             // Cannot find the MLT profiles, ask for location
2213             KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find your MLT profiles, please give the path"), this);
2214             getUrl->fileDialog()->setMode(KFile::Directory);
2215             if (getUrl->exec() == QDialog::Rejected) {
2216                 ::exit(0);
2217             }
2218             KUrl mltPath = getUrl->selectedUrl();
2219             delete getUrl;
2220             if (mltPath.isEmpty()) ::exit(0);
2221             KdenliveSettings::setMltpath(mltPath.path(KUrl::AddTrailingSlash));
2222             profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
2223         }
2224     }
2225
2226     kDebug() << "RESULTING MLT PATH: " << KdenliveSettings::mltpath();
2227
2228     // Parse again MLT profiles to build a list of available video formats
2229     if (profilesList.isEmpty()) parseProfiles();
2230 }
2231
2232
2233 void MainWindow::slotEditProfiles()
2234 {
2235     ProfilesDialog *w = new ProfilesDialog;
2236     if (w->exec() == QDialog::Accepted) {
2237         KdenliveSettingsDialog* d = static_cast <KdenliveSettingsDialog*>(KConfigDialog::exists("settings"));
2238         if (d) d->checkProfile();
2239     }
2240     delete w;
2241 }
2242
2243 void MainWindow::slotDetectAudioDriver()
2244 {
2245     /* WARNING: do not use this method because sometimes detects wrong driver (pulse instead of alsa),
2246     leading to no audio output, see bug #934 */
2247
2248     //decide which audio driver is really best, in some cases SDL is wrong
2249     if (KdenliveSettings::audiodrivername().isEmpty()) {
2250         QString driver;
2251         KProcess readProcess;
2252         //PulseAudio needs to be selected if it exists, the ALSA pulse pcm device is not fast enough.
2253         if (!KStandardDirs::findExe("pactl").isEmpty()) {
2254             readProcess.setOutputChannelMode(KProcess::OnlyStdoutChannel);
2255             readProcess.setProgram("pactl", QStringList() << "stat");
2256             readProcess.execute(2000); // Kill it after 2 seconds
2257
2258             QString result = QString(readProcess.readAllStandardOutput());
2259             kDebug() << "// / / / / / READING PACTL: ";
2260             kDebug() << result;
2261             if (!result.isEmpty()) {
2262                 driver = "pulse";
2263                 kDebug() << "// / / / / PULSEAUDIO DETECTED";
2264             }
2265         }
2266         //put others here
2267         KdenliveSettings::setAutoaudiodrivername(driver);
2268     }
2269 }
2270
2271 void MainWindow::slotEditProjectSettings()
2272 {
2273     QPoint p = m_activeDocument->getTracksCount();
2274     ProjectSettings *w = new ProjectSettings(m_projectList, m_activeTimeline->projectView()->extractTransitionsLumas(), p.x(), p.y(), m_activeDocument->projectFolder().path(), true, !m_activeDocument->isModified(), this);
2275     connect(w, SIGNAL(disableProxies()), this, SLOT(slotDisableProxies()));
2276
2277     if (w->exec() == QDialog::Accepted) {
2278         QString profile = w->selectedProfile();
2279         m_activeDocument->setProjectFolder(w->selectedFolder());
2280 #ifndef Q_WS_MAC
2281         m_recMonitor->slotUpdateCaptureFolder(m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash));
2282 #endif
2283         if (m_renderWidget) m_renderWidget->setDocumentPath(m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash));
2284         if (KdenliveSettings::videothumbnails() != w->enableVideoThumbs()) slotSwitchVideoThumbs();
2285         if (KdenliveSettings::audiothumbnails() != w->enableAudioThumbs()) slotSwitchAudioThumbs();
2286         if (m_activeDocument->profilePath() != profile) slotUpdateProjectProfile(profile);
2287         if (m_activeDocument->getDocumentProperty("proxyparams") != w->proxyParams()) {
2288             m_activeDocument->setModified();
2289             m_activeDocument->setDocumentProperty("proxyparams", w->proxyParams());
2290             if (m_activeDocument->clipManager()->clipsCount() > 0 && KMessageBox::questionYesNo(this, i18n("You have changed the proxy parameters. Do you want to recreate all proxy clips for this project?")) == KMessageBox::Yes) {
2291                 //TODO: rebuild all proxies
2292                 //m_projectList->rebuildProxies();
2293             }
2294         }
2295         if (m_activeDocument->getDocumentProperty("proxyextension") != w->proxyExtension()) {
2296             m_activeDocument->setModified();
2297             m_activeDocument->setDocumentProperty("proxyextension", w->proxyExtension());
2298         }
2299         if (m_activeDocument->getDocumentProperty("generateproxy") != QString::number((int) w->generateProxy())) {
2300             m_activeDocument->setModified();
2301             m_activeDocument->setDocumentProperty("generateproxy", QString::number((int) w->generateProxy()));
2302         }
2303         if (m_activeDocument->getDocumentProperty("proxyminsize") != QString::number(w->proxyMinSize())) {
2304             m_activeDocument->setModified();
2305             m_activeDocument->setDocumentProperty("proxyminsize", QString::number(w->proxyMinSize()));
2306         }
2307         if (m_activeDocument->getDocumentProperty("generateimageproxy") != QString::number((int) w->generateImageProxy())) {
2308             m_activeDocument->setModified();
2309             m_activeDocument->setDocumentProperty("generateimageproxy", QString::number((int) w->generateImageProxy()));
2310         }
2311         if (m_activeDocument->getDocumentProperty("proxyimageminsize") != QString::number(w->proxyImageMinSize())) {
2312             m_activeDocument->setModified();
2313             m_activeDocument->setDocumentProperty("proxyimageminsize", QString::number(w->proxyImageMinSize()));
2314         }
2315         if (QString::number((int) w->useProxy()) != m_activeDocument->getDocumentProperty("enableproxy")) {
2316             m_activeDocument->setDocumentProperty("enableproxy", QString::number((int) w->useProxy()));
2317             m_activeDocument->setModified();
2318             slotUpdateProxySettings();
2319         }
2320     }
2321     delete w;
2322 }
2323
2324 void MainWindow::slotDisableProxies()
2325 {
2326     m_activeDocument->setDocumentProperty("enableproxy", QString::number((int) false));
2327     m_activeDocument->setModified();
2328     slotUpdateProxySettings();
2329 }
2330
2331 void MainWindow::slotUpdateProjectProfile(const QString &profile)
2332 {
2333     // Recreate the stopmotion widget if profile changes
2334     if (m_stopmotion) {
2335         delete m_stopmotion;
2336         m_stopmotion = NULL;
2337     }
2338
2339     // Deselect current effect / transition
2340     m_effectStack->slotClipItemSelected(NULL, 0);
2341     m_transitionConfig->slotTransitionItemSelected(NULL, 0, QPoint(), false);
2342     m_clipMonitor->slotSetClipProducer(NULL);
2343     bool updateFps = m_activeDocument->setProfilePath(profile);
2344     KdenliveSettings::setCurrent_profile(profile);
2345     KdenliveSettings::setProject_fps(m_activeDocument->fps());
2346     setCaption(m_activeDocument->description(), m_activeDocument->isModified());
2347
2348     m_activeDocument->clipManager()->clearUnusedProducers();
2349     m_monitorManager->resetProfiles(m_activeDocument->timecode());
2350     m_transitionConfig->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode(), m_activeDocument->tracksList());
2351     m_effectStack->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode());
2352     m_projectList->updateProjectFormat(m_activeDocument->timecode());
2353     if (m_renderWidget) m_renderWidget->setProfile(m_activeDocument->mltProfile());
2354     m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
2355     if (updateFps) m_activeTimeline->updateProjectFps();
2356     m_activeDocument->clipManager()->clearCache();
2357     m_activeTimeline->updateProfile();
2358     m_activeDocument->setModified(true);
2359     m_commandStack->activeStack()->clear();
2360     //Update the mouse position display so it will display in DF/NDF format by default based on the project setting.
2361     slotUpdateMousePosition(0);
2362     // We need to desactivate & reactivate monitors to get a refresh
2363     //m_monitorManager->switchMonitors();
2364 }
2365
2366
2367 void MainWindow::slotRenderProject()
2368 {
2369     if (!m_renderWidget) {
2370         QString projectfolder = m_activeDocument ? m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash) : KdenliveSettings::defaultprojectfolder();
2371         MltVideoProfile profile;
2372         if (m_activeDocument) profile = m_activeDocument->mltProfile();
2373         m_renderWidget = new RenderWidget(projectfolder, m_projectList->useProxy(), profile, this);
2374         connect(m_renderWidget, SIGNAL(shutdown()), this, SLOT(slotShutdown()));
2375         connect(m_renderWidget, SIGNAL(selectedRenderProfile(QMap <QString, QString>)), this, SLOT(slotSetDocumentRenderProfile(QMap <QString, QString>)));
2376         connect(m_renderWidget, SIGNAL(prepareRenderingData(bool, bool, const QString&)), this, SLOT(slotPrepareRendering(bool, bool, const QString&)));
2377         connect(m_renderWidget, SIGNAL(abortProcess(const QString &)), this, SIGNAL(abortRenderJob(const QString &)));
2378         connect(m_renderWidget, SIGNAL(openDvdWizard(const QString &, const QString &)), this, SLOT(slotDvdWizard(const QString &, const QString &)));
2379         if (m_activeDocument) {
2380             m_renderWidget->setProfile(m_activeDocument->mltProfile());
2381             m_renderWidget->setGuides(m_activeDocument->guidesXml(), m_activeDocument->projectDuration());
2382             m_renderWidget->setDocumentPath(m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash));
2383             m_renderWidget->setRenderProfile(m_activeDocument->getRenderProperties());
2384         }
2385     }
2386     slotCheckRenderStatus();
2387     m_renderWidget->show();
2388     m_renderWidget->showNormal();
2389
2390     // What are the following lines supposed to do?
2391     //m_activeTimeline->tracksNumber();
2392     //m_renderWidget->enableAudio(false);
2393     //m_renderWidget->export_audio;
2394 }
2395
2396 void MainWindow::slotCheckRenderStatus()
2397 {
2398     // Make sure there are no missing clips
2399     if (m_renderWidget)
2400         m_renderWidget->missingClips(m_projectList->hasMissingClips());
2401 }
2402
2403 void MainWindow::setRenderingProgress(const QString &url, int progress)
2404 {
2405     if (m_renderWidget)
2406         m_renderWidget->setRenderJob(url, progress);
2407 }
2408
2409 void MainWindow::setRenderingFinished(const QString &url, int status, const QString &error)
2410 {
2411     if (m_renderWidget)
2412         m_renderWidget->setRenderStatus(url, status, error);
2413 }
2414
2415 void MainWindow::slotCleanProject()
2416 {
2417     if (KMessageBox::warningContinueCancel(this, i18n("This will remove all unused clips from your project."), i18n("Clean up project")) == KMessageBox::Cancel) return;
2418     m_projectList->cleanup();
2419 }
2420
2421 void MainWindow::slotUpdateMousePosition(int pos)
2422 {
2423     if (m_activeDocument)
2424         switch (m_timecodeFormat->currentIndex()) {
2425         case 0:
2426             statusBar()->changeItem(m_activeDocument->timecode().getTimecodeFromFrames(pos), ID_TIMELINE_POS);
2427             break;
2428         default:
2429             statusBar()->changeItem(QString::number(pos), ID_TIMELINE_POS);
2430         }
2431 }
2432
2433 void MainWindow::slotUpdateDocumentState(bool modified)
2434 {
2435     if (!m_activeDocument) return;
2436     setCaption(m_activeDocument->description(), modified);
2437     m_saveAction->setEnabled(modified);
2438     if (modified) {
2439         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Link));
2440         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("document-save"));
2441     } else {
2442         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Text));
2443         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("kdenlive"));
2444     }
2445 }
2446
2447 void MainWindow::connectDocumentInfo(KdenliveDoc *doc)
2448 {
2449     if (m_activeDocument) {
2450         if (m_activeDocument == doc) return;
2451         disconnect(m_activeDocument, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
2452     }
2453     connect(doc, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
2454 }
2455
2456 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc)   //changed
2457 {
2458     //m_projectMonitor->stop();
2459     m_closeAction->setEnabled(m_timelineArea->count() > 1);
2460     kDebug() << "///////////////////   CONNECTING DOC TO PROJECT VIEW ////////////////";
2461     if (m_activeDocument) {
2462         if (m_activeDocument == doc) return;
2463         if (m_activeTimeline) {
2464             disconnect(m_projectMonitor, SIGNAL(renderPosition(int)), m_activeTimeline, SLOT(moveCursorPos(int)));
2465             disconnect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), m_activeTimeline, SLOT(slotSetZone(QPoint)));
2466             disconnect(m_projectMonitor, SIGNAL(durationChanged(int)), m_activeTimeline, SLOT(setDuration(int)));
2467             disconnect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), m_activeDocument, SLOT(setModified()));
2468             disconnect(m_notesWidget, SIGNAL(textChanged()), m_activeDocument, SLOT(setModified()));
2469             disconnect(m_clipMonitor, SIGNAL(zoneUpdated(QPoint)), m_activeDocument, SLOT(setModified()));
2470             disconnect(m_projectList, SIGNAL(projectModified()), m_activeDocument, SLOT(setModified()));
2471
2472             disconnect(m_projectMonitor->render, SIGNAL(refreshDocumentProducers(bool, bool)), m_activeDocument, SLOT(checkProjectClips(bool, bool)));
2473
2474             disconnect(m_activeDocument, SIGNAL(guidesUpdated()), this, SLOT(slotGuidesUpdated()));
2475             disconnect(m_activeDocument, SIGNAL(addProjectClip(DocClipBase *, bool)), m_projectList, SLOT(slotAddClip(DocClipBase *, bool)));
2476             disconnect(m_activeDocument, SIGNAL(resetProjectList()), m_projectList, SLOT(slotResetProjectList()));
2477             disconnect(m_activeDocument, SIGNAL(signalDeleteProjectClip(const QString &)), this, SLOT(slotDeleteClip(const QString &)));
2478             disconnect(m_activeDocument, SIGNAL(updateClipDisplay(const QString &)), m_projectList, SLOT(slotUpdateClip(const QString &)));
2479             disconnect(m_activeDocument, SIGNAL(selectLastAddedClip(const QString &)), m_projectList, SLOT(slotSelectClip(const QString &)));
2480             disconnect(m_activeTimeline->projectView(), SIGNAL(clipItemSelected(ClipItem*, int, bool)), m_effectStack, SLOT(slotClipItemSelected(ClipItem*, int)));
2481             disconnect(m_activeTimeline->projectView(), SIGNAL(clipItemSelected(ClipItem*, int, bool)), this, SLOT(slotActivateEffectStackView(ClipItem*, int, bool)));
2482             disconnect(m_activeTimeline->projectView(), SIGNAL(clipItemSelected(ClipItem*, int, bool)), m_projectMonitor, SLOT(slotSetSelectedClip(ClipItem*)));
2483             disconnect(m_activeTimeline->projectView(), SIGNAL(transitionItemSelected(Transition*, int, QPoint, bool)), m_transitionConfig, SLOT(slotTransitionItemSelected(Transition*, int, QPoint, bool)));
2484             disconnect(m_activeTimeline->projectView(), SIGNAL(transitionItemSelected(Transition*, int, QPoint, bool)), this, SLOT(slotActivateTransitionView(Transition *)));
2485             disconnect(m_activeTimeline->projectView(), SIGNAL(transitionItemSelected(Transition*, int, QPoint, bool)), m_projectMonitor, SLOT(slotSetSelectedClip(Transition*)));
2486             disconnect(m_activeTimeline->projectView(), SIGNAL(playMonitor()), m_projectMonitor, SLOT(slotPlay()));
2487             disconnect(m_activeTimeline->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
2488             disconnect(m_activeTimeline->projectView(), SIGNAL(showClipFrame(DocClipBase *, QPoint, bool, const int)), m_clipMonitor, SLOT(slotSetClipProducer(DocClipBase *, QPoint, bool, const int)));
2489             disconnect(m_activeTimeline, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
2490             disconnect(m_activeTimeline, SIGNAL(insertTrack(int)), this, SLOT(slotInsertTrack(int)));
2491             disconnect(m_activeTimeline, SIGNAL(deleteTrack(int)), this, SLOT(slotDeleteTrack(int)));
2492             disconnect(m_activeTimeline, SIGNAL(configTrack(int)), this, SLOT(slotConfigTrack(int)));
2493             disconnect(m_activeDocument, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
2494             disconnect(m_effectStack, SIGNAL(updateEffect(ClipItem*, int, QDomElement, QDomElement, int)), m_activeTimeline->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, int, QDomElement, QDomElement, int)));
2495             disconnect(m_effectStack, SIGNAL(removeEffect(ClipItem*, int, QDomElement)), m_activeTimeline->projectView(), SLOT(slotDeleteEffect(ClipItem*, int, QDomElement)));
2496             disconnect(m_effectStack, SIGNAL(changeEffectState(ClipItem*, int, int, bool)), m_activeTimeline->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, int, bool)));
2497             disconnect(m_effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int, int)), m_activeTimeline->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int, int)));
2498             disconnect(m_effectStack, SIGNAL(refreshEffectStack(ClipItem*)), m_activeTimeline->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
2499             disconnect(m_effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
2500             disconnect(m_effectStack, SIGNAL(displayMessage(const QString&, int)), this, SLOT(slotGotProgressInfo(const QString&, int)));
2501             disconnect(m_transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), m_activeTimeline->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
2502             disconnect(m_transitionConfig, SIGNAL(seekTimeline(int)), m_activeTimeline->projectView() , SLOT(setCursorPos(int)));
2503             disconnect(m_activeTimeline->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
2504             disconnect(m_activeTimeline, SIGNAL(zoneMoved(int, int)), this, SLOT(slotZoneMoved(int, int)));
2505             disconnect(m_projectList, SIGNAL(loadingIsOver()), m_activeTimeline->projectView(), SLOT(slotUpdateAllThumbs()));
2506             disconnect(m_projectList, SIGNAL(refreshClip(const QString &)), m_activeTimeline->projectView(), SLOT(slotRefreshThumbs(const QString &)));
2507             m_effectStack->clear();
2508         }
2509         //m_activeDocument->setRenderer(NULL);
2510         m_clipMonitor->stop();
2511     }
2512     KdenliveSettings::setCurrent_profile(doc->profilePath());
2513     KdenliveSettings::setProject_fps(doc->fps());
2514     m_monitorManager->resetProfiles(doc->timecode());
2515     m_clipMonitorDock->raise();
2516     m_projectList->setDocument(doc);
2517     m_transitionConfig->updateProjectFormat(doc->mltProfile(), doc->timecode(), doc->tracksList());
2518     m_effectStack->updateProjectFormat(doc->mltProfile(), doc->timecode());
2519     connect(m_projectList, SIGNAL(refreshClip(const QString &, bool)), trackView->projectView(), SLOT(slotRefreshThumbs(const QString &, bool)));
2520
2521     connect(m_projectList, SIGNAL(projectModified()), doc, SLOT(setModified()));
2522     connect(m_projectList, SIGNAL(clipNameChanged(const QString, const QString)), trackView->projectView(), SLOT(clipNameChanged(const QString, const QString)));
2523
2524     //connect(trackView, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
2525     connect(trackView, SIGNAL(insertTrack(int)), this, SLOT(slotInsertTrack(int)));
2526     connect(trackView, SIGNAL(deleteTrack(int)), this, SLOT(slotDeleteTrack(int)));
2527     connect(trackView, SIGNAL(configTrack(int)), this, SLOT(slotConfigTrack(int)));
2528     connect(trackView, SIGNAL(updateTracksInfo()), this, SLOT(slotUpdateTrackInfo()));
2529     connect(trackView, SIGNAL(mousePosition(int)), this, SLOT(slotUpdateMousePosition(int)));
2530     connect(trackView->projectView(), SIGNAL(forceClipProcessing(const QString &)), m_projectList, SLOT(slotForceProcessing(const QString &)));
2531     connect(m_projectMonitor, SIGNAL(renderPosition(int)), trackView, SLOT(moveCursorPos(int)));
2532     connect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), trackView, SLOT(slotSetZone(QPoint)));
2533     connect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), doc, SLOT(setModified()));
2534     connect(m_clipMonitor, SIGNAL(zoneUpdated(QPoint)), doc, SLOT(setModified()));
2535     connect(m_projectMonitor, SIGNAL(durationChanged(int)), trackView, SLOT(setDuration(int)));
2536     connect(m_projectMonitor->render, SIGNAL(refreshDocumentProducers(bool, bool)), doc, SLOT(checkProjectClips(bool, bool)));
2537
2538     connect(doc, SIGNAL(addProjectClip(DocClipBase *, bool)), m_projectList, SLOT(slotAddClip(DocClipBase *, bool)));
2539     connect(doc, SIGNAL(resetProjectList()), m_projectList, SLOT(slotResetProjectList()));
2540     connect(doc, SIGNAL(signalDeleteProjectClip(const QString &)), this, SLOT(slotDeleteClip(const QString &)));
2541     connect(doc, SIGNAL(updateClipDisplay(const QString &)), m_projectList, SLOT(slotUpdateClip(const QString &)));
2542     connect(doc, SIGNAL(selectLastAddedClip(const QString &)), m_projectList, SLOT(slotSelectClip(const QString &)));
2543
2544     connect(doc, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
2545     connect(doc, SIGNAL(guidesUpdated()), this, SLOT(slotGuidesUpdated()));
2546     connect(doc, SIGNAL(saveTimelinePreview(const QString &)), trackView, SLOT(slotSaveTimelinePreview(const QString)));
2547     
2548     connect(m_notesWidget, SIGNAL(textChanged()), doc, SLOT(setModified()));
2549
2550     connect(trackView->projectView(), SIGNAL(clipItemSelected(ClipItem*, int, bool)), m_effectStack, SLOT(slotClipItemSelected(ClipItem*, int)));
2551     connect(trackView->projectView(), SIGNAL(updateClipMarkers(DocClipBase *)), this, SLOT(slotUpdateClipMarkers(DocClipBase*)));
2552     connect(trackView, SIGNAL(showTrackEffects(int, TrackInfo)), m_effectStack, SLOT(slotTrackItemSelected(int, TrackInfo)));
2553     connect(trackView, SIGNAL(showTrackEffects(int, TrackInfo)), this, SLOT(slotActivateEffectStackView()));
2554
2555     connect(trackView->projectView(), SIGNAL(clipItemSelected(ClipItem*, int, bool)), this, SLOT(slotActivateEffectStackView(ClipItem*, int, bool)));
2556     connect(trackView->projectView(), SIGNAL(transitionItemSelected(Transition*, int, QPoint, bool)), m_transitionConfig, SLOT(slotTransitionItemSelected(Transition*, int, QPoint, bool)));
2557     connect(trackView->projectView(), SIGNAL(transitionItemSelected(Transition*, int, QPoint, bool)), this, SLOT(slotActivateTransitionView(Transition *)));
2558     m_zoomSlider->setValue(doc->zoom().x());
2559     connect(trackView->projectView(), SIGNAL(zoomIn()), this, SLOT(slotZoomIn()));
2560     connect(trackView->projectView(), SIGNAL(zoomOut()), this, SLOT(slotZoomOut()));
2561     connect(trackView, SIGNAL(setZoom(int)), this, SLOT(slotSetZoom(int)));
2562     connect(trackView->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
2563
2564     connect(trackView->projectView(), SIGNAL(showClipFrame(DocClipBase *, QPoint, bool, const int)), m_clipMonitor, SLOT(slotSetClipProducer(DocClipBase *, QPoint, bool, const int)));
2565     connect(trackView->projectView(), SIGNAL(playMonitor()), m_projectMonitor, SLOT(slotPlay()));
2566
2567     connect(trackView->projectView(), SIGNAL(clipItemSelected(ClipItem*, int, bool)), m_projectMonitor, SLOT(slotSetSelectedClip(ClipItem*)));
2568     connect(trackView->projectView(), SIGNAL(transitionItemSelected(Transition*, int, QPoint, bool)), m_projectMonitor, SLOT(slotSetSelectedClip(Transition*)));
2569
2570     connect(m_effectStack, SIGNAL(updateEffect(ClipItem*, int, QDomElement, QDomElement, int)), trackView->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, int, QDomElement, QDomElement, int)));
2571     connect(m_effectStack, SIGNAL(updateClipRegion(ClipItem*, int, QString)), trackView->projectView(), SLOT(slotUpdateClipRegion(ClipItem*, int, QString)));
2572     connect(m_effectStack, SIGNAL(removeEffect(ClipItem*, int, QDomElement)), trackView->projectView(), SLOT(slotDeleteEffect(ClipItem*, int, QDomElement)));
2573     connect(m_effectStack, SIGNAL(changeEffectState(ClipItem*, int, int, bool)), trackView->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, int, bool)));
2574     connect(m_effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int, int)), trackView->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int, int)));
2575     connect(m_effectStack, SIGNAL(refreshEffectStack(ClipItem*)), trackView->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
2576     connect(m_transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
2577     connect(m_transitionConfig, SIGNAL(seekTimeline(int)), trackView->projectView() , SLOT(setCursorPos(int)));
2578     connect(m_effectStack, SIGNAL(seekTimeline(int)), trackView->projectView() , SLOT(setCursorPos(int)));
2579     connect(m_effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
2580     connect(m_effectStack, SIGNAL(displayMessage(const QString&, int)), this, SLOT(slotGotProgressInfo(const QString&, int)));
2581
2582     connect(trackView->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
2583     connect(trackView, SIGNAL(zoneMoved(int, int)), this, SLOT(slotZoneMoved(int, int)));
2584     connect(m_projectList, SIGNAL(loadingIsOver()), trackView->projectView(), SLOT(slotUpdateAllThumbs()));
2585
2586
2587     trackView->projectView()->setContextMenu(m_timelineContextMenu, m_timelineContextClipMenu, m_timelineContextTransitionMenu, m_clipTypeGroup, (QMenu*)(factory()->container("marker_menu", this)));
2588     m_activeTimeline = trackView;
2589     if (m_renderWidget) {
2590         slotCheckRenderStatus();
2591         m_renderWidget->setProfile(doc->mltProfile());
2592         m_renderWidget->setGuides(doc->guidesXml(), doc->projectDuration());
2593         m_renderWidget->setDocumentPath(doc->projectFolder().path(KUrl::AddTrailingSlash));
2594         m_renderWidget->setRenderProfile(doc->getRenderProperties());
2595     }
2596     //doc->setRenderer(m_projectMonitor->render);
2597     m_commandStack->setActiveStack(doc->commandStack());
2598     KdenliveSettings::setProject_display_ratio(doc->dar());
2599     //doc->clipManager()->checkAudioThumbs();
2600
2601     //m_overView->setScene(trackView->projectScene());
2602     //m_overView->scale(m_overView->width() / trackView->duration(), m_overView->height() / (50 * trackView->tracksNumber()));
2603     //m_overView->fitInView(m_overView->itemAt(0, 50), Qt::KeepAspectRatio);
2604
2605     setCaption(doc->description(), doc->isModified());
2606     m_saveAction->setEnabled(doc->isModified());
2607     m_normalEditTool->setChecked(true);
2608     m_activeDocument = doc;
2609     m_activeTimeline->updateProjectFps();
2610     m_activeDocument->checkProjectClips();
2611 #ifndef Q_WS_MAC
2612     m_recMonitor->slotUpdateCaptureFolder(m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash));
2613 #endif
2614     //Update the mouse position display so it will display in DF/NDF format by default based on the project setting.
2615     slotUpdateMousePosition(0);
2616     m_monitorManager->activateMonitor("clip");
2617     // set tool to select tool
2618     m_buttonSelectTool->setChecked(true);
2619 }
2620
2621 void MainWindow::slotZoneMoved(int start, int end)
2622 {
2623     m_activeDocument->setZone(start, end);
2624     m_projectMonitor->slotZoneMoved(start, end);
2625 }
2626
2627 void MainWindow::slotGuidesUpdated()
2628 {
2629     if (m_renderWidget)
2630         m_renderWidget->setGuides(m_activeDocument->guidesXml(), m_activeDocument->projectDuration());
2631 }
2632
2633 void MainWindow::slotEditKeys()
2634 {
2635     KShortcutsDialog dialog(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsAllowed, this);
2636     dialog.addCollection(actionCollection(), i18nc("general keyboard shortcuts", "General"));
2637     dialog.addCollection(m_effectsActionCollection, i18nc("effects and transitions keyboard shortcuts", "Effects & Transitions"));
2638     dialog.configure();
2639 }
2640
2641 void MainWindow::slotPreferences(int page, int option)
2642 {
2643     /*
2644      * An instance of your dialog could be already created and could be
2645      * cached, in which case you want to display the cached dialog
2646      * instead of creating another one
2647      */
2648     if (m_stopmotion) m_stopmotion->slotLive(false);
2649     if (KConfigDialog::showDialog("settings")) {
2650         KdenliveSettingsDialog* d = static_cast <KdenliveSettingsDialog*>(KConfigDialog::exists("settings"));
2651         if (page != -1) d->showPage(page, option);
2652         return;
2653     }
2654
2655     // KConfigDialog didn't find an instance of this dialog, so lets
2656     // create it :
2657     
2658     // Get the mappable actions in localized form
2659     QMap<QString, QString> actions;
2660     KActionCollection* collection = actionCollection();
2661     foreach (const QString& action_name, m_action_names) {
2662         actions[collection->action(action_name)->text()] = action_name;
2663     }
2664     
2665     KdenliveSettingsDialog* dialog = new KdenliveSettingsDialog(actions, this);
2666     connect(dialog, SIGNAL(settingsChanged(const QString&)), this, SLOT(updateConfiguration()));
2667     connect(dialog, SIGNAL(doResetProfile()), m_monitorManager, SLOT(slotResetProfiles()));
2668 #ifndef Q_WS_MAC
2669     connect(dialog, SIGNAL(updateCaptureFolder()), this, SLOT(slotUpdateCaptureFolder()));
2670 #endif
2671     dialog->show();
2672     if (page != -1) dialog->showPage(page, option);
2673 }
2674
2675 void MainWindow::slotUpdateCaptureFolder()
2676 {
2677
2678 #ifndef Q_WS_MAC
2679     if (m_activeDocument) m_recMonitor->slotUpdateCaptureFolder(m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash));
2680     else m_recMonitor->slotUpdateCaptureFolder(KdenliveSettings::defaultprojectfolder());
2681 #endif
2682 }
2683
2684 void MainWindow::updateConfiguration()
2685 {
2686     //TODO: we should apply settings to all projects, not only the current one
2687     if (m_activeTimeline) {
2688         m_activeTimeline->refresh();
2689         m_activeTimeline->projectView()->checkAutoScroll();
2690         m_activeTimeline->checkTrackHeight();
2691         if (m_activeDocument)
2692             m_activeDocument->clipManager()->checkAudioThumbs();
2693     }
2694     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
2695     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
2696     m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
2697     m_buttonAutomaticSplitAudio->setChecked(KdenliveSettings::splitaudio());
2698
2699     // Update list of transcoding profiles
2700     loadTranscoders();
2701         loadStabilize();
2702 #ifdef USE_JOGSHUTTLE
2703     activateShuttleDevice();
2704 #endif
2705
2706 }
2707
2708 void MainWindow::slotSwitchSplitAudio()
2709 {
2710     KdenliveSettings::setSplitaudio(!KdenliveSettings::splitaudio());
2711     m_buttonAutomaticSplitAudio->setChecked(KdenliveSettings::splitaudio());
2712 }
2713
2714 void MainWindow::slotSwitchVideoThumbs()
2715 {
2716     KdenliveSettings::setVideothumbnails(!KdenliveSettings::videothumbnails());
2717     if (m_activeTimeline)
2718         m_activeTimeline->projectView()->slotUpdateAllThumbs();
2719     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
2720 }
2721
2722 void MainWindow::slotSwitchAudioThumbs()
2723 {
2724     KdenliveSettings::setAudiothumbnails(!KdenliveSettings::audiothumbnails());
2725     if (m_activeTimeline) {
2726         m_activeTimeline->refresh();
2727         m_activeTimeline->projectView()->checkAutoScroll();
2728         if (m_activeDocument)
2729             m_activeDocument->clipManager()->checkAudioThumbs();
2730     }
2731     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
2732 }
2733
2734 void MainWindow::slotSwitchMarkersComments()
2735 {
2736     KdenliveSettings::setShowmarkers(!KdenliveSettings::showmarkers());
2737     if (m_activeTimeline)
2738         m_activeTimeline->refresh();
2739     m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
2740 }
2741
2742 void MainWindow::slotSwitchSnap()
2743 {
2744     KdenliveSettings::setSnaptopoints(!KdenliveSettings::snaptopoints());
2745     m_buttonSnap->setChecked(KdenliveSettings::snaptopoints());
2746 }
2747
2748
2749 void MainWindow::slotDeleteItem()
2750 {
2751     if (QApplication::focusWidget() &&
2752             QApplication::focusWidget()->parentWidget() &&
2753             QApplication::focusWidget()->parentWidget()->parentWidget() &&
2754             QApplication::focusWidget()->parentWidget()->parentWidget() == m_projectListDock) {
2755         m_projectList->slotRemoveClip();
2756
2757     } else {
2758         QWidget *widget = QApplication::focusWidget();
2759         while (widget) {
2760             if (widget == m_effectStackDock) {
2761                 m_effectStack->slotItemDel();
2762                 return;
2763             }
2764             widget = widget->parentWidget();
2765         }
2766
2767         // effect stack has no focus
2768         if (m_activeTimeline)
2769             m_activeTimeline->projectView()->deleteSelectedClips();
2770     }
2771 }
2772
2773 void MainWindow::slotUpdateClipMarkers(DocClipBase *clip)
2774 {
2775     if (m_clipMonitor->isActive())
2776         m_clipMonitor->checkOverlay();
2777     m_clipMonitor->updateMarkers(clip);
2778 }
2779
2780 void MainWindow::slotAddClipMarker()
2781 {
2782     DocClipBase *clip = NULL;
2783     GenTime pos;
2784     if (m_projectMonitor->isActive()) {
2785         if (m_activeTimeline) {
2786             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
2787             if (item) {
2788                 pos = GenTime((int)((m_projectMonitor->position() - item->startPos() + item->cropStart()).frames(m_activeDocument->fps()) * item->speed() + 0.5), m_activeDocument->fps());
2789                 clip = item->baseClip();
2790             }
2791         }
2792     } else {
2793         clip = m_clipMonitor->activeClip();
2794         pos = m_clipMonitor->position();
2795     }
2796     if (!clip) {
2797         m_messageLabel->setMessage(i18n("Cannot find clip to add marker"), ErrorMessage);
2798         return;
2799     }
2800     QString id = clip->getId();
2801     CommentedTime marker(pos, i18n("Marker"));
2802     MarkerDialog d(clip, marker, m_activeDocument->timecode(), i18n("Add Marker"), this);
2803     if (d.exec() == QDialog::Accepted)
2804         m_activeTimeline->projectView()->slotAddClipMarker(id, d.newMarker().time(), d.newMarker().comment());
2805 }
2806
2807 void MainWindow::slotDeleteClipMarker()
2808 {
2809     DocClipBase *clip = NULL;
2810     GenTime pos;
2811     if (m_projectMonitor->isActive()) {
2812         if (m_activeTimeline) {
2813             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
2814             if (item) {
2815                 pos = (m_projectMonitor->position() - item->startPos() + item->cropStart()) / item->speed();
2816                 clip = item->baseClip();
2817             }
2818         }
2819     } else {
2820         clip = m_clipMonitor->activeClip();
2821         pos = m_clipMonitor->position();
2822     }
2823     if (!clip) {
2824         m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
2825         return;
2826     }
2827
2828     QString id = clip->getId();
2829     QString comment = clip->markerComment(pos);
2830     if (comment.isEmpty()) {
2831         m_messageLabel->setMessage(i18n("No marker found at cursor time"), ErrorMessage);
2832         return;
2833     }
2834     m_activeTimeline->projectView()->slotDeleteClipMarker(comment, id, pos);
2835 }
2836
2837 void MainWindow::slotDeleteAllClipMarkers()
2838 {
2839     DocClipBase *clip = NULL;
2840     if (m_projectMonitor->isActive()) {
2841         if (m_activeTimeline) {
2842             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
2843             if (item) {
2844                 clip = item->baseClip();
2845             }
2846         }
2847     } else {
2848         clip = m_clipMonitor->activeClip();
2849     }
2850     if (!clip) {
2851         m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
2852         return;
2853     }
2854     m_activeTimeline->projectView()->slotDeleteAllClipMarkers(clip->getId());
2855 }
2856
2857 void MainWindow::slotEditClipMarker()
2858 {
2859     DocClipBase *clip = NULL;
2860     GenTime pos;
2861     if (m_projectMonitor->isActive()) {
2862         if (m_activeTimeline) {
2863             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
2864             if (item) {
2865                 pos = (m_projectMonitor->position() - item->startPos() + item->cropStart()) / item->speed();
2866                 clip = item->baseClip();
2867             }
2868         }
2869     } else {
2870         clip = m_clipMonitor->activeClip();
2871         pos = m_clipMonitor->position();
2872     }
2873     if (!clip) {
2874         m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
2875         return;
2876     }
2877
2878     QString id = clip->getId();
2879     QString oldcomment = clip->markerComment(pos);
2880     if (oldcomment.isEmpty()) {
2881         m_messageLabel->setMessage(i18n("No marker found at cursor time"), ErrorMessage);
2882         return;
2883     }
2884
2885     CommentedTime marker(pos, oldcomment);
2886     MarkerDialog d(clip, marker, m_activeDocument->timecode(), i18n("Edit Marker"), this);
2887     if (d.exec() == QDialog::Accepted) {
2888         m_activeTimeline->projectView()->slotAddClipMarker(id, d.newMarker().time(), d.newMarker().comment());
2889         if (d.newMarker().time() != pos) {
2890             // remove old marker
2891             m_activeTimeline->projectView()->slotAddClipMarker(id, pos, QString());
2892         }
2893     }
2894 }
2895
2896 void MainWindow::slotAddMarkerGuideQuickly()
2897 {
2898     if (!m_activeTimeline || !m_activeDocument)
2899         return;
2900
2901     if (m_clipMonitor->isActive()) {
2902         DocClipBase *clip = m_clipMonitor->activeClip();
2903         GenTime pos = m_clipMonitor->position();
2904
2905         if (!clip) {
2906             m_messageLabel->setMessage(i18n("Cannot find clip to add marker"), ErrorMessage);
2907             return;
2908         }
2909
2910         m_activeTimeline->projectView()->slotAddClipMarker(clip->getId(), pos, m_activeDocument->timecode().getDisplayTimecode(pos, false));
2911     } else {
2912         m_activeTimeline->projectView()->slotAddGuide(false);
2913     }
2914 }
2915
2916 void MainWindow::slotAddGuide()
2917 {
2918     if (m_activeTimeline)
2919         m_activeTimeline->projectView()->slotAddGuide();
2920 }
2921
2922 void MainWindow::slotInsertSpace()
2923 {
2924     if (m_activeTimeline)
2925         m_activeTimeline->projectView()->slotInsertSpace();
2926 }
2927
2928 void MainWindow::slotRemoveSpace()
2929 {
2930     if (m_activeTimeline)
2931         m_activeTimeline->projectView()->slotRemoveSpace();
2932 }
2933
2934 void MainWindow::slotInsertTrack(int ix)
2935 {
2936     m_projectMonitor->activateMonitor();
2937     if (m_activeTimeline)
2938         m_activeTimeline->projectView()->slotInsertTrack(ix);
2939     if (m_activeDocument)
2940         m_transitionConfig->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode(), m_activeDocument->tracksList());
2941 }
2942
2943 void MainWindow::slotDeleteTrack(int ix)
2944 {
2945     m_projectMonitor->activateMonitor();
2946     if (m_activeTimeline)
2947         m_activeTimeline->projectView()->slotDeleteTrack(ix);
2948     if (m_activeDocument)
2949         m_transitionConfig->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode(), m_activeDocument->tracksList());
2950 }
2951
2952 void MainWindow::slotConfigTrack(int ix)
2953 {
2954     m_projectMonitor->activateMonitor();
2955     if (m_activeTimeline)
2956         m_activeTimeline->projectView()->slotConfigTracks(ix);
2957     if (m_activeDocument)
2958         m_transitionConfig->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode(), m_activeDocument->tracksList());
2959 }
2960
2961 void MainWindow::slotEditGuide()
2962 {
2963     if (m_activeTimeline)
2964         m_activeTimeline->projectView()->slotEditGuide();
2965 }
2966
2967 void MainWindow::slotDeleteGuide()
2968 {
2969     if (m_activeTimeline)
2970         m_activeTimeline->projectView()->slotDeleteGuide();
2971 }
2972
2973 void MainWindow::slotDeleteAllGuides()
2974 {
2975     if (m_activeTimeline)
2976         m_activeTimeline->projectView()->slotDeleteAllGuides();
2977 }
2978
2979 void MainWindow::slotCutTimelineClip()
2980 {
2981     if (m_activeTimeline)
2982         m_activeTimeline->projectView()->cutSelectedClips();
2983 }
2984
2985 void MainWindow::slotInsertClipOverwrite()
2986 {
2987     if (m_activeTimeline) {
2988         QStringList data = m_clipMonitor->getZoneInfo();
2989         m_activeTimeline->projectView()->insertZoneOverwrite(data, m_activeTimeline->inPoint());
2990     }
2991 }
2992
2993 void MainWindow::slotSelectTimelineClip()
2994 {
2995     if (m_activeTimeline)
2996         m_activeTimeline->projectView()->selectClip(true);
2997 }
2998
2999 void MainWindow::slotSelectTimelineTransition()
3000 {
3001     if (m_activeTimeline)
3002         m_activeTimeline->projectView()->selectTransition(true);
3003 }
3004
3005 void MainWindow::slotDeselectTimelineClip()
3006 {
3007     if (m_activeTimeline)
3008         m_activeTimeline->projectView()->selectClip(false, true);
3009 }
3010
3011 void MainWindow::slotDeselectTimelineTransition()
3012 {
3013     if (m_activeTimeline)
3014         m_activeTimeline->projectView()->selectTransition(false, true);
3015 }
3016
3017 void MainWindow::slotSelectAddTimelineClip()
3018 {
3019     if (m_activeTimeline)
3020         m_activeTimeline->projectView()->selectClip(true, true);
3021 }
3022
3023 void MainWindow::slotSelectAddTimelineTransition()
3024 {
3025     if (m_activeTimeline)
3026         m_activeTimeline->projectView()->selectTransition(true, true);
3027 }
3028
3029 void MainWindow::slotGroupClips()
3030 {
3031     if (m_activeTimeline)
3032         m_activeTimeline->projectView()->groupClips();
3033 }
3034
3035 void MainWindow::slotUnGroupClips()
3036 {
3037     if (m_activeTimeline)
3038         m_activeTimeline->projectView()->groupClips(false);
3039 }
3040
3041 void MainWindow::slotEditItemDuration()
3042 {
3043     if (m_activeTimeline)
3044         m_activeTimeline->projectView()->editItemDuration();
3045 }
3046
3047 void MainWindow::slotAddProjectClip(KUrl url)
3048 {
3049     if (m_activeDocument)
3050         m_activeDocument->slotAddClipFile(url, QString());
3051 }
3052
3053 void MainWindow::slotAddProjectClipList(KUrl::List urls)
3054 {
3055     if (m_activeDocument)
3056         m_activeDocument->slotAddClipList(urls, QString());
3057 }
3058
3059 void MainWindow::slotAddTransition(QAction *result)
3060 {
3061     if (!result) return;
3062     QStringList info = result->data().toStringList();
3063     if (info.isEmpty()) return;
3064     QDomElement transition = transitions.getEffectByTag(info.at(1), info.at(2));
3065     if (m_activeTimeline && !transition.isNull()) {
3066         m_activeTimeline->projectView()->slotAddTransitionToSelectedClips(transition.cloneNode().toElement());
3067     }
3068 }
3069
3070 void MainWindow::slotAddVideoEffect(QAction *result)
3071 {
3072     if (!result) return;
3073     const int EFFECT_VIDEO = 1;
3074     const int EFFECT_AUDIO = 2;
3075     QStringList info = result->data().toStringList();
3076
3077     if (info.isEmpty() || info.size() < 3) return;
3078     QDomElement effect ;
3079     if (info.at(2) == QString::number((int) EFFECT_VIDEO))
3080             effect = videoEffects.getEffectByTag(info.at(0), info.at(1));
3081     else if (info.at(2) == QString::number((int) EFFECT_AUDIO))
3082             effect = audioEffects.getEffectByTag(info.at(0), info.at(1));
3083     else
3084             effect = customEffects.getEffectByTag(info.at(0), info.at(1));
3085     if (!effect.isNull()) slotAddEffect(effect);
3086     else m_messageLabel->setMessage(i18n("Cannot find effect %1 / %2").arg(info.at(0)).arg(info.at(1)), ErrorMessage);
3087 }
3088
3089
3090 void MainWindow::slotZoomIn()
3091 {
3092     m_zoomSlider->setValue(m_zoomSlider->value() - 1);
3093     slotShowZoomSliderToolTip();
3094 }
3095
3096 void MainWindow::slotZoomOut()
3097 {
3098     m_zoomSlider->setValue(m_zoomSlider->value() + 1);
3099     slotShowZoomSliderToolTip();
3100 }
3101
3102 void MainWindow::slotFitZoom()
3103 {
3104     if (m_activeTimeline)
3105         m_zoomSlider->setValue(m_activeTimeline->fitZoom());
3106 }
3107
3108 void MainWindow::slotSetZoom(int value)
3109 {
3110     value = qMax(m_zoomSlider->minimum(), value);
3111     value = qMin(m_zoomSlider->maximum(), value);
3112
3113     if (m_activeTimeline)
3114         m_activeTimeline->slotChangeZoom(value);
3115
3116     m_zoomOut->setEnabled(value < m_zoomSlider->maximum());
3117     m_zoomIn->setEnabled(value > m_zoomSlider->minimum());
3118     slotUpdateZoomSliderToolTip(value);
3119
3120     m_zoomSlider->blockSignals(true);
3121     m_zoomSlider->setValue(value);
3122     m_zoomSlider->blockSignals(false);
3123 }
3124
3125 void MainWindow::slotShowZoomSliderToolTip(int zoomlevel)
3126 {
3127     if (zoomlevel != -1)
3128         slotUpdateZoomSliderToolTip(zoomlevel);
3129
3130     QPoint global = m_zoomSlider->rect().topLeft();
3131     global.ry() += m_zoomSlider->height() / 2;
3132     QHelpEvent toolTipEvent(QEvent::ToolTip, QPoint(0, 0), m_zoomSlider->mapToGlobal(global));
3133     QApplication::sendEvent(m_zoomSlider, &toolTipEvent);
3134 }
3135
3136 void MainWindow::slotUpdateZoomSliderToolTip(int zoomlevel)
3137 {
3138     m_zoomSlider->setToolTip(i18n("Zoom Level: %1/13", (13 - zoomlevel)));
3139 }
3140
3141 void MainWindow::slotGotProgressInfo(const QString &message, int progress)
3142 {
3143     m_statusProgressBar->setValue(progress);
3144     if (progress >= 0) {
3145         if (!message.isEmpty())
3146             m_messageLabel->setMessage(message, InformationMessage);//statusLabel->setText(message);
3147         m_statusProgressBar->setVisible(true);
3148     } else if (progress == -2) {
3149         if (!message.isEmpty())
3150             m_messageLabel->setMessage(message, ErrorMessage);
3151         m_statusProgressBar->setVisible(false);
3152     } else {
3153         m_messageLabel->setMessage(QString(), DefaultMessage);
3154         m_statusProgressBar->setVisible(false);
3155     }
3156 }
3157
3158 void MainWindow::slotShowClipProperties(DocClipBase *clip)
3159 {
3160     if (clip->clipType() == TEXT) {
3161         QString titlepath = m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
3162         if (!clip->getProperty("resource").isEmpty() && clip->getProperty("xmldata").isEmpty()) {
3163             // template text clip
3164
3165             // Get the list of existing templates
3166             QStringList filter;
3167             filter << "*.kdenlivetitle";
3168             QStringList templateFiles = QDir(titlepath).entryList(filter, QDir::Files);
3169
3170             QDialog *dia = new QDialog(this);
3171             Ui::TemplateClip_UI dia_ui;
3172             dia_ui.setupUi(dia);
3173             int ix = -1;
3174             const QString templatePath = clip->getProperty("resource");
3175             for (int i = 0; i < templateFiles.size(); ++i) {
3176                 dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), titlepath + templateFiles.at(i));
3177                 if (templatePath == KUrl(titlepath + templateFiles.at(i)).path()) ix = i;
3178             }
3179             if (ix != -1) dia_ui.template_list->comboBox()->setCurrentIndex(ix);
3180             else dia_ui.template_list->comboBox()->insertItem(0, templatePath);
3181             dia_ui.template_list->fileDialog()->setFilter("*.kdenlivetitle");
3182             //warning: setting base directory doesn't work??
3183             KUrl startDir(titlepath);
3184             dia_ui.template_list->fileDialog()->setUrl(startDir);
3185             dia_ui.description->setText(clip->getProperty("description"));
3186             if (dia->exec() == QDialog::Accepted) {
3187                 QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
3188                 if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
3189
3190                 QMap <QString, QString> newprops;
3191
3192                 if (KUrl(textTemplate).path() != templatePath) {
3193                     // The template was changed
3194                     newprops.insert("resource", textTemplate);
3195                 }
3196
3197                 if (dia_ui.description->toPlainText() != clip->getProperty("description")) {
3198                     newprops.insert("description", dia_ui.description->toPlainText());
3199                 }
3200
3201                 QString newtemplate = newprops.value("xmltemplate");
3202                 if (newtemplate.isEmpty()) newtemplate = templatePath;
3203
3204                 // template modified we need to update xmldata
3205                 QString description = newprops.value("description");
3206                 if (description.isEmpty()) description = clip->getProperty("description");
3207                 else newprops.insert("templatetext", description);
3208                 //newprops.insert("xmldata", m_projectList->generateTemplateXml(newtemplate, description).toString());
3209                 if (!newprops.isEmpty()) {
3210                     EditClipCommand *command = new EditClipCommand(m_projectList, clip->getId(), clip->currentProperties(newprops), newprops, true);
3211                     m_activeDocument->commandStack()->push(command);
3212                 }
3213             }
3214             delete dia;
3215             return;
3216         }
3217         QString path = clip->getProperty("resource");
3218         TitleWidget *dia_ui = new TitleWidget(KUrl(), m_activeDocument->timecode(), titlepath, m_projectMonitor->render, this);
3219         QDomDocument doc;
3220         doc.setContent(clip->getProperty("xmldata"));
3221         dia_ui->setXml(doc);
3222         if (dia_ui->exec() == QDialog::Accepted) {
3223             QMap <QString, QString> newprops;
3224             newprops.insert("xmldata", dia_ui->xml().toString());
3225             if (dia_ui->outPoint() != clip->duration().frames(m_activeDocument->fps())) {
3226                 // duration changed, we need to update duration
3227                 newprops.insert("out", QString::number(dia_ui->outPoint()));
3228                 int currentLength = QString(clip->producerProperty("length")).toInt();
3229                 if (currentLength <= dia_ui->outPoint())
3230                         newprops.insert("length", QString::number(dia_ui->outPoint() + 1));
3231                 else newprops.insert("length", clip->producerProperty("length"));
3232             }
3233             if (!path.isEmpty()) {
3234                 // we are editing an external file, asked if we want to detach from that file or save the result to that title file.
3235                 if (KMessageBox::questionYesNo(this, i18n("You are editing an external title clip (%1). Do you want to save your changes to the title file or save the changes for this project only?", path), i18n("Save Title"), KGuiItem(i18n("Save to title file")), KGuiItem(i18n("Save in project only"))) == KMessageBox::Yes) {
3236                     // save to external file
3237                     dia_ui->saveTitle(path);
3238                 } else newprops.insert("resource", QString());
3239             }
3240             EditClipCommand *command = new EditClipCommand(m_projectList, clip->getId(), clip->currentProperties(newprops), newprops, true);
3241             m_activeDocument->commandStack()->push(command);
3242             //m_activeTimeline->projectView()->slotUpdateClip(clip->getId());
3243             m_activeDocument->setModified(true);
3244         }
3245         delete dia_ui;
3246
3247         //m_activeDocument->editTextClip(clip->getProperty("xml"), clip->getId());
3248         return;
3249     }
3250
3251     // any type of clip but a title
3252     ClipProperties *dia = new ClipProperties(clip, m_activeDocument->timecode(), m_activeDocument->fps(), this);
3253     connect(dia, SIGNAL(addMarker(const QString &, GenTime, QString)), m_activeTimeline->projectView(), SLOT(slotAddClipMarker(const QString &, GenTime, QString)));
3254     connect(dia, SIGNAL(deleteProxy(const QString)), m_projectList, SLOT(slotDeleteProxy(const QString)));
3255     connect(dia, SIGNAL(applyNewClipProperties(const QString, QMap <QString, QString> , QMap <QString, QString> , bool, bool)), this, SLOT(slotApplyNewClipProperties(const QString, QMap <QString, QString> , QMap <QString, QString> , bool, bool)));
3256     dia->show();
3257 }
3258
3259
3260 void MainWindow::slotApplyNewClipProperties(const QString id, QMap <QString, QString> props, QMap <QString, QString> newprops, bool refresh, bool reload)
3261 {
3262     if (newprops.isEmpty()) return;
3263     EditClipCommand *command = new EditClipCommand(m_projectList, id, props, newprops, true);
3264     m_activeDocument->commandStack()->push(command);
3265     m_activeDocument->setModified();
3266
3267     if (refresh) {
3268         // update clip occurences in timeline
3269         m_activeTimeline->projectView()->slotUpdateClip(id, reload);
3270     }
3271 }
3272
3273
3274 void MainWindow::slotShowClipProperties(QList <DocClipBase *> cliplist, QMap<QString, QString> commonproperties)
3275 {
3276     ClipProperties dia(cliplist, m_activeDocument->timecode(), commonproperties, this);
3277     if (dia.exec() == QDialog::Accepted) {
3278         QUndoCommand *command = new QUndoCommand();
3279         command->setText(i18n("Edit clips"));
3280         QMap <QString, QString> newImageProps = dia.properties();
3281         // Transparency setting applies only for images
3282         QMap <QString, QString> newProps = newImageProps;
3283         newProps.remove("transparency");
3284
3285         for (int i = 0; i < cliplist.count(); i++) {
3286             DocClipBase *clip = cliplist.at(i);
3287             if (clip->clipType() == IMAGE)
3288                 new EditClipCommand(m_projectList, clip->getId(), clip->currentProperties(newImageProps), newImageProps, true, command);
3289             else 
3290                 new EditClipCommand(m_projectList, clip->getId(), clip->currentProperties(newProps), newProps, true, command);
3291         }
3292         m_activeDocument->commandStack()->push(command);
3293         for (int i = 0; i < cliplist.count(); i++)
3294             m_activeTimeline->projectView()->slotUpdateClip(cliplist.at(i)->getId(), dia.needsTimelineReload());
3295     }
3296 }
3297
3298 void MainWindow::customEvent(QEvent* e)
3299 {
3300     if (e->type() == QEvent::User)
3301         m_messageLabel->setMessage(static_cast <MltErrorEvent *>(e)->message(), MltError);
3302 }
3303 void MainWindow::slotActivateEffectStackView(ClipItem* item, int ix, bool raise)
3304 {
3305     Q_UNUSED(item)
3306     Q_UNUSED(ix)
3307
3308     if (raise)
3309         m_effectStack->raiseWindow(m_effectStackDock);
3310 }
3311
3312 void MainWindow::slotActivateTransitionView(Transition *t)
3313 {
3314     if (t)
3315         m_transitionConfig->raiseWindow(m_transitionConfigDock);
3316 }
3317
3318 void MainWindow::slotSnapRewind()
3319 {
3320     if (m_projectMonitor->isActive()) {
3321         if (m_activeTimeline)
3322             m_activeTimeline->projectView()->slotSeekToPreviousSnap();
3323     } else  {
3324         m_clipMonitor->slotSeekToPreviousSnap();
3325     }
3326 }
3327
3328 void MainWindow::slotSnapForward()
3329 {
3330     if (m_projectMonitor->isActive()) {
3331         if (m_activeTimeline)
3332             m_activeTimeline->projectView()->slotSeekToNextSnap();
3333     } else {
3334         m_clipMonitor->slotSeekToNextSnap();
3335     }
3336 }
3337
3338 void MainWindow::slotClipStart()
3339 {
3340     if (m_projectMonitor->isActive()) {
3341         if (m_activeTimeline)
3342             m_activeTimeline->projectView()->clipStart();
3343     }
3344 }
3345
3346 void MainWindow::slotClipEnd()
3347 {
3348     if (m_projectMonitor->isActive()) {
3349         if (m_activeTimeline)
3350             m_activeTimeline->projectView()->clipEnd();
3351     }
3352 }
3353
3354 void MainWindow::slotZoneStart()
3355 {
3356     if (m_projectMonitor->isActive())
3357         m_projectMonitor->slotZoneStart();
3358     else
3359         m_clipMonitor->slotZoneStart();
3360 }
3361
3362 void MainWindow::slotZoneEnd()
3363 {
3364     if (m_projectMonitor->isActive())
3365         m_projectMonitor->slotZoneEnd();
3366     else
3367         m_clipMonitor->slotZoneEnd();
3368 }
3369
3370 void MainWindow::slotChangeTool(QAction * action)
3371 {
3372     if (action == m_buttonSelectTool)
3373         slotSetTool(SELECTTOOL);
3374     else if (action == m_buttonRazorTool)
3375         slotSetTool(RAZORTOOL);
3376     else if (action == m_buttonSpacerTool)
3377         slotSetTool(SPACERTOOL);
3378 }
3379
3380 void MainWindow::slotChangeEdit(QAction * action)
3381 {
3382     if (!m_activeTimeline)
3383         return;
3384
3385     if (action == m_overwriteEditTool)
3386         m_activeTimeline->projectView()->setEditMode(OVERWRITEEDIT);
3387     else if (action == m_insertEditTool)
3388         m_activeTimeline->projectView()->setEditMode(INSERTEDIT);
3389     else
3390         m_activeTimeline->projectView()->setEditMode(NORMALEDIT);
3391 }
3392
3393 void MainWindow::slotSetTool(PROJECTTOOL tool)
3394 {
3395     if (m_activeDocument && m_activeTimeline) {
3396         //m_activeDocument->setTool(tool);
3397         QString message;
3398         switch (tool)  {
3399         case SPACERTOOL:
3400             message = i18n("Ctrl + click to use spacer on current track only");
3401             break;
3402         case RAZORTOOL:
3403             message = i18n("Click on a clip to cut it");
3404             break;
3405         default:
3406             message = i18n("Shift + click to create a selection rectangle, Ctrl + click to add an item to selection");
3407             break;
3408         }
3409         m_messageLabel->setMessage(message, InformationMessage);
3410         m_activeTimeline->projectView()->setTool(tool);
3411     }
3412 }
3413
3414 void MainWindow::slotCopy()
3415 {
3416     if (m_activeDocument && m_activeTimeline)
3417         m_activeTimeline->projectView()->copyClip();
3418 }
3419
3420 void MainWindow::slotPaste()
3421 {
3422     if (m_activeDocument && m_activeTimeline)
3423         m_activeTimeline->projectView()->pasteClip();
3424 }
3425
3426 void MainWindow::slotPasteEffects()
3427 {
3428     if (m_activeDocument && m_activeTimeline)
3429         m_activeTimeline->projectView()->pasteClipEffects();
3430 }
3431
3432 void MainWindow::slotFind()
3433 {
3434     if (!m_activeDocument || !m_activeTimeline) return;
3435     m_projectSearch->setEnabled(false);
3436     m_findActivated = true;
3437     m_findString.clear();
3438     m_activeTimeline->projectView()->initSearchStrings();
3439     statusBar()->showMessage(i18n("Starting -- find text as you type"));
3440     m_findTimer.start(5000);
3441     qApp->installEventFilter(this);
3442 }
3443
3444 void MainWindow::slotFindNext()
3445 {
3446     if (m_activeTimeline && m_activeTimeline->projectView()->findNextString(m_findString))
3447         statusBar()->showMessage(i18n("Found: %1", m_findString));
3448     else
3449         statusBar()->showMessage(i18n("Reached end of project"));
3450     m_findTimer.start(4000);
3451 }
3452
3453 void MainWindow::findAhead()
3454 {
3455     if (m_activeTimeline && m_activeTimeline->projectView()->findString(m_findString)) {
3456         m_projectSearchNext->setEnabled(true);
3457         statusBar()->showMessage(i18n("Found: %1", m_findString));
3458     } else {
3459         m_projectSearchNext->setEnabled(false);
3460         statusBar()->showMessage(i18n("Not found: %1", m_findString));
3461     }
3462 }
3463
3464 void MainWindow::findTimeout()
3465 {
3466     m_projectSearchNext->setEnabled(false);
3467     m_findActivated = false;
3468     m_findString.clear();
3469     statusBar()->showMessage(i18n("Find stopped"), 3000);
3470     if (m_activeTimeline) m_activeTimeline->projectView()->clearSearchStrings();
3471     m_projectSearch->setEnabled(true);
3472     removeEventFilter(this);
3473 }
3474
3475 void MainWindow::slotClipInTimeline(const QString &clipId)
3476 {
3477     if (m_activeTimeline && m_activeDocument) {
3478         QList<ItemInfo> matching = m_activeTimeline->projectView()->findId(clipId);
3479
3480         QMenu *inTimelineMenu = static_cast<QMenu*>(factory()->container("clip_in_timeline", this));
3481         inTimelineMenu->clear();
3482
3483         QList <QAction *> actionList;
3484
3485         for (int i = 0; i < matching.count(); ++i) {
3486             QString track = QString::number(matching.at(i).track);
3487             QString start = m_activeDocument->timecode().getTimecode(matching.at(i).startPos);
3488             int j = 0;
3489             QAction *a = new QAction(track + ": " + start, this);
3490             a->setData(QStringList() << track << start);
3491             connect(a, SIGNAL(triggered()), this, SLOT(slotSelectClipInTimeline()));
3492             while (j < actionList.count()) {
3493                 if (actionList.at(j)->text() > a->text()) break;
3494                 j++;
3495             }
3496             actionList.insert(j, a);
3497         }
3498         inTimelineMenu->addActions(actionList);
3499
3500         if (matching.empty())
3501             inTimelineMenu->setEnabled(false);
3502         else
3503             inTimelineMenu->setEnabled(true);
3504     }
3505 }
3506
3507 void MainWindow::slotClipInProjectTree()
3508 {
3509     if (m_activeTimeline) {
3510         const QStringList &clipIds = m_activeTimeline->projectView()->selectedClips();
3511         if (clipIds.isEmpty())
3512             return;
3513         m_projectListDock->raise();
3514         for (int i = 0; i < clipIds.count(); i++)
3515             m_projectList->selectItemById(clipIds.at(i));
3516         if (m_projectMonitor->isActive())
3517             slotSwitchMonitors();
3518     }
3519 }
3520
3521 /*void MainWindow::slotClipToProjectTree()
3522 {
3523     if (m_activeTimeline) {
3524     const QList<ClipItem *> clips =  m_activeTimeline->projectView()->selectedClipItems();
3525         if (clips.isEmpty()) return;
3526         for (int i = 0; i < clips.count(); i++) {
3527         m_projectList->slotAddXmlClip(clips.at(i)->itemXml());
3528         }
3529         //m_projectList->selectItemById(clipIds.at(i));
3530     }
3531 }*/
3532
3533 void MainWindow::slotSelectClipInTimeline()
3534 {
3535     if (m_activeTimeline) {
3536         QAction *action = qobject_cast<QAction *>(sender());
3537         QStringList data = action->data().toStringList();
3538         m_activeTimeline->projectView()->selectFound(data.at(0), data.at(1));
3539     }
3540 }
3541
3542 void MainWindow::keyPressEvent(QKeyEvent *ke)
3543 {
3544     if (m_findActivated) {
3545         if (ke->key() == Qt::Key_Backspace) {
3546             m_findString = m_findString.left(m_findString.length() - 1);
3547
3548             if (!m_findString.isEmpty())
3549                 findAhead();
3550             else
3551                 findTimeout();
3552
3553             m_findTimer.start(4000);
3554             ke->accept();
3555             return;
3556         } else if (ke->key() == Qt::Key_Escape) {
3557             findTimeout();
3558             ke->accept();
3559             return;
3560         } else if (ke->key() == Qt::Key_Space || !ke->text().trimmed().isEmpty()) {
3561             m_findString += ke->text();
3562
3563             findAhead();
3564
3565             m_findTimer.start(4000);
3566             ke->accept();
3567             return;
3568         }
3569     } else {
3570         KXmlGuiWindow::keyPressEvent(ke);
3571     }
3572 }
3573
3574
3575 /** Gets called when the window gets hidden */
3576 void MainWindow::hideEvent(QHideEvent */*event*/)
3577 {
3578     if (isMinimized() && m_monitorManager)
3579         m_monitorManager->stopActiveMonitor();
3580 }
3581
3582 bool MainWindow::eventFilter(QObject *obj, QEvent *event)
3583 {
3584     if (m_findActivated) {
3585         if (event->type() == QEvent::ShortcutOverride) {
3586             QKeyEvent* ke = (QKeyEvent*) event;
3587             if (ke->text().trimmed().isEmpty()) return false;
3588             ke->accept();
3589             return true;
3590         } else {
3591             return false;
3592         }
3593     } else {
3594         // pass the event on to the parent class
3595         return QMainWindow::eventFilter(obj, event);
3596     }
3597 }
3598
3599
3600 void MainWindow::slotSaveZone(Render *render, QPoint zone, DocClipBase *baseClip, KUrl path)
3601 {
3602     KDialog *dialog = new KDialog(this);
3603     dialog->setCaption("Save clip zone");
3604     dialog->setButtons(KDialog::Ok | KDialog::Cancel);
3605
3606     QWidget *widget = new QWidget(dialog);
3607     dialog->setMainWidget(widget);
3608
3609     QVBoxLayout *vbox = new QVBoxLayout(widget);
3610     QLabel *label1 = new QLabel(i18n("Save clip zone as:"), this);
3611     if (path.isEmpty()) {
3612         QString tmppath = m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash);
3613         if (baseClip == NULL) tmppath.append("untitled.mlt");
3614         else {
3615             tmppath.append((baseClip->name().isEmpty() ? baseClip->fileURL().fileName() : baseClip->name()) + "-" + QString::number(zone.x()).rightJustified(4, '0') + ".mlt");
3616         }
3617         path = KUrl(tmppath);
3618     }
3619     KUrlRequester *url = new KUrlRequester(path, this);
3620     url->setFilter("video/mlt-playlist");
3621     QLabel *label2 = new QLabel(i18n("Description:"), this);
3622     KLineEdit *edit = new KLineEdit(this);
3623     vbox->addWidget(label1);
3624     vbox->addWidget(url);
3625     vbox->addWidget(label2);
3626     vbox->addWidget(edit);
3627     if (dialog->exec() == QDialog::Accepted) {
3628         if (QFile::exists(url->url().path())) {
3629             if (KMessageBox::questionYesNo(this, i18n("File %1 already exists.\nDo you want to overwrite it?", url->url().path())) == KMessageBox::No) {
3630                 slotSaveZone(render, zone, baseClip, url->url());
3631                 return;
3632             }
3633         }
3634         if (baseClip && !baseClip->fileURL().isEmpty()) {
3635             // create zone from clip url, so that we don't have problems with proxy clips
3636             QProcess p;
3637 #if QT_VERSION >= 0x040600
3638             QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
3639             env.remove("MLT_PROFILE");
3640             p.setProcessEnvironment(env);
3641 #else
3642             QStringList env = QProcess::systemEnvironment();
3643             env << "MLT_PROFILE='\0'";
3644             p.setEnvironment(env);
3645 #endif
3646             p.start(KdenliveSettings::rendererpath(), QStringList() << baseClip->fileURL().path() << "in=" + QString::number(zone.x()) << "out=" + QString::number(zone.y()) << "-consumer" << "xml:" + url->url().path());
3647             if (!p.waitForStarted(3000)) {
3648                 KMessageBox::sorry(this, i18n("Cannot start MLT's renderer:\n%1", KdenliveSettings::rendererpath()));
3649             }
3650             else if (!p.waitForFinished(5000)) {
3651                 KMessageBox::sorry(this, i18n("Timeout while creating xml output"));
3652             }
3653         }
3654         else render->saveZone(url->url(), edit->text(), zone);
3655     }
3656
3657 }
3658
3659 void MainWindow::slotSetInPoint()
3660 {
3661     if (m_clipMonitor->isActive()) {
3662         m_clipMonitor->slotSetZoneStart();
3663     } else {
3664         m_projectMonitor->slotSetZoneStart();
3665     }
3666 }
3667
3668 void MainWindow::slotSetOutPoint()
3669 {
3670     if (m_clipMonitor->isActive()) {
3671         m_clipMonitor->slotSetZoneEnd();
3672     } else {
3673         m_projectMonitor->slotSetZoneEnd();
3674     }
3675 }
3676
3677 void MainWindow::slotResizeItemStart()
3678 {
3679     if (m_activeTimeline)
3680         m_activeTimeline->projectView()->setInPoint();
3681 }
3682
3683 void MainWindow::slotResizeItemEnd()
3684 {
3685     if (m_activeTimeline)
3686         m_activeTimeline->projectView()->setOutPoint();
3687 }
3688
3689 int MainWindow::getNewStuff(const QString &configFile)
3690 {
3691     KNS3::Entry::List entries;
3692 #if KDE_IS_VERSION(4,3,80)
3693     KNS3::DownloadDialog dialog(configFile);
3694     dialog.exec();
3695     entries = dialog.changedEntries();
3696     foreach(const KNS3::Entry & entry, entries) {
3697         if (entry.status() == KNS3::Entry::Installed)
3698             kDebug() << "// Installed files: " << entry.installedFiles();
3699     }
3700 #else
3701     KNS::Engine engine(0);
3702     if (engine.init(configFile))
3703         entries = engine.downloadDialogModal(this);
3704     foreach(KNS::Entry * entry, entries) {
3705         if (entry->status() == KNS::Entry::Installed)
3706             kDebug() << "// Installed files: " << entry->installedFiles();
3707     }
3708 #endif
3709     return entries.size();
3710 }
3711
3712 void MainWindow::slotGetNewTitleStuff()
3713 {
3714     if (getNewStuff("kdenlive_titles.knsrc") > 0)
3715         TitleWidget::refreshTitleTemplates();
3716 }
3717
3718 void MainWindow::slotGetNewLumaStuff()
3719 {
3720     if (getNewStuff("kdenlive_wipes.knsrc") > 0) {
3721         initEffects::refreshLumas();
3722         m_activeTimeline->projectView()->reloadTransitionLumas();
3723     }
3724 }
3725
3726 void MainWindow::slotGetNewRenderStuff()
3727 {
3728     if (getNewStuff("kdenlive_renderprofiles.knsrc") > 0)
3729         if (m_renderWidget)
3730             m_renderWidget->reloadProfiles();
3731 }
3732
3733 void MainWindow::slotGetNewMltProfileStuff()
3734 {
3735     if (getNewStuff("kdenlive_projectprofiles.knsrc") > 0) {
3736         // update the list of profiles in settings dialog
3737         KdenliveSettingsDialog* d = static_cast <KdenliveSettingsDialog*>(KConfigDialog::exists("settings"));
3738         if (d)
3739             d->checkProfile();
3740     }
3741 }
3742
3743 void MainWindow::slotAutoTransition()
3744 {
3745     if (m_activeTimeline)
3746         m_activeTimeline->projectView()->autoTransition();
3747 }
3748
3749 void MainWindow::slotSplitAudio()
3750 {
3751     if (m_activeTimeline)
3752         m_activeTimeline->projectView()->splitAudio();
3753 }
3754
3755 void MainWindow::slotUpdateClipType(QAction *action)
3756 {
3757     if (m_activeTimeline) {
3758         if (action->data().toString() == "clip_audio_only") m_activeTimeline->projectView()->setAudioOnly();
3759         else if (action->data().toString() == "clip_video_only") m_activeTimeline->projectView()->setVideoOnly();
3760         else m_activeTimeline->projectView()->setAudioAndVideo();
3761     }
3762 }
3763
3764 void MainWindow::slotDvdWizard(const QString &url, const QString &profile)
3765 {
3766     // We must stop the monitors since we create a new on in the dvd wizard
3767     m_clipMonitor->stop();
3768     m_projectMonitor->stop();
3769     DvdWizard w(url, profile, this);
3770     w.exec();
3771     m_projectMonitor->start();
3772 }
3773
3774 void MainWindow::slotShowTimeline(bool show)
3775 {
3776     if (show == false) {
3777         m_timelineState = saveState();
3778         centralWidget()->setHidden(true);
3779     } else {
3780         centralWidget()->setHidden(false);
3781         restoreState(m_timelineState);
3782     }
3783 }
3784
3785 void MainWindow::slotMaximizeCurrent(bool)
3786 {
3787     //TODO: is there a way to maximize current widget?
3788
3789     m_timelineState = saveState();
3790     QWidget *par = focusWidget()->parentWidget();
3791     while (par->parentWidget() && par->parentWidget() != this)
3792         par = par->parentWidget();
3793     kDebug() << "CURRENT WIDGET: " << par->objectName();
3794 }
3795
3796 void MainWindow::loadStabilize()
3797 {
3798         QMenu* stabMenu= static_cast<QMenu*>(factory()->container("stabilize", this));
3799         if (stabMenu){
3800                 stabMenu->clear();
3801                 Mlt::Profile profile;
3802                 if (Mlt::Factory::filter(profile,(char*)"videostab")){
3803                         QAction *action=stabMenu->addAction("Videostab (vstab)");
3804                         action->setData("videostab");
3805                         connect(action,SIGNAL(triggered()), this, SLOT(slotStabilize()));
3806                 }
3807                 if (Mlt::Factory::filter(profile,(char*)"videostab2")){
3808                         QAction *action=stabMenu->addAction("Videostab (transcode)");
3809                         action->setData("videostab2");
3810                         connect(action,SIGNAL(triggered()), this, SLOT(slotStabilize()));
3811                 }
3812         }
3813
3814
3815 }
3816
3817 void MainWindow::loadTranscoders()
3818 {
3819     QMenu *transMenu = static_cast<QMenu*>(factory()->container("transcoders", this));
3820     transMenu->clear();
3821
3822     KSharedConfigPtr config = KSharedConfig::openConfig("kdenlivetranscodingrc");
3823     KConfigGroup transConfig(config, "Transcoding");
3824     // read the entries
3825     QMap< QString, QString > profiles = transConfig.entryMap();
3826     QMapIterator<QString, QString> i(profiles);
3827     while (i.hasNext()) {
3828         i.next();
3829         QStringList data = i.value().split(";", QString::SkipEmptyParts);
3830         QAction *a = transMenu->addAction(i.key());
3831         a->setData(data);
3832         if (data.count() > 1)
3833             a->setToolTip(data.at(1));
3834         connect(a, SIGNAL(triggered()), this, SLOT(slotTranscode()));
3835     }
3836 }
3837
3838 void MainWindow::slotStabilize(KUrl::List urls)
3839 {
3840         QString condition,filtername;
3841
3842         if (urls.isEmpty()) {
3843         QAction *action = qobject_cast<QAction *>(sender());
3844                 if (action){
3845                         filtername=action->data().toString();
3846                         urls = m_projectList->getConditionalUrls(condition);
3847                 }
3848     }
3849     if (urls.isEmpty()) {
3850         m_messageLabel->setMessage(i18n("No clip to transcode"), ErrorMessage);
3851         return;
3852     }
3853         Mlt::Profile profile;
3854         Mlt::Filter filter(profile,filtername.toUtf8().data());
3855         ClipStabilize *d=new ClipStabilize(urls,filtername,&filter);
3856         connect(d, SIGNAL(addClip(KUrl)), this, SLOT(slotAddProjectClip(KUrl)));
3857         d->show();
3858
3859 }
3860
3861 void MainWindow::slotTranscode(KUrl::List urls)
3862 {
3863     QString params;
3864     QString desc;
3865     QString condition;
3866     if (urls.isEmpty()) {
3867         QAction *action = qobject_cast<QAction *>(sender());
3868         QStringList data = action->data().toStringList();
3869         params = data.at(0);
3870         if (data.count() > 1) desc = data.at(1);
3871         if (data.count() > 2) condition = data.at(2);
3872         urls << m_projectList->getConditionalUrls(condition);
3873         urls.removeAll(KUrl());
3874     }
3875     if (urls.isEmpty()) {
3876         m_messageLabel->setMessage(i18n("No clip to transcode"), ErrorMessage);
3877         return;
3878     }
3879     ClipTranscode *d = new ClipTranscode(urls, params, desc);
3880     connect(d, SIGNAL(addClip(KUrl)), this, SLOT(slotAddProjectClip(KUrl)));
3881     d->show();
3882     //QProcess::startDetached("ffmpeg", parameters);
3883 }
3884
3885 void MainWindow::slotTranscodeClip()
3886 {
3887     KUrl::List urls = KFileDialog::getOpenUrls(KUrl("kfiledialog:///projectfolder"));
3888     if (urls.isEmpty()) return;
3889     slotTranscode(urls);
3890 }
3891
3892 void MainWindow::slotSetDocumentRenderProfile(QMap <QString, QString> props)
3893 {
3894     if (m_activeDocument == NULL) return;
3895     QMapIterator<QString, QString> i(props);
3896     while (i.hasNext()) {
3897         i.next();
3898         m_activeDocument->setDocumentProperty(i.key(), i.value());
3899     }
3900     m_activeDocument->setModified(true);
3901 }
3902
3903
3904 void MainWindow::slotPrepareRendering(bool scriptExport, bool zoneOnly, const QString &chapterFile)
3905 {
3906     if (m_activeDocument == NULL || m_renderWidget == NULL) return;
3907     QString scriptPath;
3908     QString playlistPath;
3909     if (scriptExport) {
3910         bool ok;
3911         QString scriptsFolder = m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash) + "scripts/";
3912         QString path = m_renderWidget->getFreeScriptName();
3913         scriptPath = QInputDialog::getText(this, i18n("Create Render Script"), i18n("Script name (will be saved in: %1)", scriptsFolder), QLineEdit::Normal, KUrl(path).fileName(), &ok);
3914         if (!ok || scriptPath.isEmpty()) return;
3915         scriptPath.prepend(scriptsFolder);
3916         QFile f(scriptPath);
3917         if (f.exists()) {
3918             if (KMessageBox::warningYesNo(this, i18n("Script file already exists. Do you want to overwrite it?")) != KMessageBox::Yes)
3919                 return;
3920         }
3921         playlistPath = scriptPath + ".mlt";
3922     } else {
3923         KTemporaryFile temp;
3924         temp.setAutoRemove(false);
3925         temp.setSuffix(".mlt");
3926         temp.open();
3927         playlistPath = temp.fileName();
3928     }
3929     QString playlistContent = m_projectMonitor->sceneList();
3930     if (!chapterFile.isEmpty()) {
3931         int in = 0;
3932         int out;
3933         if (!zoneOnly) out = (int) GenTime(m_activeDocument->projectDuration()).frames(m_activeDocument->fps());
3934         else {
3935             in = m_activeTimeline->inPoint();
3936             out = m_activeTimeline->outPoint();
3937         }
3938         QDomDocument doc;
3939         QDomElement chapters = doc.createElement("chapters");
3940         chapters.setAttribute("fps", m_activeDocument->fps());
3941         doc.appendChild(chapters);
3942
3943         QDomElement guidesxml = m_activeDocument->guidesXml();
3944         QDomNodeList nodes = guidesxml.elementsByTagName("guide");
3945         for (int i = 0; i < nodes.count(); i++) {
3946             QDomElement e = nodes.item(i).toElement();
3947             if (!e.isNull()) {
3948                 QString comment = e.attribute("comment");
3949                 int time = (int) GenTime(e.attribute("time").toDouble()).frames(m_activeDocument->fps());
3950                 if (time >= in && time < out) {
3951                     if (zoneOnly) time = time - in;
3952                     QDomElement chapter = doc.createElement("chapter");
3953                     chapters.appendChild(chapter);
3954                     chapter.setAttribute("title", comment);
3955                     chapter.setAttribute("time", time);
3956                 }
3957             }
3958         }
3959         if (chapters.childNodes().count() > 0) {
3960             if (m_activeTimeline->projectView()->hasGuide(out, 0) == -1) {
3961                 // Always insert a guide in pos 0
3962                 QDomElement chapter = doc.createElement("chapter");
3963                 chapters.insertBefore(chapter, QDomNode());
3964                 chapter.setAttribute("title", i18n("Start"));
3965                 chapter.setAttribute("time", "0");
3966             }
3967             // save chapters file
3968             QFile file(chapterFile);
3969             if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
3970                 kWarning() << "//////  ERROR writing DVD CHAPTER file: " << chapterFile;
3971             } else {
3972                 file.write(doc.toString().toUtf8());
3973                 if (file.error() != QFile::NoError) {
3974                     kWarning() << "//////  ERROR writing DVD CHAPTER file: " << chapterFile;
3975                 }
3976                 file.close();
3977             }
3978         }
3979     }
3980     bool exportAudio;
3981     if (m_renderWidget->automaticAudioExport()) {
3982         exportAudio = m_activeTimeline->checkProjectAudio();
3983     } else exportAudio = m_renderWidget->selectedAudioExport();
3984
3985     // Set playlist audio volume to 100%
3986     QDomDocument doc;
3987     doc.setContent(playlistContent);
3988     QDomElement tractor = doc.documentElement().firstChildElement("tractor");
3989     if (!tractor.isNull()) {
3990         QDomNodeList props = tractor.elementsByTagName("property");
3991         for (int i = 0; i < props.count(); i++) {
3992             if (props.at(i).toElement().attribute("name") == "meta.volume") {
3993                 props.at(i).firstChild().setNodeValue("1");
3994                 break;
3995             }
3996         }
3997     }
3998     
3999     // Do we want proxy rendering
4000     if (m_projectList->useProxy() && !m_renderWidget->proxyRendering()) {
4001         QString root = doc.documentElement().attribute("root");
4002
4003         // replace proxy clips with originals
4004         QMap <QString, QString> proxies = m_projectList->getProxies();
4005
4006         QDomNodeList producers = doc.elementsByTagName("producer");
4007         QString producerResource;
4008         QString suffix;
4009         for (uint n = 0; n < producers.length(); n++) {
4010             QDomElement e = producers.item(n).toElement();
4011             producerResource = EffectsList::property(e, "resource");
4012             if (producerResource.isEmpty()) continue;
4013             if (!producerResource.startsWith("/")) {
4014                 producerResource.prepend(root + "/");
4015             }
4016             if (producerResource.contains('?')) {
4017                 // slowmotion producer
4018                 suffix = "?" + producerResource.section('?', 1);
4019                 producerResource = producerResource.section('?', 0, 0);
4020             }
4021             else suffix.clear();
4022             if (!producerResource.isEmpty()) {
4023                 if (proxies.contains(producerResource)) {
4024                     EffectsList::setProperty(e, "resource", proxies.value(producerResource) + suffix);
4025                     // We need to delete the "aspect_ratio" property because proxy clips
4026                     // sometimes have different ratio than original clips
4027                     EffectsList::removeProperty(e, "aspect_ratio");
4028                     EffectsList::removeMetaProperties(e);
4029                 }
4030             }
4031         }
4032         
4033         /*QMapIterator<QString, QString> i(proxies);
4034         while (i.hasNext()) {
4035             i.next();
4036             // Replace all keys with their values (proxy path with original path)
4037             QString key = i.key();
4038             playlistContent.replace(key, i.value());
4039             if (!root.isEmpty() && key.startsWith(root)) {
4040                 // in case the resource path in MLT playlist is relative
4041                 key.remove(0, root.count() + 1);
4042                 playlistContent.replace(key, i.value());
4043             }
4044         }*/
4045     }
4046     playlistContent = doc.toString();
4047     
4048     // Do save scenelist
4049     QFile file(playlistPath);
4050     if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
4051         m_messageLabel->setMessage(i18n("Cannot write to file %1").arg(playlistPath), ErrorMessage);
4052         return;
4053     }
4054     file.write(playlistContent.toUtf8());
4055     if (file.error() != QFile::NoError) {
4056         m_messageLabel->setMessage(i18n("Cannot write to file %1").arg(playlistPath), ErrorMessage);
4057         file.close();
4058         return;
4059     }
4060     file.close();
4061     m_renderWidget->slotExport(scriptExport, m_activeTimeline->inPoint(), m_activeTimeline->outPoint(), playlistPath, scriptPath, exportAudio);
4062 }
4063
4064 void MainWindow::slotUpdateTimecodeFormat(int ix)
4065 {
4066     KdenliveSettings::setFrametimecode(ix == 1);
4067     m_clipMonitor->updateTimecodeFormat();
4068     m_projectMonitor->updateTimecodeFormat();
4069     m_transitionConfig->updateTimecodeFormat();
4070     m_effectStack->updateTimecodeFormat();
4071     //m_activeTimeline->projectView()->clearSelection();
4072     m_activeTimeline->updateRuler();
4073 }
4074
4075 void MainWindow::slotRemoveFocus()
4076 {
4077     statusBar()->setFocus();
4078     statusBar()->clearFocus();
4079 }
4080
4081 void MainWindow::slotRevert()
4082 {
4083     if (KMessageBox::warningContinueCancel(this, i18n("This will delete all changes made since you last saved your project. Are you sure you want to continue?"), i18n("Revert to last saved version")) == KMessageBox::Cancel) return;
4084     KUrl url = m_activeDocument->url();
4085     if (closeCurrentDocument(false))
4086         doOpenFile(url, NULL);
4087 }
4088
4089
4090 void MainWindow::slotShutdown()
4091 {
4092     if (m_activeDocument) m_activeDocument->setModified(false);
4093     // Call shutdown
4094     QDBusConnectionInterface* interface = QDBusConnection::sessionBus().interface();
4095     if (interface && interface->isServiceRegistered("org.kde.ksmserver")) {
4096         QDBusInterface smserver("org.kde.ksmserver", "/KSMServer", "org.kde.KSMServerInterface");
4097         smserver.call("logout", 1, 2, 2);
4098     } else if (interface && interface->isServiceRegistered("org.gnome.SessionManager")) {
4099         QDBusInterface smserver("org.gnome.SessionManager", "/org/gnome/SessionManager", "org.gnome.SessionManager");
4100         smserver.call("Shutdown");
4101     }
4102 }
4103
4104 void MainWindow::slotUpdateTrackInfo()
4105 {
4106     if (m_activeDocument)
4107         m_transitionConfig->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode(), m_activeDocument->tracksList());
4108 }
4109
4110 void MainWindow::slotChangePalette(QAction *action, const QString &themename)
4111 {
4112     // Load the theme file
4113     QString theme;
4114     if (action == NULL) theme = themename;
4115     else theme = action->data().toString();
4116     KdenliveSettings::setColortheme(theme);
4117     // Make palette for all widgets.
4118     QPalette plt = kapp->palette();
4119     if (theme.isEmpty()) {
4120         plt = QApplication::desktop()->palette();
4121     } else {
4122         KSharedConfigPtr config = KSharedConfig::openConfig(theme);
4123
4124 #if KDE_IS_VERSION(4,6,3)
4125         plt = KGlobalSettings::createNewApplicationPalette(config);
4126 #else
4127         // Since there was a bug in createApplicationPalette in KDE < 4.6.3 we need
4128         // to do the palette loading stuff ourselves. (https://bugs.kde.org/show_bug.cgi?id=263497)     
4129         QPalette::ColorGroup states[3] = { QPalette::Active, QPalette::Inactive,
4130                                             QPalette::Disabled };
4131         // TT thinks tooltips shouldn't use active, so we use our active colors for all states
4132         KColorScheme schemeTooltip(QPalette::Active, KColorScheme::Tooltip, config);
4133  
4134         for ( int i = 0; i < 3 ; i++ ) {
4135             QPalette::ColorGroup state = states[i];
4136             KColorScheme schemeView(state, KColorScheme::View, config);
4137             KColorScheme schemeWindow(state, KColorScheme::Window, config);
4138             KColorScheme schemeButton(state, KColorScheme::Button, config);
4139             KColorScheme schemeSelection(state, KColorScheme::Selection, config);
4140  
4141             plt.setBrush( state, QPalette::WindowText, schemeWindow.foreground() );
4142             plt.setBrush( state, QPalette::Window, schemeWindow.background() );
4143             plt.setBrush( state, QPalette::Base, schemeView.background() );
4144             plt.setBrush( state, QPalette::Text, schemeView.foreground() );
4145             plt.setBrush( state, QPalette::Button, schemeButton.background() );
4146             plt.setBrush( state, QPalette::ButtonText, schemeButton.foreground() );
4147             plt.setBrush( state, QPalette::Highlight, schemeSelection.background() );
4148             plt.setBrush( state, QPalette::HighlightedText, schemeSelection.foreground() );
4149             plt.setBrush( state, QPalette::ToolTipBase, schemeTooltip.background() );
4150             plt.setBrush( state, QPalette::ToolTipText, schemeTooltip.foreground() );
4151  
4152             plt.setColor( state, QPalette::Light, schemeWindow.shade( KColorScheme::LightShade ) );
4153             plt.setColor( state, QPalette::Midlight, schemeWindow.shade( KColorScheme::MidlightShade ) );
4154             plt.setColor( state, QPalette::Mid, schemeWindow.shade( KColorScheme::MidShade ) );
4155             plt.setColor( state, QPalette::Dark, schemeWindow.shade( KColorScheme::DarkShade ) );
4156             plt.setColor( state, QPalette::Shadow, schemeWindow.shade( KColorScheme::ShadowShade ) );
4157  
4158             plt.setBrush( state, QPalette::AlternateBase, schemeView.background( KColorScheme::AlternateBackground) );
4159             plt.setBrush( state, QPalette::Link, schemeView.foreground( KColorScheme::LinkText ) );
4160             plt.setBrush( state, QPalette::LinkVisited, schemeView.foreground( KColorScheme::VisitedText ) );
4161         }
4162 #endif
4163     }
4164
4165     kapp->setPalette(plt);
4166     const QObjectList children = statusBar()->children();
4167
4168     foreach(QObject * child, children) {
4169         if (child->isWidgetType())
4170             ((QWidget*)child)->setPalette(plt);
4171         const QObjectList subchildren = child->children();
4172         foreach(QObject * subchild, subchildren) {
4173             if (subchild->isWidgetType())
4174                 ((QWidget*)subchild)->setPalette(plt);
4175         }
4176     }
4177     if (m_activeTimeline) {
4178         m_activeTimeline->projectView()->updatePalette();
4179     }
4180 }
4181
4182
4183 QPixmap MainWindow::createSchemePreviewIcon(const KSharedConfigPtr &config)
4184 {
4185     // code taken from kdebase/workspace/kcontrol/colors/colorscm.cpp
4186     const uchar bits1[] = { 0xff, 0xff, 0xff, 0x2c, 0x16, 0x0b };
4187     const uchar bits2[] = { 0x68, 0x34, 0x1a, 0xff, 0xff, 0xff };
4188     const QSize bitsSize(24, 2);
4189     const QBitmap b1 = QBitmap::fromData(bitsSize, bits1);
4190     const QBitmap b2 = QBitmap::fromData(bitsSize, bits2);
4191
4192     QPixmap pixmap(23, 16);
4193     pixmap.fill(Qt::black); // ### use some color other than black for borders?
4194
4195     KConfigGroup group(config, "WM");
4196     QPainter p(&pixmap);
4197     KColorScheme windowScheme(QPalette::Active, KColorScheme::Window, config);
4198     p.fillRect(1,  1, 7, 7, windowScheme.background());
4199     p.fillRect(2,  2, 5, 2, QBrush(windowScheme.foreground().color(), b1));
4200
4201     KColorScheme buttonScheme(QPalette::Active, KColorScheme::Button, config);
4202     p.fillRect(8,  1, 7, 7, buttonScheme.background());
4203     p.fillRect(9,  2, 5, 2, QBrush(buttonScheme.foreground().color(), b1));
4204
4205     p.fillRect(15,  1, 7, 7, group.readEntry("activeBackground", QColor(96, 148, 207)));
4206     p.fillRect(16,  2, 5, 2, QBrush(group.readEntry("activeForeground", QColor(255, 255, 255)), b1));
4207
4208     KColorScheme viewScheme(QPalette::Active, KColorScheme::View, config);
4209     p.fillRect(1,  8, 7, 7, viewScheme.background());
4210     p.fillRect(2, 12, 5, 2, QBrush(viewScheme.foreground().color(), b2));
4211
4212     KColorScheme selectionScheme(QPalette::Active, KColorScheme::Selection, config);
4213     p.fillRect(8,  8, 7, 7, selectionScheme.background());
4214     p.fillRect(9, 12, 5, 2, QBrush(selectionScheme.foreground().color(), b2));
4215
4216     p.fillRect(15,  8, 7, 7, group.readEntry("inactiveBackground", QColor(224, 223, 222)));
4217     p.fillRect(16, 12, 5, 2, QBrush(group.readEntry("inactiveForeground", QColor(20, 19, 18)), b2));
4218
4219     p.end();
4220     return pixmap;
4221 }
4222
4223 void MainWindow::slotSwitchMonitors()
4224 {
4225     m_monitorManager->slotSwitchMonitors(!m_clipMonitor->isActive());
4226     if (m_projectMonitor->isActive()) m_activeTimeline->projectView()->setFocus();
4227     else m_projectList->focusTree();
4228 }
4229
4230 void MainWindow::slotSwitchFullscreen()
4231 {
4232     if (m_projectMonitor->isActive()) m_projectMonitor->slotSwitchFullScreen();
4233     else m_clipMonitor->slotSwitchFullScreen();
4234 }
4235
4236 void MainWindow::slotInsertZoneToTree()
4237 {
4238     if (!m_clipMonitor->isActive() || m_clipMonitor->activeClip() == NULL) return;
4239     QStringList info = m_clipMonitor->getZoneInfo();
4240     m_projectList->slotAddClipCut(info.at(0), info.at(1).toInt(), info.at(2).toInt());
4241 }
4242
4243 void MainWindow::slotInsertZoneToTimeline()
4244 {
4245     if (m_activeTimeline == NULL || m_clipMonitor->activeClip() == NULL) return;
4246     QStringList info = m_clipMonitor->getZoneInfo();
4247     m_activeTimeline->projectView()->insertClipCut(m_clipMonitor->activeClip(), info.at(1).toInt(), info.at(2).toInt());
4248 }
4249
4250
4251 void MainWindow::slotDeleteProjectClips(QStringList ids, QMap<QString, QString> folderids)
4252 {
4253     if (m_activeDocument && m_activeTimeline) {
4254         if (!ids.isEmpty()) {
4255             for (int i = 0; i < ids.size(); ++i) {
4256                 m_activeTimeline->slotDeleteClip(ids.at(i));
4257             }
4258             m_activeDocument->clipManager()->slotDeleteClips(ids);
4259         }
4260         if (!folderids.isEmpty()) m_projectList->deleteProjectFolder(folderids);
4261         m_activeDocument->setModified(true);
4262     }
4263 }
4264
4265 void MainWindow::slotShowTitleBars(bool show)
4266 {
4267     QList <QDockWidget *> docks = findChildren<QDockWidget *>();
4268     for (int i = 0; i < docks.count(); i++) {
4269         QDockWidget* dock = docks.at(i);
4270         if (show) {
4271             dock->setTitleBarWidget(0);
4272         } else {
4273             if (!dock->isFloating()) {
4274                 dock->setTitleBarWidget(new QWidget);
4275             }
4276         }
4277     }
4278     KdenliveSettings::setShowtitlebars(show);
4279 }
4280
4281 void MainWindow::slotSwitchTitles()
4282 {
4283     slotShowTitleBars(!KdenliveSettings::showtitlebars());
4284 }
4285
4286 QString MainWindow::getMimeType(bool open)
4287 {
4288     QString mimetype = "application/x-kdenlive";
4289     KMimeType::Ptr mime = KMimeType::mimeType(mimetype);
4290     if (!mime) {
4291         mimetype = "*.kdenlive";
4292         if (open) mimetype.append(" *.tar.gz");
4293     }
4294     else if (open) mimetype.append(" application/x-compressed-tar");
4295     return mimetype;
4296 }
4297
4298 void MainWindow::slotMonitorRequestRenderFrame(bool request)
4299 {
4300     if (request) {
4301         m_projectMonitor->render->sendFrameForAnalysis = true;
4302         return;
4303     } else {
4304         for (int i = 0; i < m_gfxScopesList.count(); i++) {
4305             if (m_gfxScopesList.at(i)->isVisible() && tabifiedDockWidgets(m_gfxScopesList.at(i)).isEmpty() && static_cast<AbstractGfxScopeWidget *>(m_gfxScopesList.at(i)->widget())->autoRefreshEnabled()) {
4306                 request = true;
4307                 break;
4308             }
4309         }
4310     }
4311 #ifdef DEBUG_MAINW
4312     qDebug() << "Any scope accepting new frames? " << request;
4313 #endif
4314     if (!request) {
4315         m_projectMonitor->render->sendFrameForAnalysis = false;
4316     }
4317 }
4318
4319 void MainWindow::slotUpdateGfxScopeFrameRequest()
4320 {
4321     // We need a delay to make sure widgets are hidden after a close event for example
4322     QTimer::singleShot(500, this, SLOT(slotDoUpdateGfxScopeFrameRequest()));
4323 }
4324
4325 void MainWindow::slotDoUpdateGfxScopeFrameRequest()
4326 {
4327     // Check scopes
4328     bool request = false;
4329     for (int i = 0; i < m_gfxScopesList.count(); i++) {
4330         if (!m_gfxScopesList.at(i)->widget()->visibleRegion().isEmpty() && static_cast<AbstractGfxScopeWidget *>(m_gfxScopesList.at(i)->widget())->autoRefreshEnabled()) {
4331             kDebug() << "SCOPE VISIBLE: " << static_cast<AbstractGfxScopeWidget *>(m_gfxScopesList.at(i)->widget())->widgetName();
4332             request = true;
4333             break;
4334         }
4335     }
4336     if (!request) {
4337         if (!m_projectMonitor->effectSceneDisplayed()) {
4338             m_projectMonitor->render->sendFrameForAnalysis = false;
4339         }
4340         m_clipMonitor->render->sendFrameForAnalysis = false;
4341         if (m_recMonitor)
4342             m_recMonitor->analyseFrames(false);
4343     } else {
4344         m_projectMonitor->render->sendFrameForAnalysis = true;
4345         m_clipMonitor->render->sendFrameForAnalysis = true;
4346         if (m_recMonitor)
4347             m_recMonitor->analyseFrames(true);
4348     }
4349 }
4350
4351 void MainWindow::slotUpdateAudioScopeFrameRequest()
4352 {
4353     QTimer::singleShot(500, this, SLOT(slotDoUpdateAudioScopeFrameRequest()));
4354 }
4355
4356 void MainWindow::slotDoUpdateAudioScopeFrameRequest()
4357 {
4358     bool request = false;
4359     for (int i = 0; i < m_audioScopesList.count(); i++) {
4360         if (!m_audioScopesList.at(i)->visibleRegion().isEmpty() && m_audioScopesList.at(i)->autoRefreshEnabled()) {
4361             kDebug() << "AUDIO SCOPE VISIBLE: " << m_audioScopesList.at(i)->widgetName();
4362             request = true;
4363             break;
4364         }
4365     }
4366     // Handle audio signal separately (no common interface)
4367     if (!m_audiosignal->visibleRegion().isEmpty() && m_audiosignal->monitoringEnabled()) {
4368         kDebug() << "AUDIO SCOPE VISIBLE: " << "audiosignal";
4369         request = true;
4370     }
4371 #ifdef DEBUG_MAINW
4372     qDebug() << "Scopes Requesting Audio data: " << request;
4373 #endif
4374     KdenliveSettings::setMonitor_audio(request);
4375     m_monitorManager->slotUpdateAudioMonitoring();
4376 }
4377
4378 void MainWindow::slotUpdateColorScopes()
4379 {
4380     bool request = false;
4381     for (int i = 0; i < m_gfxScopesList.count(); i++) {
4382         // Check if we need the renderer to send a new frame for update
4383         if (!m_gfxScopesList.at(i)->widget()->visibleRegion().isEmpty() && !(static_cast<AbstractGfxScopeWidget *>(m_gfxScopesList.at(i)->widget())->autoRefreshEnabled())) request = true;
4384         static_cast<AbstractGfxScopeWidget *>(m_gfxScopesList.at(i)->widget())->slotActiveMonitorChanged();
4385     }
4386     if (request && m_monitorManager->activeRenderer()) {
4387         m_monitorManager->activeRenderer()->sendFrameUpdate();
4388     }
4389     if (m_audiosignal->isVisible() && m_recMonitor->abstractRender()) {
4390         connect(m_recMonitor->abstractRender(), SIGNAL(audioSamplesSignal(const QVector<int16_t>&, const int&, const int&, const int&)), m_audiosignal, SLOT(slotReceiveAudio(const QVector<int16_t>&, const int&, const int&, const int&)));
4391     }
4392 }
4393
4394 void MainWindow::slotClearColorScopes()
4395 {
4396     for (int i = 0; i < m_gfxScopesList.count(); i++) {
4397         static_cast<AbstractGfxScopeWidget *>(m_gfxScopesList.at(i)->widget())->slotClearMonitor();
4398     }
4399 }
4400
4401 void MainWindow::slotOpenStopmotion()
4402 {
4403     if (m_stopmotion == NULL) {
4404         m_stopmotion = new StopmotionWidget(m_monitorManager, m_activeDocument->projectFolder(), m_stopmotion_actions->actions(), this);
4405         connect(m_stopmotion, SIGNAL(addOrUpdateSequence(const QString &)), m_projectList, SLOT(slotAddOrUpdateSequence(const QString)));
4406         //for (int i = 0; i < m_gfxScopesList.count(); i++) {
4407             // Check if we need the renderer to send a new frame for update
4408             /*if (!m_scopesList.at(i)->widget()->visibleRegion().isEmpty() && !(static_cast<AbstractScopeWidget *>(m_scopesList.at(i)->widget())->autoRefreshEnabled())) request = true;*/
4409             //connect(m_stopmotion, SIGNAL(gotFrame(QImage)), static_cast<AbstractGfxScopeWidget *>(m_gfxScopesList.at(i)->widget()), SLOT(slotRenderZoneUpdated(QImage)));
4410             //static_cast<AbstractScopeWidget *>(m_scopesList.at(i)->widget())->slotMonitorCapture();
4411         //}
4412     }
4413     m_stopmotion->show();
4414 }
4415
4416 void MainWindow::slotDeleteClip(const QString &id)
4417 {
4418     QList <ClipProperties *> list = findChildren<ClipProperties *>();
4419     for (int i = 0; i < list.size(); ++i) {
4420         list.at(i)->disableClipId(id);
4421     }
4422     m_projectList->slotDeleteClip(id);
4423 }
4424
4425 void MainWindow::slotUpdateProxySettings()
4426 {
4427     if (m_renderWidget) m_renderWidget->updateProxyConfig(m_projectList->useProxy());
4428     if (KdenliveSettings::enableproxy())
4429         KStandardDirs::makeDir(m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash) + "proxy/");
4430     m_projectList->updateProxyConfig();
4431 }
4432
4433 void MainWindow::slotInsertNotesTimecode()
4434 {
4435     int frames = m_projectMonitor->render->seekPosition().frames(m_activeDocument->fps());
4436     QString position = m_activeDocument->timecode().getTimecodeFromFrames(frames);
4437     m_notesWidget->insertHtml("<a href=\"" + QString::number(frames) + "\">" + position + "</a> ");
4438 }
4439
4440 void MainWindow::slotArchiveProject()
4441 {
4442     QList <DocClipBase*> list = m_projectList->documentClipList();
4443     QDomDocument doc = m_activeDocument->xmlSceneList(m_projectMonitor->sceneList(), m_projectList->expandedFolders());
4444     ArchiveWidget *d = new ArchiveWidget(m_activeDocument->url().fileName(), doc, list, m_activeTimeline->projectView()->extractTransitionsLumas(), this);
4445     d->exec();
4446 }
4447
4448
4449 void MainWindow::slotOpenBackupDialog(const KUrl url)
4450 {
4451     KUrl projectFile;
4452     KUrl projectFolder;
4453     QString projectId;
4454     kDebug()<<"// BACKUP URL: "<<url.path();
4455     if (!url.isEmpty()) {
4456         // we could not open the project file, guess where the backups are
4457         projectFolder = KUrl(KdenliveSettings::defaultprojectfolder());
4458         projectFile = url;
4459     }
4460     else {
4461         projectFolder = m_activeDocument->projectFolder();
4462         projectFile = m_activeDocument->url();
4463         projectId = m_activeDocument->getDocumentProperty("documentid");
4464     }
4465
4466     BackupWidget *dia = new BackupWidget(projectFile, projectFolder, projectId, this);
4467     if (dia->exec() == QDialog::Accepted) {
4468         QString requestedBackup = dia->selectedFile();
4469         m_activeDocument->backupLastSavedVersion(projectFile.path());
4470         closeCurrentDocument(false);
4471         doOpenFile(KUrl(requestedBackup), NULL);
4472         m_activeDocument->setUrl(projectFile);
4473         m_activeDocument->setModified(true);
4474         setCaption(m_activeDocument->description());
4475     }
4476     delete dia;
4477 }
4478
4479 void MainWindow::slotElapsedTime()
4480 {
4481     kDebug()<<"-----------------------------------------\n"<<"Time elapsed: "<<m_timer.elapsed()<<"\n-------------------------";
4482 }
4483
4484
4485 #include "mainwindow.moc"
4486
4487 #ifdef DEBUG_MAINW
4488 #undef DEBUG_MAINW
4489 #endif