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