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