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