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