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