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