]> git.sesse.net Git - kdenlive/blob - src/mainwindow.cpp
Progress on stopmotion widget (make it possible to switch between HDMI and V4L)
[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     // Recreate stopmotion widget on document change
1971     if (m_stopmotion) {
1972         delete m_stopmotion;
1973         m_stopmotion = NULL;
1974     }
1975
1976     KProgressDialog progressDialog(this, i18n("Loading project"), i18n("Loading project"));
1977     progressDialog.setAllowCancel(false);
1978     progressDialog.progressBar()->setMaximum(4);
1979     progressDialog.show();
1980     progressDialog.progressBar()->setValue(0);
1981     qApp->processEvents();
1982
1983     KdenliveDoc *doc = new KdenliveDoc(url, KdenliveSettings::defaultprojectfolder(), m_commandStack, KdenliveSettings::default_profile(), QPoint(KdenliveSettings::videotracks(), KdenliveSettings::audiotracks()), m_projectMonitor->render, m_notesWidget, this, &progressDialog);
1984
1985     progressDialog.progressBar()->setValue(1);
1986     progressDialog.progressBar()->setMaximum(4);
1987     progressDialog.setLabelText(i18n("Loading project"));
1988     qApp->processEvents();
1989
1990     if (stale == NULL) {
1991         stale = new KAutoSaveFile(url, doc);
1992         doc->m_autosave = stale;
1993     } else {
1994         doc->m_autosave = stale;
1995         doc->setUrl(stale->managedFile());
1996         doc->setModified(true);
1997         stale->setParent(doc);
1998     }
1999     connectDocumentInfo(doc);
2000
2001     progressDialog.progressBar()->setValue(2);
2002     qApp->processEvents();
2003
2004     bool ok;
2005     TrackView *trackView = new TrackView(doc, &ok, this);
2006
2007     progressDialog.progressBar()->setValue(3);
2008     qApp->processEvents();
2009
2010     m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description()));
2011     if (!ok) {
2012         m_timelineArea->setEnabled(false);
2013         m_projectList->setEnabled(false);
2014         KMessageBox::sorry(this, i18n("Cannot open file %1.\nProject is corrupted.", url.path()));
2015         slotGotProgressInfo(QString(), -1);
2016         newFile(false, true);
2017         return;
2018     }
2019     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), doc->url().path());
2020     trackView->setDuration(trackView->duration());
2021     trackView->projectView()->initCursorPos(m_projectMonitor->render->seekPosition().frames(doc->fps()));
2022
2023     if (m_timelineArea->count() > 1) m_timelineArea->setTabBarHidden(false);
2024     slotGotProgressInfo(QString(), -1);
2025     m_projectMonitor->adjustRulerSize(trackView->duration());
2026     m_projectMonitor->slotZoneMoved(trackView->inPoint(), trackView->outPoint());
2027     m_clipMonitor->refreshMonitor(true);
2028
2029     progressDialog.progressBar()->setValue(4);
2030 }
2031
2032 void MainWindow::recoverFiles(QList<KAutoSaveFile *> staleFiles)
2033 {
2034     foreach(KAutoSaveFile * stale, staleFiles) {
2035         /*if (!stale->open(QIODevice::QIODevice::ReadOnly)) {
2036                   // show an error message; we could not steal the lockfile
2037                   // maybe another application got to the file before us?
2038                   delete stale;
2039                   continue;
2040         }*/
2041         kDebug() << "// OPENING RECOVERY: " << stale->fileName() << "\nMANAGED: " << stale->managedFile().path();
2042         // the stalefiles also contain ".lock" files so we must ignore them... bug in KAutoSaveFile?
2043         if (!stale->fileName().endsWith(".lock")) doOpenFile(KUrl(stale->fileName()), stale);
2044         else KIO::NetAccess::del(KUrl(stale->fileName()), this);
2045     }
2046 }
2047
2048 void MainWindow::parseProfiles(const QString &mltPath)
2049 {
2050     //KdenliveSettings::setDefaulttmpfolder();
2051     if (!mltPath.isEmpty()) {
2052         KdenliveSettings::setMltpath(mltPath + "/share/mlt/profiles/");
2053         KdenliveSettings::setRendererpath(mltPath + "/bin/melt");
2054     }
2055
2056     if (KdenliveSettings::mltpath().isEmpty())
2057         KdenliveSettings::setMltpath(QString(MLT_PREFIX) + QString("/share/mlt/profiles/"));
2058
2059     if (KdenliveSettings::rendererpath().isEmpty() || KdenliveSettings::rendererpath().endsWith("inigo")) {
2060         QString meltPath = QString(MLT_PREFIX) + QString("/bin/melt");
2061         if (!QFile::exists(meltPath))
2062             meltPath = KStandardDirs::findExe("melt");
2063         KdenliveSettings::setRendererpath(meltPath);
2064     }
2065
2066     if (KdenliveSettings::rendererpath().isEmpty()) {
2067         // Cannot find the MLT melt renderer, ask for location
2068         KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(QString(), i18n("Cannot find the melt program required for rendering (part of MLT)"), this);
2069         if (getUrl->exec() == QDialog::Rejected) {
2070             ::exit(0);
2071         }
2072         KUrl rendererPath = getUrl->selectedUrl();
2073         delete getUrl;
2074         if (rendererPath.isEmpty()) ::exit(0);
2075         KdenliveSettings::setRendererpath(rendererPath.path());
2076     }
2077
2078     QStringList profilesFilter;
2079     profilesFilter << "*";
2080     QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
2081     if (profilesList.isEmpty()) {
2082         // Cannot find MLT path, try finding melt
2083         QString profilePath = KdenliveSettings::rendererpath();
2084         if (!profilePath.isEmpty()) {
2085             profilePath = profilePath.section('/', 0, -3);
2086             KdenliveSettings::setMltpath(profilePath + "/share/mlt/profiles/");
2087             profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
2088         }
2089         if (profilesList.isEmpty()) {
2090             // Cannot find the MLT profiles, ask for location
2091             KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find your MLT profiles, please give the path"), this);
2092             getUrl->fileDialog()->setMode(KFile::Directory);
2093             if (getUrl->exec() == QDialog::Rejected) {
2094                 ::exit(0);
2095             }
2096             KUrl mltPath = getUrl->selectedUrl();
2097             delete getUrl;
2098             if (mltPath.isEmpty()) ::exit(0);
2099             KdenliveSettings::setMltpath(mltPath.path(KUrl::AddTrailingSlash));
2100             profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
2101         }
2102     }
2103
2104     kDebug() << "RESULTING MLT PATH: " << KdenliveSettings::mltpath();
2105
2106     // Parse again MLT profiles to build a list of available video formats
2107     if (profilesList.isEmpty()) parseProfiles();
2108 }
2109
2110
2111 void MainWindow::slotEditProfiles()
2112 {
2113     ProfilesDialog *w = new ProfilesDialog;
2114     if (w->exec() == QDialog::Accepted) {
2115         KdenliveSettingsDialog* d = static_cast <KdenliveSettingsDialog*>(KConfigDialog::exists("settings"));
2116         if (d) d->checkProfile();
2117     }
2118     delete w;
2119 }
2120
2121 void MainWindow::slotDetectAudioDriver()
2122 {
2123     /* WARNING: do not use this method because sometimes detects wrong driver (pulse instead of alsa),
2124     leading to no audio output, see bug #934 */
2125
2126     //decide which audio driver is really best, in some cases SDL is wrong
2127     if (KdenliveSettings::audiodrivername().isEmpty()) {
2128         QString driver;
2129         KProcess readProcess;
2130         //PulseAudio needs to be selected if it exists, the ALSA pulse pcm device is not fast enough.
2131         if (!KStandardDirs::findExe("pactl").isEmpty()) {
2132             readProcess.setOutputChannelMode(KProcess::OnlyStdoutChannel);
2133             readProcess.setProgram("pactl", QStringList() << "stat");
2134             readProcess.execute(2000); // Kill it after 2 seconds
2135
2136             QString result = QString(readProcess.readAllStandardOutput());
2137             kDebug() << "// / / / / / READING PACTL: ";
2138             kDebug() << result;
2139             if (!result.isEmpty()) {
2140                 driver = "pulse";
2141                 kDebug() << "// / / / / PULSEAUDIO DETECTED";
2142             }
2143         }
2144         //put others here
2145         KdenliveSettings::setAutoaudiodrivername(driver);
2146     }
2147 }
2148
2149 void MainWindow::slotEditProjectSettings()
2150 {
2151     QPoint p = m_activeDocument->getTracksCount();
2152     ProjectSettings *w = new ProjectSettings(m_projectList, m_activeTimeline->projectView()->extractTransitionsLumas(), p.x(), p.y(), m_activeDocument->projectFolder().path(), true, !m_activeDocument->isModified(), this);
2153
2154     if (w->exec() == QDialog::Accepted) {
2155         QString profile = w->selectedProfile();
2156         m_activeDocument->setProjectFolder(w->selectedFolder());
2157 #ifndef   Q_WS_MAC
2158         m_recMonitor->slotUpdateCaptureFolder(m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash));
2159 #endif
2160         if (m_renderWidget) m_renderWidget->setDocumentPath(m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash));
2161         if (KdenliveSettings::videothumbnails() != w->enableVideoThumbs()) slotSwitchVideoThumbs();
2162         if (KdenliveSettings::audiothumbnails() != w->enableAudioThumbs()) slotSwitchAudioThumbs();
2163         if (m_activeDocument->profilePath() != profile) slotUpdateProjectProfile(profile);
2164     }
2165     delete w;
2166 }
2167
2168 void MainWindow::slotUpdateProjectProfile(const QString &profile)
2169 {
2170     double dar = m_activeDocument->dar();
2171
2172     // Recreate the stopmotion widget if profile changes
2173     if (m_stopmotion) {
2174         delete m_stopmotion;
2175         m_stopmotion = NULL;
2176     }
2177
2178     // Deselect current effect / transition
2179     m_effectStack->slotClipItemSelected(NULL, 0);
2180     m_transitionConfig->slotTransitionItemSelected(NULL, 0, QPoint(), false);
2181     m_clipMonitor->slotSetXml(NULL);
2182     bool updateFps = m_activeDocument->setProfilePath(profile);
2183     KdenliveSettings::setCurrent_profile(profile);
2184     KdenliveSettings::setProject_fps(m_activeDocument->fps());
2185     setCaption(m_activeDocument->description(), m_activeDocument->isModified());
2186
2187     m_activeDocument->clipManager()->clearUnusedProducers();
2188     m_monitorManager->resetProfiles(m_activeDocument->timecode());
2189     m_transitionConfig->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode(), m_activeDocument->tracksList());
2190     m_effectStack->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode());
2191     m_projectList->updateProjectFormat(m_activeDocument->timecode());
2192     if (m_renderWidget) m_renderWidget->setProfile(m_activeDocument->mltProfile());
2193     m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
2194     //m_activeDocument->clipManager()->resetProducersList(m_projectMonitor->render->producersList());
2195     if (dar != m_activeDocument->dar()) m_projectList->reloadClipThumbnails();
2196     if (updateFps) m_activeTimeline->updateProjectFps();
2197     m_activeDocument->setModified(true);
2198     m_commandStack->activeStack()->clear();
2199     //Update the mouse position display so it will display in DF/NDF format by default based on the project setting.
2200     slotUpdateMousePosition(0);
2201     // We need to desactivate & reactivate monitors to get a refresh
2202     //m_monitorManager->switchMonitors();
2203 }
2204
2205
2206 void MainWindow::slotRenderProject()
2207 {
2208     if (!m_renderWidget) {
2209         QString projectfolder = m_activeDocument ? m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash) : KdenliveSettings::defaultprojectfolder();
2210         m_renderWidget = new RenderWidget(projectfolder, this);
2211         connect(m_renderWidget, SIGNAL(shutdown()), this, SLOT(slotShutdown()));
2212         connect(m_renderWidget, SIGNAL(selectedRenderProfile(QMap <QString, QString>)), this, SLOT(slotSetDocumentRenderProfile(QMap <QString, QString>)));
2213         connect(m_renderWidget, SIGNAL(prepareRenderingData(bool, bool, const QString&)), this, SLOT(slotPrepareRendering(bool, bool, const QString&)));
2214         connect(m_renderWidget, SIGNAL(abortProcess(const QString &)), this, SIGNAL(abortRenderJob(const QString &)));
2215         connect(m_renderWidget, SIGNAL(openDvdWizard(const QString &, const QString &)), this, SLOT(slotDvdWizard(const QString &, const QString &)));
2216         if (m_activeDocument) {
2217             m_renderWidget->setProfile(m_activeDocument->mltProfile());
2218             m_renderWidget->setGuides(m_activeDocument->guidesXml(), m_activeDocument->projectDuration());
2219             m_renderWidget->setDocumentPath(m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash));
2220             m_renderWidget->setRenderProfile(m_activeDocument->getRenderProperties());
2221         }
2222     }
2223     slotCheckRenderStatus();
2224     m_renderWidget->show();
2225     m_renderWidget->showNormal();
2226
2227     // What are the following lines supposed to do?
2228     //m_activeTimeline->tracksNumber();
2229     //m_renderWidget->enableAudio(false);
2230     //m_renderWidget->export_audio;
2231 }
2232
2233 void MainWindow::slotCheckRenderStatus()
2234 {
2235     // Make sure there are no missing clips
2236     if (m_renderWidget)
2237         m_renderWidget->missingClips(m_projectList->hasMissingClips());
2238 }
2239
2240 void MainWindow::setRenderingProgress(const QString &url, int progress)
2241 {
2242     if (m_renderWidget)
2243         m_renderWidget->setRenderJob(url, progress);
2244 }
2245
2246 void MainWindow::setRenderingFinished(const QString &url, int status, const QString &error)
2247 {
2248     if (m_renderWidget)
2249         m_renderWidget->setRenderStatus(url, status, error);
2250 }
2251
2252 void MainWindow::slotCleanProject()
2253 {
2254     if (KMessageBox::warningContinueCancel(this, i18n("This will remove all unused clips from your project."), i18n("Clean up project")) == KMessageBox::Cancel) return;
2255     m_projectList->cleanup();
2256 }
2257
2258 void MainWindow::slotUpdateMousePosition(int pos)
2259 {
2260     if (m_activeDocument)
2261         switch (m_timecodeFormat->currentIndex()) {
2262         case 0:
2263             statusBar()->changeItem(m_activeDocument->timecode().getTimecodeFromFrames(pos), ID_TIMELINE_POS);
2264             break;
2265         default:
2266             statusBar()->changeItem(QString::number(pos), ID_TIMELINE_POS);
2267         }
2268 }
2269
2270 void MainWindow::slotUpdateDocumentState(bool modified)
2271 {
2272     if (!m_activeDocument) return;
2273     setCaption(m_activeDocument->description(), modified);
2274     m_saveAction->setEnabled(modified);
2275     if (modified) {
2276         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Link));
2277         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("document-save"));
2278     } else {
2279         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Text));
2280         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("kdenlive"));
2281     }
2282 }
2283
2284 void MainWindow::connectDocumentInfo(KdenliveDoc *doc)
2285 {
2286     if (m_activeDocument) {
2287         if (m_activeDocument == doc) return;
2288         disconnect(m_activeDocument, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
2289     }
2290     connect(doc, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
2291 }
2292
2293 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc)   //changed
2294 {
2295     //m_projectMonitor->stop();
2296     m_closeAction->setEnabled(m_timelineArea->count() > 1);
2297     kDebug() << "///////////////////   CONNECTING DOC TO PROJECT VIEW ////////////////";
2298     if (m_activeDocument) {
2299         if (m_activeDocument == doc) return;
2300         if (m_activeTimeline) {
2301             disconnect(m_projectMonitor, SIGNAL(renderPosition(int)), m_activeTimeline, SLOT(moveCursorPos(int)));
2302             disconnect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), m_activeTimeline, SLOT(slotSetZone(QPoint)));
2303             disconnect(m_projectMonitor, SIGNAL(durationChanged(int)), m_activeTimeline, SLOT(setDuration(int)));
2304             disconnect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), m_activeDocument, SLOT(setModified()));
2305             disconnect(m_notesWidget, SIGNAL(textChanged()), m_activeDocument, SLOT(setModified()));
2306             disconnect(m_clipMonitor, SIGNAL(zoneUpdated(QPoint)), m_activeDocument, SLOT(setModified()));
2307             disconnect(m_projectList, SIGNAL(projectModified()), m_activeDocument, SLOT(setModified()));
2308             disconnect(m_projectList, SIGNAL(updateProfile(const QString &)), this, SLOT(slotUpdateProjectProfile(const QString &)));
2309
2310             disconnect(m_projectMonitor->render, SIGNAL(refreshDocumentProducers()), m_activeDocument, SLOT(checkProjectClips()));
2311
2312             disconnect(m_activeDocument, SIGNAL(guidesUpdated()), this, SLOT(slotGuidesUpdated()));
2313             disconnect(m_activeDocument, SIGNAL(addProjectClip(DocClipBase *, bool)), m_projectList, SLOT(slotAddClip(DocClipBase *, bool)));
2314             disconnect(m_activeDocument, SIGNAL(resetProjectList()), m_projectList, SLOT(slotResetProjectList()));
2315             disconnect(m_activeDocument, SIGNAL(signalDeleteProjectClip(const QString &)), this, SLOT(slotDeleteClip(const QString &)));
2316             disconnect(m_activeDocument, SIGNAL(updateClipDisplay(const QString &)), m_projectList, SLOT(slotUpdateClip(const QString &)));
2317             disconnect(m_activeDocument, SIGNAL(selectLastAddedClip(const QString &)), m_projectList, SLOT(slotSelectClip(const QString &)));
2318             disconnect(m_activeDocument, SIGNAL(deleteTimelineClip(const QString &)), m_activeTimeline, SLOT(slotDeleteClip(const QString &)));
2319             disconnect(m_activeTimeline->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), m_effectStack, SLOT(slotClipItemSelected(ClipItem*, int)));
2320             disconnect(m_activeTimeline->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), this, SLOT(slotActivateEffectStackView()));
2321             disconnect(m_activeTimeline->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), m_projectMonitor, SLOT(slotSetSelectedClip(ClipItem*)));
2322             disconnect(m_activeTimeline->projectView(), SIGNAL(transitionItemSelected(Transition*, int, QPoint, bool)), m_transitionConfig, SLOT(slotTransitionItemSelected(Transition*, int, QPoint, bool)));
2323             disconnect(m_activeTimeline->projectView(), SIGNAL(transitionItemSelected(Transition*, int, QPoint, bool)), this, SLOT(slotActivateTransitionView(Transition *)));
2324             disconnect(m_activeTimeline->projectView(), SIGNAL(transitionItemSelected(Transition*, int, QPoint, bool)), m_projectMonitor, SLOT(slotSetSelectedClip(Transition*)));
2325             disconnect(m_activeTimeline->projectView(), SIGNAL(playMonitor()), m_projectMonitor, SLOT(slotPlay()));
2326             disconnect(m_activeTimeline->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
2327             disconnect(m_activeTimeline->projectView(), SIGNAL(showClipFrame(DocClipBase *, QPoint, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, QPoint, const int)));
2328             disconnect(m_activeTimeline, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
2329             disconnect(m_activeTimeline, SIGNAL(insertTrack(int)), this, SLOT(slotInsertTrack(int)));
2330             disconnect(m_activeTimeline, SIGNAL(deleteTrack(int)), this, SLOT(slotDeleteTrack(int)));
2331             disconnect(m_activeTimeline, SIGNAL(configTrack(int)), this, SLOT(slotConfigTrack(int)));
2332             disconnect(m_activeDocument, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
2333             disconnect(m_effectStack, SIGNAL(updateEffect(ClipItem*, int, QDomElement, QDomElement, int)), m_activeTimeline->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, int, QDomElement, QDomElement, int)));
2334             disconnect(m_effectStack, SIGNAL(removeEffect(ClipItem*, int, QDomElement)), m_activeTimeline->projectView(), SLOT(slotDeleteEffect(ClipItem*, int, QDomElement)));
2335             disconnect(m_effectStack, SIGNAL(changeEffectState(ClipItem*, int, int, bool)), m_activeTimeline->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, int, bool)));
2336             disconnect(m_effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int, int)), m_activeTimeline->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int, int)));
2337             disconnect(m_effectStack, SIGNAL(refreshEffectStack(ClipItem*)), m_activeTimeline->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
2338             disconnect(m_effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
2339             disconnect(m_effectStack, SIGNAL(displayMessage(const QString&, int)), this, SLOT(slotGotProgressInfo(const QString&, int)));
2340             disconnect(m_transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), m_activeTimeline->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
2341             disconnect(m_transitionConfig, SIGNAL(seekTimeline(int)), m_activeTimeline->projectView() , SLOT(setCursorPos(int)));
2342             disconnect(m_activeTimeline->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
2343             disconnect(m_activeTimeline, SIGNAL(zoneMoved(int, int)), this, SLOT(slotZoneMoved(int, int)));
2344             disconnect(m_projectList, SIGNAL(loadingIsOver()), m_activeTimeline->projectView(), SLOT(slotUpdateAllThumbs()));
2345             disconnect(m_projectList, SIGNAL(displayMessage(const QString&, int)), this, SLOT(slotGotProgressInfo(const QString&, int)));
2346             disconnect(m_projectList, SIGNAL(updateRenderStatus()), this, SLOT(slotCheckRenderStatus()));
2347             disconnect(m_projectList, SIGNAL(clipNeedsReload(const QString&, bool)), m_activeTimeline->projectView(), SLOT(slotUpdateClip(const QString &, bool)));
2348             m_effectStack->clear();
2349         }
2350         //m_activeDocument->setRenderer(NULL);
2351         disconnect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
2352         disconnect(m_projectList, SIGNAL(refreshClip()), m_monitorManager, SLOT(slotRefreshCurrentMonitor()));
2353         m_clipMonitor->stop();
2354     }
2355     KdenliveSettings::setCurrent_profile(doc->profilePath());
2356     KdenliveSettings::setProject_fps(doc->fps());
2357     m_monitorManager->resetProfiles(doc->timecode());
2358     m_projectList->setDocument(doc);
2359     m_transitionConfig->updateProjectFormat(doc->mltProfile(), doc->timecode(), doc->tracksList());
2360     m_effectStack->updateProjectFormat(doc->mltProfile(), doc->timecode());
2361     connect(m_projectList, SIGNAL(clipSelected(DocClipBase *, QPoint)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, QPoint)));
2362     connect(m_projectList, SIGNAL(refreshClip()), m_monitorManager, SLOT(slotRefreshCurrentMonitor()));
2363     connect(m_projectList, SIGNAL(clipNeedsReload(const QString&, bool)), trackView->projectView(), SLOT(slotUpdateClip(const QString &, bool)));
2364
2365     connect(m_projectList, SIGNAL(projectModified()), doc, SLOT(setModified()));
2366     connect(m_projectList, SIGNAL(updateProfile(const QString &)), this, SLOT(slotUpdateProjectProfile(const QString &)));
2367     connect(m_projectList, SIGNAL(clipNameChanged(const QString, const QString)), trackView->projectView(), SLOT(clipNameChanged(const QString, const QString)));
2368
2369     connect(m_projectList, SIGNAL(findInTimeline(const QString&)), this, SLOT(slotClipInTimeline(const QString&)));
2370
2371
2372     connect(trackView, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
2373     connect(trackView, SIGNAL(insertTrack(int)), this, SLOT(slotInsertTrack(int)));
2374     connect(trackView, SIGNAL(deleteTrack(int)), this, SLOT(slotDeleteTrack(int)));
2375     connect(trackView, SIGNAL(configTrack(int)), this, SLOT(slotConfigTrack(int)));
2376     connect(trackView, SIGNAL(updateTracksInfo()), this, SLOT(slotUpdateTrackInfo()));
2377     connect(trackView, SIGNAL(mousePosition(int)), this, SLOT(slotUpdateMousePosition(int)));
2378     connect(trackView->projectView(), SIGNAL(forceClipProcessing(const QString &)), m_projectList, SLOT(slotForceProcessing(const QString &)));
2379     connect(m_projectMonitor, SIGNAL(renderPosition(int)), trackView, SLOT(moveCursorPos(int)));
2380     connect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), trackView, SLOT(slotSetZone(QPoint)));
2381     connect(m_clipMonitor, SIGNAL(zoneUpdated(QPoint)), m_projectList, SLOT(slotUpdateClipCut(QPoint)));
2382     connect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), doc, SLOT(setModified()));
2383     connect(m_clipMonitor, SIGNAL(zoneUpdated(QPoint)), doc, SLOT(setModified()));
2384     connect(m_projectMonitor, SIGNAL(durationChanged(int)), trackView, SLOT(setDuration(int)));
2385     connect(m_projectMonitor->render, SIGNAL(refreshDocumentProducers()), doc, SLOT(checkProjectClips()));
2386
2387     connect(doc, SIGNAL(addProjectClip(DocClipBase *, bool)), m_projectList, SLOT(slotAddClip(DocClipBase *, bool)));
2388     connect(doc, SIGNAL(resetProjectList()), m_projectList, SLOT(slotResetProjectList()));
2389     connect(doc, SIGNAL(signalDeleteProjectClip(const QString &)), this, SLOT(slotDeleteClip(const QString &)));
2390     connect(doc, SIGNAL(updateClipDisplay(const QString &)), m_projectList, SLOT(slotUpdateClip(const QString &)));
2391     connect(doc, SIGNAL(selectLastAddedClip(const QString &)), m_projectList, SLOT(slotSelectClip(const QString &)));
2392
2393     connect(doc, SIGNAL(deleteTimelineClip(const QString &)), trackView, SLOT(slotDeleteClip(const QString &)));
2394     connect(doc, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
2395     connect(doc, SIGNAL(guidesUpdated()), this, SLOT(slotGuidesUpdated()));
2396     connect(m_notesWidget, SIGNAL(textChanged()), doc, SLOT(setModified()));
2397
2398     connect(trackView->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), m_effectStack, SLOT(slotClipItemSelected(ClipItem*, int)));
2399     connect(trackView->projectView(), SIGNAL(updateClipMarkers(DocClipBase *)), this, SLOT(slotUpdateClipMarkers(DocClipBase*)));
2400     connect(trackView, SIGNAL(showTrackEffects(int, TrackInfo)), m_effectStack, SLOT(slotTrackItemSelected(int, TrackInfo)));
2401     connect(trackView, SIGNAL(showTrackEffects(int, TrackInfo)), this, SLOT(slotActivateEffectStackView()));
2402
2403     connect(trackView->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), this, SLOT(slotActivateEffectStackView()));
2404     connect(trackView->projectView(), SIGNAL(transitionItemSelected(Transition*, int, QPoint, bool)), m_transitionConfig, SLOT(slotTransitionItemSelected(Transition*, int, QPoint, bool)));
2405     connect(trackView->projectView(), SIGNAL(transitionItemSelected(Transition*, int, QPoint, bool)), this, SLOT(slotActivateTransitionView(Transition *)));
2406     m_zoomSlider->setValue(doc->zoom().x());
2407     connect(trackView->projectView(), SIGNAL(zoomIn()), this, SLOT(slotZoomIn()));
2408     connect(trackView->projectView(), SIGNAL(zoomOut()), this, SLOT(slotZoomOut()));
2409     connect(trackView, SIGNAL(setZoom(int)), this, SLOT(slotSetZoom(int)));
2410     connect(trackView->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
2411
2412     connect(trackView->projectView(), SIGNAL(showClipFrame(DocClipBase *, QPoint, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, QPoint, const int)));
2413     connect(trackView->projectView(), SIGNAL(playMonitor()), m_projectMonitor, SLOT(slotPlay()));
2414
2415     connect(trackView->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), m_projectMonitor, SLOT(slotSetSelectedClip(ClipItem*)));
2416     connect(trackView->projectView(), SIGNAL(transitionItemSelected(Transition*, int, QPoint, bool)), m_projectMonitor, SLOT(slotSetSelectedClip(Transition*)));
2417
2418     connect(m_effectStack, SIGNAL(updateEffect(ClipItem*, int, QDomElement, QDomElement, int)), trackView->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, int, QDomElement, QDomElement, int)));
2419     connect(m_effectStack, SIGNAL(updateClipRegion(ClipItem*, int, QString)), trackView->projectView(), SLOT(slotUpdateClipRegion(ClipItem*, int, QString)));
2420     connect(m_effectStack, SIGNAL(removeEffect(ClipItem*, int, QDomElement)), trackView->projectView(), SLOT(slotDeleteEffect(ClipItem*, int, QDomElement)));
2421     connect(m_effectStack, SIGNAL(changeEffectState(ClipItem*, int, int, bool)), trackView->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, int, bool)));
2422     connect(m_effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int, int)), trackView->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int, int)));
2423     connect(m_effectStack, SIGNAL(refreshEffectStack(ClipItem*)), trackView->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
2424     connect(m_transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
2425     connect(m_transitionConfig, SIGNAL(seekTimeline(int)), trackView->projectView() , SLOT(setCursorPos(int)));
2426     connect(m_effectStack, SIGNAL(seekTimeline(int)), trackView->projectView() , SLOT(setCursorPos(int)));
2427     connect(m_effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
2428     connect(m_effectStack, SIGNAL(displayMessage(const QString&, int)), this, SLOT(slotGotProgressInfo(const QString&, int)));
2429
2430     connect(trackView->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
2431     connect(trackView, SIGNAL(zoneMoved(int, int)), this, SLOT(slotZoneMoved(int, int)));
2432     connect(m_projectList, SIGNAL(loadingIsOver()), trackView->projectView(), SLOT(slotUpdateAllThumbs()));
2433     connect(m_projectList, SIGNAL(displayMessage(const QString&, int)), this, SLOT(slotGotProgressInfo(const QString&, int)));
2434     connect(m_projectList, SIGNAL(updateRenderStatus()), this, SLOT(slotCheckRenderStatus()));
2435
2436
2437     trackView->projectView()->setContextMenu(m_timelineContextMenu, m_timelineContextClipMenu, m_timelineContextTransitionMenu, m_clipTypeGroup, (QMenu*)(factory()->container("marker_menu", this)));
2438     m_activeTimeline = trackView;
2439     if (m_renderWidget) {
2440         slotCheckRenderStatus();
2441         m_renderWidget->setProfile(doc->mltProfile());
2442         m_renderWidget->setGuides(doc->guidesXml(), doc->projectDuration());
2443         m_renderWidget->setDocumentPath(doc->projectFolder().path(KUrl::AddTrailingSlash));
2444         m_renderWidget->setRenderProfile(doc->getRenderProperties());
2445     }
2446     //doc->setRenderer(m_projectMonitor->render);
2447     m_commandStack->setActiveStack(doc->commandStack());
2448     KdenliveSettings::setProject_display_ratio(doc->dar());
2449     //doc->clipManager()->checkAudioThumbs();
2450
2451     //m_overView->setScene(trackView->projectScene());
2452     //m_overView->scale(m_overView->width() / trackView->duration(), m_overView->height() / (50 * trackView->tracksNumber()));
2453     //m_overView->fitInView(m_overView->itemAt(0, 50), Qt::KeepAspectRatio);
2454
2455     setCaption(doc->description(), doc->isModified());
2456     m_saveAction->setEnabled(doc->isModified());
2457     m_normalEditTool->setChecked(true);
2458     m_activeDocument = doc;
2459     m_activeTimeline->updateProjectFps();
2460     m_activeDocument->checkProjectClips();
2461 #ifndef   Q_WS_MAC
2462     m_recMonitor->slotUpdateCaptureFolder(m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash));
2463 #endif
2464     if (KdenliveSettings::dropbframes()) slotUpdatePreviewSettings();
2465     //Update the mouse position display so it will display in DF/NDF format by default based on the project setting.
2466     slotUpdateMousePosition(0);
2467     // set tool to select tool
2468     m_buttonSelectTool->setChecked(true);
2469 }
2470
2471 void MainWindow::slotZoneMoved(int start, int end)
2472 {
2473     m_activeDocument->setZone(start, end);
2474     m_projectMonitor->slotZoneMoved(start, end);
2475 }
2476
2477 void MainWindow::slotGuidesUpdated()
2478 {
2479     if (m_renderWidget)
2480         m_renderWidget->setGuides(m_activeDocument->guidesXml(), m_activeDocument->projectDuration());
2481 }
2482
2483 void MainWindow::slotEditKeys()
2484 {
2485     KShortcutsDialog dialog(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsAllowed, this);
2486     dialog.addCollection(actionCollection(), i18nc("general keyboard shortcuts", "General"));
2487     dialog.addCollection(m_effectsActionCollection, i18nc("effects and transitions keyboard shortcuts", "Effects & Transitions"));
2488     dialog.configure();
2489 }
2490
2491 void MainWindow::slotPreferences(int page, int option)
2492 {
2493     /*
2494      * An instance of your dialog could be already created and could be
2495      * cached, in which case you want to display the cached dialog
2496      * instead of creating another one
2497      */
2498     if (KConfigDialog::showDialog("settings")) {
2499         KdenliveSettingsDialog* d = static_cast <KdenliveSettingsDialog*>(KConfigDialog::exists("settings"));
2500         if (page != -1) d->showPage(page, option);
2501         return;
2502     }
2503
2504     // KConfigDialog didn't find an instance of this dialog, so lets
2505     // create it :
2506     KdenliveSettingsDialog* dialog = new KdenliveSettingsDialog(this);
2507     connect(dialog, SIGNAL(settingsChanged(const QString&)), this, SLOT(updateConfiguration()));
2508     //connect(dialog, SIGNAL(doResetProfile()), this, SLOT(slotDetectAudioDriver()));
2509     connect(dialog, SIGNAL(doResetProfile()), m_monitorManager, SLOT(slotResetProfiles()));
2510     connect(dialog, SIGNAL(updatePreviewSettings()), this, SLOT(slotUpdatePreviewSettings()));
2511 #ifndef Q_WS_MAC
2512     connect(dialog, SIGNAL(updateCaptureFolder()), this, SLOT(slotUpdateCaptureFolder()));
2513 #endif
2514     //connect(dialog, SIGNAL(updatePreviewSettings()), this, SLOT(slotUpdatePreviewSettings()));
2515     dialog->show();
2516     if (page != -1) dialog->showPage(page, option);
2517 }
2518
2519 void MainWindow::slotUpdateCaptureFolder()
2520 {
2521
2522 #ifndef   Q_WS_MAC
2523     if (m_activeDocument) m_recMonitor->slotUpdateCaptureFolder(m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash));
2524     else m_recMonitor->slotUpdateCaptureFolder(KdenliveSettings::defaultprojectfolder());
2525 #endif
2526 }
2527
2528 void MainWindow::slotUpdatePreviewSettings()
2529 {
2530     if (m_activeDocument) {
2531         m_clipMonitor->slotSetXml(NULL);
2532         m_activeDocument->updatePreviewSettings();
2533     }
2534 }
2535
2536 void MainWindow::updateConfiguration()
2537 {
2538     //TODO: we should apply settings to all projects, not only the current one
2539     if (m_activeTimeline) {
2540         m_activeTimeline->refresh();
2541         m_activeTimeline->projectView()->checkAutoScroll();
2542         m_activeTimeline->projectView()->checkTrackHeight();
2543         if (m_activeDocument)
2544             m_activeDocument->clipManager()->checkAudioThumbs();
2545     }
2546     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
2547     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
2548     m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
2549     m_buttonAutomaticSplitAudio->setChecked(KdenliveSettings::splitaudio());
2550
2551     // Update list of transcoding profiles
2552     loadTranscoders();
2553 #ifndef NO_JOGSHUTTLE
2554     activateShuttleDevice();
2555 #endif /* NO_JOGSHUTTLE */
2556
2557 }
2558
2559 void MainWindow::slotSwitchSplitAudio()
2560 {
2561     KdenliveSettings::setSplitaudio(!KdenliveSettings::splitaudio());
2562     m_buttonAutomaticSplitAudio->setChecked(KdenliveSettings::splitaudio());
2563 }
2564
2565 void MainWindow::slotSwitchVideoThumbs()
2566 {
2567     KdenliveSettings::setVideothumbnails(!KdenliveSettings::videothumbnails());
2568     if (m_activeTimeline)
2569         m_activeTimeline->projectView()->slotUpdateAllThumbs();
2570     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
2571 }
2572
2573 void MainWindow::slotSwitchAudioThumbs()
2574 {
2575     KdenliveSettings::setAudiothumbnails(!KdenliveSettings::audiothumbnails());
2576     if (m_activeTimeline) {
2577         m_activeTimeline->refresh();
2578         m_activeTimeline->projectView()->checkAutoScroll();
2579         if (m_activeDocument)
2580             m_activeDocument->clipManager()->checkAudioThumbs();
2581     }
2582     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
2583 }
2584
2585 void MainWindow::slotSwitchMarkersComments()
2586 {
2587     KdenliveSettings::setShowmarkers(!KdenliveSettings::showmarkers());
2588     if (m_activeTimeline)
2589         m_activeTimeline->refresh();
2590     m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
2591 }
2592
2593 void MainWindow::slotSwitchSnap()
2594 {
2595     KdenliveSettings::setSnaptopoints(!KdenliveSettings::snaptopoints());
2596     m_buttonSnap->setChecked(KdenliveSettings::snaptopoints());
2597 }
2598
2599
2600 void MainWindow::slotDeleteItem()
2601 {
2602     if (QApplication::focusWidget() &&
2603             QApplication::focusWidget()->parentWidget() &&
2604             QApplication::focusWidget()->parentWidget()->parentWidget() &&
2605             QApplication::focusWidget()->parentWidget()->parentWidget() == m_projectListDock) {
2606         m_projectList->slotRemoveClip();
2607
2608     } else {
2609         QWidget *widget = QApplication::focusWidget();
2610         while (widget) {
2611             if (widget == m_effectStackDock) {
2612                 m_effectStack->slotItemDel();
2613                 return;
2614             }
2615             widget = widget->parentWidget();
2616         }
2617
2618         // effect stack has no focus
2619         if (m_activeTimeline)
2620             m_activeTimeline->projectView()->deleteSelectedClips();
2621     }
2622 }
2623
2624 void MainWindow::slotUpdateClipMarkers(DocClipBase *clip)
2625 {
2626     if (m_clipMonitor->isActive())
2627         m_clipMonitor->checkOverlay();
2628     m_clipMonitor->updateMarkers(clip);
2629 }
2630
2631 void MainWindow::slotAddClipMarker()
2632 {
2633     DocClipBase *clip = NULL;
2634     GenTime pos;
2635     if (m_projectMonitor->isActive()) {
2636         if (m_activeTimeline) {
2637             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
2638             if (item) {
2639                 pos = GenTime((int)((m_projectMonitor->position() - item->startPos() + item->cropStart()).frames(m_activeDocument->fps()) * item->speed() + 0.5), m_activeDocument->fps());
2640                 clip = item->baseClip();
2641             }
2642         }
2643     } else {
2644         clip = m_clipMonitor->activeClip();
2645         pos = m_clipMonitor->position();
2646     }
2647     if (!clip) {
2648         m_messageLabel->setMessage(i18n("Cannot find clip to add marker"), ErrorMessage);
2649         return;
2650     }
2651     QString id = clip->getId();
2652     CommentedTime marker(pos, i18n("Marker"));
2653     MarkerDialog d(clip, marker, m_activeDocument->timecode(), i18n("Add Marker"), this);
2654     if (d.exec() == QDialog::Accepted)
2655         m_activeTimeline->projectView()->slotAddClipMarker(id, d.newMarker().time(), d.newMarker().comment());
2656 }
2657
2658 void MainWindow::slotDeleteClipMarker()
2659 {
2660     DocClipBase *clip = NULL;
2661     GenTime pos;
2662     if (m_projectMonitor->isActive()) {
2663         if (m_activeTimeline) {
2664             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
2665             if (item) {
2666                 pos = (m_projectMonitor->position() - item->startPos() + item->cropStart()) / item->speed();
2667                 clip = item->baseClip();
2668             }
2669         }
2670     } else {
2671         clip = m_clipMonitor->activeClip();
2672         pos = m_clipMonitor->position();
2673     }
2674     if (!clip) {
2675         m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
2676         return;
2677     }
2678
2679     QString id = clip->getId();
2680     QString comment = clip->markerComment(pos);
2681     if (comment.isEmpty()) {
2682         m_messageLabel->setMessage(i18n("No marker found at cursor time"), ErrorMessage);
2683         return;
2684     }
2685     m_activeTimeline->projectView()->slotDeleteClipMarker(comment, id, pos);
2686 }
2687
2688 void MainWindow::slotDeleteAllClipMarkers()
2689 {
2690     DocClipBase *clip = NULL;
2691     if (m_projectMonitor->isActive()) {
2692         if (m_activeTimeline) {
2693             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
2694             if (item) {
2695                 clip = item->baseClip();
2696             }
2697         }
2698     } else {
2699         clip = m_clipMonitor->activeClip();
2700     }
2701     if (!clip) {
2702         m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
2703         return;
2704     }
2705     m_activeTimeline->projectView()->slotDeleteAllClipMarkers(clip->getId());
2706 }
2707
2708 void MainWindow::slotEditClipMarker()
2709 {
2710     DocClipBase *clip = NULL;
2711     GenTime pos;
2712     if (m_projectMonitor->isActive()) {
2713         if (m_activeTimeline) {
2714             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
2715             if (item) {
2716                 pos = (m_projectMonitor->position() - item->startPos() + item->cropStart()) / item->speed();
2717                 clip = item->baseClip();
2718             }
2719         }
2720     } else {
2721         clip = m_clipMonitor->activeClip();
2722         pos = m_clipMonitor->position();
2723     }
2724     if (!clip) {
2725         m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
2726         return;
2727     }
2728
2729     QString id = clip->getId();
2730     QString oldcomment = clip->markerComment(pos);
2731     if (oldcomment.isEmpty()) {
2732         m_messageLabel->setMessage(i18n("No marker found at cursor time"), ErrorMessage);
2733         return;
2734     }
2735
2736     CommentedTime marker(pos, oldcomment);
2737     MarkerDialog d(clip, marker, m_activeDocument->timecode(), i18n("Edit Marker"), this);
2738     if (d.exec() == QDialog::Accepted) {
2739         m_activeTimeline->projectView()->slotAddClipMarker(id, d.newMarker().time(), d.newMarker().comment());
2740         if (d.newMarker().time() != pos) {
2741             // remove old marker
2742             m_activeTimeline->projectView()->slotAddClipMarker(id, pos, QString());
2743         }
2744     }
2745 }
2746
2747 void MainWindow::slotAddMarkerGuideQuickly()
2748 {
2749     if (!m_activeTimeline || !m_activeDocument)
2750         return;
2751
2752     if (m_clipMonitor->isActive()) {
2753         DocClipBase *clip = m_clipMonitor->activeClip();
2754         GenTime pos = m_clipMonitor->position();
2755
2756         if (!clip) {
2757             m_messageLabel->setMessage(i18n("Cannot find clip to add marker"), ErrorMessage);
2758             return;
2759         }
2760
2761         m_activeTimeline->projectView()->slotAddClipMarker(clip->getId(), pos, m_activeDocument->timecode().getDisplayTimecode(pos, false));
2762     } else {
2763         m_activeTimeline->projectView()->slotAddGuide(false);
2764     }
2765 }
2766
2767 void MainWindow::slotAddGuide()
2768 {
2769     if (m_activeTimeline)
2770         m_activeTimeline->projectView()->slotAddGuide();
2771 }
2772
2773 void MainWindow::slotInsertSpace()
2774 {
2775     if (m_activeTimeline)
2776         m_activeTimeline->projectView()->slotInsertSpace();
2777 }
2778
2779 void MainWindow::slotRemoveSpace()
2780 {
2781     if (m_activeTimeline)
2782         m_activeTimeline->projectView()->slotRemoveSpace();
2783 }
2784
2785 void MainWindow::slotInsertTrack(int ix)
2786 {
2787     m_projectMonitor->activateMonitor();
2788     if (m_activeTimeline)
2789         m_activeTimeline->projectView()->slotInsertTrack(ix);
2790     if (m_activeDocument)
2791         m_transitionConfig->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode(), m_activeDocument->tracksList());
2792 }
2793
2794 void MainWindow::slotDeleteTrack(int ix)
2795 {
2796     m_projectMonitor->activateMonitor();
2797     if (m_activeTimeline)
2798         m_activeTimeline->projectView()->slotDeleteTrack(ix);
2799     if (m_activeDocument)
2800         m_transitionConfig->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode(), m_activeDocument->tracksList());
2801 }
2802
2803 void MainWindow::slotConfigTrack(int ix)
2804 {
2805     m_projectMonitor->activateMonitor();
2806     if (m_activeTimeline)
2807         m_activeTimeline->projectView()->slotConfigTracks(ix);
2808     if (m_activeDocument)
2809         m_transitionConfig->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode(), m_activeDocument->tracksList());
2810 }
2811
2812 void MainWindow::slotEditGuide()
2813 {
2814     if (m_activeTimeline)
2815         m_activeTimeline->projectView()->slotEditGuide();
2816 }
2817
2818 void MainWindow::slotDeleteGuide()
2819 {
2820     if (m_activeTimeline)
2821         m_activeTimeline->projectView()->slotDeleteGuide();
2822 }
2823
2824 void MainWindow::slotDeleteAllGuides()
2825 {
2826     if (m_activeTimeline)
2827         m_activeTimeline->projectView()->slotDeleteAllGuides();
2828 }
2829
2830 void MainWindow::slotCutTimelineClip()
2831 {
2832     if (m_activeTimeline)
2833         m_activeTimeline->projectView()->cutSelectedClips();
2834 }
2835
2836 void MainWindow::slotInsertClipOverwrite()
2837 {
2838     if (m_activeTimeline) {
2839         QStringList data = m_clipMonitor->getZoneInfo();
2840         m_activeTimeline->projectView()->insertZoneOverwrite(data, m_activeTimeline->inPoint());
2841     }
2842 }
2843
2844 void MainWindow::slotSelectTimelineClip()
2845 {
2846     if (m_activeTimeline)
2847         m_activeTimeline->projectView()->selectClip(true);
2848 }
2849
2850 void MainWindow::slotSelectTimelineTransition()
2851 {
2852     if (m_activeTimeline)
2853         m_activeTimeline->projectView()->selectTransition(true);
2854 }
2855
2856 void MainWindow::slotDeselectTimelineClip()
2857 {
2858     if (m_activeTimeline)
2859         m_activeTimeline->projectView()->selectClip(false, true);
2860 }
2861
2862 void MainWindow::slotDeselectTimelineTransition()
2863 {
2864     if (m_activeTimeline)
2865         m_activeTimeline->projectView()->selectTransition(false, true);
2866 }
2867
2868 void MainWindow::slotSelectAddTimelineClip()
2869 {
2870     if (m_activeTimeline)
2871         m_activeTimeline->projectView()->selectClip(true, true);
2872 }
2873
2874 void MainWindow::slotSelectAddTimelineTransition()
2875 {
2876     if (m_activeTimeline)
2877         m_activeTimeline->projectView()->selectTransition(true, true);
2878 }
2879
2880 void MainWindow::slotGroupClips()
2881 {
2882     if (m_activeTimeline)
2883         m_activeTimeline->projectView()->groupClips();
2884 }
2885
2886 void MainWindow::slotUnGroupClips()
2887 {
2888     if (m_activeTimeline)
2889         m_activeTimeline->projectView()->groupClips(false);
2890 }
2891
2892 void MainWindow::slotEditItemDuration()
2893 {
2894     if (m_activeTimeline)
2895         m_activeTimeline->projectView()->editItemDuration();
2896 }
2897
2898 void MainWindow::slotAddProjectClip(KUrl url)
2899 {
2900     if (m_activeDocument)
2901         m_activeDocument->slotAddClipFile(url, QString());
2902 }
2903
2904 void MainWindow::slotAddTransition(QAction *result)
2905 {
2906     if (!result) return;
2907     QStringList info = result->data().toStringList();
2908     if (info.isEmpty()) return;
2909     QDomElement transition = transitions.getEffectByTag(info.at(1), info.at(2));
2910     if (m_activeTimeline && !transition.isNull()) {
2911         m_activeTimeline->projectView()->slotAddTransitionToSelectedClips(transition.cloneNode().toElement());
2912     }
2913 }
2914
2915 void MainWindow::slotAddVideoEffect(QAction *result)
2916 {
2917     if (!result) return;
2918     QStringList info = result->data().toStringList();
2919     if (info.isEmpty()) return;
2920     QDomElement effect = videoEffects.getEffectByTag(info.at(1), info.at(2));
2921     slotAddEffect(effect);
2922 }
2923
2924 void MainWindow::slotAddAudioEffect(QAction *result)
2925 {
2926     if (!result) return;
2927     QStringList info = result->data().toStringList();
2928     if (info.isEmpty()) return;
2929     QDomElement effect = audioEffects.getEffectByTag(info.at(1), info.at(2));
2930     slotAddEffect(effect);
2931 }
2932
2933 void MainWindow::slotAddCustomEffect(QAction *result)
2934 {
2935     if (!result) return;
2936     QStringList info = result->data().toStringList();
2937     if (info.isEmpty()) return;
2938     QDomElement effect = customEffects.getEffectByTag(info.at(1), info.at(2));
2939     slotAddEffect(effect);
2940 }
2941
2942 void MainWindow::slotZoomIn()
2943 {
2944     m_zoomSlider->setValue(m_zoomSlider->value() - 1);
2945     slotShowZoomSliderToolTip();
2946 }
2947
2948 void MainWindow::slotZoomOut()
2949 {
2950     m_zoomSlider->setValue(m_zoomSlider->value() + 1);
2951     slotShowZoomSliderToolTip();
2952 }
2953
2954 void MainWindow::slotFitZoom()
2955 {
2956     if (m_activeTimeline)
2957         m_zoomSlider->setValue(m_activeTimeline->fitZoom());
2958 }
2959
2960 void MainWindow::slotSetZoom(int value)
2961 {
2962     value = qMax(m_zoomSlider->minimum(), value);
2963     value = qMin(m_zoomSlider->maximum(), value);
2964
2965     if (m_activeTimeline)
2966         m_activeTimeline->slotChangeZoom(value);
2967
2968     m_zoomOut->setEnabled(value < m_zoomSlider->maximum());
2969     m_zoomIn->setEnabled(value > m_zoomSlider->minimum());
2970     slotUpdateZoomSliderToolTip(value);
2971
2972     m_zoomSlider->blockSignals(true);
2973     m_zoomSlider->setValue(value);
2974     m_zoomSlider->blockSignals(false);
2975 }
2976
2977 void MainWindow::slotShowZoomSliderToolTip(int zoomlevel)
2978 {
2979     if (zoomlevel != -1)
2980         slotUpdateZoomSliderToolTip(zoomlevel);
2981
2982     QPoint global = m_zoomSlider->rect().topLeft();
2983     global.ry() += m_zoomSlider->height() / 2;
2984     QHelpEvent toolTipEvent(QEvent::ToolTip, QPoint(0, 0), m_zoomSlider->mapToGlobal(global));
2985     QApplication::sendEvent(m_zoomSlider, &toolTipEvent);
2986 }
2987
2988 void MainWindow::slotUpdateZoomSliderToolTip(int zoomlevel)
2989 {
2990     m_zoomSlider->setToolTip(i18n("Zoom Level: %1/13", (13 - zoomlevel)));
2991 }
2992
2993 void MainWindow::slotGotProgressInfo(const QString &message, int progress)
2994 {
2995     m_statusProgressBar->setValue(progress);
2996     if (progress >= 0) {
2997         if (!message.isEmpty())
2998             m_messageLabel->setMessage(message, InformationMessage);//statusLabel->setText(message);
2999         m_statusProgressBar->setVisible(true);
3000     } else if (progress == -2) {
3001         if (!message.isEmpty())
3002             m_messageLabel->setMessage(message, ErrorMessage);
3003         m_statusProgressBar->setVisible(false);
3004     } else {
3005         m_messageLabel->setMessage(QString(), DefaultMessage);
3006         m_statusProgressBar->setVisible(false);
3007     }
3008 }
3009
3010 void MainWindow::slotShowClipProperties(DocClipBase *clip)
3011 {
3012     if (clip->clipType() == TEXT) {
3013         QString titlepath = m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
3014         if (!clip->getProperty("resource").isEmpty() && clip->getProperty("xmldata").isEmpty()) {
3015             // template text clip
3016
3017             // Get the list of existing templates
3018             QStringList filter;
3019             filter << "*.kdenlivetitle";
3020             QStringList templateFiles = QDir(titlepath).entryList(filter, QDir::Files);
3021
3022             QDialog *dia = new QDialog(this);
3023             Ui::TemplateClip_UI dia_ui;
3024             dia_ui.setupUi(dia);
3025             int ix = -1;
3026             const QString templatePath = clip->getProperty("resource");
3027             for (int i = 0; i < templateFiles.size(); ++i) {
3028                 dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), titlepath + templateFiles.at(i));
3029                 if (templatePath == KUrl(titlepath + templateFiles.at(i)).path()) ix = i;
3030             }
3031             if (ix != -1) dia_ui.template_list->comboBox()->setCurrentIndex(ix);
3032             else dia_ui.template_list->comboBox()->insertItem(0, templatePath);
3033             dia_ui.template_list->fileDialog()->setFilter("*.kdenlivetitle");
3034             //warning: setting base directory doesn't work??
3035             KUrl startDir(titlepath);
3036             dia_ui.template_list->fileDialog()->setUrl(startDir);
3037             dia_ui.description->setText(clip->getProperty("description"));
3038             if (dia->exec() == QDialog::Accepted) {
3039                 QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
3040                 if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
3041
3042                 QMap <QString, QString> newprops;
3043
3044                 if (KUrl(textTemplate).path() != templatePath) {
3045                     // The template was changed
3046                     newprops.insert("resource", textTemplate);
3047                 }
3048
3049                 if (dia_ui.description->toPlainText() != clip->getProperty("description")) {
3050                     newprops.insert("description", dia_ui.description->toPlainText());
3051                 }
3052
3053                 QString newtemplate = newprops.value("xmltemplate");
3054                 if (newtemplate.isEmpty()) newtemplate = templatePath;
3055
3056                 // template modified we need to update xmldata
3057                 QString description = newprops.value("description");
3058                 if (description.isEmpty()) description = clip->getProperty("description");
3059                 else newprops.insert("templatetext", description);
3060                 //newprops.insert("xmldata", m_projectList->generateTemplateXml(newtemplate, description).toString());
3061                 if (!newprops.isEmpty()) {
3062                     EditClipCommand *command = new EditClipCommand(m_projectList, clip->getId(), clip->properties(), newprops, true);
3063                     m_activeDocument->commandStack()->push(command);
3064                 }
3065             }
3066             delete dia;
3067             return;
3068         }
3069         QString path = clip->getProperty("resource");
3070         TitleWidget *dia_ui = new TitleWidget(KUrl(), m_activeDocument->timecode(), titlepath, m_projectMonitor->render, this);
3071         QDomDocument doc;
3072         doc.setContent(clip->getProperty("xmldata"));
3073         dia_ui->setXml(doc);
3074         if (dia_ui->exec() == QDialog::Accepted) {
3075             QMap <QString, QString> newprops;
3076             newprops.insert("xmldata", dia_ui->xml().toString());
3077             if (dia_ui->outPoint() != clip->duration().frames(m_activeDocument->fps()) - 1) {
3078                 // duration changed, we need to update duration
3079                 newprops.insert("out", QString::number(dia_ui->outPoint()));
3080             }
3081             EditClipCommand *command = new EditClipCommand(m_projectList, clip->getId(), clip->properties(), newprops, true);
3082             m_activeDocument->commandStack()->push(command);
3083             //m_activeTimeline->projectView()->slotUpdateClip(clip->getId());
3084             m_activeDocument->setModified(true);
3085         }
3086         delete dia_ui;
3087
3088         //m_activeDocument->editTextClip(clip->getProperty("xml"), clip->getId());
3089         return;
3090     }
3091
3092     // any type of clip but a title
3093     ClipProperties *dia = new ClipProperties(clip, m_activeDocument->timecode(), m_activeDocument->fps(), this);
3094     connect(dia, SIGNAL(addMarker(const QString &, GenTime, QString)), m_activeTimeline->projectView(), SLOT(slotAddClipMarker(const QString &, GenTime, QString)));
3095     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)));
3096     dia->show();
3097 }
3098
3099
3100 void MainWindow::slotApplyNewClipProperties(const QString id, QMap <QString, QString> props, QMap <QString, QString> newprops, bool refresh, bool reload)
3101 {
3102     if (newprops.isEmpty()) return;
3103     EditClipCommand *command = new EditClipCommand(m_projectList, id, props, newprops, true);
3104     m_activeDocument->commandStack()->push(command);
3105     m_activeDocument->setModified();
3106
3107     if (refresh) {
3108         // update clip occurences in timeline
3109         m_activeTimeline->projectView()->slotUpdateClip(id, reload);
3110     }
3111 }
3112
3113
3114 void MainWindow::slotShowClipProperties(QList <DocClipBase *> cliplist, QMap<QString, QString> commonproperties)
3115 {
3116     ClipProperties dia(cliplist, m_activeDocument->timecode(), commonproperties, this);
3117     if (dia.exec() == QDialog::Accepted) {
3118         QUndoCommand *command = new QUndoCommand();
3119         command->setText(i18n("Edit clips"));
3120         for (int i = 0; i < cliplist.count(); i++) {
3121             DocClipBase *clip = cliplist.at(i);
3122             new EditClipCommand(m_projectList, clip->getId(), clip->properties(), dia.properties(), true, command);
3123         }
3124         m_activeDocument->commandStack()->push(command);
3125         for (int i = 0; i < cliplist.count(); i++)
3126             m_activeTimeline->projectView()->slotUpdateClip(cliplist.at(i)->getId(), dia.needsTimelineReload());
3127     }
3128 }
3129
3130 void MainWindow::customEvent(QEvent* e)
3131 {
3132     if (e->type() == QEvent::User)
3133         m_messageLabel->setMessage(static_cast <MltErrorEvent *>(e)->message(), MltError);
3134 }
3135 void MainWindow::slotActivateEffectStackView()
3136 {
3137     m_effectStack->raiseWindow(m_effectStackDock);
3138 }
3139
3140 void MainWindow::slotActivateTransitionView(Transition *t)
3141 {
3142     if (t)
3143         m_transitionConfig->raiseWindow(m_transitionConfigDock);
3144 }
3145
3146 void MainWindow::slotSnapRewind()
3147 {
3148     if (m_projectMonitor->isActive()) {
3149         if (m_activeTimeline)
3150             m_activeTimeline->projectView()->slotSeekToPreviousSnap();
3151     } else  {
3152         m_clipMonitor->slotSeekToPreviousSnap();
3153     }
3154 }
3155
3156 void MainWindow::slotSnapForward()
3157 {
3158     if (m_projectMonitor->isActive()) {
3159         if (m_activeTimeline)
3160             m_activeTimeline->projectView()->slotSeekToNextSnap();
3161     } else {
3162         m_clipMonitor->slotSeekToNextSnap();
3163     }
3164 }
3165
3166 void MainWindow::slotClipStart()
3167 {
3168     if (m_projectMonitor->isActive()) {
3169         if (m_activeTimeline)
3170             m_activeTimeline->projectView()->clipStart();
3171     }
3172 }
3173
3174 void MainWindow::slotClipEnd()
3175 {
3176     if (m_projectMonitor->isActive()) {
3177         if (m_activeTimeline)
3178             m_activeTimeline->projectView()->clipEnd();
3179     }
3180 }
3181
3182 void MainWindow::slotZoneStart()
3183 {
3184     if (m_projectMonitor->isActive())
3185         m_projectMonitor->slotZoneStart();
3186     else
3187         m_clipMonitor->slotZoneStart();
3188 }
3189
3190 void MainWindow::slotZoneEnd()
3191 {
3192     if (m_projectMonitor->isActive())
3193         m_projectMonitor->slotZoneEnd();
3194     else
3195         m_clipMonitor->slotZoneEnd();
3196 }
3197
3198 void MainWindow::slotChangeTool(QAction * action)
3199 {
3200     if (action == m_buttonSelectTool)
3201         slotSetTool(SELECTTOOL);
3202     else if (action == m_buttonRazorTool)
3203         slotSetTool(RAZORTOOL);
3204     else if (action == m_buttonSpacerTool)
3205         slotSetTool(SPACERTOOL);
3206 }
3207
3208 void MainWindow::slotChangeEdit(QAction * action)
3209 {
3210     if (!m_activeTimeline)
3211         return;
3212
3213     if (action == m_overwriteEditTool)
3214         m_activeTimeline->projectView()->setEditMode(OVERWRITEEDIT);
3215     else if (action == m_insertEditTool)
3216         m_activeTimeline->projectView()->setEditMode(INSERTEDIT);
3217     else
3218         m_activeTimeline->projectView()->setEditMode(NORMALEDIT);
3219 }
3220
3221 void MainWindow::slotSetTool(PROJECTTOOL tool)
3222 {
3223     if (m_activeDocument && m_activeTimeline) {
3224         //m_activeDocument->setTool(tool);
3225         QString message;
3226         switch (tool)  {
3227         case SPACERTOOL:
3228             message = i18n("Ctrl + click to use spacer on current track only");
3229             break;
3230         case RAZORTOOL:
3231             message = i18n("Click on a clip to cut it");
3232             break;
3233         default:
3234             message = i18n("Shift + click to create a selection rectangle, Ctrl + click to add an item to selection");
3235             break;
3236         }
3237         m_messageLabel->setMessage(message, InformationMessage);
3238         m_activeTimeline->projectView()->setTool(tool);
3239     }
3240 }
3241
3242 void MainWindow::slotCopy()
3243 {
3244     if (m_activeDocument && m_activeTimeline)
3245         m_activeTimeline->projectView()->copyClip();
3246 }
3247
3248 void MainWindow::slotPaste()
3249 {
3250     if (m_activeDocument && m_activeTimeline)
3251         m_activeTimeline->projectView()->pasteClip();
3252 }
3253
3254 void MainWindow::slotPasteEffects()
3255 {
3256     if (m_activeDocument && m_activeTimeline)
3257         m_activeTimeline->projectView()->pasteClipEffects();
3258 }
3259
3260 void MainWindow::slotFind()
3261 {
3262     if (!m_activeDocument || !m_activeTimeline) return;
3263     m_projectSearch->setEnabled(false);
3264     m_findActivated = true;
3265     m_findString.clear();
3266     m_activeTimeline->projectView()->initSearchStrings();
3267     statusBar()->showMessage(i18n("Starting -- find text as you type"));
3268     m_findTimer.start(5000);
3269     qApp->installEventFilter(this);
3270 }
3271
3272 void MainWindow::slotFindNext()
3273 {
3274     if (m_activeTimeline && m_activeTimeline->projectView()->findNextString(m_findString))
3275         statusBar()->showMessage(i18n("Found: %1", m_findString));
3276     else
3277         statusBar()->showMessage(i18n("Reached end of project"));
3278     m_findTimer.start(4000);
3279 }
3280
3281 void MainWindow::findAhead()
3282 {
3283     if (m_activeTimeline && m_activeTimeline->projectView()->findString(m_findString)) {
3284         m_projectSearchNext->setEnabled(true);
3285         statusBar()->showMessage(i18n("Found: %1", m_findString));
3286     } else {
3287         m_projectSearchNext->setEnabled(false);
3288         statusBar()->showMessage(i18n("Not found: %1", m_findString));
3289     }
3290 }
3291
3292 void MainWindow::findTimeout()
3293 {
3294     m_projectSearchNext->setEnabled(false);
3295     m_findActivated = false;
3296     m_findString.clear();
3297     statusBar()->showMessage(i18n("Find stopped"), 3000);
3298     if (m_activeTimeline) m_activeTimeline->projectView()->clearSearchStrings();
3299     m_projectSearch->setEnabled(true);
3300     removeEventFilter(this);
3301 }
3302
3303 void MainWindow::slotClipInTimeline(const QString &clipId)
3304 {
3305     if (m_activeTimeline && m_activeDocument) {
3306         QList<ItemInfo> matching = m_activeTimeline->projectView()->findId(clipId);
3307
3308         QMenu *inTimelineMenu = static_cast<QMenu*>(factory()->container("clip_in_timeline", this));
3309         inTimelineMenu->clear();
3310
3311         QList <QAction *> actionList;
3312
3313         for (int i = 0; i < matching.count(); ++i) {
3314             QString track = QString::number(matching.at(i).track);
3315             QString start = m_activeDocument->timecode().getTimecode(matching.at(i).startPos);
3316             int j = 0;
3317             QAction *a = new QAction(track + ": " + start, this);
3318             a->setData(QStringList() << track << start);
3319             connect(a, SIGNAL(triggered()), this, SLOT(slotSelectClipInTimeline()));
3320             while (j < actionList.count()) {
3321                 if (actionList.at(j)->text() > a->text()) break;
3322                 j++;
3323             }
3324             actionList.insert(j, a);
3325         }
3326         inTimelineMenu->addActions(actionList);
3327
3328         if (matching.empty())
3329             inTimelineMenu->setEnabled(false);
3330         else
3331             inTimelineMenu->setEnabled(true);
3332     }
3333 }
3334
3335 void MainWindow::slotClipInProjectTree()
3336 {
3337     if (m_activeTimeline) {
3338         const QStringList &clipIds = m_activeTimeline->projectView()->selectedClips();
3339         if (clipIds.isEmpty())
3340             return;
3341         m_projectListDock->raise();
3342         for (int i = 0; i < clipIds.count(); i++)
3343             m_projectList->selectItemById(clipIds.at(i));
3344         if (m_projectMonitor->isActive())
3345             slotSwitchMonitors();
3346     }
3347 }
3348
3349 /*void MainWindow::slotClipToProjectTree()
3350 {
3351     if (m_activeTimeline) {
3352     const QList<ClipItem *> clips =  m_activeTimeline->projectView()->selectedClipItems();
3353         if (clips.isEmpty()) return;
3354         for (int i = 0; i < clips.count(); i++) {
3355         m_projectList->slotAddXmlClip(clips.at(i)->itemXml());
3356         }
3357         //m_projectList->selectItemById(clipIds.at(i));
3358     }
3359 }*/
3360
3361 void MainWindow::slotSelectClipInTimeline()
3362 {
3363     if (m_activeTimeline) {
3364         QAction *action = qobject_cast<QAction *>(sender());
3365         QStringList data = action->data().toStringList();
3366         m_activeTimeline->projectView()->selectFound(data.at(0), data.at(1));
3367     }
3368 }
3369
3370 void MainWindow::keyPressEvent(QKeyEvent *ke)
3371 {
3372     if (m_findActivated) {
3373         if (ke->key() == Qt::Key_Backspace) {
3374             m_findString = m_findString.left(m_findString.length() - 1);
3375
3376             if (!m_findString.isEmpty())
3377                 findAhead();
3378             else
3379                 findTimeout();
3380
3381             m_findTimer.start(4000);
3382             ke->accept();
3383             return;
3384         } else if (ke->key() == Qt::Key_Escape) {
3385             findTimeout();
3386             ke->accept();
3387             return;
3388         } else if (ke->key() == Qt::Key_Space || !ke->text().trimmed().isEmpty()) {
3389             m_findString += ke->text();
3390
3391             findAhead();
3392
3393             m_findTimer.start(4000);
3394             ke->accept();
3395             return;
3396         }
3397     } else {
3398         KXmlGuiWindow::keyPressEvent(ke);
3399     }
3400 }
3401
3402
3403 /** Gets called when the window gets hidden */
3404 void MainWindow::hideEvent(QHideEvent */*event*/)
3405 {
3406     if (isMinimized() && m_monitorManager)
3407         m_monitorManager->stopActiveMonitor();
3408 }
3409
3410 bool MainWindow::eventFilter(QObject *obj, QEvent *event)
3411 {
3412     if (m_findActivated) {
3413         if (event->type() == QEvent::ShortcutOverride) {
3414             QKeyEvent* ke = (QKeyEvent*) event;
3415             if (ke->text().trimmed().isEmpty()) return false;
3416             ke->accept();
3417             return true;
3418         } else {
3419             return false;
3420         }
3421     } else {
3422         // pass the event on to the parent class
3423         return QMainWindow::eventFilter(obj, event);
3424     }
3425 }
3426
3427
3428 void MainWindow::slotSaveZone(Render *render, QPoint zone)
3429 {
3430     KDialog *dialog = new KDialog(this);
3431     dialog->setCaption("Save clip zone");
3432     dialog->setButtons(KDialog::Ok | KDialog::Cancel);
3433
3434     QWidget *widget = new QWidget(dialog);
3435     dialog->setMainWidget(widget);
3436
3437     QVBoxLayout *vbox = new QVBoxLayout(widget);
3438     QLabel *label1 = new QLabel(i18n("Save clip zone as:"), this);
3439     QString path = m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash);
3440     path.append("untitled.mlt");
3441     KUrlRequester *url = new KUrlRequester(KUrl(path), this);
3442     url->setFilter("video/mlt-playlist");
3443     QLabel *label2 = new QLabel(i18n("Description:"), this);
3444     KLineEdit *edit = new KLineEdit(this);
3445     vbox->addWidget(label1);
3446     vbox->addWidget(url);
3447     vbox->addWidget(label2);
3448     vbox->addWidget(edit);
3449     if (dialog->exec() == QDialog::Accepted)
3450         render->saveZone(url->url(), edit->text(), zone);
3451
3452 }
3453
3454 void MainWindow::slotSetInPoint()
3455 {
3456     if (m_clipMonitor->isActive())
3457         m_clipMonitor->slotSetZoneStart();
3458     else
3459         m_projectMonitor->slotSetZoneStart();
3460     //else m_activeTimeline->projectView()->setInPoint();
3461 }
3462
3463 void MainWindow::slotSetOutPoint()
3464 {
3465     if (m_clipMonitor->isActive())
3466         m_clipMonitor->slotSetZoneEnd();
3467     else
3468         m_projectMonitor->slotSetZoneEnd();
3469     // else m_activeTimeline->projectView()->setOutPoint();
3470 }
3471
3472 void MainWindow::slotResizeItemStart()
3473 {
3474     if (m_activeTimeline)
3475         m_activeTimeline->projectView()->setInPoint();
3476 }
3477
3478 void MainWindow::slotResizeItemEnd()
3479 {
3480     if (m_activeTimeline)
3481         m_activeTimeline->projectView()->setOutPoint();
3482 }
3483
3484 int MainWindow::getNewStuff(const QString &configFile)
3485 {
3486     KNS3::Entry::List entries;
3487 #if KDE_IS_VERSION(4,3,80)
3488     KNS3::DownloadDialog dialog(configFile);
3489     dialog.exec();
3490     entries = dialog.changedEntries();
3491     foreach(const KNS3::Entry & entry, entries) {
3492         if (entry.status() == KNS3::Entry::Installed)
3493             kDebug() << "// Installed files: " << entry.installedFiles();
3494     }
3495 #else
3496     KNS::Engine engine(0);
3497     if (engine.init(configFile))
3498         entries = engine.downloadDialogModal(this);
3499     foreach(KNS::Entry * entry, entries) {
3500         if (entry->status() == KNS::Entry::Installed)
3501             kDebug() << "// Installed files: " << entry->installedFiles();
3502     }
3503 #endif /* KDE_IS_VERSION(4,3,80) */
3504     return entries.size();
3505 }
3506
3507 void MainWindow::slotGetNewTitleStuff()
3508 {
3509     if (getNewStuff("kdenlive_titles.knsrc") > 0)
3510         TitleWidget::refreshTitleTemplates();
3511 }
3512
3513 void MainWindow::slotGetNewLumaStuff()
3514 {
3515     if (getNewStuff("kdenlive_wipes.knsrc") > 0) {
3516         initEffects::refreshLumas();
3517         m_activeTimeline->projectView()->reloadTransitionLumas();
3518     }
3519 }
3520
3521 void MainWindow::slotGetNewRenderStuff()
3522 {
3523     if (getNewStuff("kdenlive_renderprofiles.knsrc") > 0)
3524         if (m_renderWidget)
3525             m_renderWidget->reloadProfiles();
3526 }
3527
3528 void MainWindow::slotGetNewMltProfileStuff()
3529 {
3530     if (getNewStuff("kdenlive_projectprofiles.knsrc") > 0) {
3531         // update the list of profiles in settings dialog
3532         KdenliveSettingsDialog* d = static_cast <KdenliveSettingsDialog*>(KConfigDialog::exists("settings"));
3533         if (d)
3534             d->checkProfile();
3535     }
3536 }
3537
3538 void MainWindow::slotAutoTransition()
3539 {
3540     if (m_activeTimeline)
3541         m_activeTimeline->projectView()->autoTransition();
3542 }
3543
3544 void MainWindow::slotSplitAudio()
3545 {
3546     if (m_activeTimeline)
3547         m_activeTimeline->projectView()->splitAudio();
3548 }
3549
3550 void MainWindow::slotUpdateClipType(QAction *action)
3551 {
3552     if (m_activeTimeline) {
3553         if (action->data().toString() == "clip_audio_only") m_activeTimeline->projectView()->setAudioOnly();
3554         else if (action->data().toString() == "clip_video_only") m_activeTimeline->projectView()->setVideoOnly();
3555         else m_activeTimeline->projectView()->setAudioAndVideo();
3556     }
3557 }
3558
3559 void MainWindow::slotDvdWizard(const QString &url, const QString &profile)
3560 {
3561     // We must stop the monitors since we create a new on in the dvd wizard
3562     m_clipMonitor->stop();
3563     m_projectMonitor->stop();
3564     DvdWizard w(url, profile, this);
3565     w.exec();
3566     m_projectMonitor->start();
3567 }
3568
3569 void MainWindow::slotShowTimeline(bool show)
3570 {
3571     if (show == false) {
3572         m_timelineState = saveState();
3573         centralWidget()->setHidden(true);
3574     } else {
3575         centralWidget()->setHidden(false);
3576         restoreState(m_timelineState);
3577     }
3578 }
3579
3580 void MainWindow::slotMaximizeCurrent(bool /*show*/)
3581 {
3582     //TODO: is there a way to maximize current widget?
3583     //if (show == true)
3584     {
3585         m_timelineState = saveState();
3586         QWidget *par = focusWidget()->parentWidget();
3587         while (par->parentWidget() && par->parentWidget() != this)
3588             par = par->parentWidget();
3589         kDebug() << "CURRENT WIDGET: " << par->objectName();
3590     }
3591     /*else {
3592     //centralWidget()->setHidden(false);
3593     //restoreState(m_timelineState);
3594     }*/
3595 }
3596
3597 void MainWindow::loadTranscoders()
3598 {
3599     QMenu *transMenu = static_cast<QMenu*>(factory()->container("transcoders", this));
3600     transMenu->clear();
3601
3602     KSharedConfigPtr config = KSharedConfig::openConfig("kdenlivetranscodingrc");
3603     KConfigGroup transConfig(config, "Transcoding");
3604     // read the entries
3605     QMap< QString, QString > profiles = transConfig.entryMap();
3606     QMapIterator<QString, QString> i(profiles);
3607     while (i.hasNext()) {
3608         i.next();
3609         QStringList data = i.value().split(";", QString::SkipEmptyParts);
3610         QAction *a = transMenu->addAction(i.key());
3611         a->setData(data);
3612         if (data.count() > 1)
3613             a->setToolTip(data.at(1));
3614         connect(a, SIGNAL(triggered()), this, SLOT(slotTranscode()));
3615     }
3616 }
3617
3618 void MainWindow::slotTranscode(KUrl::List urls)
3619 {
3620     QString params;
3621     QString desc;
3622     QString condition;
3623     if (urls.isEmpty()) {
3624         QAction *action = qobject_cast<QAction *>(sender());
3625         QStringList data = action->data().toStringList();
3626         params = data.at(0);
3627         if (data.count() > 1) desc = data.at(1);
3628         if (data.count() > 2) condition = data.at(2);
3629         urls << m_projectList->getConditionalUrls(condition);
3630         urls.removeAll(KUrl());
3631     }
3632     if (urls.isEmpty()) {
3633         m_messageLabel->setMessage(i18n("No clip to transcode"), ErrorMessage);
3634         return;
3635     }
3636     ClipTranscode *d = new ClipTranscode(urls, params, desc);
3637     connect(d, SIGNAL(addClip(KUrl)), this, SLOT(slotAddProjectClip(KUrl)));
3638     d->show();
3639     //QProcess::startDetached("ffmpeg", parameters);
3640 }
3641
3642 void MainWindow::slotTranscodeClip()
3643 {
3644     KUrl::List urls = KFileDialog::getOpenUrls(KUrl("kfiledialog:///projectfolder"));
3645     if (urls.isEmpty()) return;
3646     slotTranscode(urls);
3647 }
3648
3649 void MainWindow::slotSetDocumentRenderProfile(QMap <QString, QString> props)
3650 {
3651     if (m_activeDocument == NULL) return;
3652     QMapIterator<QString, QString> i(props);
3653     while (i.hasNext()) {
3654         i.next();
3655         m_activeDocument->setDocumentProperty(i.key(), i.value());
3656     }
3657     m_activeDocument->setModified(true);
3658 }
3659
3660
3661 void MainWindow::slotPrepareRendering(bool scriptExport, bool zoneOnly, const QString &chapterFile)
3662 {
3663     if (m_activeDocument == NULL || m_renderWidget == NULL) return;
3664     QString scriptPath;
3665     QString playlistPath;
3666     if (scriptExport) {
3667         bool ok;
3668         QString scriptsFolder = m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash) + "scripts/";
3669         QString path = m_renderWidget->getFreeScriptName();
3670         scriptPath = QInputDialog::getText(this, i18n("Create Render Script"), i18n("Script name (will be saved in: %1)", scriptsFolder), QLineEdit::Normal, KUrl(path).fileName(), &ok);
3671         if (!ok || scriptPath.isEmpty()) return;
3672         scriptPath.prepend(scriptsFolder);
3673         QFile f(scriptPath);
3674         if (f.exists()) {
3675             if (KMessageBox::warningYesNo(this, i18n("Script file already exists. Do you want to overwrite it?")) != KMessageBox::Yes)
3676                 return;
3677         }
3678         playlistPath = scriptPath + ".mlt";
3679         m_projectMonitor->saveSceneList(playlistPath);
3680     } else {
3681         KTemporaryFile temp;
3682         temp.setAutoRemove(false);
3683         temp.setSuffix(".mlt");
3684         temp.open();
3685         playlistPath = temp.fileName();
3686         m_projectMonitor->saveSceneList(playlistPath);
3687     }
3688
3689     if (!chapterFile.isEmpty()) {
3690         int in = 0;
3691         int out;
3692         if (!zoneOnly) out = (int) GenTime(m_activeDocument->projectDuration()).frames(m_activeDocument->fps());
3693         else {
3694             in = m_activeTimeline->inPoint();
3695             out = m_activeTimeline->outPoint();
3696         }
3697         QDomDocument doc;
3698         QDomElement chapters = doc.createElement("chapters");
3699         chapters.setAttribute("fps", m_activeDocument->fps());
3700         doc.appendChild(chapters);
3701
3702         QDomElement guidesxml = m_activeDocument->guidesXml();
3703         QDomNodeList nodes = guidesxml.elementsByTagName("guide");
3704         for (int i = 0; i < nodes.count(); i++) {
3705             QDomElement e = nodes.item(i).toElement();
3706             if (!e.isNull()) {
3707                 QString comment = e.attribute("comment");
3708                 int time = (int) GenTime(e.attribute("time").toDouble()).frames(m_activeDocument->fps());
3709                 if (time >= in && time < out) {
3710                     if (zoneOnly) time = time - in;
3711                     QDomElement chapter = doc.createElement("chapter");
3712                     chapters.appendChild(chapter);
3713                     chapter.setAttribute("title", comment);
3714                     chapter.setAttribute("time", time);
3715                 }
3716             }
3717         }
3718         if (chapters.childNodes().count() > 0) {
3719             if (m_activeTimeline->projectView()->hasGuide(out, 0) == -1) {
3720                 // Always insert a guide in pos 0
3721                 QDomElement chapter = doc.createElement("chapter");
3722                 chapters.insertBefore(chapter, QDomNode());
3723                 chapter.setAttribute("title", i18n("Start"));
3724                 chapter.setAttribute("time", "0");
3725             }
3726             // save chapters file
3727             QFile file(chapterFile);
3728             if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
3729                 kWarning() << "//////  ERROR writing DVD CHAPTER file: " << chapterFile;
3730             } else {
3731                 file.write(doc.toString().toUtf8());
3732                 if (file.error() != QFile::NoError) {
3733                     kWarning() << "//////  ERROR writing DVD CHAPTER file: " << chapterFile;
3734                 }
3735                 file.close();
3736             }
3737         }
3738     }
3739     bool exportAudio;
3740     if (m_renderWidget->automaticAudioExport()) {
3741         exportAudio = m_activeTimeline->checkProjectAudio();
3742     } else exportAudio = m_renderWidget->selectedAudioExport();
3743     m_renderWidget->slotExport(scriptExport, m_activeTimeline->inPoint(), m_activeTimeline->outPoint(), playlistPath, scriptPath, exportAudio);
3744 }
3745
3746 void MainWindow::slotUpdateTimecodeFormat(int ix)
3747 {
3748     KdenliveSettings::setFrametimecode(ix == 1);
3749     m_clipMonitor->updateTimecodeFormat();
3750     m_projectMonitor->updateTimecodeFormat();
3751     m_transitionConfig->updateTimecodeFormat();
3752     m_effectStack->updateTimecodeFormat();
3753     //m_activeTimeline->projectView()->clearSelection();
3754     m_activeTimeline->updateRuler();
3755 }
3756
3757 void MainWindow::slotRemoveFocus()
3758 {
3759     statusBar()->setFocus();
3760     statusBar()->clearFocus();
3761 }
3762
3763 void MainWindow::slotRevert()
3764 {
3765     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;
3766     KUrl url = m_activeDocument->url();
3767     if (closeCurrentDocument(false))
3768         doOpenFile(url, NULL);
3769 }
3770
3771
3772 void MainWindow::slotShutdown()
3773 {
3774     if (m_activeDocument) m_activeDocument->setModified(false);
3775     // Call shutdown
3776     QDBusConnectionInterface* interface = QDBusConnection::sessionBus().interface();
3777     if (interface && interface->isServiceRegistered("org.kde.ksmserver")) {
3778         QDBusInterface smserver("org.kde.ksmserver", "/KSMServer", "org.kde.KSMServerInterface");
3779         smserver.call("logout", 1, 2, 2);
3780     } else if (interface && interface->isServiceRegistered("org.gnome.SessionManager")) {
3781         QDBusInterface smserver("org.gnome.SessionManager", "/org/gnome/SessionManager", "org.gnome.SessionManager");
3782         smserver.call("Shutdown");
3783     }
3784 }
3785
3786 void MainWindow::slotUpdateTrackInfo()
3787 {
3788     if (m_activeDocument)
3789         m_transitionConfig->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode(), m_activeDocument->tracksList());
3790 }
3791
3792 void MainWindow::slotChangePalette(QAction *action, const QString &themename)
3793 {
3794     // Load the theme file
3795     QString theme;
3796     if (action == NULL) theme = themename;
3797     else theme = action->data().toString();
3798     KdenliveSettings::setColortheme(theme);
3799     // Make palette for all widgets.
3800     QPalette plt;
3801     if (theme.isEmpty())
3802         plt = QApplication::desktop()->palette();
3803     else {
3804         KSharedConfigPtr config = KSharedConfig::openConfig(theme);
3805         plt = KGlobalSettings::createApplicationPalette(config);
3806     }
3807
3808     kapp->setPalette(plt);
3809     const QObjectList children = statusBar()->children();
3810
3811     foreach(QObject * child, children) {
3812         if (child->isWidgetType())
3813             ((QWidget*)child)->setPalette(plt);
3814         const QObjectList subchildren = child->children();
3815         foreach(QObject * subchild, subchildren) {
3816             if (subchild->isWidgetType())
3817                 ((QWidget*)subchild)->setPalette(plt);
3818         }
3819     }
3820     if (m_activeTimeline) {
3821         m_activeTimeline->projectView()->updatePalette();
3822     }
3823 }
3824
3825
3826 QPixmap MainWindow::createSchemePreviewIcon(const KSharedConfigPtr &config)
3827 {
3828     // code taken from kdebase/workspace/kcontrol/colors/colorscm.cpp
3829     const uchar bits1[] = { 0xff, 0xff, 0xff, 0x2c, 0x16, 0x0b };
3830     const uchar bits2[] = { 0x68, 0x34, 0x1a, 0xff, 0xff, 0xff };
3831     const QSize bitsSize(24, 2);
3832     const QBitmap b1 = QBitmap::fromData(bitsSize, bits1);
3833     const QBitmap b2 = QBitmap::fromData(bitsSize, bits2);
3834
3835     QPixmap pixmap(23, 16);
3836     pixmap.fill(Qt::black); // ### use some color other than black for borders?
3837
3838     KConfigGroup group(config, "WM");
3839     QPainter p(&pixmap);
3840     KColorScheme windowScheme(QPalette::Active, KColorScheme::Window, config);
3841     p.fillRect(1,  1, 7, 7, windowScheme.background());
3842     p.fillRect(2,  2, 5, 2, QBrush(windowScheme.foreground().color(), b1));
3843
3844     KColorScheme buttonScheme(QPalette::Active, KColorScheme::Button, config);
3845     p.fillRect(8,  1, 7, 7, buttonScheme.background());
3846     p.fillRect(9,  2, 5, 2, QBrush(buttonScheme.foreground().color(), b1));
3847
3848     p.fillRect(15,  1, 7, 7, group.readEntry("activeBackground", QColor(96, 148, 207)));
3849     p.fillRect(16,  2, 5, 2, QBrush(group.readEntry("activeForeground", QColor(255, 255, 255)), b1));
3850
3851     KColorScheme viewScheme(QPalette::Active, KColorScheme::View, config);
3852     p.fillRect(1,  8, 7, 7, viewScheme.background());
3853     p.fillRect(2, 12, 5, 2, QBrush(viewScheme.foreground().color(), b2));
3854
3855     KColorScheme selectionScheme(QPalette::Active, KColorScheme::Selection, config);
3856     p.fillRect(8,  8, 7, 7, selectionScheme.background());
3857     p.fillRect(9, 12, 5, 2, QBrush(selectionScheme.foreground().color(), b2));
3858
3859     p.fillRect(15,  8, 7, 7, group.readEntry("inactiveBackground", QColor(224, 223, 222)));
3860     p.fillRect(16, 12, 5, 2, QBrush(group.readEntry("inactiveForeground", QColor(20, 19, 18)), b2));
3861
3862     p.end();
3863     return pixmap;
3864 }
3865
3866 void MainWindow::slotSwitchMonitors()
3867 {
3868     m_monitorManager->slotSwitchMonitors(!m_clipMonitor->isActive());
3869     if (m_projectMonitor->isActive()) m_activeTimeline->projectView()->setFocus();
3870     else m_projectList->focusTree();
3871 }
3872
3873 void MainWindow::slotSwitchFullscreen()
3874 {
3875     if (m_projectMonitor->isActive()) m_projectMonitor->slotSwitchFullScreen();
3876     else m_clipMonitor->slotSwitchFullScreen();
3877 }
3878
3879 void MainWindow::slotInsertZoneToTree()
3880 {
3881     if (!m_clipMonitor->isActive() || m_clipMonitor->activeClip() == NULL) return;
3882     QStringList info = m_clipMonitor->getZoneInfo();
3883     m_projectList->slotAddClipCut(info.at(0), info.at(1).toInt(), info.at(2).toInt());
3884 }
3885
3886 void MainWindow::slotInsertZoneToTimeline()
3887 {
3888     if (m_activeTimeline == NULL || m_clipMonitor->activeClip() == NULL) return;
3889     QStringList info = m_clipMonitor->getZoneInfo();
3890     m_activeTimeline->projectView()->insertClipCut(m_clipMonitor->activeClip(), info.at(1).toInt(), info.at(2).toInt());
3891 }
3892
3893
3894 void MainWindow::slotDeleteProjectClips(QStringList ids, QMap<QString, QString> folderids)
3895 {
3896     if (m_activeDocument && m_activeTimeline) {
3897         if (!ids.isEmpty()) {
3898             for (int i = 0; i < ids.size(); ++i) {
3899                 m_activeTimeline->slotDeleteClip(ids.at(i));
3900             }
3901             m_activeDocument->clipManager()->slotDeleteClips(ids);
3902         }
3903         if (!folderids.isEmpty()) m_projectList->deleteProjectFolder(folderids);
3904         m_activeDocument->setModified(true);
3905     }
3906 }
3907
3908 void MainWindow::slotShowTitleBars(bool show)
3909 {
3910     QList <QDockWidget *> docks = findChildren<QDockWidget *>();
3911     for (int i = 0; i < docks.count(); i++) {
3912         QDockWidget* dock = docks.at(i);
3913         if (show) {
3914             dock->setTitleBarWidget(0);
3915         } else {
3916             if (!dock->isFloating()) {
3917                 dock->setTitleBarWidget(new QWidget);
3918             }
3919         }
3920     }
3921     KdenliveSettings::setShowtitlebars(show);
3922 }
3923
3924 void MainWindow::slotSwitchTitles()
3925 {
3926     slotShowTitleBars(!KdenliveSettings::showtitlebars());
3927 }
3928
3929 QString MainWindow::getMimeType()
3930 {
3931     QString mimetype = "application/x-kdenlive";
3932     KMimeType::Ptr mime = KMimeType::mimeType(mimetype);
3933     if (!mime) mimetype = "*.kdenlive";
3934     return mimetype;
3935 }
3936
3937 void MainWindow::slotMonitorRequestRenderFrame(bool request)
3938 {
3939     if (request) {
3940         m_projectMonitor->render->sendFrameForAnalysis = true;
3941         return;
3942     } else {
3943         for (int i = 0; i < m_scopesList.count(); i++) {
3944             if (m_scopesList.at(i)->isVisible() && tabifiedDockWidgets(m_scopesList.at(i)).isEmpty() && static_cast<AbstractScopeWidget *>(m_scopesList.at(i)->widget())->autoRefreshEnabled()) {
3945                 request = true;
3946                 break;
3947             }
3948         }
3949     }
3950     if (!request) {
3951         m_projectMonitor->render->sendFrameForAnalysis = false;
3952     }
3953 }
3954
3955 void MainWindow::slotUpdateScopeFrameRequest()
3956 {
3957     // We need a delay to make sure widgets are hidden after a close event for example
3958     QTimer::singleShot(500, this, SLOT(slotDoUpdateScopeFrameRequest()));
3959 }
3960
3961 void MainWindow::slotDoUpdateScopeFrameRequest()
3962 {
3963     // Check scopes
3964     bool request = false;
3965     for (int i = 0; i < m_scopesList.count(); i++) {
3966         if (!m_scopesList.at(i)->widget()->visibleRegion().isEmpty() && static_cast<AbstractScopeWidget *>(m_scopesList.at(i)->widget())->autoRefreshEnabled()) {
3967             kDebug() << "SCOPE VISIBLE: " << static_cast<AbstractScopeWidget *>(m_scopesList.at(i)->widget())->widgetName();
3968             request = true;
3969             break;
3970         }
3971     }
3972     if (!request) {
3973         if (!m_projectMonitor->effectSceneDisplayed())
3974             m_projectMonitor->render->sendFrameForAnalysis = false;
3975         m_clipMonitor->render->sendFrameForAnalysis = false;
3976     } else {
3977         m_projectMonitor->render->sendFrameForAnalysis = true;
3978         m_clipMonitor->render->sendFrameForAnalysis = true;
3979     }
3980 }
3981
3982 void MainWindow::slotUpdateColorScopes()
3983 {
3984     bool request = false;
3985     for (int i = 0; i < m_scopesList.count(); i++) {
3986         // Check if we need the renderer to send a new frame for update
3987         if (!m_scopesList.at(i)->widget()->visibleRegion().isEmpty() && !(static_cast<AbstractScopeWidget *>(m_scopesList.at(i)->widget())->autoRefreshEnabled())) request = true;
3988         static_cast<AbstractScopeWidget *>(m_scopesList.at(i)->widget())->slotActiveMonitorChanged(m_clipMonitor->isActive());
3989     }
3990     if (request) {
3991         if (m_clipMonitor->isActive()) m_clipMonitor->render->sendFrameUpdate();
3992         else m_projectMonitor->render->sendFrameUpdate();
3993     }
3994 }
3995
3996 void MainWindow::slotOpenStopmotion()
3997 {
3998     if (m_stopmotion == NULL) {
3999         m_stopmotion = new StopmotionWidget(m_activeDocument->projectFolder(), this);
4000         connect(m_stopmotion, SIGNAL(addOrUpdateSequence(const QString)), m_projectList, SLOT(slotAddOrUpdateSequence(const QString)));
4001     }
4002     m_stopmotion->show();
4003 }
4004
4005
4006 void MainWindow::slotDeleteClip(const QString &id)
4007 {
4008     QList <ClipProperties *> list = findChildren<ClipProperties *>();
4009     for (int i = 0; i < list.size(); ++i) {
4010         list.at(i)->disableClipId(id);
4011     }
4012     m_projectList->slotDeleteClip(id);
4013 }
4014
4015 #include "mainwindow.moc"
4016