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