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