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