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