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