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