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