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