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