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