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