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