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