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