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