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