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