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