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