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