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