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