]> git.sesse.net Git - kdenlive/blob - src/mainwindow.cpp
*Render dialog can now create xml files for dvd chapters based on guides (usable...
[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             doc.appendChild(chapters);
1666
1667             QDomElement guidesxml = m_activeDocument->guidesXml();
1668             if (!zoneOnly) out = (int) GenTime(m_activeDocument->projectDuration()).frames(m_activeDocument->fps());
1669
1670             QDomNodeList nodes = guidesxml.elementsByTagName("guide");
1671             for (int i = 0; i < nodes.count(); i++) {
1672                 QDomElement e = nodes.item(i).toElement();
1673                 if (!e.isNull()) {
1674                     QString comment = e.attribute("comment");
1675                     int time = (int) GenTime(e.attribute("time").toDouble()).frames(m_activeDocument->fps());
1676                     if (time >= in && time < out) {
1677                         if (zoneOnly) time = time - in;
1678                         QDomElement chapter = doc.createElement("chapter");
1679                         chapters.appendChild(chapter);
1680                         chapter.setAttribute("title", comment);
1681                         chapter.setAttribute("time", Timecode::getStringTimecode(time, m_activeDocument->fps()));
1682                     }
1683                 }
1684             }
1685             if (chapters.childNodes().count() > 0) {
1686                 if (m_activeTimeline->projectView()->hasGuide(out, 0) == -1) {
1687                     // Always insert a guide in pos 0
1688                     QDomElement chapter = doc.createElement("chapter");
1689                     chapters.insertBefore(chapter, QDomNode());
1690                     chapter.setAttribute("title", i18n("Start"));
1691                     chapter.setAttribute("time", "0");
1692                 }
1693                 // save chapters file
1694                 QFile file(dest + ".dvdchapter");
1695                 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
1696                     kWarning() << "//////  ERROR writing DVD CHAPTER file: " << dest + ".dvdchapter";
1697                 } else {
1698                     file.write(doc.toString().toUtf8());
1699                     if (file.error() != QFile::NoError)
1700                         kWarning() << "//////  ERROR writing DVD CHAPTER file: " << dest + ".dvdchapter";
1701                     file.close();
1702                 }
1703             }
1704         }
1705     }
1706 }
1707
1708 void MainWindow::setRenderingProgress(const QString &url, int progress)
1709 {
1710     if (m_renderWidget) m_renderWidget->setRenderJob(url, progress);
1711 }
1712
1713 void MainWindow::setRenderingFinished(const QString &url, int status, const QString &error)
1714 {
1715     if (m_renderWidget) m_renderWidget->setRenderStatus(url, status, error);
1716 }
1717
1718 void MainWindow::slotUpdateMousePosition(int pos)
1719 {
1720     if (m_activeDocument)
1721         switch (m_timecodeFormat->currentIndex()) {
1722         case 0:
1723             statusBar()->changeItem(m_activeDocument->timecode().getTimecodeFromFrames(pos), ID_TIMELINE_POS);
1724             break;
1725         default:
1726             statusBar()->changeItem(QString::number(pos), ID_TIMELINE_POS);
1727         }
1728 }
1729
1730 void MainWindow::slotUpdateDocumentState(bool modified)
1731 {
1732     if (!m_activeDocument) return;
1733     setCaption(m_activeDocument->description(), modified);
1734     m_saveAction->setEnabled(modified);
1735     if (modified) {
1736         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Link));
1737         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("document-save"));
1738     } else {
1739         m_timelineArea->setTabTextColor(m_timelineArea->currentIndex(), palette().color(QPalette::Text));
1740         m_timelineArea->setTabIcon(m_timelineArea->currentIndex(), KIcon("kdenlive"));
1741     }
1742 }
1743
1744 void MainWindow::connectDocumentInfo(KdenliveDoc *doc)
1745 {
1746     if (m_activeDocument) {
1747         if (m_activeDocument == doc) return;
1748         disconnect(m_activeDocument, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
1749     }
1750     connect(doc, SIGNAL(progressInfo(const QString &, int)), this, SLOT(slotGotProgressInfo(const QString &, int)));
1751 }
1752
1753 void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc)   //changed
1754 {
1755     //m_projectMonitor->stop();
1756     m_closeAction->setEnabled(m_timelineArea->count() > 1);
1757     kDebug() << "///////////////////   CONNECTING DOC TO PROJECT VIEW ////////////////";
1758     if (m_activeDocument) {
1759         if (m_activeDocument == doc) return;
1760         if (m_activeTimeline) {
1761             disconnect(m_projectMonitor, SIGNAL(renderPosition(int)), m_activeTimeline, SLOT(moveCursorPos(int)));
1762             disconnect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), m_activeTimeline, SLOT(slotSetZone(QPoint)));
1763             disconnect(m_projectMonitor, SIGNAL(durationChanged(int)), m_activeTimeline, SLOT(setDuration(int)));
1764             disconnect(m_projectList, SIGNAL(projectModified()), m_activeDocument, SLOT(setModified()));
1765             disconnect(m_projectMonitor->render, SIGNAL(refreshDocumentProducers()), m_activeDocument, SLOT(checkProjectClips()));
1766
1767
1768             disconnect(m_activeDocument, SIGNAL(guidesUpdated()), this, SLOT(slotGuidesUpdated()));
1769             disconnect(m_activeDocument, SIGNAL(addProjectClip(DocClipBase *, bool)), m_projectList, SLOT(slotAddClip(DocClipBase *, bool)));
1770             disconnect(m_activeDocument, SIGNAL(resetProjectList()), m_projectList, SLOT(slotResetProjectList()));
1771             disconnect(m_activeDocument, SIGNAL(signalDeleteProjectClip(const QString &)), m_projectList, SLOT(slotDeleteClip(const QString &)));
1772             disconnect(m_activeDocument, SIGNAL(updateClipDisplay(const QString &)), m_projectList, SLOT(slotUpdateClip(const QString &)));
1773             disconnect(m_activeDocument, SIGNAL(selectLastAddedClip(const QString &)), m_projectList, SLOT(slotSelectClip(const QString &)));
1774             disconnect(m_activeDocument, SIGNAL(deleteTimelineClip(const QString &)), m_activeTimeline, SLOT(slotDeleteClip(const QString &)));
1775             disconnect(m_activeTimeline->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), m_effectStack, SLOT(slotClipItemSelected(ClipItem*, int)));
1776             disconnect(m_activeTimeline->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), this, SLOT(slotActivateEffectStackView()));
1777             disconnect(m_activeTimeline, SIGNAL(transitionItemSelected(Transition*, bool)), m_transitionConfig, SLOT(slotTransitionItemSelected(Transition*, bool)));
1778             disconnect(m_activeTimeline, SIGNAL(transitionItemSelected(Transition*, bool)), this, SLOT(slotActivateTransitionView(Transition *)));
1779             disconnect(m_zoomSlider, SIGNAL(valueChanged(int)), m_activeTimeline, SLOT(slotChangeZoom(int)));
1780             disconnect(m_activeTimeline->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
1781             disconnect(m_activeTimeline->projectView(), SIGNAL(showClipFrame(DocClipBase *, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, const int)));
1782             disconnect(m_activeTimeline, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
1783             disconnect(m_activeTimeline, SIGNAL(insertTrack(int)), this, SLOT(slotInsertTrack(int)));
1784             disconnect(m_activeTimeline, SIGNAL(deleteTrack(int)), this, SLOT(slotDeleteTrack(int)));
1785             disconnect(m_activeTimeline, SIGNAL(changeTrack(int)), this, SLOT(slotChangeTrack(int)));
1786             disconnect(m_activeDocument, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
1787             disconnect(m_effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement, int)), m_activeTimeline->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement, int)));
1788             disconnect(m_effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), m_activeTimeline->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
1789             disconnect(m_effectStack, SIGNAL(changeEffectState(ClipItem*, int, bool)), m_activeTimeline->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, bool)));
1790             disconnect(m_effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), m_activeTimeline->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
1791             disconnect(m_effectStack, SIGNAL(refreshEffectStack(ClipItem*)), m_activeTimeline->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
1792             disconnect(m_effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
1793             disconnect(m_transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), m_activeTimeline->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
1794             disconnect(m_transitionConfig, SIGNAL(seekTimeline(int)), m_activeTimeline->projectView() , SLOT(setCursorPos(int)));
1795             disconnect(m_activeTimeline->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
1796             disconnect(m_activeTimeline, SIGNAL(zoneMoved(int, int)), this, SLOT(slotZoneMoved(int, int)));
1797             disconnect(m_projectList, SIGNAL(loadingIsOver()), m_activeTimeline->projectView(), SLOT(slotUpdateAllThumbs()));
1798             m_effectStack->clear();
1799         }
1800         //m_activeDocument->setRenderer(NULL);
1801         disconnect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
1802         m_clipMonitor->stop();
1803     }
1804     KdenliveSettings::setCurrent_profile(doc->profilePath());
1805     KdenliveSettings::setProject_fps(doc->fps());
1806     m_monitorManager->resetProfiles(doc->timecode());
1807     m_projectList->setDocument(doc);
1808     m_transitionConfig->updateProjectFormat(doc->mltProfile(), doc->timecode(), trackView->tracksNumber());
1809     m_effectStack->updateProjectFormat(doc->mltProfile(), doc->timecode());
1810     connect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *)));
1811     connect(m_projectList, SIGNAL(projectModified()), doc, SLOT(setModified()));
1812     connect(m_projectList, SIGNAL(clipNameChanged(const QString, const QString)), trackView->projectView(), SLOT(clipNameChanged(const QString, const QString)));
1813
1814
1815     connect(trackView, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor()));
1816     connect(trackView, SIGNAL(insertTrack(int)), this, SLOT(slotInsertTrack(int)));
1817     connect(trackView, SIGNAL(deleteTrack(int)), this, SLOT(slotDeleteTrack(int)));
1818     connect(trackView, SIGNAL(changeTrack(int)), this, SLOT(slotChangeTrack(int)));
1819     connect(trackView, SIGNAL(mousePosition(int)), this, SLOT(slotUpdateMousePosition(int)));
1820     connect(m_projectMonitor, SIGNAL(renderPosition(int)), trackView, SLOT(moveCursorPos(int)));
1821     connect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), trackView, SLOT(slotSetZone(QPoint)));
1822     connect(m_projectMonitor, SIGNAL(durationChanged(int)), trackView, SLOT(setDuration(int)));
1823     connect(m_projectMonitor->render, SIGNAL(refreshDocumentProducers()), doc, SLOT(checkProjectClips()));
1824     connect(doc, SIGNAL(addProjectClip(DocClipBase *, bool)), m_projectList, SLOT(slotAddClip(DocClipBase *, bool)));
1825     connect(doc, SIGNAL(resetProjectList()), m_projectList, SLOT(slotResetProjectList()));
1826     connect(doc, SIGNAL(signalDeleteProjectClip(const QString &)), m_projectList, SLOT(slotDeleteClip(const QString &)));
1827     connect(doc, SIGNAL(updateClipDisplay(const QString &)), m_projectList, SLOT(slotUpdateClip(const QString &)));
1828     connect(doc, SIGNAL(selectLastAddedClip(const QString &)), m_projectList, SLOT(slotSelectClip(const QString &)));
1829
1830     connect(doc, SIGNAL(deleteTimelineClip(const QString &)), trackView, SLOT(slotDeleteClip(const QString &)));
1831     connect(doc, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool)));
1832     connect(doc, SIGNAL(guidesUpdated()), this, SLOT(slotGuidesUpdated()));
1833
1834
1835     connect(trackView->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), m_effectStack, SLOT(slotClipItemSelected(ClipItem*, int)));
1836     connect(trackView->projectView(), SIGNAL(clipItemSelected(ClipItem*, int)), this, SLOT(slotActivateEffectStackView()));
1837     connect(trackView, SIGNAL(transitionItemSelected(Transition*, bool)), m_transitionConfig, SLOT(slotTransitionItemSelected(Transition*, bool)));
1838     connect(trackView, SIGNAL(transitionItemSelected(Transition*, bool)), this, SLOT(slotActivateTransitionView(Transition *)));
1839     m_zoomSlider->setValue(doc->zoom());
1840     connect(m_zoomSlider, SIGNAL(valueChanged(int)), trackView, SLOT(slotChangeZoom(int)));
1841     connect(trackView->projectView(), SIGNAL(zoomIn()), this, SLOT(slotZoomIn()));
1842     connect(trackView->projectView(), SIGNAL(zoomOut()), this, SLOT(slotZoomOut()));
1843     connect(trackView->projectView(), SIGNAL(displayMessage(const QString&, MessageType)), m_messageLabel, SLOT(setMessage(const QString&, MessageType)));
1844
1845     connect(trackView->projectView(), SIGNAL(showClipFrame(DocClipBase *, const int)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *, const int)));
1846
1847
1848     connect(m_effectStack, SIGNAL(updateClipEffect(ClipItem*, QDomElement, QDomElement, int)), trackView->projectView(), SLOT(slotUpdateClipEffect(ClipItem*, QDomElement, QDomElement, int)));
1849     connect(m_effectStack, SIGNAL(removeEffect(ClipItem*, QDomElement)), trackView->projectView(), SLOT(slotDeleteEffect(ClipItem*, QDomElement)));
1850     connect(m_effectStack, SIGNAL(changeEffectState(ClipItem*, int, bool)), trackView->projectView(), SLOT(slotChangeEffectState(ClipItem*, int, bool)));
1851     connect(m_effectStack, SIGNAL(changeEffectPosition(ClipItem*, int, int)), trackView->projectView(), SLOT(slotChangeEffectPosition(ClipItem*, int, int)));
1852     connect(m_effectStack, SIGNAL(refreshEffectStack(ClipItem*)), trackView->projectView(), SLOT(slotRefreshEffects(ClipItem*)));
1853     connect(m_transitionConfig, SIGNAL(transitionUpdated(Transition *, QDomElement)), trackView->projectView() , SLOT(slotTransitionUpdated(Transition *, QDomElement)));
1854     connect(m_transitionConfig, SIGNAL(seekTimeline(int)), trackView->projectView() , SLOT(setCursorPos(int)));
1855     connect(m_effectStack, SIGNAL(reloadEffects()), this, SLOT(slotReloadEffects()));
1856
1857     connect(trackView->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor()));
1858     connect(trackView, SIGNAL(zoneMoved(int, int)), this, SLOT(slotZoneMoved(int, int)));
1859     connect(m_projectList, SIGNAL(loadingIsOver()), trackView->projectView(), SLOT(slotUpdateAllThumbs()));
1860
1861     trackView->projectView()->setContextMenu(m_timelineContextMenu, m_timelineContextClipMenu, m_timelineContextTransitionMenu, m_clipTypeGroup);
1862     m_activeTimeline = trackView;
1863     if (m_renderWidget) {
1864         m_renderWidget->setProfile(doc->mltProfile());
1865         m_renderWidget->setDocumentPath(doc->projectFolder().path());
1866     }
1867     //doc->setRenderer(m_projectMonitor->render);
1868     m_commandStack->setActiveStack(doc->commandStack());
1869     KdenliveSettings::setProject_display_ratio(doc->dar());
1870     m_projectList->updateAllClips();
1871     //doc->clipManager()->checkAudioThumbs();
1872
1873     //m_overView->setScene(trackView->projectScene());
1874     //m_overView->scale(m_overView->width() / trackView->duration(), m_overView->height() / (50 * trackView->tracksNumber()));
1875     //m_overView->fitInView(m_overView->itemAt(0, 50), Qt::KeepAspectRatio);
1876
1877     setCaption(doc->description(), doc->isModified());
1878     m_saveAction->setEnabled(doc->isModified());
1879     m_activeDocument = doc;
1880     if (KdenliveSettings::dropbframes()) slotUpdatePreviewSettings();
1881
1882     // set tool to select tool
1883     m_buttonSelectTool->setChecked(true);
1884 }
1885
1886 void MainWindow::slotZoneMoved(int start, int end)
1887 {
1888     m_activeDocument->setZone(start, end);
1889     m_projectMonitor->slotZoneMoved(start, end);
1890 }
1891
1892 void MainWindow::slotGuidesUpdated()
1893 {
1894     if (m_renderWidget) m_renderWidget->setGuides(m_activeDocument->guidesXml(), m_activeDocument->projectDuration());
1895 }
1896
1897 void MainWindow::slotPreferences(int page, int option)
1898 {
1899     //An instance of your dialog could be already created and could be
1900     // cached, in which case you want to display the cached dialog
1901     // instead of creating another one
1902     if (KConfigDialog::showDialog("settings")) {
1903         KdenliveSettingsDialog* d = static_cast <KdenliveSettingsDialog*>(KConfigDialog::exists("settings"));
1904         if (page != -1) d->showPage(page, option);
1905         return;
1906     }
1907
1908     // KConfigDialog didn't find an instance of this dialog, so lets
1909     // create it :
1910     KdenliveSettingsDialog* dialog = new KdenliveSettingsDialog(this);
1911     connect(dialog, SIGNAL(settingsChanged(const QString&)), this, SLOT(updateConfiguration()));
1912     connect(dialog, SIGNAL(doResetProfile()), m_monitorManager, SLOT(slotResetProfiles()));
1913     connect(dialog, SIGNAL(updatePreviewSettings()), this, SLOT(slotUpdatePreviewSettings()));
1914     connect(dialog, SIGNAL(updateCaptureFolder()), m_recMonitor, SLOT(slotUpdateCaptureFolder()));
1915     //connect(dialog, SIGNAL(updatePreviewSettings()), this, SLOT(slotUpdatePreviewSettings()));
1916     dialog->show();
1917     if (page != -1) dialog->showPage(page, option);
1918 }
1919
1920 void MainWindow::slotUpdatePreviewSettings()
1921 {
1922     if (m_activeDocument) {
1923         m_clipMonitor->slotSetXml(NULL, 0);
1924         m_activeDocument->updatePreviewSettings();
1925     }
1926 }
1927
1928 void MainWindow::updateConfiguration()
1929 {
1930     //TODO: we should apply settings to all projects, not only the current one
1931     if (m_activeTimeline) {
1932         m_activeTimeline->refresh();
1933         m_activeTimeline->projectView()->checkAutoScroll();
1934         m_activeTimeline->projectView()->checkTrackHeight();
1935         if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
1936     }
1937     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
1938     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
1939 #ifndef NO_JOGSHUTTLE
1940     activateShuttleDevice();
1941 #endif /* NO_JOGSHUTTLE */
1942
1943 }
1944
1945
1946 void MainWindow::slotSwitchVideoThumbs()
1947 {
1948     KdenliveSettings::setVideothumbnails(!KdenliveSettings::videothumbnails());
1949     if (m_activeTimeline) {
1950         m_activeTimeline->projectView()->slotUpdateAllThumbs();
1951     }
1952     m_buttonVideoThumbs->setChecked(KdenliveSettings::videothumbnails());
1953 }
1954
1955 void MainWindow::slotSwitchAudioThumbs()
1956 {
1957     KdenliveSettings::setAudiothumbnails(!KdenliveSettings::audiothumbnails());
1958     if (m_activeTimeline) {
1959         m_activeTimeline->refresh();
1960         m_activeTimeline->projectView()->checkAutoScroll();
1961         if (m_activeDocument) m_activeDocument->clipManager()->checkAudioThumbs();
1962     }
1963     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
1964 }
1965
1966 void MainWindow::slotSwitchMarkersComments()
1967 {
1968     KdenliveSettings::setShowmarkers(!KdenliveSettings::showmarkers());
1969     if (m_activeTimeline) {
1970         m_activeTimeline->refresh();
1971     }
1972     m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
1973 }
1974
1975 void MainWindow::slotSwitchSnap()
1976 {
1977     KdenliveSettings::setSnaptopoints(!KdenliveSettings::snaptopoints());
1978     m_buttonSnap->setChecked(KdenliveSettings::snaptopoints());
1979 }
1980
1981
1982 void MainWindow::slotDeleteTimelineClip()
1983 {
1984     if (QApplication::focusWidget()->parentWidget()->parentWidget() == m_projectListDock) m_projectList->slotRemoveClip();
1985     else if (m_activeTimeline) {
1986         m_activeTimeline->projectView()->deleteSelectedClips();
1987     }
1988 }
1989
1990 void MainWindow::slotChangeClipSpeed()
1991 {
1992     if (m_activeTimeline) {
1993         m_activeTimeline->projectView()->changeClipSpeed();
1994     }
1995 }
1996
1997 void MainWindow::slotAddClipMarker()
1998 {
1999     DocClipBase *clip = NULL;
2000     GenTime pos;
2001     if (m_projectMonitor->isActive()) {
2002         if (m_activeTimeline) {
2003             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
2004             if (item) {
2005                 pos = m_projectMonitor->position() - item->startPos() + item->cropStart();
2006                 clip = item->baseClip();
2007             }
2008         }
2009     } else {
2010         clip = m_clipMonitor->activeClip();
2011         pos = m_clipMonitor->position();
2012     }
2013     if (!clip) {
2014         m_messageLabel->setMessage(i18n("Cannot find clip to add marker"), ErrorMessage);
2015         return;
2016     }
2017     QString id = clip->getId();
2018     CommentedTime marker(pos, i18n("Marker"));
2019     MarkerDialog d(clip, marker, m_activeDocument->timecode(), i18n("Add Marker"), this);
2020     if (d.exec() == QDialog::Accepted) {
2021         m_activeTimeline->projectView()->slotAddClipMarker(id, d.newMarker().time(), d.newMarker().comment());
2022     }
2023     if (m_clipMonitor->isActive()) m_clipMonitor->checkOverlay();
2024 }
2025
2026 void MainWindow::slotDeleteClipMarker()
2027 {
2028     DocClipBase *clip = NULL;
2029     GenTime pos;
2030     if (m_projectMonitor->isActive()) {
2031         if (m_activeTimeline) {
2032             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
2033             if (item) {
2034                 pos = m_projectMonitor->position() - item->startPos() + item->cropStart();
2035                 clip = item->baseClip();
2036             }
2037         }
2038     } else {
2039         clip = m_clipMonitor->activeClip();
2040         pos = m_clipMonitor->position();
2041     }
2042     if (!clip) {
2043         m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
2044         return;
2045     }
2046
2047     QString id = clip->getId();
2048     QString comment = clip->markerComment(pos);
2049     if (comment.isEmpty()) {
2050         m_messageLabel->setMessage(i18n("No marker found at cursor time"), ErrorMessage);
2051         return;
2052     }
2053     m_activeTimeline->projectView()->slotDeleteClipMarker(comment, id, pos);
2054     if (m_clipMonitor->isActive()) m_clipMonitor->checkOverlay();
2055
2056 }
2057
2058 void MainWindow::slotDeleteAllClipMarkers()
2059 {
2060     DocClipBase *clip = NULL;
2061     if (m_projectMonitor->isActive()) {
2062         if (m_activeTimeline) {
2063             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
2064             if (item) {
2065                 clip = item->baseClip();
2066             }
2067         }
2068     } else {
2069         clip = m_clipMonitor->activeClip();
2070     }
2071     if (!clip) {
2072         m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
2073         return;
2074     }
2075     m_activeTimeline->projectView()->slotDeleteAllClipMarkers(clip->getId());
2076     if (m_clipMonitor->isActive()) m_clipMonitor->checkOverlay();
2077 }
2078
2079 void MainWindow::slotEditClipMarker()
2080 {
2081     DocClipBase *clip = NULL;
2082     GenTime pos;
2083     if (m_projectMonitor->isActive()) {
2084         if (m_activeTimeline) {
2085             ClipItem *item = m_activeTimeline->projectView()->getActiveClipUnderCursor();
2086             if (item) {
2087                 pos = m_projectMonitor->position() - item->startPos() + item->cropStart();
2088                 clip = item->baseClip();
2089             }
2090         }
2091     } else {
2092         clip = m_clipMonitor->activeClip();
2093         pos = m_clipMonitor->position();
2094     }
2095     if (!clip) {
2096         m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
2097         return;
2098     }
2099
2100     QString id = clip->getId();
2101     QString oldcomment = clip->markerComment(pos);
2102     if (oldcomment.isEmpty()) {
2103         m_messageLabel->setMessage(i18n("No marker found at cursor time"), ErrorMessage);
2104         return;
2105     }
2106
2107     CommentedTime marker(pos, oldcomment);
2108     MarkerDialog d(clip, marker, m_activeDocument->timecode(), i18n("Edit Marker"), this);
2109     if (d.exec() == QDialog::Accepted) {
2110         m_activeTimeline->projectView()->slotAddClipMarker(id, d.newMarker().time(), d.newMarker().comment());
2111         if (d.newMarker().time() != pos) {
2112             // remove old marker
2113             m_activeTimeline->projectView()->slotAddClipMarker(id, pos, QString());
2114         }
2115         if (m_clipMonitor->isActive()) m_clipMonitor->checkOverlay();
2116     }
2117 }
2118
2119 void MainWindow::slotAddGuide()
2120 {
2121     if (m_activeTimeline)
2122         m_activeTimeline->projectView()->slotAddGuide();
2123 }
2124
2125 void MainWindow::slotInsertSpace()
2126 {
2127     if (m_activeTimeline)
2128         m_activeTimeline->projectView()->slotInsertSpace();
2129 }
2130
2131 void MainWindow::slotRemoveSpace()
2132 {
2133     if (m_activeTimeline)
2134         m_activeTimeline->projectView()->slotRemoveSpace();
2135 }
2136
2137 void MainWindow::slotInsertTrack(int ix)
2138 {
2139     m_projectMonitor->activateMonitor();
2140     if (m_activeTimeline)
2141         m_activeTimeline->projectView()->slotInsertTrack(ix);
2142 }
2143
2144 void MainWindow::slotDeleteTrack(int ix)
2145 {
2146     m_projectMonitor->activateMonitor();
2147     if (m_activeTimeline)
2148         m_activeTimeline->projectView()->slotDeleteTrack(ix);
2149 }
2150
2151 void MainWindow::slotChangeTrack(int ix)
2152 {
2153     m_projectMonitor->activateMonitor();
2154     if (m_activeTimeline)
2155         m_activeTimeline->projectView()->slotChangeTrack(ix);
2156 }
2157
2158 void MainWindow::slotEditGuide()
2159 {
2160     if (m_activeTimeline)
2161         m_activeTimeline->projectView()->slotEditGuide();
2162 }
2163
2164 void MainWindow::slotDeleteGuide()
2165 {
2166     if (m_activeTimeline)
2167         m_activeTimeline->projectView()->slotDeleteGuide();
2168 }
2169
2170 void MainWindow::slotDeleteAllGuides()
2171 {
2172     if (m_activeTimeline)
2173         m_activeTimeline->projectView()->slotDeleteAllGuides();
2174 }
2175
2176 void MainWindow::slotCutTimelineClip()
2177 {
2178     if (m_activeTimeline) {
2179         m_activeTimeline->projectView()->cutSelectedClips();
2180     }
2181 }
2182
2183 void MainWindow::slotGroupClips()
2184 {
2185     if (m_activeTimeline) {
2186         m_activeTimeline->projectView()->groupClips();
2187     }
2188 }
2189
2190 void MainWindow::slotUnGroupClips()
2191 {
2192     if (m_activeTimeline) {
2193         m_activeTimeline->projectView()->groupClips(false);
2194     }
2195 }
2196
2197 void MainWindow::slotAddProjectClip(KUrl url)
2198 {
2199     if (m_activeDocument)
2200         m_activeDocument->slotAddClipFile(url, QString());
2201 }
2202
2203 void MainWindow::slotAddTransition(QAction *result)
2204 {
2205     if (!result) return;
2206     QStringList info = result->data().toStringList();
2207     if (info.isEmpty()) return;
2208     QDomElement transition = transitions.getEffectByTag(info.at(1), info.at(2));
2209     if (m_activeTimeline && !transition.isNull()) {
2210         m_activeTimeline->projectView()->slotAddTransitionToSelectedClips(transition.cloneNode().toElement());
2211     }
2212 }
2213
2214 void MainWindow::slotAddVideoEffect(QAction *result)
2215 {
2216     if (!result) return;
2217     QStringList info = result->data().toStringList();
2218     if (info.isEmpty()) return;
2219     QDomElement effect = videoEffects.getEffectByTag(info.at(1), info.at(2));
2220     slotAddEffect(effect);
2221 }
2222
2223 void MainWindow::slotAddAudioEffect(QAction *result)
2224 {
2225     if (!result) return;
2226     QStringList info = result->data().toStringList();
2227     if (info.isEmpty()) return;
2228     QDomElement effect = audioEffects.getEffectByTag(info.at(1), info.at(2));
2229     slotAddEffect(effect);
2230 }
2231
2232 void MainWindow::slotAddCustomEffect(QAction *result)
2233 {
2234     if (!result) return;
2235     QStringList info = result->data().toStringList();
2236     if (info.isEmpty()) return;
2237     QDomElement effect = customEffects.getEffectByTag(info.at(1), info.at(2));
2238     slotAddEffect(effect);
2239 }
2240
2241 void MainWindow::slotZoomIn()
2242 {
2243     m_zoomSlider->setValue(m_zoomSlider->value() - 1);
2244 }
2245
2246 void MainWindow::slotZoomOut()
2247 {
2248     m_zoomSlider->setValue(m_zoomSlider->value() + 1);
2249 }
2250
2251 void MainWindow::slotFitZoom()
2252 {
2253     if (m_activeTimeline) {
2254         m_zoomSlider->setValue(m_activeTimeline->fitZoom());
2255     }
2256 }
2257
2258 void MainWindow::slotGotProgressInfo(const QString &message, int progress)
2259 {
2260     m_statusProgressBar->setValue(progress);
2261     if (progress >= 0) {
2262         if (!message.isEmpty()) m_messageLabel->setMessage(message, InformationMessage);//statusLabel->setText(message);
2263         m_statusProgressBar->setVisible(true);
2264     } else {
2265         m_messageLabel->setMessage(QString(), DefaultMessage);
2266         m_statusProgressBar->setVisible(false);
2267     }
2268 }
2269
2270 void MainWindow::slotShowClipProperties(DocClipBase *clip)
2271 {
2272     if (clip->clipType() == TEXT) {
2273         QString titlepath = m_activeDocument->projectFolder().path() + "/titles/";
2274         QString path = clip->getProperty("resource");
2275         TitleWidget *dia_ui = new TitleWidget(KUrl(), titlepath, m_projectMonitor->render, this);
2276         QDomDocument doc;
2277         doc.setContent(clip->getProperty("xmldata"));
2278         dia_ui->setXml(doc);
2279         if (dia_ui->exec() == QDialog::Accepted) {
2280             QImage pix = dia_ui->renderedPixmap();
2281             pix.save(path);
2282             //slotAddClipFile(KUrl("/tmp/kdenlivetitle.png"), QString(), -1);
2283             //m_clipManager->slotEditTextClipFile(id, dia_ui->xml().toString());
2284             QMap <QString, QString> newprops;
2285             newprops.insert("xmldata", dia_ui->xml().toString());
2286             EditClipCommand *command = new EditClipCommand(m_projectList, clip->getId(), clip->properties(), newprops, true);
2287             m_activeDocument->commandStack()->push(command);
2288             m_clipMonitor->refreshMonitor(true);
2289             m_activeDocument->setModified(true);
2290         }
2291         delete dia_ui;
2292
2293         //m_activeDocument->editTextClip(clip->getProperty("xml"), clip->getId());
2294         return;
2295     }
2296     ClipProperties dia(clip, m_activeDocument->timecode(), m_activeDocument->fps(), this);
2297     connect(&dia, SIGNAL(addMarker(const QString &, GenTime, QString)), m_activeTimeline->projectView(), SLOT(slotAddClipMarker(const QString &, GenTime, QString)));
2298     if (dia.exec() == QDialog::Accepted) {
2299         EditClipCommand *command = new EditClipCommand(m_projectList, dia.clipId(), clip->properties(), dia.properties(), true);
2300         m_activeDocument->commandStack()->push(command);
2301
2302         //m_projectList->slotUpdateClipProperties(dia.clipId(), dia.properties());
2303         if (dia.needsTimelineRefresh()) {
2304             // update clip occurences in timeline
2305             m_activeTimeline->projectView()->slotUpdateClip(dia.clipId());
2306         }
2307     }
2308 }
2309
2310 void MainWindow::customEvent(QEvent* e)
2311 {
2312     if (e->type() == QEvent::User) {
2313         // The timeline playing position changed...
2314         kDebug() << "RECEIVED JOG EVEMNT!!!";
2315     }
2316 }
2317 void MainWindow::slotActivateEffectStackView()
2318 {
2319     m_effectStack->raiseWindow(m_effectStackDock);
2320 }
2321
2322 void MainWindow::slotActivateTransitionView(Transition *t)
2323 {
2324     if (t) m_transitionConfig->raiseWindow(m_transitionConfigDock);
2325 }
2326
2327 void MainWindow::slotSnapRewind()
2328 {
2329     if (m_projectMonitor->isActive()) {
2330         if (m_activeTimeline)
2331             m_activeTimeline->projectView()->slotSeekToPreviousSnap();
2332     } else m_clipMonitor->slotSeekToPreviousSnap();
2333 }
2334
2335 void MainWindow::slotSnapForward()
2336 {
2337     if (m_projectMonitor->isActive()) {
2338         if (m_activeTimeline)
2339             m_activeTimeline->projectView()->slotSeekToNextSnap();
2340     } else m_clipMonitor->slotSeekToNextSnap();
2341 }
2342
2343 void MainWindow::slotClipStart()
2344 {
2345     if (m_projectMonitor->isActive()) {
2346         if (m_activeTimeline)
2347             m_activeTimeline->projectView()->clipStart();
2348     }
2349 }
2350
2351 void MainWindow::slotClipEnd()
2352 {
2353     if (m_projectMonitor->isActive()) {
2354         if (m_activeTimeline)
2355             m_activeTimeline->projectView()->clipEnd();
2356     }
2357 }
2358
2359 void MainWindow::slotChangeTool(QAction * action)
2360 {
2361     if (action == m_buttonSelectTool) slotSetTool(SELECTTOOL);
2362     else if (action == m_buttonRazorTool) slotSetTool(RAZORTOOL);
2363     else if (action == m_buttonSpacerTool) slotSetTool(SPACERTOOL);
2364 }
2365
2366 void MainWindow::slotSetTool(PROJECTTOOL tool)
2367 {
2368     if (m_activeDocument && m_activeTimeline) {
2369         //m_activeDocument->setTool(tool);
2370         m_activeTimeline->projectView()->setTool(tool);
2371     }
2372 }
2373
2374 void MainWindow::slotCopy()
2375 {
2376     if (!m_activeDocument || !m_activeTimeline) return;
2377     m_activeTimeline->projectView()->copyClip();
2378 }
2379
2380 void MainWindow::slotPaste()
2381 {
2382     if (!m_activeDocument || !m_activeTimeline) return;
2383     m_activeTimeline->projectView()->pasteClip();
2384 }
2385
2386 void MainWindow::slotPasteEffects()
2387 {
2388     if (!m_activeDocument || !m_activeTimeline) return;
2389     m_activeTimeline->projectView()->pasteClipEffects();
2390 }
2391
2392 void MainWindow::slotFind()
2393 {
2394     if (!m_activeDocument || !m_activeTimeline) return;
2395     m_projectSearch->setEnabled(false);
2396     m_findActivated = true;
2397     m_findString.clear();
2398     m_activeTimeline->projectView()->initSearchStrings();
2399     statusBar()->showMessage(i18n("Starting -- find text as you type"));
2400     m_findTimer.start(5000);
2401     qApp->installEventFilter(this);
2402 }
2403
2404 void MainWindow::slotFindNext()
2405 {
2406     if (m_activeTimeline && m_activeTimeline->projectView()->findNextString(m_findString)) {
2407         statusBar()->showMessage(i18n("Found: %1", m_findString));
2408     } else {
2409         statusBar()->showMessage(i18n("Reached end of project"));
2410     }
2411     m_findTimer.start(4000);
2412 }
2413
2414 void MainWindow::findAhead()
2415 {
2416     if (m_activeTimeline && m_activeTimeline->projectView()->findString(m_findString)) {
2417         m_projectSearchNext->setEnabled(true);
2418         statusBar()->showMessage(i18n("Found: %1", m_findString));
2419     } else {
2420         m_projectSearchNext->setEnabled(false);
2421         statusBar()->showMessage(i18n("Not found: %1", m_findString));
2422     }
2423 }
2424
2425 void MainWindow::findTimeout()
2426 {
2427     m_projectSearchNext->setEnabled(false);
2428     m_findActivated = false;
2429     m_findString.clear();
2430     statusBar()->showMessage(i18n("Find stopped"), 3000);
2431     if (m_activeTimeline) m_activeTimeline->projectView()->clearSearchStrings();
2432     m_projectSearch->setEnabled(true);
2433     removeEventFilter(this);
2434 }
2435
2436 void MainWindow::keyPressEvent(QKeyEvent *ke)
2437 {
2438     if (m_findActivated) {
2439         if (ke->key() == Qt::Key_Backspace) {
2440             m_findString = m_findString.left(m_findString.length() - 1);
2441
2442             if (!m_findString.isEmpty()) {
2443                 findAhead();
2444             } else {
2445                 findTimeout();
2446             }
2447
2448             m_findTimer.start(4000);
2449             ke->accept();
2450             return;
2451         } else if (ke->key() == Qt::Key_Escape) {
2452             findTimeout();
2453             ke->accept();
2454             return;
2455         } else if (ke->key() == Qt::Key_Space || !ke->text().trimmed().isEmpty()) {
2456             m_findString += ke->text();
2457
2458             findAhead();
2459
2460             m_findTimer.start(4000);
2461             ke->accept();
2462             return;
2463         }
2464     } else KXmlGuiWindow::keyPressEvent(ke);
2465 }
2466
2467
2468 /** Gets called when the window gets hidden */
2469 void MainWindow::hideEvent(QHideEvent */*event*/)
2470 {
2471     // kDebug() << "I was hidden";
2472     // issue http://www.kdenlive.org/mantis/view.php?id=231
2473     if (isMinimized()) {
2474         // kDebug() << "I am minimized";
2475         if (m_monitorManager) m_monitorManager->stopActiveMonitor();
2476     }
2477 }
2478
2479 bool MainWindow::eventFilter(QObject *obj, QEvent *event)
2480 {
2481     if (m_findActivated) {
2482         if (event->type() == QEvent::ShortcutOverride) {
2483             QKeyEvent* ke = (QKeyEvent*) event;
2484             if (ke->text().trimmed().isEmpty()) return false;
2485             ke->accept();
2486             return true;
2487         } else return false;
2488     } else {
2489         // pass the event on to the parent class
2490         return QMainWindow::eventFilter(obj, event);
2491     }
2492 }
2493
2494 void MainWindow::slotSaveZone(Render *render, QPoint zone)
2495 {
2496     KDialog *dialog = new KDialog(this);
2497     dialog->setCaption("Save clip zone");
2498     dialog->setButtons(KDialog::Ok | KDialog::Cancel);
2499
2500     QWidget *widget = new QWidget(dialog);
2501     dialog->setMainWidget(widget);
2502
2503     QVBoxLayout *vbox = new QVBoxLayout(widget);
2504     QLabel *label1 = new QLabel(i18n("Save clip zone as:"), this);
2505     QString path = m_activeDocument->projectFolder().path();
2506     path.append("/");
2507     path.append("untitled.westley");
2508     KUrlRequester *url = new KUrlRequester(KUrl(path), this);
2509     url->setFilter("video/mlt-playlist");
2510     QLabel *label2 = new QLabel(i18n("Description:"), this);
2511     KLineEdit *edit = new KLineEdit(this);
2512     vbox->addWidget(label1);
2513     vbox->addWidget(url);
2514     vbox->addWidget(label2);
2515     vbox->addWidget(edit);
2516     if (dialog->exec() == QDialog::Accepted) render->saveZone(url->url(), edit->text(), zone);
2517
2518 }
2519
2520 void MainWindow::slotSetInPoint()
2521 {
2522     if (m_clipMonitor->isActive()) {
2523         m_clipMonitor->slotSetZoneStart();
2524     } else m_activeTimeline->projectView()->setInPoint();
2525 }
2526
2527 void MainWindow::slotSetOutPoint()
2528 {
2529     if (m_clipMonitor->isActive()) {
2530         m_clipMonitor->slotSetZoneEnd();
2531     } else m_activeTimeline->projectView()->setOutPoint();
2532 }
2533
2534 void MainWindow::slotGetNewLumaStuff()
2535 {
2536     //KNS::Entry::List download();
2537     KNS::Entry::List entries = KNS::Engine::download();
2538     // list of changed entries
2539     kDebug() << "// PARSING KNS";
2540     foreach(KNS::Entry* entry, entries) {
2541         // care only about installed ones
2542         if (entry->status() == KNS::Entry::Installed) {
2543             foreach(const QString &file, entry->installedFiles()) {
2544                 kDebug() << "// CURRENTLY INSTALLED: " << file;
2545             }
2546         }
2547     }
2548     qDeleteAll(entries);
2549     initEffects::refreshLumas();
2550 }
2551
2552 void MainWindow::slotGetNewRenderStuff()
2553 {
2554     //KNS::Entry::List download();
2555
2556     KNS::Engine engine(0);
2557     if (engine.init("kdenlive_render.knsrc")) {
2558         KNS::Entry::List entries = engine.downloadDialogModal(this);
2559
2560         if (entries.size() > 0) {
2561             foreach(KNS::Entry* entry, entries) {
2562                 // care only about installed ones
2563                 if (entry->status() == KNS::Entry::Installed) {
2564                     foreach(const QString &file, entry->installedFiles()) {
2565                         kDebug() << "// CURRENTLY INSTALLED: " << file;
2566                     }
2567                 }
2568             }
2569         }
2570         if (m_renderWidget) m_renderWidget->reloadProfiles();
2571     }
2572 }
2573
2574 void MainWindow::slotGetNewMltProfileStuff()
2575 {
2576     //KNS::Entry::List download();
2577
2578     KNS::Engine engine(0);
2579     if (engine.init("kdenlive_mltprofiles.knsrc")) {
2580         KNS::Entry::List entries = engine.downloadDialogModal(this);
2581
2582         if (entries.size() > 0) {
2583             foreach(KNS::Entry* entry, entries) {
2584                 // care only about installed ones
2585                 if (entry->status() == KNS::Entry::Installed) {
2586                     foreach(const QString &file, entry->installedFiles()) {
2587                         kDebug() << "// CURRENTLY INSTALLED: " << file;
2588                     }
2589                 }
2590             }
2591
2592             // update the list of profiles in settings dialog
2593             KdenliveSettingsDialog* d = static_cast <KdenliveSettingsDialog*>(KConfigDialog::exists("settings"));
2594             if (d) d->checkProfile();
2595         }
2596     }
2597 }
2598
2599 void MainWindow::slotAutoTransition()
2600 {
2601     if (m_activeTimeline) m_activeTimeline->projectView()->autoTransition();
2602 }
2603
2604 void MainWindow::slotSplitAudio()
2605 {
2606     if (m_activeTimeline) m_activeTimeline->projectView()->splitAudio();
2607 }
2608
2609 void MainWindow::slotUpdateClipType(QAction *action)
2610 {
2611     if (m_activeTimeline) {
2612         if (action->data().toString() == "clip_audio_only") m_activeTimeline->projectView()->setAudioOnly();
2613         else if (action->data().toString() == "clip_video_only") m_activeTimeline->projectView()->setVideoOnly();
2614         else m_activeTimeline->projectView()->setAudioAndVideo();
2615     }
2616 }
2617
2618 void MainWindow::slotDvdWizard(const QString &url, const QString &profile)
2619 {
2620     DvdWizard *w = new DvdWizard(url, profile, this);
2621     w->exec();
2622 }
2623
2624 void MainWindow::slotShowTimeline(bool show)
2625 {
2626     if (show == false) {
2627         m_timelineState = saveState();
2628         centralWidget()->setHidden(true);
2629     } else {
2630         centralWidget()->setHidden(false);
2631         restoreState(m_timelineState);
2632     }
2633 }
2634
2635 void MainWindow::slotMaximizeCurrent(bool show)
2636 {
2637     //TODO: is there a way to maximize current widget?
2638     //if (show == true)
2639     {
2640         m_timelineState = saveState();
2641         QWidget *par = focusWidget()->parentWidget();
2642         while (par->parentWidget() && par->parentWidget() != this) {
2643             par = par->parentWidget();
2644         }
2645         kDebug() << "CURRENT WIDGET: " << par->objectName();
2646     }
2647     /*else {
2648     //centralWidget()->setHidden(false);
2649     //restoreState(m_timelineState);
2650     }*/
2651 }
2652
2653 #include "mainwindow.moc"