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