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