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