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