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