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