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