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