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