]> git.sesse.net Git - kdenlive/blob - src/mainwindow.cpp
jogshuttle: add support for shuttles on newer systems - part1
[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 "effectstack/effectstackview2.h"
39 #include "transitionsettings.h"
40 #include "widgets/renderwidget.h"
41 #include "renderer.h"
42 #ifdef USE_JOGSHUTTLE
43 #include "jogshuttle.h"
44 #include "jogaction.h"
45 #include "jogshuttleconfig.h"
46 #endif
47 #include "clipproperties.h"
48 #include "wizard.h"
49 #include "commands/editclipcommand.h"
50 #include "widgets/titlewidget.h"
51 #include "markerdialog.h"
52 #include "clipitem.h"
53 #include "interfaces.h"
54 #include "config-kdenlive.h"
55 #include "cliptranscode.h"
56 #include "ui_templateclip_ui.h"
57 #include "scopes/scopemanager.h"
58 #include "scopes/colorscopes/vectorscope.h"
59 #include "scopes/colorscopes/waveform.h"
60 #include "scopes/colorscopes/rgbparade.h"
61 #include "scopes/colorscopes/histogram.h"
62 #include "scopes/audioscopes/audiosignal.h"
63 #include "scopes/audioscopes/audiospectrum.h"
64 #include "scopes/audioscopes/spectrogram.h"
65 #include "widgets/archivewidget.h"
66 #include "databackup/backupwidget.h"
67 #include "utils/resourcewidget.h"
68
69
70 #include <KApplication>
71 #include <KAction>
72 #include <KLocalizedString>
73 #include <KGlobal>
74 #include <KActionCollection>
75 #include <KActionCategory>
76 #include <KStandardAction>
77 #include <KShortcutsDialog>
78 #include <KFileDialog>
79 #include <KMessageBox>
80 #include <KDebug>
81 #include <KIO/NetAccess>
82 #include <KSaveFile>
83 #include <KRuler>
84 #include <KConfigDialog>
85 #include <KXMLGUIFactory>
86 #include <KStatusBar>
87 #include <kstandarddirs.h>
88 #include <KUrlRequesterDialog>
89 #include <KTemporaryFile>
90 #include <KProcess>
91 #include <KActionMenu>
92 #include <KMenu>
93 #include <ktogglefullscreenaction.h>
94 #include <KFileItem>
95 #include <KNotification>
96 #include <KNotifyConfigWidget>
97 #if KDE_IS_VERSION(4,3,80)
98 #include <knewstuff3/downloaddialog.h>
99 #include <knewstuff3/knewstuffaction.h>
100 #else
101 #include <knewstuff2/engine.h>
102 #include <knewstuff2/ui/knewstuffaction.h>
103 #define KNS3 KNS
104 #endif
105 #include <KToolBar>
106 #include <KColorScheme>
107 #include <KProgressDialog>
108
109 #include <QTextStream>
110 #include <QTimer>
111 #include <QAction>
112 #include <QKeyEvent>
113 #include <QInputDialog>
114 #include <QDesktopWidget>
115 #include <QBitmap>
116 #include <QUndoGroup>
117
118 #include <stdlib.h>
119 #include <locale.h>
120
121 // Uncomment for deeper debugging
122 //#define DEBUG_MAINW
123
124 #ifdef DEBUG_MAINW
125 #include <QDebug>
126 #endif
127
128 static const char version[] = VERSION;
129
130 namespace Mlt
131 {
132 class Producer;
133 };
134
135 Q_DECLARE_METATYPE(QVector<int16_t>)
136
137
138 EffectsList MainWindow::videoEffects;
139 EffectsList MainWindow::audioEffects;
140 EffectsList MainWindow::customEffects;
141 EffectsList MainWindow::transitions;
142
143 QMap <QString,QImage> MainWindow::m_lumacache;
144
145 static bool sortByNames(const QPair<QString, KAction*> &a, const QPair<QString, KAction*> &b)
146 {
147     return a.first < b.first;
148 }
149
150 MainWindow::MainWindow(const QString &MltPath, const KUrl & Url, const QString & clipsToLoad, QWidget *parent) :
151     KXmlGuiWindow(parent),
152     m_activeDocument(NULL),
153     m_activeTimeline(NULL),
154     m_projectList(NULL),
155     m_effectList(NULL),
156     m_effectStack(NULL),
157     m_clipMonitor(NULL),
158     m_projectMonitor(NULL),
159     m_recMonitor(NULL),
160     m_renderWidget(NULL),
161     #ifdef USE_JOGSHUTTLE
162     m_jogProcess(NULL),
163     m_jogShuttle(NULL),
164     #endif
165     m_findActivated(false),
166     m_stopmotion(NULL),
167     m_mainClip(NULL)
168 {
169     qRegisterMetaType<QVector<int16_t> > ();
170     qRegisterMetaType<stringMap> ("stringMap");
171     qRegisterMetaType<audioByteArray> ("audioByteArray");
172
173     // Init locale
174     QLocale systemLocale = QLocale();
175     setlocale(LC_NUMERIC, NULL);
176     char *separator = localeconv()->decimal_point;
177     if (separator != systemLocale.decimalPoint()) {
178         kDebug()<<"------\n!!! system locale is not similar to Qt's locale... be prepared for bugs!!!\n------";
179         // HACK: There is a locale conflict, so set locale to C
180         // Make sure to override exported values or it won't work
181         setenv("LANG", "C", 1);
182         setlocale(LC_NUMERIC, "C");
183         systemLocale = QLocale::c();
184     }
185
186     systemLocale.setNumberOptions(QLocale::OmitGroupSeparator);
187     QLocale::setDefault(systemLocale);
188
189     // Create DBus interface
190     new MainWindowAdaptor(this);
191     QDBusConnection dbus = QDBusConnection::sessionBus();
192     dbus.registerObject("/MainWindow", this);
193
194     if (!KdenliveSettings::colortheme().isEmpty()) slotChangePalette(NULL, KdenliveSettings::colortheme());
195     setFont(KGlobalSettings::toolBarFont());
196     parseProfiles(MltPath);
197     KdenliveSettings::setCurrent_profile(KdenliveSettings::default_profile());
198     m_commandStack = new QUndoGroup;
199     setDockNestingEnabled(true);
200     m_timelineArea = new KTabWidget(this);
201     m_timelineArea->setTabReorderingEnabled(true);
202     m_timelineArea->setTabBarHidden(true);
203     m_timelineArea->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
204     m_timelineArea->setMinimumHeight(200);
205
206     QToolButton *closeTabButton = new QToolButton;
207     connect(closeTabButton, SIGNAL(clicked()), this, SLOT(closeCurrentDocument()));
208     closeTabButton->setIcon(KIcon("tab-close"));
209     closeTabButton->adjustSize();
210     closeTabButton->setToolTip(i18n("Close the current tab"));
211     m_timelineArea->setCornerWidget(closeTabButton);
212     //connect(m_timelineArea, SIGNAL(currentChanged(int)), this, SLOT(activateDocument()));
213
214     connect(&m_findTimer, SIGNAL(timeout()), this, SLOT(findTimeout()));
215     m_findTimer.setSingleShot(true);
216
217     // FIXME: the next call returns a newly allocated object, which leaks
218     initEffects::parseEffectFiles();
219     //initEffects::parseCustomEffectsFile();
220     
221     m_monitorManager = new MonitorManager();
222
223     m_shortcutRemoveFocus = new QShortcut(QKeySequence("Esc"), this);
224     connect(m_shortcutRemoveFocus, SIGNAL(activated()), this, SLOT(slotRemoveFocus()));
225
226
227     /// Add Widgets ///
228
229     m_projectListDock = new QDockWidget(i18n("Project Tree"), this);
230     m_projectListDock->setObjectName("project_tree");
231     m_projectList = new ProjectList();
232     m_projectListDock->setWidget(m_projectList);
233     addDockWidget(Qt::TopDockWidgetArea, m_projectListDock);
234
235     m_clipMonitorDock = new QDockWidget(i18n("Clip Monitor"), this);
236     m_clipMonitorDock->setObjectName("clip_monitor");
237     m_clipMonitor = new Monitor(Kdenlive::ClipMonitor, m_monitorManager, QString(), m_timelineArea);
238     m_clipMonitorDock->setWidget(m_clipMonitor);
239
240     // Connect the project list
241     connect(m_projectList, SIGNAL(clipSelected(DocClipBase*,QPoint,bool)), m_clipMonitor, SLOT(slotSetClipProducer(DocClipBase*,QPoint,bool)));
242     connect(m_projectList, SIGNAL(raiseClipMonitor(bool)), m_clipMonitor, SLOT(slotActivateMonitor(bool)));
243     connect(m_projectList, SIGNAL(loadingIsOver()), this, SLOT(slotElapsedTime()));
244     connect(m_projectList, SIGNAL(displayMessage(QString,int,MessageType)), this, SLOT(slotGotProgressInfo(QString,int,MessageType)));
245     connect(m_projectList, SIGNAL(updateRenderStatus()), this, SLOT(slotCheckRenderStatus()));
246     connect(m_projectList, SIGNAL(clipNeedsReload(QString)),this, SLOT(slotUpdateClip(QString)));
247     connect(m_projectList, SIGNAL(updateProfile(QString)), this, SLOT(slotUpdateProjectProfile(QString)));
248     connect(m_projectList, SIGNAL(refreshClip(QString,bool)), m_monitorManager, SLOT(slotRefreshCurrentMonitor(QString)));
249     connect(m_projectList, SIGNAL(findInTimeline(QString)), this, SLOT(slotClipInTimeline(QString)));
250     connect(m_clipMonitor, SIGNAL(zoneUpdated(QPoint)), m_projectList, SLOT(slotUpdateClipCut(QPoint)));
251     connect(m_clipMonitor, SIGNAL(extractZone(QString,QPoint)), m_projectList, SLOT(slotCutClipJob(QString,QPoint)));
252
253     m_projectMonitorDock = new QDockWidget(i18n("Project Monitor"), this);
254     m_projectMonitorDock->setObjectName("project_monitor");
255     m_projectMonitor = new Monitor(Kdenlive::ProjectMonitor, m_monitorManager, QString());
256     m_projectMonitorDock->setWidget(m_projectMonitor);
257
258 #ifndef Q_WS_MAC
259     m_recMonitorDock = new QDockWidget(i18n("Record Monitor"), this);
260     m_recMonitorDock->setObjectName("record_monitor");
261     m_recMonitor = new RecMonitor(Kdenlive::RecordMonitor, m_monitorManager);
262     m_recMonitorDock->setWidget(m_recMonitor);
263     connect(m_recMonitor, SIGNAL(addProjectClip(KUrl)), this, SLOT(slotAddProjectClip(KUrl)));
264     connect(m_recMonitor, SIGNAL(addProjectClipList(KUrl::List)), this, SLOT(slotAddProjectClipList(KUrl::List)));
265     connect(m_recMonitor, SIGNAL(showConfigDialog(int,int)), this, SLOT(slotPreferences(int,int)));
266
267 #endif /* ! Q_WS_MAC */
268     m_monitorManager->initMonitors(m_clipMonitor, m_projectMonitor, m_recMonitor);
269
270     m_notesDock = new QDockWidget(i18n("Project Notes"), this);
271     m_notesDock->setObjectName("notes_widget");
272     m_notesWidget = new NotesWidget();
273     connect(m_notesWidget, SIGNAL(insertNotesTimecode()), this, SLOT(slotInsertNotesTimecode()));
274     connect(m_notesWidget, SIGNAL(seekProject(int)), m_projectMonitor->render, SLOT(seekToFrame(int)));
275
276     m_notesWidget->setTabChangesFocus(true);
277 #if KDE_IS_VERSION(4,4,0)
278     m_notesWidget->setClickMessage(i18n("Enter your project notes here ..."));
279 #endif
280     m_notesDock->setWidget(m_notesWidget);
281     addDockWidget(Qt::TopDockWidgetArea, m_notesDock);
282
283     m_effectStackDock = new QDockWidget(i18n("Effect Stack"), this);
284     m_effectStackDock->setObjectName("effect_stack");
285     m_effectStack = new EffectStackView2(m_projectMonitor);
286     m_effectStackDock->setWidget(m_effectStack);
287     addDockWidget(Qt::TopDockWidgetArea, m_effectStackDock);
288     connect(m_effectStack, SIGNAL(startFilterJob(ItemInfo,QString,QString,QString,QString,QString,QMap<QString,QString>)), m_projectList, SLOT(slotStartFilterJob(ItemInfo,QString,QString,QString,QString,QString,QMap<QString,QString>)));
289
290     m_transitionConfigDock = new QDockWidget(i18n("Transition"), this);
291     m_transitionConfigDock->setObjectName("transition");
292     m_transitionConfig = new TransitionSettings(m_projectMonitor);
293     m_transitionConfigDock->setWidget(m_transitionConfig);
294     addDockWidget(Qt::TopDockWidgetArea, m_transitionConfigDock);
295
296     m_effectListDock = new QDockWidget(i18n("Effect List"), this);
297     m_effectListDock->setObjectName("effect_list");
298     m_effectList = new EffectsListView();
299     m_effectListDock->setWidget(m_effectList);
300     addDockWidget(Qt::TopDockWidgetArea, m_effectListDock);
301
302     m_scopeManager = new ScopeManager(m_monitorManager);
303     m_vectorscope = new Vectorscope();
304     m_vectorscopeDock = new QDockWidget(i18n("Vectorscope"), this);
305     m_vectorscopeDock->setObjectName(m_vectorscope->widgetName());
306     m_vectorscopeDock->setWidget(m_vectorscope);
307     addDockWidget(Qt::TopDockWidgetArea, m_vectorscopeDock);
308     m_scopeManager->addScope(m_vectorscope, m_vectorscopeDock);
309
310     m_waveform = new Waveform();
311     m_waveformDock = new QDockWidget(i18n("Waveform"), this);
312     m_waveformDock->setObjectName(m_waveform->widgetName());
313     m_waveformDock->setWidget(m_waveform);
314     addDockWidget(Qt::TopDockWidgetArea, m_waveformDock);
315     m_scopeManager->addScope(m_waveform, m_waveformDock);
316
317     m_RGBParade = new RGBParade();
318     m_RGBParadeDock = new QDockWidget(i18n("RGB Parade"), this);
319     m_RGBParadeDock->setObjectName(m_RGBParade->widgetName());
320     m_RGBParadeDock->setWidget(m_RGBParade);
321     addDockWidget(Qt::TopDockWidgetArea, m_RGBParadeDock);
322     m_scopeManager->addScope(m_RGBParade, m_RGBParadeDock);
323
324     m_histogram = new Histogram();
325     m_histogramDock = new QDockWidget(i18n("Histogram"), this);
326     m_histogramDock->setObjectName(m_histogram->widgetName());
327     m_histogramDock->setWidget(m_histogram);
328     addDockWidget(Qt::TopDockWidgetArea, m_histogramDock);
329     m_scopeManager->addScope(m_histogram, m_histogramDock);
330
331     m_audiosignal = new AudioSignal;
332     m_audiosignalDock = new QDockWidget(i18n("Audio Signal"), this);
333     m_audiosignalDock->setObjectName("audiosignal");
334     m_audiosignalDock->setWidget(m_audiosignal);
335     addDockWidget(Qt::TopDockWidgetArea, m_audiosignalDock);
336     m_scopeManager->addScope(m_audiosignal, m_audiosignalDock);
337
338     m_audioSpectrum = new AudioSpectrum();
339     m_audioSpectrumDock = new QDockWidget(i18n("AudioSpectrum"), this);
340     m_audioSpectrumDock->setObjectName(m_audioSpectrum->widgetName());
341     m_audioSpectrumDock->setWidget(m_audioSpectrum);
342     addDockWidget(Qt::TopDockWidgetArea, m_audioSpectrumDock);
343     m_scopeManager->addScope(m_audioSpectrum, m_audioSpectrumDock);
344
345     m_spectrogram = new Spectrogram();
346     m_spectrogramDock = new QDockWidget(i18n("Spectrogram"), this);
347     m_spectrogramDock->setObjectName(m_spectrogram->widgetName());
348     m_spectrogramDock->setWidget(m_spectrogram);
349     addDockWidget(Qt::TopDockWidgetArea, m_spectrogramDock);
350     m_scopeManager->addScope(m_spectrogram, m_spectrogramDock);
351
352     // Add monitors here to keep them at the right of the window
353     addDockWidget(Qt::TopDockWidgetArea, m_clipMonitorDock);
354     addDockWidget(Qt::TopDockWidgetArea, m_projectMonitorDock);
355 #ifndef Q_WS_MAC
356     addDockWidget(Qt::TopDockWidgetArea, m_recMonitorDock);
357 #endif
358
359     m_undoViewDock = new QDockWidget(i18n("Undo History"), this);
360     m_undoViewDock->setObjectName("undo_history");
361     m_undoView = new QUndoView();
362     m_undoView->setCleanIcon(KIcon("edit-clear"));
363     m_undoView->setEmptyLabel(i18n("Clean"));
364     m_undoViewDock->setWidget(m_undoView);
365     m_undoView->setGroup(m_commandStack);
366     addDockWidget(Qt::TopDockWidgetArea, m_undoViewDock);
367
368
369     setupActions();
370     connect(m_commandStack, SIGNAL(cleanChanged(bool)), m_saveAction, SLOT(setDisabled(bool)));
371
372
373     // Close non-general docks for the initial layout
374     // only show important ones
375     m_histogramDock->close();
376     m_RGBParadeDock->close();
377     m_waveformDock->close();
378     m_vectorscopeDock->close();
379
380     m_audioSpectrumDock->close();
381     m_spectrogramDock->close();
382     m_audiosignalDock->close();
383
384     m_undoViewDock->close();
385
386
387
388     /// Tabify Widgets ///
389     tabifyDockWidget(m_effectListDock, m_effectStackDock);
390     tabifyDockWidget(m_effectListDock, m_transitionConfigDock);
391     tabifyDockWidget(m_projectListDock, m_notesDock);
392
393     tabifyDockWidget(m_clipMonitorDock, m_projectMonitorDock);
394 #ifndef Q_WS_MAC
395     tabifyDockWidget(m_clipMonitorDock, m_recMonitorDock);
396 #endif
397     setCentralWidget(m_timelineArea);
398
399     m_fileOpenRecent = KStandardAction::openRecent(this, SLOT(openFile(KUrl)), actionCollection());
400     readOptions();
401     m_fileRevert = KStandardAction::revert(this, SLOT(slotRevert()), actionCollection());
402     m_fileRevert->setEnabled(false);
403
404     // Prepare layout actions
405     KActionCategory *layoutActions = new KActionCategory(i18n("Layouts"), actionCollection());
406     m_loadLayout = new KSelectAction(i18n("Load Layout"), actionCollection());
407     for (int i = 1; i < 5; ++i) {
408         KAction *load = new KAction(KIcon(), i18n("Layout %1", i), this);
409         load->setData('_' + QString::number(i));
410         layoutActions->addAction("load_layout" + QString::number(i), load);
411         m_loadLayout->addAction(load);
412         KAction *save = new KAction(KIcon(), i18n("Save As Layout %1", i), this);
413         save->setData('_' + QString::number(i));
414         layoutActions->addAction("save_layout" + QString::number(i), save);
415     }
416     // Required to enable user to add the load layout action to toolbar
417     layoutActions->addAction("load_layouts", m_loadLayout);
418     connect(m_loadLayout, SIGNAL(triggered(QAction*)), this, SLOT(slotLoadLayout(QAction*)));
419
420     KAction *action;
421     // Stop motion actions. Beware of the order, we MUST use the same order in stopmotion/stopmotion.cpp
422     m_stopmotion_actions = new KActionCategory(i18n("Stop Motion"), actionCollection());
423     action = new KAction(KIcon("media-record"), i18n("Capture frame"), this);
424     //action->setShortcutContext(Qt::WidgetWithChildrenShortcut);
425     m_stopmotion_actions->addAction("stopmotion_capture", action);
426     action = new KAction(i18n("Switch live / captured frame"), this);
427     //action->setShortcutContext(Qt::WidgetWithChildrenShortcut);
428     m_stopmotion_actions->addAction("stopmotion_switch", action);
429     action = new KAction(KIcon("edit-paste"), i18n("Show last frame over video"), this);
430     action->setCheckable(true);
431     action->setChecked(false);
432     m_stopmotion_actions->addAction("stopmotion_overlay", action);
433
434     // Build effects menu
435     m_effectsMenu = new QMenu(i18n("Add Effect"));
436     m_effectActions = new KActionCategory(i18n("Effects"), actionCollection());
437     m_effectList->reloadEffectList(m_effectsMenu, m_effectActions);
438     m_effectsActionCollection->readSettings();
439
440     // Populate View menu with show / hide actions for dock widgets
441     KActionCategory *guiActions = new KActionCategory(i18n("Interface"), actionCollection());
442
443     setupGUI();
444
445     // Find QDockWidget tab bars and show / hide widget title bars on right click
446     QList <QTabBar *> tabs = findChildren<QTabBar *>();
447     for (int i = 0; i < tabs.count(); ++i) {
448         tabs.at(i)->setContextMenuPolicy(Qt::CustomContextMenu);
449         connect(tabs.at(i), SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(slotSwitchTitles()));
450     }
451
452     /*ScriptingPart* sp = new ScriptingPart(this, QStringList());
453     guiFactory()->addClient(sp);*/
454     QMenu *trackMenu = (QMenu*)(factory()->container("track_menu", this));
455     if (trackMenu) trackMenu->addActions(m_tracksActionCollection->actions());
456
457
458     QMenu *saveLayout = (QMenu*)(factory()->container("layout_save_as", this));
459     if (saveLayout)
460         connect(saveLayout, SIGNAL(triggered(QAction*)), this, SLOT(slotSaveLayout(QAction*)));
461
462
463     // Load layout names from config file
464     loadLayouts();
465
466     loadPlugins();
467     loadTranscoders();
468     loadClipActions();
469
470     m_projectMonitor->setupMenu(static_cast<QMenu*>(factory()->container("monitor_go", this)), m_playZone, m_loopZone, NULL, m_loopClip);
471     m_clipMonitor->setupMenu(static_cast<QMenu*>(factory()->container("monitor_go", this)), m_playZone, m_loopZone, static_cast<QMenu*>(factory()->container("marker_menu", this)));
472
473     QMenu *clipInTimeline = static_cast<QMenu*>(factory()->container("clip_in_timeline", this));
474     clipInTimeline->setIcon(KIcon("go-jump"));
475     QHash<QString,QMenu*> menus;
476     menus.insert("addMenu",static_cast<QMenu*>(factory()->container("generators", this)));
477     menus.insert("extractAudioMenu",static_cast<QMenu*>(factory()->container("extract_audio", this)));
478     menus.insert("transcodeMenu",static_cast<QMenu*>(factory()->container("transcoders", this)));
479     menus.insert("clipActionsMenu",static_cast<QMenu*>(factory()->container("clip_actions", this)));
480     menus.insert("inTimelineMenu",clipInTimeline);
481     m_projectList->setupGeneratorMenu(menus);
482
483     // build themes menus
484     QMenu *themesMenu = static_cast<QMenu*>(factory()->container("themes_menu", this));
485     QActionGroup *themegroup = new QActionGroup(this);
486     themegroup->setExclusive(true);
487     action = new KAction(i18n("Default"), this);
488     action->setCheckable(true);
489     themegroup->addAction(action);
490     if (KdenliveSettings::colortheme().isEmpty()) action->setChecked(true);
491
492     const QStringList schemeFiles = KGlobal::dirs()->findAllResources("data", "color-schemes/*.colors", KStandardDirs::NoDuplicates);
493
494     for (int i = 0; i < schemeFiles.size(); ++i) {
495         // get the file name
496         const QString filename = schemeFiles.at(i);
497         const QFileInfo info(filename);
498
499         // add the entry
500         KSharedConfigPtr config = KSharedConfig::openConfig(filename);
501         QIcon icon = createSchemePreviewIcon(config);
502         KConfigGroup group(config, "General");
503         const QString name = group.readEntry("Name", info.baseName());
504         action = new KAction(name, this);
505         action->setData(filename);
506         action->setIcon(icon);
507         action->setCheckable(true);
508         themegroup->addAction(action);
509         if (KdenliveSettings::colortheme() == filename) action->setChecked(true);
510     }
511
512     /*KGlobal::dirs()->addResourceDir("themes", KStandardDirs::installPath("data") + QString("kdenlive/themes"));
513     QStringList themes = KGlobal::dirs()->findAllResources("themes", QString(), KStandardDirs::Recursive | KStandardDirs::NoDuplicates);
514     for (QStringList::const_iterator it = themes.constBegin(); it != themes.constEnd(); ++it)
515     {
516     QFileInfo fi(*it);
517         action = new QAction(fi.fileName(), this);
518         action->setData(*it);
519     action->setCheckable(true);
520     themegroup->addAction(action);
521     if (KdenliveSettings::colortheme() == *it) action->setChecked(true);
522     }*/
523     themesMenu->addActions(themegroup->actions());
524     connect(themesMenu, SIGNAL(triggered(QAction*)), this, SLOT(slotChangePalette(QAction*)));
525
526     // Setup and fill effects and transitions menus.
527
528
529     QMenu *m = static_cast<QMenu*>(factory()->container("video_effects_menu", this));
530     m->addActions(m_effectsMenu->actions());
531
532
533     m_transitionsMenu = new QMenu(i18n("Add Transition"), this);
534     for (int i = 0; i < transitions.count(); ++i)
535         m_transitionsMenu->addAction(m_transitions[i]);
536
537     connect(m, SIGNAL(triggered(QAction*)), this, SLOT(slotAddVideoEffect(QAction*)));
538     connect(m_effectsMenu, SIGNAL(triggered(QAction*)), this, SLOT(slotAddVideoEffect(QAction*)));
539     connect(m_transitionsMenu, SIGNAL(triggered(QAction*)), this, SLOT(slotAddTransition(QAction*)));
540
541     m_timelineContextMenu = new QMenu(this);
542     m_timelineContextClipMenu = new QMenu(this);
543     m_timelineContextTransitionMenu = new QMenu(this);
544
545     m_timelineContextMenu->addAction(actionCollection()->action("insert_space"));
546     m_timelineContextMenu->addAction(actionCollection()->action("delete_space"));
547     m_timelineContextMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Paste)));
548
549     m_timelineContextClipMenu->addAction(actionCollection()->action("clip_in_project_tree"));
550     //m_timelineContextClipMenu->addAction(actionCollection()->action("clip_to_project_tree"));
551     m_timelineContextClipMenu->addAction(actionCollection()->action("delete_timeline_clip"));
552     m_timelineContextClipMenu->addSeparator();
553     m_timelineContextClipMenu->addAction(actionCollection()->action("group_clip"));
554     m_timelineContextClipMenu->addAction(actionCollection()->action("ungroup_clip"));
555     m_timelineContextClipMenu->addAction(actionCollection()->action("split_audio"));
556     m_timelineContextClipMenu->addAction(actionCollection()->action("set_audio_align_ref"));
557     m_timelineContextClipMenu->addAction(actionCollection()->action("align_audio"));
558     m_timelineContextClipMenu->addSeparator();
559     m_timelineContextClipMenu->addAction(actionCollection()->action("cut_timeline_clip"));
560     m_timelineContextClipMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Copy)));
561     m_timelineContextClipMenu->addAction(actionCollection()->action("paste_effects"));
562     m_timelineContextClipMenu->addSeparator();
563
564     QMenu *markersMenu = (QMenu*)(factory()->container("marker_menu", this));
565     m_timelineContextClipMenu->addMenu(markersMenu);
566     m_timelineContextClipMenu->addSeparator();
567     m_timelineContextClipMenu->addMenu(m_transitionsMenu);
568     m_timelineContextClipMenu->addMenu(m_effectsMenu);
569
570     m_timelineContextTransitionMenu->addAction(actionCollection()->action("delete_timeline_clip"));
571     m_timelineContextTransitionMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Copy)));
572
573     m_timelineContextTransitionMenu->addAction(actionCollection()->action("auto_transition"));
574
575     connect(m_projectMonitorDock, SIGNAL(visibilityChanged(bool)), m_projectMonitor, SLOT(refreshMonitor(bool)));
576     connect(m_clipMonitorDock, SIGNAL(visibilityChanged(bool)), m_clipMonitor, SLOT(refreshMonitor(bool)));
577     connect(m_effectList, SIGNAL(addEffect(QDomElement)), this, SLOT(slotAddEffect(QDomElement)));
578     connect(m_effectList, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
579
580     slotConnectMonitors();
581
582 #ifdef USE_JOGSHUTTLE
583     activateShuttleDevice();
584 #endif
585     m_projectListDock->raise();
586
587     actionCollection()->addAssociatedWidget(m_clipMonitor->container());
588     actionCollection()->addAssociatedWidget(m_projectMonitor->container());
589
590     QList<QPair<QString, KAction *> > viewActions;
591     QPair <QString, KAction *> pair;
592     KAction *showTimeline = new KAction(i18n("Timeline"), this);
593     showTimeline->setCheckable(true);
594     showTimeline->setChecked(true);
595     connect(showTimeline, SIGNAL(triggered(bool)), this, SLOT(slotShowTimeline(bool)));
596     
597     KMenu *viewMenu = static_cast<KMenu*>(factory()->container("dockwindows", this));
598     pair.first = showTimeline->text();
599     pair.second = showTimeline;
600     viewActions.append(pair);
601     
602     QList <QDockWidget *> docks = findChildren<QDockWidget *>();
603     for (int i = 0; i < docks.count(); ++i) {
604         QDockWidget* dock = docks.at(i);
605         QAction * a = dock->toggleViewAction();
606         if (!a) continue;
607         KAction* dockInformations = new KAction(this);
608         dockInformations->setText(a->text());
609         dockInformations->setCheckable(true);
610         dockInformations->setChecked(!dock->isHidden());
611         // HACK: since QActions cannot be used in KActionCategory to allow shortcut, we create a duplicate KAction of the dock QAction and link them
612         connect(a,SIGNAL(toggled(bool)), dockInformations, SLOT(setChecked(bool)));
613         connect(dockInformations,SIGNAL(triggered(bool)), a, SLOT(trigger()));
614         pair.first = dockInformations->text();
615         pair.second = dockInformations;
616         viewActions.append(pair);
617     }
618     
619     // Sort dock view action by name
620     qSort(viewActions.begin(), viewActions.end(), sortByNames);
621     // Populate view menu
622     for (int i = 0; i < viewActions.count(); ++i)
623         viewMenu->addAction(guiActions->addAction(viewActions.at(i).first, viewActions.at(i).second));
624     
625     // Populate encoding profiles
626     KConfig conf("encodingprofiles.rc", KConfig::CascadeConfig, "appdata");
627     if (KdenliveSettings::proxyparams().isEmpty() || KdenliveSettings::proxyextension().isEmpty()) {
628         KConfigGroup group(&conf, "proxy");
629         QMap< QString, QString > values = group.entryMap();
630         QMapIterator<QString, QString> i(values);
631         if (i.hasNext()) {
632             i.next();
633             QString data = i.value();
634             KdenliveSettings::setProxyparams(data.section(';', 0, 0));
635             KdenliveSettings::setProxyextension(data.section(';', 1, 1));
636         }
637     }
638     if (KdenliveSettings::v4l_parameters().isEmpty() || KdenliveSettings::v4l_extension().isEmpty()) {
639         KConfigGroup group(&conf, "video4linux");
640         QMap< QString, QString > values = group.entryMap();
641         QMapIterator<QString, QString> i(values);
642         if (i.hasNext()) {
643             i.next();
644             QString data = i.value();
645             KdenliveSettings::setV4l_parameters(data.section(';', 0, 0));
646             KdenliveSettings::setV4l_extension(data.section(';', 1, 1));
647         }
648     }
649     if (KdenliveSettings::grab_parameters().isEmpty() || KdenliveSettings::grab_extension().isEmpty()) {
650         KConfigGroup group(&conf, "screengrab");
651         QMap< QString, QString > values = group.entryMap();
652         QMapIterator<QString, QString> i(values);
653         if (i.hasNext()) {
654             i.next();
655             QString data = i.value();
656             KdenliveSettings::setGrab_parameters(data.section(';', 0, 0));
657             KdenliveSettings::setGrab_extension(data.section(';', 1, 1));
658         }
659     }
660     if (KdenliveSettings::decklink_parameters().isEmpty() || KdenliveSettings::decklink_extension().isEmpty()) {
661         KConfigGroup group(&conf, "decklink");
662         QMap< QString, QString > values = group.entryMap();
663         QMapIterator<QString, QString> i(values);
664         if (i.hasNext()) {
665             i.next();
666             QString data = i.value();
667             KdenliveSettings::setDecklink_parameters(data.section(';', 0, 0));
668             KdenliveSettings::setDecklink_extension(data.section(';', 1, 1));
669         }
670     }
671     
672     connect (KGlobalSettings::self(), SIGNAL(kdisplayPaletteChanged()), this, SLOT(slotChangePalette()));
673
674     // Open or create a file.  Command line argument passed in Url has
675     // precedence, then "openlastproject", then just a plain empty file.
676     // If opening Url fails, openlastproject will _not_ be used.
677     if (!Url.isEmpty()) {
678         // delay loading so that the window shows up
679         m_startUrl = Url;
680         QTimer::singleShot(500, this, SLOT(openFile()));
681     } else if (KdenliveSettings::openlastproject()) {
682         QTimer::singleShot(500, this, SLOT(openLastFile()));
683     } else { //if (m_timelineArea->count() == 0) {
684         newFile(false);
685     }
686
687     if (!clipsToLoad.isEmpty() && m_activeDocument) {
688         QStringList list = clipsToLoad.split(',');
689         QList <QUrl> urls;
690         foreach(const QString &path, list) {
691             kDebug() << QDir::current().absoluteFilePath(path);
692             urls << QUrl::fromLocalFile(QDir::current().absoluteFilePath(path));
693         }
694         m_projectList->slotAddClip(urls);
695     }
696 }
697
698 MainWindow::~MainWindow()
699 {
700     delete m_stopmotion;
701
702 #ifdef USE_JOGSHUTTLE
703     delete m_jogProcess;
704 #endif
705
706     m_effectStack->slotClipItemSelected(NULL);
707     m_transitionConfig->slotTransitionItemSelected(NULL, 0, QPoint(), false);
708
709     if (m_projectMonitor) m_projectMonitor->stop();
710     if (m_clipMonitor) m_clipMonitor->stop();
711
712     delete m_activeTimeline;
713     delete m_effectStack;
714     delete m_transitionConfig;
715     delete m_activeDocument;
716     delete m_projectMonitor;
717     delete m_clipMonitor;
718     delete m_shortcutRemoveFocus;
719     delete[] m_transitions;
720     delete m_monitorManager;
721     delete m_scopeManager;
722     Mlt::Factory::close();
723 }
724
725 //virtual
726 bool MainWindow::queryClose()
727 {
728     if (m_renderWidget) {
729         int waitingJobs = m_renderWidget->waitingJobsCount();
730         if (waitingJobs > 0) {
731             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")))) {
732             case KMessageBox::Yes :
733                 // create script with waiting jobs and start it
734                 if (m_renderWidget->startWaitingRenderJobs() == false) return false;
735                 break;
736             case KMessageBox::No :
737                 // Don't do anything, jobs will be deleted
738                 break;
739             default:
740                 return false;
741             }
742         }
743     }
744     saveOptions();
745     if (m_monitorManager) {
746         m_monitorManager->stopActiveMonitor();
747     }
748
749     // warn the user to save if document is modified and we have clips in our project list
750     if (m_activeDocument && m_activeDocument->isModified() &&
751             ((m_projectList->documentClipList().isEmpty() && !m_activeDocument->url().isEmpty()) ||
752              !m_projectList->documentClipList().isEmpty())) {
753         raise();
754         activateWindow();
755         QString message;
756         if (m_activeDocument->url().fileName().isEmpty()) {
757             message = i18n("Save changes to document?");
758         } else {
759             message = i18n("The project <b>\"%1\"</b> has been changed.\nDo you want to save your changes?", m_activeDocument->url().fileName());
760         }
761         switch (KMessageBox::warningYesNoCancel(this, message)) {
762         case KMessageBox::Yes :
763             // save document here. If saving fails, return false;
764             return saveFile();
765         case KMessageBox::No :
766             // User does not want to save the changes, clear recovery files
767             m_activeDocument->m_autosave->resize(0);
768             return true;
769         default: // cancel
770             return false;
771         }
772     }
773     return true;
774 }
775
776 void MainWindow::loadPlugins()
777 {
778     foreach(QObject * plugin, QPluginLoader::staticInstances()) {
779         populateMenus(plugin);
780     }
781
782     QStringList directories = KGlobal::dirs()->findDirs("module", QString());
783     QStringList filters;
784     filters << "libkdenlive*";
785     foreach(const QString & folder, directories) {
786         kDebug() << "Parsing plugin folder: " << folder;
787         QDir pluginsDir(folder);
788         foreach(const QString & fileName,
789                 pluginsDir.entryList(filters, QDir::Files)) {
790             /*
791              * Avoid loading the same plugin twice when there is more than one
792              * installation.
793              */
794             if (!m_pluginFileNames.contains(fileName)) {
795                 kDebug() << "Found plugin: " << fileName;
796                 QPluginLoader loader(pluginsDir.absoluteFilePath(fileName));
797                 QObject *plugin = loader.instance();
798                 if (plugin) {
799                     populateMenus(plugin);
800                     m_pluginFileNames += fileName;
801                 } else
802                     kDebug() << "Error loading plugin: " << fileName << ", " << loader.errorString();
803             }
804         }
805     }
806 }
807
808 void MainWindow::populateMenus(QObject *plugin)
809 {
810     QMenu *addMenu = static_cast<QMenu*>(factory()->container("generators", this));
811     ClipGenerator *iGenerator = qobject_cast<ClipGenerator *>(plugin);
812     if (iGenerator)
813         addToMenu(plugin, iGenerator->generators(KdenliveSettings::producerslist()), addMenu, SLOT(generateClip()),
814                   NULL);
815 }
816
817 void MainWindow::addToMenu(QObject *plugin, const QStringList &texts,
818                            QMenu *menu, const char *member,
819                            QActionGroup *actionGroup)
820 {
821     kDebug() << "// ADD to MENU" << texts;
822     foreach(const QString & text, texts) {
823         QAction *action = new QAction(text, plugin);
824         action->setData(text);
825         connect(action, SIGNAL(triggered()), this, member);
826         menu->addAction(action);
827
828         if (actionGroup) {
829             action->setCheckable(true);
830             actionGroup->addAction(action);
831         }
832     }
833 }
834
835 void MainWindow::aboutPlugins()
836 {
837     //PluginDialog dialog(pluginsDir.path(), m_pluginFileNames, this);
838     //dialog.exec();
839 }
840
841
842 void MainWindow::generateClip()
843 {
844     QAction *action = qobject_cast<QAction *>(sender());
845     ClipGenerator *iGenerator = qobject_cast<ClipGenerator *>(action->parent());
846
847     KUrl clipUrl = iGenerator->generatedClip(KdenliveSettings::rendererpath(), action->data().toString(), m_activeDocument->projectFolder(),
848                                              QStringList(), QStringList(), m_activeDocument->fps(), m_activeDocument->width(), m_activeDocument->height());
849     if (!clipUrl.isEmpty()) {
850         m_projectList->slotAddClip(QList <QUrl> () << clipUrl);
851     }
852 }
853
854 void MainWindow::saveProperties(KConfigGroup &config)
855 {
856     // save properties here,used by session management
857     saveFile();
858     KMainWindow::saveProperties(config);
859 }
860
861
862 void MainWindow::readProperties(const KConfigGroup &config)
863 {
864     // read properties here,used by session management
865     KMainWindow::readProperties(config);
866     QString Lastproject = config.group("Recent Files").readPathEntry("File1", QString());
867     openFile(KUrl(Lastproject));
868 }
869
870 void MainWindow::slotReloadEffects()
871 {
872     initEffects::parseCustomEffectsFile();
873     m_effectList->reloadEffectList(m_effectsMenu, m_effectActions);
874 }
875
876 #ifdef USE_JOGSHUTTLE
877 void MainWindow::activateShuttleDevice()
878 {
879     delete m_jogShuttle;
880     m_jogShuttle = NULL;
881     delete m_jogProcess;
882     m_jogProcess = NULL;
883     if (KdenliveSettings::enableshuttle() == false) return;
884
885     m_jogProcess = new JogShuttle(JogShuttle::enumerateDevice(KdenliveSettings::shuttledevice()));
886     m_jogShuttle = new JogShuttleAction(m_jogProcess, JogShuttleConfig::actionMap(KdenliveSettings::shuttlebuttons()));
887
888     connect(m_jogShuttle, SIGNAL(rewindOneFrame()), m_monitorManager, SLOT(slotRewindOneFrame()));
889     connect(m_jogShuttle, SIGNAL(forwardOneFrame()), m_monitorManager, SLOT(slotForwardOneFrame()));
890     connect(m_jogShuttle, SIGNAL(rewind(double)), m_monitorManager, SLOT(slotRewind(double)));
891     connect(m_jogShuttle, SIGNAL(forward(double)), m_monitorManager, SLOT(slotForward(double)));
892     connect(m_jogShuttle, SIGNAL(action(QString)), this, SLOT(slotDoAction(QString)));
893 }
894 #endif /* USE_JOGSHUTTLE */
895
896 void MainWindow::slotDoAction(const QString& action_name)
897 {
898     QAction* action = actionCollection()->action(action_name);
899     if (!action) {
900         fprintf(stderr, "%s", QString("shuttle action '%1' unknown\n").arg(action_name).toAscii().constData());
901         return;
902     }
903     action->trigger();
904 }
905
906 void MainWindow::configureNotifications()
907 {
908     KNotifyConfigWidget::configure(this);
909 }
910
911 void MainWindow::slotFullScreen()
912 {
913     KToggleFullScreenAction::setFullScreen(this, actionCollection()->action("fullscreen")->isChecked());
914 }
915
916 void MainWindow::slotAddEffect(const QDomElement &effect)
917 {
918     if (!m_activeDocument) return;
919     if (effect.isNull()) {
920         kDebug() << "--- ERROR, TRYING TO APPEND NULL EFFECT";
921         return;
922     }
923     QDomElement effectToAdd = effect.cloneNode().toElement();
924     bool ok;
925     int ix = m_effectStack->isTrackMode(&ok);
926     if (ok) m_activeTimeline->projectView()->slotAddTrackEffect(effectToAdd, m_activeDocument->tracksCount() - ix);
927     else m_activeTimeline->projectView()->slotAddEffect(effectToAdd, GenTime(), -1);
928 }
929
930 void MainWindow::slotUpdateClip(const QString &id)
931 {
932     if (!m_activeDocument) {
933         return;
934     }
935     DocClipBase *clip = m_activeDocument->clipManager()->getClipById(id);
936     if (!clip) {
937         return;
938     }
939     if (clip->numReferences() > 0) {
940         m_activeTimeline->projectView()->slotUpdateClip(id);
941     }
942     if (m_clipMonitor->activeClip() && m_clipMonitor->activeClip()->getId() == id) {
943         Mlt::Producer *monitorProducer = clip->getCloneProducer();
944         m_clipMonitor->updateClipProducer(monitorProducer);
945     }
946     clip->cleanupProducers();
947 }
948
949 void MainWindow::slotConnectMonitors()
950 {
951     m_projectList->setRenderer(m_projectMonitor->render);
952     connect(m_projectList, SIGNAL(pauseMonitor()), m_monitorManager, SLOT(slotPause()));
953     connect(m_projectList, SIGNAL(deleteProjectClips(QStringList,QMap<QString,QString>)), this, SLOT(slotDeleteProjectClips(QStringList,QMap<QString,QString>)));
954     connect(m_projectList, SIGNAL(showClipProperties(DocClipBase*)), this, SLOT(slotShowClipProperties(DocClipBase*)));
955     connect(m_projectList, SIGNAL(showClipProperties(QList<DocClipBase*>,QMap<QString,QString>)), this, SLOT(slotShowClipProperties(QList<DocClipBase*>,QMap<QString,QString>)));
956     connect(m_projectMonitor->render, SIGNAL(replyGetImage(QString,QString,int,int)), m_projectList, SLOT(slotReplyGetImage(QString,QString,int,int)));
957     connect(m_projectMonitor->render, SIGNAL(replyGetImage(QString,QImage)), m_projectList, SLOT(slotReplyGetImage(QString,QImage)));
958
959     connect(m_projectMonitor->render, SIGNAL(replyGetFileProperties(QString,Mlt::Producer*,stringMap,stringMap,bool)), m_projectList, SLOT(slotReplyGetFileProperties(QString,Mlt::Producer*,stringMap,stringMap,bool)));
960
961     connect(m_projectMonitor->render, SIGNAL(removeInvalidClip(QString,bool)), m_projectList, SLOT(slotRemoveInvalidClip(QString,bool)));
962
963     connect(m_projectMonitor->render, SIGNAL(removeInvalidProxy(QString,bool)), m_projectList, SLOT(slotRemoveInvalidProxy(QString,bool)));
964
965     connect(m_clipMonitor, SIGNAL(refreshClipThumbnail(QString,bool)), m_projectList, SLOT(slotRefreshClipThumbnail(QString,bool)));
966
967     connect(m_clipMonitor, SIGNAL(adjustMonitorSize()), this, SLOT(slotAdjustClipMonitor()));
968     connect(m_projectMonitor, SIGNAL(adjustMonitorSize()), this, SLOT(slotAdjustProjectMonitor()));
969
970     connect(m_projectMonitor, SIGNAL(requestFrameForAnalysis(bool)), this, SLOT(slotMonitorRequestRenderFrame(bool)));
971
972     connect(m_clipMonitor, SIGNAL(saveZone(Render*,QPoint,DocClipBase*)), this, SLOT(slotSaveZone(Render*,QPoint,DocClipBase*)));
973     connect(m_projectMonitor, SIGNAL(saveZone(Render*,QPoint,DocClipBase*)), this, SLOT(slotSaveZone(Render*,QPoint,DocClipBase*)));
974 }
975
976 void MainWindow::slotAdjustClipMonitor()
977 {
978     m_clipMonitorDock->updateGeometry();
979     m_clipMonitorDock->adjustSize();
980     m_clipMonitor->resetSize();
981 }
982
983 void MainWindow::slotAdjustProjectMonitor()
984 {
985     m_projectMonitorDock->updateGeometry();
986     m_projectMonitorDock->adjustSize();
987     m_projectMonitor->resetSize();
988 }
989
990
991 class NameGrabbingKActionCollection {
992 public:
993     NameGrabbingKActionCollection(KActionCollection* collection, QStringList& action_names)
994         : m_collection(collection), m_action_names(action_names) {
995         m_action_names.clear();
996     }
997     KAction* addAction(const QString& action_name) {
998         m_action_names << action_name;
999         return m_collection->addAction(action_name);
1000     }
1001     void addAction(const QString& action_name, QAction* action) {
1002         m_action_names << action_name;
1003         m_collection->addAction(action_name, action);
1004     }
1005     operator KActionCollection*() { return m_collection; }
1006     const QStringList& actionNames() const { return m_action_names; }
1007 private:
1008     KActionCollection* m_collection;
1009     QStringList& m_action_names;
1010 };
1011
1012 void MainWindow::setupActions()
1013 {
1014     NameGrabbingKActionCollection collection(actionCollection(), m_action_names);
1015     m_statusProgressBar = new QProgressBar(this);
1016     m_statusProgressBar->setMinimum(0);
1017     m_statusProgressBar->setMaximum(100);
1018     m_statusProgressBar->setMaximumWidth(150);
1019     m_statusProgressBar->setVisible(false);
1020
1021     KToolBar *toolbar = new KToolBar("statusToolBar", this, Qt::BottomToolBarArea);
1022     toolbar->setMovable(false);
1023     
1024     setStatusBarStyleSheet(palette());
1025     QString styleBorderless = "QToolButton { border-width: 0px;margin: 1px 3px 0px;padding: 0px;}";
1026     
1027     //create edit mode buttons
1028     m_normalEditTool = new KAction(KIcon("kdenlive-normal-edit"), i18n("Normal mode"), this);
1029     m_normalEditTool->setShortcut(i18nc("Normal editing", "n"));
1030     toolbar->addAction(m_normalEditTool);
1031     m_normalEditTool->setCheckable(true);
1032     m_normalEditTool->setChecked(true);
1033
1034     m_overwriteEditTool = new KAction(KIcon("kdenlive-overwrite-edit"), i18n("Overwrite mode"), this);
1035     //m_overwriteEditTool->setShortcut(i18nc("Overwrite mode shortcut", "o"));
1036     toolbar->addAction(m_overwriteEditTool);
1037     m_overwriteEditTool->setCheckable(true);
1038     m_overwriteEditTool->setChecked(false);
1039
1040     m_insertEditTool = new KAction(KIcon("kdenlive-insert-edit"), i18n("Insert mode"), this);
1041     //m_insertEditTool->setShortcut(i18nc("Insert mode shortcut", "i"));
1042     toolbar->addAction(m_insertEditTool);
1043     m_insertEditTool->setCheckable(true);
1044     m_insertEditTool->setChecked(false);
1045     // not implemented yet
1046     m_insertEditTool->setEnabled(false);
1047
1048     QActionGroup *editGroup = new QActionGroup(this);
1049     editGroup->addAction(m_normalEditTool);
1050     editGroup->addAction(m_overwriteEditTool);
1051     editGroup->addAction(m_insertEditTool);
1052     editGroup->setExclusive(true);
1053     connect(editGroup, SIGNAL(triggered(QAction*)), this, SLOT(slotChangeEdit(QAction*)));
1054     //connect(m_overwriteEditTool, SIGNAL(toggled(bool)), this, SLOT(slotSetOverwriteMode(bool)));
1055
1056     toolbar->addSeparator();
1057
1058     // create tools buttons
1059     m_buttonSelectTool = new KAction(KIcon("kdenlive-select-tool"), i18n("Selection tool"), this);
1060     m_buttonSelectTool->setShortcut(i18nc("Selection tool shortcut", "s"));
1061     toolbar->addAction(m_buttonSelectTool);
1062     m_buttonSelectTool->setCheckable(true);
1063     m_buttonSelectTool->setChecked(true);
1064
1065     m_buttonRazorTool = new KAction(KIcon("edit-cut"), i18n("Razor tool"), this);
1066     m_buttonRazorTool->setShortcut(i18nc("Razor tool shortcut", "x"));
1067     toolbar->addAction(m_buttonRazorTool);
1068     m_buttonRazorTool->setCheckable(true);
1069     m_buttonRazorTool->setChecked(false);
1070
1071     m_buttonSpacerTool = new KAction(KIcon("kdenlive-spacer-tool"), i18n("Spacer tool"), this);
1072     m_buttonSpacerTool->setShortcut(i18nc("Spacer tool shortcut", "m"));
1073     toolbar->addAction(m_buttonSpacerTool);
1074     m_buttonSpacerTool->setCheckable(true);
1075     m_buttonSpacerTool->setChecked(false);
1076
1077     QActionGroup *toolGroup = new QActionGroup(this);
1078     toolGroup->addAction(m_buttonSelectTool);
1079     toolGroup->addAction(m_buttonRazorTool);
1080     toolGroup->addAction(m_buttonSpacerTool);
1081     toolGroup->setExclusive(true);
1082     toolbar->setToolButtonStyle(Qt::ToolButtonIconOnly);
1083
1084     QWidget * actionWidget;
1085     int max = toolbar->iconSizeDefault() + 2;
1086     actionWidget = toolbar->widgetForAction(m_normalEditTool);
1087     actionWidget->setMaximumWidth(max);
1088     actionWidget->setMaximumHeight(max - 4);
1089
1090     actionWidget = toolbar->widgetForAction(m_insertEditTool);
1091     actionWidget->setMaximumWidth(max);
1092     actionWidget->setMaximumHeight(max - 4);
1093
1094     actionWidget = toolbar->widgetForAction(m_overwriteEditTool);
1095     actionWidget->setMaximumWidth(max);
1096     actionWidget->setMaximumHeight(max - 4);
1097
1098     actionWidget = toolbar->widgetForAction(m_buttonSelectTool);
1099     actionWidget->setMaximumWidth(max);
1100     actionWidget->setMaximumHeight(max - 4);
1101
1102     actionWidget = toolbar->widgetForAction(m_buttonRazorTool);
1103     actionWidget->setMaximumWidth(max);
1104     actionWidget->setMaximumHeight(max - 4);
1105
1106     actionWidget = toolbar->widgetForAction(m_buttonSpacerTool);
1107     actionWidget->setMaximumWidth(max);
1108     actionWidget->setMaximumHeight(max - 4);
1109
1110     connect(toolGroup, SIGNAL(triggered(QAction*)), this, SLOT(slotChangeTool(QAction*)));
1111
1112     toolbar->addSeparator();
1113     m_buttonFitZoom = new KAction(KIcon("zoom-fit-best"), i18n("Fit zoom to project"), this);
1114     toolbar->addAction(m_buttonFitZoom);
1115     m_buttonFitZoom->setCheckable(false);
1116
1117     m_zoomOut = new KAction(KIcon("zoom-out"), i18n("Zoom Out"), this);
1118     toolbar->addAction(m_zoomOut);
1119     m_zoomOut->setShortcut(Qt::CTRL + Qt::Key_Minus);
1120
1121     m_zoomSlider = new QSlider(Qt::Horizontal, this);
1122     m_zoomSlider->setMaximum(13);
1123     m_zoomSlider->setPageStep(1);
1124     m_zoomSlider->setInvertedAppearance(true);
1125
1126     m_zoomSlider->setMaximumWidth(150);
1127     m_zoomSlider->setMinimumWidth(100);
1128     toolbar->addWidget(m_zoomSlider);
1129
1130     m_zoomIn = new KAction(KIcon("zoom-in"), i18n("Zoom In"), this);
1131     toolbar->addAction(m_zoomIn);
1132     m_zoomIn->setShortcut(Qt::CTRL + Qt::Key_Plus);
1133
1134     actionWidget = toolbar->widgetForAction(m_buttonFitZoom);
1135     actionWidget->setMaximumWidth(max);
1136     actionWidget->setMaximumHeight(max - 4);
1137     actionWidget->setStyleSheet(styleBorderless);
1138
1139     actionWidget = toolbar->widgetForAction(m_zoomIn);
1140     actionWidget->setMaximumWidth(max);
1141     actionWidget->setMaximumHeight(max - 4);
1142     actionWidget->setStyleSheet(styleBorderless);
1143
1144     actionWidget = toolbar->widgetForAction(m_zoomOut);
1145     actionWidget->setMaximumWidth(max);
1146     actionWidget->setMaximumHeight(max - 4);
1147     actionWidget->setStyleSheet(styleBorderless);
1148
1149     connect(m_zoomSlider, SIGNAL(valueChanged(int)), this, SLOT(slotSetZoom(int)));
1150     connect(m_zoomSlider, SIGNAL(sliderMoved(int)), this, SLOT(slotShowZoomSliderToolTip(int)));
1151     connect(m_buttonFitZoom, SIGNAL(triggered()), this, SLOT(slotFitZoom()));
1152     connect(m_zoomIn, SIGNAL(triggered(bool)), this, SLOT(slotZoomIn()));
1153     connect(m_zoomOut, SIGNAL(triggered(bool)), this, SLOT(slotZoomOut()));
1154
1155     toolbar->addSeparator();
1156
1157     //create automatic audio split button
1158     m_buttonAutomaticSplitAudio = new KAction(KIcon("kdenlive-split-audio"), i18n("Split audio and video automatically"), this);
1159     toolbar->addAction(m_buttonAutomaticSplitAudio);
1160     m_buttonAutomaticSplitAudio->setCheckable(true);
1161     m_buttonAutomaticSplitAudio->setChecked(KdenliveSettings::splitaudio());
1162     connect(m_buttonAutomaticSplitAudio, SIGNAL(triggered()), this, SLOT(slotSwitchSplitAudio()));
1163
1164     m_buttonVideoThumbs = new KAction(KIcon("kdenlive-show-videothumb"), i18n("Show video thumbnails"), this);
1165     toolbar->addAction(m_buttonVideoThumbs);
1166     m_buttonVideoThumbs->setCheckable(true);
1167     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
1168     connect(m_buttonVideoThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchVideoThumbs()));
1169
1170     m_buttonAudioThumbs = new KAction(KIcon("kdenlive-show-audiothumb"), i18n("Show audio thumbnails"), this);
1171     toolbar->addAction(m_buttonAudioThumbs);
1172     m_buttonAudioThumbs->setCheckable(true);
1173     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
1174     connect(m_buttonAudioThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchAudioThumbs()));
1175
1176     m_buttonShowMarkers = new KAction(KIcon("kdenlive-show-markers"), i18n("Show markers comments"), this);
1177     toolbar->addAction(m_buttonShowMarkers);
1178     m_buttonShowMarkers->setCheckable(true);
1179     m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
1180     connect(m_buttonShowMarkers, SIGNAL(triggered()), this, SLOT(slotSwitchMarkersComments()));
1181
1182     m_buttonSnap = new KAction(KIcon("kdenlive-snap"), i18n("Snap"), this);
1183     toolbar->addAction(m_buttonSnap);
1184     m_buttonSnap->setCheckable(true);
1185     m_buttonSnap->setChecked(KdenliveSettings::snaptopoints());
1186     connect(m_buttonSnap, SIGNAL(triggered()), this, SLOT(slotSwitchSnap()));
1187
1188     actionWidget = toolbar->widgetForAction(m_buttonAutomaticSplitAudio);
1189     actionWidget->setMaximumWidth(max);
1190     actionWidget->setMaximumHeight(max - 4);
1191
1192     actionWidget = toolbar->widgetForAction(m_buttonVideoThumbs);
1193     actionWidget->setMaximumWidth(max);
1194     actionWidget->setMaximumHeight(max - 4);
1195
1196     actionWidget = toolbar->widgetForAction(m_buttonAudioThumbs);
1197     actionWidget->setMaximumWidth(max);
1198     actionWidget->setMaximumHeight(max - 4);
1199
1200     actionWidget = toolbar->widgetForAction(m_buttonShowMarkers);
1201     actionWidget->setMaximumWidth(max);
1202     actionWidget->setMaximumHeight(max - 4);
1203
1204     actionWidget = toolbar->widgetForAction(m_buttonSnap);
1205     actionWidget->setMaximumWidth(max);
1206     actionWidget->setMaximumHeight(max - 4);
1207
1208     m_messageLabel = new StatusBarMessageLabel(this);
1209     m_messageLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding);
1210
1211     statusBar()->addWidget(m_messageLabel, 10);
1212     statusBar()->addWidget(m_statusProgressBar, 0);
1213     statusBar()->addPermanentWidget(toolbar);
1214
1215     m_timeFormatButton = new KSelectAction("00:00:00:00 / 00:00:00:00", this);
1216     m_timeFormatButton->addAction(i18n("hh:mm:ss:ff"));
1217     m_timeFormatButton->addAction(i18n("Frames"));
1218     if (KdenliveSettings::frametimecode()) m_timeFormatButton->setCurrentItem(1);
1219     else m_timeFormatButton->setCurrentItem(0);
1220     connect(m_timeFormatButton, SIGNAL(triggered(int)), this, SLOT(slotUpdateTimecodeFormat(int)));
1221     m_timeFormatButton->setToolBarMode(KSelectAction::MenuMode);
1222     toolbar->addAction(m_timeFormatButton);
1223
1224     const QFontMetrics metric(statusBar()->font());
1225     int requiredWidth = metric.boundingRect("00:00:00:00 / 00:00:00:00").width() + 20;
1226     actionWidget = toolbar->widgetForAction(m_timeFormatButton);
1227     actionWidget->setObjectName("timecode");
1228     actionWidget->setMinimumWidth(requiredWidth);
1229
1230     collection.addAction("normal_mode", m_normalEditTool);
1231     collection.addAction("overwrite_mode", m_overwriteEditTool);
1232     collection.addAction("insert_mode", m_insertEditTool);
1233     collection.addAction("select_tool", m_buttonSelectTool);
1234     collection.addAction("razor_tool", m_buttonRazorTool);
1235     collection.addAction("spacer_tool", m_buttonSpacerTool);
1236
1237     collection.addAction("automatic_split_audio", m_buttonAutomaticSplitAudio);
1238     collection.addAction("show_video_thumbs", m_buttonVideoThumbs);
1239     collection.addAction("show_audio_thumbs", m_buttonAudioThumbs);
1240     collection.addAction("show_markers", m_buttonShowMarkers);
1241     collection.addAction("snap", m_buttonSnap);
1242     collection.addAction("zoom_fit", m_buttonFitZoom);
1243     collection.addAction("zoom_in", m_zoomIn);
1244     collection.addAction("zoom_out", m_zoomOut);
1245
1246     m_projectSearch = new KAction(KIcon("edit-find"), i18n("Find"), this);
1247     collection.addAction("project_find", m_projectSearch);
1248     connect(m_projectSearch, SIGNAL(triggered(bool)), this, SLOT(slotFind()));
1249     m_projectSearch->setShortcut(Qt::Key_Slash);
1250
1251     m_projectSearchNext = new KAction(KIcon("go-down-search"), i18n("Find Next"), this);
1252     collection.addAction("project_find_next", m_projectSearchNext);
1253     connect(m_projectSearchNext, SIGNAL(triggered(bool)), this, SLOT(slotFindNext()));
1254     m_projectSearchNext->setShortcut(Qt::Key_F3);
1255     m_projectSearchNext->setEnabled(false);
1256
1257     KAction* profilesAction = new KAction(KIcon("document-new"), i18n("Manage Project Profiles"), this);
1258     collection.addAction("manage_profiles", profilesAction);
1259     connect(profilesAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProfiles()));
1260
1261     KNS3::standardAction(i18n("Download New Wipes..."),            this, SLOT(slotGetNewLumaStuff()),       actionCollection(), "get_new_lumas");
1262     KNS3::standardAction(i18n("Download New Render Profiles..."),  this, SLOT(slotGetNewRenderStuff()),     actionCollection(), "get_new_profiles");
1263     KNS3::standardAction(i18n("Download New Project Profiles..."), this, SLOT(slotGetNewMltProfileStuff()), actionCollection(), "get_new_mlt_profiles");
1264     KNS3::standardAction(i18n("Download New Title Templates..."),  this, SLOT(slotGetNewTitleStuff()),      actionCollection(), "get_new_titles");
1265
1266     KAction* wizAction = new KAction(KIcon("configure"), i18n("Run Config Wizard"), this);
1267     collection.addAction("run_wizard", wizAction);
1268     connect(wizAction, SIGNAL(triggered(bool)), this, SLOT(slotRunWizard()));
1269
1270     KAction* projectAction = new KAction(KIcon("configure"), i18n("Project Settings"), this);
1271     collection.addAction("project_settings", projectAction);
1272     connect(projectAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProjectSettings()));
1273
1274     KAction* backupAction = new KAction(KIcon("edit-undo"), i18n("Open Backup File"), this);
1275     collection.addAction("open_backup", backupAction);
1276     connect(backupAction, SIGNAL(triggered(bool)), this, SLOT(slotOpenBackupDialog()));
1277
1278     KAction* projectRender = new KAction(KIcon("media-record"), i18n("Render"), this);
1279     collection.addAction("project_render", projectRender);
1280     projectRender->setShortcut(Qt::CTRL + Qt::Key_Return);
1281     connect(projectRender, SIGNAL(triggered(bool)), this, SLOT(slotRenderProject()));
1282
1283     KAction* projectClean = new KAction(KIcon("edit-clear"), i18n("Clean Project"), this);
1284     collection.addAction("project_clean", projectClean);
1285     connect(projectClean, SIGNAL(triggered(bool)), this, SLOT(slotCleanProject()));
1286
1287     KAction* projectAdjust = new KAction(KIcon(), i18n("Adjust Profile to Current Clip"), this);
1288     collection.addAction("project_adjust_profile", projectAdjust);
1289     connect(projectAdjust, SIGNAL(triggered(bool)), m_projectList, SLOT(adjustProjectProfileToItem()));
1290
1291     KAction* monitorPlay = new KAction(KIcon("media-playback-start"), i18n("Play"), this);
1292     monitorPlay->setShortcut(Qt::Key_Space);
1293     collection.addAction("monitor_play", monitorPlay);
1294     connect(monitorPlay, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotPlay()));
1295
1296     KAction* monitorPause = new KAction(KIcon("media-playback-stop"), i18n("Pause"), this);
1297     monitorPause->setShortcut(Qt::Key_K);
1298     collection.addAction("monitor_pause", monitorPause);
1299     connect(monitorPause, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotPause()));
1300
1301     m_playZone = new KAction(KIcon("media-playback-start"), i18n("Play Zone"), this);
1302     m_playZone->setShortcut(Qt::CTRL + Qt::Key_Space);
1303     collection.addAction("monitor_play_zone", m_playZone);
1304     connect(m_playZone, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotPlayZone()));
1305
1306     m_loopZone = new KAction(KIcon("media-playback-start"), i18n("Loop Zone"), this);
1307     m_loopZone->setShortcut(Qt::ALT + Qt::Key_Space);
1308     collection.addAction("monitor_loop_zone", m_loopZone);
1309     connect(m_loopZone, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotLoopZone()));
1310
1311     m_loopClip = new KAction(KIcon("media-playback-start"), i18n("Loop selected clip"), this);
1312     m_loopClip->setEnabled(false);
1313     collection.addAction("monitor_loop_clip", m_loopClip);
1314     connect(m_loopClip, SIGNAL(triggered(bool)), m_projectMonitor, SLOT(slotLoopClip()));
1315
1316     KAction *dvdWizard =  new KAction(KIcon("media-optical"), i18n("DVD Wizard"), this);
1317     collection.addAction("dvd_wizard", dvdWizard);
1318     connect(dvdWizard, SIGNAL(triggered(bool)), this, SLOT(slotDvdWizard()));
1319
1320     KAction *transcodeClip =  new KAction(KIcon("edit-copy"), i18n("Transcode Clips"), this);
1321     collection.addAction("transcode_clip", transcodeClip);
1322     connect(transcodeClip, SIGNAL(triggered(bool)), this, SLOT(slotTranscodeClip()));
1323
1324     KAction *archiveProject =  new KAction(KIcon("file-save"), i18n("Archive Project"), this);
1325     collection.addAction("archive_project", archiveProject);
1326     connect(archiveProject, SIGNAL(triggered(bool)), this, SLOT(slotArchiveProject()));
1327
1328
1329     KAction *markIn = collection.addAction("mark_in");
1330     markIn->setText(i18n("Set Zone In"));
1331     markIn->setShortcut(Qt::Key_I);
1332     connect(markIn, SIGNAL(triggered(bool)), this, SLOT(slotSetInPoint()));
1333
1334     KAction *markOut = collection.addAction("mark_out");
1335     markOut->setText(i18n("Set Zone Out"));
1336     markOut->setShortcut(Qt::Key_O);
1337     connect(markOut, SIGNAL(triggered(bool)), this, SLOT(slotSetOutPoint()));
1338
1339     KAction *switchMon = collection.addAction("switch_monitor");
1340     switchMon->setText(i18n("Switch monitor"));
1341     switchMon->setShortcut(Qt::Key_T);
1342     connect(switchMon, SIGNAL(triggered(bool)), this, SLOT(slotSwitchMonitors()));
1343
1344     KAction *fullMon = collection.addAction("monitor_fullscreen");
1345     fullMon->setText(i18n("Switch monitor fullscreen"));
1346     fullMon->setIcon(KIcon("view-fullscreen"));
1347     connect(fullMon, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotSwitchFullscreen()));
1348     
1349     KSelectAction *interlace = new KSelectAction(i18n("Deinterlacer"), this);
1350     interlace->addAction(i18n("One Field (fast)"));
1351     interlace->addAction(i18n("Linear Blend (fast)"));
1352     interlace->addAction(i18n("YADIF - temporal only (good)"));
1353     interlace->addAction(i18n("YADIF - temporal + spacial (best)"));
1354     if (KdenliveSettings::mltdeinterlacer() == "linearblend") interlace->setCurrentItem(1);
1355     else if (KdenliveSettings::mltdeinterlacer() == "yadif-temporal") interlace->setCurrentItem(2);
1356     else if (KdenliveSettings::mltdeinterlacer() == "yadif") interlace->setCurrentItem(3);
1357     else interlace->setCurrentItem(0);
1358     collection.addAction("mlt_interlace", interlace);
1359     connect(interlace, SIGNAL(triggered(int)), this, SLOT(slotSetDeinterlacer(int)));
1360     
1361     KSelectAction *interpol = new KSelectAction(i18n("Interpolation"), this);
1362     interpol->addAction(i18n("Nearest Neighbor (fast)"));
1363     interpol->addAction(i18n("Bilinear (good)"));
1364     interpol->addAction(i18n("Bicubic (better)"));
1365     interpol->addAction(i18n("Hyper/Lanczos (best)"));
1366     if (KdenliveSettings::mltinterpolation() == "bilinear") interpol->setCurrentItem(1);
1367     else if (KdenliveSettings::mltinterpolation() == "bicubic") interpol->setCurrentItem(2);
1368     else if (KdenliveSettings::mltinterpolation() == "hyper") interpol->setCurrentItem(3);
1369     else interpol->setCurrentItem(0);
1370     collection.addAction("mlt_interpolation", interpol);
1371     connect(interpol, SIGNAL(triggered(int)), this, SLOT(slotSetInterpolation(int)));
1372
1373     KAction *insertTree = collection.addAction("insert_project_tree");
1374     insertTree->setText(i18n("Insert zone in project tree"));
1375     insertTree->setShortcut(Qt::CTRL + Qt::Key_I);
1376     connect(insertTree, SIGNAL(triggered(bool)), this, SLOT(slotInsertZoneToTree()));
1377
1378     KAction *insertTimeline = collection.addAction("insert_timeline");
1379     insertTimeline->setText(i18n("Insert zone in timeline"));
1380     insertTimeline->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_I);
1381     connect(insertTimeline, SIGNAL(triggered(bool)), this, SLOT(slotInsertZoneToTimeline()));
1382
1383     KAction *resizeStart =  new KAction(KIcon(), i18n("Resize Item Start"), this);
1384     collection.addAction("resize_timeline_clip_start", resizeStart);
1385     resizeStart->setShortcut(Qt::Key_1);
1386     connect(resizeStart, SIGNAL(triggered(bool)), this, SLOT(slotResizeItemStart()));
1387
1388     KAction *resizeEnd =  new KAction(KIcon(), i18n("Resize Item End"), this);
1389     collection.addAction("resize_timeline_clip_end", resizeEnd);
1390     resizeEnd->setShortcut(Qt::Key_2);
1391     connect(resizeEnd, SIGNAL(triggered(bool)), this, SLOT(slotResizeItemEnd()));
1392
1393     KAction* monitorSeekBackward = new KAction(KIcon("media-seek-backward"), i18n("Rewind"), this);
1394     monitorSeekBackward->setShortcut(Qt::Key_J);
1395     collection.addAction("monitor_seek_backward", monitorSeekBackward);
1396     connect(monitorSeekBackward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewind()));
1397
1398     KAction* monitorSeekBackwardOneFrame = new KAction(KIcon("media-skip-backward"), i18n("Rewind 1 Frame"), this);
1399     monitorSeekBackwardOneFrame->setShortcut(Qt::Key_Left);
1400     collection.addAction("monitor_seek_backward-one-frame", monitorSeekBackwardOneFrame);
1401     connect(monitorSeekBackwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewindOneFrame()));
1402
1403     KAction* monitorSeekBackwardOneSecond = new KAction(KIcon("media-skip-backward"), i18n("Rewind 1 Second"), this);
1404     monitorSeekBackwardOneSecond->setShortcut(Qt::SHIFT + Qt::Key_Left);
1405     collection.addAction("monitor_seek_backward-one-second", monitorSeekBackwardOneSecond);
1406     connect(monitorSeekBackwardOneSecond, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewindOneSecond()));
1407
1408     KAction* monitorSeekSnapBackward = new KAction(KIcon("media-seek-backward"), i18n("Go to Previous Snap Point"), this);
1409     monitorSeekSnapBackward->setShortcut(Qt::ALT + Qt::Key_Left);
1410     collection.addAction("monitor_seek_snap_backward", monitorSeekSnapBackward);
1411     connect(monitorSeekSnapBackward, SIGNAL(triggered(bool)), this, SLOT(slotSnapRewind()));
1412
1413     KAction* monitorSeekForward = new KAction(KIcon("media-seek-forward"), i18n("Forward"), this);
1414     monitorSeekForward->setShortcut(Qt::Key_L);
1415     collection.addAction("monitor_seek_forward", monitorSeekForward);
1416     connect(monitorSeekForward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForward()));
1417
1418     KAction* clipStart = new KAction(KIcon("media-seek-backward"), i18n("Go to Clip Start"), this);
1419     clipStart->setShortcut(Qt::Key_Home);
1420     collection.addAction("seek_clip_start", clipStart);
1421     connect(clipStart, SIGNAL(triggered(bool)), this, SLOT(slotClipStart()));
1422
1423     KAction* clipEnd = new KAction(KIcon("media-seek-forward"), i18n("Go to Clip End"), this);
1424     clipEnd->setShortcut(Qt::Key_End);
1425     collection.addAction("seek_clip_end", clipEnd);
1426     connect(clipEnd, SIGNAL(triggered(bool)), this, SLOT(slotClipEnd()));
1427
1428     KAction* zoneStart = new KAction(KIcon("media-seek-backward"), i18n("Go to Zone Start"), this);
1429     zoneStart->setShortcut(Qt::SHIFT + Qt::Key_I);
1430     collection.addAction("seek_zone_start", zoneStart);
1431     connect(zoneStart, SIGNAL(triggered(bool)), this, SLOT(slotZoneStart()));
1432
1433     KAction* zoneEnd = new KAction(KIcon("media-seek-forward"), i18n("Go to Zone End"), this);
1434     zoneEnd->setShortcut(Qt::SHIFT + Qt::Key_O);
1435     collection.addAction("seek_zone_end", zoneEnd);
1436     connect(zoneEnd, SIGNAL(triggered(bool)), this, SLOT(slotZoneEnd()));
1437
1438     KAction* projectStart = new KAction(KIcon("go-first"), i18n("Go to Project Start"), this);
1439     projectStart->setShortcut(Qt::CTRL + Qt::Key_Home);
1440     collection.addAction("seek_start", projectStart);
1441     connect(projectStart, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotStart()));
1442
1443     KAction* projectEnd = new KAction(KIcon("go-last"), i18n("Go to Project End"), this);
1444     projectEnd->setShortcut(Qt::CTRL + Qt::Key_End);
1445     collection.addAction("seek_end", projectEnd);
1446     connect(projectEnd, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotEnd()));
1447
1448     KAction* monitorSeekForwardOneFrame = new KAction(KIcon("media-skip-forward"), i18n("Forward 1 Frame"), this);
1449     monitorSeekForwardOneFrame->setShortcut(Qt::Key_Right);
1450     collection.addAction("monitor_seek_forward-one-frame", monitorSeekForwardOneFrame);
1451     connect(monitorSeekForwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForwardOneFrame()));
1452
1453     KAction* monitorSeekForwardOneSecond = new KAction(KIcon("media-skip-forward"), i18n("Forward 1 Second"), this);
1454     monitorSeekForwardOneSecond->setShortcut(Qt::SHIFT + Qt::Key_Right);
1455     collection.addAction("monitor_seek_forward-one-second", monitorSeekForwardOneSecond);
1456     connect(monitorSeekForwardOneSecond, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForwardOneSecond()));
1457
1458     KAction* monitorSeekSnapForward = new KAction(KIcon("media-seek-forward"), i18n("Go to Next Snap Point"), this);
1459     monitorSeekSnapForward->setShortcut(Qt::ALT + Qt::Key_Right);
1460     collection.addAction("monitor_seek_snap_forward", monitorSeekSnapForward);
1461     connect(monitorSeekSnapForward, SIGNAL(triggered(bool)), this, SLOT(slotSnapForward()));
1462
1463     KAction* deleteItem = new KAction(KIcon("edit-delete"), i18n("Delete Selected Item"), this);
1464     deleteItem->setShortcut(Qt::Key_Delete);
1465     collection.addAction("delete_timeline_clip", deleteItem);
1466     connect(deleteItem, SIGNAL(triggered(bool)), this, SLOT(slotDeleteItem()));
1467
1468     KAction* alignPlayhead = new KAction(i18n("Align Playhead to Mouse Position"), this);
1469     alignPlayhead->setShortcut(Qt::Key_P);
1470     collection.addAction("align_playhead", alignPlayhead);
1471     connect(alignPlayhead, SIGNAL(triggered(bool)), this, SLOT(slotAlignPlayheadToMousePos()));
1472
1473     /*KAction* editTimelineClipSpeed = new KAction(i18n("Change Clip Speed"), this);
1474     collection.addAction("change_clip_speed", editTimelineClipSpeed);
1475     editTimelineClipSpeed->setData("change_speed");
1476     connect(editTimelineClipSpeed, SIGNAL(triggered(bool)), this, SLOT(slotChangeClipSpeed()));*/
1477
1478     KAction *stickTransition = collection.addAction("auto_transition");
1479     stickTransition->setData(QString("auto"));
1480     stickTransition->setCheckable(true);
1481     stickTransition->setEnabled(false);
1482     stickTransition->setText(i18n("Automatic Transition"));
1483     connect(stickTransition, SIGNAL(triggered(bool)), this, SLOT(slotAutoTransition()));
1484
1485     KAction* groupClip = new KAction(KIcon("object-group"), i18n("Group Clips"), this);
1486     groupClip->setShortcut(Qt::CTRL + Qt::Key_G);
1487     collection.addAction("group_clip", groupClip);
1488     connect(groupClip, SIGNAL(triggered(bool)), this, SLOT(slotGroupClips()));
1489
1490     KAction* ungroupClip = new KAction(KIcon("object-ungroup"), i18n("Ungroup Clips"), this);
1491     collection.addAction("ungroup_clip", ungroupClip);
1492     ungroupClip->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_G);
1493     ungroupClip->setData("ungroup_clip");
1494     connect(ungroupClip, SIGNAL(triggered(bool)), this, SLOT(slotUnGroupClips()));
1495
1496     KAction* editItemDuration = new KAction(KIcon("measure"), i18n("Edit Duration"), this);
1497     collection.addAction("edit_item_duration", editItemDuration);
1498     connect(editItemDuration, SIGNAL(triggered(bool)), this, SLOT(slotEditItemDuration()));
1499     
1500     KAction* saveTimelineClip = new KAction(KIcon("document-save"), i18n("Save clip"), this);
1501     collection.addAction("save_timeline_clip", saveTimelineClip);
1502     connect(saveTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotSaveTimelineClip()));
1503
1504     KAction* clipInProjectTree = new KAction(KIcon("go-jump-definition"), i18n("Clip in Project Tree"), this);
1505     collection.addAction("clip_in_project_tree", clipInProjectTree);
1506     connect(clipInProjectTree, SIGNAL(triggered(bool)), this, SLOT(slotClipInProjectTree()));
1507
1508     /*KAction* clipToProjectTree = new KAction(KIcon("go-jump-definition"), i18n("Add Clip to Project Tree"), this);
1509     collection.addAction("clip_to_project_tree", clipToProjectTree);
1510     connect(clipToProjectTree, SIGNAL(triggered(bool)), this, SLOT(slotClipToProjectTree()));*/
1511
1512     KAction* insertOvertwrite = new KAction(KIcon(), i18n("Insert Clip Zone in Timeline (Overwrite)"), this);
1513     insertOvertwrite->setShortcut(Qt::Key_V);
1514     collection.addAction("overwrite_to_in_point", insertOvertwrite);
1515     connect(insertOvertwrite, SIGNAL(triggered(bool)), this, SLOT(slotInsertClipOverwrite()));
1516
1517     KAction* selectTimelineClip = new KAction(KIcon("edit-select"), i18n("Select Clip"), this);
1518     selectTimelineClip->setShortcut(Qt::Key_Plus);
1519     collection.addAction("select_timeline_clip", selectTimelineClip);
1520     connect(selectTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotSelectTimelineClip()));
1521
1522     KAction* deselectTimelineClip = new KAction(KIcon("edit-select"), i18n("Deselect Clip"), this);
1523     deselectTimelineClip->setShortcut(Qt::Key_Minus);
1524     collection.addAction("deselect_timeline_clip", deselectTimelineClip);
1525     connect(deselectTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotDeselectTimelineClip()));
1526
1527     KAction* selectAddTimelineClip = new KAction(KIcon("edit-select"), i18n("Add Clip To Selection"), this);
1528     selectAddTimelineClip->setShortcut(Qt::ALT + Qt::Key_Plus);
1529     collection.addAction("select_add_timeline_clip", selectAddTimelineClip);
1530     connect(selectAddTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotSelectAddTimelineClip()));
1531
1532     KAction* selectTimelineTransition = new KAction(KIcon("edit-select"), i18n("Select Transition"), this);
1533     selectTimelineTransition->setShortcut(Qt::SHIFT + Qt::Key_Plus);
1534     collection.addAction("select_timeline_transition", selectTimelineTransition);
1535     connect(selectTimelineTransition, SIGNAL(triggered(bool)), this, SLOT(slotSelectTimelineTransition()));
1536
1537     KAction* deselectTimelineTransition = new KAction(KIcon("edit-select"), i18n("Deselect Transition"), this);
1538     deselectTimelineTransition->setShortcut(Qt::SHIFT + Qt::Key_Minus);
1539     collection.addAction("deselect_timeline_transition", deselectTimelineTransition);
1540     connect(deselectTimelineTransition, SIGNAL(triggered(bool)), this, SLOT(slotDeselectTimelineTransition()));
1541
1542     KAction* selectAddTimelineTransition = new KAction(KIcon("edit-select"), i18n("Add Transition To Selection"), this);
1543     selectAddTimelineTransition->setShortcut(Qt::ALT + Qt::SHIFT + Qt::Key_Plus);
1544     collection.addAction("select_add_timeline_transition", selectAddTimelineTransition);
1545     connect(selectAddTimelineTransition, SIGNAL(triggered(bool)), this, SLOT(slotSelectAddTimelineTransition()));
1546
1547     KAction* cutTimelineClip = new KAction(KIcon("edit-cut"), i18n("Cut Clip"), this);
1548     cutTimelineClip->setShortcut(Qt::SHIFT + Qt::Key_R);
1549     collection.addAction("cut_timeline_clip", cutTimelineClip);
1550     connect(cutTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotCutTimelineClip()));
1551
1552     KAction* addClipMarker = new KAction(KIcon("bookmark-new"), i18n("Add Marker"), this);
1553     collection.addAction("add_clip_marker", addClipMarker);
1554     connect(addClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotAddClipMarker()));
1555
1556     KAction* deleteClipMarker = new KAction(KIcon("edit-delete"), i18n("Delete Marker"), this);
1557     collection.addAction("delete_clip_marker", deleteClipMarker);
1558     connect(deleteClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotDeleteClipMarker()));
1559
1560     KAction* deleteAllClipMarkers = new KAction(KIcon("edit-delete"), i18n("Delete All Markers"), this);
1561     collection.addAction("delete_all_clip_markers", deleteAllClipMarkers);
1562     connect(deleteAllClipMarkers, SIGNAL(triggered(bool)), this, SLOT(slotDeleteAllClipMarkers()));
1563
1564     KAction* editClipMarker = new KAction(KIcon("document-properties"), i18n("Edit Marker"), this);
1565     editClipMarker->setData(QString("edit_marker"));
1566     collection.addAction("edit_clip_marker", editClipMarker);
1567     connect(editClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotEditClipMarker()));
1568
1569     KAction* addMarkerGuideQuickly = new KAction(KIcon("bookmark-new"), i18n("Add Marker/Guide quickly"), this);
1570     addMarkerGuideQuickly->setShortcut(Qt::Key_Asterisk);
1571     collection.addAction("add_marker_guide_quickly", addMarkerGuideQuickly);
1572     connect(addMarkerGuideQuickly, SIGNAL(triggered(bool)), this, SLOT(slotAddMarkerGuideQuickly()));
1573
1574     KAction* splitAudio = new KAction(KIcon("document-new"), i18n("Split Audio"), this);
1575     collection.addAction("split_audio", splitAudio);
1576     // "A+V" as data means this action should only be available for clips with audio AND video
1577     splitAudio->setData("A+V");
1578     connect(splitAudio, SIGNAL(triggered(bool)), this, SLOT(slotSplitAudio()));
1579
1580     KAction* setAudioAlignReference = new KAction(i18n("Set Audio Reference"), this);
1581     collection.addAction("set_audio_align_ref", setAudioAlignReference);
1582     // "A" as data means this action should only be available for clips with audio
1583     setAudioAlignReference->setData("A");
1584     connect(setAudioAlignReference, SIGNAL(triggered()), this, SLOT(slotSetAudioAlignReference()));
1585
1586     KAction* alignAudio = new KAction(i18n("Align Audio to Reference"), this);
1587     collection.addAction("align_audio", alignAudio);
1588     // "A" as data means this action should only be available for clips with audio
1589     alignAudio->setData("A");
1590     connect(alignAudio, SIGNAL(triggered()), this, SLOT(slotAlignAudio()));
1591
1592     KAction* audioOnly = new KAction(KIcon("document-new"), i18n("Audio Only"), this);
1593     collection.addAction("clip_audio_only", audioOnly);
1594     audioOnly->setData("clip_audio_only");
1595     audioOnly->setCheckable(true);
1596
1597     KAction* videoOnly = new KAction(KIcon("document-new"), i18n("Video Only"), this);
1598     collection.addAction("clip_video_only", videoOnly);
1599     videoOnly->setData("clip_video_only");
1600     videoOnly->setCheckable(true);
1601
1602     KAction* audioAndVideo = new KAction(KIcon("document-new"), i18n("Audio and Video"), this);
1603     collection.addAction("clip_audio_and_video", audioAndVideo);
1604     audioAndVideo->setData("clip_audio_and_video");
1605     audioAndVideo->setCheckable(true);
1606
1607     m_clipTypeGroup = new QActionGroup(this);
1608     m_clipTypeGroup->addAction(audioOnly);
1609     m_clipTypeGroup->addAction(videoOnly);
1610     m_clipTypeGroup->addAction(audioAndVideo);
1611     connect(m_clipTypeGroup, SIGNAL(triggered(QAction*)), this, SLOT(slotUpdateClipType(QAction*)));
1612     m_clipTypeGroup->setEnabled(false);
1613
1614     KAction *insertSpace = new KAction(KIcon(), i18n("Insert Space"), this);
1615     collection.addAction("insert_space", insertSpace);
1616     connect(insertSpace, SIGNAL(triggered()), this, SLOT(slotInsertSpace()));
1617
1618     KAction *removeSpace = new KAction(KIcon(), i18n("Remove Space"), this);
1619     collection.addAction("delete_space", removeSpace);
1620     connect(removeSpace, SIGNAL(triggered()), this, SLOT(slotRemoveSpace()));
1621
1622     m_tracksActionCollection = new KActionCollection(this, KGlobal::mainComponent());
1623     m_tracksActionCollection->addAssociatedWidget(m_timelineArea);
1624
1625     KAction *insertTrack = new KAction(KIcon(), i18n("Insert Track"), m_tracksActionCollection);
1626     m_tracksActionCollection->addAction("insert_track", insertTrack);
1627     connect(insertTrack, SIGNAL(triggered()), this, SLOT(slotInsertTrack()));
1628
1629     KAction *deleteTrack = new KAction(KIcon(), i18n("Delete Track"), m_tracksActionCollection);
1630     m_tracksActionCollection->addAction("delete_track", deleteTrack);
1631     connect(deleteTrack, SIGNAL(triggered()), this, SLOT(slotDeleteTrack()));
1632
1633     KAction *configTracks = new KAction(KIcon("configure"), i18n("Configure Tracks"), m_tracksActionCollection);
1634     m_tracksActionCollection->addAction("config_tracks", configTracks);
1635     connect(configTracks, SIGNAL(triggered()), this, SLOT(slotConfigTrack()));
1636
1637     KAction *selectTrack = new KAction(KIcon(), i18n("Select All in Current Track"), m_tracksActionCollection);
1638     connect(selectTrack, SIGNAL(triggered()), this, SLOT(slotSelectTrack()));
1639     m_tracksActionCollection->addAction("select_track", selectTrack);
1640
1641     QAction *selectAll = KStandardAction::selectAll(this, SLOT(slotSelectAllTracks()), m_tracksActionCollection);
1642     selectAll->setShortcutContext(Qt::WidgetWithChildrenShortcut);
1643     m_tracksActionCollection->addAction("select_all_tracks", selectAll);
1644
1645     KAction *addGuide = new KAction(KIcon("document-new"), i18n("Add Guide"), this);
1646     collection.addAction("add_guide", addGuide);
1647     connect(addGuide, SIGNAL(triggered()), this, SLOT(slotAddGuide()));
1648
1649     QAction *delGuide = new KAction(KIcon("edit-delete"), i18n("Delete Guide"), this);
1650     collection.addAction("delete_guide", delGuide);
1651     connect(delGuide, SIGNAL(triggered()), this, SLOT(slotDeleteGuide()));
1652
1653     QAction *editGuide = new KAction(KIcon("document-properties"), i18n("Edit Guide"), this);
1654     collection.addAction("edit_guide", editGuide);
1655     connect(editGuide, SIGNAL(triggered()), this, SLOT(slotEditGuide()));
1656
1657     QAction *delAllGuides = new KAction(KIcon("edit-delete"), i18n("Delete All Guides"), this);
1658     collection.addAction("delete_all_guides", delAllGuides);
1659     connect(delAllGuides, SIGNAL(triggered()), this, SLOT(slotDeleteAllGuides()));
1660
1661     QAction *pasteEffects = new KAction(KIcon("edit-paste"), i18n("Paste Effects"), this);
1662     collection.addAction("paste_effects", pasteEffects);
1663     pasteEffects->setData("paste_effects");
1664     connect(pasteEffects , SIGNAL(triggered()), this, SLOT(slotPasteEffects()));
1665
1666     QAction *showTitleBar = new KAction(i18n("Show Title Bars"), this);
1667     collection.addAction("show_titlebars", showTitleBar);
1668     showTitleBar->setCheckable(true);
1669     connect(showTitleBar, SIGNAL(triggered(bool)), this, SLOT(slotShowTitleBars(bool)));
1670     showTitleBar->setChecked(KdenliveSettings::showtitlebars());
1671     slotShowTitleBars(KdenliveSettings::showtitlebars());
1672
1673     m_closeAction = KStandardAction::close(this,  SLOT(closeCurrentDocument()),   collection);
1674     KStandardAction::quit(this,                   SLOT(close()),                  collection);
1675     KStandardAction::open(this,                   SLOT(openFile()),               collection);
1676     m_saveAction = KStandardAction::save(this,    SLOT(saveFile()),               collection);
1677     KStandardAction::saveAs(this,                 SLOT(saveFileAs()),             collection);
1678     KStandardAction::openNew(this,                SLOT(newFile()),                collection);
1679     // TODO: make the following connection to slotEditKeys work
1680     //KStandardAction::keyBindings(this,            SLOT(slotEditKeys()),           collection);
1681     KStandardAction::preferences(this,            SLOT(slotPreferences()),        collection);
1682     KStandardAction::configureNotifications(this, SLOT(configureNotifications()), collection);
1683     KStandardAction::copy(this,                   SLOT(slotCopy()),               collection);
1684     KStandardAction::paste(this,                  SLOT(slotPaste()),              collection);
1685     KStandardAction::fullScreen(this,             SLOT(slotFullScreen()), this,   collection);
1686
1687     KAction *undo = KStandardAction::undo(m_commandStack, SLOT(undo()), collection);
1688     undo->setEnabled(false);
1689     connect(m_commandStack, SIGNAL(canUndoChanged(bool)), undo, SLOT(setEnabled(bool)));
1690
1691     KAction *redo = KStandardAction::redo(m_commandStack, SLOT(redo()), collection);
1692     redo->setEnabled(false);
1693     connect(m_commandStack, SIGNAL(canRedoChanged(bool)), redo, SLOT(setEnabled(bool)));
1694
1695     /*
1696     //TODO: Add status tooltip to actions ?
1697     connect(collection, SIGNAL(actionHovered(QAction*)),
1698             this, SLOT(slotDisplayActionMessage(QAction*)));*/
1699
1700
1701     QAction *addClip = new KAction(KIcon("kdenlive-add-clip"), i18n("Add Clip"), this);
1702     collection.addAction("add_clip", addClip);
1703     connect(addClip , SIGNAL(triggered()), m_projectList, SLOT(slotAddClip()));
1704
1705     QAction *addColorClip = new KAction(KIcon("kdenlive-add-color-clip"), i18n("Add Color Clip"), this);
1706     collection.addAction("add_color_clip", addColorClip);
1707     connect(addColorClip , SIGNAL(triggered()), m_projectList, SLOT(slotAddColorClip()));
1708
1709     QAction *addSlideClip = new KAction(KIcon("kdenlive-add-slide-clip"), i18n("Add Slideshow Clip"), this);
1710     collection.addAction("add_slide_clip", addSlideClip);
1711     connect(addSlideClip , SIGNAL(triggered()), m_projectList, SLOT(slotAddSlideshowClip()));
1712
1713     QAction *addTitleClip = new KAction(KIcon("kdenlive-add-text-clip"), i18n("Add Title Clip"), this);
1714     collection.addAction("add_text_clip", addTitleClip);
1715     connect(addTitleClip , SIGNAL(triggered()), m_projectList, SLOT(slotAddTitleClip()));
1716
1717     QAction *addTitleTemplateClip = new KAction(KIcon("kdenlive-add-text-clip"), i18n("Add Template Title"), this);
1718     collection.addAction("add_text_template_clip", addTitleTemplateClip);
1719     connect(addTitleTemplateClip , SIGNAL(triggered()), m_projectList, SLOT(slotAddTitleTemplateClip()));
1720
1721     QAction *addFolderButton = new KAction(KIcon("folder-new"), i18n("Create Folder"), this);
1722     collection.addAction("add_folder", addFolderButton);
1723     connect(addFolderButton , SIGNAL(triggered()), m_projectList, SLOT(slotAddFolder()));
1724
1725     QAction *downloadResources = new KAction(KIcon("download"), i18n("Online Resources"), this);
1726     collection.addAction("download_resource", downloadResources);
1727     connect(downloadResources , SIGNAL(triggered()), this, SLOT(slotDownloadResources()));
1728
1729     QAction *clipProperties = new KAction(KIcon("document-edit"), i18n("Clip Properties"), this);
1730     collection.addAction("clip_properties", clipProperties);
1731     clipProperties->setData("clip_properties");
1732     connect(clipProperties , SIGNAL(triggered()), m_projectList, SLOT(slotEditClip()));
1733     clipProperties->setEnabled(false);
1734
1735     QAction *openClip = new KAction(KIcon("document-open"), i18n("Edit Clip"), this);
1736     collection.addAction("edit_clip", openClip);
1737     openClip->setData("edit_clip");
1738     connect(openClip , SIGNAL(triggered()), m_projectList, SLOT(slotOpenClip()));
1739     openClip->setEnabled(false);
1740
1741     QAction *deleteClip = new KAction(KIcon("edit-delete"), i18n("Delete Clip"), this);
1742     collection.addAction("delete_clip", deleteClip);
1743     deleteClip->setData("delete_clip");
1744     connect(deleteClip , SIGNAL(triggered()), m_projectList, SLOT(slotRemoveClip()));
1745     deleteClip->setEnabled(false);
1746
1747     QAction *reloadClip = new KAction(KIcon("view-refresh"), i18n("Reload Clip"), this);
1748     collection.addAction("reload_clip", reloadClip);
1749     reloadClip->setData("reload_clip");
1750     connect(reloadClip , SIGNAL(triggered()), m_projectList, SLOT(slotReloadClip()));
1751     reloadClip->setEnabled(false);
1752
1753     QAction *proxyClip = new KAction(i18n("Proxy Clip"), this);
1754     collection.addAction("proxy_clip", proxyClip);
1755     proxyClip->setData("proxy_clip");
1756     proxyClip->setCheckable(true);
1757     proxyClip->setChecked(false);
1758     connect(proxyClip, SIGNAL(toggled(bool)), m_projectList, SLOT(slotProxyCurrentItem(bool)));
1759
1760     QAction *stopMotion = new KAction(KIcon("image-x-generic"), i18n("Stop Motion Capture"), this);
1761     collection.addAction("stopmotion", stopMotion);
1762     connect(stopMotion , SIGNAL(triggered()), this, SLOT(slotOpenStopmotion()));
1763
1764     QMenu *addClips = new QMenu();
1765     addClips->addAction(addClip);
1766     addClips->addAction(addColorClip);
1767     addClips->addAction(addSlideClip);
1768     addClips->addAction(addTitleClip);
1769     addClips->addAction(addTitleTemplateClip);
1770     addClips->addAction(addFolderButton);
1771     addClips->addAction(downloadResources);
1772
1773     addClips->addAction(reloadClip);
1774     addClips->addAction(proxyClip);
1775     addClips->addAction(clipProperties);
1776     addClips->addAction(openClip);
1777     addClips->addAction(deleteClip);
1778     m_projectList->setupMenu(addClips, addClip);
1779
1780     // Setup effects and transitions actions.
1781     m_effectsActionCollection = new KActionCollection(this, KGlobal::mainComponent());
1782     //KActionCategory *transitionActions = new KActionCategory(i18n("Transitions"), m_effectsActionCollection);
1783     KActionCategory *transitionActions = new KActionCategory(i18n("Transitions"), collection);
1784     m_transitions = new KAction*[transitions.count()];
1785     for (int i = 0; i < transitions.count(); ++i) {
1786         QStringList effectInfo = transitions.effectIdInfo(i);
1787         m_transitions[i] = new KAction(effectInfo.at(0), this);
1788         m_transitions[i]->setData(effectInfo);
1789         m_transitions[i]->setIconVisibleInMenu(false);
1790         QString id = effectInfo.at(2);
1791         if (id.isEmpty()) id = effectInfo.at(1);
1792         transitionActions->addAction("transition_" + id, m_transitions[i]);
1793     }
1794     //m_effectsActionCollection->readSettings();
1795
1796 }
1797
1798 void MainWindow::slotDisplayActionMessage(QAction *a)
1799 {
1800     statusBar()->showMessage(a->data().toString(), 3000);
1801 }
1802
1803 void MainWindow::setStatusBarStyleSheet(const QPalette &p)
1804 {
1805     KColorScheme scheme(p.currentColorGroup(), KColorScheme::Window, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
1806     QColor buttonBg = scheme.background(KColorScheme::LinkBackground).color();
1807     QColor buttonBord = scheme.foreground(KColorScheme::LinkText).color();
1808     QColor buttonBord2 = scheme.shade(KColorScheme::LightShade);
1809     statusBar()->setStyleSheet(QString("QStatusBar QLabel {font-size:%1pt;} QStatusBar::item { border: 0px; font-size:%1pt;padding:0px; }").arg(statusBar()->font().pointSize()));
1810     QString style1 = QString("QToolBar { border: 0px } QToolButton { border-style: inset; border:1px solid transparent;border-radius: 3px;margin: 0px 3px;padding: 0px;} QToolButton#timecode {padding-right:10px;} QToolButton:hover { background: %3;border-style: inset; border:1px solid %3;border-radius: 3px;} QToolButton:checked { background-color: %1; border-style: inset; border:1px solid %2;border-radius: 3px;}").arg(buttonBg.name()).arg(buttonBord.name()).arg(buttonBord2.name());
1811     statusBar()->setStyleSheet(style1);
1812 }
1813
1814 void MainWindow::loadLayouts()
1815 {
1816     QMenu *saveLayout = (QMenu*)(factory()->container("layout_save_as", this));
1817     if (m_loadLayout == NULL || saveLayout == NULL) return;
1818     KSharedConfigPtr config = KGlobal::config();
1819     KConfigGroup layoutGroup(config, "Layouts");
1820     QStringList entries = layoutGroup.keyList();
1821     QList<QAction *> loadActions = m_loadLayout->actions();
1822     QList<QAction *> saveActions = saveLayout->actions();
1823     for (int i = 1; i < 5; ++i) {
1824         // Rename the layouts actions
1825         foreach(const QString & key, entries) {
1826             if (key.endsWith(QString("_%1").arg(i))) {
1827                 // Found previously saved layout
1828                 QString layoutName = key.section('_', 0, -2);
1829                 for (int j = 0; j < loadActions.count(); j++) {
1830                     if (loadActions.at(j)->data().toString().endsWith('_' + QString::number(i))) {
1831                         loadActions[j]->setText(layoutName);
1832                         loadActions[j]->setData(key);
1833                         break;
1834                     }
1835                 }
1836                 for (int j = 0; j < saveActions.count(); j++) {
1837                     if (saveActions.at(j)->data().toString().endsWith('_' + QString::number(i))) {
1838                         saveActions[j]->setText(i18n("Save as %1", layoutName));
1839                         saveActions[j]->setData(key);
1840                         break;
1841                     }
1842                 }
1843             }
1844         }
1845     }
1846 }
1847
1848 void MainWindow::slotLoadLayout(QAction *action)
1849 {
1850     if (!action) {
1851         return;
1852     }
1853
1854     QString layoutId = action->data().toString();
1855     if (layoutId.isEmpty()) {
1856         return;
1857     }
1858
1859     KSharedConfigPtr config = KGlobal::config();
1860     KConfigGroup layouts(config, "Layouts");
1861     QByteArray state = QByteArray::fromBase64(layouts.readEntry(layoutId).toAscii());
1862     restoreState(state);
1863 }
1864
1865 void MainWindow::slotSaveLayout(QAction *action)
1866 {
1867     QString originallayoutName = action->data().toString();
1868     int layoutId = originallayoutName.section('_', -1).toInt();
1869
1870     QString layoutName = QInputDialog::getText(this, i18n("Save Layout"), i18n("Layout name:"), QLineEdit::Normal, originallayoutName.section('_', 0, -2));
1871     if (layoutName.isEmpty()) {
1872         return;
1873     }
1874     KSharedConfigPtr config = KGlobal::config();
1875     KConfigGroup layouts(config, "Layouts");
1876     layouts.deleteEntry(originallayoutName);
1877
1878     QByteArray st = saveState();
1879     layoutName.append('_' + QString::number(layoutId));
1880     layouts.writeEntry(layoutName, st.toBase64());
1881     loadLayouts();
1882 }
1883
1884 void MainWindow::saveOptions()
1885 {
1886     KdenliveSettings::self()->writeConfig();
1887     KSharedConfigPtr config = KGlobal::config();
1888     m_fileOpenRecent->saveEntries(KConfigGroup(config, "Recent Files"));
1889     KConfigGroup treecolumns(config, "Project Tree");
1890     treecolumns.writeEntry("columns", m_projectList->headerInfo());
1891     config->sync();
1892 }
1893
1894 void MainWindow::readOptions()
1895 {
1896     KSharedConfigPtr config = KGlobal::config();
1897     m_fileOpenRecent->loadEntries(KConfigGroup(config, "Recent Files"));
1898     KConfigGroup initialGroup(config, "version");
1899     bool upgrade = false;
1900     if (initialGroup.exists()) {
1901         if (initialGroup.readEntry("version", QString()).section(' ', 0, 0) != QString(version).section(' ', 0, 0)) {
1902             upgrade = true;
1903         }
1904
1905         if (initialGroup.readEntry("version") == "0.7") {
1906             //Add new settings from 0.7.1
1907             if (KdenliveSettings::defaultprojectfolder().isEmpty()) {
1908                 QString path = QDir::homePath() + "/kdenlive";
1909                 if (KStandardDirs::makeDir(path)  == false) {
1910                     kDebug() << "/// ERROR CREATING PROJECT FOLDER: " << path;
1911                 } else {
1912                     KdenliveSettings::setDefaultprojectfolder(path);
1913                 }
1914             }
1915         }
1916     }
1917
1918     if (KdenliveSettings::ffmpegpath().isEmpty() || KdenliveSettings::ffplaypath().isEmpty()) {
1919         upgrade = true;
1920     }
1921
1922     if (!initialGroup.exists() || upgrade) {
1923         // this is our first run, show Wizard
1924         QPointer<Wizard> w = new Wizard(upgrade, this);
1925         if (w->exec() == QDialog::Accepted && w->isOk()) {
1926             w->adjustSettings();
1927             initialGroup.writeEntry("version", version);
1928             delete w;
1929         } else {
1930             delete w;
1931             ::exit(1);
1932         }
1933     }
1934
1935     KConfigGroup treecolumns(config, "Project Tree");
1936     const QByteArray state = treecolumns.readEntry("columns", QByteArray());
1937     if (!state.isEmpty()) {
1938         m_projectList->setHeaderInfo(state);
1939     }
1940 }
1941
1942 void MainWindow::slotRunWizard()
1943 {
1944     QPointer<Wizard> w = new Wizard(false, this);
1945     if (w->exec() == QDialog::Accepted && w->isOk()) {
1946         w->adjustSettings();
1947     }
1948     delete w;
1949 }
1950
1951 void MainWindow::newFile(bool showProjectSettings, bool force)
1952 {
1953     if (!m_timelineArea->isEnabled() && !force) {
1954         return;
1955     }
1956     m_fileRevert->setEnabled(false);
1957     QString profileName = KdenliveSettings::default_profile();
1958     KUrl projectFolder = KdenliveSettings::defaultprojectfolder();
1959     QMap <QString, QString> documentProperties;
1960     QMap <QString, QString> documentMetadata;
1961     QPoint projectTracks(KdenliveSettings::videotracks(), KdenliveSettings::audiotracks());
1962     if (!showProjectSettings) {
1963         if (!KdenliveSettings::activatetabs()) {
1964             if (!closeCurrentDocument()) {
1965                 return;
1966             }
1967         }
1968     } else {
1969         QPointer<ProjectSettings> w = new ProjectSettings(NULL, QMap <QString, QString> (), QStringList(), projectTracks.x(), projectTracks.y(), KdenliveSettings::defaultprojectfolder(), false, true, this);
1970         if (w->exec() != QDialog::Accepted) {
1971             delete w;
1972             return;
1973         }
1974         if (!KdenliveSettings::activatetabs()) {
1975             if (!closeCurrentDocument()) {
1976                 delete w;
1977                 return;
1978             }
1979         }
1980         if (KdenliveSettings::videothumbnails() != w->enableVideoThumbs()) {
1981             slotSwitchVideoThumbs();
1982         }
1983         if (KdenliveSettings::audiothumbnails() != w->enableAudioThumbs()) {
1984             slotSwitchAudioThumbs();
1985         }
1986         profileName = w->selectedProfile();
1987         projectFolder = w->selectedFolder();
1988         projectTracks = w->tracks();
1989         documentProperties.insert("enableproxy", QString::number((int) w->useProxy()));
1990         documentProperties.insert("generateproxy", QString::number((int) w->generateProxy()));
1991         documentProperties.insert("proxyminsize", QString::number(w->proxyMinSize()));
1992         documentProperties.insert("proxyparams", w->proxyParams());
1993         documentProperties.insert("proxyextension", w->proxyExtension());
1994         documentProperties.insert("generateimageproxy", QString::number((int) w->generateImageProxy()));
1995         documentProperties.insert("proxyimageminsize", QString::number(w->proxyImageMinSize()));
1996         documentMetadata = w->metadata();
1997         delete w;
1998     }
1999     m_timelineArea->setEnabled(true);
2000     m_projectList->setEnabled(true);
2001     bool openBackup;
2002     KdenliveDoc *doc = new KdenliveDoc(KUrl(), projectFolder, m_commandStack, profileName, documentProperties, documentMetadata, projectTracks, m_projectMonitor->render, m_notesWidget, &openBackup, this);
2003     doc->m_autosave = new KAutoSaveFile(KUrl(), doc);
2004     bool ok;
2005     TrackView *trackView = new TrackView(doc, m_tracksActionCollection->actions(), &ok, this);
2006     m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description());
2007     if (!ok) {
2008         // MLT is broken
2009         //m_timelineArea->setEnabled(false);
2010         //m_projectList->setEnabled(false);
2011         slotPreferences(6);
2012         return;
2013     }
2014     if (m_timelineArea->count() == 1) {
2015         connectDocumentInfo(doc);
2016         connectDocument(trackView, doc);
2017     } else {
2018         m_timelineArea->setTabBarHidden(false);
2019     }
2020     m_monitorManager->activateMonitor(Kdenlive::ClipMonitor);
2021     m_closeAction->setEnabled(m_timelineArea->count() > 1);
2022 }
2023
2024 void MainWindow::activateDocument()
2025 {
2026     if (m_timelineArea->currentWidget() == NULL || !m_timelineArea->isEnabled()) {
2027         return;
2028     }
2029     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
2030     KdenliveDoc *currentDoc = currentTab->document();
2031     connectDocumentInfo(currentDoc);
2032     connectDocument(currentTab, currentDoc);
2033 }
2034
2035 bool MainWindow::closeCurrentDocument(bool saveChanges)
2036 {
2037     QWidget *w = m_timelineArea->currentWidget();
2038     if (!w) {
2039         return true;
2040     }
2041     // closing current document
2042     int ix = m_timelineArea->currentIndex() + 1;
2043     if (ix == m_timelineArea->count()) {
2044         ix = 0;
2045     }
2046     m_timelineArea->setCurrentIndex(ix);
2047     TrackView *tabToClose = (TrackView *) w;
2048     KdenliveDoc *docToClose = tabToClose->document();
2049     if (docToClose && docToClose->isModified() && saveChanges) {
2050         QString message;
2051         if (m_activeDocument->url().fileName().isEmpty()) {
2052             message = i18n("Save changes to document?");
2053         } else {
2054             message = i18n("The project <b>\"%1\"</b> has been changed.\nDo you want to save your changes?", m_activeDocument->url().fileName());
2055         }
2056
2057         switch (KMessageBox::warningYesNoCancel(this, message)) {
2058         case KMessageBox::Yes :
2059             // save document here. If saving fails, return false;
2060             if (saveFile() == false) return false;
2061             break;
2062         case KMessageBox::Cancel :
2063             return false;
2064             break;
2065         default:
2066             break;
2067         }
2068     }
2069
2070     slotTimelineClipSelected(NULL, false);
2071     m_clipMonitor->slotSetClipProducer(NULL);
2072     m_projectList->slotResetProjectList();
2073     m_timelineArea->removeTab(m_timelineArea->indexOf(w));
2074     if (m_timelineArea->count() == 1) {
2075         m_timelineArea->setTabBarHidden(true);
2076         m_closeAction->setEnabled(false);
2077     }
2078
2079     if (docToClose == m_activeDocument) {
2080         delete m_activeDocument;
2081         m_activeDocument = NULL;
2082         m_monitorManager->setDocument(m_activeDocument);
2083         m_effectStack->clear();
2084         m_transitionConfig->slotTransitionItemSelected(NULL, 0, QPoint(), false);
2085     } else {
2086         delete docToClose;
2087     }
2088
2089     if (w == m_activeTimeline) {
2090         delete m_activeTimeline;
2091         m_activeTimeline = NULL;
2092     } else {
2093         delete w;
2094     }
2095
2096     return true;
2097 }
2098
2099 bool MainWindow::saveFileAs(const QString &outputFileName)
2100 {
2101     m_monitorManager->stopActiveMonitor();
2102
2103     if (m_activeDocument->saveSceneList(outputFileName, m_projectMonitor->sceneList(), m_projectList->expandedFolders()) == false) {
2104         return false;
2105     }
2106
2107     // Save timeline thumbnails
2108     m_activeTimeline->projectView()->saveThumbnails();
2109     m_activeDocument->setUrl(KUrl(outputFileName));
2110     QByteArray hash = QCryptographicHash::hash(KUrl(outputFileName).encodedPath(), QCryptographicHash::Md5).toHex();
2111     if (m_activeDocument->m_autosave == NULL) {
2112         m_activeDocument->m_autosave = new KAutoSaveFile(KUrl(hash), this);
2113     } else {
2114         m_activeDocument->m_autosave->setManagedFile(KUrl(hash));
2115     }
2116
2117     setCaption(m_activeDocument->description());
2118     m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
2119     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), m_activeDocument->url().path());
2120     m_activeDocument->setModified(false);
2121     m_fileOpenRecent->addUrl(KUrl(outputFileName));
2122     m_fileRevert->setEnabled(true);
2123     m_undoView->stack()->setClean();
2124
2125     return true;
2126 }
2127
2128 bool MainWindow::saveFileAs()
2129 {
2130     QString outputFile = KFileDialog::getSaveFileName(m_activeDocument->projectFolder(), getMimeType(false));
2131     if (outputFile.isEmpty()) {
2132         return false;
2133     }
2134
2135     if (QFile::exists(outputFile)) {
2136         // Show the file dialog again if the user does not want to overwrite the file
2137         if (KMessageBox::questionYesNo(this, i18n("File %1 already exists.\nDo you want to overwrite it?", outputFile)) == KMessageBox::No) {
2138             return saveFileAs();
2139         }
2140     }
2141
2142     return saveFileAs(outputFile);
2143 }
2144
2145 bool MainWindow::saveFile()
2146 {
2147     if (!m_activeDocument) {
2148         return true;
2149     }
2150
2151     if (m_activeDocument->url().isEmpty()) {
2152         return saveFileAs();
2153     } else {
2154         bool result = saveFileAs(m_activeDocument->url().path());
2155         m_activeDocument->m_autosave->resize(0);
2156         return result;
2157     }
2158 }
2159
2160 void MainWindow::openFile()
2161 {
2162     if (!m_startUrl.isEmpty()) {
2163         openFile(m_startUrl);
2164         m_startUrl = KUrl();
2165         return;
2166     }
2167     KUrl url = KFileDialog::getOpenUrl(KUrl("kfiledialog:///projectfolder"), getMimeType());
2168     if (url.isEmpty()) {
2169         return;
2170     }
2171
2172     m_fileOpenRecent->addUrl(url);
2173     openFile(url);
2174 }
2175
2176 void MainWindow::openLastFile()
2177 {
2178     if (m_fileOpenRecent->selectableActionGroup()->actions().isEmpty()) {
2179         // No files in history
2180         newFile(false);
2181         return;
2182     }
2183
2184     QAction *firstUrlAction = m_fileOpenRecent->selectableActionGroup()->actions().last();
2185     if (firstUrlAction) {
2186         firstUrlAction->trigger();
2187     } else {
2188         newFile(false);
2189     }
2190 }
2191
2192 void MainWindow::openFile(const KUrl &url)
2193 {
2194     // Make sure the url is a Kdenlive project file
2195     KMimeType::Ptr mime = KMimeType::findByUrl(url);
2196     if (mime.data()->is("application/x-compressed-tar")) {
2197         // Opening a compressed project file, we need to process it
2198         kDebug()<<"Opening archive, processing";
2199         QPointer<ArchiveWidget> ar = new ArchiveWidget(url);
2200         if (ar->exec() == QDialog::Accepted) {
2201             openFile(KUrl(ar->extractedProjectFile()));
2202         } else if (!m_startUrl.isEmpty()) {
2203             // we tried to open an invalid file from command line, init new project
2204             newFile(false);
2205         }
2206         delete ar;
2207         return;
2208     }
2209
2210     if (!url.fileName().endsWith(".kdenlive")) {
2211         // This is not a Kdenlive project file, abort loading
2212         KMessageBox::sorry(this, i18n("File %1 is not a Kdenlive project file", url.path()));
2213         if (!m_startUrl.isEmpty()) {
2214             // we tried to open an invalid file from command line, init new project
2215             newFile(false);
2216         }
2217         return;
2218     }
2219
2220     // Check if the document is already opened
2221     const int ct = m_timelineArea->count();
2222     bool isOpened = false;
2223     int i;
2224     for (i = 0; i < ct; ++i) {
2225         TrackView *tab = (TrackView *) m_timelineArea->widget(i);
2226         KdenliveDoc *doc = tab->document();
2227         if (doc->url() == url) {
2228             isOpened = true;
2229             break;
2230         }
2231     }
2232
2233     if (isOpened) {
2234         m_timelineArea->setCurrentIndex(i);
2235         return;
2236     }
2237
2238     if (!KdenliveSettings::activatetabs()) {
2239         if (!closeCurrentDocument()) {
2240             return;
2241         }
2242     }
2243
2244     // Check for backup file
2245     QByteArray hash = QCryptographicHash::hash(url.encodedPath(), QCryptographicHash::Md5).toHex();
2246     QList<KAutoSaveFile *> staleFiles = KAutoSaveFile::staleFiles(KUrl(hash));
2247     if (!staleFiles.isEmpty()) {
2248         if (KMessageBox::questionYesNo(this,
2249                                        i18n("Auto-saved files exist. Do you want to recover them now?"),
2250                                        i18n("File Recovery"),
2251                                        KGuiItem(i18n("Recover")), KGuiItem(i18n("Don't recover"))) == KMessageBox::Yes) {
2252             recoverFiles(staleFiles, url);
2253             return;
2254         } else {
2255             // remove the stale files
2256             foreach(KAutoSaveFile * stale, staleFiles) {
2257                 stale->open(QIODevice::ReadWrite);
2258                 delete stale;
2259             }
2260         }
2261     }
2262     m_messageLabel->setMessage(i18n("Opening file %1", url.path()), InformationMessage);
2263     m_messageLabel->repaint();
2264     doOpenFile(url, NULL);
2265 }
2266
2267 void MainWindow::doOpenFile(const KUrl &url, KAutoSaveFile *stale)
2268 {
2269     if (!m_timelineArea->isEnabled()) return;
2270     m_fileRevert->setEnabled(true);
2271
2272     // Recreate stopmotion widget on document change
2273     if (m_stopmotion) {
2274         delete m_stopmotion;
2275         m_stopmotion = NULL;
2276     }
2277
2278     m_timer.start();
2279     KProgressDialog progressDialog(this, i18n("Loading project"), i18n("Loading project"));
2280     progressDialog.setAllowCancel(false);
2281     progressDialog.progressBar()->setMaximum(4);
2282     progressDialog.show();
2283     progressDialog.progressBar()->setValue(0);
2284
2285     bool openBackup;
2286     KdenliveDoc *doc = new KdenliveDoc(stale ? KUrl(stale->fileName()) : url, KdenliveSettings::defaultprojectfolder(), m_commandStack, KdenliveSettings::default_profile(), QMap <QString, QString> (), QMap <QString, QString> (), QPoint(KdenliveSettings::videotracks(), KdenliveSettings::audiotracks()), m_projectMonitor->render, m_notesWidget, &openBackup, this, &progressDialog);
2287
2288     progressDialog.progressBar()->setValue(1);
2289     progressDialog.progressBar()->setMaximum(4);
2290     progressDialog.setLabelText(i18n("Loading project"));
2291     progressDialog.repaint();
2292
2293     if (stale == NULL) {
2294         QByteArray hash = QCryptographicHash::hash(url.encodedPath(), QCryptographicHash::Md5).toHex();
2295         stale = new KAutoSaveFile(KUrl(hash), doc);
2296         doc->m_autosave = stale;
2297     } else {
2298         doc->m_autosave = stale;
2299         doc->setUrl(url);//stale->managedFile());
2300         doc->setModified(true);
2301         stale->setParent(doc);
2302     }
2303     connectDocumentInfo(doc);
2304
2305     progressDialog.progressBar()->setValue(2);
2306     progressDialog.repaint();
2307
2308     bool ok;
2309     TrackView *trackView = new TrackView(doc, m_tracksActionCollection->actions(), &ok, this);
2310     connectDocument(trackView, doc);
2311     progressDialog.progressBar()->setValue(3);
2312     progressDialog.repaint();
2313
2314     m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description()));
2315     if (!ok) {
2316         m_timelineArea->setEnabled(false);
2317         m_projectList->setEnabled(false);
2318         KMessageBox::sorry(this, i18n("Cannot open file %1.\nProject is corrupted.", url.path()));
2319         slotGotProgressInfo(QString(), -1);
2320         newFile(false, true);
2321         return;
2322     }
2323     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), doc->url().path());
2324     trackView->setDuration(trackView->duration());
2325
2326     if (m_timelineArea->count() > 1) {
2327         m_timelineArea->setTabBarHidden(false);
2328     }
2329
2330     slotGotProgressInfo(QString(), -1);
2331     m_projectMonitor->adjustRulerSize(trackView->duration());
2332     m_projectMonitor->slotZoneMoved(trackView->inPoint(), trackView->outPoint());
2333     progressDialog.progressBar()->setValue(4);
2334     if (openBackup) {
2335         slotOpenBackupDialog(url);
2336     }
2337 }
2338
2339 void MainWindow::recoverFiles(const QList<KAutoSaveFile *> &staleFiles, const KUrl &originUrl)
2340 {
2341     foreach(KAutoSaveFile * stale, staleFiles) {
2342         /*if (!stale->open(QIODevice::QIODevice::ReadOnly)) {
2343                   // show an error message; we could not steal the lockfile
2344                   // maybe another application got to the file before us?
2345                   delete stale;
2346                   continue;
2347         }*/
2348         kDebug() << "// OPENING RECOVERY: " << stale->fileName() << "\nMANAGED: " << stale->managedFile().path();
2349         // the stalefiles also contain ".lock" files so we must ignore them... bug in KAutoSaveFile?
2350         if (!stale->fileName().endsWith(".lock")) {
2351             doOpenFile(originUrl, stale);
2352         } else {
2353             KIO::NetAccess::del(KUrl(stale->fileName()), this);
2354         }
2355     }
2356 }
2357
2358 void MainWindow::parseProfiles(const QString &mltPath)
2359 {
2360     //KdenliveSettings::setDefaulttmpfolder();
2361     if (!mltPath.isEmpty()) {
2362         KdenliveSettings::setMltpath(mltPath + "/share/mlt/profiles/");
2363         KdenliveSettings::setRendererpath(mltPath + "/bin/melt");
2364     }
2365
2366     if (KdenliveSettings::mltpath().isEmpty()) {
2367         KdenliveSettings::setMltpath(QString(MLT_PREFIX) + QString("/share/mlt/profiles/"));
2368     }
2369
2370     if (KdenliveSettings::rendererpath().isEmpty() || KdenliveSettings::rendererpath().endsWith("inigo")) {
2371         QString meltPath = QString(MLT_PREFIX) + QString("/bin/melt");
2372         if (!QFile::exists(meltPath)) {
2373             meltPath = KStandardDirs::findExe("melt");
2374         }
2375         KdenliveSettings::setRendererpath(meltPath);
2376     }
2377
2378     if (KdenliveSettings::rendererpath().isEmpty()) {
2379         // Cannot find the MLT melt renderer, ask for location
2380         QPointer<KUrlRequesterDialog> getUrl = new KUrlRequesterDialog(QString(), i18n("Cannot find the melt program required for rendering (part of MLT)"), this);
2381         if (getUrl->exec() == QDialog::Rejected) {
2382             delete getUrl;
2383             ::exit(0);
2384         }
2385         KUrl rendererPath = getUrl->selectedUrl();
2386         delete getUrl;
2387         if (rendererPath.isEmpty()) ::exit(0);
2388         KdenliveSettings::setRendererpath(rendererPath.path());
2389     }
2390
2391     QStringList profilesFilter;
2392     profilesFilter << "*";
2393     QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
2394     if (profilesList.isEmpty()) {
2395         // Cannot find MLT path, try finding melt
2396         QString profilePath = KdenliveSettings::rendererpath();
2397         if (!profilePath.isEmpty()) {
2398             profilePath = profilePath.section('/', 0, -3);
2399             KdenliveSettings::setMltpath(profilePath + "/share/mlt/profiles/");
2400             profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
2401         }
2402         if (profilesList.isEmpty()) {
2403             // Cannot find the MLT profiles, ask for location
2404             QPointer<KUrlRequesterDialog> getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find your MLT profiles, please give the path"), this);
2405             getUrl->fileDialog()->setMode(KFile::Directory);
2406             if (getUrl->exec() == QDialog::Rejected) {
2407                 delete getUrl;
2408                 ::exit(0);
2409             }
2410             KUrl mltPath = getUrl->selectedUrl();
2411             delete getUrl;
2412             if (mltPath.isEmpty()) ::exit(0);
2413             KdenliveSettings::setMltpath(mltPath.path(KUrl::AddTrailingSlash));
2414             profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
2415         }
2416     }
2417
2418     kDebug() << "RESULTING MLT PATH: " << KdenliveSettings::mltpath();
2419
2420     // Parse again MLT profiles to build a list of available video formats
2421     if (profilesList.isEmpty()) {
2422         parseProfiles();
2423     }
2424 }
2425
2426
2427 void MainWindow::slotEditProfiles()
2428 {
2429     ProfilesDialog *w = new ProfilesDialog;
2430     if (w->exec() == QDialog::Accepted) {
2431         KdenliveSettingsDialog* d = static_cast <KdenliveSettingsDialog*>(KConfigDialog::exists("settings"));
2432         if (d) {
2433             d->checkProfile();
2434         }
2435     }
2436     delete w;
2437 }
2438
2439 void MainWindow::slotDetectAudioDriver()
2440 {
2441     /* WARNING: do not use this method because sometimes detects wrong driver (pulse instead of alsa),
2442     leading to no audio output, see bug #934 */
2443
2444     //decide which audio driver is really best, in some cases SDL is wrong
2445     if (KdenliveSettings::audiodrivername().isEmpty()) {
2446         QString driver;
2447         KProcess readProcess;
2448         //PulseAudio needs to be selected if it exists, the ALSA pulse pcm device is not fast enough.
2449         if (!KStandardDirs::findExe("pactl").isEmpty()) {
2450             readProcess.setOutputChannelMode(KProcess::OnlyStdoutChannel);
2451             readProcess.setProgram("pactl", QStringList() << "stat");
2452             readProcess.execute(2000); // Kill it after 2 seconds
2453
2454             QString result = QString(readProcess.readAllStandardOutput());
2455             kDebug() << "// / / / / / READING PACTL: ";
2456             kDebug() << result;
2457             if (!result.isEmpty()) {
2458                 driver = "pulse";
2459                 kDebug() << "// / / / / PULSEAUDIO DETECTED";
2460             }
2461         }
2462         //put others here
2463         KdenliveSettings::setAutoaudiodrivername(driver);
2464     }
2465 }
2466
2467 void MainWindow::slotEditProjectSettings()
2468 {
2469     QPoint p = m_activeDocument->getTracksCount();
2470     QPointer<ProjectSettings> w = new ProjectSettings(m_projectList, m_activeDocument->metadata(), m_activeTimeline->projectView()->extractTransitionsLumas(), p.x(), p.y(), m_activeDocument->projectFolder().path(), true, !m_activeDocument->isModified(), this);
2471     connect(w, SIGNAL(disableProxies()), this, SLOT(slotDisableProxies()));
2472
2473     if (w->exec() == QDialog::Accepted) {
2474         QString profile = w->selectedProfile();
2475         m_activeDocument->setProjectFolder(w->selectedFolder());
2476 #ifndef Q_WS_MAC
2477         m_recMonitor->slotUpdateCaptureFolder(m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash));
2478 #endif
2479         if (m_renderWidget) {
2480             m_renderWidget->setDocumentPath(m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash));
2481         }
2482         if (KdenliveSettings::videothumbnails() != w->enableVideoThumbs()) {
2483             slotSwitchVideoThumbs();
2484         }
2485         if (KdenliveSettings::audiothumbnails() != w->enableAudioThumbs()) {
2486             slotSwitchAudioThumbs();
2487         }
2488         if (m_activeDocument->profilePath() != profile) {
2489             slotUpdateProjectProfile(profile);
2490         }
2491         if (m_activeDocument->getDocumentProperty("proxyparams") != w->proxyParams()) {
2492             m_activeDocument->setModified();
2493             m_activeDocument->setDocumentProperty("proxyparams", w->proxyParams());
2494             if (m_activeDocument->clipManager()->clipsCount() > 0 && KMessageBox::questionYesNo(this, i18n("You have changed the proxy parameters. Do you want to recreate all proxy clips for this project?")) == KMessageBox::Yes) {
2495                 //TODO: rebuild all proxies
2496                 //m_projectList->rebuildProxies();
2497             }
2498         }
2499         if (m_activeDocument->getDocumentProperty("proxyextension") != w->proxyExtension()) {
2500             m_activeDocument->setModified();
2501             m_activeDocument->setDocumentProperty("proxyextension", w->proxyExtension());
2502         }
2503         if (m_activeDocument->getDocumentProperty("generateproxy") != QString::number((int) w->generateProxy())) {
2504             m_activeDocument->setModified();
2505             m_activeDocument->setDocumentProperty("generateproxy", QString::number((int) w->generateProxy()));
2506         }
2507         if (m_activeDocument->getDocumentProperty("proxyminsize") != QString::number(w->proxyMinSize())) {
2508             m_activeDocument->setModified();
2509             m_activeDocument->setDocumentProperty("proxyminsize", QString::number(w->proxyMinSize()));
2510         }
2511         if (m_activeDocument->getDocumentProperty("generateimageproxy") != QString::number((int) w->generateImageProxy())) {
2512             m_activeDocument->setModified();
2513             m_activeDocument->setDocumentProperty("generateimageproxy", QString::number((int) w->generateImageProxy()));
2514         }
2515         if (m_activeDocument->getDocumentProperty("proxyimageminsize") != QString::number(w->proxyImageMinSize())) {
2516             m_activeDocument->setModified();
2517             m_activeDocument->setDocumentProperty("proxyimageminsize", QString::number(w->proxyImageMinSize()));
2518         }
2519         if (QString::number((int) w->useProxy()) != m_activeDocument->getDocumentProperty("enableproxy")) {
2520             m_activeDocument->setDocumentProperty("enableproxy", QString::number((int) w->useProxy()));
2521             m_activeDocument->setModified();
2522             slotUpdateProxySettings();
2523         }
2524         if (w->metadata() != m_activeDocument->metadata()) {
2525             m_activeDocument->setMetadata(w->metadata());
2526         }
2527     }
2528     delete w;
2529 }
2530
2531 void MainWindow::slotDisableProxies()
2532 {
2533     m_activeDocument->setDocumentProperty("enableproxy", QString::number((int) false));
2534     m_activeDocument->setModified();
2535     slotUpdateProxySettings();
2536 }
2537
2538 void MainWindow::slotUpdateProjectProfile(const QString &profile)
2539 {
2540     // Recreate the stopmotion widget if profile changes
2541     if (m_stopmotion) {
2542         delete m_stopmotion;
2543         m_stopmotion = NULL;
2544     }
2545
2546     // Deselect current effect / transition
2547     m_effectStack->slotClipItemSelected(NULL);
2548     m_transitionConfig->slotTransitionItemSelected(NULL, 0, QPoint(), false);
2549     m_clipMonitor->slotSetClipProducer(NULL);
2550     bool updateFps = m_activeDocument->setProfilePath(profile);
2551     KdenliveSettings::setCurrent_profile(profile);
2552     KdenliveSettings::setProject_fps(m_activeDocument->fps());
2553     setCaption(m_activeDocument->description(), m_activeDocument->isModified());
2554     m_activeDocument->clipManager()->clearUnusedProducers();
2555     m_monitorManager->resetProfiles(m_activeDocument->timecode());
2556     m_transitionConfig->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode(), m_activeDocument->tracksList());
2557     m_effectStack->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode());
2558     m_projectList->updateProjectFormat(m_activeDocument->timecode());
2559     if (m_renderWidget) {
2560         m_renderWidget->setProfile(m_activeDocument->mltProfile());
2561     }
2562     m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
2563     if (updateFps) {
2564         m_activeTimeline->updateProjectFps();
2565     }
2566     m_activeDocument->clipManager()->clearCache();
2567     m_activeTimeline->updateProfile();
2568     m_activeDocument->setModified(true);
2569     m_commandStack->activeStack()->clear();
2570     //Update the mouse position display so it will display in DF/NDF format by default based on the project setting.
2571     slotUpdateMousePosition(0);
2572     m_projectList->slotReloadClip();
2573     // We need to desactivate & reactivate monitors to get a refresh
2574     //m_monitorManager->switchMonitors();
2575 }
2576
2577
2578 void MainWindow::slotRenderProject()
2579 {
2580     if (!m_renderWidget) {
2581         QString projectfolder = m_activeDocument ? m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash) : KdenliveSettings::defaultprojectfolder();
2582         MltVideoProfile profile;
2583         if (m_activeDocument) {
2584             profile = m_activeDocument->mltProfile();
2585         }
2586         m_renderWidget = new RenderWidget(projectfolder, m_projectList->useProxy(), profile, this);
2587         connect(m_renderWidget, SIGNAL(shutdown()), this, SLOT(slotShutdown()));
2588         connect(m_renderWidget, SIGNAL(selectedRenderProfile(QMap<QString,QString>)), this, SLOT(slotSetDocumentRenderProfile(QMap<QString,QString>)));
2589         connect(m_renderWidget, SIGNAL(prepareRenderingData(bool,bool,QString)), this, SLOT(slotPrepareRendering(bool,bool,QString)));
2590         connect(m_renderWidget, SIGNAL(abortProcess(QString)), this, SIGNAL(abortRenderJob(QString)));
2591         connect(m_renderWidget, SIGNAL(openDvdWizard(QString)), this, SLOT(slotDvdWizard(QString)));
2592         if (m_activeDocument) {
2593             m_renderWidget->setProfile(m_activeDocument->mltProfile());
2594             m_renderWidget->setGuides(m_activeDocument->guidesXml(), m_activeDocument->projectDuration());
2595             m_renderWidget->setDocumentPath(m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash));
2596             m_renderWidget->setRenderProfile(m_activeDocument->getRenderProperties());
2597         }
2598     }
2599     slotCheckRenderStatus();
2600     m_renderWidget->show();
2601     m_renderWidget->showNormal();
2602
2603     // What are the following lines supposed to do?
2604     //m_activeTimeline->tracksNumber();
2605     //m_renderWidget->enableAudio(false);
2606     //m_renderWidget->export_audio;
2607 }
2608
2609 void MainWindow::slotCheckRenderStatus()
2610 {
2611     // Make sure there are no missing clips
2612     if (m_renderWidget)
2613         m_renderWidget->missingClips(m_projectList->hasMissingClips());
2614 }
2615
2616 void MainWindow::setRenderingProgress(const QString &url, int progress)
2617 {
2618     if (m_renderWidget)
2619         m_renderWidget->setRenderJob(url, progress);
2620 }
2621
2622 void MainWindow::setRenderingFinished(const QString &url, int status, const QString &error)
2623 {
2624     if (m_renderWidget)
2625         m_renderWidget->setRenderStatus(url, status, error);
2626 }
2627
2628 void MainWindow::slotCleanProject()
2629 {
2630     if (KMessageBox::warningContinueCancel(this, i18n("This will remove all unused clips from your project."), i18n("Clean up project")) == KMessageBox::Cancel) return;
2631     m_projectList->cleanup();
2632 }
2633
2634 void MainWindow::slotUpdateMousePosition(int pos)
2635 {
2636     if (m_activeDocument) {
2637         switch (m_timeFormatButton->currentItem()) {
2638         case 0:
2639             m_timeFormatButton->setText(m_activeDocument->timecode().getTimecodeFromFrames(pos) + " / " + m_activeDocument->timecode().getTimecodeFromFrames(m_activeTimeline->duration()));
2640             break;
2641         default:
2642             m_timeFormatButton->setText(QString::number(pos) + " / " + QString::number(m_activeTimeline->duration()));
2643         }
2644     }
2645 }
2646
2647 void MainWindow::slotUpdateProjectDuration(int pos)
2648 {
2649     if (m_activeDocument) {
2650         m_activeTimeline->setDuration(pos);
2651         slotUpdateMousePosition(m_activeTimeline->projectView()->getMousePos());
2652     }
2653 }
2654
2655 void MainWindow::slotUpdateDocumentState(bool modified)
2656 {
2657     if (!m_activeDocument) return;
2658     setCaption(m_activeDocument->description(), modified);
2659     m_saveAction->setEnabled(modified);
2660     if (modified) {
2661         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Link));
2662         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("document-save"));
2663     } else {
2664         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Text));
2665         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("kdenlive"));
2666     }
2667 }
2668
2669 void MainWindow::connectDocumentInfo(KdenliveDoc *doc)
2670 {
2671     if (m_activeDocument) {
2672         if (m_activeDocument == doc) return;
2673         disconnect(m_activeDocument, SIGNAL(progressInfo(QString,int)), this, SLOT(slotGotProgressInfo(QString,int)));
2674     }
2675     connect(doc, SIGNAL(progressInfo(QString,int)), this, SLOT(slotGotProgressInfo(QString,int)));
2676 }
2677
2678 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc)   //changed
2679 {
2680     //m_projectMonitor->stop();
2681     m_closeAction->setEnabled(m_timelineArea->count() > 1);
2682     kDebug() << "///////////////////   CONNECTING DOC TO PROJECT VIEW ////////////////";
2683     if (m_activeDocument) {
2684         if (m_activeDocument == doc) {
2685             return;
2686         }
2687         if (m_activeTimeline) {
2688             disconnect(m_projectMonitor, SIGNAL(renderPosition(int)), m_activeTimeline, SLOT(moveCursorPos(int)));
2689             disconnect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), m_activeTimeline, SLOT(slotSetZone(QPoint)));
2690             disconnect(m_projectMonitor, SIGNAL(durationChanged(int)), m_activeTimeline, SLOT(setDuration(int)));
2691             disconnect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), m_activeDocument, SLOT(setModified()));
2692             disconnect(m_notesWidget, SIGNAL(textChanged()), m_activeDocument, SLOT(setModified()));
2693             disconnect(m_clipMonitor, SIGNAL(zoneUpdated(QPoint)), m_activeDocument, SLOT(setModified()));
2694             disconnect(m_projectList, SIGNAL(projectModified()), m_activeDocument, SLOT(setModified()));
2695
2696             disconnect(m_projectMonitor->render, SIGNAL(refreshDocumentProducers(bool,bool)), m_activeDocument, SLOT(checkProjectClips(bool,bool)));
2697
2698             disconnect(m_activeDocument, SIGNAL(guidesUpdated()), this, SLOT(slotGuidesUpdated()));
2699             disconnect(m_activeDocument, SIGNAL(addProjectClip(DocClipBase*,bool)), m_projectList, SLOT(slotAddClip(DocClipBase*,bool)));
2700             disconnect(m_activeDocument, SIGNAL(resetProjectList()), m_projectList, SLOT(slotResetProjectList()));
2701             disconnect(m_activeDocument, SIGNAL(signalDeleteProjectClip(QString)), this, SLOT(slotDeleteClip(QString)));
2702             disconnect(m_activeDocument, SIGNAL(updateClipDisplay(QString)), m_projectList, SLOT(slotUpdateClip(QString)));
2703             disconnect(m_activeDocument, SIGNAL(selectLastAddedClip(QString)), m_projectList, SLOT(slotSelectClip(QString)));
2704             disconnect(m_activeTimeline->projectView(), SIGNAL(clipItemSelected(ClipItem*,bool)), this, SLOT(slotTimelineClipSelected(ClipItem*,bool)));
2705             disconnect(m_activeTimeline->projectView(), SIGNAL(transitionItemSelected(Transition*,int,QPoint,bool)), m_transitionConfig, SLOT(slotTransitionItemSelected(Transition*,int,QPoint,bool)));
2706             disconnect(m_activeTimeline->projectView(), SIGNAL(transitionItemSelected(Transition*,int,QPoint,bool)), this, SLOT(slotActivateTransitionView(Transition*)));
2707             disconnect(m_activeTimeline->projectView(), SIGNAL(playMonitor()), m_projectMonitor, SLOT(slotPlay()));
2708             disconnect(m_activeTimeline->projectView(), SIGNAL(displayMessage(QString,MessageType)), m_messageLabel, SLOT(setMessage(QString,MessageType)));
2709             disconnect(m_activeTimeline->projectView(), SIGNAL(showClipFrame(DocClipBase*,QPoint,bool,int)), m_clipMonitor, SLOT(slotSetClipProducer(DocClipBase*,QPoint,bool,int)));
2710             disconnect(m_projectList, SIGNAL(gotFilterJobResults(QString,int,int,stringMap,stringMap)), m_activeTimeline->projectView(), SLOT(slotGotFilterJobResults(QString,int,int,stringMap,stringMap)));
2711
2712             disconnect(m_activeTimeline, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(slotActivateMonitor()));
2713             disconnect(m_activeTimeline, SIGNAL(configTrack(int)), this, SLOT(slotConfigTrack(int)));
2714             disconnect(m_activeDocument, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
2715             disconnect(m_effectStack, SIGNAL(updateEffect(ClipItem*,int,QDomElement,QDomElement,int,bool)), m_activeTimeline->projectView(), SLOT(slotUpdateClipEffect(ClipItem*,int,QDomElement,QDomElement,int,bool)));
2716             disconnect(m_effectStack, SIGNAL(removeEffect(ClipItem*,int,QDomElement)), m_activeTimeline->projectView(), SLOT(slotDeleteEffect(ClipItem*,int,QDomElement)));
2717             disconnect(m_effectStack, SIGNAL(addEffect(ClipItem*,QDomElement)), trackView->projectView(), SLOT(slotAddEffect(ClipItem*,QDomElement)));
2718             disconnect(m_effectStack, SIGNAL(changeEffectState(ClipItem*,int,QList<int>,bool)), m_activeTimeline->projectView(), SLOT(slotChangeEffectState(ClipItem*,int,QList<int>,bool)));
2719             disconnect(m_effectStack, SIGNAL(changeEffectPosition(ClipItem*,int,QList<int>,int)), m_activeTimeline->projectView(), SLOT(slotChangeEffectPosition(ClipItem*,int,QList<int>,int)));
2720             disconnect(m_effectStack, SIGNAL(refreshEffectStack(ClipItem*)), m_activeTimeline->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
2721             disconnect(m_effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
2722             disconnect(m_effectStack, SIGNAL(displayMessage(QString,int)), this, SLOT(slotGotProgressInfo(QString,int)));
2723             disconnect(m_transitionConfig, SIGNAL(transitionUpdated(Transition*,QDomElement)), m_activeTimeline->projectView() , SLOT(slotTransitionUpdated(Transition*,QDomElement)));
2724             disconnect(m_transitionConfig, SIGNAL(seekTimeline(int)), m_activeTimeline->projectView() , SLOT(setCursorPos(int)));
2725             disconnect(m_transitionConfig, SIGNAL(importClipKeyframes(GraphicsRectItem)), m_activeTimeline->projectView() , SLOT(slotImportClipKeyframes(GraphicsRectItem)));
2726
2727             disconnect(m_activeTimeline->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(slotActivateMonitor()));
2728             disconnect(m_activeTimeline, SIGNAL(zoneMoved(int,int)), this, SLOT(slotZoneMoved(int,int)));
2729             disconnect(m_projectList, SIGNAL(loadingIsOver()), m_activeTimeline->projectView(), SLOT(slotUpdateAllThumbs()));
2730             disconnect(m_projectList, SIGNAL(refreshClip(QString)), m_activeTimeline->projectView(), SLOT(slotRefreshThumbs(QString)));
2731             disconnect(m_projectList, SIGNAL(addMarkers(QString,QList<CommentedTime>)), m_activeTimeline->projectView(), SLOT(slotAddClipMarker(QString,QList<CommentedTime>)));
2732             m_effectStack->clear();
2733         }
2734         //m_activeDocument->setRenderer(NULL);
2735         m_clipMonitor->stop();
2736     }
2737     KdenliveSettings::setCurrent_profile(doc->profilePath());
2738     KdenliveSettings::setProject_fps(doc->fps());
2739     m_monitorManager->resetProfiles(doc->timecode());
2740     m_clipMonitorDock->raise();
2741     m_projectList->setDocument(doc);
2742     m_transitionConfig->updateProjectFormat(doc->mltProfile(), doc->timecode(), doc->tracksList());
2743     m_effectStack->updateProjectFormat(doc->mltProfile(), doc->timecode());
2744     connect(m_projectList, SIGNAL(refreshClip(QString,bool)), trackView->projectView(), SLOT(slotRefreshThumbs(QString,bool)));
2745
2746     connect(m_projectList, SIGNAL(projectModified()), doc, SLOT(setModified()));
2747     connect(m_projectList, SIGNAL(clipNameChanged(QString,QString)), trackView->projectView(), SLOT(clipNameChanged(QString,QString)));
2748
2749     connect(trackView, SIGNAL(configTrack(int)), this, SLOT(slotConfigTrack(int)));
2750     connect(trackView, SIGNAL(updateTracksInfo()), this, SLOT(slotUpdateTrackInfo()));
2751     connect(trackView, SIGNAL(mousePosition(int)), this, SLOT(slotUpdateMousePosition(int)));
2752     connect(trackView->projectView(), SIGNAL(forceClipProcessing(QString)), m_projectList, SLOT(slotForceProcessing(QString)));
2753
2754     connect(trackView->projectView(), SIGNAL(importKeyframes(GraphicsRectItem,QString,int)), this, SLOT(slotProcessImportKeyframes(GraphicsRectItem,QString,int)));
2755
2756     connect(m_projectMonitor, SIGNAL(renderPosition(int)), trackView, SLOT(moveCursorPos(int)));
2757     connect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), trackView, SLOT(slotSetZone(QPoint)));
2758     connect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), doc, SLOT(setModified()));
2759     connect(m_clipMonitor, SIGNAL(zoneUpdated(QPoint)), doc, SLOT(setModified()));
2760     connect(m_projectMonitor->render, SIGNAL(refreshDocumentProducers(bool,bool)), doc, SLOT(checkProjectClips(bool,bool)));
2761
2762     connect(doc, SIGNAL(addProjectClip(DocClipBase*,bool)), m_projectList, SLOT(slotAddClip(DocClipBase*,bool)));
2763     connect(doc, SIGNAL(resetProjectList()), m_projectList, SLOT(slotResetProjectList()));
2764     connect(doc, SIGNAL(signalDeleteProjectClip(QString)), this, SLOT(slotDeleteClip(QString)));
2765     connect(doc, SIGNAL(updateClipDisplay(QString)), m_projectList, SLOT(slotUpdateClip(QString)));
2766     connect(doc, SIGNAL(selectLastAddedClip(QString)), m_projectList, SLOT(slotSelectClip(QString)));
2767
2768     connect(doc, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
2769     connect(doc, SIGNAL(guidesUpdated()), this, SLOT(slotGuidesUpdated()));
2770     connect(doc, SIGNAL(saveTimelinePreview(QString)), trackView, SLOT(slotSaveTimelinePreview(QString)));
2771
2772     connect(m_notesWidget, SIGNAL(textChanged()), doc, SLOT(setModified()));
2773
2774     connect(trackView->projectView(), SIGNAL(updateClipMarkers(DocClipBase*)), this, SLOT(slotUpdateClipMarkers(DocClipBase*)));
2775     connect(trackView, SIGNAL(showTrackEffects(int,TrackInfo)), this, SLOT(slotTrackSelected(int,TrackInfo)));
2776
2777     connect(trackView->projectView(), SIGNAL(clipItemSelected(ClipItem*,bool)), this, SLOT(slotTimelineClipSelected(ClipItem*,bool)));
2778     connect(trackView->projectView(), SIGNAL(transitionItemSelected(Transition*,int,QPoint,bool)), m_transitionConfig, SLOT(slotTransitionItemSelected(Transition*,int,QPoint,bool)));
2779     connect(trackView->projectView(), SIGNAL(transitionItemSelected(Transition*,int,QPoint,bool)), this, SLOT(slotActivateTransitionView(Transition*)));
2780     m_zoomSlider->setValue(doc->zoom().x());
2781     connect(trackView->projectView(), SIGNAL(zoomIn()), this, SLOT(slotZoomIn()));
2782     connect(trackView->projectView(), SIGNAL(zoomOut()), this, SLOT(slotZoomOut()));
2783     connect(trackView, SIGNAL(setZoom(int)), this, SLOT(slotSetZoom(int)));
2784     connect(trackView->projectView(), SIGNAL(displayMessage(QString,MessageType)), m_messageLabel, SLOT(setMessage(QString,MessageType)));
2785
2786     connect(trackView->projectView(), SIGNAL(showClipFrame(DocClipBase*,QPoint,bool,int)), m_clipMonitor, SLOT(slotSetClipProducer(DocClipBase*,QPoint,bool,int)));
2787     connect(trackView->projectView(), SIGNAL(playMonitor()), m_projectMonitor, SLOT(slotPlay()));
2788
2789     connect(trackView->projectView(), SIGNAL(transitionItemSelected(Transition*,int,QPoint,bool)), m_projectMonitor, SLOT(slotSetSelectedClip(Transition*)));
2790
2791     connect(m_projectList, SIGNAL(gotFilterJobResults(QString,int,int,stringMap,stringMap)), trackView->projectView(), SLOT(slotGotFilterJobResults(QString,int,int,stringMap,stringMap)));
2792
2793     connect(m_projectList, SIGNAL(addMarkers(QString,QList<CommentedTime>)), trackView->projectView(), SLOT(slotAddClipMarker(QString,QList<CommentedTime>)));
2794
2795     // Effect stack signals
2796     connect(m_effectStack, SIGNAL(updateEffect(ClipItem*,int,QDomElement,QDomElement,int,bool)), trackView->projectView(), SLOT(slotUpdateClipEffect(ClipItem*,int,QDomElement,QDomElement,int,bool)));
2797     connect(m_effectStack, SIGNAL(updateClipRegion(ClipItem*,int,QString)), trackView->projectView(), SLOT(slotUpdateClipRegion(ClipItem*,int,QString)));
2798     connect(m_effectStack, SIGNAL(removeEffect(ClipItem*,int,QDomElement)), trackView->projectView(), SLOT(slotDeleteEffect(ClipItem*,int,QDomElement)));
2799     connect(m_effectStack, SIGNAL(addEffect(ClipItem*,QDomElement)), trackView->projectView(), SLOT(slotAddEffect(ClipItem*,QDomElement)));
2800     connect(m_effectStack, SIGNAL(changeEffectState(ClipItem*,int,QList<int>,bool)), trackView->projectView(), SLOT(slotChangeEffectState(ClipItem*,int,QList<int>,bool)));
2801     connect(m_effectStack, SIGNAL(changeEffectPosition(ClipItem*,int,QList<int>,int)), trackView->projectView(), SLOT(slotChangeEffectPosition(ClipItem*,int,QList<int>,int)));
2802     
2803     connect(m_effectStack, SIGNAL(refreshEffectStack(ClipItem*)), trackView->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
2804     connect(m_effectStack, SIGNAL(seekTimeline(int)), trackView->projectView(), SLOT(seekCursorPos(int)));
2805     connect(m_effectStack, SIGNAL(importClipKeyframes(GraphicsRectItem)), trackView->projectView(), SLOT(slotImportClipKeyframes(GraphicsRectItem)));
2806     connect(m_effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
2807     connect(m_effectStack, SIGNAL(displayMessage(QString,int)), this, SLOT(slotGotProgressInfo(QString,int)));
2808     
2809     // Transition config signals
2810     connect(m_transitionConfig, SIGNAL(transitionUpdated(Transition*,QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition*,QDomElement)));
2811     connect(m_transitionConfig, SIGNAL(importClipKeyframes(GraphicsRectItem)), trackView->projectView() , SLOT(slotImportClipKeyframes(GraphicsRectItem)));
2812     connect(m_transitionConfig, SIGNAL(seekTimeline(int)), trackView->projectView() , SLOT(seekCursorPos(int)));
2813
2814     connect(trackView->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(slotActivateMonitor()));
2815     connect(trackView, SIGNAL(zoneMoved(int,int)), this, SLOT(slotZoneMoved(int,int)));
2816     connect(m_projectList, SIGNAL(loadingIsOver()), trackView->projectView(), SLOT(slotUpdateAllThumbs()));
2817     trackView->projectView()->setContextMenu(m_timelineContextMenu, m_timelineContextClipMenu, m_timelineContextTransitionMenu, m_clipTypeGroup, static_cast<QMenu*>(factory()->container("marker_menu", this)));
2818     m_activeTimeline = trackView;
2819     if (m_renderWidget) {
2820         slotCheckRenderStatus();
2821         m_renderWidget->setProfile(doc->mltProfile());
2822         m_renderWidget->setGuides(doc->guidesXml(), doc->projectDuration());
2823         m_renderWidget->setDocumentPath(doc->projectFolder().path(KUrl::AddTrailingSlash));
2824         m_renderWidget->setRenderProfile(doc->getRenderProperties());
2825     }
2826     //doc->setRenderer(m_projectMonitor->render);
2827     m_commandStack->setActiveStack(doc->commandStack());
2828     KdenliveSettings::setProject_display_ratio(doc->dar());
2829     //doc->clipManager()->checkAudioThumbs();
2830
2831     //m_overView->setScene(trackView->projectScene());
2832     //m_overView->scale(m_overView->width() / trackView->duration(), m_overView->height() / (50 * trackView->tracksNumber()));
2833     //m_overView->fitInView(m_overView->itemAt(0, 50), Qt::KeepAspectRatio);
2834
2835     setCaption(doc->description(), doc->isModified());
2836     m_saveAction->setEnabled(doc->isModified());
2837     m_normalEditTool->setChecked(true);
2838     m_activeDocument = doc;
2839     connect(m_projectMonitor, SIGNAL(durationChanged(int)), this, SLOT(slotUpdateProjectDuration(int)));
2840     m_monitorManager->setDocument(m_activeDocument);
2841     m_activeTimeline->updateProjectFps();
2842     m_activeDocument->checkProjectClips();
2843 #ifndef Q_WS_MAC
2844     m_recMonitor->slotUpdateCaptureFolder(m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash));
2845 #endif
2846     //Update the mouse position display so it will display in DF/NDF format by default based on the project setting.
2847     slotUpdateMousePosition(0);
2848
2849     // Make sure monitor is visible so that it is painted black on startup
2850     show();
2851     m_monitorManager->activateMonitor(Kdenlive::ClipMonitor, true);
2852     // set tool to select tool
2853     m_buttonSelectTool->setChecked(true);
2854 }
2855
2856 void MainWindow::slotZoneMoved(int start, int end)
2857 {
2858     m_activeDocument->setZone(start, end);
2859     m_projectMonitor->slotZoneMoved(start, end);
2860 }
2861
2862 void MainWindow::slotGuidesUpdated()
2863 {
2864     if (m_renderWidget)
2865         m_renderWidget->setGuides(m_activeDocument->guidesXml(), m_activeDocument->projectDuration());
2866 }
2867
2868 void MainWindow::slotEditKeys()
2869 {
2870     KShortcutsDialog dialog(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsAllowed, this);
2871     dialog.addCollection(actionCollection(), i18nc("general keyboard shortcuts", "General"));
2872     dialog.addCollection(m_effectsActionCollection, i18nc("effects and transitions keyboard shortcuts", "Effects & Transitions"));
2873     dialog.addCollection(m_tracksActionCollection, i18nc("timeline track keyboard shortcuts", "Timeline and Tracks"));
2874     dialog.configure();
2875 }
2876
2877 void MainWindow::slotPreferences(int page, int option)
2878 {
2879     /*
2880      * An instance of your dialog could be already created and could be
2881      * cached, in which case you want to display the cached dialog
2882      * instead of creating another one
2883      */
2884     if (m_stopmotion) {
2885         m_stopmotion->slotLive(false);
2886     }
2887
2888     if (KConfigDialog::showDialog("settings")) {
2889         KdenliveSettingsDialog* d = static_cast <KdenliveSettingsDialog*>(KConfigDialog::exists("settings"));
2890         if (page != -1) d->showPage(page, option);
2891         return;
2892     }
2893
2894     // KConfigDialog didn't find an instance of this dialog, so lets
2895     // create it :
2896
2897     // Get the mappable actions in localized form
2898     QMap<QString, QString> actions;
2899     KActionCollection* collection = actionCollection();
2900     foreach (const QString& action_name, m_action_names) {
2901         actions[collection->action(action_name)->text()] = action_name;
2902     }
2903
2904     KdenliveSettingsDialog* dialog = new KdenliveSettingsDialog(actions, this);
2905     connect(dialog, SIGNAL(settingsChanged(QString)), this, SLOT(updateConfiguration()));
2906     connect(dialog, SIGNAL(doResetProfile()), m_monitorManager, SLOT(slotResetProfiles()));
2907 #ifndef Q_WS_MAC
2908     connect(dialog, SIGNAL(updateCaptureFolder()), this, SLOT(slotUpdateCaptureFolder()));
2909 #endif
2910     dialog->show();
2911     if (page != -1) {
2912         dialog->showPage(page, option);
2913     }
2914 }
2915
2916 void MainWindow::slotUpdateCaptureFolder()
2917 {
2918
2919 #ifndef Q_WS_MAC
2920     if (m_activeDocument) m_recMonitor->slotUpdateCaptureFolder(m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash));
2921     else m_recMonitor->slotUpdateCaptureFolder(KdenliveSettings::defaultprojectfolder());
2922 #endif
2923 }
2924
2925 void MainWindow::updateConfiguration()
2926 {
2927     //TODO: we should apply settings to all projects, not only the current one
2928     if (m_activeTimeline) {
2929         m_activeTimeline->refresh();
2930         m_activeTimeline->projectView()->checkAutoScroll();
2931         m_activeTimeline->checkTrackHeight();
2932         if (m_activeDocument)
2933             m_activeDocument->clipManager()->checkAudioThumbs();
2934     }
2935     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
2936     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
2937     m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
2938     m_buttonAutomaticSplitAudio->setChecked(KdenliveSettings::splitaudio());
2939
2940     // Update list of transcoding profiles
2941     loadTranscoders();
2942     loadClipActions();
2943 #ifdef USE_JOGSHUTTLE
2944     activateShuttleDevice();
2945 #endif
2946
2947 }
2948
2949 void MainWindow::slotSwitchSplitAudio()
2950 {
2951     KdenliveSettings::setSplitaudio(!KdenliveSettings::splitaudio());
2952     m_buttonAutomaticSplitAudio->setChecked(KdenliveSettings::splitaudio());
2953 }
2954
2955 void MainWindow::slotSwitchVideoThumbs()
2956 {
2957     KdenliveSettings::setVideothumbnails(!KdenliveSettings::videothumbnails());
2958     if (m_activeTimeline) {
2959         m_activeTimeline->projectView()->slotUpdateAllThumbs();
2960     }
2961     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
2962 }
2963
2964 void MainWindow::slotSwitchAudioThumbs()
2965 {
2966     KdenliveSettings::setAudiothumbnails(!KdenliveSettings::audiothumbnails());
2967     if (m_activeTimeline) {
2968         m_activeTimeline->refresh();
2969         m_activeTimeline->projectView()->checkAutoScroll();
2970         if (m_activeDocument) {
2971             m_activeDocument->clipManager()->checkAudioThumbs();
2972         }
2973     }
2974     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
2975 }
2976
2977 void MainWindow::slotSwitchMarkersComments()
2978 {
2979     KdenliveSettings::setShowmarkers(!KdenliveSettings::showmarkers());
2980     if (m_activeTimeline) {
2981         m_activeTimeline->refresh();
2982     }
2983     m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
2984 }
2985
2986 void MainWindow::slotSwitchSnap()
2987 {
2988     KdenliveSettings::setSnaptopoints(!KdenliveSettings::snaptopoints());
2989     m_buttonSnap->setChecked(KdenliveSettings::snaptopoints());
2990 }
2991
2992
2993 void MainWindow::slotDeleteItem()
2994 {
2995     if (QApplication::focusWidget() &&
2996             QApplication::focusWidget()->parentWidget() &&
2997             QApplication::focusWidget()->parentWidget()->parentWidget() &&
2998             QApplication::focusWidget()->parentWidget()->parentWidget() == m_projectListDock) {
2999         m_projectList->slotRemoveClip();
3000
3001     } else {
3002         QWidget *widget = QApplication::focusWidget();
3003         while (widget) {
3004             if (widget == m_effectStackDock) {
3005                 m_effectStack->deleteCurrentEffect();
3006                 return;
3007             }
3008             widget = widget->parentWidget();
3009         }
3010
3011         // effect stack has no focus
3012         if (m_activeTimeline) {
3013             m_activeTimeline->projectView()->deleteSelectedClips();
3014         }
3015     }
3016 }
3017
3018 void MainWindow::slotUpdateClipMarkers(DocClipBase *clip)
3019 {
3020     if (m_clipMonitor->isActive()) {
3021         m_clipMonitor->checkOverlay();
3022     }
3023     m_clipMonitor->updateMarkers(clip);
3024 }
3025
3026 void MainWindow::slotAddClipMarker()
3027 {
3028     DocClipBase *clip = NULL;
3029     GenTime pos;
3030     if (m_projectMonitor->isActive()) {
3031         if (m_activeTimeline) {
3032             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
3033             if (item) {
3034                 pos = GenTime((int)((m_projectMonitor->position() - item->startPos() + item->cropStart()).frames(m_activeDocument->fps()) * item->speed() + 0.5), m_activeDocument->fps());
3035                 clip = item->baseClip();
3036             }
3037         }
3038     } else {
3039         clip = m_clipMonitor->activeClip();
3040         pos = m_clipMonitor->position();
3041     }
3042     if (!clip) {
3043         m_messageLabel->setMessage(i18n("Cannot find clip to add marker"), ErrorMessage);
3044         return;
3045     }
3046     QString id = clip->getId();
3047     CommentedTime marker(pos, i18n("Marker"), KdenliveSettings::default_marker_type());
3048     QPointer<MarkerDialog> d = new MarkerDialog(clip, marker,
3049                                                 m_activeDocument->timecode(), i18n("Add Marker"), this);
3050     if (d->exec() == QDialog::Accepted) {
3051         m_activeTimeline->projectView()->slotAddClipMarker(id, QList <CommentedTime>() << d->newMarker());
3052         QString hash = clip->getClipHash();
3053         if (!hash.isEmpty()) m_activeDocument->cacheImage(hash + '#' + QString::number(d->newMarker().time().frames(m_activeDocument->fps())), d->markerImage());
3054     }
3055     delete d;
3056 }
3057
3058 void MainWindow::slotDeleteClipMarker()
3059 {
3060     DocClipBase *clip = NULL;
3061     GenTime pos;
3062     if (m_projectMonitor->isActive()) {
3063         if (m_activeTimeline) {
3064             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
3065             if (item) {
3066                 pos = (m_projectMonitor->position() - item->startPos() + item->cropStart()) / item->speed();
3067                 clip = item->baseClip();
3068             }
3069         }
3070     } else {
3071         clip = m_clipMonitor->activeClip();
3072         pos = m_clipMonitor->position();
3073     }
3074     if (!clip) {
3075         m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
3076         return;
3077     }
3078
3079     QString id = clip->getId();
3080     QString comment = clip->markerComment(pos);
3081     if (comment.isEmpty()) {
3082         m_messageLabel->setMessage(i18n("No marker found at cursor time"), ErrorMessage);
3083         return;
3084     }
3085     m_activeTimeline->projectView()->slotDeleteClipMarker(comment, id, pos);
3086 }
3087
3088 void MainWindow::slotDeleteAllClipMarkers()
3089 {
3090     DocClipBase *clip = NULL;
3091     if (m_projectMonitor->isActive()) {
3092         if (m_activeTimeline) {
3093             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
3094             if (item) {
3095                 clip = item->baseClip();
3096             }
3097         }
3098     } else {
3099         clip = m_clipMonitor->activeClip();
3100     }
3101     if (!clip) {
3102         m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
3103         return;
3104     }
3105     m_activeTimeline->projectView()->slotDeleteAllClipMarkers(clip->getId());
3106 }
3107
3108 void MainWindow::slotEditClipMarker()
3109 {
3110     DocClipBase *clip = NULL;
3111     GenTime pos;
3112     if (m_projectMonitor->isActive()) {
3113         if (m_activeTimeline) {
3114             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
3115             if (item) {
3116                 pos = (m_projectMonitor->position() - item->startPos() + item->cropStart()) / item->speed();
3117                 clip = item->baseClip();
3118             }
3119         }
3120     } else {
3121         clip = m_clipMonitor->activeClip();
3122         pos = m_clipMonitor->position();
3123     }
3124     if (!clip) {
3125         m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
3126         return;
3127     }
3128
3129     QString id = clip->getId();
3130     CommentedTime oldMarker = clip->markerAt(pos);
3131     if (oldMarker == CommentedTime()) {
3132         m_messageLabel->setMessage(i18n("No marker found at cursor time"), ErrorMessage);
3133         return;
3134     }
3135
3136     QPointer<MarkerDialog> d = new MarkerDialog(clip, oldMarker,
3137                                                 m_activeDocument->timecode(), i18n("Edit Marker"), this);
3138     if (d->exec() == QDialog::Accepted) {
3139         m_activeTimeline->projectView()->slotAddClipMarker(id, QList <CommentedTime>() <<d->newMarker());
3140         QString hash = clip->getClipHash();
3141         if (!hash.isEmpty()) m_activeDocument->cacheImage(hash + '#' + QString::number(d->newMarker().time().frames(m_activeDocument->fps())), d->markerImage());
3142         if (d->newMarker().time() != pos) {
3143             // remove old marker
3144             oldMarker.setMarkerType(-1);
3145             m_activeTimeline->projectView()->slotAddClipMarker(id, QList <CommentedTime>() <<oldMarker);
3146         }
3147     }
3148     delete d;
3149 }
3150
3151 void MainWindow::slotAddMarkerGuideQuickly()
3152 {
3153     if (!m_activeTimeline || !m_activeDocument)
3154         return;
3155
3156     if (m_clipMonitor->isActive()) {
3157         DocClipBase *clip = m_clipMonitor->activeClip();
3158         GenTime pos = m_clipMonitor->position();
3159
3160         if (!clip) {
3161             m_messageLabel->setMessage(i18n("Cannot find clip to add marker"), ErrorMessage);
3162             return;
3163         }
3164         //TODO: allow user to set default marker category
3165         CommentedTime marker(pos, m_activeDocument->timecode().getDisplayTimecode(pos, false), KdenliveSettings::default_marker_type());
3166         m_activeTimeline->projectView()->slotAddClipMarker(clip->getId(), QList <CommentedTime>() <<marker);
3167     } else {
3168         m_activeTimeline->projectView()->slotAddGuide(false);
3169     }
3170 }
3171
3172 void MainWindow::slotAddGuide()
3173 {
3174     if (m_activeTimeline)
3175         m_activeTimeline->projectView()->slotAddGuide();
3176 }
3177
3178 void MainWindow::slotInsertSpace()
3179 {
3180     if (m_activeTimeline)
3181         m_activeTimeline->projectView()->slotInsertSpace();
3182 }
3183
3184 void MainWindow::slotRemoveSpace()
3185 {
3186     if (m_activeTimeline)
3187         m_activeTimeline->projectView()->slotRemoveSpace();
3188 }
3189
3190 void MainWindow::slotInsertTrack(int ix)
3191 {
3192     m_monitorManager->activateMonitor(Kdenlive::ProjectMonitor);
3193     if (m_activeTimeline) {
3194         if (ix == -1) {
3195             ix = m_activeTimeline->projectView()->selectedTrack();
3196         }
3197         m_activeTimeline->projectView()->slotInsertTrack(ix);
3198     }
3199     if (m_activeDocument) {
3200         m_transitionConfig->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode(), m_activeDocument->tracksList());
3201     }
3202 }
3203
3204 void MainWindow::slotDeleteTrack(int ix)
3205 {
3206     m_monitorManager->activateMonitor(Kdenlive::ProjectMonitor);
3207     if (m_activeTimeline) {
3208         if (ix == -1) {
3209             ix = m_activeTimeline->projectView()->selectedTrack();
3210         }
3211         m_activeTimeline->projectView()->slotDeleteTrack(ix);
3212     }
3213     if (m_activeDocument) {
3214         m_transitionConfig->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode(), m_activeDocument->tracksList());
3215     }
3216 }
3217
3218 void MainWindow::slotConfigTrack(int ix)
3219 {
3220     m_monitorManager->activateMonitor(Kdenlive::ProjectMonitor);
3221     if (m_activeTimeline)
3222         m_activeTimeline->projectView()->slotConfigTracks(ix);
3223     if (m_activeDocument)
3224         m_transitionConfig->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode(), m_activeDocument->tracksList());
3225 }
3226
3227 void MainWindow::slotSelectTrack()
3228 {
3229     m_monitorManager->activateMonitor(Kdenlive::ProjectMonitor);
3230     if (m_activeTimeline) {
3231         m_activeTimeline->projectView()->slotSelectClipsInTrack();
3232     }
3233 }
3234
3235 void MainWindow::slotSelectAllTracks()
3236 {
3237     m_monitorManager->activateMonitor(Kdenlive::ProjectMonitor);
3238     if (m_activeTimeline)
3239         m_activeTimeline->projectView()->slotSelectAllClips();
3240 }
3241
3242 void MainWindow::slotEditGuide()
3243 {
3244     if (m_activeTimeline)
3245         m_activeTimeline->projectView()->slotEditGuide();
3246 }
3247
3248 void MainWindow::slotDeleteGuide()
3249 {
3250     if (m_activeTimeline)
3251         m_activeTimeline->projectView()->slotDeleteGuide();
3252 }
3253
3254 void MainWindow::slotDeleteAllGuides()
3255 {
3256     if (m_activeTimeline)
3257         m_activeTimeline->projectView()->slotDeleteAllGuides();
3258 }
3259
3260 void MainWindow::slotCutTimelineClip()
3261 {
3262     if (m_activeTimeline)
3263         m_activeTimeline->projectView()->cutSelectedClips();
3264 }
3265
3266 void MainWindow::slotInsertClipOverwrite()
3267 {
3268     if (m_activeTimeline) {
3269         QStringList data = m_clipMonitor->getZoneInfo();
3270         m_activeTimeline->projectView()->insertZoneOverwrite(data, m_activeTimeline->inPoint());
3271     }
3272 }
3273
3274 void MainWindow::slotSelectTimelineClip()
3275 {
3276     if (m_activeTimeline)
3277         m_activeTimeline->projectView()->selectClip(true);
3278 }
3279
3280 void MainWindow::slotSelectTimelineTransition()
3281 {
3282     if (m_activeTimeline)
3283         m_activeTimeline->projectView()->selectTransition(true);
3284 }
3285
3286 void MainWindow::slotDeselectTimelineClip()
3287 {
3288     if (m_activeTimeline)
3289         m_activeTimeline->projectView()->selectClip(false, true);
3290 }
3291
3292 void MainWindow::slotDeselectTimelineTransition()
3293 {
3294     if (m_activeTimeline)
3295         m_activeTimeline->projectView()->selectTransition(false, true);
3296 }
3297
3298 void MainWindow::slotSelectAddTimelineClip()
3299 {
3300     if (m_activeTimeline)
3301         m_activeTimeline->projectView()->selectClip(true, true);
3302 }
3303
3304 void MainWindow::slotSelectAddTimelineTransition()
3305 {
3306     if (m_activeTimeline)
3307         m_activeTimeline->projectView()->selectTransition(true, true);
3308 }
3309
3310 void MainWindow::slotGroupClips()
3311 {
3312     if (m_activeTimeline)
3313         m_activeTimeline->projectView()->groupClips();
3314 }
3315
3316 void MainWindow::slotUnGroupClips()
3317 {
3318     if (m_activeTimeline)
3319         m_activeTimeline->projectView()->groupClips(false);
3320 }
3321
3322 void MainWindow::slotEditItemDuration()
3323 {
3324     if (m_activeTimeline)
3325         m_activeTimeline->projectView()->editItemDuration();
3326 }
3327
3328 void MainWindow::slotAddProjectClip(const KUrl &url, const stringMap &data)
3329 {
3330     if (m_activeDocument) {
3331         m_activeDocument->slotAddClipFile(url, data);
3332     }
3333 }
3334
3335 void MainWindow::slotAddProjectClipList(const KUrl::List &urls)
3336 {
3337     if (m_activeDocument)
3338         m_activeDocument->slotAddClipList(urls);
3339 }
3340
3341 void MainWindow::slotAddTransition(QAction *result)
3342 {
3343     if (!result) return;
3344     QStringList info = result->data().toStringList();
3345     if (info.isEmpty()) return;
3346     QDomElement transition = transitions.getEffectByTag(info.at(1), info.at(2));
3347     if (m_activeTimeline && !transition.isNull()) {
3348         m_activeTimeline->projectView()->slotAddTransitionToSelectedClips(transition.cloneNode().toElement());
3349     }
3350 }
3351
3352 void MainWindow::slotAddVideoEffect(QAction *result)
3353 {
3354     if (!result) {
3355         return;
3356     }
3357     const int VideoEffect = 1;
3358     const int AudioEffect = 2;
3359     QStringList info = result->data().toStringList();
3360
3361     if (info.isEmpty() || info.size() < 3) {
3362         return;
3363     }
3364     QDomElement effect ;
3365     if (info.last() == QString::number((int) VideoEffect)) {
3366         effect = videoEffects.getEffectByTag(info.at(0), info.at(1));
3367     } else if (info.last() == QString::number((int) AudioEffect)) {
3368         effect = audioEffects.getEffectByTag(info.at(0), info.at(1));
3369     } else {
3370         effect = customEffects.getEffectByTag(info.at(0), info.at(1));
3371     }
3372
3373     if (!effect.isNull()) {
3374         slotAddEffect(effect);
3375     } else {
3376         m_messageLabel->setMessage(i18n("Cannot find effect %1 / %2", info.at(0), info.at(1)), ErrorMessage);
3377     }
3378 }
3379
3380
3381 void MainWindow::slotZoomIn()
3382 {
3383     m_zoomSlider->setValue(m_zoomSlider->value() - 1);
3384     slotShowZoomSliderToolTip();
3385 }
3386
3387 void MainWindow::slotZoomOut()
3388 {
3389     m_zoomSlider->setValue(m_zoomSlider->value() + 1);
3390     slotShowZoomSliderToolTip();
3391 }
3392
3393 void MainWindow::slotFitZoom()
3394 {
3395     if (m_activeTimeline)
3396         m_zoomSlider->setValue(m_activeTimeline->fitZoom());
3397 }
3398
3399 void MainWindow::slotSetZoom(int value)
3400 {
3401     value = qMax(m_zoomSlider->minimum(), value);
3402     value = qMin(m_zoomSlider->maximum(), value);
3403
3404     if (m_activeTimeline) {
3405         m_activeTimeline->slotChangeZoom(value);
3406     }
3407
3408     m_zoomOut->setEnabled(value < m_zoomSlider->maximum());
3409     m_zoomIn->setEnabled(value > m_zoomSlider->minimum());
3410     slotUpdateZoomSliderToolTip(value);
3411
3412     m_zoomSlider->blockSignals(true);
3413     m_zoomSlider->setValue(value);
3414     m_zoomSlider->blockSignals(false);
3415 }
3416
3417 void MainWindow::slotShowZoomSliderToolTip(int zoomlevel)
3418 {
3419     if (zoomlevel != -1) {
3420         slotUpdateZoomSliderToolTip(zoomlevel);
3421     }
3422
3423     QPoint global = m_zoomSlider->rect().topLeft();
3424     global.ry() += m_zoomSlider->height() / 2;
3425     QHelpEvent toolTipEvent(QEvent::ToolTip, QPoint(0, 0), m_zoomSlider->mapToGlobal(global));
3426     QApplication::sendEvent(m_zoomSlider, &toolTipEvent);
3427 }
3428
3429 void MainWindow::slotUpdateZoomSliderToolTip(int zoomlevel)
3430 {
3431     m_zoomSlider->setToolTip(i18n("Zoom Level: %1/13", (13 - zoomlevel)));
3432 }
3433
3434 void MainWindow::slotGotProgressInfo(const QString &message, int progress, MessageType type)
3435 {
3436     if (type == DefaultMessage) {
3437         m_statusProgressBar->setValue(progress);
3438     }
3439     m_messageLabel->setMessage(message, type);
3440     if (progress >= 0) {
3441         if (type == DefaultMessage) {
3442             m_statusProgressBar->setVisible(true);
3443         }
3444     } else {
3445         m_statusProgressBar->setVisible(false);
3446     }
3447 }
3448
3449 void MainWindow::slotShowClipProperties(DocClipBase *clip)
3450 {
3451     if (clip->clipType() == Text) {
3452         QString titlepath = m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
3453         if (!clip->getProperty("resource").isEmpty() && clip->getProperty("xmldata").isEmpty()) {
3454             // template text clip
3455
3456             // Get the list of existing templates
3457             QStringList filter;
3458             filter << "*.kdenlivetitle";
3459             QStringList templateFiles = QDir(titlepath).entryList(filter, QDir::Files);
3460
3461             QDialog *dia = new QDialog(this);
3462             Ui::TemplateClip_UI dia_ui;
3463             dia_ui.setupUi(dia);
3464             int ix = -1;
3465             const QString templatePath = clip->getProperty("resource");
3466             for (int i = 0; i < templateFiles.size(); ++i) {
3467                 dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), titlepath + templateFiles.at(i));
3468                 if (templatePath == KUrl(titlepath + templateFiles.at(i)).path()) ix = i;
3469             }
3470             if (ix != -1) dia_ui.template_list->comboBox()->setCurrentIndex(ix);
3471             else dia_ui.template_list->comboBox()->insertItem(0, templatePath);
3472             dia_ui.template_list->fileDialog()->setFilter("*.kdenlivetitle");
3473             //warning: setting base directory doesn't work??
3474             KUrl startDir(titlepath);
3475             dia_ui.template_list->fileDialog()->setUrl(startDir);
3476             dia_ui.description->setText(clip->getProperty("description"));
3477             if (dia->exec() == QDialog::Accepted) {
3478                 QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
3479                 if (textTemplate.isEmpty()) {
3480                     textTemplate = dia_ui.template_list->comboBox()->currentText();
3481                 }
3482
3483                 QMap <QString, QString> newprops;
3484
3485                 if (KUrl(textTemplate).path() != templatePath) {
3486                     // The template was changed
3487                     newprops.insert("resource", textTemplate);
3488                 }
3489
3490                 if (dia_ui.description->toPlainText() != clip->getProperty("description")) {
3491                     newprops.insert("description", dia_ui.description->toPlainText());
3492                 }
3493
3494                 QString newtemplate = newprops.value("xmltemplate");
3495                 if (newtemplate.isEmpty()) {
3496                     newtemplate = templatePath;
3497                 }
3498
3499                 // template modified we need to update xmldata
3500                 QString description = newprops.value("description");
3501                 if (description.isEmpty()) {
3502                     description = clip->getProperty("description");
3503                 } else {
3504                     newprops.insert("templatetext", description);
3505                 }
3506
3507                 //newprops.insert("xmldata", m_projectList->generateTemplateXml(newtemplate, description).toString());
3508                 if (!newprops.isEmpty()) {
3509                     EditClipCommand *command = new EditClipCommand(m_projectList, clip->getId(), clip->currentProperties(newprops), newprops, true);
3510                     m_activeDocument->commandStack()->push(command);
3511                 }
3512             }
3513             delete dia;
3514             return;
3515         }
3516         QString path = clip->getProperty("resource");
3517         QPointer<TitleWidget> dia_ui = new TitleWidget(KUrl(), m_activeDocument->timecode(), titlepath, m_projectMonitor->render, this);
3518         QDomDocument doc;
3519         doc.setContent(clip->getProperty("xmldata"));
3520         dia_ui->setXml(doc);
3521         if (dia_ui->exec() == QDialog::Accepted) {
3522             QMap <QString, QString> newprops;
3523             newprops.insert("xmldata", dia_ui->xml().toString());
3524             if (dia_ui->duration() != clip->duration().frames(m_activeDocument->fps())) {
3525                 // duration changed, we need to update duration
3526                 newprops.insert("out", QString::number(dia_ui->duration() - 1));
3527                 int currentLength = QString(clip->producerProperty("length")).toInt();
3528                 if (currentLength <= dia_ui->duration()) {
3529                     newprops.insert("length", QString::number(dia_ui->duration()));
3530                 } else {
3531                     newprops.insert("length", clip->producerProperty("length"));
3532                 }
3533             }
3534             if (!path.isEmpty()) {
3535                 // we are editing an external file, asked if we want to detach from that file or save the result to that title file.
3536                 if (KMessageBox::questionYesNo(this, i18n("You are editing an external title clip (%1). Do you want to save your changes to the title file or save the changes for this project only?", path), i18n("Save Title"), KGuiItem(i18n("Save to title file")), KGuiItem(i18n("Save in project only"))) == KMessageBox::Yes) {
3537                     // save to external file
3538                     dia_ui->saveTitle(path);
3539                 } else {
3540                     newprops.insert("resource", QString());
3541                 }
3542             }
3543             EditClipCommand *command = new EditClipCommand(m_projectList, clip->getId(), clip->currentProperties(newprops), newprops, true);
3544             m_activeDocument->commandStack()->push(command);
3545             //m_activeTimeline->projectView()->slotUpdateClip(clip->getId());
3546             m_activeDocument->setModified(true);
3547         }
3548         delete dia_ui;
3549
3550         //m_activeDocument->editTextClip(clip->getProperty("xml"), clip->getId());
3551         return;
3552     }
3553     
3554     // Check if we already have a properties dialog opened for that clip
3555     QList <ClipProperties *> list = findChildren<ClipProperties *>();
3556     for (int i = 0; i < list.size(); ++i) {
3557         if (list.at(i)->clipId() == clip->getId()) {
3558             // We have one dialog, show it
3559             list.at(i)->raise();
3560             return;
3561         }
3562     }
3563
3564     // any type of clip but a title
3565     ClipProperties *dia = new ClipProperties(clip, m_activeDocument->timecode(), m_activeDocument->fps(), this);
3566
3567     if (clip->clipType() == AV || clip->clipType() == Video || clip->clipType() == Playlist || clip->clipType() == SlideShow) {
3568         // request clip thumbnails
3569         connect(m_activeDocument->clipManager(), SIGNAL(gotClipPropertyThumbnail(QString,QImage)), dia, SLOT(slotGotThumbnail(QString,QImage)));
3570         connect(dia, SIGNAL(requestThumb(QString,QList<int>)), m_activeDocument->clipManager(), SLOT(slotRequestThumbs(QString,QList<int>)));
3571         m_activeDocument->clipManager()->slotRequestThumbs(QString('?' + clip->getId()), QList<int>() << clip->getClipThumbFrame());
3572     }
3573     
3574     connect(dia, SIGNAL(addMarkers(QString,QList<CommentedTime>)), m_activeTimeline->projectView(), SLOT(slotAddClipMarker(QString,QList<CommentedTime>)));
3575     connect(dia, SIGNAL(editAnalysis(QString,QString,QString)), m_activeTimeline->projectView(), SLOT(slotAddClipExtraData(QString,QString,QString)));
3576     connect(m_activeTimeline->projectView(), SIGNAL(updateClipMarkers(DocClipBase*)), dia, SLOT(slotFillMarkersList(DocClipBase*)));
3577     connect(m_activeTimeline->projectView(), SIGNAL(updateClipExtraData(DocClipBase*)), dia, SLOT(slotUpdateAnalysisData(DocClipBase*)));
3578     connect(m_projectList, SIGNAL(updateAnalysisData(DocClipBase*)), dia, SLOT(slotUpdateAnalysisData(DocClipBase*)));
3579     connect(dia, SIGNAL(loadMarkers(QString)), m_activeTimeline->projectView(), SLOT(slotLoadClipMarkers(QString)));
3580     connect(dia, SIGNAL(saveMarkers(QString)), m_activeTimeline->projectView(), SLOT(slotSaveClipMarkers(QString)));
3581     connect(dia, SIGNAL(deleteProxy(QString)), m_projectList, SLOT(slotDeleteProxy(QString)));
3582     connect(dia, SIGNAL(applyNewClipProperties(QString,QMap<QString,QString>,QMap<QString,QString>,bool,bool)), this, SLOT(slotApplyNewClipProperties(QString,QMap<QString,QString>,QMap<QString,QString>,bool,bool)));
3583     dia->show();
3584 }
3585
3586
3587 void MainWindow::slotApplyNewClipProperties(const QString &id, const QMap <QString, QString> &props, const QMap <QString, QString> &newprops, bool refresh, bool reload)
3588 {
3589     if (newprops.isEmpty()) {
3590         return;
3591     }
3592
3593     EditClipCommand *command = new EditClipCommand(m_projectList, id, props, newprops, true);
3594     m_activeDocument->commandStack()->push(command);
3595     m_activeDocument->setModified();
3596
3597     if (refresh) {
3598         // update clip occurences in timeline
3599         m_activeTimeline->projectView()->slotUpdateClip(id, reload);
3600     }
3601 }
3602
3603
3604 void MainWindow::slotShowClipProperties(const QList <DocClipBase *> &cliplist, const QMap<QString, QString> &commonproperties)
3605 {
3606     QPointer<ClipProperties> dia = new ClipProperties(cliplist,
3607                                                       m_activeDocument->timecode(), commonproperties, this);
3608     if (dia->exec() == QDialog::Accepted) {
3609         QUndoCommand *command = new QUndoCommand();
3610         command->setText(i18n("Edit clips"));
3611         QMap <QString, QString> newImageProps = dia->properties();
3612         // Transparency setting applies only for images
3613         QMap <QString, QString> newProps = newImageProps;
3614         newProps.remove("transparency");
3615
3616         for (int i = 0; i < cliplist.count(); ++i) {
3617             DocClipBase *clip = cliplist.at(i);
3618             if (clip->clipType() == Image)
3619                 new EditClipCommand(m_projectList, clip->getId(), clip->currentProperties(newImageProps), newImageProps, true, command);
3620             else
3621                 new EditClipCommand(m_projectList, clip->getId(), clip->currentProperties(newProps), newProps, true, command);
3622         }
3623         m_activeDocument->commandStack()->push(command);
3624         for (int i = 0; i < cliplist.count(); ++i) {
3625             m_activeTimeline->projectView()->slotUpdateClip(cliplist.at(i)->getId(), dia->needsTimelineReload());
3626         }
3627     }
3628     delete dia;
3629 }
3630
3631 void MainWindow::customEvent(QEvent* e)
3632 {
3633     if (e->type() == QEvent::User)
3634         m_messageLabel->setMessage(static_cast <MltErrorEvent *>(e)->message(), MltError);
3635 }
3636
3637 void MainWindow::slotTimelineClipSelected(ClipItem* item, bool raise)
3638 {
3639     if (item != m_mainClip) {
3640         if (m_mainClip) {
3641             m_mainClip->setMainSelectedClip(false);
3642         }
3643         if (item) {
3644             item->setMainSelectedClip(true);
3645         }
3646         m_mainClip = item;
3647     }
3648
3649     m_effectStack->slotClipItemSelected(item);
3650     m_projectMonitor->slotSetSelectedClip(item);
3651     if (raise) {
3652         m_effectStack->raiseWindow(m_effectStackDock);
3653     }
3654 }
3655
3656 void MainWindow::slotTrackSelected(int index, const TrackInfo &info, bool raise)
3657 {
3658     m_effectStack->slotTrackItemSelected(index, info);
3659     if (raise) {
3660         m_effectStack->raiseWindow(m_effectStackDock);
3661     }
3662 }
3663
3664 void MainWindow::slotActivateTransitionView(Transition *transition)
3665 {
3666     if (transition)
3667         m_transitionConfig->raiseWindow(m_transitionConfigDock);
3668 }
3669
3670 void MainWindow::slotSnapRewind()
3671 {
3672     if (m_projectMonitor->isActive()) {
3673         if (m_activeTimeline) {
3674             m_activeTimeline->projectView()->slotSeekToPreviousSnap();
3675         }
3676     } else  {
3677         m_clipMonitor->slotSeekToPreviousSnap();
3678     }
3679 }
3680
3681 void MainWindow::slotSnapForward()
3682 {
3683     if (m_projectMonitor->isActive()) {
3684         if (m_activeTimeline) {
3685             m_activeTimeline->projectView()->slotSeekToNextSnap();
3686         }
3687     } else {
3688         m_clipMonitor->slotSeekToNextSnap();
3689     }
3690 }
3691
3692 void MainWindow::slotClipStart()
3693 {
3694     if (m_projectMonitor->isActive()) {
3695         if (m_activeTimeline) {
3696             m_activeTimeline->projectView()->clipStart();
3697         }
3698     }
3699 }
3700
3701 void MainWindow::slotClipEnd()
3702 {
3703     if (m_projectMonitor->isActive()) {
3704         if (m_activeTimeline) {
3705             m_activeTimeline->projectView()->clipEnd();
3706         }
3707     }
3708 }
3709
3710 void MainWindow::slotZoneStart()
3711 {
3712     if (m_projectMonitor->isActive())
3713         m_projectMonitor->slotZoneStart();
3714     else
3715         m_clipMonitor->slotZoneStart();
3716 }
3717
3718 void MainWindow::slotZoneEnd()
3719 {
3720     if (m_projectMonitor->isActive())
3721         m_projectMonitor->slotZoneEnd();
3722     else
3723         m_clipMonitor->slotZoneEnd();
3724 }
3725
3726 void MainWindow::slotChangeTool(QAction * action)
3727 {
3728     if (action == m_buttonSelectTool)
3729         slotSetTool(SelectTool);
3730     else if (action == m_buttonRazorTool)
3731         slotSetTool(RazorTool);
3732     else if (action == m_buttonSpacerTool)
3733         slotSetTool(SpacerTool);
3734 }
3735
3736 void MainWindow::slotChangeEdit(QAction * action)
3737 {
3738     if (!m_activeTimeline)
3739         return;
3740
3741     if (action == m_overwriteEditTool)
3742         m_activeTimeline->projectView()->setEditMode(OverwriteEdit);
3743     else if (action == m_insertEditTool)
3744         m_activeTimeline->projectView()->setEditMode(InsertEdit);
3745     else
3746         m_activeTimeline->projectView()->setEditMode(NormalEdit);
3747 }
3748
3749 void MainWindow::slotSetTool(ProjectTool tool)
3750 {
3751     if (m_activeDocument && m_activeTimeline) {
3752         //m_activeDocument->setTool(tool);
3753         QString message;
3754         switch (tool)  {
3755         case SpacerTool:
3756             message = i18n("Ctrl + click to use spacer on current track only");
3757             break;
3758         case RazorTool:
3759             message = i18n("Click on a clip to cut it");
3760             break;
3761         default:
3762             message = i18n("Shift + click to create a selection rectangle, Ctrl + click to add an item to selection");
3763             break;
3764         }
3765         m_messageLabel->setMessage(message, InformationMessage);
3766         m_activeTimeline->projectView()->setTool(tool);
3767     }
3768 }
3769
3770 void MainWindow::slotCopy()
3771 {
3772     if (m_activeDocument && m_activeTimeline)
3773         m_activeTimeline->projectView()->copyClip();
3774 }
3775
3776 void MainWindow::slotPaste()
3777 {
3778     if (m_activeDocument && m_activeTimeline)
3779         m_activeTimeline->projectView()->pasteClip();
3780 }
3781
3782 void MainWindow::slotPasteEffects()
3783 {
3784     if (m_activeDocument && m_activeTimeline)
3785         m_activeTimeline->projectView()->pasteClipEffects();
3786 }
3787
3788 void MainWindow::slotFind()
3789 {
3790     if (!m_activeDocument || !m_activeTimeline) {
3791         return;
3792     }
3793
3794     m_projectSearch->setEnabled(false);
3795     m_findActivated = true;
3796     m_findString.clear();
3797     m_activeTimeline->projectView()->initSearchStrings();
3798     statusBar()->showMessage(i18n("Starting -- find text as you type"));
3799     m_findTimer.start(5000);
3800     qApp->installEventFilter(this);
3801 }
3802
3803 void MainWindow::slotFindNext()
3804 {
3805     if (m_activeTimeline && m_activeTimeline->projectView()->findNextString(m_findString)) {
3806         statusBar()->showMessage(i18n("Found: %1", m_findString));
3807     } else {
3808         statusBar()->showMessage(i18n("Reached end of project"));
3809     }
3810     m_findTimer.start(4000);
3811 }
3812
3813 void MainWindow::findAhead()
3814 {
3815     if (m_activeTimeline && m_activeTimeline->projectView()->findString(m_findString)) {
3816         m_projectSearchNext->setEnabled(true);
3817         statusBar()->showMessage(i18n("Found: %1", m_findString));
3818     } else {
3819         m_projectSearchNext->setEnabled(false);
3820         statusBar()->showMessage(i18n("Not found: %1", m_findString));
3821     }
3822 }
3823
3824 void MainWindow::findTimeout()
3825 {
3826     m_projectSearchNext->setEnabled(false);
3827     m_findActivated = false;
3828     m_findString.clear();
3829     statusBar()->showMessage(i18n("Find stopped"), 3000);
3830     if (m_activeTimeline) m_activeTimeline->projectView()->clearSearchStrings();
3831     m_projectSearch->setEnabled(true);
3832     removeEventFilter(this);
3833 }
3834
3835 void MainWindow::slotClipInTimeline(const QString &clipId)
3836 {
3837     if (m_activeTimeline && m_activeDocument) {
3838         QList<ItemInfo> matching = m_activeTimeline->projectView()->findId(clipId);
3839
3840         QMenu *inTimelineMenu = static_cast<QMenu*>(factory()->container("clip_in_timeline", this));
3841         inTimelineMenu->clear();
3842
3843         QList <QAction *> actionList;
3844
3845         for (int i = 0; i < matching.count(); ++i) {
3846             QString track = QString::number(matching.at(i).track);
3847             QString start = m_activeDocument->timecode().getTimecode(matching.at(i).startPos);
3848             int j = 0;
3849             QAction *a = new QAction(track + ": " + start, this);
3850             a->setData(QStringList() << track << start);
3851             connect(a, SIGNAL(triggered()), this, SLOT(slotSelectClipInTimeline()));
3852             while (j < actionList.count()) {
3853                 if (actionList.at(j)->text() > a->text()) break;
3854                 j++;
3855             }
3856             actionList.insert(j, a);
3857         }
3858         inTimelineMenu->addActions(actionList);
3859
3860         if (matching.empty()) {
3861             inTimelineMenu->setEnabled(false);
3862         } else {
3863             inTimelineMenu->setEnabled(true);
3864         }
3865     }
3866 }
3867
3868 void MainWindow::slotClipInProjectTree()
3869 {
3870     if (m_activeTimeline) {
3871         QStringList clipIds;
3872         if (m_mainClip) {
3873             clipIds << m_mainClip->clipProducer();
3874         } else {
3875             clipIds = m_activeTimeline->projectView()->selectedClips();
3876         }
3877         if (clipIds.isEmpty()) {
3878             return;
3879         }
3880         m_projectListDock->raise();
3881         m_projectList->selectItemById(clipIds.at(0));
3882         if (m_projectMonitor->isActive()) {
3883             slotSwitchMonitors();
3884         }
3885     }
3886 }
3887
3888 /*void MainWindow::slotClipToProjectTree()
3889 {
3890     if (m_activeTimeline) {
3891     const QList<ClipItem *> clips =  m_activeTimeline->projectView()->selectedClipItems();
3892         if (clips.isEmpty()) return;
3893         for (int i = 0; i < clips.count(); ++i) {
3894         m_projectList->slotAddXmlClip(clips.at(i)->itemXml());
3895         }
3896         //m_projectList->selectItemById(clipIds.at(i));
3897     }
3898 }*/
3899
3900 void MainWindow::slotSelectClipInTimeline()
3901 {
3902     if (m_activeTimeline) {
3903         QAction *action = qobject_cast<QAction *>(sender());
3904         QStringList data = action->data().toStringList();
3905         m_activeTimeline->projectView()->selectFound(data.at(0), data.at(1));
3906     }
3907 }
3908
3909 void MainWindow::keyPressEvent(QKeyEvent *ke)
3910 {
3911     if (m_findActivated) {
3912         if (ke->key() == Qt::Key_Backspace) {
3913             m_findString = m_findString.left(m_findString.length() - 1);
3914
3915             if (!m_findString.isEmpty()) {
3916                 findAhead();
3917             } else {
3918                 findTimeout();
3919             }
3920
3921             m_findTimer.start(4000);
3922             ke->accept();
3923             return;
3924         } else if (ke->key() == Qt::Key_Escape) {
3925             findTimeout();
3926             ke->accept();
3927             return;
3928         } else if (ke->key() == Qt::Key_Space || !ke->text().trimmed().isEmpty()) {
3929             m_findString += ke->text();
3930
3931             findAhead();
3932
3933             m_findTimer.start(4000);
3934             ke->accept();
3935             return;
3936         }
3937     } else {
3938         KXmlGuiWindow::keyPressEvent(ke);
3939     }
3940 }
3941
3942
3943 /** Gets called when the window gets hidden */
3944 void MainWindow::hideEvent(QHideEvent */*event*/)
3945 {
3946     if (isMinimized() && m_monitorManager)
3947         m_monitorManager->stopActiveMonitor();
3948 }
3949
3950 bool MainWindow::eventFilter(QObject *obj, QEvent *event)
3951 {
3952     if (m_findActivated) {
3953         if (event->type() == QEvent::ShortcutOverride) {
3954             QKeyEvent* ke = (QKeyEvent*) event;
3955             if (ke->text().trimmed().isEmpty()) return false;
3956             ke->accept();
3957             return true;
3958         } else {
3959             return false;
3960         }
3961     } else {
3962         // pass the event on to the parent class
3963         return QMainWindow::eventFilter(obj, event);
3964     }
3965 }
3966
3967
3968 void MainWindow::slotSaveZone(Render *render, const QPoint &zone, DocClipBase *baseClip, KUrl path)
3969 {
3970     KDialog *dialog = new KDialog(this);
3971     dialog->setCaption("Save clip zone");
3972     dialog->setButtons(KDialog::Ok | KDialog::Cancel);
3973
3974     QWidget *widget = new QWidget(dialog);
3975     dialog->setMainWidget(widget);
3976
3977     QVBoxLayout *vbox = new QVBoxLayout(widget);
3978     QLabel *label1 = new QLabel(i18n("Save clip zone as:"), this);
3979     if (path.isEmpty()) {
3980         QString tmppath = m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash);
3981         if (baseClip == NULL) {
3982             tmppath.append("untitled.mlt");
3983         } else {
3984             tmppath.append((baseClip->name().isEmpty() ? baseClip->fileURL().fileName() : baseClip->name()) + '-' + QString::number(zone.x()).rightJustified(4, '0') + ".mlt");
3985         }
3986         path = KUrl(tmppath);
3987     }
3988     KUrlRequester *url = new KUrlRequester(path, this);
3989     url->setFilter("video/mlt-playlist");
3990     QLabel *label2 = new QLabel(i18n("Description:"), this);
3991     KLineEdit *edit = new KLineEdit(this);
3992     vbox->addWidget(label1);
3993     vbox->addWidget(url);
3994     vbox->addWidget(label2);
3995     vbox->addWidget(edit);
3996     if (dialog->exec() == QDialog::Accepted) {
3997         if (QFile::exists(url->url().path())) {
3998             if (KMessageBox::questionYesNo(this, i18n("File %1 already exists.\nDo you want to overwrite it?", url->url().path())) == KMessageBox::No) {
3999                 slotSaveZone(render, zone, baseClip, url->url());
4000                 delete dialog;
4001                 return;
4002             }
4003         }
4004         if (baseClip && !baseClip->fileURL().isEmpty()) {
4005             // create zone from clip url, so that we don't have problems with proxy clips
4006             QProcess p;
4007 #if QT_VERSION >= 0x040600
4008             QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
4009             env.remove("MLT_PROFILE");
4010             p.setProcessEnvironment(env);
4011 #else
4012             QStringList env = QProcess::systemEnvironment();
4013             env << "MLT_PROFILE='\0'";
4014             p.setEnvironment(env);
4015 #endif
4016             p.start(KdenliveSettings::rendererpath(), QStringList() << baseClip->fileURL().path() << "in=" + QString::number(zone.x()) << "out=" + QString::number(zone.y()) << "-consumer" << "xml:" + url->url().path());
4017             if (!p.waitForStarted(3000)) {
4018                 KMessageBox::sorry(this, i18n("Cannot start MLT's renderer:\n%1", KdenliveSettings::rendererpath()));
4019             }
4020             else if (!p.waitForFinished(5000)) {
4021                 KMessageBox::sorry(this, i18n("Timeout while creating xml output"));
4022             }
4023         }
4024         else render->saveZone(url->url(), edit->text(), zone);
4025     }
4026     delete dialog;
4027
4028 }
4029
4030 void MainWindow::slotSetInPoint()
4031 {
4032     if (m_clipMonitor->isActive()) {
4033         m_clipMonitor->slotSetZoneStart();
4034     } else {
4035         m_projectMonitor->slotSetZoneStart();
4036     }
4037 }
4038
4039 void MainWindow::slotSetOutPoint()
4040 {
4041     if (m_clipMonitor->isActive()) {
4042         m_clipMonitor->slotSetZoneEnd();
4043     } else {
4044         m_projectMonitor->slotSetZoneEnd();
4045     }
4046 }
4047
4048 void MainWindow::slotResizeItemStart()
4049 {
4050     if (m_activeTimeline)
4051         m_activeTimeline->projectView()->setInPoint();
4052 }
4053
4054 void MainWindow::slotResizeItemEnd()
4055 {
4056     if (m_activeTimeline)
4057         m_activeTimeline->projectView()->setOutPoint();
4058 }
4059
4060 int MainWindow::getNewStuff(const QString &configFile)
4061 {
4062     KNS3::Entry::List entries;
4063 #if KDE_IS_VERSION(4,3,80)
4064     QPointer<KNS3::DownloadDialog> dialog = new KNS3::DownloadDialog(configFile);
4065     if (dialog->exec()) entries = dialog->changedEntries();
4066     foreach(const KNS3::Entry & entry, entries) {
4067         if (entry.status() == KNS3::Entry::Installed)
4068             kDebug() << "// Installed files: " << entry.installedFiles();
4069     }
4070     delete dialog;
4071 #else
4072     KNS::Engine engine(0);
4073     if (engine.init(configFile))
4074         entries = engine.downloadDialogModal(this);
4075     foreach(KNS::Entry * entry, entries) {
4076         if (entry->status() == KNS::Entry::Installed)
4077             kDebug() << "// Installed files: " << entry->installedFiles();
4078     }
4079 #endif
4080     return entries.size();
4081 }
4082
4083 void MainWindow::slotGetNewTitleStuff()
4084 {
4085     if (getNewStuff("kdenlive_titles.knsrc") > 0)
4086         TitleWidget::refreshTitleTemplates();
4087 }
4088
4089 void MainWindow::slotGetNewLumaStuff()
4090 {
4091     if (getNewStuff("kdenlive_wipes.knsrc") > 0) {
4092         initEffects::refreshLumas();
4093         m_activeTimeline->projectView()->reloadTransitionLumas();
4094     }
4095 }
4096
4097 void MainWindow::slotGetNewRenderStuff()
4098 {
4099     if (getNewStuff("kdenlive_renderprofiles.knsrc") > 0)
4100         if (m_renderWidget)
4101             m_renderWidget->reloadProfiles();
4102 }
4103
4104 void MainWindow::slotGetNewMltProfileStuff()
4105 {
4106     if (getNewStuff("kdenlive_projectprofiles.knsrc") > 0) {
4107         // update the list of profiles in settings dialog
4108         KdenliveSettingsDialog* d = static_cast <KdenliveSettingsDialog*>(KConfigDialog::exists("settings"));
4109         if (d)
4110             d->checkProfile();
4111     }
4112 }
4113
4114 void MainWindow::slotAutoTransition()
4115 {
4116     if (m_activeTimeline)
4117         m_activeTimeline->projectView()->autoTransition();
4118 }
4119
4120 void MainWindow::slotSplitAudio()
4121 {
4122     if (m_activeTimeline)
4123         m_activeTimeline->projectView()->splitAudio();
4124 }
4125
4126 void MainWindow::slotSetAudioAlignReference()
4127 {
4128     if (m_activeTimeline) {
4129         m_activeTimeline->projectView()->setAudioAlignReference();
4130     }
4131 }
4132
4133 void MainWindow::slotAlignAudio()
4134 {
4135     if (m_activeTimeline) {
4136         m_activeTimeline->projectView()->alignAudio();
4137     }
4138 }
4139
4140 void MainWindow::slotUpdateClipType(QAction *action)
4141 {
4142     if (m_activeTimeline) {
4143         if (action->data().toString() == "clip_audio_only") m_activeTimeline->projectView()->setAudioOnly();
4144         else if (action->data().toString() == "clip_video_only") m_activeTimeline->projectView()->setVideoOnly();
4145         else m_activeTimeline->projectView()->setAudioAndVideo();
4146     }
4147 }
4148
4149 void MainWindow::slotDvdWizard(const QString &url)
4150 {
4151     // We must stop the monitors since we create a new on in the dvd wizard
4152     m_monitorManager->activateMonitor(Kdenlive::DvdMonitor);
4153     QPointer<DvdWizard> w = new DvdWizard(m_monitorManager, url, this);
4154     w->exec();
4155     delete w;
4156     m_monitorManager->activateMonitor(Kdenlive::ClipMonitor);
4157 }
4158
4159 void MainWindow::slotShowTimeline(bool show)
4160 {
4161     if (show == false) {
4162         m_timelineState = saveState();
4163         centralWidget()->setHidden(true);
4164     } else {
4165         centralWidget()->setHidden(false);
4166         restoreState(m_timelineState);
4167     }
4168 }
4169
4170 void MainWindow::slotMaximizeCurrent(bool)
4171 {
4172     //TODO: is there a way to maximize current widget?
4173
4174     m_timelineState = saveState();
4175     QWidget *par = focusWidget()->parentWidget();
4176     while (par->parentWidget() && par->parentWidget() != this)
4177         par = par->parentWidget();
4178     kDebug() << "CURRENT WIDGET: " << par->objectName();
4179 }
4180
4181 void MainWindow::loadClipActions()
4182 {
4183     QMenu* actionMenu= static_cast<QMenu*>(factory()->container("clip_actions", this));
4184     if (actionMenu){
4185         actionMenu->clear();
4186         Mlt::Profile profile;
4187         Mlt::Filter *filter = Mlt::Factory::filter(profile,(char*)"videostab");
4188         if (filter) {
4189             if (!filter->is_valid()) {
4190                 delete filter;
4191             }
4192             else {
4193                 delete filter;
4194                 QAction *action=actionMenu->addAction(i18n("Stabilize (vstab)"));
4195                 action->setData("videostab");
4196                 connect(action,SIGNAL(triggered()), this, SLOT(slotStartClipAction()));
4197             }
4198         }
4199         filter = Mlt::Factory::filter(profile,(char*)"videostab2");
4200         if (filter) {
4201             if (!filter->is_valid()) {
4202                 delete filter;
4203             }
4204             else {
4205                 delete filter;
4206                 QAction *action=actionMenu->addAction(i18n("Stabilize (transcode)"));
4207                 action->setData("videostab2");
4208                 connect(action,SIGNAL(triggered()), this, SLOT(slotStartClipAction()));
4209             }
4210         }
4211         filter = Mlt::Factory::filter(profile,(char*)"motion_est");
4212         if (filter) {
4213             if (!filter->is_valid()) {
4214                 delete filter;
4215             }
4216             else {
4217                 delete filter;
4218                 QAction *action=actionMenu->addAction(i18n("Automatic scene split"));
4219                 action->setData("motion_est");
4220                 connect(action,SIGNAL(triggered()), this, SLOT(slotStartClipAction()));
4221             }
4222         }
4223         if (KdenliveSettings::producerslist().contains("framebuffer")) {
4224             QAction *action=actionMenu->addAction(i18n("Reverse clip"));
4225             action->setData("framebuffer");
4226             connect(action,SIGNAL(triggered()), this, SLOT(slotStartClipAction()));
4227         }
4228     }
4229
4230 }
4231
4232 void MainWindow::loadTranscoders()
4233 {
4234     QMenu *transMenu = static_cast<QMenu*>(factory()->container("transcoders", this));
4235     transMenu->clear();
4236
4237     QMenu *extractAudioMenu = static_cast<QMenu*>(factory()->container("extract_audio", this));
4238     extractAudioMenu->clear();
4239
4240     KSharedConfigPtr config = KSharedConfig::openConfig("kdenlivetranscodingrc", KConfig::CascadeConfig);
4241     KConfigGroup transConfig(config, "Transcoding");
4242     // read the entries
4243     QMap< QString, QString > profiles = transConfig.entryMap();
4244     QMapIterator<QString, QString> i(profiles);
4245     while (i.hasNext()) {
4246         i.next();
4247         QStringList data = i.value().split(';');
4248         QAction *a;
4249         // separate audio transcoding in a separate menu
4250         if (data.count() > 2 && data.at(2) == "audio") {
4251             a = extractAudioMenu->addAction(i.key());
4252         }
4253         else {
4254             a = transMenu->addAction(i.key());
4255         }
4256         a->setData(data);
4257         if (data.count() > 1) a->setToolTip(data.at(1));
4258         connect(a, SIGNAL(triggered()), this, SLOT(slotTranscode()));
4259     }
4260 }
4261
4262 void MainWindow::slotStartClipAction()
4263 {
4264     QString condition,filtername;
4265     QStringList ids;
4266
4267     // Stablize selected clips
4268     QAction *action = qobject_cast<QAction *>(sender());
4269     if (action){
4270         filtername=action->data().toString();
4271     }
4272     m_projectList->startClipFilterJob(filtername, condition);
4273 }
4274
4275 void MainWindow::slotTranscode(const KUrl::List &urls)
4276 {
4277     QString params;
4278     QString desc;
4279     QString condition;
4280     if (urls.isEmpty()) {
4281         QAction *action = qobject_cast<QAction *>(sender());
4282         QStringList data = action->data().toStringList();
4283         params = data.at(0);
4284         if (data.count() > 1)
4285             desc = data.at(1);
4286         if (data.count() > 3)
4287             condition = data.at(3);
4288         m_projectList->slotTranscodeClipJob(condition, params, desc);
4289         return;
4290     }
4291     if (urls.isEmpty()) {
4292         m_messageLabel->setMessage(i18n("No clip to transcode"), ErrorMessage);
4293         return;
4294     }
4295     ClipTranscode *d = new ClipTranscode(urls, params, QStringList(), desc);
4296     connect(d, SIGNAL(addClip(KUrl)), this, SLOT(slotAddProjectClip(KUrl)));
4297     d->show();
4298 }
4299
4300 void MainWindow::slotTranscodeClip()
4301 {
4302     KUrl::List urls = KFileDialog::getOpenUrls(KUrl("kfiledialog:///projectfolder"));
4303     if (urls.isEmpty()) return;
4304     slotTranscode(urls);
4305 }
4306
4307 void MainWindow::slotSetDocumentRenderProfile(const QMap <QString, QString> &props)
4308 {
4309     if (m_activeDocument == NULL) return;
4310     QMapIterator<QString, QString> i(props);
4311     while (i.hasNext()) {
4312         i.next();
4313         m_activeDocument->setDocumentProperty(i.key(), i.value());
4314     }
4315     m_activeDocument->setModified(true);
4316 }
4317
4318
4319 void MainWindow::slotPrepareRendering(bool scriptExport, bool zoneOnly, const QString &chapterFile)
4320 {
4321     if (m_activeDocument == NULL || m_renderWidget == NULL) return;
4322     QString scriptPath;
4323     QString playlistPath;
4324     if (scriptExport) {
4325         //QString scriptsFolder = m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash) + "scripts/";
4326         QString path = m_renderWidget->getFreeScriptName(m_activeDocument->url());
4327         QPointer<KUrlRequesterDialog> getUrl = new KUrlRequesterDialog(path, i18n("Create Render Script"), this);
4328         getUrl->fileDialog()->setMode(KFile::File);
4329         getUrl->fileDialog()->setOperationMode(KFileDialog::Saving);
4330         if (getUrl->exec() == QDialog::Rejected) {
4331             delete getUrl;
4332             return;
4333         }
4334         scriptPath = getUrl->selectedUrl().path();
4335         delete getUrl;
4336         QFile f(scriptPath);
4337         if (f.exists()) {
4338             if (KMessageBox::warningYesNo(this, i18n("Script file already exists. Do you want to overwrite it?")) != KMessageBox::Yes)
4339                 return;
4340         }
4341         playlistPath = scriptPath + ".mlt";
4342     } else {
4343         KTemporaryFile temp;
4344         temp.setAutoRemove(false);
4345         temp.setSuffix(".mlt");
4346         temp.open();
4347         playlistPath = temp.fileName();
4348     }
4349     QString playlistContent = m_projectMonitor->sceneList();
4350     if (!chapterFile.isEmpty()) {
4351         int in = 0;
4352         int out;
4353         if (!zoneOnly) out = (int) GenTime(m_activeDocument->projectDuration()).frames(m_activeDocument->fps());
4354         else {
4355             in = m_activeTimeline->inPoint();
4356             out = m_activeTimeline->outPoint();
4357         }
4358         QDomDocument doc;
4359         QDomElement chapters = doc.createElement("chapters");
4360         chapters.setAttribute("fps", m_activeDocument->fps());
4361         doc.appendChild(chapters);
4362
4363         QDomElement guidesxml = m_activeDocument->guidesXml();
4364         QDomNodeList nodes = guidesxml.elementsByTagName("guide");
4365         for (int i = 0; i < nodes.count(); ++i) {
4366             QDomElement e = nodes.item(i).toElement();
4367             if (!e.isNull()) {
4368                 QString comment = e.attribute("comment");
4369                 int time = (int) GenTime(e.attribute("time").toDouble()).frames(m_activeDocument->fps());
4370                 if (time >= in && time < out) {
4371                     if (zoneOnly) time = time - in;
4372                     QDomElement chapter = doc.createElement("chapter");
4373                     chapters.appendChild(chapter);
4374                     chapter.setAttribute("title", comment);
4375                     chapter.setAttribute("time", time);
4376                 }
4377             }
4378         }
4379         if (chapters.childNodes().count() > 0) {
4380             if (m_activeTimeline->projectView()->hasGuide(out, 0) == -1) {
4381                 // Always insert a guide in pos 0
4382                 QDomElement chapter = doc.createElement("chapter");
4383                 chapters.insertBefore(chapter, QDomNode());
4384                 chapter.setAttribute("title", i18nc("the first in a list of chapters", "Start"));
4385                 chapter.setAttribute("time", "0");
4386             }
4387             // save chapters file
4388             QFile file(chapterFile);
4389             if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
4390                 kWarning() << "//////  ERROR writing DVD CHAPTER file: " << chapterFile;
4391             } else {
4392                 file.write(doc.toString().toUtf8());
4393                 if (file.error() != QFile::NoError) {
4394                     kWarning() << "//////  ERROR writing DVD CHAPTER file: " << chapterFile;
4395                 }
4396                 file.close();
4397             }
4398         }
4399     }
4400     bool exportAudio;
4401     if (m_renderWidget->automaticAudioExport()) {
4402         exportAudio = m_activeTimeline->checkProjectAudio();
4403     } else exportAudio = m_renderWidget->selectedAudioExport();
4404
4405     // Set playlist audio volume to 100%
4406     QDomDocument doc;
4407     doc.setContent(playlistContent);
4408     QDomElement tractor = doc.documentElement().firstChildElement("tractor");
4409     if (!tractor.isNull()) {
4410         QDomNodeList props = tractor.elementsByTagName("property");
4411         for (int i = 0; i < props.count(); ++i) {
4412             if (props.at(i).toElement().attribute("name") == "meta.volume") {
4413                 props.at(i).firstChild().setNodeValue("1");
4414                 break;
4415             }
4416         }
4417     }
4418
4419     // Do we want proxy rendering
4420     if (m_projectList->useProxy() && !m_renderWidget->proxyRendering()) {
4421         QString root = doc.documentElement().attribute("root");
4422
4423         // replace proxy clips with originals
4424         QMap <QString, QString> proxies = m_projectList->getProxies();
4425
4426         QDomNodeList producers = doc.elementsByTagName("producer");
4427         QString producerResource;
4428         QString suffix;
4429         for (uint n = 0; n < producers.length(); n++) {
4430             QDomElement e = producers.item(n).toElement();
4431             producerResource = EffectsList::property(e, "resource");
4432             if (producerResource.isEmpty()) continue;
4433             if (!producerResource.startsWith('/')) {
4434                 producerResource.prepend(root + '/');
4435             }
4436             if (producerResource.contains('?')) {
4437                 // slowmotion producer
4438                 suffix = '?' + producerResource.section('?', 1);
4439                 producerResource = producerResource.section('?', 0, 0);
4440             }
4441             else suffix.clear();
4442             if (!producerResource.isEmpty()) {
4443                 if (proxies.contains(producerResource)) {
4444                     EffectsList::setProperty(e, "resource", proxies.value(producerResource) + suffix);
4445                     // We need to delete the "aspect_ratio" property because proxy clips
4446                     // sometimes have different ratio than original clips
4447                     EffectsList::removeProperty(e, "aspect_ratio");
4448                     EffectsList::removeMetaProperties(e);
4449                 }
4450             }
4451         }
4452
4453         /*QMapIterator<QString, QString> i(proxies);
4454         while (i.hasNext()) {
4455             i.next();
4456             // Replace all keys with their values (proxy path with original path)
4457             QString key = i.key();
4458             playlistContent.replace(key, i.value());
4459             if (!root.isEmpty() && key.startsWith(root)) {
4460                 // in case the resource path in MLT playlist is relative
4461                 key.remove(0, root.count() + 1);
4462                 playlistContent.replace(key, i.value());
4463             }
4464         }*/
4465     }
4466     playlistContent = doc.toString();
4467
4468     // Do save scenelist
4469     QFile file(playlistPath);
4470     if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
4471         m_messageLabel->setMessage(i18n("Cannot write to file %1", playlistPath), ErrorMessage);
4472         return;
4473     }
4474     file.write(playlistContent.toUtf8());
4475     if (file.error() != QFile::NoError) {
4476         m_messageLabel->setMessage(i18n("Cannot write to file %1", playlistPath), ErrorMessage);
4477         file.close();
4478         return;
4479     }
4480     file.close();
4481     m_renderWidget->slotExport(scriptExport, m_activeTimeline->inPoint(), m_activeTimeline->outPoint(), m_activeDocument->metadata(), playlistPath, scriptPath, exportAudio);
4482 }
4483
4484 void MainWindow::slotUpdateTimecodeFormat(int ix)
4485 {
4486     KdenliveSettings::setFrametimecode(ix == 1);
4487     m_clipMonitor->updateTimecodeFormat();
4488     m_projectMonitor->updateTimecodeFormat();
4489     m_transitionConfig->updateTimecodeFormat();
4490     m_effectStack->updateTimecodeFormat();
4491     //m_activeTimeline->projectView()->clearSelection();
4492     m_activeTimeline->updateRuler();
4493     slotUpdateMousePosition(m_activeTimeline->projectView()->getMousePos());
4494 }
4495
4496 void MainWindow::slotRemoveFocus()
4497 {
4498     statusBar()->setFocus();
4499     statusBar()->clearFocus();
4500 }
4501
4502 void MainWindow::slotRevert()
4503 {
4504     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;
4505     KUrl url = m_activeDocument->url();
4506     if (closeCurrentDocument(false))
4507         doOpenFile(url, NULL);
4508 }
4509
4510
4511 void MainWindow::slotShutdown()
4512 {
4513     if (m_activeDocument) m_activeDocument->setModified(false);
4514     // Call shutdown
4515     QDBusConnectionInterface* interface = QDBusConnection::sessionBus().interface();
4516     if (interface && interface->isServiceRegistered("org.kde.ksmserver")) {
4517         QDBusInterface smserver("org.kde.ksmserver", "/KSMServer", "org.kde.KSMServerInterface");
4518         smserver.call("logout", 1, 2, 2);
4519     } else if (interface && interface->isServiceRegistered("org.gnome.SessionManager")) {
4520         QDBusInterface smserver("org.gnome.SessionManager", "/org/gnome/SessionManager", "org.gnome.SessionManager");
4521         smserver.call("Shutdown");
4522     }
4523 }
4524
4525 void MainWindow::slotUpdateTrackInfo()
4526 {
4527     if (m_activeDocument)
4528         m_transitionConfig->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode(), m_activeDocument->tracksList());
4529 }
4530
4531 void MainWindow::slotChangePalette(QAction *action, const QString &themename)
4532 {
4533     // Load the theme file
4534     QString theme;
4535     if (action == NULL) theme = themename;
4536     else theme = action->data().toString();
4537     KdenliveSettings::setColortheme(theme);
4538     // Make palette for all widgets.
4539     QPalette plt = kapp->palette();
4540     if (theme.isEmpty()) {
4541         plt = QApplication::desktop()->palette();
4542     } else {
4543         KSharedConfigPtr config = KSharedConfig::openConfig(theme);
4544
4545 #if KDE_IS_VERSION(4,6,3)
4546         plt = KGlobalSettings::createNewApplicationPalette(config);
4547 #else
4548         // Since there was a bug in createApplicationPalette in KDE < 4.6.3 we need
4549         // to do the palette loading stuff ourselves. (https://bugs.kde.org/show_bug.cgi?id=263497)
4550         QPalette::ColorGroup states[3] = { QPalette::Active, QPalette::Inactive,
4551                                            QPalette::Disabled };
4552         // TT thinks tooltips shouldn't use active, so we use our active colors for all states
4553         KColorScheme schemeTooltip(QPalette::Active, KColorScheme::Tooltip, config);
4554
4555         for ( int i = 0; i < 3 ; ++i ) {
4556             QPalette::ColorGroup state = states[i];
4557             KColorScheme schemeView(state, KColorScheme::View, config);
4558             KColorScheme schemeWindow(state, KColorScheme::Window, config);
4559             KColorScheme schemeButton(state, KColorScheme::Button, config);
4560             KColorScheme schemeSelection(state, KColorScheme::Selection, config);
4561
4562             plt.setBrush( state, QPalette::WindowText, schemeWindow.foreground() );
4563             plt.setBrush( state, QPalette::Window, schemeWindow.background() );
4564             plt.setBrush( state, QPalette::Base, schemeView.background() );
4565             plt.setBrush( state, QPalette::Text, schemeView.foreground() );
4566             plt.setBrush( state, QPalette::Button, schemeButton.background() );
4567             plt.setBrush( state, QPalette::ButtonText, schemeButton.foreground() );
4568             plt.setBrush( state, QPalette::Highlight, schemeSelection.background() );
4569             plt.setBrush( state, QPalette::HighlightedText, schemeSelection.foreground() );
4570             plt.setBrush( state, QPalette::ToolTipBase, schemeTooltip.background() );
4571             plt.setBrush( state, QPalette::ToolTipText, schemeTooltip.foreground() );
4572
4573             plt.setColor( state, QPalette::Light, schemeWindow.shade( KColorScheme::LightShade ) );
4574             plt.setColor( state, QPalette::Midlight, schemeWindow.shade( KColorScheme::MidlightShade ) );
4575             plt.setColor( state, QPalette::Mid, schemeWindow.shade( KColorScheme::MidShade ) );
4576             plt.setColor( state, QPalette::Dark, schemeWindow.shade( KColorScheme::DarkShade ) );
4577             plt.setColor( state, QPalette::Shadow, schemeWindow.shade( KColorScheme::ShadowShade ) );
4578
4579             plt.setBrush( state, QPalette::AlternateBase, schemeView.background( KColorScheme::AlternateBackground) );
4580             plt.setBrush( state, QPalette::Link, schemeView.foreground( KColorScheme::LinkText ) );
4581             plt.setBrush( state, QPalette::LinkVisited, schemeView.foreground( KColorScheme::VisitedText ) );
4582         }
4583 #endif
4584     }
4585
4586     kapp->setPalette(plt);
4587     slotChangePalette();
4588     const QObjectList children = statusBar()->children();
4589
4590     foreach(QObject * child, children) {
4591         if (child->isWidgetType())
4592             ((QWidget*)child)->setPalette(plt);
4593         const QObjectList subchildren = child->children();
4594         foreach(QObject * subchild, subchildren) {
4595             if (subchild->isWidgetType())
4596                 ((QWidget*)subchild)->setPalette(plt);
4597         }
4598     }
4599 }
4600
4601
4602 QPixmap MainWindow::createSchemePreviewIcon(const KSharedConfigPtr &config)
4603 {
4604     // code taken from kdebase/workspace/kcontrol/colors/colorscm.cpp
4605     const uchar bits1[] = { 0xff, 0xff, 0xff, 0x2c, 0x16, 0x0b };
4606     const uchar bits2[] = { 0x68, 0x34, 0x1a, 0xff, 0xff, 0xff };
4607     const QSize bitsSize(24, 2);
4608     const QBitmap b1 = QBitmap::fromData(bitsSize, bits1);
4609     const QBitmap b2 = QBitmap::fromData(bitsSize, bits2);
4610
4611     QPixmap pixmap(23, 16);
4612     pixmap.fill(Qt::black); // ### use some color other than black for borders?
4613
4614     KConfigGroup group(config, "WM");
4615     QPainter p(&pixmap);
4616     KColorScheme windowScheme(QPalette::Active, KColorScheme::Window, config);
4617     p.fillRect(1,  1, 7, 7, windowScheme.background());
4618     p.fillRect(2,  2, 5, 2, QBrush(windowScheme.foreground().color(), b1));
4619
4620     KColorScheme buttonScheme(QPalette::Active, KColorScheme::Button, config);
4621     p.fillRect(8,  1, 7, 7, buttonScheme.background());
4622     p.fillRect(9,  2, 5, 2, QBrush(buttonScheme.foreground().color(), b1));
4623
4624     p.fillRect(15,  1, 7, 7, group.readEntry("activeBackground", QColor(96, 148, 207)));
4625     p.fillRect(16,  2, 5, 2, QBrush(group.readEntry("activeForeground", QColor(255, 255, 255)), b1));
4626
4627     KColorScheme viewScheme(QPalette::Active, KColorScheme::View, config);
4628     p.fillRect(1,  8, 7, 7, viewScheme.background());
4629     p.fillRect(2, 12, 5, 2, QBrush(viewScheme.foreground().color(), b2));
4630
4631     KColorScheme selectionScheme(QPalette::Active, KColorScheme::Selection, config);
4632     p.fillRect(8,  8, 7, 7, selectionScheme.background());
4633     p.fillRect(9, 12, 5, 2, QBrush(selectionScheme.foreground().color(), b2));
4634
4635     p.fillRect(15,  8, 7, 7, group.readEntry("inactiveBackground", QColor(224, 223, 222)));
4636     p.fillRect(16, 12, 5, 2, QBrush(group.readEntry("inactiveForeground", QColor(20, 19, 18)), b2));
4637
4638     p.end();
4639     return pixmap;
4640 }
4641
4642 void MainWindow::slotSwitchMonitors()
4643 {
4644     m_monitorManager->slotSwitchMonitors(!m_clipMonitor->isActive());
4645     if (m_projectMonitor->isActive()) m_activeTimeline->projectView()->setFocus();
4646     else m_projectList->focusTree();
4647 }
4648
4649 void MainWindow::slotInsertZoneToTree()
4650 {
4651     if (!m_clipMonitor->isActive() || m_clipMonitor->activeClip() == NULL) return;
4652     QStringList info = m_clipMonitor->getZoneInfo();
4653     m_projectList->slotAddClipCut(info.at(0), info.at(1).toInt(), info.at(2).toInt());
4654 }
4655
4656 void MainWindow::slotInsertZoneToTimeline()
4657 {
4658     if (m_activeTimeline == NULL || m_clipMonitor->activeClip() == NULL) return;
4659     QStringList info = m_clipMonitor->getZoneInfo();
4660     m_activeTimeline->projectView()->insertClipCut(m_clipMonitor->activeClip(), info.at(1).toInt(), info.at(2).toInt());
4661 }
4662
4663
4664 void MainWindow::slotDeleteProjectClips(const QStringList &ids, const QMap<QString, QString> &folderids)
4665 {
4666     if (m_activeDocument && m_activeTimeline) {
4667         if (!ids.isEmpty()) {
4668             for (int i = 0; i < ids.size(); ++i) {
4669                 m_activeTimeline->slotDeleteClip(ids.at(i));
4670             }
4671             m_activeDocument->clipManager()->slotDeleteClips(ids);
4672         }
4673         if (!folderids.isEmpty()) m_projectList->deleteProjectFolder(folderids);
4674         m_activeDocument->setModified(true);
4675     }
4676 }
4677
4678 void MainWindow::slotShowTitleBars(bool show)
4679 {
4680     QList <QDockWidget *> docks = findChildren<QDockWidget *>();
4681     for (int i = 0; i < docks.count(); ++i) {
4682         QDockWidget* dock = docks.at(i);
4683         if (show) {
4684             dock->setTitleBarWidget(0);
4685         } else {
4686             if (!dock->isFloating()) {
4687                 dock->setTitleBarWidget(new QWidget);
4688             }
4689         }
4690     }
4691     KdenliveSettings::setShowtitlebars(show);
4692 }
4693
4694 void MainWindow::slotSwitchTitles()
4695 {
4696     slotShowTitleBars(!KdenliveSettings::showtitlebars());
4697 }
4698
4699 QString MainWindow::getMimeType(bool open)
4700 {
4701     QString mimetype = "application/x-kdenlive";
4702     KMimeType::Ptr mime = KMimeType::mimeType(mimetype);
4703     if (!mime) {
4704         mimetype = "*.kdenlive";
4705         if (open) mimetype.append(" *.tar.gz");
4706     }
4707     else if (open) mimetype.append(" application/x-compressed-tar");
4708     return mimetype;
4709 }
4710
4711 void MainWindow::slotMonitorRequestRenderFrame(bool request)
4712 {
4713     if (request) {
4714         m_projectMonitor->render->sendFrameForAnalysis = true;
4715         return;
4716     } else {
4717         for (int i = 0; i < m_gfxScopesList.count(); ++i) {
4718             if (m_gfxScopesList.at(i)->isVisible() && tabifiedDockWidgets(m_gfxScopesList.at(i)).isEmpty() && static_cast<AbstractGfxScopeWidget *>(m_gfxScopesList.at(i)->widget())->autoRefreshEnabled()) {
4719                 request = true;
4720                 break;
4721             }
4722         }
4723     }
4724 #ifdef DEBUG_MAINW
4725     qDebug() << "Any scope accepting new frames? " << request;
4726 #endif
4727     if (!request) {
4728         m_projectMonitor->render->sendFrameForAnalysis = false;
4729     }
4730 }
4731
4732
4733 void MainWindow::slotOpenStopmotion()
4734 {
4735     if (m_stopmotion == NULL) {
4736         m_stopmotion = new StopmotionWidget(m_monitorManager, m_activeDocument->projectFolder(), m_stopmotion_actions->actions(), this);
4737         connect(m_stopmotion, SIGNAL(addOrUpdateSequence(QString)), m_projectList, SLOT(slotAddOrUpdateSequence(QString)));
4738         //for (int i = 0; i < m_gfxScopesList.count(); ++i) {
4739         // Check if we need the renderer to send a new frame for update
4740         /*if (!m_scopesList.at(i)->widget()->visibleRegion().isEmpty() && !(static_cast<AbstractScopeWidget *>(m_scopesList.at(i)->widget())->autoRefreshEnabled())) request = true;*/
4741         //connect(m_stopmotion, SIGNAL(gotFrame(QImage)), static_cast<AbstractGfxScopeWidget *>(m_gfxScopesList.at(i)->widget()), SLOT(slotRenderZoneUpdated(QImage)));
4742         //static_cast<AbstractScopeWidget *>(m_scopesList.at(i)->widget())->slotMonitorCapture();
4743         //}
4744     }
4745     m_stopmotion->show();
4746 }
4747
4748 void MainWindow::slotDeleteClip(const QString &id)
4749 {
4750     QList <ClipProperties *> list = findChildren<ClipProperties *>();
4751     for (int i = 0; i < list.size(); ++i) {
4752         list.at(i)->disableClipId(id);
4753     }
4754     m_projectList->slotDeleteClip(id);
4755 }
4756
4757 void MainWindow::slotUpdateProxySettings()
4758 {
4759     if (m_renderWidget) m_renderWidget->updateProxyConfig(m_projectList->useProxy());
4760     if (KdenliveSettings::enableproxy())
4761         KStandardDirs::makeDir(m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash) + "proxy/");
4762     m_projectList->updateProxyConfig();
4763 }
4764
4765 void MainWindow::slotInsertNotesTimecode()
4766 {
4767     int frames = m_projectMonitor->render->seekPosition().frames(m_activeDocument->fps());
4768     QString position = m_activeDocument->timecode().getTimecodeFromFrames(frames);
4769     m_notesWidget->insertHtml("<a href=\"" + QString::number(frames) + "\">" + position + "</a> ");
4770 }
4771
4772 void MainWindow::slotArchiveProject()
4773 {
4774     QList <DocClipBase*> list = m_projectList->documentClipList();
4775     QDomDocument doc = m_activeDocument->xmlSceneList(m_projectMonitor->sceneList(), m_projectList->expandedFolders());
4776     ArchiveWidget *d = new ArchiveWidget(m_activeDocument->url().fileName(), doc, list, m_activeTimeline->projectView()->extractTransitionsLumas(), this);
4777     if (d->exec()) {
4778         m_messageLabel->setMessage(i18n("Archiving project"), OperationCompletedMessage);
4779     }
4780 }
4781
4782
4783 void MainWindow::slotOpenBackupDialog(const KUrl &url)
4784 {
4785     KUrl projectFile;
4786     KUrl projectFolder;
4787     QString projectId;
4788     kDebug()<<"// BACKUP URL: "<<url.path();
4789     if (!url.isEmpty()) {
4790         // we could not open the project file, guess where the backups are
4791         projectFolder = KUrl(KdenliveSettings::defaultprojectfolder());
4792         projectFile = url;
4793     }
4794     else {
4795         projectFolder = m_activeDocument->projectFolder();
4796         projectFile = m_activeDocument->url();
4797         projectId = m_activeDocument->getDocumentProperty("documentid");
4798     }
4799
4800     QPointer<BackupWidget> dia = new BackupWidget(projectFile, projectFolder, projectId, this);
4801     if (dia->exec() == QDialog::Accepted) {
4802         QString requestedBackup = dia->selectedFile();
4803         m_activeDocument->backupLastSavedVersion(projectFile.path());
4804         closeCurrentDocument(false);
4805         doOpenFile(KUrl(requestedBackup), NULL);
4806         m_activeDocument->setUrl(projectFile);
4807         m_activeDocument->setModified(true);
4808         setCaption(m_activeDocument->description());
4809     }
4810     delete dia;
4811 }
4812
4813 void MainWindow::slotElapsedTime()
4814 {
4815     kDebug()<<"-----------------------------------------\n"<<"Time elapsed: "<<m_timer.elapsed()<<"\n-------------------------";
4816 }
4817
4818
4819 void MainWindow::slotDownloadResources()
4820 {
4821     QString currentFolder;
4822     if (m_activeDocument) currentFolder = m_activeDocument->projectFolder().path();
4823     else currentFolder = KdenliveSettings::defaultprojectfolder();
4824     ResourceWidget *d = new ResourceWidget(currentFolder);
4825     connect(d, SIGNAL(addClip(KUrl,stringMap)), this, SLOT(slotAddProjectClip(KUrl,stringMap)));
4826     d->show();
4827 }
4828
4829 void MainWindow::slotChangePalette()
4830 {
4831     QPalette plt = QApplication::palette();
4832     if (m_effectStack) m_effectStack->updatePalette();
4833     if (m_projectList) m_projectList->updatePalette();
4834     if (m_effectList) m_effectList->updatePalette();
4835     
4836     if (m_clipMonitor) m_clipMonitor->setPalette(plt);
4837     if (m_projectMonitor) m_projectMonitor->setPalette(plt);
4838     
4839     setStatusBarStyleSheet(plt);
4840     if (m_activeTimeline) {
4841         m_activeTimeline->updatePalette();
4842     }
4843 }
4844
4845 void MainWindow::slotSaveTimelineClip()
4846 {
4847     if (m_activeTimeline && m_projectMonitor->render) {
4848         ClipItem *clip = m_activeTimeline->projectView()->getActiveClipUnderCursor(true);
4849         if (!clip) {
4850             m_messageLabel->setMessage(i18n("Select a clip to save"), InformationMessage);
4851             return;
4852         }
4853         KUrl url = KFileDialog::getSaveUrl(m_activeDocument->projectFolder(), "video/mlt-playlist");
4854         if (!url.isEmpty()) m_projectMonitor->render->saveClip(m_activeDocument->tracksCount() - clip->track(), clip->startPos(), url);
4855     }
4856 }
4857
4858 void MainWindow::slotProcessImportKeyframes(GraphicsRectItem type, const QString& data, int maximum)
4859 {
4860     if (type == AVWidget) {
4861         // This data should be sent to the effect stack
4862         m_effectStack->setKeyframes(data, maximum);
4863     }
4864     else if (type == TransitionWidget) {
4865         // This data should be sent to the transition stack
4866         m_transitionConfig->setKeyframes(data, maximum);
4867     }
4868     else {
4869         // Error
4870     }
4871 }
4872
4873 void MainWindow::slotAlignPlayheadToMousePos()
4874 {
4875     m_monitorManager->activateMonitor(Kdenlive::ProjectMonitor);
4876     m_activeTimeline->projectView()->slotAlignPlayheadToMousePos();
4877 }
4878
4879 void MainWindow::slotSetDeinterlacer(int ix)
4880 {
4881     QString value;
4882     switch (ix) {
4883
4884     case 1:
4885         value = "linearblend";
4886         break;
4887     case 2:
4888         value = "yadif-nospatial";
4889         break;
4890     case 3:
4891         value = "yadif";
4892         break;
4893     default:
4894         value = "onefield";
4895     }
4896     KdenliveSettings::setMltdeinterlacer(value);
4897     m_monitorManager->setConsumerProperty("deinterlace_method", value);
4898 }
4899
4900 void MainWindow::slotSetInterpolation(int ix)
4901 {
4902     QString value;
4903     switch (ix) {
4904     case 1:
4905         value = "bilinear";
4906         break;
4907     case 2:
4908         value = "bicubic";
4909         break;
4910     case 3:
4911         value = "hyper";
4912         break;
4913     default:
4914         value = "nearest";
4915     }
4916     KdenliveSettings::setMltinterpolation(value);
4917     m_monitorManager->setConsumerProperty("rescale", value);
4918 }
4919
4920 #include "mainwindow.moc"
4921
4922 #ifdef DEBUG_MAINW
4923 #undef DEBUG_MAINW
4924 #endif