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