]> git.sesse.net Git - kdenlive/blob - src/mainwindow.cpp
06f891e4bde9a58ec04b9e234dd95252c13c5c06
[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* projectAdjust = new KAction(KIcon(), i18n("Adjust Profile to Current Clip"), this);
1096     collection->addAction("project_adjust_profile", projectAdjust);
1097     connect(projectAdjust, SIGNAL(triggered(bool)), m_projectList, SLOT(adjustProjectProfileToItem()));
1098
1099     KAction* monitorPlay = new KAction(KIcon("media-playback-start"), i18n("Play"), this);
1100     KShortcut playShortcut;
1101     playShortcut.setPrimary(Qt::Key_Space);
1102     playShortcut.setAlternate(Qt::Key_K);
1103     monitorPlay->setShortcut(playShortcut);
1104     collection->addAction("monitor_play", monitorPlay);
1105     connect(monitorPlay, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotPlay()));
1106
1107     m_playZone = new KAction(KIcon("media-playback-start"), i18n("Play Zone"), this);
1108     m_playZone->setShortcut(Qt::CTRL + Qt::Key_Space);
1109     collection->addAction("monitor_play_zone", m_playZone);
1110     connect(m_playZone, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotPlayZone()));
1111
1112     m_loopZone = new KAction(KIcon("media-playback-start"), i18n("Loop Zone"), this);
1113     m_loopZone->setShortcut(Qt::ALT + Qt::Key_Space);
1114     collection->addAction("monitor_loop_zone", m_loopZone);
1115     connect(m_loopZone, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotLoopZone()));
1116
1117     KAction *dvdWizard =  new KAction(KIcon("media-optical"), i18n("DVD Wizard"), this);
1118     collection->addAction("dvd_wizard", dvdWizard);
1119     connect(dvdWizard, SIGNAL(triggered(bool)), this, SLOT(slotDvdWizard()));
1120
1121     KAction *transcodeClip =  new KAction(KIcon("edit-copy"), i18n("Transcode Clips"), this);
1122     collection->addAction("transcode_clip", transcodeClip);
1123     connect(transcodeClip, SIGNAL(triggered(bool)), this, SLOT(slotTranscodeClip()));
1124
1125     KAction *markIn = collection->addAction("mark_in");
1126     markIn->setText(i18n("Set Zone In"));
1127     markIn->setShortcut(Qt::Key_I);
1128     connect(markIn, SIGNAL(triggered(bool)), this, SLOT(slotSetInPoint()));
1129
1130     KAction *markOut = collection->addAction("mark_out");
1131     markOut->setText(i18n("Set Zone Out"));
1132     markOut->setShortcut(Qt::Key_O);
1133     connect(markOut, SIGNAL(triggered(bool)), this, SLOT(slotSetOutPoint()));
1134
1135     KAction *switchMon = collection->addAction("switch_monitor");
1136     switchMon->setText(i18n("Switch monitor"));
1137     switchMon->setShortcut(Qt::Key_T);
1138     connect(switchMon, SIGNAL(triggered(bool)), this, SLOT(slotSwitchMonitors()));
1139
1140     KAction *insertTree = collection->addAction("insert_project_tree");
1141     insertTree->setText(i18n("Insert zone in project tree"));
1142     insertTree->setShortcut(Qt::CTRL + Qt::Key_I);
1143     connect(insertTree, SIGNAL(triggered(bool)), this, SLOT(slotInsertZoneToTree()));
1144
1145     KAction *insertTimeline = collection->addAction("insert_timeline");
1146     insertTimeline->setText(i18n("Insert zone in timeline"));
1147     insertTimeline->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_I);
1148     connect(insertTimeline, SIGNAL(triggered(bool)), this, SLOT(slotInsertZoneToTimeline()));
1149
1150     KAction *resizeStart =  new KAction(KIcon(), i18n("Resize Item Start"), this);
1151     collection->addAction("resize_timeline_clip_start", resizeStart);
1152     resizeStart->setShortcut(Qt::Key_1);
1153     connect(resizeStart, SIGNAL(triggered(bool)), this, SLOT(slotResizeItemStart()));
1154
1155     KAction *resizeEnd =  new KAction(KIcon(), i18n("Resize Item End"), this);
1156     collection->addAction("resize_timeline_clip_end", resizeEnd);
1157     resizeEnd->setShortcut(Qt::Key_2);
1158     connect(resizeEnd, SIGNAL(triggered(bool)), this, SLOT(slotResizeItemEnd()));
1159
1160     KAction* monitorSeekBackward = new KAction(KIcon("media-seek-backward"), i18n("Rewind"), this);
1161     monitorSeekBackward->setShortcut(Qt::Key_J);
1162     collection->addAction("monitor_seek_backward", monitorSeekBackward);
1163     connect(monitorSeekBackward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewind()));
1164
1165     KAction* monitorSeekBackwardOneFrame = new KAction(KIcon("media-skip-backward"), i18n("Rewind 1 Frame"), this);
1166     monitorSeekBackwardOneFrame->setShortcut(Qt::Key_Left);
1167     collection->addAction("monitor_seek_backward-one-frame", monitorSeekBackwardOneFrame);
1168     connect(monitorSeekBackwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewindOneFrame()));
1169
1170     KAction* monitorSeekBackwardOneSecond = new KAction(KIcon("media-skip-backward"), i18n("Rewind 1 Second"), this);
1171     monitorSeekBackwardOneSecond->setShortcut(Qt::SHIFT + Qt::Key_Left);
1172     collection->addAction("monitor_seek_backward-one-second", monitorSeekBackwardOneSecond);
1173     connect(monitorSeekBackwardOneSecond, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewindOneSecond()));
1174
1175     KAction* monitorSeekSnapBackward = new KAction(KIcon("media-seek-backward"), i18n("Go to Previous Snap Point"), this);
1176     monitorSeekSnapBackward->setShortcut(Qt::ALT + Qt::Key_Left);
1177     collection->addAction("monitor_seek_snap_backward", monitorSeekSnapBackward);
1178     connect(monitorSeekSnapBackward, SIGNAL(triggered(bool)), this, SLOT(slotSnapRewind()));
1179
1180     KAction* monitorSeekForward = new KAction(KIcon("media-seek-forward"), i18n("Forward"), this);
1181     monitorSeekForward->setShortcut(Qt::Key_L);
1182     collection->addAction("monitor_seek_forward", monitorSeekForward);
1183     connect(monitorSeekForward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForward()));
1184
1185     KAction* clipStart = new KAction(KIcon("media-seek-backward"), i18n("Go to Clip Start"), this);
1186     clipStart->setShortcut(Qt::Key_Home);
1187     collection->addAction("seek_clip_start", clipStart);
1188     connect(clipStart, SIGNAL(triggered(bool)), this, SLOT(slotClipStart()));
1189
1190     KAction* clipEnd = new KAction(KIcon("media-seek-forward"), i18n("Go to Clip End"), this);
1191     clipEnd->setShortcut(Qt::Key_End);
1192     collection->addAction("seek_clip_end", clipEnd);
1193     connect(clipEnd, SIGNAL(triggered(bool)), this, SLOT(slotClipEnd()));
1194
1195     KAction* zoneStart = new KAction(KIcon("media-seek-backward"), i18n("Go to Zone Start"), this);
1196     zoneStart->setShortcut(Qt::SHIFT + Qt::Key_I);
1197     collection->addAction("seek_zone_start", zoneStart);
1198     connect(zoneStart, SIGNAL(triggered(bool)), this, SLOT(slotZoneStart()));
1199
1200     KAction* zoneEnd = new KAction(KIcon("media-seek-forward"), i18n("Go to Zone End"), this);
1201     zoneEnd->setShortcut(Qt::SHIFT + Qt::Key_O);
1202     collection->addAction("seek_zone_end", zoneEnd);
1203     connect(zoneEnd, SIGNAL(triggered(bool)), this, SLOT(slotZoneEnd()));
1204
1205     KAction* projectStart = new KAction(KIcon("go-first"), i18n("Go to Project Start"), this);
1206     projectStart->setShortcut(Qt::CTRL + Qt::Key_Home);
1207     collection->addAction("seek_start", projectStart);
1208     connect(projectStart, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotStart()));
1209
1210     KAction* projectEnd = new KAction(KIcon("go-last"), i18n("Go to Project End"), this);
1211     projectEnd->setShortcut(Qt::CTRL + Qt::Key_End);
1212     collection->addAction("seek_end", projectEnd);
1213     connect(projectEnd, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotEnd()));
1214
1215     KAction* monitorSeekForwardOneFrame = new KAction(KIcon("media-skip-forward"), i18n("Forward 1 Frame"), this);
1216     monitorSeekForwardOneFrame->setShortcut(Qt::Key_Right);
1217     collection->addAction("monitor_seek_forward-one-frame", monitorSeekForwardOneFrame);
1218     connect(monitorSeekForwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForwardOneFrame()));
1219
1220     KAction* monitorSeekForwardOneSecond = new KAction(KIcon("media-skip-forward"), i18n("Forward 1 Second"), this);
1221     monitorSeekForwardOneSecond->setShortcut(Qt::SHIFT + Qt::Key_Right);
1222     collection->addAction("monitor_seek_forward-one-second", monitorSeekForwardOneSecond);
1223     connect(monitorSeekForwardOneSecond, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForwardOneSecond()));
1224
1225     KAction* monitorSeekSnapForward = new KAction(KIcon("media-seek-forward"), i18n("Go to Next Snap Point"), this);
1226     monitorSeekSnapForward->setShortcut(Qt::ALT + Qt::Key_Right);
1227     collection->addAction("monitor_seek_snap_forward", monitorSeekSnapForward);
1228     connect(monitorSeekSnapForward, SIGNAL(triggered(bool)), this, SLOT(slotSnapForward()));
1229
1230     KAction* deleteItem = new KAction(KIcon("edit-delete"), i18n("Delete Selected Item"), this);
1231     deleteItem->setShortcut(Qt::Key_Delete);
1232     collection->addAction("delete_timeline_clip", deleteItem);
1233     connect(deleteItem, SIGNAL(triggered(bool)), this, SLOT(slotDeleteItem()));
1234
1235     /*KAction* editTimelineClipSpeed = new KAction(i18n("Change Clip Speed"), this);
1236     collection->addAction("change_clip_speed", editTimelineClipSpeed);
1237     editTimelineClipSpeed->setData("change_speed");
1238     connect(editTimelineClipSpeed, SIGNAL(triggered(bool)), this, SLOT(slotChangeClipSpeed()));*/
1239
1240     KAction *stickTransition = collection->addAction("auto_transition");
1241     stickTransition->setData(QString("auto"));
1242     stickTransition->setCheckable(true);
1243     stickTransition->setEnabled(false);
1244     stickTransition->setText(i18n("Automatic Transition"));
1245     connect(stickTransition, SIGNAL(triggered(bool)), this, SLOT(slotAutoTransition()));
1246
1247     KAction* groupClip = new KAction(KIcon("object-group"), i18n("Group Clips"), this);
1248     groupClip->setShortcut(Qt::CTRL + Qt::Key_G);
1249     collection->addAction("group_clip", groupClip);
1250     connect(groupClip, SIGNAL(triggered(bool)), this, SLOT(slotGroupClips()));
1251
1252     KAction* ungroupClip = new KAction(KIcon("object-ungroup"), i18n("Ungroup Clips"), this);
1253     collection->addAction("ungroup_clip", ungroupClip);
1254     ungroupClip->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_G);
1255     ungroupClip->setData("ungroup_clip");
1256     connect(ungroupClip, SIGNAL(triggered(bool)), this, SLOT(slotUnGroupClips()));
1257
1258     KAction* editItemDuration = new KAction(KIcon("measure"), i18n("Edit Duration"), this);
1259     collection->addAction("edit_item_duration", editItemDuration);
1260     connect(editItemDuration, SIGNAL(triggered(bool)), this, SLOT(slotEditItemDuration()));
1261
1262     KAction* clipInProjectTree = new KAction(KIcon("go-jump-definition"), i18n("Clip in Project Tree"), this);
1263     collection->addAction("clip_in_project_tree", clipInProjectTree);
1264     connect(clipInProjectTree, SIGNAL(triggered(bool)), this, SLOT(slotClipInProjectTree()));
1265
1266     /*KAction* clipToProjectTree = new KAction(KIcon("go-jump-definition"), i18n("Add Clip to Project Tree"), this);
1267     collection->addAction("clip_to_project_tree", clipToProjectTree);
1268     connect(clipToProjectTree, SIGNAL(triggered(bool)), this, SLOT(slotClipToProjectTree()));*/
1269
1270     KAction* insertOvertwrite = new KAction(KIcon(), i18n("Insert Clip Zone in Timeline (Overwrite)"), this);
1271     insertOvertwrite->setShortcut(Qt::Key_V);
1272     collection->addAction("overwrite_to_in_point", insertOvertwrite);
1273     connect(insertOvertwrite, SIGNAL(triggered(bool)), this, SLOT(slotInsertClipOverwrite()));
1274
1275     KAction* selectTimelineClip = new KAction(KIcon("edit-select"), i18n("Select Clip"), this);
1276     selectTimelineClip->setShortcut(Qt::Key_Plus);
1277     collection->addAction("select_timeline_clip", selectTimelineClip);
1278     connect(selectTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotSelectTimelineClip()));
1279
1280     KAction* deselectTimelineClip = new KAction(KIcon("edit-select"), i18n("Deselect Clip"), this);
1281     deselectTimelineClip->setShortcut(Qt::Key_Minus);
1282     collection->addAction("deselect_timeline_clip", deselectTimelineClip);
1283     connect(deselectTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotDeselectTimelineClip()));
1284
1285     KAction* selectAddTimelineClip = new KAction(KIcon("edit-select"), i18n("Add Clip To Selection"), this);
1286     selectAddTimelineClip->setShortcut(Qt::ALT + Qt::Key_Plus);
1287     collection->addAction("select_add_timeline_clip", selectAddTimelineClip);
1288     connect(selectAddTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotSelectAddTimelineClip()));
1289
1290     KAction* selectTimelineTransition = new KAction(KIcon("edit-select"), i18n("Select Transition"), this);
1291     selectTimelineTransition->setShortcut(Qt::SHIFT + Qt::Key_Plus);
1292     collection->addAction("select_timeline_transition", selectTimelineTransition);
1293     connect(selectTimelineTransition, SIGNAL(triggered(bool)), this, SLOT(slotSelectTimelineTransition()));
1294
1295     KAction* deselectTimelineTransition = new KAction(KIcon("edit-select"), i18n("Deselect Transition"), this);
1296     deselectTimelineTransition->setShortcut(Qt::SHIFT + Qt::Key_Minus);
1297     collection->addAction("deselect_timeline_transition", deselectTimelineTransition);
1298     connect(deselectTimelineTransition, SIGNAL(triggered(bool)), this, SLOT(slotDeselectTimelineTransition()));
1299
1300     KAction* selectAddTimelineTransition = new KAction(KIcon("edit-select"), i18n("Add Transition To Selection"), this);
1301     selectAddTimelineTransition->setShortcut(Qt::ALT + Qt::SHIFT + Qt::Key_Plus);
1302     collection->addAction("select_add_timeline_transition", selectAddTimelineTransition);
1303     connect(selectAddTimelineTransition, SIGNAL(triggered(bool)), this, SLOT(slotSelectAddTimelineTransition()));
1304
1305     KAction* cutTimelineClip = new KAction(KIcon("edit-cut"), i18n("Cut Clip"), this);
1306     cutTimelineClip->setShortcut(Qt::SHIFT + Qt::Key_R);
1307     collection->addAction("cut_timeline_clip", cutTimelineClip);
1308     connect(cutTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotCutTimelineClip()));
1309
1310     KAction* addClipMarker = new KAction(KIcon("bookmark-new"), i18n("Add Marker"), this);
1311     collection->addAction("add_clip_marker", addClipMarker);
1312     connect(addClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotAddClipMarker()));
1313
1314     KAction* deleteClipMarker = new KAction(KIcon("edit-delete"), i18n("Delete Marker"), this);
1315     collection->addAction("delete_clip_marker", deleteClipMarker);
1316     connect(deleteClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotDeleteClipMarker()));
1317
1318     KAction* deleteAllClipMarkers = new KAction(KIcon("edit-delete"), i18n("Delete All Markers"), this);
1319     collection->addAction("delete_all_clip_markers", deleteAllClipMarkers);
1320     connect(deleteAllClipMarkers, SIGNAL(triggered(bool)), this, SLOT(slotDeleteAllClipMarkers()));
1321
1322     KAction* editClipMarker = new KAction(KIcon("document-properties"), i18n("Edit Marker"), this);
1323     collection->addAction("edit_clip_marker", editClipMarker);
1324     connect(editClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotEditClipMarker()));
1325
1326     KAction* splitAudio = new KAction(KIcon("document-new"), i18n("Split Audio"), this);
1327     collection->addAction("split_audio", splitAudio);
1328     connect(splitAudio, SIGNAL(triggered(bool)), this, SLOT(slotSplitAudio()));
1329
1330     KAction* audioOnly = new KAction(KIcon("document-new"), i18n("Audio Only"), this);
1331     collection->addAction("clip_audio_only", audioOnly);
1332     audioOnly->setData("clip_audio_only");
1333     audioOnly->setCheckable(true);
1334
1335     KAction* videoOnly = new KAction(KIcon("document-new"), i18n("Video Only"), this);
1336     collection->addAction("clip_video_only", videoOnly);
1337     videoOnly->setData("clip_video_only");
1338     videoOnly->setCheckable(true);
1339
1340     KAction* audioAndVideo = new KAction(KIcon("document-new"), i18n("Audio and Video"), this);
1341     collection->addAction("clip_audio_and_video", audioAndVideo);
1342     audioAndVideo->setData("clip_audio_and_video");
1343     audioAndVideo->setCheckable(true);
1344
1345     m_clipTypeGroup = new QActionGroup(this);
1346     m_clipTypeGroup->addAction(audioOnly);
1347     m_clipTypeGroup->addAction(videoOnly);
1348     m_clipTypeGroup->addAction(audioAndVideo);
1349     connect(m_clipTypeGroup, SIGNAL(triggered(QAction *)), this, SLOT(slotUpdateClipType(QAction *)));
1350     m_clipTypeGroup->setEnabled(false);
1351
1352     KAction *insertSpace = new KAction(KIcon(), i18n("Insert Space"), this);
1353     collection->addAction("insert_space", insertSpace);
1354     connect(insertSpace, SIGNAL(triggered()), this, SLOT(slotInsertSpace()));
1355
1356     KAction *removeSpace = new KAction(KIcon(), i18n("Remove Space"), this);
1357     collection->addAction("delete_space", removeSpace);
1358     connect(removeSpace, SIGNAL(triggered()), this, SLOT(slotRemoveSpace()));
1359
1360     KAction *insertTrack = new KAction(KIcon(), i18n("Insert Track"), this);
1361     collection->addAction("insert_track", insertTrack);
1362     connect(insertTrack, SIGNAL(triggered()), this, SLOT(slotInsertTrack()));
1363
1364     KAction *deleteTrack = new KAction(KIcon(), i18n("Delete Track"), this);
1365     collection->addAction("delete_track", deleteTrack);
1366     connect(deleteTrack, SIGNAL(triggered()), this, SLOT(slotDeleteTrack()));
1367
1368     KAction *configTracks = new KAction(KIcon("configure"), i18n("Configure Tracks"), this);
1369     collection->addAction("config_tracks", configTracks);
1370     connect(configTracks, SIGNAL(triggered()), this, SLOT(slotConfigTrack()));
1371
1372     KAction *addGuide = new KAction(KIcon("document-new"), i18n("Add Guide"), this);
1373     collection->addAction("add_guide", addGuide);
1374     connect(addGuide, SIGNAL(triggered()), this, SLOT(slotAddGuide()));
1375
1376     QAction *delGuide = new KAction(KIcon("edit-delete"), i18n("Delete Guide"), this);
1377     collection->addAction("delete_guide", delGuide);
1378     connect(delGuide, SIGNAL(triggered()), this, SLOT(slotDeleteGuide()));
1379
1380     QAction *editGuide = new KAction(KIcon("document-properties"), i18n("Edit Guide"), this);
1381     collection->addAction("edit_guide", editGuide);
1382     connect(editGuide, SIGNAL(triggered()), this, SLOT(slotEditGuide()));
1383
1384     QAction *delAllGuides = new KAction(KIcon("edit-delete"), i18n("Delete All Guides"), this);
1385     collection->addAction("delete_all_guides", delAllGuides);
1386     connect(delAllGuides, SIGNAL(triggered()), this, SLOT(slotDeleteAllGuides()));
1387
1388     QAction *pasteEffects = new KAction(KIcon("edit-paste"), i18n("Paste Effects"), this);
1389     collection->addAction("paste_effects", pasteEffects);
1390     pasteEffects->setData("paste_effects");
1391     connect(pasteEffects , SIGNAL(triggered()), this, SLOT(slotPasteEffects()));
1392
1393     QAction *showTimeline = new KAction(i18n("Show Timeline"), this);
1394     collection->addAction("show_timeline", showTimeline);
1395     showTimeline->setCheckable(true);
1396     showTimeline->setChecked(true);
1397     connect(showTimeline, SIGNAL(triggered(bool)), this, SLOT(slotShowTimeline(bool)));
1398
1399     QAction *showTitleBar = new KAction(i18n("Show Title Bars"), this);
1400     collection->addAction("show_titlebars", showTitleBar);
1401     showTitleBar->setCheckable(true);
1402     connect(showTitleBar, SIGNAL(triggered(bool)), this, SLOT(slotShowTitleBars(bool)));
1403     showTitleBar->setChecked(KdenliveSettings::showtitlebars());
1404     slotShowTitleBars(KdenliveSettings::showtitlebars());
1405
1406
1407     //const QByteArray state = layoutGroup.readEntry("layout1", QByteArray());
1408
1409     /*QAction *maxCurrent = new KAction(i18n("Maximize Current Widget"), this);
1410     collection->addAction("maximize_current", maxCurrent);
1411     maxCurrent->setCheckable(true);
1412     maxCurrent->setChecked(false);
1413     connect(maxCurrent, SIGNAL(triggered(bool)), this, SLOT(slotMaximizeCurrent(bool)));*/
1414
1415     m_closeAction = KStandardAction::close(this,  SLOT(closeCurrentDocument()),   collection);
1416     KStandardAction::quit(this,                   SLOT(queryQuit()),              collection);
1417     KStandardAction::open(this,                   SLOT(openFile()),               collection);
1418     m_saveAction = KStandardAction::save(this,    SLOT(saveFile()),               collection);
1419     KStandardAction::saveAs(this,                 SLOT(saveFileAs()),             collection);
1420     KStandardAction::openNew(this,                SLOT(newFile()),                collection);
1421     // TODO: make the following connection to slotEditKeys work
1422     KStandardAction::keyBindings(this,            SLOT(slotEditKeys()),           collection);
1423     KStandardAction::preferences(this,            SLOT(slotPreferences()),        collection);
1424     KStandardAction::configureNotifications(this, SLOT(configureNotifications()), collection);
1425     KStandardAction::copy(this,                   SLOT(slotCopy()),               collection);
1426     KStandardAction::paste(this,                  SLOT(slotPaste()),              collection);
1427     KStandardAction::fullScreen(this,             SLOT(slotFullScreen()), this,   collection);
1428
1429     KAction *undo = KStandardAction::undo(m_commandStack, SLOT(undo()), collection);
1430     undo->setEnabled(false);
1431     connect(m_commandStack, SIGNAL(canUndoChanged(bool)), undo, SLOT(setEnabled(bool)));
1432
1433     KAction *redo = KStandardAction::redo(m_commandStack, SLOT(redo()), collection);
1434     redo->setEnabled(false);
1435     connect(m_commandStack, SIGNAL(canRedoChanged(bool)), redo, SLOT(setEnabled(bool)));
1436
1437     /*
1438     //TODO: Add status tooltip to actions ?
1439     connect(collection, SIGNAL(actionHovered(QAction*)),
1440             this, SLOT(slotDisplayActionMessage(QAction*)));*/
1441
1442
1443     QAction *addClip = new KAction(KIcon("kdenlive-add-clip"), i18n("Add Clip"), this);
1444     collection->addAction("add_clip", addClip);
1445     connect(addClip , SIGNAL(triggered()), m_projectList, SLOT(slotAddClip()));
1446
1447     QAction *addColorClip = new KAction(KIcon("kdenlive-add-color-clip"), i18n("Add Color Clip"), this);
1448     collection->addAction("add_color_clip", addColorClip);
1449     connect(addColorClip , SIGNAL(triggered()), m_projectList, SLOT(slotAddColorClip()));
1450
1451     QAction *addSlideClip = new KAction(KIcon("kdenlive-add-slide-clip"), i18n("Add Slideshow Clip"), this);
1452     collection->addAction("add_slide_clip", addSlideClip);
1453     connect(addSlideClip , SIGNAL(triggered()), m_projectList, SLOT(slotAddSlideshowClip()));
1454
1455     QAction *addTitleClip = new KAction(KIcon("kdenlive-add-text-clip"), i18n("Add Title Clip"), this);
1456     collection->addAction("add_text_clip", addTitleClip);
1457     connect(addTitleClip , SIGNAL(triggered()), m_projectList, SLOT(slotAddTitleClip()));
1458
1459     QAction *addTitleTemplateClip = new KAction(KIcon("kdenlive-add-text-clip"), i18n("Add Template Title"), this);
1460     collection->addAction("add_text_template_clip", addTitleTemplateClip);
1461     connect(addTitleTemplateClip , SIGNAL(triggered()), m_projectList, SLOT(slotAddTitleTemplateClip()));
1462
1463     QAction *addFolderButton = new KAction(KIcon("folder-new"), i18n("Create Folder"), this);
1464     collection->addAction("add_folder", addFolderButton);
1465     connect(addFolderButton , SIGNAL(triggered()), m_projectList, SLOT(slotAddFolder()));
1466
1467     QAction *clipProperties = new KAction(KIcon("document-edit"), i18n("Clip Properties"), this);
1468     collection->addAction("clip_properties", clipProperties);
1469     clipProperties->setData("clip_properties");
1470     connect(clipProperties , SIGNAL(triggered()), m_projectList, SLOT(slotEditClip()));
1471     clipProperties->setEnabled(false);
1472
1473     QAction *openClip = new KAction(KIcon("document-open"), i18n("Edit Clip"), this);
1474     collection->addAction("edit_clip", openClip);
1475     openClip->setData("edit_clip");
1476     connect(openClip , SIGNAL(triggered()), m_projectList, SLOT(slotOpenClip()));
1477     openClip->setEnabled(false);
1478
1479     QAction *deleteClip = new KAction(KIcon("edit-delete"), i18n("Delete Clip"), this);
1480     collection->addAction("delete_clip", deleteClip);
1481     deleteClip->setData("delete_clip");
1482     connect(deleteClip , SIGNAL(triggered()), m_projectList, SLOT(slotRemoveClip()));
1483     deleteClip->setEnabled(false);
1484
1485     QAction *reloadClip = new KAction(KIcon("view-refresh"), i18n("Reload Clip"), this);
1486     collection->addAction("reload_clip", reloadClip);
1487     reloadClip->setData("reload_clip");
1488     connect(reloadClip , SIGNAL(triggered()), m_projectList, SLOT(slotReloadClip()));
1489     reloadClip->setEnabled(false);
1490
1491     QMenu *addClips = new QMenu();
1492     addClips->addAction(addClip);
1493     addClips->addAction(addColorClip);
1494     addClips->addAction(addSlideClip);
1495     addClips->addAction(addTitleClip);
1496     addClips->addAction(addTitleTemplateClip);
1497     addClips->addAction(addFolderButton);
1498
1499     addClips->addAction(reloadClip);
1500     addClips->addAction(clipProperties);
1501     addClips->addAction(openClip);
1502     addClips->addAction(deleteClip);
1503     m_projectList->setupMenu(addClips, addClip);
1504
1505     // Setup effects and transitions actions.
1506     m_effectsActionCollection = new KActionCollection(this, KGlobal::mainComponent());
1507     //KActionCategory *videoEffectActions = new KActionCategory(i18n("Video Effects"), m_effectsActionCollection);
1508     KActionCategory *videoEffectActions = new KActionCategory(i18n("Video Effects"), collection);
1509     m_videoEffects = new KAction*[videoEffects.count()];
1510     for (int i = 0; i < videoEffects.count(); ++i) {
1511         QStringList effectInfo = videoEffects.effectIdInfo(i);
1512         m_videoEffects[i] = new KAction(KIcon("kdenlive-show-video"), effectInfo.at(0), this);
1513         m_videoEffects[i]->setData(effectInfo);
1514         m_videoEffects[i]->setIconVisibleInMenu(false);
1515         videoEffectActions->addAction("video_effect_" + effectInfo.at(0), m_videoEffects[i]);
1516     }
1517     //KActionCategory *audioEffectActions = new KActionCategory(i18n("Audio Effects"), m_effectsActionCollection);
1518     KActionCategory *audioEffectActions = new KActionCategory(i18n("Audio Effects"), collection);
1519     m_audioEffects = new KAction*[audioEffects.count()];
1520     for (int i = 0; i < audioEffects.count(); ++i) {
1521         QStringList effectInfo = audioEffects.effectIdInfo(i);
1522         m_audioEffects[i] = new KAction(KIcon("kdenlive-show-audio"), effectInfo.at(0), this);
1523         m_audioEffects[i]->setData(effectInfo);
1524         m_audioEffects[i]->setIconVisibleInMenu(false);
1525         audioEffectActions->addAction("audio_effect_" + effectInfo.at(0), m_audioEffects[i]);
1526     }
1527     //KActionCategory *customEffectActions = new KActionCategory(i18n("Custom Effects"), m_effectsActionCollection);
1528     KActionCategory *customEffectActions = new KActionCategory(i18n("Custom Effects"), collection);
1529     m_customEffects = new KAction*[customEffects.count()];
1530     for (int i = 0; i < customEffects.count(); ++i) {
1531         QStringList effectInfo = customEffects.effectIdInfo(i);
1532         m_customEffects[i] = new KAction(KIcon("kdenlive-custom-effect"), effectInfo.at(0), this);
1533         m_customEffects[i]->setData(effectInfo);
1534         m_customEffects[i]->setIconVisibleInMenu(false);
1535         customEffectActions->addAction("custom_effect_" + effectInfo.at(0), m_customEffects[i]);
1536     }
1537     //KActionCategory *transitionActions = new KActionCategory(i18n("Transitions"), m_effectsActionCollection);
1538     KActionCategory *transitionActions = new KActionCategory(i18n("Transitions"), collection);
1539     m_transitions = new KAction*[transitions.count()];
1540     for (int i = 0; i < transitions.count(); i++) {
1541         QStringList effectInfo = transitions.effectIdInfo(i);
1542         m_transitions[i] = new KAction(effectInfo.at(0), this);
1543         m_transitions[i]->setData(effectInfo);
1544         m_transitions[i]->setIconVisibleInMenu(false);
1545         transitionActions->addAction("transition_" + effectInfo.at(0), m_transitions[i]);
1546     }
1547     m_effectsActionCollection->readSettings();
1548
1549     //connect(collection, SIGNAL( clearStatusText() ),
1550     //statusBar(), SLOT( clear() ) );
1551 }
1552
1553 void MainWindow::slotDisplayActionMessage(QAction *a)
1554 {
1555     statusBar()->showMessage(a->data().toString(), 3000);
1556 }
1557
1558 void MainWindow::loadLayouts()
1559 {
1560     QMenu *saveLayout = (QMenu*)(factory()->container("layout_save_as", this));
1561     QMenu *loadLayout = (QMenu*)(factory()->container("layout_load", this));
1562     if (loadLayout == NULL || saveLayout == NULL) return;
1563     KSharedConfigPtr config = KGlobal::config();
1564     KConfigGroup layoutGroup(config, "Layouts");
1565     QStringList entries = layoutGroup.keyList();
1566     QList<QAction *> loadActions = loadLayout->actions();
1567     QList<QAction *> saveActions = saveLayout->actions();
1568     for (int i = 1; i < 5; i++) {
1569         // Rename the layouts actions
1570         foreach(const QString & key, entries) {
1571             if (key.endsWith(QString("_%1").arg(i))) {
1572                 // Found previously saved layout
1573                 QString layoutName = key.section("_", 0, -2);
1574                 for (int j = 0; j < loadActions.count(); j++) {
1575                     if (loadActions.at(j)->data().toString().endsWith("_" + QString::number(i))) {
1576                         loadActions[j]->setText(layoutName);
1577                         loadActions[j]->setData(key);
1578                         break;
1579                     }
1580                 }
1581                 for (int j = 0; j < saveActions.count(); j++) {
1582                     if (saveActions.at(j)->data().toString().endsWith("_" + QString::number(i))) {
1583                         saveActions[j]->setText(layoutName);
1584                         saveActions[j]->setData(key);
1585                         break;
1586                     }
1587                 }
1588             }
1589         }
1590     }
1591 }
1592
1593 void MainWindow::slotLoadLayout(QAction *action)
1594 {
1595     if (!action) return;
1596     QString layoutId = action->data().toString();
1597     if (layoutId.isEmpty()) return;
1598     KSharedConfigPtr config = KGlobal::config();
1599     KConfigGroup layouts(config, "Layouts");
1600     //QByteArray geom = QByteArray::fromBase64(layouts.readEntry(layoutId).toAscii());
1601     QByteArray state = QByteArray::fromBase64(layouts.readEntry(layoutId).toAscii());
1602     //restoreGeometry(geom);
1603     restoreState(state);
1604 }
1605
1606 void MainWindow::slotSaveLayout(QAction *action)
1607 {
1608     QString originallayoutName = action->data().toString();
1609     int layoutId = originallayoutName.section('_', -1).toInt();
1610
1611     QString layoutName = QInputDialog::getText(this, i18n("Save Layout"), i18n("Layout name:"), QLineEdit::Normal, originallayoutName.section('_', 0, -2));
1612     if (layoutName.isEmpty()) return;
1613     KSharedConfigPtr config = KGlobal::config();
1614     KConfigGroup layouts(config, "Layouts");
1615     layouts.deleteEntry(originallayoutName);
1616
1617     QByteArray st = saveState();
1618     layoutName.append("_" + QString::number(layoutId));
1619     layouts.writeEntry(layoutName, st.toBase64());
1620     loadLayouts();
1621 }
1622
1623 void MainWindow::saveOptions()
1624 {
1625     KdenliveSettings::self()->writeConfig();
1626     KSharedConfigPtr config = KGlobal::config();
1627     m_fileOpenRecent->saveEntries(KConfigGroup(config, "Recent Files"));
1628     KConfigGroup treecolumns(config, "Project Tree");
1629     treecolumns.writeEntry("columns", m_projectList->headerInfo());
1630     config->sync();
1631 }
1632
1633 void MainWindow::readOptions()
1634 {
1635     KSharedConfigPtr config = KGlobal::config();
1636     m_fileOpenRecent->loadEntries(KConfigGroup(config, "Recent Files"));
1637     KConfigGroup initialGroup(config, "version");
1638     bool upgrade = false;
1639     if (initialGroup.exists()) {
1640         if (initialGroup.readEntry("version", QString()).section(' ', 0, 0) != QString(version).section(' ', 0, 0)) {
1641             upgrade = true;
1642         }
1643
1644         if (initialGroup.readEntry("version") == "0.7") {
1645             //Add new settings from 0.7.1
1646             if (KdenliveSettings::defaultprojectfolder().isEmpty()) {
1647                 QString path = QDir::homePath() + "/kdenlive";
1648                 if (KStandardDirs::makeDir(path)  == false) {
1649                     kDebug() << "/// ERROR CREATING PROJECT FOLDER: " << path;
1650                 } else KdenliveSettings::setDefaultprojectfolder(path);
1651             }
1652         }
1653
1654     }
1655
1656     if (!initialGroup.exists() || upgrade) {
1657         // this is our first run, show Wizard
1658         Wizard *w = new Wizard(upgrade, this);
1659         if (w->exec() == QDialog::Accepted && w->isOk()) {
1660             w->adjustSettings();
1661             initialGroup.writeEntry("version", version);
1662             delete w;
1663         } else {
1664             ::exit(1);
1665         }
1666     }
1667     KConfigGroup treecolumns(config, "Project Tree");
1668     const QByteArray state = treecolumns.readEntry("columns", QByteArray());
1669     if (!state.isEmpty())
1670         m_projectList->setHeaderInfo(state);
1671 }
1672
1673 void MainWindow::slotRunWizard()
1674 {
1675     Wizard *w = new Wizard(false, this);
1676     if (w->exec() == QDialog::Accepted && w->isOk()) {
1677         w->adjustSettings();
1678     }
1679     delete w;
1680 }
1681
1682 void MainWindow::newFile(bool showProjectSettings, bool force)
1683 {
1684     if (!m_timelineArea->isEnabled() && !force)
1685         return;
1686     m_fileRevert->setEnabled(false);
1687     QString profileName = KdenliveSettings::default_profile();
1688     KUrl projectFolder = KdenliveSettings::defaultprojectfolder();
1689     QPoint projectTracks(KdenliveSettings::videotracks(), KdenliveSettings::audiotracks());
1690     if (!showProjectSettings) {
1691         if (!KdenliveSettings::activatetabs())
1692             if (!closeCurrentDocument())
1693                 return;
1694     } else {
1695         ProjectSettings *w = new ProjectSettings(NULL, QStringList(), projectTracks.x(), projectTracks.y(), KdenliveSettings::defaultprojectfolder(), false, true, this);
1696         if (w->exec() != QDialog::Accepted)
1697             return;
1698         if (!KdenliveSettings::activatetabs())
1699             if (!closeCurrentDocument())
1700                 return;
1701         if (KdenliveSettings::videothumbnails() != w->enableVideoThumbs())
1702             slotSwitchVideoThumbs();
1703         if (KdenliveSettings::audiothumbnails() != w->enableAudioThumbs())
1704             slotSwitchAudioThumbs();
1705         profileName = w->selectedProfile();
1706         projectFolder = w->selectedFolder();
1707         projectTracks = w->tracks();
1708         delete w;
1709     }
1710     m_timelineArea->setEnabled(true);
1711     m_projectList->setEnabled(true);
1712     KdenliveDoc *doc = new KdenliveDoc(KUrl(), projectFolder, m_commandStack, profileName, projectTracks, m_projectMonitor->render, this);
1713     doc->m_autosave = new KAutoSaveFile(KUrl(), doc);
1714     bool ok;
1715     TrackView *trackView = new TrackView(doc, &ok, this);
1716     m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description());
1717     if (!ok) {
1718         // MLT is broken
1719         //m_timelineArea->setEnabled(false);
1720         //m_projectList->setEnabled(false);
1721         slotPreferences(6);
1722         return;
1723     }
1724     if (m_timelineArea->count() == 1) {
1725         connectDocumentInfo(doc);
1726         connectDocument(trackView, doc);
1727     } else
1728         m_timelineArea->setTabBarHidden(false);
1729     m_monitorManager->activateMonitor("clip");
1730     m_closeAction->setEnabled(m_timelineArea->count() > 1);
1731 }
1732
1733 void MainWindow::activateDocument()
1734 {
1735     if (m_timelineArea->currentWidget() == NULL || !m_timelineArea->isEnabled()) return;
1736     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
1737     KdenliveDoc *currentDoc = currentTab->document();
1738     connectDocumentInfo(currentDoc);
1739     connectDocument(currentTab, currentDoc);
1740 }
1741
1742 bool MainWindow::closeCurrentDocument(bool saveChanges)
1743 {
1744     QWidget *w = m_timelineArea->currentWidget();
1745     if (!w) return true;
1746     // closing current document
1747     int ix = m_timelineArea->currentIndex() + 1;
1748     if (ix == m_timelineArea->count()) ix = 0;
1749     m_timelineArea->setCurrentIndex(ix);
1750     TrackView *tabToClose = (TrackView *) w;
1751     KdenliveDoc *docToClose = tabToClose->document();
1752     if (docToClose && docToClose->isModified() && saveChanges) {
1753         QString message;
1754         if (m_activeDocument->url().fileName().isEmpty())
1755             message = i18n("Save changes to document?");
1756         else
1757             message = i18n("The project <b>\"%1\"</b> has been changed.\nDo you want to save your changes?").arg(m_activeDocument->url().fileName());
1758         switch (KMessageBox::warningYesNoCancel(this, message)) {
1759         case KMessageBox::Yes :
1760             // save document here. If saving fails, return false;
1761             if (saveFile() == false) return false;
1762             break;
1763         case KMessageBox::Cancel :
1764             return false;
1765             break;
1766         default:
1767             break;
1768         }
1769     }
1770     m_clipMonitor->slotSetXml(NULL);
1771     m_timelineArea->removeTab(m_timelineArea->indexOf(w));
1772     if (m_timelineArea->count() == 1) {
1773         m_timelineArea->setTabBarHidden(true);
1774         m_closeAction->setEnabled(false);
1775     }
1776     if (docToClose == m_activeDocument) {
1777         delete m_activeDocument;
1778         m_activeDocument = NULL;
1779         m_effectStack->clear();
1780         m_transitionConfig->slotTransitionItemSelected(NULL, 0, QPoint(), false);
1781     } else {
1782         delete docToClose;
1783     }
1784     if (w == m_activeTimeline) {
1785         delete m_activeTimeline;
1786         m_activeTimeline = NULL;
1787     } else {
1788         delete w;
1789     }
1790     return true;
1791 }
1792
1793 bool MainWindow::saveFileAs(const QString &outputFileName)
1794 {
1795     QString currentSceneList;
1796     m_monitorManager->stopActiveMonitor();
1797     if (KdenliveSettings::dropbframes()) {
1798         KdenliveSettings::setDropbframes(false);
1799         m_activeDocument->clipManager()->updatePreviewSettings();
1800         currentSceneList = m_projectMonitor->sceneList();
1801         KdenliveSettings::setDropbframes(true);
1802         m_activeDocument->clipManager()->updatePreviewSettings();
1803     } else currentSceneList = m_projectMonitor->sceneList();
1804
1805     if (m_activeDocument->saveSceneList(outputFileName, currentSceneList) == false)
1806         return false;
1807
1808     // Save timeline thumbnails
1809     m_activeTimeline->projectView()->saveThumbnails();
1810     m_activeDocument->setUrl(KUrl(outputFileName));
1811     if (m_activeDocument->m_autosave == NULL) {
1812         m_activeDocument->m_autosave = new KAutoSaveFile(KUrl(outputFileName), this);
1813     } else m_activeDocument->m_autosave->setManagedFile(KUrl(outputFileName));
1814     setCaption(m_activeDocument->description());
1815     m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
1816     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), m_activeDocument->url().path());
1817     m_activeDocument->setModified(false);
1818     m_fileOpenRecent->addUrl(KUrl(outputFileName));
1819     m_fileRevert->setEnabled(true);
1820     return true;
1821 }
1822
1823 bool MainWindow::saveFileAs()
1824 {
1825     QString outputFile = KFileDialog::getSaveFileName(m_activeDocument->projectFolder(), getMimeType());
1826     if (outputFile.isEmpty()) {
1827         return false;
1828     }
1829     if (QFile::exists(outputFile)) {
1830         // Show the file dialog again if the user does not want to overwrite the file
1831         if (KMessageBox::questionYesNo(this, i18n("File %1 already exists.\nDo you want to overwrite it?", outputFile)) == KMessageBox::No)
1832             return saveFileAs();
1833     }
1834     return saveFileAs(outputFile);
1835 }
1836
1837 bool MainWindow::saveFile()
1838 {
1839     if (!m_activeDocument) return true;
1840     if (m_activeDocument->url().isEmpty()) {
1841         return saveFileAs();
1842     } else {
1843         bool result = saveFileAs(m_activeDocument->url().path());
1844         m_activeDocument->m_autosave->resize(0);
1845         return result;
1846     }
1847 }
1848
1849 void MainWindow::openFile()
1850 {
1851     if (!m_startUrl.isEmpty()) {
1852         openFile(m_startUrl);
1853         m_startUrl = KUrl();
1854         return;
1855     }
1856     KUrl url = KFileDialog::getOpenUrl(KUrl("kfiledialog:///projectfolder"), getMimeType());
1857     if (url.isEmpty()) return;
1858     m_fileOpenRecent->addUrl(url);
1859     openFile(url);
1860 }
1861
1862 void MainWindow::openLastFile()
1863 {
1864     KSharedConfigPtr config = KGlobal::config();
1865     KUrl::List urls = m_fileOpenRecent->urls();
1866     //WARNING: this is buggy, we get a random url, not the last one. Bug in KRecentFileAction?
1867     if (urls.isEmpty()) newFile(false);
1868     else openFile(urls.last());
1869 }
1870
1871 void MainWindow::openFile(const KUrl &url)
1872 {
1873     // Check if the document is already opened
1874     const int ct = m_timelineArea->count();
1875     bool isOpened = false;
1876     int i;
1877     for (i = 0; i < ct; i++) {
1878         TrackView *tab = (TrackView *) m_timelineArea->widget(i);
1879         KdenliveDoc *doc = tab->document();
1880         if (doc->url() == url) {
1881             isOpened = true;
1882             break;
1883         }
1884     }
1885     if (isOpened) {
1886         m_timelineArea->setCurrentIndex(i);
1887         return;
1888     }
1889
1890     if (!KdenliveSettings::activatetabs()) if (!closeCurrentDocument()) return;
1891
1892     // Check for backup file
1893     QList<KAutoSaveFile *> staleFiles = KAutoSaveFile::staleFiles(url);
1894     if (!staleFiles.isEmpty()) {
1895         if (KMessageBox::questionYesNo(this,
1896                                        i18n("Auto-saved files exist. Do you want to recover them now?"),
1897                                        i18n("File Recovery"),
1898                                        KGuiItem(i18n("Recover")), KGuiItem(i18n("Don't recover"))) == KMessageBox::Yes) {
1899             recoverFiles(staleFiles);
1900             return;
1901         } else {
1902             // remove the stale files
1903             foreach(KAutoSaveFile * stale, staleFiles) {
1904                 stale->open(QIODevice::ReadWrite);
1905                 delete stale;
1906             }
1907         }
1908     }
1909     m_messageLabel->setMessage(i18n("Opening file %1", url.path()), InformationMessage);
1910     m_messageLabel->repaint();
1911     doOpenFile(url, NULL);
1912 }
1913
1914 void MainWindow::doOpenFile(const KUrl &url, KAutoSaveFile *stale)
1915 {
1916     if (!m_timelineArea->isEnabled()) return;
1917     m_fileRevert->setEnabled(true);
1918     KdenliveDoc *doc = new KdenliveDoc(url, KdenliveSettings::defaultprojectfolder(), m_commandStack, KdenliveSettings::default_profile(), QPoint(KdenliveSettings::videotracks(), KdenliveSettings::audiotracks()), m_projectMonitor->render, this);
1919     if (stale == NULL) {
1920         stale = new KAutoSaveFile(url, doc);
1921         doc->m_autosave = stale;
1922     } else {
1923         doc->m_autosave = stale;
1924         doc->setUrl(stale->managedFile());
1925         doc->setModified(true);
1926         stale->setParent(doc);
1927     }
1928     connectDocumentInfo(doc);
1929     bool ok;
1930     TrackView *trackView = new TrackView(doc, &ok, this);
1931     m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description()));
1932     if (!ok) {
1933         m_timelineArea->setEnabled(false);
1934         m_projectList->setEnabled(false);
1935         KMessageBox::sorry(this, i18n("Cannot open file %1.\nProject is corrupted.", url.path()));
1936         slotGotProgressInfo(QString(), -1);
1937         newFile(false, true);
1938         return;
1939     }
1940     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), doc->url().path());
1941     trackView->setDuration(trackView->duration());
1942     trackView->projectView()->initCursorPos(m_projectMonitor->render->seekPosition().frames(doc->fps()));
1943
1944     if (m_timelineArea->count() > 1) m_timelineArea->setTabBarHidden(false);
1945     slotGotProgressInfo(QString(), -1);
1946     m_projectMonitor->adjustRulerSize(trackView->duration());
1947     m_projectMonitor->slotZoneMoved(trackView->inPoint(), trackView->outPoint());
1948     m_clipMonitor->refreshMonitor(true);
1949 }
1950
1951 void MainWindow::recoverFiles(QList<KAutoSaveFile *> staleFiles)
1952 {
1953     foreach(KAutoSaveFile * stale, staleFiles) {
1954         /*if (!stale->open(QIODevice::QIODevice::ReadOnly)) {
1955                   // show an error message; we could not steal the lockfile
1956                   // maybe another application got to the file before us?
1957                   delete stale;
1958                   continue;
1959         }*/
1960         kDebug() << "// OPENING RECOVERY: " << stale->fileName() << "\nMANAGED: " << stale->managedFile().path();
1961         // the stalefiles also contain ".lock" files so we must ignore them... bug in KAutoSaveFile?
1962         if (!stale->fileName().endsWith(".lock")) doOpenFile(KUrl(stale->fileName()), stale);
1963         else KIO::NetAccess::del(KUrl(stale->fileName()), this);
1964     }
1965 }
1966
1967 void MainWindow::parseProfiles(const QString &mltPath)
1968 {
1969     //KdenliveSettings::setDefaulttmpfolder();
1970     if (!mltPath.isEmpty()) {
1971         KdenliveSettings::setMltpath(mltPath + "/share/mlt/profiles/");
1972         KdenliveSettings::setRendererpath(mltPath + "/bin/melt");
1973     }
1974
1975     if (KdenliveSettings::mltpath().isEmpty())
1976         KdenliveSettings::setMltpath(QString(MLT_PREFIX) + QString("/share/mlt/profiles/"));
1977
1978     if (KdenliveSettings::rendererpath().isEmpty() || KdenliveSettings::rendererpath().endsWith("inigo")) {
1979         QString meltPath = QString(MLT_PREFIX) + QString("/bin/melt");
1980         if (!QFile::exists(meltPath))
1981             meltPath = KStandardDirs::findExe("melt");
1982         KdenliveSettings::setRendererpath(meltPath);
1983     }
1984
1985     if (KdenliveSettings::rendererpath().isEmpty()) {
1986         // Cannot find the MLT melt renderer, ask for location
1987         KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(QString(), i18n("Cannot find the melt program required for rendering (part of MLT)"), this);
1988         if (getUrl->exec() == QDialog::Rejected) {
1989             ::exit(0);
1990         }
1991         KUrl rendererPath = getUrl->selectedUrl();
1992         delete getUrl;
1993         if (rendererPath.isEmpty()) ::exit(0);
1994         KdenliveSettings::setRendererpath(rendererPath.path());
1995     }
1996
1997     QStringList profilesFilter;
1998     profilesFilter << "*";
1999     QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
2000     if (profilesList.isEmpty()) {
2001         // Cannot find MLT path, try finding melt
2002         QString profilePath = KdenliveSettings::rendererpath();
2003         if (!profilePath.isEmpty()) {
2004             profilePath = profilePath.section('/', 0, -3);
2005             KdenliveSettings::setMltpath(profilePath + "/share/mlt/profiles/");
2006             profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
2007         }
2008         if (profilesList.isEmpty()) {
2009             // Cannot find the MLT profiles, ask for location
2010             KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find your MLT profiles, please give the path"), this);
2011             getUrl->fileDialog()->setMode(KFile::Directory);
2012             if (getUrl->exec() == QDialog::Rejected) {
2013                 ::exit(0);
2014             }
2015             KUrl mltPath = getUrl->selectedUrl();
2016             delete getUrl;
2017             if (mltPath.isEmpty()) ::exit(0);
2018             KdenliveSettings::setMltpath(mltPath.path(KUrl::AddTrailingSlash));
2019             profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
2020         }
2021     }
2022
2023     kDebug() << "RESULTING MLT PATH: " << KdenliveSettings::mltpath();
2024
2025     // Parse again MLT profiles to build a list of available video formats
2026     if (profilesList.isEmpty()) parseProfiles();
2027 }
2028
2029
2030 void MainWindow::slotEditProfiles()
2031 {
2032     ProfilesDialog *w = new ProfilesDialog;
2033     if (w->exec() == QDialog::Accepted) {
2034         KdenliveSettingsDialog* d = static_cast <KdenliveSettingsDialog*>(KConfigDialog::exists("settings"));
2035         if (d) d->checkProfile();
2036     }
2037     delete w;
2038 }
2039
2040 void MainWindow::slotDetectAudioDriver()
2041 {
2042     /* WARNING: do not use this method because sometimes detects wrong driver (pulse instead of alsa),
2043     leading to no audio output, see bug #934 */
2044
2045     //decide which audio driver is really best, in some cases SDL is wrong
2046     if (KdenliveSettings::audiodrivername().isEmpty()) {
2047         QString driver;
2048         KProcess readProcess;
2049         //PulseAudio needs to be selected if it exists, the ALSA pulse pcm device is not fast enough.
2050         if (!KStandardDirs::findExe("pactl").isEmpty()) {
2051             readProcess.setOutputChannelMode(KProcess::OnlyStdoutChannel);
2052             readProcess.setProgram("pactl", QStringList() << "stat");
2053             readProcess.execute(2000); // Kill it after 2 seconds
2054
2055             QString result = QString(readProcess.readAllStandardOutput());
2056             kDebug() << "// / / / / / READING PACTL: ";
2057             kDebug() << result;
2058             if (!result.isEmpty()) {
2059                 driver = "pulse";
2060                 kDebug() << "// / / / / PULSEAUDIO DETECTED";
2061             }
2062         }
2063         //put others here
2064         KdenliveSettings::setAutoaudiodrivername(driver);
2065     }
2066 }
2067
2068 void MainWindow::slotEditProjectSettings()
2069 {
2070     QPoint p = m_activeDocument->getTracksCount();
2071     ProjectSettings *w = new ProjectSettings(m_projectList, m_activeTimeline->projectView()->extractTransitionsLumas(), p.x(), p.y(), m_activeDocument->projectFolder().path(), true, !m_activeDocument->isModified(), this);
2072
2073     if (w->exec() == QDialog::Accepted) {
2074         QString profile = w->selectedProfile();
2075         m_activeDocument->setProjectFolder(w->selectedFolder());
2076         if (m_renderWidget) m_renderWidget->setDocumentPath(w->selectedFolder().path(KUrl::AddTrailingSlash));
2077         if (KdenliveSettings::videothumbnails() != w->enableVideoThumbs()) slotSwitchVideoThumbs();
2078         if (KdenliveSettings::audiothumbnails() != w->enableAudioThumbs()) slotSwitchAudioThumbs();
2079         if (m_activeDocument->profilePath() != profile) slotUpdateProjectProfile(profile);
2080     }
2081     delete w;
2082 }
2083
2084 void MainWindow::slotUpdateProjectProfile(const QString &profile)
2085 {
2086     double dar = m_activeDocument->dar();
2087
2088     // Deselect current effect / transition
2089     m_effectStack->slotClipItemSelected(NULL, 0);
2090     m_transitionConfig->slotTransitionItemSelected(NULL, 0, QPoint(), false);
2091     m_clipMonitor->slotSetXml(NULL);
2092     bool updateFps = m_activeDocument->setProfilePath(profile);
2093     KdenliveSettings::setCurrent_profile(profile);
2094     KdenliveSettings::setProject_fps(m_activeDocument->fps());
2095     setCaption(m_activeDocument->description(), m_activeDocument->isModified());
2096
2097     m_activeDocument->clipManager()->clearUnusedProducers();
2098     m_monitorManager->resetProfiles(m_activeDocument->timecode());
2099     m_transitionConfig->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode(), m_activeDocument->tracksList());
2100     m_effectStack->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode());
2101     m_projectList->updateProjectFormat(m_activeDocument->timecode());
2102     if (m_renderWidget) m_renderWidget->setProfile(m_activeDocument->mltProfile());
2103     m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
2104     //m_activeDocument->clipManager()->resetProducersList(m_projectMonitor->render->producersList());
2105     if (dar != m_activeDocument->dar()) m_projectList->reloadClipThumbnails();
2106     if (updateFps) m_activeTimeline->updateProjectFps();
2107     m_activeDocument->setModified(true);
2108     m_commandStack->activeStack()->clear();
2109     //Update the mouse position display so it will display in DF/NDF format by default based on the project setting.
2110     slotUpdateMousePosition(0);
2111     // We need to desactivate & reactivate monitors to get a refresh
2112     //m_monitorManager->switchMonitors();
2113 }
2114
2115
2116 void MainWindow::slotRenderProject()
2117 {
2118     if (!m_renderWidget) {
2119         QString projectfolder = m_activeDocument ? m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash) : KdenliveSettings::defaultprojectfolder();
2120         m_renderWidget = new RenderWidget(projectfolder, this);
2121         connect(m_renderWidget, SIGNAL(shutdown()), this, SLOT(slotShutdown()));
2122         connect(m_renderWidget, SIGNAL(selectedRenderProfile(QMap <QString, QString>)), this, SLOT(slotSetDocumentRenderProfile(QMap <QString, QString>)));
2123         connect(m_renderWidget, SIGNAL(prepareRenderingData(bool, bool, const QString&)), this, SLOT(slotPrepareRendering(bool, bool, const QString&)));
2124         connect(m_renderWidget, SIGNAL(abortProcess(const QString &)), this, SIGNAL(abortRenderJob(const QString &)));
2125         connect(m_renderWidget, SIGNAL(openDvdWizard(const QString &, const QString &)), this, SLOT(slotDvdWizard(const QString &, const QString &)));
2126         if (m_activeDocument) {
2127             m_renderWidget->setProfile(m_activeDocument->mltProfile());
2128             m_renderWidget->setGuides(m_activeDocument->guidesXml(), m_activeDocument->projectDuration());
2129             m_renderWidget->setDocumentPath(m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash));
2130             m_renderWidget->setRenderProfile(m_activeDocument->getRenderProperties());
2131         }
2132     }
2133     slotCheckRenderStatus();
2134     m_renderWidget->show();
2135     m_renderWidget->showNormal();
2136
2137     // What are the following lines supposed to do?
2138     //m_activeTimeline->tracksNumber();
2139     //m_renderWidget->enableAudio(false);
2140     //m_renderWidget->export_audio;
2141 }
2142
2143 void MainWindow::slotCheckRenderStatus()
2144 {
2145     // Make sure there are no missing clips
2146     if (m_renderWidget)
2147         m_renderWidget->missingClips(m_projectList->hasMissingClips());
2148 }
2149
2150 void MainWindow::setRenderingProgress(const QString &url, int progress)
2151 {
2152     if (m_renderWidget)
2153         m_renderWidget->setRenderJob(url, progress);
2154 }
2155
2156 void MainWindow::setRenderingFinished(const QString &url, int status, const QString &error)
2157 {
2158     if (m_renderWidget)
2159         m_renderWidget->setRenderStatus(url, status, error);
2160 }
2161
2162 void MainWindow::slotCleanProject()
2163 {
2164     if (KMessageBox::warningContinueCancel(this, i18n("This will remove all unused clips from your project."), i18n("Clean up project")) == KMessageBox::Cancel) return;
2165     m_projectList->cleanup();
2166 }
2167
2168 void MainWindow::slotUpdateMousePosition(int pos)
2169 {
2170     if (m_activeDocument)
2171         switch (m_timecodeFormat->currentIndex()) {
2172         case 0:
2173             statusBar()->changeItem(m_activeDocument->timecode().getTimecodeFromFrames(pos), ID_TIMELINE_POS);
2174             break;
2175         default:
2176             statusBar()->changeItem(QString::number(pos), ID_TIMELINE_POS);
2177         }
2178 }
2179
2180 void MainWindow::slotUpdateDocumentState(bool modified)
2181 {
2182     if (!m_activeDocument) return;
2183     setCaption(m_activeDocument->description(), modified);
2184     m_saveAction->setEnabled(modified);
2185     if (modified) {
2186         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Link));
2187         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("document-save"));
2188     } else {
2189         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Text));
2190         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("kdenlive"));
2191     }
2192 }
2193
2194 void MainWindow::connectDocumentInfo(KdenliveDoc *doc)
2195 {
2196     if (m_activeDocument) {
2197         if (m_activeDocument == doc) return;
2198         disconnect(m_activeDocument, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
2199     }
2200     connect(doc, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
2201 }
2202
2203 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc)   //changed
2204 {
2205     //m_projectMonitor->stop();
2206     m_closeAction->setEnabled(m_timelineArea->count() > 1);
2207     kDebug() << "///////////////////   CONNECTING DOC TO PROJECT VIEW ////////////////";
2208     if (m_activeDocument) {
2209         if (m_activeDocument == doc) return;
2210         if (m_activeTimeline) {
2211             disconnect(m_projectMonitor, SIGNAL(renderPosition(int)), m_activeTimeline, SLOT(moveCursorPos(int)));
2212             disconnect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), m_activeTimeline, SLOT(slotSetZone(QPoint)));
2213             disconnect(m_projectMonitor, SIGNAL(durationChanged(int)), m_activeTimeline, SLOT(setDuration(int)));
2214             disconnect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), m_activeDocument, SLOT(setModified()));
2215             disconnect(m_clipMonitor, SIGNAL(zoneUpdated(QPoint)), m_activeDocument, SLOT(setModified()));
2216             disconnect(m_projectList, SIGNAL(projectModified()), m_activeDocument, SLOT(setModified()));
2217             disconnect(m_projectList, SIGNAL(updateProfile(const QString &)), this, SLOT(slotUpdateProjectProfile(const QString &)));
2218
2219             disconnect(m_projectMonitor->render, SIGNAL(refreshDocumentProducers()), m_activeDocument, SLOT(checkProjectClips()));
2220
2221             disconnect(m_activeDocument, SIGNAL(guidesUpdated()), this, SLOT(slotGuidesUpdated()));
2222             disconnect(m_activeDocument, SIGNAL(addProjectClip(DocClipBase *, bool)), m_projectList, SLOT(slotAddClip(DocClipBase *, bool)));
2223             disconnect(m_activeDocument, SIGNAL(resetProjectList()), m_projectList, SLOT(slotResetProjectList()));
2224             disconnect(m_activeDocument, SIGNAL(signalDeleteProjectClip(const QString &)), m_projectList, SLOT(slotDeleteClip(const QString &)));
2225             disconnect(m_activeDocument, SIGNAL(updateClipDisplay(const QString &)), m_projectList, SLOT(slotUpdateClip(const QString &)));
2226             disconnect(m_activeDocument, SIGNAL(selectLastAddedClip(const QString &)), m_projectList, SLOT(slotSelectClip(const QString &)));
2227             disconnect(m_activeDocument, SIGNAL(deleteTimelineClip(const QString &)), m_activeTimeline, SLOT(slotDeleteClip(const QString &)));
2228             disconnect(m_activeTimeline->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), m_effectStack, SLOT(slotClipItemSelected(ClipItem*, int)));
2229             disconnect(m_activeTimeline->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), this, SLOT(slotActivateEffectStackView()));
2230             disconnect(m_activeTimeline->projectView(), SIGNAL(transitionItemSelected(Transition*, int, QPoint, bool)), m_transitionConfig, SLOT(slotTransitionItemSelected(Transition*, int, QPoint, bool)));
2231             disconnect(m_activeTimeline->projectView(), SIGNAL(transitionItemSelected(Transition*, int, QPoint, bool)), this, SLOT(slotActivateTransitionView(Transition *)));
2232             disconnect(m_activeTimeline->projectView(), SIGNAL(playMonitor()), m_projectMonitor, SLOT(slotPlay()));
2233             disconnect(m_activeTimeline->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
2234             disconnect(m_activeTimeline->projectView(), SIGNAL(showClipFrame(DocClipBase *, QPoint, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, QPoint, const int)));
2235             disconnect(m_activeTimeline, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
2236             disconnect(m_activeTimeline, SIGNAL(insertTrack(int)), this, SLOT(slotInsertTrack(int)));
2237             disconnect(m_activeTimeline, SIGNAL(deleteTrack(int)), this, SLOT(slotDeleteTrack(int)));
2238             disconnect(m_activeTimeline, SIGNAL(configTrack(int)), this, SLOT(slotConfigTrack(int)));
2239             disconnect(m_activeDocument, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
2240             disconnect(m_effectStack, SIGNAL(updateEffect(ClipItem*, int, QDomElement, QDomElement, int)), m_activeTimeline->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, int, QDomElement, QDomElement, int)));
2241             disconnect(m_effectStack, SIGNAL(removeEffect(ClipItem*, int, QDomElement)), m_activeTimeline->projectView(), SLOT(slotDeleteEffect(ClipItem*, int, QDomElement)));
2242             disconnect(m_effectStack, SIGNAL(changeEffectState(ClipItem*, int, int, bool)), m_activeTimeline->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, int, bool)));
2243             disconnect(m_effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int, int)), m_activeTimeline->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int, int)));
2244             disconnect(m_effectStack, SIGNAL(refreshEffectStack(ClipItem*)), m_activeTimeline->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
2245             disconnect(m_effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
2246             disconnect(m_effectStack, SIGNAL(displayMessage(const QString&, int)), this, SLOT(slotGotProgressInfo(const QString&, int)));
2247             disconnect(m_transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), m_activeTimeline->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
2248             disconnect(m_transitionConfig, SIGNAL(seekTimeline(int)), m_activeTimeline->projectView() , SLOT(setCursorPos(int)));
2249             disconnect(m_activeTimeline->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
2250             disconnect(m_activeTimeline, SIGNAL(zoneMoved(int, int)), this, SLOT(slotZoneMoved(int, int)));
2251             disconnect(m_projectList, SIGNAL(loadingIsOver()), m_activeTimeline->projectView(), SLOT(slotUpdateAllThumbs()));
2252             disconnect(m_projectList, SIGNAL(displayMessage(const QString&, int)), this, SLOT(slotGotProgressInfo(const QString&, int)));
2253             disconnect(m_projectList, SIGNAL(updateRenderStatus()), this, SLOT(slotCheckRenderStatus()));
2254             disconnect(m_projectList, SIGNAL(clipNeedsReload(const QString&, bool)), m_activeTimeline->projectView(), SLOT(slotUpdateClip(const QString &, bool)));
2255             m_effectStack->clear();
2256         }
2257         //m_activeDocument->setRenderer(NULL);
2258         disconnect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
2259         disconnect(m_projectList, SIGNAL(refreshClip()), m_clipMonitor, SLOT(refreshMonitor()));
2260         m_clipMonitor->stop();
2261     }
2262     KdenliveSettings::setCurrent_profile(doc->profilePath());
2263     KdenliveSettings::setProject_fps(doc->fps());
2264     m_monitorManager->resetProfiles(doc->timecode());
2265     m_projectList->setDocument(doc);
2266     m_transitionConfig->updateProjectFormat(doc->mltProfile(), doc->timecode(), doc->tracksList());
2267     m_effectStack->updateProjectFormat(doc->mltProfile(), doc->timecode());
2268     connect(m_projectList, SIGNAL(clipSelected(DocClipBase *, QPoint)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, QPoint)));
2269     connect(m_projectList, SIGNAL(refreshClip()), m_clipMonitor, SLOT(refreshMonitor()));
2270     connect(m_projectList, SIGNAL(clipNeedsReload(const QString&, bool)), trackView->projectView(), SLOT(slotUpdateClip(const QString &, bool)));
2271
2272     connect(m_projectList, SIGNAL(projectModified()), doc, SLOT(setModified()));
2273     connect(m_projectList, SIGNAL(updateProfile(const QString &)), this, SLOT(slotUpdateProjectProfile(const QString &)));
2274     connect(m_projectList, SIGNAL(clipNameChanged(const QString, const QString)), trackView->projectView(), SLOT(clipNameChanged(const QString, const QString)));
2275
2276     connect(m_projectList, SIGNAL(findInTimeline(const QString&)), this, SLOT(slotClipInTimeline(const QString&)));
2277
2278
2279     connect(trackView, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
2280     connect(trackView, SIGNAL(insertTrack(int)), this, SLOT(slotInsertTrack(int)));
2281     connect(trackView, SIGNAL(deleteTrack(int)), this, SLOT(slotDeleteTrack(int)));
2282     connect(trackView, SIGNAL(configTrack(int)), this, SLOT(slotConfigTrack(int)));
2283     connect(trackView, SIGNAL(updateTracksInfo()), this, SLOT(slotUpdateTrackInfo()));
2284     connect(trackView, SIGNAL(mousePosition(int)), this, SLOT(slotUpdateMousePosition(int)));
2285     connect(trackView->projectView(), SIGNAL(forceClipProcessing(const QString &)), m_projectList, SLOT(slotForceProcessing(const QString &)));
2286     connect(m_projectMonitor, SIGNAL(renderPosition(int)), trackView, SLOT(moveCursorPos(int)));
2287     connect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), trackView, SLOT(slotSetZone(QPoint)));
2288     connect(m_clipMonitor, SIGNAL(zoneUpdated(QPoint)), m_projectList, SLOT(slotUpdateClipCut(QPoint)));
2289     connect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), doc, SLOT(setModified()));
2290     connect(m_clipMonitor, SIGNAL(zoneUpdated(QPoint)), doc, SLOT(setModified()));
2291     connect(m_projectMonitor, SIGNAL(durationChanged(int)), trackView, SLOT(setDuration(int)));
2292     connect(m_projectMonitor->render, SIGNAL(refreshDocumentProducers()), doc, SLOT(checkProjectClips()));
2293
2294     connect(doc, SIGNAL(addProjectClip(DocClipBase *, bool)), m_projectList, SLOT(slotAddClip(DocClipBase *, bool)));
2295     connect(doc, SIGNAL(resetProjectList()), m_projectList, SLOT(slotResetProjectList()));
2296     connect(doc, SIGNAL(signalDeleteProjectClip(const QString &)), m_projectList, SLOT(slotDeleteClip(const QString &)));
2297     connect(doc, SIGNAL(updateClipDisplay(const QString &)), m_projectList, SLOT(slotUpdateClip(const QString &)));
2298     connect(doc, SIGNAL(selectLastAddedClip(const QString &)), m_projectList, SLOT(slotSelectClip(const QString &)));
2299
2300     connect(doc, SIGNAL(deleteTimelineClip(const QString &)), trackView, SLOT(slotDeleteClip(const QString &)));
2301     connect(doc, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
2302     connect(doc, SIGNAL(guidesUpdated()), this, SLOT(slotGuidesUpdated()));
2303
2304
2305     connect(trackView->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), m_effectStack, SLOT(slotClipItemSelected(ClipItem*, int)));
2306     connect(trackView->projectView(), SIGNAL(updateClipMarkers(DocClipBase *)), this, SLOT(slotUpdateClipMarkers(DocClipBase*)));
2307     connect(trackView, SIGNAL(showTrackEffects(int, TrackInfo)), m_effectStack, SLOT(slotTrackItemSelected(int, TrackInfo)));
2308     connect(trackView, SIGNAL(showTrackEffects(int, TrackInfo)), this, SLOT(slotActivateEffectStackView()));
2309
2310     connect(trackView->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), this, SLOT(slotActivateEffectStackView()));
2311     connect(trackView->projectView(), SIGNAL(transitionItemSelected(Transition*, int, QPoint, bool)), m_transitionConfig, SLOT(slotTransitionItemSelected(Transition*, int, QPoint, bool)));
2312     connect(trackView->projectView(), SIGNAL(transitionItemSelected(Transition*, int, QPoint, bool)), this, SLOT(slotActivateTransitionView(Transition *)));
2313     m_zoomSlider->setValue(doc->zoom().x());
2314     connect(trackView->projectView(), SIGNAL(zoomIn()), this, SLOT(slotZoomIn()));
2315     connect(trackView->projectView(), SIGNAL(zoomOut()), this, SLOT(slotZoomOut()));
2316     connect(trackView, SIGNAL(setZoom(int)), this, SLOT(slotSetZoom(int)));
2317     connect(trackView->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
2318
2319     connect(trackView->projectView(), SIGNAL(showClipFrame(DocClipBase *, QPoint, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, QPoint, const int)));
2320     connect(trackView->projectView(), SIGNAL(playMonitor()), m_projectMonitor, SLOT(slotPlay()));
2321
2322
2323     connect(m_effectStack, SIGNAL(updateEffect(ClipItem*, int, QDomElement, QDomElement, int)), trackView->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, int, QDomElement, QDomElement, int)));
2324     connect(m_effectStack, SIGNAL(updateClipRegion(ClipItem*, int, QString)), trackView->projectView(), SLOT(slotUpdateClipRegion(ClipItem*, int, QString)));
2325     connect(m_effectStack, SIGNAL(removeEffect(ClipItem*, int, QDomElement)), trackView->projectView(), SLOT(slotDeleteEffect(ClipItem*, int, QDomElement)));
2326     connect(m_effectStack, SIGNAL(changeEffectState(ClipItem*, int, int, bool)), trackView->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, int, bool)));
2327     connect(m_effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int, int)), trackView->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int, int)));
2328     connect(m_effectStack, SIGNAL(refreshEffectStack(ClipItem*)), trackView->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
2329     connect(m_transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
2330     connect(m_transitionConfig, SIGNAL(seekTimeline(int)), trackView->projectView() , SLOT(setCursorPos(int)));
2331     connect(m_effectStack, SIGNAL(seekTimeline(int)), trackView->projectView() , SLOT(setCursorPos(int)));
2332     connect(m_effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
2333     connect(m_effectStack, SIGNAL(displayMessage(const QString&, int)), this, SLOT(slotGotProgressInfo(const QString&, int)));
2334
2335     connect(trackView->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
2336     connect(trackView, SIGNAL(zoneMoved(int, int)), this, SLOT(slotZoneMoved(int, int)));
2337     connect(m_projectList, SIGNAL(loadingIsOver()), trackView->projectView(), SLOT(slotUpdateAllThumbs()));
2338     connect(m_projectList, SIGNAL(displayMessage(const QString&, int)), this, SLOT(slotGotProgressInfo(const QString&, int)));
2339     connect(m_projectList, SIGNAL(updateRenderStatus()), this, SLOT(slotCheckRenderStatus()));
2340
2341
2342     trackView->projectView()->setContextMenu(m_timelineContextMenu, m_timelineContextClipMenu, m_timelineContextTransitionMenu, m_clipTypeGroup, (QMenu*)(factory()->container("marker_menu", this)));
2343     m_activeTimeline = trackView;
2344     if (m_renderWidget) {
2345         slotCheckRenderStatus();
2346         m_renderWidget->setProfile(doc->mltProfile());
2347         m_renderWidget->setGuides(doc->guidesXml(), doc->projectDuration());
2348         m_renderWidget->setDocumentPath(doc->projectFolder().path(KUrl::AddTrailingSlash));
2349         m_renderWidget->setRenderProfile(doc->getRenderProperties());
2350     }
2351     //doc->setRenderer(m_projectMonitor->render);
2352     m_commandStack->setActiveStack(doc->commandStack());
2353     KdenliveSettings::setProject_display_ratio(doc->dar());
2354     //doc->clipManager()->checkAudioThumbs();
2355
2356     //m_overView->setScene(trackView->projectScene());
2357     //m_overView->scale(m_overView->width() / trackView->duration(), m_overView->height() / (50 * trackView->tracksNumber()));
2358     //m_overView->fitInView(m_overView->itemAt(0, 50), Qt::KeepAspectRatio);
2359
2360     setCaption(doc->description(), doc->isModified());
2361     m_saveAction->setEnabled(doc->isModified());
2362     m_normalEditTool->setChecked(true);
2363     m_activeDocument = doc;
2364     m_activeTimeline->updateProjectFps();
2365     m_activeDocument->checkProjectClips();
2366     if (KdenliveSettings::dropbframes()) slotUpdatePreviewSettings();
2367     //Update the mouse position display so it will display in DF/NDF format by default based on the project setting.
2368     slotUpdateMousePosition(0);
2369     // set tool to select tool
2370     m_buttonSelectTool->setChecked(true);
2371 }
2372
2373 void MainWindow::slotZoneMoved(int start, int end)
2374 {
2375     m_activeDocument->setZone(start, end);
2376     m_projectMonitor->slotZoneMoved(start, end);
2377 }
2378
2379 void MainWindow::slotGuidesUpdated()
2380 {
2381     if (m_renderWidget)
2382         m_renderWidget->setGuides(m_activeDocument->guidesXml(), m_activeDocument->projectDuration());
2383 }
2384
2385 void MainWindow::slotEditKeys()
2386 {
2387     KShortcutsDialog dialog(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsAllowed, this);
2388     dialog.addCollection(actionCollection(), i18nc("general keyboard shortcuts", "General"));
2389     dialog.addCollection(m_effectsActionCollection, i18nc("effects and transitions keyboard shortcuts", "Effects & Transitions"));
2390     dialog.configure();
2391 }
2392
2393 void MainWindow::slotPreferences(int page, int option)
2394 {
2395     //An instance of your dialog could be already created and could be
2396     // cached, in which case you want to display the cached dialog
2397     // instead of creating another one
2398     if (KConfigDialog::showDialog("settings")) {
2399         KdenliveSettingsDialog* d = static_cast <KdenliveSettingsDialog*>(KConfigDialog::exists("settings"));
2400         if (page != -1) d->showPage(page, option);
2401         return;
2402     }
2403
2404     // KConfigDialog didn't find an instance of this dialog, so lets
2405     // create it :
2406     KdenliveSettingsDialog* dialog = new KdenliveSettingsDialog(this);
2407     connect(dialog, SIGNAL(settingsChanged(const QString&)), this, SLOT(updateConfiguration()));
2408     //connect(dialog, SIGNAL(doResetProfile()), this, SLOT(slotDetectAudioDriver()));
2409     connect(dialog, SIGNAL(doResetProfile()), m_monitorManager, SLOT(slotResetProfiles()));
2410     connect(dialog, SIGNAL(updatePreviewSettings()), this, SLOT(slotUpdatePreviewSettings()));
2411 #ifndef Q_WS_MAC
2412     connect(dialog, SIGNAL(updateCaptureFolder()), m_recMonitor, SLOT(slotUpdateCaptureFolder()));
2413 #endif
2414     //connect(dialog, SIGNAL(updatePreviewSettings()), this, SLOT(slotUpdatePreviewSettings()));
2415     dialog->show();
2416     if (page != -1) dialog->showPage(page, option);
2417 }
2418
2419 void MainWindow::slotUpdatePreviewSettings()
2420 {
2421     if (m_activeDocument) {
2422         m_clipMonitor->slotSetXml(NULL);
2423         m_activeDocument->updatePreviewSettings();
2424     }
2425 }
2426
2427 void MainWindow::updateConfiguration()
2428 {
2429     //TODO: we should apply settings to all projects, not only the current one
2430     if (m_activeTimeline) {
2431         m_activeTimeline->refresh();
2432         m_activeTimeline->projectView()->checkAutoScroll();
2433         m_activeTimeline->projectView()->checkTrackHeight();
2434         if (m_activeDocument)
2435             m_activeDocument->clipManager()->checkAudioThumbs();
2436     }
2437     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
2438     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
2439     m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
2440     m_buttonAutomaticSplitAudio->setChecked(KdenliveSettings::splitaudio());
2441
2442     // Update list of transcoding profiles
2443     loadTranscoders();
2444 #ifndef NO_JOGSHUTTLE
2445     activateShuttleDevice();
2446 #endif /* NO_JOGSHUTTLE */
2447
2448 }
2449
2450 void MainWindow::slotSwitchSplitAudio()
2451 {
2452     KdenliveSettings::setSplitaudio(!KdenliveSettings::splitaudio());
2453     m_buttonAutomaticSplitAudio->setChecked(KdenliveSettings::splitaudio());
2454 }
2455
2456 void MainWindow::slotSwitchVideoThumbs()
2457 {
2458     KdenliveSettings::setVideothumbnails(!KdenliveSettings::videothumbnails());
2459     if (m_activeTimeline)
2460         m_activeTimeline->projectView()->slotUpdateAllThumbs();
2461     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
2462 }
2463
2464 void MainWindow::slotSwitchAudioThumbs()
2465 {
2466     KdenliveSettings::setAudiothumbnails(!KdenliveSettings::audiothumbnails());
2467     if (m_activeTimeline) {
2468         m_activeTimeline->refresh();
2469         m_activeTimeline->projectView()->checkAutoScroll();
2470         if (m_activeDocument)
2471             m_activeDocument->clipManager()->checkAudioThumbs();
2472     }
2473     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
2474 }
2475
2476 void MainWindow::slotSwitchMarkersComments()
2477 {
2478     KdenliveSettings::setShowmarkers(!KdenliveSettings::showmarkers());
2479     if (m_activeTimeline)
2480         m_activeTimeline->refresh();
2481     m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
2482 }
2483
2484 void MainWindow::slotSwitchSnap()
2485 {
2486     KdenliveSettings::setSnaptopoints(!KdenliveSettings::snaptopoints());
2487     m_buttonSnap->setChecked(KdenliveSettings::snaptopoints());
2488 }
2489
2490
2491 void MainWindow::slotDeleteItem()
2492 {
2493     if (QApplication::focusWidget() &&
2494             QApplication::focusWidget()->parentWidget() &&
2495             QApplication::focusWidget()->parentWidget()->parentWidget() &&
2496             QApplication::focusWidget()->parentWidget()->parentWidget() == m_projectListDock) {
2497         m_projectList->slotRemoveClip();
2498
2499     } else {
2500         QWidget *widget = QApplication::focusWidget();
2501         while (widget) {
2502             if (widget == m_effectStackDock) {
2503                 m_effectStack->slotItemDel();
2504                 return;
2505             }
2506             widget = widget->parentWidget();
2507         }
2508
2509         // effect stack has no focus
2510         if (m_activeTimeline)
2511             m_activeTimeline->projectView()->deleteSelectedClips();
2512     }
2513 }
2514
2515 void MainWindow::slotUpdateClipMarkers(DocClipBase *clip)
2516 {
2517     if (m_clipMonitor->isActive())
2518         m_clipMonitor->checkOverlay();
2519     m_clipMonitor->updateMarkers(clip);
2520 }
2521
2522 void MainWindow::slotAddClipMarker()
2523 {
2524     DocClipBase *clip = NULL;
2525     GenTime pos;
2526     if (m_projectMonitor->isActive()) {
2527         if (m_activeTimeline) {
2528             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
2529             if (item) {
2530                 pos = GenTime((int)((m_projectMonitor->position() - item->startPos() + item->cropStart()).frames(m_activeDocument->fps()) * item->speed() + 0.5), m_activeDocument->fps());
2531                 clip = item->baseClip();
2532             }
2533         }
2534     } else {
2535         clip = m_clipMonitor->activeClip();
2536         pos = m_clipMonitor->position();
2537     }
2538     if (!clip) {
2539         m_messageLabel->setMessage(i18n("Cannot find clip to add marker"), ErrorMessage);
2540         return;
2541     }
2542     QString id = clip->getId();
2543     CommentedTime marker(pos, i18n("Marker"));
2544     MarkerDialog d(clip, marker, m_activeDocument->timecode(), i18n("Add Marker"), this);
2545     if (d.exec() == QDialog::Accepted)
2546         m_activeTimeline->projectView()->slotAddClipMarker(id, d.newMarker().time(), d.newMarker().comment());
2547 }
2548
2549 void MainWindow::slotDeleteClipMarker()
2550 {
2551     DocClipBase *clip = NULL;
2552     GenTime pos;
2553     if (m_projectMonitor->isActive()) {
2554         if (m_activeTimeline) {
2555             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
2556             if (item) {
2557                 pos = (m_projectMonitor->position() - item->startPos() + item->cropStart()) / item->speed();
2558                 clip = item->baseClip();
2559             }
2560         }
2561     } else {
2562         clip = m_clipMonitor->activeClip();
2563         pos = m_clipMonitor->position();
2564     }
2565     if (!clip) {
2566         m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
2567         return;
2568     }
2569
2570     QString id = clip->getId();
2571     QString comment = clip->markerComment(pos);
2572     if (comment.isEmpty()) {
2573         m_messageLabel->setMessage(i18n("No marker found at cursor time"), ErrorMessage);
2574         return;
2575     }
2576     m_activeTimeline->projectView()->slotDeleteClipMarker(comment, id, pos);
2577 }
2578
2579 void MainWindow::slotDeleteAllClipMarkers()
2580 {
2581     DocClipBase *clip = NULL;
2582     if (m_projectMonitor->isActive()) {
2583         if (m_activeTimeline) {
2584             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
2585             if (item) {
2586                 clip = item->baseClip();
2587             }
2588         }
2589     } else {
2590         clip = m_clipMonitor->activeClip();
2591     }
2592     if (!clip) {
2593         m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
2594         return;
2595     }
2596     m_activeTimeline->projectView()->slotDeleteAllClipMarkers(clip->getId());
2597 }
2598
2599 void MainWindow::slotEditClipMarker()
2600 {
2601     DocClipBase *clip = NULL;
2602     GenTime pos;
2603     if (m_projectMonitor->isActive()) {
2604         if (m_activeTimeline) {
2605             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
2606             if (item) {
2607                 pos = (m_projectMonitor->position() - item->startPos() + item->cropStart()) / item->speed();
2608                 clip = item->baseClip();
2609             }
2610         }
2611     } else {
2612         clip = m_clipMonitor->activeClip();
2613         pos = m_clipMonitor->position();
2614     }
2615     if (!clip) {
2616         m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
2617         return;
2618     }
2619
2620     QString id = clip->getId();
2621     QString oldcomment = clip->markerComment(pos);
2622     if (oldcomment.isEmpty()) {
2623         m_messageLabel->setMessage(i18n("No marker found at cursor time"), ErrorMessage);
2624         return;
2625     }
2626
2627     CommentedTime marker(pos, oldcomment);
2628     MarkerDialog d(clip, marker, m_activeDocument->timecode(), i18n("Edit Marker"), this);
2629     if (d.exec() == QDialog::Accepted) {
2630         m_activeTimeline->projectView()->slotAddClipMarker(id, d.newMarker().time(), d.newMarker().comment());
2631         if (d.newMarker().time() != pos) {
2632             // remove old marker
2633             m_activeTimeline->projectView()->slotAddClipMarker(id, pos, QString());
2634         }
2635     }
2636 }
2637
2638 void MainWindow::slotAddGuide()
2639 {
2640     if (m_activeTimeline)
2641         m_activeTimeline->projectView()->slotAddGuide();
2642 }
2643
2644 void MainWindow::slotInsertSpace()
2645 {
2646     if (m_activeTimeline)
2647         m_activeTimeline->projectView()->slotInsertSpace();
2648 }
2649
2650 void MainWindow::slotRemoveSpace()
2651 {
2652     if (m_activeTimeline)
2653         m_activeTimeline->projectView()->slotRemoveSpace();
2654 }
2655
2656 void MainWindow::slotInsertTrack(int ix)
2657 {
2658     m_projectMonitor->activateMonitor();
2659     if (m_activeTimeline)
2660         m_activeTimeline->projectView()->slotInsertTrack(ix);
2661     if (m_activeDocument)
2662         m_transitionConfig->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode(), m_activeDocument->tracksList());
2663 }
2664
2665 void MainWindow::slotDeleteTrack(int ix)
2666 {
2667     m_projectMonitor->activateMonitor();
2668     if (m_activeTimeline)
2669         m_activeTimeline->projectView()->slotDeleteTrack(ix);
2670     if (m_activeDocument)
2671         m_transitionConfig->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode(), m_activeDocument->tracksList());
2672 }
2673
2674 void MainWindow::slotConfigTrack(int ix)
2675 {
2676     m_projectMonitor->activateMonitor();
2677     if (m_activeTimeline)
2678         m_activeTimeline->projectView()->slotConfigTracks(ix);
2679     if (m_activeDocument)
2680         m_transitionConfig->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode(), m_activeDocument->tracksList());
2681 }
2682
2683 void MainWindow::slotEditGuide()
2684 {
2685     if (m_activeTimeline)
2686         m_activeTimeline->projectView()->slotEditGuide();
2687 }
2688
2689 void MainWindow::slotDeleteGuide()
2690 {
2691     if (m_activeTimeline)
2692         m_activeTimeline->projectView()->slotDeleteGuide();
2693 }
2694
2695 void MainWindow::slotDeleteAllGuides()
2696 {
2697     if (m_activeTimeline)
2698         m_activeTimeline->projectView()->slotDeleteAllGuides();
2699 }
2700
2701 void MainWindow::slotCutTimelineClip()
2702 {
2703     if (m_activeTimeline)
2704         m_activeTimeline->projectView()->cutSelectedClips();
2705 }
2706
2707 void MainWindow::slotInsertClipOverwrite()
2708 {
2709     if (m_activeTimeline) {
2710         QStringList data = m_clipMonitor->getZoneInfo();
2711         m_activeTimeline->projectView()->insertZoneOverwrite(data, m_activeTimeline->inPoint());
2712     }
2713 }
2714
2715 void MainWindow::slotSelectTimelineClip()
2716 {
2717     if (m_activeTimeline)
2718         m_activeTimeline->projectView()->selectClip(true);
2719 }
2720
2721 void MainWindow::slotSelectTimelineTransition()
2722 {
2723     if (m_activeTimeline)
2724         m_activeTimeline->projectView()->selectTransition(true);
2725 }
2726
2727 void MainWindow::slotDeselectTimelineClip()
2728 {
2729     if (m_activeTimeline)
2730         m_activeTimeline->projectView()->selectClip(false, true);
2731 }
2732
2733 void MainWindow::slotDeselectTimelineTransition()
2734 {
2735     if (m_activeTimeline)
2736         m_activeTimeline->projectView()->selectTransition(false, true);
2737 }
2738
2739 void MainWindow::slotSelectAddTimelineClip()
2740 {
2741     if (m_activeTimeline)
2742         m_activeTimeline->projectView()->selectClip(true, true);
2743 }
2744
2745 void MainWindow::slotSelectAddTimelineTransition()
2746 {
2747     if (m_activeTimeline)
2748         m_activeTimeline->projectView()->selectTransition(true, true);
2749 }
2750
2751 void MainWindow::slotGroupClips()
2752 {
2753     if (m_activeTimeline)
2754         m_activeTimeline->projectView()->groupClips();
2755 }
2756
2757 void MainWindow::slotUnGroupClips()
2758 {
2759     if (m_activeTimeline)
2760         m_activeTimeline->projectView()->groupClips(false);
2761 }
2762
2763 void MainWindow::slotEditItemDuration()
2764 {
2765     if (m_activeTimeline)
2766         m_activeTimeline->projectView()->editItemDuration();
2767 }
2768
2769 void MainWindow::slotAddProjectClip(KUrl url)
2770 {
2771     if (m_activeDocument)
2772         m_activeDocument->slotAddClipFile(url, QString());
2773 }
2774
2775 void MainWindow::slotAddTransition(QAction *result)
2776 {
2777     if (!result) return;
2778     QStringList info = result->data().toStringList();
2779     if (info.isEmpty()) return;
2780     QDomElement transition = transitions.getEffectByTag(info.at(1), info.at(2));
2781     if (m_activeTimeline && !transition.isNull()) {
2782         m_activeTimeline->projectView()->slotAddTransitionToSelectedClips(transition.cloneNode().toElement());
2783     }
2784 }
2785
2786 void MainWindow::slotAddVideoEffect(QAction *result)
2787 {
2788     if (!result) return;
2789     QStringList info = result->data().toStringList();
2790     if (info.isEmpty()) return;
2791     QDomElement effect = videoEffects.getEffectByTag(info.at(1), info.at(2));
2792     slotAddEffect(effect);
2793 }
2794
2795 void MainWindow::slotAddAudioEffect(QAction *result)
2796 {
2797     if (!result) return;
2798     QStringList info = result->data().toStringList();
2799     if (info.isEmpty()) return;
2800     QDomElement effect = audioEffects.getEffectByTag(info.at(1), info.at(2));
2801     slotAddEffect(effect);
2802 }
2803
2804 void MainWindow::slotAddCustomEffect(QAction *result)
2805 {
2806     if (!result) return;
2807     QStringList info = result->data().toStringList();
2808     if (info.isEmpty()) return;
2809     QDomElement effect = customEffects.getEffectByTag(info.at(1), info.at(2));
2810     slotAddEffect(effect);
2811 }
2812
2813 void MainWindow::slotZoomIn()
2814 {
2815     m_zoomSlider->setValue(m_zoomSlider->value() - 1);
2816     slotShowZoomSliderToolTip();
2817 }
2818
2819 void MainWindow::slotZoomOut()
2820 {
2821     m_zoomSlider->setValue(m_zoomSlider->value() + 1);
2822     slotShowZoomSliderToolTip();
2823 }
2824
2825 void MainWindow::slotFitZoom()
2826 {
2827     if (m_activeTimeline)
2828         m_zoomSlider->setValue(m_activeTimeline->fitZoom());
2829 }
2830
2831 void MainWindow::slotSetZoom(int value)
2832 {
2833     value = qMax(m_zoomSlider->minimum(), value);
2834     value = qMin(m_zoomSlider->maximum(), value);
2835
2836     if (m_activeTimeline)
2837         m_activeTimeline->slotChangeZoom(value);
2838
2839     m_zoomOut->setEnabled(value < m_zoomSlider->maximum());
2840     m_zoomIn->setEnabled(value > m_zoomSlider->minimum());
2841     slotUpdateZoomSliderToolTip(value);
2842
2843     m_zoomSlider->blockSignals(true);
2844     m_zoomSlider->setValue(value);
2845     m_zoomSlider->blockSignals(false);
2846 }
2847
2848 void MainWindow::slotShowZoomSliderToolTip(int zoomlevel)
2849 {
2850     if (zoomlevel != -1)
2851         slotUpdateZoomSliderToolTip(zoomlevel);
2852
2853     QPoint global = m_zoomSlider->rect().topLeft();
2854     global.ry() += m_zoomSlider->height() / 2;
2855     QHelpEvent toolTipEvent(QEvent::ToolTip, QPoint(0, 0), m_zoomSlider->mapToGlobal(global));
2856     QApplication::sendEvent(m_zoomSlider, &toolTipEvent);
2857 }
2858
2859 void MainWindow::slotUpdateZoomSliderToolTip(int zoomlevel)
2860 {
2861     m_zoomSlider->setToolTip(i18n("Zoom Level: %1/13", (13 - zoomlevel)));
2862 }
2863
2864 void MainWindow::slotGotProgressInfo(const QString &message, int progress)
2865 {
2866     m_statusProgressBar->setValue(progress);
2867     if (progress >= 0) {
2868         if (!message.isEmpty())
2869             m_messageLabel->setMessage(message, InformationMessage);//statusLabel->setText(message);
2870         m_statusProgressBar->setVisible(true);
2871     } else if (progress == -2) {
2872         if (!message.isEmpty())
2873             m_messageLabel->setMessage(message, ErrorMessage);
2874         m_statusProgressBar->setVisible(false);
2875     } else {
2876         m_messageLabel->setMessage(QString(), DefaultMessage);
2877         m_statusProgressBar->setVisible(false);
2878     }
2879 }
2880
2881 void MainWindow::slotShowClipProperties(DocClipBase *clip)
2882 {
2883     if (clip->clipType() == TEXT) {
2884         QString titlepath = m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
2885         if (!clip->getProperty("resource").isEmpty() && clip->getProperty("xmldata").isEmpty()) {
2886             // template text clip
2887
2888             // Get the list of existing templates
2889             QStringList filter;
2890             filter << "*.kdenlivetitle";
2891             QStringList templateFiles = QDir(titlepath).entryList(filter, QDir::Files);
2892
2893             QDialog *dia = new QDialog(this);
2894             Ui::TemplateClip_UI dia_ui;
2895             dia_ui.setupUi(dia);
2896             int ix = -1;
2897             const QString templatePath = clip->getProperty("resource");
2898             for (int i = 0; i < templateFiles.size(); ++i) {
2899                 dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), titlepath + templateFiles.at(i));
2900                 if (templatePath == KUrl(titlepath + templateFiles.at(i)).path()) ix = i;
2901             }
2902             if (ix != -1) dia_ui.template_list->comboBox()->setCurrentIndex(ix);
2903             else dia_ui.template_list->comboBox()->insertItem(0, templatePath);
2904             dia_ui.template_list->fileDialog()->setFilter("*.kdenlivetitle");
2905             //warning: setting base directory doesn't work??
2906             KUrl startDir(titlepath);
2907             dia_ui.template_list->fileDialog()->setUrl(startDir);
2908             dia_ui.description->setText(clip->getProperty("description"));
2909             if (dia->exec() == QDialog::Accepted) {
2910                 QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
2911                 if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
2912
2913                 QMap <QString, QString> newprops;
2914
2915                 if (KUrl(textTemplate).path() != templatePath) {
2916                     // The template was changed
2917                     newprops.insert("resource", textTemplate);
2918                 }
2919
2920                 if (dia_ui.description->toPlainText() != clip->getProperty("description")) {
2921                     newprops.insert("description", dia_ui.description->toPlainText());
2922                 }
2923
2924                 QString newtemplate = newprops.value("xmltemplate");
2925                 if (newtemplate.isEmpty()) newtemplate = templatePath;
2926
2927                 // template modified we need to update xmldata
2928                 QString description = newprops.value("description");
2929                 if (description.isEmpty()) description = clip->getProperty("description");
2930                 else newprops.insert("templatetext", description);
2931                 //newprops.insert("xmldata", m_projectList->generateTemplateXml(newtemplate, description).toString());
2932                 if (!newprops.isEmpty()) {
2933                     EditClipCommand *command = new EditClipCommand(m_projectList, clip->getId(), clip->properties(), newprops, true);
2934                     m_activeDocument->commandStack()->push(command);
2935                 }
2936             }
2937             delete dia;
2938             return;
2939         }
2940         QString path = clip->getProperty("resource");
2941         TitleWidget *dia_ui = new TitleWidget(KUrl(), m_activeDocument->timecode(), titlepath, m_projectMonitor->render, this);
2942         QDomDocument doc;
2943         doc.setContent(clip->getProperty("xmldata"));
2944         dia_ui->setXml(doc);
2945         if (dia_ui->exec() == QDialog::Accepted) {
2946             QMap <QString, QString> newprops;
2947             newprops.insert("xmldata", dia_ui->xml().toString());
2948             if (dia_ui->outPoint() != clip->duration().frames(m_activeDocument->fps()) - 1) {
2949                 // duration changed, we need to update duration
2950                 newprops.insert("out", QString::number(dia_ui->outPoint()));
2951             }
2952             EditClipCommand *command = new EditClipCommand(m_projectList, clip->getId(), clip->properties(), newprops, true);
2953             m_activeDocument->commandStack()->push(command);
2954             //m_activeTimeline->projectView()->slotUpdateClip(clip->getId());
2955             m_activeDocument->setModified(true);
2956         }
2957         delete dia_ui;
2958
2959         //m_activeDocument->editTextClip(clip->getProperty("xml"), clip->getId());
2960         return;
2961     }
2962
2963     // any type of clip but a title
2964     ClipProperties dia(clip, m_activeDocument->timecode(), m_activeDocument->fps(), this);
2965     connect(&dia, SIGNAL(addMarker(const QString &, GenTime, QString)), m_activeTimeline->projectView(), SLOT(slotAddClipMarker(const QString &, GenTime, QString)));
2966     if (dia.exec() == QDialog::Accepted) {
2967         QMap <QString, QString> newprops = dia.properties();
2968         if (newprops.isEmpty()) return;
2969         EditClipCommand *command = new EditClipCommand(m_projectList, clip->getId(), clip->properties(), newprops, true);
2970         m_activeDocument->commandStack()->push(command);
2971         m_activeDocument->setModified();
2972
2973         if (dia.needsTimelineRefresh()) {
2974             // update clip occurences in timeline
2975             m_activeTimeline->projectView()->slotUpdateClip(clip->getId(), dia.needsTimelineReload());
2976         }
2977     }
2978 }
2979
2980
2981 void MainWindow::slotShowClipProperties(QList <DocClipBase *> cliplist, QMap<QString, QString> commonproperties)
2982 {
2983     ClipProperties dia(cliplist, m_activeDocument->timecode(), commonproperties, this);
2984     if (dia.exec() == QDialog::Accepted) {
2985         QUndoCommand *command = new QUndoCommand();
2986         command->setText(i18n("Edit clips"));
2987         for (int i = 0; i < cliplist.count(); i++) {
2988             DocClipBase *clip = cliplist.at(i);
2989             new EditClipCommand(m_projectList, clip->getId(), clip->properties(), dia.properties(), true, command);
2990         }
2991         m_activeDocument->commandStack()->push(command);
2992         for (int i = 0; i < cliplist.count(); i++)
2993             m_activeTimeline->projectView()->slotUpdateClip(cliplist.at(i)->getId(), dia.needsTimelineReload());
2994     }
2995 }
2996
2997 void MainWindow::customEvent(QEvent* e)
2998 {
2999     if (e->type() == QEvent::User)
3000         m_messageLabel->setMessage(static_cast <MltErrorEvent *>(e)->message(), MltError);
3001 }
3002 void MainWindow::slotActivateEffectStackView()
3003 {
3004     m_effectStack->raiseWindow(m_effectStackDock);
3005 }
3006
3007 void MainWindow::slotActivateTransitionView(Transition *t)
3008 {
3009     if (t)
3010         m_transitionConfig->raiseWindow(m_transitionConfigDock);
3011 }
3012
3013 void MainWindow::slotSnapRewind()
3014 {
3015     if (m_projectMonitor->isActive()) {
3016         if (m_activeTimeline)
3017             m_activeTimeline->projectView()->slotSeekToPreviousSnap();
3018     } else  {
3019         m_clipMonitor->slotSeekToPreviousSnap();
3020     }
3021 }
3022
3023 void MainWindow::slotSnapForward()
3024 {
3025     if (m_projectMonitor->isActive()) {
3026         if (m_activeTimeline)
3027             m_activeTimeline->projectView()->slotSeekToNextSnap();
3028     } else {
3029         m_clipMonitor->slotSeekToNextSnap();
3030     }
3031 }
3032
3033 void MainWindow::slotClipStart()
3034 {
3035     if (m_projectMonitor->isActive()) {
3036         if (m_activeTimeline)
3037             m_activeTimeline->projectView()->clipStart();
3038     }
3039 }
3040
3041 void MainWindow::slotClipEnd()
3042 {
3043     if (m_projectMonitor->isActive()) {
3044         if (m_activeTimeline)
3045             m_activeTimeline->projectView()->clipEnd();
3046     }
3047 }
3048
3049 void MainWindow::slotZoneStart()
3050 {
3051     if (m_projectMonitor->isActive())
3052         m_projectMonitor->slotZoneStart();
3053     else
3054         m_clipMonitor->slotZoneStart();
3055 }
3056
3057 void MainWindow::slotZoneEnd()
3058 {
3059     if (m_projectMonitor->isActive())
3060         m_projectMonitor->slotZoneEnd();
3061     else
3062         m_clipMonitor->slotZoneEnd();
3063 }
3064
3065 void MainWindow::slotChangeTool(QAction * action)
3066 {
3067     if (action == m_buttonSelectTool)
3068         slotSetTool(SELECTTOOL);
3069     else if (action == m_buttonRazorTool)
3070         slotSetTool(RAZORTOOL);
3071     else if (action == m_buttonSpacerTool)
3072         slotSetTool(SPACERTOOL);
3073 }
3074
3075 void MainWindow::slotChangeEdit(QAction * action)
3076 {
3077     if (!m_activeTimeline)
3078         return;
3079
3080     if (action == m_overwriteEditTool)
3081         m_activeTimeline->projectView()->setEditMode(OVERWRITEEDIT);
3082     else if (action == m_insertEditTool)
3083         m_activeTimeline->projectView()->setEditMode(INSERTEDIT);
3084     else
3085         m_activeTimeline->projectView()->setEditMode(NORMALEDIT);
3086 }
3087
3088 void MainWindow::slotSetTool(PROJECTTOOL tool)
3089 {
3090     if (m_activeDocument && m_activeTimeline) {
3091         //m_activeDocument->setTool(tool);
3092         QString message;
3093         switch (tool)  {
3094         case SPACERTOOL:
3095             message = i18n("Ctrl + click to use spacer on current track only");
3096             break;
3097         case RAZORTOOL:
3098             message = i18n("Click on a clip to cut it");
3099             break;
3100         default:
3101             message = i18n("Shift + click to create a selection rectangle, Ctrl + click to add an item to selection");
3102             break;
3103         }
3104         m_messageLabel->setMessage(message, InformationMessage);
3105         m_activeTimeline->projectView()->setTool(tool);
3106     }
3107 }
3108
3109 void MainWindow::slotCopy()
3110 {
3111     if (m_activeDocument && m_activeTimeline)
3112         m_activeTimeline->projectView()->copyClip();
3113 }
3114
3115 void MainWindow::slotPaste()
3116 {
3117     if (m_activeDocument && m_activeTimeline)
3118         m_activeTimeline->projectView()->pasteClip();
3119 }
3120
3121 void MainWindow::slotPasteEffects()
3122 {
3123     if (m_activeDocument && m_activeTimeline)
3124         m_activeTimeline->projectView()->pasteClipEffects();
3125 }
3126
3127 void MainWindow::slotFind()
3128 {
3129     if (!m_activeDocument || !m_activeTimeline) return;
3130     m_projectSearch->setEnabled(false);
3131     m_findActivated = true;
3132     m_findString.clear();
3133     m_activeTimeline->projectView()->initSearchStrings();
3134     statusBar()->showMessage(i18n("Starting -- find text as you type"));
3135     m_findTimer.start(5000);
3136     qApp->installEventFilter(this);
3137 }
3138
3139 void MainWindow::slotFindNext()
3140 {
3141     if (m_activeTimeline && m_activeTimeline->projectView()->findNextString(m_findString))
3142         statusBar()->showMessage(i18n("Found: %1", m_findString));
3143     else
3144         statusBar()->showMessage(i18n("Reached end of project"));
3145     m_findTimer.start(4000);
3146 }
3147
3148 void MainWindow::findAhead()
3149 {
3150     if (m_activeTimeline && m_activeTimeline->projectView()->findString(m_findString)) {
3151         m_projectSearchNext->setEnabled(true);
3152         statusBar()->showMessage(i18n("Found: %1", m_findString));
3153     } else {
3154         m_projectSearchNext->setEnabled(false);
3155         statusBar()->showMessage(i18n("Not found: %1", m_findString));
3156     }
3157 }
3158
3159 void MainWindow::findTimeout()
3160 {
3161     m_projectSearchNext->setEnabled(false);
3162     m_findActivated = false;
3163     m_findString.clear();
3164     statusBar()->showMessage(i18n("Find stopped"), 3000);
3165     if (m_activeTimeline) m_activeTimeline->projectView()->clearSearchStrings();
3166     m_projectSearch->setEnabled(true);
3167     removeEventFilter(this);
3168 }
3169
3170 void MainWindow::slotClipInTimeline(const QString &clipId)
3171 {
3172     if (m_activeTimeline && m_activeDocument) {
3173         QList<ItemInfo> matching = m_activeTimeline->projectView()->findId(clipId);
3174
3175         QMenu *inTimelineMenu = static_cast<QMenu*>(factory()->container("clip_in_timeline", this));
3176         inTimelineMenu->clear();
3177
3178         QList <QAction *> actionList;
3179
3180         for (int i = 0; i < matching.count(); ++i) {
3181             QString track = QString::number(matching.at(i).track);
3182             QString start = m_activeDocument->timecode().getTimecode(matching.at(i).startPos);
3183             int j = 0;
3184             QAction *a = new QAction(track + ": " + start, this);
3185             a->setData(QStringList() << track << start);
3186             connect(a, SIGNAL(triggered()), this, SLOT(slotSelectClipInTimeline()));
3187             while (j < actionList.count()) {
3188                 if (actionList.at(j)->text() > a->text()) break;
3189                 j++;
3190             }
3191             actionList.insert(j, a);
3192         }
3193         inTimelineMenu->addActions(actionList);
3194
3195         if (matching.empty())
3196             inTimelineMenu->setEnabled(false);
3197         else
3198             inTimelineMenu->setEnabled(true);
3199     }
3200 }
3201
3202 void MainWindow::slotClipInProjectTree()
3203 {
3204     if (m_activeTimeline) {
3205         const QStringList &clipIds = m_activeTimeline->projectView()->selectedClips();
3206         if (clipIds.isEmpty())
3207             return;
3208         m_projectListDock->raise();
3209         for (int i = 0; i < clipIds.count(); i++)
3210             m_projectList->selectItemById(clipIds.at(i));
3211         if (m_projectMonitor->isActive())
3212             slotSwitchMonitors();
3213     }
3214 }
3215
3216 /*void MainWindow::slotClipToProjectTree()
3217 {
3218     if (m_activeTimeline) {
3219     const QList<ClipItem *> clips =  m_activeTimeline->projectView()->selectedClipItems();
3220         if (clips.isEmpty()) return;
3221         for (int i = 0; i < clips.count(); i++) {
3222         m_projectList->slotAddXmlClip(clips.at(i)->itemXml());
3223         }
3224         //m_projectList->selectItemById(clipIds.at(i));
3225     }
3226 }*/
3227
3228 void MainWindow::slotSelectClipInTimeline()
3229 {
3230     if (m_activeTimeline) {
3231         QAction *action = qobject_cast<QAction *>(sender());
3232         QStringList data = action->data().toStringList();
3233         m_activeTimeline->projectView()->selectFound(data.at(0), data.at(1));
3234     }
3235 }
3236
3237 void MainWindow::keyPressEvent(QKeyEvent *ke)
3238 {
3239     if (m_findActivated) {
3240         if (ke->key() == Qt::Key_Backspace) {
3241             m_findString = m_findString.left(m_findString.length() - 1);
3242
3243             if (!m_findString.isEmpty())
3244                 findAhead();
3245             else
3246                 findTimeout();
3247
3248             m_findTimer.start(4000);
3249             ke->accept();
3250             return;
3251         } else if (ke->key() == Qt::Key_Escape) {
3252             findTimeout();
3253             ke->accept();
3254             return;
3255         } else if (ke->key() == Qt::Key_Space || !ke->text().trimmed().isEmpty()) {
3256             m_findString += ke->text();
3257
3258             findAhead();
3259
3260             m_findTimer.start(4000);
3261             ke->accept();
3262             return;
3263         }
3264     } else {
3265         KXmlGuiWindow::keyPressEvent(ke);
3266     }
3267 }
3268
3269
3270 /** Gets called when the window gets hidden */
3271 void MainWindow::hideEvent(QHideEvent */*event*/)
3272 {
3273     if (isMinimized() && m_monitorManager)
3274         m_monitorManager->stopActiveMonitor();
3275 }
3276
3277 bool MainWindow::eventFilter(QObject *obj, QEvent *event)
3278 {
3279     if (m_findActivated) {
3280         if (event->type() == QEvent::ShortcutOverride) {
3281             QKeyEvent* ke = (QKeyEvent*) event;
3282             if (ke->text().trimmed().isEmpty()) return false;
3283             ke->accept();
3284             return true;
3285         } else {
3286             return false;
3287         }
3288     } else {
3289         // pass the event on to the parent class
3290         return QMainWindow::eventFilter(obj, event);
3291     }
3292 }
3293
3294
3295 void MainWindow::slotSaveZone(Render *render, QPoint zone)
3296 {
3297     KDialog *dialog = new KDialog(this);
3298     dialog->setCaption("Save clip zone");
3299     dialog->setButtons(KDialog::Ok | KDialog::Cancel);
3300
3301     QWidget *widget = new QWidget(dialog);
3302     dialog->setMainWidget(widget);
3303
3304     QVBoxLayout *vbox = new QVBoxLayout(widget);
3305     QLabel *label1 = new QLabel(i18n("Save clip zone as:"), this);
3306     QString path = m_activeDocument->projectFolder().path();
3307     path.append("/");
3308     path.append("untitled.mlt");
3309     KUrlRequester *url = new KUrlRequester(KUrl(path), this);
3310     url->setFilter("video/mlt-playlist");
3311     QLabel *label2 = new QLabel(i18n("Description:"), this);
3312     KLineEdit *edit = new KLineEdit(this);
3313     vbox->addWidget(label1);
3314     vbox->addWidget(url);
3315     vbox->addWidget(label2);
3316     vbox->addWidget(edit);
3317     if (dialog->exec() == QDialog::Accepted)
3318         render->saveZone(url->url(), edit->text(), zone);
3319
3320 }
3321
3322 void MainWindow::slotSetInPoint()
3323 {
3324     if (m_clipMonitor->isActive())
3325         m_clipMonitor->slotSetZoneStart();
3326     else
3327         m_projectMonitor->slotSetZoneStart();
3328     //else m_activeTimeline->projectView()->setInPoint();
3329 }
3330
3331 void MainWindow::slotSetOutPoint()
3332 {
3333     if (m_clipMonitor->isActive())
3334         m_clipMonitor->slotSetZoneEnd();
3335     else
3336         m_projectMonitor->slotSetZoneEnd();
3337     // else m_activeTimeline->projectView()->setOutPoint();
3338 }
3339
3340 void MainWindow::slotResizeItemStart()
3341 {
3342     if (m_activeTimeline)
3343         m_activeTimeline->projectView()->setInPoint();
3344 }
3345
3346 void MainWindow::slotResizeItemEnd()
3347 {
3348     if (m_activeTimeline)
3349         m_activeTimeline->projectView()->setOutPoint();
3350 }
3351
3352 int MainWindow::getNewStuff(const QString &configFile)
3353 {
3354     KNS3::Entry::List entries;
3355 #if KDE_IS_VERSION(4,3,80)
3356     KNS3::DownloadDialog dialog(configFile);
3357     dialog.exec();
3358     entries = dialog.changedEntries();
3359     foreach(const KNS3::Entry & entry, entries) {
3360         if (entry.status() == KNS3::Entry::Installed)
3361             kDebug() << "// Installed files: " << entry.installedFiles();
3362     }
3363 #else
3364     KNS::Engine engine(0);
3365     if (engine.init(configFile))
3366         entries = engine.downloadDialogModal(this);
3367     foreach(KNS::Entry * entry, entries) {
3368         if (entry->status() == KNS::Entry::Installed)
3369             kDebug() << "// Installed files: " << entry->installedFiles();
3370     }
3371 #endif /* KDE_IS_VERSION(4,3,80) */
3372     return entries.size();
3373 }
3374
3375 void MainWindow::slotGetNewTitleStuff()
3376 {
3377     if (getNewStuff("kdenlive_titles.knsrc") > 0)
3378         TitleWidget::refreshTitleTemplates();
3379 }
3380
3381 void MainWindow::slotGetNewLumaStuff()
3382 {
3383     if (getNewStuff("kdenlive_wipes.knsrc") > 0) {
3384         initEffects::refreshLumas();
3385         m_activeTimeline->projectView()->reloadTransitionLumas();
3386     }
3387 }
3388
3389 void MainWindow::slotGetNewRenderStuff()
3390 {
3391     if (getNewStuff("kdenlive_renderprofiles.knsrc") > 0)
3392         if (m_renderWidget)
3393             m_renderWidget->reloadProfiles();
3394 }
3395
3396 void MainWindow::slotGetNewMltProfileStuff()
3397 {
3398     if (getNewStuff("kdenlive_projectprofiles.knsrc") > 0) {
3399         // update the list of profiles in settings dialog
3400         KdenliveSettingsDialog* d = static_cast <KdenliveSettingsDialog*>(KConfigDialog::exists("settings"));
3401         if (d)
3402             d->checkProfile();
3403     }
3404 }
3405
3406 void MainWindow::slotAutoTransition()
3407 {
3408     if (m_activeTimeline)
3409         m_activeTimeline->projectView()->autoTransition();
3410 }
3411
3412 void MainWindow::slotSplitAudio()
3413 {
3414     if (m_activeTimeline)
3415         m_activeTimeline->projectView()->splitAudio();
3416 }
3417
3418 void MainWindow::slotUpdateClipType(QAction *action)
3419 {
3420     if (m_activeTimeline) {
3421         if (action->data().toString() == "clip_audio_only") m_activeTimeline->projectView()->setAudioOnly();
3422         else if (action->data().toString() == "clip_video_only") m_activeTimeline->projectView()->setVideoOnly();
3423         else m_activeTimeline->projectView()->setAudioAndVideo();
3424     }
3425 }
3426
3427 void MainWindow::slotDvdWizard(const QString &url, const QString &profile)
3428 {
3429     // We must stop the monitors since we create a new on in the dvd wizard
3430     m_clipMonitor->stop();
3431     m_projectMonitor->stop();
3432     DvdWizard w(url, profile, this);
3433     w.exec();
3434     m_projectMonitor->start();
3435 }
3436
3437 void MainWindow::slotShowTimeline(bool show)
3438 {
3439     if (show == false) {
3440         m_timelineState = saveState();
3441         centralWidget()->setHidden(true);
3442     } else {
3443         centralWidget()->setHidden(false);
3444         restoreState(m_timelineState);
3445     }
3446 }
3447
3448 void MainWindow::slotMaximizeCurrent(bool /*show*/)
3449 {
3450     //TODO: is there a way to maximize current widget?
3451     //if (show == true)
3452     {
3453         m_timelineState = saveState();
3454         QWidget *par = focusWidget()->parentWidget();
3455         while (par->parentWidget() && par->parentWidget() != this)
3456             par = par->parentWidget();
3457         kDebug() << "CURRENT WIDGET: " << par->objectName();
3458     }
3459     /*else {
3460     //centralWidget()->setHidden(false);
3461     //restoreState(m_timelineState);
3462     }*/
3463 }
3464
3465 void MainWindow::loadTranscoders()
3466 {
3467     QMenu *transMenu = static_cast<QMenu*>(factory()->container("transcoders", this));
3468     transMenu->clear();
3469
3470     KSharedConfigPtr config = KSharedConfig::openConfig("kdenlivetranscodingrc");
3471     KConfigGroup transConfig(config, "Transcoding");
3472     // read the entries
3473     QMap< QString, QString > profiles = transConfig.entryMap();
3474     QMapIterator<QString, QString> i(profiles);
3475     while (i.hasNext()) {
3476         i.next();
3477         QStringList data = i.value().split(";", QString::SkipEmptyParts);
3478         QAction *a = transMenu->addAction(i.key());
3479         a->setData(data);
3480         if (data.count() > 1)
3481             a->setToolTip(data.at(1));
3482         connect(a, SIGNAL(triggered()), this, SLOT(slotTranscode()));
3483     }
3484 }
3485
3486 void MainWindow::slotTranscode(KUrl::List urls)
3487 {
3488     QString params;
3489     QString desc;
3490     QString condition;
3491     if (urls.isEmpty()) {
3492         QAction *action = qobject_cast<QAction *>(sender());
3493         QStringList data = action->data().toStringList();
3494         params = data.at(0);
3495         if (data.count() > 1) desc = data.at(1);
3496         if (data.count() > 2) condition = data.at(2);
3497         urls << m_projectList->getConditionalUrls(condition);
3498         urls.removeAll(KUrl());
3499     }
3500     if (urls.isEmpty()) {
3501         m_messageLabel->setMessage(i18n("No clip to transcode"), ErrorMessage);
3502         return;
3503     }
3504     ClipTranscode *d = new ClipTranscode(urls, params, desc);
3505     connect(d, SIGNAL(addClip(KUrl)), this, SLOT(slotAddProjectClip(KUrl)));
3506     d->show();
3507     //QProcess::startDetached("ffmpeg", parameters);
3508 }
3509
3510 void MainWindow::slotTranscodeClip()
3511 {
3512     KUrl::List urls = KFileDialog::getOpenUrls(KUrl("kfiledialog:///projectfolder"));
3513     if (urls.isEmpty()) return;
3514     slotTranscode(urls);
3515 }
3516
3517 void MainWindow::slotSetDocumentRenderProfile(QMap <QString, QString> props)
3518 {
3519     if (m_activeDocument == NULL) return;
3520     QMapIterator<QString, QString> i(props);
3521     while (i.hasNext()) {
3522         i.next();
3523         m_activeDocument->setDocumentProperty(i.key(), i.value());
3524     }
3525     m_activeDocument->setModified(true);
3526 }
3527
3528
3529 void MainWindow::slotPrepareRendering(bool scriptExport, bool zoneOnly, const QString &chapterFile)
3530 {
3531     if (m_activeDocument == NULL || m_renderWidget == NULL) return;
3532     QString scriptPath;
3533     QString playlistPath;
3534     if (scriptExport) {
3535         bool ok;
3536         QString scriptsFolder = m_activeDocument->projectFolder().path() + "/scripts/";
3537         QString path = m_renderWidget->getFreeScriptName();
3538         scriptPath = QInputDialog::getText(this, i18n("Create Render Script"), i18n("Script name (will be saved in: %1)", scriptsFolder), QLineEdit::Normal, KUrl(path).fileName(), &ok);
3539         if (!ok || scriptPath.isEmpty()) return;
3540         scriptPath.prepend(scriptsFolder);
3541         QFile f(scriptPath);
3542         if (f.exists()) {
3543             if (KMessageBox::warningYesNo(this, i18n("Script file already exists. Do you want to overwrite it?")) != KMessageBox::Yes)
3544                 return;
3545         }
3546         playlistPath = scriptPath + ".mlt";
3547         m_projectMonitor->saveSceneList(playlistPath);
3548     } else {
3549         KTemporaryFile temp;
3550         temp.setAutoRemove(false);
3551         temp.setSuffix(".mlt");
3552         temp.open();
3553         playlistPath = temp.fileName();
3554         m_projectMonitor->saveSceneList(playlistPath);
3555     }
3556
3557     if (!chapterFile.isEmpty()) {
3558         int in = 0;
3559         int out;
3560         if (!zoneOnly) out = (int) GenTime(m_activeDocument->projectDuration()).frames(m_activeDocument->fps());
3561         else {
3562             in = m_activeTimeline->inPoint();
3563             out = m_activeTimeline->outPoint();
3564         }
3565         QDomDocument doc;
3566         QDomElement chapters = doc.createElement("chapters");
3567         chapters.setAttribute("fps", m_activeDocument->fps());
3568         doc.appendChild(chapters);
3569
3570         QDomElement guidesxml = m_activeDocument->guidesXml();
3571         QDomNodeList nodes = guidesxml.elementsByTagName("guide");
3572         for (int i = 0; i < nodes.count(); i++) {
3573             QDomElement e = nodes.item(i).toElement();
3574             if (!e.isNull()) {
3575                 QString comment = e.attribute("comment");
3576                 int time = (int) GenTime(e.attribute("time").toDouble()).frames(m_activeDocument->fps());
3577                 if (time >= in && time < out) {
3578                     if (zoneOnly) time = time - in;
3579                     QDomElement chapter = doc.createElement("chapter");
3580                     chapters.appendChild(chapter);
3581                     chapter.setAttribute("title", comment);
3582                     chapter.setAttribute("time", time);
3583                 }
3584             }
3585         }
3586         if (chapters.childNodes().count() > 0) {
3587             if (m_activeTimeline->projectView()->hasGuide(out, 0) == -1) {
3588                 // Always insert a guide in pos 0
3589                 QDomElement chapter = doc.createElement("chapter");
3590                 chapters.insertBefore(chapter, QDomNode());
3591                 chapter.setAttribute("title", i18n("Start"));
3592                 chapter.setAttribute("time", "0");
3593             }
3594             // save chapters file
3595             QFile file(chapterFile);
3596             if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
3597                 kWarning() << "//////  ERROR writing DVD CHAPTER file: " << chapterFile;
3598             } else {
3599                 file.write(doc.toString().toUtf8());
3600                 if (file.error() != QFile::NoError) {
3601                     kWarning() << "//////  ERROR writing DVD CHAPTER file: " << chapterFile;
3602                 }
3603                 file.close();
3604             }
3605         }
3606     }
3607     bool exportAudio;
3608     if (m_renderWidget->automaticAudioExport()) {
3609         exportAudio = m_activeTimeline->checkProjectAudio();
3610     } else exportAudio = m_renderWidget->selectedAudioExport();
3611     m_renderWidget->slotExport(scriptExport, m_activeTimeline->inPoint(), m_activeTimeline->outPoint(), playlistPath, scriptPath, exportAudio);
3612 }
3613
3614 void MainWindow::slotUpdateTimecodeFormat(int ix)
3615 {
3616     KdenliveSettings::setFrametimecode(ix == 1);
3617     m_clipMonitor->updateTimecodeFormat();
3618     m_projectMonitor->updateTimecodeFormat();
3619     m_transitionConfig->updateTimecodeFormat();
3620     m_effectStack->updateTimecodeFormat();
3621     //m_activeTimeline->projectView()->clearSelection();
3622     m_activeTimeline->updateRuler();
3623 }
3624
3625 void MainWindow::slotRemoveFocus()
3626 {
3627     statusBar()->setFocus();
3628     statusBar()->clearFocus();
3629 }
3630
3631 void MainWindow::slotRevert()
3632 {
3633     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;
3634     KUrl url = m_activeDocument->url();
3635     if (closeCurrentDocument(false))
3636         doOpenFile(url, NULL);
3637 }
3638
3639
3640 void MainWindow::slotShutdown()
3641 {
3642     if (m_activeDocument) m_activeDocument->setModified(false);
3643     // Call shutdown
3644     QDBusConnectionInterface* interface = QDBusConnection::sessionBus().interface();
3645     if (interface && interface->isServiceRegistered("org.kde.ksmserver")) {
3646         QDBusInterface smserver("org.kde.ksmserver", "/KSMServer", "org.kde.KSMServerInterface");
3647         smserver.call("logout", 1, 2, 2);
3648     } else if (interface && interface->isServiceRegistered("org.gnome.SessionManager")) {
3649         QDBusInterface smserver("org.gnome.SessionManager", "/org/gnome/SessionManager", "org.gnome.SessionManager");
3650         smserver.call("Shutdown");
3651     }
3652 }
3653
3654 void MainWindow::slotUpdateTrackInfo()
3655 {
3656     if (m_activeDocument)
3657         m_transitionConfig->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode(), m_activeDocument->tracksList());
3658 }
3659
3660 void MainWindow::slotChangePalette(QAction *action, const QString &themename)
3661 {
3662     // Load the theme file
3663     QString theme;
3664     if (action == NULL) theme = themename;
3665     else theme = action->data().toString();
3666     KdenliveSettings::setColortheme(theme);
3667     // Make palette for all widgets.
3668     QPalette plt;
3669     if (theme.isEmpty())
3670         plt = QApplication::desktop()->palette();
3671     else {
3672         KSharedConfigPtr config = KSharedConfig::openConfig(theme);
3673         plt = KGlobalSettings::createApplicationPalette(config);
3674     }
3675
3676     kapp->setPalette(plt);
3677     const QObjectList children = statusBar()->children();
3678
3679     foreach(QObject * child, children) {
3680         if (child->isWidgetType())
3681             ((QWidget*)child)->setPalette(plt);
3682         const QObjectList subchildren = child->children();
3683         foreach(QObject * subchild, subchildren) {
3684             if (subchild->isWidgetType())
3685                 ((QWidget*)subchild)->setPalette(plt);
3686         }
3687     }
3688     if (m_activeTimeline) {
3689         m_activeTimeline->projectView()->updatePalette();
3690     }
3691 }
3692
3693
3694 QPixmap MainWindow::createSchemePreviewIcon(const KSharedConfigPtr &config)
3695 {
3696     // code taken from kdebase/workspace/kcontrol/colors/colorscm.cpp
3697     const uchar bits1[] = { 0xff, 0xff, 0xff, 0x2c, 0x16, 0x0b };
3698     const uchar bits2[] = { 0x68, 0x34, 0x1a, 0xff, 0xff, 0xff };
3699     const QSize bitsSize(24, 2);
3700     const QBitmap b1 = QBitmap::fromData(bitsSize, bits1);
3701     const QBitmap b2 = QBitmap::fromData(bitsSize, bits2);
3702
3703     QPixmap pixmap(23, 16);
3704     pixmap.fill(Qt::black); // ### use some color other than black for borders?
3705
3706     KConfigGroup group(config, "WM");
3707     QPainter p(&pixmap);
3708     KColorScheme windowScheme(QPalette::Active, KColorScheme::Window, config);
3709     p.fillRect(1,  1, 7, 7, windowScheme.background());
3710     p.fillRect(2,  2, 5, 2, QBrush(windowScheme.foreground().color(), b1));
3711
3712     KColorScheme buttonScheme(QPalette::Active, KColorScheme::Button, config);
3713     p.fillRect(8,  1, 7, 7, buttonScheme.background());
3714     p.fillRect(9,  2, 5, 2, QBrush(buttonScheme.foreground().color(), b1));
3715
3716     p.fillRect(15,  1, 7, 7, group.readEntry("activeBackground", QColor(96, 148, 207)));
3717     p.fillRect(16,  2, 5, 2, QBrush(group.readEntry("activeForeground", QColor(255, 255, 255)), b1));
3718
3719     KColorScheme viewScheme(QPalette::Active, KColorScheme::View, config);
3720     p.fillRect(1,  8, 7, 7, viewScheme.background());
3721     p.fillRect(2, 12, 5, 2, QBrush(viewScheme.foreground().color(), b2));
3722
3723     KColorScheme selectionScheme(QPalette::Active, KColorScheme::Selection, config);
3724     p.fillRect(8,  8, 7, 7, selectionScheme.background());
3725     p.fillRect(9, 12, 5, 2, QBrush(selectionScheme.foreground().color(), b2));
3726
3727     p.fillRect(15,  8, 7, 7, group.readEntry("inactiveBackground", QColor(224, 223, 222)));
3728     p.fillRect(16, 12, 5, 2, QBrush(group.readEntry("inactiveForeground", QColor(20, 19, 18)), b2));
3729
3730     p.end();
3731     return pixmap;
3732 }
3733
3734 void MainWindow::slotSwitchMonitors()
3735 {
3736     m_monitorManager->slotSwitchMonitors(!m_clipMonitor->isActive());
3737     if (m_projectMonitor->isActive()) m_activeTimeline->projectView()->setFocus();
3738     else m_projectList->focusTree();
3739 }
3740
3741 void MainWindow::slotInsertZoneToTree()
3742 {
3743     if (!m_clipMonitor->isActive() || m_clipMonitor->activeClip() == NULL) return;
3744     QStringList info = m_clipMonitor->getZoneInfo();
3745     m_projectList->slotAddClipCut(info.at(0), info.at(1).toInt(), info.at(2).toInt());
3746 }
3747
3748 void MainWindow::slotInsertZoneToTimeline()
3749 {
3750     if (m_activeTimeline == NULL || m_clipMonitor->activeClip() == NULL) return;
3751     QStringList info = m_clipMonitor->getZoneInfo();
3752     m_activeTimeline->projectView()->insertClipCut(m_clipMonitor->activeClip(), info.at(1).toInt(), info.at(2).toInt());
3753 }
3754
3755
3756 void MainWindow::slotDeleteProjectClips(QStringList ids, QMap<QString, QString> folderids)
3757 {
3758     if (m_activeDocument && m_activeTimeline) {
3759         if (!ids.isEmpty()) {
3760             for (int i = 0; i < ids.size(); ++i) {
3761                 m_activeTimeline->slotDeleteClip(ids.at(i));
3762             }
3763             m_activeDocument->clipManager()->slotDeleteClips(ids);
3764         }
3765         if (!folderids.isEmpty()) m_projectList->deleteProjectFolder(folderids);
3766         m_activeDocument->setModified(true);
3767     }
3768 }
3769
3770 void MainWindow::slotShowTitleBars(bool show)
3771 {
3772     if (show) {
3773         m_effectStackDock->setTitleBarWidget(0);
3774         m_clipMonitorDock->setTitleBarWidget(0);
3775         m_projectMonitorDock->setTitleBarWidget(0);
3776 #ifndef Q_WS_MAC
3777         m_recMonitorDock->setTitleBarWidget(0);
3778 #endif
3779         m_effectListDock->setTitleBarWidget(0);
3780         m_transitionConfigDock->setTitleBarWidget(0);
3781         m_projectListDock->setTitleBarWidget(0);
3782         m_undoViewDock->setTitleBarWidget(0);
3783         m_vectorscopeDock->setTitleBarWidget(0);
3784         m_waveformDock->setTitleBarWidget(0);
3785         m_RGBParadeDock->setTitleBarWidget(0);
3786         m_histogramDock->setTitleBarWidget(0);
3787     } else {
3788         if (!m_effectStackDock->isFloating()) {
3789             m_effectStackDock->setTitleBarWidget(new QWidget);
3790         }
3791         if (!m_clipMonitorDock->isFloating()) {
3792             m_clipMonitorDock->setTitleBarWidget(new QWidget);
3793         }
3794         if (!m_projectMonitorDock->isFloating()) {
3795             m_projectMonitorDock->setTitleBarWidget(new QWidget);
3796         }
3797 #ifndef Q_WS_MAC
3798         if (!m_recMonitorDock->isFloating()) {
3799             m_recMonitorDock->setTitleBarWidget(new QWidget);
3800         }
3801 #endif
3802         if (!m_effectListDock->isFloating()) {
3803             m_effectListDock->setTitleBarWidget(new QWidget);
3804         }
3805         if (!m_transitionConfigDock->isFloating()) {
3806             m_transitionConfigDock->setTitleBarWidget(new QWidget);
3807         }
3808         if (!m_projectListDock->isFloating()) {
3809             m_projectListDock->setTitleBarWidget(new QWidget);
3810         }
3811         if (!m_undoViewDock->isFloating()) {
3812             m_undoViewDock->setTitleBarWidget(new QWidget);
3813         }
3814         if (!m_vectorscopeDock->isFloating()) {
3815             m_vectorscopeDock->setTitleBarWidget(new QWidget);
3816         }
3817         if (!m_waveformDock->isFloating()) {
3818             m_waveformDock->setTitleBarWidget(new QWidget);
3819         }
3820         if (!m_RGBParadeDock->isFloating()) {
3821             m_RGBParadeDock->setTitleBarWidget(new QWidget(this));
3822         }
3823         if (!m_histogramDock->isFloating()) {
3824             m_histogramDock->setTitleBarWidget(new QWidget(this));
3825         }
3826     }
3827     KdenliveSettings::setShowtitlebars(show);
3828 }
3829
3830 void MainWindow::slotSwitchTitles()
3831 {
3832     slotShowTitleBars(!KdenliveSettings::showtitlebars());
3833 }
3834
3835 QString MainWindow::getMimeType()
3836 {
3837     QString mimetype = "application/x-kdenlive";
3838     KMimeType::Ptr mime = KMimeType::mimeType(mimetype);
3839     if (!mime) mimetype = "*.kdenlive";
3840     return mimetype;
3841 }
3842
3843 void MainWindow::slotMonitorRequestRenderFrame(bool request)
3844 {
3845     if (request) {
3846         m_projectMonitor->render->sendFrameForAnalysis = true;
3847         return;
3848     } else {
3849         for (int i = 0; i < m_scopesList.count(); i++) {
3850             if (m_scopesList.at(i)->isVisible() && tabifiedDockWidgets(m_scopesList.at(i)).isEmpty() && static_cast<AbstractScopeWidget *>(m_scopesList.at(i)->widget())->autoRefreshEnabled()) {
3851                 request = true;
3852                 break;
3853             }
3854         }
3855     }
3856     if (!request) {
3857         m_projectMonitor->render->sendFrameForAnalysis = false;
3858     }
3859 }
3860
3861 void MainWindow::slotUpdateScopeFrameRequest()
3862 {
3863     // We need a delay to make sure widgets are hidden after a close event for example
3864     QTimer::singleShot(500, this, SLOT(slotDoUpdateScopeFrameRequest()));
3865 }
3866
3867 void MainWindow::slotDoUpdateScopeFrameRequest()
3868 {
3869     // Check scopes
3870     bool request = false;
3871     for (int i = 0; i < m_scopesList.count(); i++) {
3872         if (!m_scopesList.at(i)->widget()->visibleRegion().isEmpty() && static_cast<AbstractScopeWidget *>(m_scopesList.at(i)->widget())->autoRefreshEnabled()) {
3873             kDebug() << "SCOPE VISIBLE: " << static_cast<AbstractScopeWidget *>(m_scopesList.at(i)->widget())->widgetName();
3874             request = true;
3875             break;
3876         }
3877     }
3878     if (!request) {
3879         if (!m_projectMonitor->effectSceneDisplayed())
3880             m_projectMonitor->render->sendFrameForAnalysis = false;
3881         m_clipMonitor->render->sendFrameForAnalysis = false;
3882     } else {
3883         m_projectMonitor->render->sendFrameForAnalysis = true;
3884         m_clipMonitor->render->sendFrameForAnalysis = true;
3885     }
3886 }
3887
3888 void MainWindow::slotUpdateColorScopes()
3889 {
3890     bool request = false;
3891     for (int i = 0; i < m_scopesList.count(); i++) {
3892         // Check if we need the renderer to send a new frame for update
3893         if (!m_scopesList.at(i)->widget()->visibleRegion().isEmpty() && !(static_cast<AbstractScopeWidget *>(m_scopesList.at(i)->widget())->autoRefreshEnabled())) request = true;
3894         static_cast<AbstractScopeWidget *>(m_scopesList.at(i)->widget())->slotActiveMonitorChanged(m_clipMonitor->isActive());
3895     }
3896     if (request) {
3897         if (m_clipMonitor->isActive()) m_clipMonitor->render->sendFrameUpdate();
3898         else m_projectMonitor->render->sendFrameUpdate();
3899     }
3900 }
3901
3902 #include "mainwindow.moc"
3903