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