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