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