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