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