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