]> git.sesse.net Git - kdenlive/blob - src/mainwindow.cpp
6d86b82c321c9e0c3f41793d76ce794e6a52c487
[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
56 #include <KApplication>
57 #include <KAction>
58 #include <KLocale>
59 #include <KGlobal>
60 #include <KActionCollection>
61 #include <KStandardAction>
62 #include <KFileDialog>
63 #include <KMessageBox>
64 #include <KDebug>
65 #include <KIO/NetAccess>
66 #include <KSaveFile>
67 #include <KRuler>
68 #include <KConfigDialog>
69 #include <KXMLGUIFactory>
70 #include <KStatusBar>
71 #include <kstandarddirs.h>
72 #include <KUrlRequesterDialog>
73 #include <KTemporaryFile>
74 #include <KProcess>
75 #include <KActionMenu>
76 #include <KMenu>
77 #include <locale.h>
78 #include <ktogglefullscreenaction.h>
79 #include <KFileItem>
80 #include <KNotification>
81 #include <KNotifyConfigWidget>
82 #include <knewstuff2/engine.h>
83 #include <knewstuff2/ui/knewstuffaction.h>
84
85 #include <QTextStream>
86 #include <QTimer>
87 #include <QAction>
88 #include <QKeyEvent>
89 #include <QInputDialog>
90
91 #include <stdlib.h>
92
93 static const char version[] = VERSION;
94
95 static const int ID_TIMELINE_POS = 0;
96
97 namespace Mlt
98 {
99 class Producer;
100 };
101
102 EffectsList MainWindow::videoEffects;
103 EffectsList MainWindow::audioEffects;
104 EffectsList MainWindow::customEffects;
105 EffectsList MainWindow::transitions;
106
107 MainWindow::MainWindow(const QString &MltPath, const KUrl & Url, QWidget *parent) :
108         KXmlGuiWindow(parent),
109         m_activeDocument(NULL),
110         m_activeTimeline(NULL),
111         m_renderWidget(NULL),
112 #ifndef NO_JOGSHUTTLE
113         m_jogProcess(NULL),
114 #endif /* NO_JOGSHUTTLE */
115         m_findActivated(false)
116 {
117
118     // Create DBus interface
119     new MainWindowAdaptor(this);
120     QDBusConnection dbus = QDBusConnection::sessionBus();
121     dbus.registerObject("/MainWindow", this);
122
123     setlocale(LC_NUMERIC, "POSIX");
124     setFont(KGlobalSettings::toolBarFont());
125     parseProfiles(MltPath);
126     m_commandStack = new QUndoGroup;
127     m_timelineArea = new KTabWidget(this);
128     m_timelineArea->setTabReorderingEnabled(true);
129     m_timelineArea->setTabBarHidden(true);
130
131     QToolButton *closeTabButton = new QToolButton;
132     connect(closeTabButton, SIGNAL(clicked()), this, SLOT(closeCurrentDocument()));
133     closeTabButton->setIcon(KIcon("tab-close"));
134     closeTabButton->adjustSize();
135     closeTabButton->setToolTip(i18n("Close the current tab"));
136     m_timelineArea->setCornerWidget(closeTabButton);
137     connect(m_timelineArea, SIGNAL(currentChanged(int)), this, SLOT(activateDocument()));
138
139     connect(&m_findTimer, SIGNAL(timeout()), this, SLOT(findTimeout()));
140     m_findTimer.setSingleShot(true);
141
142     // FIXME: the next call returns a newly allocated object, which leaks
143     initEffects::parseEffectFiles();
144     //initEffects::parseCustomEffectsFile();
145
146     m_monitorManager = new MonitorManager();
147
148     m_projectListDock = new QDockWidget(i18n("Project Tree"), this);
149     m_projectListDock->setObjectName("project_tree");
150     m_projectList = new ProjectList(this);
151     m_projectListDock->setWidget(m_projectList);
152     addDockWidget(Qt::TopDockWidgetArea, m_projectListDock);
153
154     m_shortcutRemoveFocus = new QShortcut(QKeySequence("Esc"), this);
155     connect(m_shortcutRemoveFocus, SIGNAL(activated()), this, SLOT(slotRemoveFocus()));
156
157     m_effectListDock = new QDockWidget(i18n("Effect List"), this);
158     m_effectListDock->setObjectName("effect_list");
159     m_effectList = new EffectsListView();
160
161     //m_effectList = new KListWidget(this);
162     m_effectListDock->setWidget(m_effectList);
163     addDockWidget(Qt::TopDockWidgetArea, m_effectListDock);
164
165     m_effectStackDock = new QDockWidget(i18n("Effect Stack"), this);
166     m_effectStackDock->setObjectName("effect_stack");
167     m_effectStack = new EffectStackView(this);
168     m_effectStackDock->setWidget(m_effectStack);
169     addDockWidget(Qt::TopDockWidgetArea, m_effectStackDock);
170
171     m_transitionConfigDock = new QDockWidget(i18n("Transition"), this);
172     m_transitionConfigDock->setObjectName("transition");
173     m_transitionConfig = new TransitionSettings(this);
174     m_transitionConfigDock->setWidget(m_transitionConfig);
175     addDockWidget(Qt::TopDockWidgetArea, m_transitionConfigDock);
176
177     KdenliveSettings::setCurrent_profile(KdenliveSettings::default_profile());
178     m_fileOpenRecent = KStandardAction::openRecent(this, SLOT(openFile(const KUrl &)),
179                        actionCollection());
180     readOptions();
181
182     //slotDetectAudioDriver();
183
184     m_clipMonitorDock = new QDockWidget(i18n("Clip Monitor"), this);
185     m_clipMonitorDock->setObjectName("clip_monitor");
186     m_clipMonitor = new Monitor("clip", m_monitorManager, this);
187     m_clipMonitorDock->setWidget(m_clipMonitor);
188     addDockWidget(Qt::TopDockWidgetArea, m_clipMonitorDock);
189     //m_clipMonitor->stop();
190
191     m_projectMonitorDock = new QDockWidget(i18n("Project Monitor"), this);
192     m_projectMonitorDock->setObjectName("project_monitor");
193     m_projectMonitor = new Monitor("project", m_monitorManager, this);
194     m_projectMonitorDock->setWidget(m_projectMonitor);
195     addDockWidget(Qt::TopDockWidgetArea, m_projectMonitorDock);
196
197     m_recMonitorDock = new QDockWidget(i18n("Record Monitor"), this);
198     m_recMonitorDock->setObjectName("record_monitor");
199     m_recMonitor = new RecMonitor("record", this);
200     m_recMonitorDock->setWidget(m_recMonitor);
201     addDockWidget(Qt::TopDockWidgetArea, m_recMonitorDock);
202
203     connect(m_recMonitor, SIGNAL(addProjectClip(KUrl)), this, SLOT(slotAddProjectClip(KUrl)));
204     connect(m_recMonitor, SIGNAL(showConfigDialog(int, int)), this, SLOT(slotPreferences(int, int)));
205
206     m_undoViewDock = new QDockWidget(i18n("Undo History"), this);
207     m_undoViewDock->setObjectName("undo_history");
208     m_undoView = new QUndoView(this);
209     m_undoView->setCleanIcon(KIcon("edit-clear"));
210     m_undoView->setEmptyLabel(i18n("Clean"));
211     m_undoViewDock->setWidget(m_undoView);
212     m_undoView->setGroup(m_commandStack);
213     addDockWidget(Qt::TopDockWidgetArea, m_undoViewDock);
214
215     //overviewDock = new QDockWidget(i18n("Project Overview"), this);
216     //overviewDock->setObjectName("project_overview");
217     //m_overView = new CustomTrackView(NULL, NULL, this);
218     //overviewDock->setWidget(m_overView);
219     //addDockWidget(Qt::TopDockWidgetArea, overviewDock);
220
221     setupActions();
222     //tabifyDockWidget(projectListDock, effectListDock);
223     tabifyDockWidget(m_projectListDock, m_effectStackDock);
224     tabifyDockWidget(m_projectListDock, m_transitionConfigDock);
225     //tabifyDockWidget(projectListDock, undoViewDock);
226
227
228     tabifyDockWidget(m_clipMonitorDock, m_projectMonitorDock);
229     tabifyDockWidget(m_clipMonitorDock, m_recMonitorDock);
230     setCentralWidget(m_timelineArea);
231
232
233     setupGUI();
234     /*ScriptingPart* sp = new ScriptingPart(this, QStringList());
235     guiFactory()->addClient(sp);*/
236
237     loadPlugins();
238     loadTranscoders();
239     //kDebug() << factory() << " " << factory()->container("video_effects_menu", this);
240
241     m_projectMonitor->setupMenu(static_cast<QMenu*>(factory()->container("monitor_go", this)), m_playZone, m_loopZone);
242     m_clipMonitor->setupMenu(static_cast<QMenu*>(factory()->container("monitor_go", this)), m_playZone, m_loopZone, static_cast<QMenu*>(factory()->container("marker_menu", this)));
243     m_projectList->setupGeneratorMenu(static_cast<QMenu*>(factory()->container("generators", this)), static_cast<QMenu*>(factory()->container("transcoders", this)));
244
245     // build effects menus
246     QAction *action;
247     QMenu *videoEffectsMenu = static_cast<QMenu*>(factory()->container("video_effects_menu", this));
248
249     QStringList effectInfo;
250     QMap<QString, QStringList> effectsList;
251     for (int ix = 0; ix < videoEffects.count(); ix++) {
252         effectInfo = videoEffects.effectIdInfo(ix);
253         effectsList.insert(effectInfo.at(0).toLower(), effectInfo);
254     }
255
256     foreach(const QStringList &value, effectsList) {
257         action = new QAction(value.at(0), this);
258         action->setData(value);
259         videoEffectsMenu->addAction(action);
260     }
261
262     QMenu *audioEffectsMenu = static_cast<QMenu*>(factory()->container("audio_effects_menu", this));
263
264
265     effectsList.clear();
266     for (int ix = 0; ix < audioEffects.count(); ix++) {
267         effectInfo = audioEffects.effectIdInfo(ix);
268         effectsList.insert(effectInfo.at(0).toLower(), effectInfo);
269     }
270
271     foreach(const QStringList &value, effectsList) {
272         action = new QAction(value.at(0), this);
273         action->setData(value);
274         audioEffectsMenu->addAction(action);
275     }
276
277     m_customEffectsMenu = static_cast<QMenu*>(factory()->container("custom_effects_menu", this));
278
279     if (customEffects.isEmpty()) m_customEffectsMenu->setEnabled(false);
280     else m_customEffectsMenu->setEnabled(true);
281
282     effectsList.clear();
283     for (int ix = 0; ix < customEffects.count(); ix++) {
284         effectInfo = customEffects.effectIdInfo(ix);
285         effectsList.insert(effectInfo.at(0).toLower(), effectInfo);
286     }
287
288     foreach(const QStringList &value, effectsList) {
289         action = new QAction(value.at(0), this);
290         action->setData(value);
291         m_customEffectsMenu->addAction(action);
292     }
293
294     QMenu *newEffect = new QMenu(this);
295     newEffect->addMenu(videoEffectsMenu);
296     newEffect->addMenu(audioEffectsMenu);
297     newEffect->addMenu(m_customEffectsMenu);
298     m_effectStack->setMenu(newEffect);
299
300
301     QMenu *viewMenu = static_cast<QMenu*>(factory()->container("dockwindows", this));
302     const QList<QAction *> viewActions = createPopupMenu()->actions();
303     viewMenu->insertActions(NULL, viewActions);
304
305     connect(videoEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddVideoEffect(QAction *)));
306     connect(audioEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddAudioEffect(QAction *)));
307     connect(m_customEffectsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddCustomEffect(QAction *)));
308
309     m_timelineContextMenu = new QMenu(this);
310     m_timelineContextClipMenu = new QMenu(this);
311     m_timelineContextTransitionMenu = new QMenu(this);
312
313
314     QMenu *transitionsMenu = new QMenu(i18n("Add Transition"), this);
315     QStringList effects = transitions.effectNames();
316
317     effectsList.clear();
318     for (int ix = 0; ix < transitions.count(); ix++) {
319         effectInfo = transitions.effectIdInfo(ix);
320         effectsList.insert(effectInfo.at(0).toLower(), effectInfo);
321     }
322     foreach(const QStringList &value, effectsList) {
323         action = new QAction(value.at(0), this);
324         action->setData(value);
325         transitionsMenu->addAction(action);
326     }
327     connect(transitionsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotAddTransition(QAction *)));
328
329     m_timelineContextMenu->addAction(actionCollection()->action("insert_space"));
330     m_timelineContextMenu->addAction(actionCollection()->action("delete_space"));
331     m_timelineContextMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Paste)));
332
333     m_timelineContextClipMenu->addAction(actionCollection()->action("delete_timeline_clip"));
334     m_timelineContextClipMenu->addAction(actionCollection()->action("group_clip"));
335     m_timelineContextClipMenu->addAction(actionCollection()->action("ungroup_clip"));
336     m_timelineContextClipMenu->addAction(actionCollection()->action("cut_timeline_clip"));
337     m_timelineContextClipMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Copy)));
338     m_timelineContextClipMenu->addAction(actionCollection()->action("paste_effects"));
339     m_timelineContextClipMenu->addAction(actionCollection()->action("split_audio"));
340
341     QMenu *markersMenu = (QMenu*)(factory()->container("marker_menu", this));
342     m_timelineContextClipMenu->addMenu(markersMenu);
343     m_timelineContextClipMenu->addMenu(transitionsMenu);
344     m_timelineContextClipMenu->addMenu(videoEffectsMenu);
345     m_timelineContextClipMenu->addMenu(audioEffectsMenu);
346     //TODO: re-enable custom effects menu when it is implemented
347     m_timelineContextClipMenu->addMenu(m_customEffectsMenu);
348
349     m_timelineContextTransitionMenu->addAction(actionCollection()->action("delete_timeline_clip"));
350     m_timelineContextTransitionMenu->addAction(actionCollection()->action(KStandardAction::name(KStandardAction::Copy)));
351
352     m_timelineContextTransitionMenu->addAction(actionCollection()->action("auto_transition"));
353
354     connect(m_projectMonitorDock, SIGNAL(visibilityChanged(bool)), m_projectMonitor, SLOT(refreshMonitor(bool)));
355     connect(m_clipMonitorDock, SIGNAL(visibilityChanged(bool)), m_clipMonitor, SLOT(refreshMonitor(bool)));
356     //connect(m_monitorManager, SIGNAL(connectMonitors()), this, SLOT(slotConnectMonitors()));
357     connect(m_monitorManager, SIGNAL(raiseClipMonitor(bool)), this, SLOT(slotRaiseMonitor(bool)));
358     connect(m_effectList, SIGNAL(addEffect(const QDomElement)), this, SLOT(slotAddEffect(const QDomElement)));
359     connect(m_effectList, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
360
361     m_monitorManager->initMonitors(m_clipMonitor, m_projectMonitor);
362     slotConnectMonitors();
363
364     // Open or create a file.  Command line argument passed in Url has
365     // precedence, then "openlastproject", then just a plain empty file.
366     // If opening Url fails, openlastproject will _not_ be used.
367     if (!Url.isEmpty()) {
368         openFile(Url);
369     } else {
370         if (KdenliveSettings::openlastproject()) {
371             openLastFile();
372         }
373     }
374     if (m_timelineArea->count() == 0) {
375         newFile(false);
376     }
377
378 #ifndef NO_JOGSHUTTLE
379     activateShuttleDevice();
380 #endif /* NO_JOGSHUTTLE */
381     m_projectListDock->raise();
382 }
383
384 void MainWindow::queryQuit()
385 {
386     if (queryClose()) {
387         delete m_effectStack;
388         delete m_activeTimeline;
389         delete m_projectMonitor;
390         delete m_clipMonitor;
391         delete m_activeDocument;
392         delete m_shortcutRemoveFocus;
393         Mlt::Factory::close();
394         kapp->quit();
395     }
396 }
397
398 //virtual
399 bool MainWindow::queryClose()
400 {
401     if (m_renderWidget) {
402         int waitingJobs = m_renderWidget->waitingJobsCount();
403         if (waitingJobs > 0) {
404             switch (KMessageBox::warningYesNoCancel(this, i18n("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")))) {
405             case KMessageBox::Yes :
406                 // create script with waiting jobs and start it
407                 if (m_renderWidget->startWaitingRenderJobs() == false) return false;
408                 break;
409             case KMessageBox::No :
410                 // Don't do anything, jobs will be deleted
411                 break;
412             default:
413                 return false;
414             }
415         }
416     }
417     saveOptions();
418     if (m_monitorManager) m_monitorManager->stopActiveMonitor();
419     if (m_activeDocument && m_activeDocument->isModified()) {
420         switch (KMessageBox::warningYesNoCancel(this, i18n("Save changes to document?"))) {
421         case KMessageBox::Yes :
422             // save document here. If saving fails, return false;
423             return saveFile();
424         case KMessageBox::No :
425             // User does not want to save the changes, clear recovery files
426             m_activeDocument->m_autosave->resize(0);
427             return true;
428         default: // cancel
429             return false;
430         }
431     }
432     return true;
433 }
434
435
436 void MainWindow::loadPlugins()
437 {
438     foreach(QObject *plugin, QPluginLoader::staticInstances())
439     populateMenus(plugin);
440
441     QStringList directories = KGlobal::dirs()->findDirs("module", QString());
442     QStringList filters;
443     filters << "libkdenlive*";
444     foreach(const QString &folder, directories) {
445         kDebug() << "// PARSING FIOLER: " << folder;
446         QDir pluginsDir(folder);
447         foreach(const QString &fileName, pluginsDir.entryList(filters, QDir::Files)) {
448             kDebug() << "// FOUND PLUGIN: " << fileName << "= " << pluginsDir.absoluteFilePath(fileName);
449             QPluginLoader loader(pluginsDir.absoluteFilePath(fileName));
450             QObject *plugin = loader.instance();
451             if (plugin) {
452                 populateMenus(plugin);
453                 m_pluginFileNames += fileName;
454             } else kDebug() << "// ERROR LOADING PLUGIN: " << fileName << ", " << loader.errorString();
455         }
456     }
457     //exit(1);
458 }
459
460 void MainWindow::populateMenus(QObject *plugin)
461 {
462     QMenu *addMenu = static_cast<QMenu*>(factory()->container("generators", this));
463     ClipGenerator *iGenerator = qobject_cast<ClipGenerator *>(plugin);
464     if (iGenerator)
465         addToMenu(plugin, iGenerator->generators(KdenliveSettings::producerslist()), addMenu, SLOT(generateClip()),
466                   NULL);
467 }
468
469 void MainWindow::addToMenu(QObject *plugin, const QStringList &texts,
470                            QMenu *menu, const char *member,
471                            QActionGroup *actionGroup)
472 {
473     kDebug() << "// ADD to MENU" << texts;
474     foreach(const QString &text, texts) {
475         QAction *action = new QAction(text, plugin);
476         action->setData(text);
477         connect(action, SIGNAL(triggered()), this, member);
478         menu->addAction(action);
479
480         if (actionGroup) {
481             action->setCheckable(true);
482             actionGroup->addAction(action);
483         }
484     }
485 }
486
487 void MainWindow::aboutPlugins()
488 {
489     //PluginDialog dialog(pluginsDir.path(), m_pluginFileNames, this);
490     //dialog.exec();
491 }
492
493
494 void MainWindow::generateClip()
495 {
496     QAction *action = qobject_cast<QAction *>(sender());
497     ClipGenerator *iGenerator = qobject_cast<ClipGenerator *>(action->parent());
498
499     KUrl clipUrl = iGenerator->generatedClip(action->data().toString(), m_activeDocument->projectFolder(), QStringList(), QStringList(), 25, 720, 576);
500     if (!clipUrl.isEmpty()) {
501         m_projectList->slotAddClip(QList <QUrl> () << clipUrl);
502     }
503 }
504
505 void MainWindow::saveProperties(KConfigGroup &config)
506 {
507     // save properties here,used by session management
508     saveFile();
509     KMainWindow::saveProperties(config);
510 }
511
512
513 void MainWindow::readProperties(const KConfigGroup &config)
514 {
515     // read properties here,used by session management
516     KMainWindow::readProperties(config);
517     QString Lastproject = config.group("Recent Files").readPathEntry("File1", QString());
518     openFile(KUrl(Lastproject));
519 }
520
521 void MainWindow::slotReloadEffects()
522 {
523     initEffects::parseCustomEffectsFile();
524     m_customEffectsMenu->clear();
525     const QStringList effects = customEffects.effectNames();
526     QAction *action;
527     if (effects.isEmpty()) m_customEffectsMenu->setEnabled(false);
528     else m_customEffectsMenu->setEnabled(true);
529
530     foreach(const QString &name, effects) {
531         action = new QAction(name, this);
532         action->setData(name);
533         m_customEffectsMenu->addAction(action);
534     }
535     m_effectList->reloadEffectList();
536 }
537
538 #ifndef NO_JOGSHUTTLE
539 void MainWindow::activateShuttleDevice()
540 {
541     delete m_jogProcess;
542     m_jogProcess = NULL;
543     if (KdenliveSettings::enableshuttle() == false) return;
544     m_jogProcess = new JogShuttle(KdenliveSettings::shuttledevice());
545     connect(m_jogProcess, SIGNAL(rewind1()), m_monitorManager, SLOT(slotRewindOneFrame()));
546     connect(m_jogProcess, SIGNAL(forward1()), m_monitorManager, SLOT(slotForwardOneFrame()));
547     connect(m_jogProcess, SIGNAL(rewind(double)), m_monitorManager, SLOT(slotRewind(double)));
548     connect(m_jogProcess, SIGNAL(forward(double)), m_monitorManager, SLOT(slotForward(double)));
549     connect(m_jogProcess, SIGNAL(stop()), m_monitorManager, SLOT(slotPlay()));
550     connect(m_jogProcess, SIGNAL(button(int)), this, SLOT(slotShuttleButton(int)));
551 }
552
553 void MainWindow::slotShuttleButton(int code)
554 {
555     switch (code) {
556     case 5:
557         slotShuttleAction(KdenliveSettings::shuttle1());
558         break;
559     case 6:
560         slotShuttleAction(KdenliveSettings::shuttle2());
561         break;
562     case 7:
563         slotShuttleAction(KdenliveSettings::shuttle3());
564         break;
565     case 8:
566         slotShuttleAction(KdenliveSettings::shuttle4());
567         break;
568     case 9:
569         slotShuttleAction(KdenliveSettings::shuttle5());
570         break;
571     }
572 }
573
574 void MainWindow::slotShuttleAction(int code)
575 {
576     switch (code) {
577     case 0:
578         return;
579     case 1:
580         m_monitorManager->slotPlay();
581         break;
582     default:
583         m_monitorManager->slotPlay();
584         break;
585     }
586 }
587 #endif /* NO_JOGSHUTTLE */
588
589 void MainWindow::configureNotifications()
590 {
591     KNotifyConfigWidget::configure(this);
592 }
593
594 void MainWindow::slotFullScreen()
595 {
596     KToggleFullScreenAction::setFullScreen(this, actionCollection()->action("fullscreen")->isChecked());
597 }
598
599 void MainWindow::slotAddEffect(const QDomElement effect, GenTime pos, int track)
600 {
601     if (!m_activeDocument) return;
602     if (effect.isNull()) {
603         kDebug() << "--- ERROR, TRYING TO APPEND NULL EFFECT";
604         return;
605     }
606     QDomElement effectToAdd = effect.cloneNode().toElement();
607     m_activeTimeline->projectView()->slotAddEffect(effectToAdd, pos, track);
608 }
609
610 void MainWindow::slotRaiseMonitor(bool clipMonitor)
611 {
612     if (clipMonitor) m_clipMonitorDock->raise();
613     else m_projectMonitorDock->raise();
614 }
615
616 void MainWindow::slotUpdateClip(const QString &id)
617 {
618     if (!m_activeDocument) return;
619     m_activeTimeline->projectView()->slotUpdateClip(id);
620 }
621
622 void MainWindow::slotConnectMonitors()
623 {
624
625     m_projectList->setRenderer(m_projectMonitor->render);
626     connect(m_projectList, SIGNAL(receivedClipDuration(const QString &)), this, SLOT(slotUpdateClip(const QString &)));
627     connect(m_projectList, SIGNAL(showClipProperties(DocClipBase *)), this, SLOT(slotShowClipProperties(DocClipBase *)));
628     connect(m_projectList, SIGNAL(getFileProperties(const QDomElement, const QString &, bool)), m_projectMonitor->render, SLOT(getFileProperties(const QDomElement, const QString &, bool)));
629     connect(m_projectMonitor->render, SIGNAL(replyGetImage(const QString &, const QPixmap &)), m_projectList, SLOT(slotReplyGetImage(const QString &, const QPixmap &)));
630     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)));
631
632     connect(m_projectMonitor->render, SIGNAL(removeInvalidClip(const QString &, bool)), m_projectList, SLOT(slotRemoveInvalidClip(const QString &, bool)));
633
634     connect(m_clipMonitor, SIGNAL(refreshClipThumbnail(const QString &)), m_projectList, SLOT(slotRefreshClipThumbnail(const QString &)));
635
636     connect(m_clipMonitor, SIGNAL(adjustMonitorSize()), this, SLOT(slotAdjustClipMonitor()));
637     connect(m_projectMonitor, SIGNAL(adjustMonitorSize()), this, SLOT(slotAdjustProjectMonitor()));
638
639     connect(m_clipMonitor, SIGNAL(saveZone(Render *, QPoint)), this, SLOT(slotSaveZone(Render *, QPoint)));
640     connect(m_projectMonitor, SIGNAL(saveZone(Render *, QPoint)), this, SLOT(slotSaveZone(Render *, QPoint)));
641 }
642
643 void MainWindow::slotAdjustClipMonitor()
644 {
645     m_clipMonitorDock->updateGeometry();
646     m_clipMonitorDock->adjustSize();
647     m_clipMonitor->resetSize();
648 }
649
650 void MainWindow::slotAdjustProjectMonitor()
651 {
652     m_projectMonitorDock->updateGeometry();
653     m_projectMonitorDock->adjustSize();
654     m_projectMonitor->resetSize();
655 }
656
657 void MainWindow::setupActions()
658 {
659
660     KActionCollection* collection = actionCollection();
661     m_timecodeFormat = new KComboBox(this);
662     m_timecodeFormat->addItem(i18n("hh:mm:ss::ff"));
663     m_timecodeFormat->addItem(i18n("Frames"));
664     if (KdenliveSettings::frametimecode()) m_timecodeFormat->setCurrentIndex(1);
665     connect(m_timecodeFormat, SIGNAL(activated(int)), this, SLOT(slotUpdateTimecodeFormat(int)));
666
667     m_statusProgressBar = new QProgressBar(this);
668     m_statusProgressBar->setMinimum(0);
669     m_statusProgressBar->setMaximum(100);
670     m_statusProgressBar->setMaximumWidth(150);
671     m_statusProgressBar->setVisible(false);
672
673     QWidget *w = new QWidget;
674
675     QHBoxLayout *layout = new QHBoxLayout;
676     w->setLayout(layout);
677     layout->setContentsMargins(5, 0, 5, 0);
678     QToolBar *toolbar = new QToolBar("statusToolBar", this);
679
680
681     m_toolGroup = new QActionGroup(this);
682
683     QString style1 = "QToolButton {background-color: rgba(230, 230, 230, 220); 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;}";
684
685     m_buttonSelectTool = new KAction(KIcon("kdenlive-select-tool"), i18n("Selection tool"), this);
686     m_buttonSelectTool->setShortcut(i18nc("Selection tool shortcut", "s"));
687     toolbar->addAction(m_buttonSelectTool);
688     m_buttonSelectTool->setCheckable(true);
689     m_buttonSelectTool->setChecked(true);
690
691     m_buttonRazorTool = new KAction(KIcon("edit-cut"), i18n("Razor tool"), this);
692     m_buttonRazorTool->setShortcut(i18nc("Razor tool shortcut", "x"));
693     toolbar->addAction(m_buttonRazorTool);
694     m_buttonRazorTool->setCheckable(true);
695     m_buttonRazorTool->setChecked(false);
696
697     m_buttonSpacerTool = new KAction(KIcon("kdenlive-spacer-tool"), i18n("Spacer tool"), this);
698     m_buttonSpacerTool->setShortcut(i18nc("Spacer tool shortcut", "m"));
699     toolbar->addAction(m_buttonSpacerTool);
700     m_buttonSpacerTool->setCheckable(true);
701     m_buttonSpacerTool->setChecked(false);
702
703     m_toolGroup->addAction(m_buttonSelectTool);
704     m_toolGroup->addAction(m_buttonRazorTool);
705     m_toolGroup->addAction(m_buttonSpacerTool);
706     m_toolGroup->setExclusive(true);
707     toolbar->setToolButtonStyle(Qt::ToolButtonIconOnly);
708
709     QWidget * actionWidget;
710     actionWidget = toolbar->widgetForAction(m_buttonSelectTool);
711     actionWidget->setMaximumWidth(24);
712     actionWidget->setMinimumHeight(18);
713
714     actionWidget = toolbar->widgetForAction(m_buttonRazorTool);
715     actionWidget->setMaximumWidth(24);
716     actionWidget->setMinimumHeight(18);
717
718     actionWidget = toolbar->widgetForAction(m_buttonSpacerTool);
719     actionWidget->setMaximumWidth(24);
720     actionWidget->setMinimumHeight(18);
721
722     toolbar->setStyleSheet(style1);
723     connect(m_toolGroup, SIGNAL(triggered(QAction *)), this, SLOT(slotChangeTool(QAction *)));
724
725     toolbar->addSeparator();
726     m_buttonFitZoom = new KAction(KIcon("zoom-fit-best"), i18n("Fit zoom to project"), this);
727     toolbar->addAction(m_buttonFitZoom);
728     m_buttonFitZoom->setCheckable(false);
729     connect(m_buttonFitZoom, SIGNAL(triggered()), this, SLOT(slotFitZoom()));
730
731     actionWidget = toolbar->widgetForAction(m_buttonFitZoom);
732     actionWidget->setMaximumWidth(24);
733     actionWidget->setMinimumHeight(18);
734
735     m_zoomSlider = new QSlider(Qt::Horizontal, this);
736     m_zoomSlider->setMaximum(13);
737     m_zoomSlider->setPageStep(1);
738
739     m_zoomSlider->setMaximumWidth(150);
740     m_zoomSlider->setMinimumWidth(100);
741
742     const int contentHeight = QFontMetrics(w->font()).height() + 8;
743
744     QString style = "QSlider::groove:horizontal { background-color: rgba(230, 230, 230, 220);border: 1px solid #999999;height: 8px;border-radius: 3px;margin-top:3px }";
745     style.append("QSlider::handle:horizontal {  background-color: white; border: 1px solid #999999;width: 9px;margin: -2px 0;border-radius: 3px; }");
746
747     m_zoomSlider->setStyleSheet(style);
748
749     //m_zoomSlider->height() + 5;
750     statusBar()->setMinimumHeight(contentHeight);
751
752
753     toolbar->addWidget(m_zoomSlider);
754
755     m_buttonVideoThumbs = new KAction(KIcon("kdenlive-show-videothumb"), i18n("Show video thumbnails"), this);
756     toolbar->addAction(m_buttonVideoThumbs);
757     m_buttonVideoThumbs->setCheckable(true);
758     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
759     connect(m_buttonVideoThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchVideoThumbs()));
760
761     m_buttonAudioThumbs = new KAction(KIcon("kdenlive-show-audiothumb"), i18n("Show audio thumbnails"), this);
762     toolbar->addAction(m_buttonAudioThumbs);
763     m_buttonAudioThumbs->setCheckable(true);
764     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
765     connect(m_buttonAudioThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchAudioThumbs()));
766
767     m_buttonShowMarkers = new KAction(KIcon("kdenlive-show-markers"), i18n("Show markers comments"), this);
768     toolbar->addAction(m_buttonShowMarkers);
769     m_buttonShowMarkers->setCheckable(true);
770     m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
771     connect(m_buttonShowMarkers, SIGNAL(triggered()), this, SLOT(slotSwitchMarkersComments()));
772
773     m_buttonSnap = new KAction(KIcon("kdenlive-snap"), i18n("Snap"), this);
774     toolbar->addAction(m_buttonSnap);
775     m_buttonSnap->setCheckable(true);
776     m_buttonSnap->setChecked(KdenliveSettings::snaptopoints());
777     connect(m_buttonSnap, SIGNAL(triggered()), this, SLOT(slotSwitchSnap()));
778     layout->addWidget(toolbar);
779
780
781     actionWidget = toolbar->widgetForAction(m_buttonVideoThumbs);
782     actionWidget->setMaximumWidth(24);
783     actionWidget->setMinimumHeight(18);
784
785     actionWidget = toolbar->widgetForAction(m_buttonAudioThumbs);
786     actionWidget->setMaximumWidth(24);
787     actionWidget->setMinimumHeight(18);
788
789     actionWidget = toolbar->widgetForAction(m_buttonShowMarkers);
790     actionWidget->setMaximumWidth(24);
791     actionWidget->setMinimumHeight(18);
792
793     actionWidget = toolbar->widgetForAction(m_buttonSnap);
794     actionWidget->setMaximumWidth(24);
795     actionWidget->setMinimumHeight(18);
796
797     m_messageLabel = new StatusBarMessageLabel(this);
798     m_messageLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding);
799
800     statusBar()->addWidget(m_messageLabel, 10);
801     statusBar()->addWidget(m_statusProgressBar, 0);
802     statusBar()->addPermanentWidget(w);
803     statusBar()->insertPermanentFixedItem("00:00:00:00", ID_TIMELINE_POS);
804     statusBar()->addPermanentWidget(m_timecodeFormat);
805     statusBar()->setMaximumHeight(statusBar()->font().pointSize() * 4);
806
807     collection->addAction("select_tool", m_buttonSelectTool);
808     collection->addAction("razor_tool", m_buttonRazorTool);
809     collection->addAction("spacer_tool", m_buttonSpacerTool);
810
811     collection->addAction("show_video_thumbs", m_buttonVideoThumbs);
812     collection->addAction("show_audio_thumbs", m_buttonAudioThumbs);
813     collection->addAction("show_markers", m_buttonShowMarkers);
814     collection->addAction("snap", m_buttonSnap);
815     collection->addAction("zoom_fit", m_buttonFitZoom);
816
817     KAction* zoomIn = new KAction(KIcon("zoom-in"), i18n("Zoom In"), this);
818     collection->addAction("zoom_in", zoomIn);
819     connect(zoomIn, SIGNAL(triggered(bool)), this, SLOT(slotZoomIn()));
820     zoomIn->setShortcut(Qt::CTRL + Qt::Key_Plus);
821
822     KAction* zoomOut = new KAction(KIcon("zoom-out"), i18n("Zoom Out"), this);
823     collection->addAction("zoom_out", zoomOut);
824     connect(zoomOut, SIGNAL(triggered(bool)), this, SLOT(slotZoomOut()));
825     zoomOut->setShortcut(Qt::CTRL + Qt::Key_Minus);
826
827     m_projectSearch = new KAction(KIcon("edit-find"), i18n("Find"), this);
828     collection->addAction("project_find", m_projectSearch);
829     connect(m_projectSearch, SIGNAL(triggered(bool)), this, SLOT(slotFind()));
830     m_projectSearch->setShortcut(Qt::Key_Slash);
831
832     m_projectSearchNext = new KAction(KIcon("go-down-search"), i18n("Find Next"), this);
833     collection->addAction("project_find_next", m_projectSearchNext);
834     connect(m_projectSearchNext, SIGNAL(triggered(bool)), this, SLOT(slotFindNext()));
835     m_projectSearchNext->setShortcut(Qt::Key_F3);
836     m_projectSearchNext->setEnabled(false);
837
838     KAction* profilesAction = new KAction(KIcon("document-new"), i18n("Manage Project Profiles"), this);
839     collection->addAction("manage_profiles", profilesAction);
840     connect(profilesAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProfiles()));
841
842     KNS::standardAction(i18n("Download New Wipes..."), this, SLOT(slotGetNewLumaStuff()), actionCollection(), "get_new_lumas");
843
844     KNS::standardAction(i18n("Download New Render Profiles..."), this, SLOT(slotGetNewRenderStuff()), actionCollection(), "get_new_profiles");
845
846     KNS::standardAction(i18n("Download New Project Profiles..."), this, SLOT(slotGetNewMltProfileStuff()), actionCollection(), "get_new_mlt_profiles");
847
848     KAction* wizAction = new KAction(KIcon("configure"), i18n("Run Config Wizard"), this);
849     collection->addAction("run_wizard", wizAction);
850     connect(wizAction, SIGNAL(triggered(bool)), this, SLOT(slotRunWizard()));
851
852     KAction* projectAction = new KAction(KIcon("configure"), i18n("Project Settings"), this);
853     collection->addAction("project_settings", projectAction);
854     connect(projectAction, SIGNAL(triggered(bool)), this, SLOT(slotEditProjectSettings()));
855
856     KAction* projectRender = new KAction(KIcon("media-record"), i18n("Render"), this);
857     collection->addAction("project_render", projectRender);
858     projectRender->setShortcut(Qt::CTRL + Qt::Key_Return);
859     connect(projectRender, SIGNAL(triggered(bool)), this, SLOT(slotRenderProject()));
860
861     KAction* monitorPlay = new KAction(KIcon("media-playback-start"), i18n("Play"), this);
862     KShortcut playShortcut;
863     playShortcut.setPrimary(Qt::Key_Space);
864     playShortcut.setAlternate(Qt::Key_K);
865     monitorPlay->setShortcut(playShortcut);
866     collection->addAction("monitor_play", monitorPlay);
867     connect(monitorPlay, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotPlay()));
868
869     m_playZone = new KAction(KIcon("media-playback-start"), i18n("Play Zone"), this);
870     m_playZone->setShortcut(Qt::CTRL + Qt::Key_Space);
871     collection->addAction("monitor_play_zone", m_playZone);
872     connect(m_playZone, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotPlayZone()));
873
874     m_loopZone = new KAction(KIcon("media-playback-start"), i18n("Loop Zone"), this);
875     m_loopZone->setShortcut(Qt::ALT + Qt::Key_Space);
876     collection->addAction("monitor_loop_zone", m_loopZone);
877     connect(m_loopZone, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotLoopZone()));
878
879     KAction *dvdWizard =  new KAction(KIcon("media-optical"), i18n("DVD Wizard"), this);
880     collection->addAction("dvd_wizard", dvdWizard);
881     connect(dvdWizard, SIGNAL(triggered(bool)), this, SLOT(slotDvdWizard()));
882
883     KAction *transcodeClip =  new KAction(KIcon("edit-copy"), i18n("Transcode Clip"), this);
884     collection->addAction("transcode_clip", transcodeClip);
885     connect(transcodeClip, SIGNAL(triggered(bool)), this, SLOT(slotTranscodeClip()));
886
887     KAction *markIn = collection->addAction("mark_in");
888     markIn->setText(i18n("Set In Point"));
889     markIn->setShortcut(Qt::Key_I);
890     connect(markIn, SIGNAL(triggered(bool)), this, SLOT(slotSetInPoint()));
891
892     KAction *markOut = collection->addAction("mark_out");
893     markOut->setText(i18n("Set Out Point"));
894     markOut->setShortcut(Qt::Key_O);
895     connect(markOut, SIGNAL(triggered(bool)), this, SLOT(slotSetOutPoint()));
896
897     KAction* monitorSeekBackward = new KAction(KIcon("media-seek-backward"), i18n("Rewind"), this);
898     monitorSeekBackward->setShortcut(Qt::Key_J);
899     collection->addAction("monitor_seek_backward", monitorSeekBackward);
900     connect(monitorSeekBackward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewind()));
901
902     KAction* monitorSeekBackwardOneFrame = new KAction(KIcon("media-skip-backward"), i18n("Rewind 1 Frame"), this);
903     monitorSeekBackwardOneFrame->setShortcut(Qt::Key_Left);
904     collection->addAction("monitor_seek_backward-one-frame", monitorSeekBackwardOneFrame);
905     connect(monitorSeekBackwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewindOneFrame()));
906
907     KAction* monitorSeekBackwardOneSecond = new KAction(KIcon("media-skip-backward"), i18n("Rewind 1 Second"), this);
908     monitorSeekBackwardOneSecond->setShortcut(Qt::SHIFT + Qt::Key_Left);
909     collection->addAction("monitor_seek_backward-one-second", monitorSeekBackwardOneSecond);
910     connect(monitorSeekBackwardOneSecond, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotRewindOneSecond()));
911
912     KAction* monitorSeekSnapBackward = new KAction(KIcon("media-seek-backward"), i18n("Go to Previous Snap Point"), this);
913     monitorSeekSnapBackward->setShortcut(Qt::ALT + Qt::Key_Left);
914     collection->addAction("monitor_seek_snap_backward", monitorSeekSnapBackward);
915     connect(monitorSeekSnapBackward, SIGNAL(triggered(bool)), this, SLOT(slotSnapRewind()));
916
917     KAction* monitorSeekForward = new KAction(KIcon("media-seek-forward"), i18n("Forward"), this);
918     monitorSeekForward->setShortcut(Qt::Key_L);
919     collection->addAction("monitor_seek_forward", monitorSeekForward);
920     connect(monitorSeekForward, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForward()));
921
922     KAction* clipStart = new KAction(KIcon("media-seek-backward"), i18n("Go to Clip Start"), this);
923     clipStart->setShortcut(Qt::Key_Home);
924     collection->addAction("seek_clip_start", clipStart);
925     connect(clipStart, SIGNAL(triggered(bool)), this, SLOT(slotClipStart()));
926
927     KAction* clipEnd = new KAction(KIcon("media-seek-forward"), i18n("Go to Clip End"), this);
928     clipEnd->setShortcut(Qt::Key_End);
929     collection->addAction("seek_clip_end", clipEnd);
930     connect(clipEnd, SIGNAL(triggered(bool)), this, SLOT(slotClipEnd()));
931
932     KAction* projectStart = new KAction(KIcon("go-first"), i18n("Go to Project Start"), this);
933     projectStart->setShortcut(Qt::CTRL + Qt::Key_Home);
934     collection->addAction("seek_start", projectStart);
935     connect(projectStart, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotStart()));
936
937     KAction* projectEnd = new KAction(KIcon("go-last"), i18n("Go to Project End"), this);
938     projectEnd->setShortcut(Qt::CTRL + Qt::Key_End);
939     collection->addAction("seek_end", projectEnd);
940     connect(projectEnd, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotEnd()));
941
942     KAction* monitorSeekForwardOneFrame = new KAction(KIcon("media-skip-forward"), i18n("Forward 1 Frame"), this);
943     monitorSeekForwardOneFrame->setShortcut(Qt::Key_Right);
944     collection->addAction("monitor_seek_forward-one-frame", monitorSeekForwardOneFrame);
945     connect(monitorSeekForwardOneFrame, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForwardOneFrame()));
946
947     KAction* monitorSeekForwardOneSecond = new KAction(KIcon("media-skip-forward"), i18n("Forward 1 Second"), this);
948     monitorSeekForwardOneSecond->setShortcut(Qt::SHIFT + Qt::Key_Right);
949     collection->addAction("monitor_seek_forward-one-second", monitorSeekForwardOneSecond);
950     connect(monitorSeekForwardOneSecond, SIGNAL(triggered(bool)), m_monitorManager, SLOT(slotForwardOneSecond()));
951
952     KAction* monitorSeekSnapForward = new KAction(KIcon("media-seek-forward"), i18n("Go to Next Snap Point"), this);
953     monitorSeekSnapForward->setShortcut(Qt::ALT + Qt::Key_Right);
954     collection->addAction("monitor_seek_snap_forward", monitorSeekSnapForward);
955     connect(monitorSeekSnapForward, SIGNAL(triggered(bool)), this, SLOT(slotSnapForward()));
956
957     KAction* deleteTimelineClip = new KAction(KIcon("edit-delete"), i18n("Delete Selected Item"), this);
958     deleteTimelineClip->setShortcut(Qt::Key_Delete);
959     collection->addAction("delete_timeline_clip", deleteTimelineClip);
960     connect(deleteTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotDeleteTimelineClip()));
961
962     /*KAction* editTimelineClipSpeed = new KAction(i18n("Change Clip Speed"), this);
963     collection->addAction("change_clip_speed", editTimelineClipSpeed);
964     editTimelineClipSpeed->setData("change_speed");
965     connect(editTimelineClipSpeed, SIGNAL(triggered(bool)), this, SLOT(slotChangeClipSpeed()));*/
966
967     KAction *stickTransition = collection->addAction("auto_transition");
968     stickTransition->setData(QString("auto"));
969     stickTransition->setCheckable(true);
970     stickTransition->setEnabled(false);
971     stickTransition->setText(i18n("Automatic Transition"));
972     connect(stickTransition, SIGNAL(triggered(bool)), this, SLOT(slotAutoTransition()));
973
974     KAction* groupClip = new KAction(KIcon("object-group"), i18n("Group Clips"), this);
975     groupClip->setShortcut(Qt::CTRL + Qt::Key_G);
976     collection->addAction("group_clip", groupClip);
977     connect(groupClip, SIGNAL(triggered(bool)), this, SLOT(slotGroupClips()));
978
979     KAction* ungroupClip = new KAction(KIcon("object-ungroup"), i18n("Ungroup Clips"), this);
980     collection->addAction("ungroup_clip", ungroupClip);
981     ungroupClip->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_G);
982     ungroupClip->setData("ungroup_clip");
983     connect(ungroupClip, SIGNAL(triggered(bool)), this, SLOT(slotUnGroupClips()));
984
985     KAction* cutTimelineClip = new KAction(KIcon("edit-cut"), i18n("Cut Clip"), this);
986     cutTimelineClip->setShortcut(Qt::SHIFT + Qt::Key_R);
987     collection->addAction("cut_timeline_clip", cutTimelineClip);
988     connect(cutTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotCutTimelineClip()));
989
990     KAction* addClipMarker = new KAction(KIcon("bookmark-new"), i18n("Add Marker"), this);
991     collection->addAction("add_clip_marker", addClipMarker);
992     connect(addClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotAddClipMarker()));
993
994     KAction* deleteClipMarker = new KAction(KIcon("edit-delete"), i18n("Delete Marker"), this);
995     collection->addAction("delete_clip_marker", deleteClipMarker);
996     connect(deleteClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotDeleteClipMarker()));
997
998     KAction* deleteAllClipMarkers = new KAction(KIcon("edit-delete"), i18n("Delete All Markers"), this);
999     collection->addAction("delete_all_clip_markers", deleteAllClipMarkers);
1000     connect(deleteAllClipMarkers, SIGNAL(triggered(bool)), this, SLOT(slotDeleteAllClipMarkers()));
1001
1002     KAction* editClipMarker = new KAction(KIcon("document-properties"), i18n("Edit Marker"), this);
1003     collection->addAction("edit_clip_marker", editClipMarker);
1004     connect(editClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotEditClipMarker()));
1005
1006     KAction* splitAudio = new KAction(KIcon("document-new"), i18n("Split Audio"), this);
1007     collection->addAction("split_audio", splitAudio);
1008     connect(splitAudio, SIGNAL(triggered(bool)), this, SLOT(slotSplitAudio()));
1009
1010     KAction* audioOnly = new KAction(KIcon("document-new"), i18n("Audio Only"), this);
1011     collection->addAction("clip_audio_only", audioOnly);
1012     audioOnly->setData("clip_audio_only");
1013     audioOnly->setCheckable(true);
1014
1015     KAction* videoOnly = new KAction(KIcon("document-new"), i18n("Video Only"), this);
1016     collection->addAction("clip_video_only", videoOnly);
1017     videoOnly->setData("clip_video_only");
1018     videoOnly->setCheckable(true);
1019
1020     KAction* audioAndVideo = new KAction(KIcon("document-new"), i18n("Audio and Video"), this);
1021     collection->addAction("clip_audio_and_video", audioAndVideo);
1022     audioAndVideo->setData("clip_audio_and_video");
1023     audioAndVideo->setCheckable(true);
1024
1025     m_clipTypeGroup = new QActionGroup(this);
1026     m_clipTypeGroup->addAction(audioOnly);
1027     m_clipTypeGroup->addAction(videoOnly);
1028     m_clipTypeGroup->addAction(audioAndVideo);
1029     connect(m_clipTypeGroup, SIGNAL(triggered(QAction *)), this, SLOT(slotUpdateClipType(QAction *)));
1030     m_clipTypeGroup->setEnabled(false);
1031
1032     KAction *insertSpace = new KAction(KIcon(), i18n("Insert Space"), this);
1033     collection->addAction("insert_space", insertSpace);
1034     connect(insertSpace, SIGNAL(triggered()), this, SLOT(slotInsertSpace()));
1035
1036     KAction *removeSpace = new KAction(KIcon(), i18n("Remove Space"), this);
1037     collection->addAction("delete_space", removeSpace);
1038     connect(removeSpace, SIGNAL(triggered()), this, SLOT(slotRemoveSpace()));
1039
1040     KAction *insertTrack = new KAction(KIcon(), i18n("Insert Track"), this);
1041     collection->addAction("insert_track", insertTrack);
1042     connect(insertTrack, SIGNAL(triggered()), this, SLOT(slotInsertTrack()));
1043
1044     KAction *deleteTrack = new KAction(KIcon(), i18n("Delete Track"), this);
1045     collection->addAction("delete_track", deleteTrack);
1046     connect(deleteTrack, SIGNAL(triggered()), this, SLOT(slotDeleteTrack()));
1047
1048     KAction *changeTrack = new KAction(KIcon(), i18n("Change Track"), this);
1049     collection->addAction("change_track", changeTrack);
1050     connect(changeTrack, SIGNAL(triggered()), this, SLOT(slotChangeTrack()));
1051
1052     KAction *addGuide = new KAction(KIcon("document-new"), i18n("Add Guide"), this);
1053     collection->addAction("add_guide", addGuide);
1054     connect(addGuide, SIGNAL(triggered()), this, SLOT(slotAddGuide()));
1055
1056     QAction *delGuide = new KAction(KIcon("edit-delete"), i18n("Delete Guide"), this);
1057     collection->addAction("delete_guide", delGuide);
1058     connect(delGuide, SIGNAL(triggered()), this, SLOT(slotDeleteGuide()));
1059
1060     QAction *editGuide = new KAction(KIcon("document-properties"), i18n("Edit Guide"), this);
1061     collection->addAction("edit_guide", editGuide);
1062     connect(editGuide, SIGNAL(triggered()), this, SLOT(slotEditGuide()));
1063
1064     QAction *delAllGuides = new KAction(KIcon("edit-delete"), i18n("Delete All Guides"), this);
1065     collection->addAction("delete_all_guides", delAllGuides);
1066     connect(delAllGuides, SIGNAL(triggered()), this, SLOT(slotDeleteAllGuides()));
1067
1068     QAction *pasteEffects = new KAction(KIcon("edit-paste"), i18n("Paste Effects"), this);
1069     collection->addAction("paste_effects", pasteEffects);
1070     pasteEffects->setData("paste_effects");
1071     connect(pasteEffects , SIGNAL(triggered()), this, SLOT(slotPasteEffects()));
1072
1073     QAction *showTimeline = new KAction(i18n("Show Timeline"), this);
1074     collection->addAction("show_timeline", showTimeline);
1075     showTimeline->setCheckable(true);
1076     showTimeline->setChecked(true);
1077     connect(showTimeline, SIGNAL(triggered(bool)), this, SLOT(slotShowTimeline(bool)));
1078
1079     /*QAction *maxCurrent = new KAction(i18n("Maximize Current Widget"), this);
1080     collection->addAction("maximize_current", maxCurrent);
1081     maxCurrent->setCheckable(true);
1082     maxCurrent->setChecked(false);
1083     connect(maxCurrent, SIGNAL(triggered(bool)), this, SLOT(slotMaximizeCurrent(bool)));*/
1084
1085
1086     m_closeAction = KStandardAction::close(this, SLOT(closeCurrentDocument()), collection);
1087
1088     KStandardAction::quit(this, SLOT(queryQuit()), collection);
1089
1090     KStandardAction::open(this, SLOT(openFile()), collection);
1091
1092     m_saveAction = KStandardAction::save(this, SLOT(saveFile()), collection);
1093
1094     KStandardAction::saveAs(this, SLOT(saveFileAs()), collection);
1095
1096     KStandardAction::openNew(this, SLOT(newFile()), collection);
1097
1098     KStandardAction::preferences(this, SLOT(slotPreferences()), collection);
1099
1100     KStandardAction::configureNotifications(this , SLOT(configureNotifications()), collection);
1101
1102     KStandardAction::copy(this, SLOT(slotCopy()), collection);
1103
1104     KStandardAction::paste(this, SLOT(slotPaste()), collection);
1105
1106     KAction *undo = KStandardAction::undo(m_commandStack, SLOT(undo()), collection);
1107     undo->setEnabled(false);
1108     connect(m_commandStack, SIGNAL(canUndoChanged(bool)), undo, SLOT(setEnabled(bool)));
1109
1110     KAction *redo = KStandardAction::redo(m_commandStack, SLOT(redo()), collection);
1111     redo->setEnabled(false);
1112     connect(m_commandStack, SIGNAL(canRedoChanged(bool)), redo, SLOT(setEnabled(bool)));
1113
1114     KStandardAction::fullScreen(this, SLOT(slotFullScreen()), this, collection);
1115
1116     /*
1117     //TODO: Add status tooltip to actions ?
1118     connect(collection, SIGNAL(actionHovered(QAction*)),
1119             this, SLOT(slotDisplayActionMessage(QAction*)));*/
1120
1121
1122     QAction *addClip = new KAction(KIcon("kdenlive-add-clip"), i18n("Add Clip"), this);
1123     collection->addAction("add_clip", addClip);
1124     connect(addClip , SIGNAL(triggered()), m_projectList, SLOT(slotAddClip()));
1125
1126     QAction *addColorClip = new KAction(KIcon("kdenlive-add-color-clip"), i18n("Add Color Clip"), this);
1127     collection->addAction("add_color_clip", addColorClip);
1128     connect(addColorClip , SIGNAL(triggered()), m_projectList, SLOT(slotAddColorClip()));
1129
1130     QAction *addSlideClip = new KAction(KIcon("kdenlive-add-slide-clip"), i18n("Add Slideshow Clip"), this);
1131     collection->addAction("add_slide_clip", addSlideClip);
1132     connect(addSlideClip , SIGNAL(triggered()), m_projectList, SLOT(slotAddSlideshowClip()));
1133
1134     QAction *addTitleClip = new KAction(KIcon("kdenlive-add-text-clip"), i18n("Add Title Clip"), this);
1135     collection->addAction("add_text_clip", addTitleClip);
1136     connect(addTitleClip , SIGNAL(triggered()), m_projectList, SLOT(slotAddTitleClip()));
1137
1138     QAction *addTitleTemplateClip = new KAction(KIcon("kdenlive-add-text-clip"), i18n("Add Template Title"), this);
1139     collection->addAction("add_text_template_clip", addTitleTemplateClip);
1140     connect(addTitleTemplateClip , SIGNAL(triggered()), m_projectList, SLOT(slotAddTitleTemplateClip()));
1141
1142     QAction *addFolderButton = new KAction(KIcon("folder-new"), i18n("Create Folder"), this);
1143     collection->addAction("add_folder", addFolderButton);
1144     connect(addFolderButton , SIGNAL(triggered()), m_projectList, SLOT(slotAddFolder()));
1145
1146     QAction *clipProperties = new KAction(KIcon("document-edit"), i18n("Clip Properties"), this);
1147     collection->addAction("clip_properties", clipProperties);
1148     clipProperties->setData("clip_properties");
1149     connect(clipProperties , SIGNAL(triggered()), m_projectList, SLOT(slotEditClip()));
1150     clipProperties->setEnabled(false);
1151
1152     QAction *openClip = new KAction(KIcon("document-open"), i18n("Edit Clip"), this);
1153     collection->addAction("edit_clip", openClip);
1154     openClip->setData("edit_clip");
1155     connect(openClip , SIGNAL(triggered()), m_projectList, SLOT(slotOpenClip()));
1156     openClip->setEnabled(false);
1157
1158     QAction *deleteClip = new KAction(KIcon("edit-delete"), i18n("Delete Clip"), this);
1159     collection->addAction("delete_clip", deleteClip);
1160     deleteClip->setData("delete_clip");
1161     connect(deleteClip , SIGNAL(triggered()), m_projectList, SLOT(slotRemoveClip()));
1162     deleteClip->setEnabled(false);
1163
1164     QAction *reloadClip = new KAction(KIcon("view-refresh"), i18n("Reload Clip"), this);
1165     collection->addAction("reload_clip", reloadClip);
1166     reloadClip->setData("reload_clip");
1167     connect(reloadClip , SIGNAL(triggered()), m_projectList, SLOT(slotReloadClip()));
1168     reloadClip->setEnabled(false);
1169
1170     QMenu *addClips = new QMenu();
1171     addClips->addAction(addClip);
1172     addClips->addAction(addColorClip);
1173     addClips->addAction(addSlideClip);
1174     addClips->addAction(addTitleClip);
1175     addClips->addAction(addTitleTemplateClip);
1176     addClips->addAction(addFolderButton);
1177
1178     addClips->addAction(reloadClip);
1179     addClips->addAction(clipProperties);
1180     addClips->addAction(openClip);
1181     addClips->addAction(deleteClip);
1182     m_projectList->setupMenu(addClips, addClip);
1183
1184     //connect(collection, SIGNAL( clearStatusText() ),
1185     //statusBar(), SLOT( clear() ) );
1186 }
1187
1188 void MainWindow::slotDisplayActionMessage(QAction *a)
1189 {
1190     statusBar()->showMessage(a->data().toString(), 3000);
1191 }
1192
1193 void MainWindow::saveOptions()
1194 {
1195     KdenliveSettings::self()->writeConfig();
1196     KSharedConfigPtr config = KGlobal::config();
1197     m_fileOpenRecent->saveEntries(KConfigGroup(config, "Recent Files"));
1198     KConfigGroup treecolumns(config, "Project Tree");
1199     treecolumns.writeEntry("columns", m_projectList->headerInfo());
1200     config->sync();
1201 }
1202
1203 void MainWindow::readOptions()
1204 {
1205     KSharedConfigPtr config = KGlobal::config();
1206     m_fileOpenRecent->loadEntries(KConfigGroup(config, "Recent Files"));
1207     KConfigGroup initialGroup(config, "version");
1208     bool upgrade = false;
1209     if (initialGroup.exists()) {
1210         if (initialGroup.readEntry("version", QString()).section(' ', 0, 0) != QString(version).section(' ', 0, 0)) {
1211             upgrade = true;
1212         }
1213
1214         if (initialGroup.readEntry("version") == "0.7") {
1215             //Add new settings from 0.7.1
1216             if (KdenliveSettings::defaultprojectfolder().isEmpty()) {
1217                 QString path = QDir::homePath() + "/kdenlive";
1218                 if (KStandardDirs::makeDir(path)  == false) {
1219                     kDebug() << "/// ERROR CREATING PROJECT FOLDER: " << path;
1220                 } else KdenliveSettings::setDefaultprojectfolder(path);
1221             }
1222         }
1223
1224     }
1225
1226     if (!initialGroup.exists() || upgrade) {
1227         // this is our first run, show Wizard
1228         Wizard *w = new Wizard(upgrade, this);
1229         if (w->exec() == QDialog::Accepted && w->isOk()) {
1230             w->adjustSettings();
1231             initialGroup.writeEntry("version", version);
1232             delete w;
1233         } else {
1234             ::exit(1);
1235         }
1236     }
1237     KConfigGroup treecolumns(config, "Project Tree");
1238     const QByteArray state = treecolumns.readEntry("columns", QByteArray());
1239     if (!state.isEmpty())
1240         m_projectList->setHeaderInfo(state);
1241 }
1242
1243 void MainWindow::slotRunWizard()
1244 {
1245     Wizard *w = new Wizard(false, this);
1246     if (w->exec() == QDialog::Accepted && w->isOk()) {
1247         w->adjustSettings();
1248     }
1249     delete w;
1250 }
1251
1252 void MainWindow::newFile(bool showProjectSettings)
1253 {
1254     if (!m_timelineArea->isEnabled()) return;
1255     QString profileName;
1256     KUrl projectFolder;
1257     QPoint projectTracks(KdenliveSettings::videotracks(), KdenliveSettings::audiotracks());
1258     if (!showProjectSettings && m_timelineArea->count() == 0) {
1259         if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
1260         profileName = KdenliveSettings::default_profile();
1261         projectFolder = KdenliveSettings::defaultprojectfolder();
1262     } else {
1263         ProjectSettings *w = new ProjectSettings(projectTracks.x(), projectTracks.y(), KdenliveSettings::defaultprojectfolder(), false, this);
1264         if (w->exec() != QDialog::Accepted) return;
1265         if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
1266         KdenliveSettings::setVideothumbnails(w->enableVideoThumbs());
1267         m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
1268         KdenliveSettings::setAudiothumbnails(w->enableAudioThumbs());
1269         m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
1270         profileName = w->selectedProfile();
1271         projectFolder = w->selectedFolder();
1272         projectTracks = w->tracks();
1273         delete w;
1274     }
1275     KdenliveDoc *doc = new KdenliveDoc(KUrl(), projectFolder, m_commandStack, profileName, projectTracks, m_projectMonitor->render, this);
1276     doc->m_autosave = new KAutoSaveFile(KUrl(), doc);
1277     bool ok;
1278     TrackView *trackView = new TrackView(doc, &ok, this);
1279     m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description());
1280     if (!ok) {
1281         // MLT is broken
1282         m_timelineArea->setEnabled(false);
1283         m_projectList->setEnabled(false);
1284         m_monitorManager->slotBlockMonitors();
1285         slotPreferences(6);
1286         return;
1287     }
1288     if (m_timelineArea->count() == 1) {
1289         connectDocumentInfo(doc);
1290         connectDocument(trackView, doc);
1291     } else m_timelineArea->setTabBarHidden(false);
1292     m_closeAction->setEnabled(m_timelineArea->count() > 1);
1293 }
1294
1295 void MainWindow::activateDocument()
1296 {
1297     if (m_timelineArea->currentWidget() == NULL || !m_timelineArea->isEnabled()) return;
1298     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
1299     KdenliveDoc *currentDoc = currentTab->document();
1300     connectDocumentInfo(currentDoc);
1301     connectDocument(currentTab, currentDoc);
1302 }
1303
1304 void MainWindow::closeCurrentDocument()
1305 {
1306     QWidget *w = m_timelineArea->currentWidget();
1307     if (!w) return;
1308     // closing current document
1309     int ix = m_timelineArea->currentIndex() + 1;
1310     if (ix == m_timelineArea->count()) ix = 0;
1311     m_timelineArea->setCurrentIndex(ix);
1312     TrackView *tabToClose = (TrackView *) w;
1313     KdenliveDoc *docToClose = tabToClose->document();
1314     if (docToClose && docToClose->isModified()) {
1315         switch (KMessageBox::warningYesNoCancel(this, i18n("Save changes to document?"))) {
1316         case KMessageBox::Yes :
1317             // save document here. If saving fails, return false;
1318             if (saveFile() == false) return;
1319             break;
1320         case KMessageBox::Cancel :
1321             return;
1322             break;
1323         default:
1324             break;
1325         }
1326     }
1327     m_timelineArea->removeTab(m_timelineArea->indexOf(w));
1328     if (m_timelineArea->count() == 1) {
1329         m_timelineArea->setTabBarHidden(true);
1330         m_closeAction->setEnabled(false);
1331     }
1332     if (docToClose == m_activeDocument) {
1333         delete m_activeDocument;
1334         m_activeDocument = NULL;
1335         m_effectStack->clear();
1336         m_transitionConfig->slotTransitionItemSelected(NULL, 0, QPoint(), false);
1337     } else delete docToClose;
1338     if (w == m_activeTimeline) {
1339         delete m_activeTimeline;
1340         m_activeTimeline = NULL;
1341     } else delete w;
1342 }
1343
1344 bool MainWindow::saveFileAs(const QString &outputFileName)
1345 {
1346     QString currentSceneList;
1347     if (KdenliveSettings::dropbframes()) {
1348         KdenliveSettings::setDropbframes(false);
1349         m_activeDocument->clipManager()->updatePreviewSettings();
1350         currentSceneList = m_projectMonitor->sceneList();
1351         KdenliveSettings::setDropbframes(true);
1352         m_activeDocument->clipManager()->updatePreviewSettings();
1353     } else currentSceneList = m_projectMonitor->sceneList();
1354
1355     if (m_activeDocument->saveSceneList(outputFileName, currentSceneList) == false)
1356         return false;
1357
1358     // Save timeline thumbnails
1359     m_activeTimeline->projectView()->saveThumbnails();
1360     m_activeDocument->setUrl(KUrl(outputFileName));
1361     if (m_activeDocument->m_autosave == NULL) {
1362         m_activeDocument->m_autosave = new KAutoSaveFile(KUrl(outputFileName), this);
1363     } else m_activeDocument->m_autosave->setManagedFile(KUrl(outputFileName));
1364     setCaption(m_activeDocument->description());
1365     m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
1366     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), m_activeDocument->url().path());
1367     m_activeDocument->setModified(false);
1368     m_fileOpenRecent->addUrl(KUrl(outputFileName));
1369     return true;
1370 }
1371
1372 bool MainWindow::saveFileAs()
1373 {
1374     // Check that the Kdenlive mime type is correctly installed
1375     QString mimetype = "application/x-kdenlive";
1376     KMimeType::Ptr mime = KMimeType::mimeType(mimetype);
1377     if (!mime) mimetype = "*.kdenlive";
1378
1379     QString outputFile = KFileDialog::getSaveFileName(KUrl(), mimetype);
1380     if (outputFile.isEmpty()) return false;
1381     if (QFile::exists(outputFile)) {
1382         if (KMessageBox::questionYesNo(this, i18n("File already exists.\nDo you want to overwrite it?")) == KMessageBox::No) return false;
1383     }
1384     return saveFileAs(outputFile);
1385 }
1386
1387 bool MainWindow::saveFile()
1388 {
1389     if (!m_activeDocument) return true;
1390     if (m_activeDocument->url().isEmpty()) {
1391         return saveFileAs();
1392     } else {
1393         bool result = saveFileAs(m_activeDocument->url().path());
1394         m_activeDocument->m_autosave->resize(0);
1395         return result;
1396     }
1397 }
1398
1399 void MainWindow::openFile()
1400 {
1401     // Check that the Kdenlive mime type is correctly installed
1402     QString mimetype = "application/x-kdenlive";
1403     KMimeType::Ptr mime = KMimeType::mimeType(mimetype);
1404     if (!mime) mimetype = "*.kdenlive";
1405
1406     KUrl url = KFileDialog::getOpenUrl(KUrl("kfiledialog:///projectfolder"), mimetype);
1407     if (url.isEmpty()) return;
1408     m_fileOpenRecent->addUrl(url);
1409     openFile(url);
1410 }
1411
1412 void MainWindow::openLastFile()
1413 {
1414     KSharedConfigPtr config = KGlobal::config();
1415     KUrl::List urls = m_fileOpenRecent->urls();
1416     //WARNING: this is buggy, we get a random url, not the last one. Bug in KRecentFileAction?
1417     if (urls.isEmpty()) newFile(false);
1418     else openFile(urls.last());
1419 }
1420
1421 void MainWindow::openFile(const KUrl &url)
1422 {
1423     // Check if the document is already opened
1424     const int ct = m_timelineArea->count();
1425     bool isOpened = false;
1426     int i;
1427     for (i = 0; i < ct; i++) {
1428         TrackView *tab = (TrackView *) m_timelineArea->widget(i);
1429         KdenliveDoc *doc = tab->document();
1430         if (doc->url() == url) {
1431             isOpened = true;
1432             break;
1433         }
1434     }
1435     if (isOpened) {
1436         m_timelineArea->setCurrentIndex(i);
1437         return;
1438     }
1439
1440     // Check for backup file
1441     QList<KAutoSaveFile *> staleFiles = KAutoSaveFile::staleFiles(url);
1442     if (!staleFiles.isEmpty()) {
1443         if (KMessageBox::questionYesNo(this,
1444                                        i18n("Auto-saved files exist. Do you want to recover them now?"),
1445                                        i18n("File Recovery"),
1446                                        KGuiItem(i18n("Recover")), KGuiItem(i18n("Don't recover"))) == KMessageBox::Yes) {
1447             recoverFiles(staleFiles);
1448             return;
1449         } else {
1450             // remove the stale files
1451             foreach(KAutoSaveFile *stale, staleFiles) {
1452                 stale->open(QIODevice::ReadWrite);
1453                 delete stale;
1454             }
1455         }
1456     }
1457     if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
1458     doOpenFile(url, NULL);
1459 }
1460
1461 void MainWindow::doOpenFile(const KUrl &url, KAutoSaveFile *stale)
1462 {
1463     if (!m_timelineArea->isEnabled()) return;
1464     KdenliveDoc *doc = new KdenliveDoc(url, KdenliveSettings::defaultprojectfolder(), m_commandStack, KdenliveSettings::default_profile(), QPoint(KdenliveSettings::videotracks(), KdenliveSettings::audiotracks()), m_projectMonitor->render, this);
1465     if (stale == NULL) {
1466         stale = new KAutoSaveFile(url, doc);
1467         doc->m_autosave = stale;
1468     } else {
1469         doc->m_autosave = stale;
1470         doc->setUrl(stale->managedFile());
1471         doc->setModified(true);
1472         stale->setParent(doc);
1473     }
1474     connectDocumentInfo(doc);
1475     bool ok;
1476     TrackView *trackView = new TrackView(doc, &ok, this);
1477     m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description()));
1478     if (!ok) {
1479         m_timelineArea->setEnabled(false);
1480         m_projectList->setEnabled(false);
1481         m_monitorManager->slotBlockMonitors();
1482         slotPreferences(6);
1483         return;
1484     }
1485     m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), doc->url().path());
1486     trackView->setDuration(trackView->duration());
1487     trackView->projectView()->initCursorPos(m_projectMonitor->render->seekPosition().frames(doc->fps()));
1488
1489     if (m_timelineArea->count() > 1) m_timelineArea->setTabBarHidden(false);
1490     slotGotProgressInfo(QString(), -1);
1491     m_clipMonitor->refreshMonitor(true);
1492     m_projectMonitor->adjustRulerSize(trackView->duration());
1493     m_projectMonitor->slotZoneMoved(trackView->inPoint(), trackView->outPoint());
1494 }
1495
1496 void MainWindow::recoverFiles(QList<KAutoSaveFile *> staleFiles)
1497 {
1498     if (!KdenliveSettings::activatetabs()) closeCurrentDocument();
1499     foreach(KAutoSaveFile *stale, staleFiles) {
1500         /*if (!stale->open(QIODevice::QIODevice::ReadOnly)) {
1501                   // show an error message; we could not steal the lockfile
1502                   // maybe another application got to the file before us?
1503                   delete stale;
1504                   continue;
1505         }*/
1506         kDebug() << "// OPENING RECOVERY: " << stale->fileName() << "\nMANAGED: " << stale->managedFile().path();
1507         // the stalefiles also contain ".lock" files so we must ignore them... bug in KAutoSaveFile?
1508         if (!stale->fileName().endsWith(".lock")) doOpenFile(KUrl(stale->fileName()), stale);
1509         else KIO::NetAccess::del(KUrl(stale->fileName()), this);
1510     }
1511 }
1512
1513
1514 void MainWindow::parseProfiles(const QString &mltPath)
1515 {
1516     // kDebug()<<" + + YOUR MLT INSTALL WAS FOUND IN: "<< MLT_PREFIX <<endl;
1517
1518     //KdenliveSettings::setDefaulttmpfolder();
1519     if (!mltPath.isEmpty()) {
1520         KdenliveSettings::setMltpath(mltPath + "/share/mlt/profiles/");
1521         KdenliveSettings::setRendererpath(mltPath + "/bin/melt");
1522     }
1523
1524     if (KdenliveSettings::mltpath().isEmpty()) {
1525         KdenliveSettings::setMltpath(QString(MLT_PREFIX) + QString("/share/mlt/profiles/"));
1526     }
1527     if (KdenliveSettings::rendererpath().isEmpty() || KdenliveSettings::rendererpath().endsWith("inigo")) {
1528         QString meltPath = QString(MLT_PREFIX) + QString("/bin/melt");
1529         if (!QFile::exists(meltPath))
1530             meltPath = KStandardDirs::findExe("melt");
1531         KdenliveSettings::setRendererpath(meltPath);
1532     }
1533     QStringList profilesFilter;
1534     profilesFilter << "*";
1535     QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
1536
1537     if (profilesList.isEmpty()) {
1538         // Cannot find MLT path, try finding melt
1539         QString profilePath = KdenliveSettings::rendererpath();
1540         if (!profilePath.isEmpty()) {
1541             profilePath = profilePath.section('/', 0, -3);
1542             KdenliveSettings::setMltpath(profilePath + "/share/mlt/profiles/");
1543             QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
1544         }
1545
1546         if (profilesList.isEmpty()) {
1547             // Cannot find the MLT profiles, ask for location
1548             KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(KdenliveSettings::mltpath(), i18n("Cannot find your Mlt profiles, please give the path"), this);
1549             getUrl->fileDialog()->setMode(KFile::Directory);
1550             if (getUrl->exec() == QDialog::Rejected) {
1551                 ::exit(0);
1552             }
1553             KUrl mltPath = getUrl->selectedUrl();
1554             delete getUrl;
1555             if (mltPath.isEmpty()) ::exit(0);
1556             KdenliveSettings::setMltpath(mltPath.path(KUrl::AddTrailingSlash));
1557             QStringList profilesList = QDir(KdenliveSettings::mltpath()).entryList(profilesFilter, QDir::Files);
1558         }
1559     }
1560
1561     if (KdenliveSettings::rendererpath().isEmpty()) {
1562         // Cannot find the MLT melt renderer, ask for location
1563         KUrlRequesterDialog *getUrl = new KUrlRequesterDialog(QString(), i18n("Cannot find the melt program required for rendering (part of Mlt)"), this);
1564         if (getUrl->exec() == QDialog::Rejected) {
1565             ::exit(0);
1566         }
1567         KUrl rendererPath = getUrl->selectedUrl();
1568         delete getUrl;
1569         if (rendererPath.isEmpty()) ::exit(0);
1570         KdenliveSettings::setRendererpath(rendererPath.path());
1571     }
1572
1573     kDebug() << "RESULTING MLT PATH: " << KdenliveSettings::mltpath();
1574
1575     // Parse MLT profiles to build a list of available video formats
1576     if (profilesList.isEmpty()) parseProfiles();
1577 }
1578
1579
1580 void MainWindow::slotEditProfiles()
1581 {
1582     ProfilesDialog *w = new ProfilesDialog;
1583     if (w->exec() == QDialog::Accepted) {
1584         KdenliveSettingsDialog* d = static_cast <KdenliveSettingsDialog*>(KConfigDialog::exists("settings"));
1585         if (d) d->checkProfile();
1586     }
1587     delete w;
1588 }
1589
1590 void MainWindow::slotDetectAudioDriver()
1591 {
1592     /* WARNING: do not use this method because sometimes detects wrong driver (pulse instead of alsa),
1593     leading to no audio output, see bug #934 */
1594
1595     //decide which audio driver is really best, in some cases SDL is wrong
1596     if (KdenliveSettings::audiodrivername().isEmpty()) {
1597         QString driver;
1598         KProcess readProcess;
1599         //PulseAudio needs to be selected if it exists, the ALSA pulse pcm device is not fast enough.
1600         if (!KStandardDirs::findExe("pactl").isEmpty()) {
1601             readProcess.setOutputChannelMode(KProcess::OnlyStdoutChannel);
1602             readProcess.setProgram("pactl", QStringList() << "stat");
1603             readProcess.execute(2000); // Kill it after 2 seconds
1604
1605             QString result = QString(readProcess.readAllStandardOutput());
1606             kDebug() << "// / / / / / READING PACTL: ";
1607             kDebug() << result;
1608             if (!result.isEmpty()) {
1609                 driver = "pulse";
1610                 kDebug() << "// / / / / PULSEAUDIO DETECTED";
1611             }
1612         }
1613         //put others here
1614         KdenliveSettings::setAutoaudiodrivername(driver);
1615     }
1616 }
1617
1618 void MainWindow::slotEditProjectSettings()
1619 {
1620     QPoint p = m_activeDocument->getTracksCount();
1621     ProjectSettings *w = new ProjectSettings(p.x(), p.y(), m_activeDocument->projectFolder().path(), true, this);
1622
1623     if (w->exec() == QDialog::Accepted) {
1624         QString profile = w->selectedProfile();
1625         m_activeDocument->setProjectFolder(w->selectedFolder());
1626         if (m_renderWidget) m_renderWidget->setDocumentPath(w->selectedFolder().path(KUrl::AddTrailingSlash));
1627         if (m_activeDocument->profilePath() != profile) {
1628             // Profile was changed
1629             double dar = m_activeDocument->dar();
1630
1631             // Deselect current effect / transition
1632             m_effectStack->slotClipItemSelected(NULL, 0);
1633             m_transitionConfig->slotTransitionItemSelected(NULL, 0, QPoint(), false);
1634             m_clipMonitor->slotSetXml(NULL, 0);
1635             m_activeDocument->setProfilePath(profile);
1636             KdenliveSettings::setCurrent_profile(profile);
1637             KdenliveSettings::setProject_fps(m_activeDocument->fps());
1638             setCaption(m_activeDocument->description(), m_activeDocument->isModified());
1639
1640             m_activeDocument->clipManager()->clearUnusedProducers();
1641             m_monitorManager->resetProfiles(m_activeDocument->timecode());
1642
1643             m_transitionConfig->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode(), m_activeTimeline->tracksNumber());
1644             m_effectStack->updateProjectFormat(m_activeDocument->mltProfile(), m_activeDocument->timecode());
1645             if (m_renderWidget) m_renderWidget->setProfile(m_activeDocument->mltProfile());
1646             m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description());
1647             //m_activeDocument->clipManager()->resetProducersList(m_projectMonitor->render->producersList());
1648             if (dar != m_activeDocument->dar()) m_projectList->reloadClipThumbnails();
1649             m_activeTimeline->updateProjectFps();
1650
1651             // We need to desactivate & reactivate monitors to get a refresh
1652             //m_monitorManager->switchMonitors();
1653         }
1654     }
1655     delete w;
1656 }
1657
1658 void MainWindow::slotRenderProject()
1659 {
1660     if (!m_renderWidget) {
1661         QString projectfolder = m_activeDocument ? m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash) : KdenliveSettings::defaultprojectfolder();
1662         m_renderWidget = new RenderWidget(projectfolder, this);
1663         connect(m_renderWidget, SIGNAL(selectedRenderProfile(const QString &, const QString &, const QString&)), this, SLOT(slotSetDocumentRenderProfile(const QString &, const QString &, const QString&)));
1664         connect(m_renderWidget, SIGNAL(prepareRenderingData(bool, bool, const QString&)), this, SLOT(slotPrepareRendering(bool, bool, const QString&)));
1665         connect(m_renderWidget, SIGNAL(abortProcess(const QString &)), this, SIGNAL(abortRenderJob(const QString &)));
1666         connect(m_renderWidget, SIGNAL(openDvdWizard(const QString &, const QString &)), this, SLOT(slotDvdWizard(const QString &, const QString &)));
1667         if (m_activeDocument) {
1668             m_renderWidget->setProfile(m_activeDocument->mltProfile());
1669             m_renderWidget->setGuides(m_activeDocument->guidesXml(), m_activeDocument->projectDuration());
1670             m_renderWidget->setDocumentPath(m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash));
1671             m_renderWidget->setRenderProfile(m_activeDocument->getDocumentProperty("renderdestination"), m_activeDocument->getDocumentProperty("renderprofile"), m_activeDocument->getDocumentProperty("renderurl"));
1672         }
1673     }
1674     /*TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
1675     if (currentTab) m_renderWidget->setTimeline(currentTab);
1676     m_renderWidget->setDocument(m_activeDocument);*/
1677     m_renderWidget->show();
1678     m_renderWidget->showNormal();
1679 }
1680
1681 void MainWindow::setRenderingProgress(const QString &url, int progress)
1682 {
1683     if (m_renderWidget) m_renderWidget->setRenderJob(url, progress);
1684 }
1685
1686 void MainWindow::setRenderingFinished(const QString &url, int status, const QString &error)
1687 {
1688     if (m_renderWidget) m_renderWidget->setRenderStatus(url, status, error);
1689 }
1690
1691 void MainWindow::slotUpdateMousePosition(int pos)
1692 {
1693     if (m_activeDocument)
1694         switch (m_timecodeFormat->currentIndex()) {
1695         case 0:
1696             statusBar()->changeItem(m_activeDocument->timecode().getTimecodeFromFrames(pos), ID_TIMELINE_POS);
1697             break;
1698         default:
1699             statusBar()->changeItem(QString::number(pos), ID_TIMELINE_POS);
1700         }
1701 }
1702
1703 void MainWindow::slotUpdateDocumentState(bool modified)
1704 {
1705     if (!m_activeDocument) return;
1706     setCaption(m_activeDocument->description(), modified);
1707     m_saveAction->setEnabled(modified);
1708     if (modified) {
1709         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Link));
1710         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("document-save"));
1711     } else {
1712         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Text));
1713         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("kdenlive"));
1714     }
1715 }
1716
1717 void MainWindow::connectDocumentInfo(KdenliveDoc *doc)
1718 {
1719     if (m_activeDocument) {
1720         if (m_activeDocument == doc) return;
1721         disconnect(m_activeDocument, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
1722     }
1723     connect(doc, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
1724 }
1725
1726 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc)   //changed
1727 {
1728     //m_projectMonitor->stop();
1729     m_closeAction->setEnabled(m_timelineArea->count() > 1);
1730     kDebug() << "///////////////////   CONNECTING DOC TO PROJECT VIEW ////////////////";
1731     if (m_activeDocument) {
1732         if (m_activeDocument == doc) return;
1733         if (m_activeTimeline) {
1734             disconnect(m_projectMonitor, SIGNAL(renderPosition(int)), m_activeTimeline, SLOT(moveCursorPos(int)));
1735             disconnect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), m_activeTimeline, SLOT(slotSetZone(QPoint)));
1736             disconnect(m_projectMonitor, SIGNAL(durationChanged(int)), m_activeTimeline, SLOT(setDuration(int)));
1737             disconnect(m_projectList, SIGNAL(projectModified()), m_activeDocument, SLOT(setModified()));
1738             disconnect(m_projectMonitor->render, SIGNAL(refreshDocumentProducers()), m_activeDocument, SLOT(checkProjectClips()));
1739
1740             disconnect(m_activeDocument, SIGNAL(guidesUpdated()), this, SLOT(slotGuidesUpdated()));
1741             disconnect(m_activeDocument, SIGNAL(addProjectClip(DocClipBase *, bool)), m_projectList, SLOT(slotAddClip(DocClipBase *, bool)));
1742             disconnect(m_activeDocument, SIGNAL(resetProjectList()), m_projectList, SLOT(slotResetProjectList()));
1743             disconnect(m_activeDocument, SIGNAL(signalDeleteProjectClip(const QString &)), m_projectList, SLOT(slotDeleteClip(const QString &)));
1744             disconnect(m_activeDocument, SIGNAL(updateClipDisplay(const QString &)), m_projectList, SLOT(slotUpdateClip(const QString &)));
1745             disconnect(m_activeDocument, SIGNAL(selectLastAddedClip(const QString &)), m_projectList, SLOT(slotSelectClip(const QString &)));
1746             disconnect(m_activeDocument, SIGNAL(deleteTimelineClip(const QString &)), m_activeTimeline, SLOT(slotDeleteClip(const QString &)));
1747             disconnect(m_activeTimeline->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), m_effectStack, SLOT(slotClipItemSelected(ClipItem*, int)));
1748             disconnect(m_activeTimeline->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), this, SLOT(slotActivateEffectStackView()));
1749             disconnect(m_activeTimeline->projectView(), SIGNAL(transitionItemSelected(Transition*, int, QPoint, bool)), m_transitionConfig, SLOT(slotTransitionItemSelected(Transition*, int, QPoint, bool)));
1750             disconnect(m_activeTimeline->projectView(), SIGNAL(transitionItemSelected(Transition*, int, QPoint, bool)), this, SLOT(slotActivateTransitionView(Transition *)));
1751             disconnect(m_zoomSlider, SIGNAL(valueChanged(int)), m_activeTimeline, SLOT(slotChangeZoom(int)));
1752             disconnect(m_activeTimeline->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
1753             disconnect(m_activeTimeline->projectView(), SIGNAL(showClipFrame(DocClipBase *, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, const int)));
1754             disconnect(m_activeTimeline, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
1755             disconnect(m_activeTimeline, SIGNAL(insertTrack(int)), this, SLOT(slotInsertTrack(int)));
1756             disconnect(m_activeTimeline, SIGNAL(deleteTrack(int)), this, SLOT(slotDeleteTrack(int)));
1757             disconnect(m_activeTimeline, SIGNAL(changeTrack(int)), this, SLOT(slotChangeTrack(int)));
1758             disconnect(m_activeDocument, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
1759             disconnect(m_effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement, int)), m_activeTimeline->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement, int)));
1760             disconnect(m_effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), m_activeTimeline->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
1761             disconnect(m_effectStack, SIGNAL(changeEffectState(ClipItem*, int, bool)), m_activeTimeline->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, bool)));
1762             disconnect(m_effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), m_activeTimeline->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
1763             disconnect(m_effectStack, SIGNAL(refreshEffectStack(ClipItem*)), m_activeTimeline->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
1764             disconnect(m_effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
1765             disconnect(m_transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), m_activeTimeline->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
1766             disconnect(m_transitionConfig, SIGNAL(seekTimeline(int)), m_activeTimeline->projectView() , SLOT(setCursorPos(int)));
1767             disconnect(m_activeTimeline->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
1768             disconnect(m_activeTimeline, SIGNAL(zoneMoved(int, int)), this, SLOT(slotZoneMoved(int, int)));
1769             disconnect(m_projectList, SIGNAL(loadingIsOver()), m_activeTimeline->projectView(), SLOT(slotUpdateAllThumbs()));
1770             m_effectStack->clear();
1771         }
1772         //m_activeDocument->setRenderer(NULL);
1773         disconnect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
1774         disconnect(m_projectList, SIGNAL(refreshClip()), m_clipMonitor, SLOT(refreshMonitor()));
1775         m_clipMonitor->stop();
1776     }
1777     KdenliveSettings::setCurrent_profile(doc->profilePath());
1778     KdenliveSettings::setProject_fps(doc->fps());
1779     m_monitorManager->resetProfiles(doc->timecode());
1780     m_projectList->setDocument(doc);
1781     m_transitionConfig->updateProjectFormat(doc->mltProfile(), doc->timecode(), trackView->tracksNumber());
1782     m_effectStack->updateProjectFormat(doc->mltProfile(), doc->timecode());
1783     connect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
1784     connect(m_projectList, SIGNAL(refreshClip()), m_clipMonitor, SLOT(refreshMonitor()));
1785     connect(m_projectList, SIGNAL(projectModified()), doc, SLOT(setModified()));
1786     connect(m_projectList, SIGNAL(clipNameChanged(const QString, const QString)), trackView->projectView(), SLOT(clipNameChanged(const QString, const QString)));
1787
1788
1789     connect(trackView, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
1790     connect(trackView, SIGNAL(insertTrack(int)), this, SLOT(slotInsertTrack(int)));
1791     connect(trackView, SIGNAL(deleteTrack(int)), this, SLOT(slotDeleteTrack(int)));
1792     connect(trackView, SIGNAL(changeTrack(int)), this, SLOT(slotChangeTrack(int)));
1793     connect(trackView, SIGNAL(mousePosition(int)), this, SLOT(slotUpdateMousePosition(int)));
1794     connect(m_projectMonitor, SIGNAL(renderPosition(int)), trackView, SLOT(moveCursorPos(int)));
1795     connect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), trackView, SLOT(slotSetZone(QPoint)));
1796     connect(m_projectMonitor, SIGNAL(durationChanged(int)), trackView, SLOT(setDuration(int)));
1797     connect(m_projectMonitor->render, SIGNAL(refreshDocumentProducers()), doc, SLOT(checkProjectClips()));
1798
1799     connect(doc, SIGNAL(addProjectClip(DocClipBase *, bool)), m_projectList, SLOT(slotAddClip(DocClipBase *, bool)));
1800     connect(doc, SIGNAL(resetProjectList()), m_projectList, SLOT(slotResetProjectList()));
1801     connect(doc, SIGNAL(signalDeleteProjectClip(const QString &)), m_projectList, SLOT(slotDeleteClip(const QString &)));
1802     connect(doc, SIGNAL(updateClipDisplay(const QString &)), m_projectList, SLOT(slotUpdateClip(const QString &)));
1803     connect(doc, SIGNAL(selectLastAddedClip(const QString &)), m_projectList, SLOT(slotSelectClip(const QString &)));
1804
1805     connect(doc, SIGNAL(deleteTimelineClip(const QString &)), trackView, SLOT(slotDeleteClip(const QString &)));
1806     connect(doc, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
1807     connect(doc, SIGNAL(guidesUpdated()), this, SLOT(slotGuidesUpdated()));
1808
1809
1810     connect(trackView->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), m_effectStack, SLOT(slotClipItemSelected(ClipItem*, int)));
1811     connect(trackView->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), this, SLOT(slotActivateEffectStackView()));
1812     connect(trackView->projectView(), SIGNAL(transitionItemSelected(Transition*, int, QPoint, bool)), m_transitionConfig, SLOT(slotTransitionItemSelected(Transition*, int, QPoint, bool)));
1813     connect(trackView->projectView(), SIGNAL(transitionItemSelected(Transition*, int, QPoint, bool)), this, SLOT(slotActivateTransitionView(Transition *)));
1814     m_zoomSlider->setValue(doc->zoom().x());
1815     connect(m_zoomSlider, SIGNAL(valueChanged(int)), trackView, SLOT(slotChangeZoom(int)));
1816     connect(trackView->projectView(), SIGNAL(zoomIn()), this, SLOT(slotZoomIn()));
1817     connect(trackView->projectView(), SIGNAL(zoomOut()), this, SLOT(slotZoomOut()));
1818     connect(trackView->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
1819
1820     connect(trackView->projectView(), SIGNAL(showClipFrame(DocClipBase *, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, const int)));
1821
1822
1823     connect(m_effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement, int)), trackView->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement, int)));
1824     connect(m_effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), trackView->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
1825     connect(m_effectStack, SIGNAL(changeEffectState(ClipItem*, int, bool)), trackView->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, bool)));
1826     connect(m_effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), trackView->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
1827     connect(m_effectStack, SIGNAL(refreshEffectStack(ClipItem*)), trackView->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
1828     connect(m_transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
1829     connect(m_transitionConfig, SIGNAL(seekTimeline(int)), trackView->projectView() , SLOT(setCursorPos(int)));
1830     connect(m_effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
1831
1832     connect(trackView->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
1833     connect(trackView, SIGNAL(zoneMoved(int, int)), this, SLOT(slotZoneMoved(int, int)));
1834     connect(m_projectList, SIGNAL(loadingIsOver()), trackView->projectView(), SLOT(slotUpdateAllThumbs()));
1835
1836     trackView->projectView()->setContextMenu(m_timelineContextMenu, m_timelineContextClipMenu, m_timelineContextTransitionMenu, m_clipTypeGroup);
1837     m_activeTimeline = trackView;
1838     if (m_renderWidget) {
1839         m_renderWidget->setProfile(doc->mltProfile());
1840         m_renderWidget->setGuides(doc->guidesXml(), doc->projectDuration());
1841         m_renderWidget->setDocumentPath(doc->projectFolder().path(KUrl::AddTrailingSlash));
1842         m_renderWidget->setRenderProfile(doc->getDocumentProperty("renderdestination"), doc->getDocumentProperty("renderprofile"), doc->getDocumentProperty("renderurl"));
1843     }
1844     //doc->setRenderer(m_projectMonitor->render);
1845     m_commandStack->setActiveStack(doc->commandStack());
1846     KdenliveSettings::setProject_display_ratio(doc->dar());
1847     //doc->clipManager()->checkAudioThumbs();
1848
1849     //m_overView->setScene(trackView->projectScene());
1850     //m_overView->scale(m_overView->width() / trackView->duration(), m_overView->height() / (50 * trackView->tracksNumber()));
1851     //m_overView->fitInView(m_overView->itemAt(0, 50), Qt::KeepAspectRatio);
1852
1853     setCaption(doc->description(), doc->isModified());
1854     m_saveAction->setEnabled(doc->isModified());
1855     m_activeDocument = doc;
1856     m_activeTimeline->updateProjectFps();
1857     m_projectList->updateAllClips();
1858     if (KdenliveSettings::dropbframes()) slotUpdatePreviewSettings();
1859
1860     // set tool to select tool
1861     m_buttonSelectTool->setChecked(true);
1862 }
1863
1864 void MainWindow::slotZoneMoved(int start, int end)
1865 {
1866     m_activeDocument->setZone(start, end);
1867     m_projectMonitor->slotZoneMoved(start, end);
1868 }
1869
1870 void MainWindow::slotGuidesUpdated()
1871 {
1872     if (m_renderWidget) m_renderWidget->setGuides(m_activeDocument->guidesXml(), m_activeDocument->projectDuration());
1873 }
1874
1875 void MainWindow::slotPreferences(int page, int option)
1876 {
1877     //An instance of your dialog could be already created and could be
1878     // cached, in which case you want to display the cached dialog
1879     // instead of creating another one
1880     if (KConfigDialog::showDialog("settings")) {
1881         KdenliveSettingsDialog* d = static_cast <KdenliveSettingsDialog*>(KConfigDialog::exists("settings"));
1882         if (page != -1) d->showPage(page, option);
1883         return;
1884     }
1885
1886     // KConfigDialog didn't find an instance of this dialog, so lets
1887     // create it :
1888     KdenliveSettingsDialog* dialog = new KdenliveSettingsDialog(this);
1889     connect(dialog, SIGNAL(settingsChanged(const QString&)), this, SLOT(updateConfiguration()));
1890     //connect(dialog, SIGNAL(doResetProfile()), this, SLOT(slotDetectAudioDriver()));
1891     connect(dialog, SIGNAL(doResetProfile()), m_monitorManager, SLOT(slotResetProfiles()));
1892     connect(dialog, SIGNAL(updatePreviewSettings()), this, SLOT(slotUpdatePreviewSettings()));
1893     connect(dialog, SIGNAL(updateCaptureFolder()), m_recMonitor, SLOT(slotUpdateCaptureFolder()));
1894     //connect(dialog, SIGNAL(updatePreviewSettings()), this, SLOT(slotUpdatePreviewSettings()));
1895     dialog->show();
1896     if (page != -1) dialog->showPage(page, option);
1897 }
1898
1899 void MainWindow::slotUpdatePreviewSettings()
1900 {
1901     if (m_activeDocument) {
1902         m_clipMonitor->slotSetXml(NULL, 0);
1903         m_activeDocument->updatePreviewSettings();
1904     }
1905 }
1906
1907 void MainWindow::updateConfiguration()
1908 {
1909     //TODO: we should apply settings to all projects, not only the current one
1910     if (m_activeTimeline) {
1911         m_activeTimeline->refresh();
1912         m_activeTimeline->projectView()->checkAutoScroll();
1913         m_activeTimeline->projectView()->checkTrackHeight();
1914         if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
1915     }
1916     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
1917     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
1918
1919     // Update list of transcoding profiles
1920     loadTranscoders();
1921 #ifndef NO_JOGSHUTTLE
1922     activateShuttleDevice();
1923 #endif /* NO_JOGSHUTTLE */
1924
1925 }
1926
1927
1928 void MainWindow::slotSwitchVideoThumbs()
1929 {
1930     KdenliveSettings::setVideothumbnails(!KdenliveSettings::videothumbnails());
1931     if (m_activeTimeline) {
1932         m_activeTimeline->projectView()->slotUpdateAllThumbs();
1933     }
1934     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
1935 }
1936
1937 void MainWindow::slotSwitchAudioThumbs()
1938 {
1939     KdenliveSettings::setAudiothumbnails(!KdenliveSettings::audiothumbnails());
1940     if (m_activeTimeline) {
1941         m_activeTimeline->refresh();
1942         m_activeTimeline->projectView()->checkAutoScroll();
1943         if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
1944     }
1945     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
1946 }
1947
1948 void MainWindow::slotSwitchMarkersComments()
1949 {
1950     KdenliveSettings::setShowmarkers(!KdenliveSettings::showmarkers());
1951     if (m_activeTimeline) {
1952         m_activeTimeline->refresh();
1953     }
1954     m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
1955 }
1956
1957 void MainWindow::slotSwitchSnap()
1958 {
1959     KdenliveSettings::setSnaptopoints(!KdenliveSettings::snaptopoints());
1960     m_buttonSnap->setChecked(KdenliveSettings::snaptopoints());
1961 }
1962
1963
1964 void MainWindow::slotDeleteTimelineClip()
1965 {
1966     if (QApplication::focusWidget()->parentWidget()->parentWidget() == m_projectListDock) m_projectList->slotRemoveClip();
1967     else if (m_activeTimeline) {
1968         m_activeTimeline->projectView()->deleteSelectedClips();
1969     }
1970 }
1971
1972 void MainWindow::slotAddClipMarker()
1973 {
1974     DocClipBase *clip = NULL;
1975     GenTime pos;
1976     if (m_projectMonitor->isActive()) {
1977         if (m_activeTimeline) {
1978             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
1979             if (item) {
1980                 pos = (m_projectMonitor->position() - item->startPos() + item->cropStart()) / item->speed();
1981                 clip = item->baseClip();
1982             }
1983         }
1984     } else {
1985         clip = m_clipMonitor->activeClip();
1986         pos = m_clipMonitor->position();
1987     }
1988     if (!clip) {
1989         m_messageLabel->setMessage(i18n("Cannot find clip to add marker"), ErrorMessage);
1990         return;
1991     }
1992     QString id = clip->getId();
1993     CommentedTime marker(pos, i18n("Marker"));
1994     MarkerDialog d(clip, marker, m_activeDocument->timecode(), i18n("Add Marker"), this);
1995     if (d.exec() == QDialog::Accepted) {
1996         m_activeTimeline->projectView()->slotAddClipMarker(id, d.newMarker().time(), d.newMarker().comment());
1997     }
1998     if (m_clipMonitor->isActive()) m_clipMonitor->checkOverlay();
1999 }
2000
2001 void MainWindow::slotDeleteClipMarker()
2002 {
2003     DocClipBase *clip = NULL;
2004     GenTime pos;
2005     if (m_projectMonitor->isActive()) {
2006         if (m_activeTimeline) {
2007             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
2008             if (item) {
2009                 pos = (m_projectMonitor->position() - item->startPos() + item->cropStart()) / item->speed();
2010                 clip = item->baseClip();
2011             }
2012         }
2013     } else {
2014         clip = m_clipMonitor->activeClip();
2015         pos = m_clipMonitor->position();
2016     }
2017     if (!clip) {
2018         m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
2019         return;
2020     }
2021
2022     QString id = clip->getId();
2023     QString comment = clip->markerComment(pos);
2024     if (comment.isEmpty()) {
2025         m_messageLabel->setMessage(i18n("No marker found at cursor time"), ErrorMessage);
2026         return;
2027     }
2028     m_activeTimeline->projectView()->slotDeleteClipMarker(comment, id, pos);
2029     if (m_clipMonitor->isActive()) m_clipMonitor->checkOverlay();
2030
2031 }
2032
2033 void MainWindow::slotDeleteAllClipMarkers()
2034 {
2035     DocClipBase *clip = NULL;
2036     if (m_projectMonitor->isActive()) {
2037         if (m_activeTimeline) {
2038             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
2039             if (item) {
2040                 clip = item->baseClip();
2041             }
2042         }
2043     } else {
2044         clip = m_clipMonitor->activeClip();
2045     }
2046     if (!clip) {
2047         m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
2048         return;
2049     }
2050     m_activeTimeline->projectView()->slotDeleteAllClipMarkers(clip->getId());
2051     if (m_clipMonitor->isActive()) m_clipMonitor->checkOverlay();
2052 }
2053
2054 void MainWindow::slotEditClipMarker()
2055 {
2056     DocClipBase *clip = NULL;
2057     GenTime pos;
2058     if (m_projectMonitor->isActive()) {
2059         if (m_activeTimeline) {
2060             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
2061             if (item) {
2062                 pos = (m_projectMonitor->position() - item->startPos() + item->cropStart()) / item->speed();
2063                 clip = item->baseClip();
2064             }
2065         }
2066     } else {
2067         clip = m_clipMonitor->activeClip();
2068         pos = m_clipMonitor->position();
2069     }
2070     if (!clip) {
2071         m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
2072         return;
2073     }
2074
2075     QString id = clip->getId();
2076     QString oldcomment = clip->markerComment(pos);
2077     if (oldcomment.isEmpty()) {
2078         m_messageLabel->setMessage(i18n("No marker found at cursor time"), ErrorMessage);
2079         return;
2080     }
2081
2082     CommentedTime marker(pos, oldcomment);
2083     MarkerDialog d(clip, marker, m_activeDocument->timecode(), i18n("Edit Marker"), this);
2084     if (d.exec() == QDialog::Accepted) {
2085         m_activeTimeline->projectView()->slotAddClipMarker(id, d.newMarker().time(), d.newMarker().comment());
2086         if (d.newMarker().time() != pos) {
2087             // remove old marker
2088             m_activeTimeline->projectView()->slotAddClipMarker(id, pos, QString());
2089         }
2090         if (m_clipMonitor->isActive()) m_clipMonitor->checkOverlay();
2091     }
2092 }
2093
2094 void MainWindow::slotAddGuide()
2095 {
2096     if (m_activeTimeline)
2097         m_activeTimeline->projectView()->slotAddGuide();
2098 }
2099
2100 void MainWindow::slotInsertSpace()
2101 {
2102     if (m_activeTimeline)
2103         m_activeTimeline->projectView()->slotInsertSpace();
2104 }
2105
2106 void MainWindow::slotRemoveSpace()
2107 {
2108     if (m_activeTimeline)
2109         m_activeTimeline->projectView()->slotRemoveSpace();
2110 }
2111
2112 void MainWindow::slotInsertTrack(int ix)
2113 {
2114     m_projectMonitor->activateMonitor();
2115     if (m_activeTimeline)
2116         m_activeTimeline->projectView()->slotInsertTrack(ix);
2117 }
2118
2119 void MainWindow::slotDeleteTrack(int ix)
2120 {
2121     m_projectMonitor->activateMonitor();
2122     if (m_activeTimeline)
2123         m_activeTimeline->projectView()->slotDeleteTrack(ix);
2124 }
2125
2126 void MainWindow::slotChangeTrack(int ix)
2127 {
2128     m_projectMonitor->activateMonitor();
2129     if (m_activeTimeline)
2130         m_activeTimeline->projectView()->slotChangeTrack(ix);
2131 }
2132
2133 void MainWindow::slotEditGuide()
2134 {
2135     if (m_activeTimeline)
2136         m_activeTimeline->projectView()->slotEditGuide();
2137 }
2138
2139 void MainWindow::slotDeleteGuide()
2140 {
2141     if (m_activeTimeline)
2142         m_activeTimeline->projectView()->slotDeleteGuide();
2143 }
2144
2145 void MainWindow::slotDeleteAllGuides()
2146 {
2147     if (m_activeTimeline)
2148         m_activeTimeline->projectView()->slotDeleteAllGuides();
2149 }
2150
2151 void MainWindow::slotCutTimelineClip()
2152 {
2153     if (m_activeTimeline) {
2154         m_activeTimeline->projectView()->cutSelectedClips();
2155     }
2156 }
2157
2158 void MainWindow::slotGroupClips()
2159 {
2160     if (m_activeTimeline) {
2161         m_activeTimeline->projectView()->groupClips();
2162     }
2163 }
2164
2165 void MainWindow::slotUnGroupClips()
2166 {
2167     if (m_activeTimeline) {
2168         m_activeTimeline->projectView()->groupClips(false);
2169     }
2170 }
2171
2172 void MainWindow::slotAddProjectClip(KUrl url)
2173 {
2174     if (m_activeDocument)
2175         m_activeDocument->slotAddClipFile(url, QString());
2176 }
2177
2178 void MainWindow::slotAddTransition(QAction *result)
2179 {
2180     if (!result) return;
2181     QStringList info = result->data().toStringList();
2182     if (info.isEmpty()) return;
2183     QDomElement transition = transitions.getEffectByTag(info.at(1), info.at(2));
2184     if (m_activeTimeline && !transition.isNull()) {
2185         m_activeTimeline->projectView()->slotAddTransitionToSelectedClips(transition.cloneNode().toElement());
2186     }
2187 }
2188
2189 void MainWindow::slotAddVideoEffect(QAction *result)
2190 {
2191     if (!result) return;
2192     QStringList info = result->data().toStringList();
2193     if (info.isEmpty()) return;
2194     QDomElement effect = videoEffects.getEffectByTag(info.at(1), info.at(2));
2195     slotAddEffect(effect);
2196 }
2197
2198 void MainWindow::slotAddAudioEffect(QAction *result)
2199 {
2200     if (!result) return;
2201     QStringList info = result->data().toStringList();
2202     if (info.isEmpty()) return;
2203     QDomElement effect = audioEffects.getEffectByTag(info.at(1), info.at(2));
2204     slotAddEffect(effect);
2205 }
2206
2207 void MainWindow::slotAddCustomEffect(QAction *result)
2208 {
2209     if (!result) return;
2210     QStringList info = result->data().toStringList();
2211     if (info.isEmpty()) return;
2212     QDomElement effect = customEffects.getEffectByTag(info.at(1), info.at(2));
2213     slotAddEffect(effect);
2214 }
2215
2216 void MainWindow::slotZoomIn()
2217 {
2218     m_zoomSlider->setValue(m_zoomSlider->value() - 1);
2219 }
2220
2221 void MainWindow::slotZoomOut()
2222 {
2223     m_zoomSlider->setValue(m_zoomSlider->value() + 1);
2224 }
2225
2226 void MainWindow::slotFitZoom()
2227 {
2228     if (m_activeTimeline) {
2229         m_zoomSlider->setValue(m_activeTimeline->fitZoom());
2230     }
2231 }
2232
2233 void MainWindow::slotGotProgressInfo(const QString &message, int progress)
2234 {
2235     m_statusProgressBar->setValue(progress);
2236     if (progress >= 0) {
2237         if (!message.isEmpty()) m_messageLabel->setMessage(message, InformationMessage);//statusLabel->setText(message);
2238         m_statusProgressBar->setVisible(true);
2239     } else {
2240         m_messageLabel->setMessage(QString(), DefaultMessage);
2241         m_statusProgressBar->setVisible(false);
2242     }
2243 }
2244
2245 void MainWindow::slotShowClipProperties(DocClipBase *clip)
2246 {
2247     if (clip->clipType() == TEXT) {
2248         QString titlepath = m_activeDocument->projectFolder().path(KUrl::AddTrailingSlash) + "titles/";
2249         if (!clip->getProperty("xmltemplate").isEmpty()) {
2250             // template text clip
2251
2252             // Get the list of existing templates
2253             QStringList filter;
2254             filter << "*.kdenlivetitle";
2255             QStringList templateFiles = QDir(titlepath).entryList(filter, QDir::Files);
2256
2257             QDialog *dia = new QDialog(this);
2258             Ui::TemplateClip_UI dia_ui;
2259             dia_ui.setupUi(dia);
2260             int ix = -1;
2261             const QString templatePath = clip->getProperty("xmltemplate");
2262             for (int i = 0; i < templateFiles.size(); ++i) {
2263                 dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), titlepath + templateFiles.at(i));
2264                 if (templatePath == KUrl(titlepath + templateFiles.at(i)).path()) ix = i;
2265             }
2266             if (ix != -1) dia_ui.template_list->comboBox()->setCurrentIndex(ix);
2267             else dia_ui.template_list->comboBox()->insertItem(0, templatePath);
2268             dia_ui.template_list->fileDialog()->setFilter("*.kdenlivetitle");
2269             //warning: setting base directory doesn't work??
2270             KUrl startDir(titlepath);
2271             dia_ui.template_list->fileDialog()->setUrl(startDir);
2272             dia_ui.description->setText(clip->getProperty("description"));
2273             dia_ui.clone_clip->setChecked(true);
2274             if (dia->exec() == QDialog::Accepted) {
2275                 QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString();
2276                 if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText();
2277
2278                 QMap <QString, QString> newprops;
2279
2280                 if (KUrl(textTemplate).path() != templatePath) {
2281                     // The template was changed
2282                     newprops.insert("xmltemplate", textTemplate);
2283                 }
2284
2285                 if (dia_ui.description->toPlainText() != clip->getProperty("description")) {
2286                     newprops.insert("description", dia_ui.description->toPlainText());
2287                 }
2288
2289                 QString newtemplate = newprops.value("xmltemplate");
2290                 if (newtemplate.isEmpty()) newtemplate = templatePath;
2291
2292                 // template modified we need to update xmldata
2293                 QString description = newprops.value("description");
2294                 if (description.isEmpty()) description = clip->getProperty("description");
2295                 newprops.insert("xmldata", m_projectList->generateTemplateXml(newtemplate, description).toString());
2296                 if (dia_ui.normal_clip->isChecked()) {
2297                     // Switch clip to normal clip
2298                     newprops.insert("xmltemplate", QString());
2299                 }
2300                 EditClipCommand *command = new EditClipCommand(m_projectList, clip->getId(), clip->properties(), newprops, true);
2301                 m_activeDocument->commandStack()->push(command);
2302             }
2303             return;
2304         }
2305         QString path = clip->getProperty("resource");
2306         TitleWidget *dia_ui = new TitleWidget(KUrl(), m_activeDocument->timecode(), titlepath, m_projectMonitor->render, this);
2307         QDomDocument doc;
2308         doc.setContent(clip->getProperty("xmldata"));
2309         dia_ui->setXml(doc);
2310         if (dia_ui->exec() == QDialog::Accepted) {
2311             QRect rect = dia_ui->renderedRect();
2312             QMap <QString, QString> newprops;
2313             newprops.insert("xmldata", dia_ui->xml().toString());
2314             newprops.insert("out", QString::number(dia_ui->duration()));
2315             newprops.insert("frame_size", QString::number(rect.width()) + 'x' + QString::number(rect.height()));
2316             EditClipCommand *command = new EditClipCommand(m_projectList, clip->getId(), clip->properties(), newprops, true);
2317             m_activeDocument->commandStack()->push(command);
2318             m_activeTimeline->projectView()->slotUpdateClip(clip->getId());
2319             m_activeDocument->setModified(true);
2320         }
2321         delete dia_ui;
2322
2323         //m_activeDocument->editTextClip(clip->getProperty("xml"), clip->getId());
2324         return;
2325     }
2326     ClipProperties dia(clip, m_activeDocument->timecode(), m_activeDocument->fps(), this);
2327     connect(&dia, SIGNAL(addMarker(const QString &, GenTime, QString)), m_activeTimeline->projectView(), SLOT(slotAddClipMarker(const QString &, GenTime, QString)));
2328     if (dia.exec() == QDialog::Accepted) {
2329         EditClipCommand *command = new EditClipCommand(m_projectList, clip->getId(), clip->properties(), dia.properties(), true);
2330         m_activeDocument->commandStack()->push(command);
2331
2332         //m_projectList->slotUpdateClipProperties(dia.clipId(), dia.properties());
2333         if (dia.needsTimelineRefresh()) {
2334             // update clip occurences in timeline
2335             m_activeTimeline->projectView()->slotUpdateClip(clip->getId());
2336         }
2337     }
2338 }
2339
2340 void MainWindow::customEvent(QEvent* e)
2341 {
2342     if (e->type() == QEvent::User) {
2343         m_messageLabel->setMessage(static_cast <MltErrorEvent *>(e)->message(), MltError);
2344     }
2345 }
2346 void MainWindow::slotActivateEffectStackView()
2347 {
2348     m_effectStack->raiseWindow(m_effectStackDock);
2349 }
2350
2351 void MainWindow::slotActivateTransitionView(Transition *t)
2352 {
2353     if (t) m_transitionConfig->raiseWindow(m_transitionConfigDock);
2354 }
2355
2356 void MainWindow::slotSnapRewind()
2357 {
2358     if (m_projectMonitor->isActive()) {
2359         if (m_activeTimeline)
2360             m_activeTimeline->projectView()->slotSeekToPreviousSnap();
2361     } else m_clipMonitor->slotSeekToPreviousSnap();
2362 }
2363
2364 void MainWindow::slotSnapForward()
2365 {
2366     if (m_projectMonitor->isActive()) {
2367         if (m_activeTimeline)
2368             m_activeTimeline->projectView()->slotSeekToNextSnap();
2369     } else m_clipMonitor->slotSeekToNextSnap();
2370 }
2371
2372 void MainWindow::slotClipStart()
2373 {
2374     if (m_projectMonitor->isActive()) {
2375         if (m_activeTimeline)
2376             m_activeTimeline->projectView()->clipStart();
2377     }
2378 }
2379
2380 void MainWindow::slotClipEnd()
2381 {
2382     if (m_projectMonitor->isActive()) {
2383         if (m_activeTimeline)
2384             m_activeTimeline->projectView()->clipEnd();
2385     }
2386 }
2387
2388 void MainWindow::slotChangeTool(QAction * action)
2389 {
2390     if (action == m_buttonSelectTool) slotSetTool(SELECTTOOL);
2391     else if (action == m_buttonRazorTool) slotSetTool(RAZORTOOL);
2392     else if (action == m_buttonSpacerTool) slotSetTool(SPACERTOOL);
2393 }
2394
2395 void MainWindow::slotSetTool(PROJECTTOOL tool)
2396 {
2397     if (m_activeDocument && m_activeTimeline) {
2398         //m_activeDocument->setTool(tool);
2399         m_activeTimeline->projectView()->setTool(tool);
2400     }
2401 }
2402
2403 void MainWindow::slotCopy()
2404 {
2405     if (!m_activeDocument || !m_activeTimeline) return;
2406     m_activeTimeline->projectView()->copyClip();
2407 }
2408
2409 void MainWindow::slotPaste()
2410 {
2411     if (!m_activeDocument || !m_activeTimeline) return;
2412     m_activeTimeline->projectView()->pasteClip();
2413 }
2414
2415 void MainWindow::slotPasteEffects()
2416 {
2417     if (!m_activeDocument || !m_activeTimeline) return;
2418     m_activeTimeline->projectView()->pasteClipEffects();
2419 }
2420
2421 void MainWindow::slotFind()
2422 {
2423     if (!m_activeDocument || !m_activeTimeline) return;
2424     m_projectSearch->setEnabled(false);
2425     m_findActivated = true;
2426     m_findString.clear();
2427     m_activeTimeline->projectView()->initSearchStrings();
2428     statusBar()->showMessage(i18n("Starting -- find text as you type"));
2429     m_findTimer.start(5000);
2430     qApp->installEventFilter(this);
2431 }
2432
2433 void MainWindow::slotFindNext()
2434 {
2435     if (m_activeTimeline && m_activeTimeline->projectView()->findNextString(m_findString)) {
2436         statusBar()->showMessage(i18n("Found: %1", m_findString));
2437     } else {
2438         statusBar()->showMessage(i18n("Reached end of project"));
2439     }
2440     m_findTimer.start(4000);
2441 }
2442
2443 void MainWindow::findAhead()
2444 {
2445     if (m_activeTimeline && m_activeTimeline->projectView()->findString(m_findString)) {
2446         m_projectSearchNext->setEnabled(true);
2447         statusBar()->showMessage(i18n("Found: %1", m_findString));
2448     } else {
2449         m_projectSearchNext->setEnabled(false);
2450         statusBar()->showMessage(i18n("Not found: %1", m_findString));
2451     }
2452 }
2453
2454 void MainWindow::findTimeout()
2455 {
2456     m_projectSearchNext->setEnabled(false);
2457     m_findActivated = false;
2458     m_findString.clear();
2459     statusBar()->showMessage(i18n("Find stopped"), 3000);
2460     if (m_activeTimeline) m_activeTimeline->projectView()->clearSearchStrings();
2461     m_projectSearch->setEnabled(true);
2462     removeEventFilter(this);
2463 }
2464
2465 void MainWindow::keyPressEvent(QKeyEvent *ke)
2466 {
2467     if (m_findActivated) {
2468         if (ke->key() == Qt::Key_Backspace) {
2469             m_findString = m_findString.left(m_findString.length() - 1);
2470
2471             if (!m_findString.isEmpty()) {
2472                 findAhead();
2473             } else {
2474                 findTimeout();
2475             }
2476
2477             m_findTimer.start(4000);
2478             ke->accept();
2479             return;
2480         } else if (ke->key() == Qt::Key_Escape) {
2481             findTimeout();
2482             ke->accept();
2483             return;
2484         } else if (ke->key() == Qt::Key_Space || !ke->text().trimmed().isEmpty()) {
2485             m_findString += ke->text();
2486
2487             findAhead();
2488
2489             m_findTimer.start(4000);
2490             ke->accept();
2491             return;
2492         }
2493     } else KXmlGuiWindow::keyPressEvent(ke);
2494 }
2495
2496
2497 /** Gets called when the window gets hidden */
2498 void MainWindow::hideEvent(QHideEvent */*event*/)
2499 {
2500     // kDebug() << "I was hidden";
2501     // issue http://www.kdenlive.org/mantis/view.php?id=231
2502     if (isMinimized()) {
2503         // kDebug() << "I am minimized";
2504         if (m_monitorManager) m_monitorManager->stopActiveMonitor();
2505     }
2506 }
2507
2508 bool MainWindow::eventFilter(QObject *obj, QEvent *event)
2509 {
2510     if (m_findActivated) {
2511         if (event->type() == QEvent::ShortcutOverride) {
2512             QKeyEvent* ke = (QKeyEvent*) event;
2513             if (ke->text().trimmed().isEmpty()) return false;
2514             ke->accept();
2515             return true;
2516         } else return false;
2517     } else {
2518         // pass the event on to the parent class
2519         return QMainWindow::eventFilter(obj, event);
2520     }
2521 }
2522
2523
2524 void MainWindow::slotSaveZone(Render *render, QPoint zone)
2525 {
2526     KDialog *dialog = new KDialog(this);
2527     dialog->setCaption("Save clip zone");
2528     dialog->setButtons(KDialog::Ok | KDialog::Cancel);
2529
2530     QWidget *widget = new QWidget(dialog);
2531     dialog->setMainWidget(widget);
2532
2533     QVBoxLayout *vbox = new QVBoxLayout(widget);
2534     QLabel *label1 = new QLabel(i18n("Save clip zone as:"), this);
2535     QString path = m_activeDocument->projectFolder().path();
2536     path.append("/");
2537     path.append("untitled.mlt");
2538     KUrlRequester *url = new KUrlRequester(KUrl(path), this);
2539     url->setFilter("video/mlt-playlist");
2540     QLabel *label2 = new QLabel(i18n("Description:"), this);
2541     KLineEdit *edit = new KLineEdit(this);
2542     vbox->addWidget(label1);
2543     vbox->addWidget(url);
2544     vbox->addWidget(label2);
2545     vbox->addWidget(edit);
2546     if (dialog->exec() == QDialog::Accepted) render->saveZone(url->url(), edit->text(), zone);
2547
2548 }
2549
2550 void MainWindow::slotSetInPoint()
2551 {
2552     if (m_clipMonitor->isActive()) {
2553         m_clipMonitor->slotSetZoneStart();
2554     } else m_activeTimeline->projectView()->setInPoint();
2555 }
2556
2557 void MainWindow::slotSetOutPoint()
2558 {
2559     if (m_clipMonitor->isActive()) {
2560         m_clipMonitor->slotSetZoneEnd();
2561     } else m_activeTimeline->projectView()->setOutPoint();
2562 }
2563
2564 void MainWindow::slotGetNewLumaStuff()
2565 {
2566     //KNS::Entry::List download();
2567     KNS::Entry::List entries = KNS::Engine::download();
2568     // list of changed entries
2569     kDebug() << "// PARSING KNS";
2570     foreach(KNS::Entry* entry, entries) {
2571         // care only about installed ones
2572         if (entry->status() == KNS::Entry::Installed) {
2573             foreach(const QString &file, entry->installedFiles()) {
2574                 kDebug() << "// CURRENTLY INSTALLED: " << file;
2575             }
2576         }
2577     }
2578     qDeleteAll(entries);
2579     initEffects::refreshLumas();
2580     m_activeTimeline->projectView()->reloadTransitionLumas();
2581 }
2582
2583 void MainWindow::slotGetNewRenderStuff()
2584 {
2585     //KNS::Entry::List download();
2586
2587     KNS::Engine engine(0);
2588     if (engine.init("kdenlive_render.knsrc")) {
2589         KNS::Entry::List entries = engine.downloadDialogModal(this);
2590
2591         if (entries.size() > 0) {
2592             foreach(KNS::Entry* entry, entries) {
2593                 // care only about installed ones
2594                 if (entry->status() == KNS::Entry::Installed) {
2595                     foreach(const QString &file, entry->installedFiles()) {
2596                         kDebug() << "// CURRENTLY INSTALLED: " << file;
2597                     }
2598                 }
2599             }
2600         }
2601         if (m_renderWidget) m_renderWidget->reloadProfiles();
2602     }
2603 }
2604
2605 void MainWindow::slotGetNewMltProfileStuff()
2606 {
2607     //KNS::Entry::List download();
2608
2609     KNS::Engine engine(0);
2610     if (engine.init("kdenlive_mltprofiles.knsrc")) {
2611         KNS::Entry::List entries = engine.downloadDialogModal(this);
2612
2613         if (entries.size() > 0) {
2614             foreach(KNS::Entry* entry, entries) {
2615                 // care only about installed ones
2616                 if (entry->status() == KNS::Entry::Installed) {
2617                     foreach(const QString &file, entry->installedFiles()) {
2618                         kDebug() << "// CURRENTLY INSTALLED: " << file;
2619                     }
2620                 }
2621             }
2622
2623             // update the list of profiles in settings dialog
2624             KdenliveSettingsDialog* d = static_cast <KdenliveSettingsDialog*>(KConfigDialog::exists("settings"));
2625             if (d) d->checkProfile();
2626         }
2627     }
2628 }
2629
2630 void MainWindow::slotAutoTransition()
2631 {
2632     if (m_activeTimeline) m_activeTimeline->projectView()->autoTransition();
2633 }
2634
2635 void MainWindow::slotSplitAudio()
2636 {
2637     if (m_activeTimeline) m_activeTimeline->projectView()->splitAudio();
2638 }
2639
2640 void MainWindow::slotUpdateClipType(QAction *action)
2641 {
2642     if (m_activeTimeline) {
2643         if (action->data().toString() == "clip_audio_only") m_activeTimeline->projectView()->setAudioOnly();
2644         else if (action->data().toString() == "clip_video_only") m_activeTimeline->projectView()->setVideoOnly();
2645         else m_activeTimeline->projectView()->setAudioAndVideo();
2646     }
2647 }
2648
2649 void MainWindow::slotDvdWizard(const QString &url, const QString &profile)
2650 {
2651     DvdWizard *w = new DvdWizard(url, profile, this);
2652     w->exec();
2653 }
2654
2655 void MainWindow::slotShowTimeline(bool show)
2656 {
2657     if (show == false) {
2658         m_timelineState = saveState();
2659         centralWidget()->setHidden(true);
2660     } else {
2661         centralWidget()->setHidden(false);
2662         restoreState(m_timelineState);
2663     }
2664 }
2665
2666 void MainWindow::slotMaximizeCurrent(bool /*show*/)
2667 {
2668     //TODO: is there a way to maximize current widget?
2669     //if (show == true)
2670     {
2671         m_timelineState = saveState();
2672         QWidget *par = focusWidget()->parentWidget();
2673         while (par->parentWidget() && par->parentWidget() != this) {
2674             par = par->parentWidget();
2675         }
2676         kDebug() << "CURRENT WIDGET: " << par->objectName();
2677     }
2678     /*else {
2679     //centralWidget()->setHidden(false);
2680     //restoreState(m_timelineState);
2681     }*/
2682 }
2683
2684 void MainWindow::loadTranscoders()
2685 {
2686     QMenu *transMenu = static_cast<QMenu*>(factory()->container("transcoders", this));
2687     transMenu->clear();
2688
2689     KSharedConfigPtr config = KSharedConfig::openConfig("kdenlivetranscodingrc");
2690     KConfigGroup transConfig(config, "Transcoding");
2691     // read the entries
2692     QMap< QString, QString > profiles = transConfig.entryMap();
2693     QMapIterator<QString, QString> i(profiles);
2694     while (i.hasNext()) {
2695         i.next();
2696         QAction *a = transMenu->addAction(i.key());
2697         a->setData(i.value());
2698         connect(a, SIGNAL(triggered()), this, SLOT(slotTranscode()));
2699     }
2700 }
2701
2702 void MainWindow::slotTranscode(KUrl::List urls)
2703 {
2704     QString params;
2705     if (urls.isEmpty()) {
2706         urls.append(m_projectList->currentClipUrl());
2707         QAction *action = qobject_cast<QAction *>(sender());
2708         params = action->data().toString();
2709     }
2710     if (urls.isEmpty()) return;
2711     ClipTranscode *d = new ClipTranscode(urls, params);
2712     connect(d, SIGNAL(addClip(KUrl)), this, SLOT(slotAddProjectClip(KUrl)));
2713     d->show();
2714     //QProcess::startDetached("ffmpeg", parameters);
2715 }
2716
2717 void MainWindow::slotTranscodeClip()
2718 {
2719     KUrl::List urls = KFileDialog::getOpenUrls(KUrl("kfiledialog:///projectfolder"));
2720     if (urls.isEmpty()) return;
2721     slotTranscode(urls);
2722 }
2723
2724 void MainWindow::slotSetDocumentRenderProfile(const QString &dest, const QString &name, const QString &file)
2725 {
2726     if (m_activeDocument == NULL) return;
2727     m_activeDocument->setDocumentProperty("renderdestination", dest);
2728     m_activeDocument->setDocumentProperty("renderprofile", name);
2729     m_activeDocument->setDocumentProperty("renderurl", file);
2730     m_activeDocument->setModified(true);
2731 }
2732
2733
2734 void MainWindow::slotPrepareRendering(bool scriptExport, bool zoneOnly, const QString &chapterFile)
2735 {
2736     if (m_activeDocument == NULL || m_renderWidget == NULL) return;
2737     QString scriptPath;
2738     QString playlistPath;
2739     if (scriptExport) {
2740         bool ok;
2741         QString scriptsFolder = m_activeDocument->projectFolder().path() + "/scripts/";
2742         QString path = m_renderWidget->getFreeScriptName();
2743         scriptPath = QInputDialog::getText(this, i18n("Create Render Script"), i18n("Script name (will be saved in: %1)", scriptsFolder), QLineEdit::Normal, KUrl(path).fileName(), &ok);
2744         if (!ok || scriptPath.isEmpty()) return;
2745         scriptPath.prepend(scriptsFolder);
2746         QFile f(scriptPath);
2747         if (f.exists()) {
2748             if (KMessageBox::warningYesNo(this, i18n("Script file already exists. Do you want to overwrite it?")) != KMessageBox::Yes)
2749                 return;
2750         }
2751         playlistPath = scriptPath + ".mlt";
2752         m_projectMonitor->saveSceneList(playlistPath);
2753     } else {
2754         KTemporaryFile temp;
2755         temp.setAutoRemove(false);
2756         temp.setSuffix(".mlt");
2757         temp.open();
2758         playlistPath = temp.fileName();
2759         m_projectMonitor->saveSceneList(playlistPath);
2760     }
2761
2762     if (!chapterFile.isEmpty()) {
2763         int in = 0;
2764         int out;
2765         if (!zoneOnly) out = (int) GenTime(m_activeDocument->projectDuration()).frames(m_activeDocument->fps());
2766         else {
2767             in = m_activeTimeline->inPoint();
2768             out = m_activeTimeline->outPoint();
2769         }
2770         QDomDocument doc;
2771         QDomElement chapters = doc.createElement("chapters");
2772         chapters.setAttribute("fps", m_activeDocument->fps());
2773         doc.appendChild(chapters);
2774
2775         QDomElement guidesxml = m_activeDocument->guidesXml();
2776         QDomNodeList nodes = guidesxml.elementsByTagName("guide");
2777         for (int i = 0; i < nodes.count(); i++) {
2778             QDomElement e = nodes.item(i).toElement();
2779             if (!e.isNull()) {
2780                 QString comment = e.attribute("comment");
2781                 int time = (int) GenTime(e.attribute("time").toDouble()).frames(m_activeDocument->fps());
2782                 if (time >= in && time < out) {
2783                     if (zoneOnly) time = time - in;
2784                     QDomElement chapter = doc.createElement("chapter");
2785                     chapters.appendChild(chapter);
2786                     chapter.setAttribute("title", comment);
2787                     chapter.setAttribute("time", time);
2788                 }
2789             }
2790         }
2791         if (chapters.childNodes().count() > 0) {
2792             if (m_activeTimeline->projectView()->hasGuide(out, 0) == -1) {
2793                 // Always insert a guide in pos 0
2794                 QDomElement chapter = doc.createElement("chapter");
2795                 chapters.insertBefore(chapter, QDomNode());
2796                 chapter.setAttribute("title", i18n("Start"));
2797                 chapter.setAttribute("time", "0");
2798             }
2799             // save chapters file
2800             QFile file(chapterFile);
2801             if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
2802                 kWarning() << "//////  ERROR writing DVD CHAPTER file: " << chapterFile;
2803             } else {
2804                 file.write(doc.toString().toUtf8());
2805                 if (file.error() != QFile::NoError) {
2806                     kWarning() << "//////  ERROR writing DVD CHAPTER file: " << chapterFile;
2807                 }
2808                 file.close();
2809             }
2810         }
2811     }
2812
2813     m_renderWidget->slotExport(scriptExport, m_activeTimeline->inPoint(), m_activeTimeline->outPoint(), playlistPath, scriptPath);
2814 }
2815
2816 void MainWindow::slotUpdateTimecodeFormat(int ix)
2817 {
2818     KdenliveSettings::setFrametimecode(ix == 1);
2819     m_clipMonitor->updateTimecodeFormat();
2820     m_projectMonitor->updateTimecodeFormat();
2821 }
2822
2823 void MainWindow::slotRemoveFocus()
2824 {
2825     statusBar()->setFocus();
2826     statusBar()->clearFocus();
2827 }
2828
2829
2830
2831
2832 #include "mainwindow.moc"