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