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