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