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