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