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