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