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