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