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