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