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