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