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