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