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