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