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