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