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