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