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