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